(function(e){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=e()}else if(typeof define==="function"&&define.amd){define([],e)}else{var t;if(typeof window!=="undefined"){t=window}else if(typeof global!=="undefined"){t=global}else if(typeof self!=="undefined"){t=self}else{t=this}t.IdbKvStore=e()}})(function(){var e,t,r;return function(){function l(o,s,u){function a(r,e){if(!s[r]){if(!o[r]){var t="function"==typeof require&&require;if(!e&&t)return t(r,!0);if(f)return f(r,!0);var n=new Error("Cannot find module '"+r+"'");throw n.code="MODULE_NOT_FOUND",n}var i=s[r]={exports:{}};o[r][0].call(i.exports,function(e){var t=o[r][1][e];return a(t||e)},i,i.exports,l,o,s,u)}return s[r].exports}for(var f="function"==typeof require&&require,e=0;e1)r=arguments[1];if(r instanceof Error){throw r}else{var f=new Error('Unhandled "error" event. ('+r+")");f.context=r;throw f}return false}n=u[t];if(!n)return false;var l=typeof n==="function";i=arguments.length;switch(i){case 1:c(n,l,this);break;case 2:h(n,l,this,arguments[1]);break;case 3:p(n,l,this,arguments[1],arguments[2]);break;case 4:v(n,l,this,arguments[1],arguments[2],arguments[3]);break;default:o=new Array(i-1);for(s=1;s0&&s.length>i){s.warned=true;var u=new Error("Possible EventEmitter memory leak detected. "+s.length+' "'+String(t)+'" listeners '+"added. Use emitter.setMaxListeners() to "+"increase limit.");u.name="MaxListenersExceededWarning";u.emitter=e;u.type=t;u.count=s.length;if(typeof console==="object"&&console.warn){console.warn("%s: %s",u.name,u.message)}}}}return e}n.prototype.addListener=function e(t,r){return y(this,t,r,false)};n.prototype.on=n.prototype.addListener;n.prototype.prependListener=function e(t,r){return y(this,t,r,true)};function _(){if(!this.fired){this.target.removeListener(this.type,this.wrapFn);this.fired=true;switch(arguments.length){case 0:return this.listener.call(this.target);case 1:return this.listener.call(this.target,arguments[0]);case 2:return this.listener.call(this.target,arguments[0],arguments[1]);case 3:return this.listener.call(this.target,arguments[0],arguments[1],arguments[2]);default:var e=new Array(arguments.length);for(var t=0;t=0;s--){if(n[s]===r||n[s].listener===r){u=n[s].listener;o=s;break}}if(o<0)return this;if(o===0)n.shift();else g(n,o);if(n.length===1)i[t]=n[0];if(i.removeListener)this.emit("removeListener",t,u||r)}return this};n.prototype.removeAllListeners=function e(t){var r,n,i;n=this._events;if(!n)return this;if(!n.removeListener){if(arguments.length===0){this._events=a(null);this._eventsCount=0}else if(n[t]){if(--this._eventsCount===0)this._events=a(null);else delete n[t]}return this}if(arguments.length===0){var o=u(n);var s;for(i=0;i=0;i--){this.removeListener(t,r[i])}}return this};n.prototype.listeners=function e(t){var r;var n;var i=this._events;if(!i)n=[];else{r=i[t];if(!r)n=[];else if(typeof r==="function")n=[r.listener||r];else n=L(r)}return n};n.listenerCount=function(e,t){if(typeof e.listenerCount==="function"){return e.listenerCount(t)}else{return w.call(e,t)}};n.prototype.listenerCount=w;function w(e){var t=this._events;if(t){var r=t[e];if(typeof r==="function"){return 1}else if(r){return r.length}}return 0}n.prototype.eventNames=function e(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};function g(e,t){for(var r=t,n=r+1,i=e.length;nn[i]){++i;if(i===n.length){a(null,s());return}}if(r===n[i]){o[r]=t.value;t.continue()}else{t.continue(n[i])}}});return a.promise};i.prototype.json=function(e,r){var t=this;if(typeof e==="function")return t.json(null,e);r=f(r);var n={};t.iterator(e,function(e,t){if(e)return r(e);if(t){n[t.key]=t.value;t.continue()}else{r(null,n)}});return r.promise};i.prototype.keys=function(e,r){var t=this;if(typeof e==="function")return t.keys(null,e);r=f(r);var n=[];t.iterator(e,function(e,t){if(e)return r(e);if(t){n.push(t.key);t.continue()}else{r(null,n)}});return r.promise};i.prototype.values=function(e,r){var t=this;if(typeof e==="function")return t.values(null,e);r=f(r);var n=[];t.iterator(e,function(e,t){if(e)return r(e);if(t){n.push(t.value);t.continue()}else{r(null,n)}});return r.promise};i.prototype.remove=function(n,i){var o=this;if(n==null)throw new Error("A key must be given as an argument");i=f(i);o._getObjectStore(function(e,t){if(e)return i(e);try{var r=t.delete(n)}catch(e){return i(e)}r.onerror=_.bind(this,i);r.onsuccess=function(){if(o._kvStore._channel){o._kvStore._channel.postMessage({method:"remove",key:n})}i(null)}});return i.promise};i.prototype.clear=function(n){var e=this;n=f(n);e._getObjectStore(function(e,t){if(e)return n(e);try{var r=t.clear()}catch(e){return n(e)}r.onerror=_.bind(this,n);r.onsuccess=function(){n(null)}});return n.promise};i.prototype.count=function(n,i){var e=this;if(typeof n==="function")return e.count(null,n);i=f(i);e._getObjectStore(function(e,t){if(e)return i(e);try{var r=n==null?t.count():t.count(n)}catch(e){return i(e)}r.onerror=_.bind(this,i);r.onsuccess=function(e){i(null,e.target.result)}});return i.promise};i.prototype.iterator=function(n,i){var e=this;if(typeof n==="function")return e.iterator(null,n);if(typeof i!=="function")throw new Error("A function must be given");e._getObjectStore(function(e,t){if(e)return i(e);try{var r=n==null?t.openCursor():t.openCursor(n)}catch(e){return i(e)}r.onerror=_.bind(this,i);r.onsuccess=function(e){var t=e.target.result;i(null,t)}})};i.prototype.abort=function(){if(this.finished)throw new Error("Transaction is finished");if(this._objectStore)this._objectStore.transaction.abort();this._close(new Error("Transaction aborted"))};i.prototype._close=function(e){if(this.finished)return;this.finished=true;this._kvStore=null;this._objectStore=null;for(var t in this._waiters)this._waiters[t](e||new Error("Transaction is finished"));this._waiters=null;if(this.onfinish)this.onfinish(e);this.onfinish=null};function _(e,t){if(t==null)return _(null,e);t.preventDefault();t.stopPropagation();if(e)e(t.target.error)}},{events:1,inherits:2,promisize:3}]},{},[])("/")});