dexie-cloud-addon 4.0.0-beta.17 → 4.0.0-beta.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modern/dexie-cloud-addon.js +1622 -1570
- package/dist/modern/dexie-cloud-addon.js.map +1 -1
- package/dist/modern/dexie-cloud-addon.min.js +1 -1
- package/dist/modern/dexie-cloud-addon.min.js.map +1 -1
- package/dist/modern/service-worker.js +1685 -1630
- package/dist/modern/service-worker.js.map +1 -1
- package/dist/modern/service-worker.min.js +1 -1
- package/dist/modern/service-worker.min.js.map +1 -1
- package/dist/module-es5/dexie-cloud-addon.js +669 -637
- package/dist/module-es5/dexie-cloud-addon.js.map +1 -1
- package/dist/module-es5/dexie-cloud-addon.min.js +1 -1
- package/dist/module-es5/dexie-cloud-addon.min.js.map +1 -1
- package/dist/umd/dexie-cloud-addon.js +669 -637
- package/dist/umd/dexie-cloud-addon.js.map +1 -1
- package/dist/umd/dexie-cloud-addon.min.js +1 -1
- package/dist/umd/dexie-cloud-addon.min.js.map +1 -1
- package/dist/umd/service-worker.js +1685 -1630
- package/dist/umd/service-worker.js.map +1 -1
- package/dist/umd/service-worker.min.js +1 -1
- package/dist/umd/service-worker.min.js.map +1 -1
- package/dist/umd-modern/dexie-cloud-addon.js +1619 -1567
- package/dist/umd-modern/dexie-cloud-addon.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
import e,{liveQuery as n,cmp as t}from"dexie";import{BehaviorSubject as r,fromEvent as o,of as i,merge as s,from as u,Observable as a,Subscription as c,Subject as l,switchMap as f,combineLatest as d,map as h,throwError as v,share as p,timer as b}from"rxjs";var y=function(e,n){return y=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])},y(e,n)};function m(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function t(){this.constructor=e}y(e,n),e.prototype=null===n?Object.create(n):(t.prototype=n.prototype,new t)}var g=function(){return g=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var o in n=arguments[t])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e},g.apply(this,arguments)};function _(e,n,t,r){return new(t||(t=Promise))((function(o,i){function s(e){try{a(r.next(e))}catch(e){i(e)}}function u(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(s,u)}a((r=r.apply(e,n||[])).next())}))}function w(e,n){var t,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(t)throw new TypeError("Generator is already executing.");for(;s;)try{if(t=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=n.call(e,s)}catch(e){i=[6,e],r=0}finally{t=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}}function S(e,n,t){if(t||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return e.concat(r||Array.prototype.slice.call(n))}var k=crypto.getRandomValues;function x(e,n,t){if(e&&void 0!==n&&(!("isFrozen"in Object)||!Object.isFrozen(e)))if("string"!=typeof n&&"length"in n){!function(e){if(!e)throw new Error("Assertion Failed")}("string"!=typeof t&&"length"in t);for(var r=0,o=n.length;r<o;++r)x(e,n[r],t[r])}else{var i=n.indexOf(".");if(-1!==i){var s=n.substr(0,i),u=n.substr(i+1);if(""===u)void 0===t?Array.isArray(e)?isNaN(parseInt(s))||e.splice(parseInt(s),1):delete e[s]:e[s]=t;else{var a=e[s];a||(a=e[s]={}),x(a,u,t)}}else void 0===t?Array.isArray(e)&&!isNaN(parseInt(n))?e.splice(n,1):delete e[n]:e[n]=t}}var I="undefined"==typeof self?function(e){var n=Buffer.alloc(e);return k(n),n.toString("base64")}:function(e){var n=new Uint8Array(e);return crypto.getRandomValues(n),btoa(String.fromCharCode.apply(null,n))};function E(e){return"string"==typeof e||!!(Array.isArray(e)&&e.some((function(e){return E(e)}))&&e.every(T))}function T(e){return"string"==typeof e||"number"==typeof e||Array.isArray(e)&&e.every(T)}function A(e,n,t){var r=e[n]||(e[n]={}),o=t.keys.map((function(e){return"string"==typeof e?e:JSON.stringify(e)}));switch(t.type){case"insert":case"upsert":o.forEach((function(e,n){r[e]={type:"ups",val:t.values[n]}}));break;case"update":case"modify":o.forEach((function(e,n){var o="update"===t.type?t.changeSpecs[n]:t.changeSpec,i=r[e];if(i)switch(i.type){case"ups":for(var s=0,u=Object.entries(o);s<u.length;s++){var a=u[s],c=a[0],l=a[1];x(i.val,c,l)}break;case"del":break;case"upd":Object.assign(i.mod,o)}else r[e]={type:"upd",mod:o}}));break;case"delete":o.forEach((function(e){r[e]={type:"del"}}))}return e}function C(e,n){for(var t=0,r=n;t<r.length;t++)for(var o=r[t],i=o.table,s=0,u=o.muts;s<u.length;s++){A(e,i,u[s])}}function P(e){return"function"==typeof e}function U(e){return function(n){if(function(e){return P(null==e?void 0:e.lift)}(n))return n.lift((function(n){try{return e(n,this)}catch(e){this.error(e)}}));throw new TypeError("Unable to lift unknown Observable type")}}var O=function(e,n){return O=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])},O(e,n)};function D(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function t(){this.constructor=e}O(e,n),e.prototype=null===n?Object.create(n):(t.prototype=n.prototype,new t)}function R(e,n,t,r){return new(t||(t=Promise))((function(o,i){function s(e){try{a(r.next(e))}catch(e){i(e)}}function u(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(s,u)}a((r=r.apply(e,n||[])).next())}))}function j(e,n){var t,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(t)throw new TypeError("Generator is already executing.");for(;s;)try{if(t=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=n.call(e,s)}catch(e){i=[6,e],r=0}finally{t=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}}function L(e){var n="function"==typeof Symbol&&Symbol.iterator,t=n&&e[n],r=0;if(t)return t.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")}function N(e,n){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var r,o,i=t.call(e),s=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(t=i.return)&&t.call(i)}finally{if(o)throw o.error}}return s}function $(e,n){for(var t=0,r=n.length,o=e.length;t<r;t++,o++)e[o]=n[t];return e}function W(e){return this instanceof W?(this.v=e,this):new W(e)}function B(e,n,t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,o=t.apply(e,n||[]),i=[];return r={},s("next"),s("throw"),s("return"),r[Symbol.asyncIterator]=function(){return this},r;function s(e){o[e]&&(r[e]=function(n){return new Promise((function(t,r){i.push([e,n,t,r])>1||u(e,n)}))})}function u(e,n){try{!function(e){e.value instanceof W?Promise.resolve(e.value.v).then(a,c):l(i[0][2],e)}(o[e](n))}catch(e){l(i[0][3],e)}}function a(e){u("next",e)}function c(e){u("throw",e)}function l(e,n){e(n),i.shift(),i.length&&u(i[0][0],i[0][1])}}function M(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n,t=e[Symbol.asyncIterator];return t?t.call(e):(e=L(e),n={},r("next"),r("throw"),r("return"),n[Symbol.asyncIterator]=function(){return this},n);function r(t){n[t]=e[t]&&function(n){return new Promise((function(r,o){(function(e,n,t,r){Promise.resolve(r).then((function(n){e({value:n,done:t})}),n)})(r,o,(n=e[t](n)).done,n.value)}))}}}var F=function(e){return e&&"number"==typeof e.length&&"function"!=typeof e};function K(e){return P(null==e?void 0:e.then)}function H(e){var n=e((function(e){Error.call(e),e.stack=(new Error).stack}));return n.prototype=Object.create(Error.prototype),n.prototype.constructor=n,n}var q=H((function(e){return function(n){e(this),this.message=n?n.length+" errors occurred during unsubscription:\n"+n.map((function(e,n){return n+1+") "+e.toString()})).join("\n "):"",this.name="UnsubscriptionError",this.errors=n}}));function V(e,n){if(e){var t=e.indexOf(n);0<=t&&e.splice(t,1)}}var z=function(){function e(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._teardowns=null}var n;return e.prototype.unsubscribe=function(){var e,n,t,r,o;if(!this.closed){this.closed=!0;var i=this._parentage;if(i)if(this._parentage=null,Array.isArray(i))try{for(var s=L(i),u=s.next();!u.done;u=s.next()){u.value.remove(this)}}catch(n){e={error:n}}finally{try{u&&!u.done&&(n=s.return)&&n.call(s)}finally{if(e)throw e.error}}else i.remove(this);var a=this.initialTeardown;if(P(a))try{a()}catch(e){o=e instanceof q?e.errors:[e]}var c=this._teardowns;if(c){this._teardowns=null;try{for(var l=L(c),f=l.next();!f.done;f=l.next()){var d=f.value;try{J(d)}catch(e){o=null!=o?o:[],e instanceof q?o=$($([],N(o)),N(e.errors)):o.push(e)}}}catch(e){t={error:e}}finally{try{f&&!f.done&&(r=l.return)&&r.call(l)}finally{if(t)throw t.error}}}if(o)throw new q(o)}},e.prototype.add=function(n){var t;if(n&&n!==this)if(this.closed)J(n);else{if(n instanceof e){if(n.closed||n._hasParent(this))return;n._addParent(this)}(this._teardowns=null!==(t=this._teardowns)&&void 0!==t?t:[]).push(n)}},e.prototype._hasParent=function(e){var n=this._parentage;return n===e||Array.isArray(n)&&n.includes(e)},e.prototype._addParent=function(e){var n=this._parentage;this._parentage=Array.isArray(n)?(n.push(e),n):n?[n,e]:e},e.prototype._removeParent=function(e){var n=this._parentage;n===e?this._parentage=null:Array.isArray(n)&&V(n,e)},e.prototype.remove=function(n){var t=this._teardowns;t&&V(t,n),n instanceof e&&n._removeParent(this)},e.EMPTY=((n=new e).closed=!0,n),e}();function G(e){return e instanceof z||e&&"closed"in e&&P(e.remove)&&P(e.add)&&P(e.unsubscribe)}function J(e){P(e)?e():e.unsubscribe()}var Y={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},Z={setTimeout:function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var t=Z.delegate;return((null==t?void 0:t.setTimeout)||setTimeout).apply(void 0,$([],N(e)))},clearTimeout:function(e){return clearTimeout(e)},delegate:void 0};function X(e){Z.setTimeout((function(){throw e}))}function Q(){}var ee=function(e){function n(n){var t=e.call(this)||this;return t.isStopped=!1,n?(t.destination=n,G(n)&&n.add(t)):t.destination=oe,t}return D(n,e),n.create=function(e,n,t){return new ne(e,n,t)},n.prototype.next=function(e){this.isStopped||this._next(e)},n.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},n.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},n.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},n.prototype._next=function(e){this.destination.next(e)},n.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},n.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},n}(z),ne=function(e){function n(n,t,r){var o,i=e.call(this)||this;if(P(n))o=n;else if(n){var s;o=n.next,t=n.error,r=n.complete,i&&Y.useDeprecatedNextContext?(s=Object.create(n)).unsubscribe=function(){return i.unsubscribe()}:s=n,o=null==o?void 0:o.bind(s),t=null==t?void 0:t.bind(s),r=null==r?void 0:r.bind(s)}return i.destination={next:o?te(o):Q,error:te(null!=t?t:re),complete:r?te(r):Q},i}return D(n,e),n}(ee);function te(e,n){return function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];try{e.apply(void 0,$([],N(n)))}catch(e){X(e)}}}function re(e){throw e}var oe={closed:!0,next:Q,error:re,complete:Q},ie="function"==typeof Symbol&&Symbol.observable||"@@observable";function se(e){return e}function ue(e){return 0===e.length?se:1===e.length?e[0]:function(n){return e.reduce((function(e,n){return n(e)}),n)}}var ae=function(){function e(e){e&&(this._subscribe=e)}return e.prototype.lift=function(n){var t=new e;return t.source=this,t.operator=n,t},e.prototype.subscribe=function(e,n,t){var r,o=this,i=(r=e)&&r instanceof ee||function(e){return e&&P(e.next)&&P(e.error)&&P(e.complete)}(r)&&G(r)?e:new ne(e,n,t);return function(){var e=o,n=e.operator,t=e.source;i.add(n?n.call(i,t):t?o._subscribe(i):o._trySubscribe(i))}(),i},e.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(n){e.error(n)}},e.prototype.forEach=function(e,n){var t=this;return new(n=ce(n))((function(n,r){var o;o=t.subscribe((function(n){try{e(n)}catch(e){r(e),null==o||o.unsubscribe()}}),r,n)}))},e.prototype._subscribe=function(e){var n;return null===(n=this.source)||void 0===n?void 0:n.subscribe(e)},e.prototype[ie]=function(){return this},e.prototype.pipe=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return ue(e)(this)},e.prototype.toPromise=function(e){var n=this;return new(e=ce(e))((function(e,t){var r;n.subscribe((function(e){return r=e}),(function(e){return t(e)}),(function(){return e(r)}))}))},e.create=function(n){return new e(n)},e}();function ce(e){var n;return null!==(n=null!=e?e:Y.Promise)&&void 0!==n?n:Promise}function le(e){return P(e[ie])}function fe(e){return Symbol.asyncIterator&&P(null==e?void 0:e[Symbol.asyncIterator])}function de(e){return new TypeError("You provided "+(null!==e&&"object"==typeof e?"an invalid object":"'"+e+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}var he="function"==typeof Symbol&&Symbol.iterator?Symbol.iterator:"@@iterator";function ve(e){return P(null==e?void 0:e[he])}function pe(e){return B(this,arguments,(function(){var n,t,r;return j(this,(function(o){switch(o.label){case 0:n=e.getReader(),o.label=1;case 1:o.trys.push([1,,9,10]),o.label=2;case 2:return[4,W(n.read())];case 3:return t=o.sent(),r=t.value,t.done?[4,W(void 0)]:[3,5];case 4:return[2,o.sent()];case 5:return[4,W(r)];case 6:return[4,o.sent()];case 7:return o.sent(),[3,2];case 8:return[3,10];case 9:return n.releaseLock(),[7];case 10:return[2]}}))}))}function be(e){return P(null==e?void 0:e.getReader)}function ye(e){if(e instanceof ae)return e;if(null!=e){if(le(e))return o=e,new ae((function(e){var n=o[ie]();if(P(n.subscribe))return n.subscribe(e);throw new TypeError("Provided object does not correctly implement Symbol.observable")}));if(F(e))return r=e,new ae((function(e){for(var n=0;n<r.length&&!e.closed;n++)e.next(r[n]);e.complete()}));if(K(e))return t=e,new ae((function(e){t.then((function(n){e.closed||(e.next(n),e.complete())}),(function(n){return e.error(n)})).then(null,X)}));if(fe(e))return me(e);if(ve(e))return n=e,new ae((function(e){var t,r;try{for(var o=L(n),i=o.next();!i.done;i=o.next()){var s=i.value;if(e.next(s),e.closed)return}}catch(e){t={error:e}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(t)throw t.error}}e.complete()}));if(be(e))return me(pe(e))}var n,t,r,o;throw de(e)}function me(e){return new ae((function(n){(function(e,n){var t,r,o,i;return R(this,void 0,void 0,(function(){var s,u;return j(this,(function(a){switch(a.label){case 0:a.trys.push([0,5,6,11]),t=M(e),a.label=1;case 1:return[4,t.next()];case 2:if((r=a.sent()).done)return[3,4];if(s=r.value,n.next(s),n.closed)return[2];a.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return u=a.sent(),o={error:u},[3,11];case 6:return a.trys.push([6,,9,10]),r&&!r.done&&(i=t.return)?[4,i.call(t)]:[3,8];case 7:a.sent(),a.label=8;case 8:return[3,10];case 9:if(o)throw o.error;return[7];case 10:return[7];case 11:return n.complete(),[2]}}))}))})(e,n).catch((function(e){return n.error(e)}))}))}var ge=function(e){function n(n,t,r,o,i){var s=e.call(this,n)||this;return s.onFinalize=i,s._next=t?function(e){try{t(e)}catch(e){n.error(e)}}:e.prototype._next,s._error=o?function(e){try{o(e)}catch(e){n.error(e)}finally{this.unsubscribe()}}:e.prototype._error,s._complete=r?function(){try{r()}catch(e){n.error(e)}finally{this.unsubscribe()}}:e.prototype._complete,s}return D(n,e),n.prototype.unsubscribe=function(){var n,t=this.closed;e.prototype.unsubscribe.call(this),!t&&(null===(n=this.onFinalize)||void 0===n||n.call(this))},n}(ee),_e=function(e){function n(n,t){return e.call(this)||this}return D(n,e),n.prototype.schedule=function(e,n){return this},n}(z),we={setInterval:function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var t=we.delegate;return((null==t?void 0:t.setInterval)||setInterval).apply(void 0,$([],N(e)))},clearInterval:function(e){return clearInterval(e)},delegate:void 0},Se=function(e){function n(n,t){var r=e.call(this,n,t)||this;return r.scheduler=n,r.work=t,r.pending=!1,r}return D(n,e),n.prototype.schedule=function(e,n){if(void 0===n&&(n=0),this.closed)return this;this.state=e;var t=this.id,r=this.scheduler;return null!=t&&(this.id=this.recycleAsyncId(r,t,n)),this.pending=!0,this.delay=n,this.id=this.id||this.requestAsyncId(r,this.id,n),this},n.prototype.requestAsyncId=function(e,n,t){return void 0===t&&(t=0),we.setInterval(e.flush.bind(e,this),t)},n.prototype.recycleAsyncId=function(e,n,t){if(void 0===t&&(t=0),null!=t&&this.delay===t&&!1===this.pending)return n;we.clearInterval(n)},n.prototype.execute=function(e,n){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var t=this._execute(e,n);if(t)return t;!1===this.pending&&null!=this.id&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},n.prototype._execute=function(e,n){var t,r=!1;try{this.work(e)}catch(e){r=!0,t=e||new Error("Scheduled action threw falsy error")}if(r)return this.unsubscribe(),t},n.prototype.unsubscribe=function(){if(!this.closed){var n=this.id,t=this.scheduler,r=t.actions;this.work=this.state=this.scheduler=null,this.pending=!1,V(r,this),null!=n&&(this.id=this.recycleAsyncId(t,n,null)),this.delay=null,e.prototype.unsubscribe.call(this)}},n}(_e),ke=function(){return Date.now()},xe=function(){function e(n,t){void 0===t&&(t=e.now),this.schedulerActionCtor=n,this.now=t}return e.prototype.schedule=function(e,n,t){return void 0===n&&(n=0),new this.schedulerActionCtor(this,e).schedule(t,n)},e.now=ke,e}(),Ie=new(function(e){function n(n,t){void 0===t&&(t=xe.now);var r=e.call(this,n,t)||this;return r.actions=[],r._active=!1,r._scheduled=void 0,r}return D(n,e),n.prototype.flush=function(e){var n=this.actions;if(this._active)n.push(e);else{var t;this._active=!0;do{if(t=e.execute(e.state,e.delay))break}while(e=n.shift());if(this._active=!1,t){for(;e=n.shift();)e.unsubscribe();throw t}}},n}(xe))(Se),Ee=Ie;function Te(e){return e&&P(e.schedule)}function Ae(e){return e instanceof Date&&!isNaN(e)}function Ce(e){return Te((n=e)[n.length-1])?e.pop():void 0;var n}function Pe(e,n,t,r,o){void 0===r&&(r=0),void 0===o&&(o=!1);var i=n.schedule((function(){t(),o?e.add(this.schedule(null,r)):this.unsubscribe()}),r);if(e.add(i),!o)return i}function Ue(e){return U((function(n,t){var r,o=null,i=!1;o=n.subscribe(new ge(t,void 0,void 0,(function(s){r=ye(e(s,Ue(e)(n))),o?(o.unsubscribe(),o=null,r.subscribe(t)):i=!0}))),i&&(o.unsubscribe(),o=null,r.subscribe(t))}))}function Oe(e,n){return void 0===n&&(n=0),U((function(t,r){t.subscribe(new ge(r,(function(t){return Pe(r,e,(function(){return r.next(t)}),n)}),(function(){return Pe(r,e,(function(){return r.complete()}),n)}),(function(t){return Pe(r,e,(function(){return r.error(t)}),n)})))}))}function De(e,n){return void 0===n&&(n=0),U((function(t,r){r.add(e.schedule((function(){return t.subscribe(r)}),n))}))}function Re(e,n){if(!e)throw new Error("Iterable cannot be null");return new ae((function(t){Pe(t,n,(function(){var r=e[Symbol.asyncIterator]();Pe(t,n,(function(){r.next().then((function(e){e.done?t.complete():t.next(e.value)}))}),0,!0)}))}))}function je(e,n){if(null!=e){if(le(e))return function(e,n){return ye(e).pipe(De(n),Oe(n))}(e,n);if(F(e))return function(e,n){return new ae((function(t){var r=0;return n.schedule((function(){r===e.length?t.complete():(t.next(e[r++]),t.closed||this.schedule())}))}))}(e,n);if(K(e))return function(e,n){return ye(e).pipe(De(n),Oe(n))}(e,n);if(fe(e))return Re(e,n);if(ve(e))return function(e,n){return new ae((function(t){var r;return Pe(t,n,(function(){r=e[he](),Pe(t,n,(function(){var e,n,o;try{n=(e=r.next()).value,o=e.done}catch(e){return void t.error(e)}o?t.complete():t.next(n)}),0,!0)})),function(){return P(null==r?void 0:r.return)&&r.return()}}))}(e,n);if(be(e))return function(e,n){return Re(pe(e),n)}(e,n)}throw de(e)}function Le(e,n){return n?je(e,n):ye(e)}function Ne(e,n){return U((function(t,r){var o=0;t.subscribe(new ge(r,(function(t){r.next(e.call(n,t,o++))})))}))}function $e(e,n,t){return void 0===t&&(t=1/0),P(n)?$e((function(t,r){return Ne((function(e,o){return n(t,e,r,o)}))(ye(e(t,r)))}),t):("number"==typeof n&&(t=n),U((function(n,r){return function(e,n,t,r,o,i,s,u){var a=[],c=0,l=0,f=!1,d=function(){!f||a.length||c||n.complete()},h=function(e){return c<r?v(e):a.push(e)},v=function(e){i&&n.next(e),c++;var u=!1;ye(t(e,l++)).subscribe(new ge(n,(function(e){null==o||o(e),i?h(e):n.next(e)}),(function(){u=!0}),void 0,(function(){if(u)try{c--;for(var e=function(){var e=a.shift();s?Pe(n,s,(function(){return v(e)})):v(e)};a.length&&c<r;)e();d()}catch(e){n.error(e)}})))};return e.subscribe(new ge(n,h,(function(){f=!0,d()}))),function(){null==u||u()}}(n,r,e,t)})))}function We(){return void 0===(e=1)&&(e=1/0),$e(se,e);var e}function Be(e,n){return void 0===n&&(n=Ie),U((function(t,r){var o=null,i=null,s=null,u=function(){if(o){o.unsubscribe(),o=null;var e=i;i=null,r.next(e)}};function a(){var t=s+e,i=n.now();if(i<t)return o=this.schedule(void 0,t-i),void r.add(o);u()}t.subscribe(new ge(r,(function(t){i=t,s=n.now(),o||(o=n.schedule(a,e),r.add(o))}),(function(){u(),r.complete()}),void 0,(function(){i=o=null})))}))}function Me(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return We()(Le(e,Ce(e)))}var Fe=new ae((function(e){return e.complete()}));function Ke(e){return e<=0?function(){return Fe}:U((function(n,t){var r=0;n.subscribe(new ge(t,(function(n){++r<=e&&(t.next(n),e<=r&&t.complete())})))}))}function He(e,n){return n?function(t){return Me(n.pipe(Ke(1),U((function(e,n){e.subscribe(new ge(n,Q))}))),t.pipe(He(e)))}:$e((function(n,t){return e(n,t).pipe(Ke(1),function(e){return Ne((function(){return e}))}(n))}))}function qe(e,n){void 0===n&&(n=Ie);var t=function(e,n,t){void 0===e&&(e=0),void 0===t&&(t=Ee);var r=-1;return null!=n&&(Te(n)?t=n:r=n),new ae((function(n){var o=Ae(e)?+e-t.now():e;o<0&&(o=0);var i=0;return t.schedule((function(){n.closed||(n.next(i++),0<=r?this.schedule(void 0,r):n.complete())}),o)}))}(e,n);return He((function(){return t}))}function Ve(e,n){return e===n}function ze(e,n){return U((function(t,r){var o=0;t.subscribe(new ge(r,(function(t){return e.call(n,t,o++)&&r.next(t)})))}))}function Ge(e){return ze((function(n,t){return e<=t}))}function Je(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var t=Ce(e);return U((function(n,r){(t?Me(e,n,t):Me(e,n)).subscribe(r)}))}function Ye(e,n){return U((function(t,r){var o=null,i=0,s=!1,u=function(){return s&&!o&&r.complete()};t.subscribe(new ge(r,(function(t){null==o||o.unsubscribe();var s=0,a=i++;ye(e(t,a)).subscribe(o=new ge(r,(function(e){return r.next(n?n(t,e,a,s++):e)}),(function(){o=null,u()})))}),(function(){s=!0,u()})))}))}function Ze(e,n,t){var r=P(e)||n||t?{next:e,error:n,complete:t}:e;return r?U((function(e,n){var t;null===(t=r.subscribe)||void 0===t||t.call(r);var o=!0;e.subscribe(new ge(n,(function(e){var t;null===(t=r.next)||void 0===t||t.call(r,e),n.next(e)}),(function(){var e;o=!1,null===(e=r.complete)||void 0===e||e.call(r),n.complete()}),(function(e){var t;o=!1,null===(t=r.error)||void 0===t||t.call(r,e),n.error(e)}),(function(){var e,n;o&&(null===(e=r.unsubscribe)||void 0===e||e.call(r)),null===(n=r.finalize)||void 0===n||n.call(r)})))})):se}var Xe=H((function(e){return function(n){void 0===n&&(n=null),e(this),this.message="Timeout has occurred",this.name="TimeoutError",this.info=n}}));function Qe(e){throw new Xe(e)}var en=!1;function nn(e,n){return _(this,void 0,void 0,(function(){var t,r;return w(this,(function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),[4,navigator.serviceWorker.ready];case 1:return t=o.sent(),"push"===n&&t.sync?[4,t.sync.register("dexie-cloud:".concat(e.name))]:[3,3];case 2:o.sent(),o.label=3;case 3:if(!t.active)throw new Error("Failed to trigger sync - there's no active service worker");return t.active.postMessage({type:"dexie-cloud-sync",dbName:e.name,purpose:n}),[2];case 4:return r=o.sent(),en||(console.debug("Dexie Cloud: Could not register sync event",r),en=!0),[3,5];case 5:return[2]}}))}))}function tn(e,n){e.cloud.usingServiceWorker?nn(e,n):e.localSyncEvent.next({purpose:n})}var rn="undefined"!=typeof Buffer?function(e){return Buffer.from(e,"base64")}:function(e){for(var n=atob(e),t=n.length,r=new Uint8Array(t),o=0;o<t;o++)r[o]=n.charCodeAt(o);return r},on="undefined"!=typeof Buffer?function(e){return ArrayBuffer.isView(e)?Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"):Buffer.from(e).toString("base64")}:function(e){return btoa(String.fromCharCode.apply(null,e))};function sn(n,t){return new Promise((function(r,o){var i=g(g({},t),{onSubmit:function(e){n.next(void 0),r(e)},onCancel:function(){n.next(void 0),o(new e.AbortError("User cancelled"))}});n.next(i)}))}function un(e,n){for(var t=[],r=2;r<arguments.length;r++)t[r-2]=arguments[r];return sn(e,{type:"message-alert",title:n,alerts:t,fields:{}})}function an(e,n,t){return _(this,void 0,void 0,(function(){var r;return w(this,(function(o){switch(o.label){case 0:r=t||"",o.label=1;case 1:return r&&/^[\w-\.]+@([\w-]+\.)+[\w-]{2,10}$/.test(r)?[3,3]:[4,sn(e,{type:"email",title:n,alerts:r?[{type:"error",messageCode:"INVALID_EMAIL",message:"Please enter a valid email address",messageParams:{}}]:[],fields:{email:{type:"email",placeholder:"you@somedomain.com"}}})];case 2:return r=o.sent().email,[3,1];case 3:return[2,r]}}))}))}function cn(e,n,t){return _(this,void 0,void 0,(function(){var r;return w(this,(function(o){switch(o.label){case 0:return r=[{type:"info",messageCode:"OTP_SENT",message:"A One-Time password has been sent to {email}",messageParams:{email:n}}],t&&r.push(t),[4,sn(e,{type:"otp",title:"Enter OTP",alerts:r,fields:{otp:{type:"otp",label:"OTP",placeholder:"Paste OTP here"}}})];case 1:return[2,o.sent().otp]}}))}))}function ln(e){var n,t;return _(this,void 0,void 0,(function(){var r,o,i,s,u,a,c;return w(this,(function(l){switch(l.label){case 0:return[4,e.getCurrentUser()];case 1:if(r=l.sent(),o=r.accessToken,i=r.accessTokenExpiration,s=r.refreshToken,u=r.refreshTokenExpiration,a=r.claims,!o)return[2];if((null!==(n=null==i?void 0:i.getTime())&&void 0!==n?n:1/0)>Date.now())return[2,o];if(!s)throw new Error("Refresh token missing");if((null!==(t=null==u?void 0:u.getTime())&&void 0!==t?t:1/0)<=Date.now())throw new Error("Refresh token has expired");return[4,dn(e.cloud.options.databaseUrl,r)];case 2:return c=l.sent(),[4,e.table("$logins").update(a.sub,{accessToken:c.accessToken,accessTokenExpiration:c.accessTokenExpiration})];case 3:return l.sent(),[2,c.accessToken]}}))}))}function fn(e,n,t,r,o){return _(this,void 0,void 0,(function(){return w(this,(function(i){switch(i.label){case 0:return n.accessToken&&n.accessTokenExpiration.getTime()>Date.now()?[2,n]:[3,1];case 1:return n.refreshToken&&(!n.refreshTokenExpiration||n.refreshTokenExpiration.getTime()>Date.now())?[4,dn(e,n)]:[3,3];case 2:case 4:return[2,i.sent()];case 3:return[4,hn(n,t,r,o)]}}))}))}function dn(e,n){return _(this,void 0,void 0,(function(){var t,r,o,i,s,u,a,c,l;return w(this,(function(f){switch(f.label){case 0:if(!n.refreshToken)throw new Error("Cannot refresh token - refresh token is missing.");if(!n.nonExportablePrivateKey)throw new Error("login.nonExportablePrivateKey is missing - cannot sign refresh token without a private key.");return t=Date.now(),r="RSASSA-PKCS1-v1_5",o=new TextEncoder,i=o.encode(n.refreshToken+t),[4,crypto.subtle.sign(r,n.nonExportablePrivateKey,i)];case 1:return s=f.sent(),u=on(s),a={grant_type:"refresh_token",refresh_token:n.refreshToken,scopes:["ACCESS_DB"],signature:u,signing_algorithm:r,time_stamp:t},[4,fetch("".concat(e,"/token"),{body:JSON.stringify(a),method:"post",headers:{"Content-Type":"application/json"},mode:"cors"})];case 2:if(200!==(c=f.sent()).status)throw new Error("RefreshToken: Status ".concat(c.status," from ").concat(e,"/token"));return[4,c.json()];case 3:return l=f.sent(),n.accessToken=l.accessToken,n.accessTokenExpiration=l.accessTokenExpiration?new Date(l.accessTokenExpiration):void 0,[2,n]}}))}))}function hn(e,n,t,r){return _(this,void 0,void 0,(function(){var o,i,s,u,a,c,l;return w(this,(function(f){switch(f.label){case 0:return[4,crypto.subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:2048,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!1,["sign","verify"])];case 1:if(o=f.sent(),i=o.privateKey,s=o.publicKey,!i||!s)throw new Error("Could not generate RSA keypair");return e.nonExportablePrivateKey=i,[4,crypto.subtle.exportKey("spki",s)];case 2:u=f.sent(),a=function(e){for(var n="-----BEGIN PUBLIC KEY-----\n";e.length>0;)n+=e.substring(0,64)+"\n",e=e.substring(64);return n+="-----END PUBLIC KEY-----"}(on(u)),e.publicKey=s,f.label=3;case 3:return f.trys.push([3,7,,9]),[4,n({public_key:a,hints:r})];case 4:if("tokens"!==(c=f.sent()).type)throw new Error("Unexpected response type from token endpoint: ".concat(c.type));return e.accessToken=c.accessToken,e.accessTokenExpiration=new Date(c.accessTokenExpiration),e.refreshToken=c.refreshToken,c.refreshTokenExpiration&&(e.refreshTokenExpiration=new Date(c.refreshTokenExpiration)),e.userId=c.claims.sub,e.email=c.claims.email,e.name=c.claims.name,e.claims=c.claims,c.alerts&&c.alerts.length>0?[4,sn(t,{type:"message-alert",title:"Authentication Alert",fields:{},alerts:c.alerts})]:[3,6];case 5:f.sent(),f.label=6;case 6:return[2,e];case 7:return l=f.sent(),[4,un(t,"Authentication Failed",{type:"error",messageCode:"GENERIC_ERROR",message:"We're having a problem authenticating right now.",messageParams:{}}).catch((function(){}))];case 8:throw f.sent(),l;case 9:return[2]}}))}))}var vn=new WeakMap,pn=function(){function e(e,n){vn.set(this,e),Object.assign(this,n)}return e.load=function(n,t){return n.table("$logins").get(t).then((function(r){return new e(n,r||{userId:t,claims:{sub:t},lastLogin:new Date(0)})}))},e.prototype.save=function(){return _(this,void 0,void 0,(function(){return w(this,(function(e){return vn.get(this).table("$logins").put(this),[2]}))}))},e}(),bn=function(e){function n(n,t){var r=e.call(this,t||"".concat(n.status," ").concat(n.statusText))||this;return r.httpStatus=n.status,r}return m(n,e),Object.defineProperty(n.prototype,"name",{get:function(){return"HttpError"},enumerable:!1,configurable:!0}),n}(Error);function yn(e){var n=e.cloud.userInteraction;return function(t){var r,o=t.public_key,i=t.hints;return _(this,void 0,void 0,(function(){var t,s,u,a,c,l,f,d,h,v,p;return w(this,(function(b){switch(b.label){case 0:if(!(s=null===(r=e.cloud.options)||void 0===r?void 0:r.databaseUrl))throw new Error("No database URL given.");return"demo"!==(null==i?void 0:i.grant_type)?[3,2]:[4,an(n,"Enter a demo user email",(null==i?void 0:i.email)||(null==i?void 0:i.userId))];case 1:return u=b.sent(),t={demo_user:u,grant_type:"demo",scopes:["ACCESS_DB"],public_key:o},[3,4];case 2:return[4,an(n,"Enter email address",null==i?void 0:i.email)];case 3:a=b.sent(),t={email:a,grant_type:"otp",scopes:["ACCESS_DB"],public_key:o},b.label=4;case 4:return[4,fetch("".concat(s,"/token"),{body:JSON.stringify(t),method:"post",headers:{"Content-Type":"application/json",mode:"cors"}})];case 5:return 200===(c=b.sent()).status?[3,8]:[4,c.text()];case 6:return p=b.sent(),[4,un(n,"Token request failed",{type:"error",messageCode:"GENERIC_ERROR",message:p,messageParams:{}}).catch((function(){}))];case 7:throw b.sent(),new bn(c,p);case 8:return[4,c.json()];case 9:return"tokens"!==(l=b.sent()).type?[3,10]:[2,l];case 10:if("otp"!==t.grant_type)return[3,22];if("otp-sent"!==l.type)throw new Error("Unexpected response from ".concat(s,"/token"));return[4,cn(n,t.email)];case 11:return f=b.sent(),t.otp=f||"",t.otp_id=l.otp_id,[4,fetch("".concat(s,"/token"),{body:JSON.stringify(t),method:"post",headers:{"Content-Type":"application/json"},mode:"cors"})];case 12:d=b.sent(),b.label=13;case 13:return 401!==d.status?[3,17]:[4,d.text()];case 14:return h=b.sent(),v=t,[4,cn(n,t.email,{type:"error",messageCode:"INVALID_OTP",message:h,messageParams:{}})];case 15:return v.otp=b.sent(),[4,fetch("".concat(s,"/token"),{body:JSON.stringify(t),method:"post",headers:{"Content-Type":"application/json"},mode:"cors"})];case 16:return d=b.sent(),[3,13];case 17:return 200===d.status?[3,20]:[4,d.text()];case 18:return p=b.sent(),[4,un(n,"OTP Authentication Failed",{type:"error",messageCode:"GENERIC_ERROR",message:p,messageParams:{}}).catch((function(){}))];case 19:throw b.sent(),new bn(d,p);case 20:return[4,d.json()];case 21:return[2,b.sent()];case 22:throw new Error("Unexpected response from ".concat(s,"/token"))}}))}))}}function mn(e,n){return _(this,void 0,void 0,(function(){var t,r=this;return w(this,(function(o){switch(o.label){case 0:return n.userId===e.cloud.currentUserId?[2]:(t=e.table("$logins"),[4,e.transaction("rw",t,(function(e){return _(r,void 0,void 0,(function(){var e;return w(this,(function(r){switch(r.label){case 0:return[4,t.toArray()];case 1:return e=r.sent(),[4,Promise.all(e.filter((function(e){return e.userId!==n.userId&&e.isLoggedIn})).map((function(e){return e.isLoggedIn=!1,t.put(e)})))];case 2:return r.sent(),n.isLoggedIn=!0,n.lastLogin=new Date,[4,n.save()];case 3:return r.sent(),console.debug("Saved new user",n.email),[2]}}))}))}))]);case 1:return o.sent(),[4,new Promise((function(t){if(e.cloud.currentUserId===n.userId)t(null);else var r=e.cloud.currentUser.subscribe((function(e){e.userId===n.userId&&(r.unsubscribe(),t(null))}))}))];case 2:return o.sent(),[2]}}))}))}function gn(e,n){return _(this,void 0,void 0,(function(){var t;return w(this,(function(r){switch(r.label){case 0:return[4,e.getCurrentUser()];case 1:if(r.sent().isLoggedIn){if(n){if(n.email&&e.cloud.currentUser.value.email!==n.email)throw new Error("Must logout before changing user");if(n.userId&&e.cloud.currentUserId!==n.userId)throw new Error("Must logout before changing user")}return[2]}return t=new pn(e,{claims:{},lastLogin:new Date(0)}),[4,fn(e.cloud.options.databaseUrl,t,e.cloud.options.fetchTokens||yn(e),e.cloud.userInteraction,n)];case 2:return r.sent(),[4,t.save()];case 3:return r.sent(),[4,mn(e,t)];case 4:return r.sent(),tn(e,"pull"),[2]}}))}))}var _n={userId:"unauthorized",name:"Unauthorized",claims:{sub:"unauthorized"},lastLogin:new Date(0)};try{Object.freeze(_n),Object.freeze(_n.claims)}catch(e){}var wn={},Sn=self.document&&navigator.serviceWorker;Sn&&Sn.ready.then((function(e){return wn.registration=e})),"undefined"!=typeof self&&"clients"in self&&!self.document&&addEventListener("message",(function(e){var n,t;(null===(t=null===(n=e.data)||void 0===n?void 0:n.type)||void 0===t?void 0:t.startsWith("sw-broadcast-"))&&S([],self.clients.matchAll({includeUncontrolled:!0}),!0).forEach((function(n){var t;return n.id!==(null===(t=e.source)||void 0===t?void 0:t.id)&&n.postMessage(e.data)}))}));var kn=function(){function e(e){this.name=e}return e.prototype.subscribe=function(e){var n=this;if(!Sn)return function(){};var t=function(t){var r;(null===(r=t.data)||void 0===r?void 0:r.type)==="sw-broadcast-".concat(n.name)&&e(t.data.message)};return Sn.addEventListener("message",t),function(){return Sn.removeEventListener("message",t)}},e.prototype.postMessage=function(e){var n,t=this;"object"==typeof self.clients?S([],self.clients.matchAll({includeUncontrolled:!0}),!0).forEach((function(n){return n.postMessage({type:"sw-broadcast-".concat(t.name),message:e})})):wn.registration&&(null===(n=wn.registration.active)||void 0===n||n.postMessage({type:"sw-broadcast-".concat(this.name),message:e}))},e}(),xn=function(e){function n(n){var t=this,r="undefined"==typeof BroadcastChannel?new kn(n):new BroadcastChannel(n);return(t=e.call(this,(function(e){function t(n){e.next(n.detail)}function o(n){console.debug("BroadcastedAndLocalEvent: onMessageEvent",n),e.next(n.data)}var i;return self.addEventListener("lbc-".concat(n),t),r instanceof kn?i=r.subscribe((function(n){return e.next(n)})):(console.debug("BroadcastedAndLocalEvent: bc.addEventListener()",n,"bc is a",r),r.addEventListener("message",o)),function(){self.removeEventListener("lbc-".concat(n),t),r instanceof kn?i():r.removeEventListener("message",o)}}))||this).name=n,t.bc=r,t}return m(n,e),n.prototype.next=function(e){console.debug("BroadcastedAndLocalEvent: bc.postMessage()",g({},e),"bc is a",this.bc),this.bc.postMessage(e);var n=new CustomEvent("lbc-".concat(this.name),{detail:e});self.dispatchEvent(n)},n}(a);function In(e){var n=e.realms,t=e.inviteRealms;return _(this,void 0,void 0,(function(){var e,r,o;return w(this,(function(i){switch(i.label){case 0:return e=JSON.stringify(S(S([],n.map((function(e){return{realmId:e,accepted:!0}})),!0),t.map((function(e){return{realmId:e,accepted:!1}})),!0).sort((function(e,n){return e.realmId<n.realmId?-1:e.realmId>n.realmId?1:0}))),r=(new TextEncoder).encode(e),[4,crypto.subtle.digest("SHA-1",r)];case 1:return o=i.sent(),[2,on(o)]}}))}))}function En(e){return Object.entries(e.cloud.schema||{}).filter((function(e){return e[1].markedForSync})).map((function(n){var t=n[0];return e.tables.filter((function(e){return e.name===t}))[0]})).filter((function(e){return e}))}function Tn(e){return"$".concat(e,"_mutations")}function An(e){var n,t=null===(n=/^\$(.*)_mutations$/.exec(e))||void 0===n?void 0:n[1];if(!t)throw new Error("Given mutationTable ".concat(e," is not correct"));return t}var Cn=[].concat;function Pn(e){return Cn.apply([],e)}function Un(e,n,t){var r=void 0===t?{}:t,o=r.since,i=void 0===o?{}:o,s=r.limit,u=void 0===s?1/0:s;return _(this,void 0,void 0,(function(){var n,t,r,o,s,a,c,l,f,d,h=this;return w(this,(function(v){switch(v.label){case 0:return[4,Promise.all(e.map((function(e){return _(h,void 0,void 0,(function(){var n,t,r;return w(this,(function(o){switch(o.label){case 0:return n=An(e.name),t=i[n],r=t?e.where("rev").above(t):e,u<1/0&&(r=r.limit(u)),[4,r.toArray()];case 1:return[2,o.sent().map((function(e){return{table:n,mut:e}}))]}}))}))})))];case 1:for(n=v.sent(),t=Pn(n).sort((function(e,n){return e.mut.ts-n.mut.ts})),r=[],o=null,s=null,a=0,c=t;a<c.length;a++)l=c[a],f=l.table,d=l.mut,o&&o.table===f&&s===d.txid?o.muts.push(d):(o={table:f,muts:[d]},s=d.txid,r.push(o));return[2,r]}}))}))}function On(e){var n=new Uint8Array(e);return crypto.getRandomValues(n),btoa(String.fromCharCode.apply(null,n))}function Dn(e,n,t,r){return _(this,void 0,void 0,(function(){var o,i,s=this;return w(this,(function(u){switch(u.label){case 0:return o="upload-".concat(On(8)),n.isLoggedIn?e.length>0?(i=new Set(r||[]),[4,Promise.all(e.map((function(e){return _(s,void 0,void 0,(function(){var r,s,u,a;return w(this,(function(c){switch(c.label){case 0:return(r=e.core.schema.primaryKey.extractKey)?(s=t[e.name],[4,((null==s?void 0:s.generatedGlobalId)?e.filter((function(e){var n=r(e);return!i.has(e.realmId||"")&&E(n)})):e.filter((function(e){return r(e),!i.has(e.realmId||"")&&(n=r(e),!(t=null==s?void 0:s.idPrefix)||"string"==typeof n&&n.startsWith(t));var n,t}))).toArray()]):[2,{table:e.name,muts:[]}];case 1:return(u=c.sent()).length>0?(a={type:"upsert",values:u,keys:u.map(r),userId:n.userId,txid:o},[2,{table:e.name,muts:[a]}]):[2,{table:e.name,muts:[]}]}}))}))})))]):[3,2]:[3,2];case 1:return[2,u.sent().filter((function(e){return e.muts.length>0}))];case 2:return[2,[]]}}))}))}var Rn={}.toString;function jn(e){return Rn.call(e).slice(8,-1)}var Ln={replace:function(e){for(var n=Object.keys(e),t=null,r=0,o=n.length;r<o;++r)"$"===n[r][0]&&(t=t||[]).push(n[r]);if(!t)return e;for(var i=g({},e),s=0,u=t;s<u.length;s++){delete i[u[s]]}for(var a=0,c=t;a<c.length;a++){var l=c[a];i["$"+l]=e[l]}return i}};function Nn(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var t=e.reduce((function(e,n){return g(g({},e),n)}),e.reduce((function(e,n){return g(g({},n),e)}),{})),r=new WeakMap;return{stringify:function(e,n,r){return JSON.stringify(e,(function(e){var r=this[e],i=o(r);return i?i.replace(r,n,t):r}),r)},parse:function(e,n){var r=[];return JSON.parse(e,(function(e,o){var i=null==o?void 0:o.$t;if(i){var s=t[i];o=s?s.revive(o,n,t):o}var u=r[r.length-1];if(u&&u[0]===o){o=g({},o);for(var a=0,c=u[1];a<c.length;a++){delete o[c[a]]}for(var l=0,f=Object.entries(u[2]);l<f.length;l++){var d=f[l],h=d[0],v=d[1];o[h]=v}r.pop()}if(void 0===o||"$"===e[0]&&"$t"!==e){var p=void 0,b=void 0;(u=r[r.length-1])&&u[0]===this?(p=u[1],b=u[2]):r.push([this,p=[],b={}]),"$"===e[0]&&"$t"!==e?(p.push(e),b[e.substr(1)]=o):b[e]=void 0}return o}))}};function o(e){var n=typeof e;switch(typeof e){case"object":case"function":if(null===e)return null;var o=Object.getPrototypeOf(e);if(!o)return Ln;var i=r.get(o);if(void 0!==i)return i;var s=jn(e),u=Object.entries(t).find((function(n){var t,r,o=n[0],i=n[1];return null!==(r=null===(t=null==i?void 0:i.test)||void 0===t?void 0:t.call(i,e,s))&&void 0!==r?r:o===s}));return(i=null==u?void 0:u[1])||(i=Array.isArray(e)?null:"function"==typeof e?t.function||null:Ln),r.set(o,i),i;default:return t[n]}}}var $n={Blob:{test:function(e,n){return"Blob"===n},replace:function(e,n){var t=n.length;return n.push(e),{$t:"Blob",mimeType:e.type,i:t}},revive:function(e,n){var t=e.i,r=e.mimeType;return new Blob([n[t]],{type:r})}}},Wn={number:{replace:function(e){switch(!0){case isNaN(e):return{$t:"number",v:"NaN"};case e===1/0:return{$t:"number",v:"Infinity"};case e===-1/0:return{$t:"number",v:"-Infinity"};default:return e}},revive:function(e){var n=e.v;return Number(n)}}},Bn={bigint:{replace:function(e){return{$t:"bigint",v:""+e}},revive:function(e){return BigInt(e.v)}}},Mn={Date:{replace:function(e){return{$t:"Date",v:isNaN(e.getTime())?"NaN":e.toISOString()}},revive:function(e){var n=e.v;return new Date("NaN"===n?NaN:Date.parse(n))}}},Fn={Set:{replace:function(e){return{$t:"Set",v:Array.from(e.entries())}},revive:function(e){var n=e.v;return new Set(n)}}},Kn={Map:{replace:function(e){return{$t:"Map",v:Array.from(e.entries())}},revive:function(e){var n=e.v;return new Map(n)}}},Hn="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"==typeof global?global:void 0,qn=["Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","DataView","BigInt64Array","BigUint64Array"].reduce((function(e,n){var t;return g(g({},e),((t={})[n]={replace:function(e,t,r){return{$t:n,v:r.ArrayBuffer.replace(0===e.byteOffset&&e.byteLength===e.buffer.byteLength?e.buffer:e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength),t,r).v}},revive:function(e,t,r){var o=e.v,i=Hn[n];return i&&new i(r.ArrayBuffer.revive({v:o},t,r))}},t))}),{});function Vn(e){return function(e){for(var n="",t=0,r=e.length;t<r;t++)n+=Jn[e[t]];return n}(on(e))}function zn(e){return rn(function(e){if("string"!=typeof e)throw new Error("invalid decoder input: "+e);for(var n="",t=0,r=e.length;t<r;t++)n+=Gn[e[t]];return n}(e))}for(var Gn={"-":"=",0:"A",1:"B",2:"C",3:"D",4:"E",5:"F",6:"G",7:"H",8:"I",9:"J",A:"K",B:"L",C:"M",D:"N",E:"O",F:"P",G:"Q",H:"R",I:"S",J:"T",K:"U",L:"V",M:"W",N:"X",O:"Y",P:"Z",Q:"a",R:"b",S:"c",T:"d",U:"e",V:"f",W:"g",X:"h",Y:"i",Z:"j",_:"k",a:"l",b:"m",c:"n",d:"o",e:"p",f:"q",g:"r",h:"s",i:"t",j:"u",k:"v",l:"w",m:"x",n:"y",o:"z",p:"0",q:"1",r:"2",s:"3",t:"4",u:"5",v:"6",w:"7",x:"8",y:"9",z:"+","|":"/"},Jn={},Yn=0,Zn=Object.keys(Gn);Yn<Zn.length;Yn++){var Xn=Zn[Yn];Jn[Gn[Xn]]=Xn}var Qn={ArrayBuffer:{replace:function(e){return{$t:"ArrayBuffer",v:Vn(e)}},revive:function(e){var n=zn(e.v);return n.buffer.byteLength===n.byteLength?n.buffer:n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength)}}},et=function(e,n){this.buf=e,this.type=n};function nt(e){var n=new XMLHttpRequest;if(n.overrideMimeType("text/plain; charset=x-user-defined"),n.open("GET",URL.createObjectURL(e),!1),n.send(),200!==n.status&&0!==n.status)throw new Error("Bad Blob access: "+n.status);return n.responseText}function tt(e){for(var n=new Uint8Array(e.length),t=0;t<e.length;++t)n[t]=e.charCodeAt(t);return n.buffer}var rt={Blob:{test:function(e,n){return"Blob"===n||e instanceof et},replace:function(e){return{$t:"Blob",v:on(e instanceof et?e.buf:tt(nt(e))),type:e.type}},revive:function(e){var n=e.type,t=e.v,r=rn(t);return void 0!==typeof Blob?new Blob([r]):new et(r.buffer,n)}}},ot=g(g(g(g(g(g(g(g({},Wn),Bn),Mn),Fn),Kn),qn),Qn),rt);function it(e){return new Promise((function(n,t){var r=new FileReader;r.onabort=function(e){return t(new Error("file read aborted"))},r.onerror=function(e){return t(e.target.error)},r.onload=function(e){return n(e.target.result)},r.readAsText(e)}))}function st(e){return new Promise((function(n,t){var r=new FileReader;r.onabort=function(e){return t(new Error("file read aborted"))},r.onerror=function(e){return t(e.target.error)},r.onload=function(e){return n(e.target.result)},r.readAsArrayBuffer(e)}))}var ut={undefined:{replace:function(){return{$t:"undefined"}},revive:function(){}}},at="bigint"==typeof BigInt(0),ct=function(){function e(e){this.v=e}return e.prototype.toString=function(){return this.v},e}(),lt=g(g({},ut),at?{}:{bigint:{test:function(e){return e instanceof ct},replace:function(e){return g({$t:"bigint"},e)},revive:function(e){var n=e.v;return new ct(n)}}}),ft=Nn(ot,lt),dt=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var t=Nn.apply(void 0,S([ot,$n],e,!1));return{toBinary:function(e){var n=this.stringify(e),t=n[0],r=n[1],o=new ArrayBuffer(4);return new DataView(o).setUint32(0,t.size),new Blob([o,t,r])},stringify:function(e){var n=[],r=t.stringify(e,n),o=new Blob(n.map((function(e){var n=new ArrayBuffer(4);return new DataView(n).setUint32(0,"byteLength"in e?e.byteLength:e.size),new Blob([n,e])})));return[o,r]},parse:function(e,n){return _(this,void 0,void 0,(function(){var r,o,i,s,u,a;return w(this,(function(c){switch(c.label){case 0:return r=0,o=[],[4,st(n)];case 1:for(i=c.sent(),s=new DataView(i);r<i.byteLength;)u=s.getUint32(r),r+=4,a=i.slice(r,r+u),r+=u,o.push(a);return[2,t.parse(e,o)]}}))}))},fromBinary:function(e){return _(this,void 0,void 0,(function(){var n,t,r,o;return w(this,(function(i){switch(i.label){case 0:return t=DataView.bind,[4,st(e.slice(0,4))];case 1:return n=(new(t.apply(DataView,[void 0,i.sent()]))).getUint32(0),r=e.slice(4,n+4),[4,it(e.slice(n+4))];case 2:return o=i.sent(),[4,this.parse(o,r)];case 3:return[2,i.sent()]}}))}))}}}(lt);function ht(n,t,r){for(var o=[],i=function(r){var i=r.table,s=r.muts,u=n.tables.find((function(e){return e.name===i}));if(!u)throw new Error("Internal error: table ".concat(i," not found in DBCore schema"));var a=u.primaryKey,c=r;s.forEach((function(n,o){var i=!a.outbound&&("upsert"===n.type||"insert"===n.type);n.keys.forEach((function(n,s){if(Array.isArray(n)){c===r&&(c=vt(r,i));var u=c.muts[o],l=JSON.stringify(n);u.keys[s]=l,i&&e.setByKeyPath(u.values[s],a.keyPath,l)}else if("#"===n[0]){c===r&&(c=vt(r,i));u=c.muts[o];if(!t.isLoggedIn)throw new Error("Internal error: Cannot sync private IDs before authenticated");l="".concat(n,":").concat(t.userId);u.keys[s]=l,i&&e.setByKeyPath(u.values[s],a.keyPath,l)}}))})),o.push(c)},s=0,u=r;s<u.length;s++){i(u[s])}return o}function vt(e,n){return g(g({},e),{muts:n?e.muts.map((function(e){return g(g({},e),{keys:e.keys.slice(),values:e.values.slice()})})):e.muts.map((function(e){return g(g({},e),{keys:e.keys.slice()})}))})}function pt(e,n,t,r,o,i,s,u){return _(this,void 0,void 0,(function(){var a,c,l,f,d,h,v;return w(this,(function(p){switch(p.label){case 0:return a={Accept:"application/json, application/x-bison, application/x-bison-stream","Content-Type":"application/tson"},[4,ln(r)];case 1:return(c=p.sent())&&(a.Authorization="Bearer ".concat(c)),l={v:2,dbID:null==n?void 0:n.remoteDbId,clientIdentity:s,schema:i||{},lastPull:n?{serverRevision:n.serverRevision,realms:n.realms,inviteRealms:n.inviteRealms}:void 0,baseRevs:t,changes:ht(r.dx.core.schema,u,e)},console.debug("Sync request",l),r.syncStateChangedEvent.next({phase:"pushing"}),[4,fetch("".concat(o,"/sync"),{method:"post",headers:a,body:ft.stringify(l)})];case 2:if(f=p.sent(),r.syncStateChangedEvent.next({phase:"pulling"}),!f.ok)throw new bn(f);switch(f.headers.get("content-type")){case"application/x-bison":return[3,3];case"application/x-bison-stream":case"application/json":return[3,5]}return[3,5];case 3:return h=(d=dt).fromBinary,[4,f.blob()];case 4:return[2,h.apply(d,[p.sent()])];case 5:return[4,f.text()];case 6:return v=p.sent(),[2,ft.parse(v)]}}))}))}function bt(e,n,t){return _(this,void 0,void 0,(function(){var r,o,i,s;return w(this,(function(u){switch(u.label){case 0:r=new Set(t||[]),o=0,i=e,u.label=1;case 1:return o<i.length?"members"!==(s=i[o]).name?[3,3]:[4,s.toCollection().modify((function(e){r.has(e.realmId)||e.userId&&e.userId!==_n.userId||(e.userId=n.userId)}))]:[3,9];case 2:return u.sent(),[3,8];case 3:return"roles"!==s.name?[3,4]:[3,8];case 4:return"realms"!==s.name?[3,6]:[4,s.toCollection().modify((function(e){r.has(e.realmId)||void 0!==e.owner&&e.owner!==_n.userId||(e.owner=n.userId)}))];case 5:return u.sent(),[3,8];case 6:return[4,s.toCollection().modify((function(e){e.realmId&&r.has(e.realmId)||(e.owner&&e.owner!==_n.userId||(e.owner=n.userId),e.realmId&&e.realmId!==_n.userId||(e.realmId=n.userId))}))];case 7:u.sent(),u.label=8;case 8:return o++,[3,1];case 9:return[2]}}))}))}function yt(n){if(null==n?void 0:n.cancelled)throw new e.AbortError("Operation was cancelled")}var mt=navigator.onLine;function gt(e,n,t,r){return _(this,void 0,void 0,(function(){return w(this,(function(o){switch(o.label){case 0:return[4,e.$baseRevs.bulkPut(Object.keys(n).filter((function(e){return n[e].markedForSync})).map((function(e){return{tableName:e,clientRev:(t[e]||0)+1,serverRev:r}})))];case 1:return o.sent(),[2]}}))}))}function _t(e,n){void 0===n&&(n={});for(var t=0,r=e;t<r.length;t++){var o=r[t],i=o.table,s=o.muts,u=s.length>0?s[s.length-1].rev:null;n[i]=u||n[i]||0}return n}function wt(n,r,o){return _(this,void 0,void 0,(function(){var i,s,u;return w(this,(function(a){switch(a.label){case 0:return[4,n.bulkGet(r)];case 1:return i=a.sent(),s=[],u=[],r.forEach((function(r,a){var c=i[a];if(c){for(var l=0,f=Object.entries(o[a]);l<f.length;l++){var d=f[l],h=d[0],v=d[1];if(h===n.schema.primKey.keyPath){if(0!==t(v,r))throw new Error("Cannot change primary key")}else e.setByKeyPath(c,h,v)}s.push(r),u.push(c)}})),[4,null==n.schema.primKey.keyPath?n.bulkPut(u,s):n.bulkPut(u)];case 2:return a.sent(),[2]}}))}))}function St(n,t){return _(this,void 0,void 0,(function(){var r,o,i,s,u,a;return w(this,(function(c){switch(c.label){case 0:console.debug("Applying server changes",n,e.currentTransaction),r=function(n,r){var o,i,s,u,a,c,l;return w(this,(function(f){switch(f.label){case 0:if(!(o=t.table(n)))return[2,"continue"];i=o.core.schema.primaryKey,s=function(e){switch(e[0]){case"[":if(e.endsWith("]"))try{return JSON.parse(e)}catch(e){}return e;case"#":return e.endsWith(":"+t.cloud.currentUserId)?e.substr(0,e.length-t.cloud.currentUserId.length-1):e;default:return e}},u=function(n){var t;return w(this,(function(r){switch(r.label){case 0:switch(t=n.keys.map(s),n.type){case"insert":return[3,1];case"upsert":return[3,6];case"modify":return[3,11];case"update":return[3,16];case"delete":return[3,18]}return[3,20];case 1:return i.outbound?[4,o.bulkAdd(n.values,t)]:[3,3];case 2:return r.sent(),[3,5];case 3:return t.forEach((function(t,r){e.setByKeyPath(n.values[r],i.keyPath,t)})),[4,o.bulkAdd(n.values)];case 4:r.sent(),r.label=5;case 5:return[3,20];case 6:return i.outbound?[4,o.bulkPut(n.values,t)]:[3,8];case 7:return r.sent(),[3,10];case 8:return t.forEach((function(t,r){e.setByKeyPath(n.values[r],i.keyPath,t)})),[4,o.bulkPut(n.values)];case 9:r.sent(),r.label=10;case 10:return[3,20];case 11:return 1!==t.length?[3,13]:[4,o.update(t[0],n.changeSpec)];case 12:return r.sent(),[3,15];case 13:return[4,o.where(":id").anyOf(t).modify(n.changeSpec)];case 14:r.sent(),r.label=15;case 15:return[3,20];case 16:return[4,wt(o,t,n.changeSpecs)];case 17:return r.sent(),[3,20];case 18:return[4,o.bulkDelete(t)];case 19:return r.sent(),[3,20];case 20:return[2]}}))},a=0,c=r,f.label=1;case 1:return a<c.length?(l=c[a],[5,u(l)]):[3,4];case 2:f.sent(),f.label=3;case 3:return a++,[3,1];case 4:return[2]}}))},o=0,i=n,c.label=1;case 1:return o<i.length?(s=i[o],u=s.table,a=s.muts,[5,r(u,a)]):[3,4];case 2:c.sent(),c.label=3;case 3:return o++,[3,1];case 4:return[2]}}))}))}self.addEventListener("online",(function(){return mt=!0})),self.addEventListener("offline",(function(){return mt=!1}));function kt(e,n,t,r){var o=this;return xt.apply(this,arguments).then((function(){(null==r?void 0:r.justCheckIfNeeded)||e.syncStateChangedEvent.next({phase:"in-sync"})})).catch((function(i){return _(o,void 0,void 0,(function(){return w(this,(function(o){switch(o.label){case 0:return(null==r?void 0:r.justCheckIfNeeded)?[2,Promise.reject(i)]:(console.debug("Error from _sync",{isOnline:mt,syncOptions:r,error:i}),mt&&(null==r?void 0:r.retryImmediatelyOnFetchError)&&"TypeError"===(null==i?void 0:i.name)&&/fetch/.test(null==i?void 0:i.message)?(e.syncStateChangedEvent.next({phase:"error",error:i}),[4,new Promise((function(e){return setTimeout(e,500)}))]):[3,3]);case 1:return o.sent(),[4,kt(e,n,t,g(g({},r),{retryImmediatelyOnFetchError:!1}))];case 2:return[2,o.sent()];case 3:return[4,e.$syncState.update("syncState",{timestamp:new Date,error:""+i})];case 4:return o.sent(),e.syncStateChangedEvent.next({phase:mt?"error":"offline",error:i}),[2,Promise.reject(i)]}}))}))}))}function xt(e,n,t,r){var o,i=void 0===r?{isInitialSync:!1}:r,s=i.isInitialSync,u=i.cancelToken,a=i.justCheckIfNeeded,c=i.purpose;return _(this,void 0,void 0,(function(){var r,i,l,f,d,h,v,p,b,y,m,g,k,x,E,T=this;return w(this,(function(A){switch(A.label){case 0:if(a||console.debug("SYNC STARTED",{isInitialSync:s,purpose:c}),!(null===(o=e.cloud.options)||void 0===o?void 0:o.databaseUrl))throw new Error("Internal error: sync must not be called when no databaseUrl is configured");return r=n.databaseUrl,[4,e.getCurrentUser()];case 1:return i=A.sent(),l=i.isLoggedIn?En(e):[],f=l.map((function(n){return e.table(Tn(n.name))})),[4,e.getPersistedSyncState()];case 2:return d=A.sent(),h=!s&&i.isLoggedIn?function(e,n){var t=(null==n?void 0:n.syncedTables)||[];return En(e).filter((function(e){return!t.includes(e.name)}))}(e,d):[],yt(u),(v=h.length>0)?a?[2,!0]:[4,e.transaction("rw",h,(function(e){return _(T,void 0,void 0,(function(){return w(this,(function(n){switch(n.label){case 0:return e.idbtrans.disableChangeTracking=!0,e.idbtrans.disableAccessControl=!0,[4,bt(h,i,null==d?void 0:d.realms)];case 1:return n.sent(),[2]}}))}))}))]:[3,4];case 3:A.sent(),yt(u),A.label=4;case 4:return[4,e.transaction("r",e.tables,(function(){return _(T,void 0,void 0,(function(){var n,r,o,s,a;return w(this,(function(c){switch(c.label){case 0:return[4,e.getPersistedSyncState()];case 1:return n=c.sent(),[4,e.$baseRevs.toArray()];case 2:return r=c.sent(),[4,Un(f)];case 3:return o=c.sent(),yt(u),v?(s=S(S([],(null==d?void 0:d.realms)||[],!0),(null==d?void 0:d.inviteRealms)||[],!0),[4,Dn(h,i,t,s)]):[3,5];case 4:return a=c.sent(),yt(u),[2,[o=o.concat(a),n,r]];case 5:return[2,[o,n,r]]}}))}))}))];case 5:return p=A.sent(),b=p[0],y=p[1],m=p[2],g=b.some((function(e){return e.muts.some((function(e){return e.keys.length>0}))})),a?(console.debug("Sync is needed:",g),[2,g]):"push"!==c||g?(k=_t(b,null==y?void 0:y.latestRevisions),x=(null==y?void 0:y.clientIdentity)||I(16),yt(u),[4,pt(b,y,m,e,r,t,x,i)]):[2,!1];case 6:return E=A.sent(),console.debug("Sync response",E),[4,e.transaction("rw",e.tables,(function(n){return _(T,void 0,void 0,(function(){var r,o,i,s,u,a,c,d,v,p;return w(this,(function(b){switch(b.label){case 0:for(n.idbtrans.disableChangeTracking=!0,n.idbtrans.disableAccessControl=!0,r=0,o=Object.keys(t);r<o.length;r++)i=o[r],E.schema[i]&&(t[i]=E.schema[i]);return[4,e.$syncState.put(t,"schema")];case 1:return b.sent(),[4,Un(f,0,{since:k})];case 2:s=b.sent(),u=function(n){var t,r;return w(this,(function(o){switch(o.label){case 0:return t=An(n.name),s.some((function(e){return e.table===t&&e.muts.length>0}))?[3,2]:[4,Promise.all([n.clear(),e.$baseRevs.where({tableName:t}).delete()])];case 1:return o.sent(),[3,5];case 2:return k[t]?(r=k[t]||0,[4,Promise.all([n.where("rev").belowOrEqual(r).delete(),e.$baseRevs.where(":id").between([t,-1/0],[t,r+1],!0,!0).reverse().offset(1).delete()])]):[3,4];case 3:return o.sent(),[3,5];case 4:o.label=5;case 5:return[2]}}))},a=0,c=f,b.label=3;case 3:return a<c.length?(d=c[a],[5,u(d)]):[3,6];case 4:b.sent(),b.label=5;case 5:return a++,[3,3];case 6:return _t(s,k),[4,gt(e,t,k,E.serverRevision)];case 7:return b.sent(),[4,e.getPersistedSyncState()];case 8:return v=b.sent(),[4,It(e,E,v)];case 9:return b.sent(),(p=v||{syncedTables:[],latestRevisions:{},realms:[],inviteRealms:[],clientIdentity:x}).syncedTables=l.map((function(e){return e.name})).concat(h.map((function(e){return e.name}))),p.latestRevisions=k,p.remoteDbId=E.dbId,p.initiallySynced=!0,p.realms=E.realms,p.inviteRealms=E.inviteRealms,p.serverRevision=E.serverRevision,p.timestamp=new Date,delete p.error,[4,St(Et(E.changes,s),e)];case 10:return b.sent(),e.$syncState.put(p,"syncState"),[2,0===s.length]}}))}))}))];case 7:return A.sent()?[3,9]:(console.debug("MORE SYNC NEEDED. Go for it again!"),[4,xt(e,n,t,{isInitialSync:s,cancelToken:u})]);case 8:return[2,A.sent()];case 9:return console.debug("SYNC DONE",{isInitialSync:s}),[2,!1]}}))}))}function It(e,n,t){return _(this,void 0,void 0,(function(){var r,o,i,s,u,a,c,l,f,d,h,v,p,b,y,m;return w(this,(function(g){switch(g.label){case 0:for(r=new Set,o=new Set,i=t?t.realms:[],s=t?t.inviteRealms:[],u=new Set(n.realms),a=new Set(n.realms.concat(n.inviteRealms)),c=0,l=i;c<l.length;c++)h=l[c],u.has(h)||(o.add(h),a.has(h)||r.add(h));for(f=0,d=s.concat(i);f<d.length;f++)h=d[f],a.has(h)||r.add(h);if(!(r.size>0||o.size>0))return[3,4];v=En(e),p=function(e){var n;return w(this,(function(t){switch(t.label){case 0:return 0===(n=["realms","members","roles"].includes(e.name)?r:o).size?[2,"continue"]:e.schema.indexes.some((function(e){return"realmId"===e.keyPath||Array.isArray(e.keyPath)&&"realmId"===e.keyPath[0]}))?[4,e.where("realmId").anyOf(S([],n,!0)).delete()]:[3,2];case 1:return t.sent(),[3,4];case 2:return[4,e.filter((function(e){return!!(null==e?void 0:e.realmId)&&n.has(e.realmId)})).delete()];case 3:t.sent(),t.label=4;case 4:return[2]}}))},b=0,y=v,g.label=1;case 1:return b<y.length?(m=y[b],[5,p(m)]):[3,4];case 2:g.sent(),g.label=3;case 3:return b++,[3,1];case 4:return[2]}}))}))}function Et(e,n){var t={};C(t,e);var r={};return C(r,n),function(e,n){for(var t,r,o,i=0,s=Object.entries(n);i<s.length;i++)for(var u=s[i],a=u[0],c=u[1],l=0,f=Object.entries(c);l<f.length;l++){var d=f[l],h=d[0],v=d[1];switch(v.type){case"ups":if(p=null===(t=e[a])||void 0===t?void 0:t[h])switch(p.type){case"ups":case"upd":delete e[a][h]}break;case"del":null===(r=e[a])||void 0===r||delete r[h];break;case"upd":var p;if(p=null===(o=e[a])||void 0===o?void 0:o[h])switch(p.type){case"ups":for(var b=0,y=Object.entries(v.mod);b<y.length;b++){var m=y[b],g=m[0],_=m[1];x(p.val,g,_)}break;case"del":break;case"upd":for(var w=0,S=Object.keys(v.mod);w<S.length;w++)g=S[w],delete p.mod[g]}}}}(t,r),function(e){for(var n=I(16),t={},r=0,o=Object.entries(e);r<o.length;r++)for(var i=o[r],s=i[0],u=i[1],a=0,c=Object.entries(u);a<c.length;a++){var l=c[a],f=l[0],d=l[1],h=t[s]||(t[s]={});(h[d.type]||(h[d.type]=[])).push(Object.assign({key:f},d))}for(var v=[],p=0,b=Object.entries(t);p<b.length;p++){for(var y=b[p],m=(s=y[0],u=y[1],{table:s,muts:[]}),g=0,_=Object.entries(u);g<_.length;g++){var w=_[g],S=w[0],k=w[1];switch(S){case"ups":d={type:"upsert",keys:k.map((function(e){return e.key})),values:k.map((function(e){return e.val})),txid:n},m.muts.push(d);break;case"upd":d={type:"update",keys:k.map((function(e){return e.key})),changeSpecs:k.map((function(e){return e.mod})),txid:n},m.muts.push(d);break;case"del":d={type:"delete",keys:k.map((function(e){return e.key})),txid:n},m.muts.push(d)}}v.push(m)}return v}(t)}var Tt=new WeakMap,At={members:"@id, [userId+realmId], [email+realmId], realmId",roles:"[realmId+name]",realms:"@realmId",$jobs:"",$syncState:"",$baseRevs:"[tableName+clientRev]",$logins:"claims.sub, lastLogin"},Ct=0;function Pt(n){"vip"in n&&(n=n.vip);var t=Tt.get(n.cloud);if(!t){var o=new l,i=new xn("syncstatechanged-".concat(n.name));o.id=++Ct;var s=!1;t={get name(){return n.name},close:function(){return n.close()},transaction:n.transaction.bind(n),table:n.table.bind(n),get tables(){return n.tables},cloud:n.cloud,get $jobs(){return n.table("$jobs")},get $syncState(){return n.table("$syncState")},get $baseRevs(){return n.table("$baseRevs")},get $logins(){return n.table("$logins")},get realms(){return n.realms},get members(){return n.members},get roles(){return n.roles},get initiallySynced(){return s},localSyncEvent:o,get syncStateChangedEvent(){return i},dx:n};var u={getCurrentUser:function(){return t.$logins.toArray().then((function(e){return e.find((function(e){return e.isLoggedIn}))||_n}))},getPersistedSyncState:function(){return t.$syncState.get("syncState")},getSchema:function(){return t.$syncState.get("schema")},getOptions:function(){return t.$syncState.get("options")},setInitiallySynced:function(e){s=e},reconfigure:function(){i=new xn("syncstatechanged-".concat(n.name))}};Object.assign(t,u),t.messageConsumer=function(n){var t=this,o=[],i=new r(!0),s=new r(null),u=!1,a=0,c=[0,0,0,0,0,0,0,0,0,Date.now()];function l(){var t,r,i;return _(this,void 0,void 0,(function(){var s,u=this;return w(this,(function(a){switch(a.label){case 0:s=function(){var s,a,c,l,f;return w(this,(function(d){switch(d.label){case 0:s=o.shift(),d.label=1;case 1:return d.trys.push([1,13,,14]),[4,n.cloud.syncState.pipe(ze((function(e){var n=e.phase;return"in-sync"===n||"error"===n})),Ke(1)).toPromise()];case 2:if(d.sent(),console.debug("processing msg",s),a=n.cloud.persistedSyncState.value,!s)return[2,"continue"];switch(s.type){case"token-expired":return[3,3];case"realm-added":return[3,6];case"realm-accepted":return[3,7];case"realm-removed":return[3,8];case"realms-changed":return[3,9];case"changes":return[3,10]}return[3,12];case 3:return console.debug("WebSocket observable: Token expired. Refreshing token..."),c=n.cloud.currentUser.value,[4,dn(n.cloud.options.databaseUrl,c)];case 4:return l=d.sent(),[4,n.table("$logins").update(c.userId,{accessToken:l.accessToken,accessTokenExpiration:l.accessTokenExpiration})];case 5:return d.sent(),[3,12];case 6:case 7:return tn(n,"pull"),[3,12];case 8:return(null===(t=null==a?void 0:a.realms)||void 0===t?void 0:t.includes(s.realm))||null===(r=null==a?void 0:a.inviteRealms)||void 0===r||r.includes(s.realm),tn(n,"pull"),[3,12];case 9:return tn(n,"pull"),[3,12];case 10:return console.debug("changes"),"error"===(null===(i=n.cloud.syncState.value)||void 0===i?void 0:i.phase)?(tn(n,"pull"),[3,12]):[4,n.transaction("rw",n.dx.tables,(function(t){return _(u,void 0,void 0,(function(){var r,o,i,u,a,c,l;return w(this,(function(f){switch(f.label){case 0:return t.idbtrans.disableChangeTracking=!0,t.idbtrans.disableAccessControl=!0,[4,Promise.all([n.getSchema(),n.getPersistedSyncState(),n.getCurrentUser()])];case 1:return r=f.sent(),o=r[0],i=r[1],u=r[2],console.debug("ws message queue: in transaction"),i&&o&&u?s.baseRev!==i.serverRevision?(console.debug("baseRev (".concat(s.baseRev,") differs from our serverRevision in syncState (").concat(i.serverRevision,")")),"string"!=typeof s.baseRev||"bigint"!=typeof i.serverRevision&&"object"!=typeof i.serverRevision||tn(n,"pull"),[2]):[4,e.waitFor(In(i))]:(console.debug("required vars not present",{syncState:i,schema:o,currentUser:u}),[2]);case 2:return a=f.sent(),console.debug("ourRealmSetHash",a),a!==s.realmSetHash?(console.debug("not same realmSetHash",s.realmSetHash),tn(n,"pull"),[2]):(c=[],u.isLoggedIn?[4,Un(En(n).map((function(e){return n.table(Tn(e.name))})))]:[3,4]);case 3:c=f.sent(),console.debug("msg queue: client changes",c),f.label=4;case 4:return s.changes.length>0?(l=Et(s.changes,c),console.debug("applying filtered server changes",l),[4,St(l,n)]):[3,6];case 5:f.sent(),f.label=6;case 6:return i.latestRevisions=_t(c,i.latestRevisions),i.serverRevision=s.newRev,console.debug("Updating baseRefs",i.latestRevisions),[4,gt(n,o,i.latestRevisions,s.newRev)];case 7:return f.sent(),console.debug("Updating syncState",i),[4,n.$syncState.put(i,"syncState")];case 8:return f.sent(),[2]}}))}))}))];case 11:return d.sent(),console.debug("msg queue: done with rw transaction"),[3,12];case 12:return[3,14];case 13:return f=d.sent(),console.error("Error in msg queue",f),[3,14];case 14:return[2]}}))},a.label=1;case 1:return o.length>0?[5,s()]:[3,3];case 2:return a.sent(),[3,1];case 3:return[2]}}))}))}return s.subscribe((function(){return _(t,void 0,void 0,(function(){return w(this,(function(e){switch(e.label){case 0:if(u)return[2];if(!(o.length>0))return[3,8];u=!0,c.shift(),c.push(Date.now()),i.next(!1),e.label=1;case 1:return e.trys.push([1,,3,8]),[4,l()];case 2:return e.sent(),[3,8];case 3:return c[c.length-1]-c[0]<1e4?Date.now()-a<5e3?(console.warn("Slowing down websocket loop for one minute"),a=Date.now()+6e4,[4,new Promise((function(e){return setTimeout(e,6e4)}))]):[3,5]:[3,7];case 4:return e.sent(),[3,7];case 5:return console.warn("Slowing down websocket loop for 10 seconds"),a=Date.now()+1e4,[4,new Promise((function(e){return setTimeout(e,1e4)}))];case 6:e.sent(),e.label=7;case 7:return u=!1,i.next(!0),[7];case 8:return[2]}}))}))})),{enqueue:function(e){o.push(e),s.next(null)},readyToServe:i}}(t),Tt.set(n.cloud,t)}return t}var Ut="undefined"!=typeof InstallTrigger,Ot="undefined"!=typeof navigator&&/Safari\//.test(navigator.userAgent)&&!/Chrom(e|ium)\/|Edge\//.test(navigator.userAgent),Dt=Ot?[].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1]:NaN,Rt=Ot&&Dt<=605||Ut;var jt="undefined"!=typeof self&&"clients"in self&&!self.document;function Lt(){throw new e.SchemaError("Version increment needed to allow dexie-cloud change tracking")}var Nt={}.toString;function $t(e){return Nt.call(e).slice(8,-1)}function Wt(e,n){var t;return"delete"===n.type?n.keys:(null===(t=n.keys)||void 0===t?void 0:t.slice())||n.values.map(e.extractKey)}var Bt=/b|c|d|f|g|h|j|k|l|m|n|p|q|r|s|t|v|x|y|z/i;var Mt=0;function Ft(e,n){var t=new Uint8Array(18),r=new Uint8Array(t.buffer,0,6),o=Date.now();Mt>=o?++Mt:Mt=o,r[0]=Mt/1099511627776,r[1]=Mt/4294967296,r[2]=Mt/16777216,r[3]=Mt/65536,r[4]=Mt/256,r[5]=Mt;var i=new Uint8Array(t.buffer,6);return crypto.getRandomValues(i),e+Vn(new Uint8Array(t.buffer))+(n||"")}function Kt(n){return{stack:"dbcore",name:"idGenerationMiddleware",level:1,create:function(t){return g(g({},t),{table:function(r){var o=t.table(r);return g(g({},o),{mutate:function(t){var i,s;if(t.trans.disableChangeTracking)return o.mutate(t);if("add"===t.type||"put"===t.type){var u=null===(i=n.cloud.schema)||void 0===i?void 0:i[r];if(null==u?void 0:u.generatedGlobalId){if((null===(s=n.cloud.options)||void 0===s?void 0:s.databaseUrl)&&!n.initiallySynced){var a=Wt(o.schema.primaryKey,t);return o.getMany({keys:a,trans:t.trans,cache:"immutable"}).then((function(e){if(e.length<a.length)throw new Error("Unable to create new objects without an initial sync having been performed.");return o.mutate(t)}))}return function(t,i){var s=null,u=Wt(o.schema.primaryKey,t);return u.forEach((function(a,c){if(void 0===a){var l=t.values[c].realmId||n.cloud.currentUserId,f=l.substr(l.length-3);u[c]=Ft(i,f),o.schema.primaryKey.outbound||(s||(s=t.values.slice()),s[c]=e.deepClone(s[c]),e.setByKeyPath(s[c],o.schema.primaryKey.keyPath,u[c]))}else if("string"!=typeof a||!a.startsWith(i)&&!a.startsWith("#"+i))throw new e.ConstraintError('The ID "'.concat(a,'" is not valid for table "').concat(r,'". ')+"Primary '@' keys requires the key to be prefixed with \"".concat(i,'" (or "#').concat(i,").\n")+"If you want to generate IDs programmatically, remove '@' from the schema to get rid of this constraint. Dexie Cloud supports custom IDs as long as they are random and globally unique.")})),o.mutate(g(g({},t),{keys:u,values:s||t.values}))}(t,u.idPrefix)}(null==u?void 0:u.markedForSync)&&Wt(o.schema.primaryKey,t).forEach((function(n,t){if(!E(n)){var o=Array.isArray(n)?n.map($t).join(","):$t(n);throw new e.ConstraintError("Invalid primary key type ".concat(o," for table ").concat(r,". Tables marked for sync has primary keys of type string or Array of string (and optional numbers)"))}}))}return o.mutate(t)}})}})}}}var Ht=0;function qt(e,n){return function(t){var r=t.trans[n]||(t.trans[n]={writers:[],readers:[]}),o=r.readers,i=r.writers,s=i.length,u=(s>0?i[s-1].then((function(){return e(t)}),(function(){return e(t)})):e(t)).finally((function(){return o.splice(o.indexOf(u))}));return o.push(u),u}}function Vt(e,n){return function(t){var r,o=t.trans[n]||(t.trans[n]={writers:[],readers:[]}),i=o.readers,s=o.writers,u=(s.length>0?s[s.length-1].then((function(){return e(t)}),(function(){return e(t)})):i.length>0?(r=i,new Promise((function(e){0===r.length&&e([]);var n=r.length,t=new Array(n);r.forEach((function(r,o){return Promise.resolve(r).then((function(e){return t[o]={status:"fulfilled",value:e}}),(function(e){return t[o]={status:"rejected",reason:e}})).then((function(){return--n||e(t)}))}))}))).then((function(){return e(t)})):e(t)).finally((function(){return s.shift()}));return s.push(u),u}}var zt=new r(new Set);function Gt(e){var n=e.currentUserObservable,t=e.db;return{stack:"dbcore",name:"MutationTrackingMiddleware",level:1,create:function(e){var r,o=e.schema.tables.filter((function(e){return!/^\$/.test(e.name)}));try{r=new Map(o.map((function(n){return[n.name,e.table("$".concat(n.name,"_mutations"))]})))}catch(e){Lt()}return g(g({},e),{transaction:function(r,o){var i;if("readwrite"===o){var s=r.filter((function(e){var n,r;return null===(r=null===(n=t.cloud.schema)||void 0===n?void 0:n[e])||void 0===r?void 0:r.markedForSync})).map((function(e){return Tn(e)}));i=e.transaction(S(S([],r,!0),s,!0),o)}else i=e.transaction(r,o);if("readwrite"===o){i.txid=On(16),i.currentUser=n.value,zt.value.add(i),zt.next(zt.value);var u=function(){i.removeEventListener("complete",a),i.removeEventListener("error",u),i.removeEventListener("abort",u),zt.value.delete(i),zt.next(zt.value)},a=function(){var e;i.mutationsAdded&&(null===(e=t.cloud.options)||void 0===e?void 0:e.databaseUrl)&&(t.cloud.usingServiceWorker?(console.debug("registering sync event"),nn(t,"push")):t.localSyncEvent.next({purpose:"push"})),u()};i.addEventListener("complete",a),i.addEventListener("error",u),i.addEventListener("abort",u)}return i},table:function(n){var o=e.table(n);if(/^\$/.test(n))return n.endsWith("_mutations")?g(g({},o),{mutate:function(e){return"add"!==e.type&&"put"!==e.type||(e.trans.mutationsAdded=!0),o.mutate(e)}}):"$logins"===n?g(g({},o),{mutate:function(e){return o.mutate(e).then((function(n){return e.trans.mutationsAdded=!0,n})).catch((function(e){return console.debug("Failed mutation $logins",e),Promise.reject(e)}))}}):o;var i=o.schema,s=r.get(n);return function(e){var n="$lock"+ ++Ht;return g(g({},e),{count:qt(e.count,n),get:qt(e.get,n),getMany:qt(e.getMany,n),openCursor:qt(e.openCursor,n),query:qt(e.query,n),mutate:Vt(e.mutate,n)})}(g(g({},o),{mutate:function(e){var r,s,a,c=e.trans;return c.txid?c.disableChangeTracking?o.mutate(e):(null===(s=null===(r=t.cloud.schema)||void 0===r?void 0:r[n])||void 0===s?void 0:s.markedForSync)&&(null===(a=c.currentUser)||void 0===a?void 0:a.isLoggedIn)?"deleteRange"===e.type?o.query({query:{range:e.range,index:i.primaryKey},trans:e.trans,values:!1}).then((function(n){return u({type:"delete",keys:n.result,trans:e.trans,criteria:{index:null,range:e.range}})})):u(e):o.mutate(e):o.mutate(e)}}));function u(e){var n=e.trans;n.mutationsAdded=!0;var t=n.txid,r=n.currentUser.userId,i=e.type;return o.mutate(e).then((function(o){var u=o.numFailures,a=o.failures,c="delete"===i?e.keys:o.results,l="values"in e?e.values:[],f="changeSpecs"in e?e.changeSpecs:[];u&&(c=c.filter((function(e,n){return!a[n]})),l=l.filter((function(e,n){return!a[n]})),f=f.filter((function(e,n){return!a[n]})));var d=Date.now(),h="delete"===e.type?{type:"delete",ts:d,keys:c,criteria:e.criteria,txid:t,userId:r}:"add"===e.type?{type:"insert",ts:d,keys:c,txid:t,userId:r,values:l}:e.criteria&&e.changeSpec?{type:"modify",ts:d,keys:c,criteria:e.criteria,changeSpec:e.changeSpec,txid:t,userId:r}:e.changeSpecs?{type:"update",ts:d,keys:c,changeSpecs:f,txid:t,userId:r}:{type:"upsert",ts:d,keys:c,values:l,txid:t,userId:r};return c.length>0||"criteria"in e&&e.criteria?s.mutate({type:"add",trans:n,values:[h]}).then((function(){return o})):o}))}}})}}}function Jt(e,n){return function(t,r){var o=g(g({},At),t),i=n.cloud.schema||(n.cloud.schema={}),s=new Set;return Object.keys(o).forEach((function(e){var n=o[e],t=i[e]||(i[e]={});null!=n?(/^\@/.test(n)&&(o[e]=o[e].substr(1),t.generatedGlobalId=!0,t.idPrefix=function(e,n){for(var t,r,o,i=e[0].toLocaleLowerCase(),s=1,u=e.length;s<u&&i.length<3;++s)(Bt.test(e[s])||(t=e[s])>="A"&&t<="Z")&&(i+=e[s].toLowerCase());for(;n.has(i);){if(/\d/g.test(i)){if(!((i=i.substr(0,i.length-1)+(i[i.length-1]+1)).length>3))continue;i=i.substr(0,3)}else if(i.length<3){i+="2";continue}for(var a=1,c=i;n.has(c)&&a<8;)r=i,c=(1&(o=a)?r[0].toUpperCase():r[0].toLowerCase())+(2&o?r[1].toUpperCase():r[1].toLowerCase())+(4&o?r[2].toUpperCase():r[2].toLowerCase()),++a;if(a<8)i=c;else{var l=i.charCodeAt(2)+1&127;i=i.substr(0,2)+String.fromCharCode(l)}}return i}(e,s),s.add(t.idPrefix)),/^\$/.test(e)||(o["$".concat(e,"_mutations")]="++rev",t.markedForSync=!0),t.deleted&&(t.deleted=!1)):(t.deleted=!0,t.markedForSync=!1,o["$".concat(e,"_mutations")]=null)})),e.call(this,o,r)}}function Yt(e,n,t){return _(this,void 0,void 0,(function(){return w(this,(function(r){switch(r.label){case 0:return console.debug("Performing initial sync"),[4,kt(e,n,t,{isInitialSync:!0})];case 1:return r.sent(),console.debug("Done initial sync"),[2]}}))}))}var Zt,Xt,Qt=new r(!0),er=new r(!0);Qt.pipe(Ye((function(e){return e?i(!0):i(!1).pipe(qe(2e4))})),(void 0===Xt&&(Xt=se),Zt=null!=Zt?Zt:Ve,U((function(e,n){var t,r=!0;e.subscribe(new ge(n,(function(e){var o=Xt(e);!r&&Zt(t,o)||(r=!1,t=o,n.next(e))})))})))).subscribe(er);var nr="undefined"!=typeof document?o(document,"visibilitychange"):i({}),tr=nr.pipe(ze((function(){return"hidden"===document.visibilityState}))),rr=nr.pipe(ze((function(){return"visible"===document.visibilityState}))),or="undefined"!=typeof window?s(rr,o(window,"mousedown"),o(window,"mousemove"),o(window,"keydown"),o(window,"wheel"),o(window,"touchmove")):i({});"undefined"!=typeof document&&s(i(!0),tr,or).pipe(Ne((function(){return"visible"===document.visibilityState})),Ze((function(e){Qt.value!==e&&Qt.next(e)})),Ye((function(e){return e?i(0).pipe(qe(16e4),Ze((function(){return Qt.next(!1)}))):i(0)}))).subscribe((function(){}));var ir=function(e){function n(){var n=e.apply(this,arguments)||this;return n.name="TokenExpiredError",n}return m(n,e),n}(Error),sr=function(e){function n(n,t,r,o,i,s,u,a){return e.call(this,(function(e){return new ar(n,t,r,o,u,a,e,i,s)}))||this}return m(n,e),n}(a),ur=0,ar=function(e){function n(n,t,r,o,i,s,u,a,c){var l=e.call(this,(function(){return l.teardown()}))||this;return l.id=++ur,l.reconnecting=!1,console.debug("New WebSocket Connection",l.id,i?"authorized":"unauthorized"),l.databaseUrl=n,l.rev=t,l.realmSetHash=r,l.clientIdentity=o,l.token=i,l.tokenExpiration=s,l.subscriber=u,l.lastUserActivity=new Date,l.messageProducer=a,l.messageProducerSubscription=null,l.webSocketStatus=c,l.connect(),l}return m(n,e),n.prototype.teardown=function(){console.debug("Teardown WebSocket Connection",this.id),this.disconnect()},n.prototype.disconnect=function(){if(this.webSocketStatus.next("disconnected"),this.pinger&&(clearInterval(this.pinger),this.pinger=null),this.ws)try{this.ws.close()}catch(e){}this.ws=null,this.messageProducerSubscription&&(this.messageProducerSubscription.unsubscribe(),this.messageProducerSubscription=null)},n.prototype.reconnect=function(){var e=this;if(!this.reconnecting){this.reconnecting=!0;try{this.disconnect()}catch(e){}this.connect().catch((function(){})).then((function(){return e.reconnecting=!1}))}},n.prototype.connect=function(){return _(this,void 0,void 0,(function(){var e,n,t,r,o=this;return w(this,(function(i){switch(i.label){case 0:if(this.lastServerActivity=new Date,this.pauseUntil&&this.pauseUntil>new Date)return console.debug("WS not reconnecting just yet",{id:this.id,pauseUntil:this.pauseUntil}),[2];if(this.ws)throw new Error("Called connect() when a connection is already open");if(!this.databaseUrl)throw new Error("Cannot connect without a database URL");if(this.closed)return[2];if(this.tokenExpiration&&this.tokenExpiration<new Date)return this.subscriber.error(new ir),[2];if(this.webSocketStatus.next("connecting"),this.pinger=setInterval((function(){return _(o,void 0,void 0,(function(){var e=this;return w(this,(function(n){if(this.closed)return console.debug("pinger check",this.id,"CLOSED."),this.teardown(),[2];if(this.ws)try{this.ws.send(JSON.stringify({type:"ping"})),setTimeout((function(){if(console.debug("pinger setTimeout",e.id,e.pinger?"alive":"dead"),e.pinger)return e.closed?(console.debug("pinger setTimeout",e.id,"subscription is closed"),void e.teardown()):void(e.lastServerActivity<new Date(Date.now()-2e4)?(console.debug("pinger: server is inactive"),console.debug("pinger reconnecting"),e.reconnect()):console.debug("pinger: server still active"))}),2e4)}catch(e){console.debug("pinger catch error",this.id,"reconnecting"),this.reconnect()}else console.debug("pinger",this.id,"reconnecting"),this.reconnect();return[2]}))}))}),3e4),(e=new URL(this.databaseUrl)).protocol="http:"===e.protocol?"ws":"wss",n=new URLSearchParams,this.subscriber.closed)return[2];n.set("v","2"),n.set("rev",this.rev),n.set("realmsHash",this.realmSetHash),n.set("clientId",this.clientIdentity),this.token&&n.set("token",this.token),console.debug("dexie-cloud WebSocket create"),(t=this.ws=new WebSocket("".concat(e,"/changes?").concat(n))).onclose=function(e){o.pinger&&(console.debug("dexie-cloud WebSocket onclosed",o.id),o.reconnect())},t.onmessage=function(e){if(o.pinger){console.debug("dexie-cloud WebSocket onmessage",e.data),o.lastServerActivity=new Date;try{var n=ft.parse(e.data);if("error"===n.type)throw new Error("Error message from dexie-cloud: ".concat(n.error));"rev"===n.type&&(o.rev=n.rev),"pong"!==n.type&&o.subscriber.next(n)}catch(e){o.subscriber.error(e)}}},i.label=1;case 1:return i.trys.push([1,3,,4]),r=!1,[4,new Promise((function(e,n){t.onopen=function(n){console.debug("dexie-cloud WebSocket onopen"),r=!0,e(null)},t.onerror=function(e){if(r)o.reconnect();else{var t=e.error||new Error("WebSocket Error");o.subscriber.error(t),o.webSocketStatus.next("error"),n(t)}}}))];case 2:return i.sent(),this.messageProducerSubscription=this.messageProducer.subscribe((function(e){var n;o.closed||("ready"===e.type&&"connected"!==o.webSocketStatus.value&&o.webSocketStatus.next("connected"),null===(n=o.ws)||void 0===n||n.send(ft.stringify(e)))})),[3,4];case 3:return i.sent(),this.pauseUntil=new Date(Date.now()+6e4),[3,4];case 4:return[2]}}))}))},n}(c);function cr(e){var n;if(!(null===(n=e.cloud.options)||void 0===n?void 0:n.databaseUrl))throw new Error("No database URL to connect WebSocket to");var t=e.messageConsumer.readyToServe.pipe(ze((function(e){return e})),Ye((function(){return e.getPersistedSyncState()})),ze((function(e){return e&&e.serverRevision})),Ne((function(e){return{type:"ready",rev:e.serverRevision}})));return function n(){var r=this;return e.cloud.persistedSyncState.pipe(ze((function(e){return null==e?void 0:e.serverRevision})),Ke(1),Ye((function(n){return e.cloud.currentUser.pipe(Ne((function(e){return[e,n]})))})),Ye((function(e){var n=e[0],t=e[1];return er.pipe(Ne((function(e){return[e?n:null,t]})))})),Ye((function(e){var n=e[0],t=e[1];return _(r,void 0,void 0,(function(){var e;return w(this,(function(r){switch(r.label){case 0:return e=[n],[4,In(t)];case 1:return[2,e.concat([r.sent()])]}}))}))})),Ye((function(n){var r=n[0],o=n[1];return r?new sr(e.cloud.options.databaseUrl,e.cloud.persistedSyncState.value.serverRevision,o,e.cloud.persistedSyncState.value.clientIdentity,t,e.cloud.webSocketStatus,r.accessToken,r.accessTokenExpiration):u([])})),Ue((function(t){return"TokenExpiredError"===(null==t?void 0:t.name)?(console.debug("WebSocket observable: Token expired. Refreshing token..."),i(!0).pipe(Ye((function(){return _(r,void 0,void 0,(function(){var n,t;return w(this,(function(r){switch(r.label){case 0:return[4,e.getCurrentUser()];case 1:return n=r.sent(),[4,dn(e.cloud.options.databaseUrl,n)];case 2:return t=r.sent(),[4,e.table("$logins").update(n.userId,{accessToken:t.accessToken,accessTokenExpiration:t.accessTokenExpiration})];case 3:return r.sent(),[2]}}))}))})),Ye((function(){return n()})))):v(t)})),Ue((function(t){return e.cloud.webSocketStatus.next("error"),u(function(e){return _(this,void 0,void 0,(function(){return w(this,(function(n){switch(n.label){case 0:return console.error("WebSocket observable: error but revive when user does some active thing...",e),[4,(t=3e3,new Promise((function(e){return setTimeout(e,t)})))];case 1:return n.sent(),console.debug("waiting for someone to do something"),[4,or.pipe(Ke(1)).toPromise()];case 2:return n.sent(),console.debug("someone did something!"),[2]}var t}))}))}(t)).pipe(Ye((function(){return n()})))})))}().subscribe((function(n){n&&(console.debug("WS got message",n),e.messageConsumer.enqueue(n))}),(function(e){console.error("Oops! The main observable errored!",e)}),(function(){console.error("Oops! The main observable completed!")}))}function lr(e){var n;return _(this,void 0,void 0,(function(){var t;return w(this,(function(r){switch(r.label){case 0:return(null===(n=e.cloud.options)||void 0===n?void 0:n.databaseUrl)&&e.cloud.schema?[4,kt(e,e.cloud.options,e.cloud.schema,{justCheckIfNeeded:!0})]:[3,2];case 1:return t=r.sent(),[3,3];case 2:t=!1,r.label=3;case 3:return[2,t]}}))}))}var fr=On(16);function dr(e,t,r,o,i){var s=(void 0===i?{}:i).awaitRemoteJob;return _(this,void 0,void 0,(function(){function i(){return _(this,void 0,void 0,(function(){var o,c,l=this;return w(this,(function(f){switch(f.label){case 0:return[4,e.transaction("rw!",r,(function(){return _(l,void 0,void 0,(function(){var e;return w(this,(function(n){switch(n.label){case 0:return[4,a.get(t)];case 1:return(e=n.sent())?[3,3]:[4,a.add({nodeId:fr,started:new Date,heartbeat:new Date},t)];case 2:case 4:return n.sent(),[2,!0];case 3:return e.heartbeat.getTime()<Date.now()-6e4?(console.warn("Latest ".concat(t," worker seem to have died.\n"),"The dead job started:",e.started,"\n","Last heart beat was:",e.heartbeat,"\n","We're now taking over!"),[4,a.put({nodeId:fr,started:new Date,heartbeat:new Date},t)]):[3,5];case 5:return[2,!1]}}))}))}))];case 1:if(f.sent())return[2,!0];if(!s)return[3,6];f.label=2;case 2:return f.trys.push([2,4,,6]),o=u(n((function(){return a.get(t)}))).pipe(function(e,n){var t=Ae(e)?{first:e}:"number"==typeof e?{each:e}:e,r=t.first,o=t.each,i=t.with,s=void 0===i?Qe:i,u=t.scheduler,a=void 0===u?null!=n?n:Ie:u,c=t.meta,l=void 0===c?null:c;if(null==r&&null==o)throw new TypeError("No timeout provided.");return U((function(e,n){var t,i,u=null,c=0,f=function(e){i=Pe(n,a,(function(){try{t.unsubscribe(),ye(s({meta:l,lastValue:u,seen:c})).subscribe(n)}catch(e){n.error(e)}}),e)};t=e.subscribe(new ge(n,(function(e){null==i||i.unsubscribe(),c++,n.next(u=e),o>0&&f(o)}),void 0,void 0,(function(){(null==i?void 0:i.closed)||null==i||i.unsubscribe(),u=null}))),f(null!=r?"number"==typeof r?r:+r-a.now():o)}))}(6e4),ze((function(e){return!e}))),[4,o.toPromise()];case 3:return f.sent(),[2,!1];case 4:if("TimeoutError"!==(c=f.sent()).name)throw c;return[4,i()];case 5:return[2,f.sent()];case 6:return[2,!1]}}))}))}var a,c,l=this;return w(this,(function(n){switch(n.label){case 0:return a=e.table(r),[4,i()];case 1:if(!n.sent())return[3,6];c=setInterval((function(){a.update(t,(function(e){e.nodeId===fr&&(e.heartbeat=new Date)}))}),1e3),n.label=2;case 2:return n.trys.push([2,,4,6]),[4,o()];case 3:return[2,n.sent()];case 4:return clearInterval(c),[4,e.transaction("rw!",r,(function(){return _(l,void 0,void 0,(function(){var e;return w(this,(function(n){switch(n.label){case 0:return[4,a.get(t)];case 1:return(e=n.sent())&&e.nodeId===fr?[4,a.delete(t)]:[3,3];case 2:n.sent(),n.label=3;case 3:return[2]}}))}))}))];case 5:return n.sent(),[7];case 6:return[2]}}))}))}var hr=new WeakMap;function vr(e,n,t,r){var o=hr.get(e);if(o){if(o.pull||"push"===(null==r?void 0:r.purpose))return console.debug("syncIfPossible(): returning the ongoing sync promise."),o.promise;var i=!1,s=e.cloud.syncState.subscribe((function(e){"pulling"===e.phase&&(i=!0)}));return o.promise.then((function(){s.unsubscribe()})).catch((function(e){return s.unsubscribe(),Promise.reject(e)})).then((function(){if(!i)return vr(e,n,t,r)}))}var u=function(){return _(this,void 0,void 0,(function(){var o;return w(this,(function(i){switch(i.label){case 0:return i.trys.push([0,6,,7]),e.cloud.usingServiceWorker?jt?[4,kt(e,n,t,r)]:[3,2]:[3,3];case 1:i.sent(),i.label=2;case 2:return[3,5];case 3:return[4,dr(e,"currentSyncWorker","$jobs",(function(){return kt(e,n,t,r)}))];case 4:i.sent(),i.label=5;case 5:return hr.delete(e),console.debug("Done sync"),[3,7];case 6:throw o=i.sent(),hr.delete(e),console.error("Failed to sync client changes",o),o;case 7:return[2]}}))}))}();return hr.set(e,{promise:u,pull:"push"!==(null==r?void 0:r.purpose)}),u}function pr(e,n,t){var r=null,o={cancelled:!1};function i(r,u){void 0===u&&(u=1),setTimeout((function(){vr(e,n,t,{cancelToken:o,retryImmediatelyOnFetchError:!0,purpose:r}).catch((function(e){console.error("error in syncIfPossible()",e),o.cancelled?s():u<3&&setTimeout((function(){return i(r,u+1)}),6e4*[0,5,15][u])}))}),0)}var s=function(){console.debug("Stopping LocalSyncWorker"),o.cancelled=!0,r&&r.unsubscribe()};return{start:function(){console.debug("Starting LocalSyncWorker",e.localSyncEvent.id),r=e.localSyncEvent.subscribe((function(e){var n=e.purpose;try{i(n||"pull")}catch(e){console.error("What-the....",e)}}))},stop:s}}function br(e,n){if(e&&n&&n.unsyncedTables)for(var t=0,r=n.unsyncedTables;t<r.length;t++){var o=r[t];e[o]&&(e[o].markedForSync=!1)}}var yr,mr,gr,_r,wr={},Sr=[],kr=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;function xr(e,n){for(var t in n)e[t]=n[t];return e}function Ir(e){var n=e.parentNode;n&&n.removeChild(e)}function Er(e,n,t){var r,o,i,s=arguments,u={};for(i in n)"key"==i?r=n[i]:"ref"==i?o=n[i]:u[i]=n[i];if(arguments.length>3)for(t=[t],i=3;i<arguments.length;i++)t.push(s[i]);if(null!=t&&(u.children=t),"function"==typeof e&&null!=e.defaultProps)for(i in e.defaultProps)void 0===u[i]&&(u[i]=e.defaultProps[i]);return Tr(e,u,r,o,null)}function Tr(e,n,t,r,o){var i={type:e,props:n,key:t,ref:r,__k:null,__:null,__b:0,__e:null,__d:void 0,__c:null,__h:null,constructor:void 0,__v:null==o?++yr.__v:o};return null!=yr.vnode&&yr.vnode(i),i}function Ar(e){return e.children}function Cr(e,n){this.props=e,this.context=n}function Pr(e,n){if(null==n)return e.__?Pr(e.__,e.__.__k.indexOf(e)+1):null;for(var t;n<e.__k.length;n++)if(null!=(t=e.__k[n])&&null!=t.__e)return t.__e;return"function"==typeof e.type?Pr(e):null}function Ur(e){var n,t;if(null!=(e=e.__)&&null!=e.__c){for(e.__e=e.__c.base=null,n=0;n<e.__k.length;n++)if(null!=(t=e.__k[n])&&null!=t.__e){e.__e=e.__c.base=t.__e;break}return Ur(e)}}function Or(e){(!e.__d&&(e.__d=!0)&&mr.push(e)&&!Dr.__r++||_r!==yr.debounceRendering)&&((_r=yr.debounceRendering)||gr)(Dr)}function Dr(){for(var e;Dr.__r=mr.length;)e=mr.sort((function(e,n){return e.__v.__b-n.__v.__b})),mr=[],e.some((function(e){var n,t,r,o,i,s;e.__d&&(i=(o=(n=e).__v).__e,(s=n.__P)&&(t=[],(r=xr({},o)).__v=o.__v+1,Mr(s,o,r,n.__n,void 0!==s.ownerSVGElement,null!=o.__h?[i]:null,t,null==i?Pr(o):i,o.__h),Fr(t,o),o.__e!=i&&Ur(o)))}))}function Rr(e,n,t,r,o,i,s,u,a,c){var l,f,d,h,v,p,b,y=r&&r.__k||Sr,m=y.length;for(t.__k=[],l=0;l<n.length;l++)if(null!=(h=t.__k[l]=null==(h=n[l])||"boolean"==typeof h?null:"string"==typeof h||"number"==typeof h||"bigint"==typeof h?Tr(null,h,null,null,h):Array.isArray(h)?Tr(Ar,{children:h},null,null,null):h.__b>0?Tr(h.type,h.props,h.key,null,h.__v):h)){if(h.__=t,h.__b=t.__b+1,null===(d=y[l])||d&&h.key==d.key&&h.type===d.type)y[l]=void 0;else for(f=0;f<m;f++){if((d=y[f])&&h.key==d.key&&h.type===d.type){y[f]=void 0;break}d=null}Mr(e,h,d=d||wr,o,i,s,u,a,c),v=h.__e,(f=h.ref)&&d.ref!=f&&(b||(b=[]),d.ref&&b.push(d.ref,null,h),b.push(f,h.__c||v,h)),null!=v?(null==p&&(p=v),"function"==typeof h.type&&null!=h.__k&&h.__k===d.__k?h.__d=a=jr(h,a,e):a=Lr(e,h,d,y,v,a),c||"option"!==t.type?"function"==typeof t.type&&(t.__d=a):e.value=""):a&&d.__e==a&&a.parentNode!=e&&(a=Pr(d))}for(t.__e=p,l=m;l--;)null!=y[l]&&("function"==typeof t.type&&null!=y[l].__e&&y[l].__e==t.__d&&(t.__d=Pr(r,l+1)),qr(y[l],y[l]));if(b)for(l=0;l<b.length;l++)Hr(b[l],b[++l],b[++l])}function jr(e,n,t){var r,o;for(r=0;r<e.__k.length;r++)(o=e.__k[r])&&(o.__=e,n="function"==typeof o.type?jr(o,n,t):Lr(t,o,o,e.__k,o.__e,n));return n}function Lr(e,n,t,r,o,i){var s,u,a;if(void 0!==n.__d)s=n.__d,n.__d=void 0;else if(null==t||o!=i||null==o.parentNode)e:if(null==i||i.parentNode!==e)e.appendChild(o),s=null;else{for(u=i,a=0;(u=u.nextSibling)&&a<r.length;a+=2)if(u==o)break e;e.insertBefore(o,i),s=i}return void 0!==s?s:o.nextSibling}function Nr(e,n,t){"-"===n[0]?e.setProperty(n,t):e[n]=null==t?"":"number"!=typeof t||kr.test(n)?t:t+"px"}function $r(e,n,t,r,o){var i;e:if("style"===n)if("string"==typeof t)e.style.cssText=t;else{if("string"==typeof r&&(e.style.cssText=r=""),r)for(n in r)t&&n in t||Nr(e.style,n,"");if(t)for(n in t)r&&t[n]===r[n]||Nr(e.style,n,t[n])}else if("o"===n[0]&&"n"===n[1])i=n!==(n=n.replace(/Capture$/,"")),n=n.toLowerCase()in e?n.toLowerCase().slice(2):n.slice(2),e.l||(e.l={}),e.l[n+i]=t,t?r||e.addEventListener(n,i?Br:Wr,i):e.removeEventListener(n,i?Br:Wr,i);else if("dangerouslySetInnerHTML"!==n){if(o)n=n.replace(/xlink[H:h]/,"h").replace(/sName$/,"s");else if("href"!==n&&"list"!==n&&"form"!==n&&"tabIndex"!==n&&"download"!==n&&n in e)try{e[n]=null==t?"":t;break e}catch(e){}"function"==typeof t||(null!=t&&(!1!==t||"a"===n[0]&&"r"===n[1])?e.setAttribute(n,t):e.removeAttribute(n))}}function Wr(e){this.l[e.type+!1](yr.event?yr.event(e):e)}function Br(e){this.l[e.type+!0](yr.event?yr.event(e):e)}function Mr(e,n,t,r,o,i,s,u,a){var c,l,f,d,h,v,p,b,y,m,g,_=n.type;if(void 0!==n.constructor)return null;null!=t.__h&&(a=t.__h,u=n.__e=t.__e,n.__h=null,i=[u]),(c=yr.__b)&&c(n);try{e:if("function"==typeof _){if(b=n.props,y=(c=_.contextType)&&r[c.__c],m=c?y?y.props.value:c.__:r,t.__c?p=(l=n.__c=t.__c).__=l.__E:("prototype"in _&&_.prototype.render?n.__c=l=new _(b,m):(n.__c=l=new Cr(b,m),l.constructor=_,l.render=Vr),y&&y.sub(l),l.props=b,l.state||(l.state={}),l.context=m,l.__n=r,f=l.__d=!0,l.__h=[]),null==l.__s&&(l.__s=l.state),null!=_.getDerivedStateFromProps&&(l.__s==l.state&&(l.__s=xr({},l.__s)),xr(l.__s,_.getDerivedStateFromProps(b,l.__s))),d=l.props,h=l.state,f)null==_.getDerivedStateFromProps&&null!=l.componentWillMount&&l.componentWillMount(),null!=l.componentDidMount&&l.__h.push(l.componentDidMount);else{if(null==_.getDerivedStateFromProps&&b!==d&&null!=l.componentWillReceiveProps&&l.componentWillReceiveProps(b,m),!l.__e&&null!=l.shouldComponentUpdate&&!1===l.shouldComponentUpdate(b,l.__s,m)||n.__v===t.__v){l.props=b,l.state=l.__s,n.__v!==t.__v&&(l.__d=!1),l.__v=n,n.__e=t.__e,n.__k=t.__k,n.__k.forEach((function(e){e&&(e.__=n)})),l.__h.length&&s.push(l);break e}null!=l.componentWillUpdate&&l.componentWillUpdate(b,l.__s,m),null!=l.componentDidUpdate&&l.__h.push((function(){l.componentDidUpdate(d,h,v)}))}l.context=m,l.props=b,l.state=l.__s,(c=yr.__r)&&c(n),l.__d=!1,l.__v=n,l.__P=e,c=l.render(l.props,l.state,l.context),l.state=l.__s,null!=l.getChildContext&&(r=xr(xr({},r),l.getChildContext())),f||null==l.getSnapshotBeforeUpdate||(v=l.getSnapshotBeforeUpdate(d,h)),g=null!=c&&c.type===Ar&&null==c.key?c.props.children:c,Rr(e,Array.isArray(g)?g:[g],n,t,r,o,i,s,u,a),l.base=n.__e,n.__h=null,l.__h.length&&s.push(l),p&&(l.__E=l.__=null),l.__e=!1}else null==i&&n.__v===t.__v?(n.__k=t.__k,n.__e=t.__e):n.__e=Kr(t.__e,n,t,r,o,i,s,a);(c=yr.diffed)&&c(n)}catch(e){n.__v=null,(a||null!=i)&&(n.__e=u,n.__h=!!a,i[i.indexOf(u)]=null),yr.__e(e,n,t)}}function Fr(e,n){yr.__c&&yr.__c(n,e),e.some((function(n){try{e=n.__h,n.__h=[],e.some((function(e){e.call(n)}))}catch(e){yr.__e(e,n.__v)}}))}function Kr(e,n,t,r,o,i,s,u){var a,c,l,f,d=t.props,h=n.props,v=n.type,p=0;if("svg"===v&&(o=!0),null!=i)for(;p<i.length;p++)if((a=i[p])&&(a===e||(v?a.localName==v:3==a.nodeType))){e=a,i[p]=null;break}if(null==e){if(null===v)return document.createTextNode(h);e=o?document.createElementNS("http://www.w3.org/2000/svg",v):document.createElement(v,h.is&&h),i=null,u=!1}if(null===v)d===h||u&&e.data===h||(e.data=h);else{if(i=i&&Sr.slice.call(e.childNodes),c=(d=t.props||wr).dangerouslySetInnerHTML,l=h.dangerouslySetInnerHTML,!u){if(null!=i)for(d={},f=0;f<e.attributes.length;f++)d[e.attributes[f].name]=e.attributes[f].value;(l||c)&&(l&&(c&&l.__html==c.__html||l.__html===e.innerHTML)||(e.innerHTML=l&&l.__html||""))}if(function(e,n,t,r,o){var i;for(i in t)"children"===i||"key"===i||i in n||$r(e,i,null,t[i],r);for(i in n)o&&"function"!=typeof n[i]||"children"===i||"key"===i||"value"===i||"checked"===i||t[i]===n[i]||$r(e,i,n[i],t[i],r)}(e,h,d,o,u),l)n.__k=[];else if(p=n.props.children,Rr(e,Array.isArray(p)?p:[p],n,t,r,o&&"foreignObject"!==v,i,s,e.firstChild,u),null!=i)for(p=i.length;p--;)null!=i[p]&&Ir(i[p]);u||("value"in h&&void 0!==(p=h.value)&&(p!==e.value||"progress"===v&&!p)&&$r(e,"value",p,d.value,!1),"checked"in h&&void 0!==(p=h.checked)&&p!==e.checked&&$r(e,"checked",p,d.checked,!1))}return e}function Hr(e,n,t){try{"function"==typeof e?e(n):e.current=n}catch(e){yr.__e(e,t)}}function qr(e,n,t){var r,o,i;if(yr.unmount&&yr.unmount(e),(r=e.ref)&&(r.current&&r.current!==e.__e||Hr(r,null,n)),t||"function"==typeof e.type||(t=null!=(o=e.__e)),e.__e=e.__d=void 0,null!=(r=e.__c)){if(r.componentWillUnmount)try{r.componentWillUnmount()}catch(e){yr.__e(e,n)}r.base=r.__P=null}if(r=e.__k)for(i=0;i<r.length;i++)r[i]&&qr(r[i],n,t);null!=o&&Ir(o)}function Vr(e,n,t){return this.constructor(e,t)}yr={__e:function(e,n){for(var t,r,o;n=n.__;)if((t=n.__c)&&!t.__)try{if((r=t.constructor)&&null!=r.getDerivedStateFromError&&(t.setState(r.getDerivedStateFromError(e)),o=t.__d),null!=t.componentDidCatch&&(t.componentDidCatch(e),o=t.__d),o)return t.__E=t}catch(n){e=n}throw e},__v:0},Cr.prototype.setState=function(e,n){var t;t=null!=this.__s&&this.__s!==this.state?this.__s:this.__s=xr({},this.state),"function"==typeof e&&(e=e(xr({},t),this.props)),e&&xr(t,e),null!=e&&this.__v&&(n&&this.__h.push(n),Or(this))},Cr.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),Or(this))},Cr.prototype.render=Ar,mr=[],gr="function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout,Dr.__r=0;var zr={Error:{color:"red"},Alert:{error:{color:"red"},warning:{color:"yellow"},info:{color:"black"}},Darken:{position:"fixed",top:0,left:0,opacity:.5,backgroundColor:"#000",width:"100vw",height:"100vh",zIndex:150,webkitBackdropFilter:"blur(2px)",backdropFilter:"blur(2px)"},DialogOuter:{position:"fixed",top:0,left:0,width:"100vw",height:"100vh",zIndex:150,alignItems:"center",display:"flex",justifyContent:"center"},DialogInner:{position:"relative",color:"#222",backgroundColor:"#fff",padding:"30px",marginBottom:"2em",maxWidth:"90%",maxHeight:"90%",overflowY:"auto",border:"3px solid #3d3d5d",borderRadius:"8px",boxShadow:"0 0 80px 10px #666",width:"auto"},Input:{height:"35px",width:"17em",borderColor:"#ccf4",outline:"none",fontSize:"17pt",padding:"8px"}};function Gr(e){var n=e.children;return Er("div",null,Er("div",{style:zr.Darken}),Er("div",{style:zr.DialogOuter},Er("div",{style:zr.DialogInner},n)))}var Jr,Yr,Zr,Xr=0,Qr=[],eo=yr.__b,no=yr.__r,to=yr.diffed,ro=yr.__c,oo=yr.unmount;function io(e,n){yr.__h&&yr.__h(Yr,e,Xr||n),Xr=0;var t=Yr.__H||(Yr.__H={__:[],__h:[]});return e>=t.__.length&&t.__.push({}),t.__[e]}function so(e){return Xr=1,function(e,n,t){var r=io(Jr++,2);return r.t=e,r.__c||(r.__=[t?t(n):vo(void 0,n),function(e){var n=r.t(r.__[0],e);r.__[0]!==n&&(r.__=[n,r.__[1]],r.__c.setState({}))}],r.__c=Yr),r.__}(vo,e)}function uo(e){return Xr=5,function(e,n){var t=io(Jr++,7);return ho(t.__H,n)&&(t.__=e(),t.__H=n,t.__h=e),t.__}((function(){return{current:e}}),[])}function ao(){Qr.forEach((function(e){if(e.__P)try{e.__H.__h.forEach(lo),e.__H.__h.forEach(fo),e.__H.__h=[]}catch(n){e.__H.__h=[],yr.__e(n,e.__v)}})),Qr=[]}yr.__b=function(e){Yr=null,eo&&eo(e)},yr.__r=function(e){no&&no(e),Jr=0;var n=(Yr=e.__c).__H;n&&(n.__h.forEach(lo),n.__h.forEach(fo),n.__h=[])},yr.diffed=function(e){to&&to(e);var n=e.__c;n&&n.__H&&n.__H.__h.length&&(1!==Qr.push(n)&&Zr===yr.requestAnimationFrame||((Zr=yr.requestAnimationFrame)||function(e){var n,t=function(){clearTimeout(r),co&&cancelAnimationFrame(n),setTimeout(e)},r=setTimeout(t,100);co&&(n=requestAnimationFrame(t))})(ao)),Yr=void 0},yr.__c=function(e,n){n.some((function(e){try{e.__h.forEach(lo),e.__h=e.__h.filter((function(e){return!e.__||fo(e)}))}catch(t){n.some((function(e){e.__h&&(e.__h=[])})),n=[],yr.__e(t,e.__v)}})),ro&&ro(e,n)},yr.unmount=function(e){oo&&oo(e);var n=e.__c;if(n&&n.__H)try{n.__H.__.forEach(lo)}catch(e){yr.__e(e,n.__v)}};var co="function"==typeof requestAnimationFrame;function lo(e){var n=Yr;"function"==typeof e.__c&&e.__c(),Yr=n}function fo(e){var n=Yr;e.__c=e.__(),Yr=n}function ho(e,n){return!e||e.length!==n.length||n.some((function(n,t){return n!==e[t]}))}function vo(e,n){return"function"==typeof n?n(e):n}function po(e){var n=e.title,t=e.alerts,r=e.fields,o=e.onCancel,i=e.onSubmit,s=so({}),u=s[0],a=s[1],c=uo();return function(e,n){var t=io(Jr++,4);!yr.__s&&ho(t.__H,n)&&(t.__=e,t.__H=n,Yr.__h.push(t))}((function(){var e;return null===(e=c.current)||void 0===e?void 0:e.focus()}),[]),Er(Gr,null,Er(Ar,null,Er("h3",{style:zr.WindowHeader},n),t.map((function(e){return Er("p",{style:zr.Alert[e.type]},function(e){var n=e.message;e.messageCode;var t=e.messageParams;return n.replace(/\{\w+\}/gi,(function(e){return t[e.substr(1,e.length-2)]}))}(e))})),Er("form",{onSubmit:function(e){e.preventDefault(),i(u)}},Object.entries(r).map((function(e,n){var t=e[0],r=e[1],o=r.type,i=r.label,s=r.placeholder;return Er("label",{style:zr.Label},i?"".concat(i,": "):"",Er("input",{ref:0===n?c:void 0,type:o,name:t,autoComplete:"on",style:zr.Input,autoFocus:!0,placeholder:s,value:u[t]||"",onInput:function(e){var n,r;return a(g(g({},u),((n={})[t]=function(e,n){switch(e){case"email":return n.toLowerCase();case"otp":return n.toUpperCase();default:return n}}(o,null===(r=e.target)||void 0===r?void 0:r.value),n)))}}))})))),Er("div",{style:zr.ButtonsDiv},Er("button",{type:"submit",style:zr.Button,onClick:function(){return i(u)}},"Submit"),Er("button",{style:zr.Button,onClick:o},"Cancel")))}var bo=function(e){function n(n){var t=e.call(this,n)||this;return t.observer=function(e){return t.setState({userInteraction:e})},t.state={userInteraction:void 0},t}return m(n,e),n.prototype.componentDidMount=function(){this.subscription=u(this.props.db.cloud.userInteraction).subscribe(this.observer)},n.prototype.componentWillUnmount=function(){this.subscription&&(this.subscription.unsubscribe(),delete this.subscription)},n.prototype.render=function(e,n){var t=n.userInteraction;return t?Er(po,g({},t)):null},n}(Cr);function yo(e){var n=document.createElement("div");document.body.appendChild(n),function(e,n,t){var r,o,i;yr.__&&yr.__(e,n),o=(r="function"==typeof t)?null:t&&t.__k||n.__k,i=[],Mr(n,e=(!r&&t||n).__k=Er(Ar,null,[e]),o||wr,wr,void 0!==n.ownerSVGElement,!r&&t?[t]:o?null:n.firstChild?Sr.slice.call(n.childNodes):null,i,!r&&t?t:o?o.__e:n.firstChild,r),Fr(i,e)}(Er(bo,{db:e.vip}),n);var t=!1;return{unsubscribe:function(){n.remove(),t=!0},get closed(){return t}}}function mo(e){var n=new WeakMap;return function(t){var r=n.get(t);return r||(r=e(t),n.set(t,r)),r}}function go(e,n){var t=n,r=u(e).pipe(h((function(e){return t=e})),p({resetOnRefCountZero:function(){return b(1e3)}})),o=new a((function(e){var n=!1,o=r.subscribe({next:function(t){n=!0,e.next(t)},error:function(n){e.error(n)},complete:function(){e.complete()}});return n||o.closed||e.next(t),o}));return o.getValue=function(){return t},o}var _o=mo((function(e){return go(n((function(){return e.roles.where({realmId:"rlm-public"}).toArray().then((function(e){for(var n={},t=0,r=e.slice().sort((function(e,n){return(e.sortOrder||0)-(n.sortOrder||0)}));t<r.length;t++){var o=r[t];n[o.name]=o}return n}))})),{})})),wo=mo((function(e){return new r(_n)})),So=mo((function(e){return go(wo(e._novip).pipe(Ye((function(t){return n((function(){return e.transaction("r","realms","members",(function(){return Promise.all([e.members.where({userId:t.userId}).toArray(),e.realms.toArray(),t.userId]).then((function(e){return{selfMembers:e[0],realms:e[1],userId:e[2]}}))}))}))}))),{selfMembers:[],realms:[],get userId(){return e.cloud.currentUserId}})}));function ko(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];if(0===e.length)return{};var t=e.reduce((function(e,n){for(var t=g({},e),r=0,o=Object.entries(n);r<o.length;r++){var i=o[r],s=i[0],u=i[1];if(s in t&&t[s]){if("*"===t[s])continue;if("*"===u)t[s]="*";else if(Array.isArray(u)&&Array.isArray(t[s])){var a=t,c=a[s];a[s]=S([],new Set(S(S([],c,!0),u,!0)),!0)}else if("object"==typeof u&&u&&"object"==typeof t[s])for(var l=t[s],f=0,d=Object.entries(u);f<d.length;f++){var h=d[f],v=h[0],p=h[1];"*"!==l[v]&&("*"===p?l[v]="*":Array.isArray(l[v])&&Array.isArray(p)&&(l[v]=S([],new Set(S(S([],l[v],!0),p,!0)),!0)))}}else t[s]=n[s]}return t}));return t}var xo=mo((function(e){var n=go(d([So(e._novip),_o(e._novip)]).pipe(Ne((function(e){var n=e[0];return{selfMembers:n.selfMembers,realms:n.realms,userId:n.userId,globalRoles:e[1]}}))),{selfMembers:[],realms:[],userId:_n.userId,globalRoles:{}});return function(e,n){var t,r=e.pipe(h((function(e){return t=n(e)})));return r.getValue=function(){return void 0!==t?t:t=n(e.getValue())},r}(n,(function(e){var n,t=e.selfMembers,r=e.realms,o=e.userId,i=e.globalRoles,s=r.map((function(e){var n=t.filter((function(n){return n.realmId===e.realmId})),r=n.map((function(e){return e.permissions})).filter((function(e){return e})),s=Pn(n.map((function(e){return e.roles})).filter((function(e){return e}))).map((function(e){return i[e]})).filter((function(e){return e})).map((function(e){return e.permissions}));return g(g({},e),{permissions:e.owner===o?{manage:"*"}:ko.apply(void 0,S(S([],r,!1),s,!1))})})).reduce((function(e,n){var t;return g(g({},e),((t={})[n.realmId]=n,t))}),((n={})[o]={realmId:o,owner:o,name:o,permissions:{manage:"*"}},n));return s}))})),Io=function(){function e(e,n,t){this.permissions=e||{},this.tableName=n,this.isOwner=t}return e.prototype.add=function(){for(var e,n=this,t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return"*"===this.permissions.manage||(!!(null===(e=this.permissions.manage)||void 0===e?void 0:e.includes(this.tableName))||("*"===this.permissions.add||!!t.every((function(e){var t;return null===(t=n.permissions.add)||void 0===t?void 0:t.includes(e)}))))},e.prototype.update=function(){for(var e,n,t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];if(this.isOwner||"*"===this.permissions.manage)return!0;if(null===(e=this.permissions.manage)||void 0===e?void 0:e.includes(this.tableName))return!0;if("*"===this.permissions.update)return t.every((function(e){return"owner"!==e}));var o=null===(n=this.permissions.update)||void 0===n?void 0:n[this.tableName];return"*"===o?t.every((function(e){return"owner"!==e})):t.every((function(e){return null==o?void 0:o.some((function(n){return n===e||"*"===n&&"owner"!==e}))}))},e.prototype.delete=function(){var e;return!(!this.isOwner&&"*"!==this.permissions.manage)||!!(null===(e=this.permissions.manage)||void 0===e?void 0:e.includes(this.tableName))},e}();var Eo=mo((function(e){var t=wo(e._novip).pipe(f((function(t){return n((function(){return e.members.where({email:t.email||""}).toArray()}))}))),r=xo(e._novip),o=So(e._novip);return go(d([t,o,r]).pipe(h((function(e){var n=e[0],t=e[1],r=e[2],o=function(e,n){var t;return g(g({},e),((t={})[n.id]=g(g({},n),{realm:r[n.realmId]}),t))},i=n.reduce(o,{}),s=t.selfMembers.reduce(o,i);return Object.values(s).filter((function(e){return!e.accepted}))}))),[])}));function To(e){return"rlm~"+e}function Ao(e){return e.startsWith("rlm~")?e.substr(4):null}var Co={nameSuffix:!0};function Po(t){var s=this,a=t.name,c=wo(t),l=[],f=!1,h=null;t.on("ready",(function(e){return _(s,void 0,void 0,(function(){var n;return w(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,y(e)];case 1:return t.sent(),[3,3];case 2:return n=t.sent(),console.error(n),[3,3];case 3:return[2]}}))}))}),!0);var v,p=!1;function b(){if(p)throw new e.DatabaseClosedError}function y(t){var r,s,u,a,v,y;return _(this,void 0,void 0,(function(){var m,S,k,x,I=this;return w(this,(function(E){switch(E.label){case 0:return p=!1,m=Pt(t),jt||((null===(r=m.cloud.options)||void 0===r?void 0:r.customLoginGui)||l.push(yo(t)),l.push(function(e){var n=e.cloud.webSocketStatus.value,t=e.cloud.webSocketStatus.pipe(Ye((function(e){var t=n;n=e;var r=i(e);switch(e){case"disconnected":return Qt.value?r.pipe(Be(500)):r;case"connecting":return"not-started"===t||"error"===t?r:r.pipe(Be(4e3));default:return r}})));return d([t,e.syncStateChangedEvent.pipe(Je({phase:"initial"})),er]).pipe(Ne((function(n){var t=n[0],r=n[1],o=n[2],i=r.phase,s=r.error,u=r.progress,a=t;return"error"===i&&(a="error"),"not-started"===t&&("pushing"!==i&&"pulling"!==i||(a="connecting")),"error"!==e.cloud.syncState.value.phase||"pushing"!==r.phase&&"pulling"!==r.phase||(a="connecting"),o||(a="disconnected"),{phase:i,error:s,progress:u,status:mt?a:"offline"}})))}(m).subscribe(t.cloud.syncState))),m.tables.every((function(e){return e.core}))||Lt(),"serviceWorker"in navigator?[4,navigator.serviceWorker.getRegistrations()]:[3,2];case 1:return k=E.sent(),[3,3];case 2:k=[],E.label=3;case 3:return S=k,[4,m.transaction("rw",m.$syncState,(function(){return _(I,void 0,void 0,(function(){var e,n,t,r,o,i,s,u,a,c,l,d,h,v,p,b;return w(this,(function(y){switch(y.label){case 0:return e=m.cloud,n=e.options,t=e.schema,[4,Promise.all([m.getOptions(),m.getSchema(),m.getPersistedSyncState()])];case 1:return r=y.sent(),o=r[0],i=r[1],s=r[2],f?[3,2]:(m.cloud.options=o||null,[3,4]);case 2:if(o&&JSON.stringify(o)===JSON.stringify(n))return[3,4];if(!n)throw new Error("Internal error");return[4,m.$syncState.put(n,"options")];case 3:y.sent(),y.label=4;case 4:return(null===(p=m.cloud.options)||void 0===p?void 0:p.tryUseServiceWorker)&&"serviceWorker"in navigator&&S.length>0&&!Rt?(console.debug("Dexie Cloud Addon: Using service worker"),m.cloud.usingServiceWorker=!0):((null===(b=m.cloud.options)||void 0===b?void 0:b.tryUseServiceWorker)&&!jt&&console.debug("dexie-cloud-addon: Not using service worker.",0===S.length?"No SW registrations found.":"serviceWorker"in navigator&&Rt?"Avoiding SW background sync and SW periodic bg sync for this browser due to browser bugs.":"navigator.serviceWorker not present"),m.cloud.usingServiceWorker=!1),br(t,m.cloud.options),br(i,m.cloud.options),t?[3,5]:(m.cloud.schema=i||null,[3,7]);case 5:if(i&&JSON.stringify(i)===JSON.stringify(t))return[3,7];for(u=i||{},a=0,c=Object.entries(t);a<c.length;a++)l=c[a],d=l[0],h=l[1],(v=u[d])?(v.markedForSync=h.markedForSync,h.deleted=v.deleted,v.generatedGlobalId=h.generatedGlobalId):u[d]=g({},h);return[4,m.$syncState.put(u,"schema")];case 6:y.sent(),Object.assign(t,u),y.label=7;case 7:return[2,null==s?void 0:s.initiallySynced]}}))}))}))];case 4:return(x=E.sent())&&m.setInitiallySynced(!0),function(n){for(var t,r,o=0,i=n.tables;o<i.length;o++){var s=i[o];if(null===(r=null===(t=n.cloud.schema)||void 0===t?void 0:t[s.name])||void 0===r?void 0:r.markedForSync){if(s.schema.primKey.auto)throw new e.SchemaError("Table ".concat(s.name," is both autoIncremented and synced. ")+"Use db.cloud.configure({unsyncedTables: [".concat(JSON.stringify(s.name),"]}) to blacklist it from sync"));if(!s.schema.primKey.keyPath)throw new e.SchemaError("Table ".concat(s.name," cannot be both synced and outbound. ")+"Use db.cloud.configure({unsyncedTables: [".concat(JSON.stringify(s.name),"]}) to blacklist it from sync"))}}}(m),!(null===(s=m.cloud.options)||void 0===s?void 0:s.databaseUrl)||x?[3,6]:[4,Yt(m,m.cloud.options,m.cloud.schema)];case 5:E.sent(),m.setInitiallySynced(!0),E.label=6;case 6:return b(),jt?[3,8]:(l.push(n((function(){return m.getCurrentUser()})).subscribe(c)),l.push(n((function(){return m.getPersistedSyncState()})).subscribe(m.cloud.persistedSyncState)),[4,d([c.pipe(Ge(1),Ke(1)),m.cloud.persistedSyncState.pipe(Ge(1),Ke(1))]).toPromise()]);case 7:E.sent(),E.label=8;case 8:return(null===(u=m.cloud.options)||void 0===u?void 0:u.requireAuth)?[4,gn(m)]:[3,10];case 9:E.sent(),E.label=10;case 10:return h&&h.stop(),h=null,b(),m.cloud.usingServiceWorker&&(null===(a=m.cloud.options)||void 0===a?void 0:a.databaseUrl)?(nn(m,"push").catch((function(){})),function(e){var n;return _(this,void 0,void 0,(function(){var t,r,o;return w(this,(function(i){switch(i.label){case 0:return i.trys.push([0,8,,9]),[4,navigator.serviceWorker.ready];case 1:if(!(t=i.sent().periodicSync))return[3,6];i.label=2;case 2:return i.trys.push([2,4,,5]),[4,t.register("dexie-cloud:".concat(e.name),null===(n=e.cloud.options)||void 0===n?void 0:n.periodicSync)];case 3:return i.sent(),console.debug("Dexie Cloud: Successfully registered periodicsync event for ".concat(e.name)),[3,5];case 4:return r=i.sent(),console.debug("Dexie Cloud: Failed to register periodic sync. Your PWA must be installed to allow background sync.",r),[3,5];case 5:return[3,7];case 6:console.debug("Dexie Cloud: periodicSync not supported."),i.label=7;case 7:return[3,9];case 8:return o=i.sent(),console.debug("Dexie Cloud: Could not register periodicSync for ".concat(e.name),o),[3,9];case 9:return[2]}}))}))}(m).catch((function(){}))):(null===(v=m.cloud.options)||void 0===v?void 0:v.databaseUrl)&&m.cloud.schema&&!jt&&((h=pr(m,m.cloud.options,m.cloud.schema)).start(),tn(m,"push")),b(),jt||l.push(o(self,"online").subscribe((function(){console.debug("online!"),m.syncStateChangedEvent.next({phase:"not-in-sync"}),tn(m,"push")})),o(self,"offline").subscribe((function(){console.debug("offline!"),m.syncStateChangedEvent.next({phase:"offline"})}))),"undefined"!=typeof window&&!jt&&(null===(y=m.cloud.options)||void 0===y?void 0:y.databaseUrl)&&l.push(cr(m)),[2]}}))}))}!function(e,n){e.on.close.subscribe(n);var t=e.close;e.close=function(){t.call(this),n()}}(t,(function(){l.forEach((function(e){return e.unsubscribe()})),p=!0,h&&h.stop(),h=null,c.next(_n)})),t.cloud={version:"4.0.0-beta.17",options:g({},Co),schema:null,serverState:null,get currentUserId(){return c.value.userId||_n.userId},currentUser:c,syncState:new r({phase:"initial",status:"not-started"}),persistedSyncState:new r(void 0),userInteraction:new r(void 0),webSocketStatus:new r("not-started"),login:function(e){return _(this,void 0,void 0,(function(){var n;return w(this,(function(r){switch(r.label){case 0:return[4,(n=Pt(t)).cloud.sync()];case 1:return r.sent(),[4,gn(n,e)];case 2:return r.sent(),[2]}}))}))},invites:Eo(t),roles:_o(t),configure:function(e){var n,r;e=t.cloud.options=g(g({},t.cloud.options),e),f=!0,e.databaseUrl&&e.nameSuffix&&(t.name="".concat(a,"-").concat((n=e.databaseUrl,"/"===(r=new URL(n)).pathname?r.hostname.split(".")[0]:r.pathname.split("/")[1])),Pt(t).reconfigure()),br(t.cloud.schema,t.cloud.options)},sync:function(e){var r=void 0===e?{wait:!0,purpose:"push"}:e,o=r.wait,i=r.purpose;return _(this,void 0,void 0,(function(){var e,r,s,a,c=this;return w(this,(function(l){switch(l.label){case 0:return void 0===o&&(o=!0),e=Pt(t),"pull"!==i?[3,3]:(r=e.cloud.persistedSyncState.value,tn(e,i),o?[4,e.cloud.persistedSyncState.pipe(ze((function(e){return null!=(null==e?void 0:e.timestamp)&&(!r||e.timestamp>r.timestamp)})),Ke(1)).toPromise()]:[3,2]);case 1:if(null==(s=l.sent())?void 0:s.error)throw new Error("Sync error: "+s.error);l.label=2;case 2:return[3,6];case 3:return[4,lr(e)];case 4:return l.sent()?(a=e.cloud.persistedSyncState.value,tn(e,i),o?(console.debug("db.cloud.login() is waiting for sync completion..."),[4,u(n((function(){return _(c,void 0,void 0,(function(){var n,t;return w(this,(function(r){switch(r.label){case 0:return[4,lr(e)];case 1:return n=r.sent(),[4,e.getPersistedSyncState()];case 2:if((null==(t=r.sent())?void 0:t.timestamp)!==(null==a?void 0:a.timestamp)&&(null==t?void 0:t.error))throw new Error("Sync error: "+t.error);return[2,n]}}))}))}))).pipe(ze((function(e){return!e})),Ke(1)).toPromise()]):[3,6]):[3,6];case 5:l.sent(),console.debug("Done waiting for sync completion because we have nothing to push anymore"),l.label=6;case 6:return[2]}}))}))},permissions:function(e,n){return function(e,n,t){if(!n)throw new TypeError("Cannot check permissions of undefined or null. A Dexie Cloud object with realmId and owner expected.");var r=n.owner,o=n.realmId;if(!t){if("function"!=typeof n.table)throw new TypeError("Missing 'table' argument to permissions and table could not be extracted from entity");t=n.table()}var i=xo(e),s=function(n){var i=n[o||e.cloud.currentUserId];return i?new Io(i.permissions,t,o===e.cloud.currentUserId||r===e.cloud.currentUserId):new Io({},t,!r||r===e.cloud.currentUserId)},u=i.pipe(Ne(s));return u.getValue=function(){return s(i.getValue())},u}(t._novip,e,n)}},t.Version.prototype._parseStoresSpec=e.override(t.Version.prototype._parseStoresSpec,(function(e){return Jt(e,t)})),t.Table.prototype.newId=function(e){var n=(void 0===e?{}:e).colocateWith,r=n&&n.substr(n.length-3);return Ft(t.cloud.schema[this.name].idPrefix||"",r)},t.Table.prototype.idPrefix=function(){var e,n;return(null===(n=null===(e=this.db.cloud.schema)||void 0===e?void 0:e[this.name])||void 0===n?void 0:n.idPrefix)||""},t.use(Gt({currentUserObservable:t.cloud.currentUser,db:Pt(t)})),t.use((v=Pt(t),{stack:"dbcore",name:"implicitPropSetterMiddleware",level:1,create:function(e){return g(g({},e),{table:function(n){var t=e.table(n);return g(g({},t),{mutate:function(e){var r,o,i,s;if(e.trans.disableChangeTracking)return t.mutate(e);var u=e.trans;if((null===(o=null===(r=v.cloud.schema)||void 0===r?void 0:r[n])||void 0===o?void 0:o.markedForSync)&&("add"===e.type||"put"===e.type))for(var a=0,c=e.values;a<c.length;a++){var l=c[a];l.owner||(l.owner=u.currentUser.userId),l.realmId||(l.realmId=u.currentUser.userId);var f=null===(s=(i=t.schema.primaryKey).extractKey)||void 0===s?void 0:s.call(i,l);"string"==typeof f&&"#"===f[0]&&"put"===e.type&&(delete e.criteria,delete e.changeSpec,delete e.changeSpecs,l.$ts=Date.now())}return t.mutate(e)}})}})}})),t.use(Kt(Pt(t)))}Po.version="4.0.0-beta.17",e.Cloud=Po;export{Po as default,Po as dexieCloud,Ao as getTiedObjectId,To as getTiedRealmId};
|
|
1
|
+
import e,{liveQuery as n,cmp as t}from"dexie";import{BehaviorSubject as r,fromEvent as o,of as i,merge as s,from as u,Observable as a,Subscription as c,Subject as l,switchMap as f,combineLatest as d,map as h,throwError as v,share as p,timer as b}from"rxjs";var y=function(e,n){return y=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])},y(e,n)};function m(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function t(){this.constructor=e}y(e,n),e.prototype=null===n?Object.create(n):(t.prototype=n.prototype,new t)}var g=function(){return g=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var o in n=arguments[t])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e},g.apply(this,arguments)};function _(e,n,t,r){return new(t||(t=Promise))((function(o,i){function s(e){try{a(r.next(e))}catch(e){i(e)}}function u(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(s,u)}a((r=r.apply(e,n||[])).next())}))}function w(e,n){var t,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(t)throw new TypeError("Generator is already executing.");for(;s;)try{if(t=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=n.call(e,s)}catch(e){i=[6,e],r=0}finally{t=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}}function S(e,n,t){if(t||2===arguments.length)for(var r,o=0,i=n.length;o<i;o++)!r&&o in n||(r||(r=Array.prototype.slice.call(n,0,o)),r[o]=n[o]);return e.concat(r||Array.prototype.slice.call(n))}function k(e,n,t,r){return new(t||(t=Promise))((function(o,i){function s(e){try{a(r.next(e))}catch(e){i(e)}}function u(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(s,u)}a((r=r.apply(e,n||[])).next())}))}var x=crypto.getRandomValues;function I(e,n,t){if(e&&void 0!==n&&(!("isFrozen"in Object)||!Object.isFrozen(e)))if("string"!=typeof n&&"length"in n){!function(e){if(!e)throw new Error("Assertion Failed")}("string"!=typeof t&&"length"in t);for(var r=0,o=n.length;r<o;++r)I(e,n[r],t[r])}else{var i=n.indexOf(".");if(-1!==i){var s=n.substr(0,i),u=n.substr(i+1);if(""===u)void 0===t?Array.isArray(e)?isNaN(parseInt(s))||e.splice(parseInt(s),1):delete e[s]:e[s]=t;else{var a=e[s];a||(a=e[s]={}),I(a,u,t)}}else void 0===t?Array.isArray(e)&&!isNaN(parseInt(n))?e.splice(n,1):delete e[n]:e[n]=t}}var E="undefined"==typeof self?function(e){var n=Buffer.alloc(e);return x(n),n.toString("base64")}:function(e){var n=new Uint8Array(e);return crypto.getRandomValues(n),btoa(String.fromCharCode.apply(null,n))};function O(e){return"string"==typeof e||!!(Array.isArray(e)&&e.some((function(e){return O(e)}))&&e.every(T))}function T(e){return"string"==typeof e||"number"==typeof e||Array.isArray(e)&&e.every(T)}function A(e,n,t){var r=e[n]||(e[n]={}),o=t.keys.map((function(e){return"string"==typeof e?e:JSON.stringify(e)}));switch(t.type){case"insert":case"upsert":o.forEach((function(e,n){r[e]={type:"ups",val:t.values[n]}}));break;case"update":case"modify":o.forEach((function(e,n){var o="update"===t.type?t.changeSpecs[n]:t.changeSpec,i=r[e];if(i)switch(i.type){case"ups":for(var s=0,u=Object.entries(o);s<u.length;s++){var a=u[s],c=a[0],l=a[1];I(i.val,c,l)}break;case"del":break;case"upd":Object.assign(i.mod,o)}else r[e]={type:"upd",mod:o}}));break;case"delete":o.forEach((function(e){r[e]={type:"del"}}))}return e}function C(e,n){for(var t=0,r=n;t<r.length;t++)for(var o=r[t],i=o.table,s=0,u=o.muts;s<u.length;s++){A(e,i,u[s])}}function P(e){return"function"==typeof e}function j(e){return function(n){if(function(e){return P(null==e?void 0:e.lift)}(n))return n.lift((function(n){try{return e(n,this)}catch(e){this.error(e)}}));throw new TypeError("Unable to lift unknown Observable type")}}var U=function(e,n){return U=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])},U(e,n)};function D(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function t(){this.constructor=e}U(e,n),e.prototype=null===n?Object.create(n):(t.prototype=n.prototype,new t)}function R(e,n,t,r){return new(t||(t=Promise))((function(o,i){function s(e){try{a(r.next(e))}catch(e){i(e)}}function u(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(s,u)}a((r=r.apply(e,n||[])).next())}))}function L(e,n){var t,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(t)throw new TypeError("Generator is already executing.");for(;s;)try{if(t=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=n.call(e,s)}catch(e){i=[6,e],r=0}finally{t=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}}function N(e){var n="function"==typeof Symbol&&Symbol.iterator,t=n&&e[n],r=0;if(t)return t.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")}function $(e,n){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var r,o,i=t.call(e),s=[];try{for(;(void 0===n||n-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(t=i.return)&&t.call(i)}finally{if(o)throw o.error}}return s}function W(e,n){for(var t=0,r=n.length,o=e.length;t<r;t++,o++)e[o]=n[t];return e}function B(e){return this instanceof B?(this.v=e,this):new B(e)}function M(e,n,t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,o=t.apply(e,n||[]),i=[];return r={},s("next"),s("throw"),s("return"),r[Symbol.asyncIterator]=function(){return this},r;function s(e){o[e]&&(r[e]=function(n){return new Promise((function(t,r){i.push([e,n,t,r])>1||u(e,n)}))})}function u(e,n){try{!function(e){e.value instanceof B?Promise.resolve(e.value.v).then(a,c):l(i[0][2],e)}(o[e](n))}catch(e){l(i[0][3],e)}}function a(e){u("next",e)}function c(e){u("throw",e)}function l(e,n){e(n),i.shift(),i.length&&u(i[0][0],i[0][1])}}function F(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n,t=e[Symbol.asyncIterator];return t?t.call(e):(e=N(e),n={},r("next"),r("throw"),r("return"),n[Symbol.asyncIterator]=function(){return this},n);function r(t){n[t]=e[t]&&function(n){return new Promise((function(r,o){(function(e,n,t,r){Promise.resolve(r).then((function(n){e({value:n,done:t})}),n)})(r,o,(n=e[t](n)).done,n.value)}))}}}var K=function(e){return e&&"number"==typeof e.length&&"function"!=typeof e};function H(e){return P(null==e?void 0:e.then)}function q(e){var n=e((function(e){Error.call(e),e.stack=(new Error).stack}));return n.prototype=Object.create(Error.prototype),n.prototype.constructor=n,n}var V=q((function(e){return function(n){e(this),this.message=n?n.length+" errors occurred during unsubscription:\n"+n.map((function(e,n){return n+1+") "+e.toString()})).join("\n "):"",this.name="UnsubscriptionError",this.errors=n}}));function z(e,n){if(e){var t=e.indexOf(n);0<=t&&e.splice(t,1)}}var G=function(){function e(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._teardowns=null}var n;return e.prototype.unsubscribe=function(){var e,n,t,r,o;if(!this.closed){this.closed=!0;var i=this._parentage;if(i)if(this._parentage=null,Array.isArray(i))try{for(var s=N(i),u=s.next();!u.done;u=s.next()){u.value.remove(this)}}catch(n){e={error:n}}finally{try{u&&!u.done&&(n=s.return)&&n.call(s)}finally{if(e)throw e.error}}else i.remove(this);var a=this.initialTeardown;if(P(a))try{a()}catch(e){o=e instanceof V?e.errors:[e]}var c=this._teardowns;if(c){this._teardowns=null;try{for(var l=N(c),f=l.next();!f.done;f=l.next()){var d=f.value;try{Y(d)}catch(e){o=null!=o?o:[],e instanceof V?o=W(W([],$(o)),$(e.errors)):o.push(e)}}}catch(e){t={error:e}}finally{try{f&&!f.done&&(r=l.return)&&r.call(l)}finally{if(t)throw t.error}}}if(o)throw new V(o)}},e.prototype.add=function(n){var t;if(n&&n!==this)if(this.closed)Y(n);else{if(n instanceof e){if(n.closed||n._hasParent(this))return;n._addParent(this)}(this._teardowns=null!==(t=this._teardowns)&&void 0!==t?t:[]).push(n)}},e.prototype._hasParent=function(e){var n=this._parentage;return n===e||Array.isArray(n)&&n.includes(e)},e.prototype._addParent=function(e){var n=this._parentage;this._parentage=Array.isArray(n)?(n.push(e),n):n?[n,e]:e},e.prototype._removeParent=function(e){var n=this._parentage;n===e?this._parentage=null:Array.isArray(n)&&z(n,e)},e.prototype.remove=function(n){var t=this._teardowns;t&&z(t,n),n instanceof e&&n._removeParent(this)},e.EMPTY=((n=new e).closed=!0,n),e}();function J(e){return e instanceof G||e&&"closed"in e&&P(e.remove)&&P(e.add)&&P(e.unsubscribe)}function Y(e){P(e)?e():e.unsubscribe()}var Z={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},X={setTimeout:function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var t=X.delegate;return((null==t?void 0:t.setTimeout)||setTimeout).apply(void 0,W([],$(e)))},clearTimeout:function(e){return clearTimeout(e)},delegate:void 0};function Q(e){X.setTimeout((function(){throw e}))}function ee(){}var ne=function(e){function n(n){var t=e.call(this)||this;return t.isStopped=!1,n?(t.destination=n,J(n)&&n.add(t)):t.destination=ie,t}return D(n,e),n.create=function(e,n,t){return new te(e,n,t)},n.prototype.next=function(e){this.isStopped||this._next(e)},n.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},n.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},n.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},n.prototype._next=function(e){this.destination.next(e)},n.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},n.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},n}(G),te=function(e){function n(n,t,r){var o,i=e.call(this)||this;if(P(n))o=n;else if(n){var s;o=n.next,t=n.error,r=n.complete,i&&Z.useDeprecatedNextContext?(s=Object.create(n)).unsubscribe=function(){return i.unsubscribe()}:s=n,o=null==o?void 0:o.bind(s),t=null==t?void 0:t.bind(s),r=null==r?void 0:r.bind(s)}return i.destination={next:o?re(o):ee,error:re(null!=t?t:oe),complete:r?re(r):ee},i}return D(n,e),n}(ne);function re(e,n){return function(){for(var n=[],t=0;t<arguments.length;t++)n[t]=arguments[t];try{e.apply(void 0,W([],$(n)))}catch(e){Q(e)}}}function oe(e){throw e}var ie={closed:!0,next:ee,error:oe,complete:ee},se="function"==typeof Symbol&&Symbol.observable||"@@observable";function ue(e){return e}function ae(e){return 0===e.length?ue:1===e.length?e[0]:function(n){return e.reduce((function(e,n){return n(e)}),n)}}var ce=function(){function e(e){e&&(this._subscribe=e)}return e.prototype.lift=function(n){var t=new e;return t.source=this,t.operator=n,t},e.prototype.subscribe=function(e,n,t){var r,o=this,i=(r=e)&&r instanceof ne||function(e){return e&&P(e.next)&&P(e.error)&&P(e.complete)}(r)&&J(r)?e:new te(e,n,t);return function(){var e=o,n=e.operator,t=e.source;i.add(n?n.call(i,t):t?o._subscribe(i):o._trySubscribe(i))}(),i},e.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(n){e.error(n)}},e.prototype.forEach=function(e,n){var t=this;return new(n=le(n))((function(n,r){var o;o=t.subscribe((function(n){try{e(n)}catch(e){r(e),null==o||o.unsubscribe()}}),r,n)}))},e.prototype._subscribe=function(e){var n;return null===(n=this.source)||void 0===n?void 0:n.subscribe(e)},e.prototype[se]=function(){return this},e.prototype.pipe=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return ae(e)(this)},e.prototype.toPromise=function(e){var n=this;return new(e=le(e))((function(e,t){var r;n.subscribe((function(e){return r=e}),(function(e){return t(e)}),(function(){return e(r)}))}))},e.create=function(n){return new e(n)},e}();function le(e){var n;return null!==(n=null!=e?e:Z.Promise)&&void 0!==n?n:Promise}function fe(e){return P(e[se])}function de(e){return Symbol.asyncIterator&&P(null==e?void 0:e[Symbol.asyncIterator])}function he(e){return new TypeError("You provided "+(null!==e&&"object"==typeof e?"an invalid object":"'"+e+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}var ve="function"==typeof Symbol&&Symbol.iterator?Symbol.iterator:"@@iterator";function pe(e){return P(null==e?void 0:e[ve])}function be(e){return M(this,arguments,(function(){var n,t,r;return L(this,(function(o){switch(o.label){case 0:n=e.getReader(),o.label=1;case 1:o.trys.push([1,,9,10]),o.label=2;case 2:return[4,B(n.read())];case 3:return t=o.sent(),r=t.value,t.done?[4,B(void 0)]:[3,5];case 4:return[2,o.sent()];case 5:return[4,B(r)];case 6:return[4,o.sent()];case 7:return o.sent(),[3,2];case 8:return[3,10];case 9:return n.releaseLock(),[7];case 10:return[2]}}))}))}function ye(e){return P(null==e?void 0:e.getReader)}function me(e){if(e instanceof ce)return e;if(null!=e){if(fe(e))return o=e,new ce((function(e){var n=o[se]();if(P(n.subscribe))return n.subscribe(e);throw new TypeError("Provided object does not correctly implement Symbol.observable")}));if(K(e))return r=e,new ce((function(e){for(var n=0;n<r.length&&!e.closed;n++)e.next(r[n]);e.complete()}));if(H(e))return t=e,new ce((function(e){t.then((function(n){e.closed||(e.next(n),e.complete())}),(function(n){return e.error(n)})).then(null,Q)}));if(de(e))return ge(e);if(pe(e))return n=e,new ce((function(e){var t,r;try{for(var o=N(n),i=o.next();!i.done;i=o.next()){var s=i.value;if(e.next(s),e.closed)return}}catch(e){t={error:e}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(t)throw t.error}}e.complete()}));if(ye(e))return ge(be(e))}var n,t,r,o;throw he(e)}function ge(e){return new ce((function(n){(function(e,n){var t,r,o,i;return R(this,void 0,void 0,(function(){var s,u;return L(this,(function(a){switch(a.label){case 0:a.trys.push([0,5,6,11]),t=F(e),a.label=1;case 1:return[4,t.next()];case 2:if((r=a.sent()).done)return[3,4];if(s=r.value,n.next(s),n.closed)return[2];a.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return u=a.sent(),o={error:u},[3,11];case 6:return a.trys.push([6,,9,10]),r&&!r.done&&(i=t.return)?[4,i.call(t)]:[3,8];case 7:a.sent(),a.label=8;case 8:return[3,10];case 9:if(o)throw o.error;return[7];case 10:return[7];case 11:return n.complete(),[2]}}))}))})(e,n).catch((function(e){return n.error(e)}))}))}var _e=function(e){function n(n,t,r,o,i){var s=e.call(this,n)||this;return s.onFinalize=i,s._next=t?function(e){try{t(e)}catch(e){n.error(e)}}:e.prototype._next,s._error=o?function(e){try{o(e)}catch(e){n.error(e)}finally{this.unsubscribe()}}:e.prototype._error,s._complete=r?function(){try{r()}catch(e){n.error(e)}finally{this.unsubscribe()}}:e.prototype._complete,s}return D(n,e),n.prototype.unsubscribe=function(){var n,t=this.closed;e.prototype.unsubscribe.call(this),!t&&(null===(n=this.onFinalize)||void 0===n||n.call(this))},n}(ne),we=function(e){function n(n,t){return e.call(this)||this}return D(n,e),n.prototype.schedule=function(e,n){return this},n}(G),Se={setInterval:function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var t=Se.delegate;return((null==t?void 0:t.setInterval)||setInterval).apply(void 0,W([],$(e)))},clearInterval:function(e){return clearInterval(e)},delegate:void 0},ke=function(e){function n(n,t){var r=e.call(this,n,t)||this;return r.scheduler=n,r.work=t,r.pending=!1,r}return D(n,e),n.prototype.schedule=function(e,n){if(void 0===n&&(n=0),this.closed)return this;this.state=e;var t=this.id,r=this.scheduler;return null!=t&&(this.id=this.recycleAsyncId(r,t,n)),this.pending=!0,this.delay=n,this.id=this.id||this.requestAsyncId(r,this.id,n),this},n.prototype.requestAsyncId=function(e,n,t){return void 0===t&&(t=0),Se.setInterval(e.flush.bind(e,this),t)},n.prototype.recycleAsyncId=function(e,n,t){if(void 0===t&&(t=0),null!=t&&this.delay===t&&!1===this.pending)return n;Se.clearInterval(n)},n.prototype.execute=function(e,n){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var t=this._execute(e,n);if(t)return t;!1===this.pending&&null!=this.id&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},n.prototype._execute=function(e,n){var t,r=!1;try{this.work(e)}catch(e){r=!0,t=e||new Error("Scheduled action threw falsy error")}if(r)return this.unsubscribe(),t},n.prototype.unsubscribe=function(){if(!this.closed){var n=this.id,t=this.scheduler,r=t.actions;this.work=this.state=this.scheduler=null,this.pending=!1,z(r,this),null!=n&&(this.id=this.recycleAsyncId(t,n,null)),this.delay=null,e.prototype.unsubscribe.call(this)}},n}(we),xe=function(){return Date.now()},Ie=function(){function e(n,t){void 0===t&&(t=e.now),this.schedulerActionCtor=n,this.now=t}return e.prototype.schedule=function(e,n,t){return void 0===n&&(n=0),new this.schedulerActionCtor(this,e).schedule(t,n)},e.now=xe,e}(),Ee=new(function(e){function n(n,t){void 0===t&&(t=Ie.now);var r=e.call(this,n,t)||this;return r.actions=[],r._active=!1,r._scheduled=void 0,r}return D(n,e),n.prototype.flush=function(e){var n=this.actions;if(this._active)n.push(e);else{var t;this._active=!0;do{if(t=e.execute(e.state,e.delay))break}while(e=n.shift());if(this._active=!1,t){for(;e=n.shift();)e.unsubscribe();throw t}}},n}(Ie))(ke),Oe=Ee;function Te(e){return e&&P(e.schedule)}function Ae(e){return e instanceof Date&&!isNaN(e)}function Ce(e){return Te((n=e)[n.length-1])?e.pop():void 0;var n}function Pe(e,n,t,r,o){void 0===r&&(r=0),void 0===o&&(o=!1);var i=n.schedule((function(){t(),o?e.add(this.schedule(null,r)):this.unsubscribe()}),r);if(e.add(i),!o)return i}function je(e){return j((function(n,t){var r,o=null,i=!1;o=n.subscribe(new _e(t,void 0,void 0,(function(s){r=me(e(s,je(e)(n))),o?(o.unsubscribe(),o=null,r.subscribe(t)):i=!0}))),i&&(o.unsubscribe(),o=null,r.subscribe(t))}))}function Ue(e,n){return void 0===n&&(n=0),j((function(t,r){t.subscribe(new _e(r,(function(t){return Pe(r,e,(function(){return r.next(t)}),n)}),(function(){return Pe(r,e,(function(){return r.complete()}),n)}),(function(t){return Pe(r,e,(function(){return r.error(t)}),n)})))}))}function De(e,n){return void 0===n&&(n=0),j((function(t,r){r.add(e.schedule((function(){return t.subscribe(r)}),n))}))}function Re(e,n){if(!e)throw new Error("Iterable cannot be null");return new ce((function(t){Pe(t,n,(function(){var r=e[Symbol.asyncIterator]();Pe(t,n,(function(){r.next().then((function(e){e.done?t.complete():t.next(e.value)}))}),0,!0)}))}))}function Le(e,n){if(null!=e){if(fe(e))return function(e,n){return me(e).pipe(De(n),Ue(n))}(e,n);if(K(e))return function(e,n){return new ce((function(t){var r=0;return n.schedule((function(){r===e.length?t.complete():(t.next(e[r++]),t.closed||this.schedule())}))}))}(e,n);if(H(e))return function(e,n){return me(e).pipe(De(n),Ue(n))}(e,n);if(de(e))return Re(e,n);if(pe(e))return function(e,n){return new ce((function(t){var r;return Pe(t,n,(function(){r=e[ve](),Pe(t,n,(function(){var e,n,o;try{n=(e=r.next()).value,o=e.done}catch(e){return void t.error(e)}o?t.complete():t.next(n)}),0,!0)})),function(){return P(null==r?void 0:r.return)&&r.return()}}))}(e,n);if(ye(e))return function(e,n){return Re(be(e),n)}(e,n)}throw he(e)}function Ne(e,n){return n?Le(e,n):me(e)}function $e(e,n){return j((function(t,r){var o=0;t.subscribe(new _e(r,(function(t){r.next(e.call(n,t,o++))})))}))}function We(e,n,t){return void 0===t&&(t=1/0),P(n)?We((function(t,r){return $e((function(e,o){return n(t,e,r,o)}))(me(e(t,r)))}),t):("number"==typeof n&&(t=n),j((function(n,r){return function(e,n,t,r,o,i,s,u){var a=[],c=0,l=0,f=!1,d=function(){!f||a.length||c||n.complete()},h=function(e){return c<r?v(e):a.push(e)},v=function(e){i&&n.next(e),c++;var u=!1;me(t(e,l++)).subscribe(new _e(n,(function(e){null==o||o(e),i?h(e):n.next(e)}),(function(){u=!0}),void 0,(function(){if(u)try{c--;for(var e=function(){var e=a.shift();s?Pe(n,s,(function(){return v(e)})):v(e)};a.length&&c<r;)e();d()}catch(e){n.error(e)}})))};return e.subscribe(new _e(n,h,(function(){f=!0,d()}))),function(){null==u||u()}}(n,r,e,t)})))}function Be(){return void 0===(e=1)&&(e=1/0),We(ue,e);var e}function Me(e,n){return void 0===n&&(n=Ee),j((function(t,r){var o=null,i=null,s=null,u=function(){if(o){o.unsubscribe(),o=null;var e=i;i=null,r.next(e)}};function a(){var t=s+e,i=n.now();if(i<t)return o=this.schedule(void 0,t-i),void r.add(o);u()}t.subscribe(new _e(r,(function(t){i=t,s=n.now(),o||(o=n.schedule(a,e),r.add(o))}),(function(){u(),r.complete()}),void 0,(function(){i=o=null})))}))}function Fe(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return Be()(Ne(e,Ce(e)))}var Ke=new ce((function(e){return e.complete()}));function He(e){return e<=0?function(){return Ke}:j((function(n,t){var r=0;n.subscribe(new _e(t,(function(n){++r<=e&&(t.next(n),e<=r&&t.complete())})))}))}function qe(e,n){return n?function(t){return Fe(n.pipe(He(1),j((function(e,n){e.subscribe(new _e(n,ee))}))),t.pipe(qe(e)))}:We((function(n,t){return e(n,t).pipe(He(1),function(e){return $e((function(){return e}))}(n))}))}function Ve(e,n){void 0===n&&(n=Ee);var t=function(e,n,t){void 0===e&&(e=0),void 0===t&&(t=Oe);var r=-1;return null!=n&&(Te(n)?t=n:r=n),new ce((function(n){var o=Ae(e)?+e-t.now():e;o<0&&(o=0);var i=0;return t.schedule((function(){n.closed||(n.next(i++),0<=r?this.schedule(void 0,r):n.complete())}),o)}))}(e,n);return qe((function(){return t}))}function ze(e,n){return e===n}function Ge(e,n){return j((function(t,r){var o=0;t.subscribe(new _e(r,(function(t){return e.call(n,t,o++)&&r.next(t)})))}))}function Je(e){return Ge((function(n,t){return e<=t}))}function Ye(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var t=Ce(e);return j((function(n,r){(t?Fe(e,n,t):Fe(e,n)).subscribe(r)}))}function Ze(e,n){return j((function(t,r){var o=null,i=0,s=!1,u=function(){return s&&!o&&r.complete()};t.subscribe(new _e(r,(function(t){null==o||o.unsubscribe();var s=0,a=i++;me(e(t,a)).subscribe(o=new _e(r,(function(e){return r.next(n?n(t,e,a,s++):e)}),(function(){o=null,u()})))}),(function(){s=!0,u()})))}))}function Xe(e,n,t){var r=P(e)||n||t?{next:e,error:n,complete:t}:e;return r?j((function(e,n){var t;null===(t=r.subscribe)||void 0===t||t.call(r);var o=!0;e.subscribe(new _e(n,(function(e){var t;null===(t=r.next)||void 0===t||t.call(r,e),n.next(e)}),(function(){var e;o=!1,null===(e=r.complete)||void 0===e||e.call(r),n.complete()}),(function(e){var t;o=!1,null===(t=r.error)||void 0===t||t.call(r,e),n.error(e)}),(function(){var e,n;o&&(null===(e=r.unsubscribe)||void 0===e||e.call(r)),null===(n=r.finalize)||void 0===n||n.call(r)})))})):ue}var Qe=q((function(e){return function(n){void 0===n&&(n=null),e(this),this.message="Timeout has occurred",this.name="TimeoutError",this.info=n}}));function en(e){throw new Qe(e)}var nn=!1;function tn(e,n){return k(this,void 0,void 0,(function(){var t,r;return w(this,(function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),[4,navigator.serviceWorker.ready];case 1:return t=o.sent(),"push"===n&&t.sync?[4,t.sync.register("dexie-cloud:".concat(e.name))]:[3,3];case 2:o.sent(),o.label=3;case 3:if(!t.active)throw new Error("Failed to trigger sync - there's no active service worker");return t.active.postMessage({type:"dexie-cloud-sync",dbName:e.name,purpose:n}),[2];case 4:return r=o.sent(),nn||(console.debug("Dexie Cloud: Could not register sync event",r),nn=!0),[3,5];case 5:return[2]}}))}))}function rn(e,n){e.cloud.usingServiceWorker?tn(e,n):e.localSyncEvent.next({purpose:n})}var on="undefined"!=typeof Buffer?function(e){return Buffer.from(e,"base64")}:function(e){for(var n=atob(e),t=n.length,r=new Uint8Array(t),o=0;o<t;o++)r[o]=n.charCodeAt(o);return r},sn="undefined"!=typeof Buffer?function(e){return ArrayBuffer.isView(e)?Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"):Buffer.from(e).toString("base64")}:function(e){return btoa(String.fromCharCode.apply(null,e))};function un(n,t){return new Promise((function(r,o){var i=Object.assign(Object.assign({},t),{onSubmit:function(e){n.next(void 0),r(e)},onCancel:function(){n.next(void 0),o(new e.AbortError("User cancelled"))}});n.next(i)}))}function an(e,n){for(var t=[],r=2;r<arguments.length;r++)t[r-2]=arguments[r];return un(e,{type:"message-alert",title:n,alerts:t,fields:{}})}function cn(e,n,t){return k(this,void 0,void 0,(function(){var r;return w(this,(function(o){switch(o.label){case 0:r=t||"",o.label=1;case 1:return r&&/^[\w-\.]+@([\w-]+\.)+[\w-]{2,10}$/.test(r)?[3,3]:[4,un(e,{type:"email",title:n,alerts:r?[{type:"error",messageCode:"INVALID_EMAIL",message:"Please enter a valid email address",messageParams:{}}]:[],fields:{email:{type:"email",placeholder:"you@somedomain.com"}}})];case 2:return r=o.sent().email,[3,1];case 3:return[2,r]}}))}))}function ln(e,n,t){return k(this,void 0,void 0,(function(){var r;return w(this,(function(o){switch(o.label){case 0:return r=[{type:"info",messageCode:"OTP_SENT",message:"A One-Time password has been sent to {email}",messageParams:{email:n}}],t&&r.push(t),[4,un(e,{type:"otp",title:"Enter OTP",alerts:r,fields:{otp:{type:"otp",label:"OTP",placeholder:"Paste OTP here"}}})];case 1:return[2,o.sent().otp]}}))}))}function fn(e){var n,t;return k(this,void 0,void 0,(function(){var r,o,i,s,u,a,c;return w(this,(function(l){switch(l.label){case 0:return[4,e.getCurrentUser()];case 1:if(r=l.sent(),o=r.accessToken,i=r.accessTokenExpiration,s=r.refreshToken,u=r.refreshTokenExpiration,a=r.claims,!o)return[2];if((null!==(n=null==i?void 0:i.getTime())&&void 0!==n?n:1/0)>Date.now())return[2,o];if(!s)throw new Error("Refresh token missing");if((null!==(t=null==u?void 0:u.getTime())&&void 0!==t?t:1/0)<=Date.now())throw new Error("Refresh token has expired");return[4,hn(e.cloud.options.databaseUrl,r)];case 2:return c=l.sent(),[4,e.table("$logins").update(a.sub,{accessToken:c.accessToken,accessTokenExpiration:c.accessTokenExpiration})];case 3:return l.sent(),[2,c.accessToken]}}))}))}function dn(e,n,t,r,o){return k(this,void 0,void 0,(function(){return w(this,(function(i){switch(i.label){case 0:return n.accessToken&&n.accessTokenExpiration.getTime()>Date.now()?[2,n]:[3,1];case 1:return n.refreshToken&&(!n.refreshTokenExpiration||n.refreshTokenExpiration.getTime()>Date.now())?[4,hn(e,n)]:[3,3];case 2:case 4:return[2,i.sent()];case 3:return[4,vn(n,t,r,o)]}}))}))}function hn(e,n){return k(this,void 0,void 0,(function(){var t,r,o,i,s,u,a,c,l;return w(this,(function(f){switch(f.label){case 0:if(!n.refreshToken)throw new Error("Cannot refresh token - refresh token is missing.");if(!n.nonExportablePrivateKey)throw new Error("login.nonExportablePrivateKey is missing - cannot sign refresh token without a private key.");return t=Date.now(),r="RSASSA-PKCS1-v1_5",o=new TextEncoder,i=o.encode(n.refreshToken+t),[4,crypto.subtle.sign(r,n.nonExportablePrivateKey,i)];case 1:return s=f.sent(),u=sn(s),a={grant_type:"refresh_token",refresh_token:n.refreshToken,scopes:["ACCESS_DB"],signature:u,signing_algorithm:r,time_stamp:t},[4,fetch("".concat(e,"/token"),{body:JSON.stringify(a),method:"post",headers:{"Content-Type":"application/json"},mode:"cors"})];case 2:if(200!==(c=f.sent()).status)throw new Error("RefreshToken: Status ".concat(c.status," from ").concat(e,"/token"));return[4,c.json()];case 3:return l=f.sent(),n.accessToken=l.accessToken,n.accessTokenExpiration=l.accessTokenExpiration?new Date(l.accessTokenExpiration):void 0,[2,n]}}))}))}function vn(e,n,t,r){return k(this,void 0,void 0,(function(){var o,i,s,u,a,c,l;return w(this,(function(f){switch(f.label){case 0:return[4,crypto.subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:2048,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!1,["sign","verify"])];case 1:if(o=f.sent(),i=o.privateKey,s=o.publicKey,!i||!s)throw new Error("Could not generate RSA keypair");return e.nonExportablePrivateKey=i,[4,crypto.subtle.exportKey("spki",s)];case 2:u=f.sent(),a=function(e){for(var n="-----BEGIN PUBLIC KEY-----\n";e.length>0;)n+=e.substring(0,64)+"\n",e=e.substring(64);return n+="-----END PUBLIC KEY-----"}(sn(u)),e.publicKey=s,f.label=3;case 3:return f.trys.push([3,7,,9]),[4,n({public_key:a,hints:r})];case 4:if("tokens"!==(c=f.sent()).type)throw new Error("Unexpected response type from token endpoint: ".concat(c.type));return e.accessToken=c.accessToken,e.accessTokenExpiration=new Date(c.accessTokenExpiration),e.refreshToken=c.refreshToken,c.refreshTokenExpiration&&(e.refreshTokenExpiration=new Date(c.refreshTokenExpiration)),e.userId=c.claims.sub,e.email=c.claims.email,e.name=c.claims.name,e.claims=c.claims,c.alerts&&c.alerts.length>0?[4,un(t,{type:"message-alert",title:"Authentication Alert",fields:{},alerts:c.alerts})]:[3,6];case 5:f.sent(),f.label=6;case 6:return[2,e];case 7:return l=f.sent(),[4,an(t,"Authentication Failed",{type:"error",messageCode:"GENERIC_ERROR",message:"We're having a problem authenticating right now.",messageParams:{}}).catch((function(){}))];case 8:throw f.sent(),l;case 9:return[2]}}))}))}var pn=new WeakMap,bn=function(){function e(e,n){pn.set(this,e),Object.assign(this,n)}return e.load=function(n,t){return n.table("$logins").get(t).then((function(r){return new e(n,r||{userId:t,claims:{sub:t},lastLogin:new Date(0)})}))},e.prototype.save=function(){return k(this,void 0,void 0,(function(){return w(this,(function(e){return pn.get(this).table("$logins").put(this),[2]}))}))},e}(),yn=function(e){function n(n,t){var r=e.call(this,t||"".concat(n.status," ").concat(n.statusText))||this;return r.httpStatus=n.status,r}return m(n,e),Object.defineProperty(n.prototype,"name",{get:function(){return"HttpError"},enumerable:!1,configurable:!0}),n}(Error);function mn(e){var n=e.cloud.userInteraction;return function(t){var r,o=t.public_key,i=t.hints;return k(this,void 0,void 0,(function(){var t,s,u,a,c,l,f,d,h,v,p;return w(this,(function(b){switch(b.label){case 0:if(!(s=null===(r=e.cloud.options)||void 0===r?void 0:r.databaseUrl))throw new Error("No database URL given.");return"demo"!==(null==i?void 0:i.grant_type)?[3,2]:[4,cn(n,"Enter a demo user email",(null==i?void 0:i.email)||(null==i?void 0:i.userId))];case 1:return u=b.sent(),t={demo_user:u,grant_type:"demo",scopes:["ACCESS_DB"],public_key:o},[3,4];case 2:return[4,cn(n,"Enter email address",null==i?void 0:i.email)];case 3:a=b.sent(),t={email:a,grant_type:"otp",scopes:["ACCESS_DB"],public_key:o},b.label=4;case 4:return[4,fetch("".concat(s,"/token"),{body:JSON.stringify(t),method:"post",headers:{"Content-Type":"application/json",mode:"cors"}})];case 5:return 200===(c=b.sent()).status?[3,8]:[4,c.text()];case 6:return p=b.sent(),[4,an(n,"Token request failed",{type:"error",messageCode:"GENERIC_ERROR",message:p,messageParams:{}}).catch((function(){}))];case 7:throw b.sent(),new yn(c,p);case 8:return[4,c.json()];case 9:return"tokens"!==(l=b.sent()).type?[3,10]:[2,l];case 10:if("otp"!==t.grant_type)return[3,22];if("otp-sent"!==l.type)throw new Error("Unexpected response from ".concat(s,"/token"));return[4,ln(n,t.email)];case 11:return f=b.sent(),t.otp=f||"",t.otp_id=l.otp_id,[4,fetch("".concat(s,"/token"),{body:JSON.stringify(t),method:"post",headers:{"Content-Type":"application/json"},mode:"cors"})];case 12:d=b.sent(),b.label=13;case 13:return 401!==d.status?[3,17]:[4,d.text()];case 14:return h=b.sent(),v=t,[4,ln(n,t.email,{type:"error",messageCode:"INVALID_OTP",message:h,messageParams:{}})];case 15:return v.otp=b.sent(),[4,fetch("".concat(s,"/token"),{body:JSON.stringify(t),method:"post",headers:{"Content-Type":"application/json"},mode:"cors"})];case 16:return d=b.sent(),[3,13];case 17:return 200===d.status?[3,20]:[4,d.text()];case 18:return p=b.sent(),[4,an(n,"OTP Authentication Failed",{type:"error",messageCode:"GENERIC_ERROR",message:p,messageParams:{}}).catch((function(){}))];case 19:throw b.sent(),new yn(d,p);case 20:return[4,d.json()];case 21:return[2,b.sent()];case 22:throw new Error("Unexpected response from ".concat(s,"/token"))}}))}))}}function gn(e,n){return k(this,void 0,void 0,(function(){var t,r=this;return w(this,(function(o){switch(o.label){case 0:return n.userId===e.cloud.currentUserId?[2]:(t=e.table("$logins"),[4,e.transaction("rw",t,(function(e){return k(r,void 0,void 0,(function(){var e;return w(this,(function(r){switch(r.label){case 0:return[4,t.toArray()];case 1:return e=r.sent(),[4,Promise.all(e.filter((function(e){return e.userId!==n.userId&&e.isLoggedIn})).map((function(e){return e.isLoggedIn=!1,t.put(e)})))];case 2:return r.sent(),n.isLoggedIn=!0,n.lastLogin=new Date,[4,n.save()];case 3:return r.sent(),console.debug("Saved new user",n.email),[2]}}))}))}))]);case 1:return o.sent(),[4,new Promise((function(t){if(e.cloud.currentUserId===n.userId)t(null);else var r=e.cloud.currentUser.subscribe((function(e){e.userId===n.userId&&(r.unsubscribe(),t(null))}))}))];case 2:return o.sent(),[2]}}))}))}function _n(e,n){return k(this,void 0,void 0,(function(){var t;return w(this,(function(r){switch(r.label){case 0:return[4,e.getCurrentUser()];case 1:if(r.sent().isLoggedIn){if(n){if(n.email&&e.cloud.currentUser.value.email!==n.email)throw new Error("Must logout before changing user");if(n.userId&&e.cloud.currentUserId!==n.userId)throw new Error("Must logout before changing user")}return[2]}return t=new bn(e,{claims:{},lastLogin:new Date(0)}),[4,dn(e.cloud.options.databaseUrl,t,e.cloud.options.fetchTokens||mn(e),e.cloud.userInteraction,n)];case 2:return r.sent(),[4,t.save()];case 3:return r.sent(),[4,gn(e,t)];case 4:return r.sent(),rn(e,"pull"),[2]}}))}))}var wn={userId:"unauthorized",name:"Unauthorized",claims:{sub:"unauthorized"},lastLogin:new Date(0)};try{Object.freeze(wn),Object.freeze(wn.claims)}catch(e){}var Sn={},kn=self.document&&navigator.serviceWorker;kn&&kn.ready.then((function(e){return Sn.registration=e})),"undefined"!=typeof self&&"clients"in self&&!self.document&&addEventListener("message",(function(e){var n,t;(null===(t=null===(n=e.data)||void 0===n?void 0:n.type)||void 0===t?void 0:t.startsWith("sw-broadcast-"))&&S([],self.clients.matchAll({includeUncontrolled:!0}),!0).forEach((function(n){var t;return n.id!==(null===(t=e.source)||void 0===t?void 0:t.id)&&n.postMessage(e.data)}))}));var xn=function(){function e(e){this.name=e}return e.prototype.subscribe=function(e){var n=this;if(!kn)return function(){};var t=function(t){var r;(null===(r=t.data)||void 0===r?void 0:r.type)==="sw-broadcast-".concat(n.name)&&e(t.data.message)};return kn.addEventListener("message",t),function(){return kn.removeEventListener("message",t)}},e.prototype.postMessage=function(e){var n,t=this;"object"==typeof self.clients?S([],self.clients.matchAll({includeUncontrolled:!0}),!0).forEach((function(n){return n.postMessage({type:"sw-broadcast-".concat(t.name),message:e})})):Sn.registration&&(null===(n=Sn.registration.active)||void 0===n||n.postMessage({type:"sw-broadcast-".concat(this.name),message:e}))},e}(),In=function(e){function n(n){var t=this,r="undefined"==typeof BroadcastChannel?new xn(n):new BroadcastChannel(n);return(t=e.call(this,(function(e){function t(n){e.next(n.detail)}function o(n){console.debug("BroadcastedAndLocalEvent: onMessageEvent",n),e.next(n.data)}var i;return self.addEventListener("lbc-".concat(n),t),r instanceof xn?i=r.subscribe((function(n){return e.next(n)})):(console.debug("BroadcastedAndLocalEvent: bc.addEventListener()",n,"bc is a",r),r.addEventListener("message",o)),function(){self.removeEventListener("lbc-".concat(n),t),r instanceof xn?i():r.removeEventListener("message",o)}}))||this).name=n,t.bc=r,t}return m(n,e),n.prototype.next=function(e){console.debug("BroadcastedAndLocalEvent: bc.postMessage()",Object.assign({},e),"bc is a",this.bc),this.bc.postMessage(e);var n=new CustomEvent("lbc-".concat(this.name),{detail:e});self.dispatchEvent(n)},n}(a);function En(e){var n=e.realms,t=e.inviteRealms;return k(this,void 0,void 0,(function(){var e,r,o;return w(this,(function(i){switch(i.label){case 0:return e=JSON.stringify(S(S([],n.map((function(e){return{realmId:e,accepted:!0}})),!0),t.map((function(e){return{realmId:e,accepted:!1}})),!0).sort((function(e,n){return e.realmId<n.realmId?-1:e.realmId>n.realmId?1:0}))),r=(new TextEncoder).encode(e),[4,crypto.subtle.digest("SHA-1",r)];case 1:return o=i.sent(),[2,sn(o)]}}))}))}function On(e){return Object.entries(e.cloud.schema||{}).filter((function(e){return e[1].markedForSync})).map((function(n){var t=n[0];return e.tables.filter((function(e){return e.name===t}))[0]})).filter((function(e){return e}))}function Tn(e){return"$".concat(e,"_mutations")}function An(e){var n,t=null===(n=/^\$(.*)_mutations$/.exec(e))||void 0===n?void 0:n[1];if(!t)throw new Error("Given mutationTable ".concat(e," is not correct"));return t}var Cn=[].concat;function Pn(e){return Cn.apply([],e)}function jn(e,n,t){var r=void 0===t?{}:t,o=r.since,i=void 0===o?{}:o,s=r.limit,u=void 0===s?1/0:s;return k(this,void 0,void 0,(function(){var n,t,r,o,s,a,c,l,f,d,h=this;return w(this,(function(v){switch(v.label){case 0:return[4,Promise.all(e.map((function(e){return k(h,void 0,void 0,(function(){var n,t,r;return w(this,(function(o){switch(o.label){case 0:return n=An(e.name),t=i[n],r=t?e.where("rev").above(t):e,u<1/0&&(r=r.limit(u)),[4,r.toArray()];case 1:return[2,o.sent().map((function(e){return{table:n,mut:e}}))]}}))}))})))];case 1:for(n=v.sent(),t=Pn(n).sort((function(e,n){return e.mut.ts-n.mut.ts})),r=[],o=null,s=null,a=0,c=t;a<c.length;a++)l=c[a],f=l.table,d=l.mut,o&&o.table===f&&s===d.txid?o.muts.push(d):(o={table:f,muts:[d]},s=d.txid,r.push(o));return[2,r]}}))}))}function Un(e){var n=new Uint8Array(e);return crypto.getRandomValues(n),btoa(String.fromCharCode.apply(null,n))}function Dn(e,n,t,r){return k(this,void 0,void 0,(function(){var o,i,s=this;return w(this,(function(u){switch(u.label){case 0:return o="upload-".concat(Un(8)),n.isLoggedIn?e.length>0?(i=new Set(r||[]),[4,Promise.all(e.map((function(e){return k(s,void 0,void 0,(function(){var r,s,u,a;return w(this,(function(c){switch(c.label){case 0:return(r=e.core.schema.primaryKey.extractKey)?(s=t[e.name],[4,((null==s?void 0:s.generatedGlobalId)?e.filter((function(e){var n=r(e);return!i.has(e.realmId||"")&&O(n)})):e.filter((function(e){return r(e),!i.has(e.realmId||"")&&(n=r(e),!(t=null==s?void 0:s.idPrefix)||"string"==typeof n&&n.startsWith(t));var n,t}))).toArray()]):[2,{table:e.name,muts:[]}];case 1:return(u=c.sent()).length>0?(a={type:"upsert",values:u,keys:u.map(r),userId:n.userId,txid:o},[2,{table:e.name,muts:[a]}]):[2,{table:e.name,muts:[]}]}}))}))})))]):[3,2]:[3,2];case 1:return[2,u.sent().filter((function(e){return e.muts.length>0}))];case 2:return[2,[]]}}))}))}var Rn={}.toString;function Ln(e){return Rn.call(e).slice(8,-1)}var Nn={replace:function(e){for(var n=Object.keys(e),t=null,r=0,o=n.length;r<o;++r)"$"===n[r][0]&&(t=t||[]).push(n[r]);if(!t)return e;for(var i=g({},e),s=0,u=t;s<u.length;s++){delete i[u[s]]}for(var a=0,c=t;a<c.length;a++){var l=c[a];i["$"+l]=e[l]}return i}};function $n(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var t=e.reduce((function(e,n){return g(g({},e),n)}),e.reduce((function(e,n){return g(g({},n),e)}),{})),r=new WeakMap;return{stringify:function(e,n,r){return JSON.stringify(e,(function(e){var r=this[e],i=o(r);return i?i.replace(r,n,t):r}),r)},parse:function(e,n){var r=[];return JSON.parse(e,(function(e,o){var i=null==o?void 0:o.$t;if(i){var s=t[i];o=s?s.revive(o,n,t):o}var u=r[r.length-1];if(u&&u[0]===o){o=g({},o);for(var a=0,c=u[1];a<c.length;a++){delete o[c[a]]}for(var l=0,f=Object.entries(u[2]);l<f.length;l++){var d=f[l],h=d[0],v=d[1];o[h]=v}r.pop()}if(void 0===o||"$"===e[0]&&"$t"!==e){var p=void 0,b=void 0;(u=r[r.length-1])&&u[0]===this?(p=u[1],b=u[2]):r.push([this,p=[],b={}]),"$"===e[0]&&"$t"!==e?(p.push(e),b[e.substr(1)]=o):b[e]=void 0}return o}))}};function o(e){var n=typeof e;switch(typeof e){case"object":case"function":if(null===e)return null;var o=Object.getPrototypeOf(e);if(!o)return Nn;var i=r.get(o);if(void 0!==i)return i;var s=Ln(e),u=Object.entries(t).find((function(n){var t,r,o=n[0],i=n[1];return null!==(r=null===(t=null==i?void 0:i.test)||void 0===t?void 0:t.call(i,e,s))&&void 0!==r?r:o===s}));return(i=null==u?void 0:u[1])||(i=Array.isArray(e)?null:"function"==typeof e?t.function||null:Nn),r.set(o,i),i;default:return t[n]}}}var Wn={Blob:{test:function(e,n){return"Blob"===n},replace:function(e,n){var t=n.length;return n.push(e),{$t:"Blob",mimeType:e.type,i:t}},revive:function(e,n){var t=e.i,r=e.mimeType;return new Blob([n[t]],{type:r})}}},Bn={number:{replace:function(e){switch(!0){case isNaN(e):return{$t:"number",v:"NaN"};case e===1/0:return{$t:"number",v:"Infinity"};case e===-1/0:return{$t:"number",v:"-Infinity"};default:return e}},revive:function(e){var n=e.v;return Number(n)}}},Mn={bigint:{replace:function(e){return{$t:"bigint",v:""+e}},revive:function(e){return BigInt(e.v)}}},Fn={Date:{replace:function(e){return{$t:"Date",v:isNaN(e.getTime())?"NaN":e.toISOString()}},revive:function(e){var n=e.v;return new Date("NaN"===n?NaN:Date.parse(n))}}},Kn={Set:{replace:function(e){return{$t:"Set",v:Array.from(e.entries())}},revive:function(e){var n=e.v;return new Set(n)}}},Hn={Map:{replace:function(e){return{$t:"Map",v:Array.from(e.entries())}},revive:function(e){var n=e.v;return new Map(n)}}},qn="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"==typeof global?global:void 0,Vn=["Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","DataView","BigInt64Array","BigUint64Array"].reduce((function(e,n){var t;return g(g({},e),((t={})[n]={replace:function(e,t,r){return{$t:n,v:r.ArrayBuffer.replace(0===e.byteOffset&&e.byteLength===e.buffer.byteLength?e.buffer:e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength),t,r).v}},revive:function(e,t,r){var o=e.v,i=qn[n];return i&&new i(r.ArrayBuffer.revive({v:o},t,r))}},t))}),{});function zn(e){return function(e){for(var n="",t=0,r=e.length;t<r;t++)n+=Yn[e[t]];return n}(sn(e))}function Gn(e){return on(function(e){if("string"!=typeof e)throw new Error("invalid decoder input: "+e);for(var n="",t=0,r=e.length;t<r;t++)n+=Jn[e[t]];return n}(e))}for(var Jn={"-":"=",0:"A",1:"B",2:"C",3:"D",4:"E",5:"F",6:"G",7:"H",8:"I",9:"J",A:"K",B:"L",C:"M",D:"N",E:"O",F:"P",G:"Q",H:"R",I:"S",J:"T",K:"U",L:"V",M:"W",N:"X",O:"Y",P:"Z",Q:"a",R:"b",S:"c",T:"d",U:"e",V:"f",W:"g",X:"h",Y:"i",Z:"j",_:"k",a:"l",b:"m",c:"n",d:"o",e:"p",f:"q",g:"r",h:"s",i:"t",j:"u",k:"v",l:"w",m:"x",n:"y",o:"z",p:"0",q:"1",r:"2",s:"3",t:"4",u:"5",v:"6",w:"7",x:"8",y:"9",z:"+","|":"/"},Yn={},Zn=0,Xn=Object.keys(Jn);Zn<Xn.length;Zn++){var Qn=Xn[Zn];Yn[Jn[Qn]]=Qn}var et={ArrayBuffer:{replace:function(e){return{$t:"ArrayBuffer",v:zn(e)}},revive:function(e){var n=Gn(e.v);return n.buffer.byteLength===n.byteLength?n.buffer:n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength)}}},nt=function(e,n){this.buf=e,this.type=n};function tt(e){var n=new XMLHttpRequest;if(n.overrideMimeType("text/plain; charset=x-user-defined"),n.open("GET",URL.createObjectURL(e),!1),n.send(),200!==n.status&&0!==n.status)throw new Error("Bad Blob access: "+n.status);return n.responseText}function rt(e){for(var n=new Uint8Array(e.length),t=0;t<e.length;++t)n[t]=e.charCodeAt(t);return n.buffer}var ot={Blob:{test:function(e,n){return"Blob"===n||e instanceof nt},replace:function(e){return{$t:"Blob",v:sn(e instanceof nt?e.buf:rt(tt(e))),type:e.type}},revive:function(e){var n=e.type,t=e.v,r=on(t);return void 0!==typeof Blob?new Blob([r]):new nt(r.buffer,n)}}},it=g(g(g(g(g(g(g(g({},Bn),Mn),Fn),Kn),Hn),Vn),et),ot);function st(e){return new Promise((function(n,t){var r=new FileReader;r.onabort=function(e){return t(new Error("file read aborted"))},r.onerror=function(e){return t(e.target.error)},r.onload=function(e){return n(e.target.result)},r.readAsText(e)}))}function ut(e){return new Promise((function(n,t){var r=new FileReader;r.onabort=function(e){return t(new Error("file read aborted"))},r.onerror=function(e){return t(e.target.error)},r.onload=function(e){return n(e.target.result)},r.readAsArrayBuffer(e)}))}var at={undefined:{replace:function(){return{$t:"undefined"}},revive:function(){}}},ct="bigint"==typeof BigInt(0),lt=function(){function e(e){this.v=e}return e.prototype.toString=function(){return this.v},e}(),ft=Object.assign(Object.assign({},at),ct?{}:{bigint:{test:function(e){return e instanceof lt},replace:function(e){return Object.assign({$t:"bigint"},e)},revive:function(e){var n=e.v;return new lt(n)}}}),dt=$n(it,ft),ht=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var t=$n.apply(void 0,S([it,Wn],e,!1));return{toBinary:function(e){var n=this.stringify(e),t=n[0],r=n[1],o=new ArrayBuffer(4);return new DataView(o).setUint32(0,t.size),new Blob([o,t,r])},stringify:function(e){var n=[],r=t.stringify(e,n),o=new Blob(n.map((function(e){var n=new ArrayBuffer(4);return new DataView(n).setUint32(0,"byteLength"in e?e.byteLength:e.size),new Blob([n,e])})));return[o,r]},parse:function(e,n){return _(this,void 0,void 0,(function(){var r,o,i,s,u,a;return w(this,(function(c){switch(c.label){case 0:return r=0,o=[],[4,ut(n)];case 1:for(i=c.sent(),s=new DataView(i);r<i.byteLength;)u=s.getUint32(r),r+=4,a=i.slice(r,r+u),r+=u,o.push(a);return[2,t.parse(e,o)]}}))}))},fromBinary:function(e){return _(this,void 0,void 0,(function(){var n,t,r,o;return w(this,(function(i){switch(i.label){case 0:return t=DataView.bind,[4,ut(e.slice(0,4))];case 1:return n=(new(t.apply(DataView,[void 0,i.sent()]))).getUint32(0),r=e.slice(4,n+4),[4,st(e.slice(n+4))];case 2:return o=i.sent(),[4,this.parse(o,r)];case 3:return[2,i.sent()]}}))}))}}}(ft);function vt(n,t,r){for(var o=[],i=function(r){var i=r.table,s=r.muts,u=n.tables.find((function(e){return e.name===i}));if(!u)throw new Error("Internal error: table ".concat(i," not found in DBCore schema"));var a=u.primaryKey,c=r;s.forEach((function(n,o){var i=!a.outbound&&("upsert"===n.type||"insert"===n.type);n.keys.forEach((function(n,s){if(Array.isArray(n)){c===r&&(c=pt(r,i));var u=c.muts[o],l=JSON.stringify(n);u.keys[s]=l,i&&e.setByKeyPath(u.values[s],a.keyPath,l)}else if("#"===n[0]){c===r&&(c=pt(r,i));u=c.muts[o];if(!t.isLoggedIn)throw new Error("Internal error: Cannot sync private IDs before authenticated");l="".concat(n,":").concat(t.userId);u.keys[s]=l,i&&e.setByKeyPath(u.values[s],a.keyPath,l)}}))})),o.push(c)},s=0,u=r;s<u.length;s++){i(u[s])}return o}function pt(e,n){return Object.assign(Object.assign({},e),{muts:n?e.muts.map((function(e){return Object.assign(Object.assign({},e),{keys:e.keys.slice(),values:e.values.slice()})})):e.muts.map((function(e){return Object.assign(Object.assign({},e),{keys:e.keys.slice()})}))})}function bt(e,n,t,r,o,i,s,u){return k(this,void 0,void 0,(function(){var a,c,l,f,d,h,v;return w(this,(function(p){switch(p.label){case 0:return a={Accept:"application/json, application/x-bison, application/x-bison-stream","Content-Type":"application/tson"},[4,fn(r)];case 1:return(c=p.sent())&&(a.Authorization="Bearer ".concat(c)),l={v:2,dbID:null==n?void 0:n.remoteDbId,clientIdentity:s,schema:i||{},lastPull:n?{serverRevision:n.serverRevision,realms:n.realms,inviteRealms:n.inviteRealms}:void 0,baseRevs:t,changes:vt(r.dx.core.schema,u,e)},console.debug("Sync request",l),r.syncStateChangedEvent.next({phase:"pushing"}),[4,fetch("".concat(o,"/sync"),{method:"post",headers:a,body:dt.stringify(l)})];case 2:if(f=p.sent(),r.syncStateChangedEvent.next({phase:"pulling"}),!f.ok)throw new yn(f);switch(f.headers.get("content-type")){case"application/x-bison":return[3,3];case"application/x-bison-stream":case"application/json":return[3,5]}return[3,5];case 3:return h=(d=ht).fromBinary,[4,f.blob()];case 4:return[2,h.apply(d,[p.sent()])];case 5:return[4,f.text()];case 6:return v=p.sent(),[2,dt.parse(v)]}}))}))}function yt(e,n,t){return k(this,void 0,void 0,(function(){var r,o,i,s;return w(this,(function(u){switch(u.label){case 0:r=new Set(t||[]),o=0,i=e,u.label=1;case 1:return o<i.length?"members"!==(s=i[o]).name?[3,3]:[4,s.toCollection().modify((function(e){r.has(e.realmId)||e.userId&&e.userId!==wn.userId||(e.userId=n.userId)}))]:[3,9];case 2:return u.sent(),[3,8];case 3:return"roles"!==s.name?[3,4]:[3,8];case 4:return"realms"!==s.name?[3,6]:[4,s.toCollection().modify((function(e){r.has(e.realmId)||void 0!==e.owner&&e.owner!==wn.userId||(e.owner=n.userId)}))];case 5:return u.sent(),[3,8];case 6:return[4,s.toCollection().modify((function(e){e.realmId&&r.has(e.realmId)||(e.owner&&e.owner!==wn.userId||(e.owner=n.userId),e.realmId&&e.realmId!==wn.userId||(e.realmId=n.userId))}))];case 7:u.sent(),u.label=8;case 8:return o++,[3,1];case 9:return[2]}}))}))}function mt(n){if(null==n?void 0:n.cancelled)throw new e.AbortError("Operation was cancelled")}var gt=navigator.onLine;function _t(e,n,t,r){return k(this,void 0,void 0,(function(){return w(this,(function(o){switch(o.label){case 0:return[4,e.$baseRevs.bulkPut(Object.keys(n).filter((function(e){return n[e].markedForSync})).map((function(e){return{tableName:e,clientRev:(t[e]||0)+1,serverRev:r}})))];case 1:return o.sent(),[2]}}))}))}function wt(e,n){void 0===n&&(n={});for(var t=0,r=e;t<r.length;t++){var o=r[t],i=o.table,s=o.muts,u=s.length>0?s[s.length-1].rev:null;n[i]=u||n[i]||0}return n}function St(n,r,o){return k(this,void 0,void 0,(function(){var i,s,u;return w(this,(function(a){switch(a.label){case 0:return[4,n.bulkGet(r)];case 1:return i=a.sent(),s=[],u=[],r.forEach((function(r,a){var c=i[a];if(c){for(var l=0,f=Object.entries(o[a]);l<f.length;l++){var d=f[l],h=d[0],v=d[1];if(h===n.schema.primKey.keyPath){if(0!==t(v,r))throw new Error("Cannot change primary key")}else e.setByKeyPath(c,h,v)}s.push(r),u.push(c)}})),[4,null==n.schema.primKey.keyPath?n.bulkPut(u,s):n.bulkPut(u)];case 2:return a.sent(),[2]}}))}))}function kt(n,t){return k(this,void 0,void 0,(function(){var r,o,i,s,u,a;return w(this,(function(c){switch(c.label){case 0:console.debug("Applying server changes",n,e.currentTransaction),r=function(n,r){var o,i,s,u,a,c,l;return w(this,(function(f){switch(f.label){case 0:if(!(o=t.table(n)))return[2,"continue"];i=o.core.schema.primaryKey,s=function(e){switch(e[0]){case"[":if(e.endsWith("]"))try{return JSON.parse(e)}catch(e){}return e;case"#":return e.endsWith(":"+t.cloud.currentUserId)?e.substr(0,e.length-t.cloud.currentUserId.length-1):e;default:return e}},u=function(n){var t;return w(this,(function(r){switch(r.label){case 0:switch(t=n.keys.map(s),n.type){case"insert":return[3,1];case"upsert":return[3,6];case"modify":return[3,11];case"update":return[3,16];case"delete":return[3,18]}return[3,20];case 1:return i.outbound?[4,o.bulkAdd(n.values,t)]:[3,3];case 2:return r.sent(),[3,5];case 3:return t.forEach((function(t,r){e.setByKeyPath(n.values[r],i.keyPath,t)})),[4,o.bulkAdd(n.values)];case 4:r.sent(),r.label=5;case 5:return[3,20];case 6:return i.outbound?[4,o.bulkPut(n.values,t)]:[3,8];case 7:return r.sent(),[3,10];case 8:return t.forEach((function(t,r){e.setByKeyPath(n.values[r],i.keyPath,t)})),[4,o.bulkPut(n.values)];case 9:r.sent(),r.label=10;case 10:return[3,20];case 11:return 1!==t.length?[3,13]:[4,o.update(t[0],n.changeSpec)];case 12:return r.sent(),[3,15];case 13:return[4,o.where(":id").anyOf(t).modify(n.changeSpec)];case 14:r.sent(),r.label=15;case 15:return[3,20];case 16:return[4,St(o,t,n.changeSpecs)];case 17:return r.sent(),[3,20];case 18:return[4,o.bulkDelete(t)];case 19:return r.sent(),[3,20];case 20:return[2]}}))},a=0,c=r,f.label=1;case 1:return a<c.length?(l=c[a],[5,u(l)]):[3,4];case 2:f.sent(),f.label=3;case 3:return a++,[3,1];case 4:return[2]}}))},o=0,i=n,c.label=1;case 1:return o<i.length?(s=i[o],u=s.table,a=s.muts,[5,r(u,a)]):[3,4];case 2:c.sent(),c.label=3;case 3:return o++,[3,1];case 4:return[2]}}))}))}self.addEventListener("online",(function(){return gt=!0})),self.addEventListener("offline",(function(){return gt=!1}));function xt(e,n,t,r){var o=this;return It.apply(this,arguments).then((function(){(null==r?void 0:r.justCheckIfNeeded)||e.syncStateChangedEvent.next({phase:"in-sync"})})).catch((function(i){return k(o,void 0,void 0,(function(){return w(this,(function(o){switch(o.label){case 0:return(null==r?void 0:r.justCheckIfNeeded)?[2,Promise.reject(i)]:(console.debug("Error from _sync",{isOnline:gt,syncOptions:r,error:i}),gt&&(null==r?void 0:r.retryImmediatelyOnFetchError)&&"TypeError"===(null==i?void 0:i.name)&&/fetch/.test(null==i?void 0:i.message)?(e.syncStateChangedEvent.next({phase:"error",error:i}),[4,new Promise((function(e){return setTimeout(e,500)}))]):[3,3]);case 1:return o.sent(),[4,xt(e,n,t,Object.assign(Object.assign({},r),{retryImmediatelyOnFetchError:!1}))];case 2:return[2,o.sent()];case 3:return[4,e.$syncState.update("syncState",{timestamp:new Date,error:""+i})];case 4:return o.sent(),e.syncStateChangedEvent.next({phase:gt?"error":"offline",error:i}),[2,Promise.reject(i)]}}))}))}))}function It(e,n,t,r){var o,i=void 0===r?{isInitialSync:!1}:r,s=i.isInitialSync,u=i.cancelToken,a=i.justCheckIfNeeded,c=i.purpose;return k(this,void 0,void 0,(function(){var r,i,l,f,d,h,v,p,b,y,m,g,_,x,I,O=this;return w(this,(function(T){switch(T.label){case 0:if(a||console.debug("SYNC STARTED",{isInitialSync:s,purpose:c}),!(null===(o=e.cloud.options)||void 0===o?void 0:o.databaseUrl))throw new Error("Internal error: sync must not be called when no databaseUrl is configured");return r=n.databaseUrl,[4,e.getCurrentUser()];case 1:return i=T.sent(),l=i.isLoggedIn?On(e):[],f=l.map((function(n){return e.table(Tn(n.name))})),[4,e.getPersistedSyncState()];case 2:return d=T.sent(),h=!s&&i.isLoggedIn?function(e,n){var t=(null==n?void 0:n.syncedTables)||[];return On(e).filter((function(e){return!t.includes(e.name)}))}(e,d):[],mt(u),(v=h.length>0)?a?[2,!0]:[4,e.transaction("rw",h,(function(e){return k(O,void 0,void 0,(function(){return w(this,(function(n){switch(n.label){case 0:return e.idbtrans.disableChangeTracking=!0,e.idbtrans.disableAccessControl=!0,[4,yt(h,i,null==d?void 0:d.realms)];case 1:return n.sent(),[2]}}))}))}))]:[3,4];case 3:T.sent(),mt(u),T.label=4;case 4:return[4,e.transaction("r",e.tables,(function(){return k(O,void 0,void 0,(function(){var n,r,o,s,a;return w(this,(function(c){switch(c.label){case 0:return[4,e.getPersistedSyncState()];case 1:return n=c.sent(),[4,e.$baseRevs.toArray()];case 2:return r=c.sent(),[4,jn(f)];case 3:return o=c.sent(),mt(u),v?(s=S(S([],(null==d?void 0:d.realms)||[],!0),(null==d?void 0:d.inviteRealms)||[],!0),[4,Dn(h,i,t,s)]):[3,5];case 4:return a=c.sent(),mt(u),[2,[o=o.concat(a),n,r]];case 5:return[2,[o,n,r]]}}))}))}))];case 5:return p=T.sent(),b=p[0],y=p[1],m=p[2],g=b.some((function(e){return e.muts.some((function(e){return e.keys.length>0}))})),a?(console.debug("Sync is needed:",g),[2,g]):"push"!==c||g?(_=wt(b,null==y?void 0:y.latestRevisions),x=(null==y?void 0:y.clientIdentity)||E(16),mt(u),[4,bt(b,y,m,e,r,t,x,i)]):[2,!1];case 6:return I=T.sent(),console.debug("Sync response",I),[4,e.transaction("rw",e.tables,(function(n){return k(O,void 0,void 0,(function(){var r,o,i,s,u,a,c,d,v,p;return w(this,(function(b){switch(b.label){case 0:for(n.idbtrans.disableChangeTracking=!0,n.idbtrans.disableAccessControl=!0,r=0,o=Object.keys(t);r<o.length;r++)i=o[r],I.schema[i]&&(t[i]=I.schema[i]);return[4,e.$syncState.put(t,"schema")];case 1:return b.sent(),[4,jn(f,0,{since:_})];case 2:s=b.sent(),u=function(n){var t,r;return w(this,(function(o){switch(o.label){case 0:return t=An(n.name),s.some((function(e){return e.table===t&&e.muts.length>0}))?[3,2]:[4,Promise.all([n.clear(),e.$baseRevs.where({tableName:t}).delete()])];case 1:return o.sent(),[3,5];case 2:return _[t]?(r=_[t]||0,[4,Promise.all([n.where("rev").belowOrEqual(r).delete(),e.$baseRevs.where(":id").between([t,-1/0],[t,r+1],!0,!0).reverse().offset(1).delete()])]):[3,4];case 3:return o.sent(),[3,5];case 4:o.label=5;case 5:return[2]}}))},a=0,c=f,b.label=3;case 3:return a<c.length?(d=c[a],[5,u(d)]):[3,6];case 4:b.sent(),b.label=5;case 5:return a++,[3,3];case 6:return wt(s,_),[4,_t(e,t,_,I.serverRevision)];case 7:return b.sent(),[4,e.getPersistedSyncState()];case 8:return v=b.sent(),[4,Et(e,I,v)];case 9:return b.sent(),(p=v||{syncedTables:[],latestRevisions:{},realms:[],inviteRealms:[],clientIdentity:x}).syncedTables=l.map((function(e){return e.name})).concat(h.map((function(e){return e.name}))),p.latestRevisions=_,p.remoteDbId=I.dbId,p.initiallySynced=!0,p.realms=I.realms,p.inviteRealms=I.inviteRealms,p.serverRevision=I.serverRevision,p.timestamp=new Date,delete p.error,[4,kt(Ot(I.changes,s),e)];case 10:return b.sent(),e.$syncState.put(p,"syncState"),[2,0===s.length]}}))}))}))];case 7:return T.sent()?[3,9]:(console.debug("MORE SYNC NEEDED. Go for it again!"),[4,It(e,n,t,{isInitialSync:s,cancelToken:u})]);case 8:return[2,T.sent()];case 9:return console.debug("SYNC DONE",{isInitialSync:s}),[2,!1]}}))}))}function Et(e,n,t){return k(this,void 0,void 0,(function(){var r,o,i,s,u,a,c,l,f,d,h,v,p,b,y,m;return w(this,(function(g){switch(g.label){case 0:for(r=new Set,o=new Set,i=t?t.realms:[],s=t?t.inviteRealms:[],u=new Set(n.realms),a=new Set(n.realms.concat(n.inviteRealms)),c=0,l=i;c<l.length;c++)h=l[c],u.has(h)||(o.add(h),a.has(h)||r.add(h));for(f=0,d=s.concat(i);f<d.length;f++)h=d[f],a.has(h)||r.add(h);if(!(r.size>0||o.size>0))return[3,4];v=On(e),p=function(e){var n;return w(this,(function(t){switch(t.label){case 0:return 0===(n=["realms","members","roles"].includes(e.name)?r:o).size?[2,"continue"]:e.schema.indexes.some((function(e){return"realmId"===e.keyPath||Array.isArray(e.keyPath)&&"realmId"===e.keyPath[0]}))?[4,e.where("realmId").anyOf(S([],n,!0)).delete()]:[3,2];case 1:return t.sent(),[3,4];case 2:return[4,e.filter((function(e){return!!(null==e?void 0:e.realmId)&&n.has(e.realmId)})).delete()];case 3:t.sent(),t.label=4;case 4:return[2]}}))},b=0,y=v,g.label=1;case 1:return b<y.length?(m=y[b],[5,p(m)]):[3,4];case 2:g.sent(),g.label=3;case 3:return b++,[3,1];case 4:return[2]}}))}))}function Ot(e,n){var t={};C(t,e);var r={};return C(r,n),function(e,n){for(var t,r,o,i=0,s=Object.entries(n);i<s.length;i++)for(var u=s[i],a=u[0],c=u[1],l=0,f=Object.entries(c);l<f.length;l++){var d=f[l],h=d[0],v=d[1];switch(v.type){case"ups":if(p=null===(t=e[a])||void 0===t?void 0:t[h])switch(p.type){case"ups":case"upd":delete e[a][h]}break;case"del":null===(r=e[a])||void 0===r||delete r[h];break;case"upd":var p;if(p=null===(o=e[a])||void 0===o?void 0:o[h])switch(p.type){case"ups":for(var b=0,y=Object.entries(v.mod);b<y.length;b++){var m=y[b],g=m[0],_=m[1];I(p.val,g,_)}break;case"del":break;case"upd":for(var w=0,S=Object.keys(v.mod);w<S.length;w++)g=S[w],delete p.mod[g]}}}}(t,r),function(e){for(var n=E(16),t={},r=0,o=Object.entries(e);r<o.length;r++)for(var i=o[r],s=i[0],u=i[1],a=0,c=Object.entries(u);a<c.length;a++){var l=c[a],f=l[0],d=l[1],h=t[s]||(t[s]={});(h[d.type]||(h[d.type]=[])).push(Object.assign({key:f},d))}for(var v=[],p=0,b=Object.entries(t);p<b.length;p++){for(var y=b[p],m=(s=y[0],u=y[1],{table:s,muts:[]}),g=0,_=Object.entries(u);g<_.length;g++){var w=_[g],S=w[0],k=w[1];switch(S){case"ups":d={type:"upsert",keys:k.map((function(e){return e.key})),values:k.map((function(e){return e.val})),txid:n},m.muts.push(d);break;case"upd":d={type:"update",keys:k.map((function(e){return e.key})),changeSpecs:k.map((function(e){return e.mod})),txid:n},m.muts.push(d);break;case"del":d={type:"delete",keys:k.map((function(e){return e.key})),txid:n},m.muts.push(d)}}v.push(m)}return v}(t)}var Tt=new WeakMap,At={members:"@id, [userId+realmId], [email+realmId], realmId",roles:"[realmId+name]",realms:"@realmId",$jobs:"",$syncState:"",$baseRevs:"[tableName+clientRev]",$logins:"claims.sub, lastLogin"},Ct=0;function Pt(n){"vip"in n&&(n=n.vip);var t=Tt.get(n.cloud);if(!t){var o=new l,i=new In("syncstatechanged-".concat(n.name));o.id=++Ct;var s=!1;t={get name(){return n.name},close:function(){return n.close()},transaction:n.transaction.bind(n),table:n.table.bind(n),get tables(){return n.tables},cloud:n.cloud,get $jobs(){return n.table("$jobs")},get $syncState(){return n.table("$syncState")},get $baseRevs(){return n.table("$baseRevs")},get $logins(){return n.table("$logins")},get realms(){return n.realms},get members(){return n.members},get roles(){return n.roles},get initiallySynced(){return s},localSyncEvent:o,get syncStateChangedEvent(){return i},dx:n};var u={getCurrentUser:function(){return t.$logins.toArray().then((function(e){return e.find((function(e){return e.isLoggedIn}))||wn}))},getPersistedSyncState:function(){return t.$syncState.get("syncState")},getSchema:function(){return t.$syncState.get("schema")},getOptions:function(){return t.$syncState.get("options")},setInitiallySynced:function(e){s=e},reconfigure:function(){i=new In("syncstatechanged-".concat(n.name))}};Object.assign(t,u),t.messageConsumer=function(n){var t=this,o=[],i=new r(!0),s=new r(null),u=!1,a=0,c=[0,0,0,0,0,0,0,0,0,Date.now()];function l(){var t,r,i;return k(this,void 0,void 0,(function(){var s,u=this;return w(this,(function(a){switch(a.label){case 0:s=function(){var s,a,c,l,f;return w(this,(function(d){switch(d.label){case 0:s=o.shift(),d.label=1;case 1:return d.trys.push([1,13,,14]),[4,n.cloud.syncState.pipe(Ge((function(e){var n=e.phase;return"in-sync"===n||"error"===n})),He(1)).toPromise()];case 2:if(d.sent(),console.debug("processing msg",s),a=n.cloud.persistedSyncState.value,!s)return[2,"continue"];switch(s.type){case"token-expired":return[3,3];case"realm-added":return[3,6];case"realm-accepted":return[3,7];case"realm-removed":return[3,8];case"realms-changed":return[3,9];case"changes":return[3,10]}return[3,12];case 3:return console.debug("WebSocket observable: Token expired. Refreshing token..."),c=n.cloud.currentUser.value,[4,hn(n.cloud.options.databaseUrl,c)];case 4:return l=d.sent(),[4,n.table("$logins").update(c.userId,{accessToken:l.accessToken,accessTokenExpiration:l.accessTokenExpiration})];case 5:return d.sent(),[3,12];case 6:case 7:return rn(n,"pull"),[3,12];case 8:return(null===(t=null==a?void 0:a.realms)||void 0===t?void 0:t.includes(s.realm))||null===(r=null==a?void 0:a.inviteRealms)||void 0===r||r.includes(s.realm),rn(n,"pull"),[3,12];case 9:return rn(n,"pull"),[3,12];case 10:return console.debug("changes"),"error"===(null===(i=n.cloud.syncState.value)||void 0===i?void 0:i.phase)?(rn(n,"pull"),[3,12]):[4,n.transaction("rw",n.dx.tables,(function(t){return k(u,void 0,void 0,(function(){var r,o,i,u,a,c,l;return w(this,(function(f){switch(f.label){case 0:return t.idbtrans.disableChangeTracking=!0,t.idbtrans.disableAccessControl=!0,[4,Promise.all([n.getSchema(),n.getPersistedSyncState(),n.getCurrentUser()])];case 1:return r=f.sent(),o=r[0],i=r[1],u=r[2],console.debug("ws message queue: in transaction"),i&&o&&u?s.baseRev!==i.serverRevision?(console.debug("baseRev (".concat(s.baseRev,") differs from our serverRevision in syncState (").concat(i.serverRevision,")")),"string"!=typeof s.baseRev||"bigint"!=typeof i.serverRevision&&"object"!=typeof i.serverRevision||rn(n,"pull"),[2]):[4,e.waitFor(En(i))]:(console.debug("required vars not present",{syncState:i,schema:o,currentUser:u}),[2]);case 2:return a=f.sent(),console.debug("ourRealmSetHash",a),a!==s.realmSetHash?(console.debug("not same realmSetHash",s.realmSetHash),rn(n,"pull"),[2]):(c=[],u.isLoggedIn?[4,jn(On(n).map((function(e){return n.table(Tn(e.name))})))]:[3,4]);case 3:c=f.sent(),console.debug("msg queue: client changes",c),f.label=4;case 4:return s.changes.length>0?(l=Ot(s.changes,c),console.debug("applying filtered server changes",l),[4,kt(l,n)]):[3,6];case 5:f.sent(),f.label=6;case 6:return i.latestRevisions=wt(c,i.latestRevisions),i.serverRevision=s.newRev,console.debug("Updating baseRefs",i.latestRevisions),[4,_t(n,o,i.latestRevisions,s.newRev)];case 7:return f.sent(),console.debug("Updating syncState",i),[4,n.$syncState.put(i,"syncState")];case 8:return f.sent(),[2]}}))}))}))];case 11:return d.sent(),console.debug("msg queue: done with rw transaction"),[3,12];case 12:return[3,14];case 13:return f=d.sent(),console.error("Error in msg queue",f),[3,14];case 14:return[2]}}))},a.label=1;case 1:return o.length>0?[5,s()]:[3,3];case 2:return a.sent(),[3,1];case 3:return[2]}}))}))}return s.subscribe((function(){return k(t,void 0,void 0,(function(){return w(this,(function(e){switch(e.label){case 0:if(u)return[2];if(!(o.length>0))return[3,8];u=!0,c.shift(),c.push(Date.now()),i.next(!1),e.label=1;case 1:return e.trys.push([1,,3,8]),[4,l()];case 2:return e.sent(),[3,8];case 3:return c[c.length-1]-c[0]<1e4?Date.now()-a<5e3?(console.warn("Slowing down websocket loop for one minute"),a=Date.now()+6e4,[4,new Promise((function(e){return setTimeout(e,6e4)}))]):[3,5]:[3,7];case 4:return e.sent(),[3,7];case 5:return console.warn("Slowing down websocket loop for 10 seconds"),a=Date.now()+1e4,[4,new Promise((function(e){return setTimeout(e,1e4)}))];case 6:e.sent(),e.label=7;case 7:return u=!1,i.next(!0),[7];case 8:return[2]}}))}))})),{enqueue:function(e){o.push(e),s.next(null)},readyToServe:i}}(t),Tt.set(n.cloud,t)}return t}var jt="undefined"!=typeof InstallTrigger,Ut="undefined"!=typeof navigator&&/Safari\//.test(navigator.userAgent)&&!/Chrom(e|ium)\/|Edge\//.test(navigator.userAgent),Dt=Ut?[].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1]:NaN,Rt=Ut&&Dt<=605||jt;var Lt="undefined"!=typeof self&&"clients"in self&&!self.document;function Nt(){throw new e.SchemaError("Version increment needed to allow dexie-cloud change tracking")}var $t={}.toString;function Wt(e){return $t.call(e).slice(8,-1)}function Bt(e,n){var t;return"delete"===n.type?n.keys:(null===(t=n.keys)||void 0===t?void 0:t.slice())||n.values.map(e.extractKey)}var Mt=/b|c|d|f|g|h|j|k|l|m|n|p|q|r|s|t|v|x|y|z/i;var Ft=0;function Kt(e,n){var t=new Uint8Array(18),r=new Uint8Array(t.buffer,0,6),o=Date.now();Ft>=o?++Ft:Ft=o,r[0]=Ft/1099511627776,r[1]=Ft/4294967296,r[2]=Ft/16777216,r[3]=Ft/65536,r[4]=Ft/256,r[5]=Ft;var i=new Uint8Array(t.buffer,6);return crypto.getRandomValues(i),e+zn(new Uint8Array(t.buffer))+(n||"")}function Ht(n){return{stack:"dbcore",name:"idGenerationMiddleware",level:1,create:function(t){return Object.assign(Object.assign({},t),{table:function(r){var o=t.table(r);return Object.assign(Object.assign({},o),{mutate:function(t){var i,s;if(t.trans.disableChangeTracking)return o.mutate(t);if("add"===t.type||"put"===t.type){var u=null===(i=n.cloud.schema)||void 0===i?void 0:i[r];if(null==u?void 0:u.generatedGlobalId){if((null===(s=n.cloud.options)||void 0===s?void 0:s.databaseUrl)&&!n.initiallySynced){var a=Bt(o.schema.primaryKey,t);return o.getMany({keys:a,trans:t.trans,cache:"immutable"}).then((function(e){if(e.length<a.length)throw new Error("Unable to create new objects without an initial sync having been performed.");return o.mutate(t)}))}return function(t,i){var s=null,u=Bt(o.schema.primaryKey,t);return u.forEach((function(a,c){if(void 0===a){var l=t.values[c].realmId||n.cloud.currentUserId,f=l.substr(l.length-3);u[c]=Kt(i,f),o.schema.primaryKey.outbound||(s||(s=t.values.slice()),s[c]=e.deepClone(s[c]),e.setByKeyPath(s[c],o.schema.primaryKey.keyPath,u[c]))}else if("string"!=typeof a||!a.startsWith(i)&&!a.startsWith("#"+i))throw new e.ConstraintError('The ID "'.concat(a,'" is not valid for table "').concat(r,'". ')+"Primary '@' keys requires the key to be prefixed with \"".concat(i,'" (or "#').concat(i,").\n")+"If you want to generate IDs programmatically, remove '@' from the schema to get rid of this constraint. Dexie Cloud supports custom IDs as long as they are random and globally unique.")})),o.mutate(Object.assign(Object.assign({},t),{keys:u,values:s||t.values}))}(t,u.idPrefix)}(null==u?void 0:u.markedForSync)&&Bt(o.schema.primaryKey,t).forEach((function(n,t){if(!O(n)){var o=Array.isArray(n)?n.map(Wt).join(","):Wt(n);throw new e.ConstraintError("Invalid primary key type ".concat(o," for table ").concat(r,". Tables marked for sync has primary keys of type string or Array of string (and optional numbers)"))}}))}return o.mutate(t)}})}})}}}var qt=0;function Vt(e,n){return function(t){var r=t.trans[n]||(t.trans[n]={writers:[],readers:[]}),o=r.readers,i=r.writers,s=i.length,u=(s>0?i[s-1].then((function(){return e(t)}),(function(){return e(t)})):e(t)).finally((function(){return o.splice(o.indexOf(u))}));return o.push(u),u}}function zt(e,n){return function(t){var r,o=t.trans[n]||(t.trans[n]={writers:[],readers:[]}),i=o.readers,s=o.writers,u=(s.length>0?s[s.length-1].then((function(){return e(t)}),(function(){return e(t)})):i.length>0?(r=i,new Promise((function(e){0===r.length&&e([]);var n=r.length,t=new Array(n);r.forEach((function(r,o){return Promise.resolve(r).then((function(e){return t[o]={status:"fulfilled",value:e}}),(function(e){return t[o]={status:"rejected",reason:e}})).then((function(){return--n||e(t)}))}))}))).then((function(){return e(t)})):e(t)).finally((function(){return s.shift()}));return s.push(u),u}}var Gt=new r(new Set);function Jt(e){var n=e.currentUserObservable,t=e.db;return{stack:"dbcore",name:"MutationTrackingMiddleware",level:1,create:function(e){var r,o=e.schema.tables.filter((function(e){return!/^\$/.test(e.name)}));try{r=new Map(o.map((function(n){return[n.name,e.table("$".concat(n.name,"_mutations"))]})))}catch(e){Nt()}return Object.assign(Object.assign({},e),{transaction:function(r,o){var i;if("readwrite"===o){var s=r.filter((function(e){var n,r;return null===(r=null===(n=t.cloud.schema)||void 0===n?void 0:n[e])||void 0===r?void 0:r.markedForSync})).map((function(e){return Tn(e)}));i=e.transaction(S(S([],r,!0),s,!0),o)}else i=e.transaction(r,o);if("readwrite"===o){i.txid=Un(16),i.currentUser=n.value,Gt.value.add(i),Gt.next(Gt.value);var u=function(){i.removeEventListener("complete",a),i.removeEventListener("error",u),i.removeEventListener("abort",u),Gt.value.delete(i),Gt.next(Gt.value)},a=function(){var e;i.mutationsAdded&&(null===(e=t.cloud.options)||void 0===e?void 0:e.databaseUrl)&&(t.cloud.usingServiceWorker?(console.debug("registering sync event"),tn(t,"push")):t.localSyncEvent.next({purpose:"push"})),u()};i.addEventListener("complete",a),i.addEventListener("error",u),i.addEventListener("abort",u)}return i},table:function(n){var o=e.table(n);if(/^\$/.test(n))return n.endsWith("_mutations")?Object.assign(Object.assign({},o),{mutate:function(e){return"add"!==e.type&&"put"!==e.type||(e.trans.mutationsAdded=!0),o.mutate(e)}}):"$logins"===n?Object.assign(Object.assign({},o),{mutate:function(e){return o.mutate(e).then((function(n){return e.trans.mutationsAdded=!0,n})).catch((function(e){return console.debug("Failed mutation $logins",e),Promise.reject(e)}))}}):o;var i=o.schema,s=r.get(n);return function(e){var n="$lock"+ ++qt;return Object.assign(Object.assign({},e),{count:Vt(e.count,n),get:Vt(e.get,n),getMany:Vt(e.getMany,n),openCursor:Vt(e.openCursor,n),query:Vt(e.query,n),mutate:zt(e.mutate,n)})}(Object.assign(Object.assign({},o),{mutate:function(e){var r,s,a,c=e.trans;return c.txid?c.disableChangeTracking?o.mutate(e):(null===(s=null===(r=t.cloud.schema)||void 0===r?void 0:r[n])||void 0===s?void 0:s.markedForSync)&&(null===(a=c.currentUser)||void 0===a?void 0:a.isLoggedIn)?"deleteRange"===e.type?o.query({query:{range:e.range,index:i.primaryKey},trans:e.trans,values:!1}).then((function(n){return u({type:"delete",keys:n.result,trans:e.trans,criteria:{index:null,range:e.range}})})):u(e):o.mutate(e):o.mutate(e)}}));function u(e){var n=e.trans;n.mutationsAdded=!0;var t=n.txid,r=n.currentUser.userId,i=e.type;return o.mutate(e).then((function(o){var u=o.numFailures,a=o.failures,c="delete"===i?e.keys:o.results,l="values"in e?e.values:[],f="changeSpecs"in e?e.changeSpecs:[];u&&(c=c.filter((function(e,n){return!a[n]})),l=l.filter((function(e,n){return!a[n]})),f=f.filter((function(e,n){return!a[n]})));var d=Date.now(),h="delete"===e.type?{type:"delete",ts:d,keys:c,criteria:e.criteria,txid:t,userId:r}:"add"===e.type?{type:"insert",ts:d,keys:c,txid:t,userId:r,values:l}:e.criteria&&e.changeSpec?{type:"modify",ts:d,keys:c,criteria:e.criteria,changeSpec:e.changeSpec,txid:t,userId:r}:e.changeSpecs?{type:"update",ts:d,keys:c,changeSpecs:f,txid:t,userId:r}:{type:"upsert",ts:d,keys:c,values:l,txid:t,userId:r};return c.length>0||"criteria"in e&&e.criteria?s.mutate({type:"add",trans:n,values:[h]}).then((function(){return o})):o}))}}})}}}function Yt(e,n){return function(t,r){var o=Object.assign(Object.assign({},At),t),i=n.cloud.schema||(n.cloud.schema={}),s=new Set;return Object.keys(o).forEach((function(e){var n=o[e],t=i[e]||(i[e]={});null!=n?(/^\@/.test(n)&&(o[e]=o[e].substr(1),t.generatedGlobalId=!0,t.idPrefix=function(e,n){for(var t,r,o,i=e[0].toLocaleLowerCase(),s=1,u=e.length;s<u&&i.length<3;++s)(Mt.test(e[s])||(t=e[s])>="A"&&t<="Z")&&(i+=e[s].toLowerCase());for(;n.has(i);){if(/\d/g.test(i)){if(!((i=i.substr(0,i.length-1)+(i[i.length-1]+1)).length>3))continue;i=i.substr(0,3)}else if(i.length<3){i+="2";continue}for(var a=1,c=i;n.has(c)&&a<8;)r=i,c=(1&(o=a)?r[0].toUpperCase():r[0].toLowerCase())+(2&o?r[1].toUpperCase():r[1].toLowerCase())+(4&o?r[2].toUpperCase():r[2].toLowerCase()),++a;if(a<8)i=c;else{var l=i.charCodeAt(2)+1&127;i=i.substr(0,2)+String.fromCharCode(l)}}return i}(e,s),s.add(t.idPrefix)),/^\$/.test(e)||(o["$".concat(e,"_mutations")]="++rev",t.markedForSync=!0),t.deleted&&(t.deleted=!1)):(t.deleted=!0,t.markedForSync=!1,o["$".concat(e,"_mutations")]=null)})),e.call(this,o,r)}}function Zt(e,n,t){return k(this,void 0,void 0,(function(){return w(this,(function(r){switch(r.label){case 0:return console.debug("Performing initial sync"),[4,xt(e,n,t,{isInitialSync:!0})];case 1:return r.sent(),console.debug("Done initial sync"),[2]}}))}))}var Xt,Qt,er=new r(!0),nr=new r(!0);er.pipe(Ze((function(e){return e?i(!0):i(!1).pipe(Ve(2e4))})),(void 0===Qt&&(Qt=ue),Xt=null!=Xt?Xt:ze,j((function(e,n){var t,r=!0;e.subscribe(new _e(n,(function(e){var o=Qt(e);!r&&Xt(t,o)||(r=!1,t=o,n.next(e))})))})))).subscribe(nr);var tr="undefined"!=typeof document?o(document,"visibilitychange"):i({}),rr=tr.pipe(Ge((function(){return"hidden"===document.visibilityState}))),or=tr.pipe(Ge((function(){return"visible"===document.visibilityState}))),ir="undefined"!=typeof window?s(or,o(window,"mousedown"),o(window,"mousemove"),o(window,"keydown"),o(window,"wheel"),o(window,"touchmove")):i({});"undefined"!=typeof document&&s(i(!0),rr,ir).pipe($e((function(){return"visible"===document.visibilityState})),Xe((function(e){er.value!==e&&er.next(e)})),Ze((function(e){return e?i(0).pipe(Ve(16e4),Xe((function(){return er.next(!1)}))):i(0)}))).subscribe((function(){}));var sr=function(e){function n(){var n=e.apply(this,arguments)||this;return n.name="TokenExpiredError",n}return m(n,e),n}(Error),ur=function(e){function n(n,t,r,o,i,s,u,a){return e.call(this,(function(e){return new cr(n,t,r,o,u,a,e,i,s)}))||this}return m(n,e),n}(a),ar=0,cr=function(e){function n(n,t,r,o,i,s,u,a,c){var l=e.call(this,(function(){return l.teardown()}))||this;return l.id=++ar,l.reconnecting=!1,console.debug("New WebSocket Connection",l.id,i?"authorized":"unauthorized"),l.databaseUrl=n,l.rev=t,l.realmSetHash=r,l.clientIdentity=o,l.token=i,l.tokenExpiration=s,l.subscriber=u,l.lastUserActivity=new Date,l.messageProducer=a,l.messageProducerSubscription=null,l.webSocketStatus=c,l.connect(),l}return m(n,e),n.prototype.teardown=function(){console.debug("Teardown WebSocket Connection",this.id),this.disconnect()},n.prototype.disconnect=function(){if(this.webSocketStatus.next("disconnected"),this.pinger&&(clearInterval(this.pinger),this.pinger=null),this.ws)try{this.ws.close()}catch(e){}this.ws=null,this.messageProducerSubscription&&(this.messageProducerSubscription.unsubscribe(),this.messageProducerSubscription=null)},n.prototype.reconnect=function(){var e=this;if(!this.reconnecting){this.reconnecting=!0;try{this.disconnect()}catch(e){}this.connect().catch((function(){})).then((function(){return e.reconnecting=!1}))}},n.prototype.connect=function(){return k(this,void 0,void 0,(function(){var e,n,t,r,o=this;return w(this,(function(i){switch(i.label){case 0:if(this.lastServerActivity=new Date,this.pauseUntil&&this.pauseUntil>new Date)return console.debug("WS not reconnecting just yet",{id:this.id,pauseUntil:this.pauseUntil}),[2];if(this.ws)throw new Error("Called connect() when a connection is already open");if(!this.databaseUrl)throw new Error("Cannot connect without a database URL");if(this.closed)return[2];if(this.tokenExpiration&&this.tokenExpiration<new Date)return this.subscriber.error(new sr),[2];if(this.webSocketStatus.next("connecting"),this.pinger=setInterval((function(){return k(o,void 0,void 0,(function(){var e=this;return w(this,(function(n){if(this.closed)return console.debug("pinger check",this.id,"CLOSED."),this.teardown(),[2];if(this.ws)try{this.ws.send(JSON.stringify({type:"ping"})),setTimeout((function(){if(console.debug("pinger setTimeout",e.id,e.pinger?"alive":"dead"),e.pinger)return e.closed?(console.debug("pinger setTimeout",e.id,"subscription is closed"),void e.teardown()):void(e.lastServerActivity<new Date(Date.now()-2e4)?(console.debug("pinger: server is inactive"),console.debug("pinger reconnecting"),e.reconnect()):console.debug("pinger: server still active"))}),2e4)}catch(e){console.debug("pinger catch error",this.id,"reconnecting"),this.reconnect()}else console.debug("pinger",this.id,"reconnecting"),this.reconnect();return[2]}))}))}),3e4),(e=new URL(this.databaseUrl)).protocol="http:"===e.protocol?"ws":"wss",n=new URLSearchParams,this.subscriber.closed)return[2];n.set("v","2"),n.set("rev",this.rev),n.set("realmsHash",this.realmSetHash),n.set("clientId",this.clientIdentity),this.token&&n.set("token",this.token),console.debug("dexie-cloud WebSocket create"),(t=this.ws=new WebSocket("".concat(e,"/changes?").concat(n))).onclose=function(e){o.pinger&&(console.debug("dexie-cloud WebSocket onclosed",o.id),o.reconnect())},t.onmessage=function(e){if(o.pinger){console.debug("dexie-cloud WebSocket onmessage",e.data),o.lastServerActivity=new Date;try{var n=dt.parse(e.data);if("error"===n.type)throw new Error("Error message from dexie-cloud: ".concat(n.error));"rev"===n.type&&(o.rev=n.rev),"pong"!==n.type&&o.subscriber.next(n)}catch(e){o.subscriber.error(e)}}},i.label=1;case 1:return i.trys.push([1,3,,4]),r=!1,[4,new Promise((function(e,n){t.onopen=function(n){console.debug("dexie-cloud WebSocket onopen"),r=!0,e(null)},t.onerror=function(e){if(r)o.reconnect();else{var t=e.error||new Error("WebSocket Error");o.subscriber.error(t),o.webSocketStatus.next("error"),n(t)}}}))];case 2:return i.sent(),this.messageProducerSubscription=this.messageProducer.subscribe((function(e){var n;o.closed||("ready"===e.type&&"connected"!==o.webSocketStatus.value&&o.webSocketStatus.next("connected"),null===(n=o.ws)||void 0===n||n.send(dt.stringify(e)))})),[3,4];case 3:return i.sent(),this.pauseUntil=new Date(Date.now()+6e4),[3,4];case 4:return[2]}}))}))},n}(c);function lr(e){var n;if(!(null===(n=e.cloud.options)||void 0===n?void 0:n.databaseUrl))throw new Error("No database URL to connect WebSocket to");var t=e.messageConsumer.readyToServe.pipe(Ge((function(e){return e})),Ze((function(){return e.getPersistedSyncState()})),Ge((function(e){return e&&e.serverRevision})),$e((function(e){return{type:"ready",rev:e.serverRevision}})));return function n(){var r=this;return e.cloud.persistedSyncState.pipe(Ge((function(e){return null==e?void 0:e.serverRevision})),He(1),Ze((function(n){return e.cloud.currentUser.pipe($e((function(e){return[e,n]})))})),Ze((function(e){var n=e[0],t=e[1];return nr.pipe($e((function(e){return[e?n:null,t]})))})),Ze((function(e){var n=e[0],t=e[1];return k(r,void 0,void 0,(function(){var e;return w(this,(function(r){switch(r.label){case 0:return e=[n],[4,En(t)];case 1:return[2,e.concat([r.sent()])]}}))}))})),Ze((function(n){var r=n[0],o=n[1];return r?new ur(e.cloud.options.databaseUrl,e.cloud.persistedSyncState.value.serverRevision,o,e.cloud.persistedSyncState.value.clientIdentity,t,e.cloud.webSocketStatus,r.accessToken,r.accessTokenExpiration):u([])})),je((function(t){return"TokenExpiredError"===(null==t?void 0:t.name)?(console.debug("WebSocket observable: Token expired. Refreshing token..."),i(!0).pipe(Ze((function(){return k(r,void 0,void 0,(function(){var n,t;return w(this,(function(r){switch(r.label){case 0:return[4,e.getCurrentUser()];case 1:return n=r.sent(),[4,hn(e.cloud.options.databaseUrl,n)];case 2:return t=r.sent(),[4,e.table("$logins").update(n.userId,{accessToken:t.accessToken,accessTokenExpiration:t.accessTokenExpiration})];case 3:return r.sent(),[2]}}))}))})),Ze((function(){return n()})))):v(t)})),je((function(t){return e.cloud.webSocketStatus.next("error"),u(function(e){return k(this,void 0,void 0,(function(){return w(this,(function(n){switch(n.label){case 0:return console.error("WebSocket observable: error but revive when user does some active thing...",e),[4,(t=3e3,new Promise((function(e){return setTimeout(e,t)})))];case 1:return n.sent(),console.debug("waiting for someone to do something"),[4,ir.pipe(He(1)).toPromise()];case 2:return n.sent(),console.debug("someone did something!"),[2]}var t}))}))}(t)).pipe(Ze((function(){return n()})))})))}().subscribe((function(n){n&&(console.debug("WS got message",n),e.messageConsumer.enqueue(n))}),(function(e){console.error("Oops! The main observable errored!",e)}),(function(){console.error("Oops! The main observable completed!")}))}function fr(e){var n;return k(this,void 0,void 0,(function(){var t;return w(this,(function(r){switch(r.label){case 0:return(null===(n=e.cloud.options)||void 0===n?void 0:n.databaseUrl)&&e.cloud.schema?[4,xt(e,e.cloud.options,e.cloud.schema,{justCheckIfNeeded:!0})]:[3,2];case 1:return t=r.sent(),[3,3];case 2:t=!1,r.label=3;case 3:return[2,t]}}))}))}var dr=Un(16);function hr(e,t,r,o,i){var s=(void 0===i?{}:i).awaitRemoteJob;return k(this,void 0,void 0,(function(){function i(){return k(this,void 0,void 0,(function(){var o,c,l=this;return w(this,(function(f){switch(f.label){case 0:return[4,e.transaction("rw!",r,(function(){return k(l,void 0,void 0,(function(){var e;return w(this,(function(n){switch(n.label){case 0:return[4,a.get(t)];case 1:return(e=n.sent())?[3,3]:[4,a.add({nodeId:dr,started:new Date,heartbeat:new Date},t)];case 2:case 4:return n.sent(),[2,!0];case 3:return e.heartbeat.getTime()<Date.now()-6e4?(console.warn("Latest ".concat(t," worker seem to have died.\n"),"The dead job started:",e.started,"\n","Last heart beat was:",e.heartbeat,"\n","We're now taking over!"),[4,a.put({nodeId:dr,started:new Date,heartbeat:new Date},t)]):[3,5];case 5:return[2,!1]}}))}))}))];case 1:if(f.sent())return[2,!0];if(!s)return[3,6];f.label=2;case 2:return f.trys.push([2,4,,6]),o=u(n((function(){return a.get(t)}))).pipe(function(e,n){var t=Ae(e)?{first:e}:"number"==typeof e?{each:e}:e,r=t.first,o=t.each,i=t.with,s=void 0===i?en:i,u=t.scheduler,a=void 0===u?null!=n?n:Ee:u,c=t.meta,l=void 0===c?null:c;if(null==r&&null==o)throw new TypeError("No timeout provided.");return j((function(e,n){var t,i,u=null,c=0,f=function(e){i=Pe(n,a,(function(){try{t.unsubscribe(),me(s({meta:l,lastValue:u,seen:c})).subscribe(n)}catch(e){n.error(e)}}),e)};t=e.subscribe(new _e(n,(function(e){null==i||i.unsubscribe(),c++,n.next(u=e),o>0&&f(o)}),void 0,void 0,(function(){(null==i?void 0:i.closed)||null==i||i.unsubscribe(),u=null}))),f(null!=r?"number"==typeof r?r:+r-a.now():o)}))}(6e4),Ge((function(e){return!e}))),[4,o.toPromise()];case 3:return f.sent(),[2,!1];case 4:if("TimeoutError"!==(c=f.sent()).name)throw c;return[4,i()];case 5:return[2,f.sent()];case 6:return[2,!1]}}))}))}var a,c,l=this;return w(this,(function(n){switch(n.label){case 0:return a=e.table(r),[4,i()];case 1:if(!n.sent())return[3,6];c=setInterval((function(){a.update(t,(function(e){e.nodeId===dr&&(e.heartbeat=new Date)}))}),1e3),n.label=2;case 2:return n.trys.push([2,,4,6]),[4,o()];case 3:return[2,n.sent()];case 4:return clearInterval(c),[4,e.transaction("rw!",r,(function(){return k(l,void 0,void 0,(function(){var e;return w(this,(function(n){switch(n.label){case 0:return[4,a.get(t)];case 1:return(e=n.sent())&&e.nodeId===dr?[4,a.delete(t)]:[3,3];case 2:n.sent(),n.label=3;case 3:return[2]}}))}))}))];case 5:return n.sent(),[7];case 6:return[2]}}))}))}var vr=new WeakMap;function pr(e,n,t,r){var o=vr.get(e);if(o){if(o.pull||"push"===(null==r?void 0:r.purpose))return console.debug("syncIfPossible(): returning the ongoing sync promise."),o.promise;var i=!1,s=e.cloud.syncState.subscribe((function(e){"pulling"===e.phase&&(i=!0)}));return o.promise.then((function(){s.unsubscribe()})).catch((function(e){return s.unsubscribe(),Promise.reject(e)})).then((function(){if(!i)return pr(e,n,t,r)}))}var u=function(){return k(this,void 0,void 0,(function(){var o;return w(this,(function(i){switch(i.label){case 0:return i.trys.push([0,6,,7]),e.cloud.usingServiceWorker?Lt?[4,xt(e,n,t,r)]:[3,2]:[3,3];case 1:i.sent(),i.label=2;case 2:return[3,5];case 3:return[4,hr(e,"currentSyncWorker","$jobs",(function(){return xt(e,n,t,r)}))];case 4:i.sent(),i.label=5;case 5:return vr.delete(e),console.debug("Done sync"),[3,7];case 6:throw o=i.sent(),vr.delete(e),console.error("Failed to sync client changes",o),o;case 7:return[2]}}))}))}();return vr.set(e,{promise:u,pull:"push"!==(null==r?void 0:r.purpose)}),u}function br(e,n,t){var r=null,o={cancelled:!1};function i(r,u){void 0===u&&(u=1),setTimeout((function(){pr(e,n,t,{cancelToken:o,retryImmediatelyOnFetchError:!0,purpose:r}).catch((function(e){console.error("error in syncIfPossible()",e),o.cancelled?s():u<3&&setTimeout((function(){return i(r,u+1)}),6e4*[0,5,15][u])}))}),0)}var s=function(){console.debug("Stopping LocalSyncWorker"),o.cancelled=!0,r&&r.unsubscribe()};return{start:function(){console.debug("Starting LocalSyncWorker",e.localSyncEvent.id),r=e.localSyncEvent.subscribe((function(e){var n=e.purpose;try{i(n||"pull")}catch(e){console.error("What-the....",e)}}))},stop:s}}function yr(e,n){if(e&&n&&n.unsyncedTables)for(var t=0,r=n.unsyncedTables;t<r.length;t++){var o=r[t];e[o]&&(e[o].markedForSync=!1)}}var mr,gr,_r,wr,Sr={},kr=[],xr=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;function Ir(e,n){for(var t in n)e[t]=n[t];return e}function Er(e){var n=e.parentNode;n&&n.removeChild(e)}function Or(e,n,t){var r,o,i,s=arguments,u={};for(i in n)"key"==i?r=n[i]:"ref"==i?o=n[i]:u[i]=n[i];if(arguments.length>3)for(t=[t],i=3;i<arguments.length;i++)t.push(s[i]);if(null!=t&&(u.children=t),"function"==typeof e&&null!=e.defaultProps)for(i in e.defaultProps)void 0===u[i]&&(u[i]=e.defaultProps[i]);return Tr(e,u,r,o,null)}function Tr(e,n,t,r,o){var i={type:e,props:n,key:t,ref:r,__k:null,__:null,__b:0,__e:null,__d:void 0,__c:null,__h:null,constructor:void 0,__v:null==o?++mr.__v:o};return null!=mr.vnode&&mr.vnode(i),i}function Ar(e){return e.children}function Cr(e,n){this.props=e,this.context=n}function Pr(e,n){if(null==n)return e.__?Pr(e.__,e.__.__k.indexOf(e)+1):null;for(var t;n<e.__k.length;n++)if(null!=(t=e.__k[n])&&null!=t.__e)return t.__e;return"function"==typeof e.type?Pr(e):null}function jr(e){var n,t;if(null!=(e=e.__)&&null!=e.__c){for(e.__e=e.__c.base=null,n=0;n<e.__k.length;n++)if(null!=(t=e.__k[n])&&null!=t.__e){e.__e=e.__c.base=t.__e;break}return jr(e)}}function Ur(e){(!e.__d&&(e.__d=!0)&&gr.push(e)&&!Dr.__r++||wr!==mr.debounceRendering)&&((wr=mr.debounceRendering)||_r)(Dr)}function Dr(){for(var e;Dr.__r=gr.length;)e=gr.sort((function(e,n){return e.__v.__b-n.__v.__b})),gr=[],e.some((function(e){var n,t,r,o,i,s;e.__d&&(i=(o=(n=e).__v).__e,(s=n.__P)&&(t=[],(r=Ir({},o)).__v=o.__v+1,Fr(s,o,r,n.__n,void 0!==s.ownerSVGElement,null!=o.__h?[i]:null,t,null==i?Pr(o):i,o.__h),Kr(t,o),o.__e!=i&&jr(o)))}))}function Rr(e,n,t,r,o,i,s,u,a,c){var l,f,d,h,v,p,b,y=r&&r.__k||kr,m=y.length;for(t.__k=[],l=0;l<n.length;l++)if(null!=(h=t.__k[l]=null==(h=n[l])||"boolean"==typeof h?null:"string"==typeof h||"number"==typeof h||"bigint"==typeof h?Tr(null,h,null,null,h):Array.isArray(h)?Tr(Ar,{children:h},null,null,null):h.__b>0?Tr(h.type,h.props,h.key,null,h.__v):h)){if(h.__=t,h.__b=t.__b+1,null===(d=y[l])||d&&h.key==d.key&&h.type===d.type)y[l]=void 0;else for(f=0;f<m;f++){if((d=y[f])&&h.key==d.key&&h.type===d.type){y[f]=void 0;break}d=null}Fr(e,h,d=d||Sr,o,i,s,u,a,c),v=h.__e,(f=h.ref)&&d.ref!=f&&(b||(b=[]),d.ref&&b.push(d.ref,null,h),b.push(f,h.__c||v,h)),null!=v?(null==p&&(p=v),"function"==typeof h.type&&null!=h.__k&&h.__k===d.__k?h.__d=a=Lr(h,a,e):a=Nr(e,h,d,y,v,a),c||"option"!==t.type?"function"==typeof t.type&&(t.__d=a):e.value=""):a&&d.__e==a&&a.parentNode!=e&&(a=Pr(d))}for(t.__e=p,l=m;l--;)null!=y[l]&&("function"==typeof t.type&&null!=y[l].__e&&y[l].__e==t.__d&&(t.__d=Pr(r,l+1)),Vr(y[l],y[l]));if(b)for(l=0;l<b.length;l++)qr(b[l],b[++l],b[++l])}function Lr(e,n,t){var r,o;for(r=0;r<e.__k.length;r++)(o=e.__k[r])&&(o.__=e,n="function"==typeof o.type?Lr(o,n,t):Nr(t,o,o,e.__k,o.__e,n));return n}function Nr(e,n,t,r,o,i){var s,u,a;if(void 0!==n.__d)s=n.__d,n.__d=void 0;else if(null==t||o!=i||null==o.parentNode)e:if(null==i||i.parentNode!==e)e.appendChild(o),s=null;else{for(u=i,a=0;(u=u.nextSibling)&&a<r.length;a+=2)if(u==o)break e;e.insertBefore(o,i),s=i}return void 0!==s?s:o.nextSibling}function $r(e,n,t){"-"===n[0]?e.setProperty(n,t):e[n]=null==t?"":"number"!=typeof t||xr.test(n)?t:t+"px"}function Wr(e,n,t,r,o){var i;e:if("style"===n)if("string"==typeof t)e.style.cssText=t;else{if("string"==typeof r&&(e.style.cssText=r=""),r)for(n in r)t&&n in t||$r(e.style,n,"");if(t)for(n in t)r&&t[n]===r[n]||$r(e.style,n,t[n])}else if("o"===n[0]&&"n"===n[1])i=n!==(n=n.replace(/Capture$/,"")),n=n.toLowerCase()in e?n.toLowerCase().slice(2):n.slice(2),e.l||(e.l={}),e.l[n+i]=t,t?r||e.addEventListener(n,i?Mr:Br,i):e.removeEventListener(n,i?Mr:Br,i);else if("dangerouslySetInnerHTML"!==n){if(o)n=n.replace(/xlink[H:h]/,"h").replace(/sName$/,"s");else if("href"!==n&&"list"!==n&&"form"!==n&&"tabIndex"!==n&&"download"!==n&&n in e)try{e[n]=null==t?"":t;break e}catch(e){}"function"==typeof t||(null!=t&&(!1!==t||"a"===n[0]&&"r"===n[1])?e.setAttribute(n,t):e.removeAttribute(n))}}function Br(e){this.l[e.type+!1](mr.event?mr.event(e):e)}function Mr(e){this.l[e.type+!0](mr.event?mr.event(e):e)}function Fr(e,n,t,r,o,i,s,u,a){var c,l,f,d,h,v,p,b,y,m,g,_=n.type;if(void 0!==n.constructor)return null;null!=t.__h&&(a=t.__h,u=n.__e=t.__e,n.__h=null,i=[u]),(c=mr.__b)&&c(n);try{e:if("function"==typeof _){if(b=n.props,y=(c=_.contextType)&&r[c.__c],m=c?y?y.props.value:c.__:r,t.__c?p=(l=n.__c=t.__c).__=l.__E:("prototype"in _&&_.prototype.render?n.__c=l=new _(b,m):(n.__c=l=new Cr(b,m),l.constructor=_,l.render=zr),y&&y.sub(l),l.props=b,l.state||(l.state={}),l.context=m,l.__n=r,f=l.__d=!0,l.__h=[]),null==l.__s&&(l.__s=l.state),null!=_.getDerivedStateFromProps&&(l.__s==l.state&&(l.__s=Ir({},l.__s)),Ir(l.__s,_.getDerivedStateFromProps(b,l.__s))),d=l.props,h=l.state,f)null==_.getDerivedStateFromProps&&null!=l.componentWillMount&&l.componentWillMount(),null!=l.componentDidMount&&l.__h.push(l.componentDidMount);else{if(null==_.getDerivedStateFromProps&&b!==d&&null!=l.componentWillReceiveProps&&l.componentWillReceiveProps(b,m),!l.__e&&null!=l.shouldComponentUpdate&&!1===l.shouldComponentUpdate(b,l.__s,m)||n.__v===t.__v){l.props=b,l.state=l.__s,n.__v!==t.__v&&(l.__d=!1),l.__v=n,n.__e=t.__e,n.__k=t.__k,n.__k.forEach((function(e){e&&(e.__=n)})),l.__h.length&&s.push(l);break e}null!=l.componentWillUpdate&&l.componentWillUpdate(b,l.__s,m),null!=l.componentDidUpdate&&l.__h.push((function(){l.componentDidUpdate(d,h,v)}))}l.context=m,l.props=b,l.state=l.__s,(c=mr.__r)&&c(n),l.__d=!1,l.__v=n,l.__P=e,c=l.render(l.props,l.state,l.context),l.state=l.__s,null!=l.getChildContext&&(r=Ir(Ir({},r),l.getChildContext())),f||null==l.getSnapshotBeforeUpdate||(v=l.getSnapshotBeforeUpdate(d,h)),g=null!=c&&c.type===Ar&&null==c.key?c.props.children:c,Rr(e,Array.isArray(g)?g:[g],n,t,r,o,i,s,u,a),l.base=n.__e,n.__h=null,l.__h.length&&s.push(l),p&&(l.__E=l.__=null),l.__e=!1}else null==i&&n.__v===t.__v?(n.__k=t.__k,n.__e=t.__e):n.__e=Hr(t.__e,n,t,r,o,i,s,a);(c=mr.diffed)&&c(n)}catch(e){n.__v=null,(a||null!=i)&&(n.__e=u,n.__h=!!a,i[i.indexOf(u)]=null),mr.__e(e,n,t)}}function Kr(e,n){mr.__c&&mr.__c(n,e),e.some((function(n){try{e=n.__h,n.__h=[],e.some((function(e){e.call(n)}))}catch(e){mr.__e(e,n.__v)}}))}function Hr(e,n,t,r,o,i,s,u){var a,c,l,f,d=t.props,h=n.props,v=n.type,p=0;if("svg"===v&&(o=!0),null!=i)for(;p<i.length;p++)if((a=i[p])&&(a===e||(v?a.localName==v:3==a.nodeType))){e=a,i[p]=null;break}if(null==e){if(null===v)return document.createTextNode(h);e=o?document.createElementNS("http://www.w3.org/2000/svg",v):document.createElement(v,h.is&&h),i=null,u=!1}if(null===v)d===h||u&&e.data===h||(e.data=h);else{if(i=i&&kr.slice.call(e.childNodes),c=(d=t.props||Sr).dangerouslySetInnerHTML,l=h.dangerouslySetInnerHTML,!u){if(null!=i)for(d={},f=0;f<e.attributes.length;f++)d[e.attributes[f].name]=e.attributes[f].value;(l||c)&&(l&&(c&&l.__html==c.__html||l.__html===e.innerHTML)||(e.innerHTML=l&&l.__html||""))}if(function(e,n,t,r,o){var i;for(i in t)"children"===i||"key"===i||i in n||Wr(e,i,null,t[i],r);for(i in n)o&&"function"!=typeof n[i]||"children"===i||"key"===i||"value"===i||"checked"===i||t[i]===n[i]||Wr(e,i,n[i],t[i],r)}(e,h,d,o,u),l)n.__k=[];else if(p=n.props.children,Rr(e,Array.isArray(p)?p:[p],n,t,r,o&&"foreignObject"!==v,i,s,e.firstChild,u),null!=i)for(p=i.length;p--;)null!=i[p]&&Er(i[p]);u||("value"in h&&void 0!==(p=h.value)&&(p!==e.value||"progress"===v&&!p)&&Wr(e,"value",p,d.value,!1),"checked"in h&&void 0!==(p=h.checked)&&p!==e.checked&&Wr(e,"checked",p,d.checked,!1))}return e}function qr(e,n,t){try{"function"==typeof e?e(n):e.current=n}catch(e){mr.__e(e,t)}}function Vr(e,n,t){var r,o,i;if(mr.unmount&&mr.unmount(e),(r=e.ref)&&(r.current&&r.current!==e.__e||qr(r,null,n)),t||"function"==typeof e.type||(t=null!=(o=e.__e)),e.__e=e.__d=void 0,null!=(r=e.__c)){if(r.componentWillUnmount)try{r.componentWillUnmount()}catch(e){mr.__e(e,n)}r.base=r.__P=null}if(r=e.__k)for(i=0;i<r.length;i++)r[i]&&Vr(r[i],n,t);null!=o&&Er(o)}function zr(e,n,t){return this.constructor(e,t)}mr={__e:function(e,n){for(var t,r,o;n=n.__;)if((t=n.__c)&&!t.__)try{if((r=t.constructor)&&null!=r.getDerivedStateFromError&&(t.setState(r.getDerivedStateFromError(e)),o=t.__d),null!=t.componentDidCatch&&(t.componentDidCatch(e),o=t.__d),o)return t.__E=t}catch(n){e=n}throw e},__v:0},Cr.prototype.setState=function(e,n){var t;t=null!=this.__s&&this.__s!==this.state?this.__s:this.__s=Ir({},this.state),"function"==typeof e&&(e=e(Ir({},t),this.props)),e&&Ir(t,e),null!=e&&this.__v&&(n&&this.__h.push(n),Ur(this))},Cr.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),Ur(this))},Cr.prototype.render=Ar,gr=[],_r="function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout,Dr.__r=0;var Gr={Error:{color:"red"},Alert:{error:{color:"red"},warning:{color:"yellow"},info:{color:"black"}},Darken:{position:"fixed",top:0,left:0,opacity:.5,backgroundColor:"#000",width:"100vw",height:"100vh",zIndex:150,webkitBackdropFilter:"blur(2px)",backdropFilter:"blur(2px)"},DialogOuter:{position:"fixed",top:0,left:0,width:"100vw",height:"100vh",zIndex:150,alignItems:"center",display:"flex",justifyContent:"center"},DialogInner:{position:"relative",color:"#222",backgroundColor:"#fff",padding:"30px",marginBottom:"2em",maxWidth:"90%",maxHeight:"90%",overflowY:"auto",border:"3px solid #3d3d5d",borderRadius:"8px",boxShadow:"0 0 80px 10px #666",width:"auto"},Input:{height:"35px",width:"17em",borderColor:"#ccf4",outline:"none",fontSize:"17pt",padding:"8px"}};function Jr(e){var n=e.children;return Or("div",null,Or("div",{style:Gr.Darken}),Or("div",{style:Gr.DialogOuter},Or("div",{style:Gr.DialogInner},n)))}var Yr,Zr,Xr,Qr=0,eo=[],no=mr.__b,to=mr.__r,ro=mr.diffed,oo=mr.__c,io=mr.unmount;function so(e,n){mr.__h&&mr.__h(Zr,e,Qr||n),Qr=0;var t=Zr.__H||(Zr.__H={__:[],__h:[]});return e>=t.__.length&&t.__.push({}),t.__[e]}function uo(e){return Qr=1,function(e,n,t){var r=so(Yr++,2);return r.t=e,r.__c||(r.__=[t?t(n):po(void 0,n),function(e){var n=r.t(r.__[0],e);r.__[0]!==n&&(r.__=[n,r.__[1]],r.__c.setState({}))}],r.__c=Zr),r.__}(po,e)}function ao(e){return Qr=5,function(e,n){var t=so(Yr++,7);return vo(t.__H,n)&&(t.__=e(),t.__H=n,t.__h=e),t.__}((function(){return{current:e}}),[])}function co(){eo.forEach((function(e){if(e.__P)try{e.__H.__h.forEach(fo),e.__H.__h.forEach(ho),e.__H.__h=[]}catch(n){e.__H.__h=[],mr.__e(n,e.__v)}})),eo=[]}mr.__b=function(e){Zr=null,no&&no(e)},mr.__r=function(e){to&&to(e),Yr=0;var n=(Zr=e.__c).__H;n&&(n.__h.forEach(fo),n.__h.forEach(ho),n.__h=[])},mr.diffed=function(e){ro&&ro(e);var n=e.__c;n&&n.__H&&n.__H.__h.length&&(1!==eo.push(n)&&Xr===mr.requestAnimationFrame||((Xr=mr.requestAnimationFrame)||function(e){var n,t=function(){clearTimeout(r),lo&&cancelAnimationFrame(n),setTimeout(e)},r=setTimeout(t,100);lo&&(n=requestAnimationFrame(t))})(co)),Zr=void 0},mr.__c=function(e,n){n.some((function(e){try{e.__h.forEach(fo),e.__h=e.__h.filter((function(e){return!e.__||ho(e)}))}catch(t){n.some((function(e){e.__h&&(e.__h=[])})),n=[],mr.__e(t,e.__v)}})),oo&&oo(e,n)},mr.unmount=function(e){io&&io(e);var n=e.__c;if(n&&n.__H)try{n.__H.__.forEach(fo)}catch(e){mr.__e(e,n.__v)}};var lo="function"==typeof requestAnimationFrame;function fo(e){var n=Zr;"function"==typeof e.__c&&e.__c(),Zr=n}function ho(e){var n=Zr;e.__c=e.__(),Zr=n}function vo(e,n){return!e||e.length!==n.length||n.some((function(n,t){return n!==e[t]}))}function po(e,n){return"function"==typeof n?n(e):n}function bo(e){var n=e.title,t=e.alerts,r=e.fields,o=e.onCancel,i=e.onSubmit,s=uo({}),u=s[0],a=s[1],c=ao();return function(e,n){var t=so(Yr++,4);!mr.__s&&vo(t.__H,n)&&(t.__=e,t.__H=n,Zr.__h.push(t))}((function(){var e;return null===(e=c.current)||void 0===e?void 0:e.focus()}),[]),Or(Jr,null,Or(Ar,null,Or("h3",{style:Gr.WindowHeader},n),t.map((function(e){return Or("p",{style:Gr.Alert[e.type]},function(e){var n=e.message;e.messageCode;var t=e.messageParams;return n.replace(/\{\w+\}/gi,(function(e){return t[e.substr(1,e.length-2)]}))}(e))})),Or("form",{onSubmit:function(e){e.preventDefault(),i(u)}},Object.entries(r).map((function(e,n){var t=e[0],r=e[1],o=r.type,i=r.label,s=r.placeholder;return Or("label",{style:Gr.Label},i?"".concat(i,": "):"",Or("input",{ref:0===n?c:void 0,type:o,name:t,autoComplete:"on",style:Gr.Input,autoFocus:!0,placeholder:s,value:u[t]||"",onInput:function(e){var n,r;return a(Object.assign(Object.assign({},u),((n={})[t]=function(e,n){switch(e){case"email":return n.toLowerCase();case"otp":return n.toUpperCase();default:return n}}(o,null===(r=e.target)||void 0===r?void 0:r.value),n)))}}))})))),Or("div",{style:Gr.ButtonsDiv},Or("button",{type:"submit",style:Gr.Button,onClick:function(){return i(u)}},"Submit"),Or("button",{style:Gr.Button,onClick:o},"Cancel")))}var yo=function(e){function n(n){var t=e.call(this,n)||this;return t.observer=function(e){return t.setState({userInteraction:e})},t.state={userInteraction:void 0},t}return m(n,e),n.prototype.componentDidMount=function(){this.subscription=u(this.props.db.cloud.userInteraction).subscribe(this.observer)},n.prototype.componentWillUnmount=function(){this.subscription&&(this.subscription.unsubscribe(),delete this.subscription)},n.prototype.render=function(e,n){var t=n.userInteraction;return t?Or(bo,Object.assign({},t)):null},n}(Cr);function mo(e){var n=document.createElement("div");document.body.appendChild(n),function(e,n,t){var r,o,i;mr.__&&mr.__(e,n),o=(r="function"==typeof t)?null:t&&t.__k||n.__k,i=[],Fr(n,e=(!r&&t||n).__k=Or(Ar,null,[e]),o||Sr,Sr,void 0!==n.ownerSVGElement,!r&&t?[t]:o?null:n.firstChild?kr.slice.call(n.childNodes):null,i,!r&&t?t:o?o.__e:n.firstChild,r),Kr(i,e)}(Or(yo,{db:e.vip}),n);var t=!1;return{unsubscribe:function(){n.remove(),t=!0},get closed(){return t}}}function go(e){var n=new WeakMap;return function(t){var r=n.get(t);return r||(r=e(t),n.set(t,r)),r}}function _o(e,n){var t=n,r=u(e).pipe(h((function(e){return t=e})),p({resetOnRefCountZero:function(){return b(1e3)}})),o=new a((function(e){var n=!1,o=r.subscribe({next:function(t){n=!0,e.next(t)},error:function(n){e.error(n)},complete:function(){e.complete()}});return n||o.closed||e.next(t),o}));return o.getValue=function(){return t},o}var wo=go((function(e){return _o(n((function(){return e.roles.where({realmId:"rlm-public"}).toArray().then((function(e){for(var n={},t=0,r=e.slice().sort((function(e,n){return(e.sortOrder||0)-(n.sortOrder||0)}));t<r.length;t++){var o=r[t];n[o.name]=o}return n}))})),{})})),So=go((function(e){return new r(wn)})),ko=go((function(e){return _o(So(e._novip).pipe(Ze((function(t){return n((function(){return e.transaction("r","realms","members",(function(){return Promise.all([e.members.where({userId:t.userId}).toArray(),e.realms.toArray(),t.userId]).then((function(e){return{selfMembers:e[0],realms:e[1],userId:e[2]}}))}))}))}))),{selfMembers:[],realms:[],get userId(){return e.cloud.currentUserId}})}));function xo(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];if(0===e.length)return{};var t=e.reduce((function(e,n){for(var t=Object.assign({},e),r=0,o=Object.entries(n);r<o.length;r++){var i=o[r],s=i[0],u=i[1];if(s in t&&t[s]){if("*"===t[s])continue;if("*"===u)t[s]="*";else if(Array.isArray(u)&&Array.isArray(t[s])){var a=t,c=a[s];a[s]=S([],new Set(S(S([],c,!0),u,!0)),!0)}else if("object"==typeof u&&u&&"object"==typeof t[s])for(var l=t[s],f=0,d=Object.entries(u);f<d.length;f++){var h=d[f],v=h[0],p=h[1];"*"!==l[v]&&("*"===p?l[v]="*":Array.isArray(l[v])&&Array.isArray(p)&&(l[v]=S([],new Set(S(S([],l[v],!0),p,!0)),!0)))}}else t[s]=n[s]}return t}));return t}var Io=go((function(e){var n=_o(d([ko(e._novip),wo(e._novip)]).pipe($e((function(e){var n=e[0];return{selfMembers:n.selfMembers,realms:n.realms,userId:n.userId,globalRoles:e[1]}}))),{selfMembers:[],realms:[],userId:wn.userId,globalRoles:{}});return function(e,n){var t,r=e.pipe(h((function(e){return t=n(e)})));return r.getValue=function(){return void 0!==t?t:t=n(e.getValue())},r}(n,(function(e){var n,t=e.selfMembers,r=e.realms,o=e.userId,i=e.globalRoles,s=r.map((function(e){var n=t.filter((function(n){return n.realmId===e.realmId})),r=n.map((function(e){return e.permissions})).filter((function(e){return e})),s=Pn(n.map((function(e){return e.roles})).filter((function(e){return e}))).map((function(e){return i[e]})).filter((function(e){return e})).map((function(e){return e.permissions}));return Object.assign(Object.assign({},e),{permissions:e.owner===o?{manage:"*"}:xo.apply(void 0,S(S([],r,!1),s,!1))})})).reduce((function(e,n){var t;return Object.assign(Object.assign({},e),((t={})[n.realmId]=n,t))}),((n={})[o]={realmId:o,owner:o,name:o,permissions:{manage:"*"}},n));return s}))})),Eo=function(){function e(e,n,t){this.permissions=e||{},this.tableName=n,this.isOwner=t}return e.prototype.add=function(){for(var e,n=this,t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return"*"===this.permissions.manage||(!!(null===(e=this.permissions.manage)||void 0===e?void 0:e.includes(this.tableName))||("*"===this.permissions.add||!!t.every((function(e){var t;return null===(t=n.permissions.add)||void 0===t?void 0:t.includes(e)}))))},e.prototype.update=function(){for(var e,n,t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];if(this.isOwner||"*"===this.permissions.manage)return!0;if(null===(e=this.permissions.manage)||void 0===e?void 0:e.includes(this.tableName))return!0;if("*"===this.permissions.update)return t.every((function(e){return"owner"!==e}));var o=null===(n=this.permissions.update)||void 0===n?void 0:n[this.tableName];return"*"===o?t.every((function(e){return"owner"!==e})):t.every((function(e){return null==o?void 0:o.some((function(n){return n===e||"*"===n&&"owner"!==e}))}))},e.prototype.delete=function(){var e;return!(!this.isOwner&&"*"!==this.permissions.manage)||!!(null===(e=this.permissions.manage)||void 0===e?void 0:e.includes(this.tableName))},e}();var Oo=go((function(e){var t=So(e._novip).pipe(f((function(t){return n((function(){return e.members.where({email:t.email||""}).toArray()}))}))),r=Io(e._novip),o=ko(e._novip);return _o(d([t,o,r]).pipe(h((function(e){var n=e[0],t=e[1],r=e[2],o=function(e,n){var t;return Object.assign(Object.assign({},e),((t={})[n.id]=Object.assign(Object.assign({},n),{realm:r[n.realmId]}),t))},i=n.reduce(o,{}),s=t.selfMembers.reduce(o,i);return Object.values(s).filter((function(e){return!e.accepted}))}))),[])}));function To(e){return"rlm~"+e}function Ao(e){return e.startsWith("rlm~")?e.substr(4):null}var Co={nameSuffix:!0};function Po(t){var s=this,a=t.name,c=So(t),l=[],f=!1,h=null;t.on("ready",(function(e){return k(s,void 0,void 0,(function(){var n;return w(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,y(e)];case 1:return t.sent(),[3,3];case 2:return n=t.sent(),console.error(n),[3,3];case 3:return[2]}}))}))}),!0);var v,p=!1;function b(){if(p)throw new e.DatabaseClosedError}function y(t){var r,s,u,a,v,y;return k(this,void 0,void 0,(function(){var m,g,_,S,x=this;return w(this,(function(I){switch(I.label){case 0:return p=!1,m=Pt(t),Lt||((null===(r=m.cloud.options)||void 0===r?void 0:r.customLoginGui)||l.push(mo(t)),l.push(function(e){var n=e.cloud.webSocketStatus.value,t=e.cloud.webSocketStatus.pipe(Ze((function(e){var t=n;n=e;var r=i(e);switch(e){case"disconnected":return er.value?r.pipe(Me(500)):r;case"connecting":return"not-started"===t||"error"===t?r:r.pipe(Me(4e3));default:return r}})));return d([t,e.syncStateChangedEvent.pipe(Ye({phase:"initial"})),nr]).pipe($e((function(n){var t=n[0],r=n[1],o=n[2],i=r.phase,s=r.error,u=r.progress,a=t;return"error"===i&&(a="error"),"not-started"===t&&("pushing"!==i&&"pulling"!==i||(a="connecting")),"error"!==e.cloud.syncState.value.phase||"pushing"!==r.phase&&"pulling"!==r.phase||(a="connecting"),o||(a="disconnected"),{phase:i,error:s,progress:u,status:gt?a:"offline"}})))}(m).subscribe(t.cloud.syncState))),m.tables.every((function(e){return e.core}))||Nt(),"serviceWorker"in navigator?[4,navigator.serviceWorker.getRegistrations()]:[3,2];case 1:return _=I.sent(),[3,3];case 2:_=[],I.label=3;case 3:return g=_,[4,m.transaction("rw",m.$syncState,(function(){return k(x,void 0,void 0,(function(){var e,n,t,r,o,i,s,u,a,c,l,d,h,v,p,b;return w(this,(function(y){switch(y.label){case 0:return t=m.cloud,r=t.options,o=t.schema,[4,Promise.all([m.getOptions(),m.getSchema(),m.getPersistedSyncState()])];case 1:return i=y.sent(),s=i[0],u=i[1],a=i[2],f?[3,2]:(m.cloud.options=s||null,[3,4]);case 2:if(s&&JSON.stringify(s)===JSON.stringify(r))return[3,4];if(!r)throw new Error("Internal error");return[4,m.$syncState.put(r,"options")];case 3:y.sent(),y.label=4;case 4:return(null===(e=m.cloud.options)||void 0===e?void 0:e.tryUseServiceWorker)&&"serviceWorker"in navigator&&g.length>0&&!Rt?(console.debug("Dexie Cloud Addon: Using service worker"),m.cloud.usingServiceWorker=!0):((null===(n=m.cloud.options)||void 0===n?void 0:n.tryUseServiceWorker)&&!Lt&&console.debug("dexie-cloud-addon: Not using service worker.",0===g.length?"No SW registrations found.":"serviceWorker"in navigator&&Rt?"Avoiding SW background sync and SW periodic bg sync for this browser due to browser bugs.":"navigator.serviceWorker not present"),m.cloud.usingServiceWorker=!1),yr(o,m.cloud.options),yr(u,m.cloud.options),o?[3,5]:(m.cloud.schema=u||null,[3,7]);case 5:if(u&&JSON.stringify(u)===JSON.stringify(o))return[3,7];for(c=u||{},l=0,d=Object.entries(o);l<d.length;l++)h=d[l],v=h[0],p=h[1],(b=c[v])?(b.markedForSync=p.markedForSync,p.deleted=b.deleted,b.generatedGlobalId=p.generatedGlobalId):c[v]=Object.assign({},p);return[4,m.$syncState.put(c,"schema")];case 6:y.sent(),Object.assign(o,c),y.label=7;case 7:return[2,null==a?void 0:a.initiallySynced]}}))}))}))];case 4:return(S=I.sent())&&m.setInitiallySynced(!0),function(n){for(var t,r,o=0,i=n.tables;o<i.length;o++){var s=i[o];if(null===(r=null===(t=n.cloud.schema)||void 0===t?void 0:t[s.name])||void 0===r?void 0:r.markedForSync){if(s.schema.primKey.auto)throw new e.SchemaError("Table ".concat(s.name," is both autoIncremented and synced. ")+"Use db.cloud.configure({unsyncedTables: [".concat(JSON.stringify(s.name),"]}) to blacklist it from sync"));if(!s.schema.primKey.keyPath)throw new e.SchemaError("Table ".concat(s.name," cannot be both synced and outbound. ")+"Use db.cloud.configure({unsyncedTables: [".concat(JSON.stringify(s.name),"]}) to blacklist it from sync"))}}}(m),!(null===(s=m.cloud.options)||void 0===s?void 0:s.databaseUrl)||S?[3,6]:[4,Zt(m,m.cloud.options,m.cloud.schema)];case 5:I.sent(),m.setInitiallySynced(!0),I.label=6;case 6:return b(),Lt?[3,8]:(l.push(n((function(){return m.getCurrentUser()})).subscribe(c)),l.push(n((function(){return m.getPersistedSyncState()})).subscribe(m.cloud.persistedSyncState)),[4,d([c.pipe(Je(1),He(1)),m.cloud.persistedSyncState.pipe(Je(1),He(1))]).toPromise()]);case 7:I.sent(),I.label=8;case 8:return(null===(u=m.cloud.options)||void 0===u?void 0:u.requireAuth)?[4,_n(m)]:[3,10];case 9:I.sent(),I.label=10;case 10:return h&&h.stop(),h=null,b(),m.cloud.usingServiceWorker&&(null===(a=m.cloud.options)||void 0===a?void 0:a.databaseUrl)?(tn(m,"push").catch((function(){})),function(e){var n;return k(this,void 0,void 0,(function(){var t,r,o;return w(this,(function(i){switch(i.label){case 0:return i.trys.push([0,8,,9]),[4,navigator.serviceWorker.ready];case 1:if(!(t=i.sent().periodicSync))return[3,6];i.label=2;case 2:return i.trys.push([2,4,,5]),[4,t.register("dexie-cloud:".concat(e.name),null===(n=e.cloud.options)||void 0===n?void 0:n.periodicSync)];case 3:return i.sent(),console.debug("Dexie Cloud: Successfully registered periodicsync event for ".concat(e.name)),[3,5];case 4:return r=i.sent(),console.debug("Dexie Cloud: Failed to register periodic sync. Your PWA must be installed to allow background sync.",r),[3,5];case 5:return[3,7];case 6:console.debug("Dexie Cloud: periodicSync not supported."),i.label=7;case 7:return[3,9];case 8:return o=i.sent(),console.debug("Dexie Cloud: Could not register periodicSync for ".concat(e.name),o),[3,9];case 9:return[2]}}))}))}(m).catch((function(){}))):(null===(v=m.cloud.options)||void 0===v?void 0:v.databaseUrl)&&m.cloud.schema&&!Lt&&((h=br(m,m.cloud.options,m.cloud.schema)).start(),rn(m,"push")),b(),Lt||l.push(o(self,"online").subscribe((function(){console.debug("online!"),m.syncStateChangedEvent.next({phase:"not-in-sync"}),rn(m,"push")})),o(self,"offline").subscribe((function(){console.debug("offline!"),m.syncStateChangedEvent.next({phase:"offline"})}))),"undefined"!=typeof window&&!Lt&&(null===(y=m.cloud.options)||void 0===y?void 0:y.databaseUrl)&&l.push(lr(m)),[2]}}))}))}!function(e,n){e.on.close.subscribe(n);var t=e.close;e.close=function(){t.call(this),n()}}(t,(function(){l.forEach((function(e){return e.unsubscribe()})),p=!0,h&&h.stop(),h=null,c.next(wn)})),t.cloud={version:"4.0.0-beta.18",options:Object.assign({},Co),schema:null,serverState:null,get currentUserId(){return c.value.userId||wn.userId},currentUser:c,syncState:new r({phase:"initial",status:"not-started"}),persistedSyncState:new r(void 0),userInteraction:new r(void 0),webSocketStatus:new r("not-started"),login:function(e){return k(this,void 0,void 0,(function(){var n;return w(this,(function(r){switch(r.label){case 0:return[4,(n=Pt(t)).cloud.sync()];case 1:return r.sent(),[4,_n(n,e)];case 2:return r.sent(),[2]}}))}))},invites:Oo(t),roles:wo(t),configure:function(e){var n,r;e=t.cloud.options=Object.assign(Object.assign({},t.cloud.options),e),f=!0,e.databaseUrl&&e.nameSuffix&&(t.name="".concat(a,"-").concat((n=e.databaseUrl,"/"===(r=new URL(n)).pathname?r.hostname.split(".")[0]:r.pathname.split("/")[1])),Pt(t).reconfigure()),yr(t.cloud.schema,t.cloud.options)},sync:function(e){var r=void 0===e?{wait:!0,purpose:"push"}:e,o=r.wait,i=r.purpose;return k(this,void 0,void 0,(function(){var e,r,s,a,c=this;return w(this,(function(l){switch(l.label){case 0:return void 0===o&&(o=!0),e=Pt(t),"pull"!==i?[3,3]:(r=e.cloud.persistedSyncState.value,rn(e,i),o?[4,e.cloud.persistedSyncState.pipe(Ge((function(e){return null!=(null==e?void 0:e.timestamp)&&(!r||e.timestamp>r.timestamp)})),He(1)).toPromise()]:[3,2]);case 1:if(null==(s=l.sent())?void 0:s.error)throw new Error("Sync error: "+s.error);l.label=2;case 2:return[3,6];case 3:return[4,fr(e)];case 4:return l.sent()?(a=e.cloud.persistedSyncState.value,rn(e,i),o?(console.debug("db.cloud.login() is waiting for sync completion..."),[4,u(n((function(){return k(c,void 0,void 0,(function(){var n,t;return w(this,(function(r){switch(r.label){case 0:return[4,fr(e)];case 1:return n=r.sent(),[4,e.getPersistedSyncState()];case 2:if((null==(t=r.sent())?void 0:t.timestamp)!==(null==a?void 0:a.timestamp)&&(null==t?void 0:t.error))throw new Error("Sync error: "+t.error);return[2,n]}}))}))}))).pipe(Ge((function(e){return!e})),He(1)).toPromise()]):[3,6]):[3,6];case 5:l.sent(),console.debug("Done waiting for sync completion because we have nothing to push anymore"),l.label=6;case 6:return[2]}}))}))},permissions:function(e,n){return function(e,n,t){if(!n)throw new TypeError("Cannot check permissions of undefined or null. A Dexie Cloud object with realmId and owner expected.");var r=n.owner,o=n.realmId;if(!t){if("function"!=typeof n.table)throw new TypeError("Missing 'table' argument to permissions and table could not be extracted from entity");t=n.table()}var i=Io(e),s=function(n){var i=n[o||e.cloud.currentUserId];return i?new Eo(i.permissions,t,o===e.cloud.currentUserId||r===e.cloud.currentUserId):new Eo({},t,!r||r===e.cloud.currentUserId)},u=i.pipe($e(s));return u.getValue=function(){return s(i.getValue())},u}(t._novip,e,n)}},t.Version.prototype._parseStoresSpec=e.override(t.Version.prototype._parseStoresSpec,(function(e){return Yt(e,t)})),t.Table.prototype.newId=function(e){var n=(void 0===e?{}:e).colocateWith,r=n&&n.substr(n.length-3);return Kt(t.cloud.schema[this.name].idPrefix||"",r)},t.Table.prototype.idPrefix=function(){var e,n;return(null===(n=null===(e=this.db.cloud.schema)||void 0===e?void 0:e[this.name])||void 0===n?void 0:n.idPrefix)||""},t.use(Jt({currentUserObservable:t.cloud.currentUser,db:Pt(t)})),t.use((v=Pt(t),{stack:"dbcore",name:"implicitPropSetterMiddleware",level:1,create:function(e){return Object.assign(Object.assign({},e),{table:function(n){var t=e.table(n);return Object.assign(Object.assign({},t),{mutate:function(e){var r,o,i,s;if(e.trans.disableChangeTracking)return t.mutate(e);var u=e.trans;if((null===(o=null===(r=v.cloud.schema)||void 0===r?void 0:r[n])||void 0===o?void 0:o.markedForSync)&&("add"===e.type||"put"===e.type))for(var a=0,c=e.values;a<c.length;a++){var l=c[a];l.owner||(l.owner=u.currentUser.userId),l.realmId||(l.realmId=u.currentUser.userId);var f=null===(s=(i=t.schema.primaryKey).extractKey)||void 0===s?void 0:s.call(i,l);"string"==typeof f&&"#"===f[0]&&"put"===e.type&&(delete e.criteria,delete e.changeSpec,delete e.changeSpecs,l.$ts=Date.now())}return t.mutate(e)}})}})}})),t.use(Ht(Pt(t)))}Po.version="4.0.0-beta.18",e.Cloud=Po;export{Po as default,Po as dexieCloud,Ao as getTiedObjectId,To as getTiedRealmId};
|