const e=self,t=new Map;function n(e){let n=`${e.databaseName}@${e.version}`,r=t.get(n);if(r)return r;let i=new Promise((t,n)=>{let r=indexedDB.open(e.databaseName,e.version);r.onerror=()=>n(r.error),r.onsuccess=()=>t(r.result),r.onupgradeneeded=t=>{let n=t.target.result;for(let t of e.stores)n.objectStoreNames.contains(t)||n.createObjectStore(t)}});return t.set(n,i),i}async function r(e,t,r){let i=(await n(e)).transaction(t,`readonly`).objectStore(t);return new Promise((e,t)=>{let n=i.get(r);n.onsuccess=()=>e(n.result??null),n.onerror=()=>t(n.error)})}async function i(e,t,r){let i=(await n(e)).transaction(t,`readonly`).objectStore(t),a=r.map(e=>new Promise((t,n)=>{let r=i.get(e);r.onsuccess=()=>t(r.result??null),r.onerror=()=>n(r.error)}));return Promise.all(a)}async function a(e,t,r,i){let a=(await n(e)).transaction(t,`readwrite`).objectStore(t);return new Promise((e,t)=>{let n=a.put(i,r);n.onsuccess=()=>e(),n.onerror=()=>t(n.error)})}async function o(e,t,r){let i=(await n(e)).transaction(t,`readwrite`).objectStore(t);return new Promise((e,t)=>{let n=i.delete(r);n.onsuccess=()=>e(),n.onerror=()=>t(n.error)})}async function s(e,t){let r=(await n(e)).transaction(t,`readwrite`).objectStore(t);return new Promise((e,t)=>{let n=r.clear();n.onsuccess=()=>e(),n.onerror=()=>t(n.error)})}async function c(e,t){let r=(await n(e)).transaction(t,`readonly`).objectStore(t);return new Promise((e,t)=>{let n=r.getAllKeys();n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)})}async function l(e,t){let r=(await n(e)).transaction(t,`readonly`).objectStore(t);return new Promise((e,t)=>{let n=r.count();n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)})}async function u(e,t){let r=(await n(e)).transaction(t,`readonly`).objectStore(t);return new Promise((e,t)=>{let n=r.getAll();n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)})}e.addEventListener(`message`,async t=>{let n=t.data;try{let t;switch(n.type){case`get`:t=await r(n.db,n.store,n.key);break;case`getBatch`:t=await i(n.db,n.store,n.keys);break;case`set`:await a(n.db,n.store,n.key,n.value),t=void 0;break;case`del`:await o(n.db,n.store,n.key),t=void 0;break;case`clear`:await s(n.db,n.store),t=void 0;break;case`keys`:t=await c(n.db,n.store);break;case`count`:t=await l(n.db,n.store);break;case`getAll`:t=await u(n.db,n.store);break;default:throw Error(`Unknown IDB operation: ${n.type}`)}let d={id:n.id,type:`success`,result:t};e.postMessage(d)}catch(t){let r={id:n.id,type:`error`,error:t instanceof Error?t.message:`Unknown error`};e.postMessage(r)}});