(function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.Dexie=t()})(this,function(){"use strict";var m=function(){return(m=Object.assign||function(e){for(var t,n=1,r=arguments.length;n.",_t="String expected.",wt=[],xt="undefined"!=typeof navigator&&/(MSIE|Trident|Edge)/.test(navigator.userAgent),kt=xt,Pt=xt,Et="__dbnames",Ot="readonly",jt="readwrite";function St(e,t){return e?t?function(){return e.apply(this,arguments)&&t.apply(this,arguments)}:e:t}var At={type:3,lower:-1/0,lowerOpen:!1,upper:[[]],upperOpen:!1};function Kt(t){return function(e){return void 0===x(e,t)&&P(e=K(e),t),e}}var Ct=(It.prototype._trans=function(e,r,t){var n=this._tx||Te.trans,i=this.name;function o(e,t,n){if(!n.schema[i])throw new te.NotFound("Table "+i+" not part of transaction");return r(n.idbtrans,n)}var u=Ye();try{return n&&n.db===this.db?n===Te.trans?n._promise(e,o,t):rt(function(){return n._promise(e,o,t)},{trans:n,transless:Te.transless||Te}):function e(t,n,r,i){if(t._state.openComplete||Te.letThrough){var o=t._createTransaction(n,r,t._dbSchema);try{o.create()}catch(e){return vt(e)}return o._promise(n,function(e,t){return rt(function(){return Te.trans=o,i(e,t,o)})}).then(function(e){return o._completion.then(function(){return e})})}if(!t._state.isBeingOpened){if(!t._options.autoOpen)return vt(new te.DatabaseClosed);t.open().catch(ie)}return t._state.dbReadyPromise.then(function(){return e(t,n,r,i)})}(this.db,e,[this.name],o)}finally{u&&Ge()}},It.prototype.get=function(t,e){var n=this;return t&&t.constructor===Object?this.where(t).first(e):this._trans("readonly",function(e){return n.core.get({trans:e,key:t}).then(function(e){return n.hook.reading.fire(e)})}).then(e)},It.prototype.where=function(u){if("string"==typeof u)return new this.db.WhereClause(this,u);if(d(u))return new this.db.WhereClause(this,"["+u.join("+")+"]");var n=_(u);if(1===n.length)return this.where(n[0]).equals(u[n[0]]);var e=this.schema.indexes.concat(this.schema.primKey).filter(function(t){return t.compound&&n.every(function(e){return 0<=t.keyPath.indexOf(e)})&&t.keyPath.every(function(e){return 0<=n.indexOf(e)})})[0];if(e&&this.db._maxKey!==gt)return this.where(e.name).equals(e.keyPath.map(function(e){return u[e]}));!e&&N&&console.warn("The query "+JSON.stringify(u)+" on "+this.name+" would benefit of a compound index ["+n.join("+")+"]");var a=this.schema.idxByName,r=this.db._deps.indexedDB;function s(e,t){try{return 0===r.cmp(e,t)}catch(e){return!1}}var t=n.reduce(function(e,n){var t=e[0],r=e[1],i=a[n],o=u[n];return[t||i,t||!i?St(r,i&&i.multi?function(e){var t=x(e,n);return d(t)&&t.some(function(e){return s(o,e)})}:function(e){return s(o,x(e,n))}):r]},[null,null]),i=t[0],o=t[1];return i?this.where(i.name).equals(u[i.keyPath]).filter(o):e?this.filter(o):this.where(n).equals("")},It.prototype.filter=function(e){return this.toCollection().and(e)},It.prototype.count=function(e){return this.toCollection().count(e)},It.prototype.offset=function(e){return this.toCollection().offset(e)},It.prototype.limit=function(e){return this.toCollection().limit(e)},It.prototype.each=function(e){return this.toCollection().each(e)},It.prototype.toArray=function(e){return this.toCollection().toArray(e)},It.prototype.toCollection=function(){return new this.db.Collection(new this.db.WhereClause(this))},It.prototype.orderBy=function(e){return new this.db.Collection(new this.db.WhereClause(this,d(e)?"["+e.join("+")+"]":e))},It.prototype.reverse=function(){return this.toCollection().reverse()},It.prototype.mapToClass=function(r){function e(e){if(!e)return e;var t=Object.create(r.prototype);for(var n in e)if(g(e,n))try{t[n]=e[n]}catch(e){}return t}return this.schema.mappedClass=r,this.schema.readHook&&this.hook.reading.unsubscribe(this.schema.readHook),this.schema.readHook=e,this.hook("reading",e),r},It.prototype.defineClass=function(){return this.mapToClass(function(e){s(this,e)})},It.prototype.add=function(t,n){var r=this,e=this.schema.primKey,i=e.auto,o=e.keyPath,u=t;return o&&i&&(u=Kt(o)(t)),this._trans("readwrite",function(e){return r.core.mutate({trans:e,type:"add",keys:null!=n?[n]:null,values:[u]})}).then(function(e){return e.numFailures?Fe.reject(e.failures[0]):e.lastResult}).then(function(e){if(o)try{k(t,o,e)}catch(e){}return e})},It.prototype.update=function(t,n){if("object"!=typeof n||d(n))throw new te.InvalidArgument("Modifications must be an object.");if("object"!=typeof t||d(t))return this.where(":id").equals(t).modify(n);_(n).forEach(function(e){k(t,e,n[e])});var e=x(t,this.schema.primKey.keyPath);return void 0===e?vt(new te.InvalidArgument("Given object does not contain its primary key")):this.where(":id").equals(e).modify(n)},It.prototype.put=function(t,n){var r=this,e=this.schema.primKey,i=e.auto,o=e.keyPath,u=t;return o&&i&&(u=Kt(o)(t)),this._trans("readwrite",function(e){return r.core.mutate({trans:e,type:"put",values:[u],keys:null!=n?[n]:null})}).then(function(e){return e.numFailures?Fe.reject(e.failures[0]):e.lastResult}).then(function(e){if(o)try{k(t,o,e)}catch(e){}return e})},It.prototype.delete=function(t){var n=this;return this._trans("readwrite",function(e){return n.core.mutate({trans:e,type:"delete",keys:[t]})}).then(function(e){return e.numFailures?Fe.reject(e.failures[0]):void 0})},It.prototype.clear=function(){var t=this;return this._trans("readwrite",function(e){return t.core.mutate({trans:e,type:"deleteRange",range:At})}).then(function(e){return e.numFailures?Fe.reject(e.failures[0]):void 0})},It.prototype.bulkGet=function(t){var n=this;return this._trans("readonly",function(e){return n.core.getMany({keys:t,trans:e}).then(function(e){return e.map(function(e){return n.hook.reading.fire(e)})})})},It.prototype.bulkAdd=function(u,e,t){var a=this,s=Array.isArray(e)?e:void 0,c=(t=t||(s?void 0:e))?t.allKeys:void 0;return this._trans("readwrite",function(e){var t=a.schema.primKey,n=t.auto,r=t.keyPath;if(r&&s)throw new te.InvalidArgument("bulkAdd(): keys argument invalid on tables with inbound keys");if(s&&s.length!==u.length)throw new te.InvalidArgument("Arguments objects and keys must have the same length");var o=u.length,i=r&&n?u.map(Kt(r)):u;return a.core.mutate({trans:e,type:"add",keys:s,values:i,wantResults:c}).then(function(e){var t=e.numFailures,n=e.results,r=e.lastResult,i=e.failures;if(0===t)return c?n:r;throw new $(a.name+".bulkAdd(): "+t+" of "+o+" operations failed",Object.keys(i).map(function(e){return i[e]}))})})},It.prototype.bulkPut=function(u,e,t){var a=this,s=Array.isArray(e)?e:void 0,c=(t=t||(s?void 0:e))?t.allKeys:void 0;return this._trans("readwrite",function(e){var t=a.schema.primKey,n=t.auto,r=t.keyPath;if(r&&s)throw new te.InvalidArgument("bulkPut(): keys argument invalid on tables with inbound keys");if(s&&s.length!==u.length)throw new te.InvalidArgument("Arguments objects and keys must have the same length");var o=u.length,i=r&&n?u.map(Kt(r)):u;return a.core.mutate({trans:e,type:"put",keys:s,values:i,wantResults:c}).then(function(e){var t=e.numFailures,n=e.results,r=e.lastResult,i=e.failures;if(0===t)return c?n:r;throw new $(a.name+".bulkPut(): "+t+" of "+o+" operations failed",Object.keys(i).map(function(e){return i[e]}))})})},It.prototype.bulkDelete=function(t){var i=this,o=t.length;return this._trans("readwrite",function(e){return i.core.mutate({trans:e,type:"delete",keys:t})}).then(function(e){var t=e.numFailures,n=e.lastResult,r=e.failures;if(0===t)return n;throw new $(i.name+".bulkDelete(): "+t+" of "+o+" operations failed",r)})},It);function It(){}function Tt(i){var u={},t=function(e,t){if(t){for(var n=arguments.length,r=new Array(n-1);--n;)r[n-1]=arguments[n];return u[e].subscribe.apply(null,r),i}if("string"==typeof e)return u[e]};t.addEventType=a;for(var e=1,n=arguments.length;es+c&&f(s+g)})})};return f(0).then(function(){if(0=l}).forEach(function(s){t.push(function(){var t=p,e=s._cfg.dbschema;On(c,t,h),On(c,e,h),p=c._dbSchema=e;var n=xn(t,e);n.add.forEach(function(e){kn(h,e[0],e[1].primKey,e[1].indexes)}),n.change.forEach(function(e){if(e.recreate)throw new te.Upgrade("Not yet support for changing primary key");var t=h.objectStore(e.name);e.add.forEach(function(e){return Pn(t,e)}),e.change.forEach(function(e){t.deleteIndex(e.name),Pn(t,e)}),e.del.forEach(function(e){return t.deleteIndex(e)})});var r=s._cfg.contentUpgrade;if(r&&s._cfg.version>l){mn(c,h),f._memoizedTables={},d=!0;var i=E(e);n.del.forEach(function(e){i[e]=t[e]}),bn(c,[c.Transaction.prototype]),gn(c,[c.Transaction.prototype],_(i),i),f.schema=i;var o,u=M(r);u&&it();var a=Fe.follow(function(){var e;(o=r(f))&&u&&(e=ot.bind(null,null),o.then(e,e))});return o&&"function"==typeof o.then?Fe.resolve(o):a.then(function(){return o})}}),t.push(function(e){d&&kt||function(e,t){for(var n=0;nMath.pow(2,62)?0:e.oldVersion,c.idbdb=s.result,wn(c,n/10,f,r))},r),s.onsuccess=Xe(function(){f=null;var e,t,n,r=c.idbdb=s.result,i=p(r.objectStoreNames);if(0