(function(n,t,i){"use strict";function s(n,t){return typeof t!="object"&&(t=t()),Object.keys(t).forEach(function(i){n[i]=t[i]}),n}function p(n){return{from:function(t){return n.prototype=Object.create(t.prototype),n.prototype.constructor=n,{extend:function(i){s(n.prototype,typeof i!="object"?i(t.prototype):i)}}}}}function w(n,t){return t(n)}function u(n,t){function cr(){b.on("versionchange",function(){b.close();b.on("error").fire(new nt("Database version changed by other database connection."))})}function gi(n){this._cfg={version:n,storesSource:null,dbschema:{},tables:{},contentUpgrade:null};this.stores({})}function lr(n,t,i,u){var e,f,s,h,l,c;if(n===0)Object.keys(st).forEach(function(n){nr(t,n,st[n].primKey,st[n].indexes)}),e=b._createTransaction(yt,fi,st),e.idbtrans=t,e.idbtrans.onerror=o(i,["populating database"]),e.on("error").subscribe(i),r.newPSD(function(){r.PSD.trans=e;try{b.on("populate").fire(e)}catch(n){u.onerror=t.onerror=function(n){n.preventDefault()};try{t.abort()}catch(f){}t.db.close();i(n)}});else{if(f=[],s=ui.filter(function(t){return t._cfg.version===n})[0],!s)throw new nt("Dexie specification of currently installed DB version is missing");st=b._dbSchema=s._cfg.dbschema;h=!1;l=ui.filter(function(t){return t._cfg.version>n});l.forEach(function(n){var e=st,r=n._cfg.dbschema,u;or(e,t);or(r,t);st=b._dbSchema=r;u=ar(e,r);u.add.forEach(function(n){f.push(function(t,i){nr(t,n[0],n[1].primKey,n[1].indexes);i()})});u.change.forEach(function(n){if(n.recreate)throw new nt("Not yet support for changing primary key");else f.push(function(t,i){var r=t.objectStore(n.name);n.add.forEach(function(n){tr(r,n)});n.change.forEach(function(n){r.deleteIndex(n.name);tr(r,n)});n.del.forEach(function(n){r.deleteIndex(n)});i()})});n._cfg.contentUpgrade&&f.push(function(t,u){var f,e;h=!0;f=b._createTransaction(yt,[].slice.call(t.db.objectStoreNames,0),r);f.idbtrans=t;e=0;f._promise=w(f._promise,function(n){return function(t,i,r){function f(n){return function(){n.apply(this,arguments);--e==0&&u()}}return++e,n.call(this,t,function(n,t){arguments[0]=f(n);arguments[1]=f(t);i.apply(this,arguments)},r)}});t.onerror=o(i,["running upgrader function for version",n._cfg.version]);f.on("error").subscribe(i);n._cfg.contentUpgrade(f);e===0&&u()});h&&dr()||f.push(function(n,t){yr(r,n);t()})});c=function(){try{f.length?f.shift()(t,c):vr(st,t)}catch(n){u.onerror=t.onerror=function(n){n.preventDefault()};try{t.abort()}catch(r){}t.db.close();i(n)}};c()}}function ar(n,t){var f={del:[],add:[],change:[]},r,e,o,i,c,s,u,l,h;for(r in n)t[r]||f.del.push(r);for(r in t)if(e=n[r],o=t[r],e)if(i={name:r,def:t[r],recreate:!1,del:[],add:[],change:[]},e.primKey.src!==o.primKey.src)i.recreate=!0,f.change.push(i);else{c=e.indexes.reduce(function(n,t){return n[t.name]=t,n},{});s=o.indexes.reduce(function(n,t){return n[t.name]=t,n},{});for(u in c)s[u]||i.del.push(u);for(u in s)l=c[u],h=s[u],l?l.src!==h.src&&i.change.push(h):i.add.push(h);(i.recreate||i.del.length>0||i.add.length>0||i.change.length>0)&&f.change.push(i)}else f.add.push([r,o]);return f}function nr(n,t,i,r){var u=n.db.createObjectStore(t,i.keyPath?{keyPath:i.keyPath,autoIncrement:i.auto}:{autoIncrement:i.auto});return r.forEach(function(n){tr(u,n)}),u}function vr(n,t){Object.keys(n).forEach(function(i){t.db.objectStoreNames.contains(i)||nr(t,i,n[i].primKey,n[i].indexes)})}function yr(n,t){for(var u,r=0;rt?1:0}function fr(n,t){return nt?-1:0}function er(n){return function(t,i){for(var r=0,u;;){if(u=n(t[r],i[r]),u!==0)return u;if(++r,r===t.length||r===i.length)return n(t.length,i.length)}}}function ki(n,t){return n?t?function(){return n.apply(this,arguments)&&t.apply(this,arguments)}:n:t}function dr(){return navigator.userAgent.indexOf("Trident")>=0||navigator.userAgent.indexOf("MSIE")>=0}function gr(){if(b.verno=it.version/10,b._dbSchema=st={},fi=[].slice.call(it.objectStoreNames,0),fi.length!==0){var n=it.transaction(ot(fi),"readonly");fi.forEach(function(t){for(var u,s,r=n.objectStore(t),i=r.keyPath,f=i&&typeof i=="string"&&i.indexOf(".")!==-1,h=new a(i,i||"",!1,!1,!!r.autoIncrement,i&&typeof i!="string",f),o=[],e=0;e0&&(ci=!1),!vi)throw new nt("indexedDB API not found. If using IE10+, make sure to run your code on a server URL (not locally). If using Safari, make sure to include indexedDB polyfill.");if(u=ci?vi.open(n):vi.open(n,Math.round(b.verno*10)),!u)throw new nt("IndexedDB API not available");u.onerror=o(f,["opening database",n]);u.onblocked=function(n){b.on("blocked").fire(n)};u.onupgradeneeded=d(function(t){var i,r;ci&&!b._allowEmptyDB?(u.onerror=function(n){n.preventDefault()},u.transaction.abort(),u.result.close(),i=vi.deleteDatabase(n),i.onsuccess=i.onerror=function(){f(new nt("Database '"+n+"' doesnt exist"))}):(t.oldVersion===0&&(s=!0),u.transaction.onerror=o(f),r=t.oldVersion>Math.pow(2,62)?0:t.oldVersion,lr(r/10,u.transaction,f,u))},f);u.onsuccess=d(function(){pi=!1;it=u.result;ci?gr():it.objectStoreNames.length>0&&or(st,it.transaction(ot(it.objectStoreNames),ti));it.onversionchange=b.on("versionchange").fire;sr||ft(function(t){if(t.indexOf(n)===-1)return t.push(n)});r.newPSD(function(){function i(){hi=!1;ri.forEach(function(n){n.resume()});ri=[];t(b)}r.PSD.letThrough=!0;try{var n=b.on.ready.fire();n&&typeof n.then=="function"?n.then(i,function(n){it.close();it=null;f(n)}):y(i)}catch(u){f(u)}})},f)}catch(h){f(h)}})};this.close=function(){it&&(it.close(),it=null,hi=!0,ei=null)};this.delete=function(){var t=arguments;return new r(function(i,r){function u(){b.close();var t=vi.deleteDatabase(n);t.onsuccess=function(){sr||ft(function(t){var i=t.indexOf(n);if(i>=0)return t.splice(i,1)});i()};t.onerror=o(r,["deleting",n]);t.onblocked=function(){b.on("blocked").fire()}}if(t.length>0)throw new nt("Arguments not allowed in db.delete()");pi?ri.push({resume:u}):u()})};this.backendDB=function(){return it};this.isOpen=function(){return it!==null};this.hasFailed=function(){return ei!==null};this.dynamicallyOpened=function(){return ci};this.name=n;Object.defineProperty(this,"tables",{get:function(){return Object.keys(dt).map(function(n){return dt[n]})}});this.on=v(this,"error","populate","blocked",{ready:[bt,f],versionchange:[pt,f]});this.on.ready.subscribe=w(this.on.ready.subscribe,function(n){return function(t,i){function r(){return i||b.on.ready.unsubscribe(r),t.apply(this,arguments)}n.call(this,r);b.isOpen()&&(hi?ri.push({resume:r}):r())}});k(function(){b.on("populate").fire(b._createTransaction(yt,fi,st));b.on("error").fire(new nt)});this.transaction=function(n,t,i){function s(t,e){var s=null,c,a,h;try{if(f)throw f;s=b._createTransaction(n,o,st,u);c=o.map(function(n){return s.tables[n]});c.push(s);h=0;r.newPSD(function(){r.PSD.trans=s;s.scopeFunc=i;u&&(s.idbtrans=u.idbtrans,s._promise=w(s._promise,function(n){return function(t,i,u){function f(n){return function(t){var i;return r._rootExec(function(){i=n(t);r._tickFinalize(function(){--h==0&&s.active&&(s.active=!1,s.on.complete.fire())})}),i}}return++h,n.call(this,t,function(n,t,r){return i(f(n),f(t),r)},u)}}));s.complete(function(){t(a)});s.error(function(n){s.idbtrans&&(s.idbtrans.onerror=ht);try{s.abort()}catch(i){}u&&(u.active=!1,u.on.error.fire(n));var t=e(n);u||t||b.on.error.fire(n)});r._rootExec(function(){a=i.apply(s,c)})});(!s.idbtrans||u&&h===0)&&s._nop()}catch(l){s&&s.idbtrans&&(s.idbtrans.onerror=ht);s&&s.abort();u&&u.on.error.fire(l);y(function(){e(l)||b.on("error").fire(l)})}}var u,e;t=[].slice.call(arguments,1,arguments.length-1);i=arguments[arguments.length-1];u=r.PSD&&r.PSD.trans;u&&u.db===b&&n.indexOf("!")===-1||(u=null);e=n.indexOf("?")!==-1;n=n.replace("!","").replace("?","");var h=Array.isArray(t[0])?t.reduce(function(n,t){return n.concat(t)}):t,f=null,o=h.map(function(n){return typeof n=="string"?n:(n instanceof oi||(f=f||new yi("Invalid type. Arguments following mode must be instances of Table or String")),n.name)});return n=="r"||n==ti?n=ti:n=="rw"||n==yt?n=yt:f=new nt("Invalid transaction mode: "+n),u&&(f||(u&&u.mode===ti&&n===yt&&(e?u=null:f=f||new nt("Cannot enter a sub-transaction with READWRITE mode when parent transaction is READONLY")),u&&o.forEach(function(n){u.tables.hasOwnProperty(n)||(e?u=null:f=f||new nt("Table "+n+" not included in parent transaction. Parent Transaction function: "+u.scopeFunc.toString()))}))),u?u._promise(n,s,"lock"):b._whenReady(s)};this.table=function(n){if(e&&ci)return new wi(n);if(!dt.hasOwnProperty(n))throw new nt("Table does not exist");return dt[n]};s(oi.prototype,function(){function n(){throw new nt("Current Transaction is READONLY");}return{_trans:function(n,t,i){return this._tpf(n,[this.name],t,i)},_idbstore:function(n,t,i){if(e)return new r(t);var u=this;return this._tpf(n,[this.name],function(n,i,r){t(n,i,r.idbtrans.objectStore(u.name),r)},i)},get:function(n,t){var i=this;return this._idbstore(ti,function(t,r,u){e&&t(i.schema.instanceTemplate);var f=u.get(n);f.onerror=o(r,["getting",n,"from",i.name]);f.onsuccess=function(){t(i.hook.reading.fire(f.result))}}).then(t)},where:function(n){return new li(this,n)},count:function(n){return this.toCollection().count(n)},offset:function(n){return this.toCollection().offset(n)},limit:function(n){return this.toCollection().limit(n)},reverse:function(){return this.toCollection().reverse()},filter:function(n){return this.toCollection().and(n)},each:function(n){var t=this;return e&&n(t.schema.instanceTemplate),this._idbstore(ti,function(i,r,u){var f=u.openCursor();f.onerror=o(r,["calling","Table.each()","on",t.name]);bi(f,null,n,i,r,t.hook.reading.fire)})},toArray:function(n){var t=this;return this._idbstore(ti,function(n,i,r){e&&n([t.schema.instanceTemplate]);var u=[],f=r.openCursor();f.onerror=o(i,["calling","Table.toArray()","on",t.name]);bi(f,null,function(n){u.push(n)},function(){n(u)},i,t.hook.reading.fire)}).then(n)},orderBy:function(n){return new this._collClass(new li(this,n))},toCollection:function(){return new this._collClass(new li(this))},mapToClass:function(n,t){var i,r;return this.schema.mappedClass=n,i=Object.create(n.prototype),t&&ut(i,t),this.schema.instanceTemplate=i,r=function(t){var r,i;if(!t)return t;r=Object.create(n.prototype);for(i in t)t.hasOwnProperty(i)&&(r[i]=t[i]);return r},this.schema.readHook&&this.hook.reading.unsubscribe(this.schema.readHook),this.schema.readHook=r,this.hook("reading",r),n},defineClass:function(n){return this.mapToClass(u.defineClass(n),n)},add:n,put:n,"delete":n,clear:n,update:n}});p(wi).from(oi).extend(function(){return{add:function(n,t){var u=this,r=this.hook.creating.fire;return this._idbstore(yt,function(e,s,l,a){var v={},w,y,p;r!==f&&(w=t||(l.keyPath?c(n,l.keyPath):i),y=r.call(v,w,n,a),w===i&&y!==i&&(l.keyPath?h(n,l.keyPath,y):t=y));p=t?l.add(n,t):l.add(n);p.onerror=o(function(n){if(v.onerror)v.onerror(n);return s(n)},["adding",n,"into",u.name]);p.onsuccess=function(t){var i=l.keyPath;if(i&&h(n,i,t.target.result),v.onsuccess)v.onsuccess(t.target.result);e(p.result)}})},put:function(n,t){var r=this,u=this.hook.creating.fire,e=this.hook.updating.fire;return u!==f||e!==f?this._trans(yt,function(u,f,e){var o=t||r.schema.primKey.keyPath&&c(n,r.schema.primKey.keyPath);o===i?e.tables[r.name].add(n).then(u,f):(e._lock(),n=l(n),e.tables[r.name].where(":id").equals(o).modify(function(){this.value=n}).then(function(i){return i===0?e.tables[r.name].add(n,t):o}).finally(function(){e._unlock()}).then(u,f))}):this._idbstore(yt,function(i,u,f){var e=t?f.put(n,t):f.put(n);e.onerror=o(u,["putting",n,"into",r.name]);e.onsuccess=function(t){var r=f.keyPath;r&&h(n,r,t.target.result);i(e.result)}})},"delete":function(n){return this.hook.deleting.subscribers.length?this.where(":id").equals(n).delete():this._idbstore(yt,function(t,i,r){var u=r.delete(n);u.onerror=o(i,["deleting",n,"from",r.name]);u.onsuccess=function(){t(u.result)}})},clear:function(){return this.hook.deleting.subscribers.length?this.toCollection().delete():this._idbstore(yt,function(n,t,i){var r=i.clear();r.onerror=o(t,["clearing",i.name]);r.onsuccess=function(){n(r.result)}})},update:function(n,t){if(typeof t!="object"||Array.isArray(t))throw new nt("db.update(keyOrObject, modifications). modifications must be an object.");if(typeof n!="object"||Array.isArray(n))return this.where(":id").equals(n).modify(t);Object.keys(t).forEach(function(i){h(n,i,t[i])});var u=c(n,this.schema.primKey.keyPath);return u===i&&r.reject(new nt("Object does not contain its primary key")),this.where(":id").equals(u).modify(t)}}});s(ir.prototype,{_lock:function(){return++this._reculock,this._reculock===1&&r.PSD&&(r.PSD.lockOwnerFor=this),this},_unlock:function(){if(--this._reculock==0)for(r.PSD&&(r.PSD.lockOwnerFor=null);this._blockedFuncs.length>0&&!this._locked();){var n=this._blockedFuncs.shift();try{n()}catch(t){}}return this},_locked:function(){return this._reculock&&(!r.PSD||r.PSD.lockOwnerFor!==this)},_nop:function(n){this.tables[this.storeNames[0]].get(0).then(n)},_promise:function(n,t,i){var f=this;return r.newPSD(function(){var e;return f._locked()?e=new r(function(r,u){f._blockedFuncs.push(function(){f._promise(n,t,i).then(r,u)})}):(e=f.active?new r(function(r,e){if(!f.idbtrans&&n){if(!it)throw ei?new nt("Database not open. Following error in populate, ready or upgrade function made Dexie.open() fail: "+ei):new nt("Database not open");var o=f.idbtrans=it.transaction(ot(f.storeNames),f.mode);o.onerror=function(n){f.on("error").fire(n&&n.target.error);n.preventDefault();f.abort()};o.onabort=function(n){y(function(){f.on("error").fire(new nt("Transaction aborted for unknown reason"))});f.active=!1;f.on("abort").fire(n)};o.oncomplete=function(n){f.active=!1;f.on("complete").fire(n)}}i&&f._lock();try{t(r,e,f)}catch(s){u.ignoreTransaction(function(){f.on("error").fire(s)});f.abort();e(s)}}):r.reject(ni(new nt("Transaction is inactive. Original Scope Function Source: "+f.scopeFunc.toString()))),f.active&&i&&e.finally(function(){f._unlock()})),e.onuncatched=function(n){u.ignoreTransaction(function(){f.on("error").fire(n)});f.abort()},e})},complete:function(n){return this.on("complete",n)},error:function(n){return this.on("error",n)},abort:function(){if(this.idbtrans&&this.active)try{this.active=!1;this.idbtrans.abort();this.on.error.fire(new nt("Transaction Aborted"))}catch(n){}},table:function(n){if(!this.tables.hasOwnProperty(n))throw new nt("Table "+n+" not in transaction");return this.tables[n]}});s(li.prototype,function(){function n(n,t){try{throw t;}catch(i){n._ctx.error=i}return n}function t(n){return Array.prototype.slice.call(n.length===1&&Array.isArray(n[0])?n[0]:n)}function r(n){return n==="next"?function(n){return n.toUpperCase()}:function(n){return n.toLowerCase()}}function u(n){return n==="next"?function(n){return n.toLowerCase()}:function(n){return n.toUpperCase()}}function f(n,t,i,r,u,f){for(var h,s=Math.min(n.length,r.length),o=-1,e=0;e=0?n.substr(0,o)+t[o]+i.substr(o+1):null;u(n[e],h)<0&&(o=e)}return st||n===t&&(i||r)&&!(i&&r))?new this._ctx.collClass(this,function(){return kt.only(n)}).limit(0):new this._ctx.collClass(this,function(){return kt.bound(n,t,!i,!r)})},equals:function(n){return new this._ctx.collClass(this,function(){return kt.only(n)})},above:function(n){return new this._ctx.collClass(this,function(){return kt.lowerBound(n,!0)})},aboveOrEqual:function(n){return new this._ctx.collClass(this,function(){return kt.lowerBound(n)})},below:function(n){return new this._ctx.collClass(this,function(){return kt.upperBound(n,!0)})},belowOrEqual:function(n){return new this._ctx.collClass(this,function(){return kt.upperBound(n)})},startsWith:function(t){return typeof t!="string"?n(new this._ctx.collClass(this),new yi("String expected")):this.between(t,t+String.fromCharCode(65535),!0,!0)},startsWithIgnoreCase:function(t){if(typeof t!="string")return n(new this._ctx.collClass(this),new yi("String expected"));if(t==="")return this.startsWith(t);var r=new this._ctx.collClass(this,function(){return kt.bound(t.toUpperCase(),t.toLowerCase()+String.fromCharCode(65535))});return i(r,function(n,t){return n.indexOf(t)===0},t),r._ondirectionchange=function(){n(r,new nt("reverse() not supported with WhereClause.startsWithIgnoreCase()"))},r},equalsIgnoreCase:function(t){if(typeof t!="string")return n(new this._ctx.collClass(this),new yi("String expected"));var r=new this._ctx.collClass(this,function(){return kt.bound(t.toUpperCase(),t.toLowerCase())});return i(r,function(n,t){return n===t},t),r},anyOf:function(){var f=this._ctx,e=f.table.schema,o=f.index?e.idxByName[f.index]:e.primKey,s=o&&o.compound,n=t(arguments),i=s?er(ii):ii,u,r;return(n.sort(i),n.length===0)?new this._ctx.collClass(this,function(){return kt.only("")}).limit(0):(u=new this._ctx.collClass(this,function(){return kt.bound(n[0],n[n.length-1])}),u._ondirectionchange=function(t){i=t==="next"?ii:fr;s&&(i=er(i));n.sort(i)},r=0,u._addAlgorithm(function(t,u,f){for(var e=t.key;i(e,n[r])>0;)if(++r,r===n.length)return u(f),!1;return i(e,n[r])===0?(u(function(){t.continue()}),!0):(u(function(){t.continue(n[r])}),!1)}),u)},notEqual:function(n){return this.below(n).or(this._ctx.index).above(n)},noneOf:function(){var i=this._ctx,f=i.table.schema,e=i.index?f.idxByName[i.index]:f.primKey,h=e&&e.compound,n=t(arguments),o,r,s,u;return n.length===0?new this._ctx.collClass(this):(o=h?er(ii):ii,n.sort(o),r=n.reduce(function(n,t){return n?n.concat([[n[n.length-1][1],t]]):[[null,t]]},null),r.push([n[n.length-1],null]),s=this,u=i.index,r.reduce(function(n,t){return n?t[1]===null?n.or(u).above(t[0]):n.or(u).between(t[0],t[1],!1,!1):s.below(t[1])},null))},startsWithAnyOf:function(){function h(n){return n>f[r]}function c(n){return n=i[r]&&s<=f[r]?(t(function(){n.continue()}),!0):(t(function(){u===ii?n.continue(i[r]):n.continue(f[r])}),!1)}),o):n(new s.collClass(this),new yi("startsWithAnyOf() only works with strings"))}}});s(ai.prototype,function(){function n(n,t){n.filter=ki(n.filter,t)}function s(n,t){n.isMatch=ki(n.isMatch,t)}function u(n,t){if(n.isPrimKey)return t;var i=n.table.schema.idxByName[n.index];if(!i)throw new nt("KeyPath "+n.index+" on object store "+t.name+" is not indexed");return n.isPrimKey?t:t.index(i.name)}function f(n,t){return u(n,t)[n.op](n.range||null,n.dir+n.unique)}function i(n,t,i,r,u){n.or?function(){function e(){++c==2&&i()}function h(n,i,u){if(!o||o(i,u,e,r)){var f=i.primaryKey.toString();s.hasOwnProperty(f)||(s[f]=!0,t(n,i,u))}}var o=n.filter,s={},l=n.table.schema.primKey.keyPath,c=0;n.or._iterate(h,e,r,u);bi(f(n,u),n.algorithm,h,e,r,n.table.hook.reading.fire)}():bi(f(n,u),ki(n.algorithm,n.filter),t,i,r,n.table.hook.reading.fire)}function t(n){return n.table.schema.instanceTemplate}return{_read:function(n,t){var i=this._ctx;return i.error?i.table._trans(null,function(n,t){t(i.error)}):i.table._idbstore(ti,n).then(t)},_write:function(n){var t=this._ctx;return t.error?t.table._trans(null,function(n,i){i(t.error)}):t.table._idbstore(yt,n,"locked")},_addAlgorithm:function(n){var t=this._ctx;t.algorithm=ki(t.algorithm,n)},_iterate:function(n,t,r,u){return i(this._ctx,n,t,r,u)},each:function(n){var r=this._ctx;return e&&n(t(r)),this._read(function(t,u,f){i(r,n,t,u,f)})},count:function(n){var s,t,f;return e?r.resolve(0).then(n):(s=this,t=this._ctx,t.filter||t.algorithm||t.or?(f=0,this._read(function(n,r,u){i(t,function(){return++f,!1},function(){n(f)},r,u)},n)):this._read(function(n,i,r){var f=u(t,r),e=t.range?f.count(t.range):f.count();e.onerror=o(i,["calling","count()","on",s.name]);e.onsuccess=function(i){n(Math.min(i.target.result,Math.max(0,t.limit-t.offset)))}},n))},sortBy:function(n,t){function r(n,t){return t?r(n[i[t]],t-1):n[e]}function o(n,t){var i=r(n,u),e=r(t,u);return ie?f:0}var s=this._ctx,i=n.split(".").reverse(),e=i[0],u=i.length-1,f=this._ctx.dir==="next"?1:-1;return this.toArray(function(n){return n.sort(o)}).then(t)},toArray:function(n){var r=this._ctx;return this._read(function(n,u,f){e&&n([t(r)]);var o=[];i(r,function(n){o.push(n)},function(){n(o)},u,f)},n)},offset:function(t){var i=this._ctx;return t<=0?this:(i.offset+=t,i.or||i.algorithm||i.filter?n(i,function(){return--t<0}):n(i,function(n,i){return t===0?!0:t===1?(--t,!1):(i(function(){n.advance(t);t=0}),!1)}),this)},limit:function(t){return this._ctx.limit=Math.min(this._ctx.limit,t),n(this._ctx,function(n,i,r){return--t<=0&&i(r),t>=0}),this},until:function(i,r){var u=this._ctx;return e&&i(t(u)),n(this._ctx,function(n,t,u){return i(n.value)?(t(u),r):!0}),this},first:function(n){return this.limit(1).toArray(function(n){return n[0]}).then(n)},last:function(n){return this.reverse().first(n)},and:function(i){return e&&i(t(this._ctx)),n(this._ctx,function(n){return i(n.value)}),s(this._ctx,i),this},or:function(n){return new li(this._ctx.table,n,this)},reverse:function(){return this._ctx.dir=this._ctx.dir==="prev"?"next":"prev",this._ondirectionchange&&this._ondirectionchange(this._ctx.dir),this},desc:function(){return this.reverse()},eachKey:function(n){var i=this._ctx;return e&&n(c(t(this._ctx),this._ctx.index?this._ctx.table.schema.idxByName[this._ctx.index].keyPath:this._ctx.table.schema.primKey.keyPath)),i.isPrimKey||(i.op="openKeyCursor"),this.each(function(t,i){n(i.key,i)})},eachUniqueKey:function(n){return this._ctx.unique="unique",this.eachKey(n)},keys:function(n){var i=this._ctx,t;return(i.isPrimKey||(i.op="openKeyCursor"),t=[],e)?new r(this.eachKey.bind(this)).then(function(n){return[n]}).then(n):this.each(function(n,i){t.push(i.key)}).then(function(){return t}).then(n)},uniqueKeys:function(n){return this._ctx.unique="unique",this.keys(n)},firstKey:function(n){return this.limit(1).keys(function(n){return n[0]}).then(n)},lastKey:function(n){return this.reverse().firstKey(n)},distinct:function(){var t={};return n(this._ctx,function(n){var i=n.primaryKey.toString(),r=t.hasOwnProperty(i);return t[i]=!0,!r}),this}}});p(rr).from(ai).extend({modify:function(n){var a=this,t=this._ctx,r=t.table.hook,i=r.updating.fire,u=r.deleting.fire;return e&&typeof n=="function"&&n.call({value:t.table.schema.instanceTemplate},t.table.schema.instanceTemplate),this._write(function(r,e,v,y){function st(n,i){var r,u,f;if(et=i.primaryKey,r={primKey:i.primaryKey,value:n},w.call(r,n)!==!1)u=!r.hasOwnProperty("value"),f=u?i.delete():i.update(r.value),++ut,f.onerror=o(function(n){if(p.push(n),nt.push(r.primKey),r.onerror)r.onerror(n);return tt(),!0},u?["deleting",n,"from",t.table.name]:["modifying",n,"on",t.table.name]),f.onsuccess=function(){if(r.onsuccess)r.onsuccess(r.value);++b;tt()};else if(r.onsuccess)r.onsuccess(r.value)}function ot(n){return n&&(p.push(n),nt.push(et)),e(new g("Error modifying one or more objects",p,b,nt))}function tt(){ft&&b+p.length===ut&&(p.length>0?ot():r(b))}var w,k,it,d;typeof n=="function"?w=i===f&&u===f?n:function(t){var f=l(t),e,r;if(n.call(this,t)===!1)return!1;this.hasOwnProperty("value")?(e=gt(f,this.value),r=i.call(this,e,this.primKey,f,y),r&&(t=this.value,Object.keys(r).forEach(function(n){h(t,n,r[n])}))):u.call(this,this.primKey,t,y)}:i===f?(k=Object.keys(n),it=k.length,w=function(t){for(var i,u,f=!1,r=0;r0)p();if(c=e.pop(),c)try{c()}catch(y){}}while(e.length>0||u.length>0);i=o;r=!0}}}function d(n){var f=r,t;r=!1;i=l;try{n()}finally{if(f){do{while(u.length>0)p();if(t=e.pop(),t)try{t()}catch(s){}}while(e.length>0||u.length>0);i=o;r=!0}}}function w(n){n._catched=!0;n._parent&&w(n._parent)}function a(n,i){var r=t.PSD;t.PSD=n._PSD;try{if(i===n)throw new TypeError("A promise cannot be resolved with itself.");if(i&&(typeof i=="object"||typeof i=="function")&&typeof i.then=="function"){k(n,function(n,t){i.then(n,t)},function(t){a(n,t)},function(t){h(n,t)});return}n._state=!0;n._value=i;b.call(n)}catch(u){h(u)}finally{t.PSD=r}}function h(n,i){var r=t.PSD;if(t.PSD=n._PSD,n._state=!1,n._value=i,b.call(n),!n._catched)try{if(n.onuncatched)n.onuncatched(n._value);t.on.error.fire(n._value)}catch(u){}return t.PSD=r,n._catched}function b(){for(var n=0,t=this._deferreds.length;n