From c95242b029405769d8a48f6cb9b9f14641f1483a Mon Sep 17 00:00:00 2001 From: Artem Artemyev Date: Sat, 2 Jan 2016 03:58:32 +0500 Subject: [PATCH] 0.4.2 --- build/marsdb.js | 33 ++++++++++++++++++--------------- build/marsdb.min.js | 6 +++--- dist/Cursor.js | 9 ++++++++- dist/StorageManager.js | 20 ++++++++------------ package.json | 2 +- 5 files changed, 38 insertions(+), 32 deletions(-) diff --git a/build/marsdb.js b/build/marsdb.js index c75a515..2a8f3ae 100644 --- a/build/marsdb.js +++ b/build/marsdb.js @@ -756,6 +756,10 @@ var _DocumentSorter = require('./DocumentSorter'); var _DocumentSorter2 = _interopRequireDefault(_DocumentSorter); +var _EJSON = require('./EJSON'); + +var _EJSON2 = _interopRequireDefault(_EJSON); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } @@ -1034,7 +1038,10 @@ var Cursor = (function (_EventEmitter) { var _this3 = this; this._executing = this._matchObjects().then(function (docs) { - return _this3.processPipeline(docs); + var clonned = (0, _map3.default)(docs, function (doc) { + return _EJSON2.default.clone(doc); + }); + return _this3.processPipeline(clonned); }).then(function (docs) { _this3._executing = null; return docs; @@ -1127,7 +1134,7 @@ var Cursor = (function (_EventEmitter) { exports.Cursor = Cursor; exports.default = Cursor; -},{"./DocumentMatcher":7,"./DocumentRetriver":9,"./DocumentSorter":10,"check-types":17,"eventemitter3":18,"fast.js/forEach":24,"fast.js/map":26,"invariant":33,"keymirror":32}],5:[function(require,module,exports){ +},{"./DocumentMatcher":7,"./DocumentRetriver":9,"./DocumentSorter":10,"./EJSON":11,"check-types":17,"eventemitter3":18,"fast.js/forEach":24,"fast.js/map":26,"invariant":33,"keymirror":32}],5:[function(require,module,exports){ 'use strict'; function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; } @@ -5477,10 +5484,6 @@ Object.defineProperty(exports, "__esModule", { }); exports.StorageManager = undefined; -var _keys2 = require('fast.js/object/keys'); - -var _keys3 = _interopRequireDefault(_keys2); - var _forEach = require('fast.js/forEach'); var _forEach2 = _interopRequireDefault(_forEach); @@ -5547,7 +5550,7 @@ var StorageManager = exports.StorageManager = (function () { value: function destroy() { var _this2 = this; - return this._loadedPromise.then(function () { + return this.loaded().then(function () { _this2._storage = {}; }); } @@ -5556,7 +5559,7 @@ var StorageManager = exports.StorageManager = (function () { value: function persist(key, value) { var _this3 = this; - return this._loadedPromise.then(function () { + return this.loaded().then(function () { _this3._storage[key] = _EJSON2.default.clone(value); }); } @@ -5565,7 +5568,7 @@ var StorageManager = exports.StorageManager = (function () { value: function _delete(key) { var _this4 = this; - return this._loadedPromise.then(function () { + return this.loaded().then(function () { delete _this4._storage[key]; }); } @@ -5574,8 +5577,8 @@ var StorageManager = exports.StorageManager = (function () { value: function get(key) { var _this5 = this; - return this._loadedPromise.then(function () { - return _EJSON2.default.clone(_this5._storage[key]); + return this.loaded().then(function () { + return _this5._storage[key]; }); } }, { @@ -5584,9 +5587,9 @@ var StorageManager = exports.StorageManager = (function () { var _this6 = this; var emitter = new _eventemitter2.default(); - this._loadedPromise.then(function () { - (0, _forEach2.default)((0, _keys3.default)(_this6._storage), function (k) { - emitter.emit('data', { value: _EJSON2.default.clone(_this6._storage[k]) }); + this.loaded().then(function () { + (0, _forEach2.default)(_this6._storage, function (v, k) { + emitter.emit('data', { value: v }); }); emitter.emit('end'); }); @@ -5604,7 +5607,7 @@ var StorageManager = exports.StorageManager = (function () { exports.default = StorageManager; -},{"./EJSON":11,"./PromiseQueue":13,"eventemitter3":18,"fast.js/forEach":24,"fast.js/object/keys":29}],16:[function(require,module,exports){ +},{"./EJSON":11,"./PromiseQueue":13,"eventemitter3":18,"fast.js/forEach":24}],16:[function(require,module,exports){ 'use strict'; var Collection = require('./dist/Collection').default; diff --git a/build/marsdb.min.js b/build/marsdb.min.js index a060b37..0cd87fd 100644 --- a/build/marsdb.min.js +++ b/build/marsdb.min.js @@ -1,3 +1,3 @@ -!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 i(u,a){if(!n[u]){if(!e[u]){var s="function"==typeof require&&require;if(!a&&s)return s(u,!0);if(o)return o(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 i(n?n:t)},c,c.exports,t,e,n,r)}return n[u].exports}for(var o="function"==typeof require&&require,u=0;u255)throw new Error("Not ascii. Base64.encode can only take ascii strings.");e[n]=r}}for(var i=[],o=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],i.push(a(o)),i.push(a(u)),i.push(a(s)),i.push(a(f)),o=null,u=null,s=null,f=null}return null!=o&&(i.push(a(o)),i.push(a(u)),null==s?i.push("="):i.push(a(s)),null==f&&i.push("=")),i.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,i=null,o=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,i=(15&c)<<4;break;case 2:c>=0&&(i|=c>>2,n[u++]=i,o=(3&c)<<6);break;case 3:c>=0&&(n[u++]=o|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},{}],2:[function(e,t,n){"use strict";function r(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function i(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 u(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!==("undefined"==typeof t?"undefined":r(t))&&"function"!=typeof t?e:t}function a(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":r(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(){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 this._ensureNotExecuting(),(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._ensureNotExecuting(),this._query=e||this._query,this._ensureMatcherSorter(),this}},{key:"sort",value:function(e){return this._ensureNotExecuting(),(0,w["default"])("object"===("undefined"==typeof e?"undefined":o(e))||"undefined"==typeof e||Array.isArray(e),"sort(...): argument must be an object"),this._sort=e,this._ensureMatcherSorter(),this}},{key:"sortFunc",value:function(e){return(0,w["default"])("function"==typeof e,"sortFunc(...): argument must be a function"),this.addPipeline($.Sort,e),this}},{key:"filter",value:function(e){return(0,w["default"])("function"==typeof e,"filter(...): argument must be a function"),this.addPipeline($.Filter,e),this}},{key:"map",value:function(e){return(0,w["default"])("function"==typeof e,"map(...): mapper must be a function"),this.addPipeline($.Map,e),this}},{key:"reduce",value:function(e,t){return(0,w["default"])("function"==typeof e,"reduce(...): reducer argument must be a function"),this.addPipeline($.Reduce,e,t),this}},{key:"aggregate",value:function(e){return(0,w["default"])("function"==typeof e,"aggregate(...): aggregator must be a function"),this.addPipeline($.Aggregate,e),this}},{key:"join",value:function(e){return(0,w["default"])("function"==typeof e,"join(...): argument must be a function"),this.addPipeline($.Join,e),this}},{key:"joinEach",value:function(e){return(0,w["default"])("function"==typeof e,"joinEach(...): argument must be a function"),this.addPipeline($.JoinEach,e),this}},{key:"joinAll",value:function(e){return(0,w["default"])("function"==typeof e,"joinAll(...): argument must be a function"),this.addPipeline($.JoinAll,e),this}},{key:"ifNotEmpty",value:function(){return this.addPipeline($.IfNotEmpty),this}},{key:"addPipeline",value:function(e,t){this._ensureNotExecuting(),(0,w["default"])(e&&$[e],"Unknown pipeline processor type %s",e);for(var n=arguments.length,r=Array(n>2?n-2:0),i=2;n>i;i++)r[i-2]=arguments[i];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(A[r.type](e,r,this)).then(function(e){return e===M?e:t.processPipeline(e,n+1)}):Promise.resolve(e)}},{key:"processSkipLimits",value:function(e){var t=this._skip||0,n=this._limit||e.length;return e.slice(t,n+t)}},{key:"exec",value:function(){var e=this;return this._executing=this._matchObjects().then(function(t){return e.processPipeline(t)}).then(function(t){return e._executing=null,t}),this._executing}},{key:"ids",value:function(){var e=this;return this._executing=this._matchObjects().then(function(e){return(0,y["default"])(e,function(e){return e._id})}).then(function(t){return e._executing=null,t}),this._executing}},{key:"then",value:function(e,t){return this.exec().then(e,t)}},{key:"whenNotExecuting",value:function(){return Promise.resolve(this._executing)}},{key:"_matchObjects",value:function(){var e=this;return new k["default"](this.db).retriveForQeury(this._query).then(function(t){var n=[],r=e._limit&&!e._skip&&!e._sorter;if((0,h["default"])(t,function(t){var i=e._matcher.documentMatches(t);return i.result&&n.push(t),r&&n.length===e._limit?!1:void 0}),r)return n;if(e._sorter){var i=e._sorter.getComparator();n.sort(i)}return e.processSkipLimits(n)})}},{key:"_ensureMatcherSorter",value:function(){this._sorter=void 0,this._matcher=new S["default"](this._query||{}),(this._matcher.hasGeoQuery||this._sort)&&(this._sorter=new I["default"](this._sort||[],{matcher:this._matcher}))}},{key:"_ensureNotExecuting",value:function(){(0,w["default"])(!this.isExecuting,"_ensureNotExecuting(...): cursor is executing, cursor is immutable!")}},{key:"isExecuting",get:function(){return!!this._executing}}]),t}(b["default"]);n.Cursor=N,n["default"]=N},{"./DocumentMatcher":7,"./DocumentRetriver":9,"./DocumentSorter":10,"check-types":17,eventemitter3:18,"fast.js/forEach":24,"fast.js/map":26,invariant:33,keymirror:32}],5:[function(e,t,n){"use strict";function r(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function i(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 u(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!==("undefined"==typeof t?"undefined":r(t))&&"function"!=typeof t?e:t}function a(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":r(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(e,t,n){var r=null,i=0,o=null,u=!0,a=null,s=function(){var s=this,f=arguments;if(o){var c=n&&i>=n;u=!c,c&&a&&(clearTimeout(r),a())}else o=new Promise(function(n,c){(a=function(){u?(r=setTimeout(a,t),u=!1):(o=null,i=0,r=null,u=!0,a=null,n(e.apply(s,f)))})()});return i+=1,o},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}var f=function(){function e(e,t){for(var n=0;nt.updatedAt)||!b["default"].equals(e,t)),i=r||e&&!t&&this._matcher.documentMatches(e).result;return i?(this.emit("cursorChanged"),this.update()):void 0}},{key:"_prepareListener",value:function(e){return s(e,0,0)}},{key:"_propagateUpdate",value:function(){var e=arguments.length<=0||void 0===arguments[0]?!1:arguments[0];this.emit("update",this._latestResult,e),!e&&this._parentCursor&&this._parentCursor._propagateUpdate&&this._parentCursor._propagateUpdate(!1)}},{key:"_updateLatestIds",value:function(){l["default"].array(this._latestResult)?this._latestIds=new Set((0,h["default"])(this._latestResult,function(e){return e._id})):this._latestResult&&this._latestResult._id&&(this._latestIds=new Set([this._latestResult._id]))}}]),t}(m["default"]);n.CursorObservable=_,n["default"]=_},{"./Cursor":4,"./EJSON":11,"check-types":17,"fast.js/map":26,"fast.js/object/keys":29}],6:[function(e,t,n){"use strict";function r(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function i(e){return e&&e.__esModule?e:{"default":e}}function o(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":"undefined"==typeof e?"undefined":r(e)}function u(e){var t=this,n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];(0,E["default"])(e,"Document(...): you must give a collection for the document"),n=m["default"].string(n)?k["default"].parse(n):n,Object.defineProperty(this,"remove",{value:function(){return(0,E["default"])(t._id,"remove(...): document must have an _id for remove"),e.remove({_id:self._id})},writable:!1}),Object.defineProperty(this,"update",{value:function(t){return(0,E["default"])(this._id,"update(...): document must have an _id for update"),e.update({_id:self._id},t)},writable:!1}),Object.defineProperty(this,"copy",{value:function(){return new u(e,k["default"].clone(t))},writable:!1}),Object.defineProperty(this,"serialize",{value:function(){return k["default"].stringify(t)},writable:!1});for(var r in e._methods)Object.defineProperty(this,r,{value:e._methods[r],writable:!1});(0,y["default"])(this,n)}function a(e){return"string"==typeof e||"number"==typeof e}function s(e){return a(e)||e&&"object"===("undefined"==typeof e?"undefined":o(e))&&e._id&&a(e._id)&&1===(0,w["default"])(e).length}function f(e){return m["default"].array(e)&&!k["default"].isBinary(e)}function c(e){return e&&3===x._type(e)}function l(e){return f(e)||c(e)}function d(e,t){if(!c(e))return!1;var n=void 0;return(0,b["default"])(e,function(r,i){var o="$"===i.substr(0,1);if(void 0===n)n=o;else if(n!==o){if(!t)throw new Error("Inconsistent operator: "+JSON.stringify(e));n=!1}}),!!n}function h(e){return/^[0-9]+$/.test(e)}Object.defineProperty(n,"__esModule",{value:!0}),n.MongoTypeComp=void 0,n.Document=u,n.selectorIsId=a,n.selectorIsIdPerhapsAsObject=s,n.isArray=f,n.isPlainObject=c,n.isIndexable=l,n.isOperatorObject=d,n.isNumericKey=h;var p=e("fast.js/object/assign"),y=i(p),v=e("check-types"),m=i(v),g=e("fast.js/forEach"),b=i(g),_=e("fast.js/object/keys"),w=i(_),j=e("invariant"),E=i(j),O=e("./EJSON"),k=i(O);n["default"]=u;var x=n.MongoTypeComp={_type:function(e){return"number"==typeof e?1:"string"==typeof e?2:"boolean"==typeof e?8:f(e)?4:null===e?10:e instanceof RegExp?11:"function"==typeof e?13:e instanceof Date?9:k["default"].isBinary(e)?5:3},_equal:function(e,t){return k["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=x._type(e),r=x._type(t),i=x._typeorder(n),o=x._typeorder(r);if(i!==o)return o>i?-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 x._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=x._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":11,"check-types":17,"fast.js/forEach":24,"fast.js/object/assign":27,"fast.js/object/keys":29,invariant:33}],7:[function(e,t,n){"use strict";function r(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function i(e){return e&&e.__esModule?e:{"default":e}}function o(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":"undefined"==typeof e?"undefined":r(e)}function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e){return function(t){return t instanceof RegExp?String(t)===String(e):"string"!=typeof t?!1:(e.lastIndex=0,e.test(t))}}function s(e){if((0,M.isOperatorObject)(e))throw Error("Can't create equalityValueSelector for operator object");return null==e?function(e){return null==e}:function(t){return M.MongoTypeComp._equal(e,t)}}function f(e,t){t=t||{};var n,r=e.split("."),i=r.length?r[0]:"",o=(0,M.isNumericKey)(i),u=r.length>=2&&(0,M.isNumericKey)(r[1]);r.length>1&&(n=f(r.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,r){if(r||(r=[]),(0,M.isArray)(e)){if(!(o&&i=0&&h["default"].number(i),a="$ne"===o&&!h["default"].object(i),s=(0,k["default"])(["$in","$nin"],o)>=0&&h["default"].array(i)&&!(0,w["default"])(i,h["default"].object);if("$eq"===o||u||s||a||(t._isSimple=!1),q.hasOwnProperty(o))r.push(q[o](i,e,t,n));else{if(!F.hasOwnProperty(o))throw new Error("Unrecognized operator: "+o);var f=F[o];r.push(C(f.compileElementSelector(i,e,t),f))}}),H(r)},J=function(e,t,n){if(!(0,M.isArray)(e)||h["default"].emptyArray(e))throw Error("$and/$or/$nor must be nonempty array");return(0,b["default"])(e,function(e){if(!(0,M.isPlainObject)(e))throw Error("$or/$and/$nor entries need to be full objects");return A(e,t,{inElemMatch:n})})},D={$and:function(e,t,n){var r=J(e,t,n);return G(r)},$or:function(e,t,n){var r=J(e,t,n);return 1===r.length?r[0]:function(e){var t=(0,w["default"])(r,function(t){return t(e).result});return{result:t}}},$nor:function(e,t,n){var r=J(e,t,n);return function(e){var t=(0,E["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}}}},R=function(e){return function(t){var n=e(t);return{result:!n.result}}},q={$not:function(e,t,n){return R(N(e,n))},$ne:function(e){return R(C(s(e)))},$nin:function(e){return R(C(F.$in.compileElementSelector(e)))},$exists:function(e){var t=C(function(e){return void 0!==e});return e?t:R(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,M.isArray)(e))throw Error("$all requires array");if(h["default"].emptyArray(e))return U;var r=[];return(0,y["default"])(e,function(e){if((0,M.isOperatorObject)(e))throw Error("no $ expressions in $all");r.push(N(e,n))}),H(r)},$near:function(e,t,n,r){if(!r)throw Error("$near can't be inside another $ operator");n._hasGeoQuery=!0;var i,o,u;if((0,M.isPlainObject)(e)&&e.hasOwnProperty("$geometry"))i=e.$maxDistance,o=e.$geometry,u=function(e){return e&&e.type?"Point"===e.type?S["default"].pointDistance(o,e):S["default"].geometryWithinRadius(e,o,i)?0:i+1:null};else{if(i=t.$maxDistance,!(0,M.isArray)(e)&&!(0,M.isPlainObject)(e))throw Error("$near argument must be coordinate pair or GeoJSON");o=B(e),u=function(e){return(0,M.isArray)(e)||(0,M.isPlainObject)(e)?V(o,e):null}}return function(e){e=c(e);var t={result:!1};return(0,y["default"])(e,function(e){var n=u(e.value); -null===n||n>i||void 0!==t.distance&&t.distance<=n||(t.result=!0,t.distance=n,e.arrayIndices?t.arrayIndices=e.arrayIndices:delete t.arrayIndices)}),t}}},V=function(e,t){e=B(e),t=B(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},B=function(e){return(0,b["default"])(e,function(e){return e})},L=function(e){return{compileElementSelector:function(t){if((0,M.isArray)(t))return function(){return!1};void 0===t&&(t=null);var n=M.MongoTypeComp._type(t);return function(r){return void 0===r&&(r=null),M.MongoTypeComp._type(r)!==n?!1:e(M.MongoTypeComp._cmp(r,t))}}}},F=n.ELEMENT_OPERATORS={$lt:L(function(e){return 0>e}),$gt:L(function(e){return e>0}),$lte:L(function(e){return 0>=e}),$gte:L(function(e){return e>=0}),$mod:{compileElementSelector:function(e){if(!(0,M.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,M.isArray)(e))throw Error("$in needs an array");var t=[];return(0,y["default"])(e,function(e){if(e instanceof RegExp)t.push(a(e));else{if((0,M.isOperatorObject)(e))throw Error("cannot nest $ under $in");t.push(s(e))}}),function(e){return void 0===e&&(e=null),(0,w["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,M.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&&M.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 a(n)}},$elemMatch:{dontExpandLeafArrays:!0,compileElementSelector:function(e,t,n){if(!(0,M.isPlainObject)(e))throw Error("$elemMatch need an object");var r,i;return(0,M.isOperatorObject)(e,!0)?(r=N(e,n),i=!1):(r=A(e,n,{inElemMatch:!0}),i=!0),function(e){if(!(0,M.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");o=n.$slice}var u=void 0;if(n.$sort){if(void 0===o)throw new Error("$sort requires $slice to be present");u=new E["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 i=[];if(null==n||"object"!==("undefined"==typeof n?"undefined":o(n))||n instanceof Array)for(var u=0;u0?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){return r.push(e.db.create(t.value))}).on("end",function(){return t(r)})})}},{key:"retriveIds",value:function(e){var t=this,n=(0,l["default"])(e,function(e){return t.retriveOne(e)});return Promise.all(n)}},{key:"retriveOne",value:function(e){var t=this;return this.db.storage.get(e).then(function(e){return t.db.create(e)})}}]),e}();n["default"]=h},{"./Document":6,"check-types":17,"fast.js/map":26,"fast.js/object/keys":29}],10:[function(e,t,n){"use strict";function r(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function i(e){return e&&e.__esModule?e:{"default":e}}function o(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":"undefined"==typeof e?"undefined":r(e)}function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var 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 w["default"](s)}this._keyComparator=O((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 O([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(",")+","},i=null;if((0,l["default"])(this._sortSpecParts,function(t,o){var u=(0,_.expandArraysInBranches)(t.lookup(e),!0);u.length||(u=[{value:null}]);var a=!1;if(n[o]={},(0,l["default"])(u,function(e){if(!e.arrayIndices){if(u.length>1)throw Error("multiple branches but no array used?");return void(n[o][""]=e.value)}a=!0;var t=r(e.arrayIndices);if(n[o].hasOwnProperty(t))throw Error("duplicate path: "+t);if(n[o][t]=e.value,i&&!i.hasOwnProperty(t))throw Error("cannot index parallel arrays")}),i){if(!n[o].hasOwnProperty("")&&(0,b["default"])(i).length!==(0,b["default"])(n[o]).length)throw Error("cannot index parallel arrays!")}else a&&(i={},(0,l["default"])(n[o],function(e,t){i[t]=!0}))}),!i){var o=(0,y["default"])(n,function(e){if(!e.hasOwnProperty(""))throw Error("no value in sole key case?");return e[""]});return void t(o)}(0,l["default"])(i,function(e,r){var i=(0,y["default"])(n,function(e){if(e.hasOwnProperty(""))return e[""];if(!e.hasOwnProperty(r))throw Error("missing path?");return e[r]});t(i)})}},{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 i=j.MongoTypeComp._cmp(n[e],r[e]);return t&&(i=-i),i}}},{key:"_getBaseComparator",value:function(){var e=this;return this._sortSpecParts.length?function(t,n){var r=e._getMinKeyFromDoc(t),i=e._getMinKeyFromDoc(n);return e._compareKeys(r,i)}: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)){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,j.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"]=E;var O=function(e){return function(t,n){for(var r=0;r=c.length?!1:o!==c[r]?!1:i.equals(e[o],t[c[r]],n)?(r++,!0):!1}),f&&r===c.length}return r=0,f=(0,b["default"])(e).every(function(o){return s(t,o)&&i.equals(e[o],t[o],n)?(r++,!0):!1}),f&&(0,b["default"])(t).length===r}},{key:"clone",value:function(e){var t,n=this;if("object"!==("undefined"==typeof e?"undefined":u(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,w["default"])(t,function(t,r){n[r]=e.toJSONValue(t)}),{$escape:n}},fromJSONValue:function(t){var n={};return(0,w["default"])(t.$escape,function(t,r){n[r]=e.fromJSONValue(t)}),n}},{matchJSONValue:function(e){return s(e,"$type")&&s(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(!s(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&&s(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":u(e))?e:((0,w["default"])(e,function(n,r){if("object"===("undefined"==typeof n?"undefined":u(n))||void 0===n||f(n)){var i=t._toJSONValueHelper(n);return i?void(e[r]=i):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"]=_},{"./CollectionIndex":3,"./DocumentRetriver":9,"./PromiseQueue":13,"fast.js/forEach":24,"fast.js/map":26,"fast.js/object/keys":29,invariant:33}],13:[function(e,t,n){"use strict";function r(e,t){this.pendingPromises=0,this.maxPendingPromises="undefined"!=typeof e?e:1/0,this.maxQueuedPromises="undefined"!=typeof t?t:1/0,this.queue=[]}Object.defineProperty(n,"__esModule",{value:!0}),n["default"]=r;var i="undefined"!=typeof Promise?Promise:function(){return{then:function(){throw new Error("Queue.configure() before use Queue")}}},o=function(){},u=function(e){return e&&"function"==typeof e.then?e:new i(function(t){t(e)})};r.configure=function(e){i=e},r.prototype.add=function(e){var t=this;return new i(function(n,r,i){return t.queue.length>=t.maxQueuedPromises?void r(new Error("Queue limit reached")):(t.queue.push({promiseGenerator:e,resolve:n,reject:r,notify:i||o}),void t._dequeue())})},r.prototype.getPendingLength=function(){return this.pendingPromises},r.prototype.getQueueLength=function(){return this.queue.length},r.prototype._dequeue=function(){var e=this;if(this.pendingPromises>=this.maxPendingPromises)return!1;var t=this.queue.shift();if(!t)return!1;try{this.pendingPromises++,u(t.promiseGenerator()).then(function(n){e.pendingPromises--,t.resolve(n),e._dequeue()},function(n){e.pendingPromises--,t.reject(n),e._dequeue()},function(e){t.notify(e)})}catch(n){e.pendingPromises--,t.reject(n),e._dequeue()}return!0}},{}],14:[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 i=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,i=0,o=1;0==t.length&&(t=[+new Date]);var u=e();n=u(" "),r=u(" "),i=u(" ");for(var a=0;an&&(n+=1),r-=u(t[a]),0>r&&(r+=1),i-=u(t[a]),0>i&&(i+=1);u=null;var s=function(){var e=2091639*n+2.3283064365386963e-10*o;return n=r,r=i,i=e-(o=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))},u="23456789ABCDEFGHJKLMNPQRSTWXYZabcdefghijkmnopqrstuvwxyz",a="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_",s=n.Random=function(){function e(){r(this,e);var t=arguments[0];if(!(void 0!==t||"undefined"!=typeof window&&window.crypto&&window.crypto.getRandomValues)){var n="undefined"!=typeof window&&window.innerHeight||"undefined"!=typeof document&&document.documentElement&&document.documentElement.clientHeight||"undefined"!=typeof document&&document.body&&document.body.clientHeight||1,i="undefined"!=typeof window&&window.innerWidth||"undefined"!=typeof document&&document.documentElement&&document.documentElement.clientWidth||"undefined"!=typeof document&&document.body&&document.body.clientWidth||1,u="undefined"!=typeof navigator&&navigator.userAgent||""; -t=[new Date,n,i,u,Math.random()]}void 0!==t&&(this.alea=o.apply(null,t))}return i(e,[{key:"fraction",value:function(){var e=this;if(e.alea)return e.alea();if("undefined"!=typeof window&&window.crypto&&window.crypto.getRandomValues){var t=new Uint32Array(1);return window.crypto.getRandomValues(t),2.3283064365386963e-10*t[0]}throw new Error("No random generator available")}},{key:"hexString",value:function(e){for(var t=this,n=[],r=0;e>r;++r)n.push(t.choice("0123456789abcdef"));return n.join("")}},{key:"_randomString",value:function(e,t){for(var n=this,r=[],i=0;e>i;i++)r[i]=n.choice(t);return r.join("")}},{key:"id",value:function(e){var t=this;return void 0===e&&(e=17),t._randomString(e,u)}},{key:"secret",value:function(e){var t=this;return void 0===e&&(e=43),t._randomString(e,a)}},{key:"choice",value:function(e){var t=Math.floor(this.fraction()*e.length);return"string"==typeof e?e.substr(t,1):e[t]}}],[{key:"createWithSeed",value:function(){if(0===arguments.length)throw new Error("No seeds were provided");return new e(arguments)}}]),e}();n["default"]=s},{}],15:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function i(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;nt}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 w(e){return"string"==typeof e}function j(e){return""===e}function E(e){return w(e)&&""!==e}function O(e,t){return w(e)&&-1!==e.indexOf(t)}function k(e,t){return w(e)&&!!e.match(t)}function x(e){return e===!1||e===!0}function S(e){return"[object Object]"===Object.prototype.toString.call(e)}function P(e){return S(e)&&0===Object.keys(e).length}function I(e,t){try{return e instanceof t}catch(n){return!1}}function M(e,t){try{return I(e,t)||Object.prototype.toString.call(e)==="[object "+t.name+"]"}catch(n){return!1}}function $(e,t){try{return I(e,t)||e.constructor.name===t.name}catch(n){return!1}}function A(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])&&A(e[n],t[n])===!1)return!1}return!0}function N(e){return Array.isArray(e)}function C(e){return N(e)&&0===e.length}function T(e){return u(e)&&f(e.length)}function J(e){return"undefined"==typeof Symbol?T(e):u(e)&&V(e[Symbol.iterator])}function D(e,t){var n,r;if(ge.assigned(e))return!1;try{if("undefined"!=typeof Symbol&&e[Symbol.iterator]&&V(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(i){return!0}return!1}function R(e,t){return u(e)&&e.length===t}function q(e){return M(e,Date)&&!isNaN(e.getTime())}function V(e){return"function"==typeof e}function B(e,t){return me.array(e),V(t)?e.map(function(e){return t(e)}):(me.array(t),me.hasLength(e,t.length),e.map(function(e,n){return t[n](e)}))}function L(e,t){return me.object(e),V(t)?F(e,t):(me.object(t),U(e,t))}function F(e,t){var n={};return Object.keys(e).forEach(function(r){n[r]=t(e[r])}),n}function U(e,t){var n={};return Object.keys(t).forEach(function(r){var i=t[r];V(i)?ge.assigned(e)?n[r]=!!i._isMaybefied:n[r]=i(e[r]):S(i)&&(n[r]=U(e[r],i))}),n}function W(e){return N(e)?Q(e,!1):(me.object(e),G(e,!1))}function Q(e,t){var n;for(n=0;ni;i++)a[i]=r[i].fn;return a},i.prototype.emit=function(e,t,n,r,i,u){var a=o?o+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,i),!0;case 6:return c.fn.call(c.context,t,n,r,i,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},i.prototype.on=function(e,t,n){var i=new r(t,n||this),u=o?o+e:e;return this._events||(this._events=o?{}:Object.create(null)),this._events[u]?this._events[u].fn?this._events[u]=[this._events[u],i]:this._events[u].push(i):this._events[u]=i,this},i.prototype.once=function(e,t,n){var i=new r(t,n||this,!0),u=o?o+e:e;return this._events||(this._events=o?{}:Object.create(null)),this._events[u]?this._events[u].fn?this._events[u]=[this._events[u],i]:this._events[u].push(i):this._events[u]=i,this},i.prototype.removeListener=function(e,t,n,r){var i=o?o+e:e;if(!this._events||!this._events[i])return this;var u=this._events[i],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[i]=1===a.length?a[0]:a:delete this._events[i],this},i.prototype.removeAllListeners=function(e){return this._events?(e?delete this._events[o?o+e:e]:this._events=o?{}:Object.create(null),this):this},i.prototype.off=i.prototype.removeListener,i.prototype.addListener=i.prototype.on,i.prototype.setMaxListeners=function(){return this},i.prefixed=o,"undefined"!=typeof t&&(t.exports=i)},{}],19:[function(e,t,n){"use strict";var r=e("../function/bindInternal3");t.exports=function(e,t,n){var i,o=e.length,u=void 0!==n?r(t,n):t;for(i=0;o>i;i++)if(!u(e[i],i,e))return!1;return!0}},{"../function/bindInternal3":25}],20:[function(e,t,n){"use strict";var r=e("../function/bindInternal3");t.exports=function(e,t,n){var i,o=e.length,u=void 0!==n?r(t,n):t;for(i=0;o>i;i++)u(e[i],i,e)}},{"../function/bindInternal3":25}],21:[function(e,t,n){"use strict";t.exports=function(e,t,n){var r=e.length,i=0;for("number"==typeof n&&(i=n,0>i&&(i+=r,0>i&&(i=0)));r>i;i++)if(e[i]===t)return i;return-1}},{}],22:[function(e,t,n){"use strict";var r=e("../function/bindInternal3");t.exports=function(e,t,n){var i,o=e.length,u=new Array(o),a=void 0!==n?r(t,n):t;for(i=0;o>i;i++)u[i]=a(e[i],i,e);return u}},{"../function/bindInternal3":25}],23:[function(e,t,n){"use strict";var r=e("../function/bindInternal3");t.exports=function(e,t,n){var i,o=e.length,u=void 0!==n?r(t,n):t;for(i=0;o>i;i++)if(u(e[i],i,e))return!0;return!1}},{"../function/bindInternal3":25}],24:[function(e,t,n){"use strict";var r=e("./array/forEach"),i=e("./object/forEach");t.exports=function(e,t,n){return e instanceof Array?r(e,t,n):i(e,t,n)}},{"./array/forEach":20,"./object/forEach":28}],25:[function(e,t,n){"use strict";t.exports=function(e,t){return function(n,r,i){return e.call(t,n,r,i)}}},{}],26:[function(e,t,n){"use strict";var r=e("./array/map"),i=e("./object/map");t.exports=function(e,t,n){return e instanceof Array?r(e,t,n):i(e,t,n)}},{"./array/map":22,"./object/map":30}],27:[function(e,t,n){"use strict";t.exports=function(e){var t,n,r,i,o,u,a=arguments.length;for(n=1;a>n;n++)for(t=arguments[n],i=Object.keys(t),r=i.length,u=0;r>u;u++)o=i[u],e[o]=t[o];return e}},{}],28:[function(e,t,n){"use strict";var r=e("../function/bindInternal3");t.exports=function(e,t,n){var i,o,u=Object.keys(e),a=u.length,s=void 0!==n?r(t,n):t;for(o=0;a>o;o++)i=u[o],s(e[i],i,e)}},{"../function/bindInternal3":25}],29:[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}},{}],30:[function(e,t,n){"use strict";var r=e("../function/bindInternal3");t.exports=function(e,t,n){var i,o,u=Object.keys(e),a=u.length,s={},f=void 0!==n?r(t,n):t;for(i=0;a>i;i++)o=u[i],s[o]=f(e[o],o,e);return s}},{"../function/bindInternal3":25}],31:[function(e,t,n){!function(){function e(e){for(var t=[],n=[],r=0;rt!=r[o][0]>t&&e<(r[o][1]-r[i][1])*(t-r[i][0])/(r[o][0]-r[i][0])+r[i][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 i=0;i<=t.coordinates.length-2;++i){var o={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[i][1],y:t.coordinates[i][0]},s={x:t.coordinates[i+1][1],y:t.coordinates[i+1][0]},f=(s.x-a.x)*(o.y-a.y)-(s.y-a.y)*(o.x-a.x),c=(u.x-o.x)*(o.y-a.y)-(u.y-o.y)*(o.x-a.x),l=(s.y-a.y)*(u.x-o.x)-(s.x-a.x)*(u.y-o.y);if(0!=l){var d=f/l,h=c/l;d>=0&&1>=d&&h>=0&&1>=h&&n.push({type:"Point",coordinates:[o.x+d*(u.x-o.x),o.y+d*(u.y-o.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,i){for(var o="Polygon"==i.type?[i.coordinates]:i.coordinates,u=!1,a=0;as;s++){var f=2*Math.PI*s/n,c=Math.asin(Math.sin(u[0])*Math.cos(o)+Math.cos(u[0])*Math.sin(o)*Math.cos(f)),l=u[1]+Math.atan2(Math.sin(f)*Math.sin(o)*Math.cos(u[0]),Math.cos(o)-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],i=t[2][0],o=t[2][1],u=i-n,a=o-r;return{type:"Point",coordinates:[n+u/2,r+a/2]}},r.pointDistance=function(e,t){var n=e.coordinates[0],i=e.coordinates[1],o=t.coordinates[0],u=t.coordinates[1],a=r.numberToRadius(u-i),s=r.numberToRadius(o-n),f=Math.pow(Math.sin(a/2),2)+Math.cos(r.numberToRadius(i))*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 i,o={};i="Polygon"==e.type?e.coordinates[0]:e.coordinates;for(var u in i)if(o.coordinates=i[u],r.pointDistance(o,t)>n)return!1}return!0},r.area=function(e){for(var t,n,r=0,i=e.coordinates[0],o=i.length-1,u=0;u0;)if(o=E[r-1],u=O[r-1],r--,u-o>1){for(d=e[u].lng()-e[o].lng(),h=e[u].lat()-e[o].lat(),Math.abs(d)>180&&(d=360-Math.abs(d)),d*=Math.cos(w*(e[u].lat()+e[o].lat())),p=d*d+h*h,a=o+1,s=o,c=-1;u>a;a++)y=e[a].lng()-e[o].lng(),v=e[a].lat()-e[o].lat(),Math.abs(y)>180&&(y=360-Math.abs(y)),y*=Math.cos(w*(e[a].lat()+e[o].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(w*(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?(j[i]=o,i++):(r++,E[r-1]=s,O[r-1]=u,r++,E[r-1]=o,O[r-1]=s)}else j[i]=o,i++;j[i]=n-1,i++;for(var k=new Array,a=0;i>a;a++)k.push(e[j[a]]);return k.map(function(e){return{type:"Point",coordinates:[e.lng,e.lat]}})},r.destinationPoint=function(e,t,n){n/=6371,t=r.numberToRadius(t);var i=r.numberToRadius(e.coordinates[0]),o=r.numberToRadius(e.coordinates[1]),u=Math.asin(Math.sin(o)*Math.cos(n)+Math.cos(o)*Math.sin(n)*Math.cos(t)),a=i+Math.atan2(Math.sin(t)*Math.sin(n)*Math.cos(o),Math.cos(n)-Math.sin(o)*Math.sin(u));return a=(a+3*Math.PI)%(2*Math.PI)-Math.PI,{type:"Point",coordinates:[r.numberToDegree(a),r.numberToDegree(u)]}}}()},{}],32:[function(e,t,n){"use strict";var r=function(e){var t,n={};if(!(e instanceof Object)||Array.isArray(e))throw new Error("keyMirror(...): Argument must be an object.");for(t in e)e.hasOwnProperty(t)&&(n[t]=t);return n};t.exports=r},{}],33:[function(e,t,n){"use strict";var r=function(e,t,n,r,i,o,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,i,o,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},{}]},{},[16])(16)}); \ No newline at end of file +!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 i(u,a){if(!n[u]){if(!e[u]){var s="function"==typeof require&&require;if(!a&&s)return s(u,!0);if(o)return o(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 i(n?n:t)},c,c.exports,t,e,n,r)}return n[u].exports}for(var o="function"==typeof require&&require,u=0;u255)throw new Error("Not ascii. Base64.encode can only take ascii strings.");e[n]=r}}for(var i=[],o=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],i.push(a(o)),i.push(a(u)),i.push(a(s)),i.push(a(f)),o=null,u=null,s=null,f=null}return null!=o&&(i.push(a(o)),i.push(a(u)),null==s?i.push("="):i.push(a(s)),null==f&&i.push("=")),i.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,i=null,o=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,i=(15&c)<<4;break;case 2:c>=0&&(i|=c>>2,n[u++]=i,o=(3&c)<<6);break;case 3:c>=0&&(n[u++]=o|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},{}],2:[function(e,t,n){"use strict";function r(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function i(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 u(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!==("undefined"==typeof t?"undefined":r(t))&&"function"!=typeof t?e:t}function a(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":r(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(){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 this._ensureNotExecuting(),(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._ensureNotExecuting(),this._query=e||this._query,this._ensureMatcherSorter(),this}},{key:"sort",value:function(e){return this._ensureNotExecuting(),(0,w["default"])("object"===("undefined"==typeof e?"undefined":o(e))||"undefined"==typeof e||Array.isArray(e),"sort(...): argument must be an object"),this._sort=e,this._ensureMatcherSorter(),this}},{key:"sortFunc",value:function(e){return(0,w["default"])("function"==typeof e,"sortFunc(...): argument must be a function"),this.addPipeline(N.Sort,e),this}},{key:"filter",value:function(e){return(0,w["default"])("function"==typeof e,"filter(...): argument must be a function"),this.addPipeline(N.Filter,e),this}},{key:"map",value:function(e){return(0,w["default"])("function"==typeof e,"map(...): mapper must be a function"),this.addPipeline(N.Map,e),this}},{key:"reduce",value:function(e,t){return(0,w["default"])("function"==typeof e,"reduce(...): reducer argument must be a function"),this.addPipeline(N.Reduce,e,t),this}},{key:"aggregate",value:function(e){return(0,w["default"])("function"==typeof e,"aggregate(...): aggregator must be a function"),this.addPipeline(N.Aggregate,e),this}},{key:"join",value:function(e){return(0,w["default"])("function"==typeof e,"join(...): argument must be a function"),this.addPipeline(N.Join,e),this}},{key:"joinEach",value:function(e){return(0,w["default"])("function"==typeof e,"joinEach(...): argument must be a function"),this.addPipeline(N.JoinEach,e),this}},{key:"joinAll",value:function(e){return(0,w["default"])("function"==typeof e,"joinAll(...): argument must be a function"),this.addPipeline(N.JoinAll,e),this}},{key:"ifNotEmpty",value:function(){return this.addPipeline(N.IfNotEmpty),this}},{key:"addPipeline",value:function(e,t){this._ensureNotExecuting(),(0,w["default"])(e&&N[e],"Unknown pipeline processor type %s",e);for(var n=arguments.length,r=Array(n>2?n-2:0),i=2;n>i;i++)r[i-2]=arguments[i];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(C[r.type](e,r,this)).then(function(e){return e===A?e:t.processPipeline(e,n+1)}):Promise.resolve(e)}},{key:"processSkipLimits",value:function(e){var t=this._skip||0,n=this._limit||e.length;return e.slice(t,n+t)}},{key:"exec",value:function(){var e=this;return this._executing=this._matchObjects().then(function(t){var n=(0,y["default"])(t,function(e){return $["default"].clone(e)});return e.processPipeline(n)}).then(function(t){return e._executing=null,t}),this._executing}},{key:"ids",value:function(){var e=this;return this._executing=this._matchObjects().then(function(e){return(0,y["default"])(e,function(e){return e._id})}).then(function(t){return e._executing=null,t}),this._executing}},{key:"then",value:function(e,t){return this.exec().then(e,t)}},{key:"whenNotExecuting",value:function(){return Promise.resolve(this._executing)}},{key:"_matchObjects",value:function(){var e=this;return new k["default"](this.db).retriveForQeury(this._query).then(function(t){var n=[],r=e._limit&&!e._skip&&!e._sorter;if((0,h["default"])(t,function(t){var i=e._matcher.documentMatches(t);return i.result&&n.push(t),r&&n.length===e._limit?!1:void 0}),r)return n;if(e._sorter){var i=e._sorter.getComparator();n.sort(i)}return e.processSkipLimits(n)})}},{key:"_ensureMatcherSorter",value:function(){this._sorter=void 0,this._matcher=new x["default"](this._query||{}),(this._matcher.hasGeoQuery||this._sort)&&(this._sorter=new I["default"](this._sort||[],{matcher:this._matcher}))}},{key:"_ensureNotExecuting",value:function(){(0,w["default"])(!this.isExecuting,"_ensureNotExecuting(...): cursor is executing, cursor is immutable!")}},{key:"isExecuting",get:function(){return!!this._executing}}]),t}(b["default"]);n.Cursor=T,n["default"]=T},{"./DocumentMatcher":7,"./DocumentRetriver":9,"./DocumentSorter":10,"./EJSON":11,"check-types":17,eventemitter3:18,"fast.js/forEach":24,"fast.js/map":26,invariant:33,keymirror:32}],5:[function(e,t,n){"use strict";function r(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function i(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 u(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!==("undefined"==typeof t?"undefined":r(t))&&"function"!=typeof t?e:t}function a(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":r(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(e,t,n){var r=null,i=0,o=null,u=!0,a=null,s=function(){var s=this,f=arguments;if(o){var c=n&&i>=n;u=!c,c&&a&&(clearTimeout(r),a())}else o=new Promise(function(n,c){(a=function(){u?(r=setTimeout(a,t),u=!1):(o=null,i=0,r=null,u=!0,a=null,n(e.apply(s,f)))})()});return i+=1,o},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}var f=function(){function e(e,t){for(var n=0;nt.updatedAt)||!b["default"].equals(e,t)),i=r||e&&!t&&this._matcher.documentMatches(e).result;return i?(this.emit("cursorChanged"),this.update()):void 0}},{key:"_prepareListener",value:function(e){return s(e,0,0)}},{key:"_propagateUpdate",value:function(){var e=arguments.length<=0||void 0===arguments[0]?!1:arguments[0];this.emit("update",this._latestResult,e),!e&&this._parentCursor&&this._parentCursor._propagateUpdate&&this._parentCursor._propagateUpdate(!1)}},{key:"_updateLatestIds",value:function(){l["default"].array(this._latestResult)?this._latestIds=new Set((0,h["default"])(this._latestResult,function(e){return e._id})):this._latestResult&&this._latestResult._id&&(this._latestIds=new Set([this._latestResult._id]))}}]),t}(m["default"]);n.CursorObservable=_,n["default"]=_},{"./Cursor":4,"./EJSON":11,"check-types":17,"fast.js/map":26,"fast.js/object/keys":29}],6:[function(e,t,n){"use strict";function r(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function i(e){return e&&e.__esModule?e:{"default":e}}function o(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":"undefined"==typeof e?"undefined":r(e)}function u(e){var t=this,n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];(0,E["default"])(e,"Document(...): you must give a collection for the document"),n=m["default"].string(n)?k["default"].parse(n):n,Object.defineProperty(this,"remove",{value:function(){return(0,E["default"])(t._id,"remove(...): document must have an _id for remove"),e.remove({_id:self._id})},writable:!1}),Object.defineProperty(this,"update",{value:function(t){return(0,E["default"])(this._id,"update(...): document must have an _id for update"),e.update({_id:self._id},t)},writable:!1}),Object.defineProperty(this,"copy",{value:function(){return new u(e,k["default"].clone(t))},writable:!1}),Object.defineProperty(this,"serialize",{value:function(){return k["default"].stringify(t)},writable:!1});for(var r in e._methods)Object.defineProperty(this,r,{value:e._methods[r],writable:!1});(0,y["default"])(this,n)}function a(e){return"string"==typeof e||"number"==typeof e}function s(e){return a(e)||e&&"object"===("undefined"==typeof e?"undefined":o(e))&&e._id&&a(e._id)&&1===(0,w["default"])(e).length}function f(e){return m["default"].array(e)&&!k["default"].isBinary(e)}function c(e){return e&&3===S._type(e)}function l(e){return f(e)||c(e)}function d(e,t){if(!c(e))return!1;var n=void 0;return(0,b["default"])(e,function(r,i){var o="$"===i.substr(0,1);if(void 0===n)n=o;else if(n!==o){if(!t)throw new Error("Inconsistent operator: "+JSON.stringify(e));n=!1}}),!!n}function h(e){return/^[0-9]+$/.test(e)}Object.defineProperty(n,"__esModule",{value:!0}),n.MongoTypeComp=void 0,n.Document=u,n.selectorIsId=a,n.selectorIsIdPerhapsAsObject=s,n.isArray=f,n.isPlainObject=c,n.isIndexable=l,n.isOperatorObject=d,n.isNumericKey=h;var p=e("fast.js/object/assign"),y=i(p),v=e("check-types"),m=i(v),g=e("fast.js/forEach"),b=i(g),_=e("fast.js/object/keys"),w=i(_),j=e("invariant"),E=i(j),O=e("./EJSON"),k=i(O);n["default"]=u;var S=n.MongoTypeComp={_type:function(e){return"number"==typeof e?1:"string"==typeof e?2:"boolean"==typeof e?8:f(e)?4:null===e?10:e instanceof RegExp?11:"function"==typeof e?13:e instanceof Date?9:k["default"].isBinary(e)?5:3},_equal:function(e,t){return k["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=S._type(e),r=S._type(t),i=S._typeorder(n),o=S._typeorder(r);if(i!==o)return o>i?-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 S._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=S._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":11,"check-types":17,"fast.js/forEach":24,"fast.js/object/assign":27,"fast.js/object/keys":29,invariant:33}],7:[function(e,t,n){"use strict";function r(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function i(e){return e&&e.__esModule?e:{"default":e}}function o(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":"undefined"==typeof e?"undefined":r(e)}function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e){return function(t){return t instanceof RegExp?String(t)===String(e):"string"!=typeof t?!1:(e.lastIndex=0,e.test(t))}}function s(e){if((0,M.isOperatorObject)(e))throw Error("Can't create equalityValueSelector for operator object");return null==e?function(e){return null==e}:function(t){return M.MongoTypeComp._equal(e,t)}}function f(e,t){t=t||{};var n,r=e.split("."),i=r.length?r[0]:"",o=(0,M.isNumericKey)(i),u=r.length>=2&&(0,M.isNumericKey)(r[1]);r.length>1&&(n=f(r.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,r){if(r||(r=[]),(0,M.isArray)(e)){if(!(o&&i=0&&h["default"].number(i),a="$ne"===o&&!h["default"].object(i),s=(0,k["default"])(["$in","$nin"],o)>=0&&h["default"].array(i)&&!(0,w["default"])(i,h["default"].object);if("$eq"===o||u||s||a||(t._isSimple=!1),q.hasOwnProperty(o))r.push(q[o](i,e,t,n));else{if(!F.hasOwnProperty(o))throw new Error("Unrecognized operator: "+o);var f=F[o];r.push(C(f.compileElementSelector(i,e,t),f))}}),H(r)},J=function(e,t,n){if(!(0,M.isArray)(e)||h["default"].emptyArray(e))throw Error("$and/$or/$nor must be nonempty array");return(0,b["default"])(e,function(e){if(!(0,M.isPlainObject)(e))throw Error("$or/$and/$nor entries need to be full objects");return A(e,t,{inElemMatch:n})})},D={$and:function(e,t,n){var r=J(e,t,n);return G(r)},$or:function(e,t,n){var r=J(e,t,n);return 1===r.length?r[0]:function(e){var t=(0,w["default"])(r,function(t){return t(e).result});return{result:t}}},$nor:function(e,t,n){var r=J(e,t,n);return function(e){var t=(0,E["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}}}},R=function(e){return function(t){var n=e(t);return{result:!n.result}}},q={$not:function(e,t,n){return R(N(e,n))},$ne:function(e){return R(C(s(e)))},$nin:function(e){return R(C(F.$in.compileElementSelector(e)))},$exists:function(e){var t=C(function(e){return void 0!==e});return e?t:R(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,M.isArray)(e))throw Error("$all requires array");if(h["default"].emptyArray(e))return U;var r=[];return(0,y["default"])(e,function(e){if((0,M.isOperatorObject)(e))throw Error("no $ expressions in $all");r.push(N(e,n))}),H(r)},$near:function(e,t,n,r){if(!r)throw Error("$near can't be inside another $ operator");n._hasGeoQuery=!0;var i,o,u;if((0,M.isPlainObject)(e)&&e.hasOwnProperty("$geometry"))i=e.$maxDistance,o=e.$geometry,u=function(e){return e&&e.type?"Point"===e.type?x["default"].pointDistance(o,e):x["default"].geometryWithinRadius(e,o,i)?0:i+1:null};else{if(i=t.$maxDistance,!(0,M.isArray)(e)&&!(0,M.isPlainObject)(e))throw Error("$near argument must be coordinate pair or GeoJSON");o=B(e),u=function(e){return(0,M.isArray)(e)||(0,M.isPlainObject)(e)?V(o,e):null; +}}return function(e){e=c(e);var t={result:!1};return(0,y["default"])(e,function(e){var n=u(e.value);null===n||n>i||void 0!==t.distance&&t.distance<=n||(t.result=!0,t.distance=n,e.arrayIndices?t.arrayIndices=e.arrayIndices:delete t.arrayIndices)}),t}}},V=function(e,t){e=B(e),t=B(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},B=function(e){return(0,b["default"])(e,function(e){return e})},L=function(e){return{compileElementSelector:function(t){if((0,M.isArray)(t))return function(){return!1};void 0===t&&(t=null);var n=M.MongoTypeComp._type(t);return function(r){return void 0===r&&(r=null),M.MongoTypeComp._type(r)!==n?!1:e(M.MongoTypeComp._cmp(r,t))}}}},F=n.ELEMENT_OPERATORS={$lt:L(function(e){return 0>e}),$gt:L(function(e){return e>0}),$lte:L(function(e){return 0>=e}),$gte:L(function(e){return e>=0}),$mod:{compileElementSelector:function(e){if(!(0,M.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,M.isArray)(e))throw Error("$in needs an array");var t=[];return(0,y["default"])(e,function(e){if(e instanceof RegExp)t.push(a(e));else{if((0,M.isOperatorObject)(e))throw Error("cannot nest $ under $in");t.push(s(e))}}),function(e){return void 0===e&&(e=null),(0,w["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,M.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&&M.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 a(n)}},$elemMatch:{dontExpandLeafArrays:!0,compileElementSelector:function(e,t,n){if(!(0,M.isPlainObject)(e))throw Error("$elemMatch need an object");var r,i;return(0,M.isOperatorObject)(e,!0)?(r=N(e,n),i=!1):(r=A(e,n,{inElemMatch:!0}),i=!0),function(e){if(!(0,M.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");o=n.$slice}var u=void 0;if(n.$sort){if(void 0===o)throw new Error("$sort requires $slice to be present");u=new E["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 i=[];if(null==n||"object"!==("undefined"==typeof n?"undefined":o(n))||n instanceof Array)for(var u=0;u0?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){return r.push(e.db.create(t.value))}).on("end",function(){return t(r)})})}},{key:"retriveIds",value:function(e){var t=this,n=(0,l["default"])(e,function(e){return t.retriveOne(e)});return Promise.all(n)}},{key:"retriveOne",value:function(e){var t=this;return this.db.storage.get(e).then(function(e){return t.db.create(e)})}}]),e}();n["default"]=h},{"./Document":6,"check-types":17,"fast.js/map":26,"fast.js/object/keys":29}],10:[function(e,t,n){"use strict";function r(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function i(e){return e&&e.__esModule?e:{"default":e}}function o(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":"undefined"==typeof e?"undefined":r(e)}function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var 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 w["default"](s)}this._keyComparator=O((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 O([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(",")+","},i=null;if((0,l["default"])(this._sortSpecParts,function(t,o){var u=(0,_.expandArraysInBranches)(t.lookup(e),!0);u.length||(u=[{value:null}]);var a=!1;if(n[o]={},(0,l["default"])(u,function(e){if(!e.arrayIndices){if(u.length>1)throw Error("multiple branches but no array used?");return void(n[o][""]=e.value)}a=!0;var t=r(e.arrayIndices);if(n[o].hasOwnProperty(t))throw Error("duplicate path: "+t);if(n[o][t]=e.value,i&&!i.hasOwnProperty(t))throw Error("cannot index parallel arrays")}),i){if(!n[o].hasOwnProperty("")&&(0,b["default"])(i).length!==(0,b["default"])(n[o]).length)throw Error("cannot index parallel arrays!")}else a&&(i={},(0,l["default"])(n[o],function(e,t){i[t]=!0}))}),!i){var o=(0,y["default"])(n,function(e){if(!e.hasOwnProperty(""))throw Error("no value in sole key case?");return e[""]});return void t(o)}(0,l["default"])(i,function(e,r){var i=(0,y["default"])(n,function(e){if(e.hasOwnProperty(""))return e[""];if(!e.hasOwnProperty(r))throw Error("missing path?");return e[r]});t(i)})}},{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 i=j.MongoTypeComp._cmp(n[e],r[e]);return t&&(i=-i),i}}},{key:"_getBaseComparator",value:function(){var e=this;return this._sortSpecParts.length?function(t,n){var r=e._getMinKeyFromDoc(t),i=e._getMinKeyFromDoc(n);return e._compareKeys(r,i)}: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)){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,j.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"]=E;var O=function(e){return function(t,n){for(var r=0;r=c.length?!1:o!==c[r]?!1:i.equals(e[o],t[c[r]],n)?(r++,!0):!1}),f&&r===c.length}return r=0,f=(0,b["default"])(e).every(function(o){return s(t,o)&&i.equals(e[o],t[o],n)?(r++,!0):!1}),f&&(0,b["default"])(t).length===r}},{key:"clone",value:function(e){var t,n=this;if("object"!==("undefined"==typeof e?"undefined":u(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,w["default"])(t,function(t,r){n[r]=e.toJSONValue(t)}),{$escape:n}},fromJSONValue:function(t){var n={};return(0,w["default"])(t.$escape,function(t,r){n[r]=e.fromJSONValue(t)}),n}},{matchJSONValue:function(e){return s(e,"$type")&&s(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(!s(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&&s(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":u(e))?e:((0,w["default"])(e,function(n,r){if("object"===("undefined"==typeof n?"undefined":u(n))||void 0===n||f(n)){var i=t._toJSONValueHelper(n);return i?void(e[r]=i):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"]=_},{"./CollectionIndex":3,"./DocumentRetriver":9,"./PromiseQueue":13,"fast.js/forEach":24,"fast.js/map":26,"fast.js/object/keys":29,invariant:33}],13:[function(e,t,n){"use strict";function r(e,t){this.pendingPromises=0,this.maxPendingPromises="undefined"!=typeof e?e:1/0,this.maxQueuedPromises="undefined"!=typeof t?t:1/0,this.queue=[]}Object.defineProperty(n,"__esModule",{value:!0}),n["default"]=r;var i="undefined"!=typeof Promise?Promise:function(){return{then:function(){throw new Error("Queue.configure() before use Queue")}}},o=function(){},u=function(e){return e&&"function"==typeof e.then?e:new i(function(t){t(e)})};r.configure=function(e){i=e},r.prototype.add=function(e){var t=this;return new i(function(n,r,i){return t.queue.length>=t.maxQueuedPromises?void r(new Error("Queue limit reached")):(t.queue.push({promiseGenerator:e,resolve:n,reject:r,notify:i||o}),void t._dequeue())})},r.prototype.getPendingLength=function(){return this.pendingPromises},r.prototype.getQueueLength=function(){return this.queue.length},r.prototype._dequeue=function(){var e=this;if(this.pendingPromises>=this.maxPendingPromises)return!1;var t=this.queue.shift();if(!t)return!1;try{this.pendingPromises++,u(t.promiseGenerator()).then(function(n){e.pendingPromises--,t.resolve(n),e._dequeue()},function(n){e.pendingPromises--,t.reject(n),e._dequeue()},function(e){t.notify(e)})}catch(n){e.pendingPromises--,t.reject(n),e._dequeue()}return!0}},{}],14:[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 i=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,i=0,o=1;0==t.length&&(t=[+new Date]);var u=e();n=u(" "),r=u(" "),i=u(" ");for(var a=0;an&&(n+=1),r-=u(t[a]),0>r&&(r+=1),i-=u(t[a]),0>i&&(i+=1);u=null;var s=function(){var e=2091639*n+2.3283064365386963e-10*o;return n=r,r=i,i=e-(o=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))},u="23456789ABCDEFGHJKLMNPQRSTWXYZabcdefghijkmnopqrstuvwxyz",a="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_",s=n.Random=function(){function e(){r(this,e);var t=arguments[0];if(!(void 0!==t||"undefined"!=typeof window&&window.crypto&&window.crypto.getRandomValues)){ +var n="undefined"!=typeof window&&window.innerHeight||"undefined"!=typeof document&&document.documentElement&&document.documentElement.clientHeight||"undefined"!=typeof document&&document.body&&document.body.clientHeight||1,i="undefined"!=typeof window&&window.innerWidth||"undefined"!=typeof document&&document.documentElement&&document.documentElement.clientWidth||"undefined"!=typeof document&&document.body&&document.body.clientWidth||1,u="undefined"!=typeof navigator&&navigator.userAgent||"";t=[new Date,n,i,u,Math.random()]}void 0!==t&&(this.alea=o.apply(null,t))}return i(e,[{key:"fraction",value:function(){var e=this;if(e.alea)return e.alea();if("undefined"!=typeof window&&window.crypto&&window.crypto.getRandomValues){var t=new Uint32Array(1);return window.crypto.getRandomValues(t),2.3283064365386963e-10*t[0]}throw new Error("No random generator available")}},{key:"hexString",value:function(e){for(var t=this,n=[],r=0;e>r;++r)n.push(t.choice("0123456789abcdef"));return n.join("")}},{key:"_randomString",value:function(e,t){for(var n=this,r=[],i=0;e>i;i++)r[i]=n.choice(t);return r.join("")}},{key:"id",value:function(e){var t=this;return void 0===e&&(e=17),t._randomString(e,u)}},{key:"secret",value:function(e){var t=this;return void 0===e&&(e=43),t._randomString(e,a)}},{key:"choice",value:function(e){var t=Math.floor(this.fraction()*e.length);return"string"==typeof e?e.substr(t,1):e[t]}}],[{key:"createWithSeed",value:function(){if(0===arguments.length)throw new Error("No seeds were provided");return new e(arguments)}}]),e}();n["default"]=s},{}],15:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function i(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;nt}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 w(e){return"string"==typeof e}function j(e){return""===e}function E(e){return w(e)&&""!==e}function O(e,t){return w(e)&&-1!==e.indexOf(t)}function k(e,t){return w(e)&&!!e.match(t)}function S(e){return e===!1||e===!0}function x(e){return"[object Object]"===Object.prototype.toString.call(e)}function P(e){return x(e)&&0===Object.keys(e).length}function I(e,t){try{return e instanceof t}catch(n){return!1}}function M(e,t){try{return I(e,t)||Object.prototype.toString.call(e)==="[object "+t.name+"]"}catch(n){return!1}}function $(e,t){try{return I(e,t)||e.constructor.name===t.name}catch(n){return!1}}function A(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(x(e[n])&&A(e[n],t[n])===!1)return!1}return!0}function N(e){return Array.isArray(e)}function C(e){return N(e)&&0===e.length}function T(e){return u(e)&&f(e.length)}function J(e){return"undefined"==typeof Symbol?T(e):u(e)&&V(e[Symbol.iterator])}function D(e,t){var n,r;if(ge.assigned(e))return!1;try{if("undefined"!=typeof Symbol&&e[Symbol.iterator]&&V(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(i){return!0}return!1}function R(e,t){return u(e)&&e.length===t}function q(e){return M(e,Date)&&!isNaN(e.getTime())}function V(e){return"function"==typeof e}function B(e,t){return me.array(e),V(t)?e.map(function(e){return t(e)}):(me.array(t),me.hasLength(e,t.length),e.map(function(e,n){return t[n](e)}))}function L(e,t){return me.object(e),V(t)?F(e,t):(me.object(t),U(e,t))}function F(e,t){var n={};return Object.keys(e).forEach(function(r){n[r]=t(e[r])}),n}function U(e,t){var n={};return Object.keys(t).forEach(function(r){var i=t[r];V(i)?ge.assigned(e)?n[r]=!!i._isMaybefied:n[r]=i(e[r]):x(i)&&(n[r]=U(e[r],i))}),n}function W(e){return N(e)?Q(e,!1):(me.object(e),G(e,!1))}function Q(e,t){var n;for(n=0;ni;i++)a[i]=r[i].fn;return a},i.prototype.emit=function(e,t,n,r,i,u){var a=o?o+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,i),!0;case 6:return c.fn.call(c.context,t,n,r,i,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},i.prototype.on=function(e,t,n){var i=new r(t,n||this),u=o?o+e:e;return this._events||(this._events=o?{}:Object.create(null)),this._events[u]?this._events[u].fn?this._events[u]=[this._events[u],i]:this._events[u].push(i):this._events[u]=i,this},i.prototype.once=function(e,t,n){var i=new r(t,n||this,!0),u=o?o+e:e;return this._events||(this._events=o?{}:Object.create(null)),this._events[u]?this._events[u].fn?this._events[u]=[this._events[u],i]:this._events[u].push(i):this._events[u]=i,this},i.prototype.removeListener=function(e,t,n,r){var i=o?o+e:e;if(!this._events||!this._events[i])return this;var u=this._events[i],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[i]=1===a.length?a[0]:a:delete this._events[i],this},i.prototype.removeAllListeners=function(e){return this._events?(e?delete this._events[o?o+e:e]:this._events=o?{}:Object.create(null),this):this},i.prototype.off=i.prototype.removeListener,i.prototype.addListener=i.prototype.on,i.prototype.setMaxListeners=function(){return this},i.prefixed=o,"undefined"!=typeof t&&(t.exports=i)},{}],19:[function(e,t,n){"use strict";var r=e("../function/bindInternal3");t.exports=function(e,t,n){var i,o=e.length,u=void 0!==n?r(t,n):t;for(i=0;o>i;i++)if(!u(e[i],i,e))return!1;return!0}},{"../function/bindInternal3":25}],20:[function(e,t,n){"use strict";var r=e("../function/bindInternal3");t.exports=function(e,t,n){var i,o=e.length,u=void 0!==n?r(t,n):t;for(i=0;o>i;i++)u(e[i],i,e)}},{"../function/bindInternal3":25}],21:[function(e,t,n){"use strict";t.exports=function(e,t,n){var r=e.length,i=0;for("number"==typeof n&&(i=n,0>i&&(i+=r,0>i&&(i=0)));r>i;i++)if(e[i]===t)return i;return-1}},{}],22:[function(e,t,n){"use strict";var r=e("../function/bindInternal3");t.exports=function(e,t,n){var i,o=e.length,u=new Array(o),a=void 0!==n?r(t,n):t;for(i=0;o>i;i++)u[i]=a(e[i],i,e);return u}},{"../function/bindInternal3":25}],23:[function(e,t,n){"use strict";var r=e("../function/bindInternal3");t.exports=function(e,t,n){var i,o=e.length,u=void 0!==n?r(t,n):t;for(i=0;o>i;i++)if(u(e[i],i,e))return!0;return!1}},{"../function/bindInternal3":25}],24:[function(e,t,n){"use strict";var r=e("./array/forEach"),i=e("./object/forEach");t.exports=function(e,t,n){return e instanceof Array?r(e,t,n):i(e,t,n)}},{"./array/forEach":20,"./object/forEach":28}],25:[function(e,t,n){"use strict";t.exports=function(e,t){return function(n,r,i){return e.call(t,n,r,i)}}},{}],26:[function(e,t,n){"use strict";var r=e("./array/map"),i=e("./object/map");t.exports=function(e,t,n){return e instanceof Array?r(e,t,n):i(e,t,n)}},{"./array/map":22,"./object/map":30}],27:[function(e,t,n){"use strict";t.exports=function(e){var t,n,r,i,o,u,a=arguments.length;for(n=1;a>n;n++)for(t=arguments[n],i=Object.keys(t),r=i.length,u=0;r>u;u++)o=i[u],e[o]=t[o];return e}},{}],28:[function(e,t,n){"use strict";var r=e("../function/bindInternal3");t.exports=function(e,t,n){var i,o,u=Object.keys(e),a=u.length,s=void 0!==n?r(t,n):t;for(o=0;a>o;o++)i=u[o],s(e[i],i,e)}},{"../function/bindInternal3":25}],29:[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}},{}],30:[function(e,t,n){"use strict";var r=e("../function/bindInternal3");t.exports=function(e,t,n){var i,o,u=Object.keys(e),a=u.length,s={},f=void 0!==n?r(t,n):t;for(i=0;a>i;i++)o=u[i],s[o]=f(e[o],o,e);return s}},{"../function/bindInternal3":25}],31:[function(e,t,n){!function(){function e(e){for(var t=[],n=[],r=0;rt!=r[o][0]>t&&e<(r[o][1]-r[i][1])*(t-r[i][0])/(r[o][0]-r[i][0])+r[i][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 i=0;i<=t.coordinates.length-2;++i){var o={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[i][1],y:t.coordinates[i][0]},s={x:t.coordinates[i+1][1],y:t.coordinates[i+1][0]},f=(s.x-a.x)*(o.y-a.y)-(s.y-a.y)*(o.x-a.x),c=(u.x-o.x)*(o.y-a.y)-(u.y-o.y)*(o.x-a.x),l=(s.y-a.y)*(u.x-o.x)-(s.x-a.x)*(u.y-o.y);if(0!=l){var d=f/l,h=c/l;d>=0&&1>=d&&h>=0&&1>=h&&n.push({type:"Point",coordinates:[o.x+d*(u.x-o.x),o.y+d*(u.y-o.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,i){for(var o="Polygon"==i.type?[i.coordinates]:i.coordinates,u=!1,a=0;as;s++){var f=2*Math.PI*s/n,c=Math.asin(Math.sin(u[0])*Math.cos(o)+Math.cos(u[0])*Math.sin(o)*Math.cos(f)),l=u[1]+Math.atan2(Math.sin(f)*Math.sin(o)*Math.cos(u[0]),Math.cos(o)-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],i=t[2][0],o=t[2][1],u=i-n,a=o-r;return{type:"Point",coordinates:[n+u/2,r+a/2]}},r.pointDistance=function(e,t){var n=e.coordinates[0],i=e.coordinates[1],o=t.coordinates[0],u=t.coordinates[1],a=r.numberToRadius(u-i),s=r.numberToRadius(o-n),f=Math.pow(Math.sin(a/2),2)+Math.cos(r.numberToRadius(i))*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 i,o={};i="Polygon"==e.type?e.coordinates[0]:e.coordinates;for(var u in i)if(o.coordinates=i[u],r.pointDistance(o,t)>n)return!1}return!0},r.area=function(e){for(var t,n,r=0,i=e.coordinates[0],o=i.length-1,u=0;u0;)if(o=E[r-1],u=O[r-1],r--,u-o>1){for(d=e[u].lng()-e[o].lng(),h=e[u].lat()-e[o].lat(),Math.abs(d)>180&&(d=360-Math.abs(d)),d*=Math.cos(w*(e[u].lat()+e[o].lat())),p=d*d+h*h,a=o+1,s=o,c=-1;u>a;a++)y=e[a].lng()-e[o].lng(),v=e[a].lat()-e[o].lat(),Math.abs(y)>180&&(y=360-Math.abs(y)),y*=Math.cos(w*(e[a].lat()+e[o].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(w*(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?(j[i]=o,i++):(r++,E[r-1]=s,O[r-1]=u,r++,E[r-1]=o,O[r-1]=s)}else j[i]=o,i++;j[i]=n-1,i++;for(var k=new Array,a=0;i>a;a++)k.push(e[j[a]]);return k.map(function(e){return{type:"Point",coordinates:[e.lng,e.lat]}})},r.destinationPoint=function(e,t,n){n/=6371,t=r.numberToRadius(t);var i=r.numberToRadius(e.coordinates[0]),o=r.numberToRadius(e.coordinates[1]),u=Math.asin(Math.sin(o)*Math.cos(n)+Math.cos(o)*Math.sin(n)*Math.cos(t)),a=i+Math.atan2(Math.sin(t)*Math.sin(n)*Math.cos(o),Math.cos(n)-Math.sin(o)*Math.sin(u));return a=(a+3*Math.PI)%(2*Math.PI)-Math.PI,{type:"Point",coordinates:[r.numberToDegree(a),r.numberToDegree(u)]}}}()},{}],32:[function(e,t,n){"use strict";var r=function(e){var t,n={};if(!(e instanceof Object)||Array.isArray(e))throw new Error("keyMirror(...): Argument must be an object.");for(t in e)e.hasOwnProperty(t)&&(n[t]=t);return n};t.exports=r},{}],33:[function(e,t,n){"use strict";var r=function(e,t,n,r,i,o,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,i,o,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},{}]},{},[16])(16)}); \ No newline at end of file diff --git a/dist/Cursor.js b/dist/Cursor.js index 79163ca..3d42eab 100644 --- a/dist/Cursor.js +++ b/dist/Cursor.js @@ -45,6 +45,10 @@ var _DocumentSorter = require('./DocumentSorter'); var _DocumentSorter2 = _interopRequireDefault(_DocumentSorter); +var _EJSON = require('./EJSON'); + +var _EJSON2 = _interopRequireDefault(_EJSON); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; } @@ -301,7 +305,10 @@ var Cursor = (function (_EventEmitter) { var _this3 = this; this._executing = this._matchObjects().then(function (docs) { - return _this3.processPipeline(docs); + var clonned = (0, _map3.default)(docs, function (doc) { + return _EJSON2.default.clone(doc); + }); + return _this3.processPipeline(clonned); }).then(function (docs) { _this3._executing = null; return docs; diff --git a/dist/StorageManager.js b/dist/StorageManager.js index 1cc6fc2..96292e2 100644 --- a/dist/StorageManager.js +++ b/dist/StorageManager.js @@ -7,10 +7,6 @@ Object.defineProperty(exports, "__esModule", { }); exports.StorageManager = undefined; -var _keys2 = require('fast.js/object/keys'); - -var _keys3 = _interopRequireDefault(_keys2); - var _forEach = require('fast.js/forEach'); var _forEach2 = _interopRequireDefault(_forEach); @@ -71,7 +67,7 @@ var StorageManager = exports.StorageManager = (function () { value: function destroy() { var _this2 = this; - return this._loadedPromise.then(function () { + return this.loaded().then(function () { _this2._storage = {}; }); } @@ -80,7 +76,7 @@ var StorageManager = exports.StorageManager = (function () { value: function persist(key, value) { var _this3 = this; - return this._loadedPromise.then(function () { + return this.loaded().then(function () { _this3._storage[key] = _EJSON2.default.clone(value); }); } @@ -89,7 +85,7 @@ var StorageManager = exports.StorageManager = (function () { value: function _delete(key) { var _this4 = this; - return this._loadedPromise.then(function () { + return this.loaded().then(function () { delete _this4._storage[key]; }); } @@ -98,8 +94,8 @@ var StorageManager = exports.StorageManager = (function () { value: function get(key) { var _this5 = this; - return this._loadedPromise.then(function () { - return _EJSON2.default.clone(_this5._storage[key]); + return this.loaded().then(function () { + return _this5._storage[key]; }); } }, { @@ -108,9 +104,9 @@ var StorageManager = exports.StorageManager = (function () { var _this6 = this; var emitter = new _eventemitter2.default(); - this._loadedPromise.then(function () { - (0, _forEach2.default)((0, _keys3.default)(_this6._storage), function (k) { - emitter.emit('data', { value: _EJSON2.default.clone(_this6._storage[k]) }); + this.loaded().then(function () { + (0, _forEach2.default)(_this6._storage, function (v, k) { + emitter.emit('data', { value: v }); }); emitter.emit('end'); }); diff --git a/package.json b/package.json index 05c4e83..d4d198a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "marsdb", - "version": "0.4.1", + "version": "0.4.2", "author": { "name": "Artem Artemev", "email": "art@studytime.me"