@korajs/store 1.0.0-beta.11 → 1.0.0-beta.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/README.md +29 -37
  2. package/dist/adapters/better-sqlite3.cjs +90 -4
  3. package/dist/adapters/better-sqlite3.cjs.map +1 -1
  4. package/dist/adapters/better-sqlite3.d.cts +21 -12
  5. package/dist/adapters/better-sqlite3.d.ts +21 -12
  6. package/dist/adapters/better-sqlite3.js +69 -5
  7. package/dist/adapters/better-sqlite3.js.map +1 -1
  8. package/dist/adapters/indexeddb.cjs +1316 -610
  9. package/dist/adapters/indexeddb.cjs.map +1 -1
  10. package/dist/adapters/indexeddb.d.cts +29 -3
  11. package/dist/adapters/indexeddb.d.ts +29 -3
  12. package/dist/adapters/indexeddb.js +247 -221
  13. package/dist/adapters/indexeddb.js.map +1 -1
  14. package/dist/adapters/sqlite-wasm-worker.cjs +803 -62
  15. package/dist/adapters/sqlite-wasm-worker.cjs.map +1 -1
  16. package/dist/adapters/sqlite-wasm-worker.js +480 -62
  17. package/dist/adapters/sqlite-wasm-worker.js.map +1 -1
  18. package/dist/adapters/sqlite-wasm.cjs +1032 -344
  19. package/dist/adapters/sqlite-wasm.cjs.map +1 -1
  20. package/dist/adapters/sqlite-wasm.d.cts +239 -18
  21. package/dist/adapters/sqlite-wasm.d.ts +239 -18
  22. package/dist/adapters/sqlite-wasm.js +111 -5
  23. package/dist/adapters/sqlite-wasm.js.map +1 -1
  24. package/dist/backup-4NUPDEMB.js +25 -0
  25. package/dist/chunk-32EDKWMI.js +876 -0
  26. package/dist/chunk-32EDKWMI.js.map +1 -0
  27. package/dist/{chunk-CYO3YKFL.js → chunk-5ZRRF6R2.js} +2 -2
  28. package/dist/chunk-A6GFH5IG.js +36 -0
  29. package/dist/chunk-A6GFH5IG.js.map +1 -0
  30. package/dist/chunk-DUKTWVZW.js +175 -0
  31. package/dist/chunk-DUKTWVZW.js.map +1 -0
  32. package/dist/chunk-HZTDBLDB.js +607 -0
  33. package/dist/chunk-HZTDBLDB.js.map +1 -0
  34. package/dist/{chunk-GSJ7EEUC.js → chunk-J5AGXF3D.js} +58 -9
  35. package/dist/chunk-J5AGXF3D.js.map +1 -0
  36. package/dist/chunk-MCQKEHOD.js +112 -0
  37. package/dist/chunk-MCQKEHOD.js.map +1 -0
  38. package/dist/chunk-P4V375FY.js +810 -0
  39. package/dist/chunk-P4V375FY.js.map +1 -0
  40. package/dist/chunk-QDUSJMFV.js +1095 -0
  41. package/dist/chunk-QDUSJMFV.js.map +1 -0
  42. package/dist/chunk-SJP2HTYZ.js +1003 -0
  43. package/dist/chunk-SJP2HTYZ.js.map +1 -0
  44. package/dist/chunk-W5F2LWG6.js +591 -0
  45. package/dist/chunk-W5F2LWG6.js.map +1 -0
  46. package/dist/chunk-Y5LRH7KI.js +5341 -0
  47. package/dist/chunk-Y5LRH7KI.js.map +1 -0
  48. package/dist/{export-audit-ODGQTQIK.js → export-audit-J2QXRHD2.js} +3 -3
  49. package/dist/index.cjs +9354 -4157
  50. package/dist/index.cjs.map +1 -1
  51. package/dist/index.d.cts +1064 -108
  52. package/dist/index.d.ts +1064 -108
  53. package/dist/index.js +249 -3092
  54. package/dist/index.js.map +1 -1
  55. package/dist/internal.cjs +580 -264
  56. package/dist/internal.cjs.map +1 -1
  57. package/dist/internal.d.cts +15 -85
  58. package/dist/internal.d.ts +15 -85
  59. package/dist/internal.js +10 -8
  60. package/dist/restore-FR7XIKT2.js +299 -0
  61. package/dist/restore-FR7XIKT2.js.map +1 -0
  62. package/dist/sql-builder-C4u55jKW.d.cts +608 -0
  63. package/dist/sql-builder-CGckdBDL.d.ts +608 -0
  64. package/dist/sqlite-wasm-channel-DVX93Uiq.d.cts +141 -0
  65. package/dist/sqlite-wasm-channel-DVX93Uiq.d.ts +141 -0
  66. package/dist/sqlite-wasm-channel-MLHLKEED.js +12 -0
  67. package/dist/store-IMWKZLWB.js +16 -0
  68. package/dist/store-IMWKZLWB.js.map +1 -0
  69. package/dist/{types-BslDOTk0.d.ts → types-Dh-xyUjP.d.cts} +99 -26
  70. package/dist/{types-BslDOTk0.d.cts → types-Dh-xyUjP.d.ts} +99 -26
  71. package/package.json +3 -2
  72. package/dist/backup-5S7K2Z35.js +0 -14
  73. package/dist/chunk-GSJ7EEUC.js.map +0 -1
  74. package/dist/chunk-HS6DBMST.js +0 -383
  75. package/dist/chunk-HS6DBMST.js.map +0 -1
  76. package/dist/chunk-RJIEKEN4.js +0 -751
  77. package/dist/chunk-RJIEKEN4.js.map +0 -1
  78. package/dist/chunk-TUR7RGEP.js +0 -84
  79. package/dist/chunk-TUR7RGEP.js.map +0 -1
  80. package/dist/chunk-VDBJQ75K.js +0 -78
  81. package/dist/chunk-VDBJQ75K.js.map +0 -1
  82. package/dist/chunk-YT7MRFCP.js +0 -687
  83. package/dist/chunk-YT7MRFCP.js.map +0 -1
  84. package/dist/sqlite-wasm-channel-GGHA2BXU.js +0 -12
  85. package/dist/sqlite-wasm-channel-L6o3bWQK.d.cts +0 -92
  86. package/dist/sqlite-wasm-channel-L6o3bWQK.d.ts +0 -92
  87. package/dist/types-BOO9EPt1.d.ts +0 -170
  88. package/dist/types-C_GDavG-.d.cts +0 -170
  89. /package/dist/{backup-5S7K2Z35.js.map → backup-4NUPDEMB.js.map} +0 -0
  90. /package/dist/{chunk-CYO3YKFL.js.map → chunk-5ZRRF6R2.js.map} +0 -0
  91. /package/dist/{export-audit-ODGQTQIK.js.map → export-audit-J2QXRHD2.js.map} +0 -0
  92. /package/dist/{sqlite-wasm-channel-GGHA2BXU.js.map → sqlite-wasm-channel-MLHLKEED.js.map} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/adapters/sqlite-wasm-adapter.ts","../src/adapters/database-dump.ts","../src/adapters/sqlite-wasm-persistence.ts","../src/adapters/storage-manifest.ts"],"sourcesContent":["import { generateFullDDL } from '@korajs/core'\nimport type { KoraEventEmitter, SchemaDefinition } from '@korajs/core'\nimport {\n\tAdapterError,\n\tBridgeTerminatedError,\n\tStorageDurabilityError,\n\tStoreNotOpenError,\n} from '../errors'\nimport {\n\tFollowerBroadcastBridge,\n\ttype TabStorageSession,\n\tacquireTabStorageSession,\n} from '../multi-tab/tab-storage'\nimport type {\n\tMigrationPlan,\n\tStorageAdapter,\n\tStorageFallbackReason,\n\tStorageOpenState,\n\tTransaction,\n} from '../types'\nimport { restoreDumpStatements } from './database-dump'\nimport type { DatabaseDump } from './database-dump'\nimport { Mutex } from './sqlite-wasm-channel'\nimport type {\n\tWebWorkerBridge,\n\tWorkerBridge,\n\tWorkerRequest,\n\tWorkerResponse,\n\tWorkerSendOptions,\n\tWorkerStatusEvent,\n} from './sqlite-wasm-channel'\nimport { deleteFromIndexedDB, loadDumpFromIndexedDB } from './sqlite-wasm-persistence'\nimport { isManifestAvailable, readManifestRecord, recordDatabase } from './storage-manifest'\n\ntype WorkerSuccessResponse = Extract<WorkerResponse, { type: 'success' }>\nlet warnedSharedWorkerDeprecated = false\n\n/** Per-request options for {@link SqliteWasmAdapter.execute} and `query`. */\nexport interface StorageRequestOptions {\n\t/**\n\t * Stop waiting for the response. The leader may still apply a write that\n\t * already reached it; retry with the same `requestId` to stay idempotent.\n\t */\n\tsignal?: AbortSignal\n\t/**\n\t * Stable id for this request. A follower tab's retry with the same id is\n\t * answered from the leader's response cache instead of being applied twice.\n\t */\n\trequestId?: string\n}\n\n/**\n * Options for creating a SqliteWasmAdapter.\n */\nexport interface SqliteWasmAdapterOptions {\n\t/**\n\t * Injected WorkerBridge for testing. If omitted, a WebWorkerBridge is created\n\t * in browser environments.\n\t */\n\tbridge?: WorkerBridge\n\n\t/**\n\t * Database name for persistence. Each database gets its own OPFS pool.\n\t */\n\tdbName?: string\n\n\t/**\n\t * URL to the sqlite-wasm-worker script. Required in browsers if no bridge is provided.\n\t */\n\tworkerUrl?: string | URL\n\n\t/** Timeout for worker / follower RPC responses. Defaults to 30000ms. */\n\tworkerResponseTimeoutMs?: number\n\n\t/**\n\t * @deprecated SharedWorker-hosted SQLite cannot use OPFS SyncAccessHandle and\n\t * is never durable. Kora ignores this option and uses the dedicated-worker\n\t * leader/follower path for durable multi-tab storage.\n\t */\n\tsharedWorkerUrl?: string | URL\n\n\t/**\n\t * When false, the adapter records a non-persistent open without emitting\n\t * `store:opfs-unavailable`. `createApp()` uses this while it promotes the store\n\t * to durable IndexedDB; direct adapter users keep the diagnostic by default.\n\t */\n\temitNonPersistentDiagnostic?: boolean\n\n\t/**\n\t * Accept writes when durable OPFS storage could not be obtained and the\n\t * database runs in memory. Defaults to false: a non-durable open or promotion\n\t * emits the blocking `store:durability-lost` event and every write is refused\n\t * with {@link StorageDurabilityError}, so data is never accepted and then lost\n\t * on reload. Set true only for apps that can tolerate losing local writes.\n\t */\n\tallowNonDurable?: boolean\n\n\t/**\n\t * For `createApp()`: skip the durability check at open only, because the caller\n\t * inspects {@link SqliteWasmAdapter.getStorageOpenState} right after open and\n\t * switches to a durable backend itself. A later leader promotion that loses\n\t * durable storage is still enforced.\n\t */\n\tdeferOpenDurabilityCheck?: boolean\n\n\t/**\n\t * Release storage ownership when the page is frozen or hidden into the\n\t * back/forward cache (`freeze` / `pagehide`), so a visible tab can take over\n\t * instead of waiting on a tab that cannot run; ownership is re-acquired on\n\t * `resume` / `pageshow`. Defaults to true.\n\t */\n\treleaseOnFreeze?: boolean\n\n\t/**\n\t * When set, storage diagnostics are emitted here: `store:opfs-unavailable`,\n\t * `store:durability-lost`, `store:storage-blocked` (another holder has the\n\t * storage; the open waits), `store:storage-migrated` and\n\t * `store:db-name-collision`.\n\t */\n\temitter?: KoraEventEmitter\n\n\t/**\n\t * @internal Used by the IndexedDB adapter: open an in-memory database that\n\t * never touches OPFS (the IndexedDB adapter persists snapshots itself).\n\t */\n\tstorage?: 'opfs' | 'memory'\n\n\t/**\n\t * @internal Do not read or write the storage manifest (the IndexedDB adapter's\n\t * inner database and its one-shot OPFS reader manage the manifest themselves).\n\t */\n\tskipBackendRecord?: boolean\n\n\t/**\n\t * @internal Used by the IndexedDB adapter (STORE-6): runs in one transaction on this\n\t * tab's OWN worker right after it opened the database as storage leader (first open\n\t * or promotion), before the worker serves any other tab. The IndexedDB adapter\n\t * restores its persisted snapshot here, so a snapshot is only ever restored into a\n\t * freshly created worker database and never over a leader's live one. Throwing fails\n\t * the open (or the promotion, which then refuses writes).\n\t */\n\tonLeaderWorkerOpened?: (tx: Transaction) => Promise<void>\n}\n\ninterface Gate {\n\tpromise: Promise<void>\n\topen(): void\n}\n\nfunction createGate(): Gate {\n\tlet open: () => void = () => {}\n\tconst promise = new Promise<void>((resolve) => {\n\t\topen = resolve\n\t})\n\treturn { promise, open }\n}\n\n/**\n * SQLite WASM adapter that communicates with a SQLite instance through a WorkerBridge.\n *\n * In browsers, one tab per database (the leader) runs a dedicated worker that\n * owns the database's OPFS pool; other tabs reach that worker over a\n * BroadcastChannel. In Node.js tests, the bridge is backed by MockWorkerBridge\n * wrapping better-sqlite3.\n *\n * Storage is durable or loud, never silently in memory (W8a): another holder of\n * the storage makes the open wait (reported with `store:storage-blocked`); only a\n * runtime without OPFS SAH support gets a non-durable database, which refuses\n * writes unless the app opted in with `allowNonDurable`.\n *\n * @example\n * ```typescript\n * // Browser usage\n * const adapter = new SqliteWasmAdapter({ workerUrl: '/sqlite-wasm-worker.js' })\n *\n * // Test usage with MockWorkerBridge\n * import { MockWorkerBridge } from './sqlite-wasm-mock-bridge'\n * const adapter = new SqliteWasmAdapter({ bridge: new MockWorkerBridge() })\n * ```\n */\nexport class SqliteWasmAdapter implements StorageAdapter {\n\tprivate bridge: WorkerBridge | null = null\n\t/** The dedicated worker this tab runs while it is the database's leader. */\n\tprivate ownWorker: WebWorkerBridge | null = null\n\tprivate opened = false\n\tprivate readonly mutex = new Mutex()\n\tprivate readonly injectedBridge: WorkerBridge | undefined\n\tprivate readonly workerUrl: string | URL | undefined\n\tprivate readonly sharedWorkerUrl: string | URL | undefined\n\tprivate readonly workerResponseTimeoutMs: number\n\tprivate readonly dbName: string\n\tprivate readonly emitter: KoraEventEmitter | undefined\n\tprivate tabSession: TabStorageSession | null = null\n\tprivate readonly emitNonPersistentDiagnostic: boolean\n\tprivate storageOpenState: StorageOpenState | null = null\n\t/** Retained so a follower promoted to leader can re-open its own worker. */\n\tprivate schema: SchemaDefinition | null = null\n\tprivate promoting = false\n\tprivate closing = false\n\tprivate suspended = false\n\t/** Requests wait here while leadership changes hands (promotion, resume). */\n\tprivate gate: Gate | null = null\n\tprivate removeLifecycleListeners: (() => void) | null = null\n\tprivate readonly allowNonDurable: boolean\n\tprivate readonly deferOpenDurabilityCheck: boolean\n\tprivate readonly releaseOnFreeze: boolean\n\tprivate readonly storage: 'opfs' | 'memory'\n\tprivate readonly skipBackendRecord: boolean\n\t/** Set when this adapter lost (or never had) durable storage; writes are refused. */\n\tprivate durabilityLoss: { phase: 'open' | 'promotion'; reason: string } | null = null\n\tprivate readonly onLeaderWorkerOpened: ((tx: Transaction) => Promise<void>) | undefined\n\n\tconstructor(options: SqliteWasmAdapterOptions = {}) {\n\t\tthis.injectedBridge = options.bridge\n\t\tthis.workerUrl = options.workerUrl\n\t\tthis.sharedWorkerUrl = options.sharedWorkerUrl\n\t\tthis.workerResponseTimeoutMs = options.workerResponseTimeoutMs ?? 30_000\n\t\tthis.dbName = options.dbName ?? 'kora-db'\n\t\tthis.emitter = options.emitter\n\t\tthis.emitNonPersistentDiagnostic = options.emitNonPersistentDiagnostic ?? true\n\t\tthis.allowNonDurable = options.allowNonDurable ?? false\n\t\tthis.deferOpenDurabilityCheck = options.deferOpenDurabilityCheck ?? false\n\t\tthis.releaseOnFreeze = options.releaseOnFreeze ?? true\n\t\tthis.storage = options.storage ?? 'opfs'\n\t\tthis.skipBackendRecord = options.skipBackendRecord ?? false\n\t\tthis.onLeaderWorkerOpened = options.onLeaderWorkerOpened\n\t}\n\n\tasync open(schema: SchemaDefinition): Promise<void> {\n\t\tif (this.opened) return\n\n\t\tconst ddlStatements = generateFullDDL(schema)\n\t\tif (this.injectedBridge) {\n\t\t\tthis.bridge = this.injectedBridge\n\t\t\tconst response = await this.openCurrentBridge(ddlStatements)\n\t\t\tthis.reportStorageMode(response.data)\n\t\t\tthis.enforceDurability('open')\n\t\t\tthis.opened = true\n\t\t\treturn\n\t\t}\n\t\tif (this.workerUrl) {\n\t\t\tthis.warnSharedWorkerDeprecated()\n\t\t\tthis.schema = schema\n\t\t\ttry {\n\t\t\t\tconst response = await this.attachAndOpen(ddlStatements)\n\t\t\t\tthis.reportStorageMode(response.data)\n\t\t\t\tthis.enforceDurability('open')\n\t\t\t\tawait this.afterLeaderOpen(response.data)\n\t\t\t\tthis.opened = true\n\t\t\t} catch (error) {\n\t\t\t\t// A failed open must not keep the worker, the OPFS pool or the leader\n\t\t\t\t// lock for the rest of the page's life (NEW-STORE-8).\n\t\t\t\tawait this.teardown()\n\t\t\t\tthrow error\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t\tthrow new AdapterError(\n\t\t\t'SqliteWasmAdapter requires either a bridge (for testing) or a workerUrl (for browsers). ' +\n\t\t\t\t'Pass { bridge: new MockWorkerBridge() } for tests, or { workerUrl: \"/worker.js\" } for browsers.',\n\t\t)\n\t}\n\n\t/**\n\t * Join the database as leader (own worker) or follower (RPC to the leader's\n\t * worker), then open it. The open waits, without a timeout, while another\n\t * holder still has the storage; the worker reports that as a blocking state.\n\t */\n\tprivate async attachAndOpen(ddlStatements: string[]): Promise<WorkerSuccessResponse> {\n\t\tconst workerUrl = this.workerUrl\n\t\tif (!workerUrl) {\n\t\t\tthrow new AdapterError('Durable SQLite WASM storage requires workerUrl.')\n\t\t}\n\t\tconst session = await acquireTabStorageSession(this.dbName, {\n\t\t\tonPromote: () => {\n\t\t\t\tvoid this.promoteToLeader()\n\t\t\t},\n\t\t})\n\t\tthis.tabSession = session\n\n\t\tif (session.role === 'leader') {\n\t\t\tconst { WebWorkerBridge } = await import('./sqlite-wasm-channel')\n\t\t\tconst worker = new WebWorkerBridge(workerUrl, this.workerResponseTimeoutMs, {\n\t\t\t\tonEvent: (event) => this.onWorkerEvent(event),\n\t\t\t})\n\t\t\tthis.ownWorker = worker\n\t\t\tthis.bridge = worker\n\t\t\tconst response = await this.openLeaderWorker(worker, ddlStatements)\n\t\t\tthis.installLifecycleListeners()\n\t\t\treturn response\n\t\t}\n\n\t\tconst followerBridge = new FollowerBroadcastBridge(\n\t\t\tsession.channelName,\n\t\t\tthis.workerResponseTimeoutMs,\n\t\t)\n\t\tthis.bridge = followerBridge\n\t\t// Another runtime on this origin already owns this database name. That is\n\t\t// expected for multiple tabs of the same app (they share one leader),\n\t\t// but a bug if these are logically separate apps, so surface it so the\n\t\t// developer can give them distinct store names.\n\t\tthis.emitter?.emit({\n\t\t\ttype: 'store:db-name-collision',\n\t\t\tdbName: this.dbName,\n\t\t\tmessage: `Another runtime on this origin is already using database \"${this.dbName}\"; this runtime is sharing it as a follower. If these are separate apps, give each a distinct store name.`,\n\t\t})\n\t\t// Readiness handshake: give the leader relay a moment to answer before the\n\t\t// first RPC, so a follower opened during a leader's startup race retries the\n\t\t// handshake instead of firing into the void.\n\t\tawait followerBridge.waitForLeader()\n\t\tthis.installLifecycleListeners()\n\t\treturn this.checkedOpen(followerBridge, ddlStatements)\n\t}\n\n\t/** Open the database in this tab's own worker and start serving followers. */\n\tprivate async openLeaderWorker(\n\t\tworker: WebWorkerBridge,\n\t\tddlStatements: string[],\n\t): Promise<WorkerSuccessResponse> {\n\t\tconst hook = this.onLeaderWorkerOpened\n\t\tif (!hook) {\n\t\t\tconst pending = this.checkedOpen(worker, ddlStatements)\n\t\t\t// Posted after the open so follower requests queue behind it in the worker.\n\t\t\tworker.post({ id: 0, type: 'serve', channelName: this.tabSession?.channelName ?? '' })\n\t\t\treturn pending\n\t\t}\n\t\tconst response = await this.checkedOpen(worker, ddlStatements)\n\t\t// The hook (snapshot restore, STORE-6) runs before the worker serves other tabs,\n\t\t// so no follower ever reads or writes the database before it holds its data.\n\t\tawait runWorkerTransaction(worker, hook)\n\t\tworker.post({ id: 0, type: 'serve', channelName: this.tabSession?.channelName ?? '' })\n\t\treturn response\n\t}\n\n\t/**\n\t * Whether this runtime owns the database's worker: the storage leader in a browser,\n\t * or any adapter with an injected bridge (tests, Node). A follower tab relays every\n\t * request to the leader's worker (STORE-6).\n\t */\n\tisLeader(): boolean {\n\t\tif (this.injectedBridge) return true\n\t\treturn this.tabSession?.role === 'leader'\n\t}\n\n\tprivate async checkedOpen(\n\t\tbridge: WorkerBridge,\n\t\tddlStatements: string[],\n\t): Promise<WorkerSuccessResponse> {\n\t\tconst response = await bridge.send(\n\t\t\t{\n\t\t\t\tid: 0,\n\t\t\t\ttype: 'open',\n\t\t\t\tddlStatements,\n\t\t\t\tdbName: this.dbName,\n\t\t\t\t...(this.storage === 'memory' ? { storage: 'memory' as const } : {}),\n\t\t\t},\n\t\t\tundefined,\n\t\t\t{ timeoutMs: Number.POSITIVE_INFINITY },\n\t\t)\n\t\tif (response.type === 'error') {\n\t\t\tthrow new AdapterError(`Failed to open database: ${response.message}`, {\n\t\t\t\tcode: response.code,\n\t\t\t\tdbName: this.dbName,\n\t\t\t\t...(response.context ?? {}),\n\t\t\t})\n\t\t}\n\t\treturn response\n\t}\n\n\tprivate async openCurrentBridge(ddlStatements: string[]): Promise<WorkerSuccessResponse> {\n\t\tconst bridge = this.bridge\n\t\tif (!bridge) throw new StoreNotOpenError()\n\t\treturn this.checkedOpen(bridge, ddlStatements)\n\t}\n\n\tprivate onWorkerEvent(event: WorkerStatusEvent): void {\n\t\tif (!this.emitter) return\n\t\tconst holder =\n\t\t\tevent.resource === 'legacy-pool'\n\t\t\t\t? 'the shared OPFS pool used by older Kora versions (a tab running an older version of this app may still be open)'\n\t\t\t\t: 'another tab or worker that is still releasing it'\n\t\tif (event.kind === 'storage-blocked') {\n\t\t\tthis.emitter.emit({\n\t\t\t\ttype: 'store:storage-blocked',\n\t\t\t\tdbName: this.dbName,\n\t\t\t\tresource: event.resource,\n\t\t\t\tstate: 'waiting',\n\t\t\t\tmessage: `Database \"${this.dbName}\" is waiting for ${holder}. Close other tabs of this app if this persists; Kora will not fall back to non-durable storage.`,\n\t\t\t})\n\t\t\treturn\n\t\t}\n\t\tthis.emitter.emit({\n\t\t\ttype: 'store:storage-blocked',\n\t\t\tdbName: this.dbName,\n\t\t\tresource: event.resource,\n\t\t\tstate: 'resolved',\n\t\t\twaitedMs: event.waitedMs,\n\t\t\tmessage: `Database \"${this.dbName}\" obtained its storage after waiting ${event.waitedMs}ms.`,\n\t\t})\n\t}\n\n\t/**\n\t * Leader-only bookkeeping after a durable open: report a legacy-pool\n\t * migration, move an IndexedDB-held copy into OPFS explicitly (never two\n\t * disjoint copies), and record OPFS as this database's backend.\n\t */\n\tprivate async afterLeaderOpen(data: unknown): Promise<void> {\n\t\tif (!this.ownWorker || this.skipBackendRecord || this.storageOpenState?.persistent !== true) {\n\t\t\treturn\n\t\t}\n\t\tconst info = (typeof data === 'object' && data !== null ? data : {}) as {\n\t\t\tmigratedFromLegacy?: boolean\n\t\t}\n\t\tif (info.migratedFromLegacy === true) {\n\t\t\tthis.emitter?.emit({\n\t\t\t\ttype: 'store:storage-migrated',\n\t\t\t\tdbName: this.dbName,\n\t\t\t\tfrom: 'legacy-opfs-pool',\n\t\t\t\tto: 'opfs',\n\t\t\t\tmessage: `Database \"${this.dbName}\" moved from the shared pre-1.0 OPFS pool into its own pool.`,\n\t\t\t})\n\t\t}\n\t\tif (!isManifestAvailable()) return\n\n\t\tlet recordedBackend: string | null = null\n\t\ttry {\n\t\t\trecordedBackend = (await readManifestRecord(this.dbName))?.backend ?? null\n\t\t} catch (error) {\n\t\t\tconsole.warn(`[kora] Could not read the storage manifest for \"${this.dbName}\":`, error)\n\t\t}\n\t\tif (recordedBackend === 'indexeddb') {\n\t\t\t// The authoritative copy is in IndexedDB (an earlier session ran without\n\t\t\t// OPFS). Move it here before anything reads or writes; a failure fails\n\t\t\t// the open instead of showing the older OPFS copy.\n\t\t\tconst dump = await loadDumpFromIndexedDB<DatabaseDump>(this.dbName)\n\t\t\tif (dump) {\n\t\t\t\tawait this.applyDumpThroughWorker(this.ownWorker, dump)\n\t\t\t}\n\t\t\tthis.emitter?.emit({\n\t\t\t\ttype: 'store:storage-migrated',\n\t\t\t\tdbName: this.dbName,\n\t\t\t\tfrom: 'indexeddb',\n\t\t\t\tto: 'opfs',\n\t\t\t\tmessage: `Database \"${this.dbName}\" moved from IndexedDB into OPFS.`,\n\t\t\t})\n\t\t}\n\t\ttry {\n\t\t\tawait recordDatabase({\n\t\t\t\tdbName: this.dbName,\n\t\t\t\tbackend: 'opfs',\n\t\t\t\t...(this.storageOpenState.poolName ? { poolName: this.storageOpenState.poolName } : {}),\n\t\t\t})\n\t\t\tif (recordedBackend === 'indexeddb') {\n\t\t\t\tawait deleteFromIndexedDB(this.dbName)\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.warn(`[kora] Could not update the storage manifest for \"${this.dbName}\":`, error)\n\t\t}\n\t}\n\n\tprivate async applyDumpThroughWorker(worker: WorkerBridge, dump: DatabaseDump): Promise<void> {\n\t\tconst check = async (request: WorkerRequest, what: string): Promise<void> => {\n\t\t\tconst response = await worker.send(request)\n\t\t\tif (response.type === 'error') {\n\t\t\t\tthrow new AdapterError(`${what} failed: ${response.message}`, { dbName: this.dbName })\n\t\t\t}\n\t\t}\n\t\tawait check({ id: 0, type: 'begin' }, 'BEGIN IndexedDB import')\n\t\ttry {\n\t\t\tfor (const statement of restoreDumpStatements(dump)) {\n\t\t\t\tawait check(\n\t\t\t\t\t{ id: 0, type: 'execute', sql: statement.sql, params: statement.params },\n\t\t\t\t\t'IndexedDB import',\n\t\t\t\t)\n\t\t\t}\n\t\t\tawait check({ id: 0, type: 'commit' }, 'COMMIT IndexedDB import')\n\t\t} catch (error) {\n\t\t\tawait worker.send({ id: 0, type: 'rollback' }).catch(() => undefined)\n\t\t\tthrow error\n\t\t}\n\t}\n\n\t/**\n\t * Surface a `store:opfs-unavailable` diagnostic when the worker reported that\n\t * persistence silently degraded to an in-memory database, so a data-loss\n\t * condition is observable instead of failing silently. A persistent open (or a\n\t * bridge that does not report a mode, e.g. the Node mock) emits nothing.\n\t */\n\tprivate reportStorageMode(data: unknown): void {\n\t\tthis.storageOpenState = parseStorageOpenState(data)\n\t\tif (!this.emitNonPersistentDiagnostic || !this.emitter || !this.storageOpenState) {\n\t\t\treturn\n\t\t}\n\t\tif (this.storageOpenState.persistent === false && this.storage === 'opfs') {\n\t\t\tconst reason = this.storageOpenState.fallbackReason ?? 'unsupported'\n\t\t\tthis.emitter.emit({\n\t\t\t\ttype: 'store:opfs-unavailable',\n\t\t\t\tdbName: this.dbName,\n\t\t\t\treason,\n\t\t\t\tmessage: `OPFS persistence is unavailable (${reason}) for database \"${this.dbName}\"; the store is running in memory and data will not survive a reload.`,\n\t\t\t})\n\t\t}\n\t}\n\n\tgetStorageOpenState(): StorageOpenState | null {\n\t\treturn this.storageOpenState\n\t}\n\n\t/**\n\t * Durable or loud, never silent (NEW-STORE-6). When the open or a promotion\n\t * ended on non-persistent storage and the app did not opt into that, emit the\n\t * blocking `store:durability-lost` event and refuse every later write. A\n\t * bridge that reports no mode (the Node mock) is not judged.\n\t */\n\tprivate enforceDurability(\n\t\tphase: 'open' | 'promotion',\n\t\tfailure?: { reason: 'open-failed'; message: string },\n\t): void {\n\t\tif (this.allowNonDurable) return\n\t\tif (phase === 'open' && this.deferOpenDurabilityCheck && !failure) return\n\t\tlet reason: 'lock-conflict' | 'timeout' | 'unsupported' | 'open-failed'\n\t\tif (failure) {\n\t\t\treason = failure.reason\n\t\t} else if (this.storageOpenState?.persistent === false) {\n\t\t\treason = this.storageOpenState.fallbackReason ?? 'unsupported'\n\t\t} else {\n\t\t\tthis.durabilityLoss = null\n\t\t\treturn\n\t\t}\n\t\tthis.durabilityLoss = { phase, reason }\n\t\tthis.emitter?.emit({\n\t\t\ttype: 'store:durability-lost',\n\t\t\tdbName: this.dbName,\n\t\t\tphase,\n\t\t\treason,\n\t\t\tmessage:\n\t\t\t\t`Database \"${this.dbName}\" has no durable storage (${reason} during ${phase}); ` +\n\t\t\t\t`writes are refused until the app reloads with durable storage.${failure ? ` ${failure.message}` : ''}`,\n\t\t})\n\t}\n\n\tprivate guardDurableWrite(): void {\n\t\tif (this.durabilityLoss) {\n\t\t\tthrow new StorageDurabilityError(\n\t\t\t\tthis.dbName,\n\t\t\t\tthis.durabilityLoss.phase,\n\t\t\t\tthis.durabilityLoss.reason,\n\t\t\t)\n\t\t}\n\t}\n\n\tprivate warnSharedWorkerDeprecated(): void {\n\t\tif (!this.sharedWorkerUrl || warnedSharedWorkerDeprecated) {\n\t\t\treturn\n\t\t}\n\t\twarnedSharedWorkerDeprecated = true\n\t\tconsole.warn(\n\t\t\t'[kora] sharedWorkerUrl is deprecated and ignored: SharedWorker-hosted SQLite ' +\n\t\t\t\t'cannot use OPFS and is never durable. Kora uses the durable dedicated-worker ' +\n\t\t\t\t'leader/follower path for multi-tab storage.',\n\t\t)\n\t}\n\n\t/**\n\t * Close the database. A leader closes the database file and releases the OPFS\n\t * pool inside its worker, terminates the worker, and only then releases the\n\t * tab leader lock, so the next leader never races a still-running worker for\n\t * the file handles (NEW-STORE-10). A follower just leaves.\n\t */\n\tasync close(): Promise<void> {\n\t\tif (!this.bridge && !this.tabSession) return\n\t\tthis.closing = true\n\t\ttry {\n\t\t\tif (this.injectedBridge && this.bridge) {\n\t\t\t\tawait this.bridge.send({ id: 0, type: 'close' })\n\t\t\t} else if (this.ownWorker && !this.ownWorker.isTerminated()) {\n\t\t\t\tconst response = await this.ownWorker\n\t\t\t\t\t.send({ id: 0, type: 'close' }, undefined, { timeoutMs: 5000 })\n\t\t\t\t\t.catch((error: unknown) => ({\n\t\t\t\t\t\tid: 0,\n\t\t\t\t\t\ttype: 'error' as const,\n\t\t\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t\t\t\tcode: 'CLOSE_FAILED',\n\t\t\t\t\t}))\n\t\t\t\tif (response.type === 'error') {\n\t\t\t\t\t// Terminating the worker below still releases the pool.\n\t\t\t\t\tconsole.warn(`[kora] Closing \"${this.dbName}\" in its worker failed:`, response.message)\n\t\t\t\t}\n\t\t\t}\n\t\t} finally {\n\t\t\tawait this.teardown()\n\t\t\tthis.closing = false\n\t\t}\n\t}\n\n\t/**\n\t * Release everything this adapter holds, in ownership order: lifecycle\n\t * listeners, then the worker (which holds the OPFS pool and its Web Lock),\n\t * then the tab leader lock or queued promotion request.\n\t */\n\tprivate async teardown(): Promise<void> {\n\t\tthis.removeLifecycleListeners?.()\n\t\tthis.removeLifecycleListeners = null\n\t\tconst session = this.tabSession\n\t\tthis.tabSession = null\n\t\tsession?.stopRelay?.()\n\t\tthis.bridge?.terminate()\n\t\tthis.bridge = null\n\t\tthis.ownWorker = null\n\t\tif (session) {\n\t\t\tif (session.releaseLock) {\n\t\t\t\tawait session.releaseLock()\n\t\t\t}\n\t\t\tsession.cancelPromotionWatch?.()\n\t\t}\n\t\tthis.opened = false\n\t\tthis.suspended = false\n\t\tconst gate = this.gate\n\t\tthis.gate = null\n\t\tgate?.open()\n\t}\n\n\t/**\n\t * Promotes a follower to leader after the previous leader released the storage\n\t * lock (its tab closed, crashed, or suspended on freeze). The new worker waits\n\t * on the pool's Web Lock and handles, so it never races the previous worker.\n\t * Requests issued during the hand-off wait for it; requests that were in\n\t * flight to the old leader fail with a retriable `BridgeTerminatedError`.\n\t */\n\tprivate async promoteToLeader(): Promise<void> {\n\t\tif (\n\t\t\tthis.promoting ||\n\t\t\tthis.closing ||\n\t\t\t!this.opened ||\n\t\t\tthis.workerUrl === undefined ||\n\t\t\tthis.schema === null\n\t\t) {\n\t\t\treturn\n\t\t}\n\t\tthis.promoting = true\n\t\tconst gate = createGate()\n\t\tthis.gate = gate\n\n\t\ttry {\n\t\t\tconst { WebWorkerBridge } = await import('./sqlite-wasm-channel')\n\t\t\tif (this.closing || !this.opened) return\n\t\t\tconst worker = new WebWorkerBridge(this.workerUrl, this.workerResponseTimeoutMs, {\n\t\t\t\tonEvent: (event) => this.onWorkerEvent(event),\n\t\t\t})\n\t\t\tconst previousBridge = this.bridge\n\t\t\tthis.bridge = worker\n\t\t\tthis.ownWorker = worker\n\t\t\tif (this.tabSession) {\n\t\t\t\tthis.tabSession.role = 'leader'\n\t\t\t}\n\t\t\tpreviousBridge?.terminate()\n\n\t\t\t// Re-open against our own worker. DDL is idempotent, and the OPFS data the\n\t\t\t// old leader persisted is readable once its worker is gone.\n\t\t\tconst ddlStatements = generateFullDDL(this.schema)\n\t\t\tlet response: WorkerSuccessResponse\n\t\t\ttry {\n\t\t\t\tresponse = await this.openLeaderWorker(worker, ddlStatements)\n\t\t\t} catch (error) {\n\t\t\t\t// The promoted worker could not obtain durable storage. Never let it\n\t\t\t\t// run silently in memory.\n\t\t\t\tthis.storageOpenState = { persistent: false, mode: 'memory' }\n\t\t\t\tthis.enforceDurability('promotion', {\n\t\t\t\t\treason: 'open-failed',\n\t\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t\t})\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.storageOpenState = parseStorageOpenState(response.data) ?? this.storageOpenState\n\t\t\tthis.enforceDurability('promotion')\n\t\t\ttry {\n\t\t\t\tawait this.afterLeaderOpen(response.data)\n\t\t\t} catch (error) {\n\t\t\t\tthis.enforceDurability('promotion', {\n\t\t\t\t\treason: 'open-failed',\n\t\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t\t})\n\t\t\t}\n\t\t} finally {\n\t\t\tthis.promoting = false\n\t\t\tif (this.gate === gate) this.gate = null\n\t\t\tgate.open()\n\t\t}\n\t}\n\n\t/**\n\t * Page Lifecycle: a frozen or bfcached page cannot run, so it must not keep\n\t * other tabs waiting on its storage. Leaders terminate their worker (freeing\n\t * the OPFS pool) and then release the leader lock, so a visible tab is\n\t * promoted; followers withdraw their queued lock request so a frozen tab is\n\t * never granted leadership it cannot use. Never uses Web Locks `steal`.\n\t */\n\tprivate installLifecycleListeners(): void {\n\t\tif (!this.releaseOnFreeze || this.removeLifecycleListeners) return\n\t\tif (typeof addEventListener !== 'function' || typeof document === 'undefined') return\n\t\tconst onFreeze = (): void => this.suspend()\n\t\tconst onPageHide = (): void => this.suspend()\n\t\tconst onResume = (): void => {\n\t\t\tvoid this.resume()\n\t\t}\n\t\tconst onPageShow = (event: Event): void => {\n\t\t\tif ((event as PageTransitionEvent).persisted) void this.resume()\n\t\t}\n\t\tdocument.addEventListener('freeze', onFreeze)\n\t\tdocument.addEventListener('resume', onResume)\n\t\taddEventListener('pagehide', onPageHide)\n\t\taddEventListener('pageshow', onPageShow)\n\t\tthis.removeLifecycleListeners = () => {\n\t\t\tdocument.removeEventListener('freeze', onFreeze)\n\t\t\tdocument.removeEventListener('resume', onResume)\n\t\t\tremoveEventListener('pagehide', onPageHide)\n\t\t\tremoveEventListener('pageshow', onPageShow)\n\t\t}\n\t}\n\n\t/** Synchronous by necessity: a `freeze` handler gets no further turns. */\n\tprivate suspend(): void {\n\t\tif (!this.opened || this.suspended || this.closing || this.promoting) return\n\t\tthis.suspended = true\n\t\tthis.gate = createGate()\n\t\tconst session = this.tabSession\n\t\tthis.tabSession = null\n\t\t// Worker (pool holder) first, then the leader lock (NEW-STORE-10).\n\t\tthis.bridge?.terminate()\n\t\tthis.bridge = null\n\t\tthis.ownWorker = null\n\t\tif (session) {\n\t\t\tvoid session.releaseLock?.()\n\t\t\tsession.cancelPromotionWatch?.()\n\t\t}\n\t}\n\n\tprivate async resume(): Promise<void> {\n\t\tif (!this.suspended || this.closing || this.schema === null) return\n\t\tconst gate = this.gate\n\t\ttry {\n\t\t\tconst response = await this.attachAndOpen(generateFullDDL(this.schema))\n\t\t\tthis.reportStorageMode(response.data)\n\t\t\tthis.enforceDurability('promotion')\n\t\t\tawait this.afterLeaderOpen(response.data)\n\t\t} catch (error) {\n\t\t\tthis.enforceDurability('promotion', {\n\t\t\t\treason: 'open-failed',\n\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t})\n\t\t} finally {\n\t\t\tthis.suspended = false\n\t\t\tif (this.gate === gate) this.gate = null\n\t\t\tgate?.open()\n\t\t}\n\t}\n\n\t/**\n\t * Non-transactional write. Takes the same mutex as {@link transaction}, so it\n\t * never lands inside this tab's open transaction and is never rolled back\n\t * with it (STORE-8). Inside a transaction callback, use the `tx` handle.\n\t */\n\tasync execute(sql: string, params?: unknown[], options?: StorageRequestOptions): Promise<void> {\n\t\tthis.guardOpen()\n\t\tthis.guardDurableWrite()\n\t\tconst release = await this.mutex.acquire()\n\t\ttry {\n\t\t\tconst response = await this.sendRequest(\n\t\t\t\t{\n\t\t\t\t\tid: 0,\n\t\t\t\t\ttype: 'execute',\n\t\t\t\t\tsql,\n\t\t\t\t\tparams,\n\t\t\t\t\t...(options?.requestId ? { requestId: options.requestId } : {}),\n\t\t\t\t},\n\t\t\t\toptions?.signal ? { signal: options.signal } : undefined,\n\t\t\t)\n\t\t\tif (response.type === 'error') {\n\t\t\t\tthrow new AdapterError(`Execute failed: ${response.message}`, { sql, params })\n\t\t\t}\n\t\t} finally {\n\t\t\trelease()\n\t\t}\n\t}\n\n\t/**\n\t * Non-transactional read. Waits for this tab's open transaction to finish, so\n\t * it never observes uncommitted (possibly rolled-back) rows (STORE-8).\n\t */\n\tasync query<T>(sql: string, params?: unknown[], options?: StorageRequestOptions): Promise<T[]> {\n\t\tthis.guardOpen()\n\t\tconst release = await this.mutex.acquire()\n\t\ttry {\n\t\t\tconst response = await this.sendRequest(\n\t\t\t\t{\n\t\t\t\t\tid: 0,\n\t\t\t\t\ttype: 'query',\n\t\t\t\t\tsql,\n\t\t\t\t\tparams,\n\t\t\t\t\t...(options?.requestId ? { requestId: options.requestId } : {}),\n\t\t\t\t},\n\t\t\t\toptions?.signal ? { signal: options.signal } : undefined,\n\t\t\t)\n\t\t\tif (response.type === 'error') {\n\t\t\t\tthrow new AdapterError(`Query failed: ${response.message}`, { sql, params })\n\t\t\t}\n\t\t\treturn (response.data as T[]) ?? []\n\t\t} finally {\n\t\t\trelease()\n\t\t}\n\t}\n\n\tasync transaction(fn: (tx: Transaction) => Promise<void>): Promise<void> {\n\t\tthis.guardOpen()\n\t\tthis.guardDurableWrite()\n\n\t\tconst release = await this.mutex.acquire()\n\t\tlet txBridge: WorkerBridge | null = null\n\t\t// Every statement of the span must reach the worker that ran BEGIN. If\n\t\t// leadership changed hands mid-transaction, the old worker rolled it back\n\t\t// (or is gone); sending the rest to the new worker would autocommit a\n\t\t// partial transaction, so fail with a retriable error instead.\n\t\tconst sendInSpan = async (request: WorkerRequest): Promise<WorkerResponse> => {\n\t\t\tif (txBridge === null || this.bridge !== txBridge) {\n\t\t\t\tthrow new BridgeTerminatedError(request.type, 'storage leader changed during transaction')\n\t\t\t}\n\t\t\treturn txBridge.send(request)\n\t\t}\n\t\ttry {\n\t\t\twhile (this.gate) {\n\t\t\t\tawait this.gate.promise\n\t\t\t}\n\t\t\ttxBridge = this.bridge\n\t\t\tif (!txBridge) throw new StoreNotOpenError()\n\t\t\tconst begin = await sendInSpan({ id: 0, type: 'begin' })\n\t\t\tif (begin.type === 'error') {\n\t\t\t\tthrow new AdapterError(`BEGIN transaction failed: ${begin.message}`)\n\t\t\t}\n\n\t\t\tconst tx: Transaction = {\n\t\t\t\texecute: async (sql: string, params?: unknown[]): Promise<void> => {\n\t\t\t\t\tconst response = await sendInSpan({ id: 0, type: 'execute', sql, params })\n\t\t\t\t\tif (response.type === 'error') {\n\t\t\t\t\t\tthrow new AdapterError(`Transaction execute failed: ${response.message}`, {\n\t\t\t\t\t\t\tsql,\n\t\t\t\t\t\t\tparams,\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tquery: async <T>(sql: string, params?: unknown[]): Promise<T[]> => {\n\t\t\t\t\tconst response = await sendInSpan({ id: 0, type: 'query', sql, params })\n\t\t\t\t\tif (response.type === 'error') {\n\t\t\t\t\t\tthrow new AdapterError(`Transaction query failed: ${response.message}`, { sql, params })\n\t\t\t\t\t}\n\t\t\t\t\treturn (response.data as T[]) ?? []\n\t\t\t\t},\n\t\t\t}\n\n\t\t\tawait fn(tx)\n\t\t\tconst commit = await sendInSpan({ id: 0, type: 'commit' })\n\t\t\tif (commit.type === 'error') {\n\t\t\t\tthrow new AdapterError(`COMMIT transaction failed: ${commit.message}`)\n\t\t\t}\n\t\t} catch (error) {\n\t\t\t// Attempt rollback on the worker that ran BEGIN, but don't mask the\n\t\t\t// original error.\n\t\t\ttry {\n\t\t\t\tif (txBridge && this.bridge === txBridge) {\n\t\t\t\t\tawait txBridge.send({ id: 0, type: 'rollback' })\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\t// Rollback failure is secondary to the original error\n\t\t\t}\n\t\t\tthrow error\n\t\t} finally {\n\t\t\trelease()\n\t\t}\n\t}\n\n\tasync migrate(from: number, to: number, migration: MigrationPlan): Promise<void> {\n\t\tthis.guardOpen()\n\t\tthis.guardDurableWrite()\n\n\t\tconst release = await this.mutex.acquire()\n\t\ttry {\n\t\t\tawait this.sendChecked({ id: 0, type: 'begin' }, 'BEGIN migration')\n\n\t\t\tfor (const sql of migration.statements) {\n\t\t\t\tconst response = await this.sendRequest({ id: 0, type: 'execute', sql })\n\t\t\t\tif (response.type === 'error') {\n\t\t\t\t\tthrow new AdapterError(`Migration from v${from} to v${to} failed: ${response.message}`, {\n\t\t\t\t\t\tfrom,\n\t\t\t\t\t\tto,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tawait this.sendChecked({ id: 0, type: 'commit' }, 'COMMIT migration')\n\t\t} catch (error) {\n\t\t\ttry {\n\t\t\t\tawait this.sendRequest({ id: 0, type: 'rollback' })\n\t\t\t} catch {\n\t\t\t\t// Rollback failure is secondary\n\t\t\t}\n\t\t\tif (error instanceof AdapterError) throw error\n\t\t\tthrow new AdapterError(\n\t\t\t\t`Migration from v${from} to v${to} failed: ${(error as Error).message}`,\n\t\t\t\t{ from, to },\n\t\t\t)\n\t\t} finally {\n\t\t\trelease()\n\t\t}\n\t}\n\n\t/**\n\t * Export the database as a Uint8Array (for IndexedDB persistence).\n\t * Only available when the database is open.\n\t */\n\tasync exportDatabase(): Promise<Uint8Array> {\n\t\tthis.guardOpen()\n\t\tconst release = await this.mutex.acquire()\n\t\ttry {\n\t\t\tconst response = await this.sendRequest({ id: 0, type: 'export' })\n\t\t\tif (response.type === 'error') {\n\t\t\t\tthrow new AdapterError(`Export failed: ${response.message}`, {\n\t\t\t\t\tcode: response.code,\n\t\t\t\t\tcontext: response.context,\n\t\t\t\t})\n\t\t\t}\n\t\t\treturn response.data as Uint8Array\n\t\t} finally {\n\t\t\trelease()\n\t\t}\n\t}\n\n\t/**\n\t * Import a serialized database snapshot.\n\t */\n\tasync importDatabase(data: Uint8Array): Promise<void> {\n\t\tthis.guardOpen()\n\t\tthis.guardDurableWrite()\n\t\tconst release = await this.mutex.acquire()\n\t\ttry {\n\t\t\tconst response = await this.sendRequest({ id: 0, type: 'import', data })\n\t\t\tif (response.type === 'error') {\n\t\t\t\tthrow new AdapterError(`Import failed: ${response.message}`)\n\t\t\t}\n\t\t} finally {\n\t\t\trelease()\n\t\t}\n\t}\n\n\tprivate guardOpen(): void {\n\t\tif (!this.opened || (!this.bridge && !this.gate)) {\n\t\t\tthrow new StoreNotOpenError()\n\t\t}\n\t}\n\n\tprivate async sendRequest(\n\t\trequest: WorkerRequest,\n\t\toptions?: WorkerSendOptions,\n\t): Promise<WorkerResponse> {\n\t\t// While leadership changes hands, wait for the new bridge instead of\n\t\t// sending into a torn-down one.\n\t\twhile (this.gate) {\n\t\t\tawait this.gate.promise\n\t\t}\n\t\tconst bridge = this.bridge\n\t\tif (!bridge) {\n\t\t\tthrow new StoreNotOpenError()\n\t\t}\n\t\treturn bridge.send(request, undefined, options)\n\t}\n\n\tprivate async sendChecked(request: WorkerRequest, description: string): Promise<void> {\n\t\tconst response = await this.sendRequest(request)\n\t\tif (response.type === 'error') {\n\t\t\tthrow new AdapterError(`${description} failed: ${response.message}`)\n\t\t}\n\t}\n}\n\n/**\n * Run `fn` in one transaction sent straight to `worker`, bypassing the adapter's mutex\n * and leadership gate (the caller is the leader opening its own worker).\n */\nasync function runWorkerTransaction(\n\tworker: WorkerBridge,\n\tfn: (tx: Transaction) => Promise<void>,\n): Promise<void> {\n\tconst send = async (request: WorkerRequest, what: string): Promise<WorkerResponse> => {\n\t\tconst response = await worker.send(request)\n\t\tif (response.type === 'error') {\n\t\t\tthrow new AdapterError(`${what} failed: ${response.message}`, {\n\t\t\t\tcode: response.code,\n\t\t\t\t...(request.type === 'execute' || request.type === 'query' ? { sql: request.sql } : {}),\n\t\t\t})\n\t\t}\n\t\treturn response\n\t}\n\tawait send({ id: 0, type: 'begin' }, 'BEGIN')\n\ttry {\n\t\tawait fn({\n\t\t\texecute: async (sql, params) => {\n\t\t\t\tawait send({ id: 0, type: 'execute', sql, params }, 'Leader open execute')\n\t\t\t},\n\t\t\tquery: async <T>(sql: string, params?: unknown[]): Promise<T[]> => {\n\t\t\t\tconst response = await send({ id: 0, type: 'query', sql, params }, 'Leader open query')\n\t\t\t\treturn ((response as WorkerSuccessResponse).data as T[]) ?? []\n\t\t\t},\n\t\t})\n\t\tawait send({ id: 0, type: 'commit' }, 'COMMIT')\n\t} catch (error) {\n\t\tawait worker.send({ id: 0, type: 'rollback' }).catch(() => undefined)\n\t\tthrow error\n\t}\n}\n\nfunction parseStorageOpenState(data: unknown): StorageOpenState | null {\n\tif (typeof data !== 'object' || data === null) {\n\t\treturn null\n\t}\n\tconst mode = data as {\n\t\tpersistent?: boolean\n\t\tfallbackReason?: StorageFallbackReason\n\t\tpoolName?: string\n\t\tjournalMode?: string\n\t}\n\tif (typeof mode.persistent !== 'boolean') {\n\t\treturn null\n\t}\n\treturn {\n\t\tpersistent: mode.persistent,\n\t\tmode: mode.persistent ? 'opfs' : 'memory',\n\t\t...(mode.fallbackReason ? { fallbackReason: mode.fallbackReason } : {}),\n\t\t...(typeof mode.poolName === 'string' ? { poolName: mode.poolName } : {}),\n\t\t...(typeof mode.journalMode === 'string' ? { journalMode: mode.journalMode } : {}),\n\t}\n}\n","import { quoteIdent } from '@korajs/core'\nimport { PersistenceError } from '../errors'\n\n/**\n * Logical copy of every user table of a SQLite database. Used to move a\n * database between storage backends (OPFS <-> IndexedDB) explicitly, and as the\n * IndexedDB adapter's durable snapshot format.\n */\nexport interface DatabaseDump {\n\ttables: Array<{\n\t\tname: string\n\t\t/**\n\t\t * The table's `CREATE TABLE` statement (from `sqlite_master`), so a restore can\n\t\t * recreate a table the target database does not have yet with its constraints.\n\t\t * Absent in dumps written before it was recorded.\n\t\t */\n\t\tsql?: string\n\t\tcolumns: string[]\n\t\trows: Array<Record<string, unknown>>\n\t}>\n}\n\n/** A parameterized SQL statement. */\nexport interface DumpStatement {\n\tsql: string\n\tparams?: unknown[]\n}\n\ntype QueryFn = <T>(sql: string, params?: unknown[]) => Promise<T[]>\n\n/** Throws unless `identifier` is a plain SQL identifier (dump data is untrusted). */\nexport function ensureSafeIdentifier(identifier: string): string {\n\tif (!/^[a-zA-Z0-9_]+$/.test(identifier)) {\n\t\tthrow new PersistenceError(`Unsafe SQL identifier: ${identifier}`, {\n\t\t\tcode: 'UNSAFE_IDENTIFIER',\n\t\t\tidentifier,\n\t\t})\n\t}\n\treturn identifier\n}\n\n/**\n * Read every user table through `query`. Pass a transaction's `query` to get a\n * consistent snapshot.\n */\nexport async function exportDump(query: QueryFn): Promise<DatabaseDump> {\n\tconst tableRows = await query<{ name: string; sql: string | null }>(\n\t\t\"SELECT name, sql FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'\",\n\t)\n\tconst tables: DatabaseDump['tables'] = []\n\tfor (const tableRow of tableRows) {\n\t\tconst tableName = ensureSafeIdentifier(tableRow.name)\n\t\tconst columns = await query<{ name: string }>(`PRAGMA table_info(${quoteIdent(tableName)})`)\n\t\tconst rows = await query<Record<string, unknown>>(`SELECT * FROM ${quoteIdent(tableName)}`)\n\t\ttables.push({\n\t\t\tname: tableName,\n\t\t\t...(typeof tableRow.sql === 'string' ? { sql: tableRow.sql } : {}),\n\t\t\tcolumns: columns.map((column) => column.name),\n\t\t\trows,\n\t\t})\n\t}\n\treturn { tables }\n}\n\n/**\n * Statements that replace the contents of each dumped table with the dump's\n * rows. Run them inside one transaction so a failure leaves the target as it was.\n *\n * A table the target does not have yet (the store creates some of its bookkeeping\n * tables after the schema DDL) is created first from the dump's recorded `CREATE TABLE`\n * statement, constraints included. A dump written before statements were recorded\n * creates it untyped, so its rows are still restored.\n *\n * @param createMissingTables - Kept for callers that restore into scratch databases\n * with no schema; missing tables are always created now.\n */\nexport function restoreDumpStatements(\n\tdump: DatabaseDump,\n\t_createMissingTables = true,\n): DumpStatement[] {\n\tconst statements: DumpStatement[] = []\n\tfor (const table of dump.tables) {\n\t\tconst name = quoteIdent(ensureSafeIdentifier(table.name))\n\t\tconst create = createTableIfNotExists(table.name, table.sql)\n\t\tif (create) {\n\t\t\tstatements.push({ sql: create })\n\t\t} else {\n\t\t\tconst columns = table.columns.map((column) => quoteIdent(ensureSafeIdentifier(column)))\n\t\t\tif (columns.length === 0) continue\n\t\t\tstatements.push({ sql: `CREATE TABLE IF NOT EXISTS ${name} (${columns.join(', ')})` })\n\t\t}\n\t\tstatements.push({ sql: `DELETE FROM ${name}` })\n\t\tfor (const row of table.rows) {\n\t\t\tconst columns = table.columns.filter((column) =>\n\t\t\t\tObject.prototype.hasOwnProperty.call(row, column),\n\t\t\t)\n\t\t\tif (columns.length === 0) continue\n\t\t\tconst quotedColumns = columns\n\t\t\t\t.map((column) => quoteIdent(ensureSafeIdentifier(column)))\n\t\t\t\t.join(', ')\n\t\t\tstatements.push({\n\t\t\t\tsql: `INSERT INTO ${name} (${quotedColumns}) VALUES (${columns.map(() => '?').join(', ')})`,\n\t\t\t\tparams: columns.map((column) => row[column]),\n\t\t\t})\n\t\t}\n\t}\n\treturn statements\n}\n\n/**\n * The recorded `CREATE TABLE` statement made idempotent, or null when there is none or\n * it is not a single plain `CREATE TABLE` of exactly this table (dump data is untrusted).\n */\nfunction createTableIfNotExists(tableName: string, sql: string | undefined): string | null {\n\tif (typeof sql !== 'string' || sql.includes(';')) return null\n\tconst match = /^\\s*CREATE\\s+TABLE\\s+(?:IF\\s+NOT\\s+EXISTS\\s+)?(\"?)([A-Za-z0-9_]+)\\1\\s*\\(/i.exec(\n\t\tsql,\n\t)\n\tif (!match || match[2] !== tableName) return null\n\treturn `CREATE TABLE IF NOT EXISTS ${quoteIdent(tableName)} ${sql.slice(match[0].length - 1)}`\n}\n","/// <reference lib=\"dom\" />\nimport { PersistenceError } from '../errors'\n\nconst IDB_DATABASE_NAME = 'kora-persistence'\nconst IDB_STORE_NAME = 'databases'\nconst IDB_VERSION = 1\n\nconst DUMP_SUFFIX = '::dump'\n\n/**\n * Returns true when an IndexedDB error indicates storage quota was exceeded.\n */\nexport function isIndexedDbQuotaError(error: unknown): boolean {\n\tif (error instanceof DOMException && error.name === 'QuotaExceededError') {\n\t\treturn true\n\t}\n\tif (error instanceof PersistenceError && error.context?.quotaExceeded === true) {\n\t\treturn true\n\t}\n\tif (error instanceof Error && /quota/i.test(error.message)) {\n\t\treturn true\n\t}\n\treturn false\n}\n\nfunction rejectWithIdbError(\n\treject: (reason: unknown) => void,\n\tmessage: string,\n\tcontext: Record<string, unknown>,\n\tevent: Event,\n): void {\n\tconst domError = (event.target as IDBRequest | IDBTransaction | undefined)?.error\n\tif (domError && isIndexedDbQuotaError(domError)) {\n\t\treject(\n\t\t\tnew PersistenceError(message, {\n\t\t\t\t...context,\n\t\t\t\tquotaExceeded: true,\n\t\t\t\tcause: domError.message,\n\t\t\t}),\n\t\t)\n\t\treturn\n\t}\n\treject(new PersistenceError(message, context))\n}\n\n/**\n * Open the IndexedDB database used for SQLite persistence.\n * Creates the object store on first access.\n */\nfunction openIdb(): Promise<IDBDatabase> {\n\treturn new Promise<IDBDatabase>((resolve, reject) => {\n\t\tconst request = indexedDB.open(IDB_DATABASE_NAME, IDB_VERSION)\n\t\trequest.onupgradeneeded = () => {\n\t\t\tconst db = request.result\n\t\t\tif (!db.objectStoreNames.contains(IDB_STORE_NAME)) {\n\t\t\t\tdb.createObjectStore(IDB_STORE_NAME)\n\t\t\t}\n\t\t}\n\t\trequest.onsuccess = () => resolve(request.result)\n\t\trequest.onerror = () =>\n\t\t\treject(\n\t\t\t\tnew PersistenceError(\n\t\t\t\t\t`Failed to open IndexedDB: ${request.error?.message ?? 'unknown error'}`,\n\t\t\t\t\t{ database: IDB_DATABASE_NAME },\n\t\t\t\t),\n\t\t\t)\n\t})\n}\n\n/**\n * Save a serialized SQLite database to IndexedDB.\n *\n * @param dbName - Key under which to store the data\n * @param data - Serialized database as Uint8Array\n */\nexport async function saveToIndexedDB(dbName: string, data: Uint8Array): Promise<void> {\n\tconst idb = await openIdb()\n\ttry {\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\tconst tx = idb.transaction(IDB_STORE_NAME, 'readwrite')\n\t\t\tconst store = tx.objectStore(IDB_STORE_NAME)\n\t\t\tstore.put(data, dbName)\n\t\t\ttx.oncomplete = () => resolve()\n\t\t\ttx.onerror = (event) =>\n\t\t\t\trejectWithIdbError(\n\t\t\t\t\treject,\n\t\t\t\t\t`Failed to save database \"${dbName}\" to IndexedDB`,\n\t\t\t\t\t{ dbName },\n\t\t\t\t\tevent,\n\t\t\t\t)\n\t\t})\n\t} finally {\n\t\tidb.close()\n\t}\n}\n\n/**\n * Save a logical SQL dump payload to IndexedDB for import-fallback restore.\n */\nexport async function saveDumpToIndexedDB(dbName: string, dump: unknown): Promise<void> {\n\tconst idb = await openIdb()\n\ttry {\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\tconst tx = idb.transaction(IDB_STORE_NAME, 'readwrite')\n\t\t\tconst store = tx.objectStore(IDB_STORE_NAME)\n\t\t\tstore.put(dump, `${dbName}${DUMP_SUFFIX}`)\n\t\t\ttx.oncomplete = () => resolve()\n\t\t\ttx.onerror = (event) =>\n\t\t\t\trejectWithIdbError(\n\t\t\t\t\treject,\n\t\t\t\t\t`Failed to save dump for database \"${dbName}\"`,\n\t\t\t\t\t{ dbName },\n\t\t\t\t\tevent,\n\t\t\t\t)\n\t\t})\n\t} finally {\n\t\tidb.close()\n\t}\n}\n\n/**\n * Load a serialized SQLite database from IndexedDB.\n *\n * @param dbName - Key under which the data was stored\n * @returns The serialized database, or null if not found\n */\nexport async function loadFromIndexedDB(dbName: string): Promise<Uint8Array | null> {\n\tconst idb = await openIdb()\n\ttry {\n\t\treturn await new Promise<Uint8Array | null>((resolve, reject) => {\n\t\t\tconst tx = idb.transaction(IDB_STORE_NAME, 'readonly')\n\t\t\tconst store = tx.objectStore(IDB_STORE_NAME)\n\t\t\tconst request = store.get(dbName)\n\t\t\trequest.onsuccess = () => {\n\t\t\t\tconst result = request.result\n\t\t\t\tif (result instanceof Uint8Array) {\n\t\t\t\t\tresolve(result)\n\t\t\t\t} else if (result) {\n\t\t\t\t\t// Handle ArrayBuffer or other typed array forms\n\t\t\t\t\tresolve(new Uint8Array(result as ArrayBuffer))\n\t\t\t\t} else {\n\t\t\t\t\tresolve(null)\n\t\t\t\t}\n\t\t\t}\n\t\t\trequest.onerror = () =>\n\t\t\t\treject(\n\t\t\t\t\tnew PersistenceError(`Failed to load database \"${dbName}\" from IndexedDB`, { dbName }),\n\t\t\t\t)\n\t\t})\n\t} finally {\n\t\tidb.close()\n\t}\n}\n\n/**\n * Load a logical SQL dump payload from IndexedDB.\n */\nexport async function loadDumpFromIndexedDB<T>(dbName: string): Promise<T | null> {\n\tconst idb = await openIdb()\n\ttry {\n\t\treturn await new Promise<T | null>((resolve, reject) => {\n\t\t\tconst tx = idb.transaction(IDB_STORE_NAME, 'readonly')\n\t\t\tconst store = tx.objectStore(IDB_STORE_NAME)\n\t\t\tconst request = store.get(`${dbName}${DUMP_SUFFIX}`)\n\t\t\trequest.onsuccess = () => {\n\t\t\t\tresolve((request.result as T | undefined) ?? null)\n\t\t\t}\n\t\t\trequest.onerror = () =>\n\t\t\t\treject(\n\t\t\t\t\tnew PersistenceError(`Failed to load dump for database \"${dbName}\" from IndexedDB`, {\n\t\t\t\t\t\tdbName,\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t})\n\t} finally {\n\t\tidb.close()\n\t}\n}\n\n/**\n * Delete only the binary SQLite database snapshot from IndexedDB.\n *\n * The logical dump is stored under a separate key and may be the authoritative\n * durable fallback when a browser worker cannot export a binary SQLite image.\n */\nexport async function deleteSnapshotFromIndexedDB(dbName: string): Promise<void> {\n\tconst idb = await openIdb()\n\ttry {\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\tconst tx = idb.transaction(IDB_STORE_NAME, 'readwrite')\n\t\t\tconst store = tx.objectStore(IDB_STORE_NAME)\n\t\t\tstore.delete(dbName)\n\t\t\ttx.oncomplete = () => resolve()\n\t\t\ttx.onerror = () =>\n\t\t\t\treject(\n\t\t\t\t\tnew PersistenceError(`Failed to delete database snapshot \"${dbName}\" from IndexedDB`, {\n\t\t\t\t\t\tdbName,\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t})\n\t} finally {\n\t\tidb.close()\n\t}\n}\n\n/**\n * Delete a serialized SQLite database from IndexedDB.\n *\n * @param dbName - Key to delete\n */\nexport async function deleteFromIndexedDB(dbName: string): Promise<void> {\n\tconst idb = await openIdb()\n\ttry {\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\tconst tx = idb.transaction(IDB_STORE_NAME, 'readwrite')\n\t\t\tconst store = tx.objectStore(IDB_STORE_NAME)\n\t\t\tstore.delete(dbName)\n\t\t\tstore.delete(`${dbName}${DUMP_SUFFIX}`)\n\t\t\ttx.oncomplete = () => resolve()\n\t\t\ttx.onerror = () =>\n\t\t\t\treject(\n\t\t\t\t\tnew PersistenceError(`Failed to delete database \"${dbName}\" from IndexedDB`, { dbName }),\n\t\t\t\t)\n\t\t})\n\t} finally {\n\t\tidb.close()\n\t}\n}\n","/// <reference lib=\"dom\" />\n/**\n * Kora-owned manifest of the local databases this origin created (W8a).\n *\n * One record per database name, kept in its own IndexedDB database so it is\n * readable from any tab without opening the OPFS pools. It records which backend\n * holds the database's data, which is how Kora keeps OPFS and IndexedDB from\n * ever holding two disjoint copies: a backend switch is a recorded, explicit\n * migration, never a silent fresh start (NEW-STORE-5, LMS-5c).\n *\n * The manifest is advisory for listing and authoritative for the backend\n * choice. Nothing is ever evicted automatically; deletion is the explicit\n * `deleteDatabase()` API.\n */\n\nconst MANIFEST_DB_NAME = 'kora-manifest'\nconst MANIFEST_STORE = 'databases'\nconst MANIFEST_VERSION = 1\n\n/** Where a database's data lives. */\nexport type LocalDatabaseBackend = 'opfs' | 'indexeddb'\n\n/** One manifest entry, as returned by `listDatabases()`. */\nexport interface LocalDatabaseRecord {\n\t/** The store name (`store.name`, plus the per-user suffix if namespaced). */\n\tdbName: string\n\t/** The backend that holds the authoritative copy. */\n\tbackend: LocalDatabaseBackend\n\t/** OPFS pool holding the file (opfs backend only). */\n\tpoolName?: string\n\t/** Wall-clock milliseconds; informational only, never used for ordering. */\n\tcreatedAt: number\n\t/** Wall-clock milliseconds of the last durable open; informational only. */\n\tlastOpenedAt: number\n}\n\n/** True when this runtime can keep a manifest (browsers; not Node tests). */\nexport function isManifestAvailable(): boolean {\n\treturn typeof indexedDB !== 'undefined'\n}\n\nfunction openManifest(): Promise<IDBDatabase> {\n\treturn new Promise<IDBDatabase>((resolve, reject) => {\n\t\tconst request = indexedDB.open(MANIFEST_DB_NAME, MANIFEST_VERSION)\n\t\trequest.onupgradeneeded = () => {\n\t\t\tconst db = request.result\n\t\t\tif (!db.objectStoreNames.contains(MANIFEST_STORE)) {\n\t\t\t\tdb.createObjectStore(MANIFEST_STORE, { keyPath: 'dbName' })\n\t\t\t}\n\t\t}\n\t\trequest.onsuccess = () => resolve(request.result)\n\t\trequest.onerror = () =>\n\t\t\treject(request.error ?? new Error('Failed to open the Kora storage manifest'))\n\t})\n}\n\nasync function withStore<T>(\n\tmode: IDBTransactionMode,\n\trun: (store: IDBObjectStore) => IDBRequest<T> | null,\n): Promise<T | undefined> {\n\tconst db = await openManifest()\n\ttry {\n\t\treturn await new Promise<T | undefined>((resolve, reject) => {\n\t\t\tconst tx = db.transaction(MANIFEST_STORE, mode)\n\t\t\tconst request = run(tx.objectStore(MANIFEST_STORE))\n\t\t\tlet result: T | undefined\n\t\t\tif (request) {\n\t\t\t\trequest.onsuccess = () => {\n\t\t\t\t\tresult = request.result\n\t\t\t\t}\n\t\t\t}\n\t\t\ttx.oncomplete = () => resolve(result)\n\t\t\ttx.onerror = () => reject(tx.error ?? new Error('Kora storage manifest transaction failed'))\n\t\t\ttx.onabort = () => reject(tx.error ?? new Error('Kora storage manifest transaction aborted'))\n\t\t})\n\t} finally {\n\t\tdb.close()\n\t}\n}\n\nfunction isRecord(value: unknown): value is LocalDatabaseRecord {\n\tif (typeof value !== 'object' || value === null) return false\n\tconst record = value as Partial<LocalDatabaseRecord>\n\treturn (\n\t\ttypeof record.dbName === 'string' &&\n\t\t(record.backend === 'opfs' || record.backend === 'indexeddb')\n\t)\n}\n\n/** Read the manifest entry for a database, or null when Kora never recorded it. */\nexport async function readManifestRecord(dbName: string): Promise<LocalDatabaseRecord | null> {\n\tif (!isManifestAvailable()) return null\n\tconst value = await withStore<unknown>('readonly', (store) => store.get(dbName))\n\treturn isRecord(value) ? value : null\n}\n\n/** Every database Kora recorded on this origin, sorted by name. */\nexport async function listManifestRecords(): Promise<LocalDatabaseRecord[]> {\n\tif (!isManifestAvailable()) return []\n\tconst values = await withStore<unknown[]>('readonly', (store) => store.getAll())\n\treturn (values ?? []).filter(isRecord).sort((a, b) => (a.dbName < b.dbName ? -1 : 1))\n}\n\n/**\n * Record (or refresh) which backend holds a database after a durable open,\n * keeping the original creation time.\n */\nexport async function recordDatabase(entry: {\n\tdbName: string\n\tbackend: LocalDatabaseBackend\n\tpoolName?: string\n}): Promise<void> {\n\tif (!isManifestAvailable()) return\n\tconst existing = await readManifestRecord(entry.dbName)\n\tconst now = Date.now()\n\tconst record: LocalDatabaseRecord = {\n\t\tdbName: entry.dbName,\n\t\tbackend: entry.backend,\n\t\t...(entry.poolName ? { poolName: entry.poolName } : {}),\n\t\tcreatedAt: existing?.createdAt ?? now,\n\t\tlastOpenedAt: now,\n\t}\n\tawait withStore('readwrite', (store) => store.put(record))\n}\n\n/** Remove a database's manifest entry (after its data was deleted). */\nexport async function deleteManifestRecord(dbName: string): Promise<void> {\n\tif (!isManifestAvailable()) return\n\tawait withStore('readwrite', (store) => store.delete(dbName))\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA,SAAS,uBAAuB;;;ACAhC,SAAS,kBAAkB;AA+BpB,SAAS,qBAAqB,YAA4B;AAChE,MAAI,CAAC,kBAAkB,KAAK,UAAU,GAAG;AACxC,UAAM,IAAI,iBAAiB,0BAA0B,UAAU,IAAI;AAAA,MAClE,MAAM;AAAA,MACN;AAAA,IACD,CAAC;AAAA,EACF;AACA,SAAO;AACR;AAMA,eAAsB,WAAW,OAAuC;AACvE,QAAM,YAAY,MAAM;AAAA,IACvB;AAAA,EACD;AACA,QAAM,SAAiC,CAAC;AACxC,aAAW,YAAY,WAAW;AACjC,UAAM,YAAY,qBAAqB,SAAS,IAAI;AACpD,UAAM,UAAU,MAAM,MAAwB,qBAAqB,WAAW,SAAS,CAAC,GAAG;AAC3F,UAAM,OAAO,MAAM,MAA+B,iBAAiB,WAAW,SAAS,CAAC,EAAE;AAC1F,WAAO,KAAK;AAAA,MACX,MAAM;AAAA,MACN,GAAI,OAAO,SAAS,QAAQ,WAAW,EAAE,KAAK,SAAS,IAAI,IAAI,CAAC;AAAA,MAChE,SAAS,QAAQ,IAAI,CAAC,WAAW,OAAO,IAAI;AAAA,MAC5C;AAAA,IACD,CAAC;AAAA,EACF;AACA,SAAO,EAAE,OAAO;AACjB;AAcO,SAAS,sBACf,MACA,uBAAuB,MACL;AAClB,QAAM,aAA8B,CAAC;AACrC,aAAW,SAAS,KAAK,Q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