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