(function(n,t,i,r){"use strict";function h(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){h(n.prototype,typeof i!="object"?i(t.prototype):i)}}}}}function w(n,t){return t(n)}function f(t,b){function ar(){if(i)nt.on("versionchange",function(t){nt.close();t.newVersion&&n.location.reload(!0)})}function nr(n){this._cfg={version:n,storesSource:null,dbschema:{},tables:{},contentUpgrade:null};this.stores({})}function vr(n,t,i,r){var e,f,o,h,l,c;if(n===0)Object.keys(kt).forEach(function(n){tr(t,n,kt[n].primKey,kt[n].indexes)}),e=nt._createTransaction(ni,ei,kt),e.idbtrans=t,e.idbtrans.onerror=s(i,["populating database"]),e.on("error").subscribe(i),u.newPSD(function(){u.PSD.trans=e;try{nt.on("populate").fire(e)}catch(n){r.onerror=t.onerror=function(n){n.preventDefault()};try{t.abort()}catch(f){}t.db.close();i(n)}});else{if(f=[],o=fi.filter(function(t){return t._cfg.version===n})[0],!o)throw new st("Dexie specification of currently installed DB version is missing");kt=nt._dbSchema=o._cfg.dbschema;h=!1;l=fi.filter(function(t){return t._cfg.version>n});l.forEach(function(n){var e=kt,r=n._cfg.dbschema,u;or(e,t);or(r,t);kt=nt._dbSchema=r;u=yr(e,r);u.add.forEach(function(n){f.push(function(t,i){tr(t,n[0],n[1].primKey,n[1].indexes);i()})});u.change.forEach(function(n){if(n.recreate)throw new st("Not yet support for changing primary key");else f.push(function(t,i){var r=t.objectStore(n.name);n.add.forEach(function(n){ir(r,n)});n.change.forEach(function(n){r.deleteIndex(n.name);ir(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=nt._createTransaction(ni,[].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=s(i,["running upgrader function for version",n._cfg.version]);f.on("error").subscribe(i);n._cfg.contentUpgrade(f);e===0&&u()});h&&nu()||f.push(function(n,t){wr(r,n);t()})});c=function(){try{f.length?f.shift()(t,c):pr(kt,t)}catch(n){r.onerror=t.onerror=function(n){n.preventDefault()};t.abort();t.db.close();i(n)}};c()}}function yr(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 tr(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){ir(u,n)}),u}function pr(n,t){Object.keys(n).forEach(function(i){t.db.objectStoreNames.contains(i)||tr(t,i,n[i].primKey,n[i].indexes)})}function wr(n,t){for(var u,i=0;it?1:0}function hr(n,t){return nt?-1:0}function cr(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 di(n,t){return n?t?function(){return n.apply(this,arguments)&&t.apply(this,arguments)}:n:t}function nu(){return navigator.userAgent.indexOf("Trident")>=0||navigator.userAgent.indexOf("MSIE")>=0}function tu(){if(nt.verno=yt.version/10,nt._dbSchema=kt={},ei=[].slice.call(yt.objectStoreNames,0),ei.length!==0){var n=yt.transaction(et(ei),"readonly");ei.forEach(function(t){for(var u,s,r=n.objectStore(t),i=r.keyPath,f=i&&typeof i=="string"&&i.indexOf(".")!==-1,h=new v(i,i||"",!1,!1,!!r.autoIncrement,i&&typeof i!="string",f),o=[],e=0;eMath.pow(2,62)?0:n.oldVersion,vr(u/10,r.transaction,f,r))},f);r.onsuccess=d(function(){pi=!1;yt=r.result;li?tu():yt.objectStoreNames.length>0&&or(kt,yt.transaction(et(yt.objectStoreNames),ri));yt.onversionchange=nt.on("versionchange").fire;sr||ut(function(n){if(n.indexOf(t)===-1)return n.push(t)});u.newPSD(function(){function i(){ci=!1;ui.forEach(function(n){n.resume()});ui=[];n()}u.PSD.letThrough=!0;try{var t=nt.on.ready.fire();t&&typeof t.then=="function"?t.then(i,function(n){yt.close();yt=null;f(n)}):k(i)}catch(r){f(r)}})},f)}catch(o){f(o)}})};this.close=function(){yt&&(yt.close(),yt=null,ci=!0,oi=null)};this.delete=function(){var n=arguments;return new u(function(i,r){function u(){nt.close();var n=yi.deleteDatabase(t);n.onsuccess=function(){sr||ut(function(n){var i=n.indexOf(t);if(i>=0)return n.splice(i,1)});i()};n.onerror=s(r,["deleting",t]);n.onblocked=function(){nt.on("blocked").fire()}}if(n.length>0)throw new st("Arguments not allowed in db.delete()");pi?ui.push({resume:u}):u()})};this.backendDB=function(){return yt};this.isOpen=function(){return yt!==null};this.hasFailed=function(){return oi!==null};this.dynamicallyOpened=function(){return li};this.name=t;Object.defineProperty(this,"tables",{get:function(){return Object.keys(ii).map(function(n){return ii[n]})}});this.on=y(this,"error","populate","blocked",{ready:[bt,e],versionchange:[pt,e]});this.on.ready.subscribe=w(this.on.ready.subscribe,function(n){return function(t,i){function r(){return i||nt.on.ready.unsubscribe(r),t.apply(this,arguments)}n.call(this,r);nt.isOpen()&&(ci?ui.push({resume:r}):r())}});o(function(){nt.on("populate").fire(nt._createTransaction(ni,ei,kt));nt.on("error").fire(new st)});this.transaction=function(n,t,i){function s(t,e){var s=null,c,a,h;try{if(f)throw f;s=nt._createTransaction(n,o,kt,r);c=o.map(function(n){return s.tables[n]});c.push(s);h=0;u.newPSD(function(){u.PSD.trans=s;s.scopeFunc=i;r&&(s.idbtrans=r.idbtrans,s._promise=w(s._promise,function(n){return function(t,i,r){function f(n){return function(t){var i=n(t);return--h==0&&s.active&&u._rootExec(function(){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)},r)}}));s.complete(function(){t(a)});s.error(function(n){s.idbtrans.onerror=ht;s.abort();r&&(r.active=!1,r.on.error.fire(n));var t=e(n);r||t||nt.on.error.fire(n)});a=i.apply(s,c)});(!s.idbtrans||r&&h===0)&&s._nop()}catch(l){s&&s.idbtrans&&(s.idbtrans.onerror=ht);s&&s.abort();r&&r.on.error.fire(l);k(function(){e(l)||nt.on("error").fire(l)})}}var r,e;t=[].slice.call(arguments,1,arguments.length-1);i=arguments[arguments.length-1];r=u.PSD&&u.PSD.trans;r&&r.db===nt&&n.indexOf("!")===-1||(r=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 si||(f=f||new wi("Invalid type. Arguments following mode must be instances of Table or String")),n.name)});return n=="r"||n==ri?n=ri:n=="rw"||n==ni?n=ni:f=new st("Invalid transaction mode: "+n),r&&(f||(r&&r.mode===ri&&n===ni&&(e?r=null:f=f||new st("Cannot enter a sub-transaction with READWRITE mode when parent transaction is READONLY")),r&&o.forEach(function(n){r.tables.hasOwnProperty(n)||(e?r=null:f=f||new st("Table "+n+" not included in parent transaction. Parent Transaction function: "+r.scopeFunc.toString()))}))),r?r._promise(n,s,"lock"):nt._whenReady(s)};this.table=function(n){if(!li&&!ii.hasOwnProperty(n))throw new st("Table does not exist");return ii[n]};h(si.prototype,function(){function n(){throw new st("Current Transaction is READONLY");}return{_trans:function(n,t,i){return this._tpf(n,[this.name],t,i)},_idbstore:function(n,t,i){var r=this;return this._tpf(n,[this.name],function(n,i,u){t(n,i,u.idbtrans.objectStore(r.name),u)},i)},get:function(n,t){var i=this;return o(function(){t(i.schema.instanceTemplate)}),this._idbstore(ri,function(t,r,u){var f=u.get(n);f.onerror=s(r,["getting",n,"from",i.name]);f.onsuccess=function(){t(i.hook.reading.fire(f.result))}}).then(t)},where:function(n){return new ai(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 o(function(){n(t.schema.instanceTemplate)}),this._idbstore(ri,function(i,r,u){var f=u.openCursor();f.onerror=s(r,["calling","Table.each()","on",t.name]);bi(f,null,n,i,r,t.hook.reading.fire)})},toArray:function(n){var t=this;return o(function(){n([t.schema.instanceTemplate])}),this._idbstore(ri,function(n,i,r){var u=[],f=r.openCursor();f.onerror=s(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 ai(this,n))},toCollection:function(){return new this._collClass(new ai(this))},mapToClass:function(n,t){var i,r;return this.schema.mappedClass=n,i=Object.create(n.prototype),this.schema.primKey.keyPath&&(c(i,this.schema.primKey.keyPath,this.schema.primKey.auto?0:""),ot(n.prototype,this.schema.primKey.keyPath)),t&&rt(i,t),this.schema.instanceTemplate=i,r=Object.setPrototypeOf?function(t){return t?(Object.setPrototypeOf(t,n.prototype),t):t}: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(f.defineClass(n),n)},add:n,put:n,"delete":n,clear:n,update:n}});p(rr).from(si).extend(function(){return{add:function(n,t){var u=this,i=this.hook.creating.fire;return this._idbstore(ni,function(f,o,h,a){var v={},w,y,p;i!==e&&(w=t||(h.keyPath?l(n,h.keyPath):r),y=i.call(v,w,n,a),w===r&&y!==r&&(h.keyPath?c(n,h.keyPath,y):t=y));p=t?h.add(n,t):h.add(n);p.onerror=s(function(n){if(v.onerror)v.onerror(n);return o(n)},["adding",n,"into",u.name]);p.onsuccess=function(t){var i=h.keyPath;if(i&&c(n,i,t.target.result),v.onsuccess)v.onsuccess(t.target.result);f(p.result)}})},put:function(n,t){var i=this,u=this.hook.creating.fire,f=this.hook.updating.fire;return u!==e||f!==e?this._trans(ni,function(u,f,e){var o=t||i.schema.primKey.keyPath&&l(n,i.schema.primKey.keyPath);o===r?e.tables[i.name].add(n).then(u,f):(e._lock(),n=a(n),e.tables[i.name].where(":id").equals(o).modify(function(){this.value=n}).then(function(r){return r===0?e.tables[i.name].add(n,t):o}).finally(function(){e._unlock()}).then(u,f))}):this._idbstore(ni,function(r,u,f){var e=t?f.put(n,t):f.put(n);e.onerror=s(u,["putting",n,"into",i.name]);e.onsuccess=function(t){var i=f.keyPath;i&&c(n,i,t.target.result);r(e.result)}})},"delete":function(n){return this.hook.deleting.subscribers.length?this.where(":id").equals(n).delete():this._idbstore(ni,function(t,i,r){var u=r.delete(n);u.onerror=s(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(ni,function(n,t,i){var r=i.clear();r.onerror=s(t,["clearing",i.name]);r.onsuccess=function(){n(r.result)}})},update:function(n,t){if(typeof t!="object"||Array.isArray(t))throw new st("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){c(n,i,t[i])});var i=l(n,this.schema.primKey.keyPath);return i===r&&u.reject(new st("Object does not contain its primary key")),this.where(":id").equals(i).modify(t)}}});h(ur.prototype,{_lock:function(){return++this._reculock,this._reculock===1&&u.PSD&&(u.PSD.lockOwnerFor=this),this},_unlock:function(){if(--this._reculock==0)for(u.PSD&&(u.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&&(!u.PSD||u.PSD.lockOwnerFor!==this)},_nop:function(n){this.tables[this.storeNames[0]].get(0).then(n)},_promise:function(n,t,i){var r=this;return u.newPSD(function(){var e;return r._locked()?e=new u(function(u,f){r._blockedFuncs.push(function(){r._promise(n,t,i).then(u,f)})}):(e=r.active?new u(function(u,e){if(!r.idbtrans&&n){if(!yt)throw oi?new st("Database not open. Following error in populate, ready or upgrade function made Dexie.open() fail: "+oi):new st("Database not open");var o=r.idbtrans=yt.transaction(et(r.storeNames),r.mode);o.onerror=function(n){r.on("error").fire(n&&n.target.error);n.preventDefault();r.abort()};o.onabort=function(n){r.active=!1;r.on("abort").fire(n)};o.oncomplete=function(n){r.active=!1;r.on("complete").fire(n)}}i&&r._lock();try{t(u,e,r)}catch(s){f.spawn(function(){r.on("error").fire(s)});r.abort();e(s)}}):u.reject(gt(new st("Transaction is inactive. Original Scope Function Source: "+r.scopeFunc.toString()))),r.active&&i&&e.finally(function(){r._unlock()})),e.onuncatched=function(n){f.spawn(function(){r.on("error").fire(n)});r.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 st("Transaction Aborted"))}catch(n){}},table:function(n){if(!this.tables.hasOwnProperty(n))throw new st("Table "+n+" not in transaction");return this.tables[n]}});h(ai.prototype,function(){function n(n,t){try{throw t;}catch(i){n._ctx.error=i}return n}function i(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 ti.only(n)}).limit(0):new this._ctx.collClass(this,function(){return ti.bound(n,t,!i,!r)})},equals:function(n){return new this._ctx.collClass(this,function(){return ti.only(n)})},above:function(n){return new this._ctx.collClass(this,function(){return ti.lowerBound(n,!0)})},aboveOrEqual:function(n){return new this._ctx.collClass(this,function(){return ti.lowerBound(n)})},below:function(n){return new this._ctx.collClass(this,function(){return ti.upperBound(n,!0)})},belowOrEqual:function(n){return new this._ctx.collClass(this,function(){return ti.upperBound(n)})},startsWith:function(t){return typeof t!="string"?n(new this._ctx.collClass(this),new wi("String expected")):this.between(t,t+String.fromCharCode(65535),!0,!0)},startsWithIgnoreCase:function(i){if(typeof i!="string")return n(new this._ctx.collClass(this),new wi("String expected"));if(i==="")return this.startsWith(i);var r=new this._ctx.collClass(this,function(){return ti.bound(i.toUpperCase(),i.toLowerCase()+String.fromCharCode(65535))});return t(r,function(n,t){return n.indexOf(t)===0},i),r._ondirectionchange=function(){n(r,new st("reverse() not supported with WhereClause.startsWithIgnoreCase()"))},r},equalsIgnoreCase:function(i){if(typeof i!="string")return n(new this._ctx.collClass(this),new wi("String expected"));var r=new this._ctx.collClass(this,function(){return ti.bound(i.toUpperCase(),i.toLowerCase())});return t(r,function(n,t){return n===t},i),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=i(arguments),t=s?cr(ki):ki,u,r;return(n.sort(t),n.length===0)?new this._ctx.collClass(this,ti.only("")).limit(0):(u=new this._ctx.collClass(this,function(){return ti.bound(n[0],n[n.length-1])}),u._ondirectionchange=function(i){t=i==="next"?ki:hr;s&&(t=cr(t));n.sort(t)},r=0,u._addAlgorithm(function(i,u,f){for(var e=i.key;t(e,n[r])>0;)if(++r,r===n.length)return u(f),!1;return t(e,n[r])===0?(u(function(){i.continue()}),!0):(u(function(){i.continue(n[r])}),!1)}),u)}}});h(vi.prototype,function(){function t(n,t){n.filter=di(n.filter,t)}function f(n,t){n.isMatch=di(n.isMatch,t)}function r(n,t){if(n.isPrimKey)return t;var i=n.table.schema.idxByName[n.index];if(!i)throw new st("KeyPath "+n.index+" on object store "+t.name+" is not indexed");return n.isPrimKey?t:t.index(i.name)}function u(n,t){return r(n,t)[n.op](n.range||null,n.dir+n.unique)}function i(n,t,i,r,f){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,f);bi(u(n,f),n.algorithm,h,e,r,n.table.hook.reading.fire)}():bi(u(n,f),di(n.algorithm,n.filter),t,i,r,n.table.hook.reading.fire)}function n(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(ri,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(ni,n,"locked")},_addAlgorithm:function(n){var t=this._ctx;t.algorithm=di(t.algorithm,n)},_iterate:function(n,t,r,u){return i(this._ctx,n,t,r,u)},each:function(t){var r=this._ctx;return o(function(){t(n(r))}),this._read(function(n,u,f){i(r,t,n,u,f)})},count:function(n){var f,t,u;return o(function(){n(0)}),f=this,t=this._ctx,t.filter||t.algorithm||t.or?(u=0,this._read(function(n,r,f){i(t,function(){return++u,!1},function(){n(u)},r,f)},n)):this._read(function(n,i,u){var e=r(t,u),o=t.range?e.count(t.range):e.count();o.onerror=s(i,["calling","count()","on",f.name]);o.onsuccess=function(i){n(Math.min(i.target.result,Math.max(0,t.limit-t.offset)))}},n)},sortBy:function(t,i){function u(n,t){return t?u(n[r[t]],t-1):n[h]}function c(n,t){var i=u(n,e),r=u(t,e);return ir?f:0}var s=this._ctx,f;o(function(){i([n(s)])});var r=t.split(".").reverse(),h=r[0],e=r.length-1;return f=this._ctx.dir==="next"?1:-1,this.toArray(function(n){return n.sort(c)}).then(i)},toArray:function(t){var r=this._ctx;return o(function(){t([n(r)])}),this._read(function(n,t,u){var f=[];i(r,function(n){f.push(n)},function(){n(f)},t,u)},t)},offset:function(n){var i=this._ctx;return n<=0?this:(i.offset+=n,i.or||i.algorithm||i.filter?t(i,function(){return--n<0}):t(i,function(t,i){return n===0?!0:n===1?(--n,!1):(i(function(){t.advance(n);n=0}),!1)}),this)},limit:function(n){return this._ctx.limit=Math.min(this._ctx.limit,n),t(this._ctx,function(t,i,r){return--n<=0&&i(r),n>=0}),this},until:function(i,r){var u=this._ctx;return o(function(){i(n(u))}),t(this._ctx,function(n,t,u){return i(n.value)?(t(u),r):!0}),this},first:function(t){var i=this;return o(function(){t(n(i._ctx))}),this.limit(1).toArray(function(n){return n[0]}).then(t)},last:function(n){return this.reverse().first(n)},and:function(i){var r=this;return o(function(){i(n(r._ctx))}),t(this._ctx,function(n){return i(n.value)}),f(this._ctx,i),this},or:function(n){return new ai(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(t){var i=this,r=this._ctx;return o(function(){t(n(i._ctx)[i._ctx.index])}),r.isPrimKey||(r.op="openKeyCursor"),this.each(function(n,i){t(i.key,i)})},eachUniqueKey:function(n){return this._ctx.unique="unique",this.eachKey(n)},keys:function(t){var u,i,r;return o(function(){t([n(i)[u._ctx.index]])}),u=this,i=this._ctx,i.isPrimKey||(i.op="openKeyCursor"),r=[],this.each(function(n,t){r.push(t.key)}).then(function(){return r}).then(t)},uniqueKeys:function(n){return this._ctx.unique="unique",this.keys(n)},firstKey:function(n){var t=this;return this.limit(1).keys(function(n){return n[0]}).then(n)},lastKey:function(n){return this.reverse().firstKey(n)},distinct:function(){var n={};return t(this._ctx,function(t){var i=t.primaryKey.toString(),r=n.hasOwnProperty(i);return n[i]=!0,!r}),this}}});p(fr).from(vi).extend({modify:function(n){var f=this,t=this._ctx,r=t.table.hook,i=r.updating.fire,u=r.deleting.fire;return o(function(){typeof n=="function"&&n.call({value:t.table.schema.instanceTemplate},t.table.schema.instanceTemplate)}),this._write(function(r,o,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=s(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)),o(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,rt,d;typeof n=="function"?w=i===e&&u===e?n:function(t){var f=a(t),e,r;if(n.call(this,t)===!1)return!1;this.hasOwnProperty("value")?(e=dt(f,this.value),r=i.call(this,e,this.primKey,f,y),r&&(t=this.value,Object.keys(r).forEach(function(n){c(t,n,r[n])}))):u.call(this,this.primKey,t,y)}:i===e?(k=Object.keys(n),rt=k.length,w=function(t){for(var i,u,f=!1,r=0;r0)v();i=s;r=!0}}}function k(n){var t=r;r=!1;i=a;try{n()}finally{if(t){while(u.length>0)v();i=s;r=!0}}}function p(n){n._catched=!0;n._parent&&p(n._parent)}function h(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"){b(n,function(n,t){i.then(n,t)},function(t){h(n,t)},function(t){o(n,t)});return}n._state=!0;n._value=i;w.call(n)}catch(u){o(u)}finally{t.PSD=r}}function o(n,i){var r=t.PSD;if(t.PSD=n._PSD,n._state=!1,n._value=i,w.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 w(){for(var n=0,t=this._deferreds.length;n