@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,10 +1,14 @@
|
|
|
1
|
+
import { refreshStorageSchemaCatalog } from "./added-exports-0-10-11.js";
|
|
1
2
|
import { dialectOf } from "./dialect.js";
|
|
2
3
|
import { StorageConfigError, StorageSchemaVersionError } from "./errors.js";
|
|
4
|
+
import { fencedPath } from "./fenced-paths.js";
|
|
3
5
|
import { recordSqliteSchemaStamps, schemaCatalogOf, sqliteSchemaStampsOf } from "./schema-catalog.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
import * as statementSequence from "./statement-sequence.js";
|
|
7
|
+
/**
|
|
8
|
+
* `transactionFinisher` of `statement-sequence.ts`, which the copies 0.10.3 and 0.10.4 loaded lack: taken from the module
|
|
9
|
+
* namespace, so this module links against them too. Without it a setup's last statements go out before its commit.
|
|
10
|
+
*/
|
|
11
|
+
const finishers = statementSequence;
|
|
8
12
|
const DEFAULT_MIGRATION_TABLE = "atomic_migrations";
|
|
9
13
|
function checkSteps(steps) {
|
|
10
14
|
let previous = 0;
|
|
@@ -26,21 +30,28 @@ async function tableExists(executor, dialect, table) {
|
|
|
26
30
|
async function assertSchemaUsage(executor, dialect) {
|
|
27
31
|
if (dialect.name !== "postgres")
|
|
28
32
|
return;
|
|
29
|
-
|
|
33
|
+
refuseWithoutSchemaUsage(await executor.get(SCHEMA_USAGE_SQL));
|
|
34
|
+
}
|
|
35
|
+
/** The schema the transaction runs in, whether it exists, and whether this role may use it: PostgreSQL only. */
|
|
36
|
+
const SCHEMA_USAGE_SQL = `SELECT s.name AS schema, current_user AS role, (n.oid IS NOT NULL)::int AS present,
|
|
30
37
|
coalesce(has_schema_privilege(n.oid, 'USAGE'), false)::int AS usage
|
|
31
38
|
FROM (SELECT trim(both '"' from split_part(current_setting('search_path'), ',', 1)) AS name) s
|
|
32
|
-
LEFT JOIN pg_catalog.pg_namespace n ON n.nspname = s.name
|
|
39
|
+
LEFT JOIN pg_catalog.pg_namespace n ON n.nspname = s.name`;
|
|
40
|
+
/** Throws for `access`, a row of {@link SCHEMA_USAGE_SQL}, where the schema exists and this role may not use it. */
|
|
41
|
+
function refuseWithoutSchemaUsage(access) {
|
|
33
42
|
if (access === undefined || Number(access.present) === 0 || Number(access.usage) === 1)
|
|
34
43
|
return;
|
|
35
|
-
throw new StorageConfigError("sdk", "privileges", "missing-privilege", `Role "${access.role}" has no USAGE on schema ${access.schema}, so it can neither find Atomic's tables there nor create them. Grant it as the schema's owner: GRANT USAGE ON SCHEMA ${access.schema} TO "${access.role}"; and, for a runtime role, the table grants in "Set up the database" in docs/storage.md`);
|
|
44
|
+
throw new StorageConfigError("sdk", "privileges", "missing-privilege", `Role "${access.role}" has no USAGE on schema ${access.schema}, so it can neither find Atomic's tables there nor create them. Grant it as the schema's owner: GRANT USAGE ON SCHEMA ${access.schema} TO "${access.role}"; and, for a runtime role, the table grants in "Set up the database" in docs/storage/postgres.md`);
|
|
36
45
|
}
|
|
37
46
|
/** Creates the ledger `table` unless it exists, so a current schema runs no DDL (#5218). */
|
|
38
|
-
async function createLedger(executor, dialect, table
|
|
47
|
+
async function createLedger(executor, dialect, table,
|
|
48
|
+
/** The transaction holds the prefix's setup lock, exclusive, already: a {@link setUpStorageOnce} try took it. */
|
|
49
|
+
locked = false) {
|
|
39
50
|
if (await tableExists(executor, dialect, table))
|
|
40
51
|
return;
|
|
41
52
|
await assertSchemaUsage(executor, dialect);
|
|
42
53
|
// Two stores that set up their schemas at once never race to create the ledger they share.
|
|
43
|
-
if (dialect.name === "postgres") {
|
|
54
|
+
if (dialect.name === "postgres" && !locked) {
|
|
44
55
|
await executor.get("SELECT pg_advisory_xact_lock(hashtextextended(?, 0)) AS locked", `${table}:schema`);
|
|
45
56
|
if (await tableExists(executor, dialect, table))
|
|
46
57
|
return;
|
|
@@ -49,32 +60,52 @@ async function createLedger(executor, dialect, table) {
|
|
|
49
60
|
await executor.exec(`CREATE TABLE IF NOT EXISTS ${table} (domain ${text} NOT NULL, version ${int} NOT NULL, applied_at ${int} NOT NULL, PRIMARY KEY (domain, version))${dialect.tableOptions}`);
|
|
50
61
|
}
|
|
51
62
|
/** The highest version `table` records for `domain`, 0 when none or when the ledger does not exist yet. */
|
|
52
|
-
async function recordedVersion(executor, dialect, table, domain
|
|
53
|
-
|
|
63
|
+
async function recordedVersion(executor, dialect, table, domain,
|
|
64
|
+
/** The ledger is known to exist: it is not looked up first. */
|
|
65
|
+
exists = false) {
|
|
66
|
+
if (!exists && !(await tableExists(executor, dialect, table)))
|
|
54
67
|
return 0;
|
|
55
|
-
const row = await executor.get(
|
|
68
|
+
const row = await executor.get(...versionRead(table, domain));
|
|
56
69
|
return Number(row?.version ?? 0);
|
|
57
70
|
}
|
|
58
|
-
async function applyVersioned(transaction, dialect, table, domain, steps,
|
|
59
|
-
|
|
71
|
+
async function applyVersioned(transaction, dialect, table, domain, steps, acceptNewer = false,
|
|
72
|
+
/** The ledger is known to exist, as a catalog read before the transaction found it: it is read, not looked up. */
|
|
73
|
+
ledgerExists = false,
|
|
74
|
+
/** The transaction holds the setup's locks already: see {@link setUpStorageOnce}. */
|
|
75
|
+
locked = false) {
|
|
76
|
+
const current = ledgerExists
|
|
77
|
+
? Number((await transaction.get(...versionRead(table, domain)))?.version ??
|
|
78
|
+
0)
|
|
79
|
+
: await recordedVersion(transaction, dialect, table, domain);
|
|
60
80
|
const supported = steps.at(-1)?.version ?? 0;
|
|
61
81
|
if (current > supported) {
|
|
62
|
-
if (
|
|
82
|
+
if (acceptNewer)
|
|
63
83
|
return { applied: [], version: current };
|
|
64
84
|
throw new StorageSchemaVersionError(domain, current, supported);
|
|
65
85
|
}
|
|
66
86
|
const applied = [];
|
|
67
87
|
// Probed first: a current schema, whose ledger exists, runs no DDL (#5218).
|
|
68
|
-
|
|
88
|
+
if (!ledgerExists)
|
|
89
|
+
await createLedger(transaction, dialect, table, locked);
|
|
90
|
+
// Each step's record goes out with the next step's first statement, on a connection that pipelines a transaction's
|
|
91
|
+
// statements; a failed one fails the migration.
|
|
92
|
+
const records = [];
|
|
69
93
|
for (const step of steps) {
|
|
70
94
|
if (step.version <= current)
|
|
71
95
|
continue;
|
|
72
96
|
await step.up(transaction, dialect);
|
|
73
|
-
|
|
97
|
+
const recorded = transaction.run(`INSERT INTO ${table} VALUES (?, ?, ${dialect.nowMs})`, domain, step.version);
|
|
98
|
+
recorded.catch(() => { });
|
|
99
|
+
records.push(recorded);
|
|
74
100
|
applied.push(step.version);
|
|
75
101
|
}
|
|
102
|
+
await Promise.all(records);
|
|
76
103
|
return { applied, version: Math.max(current, supported) };
|
|
77
104
|
}
|
|
105
|
+
/** The read of the highest version `table` records for `domain`, as arguments of `get`. */
|
|
106
|
+
function versionRead(table, domain) {
|
|
107
|
+
return [`SELECT MAX(version) AS version FROM ${table} WHERE domain = ?`, domain];
|
|
108
|
+
}
|
|
78
109
|
/**
|
|
79
110
|
* Advances `domain`'s schema to the last of `steps`, or refuses. Runs in one `serial` transaction whose domain is the ledger
|
|
80
111
|
* table's name, so concurrent migrators under one prefix run one after another and a failed step rolls back the
|
|
@@ -90,13 +121,44 @@ export async function applyStorageMigrations(database, domain, steps, options =
|
|
|
90
121
|
const recorded = dialect.versionedMigrations ? await recordedInCatalog(database, table, domain) : undefined;
|
|
91
122
|
const supported = steps.at(-1)?.version ?? 0;
|
|
92
123
|
if (recorded !== undefined && recorded >= supported && supported > 0) {
|
|
93
|
-
if (
|
|
124
|
+
if (recorded > supported && !options.acceptNewer)
|
|
94
125
|
throw new StorageSchemaVersionError(domain, recorded, supported);
|
|
95
126
|
return { applied: [], version: recorded };
|
|
96
127
|
}
|
|
128
|
+
// One process sets a new database up while the others that open it at once wait for it to finish, without holding a
|
|
129
|
+
// lock or a connection: the locks are those an earlier build's migration and setup take, so it waits for those too.
|
|
130
|
+
if (dialect.name === "postgres" && supported > 0) {
|
|
131
|
+
let ledgerExists = await ledgerInCatalog(database, table);
|
|
132
|
+
return setUpStorageOnce(database, {
|
|
133
|
+
// An earlier build migrates in a serial transaction of the ledger's domain: the database's lock and the domain's,
|
|
134
|
+
// which this takes shared, so the domains migrate beside one another but never beside an earlier build's.
|
|
135
|
+
get locks() {
|
|
136
|
+
return [
|
|
137
|
+
...setupLocks(table, domain, ledgerExists),
|
|
138
|
+
{ scope: POSTGRES_DATABASE_LOCK_SCOPE, inSchema: true, shared: true },
|
|
139
|
+
{ scope: table, inSchema: true, shared: true },
|
|
140
|
+
];
|
|
141
|
+
},
|
|
142
|
+
done: async () => {
|
|
143
|
+
const version = await recordedNow(database, table, domain, ledgerExists);
|
|
144
|
+
ledgerExists ||= await ledgerInCatalog(database, table);
|
|
145
|
+
if (version < supported)
|
|
146
|
+
return undefined;
|
|
147
|
+
if (version > supported && !options.acceptNewer)
|
|
148
|
+
throw new StorageSchemaVersionError(domain, version, supported);
|
|
149
|
+
return { applied: [], version };
|
|
150
|
+
},
|
|
151
|
+
get leading() {
|
|
152
|
+
const [sql, key] = versionRead(table, domain);
|
|
153
|
+
return ledgerExists ? [{ sql, params: [key] }] : [];
|
|
154
|
+
},
|
|
155
|
+
setup: (transaction, locked) => applyVersioned(transaction, dialect, table, domain, steps, options.acceptNewer, locked && ledgerExists, locked),
|
|
156
|
+
concurrency: { kind: "serial", domain: table },
|
|
157
|
+
});
|
|
158
|
+
}
|
|
97
159
|
return database.transaction(async (transaction) => {
|
|
98
160
|
if (dialect.versionedMigrations)
|
|
99
|
-
return applyVersioned(transaction, dialect, table, domain, steps, options);
|
|
161
|
+
return applyVersioned(transaction, dialect, table, domain, steps, options.acceptNewer);
|
|
100
162
|
for (const step of steps)
|
|
101
163
|
await step.up(transaction, dialect);
|
|
102
164
|
return { applied: steps.map((step) => step.version), version: steps.at(-1)?.version ?? 0 };
|
|
@@ -112,6 +174,116 @@ async function recordedInCatalog(database, table, domain) {
|
|
|
112
174
|
return undefined;
|
|
113
175
|
return catalog.recordedVersion(domain);
|
|
114
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* The version `ledger` records for `domain` now, read without a lock or a transaction of its own; 0 where the ledger
|
|
179
|
+
* does not exist. Where `ledgerExists`, one read of the ledger answers; otherwise, inside an open
|
|
180
|
+
* (`withStorageSchemaCatalog`), the open's catalog is read again. Either way, once the version is found, the open's
|
|
181
|
+
* catalog is read again at its next question, so the stores the open sets up next find what another process set up.
|
|
182
|
+
*/
|
|
183
|
+
async function recordedNow(database, ledger, domain, ledgerExists) {
|
|
184
|
+
if (ledgerExists) {
|
|
185
|
+
const version = Number((await database.get(...versionRead(ledger, domain)))?.version ?? 0);
|
|
186
|
+
if (version > 0)
|
|
187
|
+
refreshStorageSchemaCatalog(database);
|
|
188
|
+
return version;
|
|
189
|
+
}
|
|
190
|
+
refreshStorageSchemaCatalog(database);
|
|
191
|
+
const catalog = await schemaCatalogOf(database, ledger);
|
|
192
|
+
if (catalog !== undefined)
|
|
193
|
+
return catalog.recordedVersion(domain);
|
|
194
|
+
return recordedVersion(database, dialectOf(database), ledger, domain);
|
|
195
|
+
}
|
|
196
|
+
/** Whether the catalog of the open in progress on `database` holds `ledger`: once it does, it always will. */
|
|
197
|
+
async function ledgerInCatalog(database, ledger) {
|
|
198
|
+
return (await schemaCatalogOf(database, ledger))?.hasTable(ledger) === true;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* The advisory lock a serial transaction without a domain takes on PostgreSQL, and one with a domain takes shared: the
|
|
202
|
+
* adapter's `DATABASE_LOCK_SCOPE`, named in the transaction's schema.
|
|
203
|
+
*/
|
|
204
|
+
const POSTGRES_DATABASE_LOCK_SCOPE = "atomic";
|
|
205
|
+
/**
|
|
206
|
+
* How long a setup that another process holds the lock for waits, polling, before it waits for the lock itself: only a
|
|
207
|
+
* holder that stalls keeps it that long on PostgreSQL, since setting a schema up takes a few round trips.
|
|
208
|
+
*/
|
|
209
|
+
const SETUP_WAIT_MS = 15_000;
|
|
210
|
+
/**
|
|
211
|
+
* The same on a SQLite file, whose write lock a try also finds taken while other writers wait in its queue, as every
|
|
212
|
+
* process's own writes do when many open at once: after this long it joins the queue, which hands the lock on in turn.
|
|
213
|
+
*/
|
|
214
|
+
const SQLITE_SETUP_WAIT_MS = 1_000;
|
|
215
|
+
/** The first pause between two polls of a setup that another process runs; each later one doubles, up to the last. */
|
|
216
|
+
const SETUP_POLL_MS = 20;
|
|
217
|
+
const SETUP_MAX_POLL_MS = 250;
|
|
218
|
+
/** The schema the transaction runs in, as `<schema>:`, and empty in `public`: what the adapter prefixes its locks with. */
|
|
219
|
+
const SCHEMA_LOCK_PREFIX = `(SELECT CASE WHEN name = 'public' THEN '' ELSE name || ':' END
|
|
220
|
+
FROM (SELECT trim(both '"' from split_part(current_setting('search_path'), ',', 1)) AS name) AS search)`;
|
|
221
|
+
/** One read that takes every one of `locks` it can without waiting, and tells whether it took them all. */
|
|
222
|
+
function tryLocksStatement(locks) {
|
|
223
|
+
const taken = locks.map(({ inSchema, shared }) => `pg_try_advisory_xact_lock${shared === true ? "_shared" : ""}(hashtextextended(${inSchema === true ? `${SCHEMA_LOCK_PREFIX} || ` : ""}?, 0))`);
|
|
224
|
+
return { sql: `SELECT (${taken.join(" AND ")})::int AS won`, params: locks.map(({ scope }) => scope) };
|
|
225
|
+
}
|
|
226
|
+
const pause = (ms) => new Promise((resolve) => setTimeout(resolve, ms * (0.5 + Math.random() / 2)));
|
|
227
|
+
/**
|
|
228
|
+
* @internal Runs `once.setup`, a schema setup, so that of the processes that start it at once, on a new database say,
|
|
229
|
+
* one runs it and the others wait for it without queueing for its lock (#6560). The setup's transaction tries its locks
|
|
230
|
+
* without waiting: an advisory lock on PostgreSQL (`once.locks`), the database's write lock on a SQLite file. A process
|
|
231
|
+
* that finds them taken holds no lock and no connection while it waits: it polls `once.done`, with growing pauses,
|
|
232
|
+
* until the setup is done, and tries again whenever it is not, so a holder that set up something else, or failed, or
|
|
233
|
+
* died, leaves the setup to the next try. After {@link SETUP_WAIT_MS} ({@link SQLITE_SETUP_WAIT_MS} on SQLite) it
|
|
234
|
+
* waits for the lock in the transaction `once.concurrency` names, as before. Where the database tries no lock without waiting, the setup runs in that
|
|
235
|
+
* transaction at once.
|
|
236
|
+
*/
|
|
237
|
+
export async function setUpStorageOnce(database, once) {
|
|
238
|
+
const attempt = trySetup(database, once);
|
|
239
|
+
const waiting = () => database.transaction((transaction) => once.setup(transaction, false), {
|
|
240
|
+
retryTransientFailures: true,
|
|
241
|
+
concurrency: once.concurrency,
|
|
242
|
+
});
|
|
243
|
+
if (attempt === undefined)
|
|
244
|
+
return waiting();
|
|
245
|
+
const deadline = performance.now() + (dialectOf(database).name === "postgres" ? SETUP_WAIT_MS : SQLITE_SETUP_WAIT_MS);
|
|
246
|
+
for (let wait = SETUP_POLL_MS;; wait = Math.min(wait * 2, SETUP_MAX_POLL_MS)) {
|
|
247
|
+
const tried = await attempt();
|
|
248
|
+
if (tried.won)
|
|
249
|
+
return tried.value;
|
|
250
|
+
if (performance.now() >= deadline)
|
|
251
|
+
return waiting();
|
|
252
|
+
await pause(wait);
|
|
253
|
+
const done = await once.done();
|
|
254
|
+
if (done !== undefined)
|
|
255
|
+
return done;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
/** One try at `once`'s setup that does not wait for its locks, or undefined where `database` cannot try one. */
|
|
259
|
+
function trySetup(database, once) {
|
|
260
|
+
if (dialectOf(database).name === "postgres") {
|
|
261
|
+
// A fenced transaction takes no lock with its start: the try is its first statement, sent with that start.
|
|
262
|
+
return () => {
|
|
263
|
+
const lock = tryLocksStatement(once.locks);
|
|
264
|
+
return database.transaction(async (transaction) => {
|
|
265
|
+
const row = await transaction.get(lock.sql, ...lock.params);
|
|
266
|
+
if (row?.won !== true && Number(row?.won) !== 1)
|
|
267
|
+
return { won: false };
|
|
268
|
+
return { won: true, value: await once.setup(transaction, true) };
|
|
269
|
+
}, {
|
|
270
|
+
retryTransientFailures: true,
|
|
271
|
+
concurrency: { kind: "fenced", audit: fencedPath("schema-setup") },
|
|
272
|
+
leading: [lock, ...(once.leading ?? [])],
|
|
273
|
+
});
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
const tryMaintenance = database.tryMaintenance?.bind(database);
|
|
277
|
+
if (tryMaintenance === undefined)
|
|
278
|
+
return undefined;
|
|
279
|
+
return async () => {
|
|
280
|
+
let value;
|
|
281
|
+
const won = await tryMaintenance(async (transaction) => {
|
|
282
|
+
value = await once.setup(transaction, false);
|
|
283
|
+
});
|
|
284
|
+
return won ? { won, value } : { won };
|
|
285
|
+
};
|
|
286
|
+
}
|
|
115
287
|
/**
|
|
116
288
|
* Migrates each of `migrations` in order, as {@link applyStorageMigrations} would, and resolves with each one's result.
|
|
117
289
|
* Where the dialect records no versions (SQLite), every step runs every time, so the domains share one transaction: one
|
|
@@ -168,14 +340,16 @@ export async function withShortSchemaLockWaits(executor, dialect, setup) {
|
|
|
168
340
|
return setup();
|
|
169
341
|
return underShortLockWaits(executor, setup);
|
|
170
342
|
}
|
|
171
|
-
async function underShortLockWaits(executor, setup) {
|
|
172
|
-
const previous = await executor.get(
|
|
343
|
+
async function underShortLockWaits(executor, setup, known, after = [], last = false) {
|
|
344
|
+
const previous = known ?? (await executor.get(LOCK_WAIT_SQL));
|
|
173
345
|
for (let attempt = 1;; attempt++) {
|
|
174
|
-
|
|
175
|
-
|
|
346
|
+
// Sent with the setup's first statement, on a connection that pipelines a transaction's statements: no round trip
|
|
347
|
+
// of its own. A failure of either fails the setup.
|
|
348
|
+
const saved = executor.exec(`SAVEPOINT atomic_schema_setup; SET LOCAL lock_timeout = ${SCHEMA_SETUP_LOCK_WAIT_MS}`);
|
|
349
|
+
saved.catch(() => { });
|
|
176
350
|
try {
|
|
177
351
|
await setup();
|
|
178
|
-
await
|
|
352
|
+
await saved;
|
|
179
353
|
break;
|
|
180
354
|
}
|
|
181
355
|
catch (error) {
|
|
@@ -186,12 +360,33 @@ async function underShortLockWaits(executor, setup) {
|
|
|
186
360
|
await new Promise((resolve) => setTimeout(resolve, pause * (0.5 + Math.random() / 2)));
|
|
187
361
|
}
|
|
188
362
|
}
|
|
189
|
-
|
|
363
|
+
// The savepoint's release, the lock wait restored, unless nothing follows in the transaction, and `after` go out
|
|
364
|
+
// together: with the commit, where they are the transaction's `last` statements and its connection allows it.
|
|
365
|
+
const statements = [
|
|
366
|
+
{ sql: "RELEASE SAVEPOINT atomic_schema_setup", params: [], script: true },
|
|
367
|
+
...(last
|
|
368
|
+
? []
|
|
369
|
+
: [
|
|
370
|
+
{
|
|
371
|
+
sql: `SET LOCAL lock_timeout = '${String(previous?.wait ?? "0").replaceAll("'", "''")}'`,
|
|
372
|
+
params: [],
|
|
373
|
+
script: true,
|
|
374
|
+
},
|
|
375
|
+
]),
|
|
376
|
+
...after,
|
|
377
|
+
];
|
|
378
|
+
if (last && finishers.transactionFinisher?.(executor)?.(statements) === true)
|
|
379
|
+
return;
|
|
380
|
+
await Promise.all(statements.map((statement) => statement.script === true ? executor.exec(statement.sql) : executor.run(statement.sql, ...statement.params)));
|
|
190
381
|
}
|
|
382
|
+
/** The transaction's lock wait, which a setup lowers while it runs and then restores. */
|
|
383
|
+
const LOCK_WAIT_SQL = "SELECT current_setting('lock_timeout') AS wait";
|
|
384
|
+
/** The prefix's setup lock, which every schema setup holds on PostgreSQL: see {@link ensureStorageSchema}. */
|
|
385
|
+
const SETUP_LOCK_SQL = "SELECT pg_advisory_xact_lock(hashtextextended(?, 0)) AS locked";
|
|
191
386
|
/**
|
|
192
387
|
* Whether the catalog an open in progress read (`withStorageSchemaCatalog`) records `schema.revision` for the
|
|
193
388
|
* store already, so {@link ensureStorageSchema} would run nothing: the store's open then skips its schema transaction
|
|
194
|
-
* and its lock (#6560). On SQLite
|
|
389
|
+
* and its lock (#6560). On SQLite the store's schema stamp records it, and only while nothing changed the
|
|
195
390
|
* schema since (`sqliteSchemaStampTable`). False outside such an open, and when the revision is not recorded.
|
|
196
391
|
*/
|
|
197
392
|
export async function storageSchemaCurrent(database, schema) {
|
|
@@ -211,11 +406,11 @@ export async function storageSchemaCurrent(database, schema) {
|
|
|
211
406
|
* database with versioned migrations (PostgreSQL) a current schema runs no DDL at all, so a runtime role with only DML
|
|
212
407
|
* privileges opens it; a schema that is behind runs `setup` under the store's advisory lock, then records the revision,
|
|
213
408
|
* so concurrent processes set it up once. A role that may not run the DDL then fails with
|
|
214
|
-
* `StorageConfigError` reason `missing-privilege` from the adapter. On SQLite
|
|
409
|
+
* `StorageConfigError` reason `missing-privilege` from the adapter. On SQLite, which keep no ledger, `setup`
|
|
215
410
|
* runs every time it is called, as before, and then stamps the store with the schema version the transaction leaves,
|
|
216
411
|
* which {@link storageSchemaCurrent} believes until the schema changes again (#6560).
|
|
217
412
|
*/
|
|
218
|
-
export async function ensureStorageSchema(executor, dialect, schema, setup) {
|
|
413
|
+
export async function ensureStorageSchema(executor, dialect, schema, setup, options = {}) {
|
|
219
414
|
if (!dialect.versionedMigrations) {
|
|
220
415
|
await setup();
|
|
221
416
|
if (dialect.name === "sqlite")
|
|
@@ -224,46 +419,177 @@ export async function ensureStorageSchema(executor, dialect, schema, setup) {
|
|
|
224
419
|
}
|
|
225
420
|
const { ledger, domain, revision } = schema;
|
|
226
421
|
const key = `schema:${domain}`;
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
await executor.get("SELECT pg_advisory_xact_lock(hashtextextended(?, 0)) AS locked", `${ledger}:schema`);
|
|
422
|
+
const record = {
|
|
423
|
+
sql: `INSERT INTO ${ledger} (domain, version, applied_at) VALUES (?, ?, ${dialect.nowMs}) ON CONFLICT DO NOTHING`,
|
|
424
|
+
params: [key, revision],
|
|
425
|
+
};
|
|
426
|
+
if (dialect.name !== "postgres") {
|
|
233
427
|
if ((await recordedVersion(executor, dialect, ledger, key)) >= revision)
|
|
234
428
|
return;
|
|
235
|
-
await assertSchemaUsage(executor, dialect);
|
|
236
|
-
await underShortLockWaits(executor, setup);
|
|
237
|
-
}
|
|
238
|
-
else
|
|
239
429
|
await setup();
|
|
240
|
-
|
|
241
|
-
|
|
430
|
+
await createLedger(executor, dialect, ledger);
|
|
431
|
+
await executor.run(record.sql, ...record.params);
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
let ledgerFound = options.locked === true && options.ledgerExists === true;
|
|
435
|
+
if (options.locked !== true) {
|
|
436
|
+
ledgerFound = await tableExists(executor, dialect, ledger);
|
|
437
|
+
if (ledgerFound && (await recordedVersion(executor, dialect, ledger, key, true)) >= revision)
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
// Serialized per prefix, so hosts that start together on a new database set each store up once, and two stores
|
|
441
|
+
// that create a table they share never race to create it. The reads go out with the lock, and each runs after it:
|
|
442
|
+
// what a holder before it recorded, whether this role may use the schema, and the lock wait the setup restores.
|
|
443
|
+
const [first, usage, lockWait] = postgresSetupReads(dialect, ledger, key, ledgerFound);
|
|
444
|
+
const [, found, access, wait] = await Promise.all([
|
|
445
|
+
options.locked === true ? undefined : executor.get(SETUP_LOCK_SQL, `${ledger}:schema`),
|
|
446
|
+
executor.get(first.sql, ...first.params),
|
|
447
|
+
executor.get(usage.sql, ...usage.params),
|
|
448
|
+
executor.get(lockWait.sql, ...lockWait.params),
|
|
449
|
+
]);
|
|
450
|
+
const ledgerExists = ledgerFound || found !== undefined;
|
|
451
|
+
const recorded = ledgerFound
|
|
452
|
+
? Number(found?.version ?? 0)
|
|
453
|
+
: ledgerExists
|
|
454
|
+
? await recordedVersion(executor, dialect, ledger, key, true)
|
|
455
|
+
: 0;
|
|
456
|
+
if (recorded >= revision)
|
|
457
|
+
return;
|
|
458
|
+
refuseWithoutSchemaUsage(access);
|
|
459
|
+
const { int, text } = dialect.types;
|
|
460
|
+
// The ledger, created where it is missing, and the record go out with the savepoint's release.
|
|
461
|
+
const createLedgerStatement = {
|
|
462
|
+
sql: `CREATE TABLE IF NOT EXISTS ${ledger} (domain ${text} NOT NULL, version ${int} NOT NULL, applied_at ${int} NOT NULL, PRIMARY KEY (domain, version))${dialect.tableOptions}`,
|
|
463
|
+
params: [],
|
|
464
|
+
script: true,
|
|
465
|
+
};
|
|
466
|
+
await underShortLockWaits(executor, setup, wait, ledgerExists ? [record] : [createLedgerStatement, record], options.last === true);
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* The reads a PostgreSQL setup of the ledger key `key` makes first, under its locks, in this order: the version the
|
|
470
|
+
* ledger records, where it is known to exist, or else whether it does; the schema's usage; and the lock wait the setup
|
|
471
|
+
* restores. A {@link setUpStorageOnce} try sends them with its start.
|
|
472
|
+
*/
|
|
473
|
+
function postgresSetupReads(dialect, ledger, key, ledgerExists) {
|
|
474
|
+
return [
|
|
475
|
+
ledgerExists ? { sql: versionRead(ledger, key)[0], params: [key] } : dialect.tableExists(ledger),
|
|
476
|
+
{ sql: SCHEMA_USAGE_SQL, params: [] },
|
|
477
|
+
{ sql: LOCK_WAIT_SQL, params: [] },
|
|
478
|
+
];
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* The advisory locks a PostgreSQL setup recorded in `ledger` under `key` tries: the prefix's setup lock, exclusive while
|
|
482
|
+
* the ledger may be missing, so one setup creates it, and shared once it exists, so the setups of other stores run
|
|
483
|
+
* beside it while an earlier build's setup, which takes it exclusive, runs alone; and a lock of the key's own, so one
|
|
484
|
+
* process sets each store up.
|
|
485
|
+
*/
|
|
486
|
+
function setupLocks(ledger, key, ledgerExists) {
|
|
487
|
+
return [{ scope: `${ledger}:schema`, shared: ledgerExists }, { scope: `${ledger}:schema:${key}` }];
|
|
242
488
|
}
|
|
489
|
+
/**
|
|
490
|
+
* Runs `setup`, a store's idempotent schema statements, as {@link ensureStorageSchema} does, in a transaction of its own:
|
|
491
|
+
* of the processes that open a new database at once, one runs it and the others wait for the ledger to record it,
|
|
492
|
+
* without its lock (`setUpStorageOnce`, #6560). Inside an open, a revision the open's catalog records runs nothing; the
|
|
493
|
+
* caller checks that first (`storageSchemaCurrent`). PostgreSQL; elsewhere the setup runs in a serial transaction of the
|
|
494
|
+
* ledger's domain.
|
|
495
|
+
*/
|
|
496
|
+
export async function ensureStorageSchemaOnce(database, schema, setup) {
|
|
497
|
+
const dialect = dialectOf(database);
|
|
498
|
+
const { ledger, domain, revision } = schema;
|
|
499
|
+
const concurrency = { kind: "serial", domain: ledger };
|
|
500
|
+
if (dialect.name !== "postgres") {
|
|
501
|
+
await database.transaction((tx) => ensureStorageSchema(tx, dialect, schema, () => setup(tx)), {
|
|
502
|
+
retryTransientFailures: true,
|
|
503
|
+
concurrency,
|
|
504
|
+
});
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
const key = `schema:${domain}`;
|
|
508
|
+
let ledgerExists = await ledgerInCatalog(database, ledger);
|
|
509
|
+
await setUpStorageOnce(database, {
|
|
510
|
+
get locks() {
|
|
511
|
+
return setupLocks(ledger, key, ledgerExists);
|
|
512
|
+
},
|
|
513
|
+
get leading() {
|
|
514
|
+
return postgresSetupReads(dialect, ledger, key, ledgerExists);
|
|
515
|
+
},
|
|
516
|
+
done: async () => {
|
|
517
|
+
const recorded = await recordedNow(database, ledger, key, ledgerExists);
|
|
518
|
+
ledgerExists ||= await ledgerInCatalog(database, ledger);
|
|
519
|
+
return recorded >= revision ? true : undefined;
|
|
520
|
+
},
|
|
521
|
+
setup: async (tx, locked) => {
|
|
522
|
+
await ensureStorageSchema(tx, dialect, schema, () => setup(tx), { locked, ledgerExists, last: true });
|
|
523
|
+
return true;
|
|
524
|
+
},
|
|
525
|
+
concurrency,
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* The fillfactor checks this process made that found nothing for it to do, by database (`databaseIdentity`, which
|
|
530
|
+
* names the role and schema too), ledger and table, and the ones under way: the table had a fillfactor, or this role
|
|
531
|
+
* does not own it (#6560). Such a check is not made again. One that set the fillfactor, or found no table, is.
|
|
532
|
+
*/
|
|
533
|
+
const fillfactorChecks = new Map();
|
|
243
534
|
/**
|
|
244
535
|
* Sets `setup.table`'s fillfactor on PostgreSQL, once per database, recorded in the ledger as `schema:<domain>`: each
|
|
245
536
|
* page then keeps room for a new version of the rows on it, so updates of rows that change no indexed column stay on
|
|
246
537
|
* their page as HOT updates and touch no index (#6560). It applies to the pages written from then on; `VACUUM FULL`
|
|
247
|
-
* or pg_repack rewrites the existing ones with it. Nothing runs where the catalog an open read records the step
|
|
248
|
-
*
|
|
249
|
-
*
|
|
538
|
+
* or pg_repack rewrites the existing ones with it. Nothing runs where the catalog an open read records the step.
|
|
539
|
+
* Otherwise one read of the table's catalog entry decides: nothing runs where the table has a fillfactor already, or
|
|
540
|
+
* where this role does not own the table, so a runtime role without DDL opens as before, and `atomic storage migrate`,
|
|
541
|
+
* run as the owner, sets it. A process reads that once for each database and table, so until migrate records the step
|
|
542
|
+
* only its first open pays the read. Does nothing on SQLite.
|
|
250
543
|
*/
|
|
251
544
|
export async function ensureTableFillfactor(database, setup) {
|
|
252
545
|
const dialect = dialectOf(database);
|
|
253
546
|
if (dialect.name !== "postgres" || database.readOnly === true)
|
|
254
547
|
return;
|
|
548
|
+
const { ledger, domain, revision, table } = setup;
|
|
549
|
+
if (await storageSchemaCurrent(database, { ledger, domain, revision }))
|
|
550
|
+
return;
|
|
551
|
+
const identity = database.databaseIdentity?.();
|
|
552
|
+
if (identity === undefined) {
|
|
553
|
+
await checkTableFillfactor(database, setup);
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
556
|
+
const key = JSON.stringify([identity, ledger, table]);
|
|
557
|
+
let check = fillfactorChecks.get(key);
|
|
558
|
+
if (check === undefined) {
|
|
559
|
+
const made = checkTableFillfactor(database, setup);
|
|
560
|
+
check = made;
|
|
561
|
+
fillfactorChecks.set(key, made);
|
|
562
|
+
const forget = () => {
|
|
563
|
+
if (fillfactorChecks.get(key) === made)
|
|
564
|
+
fillfactorChecks.delete(key);
|
|
565
|
+
};
|
|
566
|
+
made.then((settled) => {
|
|
567
|
+
if (!settled)
|
|
568
|
+
forget();
|
|
569
|
+
}, forget);
|
|
570
|
+
}
|
|
571
|
+
await check;
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* {@link ensureTableFillfactor}'s read of the table's catalog entry, and the change where it is due. True where it
|
|
575
|
+
* found nothing this role can do: the table has a fillfactor, or this role does not own it.
|
|
576
|
+
*/
|
|
577
|
+
async function checkTableFillfactor(database, setup) {
|
|
578
|
+
const dialect = dialectOf(database);
|
|
255
579
|
const { ledger, domain, revision, table, fillfactor } = setup;
|
|
256
580
|
const schema = { ledger, domain, revision };
|
|
257
|
-
if (await storageSchemaCurrent(database, schema))
|
|
258
|
-
return;
|
|
259
581
|
const found = await database.get(`SELECT pg_catalog.pg_has_role(current_user, c.relowner, 'USAGE') AS owned,
|
|
260
582
|
coalesce(array_to_string(c.reloptions, ',') LIKE '%fillfactor=%', false) AS tuned
|
|
261
583
|
FROM pg_catalog.pg_class c WHERE c.relnamespace = current_schema()::regnamespace AND c.relname = ?`, dialect.identifier(table));
|
|
262
584
|
const yes = (value) => value === true || Number(value) === 1;
|
|
263
|
-
if (found === undefined
|
|
264
|
-
return;
|
|
265
|
-
|
|
585
|
+
if (found === undefined)
|
|
586
|
+
return false;
|
|
587
|
+
if (yes(found.tuned) || !yes(found.owned))
|
|
588
|
+
return true;
|
|
589
|
+
// Hosts that open a new database at once set it once, and the others wait for that without the lock.
|
|
590
|
+
await ensureStorageSchemaOnce(database, schema, async (tx) => {
|
|
266
591
|
await tx.exec(`ALTER TABLE ${table} SET (fillfactor = ${Math.trunc(fillfactor)})`);
|
|
267
|
-
})
|
|
592
|
+
});
|
|
593
|
+
return false;
|
|
268
594
|
}
|
|
269
595
|
//# sourceMappingURL=migrations.js.map
|