const e=Promise,t=globalThis.window,n=clearInterval,r=e=>null==e,o=(e,t,n)=>r(e)?null==n?void 0:n():t(e),l=e=>Array.isArray(e),i=t=>new e(t),u=t=>{return n=function*(){return e.all(t)},new Promise(((e,t)=>{var r=e=>{try{l(n.next(e))}catch(e){t(e)}},o=e=>{try{l(n.throw(e))}catch(e){t(e)}},l=t=>t.done?e(t.value):Promise.resolve(t.value).then(r,o);l((n=n.apply(void 0,null)).next())}));var n},a=e=>{throw Error(e)},s=(e,t)=>e.map(t),c=(e,...t)=>e.push(...t),d=Object,v=e=>d.getPrototypeOf(e),y=d.entries,p=d.keys,h=d.freeze,f=e=>(e=>!r(e)&&o(v(e),(e=>e==d.prototype||r(v(e))),(()=>!0)))(e)&&0==(e=>p(e).length)(e),g=e=>new Map(e),b=(e,t)=>null==e?void 0:e.get(t),w=(e,t,n)=>{return r(n)?(l=t,null==(o=e)||o.delete(l),e):null==e?void 0:e.set(t,n);var o,l},m=(e,t,n,r)=>{var o,l,i;return l=t,null!=(i=null==(o=e)?void 0:o.has(l))&&i||w(e,t,n()),b(e,t)};var P=Object.defineProperty,A=Object.getOwnPropertySymbols,C=Object.prototype.hasOwnProperty,S=Object.prototype.propertyIsEnumerable,x=(e,t,n)=>t in e?P(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,O=(e,t,n)=>new Promise(((r,o)=>{var l=e=>{try{u(n.next(e))}catch(e){o(e)}},i=e=>{try{u(n.throw(e))}catch(e){o(e)}},u=e=>e.done?r(e.value):Promise.resolve(e.value).then(l,i);u((n=n.apply(e,t)).next())}));const j=g(),D=g();var M=(e,t,n)=>new Promise(((r,o)=>{var l=e=>{try{u(n.next(e))}catch(e){o(e)}},i=e=>{try{u(n.throw(e))}catch(e){o(e)}},u=e=>e.done?r(e.value):Promise.resolve(e.value).then(l,i);u((n=n.apply(e,t)).next())}));const k=["t","v"],L={keyPath:"k"},T=(e,t)=>M(void 0,null,(function*(){const n=(t=>s(y(t),(([t,n])=>B(e,"put",{k:t,v:n}))))(t);s(yield B(e,"getAllKeys"),(r=>((e,t)=>t in e)(t,r)?0:c(n,B(e,"delete",r)))),yield u(n)})),B=(e,t,n)=>M(void 0,null,(function*(){return i(((r,o)=>{const l=e[t](n);l.onsuccess=()=>r(l.result),l.onerror=()=>o(`objectStore.${t} error`)}))})),E=(e,v,y=1,p)=>{const g=(e,...n)=>M(void 0,[e,...n],(function*(e,n=[],r=0){return i(((o,l)=>{const i=(t?t.indexedDB:indexedDB).open(v,r?2:void 0);i.onupgradeneeded=()=>r&&s(k,(e=>{try{i.result.createObjectStore(e,L)}catch(e){}})),i.onsuccess=()=>M(void 0,null,(function*(){try{const t=i.result.transaction(k,"readwrite"),r=yield u(s(k,((r,o)=>M(void 0,null,(function*(){return yield e(t.objectStore(r),n[o])})))));i.result.close(),o(r)}catch(e){i.result.close(),l(e)}})),i.onerror=()=>l("indexedDB.open error")}))}));return((e,t,n,i,u,s,d,v={},y=[])=>{let p,g,P,M=0,k=0,L=0;m(j,y,(()=>0)),m(D,y,(()=>[]));const[T,B,E,I,z]=((e=1,t)=>1!=e&&t.isMergeable()?[1,t.getMergeableContent,t.getTransactionMergeableChanges,([[e],[t]])=>!f(e)||!f(t),t.setDefaultContent]:2!=e?[0,t.getContent,t.getTransactionChanges,([e,t])=>!f(e)||!f(t),t.setContent]:a("Store type not supported by this Persister"))(d,e),F=t=>{(T&&l(null==t?void 0:t[0])?1===(null==t?void 0:t[2])?e.applyMergeableChanges:e.setMergeableContent:1===(null==t?void 0:t[2])?e.applyChanges:e.setContent)(t)},K=e=>O(void 0,null,(function*(){return 2!=M&&(M=1,k++,yield G((()=>O(void 0,null,(function*(){try{const e=yield t();l(e)?F(e):a("Content is not an array "+e)}catch(t){null==s||s(t),e&&z(e)}M=0}))))),H})),N=()=>(g&&(u(g),g=void 0),H),$=e=>O(void 0,null,(function*(){return 1!=M&&(M=2,L++,yield G((()=>O(void 0,null,(function*(){try{yield n(B,e)}catch(e){null==s||s(e)}M=0}))))),H})),q=()=>(o(P,e.delListener),P=void 0,H),G=(...e)=>O(void 0,null,(function*(){return c(b(D,y),...e),yield O(void 0,null,(function*(){if(!b(j,y)){for(w(j,y,1);!r((e=b(D,y),p=e.shift()));)try{yield p()}catch(e){null==s||s(e)}w(j,y,0)}var e})),H})),H=((e,t)=>{for(var n in t||(t={}))C.call(t,n)&&x(e,n,t[n]);if(A)for(var n of A(t))S.call(t,n)&&x(e,n,t[n]);return e})({load:K,startAutoLoad:e=>O(void 0,null,(function*(){yield N().load(e);try{g=yield i(((e,t)=>O(void 0,null,(function*(){t||e?2!=M&&(M=1,k++,F(null!=t?t:e),M=0):yield K()}))))}catch(e){null==s||s(e)}return H})),stopAutoLoad:N,isAutoLoading:()=>!r(g),save:$,startAutoSave:()=>O(void 0,null,(function*(){return yield q().save(),P=e.addDidFinishTransactionListener((()=>{const e=E();I(e)&&$(e)})),H})),stopAutoSave:q,isAutoSaving:()=>!r(P),schedule:G,getStore:()=>e,destroy:()=>(b(D,y).splice(0,void 0),N().stopAutoSave()),getStats:()=>({loads:k,saves:L})},v);return h(H)})(e,(()=>M(void 0,null,(function*(){return yield g((e=>M(void 0,null,(function*(){return((e=[])=>d.fromEntries(e))(s(yield B(e,"getAll"),(({k:e,v:t})=>[e,t])))}))))}))),(e=>M(void 0,null,(function*(){return yield g(((e,t)=>M(void 0,null,(function*(){return yield T(e,t)}))),e(),1)}))),(e=>setInterval(e,1e3*y)),(e=>n(e)),p,1,{getDbName:()=>v})};export{E as createIndexedDbPersister,T as objectStoreMatch};
