class c{constructor(){this.ready()}ready(){return new Promise((o,t)=>{if(this.db)o(this);else{this.objectStoreName="data-store";const r=window.indexedDB.open("data-project",1);r.onsuccess=e=>{this.db=e.target.result,o(this)},r.onupgradeneeded=e=>{const s=e.target.result;s.objectStoreNames.contains(this.objectStoreName)||s.createObjectStore(this.objectStoreName)},r.onerror=e=>{t(e)}}})}init(o,t){return new Promise((r,e)=>{const s=i=>{t&&typeof t=="function"&&t(!1,i),r(i)},n=i=>{t&&typeof t=="function"&&t(i),e(i)};return this.ready().then(()=>{o(s,n)}).catch(n)})}setItem(o,t,r){return this.init((e,s)=>{const n=this.db.transaction(this.objectStoreName,"readwrite").objectStore(this.objectStoreName).put(t,o);n.onsuccess=()=>e(t),n.onerror=s},r)}getItem(o,t){return this.init((r,e)=>{const s=this.db.transaction(this.objectStoreName).objectStore(this.objectStoreName).get(o);s.onsuccess=()=>r(s.result),s.onerror=e},t)}removeItem(o,t){return this.init((r,e)=>{const s=this.db.transaction(this.objectStoreName,"readwrite").objectStore(this.objectStoreName).delete(o);s.onsuccess=()=>r(o),s.onerror=e},t)}key(o,t){return this.init((r,e)=>{const s=this.db.transaction(this.objectStoreName).objectStore(this.objectStoreName).getAllKeys();s.onsuccess=()=>r(s.result[o]),s.onerror=e},t)}keys(o){return this.init((t,r)=>{const e=this.db.transaction(this.objectStoreName).objectStore(this.objectStoreName).getAllKeys();e.onsuccess=()=>t(e.result),e.onerror=r},o)}clear(o){return this.init((t,r)=>{const e=this.db.transaction(this.objectStoreName,"readwrite").objectStore(this.objectStoreName).clear();e.onsuccess=()=>t(null),e.onerror=r},o)}}typeof module<"u"&&typeof module.exports<"u"?module.exports=new c:window.dbStorage=new c;const u=new c;export{u as d};
