marsdb-sync-client
Advanced tools
Comparing version 0.2.8 to 0.2.9
@@ -1,2 +0,2 @@ | ||
!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||(t.Mars={})).Client=e()}}(function(){return function e(t,n,r){function o(a,s){if(!n[a]){if(!t[a]){var u="function"==typeof require&&require;if(!s&&u)return u(a,!0);if(i)return i(a,!0);var c=new Error("Cannot find module '"+a+"'");throw c.code="MODULE_NOT_FOUND",c}var l=n[a]={exports:{}};t[a][0].call(l.exports,function(e){var n=t[a][1][e];return o(n?n:e)},l,l.exports,e,t,n,r)}return n[a].exports}for(var i="function"==typeof require&&require,a=0;a<r.length;a++)o(r[a]);return o}({1:[function(e,t,n){(function(t){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof 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 u(e){var n=b.defaultDelegate(),r=function(n){function r(){var n;i(this,r);for(var o=arguments.length,s=Array(o),u=0;o>u;u++)s[u]=arguments[u];var c=a(this,(n=Object.getPrototypeOf(r)).call.apply(n,[this].concat(s)));return e.on("status:connected",(0,h["default"])(c._handleConnected,c)),e.on("message:added",(0,h["default"])(c._handleRemoteAdded,c)),e.on("message:changed",(0,h["default"])(c._handleRemoteChanged,c)),e.on("message:removed",(0,h["default"])(c._handleRemoteRemoved,c)),t.nextTick(function(){e.isConnected&&c._handleConnected(!1)}),c}return s(r,n),l(r,[{key:"insert",value:function(t){var n=this,o=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],i=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],a=void 0,s=o.quiet,u=o.retryOnDisconnect,c=void 0===u?!0:u,l=o.waitResult;if(!s){var d="/"+this.db.modelName+"/insert",h={retryOnDisconnect:!!c,randomSeed:i.seed},p=e.methodManager.apply(d,[t],h);if(l)return p.then(function(){return t._id});p.then(null,function(e){return a.then(function(){return n.db.remove(t._id,{quiet:!0})}).then(function(){throw e})})}return a=f(Object.getPrototypeOf(r.prototype),"insert",this).call(this,t,o,i)}},{key:"remove",value:function(t){var n=this,o=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],i=void 0,a=o.quiet,s=o.retryOnDisconnect,u=void 0===s?!0:s,c=o.waitResult;if(!a){var l="/"+this.db.modelName+"/remove",d={retryOnDisconnect:!!u},h=e.methodManager.apply(l,[t],d);if(c)return h;h.then(null,function(e){return i.then(function(e){return n.db.insertAll(e,{quiet:!0})}).then(function(){throw e})})}return i=f(Object.getPrototypeOf(r.prototype),"remove",this).call(this,t,o)}},{key:"update",value:function(t,n){var i=this,a=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],s=void 0,u=a.quiet,c=a.retryOnDisconnect,l=void 0===c?!0:c,d=a.waitResult,h=o(a,["quiet","retryOnDisconnect","waitResult"]);if(!u){var p="/"+this.db.modelName+"/update",y={retryOnDisconnect:!!l},v=e.methodManager.apply(p,[t,n,h],y);if(d)return v;v.then(null,function(e){return s.then(function(e){return(0,m["default"])(e.updated,function(t,n){if(e.original[n]){var r=e.original[n]._id;return delete e.original[n]._id,i.db.update({_id:r},e.original[n],{quiet:!0,upsert:!0})}return i.db.remove(t._id,{quiet:!0})})}).then(function(){throw e})})}return s=f(Object.getPrototypeOf(r.prototype),"update",this).call(this,t,n,a)}},{key:"_handleConnected",value:function(t){var n=this,r="/"+this.db.modelName+"/sync";return this.db.ids().then(function(t){return e.methodManager.apply(r,[t]).result()}).then(function(e){return n.db.remove({_id:{$in:e}},{quiet:!0,multi:!0})})}},{key:"_handleRemoteAdded",value:function(e){return e.collection===this.db.modelName?(delete e.fields._id,this.db.update({_id:e.id},e.fields,{quiet:!0,upsert:!0})):Promise.resolve()}},{key:"_handleRemoteChanged",value:function(e){var t=this;if(e.collection!==this.db.modelName)return Promise.resolve();var n=function(){var n={};if(Array.isArray(e.cleared)&&e.cleared.length>0){n.$unset={};var r=!0,o=!1,i=void 0;try{for(var a,s=e.cleared[Symbol.iterator]();!(r=(a=s.next()).done);r=!0){var u=a.value;n.$unset[u]=1}}catch(c){o=!0,i=c}finally{try{!r&&s["return"]&&s["return"]()}finally{if(o)throw i}}}return e.fields&&(delete e.fields._id,n.$set={},(0,y["default"])(e.fields,function(e,t){n.$set[t]=e})),(0,g["default"])(n).length>0?{v:t.db.update(e.id,n,{quiet:!0})}:void 0}();return"object"===("undefined"==typeof n?"undefined":c(n))?n.v:void 0}},{key:"_handleRemoteRemoved",value:function(e){return e.collection===this.db.modelName?this.db.remove(e.id,{quiet:!0}):Promise.resolve()}}]),r}(n);return 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?"symbol":typeof e},l=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),f=function w(e,t,n){null===e&&(e=Function.prototype);var r=Object.getOwnPropertyDescriptor(e,t);if(void 0===r){var o=Object.getPrototypeOf(e);return null===o?void 0:w(o,t,n)}if("value"in r)return r.value;var i=r.get;if(void 0!==i)return i.call(n)};Object.defineProperty(n,"__esModule",{value:!0}),n.createCollectionDelegate=u;var d=e("fast.js/function/bind"),h=r(d),p=e("fast.js/forEach"),y=r(p),v=e("fast.js/map"),m=r(v),_=e("fast.js/object/keys"),g=r(_),b="undefined"!=typeof window&&window.Mars?window.Mars.Collection:e("marsdb").Collection}).call(this,e("_process"))},{_process:25,"fast.js/forEach":14,"fast.js/function/bind":17,"fast.js/map":20,"fast.js/object/keys":22,marsdb:void 0}],2:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof 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 u(e,t){var n=!1;return"function"==typeof e?n=e(t):(Array.isArray(t)&&t.length>0||"[object Object]"===Object.prototype.toString.call(t)&&(0,h["default"])(t).length>0)&&(n=!0),n}function c(e){var t=p.defaultCursor(),n=function(t){function n(){return i(this,n),a(this,Object.getPrototypeOf(n).apply(this,arguments))}return s(n,t),l(n,[{key:"_doUpdate",value:function(t){var r=this,i=this.options,a=i.sub,s=i.waitReady,c=i.tryCache,l=function(){return f(Object.getPrototypeOf(n.prototype),"_doUpdate",r).call(r,t)};if(!this._subscription&&a){var d;if(this._subscription=(d=e.subManager).subscribe.apply(d,o(a)),this.once("observeStopped",function(){r._subscription.stop(),delete r._subscription}),s)return this._subscription.ready().then(l);if(c)return this.exec().then(function(e){return u(c,e)?(r._updateLatestIds(),r._propagateUpdate(t).then(function(){return e})):r._subscription.ready().then(l)})}return l()}}]),n}(t);return n}var l=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),f=function y(e,t,n){null===e&&(e=Function.prototype);var r=Object.getOwnPropertyDescriptor(e,t);if(void 0===r){var o=Object.getPrototypeOf(e);return null===o?void 0:y(o,t,n)}if("value"in r)return r.value;var i=r.get;if(void 0!==i)return i.call(n)};Object.defineProperty(n,"__esModule",{value:!0}),n._isCacheValid=u,n.createCursorWithSub=c;var d=e("fast.js/object/keys"),h=r(d),p="undefined"!=typeof window&&window.Mars?window.Mars.Collection:e("marsdb").Collection},{"fast.js/object/keys":22,marsdb:void 0}],3:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof 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 "+typeof 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<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();Object.defineProperty(n,"__esModule",{value:!0}),n.CONN_STATUS=void 0;var u=e("fast.js/function/try"),c=r(u),l=e("fast.js/function/bind"),f=r(l),d=e("./HeartbeatManager"),h=r(d),p="undefined"!=typeof window&&window.Mars?window.Mars.EventEmitter:e("marsdb").EventEmitter,y="undefined"!=typeof window&&window.Mars?window.Mars.PromiseQueue:e("marsdb").PromiseQueue,v="undefined"!=typeof window&&window.Mars?window.Mars.EJSON:e("marsdb").EJSON,m="undefined"!=typeof window&&window.Mars?window.Mars.Random:e("marsdb").Random,_="1",g=17500,b=15e3,w=5e3,E=n.CONN_STATUS={CONNECTING:"CONNECTING",CONNECTED:"CONNECTED",DISCONNECTED:"DISCONNECTED"},O=function(e){function t(e){var n=e.url,r=e.socket,a=e.autoReconnect,s=void 0===a?!0:a;o(this,t);var u=i(this,Object.getPrototypeOf(t).call(this));return u.url=n,u._processQueue=new y(1),u._sessionId=null,u._autoReconnect=s,u._socket=r,u._status=E.DISCONNECTED,u._fullConnectedOnce=!1,u._heartbeat=new h["default"](g,b),u._heartbeat.on("timeout",(0,f["default"])(u._handleHearbeatTimeout,u)),u._heartbeat.on("sendPing",(0,f["default"])(u.sendPing,u)),u._heartbeat.on("sendPong",(0,f["default"])(u.sendPong,u)),u}return a(t,e),s(t,[{key:"sendMethod",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?[]:arguments[1],n=arguments[2],r=arguments[3],o={msg:"method",id:n,method:e,params:t};r&&(o.randomSeed=r),this._sendMessage(o)}},{key:"sendSub",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?[]:arguments[1],n=arguments[2];this._sendMessage({msg:"sub",id:n,name:e,params:t})}},{key:"sendUnsub",value:function(e){this._sendMessage({msg:"unsub",id:e})}},{key:"sendPing",value:function(){this._sendMessage({msg:"ping",id:m["default"]().id(20)})}},{key:"sendPong",value:function(e){this._sendMessage({msg:"pong",id:e})}},{key:"connect",value:function(){return this.isDisconnected?(this._rawConn=new this._socket(this.url),this._rawConn.onopen=(0,f["default"])(this._handleOpen,this),this._rawConn.onerror=(0,f["default"])(this._handleError,this),this._rawConn.onclose=(0,f["default"])(this._handleClose,this),this._rawConn.onmessage=(0,f["default"])(this._handleRawMessage,this),this._setStatus(E.CONNECTING),!0):!1}},{key:"reconnect",value:function(){var e=this;return this.isDisconnected?(clearTimeout(this._reconnTimer),this._reconnecting=!0,this._reconnTimer=setTimeout((0,f["default"])(this.connect,this),w),function(){clearTimeout(e._reconnTimer),e._reconnecting=!1,e.disconnect()}):void 0}},{key:"disconnect",value:function(){var e=this;(0,c["default"])(function(){return e._rawConn&&e._rawConn.close()})}},{key:"_handleOpen",value:function(){this._heartbeat.waitPing();var e={msg:"connect",version:_,support:[_]};this._sessionId&&(e.session=this._sessionId),this._sendMessage(e)}},{key:"_handleConnectedMessage",value:function(e){if(!this.isConnected){var t=this._fullConnectedOnce&&this._reconnecting;this._setStatus(E.CONNECTED,t),this._sessionId=e.session,this._reconnecting=!1,this._fullConnectedOnce=!0}}},{key:"_handleClose",value:function(){this._heartbeat._clearTimers(),this._setStatus(E.DISCONNECTED,this._fullConnectedOnce),this._autoReconnect&&(this._reconnecting=!1,this.reconnect())}},{key:"_handleHearbeatTimeout",value:function(){this.disconnect()}},{key:"_handleError",value:function(e){this.emit("error",e)}},{key:"_handleRawMessage",value:function(e){var t=this;return this._processQueue.add(function(){var n=v.parse(e.data);return t._processMessage(n)}).then(null,function(e){t._handleError(e)})}},{key:"_processMessage",value:function(e){switch(e.msg){case"connected":return this._handleConnectedMessage(e);case"ping":return this._heartbeat.handlePing(e);case"pong":return this._heartbeat.handlePong(e);case"removed":case"changed":case"added":case"updated":case"result":case"nosub":case"ready":case"error":return this.emitAsync("message:"+e.msg,e)}}},{key:"_sendMessage",value:function(e){var t=this,n=(0,c["default"])(function(){return t._rawConn.send(v.stringify(e))});n instanceof Error&&this._handleError(n)}},{key:"_setStatus",value:function(e,t){this._status=e,this.emit(("status:"+e).toLowerCase(),t)}},{key:"isConnected",get:function(){return this._status===E.CONNECTED}},{key:"isDisconnected",get:function(){return this._status===E.DISCONNECTED}}]),t}(p);n["default"]=O},{"./HeartbeatManager":5,"fast.js/function/bind":17,"fast.js/function/try":19,marsdb:void 0}],4:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();Object.defineProperty(n,"__esModule",{value:!0});var a=e("fast.js/function/bind"),s=r(a),u=function(){function e(t){o(this,e),this.conn=t,t.on("message:error",(0,s["default"])(this._handleError,this)),t.on("error",(0,s["default"])(this._handleError,this))}return i(e,[{key:"_handleError",value:function(e){e&&e.message?console.warn(e.message+"\n"+e.stack):console.warn(JSON.stringify(e))}}]),e}();n["default"]=u},{"fast.js/function/bind":17}],5:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var a=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();Object.defineProperty(n,"__esModule",{value:!0});var s="undefined"!=typeof window&&window.Mars?window.Mars.EventEmitter:e("marsdb").EventEmitter,u=function(e){function t(){var e=arguments.length<=0||void 0===arguments[0]?17500:arguments[0],n=arguments.length<=1||void 0===arguments[1]?1e4:arguments[1];r(this,t);var i=o(this,Object.getPrototypeOf(t).call(this));return i.pingTimeout=e,i.pongTimeout=n,i}return i(t,e),a(t,[{key:"waitPing",value:function(){var e=this;this._clearTimers(),this.waitPingTimer=setTimeout(function(){e.emit("sendPing"),e.waitPong()},this.pingTimeout)}},{key:"waitPong",value:function(){var e=this;this._clearTimers(),this.waitPongTimer=setTimeout(function(){return e.emit("timeout")},this.pongTimeout)}},{key:"handlePing",value:function(e){this._clearTimers(),this.emit("sendPong",e),this.waitPing()}},{key:"handlePong",value:function(){this._clearTimers(),this.waitPing()}},{key:"_clearTimers",value:function(){clearTimeout(this.waitPingTimer),clearTimeout(this.waitPongTimer)}}]),t}(s);n["default"]=u},{marsdb:void 0}],6:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var a=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();Object.defineProperty(n,"__esModule",{value:!0});var s="undefined"!=typeof window&&window.Mars?window.Mars.EventEmitter:e("marsdb").EventEmitter,u="undefined"!=typeof window&&window.Mars?window.Mars.Random:e("marsdb").Random,c=n.CALL_STATUS={PENDING:"PENDING",SENT:"SENT",RESULT:"RESULT",ERROR:"ERROR",UPDATED:"UPDATED"},l=function(e){function t(e,n){var i=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],a=arguments[3];r(this,t);var s=o(this,Object.getPrototypeOf(t).call(this));return s.result=function(){return s._promiseMixed(new Promise(function(e,t){s._resulted?e(s._result):s._errored?t(s._error):(s.once(c.RESULT,e),s.once(c.ERROR,t))}))},s.updated=function(){return s._promiseMixed(new Promise(function(e,t){s._updated?e():s.once(c.UPDATED,e)}))},s.id=u["default"]().id(20),s.status=c.PENDING,s.method=e,s.params=n,s.options=i,s._conn=a,s}return i(t,e),a(t,[{key:"then",value:function(e,t){var n=this;return this.updated().then(function(){return n.result().then(e,t)},t)}},{key:"_invoke",value:function(){this._conn.sendMethod(this.method,this.params,this.id,this.options.randomSeed),this._setStatus(c.SENT)}},{key:"_retry",value:function(){this._setStatus(c.PENDING)}},{key:"_promiseMixed",value:function(e){var t=this;return{result:this.result,updated:this.updated,then:function(){return t._promiseMixed(e.then.apply(e,arguments))}}}},{key:"_handleResult",value:function(e,t){e?(this._errored=!0,this._error=e,this._setStatus(c.ERROR,e)):(this._resulted=!0,this._result=t,this._setStatus(c.RESULT,t))}},{key:"_handleUpdated",value:function(e){this._updated=!0,this._setStatus(c.UPDATED)}},{key:"_setStatus",value:function(e,t,n,r,o){this.status=e,this.emit(e,t,n,r,o)}},{key:"isPending",get:function(){return this.status===c.PENDING}},{key:"isSent",get:function(){return this.status===c.SENT}},{key:"isDone",get:function(){return this.status!==c.SENT&&this.status!==c.PENDING}}]),t}(s);n["default"]=l},{marsdb:void 0}],7:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();Object.defineProperty(n,"__esModule",{value:!0});var a=e("fast.js/function/bind"),s=r(a),u=e("fast.js/forEach"),c=r(u),l=e("./MethodCall"),f=r(l),d=function(){function e(t){o(this,e),this.conn=t,this._methods={},t.on("status:disconnected",(0,s["default"])(this._handleDisconnected,this)),t.on("status:connected",(0,s["default"])(this._handleConnected,this)),t.on("message:result",(0,s["default"])(this._handleMethodResult,this)),t.on("message:updated",(0,s["default"])(this._handleMethodUpdated,this))}return i(e,[{key:"call",value:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];return this.apply(e,n)}},{key:"apply",value:function(e){var t=this,n=arguments.length<=1||void 0===arguments[1]?[]:arguments[1],r=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],o=new f["default"](e,n,r,this.conn);this._methods[o.id]=o;var i=function(){return delete t._methods[o.id]};return o.then(i,i),this.conn.isConnected&&o._invoke(),o}},{key:"_handleMethodResult",value:function(e){if(e.id&&this._methods[e.id]){var t=e.result,n=e.error;this._methods[e.id]._handleResult(n,t)}}},{key:"_handleMethodUpdated",value:function(e){var t=this;(0,c["default"])(e.methods,function(e){t._methods[e]&&t._methods[e]._handleUpdated()})}},{key:"_handleDisconnected",value:function(){(0,c["default"])(this._methods,function(e){e.isSent&&(e.options.retryOnDisconnect?e._retry():e._handleResult({reason:"Disconnected, method can't be done",code:"DISCONNECTED"}))})}},{key:"_handleConnected",value:function(){(0,c["default"])(this._methods,function(e){e.isPending&&e._invoke()})}}]),e}();n["default"]=d},{"./MethodCall":6,"fast.js/forEach":14,"fast.js/function/bind":17}],8:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var a=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();Object.defineProperty(n,"__esModule",{value:!0});var s="undefined"!=typeof window&&window.Mars?window.Mars.EventEmitter:e("marsdb").EventEmitter,u="undefined"!=typeof window&&window.Mars?window.Mars.Random:e("marsdb").Random,c=n.SUB_STATUS={READY_PENDING:"READY_PENDING",READY:"READY",ERROR:"ERROR",STOP_PENDING:"STOP_PENDING",STOPPED:"STOPPED",FROZEN:"FROZEN"},l=function(e){function t(e,n,i){var a=arguments.length<=3||void 0===arguments[3]?15e3:arguments[3];r(this,t);var s=o(this,Object.getPrototypeOf(t).call(this));return s.ready=function(){return s._promiseMixed(new Promise(function(e,t){s.isReady?e():(s.once(c.READY,e),s.once(c.ERROR,t))}))},s.stopped=function(){return s._promiseMixed(new Promise(function(e,t){s.isStopped?e():(s.once(c.STOPPED,e),s.once(c.ERROR,t))}))},s.stop=function(){s._scheduleStop()},s.id=u["default"]().id(20),s.name=e,s.params=n,s._conn=i,s._ready=!1,s._stopWaitTimeout=a,s}return i(t,e),a(t,[{key:"then",value:function(e,t){return this.ready().then(e,t)}},{key:"_promiseMixed",value:function(e){var t=this;return{stopped:this.stopped,ready:this.ready,stop:this.stop,then:function(){return t._promiseMixed(e.then.apply(e,arguments))}}}},{key:"_subscribe",value:function(){this.status&&this.status!==c.STOP_PENDING&&this.status!==c.STOPPED&&this.status!==c.ERROR&&this.status!==c.FROZEN||(this.status===c.STOP_PENDING?this._ready?(this._clearStopper(),this._setStatus(c.READY)):this._setStatus(c.READY_PENDING):(this._setStatus(c.READY_PENDING),this._conn.sendSub(this.name,this.params,this.id)))}},{key:"_scheduleStop",value:function(){var e=this;this.status!==c.STOP_PENDING&&this.status!==c.STOPPED&&(this._setStatus(c.STOP_PENDING),this._stopTimer=setTimeout(function(){return e._stopImmediately()},this._stopWaitTimeout))}},{key:"_stopImmediately",value:function(e){this.status!==c.STOPPED&&(this._clearStopper(),this._setStatus(c.STOPPED),this._ready=!1,e&&e.dontSendMsg||this._conn.sendUnsub(this.id))}},{key:"_freeze",value:function(){this.status===c.STOP_PENDING?this._stopImmediately({dontSendMsg:!0}):this.status&&this.status===c.STOPPED||this._setStatus(c.FROZEN)}},{key:"_setStatus",value:function(e,t,n,r,o){this.status=e,this.emit(e,t,n,r,o)}},{key:"_clearStopper",value:function(){clearTimeout(this._stopTimer),this._stopTimer=null}},{key:"_handleNosub",value:function(e){this._clearStopper(),e?this._setStatus(c.ERROR,e):this._stopImmediately({dontSendMsg:!0})}},{key:"_handleReady",value:function(){this.status!==c.STOPPED&&this.status!==c.STOP_PENDING&&(this._ready=!0,this._setStatus(c.READY))}},{key:"isReady",get:function(){return this.status==c.READY||this.status===c.FROZEN&&this._ready}},{key:"isReadyPending",get:function(){return this.status===c.READY_PENDING}},{key:"isStopped",get:function(){return this.status===c.STOPPED}},{key:"isStopPending",get:function(){return this.status===c.STOP_PENDING}},{key:"isFaulted",get:function(){return this.status===c.ERROR}},{key:"isFrozen",get:function(){return this.status==c.FROZEN}}]),t}(s);n["default"]=l},{marsdb:void 0}],9:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof 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 "+typeof 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<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();Object.defineProperty(n,"__esModule",{value:!0});var u=e("fast.js/function/bind"),c=r(u),l=e("fast.js/forEach"),f=r(l),d=e("./Subscription"),h=r(d),p="undefined"!=typeof window&&window.Mars?window.Mars.EventEmitter:e("marsdb").EventEmitter,y=15e3,v=function(e){function t(e){o(this,t);var n=i(this,Object.getPrototypeOf(t).call(this));return n._subs={},n._loading=new Set,n._conn=e,e.on("status:connected",(0,c["default"])(n._handleConnected,n)),e.on("status:disconnected",(0,c["default"])(n._handleDisconnected,n)),e.on("message:ready",(0,c["default"])(n._handleSubscriptionReady,n)),e.on("message:nosub",(0,c["default"])(n._handleSubscriptionNosub,n)),n}return a(t,e),s(t,[{key:"subscribe",value:function(e){for(var t=this,n=arguments.length,r=Array(n>1?n-1:0),o=1;n>o;o++)r[o-1]=arguments[o];var i=new h["default"](e,r,this._conn,y);this._subs[i.id]=i,this._trackLoadingStart(i.id);var a=function(){delete t._subs[i.id],t._trackLoadingReady(i.id)};return i.once(d.SUB_STATUS.STOPPED,a),i.once(d.SUB_STATUS.ERROR,a),this._conn.isConnected?i._subscribe():i._freeze(),i}},{key:"addReadyListener",value:function(e){var t=this;return this.on("ready",e),function(){return t.removeListener("ready",e)}}},{key:"addLoadingListener",value:function(e){var t=this;return this.on("loading",e),function(){return t.removeListener("loading",e)}}},{key:"_handleConnected",value:function(){(0,f["default"])(this._subs,function(e){return e._subscribe()})}},{key:"_handleDisconnected",value:function(){var e=this;(0,f["default"])(this._subs,function(t,n){t._freeze(),t.isFrozen?e._trackLoadingStart(n):e._trackLoadingReady(n)})}},{key:"_handleSubscriptionReady",value:function(e){var t=this;(0,f["default"])(e.subs,function(e){var n=t._subs[e];n&&(n._handleReady(),t._trackLoadingReady(e))})}},{key:"_handleSubscriptionNosub",value:function(e){var t=this._subs[e.id];t&&t._handleNosub(e.error)}},{key:"_trackLoadingStart",value:function(e){var t=this._loading.size;this._loading.add(e),0===t&&this._loading.size>0&&this.emit("loading")}},{key:"_trackLoadingReady",value:function(e){var t=this._loading.size;this._loading["delete"](e),t>0&&0===this._loading.size&&this.emit("ready")}}]),t}(p);n["default"]=v},{"./Subscription":8,"fast.js/forEach":14,"fast.js/function/bind":17,marsdb:void 0}],10:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(){T=null}function i(){return T}function a(e){return(0,p["default"])(!T,"addManager(...): you can add managers only at first execution cycle"),k.push(e)}function s(){var e;return(0,p["default"])(T,"call(...): connection is not established yet. Please use Collection.startup(...) to initialize your app"),(e=T.methodManager).call.apply(e,arguments)}function u(){var e;return(0,p["default"])(T,"apply(...): connection is not established yet. Please use Collection.startup(...) to initialize your app"),(e=T.methodManager).apply.apply(e,arguments)}function c(){var e;return(0,p["default"])(T,"subscribe(...): connection is not established yet. Please use Collection.startup(...) to initialize your app"),(e=T.subManager).subscribe.apply(e,arguments)}function l(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return(0,p["default"])(e.socket||"undefined"!=typeof WebSocket,"configure(...): no socket consturctor provided and not available in global"),(0,p["default"])(!T,"configure(...): connection already configured"),e.socket=e.socket||WebSocket,T=new v["default"](e),S.defaultDelegate((0,O.createCollectionDelegate)(T)),S.defaultCursor((0,P.createCursorWithSub)(T)),T.customManagers=(0,d["default"])(k,function(e){return new e(T)}),T.methodManager=new b["default"](T),T.subManager=new _["default"](T),T.errorManager=new E["default"](T),T.connect(),T}Object.defineProperty(n,"__esModule",{value:!0}),n._removeConnection=o,n.getConnection=i,n.addManager=a,n.call=s,n.apply=u,n.subscribe=c,n.configure=l;var f=e("fast.js/map"),d=r(f),h=e("invariant"),p=r(h),y=e("./DDPConnection"),v=r(y),m=e("./SubscriptionManager"),_=r(m),g=e("./MethodCallManager"),b=r(g),w=e("./ErrorManager"),E=r(w),O=e("./CollectionManager"),P=e("./CursorWithSub"),S="undefined"!=typeof window&&window.Mars?window.Mars.Collection:e("marsdb").Collection,k=[],T=null},{"./CollectionManager":1,"./CursorWithSub":2,"./DDPConnection":3,"./ErrorManager":4,"./MethodCallManager":7,"./SubscriptionManager":9,"fast.js/map":20,invariant:24,marsdb:void 0}],11:[function(e,t,n){t.exports=e("./dist")},{"./dist":10}],12:[function(e,t,n){"use strict";var r=e("../function/bindInternal3");t.exports=function(e,t,n){var o,i=e.length,a=void 0!==n?r(t,n):t;for(o=0;i>o;o++)a(e[o],o,e)}},{"../function/bindInternal3":18}],13:[function(e,t,n){"use strict";var r=e("../function/bindInternal3");t.exports=function(e,t,n){var o,i=e.length,a=new Array(i),s=void 0!==n?r(t,n):t;for(o=0;i>o;o++)a[o]=s(e[o],o,e);return a}},{"../function/bindInternal3":18}],14:[function(e,t,n){"use strict";var r=e("./array/forEach"),o=e("./object/forEach");t.exports=function(e,t,n){return e instanceof Array?r(e,t,n):o(e,t,n)}},{"./array/forEach":12,"./object/forEach":21}],15:[function(e,t,n){"use strict";t.exports=function(e,t){switch(t.length){case 0:return e();case 1:return e(t[0]);case 2:return e(t[0],t[1]);case 3:return e(t[0],t[1],t[2]);case 4:return e(t[0],t[1],t[2],t[3]);case 5:return e(t[0],t[1],t[2],t[3],t[4]);case 6:return e(t[0],t[1],t[2],t[3],t[4],t[5]);case 7:return e(t[0],t[1],t[2],t[3],t[4],t[5],t[6]);case 8:return e(t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7]); | ||
default:return e.apply(void 0,t)}}},{}],16:[function(e,t,n){"use strict";t.exports=function(e,t,n){switch(n.length){case 0:return e.call(t);case 1:return e.call(t,n[0]);case 2:return e.call(t,n[0],n[1]);case 3:return e.call(t,n[0],n[1],n[2]);case 4:return e.call(t,n[0],n[1],n[2],n[3]);case 5:return e.call(t,n[0],n[1],n[2],n[3],n[4]);case 6:return e.call(t,n[0],n[1],n[2],n[3],n[4],n[5]);case 7:return e.call(t,n[0],n[1],n[2],n[3],n[4],n[5],n[6]);case 8:return e.call(t,n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]);default:return e.apply(t,n)}}},{}],17:[function(e,t,n){"use strict";var r=e("./applyWithContext"),o=e("./applyNoContext");t.exports=function(e,t){var n,i=arguments.length-2;if(i>0){n=new Array(i);for(var a=0;i>a;a++)n[a]=arguments[a+2];return void 0!==t?function(){var o,a=arguments.length,s=new Array(i+a);for(o=0;i>o;o++)s[o]=n[o];for(o=0;a>o;o++)s[i+o]=arguments[o];return r(e,t,s)}:function(){var t,r=arguments.length,a=new Array(i+r);for(t=0;i>t;t++)a[t]=n[t];for(t=0;r>t;t++)a[i+t]=arguments[t];return o(e,a)}}return void 0!==t?function(){return r(e,t,arguments)}:function(){return o(e,arguments)}}},{"./applyNoContext":15,"./applyWithContext":16}],18:[function(e,t,n){"use strict";t.exports=function(e,t){return function(n,r,o){return e.call(t,n,r,o)}}},{}],19:[function(e,t,n){"use strict";t.exports=function(e){try{return e()}catch(t){return t instanceof Error?t:new Error(t)}}},{}],20:[function(e,t,n){"use strict";var r=e("./array/map"),o=e("./object/map");t.exports=function(e,t,n){return e instanceof Array?r(e,t,n):o(e,t,n)}},{"./array/map":13,"./object/map":23}],21:[function(e,t,n){"use strict";var r=e("../function/bindInternal3");t.exports=function(e,t,n){var o,i,a=Object.keys(e),s=a.length,u=void 0!==n?r(t,n):t;for(i=0;s>i;i++)o=a[i],u(e[o],o,e)}},{"../function/bindInternal3":18}],22:[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}},{}],23:[function(e,t,n){"use strict";var r=e("../function/bindInternal3");t.exports=function(e,t,n){var o,i,a=Object.keys(e),s=a.length,u={},c=void 0!==n?r(t,n):t;for(o=0;s>o;o++)i=a[o],u[i]=c(e[i],i,e);return u}},{"../function/bindInternal3":18}],24:[function(e,t,n){"use strict";var r=function(e,t,n,r,o,i,a,s){if(!e){var u;if(void 0===t)u=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var c=[n,r,o,i,a,s],l=0;u=new Error(t.replace(/%s/g,function(){return c[l++]})),u.name="Invariant Violation"}throw u.framesToPop=1,u}};t.exports=r},{}],25:[function(e,t,n){function r(){l=!1,s.length?c=s.concat(c):f=-1,c.length&&o()}function o(){if(!l){var e=setTimeout(r);l=!0;for(var t=c.length;t;){for(s=c,c=[];++f<t;)s&&s[f].run();f=-1,t=c.length}s=null,l=!1,clearTimeout(e)}}function i(e,t){this.fun=e,this.array=t}function a(){}var s,u=t.exports={},c=[],l=!1,f=-1;u.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];c.push(new i(e,t)),1!==c.length||l||setTimeout(o,0)},i.prototype.run=function(){this.fun.apply(null,this.array)},u.title="browser",u.browser=!0,u.env={},u.argv=[],u.version="",u.versions={},u.on=a,u.addListener=a,u.once=a,u.off=a,u.removeListener=a,u.removeAllListeners=a,u.emit=a,u.binding=function(e){throw new Error("process.binding is not supported")},u.cwd=function(){return"/"},u.chdir=function(e){throw new Error("process.chdir is not supported")},u.umask=function(){return 0}},{}]},{},[11])(11)}); | ||
!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||(t.Mars={})).Client=e()}}(function(){return function e(t,n,r){function o(a,s){if(!n[a]){if(!t[a]){var u="function"==typeof require&&require;if(!s&&u)return u(a,!0);if(i)return i(a,!0);var c=new Error("Cannot find module '"+a+"'");throw c.code="MODULE_NOT_FOUND",c}var l=n[a]={exports:{}};t[a][0].call(l.exports,function(e){var n=t[a][1][e];return o(n?n:e)},l,l.exports,e,t,n,r)}return n[a].exports}for(var i="function"==typeof require&&require,a=0;a<r.length;a++)o(r[a]);return o}({1:[function(e,t,n){(function(t){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof 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 u(e){var n=b.defaultDelegate(),r=function(n){function r(){var n;i(this,r);for(var o=arguments.length,s=Array(o),u=0;o>u;u++)s[u]=arguments[u];var c=a(this,(n=Object.getPrototypeOf(r)).call.apply(n,[this].concat(s)));return e.on("status:connected",(0,h["default"])(c._handleConnected,c)),e.on("message:added",(0,h["default"])(c._handleRemoteAdded,c)),e.on("message:changed",(0,h["default"])(c._handleRemoteChanged,c)),e.on("message:removed",(0,h["default"])(c._handleRemoteRemoved,c)),t.nextTick(function(){e.isConnected&&c._handleConnected(!1)}),c}return s(r,n),l(r,[{key:"insert",value:function(t){var n=this,o=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],i=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],a=f(Object.getPrototypeOf(r.prototype),"insert",this).call(this,t,o,i),s=o.quiet,u=o.retryOnDisconnect,c=void 0===u?!0:u,l=o.waitResult;if(!s){var d="/"+this.db.modelName+"/insert",h={retryOnDisconnect:!!c,randomSeed:i.seed},p=e.methodManager.apply(d,[t],h).then(null,function(e){return a.then(function(){return n.db.remove(t._id,{quiet:!0})}).then(function(){throw e})});if(l)return p.then(function(){return a})}return a}},{key:"remove",value:function(t){var n=this,o=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],i=f(Object.getPrototypeOf(r.prototype),"remove",this).call(this,t,o),a=o.quiet,s=o.retryOnDisconnect,u=void 0===s?!0:s,c=o.waitResult;if(!a){var l="/"+this.db.modelName+"/remove",d={retryOnDisconnect:!!u},h=e.methodManager.apply(l,[t],d).then(null,function(e){return i.then(function(e){return n.db.insertAll(e,{quiet:!0})}).then(function(){throw e})});if(c)return h.then(function(){return i})}return i}},{key:"update",value:function(t,n){var i=this,a=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],s=f(Object.getPrototypeOf(r.prototype),"update",this).call(this,t,n,a),u=a.quiet,c=a.retryOnDisconnect,l=void 0===c?!0:c,d=a.waitResult,h=o(a,["quiet","retryOnDisconnect","waitResult"]);if(!u){var p="/"+this.db.modelName+"/update",y={retryOnDisconnect:!!l},m=e.methodManager.apply(p,[t,n,h],y).then(null,function(e){return s.then(function(e){return(0,v["default"])(e.updated,function(t,n){if(e.original[n]){var r=e.original[n]._id;return delete e.original[n]._id,i.db.update({_id:r},e.original[n],{quiet:!0,upsert:!0})}return i.db.remove(t._id,{quiet:!0})})}).then(function(){throw e})});if(d)return m.then(function(){return s})}return s}},{key:"_handleConnected",value:function(t){var n=this,r="/"+this.db.modelName+"/sync";return this.db.ids().then(function(t){return e.methodManager.apply(r,[t]).result()}).then(function(e){return n.db.remove({_id:{$in:e}},{quiet:!0,multi:!0})})}},{key:"_handleRemoteAdded",value:function(e){return e.collection===this.db.modelName?(delete e.fields._id,this.db.update({_id:e.id},e.fields,{quiet:!0,upsert:!0})):Promise.resolve()}},{key:"_handleRemoteChanged",value:function(e){var t=this;if(e.collection!==this.db.modelName)return Promise.resolve();var n=function(){var n={};if(Array.isArray(e.cleared)&&e.cleared.length>0){n.$unset={};var r=!0,o=!1,i=void 0;try{for(var a,s=e.cleared[Symbol.iterator]();!(r=(a=s.next()).done);r=!0){var u=a.value;n.$unset[u]=1}}catch(c){o=!0,i=c}finally{try{!r&&s["return"]&&s["return"]()}finally{if(o)throw i}}}return e.fields&&(delete e.fields._id,n.$set={},(0,y["default"])(e.fields,function(e,t){n.$set[t]=e})),(0,g["default"])(n).length>0?{v:t.db.update(e.id,n,{quiet:!0})}:void 0}();return"object"===("undefined"==typeof n?"undefined":c(n))?n.v:void 0}},{key:"_handleRemoteRemoved",value:function(e){return e.collection===this.db.modelName?this.db.remove(e.id,{quiet:!0}):Promise.resolve()}}]),r}(n);return 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?"symbol":typeof e},l=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),f=function w(e,t,n){null===e&&(e=Function.prototype);var r=Object.getOwnPropertyDescriptor(e,t);if(void 0===r){var o=Object.getPrototypeOf(e);return null===o?void 0:w(o,t,n)}if("value"in r)return r.value;var i=r.get;if(void 0!==i)return i.call(n)};Object.defineProperty(n,"__esModule",{value:!0}),n.createCollectionDelegate=u;var d=e("fast.js/function/bind"),h=r(d),p=e("fast.js/forEach"),y=r(p),m=e("fast.js/map"),v=r(m),_=e("fast.js/object/keys"),g=r(_),b="undefined"!=typeof window&&window.Mars?window.Mars.Collection:e("marsdb").Collection}).call(this,e("_process"))},{_process:25,"fast.js/forEach":14,"fast.js/function/bind":17,"fast.js/map":20,"fast.js/object/keys":22,marsdb:void 0}],2:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof 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 u(e,t){var n=!1;return"function"==typeof e?n=e(t):(Array.isArray(t)&&t.length>0||"[object Object]"===Object.prototype.toString.call(t)&&(0,h["default"])(t).length>0)&&(n=!0),n}function c(e){var t=p.defaultCursor(),n=function(t){function n(){return i(this,n),a(this,Object.getPrototypeOf(n).apply(this,arguments))}return s(n,t),l(n,[{key:"_doUpdate",value:function(t){var r=this,i=this.options,a=i.sub,s=i.waitReady,c=i.tryCache,l=function(){return f(Object.getPrototypeOf(n.prototype),"_doUpdate",r).call(r,t)};if(!this._subscription&&a){var d;if(this._subscription=(d=e.subManager).subscribe.apply(d,o(a)),this.once("observeStopped",function(){r._subscription.stop(),delete r._subscription}),s)return this._subscription.ready().then(l);if(c)return this.exec().then(function(e){return u(c,e)?(r._updateLatestIds(),r._propagateUpdate(t).then(function(){return e})):r._subscription.ready().then(l)})}return l()}}]),n}(t);return n}var l=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),f=function y(e,t,n){null===e&&(e=Function.prototype);var r=Object.getOwnPropertyDescriptor(e,t);if(void 0===r){var o=Object.getPrototypeOf(e);return null===o?void 0:y(o,t,n)}if("value"in r)return r.value;var i=r.get;if(void 0!==i)return i.call(n)};Object.defineProperty(n,"__esModule",{value:!0}),n._isCacheValid=u,n.createCursorWithSub=c;var d=e("fast.js/object/keys"),h=r(d),p="undefined"!=typeof window&&window.Mars?window.Mars.Collection:e("marsdb").Collection},{"fast.js/object/keys":22,marsdb:void 0}],3:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof 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 "+typeof 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<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();Object.defineProperty(n,"__esModule",{value:!0}),n.CONN_STATUS=void 0;var u=e("fast.js/function/try"),c=r(u),l=e("fast.js/function/bind"),f=r(l),d=e("./HeartbeatManager"),h=r(d),p="undefined"!=typeof window&&window.Mars?window.Mars.EventEmitter:e("marsdb").EventEmitter,y="undefined"!=typeof window&&window.Mars?window.Mars.PromiseQueue:e("marsdb").PromiseQueue,m="undefined"!=typeof window&&window.Mars?window.Mars.EJSON:e("marsdb").EJSON,v="undefined"!=typeof window&&window.Mars?window.Mars.Random:e("marsdb").Random,_="1",g=17500,b=15e3,w=5e3,E=n.CONN_STATUS={CONNECTING:"CONNECTING",CONNECTED:"CONNECTED",DISCONNECTED:"DISCONNECTED"},O=function(e){function t(e){var n=e.url,r=e.socket,a=e.autoReconnect,s=void 0===a?!0:a;o(this,t);var u=i(this,Object.getPrototypeOf(t).call(this));return u.url=n,u._processQueue=new y(1),u._sessionId=null,u._autoReconnect=s,u._socket=r,u._status=E.DISCONNECTED,u._fullConnectedOnce=!1,u._heartbeat=new h["default"](g,b),u._heartbeat.on("timeout",(0,f["default"])(u._handleHearbeatTimeout,u)),u._heartbeat.on("sendPing",(0,f["default"])(u.sendPing,u)),u._heartbeat.on("sendPong",(0,f["default"])(u.sendPong,u)),u}return a(t,e),s(t,[{key:"sendMethod",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?[]:arguments[1],n=arguments[2],r=arguments[3],o={msg:"method",id:n,method:e,params:t};r&&(o.randomSeed=r),this._sendMessage(o)}},{key:"sendSub",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?[]:arguments[1],n=arguments[2];this._sendMessage({msg:"sub",id:n,name:e,params:t})}},{key:"sendUnsub",value:function(e){this._sendMessage({msg:"unsub",id:e})}},{key:"sendPing",value:function(){this._sendMessage({msg:"ping",id:v["default"]().id(20)})}},{key:"sendPong",value:function(e){this._sendMessage({msg:"pong",id:e})}},{key:"connect",value:function(){return this.isDisconnected?(this._rawConn=new this._socket(this.url),this._rawConn.onopen=(0,f["default"])(this._handleOpen,this),this._rawConn.onerror=(0,f["default"])(this._handleError,this),this._rawConn.onclose=(0,f["default"])(this._handleClose,this),this._rawConn.onmessage=(0,f["default"])(this._handleRawMessage,this),this._setStatus(E.CONNECTING),!0):!1}},{key:"reconnect",value:function(){var e=this;return this.isDisconnected?(clearTimeout(this._reconnTimer),this._reconnecting=!0,this._reconnTimer=setTimeout((0,f["default"])(this.connect,this),w),function(){clearTimeout(e._reconnTimer),e._reconnecting=!1,e.disconnect()}):void 0}},{key:"disconnect",value:function(){var e=this;(0,c["default"])(function(){return e._rawConn&&e._rawConn.close()})}},{key:"_handleOpen",value:function(){this._heartbeat.waitPing();var e={msg:"connect",version:_,support:[_]};this._sessionId&&(e.session=this._sessionId),this._sendMessage(e)}},{key:"_handleConnectedMessage",value:function(e){if(!this.isConnected){var t=this._fullConnectedOnce&&this._reconnecting;this._setStatus(E.CONNECTED,t),this._sessionId=e.session,this._reconnecting=!1,this._fullConnectedOnce=!0}}},{key:"_handleClose",value:function(){this._heartbeat._clearTimers(),this._setStatus(E.DISCONNECTED,this._fullConnectedOnce),this._autoReconnect&&(this._reconnecting=!1,this.reconnect())}},{key:"_handleHearbeatTimeout",value:function(){this.disconnect()}},{key:"_handleError",value:function(e){this.emit("error",e)}},{key:"_handleRawMessage",value:function(e){var t=this;return this._processQueue.add(function(){var n=m.parse(e.data);return t._processMessage(n)}).then(null,function(e){t._handleError(e)})}},{key:"_processMessage",value:function(e){switch(e.msg){case"connected":return this._handleConnectedMessage(e);case"ping":return this._heartbeat.handlePing(e);case"pong":return this._heartbeat.handlePong(e);case"removed":case"changed":case"added":case"updated":case"result":case"nosub":case"ready":case"error":return this.emitAsync("message:"+e.msg,e)}}},{key:"_sendMessage",value:function(e){var t=this,n=(0,c["default"])(function(){return t._rawConn.send(m.stringify(e))});n instanceof Error&&this._handleError(n)}},{key:"_setStatus",value:function(e,t){this._status=e,this.emit(("status:"+e).toLowerCase(),t)}},{key:"isConnected",get:function(){return this._status===E.CONNECTED}},{key:"isDisconnected",get:function(){return this._status===E.DISCONNECTED}}]),t}(p);n["default"]=O},{"./HeartbeatManager":5,"fast.js/function/bind":17,"fast.js/function/try":19,marsdb:void 0}],4:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();Object.defineProperty(n,"__esModule",{value:!0});var a=e("fast.js/function/bind"),s=r(a),u=function(){function e(t){o(this,e),this.conn=t,t.on("message:error",(0,s["default"])(this._handleError,this)),t.on("error",(0,s["default"])(this._handleError,this))}return i(e,[{key:"_handleError",value:function(e){e&&e.message?console.warn(e.message+"\n"+e.stack):console.warn(JSON.stringify(e))}}]),e}();n["default"]=u},{"fast.js/function/bind":17}],5:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var a=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();Object.defineProperty(n,"__esModule",{value:!0});var s="undefined"!=typeof window&&window.Mars?window.Mars.EventEmitter:e("marsdb").EventEmitter,u=function(e){function t(){var e=arguments.length<=0||void 0===arguments[0]?17500:arguments[0],n=arguments.length<=1||void 0===arguments[1]?1e4:arguments[1];r(this,t);var i=o(this,Object.getPrototypeOf(t).call(this));return i.pingTimeout=e,i.pongTimeout=n,i}return i(t,e),a(t,[{key:"waitPing",value:function(){var e=this;this._clearTimers(),this.waitPingTimer=setTimeout(function(){e.emit("sendPing"),e.waitPong()},this.pingTimeout)}},{key:"waitPong",value:function(){var e=this;this._clearTimers(),this.waitPongTimer=setTimeout(function(){return e.emit("timeout")},this.pongTimeout)}},{key:"handlePing",value:function(e){this._clearTimers(),this.emit("sendPong",e),this.waitPing()}},{key:"handlePong",value:function(){this._clearTimers(),this.waitPing()}},{key:"_clearTimers",value:function(){clearTimeout(this.waitPingTimer),clearTimeout(this.waitPongTimer)}}]),t}(s);n["default"]=u},{marsdb:void 0}],6:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var a=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();Object.defineProperty(n,"__esModule",{value:!0});var s="undefined"!=typeof window&&window.Mars?window.Mars.EventEmitter:e("marsdb").EventEmitter,u="undefined"!=typeof window&&window.Mars?window.Mars.Random:e("marsdb").Random,c=n.CALL_STATUS={PENDING:"PENDING",SENT:"SENT",RESULT:"RESULT",ERROR:"ERROR",UPDATED:"UPDATED"},l=function(e){function t(e,n){var i=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],a=arguments[3];r(this,t);var s=o(this,Object.getPrototypeOf(t).call(this));return s.result=function(){return s._promiseMixed(new Promise(function(e,t){s._resulted?e(s._result):s._errored?t(s._error):(s.once(c.RESULT,e),s.once(c.ERROR,t))}))},s.updated=function(){return s._promiseMixed(new Promise(function(e,t){s._updated?e():s.once(c.UPDATED,e)}))},s.id=u["default"]().id(20),s.status=c.PENDING,s.method=e,s.params=n,s.options=i,s._conn=a,s}return i(t,e),a(t,[{key:"then",value:function(e,t){var n=this;return this.updated().then(function(){return n.result().then(e,t)},t)}},{key:"_invoke",value:function(){this._conn.sendMethod(this.method,this.params,this.id,this.options.randomSeed),this._setStatus(c.SENT)}},{key:"_retry",value:function(){this._setStatus(c.PENDING)}},{key:"_promiseMixed",value:function(e){var t=this;return{result:this.result,updated:this.updated,then:function(){return t._promiseMixed(e.then.apply(e,arguments))}}}},{key:"_handleResult",value:function(e,t){e?(this._errored=!0,this._error=e,this._setStatus(c.ERROR,e)):(this._resulted=!0,this._result=t,this._setStatus(c.RESULT,t))}},{key:"_handleUpdated",value:function(e){this._updated=!0,this._setStatus(c.UPDATED)}},{key:"_setStatus",value:function(e,t,n,r,o){this.status=e,this.emit(e,t,n,r,o)}},{key:"isPending",get:function(){return this.status===c.PENDING}},{key:"isSent",get:function(){return this.status===c.SENT}},{key:"isDone",get:function(){return this.status!==c.SENT&&this.status!==c.PENDING}}]),t}(s);n["default"]=l},{marsdb:void 0}],7:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();Object.defineProperty(n,"__esModule",{value:!0});var a=e("fast.js/function/bind"),s=r(a),u=e("fast.js/forEach"),c=r(u),l=e("./MethodCall"),f=r(l),d=function(){function e(t){o(this,e),this.conn=t,this._methods={},t.on("status:disconnected",(0,s["default"])(this._handleDisconnected,this)),t.on("status:connected",(0,s["default"])(this._handleConnected,this)),t.on("message:result",(0,s["default"])(this._handleMethodResult,this)),t.on("message:updated",(0,s["default"])(this._handleMethodUpdated,this))}return i(e,[{key:"call",value:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];return this.apply(e,n)}},{key:"apply",value:function(e){var t=this,n=arguments.length<=1||void 0===arguments[1]?[]:arguments[1],r=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],o=new f["default"](e,n,r,this.conn);this._methods[o.id]=o;var i=function(){return delete t._methods[o.id]};return o.then(i,i),this.conn.isConnected&&o._invoke(),o}},{key:"_handleMethodResult",value:function(e){if(e.id&&this._methods[e.id]){var t=e.result,n=e.error;this._methods[e.id]._handleResult(n,t)}}},{key:"_handleMethodUpdated",value:function(e){var t=this;(0,c["default"])(e.methods,function(e){t._methods[e]&&t._methods[e]._handleUpdated()})}},{key:"_handleDisconnected",value:function(){(0,c["default"])(this._methods,function(e){e.isSent&&(e.options.retryOnDisconnect?e._retry():e._handleResult({reason:"Disconnected, method can't be done",code:"DISCONNECTED"}))})}},{key:"_handleConnected",value:function(){(0,c["default"])(this._methods,function(e){e.isPending&&e._invoke()})}}]),e}();n["default"]=d},{"./MethodCall":6,"fast.js/forEach":14,"fast.js/function/bind":17}],8:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var a=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();Object.defineProperty(n,"__esModule",{value:!0});var s="undefined"!=typeof window&&window.Mars?window.Mars.EventEmitter:e("marsdb").EventEmitter,u="undefined"!=typeof window&&window.Mars?window.Mars.Random:e("marsdb").Random,c=n.SUB_STATUS={READY_PENDING:"READY_PENDING",READY:"READY",ERROR:"ERROR",STOP_PENDING:"STOP_PENDING",STOPPED:"STOPPED",FROZEN:"FROZEN"},l=function(e){function t(e,n,i){var a=arguments.length<=3||void 0===arguments[3]?15e3:arguments[3];r(this,t);var s=o(this,Object.getPrototypeOf(t).call(this));return s.ready=function(){return s._promiseMixed(new Promise(function(e,t){s.isReady?e():(s.once(c.READY,e),s.once(c.ERROR,t))}))},s.stopped=function(){return s._promiseMixed(new Promise(function(e,t){s.isStopped?e():(s.once(c.STOPPED,e),s.once(c.ERROR,t))}))},s.stop=function(){s._scheduleStop()},s.id=u["default"]().id(20),s.name=e,s.params=n,s._conn=i,s._ready=!1,s._stopWaitTimeout=a,s}return i(t,e),a(t,[{key:"then",value:function(e,t){return this.ready().then(e,t)}},{key:"_promiseMixed",value:function(e){var t=this;return{stopped:this.stopped,ready:this.ready,stop:this.stop,then:function(){return t._promiseMixed(e.then.apply(e,arguments))}}}},{key:"_subscribe",value:function(){this.status&&this.status!==c.STOP_PENDING&&this.status!==c.STOPPED&&this.status!==c.ERROR&&this.status!==c.FROZEN||(this.status===c.STOP_PENDING?this._ready?(this._clearStopper(),this._setStatus(c.READY)):this._setStatus(c.READY_PENDING):(this._setStatus(c.READY_PENDING),this._conn.sendSub(this.name,this.params,this.id)))}},{key:"_scheduleStop",value:function(){var e=this;this.status!==c.STOP_PENDING&&this.status!==c.STOPPED&&(this._setStatus(c.STOP_PENDING),this._stopTimer=setTimeout(function(){return e._stopImmediately()},this._stopWaitTimeout))}},{key:"_stopImmediately",value:function(e){this.status!==c.STOPPED&&(this._clearStopper(),this._setStatus(c.STOPPED),this._ready=!1,e&&e.dontSendMsg||this._conn.sendUnsub(this.id))}},{key:"_freeze",value:function(){this.status===c.STOP_PENDING?this._stopImmediately({dontSendMsg:!0}):this.status&&this.status===c.STOPPED||this._setStatus(c.FROZEN)}},{key:"_setStatus",value:function(e,t,n,r,o){this.status=e,this.emit(e,t,n,r,o)}},{key:"_clearStopper",value:function(){clearTimeout(this._stopTimer),this._stopTimer=null}},{key:"_handleNosub",value:function(e){this._clearStopper(),e?this._setStatus(c.ERROR,e):this._stopImmediately({dontSendMsg:!0})}},{key:"_handleReady",value:function(){this.status!==c.STOPPED&&this.status!==c.STOP_PENDING&&(this._ready=!0,this._setStatus(c.READY))}},{key:"isReady",get:function(){return this.status==c.READY||this.status===c.FROZEN&&this._ready}},{key:"isReadyPending",get:function(){return this.status===c.READY_PENDING}},{key:"isStopped",get:function(){return this.status===c.STOPPED}},{key:"isStopPending",get:function(){return this.status===c.STOP_PENDING}},{key:"isFaulted",get:function(){return this.status===c.ERROR}},{key:"isFrozen",get:function(){return this.status==c.FROZEN}}]),t}(s);n["default"]=l},{marsdb:void 0}],9:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof 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 "+typeof 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<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();Object.defineProperty(n,"__esModule",{value:!0});var u=e("fast.js/function/bind"),c=r(u),l=e("fast.js/forEach"),f=r(l),d=e("./Subscription"),h=r(d),p="undefined"!=typeof window&&window.Mars?window.Mars.EventEmitter:e("marsdb").EventEmitter,y=15e3,m=function(e){function t(e){o(this,t);var n=i(this,Object.getPrototypeOf(t).call(this));return n._subs={},n._loading=new Set,n._conn=e,e.on("status:connected",(0,c["default"])(n._handleConnected,n)),e.on("status:disconnected",(0,c["default"])(n._handleDisconnected,n)),e.on("message:ready",(0,c["default"])(n._handleSubscriptionReady,n)),e.on("message:nosub",(0,c["default"])(n._handleSubscriptionNosub,n)),n}return a(t,e),s(t,[{key:"subscribe",value:function(e){for(var t=this,n=arguments.length,r=Array(n>1?n-1:0),o=1;n>o;o++)r[o-1]=arguments[o];var i=new h["default"](e,r,this._conn,y);this._subs[i.id]=i,this._trackLoadingStart(i.id);var a=function(){delete t._subs[i.id],t._trackLoadingReady(i.id)};return i.once(d.SUB_STATUS.STOPPED,a),i.once(d.SUB_STATUS.ERROR,a),this._conn.isConnected?i._subscribe():i._freeze(),i}},{key:"addReadyListener",value:function(e){var t=this;return this.on("ready",e),function(){return t.removeListener("ready",e)}}},{key:"addLoadingListener",value:function(e){var t=this;return this.on("loading",e),function(){return t.removeListener("loading",e)}}},{key:"_handleConnected",value:function(){(0,f["default"])(this._subs,function(e){return e._subscribe()})}},{key:"_handleDisconnected",value:function(){var e=this;(0,f["default"])(this._subs,function(t,n){t._freeze(),t.isFrozen?e._trackLoadingStart(n):e._trackLoadingReady(n)})}},{key:"_handleSubscriptionReady",value:function(e){var t=this;(0,f["default"])(e.subs,function(e){var n=t._subs[e];n&&(n._handleReady(),t._trackLoadingReady(e))})}},{key:"_handleSubscriptionNosub",value:function(e){var t=this._subs[e.id];t&&t._handleNosub(e.error)}},{key:"_trackLoadingStart",value:function(e){var t=this._loading.size;this._loading.add(e),0===t&&this._loading.size>0&&this.emit("loading")}},{key:"_trackLoadingReady",value:function(e){var t=this._loading.size;this._loading["delete"](e),t>0&&0===this._loading.size&&this.emit("ready")}}]),t}(p);n["default"]=m},{"./Subscription":8,"fast.js/forEach":14,"fast.js/function/bind":17,marsdb:void 0}],10:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(){T=null}function i(){return T}function a(e){return(0,p["default"])(!T,"addManager(...): you can add managers only at first execution cycle"),k.push(e)}function s(){var e;return(0,p["default"])(T,"call(...): connection is not established yet. Please use Collection.startup(...) to initialize your app"),(e=T.methodManager).call.apply(e,arguments)}function u(){var e;return(0,p["default"])(T,"apply(...): connection is not established yet. Please use Collection.startup(...) to initialize your app"),(e=T.methodManager).apply.apply(e,arguments)}function c(){var e;return(0,p["default"])(T,"subscribe(...): connection is not established yet. Please use Collection.startup(...) to initialize your app"),(e=T.subManager).subscribe.apply(e,arguments)}function l(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return(0,p["default"])(e.socket||"undefined"!=typeof WebSocket,"configure(...): no socket consturctor provided and not available in global"),(0,p["default"])(!T,"configure(...): connection already configured"),e.socket=e.socket||WebSocket,T=new m["default"](e),S.defaultDelegate((0,O.createCollectionDelegate)(T)),S.defaultCursor((0,P.createCursorWithSub)(T)),T.customManagers=(0,d["default"])(k,function(e){return new e(T)}),T.methodManager=new b["default"](T),T.subManager=new _["default"](T),T.errorManager=new E["default"](T),T.connect(),T}Object.defineProperty(n,"__esModule",{value:!0}),n._removeConnection=o,n.getConnection=i,n.addManager=a,n.call=s,n.apply=u,n.subscribe=c,n.configure=l;var f=e("fast.js/map"),d=r(f),h=e("invariant"),p=r(h),y=e("./DDPConnection"),m=r(y),v=e("./SubscriptionManager"),_=r(v),g=e("./MethodCallManager"),b=r(g),w=e("./ErrorManager"),E=r(w),O=e("./CollectionManager"),P=e("./CursorWithSub"),S="undefined"!=typeof window&&window.Mars?window.Mars.Collection:e("marsdb").Collection,k=[],T=null},{"./CollectionManager":1,"./CursorWithSub":2,"./DDPConnection":3,"./ErrorManager":4,"./MethodCallManager":7,"./SubscriptionManager":9,"fast.js/map":20,invariant:24,marsdb:void 0}],11:[function(e,t,n){t.exports=e("./dist")},{"./dist":10}],12:[function(e,t,n){"use strict";var r=e("../function/bindInternal3");t.exports=function(e,t,n){var o,i=e.length,a=void 0!==n?r(t,n):t;for(o=0;i>o;o++)a(e[o],o,e)}},{"../function/bindInternal3":18}],13:[function(e,t,n){"use strict";var r=e("../function/bindInternal3");t.exports=function(e,t,n){var o,i=e.length,a=new Array(i),s=void 0!==n?r(t,n):t;for(o=0;i>o;o++)a[o]=s(e[o],o,e);return a}},{"../function/bindInternal3":18}],14:[function(e,t,n){"use strict";var r=e("./array/forEach"),o=e("./object/forEach");t.exports=function(e,t,n){return e instanceof Array?r(e,t,n):o(e,t,n)}},{"./array/forEach":12,"./object/forEach":21}],15:[function(e,t,n){"use strict";t.exports=function(e,t){switch(t.length){case 0:return e();case 1:return e(t[0]);case 2:return e(t[0],t[1]);case 3:return e(t[0],t[1],t[2]);case 4:return e(t[0],t[1],t[2],t[3]);case 5:return e(t[0],t[1],t[2],t[3],t[4]);case 6:return e(t[0],t[1],t[2],t[3],t[4],t[5]);case 7:return e(t[0],t[1],t[2],t[3],t[4],t[5],t[6]);case 8: | ||
return e(t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7]);default:return e.apply(void 0,t)}}},{}],16:[function(e,t,n){"use strict";t.exports=function(e,t,n){switch(n.length){case 0:return e.call(t);case 1:return e.call(t,n[0]);case 2:return e.call(t,n[0],n[1]);case 3:return e.call(t,n[0],n[1],n[2]);case 4:return e.call(t,n[0],n[1],n[2],n[3]);case 5:return e.call(t,n[0],n[1],n[2],n[3],n[4]);case 6:return e.call(t,n[0],n[1],n[2],n[3],n[4],n[5]);case 7:return e.call(t,n[0],n[1],n[2],n[3],n[4],n[5],n[6]);case 8:return e.call(t,n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]);default:return e.apply(t,n)}}},{}],17:[function(e,t,n){"use strict";var r=e("./applyWithContext"),o=e("./applyNoContext");t.exports=function(e,t){var n,i=arguments.length-2;if(i>0){n=new Array(i);for(var a=0;i>a;a++)n[a]=arguments[a+2];return void 0!==t?function(){var o,a=arguments.length,s=new Array(i+a);for(o=0;i>o;o++)s[o]=n[o];for(o=0;a>o;o++)s[i+o]=arguments[o];return r(e,t,s)}:function(){var t,r=arguments.length,a=new Array(i+r);for(t=0;i>t;t++)a[t]=n[t];for(t=0;r>t;t++)a[i+t]=arguments[t];return o(e,a)}}return void 0!==t?function(){return r(e,t,arguments)}:function(){return o(e,arguments)}}},{"./applyNoContext":15,"./applyWithContext":16}],18:[function(e,t,n){"use strict";t.exports=function(e,t){return function(n,r,o){return e.call(t,n,r,o)}}},{}],19:[function(e,t,n){"use strict";t.exports=function(e){try{return e()}catch(t){return t instanceof Error?t:new Error(t)}}},{}],20:[function(e,t,n){"use strict";var r=e("./array/map"),o=e("./object/map");t.exports=function(e,t,n){return e instanceof Array?r(e,t,n):o(e,t,n)}},{"./array/map":13,"./object/map":23}],21:[function(e,t,n){"use strict";var r=e("../function/bindInternal3");t.exports=function(e,t,n){var o,i,a=Object.keys(e),s=a.length,u=void 0!==n?r(t,n):t;for(i=0;s>i;i++)o=a[i],u(e[o],o,e)}},{"../function/bindInternal3":18}],22:[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}},{}],23:[function(e,t,n){"use strict";var r=e("../function/bindInternal3");t.exports=function(e,t,n){var o,i,a=Object.keys(e),s=a.length,u={},c=void 0!==n?r(t,n):t;for(o=0;s>o;o++)i=a[o],u[i]=c(e[i],i,e);return u}},{"../function/bindInternal3":18}],24:[function(e,t,n){"use strict";var r=function(e,t,n,r,o,i,a,s){if(!e){var u;if(void 0===t)u=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var c=[n,r,o,i,a,s],l=0;u=new Error(t.replace(/%s/g,function(){return c[l++]})),u.name="Invariant Violation"}throw u.framesToPop=1,u}};t.exports=r},{}],25:[function(e,t,n){function r(){l=!1,s.length?c=s.concat(c):f=-1,c.length&&o()}function o(){if(!l){var e=setTimeout(r);l=!0;for(var t=c.length;t;){for(s=c,c=[];++f<t;)s&&s[f].run();f=-1,t=c.length}s=null,l=!1,clearTimeout(e)}}function i(e,t){this.fun=e,this.array=t}function a(){}var s,u=t.exports={},c=[],l=!1,f=-1;u.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];c.push(new i(e,t)),1!==c.length||l||setTimeout(o,0)},i.prototype.run=function(){this.fun.apply(null,this.array)},u.title="browser",u.browser=!0,u.env={},u.argv=[],u.version="",u.versions={},u.on=a,u.addListener=a,u.once=a,u.off=a,u.removeListener=a,u.removeAllListeners=a,u.emit=a,u.binding=function(e){throw new Error("process.binding is not supported")},u.cwd=function(){return"/"},u.chdir=function(e){throw new Error("process.chdir is not supported")},u.umask=function(){return 0}},{}]},{},[11])(11)}); |
@@ -103,3 +103,3 @@ 'use strict'; | ||
var localInsert = undefined; | ||
var localInsert = _get(Object.getPrototypeOf(CollectionManager.prototype), 'insert', this).call(this, doc, options, randomId); | ||
var quiet = options.quiet; | ||
@@ -116,20 +116,17 @@ var _options$retryOnDisco = options.retryOnDisconnect; | ||
}; | ||
var result = connection.methodManager.apply(methodName, [doc], applyOpts); | ||
var result = connection.methodManager.apply(methodName, [doc], applyOpts).then(null, function (e) { | ||
return localInsert.then(function () { | ||
return _this2.db.remove(doc._id, { quiet: true }); | ||
}).then(function () { | ||
throw e; | ||
}); | ||
}); | ||
if (waitResult) { | ||
return result.then(function () { | ||
return doc._id; | ||
return localInsert; | ||
}); | ||
} else { | ||
result.then(null, function (e) { | ||
return localInsert.then(function () { | ||
return _this2.db.remove(doc._id, { quiet: true }); | ||
}).then(function () { | ||
throw e; | ||
}); | ||
}); | ||
} | ||
} | ||
localInsert = _get(Object.getPrototypeOf(CollectionManager.prototype), 'insert', this).call(this, doc, options, randomId); | ||
return localInsert; | ||
@@ -161,3 +158,3 @@ } | ||
var localRemove = undefined; | ||
var localRemove = _get(Object.getPrototypeOf(CollectionManager.prototype), 'remove', this).call(this, query, options); | ||
var quiet = options.quiet; | ||
@@ -171,13 +168,13 @@ var _options$retryOnDisco2 = options.retryOnDisconnect; | ||
var applyOpts = { retryOnDisconnect: !!retryOnDisconnect }; | ||
var result = connection.methodManager.apply(methodName, [query], applyOpts); | ||
var result = connection.methodManager.apply(methodName, [query], applyOpts).then(null, function (e) { | ||
return localRemove.then(function (remDocs) { | ||
return _this3.db.insertAll(remDocs, { quiet: true }); | ||
}).then(function () { | ||
throw e; | ||
}); | ||
}); | ||
if (waitResult) { | ||
return result; | ||
} else { | ||
result.then(null, function (e) { | ||
return localRemove.then(function (remDocs) { | ||
return _this3.db.insertAll(remDocs, { quiet: true }); | ||
}).then(function () { | ||
throw e; | ||
}); | ||
return result.then(function () { | ||
return localRemove; | ||
}); | ||
@@ -187,3 +184,2 @@ } | ||
localRemove = _get(Object.getPrototypeOf(CollectionManager.prototype), 'remove', this).call(this, query, options); | ||
return localRemove; | ||
@@ -215,3 +211,3 @@ } | ||
var localUpdate = undefined; | ||
var localUpdate = _get(Object.getPrototypeOf(CollectionManager.prototype), 'update', this).call(this, query, modifier, options); | ||
var quiet = options.quiet; | ||
@@ -227,21 +223,21 @@ var _options$retryOnDisco3 = options.retryOnDisconnect; | ||
var applyOpts = { retryOnDisconnect: !!retryOnDisconnect }; | ||
var result = connection.methodManager.apply(methodName, [query, modifier, otherOpts], applyOpts); | ||
var result = connection.methodManager.apply(methodName, [query, modifier, otherOpts], applyOpts).then(null, function (e) { | ||
return localUpdate.then(function (res) { | ||
return (0, _map3.default)(res.updated, function (d, i) { | ||
if (!res.original[i]) { | ||
return _this4.db.remove(d._id, { quiet: true }); | ||
} else { | ||
var docId = res.original[i]._id; | ||
delete res.original[i]._id; | ||
return _this4.db.update({ _id: docId }, res.original[i], { quiet: true, upsert: true }); | ||
} | ||
}); | ||
}).then(function () { | ||
throw e; | ||
}); | ||
}); | ||
if (waitResult) { | ||
return result; | ||
} else { | ||
result.then(null, function (e) { | ||
return localUpdate.then(function (res) { | ||
return (0, _map3.default)(res.updated, function (d, i) { | ||
if (!res.original[i]) { | ||
return _this4.db.remove(d._id, { quiet: true }); | ||
} else { | ||
var docId = res.original[i]._id; | ||
delete res.original[i]._id; | ||
return _this4.db.update({ _id: docId }, res.original[i], { quiet: true, upsert: true }); | ||
} | ||
}); | ||
}).then(function () { | ||
throw e; | ||
}); | ||
return result.then(function () { | ||
return localUpdate; | ||
}); | ||
@@ -251,3 +247,2 @@ } | ||
localUpdate = _get(Object.getPrototypeOf(CollectionManager.prototype), 'update', this).call(this, query, modifier, options); | ||
return localUpdate; | ||
@@ -254,0 +249,0 @@ } |
@@ -49,3 +49,3 @@ import _bind from 'fast.js/function/bind'; | ||
insert(doc, options = {}, randomId = {}) { | ||
let localInsert; | ||
const localInsert = super.insert(doc, options, randomId); | ||
const { quiet, retryOnDisconnect = true, waitResult } = options; | ||
@@ -60,8 +60,4 @@ | ||
const result = connection.methodManager | ||
.apply(methodName, [doc], applyOpts); | ||
if (waitResult) { | ||
return result.then(() => doc._id); | ||
} else { | ||
result.then(null, (e) => { | ||
.apply(methodName, [doc], applyOpts) | ||
.then(null, (e) => { | ||
return localInsert | ||
@@ -73,6 +69,8 @@ .then(() => this.db.remove(doc._id, {quiet: true})) | ||
}); | ||
if (waitResult) { | ||
return result.then(() => localInsert); | ||
} | ||
} | ||
localInsert = super.insert(doc, options, randomId); | ||
return localInsert; | ||
@@ -97,3 +95,3 @@ } | ||
remove(query, options = {}) { | ||
let localRemove; | ||
const localRemove = super.remove(query, options); | ||
const { quiet, retryOnDisconnect = true, waitResult } = options; | ||
@@ -105,8 +103,4 @@ | ||
const result = connection.methodManager | ||
.apply(methodName, [query], applyOpts); | ||
if (waitResult) { | ||
return result; | ||
} else { | ||
result.then(null, (e) => { | ||
.apply(methodName, [query], applyOpts) | ||
.then(null, (e) => { | ||
return localRemove | ||
@@ -118,6 +112,8 @@ .then((remDocs) => this.db.insertAll(remDocs, {quiet: true})) | ||
}); | ||
if (waitResult) { | ||
return result.then(() => localRemove); | ||
} | ||
} | ||
localRemove = super.remove(query, options); | ||
return localRemove; | ||
@@ -142,3 +138,3 @@ } | ||
update(query, modifier, options = {}) { | ||
let localUpdate; | ||
const localUpdate = super.update(query, modifier, options); | ||
const { quiet, retryOnDisconnect = true, waitResult, ...otherOpts } = options; | ||
@@ -150,8 +146,4 @@ | ||
const result = connection.methodManager | ||
.apply(methodName, [query, modifier, otherOpts], applyOpts); | ||
if (waitResult) { | ||
return result; | ||
} else { | ||
result.then(null, (e) => { | ||
.apply(methodName, [query, modifier, otherOpts], applyOpts) | ||
.then(null, (e) => { | ||
return localUpdate.then((res) => { | ||
@@ -172,6 +164,8 @@ return _map(res.updated, (d, i) => { | ||
}); | ||
if (waitResult) { | ||
return result.then(() => localUpdate); | ||
} | ||
} | ||
localUpdate = super.update(query, modifier, options); | ||
return localUpdate; | ||
@@ -178,0 +172,0 @@ } |
{ | ||
"name": "marsdb-sync-client", | ||
"version": "0.2.8", | ||
"version": "0.2.9", | ||
"author": "Artem Artemev <art@studytime.me>", | ||
@@ -5,0 +5,0 @@ "contributors": [ |
@@ -292,8 +292,3 @@ import { createCollectionDelegate } from '../../lib/CollectionManager'; | ||
const cb = sinon.spy(); | ||
conn.methodManager = { apply: sinon.spy(() => | ||
Promise.all([ | ||
Promise.resolve('2'), | ||
db.insert({_id: '2', a: 1}, {quiet: true}) | ||
]) | ||
)} | ||
conn.methodManager = { apply: sinon.spy(() => Promise.resolve())} | ||
return manager.insert({_id: '1', a: 2}, {waitResult: true}) | ||
@@ -306,3 +301,3 @@ .then((docId) => { | ||
res.should.have.length(1); | ||
res[0].should.be.deep.equal({_id: '2', a: 1}); | ||
res[0].should.be.deep.equal({_id: '1', a: 2}); | ||
}); | ||
@@ -309,0 +304,0 @@ }); |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
517166
10753