"use strict";(self.webpackChunk_bidwright_model_editor=self.webpackChunk_bidwright_model_editor||[]).push([["725"],{4636(e,r,t){t.d(r,{IndexedDBStorage:()=>IndexedDBStorage});var o=t(9217);let IndexedDBStorage=class IndexedDBStorage{async createDBIfNeeded(e,r){let t=await this.openOrCreateDB(e,r),o=!1;for(let e of r)if(!t.objectStoreNames.contains(e)){o=!0;break}if(o){let o=t.version+1;t.close(),t=await this.openOrCreateDB(e,r,o)}t.close()}openOrCreateDB(e,r,t){return new Promise((s,n)=>{let a=window.indexedDB.open(e,t);a.onsuccess=r=>{o.Logger.info(`open ${e} success`),s(r.target.result)},a.onerror=r=>{o.Logger.error(`open ${e} error`),n(r)},a.onupgradeneeded=t=>{o.Logger.info(`upgrade ${e}`);let s=t.target.result;r.forEach(e=>{s.objectStoreNames.contains(e)||(o.Logger.info(`create store ${e}`),s.createObjectStore(e))})}})}async get(e,r,t){let o=await this.open(e);return Promise.try(IndexedDBStorage.get,o,r,t).finally(()=>{o.close()})}async put(e,r,t,o){let s=await this.open(e);return Promise.try(IndexedDBStorage.put,s,r,t,o).finally(()=>{s.close()})}async delete(e,r,t){let o=await this.open(e);return Promise.try(IndexedDBStorage.delete,o,r,t).finally(()=>{o.close()})}async page(e,r,t){let o=await this.open(e);return Promise.try(IndexedDBStorage.getPage,o,r,t).finally(()=>{o.close()})}open(e){let r=window.indexedDB.open(e);return new Promise((t,s)=>{r.onsuccess=r=>{o.Logger.info(`open ${e} success`),t(r.target.result)},r.onerror=r=>{o.Logger.error(`open ${e} error`),s(r)}})}static get(e,r,t){let s=e.transaction([r],"readonly").objectStore(r).get(t);return new Promise((e,t)=>{s.onsuccess=t=>{o.Logger.info(`${r} store get object success`),e(t.target.result)},s.onerror=e=>{o.Logger.error(`${r} store get object error`),t(e)}})}static getPage(e,r,t,s=20){let n=[],a=0,c=!1,i=e.transaction([r],"readonly").objectStore(r).openCursor();return new Promise((e,g)=>{i.onsuccess=i=>{let g=i.target.result;g&&a!==s?!c&&t*s>0?(c=!0,g.advance(t*s)):(n.push(g.value),a++,g.continue()):(o.Logger.info(`${r} store get objects success`),e(n))},i.onerror=e=>{o.Logger.error(`${r} store get objects error`),g(e)}})}static delete(e,r,t){let s=e.transaction([r],"readwrite").objectStore(r).delete(t);return new Promise((e,t)=>{s.onsuccess=()=>{o.Logger.info(`${r} store delete object success`),e(!0)},s.onerror=e=>{o.Logger.error(`${r} store delete object error`),t(e)}})}static put(e,r,t,s){let n=e.transaction([r],"readwrite").objectStore(r).put(s,t);return new Promise((e,t)=>{n.onsuccess=()=>{o.Logger.info(`${r} store put object success`),e(!0)},n.onerror=e=>{o.Logger.error(`${r} store put object error`),t(e)}})}}}}]);