(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.",mt="String expected.",gt=[],bt="undefined"!=typeof navigator&&/(MSIE|Trident|Edge)/.test(navigator.userAgent),_t=bt,wt=bt,xt="__dbnames",kt="readonly",Ot="readwrite";function Pt(e,t){return e?t?function(){return e.apply(this,arguments)&&t.apply(this,arguments)}:e:t}var Et={type:3,lower:-1/0,lowerOpen:!1,upper:[[]],upperOpen:!1},jt=(Kt.prototype._trans=function(e,r,t){var n=this._tx||Ce.trans,i=this.name;function o(e,t,n){if(!n.schema[i])throw new $.NotFound("Table "+i+" not part of transaction");return r(n.idbtrans,n)}var u=We();try{return n&&n.db===this.db?n===Ce.trans?n._promise(e,o,t):et(function(){return n._promise(e,o,t)},{trans:n,transless:Ce.transless||Ce}):function e(t,n,r,i){if(t._state.openComplete||Ce.letThrough){var o=t._createTransaction(n,r,t._dbSchema);try{o.create()}catch(e){return ht(e)}return o._promise(n,function(e,t){return et(function(){return Ce.trans=o,i(e,t,o)})}).then(function(e){return o._completion.then(function(){return e})})}if(!t._state.isBeingOpened){if(!t._options.autoOpen)return ht(new $.DatabaseClosed);t.open().catch(te)}return t._state.dbReadyPromise.then(function(){return e(t,n,r,i)})}(this.db,e,[this.name],o)}finally{u&&ze()}},Kt.prototype.get=function(t,e){var n=this;return t&&t.constructor===Object?this.where(t).first(e):this._trans("readonly",function(e){return n.core.get({trans:e,key:t}).then(function(e){return n.hook.reading.fire(e)})}).then(e)},Kt.prototype.where=function(u){if("string"==typeof u)return new this.db.WhereClause(this,u);if(d(u))return new this.db.WhereClause(this,"["+u.join("+")+"]");var n=_(u);if(1===n.length)return this.where(n[0]).equals(u[n[0]]);var e=this.schema.indexes.concat(this.schema.primKey).filter(function(t){return t.compound&&n.every(function(e){return 0<=t.keyPath.indexOf(e)})&&t.keyPath.every(function(e){return 0<=n.indexOf(e)})})[0];if(e&&this.db._maxKey!==yt)return this.where(e.name).equals(e.keyPath.map(function(e){return u[e]}));!e&&F&&console.warn("The query "+JSON.stringify(u)+" on "+this.name+" would benefit of a compound index ["+n.join("+")+"]");var a=this.schema.idxByName,r=this.db._deps.indexedDB;function s(e,t){try{return 0===r.cmp(e,t)}catch(e){return!1}}var t=n.reduce(function(e,n){var t=e[0],r=e[1],i=a[n],o=u[n];return[t||i,t||!i?Pt(r,i&&i.multi?function(e){var t=w(e,n);return d(t)&&t.some(function(e){return s(o,e)})}:function(e){return s(o,w(e,n))}):r]},[null,null]),i=t[0],o=t[1];return i?this.where(i.name).equals(u[i.keyPath]).filter(o):e?this.filter(o):this.where(n).equals("")},Kt.prototype.filter=function(e){return this.toCollection().and(e)},Kt.prototype.count=function(e){return this.toCollection().count(e)},Kt.prototype.offset=function(e){return this.toCollection().offset(e)},Kt.prototype.limit=function(e){return this.toCollection().limit(e)},Kt.prototype.each=function(e){return this.toCollection().each(e)},Kt.prototype.toArray=function(e){return this.toCollection().toArray(e)},Kt.prototype.toCollection=function(){return new this.db.Collection(new this.db.WhereClause(this))},Kt.prototype.orderBy=function(e){return new this.db.Collection(new this.db.WhereClause(this,d(e)?"["+e.join("+")+"]":e))},Kt.prototype.reverse=function(){return this.toCollection().reverse()},Kt.prototype.mapToClass=function(r){function e(e){if(!e)return e;var t=Object.create(r.prototype);for(var n in e)if(c(e,n))try{t[n]=e[n]}catch(e){}return t}return this.schema.mappedClass=r,this.schema.readHook&&this.hook.reading.unsubscribe(this.schema.readHook),this.schema.readHook=e,this.hook("reading",e),r},Kt.prototype.defineClass=function(){return this.mapToClass(function(e){s(this,e)})},Kt.prototype.add=function(t,n){var r=this;return this._trans("readwrite",function(e){return r.core.mutate({trans:e,type:"add",keys:null!=n?[n]:null,values:[t]})}).then(function(e){return e.numFailures?De.reject(e.failures[0]):e.lastResult}).then(function(e){if(!r.core.schema.primaryKey.outbound)try{x(t,r.core.schema.primaryKey.keyPath,e)}catch(e){}return e})},Kt.prototype.update=function(t,n){if("object"!=typeof n||d(n))throw new $.InvalidArgument("Modifications must be an object.");if("object"!=typeof t||d(t))return this.where(":id").equals(t).modify(n);_(n).forEach(function(e){x(t,e,n[e])});var e=w(t,this.schema.primKey.keyPath);return void 0===e?ht(new $.InvalidArgument("Given object does not contain its primary key")):this.where(":id").equals(e).modify(n)},Kt.prototype.put=function(t,n){var r=this;return this._trans("readwrite",function(e){return r.core.mutate({trans:e,type:"put",values:[t],keys:null!=n?[n]:null})}).then(function(e){return e.numFailures?De.reject(e.failures[0]):e.lastResult}).then(function(e){if(!r.core.schema.primaryKey.outbound)try{x(t,r.core.schema.primaryKey.keyPath,e)}catch(e){}return e})},Kt.prototype.delete=function(t){var n=this;return this._trans("readwrite",function(e){return n.core.mutate({trans:e,type:"delete",keys:[t]})}).then(function(e){return e.numFailures?De.reject(e.failures[0]):void 0})},Kt.prototype.clear=function(){var t=this;return this._trans("readwrite",function(e){return t.core.mutate({trans:e,type:"deleteRange",range:Et})}).then(function(e){return e.numFailures?De.reject(e.failures[0]):void 0})},Kt.prototype.bulkGet=function(t){var n=this;return this._trans("readonly",function(e){return n.core.getMany({keys:t,trans:e})})},Kt.prototype.bulkAdd=function(t,e,n){var u=this,r=Array.isArray(e)?e:void 0,a=(n=n||(r?void 0:e))?n.allKeys:void 0;return this._trans("readwrite",function(e){if(!u.core.schema.primaryKey.outbound&&r)throw new $.InvalidArgument("bulkAdd(): keys argument invalid on tables with inbound keys");if(r&&r.length!==t.length)throw new $.InvalidArgument("Arguments objects and keys must have the same length");var o=t.length;return u.core.mutate({trans:e,type:"add",keys:r,values:t,wantResults:a}).then(function(e){var t=e.numFailures,n=e.results,r=e.lastResult,i=e.failures;if(0===t)return a?n:r;throw new Q(u.name+".bulkAdd(): "+t+" of "+o+" operations failed",Object.keys(i).map(function(e){return i[e]}))})})},Kt.prototype.bulkPut=function(t,e,n){var u=this,r=Array.isArray(e)?e:void 0,a=(n=n||(r?void 0:e))?n.allKeys:void 0;return this._trans("readwrite",function(e){if(!u.core.schema.primaryKey.outbound&&r)throw new $.InvalidArgument("bulkPut(): keys argument invalid on tables with inbound keys");if(r&&r.length!==t.length)throw new $.InvalidArgument("Arguments objects and keys must have the same length");var o=t.length;return u.core.mutate({trans:e,type:"put",keys:r,values:t,wantResults:a}).then(function(e){var t=e.numFailures,n=e.results,r=e.lastResult,i=e.failures;if(0===t)return a?n:r;throw new Q(u.name+".bulkPut(): "+t+" of "+o+" operations failed",Object.keys(i).map(function(e){return i[e]}))})})},Kt.prototype.bulkDelete=function(t){var i=this,o=t.length;return this._trans("readwrite",function(e){return i.core.mutate({trans:e,type:"delete",keys:t})}).then(function(e){var t=e.numFailures,n=e.lastResult,r=e.failures;if(0===t)return n;throw new Q(i.name+".bulkDelete(): "+t+" of "+o+" operations failed",r)})},Kt);function Kt(){}function At(i){var u={},t=function(e,t){if(t){for(var n=arguments.length,r=new Array(n-1);--n;)r[n-1]=arguments[n];return u[e].subscribe.apply(null,r),i}if("string"==typeof e)return u[e]};t.addEventType=a;for(var e=1,n=arguments.length;es+c&&f(s+g)})})};return f(0).then(function(){if(0=c}).forEach(function(a){t.push(function(){var t=h,e=a._cfg.dbschema;wn(s,t,f),wn(s,e,f),h=s._dbSchema=e;var n=function(e,t){var n,r={del:[],add:[],change:[]};for(n in e)t[n]||r.del.push(n);for(n in t){var i=e[n],o=t[n];if(i){var u={name:n,def:o,recreate:!1,del:[],add:[],change:[]};if(i.primKey.src===o.primKey.src||bt){var a=i.idxByName,s=o.idxByName,c=void 0;for(c in a)s[c]||u.del.push(c);for(c in s){var l=a[c],f=s[c];l?l.src!==f.src&&u.change.push(f):u.add.push(f)}(0c){pn(s,f),p=!0;var i,o=k(e);n.del.forEach(function(e){o[e]=t[e]}),yn(s,[s.Transaction.prototype]),dn(s,[s.Transaction.prototype],_(o),o),l.schema=o,tt();var u=De.follow(function(){if(i=r(l))if(i.constructor===ge){var e=nt.bind(null,null);i.then(e,e)}else nt();else nt()});return i&&"function"==typeof i.then?De.resolve(i):u.then(function(){return i})}}),t.push(function(e){p&&_t||function(e,t){for(var n=0;nMath.pow(2,62)?0:e.oldVersion;a.idbdb=u.result,mn(a,n/10,l,i)}},i),u.onsuccess=Ge(function(){l=null;var e=a.idbdb=u.result,t=p(e.objectStoreNames);if(0