@tearleads/client-sdk 0.1.262 → 0.1.263
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.
- package/README.md +1 -1
- package/internal/sqlite-worker/crossTabConnectionMachine.js +67 -0
- package/internal/sqlite-worker/crossTabConnectionMachine.js.map +1 -0
- package/internal/sqlite-worker/crossTabLocalClient.js +76 -14
- package/internal/sqlite-worker/crossTabLocalClient.js.map +1 -1
- package/internal/sqlite-worker/crossTabProtocol.js +17 -0
- package/internal/sqlite-worker/crossTabProtocol.js.map +1 -1
- package/internal/sqlite-worker/crossTabRuntime.js +20 -18
- package/internal/sqlite-worker/crossTabRuntime.js.map +1 -1
- package/internal/sqlite-worker/runtime.d.ts +1 -1
- package/internal/sqlite-worker/runtime.js +1 -0
- package/internal/sqlite-worker/runtime.js.map +1 -1
- package/internal/sqlite-worker/types.d.ts +7 -0
- package/internal/sqlite-worker/types.js +12 -0
- package/internal/sqlite-worker/types.js.map +1 -1
- package/internal/sqlite-worker/workerCrash.d.ts +23 -0
- package/internal/sqlite-worker/workerCrash.js +17 -0
- package/internal/sqlite-worker/workerCrash.js.map +1 -1
- package/package.json +1 -1
- package/sqlite/index.d.ts +1 -1
- package/sqlite/index.js +1 -1
- package/sqlite/index.js.map +1 -1
- package/sqlite/worker.js +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EACL,0BAA0B,GAG3B,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EACL,kCAAkC,EAClC,gBAAgB,EAChB,2BAA2B,EAG3B,qBAAqB,GACtB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAE1D,MAA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AAC,uBAAuB,KAAK,SAAS;QAC7C,OAAO,MAAM,KAAK,WAAW,EAC7B,CAAC;QACD,MAAM,cAAc,GAAG,4BAA4B,CACjD,OAAO,CAAC,SAAS,IAAI,2BAA2B,EAChD,UAAU,CAAC,MAAM,CAClB,CAAC;QACF,IAAI,cAAc,EAAE,CAAC;YACnB,OAAO,2BAA2B,CAAC,cAAc,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;IAED,MAAM,gBAAgB,GAAG,8BAA8B,CAAC,OAAO,CAAC,CAAC;IACjE,IAAI,gBAAgB,EAAE,CAAC;QACrB,OAAO,2BAA2B,CAAC,gBAAgB,CAAC,CAAC;IACvD,CAAC;IAED,IACE,OAAO,OAAO,CAAC,iBAAiB,KAAK,WAAW;QAChD,OAAO,MAAM,KAAK,WAAW,EAC7B,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAED,OAAO,qBAAqB,CAC1B,kBAAkB,CAChB,OAAO,CAAC,SAAS,IAAI,2BAA2B,EAChD,OAAO,CAAC,iBAAiB,CAC1B,EACD,kCAAkC,CAAC,OAAO,CAAC,yBAAyB,CAAC,CACtE,CAAC;AACJ,CAAC","sourcesContent":["import { evictCachedDatabasePages } from \"./cachedPageEviction\";\nimport {\n createDatabaseWorkerClient,\n type DatabaseWorkerClient,\n type WorkerLike,\n} from \"./client\";\nimport { createCrossTabDatabaseWorker } from \"./crossTabRuntime\";\nimport {\n availableMessageChannelConstructor,\n closeMessagePort,\n createRenewedDatabaseClient,\n type DatabaseRuntimeMessageChannelConstructor,\n type DatabaseRuntimeMessagePort,\n disconnectMessagePort,\n} from \"./renewedClientTransport\";\nimport { workerCrashErrorFromEvent } from \"./workerCrash\";\n\nconst DEFAULT_DATABASE_WORKER_URL = \"/worker.js\";\nconst DEFAULT_SHARED_DATABASE_WORKER_NAME = \"tearleads-sqlite-worker\";\n\ninterface TerminableWorkerLike extends WorkerLike {\n terminate(): void;\n}\n\ninterface CloseableWorkerLike extends WorkerLike {\n close(): void;\n /**\n * Cross-tab worker only: force-stop a possibly-wedged owner (its worker went\n * silent and never answered the graceful `close`) so the next boot builds a\n * fresh owner. Absent on a real SharedWorker port, where the browser reclaims\n * the port/owner itself; called optionally.\n */\n forceStopOwner?(): void;\n}\n\nexport interface ModuleWorkerLike extends TerminableWorkerLike {}\n\nexport interface ModuleWorkerConstructor {\n new (scriptURL: string | URL, options?: WorkerOptions): ModuleWorkerLike;\n}\n\nexport interface ModuleSharedWorkerLike {\n readonly port: CloseableWorkerLike & { start?: () => void };\n addEventListener?: WorkerLike[\"addEventListener\"];\n removeEventListener?: WorkerLike[\"removeEventListener\"];\n}\n\nexport interface ModuleSharedWorkerConstructor {\n new (\n scriptURL: string | URL,\n options?: {\n name?: string;\n type?: \"classic\" | \"module\";\n },\n ): ModuleSharedWorkerLike;\n}\n\nexport interface DatabaseRuntime {\n id: string;\n client: DatabaseWorkerClient;\n destroy(): void;\n /**\n * Permanently destroy the persisted database: ask the worker to wipe its OPFS\n * files (not merely release the handles, as {@link destroy} does), then\n * terminate the worker. Resolves once teardown completes. Used to forget local\n * data on logout. Best-effort: a wipe failure still terminates the worker.\n */\n deleteData(): Promise<void>;\n /**\n * Synchronous, abrupt teardown for page-unload handlers (`pagehide`), where\n * there is no time for destroy()'s async graceful close. Terminating the worker\n * thread releases its OPFS access handles promptly, so the next page's worker\n * can acquire them instead of racing a leaked handle from the discarded page.\n */\n terminateNow(): void;\n /**\n * Replace this runtime's main-thread client (and its `id`) with a fresh one on\n * the SAME worker, without tearing the worker down. Used when the worker is\n * reused for a different database (see the app's `reuseDatabaseWorker` path):\n * the SDK keys per-connection caches — schema/projection ensures, mutation\n * queues, persistence runtimes — off the client object, so a new database MUST\n * see a fresh client or it inherits the previous database's \"schema already\n * ensured\" state and then queries/writes missing tables. Only the dedicated\n * runtime implements this; the cross-tab runtime omits it (it is never reused).\n */\n renewClient?(): void;\n /**\n * Observe the worker crashing (an `error` event: a failed script load or an\n * uncaught exception outside request handling). The client has already\n * rejected every in-flight request with the same failure; this is the host's\n * signal to report it and retire the runtime, because errors thrown inside a\n * Worker never reach the page's own error handlers. Returns an unsubscribe.\n * Runtimes hosts construct themselves may omit it.\n */\n subscribeWorkerError?(listener: (error: Error) => void): () => void;\n}\n\nfunction subscribeWorkerError(\n worker: WorkerLike,\n): NonNullable<DatabaseRuntime[\"subscribeWorkerError\"]> {\n return (listener) => {\n const handleError = (event: Event) => {\n listener(workerCrashErrorFromEvent(event));\n };\n worker.addEventListener(\"error\", handleError);\n return () => {\n worker.removeEventListener(\"error\", handleError);\n };\n };\n}\n\nexport interface CreateModuleDatabaseRuntimeOptions {\n /**\n * Dedicated Worker fallback. Supplying this keeps the historical dedicated\n * worker path, which is useful for tests and non-browser hosts.\n */\n workerConstructor?: ModuleWorkerConstructor;\n /**\n * SharedWorker constructor for browser hosts that can share one SQLite owner\n * across tabs. Pass `null` to force the dedicated Worker fallback.\n */\n sharedWorkerConstructor?: ModuleSharedWorkerConstructor | null;\n sharedWorkerName?: string;\n /**\n * Overrides the channel used to give a renewed client fresh worker-side\n * connection state. Pass `null` in hosts without transferable message ports;\n * the returned runtime then omits its optional renewal capability.\n */\n messageChannelConstructor?: DatabaseRuntimeMessageChannelConstructor | null;\n workerUrl?: string | URL;\n}\n\nfunction createModuleWorker(\n workerUrl: string | URL,\n workerConstructor: ModuleWorkerConstructor = globalThis.Worker,\n): ModuleWorkerLike {\n return new workerConstructor(workerUrl, { type: \"module\" });\n}\n\nfunction portFromModuleSharedWorker(\n sharedWorker: ModuleSharedWorkerLike,\n): CloseableWorkerLike {\n sharedWorker.port.start?.();\n\n return {\n postMessage(message) {\n sharedWorker.port.postMessage(message);\n },\n addEventListener(type, listener) {\n if (type === \"error\" && sharedWorker.addEventListener) {\n sharedWorker.addEventListener(type, listener);\n return;\n }\n\n sharedWorker.port.addEventListener(type, listener);\n },\n removeEventListener(type, listener) {\n if (type === \"error\" && sharedWorker.removeEventListener) {\n sharedWorker.removeEventListener(type, listener);\n return;\n }\n\n sharedWorker.port.removeEventListener(type, listener);\n },\n close() {\n sharedWorker.port.close();\n },\n };\n}\n\nfunction createModuleSharedWorkerPort(\n workerUrl: string | URL,\n sharedWorkerConstructor: ModuleSharedWorkerConstructor,\n sharedWorkerName: string,\n): CloseableWorkerLike {\n return portFromModuleSharedWorker(\n new sharedWorkerConstructor(workerUrl, {\n name: sharedWorkerName,\n type: \"module\",\n }),\n );\n}\n\nfunction createExplicitSharedWorkerPort(\n options: CreateModuleDatabaseRuntimeOptions,\n): CloseableWorkerLike | null {\n if (options.workerConstructor || !options.sharedWorkerConstructor) {\n return null;\n }\n\n return createModuleSharedWorkerPort(\n options.workerUrl ?? DEFAULT_DATABASE_WORKER_URL,\n options.sharedWorkerConstructor,\n options.sharedWorkerName ?? DEFAULT_SHARED_DATABASE_WORKER_NAME,\n );\n}\n\n// Upper bound on how long destroy() waits for the worker's graceful close\n// (db close + SAHPool handle release) before terminating anyway. Releasing the\n// OPFS handles is near-instant; this only guards against a wedged worker so\n// teardown can never hang. If it elapses we terminate regardless — the browser\n// then releases the handles asynchronously and the next boot's contention retry\n// covers the gap.\nconst GRACEFUL_CLOSE_TIMEOUT_MS = 1_000;\n\nexport function createDatabaseRuntime(\n worker: TerminableWorkerLike,\n messageChannelConstructor = availableMessageChannelConstructor(),\n): DatabaseRuntime {\n // Client/id stay mutable for same-worker renewal; one request-id sequence spans\n // generations so a late old response cannot match a replacement request.\n const requestIdSequence = { current: 1 };\n let client = createDatabaseWorkerClient(worker, requestIdSequence);\n let activeClientPort: DatabaseRuntimeMessagePort | null = null;\n let id: string = crypto.randomUUID();\n let torndown = false;\n\n // Terminate exactly once, tearing down the client first so its pending-request\n // map is cleared and listeners removed.\n const terminate = () => {\n if (torndown) {\n return;\n }\n torndown = true;\n client.destroy();\n closeMessagePort(activeClientPort);\n activeClientPort = null;\n worker.terminate();\n };\n\n const runtime: DatabaseRuntime = {\n get id() {\n return id;\n },\n get client() {\n return client;\n },\n destroy() {\n if (torndown) {\n return;\n }\n // Ask the worker to release the database and its OPFS access handles\n // *before* we terminate it. terminate() alone releases handles only\n // asynchronously, which is what makes a reloaded page's SAHPool install\n // race and fail; closing first hands the handles off cleanly.\n //\n // destroy() stays synchronous (React effect cleanups can't await), so this\n // is fire-and-forget: terminate once the worker confirms the close, or\n // once the timeout elapses if it never does. `terminate` is idempotent, so\n // the race between the two is harmless.\n const timeoutId = setTimeout(terminate, GRACEFUL_CLOSE_TIMEOUT_MS);\n client.close().then(\n () => {\n clearTimeout(timeoutId);\n terminate();\n },\n () => {\n // The worker may already be gone or never responded; terminate anyway.\n clearTimeout(timeoutId);\n terminate();\n },\n );\n },\n async deleteData() {\n if (torndown) {\n return;\n }\n // Ask the worker to wipe its OPFS files before terminating. Unlike\n // destroy()'s fire-and-forget close, callers await this so they know the\n // data is gone before re-provisioning a fresh database. The wipe is\n // best-effort inside the worker; terminate regardless once it settles or\n // the timeout elapses so teardown can never hang on a wedged worker.\n await new Promise<void>((resolve) => {\n const timeoutId = setTimeout(() => {\n terminate();\n resolve();\n }, GRACEFUL_CLOSE_TIMEOUT_MS);\n const finish = () => {\n clearTimeout(timeoutId);\n terminate();\n resolve();\n };\n client.delete().then(finish, finish);\n });\n },\n terminateNow() {\n terminate();\n },\n subscribeWorkerError: subscribeWorkerError(worker),\n };\n\n if (messageChannelConstructor) {\n runtime.renewClient = () => {\n if (torndown) {\n return;\n }\n\n let renewed: ReturnType<typeof createRenewedDatabaseClient>;\n try {\n renewed = createRenewedDatabaseClient({\n messageChannelConstructor,\n requestIdSequence,\n worker,\n });\n } catch (error) {\n // MessageChannel existence does not guarantee this Worker accepts a\n // transferred port. Retire the capability so the app's next retry uses\n // its safe teardown/new-runtime fallback instead of looping this failure.\n delete runtime.renewClient;\n throw error;\n }\n\n const previousClient = client;\n const previousPort = activeClientPort;\n client = renewed.client;\n activeClientPort = renewed.port;\n id = renewed.id;\n\n // Only retire the previous generation after the worker accepted the new\n // port. A failed transfer therefore leaves the old client fully usable.\n previousClient.destroy();\n disconnectMessagePort(previousPort);\n };\n }\n\n return runtime;\n}\n\nfunction postCloseWithoutWaiting(worker: WorkerLike): void {\n try {\n worker.postMessage({ id: 0, method: \"close\", params: undefined });\n } catch {\n // The page is unloading or the closeable port is already gone. The browser\n // will release page-owned ports/workers when the document is discarded.\n }\n}\n\nexport function createSharedDatabaseRuntime(\n worker: CloseableWorkerLike,\n): DatabaseRuntime {\n const client = createDatabaseWorkerClient(worker);\n let torndown = false;\n\n const close = () => {\n if (torndown) {\n return;\n }\n\n torndown = true;\n client.destroy();\n worker.close();\n };\n\n // Abrupt teardown: the graceful `close`/`delete` never came back (the worker is\n // wedged) or there was no time to wait for it, so the owner was never stopped\n // via its close-response. Also force-stop a possibly-wedged owner so the next\n // boot re-contends and builds a fresh owner instead of routing into the dead\n // one. Idempotent and no-ops when the owner already stopped itself (healthy\n // close) or this tab is not the owner.\n const forceClose = () => {\n if (torndown) {\n return;\n }\n\n torndown = true;\n client.destroy();\n worker.forceStopOwner?.();\n worker.close();\n };\n\n return {\n id: crypto.randomUUID(),\n client,\n destroy() {\n if (torndown) {\n return;\n }\n\n // The worker acked the graceful close within the budget → it already stopped\n // the owner itself, so a plain close() suffices. If it did NOT ack (timeout\n // or rejection), it may be wedged → force-stop the owner.\n const timeoutId = setTimeout(forceClose, GRACEFUL_CLOSE_TIMEOUT_MS);\n client.close().then(\n () => {\n clearTimeout(timeoutId);\n close();\n },\n () => {\n clearTimeout(timeoutId);\n forceClose();\n },\n );\n },\n async deleteData() {\n if (torndown) {\n return;\n }\n\n await new Promise<void>((resolve) => {\n const timeoutId = setTimeout(() => {\n forceClose();\n resolve();\n }, GRACEFUL_CLOSE_TIMEOUT_MS);\n const finish = () => {\n clearTimeout(timeoutId);\n close();\n resolve();\n };\n const fail = () => {\n clearTimeout(timeoutId);\n forceClose();\n resolve();\n };\n client.delete().then(finish, fail);\n });\n },\n terminateNow() {\n if (torndown) {\n return;\n }\n\n postCloseWithoutWaiting(worker);\n forceClose();\n },\n subscribeWorkerError: subscribeWorkerError(worker),\n };\n}\n\nexport function createModuleDatabaseRuntime(\n options: CreateModuleDatabaseRuntimeOptions = {},\n): DatabaseRuntime {\n evictCachedDatabasePages();\n if (\n !options.workerConstructor &&\n options.sharedWorkerConstructor === undefined &&\n typeof Worker !== \"undefined\"\n ) {\n const crossTabWorker = createCrossTabDatabaseWorker(\n options.workerUrl ?? DEFAULT_DATABASE_WORKER_URL,\n globalThis.Worker,\n );\n if (crossTabWorker) {\n return createSharedDatabaseRuntime(crossTabWorker);\n }\n }\n\n const sharedWorkerPort = createExplicitSharedWorkerPort(options);\n if (sharedWorkerPort) {\n return createSharedDatabaseRuntime(sharedWorkerPort);\n }\n\n if (\n typeof options.workerConstructor === \"undefined\" &&\n typeof Worker === \"undefined\"\n ) {\n throw new Error(\"Worker must be defined.\");\n }\n\n return createDatabaseRuntime(\n createModuleWorker(\n options.workerUrl ?? DEFAULT_DATABASE_WORKER_URL,\n options.workerConstructor,\n ),\n availableMessageChannelConstructor(options.messageChannelConstructor),\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EACL,0BAA0B,GAG3B,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EACL,kCAAkC,EAClC,gBAAgB,EAChB,2BAA2B,EAG3B,qBAAqB,GACtB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAE1D,OAAO,EACL,2BAA2B,EAC3B,6BAA6B,GAC9B,MAAM,eAAe,CAAC;AAEvB,MAAM,2BAA2B,GAAG,YAAY,CAAC;AACjD,MAAM,mCAAmC,GAAG,yBAAyB,CAAC;AA+EtE,SAAS,oBAAo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G,4BAA4B,CACjD,OAAO,CAAC,SAAS,IAAI,2BAA2B,EAChD,UAAU,CAAC,MAAM,CAClB,CAAC;QACF,IAAI,cAAc,EAAE,CAAC;YACnB,OAAO,2BAA2B,CAAC,cAAc,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;IAED,MAAM,gBAAgB,GAAG,8BAA8B,CAAC,OAAO,CAAC,CAAC;IACjE,IAAI,gBAAgB,EAAE,CAAC;QACrB,OAAO,2BAA2B,CAAC,gBAAgB,CAAC,CAAC;IACvD,CAAC;IAED,IACE,OAAO,OAAO,CAAC,iBAAiB,KAAK,WAAW;QAChD,OAAO,MAAM,KAAK,WAAW,EAC7B,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAED,OAAO,qBAAqB,CAC1B,kBAAkB,CAChB,OAAO,CAAC,SAAS,IAAI,2BAA2B,EAChD,OAAO,CAAC,iBAAiB,CAC1B,EACD,kCAAkC,CAAC,OAAO,CAAC,yBAAyB,CAAC,CACtE,CAAC;AACJ,CAAC","sourcesContent":["import { evictCachedDatabasePages } from \"./cachedPageEviction\";\nimport {\n createDatabaseWorkerClient,\n type DatabaseWorkerClient,\n type WorkerLike,\n} from \"./client\";\nimport { createCrossTabDatabaseWorker } from \"./crossTabRuntime\";\nimport {\n availableMessageChannelConstructor,\n closeMessagePort,\n createRenewedDatabaseClient,\n type DatabaseRuntimeMessageChannelConstructor,\n type DatabaseRuntimeMessagePort,\n disconnectMessagePort,\n} from \"./renewedClientTransport\";\nimport { workerCrashErrorFromEvent } from \"./workerCrash\";\n\nexport {\n DatabaseConnectionLostError,\n isDatabaseConnectionLostError,\n} from \"./workerCrash\";\n\nconst DEFAULT_DATABASE_WORKER_URL = \"/worker.js\";\nconst DEFAULT_SHARED_DATABASE_WORKER_NAME = \"tearleads-sqlite-worker\";\n\ninterface TerminableWorkerLike extends WorkerLike {\n terminate(): void;\n}\n\ninterface CloseableWorkerLike extends WorkerLike {\n close(): void;\n /**\n * Cross-tab worker only: force-stop a possibly-wedged owner (its worker went\n * silent and never answered the graceful `close`) so the next boot builds a\n * fresh owner. Absent on a real SharedWorker port, where the browser reclaims\n * the port/owner itself; called optionally.\n */\n forceStopOwner?(): void;\n}\n\nexport interface ModuleWorkerLike extends TerminableWorkerLike {}\n\nexport interface ModuleWorkerConstructor {\n new (scriptURL: string | URL, options?: WorkerOptions): ModuleWorkerLike;\n}\n\nexport interface ModuleSharedWorkerLike {\n readonly port: CloseableWorkerLike & { start?: () => void };\n addEventListener?: WorkerLike[\"addEventListener\"];\n removeEventListener?: WorkerLike[\"removeEventListener\"];\n}\n\nexport interface ModuleSharedWorkerConstructor {\n new (\n scriptURL: string | URL,\n options?: {\n name?: string;\n type?: \"classic\" | \"module\";\n },\n ): ModuleSharedWorkerLike;\n}\n\nexport interface DatabaseRuntime {\n id: string;\n client: DatabaseWorkerClient;\n destroy(): void;\n /**\n * Permanently destroy the persisted database: ask the worker to wipe its OPFS\n * files (not merely release the handles, as {@link destroy} does), then\n * terminate the worker. Resolves once teardown completes. Used to forget local\n * data on logout. Best-effort: a wipe failure still terminates the worker.\n */\n deleteData(): Promise<void>;\n /**\n * Synchronous, abrupt teardown for page-unload handlers (`pagehide`), where\n * there is no time for destroy()'s async graceful close. Terminating the worker\n * thread releases its OPFS access handles promptly, so the next page's worker\n * can acquire them instead of racing a leaked handle from the discarded page.\n */\n terminateNow(): void;\n /**\n * Replace this runtime's main-thread client (and its `id`) with a fresh one on\n * the SAME worker, without tearing the worker down. Used when the worker is\n * reused for a different database (see the app's `reuseDatabaseWorker` path):\n * the SDK keys per-connection caches — schema/projection ensures, mutation\n * queues, persistence runtimes — off the client object, so a new database MUST\n * see a fresh client or it inherits the previous database's \"schema already\n * ensured\" state and then queries/writes missing tables. Only the dedicated\n * runtime implements this; the cross-tab runtime omits it (it is never reused).\n */\n renewClient?(): void;\n /**\n * Observe the worker crashing (an `error` event: a failed script load or an\n * uncaught exception outside request handling). The client has already\n * rejected every in-flight request with the same failure; this is the host's\n * signal to report it and retire the runtime, because errors thrown inside a\n * Worker never reach the page's own error handlers. Returns an unsubscribe.\n * Runtimes hosts construct themselves may omit it.\n */\n subscribeWorkerError?(listener: (error: Error) => void): () => void;\n}\n\nfunction subscribeWorkerError(\n worker: WorkerLike,\n): NonNullable<DatabaseRuntime[\"subscribeWorkerError\"]> {\n return (listener) => {\n const handleError = (event: Event) => {\n listener(workerCrashErrorFromEvent(event));\n };\n worker.addEventListener(\"error\", handleError);\n return () => {\n worker.removeEventListener(\"error\", handleError);\n };\n };\n}\n\nexport interface CreateModuleDatabaseRuntimeOptions {\n /**\n * Dedicated Worker fallback. Supplying this keeps the historical dedicated\n * worker path, which is useful for tests and non-browser hosts.\n */\n workerConstructor?: ModuleWorkerConstructor;\n /**\n * SharedWorker constructor for browser hosts that can share one SQLite owner\n * across tabs. Pass `null` to force the dedicated Worker fallback.\n */\n sharedWorkerConstructor?: ModuleSharedWorkerConstructor | null;\n sharedWorkerName?: string;\n /**\n * Overrides the channel used to give a renewed client fresh worker-side\n * connection state. Pass `null` in hosts without transferable message ports;\n * the returned runtime then omits its optional renewal capability.\n */\n messageChannelConstructor?: DatabaseRuntimeMessageChannelConstructor | null;\n workerUrl?: string | URL;\n}\n\nfunction createModuleWorker(\n workerUrl: string | URL,\n workerConstructor: ModuleWorkerConstructor = globalThis.Worker,\n): ModuleWorkerLike {\n return new workerConstructor(workerUrl, { type: \"module\" });\n}\n\nfunction portFromModuleSharedWorker(\n sharedWorker: ModuleSharedWorkerLike,\n): CloseableWorkerLike {\n sharedWorker.port.start?.();\n\n return {\n postMessage(message) {\n sharedWorker.port.postMessage(message);\n },\n addEventListener(type, listener) {\n if (type === \"error\" && sharedWorker.addEventListener) {\n sharedWorker.addEventListener(type, listener);\n return;\n }\n\n sharedWorker.port.addEventListener(type, listener);\n },\n removeEventListener(type, listener) {\n if (type === \"error\" && sharedWorker.removeEventListener) {\n sharedWorker.removeEventListener(type, listener);\n return;\n }\n\n sharedWorker.port.removeEventListener(type, listener);\n },\n close() {\n sharedWorker.port.close();\n },\n };\n}\n\nfunction createModuleSharedWorkerPort(\n workerUrl: string | URL,\n sharedWorkerConstructor: ModuleSharedWorkerConstructor,\n sharedWorkerName: string,\n): CloseableWorkerLike {\n return portFromModuleSharedWorker(\n new sharedWorkerConstructor(workerUrl, {\n name: sharedWorkerName,\n type: \"module\",\n }),\n );\n}\n\nfunction createExplicitSharedWorkerPort(\n options: CreateModuleDatabaseRuntimeOptions,\n): CloseableWorkerLike | null {\n if (options.workerConstructor || !options.sharedWorkerConstructor) {\n return null;\n }\n\n return createModuleSharedWorkerPort(\n options.workerUrl ?? DEFAULT_DATABASE_WORKER_URL,\n options.sharedWorkerConstructor,\n options.sharedWorkerName ?? DEFAULT_SHARED_DATABASE_WORKER_NAME,\n );\n}\n\n// Upper bound on how long destroy() waits for the worker's graceful close\n// (db close + SAHPool handle release) before terminating anyway. Releasing the\n// OPFS handles is near-instant; this only guards against a wedged worker so\n// teardown can never hang. If it elapses we terminate regardless — the browser\n// then releases the handles asynchronously and the next boot's contention retry\n// covers the gap.\nconst GRACEFUL_CLOSE_TIMEOUT_MS = 1_000;\n\nexport function createDatabaseRuntime(\n worker: TerminableWorkerLike,\n messageChannelConstructor = availableMessageChannelConstructor(),\n): DatabaseRuntime {\n // Client/id stay mutable for same-worker renewal; one request-id sequence spans\n // generations so a late old response cannot match a replacement request.\n const requestIdSequence = { current: 1 };\n let client = createDatabaseWorkerClient(worker, requestIdSequence);\n let activeClientPort: DatabaseRuntimeMessagePort | null = null;\n let id: string = crypto.randomUUID();\n let torndown = false;\n\n // Terminate exactly once, tearing down the client first so its pending-request\n // map is cleared and listeners removed.\n const terminate = () => {\n if (torndown) {\n return;\n }\n torndown = true;\n client.destroy();\n closeMessagePort(activeClientPort);\n activeClientPort = null;\n worker.terminate();\n };\n\n const runtime: DatabaseRuntime = {\n get id() {\n return id;\n },\n get client() {\n return client;\n },\n destroy() {\n if (torndown) {\n return;\n }\n // Ask the worker to release the database and its OPFS access handles\n // *before* we terminate it. terminate() alone releases handles only\n // asynchronously, which is what makes a reloaded page's SAHPool install\n // race and fail; closing first hands the handles off cleanly.\n //\n // destroy() stays synchronous (React effect cleanups can't await), so this\n // is fire-and-forget: terminate once the worker confirms the close, or\n // once the timeout elapses if it never does. `terminate` is idempotent, so\n // the race between the two is harmless.\n const timeoutId = setTimeout(terminate, GRACEFUL_CLOSE_TIMEOUT_MS);\n client.close().then(\n () => {\n clearTimeout(timeoutId);\n terminate();\n },\n () => {\n // The worker may already be gone or never responded; terminate anyway.\n clearTimeout(timeoutId);\n terminate();\n },\n );\n },\n async deleteData() {\n if (torndown) {\n return;\n }\n // Ask the worker to wipe its OPFS files before terminating. Unlike\n // destroy()'s fire-and-forget close, callers await this so they know the\n // data is gone before re-provisioning a fresh database. The wipe is\n // best-effort inside the worker; terminate regardless once it settles or\n // the timeout elapses so teardown can never hang on a wedged worker.\n await new Promise<void>((resolve) => {\n const timeoutId = setTimeout(() => {\n terminate();\n resolve();\n }, GRACEFUL_CLOSE_TIMEOUT_MS);\n const finish = () => {\n clearTimeout(timeoutId);\n terminate();\n resolve();\n };\n client.delete().then(finish, finish);\n });\n },\n terminateNow() {\n terminate();\n },\n subscribeWorkerError: subscribeWorkerError(worker),\n };\n\n if (messageChannelConstructor) {\n runtime.renewClient = () => {\n if (torndown) {\n return;\n }\n\n let renewed: ReturnType<typeof createRenewedDatabaseClient>;\n try {\n renewed = createRenewedDatabaseClient({\n messageChannelConstructor,\n requestIdSequence,\n worker,\n });\n } catch (error) {\n // MessageChannel existence does not guarantee this Worker accepts a\n // transferred port. Retire the capability so the app's next retry uses\n // its safe teardown/new-runtime fallback instead of looping this failure.\n delete runtime.renewClient;\n throw error;\n }\n\n const previousClient = client;\n const previousPort = activeClientPort;\n client = renewed.client;\n activeClientPort = renewed.port;\n id = renewed.id;\n\n // Only retire the previous generation after the worker accepted the new\n // port. A failed transfer therefore leaves the old client fully usable.\n previousClient.destroy();\n disconnectMessagePort(previousPort);\n };\n }\n\n return runtime;\n}\n\nfunction postCloseWithoutWaiting(worker: WorkerLike): void {\n try {\n worker.postMessage({ id: 0, method: \"close\", params: undefined });\n } catch {\n // The page is unloading or the closeable port is already gone. The browser\n // will release page-owned ports/workers when the document is discarded.\n }\n}\n\nexport function createSharedDatabaseRuntime(\n worker: CloseableWorkerLike,\n): DatabaseRuntime {\n const client = createDatabaseWorkerClient(worker);\n let torndown = false;\n\n const close = () => {\n if (torndown) {\n return;\n }\n\n torndown = true;\n client.destroy();\n worker.close();\n };\n\n // Abrupt teardown: the graceful `close`/`delete` never came back (the worker is\n // wedged) or there was no time to wait for it, so the owner was never stopped\n // via its close-response. Also force-stop a possibly-wedged owner so the next\n // boot re-contends and builds a fresh owner instead of routing into the dead\n // one. Idempotent and no-ops when the owner already stopped itself (healthy\n // close) or this tab is not the owner.\n const forceClose = () => {\n if (torndown) {\n return;\n }\n\n torndown = true;\n client.destroy();\n worker.forceStopOwner?.();\n worker.close();\n };\n\n return {\n id: crypto.randomUUID(),\n client,\n destroy() {\n if (torndown) {\n return;\n }\n\n // The worker acked the graceful close within the budget → it already stopped\n // the owner itself, so a plain close() suffices. If it did NOT ack (timeout\n // or rejection), it may be wedged → force-stop the owner.\n const timeoutId = setTimeout(forceClose, GRACEFUL_CLOSE_TIMEOUT_MS);\n client.close().then(\n () => {\n clearTimeout(timeoutId);\n close();\n },\n () => {\n clearTimeout(timeoutId);\n forceClose();\n },\n );\n },\n async deleteData() {\n if (torndown) {\n return;\n }\n\n await new Promise<void>((resolve) => {\n const timeoutId = setTimeout(() => {\n forceClose();\n resolve();\n }, GRACEFUL_CLOSE_TIMEOUT_MS);\n const finish = () => {\n clearTimeout(timeoutId);\n close();\n resolve();\n };\n const fail = () => {\n clearTimeout(timeoutId);\n forceClose();\n resolve();\n };\n client.delete().then(finish, fail);\n });\n },\n terminateNow() {\n if (torndown) {\n return;\n }\n\n postCloseWithoutWaiting(worker);\n forceClose();\n },\n subscribeWorkerError: subscribeWorkerError(worker),\n };\n}\n\nexport function createModuleDatabaseRuntime(\n options: CreateModuleDatabaseRuntimeOptions = {},\n): DatabaseRuntime {\n evictCachedDatabasePages();\n if (\n !options.workerConstructor &&\n options.sharedWorkerConstructor === undefined &&\n typeof Worker !== \"undefined\"\n ) {\n const crossTabWorker = createCrossTabDatabaseWorker(\n options.workerUrl ?? DEFAULT_DATABASE_WORKER_URL,\n globalThis.Worker,\n );\n if (crossTabWorker) {\n return createSharedDatabaseRuntime(crossTabWorker);\n }\n }\n\n const sharedWorkerPort = createExplicitSharedWorkerPort(options);\n if (sharedWorkerPort) {\n return createSharedDatabaseRuntime(sharedWorkerPort);\n }\n\n if (\n typeof options.workerConstructor === \"undefined\" &&\n typeof Worker === \"undefined\"\n ) {\n throw new Error(\"Worker must be defined.\");\n }\n\n return createDatabaseRuntime(\n createModuleWorker(\n options.workerUrl ?? DEFAULT_DATABASE_WORKER_URL,\n options.workerConstructor,\n ),\n availableMessageChannelConstructor(options.messageChannelConstructor),\n );\n}\n"]}
|
|
@@ -93,6 +93,13 @@ export interface WorkerRequestMap {
|
|
|
93
93
|
export declare const WORKER_CONNECT_PORT_MESSAGE_TYPE = "tearleads:sqlite-connect-port";
|
|
94
94
|
export declare const WORKER_DISCONNECT_PORT_MESSAGE_TYPE = "tearleads:sqlite-disconnect-port";
|
|
95
95
|
export declare const WORKER_PORT_DISCONNECTED_MESSAGE_TYPE = "tearleads:sqlite-port-disconnected";
|
|
96
|
+
export declare const DATABASE_NOT_INITIALIZED_MESSAGE = "Database has not been initialized.";
|
|
97
|
+
export declare const DATABASE_DELETED_MESSAGE = "Database was deleted by another connection.";
|
|
98
|
+
export declare const WORKER_DATABASE_DELETED_MESSAGE_TYPE = "tearleads:sqlite-database-deleted";
|
|
99
|
+
/** Posts an unprompted notice back to the connection's client. */
|
|
100
|
+
export type DatabaseWorkerNotify = (message: {
|
|
101
|
+
readonly type: string;
|
|
102
|
+
}) => void;
|
|
96
103
|
export type WorkerMethod = keyof WorkerRequestMap;
|
|
97
104
|
export type WorkerRequest<K extends WorkerMethod = WorkerMethod> = K extends WorkerMethod ? {
|
|
98
105
|
id: number;
|
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
export const WORKER_CONNECT_PORT_MESSAGE_TYPE = "tearleads:sqlite-connect-port";
|
|
2
2
|
export const WORKER_DISCONNECT_PORT_MESSAGE_TYPE = "tearleads:sqlite-disconnect-port";
|
|
3
3
|
export const WORKER_PORT_DISCONNECTED_MESSAGE_TYPE = "tearleads:sqlite-port-disconnected";
|
|
4
|
+
// The worker's answer to a statement on a connection with no open database.
|
|
5
|
+
// The cross-tab coordinator matches it to notice a client whose database was
|
|
6
|
+
// lost, so the worker and the coordinator share this one string.
|
|
7
|
+
export const DATABASE_NOT_INITIALIZED_MESSAGE = "Database has not been initialized.";
|
|
8
|
+
// The worker's answer to a statement on a connection whose database another
|
|
9
|
+
// connection deleted. A deliberate delete (logout, destroying an identity) is
|
|
10
|
+
// not a loss to recover from, so it must not read as a never-opened database.
|
|
11
|
+
export const DATABASE_DELETED_MESSAGE = "Database was deleted by another connection.";
|
|
12
|
+
// Posted unprompted on each other connection to a database the moment one
|
|
13
|
+
// connection deletes it, so a client learns of the delete before its owner tab
|
|
14
|
+
// can go away, even when it sends nothing in between.
|
|
15
|
+
export const WORKER_DATABASE_DELETED_MESSAGE_TYPE = "tearleads:sqlite-database-deleted";
|
|
4
16
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"AA0HA,MAAM,CAAC,MAAM,gCAAgC,GAAG,+BAA+B,CAAC;AAChF,MAAM,CAAC,MAAM,mCAAmC,GAC9C,kCAAkC,CAAC;AACrC,MAAM,CAAC,MAAM,qCAAqC,GAChD,oCAAoC,CAAC","sourcesContent":["export type CipherName =\n | \"sqlcipher\"\n | \"chacha20\"\n | \"aes128cbc\"\n | \"aes256cbc\"\n | \"ascon128\";\n\n/**\n * Where the database file lives.\n *\n * - `\"memory\"`: transient in-memory database (the historical default). Wiped on\n * every reload / worker restart.\n * - `\"opfs-sahpool\"`: persistent database backed by the OPFS SyncAccessHandle\n * Pool VFS. Survives reloads (including hard / shift+reload) because the bytes\n * live in the Origin Private File System, not in the worker heap or the HTTP\n * cache. Requires neither `SharedArrayBuffer` nor COOP/COEP headers.\n *\n * When `\"opfs-sahpool\"` is requested but OPFS is unavailable (or the VFS fails\n * to install), `initDatabase` throws rather than silently degrading to memory —\n * persistence is opt-in and a missing backend is treated as a hard error.\n */\nexport type DatabasePersistenceMode = \"memory\" | \"opfs-sahpool\";\n\nexport interface DatabaseWorkerInitOptions {\n dbName: string;\n cipher: CipherName;\n key: string;\n /**\n * Storage backend for the database. Defaults to `\"memory\"` to preserve the\n * historical behavior for callers that do not opt into persistence.\n */\n persistence?: DatabasePersistenceMode;\n}\n\nexport type SqliteBindValue = string | number | null;\nexport type SqliteBind =\n | Record<string, SqliteBindValue>\n | ReadonlyArray<SqliteBindValue>;\nexport type SqliteRowMode = \"object\" | \"array\";\nexport type SqliteObjectRow = Record<string, SqliteBindValue>;\nexport type SqliteArrayRow = SqliteBindValue[];\nexport type SqliteRow = SqliteObjectRow | SqliteArrayRow;\n\nexport interface DatabaseWorkerExecOptions {\n sql: string;\n bind?: SqliteBind;\n rowMode?: SqliteRowMode;\n}\n\nexport interface DatabaseWorkerExecResult {\n ok: true;\n rows: SqliteRow[];\n}\n\nexport interface DatabaseWorkerReady {\n ok: true;\n}\n\nexport interface DatabaseWorkerClosed {\n ok: true;\n}\n\nexport interface DatabaseWorkerDeleted {\n ok: true;\n}\n\nexport interface DatabaseWorkerStorageWiped {\n ok: true;\n}\n\nexport interface DatabaseWorkerPingResult {\n ok: true;\n message: \"pong\";\n}\n\nexport interface DatabaseWorkerError {\n ok: false;\n message: string;\n}\n\nexport type DatabaseWorkerResult<T> = T | DatabaseWorkerError;\n\nexport interface WorkerRequestMap {\n ping: {\n params: undefined;\n result: DatabaseWorkerPingResult;\n };\n init: {\n params: DatabaseWorkerInitOptions;\n result: DatabaseWorkerReady;\n };\n exec: {\n params: DatabaseWorkerExecOptions;\n result: DatabaseWorkerExecResult;\n };\n // Graceful shutdown: close the db and release the persistent VFS's OPFS access\n // handles before the worker is terminated, so the next worker (reload / other\n // tab) can acquire them without losing the SAHPool lock-contention race.\n close: {\n params: undefined;\n result: DatabaseWorkerClosed;\n };\n // Drain previously accepted database work before the host authorizes a wipe.\n prepareDelete: {\n params: undefined;\n result: DatabaseWorkerReady;\n };\n // Destructive shutdown: close the db and WIPE the persistent VFS's OPFS files\n // (not merely release the handles). Used to forget local data on logout.\n delete: {\n params: undefined;\n result: DatabaseWorkerDeleted;\n };\n // Device reset: remove everything in this origin's OPFS from the worker, for\n // shells whose main thread has no OPFS (WKWebView). Rejected once this worker\n // has opened persistent storage, whose access handles it would still hold.\n wipeStorage: {\n params: undefined;\n result: DatabaseWorkerStorageWiped;\n };\n}\n\nexport const WORKER_CONNECT_PORT_MESSAGE_TYPE = \"tearleads:sqlite-connect-port\";\nexport const WORKER_DISCONNECT_PORT_MESSAGE_TYPE =\n \"tearleads:sqlite-disconnect-port\";\nexport const WORKER_PORT_DISCONNECTED_MESSAGE_TYPE =\n \"tearleads:sqlite-port-disconnected\";\n\nexport type WorkerMethod = keyof WorkerRequestMap;\n\nexport type WorkerRequest<K extends WorkerMethod = WorkerMethod> =\n K extends WorkerMethod\n ? {\n id: number;\n method: K;\n params: WorkerRequestMap[K][\"params\"];\n }\n : never;\n\nexport type WorkerResponse<K extends WorkerMethod = WorkerMethod> =\n K extends WorkerMethod\n ? {\n id: number;\n result: DatabaseWorkerResult<WorkerRequestMap[K][\"result\"]>;\n }\n : never;\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"AA0HA,MAAM,CAAC,MAAM,gCAAgC,GAAG,+BAA+B,CAAC;AAChF,MAAM,CAAC,MAAM,mCAAmC,GAC9C,kCAAkC,CAAC;AACrC,MAAM,CAAC,MAAM,qCAAqC,GAChD,oCAAoC,CAAC;AAEvC,4EAA4E;AAC5E,6EAA6E;AAC7E,iEAAiE;AACjE,MAAM,CAAC,MAAM,gCAAgC,GAC3C,oCAAoC,CAAC;AAEvC,4EAA4E;AAC5E,8EAA8E;AAC9E,8EAA8E;AAC9E,MAAM,CAAC,MAAM,wBAAwB,GACnC,6CAA6C,CAAC;AAEhD,0EAA0E;AAC1E,+EAA+E;AAC/E,sDAAsD;AACtD,MAAM,CAAC,MAAM,oCAAoC,GAC/C,mCAAmC,CAAC","sourcesContent":["export type CipherName =\n | \"sqlcipher\"\n | \"chacha20\"\n | \"aes128cbc\"\n | \"aes256cbc\"\n | \"ascon128\";\n\n/**\n * Where the database file lives.\n *\n * - `\"memory\"`: transient in-memory database (the historical default). Wiped on\n * every reload / worker restart.\n * - `\"opfs-sahpool\"`: persistent database backed by the OPFS SyncAccessHandle\n * Pool VFS. Survives reloads (including hard / shift+reload) because the bytes\n * live in the Origin Private File System, not in the worker heap or the HTTP\n * cache. Requires neither `SharedArrayBuffer` nor COOP/COEP headers.\n *\n * When `\"opfs-sahpool\"` is requested but OPFS is unavailable (or the VFS fails\n * to install), `initDatabase` throws rather than silently degrading to memory —\n * persistence is opt-in and a missing backend is treated as a hard error.\n */\nexport type DatabasePersistenceMode = \"memory\" | \"opfs-sahpool\";\n\nexport interface DatabaseWorkerInitOptions {\n dbName: string;\n cipher: CipherName;\n key: string;\n /**\n * Storage backend for the database. Defaults to `\"memory\"` to preserve the\n * historical behavior for callers that do not opt into persistence.\n */\n persistence?: DatabasePersistenceMode;\n}\n\nexport type SqliteBindValue = string | number | null;\nexport type SqliteBind =\n | Record<string, SqliteBindValue>\n | ReadonlyArray<SqliteBindValue>;\nexport type SqliteRowMode = \"object\" | \"array\";\nexport type SqliteObjectRow = Record<string, SqliteBindValue>;\nexport type SqliteArrayRow = SqliteBindValue[];\nexport type SqliteRow = SqliteObjectRow | SqliteArrayRow;\n\nexport interface DatabaseWorkerExecOptions {\n sql: string;\n bind?: SqliteBind;\n rowMode?: SqliteRowMode;\n}\n\nexport interface DatabaseWorkerExecResult {\n ok: true;\n rows: SqliteRow[];\n}\n\nexport interface DatabaseWorkerReady {\n ok: true;\n}\n\nexport interface DatabaseWorkerClosed {\n ok: true;\n}\n\nexport interface DatabaseWorkerDeleted {\n ok: true;\n}\n\nexport interface DatabaseWorkerStorageWiped {\n ok: true;\n}\n\nexport interface DatabaseWorkerPingResult {\n ok: true;\n message: \"pong\";\n}\n\nexport interface DatabaseWorkerError {\n ok: false;\n message: string;\n}\n\nexport type DatabaseWorkerResult<T> = T | DatabaseWorkerError;\n\nexport interface WorkerRequestMap {\n ping: {\n params: undefined;\n result: DatabaseWorkerPingResult;\n };\n init: {\n params: DatabaseWorkerInitOptions;\n result: DatabaseWorkerReady;\n };\n exec: {\n params: DatabaseWorkerExecOptions;\n result: DatabaseWorkerExecResult;\n };\n // Graceful shutdown: close the db and release the persistent VFS's OPFS access\n // handles before the worker is terminated, so the next worker (reload / other\n // tab) can acquire them without losing the SAHPool lock-contention race.\n close: {\n params: undefined;\n result: DatabaseWorkerClosed;\n };\n // Drain previously accepted database work before the host authorizes a wipe.\n prepareDelete: {\n params: undefined;\n result: DatabaseWorkerReady;\n };\n // Destructive shutdown: close the db and WIPE the persistent VFS's OPFS files\n // (not merely release the handles). Used to forget local data on logout.\n delete: {\n params: undefined;\n result: DatabaseWorkerDeleted;\n };\n // Device reset: remove everything in this origin's OPFS from the worker, for\n // shells whose main thread has no OPFS (WKWebView). Rejected once this worker\n // has opened persistent storage, whose access handles it would still hold.\n wipeStorage: {\n params: undefined;\n result: DatabaseWorkerStorageWiped;\n };\n}\n\nexport const WORKER_CONNECT_PORT_MESSAGE_TYPE = \"tearleads:sqlite-connect-port\";\nexport const WORKER_DISCONNECT_PORT_MESSAGE_TYPE =\n \"tearleads:sqlite-disconnect-port\";\nexport const WORKER_PORT_DISCONNECTED_MESSAGE_TYPE =\n \"tearleads:sqlite-port-disconnected\";\n\n// The worker's answer to a statement on a connection with no open database.\n// The cross-tab coordinator matches it to notice a client whose database was\n// lost, so the worker and the coordinator share this one string.\nexport const DATABASE_NOT_INITIALIZED_MESSAGE =\n \"Database has not been initialized.\";\n\n// The worker's answer to a statement on a connection whose database another\n// connection deleted. A deliberate delete (logout, destroying an identity) is\n// not a loss to recover from, so it must not read as a never-opened database.\nexport const DATABASE_DELETED_MESSAGE =\n \"Database was deleted by another connection.\";\n\n// Posted unprompted on each other connection to a database the moment one\n// connection deletes it, so a client learns of the delete before its owner tab\n// can go away, even when it sends nothing in between.\nexport const WORKER_DATABASE_DELETED_MESSAGE_TYPE =\n \"tearleads:sqlite-database-deleted\";\n\n/** Posts an unprompted notice back to the connection's client. */\nexport type DatabaseWorkerNotify = (message: { readonly type: string }) => void;\n\nexport type WorkerMethod = keyof WorkerRequestMap;\n\nexport type WorkerRequest<K extends WorkerMethod = WorkerMethod> =\n K extends WorkerMethod\n ? {\n id: number;\n method: K;\n params: WorkerRequestMap[K][\"params\"];\n }\n : never;\n\nexport type WorkerResponse<K extends WorkerMethod = WorkerMethod> =\n K extends WorkerMethod\n ? {\n id: number;\n result: DatabaseWorkerResult<WorkerRequestMap[K][\"result\"]>;\n }\n : never;\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface WorkerCrashDetail {
|
|
2
|
+
readonly message: string;
|
|
3
|
+
readonly filename?: string;
|
|
4
|
+
readonly lineno?: number;
|
|
5
|
+
readonly colno?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare class DatabaseWorkerCrashError extends Error {
|
|
8
|
+
readonly detail: WorkerCrashDetail;
|
|
9
|
+
constructor(detail: WorkerCrashDetail);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A client's open database went away with the owner tab whose worker held it.
|
|
13
|
+
* Hosts handle it as a crash (retire the runtime, open a new one) but it is the
|
|
14
|
+
* expected result of closing or reloading a tab, not a defect: report it below
|
|
15
|
+
* error level. The inherited message prefix keeps "the database went away"
|
|
16
|
+
* classifiers matching it.
|
|
17
|
+
*/
|
|
18
|
+
export declare class DatabaseConnectionLostError extends DatabaseWorkerCrashError {
|
|
19
|
+
constructor();
|
|
20
|
+
}
|
|
21
|
+
export declare function isDatabaseConnectionLostError(error: unknown): error is DatabaseConnectionLostError;
|
|
22
|
+
export declare function describeWorkerErrorEvent(event: Event): WorkerCrashDetail;
|
|
23
|
+
export declare function workerCrashErrorFromEvent(event: Event): Error;
|
|
@@ -17,6 +17,23 @@ export class DatabaseWorkerCrashError extends Error {
|
|
|
17
17
|
this.detail = detail;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
+
const CONNECTION_LOST_DETAIL = "The database connection was lost when the tab that owned it closed. Open the database again.";
|
|
21
|
+
/**
|
|
22
|
+
* A client's open database went away with the owner tab whose worker held it.
|
|
23
|
+
* Hosts handle it as a crash (retire the runtime, open a new one) but it is the
|
|
24
|
+
* expected result of closing or reloading a tab, not a defect: report it below
|
|
25
|
+
* error level. The inherited message prefix keeps "the database went away"
|
|
26
|
+
* classifiers matching it.
|
|
27
|
+
*/
|
|
28
|
+
export class DatabaseConnectionLostError extends DatabaseWorkerCrashError {
|
|
29
|
+
constructor() {
|
|
30
|
+
super({ message: CONNECTION_LOST_DETAIL });
|
|
31
|
+
this.name = "DatabaseConnectionLostError";
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export function isDatabaseConnectionLostError(error) {
|
|
35
|
+
return error instanceof DatabaseConnectionLostError;
|
|
36
|
+
}
|
|
20
37
|
export function describeWorkerErrorEvent(event) {
|
|
21
38
|
if (!(event instanceof ErrorEvent)) {
|
|
22
39
|
return { message: "" };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workerCrash.js","sourceRoot":"","sources":["workerCrash.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,EAAE;AACF,yEAAyE;AACzE,4EAA4E;AAC5E,iFAAiF;AACjF,iFAAiF;AACjF,4EAA4E;AAC5E,+EAA+E;AAE/E,MAAM,oBAAoB,GAAG,yBAAyB,CAAC;AASvD,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACxC,MAAM,CAAoB;IAEnC,YAAY,MAAyB;QACnC,KAAK,CACH,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC;YACvB,CAAC,CAAC,GAAG,oBAAoB,IAAI,MAAM,CAAC,OAAO,EAAE;YAC7C,CAAC,CAAC,oBAAoB,CACzB,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;QACvC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED,MAAM,UAAU,wBAAwB,CAAC,KAAY;IACnD,IAAI,CAAC,CAAC,KAAK,YAAY,UAAU,CAAC,EAAE,CAAC;QACnC,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IACzB,CAAC;IAED,OAAO;QACL,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,KAAK,EAAE,KAAK,CAAC,KAAK;KACnB,CAAC;AACJ,CAAC;AAED,yEAAyE;AACzE,+EAA+E;AAC/E,yEAAyE;AACzE,MAAM,UAAU,yBAAyB,CAAC,KAAY;IACpD,IAAI,KAAK,YAAY,UAAU,IAAI,KAAK,CAAC,KAAK,YAAY,KAAK,EAAE,CAAC;QAChE,OAAO,KAAK,CAAC,KAAK,CAAC;IACrB,CAAC;IAED,OAAO,IAAI,wBAAwB,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC,CAAC;AACvE,CAAC","sourcesContent":["// Runs on the main thread.\n//\n// An uncaught exception inside the SQLite worker reaches its owner as an\n// `ErrorEvent` whose `error` is null across the agent boundary, so the only\n// `Error` that can carry a stack is one minted here. This module is bundled into\n// the application chunk, never into the worker script, so the resulting frame is\n// one the diagnostics allowlist admits — and a single, stable location that\n// tells \"the database worker crashed\" apart from every other database failure.\n\nconst WORKER_CRASH_MESSAGE = \"Database worker failed.\";\n\nexport interface WorkerCrashDetail {\n readonly message: string;\n readonly filename?: string;\n readonly lineno?: number;\n readonly colno?: number;\n}\n\nexport class DatabaseWorkerCrashError extends Error {\n readonly detail: WorkerCrashDetail;\n\n constructor(detail: WorkerCrashDetail) {\n super(\n detail.message.length > 0\n ? `${WORKER_CRASH_MESSAGE} ${detail.message}`\n : WORKER_CRASH_MESSAGE,\n );\n this.name = \"DatabaseWorkerCrashError\";\n this.detail = detail;\n }\n}\n\nexport function describeWorkerErrorEvent(event: Event): WorkerCrashDetail {\n if (!(event instanceof ErrorEvent)) {\n return { message: \"\" };\n }\n\n return {\n message: event.message,\n filename: event.filename,\n lineno: event.lineno,\n colno: event.colno,\n };\n}\n\n// Reuses an `Error` the event already carries: the cross-tab coordinator\n// dispatches synthetic events that hold the instance minted at the catch site,\n// so every listener sees the same stack instead of one rooted in itself.\nexport function workerCrashErrorFromEvent(event: Event): Error {\n if (event instanceof ErrorEvent && event.error instanceof Error) {\n return event.error;\n }\n\n return new DatabaseWorkerCrashError(describeWorkerErrorEvent(event));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"workerCrash.js","sourceRoot":"","sources":["workerCrash.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,EAAE;AACF,yEAAyE;AACzE,4EAA4E;AAC5E,iFAAiF;AACjF,iFAAiF;AACjF,4EAA4E;AAC5E,+EAA+E;AAE/E,MAAM,oBAAoB,GAAG,yBAAyB,CAAC;AASvD,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACxC,MAAM,CAAoB;IAEnC,YAAY,MAAyB;QACnC,KAAK,CACH,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC;YACvB,CAAC,CAAC,GAAG,oBAAoB,IAAI,MAAM,CAAC,OAAO,EAAE;YAC7C,CAAC,CAAC,oBAAoB,CACzB,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;QACvC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED,MAAM,sBAAsB,GAC1B,8FAA8F,CAAC;AAEjG;;;;;;GAMG;AACH,MAAM,OAAO,2BAA4B,SAAQ,wBAAwB;IACvE;QACE,KAAK,CAAC,EAAE,OAAO,EAAE,sBAAsB,EAAE,CAAC,CAAC;QAC3C,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;IAC5C,CAAC;CACF;AAED,MAAM,UAAU,6BAA6B,CAC3C,KAAc;IAEd,OAAO,KAAK,YAAY,2BAA2B,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,KAAY;IACnD,IAAI,CAAC,CAAC,KAAK,YAAY,UAAU,CAAC,EAAE,CAAC;QACnC,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IACzB,CAAC;IAED,OAAO;QACL,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,KAAK,EAAE,KAAK,CAAC,KAAK;KACnB,CAAC;AACJ,CAAC;AAED,yEAAyE;AACzE,+EAA+E;AAC/E,yEAAyE;AACzE,MAAM,UAAU,yBAAyB,CAAC,KAAY;IACpD,IAAI,KAAK,YAAY,UAAU,IAAI,KAAK,CAAC,KAAK,YAAY,KAAK,EAAE,CAAC;QAChE,OAAO,KAAK,CAAC,KAAK,CAAC;IACrB,CAAC;IAED,OAAO,IAAI,wBAAwB,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC,CAAC;AACvE,CAAC","sourcesContent":["// Runs on the main thread.\n//\n// An uncaught exception inside the SQLite worker reaches its owner as an\n// `ErrorEvent` whose `error` is null across the agent boundary, so the only\n// `Error` that can carry a stack is one minted here. This module is bundled into\n// the application chunk, never into the worker script, so the resulting frame is\n// one the diagnostics allowlist admits — and a single, stable location that\n// tells \"the database worker crashed\" apart from every other database failure.\n\nconst WORKER_CRASH_MESSAGE = \"Database worker failed.\";\n\nexport interface WorkerCrashDetail {\n readonly message: string;\n readonly filename?: string;\n readonly lineno?: number;\n readonly colno?: number;\n}\n\nexport class DatabaseWorkerCrashError extends Error {\n readonly detail: WorkerCrashDetail;\n\n constructor(detail: WorkerCrashDetail) {\n super(\n detail.message.length > 0\n ? `${WORKER_CRASH_MESSAGE} ${detail.message}`\n : WORKER_CRASH_MESSAGE,\n );\n this.name = \"DatabaseWorkerCrashError\";\n this.detail = detail;\n }\n}\n\nconst CONNECTION_LOST_DETAIL =\n \"The database connection was lost when the tab that owned it closed. Open the database again.\";\n\n/**\n * A client's open database went away with the owner tab whose worker held it.\n * Hosts handle it as a crash (retire the runtime, open a new one) but it is the\n * expected result of closing or reloading a tab, not a defect: report it below\n * error level. The inherited message prefix keeps \"the database went away\"\n * classifiers matching it.\n */\nexport class DatabaseConnectionLostError extends DatabaseWorkerCrashError {\n constructor() {\n super({ message: CONNECTION_LOST_DETAIL });\n this.name = \"DatabaseConnectionLostError\";\n }\n}\n\nexport function isDatabaseConnectionLostError(\n error: unknown,\n): error is DatabaseConnectionLostError {\n return error instanceof DatabaseConnectionLostError;\n}\n\nexport function describeWorkerErrorEvent(event: Event): WorkerCrashDetail {\n if (!(event instanceof ErrorEvent)) {\n return { message: \"\" };\n }\n\n return {\n message: event.message,\n filename: event.filename,\n lineno: event.lineno,\n colno: event.colno,\n };\n}\n\n// Reuses an `Error` the event already carries: the cross-tab coordinator\n// dispatches synthetic events that hold the instance minted at the catch site,\n// so every listener sees the same stack instead of one rooted in itself.\nexport function workerCrashErrorFromEvent(event: Event): Error {\n if (event instanceof ErrorEvent && event.error instanceof Error) {\n return event.error;\n }\n\n return new DatabaseWorkerCrashError(describeWorkerErrorEvent(event));\n}\n"]}
|
package/package.json
CHANGED
package/sqlite/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export type SQLiteModuleWorkerLike = ModuleWorkerLike;
|
|
|
8
8
|
export interface SQLiteRuntimeWorker extends WorkerLike {
|
|
9
9
|
terminate(): void;
|
|
10
10
|
}
|
|
11
|
-
export { createModuleDatabaseRuntime as createSQLiteRuntime } from "../internal/sqlite-worker/runtime.js";
|
|
11
|
+
export { createModuleDatabaseRuntime as createSQLiteRuntime, DatabaseConnectionLostError, isDatabaseConnectionLostError, } from "../internal/sqlite-worker/runtime.js";
|
|
12
12
|
export declare function createSQLiteRuntimeFromWorker(worker: SQLiteRuntimeWorker): SQLiteRuntime;
|
|
13
13
|
export { purgeOpfsSqliteDatabase } from "../internal/sqlite-worker/purgeOpfsDatabase.js";
|
|
14
14
|
export type { DatabasePersistenceMode } from "../internal/sqlite-worker/types.js";
|
package/sqlite/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createDatabaseRuntime, } from "../internal/sqlite-worker/runtime.js";
|
|
2
|
-
export { createModuleDatabaseRuntime as createSQLiteRuntime } from "../internal/sqlite-worker/runtime.js";
|
|
2
|
+
export { createModuleDatabaseRuntime as createSQLiteRuntime, DatabaseConnectionLostError, isDatabaseConnectionLostError, } from "../internal/sqlite-worker/runtime.js";
|
|
3
3
|
export function createSQLiteRuntimeFromWorker(worker) {
|
|
4
4
|
return createDatabaseRuntime(worker);
|
|
5
5
|
}
|
package/sqlite/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,qBAAqB,GAItB,MAAM,kCAAkC,CAAC;AAW1C,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,qBAAqB,GAItB,MAAM,kCAAkC,CAAC;AAW1C,OAAO,EACL,2BAA2B,IAAI,mBAAmB,EAClD,2BAA2B,EAC3B,6BAA6B,GAC9B,MAAM,kCAAkC,CAAC;AAE1C,MAAM,UAAU,6BAA6B,CAC3C,MAA2B;IAE3B,OAAO,qBAAqB,CAAC,MAAM,CAAC,CAAC;AACvC,CAAC;AAED,OAAO,EAAE,uBAAuB,EAAE,MAAM,8CAA8C,CAAC;AAEvF,OAAO,EAEL,eAAe,GAChB,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAIL,iCAAiC,IAAI,2BAA2B,GACjE,MAAM,yCAAyC,CAAC;AACjD,OAAO,EACL,iCAAiC,EACjC,aAAa,EACb,oBAAoB,EAGpB,yBAAyB,EACzB,eAAe,EACf,6BAA6B,EAC7B,kBAAkB,EAClB,yBAAyB,EACzB,wBAAwB,EAOxB,kBAAkB,EAClB,4BAA4B,GAC7B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,wBAAwB,EACxB,4BAA4B,EAC5B,yBAAyB,EAEzB,wBAAwB,EACxB,+BAA+B,GAEhC,MAAM,mCAAmC,CAAC","sourcesContent":["import type {\n DatabaseWorkerClient,\n WorkerLike,\n} from \"@tearleads/sqlite-worker/client\";\nimport {\n type CreateModuleDatabaseRuntimeOptions,\n createDatabaseRuntime,\n type DatabaseRuntime,\n type ModuleWorkerConstructor,\n type ModuleWorkerLike,\n} from \"@tearleads/sqlite-worker/runtime\";\n\nexport type SQLiteWorkerClient = DatabaseWorkerClient;\nexport type CreateSQLiteRuntimeOptions = CreateModuleDatabaseRuntimeOptions;\nexport type SQLiteRuntime = DatabaseRuntime;\nexport type SQLiteModuleWorkerConstructor = ModuleWorkerConstructor;\nexport type SQLiteModuleWorkerLike = ModuleWorkerLike;\nexport interface SQLiteRuntimeWorker extends WorkerLike {\n terminate(): void;\n}\n\nexport {\n createModuleDatabaseRuntime as createSQLiteRuntime,\n DatabaseConnectionLostError,\n isDatabaseConnectionLostError,\n} from \"@tearleads/sqlite-worker/runtime\";\n\nexport function createSQLiteRuntimeFromWorker(\n worker: SQLiteRuntimeWorker,\n): SQLiteRuntime {\n return createDatabaseRuntime(worker);\n}\n\nexport { purgeOpfsSqliteDatabase } from \"@tearleads/sqlite-worker/purge-opfs-database\";\nexport type { DatabasePersistenceMode } from \"@tearleads/sqlite-worker/types\";\nexport {\n type WipeOpfsStorageResult,\n wipeOpfsStorage,\n} from \"@tearleads/sqlite-worker/wipe-opfs-storage\";\nexport { clientSQLiteSchema } from \"../data/sqlite/schema\";\nexport {\n type ClientSQLiteDatabase as SQLiteDatabase,\n type ClientSQLitePersistenceRuntime as SQLitePersistenceRuntime,\n type ClientSQLiteTransactionScope as SQLiteTransaction,\n getClientSQLitePersistenceRuntime as getSQLitePersistenceRuntime,\n} from \"../data/sqlite/sqlitePersistenceRuntime\";\nexport {\n assertRestorableLocalSchemaLedger,\n createExecSql,\n defineSqlTableSchema,\n type ExecSql,\n type ExecSqlClientLike,\n ensureLocalSchemaMigrated,\n ensureSqlTables,\n LOCAL_SCHEMA_MIGRATIONS_TABLE,\n migrateLocalSchema,\n resetConnectionSchemaMemo,\n runSerializedSqlMutation,\n type SqlArrayRow,\n type SqlBind,\n type SqlRow,\n type SqlRowMode,\n type SqlRowValue,\n type SqlTableSchema,\n unavailableExecSql,\n withLocalSchemaMigrationLock,\n} from \"../data/sqlite/sqlSchema\";\nexport {\n EPHEMERAL_STORAGE_POLICY,\n isPersistentStorageSupported,\n PERSISTENT_STORAGE_POLICY,\n type RequestPersistentStorageResult,\n requestPersistentStorage,\n resolveStoragePersistencePolicy,\n type StoragePersistencePolicy,\n} from \"../data/sqlite/storagePersistence\";\n"]}
|