UNPKG

mobdb

Version:

MarsDB is a lightweight client-side MongoDB-like database, Promise based, written in ES6

2 lines 234 kB
!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(){function e(t,r,n){function o(u,s){if(!r[u]){if(!t[u]){var a="function"==typeof require&&require;if(!s&&a)return a(u,!0);if(i)return i(u,!0);var c=new Error("Cannot find module '"+u+"'");throw c.code="MODULE_NOT_FOUND",c}var f=r[u]={exports:{}};t[u][0].call(f.exports,function(e){var r=t[u][1][e];return o(r||e)},f,f.exports,e,t,r,n)}return r[u].exports}for(var i="function"==typeof require&&require,u=0;u<n.length;u++)o(n[u]);return o}return e}()({1:[function(e,t,r){"use strict";function n(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":s(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":s(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 s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};Object.defineProperty(r,"__esModule",{value:!0});var a=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),c=e("eventemitter3"),f=n(c),l=function(e){function t(){return o(this,t),i(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return u(t,e),a(t,[{key:"emitAsync",value:function(e,t,r,n,o,i){var u=f["default"].prefixed,s=u?u+e:e;if(!this._events||!this._events[s])return Promise.resolve();var a=void 0,c=this._events[s],l=arguments.length,d=void 0;if("function"==typeof c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),l){case 1:return Promise.resolve(c.fn.call(c.context));case 2:return Promise.resolve(c.fn.call(c.context,t));case 3:return Promise.resolve(c.fn.call(c.context,t,r));case 4:return Promise.resolve(c.fn.call(c.context,t,r,n));case 5:return Promise.resolve(c.fn.call(c.context,t,r,n,o));case 6:return Promise.resolve(c.fn.call(c.context,t,r,n,o,i))}for(a=1,d=new Array(l-1);a<l;a++)d[a-1]=arguments[a];return Promise.resolve(c.fn.apply(c.context,d))}var h=[],p=c.length,b=void 0;for(a=0;a<p;a++)switch(c[a].once&&this.removeListener(e,c[a].fn,void 0,!0),l){case 1:h.push(Promise.resolve(c[a].fn.call(c[a].context)));break;case 2:h.push(Promise.resolve(c[a].fn.call(c[a].context,t)));break;case 3:h.push(Promise.resolve(c[a].fn.call(c[a].context,t,r)));break;default:if(!d)for(b=1,d=new Array(l-1);b<l;b++)d[b-1]=arguments[b];h.push(Promise.resolve(c[a].fn.apply(c[a].context,d)))}return Promise.all(h)}}]),t}(f["default"]);r["default"]=l},{eventemitter3:35}],2:[function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0});var o=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",u={};!function(){for(var e=0;e<i.length;e++)u[i.charAt(e)]=e}();var s=function(e){return i.charAt(e)},a=function(e){return"="===e?-1:u[e]},c=r.Base64=function(){function e(){n(this,e)}return o(e,[{key:"encode",value:function(e){if("string"==typeof e){var t=e;e=this.newBinary(t.length);for(var r=0;r<t.length;r++){var n=t.charCodeAt(r);if(n>255)throw new Error("Not ascii. Base64.encode can only take ascii strings.");e[r]=n}}for(var o=[],i=null,u=null,a=null,c=null,f=0;f<e.length;f++)switch(f%3){case 0:i=e[f]>>2&63,u=(3&e[f])<<4;break;case 1:u|=e[f]>>4&15,a=(15&e[f])<<2;break;case 2:a|=e[f]>>6&3,c=63&e[f],o.push(s(i)),o.push(s(u)),o.push(s(a)),o.push(s(c)),i=null,u=null,a=null,c=null}return null!=i&&(o.push(s(i)),o.push(s(u)),null==a?o.push("="):o.push(s(a)),null==c&&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 r=this.newBinary(t),n=null,o=null,i=null,u=0,s=0;s<e.length;s++){var c=e.charAt(s),f=a(c);switch(s%4){case 0:if(f<0)throw new Error("invalid base64 string");n=f<<2;break;case 1:if(f<0)throw new Error("invalid base64 string");n|=f>>4,r[u++]=n,o=(15&f)<<4;break;case 2:f>=0&&(o|=f>>2,r[u++]=o,i=(3&f)<<6);break;case 3:f>=0&&(r[u++]=i|f)}}return r}},{key:"newBinary",value:function(e){if("undefined"==typeof Uint8Array||"undefined"==typeof ArrayBuffer){for(var t=[],r=0;r<e;r++)t.push(0);return t.$Uint8ArrayPolyfill=!0,t}return new Uint8Array(new ArrayBuffer(e))}}]),e}();r["default"]=new c},{}],3:[function(e,t,r){"use strict";function n(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":c(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":c(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 s(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;F+=1,$=[],D=!1;var t=F;setTimeout(function(){t===F&&(D=!0,(0,p["default"])($,function(e){return e()}),$=[])},e)}function a(){D&&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 c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};Object.defineProperty(r,"__esModule",{value:!0}),r.Collection=void 0;var f=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();r._resetStartup=s,r._warnIfAlreadyStarted=a;var l=e("fast.js/map"),d=n(l),h=e("fast.js/forEach"),p=n(h),b=e("check-types"),v=n(b),y=e("./AsyncEventEmitter"),m=n(y),_=e("./IndexManager"),g=n(_),O=e("./StorageManager"),j=n(O),w=e("./CollectionDelegate"),S=n(w),E=e("./CursorObservable"),P=n(E),x=e("./ShortIdGenerator"),A=n(x),I=e("./EJSON"),k=n(I),M=P["default"],N=S["default"],T=j["default"],C=g["default"],R=A["default"],D=!1,$=[],F=0;s();var B=r.Collection=function(e){function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};o(this,t);var n=i(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return n.options=r,n._modelName=e,r.inMemory&&(r.cursorClass=r.cursorClass||P["default"],r.delegate=r.delegate||S["default"],r.storageManager=r.storageManager||j["default"],r.indexManager=r.indexManager||g["default"],r.idGenerator=r.idGenerator||A["default"]),t.startup(function(){return n._lazyInitCollection()}),n}return u(t,e),f(t,[{key:"create",value:function(e){return v["default"].string(e)?k["default"].parse(e):e}},{key:"insert",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this._lazyInitCollection();var n=this.idGenerator(this.modelName);return e=this.create(e),e._id=e._id||n.value,this.emit("beforeInsert",e,n),r.quiet||this.emit("sync:insert",e,n),this.delegate.insert(e,r,n).then(function(r){return t.emit("insert",e,null,n),r})}},{key:"insertAll",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return Promise.all((0,d["default"])(e,function(e){return t.insert(e,r)}))}},{key:"remove",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this._lazyInitCollection(),this.emit("beforeRemove",e,r),r.quiet||this.emit("sync:remove",e,r),this.delegate.remove(e,r).then(function(e){return(0,p["default"])(e,function(e){return t.emit("remove",null,e)}),e})}},{key:"update",value:function(e,t){var r=this,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return this._lazyInitCollection(),this.emit("beforeUpdate",e,t,n),n.quiet||this.emit("sync:update",e,t,n),this.delegate.update(e,t,n).then(function(e){return(0,p["default"])(e.updated,function(t,n){r.emit("update",t,e.original[n])}),e})}},{key:"find",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this._lazyInitCollection(),this.delegate.find(e,t)}},{key:"findOne",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this._lazyInitCollection(),this.delegate.findOne(e,t)}},{key:"count",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this._lazyInitCollection(),this.delegate.count(e,t)}},{key:"ids",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this._lazyInitCollection(),this.delegate.ids(e,t)}},{key:"_lazyInitCollection",value:function(){if(!this._initialized){this._initialized=!0;var e=this.options,t=e.storageManager||T,r=e.delegate||N,n=e.indexManager||C;this.idGenerator=e.idGenerator||R,this.cursorClass=e.cursorClass||M,this.indexManager=new n(this,e),this.storageManager=new t(this,e),this.delegate=new r(this,e)}}},{key:"modelName",get:function(){return this._modelName}},{key:"indexes",get:function(){return this._lazyInitCollection(),this.indexManager.indexes}},{key:"storage",get:function(){return this._lazyInitCollection(),this.storageManager}}],[{key:"defaultCursor",value:function(){return arguments.length>0?(a(),void(M=arguments[0])):M}},{key:"defaultStorageManager",value:function(){return arguments.length>0?(a(),void(T=arguments[0])):T}},{key:"defaultIdGenerator",value:function(){return arguments.length>0?(a(),void(R=arguments[0])):R}},{key:"defaultDelegate",value:function(){return arguments.length>0?(a(),void(N=arguments[0])):N}},{key:"defaultIndexManager",value:function(){return arguments.length>0?(a(),void(C=arguments[0])):C}},{key:"startup",value:function(e){D?e():$.push(e)}}]),t}(m["default"]);r["default"]=B},{"./AsyncEventEmitter":1,"./CollectionDelegate":4,"./CursorObservable":7,"./EJSON":14,"./IndexManager":15,"./ShortIdGenerator":19,"./StorageManager":20,"check-types":33,"fast.js/forEach":43,"fast.js/map":50}],4:[function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function o(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(r,"__esModule",{value:!0}),r.CollectionDelegate=void 0;var u=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),s=e("fast.js/map"),a=n(s),c=e("./DocumentModifier"),f=n(c),l=r.CollectionDelegate=function(){function e(t){i(this,e),this.db=t}return u(e,[{key:"insert",value:function(e){var t=this;arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},arguments[2];return this.db.indexManager.indexDocument(e).then(function(){return t.db.storageManager.persist(e._id,e).then(function(){return e._id})})}},{key:"remove",value:function(e,t){var r=this,n=t.sort,i=void 0===n?{_id:1}:n,u=t.multi,s=void 0!==u&&u;return this.find(e,{noClone:!0}).sort(i).then(function(e){e.length>1&&!s&&(e=[e[0]]);var t=(0,a["default"])(e,function(e){return r.db.storageManager["delete"](e._id)}),n=(0,a["default"])(e,function(e){return r.db.indexManager.deindexDocument(e)});return Promise.all([].concat(o(t),o(n))).then(function(){return e})})}},{key:"update",value:function(e,t,r){var n=this,i=r.sort,u=void 0===i?{_id:1}:i,s=r.multi,c=void 0!==s&&s,l=r.upsert,d=void 0!==l&&l;return this.find(e,{noClone:!0}).sort(u).then(function(r){return r.length>1&&!c&&(r=[r[0]]),new f["default"](e).modify(r,t,{upsert:d})}).then(function(e){var t=e.original,r=e.updated,i=(0,a["default"])(r,function(e){return n.db.storageManager.persist(e._id,e)}),u=(0,a["default"])(r,function(e,r){return n.db.indexManager.reindexDocument(t[r],e)});return Promise.all([].concat(o(i),o(u))).then(function(){return{modified:r.length,original:t,updated:r}})})}},{key:"find",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=this.db.cursorClass;return new r(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}();r["default"]=l},{"./DocumentModifier":10,"fast.js/map":50}],5:[function(e,t,r){"use strict";function n(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")}Object.defineProperty(r,"__esModule",{value:!0}),r.CollectionIndex=void 0;var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),u=e("invariant"),s=n(u),a=r.CollectionIndex=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};o(this,e),(0,s["default"])(t.fieldName,'CollectionIndex(...): you must specify a "feildName" option'),(0,s["default"])(!Array.isArray(t.fieldName),"CollectionIndex(...): compound index is not supported yet"),this.fieldName=t.fieldName,this.unique=t.unique||!1,this.sparse=t.sparse||!1,this.reset()}return i(e,[{key:"reset",value:function(){}},{key:"insert",value:function(e){}},{key:"remove",value:function(e){}},{key:"update",value:function(e,t){}},{key:"getMatching",value:function(e){}},{key:"getBetweenBounds",value:function(e){}},{key:"getAll",value:function(e){}}]),e}();r["default"]=a},{invariant:57}],6:[function(e,t,r){"use strict";function n(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":s(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":s(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 s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};Object.defineProperty(r,"__esModule",{value:!0}),r.Cursor=r.PIPELINE_PROCESSORS=void 0;var a="function"==typeof Symbol&&"symbol"===s(Symbol.iterator)?function(e){return"undefined"==typeof e?"undefined":s(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":"undefined"==typeof e?"undefined":s(e)},c=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),f=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},l=e("fast.js/forEach"),d=n(l),h=e("fast.js/object/assign"),p=n(h),b=e("fast.js/object/keys"),v=n(b),y=e("fast.js/map"),m=n(y),_=e("./AsyncEventEmitter"),g=n(_),O=e("invariant"),j=n(O),w=e("./DocumentRetriver"),S=n(w),E=e("./DocumentMatcher"),P=n(E),x=e("./DocumentSorter"),A=n(x),I=e("./DocumentProjector"),k=n(I),M=e("./EJSON"),N=n(M),T=0,C=r.PIPELINE_PROCESSORS=f({},e("./cursor-processors/filter"),e("./cursor-processors/sortFunc"),e("./cursor-processors/map"),e("./cursor-processors/aggregate"),e("./cursor-processors/reduce"),e("./cursor-processors/join"),e("./cursor-processors/joinEach"),e("./cursor-processors/joinAll"),e("./cursor-processors/joinObj"),e("./cursor-processors/ifNotEmpty")),R=function(e){function t(){return o(this,t),i(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return u(t,e),t}(g["default"]);(0,d["default"])(C,function(e,t){R.prototype[t]=e.method});var D=function(e){function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};o(this,t);var u=i(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return u.db=e,u.options=n,u._id=T++,u._query=r,u._pipeline=[],u._latestResult=null,u._childrenCursors={},u._parentCursors={},u._ensureMatcherSorter(),u}return u(t,e),c(t,[{key:"skip",value:function(e){return(0,j["default"])(e>=0||"undefined"==typeof e,"skip(...): skip must be a positive number"),this._skip=e,this}},{key:"limit",value:function(e){return(0,j["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 k["default"](e):this._projector=null,this}},{key:"sort",value:function(e){return(0,j["default"])("object"===("undefined"==typeof e?"undefined":a(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,j["default"])(e&&C[e],"Unknown pipeline processor type %s",e);for(var r=arguments.length,n=Array(r>2?r-2:0),o=2;o<r;o++)n[o-2]=arguments[o];return this._pipeline.push({type:e,value:t,args:n||[]}),this}},{key:"_processPipeline",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=this._pipeline[r];return n?Promise.resolve(C[n.type].process(e,n,this)).then(function(e){return"___[STOP]___"===e?e:t._processPipeline(e,r+1)}):Promise.resolve(e)}},{key:"_doExecute",value:function(){var e=this;return this._matchObjects().then(function(t){var r=void 0;return r=e.options.noClone?t:e._projector?e._projector.project(t):(0,m["default"])(t,function(e){return N["default"].clone(e)}),e._processPipeline(r)})}},{key:"_matchObjects",value:function(){var e=this,t=this._limit&&!this._skip&&!this._sorter,r=t?{limit:this._limit}:{},n=function(t){return t&&e._matcher.documentMatches(t).result};return new S["default"](this.db).retriveForQeury(this._query,n,r).then(function(r){if(t)return r;if(e._sorter){var n=e._sorter.getComparator();r.sort(n)}var o=e._skip||0,i=e._limit||r.length;return r.slice(o,i+o)})}},{key:"_ensureMatcherSorter",value:function(){this._sorter=void 0,this._matcher=new P["default"](this._query||{}),(this._matcher.hasGeoQuery||this._sort)&&(this._sorter=new A["default"](this._sort||[],{matcher:this._matcher}))}},{key:"_trackChildCursorPromise",value:function(e){var t=this,r=e.cursor;this._childrenCursors[r._id]=r,r._parentCursors[this._id]=this,this.once("beforeExecute",function(){delete t._childrenCursors[r._id],delete r._parentCursors[t._id],0===(0,v["default"])(r._parentCursors).length&&r.emit("beforeExecute")})}},{key:"_createCursorPromise",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return(0,p["default"])({cursor:this,then:function(n,o){return t._createCursorPromise(e.then(n,o),r)}},r)}}]),t}(R);r.Cursor=D,r["default"]=D},{"./AsyncEventEmitter":1,"./DocumentMatcher":9,"./DocumentProjector":11,"./DocumentRetriver":12,"./DocumentSorter":13,"./EJSON":14,"./cursor-processors/aggregate":21,"./cursor-processors/filter":22,"./cursor-processors/ifNotEmpty":23,"./cursor-processors/join":24,"./cursor-processors/joinAll":25,"./cursor-processors/joinEach":26,"./cursor-processors/joinObj":27,"./cursor-processors/map":28,"./cursor-processors/reduce":29,"./cursor-processors/sortFunc":30,"fast.js/forEach":43,"fast.js/map":50,"fast.js/object/assign":51,"fast.js/object/keys":53,invariant:57}],7:[function(e,t,r){"use strict";function n(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":s(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":s(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 s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};Object.defineProperty(r,"__esModule",{value:!0}),r.CursorObservable=void 0;var a=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),c=function I(e,t,r){null===e&&(e=Function.prototype);var n=Object.getOwnPropertyDescriptor(e,t);if(void 0===n){var o=Object.getPrototypeOf(e);return null===o?void 0:I(o,t,r)}if("value"in n)return n.value;var i=n.get;if(void 0!==i)return i.call(r)},f=e("fast.js/function/bind"),l=n(f),d=e("check-types"),h=n(d),p=e("fast.js/object/values"),b=n(p),v=e("fast.js/map"),y=n(v),m=e("./Cursor"),_=n(m),g=e("./EJSON"),O=n(g),j=e("./PromiseQueue"),w=n(j),S=e("./debounce"),E=n(S),P=1e3/60,x=10,A=function(e){function t(e,r,n){o(this,t);var u=i(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,r,n));return u.maybeUpdate=(0,l["default"])(u.maybeUpdate,u),u._observers=0,u._updateQueue=new w["default"](1),u._propagateUpdate=(0,E["default"])((0,l["default"])(u._propagateUpdate,u),0,0),u._doUpdate=(0,E["default"])((0,l["default"])(u._doUpdate,u),P,x),u}return u(t,e),a(t,[{key:"batchSize",value:function(e){return this._doUpdate.updateBatchSize(e),this}},{key:"debounce",value:function(e){return this._doUpdate.updateWait(e),this}},{key:"observe",value:function(e){function t(){r&&(r=!1,n._observers-=1,n.removeListener("update",e),n.removeListener("stop",t),0===n._observers&&(n._latestIds=null,n._latestResult=null,n._updatePromise=null,n.emit("observeStopped"),n.db.removeListener("insert",n.maybeUpdate),n.db.removeListener("update",n.maybeUpdate),n.db.removeListener("remove",n.maybeUpdate)))}arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e=e||function(){},this._observers<=0&&(this.db.on("insert",this.maybeUpdate),this.db.on("update",this.maybeUpdate),this.db.on("remove",this.maybeUpdate));var r=!0,n=this;this._observers+=1,this.on("update",e),this.on("stop",t),this._updatePromise?null!==this._latestResult&&e(this._latestResult):this.update(!0,!0);var o={stop:t};return this._createCursorPromise(this._updatePromise,o)}},{key:"stopObservers",value:function(){return this._doUpdate.cancel(),this.emit("stop"),this}},{key:"update",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!r){if(this._updateDebPromise&&!this._updateDebPromise.debouncePassed)return this._doUpdate(t),this._updatePromise;if(!(!this._updateDebAdded||this._updateDebPromise&&this._updateDebPromise.debouncePassed))return this._updatePromise;this._updateDebAdded=!0}return this._updatePromise=this._updateQueue.add(function(){return r?e._doUpdate.func(t):(e._updateDebAdded=!0,e._updateDebPromise=e._doUpdate(t),e._updateDebPromise.then(function(){e._updateDebAdded=!1,e._updateDebPromise=null}))}),this._updatePromise}},{key:"maybeUpdate",value:function(e,t){var r=null===e&&null===t,n=r||!e&&t&&(!this._latestIds||this._latestIds.has(t._id)),o=n||e&&t&&(this._matcher.documentMatches(e).result||this._matcher.documentMatches(t).result)&&!O["default"].equals(e,t),i=o||e&&!t&&this._matcher.documentMatches(e).result;if(i)return this.update()}},{key:"_propagateUpdate",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=this.emitAsync("update",this._latestResult,e),r=void 0;return e||(r=Promise.all((0,b["default"])((0,y["default"])(this._parentCursors,function(e,t){if(e._propagateUpdate)return e._propagateUpdate(!1)})))),t.then(function(){return r})}},{key:"_doUpdate",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return this.exec().then(function(r){return e._updateLatestIds(),e._propagateUpdate(t).then(function(){return r})})}},{key:"_updateLatestIds",value:function(){var e=h["default"].array(this._latestResult)?(0,y["default"])(this._latestResult,function(e){return e._id}):this._latestResult&&[this._latestResult._id];this._latestIds=new Set(e)}},{key:"_trackChildCursorPromise",value:function(e){c(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"_trackChildCursorPromise",this).call(this,e),e.stop&&(this.once("cursorChanged",e.stop),this.once("observeStopped",e.stop),this.once("beforeExecute",e.stop))}}],[{key:"defaultDebounce",value:function(){return arguments.length>0?void(P=arguments[0]):P}},{key:"defaultBatchSize",value:function(){return arguments.length>0?void(x=arguments[0]):x}}]),t}(_["default"]);r.CursorObservable=A,r["default"]=A},{"./Cursor":6,"./EJSON":14,"./PromiseQueue":17,"./debounce":31,"check-types":33,"fast.js/function/bind":46,"fast.js/map":50,"fast.js/object/values":55}],8:[function(e,t,r){"use strict";function n(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)&&!m["default"].isBinary(e)}function s(e){return e&&3===_._type(e)}function a(e){return u(e)||s(e)}function c(e,t){if(!s(e))return!1;var r=void 0;return(0,p["default"])(e,function(n,o){var i="$"===o.substr(0,1);if(void 0===r)r=i;else if(r!==i){if(!t)throw new Error("Inconsistent operator: "+JSON.stringify(e));r=!1}}),!!r}function f(e){return/^[0-9]+$/.test(e)}Object.defineProperty(r,"__esModule",{value:!0}),r.MongoTypeComp=void 0,r.selectorIsId=o,r.selectorIsIdPerhapsAsObject=i,r.isArray=u,r.isPlainObject=s,r.isIndexable=a,r.isOperatorObject=c,r.isNumericKey=f;var l=e("check-types"),d=n(l),h=e("fast.js/forEach"),p=n(h),b=e("fast.js/object/keys"),v=n(b),y=e("./EJSON"),m=n(y),_=r.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:m["default"].isBinary(e)?5:3},_equal:function(e,t){return m["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 r=_._type(e),n=_._type(t),o=_._typeorder(r),i=_._typeorder(n);if(o!==i)return o<i?-1:1;if(r!==n)throw Error("Missing type coercion logic in _cmp");if(7===r&&(r=n=2,e=e.toHexString(),t=t.toHexString()),9===r&&(r=n=1,e=e.getTime(),t=t.getTime()),1===r)return e-t;if(2===n)return e<t?-1:e===t?0:1;if(3===r){var u=function(e){var t=[];for(var r in e)t.push(r),t.push(e[r]);return t};return _._cmp(u(e),u(t))}if(4===r)for(var s=0;;s++){if(s===e.length)return s===t.length?0:-1;if(s===t.length)return 1;var a=_._cmp(e[s],t[s]);if(0!==a)return a}if(5===r){if(e.length!==t.length)return e.length-t.length;for(s=0;s<e.length;s++){if(e[s]<t[s])return-1;if(e[s]>t[s])return 1}return 0}if(8===r)return e?t?0:1:t?-1:0;if(10===r)return 0;if(11===r)throw Error("Sorting not supported on regular expression");if(13===r)throw Error("Sorting not supported on Javascript code");throw Error("Unknown type to sort")}}},{"./EJSON":14,"check-types":33,"fast.js/forEach":43,"fast.js/object/keys":53}],9:[function(e,t,r){"use strict";function n(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&&(e.lastIndex=0,e.test(t))}}function u(e){if((0,k.isOperatorObject)(e))throw Error("Can't create equalityValueSelector for operator object");return null==e?function(e){return null==e}:function(t){return k.MongoTypeComp._equal(e,t)}}function s(e,t){t=t||{};var r,n=e.split("."),o=n.length?n[0]:"",i=(0,k.isNumericKey)(o),u=n.length>=2&&(0,k.isNumericKey)(n[1]);n.length>1&&(r=s(n.slice(1).join(".")));var a=function(e){return e.dontIterate||delete e.dontIterate,e.arrayIndices&&!e.arrayIndices.length&&delete e.arrayIndices,e};return function(e,n){if(n||(n=[]),(0,k.isArray)(e)){if(!(i&&o<e.length))return[];n=n.concat(+o,"x")}var s=e[o];if(!r)return[a({value:s,dontIterate:(0,k.isArray)(e)&&(0,k.isArray)(s),arrayIndices:n})];if(!(0,k.isIndexable)(s))return(0,k.isArray)(e)?[]:[a({value:void 0,arrayIndices:n})];var c=[],f=function(e){Array.prototype.push.apply(c,e)};return f(r(s,n)),!(0,k.isArray)(s)||u&&t.forSort||(0,b["default"])(s,function(e,t){(0,k.isPlainObject)(e)&&f(r(e,n.concat(t)))}),c}}function a(e,t){var r=[];return(0,b["default"])(e,function(e){var n=(0,k.isArray)(e.value);t&&n&&!e.dontIterate||r.push({value:e.value,arrayIndices:e.arrayIndices}),n&&!e.dontIterate&&(0,b["default"])(e.value,function(t,n){r.push({value:t,arrayIndices:(e.arrayIndices||[]).concat(n)})})}),r}var c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};Object.defineProperty(r,"__esModule",{value:!0}),r.ELEMENT_OPERATORS=r.DocumentMatcher=void 0;var f="function"==typeof Symbol&&"symbol"===c(Symbol.iterator)?function(e){return"undefined"==typeof e?"undefined":c(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":"undefined"==typeof e?"undefined":c(e); },l=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();r.regexpElementMatcher=i,r.equalityElementMatcher=u,r.makeLookupFunction=s,r.expandArraysInBranches=a;var d=e("check-types"),h=n(d),p=e("fast.js/forEach"),b=n(p),v=e("fast.js/object/keys"),y=n(v),m=e("fast.js/map"),_=n(m),g=e("fast.js/array/some"),O=n(g),j=e("fast.js/array/every"),w=n(j),S=e("fast.js/array/indexOf"),E=n(S),P=e("geojson-utils"),x=n(P),A=e("./EJSON"),I=n(A),k=e("./Document"),M=r.DocumentMatcher=function(){function e(t){o(this,e),this._paths={},this._hasGeoQuery=!1,this._hasWhere=!1,this._isSimple=!0,this._matchingDocument=void 0,this._selector=null,this._docMatcher=this._compileSelector(t)}return l(e,[{key:"documentMatches",value:function(e){if(!e||"object"!==("undefined"==typeof e?"undefined":f(e)))throw Error("documentMatches needs a document");return this._docMatcher(e)}},{key:"_compileSelector",value:function(e){if(e instanceof Function)return this._isSimple=!1,this._selector=e,this._recordPathUsed(""),function(t){return{result:!!e.call(t)}};if((0,k.selectorIsId)(e))return this._selector={_id:e},this._recordPathUsed("_id"),function(t){return{result:I["default"].equals(t._id,e)}};if(!e||"_id"in e&&!e._id)return this._isSimple=!1,J;if("boolean"==typeof e||(0,k.isArray)(e)||I["default"].isBinary(e))throw new Error("Invalid selector: "+e);return this._selector=I["default"].clone(e),N(e,this,{isRoot:!0})}},{key:"_recordPathUsed",value:function(e){this._paths[e]=!0}},{key:"_getPaths",value:function(){return h["default"].object(this._paths)?(0,y["default"])(this._paths):null}},{key:"hasGeoQuery",get:function(){return this._hasGeoQuery}},{key:"hasWhere",get:function(){return this._hasWhere}},{key:"isSimple",get:function(){return this._isSimple}}]),e}();r["default"]=M;var N=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=[];return(0,b["default"])(e,function(e,o){if("$"===o.substr(0,1)){if(!$.hasOwnProperty(o))throw new Error("Unrecognized logical operator: "+o);t._isSimple=!1,n.push($[o](e,t,r.inElemMatch))}else{r.inElemMatch||t._recordPathUsed(o);var i=s(o),u=T(e,t,r.isRoot);n.push(function(e){var t=i(e);return u(t)})}}),Y(n)},T=function(e,t,r){return e instanceof RegExp?(t._isSimple=!1,C(i(e))):(0,k.isOperatorObject)(e)?R(e,t,r):C(u(e))},C=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return function(r){var n=r;t.dontExpandLeafArrays||(n=a(r,t.dontIncludeLeafArrays));var o={};return o.result=(0,O["default"])(n,function(t){var r=e(t.value);return"number"==typeof r&&(t.arrayIndices||(t.arrayIndices=[r]),r=!0),r&&t.arrayIndices&&(o.arrayIndices=t.arrayIndices),r}),o}},R=function(e,t,r){var n=[];return(0,b["default"])(e,function(o,i){var u=(0,E["default"])(["$lt","$lte","$gt","$gte"],i)>=0&&h["default"].number(o),s="$ne"===i&&!h["default"].object(o),a=(0,E["default"])(["$in","$nin"],i)>=0&&h["default"].array(o)&&!(0,O["default"])(o,h["default"].object);if("$eq"===i||u||a||s||(t._isSimple=!1),B.hasOwnProperty(i))n.push(B[i](o,e,t,r));else{if(!V.hasOwnProperty(i))throw new Error("Unrecognized operator: "+i);var c=V[i];n.push(C(c.compileElementSelector(o,e,t),c))}}),Q(n)},D=function(e,t,r){if(!(0,k.isArray)(e)||h["default"].emptyArray(e))throw Error("$and/$or/$nor must be nonempty array");return(0,_["default"])(e,function(e){if(!(0,k.isPlainObject)(e))throw Error("$or/$and/$nor entries need to be full objects");return N(e,t,{inElemMatch:r})})},$={$and:function(e,t,r){var n=D(e,t,r);return Y(n)},$or:function(e,t,r){var n=D(e,t,r);return 1===n.length?n[0]:function(e){var t=(0,O["default"])(n,function(t){return t(e).result});return{result:t}}},$nor:function(e,t,r){var n=D(e,t,r);return function(e){var t=(0,w["default"])(n,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}}}},F=function(e){return function(t){var r=e(t);return{result:!r.result}}},B={$not:function(e,t,r){return F(T(e,r))},$ne:function(e){return F(C(u(e)))},$nin:function(e){return F(C(V.$in.compileElementSelector(e)))},$exists:function(e){var t=C(function(e){return void 0!==e});return e?t:F(t)},$options:function(e,t){if(!h["default"].object(t)||!t.hasOwnProperty("$regex"))throw Error("$options needs a $regex");return z},$maxDistance:function(e,t){if(!t.$near)throw Error("$maxDistance needs a $near");return z},$all:function(e,t,r){if(!(0,k.isArray)(e))throw Error("$all requires array");if(h["default"].emptyArray(e))return J;var n=[];return(0,b["default"])(e,function(e){if((0,k.isOperatorObject)(e))throw Error("no $ expressions in $all");n.push(T(e,r))}),Q(n)},$near:function(e,t,r,n){if(!n)throw Error("$near can't be inside another $ operator");r._hasGeoQuery=!0;var o,i,u;if((0,k.isPlainObject)(e)&&e.hasOwnProperty("$geometry"))o=e.$maxDistance,i=e.$geometry,u=function(e){return e&&e.type?"Point"===e.type?x["default"].pointDistance(i,e):x["default"].geometryWithinRadius(e,i,o)?0:o+1:null};else{if(o=t.$maxDistance,!(0,k.isArray)(e)&&!(0,k.isPlainObject)(e))throw Error("$near argument must be coordinate pair or GeoJSON");i=U(e),u=function(e){return(0,k.isArray)(e)||(0,k.isPlainObject)(e)?q(i,e):null}}return function(e){e=a(e);var t={result:!1};return(0,b["default"])(e,function(e){var r=u(e.value);null===r||r>o||void 0!==t.distance&&t.distance<=r||(t.result=!0,t.distance=r,e.arrayIndices?t.arrayIndices=e.arrayIndices:delete t.arrayIndices)}),t}}},q=function(e,t){e=U(e),t=U(t);var r=e[0]-t[0],n=e[1]-t[1];return h["default"].number(r)&&h["default"].number(n)?Math.sqrt(r*r+n*n):null},U=function(e){return(0,_["default"])(e,function(e){return e})},L=function(e){return{compileElementSelector:function(t){if((0,k.isArray)(t))return function(){return!1};void 0===t&&(t=null);var r=k.MongoTypeComp._type(t);return function(n){return void 0===n&&(n=null),k.MongoTypeComp._type(n)===r&&e(k.MongoTypeComp._cmp(n,t))}}}},V=r.ELEMENT_OPERATORS={$lt:L(function(e){return e<0}),$gt:L(function(e){return e>0}),$lte:L(function(e){return e<=0}),$gte:L(function(e){return e>=0}),$mod:{compileElementSelector:function(e){if(!(0,k.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],r=e[1];return function(e){return"number"==typeof e&&e%t===r}}},$in:{compileElementSelector:function(e){if(!(0,k.isArray)(e))throw Error("$in needs an array");var t=[];return(0,b["default"])(e,function(e){if(e instanceof RegExp)t.push(i(e));else{if((0,k.isOperatorObject)(e))throw Error("cannot nest $ under $in");t.push(u(e))}}),function(e){return void 0===e&&(e=null),(0,O["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,k.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&&k.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 r;if(void 0!==t.$options){if(/[^gim]/.test(t.$options))throw new Error("Only the i, m, and g regexp options are supported");var n=e instanceof RegExp?e.source:e;r=new RegExp(n,t.$options)}else r=e instanceof RegExp?e:new RegExp(e);return i(r)}},$elemMatch:{dontExpandLeafArrays:!0,compileElementSelector:function(e,t,r){if(!(0,k.isPlainObject)(e))throw Error("$elemMatch need an object");var n,o;return(0,k.isOperatorObject)(e,!0)?(n=T(e,r),o=!1):(n=N(e,r,{inElemMatch:!0}),o=!0),function(e){if(!(0,k.isArray)(e))return!1;for(var t=0;t<e.length;++t){var r,i=e[t];if(o){if(!(0,k.isPlainObject)(i)&&!(0,k.isArray)(i))return!1;r=i}else r=[{value:i,dontIterate:!0}];if(n(r).result)return t}return!1}}}},J=function(e){return{result:!1}},z=function(e){return{result:!0}},W=function(e){return 0===e.length?z:1===e.length?e[0]:function(t){var r={};return r.result=(0,w["default"])(e,function(e){var n=e(t);return n.result&&void 0!==n.distance&&void 0===r.distance&&(r.distance=n.distance),n.result&&n.arrayIndices&&(r.arrayIndices=n.arrayIndices),n.result}),r.result||(delete r.distance,delete r.arrayIndices),r}},Y=W,Q=W},{"./Document":8,"./EJSON":14,"check-types":33,"fast.js/array/every":36,"fast.js/array/indexOf":39,"fast.js/array/some":42,"fast.js/forEach":43,"fast.js/map":50,"fast.js/object/keys":53,"geojson-utils":56}],10:[function(e,t,r){"use strict";function n(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&&e!==Symbol.prototype?"symbol":typeof e};Object.defineProperty(r,"__esModule",{value:!0}),r.findModTarget=r.DocumentModifier=void 0;var 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&&e!==Symbol.prototype?"symbol":"undefined"==typeof e?"undefined":i(e)},s=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),a=e("check-types"),c=n(a),f=e("fast.js/object/assign"),l=n(f),d=e("fast.js/forEach"),h=n(d),p=e("fast.js/array/every"),b=n(p),v=e("./EJSON"),y=n(v),m=e("./Random"),_=n(m),g=e("./DocumentMatcher"),O=n(g),j=e("./DocumentSorter"),w=n(j),S=e("./Document"),E=r.DocumentModifier=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};o(this,e),this._query=t,this._matcher=new O["default"](t)}return s(e,[{key:"modify",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=[],i=[];if((0,h["default"])(e,function(e){var u=t._matcher.documentMatches(e);if(u.result){var s=(0,l["default"])({arrayIndices:u.arrayIndices},n),a=t._modifyDocument(e,r,s);i.push(a),o.push(e)}}),!i.length&&n.upsert){var u=P(this._query);u._id=u._id||_["default"]["default"]().id(17),u=this._modifyDocument(u,r,{isInsert:!0}),i.push(u),o.push(null)}return{updated:i,original:o}}},{key:"_modifyDocument",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!(0,S.isPlainObject)(t))throw new Error("Modifier must be an object");t=y["default"].clone(t);var n,o=(0,S.isOperatorObject)(t);if(o)n=y["default"].clone(e),(0,h["default"])(t,function(e,t){var o=I[t];if(r.isInsert&&"$setOnInsert"===t&&(o=I.$set),!o)throw new Error("Invalid modifier specified "+t);(0,h["default"])(e,function(e,i){if(""===i)throw new Error("An empty update path is not valid.");if("_id"===i&&!r.isInsert)throw new Error("Mod on _id not allowed for update.");var u=i.split(".");if(!(0,b["default"])(u,function(e){return e}))throw new Error("The update path '"+i+"' contains an empty field name, which is not allowed.");var s=x(n,u,{noCreate:A[t],forbidArray:"$rename"===t,arrayIndices:r.arrayIndices}),a=u.pop();o(s,a,e,i,n)})});else{if(!r.isInsert&&t._id&&!y["default"].equals(e._id,t._id))throw new Error("Cannot change the _id of a document");for(var i in t)if(/\./.test(i))throw new Error("When replacing document, field name may not contain '.'");n=t,n._id=e._id}return n}}]),e}();r["default"]=E;var P=function(e){var t={};return c["default"].object(e)||(e={_id:e}),(0,h["default"])(e,function(e,r){if("$"!==r.substr(0,1)&&!(0,S.isOperatorObject)(e,!0)){var n=r.split("."),o=x(t,n);o&&(o[n[n.length-1]]=e)}}),t},x=r.findModTarget=function(e,t,r){r=r||{};for(var n=!1,o=0;o<t.length;o++){var i=o===t.length-1,s=t[o],a=(0,S.isIndexable)(e);if(!a){if(r.noCreate)return;var c=new Error("cannot use the part '"+s+"' to traverse "+e);throw c.setPropertyError=!0,c}if(e instanceof Array){if(r.forbidArray)return null;if("$"===s){if(n)throw new Error("Too many positional (i.e. '$') elements");if(!r.arrayIndices||!r.arrayIndices.length)throw new Error("The positional operator did not find the match needed from the query");s=r.arrayIndices[0],n=!0}else{if(!(0,S.isNumericKey)(s)){if(r.noCreate)return;throw new Error("can't append to array using string field name ["+s+"]")}s=parseInt(s,10)}if(i&&(t[o]=s),r.noCreate&&s>=e.length)return;for(;e.length<s;)e.push(null);if(!i)if(e.length===s)e.push({});else if("object"!==u(e[s]))throw new Error("can't modify field '"+t[o+1]+"' of list value "+JSON.stringify(e[s]))}else{if(s.length&&"$"===s.substr(0,1))throw new Error("can't set field named "+s);if(!(s in e)){if(r.noCreate)return;i||(e[s]={})}}if(i)return e;e=e[s]}},A={$unset:!0,$pop:!0,$rename:!0,$pull:!0,$pullAll:!0},I={$inc:function(e,t,r){if("number"!=typeof r)throw new Error("Modifier $inc allowed for numbers only");if(t in e){if("number"!=typeof e[t])throw new Error("Cannot apply $inc modifier to non-number");e[t]+=r}else e[t]=r},$set:function(e,t,r){if(!c["default"].object(e)&&!c["default"].array(e)){var n=new Error("Cannot set property on non-object field");throw n.setPropertyError=!0,n}if(null===e){var o=new Error("Cannot set property on null");throw o.setPropertyError=!0,o}e[t]=r},$setOnInsert:function(e,t,r){},$unset:function(e,t,r){void 0!==e&&(e instanceof Array?t in e&&(e[t]=null):delete e[t])},$push:function(e,t,r){if(void 0===e[t]&&(e[t]=[]),!(e[t]instanceof Array))throw new Error("Cannot apply $push modifier to non-array");if(!r||!r.$each)return void e[t].push(r);var n=r.$each;if(!(n instanceof Array))throw new Error("$each must be an array");var o=void 0;if("$position"in r){if("number"!=typeof r.$position)throw new Error("$position must be a numeric value");if(r.$position<0)throw new Error("$position in $push must be zero or positive");o=r.$position}var i=void 0;if("$slice"in r){if("number"!=typeof r.$slice)throw new Error("$slice must be a numeric value");if(r.$slice>0)throw new Error("$slice in $push must be zero or negative");i=r.$slice}var u=void 0;if(r.$sort){if(void 0===i)throw new Error("$sort requires $slice to be present");u=new w["default"](r.$sort).getComparator();for(var s=0;s<n.length;s++)if(3!==S.MongoTypeComp._type(n[s]))throw new Error("$push like modifiers using $sort require all elements to be objects")}if(void 0===o)for(var a=0;a<n.length;a++)e[t].push(n[a]);else{for(var c=[o,0],f=0;f<n.length;f++)c.push(n[f]);Array.prototype.splice.apply(e[t],c)}u&&e[t].sort(u),void 0!==i&&(0===i?e[t]=[]:e[t]=e[t].slice(i))},$pushAll:function(e,t,r){if(!("object"===("undefined"==typeof r?"undefined":u(r))&&r instanceof Array))throw new Error("Modifier $pushAll/pullAll allowed for arrays only");var n=e[t];if(void 0===n)e[t]=r;else{if(!(n instanceof Array))throw new Error("Cannot apply $pushAll modifier to non-array");for(var o=0;o<r.length;o++)n.push(r[o])}},$addToSet:function(e,t,r){var n=!1;if("object"===("undefined"==typeof r?"undefined":u(r)))for(var o in r){"$each"===o&&(n=!0);break}var i=n?r.$each:[r],s=e[t];if(void 0===s)e[t]=i;else{if(!(s instanceof Array))throw new Error("Cannot apply $addToSet modifier to non-array");(0,h["default"])(i,function(e){for(var t=0;t<s.length;t++)if(S.MongoTypeComp._equal(e,s[t]))return;s.push(e)})}},$pop:function(e,t,r){if(void 0!==e){var n=e[t];if(void 0!==n){if(!(n instanceof Array))throw new Error("Cannot apply $pop modifier to non-array");"number"==typeof r&&r<0?n.splice(0,1):n.pop()}}},$pull:function(e,t,r){if(void 0!==e){var n=e[t];if(void 0!==n){if(!(n instanceof Array))throw new Error("Cannot apply $pull/pullAll modifier to non-array");var o=[];if(null==r||"object"!==("undefined"==typeof r?"undefined":u(r))||r instanceof Array)for(var i=0;i<n.length;i++)S.MongoTypeComp._equal(n[i],r)||o.push(n[i]);else for(var s=new O["default"](r),a=0;a<n.length;a++)s.documentMatches(n[a]).result||o.push(n[a]);e[t]=o}}},$pullAll:function(e,t,r){if(!("object"===("undefined"==typeof r?"undefined":u(r))&&r instanceof Array))throw new Error("Modifier $pushAll/pullAll allowed for arrays only");if(void 0!==e){var n=e[t];if(void 0!==n){if(!(n instanceof Array))throw new Error("Cannot apply $pull/pullAll modifier to non-array");for(var o=[],i=0;i<n.length;i++){for(var s=!1,a=0;a<r.length;a++)if(S.MongoTypeComp._equal(n[i],r[a])){s=!0;break}s||o.push(n[i])}e[t]=o}}},$rename:function(e,t,r,n,o){if(n===r)throw new Error("$rename source must differ from target");if(null===e)throw new Error("$rename source field invalid");if("string"!=typeof r)throw new Error("$rename target must be a string");if(void 0!==e){var i=e[t];delete e[t];var u=r.split("."),s=x(o,u,{forbidArray:!0});if(null===s)throw new Error("$rename target field invalid");var a=u.pop();s[a]=i}},$bit:function(e,t,r){throw new Error("$bit is not supported")}}},{"./Document":8,"./DocumentMatcher":9,"./DocumentSorter":13,"./EJSON":14,"./Random":18,"check-types":33,"fast.js/array/every":36,"fast.js/forEach":43,"fast.js/object/assign":51}],11:[function(e,t,r){"use strict";function n(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){return y["default"].object(e)&&e.hasOwnProperty(t)}function u(e){s(e);var t=void 0===e._id||e._id,r=a(e),n=function o(e,t){if(y["default"].array(e))return(0,I["default"])(e,function(e){return o(e,t)});var n=r.including?{}:T["default"].clone(e);return(0,_["default"])(t,function(t,u){i(e,u)&&(y