@openmrs/esm-offline 3.2.0 → 3.2.1-pre.933
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/openmrs-esm-offline.js +1 -1
- package/dist/openmrs-esm-offline.js.map +1 -1
- package/package.json +6 -6
- package/src/sync.ts +152 -24
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
System.register(["@openmrs/esm-api","@openmrs/esm-state"],(function(e,t){var n={},r={};return{setters:[function(e){n.getLoggedInUser=e.getLoggedInUser},function(e){r.createGlobalStore=e.createGlobalStore}],execute:function(){e((()=>{var e={968:(e,t,n)=>{const r=n(577).R;t.s=function(e){if(e||(e=1),!n.y.meta||!n.y.meta.url)throw console.error("__system_context__",n.y),Error("systemjs-webpack-interop was provided an unknown SystemJS context. Expected context.meta.url, but none was provided");n.p=r(n.y.meta.url,e)}},577:(e,t,n)=>{t.R=function(e,t){var n=document.createElement("a");n.href=e;for(var r="/"===n.pathname[0]?n.pathname:"/"+n.pathname,i=0,o=r.length;i!==t&&o>=0;)"/"===r[--o]&&i++;if(i!==t)throw Error("systemjs-webpack-interop: rootDirectoryLevel ("+t+") is greater than the number of directories ("+i+") in the URL path "+e);var a=r.slice(0,o+1);return n.protocol+"//"+n.host+a};Number.isInteger},766:e=>{"use strict";e.exports=n},685:e=>{"use strict";e.exports=r}},i={};function o(t){var n=i[t];if(void 0!==n)return n.exports;var r=i[t]={exports:{}};return e[t](r,r.exports,o),r.exports}o.y=t,o.d=(e,t)=>{for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e;o.g.importScripts&&(e=o.g.location+"");var t=o.g.document;if(!e&&t&&(t.currentScript&&(e=t.currentScript.src),!e)){var n=t.getElementsByTagName("script");n.length&&(e=n[n.length-1].src)}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),o.p=e})();var a={};return(0,o(968).s)(1),(()=>{"use strict";o.r(a),o.d(a,{deleteSynchronizationItem:()=>xr,dispatchNetworkRequestFailed:()=>k,generateOfflineUuid:()=>Tr,getOfflineDb:()=>dr,getOfflinePatientDataStore:()=>Fr,getOfflineSynchronizationStore:()=>yr,getOmrsServiceWorker:()=>y,getSynchronizationItems:()=>kr,getSynchronizationItemsFor:()=>_r,isOfflineUuid:()=>Rr,loadPersistedPatientDataSyncState:()=>Ur,messageOmrsServiceWorker:()=>b,offlineUuidPrefix:()=>Dr,omrsOfflineCachingStrategyHttpHeaderName:()=>g,omrsOfflineResponseBodyHttpHeaderName:()=>v,omrsOfflineResponseStatusHttpHeaderName:()=>m,patchXMLHttpRequest:()=>S,queueSynchronizationItem:()=>wr,queueSynchronizationItemFor:()=>br,registerOfflinePatientHandler:()=>qr,registerOmrsServiceWorker:()=>p,runSynchronization:()=>vr,setupOfflineSync:()=>Sr,subscribeNetworkRequestFailed:()=>x,syncOfflinePatientData:()=>Nr});try{self["workbox:window:6.2.4"]&&_()}catch(e){}function e(e,t){return new Promise((function(n){var r=new MessageChannel;r.port1.onmessage=function(e){n(e.data)},e.postMessage(t,[r.port2])}))}function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function n(e,n){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,n){if(e){if("string"==typeof e)return t(e,n);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?t(e,n):void 0}}(e))||n&&e&&"number"==typeof e.length){r&&(e=r);var i=0;return function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=e[Symbol.iterator]()).next.bind(r)}try{self["workbox:core:6.2.4"]&&_()}catch(e){}var r=function(){var e=this;this.promise=new Promise((function(t,n){e.resolve=t,e.reject=n}))};function i(e,t){var n=location.href;return new URL(e,n).href===new URL(t,n).href}var u=function(e,t){this.type=e,Object.assign(this,t)};function s(e,t,n){return n?t?t(e):e:(e&&e.then||(e=Promise.resolve(e)),t?e.then(t):e)}function c(){}var l={type:"SKIP_WAITING"};function f(e,t){if(!t)return e&&e.then?e.then(c):Promise.resolve()}var h=function(t){var n,o;function a(e,n){var o,a;return void 0===n&&(n={}),(o=t.call(this)||this).nn={},o.tn=0,o.rn=new r,o.en=new r,o.on=new r,o.un=0,o.an=new Set,o.cn=function(){var e=o.fn,t=e.installing;o.tn>0||!i(t.scriptURL,o.sn.toString())||performance.now()>o.un+6e4?(o.vn=t,e.removeEventListener("updatefound",o.cn)):(o.hn=t,o.an.add(t),o.rn.resolve(t)),++o.tn,t.addEventListener("statechange",o.ln)},o.ln=function(e){var t=o.fn,n=e.target,r=n.state,i=n===o.vn,a={sw:n,isExternal:i,originalEvent:e};!i&&o.mn&&(a.isUpdate=!0),o.dispatchEvent(new u(r,a)),"installed"===r?o.wn=self.setTimeout((function(){"installed"===r&&t.waiting===n&&o.dispatchEvent(new u("waiting",a))}),200):"activating"===r&&(clearTimeout(o.wn),i||o.en.resolve(n))},o.dn=function(e){var t=o.hn,n=t!==navigator.serviceWorker.controller;o.dispatchEvent(new u("controlling",{isExternal:n,originalEvent:e,sw:t,isUpdate:o.mn})),n||o.on.resolve(t)},o.gn=(a=function(e){var t=e.data,n=e.ports,r=e.source;return s(o.getSW(),(function(){o.an.has(r)&&o.dispatchEvent(new u("message",{data:t,originalEvent:e,ports:n,sw:r}))}))},function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];try{return Promise.resolve(a.apply(this,e))}catch(e){return Promise.reject(e)}}),o.sn=e,o.nn=n,navigator.serviceWorker.addEventListener("message",o.gn),o}o=t,(n=a).prototype=Object.create(o.prototype),n.prototype.constructor=n,n.__proto__=o;var c,h=a.prototype;return h.register=function(e){var t=(void 0===e?{}:e).immediate,n=void 0!==t&&t;try{var r=this;return function(e,t){var n=e();return n&&n.then?n.then(t):t()}((function(){if(!n&&"complete"!==document.readyState)return f(new Promise((function(e){return window.addEventListener("load",e)})))}),(function(){return r.mn=Boolean(navigator.serviceWorker.controller),r.yn=r.pn(),s(r.bn(),(function(e){r.fn=e,r.yn&&(r.hn=r.yn,r.en.resolve(r.yn),r.on.resolve(r.yn),r.yn.addEventListener("statechange",r.ln,{once:!0}));var t=r.fn.waiting;return t&&i(t.scriptURL,r.sn.toString())&&(r.hn=t,Promise.resolve().then((function(){r.dispatchEvent(new u("waiting",{sw:t,wasWaitingBeforeRegister:!0}))})).then((function(){}))),r.hn&&(r.rn.resolve(r.hn),r.an.add(r.hn)),r.fn.addEventListener("updatefound",r.cn),navigator.serviceWorker.addEventListener("controllerchange",r.dn),r.fn}))}))}catch(e){return Promise.reject(e)}},h.update=function(){try{return this.fn?f(this.fn.update()):void 0}catch(e){return Promise.reject(e)}},h.getSW=function(){return void 0!==this.hn?Promise.resolve(this.hn):this.rn.promise},h.messageSW=function(t){try{return s(this.getSW(),(function(n){return e(n,t)}))}catch(e){return Promise.reject(e)}},h.messageSkipWaiting=function(){this.fn&&this.fn.waiting&&e(this.fn.waiting,l)},h.pn=function(){var e=navigator.serviceWorker.controller;return e&&i(e.scriptURL,this.sn.toString())?e:void 0},h.bn=function(){try{var e=this;return function(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}((function(){return s(navigator.serviceWorker.register(e.sn,e.nn),(function(t){return e.un=performance.now(),t}))}),(function(e){throw e}))}catch(e){return Promise.reject(e)}},(c=[{key:"active",get:function(){return this.en.promise}},{key:"controlling",get:function(){return this.on.promise}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(a.prototype,c),a}(function(){function e(){this.Pn=new Map}var t=e.prototype;return t.addEventListener=function(e,t){this.Sn(e).add(t)},t.removeEventListener=function(e,t){this.Sn(e).delete(t)},t.dispatchEvent=function(e){e.target=this;for(var t,r=n(this.Sn(e.type));!(t=r()).done;)(0,t.value)(e)},t.Sn=function(e){return this.Pn.has(e)||this.Pn.set(e,new Set),this.Pn.get(e)},e}());let d;function p(e,t){if(void 0!==d)return console.warn(`The application's Service Worker has already been registered. The new service worker at ${e} will not be registered.`),d;if(!("serviceWorker"in navigator))throw new Error("Registering the Service Worker is not possible due to missing browser capabilities.");const n=new h(e,t);return d=n.register().then((()=>n)),d}function y(){var e;return null!==(e=d)&&void 0!==e?e:Promise.resolve(void 0)}const v="x-omrs-offline-response-body",m="x-omrs-offline-response-status",g="x-omrs-offline-caching-strategy";async function b(e){const t=await y();return t?await t.messageSW(e):{success:!1,result:void 0,error:"No service worker has been registered. This is typically the case when the application has been built without offline-related features."}}const w="openmrs:network-request-failed";function k(e){window.dispatchEvent(new CustomEvent(w,{detail:e}))}function x(e){const t=t=>e(t.detail);return window.addEventListener(w,t),()=>window.removeEventListener(w,t)}function S(){const e=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.send=function(...t){return e.apply(this,t)}}var P=function(){return(P=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};function E(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;var r=Array(e),i=0;for(t=0;t<n;t++)for(var o=arguments[t],a=0,u=o.length;a<u;a++,i++)r[i]=o[a];return r}var O=Object.keys,j=Array.isArray,A="undefined"!=typeof self?self:"undefined"!=typeof window?window:global;function C(e,t){return"object"!=typeof t||O(t).forEach((function(n){e[n]=t[n]})),e}"undefined"==typeof Promise||A.Promise||(A.Promise=Promise);var I=Object.getPrototypeOf,K={}.hasOwnProperty;function D(e,t){return K.call(e,t)}function T(e,t){"function"==typeof t&&(t=t(I(e))),O(t).forEach((function(n){B(e,n,t[n])}))}var R=Object.defineProperty;function B(e,t,n,r){R(e,t,C(n&&D(n,"get")&&"function"==typeof n.get?{get:n.get,set:n.set,configurable:!0}:{value:n,configurable:!0,writable:!0},r))}function F(e){return{from:function(t){return e.prototype=Object.create(t.prototype),B(e.prototype,"constructor",e),{extend:T.bind(null,e.prototype)}}}}var q=Object.getOwnPropertyDescriptor;function N(e,t){var n;return q(e,t)||(n=I(e))&&N(n,t)}var M=[].slice;function U(e,t,n){return M.call(e,t,n)}function L(e,t){return t(e)}function W(e){if(!e)throw new Error("Assertion Failed")}function H(e){A.setImmediate?setImmediate(e):setTimeout(e,0)}function z(e,t){return e.reduce((function(e,n,r){var i=t(n,r);return i&&(e[i[0]]=i[1]),e}),{})}function V(e,t){if(D(e,t))return e[t];if(!t)return e;if("string"!=typeof t){for(var n=[],r=0,i=t.length;r<i;++r){var o=V(e,t[r]);n.push(o)}return n}var a=t.indexOf(".");if(-1!==a){var u=e[t.substr(0,a)];return void 0===u?void 0:V(u,t.substr(a+1))}}function G(e,t,n){if(e&&void 0!==t&&(!("isFrozen"in Object)||!Object.isFrozen(e)))if("string"!=typeof t&&"length"in t){W("string"!=typeof n&&"length"in n);for(var r=0,i=t.length;r<i;++r)G(e,t[r],n[r])}else{var o=t.indexOf(".");if(-1!==o){var a=t.substr(0,o),u=t.substr(o+1);if(""===u)void 0===n?j(e)&&!isNaN(parseInt(a))?e.splice(a,1):delete e[a]:e[a]=n;else{var s=e[a];s||(s=e[a]={}),G(s,u,n)}}else void 0===n?j(e)&&!isNaN(parseInt(t))?e.splice(t,1):delete e[t]:e[t]=n}}function Q(e,t){"string"==typeof t?G(e,t,void 0):"length"in t&&[].map.call(t,(function(t){G(e,t,void 0)}))}function Y(e){var t={};for(var n in e)D(e,n)&&(t[n]=e[n]);return t}var X=[].concat;function $(e){return X.apply([],e)}var J="Boolean,String,Date,RegExp,Blob,File,FileList,ArrayBuffer,DataView,Uint8ClampedArray,ImageData,Map,Set".split(",").concat($([8,16,32,64].map((function(e){return["Int","Uint","Float"].map((function(t){return t+e+"Array"}))})))).filter((function(e){return A[e]})),Z=J.map((function(e){return A[e]})),ee=z(J,(function(e){return[e,!0]}));function te(e){if(!e||"object"!=typeof e)return e;var t;if(j(e)){t=[];for(var n=0,r=e.length;n<r;++n)t.push(te(e[n]))}else if(Z.indexOf(e.constructor)>=0)t=e;else for(var i in t=e.constructor?Object.create(e.constructor.prototype):{},e)D(e,i)&&(t[i]=te(e[i]));return t}var ne={}.toString;function re(e){return ne.call(e).slice(8,-1)}var ie=function(e,t){return"Array"===t?""+e.map((function(e){return ie(e,re(e))})):"ArrayBuffer"===t?""+new Uint8Array(e):"Date"===t?e.getTime():ArrayBuffer.isView(e)?""+new Uint8Array(e.buffer):e};function oe(e,t,n,r){return n=n||{},r=r||"",O(e).forEach((function(i){if(D(t,i)){var o=e[i],a=t[i];if("object"==typeof o&&"object"==typeof a&&o&&a){var u=re(o),s=re(a);u===s?ee[u]?ie(o,u)!==ie(a,s)&&(n[r+i]=t[i]):oe(o,a,n,r+i+"."):n[r+i]=t[i]}else o!==a&&(n[r+i]=t[i])}else n[r+i]=void 0})),O(t).forEach((function(i){D(e,i)||(n[r+i]=t[i])})),n}var ae="undefined"!=typeof Symbol&&Symbol.iterator,ue=ae?function(e){var t;return null!=e&&(t=e[ae])&&t.apply(e)}:function(){return null},se={};function ce(e){var t,n,r,i;if(1===arguments.length){if(j(e))return e.slice();if(this===se&&"string"==typeof e)return[e];if(i=ue(e)){for(n=[];!(r=i.next()).done;)n.push(r.value);return n}if(null==e)return[e];if("number"==typeof(t=e.length)){for(n=new Array(t);t--;)n[t]=e[t];return n}return[e]}for(t=arguments.length,n=new Array(t);t--;)n[t]=arguments[t];return n}var le="undefined"!=typeof Symbol?function(e){return"AsyncFunction"===e[Symbol.toStringTag]}:function(){return!1},fe="undefined"!=typeof location&&/^(http|https):\/\/(localhost|127\.0\.0\.1)/.test(location.href);function he(e,t){fe=e,de=t}var de=function(){return!0},pe=!new Error("").stack;function ye(){if(pe)try{throw new Error}catch(e){return e}return new Error}function ve(e,t){var n=e.stack;return n?(t=t||0,0===n.indexOf(e.name)&&(t+=(e.name+e.message).split("\n").length),n.split("\n").slice(t).filter(de).map((function(e){return"\n"+e})).join("")):""}var me=["Unknown","Constraint","Data","TransactionInactive","ReadOnly","Version","NotFound","InvalidState","InvalidAccess","Abort","Timeout","QuotaExceeded","Syntax","DataClone"],ge=["Modify","Bulk","OpenFailed","VersionChange","Schema","Upgrade","InvalidTable","MissingAPI","NoSuchDatabase","InvalidArgument","SubTransaction","Unsupported","Internal","DatabaseClosed","PrematureCommit","ForeignAwait"].concat(me),be={VersionChanged:"Database version changed by other database connection",DatabaseClosed:"Database has been closed",Abort:"Transaction aborted",TransactionInactive:"Transaction has already completed or failed"};function we(e,t){this._e=ye(),this.name=e,this.message=t}function _e(e,t){return e+". Errors: "+Object.keys(t).map((function(e){return t[e].toString()})).filter((function(e,t,n){return n.indexOf(e)===t})).join("\n")}function ke(e,t,n,r){this._e=ye(),this.failures=t,this.failedKeys=r,this.successCount=n,this.message=_e(e,t)}function xe(e,t){this._e=ye(),this.name="BulkError",this.failures=t,this.message=_e(e,t)}F(we).from(Error).extend({stack:{get:function(){return this._stack||(this._stack=this.name+": "+this.message+ve(this._e,2))}},toString:function(){return this.name+": "+this.message}}),F(ke).from(we),F(xe).from(we);var Se=ge.reduce((function(e,t){return e[t]=t+"Error",e}),{}),Pe=we,Ee=ge.reduce((function(e,t){var n=t+"Error";function r(e,r){this._e=ye(),this.name=n,e?"string"==typeof e?(this.message=e+(r?"\n "+r:""),this.inner=r||null):"object"==typeof e&&(this.message=e.name+" "+e.message,this.inner=e):(this.message=be[t]||n,this.inner=null)}return F(r).from(Pe),e[t]=r,e}),{});Ee.Syntax=SyntaxError,Ee.Type=TypeError,Ee.Range=RangeError;var Oe=me.reduce((function(e,t){return e[t+"Error"]=Ee[t],e}),{}),je=ge.reduce((function(e,t){return-1===["Syntax","Type","Range"].indexOf(t)&&(e[t+"Error"]=Ee[t]),e}),{});function Ae(){}function Ce(e){return e}function Ie(e,t){return null==e||e===Ce?t:function(n){return t(e(n))}}function Ke(e,t){return function(){e.apply(this,arguments),t.apply(this,arguments)}}function De(e,t){return e===Ae?t:function(){var n=e.apply(this,arguments);void 0!==n&&(arguments[0]=n);var r=this.onsuccess,i=this.onerror;this.onsuccess=null,this.onerror=null;var o=t.apply(this,arguments);return r&&(this.onsuccess=this.onsuccess?Ke(r,this.onsuccess):r),i&&(this.onerror=this.onerror?Ke(i,this.onerror):i),void 0!==o?o:n}}function Te(e,t){return e===Ae?t:function(){e.apply(this,arguments);var n=this.onsuccess,r=this.onerror;this.onsuccess=this.onerror=null,t.apply(this,arguments),n&&(this.onsuccess=this.onsuccess?Ke(n,this.onsuccess):n),r&&(this.onerror=this.onerror?Ke(r,this.onerror):r)}}function Re(e,t){return e===Ae?t:function(n){var r=e.apply(this,arguments);C(n,r);var i=this.onsuccess,o=this.onerror;this.onsuccess=null,this.onerror=null;var a=t.apply(this,arguments);return i&&(this.onsuccess=this.onsuccess?Ke(i,this.onsuccess):i),o&&(this.onerror=this.onerror?Ke(o,this.onerror):o),void 0===r?void 0===a?void 0:a:C(r,a)}}function Be(e,t){return e===Ae?t:function(){return!1!==t.apply(this,arguments)&&e.apply(this,arguments)}}function Fe(e,t){return e===Ae?t:function(){var n=e.apply(this,arguments);if(n&&"function"==typeof n.then){for(var r=this,i=arguments.length,o=new Array(i);i--;)o[i]=arguments[i];return n.then((function(){return t.apply(r,o)}))}return t.apply(this,arguments)}}je.ModifyError=ke,je.DexieError=we,je.BulkError=xe;var qe={},Ne="undefined"==typeof Promise?[]:function(){var e=Promise.resolve();if("undefined"==typeof crypto||!crypto.subtle)return[e,e.__proto__,e];var t=crypto.subtle.digest("SHA-512",new Uint8Array([0]));return[t,t.__proto__,e]}(),Me=Ne[0],Ue=Ne[1],Le=Ne[2],We=Ue&&Ue.then,He=Me&&Me.constructor,ze=!!Le,Ve=!1,Ge=Le?function(){Le.then(vt)}:A.setImmediate?setImmediate.bind(null,vt):A.MutationObserver?function(){var e=document.createElement("div");new MutationObserver((function(){vt(),e=null})).observe(e,{attributes:!0}),e.setAttribute("i","1")}:function(){setTimeout(vt,0)},Qe=function(e,t){rt.push([e,t]),Xe&&(Ge(),Xe=!1)},Ye=!0,Xe=!0,$e=[],Je=[],Ze=null,et=Ce,tt={id:"global",global:!0,ref:0,unhandleds:[],onunhandled:Ut,pgp:!1,env:{},finalize:function(){this.unhandleds.forEach((function(e){try{Ut(e[0],e[1])}catch(e){}}))}},nt=tt,rt=[],it=0,ot=[];function at(e){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");this._listeners=[],this.onuncatched=Ae,this._lib=!1;var t=this._PSD=nt;if(fe&&(this._stackHolder=ye(),this._prev=null,this._numPrev=0),"function"!=typeof e){if(e!==qe)throw new TypeError("Not a function");return this._state=arguments[1],this._value=arguments[2],void(!1===this._state&<(this,this._value))}this._state=null,this._value=null,++t.ref,ct(this,e)}var ut={get:function(){var e=nt,t=Et;function n(n,r){var i=this,o=!e.global&&(e!==nt||t!==Et),a=o&&!Ct(),u=new at((function(t,u){ht(i,new st(qt(n,e,o,a),qt(r,e,o,a),t,u,e))}));return fe&&yt(u,this),u}return n.prototype=qe,n},set:function(e){B(this,"then",e&&e.prototype===qe?ut:{get:function(){return e},set:ut.set})}};function st(e,t,n,r,i){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof t?t:null,this.resolve=n,this.reject=r,this.psd=i}function ct(e,t){try{t((function(t){if(null===e._state){if(t===e)throw new TypeError("A promise cannot be resolved with itself.");var n=e._lib&&mt();t&&"function"==typeof t.then?ct(e,(function(e,n){t instanceof at?t._then(e,n):t.then(e,n)})):(e._state=!0,e._value=t,ft(e)),n&>()}}),lt.bind(null,e))}catch(t){lt(e,t)}}function lt(e,t){if(Je.push(t),null===e._state){var n=e._lib&&mt();t=et(t),e._state=!1,e._value=t,fe&&null!==t&&"object"==typeof t&&!t._promise&&function(n,r,i){try{(function(){var n=N(t,"stack");t._promise=e,B(t,"stack",{get:function(){return Ve?n&&(n.get?n.get.apply(t):n.value):e.stack}})}).apply(null,void 0)}catch(e){}}(),function(e){$e.some((function(t){return t._value===e._value}))||$e.push(e)}(e),ft(e),n&>()}}function ft(e){var t=e._listeners;e._listeners=[];for(var n=0,r=t.length;n<r;++n)ht(e,t[n]);var i=e._PSD;--i.ref||i.finalize(),0===it&&(++it,Qe((function(){0==--it&&bt()}),[]))}function ht(e,t){if(null!==e._state){var n=e._state?t.onFulfilled:t.onRejected;if(null===n)return(e._state?t.resolve:t.reject)(e._value);++t.psd.ref,++it,Qe(dt,[n,e,t])}else e._listeners.push(t)}function dt(e,t,n){try{Ze=t;var r,i=t._value;t._state?r=e(i):(Je.length&&(Je=[]),r=e(i),-1===Je.indexOf(i)&&function(e){for(var t=$e.length;t;)if($e[--t]._value===e._value)return void $e.splice(t,1)}(t)),n.resolve(r)}catch(e){n.reject(e)}finally{Ze=null,0==--it&&bt(),--n.psd.ref||n.psd.finalize()}}function pt(e,t,n){if(t.length===n)return t;var r="";if(!1===e._state){var i,o,a=e._value;null!=a?(i=a.name||"Error",o=a.message||a,r=ve(a,0)):(i=a,o=""),t.push(i+(o?": "+o:"")+r)}return fe&&((r=ve(e._stackHolder,2))&&-1===t.indexOf(r)&&t.push(r),e._prev&&pt(e._prev,t,n)),t}function yt(e,t){var n=t?t._numPrev+1:0;n<100&&(e._prev=t,e._numPrev=n)}function vt(){mt()&>()}function mt(){var e=Ye;return Ye=!1,Xe=!1,e}function gt(){var e,t,n;do{for(;rt.length>0;)for(e=rt,rt=[],n=e.length,t=0;t<n;++t){var r=e[t];r[0].apply(null,r[1])}}while(rt.length>0);Ye=!0,Xe=!0}function bt(){var e=$e;$e=[],e.forEach((function(e){e._PSD.onunhandled.call(null,e._value,e)}));for(var t=ot.slice(0),n=t.length;n;)t[--n]()}function wt(e){return new at(qe,!1,e)}function _t(e,t){var n=nt;return function(){var r=mt(),i=nt;try{return Tt(n,!0),e.apply(this,arguments)}catch(e){t&&t(e)}finally{Tt(i,!1),r&>()}}}T(at.prototype,{then:ut,_then:function(e,t){ht(this,new st(null,null,e,t,nt))},catch:function(e){if(1===arguments.length)return this.then(null,e);var t=arguments[0],n=arguments[1];return"function"==typeof t?this.then(null,(function(e){return e instanceof t?n(e):wt(e)})):this.then(null,(function(e){return e&&e.name===t?n(e):wt(e)}))},finally:function(e){return this.then((function(t){return e(),t}),(function(t){return e(),wt(t)}))},stack:{get:function(){if(this._stack)return this._stack;try{Ve=!0;var e=pt(this,[],20).join("\nFrom previous: ");return null!==this._state&&(this._stack=e),e}finally{Ve=!1}}},timeout:function(e,t){var n=this;return e<1/0?new at((function(r,i){var o=setTimeout((function(){return i(new Ee.Timeout(t))}),e);n.then(r,i).finally(clearTimeout.bind(null,o))})):this}}),"undefined"!=typeof Symbol&&Symbol.toStringTag&&B(at.prototype,Symbol.toStringTag,"Dexie.Promise"),tt.env=Rt(),T(at,{all:function(){var e=ce.apply(null,arguments).map(It);return new at((function(t,n){0===e.length&&t([]);var r=e.length;e.forEach((function(i,o){return at.resolve(i).then((function(n){e[o]=n,--r||t(e)}),n)}))}))},resolve:function(e){if(e instanceof at)return e;if(e&&"function"==typeof e.then)return new at((function(t,n){e.then(t,n)}));var t=new at(qe,!0,e);return yt(t,Ze),t},reject:wt,race:function(){var e=ce.apply(null,arguments).map(It);return new at((function(t,n){e.map((function(e){return at.resolve(e).then(t,n)}))}))},PSD:{get:function(){return nt},set:function(e){return nt=e}},totalEchoes:{get:function(){return Et}},newPSD:jt,usePSD:Bt,scheduler:{get:function(){return Qe},set:function(e){Qe=e}},rejectionMapper:{get:function(){return et},set:function(e){et=e}},follow:function(e,t){return new at((function(n,r){return jt((function(t,n){var r=nt;r.unhandleds=[],r.onunhandled=n,r.finalize=Ke((function(){var e=this;ot.push((function r(){0===e.unhandleds.length?t():n(e.unhandleds[0]),ot.splice(ot.indexOf(r),1)})),++it,Qe((function(){0==--it&&bt()}),[])}),r.finalize),e()}),t,n,r)}))}}),He&&(He.allSettled&&B(at,"allSettled",(function(){var e=ce.apply(null,arguments).map(It);return new at((function(t){0===e.length&&t([]);var n=e.length,r=new Array(n);e.forEach((function(e,i){return at.resolve(e).then((function(e){return r[i]={status:"fulfilled",value:e}}),(function(e){return r[i]={status:"rejected",reason:e}})).then((function(){return--n||t(r)}))}))}))})),He.any&&"undefined"!=typeof AggregateError&&B(at,"any",(function(){var e=ce.apply(null,arguments).map(It);return new at((function(t,n){0===e.length&&n(new AggregateError([]));var r=e.length,i=new Array(r);e.forEach((function(e,o){return at.resolve(e).then((function(e){return t(e)}),(function(e){i[o]=e,--r||n(new AggregateError(i))}))}))}))})));var kt={awaits:0,echoes:0,id:0},xt=0,St=[],Pt=0,Et=0,Ot=0;function jt(e,t,n,r){var i=nt,o=Object.create(i);o.parent=i,o.ref=0,o.global=!1,o.id=++Ot;var a=tt.env;o.env=ze?{Promise:at,PromiseProp:{value:at,configurable:!0,writable:!0},all:at.all,race:at.race,allSettled:at.allSettled,any:at.any,resolve:at.resolve,reject:at.reject,nthen:Nt(a.nthen,o),gthen:Nt(a.gthen,o)}:{},t&&C(o,t),++i.ref,o.finalize=function(){--this.parent.ref||this.parent.finalize()};var u=Bt(o,e,n,r);return 0===o.ref&&o.finalize(),u}function At(){return kt.id||(kt.id=++xt),++kt.awaits,kt.echoes+=100,kt.id}function Ct(){return!!kt.awaits&&(0==--kt.awaits&&(kt.id=0),kt.echoes=100*kt.awaits,!0)}function It(e){return kt.echoes&&e&&e.constructor===He?(At(),e.then((function(e){return Ct(),e}),(function(e){return Ct(),Lt(e)}))):e}function Kt(e){++Et,kt.echoes&&0!=--kt.echoes||(kt.echoes=kt.id=0),St.push(nt),Tt(e,!0)}function Dt(){var e=St[St.length-1];St.pop(),Tt(e,!1)}function Tt(e,t){var n=nt;if((t?!kt.echoes||Pt++&&e===nt:!Pt||--Pt&&e===nt)||Ft(t?Kt.bind(null,e):Dt),e!==nt&&(nt=e,n===tt&&(tt.env=Rt()),ze)){var r=tt.env.Promise,i=e.env;Ue.then=i.nthen,r.prototype.then=i.gthen,(n.global||e.global)&&(Object.defineProperty(A,"Promise",i.PromiseProp),r.all=i.all,r.race=i.race,r.resolve=i.resolve,r.reject=i.reject,i.allSettled&&(r.allSettled=i.allSettled),i.any&&(r.any=i.any))}}function Rt(){var e=A.Promise;return ze?{Promise:e,PromiseProp:Object.getOwnPropertyDescriptor(A,"Promise"),all:e.all,race:e.race,allSettled:e.allSettled,any:e.any,resolve:e.resolve,reject:e.reject,nthen:Ue.then,gthen:e.prototype.then}:{}}function Bt(e,t,n,r,i){var o=nt;try{return Tt(e,!0),t(n,r,i)}finally{Tt(o,!1)}}function Ft(e){We.call(Me,e)}function qt(e,t,n,r){return"function"!=typeof e?e:function(){var i=nt;n&&At(),Tt(t,!0);try{return e.apply(this,arguments)}finally{Tt(i,!1),r&&Ft(Ct)}}}function Nt(e,t){return function(n,r){return e.call(this,qt(n,t),qt(r,t))}}-1===(""+We).indexOf("[native code]")&&(At=Ct=Ae);var Mt="unhandledrejection";function Ut(e,t){var n;try{n=t.onuncatched(e)}catch(e){}if(!1!==n)try{var r,i={promise:t,reason:e};if(A.document&&document.createEvent?((r=document.createEvent("Event")).initEvent(Mt,!0,!0),C(r,i)):A.CustomEvent&&C(r=new CustomEvent(Mt,{detail:i}),i),r&&A.dispatchEvent&&(dispatchEvent(r),!A.PromiseRejectionEvent&&A.onunhandledrejection))try{A.onunhandledrejection(r)}catch(e){}fe&&r&&!r.defaultPrevented&&console.warn("Unhandled rejection: "+(e.stack||e))}catch(e){}}var Lt=at.reject;function Wt(e,t,n,r){if(e._state.openComplete||nt.letThrough){var i=e._createTransaction(t,n,e._dbSchema);try{i.create()}catch(e){return Lt(e)}return i._promise(t,(function(e,t){return jt((function(){return nt.trans=i,r(e,t,i)}))})).then((function(e){return i._completion.then((function(){return e}))}))}if(!e._state.isBeingOpened){if(!e._options.autoOpen)return Lt(new Ee.DatabaseClosed);e.open().catch(Ae)}return e._state.dbReadyPromise.then((function(){return Wt(e,t,n,r)}))}var Ht="3.0.3",zt=String.fromCharCode(65535),Vt=-1/0,Gt="Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.",Qt="String expected.",Yt=[],Xt="undefined"!=typeof navigator&&/(MSIE|Trident|Edge)/.test(navigator.userAgent),$t=Xt,Jt=Xt,Zt=function(e){return!/(dexie\.js|dexie\.min\.js)/.test(e)},en="__dbnames",tn="readonly",nn="readwrite";function rn(e,t){return e?t?function(){return e.apply(this,arguments)&&t.apply(this,arguments)}:e:t}var on={type:3,lower:-1/0,lowerOpen:!1,upper:[[]],upperOpen:!1};function an(e){return function(t){return void 0===V(t,e)&&Q(t=te(t),e),t}}var un=function(){function e(){}return e.prototype._trans=function(e,t,n){var r=this._tx||nt.trans,i=this.name;function o(e,n,r){if(!r.schema[i])throw new Ee.NotFound("Table "+i+" not part of transaction");return t(r.idbtrans,r)}var a=mt();try{return r&&r.db===this.db?r===nt.trans?r._promise(e,o,n):jt((function(){return r._promise(e,o,n)}),{trans:r,transless:nt.transless||nt}):Wt(this.db,e,[this.name],o)}finally{a&>()}},e.prototype.get=function(e,t){var n=this;return e&&e.constructor===Object?this.where(e).first(t):this._trans("readonly",(function(t){return n.core.get({trans:t,key:e}).then((function(e){return n.hook.reading.fire(e)}))})).then(t)},e.prototype.where=function(e){if("string"==typeof e)return new this.db.WhereClause(this,e);if(j(e))return new this.db.WhereClause(this,"["+e.join("+")+"]");var t=O(e);if(1===t.length)return this.where(t[0]).equals(e[t[0]]);var n=this.schema.indexes.concat(this.schema.primKey).filter((function(e){return e.compound&&t.every((function(t){return e.keyPath.indexOf(t)>=0}))&&e.keyPath.every((function(e){return t.indexOf(e)>=0}))}))[0];if(n&&this.db._maxKey!==zt)return this.where(n.name).equals(n.keyPath.map((function(t){return e[t]})));!n&&fe&&console.warn("The query "+JSON.stringify(e)+" on "+this.name+" would benefit of a compound index ["+t.join("+")+"]");var r=this.schema.idxByName,i=this.db._deps.indexedDB;function o(e,t){try{return 0===i.cmp(e,t)}catch(e){return!1}}var a=t.reduce((function(t,n){var i=t[0],a=t[1],u=r[n],s=e[n];return[i||u,i||!u?rn(a,u&&u.multi?function(e){var t=V(e,n);return j(t)&&t.some((function(e){return o(s,e)}))}:function(e){return o(s,V(e,n))}):a]}),[null,null]),u=a[0],s=a[1];return u?this.where(u.name).equals(e[u.keyPath]).filter(s):n?this.filter(s):this.where(t).equals("")},e.prototype.filter=function(e){return this.toCollection().and(e)},e.prototype.count=function(e){return this.toCollection().count(e)},e.prototype.offset=function(e){return this.toCollection().offset(e)},e.prototype.limit=function(e){return this.toCollection().limit(e)},e.prototype.each=function(e){return this.toCollection().each(e)},e.prototype.toArray=function(e){return this.toCollection().toArray(e)},e.prototype.toCollection=function(){return new this.db.Collection(new this.db.WhereClause(this))},e.prototype.orderBy=function(e){return new this.db.Collection(new this.db.WhereClause(this,j(e)?"["+e.join("+")+"]":e))},e.prototype.reverse=function(){return this.toCollection().reverse()},e.prototype.mapToClass=function(e){this.schema.mappedClass=e;var t=function(t){if(!t)return t;var n=Object.create(e.prototype);for(var r in t)if(D(t,r))try{n[r]=t[r]}catch(e){}return n};return this.schema.readHook&&this.hook.reading.unsubscribe(this.schema.readHook),this.schema.readHook=t,this.hook("reading",t),e},e.prototype.defineClass=function(){return this.mapToClass((function(e){C(this,e)}))},e.prototype.add=function(e,t){var n=this,r=this.schema.primKey,i=r.auto,o=r.keyPath,a=e;return o&&i&&(a=an(o)(e)),this._trans("readwrite",(function(e){return n.core.mutate({trans:e,type:"add",keys:null!=t?[t]:null,values:[a]})})).then((function(e){return e.numFailures?at.reject(e.failures[0]):e.lastResult})).then((function(t){if(o)try{G(e,o,t)}catch(e){}return t}))},e.prototype.update=function(e,t){if("object"!=typeof t||j(t))throw new Ee.InvalidArgument("Modifications must be an object.");if("object"!=typeof e||j(e))return this.where(":id").equals(e).modify(t);O(t).forEach((function(n){G(e,n,t[n])}));var n=V(e,this.schema.primKey.keyPath);return void 0===n?Lt(new Ee.InvalidArgument("Given object does not contain its primary key")):this.where(":id").equals(n).modify(t)},e.prototype.put=function(e,t){var n=this,r=this.schema.primKey,i=r.auto,o=r.keyPath,a=e;return o&&i&&(a=an(o)(e)),this._trans("readwrite",(function(e){return n.core.mutate({trans:e,type:"put",values:[a],keys:null!=t?[t]:null})})).then((function(e){return e.numFailures?at.reject(e.failures[0]):e.lastResult})).then((function(t){if(o)try{G(e,o,t)}catch(e){}return t}))},e.prototype.delete=function(e){var t=this;return this._trans("readwrite",(function(n){return t.core.mutate({trans:n,type:"delete",keys:[e]})})).then((function(e){return e.numFailures?at.reject(e.failures[0]):void 0}))},e.prototype.clear=function(){var e=this;return this._trans("readwrite",(function(t){return e.core.mutate({trans:t,type:"deleteRange",range:on})})).then((function(e){return e.numFailures?at.reject(e.failures[0]):void 0}))},e.prototype.bulkGet=function(e){var t=this;return this._trans("readonly",(function(n){return t.core.getMany({keys:e,trans:n}).then((function(e){return e.map((function(e){return t.hook.reading.fire(e)}))}))}))},e.prototype.bulkAdd=function(e,t,n){var r=this,i=Array.isArray(t)?t:void 0,o=(n=n||(i?void 0:t))?n.allKeys:void 0;return this._trans("readwrite",(function(t){var n=r.schema.primKey,a=n.auto,u=n.keyPath;if(u&&i)throw new Ee.InvalidArgument("bulkAdd(): keys argument invalid on tables with inbound keys");if(i&&i.length!==e.length)throw new Ee.InvalidArgument("Arguments objects and keys must have the same length");var s=e.length,c=u&&a?e.map(an(u)):e;return r.core.mutate({trans:t,type:"add",keys:i,values:c,wantResults:o}).then((function(e){var t=e.numFailures,n=e.results,i=e.lastResult,a=e.failures;if(0===t)return o?n:i;throw new xe(r.name+".bulkAdd(): "+t+" of "+s+" operations failed",Object.keys(a).map((function(e){return a[e]})))}))}))},e.prototype.bulkPut=function(e,t,n){var r=this,i=Array.isArray(t)?t:void 0,o=(n=n||(i?void 0:t))?n.allKeys:void 0;return this._trans("readwrite",(function(t){var n=r.schema.primKey,a=n.auto,u=n.keyPath;if(u&&i)throw new Ee.InvalidArgument("bulkPut(): keys argument invalid on tables with inbound keys");if(i&&i.length!==e.length)throw new Ee.InvalidArgument("Arguments objects and keys must have the same length");var s=e.length,c=u&&a?e.map(an(u)):e;return r.core.mutate({trans:t,type:"put",keys:i,values:c,wantResults:o}).then((function(e){var t=e.numFailures,n=e.results,i=e.lastResult,a=e.failures;if(0===t)return o?n:i;throw new xe(r.name+".bulkPut(): "+t+" of "+s+" operations failed",Object.keys(a).map((function(e){return a[e]})))}))}))},e.prototype.bulkDelete=function(e){var t=this,n=e.length;return this._trans("readwrite",(function(n){return t.core.mutate({trans:n,type:"delete",keys:e})})).then((function(e){var r=e.numFailures,i=e.lastResult,o=e.failures;if(0===r)return i;throw new xe(t.name+".bulkDelete(): "+r+" of "+n+" operations failed",o)}))},e}();function sn(e){var t={},n=function(n,r){if(r){for(var i=arguments.length,o=new Array(i-1);--i;)o[i-1]=arguments[i];return t[n].subscribe.apply(null,o),e}if("string"==typeof n)return t[n]};n.addEventType=o;for(var r=1,i=arguments.length;r<i;++r)o(arguments[r]);return n;function o(e,r,i){if("object"==typeof e)return a(e);r||(r=Be),i||(i=Ae);var o={subscribers:[],fire:i,subscribe:function(e){-1===o.subscribers.indexOf(e)&&(o.subscribers.push(e),o.fire=r(o.fire,e))},unsubscribe:function(e){o.subscribers=o.subscribers.filter((function(t){return t!==e})),o.fire=o.subscribers.reduce(r,i)}};return t[e]=n[e]=o,o}function a(e){O(e).forEach((function(t){var n=e[t];if(j(n))o(t,e[t][0],e[t][1]);else{if("asap"!==n)throw new Ee.InvalidArgument("Invalid event config");var r=o(t,Ce,(function(){for(var e=arguments.length,t=new Array(e);e--;)t[e]=arguments[e];r.subscribers.forEach((function(e){H((function(){e.apply(null,t)}))}))}))}}))}}function cn(e,t){return F(t).from({prototype:e}),t}function ln(e,t){return!(e.filter||e.algorithm||e.or)&&(t?e.justLimit:!e.replayFilter)}function fn(e,t){e.filter=rn(e.filter,t)}function hn(e,t,n){var r=e.replayFilter;e.replayFilter=r?function(){return rn(r(),t())}:t,e.justLimit=n&&!r}function dn(e,t){if(e.isPrimKey)return t.primaryKey;var n=t.getIndexByKeyPath(e.index);if(!n)throw new Ee.Schema("KeyPath "+e.index+" on object store "+t.name+" is not indexed");return n}function pn(e,t,n){var r=dn(e,t.schema);return t.openCursor({trans:n,values:!e.keysOnly,reverse:"prev"===e.dir,unique:!!e.unique,query:{index:r,range:e.range}})}function yn(e,t,n,r){var i=e.replayFilter?rn(e.filter,e.replayFilter()):e.filter;if(e.or){var o={},a=function(e,n,r){if(!i||i(n,r,(function(e){return n.stop(e)}),(function(e){return n.fail(e)}))){var a=n.primaryKey,u=""+a;"[object ArrayBuffer]"===u&&(u=""+new Uint8Array(a)),D(o,u)||(o[u]=!0,t(e,n,r))}};return Promise.all([e.or._iterate(a,n),vn(pn(e,r,n),e.algorithm,a,!e.keysOnly&&e.valueMapper)])}return vn(pn(e,r,n),rn(e.algorithm,i),t,!e.keysOnly&&e.valueMapper)}function vn(e,t,n,r){var i=_t(r?function(e,t,i){return n(r(e),t,i)}:n);return e.then((function(e){if(e)return e.start((function(){var n=function(){return e.continue()};t&&!t(e,(function(e){return n=e}),(function(t){e.stop(t),n=Ae}),(function(t){e.fail(t),n=Ae}))||i(e.value,e,(function(e){return n=e})),n()}))}))}var mn=function(){function e(){}return e.prototype._read=function(e,t){var n=this._ctx;return n.error?n.table._trans(null,Lt.bind(null,n.error)):n.table._trans("readonly",e).then(t)},e.prototype._write=function(e){var t=this._ctx;return t.error?t.table._trans(null,Lt.bind(null,t.error)):t.table._trans("readwrite",e,"locked")},e.prototype._addAlgorithm=function(e){var t=this._ctx;t.algorithm=rn(t.algorithm,e)},e.prototype._iterate=function(e,t){return yn(this._ctx,e,t,this._ctx.table.core)},e.prototype.clone=function(e){var t=Object.create(this.constructor.prototype),n=Object.create(this._ctx);return e&&C(n,e),t._ctx=n,t},e.prototype.raw=function(){return this._ctx.valueMapper=null,this},e.prototype.each=function(e){var t=this._ctx;return this._read((function(n){return yn(t,e,n,t.table.core)}))},e.prototype.count=function(e){var t=this;return this._read((function(e){var n=t._ctx,r=n.table.core;if(ln(n,!0))return r.count({trans:e,query:{index:dn(n,r.schema),range:n.range}}).then((function(e){return Math.min(e,n.limit)}));var i=0;return yn(n,(function(){return++i,!1}),e,r).then((function(){return i}))})).then(e)},e.prototype.sortBy=function(e,t){var n=e.split(".").reverse(),r=n[0],i=n.length-1;function o(e,t){return t?o(e[n[t]],t-1):e[r]}var a="next"===this._ctx.dir?1:-1;function u(e,t){var n=o(e,i),r=o(t,i);return n<r?-a:n>r?a:0}return this.toArray((function(e){return e.sort(u)})).then(t)},e.prototype.toArray=function(e){var t=this;return this._read((function(e){var n=t._ctx;if("next"===n.dir&&ln(n,!0)&&n.limit>0){var r=n.valueMapper,i=dn(n,n.table.core.schema);return n.table.core.query({trans:e,limit:n.limit,values:!0,query:{index:i,range:n.range}}).then((function(e){var t=e.result;return r?t.map(r):t}))}var o=[];return yn(n,(function(e){return o.push(e)}),e,n.table.core).then((function(){return o}))}),e)},e.prototype.offset=function(e){var t=this._ctx;return e<=0||(t.offset+=e,ln(t)?hn(t,(function(){var t=e;return function(e,n){return 0===t||(1===t?(--t,!1):(n((function(){e.advance(t),t=0})),!1))}})):hn(t,(function(){var t=e;return function(){return--t<0}}))),this},e.prototype.limit=function(e){return this._ctx.limit=Math.min(this._ctx.limit,e),hn(this._ctx,(function(){var t=e;return function(e,n,r){return--t<=0&&n(r),t>=0}}),!0),this},e.prototype.until=function(e,t){return fn(this._ctx,(function(n,r,i){return!e(n.value)||(r(i),t)})),this},e.prototype.first=function(e){return this.limit(1).toArray((function(e){return e[0]})).then(e)},e.prototype.last=function(e){return this.reverse().first(e)},e.prototype.filter=function(e){var t,n;return fn(this._ctx,(function(t){return e(t.value)})),t=this._ctx,n=e,t.isMatch=rn(t.isMatch,n),this},e.prototype.and=function(e){return this.filter(e)},e.prototype.or=function(e){return new this.db.WhereClause(this._ctx.table,e,this)},e.prototype.reverse=function(){return this._ctx.dir="prev"===this._ctx.dir?"next":"prev",this._ondirectionchange&&this._ondirectionchange(this._ctx.dir),this},e.prototype.desc=function(){return this.reverse()},e.prototype.eachKey=function(e){var t=this._ctx;return t.keysOnly=!t.isMatch,this.each((function(t,n){e(n.key,n)}))},e.prototype.eachUniqueKey=function(e){return this._ctx.unique="unique",this.eachKey(e)},e.prototype.eachPrimaryKey=function(e){var t=this._ctx;return t.keysOnly=!t.isMatch,this.each((function(t,n){e(n.primaryKey,n)}))},e.prototype.keys=function(e){var t=this._ctx;t.keysOnly=!t.isMatch;var n=[];return this.each((function(e,t){n.push(t.key)})).then((function(){return n})).then(e)},e.prototype.primaryKeys=function(e){var t=this._ctx;if("next"===t.dir&&ln(t,!0)&&t.limit>0)return this._read((function(e){var n=dn(t,t.table.core.schema);return t.table.core.query({trans:e,values:!1,limit:t.limit,query:{index:n,range:t.range}})})).then((function(e){return e.result})).then(e);t.keysOnly=!t.isMatch;var n=[];return this.each((function(e,t){n.push(t.primaryKey)})).then((function(){return n})).then(e)},e.prototype.uniqueKeys=function(e){return this._ctx.unique="unique",this.keys(e)},e.prototype.firstKey=function(e){return this.limit(1).keys((function(e){return e[0]})).then(e)},e.prototype.lastKey=function(e){return this.reverse().firstKey(e)},e.prototype.distinct=function(){var e=this._ctx,t=e.index&&e.table.schema.idxByName[e.index];if(!t||!t.multi)return this;var n={};return fn(this._ctx,(function(e){var t=e.primaryKey.toString(),r=D(n,t);return n[t]=!0,!r})),this},e.prototype.modify=function(e){var t=this,n=this._ctx;return this._write((function(r){var i;if("function"==typeof e)i=e;else{var o=O(e),a=o.length;i=function(t){for(var n=!1,r=0;r<a;++r){var i=o[r],u=e[i];V(t,i)!==u&&(G(t,i,u),n=!0)}return n}}var u=n.table.core,s=u.schema.primaryKey,c=s.outbound,l=s.extractKey,f="testmode"in ar?1:2e3,h=t.db.core.cmp,d=[],p=0,y=[],v=function(e,t){var n=t.failures,r=t.numFailures;p+=e-r;for(var i=0,o=O(n);i<o.length;i++){var a=o[i];d.push(n[a])}};return t.clone().primaryKeys().then((function(e){var t=function(n){var o=Math.min(f,e.length-n);return u.getMany({trans:r,keys:e.slice(n,n+o)}).then((function(a){for(var s=[],d=[],p=c?[]:null,y=[],m=0;m<o;++m){var g=a[m],b={value:te(g),primKey:e[n+m]};!1!==i.call(b,b.value,b)&&(null==b.value?y.push(e[n+m]):c||0===h(l(g),l(b.value))?(d.push(b.value),c&&p.push(e[n+m])):(y.push(e[n+m]),s.push(b.value)))}return Promise.resolve(s.length>0&&u.mutate({trans:r,type:"add",values:s}).then((function(e){for(var t in e.failures)y.splice(parseInt(t),1);v(s.length,e)}))).then((function(e){return d.length>0&&u.mutate({trans:r,type:"put",keys:p,values:d}).then((function(e){return v(d.length,e)}))})).then((function(){return y.length>0&&u.mutate({trans:r,type:"delete",keys:y}).then((function(e){return v(y.length,e)}))})).then((function(){return e.length>n+o&&t(n+f)}))}))};return t(0).then((function(){if(d.length>0)throw new ke("Error modifying one or more objects",d,p,y);return e.length}))}))}))},e.prototype.delete=function(){var e=this._ctx,t=e.range;return ln(e)&&(e.isPrimKey&&!Jt||3===t.type)?this._write((function(n){var r=e.table.core.schema.primaryKey,i=t;return e.table.core.count({trans:n,query:{index:r,range:i}}).then((function(t){return e.table.core.mutate({trans:n,type:"deleteRange",range:i}).then((function(e){var n=e.failures,r=(e.lastResult,e.results,e.numFailures);if(r)throw new ke("Could not delete some values",Object.keys(n).map((function(e){return n[e]})),t-r);return t-r}))}))})):this.modify((function(e,t){return t.value=null}))},e}();function gn(e,t){return e<t?-1:e===t?0:1}function bn(e,t){return e>t?-1:e===t?0:1}function wn(e,t,n){var r=e instanceof En?new e.Collection(e):e;return r._ctx.error=n?new n(t):new TypeError(t),r}function _n(e){return new e.Collection(e,(function(){return Pn("")})).limit(0)}function kn(e,t,n,r,i,o){for(var a=Math.min(e.length,r.length),u=-1,s=0;s<a;++s){var c=t[s];if(c!==r[s])return i(e[s],n[s])<0?e.substr(0,s)+n[s]+n.substr(s+1):i(e[s],r[s])<0?e.substr(0,s)+r[s]+n.substr(s+1):u>=0?e.substr(0,u)+t[u]+n.substr(u+1):null;i(e[s],c)<0&&(u=s)}return a<r.length&&"next"===o?e+n.substr(e.length):a<e.length&&"prev"===o?e.substr(0,n.length):u<0?null:e.substr(0,u)+r[u]+n.substr(u+1)}function xn(e,t,n,r){var i,o,a,u,s,c,l,f=n.length;if(!n.every((function(e){return"string"==typeof e})))return wn(e,Qt);function h(e){i=function(e){return"next"===e?function(e){return e.toUpperCase()}:function(e){return e.toLowerCase()}}(e),o=function(e){return"next"===e?function(e){return e.toLowerCase()}:function(e){return e.toUpperCase()}}(e),a="next"===e?gn:bn;var t=n.map((function(e){return{lower:o(e),upper:i(e)}})).sort((function(e,t){return a(e.lower,t.lower)}));u=t.map((function(e){return e.upper})),s=t.map((function(e){return e.lower})),c=e,l="next"===e?"":r}h("next");var d=new e.Collection(e,(function(){return Sn(u[0],s[f-1]+r)}));d._ondirectionchange=function(e){h(e)};var p=0;return d._addAlgorithm((function(e,n,r){var i=e.key;if("string"!=typeof i)return!1;var h=o(i);if(t(h,s,p))return!0;for(var d=null,y=p;y<f;++y){var v=kn(i,h,u[y],s[y],a,c);null===v&&null===d?p=y+1:(null===d||a(d,v)>0)&&(d=v)}return n(null!==d?function(){e.continue(d+l)}:r),!1})),d}function Sn(e,t,n,r){return{type:2,lower:e,upper:t,lowerOpen:n,upperOpen:r}}function Pn(e){return{type:1,lower:e,upper:e}}var En=function(){function e(){}return Object.defineProperty(e.prototype,"Collection",{get:function(){return this._ctx.table.db.Collection},enumerable:!0,configurable:!0}),e.prototype.between=function(e,t,n,r){n=!1!==n,r=!0===r;try{return this._cmp(e,t)>0||0===this._cmp(e,t)&&(n||r)&&(!n||!r)?_n(this):new this.Collection(this,(function(){return Sn(e,t,!n,!r)}))}catch(e){return wn(this,Gt)}},e.prototype.equals=function(e){return null==e?wn(this,Gt):new this.Collection(this,(function(){return Pn(e)}))},e.prototype.above=function(e){return null==e?wn(this,Gt):new this.Collection(this,(function(){return Sn(e,void 0,!0)}))},e.prototype.aboveOrEqual=function(e){return null==e?wn(this,Gt):new this.Collection(this,(function(){return Sn(e,void 0,!1)}))},e.prototype.below=function(e){return null==e?wn(this,Gt):new this.Collection(this,(function(){return Sn(void 0,e,!1,!0)}))},e.prototype.belowOrEqual=function(e){return null==e?wn(this,Gt):new this.Collection(this,(function(){return Sn(void 0,e)}))},e.prototype.startsWith=function(e){return"string"!=typeof e?wn(this,Qt):this.between(e,e+zt,!0,!0)},e.prototype.startsWithIgnoreCase=function(e){return""===e?this.startsWith(e):xn(this,(function(e,t){return 0===e.indexOf(t[0])}),[e],zt)},e.prototype.equalsIgnoreCase=function(e){return xn(this,(function(e,t){return e===t[0]}),[e],"")},e.prototype.anyOfIgnoreCase=function(){var e=ce.apply(se,arguments);return 0===e.length?_n(this):xn(this,(function(e,t){return-1!==t.indexOf(e)}),e,"")},e.prototype.startsWithAnyOfIgnoreCase=function(){var e=ce.apply(se,arguments);return 0===e.length?_n(this):xn(this,(function(e,t){return t.some((function(t){return 0===e.indexOf(t)}))}),e,zt)},e.prototype.anyOf=function(){var e=this,t=ce.apply(se,arguments),n=this._cmp;try{t.sort(n)}catch(e){return wn(this,Gt)}if(0===t.length)return _n(this);var r=new this.Collection(this,(function(){return Sn(t[0],t[t.length-1])}));r._ondirectionchange=function(r){n="next"===r?e._ascending:e._descending,t.sort(n)};var i=0;return r._addAlgorithm((function(e,r,o){for(var a=e.key;n(a,t[i])>0;)if(++i===t.length)return r(o),!1;return 0===n(a,t[i])||(r((function(){e.continue(t[i])})),!1)})),r},e.prototype.notEqual=function(e){return this.inAnyRange([[Vt,e],[e,this.db._maxKey]],{includeLowers:!1,includeUppers:!1})},e.prototype.noneOf=function(){var e=ce.apply(se,arguments);if(0===e.length)return new this.Collection(this);try{e.sort(this._ascending)}catch(e){return wn(this,Gt)}var t=e.reduce((function(e,t){return e?e.concat([[e[e.length-1][1],t]]):[[Vt,t]]}),null);return t.push([e[e.length-1],this.db._maxKey]),this.inAnyRange(t,{includeLowers:!1,includeUppers:!1})},e.prototype.inAnyRange=function(e,t){var n=this,r=this._cmp,i=this._ascending,o=this._descending,a=this._min,u=this._max;if(0===e.length)return _n(this);if(!e.every((function(e){return void 0!==e[0]&&void 0!==e[1]&&i(e[0],e[1])<=0})))return wn(this,"First argument to inAnyRange() must be an Array of two-value Arrays [lower,upper] where upper must not be lower than lower",Ee.InvalidArgument);var s,c=!t||!1!==t.includeLowers,l=t&&!0===t.includeUppers,f=i;function h(e,t){return f(e[0],t[0])}try{(s=e.reduce((function(e,t){for(var n=0,i=e.length;n<i;++n){var o=e[n];if(r(t[0],o[1])<0&&r(t[1],o[0])>0){o[0]=a(o[0],t[0]),o[1]=u(o[1],t[1]);break}}return n===i&&e.push(t),e}),[])).sort(h)}catch(e){return wn(this,Gt)}var d=0,p=l?function(e){return i(e,s[d][1])>0}:function(e){return i(e,s[d][1])>=0},y=c?function(e){return o(e,s[d][0])>0}:function(e){return o(e,s[d][0])>=0},v=p,m=new this.Collection(this,(function(){return Sn(s[0][0],s[s.length-1][1],!c,!l)}));return m._ondirectionchange=function(e){"next"===e?(v=p,f=i):(v=y,f=o),s.sort(h)},m._addAlgorithm((function(e,t,r){for(var o=e.key;v(o);)if(++d===s.length)return t(r),!1;return!!function(e){return!p(e)&&!y(e)}(o)||(0===n._cmp(o,s[d][1])||0===n._cmp(o,s[d][0])||t((function(){f===i?e.continue(s[d][0]):e.continue(s[d][1])})),!1)})),m},e.prototype.startsWithAnyOf=function(){var e=ce.apply(se,arguments);return e.every((function(e){return"string"==typeof e}))?0===e.length?_n(this):this.inAnyRange(e.map((function(e){return[e,e+zt]}))):wn(this,"startsWithAnyOf() only works with strings")},e}();function On(e){return 1===e.length?e[0]:e}function jn(e){try{return e.only([[]]),[[]]}catch(e){return zt}}function An(e){return _t((function(t){return Cn(t),e(t.target.error),!1}))}function Cn(e){e.stopPropagation&&e.stopPropagation(),e.preventDefault&&e.preventDefault()}var In=function(){function e(){}return e.prototype._lock=function(){return W(!nt.global),++this._reculock,1!==this._reculock||nt.global||(nt.lockOwnerFor=this),this},e.prototype._unlock=function(){if(W(!nt.global),0==--this._reculock)for(nt.global||(nt.lockOwnerFor=null);this._blockedFuncs.length>0&&!this._locked();){var e=this._blockedFuncs.shift();try{Bt(e[1],e[0])}catch(e){}}return this},e.prototype._locked=function(){return this._reculock&&nt.lockOwnerFor!==this},e.prototype.create=function(e){var t=this;if(!this.mode)return this;var n=this.db.idbdb,r=this.db._state.dbOpenError;if(W(!this.idbtrans),!e&&!n)switch(r&&r.name){case"DatabaseClosedError":throw new Ee.DatabaseClosed(r);case"MissingAPIError":throw new Ee.MissingAPI(r.message,r);default:throw new Ee.OpenFailed(r)}if(!this.active)throw new Ee.TransactionInactive;return W(null===this._completion._state),(e=this.idbtrans=e||n.transaction(On(this.storeNames),this.mode)).onerror=_t((function(n){Cn(n),t._reject(e.error)})),e.onabort=_t((function(n){Cn(n),t.active&&t._reject(new Ee.Abort(e.error)),t.active=!1,t.on("abort").fire(n)})),e.oncomplete=_t((function(){t.active=!1,t._resolve()})),this},e.prototype._promise=function(e,t,n){var r=this;if("readwrite"===e&&"readwrite"!==this.mode)return Lt(new Ee.ReadOnly("Transaction is readonly"));if(!this.active)return Lt(new Ee.TransactionInactive);if(this._locked())return new at((function(i,o){r._blockedFuncs.push([function(){r._promise(e,t,n).then(i,o)},nt])}));if(n)return jt((function(){var e=new at((function(e,n){r._lock();var i=t(e,n,r);i&&i.then&&i.then(e,n)}));return e.finally((function(){return r._unlock()})),e._lib=!0,e}));var i=new at((function(e,n){var i=t(e,n,r);i&&i.then&&i.then(e,n)}));return i._lib=!0,i},e.prototype._root=function(){return this.parent?this.parent._root():this},e.prototype.waitFor=function(e){var t=this._root(),n=at.resolve(e);if(t._waitingFor)t._waitingFor=t._waitingFor.then((function(){return n}));else{t._waitingFor=n,t._waitingQueue=[];var r=t.idbtrans.objectStore(t.storeNames[0]);!function e(){for(++t._spinCount;t._waitingQueue.length;)t._waitingQueue.shift()();t._waitingFor&&(r.get(-1/0).onsuccess=e)}()}var i=t._waitingFor;return new at((function(e,r){n.then((function(n){return t._waitingQueue.push(_t(e.bind(null,n)))}),(function(e){return t._waitingQueue.push(_t(r.bind(null,e)))})).finally((function(){t._waitingFor===i&&(t._waitingFor=null)}))}))},e.prototype.abort=function(){this.active&&this._reject(new Ee.Abort),this.active=!1},e.prototype.table=function(e){var t=this._memoizedTables||(this._memoizedTables={});if(D(t,e))return t[e];var n=this.schema[e];if(!n)throw new Ee.NotFound("Table "+e+" not part of transaction");var r=new this.db.Table(e,n,this);return r.core=this.db.core.table(e),t[e]=r,r},e}();function Kn(e,t,n,r,i,o,a){return{name:e,keyPath:t,unique:n,multi:r,auto:i,compound:o,src:(n&&!a?"&":"")+(r?"*":"")+(i?"++":"")+Dn(t)}}function Dn(e){return"string"==typeof e?e:e?"["+[].join.call(e,"+")+"]":""}function Tn(e,t,n){return{name:e,primKey:t,indexes:n,mappedClass:null,idxByName:z(n,(function(e){return[e.name,e]}))}}function Rn(e){return null==e?function(){}:"string"==typeof e?function(e){return 1===e.split(".").length?function(t){return t[e]}:function(t){return V(t,e)}}(e):function(t){return V(t,e)}}function Bn(e,t){return"delete"===t.type?t.keys:t.keys||t.values.map(e.extractKey)}function Fn(e){return[].slice.call(e)}var qn=0;function Nn(e){return null==e?":id":"string"==typeof e?e:"["+e.join("+")+"]"}function Mn(e,t,n,r){var i=t.cmp.bind(t);function o(e){if(3===e.type)return null;if(4===e.type)throw new Error("Cannot convert never type to IDBKeyRange");var t=e.lower,r=e.upper,i=e.lowerOpen,o=e.upperOpen;return void 0===t?void 0===r?null:n.upperBound(r,!!o):void 0===r?n.lowerBound(t,!!i):n.bound(t,r,!!i,!!o)}var a=function(e,t){var n=Fn(e.objectStoreNames);return{schema:{name:e.name,tables:n.map((function(e){return t.objectStore(e)})).map((function(e){var t=e.keyPath,n=e.autoIncrement,r=j(t),i=null==t,o={},a={name:e.name,primaryKey:{name:null,isPrimaryKey:!0,outbound:i,compound:r,keyPath:t,autoIncrement:n,unique:!0,extractKey:Rn(t)},indexes:Fn(e.indexNames).map((function(t){return e.index(t)})).map((function(e){var t=e.name,n=e.unique,r=e.multiEntry,i=e.keyPath,a={name:t,compound:j(i),keyPath:i,unique:n,multiEntry:r,extractKey:Rn(i)};return o[Nn(i)]=a,a})),getIndexByKeyPath:function(e){return o[Nn(e)]}};return o[":id"]=a.primaryKey,null!=t&&(o[Nn(t)]=a.primaryKey),a}))},hasGetAll:n.length>0&&"getAll"in t.objectStore(n[0])&&!("undefined"!=typeof navigator&&/Safari/.test(navigator.userAgent)&&!/(Chrome\/|Edge\/)/.test(navigator.userAgent)&&[].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1]<604)}}(e,r),u=a.schema,s=a.hasGetAll,c=u.tables.map((function(e){return function(e){var t=e.name;return{name:t,schema:e,mutate:function(n){var r=n.trans,i=n.type,a=n.keys,u=n.values,s=n.range,c=n.wantResults;return new Promise((function(n,l){n=_t(n);var f=r.objectStore(t),h=null==f.keyPath,d="put"===i||"add"===i;if(!d&&"delete"!==i&&"deleteRange"!==i)throw new Error("Invalid operation type: "+i);var p=(a||u||{length:1}).length;if(a&&u&&a.length!==u.length)throw new Error("Given keys array must have same length as given values array.");if(0===p)return n({numFailures:0,failures:{},results:[],lastResult:void 0});var y,v=c&&E(a||Bn(e.primaryKey,{type:i,keys:a,values:u})),m=[],g=0,b=function(e){++g,Cn(e),v&&(v[e.target._reqno]=void 0),m[e.target._reqno]=e.target.error},w=function(e){var t=e.target;v[t._reqno]=t.result};if("deleteRange"===i){if(4===s.type)return n({numFailures:g,failures:m,results:v,lastResult:void 0});y=3===s.type?f.clear():f.delete(o(s))}else{var _=d?h?[u,a]:[u,null]:[a,null],k=_[0],x=_[1];if(d)for(var S=0;S<p;++S)(y=x&&void 0!==x[S]?f[i](k[S],x[S]):f[i](k[S]))._reqno=S,v&&void 0===v[S]&&(y.onsuccess=w),y.onerror=b;else for(S=0;S<p;++S)(y=f[i](k[S]))._reqno=S,y.onerror=b}var P=function(e){var t=e.target.result;v&&(v[p-1]=t),n({numFailures:g,failures:m,results:v,lastResult:t})};y.onerror=function(e){b(e),P(e)},y.onsuccess=P}))},getMany:function(e){var n=e.trans,r=e.keys;return new Promise((function(e,i){e=_t(e);for(var o,a=n.objectStore(t),u=r.length,s=new Array(u),c=0,l=0,f=function(t){var n=t.target;s[n._pos]=n.result,++l===c&&e(s)},h=An(i),d=0;d<u;++d)null!=r[d]&&((o=a.get(r[d]))._pos=d,o.onsuccess=f,o.onerror=h,++c);0===c&&e(s)}))},get:function(e){var n=e.trans,r=e.key;return new Promise((function(e,i){e=_t(e);var o=n.objectStore(t).get(r);o.onsuccess=function(t){return e(t.target.result)},o.onerror=An(i)}))},query:function(e){return function(n){return new Promise((function(r,i){r=_t(r);var a=n.trans,u=n.values,s=n.limit,c=n.query,l=s===1/0?void 0:s,f=c.index,h=c.range,d=a.objectStore(t),p=f.isPrimaryKey?d:d.index(f.name),y=o(h);if(0===s)return r({result:[]});if(e){var v=u?p.getAll(y,l):p.getAllKeys(y,l);v.onsuccess=function(e){return r({result:e.target.result})},v.onerror=An(i)}else{var m=0,g=u||!("openKeyCursor"in p)?p.openCursor(y):p.openKeyCursor(y),b=[];g.onsuccess=function(e){var t=g.result;return t?(b.push(u?t.value:t.primaryKey),++m===s?r({result:b}):void t.continue()):r({result:b})},g.onerror=An(i)}}))}}(s),openCursor:function(e){var n=e.trans,r=e.values,i=e.query,a=e.reverse,u=e.unique;return new Promise((function(e,s){e=_t(e);var c=i.index,l=i.range,f=n.objectStore(t),h=c.isPrimaryKey?f:f.index(c.name),d=a?u?"prevunique":"prev":u?"nextunique":"next",p=r||!("openKeyCursor"in h)?h.openCursor(o(l),d):h.openKeyCursor(o(l),d);p.onerror=An(s),p.onsuccess=_t((function(t){var r=p.result;if(r){r.___id=++qn,r.done=!1;var i=r.continue.bind(r),o=r.continuePrimaryKey;o&&(o=o.bind(r));var a=r.advance.bind(r),u=function(){throw new Error("Cursor not stopped")};r.trans=n,r.stop=r.continue=r.continuePrimaryKey=r.advance=function(){throw new Error("Cursor not started")},r.fail=_t(s),r.next=function(){var e=this,t=1;return this.start((function(){return t--?e.continue():e.stop()})).then((function(){return e}))},r.start=function(e){var t=new Promise((function(e,t){e=_t(e),p.onerror=An(t),r.fail=t,r.stop=function(t){r.stop=r.continue=r.continuePrimaryKey=r.advance=u,e(t)}})),n=function(){if(p.result)try{e()}catch(e){r.fail(e)}else r.done=!0,r.start=function(){throw new Error("Cursor behind last entry")},r.stop()};return p.onsuccess=_t((function(e){p.onsuccess=n,n()})),r.continue=i,r.continuePrimaryKey=o,r.advance=a,n(),t},e(r)}else e(null)}),s)}))},count:function(e){var n=e.query,r=e.trans,i=n.index,a=n.range;return new Promise((function(e,n){var u=r.objectStore(t),s=i.isPrimaryKey?u:u.index(i.name),c=o(a),l=c?s.count(c):s.count();l.onsuccess=_t((function(t){return e(t.target.result)})),l.onerror=An(n)}))}}}(e)})),l={};return c.forEach((function(e){return l[e.name]=e})),{stack:"dbcore",transaction:e.transaction.bind(e),table:function(e){if(!l[e])throw new Error("Table '"+e+"' not found");return l[e]},cmp:i,MIN_KEY:-1/0,MAX_KEY:jn(n),schema:u}}function Un(e,t){var n=t.db,r=function(e,t,n,r){var i=n.IDBKeyRange;return{dbcore:function(e,t){return t.reduce((function(e,t){var n=t.create;return P(P({},e),n(e))}),e)}(Mn(t,n.indexedDB,i,r),e.dbcore)}}(e._middlewares,n,e._deps,t);e.core=r.dbcore,e.tables.forEach((function(t){var n=t.name;e.core.schema.tables.some((function(e){return e.name===n}))&&(t.core=e.core.table(n),e[n]instanceof e.Table&&(e[n].core=t.core))}))}function Ln(e,t,n,r){n.forEach((function(n){var i=r[n];t.forEach((function(t){var r=N(t,n);(!r||"value"in r&&void 0===r.value)&&(t===e.Transaction.prototype||t instanceof e.Transaction?B(t,n,{get:function(){return this.table(n)},set:function(e){R(this,n,{value:e,writable:!0,configurable:!0,enumerable:!0})}}):t[n]=new e.Table(n,i))}))}))}function Wn(e,t){t.forEach((function(t){for(var n in t)t[n]instanceof e.Table&&delete t[n]}))}function Hn(e,t){return e._cfg.version-t._cfg.version}function zn(e,t){var n,r={del:[],add:[],change:[]};for(n in e)t[n]||r.del.push(n);for(n in t){var i=e[n],o=t[n];if(i){var a={name:n,def:o,recreate:!1,del:[],add:[],change:[]};if(""+(i.primKey.keyPath||"")!=""+(o.primKey.keyPath||"")||i.primKey.auto!==o.primKey.auto&&!Xt)a.recreate=!0,r.change.push(a);else{var u=i.idxByName,s=o.idxByName,c=void 0;for(c in u)s[c]||a.del.push(c);for(c in s){var l=u[c],f=s[c];l?l.src!==f.src&&a.change.push(f):a.add.push(f)}(a.del.length>0||a.add.length>0||a.change.length>0)&&r.change.push(a)}}else r.add.push([n,o])}return r}function Vn(e,t,n,r){var i=e.db.createObjectStore(t,n.keyPath?{keyPath:n.keyPath,autoIncrement:n.auto}:{autoIncrement:n.auto});return r.forEach((function(e){return Gn(i,e)})),i}function Gn(e,t){e.createIndex(t.name,t.keyPath,{unique:t.unique,multiEntry:t.multi})}function Qn(e,t,n){var r={};return U(t.objectStoreNames,0).forEach((function(e){for(var t=n.objectStore(e),i=t.keyPath,o=Kn(Dn(i),i||"",!1,!1,!!t.autoIncrement,i&&"string"!=typeof i,!0),a=[],u=0;u<t.indexNames.length;++u){var s=t.index(t.indexNames[u]);i=s.keyPath;var c=Kn(s.name,i,!!s.unique,!!s.multiEntry,!1,i&&"string"!=typeof i,!1);a.push(c)}r[e]=Tn(e,o,a)})),r}function Yn(e,t,n){for(var r=n.db.objectStoreNames,i=0;i<r.length;++i){var o=r[i],a=n.objectStore(o);e._hasGetAll="getAll"in a;for(var u=0;u<a.indexNames.length;++u){var s=a.indexNames[u],c=a.index(s).keyPath,l="string"==typeof c?c:"["+U(c).join("+")+"]";if(t[o]){var f=t[o].idxByName[l];f&&(f.name=s,delete t[o].idxByName[l],t[o].idxByName[s]=f)}}}"undefined"!=typeof navigator&&/Safari/.test(navigator.userAgent)&&!/(Chrome\/|Edge\/)/.test(navigator.userAgent)&&A.WorkerGlobalScope&&A instanceof A.WorkerGlobalScope&&[].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1]<604&&(e._hasGetAll=!1)}var Xn,$n=function(){function e(){}return e.prototype._parseStoresSpec=function(e,t){O(e).forEach((function(n){if(null!==e[n]){var r=e[n].split(",").map((function(e,t){var n=(e=e.trim()).replace(/([&*]|\+\+)/g,""),r=/^\[/.test(n)?n.match(/^\[(.*)\]$/)[1].split("+"):n;return Kn(n,r||null,/\&/.test(e),/\*/.test(e),/\+\+/.test(e),j(r),0===t)})),i=r.shift();if(i.multi)throw new Ee.Schema("Primary key cannot be multi-valued");r.forEach((function(e){if(e.auto)throw new Ee.Schema("Only primary key can be marked as autoIncrement (++)");if(!e.keyPath)throw new Ee.Schema("Index must have a name and cannot be an empty string")})),t[n]=Tn(n,i,r)}}))},e.prototype.stores=function(e){var t=this.db;this._cfg.storesSource=this._cfg.storesSource?C(this._cfg.storesSource,e):e;var n=t._versions,r={},i={};return n.forEach((function(e){C(r,e._cfg.storesSource),i=e._cfg.dbschema={},e._parseStoresSpec(r,i)})),t._dbSchema=i,Wn(t,[t._allTables,t,t.Transaction.prototype]),Ln(t,[t._allTables,t,t.Transaction.prototype,this._cfg.tables],O(i),i),t._storeNames=O(i),this},e.prototype.upgrade=function(e){return this._cfg.contentUpgrade=e,this},e}();function Jn(e){return jt((function(){return nt.letThrough=!0,e()}))}function Zn(e){var t=e._state,n=e._deps.indexedDB;if(t.isBeingOpened||e.idbdb)return t.dbReadyPromise.then((function(){return t.dbOpenError?Lt(t.dbOpenError):e}));fe&&(t.openCanceller._stackHolder=ye()),t.isBeingOpened=!0,t.dbOpenError=null,t.openComplete=!1;var r=t.dbReadyResolve,i=null;return at.race([t.openCanceller,new at((function(r,o){if(!n)throw new Ee.MissingAPI("indexedDB API not found. If using IE10+, make sure to run your code on a server URL (not locally). If using old Safari versions, make sure to include indexedDB polyfill.");var a=e.name,u=t.autoSchema?n.open(a):n.open(a,Math.round(10*e.verno));if(!u)throw new Ee.MissingAPI("IndexedDB API not available");u.onerror=An(o),u.onblocked=_t(e._fireOnBlocked),u.onupgradeneeded=_t((function(r){if(i=u.transaction,t.autoSchema&&!e._options.allowEmptyDB){u.onerror=Cn,i.abort(),u.result.close();var s=n.deleteDatabase(a);s.onsuccess=s.onerror=_t((function(){o(new Ee.NoSuchDatabase("Database "+a+" doesnt exist"))}))}else{i.onerror=An(o);var c=r.oldVersion>Math.pow(2,62)?0:r.oldVersion;e.idbdb=u.result,function(e,t,n,r){var i=e._dbSchema,o=e._createTransaction("readwrite",e._storeNames,i);o.create(n),o._completion.catch(r);var a=o._reject.bind(o),u=nt.transless||nt;jt((function(){nt.trans=o,nt.transless=u,0===t?(O(i).forEach((function(e){Vn(n,e,i[e].primKey,i[e].indexes)})),Un(e,n),at.follow((function(){return e.on.populate.fire(o)})).catch(a)):function(e,t,n,r){var i=[],o=e._versions,a=e._dbSchema=Qn(0,e.idbdb,r),u=!1;return o.filter((function(e){return e._cfg.version>=t})).forEach((function(o){i.push((function(){var i=a,s=o._cfg.dbschema;Yn(e,i,r),Yn(e,s,r),a=e._dbSchema=s;var c=zn(i,s);c.add.forEach((function(e){Vn(r,e[0],e[1].primKey,e[1].indexes)})),c.change.forEach((function(e){if(e.recreate)throw new Ee.Upgrade("Not yet support for changing primary key");var t=r.objectStore(e.name);e.add.forEach((function(e){return Gn(t,e)})),e.change.forEach((function(e){t.deleteIndex(e.name),Gn(t,e)})),e.del.forEach((function(e){return t.deleteIndex(e)}))}));var l=o._cfg.contentUpgrade;if(l&&o._cfg.version>t){Un(e,r),n._memoizedTables={},u=!0;var f=Y(s);c.del.forEach((function(e){f[e]=i[e]})),Wn(e,[e.Transaction.prototype]),Ln(e,[e.Transaction.prototype],O(f),f),n.schema=f;var h,d=le(l);d&&At();var p=at.follow((function(){if((h=l(n))&&d){var e=Ct.bind(null,null);h.then(e,e)}}));return h&&"function"==typeof h.then?at.resolve(h):p.then((function(){return h}))}})),i.push((function(t){u&&$t||function(e,t){for(var n=0;n<t.db.objectStoreNames.length;++n){var r=t.db.objectStoreNames[n];null==e[r]&&t.db.deleteObjectStore(r)}}(o._cfg.dbschema,t),Wn(e,[e.Transaction.prototype]),Ln(e,[e.Transaction.prototype],e._storeNames,e._dbSchema),n.schema=e._dbSchema}))})),function e(){return i.length?at.resolve(i.shift()(n.idbtrans)).then(e):at.resolve()}().then((function(){var e,t;t=r,O(e=a).forEach((function(n){t.db.objectStoreNames.contains(n)||Vn(t,n,e[n].primKey,e[n].indexes)}))}))}(e,t,o,n).catch(a)}))}(e,c/10,i,o)}}),o),u.onsuccess=_t((function(){i=null;var n=e.idbdb=u.result,o=U(n.objectStoreNames);if(o.length>0)try{var s=n.transaction(On(o),"readonly");t.autoSchema?function(e,t,n){e.verno=t.version/10;var r=e._dbSchema=Qn(0,t,n);e._storeNames=U(t.objectStoreNames,0),Ln(e,[e._allTables],O(r),r)}(e,n,s):(Yn(e,e._dbSchema,s),function(e,t){var n=zn(Qn(0,e.idbdb,t),e._dbSchema);return!(n.add.length||n.change.some((function(e){return e.add.length||e.change.length})))}(e,s)||console.warn("Dexie SchemaDiff: Schema was extended without increasing the number passed to db.version(). Some queries may fail.")),Un(e,s)}catch(e){}Yt.push(e),n.onversionchange=_t((function(n){t.vcFired=!0,e.on("versionchange").fire(n)})),Xn.add(a),r()}),o)}))]).then((function(){return t.onReadyBeingFired=[],at.resolve(Jn(e.on.ready.fire)).then((function e(){if(t.onReadyBeingFired.length>0){var n=t.onReadyBeingFired.reduce(Fe,Ae);return t.onReadyBeingFired=[],at.resolve(Jn(n)).then(e)}}))})).finally((function(){t.onReadyBeingFired=null})).then((function(){return t.isBeingOpened=!1,e})).catch((function(n){try{i&&i.abort()}catch(e){}return t.isBeingOpened=!1,e.close(),t.dbOpenError=n,Lt(t.dbOpenError)})).finally((function(){t.openComplete=!0,r()}))}function er(e){var t=function(t){return e.next(t)},n=i(t),r=i((function(t){return e.throw(t)}));function i(e){return function(t){var i=e(t),o=i.value;return i.done?o:o&&"function"==typeof o.then?o.then(n,r):j(o)?Promise.all(o).then(n,r):n(o)}}return i(t)()}function tr(e,t,n){var r=arguments.length;if(r<2)throw new Ee.InvalidArgument("Too few arguments");for(var i=new Array(r-1);--r;)i[r-1]=arguments[r];n=i.pop();var o=$(i);return[e,o,n]}function nr(e,t,n,r,i){return at.resolve().then((function(){var o=nt.transless||nt,a=e._createTransaction(t,n,e._dbSchema,r),u={trans:a,transless:o};r?a.idbtrans=r.idbtrans:a.create();var s,c=le(i);c&&At();var l=at.follow((function(){if(s=i.call(a,a))if(c){var e=Ct.bind(null,null);s.then(e,e)}else"function"==typeof s.next&&"function"==typeof s.throw&&(s=er(s))}),u);return(s&&"function"==typeof s.then?at.resolve(s).then((function(e){return a.active?e:Lt(new Ee.PrematureCommit("Transaction committed too early. See http://bit.ly/2kdckMn"))})):l.then((function(){return s}))).then((function(e){return r&&a._resolve(),a._completion.then((function(){return e}))})).catch((function(e){return a._reject(e),Lt(e)}))}))}function rr(e,t,n){for(var r=j(e)?e.slice():[e],i=0;i<n;++i)r.push(t);return r}var ir={stack:"dbcore",name:"VirtualIndexMiddleware",level:1,create:function(e){return P(P({},e),{table:function(t){var n=e.table(t),r=n.schema,i={},o=[];function a(e,t,n){var r=Nn(e),u=i[r]=i[r]||[],s=null==e?0:"string"==typeof e?1:e.length,c=t>0,l=P(P({},n),{isVirtual:c,isPrimaryKey:!c&&n.isPrimaryKey,keyTail:t,keyLength:s,extractKey:Rn(e),unique:!c&&n.unique});return u.push(l),l.isPrimaryKey||o.push(l),s>1&&a(2===s?e[0]:e.slice(0,s-1),t+1,n),u.sort((function(e,t){return e.keyTail-t.keyTail})),l}var u=a(r.primaryKey.keyPath,0,r.primaryKey);i[":id"]=[u];for(var s=0,c=r.indexes;s<c.length;s++){var l=c[s];a(l.keyPath,0,l)}function f(t){var n,r,i=t.query.index;return i.isVirtual?P(P({},t),{query:{index:i,range:(n=t.query.range,r=i.keyTail,{type:1===n.type?2:n.type,lower:rr(n.lower,n.lowerOpen?e.MAX_KEY:e.MIN_KEY,r),lowerOpen:!0,upper:rr(n.upper,n.upperOpen?e.MIN_KEY:e.MAX_KEY,r),upperOpen:!0})}}):t}return P(P({},n),{schema:P(P({},r),{primaryKey:u,indexes:o,getIndexByKeyPath:function(e){var t=i[Nn(e)];return t&&t[0]}}),count:function(e){return n.count(f(e))},query:function(e){return n.query(f(e))},openCursor:function(t){var r=t.query.index,i=r.keyTail,o=r.isVirtual,a=r.keyLength;return o?n.openCursor(f(t)).then((function(n){return n&&function(n){return Object.create(n,{continue:{value:function(r){null!=r?n.continue(rr(r,t.reverse?e.MAX_KEY:e.MIN_KEY,i)):t.unique?n.continue(rr(n.key,t.reverse?e.MIN_KEY:e.MAX_KEY,i)):n.continue()}},continuePrimaryKey:{value:function(t,r){n.continuePrimaryKey(rr(t,e.MAX_KEY,i),r)}},key:{get:function(){var e=n.key;return 1===a?e[0]:e.slice(0,a)}},value:{get:function(){return n.value}}})}(n)})):n.openCursor(t)}})}})}},or={stack:"dbcore",name:"HooksMiddleware",level:2,create:function(e){return P(P({},e),{table:function(t){var n=e.table(t),r=n.schema.primaryKey;return P(P({},n),{mutate:function(e){var i=nt.trans,o=i.table(t).hook,a=o.deleting,u=o.creating,s=o.updating;switch(e.type){case"add":if(u.fire===Ae)break;return i._promise("readwrite",(function(){return c(e)}),!0);case"put":if(u.fire===Ae&&s.fire===Ae)break;return i._promise("readwrite",(function(){return c(e)}),!0);case"delete":if(a.fire===Ae)break;return i._promise("readwrite",(function(){return c(e)}),!0);case"deleteRange":if(a.fire===Ae)break;return i._promise("readwrite",(function(){return function(e){return l(e.trans,e.range,1e4)}(e)}),!0)}return n.mutate(e);function c(e){var t=nt.trans,i=e.keys||Bn(r,e);if(!i)throw new Error("Keys missing");return"delete"!==(e="add"===e.type||"put"===e.type?P(P({},e),{keys:i,wantResults:!0}):P({},e)).type&&(e.values=E(e.values)),e.keys&&(e.keys=E(e.keys)),function(e,t,n){return"add"===t.type?Promise.resolve(new Array(t.values.length)):e.getMany({trans:t.trans,keys:n})}(n,e,i).then((function(o){var c=i.map((function(n,i){var c=o[i],l={onerror:null,onsuccess:null};if("delete"===e.type)a.fire.call(l,n,c,t);else if("add"===e.type||void 0===c){var f=u.fire.call(l,n,e.values[i],t);null==n&&null!=f&&(n=f,e.keys[i]=n,r.outbound||G(e.values[i],r.keyPath,n))}else{var h=oe(c,e.values[i]),d=s.fire.call(l,h,n,c,t);if(d){var p=e.values[i];Object.keys(d).forEach((function(e){D(p,e)?p[e]=d[e]:G(p,e,d[e])}))}}return l}));return n.mutate(e).then((function(t){for(var n=t.failures,r=t.results,a=t.numFailures,u=t.lastResult,s=0;s<i.length;++s){var l=r?r[s]:i[s],f=c[s];null==l?f.onerror&&f.onerror(n[s]):f.onsuccess&&f.onsuccess("put"===e.type&&o[s]?e.values[s]:l)}return{failures:n,results:r,numFailures:a,lastResult:u}})).catch((function(e){return c.forEach((function(t){return t.onerror&&t.onerror(e)})),Promise.reject(e)}))}))}function l(e,t,i){return n.query({trans:e,values:!1,query:{index:r,range:t},limit:i}).then((function(n){var r=n.result;return c({type:"delete",keys:r,trans:e}).then((function(n){return n.numFailures>0?Promise.reject(n.failures[0]):r.length<i?{failures:[],numFailures:0,lastResult:void 0}:l(e,P(P({},t),{lower:r[r.length-1],lowerOpen:!0}),i)}))}))}}})}})}},ar=function(){function e(t,n){var r=this;this._middlewares={},this.verno=0;var i=e.dependencies;this._options=n=P({addons:e.addons,autoOpen:!0,indexedDB:i.indexedDB,IDBKeyRange:i.IDBKeyRange},n),this._deps={indexedDB:n.indexedDB,IDBKeyRange:n.IDBKeyRange};var o=n.addons;this._dbSchema={},this._versions=[],this._storeNames=[],this._allTables={},this.idbdb=null;var a={dbOpenError:null,isBeingOpened:!1,onReadyBeingFired:null,openComplete:!1,dbReadyResolve:Ae,dbReadyPromise:null,cancelOpen:Ae,openCanceller:null,autoSchema:!0};a.dbReadyPromise=new at((function(e){a.dbReadyResolve=e})),a.openCanceller=new at((function(e,t){a.cancelOpen=t})),this._state=a,this.name=t,this.on=sn(this,"populate","blocked","versionchange",{ready:[Fe,Ae]}),this.on.ready.subscribe=L(this.on.ready.subscribe,(function(t){return function(n,i){e.vip((function(){var e=r._state;if(e.openComplete)e.dbOpenError||at.resolve().then(n),i&&t(n);else if(e.onReadyBeingFired)e.onReadyBeingFired.push(n),i&&t(n);else{t(n);var o=r;i||t((function e(){o.on.ready.unsubscribe(n),o.on.ready.unsubscribe(e)}))}}))}})),this.Collection=function(e){return cn(mn.prototype,(function(t,n){this.db=e;var r=on,i=null;if(n)try{r=n()}catch(e){i=e}var o=t._ctx,a=o.table,u=a.hook.reading.fire;this._ctx={table:a,index:o.index,isPrimKey:!o.index||a.schema.primKey.keyPath&&o.index===a.schema.primKey.name,range:r,keysOnly:!1,dir:"next",unique:"",algorithm:null,filter:null,replayFilter:null,justLimit:!0,isMatch:null,offset:0,limit:1/0,error:i,or:o.or,valueMapper:u!==Ce?u:null}}))}(this),this.Table=function(e){return cn(un.prototype,(function(t,n,r){this.db=e,this._tx=r,this.name=t,this.schema=n,this.hook=e._allTables[t]?e._allTables[t].hook:sn(null,{creating:[De,Ae],reading:[Ie,Ce],updating:[Re,Ae],deleting:[Te,Ae]})}))}(this),this.Transaction=function(e){return cn(In.prototype,(function(t,n,r,i){var o=this;this.db=e,this.mode=t,this.storeNames=n,this.schema=r,this.idbtrans=null,this.on=sn(this,"complete","error","abort"),this.parent=i||null,this.active=!0,this._reculock=0,this._blockedFuncs=[],this._resolve=null,this._reject=null,this._waitingFor=null,this._waitingQueue=null,this._spinCount=0,this._completion=new at((function(e,t){o._resolve=e,o._reject=t})),this._completion.then((function(){o.active=!1,o.on.complete.fire()}),(function(e){var t=o.active;return o.active=!1,o.on.error.fire(e),o.parent?o.parent._reject(e):t&&o.idbtrans&&o.idbtrans.abort(),Lt(e)}))}))}(this),this.Version=function(e){return cn($n.prototype,(function(t){this.db=e,this._cfg={version:t,storesSource:null,dbschema:{},tables:{},contentUpgrade:null}}))}(this),this.WhereClause=function(e){return cn(En.prototype,(function(t,n,r){this.db=e,this._ctx={table:t,index:":id"===n?null:n,or:r};var i=e._deps.indexedDB;if(!i)throw new Ee.MissingAPI("indexedDB API missing");this._cmp=this._ascending=i.cmp.bind(i),this._descending=function(e,t){return i.cmp(t,e)},this._max=function(e,t){return i.cmp(e,t)>0?e:t},this._min=function(e,t){return i.cmp(e,t)<0?e:t},this._IDBKeyRange=e._deps.IDBKeyRange}))}(this),this.on("versionchange",(function(e){e.newVersion>0?console.warn("Another connection wants to upgrade database '"+r.name+"'. Closing db now to resume the upgrade."):console.warn("Another connection wants to delete database '"+r.name+"'. Closing db now to resume the delete request."),r.close()})),this.on("blocked",(function(e){!e.newVersion||e.newVersion<e.oldVersion?console.warn("Dexie.delete('"+r.name+"') was blocked"):console.warn("Upgrade '"+r.name+"' blocked by other connection holding version "+e.oldVersion/10)})),this._maxKey=jn(n.IDBKeyRange),this._createTransaction=function(e,t,n,i){return new r.Transaction(e,t,n,i)},this._fireOnBlocked=function(e){r.on("blocked").fire(e),Yt.filter((function(e){return e.name===r.name&&e!==r&&!e._state.vcFired})).map((function(t){return t.on("versionchange").fire(e)}))},this.use(ir),this.use(or),o.forEach((function(e){return e(r)}))}return e.prototype.version=function(e){if(isNaN(e)||e<.1)throw new Ee.Type("Given version is not a positive number");if(e=Math.round(10*e)/10,this.idbdb||this._state.isBeingOpened)throw new Ee.Schema("Cannot add version when database is open");this.verno=Math.max(this.verno,e);var t=this._versions,n=t.filter((function(t){return t._cfg.version===e}))[0];return n||(n=new this.Version(e),t.push(n),t.sort(Hn),n.stores({}),this._state.autoSchema=!1,n)},e.prototype._whenReady=function(e){var t=this;return this._state.openComplete||nt.letThrough?e():new at((function(e,n){if(!t._state.isBeingOpened){if(!t._options.autoOpen)return void n(new Ee.DatabaseClosed);t.open().catch(Ae)}t._state.dbReadyPromise.then(e,n)})).then(e)},e.prototype.use=function(e){var t=e.stack,n=e.create,r=e.level,i=e.name;i&&this.unuse({stack:t,name:i});var o=this._middlewares[t]||(this._middlewares[t]=[]);return o.push({stack:t,create:n,level:null==r?10:r,name:i}),o.sort((function(e,t){return e.level-t.level})),this},e.prototype.unuse=function(e){var t=e.stack,n=e.name,r=e.create;return t&&this._middlewares[t]&&(this._middlewares[t]=this._middlewares[t].filter((function(e){return r?e.create!==r:!!n&&e.name!==n}))),this},e.prototype.open=function(){return Zn(this)},e.prototype.close=function(){var e=Yt.indexOf(this),t=this._state;if(e>=0&&Yt.splice(e,1),this.idbdb){try{this.idbdb.close()}catch(e){}this.idbdb=null}this._options.autoOpen=!1,t.dbOpenError=new Ee.DatabaseClosed,t.isBeingOpened&&t.cancelOpen(t.dbOpenError),t.dbReadyPromise=new at((function(e){t.dbReadyResolve=e})),t.openCanceller=new at((function(e,n){t.cancelOpen=n}))},e.prototype.delete=function(){var e=this,t=arguments.length>0,n=this._state;return new at((function(r,i){var o=function(){e.close();var t=e._deps.indexedDB.deleteDatabase(e.name);t.onsuccess=_t((function(){Xn.remove(e.name),r()})),t.onerror=An(i),t.onblocked=e._fireOnBlocked};if(t)throw new Ee.InvalidArgument("Arguments not allowed in db.delete()");n.isBeingOpened?n.dbReadyPromise.then(o):o()}))},e.prototype.backendDB=function(){return this.idbdb},e.prototype.isOpen=function(){return null!==this.idbdb},e.prototype.hasBeenClosed=function(){var e=this._state.dbOpenError;return e&&"DatabaseClosed"===e.name},e.prototype.hasFailed=function(){return null!==this._state.dbOpenError},e.prototype.dynamicallyOpened=function(){return this._state.autoSchema},Object.defineProperty(e.prototype,"tables",{get:function(){var e=this;return O(this._allTables).map((function(t){return e._allTables[t]}))},enumerable:!0,configurable:!0}),e.prototype.transaction=function(){var e=tr.apply(this,arguments);return this._transaction.apply(this,e)},e.prototype._transaction=function(e,t,n){var r=this,i=nt.trans;i&&i.db===this&&-1===e.indexOf("!")||(i=null);var o,a,u=-1!==e.indexOf("?");e=e.replace("!","").replace("?","");try{if(a=t.map((function(e){var t=e instanceof r.Table?e.name:e;if("string"!=typeof t)throw new TypeError("Invalid table argument to Dexie.transaction(). Only Table or String are allowed");return t})),"r"==e||e===tn)o=tn;else{if("rw"!=e&&e!=nn)throw new Ee.InvalidArgument("Invalid transaction mode: "+e);o=nn}if(i){if(i.mode===tn&&o===nn){if(!u)throw new Ee.SubTransaction("Cannot enter a sub-transaction with READWRITE mode when parent transaction is READONLY");i=null}i&&a.forEach((function(e){if(i&&-1===i.storeNames.indexOf(e)){if(!u)throw new Ee.SubTransaction("Table "+e+" not included in parent transaction.");i=null}})),u&&i&&!i.active&&(i=null)}}catch(e){return i?i._promise(null,(function(t,n){n(e)})):Lt(e)}var s=nr.bind(null,this,o,a,i,n);return i?i._promise(o,s,"lock"):nt.trans?Bt(nt.transless,(function(){return r._whenReady(s)})):this._whenReady(s)},e.prototype.table=function(e){if(!D(this._allTables,e))throw new Ee.InvalidTable("Table "+e+" does not exist");return this._allTables[e]},e}(),ur=ar;T(ur,P(P({},je),{delete:function(e){return new ur(e).delete()},exists:function(e){return new ur(e,{addons:[]}).open().then((function(e){return e.close(),!0})).catch("NoSuchDatabaseError",(function(){return!1}))},getDatabaseNames:function(e){return Xn?Xn.getDatabaseNames().then(e):at.resolve([])},defineClass:function(){return function(e){C(this,e)}},ignoreTransaction:function(e){return nt.trans?Bt(nt.transless,e):e()},vip:Jn,async:function(e){return function(){try{var t=er(e.apply(this,arguments));return t&&"function"==typeof t.then?t:at.resolve(t)}catch(e){return Lt(e)}}},spawn:function(e,t,n){try{var r=er(e.apply(n,t||[]));return r&&"function"==typeof r.then?r:at.resolve(r)}catch(e){return Lt(e)}},currentTransaction:{get:function(){return nt.trans||null}},waitFor:function(e,t){var n=at.resolve("function"==typeof e?ur.ignoreTransaction(e):e).timeout(t||6e4);return nt.trans?nt.trans.waitFor(n):n},Promise:at,debug:{get:function(){return fe},set:function(e){he(e,"dexie"===e?function(){return!0}:Zt)}},derive:F,extend:C,props:T,override:L,Events:sn,getByKeyPath:V,setByKeyPath:G,delByKeyPath:Q,shallowClone:Y,deepClone:te,getObjectDiff:oe,asap:H,minKey:Vt,addons:[],connections:Yt,errnames:Se,dependencies:function(){try{return{indexedDB:A.indexedDB||A.mozIndexedDB||A.webkitIndexedDB||A.msIndexedDB,IDBKeyRange:A.IDBKeyRange||A.webkitIDBKeyRange}}catch(e){return{indexedDB:null,IDBKeyRange:null}}}(),semVer:Ht,version:Ht.split(".").map((function(e){return parseInt(e)})).reduce((function(e,t,n){return e+t/Math.pow(10,2*n)})),default:ur,Dexie:ur})),ur.maxKey=jn(ur.dependencies.IDBKeyRange),function(e){try{Xn=function(e){var t,n=e&&"function"==typeof e.databases;if(!n){var r=new ar(en,{addons:[]});r.version(1).stores({dbnames:"name"}),t=r.table("dbnames")}return{getDatabaseNames:function(){return n?at.resolve(e.databases()).then((function(e){return e.map((function(e){return e.name})).filter((function(e){return e!==en}))})):t.toCollection().primaryKeys()},add:function(e){return!n&&e!==en&&t.put({name:e}).catch(Ae)},remove:function(e){return!n&&e!==en&&t.delete(e).catch(Ae)}}}(e)}catch(e){}}(ar.dependencies.indexedDB),at.rejectionMapper=function(e,t){if(!e||e instanceof we||e instanceof TypeError||e instanceof SyntaxError||!e.name||!Oe[e.name])return e;var n=new Oe[e.name](t||e.message,e);return"stack"in e&&B(n,"stack",{get:function(){return this.inner.stack}}),n},he(fe,Zt);const sr=ar;var cr=o(766),lr=o(685);const fr=new class extends sr{constructor(){super("EsmOffline"),this.version(3).stores({syncQueue:"++id,userId,type,[userId+type]"}),this.syncQueue=this.table("syncQueue")}},hr={};function dr(){return fr}const pr=(0,lr.createGlobalStore)("offline-synchronization",{});function yr(){return pr}async function vr(){if(pr.getState().synchronization)return;const e=await fr.syncQueue.count(),t={},n=Object.entries(hr),r=n.length,i={},o=new AbortController,a=()=>{const e=pr.getState().synchronization;pr.setState({synchronization:{...e,pendingCount:e.pendingCount-1}})};try{pr.setState({synchronization:{totalCount:e,pendingCount:e,abortController:o}});for(let e=0;e<r&&n.length>0;e++)for(let e=n.length;e--;){const[r,u]=n[e],s=u.dependsOn.map((e=>t[e]));s.every(Boolean)&&(i[r]={},await Promise.all(s),t[r]=mr(u,i,o,a),n.splice(e,1))}await Promise.allSettled(Object.values(t))}finally{pr.setState({synchronization:void 0})}}async function mr({type:e,dependsOn:t,process:n},r,i,o){const a=fr.syncQueue,u=[],s=[],c=await gr();await a.where({type:e,userId:c}).each(((e,t)=>{u.push([t.primaryKey,e.content,e.descriptor]),s.push(e.content)}));for(let f=0;f<u.length;f++){const[h,d,{id:p,dependencies:y=[]}]=u[f];try{const u=await n(d,{abort:i,index:f,items:s,userId:c,dependencies:y.map((({id:e,type:n})=>t.includes(n)?r[n][e]:void 0))});void 0!==p&&(r[e][p]=u),await a.delete(h)}catch(e){var l;await a.update(h,{lastError:{name:null==e?void 0:e.name,message:null!==(l=null==e?void 0:e.message)&&void 0!==l?l:null==e?void 0:e.toString()}})}finally{o()}}}async function gr(){const e=await(0,cr.getLoggedInUser)();return(null==e?void 0:e.uuid)||"*"}async function br(e,t,n,r){const i=fr.syncQueue,o=r&&r.id;return void 0!==o&&await i.where({type:t,userId:e}).filter((e=>(null==e?void 0:e.descriptor.id)===o)).delete(),await i.add({type:t,content:n,userId:e,descriptor:r||{},createdOn:new Date})}async function wr(e,t,n){const r=await gr();return await br(r,e,t,n)}async function _r(e,t){const n=fr.syncQueue,r=[];return await n.where({type:t,userId:e}).each((e=>{r.push(e.content)})),r}async function kr(e){const t=await gr();return await _r(t,e)}async function xr(e){await fr.syncQueue.delete(e)}function Sr(e,t,n){hr[e]={type:e,dependsOn:t,process:n}}var Pr,Er=new Uint8Array(16);function Or(){if(!Pr&&!(Pr="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Pr(Er)}const jr=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i,Ar=function(e){return"string"==typeof e&&jr.test(e)};for(var Cr=[],Ir=0;Ir<256;++Ir)Cr.push((Ir+256).toString(16).substr(1));const Kr=function(e,t,n){var r=(e=e||{}).random||(e.rng||Or)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(var i=0;i<16;++i)t[n+i]=r[i];return t}return function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(Cr[e[t+0]]+Cr[e[t+1]]+Cr[e[t+2]]+Cr[e[t+3]]+"-"+Cr[e[t+4]]+Cr[e[t+5]]+"-"+Cr[e[t+6]]+Cr[e[t+7]]+"-"+Cr[e[t+8]]+Cr[e[t+9]]+"-"+Cr[e[t+10]]+Cr[e[t+11]]+Cr[e[t+12]]+Cr[e[t+13]]+Cr[e[t+14]]+Cr[e[t+15]]).toLowerCase();if(!Ar(n))throw TypeError("Stringified UUID is invalid");return n}(r)},Dr="OFFLINE+";function Tr(){return Dr+Kr()}function Rr(e){return e.startsWith(Dr)}const Br=(0,lr.createGlobalStore)("offline-patients",{offlinePatientDataSyncState:{},handlers:{}});function Fr(){return Br}function qr(e,t){const n=Br.getState();Br.setState({handlers:{...n.handlers,[e]:t}})}async function Nr(e){const t=Object.entries(Br.getState().handlers),n=t.map((([e])=>e)),r=[],i=[],o={},a=new AbortController;await Mr(e,{timestamp:new Date,syncingHandlers:n,syncedHandlers:r,failedHandlers:i,errors:o,abort:()=>(a.abort(),!0)}),await Promise.all(t.map((async([t,n])=>{try{await n.onOfflinePatientAdded({patientUuid:e,signal:a.signal}),console.debug(`Offline patient handler ${t} successfully synchronized patient data.`),r.push(t)}catch(e){var u,s;console.error(`Offline patient handler ${t} failed. Error: `,e),i.push(t),o[t]=null!==(u=null!==(s=null==e?void 0:e.message)&&void 0!==s?s:null==e?void 0:e.toString())&&void 0!==u?u:""}}))),await Mr(e,{timestamp:new Date,syncingHandlers:[],syncedHandlers:r,failedHandlers:i,errors:o,abort:()=>!1})}async function Mr(e,t){const n=Br.getState();Br.setState({offlinePatientDataSyncState:{...n.offlinePatientDataSyncState,[e]:t}});const r=new Lr,i=await r.offlinePatientDataSyncStates.get({patientUuid:e}),o={id:null==i?void 0:i.id,patientUuid:e,state:{timestamp:t.timestamp,syncedHandlers:t.syncedHandlers,failedHandlers:[...t.failedHandlers,...t.syncingHandlers],errors:t.errors}};await r.offlinePatientDataSyncStates.put(o)}async function Ur(){const e=new Lr,t=await e.offlinePatientDataSyncStates.toArray(),n=Br.getState().offlinePatientDataSyncState;for(const e of t)n[e.patientUuid]={...e.state,syncingHandlers:[],abort:()=>!1};Br.setState({offlinePatientDataSyncState:n})}class Lr extends sr{constructor(){super("EsmOfflinePatientData"),this.version(1).stores({offlinePatientDataSyncStates:"++id,&patientUuid"}),this.offlinePatientDataSyncStates=this.table("offlinePatientDataSyncStates")}}})(),a})())}}}));
|
|
1
|
+
System.register(["@openmrs/esm-api","@openmrs/esm-state"],(function(e,t){var n={},r={};return{setters:[function(e){n.getLoggedInUser=e.getLoggedInUser},function(e){r.createGlobalStore=e.createGlobalStore}],execute:function(){e((()=>{var e={968:(e,t,n)=>{const r=n(577).R;t.s=function(e){if(e||(e=1),!n.y.meta||!n.y.meta.url)throw console.error("__system_context__",n.y),Error("systemjs-webpack-interop was provided an unknown SystemJS context. Expected context.meta.url, but none was provided");n.p=r(n.y.meta.url,e)}},577:(e,t,n)=>{t.R=function(e,t){var n=document.createElement("a");n.href=e;for(var r="/"===n.pathname[0]?n.pathname:"/"+n.pathname,i=0,s=r.length;i!==t&&s>=0;)"/"===r[--s]&&i++;if(i!==t)throw Error("systemjs-webpack-interop: rootDirectoryLevel ("+t+") is greater than the number of directories ("+i+") in the URL path "+e);var o=r.slice(0,s+1);return n.protocol+"//"+n.host+o};Number.isInteger},766:e=>{"use strict";e.exports=n},685:e=>{"use strict";e.exports=r}},i={};function s(t){var n=i[t];if(void 0!==n)return n.exports;var r=i[t]={exports:{}};return e[t](r,r.exports,s),r.exports}s.y=t,s.d=(e,t)=>{for(var n in t)s.o(t,n)&&!s.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},s.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),s.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),s.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e;s.g.importScripts&&(e=s.g.location+"");var t=s.g.document;if(!e&&t&&(t.currentScript&&(e=t.currentScript.src),!e)){var n=t.getElementsByTagName("script");n.length&&(e=n[n.length-1].src)}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),s.p=e})();var o={};return(0,s(968).s)(1),(()=>{"use strict";s.r(o),s.d(o,{beginEditSynchronizationItem:()=>$r,canBeginEditSynchronizationItemsOfType:()=>Ur,deleteSynchronizationItem:()=>Lr,dispatchNetworkRequestFailed:()=>x,generateOfflineUuid:()=>ei,getOfflineDb:()=>Cr,getOfflinePatientDataStore:()=>ri,getOfflineSynchronizationStore:()=>Ir,getOmrsServiceWorker:()=>y,getSynchronizationItem:()=>qr,getSynchronizationItems:()=>Nr,getSynchronizationItemsFor:()=>Mr,isOfflineUuid:()=>ti,loadPersistedPatientDataSyncState:()=>ai,messageOmrsServiceWorker:()=>b,offlineUuidPrefix:()=>Zr,omrsOfflineCachingStrategyHttpHeaderName:()=>g,omrsOfflineResponseBodyHttpHeaderName:()=>m,omrsOfflineResponseStatusHttpHeaderName:()=>v,patchXMLHttpRequest:()=>S,queueSynchronizationItem:()=>Fr,queueSynchronizationItemFor:()=>Br,registerOfflinePatientHandler:()=>ii,registerOmrsServiceWorker:()=>p,runSynchronization:()=>Dr,setupOfflineSync:()=>Wr,subscribeNetworkRequestFailed:()=>k,syncOfflinePatientData:()=>si});try{self["workbox:window:6.4.1"]&&_()}catch(e){}function e(e,t){return new Promise((function(n){var r=new MessageChannel;r.port1.onmessage=function(e){n(e.data)},e.postMessage(t,[r.port2])}))}function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function n(e,n){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,n){if(e){if("string"==typeof e)return t(e,n);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?t(e,n):void 0}}(e))||n&&e&&"number"==typeof e.length){r&&(e=r);var i=0;return function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=e[Symbol.iterator]()).next.bind(r)}try{self["workbox:core:6.4.1"]&&_()}catch(e){}var r=function(){var e=this;this.promise=new Promise((function(t,n){e.resolve=t,e.reject=n}))};function i(e,t){var n=location.href;return new URL(e,n).href===new URL(t,n).href}var a=function(e,t){this.type=e,Object.assign(this,t)};function u(e,t,n){return n?t?t(e):e:(e&&e.then||(e=Promise.resolve(e)),t?e.then(t):e)}function c(){}var l={type:"SKIP_WAITING"};function h(e,t){if(!t)return e&&e.then?e.then(c):Promise.resolve()}var d=function(t){var n,s;function o(e,n){var s,o;return void 0===n&&(n={}),(s=t.call(this)||this).nn={},s.tn=0,s.rn=new r,s.en=new r,s.on=new r,s.un=0,s.an=new Set,s.cn=function(){var e=s.fn,t=e.installing;s.tn>0||!i(t.scriptURL,s.sn.toString())||performance.now()>s.un+6e4?(s.vn=t,e.removeEventListener("updatefound",s.cn)):(s.hn=t,s.an.add(t),s.rn.resolve(t)),++s.tn,t.addEventListener("statechange",s.ln)},s.ln=function(e){var t=s.fn,n=e.target,r=n.state,i=n===s.vn,o={sw:n,isExternal:i,originalEvent:e};!i&&s.mn&&(o.isUpdate=!0),s.dispatchEvent(new a(r,o)),"installed"===r?s.wn=self.setTimeout((function(){"installed"===r&&t.waiting===n&&s.dispatchEvent(new a("waiting",o))}),200):"activating"===r&&(clearTimeout(s.wn),i||s.en.resolve(n))},s.dn=function(e){var t=s.hn,n=t!==navigator.serviceWorker.controller;s.dispatchEvent(new a("controlling",{isExternal:n,originalEvent:e,sw:t,isUpdate:s.mn})),n||s.on.resolve(t)},s.gn=(o=function(e){var t=e.data,n=e.ports,r=e.source;return u(s.getSW(),(function(){s.an.has(r)&&s.dispatchEvent(new a("message",{data:t,originalEvent:e,ports:n,sw:r}))}))},function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];try{return Promise.resolve(o.apply(this,e))}catch(e){return Promise.reject(e)}}),s.sn=e,s.nn=n,navigator.serviceWorker.addEventListener("message",s.gn),s}s=t,(n=o).prototype=Object.create(s.prototype),n.prototype.constructor=n,n.__proto__=s;var c,d=o.prototype;return d.register=function(e){var t=(void 0===e?{}:e).immediate,n=void 0!==t&&t;try{var r=this;return function(e,t){var n=e();return n&&n.then?n.then(t):t()}((function(){if(!n&&"complete"!==document.readyState)return h(new Promise((function(e){return window.addEventListener("load",e)})))}),(function(){return r.mn=Boolean(navigator.serviceWorker.controller),r.yn=r.pn(),u(r.bn(),(function(e){r.fn=e,r.yn&&(r.hn=r.yn,r.en.resolve(r.yn),r.on.resolve(r.yn),r.yn.addEventListener("statechange",r.ln,{once:!0}));var t=r.fn.waiting;return t&&i(t.scriptURL,r.sn.toString())&&(r.hn=t,Promise.resolve().then((function(){r.dispatchEvent(new a("waiting",{sw:t,wasWaitingBeforeRegister:!0}))})).then((function(){}))),r.hn&&(r.rn.resolve(r.hn),r.an.add(r.hn)),r.fn.addEventListener("updatefound",r.cn),navigator.serviceWorker.addEventListener("controllerchange",r.dn),r.fn}))}))}catch(e){return Promise.reject(e)}},d.update=function(){try{return this.fn?h(this.fn.update()):void 0}catch(e){return Promise.reject(e)}},d.getSW=function(){return void 0!==this.hn?Promise.resolve(this.hn):this.rn.promise},d.messageSW=function(t){try{return u(this.getSW(),(function(n){return e(n,t)}))}catch(e){return Promise.reject(e)}},d.messageSkipWaiting=function(){this.fn&&this.fn.waiting&&e(this.fn.waiting,l)},d.pn=function(){var e=navigator.serviceWorker.controller;return e&&i(e.scriptURL,this.sn.toString())?e:void 0},d.bn=function(){try{var e=this;return function(e,t){try{var n=e()}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}((function(){return u(navigator.serviceWorker.register(e.sn,e.nn),(function(t){return e.un=performance.now(),t}))}),(function(e){throw e}))}catch(e){return Promise.reject(e)}},(c=[{key:"active",get:function(){return this.en.promise}},{key:"controlling",get:function(){return this.on.promise}}])&&function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(o.prototype,c),o}(function(){function e(){this.Pn=new Map}var t=e.prototype;return t.addEventListener=function(e,t){this.Sn(e).add(t)},t.removeEventListener=function(e,t){this.Sn(e).delete(t)},t.dispatchEvent=function(e){e.target=this;for(var t,r=n(this.Sn(e.type));!(t=r()).done;)(0,t.value)(e)},t.Sn=function(e){return this.Pn.has(e)||this.Pn.set(e,new Set),this.Pn.get(e)},e}());let f;function p(e,t){if(void 0!==f)return console.warn(`The application's Service Worker has already been registered. The new service worker at ${e} will not be registered.`),f;if(!("serviceWorker"in navigator))throw new Error("Registering the Service Worker is not possible due to missing browser capabilities.");const n=new d(e,t);return f=n.register().then((()=>n)),f}function y(){return f??Promise.resolve(void 0)}const m="x-omrs-offline-response-body",v="x-omrs-offline-response-status",g="x-omrs-offline-caching-strategy";async function b(e){const t=await y();return t?await t.messageSW(e):{success:!1,result:void 0,error:"No service worker has been registered. This is typically the case when the application has been built without offline-related features."}}const w="openmrs:network-request-failed";function x(e){window.dispatchEvent(new CustomEvent(w,{detail:e}))}function k(e){const t=t=>e(t.detail);return window.addEventListener(w,t),()=>window.removeEventListener(w,t)}function S(){const e=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.send=function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return e.apply(this,n)}}const E="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:global,P=Object.keys,O=Array.isArray;function K(e,t){return"object"!=typeof t||P(t).forEach((function(n){e[n]=t[n]})),e}"undefined"==typeof Promise||E.Promise||(E.Promise=Promise);const j=Object.getPrototypeOf,C={}.hasOwnProperty;function A(e,t){return C.call(e,t)}function I(e,t){"function"==typeof t&&(t=t(j(e))),("undefined"==typeof Reflect?P:Reflect.ownKeys)(t).forEach((n=>{T(e,n,t[n])}))}const D=Object.defineProperty;function T(e,t,n,r){D(e,t,K(n&&A(n,"get")&&"function"==typeof n.get?{get:n.get,set:n.set,configurable:!0}:{value:n,configurable:!0,writable:!0},r))}function R(e){return{from:function(t){return e.prototype=Object.create(t.prototype),T(e.prototype,"constructor",e),{extend:I.bind(null,e.prototype)}}}}const B=Object.getOwnPropertyDescriptor;function F(e,t){let n;return B(e,t)||(n=j(e))&&F(n,t)}const M=[].slice;function N(e,t,n){return M.call(e,t,n)}function q(e,t){return t(e)}function U(e){if(!e)throw new Error("Assertion Failed")}function $(e){E.setImmediate?setImmediate(e):setTimeout(e,0)}function L(e,t){return e.reduce(((e,n,r)=>{var i=t(n,r);return i&&(e[i[0]]=i[1]),e}),{})}function W(e,t){if(A(e,t))return e[t];if(!t)return e;if("string"!=typeof t){for(var n=[],r=0,i=t.length;r<i;++r){var s=W(e,t[r]);n.push(s)}return n}var o=t.indexOf(".");if(-1!==o){var a=e[t.substr(0,o)];return void 0===a?void 0:W(a,t.substr(o+1))}}function z(e,t,n){if(e&&void 0!==t&&(!("isFrozen"in Object)||!Object.isFrozen(e)))if("string"!=typeof t&&"length"in t){U("string"!=typeof n&&"length"in n);for(var r=0,i=t.length;r<i;++r)z(e,t[r],n[r])}else{var s=t.indexOf(".");if(-1!==s){var o=t.substr(0,s),a=t.substr(s+1);if(""===a)void 0===n?O(e)&&!isNaN(parseInt(o))?e.splice(o,1):delete e[o]:e[o]=n;else{var u=e[o];u||(u=e[o]={}),z(u,a,n)}}else void 0===n?O(e)&&!isNaN(parseInt(t))?e.splice(t,1):delete e[t]:e[t]=n}}function H(e){var t={};for(var n in e)A(e,n)&&(t[n]=e[n]);return t}const V=[].concat;function Q(e){return V.apply([],e)}const Y="Boolean,String,Date,RegExp,Blob,File,FileList,FileSystemFileHandle,ArrayBuffer,DataView,Uint8ClampedArray,ImageBitmap,ImageData,Map,Set,CryptoKey".split(",").concat(Q([8,16,32,64].map((e=>["Int","Uint","Float"].map((t=>t+e+"Array")))))).filter((e=>E[e])),G=Y.map((e=>E[e]));L(Y,(e=>[e,!0]));let X=null;function J(e){X="undefined"!=typeof WeakMap&&new WeakMap;const t=Z(e);return X=null,t}function Z(e){if(!e||"object"!=typeof e)return e;let t=X&&X.get(e);if(t)return t;if(O(e)){t=[],X&&X.set(e,t);for(var n=0,r=e.length;n<r;++n)t.push(Z(e[n]))}else if(G.indexOf(e.constructor)>=0)t=e;else{const n=j(e);for(var i in t=n===Object.prototype?{}:Object.create(n),X&&X.set(e,t),e)A(e,i)&&(t[i]=Z(e[i]))}return t}const{toString:ee}={};function te(e){return ee.call(e).slice(8,-1)}const ne="undefined"!=typeof Symbol?Symbol.iterator:"@@iterator",re="symbol"==typeof ne?function(e){var t;return null!=e&&(t=e[ne])&&t.apply(e)}:function(){return null},ie={};function se(e){var t,n,r,i;if(1===arguments.length){if(O(e))return e.slice();if(this===ie&&"string"==typeof e)return[e];if(i=re(e)){for(n=[];!(r=i.next()).done;)n.push(r.value);return n}if(null==e)return[e];if("number"==typeof(t=e.length)){for(n=new Array(t);t--;)n[t]=e[t];return n}return[e]}for(t=arguments.length,n=new Array(t);t--;)n[t]=arguments[t];return n}const oe="undefined"!=typeof Symbol?e=>"AsyncFunction"===e[Symbol.toStringTag]:()=>!1;var ae="undefined"!=typeof location&&/^(http|https):\/\/(localhost|127\.0\.0\.1)/.test(location.href);function ue(e,t){ae=e,ce=t}var ce=()=>!0;const le=!new Error("").stack;function he(){if(le)try{throw he.arguments,new Error}catch(e){return e}return new Error}function de(e,t){var n=e.stack;return n?(t=t||0,0===n.indexOf(e.name)&&(t+=(e.name+e.message).split("\n").length),n.split("\n").slice(t).filter(ce).map((e=>"\n"+e)).join("")):""}var fe=["Unknown","Constraint","Data","TransactionInactive","ReadOnly","Version","NotFound","InvalidState","InvalidAccess","Abort","Timeout","QuotaExceeded","Syntax","DataClone"],pe=["Modify","Bulk","OpenFailed","VersionChange","Schema","Upgrade","InvalidTable","MissingAPI","NoSuchDatabase","InvalidArgument","SubTransaction","Unsupported","Internal","DatabaseClosed","PrematureCommit","ForeignAwait"].concat(fe),ye={VersionChanged:"Database version changed by other database connection",DatabaseClosed:"Database has been closed",Abort:"Transaction aborted",TransactionInactive:"Transaction has already completed or failed",MissingAPI:"IndexedDB API missing. Please visit https://tinyurl.com/y2uuvskb"};function me(e,t){this._e=he(),this.name=e,this.message=t}function ve(e,t){return e+". Errors: "+Object.keys(t).map((e=>t[e].toString())).filter(((e,t,n)=>n.indexOf(e)===t)).join("\n")}function ge(e,t,n,r){this._e=he(),this.failures=t,this.failedKeys=r,this.successCount=n,this.message=ve(e,t)}function be(e,t){this._e=he(),this.name="BulkError",this.failures=Object.keys(t).map((e=>t[e])),this.failuresByPos=t,this.message=ve(e,t)}R(me).from(Error).extend({stack:{get:function(){return this._stack||(this._stack=this.name+": "+this.message+de(this._e,2))}},toString:function(){return this.name+": "+this.message}}),R(ge).from(me),R(be).from(me);var we=pe.reduce(((e,t)=>(e[t]=t+"Error",e)),{});const _e=me;var xe=pe.reduce(((e,t)=>{var n=t+"Error";function r(e,r){this._e=he(),this.name=n,e?"string"==typeof e?(this.message=`${e}${r?"\n "+r:""}`,this.inner=r||null):"object"==typeof e&&(this.message=`${e.name} ${e.message}`,this.inner=e):(this.message=ye[t]||n,this.inner=null)}return R(r).from(_e),e[t]=r,e}),{});xe.Syntax=SyntaxError,xe.Type=TypeError,xe.Range=RangeError;var ke=fe.reduce(((e,t)=>(e[t+"Error"]=xe[t],e)),{}),Se=pe.reduce(((e,t)=>(-1===["Syntax","Type","Range"].indexOf(t)&&(e[t+"Error"]=xe[t]),e)),{});function Ee(){}function Pe(e){return e}function Oe(e,t){return null==e||e===Pe?t:function(n){return t(e(n))}}function Ke(e,t){return function(){e.apply(this,arguments),t.apply(this,arguments)}}function je(e,t){return e===Ee?t:function(){var n=e.apply(this,arguments);void 0!==n&&(arguments[0]=n);var r=this.onsuccess,i=this.onerror;this.onsuccess=null,this.onerror=null;var s=t.apply(this,arguments);return r&&(this.onsuccess=this.onsuccess?Ke(r,this.onsuccess):r),i&&(this.onerror=this.onerror?Ke(i,this.onerror):i),void 0!==s?s:n}}function Ce(e,t){return e===Ee?t:function(){e.apply(this,arguments);var n=this.onsuccess,r=this.onerror;this.onsuccess=this.onerror=null,t.apply(this,arguments),n&&(this.onsuccess=this.onsuccess?Ke(n,this.onsuccess):n),r&&(this.onerror=this.onerror?Ke(r,this.onerror):r)}}function Ae(e,t){return e===Ee?t:function(n){var r=e.apply(this,arguments);K(n,r);var i=this.onsuccess,s=this.onerror;this.onsuccess=null,this.onerror=null;var o=t.apply(this,arguments);return i&&(this.onsuccess=this.onsuccess?Ke(i,this.onsuccess):i),s&&(this.onerror=this.onerror?Ke(s,this.onerror):s),void 0===r?void 0===o?void 0:o:K(r,o)}}function Ie(e,t){return e===Ee?t:function(){return!1!==t.apply(this,arguments)&&e.apply(this,arguments)}}function De(e,t){return e===Ee?t:function(){var n=e.apply(this,arguments);if(n&&"function"==typeof n.then){for(var r=this,i=arguments.length,s=new Array(i);i--;)s[i]=arguments[i];return n.then((function(){return t.apply(r,s)}))}return t.apply(this,arguments)}}Se.ModifyError=ge,Se.DexieError=me,Se.BulkError=be;var Te={};const[Re,Be,Fe]="undefined"==typeof Promise?[]:(()=>{let e=Promise.resolve();if("undefined"==typeof crypto||!crypto.subtle)return[e,j(e),e];const t=crypto.subtle.digest("SHA-512",new Uint8Array([0]));return[t,j(t),e]})(),Me=Be&&Be.then,Ne=Re&&Re.constructor,qe=!!Fe;var Ue=!1,$e=Fe?()=>{Fe.then(ht)}:E.setImmediate?setImmediate.bind(null,ht):E.MutationObserver?()=>{var e=document.createElement("div");new MutationObserver((()=>{ht(),e=null})).observe(e,{attributes:!0}),e.setAttribute("i","1")}:()=>{setTimeout(ht,0)},Le=function(e,t){Je.push([e,t]),ze&&($e(),ze=!1)},We=!0,ze=!0,He=[],Ve=[],Qe=null,Ye=Pe,Ge={id:"global",global:!0,ref:0,unhandleds:[],onunhandled:Bt,pgp:!1,env:{},finalize:function(){this.unhandleds.forEach((e=>{try{Bt(e[0],e[1])}catch(e){}}))}},Xe=Ge,Je=[],Ze=0,et=[];function tt(e){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");this._listeners=[],this.onuncatched=Ee,this._lib=!1;var t=this._PSD=Xe;if(ae&&(this._stackHolder=he(),this._prev=null,this._numPrev=0),"function"!=typeof e){if(e!==Te)throw new TypeError("Not a function");return this._state=arguments[1],this._value=arguments[2],void(!1===this._state&&st(this,this._value))}this._state=null,this._value=null,++t.ref,it(this,e)}const nt={get:function(){var e=Xe,t=_t;function n(n,r){var i=!e.global&&(e!==Xe||t!==_t);const s=i&&!Et();var o=new tt(((t,o)=>{at(this,new rt(Dt(n,e,i,s),Dt(r,e,i,s),t,o,e))}));return ae&<(o,this),o}return n.prototype=Te,n},set:function(e){T(this,"then",e&&e.prototype===Te?nt:{get:function(){return e},set:nt.set})}};function rt(e,t,n,r,i){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof t?t:null,this.resolve=n,this.reject=r,this.psd=i}function it(e,t){try{t((t=>{if(null===e._state){if(t===e)throw new TypeError("A promise cannot be resolved with itself.");var n=e._lib&&dt();t&&"function"==typeof t.then?it(e,((e,n)=>{t instanceof tt?t._then(e,n):t.then(e,n)})):(e._state=!0,e._value=t,ot(e)),n&&ft()}}),st.bind(null,e))}catch(t){st(e,t)}}function st(e,t){if(Ve.push(t),null===e._state){var n=e._lib&&dt();t=Ye(t),e._state=!1,e._value=t,ae&&null!==t&&"object"==typeof t&&!t._promise&&function(n,r,i){try{(()=>{var n=F(t,"stack");t._promise=e,T(t,"stack",{get:()=>Ue?n&&(n.get?n.get.apply(t):n.value):e.stack})}).apply(null,void 0)}catch(e){}}(),function(e){He.some((t=>t._value===e._value))||He.push(e)}(e),ot(e),n&&ft()}}function ot(e){var t=e._listeners;e._listeners=[];for(var n=0,r=t.length;n<r;++n)at(e,t[n]);var i=e._PSD;--i.ref||i.finalize(),0===Ze&&(++Ze,Le((()=>{0==--Ze&&pt()}),[]))}function at(e,t){if(null!==e._state){var n=e._state?t.onFulfilled:t.onRejected;if(null===n)return(e._state?t.resolve:t.reject)(e._value);++t.psd.ref,++Ze,Le(ut,[n,e,t])}else e._listeners.push(t)}function ut(e,t,n){try{Qe=t;var r,i=t._value;t._state?r=e(i):(Ve.length&&(Ve=[]),r=e(i),-1===Ve.indexOf(i)&&function(e){for(var t=He.length;t;)if(He[--t]._value===e._value)return void He.splice(t,1)}(t)),n.resolve(r)}catch(e){n.reject(e)}finally{Qe=null,0==--Ze&&pt(),--n.psd.ref||n.psd.finalize()}}function ct(e,t,n){if(t.length===n)return t;var r="";if(!1===e._state){var i,s,o=e._value;null!=o?(i=o.name||"Error",s=o.message||o,r=de(o,0)):(i=o,s=""),t.push(i+(s?": "+s:"")+r)}return ae&&((r=de(e._stackHolder,2))&&-1===t.indexOf(r)&&t.push(r),e._prev&&ct(e._prev,t,n)),t}function lt(e,t){var n=t?t._numPrev+1:0;n<100&&(e._prev=t,e._numPrev=n)}function ht(){dt()&&ft()}function dt(){var e=We;return We=!1,ze=!1,e}function ft(){var e,t,n;do{for(;Je.length>0;)for(e=Je,Je=[],n=e.length,t=0;t<n;++t){var r=e[t];r[0].apply(null,r[1])}}while(Je.length>0);We=!0,ze=!0}function pt(){var e=He;He=[],e.forEach((e=>{e._PSD.onunhandled.call(null,e._value,e)}));for(var t=et.slice(0),n=t.length;n;)t[--n]()}function yt(e){return new tt(Te,!1,e)}function mt(e,t){var n=Xe;return function(){var r=dt(),i=Xe;try{return jt(n,!0),e.apply(this,arguments)}catch(e){t&&t(e)}finally{jt(i,!1),r&&ft()}}}I(tt.prototype,{then:nt,_then:function(e,t){at(this,new rt(null,null,e,t,Xe))},catch:function(e){if(1===arguments.length)return this.then(null,e);var t=arguments[0],n=arguments[1];return"function"==typeof t?this.then(null,(e=>e instanceof t?n(e):yt(e))):this.then(null,(e=>e&&e.name===t?n(e):yt(e)))},finally:function(e){return this.then((t=>(e(),t)),(t=>(e(),yt(t))))},stack:{get:function(){if(this._stack)return this._stack;try{Ue=!0;var e=ct(this,[],20).join("\nFrom previous: ");return null!==this._state&&(this._stack=e),e}finally{Ue=!1}}},timeout:function(e,t){return e<1/0?new tt(((n,r)=>{var i=setTimeout((()=>r(new xe.Timeout(t))),e);this.then(n,r).finally(clearTimeout.bind(null,i))})):this}}),"undefined"!=typeof Symbol&&Symbol.toStringTag&&T(tt.prototype,Symbol.toStringTag,"Dexie.Promise"),Ge.env=Ct(),I(tt,{all:function(){var e=se.apply(null,arguments).map(Pt);return new tt((function(t,n){0===e.length&&t([]);var r=e.length;e.forEach(((i,s)=>tt.resolve(i).then((n=>{e[s]=n,--r||t(e)}),n)))}))},resolve:e=>{if(e instanceof tt)return e;if(e&&"function"==typeof e.then)return new tt(((t,n)=>{e.then(t,n)}));var t=new tt(Te,!0,e);return lt(t,Qe),t},reject:yt,race:function(){var e=se.apply(null,arguments).map(Pt);return new tt(((t,n)=>{e.map((e=>tt.resolve(e).then(t,n)))}))},PSD:{get:()=>Xe,set:e=>Xe=e},totalEchoes:{get:()=>_t},newPSD:kt,usePSD:At,scheduler:{get:()=>Le,set:e=>{Le=e}},rejectionMapper:{get:()=>Ye,set:e=>{Ye=e}},follow:(e,t)=>new tt(((n,r)=>kt(((t,n)=>{var r=Xe;r.unhandleds=[],r.onunhandled=n,r.finalize=Ke((function(){!function(e){et.push((function t(){e(),et.splice(et.indexOf(t),1)})),++Ze,Le((()=>{0==--Ze&&pt()}),[])}((()=>{0===this.unhandleds.length?t():n(this.unhandleds[0])}))}),r.finalize),e()}),t,n,r)))}),Ne&&(Ne.allSettled&&T(tt,"allSettled",(function(){const e=se.apply(null,arguments).map(Pt);return new tt((t=>{0===e.length&&t([]);let n=e.length;const r=new Array(n);e.forEach(((e,i)=>tt.resolve(e).then((e=>r[i]={status:"fulfilled",value:e}),(e=>r[i]={status:"rejected",reason:e})).then((()=>--n||t(r)))))}))})),Ne.any&&"undefined"!=typeof AggregateError&&T(tt,"any",(function(){const e=se.apply(null,arguments).map(Pt);return new tt(((t,n)=>{0===e.length&&n(new AggregateError([]));let r=e.length;const i=new Array(r);e.forEach(((e,s)=>tt.resolve(e).then((e=>t(e)),(e=>{i[s]=e,--r||n(new AggregateError(i))}))))}))})));const vt={awaits:0,echoes:0,id:0};var gt=0,bt=[],wt=0,_t=0,xt=0;function kt(e,t,n,r){var i=Xe,s=Object.create(i);s.parent=i,s.ref=0,s.global=!1,s.id=++xt;var o=Ge.env;s.env=qe?{Promise:tt,PromiseProp:{value:tt,configurable:!0,writable:!0},all:tt.all,race:tt.race,allSettled:tt.allSettled,any:tt.any,resolve:tt.resolve,reject:tt.reject,nthen:Tt(o.nthen,s),gthen:Tt(o.gthen,s)}:{},t&&K(s,t),++i.ref,s.finalize=function(){--this.parent.ref||this.parent.finalize()};var a=At(s,e,n,r);return 0===s.ref&&s.finalize(),a}function St(){return vt.id||(vt.id=++gt),++vt.awaits,vt.echoes+=100,vt.id}function Et(){return!!vt.awaits&&(0==--vt.awaits&&(vt.id=0),vt.echoes=100*vt.awaits,!0)}function Pt(e){return vt.echoes&&e&&e.constructor===Ne?(St(),e.then((e=>(Et(),e)),(e=>(Et(),Ft(e))))):e}function Ot(e){++_t,vt.echoes&&0!=--vt.echoes||(vt.echoes=vt.id=0),bt.push(Xe),jt(e,!0)}function Kt(){var e=bt[bt.length-1];bt.pop(),jt(e,!1)}function jt(e,t){var n=Xe;if((t?!vt.echoes||wt++&&e===Xe:!wt||--wt&&e===Xe)||It(t?Ot.bind(null,e):Kt),e!==Xe&&(Xe=e,n===Ge&&(Ge.env=Ct()),qe)){var r=Ge.env.Promise,i=e.env;Be.then=i.nthen,r.prototype.then=i.gthen,(n.global||e.global)&&(Object.defineProperty(E,"Promise",i.PromiseProp),r.all=i.all,r.race=i.race,r.resolve=i.resolve,r.reject=i.reject,i.allSettled&&(r.allSettled=i.allSettled),i.any&&(r.any=i.any))}}function Ct(){var e=E.Promise;return qe?{Promise:e,PromiseProp:Object.getOwnPropertyDescriptor(E,"Promise"),all:e.all,race:e.race,allSettled:e.allSettled,any:e.any,resolve:e.resolve,reject:e.reject,nthen:Be.then,gthen:e.prototype.then}:{}}function At(e,t,n,r,i){var s=Xe;try{return jt(e,!0),t(n,r,i)}finally{jt(s,!1)}}function It(e){Me.call(Re,e)}function Dt(e,t,n,r){return"function"!=typeof e?e:function(){var i=Xe;n&&St(),jt(t,!0);try{return e.apply(this,arguments)}finally{jt(i,!1),r&&It(Et)}}}function Tt(e,t){return function(n,r){return e.call(this,Dt(n,t),Dt(r,t))}}-1===(""+Me).indexOf("[native code]")&&(St=Et=Ee);const Rt="unhandledrejection";function Bt(e,t){var n;try{n=t.onuncatched(e)}catch(e){}if(!1!==n)try{var r,i={promise:t,reason:e};if(E.document&&document.createEvent?((r=document.createEvent("Event")).initEvent(Rt,!0,!0),K(r,i)):E.CustomEvent&&K(r=new CustomEvent(Rt,{detail:i}),i),r&&E.dispatchEvent&&(dispatchEvent(r),!E.PromiseRejectionEvent&&E.onunhandledrejection))try{E.onunhandledrejection(r)}catch(e){}ae&&r&&!r.defaultPrevented&&console.warn(`Unhandled rejection: ${e.stack||e}`)}catch(e){}}var Ft=tt.reject;function Mt(e,t,n,r){if(e.idbdb&&(e._state.openComplete||Xe.letThrough||e._vip)){var i=e._createTransaction(t,n,e._dbSchema);try{i.create()}catch(e){return Ft(e)}return i._promise(t,((e,t)=>kt((()=>(Xe.trans=i,r(e,t,i)))))).then((e=>i._completion.then((()=>e))))}if(e._state.openComplete)return Ft(new xe.DatabaseClosed(e._state.dbOpenError));if(!e._state.isBeingOpened){if(!e._options.autoOpen)return Ft(new xe.DatabaseClosed);e.open().catch(Ee)}return e._state.dbReadyPromise.then((()=>Mt(e,t,n,r)))}const Nt="3.2.0",qt=String.fromCharCode(65535),Ut=-1/0,$t="Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.",Lt="String expected.",Wt=[],zt="undefined"!=typeof navigator&&/(MSIE|Trident|Edge)/.test(navigator.userAgent),Ht=zt,Vt=zt,Qt=e=>!/(dexie\.js|dexie\.min\.js)/.test(e),Yt="__dbnames",Gt="readonly",Xt="readwrite";function Jt(e,t){return e?t?function(){return e.apply(this,arguments)&&t.apply(this,arguments)}:e:t}const Zt={type:3,lower:-1/0,lowerOpen:!1,upper:[[]],upperOpen:!1};function en(e){return"string"!=typeof e||/\./.test(e)?e=>e:t=>(void 0===t[e]&&e in t&&delete(t=J(t))[e],t)}class tn{_trans(e,t,n){const r=this._tx||Xe.trans,i=this.name;function s(e,n,r){if(!r.schema[i])throw new xe.NotFound("Table "+i+" not part of transaction");return t(r.idbtrans,r)}const o=dt();try{return r&&r.db===this.db?r===Xe.trans?r._promise(e,s,n):kt((()=>r._promise(e,s,n)),{trans:r,transless:Xe.transless||Xe}):Mt(this.db,e,[this.name],s)}finally{o&&ft()}}get(e,t){return e&&e.constructor===Object?this.where(e).first(t):this._trans("readonly",(t=>this.core.get({trans:t,key:e}).then((e=>this.hook.reading.fire(e))))).then(t)}where(e){if("string"==typeof e)return new this.db.WhereClause(this,e);if(O(e))return new this.db.WhereClause(this,`[${e.join("+")}]`);const t=P(e);if(1===t.length)return this.where(t[0]).equals(e[t[0]]);const n=this.schema.indexes.concat(this.schema.primKey).filter((e=>e.compound&&t.every((t=>e.keyPath.indexOf(t)>=0))&&e.keyPath.every((e=>t.indexOf(e)>=0))))[0];if(n&&this.db._maxKey!==qt)return this.where(n.name).equals(n.keyPath.map((t=>e[t])));!n&&ae&&console.warn(`The query ${JSON.stringify(e)} on ${this.name} would benefit of a compound index [${t.join("+")}]`);const{idxByName:r}=this.schema,i=this.db._deps.indexedDB;function s(e,t){try{return 0===i.cmp(e,t)}catch(e){return!1}}const[o,a]=t.reduce((([t,n],i)=>{const o=r[i],a=e[i];return[t||o,t||!o?Jt(n,o&&o.multi?e=>{const t=W(e,i);return O(t)&&t.some((e=>s(a,e)))}:e=>s(a,W(e,i))):n]}),[null,null]);return o?this.where(o.name).equals(e[o.keyPath]).filter(a):n?this.filter(a):this.where(t).equals("")}filter(e){return this.toCollection().and(e)}count(e){return this.toCollection().count(e)}offset(e){return this.toCollection().offset(e)}limit(e){return this.toCollection().limit(e)}each(e){return this.toCollection().each(e)}toArray(e){return this.toCollection().toArray(e)}toCollection(){return new this.db.Collection(new this.db.WhereClause(this))}orderBy(e){return new this.db.Collection(new this.db.WhereClause(this,O(e)?`[${e.join("+")}]`:e))}reverse(){return this.toCollection().reverse()}mapToClass(e){this.schema.mappedClass=e;const t=t=>{if(!t)return t;const n=Object.create(e.prototype);for(var r in t)if(A(t,r))try{n[r]=t[r]}catch(e){}return n};return this.schema.readHook&&this.hook.reading.unsubscribe(this.schema.readHook),this.schema.readHook=t,this.hook("reading",t),e}defineClass(){return this.mapToClass((function(e){K(this,e)}))}add(e,t){const{auto:n,keyPath:r}=this.schema.primKey;let i=e;return r&&n&&(i=en(r)(e)),this._trans("readwrite",(e=>this.core.mutate({trans:e,type:"add",keys:null!=t?[t]:null,values:[i]}))).then((e=>e.numFailures?tt.reject(e.failures[0]):e.lastResult)).then((t=>{if(r)try{z(e,r,t)}catch(e){}return t}))}update(e,t){if("object"!=typeof e||O(e))return this.where(":id").equals(e).modify(t);{const n=W(e,this.schema.primKey.keyPath);if(void 0===n)return Ft(new xe.InvalidArgument("Given object does not contain its primary key"));try{"function"!=typeof t?P(t).forEach((n=>{z(e,n,t[n])})):t(e,{value:e,primKey:n})}catch(e){}return this.where(":id").equals(n).modify(t)}}put(e,t){const{auto:n,keyPath:r}=this.schema.primKey;let i=e;return r&&n&&(i=en(r)(e)),this._trans("readwrite",(e=>this.core.mutate({trans:e,type:"put",values:[i],keys:null!=t?[t]:null}))).then((e=>e.numFailures?tt.reject(e.failures[0]):e.lastResult)).then((t=>{if(r)try{z(e,r,t)}catch(e){}return t}))}delete(e){return this._trans("readwrite",(t=>this.core.mutate({trans:t,type:"delete",keys:[e]}))).then((e=>e.numFailures?tt.reject(e.failures[0]):void 0))}clear(){return this._trans("readwrite",(e=>this.core.mutate({trans:e,type:"deleteRange",range:Zt}))).then((e=>e.numFailures?tt.reject(e.failures[0]):void 0))}bulkGet(e){return this._trans("readonly",(t=>this.core.getMany({keys:e,trans:t}).then((e=>e.map((e=>this.hook.reading.fire(e)))))))}bulkAdd(e,t,n){const r=Array.isArray(t)?t:void 0,i=(n=n||(r?void 0:t))?n.allKeys:void 0;return this._trans("readwrite",(t=>{const{auto:n,keyPath:s}=this.schema.primKey;if(s&&r)throw new xe.InvalidArgument("bulkAdd(): keys argument invalid on tables with inbound keys");if(r&&r.length!==e.length)throw new xe.InvalidArgument("Arguments objects and keys must have the same length");const o=e.length;let a=s&&n?e.map(en(s)):e;return this.core.mutate({trans:t,type:"add",keys:r,values:a,wantResults:i}).then((({numFailures:e,results:t,lastResult:n,failures:r})=>{if(0===e)return i?t:n;throw new be(`${this.name}.bulkAdd(): ${e} of ${o} operations failed`,r)}))}))}bulkPut(e,t,n){const r=Array.isArray(t)?t:void 0,i=(n=n||(r?void 0:t))?n.allKeys:void 0;return this._trans("readwrite",(t=>{const{auto:n,keyPath:s}=this.schema.primKey;if(s&&r)throw new xe.InvalidArgument("bulkPut(): keys argument invalid on tables with inbound keys");if(r&&r.length!==e.length)throw new xe.InvalidArgument("Arguments objects and keys must have the same length");const o=e.length;let a=s&&n?e.map(en(s)):e;return this.core.mutate({trans:t,type:"put",keys:r,values:a,wantResults:i}).then((({numFailures:e,results:t,lastResult:n,failures:r})=>{if(0===e)return i?t:n;throw new be(`${this.name}.bulkPut(): ${e} of ${o} operations failed`,r)}))}))}bulkDelete(e){const t=e.length;return this._trans("readwrite",(t=>this.core.mutate({trans:t,type:"delete",keys:e}))).then((({numFailures:e,lastResult:n,failures:r})=>{if(0===e)return n;throw new be(`${this.name}.bulkDelete(): ${e} of ${t} operations failed`,r)}))}}function nn(e){var t={},n=function(n,r){if(r){for(var i=arguments.length,s=new Array(i-1);--i;)s[i-1]=arguments[i];return t[n].subscribe.apply(null,s),e}if("string"==typeof n)return t[n]};n.addEventType=s;for(var r=1,i=arguments.length;r<i;++r)s(arguments[r]);return n;function s(e,r,i){if("object"==typeof e)return o(e);r||(r=Ie),i||(i=Ee);var s={subscribers:[],fire:i,subscribe:function(e){-1===s.subscribers.indexOf(e)&&(s.subscribers.push(e),s.fire=r(s.fire,e))},unsubscribe:function(e){s.subscribers=s.subscribers.filter((function(t){return t!==e})),s.fire=s.subscribers.reduce(r,i)}};return t[e]=n[e]=s,s}function o(e){P(e).forEach((function(t){var n=e[t];if(O(n))s(t,e[t][0],e[t][1]);else{if("asap"!==n)throw new xe.InvalidArgument("Invalid event config");var r=s(t,Pe,(function(){for(var e=arguments.length,t=new Array(e);e--;)t[e]=arguments[e];r.subscribers.forEach((function(e){$((function(){e.apply(null,t)}))}))}))}}))}}function rn(e,t){return R(t).from({prototype:e}),t}function sn(e,t){return!(e.filter||e.algorithm||e.or)&&(t?e.justLimit:!e.replayFilter)}function on(e,t){e.filter=Jt(e.filter,t)}function an(e,t,n){var r=e.replayFilter;e.replayFilter=r?()=>Jt(r(),t()):t,e.justLimit=n&&!r}function un(e,t){if(e.isPrimKey)return t.primaryKey;const n=t.getIndexByKeyPath(e.index);if(!n)throw new xe.Schema("KeyPath "+e.index+" on object store "+t.name+" is not indexed");return n}function cn(e,t,n){const r=un(e,t.schema);return t.openCursor({trans:n,values:!e.keysOnly,reverse:"prev"===e.dir,unique:!!e.unique,query:{index:r,range:e.range}})}function ln(e,t,n,r){const i=e.replayFilter?Jt(e.filter,e.replayFilter()):e.filter;if(e.or){const s={},o=(e,n,r)=>{if(!i||i(n,r,(e=>n.stop(e)),(e=>n.fail(e)))){var o=n.primaryKey,a=""+o;"[object ArrayBuffer]"===a&&(a=""+new Uint8Array(o)),A(s,a)||(s[a]=!0,t(e,n,r))}};return Promise.all([e.or._iterate(o,n),hn(cn(e,r,n),e.algorithm,o,!e.keysOnly&&e.valueMapper)])}return hn(cn(e,r,n),Jt(e.algorithm,i),t,!e.keysOnly&&e.valueMapper)}function hn(e,t,n,r){var i=r?(e,t,i)=>n(r(e),t,i):n,s=mt(i);return e.then((e=>{if(e)return e.start((()=>{var n=()=>e.continue();t&&!t(e,(e=>n=e),(t=>{e.stop(t),n=Ee}),(t=>{e.fail(t),n=Ee}))||s(e.value,e,(e=>n=e)),n()}))}))}function dn(e,t){try{const n=fn(e),r=fn(t);if(n!==r)return"Array"===n?1:"Array"===r?-1:"binary"===n?1:"binary"===r?-1:"string"===n?1:"string"===r?-1:"Date"===n?1:"Date"!==r?NaN:-1;switch(n){case"number":case"Date":case"string":return e>t?1:e<t?-1:0;case"binary":return function(e,t){const n=e.length,r=t.length,i=n<r?n:r;for(let n=0;n<i;++n)if(e[n]!==t[n])return e[n]<t[n]?-1:1;return n===r?0:n<r?-1:1}(pn(e),pn(t));case"Array":return function(e,t){const n=e.length,r=t.length,i=n<r?n:r;for(let n=0;n<i;++n){const r=dn(e[n],t[n]);if(0!==r)return r}return n===r?0:n<r?-1:1}(e,t)}}catch(e){}return NaN}function fn(e){const t=typeof e;if("object"!==t)return t;if(ArrayBuffer.isView(e))return"binary";const n=te(e);return"ArrayBuffer"===n?"binary":n}function pn(e){return e instanceof Uint8Array?e:ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e)}class yn{_read(e,t){var n=this._ctx;return n.error?n.table._trans(null,Ft.bind(null,n.error)):n.table._trans("readonly",e).then(t)}_write(e){var t=this._ctx;return t.error?t.table._trans(null,Ft.bind(null,t.error)):t.table._trans("readwrite",e,"locked")}_addAlgorithm(e){var t=this._ctx;t.algorithm=Jt(t.algorithm,e)}_iterate(e,t){return ln(this._ctx,e,t,this._ctx.table.core)}clone(e){var t=Object.create(this.constructor.prototype),n=Object.create(this._ctx);return e&&K(n,e),t._ctx=n,t}raw(){return this._ctx.valueMapper=null,this}each(e){var t=this._ctx;return this._read((n=>ln(t,e,n,t.table.core)))}count(e){return this._read((e=>{const t=this._ctx,n=t.table.core;if(sn(t,!0))return n.count({trans:e,query:{index:un(t,n.schema),range:t.range}}).then((e=>Math.min(e,t.limit)));var r=0;return ln(t,(()=>(++r,!1)),e,n).then((()=>r))})).then(e)}sortBy(e,t){const n=e.split(".").reverse(),r=n[0],i=n.length-1;function s(e,t){return t?s(e[n[t]],t-1):e[r]}var o="next"===this._ctx.dir?1:-1;function a(e,t){var n=s(e,i),r=s(t,i);return n<r?-o:n>r?o:0}return this.toArray((function(e){return e.sort(a)})).then(t)}toArray(e){return this._read((e=>{var t=this._ctx;if("next"===t.dir&&sn(t,!0)&&t.limit>0){const{valueMapper:n}=t,r=un(t,t.table.core.schema);return t.table.core.query({trans:e,limit:t.limit,values:!0,query:{index:r,range:t.range}}).then((({result:e})=>n?e.map(n):e))}{const n=[];return ln(t,(e=>n.push(e)),e,t.table.core).then((()=>n))}}),e)}offset(e){var t=this._ctx;return e<=0||(t.offset+=e,sn(t)?an(t,(()=>{var t=e;return(e,n)=>0===t||(1===t?(--t,!1):(n((()=>{e.advance(t),t=0})),!1))})):an(t,(()=>{var t=e;return()=>--t<0}))),this}limit(e){return this._ctx.limit=Math.min(this._ctx.limit,e),an(this._ctx,(()=>{var t=e;return function(e,n,r){return--t<=0&&n(r),t>=0}}),!0),this}until(e,t){return on(this._ctx,(function(n,r,i){return!e(n.value)||(r(i),t)})),this}first(e){return this.limit(1).toArray((function(e){return e[0]})).then(e)}last(e){return this.reverse().first(e)}filter(e){var t,n;return on(this._ctx,(function(t){return e(t.value)})),t=this._ctx,n=e,t.isMatch=Jt(t.isMatch,n),this}and(e){return this.filter(e)}or(e){return new this.db.WhereClause(this._ctx.table,e,this)}reverse(){return this._ctx.dir="prev"===this._ctx.dir?"next":"prev",this._ondirectionchange&&this._ondirectionchange(this._ctx.dir),this}desc(){return this.reverse()}eachKey(e){var t=this._ctx;return t.keysOnly=!t.isMatch,this.each((function(t,n){e(n.key,n)}))}eachUniqueKey(e){return this._ctx.unique="unique",this.eachKey(e)}eachPrimaryKey(e){var t=this._ctx;return t.keysOnly=!t.isMatch,this.each((function(t,n){e(n.primaryKey,n)}))}keys(e){var t=this._ctx;t.keysOnly=!t.isMatch;var n=[];return this.each((function(e,t){n.push(t.key)})).then((function(){return n})).then(e)}primaryKeys(e){var t=this._ctx;if("next"===t.dir&&sn(t,!0)&&t.limit>0)return this._read((e=>{var n=un(t,t.table.core.schema);return t.table.core.query({trans:e,values:!1,limit:t.limit,query:{index:n,range:t.range}})})).then((({result:e})=>e)).then(e);t.keysOnly=!t.isMatch;var n=[];return this.each((function(e,t){n.push(t.primaryKey)})).then((function(){return n})).then(e)}uniqueKeys(e){return this._ctx.unique="unique",this.keys(e)}firstKey(e){return this.limit(1).keys((function(e){return e[0]})).then(e)}lastKey(e){return this.reverse().firstKey(e)}distinct(){var e=this._ctx,t=e.index&&e.table.schema.idxByName[e.index];if(!t||!t.multi)return this;var n={};return on(this._ctx,(function(e){var t=e.primaryKey.toString(),r=A(n,t);return n[t]=!0,!r})),this}modify(e){var t=this._ctx;return this._write((n=>{var r;if("function"==typeof e)r=e;else{var i=P(e),s=i.length;r=function(t){for(var n=!1,r=0;r<s;++r){var o=i[r],a=e[o];W(t,o)!==a&&(z(t,o,a),n=!0)}return n}}const o=t.table.core,{outbound:a,extractKey:u}=o.schema.primaryKey,c=this.db._options.modifyChunkSize||200,l=[];let h=0;const d=[],f=(e,t)=>{const{failures:n,numFailures:r}=t;h+=e-r;for(let e of P(n))l.push(n[e])};return this.clone().primaryKeys().then((i=>{const s=l=>{const h=Math.min(c,i.length-l);return o.getMany({trans:n,keys:i.slice(l,l+h),cache:"immutable"}).then((d=>{const p=[],y=[],m=a?[]:null,v=[];for(let e=0;e<h;++e){const t=d[e],n={value:J(t),primKey:i[l+e]};!1!==r.call(n,n.value,n)&&(null==n.value?v.push(i[l+e]):a||0===dn(u(t),u(n.value))?(y.push(n.value),a&&m.push(i[l+e])):(v.push(i[l+e]),p.push(n.value)))}const g=sn(t)&&t.limit===1/0&&("function"!=typeof e||e===mn)&&{index:t.index,range:t.range};return Promise.resolve(p.length>0&&o.mutate({trans:n,type:"add",values:p}).then((e=>{for(let t in e.failures)v.splice(parseInt(t),1);f(p.length,e)}))).then((()=>(y.length>0||g&&"object"==typeof e)&&o.mutate({trans:n,type:"put",keys:m,values:y,criteria:g,changeSpec:"function"!=typeof e&&e}).then((e=>f(y.length,e))))).then((()=>(v.length>0||g&&e===mn)&&o.mutate({trans:n,type:"delete",keys:v,criteria:g}).then((e=>f(v.length,e))))).then((()=>i.length>l+h&&s(l+c)))}))};return s(0).then((()=>{if(l.length>0)throw new ge("Error modifying one or more objects",l,h,d);return i.length}))}))}))}delete(){var e=this._ctx,t=e.range;return sn(e)&&(e.isPrimKey&&!Vt||3===t.type)?this._write((n=>{const{primaryKey:r}=e.table.core.schema,i=t;return e.table.core.count({trans:n,query:{index:r,range:i}}).then((t=>e.table.core.mutate({trans:n,type:"deleteRange",range:i}).then((({failures:e,lastResult:n,results:r,numFailures:i})=>{if(i)throw new ge("Could not delete some values",Object.keys(e).map((t=>e[t])),t-i);return t-i}))))})):this.modify(mn)}}const mn=(e,t)=>t.value=null;function vn(e,t){return e<t?-1:e===t?0:1}function gn(e,t){return e>t?-1:e===t?0:1}function bn(e,t,n){var r=e instanceof En?new e.Collection(e):e;return r._ctx.error=n?new n(t):new TypeError(t),r}function wn(e){return new e.Collection(e,(()=>Sn(""))).limit(0)}function _n(e,t,n,r,i,s){for(var o=Math.min(e.length,r.length),a=-1,u=0;u<o;++u){var c=t[u];if(c!==r[u])return i(e[u],n[u])<0?e.substr(0,u)+n[u]+n.substr(u+1):i(e[u],r[u])<0?e.substr(0,u)+r[u]+n.substr(u+1):a>=0?e.substr(0,a)+t[a]+n.substr(a+1):null;i(e[u],c)<0&&(a=u)}return o<r.length&&"next"===s?e+n.substr(e.length):o<e.length&&"prev"===s?e.substr(0,n.length):a<0?null:e.substr(0,a)+r[a]+n.substr(a+1)}function xn(e,t,n,r){var i,s,o,a,u,c,l,h=n.length;if(!n.every((e=>"string"==typeof e)))return bn(e,Lt);function d(e){i=function(e){return"next"===e?e=>e.toUpperCase():e=>e.toLowerCase()}(e),s=function(e){return"next"===e?e=>e.toLowerCase():e=>e.toUpperCase()}(e),o="next"===e?vn:gn;var t=n.map((function(e){return{lower:s(e),upper:i(e)}})).sort((function(e,t){return o(e.lower,t.lower)}));a=t.map((function(e){return e.upper})),u=t.map((function(e){return e.lower})),c=e,l="next"===e?"":r}d("next");var f=new e.Collection(e,(()=>kn(a[0],u[h-1]+r)));f._ondirectionchange=function(e){d(e)};var p=0;return f._addAlgorithm((function(e,n,r){var i=e.key;if("string"!=typeof i)return!1;var d=s(i);if(t(d,u,p))return!0;for(var f=null,y=p;y<h;++y){var m=_n(i,d,a[y],u[y],o,c);null===m&&null===f?p=y+1:(null===f||o(f,m)>0)&&(f=m)}return n(null!==f?function(){e.continue(f+l)}:r),!1})),f}function kn(e,t,n,r){return{type:2,lower:e,upper:t,lowerOpen:n,upperOpen:r}}function Sn(e){return{type:1,lower:e,upper:e}}class En{get Collection(){return this._ctx.table.db.Collection}between(e,t,n,r){n=!1!==n,r=!0===r;try{return this._cmp(e,t)>0||0===this._cmp(e,t)&&(n||r)&&(!n||!r)?wn(this):new this.Collection(this,(()=>kn(e,t,!n,!r)))}catch(e){return bn(this,$t)}}equals(e){return null==e?bn(this,$t):new this.Collection(this,(()=>Sn(e)))}above(e){return null==e?bn(this,$t):new this.Collection(this,(()=>kn(e,void 0,!0)))}aboveOrEqual(e){return null==e?bn(this,$t):new this.Collection(this,(()=>kn(e,void 0,!1)))}below(e){return null==e?bn(this,$t):new this.Collection(this,(()=>kn(void 0,e,!1,!0)))}belowOrEqual(e){return null==e?bn(this,$t):new this.Collection(this,(()=>kn(void 0,e)))}startsWith(e){return"string"!=typeof e?bn(this,Lt):this.between(e,e+qt,!0,!0)}startsWithIgnoreCase(e){return""===e?this.startsWith(e):xn(this,((e,t)=>0===e.indexOf(t[0])),[e],qt)}equalsIgnoreCase(e){return xn(this,((e,t)=>e===t[0]),[e],"")}anyOfIgnoreCase(){var e=se.apply(ie,arguments);return 0===e.length?wn(this):xn(this,((e,t)=>-1!==t.indexOf(e)),e,"")}startsWithAnyOfIgnoreCase(){var e=se.apply(ie,arguments);return 0===e.length?wn(this):xn(this,((e,t)=>t.some((t=>0===e.indexOf(t)))),e,qt)}anyOf(){const e=se.apply(ie,arguments);let t=this._cmp;try{e.sort(t)}catch(e){return bn(this,$t)}if(0===e.length)return wn(this);const n=new this.Collection(this,(()=>kn(e[0],e[e.length-1])));n._ondirectionchange=n=>{t="next"===n?this._ascending:this._descending,e.sort(t)};let r=0;return n._addAlgorithm(((n,i,s)=>{const o=n.key;for(;t(o,e[r])>0;)if(++r,r===e.length)return i(s),!1;return 0===t(o,e[r])||(i((()=>{n.continue(e[r])})),!1)})),n}notEqual(e){return this.inAnyRange([[Ut,e],[e,this.db._maxKey]],{includeLowers:!1,includeUppers:!1})}noneOf(){const e=se.apply(ie,arguments);if(0===e.length)return new this.Collection(this);try{e.sort(this._ascending)}catch(e){return bn(this,$t)}const t=e.reduce(((e,t)=>e?e.concat([[e[e.length-1][1],t]]):[[Ut,t]]),null);return t.push([e[e.length-1],this.db._maxKey]),this.inAnyRange(t,{includeLowers:!1,includeUppers:!1})}inAnyRange(e,t){const n=this._cmp,r=this._ascending,i=this._descending,s=this._min,o=this._max;if(0===e.length)return wn(this);if(!e.every((e=>void 0!==e[0]&&void 0!==e[1]&&r(e[0],e[1])<=0)))return bn(this,"First argument to inAnyRange() must be an Array of two-value Arrays [lower,upper] where upper must not be lower than lower",xe.InvalidArgument);const a=!t||!1!==t.includeLowers,u=t&&!0===t.includeUppers;let c,l=r;function h(e,t){return l(e[0],t[0])}try{c=e.reduce((function(e,t){let r=0,i=e.length;for(;r<i;++r){const i=e[r];if(n(t[0],i[1])<0&&n(t[1],i[0])>0){i[0]=s(i[0],t[0]),i[1]=o(i[1],t[1]);break}}return r===i&&e.push(t),e}),[]),c.sort(h)}catch(e){return bn(this,$t)}let d=0;const f=u?e=>r(e,c[d][1])>0:e=>r(e,c[d][1])>=0,p=a?e=>i(e,c[d][0])>0:e=>i(e,c[d][0])>=0;let y=f;const m=new this.Collection(this,(()=>kn(c[0][0],c[c.length-1][1],!a,!u)));return m._ondirectionchange=e=>{"next"===e?(y=f,l=r):(y=p,l=i),c.sort(h)},m._addAlgorithm(((e,t,n)=>{for(var i=e.key;y(i);)if(++d,d===c.length)return t(n),!1;return!!function(e){return!f(e)&&!p(e)}(i)||(0===this._cmp(i,c[d][1])||0===this._cmp(i,c[d][0])||t((()=>{l===r?e.continue(c[d][0]):e.continue(c[d][1])})),!1)})),m}startsWithAnyOf(){const e=se.apply(ie,arguments);return e.every((e=>"string"==typeof e))?0===e.length?wn(this):this.inAnyRange(e.map((e=>[e,e+qt]))):bn(this,"startsWithAnyOf() only works with strings")}}function Pn(e){return mt((function(t){return On(t),e(t.target.error),!1}))}function On(e){e.stopPropagation&&e.stopPropagation(),e.preventDefault&&e.preventDefault()}const Kn="storagemutated",jn="x-storagemutated-1",Cn=nn(null,Kn);class An{_lock(){return U(!Xe.global),++this._reculock,1!==this._reculock||Xe.global||(Xe.lockOwnerFor=this),this}_unlock(){if(U(!Xe.global),0==--this._reculock)for(Xe.global||(Xe.lockOwnerFor=null);this._blockedFuncs.length>0&&!this._locked();){var e=this._blockedFuncs.shift();try{At(e[1],e[0])}catch(e){}}return this}_locked(){return this._reculock&&Xe.lockOwnerFor!==this}create(e){if(!this.mode)return this;const t=this.db.idbdb,n=this.db._state.dbOpenError;if(U(!this.idbtrans),!e&&!t)switch(n&&n.name){case"DatabaseClosedError":throw new xe.DatabaseClosed(n);case"MissingAPIError":throw new xe.MissingAPI(n.message,n);default:throw new xe.OpenFailed(n)}if(!this.active)throw new xe.TransactionInactive;return U(null===this._completion._state),(e=this.idbtrans=e||(this.db.core?this.db.core.transaction(this.storeNames,this.mode,{durability:this.chromeTransactionDurability}):t.transaction(this.storeNames,this.mode,{durability:this.chromeTransactionDurability}))).onerror=mt((t=>{On(t),this._reject(e.error)})),e.onabort=mt((t=>{On(t),this.active&&this._reject(new xe.Abort(e.error)),this.active=!1,this.on("abort").fire(t)})),e.oncomplete=mt((()=>{this.active=!1,this._resolve(),"mutatedParts"in e&&Cn.storagemutated.fire(e.mutatedParts)})),this}_promise(e,t,n){if("readwrite"===e&&"readwrite"!==this.mode)return Ft(new xe.ReadOnly("Transaction is readonly"));if(!this.active)return Ft(new xe.TransactionInactive);if(this._locked())return new tt(((r,i)=>{this._blockedFuncs.push([()=>{this._promise(e,t,n).then(r,i)},Xe])}));if(n)return kt((()=>{var e=new tt(((e,n)=>{this._lock();const r=t(e,n,this);r&&r.then&&r.then(e,n)}));return e.finally((()=>this._unlock())),e._lib=!0,e}));var r=new tt(((e,n)=>{var r=t(e,n,this);r&&r.then&&r.then(e,n)}));return r._lib=!0,r}_root(){return this.parent?this.parent._root():this}waitFor(e){var t=this._root();const n=tt.resolve(e);if(t._waitingFor)t._waitingFor=t._waitingFor.then((()=>n));else{t._waitingFor=n,t._waitingQueue=[];var r=t.idbtrans.objectStore(t.storeNames[0]);!function e(){for(++t._spinCount;t._waitingQueue.length;)t._waitingQueue.shift()();t._waitingFor&&(r.get(-1/0).onsuccess=e)}()}var i=t._waitingFor;return new tt(((e,r)=>{n.then((n=>t._waitingQueue.push(mt(e.bind(null,n)))),(e=>t._waitingQueue.push(mt(r.bind(null,e))))).finally((()=>{t._waitingFor===i&&(t._waitingFor=null)}))}))}abort(){this.active&&(this.active=!1,this.idbtrans&&this.idbtrans.abort(),this._reject(new xe.Abort))}table(e){const t=this._memoizedTables||(this._memoizedTables={});if(A(t,e))return t[e];const n=this.schema[e];if(!n)throw new xe.NotFound("Table "+e+" not part of transaction");const r=new this.db.Table(e,n,this);return r.core=this.db.core.table(e),t[e]=r,r}}function In(e,t,n,r,i,s,o){return{name:e,keyPath:t,unique:n,multi:r,auto:i,compound:s,src:(n&&!o?"&":"")+(r?"*":"")+(i?"++":"")+Dn(t)}}function Dn(e){return"string"==typeof e?e:e?"["+[].join.call(e,"+")+"]":""}function Tn(e,t,n){return{name:e,primKey:t,indexes:n,mappedClass:null,idxByName:L(n,(e=>[e.name,e]))}}let Rn=e=>{try{return e.only([[]]),Rn=()=>[[]],[[]]}catch(e){return Rn=()=>qt,qt}};function Bn(e){return null==e?()=>{}:"string"==typeof e?function(e){return 1===e.split(".").length?t=>t[e]:t=>W(t,e)}(e):t=>W(t,e)}function Fn(e){return[].slice.call(e)}let Mn=0;function Nn(e){return null==e?":id":"string"==typeof e?e:`[${e.join("+")}]`}function qn({_novip:e},t){const n=t.db,r=function(e,t,{IDBKeyRange:n,indexedDB:r},i){const s=function(e,t){return t.reduce(((e,{create:t})=>({...e,...t(e)})),e)}(function(e,t,n){function r(e){if(3===e.type)return null;if(4===e.type)throw new Error("Cannot convert never type to IDBKeyRange");const{lower:n,upper:r,lowerOpen:i,upperOpen:s}=e;return void 0===n?void 0===r?null:t.upperBound(r,!!s):void 0===r?t.lowerBound(n,!!i):t.bound(n,r,!!i,!!s)}const{schema:i,hasGetAll:s}=function(e,t){const n=Fn(e.objectStoreNames);return{schema:{name:e.name,tables:n.map((e=>t.objectStore(e))).map((e=>{const{keyPath:t,autoIncrement:n}=e,r=O(t),i=null==t,s={},o={name:e.name,primaryKey:{name:null,isPrimaryKey:!0,outbound:i,compound:r,keyPath:t,autoIncrement:n,unique:!0,extractKey:Bn(t)},indexes:Fn(e.indexNames).map((t=>e.index(t))).map((e=>{const{name:t,unique:n,multiEntry:r,keyPath:i}=e,o={name:t,compound:O(i),keyPath:i,unique:n,multiEntry:r,extractKey:Bn(i)};return s[Nn(i)]=o,o})),getIndexByKeyPath:e=>s[Nn(e)]};return s[":id"]=o.primaryKey,null!=t&&(s[Nn(t)]=o.primaryKey),o}))},hasGetAll:n.length>0&&"getAll"in t.objectStore(n[0])&&!("undefined"!=typeof navigator&&/Safari/.test(navigator.userAgent)&&!/(Chrome\/|Edge\/)/.test(navigator.userAgent)&&[].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1]<604)}}(e,n),o=i.tables.map((e=>function(e){const t=e.name;return{name:t,schema:e,mutate:function({trans:e,type:n,keys:i,values:s,range:o}){return new Promise(((a,u)=>{a=mt(a);const c=e.objectStore(t),l=null==c.keyPath,h="put"===n||"add"===n;if(!h&&"delete"!==n&&"deleteRange"!==n)throw new Error("Invalid operation type: "+n);const{length:d}=i||s||{length:1};if(i&&s&&i.length!==s.length)throw new Error("Given keys array must have same length as given values array.");if(0===d)return a({numFailures:0,failures:{},results:[],lastResult:void 0});let f;const p=[],y=[];let m=0;const v=e=>{++m,On(e)};if("deleteRange"===n){if(4===o.type)return a({numFailures:m,failures:y,results:[],lastResult:void 0});3===o.type?p.push(f=c.clear()):p.push(f=c.delete(r(o)))}else{const[e,t]=h?l?[s,i]:[s,null]:[i,null];if(h)for(let r=0;r<d;++r)p.push(f=t&&void 0!==t[r]?c[n](e[r],t[r]):c[n](e[r])),f.onerror=v;else for(let t=0;t<d;++t)p.push(f=c[n](e[t])),f.onerror=v}const g=e=>{const t=e.target.result;p.forEach(((e,t)=>null!=e.error&&(y[t]=e.error))),a({numFailures:m,failures:y,results:"delete"===n?i:p.map((e=>e.result)),lastResult:t})};f.onerror=e=>{v(e),g(e)},f.onsuccess=g}))},getMany:({trans:e,keys:n})=>new Promise(((r,i)=>{r=mt(r);const s=e.objectStore(t),o=n.length,a=new Array(o);let u,c=0,l=0;const h=e=>{const t=e.target;a[t._pos]=t.result,++l===c&&r(a)},d=Pn(i);for(let e=0;e<o;++e)null!=n[e]&&(u=s.get(n[e]),u._pos=e,u.onsuccess=h,u.onerror=d,++c);0===c&&r(a)})),get:({trans:e,key:n})=>new Promise(((r,i)=>{r=mt(r);const s=e.objectStore(t).get(n);s.onsuccess=e=>r(e.target.result),s.onerror=Pn(i)})),query:function(e){return n=>new Promise(((i,s)=>{i=mt(i);const{trans:o,values:a,limit:u,query:c}=n,l=u===1/0?void 0:u,{index:h,range:d}=c,f=o.objectStore(t),p=h.isPrimaryKey?f:f.index(h.name),y=r(d);if(0===u)return i({result:[]});if(e){const e=a?p.getAll(y,l):p.getAllKeys(y,l);e.onsuccess=e=>i({result:e.target.result}),e.onerror=Pn(s)}else{let e=0;const t=a||!("openKeyCursor"in p)?p.openCursor(y):p.openKeyCursor(y),n=[];t.onsuccess=r=>{const s=t.result;return s?(n.push(a?s.value:s.primaryKey),++e===u?i({result:n}):void s.continue()):i({result:n})},t.onerror=Pn(s)}}))}(s),openCursor:function({trans:e,values:n,query:i,reverse:s,unique:o}){return new Promise(((a,u)=>{a=mt(a);const{index:c,range:l}=i,h=e.objectStore(t),d=c.isPrimaryKey?h:h.index(c.name),f=s?o?"prevunique":"prev":o?"nextunique":"next",p=n||!("openKeyCursor"in d)?d.openCursor(r(l),f):d.openKeyCursor(r(l),f);p.onerror=Pn(u),p.onsuccess=mt((t=>{const n=p.result;if(!n)return void a(null);n.___id=++Mn,n.done=!1;const r=n.continue.bind(n);let i=n.continuePrimaryKey;i&&(i=i.bind(n));const s=n.advance.bind(n),o=()=>{throw new Error("Cursor not stopped")};n.trans=e,n.stop=n.continue=n.continuePrimaryKey=n.advance=()=>{throw new Error("Cursor not started")},n.fail=mt(u),n.next=function(){let e=1;return this.start((()=>e--?this.continue():this.stop())).then((()=>this))},n.start=e=>{const t=new Promise(((e,t)=>{e=mt(e),p.onerror=Pn(t),n.fail=t,n.stop=t=>{n.stop=n.continue=n.continuePrimaryKey=n.advance=o,e(t)}})),a=()=>{if(p.result)try{e()}catch(e){n.fail(e)}else n.done=!0,n.start=()=>{throw new Error("Cursor behind last entry")},n.stop()};return p.onsuccess=mt((e=>{p.onsuccess=a,a()})),n.continue=r,n.continuePrimaryKey=i,n.advance=s,a(),t},a(n)}),u)}))},count({query:e,trans:n}){const{index:i,range:s}=e;return new Promise(((e,o)=>{const a=n.objectStore(t),u=i.isPrimaryKey?a:a.index(i.name),c=r(s),l=c?u.count(c):u.count();l.onsuccess=mt((t=>e(t.target.result))),l.onerror=Pn(o)}))}}}(e))),a={};return o.forEach((e=>a[e.name]=e)),{stack:"dbcore",transaction:e.transaction.bind(e),table(e){if(!a[e])throw new Error(`Table '${e}' not found`);return a[e]},MIN_KEY:-1/0,MAX_KEY:Rn(t),schema:i}}(t,n,i),e.dbcore);return{dbcore:s}}(e._middlewares,n,e._deps,t);e.core=r.dbcore,e.tables.forEach((t=>{const n=t.name;e.core.schema.tables.some((e=>e.name===n))&&(t.core=e.core.table(n),e[n]instanceof e.Table&&(e[n].core=t.core))}))}function Un({_novip:e},t,n,r){n.forEach((n=>{const i=r[n];t.forEach((t=>{const r=F(t,n);(!r||"value"in r&&void 0===r.value)&&(t===e.Transaction.prototype||t instanceof e.Transaction?T(t,n,{get(){return this.table(n)},set(e){D(this,n,{value:e,writable:!0,configurable:!0,enumerable:!0})}}):t[n]=new e.Table(n,i))}))}))}function $n({_novip:e},t){t.forEach((t=>{for(let n in t)t[n]instanceof e.Table&&delete t[n]}))}function Ln(e,t){return e._cfg.version-t._cfg.version}function Wn(e,t){const n={del:[],add:[],change:[]};let r;for(r in e)t[r]||n.del.push(r);for(r in t){const i=e[r],s=t[r];if(i){const e={name:r,def:s,recreate:!1,del:[],add:[],change:[]};if(""+(i.primKey.keyPath||"")!=""+(s.primKey.keyPath||"")||i.primKey.auto!==s.primKey.auto&&!zt)e.recreate=!0,n.change.push(e);else{const t=i.idxByName,r=s.idxByName;let o;for(o in t)r[o]||e.del.push(o);for(o in r){const n=t[o],i=r[o];n?n.src!==i.src&&e.change.push(i):e.add.push(i)}(e.del.length>0||e.add.length>0||e.change.length>0)&&n.change.push(e)}}else n.add.push([r,s])}return n}function zn(e,t,n,r){const i=e.db.createObjectStore(t,n.keyPath?{keyPath:n.keyPath,autoIncrement:n.auto}:{autoIncrement:n.auto});return r.forEach((e=>Hn(i,e))),i}function Hn(e,t){e.createIndex(t.name,t.keyPath,{unique:t.unique,multiEntry:t.multi})}function Vn(e,t,n){const r={};return N(t.objectStoreNames,0).forEach((e=>{const t=n.objectStore(e);let i=t.keyPath;const s=In(Dn(i),i||"",!1,!1,!!t.autoIncrement,i&&"string"!=typeof i,!0),o=[];for(let e=0;e<t.indexNames.length;++e){const n=t.index(t.indexNames[e]);i=n.keyPath;var a=In(n.name,i,!!n.unique,!!n.multiEntry,!1,i&&"string"!=typeof i,!1);o.push(a)}r[e]=Tn(e,s,o)})),r}function Qn({_novip:e},t,n){const r=n.db.objectStoreNames;for(let i=0;i<r.length;++i){const s=r[i],o=n.objectStore(s);e._hasGetAll="getAll"in o;for(let e=0;e<o.indexNames.length;++e){const n=o.indexNames[e],r=o.index(n).keyPath,i="string"==typeof r?r:"["+N(r).join("+")+"]";if(t[s]){const e=t[s].idxByName[i];e&&(e.name=n,delete t[s].idxByName[i],t[s].idxByName[n]=e)}}}"undefined"!=typeof navigator&&/Safari/.test(navigator.userAgent)&&!/(Chrome\/|Edge\/)/.test(navigator.userAgent)&&E.WorkerGlobalScope&&E instanceof E.WorkerGlobalScope&&[].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1]<604&&(e._hasGetAll=!1)}class Yn{_parseStoresSpec(e,t){P(e).forEach((n=>{if(null!==e[n]){var r=e[n].split(",").map(((e,t)=>{const n=(e=e.trim()).replace(/([&*]|\+\+)/g,""),r=/^\[/.test(n)?n.match(/^\[(.*)\]$/)[1].split("+"):n;return In(n,r||null,/\&/.test(e),/\*/.test(e),/\+\+/.test(e),O(r),0===t)})),i=r.shift();if(i.multi)throw new xe.Schema("Primary key cannot be multi-valued");r.forEach((e=>{if(e.auto)throw new xe.Schema("Only primary key can be marked as autoIncrement (++)");if(!e.keyPath)throw new xe.Schema("Index must have a name and cannot be an empty string")})),t[n]=Tn(n,i,r)}}))}stores(e){const t=this.db;this._cfg.storesSource=this._cfg.storesSource?K(this._cfg.storesSource,e):e;const n=t._versions,r={};let i={};return n.forEach((e=>{K(r,e._cfg.storesSource),i=e._cfg.dbschema={},e._parseStoresSpec(r,i)})),t._dbSchema=i,$n(t,[t._allTables,t,t.Transaction.prototype]),Un(t,[t._allTables,t,t.Transaction.prototype,this._cfg.tables],P(i),i),t._storeNames=P(i),this}upgrade(e){return this._cfg.contentUpgrade=De(this._cfg.contentUpgrade||Ee,e),this}}function Gn(e,t){let n=e._dbNamesDB;return n||(n=e._dbNamesDB=new gr(Yt,{addons:[],indexedDB:e,IDBKeyRange:t}),n.version(1).stores({dbnames:"name"})),n.table("dbnames")}function Xn(e){return e&&"function"==typeof e.databases}function Jn(e){return kt((function(){return Xe.letThrough=!0,e()}))}function Zn(){var e;return!navigator.userAgentData&&/Safari\//.test(navigator.userAgent)&&!/Chrom(e|ium)\//.test(navigator.userAgent)&&indexedDB.databases?new Promise((function(t){var n=function(){return indexedDB.databases().finally(t)};e=setInterval(n,100),n()})).finally((function(){return clearInterval(e)})):Promise.resolve()}function er(e){const t=e._state,{indexedDB:n}=e._deps;if(t.isBeingOpened||e.idbdb)return t.dbReadyPromise.then((()=>t.dbOpenError?Ft(t.dbOpenError):e));ae&&(t.openCanceller._stackHolder=he()),t.isBeingOpened=!0,t.dbOpenError=null,t.openComplete=!1;const r=t.openCanceller;function i(){if(t.openCanceller!==r)throw new xe.DatabaseClosed("db.open() was cancelled")}let s=t.dbReadyResolve,o=null,a=!1;return tt.race([r,("undefined"==typeof navigator?tt.resolve():Zn()).then((()=>new tt(((r,s)=>{if(i(),!n)throw new xe.MissingAPI;const u=e.name,c=t.autoSchema?n.open(u):n.open(u,Math.round(10*e.verno));if(!c)throw new xe.MissingAPI;c.onerror=Pn(s),c.onblocked=mt(e._fireOnBlocked),c.onupgradeneeded=mt((r=>{if(o=c.transaction,t.autoSchema&&!e._options.allowEmptyDB){c.onerror=On,o.abort(),c.result.close();const e=n.deleteDatabase(u);e.onsuccess=e.onerror=mt((()=>{s(new xe.NoSuchDatabase(`Database ${u} doesnt exist`))}))}else{o.onerror=Pn(s);var i=r.oldVersion>Math.pow(2,62)?0:r.oldVersion;a=i<1,e._novip.idbdb=c.result,function(e,t,n,r){const i=e._dbSchema,s=e._createTransaction("readwrite",e._storeNames,i);s.create(n),s._completion.catch(r);const o=s._reject.bind(s),a=Xe.transless||Xe;kt((()=>{Xe.trans=s,Xe.transless=a,0===t?(P(i).forEach((e=>{zn(n,e,i[e].primKey,i[e].indexes)})),qn(e,n),tt.follow((()=>e.on.populate.fire(s))).catch(o)):function({_novip:e},t,n,r){const i=[],s=e._versions;let o=e._dbSchema=Vn(0,e.idbdb,r),a=!1;const u=s.filter((e=>e._cfg.version>=t));return u.forEach((s=>{i.push((()=>{const i=o,u=s._cfg.dbschema;Qn(e,i,r),Qn(e,u,r),o=e._dbSchema=u;const c=Wn(i,u);c.add.forEach((e=>{zn(r,e[0],e[1].primKey,e[1].indexes)})),c.change.forEach((e=>{if(e.recreate)throw new xe.Upgrade("Not yet support for changing primary key");{const t=r.objectStore(e.name);e.add.forEach((e=>Hn(t,e))),e.change.forEach((e=>{t.deleteIndex(e.name),Hn(t,e)})),e.del.forEach((e=>t.deleteIndex(e)))}}));const l=s._cfg.contentUpgrade;if(l&&s._cfg.version>t){qn(e,r),n._memoizedTables={},a=!0;let t=H(u);c.del.forEach((e=>{t[e]=i[e]})),$n(e,[e.Transaction.prototype]),Un(e,[e.Transaction.prototype],P(t),t),n.schema=t;const s=oe(l);let o;s&&St();const h=tt.follow((()=>{if(o=l(n),o&&s){var e=Et.bind(null,null);o.then(e,e)}}));return o&&"function"==typeof o.then?tt.resolve(o):h.then((()=>o))}})),i.push((t=>{a&&Ht||function(e,t){[].slice.call(t.db.objectStoreNames).forEach((n=>null==e[n]&&t.db.deleteObjectStore(n)))}(s._cfg.dbschema,t),$n(e,[e.Transaction.prototype]),Un(e,[e.Transaction.prototype],e._storeNames,e._dbSchema),n.schema=e._dbSchema}))})),function e(){return i.length?tt.resolve(i.shift()(n.idbtrans)).then(e):tt.resolve()}().then((()=>{var e,t;t=r,P(e=o).forEach((n=>{t.db.objectStoreNames.contains(n)||zn(t,n,e[n].primKey,e[n].indexes)}))}))}(e,t,s,n).catch(o)}))}(e,i/10,o,s)}}),s),c.onsuccess=mt((()=>{o=null;const n=e._novip.idbdb=c.result,i=N(n.objectStoreNames);if(i.length>0)try{const r=n.transaction(1===(s=i).length?s[0]:s,"readonly");t.autoSchema?function({_novip:e},t,n){e.verno=t.version/10;const r=e._dbSchema=Vn(0,t,n);e._storeNames=N(t.objectStoreNames,0),Un(e,[e._allTables],P(r),r)}(e,n,r):(Qn(e,e._dbSchema,r),function(e,t){const n=Wn(Vn(0,e.idbdb,t),e._dbSchema);return!(n.add.length||n.change.some((e=>e.add.length||e.change.length)))}(e,r)||console.warn("Dexie SchemaDiff: Schema was extended without increasing the number passed to db.version(). Some queries may fail.")),qn(e,r)}catch(e){}var s;Wt.push(e),n.onversionchange=mt((n=>{t.vcFired=!0,e.on("versionchange").fire(n)})),n.onclose=mt((t=>{e.on("close").fire(t)})),a&&function({indexedDB:e,IDBKeyRange:t},n){!Xn(e)&&n!==Yt&&Gn(e,t).put({name:n}).catch(Ee)}(e._deps,u),r()}),s)}))))]).then((()=>(i(),t.onReadyBeingFired=[],tt.resolve(Jn((()=>e.on.ready.fire(e.vip)))).then((function n(){if(t.onReadyBeingFired.length>0){let r=t.onReadyBeingFired.reduce(De,Ee);return t.onReadyBeingFired=[],tt.resolve(Jn((()=>r(e.vip)))).then(n)}}))))).finally((()=>{t.onReadyBeingFired=null,t.isBeingOpened=!1})).then((()=>e)).catch((n=>{t.dbOpenError=n;try{o&&o.abort()}catch(e){}return r===t.openCanceller&&e._close(),Ft(n)})).finally((()=>{t.openComplete=!0,s()}))}function tr(e){var t=t=>e.next(t),n=i(t),r=i((t=>e.throw(t)));function i(e){return t=>{var i=e(t),s=i.value;return i.done?s:s&&"function"==typeof s.then?s.then(n,r):O(s)?Promise.all(s).then(n,r):n(s)}}return i(t)()}function nr(e,t,n){var r=arguments.length;if(r<2)throw new xe.InvalidArgument("Too few arguments");for(var i=new Array(r-1);--r;)i[r-1]=arguments[r];n=i.pop();var s=Q(i);return[e,s,n]}function rr(e,t,n,r,i){return tt.resolve().then((()=>{const s=Xe.transless||Xe,o=e._createTransaction(t,n,e._dbSchema,r),a={trans:o,transless:s};r?o.idbtrans=r.idbtrans:o.create();const u=oe(i);let c;u&&St();const l=tt.follow((()=>{if(c=i.call(o,o),c)if(u){var e=Et.bind(null,null);c.then(e,e)}else"function"==typeof c.next&&"function"==typeof c.throw&&(c=tr(c))}),a);return(c&&"function"==typeof c.then?tt.resolve(c).then((e=>o.active?e:Ft(new xe.PrematureCommit("Transaction committed too early. See http://bit.ly/2kdckMn")))):l.then((()=>c))).then((e=>(r&&o._resolve(),o._completion.then((()=>e))))).catch((e=>(o._reject(e),Ft(e))))}))}function ir(e,t,n){const r=O(e)?e.slice():[e];for(let e=0;e<n;++e)r.push(t);return r}const sr={stack:"dbcore",name:"VirtualIndexMiddleware",level:1,create:function(e){return{...e,table(t){const n=e.table(t),{schema:r}=n,i={},s=[];function o(e,t,n){const r=Nn(e),a=i[r]=i[r]||[],u=null==e?0:"string"==typeof e?1:e.length,c=t>0,l={...n,isVirtual:c,keyTail:t,keyLength:u,extractKey:Bn(e),unique:!c&&n.unique};return a.push(l),l.isPrimaryKey||s.push(l),u>1&&o(2===u?e[0]:e.slice(0,u-1),t+1,n),a.sort(((e,t)=>e.keyTail-t.keyTail)),l}const a=o(r.primaryKey.keyPath,0,r.primaryKey);i[":id"]=[a];for(const e of r.indexes)o(e.keyPath,0,e);function u(t){const n=t.query.index;return n.isVirtual?{...t,query:{index:n,range:(r=t.query.range,i=n.keyTail,{type:1===r.type?2:r.type,lower:ir(r.lower,r.lowerOpen?e.MAX_KEY:e.MIN_KEY,i),lowerOpen:!0,upper:ir(r.upper,r.upperOpen?e.MIN_KEY:e.MAX_KEY,i),upperOpen:!0})}}:t;var r,i}const c={...n,schema:{...r,primaryKey:a,indexes:s,getIndexByKeyPath:function(e){const t=i[Nn(e)];return t&&t[0]}},count:e=>n.count(u(e)),query:e=>n.query(u(e)),openCursor(t){const{keyTail:r,isVirtual:i,keyLength:s}=t.query.index;return i?n.openCursor(u(t)).then((n=>n&&function(n){const i=Object.create(n,{continue:{value:function(i){null!=i?n.continue(ir(i,t.reverse?e.MAX_KEY:e.MIN_KEY,r)):t.unique?n.continue(n.key.slice(0,s).concat(t.reverse?e.MIN_KEY:e.MAX_KEY,r)):n.continue()}},continuePrimaryKey:{value(t,i){n.continuePrimaryKey(ir(t,e.MAX_KEY,r),i)}},primaryKey:{get:()=>n.primaryKey},key:{get(){const e=n.key;return 1===s?e[0]:e.slice(0,s)}},value:{get:()=>n.value}});return i}(n))):n.openCursor(t)}};return c}}}};function or(e,t,n,r){return n=n||{},r=r||"",P(e).forEach((i=>{if(A(t,i)){var s=e[i],o=t[i];if("object"==typeof s&&"object"==typeof o&&s&&o){const e=te(s);e!==te(o)?n[r+i]=t[i]:"Object"===e?or(s,o,n,r+i+"."):s!==o&&(n[r+i]=t[i])}else s!==o&&(n[r+i]=t[i])}else n[r+i]=void 0})),P(t).forEach((i=>{A(e,i)||(n[r+i]=t[i])})),n}const ar={stack:"dbcore",name:"HooksMiddleware",level:2,create:e=>({...e,table(t){const n=e.table(t),{primaryKey:r}=n.schema,i={...n,mutate(e){const i=Xe.trans,{deleting:s,creating:o,updating:a}=i.table(t).hook;switch(e.type){case"add":if(o.fire===Ee)break;return i._promise("readwrite",(()=>u(e)),!0);case"put":if(o.fire===Ee&&a.fire===Ee)break;return i._promise("readwrite",(()=>u(e)),!0);case"delete":if(s.fire===Ee)break;return i._promise("readwrite",(()=>u(e)),!0);case"deleteRange":if(s.fire===Ee)break;return i._promise("readwrite",(()=>function(e){return c(e.trans,e.range,1e4)}(e)),!0)}return n.mutate(e);function u(e){const t=Xe.trans,i=e.keys||function(e,t){return"delete"===t.type?t.keys:t.keys||t.values.map(e.extractKey)}(r,e);if(!i)throw new Error("Keys missing");return"delete"!==(e="add"===e.type||"put"===e.type?{...e,keys:i}:{...e}).type&&(e.values=[...e.values]),e.keys&&(e.keys=[...e.keys]),function(e,t,n){return"add"===t.type?Promise.resolve([]):e.getMany({trans:t.trans,keys:n,cache:"immutable"})}(n,e,i).then((u=>{const c=i.map(((n,i)=>{const c=u[i],l={onerror:null,onsuccess:null};if("delete"===e.type)s.fire.call(l,n,c,t);else if("add"===e.type||void 0===c){const s=o.fire.call(l,n,e.values[i],t);null==n&&null!=s&&(n=s,e.keys[i]=n,r.outbound||z(e.values[i],r.keyPath,n))}else{const r=or(c,e.values[i]),s=a.fire.call(l,r,n,c,t);if(s){const t=e.values[i];Object.keys(s).forEach((e=>{A(t,e)?t[e]=s[e]:z(t,e,s[e])}))}}return l}));return n.mutate(e).then((({failures:t,results:n,numFailures:r,lastResult:s})=>{for(let r=0;r<i.length;++r){const s=n?n[r]:i[r],o=c[r];null==s?o.onerror&&o.onerror(t[r]):o.onsuccess&&o.onsuccess("put"===e.type&&u[r]?e.values[r]:s)}return{failures:t,results:n,numFailures:r,lastResult:s}})).catch((e=>(c.forEach((t=>t.onerror&&t.onerror(e))),Promise.reject(e))))}))}function c(e,t,i){return n.query({trans:e,values:!1,query:{index:r,range:t},limit:i}).then((({result:n})=>u({type:"delete",keys:n,trans:e}).then((r=>r.numFailures>0?Promise.reject(r.failures[0]):n.length<i?{failures:[],numFailures:0,lastResult:void 0}:c(e,{...t,lower:n[n.length-1],lowerOpen:!0},i)))))}}};return i}})};function ur(e,t,n){try{if(!t)return null;if(t.keys.length<e.length)return null;const r=[];for(let i=0,s=0;i<t.keys.length&&s<e.length;++i)0===dn(t.keys[i],e[s])&&(r.push(n?J(t.values[i]):t.values[i]),++s);return r.length===e.length?r:null}catch(e){return null}}const cr={stack:"dbcore",level:-1,create:e=>({table:t=>{const n=e.table(t);return{...n,getMany:e=>{if(!e.cache)return n.getMany(e);const t=ur(e.keys,e.trans._cache,"clone"===e.cache);return t?tt.resolve(t):n.getMany(e).then((t=>(e.trans._cache={keys:e.keys,values:"clone"===e.cache?J(t):t},t)))},mutate:e=>("add"!==e.type&&(e.trans._cache=null),n.mutate(e))}}})};function lr(e){return!("from"in e)}const hr=function(e,t){if(!this){const t=new hr;return e&&"d"in e&&K(t,e),t}K(this,arguments.length?{d:1,from:e,to:arguments.length>1?t:e}:{d:0})};function dr(e,t,n){const r=dn(t,n);if(isNaN(r))return;if(r>0)throw RangeError();if(lr(e))return K(e,{from:t,to:n,d:1});const i=e.l,s=e.r;if(dn(n,e.from)<0)return i?dr(i,t,n):e.l={from:t,to:n,d:1,l:null,r:null},yr(e);if(dn(t,e.to)>0)return s?dr(s,t,n):e.r={from:t,to:n,d:1,l:null,r:null},yr(e);dn(t,e.from)<0&&(e.from=t,e.l=null,e.d=s?s.d+1:1),dn(n,e.to)>0&&(e.to=n,e.r=null,e.d=e.l?e.l.d+1:1);const o=!e.r;i&&!e.l&&fr(e,i),s&&o&&fr(e,s)}function fr(e,t){lr(t)||function e(t,{from:n,to:r,l:i,r:s}){dr(t,n,r),i&&e(t,i),s&&e(t,s)}(e,t)}function pr(e){let t=lr(e)?null:{s:0,n:e};return{next(e){const n=arguments.length>0;for(;t;)switch(t.s){case 0:if(t.s=1,n)for(;t.n.l&&dn(e,t.n.from)<0;)t={up:t,n:t.n.l,s:1};else for(;t.n.l;)t={up:t,n:t.n.l,s:1};case 1:if(t.s=2,!n||dn(e,t.n.to)<=0)return{value:t.n,done:!1};case 2:if(t.n.r){t.s=3,t={up:t,n:t.n.r,s:0};continue}case 3:t=t.up}return{done:!0}}}}function yr(e){var t,n;const r=((null===(t=e.r)||void 0===t?void 0:t.d)||0)-((null===(n=e.l)||void 0===n?void 0:n.d)||0),i=r>1?"r":r<-1?"l":"";if(i){const t="r"===i?"l":"r",n={...e},r=e[i];e.from=r.from,e.to=r.to,e[i]=r[i],n[i]=r[t],e[t]=n,n.d=mr(n)}e.d=mr(e)}function mr({r:e,l:t}){return(e?t?Math.max(e.d,t.d):e.d:t?t.d:0)+1}I(hr.prototype,{add(e){return fr(this,e),this},addKey(e){return dr(this,e,e),this},addKeys(e){return e.forEach((e=>dr(this,e,e))),this},[ne](){return pr(this)}});const vr={stack:"dbcore",level:0,create:e=>{const t=e.schema.name,n=new hr(e.MIN_KEY,e.MAX_KEY);return{...e,table:r=>{const i=e.table(r),{schema:s}=i,{primaryKey:o}=s,{extractKey:a,outbound:u}=o,c={...i,mutate:e=>{const o=e.trans,a=o.mutatedParts||(o.mutatedParts={}),u=e=>{const n=`idb://${t}/${r}/${e}`;return a[n]||(a[n]=new hr)},c=u(""),l=u(":dels"),{type:h}=e;let[d,f]="deleteRange"===e.type?[e.range]:"delete"===e.type?[e.keys]:e.values.length<50?[[],e.values]:[];const p=e.trans._cache;return i.mutate(e).then((e=>{if(O(d)){"delete"!==h&&(d=e.results),c.addKeys(d);const t=ur(d,p);t||"add"===h||l.addKeys(d),(t||f)&&function(e,t,n,r){t.indexes.forEach((function(t){const i=e(t.name||"");function s(e){return null!=e?t.extractKey(e):null}const o=e=>t.multiEntry&&O(e)?e.forEach((e=>i.addKey(e))):i.addKey(e);(n||r).forEach(((e,t)=>{const i=n&&s(n[t]),a=r&&s(r[t]);0!==dn(i,a)&&(null!=i&&o(i),null!=a&&o(a))}))}))}(u,s,t,f)}else if(d){const e={from:d.lower,to:d.upper};l.add(e),c.add(e)}else c.add(n),l.add(n),s.indexes.forEach((e=>u(e.name).add(n)));return e}))}},l=({query:{index:t,range:n}})=>{var r,i;return[t,new hr(null!==(r=n.lower)&&void 0!==r?r:e.MIN_KEY,null!==(i=n.upper)&&void 0!==i?i:e.MAX_KEY)]},h={get:e=>[o,new hr(e.key)],getMany:e=>[o,(new hr).addKeys(e.keys)],count:l,query:l,openCursor:l};return P(h).forEach((e=>{c[e]=function(s){const{subscr:o}=Xe;if(o){const c=e=>{const n=`idb://${t}/${r}/${e}`;return o[n]||(o[n]=new hr)},l=c(""),d=c(":dels"),[f,p]=h[e](s);if(c(f.name||"").add(p),!f.isPrimaryKey){if("count"!==e){const t="query"===e&&u&&s.values&&i.query({...s,values:!1});return i[e].apply(this,arguments).then((n=>{if("query"===e){if(u&&s.values)return t.then((({result:e})=>(l.addKeys(e),n)));const e=s.values?n.result.map(a):n.result;s.values?l.addKeys(e):d.addKeys(e)}else if("openCursor"===e){const e=n,t=s.values;return e&&Object.create(e,{key:{get:()=>(d.addKey(e.primaryKey),e.key)},primaryKey:{get(){const t=e.primaryKey;return d.addKey(t),t}},value:{get:()=>(t&&l.addKey(e.primaryKey),e.value)}})}return n}))}d.add(n)}}return i[e].apply(this,arguments)}})),c}}}};class gr{constructor(e,t){this._middlewares={},this.verno=0;const n=gr.dependencies;this._options=t={addons:gr.addons,autoOpen:!0,indexedDB:n.indexedDB,IDBKeyRange:n.IDBKeyRange,...t},this._deps={indexedDB:t.indexedDB,IDBKeyRange:t.IDBKeyRange};const{addons:r}=t;this._dbSchema={},this._versions=[],this._storeNames=[],this._allTables={},this.idbdb=null,this._novip=this;const i={dbOpenError:null,isBeingOpened:!1,onReadyBeingFired:null,openComplete:!1,dbReadyResolve:Ee,dbReadyPromise:null,cancelOpen:Ee,openCanceller:null,autoSchema:!0};i.dbReadyPromise=new tt((e=>{i.dbReadyResolve=e})),i.openCanceller=new tt(((e,t)=>{i.cancelOpen=t})),this._state=i,this.name=e,this.on=nn(this,"populate","blocked","versionchange","close",{ready:[De,Ee]}),this.on.ready.subscribe=q(this.on.ready.subscribe,(e=>(t,n)=>{gr.vip((()=>{const r=this._state;if(r.openComplete)r.dbOpenError||tt.resolve().then(t),n&&e(t);else if(r.onReadyBeingFired)r.onReadyBeingFired.push(t),n&&e(t);else{e(t);const r=this;n||e((function e(){r.on.ready.unsubscribe(t),r.on.ready.unsubscribe(e)}))}}))})),this.Collection=function(e){return rn(yn.prototype,(function(t,n){this.db=e;let r=Zt,i=null;if(n)try{r=n()}catch(e){i=e}const s=t._ctx,o=s.table,a=o.hook.reading.fire;this._ctx={table:o,index:s.index,isPrimKey:!s.index||o.schema.primKey.keyPath&&s.index===o.schema.primKey.name,range:r,keysOnly:!1,dir:"next",unique:"",algorithm:null,filter:null,replayFilter:null,justLimit:!0,isMatch:null,offset:0,limit:1/0,error:i,or:s.or,valueMapper:a!==Pe?a:null}}))}(this),this.Table=function(e){return rn(tn.prototype,(function(t,n,r){this.db=e,this._tx=r,this.name=t,this.schema=n,this.hook=e._allTables[t]?e._allTables[t].hook:nn(null,{creating:[je,Ee],reading:[Oe,Pe],updating:[Ae,Ee],deleting:[Ce,Ee]})}))}(this),this.Transaction=function(e){return rn(An.prototype,(function(t,n,r,i,s){this.db=e,this.mode=t,this.storeNames=n,this.schema=r,this.chromeTransactionDurability=i,this.idbtrans=null,this.on=nn(this,"complete","error","abort"),this.parent=s||null,this.active=!0,this._reculock=0,this._blockedFuncs=[],this._resolve=null,this._reject=null,this._waitingFor=null,this._waitingQueue=null,this._spinCount=0,this._completion=new tt(((e,t)=>{this._resolve=e,this._reject=t})),this._completion.then((()=>{this.active=!1,this.on.complete.fire()}),(e=>{var t=this.active;return this.active=!1,this.on.error.fire(e),this.parent?this.parent._reject(e):t&&this.idbtrans&&this.idbtrans.abort(),Ft(e)}))}))}(this),this.Version=function(e){return rn(Yn.prototype,(function(t){this.db=e,this._cfg={version:t,storesSource:null,dbschema:{},tables:{},contentUpgrade:null}}))}(this),this.WhereClause=function(e){return rn(En.prototype,(function(t,n,r){this.db=e,this._ctx={table:t,index:":id"===n?null:n,or:r};const i=e._deps.indexedDB;if(!i)throw new xe.MissingAPI;this._cmp=this._ascending=i.cmp.bind(i),this._descending=(e,t)=>i.cmp(t,e),this._max=(e,t)=>i.cmp(e,t)>0?e:t,this._min=(e,t)=>i.cmp(e,t)<0?e:t,this._IDBKeyRange=e._deps.IDBKeyRange}))}(this),this.on("versionchange",(e=>{e.newVersion>0?console.warn(`Another connection wants to upgrade database '${this.name}'. Closing db now to resume the upgrade.`):console.warn(`Another connection wants to delete database '${this.name}'. Closing db now to resume the delete request.`),this.close()})),this.on("blocked",(e=>{!e.newVersion||e.newVersion<e.oldVersion?console.warn(`Dexie.delete('${this.name}') was blocked`):console.warn(`Upgrade '${this.name}' blocked by other connection holding version ${e.oldVersion/10}`)})),this._maxKey=Rn(t.IDBKeyRange),this._createTransaction=(e,t,n,r)=>new this.Transaction(e,t,n,this._options.chromeTransactionDurability,r),this._fireOnBlocked=e=>{this.on("blocked").fire(e),Wt.filter((e=>e.name===this.name&&e!==this&&!e._state.vcFired)).map((t=>t.on("versionchange").fire(e)))},this.use(sr),this.use(ar),this.use(vr),this.use(cr),this.vip=Object.create(this,{_vip:{value:!0}}),r.forEach((e=>e(this)))}version(e){if(isNaN(e)||e<.1)throw new xe.Type("Given version is not a positive number");if(e=Math.round(10*e)/10,this.idbdb||this._state.isBeingOpened)throw new xe.Schema("Cannot add version when database is open");this.verno=Math.max(this.verno,e);const t=this._versions;var n=t.filter((t=>t._cfg.version===e))[0];return n||(n=new this.Version(e),t.push(n),t.sort(Ln),n.stores({}),this._state.autoSchema=!1,n)}_whenReady(e){return this.idbdb&&(this._state.openComplete||Xe.letThrough||this._vip)?e():new tt(((e,t)=>{if(this._state.openComplete)return t(new xe.DatabaseClosed(this._state.dbOpenError));if(!this._state.isBeingOpened){if(!this._options.autoOpen)return void t(new xe.DatabaseClosed);this.open().catch(Ee)}this._state.dbReadyPromise.then(e,t)})).then(e)}use({stack:e,create:t,level:n,name:r}){r&&this.unuse({stack:e,name:r});const i=this._middlewares[e]||(this._middlewares[e]=[]);return i.push({stack:e,create:t,level:null==n?10:n,name:r}),i.sort(((e,t)=>e.level-t.level)),this}unuse({stack:e,name:t,create:n}){return e&&this._middlewares[e]&&(this._middlewares[e]=this._middlewares[e].filter((e=>n?e.create!==n:!!t&&e.name!==t))),this}open(){return er(this)}_close(){const e=this._state,t=Wt.indexOf(this);if(t>=0&&Wt.splice(t,1),this.idbdb){try{this.idbdb.close()}catch(e){}this._novip.idbdb=null}e.dbReadyPromise=new tt((t=>{e.dbReadyResolve=t})),e.openCanceller=new tt(((t,n)=>{e.cancelOpen=n}))}close(){this._close();const e=this._state;this._options.autoOpen=!1,e.dbOpenError=new xe.DatabaseClosed,e.isBeingOpened&&e.cancelOpen(e.dbOpenError)}delete(){const e=arguments.length>0,t=this._state;return new tt(((n,r)=>{const i=()=>{this.close();var e=this._deps.indexedDB.deleteDatabase(this.name);e.onsuccess=mt((()=>{!function({indexedDB:e,IDBKeyRange:t},n){!Xn(e)&&n!==Yt&&Gn(e,t).delete(n).catch(Ee)}(this._deps,this.name),n()})),e.onerror=Pn(r),e.onblocked=this._fireOnBlocked};if(e)throw new xe.InvalidArgument("Arguments not allowed in db.delete()");t.isBeingOpened?t.dbReadyPromise.then(i):i()}))}backendDB(){return this.idbdb}isOpen(){return null!==this.idbdb}hasBeenClosed(){const e=this._state.dbOpenError;return e&&"DatabaseClosed"===e.name}hasFailed(){return null!==this._state.dbOpenError}dynamicallyOpened(){return this._state.autoSchema}get tables(){return P(this._allTables).map((e=>this._allTables[e]))}transaction(){const e=nr.apply(this,arguments);return this._transaction.apply(this,e)}_transaction(e,t,n){let r=Xe.trans;r&&r.db===this&&-1===e.indexOf("!")||(r=null);const i=-1!==e.indexOf("?");let s,o;e=e.replace("!","").replace("?","");try{if(o=t.map((e=>{var t=e instanceof this.Table?e.name:e;if("string"!=typeof t)throw new TypeError("Invalid table argument to Dexie.transaction(). Only Table or String are allowed");return t})),"r"==e||e===Gt)s=Gt;else{if("rw"!=e&&e!=Xt)throw new xe.InvalidArgument("Invalid transaction mode: "+e);s=Xt}if(r){if(r.mode===Gt&&s===Xt){if(!i)throw new xe.SubTransaction("Cannot enter a sub-transaction with READWRITE mode when parent transaction is READONLY");r=null}r&&o.forEach((e=>{if(r&&-1===r.storeNames.indexOf(e)){if(!i)throw new xe.SubTransaction("Table "+e+" not included in parent transaction.");r=null}})),i&&r&&!r.active&&(r=null)}}catch(e){return r?r._promise(null,((t,n)=>{n(e)})):Ft(e)}const a=rr.bind(null,this,s,o,r,n);return r?r._promise(s,a,"lock"):Xe.trans?At(Xe.transless,(()=>this._whenReady(a))):this._whenReady(a)}table(e){if(!A(this._allTables,e))throw new xe.InvalidTable(`Table ${e} does not exist`);return this._allTables[e]}}const br="undefined"!=typeof Symbol&&"observable"in Symbol?Symbol.observable:"@@observable";class wr{constructor(e){this._subscribe=e}subscribe(e,t,n){return this._subscribe(e&&"function"!=typeof e?e:{next:e,error:t,complete:n})}[br](){return this}}function _r(e,t){return P(t).forEach((n=>{fr(e[n]||(e[n]=new hr),t[n])})),e}let xr;try{xr={indexedDB:E.indexedDB||E.mozIndexedDB||E.webkitIndexedDB||E.msIndexedDB,IDBKeyRange:E.IDBKeyRange||E.webkitIDBKeyRange}}catch(n){xr={indexedDB:null,IDBKeyRange:null}}const kr=gr;function Sr(e){let t=Er;try{Er=!0,Cn.storagemutated.fire(e)}finally{Er=t}}I(kr,{...Se,delete:e=>new kr(e,{addons:[]}).delete(),exists:e=>new kr(e,{addons:[]}).open().then((e=>(e.close(),!0))).catch("NoSuchDatabaseError",(()=>!1)),getDatabaseNames(e){try{return function({indexedDB:e,IDBKeyRange:t}){return Xn(e)?Promise.resolve(e.databases()).then((e=>e.map((e=>e.name)).filter((e=>e!==Yt)))):Gn(e,t).toCollection().primaryKeys()}(kr.dependencies).then(e)}catch(e){return Ft(new xe.MissingAPI)}},defineClass:()=>function(e){K(this,e)},ignoreTransaction:e=>Xe.trans?At(Xe.transless,e):e(),vip:Jn,async:function(e){return function(){try{var t=tr(e.apply(this,arguments));return t&&"function"==typeof t.then?t:tt.resolve(t)}catch(e){return Ft(e)}}},spawn:function(e,t,n){try{var r=tr(e.apply(n,t||[]));return r&&"function"==typeof r.then?r:tt.resolve(r)}catch(e){return Ft(e)}},currentTransaction:{get:()=>Xe.trans||null},waitFor:function(e,t){const n=tt.resolve("function"==typeof e?kr.ignoreTransaction(e):e).timeout(t||6e4);return Xe.trans?Xe.trans.waitFor(n):n},Promise:tt,debug:{get:()=>ae,set:e=>{ue(e,"dexie"===e?()=>!0:Qt)}},derive:R,extend:K,props:I,override:q,Events:nn,on:Cn,liveQuery:function(e){return new wr((t=>{const n=oe(e);let r=!1,i={},s={};const o={get closed(){return r},unsubscribe:()=>{r=!0,Cn.storagemutated.unsubscribe(l)}};t.start&&t.start(o);let a=!1,u=!1;function c(){return P(s).some((e=>i[e]&&function(e,t){const n=pr(t);let r=n.next();if(r.done)return!1;let i=r.value;const s=pr(e);let o=s.next(i.from),a=o.value;for(;!r.done&&!o.done;){if(dn(a.from,i.to)<=0&&dn(a.to,i.from)>=0)return!0;dn(i.from,a.from)<0?i=(r=n.next(a.from)).value:a=(o=s.next(i.from)).value}return!1}(i[e],s[e])))}const l=e=>{_r(i,e),c()&&h()},h=()=>{if(a||r)return;i={};const d={},f=function(t){n&&St();const r=()=>kt(e,{subscr:t,trans:null}),i=Xe.trans?At(Xe.transless,r):r();return n&&i.then(Et,Et),i}(d);u||(Cn(Kn,l),u=!0),a=!0,Promise.resolve(f).then((e=>{a=!1,r||(c()?h():(i={},s=d,t.next&&t.next(e)))}),(e=>{a=!1,t.error&&t.error(e),o.unsubscribe()}))};return h(),o}))},extendObservabilitySet:_r,getByKeyPath:W,setByKeyPath:z,delByKeyPath:function(e,t){"string"==typeof t?z(e,t,void 0):"length"in t&&[].map.call(t,(function(t){z(e,t,void 0)}))},shallowClone:H,deepClone:J,getObjectDiff:or,cmp:dn,asap:$,minKey:Ut,addons:[],connections:Wt,errnames:we,dependencies:xr,semVer:Nt,version:Nt.split(".").map((e=>parseInt(e))).reduce(((e,t,n)=>e+t/Math.pow(10,2*n)))}),kr.maxKey=Rn(kr.dependencies.IDBKeyRange),"undefined"!=typeof dispatchEvent&&"undefined"!=typeof addEventListener&&(Cn(Kn,(e=>{if(!Er){let t;zt?(t=document.createEvent("CustomEvent"),t.initCustomEvent(jn,!0,!0,e)):t=new CustomEvent(jn,{detail:e}),Er=!0,dispatchEvent(t),Er=!1}})),addEventListener(jn,(({detail:e})=>{Er||Sr(e)})));let Er=!1;if("undefined"!=typeof BroadcastChannel){const e=new BroadcastChannel(jn);Cn(Kn,(t=>{Er||e.postMessage(t)})),e.onmessage=e=>{e.data&&Sr(e.data)}}else if("undefined"!=typeof self&&"undefined"!=typeof navigator){Cn(Kn,(e=>{try{Er||("undefined"!=typeof localStorage&&localStorage.setItem(jn,JSON.stringify({trig:Math.random(),changedParts:e})),"object"==typeof self.clients&&[...self.clients.matchAll({includeUncontrolled:!0})].forEach((t=>t.postMessage({type:jn,changedParts:e}))))}catch(e){}})),addEventListener("storage",(e=>{if(e.key===jn){const t=JSON.parse(e.newValue);t&&Sr(t.changedParts)}}));const e=self.document&&navigator.serviceWorker;e&&e.addEventListener("message",(function({data:e}){e&&e.type===jn&&Sr(e.changedParts)}))}tt.rejectionMapper=function(e,t){if(!e||e instanceof me||e instanceof TypeError||e instanceof SyntaxError||!e.name||!ke[e.name])return e;var n=new ke[e.name](t||e.message,e);return"stack"in e&&T(n,"stack",{get:function(){return this.inner.stack}}),n},ue(ae,Qt);var Pr=s(766),Or=s(685);const Kr=new class extends gr{constructor(){super("EsmOffline"),this.version(3).stores({syncQueue:"++id,userId,type,[userId+type]"}),this.syncQueue=this.table("syncQueue")}},jr={};function Cr(){return Kr}const Ar=(0,Or.createGlobalStore)("offline-synchronization",{});function Ir(){return Ar}async function Dr(){if(Ar.getState().synchronization)return;const e=await Kr.syncQueue.count(),t={},n=Object.entries(jr),r=n.length,i={},s=new AbortController,o=()=>{const e=Ar.getState().synchronization;Ar.setState({synchronization:{...e,pendingCount:e.pendingCount-1}})};try{Ar.setState({synchronization:{totalCount:e,pendingCount:e,abortController:s}});for(let e=0;e<r&&n.length>0;e++)for(let e=n.length;e--;){const[r,a]=n[e],u=a.dependsOn.map((e=>t[e]));u.every(Boolean)&&(i[r]={},await Promise.all(u),t[r]=Tr(a,i,s,o),n.splice(e,1))}await Promise.allSettled(Object.values(t))}finally{Ar.setState({synchronization:void 0})}}async function Tr(e,t,n,r){let{type:i,dependsOn:s,process:o}=e;const a=Kr.syncQueue,u=[],c=[],l=await Rr();await a.where({type:i,userId:l}).each(((e,t)=>{u.push([t.primaryKey,e.content,e.descriptor]),c.push(e.content)}));for(let e=0;e<u.length;e++){const[h,d,{id:f,dependencies:p=[]}]=u[e];try{const u=await o(d,{abort:n,index:e,items:c,userId:l,dependencies:p.map((e=>{let{id:n,type:r}=e;return s.includes(r)?t[r][n]:void 0}))});void 0!==f&&(t[i][f]=u),await a.delete(h)}catch(e){await a.update(h,{lastError:{name:e?.name,message:e?.message??e?.toString()}})}finally{r()}}}async function Rr(){return(await(0,Pr.getLoggedInUser)())?.uuid||"*"}async function Br(e,t,n,r){const i=Kr.syncQueue,s=r&&r.id;return void 0!==s&&await i.where({type:t,userId:e}).filter((e=>e?.descriptor.id===s)).delete(),await i.add({type:t,content:n,userId:e,descriptor:r||{},createdOn:new Date})}async function Fr(e,t,n){const r=await Rr();return await Br(r,e,t,n)}async function Mr(e,t){const n=Kr.syncQueue,r=[];return await n.where({type:t,userId:e}).each((e=>{r.push(e.content)})),r}async function Nr(e){const t=await Rr();return await Mr(t,e)}async function qr(e){return await Kr.syncQueue.get(e)}function Ur(e){return!!jr[e]?.options.onBeginEditSyncItem}async function $r(e){const t=await qr(e);if(!t)throw new Error(`No sync item with the ID ${e} exists.`);const n=jr[t.type]?.options.onBeginEditSyncItem;if(!n)throw new Error(`A sync item with the ID ${e} exists, but the associated handler (if one exists) doesn't support editing the item. You can avoid this error by either verifying that sync items of this type can be edited via the "canEditSynchronizationItemsOfType(type: string)" function or alternatively ensure that the synchronizaton handler for sync items of type "${t.type}" supports editing items.`);n(t)}async function Lr(e){await Kr.syncQueue.delete(e)}function Wr(e,t,n){let r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};jr[e]={type:e,dependsOn:t,process:n,options:r}}var zr,Hr=new Uint8Array(16);function Vr(){if(!zr&&!(zr="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return zr(Hr)}const Qr=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i,Yr=function(e){return"string"==typeof e&&Qr.test(e)};for(var Gr=[],Xr=0;Xr<256;++Xr)Gr.push((Xr+256).toString(16).substr(1));const Jr=function(e,t,n){var r=(e=e||{}).random||(e.rng||Vr)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(var i=0;i<16;++i)t[n+i]=r[i];return t}return function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(Gr[e[t+0]]+Gr[e[t+1]]+Gr[e[t+2]]+Gr[e[t+3]]+"-"+Gr[e[t+4]]+Gr[e[t+5]]+"-"+Gr[e[t+6]]+Gr[e[t+7]]+"-"+Gr[e[t+8]]+Gr[e[t+9]]+"-"+Gr[e[t+10]]+Gr[e[t+11]]+Gr[e[t+12]]+Gr[e[t+13]]+Gr[e[t+14]]+Gr[e[t+15]]).toLowerCase();if(!Yr(n))throw TypeError("Stringified UUID is invalid");return n}(r)},Zr="OFFLINE+";function ei(){return Zr+Jr()}function ti(e){return e.startsWith(Zr)}const ni=(0,Or.createGlobalStore)("offline-patients",{offlinePatientDataSyncState:{},handlers:{}});function ri(){return ni}function ii(e,t){const n=ni.getState();ni.setState({handlers:{...n.handlers,[e]:t}})}async function si(e){const t=Object.entries(ni.getState().handlers),n=t.map((e=>{let[t]=e;return t})),r=[],i=[],s={},o=new AbortController;await oi(e,{timestamp:new Date,syncingHandlers:n,syncedHandlers:r,failedHandlers:i,errors:s,abort:()=>(o.abort(),!0)}),await Promise.all(t.map((async t=>{let[n,a]=t;try{await a.onOfflinePatientAdded({patientUuid:e,signal:o.signal}),console.debug(`Offline patient handler ${n} successfully synchronized patient data.`),r.push(n)}catch(e){console.error(`Offline patient handler ${n} failed. Error: `,e),i.push(n),s[n]=e?.message??e?.toString()??""}}))),await oi(e,{timestamp:new Date,syncingHandlers:[],syncedHandlers:r,failedHandlers:i,errors:s,abort:()=>!1})}async function oi(e,t){const n=ni.getState();ni.setState({offlinePatientDataSyncState:{...n.offlinePatientDataSyncState,[e]:t}});const r=new ui,i={id:(await r.offlinePatientDataSyncStates.get({patientUuid:e}))?.id,patientUuid:e,state:{timestamp:t.timestamp,syncedHandlers:t.syncedHandlers,failedHandlers:[...t.failedHandlers,...t.syncingHandlers],errors:t.errors}};await r.offlinePatientDataSyncStates.put(i)}async function ai(){const e=new ui,t=await e.offlinePatientDataSyncStates.toArray(),n=ni.getState().offlinePatientDataSyncState;for(const e of t)n[e.patientUuid]={...e.state,syncingHandlers:[],abort:()=>!1};ni.setState({offlinePatientDataSyncState:n})}class ui extends gr{constructor(){super("EsmOfflinePatientData"),this.version(1).stores({offlinePatientDataSyncStates:"++id,&patientUuid"}),this.offlinePatientDataSyncStates=this.table("offlinePatientDataSyncStates")}}})(),o})())}}}));
|
|
2
2
|
//# sourceMappingURL=openmrs-esm-offline.js.map
|