diff --git a/build/marsdb.js b/build/marsdb.js index 4d4fb4f..72abfd0 100644 --- a/build/marsdb.js +++ b/build/marsdb.js @@ -427,19 +427,22 @@ var _defaultIdGenerator = _ShortIdGenerator2.default; // the second execution cycle var _startedUp = false; var _startUpQueue = []; -var _startUpTimeout = 0; +var _startUpId = 0; // Internals function _resetStartup() { - clearTimeout(_startUpTimeout); + _startUpId += 1; _startUpQueue = []; _startedUp = false; - _startUpTimeout = setTimeout(function () { - _startedUp = true; - (0, _forEach2.default)(_startUpQueue, function (fn) { - return fn(); - }); - _startUpQueue = []; + var currStartId = _startUpId; + setTimeout(function () { + if (currStartId === _startUpId) { + _startedUp = true; + (0, _forEach2.default)(_startUpQueue, function (fn) { + return fn(); + }); + _startUpQueue = []; + } }, 0); } @@ -1763,7 +1766,6 @@ var CursorObservable = function (_Cursor) { var insertedInResult = updatedInResult || newDoc && !oldDoc && this._matcher.documentMatches(newDoc).result; if (insertedInResult) { - this.emit('cursorChanged'); return this.update(); } } @@ -1812,6 +1814,10 @@ var CursorObservable = function (_Cursor) { var firstRun = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0]; + if (!firstRun) { + this.emit('cursorChanged'); + } + return this.exec().then(function (result) { _this3._updateLatestIds(); return _this3._propagateUpdate(firstRun).then(function () { diff --git a/build/marsdb.min.js b/build/marsdb.min.js index d6be3f0..3844093 100644 --- a/build/marsdb.min.js +++ b/build/marsdb.min.js @@ -1,4 +1,4 @@ -!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.Mars=e()}}(function(){var e;return function t(e,n,r){function o(u,a){if(!n[u]){if(!e[u]){var s="function"==typeof require&&require;if(!a&&s)return s(u,!0);if(i)return i(u,!0);var f=new Error("Cannot find module '"+u+"'");throw f.code="MODULE_NOT_FOUND",f}var c=n[u]={exports:{}};e[u][0].call(c.exports,function(t){var n=e[u][1][t];return o(n?n:t)},c,c.exports,t,e,n,r)}return n[u].exports}for(var i="function"==typeof require&&require,u=0;us;s++)d[s-1]=arguments[s];return Promise.resolve(f.fn.apply(f.context,d))}var h=[],p=f.length,y=void 0;for(s=0;p>s;s++)switch(f[s].once&&this.removeListener(e,f[s].fn,void 0,!0),l){case 1:h.push(Promise.resolve(f[s].fn.call(f[s].context)));break;case 2:h.push(Promise.resolve(f[s].fn.call(f[s].context,t)));break;case 3:h.push(Promise.resolve(f[s].fn.call(f[s].context,t,n)));break;default:if(!d)for(y=1,d=new Array(l-1);l>y;y++)d[y-1]=arguments[y];h.push(Promise.resolve(f[s].fn.apply(f[s].context,d)))}return Promise.all(h)}}]),t}(c["default"]);n["default"]=l},{eventemitter3:34}],2:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var n=0;n255)throw new Error("Not ascii. Base64.encode can only take ascii strings.");e[n]=r}}for(var o=[],i=null,u=null,s=null,f=null,n=0;n>2&63,u=(3&e[n])<<4;break;case 1:u|=e[n]>>4&15,s=(15&e[n])<<2;break;case 2:s|=e[n]>>6&3,f=63&e[n],o.push(a(i)),o.push(a(u)),o.push(a(s)),o.push(a(f)),i=null,u=null,s=null,f=null}return null!=i&&(o.push(a(i)),o.push(a(u)),null==s?o.push("="):o.push(a(s)),null==f&&o.push("=")),o.join("")}},{key:"decode",value:function(e){var t=Math.floor(3*e.length/4);"="==e.charAt(e.length-1)&&(t--,"="==e.charAt(e.length-2)&&t--);for(var n=this.newBinary(t),r=null,o=null,i=null,u=0,a=0;ac)throw new Error("invalid base64 string");r=c<<2;break;case 1:if(0>c)throw new Error("invalid base64 string");r|=c>>4,n[u++]=r,o=(15&c)<<4;break;case 2:c>=0&&(o|=c>>2,n[u++]=o,i=(3&c)<<6);break;case 3:c>=0&&(n[u++]=i|c)}}return n}},{key:"newBinary",value:function(e){if("undefined"==typeof Uint8Array||"undefined"==typeof ArrayBuffer){for(var t=[],n=0;e>n;n++)t.push(0);return t.$Uint8ArrayPolyfill=!0,t}return new Uint8Array(new ArrayBuffer(e))}}]),e}();n["default"]=new f},{}],3:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!==("undefined"==typeof t?"undefined":f(t))&&"function"!=typeof t?e:t}function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+("undefined"==typeof t?"undefined":f(t)));e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function a(){clearTimeout(B),q=[],J=!1,B=setTimeout(function(){J=!0,(0,p["default"])(q,function(e){return e()}),q=[]},0)}function s(){J&&console.warn("You are trying to change some default of the Collection,but all collections is already initialized. It may be happened because you are trying to configure Collection not at first execution cycle of main script. Please consider to move all configuration to first execution cycle.")}var f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},c=function(){function e(e,t){for(var n=0;n0?(s(),void($=arguments[0])):$}},{key:"defaultStorageManager",value:function(){return arguments.length>0?(s(),void(T=arguments[0])):T}},{key:"defaultIdGenerator",value:function(){return arguments.length>0?(s(),void(R=arguments[0])):R}},{key:"defaultDelegate",value:function(){return arguments.length>0?(s(),void(N=arguments[0])):N}},{key:"defaultIndexManager",value:function(){return arguments.length>0?(s(),void(D=arguments[0])):D}},{key:"startup",value:function(e){J?e():q.push(e)}}]),t}(g["default"]);n["default"]=V},{"./AsyncEventEmitter":1,"./CollectionDelegate":4,"./CursorObservable":7,"./EJSON":14,"./IndexManager":15,"./PromiseQueue":16,"./ShortIdGenerator":18,"./StorageManager":19,"check-types":32,"fast.js/forEach":42,"fast.js/map":49}],4:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t1&&!a&&(e=[e[0]]);var t=(0,s["default"])(e,function(e){return n.db.storageManager["delete"](e._id)}),r=(0,s["default"])(e,function(e){return n.db.indexManager.deindexDocument(e)});return Promise.all([].concat(o(t),o(r))).then(function(){return e})})}},{key:"update",value:function(e,t,n){var r=this,i=n.sort,u=void 0===i?{_id:1}:i,a=n.multi,f=void 0===a?!1:a,l=n.upsert,d=void 0===l?!1:l;return this.find(e,{noClone:!0}).sort(u).then(function(n){return n.length>1&&!f&&(n=[n[0]]),new c["default"](e).modify(n,t,{upsert:d})}).then(function(e){var t=e.original,n=e.updated,i=(0,s["default"])(n,function(e){return r.db.storageManager.persist(e._id,e)}),u=(0,s["default"])(n,function(e,n){return r.db.indexManager.reindexDocument(t[n],e)});return Promise.all([].concat(o(i),o(u))).then(function(){return{modified:n.length,original:t,updated:n}})})}},{key:"find",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],n=this.db.cursorClass;return new n(this.db,e,t)}},{key:"findOne",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];return this.find(e,t).aggregate(function(e){return e[0]}).limit(1)}},{key:"count",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];return t.noClone=!0,this.find(e,t).aggregate(function(e){return e.length})}},{key:"ids",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];return t.noClone=!0,this.find(e,t).map(function(e){return e._id})}}]),e}();n["default"]=l},{"./DocumentModifier":10,"fast.js/map":49}],5:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,t){for(var n=0;n=0||"undefined"==typeof e,"skip(...): skip must be a positive number"),this._skip=e,this}},{key:"limit",value:function(e){return(0,w["default"])(e>=0||"undefined"==typeof e,"limit(...): limit must be a positive number"),this._limit=e,this}},{key:"find",value:function(e){return this._query=e,this._ensureMatcherSorter(),this}},{key:"project",value:function(e){return e?this._projector=new A["default"](e):this._projector=null,this}},{key:"sort",value:function(e){return(0,w["default"])("object"===("undefined"==typeof e?"undefined":s(e))||"undefined"==typeof e||Array.isArray(e),"sort(...): argument must be an object"),this._sort=e,this._ensureMatcherSorter(),this}},{key:"exec",value:function(){var e=this;return this.emit("beforeExecute"),this._createCursorPromise(this._doExecute().then(function(t){return e._latestResult=t,t}))}},{key:"then",value:function(e,t){return this.exec().then(e,t)}},{key:"_addPipeline",value:function(e,t){(0,w["default"])(e&&N[e],"Unknown pipeline processor type %s",e);for(var n=arguments.length,r=Array(n>2?n-2:0),o=2;n>o;o++)r[o-2]=arguments[o];return this._pipeline.push({type:e,value:t,args:r||[]}),this}},{key:"_processPipeline",value:function(e){var t=this,n=arguments.length<=1||void 0===arguments[1]?0:arguments[1],r=this._pipeline[n];return r?Promise.resolve(N[r.type].process(e,r,this)).then(function(e){return"___[STOP]___"===e?e:t._processPipeline(e,n+1)}):Promise.resolve(e)}},{key:"_doExecute",value:function(){var e=this;return this._matchObjects().then(function(t){var n=void 0;return n=e.options.noClone?t:e._projector?e._projector.project(t):(0,g["default"])(t,function(e){return C["default"].clone(e)}),e._processPipeline(n)})}},{key:"_matchObjects",value:function(){var e=this;return new E["default"](this.db).retriveForQeury(this._query).then(function(t){var n=[],r=e._limit&&!e._skip&&!e._sorter;if((0,d["default"])(t,function(t){var o=e._matcher.documentMatches(t);return o.result&&n.push(t),r&&n.length===e._limit?!1:void 0}),r)return n;if(e._sorter){var o=e._sorter.getComparator();n.sort(o)}var i=e._skip||0,u=e._limit||n.length;return n.slice(i,u+i)})}},{key:"_ensureMatcherSorter",value:function(){this._sorter=void 0,this._matcher=new k["default"](this._query||{}),(this._matcher.hasGeoQuery||this._sort)&&(this._sorter=new M["default"](this._sort||[],{matcher:this._matcher}))}},{key:"_trackChildCursorPromise",value:function(e){var t=this,n=e.cursor;this._childrenCursors[n._id]=n,n._parentCursors[this._id]=this,this.once("beforeExecute",function(){delete t._childrenCursors[n._id],delete n._parentCursors[t._id],0===(0,v["default"])(n._parentCursors).length&&n.emit("beforeExecute")})}},{key:"_createCursorPromise",value:function(e){var t=this,n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];return(0,p["default"])({cursor:this,then:function(r,o){return t._createCursorPromise(e.then(r,o),n)}},n)}}]),t}(T);n.Cursor=D,n["default"]=D},{"./AsyncEventEmitter":1,"./DocumentMatcher":9,"./DocumentProjector":11,"./DocumentRetriver":12,"./DocumentSorter":13,"./EJSON":14,"./cursor-processors/aggregate":20,"./cursor-processors/filter":21,"./cursor-processors/ifNotEmpty":22,"./cursor-processors/join":23,"./cursor-processors/joinAll":24,"./cursor-processors/joinEach":25,"./cursor-processors/joinObj":26,"./cursor-processors/map":27,"./cursor-processors/reduce":28,"./cursor-processors/sortFunc":29,"fast.js/forEach":42,"fast.js/map":49,"fast.js/object/assign":50,"fast.js/object/keys":52,invariant:56}],7:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!==("undefined"==typeof t?"undefined":a(t))&&"function"!=typeof t?e:t}function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+("undefined"==typeof t?"undefined":a(t)));e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},s=function(){function e(e,t){for(var n=0;n0?void(k=arguments[0]):k}},{key:"defaultBatchSize",value:function(){return arguments.length>0?void(S=arguments[0]):S}}]),t}(b["default"]);n.CursorObservable=M,n["default"]=M},{"./Cursor":6,"./EJSON":14,"./PromiseQueue":16,"./debounce":30,"check-types":32,"fast.js/function/bind":45,"fast.js/map":49,"fast.js/object/values":54}],8:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e){return d["default"].string(e)||d["default"].number(e)}function i(e){return o(e)||e&&d["default"].object(e)&&e._id&&o(e._id)&&1===(0,v["default"])(e).length}function u(e){return d["default"].array(e)&&!g["default"].isBinary(e)}function a(e){return e&&3===b._type(e)}function s(e){return u(e)||a(e)}function f(e,t){if(!a(e))return!1;var n=void 0;return(0,p["default"])(e,function(r,o){var i="$"===o.substr(0,1);if(void 0===n)n=i;else if(n!==i){if(!t)throw new Error("Inconsistent operator: "+JSON.stringify(e));n=!1}}),!!n}function c(e){return/^[0-9]+$/.test(e)}Object.defineProperty(n,"__esModule",{value:!0}),n.MongoTypeComp=void 0,n.selectorIsId=o,n.selectorIsIdPerhapsAsObject=i,n.isArray=u,n.isPlainObject=a,n.isIndexable=s,n.isOperatorObject=f,n.isNumericKey=c;var l=e("check-types"),d=r(l),h=e("fast.js/forEach"),p=r(h),y=e("fast.js/object/keys"),v=r(y),m=e("./EJSON"),g=r(m),b=n.MongoTypeComp={_type:function(e){return"number"==typeof e?1:"string"==typeof e?2:"boolean"==typeof e?8:u(e)?4:null===e?10:e instanceof RegExp?11:"function"==typeof e?13:e instanceof Date?9:g["default"].isBinary(e)?5:3},_equal:function(e,t){return g["default"].equals(e,t,{keyOrderSensitive:!0})},_typeorder:function(e){return[-1,1,2,3,4,5,-1,6,7,8,0,9,-1,100,2,100,1,8,1][e]},_cmp:function(e,t){if(void 0===e)return void 0===t?0:-1;if(void 0===t)return 1;var n=b._type(e),r=b._type(t),o=b._typeorder(n),i=b._typeorder(r);if(o!==i)return i>o?-1:1;if(n!==r)throw Error("Missing type coercion logic in _cmp");if(7===n&&(n=r=2,e=e.toHexString(),t=t.toHexString()),9===n&&(n=r=1,e=e.getTime(),t=t.getTime()),1===n)return e-t;if(2===r)return t>e?-1:e===t?0:1;if(3===n){var u=function(e){var t=[];for(var n in e)t.push(n),t.push(e[n]);return t};return b._cmp(u(e),u(t))}if(4===n)for(var a=0;;a++){if(a===e.length)return a===t.length?0:-1;if(a===t.length)return 1;var s=b._cmp(e[a],t[a]);if(0!==s)return s}if(5===n){if(e.length!==t.length)return e.length-t.length;for(a=0;at[a])return 1}return 0}if(8===n)return e?t?0:1:t?-1:0;if(10===n)return 0;if(11===n)throw Error("Sorting not supported on regular expression");if(13===n)throw Error("Sorting not supported on Javascript code");throw Error("Unknown type to sort")}}},{"./EJSON":14,"check-types":32,"fast.js/forEach":42,"fast.js/object/keys":52}],9:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e){return function(t){return t instanceof RegExp?String(t)===String(e):"string"!=typeof t?!1:(e.lastIndex=0,e.test(t))}}function u(e){if((0,A.isOperatorObject)(e))throw Error("Can't create equalityValueSelector for operator object");return null==e?function(e){return null==e}:function(t){return A.MongoTypeComp._equal(e,t)}}function a(e,t){t=t||{};var n,r=e.split("."),o=r.length?r[0]:"",i=(0,A.isNumericKey)(o),u=r.length>=2&&(0,A.isNumericKey)(r[1]);r.length>1&&(n=a(r.slice(1).join(".")));var s=function(e){return e.dontIterate||delete e.dontIterate,e.arrayIndices&&!e.arrayIndices.length&&delete e.arrayIndices,e};return function(e,r){if(r||(r=[]),(0,A.isArray)(e)){if(!(i&&os;s++)d[s-1]=arguments[s];return Promise.resolve(f.fn.apply(f.context,d))}var h=[],p=f.length,y=void 0;for(s=0;p>s;s++)switch(f[s].once&&this.removeListener(e,f[s].fn,void 0,!0),l){case 1:h.push(Promise.resolve(f[s].fn.call(f[s].context)));break;case 2:h.push(Promise.resolve(f[s].fn.call(f[s].context,t)));break;case 3:h.push(Promise.resolve(f[s].fn.call(f[s].context,t,n)));break;default:if(!d)for(y=1,d=new Array(l-1);l>y;y++)d[y-1]=arguments[y];h.push(Promise.resolve(f[s].fn.apply(f[s].context,d)))}return Promise.all(h)}}]),t}(c["default"]);n["default"]=l},{eventemitter3:34}],2:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var n=0;n255)throw new Error("Not ascii. Base64.encode can only take ascii strings.");e[n]=r}}for(var o=[],i=null,u=null,s=null,f=null,n=0;n>2&63,u=(3&e[n])<<4;break;case 1:u|=e[n]>>4&15,s=(15&e[n])<<2;break;case 2:s|=e[n]>>6&3,f=63&e[n],o.push(a(i)),o.push(a(u)),o.push(a(s)),o.push(a(f)),i=null,u=null,s=null,f=null}return null!=i&&(o.push(a(i)),o.push(a(u)),null==s?o.push("="):o.push(a(s)),null==f&&o.push("=")),o.join("")}},{key:"decode",value:function(e){var t=Math.floor(3*e.length/4);"="==e.charAt(e.length-1)&&(t--,"="==e.charAt(e.length-2)&&t--);for(var n=this.newBinary(t),r=null,o=null,i=null,u=0,a=0;ac)throw new Error("invalid base64 string");r=c<<2;break;case 1:if(0>c)throw new Error("invalid base64 string");r|=c>>4,n[u++]=r,o=(15&c)<<4;break;case 2:c>=0&&(o|=c>>2,n[u++]=o,i=(3&c)<<6);break;case 3:c>=0&&(n[u++]=i|c)}}return n}},{key:"newBinary",value:function(e){if("undefined"==typeof Uint8Array||"undefined"==typeof ArrayBuffer){for(var t=[],n=0;e>n;n++)t.push(0);return t.$Uint8ArrayPolyfill=!0,t}return new Uint8Array(new ArrayBuffer(e))}}]),e}();n["default"]=new f},{}],3:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!==("undefined"==typeof t?"undefined":f(t))&&"function"!=typeof t?e:t}function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+("undefined"==typeof t?"undefined":f(t)));e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function a(){B+=1,q=[],J=!1;var e=B;setTimeout(function(){e===B&&(J=!0,(0,p["default"])(q,function(e){return e()}),q=[])},0)}function s(){J&&console.warn("You are trying to change some default of the Collection,but all collections is already initialized. It may be happened because you are trying to configure Collection not at first execution cycle of main script. Please consider to move all configuration to first execution cycle.")}var f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},c=function(){function e(e,t){for(var n=0;n0?(s(),void($=arguments[0])):$}},{key:"defaultStorageManager",value:function(){return arguments.length>0?(s(),void(T=arguments[0])):T}},{key:"defaultIdGenerator",value:function(){return arguments.length>0?(s(),void(R=arguments[0])):R}},{key:"defaultDelegate",value:function(){return arguments.length>0?(s(),void(N=arguments[0])):N}},{key:"defaultIndexManager",value:function(){return arguments.length>0?(s(),void(D=arguments[0])):D}},{key:"startup",value:function(e){J?e():q.push(e)}}]),t}(g["default"]);n["default"]=V},{"./AsyncEventEmitter":1,"./CollectionDelegate":4,"./CursorObservable":7,"./EJSON":14,"./IndexManager":15,"./PromiseQueue":16,"./ShortIdGenerator":18,"./StorageManager":19,"check-types":32,"fast.js/forEach":42,"fast.js/map":49}],4:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t1&&!a&&(e=[e[0]]);var t=(0,s["default"])(e,function(e){return n.db.storageManager["delete"](e._id)}),r=(0,s["default"])(e,function(e){return n.db.indexManager.deindexDocument(e)});return Promise.all([].concat(o(t),o(r))).then(function(){return e})})}},{key:"update",value:function(e,t,n){var r=this,i=n.sort,u=void 0===i?{_id:1}:i,a=n.multi,f=void 0===a?!1:a,l=n.upsert,d=void 0===l?!1:l;return this.find(e,{noClone:!0}).sort(u).then(function(n){return n.length>1&&!f&&(n=[n[0]]),new c["default"](e).modify(n,t,{upsert:d})}).then(function(e){var t=e.original,n=e.updated,i=(0,s["default"])(n,function(e){return r.db.storageManager.persist(e._id,e)}),u=(0,s["default"])(n,function(e,n){return r.db.indexManager.reindexDocument(t[n],e)});return Promise.all([].concat(o(i),o(u))).then(function(){return{modified:n.length,original:t,updated:n}})})}},{key:"find",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],n=this.db.cursorClass;return new n(this.db,e,t)}},{key:"findOne",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];return this.find(e,t).aggregate(function(e){return e[0]}).limit(1)}},{key:"count",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];return t.noClone=!0,this.find(e,t).aggregate(function(e){return e.length})}},{key:"ids",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];return t.noClone=!0,this.find(e,t).map(function(e){return e._id})}}]),e}();n["default"]=l},{"./DocumentModifier":10,"fast.js/map":49}],5:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,t){for(var n=0;n=0||"undefined"==typeof e,"skip(...): skip must be a positive number"),this._skip=e,this}},{key:"limit",value:function(e){return(0,w["default"])(e>=0||"undefined"==typeof e,"limit(...): limit must be a positive number"),this._limit=e,this}},{key:"find",value:function(e){return this._query=e,this._ensureMatcherSorter(),this}},{key:"project",value:function(e){return e?this._projector=new A["default"](e):this._projector=null,this}},{key:"sort",value:function(e){return(0,w["default"])("object"===("undefined"==typeof e?"undefined":s(e))||"undefined"==typeof e||Array.isArray(e),"sort(...): argument must be an object"),this._sort=e,this._ensureMatcherSorter(),this}},{key:"exec",value:function(){var e=this;return this.emit("beforeExecute"),this._createCursorPromise(this._doExecute().then(function(t){return e._latestResult=t,t}))}},{key:"then",value:function(e,t){return this.exec().then(e,t)}},{key:"_addPipeline",value:function(e,t){(0,w["default"])(e&&N[e],"Unknown pipeline processor type %s",e);for(var n=arguments.length,r=Array(n>2?n-2:0),o=2;n>o;o++)r[o-2]=arguments[o];return this._pipeline.push({type:e,value:t,args:r||[]}),this}},{key:"_processPipeline",value:function(e){var t=this,n=arguments.length<=1||void 0===arguments[1]?0:arguments[1],r=this._pipeline[n];return r?Promise.resolve(N[r.type].process(e,r,this)).then(function(e){return"___[STOP]___"===e?e:t._processPipeline(e,n+1)}):Promise.resolve(e)}},{key:"_doExecute",value:function(){var e=this;return this._matchObjects().then(function(t){var n=void 0;return n=e.options.noClone?t:e._projector?e._projector.project(t):(0,g["default"])(t,function(e){return C["default"].clone(e)}),e._processPipeline(n)})}},{key:"_matchObjects",value:function(){var e=this;return new E["default"](this.db).retriveForQeury(this._query).then(function(t){var n=[],r=e._limit&&!e._skip&&!e._sorter;if((0,d["default"])(t,function(t){var o=e._matcher.documentMatches(t);return o.result&&n.push(t),r&&n.length===e._limit?!1:void 0}),r)return n;if(e._sorter){var o=e._sorter.getComparator();n.sort(o)}var i=e._skip||0,u=e._limit||n.length;return n.slice(i,u+i)})}},{key:"_ensureMatcherSorter",value:function(){this._sorter=void 0,this._matcher=new k["default"](this._query||{}),(this._matcher.hasGeoQuery||this._sort)&&(this._sorter=new M["default"](this._sort||[],{matcher:this._matcher}))}},{key:"_trackChildCursorPromise",value:function(e){var t=this,n=e.cursor;this._childrenCursors[n._id]=n,n._parentCursors[this._id]=this,this.once("beforeExecute",function(){delete t._childrenCursors[n._id],delete n._parentCursors[t._id],0===(0,v["default"])(n._parentCursors).length&&n.emit("beforeExecute")})}},{key:"_createCursorPromise",value:function(e){var t=this,n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];return(0,p["default"])({cursor:this,then:function(r,o){return t._createCursorPromise(e.then(r,o),n)}},n)}}]),t}(T);n.Cursor=D,n["default"]=D},{"./AsyncEventEmitter":1,"./DocumentMatcher":9,"./DocumentProjector":11,"./DocumentRetriver":12,"./DocumentSorter":13,"./EJSON":14,"./cursor-processors/aggregate":20,"./cursor-processors/filter":21,"./cursor-processors/ifNotEmpty":22,"./cursor-processors/join":23,"./cursor-processors/joinAll":24,"./cursor-processors/joinEach":25,"./cursor-processors/joinObj":26,"./cursor-processors/map":27,"./cursor-processors/reduce":28,"./cursor-processors/sortFunc":29,"fast.js/forEach":42,"fast.js/map":49,"fast.js/object/assign":50,"fast.js/object/keys":52,invariant:56}],7:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!==("undefined"==typeof t?"undefined":a(t))&&"function"!=typeof t?e:t}function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+("undefined"==typeof t?"undefined":a(t)));e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},s=function(){function e(e,t){for(var n=0;n0?void(k=arguments[0]):k}},{key:"defaultBatchSize",value:function(){return arguments.length>0?void(S=arguments[0]):S}}]),t}(b["default"]);n.CursorObservable=M,n["default"]=M},{"./Cursor":6,"./EJSON":14,"./PromiseQueue":16,"./debounce":30,"check-types":32,"fast.js/function/bind":45,"fast.js/map":49,"fast.js/object/values":54}],8:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e){return d["default"].string(e)||d["default"].number(e)}function i(e){return o(e)||e&&d["default"].object(e)&&e._id&&o(e._id)&&1===(0,v["default"])(e).length}function u(e){return d["default"].array(e)&&!g["default"].isBinary(e)}function a(e){return e&&3===b._type(e)}function s(e){return u(e)||a(e)}function f(e,t){if(!a(e))return!1;var n=void 0;return(0,p["default"])(e,function(r,o){var i="$"===o.substr(0,1);if(void 0===n)n=i;else if(n!==i){if(!t)throw new Error("Inconsistent operator: "+JSON.stringify(e));n=!1}}),!!n}function c(e){return/^[0-9]+$/.test(e)}Object.defineProperty(n,"__esModule",{value:!0}),n.MongoTypeComp=void 0,n.selectorIsId=o,n.selectorIsIdPerhapsAsObject=i,n.isArray=u,n.isPlainObject=a,n.isIndexable=s,n.isOperatorObject=f,n.isNumericKey=c;var l=e("check-types"),d=r(l),h=e("fast.js/forEach"),p=r(h),y=e("fast.js/object/keys"),v=r(y),m=e("./EJSON"),g=r(m),b=n.MongoTypeComp={_type:function(e){return"number"==typeof e?1:"string"==typeof e?2:"boolean"==typeof e?8:u(e)?4:null===e?10:e instanceof RegExp?11:"function"==typeof e?13:e instanceof Date?9:g["default"].isBinary(e)?5:3},_equal:function(e,t){return g["default"].equals(e,t,{keyOrderSensitive:!0})},_typeorder:function(e){return[-1,1,2,3,4,5,-1,6,7,8,0,9,-1,100,2,100,1,8,1][e]},_cmp:function(e,t){if(void 0===e)return void 0===t?0:-1;if(void 0===t)return 1;var n=b._type(e),r=b._type(t),o=b._typeorder(n),i=b._typeorder(r);if(o!==i)return i>o?-1:1;if(n!==r)throw Error("Missing type coercion logic in _cmp");if(7===n&&(n=r=2,e=e.toHexString(),t=t.toHexString()),9===n&&(n=r=1,e=e.getTime(),t=t.getTime()),1===n)return e-t;if(2===r)return t>e?-1:e===t?0:1;if(3===n){var u=function(e){var t=[];for(var n in e)t.push(n),t.push(e[n]);return t};return b._cmp(u(e),u(t))}if(4===n)for(var a=0;;a++){if(a===e.length)return a===t.length?0:-1;if(a===t.length)return 1;var s=b._cmp(e[a],t[a]);if(0!==s)return s}if(5===n){if(e.length!==t.length)return e.length-t.length;for(a=0;at[a])return 1}return 0}if(8===n)return e?t?0:1:t?-1:0;if(10===n)return 0;if(11===n)throw Error("Sorting not supported on regular expression");if(13===n)throw Error("Sorting not supported on Javascript code");throw Error("Unknown type to sort")}}},{"./EJSON":14,"check-types":32,"fast.js/forEach":42,"fast.js/object/keys":52}],9:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e){return function(t){return t instanceof RegExp?String(t)===String(e):"string"!=typeof t?!1:(e.lastIndex=0,e.test(t))}}function u(e){if((0,A.isOperatorObject)(e))throw Error("Can't create equalityValueSelector for operator object");return null==e?function(e){return null==e}:function(t){return A.MongoTypeComp._equal(e,t)}}function a(e,t){t=t||{};var n,r=e.split("."),o=r.length?r[0]:"",i=(0,A.isNumericKey)(o),u=r.length>=2&&(0,A.isNumericKey)(r[1]);r.length>1&&(n=a(r.slice(1).join(".")));var s=function(e){return e.dontIterate||delete e.dontIterate,e.arrayIndices&&!e.arrayIndices.length&&delete e.arrayIndices,e};return function(e,r){if(r||(r=[]),(0,A.isArray)(e)){if(!(i&&o=0&&h["default"].number(o),a="$ne"===i&&!h["default"].object(o),s=(0,P["default"])(["$in","$nin"],i)>=0&&h["default"].array(o)&&!(0,j["default"])(o,h["default"].object);if("$eq"===i||u||s||a||(t._isSimple=!1),q.hasOwnProperty(i))r.push(q[i](o,e,t,n));else{if(!L.hasOwnProperty(i))throw new Error("Unrecognized operator: "+i);var f=L[i];r.push(N(f.compileElementSelector(o,e,t),f))}}),G(r)},D=function(e,t,n){if(!(0,A.isArray)(e)||h["default"].emptyArray(e))throw Error("$and/$or/$nor must be nonempty array");return(0,b["default"])(e,function(e){if(!(0,A.isPlainObject)(e))throw Error("$or/$and/$nor entries need to be full objects");return C(e,t,{inElemMatch:n})})},R={$and:function(e,t,n){var r=D(e,t,n);return Q(r)},$or:function(e,t,n){var r=D(e,t,n);return 1===r.length?r[0]:function(e){var t=(0,j["default"])(r,function(t){return t(e).result});return{result:t}}},$nor:function(e,t,n){var r=D(e,t,n);return function(e){var t=(0,O["default"])(r,function(t){return!t(e).result});return{result:t}}},$where:function(e,t){return t._recordPathUsed(""),t._hasWhere=!0,e instanceof Function||(e=Function("obj","return "+e)),function(t){return{result:e.call(t,t)}}},$comment:function(){return function(){return{result:!0}}}},J=function(e){return function(t){var n=e(t);return{result:!n.result}}},q={$not:function(e,t,n){return J($(e,n))},$ne:function(e){return J(N(u(e)))},$nin:function(e){return J(N(L.$in.compileElementSelector(e)))},$exists:function(e){var t=N(function(e){return void 0!==e});return e?t:J(t)},$options:function(e,t){if(!h["default"].object(t)||!t.hasOwnProperty("$regex"))throw Error("$options needs a $regex");return W},$maxDistance:function(e,t){if(!t.$near)throw Error("$maxDistance needs a $near");return W},$all:function(e,t,n){if(!(0,A.isArray)(e))throw Error("$all requires array");if(h["default"].emptyArray(e))return F;var r=[];return(0,y["default"])(e,function(e){if((0,A.isOperatorObject)(e))throw Error("no $ expressions in $all");r.push($(e,n))}),G(r)},$near:function(e,t,n,r){if(!r)throw Error("$near can't be inside another $ operator");n._hasGeoQuery=!0;var o,i,u;if((0,A.isPlainObject)(e)&&e.hasOwnProperty("$geometry"))o=e.$maxDistance,i=e.$geometry,u=function(e){return e&&e.type?"Point"===e.type?S["default"].pointDistance(i,e):S["default"].geometryWithinRadius(e,i,o)?0:o+1:null};else{if(o=t.$maxDistance,!(0,A.isArray)(e)&&!(0,A.isPlainObject)(e))throw Error("$near argument must be coordinate pair or GeoJSON");i=V(e),u=function(e){return(0,A.isArray)(e)||(0,A.isPlainObject)(e)?B(i,e):null}}return function(e){e=s(e);var t={result:!1};return(0,y["default"])(e,function(e){var n=u(e.value);null===n||n>o||void 0!==t.distance&&t.distance<=n||(t.result=!0,t.distance=n,e.arrayIndices?t.arrayIndices=e.arrayIndices:delete t.arrayIndices)}),t}}},B=function(e,t){e=V(e),t=V(t);var n=e[0]-t[0],r=e[1]-t[1];return h["default"].number(n)&&h["default"].number(r)?Math.sqrt(n*n+r*r):null},V=function(e){return(0,b["default"])(e,function(e){return e})},U=function(e){return{compileElementSelector:function(t){if((0,A.isArray)(t))return function(){return!1};void 0===t&&(t=null);var n=A.MongoTypeComp._type(t);return function(r){return void 0===r&&(r=null),A.MongoTypeComp._type(r)!==n?!1:e(A.MongoTypeComp._cmp(r,t))}}}},L=n.ELEMENT_OPERATORS={$lt:U(function(e){return 0>e}),$gt:U(function(e){return e>0}),$lte:U(function(e){return 0>=e}),$gte:U(function(e){return e>=0}),$mod:{compileElementSelector:function(e){if(!(0,A.isArray)(e)||2!==e.length||"number"!=typeof e[0]||"number"!=typeof e[1])throw Error("argument to $mod must be an array of two numbers");var t=e[0],n=e[1];return function(e){return"number"==typeof e&&e%t===n}}},$in:{compileElementSelector:function(e){if(!(0,A.isArray)(e))throw Error("$in needs an array");var t=[];return(0,y["default"])(e,function(e){if(e instanceof RegExp)t.push(i(e));else{if((0,A.isOperatorObject)(e))throw Error("cannot nest $ under $in");t.push(u(e))}}),function(e){return void 0===e&&(e=null),(0,j["default"])(t,function(t){return t(e)})}}},$size:{dontExpandLeafArrays:!0,compileElementSelector:function(e){if("string"==typeof e)e=0;else if("number"!=typeof e)throw Error("$size needs a number");return function(t){return(0,A.isArray)(t)&&t.length===e}}},$type:{dontIncludeLeafArrays:!0,compileElementSelector:function(e){if("number"!=typeof e)throw Error("$type needs a number");return function(t){return void 0!==t&&A.MongoTypeComp._type(t)===e}}},$regex:{compileElementSelector:function(e,t){if(!("string"==typeof e||e instanceof RegExp))throw Error("$regex has to be a string or RegExp");var n;if(void 0!==t.$options){if(/[^gim]/.test(t.$options))throw new Error("Only the i, m, and g regexp options are supported");var r=e instanceof RegExp?e.source:e;n=new RegExp(r,t.$options)}else n=e instanceof RegExp?e:new RegExp(e);return i(n)}},$elemMatch:{dontExpandLeafArrays:!0,compileElementSelector:function(e,t,n){if(!(0,A.isPlainObject)(e))throw Error("$elemMatch need an object");var r,o;return(0,A.isOperatorObject)(e,!0)?(r=$(e,n),o=!1):(r=C(e,n,{inElemMatch:!0}),o=!0),function(e){if(!(0,A.isArray)(e))return!1;for(var t=0;t=e.length)return;for(;e.length0)throw new Error("$slice in $push must be zero or negative");i=n.$slice}var u=void 0;if(n.$sort){if(void 0===i)throw new Error("$sort requires $slice to be present");u=new O["default"](n.$sort).getComparator();for(var a=0;an?r.splice(0,1):r.pop()}}},$pull:function(e,t,n){if(void 0!==e){var r=e[t];if(void 0!==r){if(!(r instanceof Array))throw new Error("Cannot apply $pull/pullAll modifier to non-array");var o=[];if(null==n||"object"!==("undefined"==typeof n?"undefined":u(n))||n instanceof Array)for(var i=0;i=0)throw Error("Minimongo doesn't support $ operator in projections yet.");if("object"===("undefined"==typeof e?"undefined":p(e))&&((0,I["default"])(n,"$elemMatch")>=0||(0,I["default"])(n,"$meta")>=0||(0,I["default"])(n,"$slice")>=0))throw Error("Minimongo doesn't support operators in projections yet.");if(-1===(0,I["default"])([1,0,!0,!1],e))throw Error("Projection values should be one of 1, 0, true, or false")})}function s(e){var t=(0,j["default"])(e).sort();!(t.length>0)||1===t.length&&"_id"===t[0]||(0,I["default"])(t,"_id")>=0&&e._id||(t=(0,S["default"])(t,function(e){return"_id"!==e}));var n=null;(0,b["default"])(t,function(t){var r=!!e[t];if(null===n&&(n=r),n!==r)throw Error("You cannot currently mix including and excluding fields.")});var r=f(t,function(e){return n},function(e,t,n){var r=n,o=t;throw Error("both "+r+" and "+o+" found in fields option, using both of them may trigger unexpected behavior. Did you mean to use only one of them?")});return{tree:r,including:n}}function f(e,t,n,r){return r=r||{},(0,b["default"])(e,function(e){var o=r,u=e.split("."),a=(0,P["default"])(u.slice(0,-1),function(t,r){if(i(o,t)){if(!m["default"].object(o[t])&&(o[t]=n(o[t],u.slice(0,r+1).join("."),e),!m["default"].object(o[t])))return!1}else o[t]={};return o=o[t],!0});if(a){var s=u[u.length-1];i(o,s)?o[s]=n(o[s],e,e):o[s]=t(e)}}),r}function c(e,t){var n=s(t),r=n.tree,o={};if(r=f(e,function(e){return!0},function(e,t,n){return!0},r),o=R(r),n.including)return o;var i={};return(0,b["default"])(o,function(e,t){e||(i[t]=!1)}),i}function l(e,t){var n=D(e._getPaths());return(0,I["default"])(n,"")>=0?{}:c(n,t)}function d(e,t){var n=D(e._getPaths());return c(n,t)}var h="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},p="function"==typeof Symbol&&"symbol"===h(Symbol.iterator)?function(e){return"undefined"==typeof e?"undefined":h(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":"undefined"==typeof e?"undefined":h(e)},y=function(){function e(e,t){for(var n=0;n0?this.retriveIds(t):this.retriveAll()}},{key:"retriveAll",value:function(){var e=this;return new Promise(function(t,n){var r=[];e.db.storage.createReadStream().on("data",function(t){t.value&&r.push(e.db.create(t.value))}).on("end",function(){return t(r)})})}},{key:"retriveIds",value:function(e){var t=this,n={},r=[];(0,l["default"])(e,function(e){n[e]||(n[e]=!0,r.push(e))});var o=(0,f["default"])(r,function(e){return t.retriveOne(e)});return Promise.all(o).then(function(e){return(0,h["default"])(e,function(e){return e})})}},{key:"retriveOne",value:function(e){var t=this;return this.db.storage.get(e).then(function(e){return e?t.db.create(e):void 0})}}]),e}();n["default"]=y},{"./Document":8,"check-types":32,"fast.js/array/filter":36,"fast.js/forEach":42,"fast.js/map":49}],13:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},u="function"==typeof Symbol&&"symbol"===i(Symbol.iterator)?function(e){return"undefined"==typeof e?"undefined":i(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":"undefined"==typeof e?"undefined":i(e)},a=function(){function e(e,t){for(var n=0;n=0)})}if(this.affectedByModifier){var s={};(0,l["default"])(this._sortSpecParts,function(e){s[e.path]=1}),this._selectorForAffectedByModifier=new j["default"](s)}this._keyComparator=E((0,y["default"])(this._sortSpecParts,function(e,t){return n._keyFieldComparator(t)})),this._keyFilter=null,r.matcher&&this._useWithMatcher(r.matcher)}return a(e,[{key:"getComparator",value:function(e){if(!e||!e.distances)return this._getBaseComparator();var t=e.distances;return E([this._getBaseComparator(),function(e,n){if(!t.has(e._id))throw Error("Missing distance for "+e._id);if(!t.has(n._id))throw Error("Missing distance for "+n._id);return t.get(e._id)-t.get(n._id)}])}},{key:"_getPaths",value:function(){return(0,y["default"])(this._sortSpecParts,function(e){return e.path})}},{key:"_getMinKeyFromDoc",value:function(e){var t=this,n=null;if(this._generateKeysFromDoc(e,function(e){return t._keyCompatibleWithSelector(e)?null===n?void(n=e):void(t._compareKeys(e,n)<0&&(n=e)):void 0}),null===n)throw Error("sort selector found no keys in doc?");return n}},{key:"_keyCompatibleWithSelector",value:function(e){return!this._keyFilter||this._keyFilter(e)}},{key:"_generateKeysFromDoc",value:function(e,t){if(0===this._sortSpecParts.length)throw new Error("can't generate keys without a spec");var n=[],r=function(e){return e.join(",")+","},o=null;if((0,l["default"])(this._sortSpecParts,function(t,i){var u=(0,_.expandArraysInBranches)(t.lookup(e),!0);u.length||(u=[{value:null}]);var a=!1;if(n[i]={},(0,l["default"])(u,function(e){if(!e.arrayIndices){if(u.length>1)throw Error("multiple branches but no array used?");return void(n[i][""]=e.value)}a=!0;var t=r(e.arrayIndices);if(n[i].hasOwnProperty(t))throw Error("duplicate path: "+t);if(n[i][t]=e.value,o&&!o.hasOwnProperty(t))throw Error("cannot index parallel arrays")}),o){if(!n[i].hasOwnProperty("")&&(0,b["default"])(o).length!==(0,b["default"])(n[i]).length)throw Error("cannot index parallel arrays!")}else a&&(o={},(0,l["default"])(n[i],function(e,t){o[t]=!0}))}),!o){var i=(0,y["default"])(n,function(e){if(!e.hasOwnProperty(""))throw Error("no value in sole key case?");return e[""]});return void t(i)}(0,l["default"])(o,function(e,r){var o=(0,y["default"])(n,function(e){if(e.hasOwnProperty(""))return e[""];if(!e.hasOwnProperty(r))throw Error("missing path?");return e[r]});t(o)})}},{key:"_compareKeys",value:function(e,t){if(e.length!==this._sortSpecParts.length||t.length!==this._sortSpecParts.length)throw Error("Key has wrong length");return this._keyComparator(e,t)}},{key:"_keyFieldComparator",value:function(e){var t=!this._sortSpecParts[e].ascending;return function(n,r){var o=w.MongoTypeComp._cmp(n[e],r[e]);return t&&(o=-o),o}}},{key:"_getBaseComparator",value:function(){var e=this;return this._sortSpecParts.length?function(t,n){var r=e._getMinKeyFromDoc(t),o=e._getMinKeyFromDoc(n);return e._compareKeys(r,o)}:function(e,t){return 0}}},{key:"_useWithMatcher",value:function(e){if(this._keyFilter)throw Error("called _useWithMatcher twice?");if(!f["default"].emptyArray(this._sortSpecParts)){var t=e._selector;if(!(t instanceof Function)&&t){var n={};(0,l["default"])(this._sortSpecParts,function(e,t){n[e.path]=[]}),(0,l["default"])(t,function(e,t){var r=n[t];if(r){if(e instanceof RegExp){if(e.ignoreCase||e.multiline)return;return void r.push((0,_.regexpElementMatcher)(e))}return(0,w.isOperatorObject)(e)?void(0,l["default"])(e,function(t,n){(0,m["default"])(["$lt","$lte","$gt","$gte"],n)>=0&&r.push(_.ELEMENT_OPERATORS[n].compileElementSelector(t)),"$regex"!==n||e.$options||r.push(_.ELEMENT_OPERATORS.$regex.compileElementSelector(t,e))}):void r.push((0,_.equalityElementMatcher)(e))}});var r=n[this._sortSpecParts[0].path];f["default"].assigned(r)&&!f["default"].emptyArray(r)&&(this._keyFilter=function(e){return(0,h["default"])(this._sortSpecParts,function(t,r){return(0,h["default"])(n[t.path],function(t){return t(e[r])})})})}}}}]),e}();n["default"]=O;var E=function(e){return function(t,n){for(var r=0;r=f.length?!1:i!==f[r]?!1:o.equals(e[i],t[f[r]],n)?(r++,!0):!1}),s&&r===f.length}return r=0,s=(0,b["default"])(e).every(function(i){return u(t,i)&&o.equals(e[i],t[i],n)?(r++,!0):!1}),s&&(0,b["default"])(t).length===r}},{key:"clone",value:function(e){var t,n=this;if("object"!==("undefined"==typeof e?"undefined":l(e)))return e;if(null===e)return null;if(e instanceof Date)return new Date(e.getTime());if(e instanceof RegExp)return e;if(this.isBinary(e)){t=h["default"].newBinary(e.length);for(var r=0;r2?!1:(0,y["default"])(e._builtinConverters,function(e){return e.matchJSONValue(t)})},toJSONValue:function(t){var n={};return(0,j["default"])(t,function(t,r){n[r]=e.toJSONValue(t)}),{$escape:n}},fromJSONValue:function(t){var n={};return(0,j["default"])(t.$escape,function(t,r){n[r]=e.fromJSONValue(t)}),n}},{matchJSONValue:function(e){return u(e,"$type")&&u(e,"$value")&&2===(0,b["default"])(e).length},matchObject:function(t){return e._isCustomType(t)},toJSONValue:function(e){var t=e.toJSONValue();return{$type:e.typeName(),$value:t}},fromJSONValue:function(t){var n=t.$type;if(!u(e._customTypes,n))throw new Error("Custom EJSON type "+n+" is not defined");var r=e._customTypes[n];return r(t.$value)}}]}},{key:"_isCustomType",value:function(e){return e&&"function"==typeof e.toJSONValue&&"function"==typeof e.typeName&&u(this._customTypes,e.typeName())}},{key:"_adjustTypesToJSONValue",value:function(e){var t=this;if(null===e)return null;var n=this._toJSONValueHelper(e);return void 0!==n?n:"object"!==("undefined"==typeof e?"undefined":l(e))?e:((0,j["default"])(e,function(n,r){if("object"===("undefined"==typeof n?"undefined":l(n))||void 0===n||a(n)){var o=t._toJSONValueHelper(n);return o?void(e[r]=o):void t._adjustTypesToJSONValue(n)}}),e)}},{key:"_toJSONValueHelper",value:function(e){for(var t=0;t0)throw new Error("Index build failed with errors: ",n)})}}]),e}();n["default"]=w},{"./CollectionIndex":5,"./DocumentRetriver":12,"./PromiseQueue":16,"fast.js/forEach":42,"fast.js/function/bind":45,"fast.js/map":49,"fast.js/object/keys":52,invariant:56}],16:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,t){for(var n=0;n=t.maxQueuedPromises)o(new Error("Queue limit reached"));else{var i={promiseGenerator:e,resolve:r,reject:o};n?t.queue.unshift(i):t.queue.push(i),t.length+=1,t._dequeue()}})}},{key:"_dequeue",value:function(){var e=this;if(this._paused||this.pendingPromises>=this.maxPendingPromises)return!1;var t=this.queue.shift();if(!t)return!1;var n=(0,a["default"])(function(){return e.pendingPromises++,Promise.resolve().then(function(){return t.promiseGenerator()}).then(function(n){e.length--,e.pendingPromises--,t.resolve(n),e._dequeue()},function(n){e.length--,e.pendingPromises--,t.reject(n),e._dequeue()})});return n instanceof Error&&(this.length--,this.pendingPromises--,t.reject(n),this._dequeue()),!0}}]),e}();n["default"]=c},{"double-ended-queue":33,"fast.js/function/try":48}],17:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(){var e="undefined"!=typeof window&&window.innerHeight||"undefined"!=typeof document&&document.documentElement&&document.documentElement.clientHeight||"undefined"!=typeof document&&document.body&&document.body.clientHeight||1,t="undefined"!=typeof window&&window.innerWidth||"undefined"!=typeof document&&document.documentElement&&document.documentElement.clientWidth||"undefined"!=typeof document&&document.body&&document.body.clientWidth||1,n="undefined"!=typeof navigator&&navigator.userAgent||"";return[new Date,e,t,n,Math.random()]}var u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},a="function"==typeof Symbol&&"symbol"===u(Symbol.iterator)?function(e){return"undefined"==typeof e?"undefined":u(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":"undefined"==typeof e?"undefined":u(e)},s=function(){function e(e,t){for(var n=0;n>>0,r-=e,r*=e,e=r>>>0,r-=e,e+=4294967296*r}return 2.3283064365386963e-10*(e>>>0)};return t.version="Mash 0.9",t}return function(t){var n=0,r=0,o=0,i=1;0==t.length&&(t=[+new Date]);var u=e();n=u(" "),r=u(" "),o=u(" ");for(var a=0;an&&(n+=1),r-=u(t[a]),0>r&&(r+=1),o-=u(t[a]),0>o&&(o+=1);u=null;var s=function(){var e=2091639*n+2.3283064365386963e-10*i;return n=r,r=o,o=e-(i=0|e)};return s.uint32=function(){return 4294967296*s()},s.fract53=function(){return s()+1.1102230246251565e-16*(2097152*s()|0)},s.version="Alea 0.9",s.args=t,s}(Array.prototype.slice.call(arguments))},g=function(){function t(e){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];o(this,t),this.type=e,(0,d["default"])(p[e],"Random(...): no generator type %s",e),e===p.ALEA&&((0,d["default"])(n.seeds,"Random(...): seed is not provided for ALEA seeded generator"),this.alea=m.apply(null,n.seeds))}return s(t,[{key:"fraction",value:function(){if(this.type===p.ALEA)return this.alea();if(this.type===p.NODE_CRYPTO){var e=parseInt(this.hexString(8),16);return 2.3283064365386963e-10*e}if(this.type===p.BROWSER_CRYPTO){var t=new Uint32Array(1);return window.crypto.getRandomValues(t),2.3283064365386963e-10*t[0]}throw new Error("Unknown random generator type: "+this.type)}},{key:"hexString",value:function(t){if(this.type!==p.NODE_CRYPTO)return this._randomString(t,"0123456789abcdef");var n=function(){var n=e("crypto"),r=Math.ceil(t/2),o=(0,c["default"])(function(){return n.randomBytes(r)});o instanceof Error&&(o=n.pseudoRandomBytes(r));var i=o.toString("hex");return{v:i.substring(0,t)}}();return"object"===("undefined"==typeof n?"undefined":a(n))?n.v:void 0}},{key:"_randomString",value:function(e,t){for(var n=[],r=0;e>r;r++)n[r]=this.choice(t);return n.join("")}},{key:"id",value:function(e){return void 0===e&&(e=17),this._randomString(e,y)}},{key:"secret",value:function(e){return void 0===e&&(e=43),this._randomString(e,v)}},{key:"choice",value:function(e){var t=Math.floor(this.fraction()*e.length);return"string"==typeof e?e.substr(t,1):e[t]}}],[{key:"default",value:function(){return h?h:"undefined"!=typeof window?window.crypto&&window.crypto.getRandomValues?new t(p.BROWSER_CRYPTO):new t(p.ALEA,{seeds:i()}):new t(p.NODE_CRYPTO)}},{key:"createWithSeeds",value:function(){return(0,d["default"])(arguments.length,"Random.createWithSeeds(...): no seeds were provided"),new t(p.ALEA,{seeds:arguments})}}]),t}();n["default"]=g,n["default"]=g},{crypto:void 0,"fast.js/function/try":48,invariant:56}],18:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(n,"__esModule",{value:!0}),n["default"]=function(e){var t=i["default"]["default"]().hexString(20),n=[t,"/collection/"+e];return{value:i["default"].createWithSeeds.apply(null,n).id(17),seed:t}};var o=e("./Random"),i=r(o)},{"./Random":17}],19:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,t){for(var n=0;n=n;if(u=!c,c&&a){var l=i;return l.debouncePassed=!0,clearTimeout(r),a(),o+=1,l}}else i=new Promise(function(n,c){(a=function(){u?(r=setTimeout(a,t),u=!1):(n(e.apply(s,f)),i=null,o=0,r=null,u=!0,a=null)})()});return o+=1,i},f=function(e){n=e},c=function(e){t=e},l=function(){clearTimeout(r)};return s.updateBatchSize=f,s.updateWait=c,s.cancel=l,s.func=e,s}Object.defineProperty(n,"__esModule",{value:!0}),n["default"]=r},{}],31:[function(e,t,n){"use strict";var r=e("./dist/AsyncEventEmitter")["default"],o=e("./dist/Collection")["default"],i=e("./dist/CursorObservable")["default"],u=e("./dist/debounce")["default"],a=e("./dist/StorageManager")["default"],s=e("./dist/Random")["default"],f=e("./dist/EJSON")["default"],c=e("./dist/Base64")["default"],l=e("./dist/PromiseQueue")["default"];t.exports={__esModule:!0,"default":o,Random:s,EJSON:f,Base64:c,Collection:o,CursorObservable:i,StorageManager:a,EventEmitter:r,PromiseQueue:l,debounce:u}},{"./dist/AsyncEventEmitter":1,"./dist/Base64":2,"./dist/Collection":3,"./dist/CursorObservable":7,"./dist/EJSON":14,"./dist/PromiseQueue":16,"./dist/Random":17,"./dist/StorageManager":19,"./dist/debounce":30}],32:[function(t,n,r){!function(t){"use strict";function r(e,t){return e===t}function o(e){return void 0===e}function i(e){return null===e}function u(e){return!o(e)&&!i(e)}function a(e){return 0===e}function s(e){return e===Number.POSITIVE_INFINITY||e===Number.NEGATIVE_INFINITY}function f(e){return"number"==typeof e&&isNaN(e)===!1&&e!==Number.POSITIVE_INFINITY&&e!==Number.NEGATIVE_INFINITY}function c(e){return f(e)&&e%1===0}function l(e){return f(e)&&e%2===0}function d(e){return c(e)&&!l(e)}function h(e,t){return f(e)&&e>t}function p(e,t){return f(e)&&t>e}function y(e,t,n){return n>t?h(e,t)&&p(e,n):p(e,t)&&h(e,n)}function v(e,t){return f(e)&&e>=t}function m(e,t){return f(e)&&t>=e}function g(e,t,n){return n>t?v(e,t)&&m(e,n):m(e,t)&&v(e,n)}function b(e){return h(e,0)}function _(e){return p(e,0)}function j(e){return"string"==typeof e}function w(e){return""===e}function O(e){return j(e)&&""!==e}function E(e,t){return j(e)&&-1!==e.indexOf(t)}function P(e,t){return j(e)&&!!e.match(t)}function k(e){return e===!1||e===!0}function S(e){return"[object Object]"===Object.prototype.toString.call(e)}function M(e){return S(e)&&0===Object.keys(e).length}function x(e,t){try{return e instanceof t}catch(n){return!1}}function A(e,t){try{return x(e,t)||Object.prototype.toString.call(e)==="[object "+t.name+"]"}catch(n){return!1}}function I(e,t){try{return x(e,t)||e.constructor.name===t.name}catch(n){return!1}}function C(e,t){var n;for(n in t)if(t.hasOwnProperty(n)){if(e.hasOwnProperty(n)===!1||typeof e[n]!=typeof t[n])return!1;if(S(e[n])&&C(e[n],t[n])===!1)return!1}return!0}function $(e){return Array.isArray(e)}function N(e){return $(e)&&0===e.length}function T(e){return u(e)&&f(e.length)}function D(e){return"undefined"==typeof Symbol?T(e):u(e)&&B(e[Symbol.iterator])}function R(e,t){var n,r;if(me.assigned(e))return!1;try{if("undefined"!=typeof Symbol&&e[Symbol.iterator]&&B(e.values)){n=e.values();do if(r=n.next(),r.value===t)return!0;while(!r.done);return!1}Object.keys(e).forEach(function(n){if(e[n]===t)throw 0})}catch(o){return!0}return!1}function J(e,t){return u(e)&&e.length===t}function q(e){return A(e,Date)&&!isNaN(e.getTime())}function B(e){return"function"==typeof e}function V(e,t){return ve.array(e),B(t)?e.map(function(e){return t(e)}):(ve.array(t),ve.hasLength(e,t.length),e.map(function(e,n){return t[n](e)}))}function U(e,t){return ve.object(e),B(t)?L(e,t):(ve.object(t),F(e,t))}function L(e,t){var n={};return Object.keys(e).forEach(function(r){n[r]=t(e[r])}),n}function F(e,t){var n={};return Object.keys(t).forEach(function(r){var o=t[r];B(o)?me.assigned(e)?n[r]=!!o._isMaybefied:n[r]=o(e[r]):S(o)&&(n[r]=F(e[r],o))}),n}function W(e){return $(e)?z(e,!1):(ve.object(e),Q(e,!1))}function z(e,t){var n;for(n=0;nn;++n)this[n]=e[n];this._length=t}}function o(e,t,n,r,o){for(var i=0;o>i;++i)n[i+r]=e[i+t]}function i(e){return e>>>=0,e-=1,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,e+1}function u(e){if("number"!=typeof e){if(!a(e))return 16;e=e.length}return i(Math.min(Math.max(16,e),1073741824))}r.prototype.toArray=function(){for(var e=this._length,t=new Array(e),n=this._front,r=this._capacity,o=0;e>o;++o)t[o]=this[n+o&r-1];return t},r.prototype.push=function(e){var t=arguments.length,n=this._length;if(t>1){var r=this._capacity;if(n+t>r){for(var o=0;t>o;++o){this._checkCapacity(n+1);var i=this._front+n&this._capacity-1;this[i]=arguments[o],n++,this._length=n}return n}for(var i=this._front,o=0;t>o;++o)this[i+n&r-1]=arguments[o],i++;return this._length=n+t,n+t}if(0===t)return n;this._checkCapacity(n+1);var o=this._front+n&this._capacity-1;return this[o]=e,this._length=n+1,n+1},r.prototype.pop=function(){var e=this._length;if(0!==e){var t=this._front+e-1&this._capacity-1,n=this[t];return this[t]=void 0,this._length=e-1,n}},r.prototype.shift=function(){var e=this._length;if(0!==e){var t=this._front,n=this[t];return this[t]=void 0,this._front=t+1&this._capacity-1,this._length=e-1,n}},r.prototype.unshift=function(e){var t=this._length,n=arguments.length;if(n>1){var r=this._capacity;if(t+n>r){for(var o=n-1;o>=0;o--){this._checkCapacity(t+1);var r=this._capacity,i=(this._front-1&r-1^r)-r;this[i]=arguments[o],t++,this._length=t,this._front=i}return t}for(var u=this._front,o=n-1;o>=0;o--){var i=(u-1&r-1^r)-r;this[i]=arguments[o],u=i}return this._front=u,this._length=t+n,t+n}if(0===n)return t;this._checkCapacity(t+1);var r=this._capacity,o=(this._front-1&r-1^r)-r;return this[o]=e,this._length=t+1,this._front=o,t+1},r.prototype.peekBack=function(){var e=this._length;if(0!==e){var t=this._front+e-1&this._capacity-1;return this[t]}},r.prototype.peekFront=function(){return 0!==this._length?this[this._front]:void 0},r.prototype.get=function(e){var t=e;if(t===(0|t)){var n=this._length;if(0>t&&(t+=n),!(0>t||t>=n))return this[this._front+t&this._capacity-1]}},r.prototype.isEmpty=function(){return 0===this._length},r.prototype.clear=function(){this._length=0,this._front=0,this._makeCapacity()},r.prototype.toString=function(){return this.toArray().toString()},r.prototype.valueOf=r.prototype.toString,r.prototype.removeFront=r.prototype.shift,r.prototype.removeBack=r.prototype.pop,r.prototype.insertFront=r.prototype.unshift,r.prototype.insertBack=r.prototype.push,r.prototype.enqueue=r.prototype.push,r.prototype.dequeue=r.prototype.shift,r.prototype.toJSON=r.prototype.toArray,Object.defineProperty(r.prototype,"length",{get:function(){return this._length},set:function(){throw new RangeError("")}}),r.prototype._makeCapacity=function(){for(var e=this._capacity,t=0;e>t;++t)this[t]=void 0},r.prototype._checkCapacity=function(e){this._capacity=t+i)o(r,t,this,0,i);else{var u=i-(t+i&n-1);o(r,t,this,0,u),o(r,0,this,u,i-u)}};var a=Array.isArray;t.exports=r},{}],34:[function(e,t,n){"use strict";function r(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function o(){}var i="function"!=typeof Object.create?"~":!1;o.prototype._events=void 0,o.prototype.listeners=function(e,t){var n=i?i+e:e,r=this._events&&this._events[n];if(t)return!!r;if(!r)return[];if(r.fn)return[r.fn];for(var o=0,u=r.length,a=new Array(u);u>o;o++)a[o]=r[o].fn;return a},o.prototype.emit=function(e,t,n,r,o,u){var a=i?i+e:e;if(!this._events||!this._events[a])return!1;var s,f,c=this._events[a],l=arguments.length;if("function"==typeof c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),l){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,r),!0;case 5:return c.fn.call(c.context,t,n,r,o),!0;case 6:return c.fn.call(c.context,t,n,r,o,u),!0}for(f=1,s=new Array(l-1);l>f;f++)s[f-1]=arguments[f];c.fn.apply(c.context,s)}else{var d,h=c.length;for(f=0;h>f;f++)switch(c[f].once&&this.removeListener(e,c[f].fn,void 0,!0),l){case 1:c[f].fn.call(c[f].context);break;case 2:c[f].fn.call(c[f].context,t);break;case 3:c[f].fn.call(c[f].context,t,n);break;default:if(!s)for(d=1,s=new Array(l-1);l>d;d++)s[d-1]=arguments[d];c[f].fn.apply(c[f].context,s)}}return!0},o.prototype.on=function(e,t,n){var o=new r(t,n||this),u=i?i+e:e;return this._events||(this._events=i?{}:Object.create(null)),this._events[u]?this._events[u].fn?this._events[u]=[this._events[u],o]:this._events[u].push(o):this._events[u]=o,this},o.prototype.once=function(e,t,n){var o=new r(t,n||this,!0),u=i?i+e:e;return this._events||(this._events=i?{}:Object.create(null)),this._events[u]?this._events[u].fn?this._events[u]=[this._events[u],o]:this._events[u].push(o):this._events[u]=o,this},o.prototype.removeListener=function(e,t,n,r){var o=i?i+e:e;if(!this._events||!this._events[o])return this;var u=this._events[o],a=[];if(t)if(u.fn)(u.fn!==t||r&&!u.once||n&&u.context!==n)&&a.push(u);else for(var s=0,f=u.length;f>s;s++)(u[s].fn!==t||r&&!u[s].once||n&&u[s].context!==n)&&a.push(u[s]);return a.length?this._events[o]=1===a.length?a[0]:a:delete this._events[o],this},o.prototype.removeAllListeners=function(e){return this._events?(e?delete this._events[i?i+e:e]:this._events=i?{}:Object.create(null),this):this},o.prototype.off=o.prototype.removeListener,o.prototype.addListener=o.prototype.on,o.prototype.setMaxListeners=function(){return this},o.prefixed=i,"undefined"!=typeof t&&(t.exports=o)},{}],35:[function(e,t,n){"use strict";var r=e("../function/bindInternal3");t.exports=function(e,t,n){var o,i=e.length,u=void 0!==n?r(t,n):t;for(o=0;i>o;o++)if(!u(e[o],o,e))return!1;return!0}},{"../function/bindInternal3":46}],36:[function(e,t,n){"use strict";var r=e("../function/bindInternal3");t.exports=function(e,t,n){var o,i=e.length,u=[],a=void 0!==n?r(t,n):t;for(o=0;i>o;o++)a(e[o],o,e)&&u.push(e[o]);return u}},{"../function/bindInternal3":46}],37:[function(e,t,n){"use strict";var r=e("../function/bindInternal3");t.exports=function(e,t,n){var o,i=e.length,u=void 0!==n?r(t,n):t;for(o=0;i>o;o++)u(e[o],o,e)}},{"../function/bindInternal3":46}],38:[function(e,t,n){"use strict";t.exports=function(e,t,n){var r=e.length,o=0;for("number"==typeof n&&(o=n,0>o&&(o+=r,0>o&&(o=0)));r>o;o++)if(e[o]===t)return o;return-1}},{}],39:[function(e,t,n){"use strict";var r=e("../function/bindInternal3");t.exports=function(e,t,n){var o,i=e.length,u=new Array(i),a=void 0!==n?r(t,n):t;for(o=0;i>o;o++)u[o]=a(e[o],o,e);return u}},{"../function/bindInternal3":46}],40:[function(e,t,n){"use strict";var r=e("../function/bindInternal4");t.exports=function(e,t,n,o){var i,u,a=e.length,s=void 0!==o?r(t,o):t;for(void 0===n?(i=1,u=e[0]):(i=0,u=n);a>i;i++)u=s(u,e[i],i,e);return u}},{"../function/bindInternal4":47}],41:[function(e,t,n){"use strict";var r=e("../function/bindInternal3");t.exports=function(e,t,n){var o,i=e.length,u=void 0!==n?r(t,n):t;for(o=0;i>o;o++)if(u(e[o],o,e))return!0;return!1}},{"../function/bindInternal3":46}],42:[function(e,t,n){"use strict";var r=e("./array/forEach"),o=e("./object/forEach");t.exports=function(e,t,n){return e instanceof Array?r(e,t,n):o(e,t,n)}},{"./array/forEach":37,"./object/forEach":51}],43:[function(e,t,n){"use strict";t.exports=function(e,t){switch(t.length){case 0:return e();case 1:return e(t[0]);case 2:return e(t[0],t[1]);case 3:return e(t[0],t[1],t[2]);case 4:return e(t[0],t[1],t[2],t[3]);case 5:return e(t[0],t[1],t[2],t[3],t[4]);case 6:return e(t[0],t[1],t[2],t[3],t[4],t[5]);case 7:return e(t[0],t[1],t[2],t[3],t[4],t[5],t[6]);case 8:return e(t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7]);default:return e.apply(void 0,t)}}},{}],44:[function(e,t,n){"use strict";t.exports=function(e,t,n){switch(n.length){case 0:return e.call(t);case 1:return e.call(t,n[0]);case 2:return e.call(t,n[0],n[1]);case 3:return e.call(t,n[0],n[1],n[2]);case 4:return e.call(t,n[0],n[1],n[2],n[3]);case 5:return e.call(t,n[0],n[1],n[2],n[3],n[4]);case 6:return e.call(t,n[0],n[1],n[2],n[3],n[4],n[5]);case 7:return e.call(t,n[0],n[1],n[2],n[3],n[4],n[5],n[6]);case 8:return e.call(t,n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]);default:return e.apply(t,n)}}},{}],45:[function(e,t,n){"use strict";var r=e("./applyWithContext"),o=e("./applyNoContext");t.exports=function(e,t){var n,i=arguments.length-2;if(i>0){n=new Array(i);for(var u=0;i>u;u++)n[u]=arguments[u+2];return void 0!==t?function(){var o,u=arguments.length,a=new Array(i+u);for(o=0;i>o;o++)a[o]=n[o];for(o=0;u>o;o++)a[i+o]=arguments[o];return r(e,t,a)}:function(){var t,r=arguments.length,u=new Array(i+r);for(t=0;i>t;t++)u[t]=n[t];for(t=0;r>t;t++)u[i+t]=arguments[t];return o(e,u)}}return void 0!==t?function(){return r(e,t,arguments)}:function(){return o(e,arguments)}}},{"./applyNoContext":43,"./applyWithContext":44}],46:[function(e,t,n){"use strict";t.exports=function(e,t){return function(n,r,o){return e.call(t,n,r,o)}}},{}],47:[function(e,t,n){"use strict";t.exports=function(e,t){return function(n,r,o,i){return e.call(t,n,r,o,i)}}},{}],48:[function(e,t,n){"use strict";t.exports=function(e){try{return e()}catch(t){return t instanceof Error?t:new Error(t)}}},{}],49:[function(e,t,n){"use strict";var r=e("./array/map"),o=e("./object/map");t.exports=function(e,t,n){return e instanceof Array?r(e,t,n):o(e,t,n)}},{"./array/map":39,"./object/map":53}],50:[function(e,t,n){"use strict";t.exports=function(e){var t,n,r,o,i,u,a=arguments.length;for(n=1;a>n;n++)for(t=arguments[n],o=Object.keys(t),r=o.length,u=0;r>u;u++)i=o[u],e[i]=t[i];return e}},{}],51:[function(e,t,n){"use strict";var r=e("../function/bindInternal3");t.exports=function(e,t,n){var o,i,u=Object.keys(e),a=u.length,s=void 0!==n?r(t,n):t;for(i=0;a>i;i++)o=u[i],s(e[o],o,e)}},{"../function/bindInternal3":46}],52:[function(e,t,n){"use strict";t.exports="function"==typeof Object.keys?Object.keys:function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.push(n);return t}},{}],53:[function(e,t,n){"use strict";var r=e("../function/bindInternal3");t.exports=function(e,t,n){var o,i,u=Object.keys(e),a=u.length,s={},f=void 0!==n?r(t,n):t;for(o=0;a>o;o++)i=u[o],s[i]=f(e[i],i,e);return s}},{"../function/bindInternal3":46}],54:[function(e,t,n){"use strict";t.exports=function(e){for(var t=Object.keys(e),n=t.length,r=new Array(n),o=0;n>o;o++)r[o]=e[t[o]];return r}},{}],55:[function(e,t,n){!function(){function e(e){for(var t=[],n=[],r=0;rt!=r[i][0]>t&&e<(r[i][1]-r[o][1])*(t-r[o][0])/(r[i][0]-r[o][0])+r[o][1]&&(u=!u);return u}var r=this.gju={};"undefined"!=typeof t&&t.exports&&(t.exports=r),r.lineStringsIntersect=function(e,t){for(var n=[],r=0;r<=e.coordinates.length-2;++r)for(var o=0;o<=t.coordinates.length-2;++o){var i={x:e.coordinates[r][1],y:e.coordinates[r][0]},u={x:e.coordinates[r+1][1],y:e.coordinates[r+1][0]},a={x:t.coordinates[o][1],y:t.coordinates[o][0]},s={x:t.coordinates[o+1][1],y:t.coordinates[o+1][0]},f=(s.x-a.x)*(i.y-a.y)-(s.y-a.y)*(i.x-a.x),c=(u.x-i.x)*(i.y-a.y)-(u.y-i.y)*(i.x-a.x),l=(s.y-a.y)*(u.x-i.x)-(s.x-a.x)*(u.y-i.y);if(0!=l){var d=f/l,h=c/l;d>=0&&1>=d&&h>=0&&1>=h&&n.push({type:"Point",coordinates:[i.x+d*(u.x-i.x),i.y+d*(u.y-i.y)]})}}return 0==n.length&&(n=!1),n},r.pointInBoundingBox=function(e,t){return!(e.coordinates[1]t[1][0]||e.coordinates[0]t[1][1])},r.pointInPolygon=function(t,o){for(var i="Polygon"==o.type?[o.coordinates]:o.coordinates,u=!1,a=0;as;s++){var f=2*Math.PI*s/n,c=Math.asin(Math.sin(u[0])*Math.cos(i)+Math.cos(u[0])*Math.sin(i)*Math.cos(f)),l=u[1]+Math.atan2(Math.sin(f)*Math.sin(i)*Math.cos(u[0]),Math.cos(i)-Math.sin(u[0])*Math.sin(c));a[s]=[],a[s][1]=r.numberToDegree(c),a[s][0]=r.numberToDegree(l)}return{type:"Polygon",coordinates:[a]}},r.rectangleCentroid=function(e){var t=e.coordinates[0],n=t[0][0],r=t[0][1],o=t[2][0],i=t[2][1],u=o-n,a=i-r;return{type:"Point",coordinates:[n+u/2,r+a/2]}},r.pointDistance=function(e,t){var n=e.coordinates[0],o=e.coordinates[1],i=t.coordinates[0],u=t.coordinates[1],a=r.numberToRadius(u-o),s=r.numberToRadius(i-n),f=Math.pow(Math.sin(a/2),2)+Math.cos(r.numberToRadius(o))*Math.cos(r.numberToRadius(u))*Math.pow(Math.sin(s/2),2),c=2*Math.atan2(Math.sqrt(f),Math.sqrt(1-f));return 6371*c*1e3},r.geometryWithinRadius=function(e,t,n){if("Point"==e.type)return r.pointDistance(e,t)<=n;if("LineString"==e.type||"Polygon"==e.type){var o,i={};o="Polygon"==e.type?e.coordinates[0]:e.coordinates;for(var u in o)if(i.coordinates=o[u],r.pointDistance(i,t)>n)return!1}return!0},r.area=function(e){for(var t,n,r=0,o=e.coordinates[0],i=o.length-1,u=0;u0;)if(i=O[r-1],u=E[r-1],r--,u-i>1){for(d=e[u].lng()-e[i].lng(),h=e[u].lat()-e[i].lat(),Math.abs(d)>180&&(d=360-Math.abs(d)),d*=Math.cos(j*(e[u].lat()+e[i].lat())),p=d*d+h*h,a=i+1,s=i,c=-1;u>a;a++)y=e[a].lng()-e[i].lng(),v=e[a].lat()-e[i].lat(),Math.abs(y)>180&&(y=360-Math.abs(y)),y*=Math.cos(j*(e[a].lat()+e[i].lat())),m=y*y+v*v,g=e[a].lng()-e[u].lng(),b=e[a].lat()-e[u].lat(),Math.abs(g)>180&&(g=360-Math.abs(g)),g*=Math.cos(j*(e[a].lat()+e[u].lat())),_=g*g+b*b,f=m>=p+_?_:_>=p+m?m:(y*h-v*d)*(y*h-v*d)/p,f>c&&(s=a,c=f);l>c?(w[o]=i,o++):(r++,O[r-1]=s,E[r-1]=u,r++,O[r-1]=i,E[r-1]=s)}else w[o]=i,o++;w[o]=n-1,o++;for(var P=new Array,a=0;o>a;a++)P.push(e[w[a]]);return P.map(function(e){return{type:"Point",coordinates:[e.lng,e.lat]}})},r.destinationPoint=function(e,t,n){n/=6371,t=r.numberToRadius(t);var o=r.numberToRadius(e.coordinates[0]),i=r.numberToRadius(e.coordinates[1]),u=Math.asin(Math.sin(i)*Math.cos(n)+Math.cos(i)*Math.sin(n)*Math.cos(t)),a=o+Math.atan2(Math.sin(t)*Math.sin(n)*Math.cos(i),Math.cos(n)-Math.sin(i)*Math.sin(u));return a=(a+3*Math.PI)%(2*Math.PI)-Math.PI,{type:"Point",coordinates:[r.numberToDegree(a),r.numberToDegree(u)]}}}()},{}],56:[function(e,t,n){"use strict";var r=function(e,t,n,r,o,i,u,a){if(!e){var s;if(void 0===t)s=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var f=[n,r,o,i,u,a],c=0;s=new Error(t.replace(/%s/g,function(){return f[c++]})),s.name="Invariant Violation"}throw s.framesToPop=1,s}};t.exports=r},{}]},{},[31])(31)}); \ No newline at end of file diff --git a/dist/Collection.js b/dist/Collection.js index e31a4a1..05f6f55 100644 --- a/dist/Collection.js +++ b/dist/Collection.js @@ -72,19 +72,22 @@ var _defaultIdGenerator = _ShortIdGenerator2.default; // the second execution cycle var _startedUp = false; var _startUpQueue = []; -var _startUpTimeout = 0; +var _startUpId = 0; // Internals function _resetStartup() { - clearTimeout(_startUpTimeout); + _startUpId += 1; _startUpQueue = []; _startedUp = false; - _startUpTimeout = setTimeout(function () { - _startedUp = true; - (0, _forEach2.default)(_startUpQueue, function (fn) { - return fn(); - }); - _startUpQueue = []; + var currStartId = _startUpId; + setTimeout(function () { + if (currStartId === _startUpId) { + _startedUp = true; + (0, _forEach2.default)(_startUpQueue, function (fn) { + return fn(); + }); + _startUpQueue = []; + } }, 0); } diff --git a/dist/CursorObservable.js b/dist/CursorObservable.js index a6ce6c3..3b89776 100644 --- a/dist/CursorObservable.js +++ b/dist/CursorObservable.js @@ -258,7 +258,6 @@ var CursorObservable = function (_Cursor) { var insertedInResult = updatedInResult || newDoc && !oldDoc && this._matcher.documentMatches(newDoc).result; if (insertedInResult) { - this.emit('cursorChanged'); return this.update(); } } @@ -307,6 +306,10 @@ var CursorObservable = function (_Cursor) { var firstRun = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0]; + if (!firstRun) { + this.emit('cursorChanged'); + } + return this.exec().then(function (result) { _this3._updateLatestIds(); return _this3._propagateUpdate(firstRun).then(function () { diff --git a/package.json b/package.json index f9fba1f..fb44ffd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "marsdb", - "version": "0.6.5", + "version": "0.6.6", "author": { "name": "Artem Artemev", "email": "art@studytime.me"