idb-keyval-amd.min.js
1.1 KB
define(["exports"],function(e){"use strict";class t{constructor(e="keyval-store",t="keyval"){this.storeName=t,this._dbp=new Promise((r,o)=>{const n=indexedDB.open(e,1);n.onerror=(()=>o(n.error)),n.onsuccess=(()=>r(n.result)),n.onupgradeneeded=(()=>{n.result.createObjectStore(t)})})}_withIDBStore(e,t){return this._dbp.then(r=>new Promise((o,n)=>{const s=r.transaction(this.storeName,e);s.oncomplete=(()=>o()),s.onabort=s.onerror=(()=>n(s.error)),t(s.objectStore(this.storeName))}))}}let r;function o(){return r||(r=new t),r}e.Store=t,e.get=function(e,t=o()){let r;return t._withIDBStore("readonly",t=>{r=t.get(e)}).then(()=>r.result)},e.set=function(e,t,r=o()){return r._withIDBStore("readwrite",r=>{r.put(t,e)})},e.del=function(e,t=o()){return t._withIDBStore("readwrite",t=>{t.delete(e)})},e.clear=function(e=o()){return e._withIDBStore("readwrite",e=>{e.clear()})},e.keys=function(e=o()){const t=[];return e._withIDBStore("readonly",e=>{(e.openKeyCursor||e.openCursor).call(e).onsuccess=function(){this.result&&(t.push(this.result.key),this.result.continue())}}).then(()=>t)},Object.defineProperty(e,"__esModule",{value:!0})});