@bastani/atomic 0.10.11-alpha.2 → 0.10.11
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 +307 -0
- package/README.md +5 -8
- package/dist/_shared/dist-KOELCESV.js +2 -2
- package/dist/_shared/fork-row-index-UAUAQRD5.js +2 -2
- package/dist/_shared/lib-4PES5P4V.js +2 -2
- package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js +6 -6
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +5 -5
- package/dist/_shared/mode-shared-2QJSCUM6.js +6 -6
- package/dist/_shared/p0-cli-BB45ZQY6.js +46 -67
- package/dist/_shared/p0-cli-BB45ZQY6.js.map +1 -1
- package/dist/_shared/p1a-prewarm-XIU57JHF.js +7 -8
- package/dist/_shared/p1a-prewarm-XIU57JHF.js.map +1 -1
- package/dist/_shared/{p1b-elig-ENCUPKKJ.js → p1b-elig-TVB5CBLL.js} +36 -8
- package/dist/_shared/p1b-elig-TVB5CBLL.js.map +1 -0
- package/dist/_shared/p2-shell-main-B2WIALFD.js +6 -3
- package/dist/_shared/p2-shell-main-B2WIALFD.js.map +1 -1
- package/dist/_shared/runtime-O4KCSG4C.js +3 -3
- package/dist/_shared/{sdk-IQMULKFU.js → sdk-B5LEWGGI.js} +1218 -657
- package/dist/_shared/sdk-B5LEWGGI.js.map +1 -0
- package/dist/_shared/session-data-AHTU7IS6.js +2 -2
- package/dist/_shared/session-manager-list-2BLEEZVG.js +1 -1
- package/dist/_shared/{startup-0-0-3IXNMFM2.js → startup-0-0-XJJDOIEC.js} +50 -48
- package/dist/_shared/startup-0-0-XJJDOIEC.js.map +1 -0
- package/dist/_shared/{startup-0-1-7T2IAE7J.js → startup-0-1-M6OWAYHH.js} +540 -136
- package/dist/_shared/startup-0-1-M6OWAYHH.js.map +1 -0
- package/dist/_shared/startup-0-2-5QHPCEON.js +47 -48
- package/dist/_shared/startup-0-2-5QHPCEON.js.map +1 -1
- package/dist/_shared/startup-0-3-4ZYBYQNM.js +5 -5
- package/dist/_shared/startup-0-4-ZMJV547D.js +12 -7
- package/dist/_shared/startup-0-4-ZMJV547D.js.map +1 -1
- package/dist/_shared/startup-0-5-YDW47QX6.js +7 -7
- package/dist/_shared/startup-0-5-YDW47QX6.js.map +1 -1
- package/dist/_shared/startup-10-0-TDQNBDDL.js +6 -6
- package/dist/_shared/startup-12-0-55AAXBJZ.js +2 -2
- package/dist/_shared/startup-14-0-MLX36RBG.js +4 -5
- package/dist/_shared/startup-14-0-MLX36RBG.js.map +1 -1
- package/dist/_shared/startup-15-0-YUKGAC63.js +4 -4
- package/dist/_shared/startup-15-1-4S7FLMNG.js +19 -27
- package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
- package/dist/_shared/startup-8-0-34CBHPZH.js +2144 -249
- package/dist/_shared/startup-8-0-34CBHPZH.js.map +1 -1
- package/dist/_shared/{startup-8-1-X32CYSXB.js → startup-8-1-LZFXSD3Z.js} +98 -1184
- package/dist/_shared/startup-8-1-LZFXSD3Z.js.map +1 -0
- package/dist/_shared/storage-command-7MGXLJGZ.js +188 -37
- package/dist/_shared/storage-command-7MGXLJGZ.js.map +1 -1
- package/dist/_shared/storage-status-K7PX2RXA.js +557 -0
- package/dist/_shared/storage-status-K7PX2RXA.js.map +1 -0
- package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
- package/dist/_shared/team-DOQKICG2.js +376 -0
- package/dist/_shared/team-DOQKICG2.js.map +1 -0
- package/dist/_shared/tree-outline-MUEPK5B7.js +2 -2
- package/dist/builtin/intercom/CHANGELOG.md +88 -0
- package/dist/builtin/intercom/README.md +2 -2
- package/dist/builtin/intercom/broker/broker.bundle.mjs +1917 -381
- package/dist/builtin/intercom/broker/client.ts +8 -0
- package/dist/builtin/intercom/broker/database-wake-up-bus.ts +324 -68
- package/dist/builtin/intercom/broker/multinode-router.ts +256 -39
- package/dist/builtin/intercom/broker/multinode-state-store.ts +71 -5
- package/dist/builtin/intercom/broker/open-broker-state.ts +14 -0
- package/dist/builtin/intercom/broker/send-order-gate.ts +5 -2
- package/dist/builtin/intercom/broker/sql-add-column.ts +50 -5
- package/dist/builtin/intercom/broker/sql-ended-child-queue-store.ts +3 -2
- package/dist/builtin/intercom/broker/sql-held-send-store.ts +2 -2
- package/dist/builtin/intercom/broker/sql-known-session-store.ts +43 -19
- package/dist/builtin/intercom/broker/sql-lease-store.ts +473 -121
- package/dist/builtin/intercom/broker/sql-outbox-store.ts +821 -79
- package/dist/builtin/intercom/broker/sql-pending-ask-store.ts +8 -5
- package/dist/builtin/intercom/broker/sql-released-ask-store.ts +12 -5
- package/dist/builtin/intercom/broker/sql-restoring-reservation-store.ts +256 -8
- package/dist/builtin/intercom/broker/sql-retention.ts +150 -0
- package/dist/builtin/intercom/broker/sql-schema.ts +175 -24
- package/dist/builtin/intercom/broker/sql-sent-message-authority.ts +74 -19
- package/dist/builtin/intercom/broker/wake-up-bus.ts +6 -0
- package/dist/builtin/intercom/index.bundle.mjs +14 -4
- 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 +20 -0
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/skills/skill-creator/eval-viewer/generate_review.py +8 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +1 -1
- package/dist/builtin/web-access/index.bundle.mjs +2 -10
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/bun/bundled-sqlite.js +41 -0
- package/dist/bun/bundled-sqlite.js.map +1 -0
- package/dist/cli/args.js +2 -2
- package/dist/cli/auth-cli.code.js +4 -4
- package/dist/cli/auth-cli.impl.js +3 -3
- package/dist/cli/auth-cli.js +3 -3
- package/dist/cli/blueprint-command.code.js +3 -3
- 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.code.js.map +1 -1
- 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 +1 -1
- package/dist/cli/session-picker.impl.js +3 -3
- package/dist/cli/session-picker.js +3 -3
- package/dist/cli/startup-ui.code.js +1 -1
- 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 +3 -3
- 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 +19 -113
- package/dist/cli/team-command.code.js.map +1 -1
- package/dist/cli/team-command.impl.js +3 -3
- package/dist/cli/team-command.js +3 -3
- package/dist/cli.js +5 -18
- package/dist/cli.js.map +1 -1
- package/dist/core/agent-rehydrate-errors.d.ts +4 -9
- package/dist/core/compaction/compactor.d.ts +3 -3
- 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.impl.js +3 -3
- package/dist/core/export-html/card-projection.js +3 -3
- package/dist/core/export-html/index.code.js +4 -4
- package/dist/core/export-html/index.code.js.map +1 -1
- 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.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 +1 -1
- package/dist/core/extensions/runner-context.js +2 -2
- package/dist/core/intercom-broker-control-host.code.js +2 -2
- 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/package-manager-storage-adapters.code.js +1 -1
- package/dist/core/package-manager-storage-adapters.impl.js +3 -3
- package/dist/core/package-manager-storage-adapters.js +3 -3
- package/dist/core/process-start-token.d.ts +12 -3
- package/dist/core/process-tree-containment.d.ts +16 -0
- package/dist/core/sdk-types.d.ts +1 -2
- package/dist/core/sdk-types.js.map +1 -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 +5 -5
- package/dist/core/session-manager-list.impl.js +3 -3
- package/dist/core/session-manager-list.js +3 -3
- package/dist/core/session-manager.code.js +1 -1
- package/dist/core/session-manager.impl.js +3 -3
- package/dist/core/session-manager.js +3 -3
- package/dist/core/session-storage.code.js +1 -1
- package/dist/core/session-storage.impl.js +3 -3
- package/dist/core/session-storage.js +3 -3
- package/dist/core/settings-schema.d.ts +0 -3
- package/dist/core/storage/added-exports-0-10-11.js +19 -0
- package/dist/core/storage/added-exports-0-10-11.js.map +1 -0
- package/dist/core/storage/creation-time.js +105 -0
- package/dist/core/storage/creation-time.js.map +1 -0
- package/dist/core/storage/database.d.ts +25 -5
- package/dist/core/storage/database.js.map +1 -1
- package/dist/core/storage/dialect.d.ts +1 -1
- package/dist/core/storage/dialect.js +1 -1
- package/dist/core/storage/dialect.js.map +1 -1
- package/dist/core/storage/errors.d.ts +13 -13
- package/dist/core/storage/errors.js +10 -16
- package/dist/core/storage/errors.js.map +1 -1
- package/dist/core/storage/fenced-paths.d.ts +18 -6
- package/dist/core/storage/fenced-paths.js +18 -6
- package/dist/core/storage/fenced-paths.js.map +1 -1
- package/dist/core/storage/file-identity.d.ts +2 -0
- package/dist/core/storage/file-identity.js +24 -8
- package/dist/core/storage/file-identity.js.map +1 -1
- package/dist/core/storage/index.d.ts +3 -2
- package/dist/core/storage/index.js +5 -3
- package/dist/core/storage/index.js.map +1 -1
- package/dist/core/storage/libsql-removed.d.ts +71 -0
- package/dist/core/storage/libsql-removed.js +123 -0
- package/dist/core/storage/libsql-removed.js.map +1 -0
- package/dist/core/storage/migrations.d.ts +78 -14
- package/dist/core/storage/migrations.js +375 -49
- package/dist/core/storage/migrations.js.map +1 -1
- package/dist/core/storage/node-sqlite-file-gate.js +0 -15
- package/dist/core/storage/node-sqlite-file-gate.js.map +1 -1
- package/dist/core/storage/node-sqlite-thread.js +215 -30
- package/dist/core/storage/node-sqlite-thread.js.map +1 -1
- package/dist/core/storage/node-sqlite.js +484 -72
- package/dist/core/storage/node-sqlite.js.map +1 -1
- 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.d.ts +1 -1
- package/dist/core/storage/prefix.js +9 -2
- package/dist/core/storage/prefix.js.map +1 -1
- package/dist/core/storage/process-selection.d.ts +5 -5
- package/dist/core/storage/provider.js +2 -2
- package/dist/core/storage/schema-catalog.d.ts +76 -15
- package/dist/core/storage/schema-catalog.js +359 -68
- package/dist/core/storage/schema-catalog.js.map +1 -1
- package/dist/core/storage/selection.d.ts +7 -82
- package/dist/core/storage/selection.js +20 -235
- package/dist/core/storage/selection.js.map +1 -1
- 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 +3 -3
- 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.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 +2 -2
- 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-detach.d.ts +11 -1
- 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 +4 -7
- package/dist/core/storage/session/fork-staging.code.js.map +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-sweep.js +31 -7
- package/dist/core/storage/session/fork-sweep.js.map +1 -1
- package/dist/core/storage/session/fork-window.code.js +3 -3
- 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-lock.d.ts +100 -0
- package/dist/core/storage/session/jsonl-session-store.d.ts +46 -24
- 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.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 +9 -9
- package/dist/core/storage/session/released-history-files.code.js.map +1 -1
- 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/session-search-index.d.ts +52 -5
- 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 +3 -3
- 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.code.js +1 -1
- package/dist/core/storage/session/sql-session-store.d.ts +99 -18
- 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.impl.js +3 -3
- package/dist/core/storage/session/tree-presentation.js +3 -3
- package/dist/core/storage/sqlite-facade.d.ts +12 -1
- package/dist/core/storage/sqlite-facade.js +310 -33
- package/dist/core/storage/sqlite-facade.js.map +1 -1
- package/dist/core/storage/sqlite-open-batch.js +10 -0
- package/dist/core/storage/sqlite-open-batch.js.map +1 -0
- package/dist/core/storage/storage-status.code.js +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.code.js +1 -1
- package/dist/core/storage/team.d.ts +26 -115
- package/dist/core/storage/team.impl.js +3 -3
- package/dist/core/storage/team.js +3 -3
- package/dist/core/structured-output/index.code.js +1 -1
- package/dist/core/structured-output/index.impl.js +3 -3
- package/dist/core/structured-output/index.js +3 -3
- 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 +4 -4
- 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.code.js +1 -1
- 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/history-tasks.d.ts +3 -2
- package/dist/core/tools/read-url.code.js +4 -4
- 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.d.ts +44 -5
- package/dist/core/worktree-snapshot/blob-store.js +553 -30
- package/dist/core/worktree-snapshot/blob-store.js.map +1 -1
- package/dist/core/worktree-snapshot/errors.code.js +2 -2
- package/dist/core/worktree-snapshot/errors.impl.js +3 -3
- package/dist/core/worktree-snapshot/errors.js +3 -3
- package/dist/core/worktree-snapshot/fork-blob-guard.js +81 -0
- package/dist/core/worktree-snapshot/fork-blob-guard.js.map +1 -0
- package/dist/core/worktree-snapshot/fork-snapshot-index.js +208 -50
- package/dist/core/worktree-snapshot/fork-snapshot-index.js.map +1 -1
- package/dist/core/worktree-snapshot/session-index-reset.code.js +4 -0
- package/dist/core/worktree-snapshot/session-index-reset.code.js.map +1 -1
- 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 +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 +2 -2
- package/dist/extensions/codemode/renderer.impl.js +3 -3
- package/dist/extensions/codemode/renderer.js +3 -3
- package/dist/extensions/mcp/cli.code.js +3 -3
- 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.code.js +1 -1
- package/dist/extensions/mcp/runtime.impl.js +3 -3
- package/dist/extensions/mcp/runtime.js +3 -3
- package/dist/index.d.ts +3 -1
- package/dist/index.js +5 -5
- package/dist/main-first-time-setup.code.js +1 -1
- package/dist/main-first-time-setup.impl.js +3 -3
- package/dist/main-first-time-setup.js +3 -3
- package/dist/main.js +1 -1
- package/dist/modes/interactive/components/stored-tree-view.code.js +2 -2
- 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.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/modes/interactive-engine/engine-prewarm.d.ts +1 -1
- package/dist/modes/print-mode.js +1 -1
- package/dist/package-manager-cli.code.js +6 -6
- 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/2.js +2 -4
- package/dist/startup-stages/3.js +1 -3
- package/dist/startup-stages/4.js +1 -2
- package/dist/startup-stages/5.js +1 -1
- package/dist/startup-stages/6.js +5 -7
- package/dist/startup-stages/7.js +3 -10
- package/dist/startup-stages/8.js +7 -2
- package/dist/startup-stages/9.js +1 -7
- package/dist/startup-stages/stages.json +1 -1
- package/dist/utils/compile-cache-deferral.js +8 -13
- package/dist/utils/compile-cache-deferral.js.map +1 -1
- package/dist/utils/compile-cache-warmup-host.js +3 -4
- package/dist/utils/compile-cache-warmup-host.js.map +1 -1
- package/dist/utils/compile-cache.js +12 -100
- package/dist/utils/compile-cache.js.map +1 -1
- package/dist/utils/startup-database-spare.code.js +2 -2
- 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/worker-threads.js +2 -15
- package/dist/utils/worker-threads.js.map +1 -1
- package/docs/build.md +3 -3
- package/docs/changelog.mdx +1498 -69
- package/docs/compaction/reference.md +5 -5
- package/docs/compaction.md +7 -9
- package/docs/containerization.md +2 -2
- package/docs/custom-provider/api-reference.md +1 -1
- package/docs/docs.json +37 -10
- package/docs/environment-variables.md +0 -2
- package/docs/extensions/api-reference.md +4 -4
- package/docs/getting-started/installation.md +3 -0
- package/docs/guides/configuration.md +1 -1
- package/docs/guides/non-interactive.md +1 -1
- package/docs/guides/resume-on-any-machine.md +14 -22
- package/docs/guides/team-setup.md +56 -83
- package/docs/guides.md +2 -4
- package/docs/herdr.md +1 -1
- package/docs/index.md +1 -1
- package/docs/intercom/operations.md +26 -21
- package/docs/intercom/reference.md +2 -2
- package/docs/intercom.md +1 -1
- package/docs/libraries/storage-postgres.md +9 -9
- package/docs/libraries.md +2 -3
- package/docs/models-configuration.md +2 -2
- package/docs/models.md +2 -3
- package/docs/packages/authoring.md +7 -7
- package/docs/packages.md +1 -1
- package/docs/programmatic.md +2 -2
- package/docs/quickstart.md +1 -1
- package/docs/reference/cli.md +6 -11
- package/docs/reference.md +2 -2
- package/docs/rpc/extension-ui.md +2 -2
- package/docs/sdk/reference.md +5 -4
- package/docs/sdk/storage.md +8 -92
- package/docs/sdk/structured-decisions.md +1 -1
- package/docs/sdk/web-server.md +3 -3
- package/docs/sdk.md +14 -4
- package/docs/security.md +1 -1
- package/docs/session-format.md +5 -5
- package/docs/sessions.md +29 -49
- package/docs/settings.md +7 -8
- package/docs/storage/custom-adapters.md +255 -0
- package/docs/storage/jsonl.md +117 -0
- package/docs/{guides/postgres-pgbouncer.md → storage/postgres/pgbouncer.md} +66 -68
- package/docs/storage/postgres/tuning.md +337 -0
- package/docs/storage/postgres.md +556 -0
- package/docs/storage/sqlite.md +99 -0
- package/docs/storage.md +326 -990
- package/docs/subagents/authoring.md +1 -1
- package/docs/subagents.md +2 -2
- package/docs/tools.md +1 -1
- package/docs/worktree-snapshots.md +2 -2
- package/package.json +9 -9
- package/schemas/models.schema.json +2 -2
- package/schemas/settings.schema.json +0 -14
- package/dist/_shared/p1b-elig-ENCUPKKJ.js.map +0 -1
- package/dist/_shared/sdk-IQMULKFU.js.map +0 -1
- package/dist/_shared/startup-0-0-3IXNMFM2.js.map +0 -1
- package/dist/_shared/startup-0-1-7T2IAE7J.js.map +0 -1
- package/dist/_shared/startup-8-1-X32CYSXB.js.map +0 -1
- package/dist/core/intercom-broker-control.d.ts +0 -129
- package/dist/startup-stages/13.js +0 -1
- package/docs/guides/postgres-tuning.md +0 -311
- package/docs/libraries/storage-libsql.md +0 -97
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-catalog.js","sourceRoot":"","sources":["../../../src/core/storage/schema-catalog.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,iBAAiB,MAAM,yBAAyB,CAAC;AAE7D;;;;GAIG;AACH,MAAM,SAAS,GAAmE,iBAAiB,CAAC;AA8BpG,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,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C,EACD,EAAE,sBAAsB,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,EAAE,CACvF,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,QAAQ;YAAE,MAAM,KAAK,CAAC;QAC1B,mCAAmC;IACpC,CAAC;AACF,CAAC","sourcesContent":["import type { SqliteDatabase, SqliteExecutor, SqliteRow } from \"./database.js\";\nimport { dialectOf } from \"./dialect.js\";\nimport * as statementSequence from \"./statement-sequence.js\";\n\n/**\n * `transactionFinisher` of `statement-sequence.ts`, which the copy of that module 0.10.3 and 0.10.4 loaded lacks: a\n * process an in-place update caught keeps that copy, where a named import would fail to link. Without it the stamps\n * go out on their own, before the commit.\n */\nconst finishers: Partial<Pick<typeof statementSequence, \"transactionFinisher\">> = statementSequence;\n\n/**\n * What a schema held when one open read it: its relations, triggers and columns, and on PostgreSQL the versions its\n * ledger records. Only a positive answer is final: the schema only moves forward, so what existed then still exists,\n * while something missing may have been created since and is checked again under the store's lock.\n */\nexport interface StorageSchemaCatalog {\n\t/** The ledger the versions were read from. */\n\treadonly ledger: string;\n\t/** The highest version `ledger` recorded for `domain`; 0 when none, or when the ledger did not exist. */\n\trecordedVersion(domain: string): number;\n\t/** Whether a table (or view) named `table` existed. */\n\thasTable(table: string): boolean;\n\t/** Whether a relation (table, index, sequence…) or a trigger named `name` existed. */\n\thasObject(name: string): boolean;\n\t/** Whether `table` had a column named `column`. */\n\thasColumn(table: string, column: string): boolean;\n\t/**\n\t * Whether a function named `name` existed in the schema and this role may run it: PostgreSQL only, absent on SQLite\n\t * and libSQL.\n\t */\n\treadonly hasFunction?: (name: string) => boolean;\n\t/**\n\t * What kind of object `name` was on SQLite and libSQL (`table`, `index`, `view` or `trigger`), from one read of\n\t * `sqlite_schema`; undefined when there was none, and always on PostgreSQL.\n\t */\n\treadonly sqliteObjectType?: (name: string) => string | undefined;\n}\n\nconst TABLE_KINDS = new Set([\"r\", \"p\", \"v\", \"m\", \"f\"]);\n\n/**\n * Every relation, trigger, column and function of the schema the statement runs in, in one statement and so one\n * snapshot. The catalog, not information_schema, finds relations, as `tableExists` does; columns come from\n * information_schema, as `columnExists` reads them. A function is listed with whether this role may execute it.\n */\nconst CATALOG_SQL = `SELECT 'relation' AS kind, c.relname::text AS name, c.relkind::text AS detail\n\tFROM pg_catalog.pg_class c WHERE c.relnamespace = current_schema()::regnamespace\nUNION ALL SELECT 'trigger', t.tgname::text, NULL\n\tFROM pg_catalog.pg_trigger t JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid\n\tWHERE c.relnamespace = current_schema()::regnamespace AND NOT t.tgisinternal\nUNION ALL SELECT 'column', table_name::text, column_name::text\n\tFROM information_schema.columns WHERE table_schema = current_schema()\nUNION ALL SELECT 'function', p.proname::text, CASE WHEN has_function_privilege(p.oid, 'EXECUTE') THEN 'executable' END\n\tFROM pg_catalog.pg_proc p WHERE p.pronamespace = current_schema()::regnamespace`;\n\ntype CatalogRow = SqliteRow & { kind: string; name: string; detail: string | null };\n\n/**\n * Every object of a SQLite or libSQL database and every column of its tables, generated ones included, in one\n * statement and so one snapshot: what `tableExists`, `columnExists` and `schemaObjects` ask one at a time (#6560).\n */\nconst SQLITE_CATALOG_SQL = `SELECT 'object' AS kind, name, type AS detail FROM sqlite_master\nUNION ALL SELECT 'column', m.name, c.name FROM sqlite_master AS m JOIN pragma_table_xinfo(m.name) AS c\n\tWHERE m.type = 'table'`;\n\n/**\n * @internal The table under `ledger`'s prefix where SQLite and libSQL record which revision of each store's schema\n * setup ran, and the database's schema version (`PRAGMA schema_version`) once it had: `domain`, `revision`,\n * `schema_version`. SQLite counts every change to the schema in that version, whoever makes it, an older Atomic that\n * records nothing included; a revision is believed only while the version still matches, so any later change is checked\n * again (#6560). Builds that do not know the table leave it alone.\n */\nexport function sqliteSchemaStampTable(ledger: string): string {\n\treturn ledger.endsWith(\"atomic_migrations\")\n\t\t? `${ledger.slice(0, -\"atomic_migrations\".length)}atomic_schema_stamps`\n\t\t: `${ledger}_schema_stamps`;\n}\n\n/** The key a store's setup is stamped under, as the PostgreSQL ledger records it. */\nconst stampKey = (domain: string) => `schema:${domain}`;\n\ntype StampRow = SqliteRow & { domain: string | null; revision: number | bigint | null; stamped: number | bigint };\n\n/**\n * The revisions `ledger`'s stamps record whose schema version is the database's now, by stamp key, read in one\n * statement so the two agree. Stamps of an older schema version are left out: something changed the schema since.\n */\nasync function readSqliteSchemaStamps(executor: SqliteExecutor, ledger: string): Promise<Map<string, number>> {\n\tconst rows = await executor.all<StampRow>(\n\t\t`SELECT domain, revision, schema_version AS stamped FROM ${sqliteSchemaStampTable(ledger)}\n\t\tUNION ALL SELECT NULL, NULL, schema_version FROM pragma_schema_version`,\n\t);\n\tconst now = rows.find((row) => row.domain === null)?.stamped;\n\tconst stamps = new Map<string, number>();\n\tfor (const row of rows)\n\t\tif (row.domain !== null && now !== undefined && Number(row.stamped) === Number(now))\n\t\t\tstamps.set(row.domain, Number(row.revision ?? 0));\n\treturn stamps;\n}\n\n/** @internal A store's schema setup, as its stamp records it: `ledger` names the prefix, `domain` the store. */\nexport interface SqliteSchemaStamp {\n\treadonly ledger: string;\n\treadonly domain: string;\n\treadonly revision: number;\n}\n\n/**\n * @internal Stamps each of `stamps`, in the transaction `tx` that ran their setups, with the schema version as that\n * transaction leaves it: a later open believes their revisions until the schema changes again (#6560). Creates the\n * stamps table first, unless `options.tableExists`, so its own creation is part of the version recorded. With\n * `options.last`, the stamps are the transaction's last statement: where its connection is pipelined, they go out with\n * its commit. SQLite and libSQL only; every stamp must share a ledger.\n */\nexport async function recordSqliteSchemaStamps(\n\ttx: SqliteExecutor,\n\tstamps: readonly SqliteSchemaStamp[],\n\toptions: { readonly tableExists?: boolean; readonly last?: boolean } = {},\n): Promise<void> {\n\tconst ledger = stamps[0]?.ledger;\n\tif (ledger === undefined) return;\n\tconst table = sqliteSchemaStampTable(ledger);\n\tif (options.tableExists !== true)\n\t\tawait tx.exec(\n\t\t\t`CREATE TABLE IF NOT EXISTS ${table} (domain TEXT NOT NULL PRIMARY KEY, revision INTEGER NOT NULL, schema_version INTEGER NOT NULL)`,\n\t\t);\n\t// The revision this transaction set up, even below a newer build's: the stamp says what was checked at this version.\n\t// One statement for them all, so a server pays one request.\n\tconst upsert = {\n\t\tsql: `INSERT INTO ${table} (domain, revision, schema_version)\n\t\tSELECT column1, column2, (SELECT schema_version FROM pragma_schema_version)\n\t\tFROM (VALUES ${stamps.map(() => \"(?, ?)\").join(\", \")}) WHERE true\n\t\tON CONFLICT(domain) DO UPDATE SET revision = excluded.revision, schema_version = excluded.schema_version`,\n\t\tparams: stamps.flatMap(({ domain, revision }) => [stampKey(domain), revision]),\n\t};\n\tif (options.last === true && finishers.transactionFinisher?.(tx)?.([upsert]) === true) return;\n\tawait tx.run(upsert.sql, ...upsert.params);\n}\n\n/** The catalog of a SQLite or libSQL database, or undefined when it cannot be read, such as on a SQLite too old. */\nasync function readSqliteCatalog(database: SqliteExecutor, ledger: string): Promise<StorageSchemaCatalog | undefined> {\n\tlet rows: CatalogRow[];\n\ttry {\n\t\trows = await database.all<CatalogRow>(SQLITE_CATALOG_SQL);\n\t} catch {\n\t\treturn undefined;\n\t}\n\tconst types = new Map<string, string>();\n\tconst columns = new Set<string>();\n\tfor (const row of rows) {\n\t\tif (row.kind === \"column\") columns.add(`${row.name}\\0${row.detail}`);\n\t\telse types.set(row.name, String(row.detail));\n\t}\n\treturn {\n\t\tledger,\n\t\t// SQLite records no versions: its stores' stamps are read on their own (`sqliteSchemaStampsOf`).\n\t\trecordedVersion: () => 0,\n\t\thasTable: (table) => types.get(table) === \"table\",\n\t\thasObject: (name) => types.has(name),\n\t\thasColumn: (table, column) => columns.has(`${table}\\0${column}`),\n\t\tsqliteObjectType: (name) => types.get(name),\n\t};\n}\n\ntype VersionRow = SqliteRow & { domain: string; version: number | string | null };\n\n/** The tables, objects, columns and executable functions of PostgreSQL catalog rows (`CATALOG_SQL`'s). */\nfunction catalogSets(rows: readonly CatalogRow[]) {\n\tconst tables = new Set<string>();\n\tconst objects = new Set<string>();\n\tconst columns = new Set<string>();\n\tconst functions = new Set<string>();\n\tfor (const row of rows) {\n\t\tif (row.kind === \"column\") columns.add(`${row.name}\\0${row.detail}`);\n\t\telse if (row.kind === \"function\") {\n\t\t\tif (row.detail === \"executable\") functions.add(row.name);\n\t\t} else {\n\t\t\tobjects.add(row.name);\n\t\t\tif (row.kind === \"relation\" && TABLE_KINDS.has(String(row.detail))) tables.add(row.name);\n\t\t}\n\t}\n\treturn { tables, objects, columns, functions };\n}\n\n/**\n * The catalog rows and the ledger's versions of `database`'s schema, read in one read-only transaction whose start\n * carries both reads, so they cost one round trip (#6560). The versions are undefined when the ledger did not exist;\n * the whole read is undefined when it failed.\n */\nasync function readPostgresCatalog(\n\tdatabase: SqliteDatabase,\n\tledger: string,\n\tphysicalLedger: string,\n): Promise<{ rows: CatalogRow[]; versions: VersionRow[] | undefined } | undefined> {\n\tconst versionsSql = `SELECT domain, MAX(version) AS version FROM ${ledger} GROUP BY domain`;\n\tlet read: { rows: CatalogRow[]; versions: VersionRow[] | undefined } | undefined;\n\ttry {\n\t\tawait database.transaction(\n\t\t\tasync (tx) => {\n\t\t\t\tread = undefined;\n\t\t\t\tconst rows = await tx.all<CatalogRow>(CATALOG_SQL);\n\t\t\t\t// Taken even where the ledger does not exist and its read failed, so the transaction ends with its commit,\n\t\t\t\t// sent at once, rather than with a rollback after it.\n\t\t\t\tconst ledgerExists = catalogSets(rows).tables.has(physicalLedger);\n\t\t\t\tconst versions = await tx.all<VersionRow>(versionsSql).catch((error: unknown) => {\n\t\t\t\t\tif (ledgerExists) throw error;\n\t\t\t\t\treturn undefined;\n\t\t\t\t});\n\t\t\t\tread = { rows, versions };\n\t\t\t},\n\t\t\t{\n\t\t\t\treadOnly: true,\n\t\t\t\tretryTransientFailures: true,\n\t\t\t\tleading: [\n\t\t\t\t\t{ sql: CATALOG_SQL, params: [] },\n\t\t\t\t\t{ sql: versionsSql, params: [] },\n\t\t\t\t],\n\t\t\t},\n\t\t);\n\t} catch {\n\t\treturn undefined;\n\t}\n\treturn read;\n}\n\n/**\n * Reads `database`'s schema and the versions `ledger` records, in one read-only transaction that takes no lock. On\n * PostgreSQL, an adapter that read them when it opened gives them once (`takeOpenedCatalog`), and the first open reads\n * nothing (#6560). On SQLite and libSQL, which record no versions, reads the schema alone in one statement. Undefined\n * when a read fails: the stores then check each object themselves.\n */\nexport async function readStorageSchemaCatalog(\n\tdatabase: SqliteDatabase,\n\tledger: string,\n): Promise<StorageSchemaCatalog | undefined> {\n\tconst dialect = dialectOf(database);\n\tif (dialect.name === \"sqlite\") return readSqliteCatalog(database, ledger);\n\tif (!dialect.versionedMigrations || dialect.name !== \"postgres\") return undefined;\n\tconst physicalLedger = dialect.identifier(ledger);\n\tconst opened = database.takeOpenedCatalog?.();\n\tconst read =\n\t\topened !== undefined && opened.ledger === physicalLedger\n\t\t\t? {\n\t\t\t\t\trows: opened.rows as readonly CatalogRow[],\n\t\t\t\t\tversions: opened.versions as readonly VersionRow[] | undefined,\n\t\t\t\t}\n\t\t\t: await readPostgresCatalog(database, ledger, physicalLedger);\n\tif (read === undefined) return undefined;\n\tconst { tables, objects, columns, functions } = catalogSets(read.rows);\n\tconst recorded = new Map<string, number>();\n\tif (tables.has(physicalLedger)) {\n\t\tif (read.versions === undefined) return undefined;\n\t\tfor (const row of read.versions) recorded.set(row.domain, Number(row.version ?? 0));\n\t}\n\treturn {\n\t\tledger,\n\t\trecordedVersion: (domain) => recorded.get(domain) ?? 0,\n\t\thasTable: (table) => tables.has(dialect.identifier(table)),\n\t\thasObject: (name) => objects.has(dialect.identifier(name)),\n\t\thasColumn: (table, column) => columns.has(`${dialect.identifier(table)}\\0${column}`),\n\t\thasFunction: (name) => functions.has(dialect.identifier(name)),\n\t};\n}\n\ninterface CatalogScope {\n\treadonly ledger: string;\n\t/** Read when the scope starts on PostgreSQL, whose opens always ask it; on SQLite at the first question. */\n\tcatalog: Promise<StorageSchemaCatalog | undefined> | undefined;\n\treadonly read: () => Promise<StorageSchemaCatalog | undefined>;\n\tusers: number;\n\t/** The stamps valid when read, by stamp key, read at the first question: see {@link sqliteSchemaStampsOf}. */\n\tstamps: Promise<ReadonlyMap<string, number> | undefined> | undefined;\n\t/** The setups this open ran on SQLite, by domain, to stamp again at its end ({@link restampStorageSchemaAtOpenEnd}). */\n\treadonly restamp: Map<string, PendingRestamp>;\n}\n\ninterface PendingRestamp extends SchemaStampAtOpenEnd {\n\treadonly stamp: SqliteSchemaStamp;\n\treadonly setup: (tx: SqliteExecutor) => Promise<unknown>;\n}\n\n/** @internal How the end of an open stamps a store's setup: see {@link restampStorageSchemaAtOpenEnd}. */\nexport interface SchemaStampAtOpenEnd {\n\t/**\n\t * Whether the store's schema, as the end's transaction reads the catalog, holds everything `setup` creates. Given,\n\t * the end runs `setup` only where it does not; absent, it runs `setup` whenever the store's stamp is behind.\n\t */\n\treadonly verify?: (catalog: StorageSchemaCatalog) => boolean;\n\t/**\n\t * `setup` has not run in this open and must: the end runs it whatever the stamp, and a failure fails the open, as\n\t * the setup's own transaction would have. For a setup whose objects all exist and whose only other statements seed\n\t * rows nothing in the open reads, such as a counter's: it then shares the end's transaction instead of taking one.\n\t */\n\treadonly deferred?: boolean;\n\t/**\n\t * `setup` ran in this open, in a transaction that stamped nothing: it is stamped only when the end takes a transaction\n\t * for another store, never in one of its own, so a new database's first open takes none.\n\t */\n\treadonly alongside?: boolean;\n}\n\nconst scopes = new WeakMap<SqliteDatabase, CatalogScope>();\n\n/**\n * Runs `body`, an open of one or more stores on `database`, with one catalog read for all of them: the schema checks\n * of the stores it opens ({@link schemaCatalogOf}) answer from it, so an open whose schema is current runs no schema\n * transaction and takes no lock. Opens on `database` that overlap share the read. `views` are other handles on the\n * same connection, such as a borrowed view, whose checks answer from the same read.\n */\nexport async function withStorageSchemaCatalog<T>(\n\tdatabase: SqliteDatabase,\n\tledger: string,\n\tbody: () => Promise<T>,\n\tviews: readonly SqliteDatabase[] = [],\n): Promise<T> {\n\tlet scope = scopes.get(database);\n\tif (scope === undefined || scope.ledger !== ledger) {\n\t\tconst read = () => readStorageSchemaCatalog(database, ledger);\n\t\tconst catalog = dialectOf(database).name === \"sqlite\" ? undefined : read();\n\t\tscope = { ledger, catalog, read, users: 0, stamps: undefined, restamp: new Map() };\n\t\tscopes.set(database, scope);\n\t}\n\tconst shared = scope;\n\tconst handles = [database, ...views.filter((view) => !scopes.has(view))];\n\tfor (const handle of handles.slice(1)) scopes.set(handle, shared);\n\tshared.users += 1;\n\ttry {\n\t\tconst value = await body();\n\t\tif (shared.users === 1 && shared.restamp.size > 0) await restamp(database, shared);\n\t\treturn value;\n\t} finally {\n\t\tshared.users -= 1;\n\t\tfor (const handle of handles.slice(1)) if (scopes.get(handle) === shared) scopes.delete(handle);\n\t\tif (shared.users === 0 && scopes.get(database) === shared) scopes.delete(database);\n\t}\n}\n\n/**\n * Drops the catalog an open of `database` in progress read, so the next question reads the schema again: for a step of\n * the open that changed the schema the stores it opens after it ask about.\n */\nexport function refreshStorageSchemaCatalog(database: SqliteDatabase): void {\n\tconst scope = scopes.get(database);\n\tif (scope !== undefined) scope.catalog = undefined;\n}\n\n/**\n * Tells the catalog an open of `database` in progress read that the open created `tables` since, so the stores it\n * opens next find them without reading the schema again.\n */\nexport function noteStorageSchemaTables(database: SqliteDatabase, tables: readonly string[]): void {\n\tconst scope = scopes.get(database);\n\tif (scope?.catalog === undefined) return;\n\tconst identifier = dialectOf(database).identifier;\n\tconst created = new Set(tables.map((table) => identifier(table)));\n\tscope.catalog = scope.catalog.then(\n\t\t(catalog) =>\n\t\t\tcatalog && {\n\t\t\t\t...catalog,\n\t\t\t\thasTable: (table) => created.has(identifier(table)) || catalog.hasTable(table),\n\t\t\t\thasObject: (name) => created.has(identifier(name)) || catalog.hasObject(name),\n\t\t\t},\n\t);\n}\n\n/**\n * The catalog an open of `database` in progress read ({@link withStorageSchemaCatalog}), when it read `ledger`'s\n * versions or no `ledger` is named; undefined outside such an open, and when it could not be read.\n */\nexport async function schemaCatalogOf(\n\tdatabase: SqliteDatabase,\n\tledger?: string,\n): Promise<StorageSchemaCatalog | undefined> {\n\tconst scope = scopes.get(database);\n\tif (scope === undefined || (ledger !== undefined && scope.ledger !== ledger)) return undefined;\n\tscope.catalog ??= scope.read();\n\treturn scope.catalog;\n}\n\n/**\n * @internal The revisions the stamps under `ledger` record for the stores of `database` (SQLite and libSQL), by stamp\n * key (`schema:<domain>`), as the open of `database` in progress read them; only those whose schema version was the\n * database's then. Undefined outside such an open, and where none could be read, such as before any stamp. The first\n * question reads them after the open's catalog, and only where it holds their table.\n */\nexport async function sqliteSchemaStampsOf(\n\tdatabase: SqliteDatabase,\n\tledger: string,\n): Promise<ReadonlyMap<string, number> | undefined> {\n\tconst scope = scopes.get(database);\n\tif (scope === undefined || scope.ledger !== ledger || dialectOf(database).name !== \"sqlite\") return undefined;\n\t// Read once the catalog shows their table: a read of a missing table would fail, which costs a request, and makes a\n\t// libSQL file driver replace its connection.\n\tscope.stamps ??= schemaCatalogOf(database, ledger).then((catalog) =>\n\t\tcatalog?.hasTable(sqliteSchemaStampTable(ledger)) === true\n\t\t\t? readSqliteSchemaStamps(database, ledger).then(\n\t\t\t\t\t(read) => read,\n\t\t\t\t\t() => undefined,\n\t\t\t\t)\n\t\t\t: undefined,\n\t);\n\treturn scope.stamps;\n}\n\n/**\n * @internal Tells the open of `database` in progress that it checked `setup`, the schema setup `stamp` names, without\n * its stamp (SQLite and libSQL only): it ran it in a transaction that stamped it, found every object it creates in the\n * catalog (with `verify`), or leaves it to the end (`deferred`). A schema change later in the same open, such as the\n * next store's setup or a column it adds, leaves a stamp behind the schema version, and a store found in the catalog has\n * none that is current, so the next open would check it again. The open's end reads the stamps once more and, where any\n * of these is behind, checks or runs them in one transaction and stamps them all with the version it leaves: the next\n * open of a current schema then takes no write lock and answers every such store from its stamp (#6560). False, and\n * nothing is kept, outside such an open: the caller then runs `setup` as it would without stamps.\n */\nexport function restampStorageSchemaAtOpenEnd(\n\tdatabase: SqliteDatabase,\n\tstamp: SqliteSchemaStamp,\n\tsetup: (tx: SqliteExecutor) => Promise<unknown>,\n\toptions: SchemaStampAtOpenEnd = {},\n): boolean {\n\tconst scope = scopes.get(database);\n\tif (scope === undefined || scope.ledger !== stamp.ledger || dialectOf(database).name !== \"sqlite\") return false;\n\tscope.restamp.set(stamp.domain, { stamp, setup, ...options });\n\treturn true;\n}\n\n/**\n * Stamps again, in one transaction, the setups `scope`'s open checked whose stamps are behind: each with `verify` is\n * checked against the catalog the transaction reads, and runs where that finds something missing; each without runs.\n * Every deferred setup runs, and fails the open where the transaction fails. Otherwise housekeeping: a failure leaves the\n * stamps behind, and the next open checks those stores as it would without them.\n */\nasync function restamp(database: SqliteDatabase, scope: CatalogScope): Promise<void> {\n\tconst pending = [...scope.restamp.values()];\n\tscope.restamp.clear();\n\tif (pending.every((each) => each.alongside === true)) return;\n\tconst deferred = pending.some((each) => each.deferred === true);\n\ttry {\n\t\t// Every setup this open checked was behind when it began. Where each is deferred or checked against the catalog,\n\t\t// the end's transaction checks it again anyway, so the stamps are not read again; otherwise they are, to spare an\n\t\t// open that changed nothing since its setups a transaction. None where no setup made the table yet.\n\t\tconst reread = pending.some((each) => each.deferred !== true && each.verify === undefined);\n\t\tconst current = reread\n\t\t\t? await readSqliteSchemaStamps(database, scope.ledger).catch(() => new Map<string, number>())\n\t\t\t: new Map<string, number>();\n\t\tconst behind = pending.filter(\n\t\t\t({ stamp, deferred }) => deferred === true || (current.get(stampKey(stamp.domain)) ?? 0) < stamp.revision,\n\t\t);\n\t\tif (behind.length === 0) return;\n\t\tconst table = sqliteSchemaStampTable(scope.ledger);\n\t\tawait database.transaction(\n\t\t\tasync (tx) => {\n\t\t\t\tconst catalog = await readSqliteCatalog(tx, scope.ledger);\n\t\t\t\tfor (const { setup, verify, deferred } of behind)\n\t\t\t\t\tif (deferred === true || verify === undefined || catalog === undefined || !verify(catalog))\n\t\t\t\t\t\tawait setup(tx);\n\t\t\t\tawait recordSqliteSchemaStamps(\n\t\t\t\t\ttx,\n\t\t\t\t\tbehind.map(({ stamp }) => stamp),\n\t\t\t\t\t{ tableExists: catalog?.hasTable(table) === true, last: true },\n\t\t\t\t);\n\t\t\t},\n\t\t\t{ retryTransientFailures: true, concurrency: { kind: \"serial\", domain: scope.ledger } },\n\t\t);\n\t} catch (error) {\n\t\tif (deferred) throw error;\n\t\t// The next open checks them again.\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"schema-catalog.js","sourceRoot":"","sources":["../../../src/core/storage/schema-catalog.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAExD,OAAO,KAAK,iBAAiB,MAAM,yBAAyB,CAAC;AAE7D;;;;;GAKG;AACH,MAAM,SAAS,GACd,iBAAiB,CAAC;AAQnB,SAAS,qBAAqB;IAC7B,MAAM,IAAI,GACT,UAGA,CAAC,OAAO,CAAC;IACV,MAAM,IAAI,GAAG,IAAI,EAAE,gBAAgB,EAAE,CAAC,aAAa,CAAC,EAAE,iBAAiB,CAAC;IACxE,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,IAAI,EAAK,CAAC;AACvD,CAAC;AA6BD,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAEvD;;;;GAIG;AACH,MAAM,WAAW,GAAG;;;;;;;;iFAQ6D,CAAC;AAIlF;;;GAGG;AACH,MAAM,kBAAkB,GAAG;;wBAEH,CAAC;AAEzB;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAAc;IACpD,OAAO,MAAM,CAAC,QAAQ,CAAC,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;YACnG,MAAM,OAAO,GAAG,MAAM,sBAAsB,CAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,GAAG,EAAkB,CAAC,CAAC;YAC5G,MAAM,MAAM,GAAG,eAAe,CAAC,MAAM,CACpC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,QAAQ,CAC1E,CAAC;YACF,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO;QACjC,CAAC;QACD,MAAM,WAAW,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,YAAY,GAAG,YAAY,IAAI,qBAAqB,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QACzF,IAAI,CAAC,WAAW,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC,KAAK,YAAY,yBAAyB,CAAC,EAAE,CAAC;YACpF,IAAI,CAAC;gBACJ,MAAM,WAAW,CAAC,IAAI,CAAC,CAAC;gBACxB,OAAO;YACR,CAAC;YAAC,OAAO,UAAU,EAAE,CAAC;gBACrB,IAAI,QAAQ;oBAAE,MAAM,UAAU,CAAC;gBAC/B,OAAO;YACR,CAAC;QACF,CAAC;QACD,IAAI,QAAQ;YAAE,MAAM,KAAK,CAAC;QAC1B,8EAA8E;IAC/E,CAAC;AACF,CAAC","sourcesContent":["import type { SqliteDatabase, SqliteExecutor, SqliteRow } from \"./database.js\";\nimport { dialectOf } from \"./dialect.js\";\nimport { StorageSchemaVersionError } from \"./errors.js\";\nimport type { SequencedStatement } from \"./statement-sequence.js\";\nimport * as statementSequence from \"./statement-sequence.js\";\n\n/**\n * `transactionFinisher`, `sequenceRunner` and `statementBatch` of `statement-sequence.ts`, which the copies 0.10.3 and\n * 0.10.4 loaded lack: a process an in-place update caught keeps those copies, where a named import would fail to link.\n * Without `statementBatch`, 0.10.3's connection thread cannot run `{ script: true }` entries inside a sequence request,\n * so multi-statement scripts run via `tx.exec` instead.\n */\nconst finishers: Partial<Pick<typeof statementSequence, \"transactionFinisher\" | \"sequenceRunner\" | \"statementBatch\">> =\n\tstatementSequence;\n\n/** Minimal AsyncLocalStorage surface, resolved portably without a static `node:` import. */\ninterface AsyncScopeStore<T> {\n\tgetStore(): T | undefined;\n\trun<R>(store: T, callback: () => R): R;\n}\n\nfunction createAsyncScopeStore<T>(): AsyncScopeStore<T> | undefined {\n\tconst proc = (\n\t\tglobalThis as {\n\t\t\tprocess?: { getBuiltinModule?: (id: string) => { AsyncLocalStorage?: new <V>() => AsyncScopeStore<V> } };\n\t\t}\n\t).process;\n\tconst Ctor = proc?.getBuiltinModule?.(\"async_hooks\")?.AsyncLocalStorage;\n\treturn Ctor === undefined ? undefined : new Ctor<T>();\n}\n\n/**\n * What a schema held when one open read it: its relations, triggers and columns, and on PostgreSQL the versions its\n * ledger records. Only a positive answer is final: the schema only moves forward, so what existed then still exists,\n * while something missing may have been created since and is checked again under the store's lock.\n */\nexport interface StorageSchemaCatalog {\n\t/** The ledger the versions were read from. */\n\treadonly ledger: string;\n\t/** The highest version `ledger` recorded for `domain`; 0 when none, or when the ledger did not exist. */\n\trecordedVersion(domain: string): number;\n\t/** Whether a table (or view) named `table` existed. */\n\thasTable(table: string): boolean;\n\t/** Whether a relation (table, index, sequence…) or a trigger named `name` existed. */\n\thasObject(name: string): boolean;\n\t/** Whether `table` had a column named `column`. */\n\thasColumn(table: string, column: string): boolean;\n\t/**\n\t * Whether a function named `name` existed in the schema and this role may run it: PostgreSQL only, absent on SQLite.\n\t */\n\treadonly hasFunction?: (name: string) => boolean;\n\t/**\n\t * What kind of object `name` was on SQLite (`table`, `index`, `view` or `trigger`), from one read of\n\t * `sqlite_schema`; undefined when there was none, and always on PostgreSQL.\n\t */\n\treadonly sqliteObjectType?: (name: string) => string | undefined;\n}\n\nconst TABLE_KINDS = new Set([\"r\", \"p\", \"v\", \"m\", \"f\"]);\n\n/**\n * Every relation, trigger, column and function of the schema the statement runs in, in one statement and so one\n * snapshot. The catalog, not information_schema, finds relations, as `tableExists` does; columns come from\n * information_schema, as `columnExists` reads them. A function is listed with whether this role may execute it.\n */\nconst CATALOG_SQL = `SELECT 'relation' AS kind, c.relname::text AS name, c.relkind::text AS detail\n\tFROM pg_catalog.pg_class c WHERE c.relnamespace = current_schema()::regnamespace\nUNION ALL SELECT 'trigger', t.tgname::text, NULL\n\tFROM pg_catalog.pg_trigger t JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid\n\tWHERE c.relnamespace = current_schema()::regnamespace AND NOT t.tgisinternal\nUNION ALL SELECT 'column', table_name::text, column_name::text\n\tFROM information_schema.columns WHERE table_schema = current_schema()\nUNION ALL SELECT 'function', p.proname::text, CASE WHEN has_function_privilege(p.oid, 'EXECUTE') THEN 'executable' END\n\tFROM pg_catalog.pg_proc p WHERE p.pronamespace = current_schema()::regnamespace`;\n\ntype CatalogRow = SqliteRow & { kind: string; name: string; detail: string | null };\n\n/**\n * Every object of a SQLite database and every column of its tables, generated ones included, in one\n * statement and so one snapshot: what `tableExists`, `columnExists` and `schemaObjects` ask one at a time (#6560).\n */\nconst SQLITE_CATALOG_SQL = `SELECT 'object' AS kind, name, type AS detail FROM sqlite_master\nUNION ALL SELECT 'column', m.name, c.name FROM sqlite_master AS m JOIN pragma_table_xinfo(m.name) AS c\n\tWHERE m.type = 'table'`;\n\n/**\n * @internal The table under `ledger`'s prefix where SQLite record which revision of each store's schema\n * setup ran, and the database's schema version (`PRAGMA schema_version`) once it had: `domain`, `revision`,\n * `schema_version`. SQLite counts every change to the schema in that version, whoever makes it, an older Atomic that\n * records nothing included; a revision is believed only while the version still matches, so any later change is checked\n * again (#6560). Builds that do not know the table leave it alone.\n */\nexport function sqliteSchemaStampTable(ledger: string): string {\n\treturn ledger.endsWith(\"atomic_migrations\")\n\t\t? `${ledger.slice(0, -\"atomic_migrations\".length)}atomic_schema_stamps`\n\t\t: `${ledger}_schema_stamps`;\n}\n\n/** The key a store's setup is stamped under, as the PostgreSQL ledger records it. */\nconst stampKey = (domain: string) => `schema:${domain}`;\n\ntype StampRow = SqliteRow & { domain: string | null; revision: number | bigint | null; stamped: number | bigint };\n\n/**\n * The revisions `ledger`'s stamps record whose schema version is the database's now, by stamp key, read in one\n * statement so the two agree. Stamps of an older schema version are left out: something changed the schema since.\n */\nasync function readSqliteSchemaStamps(executor: SqliteExecutor, ledger: string): Promise<Map<string, number>> {\n\tconst rows = await executor.all<StampRow>(\n\t\t`SELECT domain, revision, schema_version AS stamped FROM ${sqliteSchemaStampTable(ledger)}\n\t\tUNION ALL SELECT NULL, NULL, schema_version FROM pragma_schema_version`,\n\t);\n\tconst now = rows.find((row) => row.domain === null)?.stamped;\n\tconst stamps = new Map<string, number>();\n\tfor (const row of rows)\n\t\tif (row.domain !== null && now !== undefined && Number(row.stamped) === Number(now))\n\t\t\tstamps.set(row.domain, Number(row.revision ?? 0));\n\treturn stamps;\n}\n\n/** @internal A store's schema setup, as its stamp records it: `ledger` names the prefix, `domain` the store. */\nexport interface SqliteSchemaStamp {\n\treadonly ledger: string;\n\treadonly domain: string;\n\treadonly revision: number;\n}\n\n/** The SQLite statements that create (unless `tableExists`) and upsert `stamps` at the current `PRAGMA schema_version`. */\nfunction sqliteStampStatements(\n\tstamps: readonly SqliteSchemaStamp[],\n\ttableExists: boolean,\n): readonly SequencedStatement[] {\n\tconst ledger = stamps[0]?.ledger;\n\tif (ledger === undefined) return [];\n\tconst table = sqliteSchemaStampTable(ledger);\n\tconst upsert: SequencedStatement = {\n\t\tsql: `INSERT INTO ${table} (domain, revision, schema_version)\n\t\tSELECT column1, column2, (SELECT schema_version FROM pragma_schema_version)\n\t\tFROM (VALUES ${stamps.map(() => \"(?, ?)\").join(\", \")}) WHERE true\n\t\tON CONFLICT(domain) DO UPDATE SET revision = excluded.revision, schema_version = excluded.schema_version`,\n\t\tparams: stamps.flatMap(({ domain, revision }) => [stampKey(domain), revision]),\n\t};\n\tif (tableExists) return [upsert];\n\treturn [\n\t\t{\n\t\t\tsql: `CREATE TABLE IF NOT EXISTS ${table} (domain TEXT NOT NULL PRIMARY KEY, revision INTEGER NOT NULL, schema_version INTEGER NOT NULL)`,\n\t\t\tparams: [],\n\t\t\tscript: true,\n\t\t},\n\t\tupsert,\n\t];\n}\n\n/**\n * @internal Stamps each of `stamps`, in the transaction `tx` that ran their setups, with the schema version as that\n * transaction leaves it: a later open believes their revisions until the schema changes again (#6560). Creates the\n * stamps table first, unless `options.tableExists`, so its own creation is part of the version recorded. With\n * `options.last`, the stamps are the transaction's last statements: where its connection is pipelined, they go out with\n * its commit. SQLite only; every stamp must share a ledger.\n */\nexport async function recordSqliteSchemaStamps(\n\ttx: SqliteExecutor,\n\tstamps: readonly SqliteSchemaStamp[],\n\toptions: { readonly tableExists?: boolean; readonly last?: boolean } = {},\n): Promise<void> {\n\tconst statements = sqliteStampStatements(stamps, options.tableExists === true);\n\tif (statements.length === 0) return;\n\tconst canSequence = finishers.statementBatch !== undefined || statements.every((each) => each.script !== true);\n\tif (options.last === true && canSequence && finishers.transactionFinisher?.(tx)?.(statements) === true) return;\n\tfor (const statement of statements) {\n\t\tif (statement.script === true) await tx.exec(statement.sql);\n\t\telse await tx.run(statement.sql, ...statement.params);\n\t}\n}\n\n/** The catalog of a SQLite database, or undefined when it cannot be read, such as on a SQLite too old. */\nasync function readSqliteCatalog(database: SqliteExecutor, ledger: string): Promise<StorageSchemaCatalog | undefined> {\n\tlet rows: CatalogRow[];\n\ttry {\n\t\trows = await database.all<CatalogRow>(SQLITE_CATALOG_SQL);\n\t} catch {\n\t\treturn undefined;\n\t}\n\tconst types = new Map<string, string>();\n\tconst columns = new Set<string>();\n\tfor (const row of rows) {\n\t\tif (row.kind === \"column\") columns.add(`${row.name}\\0${row.detail}`);\n\t\telse types.set(row.name, String(row.detail));\n\t}\n\treturn {\n\t\tledger,\n\t\t// SQLite records no versions: its stores' stamps are read on their own (`sqliteSchemaStampsOf`).\n\t\trecordedVersion: () => 0,\n\t\thasTable: (table) => types.get(table) === \"table\",\n\t\thasObject: (name) => types.has(name),\n\t\thasColumn: (table, column) => columns.has(`${table}\\0${column}`),\n\t\tsqliteObjectType: (name) => types.get(name),\n\t};\n}\n\ntype VersionRow = SqliteRow & { domain: string; version: number | string | null };\n\n/** The tables, objects, columns and executable functions of PostgreSQL catalog rows (`CATALOG_SQL`'s). */\nfunction catalogSets(rows: readonly CatalogRow[]) {\n\tconst tables = new Set<string>();\n\tconst objects = new Set<string>();\n\tconst columns = new Set<string>();\n\tconst functions = new Set<string>();\n\tfor (const row of rows) {\n\t\tif (row.kind === \"column\") columns.add(`${row.name}\\0${row.detail}`);\n\t\telse if (row.kind === \"function\") {\n\t\t\tif (row.detail === \"executable\") functions.add(row.name);\n\t\t} else {\n\t\t\tobjects.add(row.name);\n\t\t\tif (row.kind === \"relation\" && TABLE_KINDS.has(String(row.detail))) tables.add(row.name);\n\t\t}\n\t}\n\treturn { tables, objects, columns, functions };\n}\n\n/**\n * The catalog rows and the ledger's versions of `database`'s schema, read in one read-only transaction whose start\n * carries both reads, so they cost one round trip (#6560). The versions are undefined when the ledger did not exist;\n * the whole read is undefined when it failed.\n */\nasync function readPostgresCatalog(\n\tdatabase: SqliteDatabase,\n\tledger: string,\n\tphysicalLedger: string,\n): Promise<{ rows: CatalogRow[]; versions: VersionRow[] | undefined } | undefined> {\n\tconst versionsSql = `SELECT domain, MAX(version) AS version FROM ${ledger} GROUP BY domain`;\n\tlet read: { rows: CatalogRow[]; versions: VersionRow[] | undefined } | undefined;\n\ttry {\n\t\tawait database.transaction(\n\t\t\tasync (tx) => {\n\t\t\t\tread = undefined;\n\t\t\t\tconst rows = await tx.all<CatalogRow>(CATALOG_SQL);\n\t\t\t\t// Taken even where the ledger does not exist and its read failed, so the transaction ends with its commit,\n\t\t\t\t// sent at once, rather than with a rollback after it.\n\t\t\t\tconst ledgerExists = catalogSets(rows).tables.has(physicalLedger);\n\t\t\t\tconst versions = await tx.all<VersionRow>(versionsSql).catch((error: unknown) => {\n\t\t\t\t\tif (ledgerExists) throw error;\n\t\t\t\t\treturn undefined;\n\t\t\t\t});\n\t\t\t\tread = { rows, versions };\n\t\t\t},\n\t\t\t{\n\t\t\t\treadOnly: true,\n\t\t\t\tretryTransientFailures: true,\n\t\t\t\tleading: [\n\t\t\t\t\t{ sql: CATALOG_SQL, params: [] },\n\t\t\t\t\t{ sql: versionsSql, params: [] },\n\t\t\t\t],\n\t\t\t},\n\t\t);\n\t} catch {\n\t\treturn undefined;\n\t}\n\treturn read;\n}\n\n/**\n * Reads `database`'s schema and the versions `ledger` records, in one read-only transaction that takes no lock. On\n * PostgreSQL, an adapter that read them when it opened gives them once (`takeOpenedCatalog`), and the first open reads\n * nothing (#6560). On SQLite, which record no versions, reads the schema alone in one statement. Undefined\n * when a read fails: the stores then check each object themselves.\n */\nexport async function readStorageSchemaCatalog(\n\tdatabase: SqliteDatabase,\n\tledger: string,\n): Promise<StorageSchemaCatalog | undefined> {\n\tconst dialect = dialectOf(database);\n\tif (dialect.name === \"sqlite\") return readSqliteCatalog(database, ledger);\n\tif (!dialect.versionedMigrations || dialect.name !== \"postgres\") return undefined;\n\tconst physicalLedger = dialect.identifier(ledger);\n\tconst opened = database.takeOpenedCatalog?.();\n\tconst read =\n\t\topened !== undefined && opened.ledger === physicalLedger\n\t\t\t? {\n\t\t\t\t\trows: opened.rows as readonly CatalogRow[],\n\t\t\t\t\tversions: opened.versions as readonly VersionRow[] | undefined,\n\t\t\t\t}\n\t\t\t: await readPostgresCatalog(database, ledger, physicalLedger);\n\tif (read === undefined) return undefined;\n\tconst { tables, objects, columns, functions } = catalogSets(read.rows);\n\tconst recorded = new Map<string, number>();\n\tif (tables.has(physicalLedger)) {\n\t\tif (read.versions === undefined) return undefined;\n\t\tfor (const row of read.versions) recorded.set(row.domain, Number(row.version ?? 0));\n\t}\n\treturn {\n\t\tledger,\n\t\trecordedVersion: (domain) => recorded.get(domain) ?? 0,\n\t\thasTable: (table) => tables.has(dialect.identifier(table)),\n\t\thasObject: (name) => objects.has(dialect.identifier(name)),\n\t\thasColumn: (table, column) => columns.has(`${dialect.identifier(table)}\\0${column}`),\n\t\thasFunction: (name) => functions.has(dialect.identifier(name)),\n\t};\n}\n\n/** @internal Context passed to a queued SQLite schema setup inside an open's single write transaction (#6709). */\nexport interface SqliteSchemaBatchContext {\n\t/** The write transaction executor. */\n\treadonly tx: SqliteExecutor;\n\t/** The live schema catalog read at the start of the write transaction, authoritative under the write lock. */\n\treadonly catalog: StorageSchemaCatalog | undefined;\n\t/**\n\t * Queues a SQLite write statement or multi-statement SQL script to run in order inside the transaction. Consecutive\n\t * queued writes go out together to the connection thread, and the final run goes out with `COMMIT`. When\n\t * `options.ignoreError` returns true for a statement's failure, that error is ignored.\n\t */\n\tenqueue(\n\t\tstatement: string | SequencedStatement,\n\t\toptions?: { readonly ignoreError?: (error: unknown) => boolean },\n\t): void;\n\t/** Executes any writes queued so far; call before issuing a read on `tx` that depends on them. */\n\tflushWrites(): Promise<void>;\n\t/** Notes that this transaction added `column` to `table`, so a later queued setup does not add it again. */\n\tnoteColumnAdded(table: string, column: string): void;\n\t/** Whether `table` already has `column` in `catalog` or added earlier in this transaction. */\n\thasColumn(table: string, column: string): boolean;\n\t/** Notes that this transaction created `table`. */\n\tnoteTableCreated(table: string): void;\n\t/** Whether `table` was created earlier in this transaction. */\n\tcreatedTable(table: string): boolean;\n\t/** Whether `table` already existed in `catalog` before this transaction began. */\n\ttableExisted(table: string): boolean;\n}\n\n/** @internal A SQLite schema setup queued inside an open scope (`withStorageSchemaCatalog`) to run in one transaction. */\nexport interface SqliteSchemaBatchSetup {\n\t/** Stamp recorded for this setup once the batched transaction commits, when the store uses SQLite schema stamps. */\n\treadonly stamp?: SqliteSchemaStamp;\n\t/** Whether the schema already holds everything this setup creates (for DDL-only setups without row seeds). */\n\treadonly verify?: (catalog: StorageSchemaCatalog) => boolean;\n\t/**\n\t * Checks outside any write lock whether another host completed this setup while we waited on `tryMaintenance`.\n\t * Throwing (such as `StorageSchemaVersionError` for a newer build's database) immediately rejects the open.\n\t */\n\treadonly done?: (\n\t\tcatalog: StorageSchemaCatalog,\n\t\tstamps: ReadonlyMap<string, number> | undefined,\n\t) => boolean | Promise<boolean>;\n\t/** Reset any mutable per-attempt JS state before each transaction attempt or retry. */\n\treadonly reset?: () => void;\n\t/** Runs this setup inside the batched write transaction. */\n\treadonly run: (context: SqliteSchemaBatchContext) => Promise<void> | void;\n\t/**\n\t * Optional setup (such as an FTS5 search index): if the transaction fails, the open retries with optional setups\n\t * isolated in savepoints, calling `onFailure` instead of failing the open.\n\t */\n\treadonly optional?: boolean;\n\t/** Called when an optional setup fails and its savepoint rolls back. */\n\treadonly onFailure?: () => void;\n}\n\ninterface OpenBatch {\n\treadonly ledger: string;\n\treadonly setups: SqliteSchemaBatchSetup[];\n\treadonly restamp: Map<string, PendingRestamp>;\n}\n\ninterface CatalogScope {\n\treadonly ledger: string;\n\t/** Read when the scope starts on PostgreSQL, whose opens always ask it; on SQLite at the first question. */\n\tcatalog: Promise<StorageSchemaCatalog | undefined> | undefined;\n\treadonly read: () => Promise<StorageSchemaCatalog | undefined>;\n\tusers: number;\n\t/** The stamps valid when read, by stamp key, read at the first question: see {@link sqliteSchemaStampsOf}. */\n\tstamps: Promise<ReadonlyMap<string, number> | undefined> | undefined;\n\t/** Fallback batch used only on runtimes lacking `AsyncLocalStorage`. */\n\treadonly fallbackBatch: OpenBatch;\n}\n\ninterface PendingRestamp extends SchemaStampAtOpenEnd {\n\treadonly stamp: SqliteSchemaStamp;\n\treadonly setup: (tx: SqliteExecutor) => Promise<unknown>;\n}\n\n/** @internal How the end of an open stamps a store's setup: see {@link restampStorageSchemaAtOpenEnd}. */\nexport interface SchemaStampAtOpenEnd {\n\t/**\n\t * Whether the store's schema, as the end's transaction reads the catalog, holds everything `setup` creates. Given,\n\t * the end runs `setup` only where it does not; absent, it runs `setup` whenever the store's stamp is behind.\n\t */\n\treadonly verify?: (catalog: StorageSchemaCatalog) => boolean;\n\t/**\n\t * `setup` has not run in this open and must: the end runs it whatever the stamp, and a failure fails the open, as\n\t * the setup's own transaction would have. For a setup whose objects all exist and whose only other statements seed\n\t * rows nothing in the open reads, such as a counter's: it then shares the end's transaction instead of taking one.\n\t */\n\treadonly deferred?: boolean;\n\t/**\n\t * `setup` ran in this open, in a transaction that stamped nothing: it is stamped only when the end takes a transaction\n\t * for another store, never in one of its own, so a new database's first open takes none.\n\t */\n\treadonly alongside?: boolean;\n}\n\nconst scopes = new WeakMap<SqliteDatabase, CatalogScope>();\n/**\n * Tracks the root open batch active on each `CatalogScope` along the current async call chain: nested opens share their\n * enclosing root's batch and commit together at the root's end, while concurrent sibling opens on the same database\n * handle each own and commit their own batch before returning (#6709).\n */\nconst activeOpenBatches = createAsyncScopeStore<ReadonlyMap<CatalogScope, OpenBatch>>();\n\n/** How long a SQLite open batch polls `done` after `tryMaintenance` finds the lock busy before joining the queue. */\nconst SQLITE_BATCH_WAIT_MS = 1_000;\nconst SQLITE_BATCH_POLL_MS = 20;\nconst SQLITE_BATCH_MAX_POLL_MS = 250;\n\nconst pausePoll = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms * (0.5 + Math.random() / 2)));\n\n/**\n * Runs `body`, an open of one or more stores on `database`, with one catalog read for all of them: the schema checks\n * of the stores it opens ({@link schemaCatalogOf}) answer from it, so an open whose schema is current runs no schema\n * transaction and takes no lock. Opens on `database` that overlap share the read. On SQLite, setups queued inside the\n * open ({@link queueSqliteSchemaSetup}) run in one write transaction before the root open returns (#6709). `views` are\n * other handles on the same connection, such as a borrowed view, whose checks answer from the same read.\n */\nexport async function withStorageSchemaCatalog<T>(\n\tdatabase: SqliteDatabase,\n\tledger: string,\n\tbody: () => Promise<T>,\n\tviews: readonly SqliteDatabase[] = [],\n): Promise<T> {\n\tlet scope = scopes.get(database);\n\tif (scope === undefined || scope.ledger !== ledger) {\n\t\tconst read = () => readStorageSchemaCatalog(database, ledger);\n\t\tconst catalog = dialectOf(database).name === \"sqlite\" ? undefined : read();\n\t\tscope = {\n\t\t\tledger,\n\t\t\tcatalog,\n\t\t\tread,\n\t\t\tusers: 0,\n\t\t\tstamps: undefined,\n\t\t\tfallbackBatch: { ledger, setups: [], restamp: new Map() },\n\t\t};\n\t\tscopes.set(database, scope);\n\t}\n\tconst shared = scope;\n\tconst handles = [database, ...views.filter((view) => !scopes.has(view))];\n\tfor (const handle of handles.slice(1)) scopes.set(handle, shared);\n\tshared.users += 1;\n\tconst enclosing = activeOpenBatches?.getStore();\n\tconst isRoot = activeOpenBatches === undefined ? shared.users === 1 : enclosing?.has(shared) !== true;\n\tconst batch: OpenBatch =\n\t\tactiveOpenBatches === undefined\n\t\t\t? shared.fallbackBatch\n\t\t\t: isRoot\n\t\t\t\t? { ledger, setups: [], restamp: new Map() }\n\t\t\t\t: enclosing!.get(shared)!;\n\tconst run = async (): Promise<T> => {\n\t\tconst value = await body();\n\t\tif (isRoot && (batch.setups.length > 0 || batch.restamp.size > 0)) await flushOpenBatch(database, shared, batch);\n\t\treturn value;\n\t};\n\ttry {\n\t\tif (!isRoot || activeOpenBatches === undefined) return await run();\n\t\tconst next = new Map(enclosing);\n\t\tnext.set(shared, batch);\n\t\treturn await activeOpenBatches.run(next, run);\n\t} finally {\n\t\tshared.users -= 1;\n\t\tfor (const handle of handles.slice(1)) if (scopes.get(handle) === shared) scopes.delete(handle);\n\t\tif (shared.users === 0 && scopes.get(database) === shared) scopes.delete(database);\n\t}\n}\n\n/**\n * Drops the catalog an open of `database` in progress read, so the next question reads the schema again: for a step of\n * the open that changed the schema the stores it opens after it ask about.\n */\nexport function refreshStorageSchemaCatalog(database: SqliteDatabase): void {\n\tconst scope = scopes.get(database);\n\tif (scope !== undefined) {\n\t\tscope.catalog = undefined;\n\t\tscope.stamps = undefined;\n\t}\n}\n\n/**\n * Tells the catalog an open of `database` in progress read that the open created `tables` since, so the stores it\n * opens next find them without reading the schema again.\n */\nexport function noteStorageSchemaTables(database: SqliteDatabase, tables: readonly string[]): void {\n\tconst scope = scopes.get(database);\n\tif (scope?.catalog === undefined) return;\n\tconst identifier = dialectOf(database).identifier;\n\tconst created = new Set(tables.map((table) => identifier(table)));\n\tscope.catalog = scope.catalog.then(\n\t\t(catalog) =>\n\t\t\tcatalog && {\n\t\t\t\t...catalog,\n\t\t\t\thasTable: (table) => created.has(identifier(table)) || catalog.hasTable(table),\n\t\t\t\thasObject: (name) => created.has(identifier(name)) || catalog.hasObject(name),\n\t\t\t},\n\t);\n}\n\n/**\n * The catalog an open of `database` in progress read ({@link withStorageSchemaCatalog}), when it read `ledger`'s\n * versions or no `ledger` is named; undefined outside such an open, and when it could not be read.\n */\nexport async function schemaCatalogOf(\n\tdatabase: SqliteDatabase,\n\tledger?: string,\n): Promise<StorageSchemaCatalog | undefined> {\n\tconst scope = scopes.get(database);\n\tif (scope === undefined || (ledger !== undefined && scope.ledger !== ledger)) return undefined;\n\tscope.catalog ??= scope.read();\n\treturn scope.catalog;\n}\n\n/**\n * @internal The revisions the stamps under `ledger` record for the stores of `database` (SQLite), by stamp\n * key (`schema:<domain>`), as the open of `database` in progress read them; only those whose schema version was the\n * database's then. Undefined outside such an open, and where none could be read, such as before any stamp. The first\n * question reads them after the open's catalog, and only where it holds their table.\n */\nexport async function sqliteSchemaStampsOf(\n\tdatabase: SqliteDatabase,\n\tledger: string,\n): Promise<ReadonlyMap<string, number> | undefined> {\n\tconst scope = scopes.get(database);\n\tif (scope === undefined || scope.ledger !== ledger || dialectOf(database).name !== \"sqlite\") return undefined;\n\t// Read once the catalog shows their table: a read of a missing table would fail, which costs a request, and makes a\n\t// driver may replace its connection.\n\tscope.stamps ??= schemaCatalogOf(database, ledger).then((catalog) =>\n\t\tcatalog?.hasTable(sqliteSchemaStampTable(ledger)) === true\n\t\t\t? readSqliteSchemaStamps(database, ledger).then(\n\t\t\t\t\t(read) => read,\n\t\t\t\t\t() => undefined,\n\t\t\t\t)\n\t\t\t: undefined,\n\t);\n\treturn scope.stamps;\n}\n\n/** Active root open batch for `database` on SQLite (matching `ledger` when given), or undefined outside one. */\nfunction activeBatchFor(\n\tdatabase: SqliteDatabase,\n\tledger?: string,\n): { readonly scope: CatalogScope; readonly batch: OpenBatch } | undefined {\n\tif (dialectOf(database).name !== \"sqlite\") return undefined;\n\tconst scope = scopes.get(database);\n\tif (scope === undefined || (ledger !== undefined && scope.ledger !== ledger)) return undefined;\n\tconst batch = activeOpenBatches === undefined ? scope.fallbackBatch : activeOpenBatches.getStore()?.get(scope);\n\treturn batch === undefined ? undefined : { scope, batch };\n}\n\n/**\n * @internal Queues `setup` into the active SQLite open scope (`withStorageSchemaCatalog`) so that all needed setups of\n * the open execute in one write transaction before the open returns (#6709). Returns `false` outside a SQLite open\n * scope (or for a different `ledger`), in which case the caller runs `setup` immediately.\n */\nexport function queueSqliteSchemaSetup(\n\tdatabase: SqliteDatabase,\n\tledger: string | undefined,\n\tsetup: SqliteSchemaBatchSetup,\n): boolean {\n\tconst active = activeBatchFor(database, ledger);\n\tif (active === undefined) return false;\n\tactive.batch.setups.push(setup);\n\treturn true;\n}\n\n/**\n * @internal Executes and commits any SQLite schema setups queued so far in the active open scope, before the open\n * needs their committed tables or evaluated outcomes (#6709). No-op when nothing is queued or outside a SQLite open.\n */\nexport async function flushStorageSchemaSetups(database: SqliteDatabase, ledger?: string): Promise<void> {\n\tconst active = activeBatchFor(database, ledger);\n\tif (active === undefined) return;\n\tif (active.batch.setups.length === 0 && active.batch.restamp.size === 0) return;\n\tawait flushOpenBatch(database, active.scope, active.batch);\n}\n\n/**\n * @internal Tells the open of `database` in progress that it checked `setup`, the schema setup `stamp` names, without\n * its stamp (SQLite only): it ran it in a transaction that stamped it, found every object it creates in the\n * catalog (with `verify`), or leaves it to the end (`deferred`). A schema change later in the same open, such as the\n * next store's setup or a column it adds, leaves a stamp behind the schema version, and a store found in the catalog has\n * none that is current, so the next open would check it again. The open's end checks or runs them in one transaction\n * and stamps them all with the version it leaves: the next open of a current schema then takes no write lock and answers\n * every such store from its stamp (#6560, #6709). False, and nothing is kept, outside such an open.\n */\nexport function restampStorageSchemaAtOpenEnd(\n\tdatabase: SqliteDatabase,\n\tstamp: SqliteSchemaStamp,\n\tsetup: (tx: SqliteExecutor) => Promise<unknown>,\n\toptions: SchemaStampAtOpenEnd = {},\n): boolean {\n\tconst active = activeBatchFor(database, stamp.ledger);\n\tif (active === undefined) return false;\n\tactive.batch.restamp.set(stamp.domain, { stamp, setup, ...options });\n\treturn true;\n}\n\ninterface QueuedBatchWrite {\n\treadonly statement: SequencedStatement;\n\treadonly ignoreError?: (error: unknown) => boolean;\n}\n\n/**\n * Sends `writes` on `tx`, piggybacking onto `COMMIT` when `last` is true and the connection supports it. Returns\n * `true` when sent via `transactionFinisher` (without per-statement `ignoreError` handling).\n */\nasync function sendBatchWrites(\n\ttx: SqliteExecutor,\n\twrites: readonly QueuedBatchWrite[],\n\tlast: boolean,\n): Promise<boolean> {\n\tif (writes.length === 0) return false;\n\tconst statements = writes.map(({ statement }) => statement);\n\tconst canSequence = finishers.statementBatch !== undefined || statements.every((each) => each.script !== true);\n\tif (last && canSequence && finishers.transactionFinisher?.(tx)?.(statements) === true) return true;\n\tconst runSequence = canSequence ? finishers.sequenceRunner?.(tx) : undefined;\n\tif (runSequence !== undefined && writes.every(({ ignoreError }) => ignoreError === undefined)) {\n\t\tawait runSequence({ statements });\n\t\treturn false;\n\t}\n\tfor (const { statement, ignoreError } of writes) {\n\t\ttry {\n\t\t\tif (statement.script === true) await tx.exec(statement.sql);\n\t\t\telse await tx.run(statement.sql, ...statement.params);\n\t\t} catch (error) {\n\t\t\tif (ignoreError?.(error) !== true) throw error;\n\t\t}\n\t}\n\treturn false;\n}\n\n/**\n * Checks outside any write lock whether another host completed every queued setup and restamp in this open batch.\n * Updates `scope.catalog` and `scope.stamps` when complete so later questions in the same open see the fresh schema.\n */\nasync function batchCompletedElsewhere(\n\tdatabase: SqliteDatabase,\n\tscope: CatalogScope,\n\tsetups: readonly SqliteSchemaBatchSetup[],\n\trestamps: readonly PendingRestamp[],\n): Promise<boolean> {\n\tconst catalog = await readSqliteCatalog(database, scope.ledger);\n\tif (catalog === undefined) return false;\n\tconst stampTable = sqliteSchemaStampTable(scope.ledger);\n\tconst needsStamps = setups.some((each) => each.stamp !== undefined) || restamps.length > 0;\n\tconst stamps =\n\t\tneedsStamps && catalog.hasTable(stampTable)\n\t\t\t? await readSqliteSchemaStamps(database, scope.ledger).catch(() => undefined)\n\t\t\t: undefined;\n\tfor (const entry of setups) {\n\t\tif (entry.done !== undefined) {\n\t\t\tif (!(await entry.done(catalog, stamps))) return false;\n\t\t\tcontinue;\n\t\t}\n\t\tif (entry.stamp !== undefined) {\n\t\t\tif ((stamps?.get(stampKey(entry.stamp.domain)) ?? 0) < entry.stamp.revision) return false;\n\t\t\tcontinue;\n\t\t}\n\t\tif (entry.verify !== undefined) {\n\t\t\tif (!entry.verify(catalog)) return false;\n\t\t\tcontinue;\n\t\t}\n\t\treturn false;\n\t}\n\tfor (const entry of restamps) {\n\t\tif (entry.alongside === true && setups.length === 0) continue;\n\t\tif ((stamps?.get(stampKey(entry.stamp.domain)) ?? 0) < entry.stamp.revision) return false;\n\t}\n\tscope.catalog = Promise.resolve(catalog);\n\tscope.stamps = stamps === undefined ? undefined : Promise.resolve(stamps);\n\treturn true;\n}\n\n/**\n * Runs every queued setup and restamp of `batch` in ONE SQLite write transaction through `tryMaintenance`, polling\n * `batchCompletedElsewhere` when another host holds the lock and falling back to a normal serial transaction after\n * {@link SQLITE_BATCH_WAIT_MS} (#6709).\n */\nasync function flushOpenBatch(database: SqliteDatabase, scope: CatalogScope, batch: OpenBatch): Promise<void> {\n\tconst setups = batch.setups.splice(0);\n\tconst pendingRestamps = [...batch.restamp.values()];\n\tbatch.restamp.clear();\n\tif (setups.length === 0 && pendingRestamps.every((each) => each.alongside === true)) return;\n\tconst required = setups.length > 0 || pendingRestamps.some((each) => each.deferred === true);\n\tconst hasOptional = setups.some((each) => each.optional === true);\n\tconst stampTable = sqliteSchemaStampTable(scope.ledger);\n\n\tlet ignoreErrorPredicates: ((error: unknown) => boolean)[] = [];\n\tlet usedFinisher = false;\n\tconst runTransaction = async (tx: SqliteExecutor, isolateOptional: boolean): Promise<void> => {\n\t\tignoreErrorPredicates = [];\n\t\tusedFinisher = false;\n\t\tfor (const entry of setups) entry.reset?.();\n\t\tconst catalog = await readSqliteCatalog(tx, scope.ledger);\n\t\tconst writes: QueuedBatchWrite[] = [];\n\t\tconst addedColumns = new Set<string>();\n\t\tconst createdTables = new Set<string>();\n\t\tconst flushWrites = async (): Promise<void> => {\n\t\t\tif (writes.length === 0) return;\n\t\t\tconst batchWrites = writes.splice(0);\n\t\t\tawait sendBatchWrites(tx, batchWrites, false);\n\t\t};\n\t\tconst context: SqliteSchemaBatchContext = {\n\t\t\ttx,\n\t\t\tcatalog,\n\t\t\tenqueue(statement, options) {\n\t\t\t\tconst sequenced: SequencedStatement =\n\t\t\t\t\ttypeof statement === \"string\" ? { sql: statement, params: [], script: true } : statement;\n\t\t\t\tif (options?.ignoreError !== undefined) ignoreErrorPredicates.push(options.ignoreError);\n\t\t\t\twrites.push({\n\t\t\t\t\tstatement: sequenced,\n\t\t\t\t\t...(options?.ignoreError === undefined ? {} : { ignoreError: options.ignoreError }),\n\t\t\t\t});\n\t\t\t},\n\t\t\tflushWrites,\n\t\t\tnoteColumnAdded(table, column) {\n\t\t\t\taddedColumns.add(`${table}\\0${column}`);\n\t\t\t},\n\t\t\thasColumn(table, column) {\n\t\t\t\treturn catalog?.hasColumn(table, column) === true || addedColumns.has(`${table}\\0${column}`);\n\t\t\t},\n\t\t\tnoteTableCreated(table) {\n\t\t\t\tcreatedTables.add(table);\n\t\t\t},\n\t\t\tcreatedTable(table) {\n\t\t\t\treturn createdTables.has(table);\n\t\t\t},\n\t\t\ttableExisted(table) {\n\t\t\t\treturn catalog?.hasTable(table) === true;\n\t\t\t},\n\t\t};\n\n\t\tfor (const entry of setups) {\n\t\t\tif (!isolateOptional || entry.optional !== true) {\n\t\t\t\tawait entry.run(context);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tawait flushWrites();\n\t\t\tawait tx.exec(\"SAVEPOINT atomic_optional_schema_setup\");\n\t\t\ttry {\n\t\t\t\tawait entry.run(context);\n\t\t\t\tawait flushWrites();\n\t\t\t} catch {\n\t\t\t\twrites.length = 0;\n\t\t\t\tawait tx.exec(\"ROLLBACK TO SAVEPOINT atomic_optional_schema_setup\");\n\t\t\t\tentry.onFailure?.();\n\t\t\t}\n\t\t\tawait tx.exec(\"RELEASE SAVEPOINT atomic_optional_schema_setup\");\n\t\t}\n\n\t\tfor (const { setup, verify, deferred } of pendingRestamps) {\n\t\t\tif (deferred === true || verify === undefined || catalog === undefined || !verify(catalog)) {\n\t\t\t\tawait flushWrites();\n\t\t\t\tawait setup(tx);\n\t\t\t}\n\t\t}\n\n\t\t// Collect stamps for every stamped setup and restamp in this batch (deduplicated by domain, keeping highest revision).\n\t\tconst stampByDomain = new Map<string, SqliteSchemaStamp>();\n\t\tfor (const entry of setups) {\n\t\t\tif (entry.stamp === undefined) continue;\n\t\t\tconst prev = stampByDomain.get(entry.stamp.domain);\n\t\t\tif (prev === undefined || entry.stamp.revision > prev.revision)\n\t\t\t\tstampByDomain.set(entry.stamp.domain, entry.stamp);\n\t\t}\n\t\tfor (const entry of pendingRestamps) {\n\t\t\tconst prev = stampByDomain.get(entry.stamp.domain);\n\t\t\tif (prev === undefined || entry.stamp.revision > prev.revision)\n\t\t\t\tstampByDomain.set(entry.stamp.domain, entry.stamp);\n\t\t}\n\t\tif (stampByDomain.size > 0) {\n\t\t\tconst stampStmts = sqliteStampStatements([...stampByDomain.values()], catalog?.hasTable(stampTable) === true);\n\t\t\tfor (const statement of stampStmts) writes.push({ statement });\n\t\t}\n\n\t\tusedFinisher = await sendBatchWrites(tx, writes.splice(0), !isolateOptional);\n\t};\n\n\tconst executeOnce = async (isolateOptional: boolean): Promise<void> => {\n\t\tconst waiting = () =>\n\t\t\tdatabase.transaction((tx) => runTransaction(tx, isolateOptional), {\n\t\t\t\tretryTransientFailures: true,\n\t\t\t\tconcurrency: { kind: \"serial\", domain: scope.ledger },\n\t\t\t});\n\t\tconst tryMaintenance = database.tryMaintenance?.bind(database);\n\t\tif (tryMaintenance === undefined) {\n\t\t\tawait waiting();\n\t\t\tscope.catalog = undefined;\n\t\t\tscope.stamps = undefined;\n\t\t\treturn;\n\t\t}\n\t\tconst deadline = performance.now() + SQLITE_BATCH_WAIT_MS;\n\t\tfor (let wait = SQLITE_BATCH_POLL_MS; ; wait = Math.min(wait * 2, SQLITE_BATCH_MAX_POLL_MS)) {\n\t\t\tconst won = await tryMaintenance((tx) => runTransaction(tx, isolateOptional));\n\t\t\tif (won) {\n\t\t\t\tscope.catalog = undefined;\n\t\t\t\tscope.stamps = undefined;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (performance.now() >= deadline) {\n\t\t\t\tawait waiting();\n\t\t\t\tscope.catalog = undefined;\n\t\t\t\tscope.stamps = undefined;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tawait pausePoll(wait);\n\t\t\tif (await batchCompletedElsewhere(database, scope, setups, pendingRestamps)) return;\n\t\t}\n\t};\n\n\ttry {\n\t\t// Pure restamp housekeeping (no queued setups, no deferred seeds): check current stamps first if any entry lacks\n\t\t// `verify`, sparing an open that changed nothing since its setups a write transaction.\n\t\tif (setups.length === 0 && !required && pendingRestamps.some((each) => each.verify === undefined)) {\n\t\t\tconst current = await readSqliteSchemaStamps(database, scope.ledger).catch(() => new Map<string, number>());\n\t\t\tconst behind = pendingRestamps.filter(\n\t\t\t\t({ stamp }) => (current.get(stampKey(stamp.domain)) ?? 0) < stamp.revision,\n\t\t\t);\n\t\t\tif (behind.length === 0) return;\n\t\t}\n\t\tawait executeOnce(false);\n\t} catch (error) {\n\t\tconst retryIgnored = usedFinisher && ignoreErrorPredicates.some((match) => match(error));\n\t\tif ((hasOptional || retryIgnored) && !(error instanceof StorageSchemaVersionError)) {\n\t\t\ttry {\n\t\t\t\tawait executeOnce(true);\n\t\t\t\treturn;\n\t\t\t} catch (retryError) {\n\t\t\t\tif (required) throw retryError;\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tif (required) throw error;\n\t\t// Pure housekeeping restamp failure: the next open checks those stores again.\n\t}\n}\n"]}
|
|
@@ -2,7 +2,7 @@ import type { SqliteDatabase } from "./database.js";
|
|
|
2
2
|
import { TeamProfileConfigError } from "./errors.js";
|
|
3
3
|
import type { StorageSteps } from "./file-identity.js";
|
|
4
4
|
import type { AdapterOptions, SecretRef, StorageSelection } from "./provider.js";
|
|
5
|
-
import type {
|
|
5
|
+
import type { TeamProfile, TeamProfileOptions } from "./team.js";
|
|
6
6
|
/** A secret held only in this process's memory: it is never written to settings, environments or files. */
|
|
7
7
|
export interface InMemorySecretRef {
|
|
8
8
|
readonly value: string;
|
|
@@ -29,51 +29,13 @@ export type StorageInputSelection = StorageSettingsSelection | {
|
|
|
29
29
|
export declare function selectStorage(value: StorageInputSelection, source: "sdk" | "settings" | "env" | "cli", field: string, defaultPath: string | (() => string)): StorageSelection;
|
|
30
30
|
export declare function selectStorageAsync(value: StorageInputSelection, source: "sdk" | "settings" | "env" | "cli", field: string, defaultPath: () => Promise<string>): Promise<StorageSelection>;
|
|
31
31
|
export declare function selectStorageSteps(value: StorageInputSelection, source: "sdk" | "settings" | "env" | "cli", field: string, defaultPath: string | (() => StorageSteps<string>)): StorageSteps<StorageSelection>;
|
|
32
|
-
/**
|
|
33
|
-
export declare const LIBSQL_ADAPTER_PACKAGE = "@bastani/atomic-storage-libsql";
|
|
34
|
-
/** Filename prefix for private token files created by `atomic storage join` and `atomic team join` in the agent directory. */
|
|
32
|
+
/** A token file `atomic storage join` created in the agent directory has this filename prefix. */
|
|
35
33
|
export declare const STORAGE_TOKEN_FILE = "storage-token";
|
|
36
|
-
/** The `sessions.storage` value
|
|
34
|
+
/** The `sessions.storage` value that pins sessions to the local default store, named explicitly. */
|
|
37
35
|
export declare const LOCAL_SESSIONS_STORAGE: {
|
|
38
36
|
readonly path: "workflows/journal.sqlite";
|
|
39
37
|
};
|
|
40
|
-
export declare const TEAM_PROFILE_ENV = "ATOMIC_PROFILE";
|
|
41
|
-
export declare const TEAM_URL_ENV = "ATOMIC_TEAM_URL";
|
|
42
|
-
export declare const TEAM_TOKEN_ENV = "ATOMIC_TEAM_TOKEN";
|
|
43
|
-
export declare const TEAM_TOKEN_FILE_ENV = "ATOMIC_TEAM_TOKEN_FILE";
|
|
44
|
-
export declare const TEAM_PREFIX_ENV = "ATOMIC_TEAM_PREFIX";
|
|
45
|
-
/** The variables `ATOMIC_PROFILE=ci` reads; setting any of them without the profile is an error. */
|
|
46
|
-
export declare const TEAM_VARIABLES: readonly string[];
|
|
47
|
-
/** A team database selection in the settings form: usable as `createAgentSession({ storage })`. */
|
|
48
|
-
export interface TeamStorageSelection {
|
|
49
|
-
readonly adapter: string;
|
|
50
|
-
readonly options: Readonly<Record<string, string>>;
|
|
51
|
-
readonly secrets?: Readonly<Record<string, SecretRef>>;
|
|
52
|
-
readonly prefix?: string;
|
|
53
|
-
}
|
|
54
|
-
export interface TeamProfileSelectionOptions {
|
|
55
|
-
readonly profile: "ci";
|
|
56
|
-
/** `libsql://`, `https://`, `wss://` or absolute `file:` URL, without a credential. */
|
|
57
|
-
readonly url: string;
|
|
58
|
-
/** The database token, held as an in-memory `{ value }` secret that is never serialized or written. */
|
|
59
|
-
readonly token?: string;
|
|
60
|
-
/** A file holding the database token; relative paths resolve against the working directory. */
|
|
61
|
-
readonly tokenFile?: string;
|
|
62
|
-
/** An environment variable holding the database token, read when the store opens. */
|
|
63
|
-
readonly tokenEnv?: string;
|
|
64
|
-
readonly prefix?: string;
|
|
65
|
-
}
|
|
66
38
|
export type TeamInputSource = "sdk" | "cli" | "env";
|
|
67
|
-
/** Whether a team database URL needs no token: a local `file:` database. */
|
|
68
|
-
export declare function isFileUrl(url: string): boolean;
|
|
69
|
-
/**
|
|
70
|
-
* Check a team database URL: a supported scheme, an absolute `file:` URL, and no credential in it. `postgres` only
|
|
71
|
-
* changes the unsupported-URL hint, for the commands that also take a `postgres://` URL through
|
|
72
|
-
* {@link checkSharedDatabaseArguments}.
|
|
73
|
-
*/
|
|
74
|
-
export declare function checkTeamUrl(url: string | undefined, source: TeamInputSource, options?: {
|
|
75
|
-
readonly postgres?: boolean;
|
|
76
|
-
}): string;
|
|
77
39
|
/** The first-party PostgreSQL adapter package that `atomic storage join postgres://…` and `--db postgres://…` select. */
|
|
78
40
|
export declare const POSTGRES_ADAPTER_PACKAGE = "@bastani/atomic-storage-postgres";
|
|
79
41
|
/** The platform credential a Postgres selection's `auth` option names, instead of a password. */
|
|
@@ -85,7 +47,7 @@ export declare function isPostgresUrl(url: string): boolean;
|
|
|
85
47
|
/** The shared database a command line names: its URL and where its credential comes from. */
|
|
86
48
|
export interface SharedDatabaseArguments {
|
|
87
49
|
readonly url: string;
|
|
88
|
-
/**
|
|
50
|
+
/** A password or token file another process keeps fresh, referenced in place. */
|
|
89
51
|
readonly tokenFile?: string;
|
|
90
52
|
/** Postgres only: a password file. */
|
|
91
53
|
readonly passwordFile?: string;
|
|
@@ -100,9 +62,9 @@ export interface CheckedSharedDatabase {
|
|
|
100
62
|
readonly auth?: PostgresAuth;
|
|
101
63
|
}
|
|
102
64
|
/**
|
|
103
|
-
* Check the database URL and credential flags of `atomic storage join` and `--db
|
|
104
|
-
* `postgresql://` URL takes exactly one of `--password-file`, `--token-file` and `--auth
|
|
105
|
-
*
|
|
65
|
+
* Check the database URL and credential flags of `atomic storage join` and `--db`: a `postgres://` or
|
|
66
|
+
* `postgresql://` URL that takes exactly one of `--password-file`, `--token-file` and `--auth`. A URL of the removed
|
|
67
|
+
* libSQL adapter is refused with how to move off it.
|
|
106
68
|
*/
|
|
107
69
|
export declare function checkSharedDatabaseArguments(input: SharedDatabaseArguments): CheckedSharedDatabase;
|
|
108
70
|
/** Check a table prefix with the same rules as every storage prefix. */
|
|
@@ -112,45 +74,8 @@ export declare function checkTeamPrefix(prefix: string | undefined, source: Team
|
|
|
112
74
|
* a file a selection references is read for every connection; an unreadable or empty file is an invalid input.
|
|
113
75
|
*/
|
|
114
76
|
export declare function readTeamTokenFile(path: string, source: TeamInputSource, field?: string, read?: "trimmed" | "as-connections-read"): string;
|
|
115
|
-
export declare function readTeamTokenFileAsync(path: string, source: TeamInputSource, field?: string, read?: "trimmed" | "as-connections-read"): Promise<string>;
|
|
116
|
-
/** A missing token for a URL that needs one. */
|
|
117
|
-
export declare function missingTeamToken(url: string, source: Exclude<TeamInputSource, "env">): TeamProfileConfigError;
|
|
118
77
|
/** More than one token source. */
|
|
119
78
|
export declare function conflictingTeamToken(source: TeamInputSource, fields: readonly string[]): TeamProfileConfigError;
|
|
120
|
-
/** A whitespace-only literal token, or an empty variable name. */
|
|
121
|
-
export declare function emptyTeamToken(source: TeamInputSource, field?: string): TeamProfileConfigError;
|
|
122
|
-
/**
|
|
123
|
-
* The CI profile as a team database selection, without reading or writing settings: sessions and Intercom can both
|
|
124
|
-
* use it. A literal `token` becomes an in-memory `{ value }` secret that serializes as
|
|
125
|
-
* `[redacted]` and that only SDK callers can pass; `tokenFile` (absolute path) and `tokenEnv` are references read
|
|
126
|
-
* when the store opens. Inputs are checked first; nothing else happens.
|
|
127
|
-
*/
|
|
128
|
-
export declare function teamProfileSelection(options: TeamProfileSelectionOptions): TeamStorageSelection;
|
|
129
|
-
/**
|
|
130
|
-
* The selection `ATOMIC_PROFILE=ci` makes from `ATOMIC_TEAM_URL` and `ATOMIC_TEAM_TOKEN` or `ATOMIC_TEAM_TOKEN_FILE`
|
|
131
|
-
* (plus an optional `ATOMIC_TEAM_PREFIX`), or `undefined` without a profile. The token is referenced, never copied:
|
|
132
|
-
* `{ env: "ATOMIC_TEAM_TOKEN" }` or the token file's absolute path, so the selection can be handed to child processes.
|
|
133
|
-
* Invalid input throws {@link TeamProfileConfigError} with `source: "env"`: a team variable without the profile, or
|
|
134
|
-
* the profile without its URL or token, is `incomplete-profile` naming every missing variable at once.
|
|
135
|
-
*/
|
|
136
|
-
export declare function environmentTeamProfile(env?: NodeJS.ProcessEnv): TeamStorageSelection | undefined;
|
|
137
|
-
export declare function environmentTeamProfileSelection(env?: NodeJS.ProcessEnv): TeamStorageSelection | undefined;
|
|
138
|
-
export declare function environmentTeamProfileAsync(env?: NodeJS.ProcessEnv): Promise<TeamStorageSelection | undefined>;
|
|
139
|
-
/**
|
|
140
|
-
* Use a team database for Intercom while sessions stay private: checks every input and the
|
|
141
|
-
* connection first, then sets the global `storage` setting to the team database and `sessions.storage` to the local
|
|
142
|
-
* default store in one settings write, and restarts the Intercom broker so it routes through the team database.
|
|
143
|
-
* Rejects with `TeamProfileConfigError` for an invalid input and `TeamProfileError` otherwise; on any rejection
|
|
144
|
-
* nothing was changed. A failed broker restart is reported in `broker`, not thrown.
|
|
145
|
-
*/
|
|
146
|
-
export declare function joinTeam(options: JoinTeamOptions): Promise<TeamJoinResult>;
|
|
147
|
-
/**
|
|
148
|
-
* Restore the individual layout: remove the global `storage` setting and the `sessions.storage` pin when they hold
|
|
149
|
-
* exactly what `joinTeam` writes, leave every other value in place, delete the removed selection's token file unless
|
|
150
|
-
* another setting references it, and restart the Intercom broker when `storage` was removed. Running it again
|
|
151
|
-
* changes nothing.
|
|
152
|
-
*/
|
|
153
|
-
export declare function leaveTeam(options?: LeaveTeamOptions): Promise<TeamLeaveResult>;
|
|
154
79
|
/**
|
|
155
80
|
* The layout in effect for this process and working directory (`individual`, `team`, `ci` or `custom`), from the
|
|
156
81
|
* storage each domain selects. Reads only; an invalid selection rejects with its `StorageConfigError`.
|