UNPKG

@liascript/exporter

Version:
14 lines 109 kB
!function(){function e(e,t,n,r){Object.defineProperty(e,t,{get:n,set:r,enumerable:!0,configurable:!0})}var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},n=t.parcelRequire55a5;n.register("dymkU",(function(t,r){e(t.exports,"Connector",(function(){return d}));var i=n("hnmIs"),o=n("9Klpk"),a=n("3bWnf"),u=n("kb0qF"),s=n("bWNdT"),c=n("32Euv"),l=n("frnPj"),f=n("hhkKM"),d=function(e){"use strict";(0,u.default)(n,e);var t=(0,s.default)(n);function n(){var e;return(0,o.default)(this,n),(e=t.call(this)).database=new f.LiaDB,e}return(0,a.default)(n,[{key:"hasIndex",value:function(){return!0}},{key:"open",value:function(e,t,n){var r=this;return(0,i.default)((function(){return(0,c.__generator)(this,(function(i){switch(i.label){case 0:return[4,r.database.open(e,t,{table:"code",id:n})];case 1:return[2,i.sent()]}}))}))()}},{key:"load",value:function(e){return this.database.load(e)}},{key:"store",value:function(e){return this.database.store(e)}},{key:"update",value:function(e,t){this.database.transaction(e,t)}},{key:"slide",value:function(e){this.database.slide(e)}},{key:"getIndex",value:function(){var e=this;return(0,i.default)((function(){return(0,c.__generator)(this,(function(t){switch(t.label){case 0:return[4,e.database.listIndex()];case 1:return[2,t.sent()]}}))}))()}},{key:"deleteFromIndex",value:function(e){this.database.deleteIndex(e)}},{key:"storeToIndex",value:function(e){var t=this;return(0,i.default)((function(){return(0,c.__generator)(this,(function(n){return[2,t.database.storeIndex(e)]}))}))()}},{key:"restoreFromIndex",value:function(e,t){return this.database.restore(e,t)}},{key:"reset",value:function(e,t){var n=this;return(0,i.default)((function(){return(0,c.__generator)(this,(function(r){switch(r.label){case 0:return e&&t?[4,n.database.reset(e,t)]:[3,2];case 1:r.sent(),l.default.info("DB: reset => ",e,t),r.label=2;case 2:return[2]}}))}))()}},{key:"getFromIndex",value:function(e){return this.database.getIndex(e)}},{key:"addMisc",value:function(e,t,n,r){var o=this;return(0,i.default)((function(){return(0,c.__generator)(this,(function(i){return o.database.addMisc(e,t,n,r),[2]}))}))()}},{key:"getMisc",value:function(e,t,n){var r=this;return(0,i.default)((function(){return(0,c.__generator)(this,(function(i){return[2,r.database.getMisc(e,t,n)]}))}))()}}]),n}(n("knzCS").Connector)})),n.register("hhkKM",(function(t,r){e(t.exports,"LiaDB",(function(){return l}));var i=n("hnmIs"),o=n("9Klpk"),a=n("3bWnf"),u=n("32Euv"),s=n("3Zw54"),c=n("frnPj"),l=function(){"use strict";function e(){(0,o.default)(this,e),this.dbIndex=new(0,s.default)("Index"),this.dbIndex.version(1).stores({courses:"&id,updated,author,created,title"}),this.version=0}return(0,a.default)(e,[{key:"open_",value:function(e){var t=new(0,s.default)(e);return t.version(1).stores({code:"[id+version], version",quiz:"[id+version], version",survey:"[id+version], version",task:"[id+version], version",offline:"[id+version], version"}),t}},{key:"open",value:function(e,t,n){var r=this;return(0,i.default)((function(){var i;return(0,u.__generator)(this,(function(o){switch(o.label){case 0:r.version=t,r.db=r.open_(e),o.label=1;case 1:return o.trys.push([1,3,,4]),[4,r.db.open()];case 2:return o.sent(),[3,4];case 3:return i=o.sent(),c.default.warn("DB: open -> ",i.message),r.db=null,[3,4];case 4:return n&&r.db?[4,r.db[n.table].get({id:n.id,version:t})]:[3,6];case 5:return[2,o.sent()];case 6:return[2]}}))}))()}},{key:"store",value:function(e,t){var n=this;return(0,i.default)((function(){return(0,u.__generator)(this,(function(r){switch(r.label){case 0:return n.db&&0!==n.version?(c.default.warn("liaDB: event(store), table(".concat(e.table,"), id(").concat(e.id,"), data(").concat(e.data,")")),[4,n.db[e.table].put({id:e.id,version:null!=t?t:n.version,data:e.data,created:(new Date).getTime()})]):[2];case 1:return r.sent(),[2]}}))}))()}},{key:"load",value:function(e,t){var n=this;return(0,i.default)((function(){var r;return(0,u.__generator)(this,(function(i){switch(i.label){case 0:return n.db?(c.default.info("loading => ",e.table,e.id),[4,n.db[e.table].get({id:e.id,version:null!=t?t:n.version})]):[2];case 1:return(r=i.sent())?(c.default.info("restore table",e.table),[2,r.data]):[2,null]}}))}))()}},{key:"slide",value:function(e){var t=this;return(0,i.default)((function(){var n;return(0,u.__generator)(this,(function(r){switch(r.label){case 0:return r.trys.push([0,3,,4]),[4,t.db.offline.get({id:0,version:t.version})];case 1:return(n=r.sent()).data.section_active=e,[4,t.db.offline.put(n)];case 2:return r.sent(),[3,4];case 3:return r.sent(),c.default.warn("DB: could not update slide => ",e),[3,4];case 4:return[2]}}))}))()}},{key:"transaction",value:function(e,t){var n=this;return(0,i.default)((function(){var r;return(0,u.__generator)(this,(function(o){switch(o.label){case 0:return n.db&&0!==n.version?[4,(r=n.db).transaction("rw",r[e.table],(0,i.default)((function(){var i;return(0,u.__generator)(this,(function(o){switch(o.label){case 0:return[4,r[e.table].get({id:e.id,version:n.version})];case 1:return(i=o.sent()).data?(i.data=t(i.data),[4,r[e.table].put(i)]):[3,3];case 2:o.sent(),o.label=3;case 3:return[2]}}))})))]:[2];case 1:return o.sent(),[2]}}))}))()}},{key:"restore",value:function(e,t){var n=this;return(0,i.default)((function(){var r;return(0,u.__generator)(this,(function(i){switch(i.label){case 0:return[4,n.dbIndex.courses.get(e)];case 1:return i.sent()?[4,n.open_(e).offline.get({id:0,version:null!=t?t:n.version})]:[3,3];case 2:return[2,void 0===(r=i.sent())?null:r.data];case 3:return[2]}}))}))()}},{key:"getIndex",value:function(e){var t=this;return(0,i.default)((function(){var n;return(0,u.__generator)(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,t.dbIndex.courses.get(e)];case 1:return[2,r.sent()];case 2:return n=r.sent(),c.default.warn("DB: getIndex -> ",n.message),[3,3];case 3:return[2,null]}}))}))()}},{key:"listIndex",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"updated",t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=this;return(0,i.default)((function(){var r;return(0,u.__generator)(this,(function(i){switch(i.label){case 0:return[4,n.dbIndex.courses.orderBy(e).toArray()];case 1:return r=i.sent(),t||r.reverse(),[2,r]}}))}))()}},{key:"storeIndex",value:function(e){var t=this;return(0,i.default)((function(){var n,r,i;return(0,u.__generator)(this,(function(o){switch(o.label){case 0:return t.dbIndex.isOpen()?(n=new Date,[4,t.dbIndex.courses.get(e.readme)]):(c.default.warn("DB: storeIndex ... db is closed"),[2]);case 1:return(r=o.sent())||(r={id:e.readme,title:e.definition.str_title,author:e.definition.author,created:n.getTime(),updated:null,updated_str:null,data:{}}),r.updated=n.getTime(),r.updated_str=n.toLocaleDateString(),r.data[e.version]?[3,3]:(r.data[e.version]=e.definition,r.data[e.version].title=e.title,c.default.info("storing new version to index",r),[4,t.db.offline.put({id:0,version:e.version,data:e,created:n.getTime(),misc:{}})]);case 2:return o.sent(),[3,6];case 3:return r.data[e.version].version===e.definition.version?[3,6]:(r.data[e.version]=e.definition,r.data[e.version].title=e.title,c.default.info("storing new version to index",r),[4,(i=t.open_(e.readme)).open()]);case 4:return o.sent(),[4,i.offline.put({id:0,version:e.version,data:e,created:n.getTime(),misc:{}})];case 5:o.sent(),o.label=6;case 6:return t.dbIndex.courses.put(r).then((function(e){c.default.info("DB: storeIndex",e)})),[2]}}))}))()}},{key:"addMisc",value:function(e,t,n,r){var o=this;return(0,i.default)((function(){var a;return(0,u.__generator)(this,(function(s){switch(s.label){case 0:return[4,(a=o.open_(e)).open()];case 1:return s.sent(),[4,a.transaction("rw",a.offline,(0,i.default)((function(){var e;return(0,u.__generator)(this,(function(i){switch(i.label){case 0:return[4,a.offline.get({id:0,version:t||o.version})];case 1:return(e=i.sent())?(e.misc[n]=r,[4,a.offline.put(e)]):[3,3];case 2:i.sent(),i.label=3;case 3:return[2]}}))})))];case 2:return s.sent(),[2]}}))}))()}},{key:"getMisc",value:function(e,t,n){var r=this;return(0,i.default)((function(){var i,o;return(0,u.__generator)(this,(function(a){switch(a.label){case 0:return[4,(i=r.open_(e)).open()];case 1:return a.sent(),[4,i.offline.get({id:0,version:t||r.version})];case 2:return o=a.sent(),n?[2,null==o?void 0:o.misc[n]]:[2,null==o?void 0:o.misc]}}))}))()}},{key:"deleteIndex",value:function(e){var t=this;return(0,i.default)((function(){return(0,u.__generator)(this,(function(n){switch(n.label){case 0:return[4,Promise.all([t.dbIndex.courses.delete(e),s.default.delete(e)])];case 1:return n.sent(),[2]}}))}))()}},{key:"reset",value:function(e,t){var n=this;return(0,i.default)((function(){var r;return(0,u.__generator)(this,(function(i){switch(i.label){case 0:return[4,(r=n.open_(e)).open()];case 1:return i.sent(),[4,Promise.all([r.code.where("version").equals(t).delete(),r.quiz.where("version").equals(t).delete(),r.survey.where("version").equals(t).delete(),r.task.where("version").equals(t).delete()])];case 2:return i.sent(),[2]}}))}))()}}]),e}()})),n.register("3Zw54",(function(r,i){e(r.exports,"default",(function(){return gr})); /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ var o=n("rJmE6"),a=function(e,t){return a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},a(e,t)},u=function(){return u=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},u.apply(this,arguments)};function s(e,t,n){if(n||2===arguments.length)for(var r,i=0,o=t.length;i<o;i++)!r&&i in t||(r||(r=Array.prototype.slice.call(t,0,i)),r[i]=t[i]);return e.concat(r||Array.prototype.slice.call(t))}var c="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:t,l=Object.keys,f=Array.isArray;function d(e,t){return"object"!=typeof t||l(t).forEach((function(n){e[n]=t[n]})),e}"undefined"==typeof Promise||c.Promise||(c.Promise=Promise);var h=Object.getPrototypeOf,p={}.hasOwnProperty;function v(e,t){return p.call(e,t)}function y(e,t){"function"==typeof t&&(t=t(h(e))),("undefined"==typeof Reflect?l:Reflect.ownKeys)(t).forEach((function(n){b(e,n,t[n])}))}var m=Object.defineProperty;function b(e,t,n,r){m(e,t,d(n&&v(n,"get")&&"function"==typeof n.get?{get:n.get,set:n.set,configurable:!0}:{value:n,configurable:!0,writable:!0},r))}function g(e){return{from:function(t){return e.prototype=Object.create(t.prototype),b(e.prototype,"constructor",e),{extend:y.bind(null,e.prototype)}}}}var w=Object.getOwnPropertyDescriptor;function _(e,t){var n;return w(e,t)||(n=h(e))&&_(n,t)}var k=[].slice;function x(e,t,n){return k.call(e,t,n)}function O(e,t){return t(e)}function P(e){if(!e)throw new Error("Assertion Failed")}function K(e){c.setImmediate?setImmediate(e):setTimeout(e,0)}function S(e,t){if("string"==typeof t&&v(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=S(e,t[r]);n.push(o)}return n}var a=t.indexOf(".");if(-1!==a){var u=e[t.substr(0,a)];return null==u?void 0:S(u,t.substr(a+1))}}function E(e,t,n){if(e&&void 0!==t&&(!("isFrozen"in Object)||!Object.isFrozen(e)))if("string"!=typeof t&&"length"in t){P("string"!=typeof n&&"length"in n);for(var r=0,i=t.length;r<i;++r)E(e,t[r],n[r])}else{var o=t.indexOf(".");if(-1!==o){var a=t.substr(0,o),u=t.substr(o+1);if(""===u)void 0===n?f(e)&&!isNaN(parseInt(a))?e.splice(a,1):delete e[a]:e[a]=n;else{var s=e[a];s&&v(e,a)||(s=e[a]={}),E(s,u,n)}}else void 0===n?f(e)&&!isNaN(parseInt(t))?e.splice(t,1):delete e[t]:e[t]=n}}function I(e){var t={};for(var n in e)v(e,n)&&(t[n]=e[n]);return t}var j=[].concat;function C(e){return j.apply([],e)}var A="BigUint64Array,BigInt64Array,Array,Boolean,String,Date,RegExp,Blob,File,FileList,FileSystemFileHandle,FileSystemDirectoryHandle,ArrayBuffer,DataView,Uint8ClampedArray,ImageBitmap,ImageData,Map,Set,CryptoKey".split(",").concat(C([8,16,32,64].map((function(e){return["Int","Uint","Float"].map((function(t){return t+e+"Array"}))})))).filter((function(e){return c[e]})),T=new Set(A.map((function(e){return c[e]})));function D(e){var t={};for(var n in e)if(v(e,n)){var r=e[n];t[n]=!r||"object"!=typeof r||T.has(r.constructor)?r:D(r)}return t}var q=null;function B(e){q=new WeakMap;var t=R(e);return q=null,t}function R(e){if(!e||"object"!=typeof e)return e;var t=q.get(e);if(t)return t;if(f(e)){t=[],q.set(e,t);for(var n=0,r=e.length;n<r;++n)t.push(R(e[n]))}else if(T.has(e.constructor))t=e;else{var i=h(e);for(var o in t=i===Object.prototype?{}:Object.create(i),q.set(e,t),e)v(e,o)&&(t[o]=R(e[o]))}return t}var M={}.toString;function F(e){return M.call(e).slice(8,-1)}var N="undefined"!=typeof Symbol?Symbol.iterator:"@@iterator",L="symbol"===(void 0===N?"undefined":(0,o.default)(N))?function(e){var t;return null!=e&&(t=e[N])&&t.apply(e)}:function(){return null};function U(e,t){var n=e.indexOf(t);return n>=0&&e.splice(n,1),n>=0}var z={};function W(e){var t,n,r,i;if(1===arguments.length){if(f(e))return e.slice();if(this===z&&"string"==typeof e)return[e];if(i=L(e)){for(n=[];!(r=i.next()).done;)n.push(r.value);return n}if(null==e)return[e];if("number"==typeof(t=e.length)){for(n=new Array(t);t--;)n[t]=e[t];return n}return[e]}for(t=arguments.length,n=new Array(t);t--;)n[t]=arguments[t];return n}var V="undefined"!=typeof Symbol?function(e){return"AsyncFunction"===e[Symbol.toStringTag]}:function(){return!1},Y=["Unknown","Constraint","Data","TransactionInactive","ReadOnly","Version","NotFound","InvalidState","InvalidAccess","Abort","Timeout","QuotaExceeded","Syntax","DataClone"],$=["Modify","Bulk","OpenFailed","VersionChange","Schema","Upgrade","InvalidTable","MissingAPI","NoSuchDatabase","InvalidArgument","SubTransaction","Unsupported","Internal","DatabaseClosed","PrematureCommit","ForeignAwait"].concat(Y),G={VersionChanged:"Database version changed by other database connection",DatabaseClosed:"Database has been closed",Abort:"Transaction aborted",TransactionInactive:"Transaction has already completed or failed",MissingAPI:"IndexedDB API missing. Please visit https://tinyurl.com/y2uuvskb"};function Q(e,t){this.name=e,this.message=t}function X(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.failures=t,this.failedKeys=r,this.successCount=n,this.message=X(e,t)}function J(e,t){this.name="BulkError",this.failures=Object.keys(t).map((function(e){return t[e]})),this.failuresByPos=t,this.message=X(e,this.failures)}g(Q).from(Error).extend({toString:function(){return this.name+": "+this.message}}),g(H).from(Q),g(J).from(Q);var Z=$.reduce((function(e,t){return e[t]=t+"Error",e}),{}),ee=Q,te=$.reduce((function(e,t){var n=function(e,n){this.name=r,e?"string"==typeof e?(this.message="".concat(e).concat(n?"\n "+n:""),this.inner=n||null):"object"==typeof e&&(this.message="".concat(e.name," ").concat(e.message),this.inner=e):(this.message=G[t]||r,this.inner=null)},r=t+"Error";return g(n).from(ee),e[t]=n,e}),{});te.Syntax=SyntaxError,te.Type=TypeError,te.Range=RangeError;var ne=Y.reduce((function(e,t){return e[t+"Error"]=te[t],e}),{}),re=$.reduce((function(e,t){return-1===["Syntax","Type","Range"].indexOf(t)&&(e[t+"Error"]=te[t]),e}),{});function ie(){}function oe(e){return e}function ae(e,t){return null==e||e===oe?t:function(n){return t(e(n))}}function ue(e,t){return function(){e.apply(this,arguments),t.apply(this,arguments)}}function se(e,t){return e===ie?t:function(){var n=e.apply(this,arguments);void 0!==n&&(arguments[0]=n);var r=this.onsuccess,i=this.onerror;this.onsuccess=null,this.onerror=null;var o=t.apply(this,arguments);return r&&(this.onsuccess=this.onsuccess?ue(r,this.onsuccess):r),i&&(this.onerror=this.onerror?ue(i,this.onerror):i),void 0!==o?o:n}}function ce(e,t){return e===ie?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?ue(n,this.onsuccess):n),r&&(this.onerror=this.onerror?ue(r,this.onerror):r)}}function le(e,t){return e===ie?t:function(n){var r=e.apply(this,arguments);d(n,r);var i=this.onsuccess,o=this.onerror;this.onsuccess=null,this.onerror=null;var a=t.apply(this,arguments);return i&&(this.onsuccess=this.onsuccess?ue(i,this.onsuccess):i),o&&(this.onerror=this.onerror?ue(o,this.onerror):o),void 0===r?void 0===a?void 0:a:d(r,a)}}function fe(e,t){return e===ie?t:function(){return!1!==t.apply(this,arguments)&&e.apply(this,arguments)}}function de(e,t){return e===ie?t:function(){var n=e.apply(this,arguments);if(n&&"function"==typeof n.then){for(var r=this,i=arguments.length,o=new Array(i);i--;)o[i]=arguments[i];return n.then((function(){return t.apply(r,o)}))}return t.apply(this,arguments)}}re.ModifyError=H,re.DexieError=Q,re.BulkError=J;var he="undefined"!=typeof location&&/^(http|https):\/\/(localhost|127\.0\.0\.1)/.test(location.href);function pe(e,t){he=e}var ve={},ye=100,me="undefined"==typeof Promise?[]:function(){var e=Promise.resolve();if("undefined"==typeof crypto||!crypto.subtle)return[e,h(e),e];var t=crypto.subtle.digest("SHA-512",new Uint8Array([0]));return[t,h(t),e]}(),be=me[0],ge=me[1],we=me[2],_e=ge&&ge.then,ke=be&&be.constructor,xe=!!we,Oe=function(e,t){Ae.push([e,t]),Ke&&(queueMicrotask(ze),Ke=!1)},Pe=!0,Ke=!0,Se=[],Ee=[],Ie=oe,je={id:"global",global:!0,ref:0,unhandleds:[],onunhandled:ie,pgp:!1,env:{},finalize:ie},Ce=je,Ae=[],Te=0,De=[];function qe(e){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");this._listeners=[],this._lib=!1;var t=this._PSD=Ce;if("function"!=typeof e){if(e!==ve)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,Me(this,e)}var Be={get:function(){var e=function(e,r){var i=this,o=!t.global&&(t!==Ce||n!==Ze),a=o&&!rt(),u=new qe((function(n,u){Le(i,new Re(lt(e,t,o,a),lt(r,t,o,a),n,u,t))}));return this._consoleTask&&(u._consoleTask=this._consoleTask),u},t=Ce,n=Ze;return e.prototype=ve,e},set:function(e){b(this,"then",e&&e.prototype===ve?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 Me(e,t){try{t((function(t){if(null===e._state){if(t===e)throw new TypeError("A promise cannot be resolved with itself.");var n=e._lib&&We();t&&"function"==typeof t.then?Me(e,(function(e,n){t instanceof qe?t._then(e,n):t.then(e,n)})):(e._state=!0,e._value=t,Ne(e)),n&&Ve()}}),Fe.bind(null,e))}catch(t){Fe(e,t)}}function Fe(e,t){if(Ee.push(t),null===e._state){var n=e._lib&&We();t=Ie(t),e._state=!1,e._value=t,function(e){Se.some((function(t){return t._value===e._value}))||Se.push(e)}(e),Ne(e),n&&Ve()}}function Ne(e){var t=e._listeners;e._listeners=[];for(var n=0,r=t.length;n<r;++n)Le(e,t[n]);var i=e._PSD;--i.ref||i.finalize(),0===Te&&(++Te,Oe((function(){0==--Te&&Ye()}),[]))}function Le(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,++Te,Oe(Ue,[n,e,t])}else e._listeners.push(t)}function Ue(e,t,n){try{var r,i=t._value;!t._state&&Ee.length&&(Ee=[]),r=he&&t._consoleTask?t._consoleTask.run((function(){return e(i)})):e(i),t._state||-1!==Ee.indexOf(i)||function(e){for(var t=Se.length;t;)if(Se[--t]._value===e._value)return void Se.splice(t,1)}(t),n.resolve(r)}catch(e){n.reject(e)}finally{0==--Te&&Ye(),--n.psd.ref||n.psd.finalize()}}function ze(){ct(je,(function(){We()&&Ve()}))}function We(){var e=Pe;return Pe=!1,Ke=!1,e}function Ve(){var e,t,n;do{for(;Ae.length>0;)for(e=Ae,Ae=[],n=e.length,t=0;t<n;++t){var r=e[t];r[0].apply(null,r[1])}}while(Ae.length>0);Pe=!0,Ke=!0}function Ye(){var e=Se;Se=[],e.forEach((function(e){e._PSD.onunhandled.call(null,e._value,e)}));for(var t=De.slice(0),n=t.length;n;)t[--n]()}function $e(e){return new qe(ve,!1,e)}function Ge(e,t){var n=Ce;return function(){var r=We(),i=Ce;try{return ut(n,!0),e.apply(this,arguments)}catch(e){t&&t(e)}finally{ut(i,!1),r&&Ve()}}}y(qe.prototype,{then:Be,_then:function(e,t){Le(this,new Re(null,null,e,t,Ce))},catch:function(e){if(1===arguments.length)return this.then(null,e);var t=arguments[0],n=arguments[1];return"function"==typeof t?this.then(null,(function(e){return e instanceof t?n(e):$e(e)})):this.then(null,(function(e){return e&&e.name===t?n(e):$e(e)}))},finally:function(e){return this.then((function(t){return qe.resolve(e()).then((function(){return t}))}),(function(t){return qe.resolve(e()).then((function(){return $e(t)}))}))},timeout:function(e,t){var n=this;return e<1/0?new qe((function(r,i){var o=setTimeout((function(){return i(new te.Timeout(t))}),e);n.then(r,i).finally(clearTimeout.bind(null,o))})):this}}),"undefined"!=typeof Symbol&&Symbol.toStringTag&&b(qe.prototype,Symbol.toStringTag,"Dexie.Promise"),je.env=st(),y(qe,{all:function(){var e=W.apply(null,arguments).map(it);return new qe((function(t,n){0===e.length&&t([]);var r=e.length;e.forEach((function(i,o){return qe.resolve(i).then((function(n){e[o]=n,--r||t(e)}),n)}))}))},resolve:function(e){return e instanceof qe?e:e&&"function"==typeof e.then?new qe((function(t,n){e.then(t,n)})):new qe(ve,!0,e)},reject:$e,race:function(){var e=W.apply(null,arguments).map(it);return new qe((function(t,n){e.map((function(e){return qe.resolve(e).then(t,n)}))}))},PSD:{get:function(){return Ce},set:function(e){return Ce=e}},totalEchoes:{get:function(){return Ze}},newPSD:tt,usePSD:ct,scheduler:{get:function(){return Oe},set:function(e){Oe=e}},rejectionMapper:{get:function(){return Ie},set:function(e){Ie=e}},follow:function(e,t){return new qe((function(n,r){return tt((function(t,n){var r=Ce;r.unhandleds=[],r.onunhandled=n,r.finalize=ue((function(){var e=this;!function(e){De.push((function t(){e(),De.splice(De.indexOf(t),1)})),++Te,Oe((function(){0==--Te&&Ye()}),[])}((function(){0===e.unhandleds.length?t():n(e.unhandleds[0])}))}),r.finalize),e()}),t,n,r)}))}}),ke&&(ke.allSettled&&b(qe,"allSettled",(function(){var e=W.apply(null,arguments).map(it);return new qe((function(t){0===e.length&&t([]);var n=e.length,r=new Array(n);e.forEach((function(e,i){return qe.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&&"undefined"!=typeof AggregateError&&b(qe,"any",(function(){var e=W.apply(null,arguments).map(it);return new qe((function(t,n){0===e.length&&n(new AggregateError([]));var r=e.length,i=new Array(r);e.forEach((function(e,o){return qe.resolve(e).then((function(e){return t(e)}),(function(e){i[o]=e,--r||n(new AggregateError(i))}))}))}))})),ke.withResolvers&&(qe.withResolvers=ke.withResolvers));var Qe={awaits:0,echoes:0,id:0},Xe=0,He=[],Je=0,Ze=0,et=0;function tt(e,t,n,r){var i=Ce,o=Object.create(i);o.parent=i,o.ref=0,o.global=!1,o.id=++et,je.env,o.env=xe?{Promise:qe,PromiseProp:{value:qe,configurable:!0,writable:!0},all:qe.all,race:qe.race,allSettled:qe.allSettled,any:qe.any,resolve:qe.resolve,reject:qe.reject}:{},t&&d(o,t),++i.ref,o.finalize=function(){--this.parent.ref||this.parent.finalize()};var a=ct(o,e,n,r);return 0===o.ref&&o.finalize(),a}function nt(){return Qe.id||(Qe.id=++Xe),++Qe.awaits,Qe.echoes+=ye,Qe.id}function rt(){return!!Qe.awaits&&(0==--Qe.awaits&&(Qe.id=0),Qe.echoes=Qe.awaits*ye,!0)}function it(e){return Qe.echoes&&e&&e.constructor===ke?(nt(),e.then((function(e){return rt(),e}),(function(e){return rt(),dt(e)}))):e}function ot(e){++Ze,Qe.echoes&&0!=--Qe.echoes||(Qe.echoes=Qe.awaits=Qe.id=0),He.push(Ce),ut(e,!0)}function at(){var e=He[He.length-1];He.pop(),ut(e,!1)}function ut(e,t){var n=Ce;if((t?!Qe.echoes||Je++&&e===Ce:!Je||--Je&&e===Ce)||queueMicrotask(t?ot.bind(null,e):at),e!==Ce&&(Ce=e,n===je&&(je.env=st()),xe)){var r=je.env.Promise,i=e.env;(n.global||e.global)&&(Object.defineProperty(c,"Promise",i.PromiseProp),r.all=i.all,r.race=i.race,r.resolve=i.resolve,r.reject=i.reject,i.allSettled&&(r.allSettled=i.allSettled),i.any&&(r.any=i.any))}}function st(){var e=c.Promise;return xe?{Promise:e,PromiseProp:Object.getOwnPropertyDescriptor(c,"Promise"),all:e.all,race:e.race,allSettled:e.allSettled,any:e.any,resolve:e.resolve,reject:e.reject}:{}}function ct(e,t,n,r,i){var o=Ce;try{return ut(e,!0),t(n,r,i)}finally{ut(o,!1)}}function lt(e,t,n,r){return"function"!=typeof e?e:function(){var i=Ce;n&&nt(),ut(t,!0);try{return e.apply(this,arguments)}finally{ut(i,!1),r&&queueMicrotask(rt)}}}function ft(e){Promise===ke&&0===Qe.echoes?0===Je?e():enqueueNativeMicroTask(e):setTimeout(e,0)}-1===(""+_e).indexOf("[native code]")&&(nt=rt=ie);var dt=qe.reject;function ht(e,t,n,r){if(e.idbdb&&(e._state.openComplete||Ce.letThrough||e._vip)){var i=e._createTransaction(t,n,e._dbSchema);try{i.create(),e._state.PR1398_maxLoop=3}catch(i){return i.name===Z.InvalidState&&e.isOpen()&&--e._state.PR1398_maxLoop>0?(console.warn("Dexie: Need to reopen db"),e.close({disableAutoOpen:!1}),e.open().then((function(){return ht(e,t,n,r)}))):dt(i)}return i._promise(t,(function(e,t){return tt((function(){return Ce.trans=i,r(e,t,i)}))})).then((function(e){if("readwrite"===t)try{i.idbtrans.commit()}catch(e){}return"readonly"===t?e:i._completion.then((function(){return e}))}))}if(e._state.openComplete)return dt(new te.DatabaseClosed(e._state.dbOpenError));if(!e._state.isBeingOpened){if(!e._state.autoOpen)return dt(new te.DatabaseClosed);e.open().catch(ie)}return e._state.dbReadyPromise.then((function(){return ht(e,t,n,r)}))}var pt="4.0.11",vt=String.fromCharCode(65535),yt=-1/0,mt="Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.",bt="String expected.",gt=[],wt="__dbnames",_t="readonly",kt="readwrite";function xt(e,t){return e?t?function(){return e.apply(this,arguments)&&t.apply(this,arguments)}:e:t}var Ot={type:3,lower:-1/0,lowerOpen:!1,upper:[[]],upperOpen:!1};function Pt(e){return"string"!=typeof e||/\./.test(e)?function(e){return e}:function(t){return void 0===t[e]&&e in t&&delete(t=B(t))[e],t}}function Kt(){throw te.Type()}function St(e,t){try{var n=Et(e),r=Et(t);if(n!==r)return"Array"===n?1:"Array"===r?-1:"binary"===n?1:"binary"===r?-1:"string"===n?1:"string"===r?-1:"Date"===n?1:"Date"!==r?NaN:-1;switch(n){case"number":case"Date":case"string":return e>t?1:e<t?-1:0;case"binary":return function(e,t){for(var n=e.length,r=t.length,i=n<r?n:r,o=0;o<i;++o)if(e[o]!==t[o])return e[o]<t[o]?-1:1;return n===r?0:n<r?-1:1}(It(e),It(t));case"Array":return function(e,t){for(var n=e.length,r=t.length,i=n<r?n:r,o=0;o<i;++o){var a=St(e[o],t[o]);if(0!==a)return a}return n===r?0:n<r?-1:1}(e,t)}}catch(e){}return NaN}function Et(e){var t=void 0===e?"undefined":(0,o.default)(e);if("object"!==t)return t;if(ArrayBuffer.isView(e))return"binary";var n=F(e);return"ArrayBuffer"===n?"binary":n}function It(e){return e instanceof Uint8Array?e:ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e)}var jt,Ct=((jt=function(){}).prototype._trans=function(e,t,n){var r=function(e,n,r){if(!r.schema[o])throw new te.NotFound("Table "+o+" not part of transaction");return t(r.idbtrans,r)},i=this._tx||Ce.trans,o=this.name,a=he&&"undefined"!=typeof console&&console.createTask&&console.createTask("Dexie: ".concat("readonly"===e?"read":"write"," ").concat(this.name)),u=We();try{var s=i&&i.db._novip===this.db._novip?i===Ce.trans?i._promise(e,r,n):tt((function(){return i._promise(e,r,n)}),{trans:i,transless:Ce.transless||Ce}):ht(this.db,e,[this.name],r);return a&&(s._consoleTask=a,s=s.catch((function(e){return console.trace(e),dt(e)}))),s}finally{u&&Ve()}},jt.prototype.get=function(e,t){var n=this;return e&&e.constructor===Object?this.where(e).first(t):null==e?dt(new te.Type("Invalid argument to Table.get()")):this._trans("readonly",(function(t){return n.core.get({trans:t,key:e}).then((function(e){return n.hook.reading.fire(e)}))})).then(t)},jt.prototype.where=function(e){var t=function(e,t){return 0===St(e,t)};if("string"==typeof e)return new this.db.WhereClause(this,e);if(f(e))return new this.db.WhereClause(this,"[".concat(e.join("+"),"]"));var n=l(e);if(1===n.length)return this.where(n[0]).equals(e[n[0]]);var r=this.schema.indexes.concat(this.schema.primKey).filter((function(e){if(e.compound&&n.every((function(t){return e.keyPath.indexOf(t)>=0}))){for(var t=0;t<n.length;++t)if(-1===n.indexOf(e.keyPath[t]))return!1;return!0}return!1})).sort((function(e,t){return e.keyPath.length-t.keyPath.length}))[0];if(r&&this.db._maxKey!==vt){var i=r.keyPath.slice(0,n.length);return this.where(i).equals(i.map((function(t){return e[t]})))}!r&&he&&console.warn("The query ".concat(JSON.stringify(e)," on ").concat(this.name," would benefit from a ")+"compound index [".concat(n.join("+"),"]"));var o=this.schema.idxByName,a=n.reduce((function(n,r){var i=n[0],a=n[1],u=o[r],s=e[r];return[i||u,i||!u?xt(a,u&&u.multi?function(e){var n=S(e,r);return f(n)&&n.some((function(e){return t(s,e)}))}:function(e){return t(s,S(e,r))}):a]}),[null,null]),u=a[0],s=a[1];return u?this.where(u.name).equals(e[u.keyPath]).filter(s):r?this.filter(s):this.where(n).equals("")},jt.prototype.filter=function(e){return this.toCollection().and(e)},jt.prototype.count=function(e){return this.toCollection().count(e)},jt.prototype.offset=function(e){return this.toCollection().offset(e)},jt.prototype.limit=function(e){return this.toCollection().limit(e)},jt.prototype.each=function(e){return this.toCollection().each(e)},jt.prototype.toArray=function(e){return this.toCollection().toArray(e)},jt.prototype.toCollection=function(){return new this.db.Collection(new this.db.WhereClause(this))},jt.prototype.orderBy=function(e){return new this.db.Collection(new this.db.WhereClause(this,f(e)?"[".concat(e.join("+"),"]"):e))},jt.prototype.reverse=function(){return this.toCollection().reverse()},jt.prototype.mapToClass=function(e){var t,n,r=this.db,i=this.name;this.schema.mappedClass=e,e.prototype instanceof Kt&&(n=function(){return null!==t&&t.apply(this,arguments)||this},function(e,t){var n=function(){this.constructor=e};if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");a(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(n,t=e),Object.defineProperty(n.prototype,"db",{get:function(){return r},enumerable:!1,configurable:!0}),n.prototype.table=function(){return i},e=n);for(var o=new Set,u=e.prototype;u;u=h(u))Object.getOwnPropertyNames(u).forEach((function(e){return o.add(e)}));var s=function(t){if(!t)return t;var n=Object.create(e.prototype);for(var r in t)if(!o.has(r))try{n[r]=t[r]}catch(e){}return n};return this.schema.readHook&&this.hook.reading.unsubscribe(this.schema.readHook),this.schema.readHook=s,this.hook("reading",s),e},jt.prototype.defineClass=function(){return this.mapToClass((function(e){d(this,e)}))},jt.prototype.add=function(e,t){var n=this,r=this.schema.primKey,i=r.auto,o=r.keyPath,a=e;return o&&i&&(a=Pt(o)(e)),this._trans("readwrite",(function(e){return n.core.mutate({trans:e,type:"add",keys:null!=t?[t]:null,values:[a]})})).then((function(e){return e.numFailures?qe.reject(e.failures[0]):e.lastResult})).then((function(t){if(o)try{E(e,o,t)}catch(e){}return t}))},jt.prototype.update=function(e,t){if("object"!=typeof e||f(e))return this.where(":id").equals(e).modify(t);var n=S(e,this.schema.primKey.keyPath);return void 0===n?dt(new te.InvalidArgument("Given object does not contain its primary key")):this.where(":id").equals(n).modify(t)},jt.prototype.put=function(e,t){var n=this,r=this.schema.primKey,i=r.auto,o=r.keyPath,a=e;return o&&i&&(a=Pt(o)(e)),this._trans("readwrite",(function(e){return n.core.mutate({trans:e,type:"put",values:[a],keys:null!=t?[t]:null})})).then((function(e){return e.numFailures?qe.reject(e.failures[0]):e.lastResult})).then((function(t){if(o)try{E(e,o,t)}catch(e){}return t}))},jt.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?qe.reject(e.failures[0]):void 0}))},jt.prototype.clear=function(){var e=this;return this._trans("readwrite",(function(t){return e.core.mutate({trans:t,type:"deleteRange",range:Ot})})).then((function(e){return e.numFailures?qe.reject(e.failures[0]):void 0}))},jt.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)}))}))}))},jt.prototype.bulkAdd=function(e,t,n){var r=this,i=Array.isArray(t)?t:void 0,o=(n=n||(i?void 0:t))?n.allKeys:void 0;return this._trans("readwrite",(function(t){var n=r.schema.primKey,a=n.auto,u=n.keyPath;if(u&&i)throw new te.InvalidArgument("bulkAdd(): keys argument invalid on tables with inbound keys");if(i&&i.length!==e.length)throw new te.InvalidArgument("Arguments objects and keys must have the same length");var s=e.length,c=u&&a?e.map(Pt(u)):e;return r.core.mutate({trans:t,type:"add",keys:i,values:c,wantResults:o}).then((function(e){var t=e.numFailures,n=e.results,i=e.lastResult,a=e.failures;if(0===t)return o?n:i;throw new J("".concat(r.name,".bulkAdd(): ").concat(t," of ").concat(s," operations failed"),a)}))}))},jt.prototype.bulkPut=function(e,t,n){var r=this,i=Array.isArray(t)?t:void 0,o=(n=n||(i?void 0:t))?n.allKeys:void 0;return this._trans("readwrite",(function(t){var n=r.schema.primKey,a=n.auto,u=n.keyPath;if(u&&i)throw new te.InvalidArgument("bulkPut(): keys argument invalid on tables with inbound keys");if(i&&i.length!==e.length)throw new te.InvalidArgument("Arguments objects and keys must have the same length");var s=e.length,c=u&&a?e.map(Pt(u)):e;return r.core.mutate({trans:t,type:"put",keys:i,values:c,wantResults:o}).then((function(e){var t=e.numFailures,n=e.results,i=e.lastResult,a=e.failures;if(0===t)return o?n:i;throw new J("".concat(r.name,".bulkPut(): ").concat(t," of ").concat(s," operations failed"),a)}))}))},jt.prototype.bulkUpdate=function(e){var t=this,n=this.core,r=e.map((function(e){return e.key})),i=e.map((function(e){return e.changes})),o=[];return this._trans("readwrite",(function(a){return n.getMany({trans:a,keys:r,cache:"clone"}).then((function(u){var s=[],c=[];e.forEach((function(e,n){var r=e.key,i=e.changes,a=u[n];if(a){for(var l=0,f=Object.keys(i);l<f.length;l++){var d=f[l],h=i[d];if(d===t.schema.primKey.keyPath){if(0!==St(h,r))throw new te.Constraint("Cannot update primary key in bulkUpdate()")}else E(a,d,h)}o.push(n),s.push(r),c.push(a)}}));var l=s.length;return n.mutate({trans:a,type:"put",keys:s,values:c,updates:{keys:r,changeSpecs:i}}).then((function(e){var n=e.numFailures,r=e.failures;if(0===n)return l;for(var i=0,a=Object.keys(r);i<a.length;i++){var u=a[i],s=o[Number(u)];if(null!=s){var c=r[u];delete r[u],r[s]=c}}throw new J("".concat(t.name,".bulkUpdate(): ").concat(n," of ").concat(l," operations failed"),r)}))}))}))},jt.prototype.bulkDelete=function(e){var t=this,n=e.length;return this._trans("readwrite",(function(n){return t.core.mutate({trans:n,type:"delete",keys:e})})).then((function(e){var r=e.numFailures,i=e.lastResult,o=e.failures;if(0===r)return i;throw new J("".concat(t.name,".bulkDelete(): ").concat(r," of ").concat(n," operations failed"),o)}))},jt);function At(e){var t=function(e,t,o){if("object"==typeof e)return n(e);t||(t=fe),o||(o=ie);var a={subscribers:[],fire:o,subscribe:function(e){-1===a.subscribers.indexOf(e)&&(a.subscribers.push(e),a.fire=t(a.fire,e))},unsubscribe:function(e){a.subscribers=a.subscribers.filter((function(t){return t!==e})),a.fire=a.subscribers.reduce(t,o)}};return r[e]=i[e]=a,a},n=function(e){l(e).forEach((function(n){var r=e[n];if(f(r))t(n,e[n][0],e[n][1]);else{if("asap"!==r)throw new te.InvalidArgument("Invalid event config");var i=t(n,oe,(function(){for(var e=arguments.length,t=new Array(e);e--;)t[e]=arguments[e];i.subscribers.forEach((function(e){K((function(){e.apply(null,t)}))}))}))}}))},r={},i=function(t,n){if(n){for(var i=arguments.length,o=new Array(i-1);--i;)o[i-1]=arguments[i];return r[t].subscribe.apply(null,o),e}if("string"==typeof t)return r[t]};i.addEventType=t;for(var o=1,a=arguments.length;o<a;++o)t(arguments[o]);return i}function Tt(e,t){return g(t).from({prototype:e}),t}function Dt(e,t){return!(e.filter||e.algorithm||e.or)&&(t?e.justLimit:!e.replayFilter)}function qt(e,t){e.filter=xt(e.filter,t)}function Bt(e,t,n){var r=e.replayFilter;e.replayFilter=r?function(){return xt(r(),t())}:t,e.justLimit=n&&!r}function Rt(e,t){if(e.isPrimKey)return t.primaryKey;var n=t.getIndexByKeyPath(e.index);if(!n)throw new te.Schema("KeyPath "+e.index+" on object store "+t.name+" is not indexed");return n}function Mt(e,t,n){var r=Rt(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 Ft(e,t,n,r){var i=e.replayFilter?xt(e.filter,e.replayFilter()):e.filter;if(e.or){var o={},a=function(e,n,r){if(!i||i(n,r,(function(e){return n.stop(e)}),(function(e){return n.fail(e)}))){var a=n.primaryKey,u=""+a;"[object ArrayBuffer]"===u&&(u=""+new Uint8Array(a)),v(o,u)||(o[u]=!0,t(e,n,r))}};return Promise.all([e.or._iterate(a,n),Nt(Mt(e,r,n),e.algorithm,a,!e.keysOnly&&e.valueMapper)])}return Nt(Mt(e,r,n),xt(e.algorithm,i),t,!e.keysOnly&&e.valueMapper)}function Nt(e,t,n,r){var i=Ge(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=ie}),(function(t){e.fail(t),n=ie}))||i(e.value,e,(function(e){return n=e})),n()}))}))}var Lt,Ut,zt=((Lt=function(e){this["@@propmod"]=e}).prototype.execute=function(e){var t,n=this["@@propmod"];if(void 0!==n.add){var r=n.add;if(f(r))return s(s([],f(e)?e:[],!0),r,!0).sort();if("number"==typeof r)return(Number(e)||0)+r;if("bigint"===(void 0===r?"undefined":(0,o.default)(r)))try{return BigInt(e)+r}catch(e){return BigInt(0)+r}throw new TypeError("Invalid term ".concat(r))}if(void 0!==n.remove){var i=n.remove;if(f(i))return f(e)?e.filter((function(e){return!i.includes(e)})).sort():[];if("number"==typeof i)return Number(e)-i;if("bigint"===(void 0===i?"undefined":(0,o.default)(i)))try{return BigInt(e)-i}catch(e){return BigInt(0)-i}throw new TypeError("Invalid subtrahend ".concat(i))}var a=null===(t=n.replacePrefix)||void 0===t?void 0:t[0];return a&&"string"==typeof e&&e.startsWith(a)?n.replacePrefix[1]+e.substring(a.length):e},Lt),Wt=((Ut=function(){}).prototype._read=function(e,t){var n=this._ctx;return n.error?n.table._trans(null,dt.bind(null,n.error)):n.table._trans("readonly",e).then(t)},Ut.prototype._write=function(e){var t=this._ctx;return t.error?t.table._trans(null,dt.bind(null,t.error)):t.table._trans("readwrite",e,"locked")},Ut.prototype._addAlgorithm=function(e){var t=this._ctx;t.algorithm=xt(t.algorithm,e)},Ut.prototype._iterate=function(e,t){return Ft(this._ctx,e,t,this._ctx.table.core)},Ut.prototype.clone=function(e){var t=Object.create(this.constructor.prototype),n=Object.create(this._ctx);return e&&d(n,e),t._ctx=n,t},Ut.prototype.raw=function(){return this._ctx.valueMapper=null,this},Ut.prototype.each=function(e){var t=this._ctx;return this._read((function(n){return Ft(t,e,n,t.table.core)}))},Ut.prototype.count=function(e){var t=this;return this._read((function(e){var n=t._ctx,r=n.table.core;if(Dt(n,!0))return r.count({trans:e,query:{index:Rt(n,r.schema),range:n.range}}).then((function(e){return Math.min(e,n.limit)}));var i=0;return Ft(n,(function(){return++i,!1}),e,r).then((function(){return i}))})).then(e)},Ut.prototype.sortBy=function(e,t){var n=function(e,t){return St(a(e,o),a(t,o))*u},r=e.split(".").reverse(),i=r[0],o=r.length-1;function a(e,t){return t?a(e[r[t]],t-1):e[i]}var u="next"===this._ctx.dir?1:-1;return this.toArray((function(e){return e.sort(n)})).then(t)},Ut.prototype.toArray=function(e){var t=this;return this._read((function(e){var n=t._ctx;if("next"===n.dir&&Dt(n,!0)&&n.limit>0){var r=n.valueMapper,i=Rt(n,n.table.core.schema);return n.table.core.query({trans:e,limit:n.limit,values:!0,query:{index:i,range:n.range}}).then((function(e){var t=e.result;return r?t.map(r):t}))}var o=[];return Ft(n,(function(e){return o.push(e)}),e,n.table.core).then((function(){return o}))}),e)},Ut.prototype.offset=function(e){var t=this._ctx;return e<=0||(t.offset+=e,Dt(t)?Bt(t,(function(){var t=e;return function(e,n){return 0===t||(1===t?(--t,!1):(n((function(){e.advance(t),t=0})),!1))}})):Bt(t,(function(){var t=e;return function(){return--t<0}}))),this},Ut.prototype.limit=function(e){return this._ctx.limit=Math.min(this._ctx.limit,e),Bt(this._ctx,(function(){var t=e;return function(e,n,r){return--t<=0&&n(r),t>=0}}),!0),this},Ut.prototype.until=function(e,t){return qt(this._ctx,(function(n,r,i){return!e(n.value)||(r(i),t)})),this},Ut.prototype.first=function(e){return this.limit(1).toArray((function(e){return e[0]})).then(e)},Ut.prototype.last=function(e){return this.reverse().first(e)},Ut.prototype.filter=function(e){var t,n;return qt(this._ctx,(function(t){return e(t.value)})),t=this._ctx,n=e,t.isMatch=xt(t.isMatch,n),this},Ut.prototype.and=function(e){return this.filter(e)},Ut.prototype.or=function(e){return new this.db.WhereClause(this._ctx.table,e,this)},Ut.prototype.reverse=function(){return this._ctx.dir="prev"===this._ctx.dir?"next":"prev",this._ondirectionchange&&this._ondirectionchange(this._ctx.dir),this},Ut.prototype.desc=function(){return this.reverse()},Ut.prototype.eachKey=function(e){var t=this._ctx;return t.keysOnly=!t.isMatch,this.each((function(t,n){e(n.key,n)}))},Ut.prototype.eachUniqueKey=function(e){return this._ctx.unique="unique",this.eachKey(e)},Ut.prototype.eachPrimaryKey=function(e){var t=this._ctx;return t.keysOnly=!t.isMatch,this.each((function(t,n){e(n.primaryKey,n)}))},Ut.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)},Ut.prototype.primaryKeys=function(e){var t=this._ctx;if("next"===t.dir&&Dt(t,!0)&&t.limit>0)return this._read((function(e){var n=Rt(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)},Ut.prototype.uniqueKeys=function(e){return this._ctx.unique="unique",this.keys(e)},Ut.prototype.firstKey=function(e){return this.limit(1).keys((function(e){return e[0]})).then(e)},Ut.prototype.lastKey=function(e){return this.reverse().firstKey(e)},Ut.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 qt(this._ctx,(function(e){var t=e.primaryKey.toString(),r=v(n,t);return n[t]=!0,!r})),this},Ut.prototype.modify=function(e){var t=this,n=this._ctx;return this._write((function(r){var i;if("function"==typeof e)i=e;else{var o=l(e),a=o.length;i=function(t){for(var n=!1,r=0;r<a;++r){var i=o[r],u=e[i],s=S(t,i);u instanceof zt?(E(t,i,u.execute(s)),n=!0):s!==u&&(E(t,i,u),n=!0)}return n}}var u=n.table.core,s=u.schema.primaryKey,c=s.outbound,f=s.extractKey,d=200,h=t.db._options.modifyChunkSize;h&&(d="object"==typeof h?h[u.name]||h["*"]||200:h);var p=[],v=0,y=[],m=function(e,t){var n=t.failures,r=t.numFailures;v+=e-r;for(var i=0,o=l(n);i<o.length;i++){var a=o[i];p.push(n[a])}};return t.clone().primaryKeys().then((function(t){var o=Dt(n)&&n.limit===1/0&&("function"!=typeof e||e===Vt)&&{index:n.index,range:n.range},a=function(n){var s=Math.min(d,t.length-n);return u.getMany({trans:r,keys:t.slice(n,n+s),cache:"immutable"}).then((function(l){for(var h=[],p=[],v=c?[]:null,y=[],b=0;b<s;++b){var g=l[b],w={value:B(g),primKey:t[n+b]};!1!==i.call(w,w.value,w)&&(null==w.value?y.push(t[n+b]):c||0===St(f(g),f(w.value))?(p.push(w.value),c&&v.push(t[n+b])):(y.push(t[n+b]),h.push(w.value)))}return Promise.resolve(h.length>0&&u.mutate({trans:r,type:"add",values:h}).then((function(e){for(var t in e.failures)y.splice(parseInt(t),1);m(h.length,e)}))).then((function(){return(p.length>0||o&&"object"==typeof e)&&u.mutate({trans:r,type:"put",keys:v,values:p,criteria:o,changeSpec:"function"!=typeof e&&e,isAdditionalChunk:n>0}).then((function(e){return m(p.length,e)}))})).then((function(){return(y.length>0||o&&e===Vt)&&u.mutate({trans:r,type:"delete",keys:y,criteria:o,isAdditionalChunk:n>0}).then((function(e){return m(y.length,e)}))})).then((function(){return t.length>n+s&&a(n+d)}))}))};return a(0).then((function(){if(p.length>0)throw new H("Error modifying one or more objects",p,v,y);return t.length}))}))}))},Ut.prototype.delete=function(){var e=this._ctx,t=e.range;return Dt(e)&&(e.isPrimKey||3===t.type)?this._write((function(n){var r=e.table.core.schema.primaryKey,i=t;return e.table.core.count({trans:n,query:{index:r,range:i}}).then((function(t){return e.table.core.mutate({trans:n,type:"deleteRange",range:i}).then((function(e){var n=e.failures;e.lastResult,e.results;var r=e.numFailures;if(r)throw new H("Could not delete some values",Object.keys(n).map((function(e){return n[e]})),t-r);return t-r}))}))})):this.modify(Vt)},Ut),Vt=function(e,t){return t.value=null};function Yt(e,t){return e<t?-1:e===t?0:1}function $t(e,t){return e>t?-1:e===t?0:1}function Gt(e,t,n){var r=e instanceof tn?new e.Collection(e):e;return r._ctx.error=n?new n(t):new TypeError(t),r}function Qt(e){return new e.Collection(e,(function(){return Zt("")})).limit(0)}function Xt(e,t,n,r,i,o){for(var a=Math.min(e.length,r.length),u=-1,s=0;s<a;++s){var c=t[s];if(c!==r[s])return i(e[s],n[s])<0?e.substr(0,s)+n[s]+n.substr(s+1):i(e[s],r[s])<0?e.substr(0,s)+r[s]+n.substr(s+1):u>=0?e.substr(0,u)+t[u]+n.substr(u+1):null;i(e[s],c)<0&&(u=s)}return a<r.length&&"next"===o?e+n.substr(e.length):a<e.length&&"prev"===o?e.substr(0,n.length):u<0?null:e.substr(0,u)+r[u]+n.substr(u+1)}function Ht(e,t,n,r){var i,o,a,u,s,c,l,f=function(e){i=function(e){return"next"===e?function(e){return e.toUpperCase()}:function(e){return e.toLowerCase()}}(e),o=function(e){return"next"===e?function(e){return e.toLowerCase()}:function(e){return e.toUpperCase()}}(e),a="next"===e?Yt:$t;var t=n.map((function(e){return{lower:o(e),upper:i(e)}})).sort((function(e,t){return a(e.lower,t.lower)}));u=t.map((function(e){return e.upper})),s=t.map((function(e){return e.lower})),c=e,l="next"===e?"":r},d=n.length;if(!n.every((function(e){return"string"==typeof e})))return Gt(e,bt);f("next");var h=new e.Collection(e,(function(){return Jt(u[0],s[d-1]+r)}));h._ondirectionchange=function(e){f(e)};var p=0;return h._addAlgorithm((function(e,n,r){var i=e.key;if("string"!=typeof i)return!1;var f=o(i);if(t(f,s,p))return!0;for(var h=null,v=p;v<d;++v){var y=Xt(i,f,u[v],s[v],a,c);null===y&&null===h?p=v+1:(null===h||a(h,y)>0)&&(h=y)}return n(null!==h?function(){e.continue(h+l)}:r),!1})),h}function Jt(e,t,n,r){return{type:2,lower:e,upper:t,lowerOpen:n,upperOpen:r}}function Zt(e){return{type:1,lower:e,upper:e}}var en,tn=(en=function(){},Object.defineProperty(en.prototype,"Collection",{get:function(){return this._ctx.table.db.Collection},enumerable:!1,configurable:!0}),en.prototype.between=function(e,t,n,r){n=!1!==n,r=!0===r;try{return this._cmp(e,t)>0||0===this._cmp(e,t)&&(n||r)&&(!n||!r)?Qt(this):new this.Collection(this,(function(){return Jt(e,t,!n,!r)}))}catch(e){return Gt(this,mt)}},en.prototype.equals=function(e){return null==e?Gt(this,mt):new this.Collection(this,(function(){return Zt(e)}))},en.prototype.above=function(e){return null==e?Gt(this,mt):new this.Collection(this,(function(){return Jt(e,void 0,!0)}))},en.prototype.aboveOrEqual=function(e){return null==e?Gt(this,mt):new this.Collection(this,(function(){return Jt(e,void 0,!1)}))},en.prototype.below=function(e){return null==e?Gt(this,mt):new this.Collection(this,(function(){return Jt(void 0,e,!1,!0)}))},en.prototype.belowOrEqual=function(e){return null==e?Gt(this,mt):new this.Collection(this,(function(){return Jt(void 0,e)}))},en.prototype.startsWith=function(e){return"string"!=typeof e?Gt(this,bt):this.between(e,e+vt,!0,!0)},en.prototype.startsWithIgnoreCase=function(e){return""===e?this.startsWith(e):Ht(this,(function(e,t){return 0===e.indexOf(t[0])}),[e],vt)},en.prototype.equalsIgnoreCase=function(e){return Ht(this,(function(e,t){return e===t[0]}),[e],"")},en.prototype.anyOfIgnoreCase=function(){var e=W.apply(z,arguments);return 0===e.length?Qt(this):Ht(this,(function(e,t){return-1!==t.indexOf(e)}),e,"")},en.prototype.startsWithAnyOfIgnoreCase=function(){var e=W.apply(z,arguments);return 0===e.length?Qt(this):Ht(this,(function(e,t){return t.some((function(t){return 0===e.indexOf(t)}))}),e,vt)},en.prototype.anyOf=function(){var e=this,t=W.apply(z,arguments),n=this._cmp;try{t.sort(n)}catch(e){return Gt(this,mt)}if(0===t.length)return Qt(this);var r=new this.Collection(this,(function(){return Jt(t[0],t[t