7 lines
70 KiB
JavaScript
7 lines
70 KiB
JavaScript
var e=function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n],t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},e.apply(this,arguments)};function t(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;for(var r=Array(e),i=0,t=0;t<n;t++)for(var a=arguments[t],o=0,s=a.length;o<s;o++,i++)r[i]=a[o];return r}var n=Object.keys,r=Array.isArray,i=typeof self<`u`?self:typeof window<`u`?window:global;typeof Promise<`u`&&!i.Promise&&(i.Promise=Promise);function a(e,t){return typeof t==`object`&&n(t).forEach(function(n){e[n]=t[n]}),e}var o=Object.getPrototypeOf,s={}.hasOwnProperty;function c(e,t){return s.call(e,t)}function l(e,t){typeof t==`function`&&(t=t(o(e))),n(t).forEach(function(n){d(e,n,t[n])})}var u=Object.defineProperty;function d(e,t,n,r){u(e,t,a(n&&c(n,`get`)&&typeof n.get==`function`?{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),d(e.prototype,`constructor`,e),{extend:l.bind(null,e.prototype)}}}}var p=Object.getOwnPropertyDescriptor;function m(e,t){var n=p(e,t),r;return n||(r=o(e))&&m(r,t)}var h=[].slice;function g(e,t,n){return h.call(e,t,n)}function _(e,t){return t(e)}function v(e){if(!e)throw Error(`Assertion Failed`)}function y(e){i.setImmediate?setImmediate(e):setTimeout(e,0)}function b(e,t){return e.reduce(function(e,n,r){var i=t(n,r);return i&&(e[i[0]]=i[1]),e},{})}function ee(e,t,n){try{e.apply(null,n)}catch(e){t&&t(e)}}function x(e,t){if(c(e,t))return e[t];if(!t)return e;if(typeof t!=`string`){for(var n=[],r=0,i=t.length;r<i;++r){var a=x(e,t[r]);n.push(a)}return n}var o=t.indexOf(`.`);if(o!==-1){var s=e[t.substr(0,o)];return s===void 0?void 0:x(s,t.substr(o+1))}}function S(e,t,n){if(!(!e||t===void 0)&&!(`isFrozen`in Object&&Object.isFrozen(e)))if(typeof t!=`string`&&`length`in t){v(typeof n!=`string`&&`length`in n);for(var i=0,a=t.length;i<a;++i)S(e,t[i],n[i])}else{var o=t.indexOf(`.`);if(o!==-1){var s=t.substr(0,o),c=t.substr(o+1);if(c===``)n===void 0?r(e)&&!isNaN(parseInt(s))?e.splice(s,1):delete e[s]:e[s]=n;else{var l=e[s];l||(l=e[s]={}),S(l,c,n)}}else n===void 0?r(e)&&!isNaN(parseInt(t))?e.splice(t,1):delete e[t]:e[t]=n}}function te(e,t){typeof t==`string`?S(e,t,void 0):`length`in t&&[].map.call(t,function(t){S(e,t,void 0)})}function C(e){var t={};for(var n in e)c(e,n)&&(t[n]=e[n]);return t}var ne=[].concat;function re(e){return ne.apply([],e)}var ie=`Boolean,String,Date,RegExp,Blob,File,FileList,ArrayBuffer,DataView,Uint8ClampedArray,ImageData,Map,Set`.split(`,`).concat(re([8,16,32,64].map(function(e){return[`Int`,`Uint`,`Float`].map(function(t){return t+e+`Array`})}))).filter(function(e){return i[e]}),ae=ie.map(function(e){return i[e]}),oe=b(ie,function(e){return[e,!0]});function w(e){if(!e||typeof e!=`object`)return e;var t;if(r(e)){t=[];for(var n=0,i=e.length;n<i;++n)t.push(w(e[n]))}else if(ae.indexOf(e.constructor)>=0)t=e;else for(var a in t=e.constructor?Object.create(e.constructor.prototype):{},e)c(e,a)&&(t[a]=w(e[a]));return t}var se={}.toString;function ce(e){return se.call(e).slice(8,-1)}var le=function(e,t){return t===`Array`?``+e.map(function(e){return le(e,ce(e))}):t===`ArrayBuffer`?``+new Uint8Array(e):t===`Date`?e.getTime():ArrayBuffer.isView(e)?``+new Uint8Array(e.buffer):e};function ue(e,t,r,i){return r=r||{},i=i||``,n(e).forEach(function(n){if(!c(t,n))r[i+n]=void 0;else{var a=e[n],o=t[n];if(typeof a==`object`&&typeof o==`object`&&a&&o){var s=ce(a),l=ce(o);s===l?oe[s]?le(a,s)!==le(o,l)&&(r[i+n]=t[n]):ue(a,o,r,i+n+`.`):r[i+n]=t[n]}else a!==o&&(r[i+n]=t[n])}}),n(t).forEach(function(n){c(e,n)||(r[i+n]=t[n])}),r}var de=typeof Symbol<`u`&&Symbol.iterator,fe=de?function(e){var t;return e!=null&&(t=e[de])&&t.apply(e)}:function(){return null},T={};function E(e){var t,n,i,a;if(arguments.length===1){if(r(e))return e.slice();if(this===T&&typeof e==`string`)return[e];if(a=fe(e)){for(n=[];i=a.next(),!i.done;)n.push(i.value);return n}if(e==null)return[e];if(t=e.length,typeof t==`number`){for(n=Array(t);t--;)n[t]=e[t];return n}return[e]}for(t=arguments.length,n=Array(t);t--;)n[t]=arguments[t];return n}var pe=typeof Symbol<`u`?function(e){return e[Symbol.toStringTag]===`AsyncFunction`}:function(){return!1},D=typeof location<`u`&&/^(http|https):\/\/(localhost|127\.0\.0\.1)/.test(location.href);function me(e,t){D=e,he=t}var he=function(){return!0},ge=!Error(``).stack;function O(){if(ge)try{throw Error()}catch(e){return e}return Error()}function _e(e,t){var n=e.stack;return n?(t=t||0,n.indexOf(e.name)===0&&(t+=(e.name+e.message).split(`
|
|
`).length),n.split(`
|
|
`).slice(t).filter(he).map(function(e){return`
|
|
`+e}).join(``)):``}var ve=[`Modify`,`Bulk`,`OpenFailed`,`VersionChange`,`Schema`,`Upgrade`,`InvalidTable`,`MissingAPI`,`NoSuchDatabase`,`InvalidArgument`,`SubTransaction`,`Unsupported`,`Internal`,`DatabaseClosed`,`PrematureCommit`,`ForeignAwait`],ye=[`Unknown`,`Constraint`,`Data`,`TransactionInactive`,`ReadOnly`,`Version`,`NotFound`,`InvalidState`,`InvalidAccess`,`Abort`,`Timeout`,`QuotaExceeded`,`Syntax`,`DataClone`],be=ve.concat(ye),xe={VersionChanged:`Database version changed by other database connection`,DatabaseClosed:`Database has been closed`,Abort:`Transaction aborted`,TransactionInactive:`Transaction has already completed or failed`};function k(e,t){this._e=O(),this.name=e,this.message=t}f(k).from(Error).extend({stack:{get:function(){return this._stack||(this._stack=this.name+`: `+this.message+_e(this._e,2))}},toString:function(){return this.name+`: `+this.message}});function Se(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(`
|
|
`)}function Ce(e,t,n,r){this._e=O(),this.failures=t,this.failedKeys=r,this.successCount=n,this.message=Se(e,t)}f(Ce).from(k);function we(e,t){this._e=O(),this.name=`BulkError`,this.failures=t,this.message=Se(e,t)}f(we).from(k);var Te=be.reduce(function(e,t){return e[t]=t+`Error`,e},{}),Ee=k,A=be.reduce(function(e,t){var n=t+`Error`;function r(e,r){this._e=O(),this.name=n,e?typeof e==`string`?(this.message=``+e+(r?`
|
|
`+r:``),this.inner=r||null):typeof e==`object`&&(this.message=e.name+` `+e.message,this.inner=e):(this.message=xe[t]||n,this.inner=null)}return f(r).from(Ee),e[t]=r,e},{});A.Syntax=SyntaxError,A.Type=TypeError,A.Range=RangeError;var De=ye.reduce(function(e,t){return e[t+`Error`]=A[t],e},{});function Oe(e,t){if(!e||e instanceof k||e instanceof TypeError||e instanceof SyntaxError||!e.name||!De[e.name])return e;var n=new De[e.name](t||e.message,e);return`stack`in e&&d(n,`stack`,{get:function(){return this.inner.stack}}),n}var ke=be.reduce(function(e,t){return[`Syntax`,`Type`,`Range`].indexOf(t)===-1&&(e[t+`Error`]=A[t]),e},{});ke.ModifyError=Ce,ke.DexieError=k,ke.BulkError=we;function j(){}function Ae(e){return e}function je(e,t){return e==null||e===Ae?t:function(n){return t(e(n))}}function M(e,t){return function(){e.apply(this,arguments),t.apply(this,arguments)}}function Me(e,t){return e===j?t:function(){var n=e.apply(this,arguments);n!==void 0&&(arguments[0]=n);var r=this.onsuccess,i=this.onerror;this.onsuccess=null,this.onerror=null;var a=t.apply(this,arguments);return r&&(this.onsuccess=this.onsuccess?M(r,this.onsuccess):r),i&&(this.onerror=this.onerror?M(i,this.onerror):i),a===void 0?n:a}}function Ne(e,t){return e===j?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?M(n,this.onsuccess):n),r&&(this.onerror=this.onerror?M(r,this.onerror):r)}}function Pe(e,t){return e===j?t:function(n){var r=e.apply(this,arguments);a(n,r);var i=this.onsuccess,o=this.onerror;this.onsuccess=null,this.onerror=null;var s=t.apply(this,arguments);return i&&(this.onsuccess=this.onsuccess?M(i,this.onsuccess):i),o&&(this.onerror=this.onerror?M(o,this.onerror):o),r===void 0?s===void 0?void 0:s:a(r,s)}}function Fe(e,t){return e===j?t:function(){return t.apply(this,arguments)===!1?!1:e.apply(this,arguments)}}function Ie(e,t){return e===j?t:function(){var n=e.apply(this,arguments);if(n&&typeof n.then==`function`){for(var r=this,i=arguments.length,a=Array(i);i--;)a[i]=arguments[i];return n.then(function(){return t.apply(r,a)})}return t.apply(this,arguments)}}var Le={},Re=100,ze=20,Be=100,Ve=typeof Promise>`u`?[]:(function(){var e=Promise.resolve();if(typeof crypto>`u`||!crypto.subtle)return[e,e.__proto__,e];var t=crypto.subtle.digest(`SHA-512`,new Uint8Array([0]));return[t,t.__proto__,e]})(),He=Ve[0],Ue=Ve[1],We=Ve[2],Ge=Ue&&Ue.then,Ke=He&&He.constructor,qe=!!We,Je=!1,Ye=We?function(){We.then(pt)}:i.setImmediate?setImmediate.bind(null,pt):i.MutationObserver?function(){var e=document.createElement(`div`);new MutationObserver(function(){pt(),e=null}).observe(e,{attributes:!0}),e.setAttribute(`i`,`1`)}:function(){setTimeout(pt,0)},Xe=function(e,t){nt.push([e,t]),Qe&&(Ye(),Qe=!1)},Ze=!0,Qe=!0,N=[],$e=[],et=null,tt=Ae,P={id:`global`,global:!0,ref:0,unhandleds:[],onunhandled:It,pgp:!1,env:{},finalize:function(){this.unhandleds.forEach(function(e){try{It(e[0],e[1])}catch{}})}},F=P,nt=[],I=0,rt=[];function L(e){if(typeof this!=`object`)throw TypeError(`Promises must be constructed via new`);this._listeners=[],this.onuncatched=j,this._lib=!1;var t=this._PSD=F;if(D&&(this._stackHolder=O(),this._prev=null,this._numPrev=0),typeof e!=`function`){if(e!==Le)throw TypeError(`Not a function`);this._state=arguments[1],this._value=arguments[2],this._state===!1&&st(this,this._value);return}this._state=null,this._value=null,++t.ref,ot(this,e)}var it={get:function(){var e=F,t=wt;function n(n,r){var i=this,a=!e.global&&(e!==F||t!==wt),o=a&&!V(),s=new L(function(t,s){lt(i,new at(Nt(n,e,a,o),Nt(r,e,a,o),t,s,e))});return D&&ft(s,this),s}return n.prototype=Le,n},set:function(e){d(this,`then`,e&&e.prototype===Le?it:{get:function(){return e},set:it.set})}};l(L.prototype,{then:it,_then:function(e,t){lt(this,new at(null,null,e,t,F))},catch:function(e){if(arguments.length===1)return this.then(null,e);var t=arguments[0],n=arguments[1];return typeof t==`function`?this.then(null,function(e){return e instanceof t?n(e):bt(e)}):this.then(null,function(e){return e&&e.name===t?n(e):bt(e)})},finally:function(e){return this.then(function(t){return e(),t},function(t){return e(),bt(t)})},stack:{get:function(){if(this._stack)return this._stack;try{Je=!0;var e=dt(this,[],ze).join(`
|
|
From previous: `);return this._state!==null&&(this._stack=e),e}finally{Je=!1}}},timeout:function(e,t){var n=this;return e<1/0?new L(function(r,i){var a=setTimeout(function(){return i(new A.Timeout(t))},e);n.then(r,i).finally(clearTimeout.bind(null,a))}):this}}),typeof Symbol<`u`&&Symbol.toStringTag&&d(L.prototype,Symbol.toStringTag,`Dexie.Promise`),P.env=At();function at(e,t,n,r,i){this.onFulfilled=typeof e==`function`?e:null,this.onRejected=typeof t==`function`?t:null,this.resolve=n,this.reject=r,this.psd=i}l(L,{all:function(){var e=E.apply(null,arguments).map(Dt);return new L(function(t,n){e.length===0&&t([]);var r=e.length;e.forEach(function(i,a){return L.resolve(i).then(function(n){e[a]=n,--r||t(e)},n)})})},resolve:function(e){if(e instanceof L)return e;if(e&&typeof e.then==`function`)return new L(function(t,n){e.then(t,n)});var t=new L(Le,!0,e);return ft(t,et),t},reject:bt,race:function(){var e=E.apply(null,arguments).map(Dt);return new L(function(t,n){e.map(function(e){return L.resolve(e).then(t,n)})})},PSD:{get:function(){return F},set:function(e){return F=e}},totalEchoes:{get:function(){return wt}},newPSD:B,usePSD:jt,scheduler:{get:function(){return Xe},set:function(e){Xe=e}},rejectionMapper:{get:function(){return tt},set:function(e){tt=e}},follow:function(e,t){return new L(function(n,r){return B(function(t,n){var r=F;r.unhandleds=[],r.onunhandled=n,r.finalize=M(function(){var e=this;_t(function(){e.unhandleds.length===0?t():n(e.unhandleds[0])})},r.finalize),e()},t,n,r)})}}),Ke&&(Ke.allSettled&&d(L,`allSettled`,function(){var e=E.apply(null,arguments).map(Dt);return new L(function(t){e.length===0&&t([]);var n=e.length,r=Array(n);e.forEach(function(e,i){return L.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)})})})}),Ke.any&&typeof AggregateError<`u`&&d(L,`any`,function(){var e=E.apply(null,arguments).map(Dt);return new L(function(t,n){e.length===0&&n(AggregateError([]));var r=e.length,i=Array(r);e.forEach(function(e,a){return L.resolve(e).then(function(e){return t(e)},function(e){i[a]=e,--r||n(AggregateError(i))})})})}));function ot(e,t){try{t(function(t){if(e._state===null){if(t===e)throw TypeError(`A promise cannot be resolved with itself.`);var n=e._lib&&mt();t&&typeof t.then==`function`?ot(e,function(e,n){t instanceof L?t._then(e,n):t.then(e,n)}):(e._state=!0,e._value=t,ct(e)),n&&ht()}},st.bind(null,e))}catch(t){st(e,t)}}function st(e,t){if($e.push(t),e._state===null){var n=e._lib&&mt();t=tt(t),e._state=!1,e._value=t,D&&typeof t==`object`&&t&&!t._promise&&ee(function(){var n=m(t,`stack`);t._promise=e,d(t,`stack`,{get:function(){return Je?n&&(n.get?n.get.apply(t):n.value):e.stack}})}),vt(e),ct(e),n&&ht()}}function ct(e){var t=e._listeners;e._listeners=[];for(var n=0,r=t.length;n<r;++n)lt(e,t[n]);var i=e._PSD;--i.ref||i.finalize(),I===0&&(++I,Xe(function(){--I===0&>()},[]))}function lt(e,t){if(e._state===null){e._listeners.push(t);return}var n=e._state?t.onFulfilled:t.onRejected;if(n===null)return(e._state?t.resolve:t.reject)(e._value);++t.psd.ref,++I,Xe(ut,[n,e,t])}function ut(e,t,n){try{et=t;var r,i=t._value;t._state?r=e(i):($e.length&&($e=[]),r=e(i),$e.indexOf(i)===-1&&yt(t)),n.resolve(r)}catch(e){n.reject(e)}finally{et=null,--I===0&>(),--n.psd.ref||n.psd.finalize()}}function dt(e,t,n){if(t.length===n)return t;var r=``;if(e._state===!1){var i=e._value,a,o;i==null?(a=i,o=``):(a=i.name||`Error`,o=i.message||i,r=_e(i,0)),t.push(a+(o?`: `+o:``)+r)}return D&&(r=_e(e._stackHolder,2),r&&t.indexOf(r)===-1&&t.push(r),e._prev&&dt(e._prev,t,n)),t}function ft(e,t){var n=t?t._numPrev+1:0;n<Re&&(e._prev=t,e._numPrev=n)}function pt(){mt()&&ht()}function mt(){var e=Ze;return Ze=!1,Qe=!1,e}function ht(){var e,t,n;do for(;nt.length>0;)for(e=nt,nt=[],n=e.length,t=0;t<n;++t){var r=e[t];r[0].apply(null,r[1])}while(nt.length>0);Ze=!0,Qe=!0}function gt(){var e=N;N=[],e.forEach(function(e){e._PSD.onunhandled.call(null,e._value,e)});for(var t=rt.slice(0),n=t.length;n;)t[--n]()}function _t(e){function t(){e(),rt.splice(rt.indexOf(t),1)}rt.push(t),++I,Xe(function(){--I===0&>()},[])}function vt(e){N.some(function(t){return t._value===e._value})||N.push(e)}function yt(e){for(var t=N.length;t;)if(N[--t]._value===e._value){N.splice(t,1);return}}function bt(e){return new L(Le,!1,e)}function R(e,t){var n=F;return function(){var r=mt(),i=F;try{return H(n,!0),e.apply(this,arguments)}catch(e){t&&t(e)}finally{H(i,!1),r&&ht()}}}var z={awaits:0,echoes:0,id:0},xt=0,St=[],Ct=0,wt=0,Tt=0;function B(e,t,n,r){var i=F,o=Object.create(i);o.parent=i,o.ref=0,o.global=!1,o.id=++Tt;var s=P.env;o.env=qe?{Promise:L,PromiseProp:{value:L,configurable:!0,writable:!0},all:L.all,race:L.race,allSettled:L.allSettled,any:L.any,resolve:L.resolve,reject:L.reject,nthen:Pt(s.nthen,o),gthen:Pt(s.gthen,o)}:{},t&&a(o,t),++i.ref,o.finalize=function(){--this.parent.ref||this.parent.finalize()};var c=jt(o,e,n,r);return o.ref===0&&o.finalize(),c}function Et(){return z.id||(z.id=++xt),++z.awaits,z.echoes+=Be,z.id}function V(){return z.awaits?(--z.awaits===0&&(z.id=0),z.echoes=z.awaits*Be,!0):!1}(``+Ge).indexOf(`[native code]`)===-1&&(Et=V=j);function Dt(e){return z.echoes&&e&&e.constructor===Ke?(Et(),e.then(function(e){return V(),e},function(e){return V(),U(e)})):e}function Ot(e){++wt,(!z.echoes||--z.echoes===0)&&(z.echoes=z.id=0),St.push(F),H(e,!0)}function kt(){var e=St[St.length-1];St.pop(),H(e,!1)}function H(e,t){var n=F;if((t?z.echoes&&(!Ct++||e!==F):Ct&&(!--Ct||e!==F))&&Mt(t?Ot.bind(null,e):kt),e!==F&&(F=e,n===P&&(P.env=At()),qe)){var r=P.env.Promise,a=e.env;Ue.then=a.nthen,r.prototype.then=a.gthen,(n.global||e.global)&&(Object.defineProperty(i,`Promise`,a.PromiseProp),r.all=a.all,r.race=a.race,r.resolve=a.resolve,r.reject=a.reject,a.allSettled&&(r.allSettled=a.allSettled),a.any&&(r.any=a.any))}}function At(){var e=i.Promise;return qe?{Promise:e,PromiseProp:Object.getOwnPropertyDescriptor(i,`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 jt(e,t,n,r,i){var a=F;try{return H(e,!0),t(n,r,i)}finally{H(a,!1)}}function Mt(e){Ge.call(He,e)}function Nt(e,t,n,r){return typeof e==`function`?function(){var i=F;n&&Et(),H(t,!0);try{return e.apply(this,arguments)}finally{H(i,!1),r&&Mt(V)}}:e}function Pt(e,t){return function(n,r){return e.call(this,Nt(n,t),Nt(r,t))}}var Ft=`unhandledrejection`;function It(e,t){var n;try{n=t.onuncatched(e)}catch{}if(n!==!1)try{var r,o={promise:t,reason:e};if(i.document&&document.createEvent?(r=document.createEvent(`Event`),r.initEvent(Ft,!0,!0),a(r,o)):i.CustomEvent&&(r=new CustomEvent(Ft,{detail:o}),a(r,o)),r&&i.dispatchEvent&&(dispatchEvent(r),!i.PromiseRejectionEvent&&i.onunhandledrejection))try{i.onunhandledrejection(r)}catch{}D&&r&&!r.defaultPrevented&&console.warn(`Unhandled rejection: `+(e.stack||e))}catch{}}var U=L.reject;function Lt(e,t,n,r){if(!e._state.openComplete&&!F.letThrough){if(!e._state.isBeingOpened){if(!e._options.autoOpen)return U(new A.DatabaseClosed);e.open().catch(j)}return e._state.dbReadyPromise.then(function(){return Lt(e,t,n,r)})}else{var i=e._createTransaction(t,n,e._dbSchema);try{i.create()}catch(e){return U(e)}return i._promise(t,function(e,t){return B(function(){return F.trans=i,r(e,t,i)})}).then(function(e){return i._completion.then(function(){return e})})}}var Rt=`3.0.3`,W=``,zt=-1/0,G=`Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.`,Bt=`String expected.`,Vt=[],Ht=typeof navigator<`u`&&/(MSIE|Trident|Edge)/.test(navigator.userAgent),Ut=Ht,Wt=Ht,Gt=function(e){return!/(dexie\.js|dexie\.min\.js)/.test(e)},Kt=`__dbnames`,qt=`readonly`,Jt=`readwrite`;function K(e,t){return e?t?function(){return e.apply(this,arguments)&&t.apply(this,arguments)}:e:t}var Yt={type:3,lower:-1/0,lowerOpen:!1,upper:[[]],upperOpen:!1};function Xt(e){return function(t){return x(t,e)===void 0&&(t=w(t),te(t,e)),t}}var Zt=function(){function e(){}return e.prototype._trans=function(e,t,n){var r=this._tx||F.trans,i=this.name;function a(e,n,r){if(!r.schema[i])throw new A.NotFound(`Table `+i+` not part of transaction`);return t(r.idbtrans,r)}var o=mt();try{return r&&r.db===this.db?r===F.trans?r._promise(e,a,n):B(function(){return r._promise(e,a,n)},{trans:r,transless:F.transless||F}):Lt(this.db,e,[this.name],a)}finally{o&&ht()}},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(typeof e==`string`)return new this.db.WhereClause(this,e);if(r(e))return new this.db.WhereClause(this,`[`+e.join(`+`)+`]`);var t=n(e);if(t.length===1)return this.where(t[0]).equals(e[t[0]]);var i=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(i&&this.db._maxKey!==W)return this.where(i.name).equals(i.keyPath.map(function(t){return e[t]}));!i&&D&&console.warn(`The query `+JSON.stringify(e)+` on `+this.name+` would benefit of a `+(`compound index [`+t.join(`+`)+`]`));var a=this.schema.idxByName,o=this.db._deps.indexedDB;function s(e,t){try{return o.cmp(e,t)===0}catch{return!1}}var c=t.reduce(function(t,n){var i=t[0],o=t[1],c=a[n],l=e[n];return[i||c,i||!c?K(o,c&&c.multi?function(e){var t=x(e,n);return r(t)&&t.some(function(e){return s(l,e)})}:function(e){return s(l,x(e,n))}):o]},[null,null]),l=c[0],u=c[1];return l?this.where(l.name).equals(e[l.keyPath]).filter(u):i?this.filter(u):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,r(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(c(t,r))try{n[r]=t[r]}catch{}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(){function e(e){a(this,e)}return this.mapToClass(e)},e.prototype.add=function(e,t){var n=this,r=this.schema.primKey,i=r.auto,a=r.keyPath,o=e;return a&&i&&(o=Xt(a)(e)),this._trans(`readwrite`,function(e){return n.core.mutate({trans:e,type:`add`,keys:t==null?null:[t],values:[o]})}).then(function(e){return e.numFailures?L.reject(e.failures[0]):e.lastResult}).then(function(t){if(a)try{S(e,a,t)}catch{}return t})},e.prototype.update=function(e,t){if(typeof t!=`object`||r(t))throw new A.InvalidArgument(`Modifications must be an object.`);if(typeof e==`object`&&!r(e)){n(t).forEach(function(n){S(e,n,t[n])});var i=x(e,this.schema.primKey.keyPath);return i===void 0?U(new A.InvalidArgument(`Given object does not contain its primary key`)):this.where(`:id`).equals(i).modify(t)}else return this.where(`:id`).equals(e).modify(t)},e.prototype.put=function(e,t){var n=this,r=this.schema.primKey,i=r.auto,a=r.keyPath,o=e;return a&&i&&(o=Xt(a)(e)),this._trans(`readwrite`,function(e){return n.core.mutate({trans:e,type:`put`,values:[o],keys:t==null?null:[t]})}).then(function(e){return e.numFailures?L.reject(e.failures[0]):e.lastResult}).then(function(t){if(a)try{S(e,a,t)}catch{}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?L.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:Yt})}).then(function(e){return e.numFailures?L.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;n=n||(i?void 0:t);var a=n?n.allKeys:void 0;return this._trans(`readwrite`,function(t){var n=r.schema.primKey,o=n.auto,s=n.keyPath;if(s&&i)throw new A.InvalidArgument(`bulkAdd(): keys argument invalid on tables with inbound keys`);if(i&&i.length!==e.length)throw new A.InvalidArgument(`Arguments objects and keys must have the same length`);var c=e.length,l=s&&o?e.map(Xt(s)):e;return r.core.mutate({trans:t,type:`add`,keys:i,values:l,wantResults:a}).then(function(e){var t=e.numFailures,n=e.results,i=e.lastResult,o=e.failures,s=a?n:i;if(t===0)return s;throw new we(r.name+`.bulkAdd(): `+t+` of `+c+` operations failed`,Object.keys(o).map(function(e){return o[e]}))})})},e.prototype.bulkPut=function(e,t,n){var r=this,i=Array.isArray(t)?t:void 0;n=n||(i?void 0:t);var a=n?n.allKeys:void 0;return this._trans(`readwrite`,function(t){var n=r.schema.primKey,o=n.auto,s=n.keyPath;if(s&&i)throw new A.InvalidArgument(`bulkPut(): keys argument invalid on tables with inbound keys`);if(i&&i.length!==e.length)throw new A.InvalidArgument(`Arguments objects and keys must have the same length`);var c=e.length,l=s&&o?e.map(Xt(s)):e;return r.core.mutate({trans:t,type:`put`,keys:i,values:l,wantResults:a}).then(function(e){var t=e.numFailures,n=e.results,i=e.lastResult,o=e.failures,s=a?n:i;if(t===0)return s;throw new we(r.name+`.bulkPut(): `+t+` of `+c+` operations failed`,Object.keys(o).map(function(e){return o[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,a=e.failures;if(r===0)return i;throw new we(t.name+`.bulkDelete(): `+r+` of `+n+` operations failed`,a)})},e}();function Qt(e){var t={},i=function(n,r){if(r){for(var i=arguments.length,a=Array(i-1);--i;)a[i-1]=arguments[i];return t[n].subscribe.apply(null,a),e}else if(typeof n==`string`)return t[n]};i.addEventType=s;for(var a=1,o=arguments.length;a<o;++a)s(arguments[a]);return i;function s(e,n,r){if(typeof e==`object`)return c(e);n||(n=Fe),r||(r=j);var a={subscribers:[],fire:r,subscribe:function(e){a.subscribers.indexOf(e)===-1&&(a.subscribers.push(e),a.fire=n(a.fire,e))},unsubscribe:function(e){a.subscribers=a.subscribers.filter(function(t){return t!==e}),a.fire=a.subscribers.reduce(n,r)}};return t[e]=i[e]=a,a}function c(e){n(e).forEach(function(t){var n=e[t];if(r(n))s(t,e[t][0],e[t][1]);else if(n===`asap`)var i=s(t,Ae,function(){for(var e=arguments.length,t=Array(e);e--;)t[e]=arguments[e];i.subscribers.forEach(function(e){y(function(){e.apply(null,t)})})});else throw new A.InvalidArgument(`Invalid event config`)})}}function $t(e,t){return f(t).from({prototype:e}),t}function en(e){return $t(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:Qt(null,{creating:[Me,j],reading:[je,Ae],updating:[Pe,j],deleting:[Ne,j]})})}function tn(e,t){return!(e.filter||e.algorithm||e.or)&&(t?e.justLimit:!e.replayFilter)}function nn(e,t){e.filter=K(e.filter,t)}function rn(e,t,n){var r=e.replayFilter;e.replayFilter=r?function(){return K(r(),t())}:t,e.justLimit=n&&!r}function an(e,t){e.isMatch=K(e.isMatch,t)}function on(e,t){if(e.isPrimKey)return t.primaryKey;var n=t.getIndexByKeyPath(e.index);if(!n)throw new A.Schema(`KeyPath `+e.index+` on object store `+t.name+` is not indexed`);return n}function sn(e,t,n){var r=on(e,t.schema);return t.openCursor({trans:n,values:!e.keysOnly,reverse:e.dir===`prev`,unique:!!e.unique,query:{index:r,range:e.range}})}function cn(e,t,n,r){var i=e.replayFilter?K(e.filter,e.replayFilter()):e.filter;if(e.or){var a={},o=function(e,n,r){if(!i||i(n,r,function(e){return n.stop(e)},function(e){return n.fail(e)})){var o=n.primaryKey,s=``+o;s===`[object ArrayBuffer]`&&(s=``+new Uint8Array(o)),c(a,s)||(a[s]=!0,t(e,n,r))}};return Promise.all([e.or._iterate(o,n),ln(sn(e,r,n),e.algorithm,o,!e.keysOnly&&e.valueMapper)])}else return ln(sn(e,r,n),K(e.algorithm,i),t,!e.keysOnly&&e.valueMapper)}function ln(e,t,n,r){var i=R(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=j},function(t){e.fail(t),n=j}))&&i(e.value,e,function(e){return n=e}),n()})})}var un=function(){function e(){}return e.prototype._read=function(e,t){var n=this._ctx;return n.error?n.table._trans(null,U.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,U.bind(null,t.error)):t.table._trans(`readwrite`,e,`locked`)},e.prototype._addAlgorithm=function(e){var t=this._ctx;t.algorithm=K(t.algorithm,e)},e.prototype._iterate=function(e,t){return cn(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&&a(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 cn(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(tn(n,!0))return r.count({trans:e,query:{index:on(n,r.schema),range:n.range}}).then(function(e){return Math.min(e,n.limit)});var i=0;return cn(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 a(e,t){return t?a(e[n[t]],t-1):e[r]}var o=this._ctx.dir===`next`?1:-1;function s(e,t){var n=a(e,i),r=a(t,i);return n<r?-o:n>r?o:0}return this.toArray(function(e){return e.sort(s)}).then(t)},e.prototype.toArray=function(e){var t=this;return this._read(function(e){var n=t._ctx;if(n.dir===`next`&&tn(n,!0)&&n.limit>0){var r=n.valueMapper,i=on(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})}else{var a=[];return cn(n,function(e){return a.push(e)},e,n.table.core).then(function(){return a})}},e)},e.prototype.offset=function(e){var t=this._ctx;return e<=0?this:(t.offset+=e,tn(t)?rn(t,function(){var t=e;return function(e,n){return t===0?!0:t===1?(--t,!1):(n(function(){e.advance(t),t=0}),!1)}}):rn(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),rn(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 nn(this._ctx,function(n,r,i){return e(n.value)?(r(i),t):!0}),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){return nn(this._ctx,function(t){return e(t.value)}),an(this._ctx,e),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=this._ctx.dir===`prev`?`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(t.dir===`next`&&tn(t,!0)&&t.limit>0)return this._read(function(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(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 nn(this._ctx,function(e){var t=e.primaryKey.toString(),r=c(n,t);return n[t]=!0,!r}),this},e.prototype.modify=function(e){var t=this,r=this._ctx;return this._write(function(i){var a;if(typeof e==`function`)a=e;else{var o=n(e),s=o.length;a=function(t){for(var n=!1,r=0;r<s;++r){var i=o[r],a=e[i];x(t,i)!==a&&(S(t,i,a),n=!0)}return n}}var c=r.table.core,l=c.schema.primaryKey,u=l.outbound,d=l.extractKey,f=`testmode`in pr?1:2e3,p=t.db.core.cmp,m=[],h=0,g=[],_=function(e,t){var r=t.failures,i=t.numFailures;h+=e-i;for(var a=0,o=n(r);a<o.length;a++){var s=o[a];m.push(r[s])}};return t.clone().primaryKeys().then(function(e){var t=function(n){var r=Math.min(f,e.length-n);return c.getMany({trans:i,keys:e.slice(n,n+r)}).then(function(o){for(var s=[],l=[],m=u?[]:null,h=[],g=0;g<r;++g){var v=o[g],y={value:w(v),primKey:e[n+g]};a.call(y,y.value,y)!==!1&&(y.value==null?h.push(e[n+g]):!u&&p(d(v),d(y.value))!==0?(h.push(e[n+g]),s.push(y.value)):(l.push(y.value),u&&m.push(e[n+g])))}return Promise.resolve(s.length>0&&c.mutate({trans:i,type:`add`,values:s}).then(function(e){for(var t in e.failures)h.splice(parseInt(t),1);_(s.length,e)})).then(function(e){return l.length>0&&c.mutate({trans:i,type:`put`,keys:m,values:l}).then(function(e){return _(l.length,e)})}).then(function(){return h.length>0&&c.mutate({trans:i,type:`delete`,keys:h}).then(function(e){return _(h.length,e)})}).then(function(){return e.length>n+r&&t(n+f)})})};return t(0).then(function(){if(m.length>0)throw new Ce(`Error modifying one or more objects`,m,h,g);return e.length})})})},e.prototype.delete=function(){var e=this._ctx,t=e.range;return tn(e)&&(e.isPrimKey&&!Wt||t.type===3)?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;e.lastResult,e.results;var r=e.numFailures;if(r)throw new Ce(`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 dn(e){return $t(un.prototype,function(t,n){this.db=e;var r=Yt,i=null;if(n)try{r=n()}catch(e){i=e}var a=t._ctx,o=a.table,s=o.hook.reading.fire;this._ctx={table:o,index:a.index,isPrimKey:!a.index||o.schema.primKey.keyPath&&a.index===o.schema.primKey.name,range:r,keysOnly:!1,dir:`next`,unique:``,algorithm:null,filter:null,replayFilter:null,justLimit:!0,isMatch:null,offset:0,limit:1/0,error:i,or:a.or,valueMapper:s===Ae?null:s}})}function fn(e,t){return e<t?-1:e===t?0:1}function pn(e,t){return e>t?-1:e===t?0:1}function q(e,t,n){var r=e instanceof yn?new e.Collection(e):e;return r._ctx.error=n?new n(t):TypeError(t),r}function J(e){return new e.Collection(e,function(){return vn(``)}).limit(0)}function mn(e){return e===`next`?function(e){return e.toUpperCase()}:function(e){return e.toLowerCase()}}function hn(e){return e===`next`?function(e){return e.toLowerCase()}:function(e){return e.toUpperCase()}}function gn(e,t,n,r,i,a){for(var o=Math.min(e.length,r.length),s=-1,c=0;c<o;++c){var l=t[c];if(l!==r[c])return i(e[c],n[c])<0?e.substr(0,c)+n[c]+n.substr(c+1):i(e[c],r[c])<0?e.substr(0,c)+r[c]+n.substr(c+1):s>=0?e.substr(0,s)+t[s]+n.substr(s+1):null;i(e[c],l)<0&&(s=c)}return o<r.length&&a===`next`?e+n.substr(e.length):o<e.length&&a===`prev`?e.substr(0,n.length):s<0?null:e.substr(0,s)+r[s]+n.substr(s+1)}function _n(e,t,n,r){var i,a,o,s,c,l,u,d=n.length;if(!n.every(function(e){return typeof e==`string`}))return q(e,Bt);function f(e){i=mn(e),a=hn(e),o=e===`next`?fn:pn;var t=n.map(function(e){return{lower:a(e),upper:i(e)}}).sort(function(e,t){return o(e.lower,t.lower)});s=t.map(function(e){return e.upper}),c=t.map(function(e){return e.lower}),l=e,u=e===`next`?``:r}f(`next`);var p=new e.Collection(e,function(){return Y(s[0],c[d-1]+r)});p._ondirectionchange=function(e){f(e)};var m=0;return p._addAlgorithm(function(e,n,r){var i=e.key;if(typeof i!=`string`)return!1;var f=a(i);if(t(f,c,m))return!0;for(var p=null,h=m;h<d;++h){var g=gn(i,f,s[h],c[h],o,l);g===null&&p===null?m=h+1:(p===null||o(p,g)>0)&&(p=g)}return n(p===null?r:function(){e.continue(p+u)}),!1}),p}function Y(e,t,n,r){return{type:2,lower:e,upper:t,lowerOpen:n,upperOpen:r}}function vn(e){return{type:1,lower:e,upper:e}}var yn=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=n!==!1,r=r===!0;try{return this._cmp(e,t)>0||this._cmp(e,t)===0&&(n||r)&&!(n&&r)?J(this):new this.Collection(this,function(){return Y(e,t,!n,!r)})}catch{return q(this,G)}},e.prototype.equals=function(e){return e==null?q(this,G):new this.Collection(this,function(){return vn(e)})},e.prototype.above=function(e){return e==null?q(this,G):new this.Collection(this,function(){return Y(e,void 0,!0)})},e.prototype.aboveOrEqual=function(e){return e==null?q(this,G):new this.Collection(this,function(){return Y(e,void 0,!1)})},e.prototype.below=function(e){return e==null?q(this,G):new this.Collection(this,function(){return Y(void 0,e,!1,!0)})},e.prototype.belowOrEqual=function(e){return e==null?q(this,G):new this.Collection(this,function(){return Y(void 0,e)})},e.prototype.startsWith=function(e){return typeof e==`string`?this.between(e,e+W,!0,!0):q(this,Bt)},e.prototype.startsWithIgnoreCase=function(e){return e===``?this.startsWith(e):_n(this,function(e,t){return e.indexOf(t[0])===0},[e],W)},e.prototype.equalsIgnoreCase=function(e){return _n(this,function(e,t){return e===t[0]},[e],``)},e.prototype.anyOfIgnoreCase=function(){var e=E.apply(T,arguments);return e.length===0?J(this):_n(this,function(e,t){return t.indexOf(e)!==-1},e,``)},e.prototype.startsWithAnyOfIgnoreCase=function(){var e=E.apply(T,arguments);return e.length===0?J(this):_n(this,function(e,t){return t.some(function(t){return e.indexOf(t)===0})},e,W)},e.prototype.anyOf=function(){var e=this,t=E.apply(T,arguments),n=this._cmp;try{t.sort(n)}catch{return q(this,G)}if(t.length===0)return J(this);var r=new this.Collection(this,function(){return Y(t[0],t[t.length-1])});r._ondirectionchange=function(r){n=r===`next`?e._ascending:e._descending,t.sort(n)};var i=0;return r._addAlgorithm(function(e,r,a){for(var o=e.key;n(o,t[i])>0;)if(++i,i===t.length)return r(a),!1;return n(o,t[i])===0?!0:(r(function(){e.continue(t[i])}),!1)}),r},e.prototype.notEqual=function(e){return this.inAnyRange([[zt,e],[e,this.db._maxKey]],{includeLowers:!1,includeUppers:!1})},e.prototype.noneOf=function(){var e=E.apply(T,arguments);if(e.length===0)return new this.Collection(this);try{e.sort(this._ascending)}catch{return q(this,G)}var t=e.reduce(function(e,t){return e?e.concat([[e[e.length-1][1],t]]):[[zt,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,a=this._descending,o=this._min,s=this._max;if(e.length===0)return J(this);if(!e.every(function(e){return e[0]!==void 0&&e[1]!==void 0&&i(e[0],e[1])<=0}))return q(this,`First argument to inAnyRange() must be an Array of two-value Arrays [lower,upper] where upper must not be lower than lower`,A.InvalidArgument);var c=!t||t.includeLowers!==!1,l=t&&t.includeUppers===!0;function u(e,t){for(var n=0,i=e.length;n<i;++n){var a=e[n];if(r(t[0],a[1])<0&&r(t[1],a[0])>0){a[0]=o(a[0],t[0]),a[1]=s(a[1],t[1]);break}}return n===i&&e.push(t),e}var d=i;function f(e,t){return d(e[0],t[0])}var p;try{p=e.reduce(u,[]),p.sort(f)}catch{return q(this,G)}var m=0,h=l?function(e){return i(e,p[m][1])>0}:function(e){return i(e,p[m][1])>=0},g=c?function(e){return a(e,p[m][0])>0}:function(e){return a(e,p[m][0])>=0};function _(e){return!h(e)&&!g(e)}var v=h,y=new this.Collection(this,function(){return Y(p[0][0],p[p.length-1][1],!c,!l)});return y._ondirectionchange=function(e){e===`next`?(v=h,d=i):(v=g,d=a),p.sort(f)},y._addAlgorithm(function(e,t,r){for(var a=e.key;v(a);)if(++m,m===p.length)return t(r),!1;return _(a)?!0:(n._cmp(a,p[m][1])===0||n._cmp(a,p[m][0])===0||t(function(){d===i?e.continue(p[m][0]):e.continue(p[m][1])}),!1)}),y},e.prototype.startsWithAnyOf=function(){var e=E.apply(T,arguments);return e.every(function(e){return typeof e==`string`})?e.length===0?J(this):this.inAnyRange(e.map(function(e){return[e,e+W]})):q(this,`startsWithAnyOf() only works with strings`)},e}();function bn(e){return $t(yn.prototype,function(t,n,r){this.db=e,this._ctx={table:t,index:n===`:id`?null:n,or:r};var i=e._deps.indexedDB;if(!i)throw new A.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})}function xn(e){return e.length===1?e[0]:e}function Sn(e){try{return e.only([[]]),[[]]}catch{return W}}function X(e){return R(function(t){return Z(t),e(t.target.error),!1})}function Z(e){e.stopPropagation&&e.stopPropagation(),e.preventDefault&&e.preventDefault()}var Cn=function(){function e(){}return e.prototype._lock=function(){return v(!F.global),++this._reculock,this._reculock===1&&!F.global&&(F.lockOwnerFor=this),this},e.prototype._unlock=function(){if(v(!F.global),--this._reculock===0)for(F.global||(F.lockOwnerFor=null);this._blockedFuncs.length>0&&!this._locked();){var e=this._blockedFuncs.shift();try{jt(e[1],e[0])}catch{}}return this},e.prototype._locked=function(){return this._reculock&&F.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(v(!this.idbtrans),!e&&!n)switch(r&&r.name){case`DatabaseClosedError`:throw new A.DatabaseClosed(r);case`MissingAPIError`:throw new A.MissingAPI(r.message,r);default:throw new A.OpenFailed(r)}if(!this.active)throw new A.TransactionInactive;return v(this._completion._state===null),e=this.idbtrans=e||n.transaction(xn(this.storeNames),this.mode),e.onerror=R(function(n){Z(n),t._reject(e.error)}),e.onabort=R(function(n){Z(n),t.active&&t._reject(new A.Abort(e.error)),t.active=!1,t.on(`abort`).fire(n)}),e.oncomplete=R(function(){t.active=!1,t._resolve()}),this},e.prototype._promise=function(e,t,n){var r=this;if(e===`readwrite`&&this.mode!==`readwrite`)return U(new A.ReadOnly(`Transaction is readonly`));if(!this.active)return U(new A.TransactionInactive);if(this._locked())return new L(function(i,a){r._blockedFuncs.push([function(){r._promise(e,t,n).then(i,a)},F])});if(n)return B(function(){var e=new L(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 L(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=L.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 L(function(e,r){n.then(function(n){return t._waitingQueue.push(R(e.bind(null,n)))},function(e){return t._waitingQueue.push(R(r.bind(null,e)))}).finally(function(){t._waitingFor===i&&(t._waitingFor=null)})})},e.prototype.abort=function(){this.active&&this._reject(new A.Abort),this.active=!1},e.prototype.table=function(e){var t=this._memoizedTables||(this._memoizedTables={});if(c(t,e))return t[e];var n=this.schema[e];if(!n)throw new A.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 wn(e){return $t(Cn.prototype,function(t,n,r,i){var a=this;this.db=e,this.mode=t,this.storeNames=n,this.schema=r,this.idbtrans=null,this.on=Qt(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 L(function(e,t){a._resolve=e,a._reject=t}),this._completion.then(function(){a.active=!1,a.on.complete.fire()},function(e){var t=a.active;return a.active=!1,a.on.error.fire(e),a.parent?a.parent._reject(e):t&&a.idbtrans&&a.idbtrans.abort(),U(e)})})}function Tn(e,t,n,r,i,a,o){return{name:e,keyPath:t,unique:n,multi:r,auto:i,compound:a,src:(n&&!o?`&`:``)+(r?`*`:``)+(i?`++`:``)+En(t)}}function En(e){return typeof e==`string`?e:e?`[`+[].join.call(e,`+`)+`]`:``}function Dn(e,t,n){return{name:e,primKey:t,indexes:n,mappedClass:null,idxByName:b(n,function(e){return[e.name,e]})}}function On(e){return e==null?function(){}:typeof e==`string`?kn(e):function(t){return x(t,e)}}function kn(e){return e.split(`.`).length===1?function(t){return t[e]}:function(t){return x(t,e)}}function An(e,t){return t.type===`delete`?t.keys:t.keys||t.values.map(e.extractKey)}function jn(e,t,n){return t.type===`add`?Promise.resolve(Array(t.values.length)):e.getMany({trans:t.trans,keys:n})}function Mn(e){return[].slice.call(e)}var Nn=0;function Pn(e){return e==null?`:id`:typeof e==`string`?e:`[`+e.join(`+`)+`]`}function Fn(e,n,i,a){var o=n.cmp.bind(n);function s(e,t){var n=Mn(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,i=r(t),a=t==null,o={},s={name:e.name,primaryKey:{name:null,isPrimaryKey:!0,outbound:a,compound:i,keyPath:t,autoIncrement:n,unique:!0,extractKey:On(t)},indexes:Mn(e.indexNames).map(function(t){return e.index(t)}).map(function(e){var t=e.name,n=e.unique,i=e.multiEntry,a=e.keyPath,s={name:t,compound:r(a),keyPath:a,unique:n,multiEntry:i,extractKey:On(a)};return o[Pn(a)]=s,s}),getIndexByKeyPath:function(e){return o[Pn(e)]}};return o[`:id`]=s.primaryKey,t!=null&&(o[Pn(t)]=s.primaryKey),s})},hasGetAll:n.length>0&&`getAll`in t.objectStore(n[0])&&!(typeof navigator<`u`&&/Safari/.test(navigator.userAgent)&&!/(Chrome\/|Edge\/)/.test(navigator.userAgent)&&[].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1]<604)}}function c(e){if(e.type===3)return null;if(e.type===4)throw Error(`Cannot convert never type to IDBKeyRange`);var t=e.lower,n=e.upper,r=e.lowerOpen,a=e.upperOpen;return t===void 0?n===void 0?null:i.upperBound(n,!!a):n===void 0?i.lowerBound(t,!!r):i.bound(t,n,!!r,!!a)}function l(e){var n=e.name;function r(r){var i=r.trans,a=r.type,o=r.keys,s=r.values,l=r.range,u=r.wantResults;return new Promise(function(r,d){r=R(r);var f=i.objectStore(n),p=f.keyPath==null,m=a===`put`||a===`add`;if(!m&&a!==`delete`&&a!==`deleteRange`)throw Error(`Invalid operation type: `+a);var h=(o||s||{length:1}).length;if(o&&s&&o.length!==s.length)throw Error(`Given keys array must have same length as given values array.`);if(h===0)return r({numFailures:0,failures:{},results:[],lastResult:void 0});var g=u&&t(o||An(e.primaryKey,{type:a,keys:o,values:s})),_,v=[],y=0,b=function(e){++y,Z(e),g&&(g[e.target._reqno]=void 0),v[e.target._reqno]=e.target.error},ee=function(e){var t=e.target;g[t._reqno]=t.result};if(a===`deleteRange`){if(l.type===4)return r({numFailures:y,failures:v,results:g,lastResult:void 0});_=l.type===3?f.clear():f.delete(c(l))}else{var x=m?p?[s,o]:[s,null]:[o,null],S=x[0],te=x[1];if(m)for(var C=0;C<h;++C)_=te&&te[C]!==void 0?f[a](S[C],te[C]):f[a](S[C]),_._reqno=C,g&&g[C]===void 0&&(_.onsuccess=ee),_.onerror=b;else for(var C=0;C<h;++C)_=f[a](S[C]),_._reqno=C,_.onerror=b}var ne=function(e){var t=e.target.result;g&&(g[h-1]=t),r({numFailures:y,failures:v,results:g,lastResult:t})};_.onerror=function(e){b(e),ne(e)},_.onsuccess=ne})}function i(e){var t=e.trans,r=e.values,i=e.query,a=e.reverse,o=e.unique;return new Promise(function(e,s){e=R(e);var l=i.index,u=i.range,d=t.objectStore(n),f=l.isPrimaryKey?d:d.index(l.name),p=a?o?`prevunique`:`prev`:o?`nextunique`:`next`,m=r||!(`openKeyCursor`in f)?f.openCursor(c(u),p):f.openKeyCursor(c(u),p);m.onerror=X(s),m.onsuccess=R(function(n){var r=m.result;if(!r){e(null);return}r.___id=++Nn,r.done=!1;var i=r.continue.bind(r),a=r.continuePrimaryKey;a&&(a=a.bind(r));var o=r.advance.bind(r),c=function(){throw Error(`Cursor not started`)},l=function(){throw Error(`Cursor not stopped`)};r.trans=t,r.stop=r.continue=r.continuePrimaryKey=r.advance=c,r.fail=R(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=R(e),m.onerror=X(t),r.fail=t,r.stop=function(t){r.stop=r.continue=r.continuePrimaryKey=r.advance=l,e(t)}}),n=function(){if(m.result)try{e()}catch(e){r.fail(e)}else r.done=!0,r.start=function(){throw Error(`Cursor behind last entry`)},r.stop()};return m.onsuccess=R(function(e){m.onsuccess=n,n()}),r.continue=i,r.continuePrimaryKey=a,r.advance=o,n(),t},e(r)},s)})}function a(e){return function(t){return new Promise(function(r,i){r=R(r);var a=t.trans,o=t.values,s=t.limit,l=t.query,u=s===1/0?void 0:s,d=l.index,f=l.range,p=a.objectStore(n),m=d.isPrimaryKey?p:p.index(d.name),h=c(f);if(s===0)return r({result:[]});if(e){var g=o?m.getAll(h,u):m.getAllKeys(h,u);g.onsuccess=function(e){return r({result:e.target.result})},g.onerror=X(i)}else{var _=0,v=o||!(`openKeyCursor`in m)?m.openCursor(h):m.openKeyCursor(h),y=[];v.onsuccess=function(e){var t=v.result;if(!t||(y.push(o?t.value:t.primaryKey),++_===s))return r({result:y});t.continue()},v.onerror=X(i)}})}}return{name:n,schema:e,mutate:r,getMany:function(e){var t=e.trans,r=e.keys;return new Promise(function(e,i){e=R(e);for(var a=t.objectStore(n),o=r.length,s=Array(o),c=0,l=0,u=0,d,f=function(t){var n=t.target;(s[n._pos]=n.result)!=null&&++u,++l===c&&e(s)},p=X(i),m=0;m<o;++m)r[m]!=null&&(d=a.get(r[m]),d._pos=m,d.onsuccess=f,d.onerror=p,++c);c===0&&e(s)})},get:function(e){var t=e.trans,r=e.key;return new Promise(function(e,i){e=R(e);var a=t.objectStore(n).get(r);a.onsuccess=function(t){return e(t.target.result)},a.onerror=X(i)})},query:a(f),openCursor:i,count:function(e){var t=e.query,r=e.trans,i=t.index,a=t.range;return new Promise(function(e,t){var o=r.objectStore(n),s=i.isPrimaryKey?o:o.index(i.name),l=c(a),u=l?s.count(l):s.count();u.onsuccess=R(function(t){return e(t.target.result)}),u.onerror=X(t)})}}}var u=s(e,a),d=u.schema,f=u.hasGetAll,p=d.tables.map(function(e){return l(e)}),m={};return p.forEach(function(e){return m[e.name]=e}),{stack:`dbcore`,transaction:e.transaction.bind(e),table:function(e){if(!m[e])throw Error(`Table '`+e+`' not found`);return m[e]},cmp:o,MIN_KEY:-1/0,MAX_KEY:Sn(i),schema:d}}function In(t,n){return n.reduce(function(t,n){var r=n.create;return e(e({},t),r(t))},t)}function Ln(e,t,n,r){var i=n.IDBKeyRange,a=n.indexedDB;return{dbcore:In(Fn(t,a,i,r),e.dbcore)}}function Rn(e,t){var n=t.db;e.core=Ln(e._middlewares,n,e._deps,t).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 zn(e,t,n,r){n.forEach(function(n){var i=r[n];t.forEach(function(t){var r=m(t,n);(!r||`value`in r&&r.value===void 0)&&(t===e.Transaction.prototype||t instanceof e.Transaction?d(t,n,{get:function(){return this.table(n)},set:function(e){u(this,n,{value:e,writable:!0,configurable:!0,enumerable:!0})}}):t[n]=new e.Table(n,i))})})}function Bn(e,t){t.forEach(function(t){for(var n in t)t[n]instanceof e.Table&&delete t[n]})}function Vn(e,t){return e._cfg.version-t._cfg.version}function Hn(e,t,r,i){var a=e._dbSchema,o=e._createTransaction(`readwrite`,e._storeNames,a);o.create(r),o._completion.catch(i);var s=o._reject.bind(o),c=F.transless||F;B(function(){F.trans=o,F.transless=c,t===0?(n(a).forEach(function(e){Gn(r,e,a[e].primKey,a[e].indexes)}),Rn(e,r),L.follow(function(){return e.on.populate.fire(o)}).catch(s)):Un(e,t,o,r).catch(s)})}function Un(e,t,r,i){var a=[],o=e._versions,s=e._dbSchema=Yn(e,e.idbdb,i),c=!1;o.filter(function(e){return e._cfg.version>=t}).forEach(function(o){a.push(function(){var a=s,l=o._cfg.dbschema;Qn(e,a,i),Qn(e,l,i),s=e._dbSchema=l;var u=Wn(a,l);u.add.forEach(function(e){Gn(i,e[0],e[1].primKey,e[1].indexes)}),u.change.forEach(function(e){if(e.recreate)throw new A.Upgrade(`Not yet support for changing primary key`);var t=i.objectStore(e.name);e.add.forEach(function(e){return Jn(t,e)}),e.change.forEach(function(e){t.deleteIndex(e.name),Jn(t,e)}),e.del.forEach(function(e){return t.deleteIndex(e)})});var d=o._cfg.contentUpgrade;if(d&&o._cfg.version>t){Rn(e,i),r._memoizedTables={},c=!0;var f=C(l);u.del.forEach(function(e){f[e]=a[e]}),Bn(e,[e.Transaction.prototype]),zn(e,[e.Transaction.prototype],n(f),f),r.schema=f;var p=pe(d);p&&Et();var m,h=L.follow(function(){if(m=d(r),m&&p){var e=V.bind(null,null);m.then(e,e)}});return m&&typeof m.then==`function`?L.resolve(m):h.then(function(){return m})}}),a.push(function(t){if(!c||!Ut){var n=o._cfg.dbschema;qn(n,t)}Bn(e,[e.Transaction.prototype]),zn(e,[e.Transaction.prototype],e._storeNames,e._dbSchema),r.schema=e._dbSchema})});function l(){return a.length?L.resolve(a.shift()(r.idbtrans)).then(l):L.resolve()}return l().then(function(){Kn(s,i)})}function Wn(e,t){var n={del:[],add:[],change:[]},r;for(r in e)t[r]||n.del.push(r);for(r in t){var i=e[r],a=t[r];if(!i)n.add.push([r,a]);else{var o={name:r,def:a,recreate:!1,del:[],add:[],change:[]};if(``+(i.primKey.keyPath||``)!=``+(a.primKey.keyPath||``)||i.primKey.auto!==a.primKey.auto&&!Ht)o.recreate=!0,n.change.push(o);else{var s=i.idxByName,c=a.idxByName,l=void 0;for(l in s)c[l]||o.del.push(l);for(l in c){var u=s[l],d=c[l];u?u.src!==d.src&&o.change.push(d):o.add.push(d)}(o.del.length>0||o.add.length>0||o.change.length>0)&&n.change.push(o)}}}return n}function Gn(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 Jn(i,e)}),i}function Kn(e,t){n(e).forEach(function(n){t.db.objectStoreNames.contains(n)||Gn(t,n,e[n].primKey,e[n].indexes)})}function qn(e,t){for(var n=0;n<t.db.objectStoreNames.length;++n){var r=t.db.objectStoreNames[n];e[r]??t.db.deleteObjectStore(r)}}function Jn(e,t){e.createIndex(t.name,t.keyPath,{unique:t.unique,multiEntry:t.multi})}function Yn(e,t,n){var r={};return g(t.objectStoreNames,0).forEach(function(e){for(var t=n.objectStore(e),i=t.keyPath,a=Tn(En(i),i||``,!1,!1,!!t.autoIncrement,i&&typeof i!=`string`,!0),o=[],s=0;s<t.indexNames.length;++s){var c=t.index(t.indexNames[s]);i=c.keyPath;var l=Tn(c.name,i,!!c.unique,!!c.multiEntry,!1,i&&typeof i!=`string`,!1);o.push(l)}r[e]=Dn(e,a,o)}),r}function Xn(e,t,r){e.verno=t.version/10;var i=e._dbSchema=Yn(e,t,r);e._storeNames=g(t.objectStoreNames,0),zn(e,[e._allTables],n(i),i)}function Zn(e,t){var n=Wn(Yn(e,e.idbdb,t),e._dbSchema);return!(n.add.length||n.change.some(function(e){return e.add.length||e.change.length}))}function Qn(e,t,n){for(var r=n.db.objectStoreNames,a=0;a<r.length;++a){var o=r[a],s=n.objectStore(o);e._hasGetAll=`getAll`in s;for(var c=0;c<s.indexNames.length;++c){var l=s.indexNames[c],u=s.index(l).keyPath,d=typeof u==`string`?u:`[`+g(u).join(`+`)+`]`;if(t[o]){var f=t[o].idxByName[d];f&&(f.name=l,delete t[o].idxByName[d],t[o].idxByName[l]=f)}}}typeof navigator<`u`&&/Safari/.test(navigator.userAgent)&&!/(Chrome\/|Edge\/)/.test(navigator.userAgent)&&i.WorkerGlobalScope&&i instanceof i.WorkerGlobalScope&&[].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1]<604&&(e._hasGetAll=!1)}function $n(e){return e.split(`,`).map(function(e,t){e=e.trim();var n=e.replace(/([&*]|\+\+)/g,``),i=/^\[/.test(n)?n.match(/^\[(.*)\]$/)[1].split(`+`):n;return Tn(n,i||null,/\&/.test(e),/\*/.test(e),/\+\+/.test(e),r(i),t===0)})}var er=function(){function e(){}return e.prototype._parseStoresSpec=function(e,t){n(e).forEach(function(n){if(e[n]!==null){var r=$n(e[n]),i=r.shift();if(i.multi)throw new A.Schema(`Primary key cannot be multi-valued`);r.forEach(function(e){if(e.auto)throw new A.Schema(`Only primary key can be marked as autoIncrement (++)`);if(!e.keyPath)throw new A.Schema(`Index must have a name and cannot be an empty string`)}),t[n]=Dn(n,i,r)}})},e.prototype.stores=function(e){var t=this.db;this._cfg.storesSource=this._cfg.storesSource?a(this._cfg.storesSource,e):e;var r=t._versions,i={},o={};return r.forEach(function(e){a(i,e._cfg.storesSource),o=e._cfg.dbschema={},e._parseStoresSpec(i,o)}),t._dbSchema=o,Bn(t,[t._allTables,t,t.Transaction.prototype]),zn(t,[t._allTables,t,t.Transaction.prototype,this._cfg.tables],n(o),o),t._storeNames=n(o),this},e.prototype.upgrade=function(e){return this._cfg.contentUpgrade=e,this},e}();function tr(e){return $t(er.prototype,function(t){this.db=e,this._cfg={version:t,storesSource:null,dbschema:{},tables:{},contentUpgrade:null}})}var nr;function rr(e){var t=e&&typeof e.databases==`function`,n;if(!t){var r=new pr(Kt,{addons:[]});r.version(1).stores({dbnames:`name`}),n=r.table(`dbnames`)}return{getDatabaseNames:function(){return t?L.resolve(e.databases()).then(function(e){return e.map(function(e){return e.name}).filter(function(e){return e!==Kt})}):n.toCollection().primaryKeys()},add:function(e){return!t&&e!==Kt&&n.put({name:e}).catch(j)},remove:function(e){return!t&&e!==Kt&&n.delete(e).catch(j)}}}function ir(e){try{nr=rr(e)}catch{}}function ar(e){return B(function(){return F.letThrough=!0,e()})}function or(e){var t=e._state,n=e._deps.indexedDB;if(t.isBeingOpened||e.idbdb)return t.dbReadyPromise.then(function(){return t.dbOpenError?U(t.dbOpenError):e});D&&(t.openCanceller._stackHolder=O()),t.isBeingOpened=!0,t.dbOpenError=null,t.openComplete=!1;var r=t.dbReadyResolve,i=null;return L.race([t.openCanceller,new L(function(r,a){if(!n)throw new A.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 o=e.name,s=t.autoSchema?n.open(o):n.open(o,Math.round(e.verno*10));if(!s)throw new A.MissingAPI(`IndexedDB API not available`);s.onerror=X(a),s.onblocked=R(e._fireOnBlocked),s.onupgradeneeded=R(function(r){if(i=s.transaction,t.autoSchema&&!e._options.allowEmptyDB){s.onerror=Z,i.abort(),s.result.close();var c=n.deleteDatabase(o);c.onsuccess=c.onerror=R(function(){a(new A.NoSuchDatabase(`Database `+o+` doesnt exist`))})}else{i.onerror=X(a);var l=r.oldVersion>2**62?0:r.oldVersion;e.idbdb=s.result,Hn(e,l/10,i,a)}},a),s.onsuccess=R(function(){i=null;var n=e.idbdb=s.result,a=g(n.objectStoreNames);if(a.length>0)try{var c=n.transaction(xn(a),`readonly`);t.autoSchema?Xn(e,n,c):(Qn(e,e._dbSchema,c),Zn(e,c)||console.warn(`Dexie SchemaDiff: Schema was extended without increasing the number passed to db.version(). Some queries may fail.`)),Rn(e,c)}catch{}Vt.push(e),n.onversionchange=R(function(n){t.vcFired=!0,e.on(`versionchange`).fire(n)}),nr.add(o),r()},a)})]).then(function(){return t.onReadyBeingFired=[],L.resolve(ar(e.on.ready.fire)).then(function e(){if(t.onReadyBeingFired.length>0){var n=t.onReadyBeingFired.reduce(Ie,j);return t.onReadyBeingFired=[],L.resolve(ar(n)).then(e)}})}).finally(function(){t.onReadyBeingFired=null}).then(function(){return t.isBeingOpened=!1,e}).catch(function(n){try{i&&i.abort()}catch{}return t.isBeingOpened=!1,e.close(),t.dbOpenError=n,U(t.dbOpenError)}).finally(function(){t.openComplete=!0,r()})}function sr(e){var t=function(t){return e.next(t)},n=function(t){return e.throw(t)},i=o(t),a=o(n);function o(e){return function(t){var n=e(t),o=n.value;return n.done?o:!o||typeof o.then!=`function`?r(o)?Promise.all(o).then(i,a):i(o):o.then(i,a)}}return o(t)()}function cr(e,t,n){var r=arguments.length;if(r<2)throw new A.InvalidArgument(`Too few arguments`);for(var i=Array(r-1);--r;)i[r-1]=arguments[r];return n=i.pop(),[e,re(i),n]}function lr(e,t,n,r,i){return L.resolve().then(function(){var a=F.transless||F,o=e._createTransaction(t,n,e._dbSchema,r),s={trans:o,transless:a};r?o.idbtrans=r.idbtrans:o.create();var c=pe(i);c&&Et();var l,u=L.follow(function(){if(l=i.call(o,o),l)if(c){var e=V.bind(null,null);l.then(e,e)}else typeof l.next==`function`&&typeof l.throw==`function`&&(l=sr(l))},s);return(l&&typeof l.then==`function`?L.resolve(l).then(function(e){return o.active?e:U(new A.PrematureCommit(`Transaction committed too early. See http://bit.ly/2kdckMn`))}):u.then(function(){return l})).then(function(e){return r&&o._resolve(),o._completion.then(function(){return e})}).catch(function(e){return o._reject(e),U(e)})})}function Q(e,t,n){for(var i=r(e)?e.slice():[e],a=0;a<n;++a)i.push(t);return i}function ur(t){return e(e({},t),{table:function(n){var r=t.table(n),i=r.schema,a={},o=[];function s(t,n,r){var i=Pn(t),c=a[i]=a[i]||[],l=t==null?0:typeof t==`string`?1:t.length,u=n>0,d=e(e({},r),{isVirtual:u,isPrimaryKey:!u&&r.isPrimaryKey,keyTail:n,keyLength:l,extractKey:On(t),unique:!u&&r.unique});return c.push(d),d.isPrimaryKey||o.push(d),l>1&&s(l===2?t[0]:t.slice(0,l-1),n+1,r),c.sort(function(e,t){return e.keyTail-t.keyTail}),d}var c=s(i.primaryKey.keyPath,0,i.primaryKey);a[`:id`]=[c];for(var l=0,u=i.indexes;l<u.length;l++){var d=u[l];s(d.keyPath,0,d)}function f(e){var t=a[Pn(e)];return t&&t[0]}function p(e,n){return{type:e.type===1?2:e.type,lower:Q(e.lower,e.lowerOpen?t.MAX_KEY:t.MIN_KEY,n),lowerOpen:!0,upper:Q(e.upper,e.upperOpen?t.MIN_KEY:t.MAX_KEY,n),upperOpen:!0}}function m(t){var n=t.query.index;return n.isVirtual?e(e({},t),{query:{index:n,range:p(t.query.range,n.keyTail)}}):t}return e(e({},r),{schema:e(e({},i),{primaryKey:c,indexes:o,getIndexByKeyPath:f}),count:function(e){return r.count(m(e))},query:function(e){return r.query(m(e))},openCursor:function(e){var n=e.query.index,i=n.keyTail,a=n.isVirtual,o=n.keyLength;if(!a)return r.openCursor(e);function s(n){function r(r){r==null?e.unique?n.continue(Q(n.key,e.reverse?t.MIN_KEY:t.MAX_KEY,i)):n.continue():n.continue(Q(r,e.reverse?t.MAX_KEY:t.MIN_KEY,i))}return Object.create(n,{continue:{value:r},continuePrimaryKey:{value:function(e,r){n.continuePrimaryKey(Q(e,t.MAX_KEY,i),r)}},key:{get:function(){var e=n.key;return o===1?e[0]:e.slice(0,o)}},value:{get:function(){return n.value}}})}return r.openCursor(m(e)).then(function(e){return e&&s(e)})}})}})}var dr={stack:`dbcore`,name:`VirtualIndexMiddleware`,level:1,create:ur},fr={stack:`dbcore`,name:`HooksMiddleware`,level:2,create:function(n){return e(e({},n),{table:function(r){var i=n.table(r),a=i.schema.primaryKey;return e(e({},i),{mutate:function(n){var o=F.trans,s=o.table(r).hook,l=s.deleting,u=s.creating,d=s.updating;switch(n.type){case`add`:if(u.fire===j)break;return o._promise(`readwrite`,function(){return f(n)},!0);case`put`:if(u.fire===j&&d.fire===j)break;return o._promise(`readwrite`,function(){return f(n)},!0);case`delete`:if(l.fire===j)break;return o._promise(`readwrite`,function(){return f(n)},!0);case`deleteRange`:if(l.fire===j)break;return o._promise(`readwrite`,function(){return p(n)},!0)}return i.mutate(n);function f(n){var r=F.trans,o=n.keys||An(a,n);if(!o)throw Error(`Keys missing`);return n=n.type===`add`||n.type===`put`?e(e({},n),{keys:o,wantResults:!0}):e({},n),n.type!==`delete`&&(n.values=t(n.values)),n.keys&&(n.keys=t(n.keys)),jn(i,n,o).then(function(e){var t=o.map(function(t,i){var o=e[i],s={onerror:null,onsuccess:null};if(n.type===`delete`)l.fire.call(s,t,o,r);else if(n.type===`add`||o===void 0){var f=u.fire.call(s,t,n.values[i],r);t==null&&f!=null&&(t=f,n.keys[i]=t,a.outbound||S(n.values[i],a.keyPath,t))}else{var p=ue(o,n.values[i]),m=d.fire.call(s,p,t,o,r);if(m){var h=n.values[i];Object.keys(m).forEach(function(e){c(h,e)?h[e]=m[e]:S(h,e,m[e])})}}return s});return i.mutate(n).then(function(r){for(var i=r.failures,a=r.results,s=r.numFailures,c=r.lastResult,l=0;l<o.length;++l){var u=a?a[l]:o[l],d=t[l];u==null?d.onerror&&d.onerror(i[l]):d.onsuccess&&d.onsuccess(n.type===`put`&&e[l]?n.values[l]:u)}return{failures:i,results:a,numFailures:s,lastResult:c}}).catch(function(e){return t.forEach(function(t){return t.onerror&&t.onerror(e)}),Promise.reject(e)})})}function p(e){return m(e.trans,e.range,1e4)}function m(t,n,r){return i.query({trans:t,values:!1,query:{index:a,range:n},limit:r}).then(function(i){var a=i.result;return f({type:`delete`,keys:a,trans:t}).then(function(i){return i.numFailures>0?Promise.reject(i.failures[0]):a.length<r?{failures:[],numFailures:0,lastResult:void 0}:m(t,e(e({},n),{lower:a[a.length-1],lowerOpen:!0}),r)})})}}})}})}},pr=function(){function t(n,r){var i=this;this._middlewares={},this.verno=0;var a=t.dependencies;this._options=r=e({addons:t.addons,autoOpen:!0,indexedDB:a.indexedDB,IDBKeyRange:a.IDBKeyRange},r),this._deps={indexedDB:r.indexedDB,IDBKeyRange:r.IDBKeyRange};var o=r.addons;this._dbSchema={},this._versions=[],this._storeNames=[],this._allTables={},this.idbdb=null;var s={dbOpenError:null,isBeingOpened:!1,onReadyBeingFired:null,openComplete:!1,dbReadyResolve:j,dbReadyPromise:null,cancelOpen:j,openCanceller:null,autoSchema:!0};s.dbReadyPromise=new L(function(e){s.dbReadyResolve=e}),s.openCanceller=new L(function(e,t){s.cancelOpen=t}),this._state=s,this.name=n,this.on=Qt(this,`populate`,`blocked`,`versionchange`,{ready:[Ie,j]}),this.on.ready.subscribe=_(this.on.ready.subscribe,function(e){return function(n,r){t.vip(function(){var t=i._state;if(t.openComplete)t.dbOpenError||L.resolve().then(n),r&&e(n);else if(t.onReadyBeingFired)t.onReadyBeingFired.push(n),r&&e(n);else{e(n);var a=i;r||e(function e(){a.on.ready.unsubscribe(n),a.on.ready.unsubscribe(e)})}})}}),this.Collection=dn(this),this.Table=en(this),this.Transaction=wn(this),this.Version=tr(this),this.WhereClause=bn(this),this.on(`versionchange`,function(e){e.newVersion>0?console.warn(`Another connection wants to upgrade database '`+i.name+`'. Closing db now to resume the upgrade.`):console.warn(`Another connection wants to delete database '`+i.name+`'. Closing db now to resume the delete request.`),i.close()}),this.on(`blocked`,function(e){!e.newVersion||e.newVersion<e.oldVersion?console.warn(`Dexie.delete('`+i.name+`') was blocked`):console.warn(`Upgrade '`+i.name+`' blocked by other connection holding version `+e.oldVersion/10)}),this._maxKey=Sn(r.IDBKeyRange),this._createTransaction=function(e,t,n,r){return new i.Transaction(e,t,n,r)},this._fireOnBlocked=function(e){i.on(`blocked`).fire(e),Vt.filter(function(e){return e.name===i.name&&e!==i&&!e._state.vcFired}).map(function(t){return t.on(`versionchange`).fire(e)})},this.use(dr),this.use(fr),o.forEach(function(e){return e(i)})}return t.prototype.version=function(e){if(isNaN(e)||e<.1)throw new A.Type(`Given version is not a positive number`);if(e=Math.round(e*10)/10,this.idbdb||this._state.isBeingOpened)throw new A.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(Vn),n.stores({}),this._state.autoSchema=!1,n)},t.prototype._whenReady=function(e){var t=this;return this._state.openComplete||F.letThrough?e():new L(function(e,n){if(!t._state.isBeingOpened){if(!t._options.autoOpen){n(new A.DatabaseClosed);return}t.open().catch(j)}t._state.dbReadyPromise.then(e,n)}).then(e)},t.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 a=this._middlewares[t]||(this._middlewares[t]=[]);return a.push({stack:t,create:n,level:r??10,name:i}),a.sort(function(e,t){return e.level-t.level}),this},t.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:!1})),this},t.prototype.open=function(){return or(this)},t.prototype.close=function(){var e=Vt.indexOf(this),t=this._state;if(e>=0&&Vt.splice(e,1),this.idbdb){try{this.idbdb.close()}catch{}this.idbdb=null}this._options.autoOpen=!1,t.dbOpenError=new A.DatabaseClosed,t.isBeingOpened&&t.cancelOpen(t.dbOpenError),t.dbReadyPromise=new L(function(e){t.dbReadyResolve=e}),t.openCanceller=new L(function(e,n){t.cancelOpen=n})},t.prototype.delete=function(){var e=this,t=arguments.length>0,n=this._state;return new L(function(r,i){var a=function(){e.close();var t=e._deps.indexedDB.deleteDatabase(e.name);t.onsuccess=R(function(){nr.remove(e.name),r()}),t.onerror=X(i),t.onblocked=e._fireOnBlocked};if(t)throw new A.InvalidArgument(`Arguments not allowed in db.delete()`);n.isBeingOpened?n.dbReadyPromise.then(a):a()})},t.prototype.backendDB=function(){return this.idbdb},t.prototype.isOpen=function(){return this.idbdb!==null},t.prototype.hasBeenClosed=function(){var e=this._state.dbOpenError;return e&&e.name===`DatabaseClosed`},t.prototype.hasFailed=function(){return this._state.dbOpenError!==null},t.prototype.dynamicallyOpened=function(){return this._state.autoSchema},Object.defineProperty(t.prototype,`tables`,{get:function(){var e=this;return n(this._allTables).map(function(t){return e._allTables[t]})},enumerable:!0,configurable:!0}),t.prototype.transaction=function(){var e=cr.apply(this,arguments);return this._transaction.apply(this,e)},t.prototype._transaction=function(e,t,n){var r=this,i=F.trans;(!i||i.db!==this||e.indexOf(`!`)!==-1)&&(i=null);var a=e.indexOf(`?`)!==-1;e=e.replace(`!`,``).replace(`?`,``);var o,s;try{if(s=t.map(function(e){var t=e instanceof r.Table?e.name:e;if(typeof t!=`string`)throw TypeError(`Invalid table argument to Dexie.transaction(). Only Table or String are allowed`);return t}),e==`r`||e===qt)o=qt;else if(e==`rw`||e==Jt)o=Jt;else throw new A.InvalidArgument(`Invalid transaction mode: `+e);if(i){if(i.mode===qt&&o===Jt)if(a)i=null;else throw new A.SubTransaction(`Cannot enter a sub-transaction with READWRITE mode when parent transaction is READONLY`);i&&s.forEach(function(e){if(i&&i.storeNames.indexOf(e)===-1)if(a)i=null;else throw new A.SubTransaction(`Table `+e+` not included in parent transaction.`)}),a&&i&&!i.active&&(i=null)}}catch(e){return i?i._promise(null,function(t,n){n(e)}):U(e)}var c=lr.bind(null,this,o,s,i,n);return i?i._promise(o,c,`lock`):F.trans?jt(F.transless,function(){return r._whenReady(c)}):this._whenReady(c)},t.prototype.table=function(e){if(!c(this._allTables,e))throw new A.InvalidTable(`Table `+e+` does not exist`);return this._allTables[e]},t}(),$=pr;l($,e(e({},ke),{delete:function(e){return new $(e).delete()},exists:function(e){return new $(e,{addons:[]}).open().then(function(e){return e.close(),!0}).catch(`NoSuchDatabaseError`,function(){return!1})},getDatabaseNames:function(e){return nr?nr.getDatabaseNames().then(e):L.resolve([])},defineClass:function(){function e(e){a(this,e)}return e},ignoreTransaction:function(e){return F.trans?jt(F.transless,e):e()},vip:ar,async:function(e){return function(){try{var t=sr(e.apply(this,arguments));return!t||typeof t.then!=`function`?L.resolve(t):t}catch(e){return U(e)}}},spawn:function(e,t,n){try{var r=sr(e.apply(n,t||[]));return!r||typeof r.then!=`function`?L.resolve(r):r}catch(e){return U(e)}},currentTransaction:{get:function(){return F.trans||null}},waitFor:function(e,t){var n=L.resolve(typeof e==`function`?$.ignoreTransaction(e):e).timeout(t||6e4);return F.trans?F.trans.waitFor(n):n},Promise:L,debug:{get:function(){return D},set:function(e){me(e,e===`dexie`?function(){return!0}:Gt)}},derive:f,extend:a,props:l,override:_,Events:Qt,getByKeyPath:x,setByKeyPath:S,delByKeyPath:te,shallowClone:C,deepClone:w,getObjectDiff:ue,asap:y,minKey:zt,addons:[],connections:Vt,errnames:Te,dependencies:(function(){try{return{indexedDB:i.indexedDB||i.mozIndexedDB||i.webkitIndexedDB||i.msIndexedDB,IDBKeyRange:i.IDBKeyRange||i.webkitIDBKeyRange}}catch{return{indexedDB:null,IDBKeyRange:null}}})(),semVer:Rt,version:Rt.split(`.`).map(function(e){return parseInt(e)}).reduce(function(e,t,n){return e+t/10**(n*2)}),default:$,Dexie:$})),$.maxKey=Sn($.dependencies.IDBKeyRange),ir(pr.dependencies.indexedDB),L.rejectionMapper=Oe,me(D,Gt);export{pr as t}; |