(database: string)
| 84 | ) |
| 85 | |
| 86 | const openDatabase = (database: string): Effect.Effect<IDBDatabase, Persistence.PersistenceError> => |
| 87 | Effect.gen(function*() { |
| 88 | const openRequest = yield* Effect.try({ |
| 89 | try: () => globalThis.indexedDB.open(database, databaseVersion), |
| 90 | catch: (cause) => |
| 91 | new Persistence.PersistenceError({ |
| 92 | message: "Failed to open backing store database", |
| 93 | cause |
| 94 | }) |
| 95 | }) |
| 96 | |
| 97 | openRequest.onupgradeneeded = () => { |
| 98 | const db = openRequest.result |
| 99 | const entries = db.objectStoreNames.contains(entriesStoreName) |
| 100 | ? openRequest.transaction?.objectStore(entriesStoreName) |
| 101 | : db.createObjectStore(entriesStoreName, { keyPath: ["storeId", "id"] }) |
| 102 | if (entries && !entries.indexNames.contains(storeIdIndexName)) { |
| 103 | entries.createIndex(storeIdIndexName, storeIdIndexName, { unique: false }) |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | return yield* idbRequest("Failed to open backing store database", () => openRequest) |
| 108 | }) |
| 109 | |
| 110 | interface EntryRow { |
| 111 | readonly storeId: string |
no test coverage detected