@bastani/atomic 0.10.10 → 0.10.11-alpha.2
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 +139 -0
- package/README.md +1 -1
- 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 +11 -13
- package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js.map +1 -1
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +9 -9
- package/dist/_shared/mode-shared-2QJSCUM6.js +55 -18
- package/dist/_shared/mode-shared-2QJSCUM6.js.map +1 -1
- package/dist/_shared/p1a-prewarm-XIU57JHF.js +3 -3
- package/dist/_shared/runtime-O4KCSG4C.js +5 -5
- package/dist/_shared/{sdk-RRLVN7ER.js → sdk-IQMULKFU.js} +2962 -470
- package/dist/_shared/sdk-IQMULKFU.js.map +1 -0
- package/dist/_shared/session-data-AHTU7IS6.js +4 -4
- package/dist/_shared/session-manager-list-2BLEEZVG.js +1 -1
- package/dist/_shared/settings-startup-8-DNZ2RIHM.js +1 -1
- package/dist/_shared/{settings-startup-4QCVCI53.js → settings-startup-HXQLSUWM.js} +8 -2
- package/dist/_shared/settings-startup-HXQLSUWM.js.map +1 -0
- package/dist/_shared/{startup-0-0-4VG2G44V.js → startup-0-0-3IXNMFM2.js} +482 -53
- package/dist/_shared/startup-0-0-3IXNMFM2.js.map +1 -0
- package/dist/_shared/{startup-0-1-XTIL65D4.js → startup-0-1-7T2IAE7J.js} +121 -251
- package/dist/_shared/startup-0-1-7T2IAE7J.js.map +1 -0
- package/dist/_shared/{startup-0-2-27OWFHV6.js → startup-0-2-5QHPCEON.js} +293 -10
- package/dist/_shared/startup-0-2-5QHPCEON.js.map +1 -0
- package/dist/_shared/{startup-0-3-T4DVFYWX.js → startup-0-3-4ZYBYQNM.js} +273 -14
- package/dist/_shared/startup-0-3-4ZYBYQNM.js.map +1 -0
- package/dist/_shared/startup-0-4-ZMJV547D.js +6 -6
- package/dist/_shared/{startup-0-5-FD2P735I.js → startup-0-5-YDW47QX6.js} +29 -71
- package/dist/_shared/startup-0-5-YDW47QX6.js.map +1 -0
- package/dist/_shared/startup-10-0-TDQNBDDL.js +9 -9
- package/dist/_shared/startup-12-0-55AAXBJZ.js +4 -4
- package/dist/_shared/startup-14-0-MLX36RBG.js +6 -6
- package/dist/_shared/startup-15-0-YUKGAC63.js +34 -10
- package/dist/_shared/startup-15-0-YUKGAC63.js.map +1 -1
- package/dist/_shared/startup-15-1-4S7FLMNG.js +10 -9
- package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
- package/dist/_shared/startup-8-0-34CBHPZH.js +421 -84
- package/dist/_shared/startup-8-0-34CBHPZH.js.map +1 -1
- package/dist/_shared/{startup-8-1-4KANEHRA.js → startup-8-1-X32CYSXB.js} +1291 -722
- package/dist/_shared/startup-8-1-X32CYSXB.js.map +1 -0
- package/dist/_shared/storage-command-7MGXLJGZ.js +17 -9
- package/dist/_shared/storage-command-7MGXLJGZ.js.map +1 -1
- package/dist/_shared/task-reference-stream-JWMUZSJX.js +1 -1
- package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
- package/dist/_shared/tree-outline-MUEPK5B7.js +3 -3
- package/dist/builtin/intercom/CHANGELOG.md +29 -0
- package/dist/builtin/intercom/broker/broker.bundle.mjs +1138 -384
- package/dist/builtin/intercom/broker/database-wake-up-bus.ts +103 -24
- package/dist/builtin/intercom/broker/multinode-router.ts +42 -21
- package/dist/builtin/intercom/broker/multinode-state-store.ts +22 -1
- package/dist/builtin/intercom/broker/open-broker-state.ts +82 -31
- package/dist/builtin/intercom/broker/paths.ts +8 -4
- package/dist/builtin/intercom/broker/released-asker-remote-replies.ts +18 -6
- package/dist/builtin/intercom/broker/sql-add-column.ts +4 -1
- package/dist/builtin/intercom/broker/sql-ended-child-queue-store.ts +65 -44
- package/dist/builtin/intercom/broker/sql-held-send-store.ts +11 -3
- package/dist/builtin/intercom/broker/sql-known-session-store.ts +24 -12
- package/dist/builtin/intercom/broker/sql-lease-store.ts +386 -65
- package/dist/builtin/intercom/broker/sql-outbox-store.ts +462 -130
- package/dist/builtin/intercom/broker/sql-pending-ask-store.ts +20 -9
- package/dist/builtin/intercom/broker/sql-released-ask-store.ts +14 -6
- package/dist/builtin/intercom/broker/sql-restoring-reservation-store.ts +27 -11
- package/dist/builtin/intercom/broker/sql-schema.ts +198 -5
- package/dist/builtin/intercom/broker/sql-sent-message-authority.ts +97 -34
- package/dist/builtin/intercom/index.bundle.mjs +11 -8
- 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 +18 -0
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/skills/skill-creator/SKILL.md +1 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +62 -23
- package/dist/builtin/web-access/index.bundle.mjs +1 -1
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/cli/args.js +2 -2
- package/dist/cli/auth-cli.code.js +6 -6
- package/dist/cli/auth-cli.impl.js +3 -3
- package/dist/cli/auth-cli.js +3 -3
- package/dist/cli/blueprint-command.code.js +4 -4
- package/dist/cli/blueprint-command.impl.js +3 -3
- package/dist/cli/blueprint-command.js +3 -3
- package/dist/cli/intercom-command.code.js +3 -3
- package/dist/cli/intercom-command.impl.js +3 -3
- package/dist/cli/intercom-command.js +3 -3
- package/dist/cli/list-models.code.js +2 -2
- package/dist/cli/list-models.impl.js +3 -3
- package/dist/cli/list-models.js +3 -3
- package/dist/cli/session-picker.code.js +2 -2
- package/dist/cli/session-picker.impl.js +3 -3
- package/dist/cli/session-picker.js +3 -3
- package/dist/cli/startup-ui.code.js +2 -2
- package/dist/cli/startup-ui.impl.js +3 -3
- package/dist/cli/startup-ui.js +3 -3
- package/dist/cli/storage-command.impl.js +3 -3
- package/dist/cli/storage-command.js +3 -3
- package/dist/cli/storage-search-session.code.js +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 +3 -3
- package/dist/cli/team-command.impl.js +3 -3
- package/dist/cli/team-command.js +3 -3
- package/dist/cli.js +2 -2
- package/dist/core/agent-session-methods.d.ts +3 -0
- package/dist/core/agent-session-methods.js.map +1 -1
- package/dist/core/agent-session.d.ts +1 -0
- package/dist/core/compaction/compactor.d.ts +2 -0
- package/dist/core/debug.impl.js +3 -3
- package/dist/core/debug.js +3 -3
- package/dist/core/export-html/card-projection.code.js +1 -1
- package/dist/core/export-html/card-projection.impl.js +3 -3
- package/dist/core/export-html/card-projection.js +3 -3
- package/dist/core/export-html/index.code.js +2 -2
- package/dist/core/export-html/index.impl.js +3 -3
- package/dist/core/export-html/index.js +3 -3
- package/dist/core/export-html/json-spans.impl.js +3 -3
- package/dist/core/export-html/json-spans.js +3 -3
- package/dist/core/export-html/oversized-render-inputs.code.js +2 -2
- package/dist/core/export-html/oversized-render-inputs.impl.js +3 -3
- package/dist/core/export-html/oversized-render-inputs.js +3 -3
- package/dist/core/export-html/tool-renderer.impl.js +3 -3
- package/dist/core/export-html/tool-renderer.js +3 -3
- package/dist/core/extensions/jiti-loader.impl.js +3 -3
- package/dist/core/extensions/jiti-loader.js +3 -3
- package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
- package/dist/core/extensions/jiti-static-loader.js +3 -3
- package/dist/core/extensions/loader-host-modules.code.js +1 -1
- package/dist/core/extensions/loader-host-modules.impl.js +3 -3
- package/dist/core/extensions/loader-host-modules.js +3 -3
- package/dist/core/extensions/loader-virtual-modules.js +2 -2
- package/dist/core/extensions/runner-context.js +4 -4
- package/dist/core/extensions/runner-context.js.map +1 -1
- package/dist/core/intercom-broker-control-host.code.js +1 -1
- package/dist/core/intercom-broker-control-host.impl.js +3 -3
- package/dist/core/intercom-broker-control-host.js +3 -3
- package/dist/core/intercom-broker-control.code.js +3 -3
- package/dist/core/intercom-broker-control.impl.js +3 -3
- package/dist/core/intercom-broker-control.js +3 -3
- package/dist/core/model-registry.js +1 -1
- package/dist/core/model-resolver-defaults.d.ts +3 -2
- 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/sdk.code.js +4 -5
- package/dist/core/sdk.impl.js +3 -3
- package/dist/core/sdk.js +3 -3
- package/dist/core/session-manager-core.d.ts +5 -2
- package/dist/core/session-manager-core.js +39 -23
- package/dist/core/session-manager-core.js.map +1 -1
- 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 +3 -3
- package/dist/core/session-manager.impl.js +3 -3
- package/dist/core/session-manager.js +3 -3
- package/dist/core/session-open-markers.js +3 -0
- package/dist/core/session-open-markers.js.map +1 -0
- 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/storage/added-exports.d.ts +6 -0
- package/dist/core/storage/added-exports.js +19 -0
- package/dist/core/storage/added-exports.js.map +1 -0
- package/dist/core/storage/database.d.ts +53 -0
- package/dist/core/storage/database.js.map +1 -1
- package/dist/core/storage/fenced-paths.d.ts +47 -0
- package/dist/core/storage/fenced-paths.js +53 -0
- package/dist/core/storage/fenced-paths.js.map +1 -1
- package/dist/core/storage/file-identity.js +31 -2
- package/dist/core/storage/file-identity.js.map +1 -1
- package/dist/core/storage/index.d.ts +4 -1
- package/dist/core/storage/index.js +5 -2
- package/dist/core/storage/index.js.map +1 -1
- package/dist/core/storage/migrations.d.ts +33 -2
- package/dist/core/storage/migrations.js +73 -5
- package/dist/core/storage/migrations.js.map +1 -1
- package/dist/core/storage/node-sqlite-thread.js +48 -6
- package/dist/core/storage/node-sqlite-thread.js.map +1 -1
- package/dist/core/storage/node-sqlite.js +137 -4
- 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 +3 -2
- package/dist/core/storage/prefix.js +23 -2
- package/dist/core/storage/prefix.js.map +1 -1
- package/dist/core/storage/provider.js +2 -2
- package/dist/core/storage/schema-catalog.d.ts +120 -0
- package/dist/core/storage/schema-catalog.js +351 -0
- package/dist/core/storage/schema-catalog.js.map +1 -0
- package/dist/core/storage/selection.js +2 -2
- package/dist/core/storage/session/branch-fork-source.code.js +47 -25
- package/dist/core/storage/session/branch-fork-source.code.js.map +1 -1
- 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 +4 -4
- package/dist/core/storage/session/child-reader.impl.js +3 -3
- package/dist/core/storage/session/child-reader.js +3 -3
- package/dist/core/storage/session/chunked-resume-projection.code.js +1 -1
- package/dist/core/storage/session/chunked-resume-projection.impl.js +3 -3
- package/dist/core/storage/session/chunked-resume-projection.js +3 -3
- package/dist/core/storage/session/errors.js +1 -1
- package/dist/core/storage/session/expanded-child-details.code.js +4 -4
- 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 +118 -0
- 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-schema.js +53 -0
- package/dist/core/storage/session/fork-schema.js.map +1 -0
- package/dist/core/storage/session/fork-segments.d.ts +58 -0
- package/dist/core/storage/session/fork-staging.code.js +176 -36
- 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 +61 -0
- package/dist/core/storage/session/fork-sweep.js.map +1 -0
- package/dist/core/storage/session/fork-window.code.js +4 -4
- package/dist/core/storage/session/fork-window.impl.js +3 -3
- package/dist/core/storage/session/fork-window.js +3 -3
- package/dist/core/storage/session/history-pages.impl.js +3 -3
- package/dist/core/storage/session/history-pages.js +3 -3
- package/dist/core/storage/session/jsonl-entry-projection.impl.js +3 -3
- package/dist/core/storage/session/jsonl-entry-projection.js +3 -3
- package/dist/core/storage/session/jsonl-session-store.d.ts +37 -1
- 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 +3 -3
- 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.code.js +1 -1
- 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 +5 -0
- package/dist/core/storage/session/snapshot-cut.impl.js +3 -3
- package/dist/core/storage/session/snapshot-cut.js +3 -3
- package/dist/core/storage/session/snapshot-history.code.js +4 -4
- package/dist/core/storage/session/snapshot-history.impl.js +3 -3
- package/dist/core/storage/session/snapshot-history.js +3 -3
- package/dist/core/storage/session/sql-chat-records.d.ts +15 -0
- package/dist/core/storage/session/sql-session-store.code.js +1 -1
- package/dist/core/storage/session/sql-session-store.d.ts +445 -11
- package/dist/core/storage/session/sql-session-store.impl.js +4 -4
- package/dist/core/storage/session/sql-session-store.js +4 -4
- package/dist/core/storage/session/tree-outline.impl.js +3 -3
- package/dist/core/storage/session/tree-outline.js +3 -3
- package/dist/core/storage/session/tree-presentation.code.js +1 -1
- package/dist/core/storage/session/tree-presentation.impl.js +3 -3
- package/dist/core/storage/session/tree-presentation.js +3 -3
- package/dist/core/storage/session/types.d.ts +36 -0
- package/dist/core/storage/sqlite-facade.d.ts +54 -6
- package/dist/core/storage/sqlite-facade.js +384 -18
- package/dist/core/storage/sqlite-facade.js.map +1 -1
- package/dist/core/storage/statement-sequence.d.ts +83 -0
- package/dist/core/storage/statement-sequence.js +21 -0
- package/dist/core/storage/statement-sequence.js.map +1 -1
- 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.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.code.js +1 -1
- package/dist/core/tasks/task-completion-entry.impl.js +3 -3
- package/dist/core/tasks/task-completion-entry.js +3 -3
- package/dist/core/tasks/task-file-history.code.js +4 -4
- 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 +5 -5
- 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/bash.d.ts +8 -4
- package/dist/core/tools/history-session.d.ts +7 -0
- package/dist/core/tools/history-tasks.d.ts +123 -0
- package/dist/core/tools/kill.d.ts +5 -2
- package/dist/core/tools/powershell.d.ts +2 -2
- package/dist/core/tools/read-url.code.js +3 -3
- package/dist/core/tools/read-url.impl.js +3 -3
- package/dist/core/tools/read-url.js +3 -3
- package/dist/core/tools/read.d.ts +12 -2
- package/dist/core/tools/resource-selectors.d.ts +2 -0
- package/dist/core/tools/search.d.ts +12 -2
- package/dist/core/worktree-snapshot/blob-store.d.ts +45 -2
- package/dist/core/worktree-snapshot/blob-store.js +228 -60
- package/dist/core/worktree-snapshot/blob-store.js.map +1 -1
- package/dist/core/worktree-snapshot/errors.code.js +3 -3
- package/dist/core/worktree-snapshot/errors.impl.js +3 -3
- package/dist/core/worktree-snapshot/errors.js +3 -3
- package/dist/core/worktree-snapshot/fork-snapshot-index.js +121 -0
- package/dist/core/worktree-snapshot/fork-snapshot-index.js.map +1 -0
- package/dist/core/worktree-snapshot/session-index-reset.impl.js +3 -3
- package/dist/core/worktree-snapshot/session-index-reset.js +3 -3
- package/dist/extensions/codemode/execute.code.js +3 -3
- 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.js +8 -8
- package/dist/main-first-time-setup.code.js +2 -2
- package/dist/main-first-time-setup.impl.js +3 -3
- package/dist/main-first-time-setup.js +3 -3
- package/dist/main.js +1 -1
- package/dist/modes/interactive/components/agent-panel.d.ts +1 -0
- package/dist/modes/interactive/components/stored-tree-view.code.js +3 -3
- package/dist/modes/interactive/components/stored-tree-view.impl.js +3 -3
- package/dist/modes/interactive/components/stored-tree-view.js +3 -3
- package/dist/modes/interactive/components/task-inspector.d.ts +2 -0
- package/dist/modes/interactive/components/user-message-selector-archive.code.js +1 -1
- package/dist/modes/interactive/components/user-message-selector-archive.impl.js +3 -3
- package/dist/modes/interactive/components/user-message-selector-archive.js +3 -3
- package/dist/modes/interactive/interactive-mode-helpers.d.ts +2 -2
- package/dist/modes/print-mode.js +1 -1
- package/dist/modes/rpc/agent-panel-bridge.d.ts +5 -0
- package/dist/package-manager-cli.code.js +7 -7
- package/dist/package-manager-cli.impl.js +3 -3
- package/dist/package-manager-cli.js +3 -3
- package/dist/rpc-entry.js +1 -1
- package/dist/startup-files.json +1 -1
- package/dist/startup-stages/0.js +1 -1
- package/dist/startup-stages/1.js +1 -1
- package/dist/startup-stages/10.js +1 -1
- package/dist/startup-stages/12.js +1 -1
- package/dist/startup-stages/2.js +9 -1
- package/dist/startup-stages/3.js +1 -6
- package/dist/startup-stages/5.js +1 -1
- package/dist/startup-stages/7.js +1 -1
- package/dist/startup-stages/8.js +2 -2
- package/dist/utils/startup-database-spare.code.js +3 -3
- package/dist/utils/startup-database-spare.impl.js +3 -3
- package/dist/utils/startup-database-spare.js +3 -3
- package/dist/utils/tools-manager.code.js +1 -1
- package/dist/utils/tools-manager.impl.js +3 -3
- package/dist/utils/tools-manager.js +3 -3
- package/docs/background-tasks.md +123 -23
- package/docs/compaction.md +18 -0
- package/docs/docs.json +2 -0
- package/docs/environment-variables.md +1 -1
- package/docs/getting-started/installation.md +9 -2
- package/docs/guides/postgres-pgbouncer.md +346 -0
- package/docs/guides/postgres-tuning.md +311 -0
- package/docs/guides/resume-on-any-machine.md +2 -2
- package/docs/guides.md +2 -0
- package/docs/index.md +1 -1
- package/docs/libraries/agent-core.md +1 -1
- package/docs/libraries/ai.md +2 -2
- package/docs/libraries/codemode.md +1 -1
- package/docs/libraries/storage-libsql.md +6 -1
- package/docs/libraries/storage-postgres.md +11 -6
- package/docs/libraries/tui.md +1 -1
- package/docs/libraries.md +2 -2
- package/docs/programmatic.md +1 -1
- package/docs/quickstart.md +1 -1
- package/docs/sdk/storage.md +1 -1
- package/docs/sdk/web-server.md +1 -3
- package/docs/sdk.md +1 -7
- package/docs/sessions.md +67 -2
- package/docs/settings.md +20 -1
- package/docs/skills/authoring.md +1 -1
- package/docs/skills.md +79 -6
- package/docs/storage.md +305 -14
- package/docs/subagents/reference.md +2 -2
- package/docs/subagents.md +4 -3
- package/docs/tools.md +44 -10
- package/docs/windows.md +1 -1
- package/package.json +9 -9
- package/dist/_shared/sdk-RRLVN7ER.js.map +0 -1
- package/dist/_shared/settings-startup-4QCVCI53.js.map +0 -1
- package/dist/_shared/startup-0-0-4VG2G44V.js.map +0 -1
- package/dist/_shared/startup-0-1-XTIL65D4.js.map +0 -1
- package/dist/_shared/startup-0-2-27OWFHV6.js.map +0 -1
- package/dist/_shared/startup-0-3-T4DVFYWX.js.map +0 -1
- package/dist/_shared/startup-0-5-FD2P735I.js.map +0 -1
- package/dist/_shared/startup-8-1-4KANEHRA.js.map +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { sqliteDialect } from "./dialect.js";
|
|
2
2
|
import { largestValueBytes, payloadTooLargeKind, StorageConfigError, StorageError, StorageInvalidTextError, StoragePayloadTooLargeError, StorageRollbackError, StorageTransactionClosedError, StorageTransientError, StorageUnavailableError, StoreClosedError, } from "./errors.js";
|
|
3
|
+
import { MAX_SEQUENCE_REQUEST_STATEMENTS, offerFinish, offerSequences, } from "./statement-sequence.js";
|
|
3
4
|
/**
|
|
4
5
|
* How many times the facade runs a call that a transient failure ended before it wrote anything, the first run
|
|
5
6
|
* included. A transaction runs again only when its options allow it (`retryTransientFailures`).
|
|
@@ -220,16 +221,20 @@ class CallQueue {
|
|
|
220
221
|
}
|
|
221
222
|
/** Starts each operation as it is pushed, so a pipelined connection receives them in push order without waiting. */
|
|
222
223
|
class PipelineQueue {
|
|
223
|
-
started =
|
|
224
|
+
started = [];
|
|
224
225
|
push(operation) {
|
|
225
226
|
const result = operation();
|
|
226
|
-
|
|
227
|
+
result.catch(() => { });
|
|
227
228
|
// A queue lasts one transaction, so it keeps every call it started.
|
|
228
|
-
this.started.
|
|
229
|
+
this.started.push(result);
|
|
229
230
|
return result;
|
|
230
231
|
}
|
|
231
232
|
drained() {
|
|
232
|
-
return Promise.
|
|
233
|
+
return Promise.allSettled(this.started).then(() => { });
|
|
234
|
+
}
|
|
235
|
+
/** The failure of the first call, in the order they were sent, that failed; undefined when none did. */
|
|
236
|
+
firstFailure() {
|
|
237
|
+
return firstFailure(this.started);
|
|
233
238
|
}
|
|
234
239
|
}
|
|
235
240
|
/**
|
|
@@ -326,6 +331,235 @@ class LaneQueue {
|
|
|
326
331
|
this.watchdog.unref();
|
|
327
332
|
}
|
|
328
333
|
}
|
|
334
|
+
const WHOLE_SCOPE = Object.freeze({ kind: "whole" });
|
|
335
|
+
const PLAIN_SCOPE = Object.freeze({ kind: "plain" });
|
|
336
|
+
const READ_SCOPE = Object.freeze({ kind: "read" });
|
|
337
|
+
/**
|
|
338
|
+
* Whether `later` must wait for `earlier`, a call queued before it. A read-only transaction waits for the writes queued
|
|
339
|
+
* before it, so it sees them, but a write queued after a read-only transaction does not wait for it.
|
|
340
|
+
*/
|
|
341
|
+
function scopesConflict(earlier, later) {
|
|
342
|
+
if (earlier.kind === "whole" || earlier.kind === "plain" || later.kind === "whole" || later.kind === "plain")
|
|
343
|
+
return true;
|
|
344
|
+
if (later.kind === "read")
|
|
345
|
+
return earlier.kind !== "read";
|
|
346
|
+
return earlier.kind === "domain" && earlier.domain === later.domain;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* `LaneQueue` for a driver that runs transactions or reads concurrently: a call starts once no unfinished call ahead of
|
|
350
|
+
* it conflicts with it (`scopesConflict`), so calls that conflict run one at a time in call order, and the others at
|
|
351
|
+
* once, reads no more than `maxReads` at a time. A priority call is ahead of every waiting call of the normal lane,
|
|
352
|
+
* as there. A waiting call fails with `stalled()` once a conflicting call ahead of it, or one such a call waits for,
|
|
353
|
+
* has run `STORAGE_PRIORITY_CALL_MAX_WAIT_MS` (a priority call) or `STORAGE_QUEUED_CALL_MAX_WAIT_MS` without
|
|
354
|
+
* settling; a read waiting for a free place waits for the reads running then.
|
|
355
|
+
*/
|
|
356
|
+
class ScopeQueue {
|
|
357
|
+
/** Unfinished calls: priority ones first, then the normal lane's, each in call order. */
|
|
358
|
+
calls = [];
|
|
359
|
+
/** How many calls of the read scope run at once at most. */
|
|
360
|
+
maxReads;
|
|
361
|
+
seq = 0;
|
|
362
|
+
clock = 0;
|
|
363
|
+
idle = [];
|
|
364
|
+
watchdog;
|
|
365
|
+
/** When the planned check runs, as `Date.now()`, or undefined when none is planned. */
|
|
366
|
+
watchdogAt;
|
|
367
|
+
stalled;
|
|
368
|
+
constructor(stalled, maxReads = Number.POSITIVE_INFINITY) {
|
|
369
|
+
this.stalled = stalled;
|
|
370
|
+
this.maxReads = maxReads;
|
|
371
|
+
}
|
|
372
|
+
push(operation, priority = false, scope = PLAIN_SCOPE) {
|
|
373
|
+
return new Promise((resolve, reject) => {
|
|
374
|
+
const call = {
|
|
375
|
+
scope,
|
|
376
|
+
priority,
|
|
377
|
+
seq: this.seq++,
|
|
378
|
+
admitted: this.clock++,
|
|
379
|
+
runningSince: 0,
|
|
380
|
+
run: () => Promise.resolve().then(operation).then(resolve, reject),
|
|
381
|
+
fail: reject,
|
|
382
|
+
};
|
|
383
|
+
const firstNormal = this.calls.findIndex((queued) => !queued.priority);
|
|
384
|
+
if (priority && firstNormal !== -1)
|
|
385
|
+
this.calls.splice(firstNormal, 0, call);
|
|
386
|
+
else
|
|
387
|
+
this.calls.push(call);
|
|
388
|
+
this.next();
|
|
389
|
+
this.watch();
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
drained() {
|
|
393
|
+
if (this.calls.length === 0)
|
|
394
|
+
return Promise.resolve();
|
|
395
|
+
return new Promise((resolve) => this.idle.push(resolve));
|
|
396
|
+
}
|
|
397
|
+
/** Whether `call`, still waiting, must wait for `other`. */
|
|
398
|
+
waitsFor(call, other) {
|
|
399
|
+
if (other === call)
|
|
400
|
+
return false;
|
|
401
|
+
// A read waits for a running read while as many as `maxReads` run.
|
|
402
|
+
if (call.scope.kind === "read" && other.scope.kind === "read" && other.started !== undefined)
|
|
403
|
+
return call.started === undefined && this.runningReads() >= this.maxReads;
|
|
404
|
+
if (!scopesConflict(other.scope, call.scope))
|
|
405
|
+
return false;
|
|
406
|
+
if (other.priority === call.priority)
|
|
407
|
+
return other.seq < call.seq;
|
|
408
|
+
// A priority call goes ahead of the normal lane's waiting calls, not of those already running when it came.
|
|
409
|
+
return other.priority || (other.started !== undefined && other.started < call.admitted);
|
|
410
|
+
}
|
|
411
|
+
runningReads() {
|
|
412
|
+
let running = 0;
|
|
413
|
+
for (const call of this.calls)
|
|
414
|
+
if (call.scope.kind === "read" && call.started !== undefined)
|
|
415
|
+
running++;
|
|
416
|
+
return running;
|
|
417
|
+
}
|
|
418
|
+
next() {
|
|
419
|
+
for (const call of this.calls) {
|
|
420
|
+
if (call.started !== undefined || this.calls.some((other) => this.waitsFor(call, other)))
|
|
421
|
+
continue;
|
|
422
|
+
call.started = this.clock++;
|
|
423
|
+
call.runningSince = Date.now();
|
|
424
|
+
// Started on a later microtask, as a promise chain starts it, never inside the call that queued it.
|
|
425
|
+
void call.run().finally(() => {
|
|
426
|
+
this.calls.splice(this.calls.indexOf(call), 1);
|
|
427
|
+
this.next();
|
|
428
|
+
this.watch();
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
if (this.calls.length > 0)
|
|
432
|
+
return;
|
|
433
|
+
const idle = this.idle;
|
|
434
|
+
this.idle = [];
|
|
435
|
+
for (const resolve of idle)
|
|
436
|
+
resolve();
|
|
437
|
+
}
|
|
438
|
+
/** Each waiting call with when the earliest running call it waits for, directly or through others, started. */
|
|
439
|
+
stuck() {
|
|
440
|
+
const since = new Map();
|
|
441
|
+
for (const call of this.calls) {
|
|
442
|
+
if (call.started !== undefined)
|
|
443
|
+
continue;
|
|
444
|
+
let earliest = Number.POSITIVE_INFINITY;
|
|
445
|
+
for (const other of this.calls) {
|
|
446
|
+
if (!this.waitsFor(call, other))
|
|
447
|
+
continue;
|
|
448
|
+
earliest = Math.min(earliest, other.started === undefined ? (since.get(other) ?? earliest) : other.runningSince);
|
|
449
|
+
}
|
|
450
|
+
since.set(call, earliest);
|
|
451
|
+
}
|
|
452
|
+
return since;
|
|
453
|
+
}
|
|
454
|
+
static bound(call) {
|
|
455
|
+
return call.priority ? STORAGE_PRIORITY_CALL_MAX_WAIT_MS : STORAGE_QUEUED_CALL_MAX_WAIT_MS;
|
|
456
|
+
}
|
|
457
|
+
/** Plans the check that fails the waiting calls whose wait passed its bound. No timer runs while nothing waits. */
|
|
458
|
+
watch() {
|
|
459
|
+
let at;
|
|
460
|
+
for (const [call, since] of this.stuck())
|
|
461
|
+
if (Number.isFinite(since))
|
|
462
|
+
at = Math.min(at ?? Number.POSITIVE_INFINITY, since + ScopeQueue.bound(call));
|
|
463
|
+
if (at === this.watchdogAt)
|
|
464
|
+
return;
|
|
465
|
+
clearTimeout(this.watchdog);
|
|
466
|
+
this.watchdog = undefined;
|
|
467
|
+
this.watchdogAt = at;
|
|
468
|
+
if (at === undefined)
|
|
469
|
+
return;
|
|
470
|
+
this.watchdog = setTimeout(() => {
|
|
471
|
+
this.watchdog = undefined;
|
|
472
|
+
this.watchdogAt = undefined;
|
|
473
|
+
const now = Date.now();
|
|
474
|
+
const failing = [];
|
|
475
|
+
for (const [call, since] of this.stuck())
|
|
476
|
+
if (now - since >= ScopeQueue.bound(call))
|
|
477
|
+
failing.push([call, now - since]);
|
|
478
|
+
for (const [call] of failing)
|
|
479
|
+
this.calls.splice(this.calls.indexOf(call), 1);
|
|
480
|
+
for (const [call, ran] of failing)
|
|
481
|
+
call.fail(this.stalled(ran));
|
|
482
|
+
this.next();
|
|
483
|
+
this.watch();
|
|
484
|
+
}, Math.max(0, at - Date.now()));
|
|
485
|
+
// A stuck call ahead of the queue never keeps the process alive on its own.
|
|
486
|
+
this.watchdog.unref();
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
/** How many reads `driver` runs at once, when it runs any beside each other (`SqliteDriver.concurrentReads`). */
|
|
490
|
+
function concurrentReads(driver) {
|
|
491
|
+
const reads = driver.concurrentReads;
|
|
492
|
+
return typeof reads === "number" && Number.isInteger(reads) && reads > 0 ? reads : undefined;
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* The scope a transaction runs in on a driver that runs transactions or reads concurrently: a write transaction keeps
|
|
496
|
+
* its domain only on a driver that runs writes concurrently (`concurrentTransactions`), and runs alone otherwise.
|
|
497
|
+
*/
|
|
498
|
+
function transactionScope(concurrency, readOnly, concurrentWrites) {
|
|
499
|
+
if (readOnly)
|
|
500
|
+
return READ_SCOPE;
|
|
501
|
+
if (concurrentWrites && concurrency.kind === "serial" && concurrency.domain !== undefined)
|
|
502
|
+
return { kind: "domain", domain: concurrency.domain };
|
|
503
|
+
return WHOLE_SCOPE;
|
|
504
|
+
}
|
|
505
|
+
function hasInvalidText(statement) {
|
|
506
|
+
return statement.params.some((value) => typeof value === "string" && value.includes("\0"));
|
|
507
|
+
}
|
|
508
|
+
/** The failure of the first of `calls` that failed, in their order, once all settled; undefined when none did. */
|
|
509
|
+
async function firstFailure(calls) {
|
|
510
|
+
for (const outcome of await Promise.allSettled(calls))
|
|
511
|
+
if (outcome.status === "rejected")
|
|
512
|
+
return outcome.reason;
|
|
513
|
+
return undefined;
|
|
514
|
+
}
|
|
515
|
+
/** `leading` with parameters snapshotted, up to the first statement that holds NUL, which the facade refuses to send. */
|
|
516
|
+
function leadingStatements(leading) {
|
|
517
|
+
const sent = [];
|
|
518
|
+
for (const statement of leading ?? []) {
|
|
519
|
+
if (hasInvalidText(statement))
|
|
520
|
+
break;
|
|
521
|
+
sent.push({ sql: statement.sql, params: snapshotParams(statement.params) });
|
|
522
|
+
}
|
|
523
|
+
return sent;
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Runs `sequence` on a transaction of a pipelined connection: `repeat` one run at a time, since each run's changes
|
|
527
|
+
* decide the next, then the statements a request's worth at a time, each request sent whole before any answer comes.
|
|
528
|
+
* A statement sent behind one that failed fails too, or runs in a transaction that can no longer commit, so the
|
|
529
|
+
* first failure in order is the sequence's, as when each waited for the one before. Nothing is sent after a statement
|
|
530
|
+
* whose text holds NUL, which fails as `run` fails it.
|
|
531
|
+
*/
|
|
532
|
+
async function pipelineSequence(handle, { repeat, statements, signal }) {
|
|
533
|
+
let repeated = 0;
|
|
534
|
+
if (repeat !== undefined) {
|
|
535
|
+
for (let done = 0; done < repeat.times; done++) {
|
|
536
|
+
signal?.throwIfAborted();
|
|
537
|
+
const { changes } = await handle.run(repeat.statement.sql, ...repeat.statement.params);
|
|
538
|
+
if (changes < repeat.minChanges)
|
|
539
|
+
break;
|
|
540
|
+
repeated++;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
const pending = statements[Symbol.iterator]();
|
|
544
|
+
for (let next = pending.next(); next.done !== true;) {
|
|
545
|
+
const sent = [];
|
|
546
|
+
for (; next.done !== true && sent.length < MAX_SEQUENCE_REQUEST_STATEMENTS; next = pending.next()) {
|
|
547
|
+
if (signal?.aborted === true)
|
|
548
|
+
break;
|
|
549
|
+
const statement = next.value;
|
|
550
|
+
sent.push(statement.script === true ? handle.exec(statement.sql) : handle.run(statement.sql, ...statement.params));
|
|
551
|
+
// `run` refuses it without sending it, so the sequence fails with that below.
|
|
552
|
+
if (hasInvalidText(statement))
|
|
553
|
+
break;
|
|
554
|
+
}
|
|
555
|
+
const outcomes = await Promise.allSettled(sent);
|
|
556
|
+
const failed = outcomes.find((outcome) => outcome.status === "rejected");
|
|
557
|
+
if (failed !== undefined)
|
|
558
|
+
throw failed.reason;
|
|
559
|
+
signal?.throwIfAborted();
|
|
560
|
+
}
|
|
561
|
+
return repeated;
|
|
562
|
+
}
|
|
329
563
|
class DriverDatabase {
|
|
330
564
|
descriptor;
|
|
331
565
|
dialect;
|
|
@@ -333,7 +567,7 @@ class DriverDatabase {
|
|
|
333
567
|
/** Fenced transactions a concurrent driver runs outside the queue; closing waits for them. */
|
|
334
568
|
concurrent = new Set();
|
|
335
569
|
redact;
|
|
336
|
-
queue
|
|
570
|
+
queue;
|
|
337
571
|
closePromise;
|
|
338
572
|
/** End the waits before calls run again, when closing begins during them. */
|
|
339
573
|
wakeRetries = new Set();
|
|
@@ -342,24 +576,73 @@ class DriverDatabase {
|
|
|
342
576
|
batch;
|
|
343
577
|
notifications;
|
|
344
578
|
freeBytes;
|
|
345
|
-
|
|
579
|
+
databaseIdentity;
|
|
580
|
+
openReader;
|
|
581
|
+
takeOpenedCatalog;
|
|
582
|
+
autocommit;
|
|
583
|
+
/** Readers this database opened and that are not closed; closing closes them. */
|
|
584
|
+
readers = new Set();
|
|
585
|
+
closed;
|
|
586
|
+
constructor(driver, redact, closed) {
|
|
346
587
|
this.driver = driver;
|
|
588
|
+
this.closed = closed;
|
|
589
|
+
const openReader = driver.openReader?.bind(driver);
|
|
590
|
+
if (openReader)
|
|
591
|
+
this.openReader = () => this.startReader(openReader);
|
|
347
592
|
if (driver.notifications !== undefined)
|
|
348
593
|
this.notifications = driver.notifications;
|
|
349
594
|
const freeBytes = driver.freeBytes?.bind(driver);
|
|
350
595
|
if (freeBytes)
|
|
351
596
|
this.freeBytes = async () => freeBytes();
|
|
597
|
+
const databaseIdentity = driver.databaseIdentity?.bind(driver);
|
|
598
|
+
if (databaseIdentity)
|
|
599
|
+
this.databaseIdentity = databaseIdentity;
|
|
600
|
+
const takeOpenedCatalog = driver.takeOpenedCatalog?.bind(driver);
|
|
601
|
+
if (takeOpenedCatalog)
|
|
602
|
+
this.takeOpenedCatalog = takeOpenedCatalog;
|
|
352
603
|
this.redact = redact;
|
|
353
604
|
this.descriptor = { adapter: driver.descriptor.adapter, location: redact(driver.descriptor.location) };
|
|
605
|
+
const stalled = (ranMs) => new StorageUnavailableError(this.descriptor, undefined, `the call was queued behind an earlier call that ran ${Math.round(ranMs / 1000)} seconds without settling, and did not run; nothing was written, retry it`);
|
|
606
|
+
const maxReads = concurrentReads(driver);
|
|
607
|
+
this.queue =
|
|
608
|
+
driver.concurrentTransactions === true || maxReads !== undefined
|
|
609
|
+
? new ScopeQueue(stalled, maxReads)
|
|
610
|
+
: new LaneQueue(stalled);
|
|
354
611
|
this.dialect = driver.dialect ?? sqliteDialect;
|
|
355
|
-
|
|
612
|
+
const readsOnly = driver.readsOnly?.bind(driver);
|
|
613
|
+
const scopeOf = readsOnly !== undefined && (driver.concurrentTransactions === true || maxReads !== undefined)
|
|
614
|
+
? (sql) => (readsOnly(sql) ? READ_SCOPE : PLAIN_SCOPE)
|
|
615
|
+
: () => PLAIN_SCOPE;
|
|
616
|
+
this.executor = this.createExecutor(driver, (operation, sql) => {
|
|
356
617
|
if (this.closePromise)
|
|
357
618
|
return Promise.reject(new StoreClosedError(this.descriptor));
|
|
358
|
-
return this.queue.push(() => this.retrying(operation, true));
|
|
619
|
+
return this.queue.push(() => this.retrying(operation, true), false, sql === undefined ? PLAIN_SCOPE : scopeOf(sql));
|
|
359
620
|
}, true);
|
|
360
621
|
const batch = driver.batch?.bind(driver);
|
|
361
622
|
if (batch)
|
|
362
623
|
this.batch = (statements, options) => this.runBatch(batch, statements, options);
|
|
624
|
+
if (driver.concurrentTransactions === true)
|
|
625
|
+
this.autocommit = (statement, concurrency) => this.runAutocommit(statement, concurrency);
|
|
626
|
+
}
|
|
627
|
+
/** `autocommit`: the statement on its own, through the driver's `execute`, in the queue scope of `concurrency`. */
|
|
628
|
+
runAutocommit(statement, concurrency) {
|
|
629
|
+
if (this.closePromise)
|
|
630
|
+
return Promise.reject(new StoreClosedError(this.descriptor));
|
|
631
|
+
let scope;
|
|
632
|
+
try {
|
|
633
|
+
scope = transactionScope(transactionConcurrency({ concurrency }), false, true);
|
|
634
|
+
}
|
|
635
|
+
catch (error) {
|
|
636
|
+
return Promise.reject(error);
|
|
637
|
+
}
|
|
638
|
+
const bound = snapshotParams(statement.params);
|
|
639
|
+
return this.queue.push(() => this.retrying(async (attempt) => {
|
|
640
|
+
const invalidIndex = bound.findIndex((value) => typeof value === "string" && value.includes("\0"));
|
|
641
|
+
if (invalidIndex !== -1)
|
|
642
|
+
throw new StorageInvalidTextError(invalidIndex);
|
|
643
|
+
const result = await this.call(() => this.driver.execute(statement.sql, bound), attempt, true, bound);
|
|
644
|
+
return result.rows.map((row) => normalizeRow(row, result.columns));
|
|
645
|
+
}, true), false, scope);
|
|
363
646
|
}
|
|
364
647
|
runBatch(batch, statements, options) {
|
|
365
648
|
if (this.closePromise)
|
|
@@ -469,7 +752,7 @@ class DriverDatabase {
|
|
|
469
752
|
if (transient !== undefined) {
|
|
470
753
|
const failure = new StorageTransientError(this.descriptor, {
|
|
471
754
|
code: transient.code,
|
|
472
|
-
outcome: applies ? transient.outcome : "not-applied",
|
|
755
|
+
outcome: applies || attempt.committing === true ? transient.outcome : "not-applied",
|
|
473
756
|
attempts: attempt.number,
|
|
474
757
|
...(transient.hop === undefined
|
|
475
758
|
? {}
|
|
@@ -495,7 +778,7 @@ class DriverDatabase {
|
|
|
495
778
|
if (invalidIndex !== -1)
|
|
496
779
|
throw new StorageInvalidTextError(invalidIndex);
|
|
497
780
|
return this.call(() => connection.execute(sql, bound), attempt, applies, bound);
|
|
498
|
-
});
|
|
781
|
+
}, sql);
|
|
499
782
|
};
|
|
500
783
|
return {
|
|
501
784
|
exec: (sql) => admit((attempt) => this.call(() => connection.executeMultiple(sql), attempt, applies)),
|
|
@@ -535,14 +818,23 @@ class DriverDatabase {
|
|
|
535
818
|
catch (error) {
|
|
536
819
|
return Promise.reject(error);
|
|
537
820
|
}
|
|
821
|
+
const leading = this.driver.pipelinedTransactions === true ? leadingStatements(options?.leading) : [];
|
|
538
822
|
const begin = {
|
|
539
823
|
concurrency,
|
|
540
824
|
...(options?.lockWaitMs === undefined ? {} : { lockWaitMs: options.lockWaitMs }),
|
|
541
825
|
...(options?.readOnly === true ? { readOnly: true } : {}),
|
|
826
|
+
...(leading.length === 0 ? {} : { leading }),
|
|
827
|
+
// Only when the callback makes nothing but calls that went with the start: a statement the facade held back is one.
|
|
828
|
+
...(options?.leadingOnly === true && leading.length > 0 && leading.length === options.leading?.length
|
|
829
|
+
? { leadingOnly: true }
|
|
830
|
+
: {}),
|
|
831
|
+
// `leading` holds the first statement whenever it holds any.
|
|
832
|
+
...(options?.lockIfLeadingFinds === true && leading.length > 0 ? { lockIfLeadingFinds: true } : {}),
|
|
542
833
|
};
|
|
543
834
|
const run = () => this.retrying((attempt) => this.runTransaction(callback, attempt, begin), replay);
|
|
544
|
-
|
|
545
|
-
|
|
835
|
+
const concurrentWrites = this.driver.concurrentTransactions === true;
|
|
836
|
+
if (concurrency.kind === "serial" || !concurrentWrites)
|
|
837
|
+
return this.queue.push(run, false, transactionScope(concurrency, options?.readOnly === true, concurrentWrites));
|
|
546
838
|
const result = run();
|
|
547
839
|
const settled = result.then(() => { }, () => { });
|
|
548
840
|
this.concurrent.add(settled);
|
|
@@ -555,22 +847,48 @@ class DriverDatabase {
|
|
|
555
847
|
const handleQueue = pipelined ? new PipelineQueue() : new CallQueue();
|
|
556
848
|
let active = true;
|
|
557
849
|
let result;
|
|
558
|
-
|
|
850
|
+
/** Set once `finish` sent the callback's last calls: the transaction takes no more. */
|
|
851
|
+
let finished = false;
|
|
852
|
+
const handle = this.createExecutor(connection, (operation) => active && !finished
|
|
853
|
+
? handleQueue.push(() => operation(attempt))
|
|
854
|
+
: Promise.reject(new StorageTransactionClosedError()), false);
|
|
855
|
+
if (pipelined) {
|
|
856
|
+
offerSequences(handle, (sequence) => pipelineSequence(handle, sequence));
|
|
857
|
+
offerFinish(handle, (statements) => {
|
|
858
|
+
if (!active || finished)
|
|
859
|
+
return false;
|
|
860
|
+
if (statements.length > MAX_SEQUENCE_REQUEST_STATEMENTS || statements.some(hasInvalidText))
|
|
861
|
+
return false;
|
|
862
|
+
// Their failures are the transaction's, reported once the commit is answered.
|
|
863
|
+
for (const statement of statements) {
|
|
864
|
+
const sent = statement.script === true
|
|
865
|
+
? handle.exec(statement.sql)
|
|
866
|
+
: handle.run(statement.sql, ...statement.params);
|
|
867
|
+
sent.catch(() => { });
|
|
868
|
+
}
|
|
869
|
+
finished = true;
|
|
870
|
+
return true;
|
|
871
|
+
});
|
|
872
|
+
}
|
|
559
873
|
const close = () => this.call(() => connection.close?.());
|
|
560
874
|
// Once the callback has returned, the commit's own failure decides whether the transaction runs again: a commit
|
|
561
875
|
// that may have applied, or that failed for a reason the driver does not recognize, never does, whatever the
|
|
562
876
|
// callback met before it. A committed transaction never runs again either.
|
|
563
877
|
const commit = () => {
|
|
564
878
|
attempt.transient = undefined;
|
|
879
|
+
attempt.committing = true;
|
|
565
880
|
return this.call(() => connection.commit(), attempt, true);
|
|
566
881
|
};
|
|
882
|
+
let returned = false;
|
|
567
883
|
try {
|
|
568
884
|
let committing;
|
|
569
885
|
try {
|
|
570
886
|
result = await callback(handle);
|
|
571
|
-
|
|
572
|
-
//
|
|
573
|
-
//
|
|
887
|
+
returned = true;
|
|
888
|
+
// A pipelined connection takes the commit behind statements the callback left unanswered, such as those sent by
|
|
889
|
+
// `finish`, so locks they take are held for one round trip. The driver's commit fails when one of them failed,
|
|
890
|
+
// so nothing commits then, and the first of them to fail is the failure. One that the server refused lets the
|
|
891
|
+
// transaction run again, having written nothing; one whose connection broke may have committed, so it does not.
|
|
574
892
|
if (pipelined) {
|
|
575
893
|
committing = commit();
|
|
576
894
|
committing.catch(() => { });
|
|
@@ -580,10 +898,25 @@ class DriverDatabase {
|
|
|
580
898
|
active = false;
|
|
581
899
|
await handleQueue.drained();
|
|
582
900
|
}
|
|
901
|
+
// A read-only transaction on a connection of its own has its answer once its reads are answered: its commit only
|
|
902
|
+
// ends the snapshot, so the connection goes back once the commit is answered, while the caller goes on.
|
|
903
|
+
if (begin.readOnly === true &&
|
|
904
|
+
(this.driver.concurrentTransactions === true || concurrentReads(this.driver) !== undefined)) {
|
|
905
|
+
this.endInBackground(committing ?? commit(), connection, close);
|
|
906
|
+
return result;
|
|
907
|
+
}
|
|
583
908
|
await (committing ?? commit());
|
|
584
909
|
}
|
|
585
910
|
catch (cause) {
|
|
586
911
|
let failure = cause;
|
|
912
|
+
// A commit that came back as a rollback names no reason: the statement that failed is the transaction's failure,
|
|
913
|
+
// and whether it may run again is that failure's, as when the callback awaited it.
|
|
914
|
+
const unanswered = returned && handleQueue instanceof PipelineQueue ? await handleQueue.firstFailure() : undefined;
|
|
915
|
+
if (unanswered !== undefined) {
|
|
916
|
+
failure = unanswered;
|
|
917
|
+
if (unanswered instanceof StorageTransientError)
|
|
918
|
+
attempt.transient = unanswered;
|
|
919
|
+
}
|
|
587
920
|
try {
|
|
588
921
|
await this.call(() => connection.rollback());
|
|
589
922
|
}
|
|
@@ -597,8 +930,40 @@ class DriverDatabase {
|
|
|
597
930
|
await close();
|
|
598
931
|
return result;
|
|
599
932
|
}
|
|
933
|
+
/**
|
|
934
|
+
* Ends a read-only transaction whose reads were all answered once `committing` settles: rolls it back when the commit
|
|
935
|
+
* failed, then closes it. Closing the database waits for it.
|
|
936
|
+
*/
|
|
937
|
+
endInBackground(committing, connection, close) {
|
|
938
|
+
const ended = committing
|
|
939
|
+
.catch(() => this.call(() => connection.rollback()).catch(() => { }))
|
|
940
|
+
.then(close)
|
|
941
|
+
.catch(() => { });
|
|
942
|
+
this.concurrent.add(ended);
|
|
943
|
+
void ended.then(() => this.concurrent.delete(ended));
|
|
944
|
+
}
|
|
945
|
+
startReader(openReader) {
|
|
946
|
+
if (this.closePromise)
|
|
947
|
+
return Promise.reject(new StoreClosedError(this.descriptor));
|
|
948
|
+
const opening = this.call(openReader).then((driver) => {
|
|
949
|
+
const reader = new DriverDatabase(driver, this.redact, () => this.readers.delete(reader));
|
|
950
|
+
this.readers.add(reader);
|
|
951
|
+
if (this.closePromise)
|
|
952
|
+
throw new StoreClosedError(this.descriptor);
|
|
953
|
+
return reader;
|
|
954
|
+
});
|
|
955
|
+
const settled = opening.then(() => { }, () => { });
|
|
956
|
+
this.concurrent.add(settled);
|
|
957
|
+
void settled.then(() => this.concurrent.delete(settled));
|
|
958
|
+
return opening;
|
|
959
|
+
}
|
|
600
960
|
close() {
|
|
601
|
-
|
|
961
|
+
const closeReaders = () => Promise.allSettled([...this.readers].map((reader) => reader.close()));
|
|
962
|
+
// Readers stop taking calls now; one that finished opening meanwhile is closed after the drain.
|
|
963
|
+
this.closePromise ??= Promise.all([this.queue.drained(), ...this.concurrent, closeReaders()])
|
|
964
|
+
.then(closeReaders)
|
|
965
|
+
.then(() => this.call(() => this.driver.close()))
|
|
966
|
+
.finally(() => this.closed?.());
|
|
602
967
|
for (const wake of this.wakeRetries)
|
|
603
968
|
wake();
|
|
604
969
|
return this.closePromise;
|
|
@@ -606,7 +971,8 @@ class DriverDatabase {
|
|
|
606
971
|
}
|
|
607
972
|
/**
|
|
608
973
|
* Wraps a SQLite-compatible driver as a `SqliteDatabase`. The facade queues operations in call order and keeps them
|
|
609
|
-
* outside active transactions
|
|
974
|
+
* outside active transactions (on a driver that runs transactions concurrently, only operations that conflict wait for
|
|
975
|
+
* each other), snapshots binary parameters at call time, rejects NUL text, returns safe-range integers
|
|
610
976
|
* as numbers and blobs as `Uint8Array` copies, expires transaction handles when their callback settles, maps driver
|
|
611
977
|
* failures to `StorageUnavailableError` with credentials redacted, and reports failed rollbacks with
|
|
612
978
|
* `StorageRollbackError`. A failure the driver recognizes as transient is a `StorageTransientError`; a statement, a
|