@bastani/atomic 0.10.15 → 0.10.16-alpha.1
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/CHANGELOG.md +50 -0
- package/dist/__atomic_timers/index.js +112 -0
- package/dist/__atomic_timers/index.js.map +1 -0
- package/dist/_shared/dist-KOELCESV.js +2 -2
- package/dist/_shared/fork-row-index-UAUAQRD5.js +2 -2
- package/dist/_shared/http-YFAPTIZD.js +20 -22
- package/dist/_shared/http-YFAPTIZD.js.map +1 -1
- package/dist/_shared/lib-4PES5P4V.js +2 -2
- package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js +55 -25
- package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js.map +1 -1
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +13 -14
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js.map +1 -1
- package/dist/_shared/mode-shared-2QJSCUM6.js +16 -17
- package/dist/_shared/mode-shared-2QJSCUM6.js.map +1 -1
- package/dist/_shared/p0-cli-BB45ZQY6.js +23 -37
- package/dist/_shared/p0-cli-BB45ZQY6.js.map +1 -1
- package/dist/_shared/p1a-prewarm-XIU57JHF.js +6 -5
- package/dist/_shared/p1a-prewarm-XIU57JHF.js.map +1 -1
- package/dist/_shared/{p1b-elig-TVB5CBLL.js → p1b-elig-BY2G5BUE.js} +28 -36
- package/dist/_shared/p1b-elig-BY2G5BUE.js.map +1 -0
- package/dist/_shared/runtime-O4KCSG4C.js +4 -4
- package/dist/_shared/sdk-OHKMDJ74.js +382 -45
- package/dist/_shared/sdk-OHKMDJ74.js.map +1 -1
- package/dist/_shared/session-data-AHTU7IS6.js +3 -3
- package/dist/_shared/session-manager-list-2BLEEZVG.js +1 -1
- package/dist/_shared/settings-startup-HXQLSUWM.js.map +1 -1
- package/dist/_shared/{startup-0-0-Q3MWKUK4.js → startup-0-0-ERMIDHQT.js} +296 -382
- package/dist/_shared/startup-0-0-ERMIDHQT.js.map +1 -0
- package/dist/_shared/{startup-0-1-M6OWAYHH.js → startup-0-1-RTASI3HG.js} +430 -102
- package/dist/_shared/startup-0-1-RTASI3HG.js.map +1 -0
- package/dist/_shared/{startup-0-2-2HUMCPKX.js → startup-0-2-YZZOC22D.js} +8109 -7962
- package/dist/_shared/startup-0-2-YZZOC22D.js.map +1 -0
- package/dist/_shared/{startup-0-3-4ZYBYQNM.js → startup-0-3-DE2NCS6A.js} +130 -83
- package/dist/_shared/startup-0-3-DE2NCS6A.js.map +1 -0
- package/dist/_shared/startup-0-4-ZMJV547D.js +7 -7
- package/dist/_shared/{startup-0-5-YDW47QX6.js → startup-0-5-HZX3ZPTP.js} +411 -85
- package/dist/_shared/startup-0-5-HZX3ZPTP.js.map +1 -0
- package/dist/_shared/startup-10-0-TDQNBDDL.js +42 -29
- package/dist/_shared/startup-10-0-TDQNBDDL.js.map +1 -1
- package/dist/_shared/startup-12-0-55AAXBJZ.js +3 -3
- package/dist/_shared/startup-14-0-MLX36RBG.js +11 -10
- package/dist/_shared/startup-14-0-MLX36RBG.js.map +1 -1
- package/dist/_shared/startup-15-0-YUKGAC63.js +9 -8
- package/dist/_shared/startup-15-0-YUKGAC63.js.map +1 -1
- package/dist/_shared/startup-15-1-4S7FLMNG.js +24 -16
- package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
- package/dist/_shared/startup-8-0-34CBHPZH.js +40 -19
- package/dist/_shared/startup-8-0-34CBHPZH.js.map +1 -1
- package/dist/_shared/startup-8-1-LZFXSD3Z.js +129 -92
- package/dist/_shared/startup-8-1-LZFXSD3Z.js.map +1 -1
- package/dist/_shared/storage-command-7MGXLJGZ.js +6 -4
- package/dist/_shared/storage-command-7MGXLJGZ.js.map +1 -1
- package/dist/_shared/storage-status-K7PX2RXA.js +7 -6
- package/dist/_shared/storage-status-K7PX2RXA.js.map +1 -1
- package/dist/_shared/task-reference-stream-JWMUZSJX.js +1 -1
- package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
- package/dist/_shared/team-DOQKICG2.js +4 -3
- package/dist/_shared/team-DOQKICG2.js.map +1 -1
- package/dist/_shared/tree-outline-MUEPK5B7.js +2 -2
- package/dist/builtin/intercom/index.bundle.mjs +1 -2
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/index.bundle.mjs +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +6 -0
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +102 -42
- package/dist/builtin/web-access/index.bundle.mjs +1 -2
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/cli/args.js +2 -2
- package/dist/cli/auth-cli.code.js +6 -6
- package/dist/cli/auth-cli.impl.js +3 -3
- package/dist/cli/auth-cli.js +3 -3
- package/dist/cli/blueprint-command.code.js +7 -6
- package/dist/cli/blueprint-command.code.js.map +1 -1
- package/dist/cli/blueprint-command.impl.js +3 -3
- package/dist/cli/blueprint-command.js +3 -3
- package/dist/cli/intercom-command.code.js +3 -3
- package/dist/cli/intercom-command.impl.js +3 -3
- package/dist/cli/intercom-command.js +3 -3
- package/dist/cli/list-models.code.js +2 -2
- package/dist/cli/list-models.impl.js +3 -3
- package/dist/cli/list-models.js +3 -3
- package/dist/cli/session-picker.code.js +2 -2
- package/dist/cli/session-picker.impl.js +3 -3
- package/dist/cli/session-picker.js +3 -3
- package/dist/cli/startup-ui.code.js +2 -2
- package/dist/cli/startup-ui.impl.js +3 -3
- package/dist/cli/startup-ui.js +3 -3
- package/dist/cli/storage-command.impl.js +3 -3
- package/dist/cli/storage-command.js +3 -3
- package/dist/cli/storage-search-session.code.js +1 -1
- package/dist/cli/storage-search-session.impl.js +3 -3
- package/dist/cli/storage-search-session.js +3 -3
- package/dist/cli/team-command.code.js +2 -2
- package/dist/cli/team-command.impl.js +3 -3
- package/dist/cli/team-command.js +3 -3
- package/dist/cli.js +2 -2
- package/dist/core/agent-session.d.ts +1 -0
- package/dist/core/debug.code.js +1 -1
- package/dist/core/debug.impl.js +3 -3
- package/dist/core/debug.js +3 -3
- package/dist/core/export-html/card-projection.code.js +1 -1
- package/dist/core/export-html/card-projection.impl.js +3 -3
- package/dist/core/export-html/card-projection.js +3 -3
- package/dist/core/export-html/index.code.js +2 -2
- package/dist/core/export-html/index.impl.js +3 -3
- package/dist/core/export-html/index.js +3 -3
- package/dist/core/export-html/json-spans.impl.js +3 -3
- package/dist/core/export-html/json-spans.js +3 -3
- package/dist/core/export-html/oversized-render-inputs.code.js +1 -1
- package/dist/core/export-html/oversized-render-inputs.impl.js +3 -3
- package/dist/core/export-html/oversized-render-inputs.js +3 -3
- package/dist/core/export-html/tool-renderer.impl.js +3 -3
- package/dist/core/export-html/tool-renderer.js +3 -3
- package/dist/core/extensions/jiti-loader.impl.js +3 -3
- package/dist/core/extensions/jiti-loader.js +3 -3
- package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
- package/dist/core/extensions/jiti-static-loader.js +3 -3
- package/dist/core/extensions/loader-host-modules.code.js +1 -1
- package/dist/core/extensions/loader-host-modules.impl.js +3 -3
- package/dist/core/extensions/loader-host-modules.js +3 -3
- package/dist/core/extensions/loader-virtual-modules.js +2 -2
- package/dist/core/extensions/runner-context.js +1 -1
- package/dist/core/http-dispatcher.d.ts +2 -1
- package/dist/core/intercom-broker-control-host.code.js +1 -1
- package/dist/core/intercom-broker-control-host.impl.js +3 -3
- package/dist/core/intercom-broker-control-host.js +3 -3
- package/dist/core/intercom-broker-control.code.js +3 -3
- package/dist/core/intercom-broker-control.impl.js +3 -3
- package/dist/core/intercom-broker-control.js +3 -3
- package/dist/core/lock-takeover.d.ts +2 -0
- package/dist/core/model-config.d.ts +28 -0
- package/dist/core/model-registry.js +1 -1
- package/dist/core/model-runtime-streaming.d.ts +3 -2
- package/dist/core/package-manager-storage-adapters.impl.js +3 -3
- package/dist/core/package-manager-storage-adapters.js +3 -3
- package/dist/core/provider-rate-limits.d.ts +17 -10
- package/dist/core/provider-request-admission.d.ts +16 -0
- package/dist/core/resume/blueprint/barrier.d.ts +6 -6
- package/dist/core/resume/blueprint/build.d.ts +3 -1
- package/dist/core/resume/blueprint/ledger.d.ts +3 -2
- package/dist/core/resume/blueprint/resume.d.ts +2 -1
- package/dist/core/retry-policy.d.ts +3 -1
- package/dist/core/sdk.code.js +3 -3
- package/dist/core/sdk.impl.js +3 -3
- package/dist/core/sdk.js +3 -3
- package/dist/core/session-manager-core.js +6 -6
- package/dist/core/session-manager-list.impl.js +3 -3
- package/dist/core/session-manager-list.js +3 -3
- package/dist/core/session-manager-types.d.ts +1 -1
- package/dist/core/session-manager.code.js +2 -2
- package/dist/core/session-manager.impl.js +3 -3
- package/dist/core/session-manager.js +3 -3
- package/dist/core/session-open-markers.js +1 -1
- package/dist/core/session-storage.impl.js +3 -3
- package/dist/core/session-storage.js +3 -3
- package/dist/core/settings-duration.d.ts +3 -0
- package/dist/core/settings-manager-resource-accessors.d.ts +2 -1
- package/dist/core/settings-schema.d.ts +1 -0
- package/dist/core/storage/index.js +2 -2
- package/dist/core/storage/node-sqlite-file-gate.js +7 -6
- package/dist/core/storage/node-sqlite-file-gate.js.map +1 -1
- package/dist/core/storage/node-sqlite-thread.js +2 -2
- package/dist/core/storage/node-sqlite.js +2 -2
- package/dist/core/storage/offline-snapshot-file.impl.js +3 -3
- package/dist/core/storage/offline-snapshot-file.js +3 -3
- package/dist/core/storage/prefix.js +3 -0
- package/dist/core/storage/prefix.js.map +1 -1
- package/dist/core/storage/provider.js +2 -2
- package/dist/core/storage/selection.js +2 -2
- package/dist/core/storage/session/branch-fork-source.code.js +2 -2
- package/dist/core/storage/session/branch-fork-source.impl.js +3 -3
- package/dist/core/storage/session/branch-fork-source.js +3 -3
- package/dist/core/storage/session/card-view.impl.js +3 -3
- package/dist/core/storage/session/card-view.js +3 -3
- package/dist/core/storage/session/child-reader.code.js +24 -7
- package/dist/core/storage/session/child-reader.code.js.map +1 -1
- package/dist/core/storage/session/child-reader.impl.js +3 -3
- package/dist/core/storage/session/child-reader.js +3 -3
- package/dist/core/storage/session/chunked-resume-projection.code.js +1 -1
- package/dist/core/storage/session/chunked-resume-projection.impl.js +3 -3
- package/dist/core/storage/session/chunked-resume-projection.js +3 -3
- package/dist/core/storage/session/expanded-child-details.code.js +3 -3
- package/dist/core/storage/session/expanded-child-details.impl.js +3 -3
- package/dist/core/storage/session/expanded-child-details.js +3 -3
- package/dist/core/storage/session/fork-row-bytes.impl.js +3 -3
- package/dist/core/storage/session/fork-row-bytes.js +3 -3
- package/dist/core/storage/session/fork-row-index.impl.js +3 -3
- package/dist/core/storage/session/fork-row-index.js +3 -3
- package/dist/core/storage/session/fork-staging.code.js +1 -1
- package/dist/core/storage/session/fork-staging.impl.js +3 -3
- package/dist/core/storage/session/fork-staging.js +3 -3
- package/dist/core/storage/session/fork-window.code.js +4 -4
- package/dist/core/storage/session/fork-window.impl.js +3 -3
- package/dist/core/storage/session/fork-window.js +3 -3
- package/dist/core/storage/session/history-pages.impl.js +3 -3
- package/dist/core/storage/session/history-pages.js +3 -3
- package/dist/core/storage/session/jsonl-entry-projection.impl.js +3 -3
- package/dist/core/storage/session/jsonl-entry-projection.js +3 -3
- package/dist/core/storage/session/jsonl-session-store.d.ts +2 -2
- package/dist/core/storage/session/jsonl-session-store.impl.js +3 -3
- package/dist/core/storage/session/jsonl-session-store.js +3 -3
- package/dist/core/storage/session/memory-session-store.d.ts +2 -2
- package/dist/core/storage/session/memory-session-store.impl.js +3 -3
- package/dist/core/storage/session/memory-session-store.js +3 -3
- package/dist/core/storage/session/pinned-branch-resume.code.js +3 -3
- package/dist/core/storage/session/pinned-branch-resume.impl.js +3 -3
- package/dist/core/storage/session/pinned-branch-resume.js +3 -3
- package/dist/core/storage/session/released-history-files.code.js +4 -4
- package/dist/core/storage/session/released-history-files.impl.js +3 -3
- package/dist/core/storage/session/released-history-files.js +3 -3
- package/dist/core/storage/session/resident-fork-rows.impl.js +3 -3
- package/dist/core/storage/session/resident-fork-rows.js +3 -3
- package/dist/core/storage/session/session-resume.impl.js +3 -3
- package/dist/core/storage/session/session-resume.js +3 -3
- package/dist/core/storage/session/snapshot-cut.impl.js +3 -3
- package/dist/core/storage/session/snapshot-cut.js +3 -3
- package/dist/core/storage/session/snapshot-history.code.js +4 -4
- package/dist/core/storage/session/snapshot-history.impl.js +3 -3
- package/dist/core/storage/session/snapshot-history.js +3 -3
- package/dist/core/storage/session/sql-session-store.d.ts +13 -4
- package/dist/core/storage/session/sql-session-store.impl.js +3 -3
- package/dist/core/storage/session/sql-session-store.js +3 -3
- package/dist/core/storage/session/tree-outline.impl.js +3 -3
- package/dist/core/storage/session/tree-outline.js +3 -3
- package/dist/core/storage/session/tree-presentation.code.js +1 -1
- package/dist/core/storage/session/tree-presentation.impl.js +3 -3
- package/dist/core/storage/session/tree-presentation.js +3 -3
- package/dist/core/storage/session/types.d.ts +20 -2
- package/dist/core/storage/sqlite-facade.js +14 -13
- package/dist/core/storage/sqlite-facade.js.map +1 -1
- package/dist/core/storage/storage-status.impl.js +3 -3
- package/dist/core/storage/storage-status.js +3 -3
- package/dist/core/storage/team.impl.js +3 -3
- package/dist/core/storage/team.js +3 -3
- package/dist/core/structured-output/index.impl.js +3 -3
- package/dist/core/structured-output/index.js +3 -3
- package/dist/core/tasks/heartbeat.d.ts +1 -0
- package/dist/core/tasks/task-completion-entry.code.js +1 -1
- package/dist/core/tasks/task-completion-entry.impl.js +3 -3
- package/dist/core/tasks/task-completion-entry.js +3 -3
- package/dist/core/tasks/task-file-history.code.js +3 -3
- package/dist/core/tasks/task-file-history.impl.js +3 -3
- package/dist/core/tasks/task-file-history.js +3 -3
- package/dist/core/tasks/task-reference-archive.code.js +3 -3
- package/dist/core/tasks/task-reference-archive.js +3 -3
- package/dist/core/tasks/task-reference-identity.js +3 -3
- package/dist/core/tasks/task-reference-stream.impl.js +3 -3
- package/dist/core/tasks/task-reference-stream.js +3 -3
- package/dist/core/tasks/task-unsaved-answer.impl.js +3 -3
- package/dist/core/tasks/task-unsaved-answer.js +3 -3
- package/dist/core/tasks/task-view-source.impl.js +3 -3
- package/dist/core/tasks/task-view-source.js +3 -3
- package/dist/core/tools/ask-user-question/ask-user-question.d.ts +1 -1
- package/dist/core/tools/history-session.d.ts +2 -0
- package/dist/core/tools/read-url.code.js +3 -3
- package/dist/core/tools/read-url.impl.js +3 -3
- package/dist/core/tools/read-url.js +3 -3
- package/dist/core/worktree-snapshot/blob-store.js +5 -6
- package/dist/core/worktree-snapshot/blob-store.js.map +1 -1
- package/dist/core/worktree-snapshot/errors.code.js +3 -3
- package/dist/core/worktree-snapshot/errors.impl.js +3 -3
- package/dist/core/worktree-snapshot/errors.js +3 -3
- package/dist/core/worktree-snapshot/git.d.ts +2 -0
- package/dist/core/worktree-snapshot/session-index-reset.impl.js +3 -3
- package/dist/core/worktree-snapshot/session-index-reset.js +3 -3
- package/dist/extensions/codemode/execute.code.js +6 -5
- package/dist/extensions/codemode/execute.code.js.map +1 -1
- package/dist/extensions/codemode/execute.impl.js +3 -3
- package/dist/extensions/codemode/execute.js +3 -3
- package/dist/extensions/codemode/renderer.code.js +1 -1
- package/dist/extensions/codemode/renderer.impl.js +3 -3
- package/dist/extensions/codemode/renderer.js +3 -3
- package/dist/extensions/mcp/cli.code.js +8 -4
- package/dist/extensions/mcp/cli.code.js.map +1 -1
- package/dist/extensions/mcp/cli.impl.js +3 -3
- package/dist/extensions/mcp/cli.js +3 -3
- package/dist/extensions/mcp/cli.lazy.code.js +2 -2
- package/dist/extensions/mcp/cli.lazy.impl.js +3 -3
- package/dist/extensions/mcp/cli.lazy.js +3 -3
- package/dist/extensions/mcp/runtime.impl.js +3 -3
- package/dist/extensions/mcp/runtime.js +3 -3
- package/dist/index.js +6 -6
- package/dist/main-first-time-setup.code.js +2 -2
- package/dist/main-first-time-setup.impl.js +3 -3
- package/dist/main-first-time-setup.js +3 -3
- package/dist/modes/interactive/components/stored-tree-view.code.js +3 -3
- package/dist/modes/interactive/components/stored-tree-view.impl.js +3 -3
- package/dist/modes/interactive/components/stored-tree-view.js +3 -3
- package/dist/modes/interactive/components/user-message-selector-archive.code.js +1 -1
- package/dist/modes/interactive/components/user-message-selector-archive.impl.js +3 -3
- package/dist/modes/interactive/components/user-message-selector-archive.js +3 -3
- package/dist/modes/interactive/startup-shell-eligibility.js +1 -1
- package/dist/package-manager-cli.code.js +7 -7
- package/dist/package-manager-cli.impl.js +3 -3
- package/dist/package-manager-cli.js +3 -3
- package/dist/rpc-entry.js +1 -1
- package/dist/startup-files.json +1 -1
- package/dist/startup-stages/10.js +1 -1
- package/dist/startup-stages/11.js +1 -1
- package/dist/startup-stages/12.js +1 -1
- package/dist/startup-stages/13.js +1 -0
- package/dist/startup-stages/2.js +2 -6
- package/dist/startup-stages/3.js +6 -1
- package/dist/startup-stages/4.js +1 -1
- package/dist/startup-stages/5.js +12 -1
- package/dist/startup-stages/6.js +8 -4
- package/dist/startup-stages/7.js +4 -3
- package/dist/startup-stages/8.js +1 -5
- package/dist/startup-stages/9.js +5 -1
- package/dist/startup-stages/stages.json +1 -1
- package/dist/utils/startup-database-spare.code.js +3 -3
- package/dist/utils/startup-database-spare.impl.js +3 -3
- package/dist/utils/startup-database-spare.js +3 -3
- package/dist/utils/tools-manager.code.js +1 -1
- package/dist/utils/tools-manager.impl.js +3 -3
- package/dist/utils/tools-manager.js +3 -3
- package/dist/utils/windows-cwd.js +3 -3
- package/dist/utils/windows-cwd.js.map +1 -1
- package/docs/changelog.mdx +2 -10
- package/docs/codemode.md +5 -2
- package/docs/compaction/branch-summaries.md +1 -1
- package/docs/compaction/custom-compactors.md +1 -1
- package/docs/custom-provider/api-reference.md +1 -1
- package/docs/custom-provider/registration.md +3 -0
- package/docs/custom-provider/streaming.md +1 -1
- package/docs/environment-variables.md +2 -2
- package/docs/guides/resume-on-any-machine.md +1 -0
- package/docs/libraries/ai.md +4 -2
- package/docs/libraries/codemode.md +1 -1
- package/docs/models/choose-a-model.md +1 -1
- package/docs/models-configuration.md +5 -2
- package/docs/models.md +32 -0
- package/docs/providers.md +33 -1
- package/docs/sdk/structured-decisions.md +4 -2
- package/docs/sessions.md +1 -1
- package/docs/settings.md +78 -16
- package/docs/storage/postgres/tuning.md +1 -0
- package/docs/subagents/reference.md +2 -1
- package/docs/tools.md +4 -3
- package/docs/worktree-snapshots/reference.md +2 -0
- package/docs/worktree-snapshots.md +4 -0
- package/package.json +9 -9
- package/schemas/models.schema.json +21 -0
- package/schemas/settings.schema.json +14 -1
- package/dist/_shared/p1b-elig-TVB5CBLL.js.map +0 -1
- package/dist/_shared/startup-0-0-Q3MWKUK4.js.map +0 -1
- package/dist/_shared/startup-0-1-M6OWAYHH.js.map +0 -1
- package/dist/_shared/startup-0-2-2HUMCPKX.js.map +0 -1
- package/dist/_shared/startup-0-3-4ZYBYQNM.js.map +0 -1
- package/dist/_shared/startup-0-5-YDW47QX6.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-sqlite-file-gate.js","sourceRoot":"","sources":["../../../src/core/storage/node-sqlite-file-gate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAuB5C;;;;;;;GAOG;AACH,MAAM,IAAI,GAAG,CAAC,CAAC;AACf,MAAM,MAAM,GAAG,CAAC,CAAC;AAuBjB,+FAA+F;AAC/F,SAAS,eAAe,CAAC,UAAwB;IAChD,OAAO;QACN,QAAQ,EAAE,MAAM,CAAC,iBAAiB;QAClC,KAAK,EAAE,SAAS;QAChB,UAAU;QACV,MAAM,EAAE,GAAG,EAAE,CAAC,KAAK;QACnB,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;KACd,CAAC;AACH,CAAC;AA8CD,6EAA6E;AAC7E,MAAM,SAAS,GAAG,CAAC,IAAI,EAAE,CAAC;AAE1B,wHAAwH;AACxH,gGAAgG;AAChG,MAAM,QAAQ,GAAG,MAAM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M,MAAM,GAA4B,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,oBAAoB,EAAE,CAAC;IACrF,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAC/F,CAAC","sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\nimport { createRequire } from \"node:module\";\nimport type { DatabaseSync, SQLInputValue, StatementSync } from \"node:sqlite\";\n\n/**\n * A connection on a thread of its own taking or holding a file's write lock: open from the moment it sends\n * `BEGIN IMMEDIATE` until it learns that the attempt was refused or failed, or until its transaction let go of the\n * lock. Only a `scoped` hold, one opened while the process had a wrapped connection to the file, makes wrapped calls\n * wait: its transaction's callback runs in its asynchronous context (`runInHold`), so calls made inside it are told\n * apart. A process that wraps no connection to the file never enters that context, and wrapped calls made while an\n * unscoped hold is open run at once, as they always have.\n */\nexport interface FileHold {\n\treadonly file: string;\n\treadonly scoped: boolean;\n\topen: boolean;\n}\n\n/** The holds whose transaction callbacks an asynchronous context runs in, innermost first. */\nexport interface HoldScope {\n\treadonly hold: FileHold;\n\treadonly outer: HoldScope | undefined;\n}\n\n/**\n * What the process's connections to one file are doing with its write lock, in one `Int32` they all share: `FREE`, a\n * statement of the calling thread running (`CALLER`), or a connection on a thread of its own taking it (`tag * 4 + 2`)\n * or holding it (`tag * 4 + 3`), by its `tag`. That thread moves it with compare-and-exchange as SQLite takes and lets\n * go of the lock: it takes the word before `BEGIN IMMEDIATE`, and gives it back once its transaction ended, before it\n * answers. A statement of the calling thread runs only while it has the word itself (`runAdmitted`), so neither can\n * take the lock from under the other.\n */\nconst FREE = 0;\nconst CALLER = 1;\n\n/** A threaded connection's share of its file's word: the word, its tag, and how to stop using it. */\nexport interface FileLock {\n\treadonly buffer: SharedArrayBuffer;\n\treadonly tag: number;\n\t/** Gives the word back if this connection still takes or holds it, as when its thread exited. */\n\tclear(): void;\n\t/** This connection no longer uses the word; the file's word goes once no connection does. */\n\trelease(): void;\n}\n\n/** A call waiting for its turn; one decided only at its turn (see `runDeferred`) is armed then. */\ninterface Waiter {\n\tdeadline: number;\n\ttimer: ReturnType<typeof setTimeout> | undefined;\n\t/** The connection the call runs on: later calls on it wait behind this one (see `runDeferred`). */\n\treadonly connection: DatabaseSync;\n\t/** Runs the call if it can run now; whether it did. */\n\ttryRun: () => boolean;\n\tfail: () => void;\n}\n\n/** A waiter for a call on `connection` that is decided at its turn: no deadline until then. */\nfunction undecidedWaiter(connection: DatabaseSync): Waiter {\n\treturn {\n\t\tdeadline: Number.POSITIVE_INFINITY,\n\t\ttimer: undefined,\n\t\tconnection,\n\t\ttryRun: () => false,\n\t\tfail: () => {},\n\t};\n}\n\n/** Statements a calling-thread connection prepared to decide how its calls run while the file is held; see `modeOf`. */\ninterface Plans {\n\treadonly explained: Map<string, StatementSync>;\n\tbusyTimeout?: StatementSync;\n\t/** Whether the file is in WAL mode; see `inWriteAheadLog`. */\n\twriteAheadLog?: boolean;\n\t/** Whether the connection lets its busy timeout be set; see `triesAllowed`. */\n\ttimeoutSettable?: boolean;\n}\n\n/**\n * One file's open holds, the calls waiting to run, and what those calls' connections prepared meanwhile, by the\n * object that owns each connection (not the connection, which its own statements keep alive), so they are kept no\n * longer than it is.\n */\nexport interface FileGate {\n\treadonly holds: Set<FileHold>;\n\treadonly waiters: Waiter[];\n\treadonly plans: WeakMap<object, Plans>;\n\twatching: boolean;\n\t/** A call ran on this file in the current turn of the event loop; the next one waits for the next turn. */\n\tpaced: boolean;\n\tpumping: boolean;\n\tpolling: boolean;\n}\n\ninterface Registry {\n\treadonly files: Map<string, FileGate>;\n\treadonly words: Map<string, FileWord>;\n\treadonly scopes: AsyncLocalStorage<HoldScope | undefined>;\n\t/** Wrapped connections to each file that are open: closed ones, and ones collected unclosed, no longer count. */\n\treadonly wrapped: Map<string, number>;\n\treadonly collected: FinalizationRegistry<{ readonly release: () => void }>;\n\t/** Connections that refused their busy timeout back after a try: never tried first again (see `attemptOnce`). */\n\treadonly untried: WeakSet<DatabaseSync>;\n}\n\n/** One file's word and the tags of the connections that use it. */\ninterface FileWord {\n\treadonly state: Int32Array;\n\treadonly tags: Set<number>;\n\tlastTag: number;\n}\n\n/** Tags stay below this, so a mark (`tag * 4 + 3`) is a positive `Int32`. */\nconst TAG_LIMIT = 2 ** 28;\n\n// Shared across module copies, as the transaction gates are: a copy that runs a transaction's callback and a copy whose\n// wrapped connection is called from it must see the same holds, words and asynchronous context.\nconst REGISTRY = Symbol.for(\"atomic-storage/node-sqlite-file-holds@1\");\nconst registryBag = globalThis as typeof globalThis & Record<symbol, Registry | undefined>;\nconst registry: Registry = registryBag[REGISTRY] ?? {\n\tfiles: new Map(),\n\twords: new Map(),\n\tscopes: new AsyncLocalStorage(),\n\twrapped: new Map(),\n\tcollected: new FinalizationRegistry((use) => use.release()),\n\tuntried: new WeakSet(),\n};\nregistryBag[REGISTRY] = registry;\n\n/** A threaded connection to `file` starts using the file's word (see `FREE`). */\nexport function useFileLock(file: string): FileLock {\n\tlet word = registry.words.get(file);\n\tif (word === undefined) {\n\t\tword = {\n\t\t\tstate: new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)),\n\t\t\ttags: new Set(),\n\t\t\tlastTag: 0,\n\t\t};\n\t\tregistry.words.set(file, word);\n\t}\n\t// The next tag no connection to the file uses, from 1 up, wrapping before the marks would leave the Int32 range.\n\tlet tag = word.lastTag;\n\tdo tag = (tag % (TAG_LIMIT - 1)) + 1;\n\twhile (word.tags.has(tag));\n\tword.lastTag = tag;\n\tword.tags.add(tag);\n\tconst { state, tags } = word;\n\tlet released = false;\n\treturn {\n\t\tbuffer: state.buffer as SharedArrayBuffer,\n\t\ttag,\n\t\tclear: () => {\n\t\t\tif (\n\t\t\t\tAtomics.compareExchange(state, 0, tag * 4 + 3, FREE) === tag * 4 + 3 ||\n\t\t\t\tAtomics.compareExchange(state, 0, tag * 4 + 2, FREE) === tag * 4 + 2\n\t\t\t)\n\t\t\t\tAtomics.notify(state, 0);\n\t\t},\n\t\trelease: () => {\n\t\t\tif (released) return;\n\t\t\treleased = true;\n\t\t\ttags.delete(tag);\n\t\t\tif (tags.size === 0 && registry.words.get(file)?.tags === tags) registry.words.delete(file);\n\t\t},\n\t};\n}\n\n/**\n * Runs `call`, a statement of the calling thread, if the file's word is free, holding the word while it runs, which is\n * synchronous; undefined, running nothing, if a threaded connection takes or holds the lock.\n */\nfunction runAdmitted<T>(state: Int32Array, call: () => Promise<T>): Promise<T> | undefined {\n\tif (Atomics.compareExchange(state, 0, FREE, CALLER) !== FREE) return undefined;\n\ttry {\n\t\treturn call();\n\t} finally {\n\t\tAtomics.store(state, 0, FREE);\n\t\tAtomics.notify(state, 0);\n\t}\n}\n\n/**\n * A wrapped connection, `owner`, to `file` counts as open until `release` or until `owner` is collected, whichever\n * comes first; see `FileHold`.\n */\nexport function useWrappedFile(file: string, owner: object): { release(): void } {\n\tregistry.wrapped.set(file, (registry.wrapped.get(file) ?? 0) + 1);\n\tlet released = false;\n\tconst use = {\n\t\trelease: () => {\n\t\t\tif (released) return;\n\t\t\treleased = true;\n\t\t\tconst count = (registry.wrapped.get(file) ?? 1) - 1;\n\t\t\tif (count > 0) registry.wrapped.set(file, count);\n\t\t\telse registry.wrapped.delete(file);\n\t\t},\n\t};\n\tregistry.collected.register(owner, use, use);\n\treturn {\n\t\trelease: () => {\n\t\t\tregistry.collected.unregister(use);\n\t\t\tuse.release();\n\t\t},\n\t};\n}\n\n/** Opens a hold on `file`, identified as `fileIdentity` identifies it, scoped if a wrapped connection to it is open. */\nexport function holdFile(file: string): FileHold {\n\tlet gate = registry.files.get(file);\n\tif (gate === undefined) {\n\t\tgate = {\n\t\t\tholds: new Set(),\n\t\t\twaiters: [],\n\t\t\tplans: new WeakMap(),\n\t\t\twatching: false,\n\t\t\tpaced: false,\n\t\t\tpumping: false,\n\t\t\tpolling: false,\n\t\t};\n\t\tregistry.files.set(file, gate);\n\t}\n\tconst hold: FileHold = { file, scoped: registry.wrapped.has(file), open: true };\n\tgate.holds.add(hold);\n\treturn hold;\n}\n\n/** Whether a scoped hold of the gate's file is open. */\nfunction scopedHoldOpen(gate: FileGate): boolean {\n\tfor (const hold of gate.holds) if (hold.scoped) return true;\n\treturn false;\n}\n\n/**\n * Closes `hold`, once. When it was the file's last, the oldest call waiting for the file runs now, if the word is free\n * and no call ran in this turn; the others follow one per turn (see `runNextWaiter`).\n */\nexport function releaseHold(hold: FileHold | undefined): void {\n\tif (hold === undefined || !hold.open) return;\n\thold.open = false;\n\tconst gate = registry.files.get(hold.file);\n\tif (gate === undefined) return;\n\tgate.holds.delete(hold);\n\tif (!scopedHoldOpen(gate)) runNextWaiter(hold.file, gate);\n\tforgetIfIdle(hold.file, gate);\n}\n\n/**\n * Runs the oldest waiting call if the word is free and no call ran on the file in this turn of the event loop, and\n * schedules the next one for the next turn: calls that queued up behind a long transaction run one per turn, so none\n * of them holds the event loop for the time of all of them. A call that finds the word taken waits again, still under\n * its own deadline.\n */\nfunction runNextWaiter(file: string, gate: FileGate): void {\n\tif (gate.paced || gate.waiters.length === 0) return;\n\tconst waiter = gate.waiters[0]!;\n\tif (!waiter.tryRun()) {\n\t\tfailOverdue(file, gate);\n\t\treturn;\n\t}\n\tgate.waiters.shift();\n\tclearTimeout(waiter.timer);\n\tranThisTurn(file, gate);\n}\n\n/**\n * The oldest call could not run: calls waiting past their deadline fail now, having run nothing (or refused, see\n * `runTryingFirst`); the others keep their place.\n */\nfunction failOverdue(file: string, gate: FileGate): void {\n\tconst now = performance.now();\n\tconst overdue = gate.waiters.filter((waiting) => now >= waiting.deadline);\n\tfor (const waiter of overdue) {\n\t\tgate.waiters.splice(gate.waiters.indexOf(waiter), 1);\n\t\tclearTimeout(waiter.timer);\n\t\twaiter.fail();\n\t}\n\t// The calls behind them get their turn.\n\tif (overdue.length > 0) ranThisTurn(file, gate);\n}\n\n/** Notes that a call ran on the file in this turn; the next waiting one gets the next turn. */\nfunction ranThisTurn(file: string, gate: FileGate): void {\n\tgate.paced = true;\n\tif (gate.pumping) return;\n\tgate.pumping = true;\n\tsetImmediate(() => {\n\t\tgate.pumping = false;\n\t\tgate.paced = false;\n\t\tconst state = registry.words.get(file)?.state;\n\t\trunNextWaiter(file, gate);\n\t\tif (state !== undefined) watchWord(file, gate, state);\n\t\tforgetIfIdle(file, gate);\n\t});\n}\n\nfunction forgetIfIdle(file: string, gate: FileGate): void {\n\tif (\n\t\tgate.holds.size === 0 &&\n\t\tgate.waiters.length === 0 &&\n\t\t!gate.pumping &&\n\t\t!gate.polling &&\n\t\tregistry.files.get(file) === gate\n\t)\n\t\tregistry.files.delete(file);\n}\n\n/**\n * Runs a transaction's callback inside the transaction callbacks it was requested in (`scope`, captured when it was\n * requested, since a group commit runs it from another's request) and inside its own hold, so calls it makes can be\n * told apart.\n */\nexport function runInHold<T>(hold: FileHold | undefined, scope: HoldScope | undefined, callback: () => T): T {\n\tconst store = hold?.scoped === true ? { hold, outer: scope } : scope;\n\t// Nothing to change, as always for a process that wraps no connection to a file: no context is entered.\n\tif (store === registry.scopes.getStore()) return callback();\n\treturn registry.scopes.run(store, callback);\n}\n\n/** The holds whose callbacks the caller runs in; captured when a call is made, not when it runs. */\nexport function currentHoldScope(): HoldScope | undefined {\n\treturn registry.scopes.getStore();\n}\n\n/**\n * Whether a call made now on a wrapped connection to `file` comes in behind a transaction: a scoped hold is open or\n * calls wait for their turn. Read when the call is made; one made once that is over runs as it always has, however\n * busy the file was before.\n */\nexport function inBacklog(file: string): boolean {\n\tconst gate = registry.files.get(file);\n\treturn gate !== undefined && (scopedHoldOpen(gate) || gate.waiters.length > 0);\n}\n\n/**\n * The gate of `file` when another context holds it open: some hold is open, and none of the callbacks `scope` runs in\n * belongs to an open hold of it. A call made inside an open hold's own callback cannot wait for it, since the\n * transaction waits for the call: it runs at once, as it always has. A call made in the backlog of a transaction\n * (`backlog`, see `inBacklog`) also takes its turn behind the calls queued before it, one per turn.\n */\nexport function heldElsewhere(file: string, scope: HoldScope | undefined, backlog: boolean): FileGate | undefined {\n\tconst gate = registry.files.get(file);\n\tif (gate === undefined || (!scopedHoldOpen(gate) && gate.waiters.length === 0 && !(gate.paced && backlog)))\n\t\treturn undefined;\n\tfor (let inner = scope; inner !== undefined; inner = inner.outer) {\n\t\tif (inner.hold.open && inner.hold.file === file) return undefined;\n\t}\n\treturn gate;\n}\n\n/**\n * Runs `run` as soon as the file's word is free: at once if it is, as SQLite's busy handler would find the lock free;\n * otherwise once a threaded connection gives the word back, or the file's last hold closes. Fails it with `busy()`,\n * having run nothing, if the word is still taken at the end of the busy timeout of `database`, which `owner` owns\n * (read only when the call has to wait). When that cannot be read, `run` runs at once, as it always has.\n */\nexport function runWhenFree<T>(\n\tfile: string,\n\tgate: FileGate,\n\towner: object,\n\tdatabase: DatabaseSync,\n\trun: () => Promise<T>,\n\tbusy: () => Error,\n): Promise<T> {\n\tconst state = registry.words.get(file)?.state;\n\tif (state === undefined) return run();\n\t// Calls already waiting go first, and one runs per turn.\n\trunNextWaiter(file, gate);\n\tconst now = gate.waiters.length === 0 && !gate.paced ? runAdmitted(state, run) : undefined;\n\tif (now !== undefined) {\n\t\tranThisTurn(file, gate);\n\t\treturn now;\n\t}\n\tconst timeoutMs = busyTimeoutOf(gate, owner, database);\n\tif (timeoutMs === undefined) return run();\n\treturn new Promise<T>((resolve, reject) => {\n\t\tconst waiter = undecidedWaiter(database);\n\t\tgate.waiters.push(waiter);\n\t\tarmWhenFree(file, gate, waiter, state, timeoutMs, run, resolve, reject, busy);\n\t});\n}\n\n/** Makes `waiter` run `run` once the word is free, for `runWhenFree`. */\nfunction armWhenFree<T>(\n\tfile: string,\n\tgate: FileGate,\n\twaiter: Waiter,\n\tstate: Int32Array,\n\ttimeoutMs: number,\n\trun: () => Promise<T>,\n\tresolve: (value: T | PromiseLike<T>) => void,\n\treject: (error: unknown) => void,\n\tbusy: () => Error,\n): void {\n\twaiter.deadline = performance.now() + timeoutMs;\n\t// Decided once the event loop handled what it already received, such as the exit of a connection's thread, which\n\t// a timer runs ahead of. At its deadline it fails if the word is taken. While the word is free it keeps its place:\n\t// a free lock is never reported busy, and its turn comes (see `runNextWaiter`), so its busy timeout bounds how long\n\t// it waits for the lock, not for its turn.\n\twaiter.timer = setTimeout(\n\t\t() =>\n\t\t\tsetImmediate(() => {\n\t\t\t\tconst index = gate.waiters.indexOf(waiter);\n\t\t\t\tif (index === -1 || Atomics.load(state, 0) === FREE) return;\n\t\t\t\tgate.waiters.splice(index, 1);\n\t\t\t\twaiter.fail();\n\t\t\t\tranThisTurn(file, gate);\n\t\t\t\tforgetIfIdle(file, gate);\n\t\t\t}),\n\t\ttimeoutMs,\n\t);\n\twaiter.tryRun = () => {\n\t\tconst ran = runAdmitted(state, run);\n\t\tif (ran === undefined) return false;\n\t\tresolve(ran);\n\t\treturn true;\n\t};\n\twaiter.fail = () => reject(busy());\n\twatchWord(file, gate, state);\n}\n\n/**\n * Wakes the gate's waiting calls whenever the file's word changes, so a call runs the moment a threaded connection\n * gives the lock back, before its answer reaches this thread. One watch per gate, for as long as calls wait.\n */\nfunction watchWord(file: string, gate: FileGate, state: Int32Array): void {\n\tfor (;;) {\n\t\tif (gate.watching || gate.waiters.length === 0) return;\n\t\tconst observed = Atomics.load(state, 0);\n\t\t// Freed since the caller found it taken: run what waits now rather than wait for a change that already came.\n\t\tif (observed === FREE) {\n\t\t\t// Free: the oldest runs now or at the next turn (see `runNextWaiter`); nothing to watch for until then.\n\t\t\trunNextWaiter(file, gate);\n\t\t\tforgetIfIdle(file, gate);\n\t\t\t// Ran, or was refused a lock the word does not announce (another process's), which `pollWaiters` tries again.\n\t\t\tif (gate.paced || Atomics.load(state, 0) === FREE) return;\n\t\t\tcontinue;\n\t\t}\n\t\t// Until the last deadline: each waiter's own timer decides at its deadline, so a watch never runs past it.\n\t\t// Calls not decided yet (see `runDeferred`) need no watch: they are decided in their turn, whatever the word.\n\t\tconst deadlines = gate.waiters.map((waiter) => waiter.deadline).filter(Number.isFinite);\n\t\tconst untilMs = Math.max(...deadlines) - performance.now();\n\t\tif (deadlines.length === 0 || untilMs <= 0) return;\n\t\tconst result = Atomics.waitAsync(state, 0, observed, untilMs);\n\t\tif (!result.async) {\n\t\t\tif (result.value === \"not-equal\") continue;\n\t\t\treturn;\n\t\t}\n\t\tgate.watching = true;\n\t\tvoid result.value.then(() => {\n\t\t\tgate.watching = false;\n\t\t\trunNextWaiter(file, gate);\n\t\t\tforgetIfIdle(file, gate);\n\t\t\twatchWord(file, gate, state);\n\t\t});\n\t\treturn;\n\t}\n}\n\n/** Most plans one connection keeps while a file is held. */\nconst MAX_PLANS = 32;\n\nfunction plansOf(gate: FileGate, owner: object): Plans {\n\tlet plans = gate.plans.get(owner);\n\tif (plans === undefined) {\n\t\tplans = { explained: new Map() };\n\t\tgate.plans.set(owner, plans);\n\t}\n\treturn plans;\n}\n\n/** Drops what the connection of `owner` prepared while `file` was held, as it closes. */\nexport function forgetPlans(file: string, owner: object): void {\n\tregistry.files.get(file)?.plans.delete(owner);\n}\n\n/** The busy timeout `database` waits for a lock now, in milliseconds; undefined when it cannot be read. */\nfunction busyTimeoutOf(gate: FileGate, owner: object, database: DatabaseSync): number | undefined {\n\tconst plans = plansOf(gate, owner);\n\ttry {\n\t\tplans.busyTimeout ??= database.prepare(\"PRAGMA busy_timeout\");\n\t\tconst timeout = Number(plans.busyTimeout.get()?.timeout);\n\t\treturn Number.isFinite(timeout) && timeout >= 0 ? timeout : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** A blank or a comment, which SQLite skips between words. */\nconst GAP = String.raw`(?:\\s|--[^\\n]*(?:\\n|$)|\\/\\*[\\s\\S]*?\\*\\/)`;\n/** What SQLite skips before a statement's first word: blanks, comments and empty statements. */\nconst LEADING = new RegExp(`^(?:${GAP}|;)*`);\n/**\n * A PRAGMA, alone or under EXPLAIN or EXPLAIN QUERY PLAN (on text without what `LEADING` matches): SQLite may carry it\n * out while it prepares it, so it is never prepared ahead.\n */\nconst PRAGMA_STATEMENT = new RegExp(`^(?:EXPLAIN${GAP}+(?:QUERY${GAP}+PLAN${GAP}+)?)?PRAGMA\\\\b`, \"i\");\n/** A name as SQLite reads it, bare or quoted, with its quotes. */\nconst NAME = String.raw`(?:\\w+|\"(?:[^\"]|\"\")*\"|'(?:[^']|'')*'|\\[[^\\]]*\\]|` + \"`(?:[^`]|``)*`)\";\n/**\n * A PRAGMA's name, past an optional EXPLAIN or EXPLAIN QUERY PLAN, `PRAGMA` and an optional schema (`schema.`), on text\n * without what `LEADING` matches.\n */\nconst PRAGMA_NAME = new RegExp(\n\t`^(EXPLAIN${GAP}+(?:QUERY${GAP}+PLAN${GAP}+)?)?PRAGMA${GAP}+(?:(${NAME})${GAP}*\\\\.${GAP}*)?(${NAME})`,\n\t\"i\",\n);\n/** A name without its quotes, in lower case. */\nfunction unquoted(name: string): string {\n\tconst quote = name[0];\n\tif (quote === '\"' || quote === \"'\" || quote === \"`\")\n\t\treturn name.slice(1, -1).replaceAll(`${quote}${quote}`, quote).toLowerCase();\n\tif (quote === \"[\") return name.slice(1, -1).toLowerCase();\n\treturn name.toLowerCase();\n}\n\n/**\n * PRAGMAs that write the file and are tried first: SQLite refuses each in its opening steps, before it changed\n * anything. Every other PRAGMA runs as it always has: one that reads or sets a setting of the connection or another\n * database needs no lock of the file in WAL mode, and runs at once anyway; and ones a try would change are among them:\n * those of the busy timeout, which the try sets, also under EXPLAIN, since SQLite sets it while it prepares the\n * statement; setters that change something before they meet the lock (`journal_mode`, `default_cache_size`,\n * `auto_vacuum`, and the ones that apply to every attached database when no schema is named); checks that run the\n * application's functions in the schema's constraints (`integrity_check`, `quick_check`); and ones that answer\n * differently when refused the lock at once (a checkpoint that waits, `optimize`).\n */\nconst TRIED_PRAGMAS = new Set([\"user_version\", \"application_id\", \"schema_version\", \"incremental_vacuum\"]);\n\n/** Whether a PRAGMA (on text without what `LEADING` matches) is tried first; see `TRIED_PRAGMAS`. */\nfunction pragmaTriedFirst(statement: string): boolean {\n\tconst match = PRAGMA_NAME.exec(statement);\n\tif (match === null) return false;\n\tconst [, explain, schema, name = \"\"] = match;\n\treturn (\n\t\texplain === undefined &&\n\t\t(schema === undefined || unquoted(schema) === \"main\") &&\n\t\tTRIED_PRAGMAS.has(unquoted(name))\n\t);\n}\n\n/**\n * Built-in functions a try cannot run safely: ones that read the connection's change counters, which a refused try\n * changes; `load_extension`, which runs an extension's code; and `sqlite_attach` (ATTACH), which reads another file\n * with its own locks.\n */\nconst UNSAFE_FUNCTIONS = new Set([\"changes\", \"total_changes\", \"last_insert_rowid\", \"load_extension\", \"sqlite_attach\"]);\n/** Steps of a plan that call a function or an aggregate, named in their P4 as `name(arguments)`. */\nconst FUNCTION_STEPS = new Set([\n\t\"Function\",\n\t\"Function0\",\n\t\"PureFunc\",\n\t\"PureFunc0\",\n\t\"AggStep\",\n\t\"AggStep0\",\n\t\"AggStep1\",\n\t\"AggFinal\",\n\t\"AggValue\",\n\t\"AggInverse\",\n]);\n/** The collating sequences SQLite builds in; `B` is how a plan's key lists `BINARY`. */\nconst BUILT_IN_COLLATIONS = new Set([\"\", \"B\", \"BINARY\", \"NOCASE\", \"RTRIM\"]);\n/** Steps of a plan that compare with a collating sequence named in their P4 as `name-encoding`. */\nconst COLLATING_STEPS = new Set([\"CollSeq\", \"Eq\", \"Ne\", \"Lt\", \"Le\", \"Gt\", \"Ge\"]);\nconst COLLATION = /^(.*)-(?:8|16le|16be|16)$/;\n/** A plan's key, `k(fields,collation,…)`, each collation after its `-` (descending) and `N.` (nulls last) marks. */\nconst KEY = /^k\\(\\d+((?:,[^,)]*)*)\\)$/;\n\n/** Whether a step of a plan compares with a collating sequence SQLite does not build in, an extension's code. */\nfunction usesOtherCollation(opcode: string, p4: string): boolean {\n\tconst key = KEY.exec(p4);\n\tif (key !== null)\n\t\treturn key[1]!\n\t\t\t.split(\",\")\n\t\t\t.slice(1)\n\t\t\t.some((field) => !BUILT_IN_COLLATIONS.has(field.replace(/^-?(?:N\\.)?/, \"\")));\n\tif (!COLLATING_STEPS.has(opcode)) return false;\n\tconst name = COLLATION.exec(p4)?.[1];\n\treturn name !== undefined && !BUILT_IN_COLLATIONS.has(name);\n}\n\n/** A VACUUM, which may create the file it writes into before it is refused. */\nconst VACUUM_STATEMENT = /^VACUUM\\b/i;\n/** `UNSAFE_FUNCTIONS` but `sqlite_attach`, whose statement, ATTACH, names it otherwise. */\nconst UNSAFE_NAMES = [\"changes\", \"total_changes\", \"last_insert_rowid\", \"load_extension\"];\n/** An INSERT, UPDATE or DELETE, possibly after a WITH clause: listing its plan resets `changes()`. */\nconst CHANGING_STATEMENT = /^(?:INSERT|REPLACE|UPDATE|DELETE|WITH)\\b/i;\n/**\n * Whether a name starts with the UTF-16 code unit `code`: a letter, `_`, or any character past ASCII, which SQLite reads\n * as part of a name (both halves of a surrogate pair, and a lone one, are past ASCII).\n */\nfunction startsName(code: number): boolean {\n\treturn code >= 0x80 || code === 0x5f || (code >= 0x41 && code <= 0x5a) || (code >= 0x61 && code <= 0x7a);\n}\n\n/** Whether a bare name goes on with the UTF-16 code unit `code`: what starts one, a digit, or `$`. */\nfunction continuesName(code: number): boolean {\n\treturn startsName(code) || (code >= 0x30 && code <= 0x39) || code === 0x24;\n}\n\n/**\n * Where a string literal or a quoted name that opens with `quote` at `start` ends, past its closing quote, or -1 when\n * no quote after `start` closes it. A doubled quote stands for the quote itself; when the text ends inside, the first\n * quote of the last doubled one closes it.\n */\nfunction quotedEnd(sql: string, start: number, quote: string): number {\n\tlet lastDoubled = -1;\n\tfor (let from = start + 1; ; ) {\n\t\tconst at = sql.indexOf(quote, from);\n\t\tif (at === -1) return lastDoubled === -1 ? -1 : lastDoubled + 1;\n\t\tif (sql[at + 1] !== quote) return at + 1;\n\t\tlastDoubled = at;\n\t\tfrom = at + 2;\n\t}\n}\n\n/**\n * The names `sql` uses, bare or quoted (`\"…\"`, `[…]`, `` `…` ``), in lower case: outside its string literals and\n * comments, in one pass over the text. A quote or `[` that nothing closes counts as a character of its own, and the\n * text after it is read as usual.\n */\nfunction namesIn(sql: string): Set<string> {\n\tconst names = new Set<string>();\n\t// A `[` after the last `]` closes no name: knowing it at once keeps each such `[` from reading to the end again.\n\tconst lastBracket = sql.lastIndexOf(\"]\");\n\tfor (let index = 0; index < sql.length; ) {\n\t\tconst char = sql[index]!;\n\t\tif (char === \"'\" || char === '\"' || char === \"`\") {\n\t\t\tconst end = quotedEnd(sql, index, char);\n\t\t\tif (end === -1) index += 1;\n\t\t\telse {\n\t\t\t\t// A string literal names nothing; a quoted name stands for its text, each doubled quote for one.\n\t\t\t\tif (char !== \"'\") {\n\t\t\t\t\tconst name = sql.slice(index + 1, end - 1).replaceAll(char + char, char);\n\t\t\t\t\tnames.add(name.toLowerCase());\n\t\t\t\t}\n\t\t\t\tindex = end;\n\t\t\t}\n\t\t} else if (char === \"[\") {\n\t\t\tif (index < lastBracket) {\n\t\t\t\tconst end = sql.indexOf(\"]\", index + 1);\n\t\t\t\tnames.add(sql.slice(index + 1, end).toLowerCase());\n\t\t\t\tindex = end + 1;\n\t\t\t} else index += 1;\n\t\t} else if (char === \"-\" && sql[index + 1] === \"-\") {\n\t\t\tconst end = sql.indexOf(\"\\n\", index + 2);\n\t\t\tindex = end === -1 ? sql.length : end;\n\t\t} else if (char === \"/\" && sql[index + 1] === \"*\") {\n\t\t\t// Left open, the comment runs to the end of the text.\n\t\t\tconst end = sql.indexOf(\"*/\", index + 2);\n\t\t\tindex = end === -1 ? sql.length : end + 2;\n\t\t} else if (startsName(sql.charCodeAt(index))) {\n\t\t\tlet end = index + 1;\n\t\t\twhile (end < sql.length && continuesName(sql.charCodeAt(end))) end += 1;\n\t\t\tnames.add(sql.slice(index, end).toLowerCase());\n\t\t\tindex = end;\n\t\t} else index += 1;\n\t}\n\treturn names;\n}\n\n/**\n * Whether `statement` names a function whose result a listing of its plan could change, which resets `changes()`\n * for an INSERT, UPDATE or DELETE: one of `UNSAFE_NAMES`, or, for such a statement, a function SQLite does not build\n * in, which could read the counters itself. When the connection cannot list its functions, every INSERT, UPDATE or\n * DELETE counts.\n */\nfunction namesUnsafeFunction(statement: string, database: DatabaseSync): boolean {\n\tconst names = namesIn(statement);\n\tif (UNSAFE_NAMES.some((name) => names.has(name))) return true;\n\tif (!CHANGING_STATEMENT.test(statement)) return false;\n\tconst userFunctions = functionsNotBuiltIn(database);\n\tif (userFunctions === undefined) return true;\n\tfor (const name of userFunctions) if (names.has(name)) return true;\n\treturn false;\n}\n\n/** The database numbers of a connection's main database, the file itself, and of its temporary database. */\nconst MAIN_DATABASE = 0;\nconst TEMP_DATABASE = 1;\n\n/**\n * How a wrapped call runs while a threaded transaction of this thread holds its file:\n *\n * - `try first`: once at once with a busy timeout of 0 (see `runTryingFirst`), refused the lock, tried again. Only a\n * statement whose plan proves that a refusal comes from its opening steps, before it did anything: the only\n * databases it writes are the file and the temporary one, and the file is in WAL mode, where a commit needs no\n * further lock; it calls no code but SQLite's own (no function or collating sequence SQLite does not build in, no\n * virtual table, no `UNSAFE_FUNCTIONS`); it is no VACUUM, which may create the file it writes into before it is\n * refused. A PRAGMA, which is never prepared ahead since SQLite may carry one out while preparing it, is tried first\n * only if it is one of `TRIED_PRAGMAS`.\n * - `as before`: every other single statement, an `exec` of no statement, and every call while the connection is\n * inside a transaction of its own or the file is not in WAL mode. It runs exactly as it always has, with the\n * connection's own busy timeout.\n * - `script`: an `exec` of more than one statement (see `splitStatements`). It waits until no transaction of this\n * thread holds the lock (see `runWhenFree`), so no part of it runs while the lock is held. An `exec` of exactly one\n * statement runs as that statement.\n *\n * At a busy timeout of 0 every single statement runs as before: it never waits for the lock, and setting the timeout,\n * as a try does, would remove a busy handler an extension installed, which reads as a timeout of 0. A script still\n * waits (for no time), which sets no timeout.\n *\n * The plan of a statement is made once while the file is held and listed again for later calls. Listing the plan of\n * an INSERT, UPDATE or DELETE resets the connection's `changes()`, which the statement's own run sets again; so a\n * statement that names a function that reads the change counters or may (see `namesUnsafeFunction`) runs as before\n * without its plan being listed.\n */\nexport function modeOf(\n\tgate: FileGate,\n\towner: object,\n\tdatabase: DatabaseSync,\n\tsql: string,\n\tparams: readonly SQLInputValue[],\n\tsingle: boolean,\n): \"try first\" | \"as before\" | \"script\" {\n\tif (!single) {\n\t\tconst statements = splitStatements(sql);\n\t\tif (statements.length > 1) return \"script\";\n\t\t// Nothing to run, nor to wait for.\n\t\tif (statements.length === 0) return \"as before\";\n\t\treturn modeOf(gate, owner, database, statements[0]!, params, true);\n\t}\n\tif (busyTimeoutOf(gate, owner, database) === 0) return \"as before\";\n\t// Inside a transaction of its own, a write's upgrade of the connection's read is refused at once, with no busy\n\t// handler, and a try again could succeed or be refused otherwise.\n\tif (\n\t\tdatabase.isTransaction !== false ||\n\t\t!inWriteAheadLog(gate, owner, database) ||\n\t\t!triesAllowed(gate, owner, database)\n\t)\n\t\treturn \"as before\";\n\t// Decided on the text SQLite reads, past the blanks, comments and empty statements it skips.\n\tconst statement = sql.replace(LEADING, \"\");\n\tif (PRAGMA_STATEMENT.test(statement)) return pragmaTriedFirst(statement) ? \"try first\" : \"as before\";\n\t// Decided without its plan: listing the plan of an INSERT, UPDATE or DELETE resets the connection's changes().\n\tif (VACUUM_STATEMENT.test(statement) || namesUnsafeFunction(statement, database)) return \"as before\";\n\tconst steps = planSteps(gate, owner, database, statement, params);\n\treturn steps !== undefined && triesSafely(steps, database) ? \"try first\" : \"as before\";\n}\n\n/**\n * Whether calls on `database`, which `owner` owns, may be tried first: it never refused its busy timeout back after a\n * try, and, checked once while the file is held, before anything is tried, the timeout can be read and set to the\n * value it has. An authorizer you set can refuse either; then every call runs as before, and the timeout is never set.\n */\nfunction triesAllowed(gate: FileGate, owner: object, database: DatabaseSync): boolean {\n\tif (registry.untried.has(database)) return false;\n\tconst plans = plansOf(gate, owner);\n\tif (plans.timeoutSettable === undefined) {\n\t\tconst timeoutMs = busyTimeoutOf(gate, owner, database);\n\t\ttry {\n\t\t\tif (timeoutMs !== undefined) setBusyTimeout(database, timeoutMs);\n\t\t\tplans.timeoutSettable = timeoutMs !== undefined;\n\t\t} catch {\n\t\t\tplans.timeoutSettable = false;\n\t\t}\n\t}\n\treturn plans.timeoutSettable;\n}\n\n/**\n * Whether the file of `database`, which `owner` owns, is in WAL mode, read once while the file is held. A connection\n * of this process on a thread of its own is open on the file, so it stays in WAL mode meanwhile.\n */\nfunction inWriteAheadLog(gate: FileGate, owner: object, database: DatabaseSync): boolean {\n\tconst plans = plansOf(gate, owner);\n\tif (plans.writeAheadLog === undefined) {\n\t\ttry {\n\t\t\tplans.writeAheadLog = String(database.prepare(\"PRAGMA main.journal_mode\").get()?.journal_mode) === \"wal\";\n\t\t} catch {\n\t\t\tplans.writeAheadLog = false;\n\t\t}\n\t}\n\treturn plans.writeAheadLog;\n}\n\n/**\n * Whether a plan, with the programs of the triggers it fires, can be refused the lock only in its opening steps, before\n * it did anything (see `modeOf`). When the connection cannot list its functions, every function counts as one SQLite\n * does not build in.\n */\nfunction triesSafely(steps: ReturnType<StatementSync[\"all\"]>, database: DatabaseSync): boolean {\n\tlet userFunctions: Set<string> | undefined | null = null;\n\tfor (const step of steps) {\n\t\tconst opcode = String(step.opcode);\n\t\tif (opcode === \"Transaction\") {\n\t\t\tconst written = Number(step.p1);\n\t\t\tif (Number(step.p2) !== 0 && written !== MAIN_DATABASE && written !== TEMP_DATABASE) return false;\n\t\t\tcontinue;\n\t\t}\n\t\tif (opcode === \"Vacuum\" || /^V[A-Z]/.test(opcode)) return false;\n\t\tif (typeof step.p4 === \"string\" && usesOtherCollation(opcode, step.p4)) return false;\n\t\tif (!FUNCTION_STEPS.has(opcode)) continue;\n\t\tconst name = /^([^(]+)\\(/.exec(String(step.p4 ?? \"\"))?.[1]?.toLowerCase();\n\t\tif (name === undefined || UNSAFE_FUNCTIONS.has(name)) return false;\n\t\tif (userFunctions === null) userFunctions = functionsNotBuiltIn(database);\n\t\tif (userFunctions === undefined || userFunctions.has(name)) return false;\n\t}\n\treturn true;\n}\n\n/** The names of the functions `database` has that SQLite does not build in; undefined when it cannot list them. */\nfunction functionsNotBuiltIn(database: DatabaseSync): Set<string> | undefined {\n\ttry {\n\t\tconst names = new Set<string>();\n\t\tlet listed = 0;\n\t\tfor (const row of database.prepare(\"PRAGMA function_list\").all()) {\n\t\t\tlisted++;\n\t\t\tif (Number(row.builtin) === 0) names.add(String(row.name).toLowerCase());\n\t\t}\n\t\treturn listed === 0 ? undefined : names;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** Whether `error` is SQLITE_BUSY itself (not one of its extended codes, such as SQLITE_BUSY_SNAPSHOT). */\nfunction plainBusy(error: unknown): boolean {\n\tfor (let cause = error; typeof cause === \"object\" && cause !== null; ) {\n\t\tconst { errcode } = cause as { errcode?: unknown };\n\t\tif (typeof errcode === \"number\") return errcode === 5;\n\t\tcause = (cause as { cause?: unknown }).cause;\n\t}\n\treturn false;\n}\n\n/** One attempt: done, with a value or an error of its own, or refused the lock (SQLITE_BUSY), having done nothing. */\ntype Attempt<T> =\n\t| { readonly kind: \"done\"; readonly value: T }\n\t| { readonly kind: \"failed\"; readonly error: unknown }\n\t| { readonly kind: \"busy\"; readonly error: unknown };\n\n/**\n * Runs `attempt`, a call that runs synchronously on `database`, once with a busy timeout of 0, then gives the\n * connection back `timeoutMs`. Undefined, having run nothing, when the connection no longer tries calls first or does\n * not take the busy timeout of 0, as read back (an authorizer you set can refuse or ignore it, though it allowed the\n * value it had; see `triesAllowed`): the call is to run as before, and the connection is not tried first again. When\n * the connection does not take the value back after the try, twice, the try's outcome is final, a refusal of the lock\n * included, and the connection is never tried first again: its busy timeout can stay 0.\n */\nfunction attemptOnce<T>(database: DatabaseSync, timeoutMs: number, attempt: () => T): Attempt<T> | undefined {\n\tif (registry.untried.has(database)) return undefined;\n\tlet zero = false;\n\ttry {\n\t\tsetBusyTimeout(database, 0);\n\t\tzero = readBusyTimeout(database) === 0;\n\t} catch {\n\t\t// Refused: the timeout is unchanged.\n\t}\n\tif (!zero) {\n\t\tregistry.untried.add(database);\n\t\ttimeoutRestored(database, timeoutMs);\n\t\treturn undefined;\n\t}\n\tlet outcome: Attempt<T>;\n\ttry {\n\t\toutcome = { kind: \"done\", value: attempt() };\n\t} catch (error) {\n\t\toutcome = plainBusy(error) ? { kind: \"busy\", error } : { kind: \"failed\", error };\n\t}\n\tif (!timeoutRestored(database, timeoutMs)) {\n\t\tregistry.untried.add(database);\n\t\tif (outcome.kind === \"busy\") return { kind: \"failed\", error: outcome.error };\n\t}\n\treturn outcome;\n}\n\n/** Gives `database` back its busy timeout after a try, trying twice; whether it took it, as read back. */\nfunction timeoutRestored(database: DatabaseSync, timeoutMs: number): boolean {\n\tfor (let tries = 0; tries < 2; tries++) {\n\t\ttry {\n\t\t\tsetBusyTimeout(database, timeoutMs);\n\t\t\tif (readBusyTimeout(database) === timeoutMs) return true;\n\t\t} catch {\n\t\t\t// Tried again once, then given up.\n\t\t}\n\t}\n\treturn false;\n}\n\n/** The busy timeout of `database` as it reads it now; undefined when it cannot be read. */\nfunction readBusyTimeout(database: DatabaseSync): number | undefined {\n\ttry {\n\t\tconst timeout = Number(database.prepare(\"PRAGMA busy_timeout\").get()?.timeout);\n\t\treturn Number.isFinite(timeout) ? timeout : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** Sets the connection's busy timeout: a setting of the connection, which touches no file. */\nfunction setBusyTimeout(database: DatabaseSync, timeoutMs: number): void {\n\tdatabase.exec(`PRAGMA busy_timeout=${timeoutMs}`);\n}\n\n/**\n * Runs a single statement, `attempt` (synchronous on `database`, the connection `owner` owns), the way SQLite's busy\n * handler would, without holding this thread: once at once with a busy timeout of 0; refused the lock, it waits off\n * this thread and is tried again once a threaded transaction gives the lock back, or on a short poll for a lock another\n * process holds, oldest first and one call per turn of the event loop; still refused at the end of the connection's\n * busy timeout, it fails with that SQLITE_BUSY. Calls already waiting go first. When the busy timeout cannot be read,\n * `asBefore` runs it as it always has.\n */\nexport function runTryingFirst<T>(\n\tfile: string,\n\tgate: FileGate,\n\towner: object,\n\tdatabase: DatabaseSync,\n\tattempt: () => T,\n\tasBefore: () => Promise<T>,\n\tbusy: () => Error,\n): Promise<T> {\n\tconst timeoutMs = busyTimeoutOf(gate, owner, database);\n\tif (timeoutMs === undefined) return asBefore();\n\trunNextWaiter(file, gate);\n\tlet refusal: unknown;\n\tif (gate.waiters.length === 0 && !gate.paced) {\n\t\tconst first = attemptOnce(database, timeoutMs, attempt);\n\t\tif (first === undefined) return asBefore();\n\t\tif (first.kind !== \"busy\") {\n\t\t\tranThisTurn(file, gate);\n\t\t\treturn first.kind === \"done\" ? Promise.resolve(first.value) : Promise.reject(first.error);\n\t\t}\n\t\trefusal = first.error;\n\t}\n\treturn new Promise<T>((resolve, reject) => {\n\t\tconst waiter = undecidedWaiter(database);\n\t\tgate.waiters.push(waiter);\n\t\tarmTry(file, gate, waiter, database, timeoutMs, attempt, asBefore, refusal, resolve, reject, busy);\n\t});\n}\n\n/**\n * Makes `waiter` try `attempt` again on each wake until its deadline, `timeoutMs` from now, for `runTryingFirst`;\n * `refusal` is the SQLITE_BUSY of its last try, if any.\n */\nfunction armTry<T>(\n\tfile: string,\n\tgate: FileGate,\n\twaiter: Waiter,\n\tdatabase: DatabaseSync,\n\ttimeoutMs: number,\n\tattempt: () => T,\n\tasBefore: () => Promise<T>,\n\trefusal: unknown,\n\tresolve: (value: T | PromiseLike<T>) => void,\n\treject: (error: unknown) => void,\n\tbusy: () => Error,\n): void {\n\tlet lastRefusal = refusal;\n\t// A try the connection does not allow runs the call as before (see `attemptOnce`).\n\tconst settle = (outcome: Attempt<T> | undefined): boolean => {\n\t\tif (outcome === undefined) {\n\t\t\tresolve(asBefore());\n\t\t\treturn true;\n\t\t}\n\t\tif (outcome.kind === \"busy\") {\n\t\t\tlastRefusal = outcome.error;\n\t\t\treturn false;\n\t\t}\n\t\tif (outcome.kind === \"done\") resolve(outcome.value);\n\t\telse reject(outcome.error);\n\t\treturn true;\n\t};\n\twaiter.deadline = performance.now() + timeoutMs;\n\t// At its deadline it is tried once more if it is the oldest; refused, or behind others while the lock is taken, it\n\t// fails with the refusal. Behind others while the lock is free, it keeps its place.\n\twaiter.timer = setTimeout(\n\t\t() =>\n\t\t\tsetImmediate(() => {\n\t\t\t\tconst index = gate.waiters.indexOf(waiter);\n\t\t\t\tif (index === -1) return;\n\t\t\t\tif (index === 0 && settle(attemptOnce(database, timeoutMs, attempt))) {\n\t\t\t\t\tgate.waiters.shift();\n\t\t\t\t\tranThisTurn(file, gate);\n\t\t\t\t} else if (index === 0 || wordTaken(file)) {\n\t\t\t\t\tgate.waiters.splice(index, 1);\n\t\t\t\t\twaiter.fail();\n\t\t\t\t\tranThisTurn(file, gate);\n\t\t\t\t}\n\t\t\t\tforgetIfIdle(file, gate);\n\t\t\t}),\n\t\ttimeoutMs,\n\t);\n\twaiter.tryRun = () => settle(attemptOnce(database, timeoutMs, attempt));\n\t// Refused at its last try, it fails with that refusal; never tried, with SQLITE_BUSY as the runtime reports it.\n\twaiter.fail = () => reject(lastRefusal ?? busy());\n\tconst state = registry.words.get(file)?.state;\n\tif (state !== undefined) watchWord(file, gate, state);\n\tpollWaiters(file, gate);\n}\n\n/** Whether a call on `database` waits for its turn. */\nexport function connectionWaits(gate: FileGate, database: DatabaseSync): boolean {\n\treturn gate.waiters.some((waiter) => waiter.connection === database);\n}\n\n/**\n * Runs a call on `database`, which `owner` owns, behind an earlier call on the same connection that waits, from this\n * or another wrapped handle, so no call runs on a connection between a refused try of an earlier call and the try that\n * follows, as none could while SQLite's busy handler waited. It is decided (see `modeOf`) only at its turn,\n * since listing the plan of an INSERT, UPDATE or DELETE resets the connection's `changes()`, which a call before it\n * could read; then it runs as `runTryingFirst` or `runWhenFree` would, or as before, with `call`. Once no threaded\n * transaction holds the file, it runs as before.\n */\nexport function runDeferred<T>(\n\tfile: string,\n\tgate: FileGate,\n\towner: object,\n\tdatabase: DatabaseSync,\n\tstatement: { readonly sql: string; readonly params: readonly SQLInputValue[]; readonly single: boolean },\n\tattempt: () => T,\n\tcall: () => Promise<T>,\n\tbusy: () => Error,\n): Promise<T> {\n\treturn new Promise<T>((resolve, reject) => {\n\t\tconst waiter = undecidedWaiter(database);\n\t\twaiter.tryRun = () => {\n\t\t\tconst mode = scopedHoldOpen(gate)\n\t\t\t\t? modeOf(gate, owner, database, statement.sql, statement.params, statement.single)\n\t\t\t\t: \"as before\";\n\t\t\tconst state = registry.words.get(file)?.state;\n\t\t\tconst timeoutMs = mode === \"as before\" ? undefined : busyTimeoutOf(gate, owner, database);\n\t\t\tif (timeoutMs === undefined || (mode === \"script\" && state === undefined)) {\n\t\t\t\tresolve(call());\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (mode === \"script\") {\n\t\t\t\tconst ran = runAdmitted(state!, call);\n\t\t\t\tif (ran !== undefined) {\n\t\t\t\t\tresolve(ran);\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tarmWhenFree(file, gate, waiter, state!, timeoutMs, call, resolve, reject, busy);\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tconst first = attemptOnce(database, timeoutMs, attempt);\n\t\t\tif (first === undefined) resolve(call());\n\t\t\telse if (first.kind === \"done\") resolve(first.value);\n\t\t\telse if (first.kind === \"failed\") reject(first.error);\n\t\t\telse {\n\t\t\t\tarmTry(file, gate, waiter, database, timeoutMs, attempt, call, first.error, resolve, reject, busy);\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\t\tgate.waiters.push(waiter);\n\t});\n}\n\n/** Whether a threaded transaction of this thread takes or holds the file's lock now, as its word says. */\nfunction wordTaken(file: string): boolean {\n\tconst state = registry.words.get(file)?.state;\n\treturn state !== undefined && Atomics.load(state, 0) !== FREE;\n}\n\n/** How often calls refused a lock that no transaction of this thread holds (another process's) are tried again. */\nconst POLL_MS = 20;\n\n/**\n * Tries the oldest waiting call again every `POLL_MS` while calls wait, for locks no word announces. While the word is\n * taken, the watch on it (`watchWord`) wakes the calls instead.\n */\nfunction pollWaiters(file: string, gate: FileGate): void {\n\tif (gate.polling || gate.waiters.length === 0) return;\n\tgate.polling = true;\n\tsetTimeout(() => {\n\t\tgate.polling = false;\n\t\tif (!wordTaken(file)) runNextWaiter(file, gate);\n\t\tforgetIfIdle(file, gate);\n\t\tpollWaiters(file, gate);\n\t}, POLL_MS);\n}\n\n/**\n * The statements of an `exec` text, split as SQLite reads them: past quoted strings and names (`'…'`, `\"…\"`, `` `…` ``,\n * `[…]`) and comments, with a trigger's body (`CREATE TRIGGER … BEGIN … END`) kept in its statement. Empty statements\n * are dropped. A comment left open runs to the end of the text; past a quote left open, or in a trigger's body without\n * its END, the rest of the text is one statement, which SQLite fails.\n */\nexport function splitStatements(sql: string): string[] {\n\tconst statements: string[] = [];\n\tlet start = 0;\n\tlet words: string[] = [];\n\tlet lastWord = \"\";\n\tlet tokens = false;\n\tconst trigger = () =>\n\t\twords[0] === \"CREATE\" &&\n\t\t(words[1] === \"TRIGGER\" || ((words[1] === \"TEMP\" || words[1] === \"TEMPORARY\") && words[2] === \"TRIGGER\"));\n\tfor (let index = 0; index < sql.length; ) {\n\t\tconst char = sql[index]!;\n\t\tif (char === \"'\" || char === '\"' || char === \"`\" || char === \"[\") {\n\t\t\tconst close = char === \"[\" ? \"]\" : char;\n\t\t\tlet end = sql.indexOf(close, index + 1);\n\t\t\t// A doubled quote stands for the quote itself, except in a bracketed name.\n\t\t\twhile (end !== -1 && close !== \"]\" && sql[end + 1] === close) end = sql.indexOf(close, end + 2);\n\t\t\ttokens = true;\n\t\t\t// Unterminated: SQLite fails the statement there, after the ones before it ran.\n\t\t\tif (end === -1) break;\n\t\t\tindex = end + 1;\n\t\t\tlastWord = \"\";\n\t\t} else if (char === \"-\" && sql[index + 1] === \"-\") {\n\t\t\tconst end = sql.indexOf(\"\\n\", index + 2);\n\t\t\tindex = end === -1 ? sql.length : end + 1;\n\t\t} else if (char === \"/\" && sql[index + 1] === \"*\") {\n\t\t\t// Unterminated, the comment runs to the end of the text.\n\t\t\tconst end = sql.indexOf(\"*/\", index + 2);\n\t\t\tindex = end === -1 ? sql.length : end + 2;\n\t\t} else if (char === \";\") {\n\t\t\tindex += 1;\n\t\t\t// Inside a trigger's body, only the semicolon after its END ends the statement.\n\t\t\tif (trigger() && lastWord !== \"END\") continue;\n\t\t\tif (tokens) statements.push(sql.slice(start, index - 1));\n\t\t\tstart = index;\n\t\t\twords = [];\n\t\t\tlastWord = \"\";\n\t\t\ttokens = false;\n\t\t} else if (/[A-Za-z_]/.test(char)) {\n\t\t\tlet end = index + 1;\n\t\t\twhile (end < sql.length && /[\\w$]/.test(sql[end]!)) end += 1;\n\t\t\tconst word = sql.slice(index, end).toUpperCase();\n\t\t\tif (words.length < 3) words.push(word);\n\t\t\tlastWord = word;\n\t\t\ttokens = true;\n\t\t\tindex = end;\n\t\t} else {\n\t\t\tif (!/\\s/.test(char)) {\n\t\t\t\ttokens = true;\n\t\t\t\tlastWord = \"\";\n\t\t\t}\n\t\t\tindex += 1;\n\t\t}\n\t}\n\t// Past an unterminated quote, or in a trigger's body without its END, SQLite fails the rest as one statement.\n\tif (tokens) statements.push(sql.slice(start));\n\treturn statements;\n}\n\n/**\n * The steps of the plan of `sql`, listed now from the plan kept for it (SQLite prepares a kept plan again when this\n * connection changed its schema since, and fails it if the statement no longer prepares), or from a new one; undefined\n * when SQLite cannot make one. The plan is bound to the call's `params` first, so parameters the statement cannot\n * bind fail before the plan is listed, which resets `changes()` (see `modeOf`), as the statement fails before it runs.\n */\nfunction planSteps(\n\tgate: FileGate,\n\towner: object,\n\tdatabase: DatabaseSync,\n\tsql: string,\n\tparams: readonly SQLInputValue[],\n): ReturnType<StatementSync[\"all\"]> | undefined {\n\tconst plans = plansOf(gate, owner);\n\tconst kept = plans.explained.get(sql);\n\tif (kept !== undefined) {\n\t\ttry {\n\t\t\treturn kept.all(...params);\n\t\t} catch {\n\t\t\tplans.explained.delete(sql);\n\t\t}\n\t}\n\ttry {\n\t\tconst explained = database.prepare(`EXPLAIN ${sql}`);\n\t\tconst steps = explained.all(...params);\n\t\tif (plans.explained.size >= MAX_PLANS) plans.explained.delete(plans.explained.keys().next().value!);\n\t\tplans.explained.set(sql, explained);\n\t\treturn steps;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nlet sqliteErrorShape: { readonly prototype: object; readonly ownCode: boolean } | undefined;\n\n/**\n * How the runtime's node:sqlite builds its errors: their class (Bun has one of its own) and whether `code` is a field\n * of each error, read once from a failure of a connection of this module's own. Plain `Error` fields when it cannot\n * be read.\n */\nfunction errorShape(): { readonly prototype: object; readonly ownCode: boolean } {\n\tif (sqliteErrorShape !== undefined) return sqliteErrorShape;\n\tsqliteErrorShape = { prototype: Error.prototype, ownCode: true };\n\ttry {\n\t\tconst { DatabaseSync: Database } = createRequire(import.meta.url)(\"node:sqlite\") as typeof import(\"node:sqlite\");\n\t\tconst probe = new Database(\":memory:\");\n\t\ttry {\n\t\t\tprobe.exec(\"SELECT\");\n\t\t} catch (error) {\n\t\t\tif (error instanceof Error)\n\t\t\t\tsqliteErrorShape = {\n\t\t\t\t\tprototype: Object.getPrototypeOf(error) as object,\n\t\t\t\t\townCode: Object.hasOwn(error, \"code\"),\n\t\t\t\t};\n\t\t} finally {\n\t\t\tprobe.close();\n\t\t}\n\t} catch {\n\t\t// The plain shape stands.\n\t}\n\treturn sqliteErrorShape;\n}\n\n/**\n * SQLITE_BUSY as the runtime's node:sqlite reports it, for a call that waited out its busy timeout without running:\n * the runtime's own error class with the fields a refused statement carries.\n */\nexport function sqliteBusyError(): Error {\n\tconst shape = errorShape();\n\tconst error = Object.setPrototypeOf(new Error(\"database is locked\"), shape.prototype) as Error;\n\tconst fields: Record<string, unknown> = { errcode: 5, errstr: \"database is locked\" };\n\treturn Object.assign(error, shape.ownCode ? { code: \"ERR_SQLITE_ERROR\", ...fields } : fields);\n}\n"]}
|
|
1
|
+
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AC;QACjH,MAAM,KAAK,GAAG,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAC;QACvC,IAAI,CAAC;YACJ,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACtB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,IAAI,KAAK,YAAY,KAAK;gBACzB,gBAAgB,GAAG;oBAClB,SAAS,EAAE,MAAM,CAAC,cAAc,CAAC,KAAK,CAAW;oBACjD,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC;iBACrC,CAAC;QACJ,CAAC;gBAAS,CAAC;YACV,KAAK,CAAC,KAAK,EAAE,CAAC;QACf,CAAC;IACF,CAAC;IAAC,MAAM,CAAC;QACR,0BAA0B;IAC3B,CAAC;IACD,OAAO,gBAAgB,CAAC;AACzB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe;IAC9B,MAAM,KAAK,GAAG,UAAU,EAAE,CAAC;IAC3B,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,IAAI,KAAK,CAAC,oBAAoB,CAAC,EAAE,KAAK,CAAC,SAAS,CAAU,CAAC;IAC/F,MAAM,MAAM,GAA4B,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,oBAAoB,EAAE,CAAC;IACrF,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAC/F,CAAC","sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\nimport { createRequire } from \"node:module\";\nimport type { DatabaseSync, SQLInputValue, StatementSync } from \"node:sqlite\";\nimport { type LongTimeout, setLongTimeoutAt } from \"@bastani/atomic-timers\";\n\n/**\n * A connection on a thread of its own taking or holding a file's write lock: open from the moment it sends\n * `BEGIN IMMEDIATE` until it learns that the attempt was refused or failed, or until its transaction let go of the\n * lock. Only a `scoped` hold, one opened while the process had a wrapped connection to the file, makes wrapped calls\n * wait: its transaction's callback runs in its asynchronous context (`runInHold`), so calls made inside it are told\n * apart. A process that wraps no connection to the file never enters that context, and wrapped calls made while an\n * unscoped hold is open run at once, as they always have.\n */\nexport interface FileHold {\n\treadonly file: string;\n\treadonly scoped: boolean;\n\topen: boolean;\n}\n\n/** The holds whose transaction callbacks an asynchronous context runs in, innermost first. */\nexport interface HoldScope {\n\treadonly hold: FileHold;\n\treadonly outer: HoldScope | undefined;\n}\n\n/**\n * What the process's connections to one file are doing with its write lock, in one `Int32` they all share: `FREE`, a\n * statement of the calling thread running (`CALLER`), or a connection on a thread of its own taking it (`tag * 4 + 2`)\n * or holding it (`tag * 4 + 3`), by its `tag`. That thread moves it with compare-and-exchange as SQLite takes and lets\n * go of the lock: it takes the word before `BEGIN IMMEDIATE`, and gives it back once its transaction ended, before it\n * answers. A statement of the calling thread runs only while it has the word itself (`runAdmitted`), so neither can\n * take the lock from under the other.\n */\nconst FREE = 0;\nconst CALLER = 1;\n\n/** A threaded connection's share of its file's word: the word, its tag, and how to stop using it. */\nexport interface FileLock {\n\treadonly buffer: SharedArrayBuffer;\n\treadonly tag: number;\n\t/** Gives the word back if this connection still takes or holds it, as when its thread exited. */\n\tclear(): void;\n\t/** This connection no longer uses the word; the file's word goes once no connection does. */\n\trelease(): void;\n}\n\n/** A call waiting for its turn; one decided only at its turn (see `runDeferred`) is armed then. */\ninterface Waiter {\n\tdeadline: number;\n\ttimer: LongTimeout | undefined;\n\t/** The connection the call runs on: later calls on it wait behind this one (see `runDeferred`). */\n\treadonly connection: DatabaseSync;\n\t/** Runs the call if it can run now; whether it did. */\n\ttryRun: () => boolean;\n\tfail: () => void;\n}\n\n/** A waiter for a call on `connection` that is decided at its turn: no deadline until then. */\nfunction undecidedWaiter(connection: DatabaseSync): Waiter {\n\treturn {\n\t\tdeadline: Number.POSITIVE_INFINITY,\n\t\ttimer: undefined,\n\t\tconnection,\n\t\ttryRun: () => false,\n\t\tfail: () => {},\n\t};\n}\n\n/** Statements a calling-thread connection prepared to decide how its calls run while the file is held; see `modeOf`. */\ninterface Plans {\n\treadonly explained: Map<string, StatementSync>;\n\tbusyTimeout?: StatementSync;\n\t/** Whether the file is in WAL mode; see `inWriteAheadLog`. */\n\twriteAheadLog?: boolean;\n\t/** Whether the connection lets its busy timeout be set; see `triesAllowed`. */\n\ttimeoutSettable?: boolean;\n}\n\n/**\n * One file's open holds, the calls waiting to run, and what those calls' connections prepared meanwhile, by the\n * object that owns each connection (not the connection, which its own statements keep alive), so they are kept no\n * longer than it is.\n */\nexport interface FileGate {\n\treadonly holds: Set<FileHold>;\n\treadonly waiters: Waiter[];\n\treadonly plans: WeakMap<object, Plans>;\n\twatching: boolean;\n\t/** A call ran on this file in the current turn of the event loop; the next one waits for the next turn. */\n\tpaced: boolean;\n\tpumping: boolean;\n\tpolling: boolean;\n}\n\ninterface Registry {\n\treadonly files: Map<string, FileGate>;\n\treadonly words: Map<string, FileWord>;\n\treadonly scopes: AsyncLocalStorage<HoldScope | undefined>;\n\t/** Wrapped connections to each file that are open: closed ones, and ones collected unclosed, no longer count. */\n\treadonly wrapped: Map<string, number>;\n\treadonly collected: FinalizationRegistry<{ readonly release: () => void }>;\n\t/** Connections that refused their busy timeout back after a try: never tried first again (see `attemptOnce`). */\n\treadonly untried: WeakSet<DatabaseSync>;\n}\n\n/** One file's word and the tags of the connections that use it. */\ninterface FileWord {\n\treadonly state: Int32Array;\n\treadonly tags: Set<number>;\n\tlastTag: number;\n}\n\n/** Tags stay below this, so a mark (`tag * 4 + 3`) is a positive `Int32`. */\nconst TAG_LIMIT = 2 ** 28;\n\n// Shared across module copies, as the transaction gates are: a copy that runs a transaction's callback and a copy whose\n// wrapped connection is called from it must see the same holds, words and asynchronous context.\nconst REGISTRY = Symbol.for(\"atomic-storage/node-sqlite-file-holds@1\");\nconst registryBag = globalThis as typeof globalThis & Record<symbol, Registry | undefined>;\nconst registry: Registry = registryBag[REGISTRY] ?? {\n\tfiles: new Map(),\n\twords: new Map(),\n\tscopes: new AsyncLocalStorage(),\n\twrapped: new Map(),\n\tcollected: new FinalizationRegistry((use) => use.release()),\n\tuntried: new WeakSet(),\n};\nregistryBag[REGISTRY] = registry;\n\n/** A threaded connection to `file` starts using the file's word (see `FREE`). */\nexport function useFileLock(file: string): FileLock {\n\tlet word = registry.words.get(file);\n\tif (word === undefined) {\n\t\tword = {\n\t\t\tstate: new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)),\n\t\t\ttags: new Set(),\n\t\t\tlastTag: 0,\n\t\t};\n\t\tregistry.words.set(file, word);\n\t}\n\t// The next tag no connection to the file uses, from 1 up, wrapping before the marks would leave the Int32 range.\n\tlet tag = word.lastTag;\n\tdo tag = (tag % (TAG_LIMIT - 1)) + 1;\n\twhile (word.tags.has(tag));\n\tword.lastTag = tag;\n\tword.tags.add(tag);\n\tconst { state, tags } = word;\n\tlet released = false;\n\treturn {\n\t\tbuffer: state.buffer as SharedArrayBuffer,\n\t\ttag,\n\t\tclear: () => {\n\t\t\tif (\n\t\t\t\tAtomics.compareExchange(state, 0, tag * 4 + 3, FREE) === tag * 4 + 3 ||\n\t\t\t\tAtomics.compareExchange(state, 0, tag * 4 + 2, FREE) === tag * 4 + 2\n\t\t\t)\n\t\t\t\tAtomics.notify(state, 0);\n\t\t},\n\t\trelease: () => {\n\t\t\tif (released) return;\n\t\t\treleased = true;\n\t\t\ttags.delete(tag);\n\t\t\tif (tags.size === 0 && registry.words.get(file)?.tags === tags) registry.words.delete(file);\n\t\t},\n\t};\n}\n\n/**\n * Runs `call`, a statement of the calling thread, if the file's word is free, holding the word while it runs, which is\n * synchronous; undefined, running nothing, if a threaded connection takes or holds the lock.\n */\nfunction runAdmitted<T>(state: Int32Array, call: () => Promise<T>): Promise<T> | undefined {\n\tif (Atomics.compareExchange(state, 0, FREE, CALLER) !== FREE) return undefined;\n\ttry {\n\t\treturn call();\n\t} finally {\n\t\tAtomics.store(state, 0, FREE);\n\t\tAtomics.notify(state, 0);\n\t}\n}\n\n/**\n * A wrapped connection, `owner`, to `file` counts as open until `release` or until `owner` is collected, whichever\n * comes first; see `FileHold`.\n */\nexport function useWrappedFile(file: string, owner: object): { release(): void } {\n\tregistry.wrapped.set(file, (registry.wrapped.get(file) ?? 0) + 1);\n\tlet released = false;\n\tconst use = {\n\t\trelease: () => {\n\t\t\tif (released) return;\n\t\t\treleased = true;\n\t\t\tconst count = (registry.wrapped.get(file) ?? 1) - 1;\n\t\t\tif (count > 0) registry.wrapped.set(file, count);\n\t\t\telse registry.wrapped.delete(file);\n\t\t},\n\t};\n\tregistry.collected.register(owner, use, use);\n\treturn {\n\t\trelease: () => {\n\t\t\tregistry.collected.unregister(use);\n\t\t\tuse.release();\n\t\t},\n\t};\n}\n\n/** Opens a hold on `file`, identified as `fileIdentity` identifies it, scoped if a wrapped connection to it is open. */\nexport function holdFile(file: string): FileHold {\n\tlet gate = registry.files.get(file);\n\tif (gate === undefined) {\n\t\tgate = {\n\t\t\tholds: new Set(),\n\t\t\twaiters: [],\n\t\t\tplans: new WeakMap(),\n\t\t\twatching: false,\n\t\t\tpaced: false,\n\t\t\tpumping: false,\n\t\t\tpolling: false,\n\t\t};\n\t\tregistry.files.set(file, gate);\n\t}\n\tconst hold: FileHold = { file, scoped: registry.wrapped.has(file), open: true };\n\tgate.holds.add(hold);\n\treturn hold;\n}\n\n/** Whether a scoped hold of the gate's file is open. */\nfunction scopedHoldOpen(gate: FileGate): boolean {\n\tfor (const hold of gate.holds) if (hold.scoped) return true;\n\treturn false;\n}\n\n/**\n * Closes `hold`, once. When it was the file's last, the oldest call waiting for the file runs now, if the word is free\n * and no call ran in this turn; the others follow one per turn (see `runNextWaiter`).\n */\nexport function releaseHold(hold: FileHold | undefined): void {\n\tif (hold === undefined || !hold.open) return;\n\thold.open = false;\n\tconst gate = registry.files.get(hold.file);\n\tif (gate === undefined) return;\n\tgate.holds.delete(hold);\n\tif (!scopedHoldOpen(gate)) runNextWaiter(hold.file, gate);\n\tforgetIfIdle(hold.file, gate);\n}\n\n/**\n * Runs the oldest waiting call if the word is free and no call ran on the file in this turn of the event loop, and\n * schedules the next one for the next turn: calls that queued up behind a long transaction run one per turn, so none\n * of them holds the event loop for the time of all of them. A call that finds the word taken waits again, still under\n * its own deadline.\n */\nfunction runNextWaiter(file: string, gate: FileGate): void {\n\tif (gate.paced || gate.waiters.length === 0) return;\n\tconst waiter = gate.waiters[0]!;\n\tif (!waiter.tryRun()) {\n\t\tfailOverdue(file, gate);\n\t\treturn;\n\t}\n\tgate.waiters.shift();\n\twaiter.timer?.clear();\n\tranThisTurn(file, gate);\n}\n\n/**\n * The oldest call could not run: calls waiting past their deadline fail now, having run nothing (or refused, see\n * `runTryingFirst`); the others keep their place.\n */\nfunction failOverdue(file: string, gate: FileGate): void {\n\tconst now = performance.now();\n\tconst overdue = gate.waiters.filter((waiting) => now >= waiting.deadline);\n\tfor (const waiter of overdue) {\n\t\tgate.waiters.splice(gate.waiters.indexOf(waiter), 1);\n\t\twaiter.timer?.clear();\n\t\twaiter.fail();\n\t}\n\t// The calls behind them get their turn.\n\tif (overdue.length > 0) ranThisTurn(file, gate);\n}\n\n/** Notes that a call ran on the file in this turn; the next waiting one gets the next turn. */\nfunction ranThisTurn(file: string, gate: FileGate): void {\n\tgate.paced = true;\n\tif (gate.pumping) return;\n\tgate.pumping = true;\n\tsetImmediate(() => {\n\t\tgate.pumping = false;\n\t\tgate.paced = false;\n\t\tconst state = registry.words.get(file)?.state;\n\t\trunNextWaiter(file, gate);\n\t\tif (state !== undefined) watchWord(file, gate, state);\n\t\tforgetIfIdle(file, gate);\n\t});\n}\n\nfunction forgetIfIdle(file: string, gate: FileGate): void {\n\tif (\n\t\tgate.holds.size === 0 &&\n\t\tgate.waiters.length === 0 &&\n\t\t!gate.pumping &&\n\t\t!gate.polling &&\n\t\tregistry.files.get(file) === gate\n\t)\n\t\tregistry.files.delete(file);\n}\n\n/**\n * Runs a transaction's callback inside the transaction callbacks it was requested in (`scope`, captured when it was\n * requested, since a group commit runs it from another's request) and inside its own hold, so calls it makes can be\n * told apart.\n */\nexport function runInHold<T>(hold: FileHold | undefined, scope: HoldScope | undefined, callback: () => T): T {\n\tconst store = hold?.scoped === true ? { hold, outer: scope } : scope;\n\t// Nothing to change, as always for a process that wraps no connection to a file: no context is entered.\n\tif (store === registry.scopes.getStore()) return callback();\n\treturn registry.scopes.run(store, callback);\n}\n\n/** The holds whose callbacks the caller runs in; captured when a call is made, not when it runs. */\nexport function currentHoldScope(): HoldScope | undefined {\n\treturn registry.scopes.getStore();\n}\n\n/**\n * Whether a call made now on a wrapped connection to `file` comes in behind a transaction: a scoped hold is open or\n * calls wait for their turn. Read when the call is made; one made once that is over runs as it always has, however\n * busy the file was before.\n */\nexport function inBacklog(file: string): boolean {\n\tconst gate = registry.files.get(file);\n\treturn gate !== undefined && (scopedHoldOpen(gate) || gate.waiters.length > 0);\n}\n\n/**\n * The gate of `file` when another context holds it open: some hold is open, and none of the callbacks `scope` runs in\n * belongs to an open hold of it. A call made inside an open hold's own callback cannot wait for it, since the\n * transaction waits for the call: it runs at once, as it always has. A call made in the backlog of a transaction\n * (`backlog`, see `inBacklog`) also takes its turn behind the calls queued before it, one per turn.\n */\nexport function heldElsewhere(file: string, scope: HoldScope | undefined, backlog: boolean): FileGate | undefined {\n\tconst gate = registry.files.get(file);\n\tif (gate === undefined || (!scopedHoldOpen(gate) && gate.waiters.length === 0 && !(gate.paced && backlog)))\n\t\treturn undefined;\n\tfor (let inner = scope; inner !== undefined; inner = inner.outer) {\n\t\tif (inner.hold.open && inner.hold.file === file) return undefined;\n\t}\n\treturn gate;\n}\n\n/**\n * Runs `run` as soon as the file's word is free: at once if it is, as SQLite's busy handler would find the lock free;\n * otherwise once a threaded connection gives the word back, or the file's last hold closes. Fails it with `busy()`,\n * having run nothing, if the word is still taken at the end of the busy timeout of `database`, which `owner` owns\n * (read only when the call has to wait). When that cannot be read, `run` runs at once, as it always has.\n */\nexport function runWhenFree<T>(\n\tfile: string,\n\tgate: FileGate,\n\towner: object,\n\tdatabase: DatabaseSync,\n\trun: () => Promise<T>,\n\tbusy: () => Error,\n): Promise<T> {\n\tconst state = registry.words.get(file)?.state;\n\tif (state === undefined) return run();\n\t// Calls already waiting go first, and one runs per turn.\n\trunNextWaiter(file, gate);\n\tconst now = gate.waiters.length === 0 && !gate.paced ? runAdmitted(state, run) : undefined;\n\tif (now !== undefined) {\n\t\tranThisTurn(file, gate);\n\t\treturn now;\n\t}\n\tconst timeoutMs = busyTimeoutOf(gate, owner, database);\n\tif (timeoutMs === undefined) return run();\n\treturn new Promise<T>((resolve, reject) => {\n\t\tconst waiter = undecidedWaiter(database);\n\t\tgate.waiters.push(waiter);\n\t\tarmWhenFree(file, gate, waiter, state, timeoutMs, run, resolve, reject, busy);\n\t});\n}\n\n/** Makes `waiter` run `run` once the word is free, for `runWhenFree`. */\nfunction armWhenFree<T>(\n\tfile: string,\n\tgate: FileGate,\n\twaiter: Waiter,\n\tstate: Int32Array,\n\ttimeoutMs: number,\n\trun: () => Promise<T>,\n\tresolve: (value: T | PromiseLike<T>) => void,\n\treject: (error: unknown) => void,\n\tbusy: () => Error,\n): void {\n\twaiter.deadline = performance.now() + timeoutMs;\n\t// Decided once the event loop handled what it already received, such as the exit of a connection's thread, which\n\t// a timer runs ahead of. At its deadline it fails if the word is taken. While the word is free it keeps its place:\n\t// a free lock is never reported busy, and its turn comes (see `runNextWaiter`), so its busy timeout bounds how long\n\t// it waits for the lock, not for its turn.\n\twaiter.timer = setLongTimeoutAt(\n\t\t() =>\n\t\t\tsetImmediate(() => {\n\t\t\t\tconst index = gate.waiters.indexOf(waiter);\n\t\t\t\tif (index === -1 || Atomics.load(state, 0) === FREE) return;\n\t\t\t\tgate.waiters.splice(index, 1);\n\t\t\t\twaiter.fail();\n\t\t\t\tranThisTurn(file, gate);\n\t\t\t\tforgetIfIdle(file, gate);\n\t\t\t}),\n\t\twaiter.deadline,\n\t);\n\twaiter.tryRun = () => {\n\t\tconst ran = runAdmitted(state, run);\n\t\tif (ran === undefined) return false;\n\t\tresolve(ran);\n\t\treturn true;\n\t};\n\twaiter.fail = () => reject(busy());\n\twatchWord(file, gate, state);\n}\n\n/**\n * Wakes the gate's waiting calls whenever the file's word changes, so a call runs the moment a threaded connection\n * gives the lock back, before its answer reaches this thread. One watch per gate, for as long as calls wait.\n */\nfunction watchWord(file: string, gate: FileGate, state: Int32Array): void {\n\tfor (;;) {\n\t\tif (gate.watching || gate.waiters.length === 0) return;\n\t\tconst observed = Atomics.load(state, 0);\n\t\t// Freed since the caller found it taken: run what waits now rather than wait for a change that already came.\n\t\tif (observed === FREE) {\n\t\t\t// Free: the oldest runs now or at the next turn (see `runNextWaiter`); nothing to watch for until then.\n\t\t\trunNextWaiter(file, gate);\n\t\t\tforgetIfIdle(file, gate);\n\t\t\t// Ran, or was refused a lock the word does not announce (another process's), which `pollWaiters` tries again.\n\t\t\tif (gate.paced || Atomics.load(state, 0) === FREE) return;\n\t\t\tcontinue;\n\t\t}\n\t\t// Until the last deadline: each waiter's own timer decides at its deadline, so a watch never runs past it.\n\t\t// Calls not decided yet (see `runDeferred`) need no watch: they are decided in their turn, whatever the word.\n\t\tconst deadlines = gate.waiters.map((waiter) => waiter.deadline).filter(Number.isFinite);\n\t\tconst untilMs = Math.max(...deadlines) - performance.now();\n\t\tif (deadlines.length === 0 || untilMs <= 0) return;\n\t\tconst result = Atomics.waitAsync(state, 0, observed, untilMs);\n\t\tif (!result.async) {\n\t\t\tif (result.value === \"not-equal\") continue;\n\t\t\treturn;\n\t\t}\n\t\tgate.watching = true;\n\t\tvoid result.value.then(() => {\n\t\t\tgate.watching = false;\n\t\t\trunNextWaiter(file, gate);\n\t\t\tforgetIfIdle(file, gate);\n\t\t\twatchWord(file, gate, state);\n\t\t});\n\t\treturn;\n\t}\n}\n\n/** Most plans one connection keeps while a file is held. */\nconst MAX_PLANS = 32;\n\nfunction plansOf(gate: FileGate, owner: object): Plans {\n\tlet plans = gate.plans.get(owner);\n\tif (plans === undefined) {\n\t\tplans = { explained: new Map() };\n\t\tgate.plans.set(owner, plans);\n\t}\n\treturn plans;\n}\n\n/** Drops what the connection of `owner` prepared while `file` was held, as it closes. */\nexport function forgetPlans(file: string, owner: object): void {\n\tregistry.files.get(file)?.plans.delete(owner);\n}\n\n/** The busy timeout `database` waits for a lock now, in milliseconds; undefined when it cannot be read. */\nfunction busyTimeoutOf(gate: FileGate, owner: object, database: DatabaseSync): number | undefined {\n\tconst plans = plansOf(gate, owner);\n\ttry {\n\t\tplans.busyTimeout ??= database.prepare(\"PRAGMA busy_timeout\");\n\t\tconst timeout = Number(plans.busyTimeout.get()?.timeout);\n\t\treturn Number.isFinite(timeout) && timeout >= 0 ? timeout : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** A blank or a comment, which SQLite skips between words. */\nconst GAP = String.raw`(?:\\s|--[^\\n]*(?:\\n|$)|\\/\\*[\\s\\S]*?\\*\\/)`;\n/** What SQLite skips before a statement's first word: blanks, comments and empty statements. */\nconst LEADING = new RegExp(`^(?:${GAP}|;)*`);\n/**\n * A PRAGMA, alone or under EXPLAIN or EXPLAIN QUERY PLAN (on text without what `LEADING` matches): SQLite may carry it\n * out while it prepares it, so it is never prepared ahead.\n */\nconst PRAGMA_STATEMENT = new RegExp(`^(?:EXPLAIN${GAP}+(?:QUERY${GAP}+PLAN${GAP}+)?)?PRAGMA\\\\b`, \"i\");\n/** A name as SQLite reads it, bare or quoted, with its quotes. */\nconst NAME = String.raw`(?:\\w+|\"(?:[^\"]|\"\")*\"|'(?:[^']|'')*'|\\[[^\\]]*\\]|` + \"`(?:[^`]|``)*`)\";\n/**\n * A PRAGMA's name, past an optional EXPLAIN or EXPLAIN QUERY PLAN, `PRAGMA` and an optional schema (`schema.`), on text\n * without what `LEADING` matches.\n */\nconst PRAGMA_NAME = new RegExp(\n\t`^(EXPLAIN${GAP}+(?:QUERY${GAP}+PLAN${GAP}+)?)?PRAGMA${GAP}+(?:(${NAME})${GAP}*\\\\.${GAP}*)?(${NAME})`,\n\t\"i\",\n);\n/** A name without its quotes, in lower case. */\nfunction unquoted(name: string): string {\n\tconst quote = name[0];\n\tif (quote === '\"' || quote === \"'\" || quote === \"`\")\n\t\treturn name.slice(1, -1).replaceAll(`${quote}${quote}`, quote).toLowerCase();\n\tif (quote === \"[\") return name.slice(1, -1).toLowerCase();\n\treturn name.toLowerCase();\n}\n\n/**\n * PRAGMAs that write the file and are tried first: SQLite refuses each in its opening steps, before it changed\n * anything. Every other PRAGMA runs as it always has: one that reads or sets a setting of the connection or another\n * database needs no lock of the file in WAL mode, and runs at once anyway; and ones a try would change are among them:\n * those of the busy timeout, which the try sets, also under EXPLAIN, since SQLite sets it while it prepares the\n * statement; setters that change something before they meet the lock (`journal_mode`, `default_cache_size`,\n * `auto_vacuum`, and the ones that apply to every attached database when no schema is named); checks that run the\n * application's functions in the schema's constraints (`integrity_check`, `quick_check`); and ones that answer\n * differently when refused the lock at once (a checkpoint that waits, `optimize`).\n */\nconst TRIED_PRAGMAS = new Set([\"user_version\", \"application_id\", \"schema_version\", \"incremental_vacuum\"]);\n\n/** Whether a PRAGMA (on text without what `LEADING` matches) is tried first; see `TRIED_PRAGMAS`. */\nfunction pragmaTriedFirst(statement: string): boolean {\n\tconst match = PRAGMA_NAME.exec(statement);\n\tif (match === null) return false;\n\tconst [, explain, schema, name = \"\"] = match;\n\treturn (\n\t\texplain === undefined &&\n\t\t(schema === undefined || unquoted(schema) === \"main\") &&\n\t\tTRIED_PRAGMAS.has(unquoted(name))\n\t);\n}\n\n/**\n * Built-in functions a try cannot run safely: ones that read the connection's change counters, which a refused try\n * changes; `load_extension`, which runs an extension's code; and `sqlite_attach` (ATTACH), which reads another file\n * with its own locks.\n */\nconst UNSAFE_FUNCTIONS = new Set([\"changes\", \"total_changes\", \"last_insert_rowid\", \"load_extension\", \"sqlite_attach\"]);\n/** Steps of a plan that call a function or an aggregate, named in their P4 as `name(arguments)`. */\nconst FUNCTION_STEPS = new Set([\n\t\"Function\",\n\t\"Function0\",\n\t\"PureFunc\",\n\t\"PureFunc0\",\n\t\"AggStep\",\n\t\"AggStep0\",\n\t\"AggStep1\",\n\t\"AggFinal\",\n\t\"AggValue\",\n\t\"AggInverse\",\n]);\n/** The collating sequences SQLite builds in; `B` is how a plan's key lists `BINARY`. */\nconst BUILT_IN_COLLATIONS = new Set([\"\", \"B\", \"BINARY\", \"NOCASE\", \"RTRIM\"]);\n/** Steps of a plan that compare with a collating sequence named in their P4 as `name-encoding`. */\nconst COLLATING_STEPS = new Set([\"CollSeq\", \"Eq\", \"Ne\", \"Lt\", \"Le\", \"Gt\", \"Ge\"]);\nconst COLLATION = /^(.*)-(?:8|16le|16be|16)$/;\n/** A plan's key, `k(fields,collation,…)`, each collation after its `-` (descending) and `N.` (nulls last) marks. */\nconst KEY = /^k\\(\\d+((?:,[^,)]*)*)\\)$/;\n\n/** Whether a step of a plan compares with a collating sequence SQLite does not build in, an extension's code. */\nfunction usesOtherCollation(opcode: string, p4: string): boolean {\n\tconst key = KEY.exec(p4);\n\tif (key !== null)\n\t\treturn key[1]!\n\t\t\t.split(\",\")\n\t\t\t.slice(1)\n\t\t\t.some((field) => !BUILT_IN_COLLATIONS.has(field.replace(/^-?(?:N\\.)?/, \"\")));\n\tif (!COLLATING_STEPS.has(opcode)) return false;\n\tconst name = COLLATION.exec(p4)?.[1];\n\treturn name !== undefined && !BUILT_IN_COLLATIONS.has(name);\n}\n\n/** A VACUUM, which may create the file it writes into before it is refused. */\nconst VACUUM_STATEMENT = /^VACUUM\\b/i;\n/** `UNSAFE_FUNCTIONS` but `sqlite_attach`, whose statement, ATTACH, names it otherwise. */\nconst UNSAFE_NAMES = [\"changes\", \"total_changes\", \"last_insert_rowid\", \"load_extension\"];\n/** An INSERT, UPDATE or DELETE, possibly after a WITH clause: listing its plan resets `changes()`. */\nconst CHANGING_STATEMENT = /^(?:INSERT|REPLACE|UPDATE|DELETE|WITH)\\b/i;\n/**\n * Whether a name starts with the UTF-16 code unit `code`: a letter, `_`, or any character past ASCII, which SQLite reads\n * as part of a name (both halves of a surrogate pair, and a lone one, are past ASCII).\n */\nfunction startsName(code: number): boolean {\n\treturn code >= 0x80 || code === 0x5f || (code >= 0x41 && code <= 0x5a) || (code >= 0x61 && code <= 0x7a);\n}\n\n/** Whether a bare name goes on with the UTF-16 code unit `code`: what starts one, a digit, or `$`. */\nfunction continuesName(code: number): boolean {\n\treturn startsName(code) || (code >= 0x30 && code <= 0x39) || code === 0x24;\n}\n\n/**\n * Where a string literal or a quoted name that opens with `quote` at `start` ends, past its closing quote, or -1 when\n * no quote after `start` closes it. A doubled quote stands for the quote itself; when the text ends inside, the first\n * quote of the last doubled one closes it.\n */\nfunction quotedEnd(sql: string, start: number, quote: string): number {\n\tlet lastDoubled = -1;\n\tfor (let from = start + 1; ; ) {\n\t\tconst at = sql.indexOf(quote, from);\n\t\tif (at === -1) return lastDoubled === -1 ? -1 : lastDoubled + 1;\n\t\tif (sql[at + 1] !== quote) return at + 1;\n\t\tlastDoubled = at;\n\t\tfrom = at + 2;\n\t}\n}\n\n/**\n * The names `sql` uses, bare or quoted (`\"…\"`, `[…]`, `` `…` ``), in lower case: outside its string literals and\n * comments, in one pass over the text. A quote or `[` that nothing closes counts as a character of its own, and the\n * text after it is read as usual.\n */\nfunction namesIn(sql: string): Set<string> {\n\tconst names = new Set<string>();\n\t// A `[` after the last `]` closes no name: knowing it at once keeps each such `[` from reading to the end again.\n\tconst lastBracket = sql.lastIndexOf(\"]\");\n\tfor (let index = 0; index < sql.length; ) {\n\t\tconst char = sql[index]!;\n\t\tif (char === \"'\" || char === '\"' || char === \"`\") {\n\t\t\tconst end = quotedEnd(sql, index, char);\n\t\t\tif (end === -1) index += 1;\n\t\t\telse {\n\t\t\t\t// A string literal names nothing; a quoted name stands for its text, each doubled quote for one.\n\t\t\t\tif (char !== \"'\") {\n\t\t\t\t\tconst name = sql.slice(index + 1, end - 1).replaceAll(char + char, char);\n\t\t\t\t\tnames.add(name.toLowerCase());\n\t\t\t\t}\n\t\t\t\tindex = end;\n\t\t\t}\n\t\t} else if (char === \"[\") {\n\t\t\tif (index < lastBracket) {\n\t\t\t\tconst end = sql.indexOf(\"]\", index + 1);\n\t\t\t\tnames.add(sql.slice(index + 1, end).toLowerCase());\n\t\t\t\tindex = end + 1;\n\t\t\t} else index += 1;\n\t\t} else if (char === \"-\" && sql[index + 1] === \"-\") {\n\t\t\tconst end = sql.indexOf(\"\\n\", index + 2);\n\t\t\tindex = end === -1 ? sql.length : end;\n\t\t} else if (char === \"/\" && sql[index + 1] === \"*\") {\n\t\t\t// Left open, the comment runs to the end of the text.\n\t\t\tconst end = sql.indexOf(\"*/\", index + 2);\n\t\t\tindex = end === -1 ? sql.length : end + 2;\n\t\t} else if (startsName(sql.charCodeAt(index))) {\n\t\t\tlet end = index + 1;\n\t\t\twhile (end < sql.length && continuesName(sql.charCodeAt(end))) end += 1;\n\t\t\tnames.add(sql.slice(index, end).toLowerCase());\n\t\t\tindex = end;\n\t\t} else index += 1;\n\t}\n\treturn names;\n}\n\n/**\n * Whether `statement` names a function whose result a listing of its plan could change, which resets `changes()`\n * for an INSERT, UPDATE or DELETE: one of `UNSAFE_NAMES`, or, for such a statement, a function SQLite does not build\n * in, which could read the counters itself. When the connection cannot list its functions, every INSERT, UPDATE or\n * DELETE counts.\n */\nfunction namesUnsafeFunction(statement: string, database: DatabaseSync): boolean {\n\tconst names = namesIn(statement);\n\tif (UNSAFE_NAMES.some((name) => names.has(name))) return true;\n\tif (!CHANGING_STATEMENT.test(statement)) return false;\n\tconst userFunctions = functionsNotBuiltIn(database);\n\tif (userFunctions === undefined) return true;\n\tfor (const name of userFunctions) if (names.has(name)) return true;\n\treturn false;\n}\n\n/** The database numbers of a connection's main database, the file itself, and of its temporary database. */\nconst MAIN_DATABASE = 0;\nconst TEMP_DATABASE = 1;\n\n/**\n * How a wrapped call runs while a threaded transaction of this thread holds its file:\n *\n * - `try first`: once at once with a busy timeout of 0 (see `runTryingFirst`), refused the lock, tried again. Only a\n * statement whose plan proves that a refusal comes from its opening steps, before it did anything: the only\n * databases it writes are the file and the temporary one, and the file is in WAL mode, where a commit needs no\n * further lock; it calls no code but SQLite's own (no function or collating sequence SQLite does not build in, no\n * virtual table, no `UNSAFE_FUNCTIONS`); it is no VACUUM, which may create the file it writes into before it is\n * refused. A PRAGMA, which is never prepared ahead since SQLite may carry one out while preparing it, is tried first\n * only if it is one of `TRIED_PRAGMAS`.\n * - `as before`: every other single statement, an `exec` of no statement, and every call while the connection is\n * inside a transaction of its own or the file is not in WAL mode. It runs exactly as it always has, with the\n * connection's own busy timeout.\n * - `script`: an `exec` of more than one statement (see `splitStatements`). It waits until no transaction of this\n * thread holds the lock (see `runWhenFree`), so no part of it runs while the lock is held. An `exec` of exactly one\n * statement runs as that statement.\n *\n * At a busy timeout of 0 every single statement runs as before: it never waits for the lock, and setting the timeout,\n * as a try does, would remove a busy handler an extension installed, which reads as a timeout of 0. A script still\n * waits (for no time), which sets no timeout.\n *\n * The plan of a statement is made once while the file is held and listed again for later calls. Listing the plan of\n * an INSERT, UPDATE or DELETE resets the connection's `changes()`, which the statement's own run sets again; so a\n * statement that names a function that reads the change counters or may (see `namesUnsafeFunction`) runs as before\n * without its plan being listed.\n */\nexport function modeOf(\n\tgate: FileGate,\n\towner: object,\n\tdatabase: DatabaseSync,\n\tsql: string,\n\tparams: readonly SQLInputValue[],\n\tsingle: boolean,\n): \"try first\" | \"as before\" | \"script\" {\n\tif (!single) {\n\t\tconst statements = splitStatements(sql);\n\t\tif (statements.length > 1) return \"script\";\n\t\t// Nothing to run, nor to wait for.\n\t\tif (statements.length === 0) return \"as before\";\n\t\treturn modeOf(gate, owner, database, statements[0]!, params, true);\n\t}\n\tif (busyTimeoutOf(gate, owner, database) === 0) return \"as before\";\n\t// Inside a transaction of its own, a write's upgrade of the connection's read is refused at once, with no busy\n\t// handler, and a try again could succeed or be refused otherwise.\n\tif (\n\t\tdatabase.isTransaction !== false ||\n\t\t!inWriteAheadLog(gate, owner, database) ||\n\t\t!triesAllowed(gate, owner, database)\n\t)\n\t\treturn \"as before\";\n\t// Decided on the text SQLite reads, past the blanks, comments and empty statements it skips.\n\tconst statement = sql.replace(LEADING, \"\");\n\tif (PRAGMA_STATEMENT.test(statement)) return pragmaTriedFirst(statement) ? \"try first\" : \"as before\";\n\t// Decided without its plan: listing the plan of an INSERT, UPDATE or DELETE resets the connection's changes().\n\tif (VACUUM_STATEMENT.test(statement) || namesUnsafeFunction(statement, database)) return \"as before\";\n\tconst steps = planSteps(gate, owner, database, statement, params);\n\treturn steps !== undefined && triesSafely(steps, database) ? \"try first\" : \"as before\";\n}\n\n/**\n * Whether calls on `database`, which `owner` owns, may be tried first: it never refused its busy timeout back after a\n * try, and, checked once while the file is held, before anything is tried, the timeout can be read and set to the\n * value it has. An authorizer you set can refuse either; then every call runs as before, and the timeout is never set.\n */\nfunction triesAllowed(gate: FileGate, owner: object, database: DatabaseSync): boolean {\n\tif (registry.untried.has(database)) return false;\n\tconst plans = plansOf(gate, owner);\n\tif (plans.timeoutSettable === undefined) {\n\t\tconst timeoutMs = busyTimeoutOf(gate, owner, database);\n\t\ttry {\n\t\t\tif (timeoutMs !== undefined) setBusyTimeout(database, timeoutMs);\n\t\t\tplans.timeoutSettable = timeoutMs !== undefined;\n\t\t} catch {\n\t\t\tplans.timeoutSettable = false;\n\t\t}\n\t}\n\treturn plans.timeoutSettable;\n}\n\n/**\n * Whether the file of `database`, which `owner` owns, is in WAL mode, read once while the file is held. A connection\n * of this process on a thread of its own is open on the file, so it stays in WAL mode meanwhile.\n */\nfunction inWriteAheadLog(gate: FileGate, owner: object, database: DatabaseSync): boolean {\n\tconst plans = plansOf(gate, owner);\n\tif (plans.writeAheadLog === undefined) {\n\t\ttry {\n\t\t\tplans.writeAheadLog = String(database.prepare(\"PRAGMA main.journal_mode\").get()?.journal_mode) === \"wal\";\n\t\t} catch {\n\t\t\tplans.writeAheadLog = false;\n\t\t}\n\t}\n\treturn plans.writeAheadLog;\n}\n\n/**\n * Whether a plan, with the programs of the triggers it fires, can be refused the lock only in its opening steps, before\n * it did anything (see `modeOf`). When the connection cannot list its functions, every function counts as one SQLite\n * does not build in.\n */\nfunction triesSafely(steps: ReturnType<StatementSync[\"all\"]>, database: DatabaseSync): boolean {\n\tlet userFunctions: Set<string> | undefined | null = null;\n\tfor (const step of steps) {\n\t\tconst opcode = String(step.opcode);\n\t\tif (opcode === \"Transaction\") {\n\t\t\tconst written = Number(step.p1);\n\t\t\tif (Number(step.p2) !== 0 && written !== MAIN_DATABASE && written !== TEMP_DATABASE) return false;\n\t\t\tcontinue;\n\t\t}\n\t\tif (opcode === \"Vacuum\" || /^V[A-Z]/.test(opcode)) return false;\n\t\tif (typeof step.p4 === \"string\" && usesOtherCollation(opcode, step.p4)) return false;\n\t\tif (!FUNCTION_STEPS.has(opcode)) continue;\n\t\tconst name = /^([^(]+)\\(/.exec(String(step.p4 ?? \"\"))?.[1]?.toLowerCase();\n\t\tif (name === undefined || UNSAFE_FUNCTIONS.has(name)) return false;\n\t\tif (userFunctions === null) userFunctions = functionsNotBuiltIn(database);\n\t\tif (userFunctions === undefined || userFunctions.has(name)) return false;\n\t}\n\treturn true;\n}\n\n/** The names of the functions `database` has that SQLite does not build in; undefined when it cannot list them. */\nfunction functionsNotBuiltIn(database: DatabaseSync): Set<string> | undefined {\n\ttry {\n\t\tconst names = new Set<string>();\n\t\tlet listed = 0;\n\t\tfor (const row of database.prepare(\"PRAGMA function_list\").all()) {\n\t\t\tlisted++;\n\t\t\tif (Number(row.builtin) === 0) names.add(String(row.name).toLowerCase());\n\t\t}\n\t\treturn listed === 0 ? undefined : names;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** Whether `error` is SQLITE_BUSY itself (not one of its extended codes, such as SQLITE_BUSY_SNAPSHOT). */\nfunction plainBusy(error: unknown): boolean {\n\tfor (let cause = error; typeof cause === \"object\" && cause !== null; ) {\n\t\tconst { errcode } = cause as { errcode?: unknown };\n\t\tif (typeof errcode === \"number\") return errcode === 5;\n\t\tcause = (cause as { cause?: unknown }).cause;\n\t}\n\treturn false;\n}\n\n/** One attempt: done, with a value or an error of its own, or refused the lock (SQLITE_BUSY), having done nothing. */\ntype Attempt<T> =\n\t| { readonly kind: \"done\"; readonly value: T }\n\t| { readonly kind: \"failed\"; readonly error: unknown }\n\t| { readonly kind: \"busy\"; readonly error: unknown };\n\n/**\n * Runs `attempt`, a call that runs synchronously on `database`, once with a busy timeout of 0, then gives the\n * connection back `timeoutMs`. Undefined, having run nothing, when the connection no longer tries calls first or does\n * not take the busy timeout of 0, as read back (an authorizer you set can refuse or ignore it, though it allowed the\n * value it had; see `triesAllowed`): the call is to run as before, and the connection is not tried first again. When\n * the connection does not take the value back after the try, twice, the try's outcome is final, a refusal of the lock\n * included, and the connection is never tried first again: its busy timeout can stay 0.\n */\nfunction attemptOnce<T>(database: DatabaseSync, timeoutMs: number, attempt: () => T): Attempt<T> | undefined {\n\tif (registry.untried.has(database)) return undefined;\n\tlet zero = false;\n\ttry {\n\t\tsetBusyTimeout(database, 0);\n\t\tzero = readBusyTimeout(database) === 0;\n\t} catch {\n\t\t// Refused: the timeout is unchanged.\n\t}\n\tif (!zero) {\n\t\tregistry.untried.add(database);\n\t\ttimeoutRestored(database, timeoutMs);\n\t\treturn undefined;\n\t}\n\tlet outcome: Attempt<T>;\n\ttry {\n\t\toutcome = { kind: \"done\", value: attempt() };\n\t} catch (error) {\n\t\toutcome = plainBusy(error) ? { kind: \"busy\", error } : { kind: \"failed\", error };\n\t}\n\tif (!timeoutRestored(database, timeoutMs)) {\n\t\tregistry.untried.add(database);\n\t\tif (outcome.kind === \"busy\") return { kind: \"failed\", error: outcome.error };\n\t}\n\treturn outcome;\n}\n\n/** Gives `database` back its busy timeout after a try, trying twice; whether it took it, as read back. */\nfunction timeoutRestored(database: DatabaseSync, timeoutMs: number): boolean {\n\tfor (let tries = 0; tries < 2; tries++) {\n\t\ttry {\n\t\t\tsetBusyTimeout(database, timeoutMs);\n\t\t\tif (readBusyTimeout(database) === timeoutMs) return true;\n\t\t} catch {\n\t\t\t// Tried again once, then given up.\n\t\t}\n\t}\n\treturn false;\n}\n\n/** The busy timeout of `database` as it reads it now; undefined when it cannot be read. */\nfunction readBusyTimeout(database: DatabaseSync): number | undefined {\n\ttry {\n\t\tconst timeout = Number(database.prepare(\"PRAGMA busy_timeout\").get()?.timeout);\n\t\treturn Number.isFinite(timeout) ? timeout : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** Sets the connection's busy timeout: a setting of the connection, which touches no file. */\nfunction setBusyTimeout(database: DatabaseSync, timeoutMs: number): void {\n\tdatabase.exec(`PRAGMA busy_timeout=${timeoutMs}`);\n}\n\n/**\n * Runs a single statement, `attempt` (synchronous on `database`, the connection `owner` owns), the way SQLite's busy\n * handler would, without holding this thread: once at once with a busy timeout of 0; refused the lock, it waits off\n * this thread and is tried again once a threaded transaction gives the lock back, or on a short poll for a lock another\n * process holds, oldest first and one call per turn of the event loop; still refused at the end of the connection's\n * busy timeout, it fails with that SQLITE_BUSY. Calls already waiting go first. When the busy timeout cannot be read,\n * `asBefore` runs it as it always has.\n */\nexport function runTryingFirst<T>(\n\tfile: string,\n\tgate: FileGate,\n\towner: object,\n\tdatabase: DatabaseSync,\n\tattempt: () => T,\n\tasBefore: () => Promise<T>,\n\tbusy: () => Error,\n): Promise<T> {\n\tconst timeoutMs = busyTimeoutOf(gate, owner, database);\n\tif (timeoutMs === undefined) return asBefore();\n\trunNextWaiter(file, gate);\n\tlet refusal: unknown;\n\tif (gate.waiters.length === 0 && !gate.paced) {\n\t\tconst first = attemptOnce(database, timeoutMs, attempt);\n\t\tif (first === undefined) return asBefore();\n\t\tif (first.kind !== \"busy\") {\n\t\t\tranThisTurn(file, gate);\n\t\t\treturn first.kind === \"done\" ? Promise.resolve(first.value) : Promise.reject(first.error);\n\t\t}\n\t\trefusal = first.error;\n\t}\n\treturn new Promise<T>((resolve, reject) => {\n\t\tconst waiter = undecidedWaiter(database);\n\t\tgate.waiters.push(waiter);\n\t\tarmTry(file, gate, waiter, database, timeoutMs, attempt, asBefore, refusal, resolve, reject, busy);\n\t});\n}\n\n/**\n * Makes `waiter` try `attempt` again on each wake until its deadline, `timeoutMs` from now, for `runTryingFirst`;\n * `refusal` is the SQLITE_BUSY of its last try, if any.\n */\nfunction armTry<T>(\n\tfile: string,\n\tgate: FileGate,\n\twaiter: Waiter,\n\tdatabase: DatabaseSync,\n\ttimeoutMs: number,\n\tattempt: () => T,\n\tasBefore: () => Promise<T>,\n\trefusal: unknown,\n\tresolve: (value: T | PromiseLike<T>) => void,\n\treject: (error: unknown) => void,\n\tbusy: () => Error,\n): void {\n\tlet lastRefusal = refusal;\n\t// A try the connection does not allow runs the call as before (see `attemptOnce`).\n\tconst settle = (outcome: Attempt<T> | undefined): boolean => {\n\t\tif (outcome === undefined) {\n\t\t\tresolve(asBefore());\n\t\t\treturn true;\n\t\t}\n\t\tif (outcome.kind === \"busy\") {\n\t\t\tlastRefusal = outcome.error;\n\t\t\treturn false;\n\t\t}\n\t\tif (outcome.kind === \"done\") resolve(outcome.value);\n\t\telse reject(outcome.error);\n\t\treturn true;\n\t};\n\twaiter.deadline = performance.now() + timeoutMs;\n\t// At its deadline it is tried once more if it is the oldest; refused, or behind others while the lock is taken, it\n\t// fails with the refusal. Behind others while the lock is free, it keeps its place.\n\twaiter.timer = setLongTimeoutAt(\n\t\t() =>\n\t\t\tsetImmediate(() => {\n\t\t\t\tconst index = gate.waiters.indexOf(waiter);\n\t\t\t\tif (index === -1) return;\n\t\t\t\tif (index === 0 && settle(attemptOnce(database, timeoutMs, attempt))) {\n\t\t\t\t\tgate.waiters.shift();\n\t\t\t\t\tranThisTurn(file, gate);\n\t\t\t\t} else if (index === 0 || wordTaken(file)) {\n\t\t\t\t\tgate.waiters.splice(index, 1);\n\t\t\t\t\twaiter.fail();\n\t\t\t\t\tranThisTurn(file, gate);\n\t\t\t\t}\n\t\t\t\tforgetIfIdle(file, gate);\n\t\t\t}),\n\t\twaiter.deadline,\n\t);\n\twaiter.tryRun = () => settle(attemptOnce(database, timeoutMs, attempt));\n\t// Refused at its last try, it fails with that refusal; never tried, with SQLITE_BUSY as the runtime reports it.\n\twaiter.fail = () => reject(lastRefusal ?? busy());\n\tconst state = registry.words.get(file)?.state;\n\tif (state !== undefined) watchWord(file, gate, state);\n\tpollWaiters(file, gate);\n}\n\n/** Whether a call on `database` waits for its turn. */\nexport function connectionWaits(gate: FileGate, database: DatabaseSync): boolean {\n\treturn gate.waiters.some((waiter) => waiter.connection === database);\n}\n\n/**\n * Runs a call on `database`, which `owner` owns, behind an earlier call on the same connection that waits, from this\n * or another wrapped handle, so no call runs on a connection between a refused try of an earlier call and the try that\n * follows, as none could while SQLite's busy handler waited. It is decided (see `modeOf`) only at its turn,\n * since listing the plan of an INSERT, UPDATE or DELETE resets the connection's `changes()`, which a call before it\n * could read; then it runs as `runTryingFirst` or `runWhenFree` would, or as before, with `call`. Once no threaded\n * transaction holds the file, it runs as before.\n */\nexport function runDeferred<T>(\n\tfile: string,\n\tgate: FileGate,\n\towner: object,\n\tdatabase: DatabaseSync,\n\tstatement: { readonly sql: string; readonly params: readonly SQLInputValue[]; readonly single: boolean },\n\tattempt: () => T,\n\tcall: () => Promise<T>,\n\tbusy: () => Error,\n): Promise<T> {\n\treturn new Promise<T>((resolve, reject) => {\n\t\tconst waiter = undecidedWaiter(database);\n\t\twaiter.tryRun = () => {\n\t\t\tconst mode = scopedHoldOpen(gate)\n\t\t\t\t? modeOf(gate, owner, database, statement.sql, statement.params, statement.single)\n\t\t\t\t: \"as before\";\n\t\t\tconst state = registry.words.get(file)?.state;\n\t\t\tconst timeoutMs = mode === \"as before\" ? undefined : busyTimeoutOf(gate, owner, database);\n\t\t\tif (timeoutMs === undefined || (mode === \"script\" && state === undefined)) {\n\t\t\t\tresolve(call());\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (mode === \"script\") {\n\t\t\t\tconst ran = runAdmitted(state!, call);\n\t\t\t\tif (ran !== undefined) {\n\t\t\t\t\tresolve(ran);\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tarmWhenFree(file, gate, waiter, state!, timeoutMs, call, resolve, reject, busy);\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tconst first = attemptOnce(database, timeoutMs, attempt);\n\t\t\tif (first === undefined) resolve(call());\n\t\t\telse if (first.kind === \"done\") resolve(first.value);\n\t\t\telse if (first.kind === \"failed\") reject(first.error);\n\t\t\telse {\n\t\t\t\tarmTry(file, gate, waiter, database, timeoutMs, attempt, call, first.error, resolve, reject, busy);\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\t\tgate.waiters.push(waiter);\n\t});\n}\n\n/** Whether a threaded transaction of this thread takes or holds the file's lock now, as its word says. */\nfunction wordTaken(file: string): boolean {\n\tconst state = registry.words.get(file)?.state;\n\treturn state !== undefined && Atomics.load(state, 0) !== FREE;\n}\n\n/** How often calls refused a lock that no transaction of this thread holds (another process's) are tried again. */\nconst POLL_MS = 20;\n\n/**\n * Tries the oldest waiting call again every `POLL_MS` while calls wait, for locks no word announces. While the word is\n * taken, the watch on it (`watchWord`) wakes the calls instead.\n */\nfunction pollWaiters(file: string, gate: FileGate): void {\n\tif (gate.polling || gate.waiters.length === 0) return;\n\tgate.polling = true;\n\tsetTimeout(() => {\n\t\tgate.polling = false;\n\t\tif (!wordTaken(file)) runNextWaiter(file, gate);\n\t\tforgetIfIdle(file, gate);\n\t\tpollWaiters(file, gate);\n\t}, POLL_MS);\n}\n\n/**\n * The statements of an `exec` text, split as SQLite reads them: past quoted strings and names (`'…'`, `\"…\"`, `` `…` ``,\n * `[…]`) and comments, with a trigger's body (`CREATE TRIGGER … BEGIN … END`) kept in its statement. Empty statements\n * are dropped. A comment left open runs to the end of the text; past a quote left open, or in a trigger's body without\n * its END, the rest of the text is one statement, which SQLite fails.\n */\nexport function splitStatements(sql: string): string[] {\n\tconst statements: string[] = [];\n\tlet start = 0;\n\tlet words: string[] = [];\n\tlet lastWord = \"\";\n\tlet tokens = false;\n\tconst trigger = () =>\n\t\twords[0] === \"CREATE\" &&\n\t\t(words[1] === \"TRIGGER\" || ((words[1] === \"TEMP\" || words[1] === \"TEMPORARY\") && words[2] === \"TRIGGER\"));\n\tfor (let index = 0; index < sql.length; ) {\n\t\tconst char = sql[index]!;\n\t\tif (char === \"'\" || char === '\"' || char === \"`\" || char === \"[\") {\n\t\t\tconst close = char === \"[\" ? \"]\" : char;\n\t\t\tlet end = sql.indexOf(close, index + 1);\n\t\t\t// A doubled quote stands for the quote itself, except in a bracketed name.\n\t\t\twhile (end !== -1 && close !== \"]\" && sql[end + 1] === close) end = sql.indexOf(close, end + 2);\n\t\t\ttokens = true;\n\t\t\t// Unterminated: SQLite fails the statement there, after the ones before it ran.\n\t\t\tif (end === -1) break;\n\t\t\tindex = end + 1;\n\t\t\tlastWord = \"\";\n\t\t} else if (char === \"-\" && sql[index + 1] === \"-\") {\n\t\t\tconst end = sql.indexOf(\"\\n\", index + 2);\n\t\t\tindex = end === -1 ? sql.length : end + 1;\n\t\t} else if (char === \"/\" && sql[index + 1] === \"*\") {\n\t\t\t// Unterminated, the comment runs to the end of the text.\n\t\t\tconst end = sql.indexOf(\"*/\", index + 2);\n\t\t\tindex = end === -1 ? sql.length : end + 2;\n\t\t} else if (char === \";\") {\n\t\t\tindex += 1;\n\t\t\t// Inside a trigger's body, only the semicolon after its END ends the statement.\n\t\t\tif (trigger() && lastWord !== \"END\") continue;\n\t\t\tif (tokens) statements.push(sql.slice(start, index - 1));\n\t\t\tstart = index;\n\t\t\twords = [];\n\t\t\tlastWord = \"\";\n\t\t\ttokens = false;\n\t\t} else if (/[A-Za-z_]/.test(char)) {\n\t\t\tlet end = index + 1;\n\t\t\twhile (end < sql.length && /[\\w$]/.test(sql[end]!)) end += 1;\n\t\t\tconst word = sql.slice(index, end).toUpperCase();\n\t\t\tif (words.length < 3) words.push(word);\n\t\t\tlastWord = word;\n\t\t\ttokens = true;\n\t\t\tindex = end;\n\t\t} else {\n\t\t\tif (!/\\s/.test(char)) {\n\t\t\t\ttokens = true;\n\t\t\t\tlastWord = \"\";\n\t\t\t}\n\t\t\tindex += 1;\n\t\t}\n\t}\n\t// Past an unterminated quote, or in a trigger's body without its END, SQLite fails the rest as one statement.\n\tif (tokens) statements.push(sql.slice(start));\n\treturn statements;\n}\n\n/**\n * The steps of the plan of `sql`, listed now from the plan kept for it (SQLite prepares a kept plan again when this\n * connection changed its schema since, and fails it if the statement no longer prepares), or from a new one; undefined\n * when SQLite cannot make one. The plan is bound to the call's `params` first, so parameters the statement cannot\n * bind fail before the plan is listed, which resets `changes()` (see `modeOf`), as the statement fails before it runs.\n */\nfunction planSteps(\n\tgate: FileGate,\n\towner: object,\n\tdatabase: DatabaseSync,\n\tsql: string,\n\tparams: readonly SQLInputValue[],\n): ReturnType<StatementSync[\"all\"]> | undefined {\n\tconst plans = plansOf(gate, owner);\n\tconst kept = plans.explained.get(sql);\n\tif (kept !== undefined) {\n\t\ttry {\n\t\t\treturn kept.all(...params);\n\t\t} catch {\n\t\t\tplans.explained.delete(sql);\n\t\t}\n\t}\n\ttry {\n\t\tconst explained = database.prepare(`EXPLAIN ${sql}`);\n\t\tconst steps = explained.all(...params);\n\t\tif (plans.explained.size >= MAX_PLANS) plans.explained.delete(plans.explained.keys().next().value!);\n\t\tplans.explained.set(sql, explained);\n\t\treturn steps;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nlet sqliteErrorShape: { readonly prototype: object; readonly ownCode: boolean } | undefined;\n\n/**\n * How the runtime's node:sqlite builds its errors: their class (Bun has one of its own) and whether `code` is a field\n * of each error, read once from a failure of a connection of this module's own. Plain `Error` fields when it cannot\n * be read.\n */\nfunction errorShape(): { readonly prototype: object; readonly ownCode: boolean } {\n\tif (sqliteErrorShape !== undefined) return sqliteErrorShape;\n\tsqliteErrorShape = { prototype: Error.prototype, ownCode: true };\n\ttry {\n\t\tconst { DatabaseSync: Database } = createRequire(import.meta.url)(\"node:sqlite\") as typeof import(\"node:sqlite\");\n\t\tconst probe = new Database(\":memory:\");\n\t\ttry {\n\t\t\tprobe.exec(\"SELECT\");\n\t\t} catch (error) {\n\t\t\tif (error instanceof Error)\n\t\t\t\tsqliteErrorShape = {\n\t\t\t\t\tprototype: Object.getPrototypeOf(error) as object,\n\t\t\t\t\townCode: Object.hasOwn(error, \"code\"),\n\t\t\t\t};\n\t\t} finally {\n\t\t\tprobe.close();\n\t\t}\n\t} catch {\n\t\t// The plain shape stands.\n\t}\n\treturn sqliteErrorShape;\n}\n\n/**\n * SQLITE_BUSY as the runtime's node:sqlite reports it, for a call that waited out its busy timeout without running:\n * the runtime's own error class with the fields a refused statement carries.\n */\nexport function sqliteBusyError(): Error {\n\tconst shape = errorShape();\n\tconst error = Object.setPrototypeOf(new Error(\"database is locked\"), shape.prototype) as Error;\n\tconst fields: Record<string, unknown> = { errcode: 5, errstr: \"database is locked\" };\n\treturn Object.assign(error, shape.ownCode ? { code: \"ERR_SQLITE_ERROR\", ...fields } : fields);\n}\n"]}
|
|
@@ -686,7 +686,7 @@ function __atomicOnDemandFailed(error, feature) {
|
|
|
686
686
|
return (async () => {
|
|
687
687
|
const root = new URL("../../", import.meta.url);
|
|
688
688
|
const releases = (globalThis[Symbol.for("atomic.in-place-update-release.v1")] ??= new Map());
|
|
689
|
-
const key = `${root.href}#0.10.
|
|
689
|
+
const key = `${root.href}#0.10.16-alpha.1`;
|
|
690
690
|
let release = releases.get(key);
|
|
691
691
|
if (release === undefined) {
|
|
692
692
|
const current = (async () => {
|
|
@@ -714,7 +714,7 @@ function __atomicOnDemandFailed(error, feature) {
|
|
|
714
714
|
} catch {
|
|
715
715
|
// No installation to read, as in a bundle of the package: the release the process runs decides.
|
|
716
716
|
}
|
|
717
|
-
const updatedTo = typeof installed === "string" && installed !== "0.10.
|
|
717
|
+
const updatedTo = typeof installed === "string" && installed !== "0.10.16-alpha.1" ? installed : running !== undefined && running.version !== "0.10.16-alpha.1" ? "0.10.16-alpha.1" : undefined;
|
|
718
718
|
if (updatedTo === undefined) throw error;
|
|
719
719
|
const application = typeof running?.name === "string" ? running.name : "atomic";
|
|
720
720
|
const restart = new Error(`${application} was updated to ${updatedTo} while this session was running; restart it to keep using ${feature}.`, {
|
|
@@ -2773,7 +2773,7 @@ function __atomicOnDemandFailed(error, feature) {
|
|
|
2773
2773
|
return (async () => {
|
|
2774
2774
|
const root = new URL("../../", import.meta.url);
|
|
2775
2775
|
const releases = (globalThis[Symbol.for("atomic.in-place-update-release.v1")] ??= new Map());
|
|
2776
|
-
const key = `${root.href}#0.10.
|
|
2776
|
+
const key = `${root.href}#0.10.16-alpha.1`;
|
|
2777
2777
|
let release = releases.get(key);
|
|
2778
2778
|
if (release === undefined) {
|
|
2779
2779
|
const current = (async () => {
|
|
@@ -2801,7 +2801,7 @@ function __atomicOnDemandFailed(error, feature) {
|
|
|
2801
2801
|
} catch {
|
|
2802
2802
|
// No installation to read, as in a bundle of the package: the release the process runs decides.
|
|
2803
2803
|
}
|
|
2804
|
-
const updatedTo = typeof installed === "string" && installed !== "0.10.
|
|
2804
|
+
const updatedTo = typeof installed === "string" && installed !== "0.10.16-alpha.1" ? installed : running !== undefined && running.version !== "0.10.16-alpha.1" ? "0.10.16-alpha.1" : undefined;
|
|
2805
2805
|
if (updatedTo === undefined) throw error;
|
|
2806
2806
|
const application = typeof running?.name === "string" ? running.name : "atomic";
|
|
2807
2807
|
const restart = new Error(`${application} was updated to ${updatedTo} while this session was running; restart it to keep using ${feature}.`, {
|
|
@@ -6,7 +6,7 @@ try {
|
|
|
6
6
|
} catch (error) {
|
|
7
7
|
const root = new URL("../../", import.meta.url);
|
|
8
8
|
const releases = (globalThis[Symbol.for("atomic.in-place-update-release.v1")] ??= new Map());
|
|
9
|
-
const key = `${root.href}#0.10.
|
|
9
|
+
const key = `${root.href}#0.10.16-alpha.1`;
|
|
10
10
|
let release = releases.get(key);
|
|
11
11
|
if (release === undefined) {
|
|
12
12
|
const current = (async () => {
|
|
@@ -27,8 +27,8 @@ try {
|
|
|
27
27
|
release = current;
|
|
28
28
|
}
|
|
29
29
|
const running = await release;
|
|
30
|
-
if (running === undefined || running.version === "0.10.
|
|
31
|
-
throw new Error((typeof running.name === "string" ? running.name : "atomic") + " was updated to 0.10.
|
|
30
|
+
if (running === undefined || running.version === "0.10.16-alpha.1") throw error;
|
|
31
|
+
throw new Error((typeof running.name === "string" ? running.name : "atomic") + " was updated to 0.10.16-alpha.1 while this session was running; restart it to keep using session storage.", {
|
|
32
32
|
cause: error,
|
|
33
33
|
});
|
|
34
34
|
}
|
|
@@ -6,7 +6,7 @@ try {
|
|
|
6
6
|
} catch (error) {
|
|
7
7
|
const root = new URL("../../", import.meta.url);
|
|
8
8
|
const releases = (globalThis[Symbol.for("atomic.in-place-update-release.v1")] ??= new Map());
|
|
9
|
-
const key = `${root.href}#0.10.
|
|
9
|
+
const key = `${root.href}#0.10.16-alpha.1`;
|
|
10
10
|
let release = releases.get(key);
|
|
11
11
|
if (release === undefined) {
|
|
12
12
|
const current = (async () => {
|
|
@@ -27,8 +27,8 @@ try {
|
|
|
27
27
|
release = current;
|
|
28
28
|
}
|
|
29
29
|
const running = await release;
|
|
30
|
-
if (running === undefined || running.version === "0.10.
|
|
31
|
-
throw new Error((typeof running.name === "string" ? running.name : "atomic") + " was updated to 0.10.
|
|
30
|
+
if (running === undefined || running.version === "0.10.16-alpha.1") throw error;
|
|
31
|
+
throw new Error((typeof running.name === "string" ? running.name : "atomic") + " was updated to 0.10.16-alpha.1 while this session was running; restart it to keep using session storage.", {
|
|
32
32
|
cause: error,
|
|
33
33
|
});
|
|
34
34
|
}
|
|
@@ -65,6 +65,9 @@ export const POSTGRES_STORAGE_IDENTIFIER_SUFFIXES = Object.freeze([
|
|
|
65
65
|
"session_chat_v1",
|
|
66
66
|
"session_chat_v1_anchor",
|
|
67
67
|
"session_entries",
|
|
68
|
+
"session_entries_capture_head",
|
|
69
|
+
"session_entries_capture_head_fn",
|
|
70
|
+
"session_entries_capture_heading",
|
|
68
71
|
"session_entries_search_forget",
|
|
69
72
|
"session_entries_search_forget_fn",
|
|
70
73
|
"session_entries_snapshot_links",
|