| 26 | } |
| 27 | |
| 28 | function openEditHistoryDb(): Promise<IDBDatabase> { |
| 29 | return new Promise((resolve, reject) => { |
| 30 | if (!globalThis.indexedDB) { |
| 31 | reject(new Error("IndexedDB is not available")); |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | const request = globalThis.indexedDB.open(DB_NAME, DB_VERSION); |
| 36 | request.onupgradeneeded = () => { |
| 37 | const db = request.result; |
| 38 | if (!db.objectStoreNames.contains(STORE_NAME)) { |
| 39 | db.createObjectStore(STORE_NAME); |
| 40 | } |
| 41 | }; |
| 42 | request.onerror = () => reject(request.error ?? new Error("Failed to open edit history db")); |
| 43 | request.onsuccess = () => resolve(request.result); |
| 44 | }); |
| 45 | } |
| 46 | |
| 47 | function withStore<T>( |
| 48 | mode: IDBTransactionMode, |