@openmrs/esm-offline 3.2.0 → 3.2.1-pre.1015
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/index.ts +1 -0
- package/src/mode.ts +79 -0
- 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,{activateOfflineCapability:()=>K,beginEditSynchronizationItem:()=>Mr,canBeginEditSynchronizationItemsOfType:()=>Br,deleteSynchronizationItem:()=>Fr,dispatchNetworkRequestFailed:()=>x,generateOfflineUuid:()=>Yr,getCurrentOfflineMode:()=>P,getOfflineDb:()=>Er,getOfflinePatientDataStore:()=>Jr,getOfflineSynchronizationStore:()=>Or,getOmrsServiceWorker:()=>y,getSynchronizationItem:()=>Tr,getSynchronizationItems:()=>Rr,getSynchronizationItemsFor:()=>Dr,isOfflineUuid:()=>Gr,loadPersistedPatientDataSyncState:()=>ni,messageOmrsServiceWorker:()=>b,offlineUuidPrefix:()=>Qr,omrsOfflineCachingStrategyHttpHeaderName:()=>g,omrsOfflineResponseBodyHttpHeaderName:()=>m,omrsOfflineResponseStatusHttpHeaderName:()=>v,patchXMLHttpRequest:()=>C,queueSynchronizationItem:()=>Ir,queueSynchronizationItemFor:()=>Ar,registerOfflinePatientHandler:()=>Zr,registerOmrsServiceWorker:()=>p,runSynchronization:()=>Kr,setCurrentOfflineMode:()=>O,setupOfflineSync:()=>Nr,subscribeNetworkRequestFailed:()=>k,syncOfflinePatientData:()=>ei});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)}const S="openmrs3:offline-mode";let E="unavailable";function P(){return{current:E,notAvailable:"unavailable"===E,active:"on"===E}}function O(e){"unavailable"!==E&&"unavailable"!==e&&(localStorage.setItem(S,"on"===e?"active":"disabled"),E=e)}async function K(){await async function(){return await async function(){return new Promise((e=>{const t=indexedDB.open("test");t.onerror=()=>e(!0),t.onsuccess=()=>e(!1)}))}()||await async function(){return!window.indexedDB}()||await async function(){const e=window.sessionStorage;try{e.setItem("someKeyHere","test"),e.removeItem("someKeyHere")}catch(t){if(t.code===DOMException.QUOTA_EXCEEDED_ERR&&0===e.length)return!0}return!1}()}()||(E="active"===localStorage.getItem(S)?"on":"off"),navigator.onLine}function C(){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 j="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:global,A=Object.keys,I=Array.isArray;function D(e,t){return"object"!=typeof t||A(t).forEach((function(n){e[n]=t[n]})),e}"undefined"==typeof Promise||j.Promise||(j.Promise=Promise);const R=Object.getPrototypeOf,T={}.hasOwnProperty;function B(e,t){return T.call(e,t)}function M(e,t){"function"==typeof t&&(t=t(R(e))),("undefined"==typeof Reflect?A:Reflect.ownKeys)(t).forEach((n=>{N(e,n,t[n])}))}const F=Object.defineProperty;function N(e,t,n,r){F(e,t,D(n&&B(n,"get")&&"function"==typeof n.get?{get:n.get,set:n.set,configurable:!0}:{value:n,configurable:!0,writable:!0},r))}function q(e){return{from:function(t){return e.prototype=Object.create(t.prototype),N(e.prototype,"constructor",e),{extend:M.bind(null,e.prototype)}}}}const L=Object.getOwnPropertyDescriptor;function U(e,t){let n;return L(e,t)||(n=R(e))&&U(n,t)}const $=[].slice;function W(e,t,n){return $.call(e,t,n)}function z(e,t){return t(e)}function H(e){if(!e)throw new Error("Assertion Failed")}function V(e){j.setImmediate?setImmediate(e):setTimeout(e,0)}function Q(e,t){return e.reduce(((e,n,r)=>{var i=t(n,r);return i&&(e[i[0]]=i[1]),e}),{})}function Y(e,t){if(B(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=Y(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:Y(a,t.substr(o+1))}}function G(e,t,n){if(e&&void 0!==t&&(!("isFrozen"in Object)||!Object.isFrozen(e)))if("string"!=typeof t&&"length"in t){H("string"!=typeof n&&"length"in n);for(var r=0,i=t.length;r<i;++r)G(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?I(e)&&!isNaN(parseInt(o))?e.splice(o,1):delete e[o]:e[o]=n;else{var u=e[o];u||(u=e[o]={}),G(u,a,n)}}else void 0===n?I(e)&&!isNaN(parseInt(t))?e.splice(t,1):delete e[t]:e[t]=n}}function X(e){var t={};for(var n in e)B(e,n)&&(t[n]=e[n]);return t}const J=[].concat;function Z(e){return J.apply([],e)}const ee="Boolean,String,Date,RegExp,Blob,File,FileList,FileSystemFileHandle,ArrayBuffer,DataView,Uint8ClampedArray,ImageBitmap,ImageData,Map,Set,CryptoKey".split(",").concat(Z([8,16,32,64].map((e=>["Int","Uint","Float"].map((t=>t+e+"Array")))))).filter((e=>j[e])),te=ee.map((e=>j[e]));Q(ee,(e=>[e,!0]));let ne=null;function re(e){ne="undefined"!=typeof WeakMap&&new WeakMap;const t=ie(e);return ne=null,t}function ie(e){if(!e||"object"!=typeof e)return e;let t=ne&&ne.get(e);if(t)return t;if(I(e)){t=[],ne&&ne.set(e,t);for(var n=0,r=e.length;n<r;++n)t.push(ie(e[n]))}else if(te.indexOf(e.constructor)>=0)t=e;else{const n=R(e);for(var i in t=n===Object.prototype?{}:Object.create(n),ne&&ne.set(e,t),e)B(e,i)&&(t[i]=ie(e[i]))}return t}const{toString:se}={};function oe(e){return se.call(e).slice(8,-1)}const ae="undefined"!=typeof Symbol?Symbol.iterator:"@@iterator",ue="symbol"==typeof ae?function(e){var t;return null!=e&&(t=e[ae])&&t.apply(e)}:function(){return null},ce={};function le(e){var t,n,r,i;if(1===arguments.length){if(I(e))return e.slice();if(this===ce&&"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}const he="undefined"!=typeof Symbol?e=>"AsyncFunction"===e[Symbol.toStringTag]:()=>!1;var de="undefined"!=typeof location&&/^(http|https):\/\/(localhost|127\.0\.0\.1)/.test(location.href);function fe(e,t){de=e,pe=t}var pe=()=>!0;const ye=!new Error("").stack;function me(){if(ye)try{throw me.arguments,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(pe).map((e=>"\n"+e)).join("")):""}var ge=["Unknown","Constraint","Data","TransactionInactive","ReadOnly","Version","NotFound","InvalidState","InvalidAccess","Abort","Timeout","QuotaExceeded","Syntax","DataClone"],be=["Modify","Bulk","OpenFailed","VersionChange","Schema","Upgrade","InvalidTable","MissingAPI","NoSuchDatabase","InvalidArgument","SubTransaction","Unsupported","Internal","DatabaseClosed","PrematureCommit","ForeignAwait"].concat(ge),we={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 _e(e,t){this._e=me(),this.name=e,this.message=t}function xe(e,t){return e+". Errors: "+Object.keys(t).map((e=>t[e].toString())).filter(((e,t,n)=>n.indexOf(e)===t)).join("\n")}function ke(e,t,n,r){this._e=me(),this.failures=t,this.failedKeys=r,this.successCount=n,this.message=xe(e,t)}function Se(e,t){this._e=me(),this.name="BulkError",this.failures=Object.keys(t).map((e=>t[e])),this.failuresByPos=t,this.message=xe(e,t)}q(_e).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}}),q(ke).from(_e),q(Se).from(_e);var Ee=be.reduce(((e,t)=>(e[t]=t+"Error",e)),{});const Pe=_e;var Oe=be.reduce(((e,t)=>{var n=t+"Error";function r(e,r){this._e=me(),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=we[t]||n,this.inner=null)}return q(r).from(Pe),e[t]=r,e}),{});Oe.Syntax=SyntaxError,Oe.Type=TypeError,Oe.Range=RangeError;var Ke=ge.reduce(((e,t)=>(e[t+"Error"]=Oe[t],e)),{}),Ce=be.reduce(((e,t)=>(-1===["Syntax","Type","Range"].indexOf(t)&&(e[t+"Error"]=Oe[t]),e)),{});function je(){}function Ae(e){return e}function Ie(e,t){return null==e||e===Ae?t:function(n){return t(e(n))}}function De(e,t){return function(){e.apply(this,arguments),t.apply(this,arguments)}}function Re(e,t){return e===je?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?De(r,this.onsuccess):r),i&&(this.onerror=this.onerror?De(i,this.onerror):i),void 0!==s?s:n}}function Te(e,t){return e===je?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?De(n,this.onsuccess):n),r&&(this.onerror=this.onerror?De(r,this.onerror):r)}}function Be(e,t){return e===je?t:function(n){var r=e.apply(this,arguments);D(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?De(i,this.onsuccess):i),s&&(this.onerror=this.onerror?De(s,this.onerror):s),void 0===r?void 0===o?void 0:o:D(r,o)}}function Me(e,t){return e===je?t:function(){return!1!==t.apply(this,arguments)&&e.apply(this,arguments)}}function Fe(e,t){return e===je?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)}}Ce.ModifyError=ke,Ce.DexieError=_e,Ce.BulkError=Se;var Ne={};const[qe,Le,Ue]="undefined"==typeof Promise?[]:(()=>{let e=Promise.resolve();if("undefined"==typeof crypto||!crypto.subtle)return[e,R(e),e];const t=crypto.subtle.digest("SHA-512",new Uint8Array([0]));return[t,R(t),e]})(),$e=Le&&Le.then,We=qe&&qe.constructor,ze=!!Ue;var He=!1,Ve=Ue?()=>{Ue.then(mt)}:j.setImmediate?setImmediate.bind(null,mt):j.MutationObserver?()=>{var e=document.createElement("div");new MutationObserver((()=>{mt(),e=null})).observe(e,{attributes:!0}),e.setAttribute("i","1")}:()=>{setTimeout(mt,0)},Qe=function(e,t){rt.push([e,t]),Ge&&(Ve(),Ge=!1)},Ye=!0,Ge=!0,Xe=[],Je=[],Ze=null,et=Ae,tt={id:"global",global:!0,ref:0,unhandleds:[],onunhandled:qt,pgp:!1,env:{},finalize:function(){this.unhandleds.forEach((e=>{try{qt(e[0],e[1])}catch(e){}}))}},nt=tt,rt=[],it=0,st=[];function ot(e){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");this._listeners=[],this.onuncatched=je,this._lib=!1;var t=this._PSD=nt;if(de&&(this._stackHolder=me(),this._prev=null,this._numPrev=0),"function"!=typeof e){if(e!==Ne)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)}const at={get:function(){var e=nt,t=Pt;function n(n,r){var i=!e.global&&(e!==nt||t!==Pt);const s=i&&!jt();var o=new ot(((t,o)=>{dt(this,new ut(Ft(n,e,i,s),Ft(r,e,i,s),t,o,e))}));return de&&yt(o,this),o}return n.prototype=Ne,n},set:function(e){N(this,"then",e&&e.prototype===Ne?at:{get:function(){return e},set:at.set})}};function ut(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((t=>{if(null===e._state){if(t===e)throw new TypeError("A promise cannot be resolved with itself.");var n=e._lib&&vt();t&&"function"==typeof t.then?ct(e,((e,n)=>{t instanceof ot?t._then(e,n):t.then(e,n)})):(e._state=!0,e._value=t,ht(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&&vt();t=et(t),e._state=!1,e._value=t,de&&null!==t&&"object"==typeof t&&!t._promise&&function(e,t,n){try{e.apply(null,void 0)}catch(e){}}((()=>{var n=U(t,"stack");t._promise=e,N(t,"stack",{get:()=>He?n&&(n.get?n.get.apply(t):n.value):e.stack})})),function(e){Xe.some((t=>t._value===e._value))||Xe.push(e)}(e),ht(e),n&>()}}function ht(e){var t=e._listeners;e._listeners=[];for(var n=0,r=t.length;n<r;++n)dt(e,t[n]);var i=e._PSD;--i.ref||i.finalize(),0===it&&(++it,Qe((()=>{0==--it&&bt()}),[]))}function dt(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(ft,[n,e,t])}else e._listeners.push(t)}function ft(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=Xe.length;t;)if(Xe[--t]._value===e._value)return void Xe.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,s,o=e._value;null!=o?(i=o.name||"Error",s=o.message||o,r=ve(o,0)):(i=o,s=""),t.push(i+(s?": "+s:"")+r)}return de&&((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 mt(){vt()&>()}function vt(){var e=Ye;return Ye=!1,Ge=!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,Ge=!0}function bt(){var e=Xe;Xe=[],e.forEach((e=>{e._PSD.onunhandled.call(null,e._value,e)}));for(var t=st.slice(0),n=t.length;n;)t[--n]()}function wt(e){return new ot(Ne,!1,e)}function _t(e,t){var n=nt;return function(){var r=vt(),i=nt;try{return Rt(n,!0),e.apply(this,arguments)}catch(e){t&&t(e)}finally{Rt(i,!1),r&>()}}}M(ot.prototype,{then:at,_then:function(e,t){dt(this,new ut(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,(e=>e instanceof t?n(e):wt(e))):this.then(null,(e=>e&&e.name===t?n(e):wt(e)))},finally:function(e){return this.then((t=>(e(),t)),(t=>(e(),wt(t))))},stack:{get:function(){if(this._stack)return this._stack;try{He=!0;var e=pt(this,[],20).join("\nFrom previous: ");return null!==this._state&&(this._stack=e),e}finally{He=!1}}},timeout:function(e,t){return e<1/0?new ot(((n,r)=>{var i=setTimeout((()=>r(new Oe.Timeout(t))),e);this.then(n,r).finally(clearTimeout.bind(null,i))})):this}}),"undefined"!=typeof Symbol&&Symbol.toStringTag&&N(ot.prototype,Symbol.toStringTag,"Dexie.Promise"),tt.env=Tt(),M(ot,{all:function(){var e=le.apply(null,arguments).map(At);return new ot((function(t,n){0===e.length&&t([]);var r=e.length;e.forEach(((i,s)=>ot.resolve(i).then((n=>{e[s]=n,--r||t(e)}),n)))}))},resolve:e=>{if(e instanceof ot)return e;if(e&&"function"==typeof e.then)return new ot(((t,n)=>{e.then(t,n)}));var t=new ot(Ne,!0,e);return yt(t,Ze),t},reject:wt,race:function(){var e=le.apply(null,arguments).map(At);return new ot(((t,n)=>{e.map((e=>ot.resolve(e).then(t,n)))}))},PSD:{get:()=>nt,set:e=>nt=e},totalEchoes:{get:()=>Pt},newPSD:Kt,usePSD:Bt,scheduler:{get:()=>Qe,set:e=>{Qe=e}},rejectionMapper:{get:()=>et,set:e=>{et=e}},follow:(e,t)=>new ot(((n,r)=>Kt(((t,n)=>{var r=nt;r.unhandleds=[],r.onunhandled=n,r.finalize=De((function(){!function(e){st.push((function t(){e(),st.splice(st.indexOf(t),1)})),++it,Qe((()=>{0==--it&&bt()}),[])}((()=>{0===this.unhandleds.length?t():n(this.unhandleds[0])}))}),r.finalize),e()}),t,n,r)))}),We&&(We.allSettled&&N(ot,"allSettled",(function(){const e=le.apply(null,arguments).map(At);return new ot((t=>{0===e.length&&t([]);let n=e.length;const r=new Array(n);e.forEach(((e,i)=>ot.resolve(e).then((e=>r[i]={status:"fulfilled",value:e}),(e=>r[i]={status:"rejected",reason:e})).then((()=>--n||t(r)))))}))})),We.any&&"undefined"!=typeof AggregateError&&N(ot,"any",(function(){const e=le.apply(null,arguments).map(At);return new ot(((t,n)=>{0===e.length&&n(new AggregateError([]));let r=e.length;const i=new Array(r);e.forEach(((e,s)=>ot.resolve(e).then((e=>t(e)),(e=>{i[s]=e,--r||n(new AggregateError(i))}))))}))})));const xt={awaits:0,echoes:0,id:0};var kt=0,St=[],Et=0,Pt=0,Ot=0;function Kt(e,t,n,r){var i=nt,s=Object.create(i);s.parent=i,s.ref=0,s.global=!1,s.id=++Ot;var o=tt.env;s.env=ze?{Promise:ot,PromiseProp:{value:ot,configurable:!0,writable:!0},all:ot.all,race:ot.race,allSettled:ot.allSettled,any:ot.any,resolve:ot.resolve,reject:ot.reject,nthen:Nt(o.nthen,s),gthen:Nt(o.gthen,s)}:{},t&&D(s,t),++i.ref,s.finalize=function(){--this.parent.ref||this.parent.finalize()};var a=Bt(s,e,n,r);return 0===s.ref&&s.finalize(),a}function Ct(){return xt.id||(xt.id=++kt),++xt.awaits,xt.echoes+=100,xt.id}function jt(){return!!xt.awaits&&(0==--xt.awaits&&(xt.id=0),xt.echoes=100*xt.awaits,!0)}function At(e){return xt.echoes&&e&&e.constructor===We?(Ct(),e.then((e=>(jt(),e)),(e=>(jt(),Lt(e))))):e}function It(e){++Pt,xt.echoes&&0!=--xt.echoes||(xt.echoes=xt.id=0),St.push(nt),Rt(e,!0)}function Dt(){var e=St[St.length-1];St.pop(),Rt(e,!1)}function Rt(e,t){var n=nt;if((t?!xt.echoes||Et++&&e===nt:!Et||--Et&&e===nt)||Mt(t?It.bind(null,e):Dt),e!==nt&&(nt=e,n===tt&&(tt.env=Tt()),ze)){var r=tt.env.Promise,i=e.env;Le.then=i.nthen,r.prototype.then=i.gthen,(n.global||e.global)&&(Object.defineProperty(j,"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 Tt(){var e=j.Promise;return ze?{Promise:e,PromiseProp:Object.getOwnPropertyDescriptor(j,"Promise"),all:e.all,race:e.race,allSettled:e.allSettled,any:e.any,resolve:e.resolve,reject:e.reject,nthen:Le.then,gthen:e.prototype.then}:{}}function Bt(e,t,n,r,i){var s=nt;try{return Rt(e,!0),t(n,r,i)}finally{Rt(s,!1)}}function Mt(e){$e.call(qe,e)}function Ft(e,t,n,r){return"function"!=typeof e?e:function(){var i=nt;n&&Ct(),Rt(t,!0);try{return e.apply(this,arguments)}finally{Rt(i,!1),r&&Mt(jt)}}}function Nt(e,t){return function(n,r){return e.call(this,Ft(n,t),Ft(r,t))}}function qt(e,t){var n;try{n=t.onuncatched(e)}catch(e){}if(!1!==n)try{var r,i={promise:t,reason:e};if(j.document&&document.createEvent?((r=document.createEvent("Event")).initEvent("unhandledrejection",!0,!0),D(r,i)):j.CustomEvent&&D(r=new CustomEvent("unhandledrejection",{detail:i}),i),r&&j.dispatchEvent&&(dispatchEvent(r),!j.PromiseRejectionEvent&&j.onunhandledrejection))try{j.onunhandledrejection(r)}catch(e){}de&&r&&!r.defaultPrevented&&console.warn(`Unhandled rejection: ${e.stack||e}`)}catch(e){}}-1===(""+$e).indexOf("[native code]")&&(Ct=jt=je);var Lt=ot.reject;function Ut(e,t,n,r){if(e.idbdb&&(e._state.openComplete||nt.letThrough||e._vip)){var i=e._createTransaction(t,n,e._dbSchema);try{i.create(),e._state.PR1398_maxLoop=3}catch(i){return i.name===Ee.InvalidState&&e.isOpen()&&--e._state.PR1398_maxLoop>0?(console.warn("Dexie: Need to reopen db"),e._close(),e.open().then((()=>Ut(e,t,n,r)))):Lt(i)}return i._promise(t,((e,t)=>Kt((()=>(nt.trans=i,r(e,t,i)))))).then((e=>i._completion.then((()=>e))))}if(e._state.openComplete)return Lt(new Oe.DatabaseClosed(e._state.dbOpenError));if(!e._state.isBeingOpened){if(!e._options.autoOpen)return Lt(new Oe.DatabaseClosed);e.open().catch(je)}return e._state.dbReadyPromise.then((()=>Ut(e,t,n,r)))}const $t=String.fromCharCode(65535),Wt="Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.",zt=[],Ht="undefined"!=typeof navigator&&/(MSIE|Trident|Edge)/.test(navigator.userAgent),Vt=Ht,Qt=Ht,Yt=e=>!/(dexie\.js|dexie\.min\.js)/.test(e);function Gt(e,t){return e?t?function(){return e.apply(this,arguments)&&t.apply(this,arguments)}:e:t}const Xt={type:3,lower:-1/0,lowerOpen:!1,upper:[[]],upperOpen:!1};function Jt(e){return"string"!=typeof e||/\./.test(e)?e=>e:t=>(void 0===t[e]&&e in t&&delete(t=re(t))[e],t)}class Zt{_trans(e,t,n){const r=this._tx||nt.trans,i=this.name;function s(e,n,r){if(!r.schema[i])throw new Oe.NotFound("Table "+i+" not part of transaction");return t(r.idbtrans,r)}const o=vt();try{return r&&r.db===this.db?r===nt.trans?r._promise(e,s,n):Kt((()=>r._promise(e,s,n)),{trans:r,transless:nt.transless||nt}):Ut(this.db,e,[this.name],s)}finally{o&>()}}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(I(e))return new this.db.WhereClause(this,`[${e.join("+")}]`);const t=A(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!==$t)return this.where(n.name).equals(n.keyPath.map((t=>e[t])));!n&&de&&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?Gt(n,o&&o.multi?e=>{const t=Y(e,i);return I(t)&&t.some((e=>s(a,e)))}:e=>s(a,Y(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,I(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(B(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){D(this,e)}))}add(e,t){const{auto:n,keyPath:r}=this.schema.primKey;let i=e;return r&&n&&(i=Jt(r)(e)),this._trans("readwrite",(e=>this.core.mutate({trans:e,type:"add",keys:null!=t?[t]:null,values:[i]}))).then((e=>e.numFailures?ot.reject(e.failures[0]):e.lastResult)).then((t=>{if(r)try{G(e,r,t)}catch(e){}return t}))}update(e,t){if("object"!=typeof e||I(e))return this.where(":id").equals(e).modify(t);{const n=Y(e,this.schema.primKey.keyPath);if(void 0===n)return Lt(new Oe.InvalidArgument("Given object does not contain its primary key"));try{"function"!=typeof t?A(t).forEach((n=>{G(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=Jt(r)(e)),this._trans("readwrite",(e=>this.core.mutate({trans:e,type:"put",values:[i],keys:null!=t?[t]:null}))).then((e=>e.numFailures?ot.reject(e.failures[0]):e.lastResult)).then((t=>{if(r)try{G(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?ot.reject(e.failures[0]):void 0))}clear(){return this._trans("readwrite",(e=>this.core.mutate({trans:e,type:"deleteRange",range:Xt}))).then((e=>e.numFailures?ot.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 Oe.InvalidArgument("bulkAdd(): keys argument invalid on tables with inbound keys");if(r&&r.length!==e.length)throw new Oe.InvalidArgument("Arguments objects and keys must have the same length");const o=e.length;let a=s&&n?e.map(Jt(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 Se(`${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 Oe.InvalidArgument("bulkPut(): keys argument invalid on tables with inbound keys");if(r&&r.length!==e.length)throw new Oe.InvalidArgument("Arguments objects and keys must have the same length");const o=e.length;let a=s&&n?e.map(Jt(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 Se(`${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 Se(`${this.name}.bulkDelete(): ${e} of ${t} operations failed`,r)}))}}function en(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=Me),i||(i=je);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){A(e).forEach((function(t){var n=e[t];if(I(n))s(t,e[t][0],e[t][1]);else{if("asap"!==n)throw new Oe.InvalidArgument("Invalid event config");var r=s(t,Ae,(function(){for(var e=arguments.length,t=new Array(e);e--;)t[e]=arguments[e];r.subscribers.forEach((function(e){V((function(){e.apply(null,t)}))}))}))}}))}}function tn(e,t){return q(t).from({prototype:e}),t}function nn(e,t){return!(e.filter||e.algorithm||e.or)&&(t?e.justLimit:!e.replayFilter)}function rn(e,t){e.filter=Gt(e.filter,t)}function sn(e,t,n){var r=e.replayFilter;e.replayFilter=r?()=>Gt(r(),t()):t,e.justLimit=n&&!r}function on(e,t){if(e.isPrimKey)return t.primaryKey;const n=t.getIndexByKeyPath(e.index);if(!n)throw new Oe.Schema("KeyPath "+e.index+" on object store "+t.name+" is not indexed");return n}function an(e,t,n){const r=on(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 un(e,t,n,r){const i=e.replayFilter?Gt(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)),B(s,a)||(s[a]=!0,t(e,n,r))}};return Promise.all([e.or._iterate(o,n),cn(an(e,r,n),e.algorithm,o,!e.keysOnly&&e.valueMapper)])}return cn(an(e,r,n),Gt(e.algorithm,i),t,!e.keysOnly&&e.valueMapper)}function cn(e,t,n,r){var i=_t(r?(e,t,i)=>n(r(e),t,i):n);return e.then((e=>{if(e)return e.start((()=>{var n=()=>e.continue();t&&!t(e,(e=>n=e),(t=>{e.stop(t),n=je}),(t=>{e.fail(t),n=je}))||i(e.value,e,(e=>n=e)),n()}))}))}function ln(e,t){try{const n=hn(e),r=hn(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}(dn(e),dn(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=ln(e[n],t[n]);if(0!==r)return r}return n===r?0:n<r?-1:1}(e,t)}}catch(e){}return NaN}function hn(e){const t=typeof e;if("object"!==t)return t;if(ArrayBuffer.isView(e))return"binary";const n=oe(e);return"ArrayBuffer"===n?"binary":n}function dn(e){return e instanceof Uint8Array?e:ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e)}class fn{_read(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)}_write(e){var t=this._ctx;return t.error?t.table._trans(null,Lt.bind(null,t.error)):t.table._trans("readwrite",e,"locked")}_addAlgorithm(e){var t=this._ctx;t.algorithm=Gt(t.algorithm,e)}_iterate(e,t){return un(this._ctx,e,t,this._ctx.table.core)}clone(e){var t=Object.create(this.constructor.prototype),n=Object.create(this._ctx);return e&&D(n,e),t._ctx=n,t}raw(){return this._ctx.valueMapper=null,this}each(e){var t=this._ctx;return this._read((n=>un(t,e,n,t.table.core)))}count(e){return this._read((e=>{const t=this._ctx,n=t.table.core;if(nn(t,!0))return n.count({trans:e,query:{index:on(t,n.schema),range:t.range}}).then((e=>Math.min(e,t.limit)));var r=0;return un(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&&nn(t,!0)&&t.limit>0){const{valueMapper:n}=t,r=on(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 un(t,(e=>n.push(e)),e,t.table.core).then((()=>n))}}),e)}offset(e){var t=this._ctx;return e<=0||(t.offset+=e,nn(t)?sn(t,(()=>{var t=e;return(e,n)=>0===t||(1===t?(--t,!1):(n((()=>{e.advance(t),t=0})),!1))})):sn(t,(()=>{var t=e;return()=>--t<0}))),this}limit(e){return this._ctx.limit=Math.min(this._ctx.limit,e),sn(this._ctx,(()=>{var t=e;return function(e,n,r){return--t<=0&&n(r),t>=0}}),!0),this}until(e,t){return rn(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 rn(this._ctx,(function(t){return e(t.value)})),t=this._ctx,n=e,t.isMatch=Gt(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&&nn(t,!0)&&t.limit>0)return this._read((e=>{var n=on(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 rn(this._ctx,(function(e){var t=e.primaryKey.toString(),r=B(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=A(e),s=i.length;r=function(t){for(var n=!1,r=0;r<s;++r){var o=i[r],a=e[o];Y(t,o)!==a&&(G(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 A(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:re(t),primKey:i[l+e]};!1!==r.call(n,n.value,n)&&(null==n.value?v.push(i[l+e]):a||0===ln(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=nn(t)&&t.limit===1/0&&("function"!=typeof e||e===pn)&&{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===pn)&&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 ke("Error modifying one or more objects",l,h,d);return i.length}))}))}))}delete(){var e=this._ctx,t=e.range;return nn(e)&&(e.isPrimKey&&!Qt||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 ke("Could not delete some values",Object.keys(e).map((t=>e[t])),t-i);return t-i}))))})):this.modify(pn)}}const pn=(e,t)=>t.value=null;function yn(e,t){return e<t?-1:e===t?0:1}function mn(e,t){return e>t?-1:e===t?0:1}function vn(e,t,n){var r=e instanceof kn?new e.Collection(e):e;return r._ctx.error=n?new n(t):new TypeError(t),r}function gn(e){return new e.Collection(e,(()=>xn(""))).limit(0)}function bn(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 wn(e,t,n,r){var i,s,o,a,u,c,l,h=n.length;if(!n.every((e=>"string"==typeof e)))return vn(e,"String expected.");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?yn:mn;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,(()=>_n(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=bn(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 _n(e,t,n,r){return{type:2,lower:e,upper:t,lowerOpen:n,upperOpen:r}}function xn(e){return{type:1,lower:e,upper:e}}class kn{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)?gn(this):new this.Collection(this,(()=>_n(e,t,!n,!r)))}catch(e){return vn(this,Wt)}}equals(e){return null==e?vn(this,Wt):new this.Collection(this,(()=>xn(e)))}above(e){return null==e?vn(this,Wt):new this.Collection(this,(()=>_n(e,void 0,!0)))}aboveOrEqual(e){return null==e?vn(this,Wt):new this.Collection(this,(()=>_n(e,void 0,!1)))}below(e){return null==e?vn(this,Wt):new this.Collection(this,(()=>_n(void 0,e,!1,!0)))}belowOrEqual(e){return null==e?vn(this,Wt):new this.Collection(this,(()=>_n(void 0,e)))}startsWith(e){return"string"!=typeof e?vn(this,"String expected."):this.between(e,e+$t,!0,!0)}startsWithIgnoreCase(e){return""===e?this.startsWith(e):wn(this,((e,t)=>0===e.indexOf(t[0])),[e],$t)}equalsIgnoreCase(e){return wn(this,((e,t)=>e===t[0]),[e],"")}anyOfIgnoreCase(){var e=le.apply(ce,arguments);return 0===e.length?gn(this):wn(this,((e,t)=>-1!==t.indexOf(e)),e,"")}startsWithAnyOfIgnoreCase(){var e=le.apply(ce,arguments);return 0===e.length?gn(this):wn(this,((e,t)=>t.some((t=>0===e.indexOf(t)))),e,$t)}anyOf(){const e=le.apply(ce,arguments);let t=this._cmp;try{e.sort(t)}catch(e){return vn(this,Wt)}if(0===e.length)return gn(this);const n=new this.Collection(this,(()=>_n(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([[-1/0,e],[e,this.db._maxKey]],{includeLowers:!1,includeUppers:!1})}noneOf(){const e=le.apply(ce,arguments);if(0===e.length)return new this.Collection(this);try{e.sort(this._ascending)}catch(e){return vn(this,Wt)}const t=e.reduce(((e,t)=>e?e.concat([[e[e.length-1][1],t]]):[[-1/0,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 gn(this);if(!e.every((e=>void 0!==e[0]&&void 0!==e[1]&&r(e[0],e[1])<=0)))return vn(this,"First argument to inAnyRange() must be an Array of two-value Arrays [lower,upper] where upper must not be lower than lower",Oe.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 vn(this,Wt)}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,(()=>_n(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=le.apply(ce,arguments);return e.every((e=>"string"==typeof e))?0===e.length?gn(this):this.inAnyRange(e.map((e=>[e,e+$t]))):vn(this,"startsWithAnyOf() only works with strings")}}function Sn(e){return _t((function(t){return En(t),e(t.target.error),!1}))}function En(e){e.stopPropagation&&e.stopPropagation(),e.preventDefault&&e.preventDefault()}const Pn=en(null,"storagemutated");class On{_lock(){return H(!nt.global),++this._reculock,1!==this._reculock||nt.global||(nt.lockOwnerFor=this),this}_unlock(){if(H(!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}_locked(){return this._reculock&&nt.lockOwnerFor!==this}create(e){if(!this.mode)return this;const t=this.db.idbdb,n=this.db._state.dbOpenError;if(H(!this.idbtrans),!e&&!t)switch(n&&n.name){case"DatabaseClosedError":throw new Oe.DatabaseClosed(n);case"MissingAPIError":throw new Oe.MissingAPI(n.message,n);default:throw new Oe.OpenFailed(n)}if(!this.active)throw new Oe.TransactionInactive;return H(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=_t((t=>{En(t),this._reject(e.error)})),e.onabort=_t((t=>{En(t),this.active&&this._reject(new Oe.Abort(e.error)),this.active=!1,this.on("abort").fire(t)})),e.oncomplete=_t((()=>{this.active=!1,this._resolve(),"mutatedParts"in e&&Pn.storagemutated.fire(e.mutatedParts)})),this}_promise(e,t,n){if("readwrite"===e&&"readwrite"!==this.mode)return Lt(new Oe.ReadOnly("Transaction is readonly"));if(!this.active)return Lt(new Oe.TransactionInactive);if(this._locked())return new ot(((r,i)=>{this._blockedFuncs.push([()=>{this._promise(e,t,n).then(r,i)},nt])}));if(n)return Kt((()=>{var e=new ot(((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 ot(((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=ot.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 ot(((e,r)=>{n.then((n=>t._waitingQueue.push(_t(e.bind(null,n)))),(e=>t._waitingQueue.push(_t(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 Oe.Abort))}table(e){const t=this._memoizedTables||(this._memoizedTables={});if(B(t,e))return t[e];const n=this.schema[e];if(!n)throw new Oe.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 Kn(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?"++":"")+Cn(t)}}function Cn(e){return"string"==typeof e?e:e?"["+[].join.call(e,"+")+"]":""}function jn(e,t,n){return{name:e,primKey:t,indexes:n,mappedClass:null,idxByName:Q(n,(e=>[e.name,e]))}}let An=e=>{try{return e.only([[]]),An=()=>[[]],[[]]}catch(e){return An=()=>$t,$t}};function In(e){return null==e?()=>{}:"string"==typeof e?function(e){return 1===e.split(".").length?t=>t[e]:t=>Y(t,e)}(e):t=>Y(t,e)}function Dn(e){return[].slice.call(e)}let Rn=0;function Tn(e){return null==e?":id":"string"==typeof e?e:`[${e.join("+")}]`}function Bn({_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=Dn(e.objectStoreNames);return{schema:{name:e.name,tables:n.map((e=>t.objectStore(e))).map((e=>{const{keyPath:t,autoIncrement:n}=e,r=I(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:In(t)},indexes:Dn(e.indexNames).map((t=>e.index(t))).map((e=>{const{name:t,unique:n,multiEntry:r,keyPath:i}=e,o={name:t,compound:I(i),keyPath:i,unique:n,multiEntry:r,extractKey:In(i)};return s[Tn(i)]=o,o})),getIndexByKeyPath:e=>s[Tn(e)]};return s[":id"]=o.primaryKey,null!=t&&(s[Tn(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=_t(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,En(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=_t(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=Sn(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=_t(r);const s=e.objectStore(t).get(n);s.onsuccess=e=>r(e.target.result),s.onerror=Sn(i)})),query:function(e){return n=>new Promise(((i,s)=>{i=_t(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=Sn(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=Sn(s)}}))}(s),openCursor:function({trans:e,values:n,query:i,reverse:s,unique:o}){return new Promise(((a,u)=>{a=_t(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=Sn(u),p.onsuccess=_t((t=>{const n=p.result;if(!n)return void a(null);n.___id=++Rn,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=_t(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=_t(e),p.onerror=Sn(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=_t((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=_t((t=>e(t.target.result))),l.onerror=Sn(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:An(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 Mn({_novip:e},t,n,r){n.forEach((n=>{const i=r[n];t.forEach((t=>{const r=U(t,n);(!r||"value"in r&&void 0===r.value)&&(t===e.Transaction.prototype||t instanceof e.Transaction?N(t,n,{get(){return this.table(n)},set(e){F(this,n,{value:e,writable:!0,configurable:!0,enumerable:!0})}}):t[n]=new e.Table(n,i))}))}))}function Fn({_novip:e},t){t.forEach((t=>{for(let n in t)t[n]instanceof e.Table&&delete t[n]}))}function Nn(e,t){return e._cfg.version-t._cfg.version}function qn(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&&!Ht)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 Ln(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=>Un(i,e))),i}function Un(e,t){e.createIndex(t.name,t.keyPath,{unique:t.unique,multiEntry:t.multi})}function $n(e,t,n){const r={};return W(t.objectStoreNames,0).forEach((e=>{const t=n.objectStore(e);let i=t.keyPath;const s=Kn(Cn(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=Kn(n.name,i,!!n.unique,!!n.multiEntry,!1,i&&"string"!=typeof i,!1);o.push(a)}r[e]=jn(e,s,o)})),r}function Wn({_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:"["+W(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)&&j.WorkerGlobalScope&&j instanceof j.WorkerGlobalScope&&[].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1]<604&&(e._hasGetAll=!1)}class zn{_parseStoresSpec(e,t){A(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 Kn(n,r||null,/\&/.test(e),/\*/.test(e),/\+\+/.test(e),I(r),0===t)})),i=r.shift();if(i.multi)throw new Oe.Schema("Primary key cannot be multi-valued");r.forEach((e=>{if(e.auto)throw new Oe.Schema("Only primary key can be marked as autoIncrement (++)");if(!e.keyPath)throw new Oe.Schema("Index must have a name and cannot be an empty string")})),t[n]=jn(n,i,r)}}))}stores(e){const t=this.db;this._cfg.storesSource=this._cfg.storesSource?D(this._cfg.storesSource,e):e;const n=t._versions,r={};let i={};return n.forEach((e=>{D(r,e._cfg.storesSource),i=e._cfg.dbschema={},e._parseStoresSpec(r,i)})),t._dbSchema=i,Fn(t,[t._allTables,t,t.Transaction.prototype]),Mn(t,[t._allTables,t,t.Transaction.prototype,this._cfg.tables],A(i),i),t._storeNames=A(i),this}upgrade(e){return this._cfg.contentUpgrade=Fe(this._cfg.contentUpgrade||je,e),this}}function Hn(e,t){let n=e._dbNamesDB;return n||(n=e._dbNamesDB=new fr("__dbnames",{addons:[],indexedDB:e,IDBKeyRange:t}),n.version(1).stores({dbnames:"name"})),n.table("dbnames")}function Vn(e){return e&&"function"==typeof e.databases}function Qn(e){return Kt((function(){return nt.letThrough=!0,e()}))}function Yn(){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 Gn(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):I(s)?Promise.all(s).then(n,r):n(s)}}return i(t)()}function Xn(e,t,n){var r=arguments.length;if(r<2)throw new Oe.InvalidArgument("Too few arguments");for(var i=new Array(r-1);--r;)i[r-1]=arguments[r];n=i.pop();var s=Z(i);return[e,s,n]}function Jn(e,t,n,r,i){return ot.resolve().then((()=>{const s=nt.transless||nt,o=e._createTransaction(t,n,e._dbSchema,r),a={trans:o,transless:s};if(r)o.idbtrans=r.idbtrans;else try{o.create(),e._state.PR1398_maxLoop=3}catch(r){return r.name===Ee.InvalidState&&e.isOpen()&&--e._state.PR1398_maxLoop>0?(console.warn("Dexie: Need to reopen db"),e._close(),e.open().then((()=>Jn(e,t,n,null,i)))):Lt(r)}const u=he(i);let c;u&&Ct();const l=ot.follow((()=>{if(c=i.call(o,o),c)if(u){var e=jt.bind(null,null);c.then(e,e)}else"function"==typeof c.next&&"function"==typeof c.throw&&(c=Gn(c))}),a);return(c&&"function"==typeof c.then?ot.resolve(c).then((e=>o.active?e:Lt(new Oe.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),Lt(e))))}))}function Zn(e,t,n){const r=I(e)?e.slice():[e];for(let e=0;e<n;++e)r.push(t);return r}const er={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=Tn(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:In(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:Zn(r.lower,r.lowerOpen?e.MAX_KEY:e.MIN_KEY,i),lowerOpen:!0,upper:Zn(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[Tn(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(Zn(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(Zn(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 tr(e,t,n,r){return n=n||{},r=r||"",A(e).forEach((i=>{if(B(t,i)){var s=e[i],o=t[i];if("object"==typeof s&&"object"==typeof o&&s&&o){const e=oe(s);e!==oe(o)?n[r+i]=t[i]:"Object"===e?tr(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})),A(t).forEach((i=>{B(e,i)||(n[r+i]=t[i])})),n}const nr={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=nt.trans,{deleting:s,creating:o,updating:a}=i.table(t).hook;switch(e.type){case"add":if(o.fire===je)break;return i._promise("readwrite",(()=>u(e)),!0);case"put":if(o.fire===je&&a.fire===je)break;return i._promise("readwrite",(()=>u(e)),!0);case"delete":if(s.fire===je)break;return i._promise("readwrite",(()=>u(e)),!0);case"deleteRange":if(s.fire===je)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=nt.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||G(e.values[i],r.keyPath,n))}else{const r=tr(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=>{B(t,e)?t[e]=s[e]:G(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 rr(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===ln(t.keys[i],e[s])&&(r.push(n?re(t.values[i]):t.values[i]),++s);return r.length===e.length?r:null}catch(e){return null}}const ir={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=rr(e.keys,e.trans._cache,"clone"===e.cache);return t?ot.resolve(t):n.getMany(e).then((t=>(e.trans._cache={keys:e.keys,values:"clone"===e.cache?re(t):t},t)))},mutate:e=>("add"!==e.type&&(e.trans._cache=null),n.mutate(e))}}})};function sr(e){return!("from"in e)}const or=function(e,t){if(!this){const t=new or;return e&&"d"in e&&D(t,e),t}D(this,arguments.length?{d:1,from:e,to:arguments.length>1?t:e}:{d:0})};function ar(e,t,n){const r=ln(t,n);if(isNaN(r))return;if(r>0)throw RangeError();if(sr(e))return D(e,{from:t,to:n,d:1});const i=e.l,s=e.r;if(ln(n,e.from)<0)return i?ar(i,t,n):e.l={from:t,to:n,d:1,l:null,r:null},lr(e);if(ln(t,e.to)>0)return s?ar(s,t,n):e.r={from:t,to:n,d:1,l:null,r:null},lr(e);ln(t,e.from)<0&&(e.from=t,e.l=null,e.d=s?s.d+1:1),ln(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&&ur(e,i),s&&o&&ur(e,s)}function ur(e,t){sr(t)||function e(t,{from:n,to:r,l:i,r:s}){ar(t,n,r),i&&e(t,i),s&&e(t,s)}(e,t)}function cr(e){let t=sr(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&&ln(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||ln(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 lr(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=hr(n)}e.d=hr(e)}function hr({r:e,l:t}){return(e?t?Math.max(e.d,t.d):e.d:t?t.d:0)+1}M(or.prototype,{add(e){return ur(this,e),this},addKey(e){return ar(this,e,e),this},addKeys(e){return e.forEach((e=>ar(this,e,e))),this},[ae](){return cr(this)}});const dr={stack:"dbcore",level:0,create:e=>{const t=e.schema.name,n=new or(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 or)},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(I(d)){"delete"!==h&&(d=e.results),c.addKeys(d);const t=rr(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&&I(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!==ln(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 or(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 or(e.key)],getMany:e=>[o,(new or).addKeys(e.keys)],count:l,query:l,openCursor:l};return A(h).forEach((e=>{c[e]=function(s){const{subscr:o}=nt;if(o){const c=e=>{const n=`idb://${t}/${r}/${e}`;return o[n]||(o[n]=new or)},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 fr{constructor(e,t){this._middlewares={},this.verno=0;const n=fr.dependencies;this._options=t={addons:fr.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:je,dbReadyPromise:null,cancelOpen:je,openCanceller:null,autoSchema:!0,PR1398_maxLoop:3};var s;i.dbReadyPromise=new ot((e=>{i.dbReadyResolve=e})),i.openCanceller=new ot(((e,t)=>{i.cancelOpen=t})),this._state=i,this.name=e,this.on=en(this,"populate","blocked","versionchange","close",{ready:[Fe,je]}),this.on.ready.subscribe=z(this.on.ready.subscribe,(e=>(t,n)=>{fr.vip((()=>{const r=this._state;if(r.openComplete)r.dbOpenError||ot.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=(s=this,tn(fn.prototype,(function(e,t){this.db=s;let n=Xt,r=null;if(t)try{n=t()}catch(e){r=e}const i=e._ctx,o=i.table,a=o.hook.reading.fire;this._ctx={table:o,index:i.index,isPrimKey:!i.index||o.schema.primKey.keyPath&&i.index===o.schema.primKey.name,range:n,keysOnly:!1,dir:"next",unique:"",algorithm:null,filter:null,replayFilter:null,justLimit:!0,isMatch:null,offset:0,limit:1/0,error:r,or:i.or,valueMapper:a!==Ae?a:null}}))),this.Table=function(e){return tn(Zt.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:en(null,{creating:[Re,je],reading:[Ie,Ae],updating:[Be,je],deleting:[Te,je]})}))}(this),this.Transaction=function(e){return tn(On.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=en(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 ot(((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(),Lt(e)}))}))}(this),this.Version=function(e){return tn(zn.prototype,(function(t){this.db=e,this._cfg={version:t,storesSource:null,dbschema:{},tables:{},contentUpgrade:null}}))}(this),this.WhereClause=function(e){return tn(kn.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 Oe.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=An(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),zt.filter((e=>e.name===this.name&&e!==this&&!e._state.vcFired)).map((t=>t.on("versionchange").fire(e)))},this.use(er),this.use(nr),this.use(dr),this.use(ir),this.vip=Object.create(this,{_vip:{value:!0}}),r.forEach((e=>e(this)))}version(e){if(isNaN(e)||e<.1)throw new Oe.Type("Given version is not a positive number");if(e=Math.round(10*e)/10,this.idbdb||this._state.isBeingOpened)throw new Oe.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(Nn),n.stores({}),this._state.autoSchema=!1,n)}_whenReady(e){return this.idbdb&&(this._state.openComplete||nt.letThrough||this._vip)?e():new ot(((e,t)=>{if(this._state.openComplete)return t(new Oe.DatabaseClosed(this._state.dbOpenError));if(!this._state.isBeingOpened){if(!this._options.autoOpen)return void t(new Oe.DatabaseClosed);this.open().catch(je)}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 function(e){const t=e._state,{indexedDB:n}=e._deps;if(t.isBeingOpened||e.idbdb)return t.dbReadyPromise.then((()=>t.dbOpenError?Lt(t.dbOpenError):e));de&&(t.openCanceller._stackHolder=me()),t.isBeingOpened=!0,t.dbOpenError=null,t.openComplete=!1;const r=t.openCanceller;function i(){if(t.openCanceller!==r)throw new Oe.DatabaseClosed("db.open() was cancelled")}let s=t.dbReadyResolve,o=null,a=!1;return ot.race([r,("undefined"==typeof navigator?ot.resolve():Yn()).then((()=>new ot(((r,s)=>{if(i(),!n)throw new Oe.MissingAPI;const u=e.name,c=t.autoSchema?n.open(u):n.open(u,Math.round(10*e.verno));if(!c)throw new Oe.MissingAPI;c.onerror=Sn(s),c.onblocked=_t(e._fireOnBlocked),c.onupgradeneeded=_t((r=>{if(o=c.transaction,t.autoSchema&&!e._options.allowEmptyDB){c.onerror=En,o.abort(),c.result.close();const e=n.deleteDatabase(u);e.onsuccess=e.onerror=_t((()=>{s(new Oe.NoSuchDatabase(`Database ${u} doesnt exist`))}))}else{o.onerror=Sn(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=nt.transless||nt;Kt((()=>{nt.trans=s,nt.transless=a,0===t?(A(i).forEach((e=>{Ln(n,e,i[e].primKey,i[e].indexes)})),Bn(e,n),ot.follow((()=>e.on.populate.fire(s))).catch(o)):function({_novip:e},t,n,r){const i=[],s=e._versions;let o=e._dbSchema=$n(0,e.idbdb,r),a=!1;return s.filter((e=>e._cfg.version>=t)).forEach((s=>{i.push((()=>{const i=o,u=s._cfg.dbschema;Wn(e,i,r),Wn(e,u,r),o=e._dbSchema=u;const c=qn(i,u);c.add.forEach((e=>{Ln(r,e[0],e[1].primKey,e[1].indexes)})),c.change.forEach((e=>{if(e.recreate)throw new Oe.Upgrade("Not yet support for changing primary key");{const t=r.objectStore(e.name);e.add.forEach((e=>Un(t,e))),e.change.forEach((e=>{t.deleteIndex(e.name),Un(t,e)})),e.del.forEach((e=>t.deleteIndex(e)))}}));const l=s._cfg.contentUpgrade;if(l&&s._cfg.version>t){Bn(e,r),n._memoizedTables={},a=!0;let t=X(u);c.del.forEach((e=>{t[e]=i[e]})),Fn(e,[e.Transaction.prototype]),Mn(e,[e.Transaction.prototype],A(t),t),n.schema=t;const s=he(l);let o;s&&Ct();const h=ot.follow((()=>{if(o=l(n),o&&s){var e=jt.bind(null,null);o.then(e,e)}}));return o&&"function"==typeof o.then?ot.resolve(o):h.then((()=>o))}})),i.push((t=>{a&&Vt||function(e,t){[].slice.call(t.db.objectStoreNames).forEach((n=>null==e[n]&&t.db.deleteObjectStore(n)))}(s._cfg.dbschema,t),Fn(e,[e.Transaction.prototype]),Mn(e,[e.Transaction.prototype],e._storeNames,e._dbSchema),n.schema=e._dbSchema}))})),function e(){return i.length?ot.resolve(i.shift()(n.idbtrans)).then(e):ot.resolve()}().then((()=>{var e,t;t=r,A(e=o).forEach((n=>{t.db.objectStoreNames.contains(n)||Ln(t,n,e[n].primKey,e[n].indexes)}))}))}(e,t,s,n).catch(o)}))}(e,i/10,o,s)}}),s),c.onsuccess=_t((()=>{o=null;const n=e._novip.idbdb=c.result,i=W(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=$n(0,t,n);e._storeNames=W(t.objectStoreNames,0),Mn(e,[e._allTables],A(r),r)}(e,n,r):(Wn(e,e._dbSchema,r),function(e,t){const n=qn($n(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.")),Bn(e,r)}catch(e){}var s;zt.push(e),n.onversionchange=_t((n=>{t.vcFired=!0,e.on("versionchange").fire(n)})),n.onclose=_t((t=>{e.on("close").fire(t)})),a&&function({indexedDB:e,IDBKeyRange:t},n){!Vn(e)&&"__dbnames"!==n&&Hn(e,t).put({name:n}).catch(je)}(e._deps,u),r()}),s)}))))]).then((()=>(i(),t.onReadyBeingFired=[],ot.resolve(Qn((()=>e.on.ready.fire(e.vip)))).then((function n(){if(t.onReadyBeingFired.length>0){let r=t.onReadyBeingFired.reduce(Fe,je);return t.onReadyBeingFired=[],ot.resolve(Qn((()=>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(),Lt(n)})).finally((()=>{t.openComplete=!0,s()}))}(this)}_close(){const e=this._state,t=zt.indexOf(this);if(t>=0&&zt.splice(t,1),this.idbdb){try{this.idbdb.close()}catch(e){}this._novip.idbdb=null}e.dbReadyPromise=new ot((t=>{e.dbReadyResolve=t})),e.openCanceller=new ot(((t,n)=>{e.cancelOpen=n}))}close(){this._close();const e=this._state;this._options.autoOpen=!1,e.dbOpenError=new Oe.DatabaseClosed,e.isBeingOpened&&e.cancelOpen(e.dbOpenError)}delete(){const e=arguments.length>0,t=this._state;return new ot(((n,r)=>{const i=()=>{this.close();var e=this._deps.indexedDB.deleteDatabase(this.name);e.onsuccess=_t((()=>{!function({indexedDB:e,IDBKeyRange:t},n){!Vn(e)&&"__dbnames"!==n&&Hn(e,t).delete(n).catch(je)}(this._deps,this.name),n()})),e.onerror=Sn(r),e.onblocked=this._fireOnBlocked};if(e)throw new Oe.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 A(this._allTables).map((e=>this._allTables[e]))}transaction(){const e=Xn.apply(this,arguments);return this._transaction.apply(this,e)}_transaction(e,t,n){let r=nt.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||"readonly"===e)s="readonly";else{if("rw"!=e&&"readwrite"!=e)throw new Oe.InvalidArgument("Invalid transaction mode: "+e);s="readwrite"}if(r){if("readonly"===r.mode&&"readwrite"===s){if(!i)throw new Oe.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 Oe.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)})):Lt(e)}const a=Jn.bind(null,this,s,o,r,n);return r?r._promise(s,a,"lock"):nt.trans?Bt(nt.transless,(()=>this._whenReady(a))):this._whenReady(a)}table(e){if(!B(this._allTables,e))throw new Oe.InvalidTable(`Table ${e} does not exist`);return this._allTables[e]}}const pr="undefined"!=typeof Symbol&&"observable"in Symbol?Symbol.observable:"@@observable";class yr{constructor(e){this._subscribe=e}subscribe(e,t,n){return this._subscribe(e&&"function"!=typeof e?e:{next:e,error:t,complete:n})}[pr](){return this}}function mr(e,t){return A(t).forEach((n=>{ur(e[n]||(e[n]=new or),t[n])})),e}let vr;try{vr={indexedDB:j.indexedDB||j.mozIndexedDB||j.webkitIndexedDB||j.msIndexedDB,IDBKeyRange:j.IDBKeyRange||j.webkitIDBKeyRange}}catch(n){vr={indexedDB:null,IDBKeyRange:null}}const gr=fr;function br(e){let t=wr;try{wr=!0,Pn.storagemutated.fire(e)}finally{wr=t}}M(gr,{...Ce,delete:e=>new gr(e,{addons:[]}).delete(),exists:e=>new gr(e,{addons:[]}).open().then((e=>(e.close(),!0))).catch("NoSuchDatabaseError",(()=>!1)),getDatabaseNames(e){try{return function({indexedDB:e,IDBKeyRange:t}){return Vn(e)?Promise.resolve(e.databases()).then((e=>e.map((e=>e.name)).filter((e=>"__dbnames"!==e)))):Hn(e,t).toCollection().primaryKeys()}(gr.dependencies).then(e)}catch(e){return Lt(new Oe.MissingAPI)}},defineClass:()=>function(e){D(this,e)},ignoreTransaction:e=>nt.trans?Bt(nt.transless,e):e(),vip:Qn,async:function(e){return function(){try{var t=Gn(e.apply(this,arguments));return t&&"function"==typeof t.then?t:ot.resolve(t)}catch(e){return Lt(e)}}},spawn:function(e,t,n){try{var r=Gn(e.apply(n,t||[]));return r&&"function"==typeof r.then?r:ot.resolve(r)}catch(e){return Lt(e)}},currentTransaction:{get:()=>nt.trans||null},waitFor:function(e,t){const n=ot.resolve("function"==typeof e?gr.ignoreTransaction(e):e).timeout(t||6e4);return nt.trans?nt.trans.waitFor(n):n},Promise:ot,debug:{get:()=>de,set:e=>{fe(e,"dexie"===e?()=>!0:Yt)}},derive:q,extend:D,props:M,override:z,Events:en,on:Pn,liveQuery:function(e){return new yr((t=>{const n=he(e);let r=!1,i={},s={};const o={get closed(){return r},unsubscribe:()=>{r=!0,Pn.storagemutated.unsubscribe(l)}};t.start&&t.start(o);let a=!1,u=!1;function c(){return A(s).some((e=>i[e]&&function(e,t){const n=cr(t);let r=n.next();if(r.done)return!1;let i=r.value;const s=cr(e);let o=s.next(i.from),a=o.value;for(;!r.done&&!o.done;){if(ln(a.from,i.to)<=0&&ln(a.to,i.from)>=0)return!0;ln(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=>{mr(i,e),c()&&h()},h=()=>{if(a||r)return;i={};const d={},f=function(t){n&&Ct();const r=()=>Kt(e,{subscr:t,trans:null}),i=nt.trans?Bt(nt.transless,r):r();return n&&i.then(jt,jt),i}(d);u||(Pn("storagemutated",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:mr,getByKeyPath:Y,setByKeyPath:G,delByKeyPath:function(e,t){"string"==typeof t?G(e,t,void 0):"length"in t&&[].map.call(t,(function(t){G(e,t,void 0)}))},shallowClone:X,deepClone:re,getObjectDiff:tr,cmp:ln,asap:V,minKey:-1/0,addons:[],connections:zt,errnames:Ee,dependencies:vr,semVer:"3.2.1",version:"3.2.1".split(".").map((e=>parseInt(e))).reduce(((e,t,n)=>e+t/Math.pow(10,2*n)))}),gr.maxKey=An(gr.dependencies.IDBKeyRange),"undefined"!=typeof dispatchEvent&&"undefined"!=typeof addEventListener&&(Pn("storagemutated",(e=>{if(!wr){let t;Ht?(t=document.createEvent("CustomEvent"),t.initCustomEvent("x-storagemutated-1",!0,!0,e)):t=new CustomEvent("x-storagemutated-1",{detail:e}),wr=!0,dispatchEvent(t),wr=!1}})),addEventListener("x-storagemutated-1",(({detail:e})=>{wr||br(e)})));let wr=!1;if("undefined"!=typeof BroadcastChannel){const e=new BroadcastChannel("x-storagemutated-1");Pn("storagemutated",(t=>{wr||e.postMessage(t)})),e.onmessage=e=>{e.data&&br(e.data)}}else if("undefined"!=typeof self&&"undefined"!=typeof navigator){Pn("storagemutated",(e=>{try{wr||("undefined"!=typeof localStorage&&localStorage.setItem("x-storagemutated-1",JSON.stringify({trig:Math.random(),changedParts:e})),"object"==typeof self.clients&&[...self.clients.matchAll({includeUncontrolled:!0})].forEach((t=>t.postMessage({type:"x-storagemutated-1",changedParts:e}))))}catch(e){}})),addEventListener("storage",(e=>{if("x-storagemutated-1"===e.key){const t=JSON.parse(e.newValue);t&&br(t.changedParts)}}));const e=self.document&&navigator.serviceWorker;e&&e.addEventListener("message",(function({data:e}){e&&"x-storagemutated-1"===e.type&&br(e.changedParts)}))}ot.rejectionMapper=function(e,t){if(!e||e instanceof _e||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&&N(n,"stack",{get:function(){return this.inner.stack}}),n},fe(de,Yt);var _r=s(766),xr=s(685);const kr=new class extends fr{constructor(){super("EsmOffline"),this.version(3).stores({syncQueue:"++id,userId,type,[userId+type]"}),this.syncQueue=this.table("syncQueue")}},Sr={};function Er(){return kr}const Pr=(0,xr.createGlobalStore)("offline-synchronization",{});function Or(){return Pr}async function Kr(){if(Pr.getState().synchronization)return;const e=await kr.syncQueue.count(),t={},n=Object.entries(Sr),r=n.length,i={},s=new AbortController,o=()=>{const e=Pr.getState().synchronization;Pr.setState({synchronization:{...e,pendingCount:e.pendingCount-1}})};try{Pr.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]=Cr(a,i,s,o),n.splice(e,1))}await Promise.allSettled(Object.values(t))}finally{Pr.setState({synchronization:void 0})}}async function Cr(e,t,n,r){let{type:i,dependsOn:s,process:o}=e;const a=kr.syncQueue,u=[],c=[],l=await jr();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 jr(){return(await(0,_r.getLoggedInUser)())?.uuid||"*"}async function Ar(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 Ir(e,t,n){const r=await jr();return await Ar(r,e,t,n)}async function Dr(e,t){const n=kr.syncQueue,r=[];return await n.where({type:t,userId:e}).each((e=>{r.push(e.content)})),r}async function Rr(e){const t=await jr();return await Dr(t,e)}async function Tr(e){return await kr.syncQueue.get(e)}function Br(e){return!!Sr[e]?.options.onBeginEditSyncItem}async function Mr(e){const t=await Tr(e);if(!t)throw new Error(`No sync item with the ID ${e} exists.`);const n=Sr[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 Fr(e){await kr.syncQueue.delete(e)}function Nr(e,t,n){let r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};Sr[e]={type:e,dependsOn:t,process:n,options:r}}var qr,Lr=new Uint8Array(16);function Ur(){if(!qr&&!(qr="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 qr(Lr)}const $r=/^(?:[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,Wr=function(e){return"string"==typeof e&&$r.test(e)};for(var zr=[],Hr=0;Hr<256;++Hr)zr.push((Hr+256).toString(16).substr(1));const Vr=function(e,t,n){var r=(e=e||{}).random||(e.rng||Ur)();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=(zr[e[t+0]]+zr[e[t+1]]+zr[e[t+2]]+zr[e[t+3]]+"-"+zr[e[t+4]]+zr[e[t+5]]+"-"+zr[e[t+6]]+zr[e[t+7]]+"-"+zr[e[t+8]]+zr[e[t+9]]+"-"+zr[e[t+10]]+zr[e[t+11]]+zr[e[t+12]]+zr[e[t+13]]+zr[e[t+14]]+zr[e[t+15]]).toLowerCase();if(!Wr(n))throw TypeError("Stringified UUID is invalid");return n}(r)},Qr="OFFLINE+";function Yr(){return Qr+Vr()}function Gr(e){return e.startsWith(Qr)}const Xr=(0,xr.createGlobalStore)("offline-patients",{offlinePatientDataSyncState:{},handlers:{}});function Jr(){return Xr}function Zr(e,t){const n=Xr.getState();Xr.setState({handlers:{...n.handlers,[e]:t}})}async function ei(e){const t=Object.entries(Xr.getState().handlers),n=t.map((e=>{let[t]=e;return t})),r=[],i=[],s={},o=new AbortController;await ti(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 ti(e,{timestamp:new Date,syncingHandlers:[],syncedHandlers:r,failedHandlers:i,errors:s,abort:()=>!1})}async function ti(e,t){const n=Xr.getState();Xr.setState({offlinePatientDataSyncState:{...n.offlinePatientDataSyncState,[e]:t}});const r=new ri,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 ni(){const e=new ri,t=await e.offlinePatientDataSyncStates.toArray(),n=Xr.getState().offlinePatientDataSyncState;for(const e of t)n[e.patientUuid]={...e.state,syncingHandlers:[],abort:()=>!1};Xr.setState({offlinePatientDataSyncState:n})}class ri extends fr{constructor(){super("EsmOfflinePatientData"),this.version(1).stores({offlinePatientDataSyncStates:"++id,&patientUuid"}),this.offlinePatientDataSyncStates=this.table("offlinePatientDataSyncStates")}}})(),o})())}}}));
|
|
2
2
|
//# sourceMappingURL=openmrs-esm-offline.js.map
|