!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},t=Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="d8d53c7e-83b3-46ab-87c2-5ba1ff5163a1",e._sentryDebugIdIdentifier="sentry-dbid-d8d53c7e-83b3-46ab-87c2-5ba1ff5163a1")}catch(e){}}();var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};"use strict";e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[Error().stack]=Object.assign({},e._sentryModuleMetadata[Error().stack],{"_sentryBundlerPluginAppKey:northstar":!0}),(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3816],{34929:function(e,t,n){/*
@license
The following license applies to all parts of this software except as
documented below.

    Copyright (c) 2016, Twilio, inc.
    All rights reserved.

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are
    met:

      1. Redistributions of source code must retain the above copyright
         notice, this list of conditions and the following disclaimer.

      2. Redistributions in binary form must reproduce the above copyright
         notice, this list of conditions and the following disclaimer in
         the documentation and/or other materials provided with the
         distribution.

      3. Neither the name of Twilio nor the names of its contributors may
         be used to endorse or promote products derived from this software
         without specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

This software includes loglevel under the following license.

    Copyright (c) 2013 Tim Perry

    Permission is hereby granted, free of charge, to any person
    obtaining a copy of this software and associated documentation
    files (the "Software"), to deal in the Software without
    restriction, including without limitation the rights to use,
    copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the
    Software is furnished to do so, subject to the following
    conditions:

    The above copyright notice and this permission notice shall be
    included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
    OTHER DEALINGS IN THE SOFTWARE.

This software includes Backoff library under the following license

    Copyright (C) 2012 Mathieu Turcotte

    Permission is hereby granted, free of charge, to any person obtaining a copy of
    this software and associated documentation files (the "Software"), to deal in
    the Software without restriction, including without limitation the rights to
    use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
    of the Software, and to permit persons to whom the Software is furnished to do
    so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    SOFTWARE.

This software includes Event-to-Promise library under the following license

    Copyright (c) 2014, Julien Fontanet <julien.fontanet@isonoe.net>.

    Permission to use, copy, modify, and/or distribute this software for any purpose
    with or without fee is hereby granted, provided that the above copyright notice
    and this permission notice appear in all copies.

    THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
    REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
    FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
    INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
    OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
    TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
    THIS SOFTWARE.

*/Object.defineProperty(t,"__esModule",{value:!0}),n(47941),n(82526),n(57327),n(38880),n(54747),n(49337),n(12419);var r,a=n(17156),i=n(56690),s=n(89728),u=n(66115),o=n(61655),c=n(94993),l=n(73808),d=n(38416);n(21249),n(41539),n(88674);var p=n(64687),f=n(18698),h=n(48261),y=n(7766);n(69600);var v=n(33496);n(68309),n(92222),n(26699),n(91038),n(78783);var m=n(2043);n(47042),n(41817),n(32165);var _=n(27424);n(66992),n(51532),n(33948),n(19601),n(74916),n(4723);var k=n(89575);n(15306);var b=n(70367),w=n(41588);n(9653);var I=n(31795);function _interopDefaultLegacy(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function _interopNamespace(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}}),t.default=e,Object.freeze(t)}var x=_interopDefaultLegacy(a),S=_interopDefaultLegacy(i),E=_interopDefaultLegacy(s),L=_interopDefaultLegacy(u),T=_interopDefaultLegacy(o),C=_interopDefaultLegacy(c),R=_interopDefaultLegacy(l),N=_interopDefaultLegacy(d),M=_interopDefaultLegacy(p),q=_interopDefaultLegacy(f),j=_interopDefaultLegacy(v),O=_interopNamespace(m),A=_interopDefaultLegacy(_),P=_interopNamespace(b),D=_interopDefaultLegacy(w),U=_interopNamespace(I);function __decorate(e,t,n,r){var a,i=arguments.length,s=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if(("undefined"==typeof Reflect?"undefined":q.default(Reflect))==="object"&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,n,r);else for(var u=e.length-1;u>=0;u--)(a=e[u])&&(s=(i<3?a(s):i>3?a(t,n,s):a(t,n))||s);return i>3&&s&&Object.defineProperty(t,n,s),s}function __metadata(e,t){if(("undefined"==typeof Reflect?"undefined":q.default(Reflect))==="object"&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function EventHandlers(){}function EventEmitter(){EventEmitter.init.call(this)}function $getMaxListeners(e){return void 0===e._maxListeners?EventEmitter.defaultMaxListeners:e._maxListeners}function _addListener(e,t,n,r){if("function"!=typeof n)throw TypeError('"listener" argument must be a function');if((i=e._events)?(i.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),i=e._events),s=i[t]):(i=e._events=new EventHandlers,e._eventsCount=0),s){if("function"==typeof s?s=i[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),!s.warned&&(a=$getMaxListeners(e))&&a>0&&s.length>a){s.warned=!0;var a,i,s,u=Error("Possible EventEmitter memory leak detected. "+s.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=s.length,"function"==typeof console.warn?console.warn(u):console.log(u)}}else s=i[t]=n,++e._eventsCount;return e}function _onceWrap(e,t,n){var r=!1;function g(){e.removeListener(t,g),r||(r=!0,n.apply(e,arguments))}return g.listener=n,g}function listenerCount(e){var t=this._events;if(t){var n=t[e];if("function"==typeof n)return 1;if(n)return n.length}return 0}function arrayClone(e,t){for(var n=Array(t);t--;)n[t]=e[t];return n}EventHandlers.prototype=Object.create(null),EventEmitter.EventEmitter=EventEmitter,EventEmitter.usingDomains=!1,EventEmitter.prototype.domain=void 0,EventEmitter.prototype._events=void 0,EventEmitter.prototype._maxListeners=void 0,EventEmitter.defaultMaxListeners=10,EventEmitter.init=function(){this.domain=null,EventEmitter.usingDomains&&r.active,this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=new EventHandlers,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},EventEmitter.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},EventEmitter.prototype.getMaxListeners=function(){return $getMaxListeners(this)},EventEmitter.prototype.emit=function(e){var t,n,r,a,i,s,u,o="error"===e;if(s=this._events)o=o&&null==s.error;else if(!o)return!1;if(u=this.domain,o){if(t=arguments[1],u)t||(t=Error('Uncaught, unspecified "error" event')),t.domainEmitter=this,t.domain=u,t.domainThrown=!1,u.emit("error",t);else if(t instanceof Error)throw t;else{var c=Error('Uncaught, unspecified "error" event. ('+t+")");throw c.context=t,c}return!1}if(!(n=s[e]))return!1;var l="function"==typeof n;switch(r=arguments.length){case 1:!function(e,t,n){if(t)e.call(n);else for(var r=e.length,a=arrayClone(e,r),i=0;i<r;++i)a[i].call(n)}(n,l,this);break;case 2:!function(e,t,n,r){if(t)e.call(n,r);else for(var a=e.length,i=arrayClone(e,a),s=0;s<a;++s)i[s].call(n,r)}(n,l,this,arguments[1]);break;case 3:!function(e,t,n,r,a){if(t)e.call(n,r,a);else for(var i=e.length,s=arrayClone(e,i),u=0;u<i;++u)s[u].call(n,r,a)}(n,l,this,arguments[1],arguments[2]);break;case 4:!function(e,t,n,r,a,i){if(t)e.call(n,r,a,i);else for(var s=e.length,u=arrayClone(e,s),o=0;o<s;++o)u[o].call(n,r,a,i)}(n,l,this,arguments[1],arguments[2],arguments[3]);break;default:for(i=1,a=Array(r-1);i<r;i++)a[i-1]=arguments[i];!function(e,t,n,r){if(t)e.apply(n,r);else for(var a=e.length,i=arrayClone(e,a),s=0;s<a;++s)i[s].apply(n,r)}(n,l,this,a)}return!0},EventEmitter.prototype.addListener=function(e,t){return _addListener(this,e,t,!1)},EventEmitter.prototype.on=EventEmitter.prototype.addListener,EventEmitter.prototype.prependListener=function(e,t){return _addListener(this,e,t,!0)},EventEmitter.prototype.once=function(e,t){if("function"!=typeof t)throw TypeError('"listener" argument must be a function');return this.on(e,_onceWrap(this,e,t)),this},EventEmitter.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw TypeError('"listener" argument must be a function');return this.prependListener(e,_onceWrap(this,e,t)),this},EventEmitter.prototype.removeListener=function(e,t){var n,r,a,i,s;if("function"!=typeof t)throw TypeError('"listener" argument must be a function');if(!(r=this._events)||!(n=r[e]))return this;if(n===t||n.listener&&n.listener===t)0==--this._eventsCount?this._events=new EventHandlers:(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(a=-1,i=n.length;i-- >0;)if(n[i]===t||n[i].listener&&n[i].listener===t){s=n[i].listener,a=i;break}if(a<0)return this;if(1===n.length){if(n[0]=void 0,0==--this._eventsCount)return this._events=new EventHandlers,this;delete r[e]}else(function(e,t){for(var n=t,r=n+1,a=e.length;r<a;n+=1,r+=1)e[n]=e[r];e.pop()})(n,a);r.removeListener&&this.emit("removeListener",e,s||t)}return this},EventEmitter.prototype.off=function(e,t){return this.removeListener(e,t)},EventEmitter.prototype.removeAllListeners=function(e){if(!(n=this._events))return this;if(!n.removeListener)return 0==arguments.length?(this._events=new EventHandlers,this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=new EventHandlers:delete n[e]),this;if(0==arguments.length){for(var t,n,r,a=Object.keys(n),i=0;i<a.length;++i)"removeListener"!==(r=a[i])&&this.removeAllListeners(r);return this.removeAllListeners("removeListener"),this._events=new EventHandlers,this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(t)do this.removeListener(e,t[t.length-1]);while(t[0]);return this},EventEmitter.prototype.listeners=function(e){var t,n=this._events;return n&&(t=n[e])?"function"==typeof t?[t.listener||t]:function(e){for(var t=Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(t):[]},EventEmitter.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):listenerCount.call(e,t)},EventEmitter.prototype.listenerCount=listenerCount,EventEmitter.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};var Q=function(){function UriBuilder(e){S.default(this,UriBuilder),this.base=e,this.args=[],this.paths=[]}return E.default(UriBuilder,[{key:"pathSegment",value:function(e){return this.paths.push(encodeURIComponent(e)),this}},{key:"queryParam",value:function(e,t){return void 0!==t&&this.args.push(encodeURIComponent(e)+"="+encodeURIComponent(t)),this}},{key:"build",value:function(){var e=this.base;return this.paths.length&&(e+="/"+this.paths.join("/")),this.args.length&&(e+="?"+this.args.join("&")),e}}]),UriBuilder}();function _createSuper$7(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct||Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}();return function(){var n,r=R.default(e);if(t){var a=R.default(this).constructor;n=Reflect.construct(r,arguments,a)}else n=r.apply(this,arguments);return C.default(this,n)}}var B=function(e){T.default(SyncError,e);var t=_createSuper$7(SyncError);function SyncError(e){var n,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return S.default(this,SyncError),(n=t.call(this)).name=n.constructor.name,n.message="".concat(e," (status: ").concat(r,", code: ").concat(a,")"),n.status=r,n.code=a,n}return SyncError}(j.default(Error)),$=function(e){T.default(SyncNetworkError,e);var t=_createSuper$7(SyncNetworkError);function SyncNetworkError(e){var n,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,i=arguments.length>3?arguments[3]:void 0;return S.default(this,SyncNetworkError),(n=t.call(this,e,r,a)).body=i,n}return SyncNetworkError}(B);function deepClone(e){return JSON.parse(JSON.stringify(e))}function validatePageSize(e){if(!(void 0===e||isPositiveInteger(e)))throw new B("Invalid pageSize parameter. Expected a positive integer, was '".concat(e,"'."),400,20007)}function isPositiveInteger(e){return!isNaN(parseInt(e))&&isFinite(e)&&e>0}var H=O.getLogger("twilio-sync");function prepareLine(e,t){return["".concat(new Date().toISOString()," Sync ").concat(e,":")].concat(Array.from(t))}var K={setLevel:function(e){H.setLevel(e)},trace:function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];H.trace.apply(null,prepareLine("T",t))},debug:function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];H.debug.apply(null,prepareLine("D",t))},info:function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];H.info.apply(null,prepareLine("I",t))},warn:function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];H.warn.apply(null,prepareLine("W",t))},error:function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];H.error.apply(null,prepareLine("E",t))}},W=function(){function Configuration(){var e,t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};S.default(this,Configuration);var r=n.region||"us1",a=n.cdsUri||"https://cds.".concat(r,".twilio.com");this.settings={subscriptionsUri:a+"/v4/Subscriptions",documentsUri:a+"/v3/Documents",listsUri:a+"/v3/Lists",mapsUri:a+"/v3/Maps",streamsUri:a+"/v3/Streams",insightsUri:a+"/v3/Insights",sessionStorageEnabled:(e=n.Sync,t="enableSessionStorage",!e||void 0===e[t]||e[t]),productId:n.productId}}return E.default(Configuration,[{key:"subscriptionsUri",get:function(){return this.settings.subscriptionsUri}},{key:"documentsUri",get:function(){return this.settings.documentsUri}},{key:"listsUri",get:function(){return this.settings.listsUri}},{key:"mapsUri",get:function(){return this.settings.mapsUri}},{key:"streamsUri",get:function(){return this.settings.streamsUri}},{key:"insightsUri",get:function(){return this.settings.insightsUri}},{key:"backoffConfig",get:function(){return this.settings.backoffConfig||{}}},{key:"sessionStorageEnabled",get:function(){return this.settings.sessionStorageEnabled}},{key:"productId",get:function(){return this.settings.productId}}]),Configuration}();function _createForOfIteratorHelper$3(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray$3(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray$3(e,t)}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,F=function(){};return{s:F,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:F}}throw TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,i=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return i=e.done,e},e:function(e){s=!0,a=e},f:function(){try{i||null==n.return||n.return()}finally{if(s)throw a}}}}function _arrayLikeToArray$3(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var z=function(){function SubscribedEntity(e){S.default(this,SubscribedEntity),this.localObject=e,this.pendingCorrelationId=null,this.pendingAction=null,this.established=!1,this.retryCount=0}return E.default(SubscribedEntity,[{key:"sid",get:function(){return this.localObject.sid}},{key:"type",get:function(){return this.localObject.type}},{key:"lastEventId",get:function(){return this.localObject.lastEventId}},{key:"indexName",get:function(){return this.localObject.indexName}},{key:"queryString",get:function(){return this.localObject.queryString}},{key:"isEstablished",get:function(){return this.established}},{key:"update",value:function(e,t){this.localObject._update(e,t)}},{key:"updatePending",value:function(e,t){this.pendingAction=e,this.pendingCorrelationId=t}},{key:"reset",value:function(){this.updatePending(null,null),this.retryCount=0,this.established=!1,this.setSubscriptionState("none")}},{key:"markAsFailed",value:function(e){this.rejectedWithError=e.error,this.updatePending(null,null),this.localObject.reportFailure(new B("Failed to subscribe on service events: ".concat(e.error.message),e.error.status,e.error.code))}},{key:"complete",value:function(e){this.updatePending(null,null),this.established=!0,this.localObject._advanceLastEventId(e)}},{key:"setSubscriptionState",value:function(e){this.localObject._setSubscriptionState(e)}}]),SubscribedEntity}(),V=function(){var e;function Subscriptions(e){var t=this;S.default(this,Subscriptions),N.default(this,"isConnected",!1),N.default(this,"maxBatchSize",100),N.default(this,"subscriptionTtlTimer",null),N.default(this,"pendingPokeReason",null),this.services=e,this.subscriptions=new Map,this.persisted=new Map,this.latestPokeResponseArrivalTimestampByCorrelationId=new Map,this.backoff=k.Backoff.exponential(Object.assign({randomisationFactor:.2,initialDelay:100,maxDelay:12e4},this.services.config.backoffConfig)),this.backoff.on("ready",function(){var e=t.getSubscriptionUpdateBatch(),n=e.action,r=e.subscriptions;n?t.applyNewSubscriptionUpdateBatch(n,r):(t.backoff.reset(),K.debug("All subscriptions resolved."))})}return E.default(Subscriptions,[{key:"getSubscriptionUpdateBatch",value:function(){function subtract(e,t,n,r){var a,i=[],s=_createForOfIteratorHelper$3(e);try{for(s.s();!(a=s.n()).done;){var u=A.default(a.value,2),o=u[0],c=u[1];if(!t.get(o)&&n!==c.pendingAction&&!c.rejectedWithError&&(i.push(c),r&&i.length>=r))break}}catch(e){s.e(e)}finally{s.f()}return i}var e=subtract(this.subscriptions,this.persisted,"establish",this.maxBatchSize);if(e.length>0)return{action:"establish",subscriptions:e};var t=subtract(this.persisted,this.subscriptions,"cancel",this.maxBatchSize);return t.length>0?{action:"cancel",subscriptions:t}:{action:null,subscriptions:null}}},{key:"persist",value:function(){this.backoff.backoff()}},{key:"applyNewSubscriptionUpdateBatch",value:(e=x.default(M.default.mark(function _callee(e,t){var n,r,a,i,s,u,o,c,l,d,p,f,h=this;return M.default.wrap(function(v){for(;;)switch(v.prev=v.next){case 0:if(this.isConnected){v.next=4;break}return K.debug("Twilsock connection (required for subscription) not ready; waiting…"),this.backoff.reset(),v.abrupt("return");case 4:t=this.processLocalActions(e,t),n=new Date().getTime(),r=_createForOfIteratorHelper$3(t);try{for(r.s();!(a=r.n()).done;)i=a.value,this.recordActionAttemptOn(i,e,n)}catch(e){r.e(e)}finally{r.f()}return s=this.pendingPokeReason,this.pendingPokeReason=null,v.prev=10,v.next=13,this.request(e,n,s,t);case 13:!isNaN(parseInt(o=(u=v.sent).body.max_batch_size))&&isFinite(o)&&o>0&&(this.maxBatchSize=o),!this.subscriptionTtlTimer&&!isNaN(parseFloat(c=u.body.ttl_in_s))&&isFinite(c)&&c>0&&(this.subscriptionTtlTimer=setTimeout(function(){return h.onSubscriptionTtlElapsed()},1e3*c)),"establish"===e&&(!isNaN(parseFloat(l=u.body.estimated_delivery_in_ms))&&isFinite(l)&&l>0?setTimeout(function(){return h.verifyPokeDelivery(n,l,t)},l):K.error("Invalid timeout: ".concat(l)),t.filter(function(e){return e.pendingCorrelationId===n}).forEach(function(e){return e.setSubscriptionState("response_in_flight")})),this.backoff.reset(),v.next=26;break;case 21:v.prev=21,v.t0=v.catch(10),d=_createForOfIteratorHelper$3(t);try{for(d.s();!(p=d.n()).done;)f=p.value,this.recordActionFailureOn(f,e)}catch(e){d.e(e)}finally{d.f()}v.t0 instanceof y.TransportUnavailableError?(K.debug("Twilsock connection (required for subscription) not ready (c:".concat(n,"); waiting…")),this.backoff.reset()):(K.debug("Failed an attempt to ".concat(e," subscriptions (c:").concat(n,"); retrying"),v.t0),this.persist());case 26:case"end":return v.stop()}},_callee,this,[[10,21]])})),function(t,n){return e.apply(this,arguments)})},{key:"verifyPokeDelivery",value:function(e,t,n){var r=this,a=this.latestPokeResponseArrivalTimestampByCorrelationId.get(e),i=a?new Date().getTime()-a:t;i>=t?(n.filter(function(t){return t.pendingCorrelationId===e}).forEach(function(e){e.updatePending(null,null),e.retryCount++,r.persisted.delete(e.sid)}),this.persist(),this.latestPokeResponseArrivalTimestampByCorrelationId.delete(e)):setTimeout(function(){return r.verifyPokeDelivery(e,t,n)},t-i)}},{key:"processLocalActions",value:function(e,t){return"cancel"===e?t.filter(function(e){return!e.rejectedWithError}):t}},{key:"recordActionAttemptOn",value:function(e,t,n){if(e.setSubscriptionState("request_in_flight"),"establish"===t)this.persisted.set(e.sid,e),e.updatePending(t,n);else{var r=this.persisted.get(e.sid);r&&r.updatePending(t,n)}}},{key:"recordActionFailureOn",value:function(e,t){e.setSubscriptionState("none"),e.updatePending(null,null),"establish"===t&&this.persisted.delete(e.sid)}},{key:"request",value:function(e,t,n,r){var a=r.map(function(t){return{object_sid:t.sid,object_type:t.type,last_event_id:"establish"===e?t.lastEventId:void 0,index_name:"establish"===e?t.indexName:void 0,query_string:"establish"===e?t.queryString:void 0}}),i=r.filter(function(e){return e.retryCount>0}).length;K.debug("Attempting '".concat(e,"' request (c:").concat(t,"):"),a);var s={event_protocol_version:4,action:e,correlation_id:t,retried_requests:i,ttl_in_s:-1,requests:a};return"ttl"===n&&(s.reason=n),this.services.network.post(this.services.config.subscriptionsUri,s)}},{key:"add",value:function(e,t){K.debug("Establishing intent to subscribe to ".concat(e));var n=this.subscriptions.get(e);n&&t&&n.lastEventId===t.lastEventId||(this.persisted.delete(e),this.subscriptions.set(e,new z(t)),this.persist())}},{key:"remove",value:function(e){K.debug("Establishing intent to unsubscribe from ".concat(e)),this.subscriptions.delete(e)&&this.persist()}},{key:"acceptMessage",value:function(e,t){K.trace("Subscriptions received",e);var n=e.event_type,r=void 0!==e.events?e.events:[e.event],a=e.correlation_id;a&&this.latestPokeResponseArrivalTimestampByCorrelationId.set(a,new Date().getTime());var i,s=_createForOfIteratorHelper$3(r);try{for(s.s();!(i=s.n()).done;){var u=i.value,o=void 0;switch(e.event_type){case"subscription_established":this.applySubscriptionEstablishedMessage(u,a);break;case"subscription_canceled":this.applySubscriptionCancelledMessage(u,a);break;case"subscription_failed":this.applySubscriptionFailedMessage(u,a);break;case(o=n.match(/^(?:map|list|document|stream|live_query)_/)||{}).input:var c=void 0;switch(o[0]){case"map_":c=u.map_sid;break;case"list_":c=u.list_sid;break;case"document_":c=u.document_sid;break;case"stream_":c=u.stream_sid;break;case"live_query_":c=u.query_id,t=!1,!0===e.strictly_ordered&&(t=!0);break;default:c=void 0}this.applyEventToSubscribedEntity(c,u,n,t);break;default:K.debug("Dropping unknown message type ".concat(n))}}}catch(e){s.e(e)}finally{s.f()}}},{key:"applySubscriptionEstablishedMessage",value:function(e,t){var n=e.object_sid,r=this.persisted.get(e.object_sid);r&&r.pendingCorrelationId===t?"interrupted"===e.replay_status?(K.debug("Event Replay for subscription to ".concat(n," (c:").concat(t,") interrupted; continuing eagerly.")),r.updatePending(null,null),this.persisted.delete(r.sid),this.backoff.reset()):"completed"===e.replay_status&&(K.debug("Event Replay for subscription to ".concat(n," (c:").concat(t,") completed. Subscription is ready.")),r.complete(e.last_event_id),this.persisted.set(e.object_sid,r),r.setSubscriptionState("established"),this.backoff.reset()):K.debug("Late message for ".concat(e.object_sid," (c:").concat(t,") dropped.")),this.persist()}},{key:"applySubscriptionCancelledMessage",value:function(e,t){var n=this.persisted.get(e.object_sid);n&&n.pendingCorrelationId===t?(n.updatePending(null,null),n.setSubscriptionState("none"),this.persisted.delete(e.object_sid)):K.debug("Late message for ".concat(e.object_sid," (c:").concat(t,") dropped.")),this.persist()}},{key:"applySubscriptionFailedMessage",value:function(e,t){var n=e.object_sid,r=this.subscriptions.get(n),a=this.persisted.get(n);r&&a?a.pendingCorrelationId===t&&(K.error("Failed to subscribe on ".concat(a.sid),e.error),a.markAsFailed(e),a.setSubscriptionState("none")):!r&&a&&(this.persisted.delete(n),a.setSubscriptionState("none")),this.persist()}},{key:"applyEventToSubscribedEntity",value:function(e,t,n,r){var a;if(e){r=r||(a=this.persisted.get(e))&&a.isEstablished;var i=this.subscriptions.get(e);i?(t.type=n,i.update(t,r)):K.debug("Message dropped for SID '".concat(e,"', for which there is no subscription."))}}},{key:"onConnectionStateChanged",value:function(e){this.isConnected=e,e&&this.poke("reconnect")}},{key:"onSubscriptionTtlElapsed",value:function(){this.isConnected&&this.poke("ttl")}},{key:"poke",value:function(e){K.debug("Triggering event replay for all subscriptions, reason=".concat(e)),this.pendingPokeReason=e,this.subscriptionTtlTimer&&(clearTimeout(this.subscriptionTtlTimer),this.subscriptionTtlTimer=null);var t,n=[],r=_createForOfIteratorHelper$3(this.persisted.values());try{for(r.s();!(t=r.n()).done;){var a=t.value;a.reset(),a.rejectedWithError&&n.push(a)}}catch(e){r.e(e)}finally{r.f()}this.persisted.clear();for(var i=0;i<n.length;i++){var s=n[i];this.persisted.set(s.sid,s)}this.persist()}},{key:"shutdown",value:function(){this.backoff.reset(),this.subscriptions.clear()}}]),Subscriptions}();function messageFromErrorBody(e){if(e.body&&e.body.message)return e.body.message;switch(e.status){case 429:return"Throttled by server";case 404:return"Not found from server";default:return"Error from server"}}function codeFromErrorBody(e){return e.body?e.body.code:0}function mapTransportError(e){return 409===e.status?new $(messageFromErrorBody(e),e.status,codeFromErrorBody(e),e.body):e.status?new B(messageFromErrorBody(e),e.status,codeFromErrorBody(e)):e instanceof y.TransportUnavailableError?e:new B(e.message,0,0)}var J=function(){function NetworkService(e,t,n){S.default(this,NetworkService),this.clientInfo=e,this.config=t,this.transport=n}return E.default(NetworkService,[{key:"createHeaders",value:function(){return{"Content-Type":"application/json","Twilio-Sync-Client-Info":JSON.stringify(this.clientInfo),"Twilio-Request-Id":"RQ"+P.v4().replace(/-/g,"")}}},{key:"backoffConfig",value:function(){return Object.assign({min:4e3,max:6e4,maxAttemptsTime:9e4,randomness:.2},this.config.backoffConfig)}},{key:"executeWithRetry",value:function(e){var t=this,n=!(arguments.length>1)||void 0===arguments[1]||arguments[1];return new Promise(function(r,a){var i=[502,503,504];n&&i.push(429);var s=new k.Retrier(t.backoffConfig());s.on("attempt",function(){e().then(function(e){return s.succeeded(e)}).catch(function(e){if(i.includes(e.status)){var t=parseInt(e.headers?e.headers["Retry-After"]:null);s.failed(mapTransportError(e),isNaN(t)?null:1e3*t)}else"Twilsock disconnected"===e.message?s.failed(mapTransportError(e)):(s.removeAllListeners(),s.cancel(),a(mapTransportError(e)))})}),s.on("succeeded",function(e){r(e)}),s.on("cancelled",function(e){return a(mapTransportError(e))}),s.on("failed",function(e){return a(mapTransportError(e))}),s.start()})}},{key:"get",value:function(e){var t=this,n=this.createHeaders();return K.debug("GET",e,"ID:",n["Twilio-Request-Id"]),this.executeWithRetry(function(){return t.transport.get(e,n,t.config.productId)},!0)}},{key:"post",value:function(e,t,n){var r=this,a=arguments.length>3&&void 0!==arguments[3]&&arguments[3],i=this.createHeaders();return null!=n&&(i["If-Match"]=n),K.debug("POST",e,"ID:",i["Twilio-Request-Id"]),this.executeWithRetry(function(){return r.transport.post(e,i,t,r.config.productId)},a)}},{key:"put",value:function(e,t,n){var r=this,a=this.createHeaders();return null!=n&&(a["If-Match"]=n),K.debug("PUT",e,"ID:",a["Twilio-Request-Id"]),this.executeWithRetry(function(){return r.transport.put(e,a,t,r.config.productId)},!1)}},{key:"delete",value:function(e){var t=this,n=this.createHeaders();return K.debug("DELETE",e,"ID:",n["Twilio-Request-Id"]),this.executeWithRetry(function(){return t.transport.delete(e,n,t.config.productId)},!1)}}]),NetworkService}(),G=function(){function SessionStorage(e,t){S.default(this,SessionStorage),this.config=e,this.storageId=null;try{this.storage=t||sessionStorage}catch(e){}}return E.default(SessionStorage,[{key:"storageKey",value:function(e,t){return"".concat(this.storageId,"::").concat(e,"::").concat(t)}},{key:"isReady",get:function(){return this.config.sessionStorageEnabled&&!!this.storageId}},{key:"updateStorageId",value:function(e){this.storageId=e}},{key:"store",value:function(e,t,n){return this.isReady?this._store(this.storageKey(e,t),n):null}},{key:"read",value:function(e,t){return this.isReady?this._read(this.storageKey(e,t)):null}},{key:"remove",value:function(e,t,n){if(!this.isReady)return null;try{this.storage.removeItem(this.storageKey(e,t)),n&&this.storage.removeItem(this.storageKey(e,n))}catch(e){}}},{key:"update",value:function(e,t,n,r){if(!this.isReady)return null;this._apply(this.storageKey(e,t),r),n&&this._apply(this.storageKey(e,n),r)}},{key:"_store",value:function(e,t){try{this.storage.setItem(e,JSON.stringify(t))}catch(e){}}},{key:"_read",value:function(e){try{var t=this.storage.getItem(e);if(t)return JSON.parse(t)}catch(e){}return null}},{key:"_apply",value:function(e,t){var n=this._read(e);if(!n)return!1;this._store(e,Object.assign(n,t))}}]),SessionStorage}();function _arrayLikeToArray$2(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var Z=function(){function SyncEntity(e,t){S.default(this,SyncEntity),this.services=e,this.removalHandler=t,this.subscriptionState="none",this._attachedListeners=new Map}return E.default(SyncEntity,[{key:"_advanceLastEventId",value:function(e,t){}},{key:"reportFailure",value:function(e){404===e.status?this.onRemoved(!1):this.broadcastEventToListeners("failure",e)}},{key:"_subscribe",value:function(){this.services.router._subscribe(this.sid,this)}},{key:"_unsubscribe",value:function(){this.services.router._unsubscribe(this.sid)}},{key:"_setSubscriptionState",value:function(e){this.subscriptionState=e,this.broadcastEventToListeners("_subscriptionStateChanged",e)}},{key:"close",value:function(){this._unsubscribe(),null!=this.removalHandler&&this.removalHandler(this.type,this.sid,this.uniqueName)}},{key:"attach",value:function(e){var t=e.listenerUuid;this._attachedListeners.get(t)||(this._attachedListeners.size||this._subscribe(),this._attachedListeners.set(t,e))}},{key:"detach",value:function(e){this._attachedListeners.delete(e),this._attachedListeners.size||this.close()}},{key:"broadcastEventToListeners",value:function(e,t){var n,r=function(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray$2(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray$2(e,t)}}(e))){n&&(e=n);var r=0,F=function(){};return{s:F,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:F}}throw TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,i=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return i=e.done,e},e:function(e){s=!0,a=e},f:function(){try{i||null==n.return||n.return()}finally{if(s)throw a}}}}(this._attachedListeners.values());try{for(r.s();!(n=r.n()).done;)n.value.emit(e,t)}catch(e){r.e(e)}finally{r.f()}}}]),SyncEntity}(),X=function(){function MergingQueue(e){S.default(this,MergingQueue),N.default(this,"queuedRequests",[]),N.default(this,"isRequestInFlight",!1),this.inputMergingFunction=e}return E.default(MergingQueue,[{key:"add",value:function(e,t){var n=this,r=new Promise(function(r,a){return n.queuedRequests.push({input:e,requestFunction:t,resolve:r,reject:a})});return this.wakeupQueue(),r}},{key:"squashAndAdd",value:function(e,t){var n,r=this.queuedRequests;this.queuedRequests=[],r.length>0?(n=r.map(function(e){return e.input}).reduce(this.inputMergingFunction),n=this.inputMergingFunction(n,e)):n=e;var a=this.add(n,t);return r.forEach(function(e){return a.then(e.resolve,e.reject)}),a}},{key:"isEmpty",value:function(){return 0===this.queuedRequests.length&&!this.isRequestInFlight}},{key:"wakeupQueue",value:function(){var e=this;if(0!==this.queuedRequests.length&&!this.isRequestInFlight){var t=this.queuedRequests.shift();this.isRequestInFlight=!0,t.requestFunction(t.input).then(t.resolve,t.reject).then(function(t){e.isRequestInFlight=!1,e.wakeupQueue()})}}}]),MergingQueue}(),Y=function(){var e,t,n;function NamespacedMergingQueue(e){S.default(this,NamespacedMergingQueue),N.default(this,"queueByNamespaceKey",new Map),this.inputReducer=e}return E.default(NamespacedMergingQueue,[{key:"add",value:(e=x.default(M.default.mark(function _callee(e,t,n){return M.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",this.invokeQueueMethod(e,function(e){return e.add(t,n)}));case 1:case"end":return r.stop()}},_callee,this)})),function(t,n,r){return e.apply(this,arguments)})},{key:"squashAndAdd",value:(t=x.default(M.default.mark(function _callee2(e,t,n){return M.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",this.invokeQueueMethod(e,function(e){return e.squashAndAdd(t,n)}));case 1:case"end":return r.stop()}},_callee2,this)})),function(e,n,r){return t.apply(this,arguments)})},{key:"invokeQueueMethod",value:(n=x.default(M.default.mark(function _callee3(e,t){var n;return M.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return this.queueByNamespaceKey.has(e)||this.queueByNamespaceKey.set(e,new X(this.inputReducer)),n=t(this.queueByNamespaceKey.get(e)),this.queueByNamespaceKey.get(e).isEmpty()&&this.queueByNamespaceKey.delete(e),r.abrupt("return",n);case 5:case"end":return r.stop()}},_callee3,this)})),function(e,t){return n.apply(this,arguments)})}]),NamespacedMergingQueue}(),ee=function(e){T.default(Closeable,e);var t,n=(t=function(){if("undefined"==typeof Reflect||!Reflect.construct||Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}(),function(){var e,n=R.default(Closeable);if(t){var r=R.default(this).constructor;e=Reflect.construct(n,arguments,r)}else e=n.apply(this,arguments);return C.default(this,e)});function Closeable(){var e;return S.default(this,Closeable),(e=n.call(this)).closed=!1,e.uuid=b.v4(),e}return E.default(Closeable,[{key:"listenerUuid",get:function(){return this.uuid}},{key:"close",value:function(){this.removeAllListeners(),this.closed=!0}},{key:"ensureNotClosed",value:function(){if(this.closed)throw Error("Invalid operation on closed object")}}]),Closeable}(EventEmitter);function _createSuper$5(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct||Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}();return function(){var n,r=R.default(e);if(t){var a=R.default(this).constructor;n=Reflect.construct(r,arguments,a)}else n=r.apply(this,arguments);return C.default(this,n)}}var et=function(e){T.default(SyncDocumentImpl,e);var t,n,r,a,i,s,u,o,c,l=_createSuper$5(SyncDocumentImpl);function SyncDocumentImpl(e,t,n){var r;return S.default(this,SyncDocumentImpl),r=l.call(this,e,n),N.default(L.default(r),"isDeleted",!1),r.updateMergingQueue=new X(function(e,t){return"number"==typeof t.ttl?{ttl:t.ttl}:e}),r.descriptor=t,r.descriptor.data=r.descriptor.data||{},r.descriptor.date_updated=new Date(r.descriptor.date_updated),r}return E.default(SyncDocumentImpl,[{key:"uri",get:function(){return this.descriptor.url}},{key:"revision",get:function(){return this.descriptor.revision}},{key:"lastEventId",get:function(){return this.descriptor.last_event_id}},{key:"dateExpires",get:function(){return this.descriptor.date_expires}},{key:"type",get:function(){return"document"}},{key:"indexName",get:function(){}},{key:"queryString",get:function(){}},{key:"sid",get:function(){return this.descriptor.sid}},{key:"data",get:function(){return this.descriptor.data}},{key:"dateUpdated",get:function(){return this.descriptor.date_updated}},{key:"uniqueName",get:function(){return this.descriptor.unique_name||null}},{key:"_update",value:function(e){switch(e.date_created=new Date(e.date_created),e.type){case"document_updated":if(e.id<=this.lastEventId){K.trace("Document update skipped, current:",this.lastEventId,", remote:",e.id);break}var t=void 0!==this.descriptor.data?deepClone(this.descriptor.data):null;this.descriptor.last_event_id=e.id,this.descriptor.revision=e.document_revision,this.descriptor.date_updated=e.date_created,this.descriptor.data=e.document_data,this.broadcastEventToListeners("updated",{data:e.document_data,isLocal:!1,previousData:t}),this.services.storage.update(this.type,this.sid,this.uniqueName,{last_event_id:e.id,revision:e.document_revision,date_updated:e.date_created,data:e.document_data});break;case"document_removed":this.onRemoved(!1)}}},{key:"set",value:(t=x.default(M.default.mark(function _callee(e,t){var n,r=this;return M.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return n=t||{},a.abrupt("return",this.updateMergingQueue.squashAndAdd(n,function(t){return r._setUnconditionally(e,t.ttl)}));case 2:case"end":return a.stop()}},_callee,this)})),function(e,n){return t.apply(this,arguments)})},{key:"mutate",value:(n=x.default(M.default.mark(function _callee2(e,t){var n,r=this;return M.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return n=t||{},a.abrupt("return",this.updateMergingQueue.add(n,function(t){return r._setWithIfMatch(e,t.ttl)}));case 2:case"end":return a.stop()}},_callee2,this)})),function(e,t){return n.apply(this,arguments)})},{key:"update",value:(r=x.default(M.default.mark(function _callee3(e,t){return M.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.abrupt("return",this.mutate(function(t){return Object.assign(t,e)},t));case 1:case"end":return n.stop()}},_callee3,this)})),function(e,t){return r.apply(this,arguments)})},{key:"setTtl",value:(a=x.default(M.default.mark(function _callee4(e){var t;return M.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,this._postUpdateToServer({ttl:e});case 2:t=n.sent,this.descriptor.date_expires=t.date_expires;case 4:case"end":return n.stop()}},_callee4,this)})),function(e){return a.apply(this,arguments)})},{key:"_setUnconditionally",value:(i=x.default(M.default.mark(function _callee5(e,t){var n;return M.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this._postUpdateToServer({data:e,revision:void 0,ttl:t});case 2:return n=r.sent,this._handleSuccessfulUpdateResult(n),r.abrupt("return",this.descriptor.data);case 5:case"end":return r.stop()}},_callee5,this)})),function(e,t){return i.apply(this,arguments)})},{key:"_setWithIfMatch",value:(s=x.default(M.default.mark(function _callee6(e,t){var n,r,a;return M.default.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:if(!(n=e(deepClone(this.descriptor.data)))){i.next=22;break}return r=this.revision,i.prev=3,i.next=6,this._postUpdateToServer({data:n,revision:r,ttl:t});case 6:return a=i.sent,this._handleSuccessfulUpdateResult(a),i.abrupt("return",this.descriptor.data);case 11:if(i.prev=11,i.t0=i.catch(3),412!==i.t0.status){i.next=19;break}return i.next=16,this._softSync();case 16:return i.abrupt("return",this._setWithIfMatch(e));case 19:throw i.t0;case 20:i.next=23;break;case 22:return i.abrupt("return",this.descriptor.data);case 23:case"end":return i.stop()}},_callee6,this,[[3,11]])})),function(e,t){return s.apply(this,arguments)})},{key:"_handleSuccessfulUpdateResult",value:function(e){if(!(e.last_event_id<=this.descriptor.last_event_id)){var t=void 0!==this.descriptor.data?deepClone(this.descriptor.data):null;this.descriptor.revision=e.revision,this.descriptor.data=e.data,this.descriptor.last_event_id=e.last_event_id,this.descriptor.date_expires=e.date_expires,this.descriptor.date_updated=new Date(e.date_updated),this.services.storage.update(this.type,this.sid,this.uniqueName,{last_event_id:e.last_event_id,revision:e.revision,date_updated:e.date_updated,data:e.data}),this.broadcastEventToListeners("updated",{data:this.descriptor.data,isLocal:!0,previousData:t})}}},{key:"_postUpdateToServer",value:(u=x.default(M.default.mark(function _callee7(e){var t,n,r;return M.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(this.isDeleted){a.next=17;break}return t={data:e.data},void 0!==e.ttl&&(t.ttl=e.ttl),n=e.revision,a.prev=4,a.next=7,this.services.network.post(this.uri,t,n);case 7:return r=a.sent,a.abrupt("return",{revision:r.body.revision,data:e.data,last_event_id:r.body.last_event_id,date_updated:r.body.date_updated,date_expires:r.body.date_expires});case 11:throw a.prev=11,a.t0=a.catch(4),404===a.t0.status&&this.onRemoved(!1),a.t0;case 15:a.next=18;break;case 17:return a.abrupt("return",Promise.reject(new B("The Document has been removed",404,54100)));case 18:case"end":return a.stop()}},_callee7,this,[[4,11]])})),function(e){return u.apply(this,arguments)})},{key:"_softSync",value:(o=x.default(M.default.mark(function _callee8(){var e=this;return M.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.services.network.get(this.uri).then(function(t){var n={type:"document_updated",id:t.body.last_event_id,document_revision:t.body.revision,document_data:t.body.data,date_created:t.body.date_updated};return e._update(n),e}).catch(function(t){404===t.status?e.onRemoved(!1):K.error("Can't get updates for ".concat(e.sid,":"),t)}));case 1:case"end":return t.stop()}},_callee8,this)})),function(){return o.apply(this,arguments)})},{key:"onRemoved",value:function(e){if(!this.isDeleted){var t=void 0!==this.descriptor.data?deepClone(this.descriptor.data):null;this.isDeleted=!0,this._unsubscribe(),this.removalHandler(this.type,this.sid,this.uniqueName),this.broadcastEventToListeners("removed",{isLocal:e,previousData:t})}}},{key:"removeDocument",value:(c=x.default(M.default.mark(function _callee9(){return M.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.isDeleted){e.next=6;break}return e.next=3,this.services.network.delete(this.uri);case 3:this.onRemoved(!0),e.next=7;break;case 6:return e.abrupt("return",Promise.reject(new B("The Document has been removed",404,54100)));case 7:case"end":return e.stop()}},_callee9,this)})),function(){return c.apply(this,arguments)})}],[{key:"type",get:function(){return"document"}}]),SyncDocumentImpl}(Z),en=function(e){T.default(SyncDocument,e);var t,n,r,a,i,s=_createSuper$5(SyncDocument);function SyncDocument(e){var t;return S.default(this,SyncDocument),(t=s.call(this)).syncDocumentImpl=e,t.syncDocumentImpl.attach(L.default(t)),t}return E.default(SyncDocument,[{key:"uri",get:function(){return this.syncDocumentImpl.uri}},{key:"revision",get:function(){return this.syncDocumentImpl.revision}},{key:"lastEventId",get:function(){return this.syncDocumentImpl.lastEventId}},{key:"dateExpires",get:function(){return this.syncDocumentImpl.dateExpires}},{key:"type",get:function(){return et.type}},{key:"sid",get:function(){return this.syncDocumentImpl.sid}},{key:"data",get:function(){return this.syncDocumentImpl.data}},{key:"dateUpdated",get:function(){return this.syncDocumentImpl.dateUpdated}},{key:"uniqueName",get:function(){return this.syncDocumentImpl.uniqueName}},{key:"set",value:(t=x.default(M.default.mark(function _callee10(e,t){return M.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return this.ensureNotClosed(),n.abrupt("return",this.syncDocumentImpl.set(e,t));case 2:case"end":return n.stop()}},_callee10,this)})),function(e,n){return t.apply(this,arguments)})},{key:"mutate",value:(n=x.default(M.default.mark(function _callee11(e,t){return M.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return this.ensureNotClosed(),n.abrupt("return",this.syncDocumentImpl.mutate(e,t));case 2:case"end":return n.stop()}},_callee11,this)})),function(e,t){return n.apply(this,arguments)})},{key:"update",value:(r=x.default(M.default.mark(function _callee12(e,t){return M.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return this.ensureNotClosed(),n.abrupt("return",this.syncDocumentImpl.update(e,t));case 2:case"end":return n.stop()}},_callee12,this)})),function(e,t){return r.apply(this,arguments)})},{key:"setTtl",value:(a=x.default(M.default.mark(function _callee13(e){return M.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return this.ensureNotClosed(),t.abrupt("return",this.syncDocumentImpl.setTtl(e));case 2:case"end":return t.stop()}},_callee13,this)})),function(e){return a.apply(this,arguments)})},{key:"removeDocument",value:(i=x.default(M.default.mark(function _callee14(){return M.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncDocumentImpl.removeDocument());case 2:case"end":return e.stop()}},_callee14,this)})),function(){return i.apply(this,arguments)})},{key:"close",value:function(){D.default(R.default(SyncDocument.prototype),"close",this).call(this),this.syncDocumentImpl.detach(this.listenerUuid)}}],[{key:"type",get:function(){return et.type}}]),SyncDocument}(ee);N.default(en,"removed","removed"),N.default(en,"updated","updated"),__decorate([h.validateTypesAsync(h.pureObject,["undefined",h.objectSchema("document metadata",{ttl:[h.nonNegativeInteger,"undefined"]})]),__metadata("design:type",Function),__metadata("design:paramtypes",[Object,Object]),__metadata("design:returntype",Promise)],en.prototype,"set",null),__decorate([h.validateTypesAsync("function",["undefined",h.objectSchema("document metadata",{ttl:[h.nonNegativeInteger,"undefined"]})]),__metadata("design:type",Function),__metadata("design:paramtypes",[Function,Object]),__metadata("design:returntype",Promise)],en.prototype,"mutate",null),__decorate([h.validateTypesAsync(h.pureObject,["undefined",h.objectSchema("document metadata",{ttl:[h.nonNegativeInteger,"undefined"]})]),__metadata("design:type",Function),__metadata("design:paramtypes",[Object,Object]),__metadata("design:returntype",Promise)],en.prototype,"update",null),__decorate([h.validateTypesAsync(h.nonNegativeInteger),__metadata("design:type",Function),__metadata("design:paramtypes",[Number]),__metadata("design:returntype",Promise)],en.prototype,"setTtl",null);var er=function(){function SyncListItem(e){S.default(this,SyncListItem),this.descriptor=e}return E.default(SyncListItem,[{key:"uri",get:function(){return this.descriptor.uri}},{key:"revision",get:function(){return this.descriptor.revision}},{key:"lastEventId",get:function(){return this.descriptor.lastEventId}},{key:"dateUpdated",get:function(){return this.descriptor.dateUpdated}},{key:"dateExpires",get:function(){return this.descriptor.dateExpires}},{key:"index",get:function(){return this.descriptor.index}},{key:"data",get:function(){return this.descriptor.data}},{key:"update",value:function(e,t,n,r){return this.descriptor.lastEventId=e,this.descriptor.revision=t,this.descriptor.data=n,this.descriptor.dateUpdated=r,this}},{key:"updateDateExpires",value:function(e){this.descriptor.dateExpires=e}}]),SyncListItem}(),ea=function(){var e,t;function Paginator(e,t,n,r){S.default(this,Paginator),this.prevToken=n,this.nextToken=r,this.items=e,this.source=t}return E.default(Paginator,[{key:"hasNextPage",get:function(){return!!this.nextToken}},{key:"hasPrevPage",get:function(){return!!this.prevToken}},{key:"nextPage",value:(e=x.default(M.default.mark(function _callee(){return M.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.hasNextPage){e.next=2;break}throw Error("No next page");case 2:return e.abrupt("return",this.source(this.nextToken));case 3:case"end":return e.stop()}},_callee,this)})),function(){return e.apply(this,arguments)})},{key:"prevPage",value:(t=x.default(M.default.mark(function _callee2(){return M.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.hasPrevPage){e.next=2;break}throw Error("No previous page");case 2:return e.abrupt("return",this.source(this.prevToken));case 3:case"end":return e.stop()}},_callee2,this)})),function(){return t.apply(this,arguments)})}]),Paginator}();function _arrayLikeToArray$1(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var ei=function(){function Node(e,t){S.default(this,Node),this.balanceFactor=0,this.key=e,this.value=t,this.parent=null,this.left=null,this.right=null}return E.default(Node,[{key:"isRoot",get:function(){return null===this.parent}},{key:"isLeaf",get:function(){return null===this.left&&null===this.right}},{key:"isLeftChild",get:function(){return this.parent.left===this}},{key:"update",value:function(e){this.value=e}},{key:"replace",value:function(e,t){e&&(this.left===t?this.left=t:this.right===t&&(this.right=t))}}]),Node}(),es=function(){function TreeMap(e,t){S.default(this,TreeMap),this.isLessThan=e||function(e,t){return e<t},this.isEqual=t||function(e,t){return e===t},this.root=null,this.count=null}return E.default(TreeMap,[{key:"size",get:function(){return this.count}},{key:"clear",value:function(){this.root=null,this.count=0}},{key:"set",value:function(e,t){var n=this.getNode(e);n?n.update(t):this.insert(e,t)}},{key:"insert",value:function(e,t){var n=new ei(e,t);if(this.count++,!this.root){this.root=n;return}for(var r=this.root;;)if(this.isLessThan(e,r.key)){if(r.left)r=r.left;else{r.left=n;break}}else if(r.right)r=r.right;else{r.right=n;break}for(n.parent=r,r=n;r.parent;){var a=r.parent,i=a.balanceFactor;if(r.isLeftChild?a.balanceFactor++:a.balanceFactor--,Math.abs(a.balanceFactor)<Math.abs(i))break;if(a.balanceFactor<-1||a.balanceFactor>1){this.rebalance(a);break}r=a}}},{key:"get",value:function(e){for(var t=this.root;t;){if(this.isEqual(e,t.key))return t.value;t=this.isLessThan(e,t.key)?t.left:t.right}return null}},{key:"delete",value:function(e){var t=this.getNode(e);if(!t||t.key!==e)return null;var n=t.parent,r=t.left,a=t.right;if(!!r!=!!a){var i=r||a;n||i?n&&!i?this.root=i:(n.replace(t,null),this.rebalance(n)):this.root=null}else{for(var s=t.left;s.right;)s=s.right;if(t.left===s)t.isRoot?(this.root=s,s.parent=null):(t.isLeftChild?t.parent.left=s:t.parent.right=s,s.parent=t.parent),s.right=t.right,s.right.parent=s,s.balanceFactor=t.balanceFactor,t={parent:s,isLeftChild:!0};else{var u=s.parent,o=s.left;u.right=o,o&&(o.parent=u),t.isRoot?(this.root=s,s.parent=null):(t.isLeftChild?t.parent.left=s:t.parent.right=s,s.parent=t.parent),s.right=t.right,s.right.parent=s,s.left=t.left,s.left.parent=s,s.balanceFactor=t.balanceFactor,t={parent:u,isLeftChild:!1}}}for(this.count--;t.parent;){var c=t.parent,l=c.balanceFactor;if(t.isLeftChild?c.balanceFactor-=1:c.balanceFactor+=1,Math.abs(c.balanceFactor)>Math.abs(l)){if(c.balanceFactor<-1||c.balanceFactor>1){if(this.rebalance(c),0===c.parent.balanceFactor)t=c.parent;else break}else break}else t=c}return null}},{key:"getNode",value:function(e){for(var t=this.root;t;){if(this.isEqual(e,t.key))return t;t=this.isLessThan(e,t.key)?t.left:t.right}return null}},{key:"rebalance",value:function(e){e.balanceFactor<0?(e.right.balanceFactor>0&&this.rotateRight(e.right),this.rotateLeft(e)):e.balanceFactor>0&&(e.left.balanceFactor<0&&this.rotateLeft(e.left),this.rotateRight(e))}},{key:"rotateLeft",value:function(e){var t=e.right;e.right=t.left,null!==t.left&&(t.left.parent=e),t.parent=e.parent,null===t.parent?this.root=t:e.isLeftChild?t.parent.left=t:t.parent.right=t,t.left=e,e.parent=t,e.balanceFactor=e.balanceFactor+1-Math.min(t.balanceFactor,0),t.balanceFactor=t.balanceFactor+1-Math.max(e.balanceFactor,0)}},{key:"rotateRight",value:function(e){var t=e.left;e.left=t.right,null!==t.right&&(t.right.parent=e),t.parent=e.parent,null===t.parent?this.root=t:e.isLeftChild?t.parent.left=t:t.parent.right=t,t.right=e,e.parent=t,e.balanceFactor=e.balanceFactor-1-Math.min(t.balanceFactor,0),t.balanceFactor=t.balanceFactor-1-Math.max(e.balanceFactor,0)}},{key:Symbol.iterator,value:M.default.mark(function value(){var e,t,n;return M.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:e=function(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray$1(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray$1(e,t)}}(e))){n&&(e=n);var r=0,F=function(){};return{s:F,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:F}}throw TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,i=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return i=e.done,e},e:function(e){s=!0,a=e},f:function(){try{i||null==n.return||n.return()}finally{if(s)throw a}}}}(this.getIterator()),r.prev=1,e.s();case 3:if((t=e.n()).done){r.next=9;break}return n=t.value,r.next=7,n;case 7:r.next=3;break;case 9:r.next=14;break;case 11:r.prev=11,r.t0=r.catch(1),e.e(r.t0);case 14:return r.prev=14,e.f(),r.finish(14);case 17:case"end":return r.stop()}},value,this,[[1,11,14,17]])})},{key:"getIterator",value:M.default.mark(function getIterator(){var e,t,n,r=arguments;return M.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:e=r.length>0&&void 0!==r[0]?r[0]:null,t=this.root;case 2:if(!t){a.next=8;break}if(!(this.isEqual(e,t.key)||null===e&&!t.left)){a.next=5;break}return a.abrupt("break",8);case 5:t=this.isLessThan(e,t.key)||null===e?t.left:t.right,a.next=2;break;case 8:if(t){a.next=10;break}return a.abrupt("return",null);case 10:n=!0;case 11:if(!n){a.next=29;break}return a.next=14,[t.key,t.value];case 14:if(n=!1,!t.right){a.next=21;break}for(t=t.right;t.left;)t=t.left;n=!0,a.next=27;break;case 21:if(!t.parent){a.next=26;break}n=t.parent.left===t,t=t.parent,a.next=27;break;case 26:case 34:return a.abrupt("break",37);case 27:a.next=35;break;case 29:if(!t.parent){a.next=34;break}n=t.parent.left===t,t=t.parent,a.next=35;break;case 35:a.next=11;break;case 37:return a.abrupt("return",null);case 38:case"end":return a.stop()}},getIterator,this)})},{key:"getReverseIterator",value:M.default.mark(function getReverseIterator(){var e,t,n,r=arguments;return M.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:e=r.length>0&&void 0!==r[0]?r[0]:null,t=this.root;case 2:if(!t){a.next=8;break}if(!(this.isEqual(e,t.key)||null===e&&!t.right)){a.next=5;break}return a.abrupt("break",8);case 5:t=this.isLessThan(e,t.key)&&null!==e?t.left:t.right,a.next=2;break;case 8:if(t){a.next=10;break}return a.abrupt("return",null);case 10:n=!0;case 11:if(!n){a.next=29;break}return a.next=14,[t.key,t.value];case 14:if(n=!1,!t.left){a.next=21;break}for(t=t.left;t.right;)t=t.right;n=!0,a.next=27;break;case 21:if(!t.parent){a.next=26;break}n=t.parent.right===t,t=t.parent,a.next=27;break;case 26:case 34:return a.abrupt("break",37);case 27:a.next=35;break;case 29:if(!t.parent){a.next=34;break}n=t.parent.right===t,t=t.parent,a.next=35;break;case 35:a.next=11;break;case 37:return a.abrupt("return",null);case 38:case"end":return a.stop()}},getReverseIterator,this)})}]),TreeMap}();function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var eu=function(){function Entry(e,t){S.default(this,Entry),this.value=e,this.revision=t||0}return E.default(Entry,[{key:"isValid",get:function(){return!0}}]),Entry}(),eo=function(){function Tombstone(e){S.default(this,Tombstone),this.revision=e}return E.default(Tombstone,[{key:"isValid",get:function(){return!1}}]),Tombstone}(),ec=function(){function Cache(){S.default(this,Cache),this.items=new es}return E.default(Cache,[{key:"store",value:function(e,t,n){var r=this.items.get(e);return r&&r.revision>n?r.isValid?r.value:null:(this.items.set(e,new eu(t,n)),t)}},{key:"delete",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=this.items.get(e);(!r||r.revision<t||r&&!0===n)&&this.items.set(e,new eo(t))}},{key:"isKnown",value:function(e,t){var n=this.items.get(e);return n&&n.revision>=t}},{key:"get",value:function(e){var t=this.items.get(e);return t&&t.isValid?t.value:null}},{key:"has",value:function(e){var t=this.items.get(e);return t&&t.isValid}},{key:"forEach",value:function(e){if(this.items){var t,n=function(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(e,t)}}(e))){n&&(e=n);var r=0,F=function(){};return{s:F,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:F}}throw TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,i=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return i=e.done,e},e:function(e){s=!0,a=e},f:function(){try{i||null==n.return||n.return()}finally{if(s)throw a}}}}(this.items);try{for(n.s();!(t=n.n()).done;){var r=A.default(t.value,2),a=r[0],i=r[1];i.isValid&&e(a,i.value)}}catch(e){n.e(e)}finally{n.f()}}}}]),Cache}();function _createSuper$4(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct||Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}();return function(){var n,r=R.default(e);if(t){var a=R.default(this).constructor;n=Reflect.construct(r,arguments,a)}else n=r.apply(this,arguments);return C.default(this,n)}}var el=function(e){T.default(SyncListImpl,e);var t,n,r,a,i,s,u,o,c,l,d,p,f,h,y,v,m=_createSuper$4(SyncListImpl);function SyncListImpl(e,t,n){var r;return S.default(this,SyncListImpl),(r=m.call(this,e,n)).updateMergingQueue=new Y(function(e,t){return"number"==typeof t.ttl?{ttl:t.ttl}:e}),r.cache=new ec,r.descriptor=t,r.descriptor.date_updated=new Date(r.descriptor.date_updated),r}return E.default(SyncListImpl,[{key:"uri",get:function(){return this.descriptor.url}},{key:"revision",get:function(){return this.descriptor.revision}},{key:"lastEventId",get:function(){return this.descriptor.last_event_id}},{key:"links",get:function(){return this.descriptor.links}},{key:"dateExpires",get:function(){return this.descriptor.date_expires}},{key:"type",get:function(){return"list"}},{key:"indexName",get:function(){}},{key:"queryString",get:function(){}},{key:"sid",get:function(){return this.descriptor.sid}},{key:"uniqueName",get:function(){return this.descriptor.unique_name||null}},{key:"dateUpdated",get:function(){return this.descriptor.date_updated}},{key:"_addOrUpdateItemOnServer",value:(t=x.default(M.default.mark(function _callee(e,t,n,r){var a,i;return M.default.wrap(function(s){for(;;)switch(s.prev=s.next){case 0:return a={data:t},void 0!==r&&(a.ttl=r),s.next=4,this.services.network.post(e,a,n);case 4:return(i=s.sent).body.data=t,i.body.date_updated=new Date(i.body.date_updated),s.abrupt("return",i.body);case 8:case"end":return s.stop()}},_callee,this)})),function(e,n,r,a){return t.apply(this,arguments)})},{key:"push",value:(n=x.default(M.default.mark(function _callee2(e,t){var n,r,a;return M.default.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return n=(t||{}).ttl,i.next=3,this._addOrUpdateItemOnServer(this.links.items,e,void 0,n);case 3:return a=Number((r=i.sent).index),this._handleItemMutated(a,r.url,r.last_event_id,r.revision,e,r.date_updated,r.date_expires,!0,!1),i.abrupt("return",this.cache.get(a));case 7:case"end":return i.stop()}},_callee2,this)})),function(e,t){return n.apply(this,arguments)})},{key:"set",value:(r=x.default(M.default.mark(function _callee3(e,t,n){var r,a=this;return M.default.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return r=n||{},i.abrupt("return",this.updateMergingQueue.squashAndAdd(e,r,function(n){return a._updateItemUnconditionally(e,t,n.ttl)}));case 2:case"end":return i.stop()}},_callee3,this)})),function(e,t,n){return r.apply(this,arguments)})},{key:"_updateItemUnconditionally",value:(a=x.default(M.default.mark(function _callee4(e,t,n){var r,a;return M.default.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return i.next=2,this.get(e);case 2:return r=i.sent,i.next=5,this._addOrUpdateItemOnServer(r.uri,t,void 0,n);case 5:return a=i.sent,this._handleItemMutated(e,a.url,a.last_event_id,a.revision,a.data,a.date_updated,a.date_expires,!1,!1),i.abrupt("return",this.cache.get(e));case 8:case"end":return i.stop()}},_callee4,this)})),function(e,t,n){return a.apply(this,arguments)})},{key:"_updateItemWithIfMatch",value:(i=x.default(M.default.mark(function _callee5(e,t,n){var r,a,i,s;return M.default.wrap(function(u){for(;;)switch(u.prev=u.next){case 0:return u.next=2,this.get(e);case 2:if(!(a=t(deepClone((r=u.sent).data)))){u.next=25;break}return i=r.revision,u.prev=6,u.next=9,this._addOrUpdateItemOnServer(r.uri,a,i,n);case 9:return s=u.sent,this._handleItemMutated(e,s.url,s.last_event_id,s.revision,s.data,s.date_updated,s.date_expires,!1,!1),u.abrupt("return",this.cache.get(e));case 14:if(u.prev=14,u.t0=u.catch(6),412!==u.t0.status){u.next=22;break}return u.next=19,this._getItemFromServer(e);case 19:return u.abrupt("return",this._updateItemWithIfMatch(e,t,n));case 22:throw u.t0;case 23:u.next=26;break;case 25:return u.abrupt("return",r);case 26:case"end":return u.stop()}},_callee5,this,[[6,14]])})),function(e,t,n){return i.apply(this,arguments)})},{key:"mutate",value:(s=x.default(M.default.mark(function _callee6(e,t,n){var r,a=this;return M.default.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return r=n||{},i.abrupt("return",this.updateMergingQueue.add(e,r,function(n){return a._updateItemWithIfMatch(e,t,n.ttl)}));case 2:case"end":return i.stop()}},_callee6,this)})),function(e,t,n){return s.apply(this,arguments)})},{key:"update",value:(u=x.default(M.default.mark(function _callee7(e,t,n){return M.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",this.mutate(e,function(e){return Object.assign(e,t)},n));case 1:case"end":return r.stop()}},_callee7,this)})),function(e,t,n){return u.apply(this,arguments)})},{key:"remove",value:(o=x.default(M.default.mark(function _callee8(e){var t,n,r;return M.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.next=2,this.get(e);case 2:return n=deepClone((t=a.sent).data),a.next=6,this.services.network.delete(t.uri);case 6:r=a.sent,this._handleItemRemoved(e,r.body.last_event_id,n,new Date(r.body.date_updated),!1);case 8:case"end":return a.stop()}},_callee8,this)})),function(e){return o.apply(this,arguments)})},{key:"get",value:(c=x.default(M.default.mark(function _callee9(e){var t;return M.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(!(t=this.cache.get(e))){n.next=5;break}return n.abrupt("return",t);case 5:return n.abrupt("return",this._getItemFromServer(e));case 6:case"end":return n.stop()}},_callee9,this)})),function(e){return c.apply(this,arguments)})},{key:"_getItemFromServer",value:(l=x.default(M.default.mark(function _callee10(e){var t;return M.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,this.queryItems({index:e});case 2:if(!((t=n.sent).items.length<1)){n.next=7;break}throw new B("No item with index ".concat(e," found"),404,54151);case 7:return n.abrupt("return",t.items[0]);case 8:case"end":return n.stop()}},_callee10,this)})),function(e){return l.apply(this,arguments)})},{key:"queryItems",value:(d=x.default(M.default.mark(function _callee11(e){var t,n,r,a,i=this;return M.default.wrap(function(s){for(;;)switch(s.prev=s.next){case 0:return e=e||{},t=new Q(this.links.items).queryParam("From",e.from).queryParam("PageSize",e.limit).queryParam("Index",e.index).queryParam("PageToken",e.pageToken).queryParam("Order",e.order).build(),s.next=4,this.services.network.get(t);case 4:return r=(n=s.sent).body.items.map(function(e){return e.date_updated=new Date(e.date_updated),i.cache.get(e.index)?i._handleItemMutated(e.index,e.url,e.last_event_id,e.revision,e.data,e.date_updated,e.date_expires,!1,!0):i.cache.store(Number(e.index),new er({index:Number(e.index),uri:e.url,revision:e.revision,lastEventId:e.last_event_id,dateUpdated:e.date_updated,dateExpires:e.date_expires,data:e.data}),e.last_event_id),i.cache.get(e.index)}),a=n.body.meta,s.abrupt("return",new ea(r,function(e){return i.queryItems({pageToken:e})},a.previous_token,a.next_token));case 8:case"end":return s.stop()}},_callee11,this)})),function(e){return d.apply(this,arguments)})},{key:"getItems",value:(p=x.default(M.default.mark(function _callee12(e){return M.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return validatePageSize((e=e||{}).pageSize),e.limit=e.pageSize||e.limit||50,e.order=e.order||"asc",t.abrupt("return",this.queryItems(e));case 5:case"end":return t.stop()}},_callee12,this)})),function(e){return p.apply(this,arguments)})},{key:"getContext",value:(f=x.default(M.default.mark(function _callee13(){var e;return M.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.context){t.next=5;break}return t.next=3,this.services.network.get(this.links.context);case 3:e=t.sent,this._updateContextIfRequired(e.body.data,e.body.last_event_id);case 5:return t.abrupt("return",this.context);case 6:case"end":return t.stop()}},_callee13,this)})),function(){return f.apply(this,arguments)})},{key:"setTtl",value:(h=x.default(M.default.mark(function _callee14(e){var t,n;return M.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.prev=0,t={ttl:e},r.next=4,this.services.network.post(this.uri,t);case 4:n=r.sent,this.descriptor.date_expires=n.body.date_expires,r.next=12;break;case 8:throw r.prev=8,r.t0=r.catch(0),404===r.t0.status&&this.onRemoved(!1),r.t0;case 12:case"end":return r.stop()}},_callee14,this,[[0,8]])})),function(e){return h.apply(this,arguments)})},{key:"setItemTtl",value:(y=x.default(M.default.mark(function _callee15(e,t){var n,r,a;return M.default.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return i.next=2,this.get(e);case 2:return n=i.sent,r={ttl:t},i.next=6,this.services.network.post(n.uri,r);case 6:a=i.sent,n.updateDateExpires(a.body.date_expires);case 8:case"end":return i.stop()}},_callee15,this)})),function(e,t){return y.apply(this,arguments)})},{key:"removeList",value:(v=x.default(M.default.mark(function _callee16(){return M.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.network.delete(this.uri);case 2:this.onRemoved(!0);case 3:case"end":return e.stop()}},_callee16,this)})),function(){return v.apply(this,arguments)})},{key:"onRemoved",value:function(e){this._unsubscribe(),this.removalHandler(this.type,this.sid,this.uniqueName),this.broadcastEventToListeners("removed",{isLocal:e})}},{key:"shouldIgnoreEvent",value:function(e,t){return this.cache.isKnown(e,t)}},{key:"_update",value:function(e,t){var n=Number(e.item_index);switch(e.date_created=new Date(e.date_created),e.type){case"list_item_added":case"list_item_updated":this._handleItemMutated(n,e.item_url,e.id,e.item_revision,e.item_data,e.date_created,void 0,"list_item_added"===e.type,!0);break;case"list_item_removed":this._handleItemRemoved(n,e.id,e.item_data,e.date_created,!0);break;case"list_context_updated":this._handleContextUpdate(e.context_data,e.id,e.date_created);break;case"list_removed":this.onRemoved(!1)}t&&this._advanceLastEventId(e.id,e.list_revision)}},{key:"_advanceLastEventId",value:function(e,t){this.lastEventId<e&&(this.descriptor.last_event_id=e,t&&(this.descriptor.revision=t))}},{key:"_updateRootDateUpdated",value:function(e){(!this.descriptor.date_updated||e.getTime()>this.descriptor.date_updated.getTime())&&(this.descriptor.date_updated=e,this.services.storage.update(this.type,this.sid,this.uniqueName,{date_updated:e}))}},{key:"_handleItemMutated",value:function(e,t,n,r,a,i,s,u,o){if(this.shouldIgnoreEvent(e,n)){K.trace("Item ".concat(e," update skipped, current: ").concat(this.lastEventId,", remote: ").concat(n));return}this._updateRootDateUpdated(i);var c=this.cache.get(e);if(!c){var l=new er({index:e,uri:t,lastEventId:n,revision:r,data:a,dateUpdated:i,dateExpires:s});this.cache.store(e,l,n),this.emitItemMutationEvent(l,o,u);return}var d=deepClone(c.data);c.update(n,r,a,i),this.cache.store(e,c,n),void 0!==s&&c.updateDateExpires(s),this.emitItemMutationEvent(c,o,!1,d)}},{key:"emitItemMutationEvent",value:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,a={item:e,isLocal:!t};n||(a.previousItemData=r),this.broadcastEventToListeners(n?"itemAdded":"itemUpdated",a)}},{key:"_handleItemRemoved",value:function(e,t,n,r,a){this._updateRootDateUpdated(r),this.cache.delete(e,t),this.broadcastEventToListeners("itemRemoved",{index:e,isLocal:!a,previousItemData:n})}},{key:"_handleContextUpdate",value:function(e,t,n){this._updateRootDateUpdated(n),this._updateContextIfRequired(e,t)&&this.broadcastEventToListeners("contextUpdated",{context:e,isLocal:!1})}},{key:"_updateContextIfRequired",value:function(e,t){return!this.contextEventId||t>this.contextEventId?(this.context=e,this.contextEventId=t,!0):(K.trace("Context update skipped, current:",this.lastEventId,", remote:",t),!1)}}],[{key:"type",get:function(){return"list"}}]),SyncListImpl}(Z),ed=function(e){T.default(SyncList,e);var t,n,r,a,i,s,u,o,c,l,d,p=_createSuper$4(SyncList);function SyncList(e){var t;return S.default(this,SyncList),(t=p.call(this)).syncListImpl=e,t.syncListImpl.attach(L.default(t)),t}return E.default(SyncList,[{key:"uri",get:function(){return this.syncListImpl.uri}},{key:"revision",get:function(){return this.syncListImpl.revision}},{key:"lastEventId",get:function(){return this.syncListImpl.lastEventId}},{key:"links",get:function(){return this.syncListImpl.links}},{key:"dateExpires",get:function(){return this.syncListImpl.dateExpires}},{key:"type",get:function(){return el.type}},{key:"sid",get:function(){return this.syncListImpl.sid}},{key:"uniqueName",get:function(){return this.syncListImpl.uniqueName}},{key:"dateUpdated",get:function(){return this.syncListImpl.dateUpdated}},{key:"push",value:(t=x.default(M.default.mark(function _callee17(e,t){return M.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return this.ensureNotClosed(),n.abrupt("return",this.syncListImpl.push(e,t));case 2:case"end":return n.stop()}},_callee17,this)})),function(e,n){return t.apply(this,arguments)})},{key:"set",value:(n=x.default(M.default.mark(function _callee18(e,t,n){return M.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return this.ensureNotClosed(),r.abrupt("return",this.syncListImpl.set(e,t,n));case 2:case"end":return r.stop()}},_callee18,this)})),function(e,t,r){return n.apply(this,arguments)})},{key:"mutate",value:(r=x.default(M.default.mark(function _callee19(e,t,n){return M.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return this.ensureNotClosed(),r.abrupt("return",this.syncListImpl.mutate(e,t,n));case 2:case"end":return r.stop()}},_callee19,this)})),function(e,t,n){return r.apply(this,arguments)})},{key:"update",value:(a=x.default(M.default.mark(function _callee20(e,t,n){return M.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return this.ensureNotClosed(),r.abrupt("return",this.syncListImpl.update(e,t,n));case 2:case"end":return r.stop()}},_callee20,this)})),function(e,t,n){return a.apply(this,arguments)})},{key:"remove",value:(i=x.default(M.default.mark(function _callee21(e){return M.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return this.ensureNotClosed(),t.abrupt("return",this.syncListImpl.remove(e));case 2:case"end":return t.stop()}},_callee21,this)})),function(e){return i.apply(this,arguments)})},{key:"get",value:(s=x.default(M.default.mark(function _callee22(e){return M.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return this.ensureNotClosed(),t.abrupt("return",this.syncListImpl.get(e));case 2:case"end":return t.stop()}},_callee22,this)})),function(e){return s.apply(this,arguments)})},{key:"getContext",value:(u=x.default(M.default.mark(function _callee23(){return M.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.getContext());case 2:case"end":return e.stop()}},_callee23,this)})),function(){return u.apply(this,arguments)})},{key:"getItems",value:(o=x.default(M.default.mark(function _callee24(e){return M.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return this.ensureNotClosed(),t.abrupt("return",this.syncListImpl.getItems(e));case 2:case"end":return t.stop()}},_callee24,this)})),function(e){return o.apply(this,arguments)})},{key:"setTtl",value:(c=x.default(M.default.mark(function _callee25(e){return M.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return this.ensureNotClosed(),t.abrupt("return",this.syncListImpl.setTtl(e));case 2:case"end":return t.stop()}},_callee25,this)})),function(e){return c.apply(this,arguments)})},{key:"setItemTtl",value:(l=x.default(M.default.mark(function _callee26(e,t){return M.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return this.ensureNotClosed(),n.abrupt("return",this.syncListImpl.setItemTtl(e,t));case 2:case"end":return n.stop()}},_callee26,this)})),function(e,t){return l.apply(this,arguments)})},{key:"removeList",value:(d=x.default(M.default.mark(function _callee27(){return M.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncListImpl.removeList());case 2:case"end":return e.stop()}},_callee27,this)})),function(){return d.apply(this,arguments)})},{key:"close",value:function(){D.default(R.default(SyncList.prototype),"close",this).call(this),this.syncListImpl.detach(this.listenerUuid)}}],[{key:"type",get:function(){return el.type}}]),SyncList}(ee);N.default(ed,"itemAdded","itemAdded"),N.default(ed,"itemUpdated","itemUpdated"),N.default(ed,"itemRemoved","itemRemoved"),N.default(ed,"removed","removed"),__decorate([h.validateTypesAsync(h.pureObject,["undefined",h.objectSchema("item metadata",{ttl:[h.nonNegativeInteger,"undefined"]})]),__metadata("design:type",Function),__metadata("design:paramtypes",[Object,Object]),__metadata("design:returntype",Promise)],ed.prototype,"push",null),__decorate([h.validateTypesAsync(h.nonNegativeInteger,h.pureObject,["undefined",h.objectSchema("item metadata",{ttl:[h.nonNegativeInteger,"undefined"]})]),__metadata("design:type",Function),__metadata("design:paramtypes",[Number,Object,Object]),__metadata("design:returntype",Promise)],ed.prototype,"set",null),__decorate([h.validateTypesAsync(h.nonNegativeInteger,"function",["undefined",h.objectSchema("item metadata",{ttl:[h.nonNegativeInteger,"undefined"]})]),__metadata("design:type",Function),__metadata("design:paramtypes",[Number,Function,Object]),__metadata("design:returntype",Promise)],ed.prototype,"mutate",null),__decorate([h.validateTypesAsync(h.nonNegativeInteger,h.pureObject,["undefined",h.objectSchema("item metadata",{ttl:[h.nonNegativeInteger,"undefined"]})]),__metadata("design:type",Function),__metadata("design:paramtypes",[Number,Object,Object]),__metadata("design:returntype",Promise)],ed.prototype,"update",null),__decorate([h.validateTypesAsync(h.nonNegativeInteger),__metadata("design:type",Function),__metadata("design:paramtypes",[Number]),__metadata("design:returntype",Promise)],ed.prototype,"remove",null),__decorate([h.validateTypesAsync(h.nonNegativeInteger),__metadata("design:type",Function),__metadata("design:paramtypes",[Number]),__metadata("design:returntype",Promise)],ed.prototype,"get",null),__decorate([h.validateTypesAsync(["undefined",h.objectSchema("query options",{from:[h.nonNegativeInteger,"undefined"],pageSize:[h.custom(function(e){return[isPositiveInteger(e),"a positive integer"]}),"undefined"]})]),__metadata("design:type",Function),__metadata("design:paramtypes",[Object]),__metadata("design:returntype",Promise)],ed.prototype,"getItems",null),__decorate([h.validateTypesAsync(h.nonNegativeInteger),__metadata("design:type",Function),__metadata("design:paramtypes",[Number]),__metadata("design:returntype",Promise)],ed.prototype,"setTtl",null),__decorate([h.validateTypesAsync(h.nonNegativeInteger,h.nonNegativeInteger),__metadata("design:type",Function),__metadata("design:paramtypes",[Number,Number]),__metadata("design:returntype",Promise)],ed.prototype,"setItemTtl",null);var ep=function(){function SyncMapItem(e){S.default(this,SyncMapItem),this.descriptor=e}return E.default(SyncMapItem,[{key:"uri",get:function(){return this.descriptor.url}},{key:"revision",get:function(){return this.descriptor.revision}},{key:"lastEventId",get:function(){return this.descriptor.last_event_id}},{key:"dateExpires",get:function(){return this.descriptor.date_expires}},{key:"key",get:function(){return this.descriptor.key}},{key:"data",get:function(){return this.descriptor.data}},{key:"dateUpdated",get:function(){return this.descriptor.date_updated}},{key:"update",value:function(e,t,n,r){return this.descriptor.last_event_id=e,this.descriptor.revision=t,this.descriptor.data=n,this.descriptor.date_updated=r,this}},{key:"updateDateExpires",value:function(e){this.descriptor.date_expires=e}}]),SyncMapItem}();function _createSuper$3(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct||Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}();return function(){var n,r=R.default(e);if(t){var a=R.default(this).constructor;n=Reflect.construct(r,arguments,a)}else n=r.apply(this,arguments);return C.default(this,n)}}var ef=function(e){T.default(SyncMapImpl,e);var t,n,r,a,i,s,u,o,c,l,d,p,f,h,y=_createSuper$3(SyncMapImpl);function SyncMapImpl(e,t,n){var r;return S.default(this,SyncMapImpl),(r=y.call(this,e,n)).updateMergingQueue=new Y(function(e,t){return"number"==typeof t.ttl?{ttl:t.ttl}:e}),r.cache=new ec,r.descriptor=t,r.descriptor.date_updated=new Date(r.descriptor.date_updated),t.items&&t.items.forEach(function(e){e.date_updated=new Date(e.date_updated),r.cache.store(e.key,new ep(e),e.last_event_id)}),r}return E.default(SyncMapImpl,[{key:"uri",get:function(){return this.descriptor.url}},{key:"links",get:function(){return this.descriptor.links}},{key:"revision",get:function(){return this.descriptor.revision}},{key:"lastEventId",get:function(){return this.descriptor.last_event_id}},{key:"dateExpires",get:function(){return this.descriptor.date_expires}},{key:"type",get:function(){return"map"}},{key:"indexName",get:function(){}},{key:"queryString",get:function(){}},{key:"sid",get:function(){return this.descriptor.sid}},{key:"uniqueName",get:function(){return this.descriptor.unique_name||null}},{key:"dateUpdated",get:function(){return this.descriptor.date_updated}},{key:"set",value:(t=x.default(M.default.mark(function _callee(e,t,n){var r,a=this;return M.default.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return r=n||{},i.abrupt("return",this.updateMergingQueue.squashAndAdd(e,r,function(n){return a._putItemUnconditionally(e,t,n.ttl)}));case 2:case"end":return i.stop()}},_callee,this)})),function(e,n,r){return t.apply(this,arguments)})},{key:"get",value:(n=x.default(M.default.mark(function _callee2(e){return M.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(null!=e){t.next=2;break}throw new B("SyncMapItem key may not be empty",400,54209);case 2:if(!this.cache.has(e)){t.next=6;break}return t.abrupt("return",this.cache.get(e));case 6:return t.abrupt("return",this._getItemFromServer(e));case 7:case"end":return t.stop()}},_callee2,this)})),function(e){return n.apply(this,arguments)})},{key:"_getItemFromServer",value:(r=x.default(M.default.mark(function _callee3(e){var t;return M.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,this.queryItems({key:e});case 2:if(!((t=n.sent).items.length<1)){n.next=7;break}throw new B("The specified Map Item does not exist",404,54201);case 7:return n.abrupt("return",t.items[0]);case 8:case"end":return n.stop()}},_callee3,this)})),function(e){return r.apply(this,arguments)})},{key:"mutate",value:(a=x.default(M.default.mark(function _callee4(e,t,n){var r,a=this;return M.default.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return r=n||{},i.abrupt("return",this.updateMergingQueue.add(e,r,function(n){return a._putItemWithIfMatch(e,t,n.ttl)}));case 2:case"end":return i.stop()}},_callee4,this)})),function(e,t,n){return a.apply(this,arguments)})},{key:"update",value:(i=x.default(M.default.mark(function _callee5(e,t,n){return M.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",this.mutate(e,function(e){return Object.assign(e,t)},n));case 1:case"end":return r.stop()}},_callee5,this)})),function(e,t,n){return i.apply(this,arguments)})},{key:"_putItemUnconditionally",value:(s=x.default(M.default.mark(function _callee6(e,t,n){var r,a;return M.default.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return i.next=2,this._putItemToServer(e,t,void 0,n);case 2:return a=(r=i.sent).item,this._handleItemMutated(a.key,a.url,a.last_event_id,a.revision,a.data,a.date_updated,a.date_expires,r.added,!1),i.abrupt("return",this.cache.get(a.key));case 6:case"end":return i.stop()}},_callee6,this)})),function(e,t,n){return s.apply(this,arguments)})},{key:"_putItemWithIfMatch",value:(u=x.default(M.default.mark(function _callee7(e,t,n){var r,a,i,s,u;return M.default.wrap(function(o){for(;;)switch(o.prev=o.next){case 0:return o.next=2,this.get(e).catch(function(t){if(404===t.status)return new ep({key:e,data:{},last_event_id:-1,revision:"-1",url:null,date_updated:null,date_expires:null});throw t});case 2:if(!(a=t(deepClone((r=o.sent).data)))){o.next=26;break}return i=r.revision,o.prev=6,o.next=9,this._putItemToServer(e,a,i,n);case 9:return u=(s=o.sent).item,this._handleItemMutated(u.key,u.url,u.last_event_id,u.revision,u.data,u.date_updated,u.date_expires,s.added,!1),o.abrupt("return",this.cache.get(u.key));case 15:if(o.prev=15,o.t0=o.catch(6),412!==o.t0.status){o.next=23;break}return o.next=20,this._getItemFromServer(e);case 20:return o.abrupt("return",this._putItemWithIfMatch(e,t,n));case 23:throw o.t0;case 24:o.next=27;break;case 26:return o.abrupt("return",r);case 27:case"end":return o.stop()}},_callee7,this,[[6,15]])})),function(e,t,n){return u.apply(this,arguments)})},{key:"_putItemToServer",value:(o=x.default(M.default.mark(function _callee8(e,t,n,r){var a,i,s,u,o;return M.default.wrap(function(c){for(;;)switch(c.prev=c.next){case 0:return a=new Q(this.links.items).pathSegment(e).build(),i={data:t},void 0!==r&&(i.ttl=r),c.prev=3,c.next=6,this.services.network.put(a,i,n);case 6:return(u=(s=c.sent).body).data=t,u.date_updated=new Date(u.date_updated),o=201===s.status.code,c.abrupt("return",{added:o,item:u});case 14:throw c.prev=14,c.t0=c.catch(3),404===c.t0.status&&this.onRemoved(!1),c.t0;case 18:case"end":return c.stop()}},_callee8,this,[[3,14]])})),function(e,t,n,r){return o.apply(this,arguments)})},{key:"remove",value:(c=x.default(M.default.mark(function _callee9(e){var t,n,r;return M.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.next=2,this.get(e);case 2:return n=deepClone((t=a.sent).data),a.next=6,this.services.network.delete(t.uri);case 6:r=a.sent,this._handleItemRemoved(e,r.body.last_event_id,n,new Date(r.body.date_updated),!1);case 8:case"end":return a.stop()}},_callee9,this)})),function(e){return c.apply(this,arguments)})},{key:"queryItems",value:(l=x.default(M.default.mark(function _callee10(e){var t,n,r,a,i=this;return M.default.wrap(function(s){for(;;)switch(s.prev=s.next){case 0:return e=e||{},t=new Q(this.links.items).queryParam("From",e.from).queryParam("PageSize",e.limit).queryParam("Key",e.key).queryParam("PageToken",e.pageToken).queryParam("Order",e.order).build(),s.next=4,this.services.network.get(t);case 4:return r=(n=s.sent).body.items.map(function(e){return e.date_updated=new Date(e.date_updated),i.cache.get(e.key)?i._handleItemMutated(e.key,e.url,e.last_event_id,e.revision,e.data,e.date_updated,e.date_expires,!1,!0):i.cache.store(e.key,new ep(e),e.last_event_id),i.cache.get(e.key)}),a=n.body.meta,s.abrupt("return",new ea(r,function(e){return i.queryItems({pageToken:e})},a.previous_token,a.next_token));case 8:case"end":return s.stop()}},_callee10,this)})),function(e){return l.apply(this,arguments)})},{key:"getItems",value:(d=x.default(M.default.mark(function _callee11(e){return M.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return validatePageSize((e=e||{}).pageSize),e.limit=e.pageSize||e.limit||50,e.order=e.order||"asc",t.abrupt("return",this.queryItems(e));case 5:case"end":return t.stop()}},_callee11,this)})),function(e){return d.apply(this,arguments)})},{key:"shouldIgnoreEvent",value:function(e,t){return this.cache.isKnown(e,t)}},{key:"_update",value:function(e,t){switch(e.date_created=new Date(e.date_created),e.type){case"map_item_added":case"map_item_updated":this._handleItemMutated(e.item_key,e.item_url,e.id,e.item_revision,e.item_data,e.date_created,void 0,"map_item_added"===e.type,!0);break;case"map_item_removed":this._handleItemRemoved(e.item_key,e.id,e.item_data,e.date_created,!0);break;case"map_removed":this.onRemoved(!1)}t&&this._advanceLastEventId(e.id,e.map_revision)}},{key:"_advanceLastEventId",value:function(e,t){this.lastEventId<e&&(this.descriptor.last_event_id=e,t&&(this.descriptor.revision=t))}},{key:"_updateRootDateUpdated",value:function(e){(!this.descriptor.date_updated||e.getTime()>this.descriptor.date_updated.getTime())&&(this.descriptor.date_updated=e,this.services.storage.update(this.type,this.sid,this.uniqueName,{date_updated:e}))}},{key:"_handleItemMutated",value:function(e,t,n,r,a,i,s,u,o){if(this.shouldIgnoreEvent(e,n)){K.trace("SyncMapItem ",e," update skipped, current:",this.lastEventId,", remote:",n);return}this._updateRootDateUpdated(i);var c=this.cache.get(e);if(!c){var l=new ep({key:e,url:t,last_event_id:n,revision:r,data:a,date_updated:i,date_expires:s});this.cache.store(e,l,n),this.emitItemMutationEvent(l,o,u);return}var d=deepClone(c.data);c.update(n,r,a,i),this.cache.store(e,c,n),void 0!==s&&c.updateDateExpires(s),this.emitItemMutationEvent(c,o,!1,d)}},{key:"emitItemMutationEvent",value:function(e,t,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,a={item:e,isLocal:!t};n||(a.previousItemData=r),this.broadcastEventToListeners(n?"itemAdded":"itemUpdated",a)}},{key:"_handleItemRemoved",value:function(e,t,n,r,a){this._updateRootDateUpdated(r),this.cache.delete(e,t),this.broadcastEventToListeners("itemRemoved",{key:e,isLocal:!a,previousItemData:n})}},{key:"onRemoved",value:function(e){this._unsubscribe(),this.removalHandler(this.type,this.sid,this.uniqueName),this.broadcastEventToListeners("removed",{isLocal:e})}},{key:"setTtl",value:(p=x.default(M.default.mark(function _callee12(e){var t,n;return M.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.prev=0,t={ttl:e},r.next=4,this.services.network.post(this.uri,t);case 4:n=r.sent,this.descriptor.date_expires=n.body.date_expires,r.next=12;break;case 8:throw r.prev=8,r.t0=r.catch(0),404===r.t0.status&&this.onRemoved(!1),r.t0;case 12:case"end":return r.stop()}},_callee12,this,[[0,8]])})),function(e){return p.apply(this,arguments)})},{key:"setItemTtl",value:(f=x.default(M.default.mark(function _callee13(e,t){var n,r,a;return M.default.wrap(function(i){for(;;)switch(i.prev=i.next){case 0:return i.next=2,this.get(e);case 2:return n=i.sent,r={ttl:t},i.next=6,this.services.network.post(n.uri,r);case 6:a=i.sent,n.updateDateExpires(a.body.date_expires);case 8:case"end":return i.stop()}},_callee13,this)})),function(e,t){return f.apply(this,arguments)})},{key:"removeMap",value:(h=x.default(M.default.mark(function _callee14(){return M.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.network.delete(this.uri);case 2:this.onRemoved(!0);case 3:case"end":return e.stop()}},_callee14,this)})),function(){return h.apply(this,arguments)})}],[{key:"type",get:function(){return"map"}}]),SyncMapImpl}(Z),eh=function(e){T.default(SyncMap,e);var t,n,r,a,i,s,u,o,c,l=_createSuper$3(SyncMap);function SyncMap(e){var t;return S.default(this,SyncMap),(t=l.call(this)).syncMapImpl=e,t.syncMapImpl.attach(L.default(t)),t}return E.default(SyncMap,[{key:"uri",get:function(){return this.syncMapImpl.uri}},{key:"links",get:function(){return this.syncMapImpl.links}},{key:"revision",get:function(){return this.syncMapImpl.revision}},{key:"lastEventId",get:function(){return this.syncMapImpl.lastEventId}},{key:"dateExpires",get:function(){return this.syncMapImpl.dateExpires}},{key:"type",get:function(){return ef.type}},{key:"sid",get:function(){return this.syncMapImpl.sid}},{key:"uniqueName",get:function(){return this.syncMapImpl.uniqueName}},{key:"dateUpdated",get:function(){return this.syncMapImpl.dateUpdated}},{key:"set",value:(t=x.default(M.default.mark(function _callee15(e,t,n){return M.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return this.ensureNotClosed(),r.abrupt("return",this.syncMapImpl.set(e,t,n));case 2:case"end":return r.stop()}},_callee15,this)})),function(e,n,r){return t.apply(this,arguments)})},{key:"get",value:(n=x.default(M.default.mark(function _callee16(e){return M.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return this.ensureNotClosed(),t.abrupt("return",this.syncMapImpl.get(e));case 2:case"end":return t.stop()}},_callee16,this)})),function(e){return n.apply(this,arguments)})},{key:"mutate",value:(r=x.default(M.default.mark(function _callee17(e,t,n){return M.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return this.ensureNotClosed(),r.abrupt("return",this.syncMapImpl.mutate(e,t,n));case 2:case"end":return r.stop()}},_callee17,this)})),function(e,t,n){return r.apply(this,arguments)})},{key:"update",value:(a=x.default(M.default.mark(function _callee18(e,t,n){return M.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return this.ensureNotClosed(),r.abrupt("return",this.syncMapImpl.update(e,t,n));case 2:case"end":return r.stop()}},_callee18,this)})),function(e,t,n){return a.apply(this,arguments)})},{key:"remove",value:(i=x.default(M.default.mark(function _callee19(e){return M.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return this.ensureNotClosed(),t.abrupt("return",this.syncMapImpl.remove(e));case 2:case"end":return t.stop()}},_callee19,this)})),function(e){return i.apply(this,arguments)})},{key:"getItems",value:(s=x.default(M.default.mark(function _callee20(e){return M.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return this.ensureNotClosed(),t.abrupt("return",this.syncMapImpl.getItems(e));case 2:case"end":return t.stop()}},_callee20,this)})),function(e){return s.apply(this,arguments)})},{key:"setTtl",value:(u=x.default(M.default.mark(function _callee21(e){return M.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return this.ensureNotClosed(),t.abrupt("return",this.syncMapImpl.setTtl(e));case 2:case"end":return t.stop()}},_callee21,this)})),function(e){return u.apply(this,arguments)})},{key:"setItemTtl",value:(o=x.default(M.default.mark(function _callee22(e,t){return M.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return this.ensureNotClosed(),n.abrupt("return",this.syncMapImpl.setItemTtl(e,t));case 2:case"end":return n.stop()}},_callee22,this)})),function(e,t){return o.apply(this,arguments)})},{key:"removeMap",value:(c=x.default(M.default.mark(function _callee23(){return M.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.next=3,this.syncMapImpl.removeMap();case 3:case"end":return e.stop()}},_callee23,this)})),function(){return c.apply(this,arguments)})},{key:"close",value:function(){D.default(R.default(SyncMap.prototype),"close",this).call(this),this.syncMapImpl.detach(this.listenerUuid)}}],[{key:"type",get:function(){return ef.type}}]),SyncMap}(ee);function _createSuper$2(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct||Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}();return function(){var n,r=R.default(e);if(t){var a=R.default(this).constructor;n=Reflect.construct(r,arguments,a)}else n=r.apply(this,arguments);return C.default(this,n)}}N.default(eh,"itemAdded","itemAdded"),N.default(eh,"itemUpdated","itemUpdated"),N.default(eh,"itemRemoved","itemRemoved"),N.default(eh,"removed","removed"),__decorate([h.validateTypesAsync("string",h.pureObject,["undefined",h.objectSchema("item metadata",{ttl:[h.nonNegativeInteger,"undefined"]})]),__metadata("design:type",Function),__metadata("design:paramtypes",[String,Object,Object]),__metadata("design:returntype",Promise)],eh.prototype,"set",null),__decorate([h.validateTypesAsync("string"),__metadata("design:type",Function),__metadata("design:paramtypes",[String]),__metadata("design:returntype",Promise)],eh.prototype,"get",null),__decorate([h.validateTypesAsync("string","function",["undefined",h.objectSchema("item metadata",{ttl:[h.nonNegativeInteger,"undefined"]})]),__metadata("design:type",Function),__metadata("design:paramtypes",[String,Function,Object]),__metadata("design:returntype",Promise)],eh.prototype,"mutate",null),__decorate([h.validateTypesAsync("string",h.pureObject,["undefined",h.objectSchema("item metadata",{ttl:[h.nonNegativeInteger,"undefined"]})]),__metadata("design:type",Function),__metadata("design:paramtypes",[String,Object,Object]),__metadata("design:returntype",Promise)],eh.prototype,"update",null),__decorate([h.validateTypesAsync("string"),__metadata("design:type",Function),__metadata("design:paramtypes",[String]),__metadata("design:returntype",Promise)],eh.prototype,"remove",null),__decorate([h.validateTypesAsync(["undefined",h.objectSchema("query options",{from:["string","undefined"],pageSize:[h.custom(function(e){return[isPositiveInteger(e),"a positive integer"]}),"undefined"]})]),__metadata("design:type",Function),__metadata("design:paramtypes",[Object]),__metadata("design:returntype",Promise)],eh.prototype,"getItems",null),__decorate([h.validateTypesAsync(h.nonNegativeInteger),__metadata("design:type",Function),__metadata("design:paramtypes",[Number]),__metadata("design:returntype",Promise)],eh.prototype,"setTtl",null),__decorate([h.validateTypesAsync("string",h.nonNegativeInteger),__metadata("design:type",Function),__metadata("design:paramtypes",[String,Number]),__metadata("design:returntype",Promise)],eh.prototype,"setItemTtl",null);var ey=function(e){T.default(SyncStreamImpl,e);var t,n,r,a=_createSuper$2(SyncStreamImpl);function SyncStreamImpl(e,t,n){var r;return S.default(this,SyncStreamImpl),(r=a.call(this,e,n)).descriptor=t,r}return E.default(SyncStreamImpl,[{key:"uri",get:function(){return this.descriptor.url}},{key:"links",get:function(){return this.descriptor.links}},{key:"dateExpires",get:function(){return this.descriptor.date_expires}},{key:"type",get:function(){return"stream"}},{key:"lastEventId",get:function(){return null}},{key:"indexName",get:function(){}},{key:"queryString",get:function(){}},{key:"sid",get:function(){return this.descriptor.sid}},{key:"uniqueName",get:function(){return this.descriptor.unique_name||null}},{key:"publishMessage",value:(t=x.default(M.default.mark(function _callee(e){var t,n,r;return M.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return t={data:e},a.next=3,this.services.network.post(this.links.messages,t);case 3:return n=a.sent.body,r=this._handleMessagePublished(n.sid,e,!1),a.abrupt("return",r);case 7:case"end":return a.stop()}},_callee,this)})),function(e){return t.apply(this,arguments)})},{key:"setTtl",value:(n=x.default(M.default.mark(function _callee2(e){var t,n;return M.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.prev=0,t={ttl:e},r.next=4,this.services.network.post(this.uri,t);case 4:n=r.sent,this.descriptor.date_expires=n.body.date_expires,r.next=12;break;case 8:throw r.prev=8,r.t0=r.catch(0),404===r.t0.status&&this.onRemoved(!1),r.t0;case 12:case"end":return r.stop()}},_callee2,this,[[0,8]])})),function(e){return n.apply(this,arguments)})},{key:"removeStream",value:(r=x.default(M.default.mark(function _callee3(){return M.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.network.delete(this.uri);case 2:this.onRemoved(!0);case 3:case"end":return e.stop()}},_callee3,this)})),function(){return r.apply(this,arguments)})},{key:"_update",value:function(e){switch(e.type){case"stream_message_published":this._handleMessagePublished(e.message_sid,e.message_data,!0);break;case"stream_removed":this.onRemoved(!1)}}},{key:"_handleMessagePublished",value:function(e,t,n){var r={sid:e,data:t};return this.broadcastEventToListeners("messagePublished",{message:r,isLocal:!n}),r}},{key:"onRemoved",value:function(e){this._unsubscribe(),this.removalHandler(this.type,this.sid,this.uniqueName),this.broadcastEventToListeners("removed",{isLocal:e})}}],[{key:"type",get:function(){return"stream"}}]),SyncStreamImpl}(Z);__decorate([h.validateTypesAsync(h.pureObject),__metadata("design:type",Function),__metadata("design:paramtypes",[Object]),__metadata("design:returntype",Promise)],ey.prototype,"publishMessage",null),__decorate([h.validateTypesAsync(h.nonNegativeInteger),__metadata("design:type",Function),__metadata("design:paramtypes",[Number]),__metadata("design:returntype",Promise)],ey.prototype,"setTtl",null);var ev=function(e){T.default(SyncStream,e);var t,n,r,a=_createSuper$2(SyncStream);function SyncStream(e){var t;return S.default(this,SyncStream),(t=a.call(this)).syncStreamImpl=e,t.syncStreamImpl.attach(L.default(t)),t}return E.default(SyncStream,[{key:"uri",get:function(){return this.syncStreamImpl.uri}},{key:"links",get:function(){return this.syncStreamImpl.links}},{key:"dateExpires",get:function(){return this.syncStreamImpl.dateExpires}},{key:"type",get:function(){return ey.type}},{key:"lastEventId",get:function(){return null}},{key:"sid",get:function(){return this.syncStreamImpl.sid}},{key:"uniqueName",get:function(){return this.syncStreamImpl.uniqueName}},{key:"publishMessage",value:(t=x.default(M.default.mark(function _callee4(e){return M.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return this.ensureNotClosed(),t.abrupt("return",this.syncStreamImpl.publishMessage(e));case 2:case"end":return t.stop()}},_callee4,this)})),function(e){return t.apply(this,arguments)})},{key:"setTtl",value:(n=x.default(M.default.mark(function _callee5(e){return M.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return this.ensureNotClosed(),t.abrupt("return",this.syncStreamImpl.setTtl(e));case 2:case"end":return t.stop()}},_callee5,this)})),function(e){return n.apply(this,arguments)})},{key:"removeStream",value:(r=x.default(M.default.mark(function _callee6(){return M.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.ensureNotClosed(),e.abrupt("return",this.syncStreamImpl.removeStream());case 2:case"end":return e.stop()}},_callee6,this)})),function(){return r.apply(this,arguments)})},{key:"close",value:function(){D.default(R.default(SyncStream.prototype),"close",this).call(this),this.syncStreamImpl.detach(this.listenerUuid)}}],[{key:"type",get:function(){return ey.type}}]),SyncStream}(ee);N.default(ev,"messagePublished","messagePublished"),N.default(ev,"removed","removed"),__decorate([h.validateTypesAsync(h.pureObject),__metadata("design:type",Function),__metadata("design:paramtypes",[Object]),__metadata("design:returntype",Promise)],ev.prototype,"publishMessage",null),__decorate([h.validateTypesAsync(h.nonNegativeInteger),__metadata("design:type",Function),__metadata("design:paramtypes",[Number]),__metadata("design:returntype",Promise)],ev.prototype,"setTtl",null);var ClientInfo=function ClientInfo(e){S.default(this,ClientInfo),this.sdk="js",this.sdkVer=e,this.os=U.os.family,this.osVer=U.os.version,this.pl=U.name,this.plVer=U.version},em=function(){function EntitiesCache(){S.default(this,EntitiesCache),this.names=new Map,this.entities=new Map}return E.default(EntitiesCache,[{key:"store",value:function(e){return this.entities.get(e.sid)||(this.entities.set(e.sid,e),e.uniqueName&&this.names.set(e.type+"::"+e.uniqueName,e.sid),e)}},{key:"getResolved",value:function(e,t){var n=this.names.get(t+"::"+e);return n?this.entities.get(n):null}},{key:"get",value:function(e,t){return this.entities.get(e)||this.getResolved(e,t)||null}},{key:"remove",value:function(e){var t=this.entities.get(e);t&&(this.entities.delete(e),t.uniqueName&&this.names.delete(t.type+"::"+t.uniqueName))}}]),EntitiesCache}();function _createSuper$1(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct||Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}();return function(){var n,r=R.default(e);if(t){var a=R.default(this).constructor;n=Reflect.construct(r,arguments,a)}else n=r.apply(this,arguments);return C.default(this,n)}}var e_=function(e){T.default(LiveQueryImpl,e);var t=_createSuper$1(LiveQueryImpl);function LiveQueryImpl(e,n,r,a){var i;return S.default(this,LiveQueryImpl),(i=t.call(this,n,r)).descriptor=e,i.cache=new ec,a&&a.forEach(function(e){i.cache.store(e.key,{key:e.key,value:e.data},e.revision)}),i}return E.default(LiveQueryImpl,[{key:"sid",get:function(){return this.descriptor.sid}},{key:"uniqueName",get:function(){return null}},{key:"type",get:function(){return LiveQueryImpl.type}},{key:"lastEventId",get:function(){return this.descriptor.last_event_id}},{key:"indexName",get:function(){return this.descriptor.indexName}},{key:"queryString",get:function(){return this.descriptor.queryExpression}},{key:"queryUri",get:function(){return this.descriptor.queryUri}},{key:"liveQueryDescriptor",get:function(){return this.descriptor}},{key:"onRemoved",value:function(){}},{key:"getItems",value:function(){var e={};return this.cache.forEach(function(t,n){e[t]=n.value}),e}},{key:"_update",value:function(e,t){switch(e.type){case"live_query_item_updated":this.handleItemMutated(e.item_key,e.item_data,e.item_revision);break;case"live_query_item_removed":this.handleItemRemoved(e.item_key,e.item_revision);break;case"live_query_updated":this.handleBatchUpdate(e.items)}t&&this._advanceLastEventId(e.last_event_id)}},{key:"handleItemMutated",value:function(e,t,n){if(this.shouldIgnoreEvent(e,n))K.trace("Item ".concat(e," update skipped, revision: ").concat(n));else{var r={key:e,value:t};this.cache.store(e,r,n),this.broadcastEventToListeners("itemUpdated",r)}}},{key:"handleItemRemoved",value:function(e,t){var n=null===t;this.shouldIgnoreEvent(e,t)?K.trace("Item ".concat(e," delete skipped, revision: ").concat(t)):(this.cache.delete(e,t,n),this.broadcastEventToListeners("itemRemoved",{key:e}))}},{key:"handleBatchUpdate",value:function(e){var t=this,n={};for(var r in null!=e&&e.forEach(function(e){n[e.key]={data:e.data,revision:e.revision}}),this.cache.forEach(function(e,r){var a=n[e];null!=a?t.handleItemMutated(e,a.data,a.revision):t.handleItemRemoved(e,null),delete n[e]}),n)this.handleItemMutated(r,n[r].data,n[r].revision)}},{key:"shouldIgnoreEvent",value:function(e,t){return null!=e&&null!=t&&this.cache.isKnown(e,t)}},{key:"_advanceLastEventId",value:function(e,t){this.lastEventId<e&&(this.descriptor.last_event_id=e)}}],[{key:"type",get:function(){return"live_query"}}]),LiveQueryImpl}(Z);function queryItems(e){return _queryItems.apply(this,arguments)}function _queryItems(){return(_queryItems=x.default(M.default.mark(function _callee3(e){var t,n,r,a,i,s;return M.default.wrap(function(u){for(;;)switch(u.prev=u.next){case 0:if(t=e.network,n=e.queryString,r=e.uri,a=e.type,null!=n){u.next=3;break}throw new B("Invalid query",400,54507);case 3:return i={query_string:n},a===eg.type&&(i.type=a),u.next=7,t.post(r,i,void 0,!0);case 7:return s=u.sent,u.abrupt("return",s.body);case 9:case"end":return u.stop()}},_callee3)}))).apply(this,arguments)}var eg=function(e){T.default(LiveQuery,e);var t=_createSuper$1(LiveQuery);function LiveQuery(e){var n;return S.default(this,LiveQuery),(n=t.call(this)).liveQueryImpl=e,n.liveQueryImpl.attach(L.default(n)),n}return E.default(LiveQuery,[{key:"type",get:function(){return e_.type}},{key:"lastEventId",get:function(){return this.liveQueryImpl.lastEventId}},{key:"sid",get:function(){return this.liveQueryImpl.sid}},{key:"close",value:function(){D.default(R.default(LiveQuery.prototype),"close",this).call(this),this.liveQueryImpl.detach(this.listenerUuid)}},{key:"getItems",value:function(){return this.ensureNotClosed(),this.liveQueryImpl.getItems()}}],[{key:"type",get:function(){return e_.type}}]),LiveQuery}(ee);N.default(eg,"itemUpdated","itemUpdated"),N.default(eg,"itemRemoved","itemRemoved");var ek=function(e){T.default(InstantQuery,e);var t,n,r=_createSuper$1(InstantQuery);function InstantQuery(e){var t;return S.default(this,InstantQuery),t=r.call(this),N.default(L.default(t),"queryExpression",null),N.default(L.default(t),"items",{}),Object.assign(L.default(t),e),t.updateIndexName(e.indexName),t}return E.default(InstantQuery,[{key:"type",get:function(){return InstantQuery.type}},{key:"search",value:(t=x.default(M.default.mark(function _callee(e){var t=this;return M.default.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return this.items={},n.abrupt("return",queryItems({network:this.network,uri:this.queryUri,queryString:e}).then(function(n){t.queryExpression=e,n.items&&n.items.forEach(function(e){t.items[e.key]=e.data}),t.emit("searchResult",t.getItems())}).catch(function(n){throw K.error("Error '".concat(n.message,"' while executing query '").concat(e,"'")),t.queryExpression=null,n}));case 2:case"end":return n.stop()}},_callee,this)})),function(e){return t.apply(this,arguments)})},{key:"subscribe",value:(n=x.default(M.default.mark(function _callee2(){return M.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=this.queryExpression){e.next=2;break}return e.abrupt("return",Promise.reject(new B("Invalid query",400,54507)));case 2:return e.abrupt("return",this.liveQueryCreator(this.indexName,this.queryExpression));case 3:case"end":return e.stop()}},_callee2,this)})),function(){return n.apply(this,arguments)})},{key:"getItems",value:function(){return this.items}},{key:"updateIndexName",value:function(e){this.indexName=e,this.queryUri=this.generateQueryUri(this.indexName)}},{key:"generateQueryUri",value:function(e){return new Q(this.insightsUri).pathSegment(e).pathSegment("Items").build()}}],[{key:"type",get:function(){return"instant_query"}}]),InstantQuery}(EventEmitter);function ownKeys(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(n),!0).forEach(function(t){N.default(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ownKeys(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}N.default(ek,"searchResult","searchResult"),__decorate([h.validateTypesAsync("string"),__metadata("design:type",Function),__metadata("design:paramtypes",[String]),__metadata("design:returntype",Promise)],ek.prototype,"search",null),__decorate([h.validateTypes(h.nonEmptyString),__metadata("design:type",Function),__metadata("design:paramtypes",[String]),__metadata("design:returntype",void 0)],ek.prototype,"updateIndexName",null);var eb="3.1.0";function decompose(e){if(!e)return{mode:"create_new"};if("string"==typeof e)return{id:e,mode:"open_or_create"};var t=e.mode||(e.id?"open_or_create":"create_new");return _objectSpread(_objectSpread({},e),{},{mode:t})}var ew="com.twilio.rtd.cds.document",eI="com.twilio.rtd.cds.list",ex="com.twilio.rtd.cds.map",eS="twilio.sync.event",eE=function(e){T.default(Client,e);var t,n,r,a,i,s,u,o,c,l,d,p,f,h,v,m,_=(t=function(){if("undefined"==typeof Reflect||!Reflect.construct||Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}(),function(){var e,n=R.default(Client);if(t){var r=R.default(this).constructor;e=Reflect.construct(n,arguments,r)}else e=n.apply(this,arguments);return C.default(this,e)});function Client(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(S.default(this,Client),t=_.call(this),!e)throw Error("Sync library needs a valid Twilio token to be passed");n.hasOwnProperty("logLevel")?K.setLevel(n.logLevel):K.setLevel("silent");var r=n.productId=n.productId||"data_sync";n.clientMetadata=n.clientMetadata||{},n.clientMetadata.hasOwnProperty("type")||(n.clientMetadata.type="sync"),n.clientMetadata.hasOwnProperty("sdk")||(n.clientMetadata.sdk="JS",n.clientMetadata.sdkv=eb);var a=!n.twilsockClient;if(!n.initRegistrations){var i=new y.InitRegistration(r);Client.populateInitRegistrations(i),n.initRegistrations=[i]}var s=n.twilsockClient=n.twilsockClient||new y.Twilsock(e,r,n);s.on("tokenAboutToExpire",function(e){return t.emit("tokenAboutToExpire",e)}),s.on("tokenExpired",function(){return t.emit("tokenExpired")}),s.on("connectionError",function(e){return t.emit("connectionError",e)}),s.on("stateChanged",function(e){t.emit("connectionStateChanged",e),t.services.subscriptions.onConnectionStateChanged("connected"===e)}),s.on("message",function(e,n){return t._routeMessage(e,n)});var u=new W(n),o=new J(new ClientInfo(eb),u,s),c=new G(u);return t.services={config:u,twilsock:s,network:o,storage:c,router:L.default(t),subscriptions:null},t.services.subscriptions=new V(t.services),t.entities=new em,a&&s.connect(),t}return E.default(Client,[{key:"_routeMessage",value:function(e,t){switch(K.trace("Notification type:",e,"content:",t),e){case ew:case eI:case ex:this.services.subscriptions.acceptMessage(t,!1);break;case eS:this.services.subscriptions.acceptMessage(t,!0)}}},{key:"_subscribe",value:function(e,t){this.services.subscriptions.add(e,t)}},{key:"_unsubscribe",value:function(e){this.services.subscriptions.remove(e)}},{key:"connectionState",get:function(){return this.services.twilsock.state}},{key:"ensureReady",value:(n=x.default(M.default.mark(function _callee(){var e;return M.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.services.config.sessionStorageEnabled){t.next=2;break}return t.abrupt("return");case 2:return t.prev=2,t.next=5,this.services.twilsock.storageId();case 5:e=t.sent,this.services.storage.updateStorageId(e.id),t.next=12;break;case 9:t.prev=9,t.t0=t.catch(2),K.warn("Failed to initialize storage",t.t0);case 12:case"end":return t.stop()}},_callee,this,[[2,9]])})),function(){return n.apply(this,arguments)})},{key:"storeRootInSessionCache",value:function(e,t,n){if(this.services.config.sessionStorageEnabled&&t){var r=deepClone(n);(e===ed.type||e===eh.type)&&(r.last_event_id=null,delete r.items),this.services.storage.store(e,t,r)}}},{key:"readRootFromSessionCache",value:function(e,t){return this.services.config.sessionStorageEnabled&&t?this.services.storage.read(e,t):null}},{key:"_get",value:(r=x.default(M.default.mark(function _callee2(e,t){var n,r,a,i=arguments;return M.default.wrap(function(s){for(;;)switch(s.prev=s.next){case 0:if(n=i.length>2&&void 0!==i[2]&&i[2],t){s.next=3;break}throw new B("Cannot get entity without id",404);case 3:return r=new Q(e).pathSegment(t).queryParam("Include",n?"items":void 0).build(),s.next=6,this.services.network.get(r);case 6:return a=s.sent,s.abrupt("return",a.body);case 8:case"end":return s.stop()}},_callee2,this)})),function(e,t){return r.apply(this,arguments)})},{key:"_createDocument",value:function(e,t,n){var r={unique_name:e,data:t||{}};return void 0!==n&&(r.ttl=n),this.services.network.post(this.services.config.documentsUri,r).then(function(e){return e.body.data=r.data,e.body})}},{key:"_getDocument",value:(a=x.default(M.default.mark(function _callee3(e){return M.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.readRootFromSessionCache(en.type,e)||this._get(this.services.config.documentsUri,e));case 1:case"end":return t.stop()}},_callee3,this)})),function(e){return a.apply(this,arguments)})},{key:"_createList",value:function(e,t,n,r){var a={unique_name:e,purpose:t,context:n};return void 0!==r&&(a.ttl=r),this.services.network.post(this.services.config.listsUri,a).then(function(e){return e.body})}},{key:"_getList",value:(i=x.default(M.default.mark(function _callee4(e){return M.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.readRootFromSessionCache(ed.type,e)||this._get(this.services.config.listsUri,e));case 1:case"end":return t.stop()}},_callee4,this)})),function(e){return i.apply(this,arguments)})},{key:"_createMap",value:function(e,t){var n={unique_name:e};return void 0!==t&&(n.ttl=t),this.services.network.post(this.services.config.mapsUri,n).then(function(e){return e.body})}},{key:"_getMap",value:(s=x.default(M.default.mark(function _callee5(e){var t,n=arguments;return M.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return t=n.length>1&&void 0!==n[1]&&n[1],r.abrupt("return",this.readRootFromSessionCache(eh.type,e)||this._get(this.services.config.mapsUri,e,t));case 2:case"end":return r.stop()}},_callee5,this)})),function(e){return s.apply(this,arguments)})},{key:"_getStream",value:(u=x.default(M.default.mark(function _callee6(e){return M.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.readRootFromSessionCache(ev.type,e)||this._get(this.services.config.streamsUri,e,!1));case 1:case"end":return t.stop()}},_callee6,this)})),function(e){return u.apply(this,arguments)})},{key:"_createStream",value:(o=x.default(M.default.mark(function _callee7(e,t){var n,r;return M.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return n={unique_name:e},void 0!==t&&(n.ttl=t),a.next=4,this.services.network.post(this.services.config.streamsUri,n);case 4:return r=a.sent,a.abrupt("return",r.body);case 6:case"end":return a.stop()}},_callee7,this)})),function(e,t){return o.apply(this,arguments)})},{key:"_getLiveQuery",value:function(e){return this.readRootFromSessionCache(eg.type,e)}},{key:"getCached",value:function(e,t){return e&&this.entities.get(e,t)||null}},{key:"removeFromCacheAndSession",value:function(e,t,n){this.entities.remove(t),this.services.config.sessionStorageEnabled&&this.services.storage.remove(e,t,n)}},{key:"document",value:(c=x.default(M.default.mark(function _callee8(e){var t,n,r,a,i=this;return M.default.wrap(function(s){for(;;)switch(s.prev=s.next){case 0:return s.next=2,this.ensureReady();case 2:if("create_new"!==(t=decompose(e)).mode){s.next=9;break}return s.next=6,this._createDocument(t.id,t.data,t.ttl);case 6:case 17:case 29:n=s.sent,s.next=39;break;case 9:if(!(r=this.getCached(t.id,en.type))){s.next=14;break}return s.abrupt("return",new en(r));case 14:return s.prev=14,s.next=17,this._getDocument(t.id);case 20:if(s.prev=20,s.t0=s.catch(14),!(404!==s.t0.status||"open_existing"===t.mode)){s.next=26;break}throw s.t0;case 26:return s.prev=26,s.next=29,this._createDocument(t.id,t.data,t.ttl);case 32:if(s.prev=32,s.t1=s.catch(26),409!==s.t1.status){s.next=38;break}return s.abrupt("return",this.document(e));case 38:throw s.t1;case 39:return this.storeRootInSessionCache(en.type,t.id,n),a=new et(this.services,n,function(e,t,n){return i.removeFromCacheAndSession(e,t,n)}),a=this.entities.store(a),s.abrupt("return",new en(a));case 43:case"end":return s.stop()}},_callee8,this,[[14,20],[26,32]])})),function(e){return c.apply(this,arguments)})},{key:"map",value:(l=x.default(M.default.mark(function _callee9(e){var t,n,r,a,i=this;return M.default.wrap(function(s){for(;;)switch(s.prev=s.next){case 0:return s.next=2,this.ensureReady();case 2:if("create_new"!==(t=decompose(e)).mode){s.next=9;break}return s.next=6,this._createMap(t.id,t.ttl);case 6:case 17:case 29:n=s.sent,s.next=39;break;case 9:if(!(r=this.getCached(t.id,eh.type))){s.next=14;break}return s.abrupt("return",new eh(r));case 14:return s.prev=14,s.next=17,this._getMap(t.id,t.includeItems);case 20:if(s.prev=20,s.t0=s.catch(14),!(404!==s.t0.status||"open_existing"===t.mode)){s.next=26;break}throw s.t0;case 26:return s.prev=26,s.next=29,this._createMap(t.id,t.ttl);case 32:if(s.prev=32,s.t1=s.catch(26),409!==s.t1.status){s.next=38;break}return s.abrupt("return",this.map(e));case 38:throw s.t1;case 39:return this.storeRootInSessionCache(eh.type,t.id,n),a=new ef(this.services,n,function(e,t,n){return i.removeFromCacheAndSession(e,t,n)}),a=this.entities.store(a),s.abrupt("return",new eh(a));case 43:case"end":return s.stop()}},_callee9,this,[[14,20],[26,32]])})),function(e){return l.apply(this,arguments)})},{key:"list",value:(d=x.default(M.default.mark(function _callee10(e){var t,n,r,a,i=this;return M.default.wrap(function(s){for(;;)switch(s.prev=s.next){case 0:return s.next=2,this.ensureReady();case 2:if("create_new"!==(t=decompose(e)).mode){s.next=9;break}return s.next=6,this._createList(t.id,t.purpose,t.context,t.ttl);case 6:case 17:case 29:n=s.sent,s.next=39;break;case 9:if(!(r=this.getCached(t.id,ed.type))){s.next=14;break}return s.abrupt("return",new ed(r));case 14:return s.prev=14,s.next=17,this._getList(t.id);case 20:if(s.prev=20,s.t0=s.catch(14),!(404!==s.t0.status||"open_existing"===t.mode)){s.next=26;break}throw s.t0;case 26:return s.prev=26,s.next=29,this._createList(t.id,t.purpose,t.context,t.ttl);case 32:if(s.prev=32,s.t1=s.catch(26),409!==s.t1.status){s.next=38;break}return s.abrupt("return",this.list(e));case 38:throw s.t1;case 39:return this.storeRootInSessionCache(ed.type,t.id,n),a=new el(this.services,n,function(e,t,n){return i.removeFromCacheAndSession(e,t,n)}),a=this.entities.store(a),s.abrupt("return",new ed(a));case 43:case"end":return s.stop()}},_callee10,this,[[14,20],[26,32]])})),function(e){return d.apply(this,arguments)})},{key:"stream",value:(p=x.default(M.default.mark(function _callee11(e){var t,n,r,a,i,s=this;return M.default.wrap(function(u){for(;;)switch(u.prev=u.next){case 0:return u.next=2,this.ensureReady();case 2:if("create_new"!==(t=decompose(e)).mode){u.next=9;break}return u.next=6,this._createStream(t.id,t.ttl);case 6:case 17:case 29:n=u.sent,u.next=39;break;case 9:if(!(r=this.getCached(t.id,ev.type))){u.next=14;break}return u.abrupt("return",new ev(r));case 14:return u.prev=14,u.next=17,this._getStream(t.id);case 20:if(u.prev=20,u.t0=u.catch(14),!(404!==u.t0.status||"open_existing"===t.mode)){u.next=26;break}throw u.t0;case 26:return u.prev=26,u.next=29,this._createStream(t.id,t.ttl);case 32:if(u.prev=32,u.t1=u.catch(26),409!==u.t1.status){u.next=38;break}return u.abrupt("return",this.stream(e));case 38:throw u.t1;case 39:return this.storeRootInSessionCache(ev.type,t.id,n),a=function(e,t,n){return s.removeFromCacheAndSession(e,t,n)},i=new ey(this.services,n,a),i=this.entities.store(i),u.abrupt("return",new ev(i));case 44:case"end":return u.stop()}},_callee11,this,[[14,20],[26,32]])})),function(e){return p.apply(this,arguments)})},{key:"shutdown",value:(f=x.default(M.default.mark(function _callee12(){return M.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.services.subscriptions.shutdown();case 2:return e.next=4,this.services.twilsock.disconnect();case 4:case"end":return e.stop()}},_callee12,this)})),function(){return f.apply(this,arguments)})},{key:"updateToken",value:(h=x.default(M.default.mark(function _callee13(e){return M.default.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.services.twilsock.updateToken(e).catch(function(e){var t,n=null==e?void 0:null===(t=e.reply)||void 0===t?void 0:t.status;if((null==n?void 0:n.code)===401&&(null==n?void 0:n.status)==="UNAUTHORIZED")throw new B("Updated token was rejected by server",400,51130);throw e}));case 1:case"end":return t.stop()}},_callee13,this)})),function(e){return h.apply(this,arguments)})},{key:"liveQuery",value:(v=x.default(M.default.mark(function _callee14(e,t){var n,r,a,i,s,u=this;return M.default.wrap(function(o){for(;;)switch(o.prev=o.next){case 0:return o.next=2,this.ensureReady();case 2:return n=new Q(this.services.config.insightsUri).pathSegment(e).pathSegment("Items").build(),o.next=5,queryItems({network:this.services.network,uri:n,queryString:t,type:eg.type});case 5:return r=o.sent,(a=this.getCached(r.query_id,eg.type))||((i=this._getLiveQuery(r.query_id))||(i={indexName:e,queryExpression:t,sid:r.query_id,queryUri:n,last_event_id:r.last_event_id}),s=function(e,t,n){return u.removeFromCacheAndSession(e,t,n)},a=new e_(i,this.services,s,r.items)),this.storeRootInSessionCache(eg.type,r.query_id,a.liveQueryDescriptor),a=this.entities.store(a),o.abrupt("return",new eg(a));case 11:case"end":return o.stop()}},_callee14,this)})),function(e,t){return v.apply(this,arguments)})},{key:"instantQuery",value:(m=x.default(M.default.mark(function _callee15(e){var t,n=this;return M.default.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this.ensureReady();case 2:return t=function(e,t){return n.liveQuery(e,t)},r.abrupt("return",new ek({indexName:e,network:this.services.network,insightsUri:this.services.config.insightsUri,liveQueryCreator:t}));case 4:case"end":return r.stop()}},_callee15,this)})),function(e){return m.apply(this,arguments)})}],[{key:"populateInitRegistrations",value:function(e){e.populateInitRegistrations([eS,ew,eI,ex])}},{key:"version",get:function(){return eb}}]),Client}(EventEmitter);N.default(eE,"connectionStateChanged","connectionStateChanged"),N.default(eE,"connectionError","connectionError"),N.default(eE,"tokenAboutToExpire","tokenAboutToExpire"),N.default(eE,"tokenExpired","tokenExpired"),__decorate([h.validateTypesAsync(["undefined","string",h.objectSchema("open document options",{id:["string","undefined"],mode:[h.literal("open_or_create","open_existing","create_new"),"undefined"],ttl:[h.nonNegativeInteger,"undefined"],data:[h.pureObject,"undefined",h.literal(null)]})]),__metadata("design:type",Function),__metadata("design:paramtypes",[Object]),__metadata("design:returntype",Promise)],eE.prototype,"document",null),__decorate([h.validateTypesAsync(["undefined","string",h.objectSchema("open map options",{id:["string","undefined"],mode:[h.literal("open_or_create","open_existing","create_new"),"undefined"],ttl:[h.nonNegativeInteger,"undefined"],data:[h.pureObject,"undefined",h.literal(null)],includeItems:["boolean","undefined"]})]),__metadata("design:type",Function),__metadata("design:paramtypes",[Object]),__metadata("design:returntype",Promise)],eE.prototype,"map",null),__decorate([h.validateTypesAsync(["undefined","string",h.objectSchema("open list options",{id:["string","undefined"],mode:[h.literal("open_or_create","open_existing","create_new"),"undefined"],ttl:[h.nonNegativeInteger,"undefined"],data:[h.pureObject,"undefined",h.literal(null)],purpose:["string","undefined"],context:[h.pureObject,"undefined"],includeItems:["boolean","undefined"]})]),__metadata("design:type",Function),__metadata("design:paramtypes",[Object]),__metadata("design:returntype",Promise)],eE.prototype,"list",null),__decorate([h.validateTypesAsync(["undefined","string",h.objectSchema("open stream options",{id:["string","undefined"],mode:[h.literal("open_or_create","open_existing","create_new"),"undefined"],ttl:[h.nonNegativeInteger,"undefined"],data:[h.pureObject,"undefined",h.literal(null)]})]),__metadata("design:type",Function),__metadata("design:paramtypes",[Object]),__metadata("design:returntype",Promise)],eE.prototype,"stream",null),__decorate([h.validateTypesAsync(h.nonEmptyString),__metadata("design:type",Function),__metadata("design:paramtypes",[String]),__metadata("design:returntype",Promise)],eE.prototype,"updateToken",null),__decorate([h.validateTypesAsync(h.nonEmptyString,"string"),__metadata("design:type",Function),__metadata("design:paramtypes",[String,String]),__metadata("design:returntype",Promise)],eE.prototype,"liveQuery",null),__decorate([h.validateTypesAsync(h.nonEmptyString),__metadata("design:type",Function),__metadata("design:paramtypes",[String]),__metadata("design:returntype",Promise)],eE.prototype,"instantQuery",null),t.Client=eE,t.InsightsItem=function InsightsItem(){S.default(this,InsightsItem)},t.InstantQuery=ek,t.LiveQuery=eg,t.Paginator=ea,t.SyncClient=eE,t.SyncDocument=en,t.SyncList=ed,t.SyncListItem=er,t.SyncMap=eh,t.SyncMapItem=ep,t.SyncStream=ev}}]);