nqm-minimongo
Version:
Client-side mongo database with server sync over http
2 lines • 37.3 kB
JavaScript
require=function n(t,e,r){function o(u,c){if(!e[u]){if(!t[u]){var a="function"==typeof require&&require;if(!c&&a)return a(u,!0);if(i)return i(u,!0);throw new Error("Cannot find module '"+u+"'")}var f=e[u]={exports:{}};t[u][0].call(f.exports,function(n){var e=t[u][1][n];return o(e?e:n)},f,f.exports,n,t,e,r)}return e[u].exports}for(var i="function"==typeof require&&require,u=0;u<r.length;u++)o(r[u]);return o}({"Focm2+":[function(n,t,e){e.MemoryDb=n("./lib/MemoryDb"),e.utils=n("./lib/utils")},{"./lib/MemoryDb":7,"./lib/utils":9}],minimongo:[function(n,t){t.exports=n("Focm2+")},{}],jquery:[function(n,t){t.exports=n("/nayFu")},{}],"/nayFu":[function(n,t){t.exports=window.$},{}],5:[function(n,t){var e=n("lodash");EJSON={};var r={};EJSON.addType=function(n,t){if(e.has(r,n))throw new Error("Type "+n+" already present");r[n]=t};var o=[{matchJSONValue:function(n){return e.has(n,"$date")&&1===e.size(n)},matchObject:function(n){return n instanceof Date},toJSONValue:function(n){return{$date:n.getTime()}},fromJSONValue:function(n){return new Date(n.$date)}},{matchJSONValue:function(n){return e.has(n,"$binary")&&1===e.size(n)},matchObject:function(n){return"undefined"!=typeof Uint8Array&&n instanceof Uint8Array||n&&e.has(n,"$Uint8ArrayPolyfill")},toJSONValue:function(n){return{$binary:EJSON._base64Encode(n)}},fromJSONValue:function(n){return EJSON._base64Decode(n.$binary)}},{matchJSONValue:function(n){return e.has(n,"$escape")&&1===e.size(n)},matchObject:function(n){return e.isEmpty(n)||e.size(n)>2?!1:e.any(o,function(t){return t.matchJSONValue(n)})},toJSONValue:function(n){var t={};return e.each(n,function(n,e){t[e]=EJSON.toJSONValue(n)}),{$escape:t}},fromJSONValue:function(n){var t={};return e.each(n.$escape,function(n,e){t[e]=EJSON.fromJSONValue(n)}),t}},{matchJSONValue:function(n){return e.has(n,"$type")&&e.has(n,"$value")&&2===e.size(n)},matchObject:function(n){return EJSON._isCustomType(n)},toJSONValue:function(n){return{$type:n.typeName(),$value:n.toJSONValue()}},fromJSONValue:function(n){var t=n.$type,e=r[t];return e(n.$value)}}];EJSON._isCustomType=function(n){return n&&"function"==typeof n.toJSONValue&&"function"==typeof n.typeName&&e.has(r,n.typeName())};var i=EJSON._adjustTypesToJSONValue=function(n){if(null===n)return null;var t=u(n);return void 0!==t?t:(e.each(n,function(t,e){if("object"==typeof t||void 0===t){var r=u(t);return r?(n[e]=r,void 0):(i(t),void 0)}}),n)},u=function(n){for(var t=0;t<o.length;t++){var e=o[t];if(e.matchObject(n))return e.toJSONValue(n)}return void 0};EJSON.toJSONValue=function(n){var t=u(n);return void 0!==t?t:("object"==typeof n&&(n=EJSON.clone(n),i(n)),n)};var c=EJSON._adjustTypesFromJSONValue=function(n){if(null===n)return null;var t=a(n);return t!==n?t:(e.each(n,function(t,e){if("object"==typeof t){var r=a(t);if(t!==r)return n[e]=r,void 0;c(t)}}),n)},a=function(n){if("object"==typeof n&&null!==n&&e.size(n)<=2&&e.all(n,function(n,t){return"string"==typeof t&&"$"===t.substr(0,1)}))for(var t=0;t<o.length;t++){var r=o[t];if(r.matchJSONValue(n))return r.fromJSONValue(n)}return n};EJSON.fromJSONValue=function(n){var t=a(n);return t===n&&"object"==typeof n?(n=EJSON.clone(n),c(n),n):t},EJSON.stringify=function(n){return JSON.stringify(EJSON.toJSONValue(n))},EJSON.parse=function(n){return EJSON.fromJSONValue(JSON.parse(n))},EJSON.isBinary=function(n){return"undefined"!=typeof Uint8Array&&n instanceof Uint8Array||n&&n.$Uint8ArrayPolyfill},EJSON.equals=function(n,t,r){var o,i=!(!r||!r.keyOrderSensitive);if(n===t)return!0;if(!n||!t)return!1;if("object"!=typeof n||"object"!=typeof t)return!1;if(n instanceof Date&&t instanceof Date)return n.valueOf()===t.valueOf();if(EJSON.isBinary(n)&&EJSON.isBinary(t)){if(n.length!==t.length)return!1;for(o=0;o<n.length;o++)if(n[o]!==t[o])return!1;return!0}if("function"==typeof n.equals)return n.equals(t,r);if(n instanceof Array){if(!(t instanceof Array))return!1;if(n.length!==t.length)return!1;for(o=0;o<n.length;o++)if(!EJSON.equals(n[o],t[o],r))return!1;return!0}var u;if(i){var c=[];return e.each(t,function(n,t){c.push(t)}),o=0,u=e.all(n,function(n,e){return o>=c.length?!1:e!==c[o]?!1:EJSON.equals(n,t[c[o]],r)?(o++,!0):!1}),u&&o===c.length}return o=0,u=e.all(n,function(n,i){return e.has(t,i)?EJSON.equals(n,t[i],r)?(o++,!0):!1:!1}),u&&e.size(t)===o},EJSON.clone=function(n){var t;if("object"!=typeof n)return n;if(null===n)return null;if(n instanceof Date)return new Date(n.getTime());if(EJSON.isBinary(n)){t=EJSON.newBinary(n.length);for(var r=0;r<n.length;r++)t[r]=n[r];return t}if(e.isArray(n)||e.isArguments(n)){for(t=[],r=0;r<n.length;r++)t[r]=EJSON.clone(n[r]);return t}return"function"==typeof n.clone?n.clone():(t={},e.each(n,function(n,e){t[e]=EJSON.clone(n)}),t)},t.exports=EJSON},{lodash:"nJZoxB"}],6:[function(n,t){var e,r,o,i,u;u=n("lodash"),o=n("./utils").processFind,i=n("./utils"),t.exports=r=function(){function n(n,t){this.localDb=n,this.remoteDb=t,this.collections={}}return n.prototype.addCollection=function(n,t,r,o){var i,c;return u.isFunction(t)&&(c=[{},t,r],t=c[0],r=c[1],o=c[2]),i=new e(n,this.localDb[n],this.remoteDb[n],t),this[n]=i,this.collections[n]=i,null!=r?r():void 0},n.prototype.removeCollection=function(n,t){return delete this[n],delete this.collections[n],null!=t?t():void 0},n.prototype.upload=function(n,t){var e,r;return e=u.values(this.collections),r=function(n,t,e){var o;return o=u.first(n),o?o.upload(function(){return r(u.rest(n),t,e)},function(n){return e(n)}):t()},r(e,n,t)},n}(),e=function(){function n(n,t,e,r){this.name=n,this.localCol=t,this.remoteCol=e,this.options=r||{},u.defaults(this.options,{cacheFind:!0,cacheFindOne:!0,interim:!0,useLocalOnRemoteError:!0,shortcut:!1,timeout:0,sortUpserts:null})}return n.prototype.find=function(n,t){return null==t&&(t={}),{fetch:function(e){return function(r,o){return e._findFetch(n,t,r,o)}}(this)}},n.prototype.findOne=function(n,t,e,r){var o,i;return null==t&&(t={}),u.isFunction(t)&&(i=[{},t,e],t=i[0],e=i[1],r=i[2]),u.defaults(t,this.options),o=function(o){return function(i){var c;return c=u.cloneDeep(t),c.interim=!1,c.cacheFind=t.cacheFindOne,n._id?c.limit=1:delete c.limit,o.find(n,c).fetch(function(n){return n.length>0?u.isEqual(i,n[0])?void 0:e(n[0]):e(null)},r)}}(this),t.interim||t.shortcut?this.localCol.findOne(n,t,function(n){return n&&(e(u.cloneDeep(n)),t.shortcut)?void 0:o(n)},r):o()},n.prototype._findFetch=function(n,t,e,r){var i,c;return u.defaults(t,this.options),c=function(i){return function(c){var a,f,l,s,p;return f=u.cloneDeep(t),t.cacheFind&&delete f.fields,p=null,s=!1,l=function(a){var f,l;return p&&clearTimeout(p),s?(t.cacheFind&&i.localCol.cache(a,n,t,function(){},r),void 0):t.cacheFind?(f=function(){var o;return o=function(n){return u.isEqual(c,n)?void 0:e(n)},i.localCol.find(n,t).fetch(o,r)},i.localCol.cache(a,n,t,f,r)):(l=a,i.localCol.pendingRemoves(function(f){var s;return f.length>0&&(s=u.object(u.map(f,function(n){return[n,n]})),l=u.filter(a,function(n){return!u.has(s,n._id)})),i.localCol.pendingUpserts(function(r){var i;return r.length>0&&(i=u.object(u.map(r,function(n){return n.doc._id}),u.map(r,function(n){return n.doc._id})),l=u.filter(l,function(n){return!u.has(i,n._id)}),l=l.concat(u.pluck(r,"doc")),l=o(l,n,t)),u.isEqual(c,l)?void 0:e(l)},r)},r))},a=function(o){if(p&&clearTimeout(p),!s&&!t.interim){if(t.useLocalOnRemoteError)return i.localCol.find(n,t).fetch(e,r);if(r)return r(o)}},t.timeout&&(p=setTimeout(function(){if(p=null,s=!0,!t.interim){if(t.useLocalOnRemoteError)return i.localCol.find(n,t).fetch(e,r);if(r)return r(new Error("Remote timed out"))}},t.timeout)),i.remoteCol.find(n,f).fetch(l,a)}}(this),t.interim?(i=function(n){return e(n),c(n)},this.localCol.find(n,t).fetch(i,r)):c()},n.prototype.upsert=function(n,t,e,r){return this.localCol.upsert(n,t,function(){return u.isFunction(t)&&(e=t),"function"==typeof e?e(n):void 0},r)},n.prototype.remove=function(n,t,e){return this.localCol.remove(n,function(){return null!=t?t():void 0},e)},n.prototype.upload=function(n,t){var e,r;return r=function(n){return function(t,e,o){var i;return i=u.first(t),i?n.remoteCol.upsert(i.doc,i.base,function(c){return n.localCol.resolveUpserts([i],function(){return c?n.localCol.cacheOne(c,function(){return r(u.rest(t),e,o)},o):n.localCol.remove(i.doc._id,function(){return n.localCol.resolveRemove(i.doc._id,function(){return r(u.rest(t),e,o)},o)},o)},o)},function(c){return 410===c.status||403===c.status?n.localCol.remove(i.doc._id,function(){return n.localCol.resolveRemove(i.doc._id,function(){return 410===c.status?r(u.rest(t),e,o):o(c)},o)},o):o(c)}):e()}}(this),e=function(n){return function(t,r,o){var i;return i=u.first(t),i?n.remoteCol.remove(i,function(){return n.localCol.resolveRemove(i,function(){return e(u.rest(t),r,o)},o)},function(c){return 410===c.status||403===c.status?n.localCol.resolveRemove(i,function(){return 410===c.status?e(u.rest(t),r,o):o(c)},o):o(c)},o):r()}}(this),this.localCol.pendingUpserts(function(o){return function(i){return o.options.sortUpserts&&i.sort(o.options.sortUpserts),r(i,function(){return o.localCol.pendingRemoves(function(r){return e(r,n,t)},t)},t)}}(this),t)},n}()},{"./utils":9,lodash:"nJZoxB"}],7:[function(n,t){var e,r,o,i,u,c,a;a=n("lodash"),o=n("async"),c=n("./utils"),u=n("./utils").processFind,i=n("./selector").compileSort,t.exports=r=function(){function n(n,t){this.collections={},t&&t(this)}return n.prototype.addCollection=function(n,t){var r;return r=new e(n),this[n]=r,this.collections[n]=r,null!=t?t():void 0},n.prototype.removeCollection=function(n,t){return delete this[n],delete this.collections[n],null!=t?t():void 0},n}(),e=function(){function n(n){this.name=n,this.items={},this.upserts={},this.removes={}}return n.prototype.find=function(n,t){return{fetch:function(e){return function(r,o){return e._findFetch(n,t,r,o)}}(this)}},n.prototype.findOne=function(n,t,e,r){var o,i;return a.isFunction(t)&&(i=[{},t,e],t=i[0],e=i[1],r=i[2]),o=this.find(n,t).fetch(function(n){return null!=e?e(n.length>0?n[0]:null):void 0},r),o&&o.length>0?o[0]:null},n.prototype._findFetch=function(n,t,e){var r;return r=u(a.values(this.items),n,t),null!=e&&e(r),r},n.prototype.upsert=function(n,t,e,r){var o,i,u,a,f;for(f=c.regularizeUpsert(n,t,e,r),i=f[0],e=f[1],r=f[2],u=0,a=i.length;a>u;u++)o=i[u],void 0===o.base&&(o.base=this.upserts[o.doc._id]?this.upserts[o.doc._id].base:this.items[o.doc._id]||null),this.items[o.doc._id]=o.doc,this.upserts[o.doc._id]=o;return e?e(n):void 0},n.prototype.remove=function(n,t,e){return a.isObject(n)?(this.find(n).fetch(function(n){return function(e){return o.each(e,function(t,e){return n.remove(t._id,function(){return e()},e)},function(){return t()})}}(this),e),void 0):(a.has(this.items,n)?(this.removes[n]=this.items[n],delete this.items[n],delete this.upserts[n]):this.removes[n]={_id:n},null!=t?t():void 0)},n.prototype.cache=function(n,t,e,r,o){var u,c,f,l,s;for(l=0,s=n.length;s>l;l++)u=n[l],this.cacheOne(u);return c=a.object(a.pluck(n,"_id"),n),e.sort&&(f=i(e.sort)),this.find(t,e).fetch(function(t){return function(o){var i,u,l;for(u=0,l=o.length;l>u;u++)if(i=o[u],!c[i._id]&&!a.has(t.upserts,i._id)){if(e.sort&&e.limit&&n.length===e.limit&&f(i,a.last(n))>=0)continue;delete t.items[i._id]}return null!=r?r():void 0}}(this),o)},n.prototype.pendingUpserts=function(n){return n(a.values(this.upserts))},n.prototype.pendingRemoves=function(n){return n(a.pluck(this.removes,"_id"))},n.prototype.resolveUpserts=function(n,t){var e,r,o,i;for(o=0,i=n.length;i>o;o++)r=n[o],e=r.doc._id,this.upserts[e]&&(a.isEqual(r.doc,this.upserts[e].doc)?delete this.upserts[e]:this.upserts[e].base=r.doc);return null!=t?t():void 0},n.prototype.resolveRemove=function(n,t){return delete this.removes[n],null!=t?t():void 0},n.prototype.seed=function(n,t){var e,r,o;for(a.isArray(n)||(n=[n]),r=0,o=n.length;o>r;r++)e=n[r],a.has(this.items,e._id)||a.has(this.removes,e._id)||(this.items[e._id]=e);return null!=t?t():void 0},n.prototype.cacheOne=function(n,t){var e;return a.has(this.upserts,n._id)||a.has(this.removes,n._id)||(e=this.items[n._id],(!e||!n._rev||!e._rev||n._rev>=e._rev)&&(this.items[n._id]=n)),null!=t?t():void 0},n.prototype.uncache=function(n,t){var e,r;return e=c.compileDocumentSelector(n),r=a.filter(a.values(this.items),function(n){return function(t){return null!=n.upserts[t._id]||!e(t)}}(this)),this.items=a.object(a.pluck(r,"_id"),r),null!=t?t():void 0},n}()},{"./selector":8,"./utils":9,async:12,lodash:"nJZoxB"}],8:[function(n,t,e){LocalCollection={},EJSON=n("./EJSON");var r=n("lodash"),o=function(n){return r.isArray(n)&&!EJSON.isBinary(n)},i=function(n,t){return o(n)?r.any(n,t):t(n)},u=function(n,t){return t(n)?!0:o(n)&&r.any(n,t)},c=function(n){var t=void 0;for(var e in n){var r="$"===e.substr(0,1);if(void 0===t)t=r;else if(t!==r)throw new Error("Inconsistent selector: "+n)}return!!t},a=function(n){if(null==n)return function(n){return i(n,function(n){return null==n})};if(!r.isObject(n))return function(t){return i(t,function(t){return t===n})};if(n instanceof RegExp)return function(t){return void 0===t?!1:i(t,function(t){return n.test(t)})};if(o(n))return function(t){return o(t)?u(t,function(t){return LocalCollection._f._equal(n,t)}):!1};if(c(n)){var t=[];return r.each(n,function(e,o){if(!r.has(l,o))throw new Error("Unrecognized operator: "+o);t.push(l[o](e,n.$options))}),function(n){return r.all(t,function(t){return t(n)})}}return function(t){return i(t,function(t){return LocalCollection._f._equal(n,t)})}},f={$and:function(n){if(!o(n)||r.isEmpty(n))throw Error("$and/$or/$nor must be nonempty array");var t=r.map(n,s);return function(n){return r.all(t,function(t){return t(n)})}},$or:function(n){if(!o(n)||r.isEmpty(n))throw Error("$and/$or/$nor must be nonempty array");var t=r.map(n,s);return function(n){return r.any(t,function(t){return t(n)})}},$nor:function(n){if(!o(n)||r.isEmpty(n))throw Error("$and/$or/$nor must be nonempty array");var t=r.map(n,s);return function(n){return r.all(t,function(t){return!t(n)})}},$where:function(n){return n instanceof Function||(n=Function("return "+n)),function(t){return n.call(t)}}},l={$in:function(n){if(!o(n))throw new Error("Argument to $in must be array");var t=null;return r.all(n,r.isString)&&(t=r.indexBy(n)),function(e){return u(e,function(e){return r.isString(e)&&null!==t?void 0!=t[e]:r.any(n,function(n){return LocalCollection._f._equal(n,e)})})}},$all:function(n){if(!o(n))throw new Error("Argument to $all must be array");return function(t){return o(t)?r.all(n,function(n){return r.any(t,function(t){return LocalCollection._f._equal(n,t)})}):!1}},$lt:function(n){return function(t){return i(t,function(t){return LocalCollection._f._cmp(t,n)<0})}},$lte:function(n){return function(t){return i(t,function(t){return LocalCollection._f._cmp(t,n)<=0})}},$gt:function(n){return function(t){return i(t,function(t){return LocalCollection._f._cmp(t,n)>0})}},$gte:function(n){return function(t){return i(t,function(t){return LocalCollection._f._cmp(t,n)>=0})}},$ne:function(n){return function(t){return!u(t,function(t){return LocalCollection._f._equal(t,n)})}},$nin:function(n){if(!o(n))throw new Error("Argument to $nin must be array");var t=l.$in(n);return function(n){return void 0===n?!0:!t(n)}},$exists:function(n){return function(t){return n===(void 0!==t)}},$mod:function(n){var t=n[0],e=n[1];return function(n){return i(n,function(n){return n%t===e})}},$size:function(n){return function(t){return o(t)&&n===t.length}},$type:function(n){return function(t){return void 0===t?!1:i(t,function(t){return LocalCollection._f._type(t)===n})}},$regex:function(n,t){if(void 0!==t){if(/[^gim]/.test(t))throw new Error("Only the i, m, and g regexp options are supported");var e=n instanceof RegExp?n.source:n;n=new RegExp(e,t)}else n instanceof RegExp||(n=new RegExp(n));return function(t){return void 0===t?!1:i(t,function(t){return n.test(t)})}},$options:function(){return function(){return!0}},$elemMatch:function(n){var t=s(n);return function(n){return o(n)?r.any(n,function(n){return t(n)}):!1}},$not:function(n){var t=a(n);return function(n){return!t(n)}},$near:function(){return function(){return!0}},$geoIntersects:function(){return function(){return!0}}};LocalCollection._f={_type:function(n){return"number"==typeof n?1:"string"==typeof n?2:"boolean"==typeof n?8:o(n)?4:null===n?10:n instanceof RegExp?11:"function"==typeof n?13:n instanceof Date?9:EJSON.isBinary(n)?5:n instanceof Meteor.Collection.ObjectID?7:3},_equal:function(n,t){return EJSON.equals(n,t,{keyOrderSensitive:!0})},_typeorder:function(n){return[-1,1,2,3,4,5,-1,6,7,8,0,9,-1,100,2,100,1,8,1][n]},_cmp:function(n,t){if(void 0===n)return void 0===t?0:-1;if(void 0===t)return 1;var e=LocalCollection._f._type(n),r=LocalCollection._f._type(t),o=LocalCollection._f._typeorder(e),i=LocalCollection._f._typeorder(r);if(o!==i)return i>o?-1:1;if(e!==r)throw Error("Missing type coercion logic in _cmp");if(7===e&&(e=r=2,n=n.toHexString(),t=t.toHexString()),9===e&&(e=r=1,n=n.getTime(),t=t.getTime()),1===e)return n-t;if(2===r)return t>n?-1:n===t?0:1;if(3===e){var u=function(n){var t=[];for(var e in n)t.push(e),t.push(n[e]);return t};return LocalCollection._f._cmp(u(n),u(t))}if(4===e)for(var c=0;;c++){if(c===n.length)return c===t.length?0:-1;if(c===t.length)return 1;var a=LocalCollection._f._cmp(n[c],t[c]);if(0!==a)return a}if(5===e){if(n.length!==t.length)return n.length-t.length;for(c=0;c<n.length;c++){if(n[c]<t[c])return-1;if(n[c]>t[c])return 1}return 0}if(8===e)return n?t?0:1:t?-1:0;if(10===e)return 0;if(11===e)throw Error("Sorting not supported on regular expression");if(13===e)throw Error("Sorting not supported on Javascript code");throw Error("Unknown type to sort")}},LocalCollection._matches=function(n,t){return LocalCollection._compileSelector(n)(t)},LocalCollection._makeLookupFunction=function(n){var t,e,i,u=n.indexOf(".");if(-1===u)t=n;else{t=n.substr(0,u);var c=n.substr(u+1);e=LocalCollection._makeLookupFunction(c),i=/^\d+(\.|$)/.test(c)}return function(n){if(null==n)return[void 0];var u=n[t];return e?o(u)&&0===u.length?[void 0]:((!o(u)||i)&&(u=[u]),Array.prototype.concat.apply([],r.map(u,e))):[u]}};var s=function(n){var t=[];return r.each(n,function(n,e){if("$"===e.substr(0,1)){if(!r.has(f,e))throw new Error("Unrecognized logical operator: "+e);t.push(f[e](n))}else{var o=LocalCollection._makeLookupFunction(e),i=a(n);t.push(function(n){var t=o(n);return r.any(t,i)})}}),function(n){return r.all(t,function(t){return t(n)})}};LocalCollection._compileSelector=function(n){if(n instanceof Function)return function(t){return n.call(t)};if(LocalCollection._selectorIsId(n))return function(t){return EJSON.equals(t._id,n)};if(!n||"_id"in n&&!n._id)return function(){return!1};if("boolean"==typeof n||o(n)||EJSON.isBinary(n))throw new Error("Invalid selector: "+n);return s(n)},LocalCollection._compileSort=function(n){var t=[];if(n instanceof Array)for(var e=0;e<n.length;e++)"string"==typeof n[e]?t.push({lookup:LocalCollection._makeLookupFunction(n[e]),ascending:!0}):t.push({lookup:LocalCollection._makeLookupFunction(n[e][0]),ascending:"desc"!==n[e][1]});else{if("object"!=typeof n)throw Error("Bad sort specification: ",JSON.stringify(n));for(var i in n)t.push({lookup:LocalCollection._makeLookupFunction(i),ascending:n[i]>=0})}if(0===t.length)return function(){return 0};var u=function(n,t){var e,i=!0;return r.each(n,function(n){o(n)||(n=[n]),o(n)&&0===n.length&&(n=[void 0]),r.each(n,function(n){if(i)e=n,i=!1;else{var r=LocalCollection._f._cmp(e,n);(t&&r>0||!t&&0>r)&&(e=n)}})}),e};return function(n,e){for(var r=0;r<t.length;++r){var o=t[r],i=u(o.lookup(n),o.ascending),c=u(o.lookup(e),o.ascending),a=LocalCollection._f._cmp(i,c);if(0!==a)return o.ascending?a:-a}return 0}},e.compileDocumentSelector=s,e.compileSort=LocalCollection._compileSort},{"./EJSON":5,lodash:"nJZoxB"}],9:[function(n,t,e){var r,o,i,u,c,a,f,l,s,p;p=n("lodash"),r=n("async"),o=n("./selector").compileDocumentSelector,i=n("./selector").compileSort,a=function(){var n;if(!window.localStorage)return!1;try{return window.localStorage.setItem("test","test"),window.localStorage.removeItem("test"),!0}catch(t){return n=t,!1}},e.compileDocumentSelector=o,e.autoselectLocalDb=function(t,e){var r;return r=n("./MemoryDb"),new r(t,e)},e.migrateLocalDb=function(t,e,r,o){var i,u,c,a,f;i=n("./HybridDb"),c=new i(t,e),f=t.collections;for(a in f)u=f[a],e[a]&&c.addCollection(a);return c.upload(r,o)},e.cloneLocalDb=function(n,t,e,o){var i,u,c;c=n.collections;for(u in c)i=c[u],t[u]||t.addCollection(u);return r.each(p.values(n.collections),function(){return function(n,e){var o;return o=t[n.name],n.find({}).fetch(function(t){return o.seed(t,function(){return n.pendingUpserts(function(t){return o.upsert(p.pluck(t,"doc"),p.pluck(t,"base"),function(){return n.pendingRemoves(function(n){return r.eachSeries(n,function(n,t){return o.remove(n,function(){return t()},t)},e)},e)},e)},e)},e)},e)}}(this),function(){return function(n){return n?o(n):e()}}(this))},e.processFind=function(n,t,r){var u;return u=p.filter(n,o(t)),u=s(t,u),u=l(t,u),r&&r.sort&&u.sort(i(r.sort)),r&&r.skip&&(u=p.slice(u,r.skip)),r&&r.limit&&(u=p.take(u,r.limit)),r&&r.fields&&(u=e.filterFields(u,r.fields)),u},e.filterFields=function(n,t){return null==t&&(t={}),0===p.keys(t).length?n:p.map(n,function(n){var e,r,o,i,u,c,a,f,l,s,h,d,m,v,y,g,O,w,S,_,b;if(o={},1===p.first(p.values(t))){for(w=p.keys(t).concat(["_id"]),f=0,d=w.length;d>f;f++){for(e=w[f],u=e.split("."),i=n,l=0,m=u.length;m>l;l++)c=u[l],i&&(i=i[c]);if(null!=i){for(r=n,a=o,S=p.initial(u),s=0,v=S.length;v>s;s++)c=S[s],a[c]=a[c]||{},a=a[c],r=r[c];a[p.last(u)]=r[p.last(u)]}}return o}for(n=p.cloneDeep(n),_=p.keys(t),h=0,y=_.length;y>h;h++){for(e=_[h],u=e.split("."),i=n,b=p.initial(u),O=0,g=b.length;g>O;O++)c=b[O],i&&(i=i[c]);null!=i&&delete i[p.last(u)]}return n})},e.createUid=function(){return"xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g,function(n){var t,e;return t=16*Math.random()|0,e="x"===n?t:3&t|8,e.toString(16)})},s=function(n,t){var e,r,o,i;for(o in n)if(i=n[o],null!=i&&i.$near){if(r=i.$near.$geometry,"Point"!==r.type)break;t=p.filter(t,function(n){return n[o]&&"Point"===n[o].type}),e=p.map(t,function(n){return{doc:n,distance:c(r.coordinates[1],r.coordinates[0],n[o].coordinates[1],n[o].coordinates[0])}}),e=p.filter(e,function(n){return n.distance>=0}),e=p.sortBy(e,"distance"),i.$near.$maxDistance&&(e=p.filter(e,function(n){return n.distance<=i.$near.$maxDistance})),t=p.pluck(e,"doc")}return t},f=function(n,t){if(!p.isEqual(p.first(t.coordinates[0]),p.last(t.coordinates[0])))throw new Error("First must equal last");return n.coordinates[0]<Math.min.apply(this,p.map(t.coordinates[0],function(n){return n[0]}))?!1:n.coordinates[1]<Math.min.apply(this,p.map(t.coordinates[0],function(n){return n[1]}))?!1:n.coordinates[0]>Math.max.apply(this,p.map(t.coordinates[0],function(n){return n[0]}))?!1:n.coordinates[1]>Math.max.apply(this,p.map(t.coordinates[0],function(n){return n[1]}))?!1:!0},c=function(n,t,e,r){var o,i,c,a,f,l;return o=6370986,f=u(e-n),l=u(r-t),i=Math.sin(f/2)*Math.sin(f/2)+Math.cos(u(n))*Math.cos(u(e))*Math.sin(l/2)*Math.sin(l/2),c=2*Math.atan2(Math.sqrt(i),Math.sqrt(1-i)),a=o*c},u=function(n){return n*(Math.PI/180)},l=function(n,t){var e,r,o;for(r in n)if(o=n[r],null!=o&&o.$geoIntersects){if(e=o.$geoIntersects.$geometry,"Polygon"!==e.type)break;t=p.filter(t,function(n){return n[r]&&"Point"===n[r].type?f(n[r],e):!1})}return t},e.regularizeUpsert=function(n,t,r,o){var i,u,c,a,f;for(p.isFunction(t)&&(f=[void 0,t,r],t=f[0],r=f[1],o=f[2]),p.isArray(n)?t=t||[]:(n=[n],t=[t]),u=p.map(n,function(n,e){return{doc:n,base:e<t.length?t[e]:void 0}}),c=0,a=u.length;a>c;c++){if(i=u[c],i.doc._id||(i.doc._id=e.createUid()),i.base&&!i.base._id)throw new Error("Base needs _id");if(i.base&&i.base._id!==i.doc._id)throw new Error("Base needs same _id")}return[u,r,o]}},{"./HybridDb":6,"./MemoryDb":7,"./selector":8,async:12,lodash:"nJZoxB"}],lodash:[function(n,t){t.exports=n("nJZoxB")},{}],nJZoxB:[function(n,t){t.exports=window._},{}],12:[function(n,t){(function(n,e){!function(){function r(){}function o(n){return n}function i(n){return!!n}function u(n){return!n}function c(n){return function(){if(null===n)throw new Error("Callback was already called.");n.apply(this,arguments),n=null}}function a(n){return function(){null!==n&&(n.apply(this,arguments),n=null)}}function f(n){return V(n)||"number"==typeof n.length&&n.length>=0&&n.length%1===0}function l(n,t){for(var e=-1,r=n.length;++e<r;)t(n[e],e,n)}function s(n,t){for(var e=-1,r=n.length,o=Array(r);++e<r;)o[e]=t(n[e],e,n);return o}function p(n){return s(Array(n),function(n,t){return t})}function h(n,t,e){return l(n,function(n,r,o){e=t(e,n,r,o)}),e}function d(n,t){l(T(n),function(e){t(n[e],e)})}function m(n,t){for(var e=0;e<n.length;e++)if(n[e]===t)return e;return-1}function v(n){var t,e,r=-1;return f(n)?(t=n.length,function(){return r++,t>r?r:null}):(e=T(n),t=e.length,function(){return r++,t>r?e[r]:null})}function y(n,t){return t=null==t?n.length-1:+t,function(){for(var e=Math.max(arguments.length-t,0),r=Array(e),o=0;e>o;o++)r[o]=arguments[o+t];switch(t){case 0:return n.call(this,r);case 1:return n.call(this,arguments[0],r)}}}function g(n){return function(t,e,r){return n(t,r)}}function O(n){return function(t,e,o){o=a(o||r),t=t||[];var i=v(t);if(0>=n)return o(null);var u=!1,f=0,l=!1;!function s(){if(u&&0>=f)return o(null);for(;n>f&&!l;){var r=i();if(null===r)return u=!0,0>=f&&o(null),void 0;f+=1,e(t[r],r,c(function(n){f-=1,n?(o(n),l=!0):s()}))}}()}}function w(n){return function(t,e,r){return n(I.eachOf,t,e,r)}}function S(n){return function(t,e,r,o){return n(O(e),t,r,o)}}function _(n){return function(t,e,r){return n(I.eachOfSeries,t,e,r)}}function b(n,t,e,o){o=a(o||r),t=t||[];var i=f(t)?[]:{};n(t,function(n,t,r){e(n,function(n,e){i[t]=e,r(n)})},function(n){o(n,i)})}function E(n,t,e,r){var o=[];n(t,function(n,t,r){e(n,function(e){e&&o.push({index:t,value:n}),r()})},function(){r(s(o.sort(function(n,t){return n.index-t.index}),function(n){return n.value}))})}function x(n,t,e,r){E(n,t,function(n,t){e(n,function(n){t(!n)})},r)}function k(n,t,e){return function(r,o,i,u){function c(){u&&u(e(!1,void 0))}function a(n,r,o){return u?(i(n,function(r){u&&t(r)&&(u(e(!0,n)),u=i=!1),o()}),void 0):o()}arguments.length>3?n(r,o,a,c):(u=i,i=o,n(r,a,c))}}function J(n,t){return t}function C(n,t,e){e=e||r;var o=f(t)?[]:{};n(t,function(n,t,e){n(y(function(n,r){r.length<=1&&(r=r[0]),o[t]=r,e(n)}))},function(n){e(n,o)})}function N(n,t,e,r){var o=[];n(t,function(n,t,r){e(n,function(n,t){o=o.concat(t||[]),r(n)})},function(n){r(n,o)})}function $(n,t,e){function o(n,t,e,o){if(null!=o&&"function"!=typeof o)throw new Error("task callback must be a function");return n.started=!0,V(t)||(t=[t]),0===t.length&&n.idle()?I.setImmediate(function(){n.drain()}):(l(t,function(t){var i={data:t,callback:o||r};e?n.tasks.unshift(i):n.tasks.push(i),n.tasks.length===n.concurrency&&n.saturated()}),I.setImmediate(n.process),void 0)}function i(n,t){return function(){u-=1;var e=!1,r=arguments;l(t,function(n){l(a,function(t,r){t!==n||e||(a.splice(r,1),e=!0)}),n.callback.apply(n,r)}),n.tasks.length+u===0&&n.drain(),n.process()}}if(null==t)t=1;else if(0===t)throw new Error("Concurrency must not be zero");var u=0,a=[],f={tasks:[],concurrency:t,payload:e,saturated:r,empty:r,drain:r,started:!1,paused:!1,push:function(n,t){o(f,n,!1,t)},kill:function(){f.drain=r,f.tasks=[]},unshift:function(n,t){o(f,n,!0,t)},process:function(){for(;!f.paused&&u<f.concurrency&&f.tasks.length;){var t=f.payload?f.tasks.splice(0,f.payload):f.tasks.splice(0,f.tasks.length),e=s(t,function(n){return n.data});0===f.tasks.length&&f.empty(),u+=1,a.push(t[0]);var r=c(i(f,t));n(e,r)}},length:function(){return f.tasks.length},running:function(){return u},workersList:function(){return a},idle:function(){return f.tasks.length+u===0},pause:function(){f.paused=!0},resume:function(){if(f.paused!==!1){f.paused=!1;for(var n=Math.min(f.concurrency,f.tasks.length),t=1;n>=t;t++)I.setImmediate(f.process)}}};return f}function L(n){return y(function(t,e){t.apply(null,e.concat([y(function(t,e){"object"==typeof console&&(t?console.error&&console.error(t):console[n]&&l(e,function(t){console[n](t)}))})]))})}function j(n){return function(t,e,r){n(p(t),e,r)}}function F(n){return y(function(t,e){var r=y(function(e){var r=this,o=e.pop();return n(t,function(n,t,o){n.apply(r,e.concat([o]))},o)});return e.length?r.apply(this,e):r})}function D(n){return y(function(t){var e=t.pop();t.push(function(){var n=arguments;r?I.setImmediate(function(){e.apply(null,n)}):e.apply(null,n)});var r=!0;n.apply(this,t),r=!1})}var q,I={},A="object"==typeof self&&self.self===self&&self||"object"==typeof e&&e.global===e&&e||this;null!=A&&(q=A.async),I.noConflict=function(){return A.async=q,I};var M=Object.prototype.toString,V=Array.isArray||function(n){return"[object Array]"===M.call(n)},U=function(n){var t=typeof n;return"function"===t||"object"===t&&!!n},T=Object.keys||function(n){var t=[];for(var e in n)n.hasOwnProperty(e)&&t.push(e);return t},B="function"==typeof setImmediate&&setImmediate,R=B?function(n){B(n)}:function(n){setTimeout(n,0)};I.nextTick="object"==typeof n&&"function"==typeof n.nextTick?n.nextTick:R,I.setImmediate=B?R:I.nextTick,I.forEach=I.each=function(n,t,e){return I.eachOf(n,g(t),e)},I.forEachSeries=I.eachSeries=function(n,t,e){return I.eachOfSeries(n,g(t),e)},I.forEachLimit=I.eachLimit=function(n,t,e,r){return O(t)(n,g(e),r)},I.forEachOf=I.eachOf=function(n,t,e){function o(n){f--,n?e(n):null===i&&0>=f&&e(null)}e=a(e||r),n=n||[];for(var i,u=v(n),f=0;null!=(i=u());)f+=1,t(n[i],i,c(o));0===f&&e(null)},I.forEachOfSeries=I.eachOfSeries=function(n,t,e){function o(){var r=!0;return null===u?e(null):(t(n[u],u,c(function(n){if(n)e(n);else{if(u=i(),null===u)return e(null);r?I.setImmediate(o):o()}})),r=!1,void 0)}e=a(e||r),n=n||[];var i=v(n),u=i();o()},I.forEachOfLimit=I.eachOfLimit=function(n,t,e,r){O(t)(n,e,r)},I.map=w(b),I.mapSeries=_(b),I.mapLimit=S(b),I.inject=I.foldl=I.reduce=function(n,t,e,r){I.eachOfSeries(n,function(n,r,o){e(t,n,function(n,e){t=e,o(n)})},function(n){r(n,t)})},I.foldr=I.reduceRight=function(n,t,e,r){var i=s(n,o).reverse();I.reduce(i,t,e,r)},I.transform=function(n,t,e,r){3===arguments.length&&(r=e,e=t,t=V(n)?[]:{}),I.eachOf(n,function(n,r,o){e(t,n,r,o)},function(n){r(n,t)})},I.select=I.filter=w(E),I.selectLimit=I.filterLimit=S(E),I.selectSeries=I.filterSeries=_(E),I.reject=w(x),I.rejectLimit=S(x),I.rejectSeries=_(x),I.any=I.some=k(I.eachOf,i,o),I.someLimit=k(I.eachOfLimit,i,o),I.all=I.every=k(I.eachOf,u,u),I.everyLimit=k(I.eachOfLimit,u,u),I.detect=k(I.eachOf,o,J),I.detectSeries=k(I.eachOfSeries,o,J),I.detectLimit=k(I.eachOfLimit,o,J),I.sortBy=function(n,t,e){function r(n,t){var e=n.criteria,r=t.criteria;return r>e?-1:e>r?1:0}I.map(n,function(n,e){t(n,function(t,r){t?e(t):e(null,{value:n,criteria:r})})},function(n,t){return n?e(n):(e(null,s(t.sort(r),function(n){return n.value})),void 0)})},I.auto=function(n,t,e){function o(n){g.unshift(n)}function i(n){var t=m(g,n);t>=0&&g.splice(t,1)}function u(){f--,l(g.slice(0),function(n){n()})}"function"==typeof arguments[1]&&(e=t,t=null),e=a(e||r);var c=T(n),f=c.length;if(!f)return e(null);t||(t=f);var s={},p=0,v=!1,g=[];o(function(){f||e(null,s)}),l(c,function(r){function c(){return t>p&&h(O,function(n,t){return n&&s.hasOwnProperty(t)},!0)&&!s.hasOwnProperty(r)}function a(){c()&&(p++,i(a),l[l.length-1](g,s))}if(!v){for(var f,l=V(n[r])?n[r]:[n[r]],g=y(function(n,t){if(p--,t.length<=1&&(t=t[0]),n){var o={};d(s,function(n,t){o[t]=n}),o[r]=t,v=!0,e(n,o)}else s[r]=t,I.setImmediate(u)}),O=l.slice(0,l.length-1),w=O.length;w--;){if(!(f=n[O[w]]))throw new Error("Has nonexistent dependency in "+O.join(", "));if(V(f)&&m(f,r)>=0)throw new Error("Has cyclic dependencies")}c()?(p++,l[l.length-1](g,s)):o(a)}})},I.retry=function(n,t,e){function r(n,t){if("number"==typeof t)n.times=parseInt(t,10)||i;else{if("object"!=typeof t)throw new Error("Unsupported argument type for 'times': "+typeof t);n.times=parseInt(t.times,10)||i,n.interval=parseInt(t.interval,10)||u}}function o(n,t){function e(n,e){return function(r){n(function(n,t){r(!n||e,{err:n,result:t})
},t)}}function r(n){return function(t){setTimeout(function(){t(null)},n)}}for(;a.times;){var o=!(a.times-=1);c.push(e(a.task,o)),!o&&a.interval>0&&c.push(r(a.interval))}I.series(c,function(t,e){e=e[e.length-1],(n||a.callback)(e.err,e.result)})}var i=5,u=0,c=[],a={times:i,interval:u},f=arguments.length;if(1>f||f>3)throw new Error("Invalid arguments - must be either (task), (task, callback), (times, task) or (times, task, callback)");return 2>=f&&"function"==typeof n&&(e=t,t=n),"function"!=typeof n&&r(a,n),a.callback=e,a.task=t,a.callback?o():o},I.waterfall=function(n,t){function e(n){return y(function(r,o){if(r)t.apply(null,[r].concat(o));else{var i=n.next();i?o.push(e(i)):o.push(t),D(n).apply(null,o)}})}if(t=a(t||r),!V(n)){var o=new Error("First argument to waterfall must be an array of functions");return t(o)}return n.length?(e(I.iterator(n))(),void 0):t()},I.parallel=function(n,t){C(I.eachOf,n,t)},I.parallelLimit=function(n,t,e){C(O(t),n,e)},I.series=function(n,t){C(I.eachOfSeries,n,t)},I.iterator=function(n){function t(e){function r(){return n.length&&n[e].apply(null,arguments),r.next()}return r.next=function(){return e<n.length-1?t(e+1):null},r}return t(0)},I.apply=y(function(n,t){return y(function(e){return n.apply(null,t.concat(e))})}),I.concat=w(N),I.concatSeries=_(N),I.whilst=function(n,t,e){if(e=e||r,n()){var o=y(function(r,i){r?e(r):n.apply(this,i)?t(o):e.apply(null,[null].concat(i))});t(o)}else e(null)},I.doWhilst=function(n,t,e){var r=0;return I.whilst(function(){return++r<=1||t.apply(this,arguments)},n,e)},I.until=function(n,t,e){return I.whilst(function(){return!n.apply(this,arguments)},t,e)},I.doUntil=function(n,t,e){return I.doWhilst(n,function(){return!t.apply(this,arguments)},e)},I.during=function(n,t,e){e=e||r;var o=y(function(t,r){t?e(t):(r.push(i),n.apply(this,r))}),i=function(n,r){n?e(n):r?t(o):e(null)};n(i)},I.doDuring=function(n,t,e){var r=0;I.during(function(n){r++<1?n(null,!0):t.apply(this,arguments)},n,e)},I.queue=function(n,t){var e=$(function(t,e){n(t[0],e)},t,1);return e},I.priorityQueue=function(n,t){function e(n,t){return n.priority-t.priority}function o(n,t,e){for(var r=-1,o=n.length-1;o>r;){var i=r+(o-r+1>>>1);e(t,n[i])>=0?r=i:o=i-1}return r}function i(n,t,i,u){if(null!=u&&"function"!=typeof u)throw new Error("task callback must be a function");return n.started=!0,V(t)||(t=[t]),0===t.length?I.setImmediate(function(){n.drain()}):(l(t,function(t){var c={data:t,priority:i,callback:"function"==typeof u?u:r};n.tasks.splice(o(n.tasks,c,e)+1,0,c),n.tasks.length===n.concurrency&&n.saturated(),I.setImmediate(n.process)}),void 0)}var u=I.queue(n,t);return u.push=function(n,t,e){i(u,n,t,e)},delete u.unshift,u},I.cargo=function(n,t){return $(n,1,t)},I.log=L("log"),I.dir=L("dir"),I.memoize=function(n,t){var e={},r={},i=Object.prototype.hasOwnProperty;t=t||o;var u=y(function(o){var u=o.pop(),c=t.apply(null,o);i.call(e,c)?I.setImmediate(function(){u.apply(null,e[c])}):i.call(r,c)?r[c].push(u):(r[c]=[u],n.apply(null,o.concat([y(function(n){e[c]=n;var t=r[c];delete r[c];for(var o=0,i=t.length;i>o;o++)t[o].apply(null,n)})])))});return u.memo=e,u.unmemoized=n,u},I.unmemoize=function(n){return function(){return(n.unmemoized||n).apply(null,arguments)}},I.times=j(I.map),I.timesSeries=j(I.mapSeries),I.timesLimit=function(n,t,e,r){return I.mapLimit(p(n),t,e,r)},I.seq=function(){var n=arguments;return y(function(t){var e=this,o=t[t.length-1];"function"==typeof o?t.pop():o=r,I.reduce(n,t,function(n,t,r){t.apply(e,n.concat([y(function(n,t){r(n,t)})]))},function(n,t){o.apply(e,[n].concat(t))})})},I.compose=function(){return I.seq.apply(null,Array.prototype.reverse.call(arguments))},I.applyEach=F(I.eachOf),I.applyEachSeries=F(I.eachOfSeries),I.forever=function(n,t){function e(n){return n?o(n):(i(e),void 0)}var o=c(t||r),i=D(n);e()},I.ensureAsync=D,I.constant=y(function(n){var t=[null].concat(n);return function(n){return n.apply(this,t)}}),I.wrapSync=I.asyncify=function(n){return y(function(t){var e,r=t.pop();try{e=n.apply(this,t)}catch(o){return r(o)}U(e)&&"function"==typeof e.then?e.then(function(n){r(null,n)})["catch"](function(n){r(n.message?n:new Error(n))}):r(null,e)})},"object"==typeof t&&t.exports?t.exports=I:"function"==typeof define&&define.amd?define([],function(){return I}):A.async=I}()}).call(this,n("g5I+bs"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"g5I+bs":13}],13:[function(n,t){function e(){}var r=t.exports={};r.nextTick=function(){var n="undefined"!=typeof window&&window.setImmediate,t="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(n)return function(n){return window.setImmediate(n)};if(t){var e=[];return window.addEventListener("message",function(n){var t=n.source;if((t===window||null===t)&&"process-tick"===n.data&&(n.stopPropagation(),e.length>0)){var r=e.shift();r()}},!0),function(n){e.push(n),window.postMessage("process-tick","*")}}return function(n){setTimeout(n,0)}}(),r.title="browser",r.browser=!0,r.env={},r.argv=[],r.on=e,r.addListener=e,r.once=e,r.off=e,r.removeListener=e,r.removeAllListeners=e,r.emit=e,r.binding=function(){throw new Error("process.binding is not supported")},r.cwd=function(){return"/"},r.chdir=function(){throw new Error("process.chdir is not supported")}},{}]},{},[]);