import e from"../../safari-14-idb-fix/dist/index.js";function promisifyRequest(e){return new Promise(((t,r)=>{e.oncomplete=e.onsuccess=()=>t(e.result),e.onabort=e.onerror=()=>r(e.error)}))}function createStore(t,r){const n=e().then((()=>{const e=indexedDB.open(t);return e.onupgradeneeded=()=>e.result.createObjectStore(r),promisifyRequest(e)}));return(e,t)=>n.then((n=>t(n.transaction(r,e).objectStore(r))))}let t;function defaultGetStore(){return t||(t=createStore("keyval-store","keyval")),t}function get(e,t=defaultGetStore()){return t("readonly",(t=>promisifyRequest(t.get(e))))}function set(e,t,r=defaultGetStore()){return r("readwrite",(r=>(r.put(t,e),promisifyRequest(r.transaction))))}function setMany(e,t=defaultGetStore()){return t("readwrite",(t=>(e.forEach((e=>t.put(e[1],e[0]))),promisifyRequest(t.transaction))))}function getMany(e,t=defaultGetStore()){return t("readonly",(t=>Promise.all(e.map((e=>promisifyRequest(t.get(e)))))))}function update(e,t,r=defaultGetStore()){return r("readwrite",(r=>new Promise(((n,o)=>{r.get(e).onsuccess=function(){try{r.put(t(this.result),e),n(promisifyRequest(r.transaction))}catch(e){o(e)}}}))))}function del(e,t=defaultGetStore()){return t("readwrite",(t=>(t.delete(e),promisifyRequest(t.transaction))))}function delMany(e,t=defaultGetStore()){return t("readwrite",(t=>(e.forEach((e=>t.delete(e))),promisifyRequest(t.transaction))))}function clear(e=defaultGetStore()){return e("readwrite",(e=>(e.clear(),promisifyRequest(e.transaction))))}function eachCursor(e,t){return e.openCursor().onsuccess=function(){this.result&&(t(this.result),this.result.continue())},promisifyRequest(e.transaction)}function keys(e=defaultGetStore()){return e("readonly",(e=>{if(e.getAllKeys)return promisifyRequest(e.getAllKeys());const t=[];return eachCursor(e,(e=>t.push(e.key))).then((()=>t))}))}function values(e=defaultGetStore()){return e("readonly",(e=>{if(e.getAll)return promisifyRequest(e.getAll());const t=[];return eachCursor(e,(e=>t.push(e.value))).then((()=>t))}))}function entries(e=defaultGetStore()){return e("readonly",(t=>{if(t.getAll&&t.getAllKeys)return Promise.all([promisifyRequest(t.getAllKeys()),promisifyRequest(t.getAll())]).then((([e,t])=>e.map(((e,r)=>[e,t[r]]))));const r=[];return e("readonly",(e=>eachCursor(e,(e=>r.push([e.key,e.value]))).then((()=>r))))}))}export{clear,createStore,del,delMany,entries,get,getMany,keys,promisifyRequest,set,setMany,update,values};