@bastani/atomic 0.10.11-alpha.2 → 0.10.11-alpha.4
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 +150 -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 +42 -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 +6 -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 +1470 -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,5 +1,5 @@
|
|
|
1
1
|
import { close, existsSync, open, readdirSync, realpathSync, statSync, unlinkSync, watch, write, } from "node:fs";
|
|
2
|
-
import { lstat, mkdir, readdir, readFile, realpath, rm, stat, statfs, unlink, utimes, writeFile, } from "node:fs/promises";
|
|
2
|
+
import { lstat, mkdir, open as openFileHandle, readdir, readFile, realpath, rm, stat, statfs, unlink, utimes, writeFile, } from "node:fs/promises";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { platform } from "node:os";
|
|
5
5
|
import { basename, dirname, join, resolve, win32 } from "node:path";
|
|
@@ -12,7 +12,7 @@ import { payloadTooLargeKind, SQLITE_PAYLOAD_LIMITS, StorageAdapterLoadError, St
|
|
|
12
12
|
import { fileIdentity, fileIdentityAsync } from "./file-identity.js";
|
|
13
13
|
import { connectionWaits, currentHoldScope, forgetPlans, heldElsewhere, holdFile, inBacklog, modeOf, releaseHold, runDeferred, runInHold, runTryingFirst, runWhenFree, sqliteBusyError, useFileLock, useWrappedFile, } from "./node-sqlite-file-gate.js";
|
|
14
14
|
import { STATEMENT_CACHE_SIZE, ThreadConnection, } from "./node-sqlite-thread.js";
|
|
15
|
-
import { MAX_SEQUENCE_REQUEST_STATEMENTS, offerSequences, } from "./statement-sequence.js";
|
|
15
|
+
import { MAX_SEQUENCE_REQUEST_STATEMENTS, offerFinish, offerSequences, } from "./statement-sequence.js";
|
|
16
16
|
import { configureConnection, isSqliteBusy, switchToWriteAheadLogSync } from "./write-ahead-log.js";
|
|
17
17
|
/** Loaded at the first degradation only, so opening a database does not load debug output. */
|
|
18
18
|
const loadDebugOutput = memoizeAsync(() => import("../debug.code.js").catch((error) => __atomicOnDemandFailed(error, "this feature")));
|
|
@@ -535,6 +535,31 @@ class SqliteHolderRecord {
|
|
|
535
535
|
this.unavailable(cause);
|
|
536
536
|
}
|
|
537
537
|
}
|
|
538
|
+
/** Open descriptor for writing on the connection thread; undefined once closed or degraded. */
|
|
539
|
+
fd() {
|
|
540
|
+
return this.descriptor;
|
|
541
|
+
}
|
|
542
|
+
/** Records a write failure observed on the connection thread, retiring the descriptor immediately. */
|
|
543
|
+
failed(cause) {
|
|
544
|
+
const descriptor = this.descriptor;
|
|
545
|
+
this.descriptor = undefined;
|
|
546
|
+
this.unavailable(cause);
|
|
547
|
+
if (descriptor === undefined)
|
|
548
|
+
return;
|
|
549
|
+
this.writes = this.writes.then(async () => {
|
|
550
|
+
try {
|
|
551
|
+
await closeFile(descriptor);
|
|
552
|
+
await unlink(this.path);
|
|
553
|
+
}
|
|
554
|
+
catch {
|
|
555
|
+
// Already gone; a leftover record of an exited process is ignored and removed by whoever reads it.
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
/** Waits for any queued write or failure cleanup on this record to finish. */
|
|
560
|
+
drain() {
|
|
561
|
+
return this.writes;
|
|
562
|
+
}
|
|
538
563
|
/** Records that this connection is about to try for the lock; written before its first attempt. */
|
|
539
564
|
trying() {
|
|
540
565
|
return this.write(`want ${String(Date.now()).padStart(15, "0")}\n`);
|
|
@@ -674,6 +699,52 @@ function isMissingOpenLockDir(error) {
|
|
|
674
699
|
function pathExists(path) {
|
|
675
700
|
return stat(path).then(() => true, () => false);
|
|
676
701
|
}
|
|
702
|
+
/** The 16 bytes a SQLite database file starts with. */
|
|
703
|
+
const SQLITE_FILE_HEADER = "SQLite format 3\0";
|
|
704
|
+
/**
|
|
705
|
+
* Creates the missing `-wal` of a WAL-mode database file before a read-only connection opens it, as SQLite creates it
|
|
706
|
+
* for a writer. The last connection to close cleanly removes the `-wal` and `-shm`. Stock SQLite, which Node bundles,
|
|
707
|
+
* creates both again for the next read-only connection; Apple's, which Bun uses on macOS, creates the `-shm` but not
|
|
708
|
+
* the `-wal`, and fails the open with SQLITE_CANTOPEN (code 14), so `atomic storage status` reported a store that
|
|
709
|
+
* `atomic storage import` had just written as unavailable. An empty `-wal` is a WAL without frames. Nothing is created
|
|
710
|
+
* for a database in another journal mode, which would read a `-wal` as its WAL, nor when the file cannot be read: the
|
|
711
|
+
* open then reports what it finds. The `-wal` takes the database file's permissions, as SQLite gives it.
|
|
712
|
+
*/
|
|
713
|
+
async function prepareReadOnlyWal(filePath) {
|
|
714
|
+
try {
|
|
715
|
+
// SQLite keeps the WAL beside the file a symbolic link names.
|
|
716
|
+
const target = await realpath(filePath);
|
|
717
|
+
const wal = `${target}-wal`;
|
|
718
|
+
if (await pathExists(wal))
|
|
719
|
+
return;
|
|
720
|
+
const database = await openFileHandle(target, "r");
|
|
721
|
+
const header = Buffer.alloc(20);
|
|
722
|
+
let mode;
|
|
723
|
+
try {
|
|
724
|
+
await database.read(header, 0, header.length, 0);
|
|
725
|
+
mode = (await database.stat()).mode & 0o777;
|
|
726
|
+
}
|
|
727
|
+
finally {
|
|
728
|
+
await database.close();
|
|
729
|
+
}
|
|
730
|
+
// Read and write format versions 2 mark a WAL-mode database.
|
|
731
|
+
if (header.toString("latin1", 0, 16) !== SQLITE_FILE_HEADER || header[18] !== 2 || header[19] !== 2)
|
|
732
|
+
return;
|
|
733
|
+
// Appending creates the file without emptying one a writer made meanwhile.
|
|
734
|
+
const created = await openFileHandle(wal, "a", mode);
|
|
735
|
+
try {
|
|
736
|
+
const stats = await created.stat();
|
|
737
|
+
if (stats.size === 0 && (stats.mode & 0o777) !== mode)
|
|
738
|
+
await created.chmod(mode);
|
|
739
|
+
}
|
|
740
|
+
finally {
|
|
741
|
+
await created.close();
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
catch {
|
|
745
|
+
// The open reports the file's state itself.
|
|
746
|
+
}
|
|
747
|
+
}
|
|
677
748
|
async function resolveOpenLockTarget(filePath, readOnly) {
|
|
678
749
|
try {
|
|
679
750
|
return await realpath(filePath);
|
|
@@ -982,6 +1053,25 @@ const MAX_GROUP_COMMIT_TRANSACTIONS = 128;
|
|
|
982
1053
|
export const DEFAULT_GROUP_COMMIT_HOLD_MS = 100;
|
|
983
1054
|
/** The span `getWriterQueueStats` reports on. */
|
|
984
1055
|
const WRITER_QUEUE_STATS_WINDOW_MS = 10_000;
|
|
1056
|
+
/** The `WriteLead` of `options`, or undefined where it names no statement this adapter can send ahead. */
|
|
1057
|
+
function writeLead(options) {
|
|
1058
|
+
const statements = [];
|
|
1059
|
+
for (const { sql, params } of options?.leading ?? []) {
|
|
1060
|
+
if (invalidTextParam(params) !== -1)
|
|
1061
|
+
break;
|
|
1062
|
+
statements.push({ sql, params: snapshotParams(params) });
|
|
1063
|
+
}
|
|
1064
|
+
if (statements.length === 0)
|
|
1065
|
+
return undefined;
|
|
1066
|
+
return { statements, only: options?.leadingOnly === true && statements.length === options.leading?.length };
|
|
1067
|
+
}
|
|
1068
|
+
/**
|
|
1069
|
+
* The COMMIT a transaction's `begin` or last request sends behind its statements: a prepared statement, as every
|
|
1070
|
+
* connection thread since sequences runs one, including one an older build started before an in-place update.
|
|
1071
|
+
*/
|
|
1072
|
+
const COMMIT = { sql: "COMMIT", params: [] };
|
|
1073
|
+
/** Sentinel returned by `attemptBegin` when a `checkQueue` probe saw entries in the writers'-queue directory. */
|
|
1074
|
+
const BEGIN_CONTENDED = Symbol("begin-contended");
|
|
985
1075
|
/** Samples in time order; those older than the window are dropped as new ones arrive. */
|
|
986
1076
|
class WindowSamples {
|
|
987
1077
|
items = [];
|
|
@@ -1295,6 +1385,8 @@ class NodeSqliteDatabase {
|
|
|
1295
1385
|
fileLock;
|
|
1296
1386
|
/** That this wrapped connection to its file is open, which scopes the holds of threaded ones (see `FileHold`). */
|
|
1297
1387
|
wrappedUse;
|
|
1388
|
+
/** What the `begin` request that took the lock answered for its leading statements, until `takeLed`. */
|
|
1389
|
+
led;
|
|
1298
1390
|
/** The ticket of the writer holding the lock, on its way out of the queue while the transaction runs. */
|
|
1299
1391
|
leaving;
|
|
1300
1392
|
/** What the writers' queue gave up on, once per reason, in the order it first happened. */
|
|
@@ -1386,9 +1478,35 @@ class NodeSqliteDatabase {
|
|
|
1386
1478
|
* Callers reach this only through `enqueue` and the transaction gate, so nothing else runs on the connection in
|
|
1387
1479
|
* between.
|
|
1388
1480
|
*/
|
|
1389
|
-
|
|
1481
|
+
/** Applies any holder-record write failure the connection thread reported, retiring and unlinking its file. */
|
|
1482
|
+
async flushThreadHolderError() {
|
|
1483
|
+
if (!(this.connection instanceof ThreadConnection))
|
|
1484
|
+
return;
|
|
1485
|
+
const error = this.connection.takeHolderError();
|
|
1486
|
+
if (error === undefined || this.holderRecord === undefined)
|
|
1487
|
+
return;
|
|
1488
|
+
this.holderRecord.failed(error);
|
|
1489
|
+
await this.holderRecord.drain();
|
|
1490
|
+
}
|
|
1491
|
+
/** Whether the connection's worker thread handles holder-record writes and writers'-queue directory checks. */
|
|
1492
|
+
threadManagesLock() {
|
|
1493
|
+
return this.connection instanceof ThreadConnection && this.connection.inTransaction !== undefined;
|
|
1494
|
+
}
|
|
1495
|
+
tryBegin(statements, checkQueue = false) {
|
|
1390
1496
|
const lock = this.fileLock;
|
|
1391
|
-
|
|
1497
|
+
const threadLock = this.threadManagesLock();
|
|
1498
|
+
return this.call({
|
|
1499
|
+
kind: "begin",
|
|
1500
|
+
...(lock === undefined ? {} : { lockState: lock.buffer, lockTag: lock.tag }),
|
|
1501
|
+
...(statements === undefined ? {} : { statements }),
|
|
1502
|
+
...(threadLock
|
|
1503
|
+
? {
|
|
1504
|
+
holderFd: this.holderRecord?.fd(),
|
|
1505
|
+
...(this.writeQueue === undefined ? {} : { writersDir: this.writeQueue.directory }),
|
|
1506
|
+
...(checkQueue ? { checkQueue: true } : {}),
|
|
1507
|
+
}
|
|
1508
|
+
: {}),
|
|
1509
|
+
});
|
|
1392
1510
|
}
|
|
1393
1511
|
/** Changes whenever another connection commits to the database: the lock is being used, not held idle. */
|
|
1394
1512
|
async dataVersion() {
|
|
@@ -1404,39 +1522,65 @@ class NodeSqliteDatabase {
|
|
|
1404
1522
|
* `StorageWriteLockTimeoutError` of a writer that gives up names the process holding the lock. Every other failure,
|
|
1405
1523
|
* including a writers' queue that cannot be used, rejects at once with its cause.
|
|
1406
1524
|
*/
|
|
1407
|
-
async begin(lockWaitMs = this.lockWaitMs) {
|
|
1525
|
+
async begin(lockWaitMs = this.lockWaitMs, statements) {
|
|
1408
1526
|
const waitStarted = performance.now();
|
|
1409
1527
|
let ticket;
|
|
1410
1528
|
let notices;
|
|
1411
1529
|
let holding = false;
|
|
1530
|
+
const threadManaged = this.threadManagesLock();
|
|
1412
1531
|
try {
|
|
1413
|
-
// Before its first attempt, so a holder stopped or starved the moment it takes the lock is still named. The writers'
|
|
1414
|
-
// queue is looked at meanwhile, so the two file system calls cost one wait for its threads instead of two.
|
|
1415
1532
|
const queue = this.writeQueue;
|
|
1416
1533
|
queue?.observe();
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1534
|
+
let lastCause;
|
|
1535
|
+
if (threadManaged) {
|
|
1536
|
+
// Uncontended fast path: the connection thread checks the writers'-queue directory, writes the holder
|
|
1537
|
+
// record, and attempts BEGIN IMMEDIATE (+ leading statements) in one request with zero thread-pool waits.
|
|
1538
|
+
const fast = await this.attemptBegin(statements, true);
|
|
1539
|
+
if (fast === undefined) {
|
|
1540
|
+
holding = true;
|
|
1541
|
+
this.lockUse.acquired(waitStarted);
|
|
1542
|
+
return this.takeLed();
|
|
1543
|
+
}
|
|
1544
|
+
if (fast === BEGIN_CONTENDED && queue !== undefined) {
|
|
1545
|
+
const waiting = await this.queueFileOp(() => queue.liveTicketsOffLoop());
|
|
1546
|
+
if (waiting.length > 0)
|
|
1547
|
+
ticket = await this.queueFileOp(() => queue.join(waiting));
|
|
1548
|
+
}
|
|
1549
|
+
else if (fast !== BEGIN_CONTENDED) {
|
|
1550
|
+
lastCause = fast;
|
|
1551
|
+
if (queue !== undefined)
|
|
1552
|
+
ticket = await this.queueFileOp(async () => queue.join(await queue.liveTicketsOffLoop()));
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
else {
|
|
1556
|
+
// Before its first attempt, so a holder stopped or starved the moment it takes the lock is still named. The writers'
|
|
1557
|
+
// queue is looked at meanwhile, so the two file system calls cost one wait for its threads instead of two.
|
|
1558
|
+
const [, contended] = await Promise.all([this.holderRecord?.trying(), queue?.contendedOffLoop()]);
|
|
1559
|
+
// Writers already waiting in other processes go first.
|
|
1560
|
+
if (queue !== undefined && contended === true) {
|
|
1561
|
+
const waiting = await this.queueFileOp(() => queue.liveTicketsOffLoop());
|
|
1562
|
+
if (waiting.length > 0)
|
|
1563
|
+
ticket = await this.queueFileOp(() => queue.join(waiting));
|
|
1564
|
+
}
|
|
1423
1565
|
}
|
|
1424
1566
|
// Read only once this writer waits, so an uncontended transaction pays nothing for it.
|
|
1425
|
-
let version = ticket === undefined ? undefined : await this.dataVersion();
|
|
1567
|
+
let version = ticket === undefined && lastCause === undefined ? undefined : await this.dataVersion();
|
|
1426
1568
|
let stalledSince = performance.now();
|
|
1427
|
-
let lastCause;
|
|
1428
1569
|
for (;;) {
|
|
1429
1570
|
notices?.clear();
|
|
1430
1571
|
if (ticket !== undefined)
|
|
1431
1572
|
notices = await this.watchTicket(ticket, notices);
|
|
1432
1573
|
const behind = ticket !== undefined && (await this.queueFileOp(() => ticket.behindOthers()));
|
|
1433
1574
|
if (!behind) {
|
|
1434
|
-
const attempt = this.attemptBegin();
|
|
1575
|
+
const attempt = this.attemptBegin(statements);
|
|
1435
1576
|
const refused = attempt instanceof Promise ? await attempt : attempt;
|
|
1436
1577
|
if (refused === undefined) {
|
|
1437
1578
|
holding = true;
|
|
1438
|
-
|
|
1439
|
-
|
|
1579
|
+
if (threadManaged)
|
|
1580
|
+
this.lockUse.acquired(waitStarted);
|
|
1581
|
+
else
|
|
1582
|
+
this.acquired(waitStarted);
|
|
1583
|
+
return this.takeLed();
|
|
1440
1584
|
}
|
|
1441
1585
|
lastCause = refused;
|
|
1442
1586
|
if (ticket === undefined && queue !== undefined) {
|
|
@@ -1457,10 +1601,13 @@ class NodeSqliteDatabase {
|
|
|
1457
1601
|
const stalledMs = performance.now() - stalledSince;
|
|
1458
1602
|
if (stalledMs >= lockWaitMs)
|
|
1459
1603
|
throw await this.lockWaitTimeout(lockWaitMs, stalledMs, behind, lastCause);
|
|
1460
|
-
if (!behind && committed && (await this.attemptThroughRelease())) {
|
|
1604
|
+
if (!behind && committed && (await this.attemptThroughRelease(statements))) {
|
|
1461
1605
|
holding = true;
|
|
1462
|
-
|
|
1463
|
-
|
|
1606
|
+
if (threadManaged)
|
|
1607
|
+
this.lockUse.acquired(waitStarted);
|
|
1608
|
+
else
|
|
1609
|
+
this.acquired(waitStarted);
|
|
1610
|
+
return this.takeLed();
|
|
1464
1611
|
}
|
|
1465
1612
|
const recheckMs = notices?.watching === true || stalledMs >= this.lockWaitMs
|
|
1466
1613
|
? LOCK_WAIT_RECHECK_MS
|
|
@@ -1478,37 +1625,51 @@ class NodeSqliteDatabase {
|
|
|
1478
1625
|
this.leaving = { ticket: ticket.name, left: ticket.leave() };
|
|
1479
1626
|
else
|
|
1480
1627
|
await ticket?.leave();
|
|
1481
|
-
if (!holding)
|
|
1628
|
+
if (!holding) {
|
|
1629
|
+
await this.flushThreadHolderError();
|
|
1482
1630
|
await this.holderRecord?.free();
|
|
1631
|
+
}
|
|
1483
1632
|
}
|
|
1484
1633
|
}
|
|
1485
1634
|
/**
|
|
1486
|
-
* One attempt at the lock: `undefined` once it is taken,
|
|
1487
|
-
*
|
|
1635
|
+
* One attempt at the lock: `undefined` once it is taken, `BEGIN_CONTENDED` when `checkQueue` found entries in the
|
|
1636
|
+
* writers'-queue directory, or the SQLITE_BUSY that refused it. Anything else fails. Answered at once on the
|
|
1637
|
+
* calling thread, and as a promise by a connection on a thread of its own.
|
|
1488
1638
|
*/
|
|
1489
|
-
attemptBegin() {
|
|
1639
|
+
attemptBegin(statements, checkQueue = false) {
|
|
1490
1640
|
const refusal = (error) => {
|
|
1491
1641
|
const cause = error instanceof StorageUnavailableError ? error.cause : undefined;
|
|
1492
1642
|
if (!isSqliteBusy(cause))
|
|
1493
1643
|
throw error;
|
|
1494
1644
|
return cause;
|
|
1495
1645
|
};
|
|
1646
|
+
const isContended = (value) => typeof value === "object" && value !== null && "contended" in value;
|
|
1496
1647
|
// Open from the moment BEGIN is sent: the connection's thread may take the lock while this thread runs on.
|
|
1497
1648
|
const hold = this.fileGate?.role === "holds" ? holdFile(this.fileGate.file) : undefined;
|
|
1498
1649
|
let attempt;
|
|
1499
1650
|
try {
|
|
1500
|
-
attempt = this.tryBegin();
|
|
1651
|
+
attempt = this.tryBegin(statements, checkQueue);
|
|
1501
1652
|
}
|
|
1502
1653
|
catch (error) {
|
|
1503
1654
|
releaseHold(hold);
|
|
1504
1655
|
return refusal(error);
|
|
1505
1656
|
}
|
|
1506
1657
|
if (!(attempt instanceof Promise)) {
|
|
1658
|
+
if (isContended(attempt)) {
|
|
1659
|
+
releaseHold(hold);
|
|
1660
|
+
return BEGIN_CONTENDED;
|
|
1661
|
+
}
|
|
1507
1662
|
this.current.hold = hold;
|
|
1663
|
+
this.led = attempt;
|
|
1508
1664
|
return undefined;
|
|
1509
1665
|
}
|
|
1510
|
-
return attempt.then(() => {
|
|
1666
|
+
return attempt.then((led) => {
|
|
1667
|
+
if (isContended(led)) {
|
|
1668
|
+
releaseHold(hold);
|
|
1669
|
+
return BEGIN_CONTENDED;
|
|
1670
|
+
}
|
|
1511
1671
|
this.current.hold = hold;
|
|
1672
|
+
this.led = led;
|
|
1512
1673
|
return undefined;
|
|
1513
1674
|
}, (error) => {
|
|
1514
1675
|
releaseHold(hold);
|
|
@@ -1524,15 +1685,21 @@ class NodeSqliteDatabase {
|
|
|
1524
1685
|
* free while that writer kept committing. Trying on every turn for a tick finds the lock the moment such a
|
|
1525
1686
|
* writer's commit lets go of it.
|
|
1526
1687
|
*/
|
|
1527
|
-
async attemptThroughRelease() {
|
|
1688
|
+
async attemptThroughRelease(statements) {
|
|
1528
1689
|
const until = performance.now() + LOCK_RELEASE_RETRY_MS;
|
|
1529
1690
|
for (let attempt = 0; attempt < LOCK_RELEASE_RETRY_ATTEMPTS && performance.now() < until; attempt++) {
|
|
1530
1691
|
await new Promise((resolve) => setImmediate(resolve));
|
|
1531
|
-
if ((await this.attemptBegin()) === undefined)
|
|
1692
|
+
if ((await this.attemptBegin(statements)) === undefined)
|
|
1532
1693
|
return true;
|
|
1533
1694
|
}
|
|
1534
1695
|
return false;
|
|
1535
1696
|
}
|
|
1697
|
+
/** The answer of the `begin` request that took the lock, for the transaction that took it, once. */
|
|
1698
|
+
takeLed() {
|
|
1699
|
+
const led = this.led;
|
|
1700
|
+
this.led = undefined;
|
|
1701
|
+
return led;
|
|
1702
|
+
}
|
|
1536
1703
|
/**
|
|
1537
1704
|
* Keeps the ticket live and watched: one watch for the whole wait, started again only when the ticket had to be
|
|
1538
1705
|
* recreated, since a watch ends with the file it watched.
|
|
@@ -1570,16 +1737,20 @@ class NodeSqliteDatabase {
|
|
|
1570
1737
|
this.current.hold = undefined;
|
|
1571
1738
|
releaseHold(hold);
|
|
1572
1739
|
this.lockUse.released(committed);
|
|
1573
|
-
const
|
|
1740
|
+
const release = this.connection instanceof ThreadConnection ? this.connection.takeReleaseState() : undefined;
|
|
1741
|
+
await this.flushThreadHolderError();
|
|
1742
|
+
const recorded = release?.freed === true ? undefined : this.holderRecord?.free();
|
|
1574
1743
|
const leaving = this.leaving;
|
|
1575
1744
|
this.leaving = undefined;
|
|
1576
1745
|
// Gone before the turn is handed on, so the writer it wakes finds no ticket of this one ahead of it.
|
|
1577
1746
|
await leaving?.left;
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1747
|
+
if (leaving !== undefined || release?.hasWaiters !== false) {
|
|
1748
|
+
try {
|
|
1749
|
+
await this.writeQueue?.wakeNext(leaving?.ticket);
|
|
1750
|
+
}
|
|
1751
|
+
catch (cause) {
|
|
1752
|
+
this.degraded("wake-failed", cause);
|
|
1753
|
+
}
|
|
1583
1754
|
}
|
|
1584
1755
|
await recorded;
|
|
1585
1756
|
}
|
|
@@ -1621,10 +1792,34 @@ class NodeSqliteDatabase {
|
|
|
1621
1792
|
* Statements on the connection, each sent the moment it is called, so calls a transaction makes without awaiting
|
|
1622
1793
|
* the ones before run in the order it made them, as on a connection that runs each one as it is called.
|
|
1623
1794
|
*/
|
|
1624
|
-
createExecutor(active) {
|
|
1625
|
-
|
|
1795
|
+
createExecutor(active, lead, finish, writeTx = false) {
|
|
1796
|
+
/** Whether the transaction takes no more calls: its COMMIT went with its start, or its callback finished it. */
|
|
1797
|
+
const ended = () => lead?.ended === true || finish?.statements !== undefined;
|
|
1798
|
+
/** The next leading statement's answer when `sql` and `params` make it; otherwise the lead ends. */
|
|
1799
|
+
const ledBy = (sql, params) => {
|
|
1800
|
+
if (lead === undefined)
|
|
1801
|
+
return undefined;
|
|
1802
|
+
const next = lead.answered[0];
|
|
1803
|
+
if (next !== undefined && next.sql === sql && sameParams(next.params, params)) {
|
|
1804
|
+
lead.answered.shift();
|
|
1805
|
+
return next;
|
|
1806
|
+
}
|
|
1807
|
+
lead.answered.length = 0;
|
|
1808
|
+
return undefined;
|
|
1809
|
+
};
|
|
1810
|
+
const closedTransactionError = () => unavailable(this.descriptor, new Error("SQLite transaction is no longer active"));
|
|
1811
|
+
const execute = async (request, params = [], answer) => {
|
|
1626
1812
|
if (!active())
|
|
1627
1813
|
throw new StorageTransactionClosedError();
|
|
1814
|
+
const led = "sql" in request && answer !== undefined ? ledBy(request.sql, params) : ledBy("", []);
|
|
1815
|
+
if (led !== undefined)
|
|
1816
|
+
return answer(led.rows, led.changes);
|
|
1817
|
+
if (lead?.aborted !== undefined)
|
|
1818
|
+
throw unavailable(this.descriptor, lead.aborted);
|
|
1819
|
+
if (ended())
|
|
1820
|
+
throw new StorageTransactionClosedError();
|
|
1821
|
+
if (writeTx && this.connection instanceof ThreadConnection && this.connection.inTransaction === false)
|
|
1822
|
+
throw closedTransactionError();
|
|
1628
1823
|
const invalidIndex = invalidTextParam(params);
|
|
1629
1824
|
if (invalidIndex !== -1)
|
|
1630
1825
|
throw new StorageInvalidTextError(invalidIndex);
|
|
@@ -1633,16 +1828,98 @@ class NodeSqliteDatabase {
|
|
|
1633
1828
|
const executor = {
|
|
1634
1829
|
checkJsonbExtract: () => execute({ kind: "jsonbExtract" }),
|
|
1635
1830
|
exec: (sql) => execute({ kind: "exec", sql }),
|
|
1636
|
-
run: (sql, ...params) => execute({ kind: "run", sql, params }, params),
|
|
1637
|
-
get: (sql, ...params) => execute({ kind: "get", sql, params }, params),
|
|
1638
|
-
all: (sql, ...params) => execute({ kind: "all", sql, params }, params),
|
|
1831
|
+
run: (sql, ...params) => execute({ kind: "run", sql, params }, params, (_rows, changes) => ({ changes })),
|
|
1832
|
+
get: (sql, ...params) => execute({ kind: "get", sql, params }, params, (rows) => rows[0]),
|
|
1833
|
+
all: (sql, ...params) => execute({ kind: "all", sql, params }, params, (rows) => rows),
|
|
1639
1834
|
};
|
|
1640
1835
|
// On the calling thread a sequence would hold the event loop for all of its statements.
|
|
1641
1836
|
const connection = this.connection;
|
|
1642
|
-
if (connection instanceof ThreadConnection)
|
|
1643
|
-
offerSequences(executor, (sequence) =>
|
|
1837
|
+
if (connection instanceof ThreadConnection) {
|
|
1838
|
+
offerSequences(executor, (sequence) => {
|
|
1839
|
+
ledBy("", []);
|
|
1840
|
+
if (active() && lead?.aborted !== undefined)
|
|
1841
|
+
return Promise.reject(unavailable(this.descriptor, lead.aborted));
|
|
1842
|
+
if (active() && ended())
|
|
1843
|
+
return Promise.reject(new StorageTransactionClosedError());
|
|
1844
|
+
if (active() && writeTx && connection.inTransaction === false)
|
|
1845
|
+
return Promise.reject(closedTransactionError());
|
|
1846
|
+
return this.sendSequence(connection, sequence, active);
|
|
1847
|
+
});
|
|
1848
|
+
if (finish !== undefined)
|
|
1849
|
+
offerFinish(executor, (statements) => {
|
|
1850
|
+
// One request carries them with the end: the end is the last of its statements.
|
|
1851
|
+
if (!active() || ended() || lead?.aborted !== undefined)
|
|
1852
|
+
return false;
|
|
1853
|
+
if (writeTx && connection.inTransaction === false)
|
|
1854
|
+
return false;
|
|
1855
|
+
if (statements.some(({ params }) => invalidTextParam(params) !== -1))
|
|
1856
|
+
return false;
|
|
1857
|
+
// Strip any matching prefix already executed by `begin` or `lead` so those statements never run twice.
|
|
1858
|
+
let skip = 0;
|
|
1859
|
+
if (lead !== undefined) {
|
|
1860
|
+
while (skip < statements.length && skip < lead.answered.length) {
|
|
1861
|
+
const next = lead.answered[skip];
|
|
1862
|
+
const statement = statements[skip];
|
|
1863
|
+
if (statement.script === true ||
|
|
1864
|
+
next.sql !== statement.sql ||
|
|
1865
|
+
!sameParams(next.params, statement.params))
|
|
1866
|
+
break;
|
|
1867
|
+
skip += 1;
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
const remaining = skip === 0 ? statements : statements.slice(skip);
|
|
1871
|
+
if (remaining.length >= MAX_SEQUENCE_REQUEST_STATEMENTS)
|
|
1872
|
+
return false;
|
|
1873
|
+
ledBy("", []);
|
|
1874
|
+
finish.statements = remaining.map(({ sql, params, script }) => sendableStatement({ sql, params: snapshotParams(params), ...(script === true ? { script } : {}) }));
|
|
1875
|
+
return true;
|
|
1876
|
+
});
|
|
1877
|
+
}
|
|
1644
1878
|
return executor;
|
|
1645
1879
|
}
|
|
1880
|
+
/**
|
|
1881
|
+
* The lead a transaction's callback is answered from, out of `led`, the answer of the `begin` or `lead` request that
|
|
1882
|
+
* sent `statements`; undefined when that request sent none. `offset` skips prefix statements such as a `SAVEPOINT`
|
|
1883
|
+
* prepended ahead of `statements`. `withCommit` says the request sent the COMMIT behind them, which ran unless a
|
|
1884
|
+
* statement before it failed.
|
|
1885
|
+
*/
|
|
1886
|
+
transactionLead(statements, led, withCommit, offset = 0) {
|
|
1887
|
+
if (led === undefined || statements === undefined)
|
|
1888
|
+
return undefined;
|
|
1889
|
+
const answered = led.answers
|
|
1890
|
+
.slice(offset, offset + statements.length)
|
|
1891
|
+
.map((answer, index) => ({ ...statements[index], ...answer }));
|
|
1892
|
+
const failedAt = led.failure === undefined ? undefined : led.answers.length - offset;
|
|
1893
|
+
const reachedCommit = withCommit && (failedAt === undefined || failedAt === statements.length);
|
|
1894
|
+
return {
|
|
1895
|
+
answered,
|
|
1896
|
+
ended: reachedCommit,
|
|
1897
|
+
...(reachedCommit && failedAt !== undefined
|
|
1898
|
+
? { commitFailure: led.failure, commitOpen: led.open === true }
|
|
1899
|
+
: {}),
|
|
1900
|
+
...(!reachedCommit && failedAt !== undefined && led.open !== true ? { aborted: led.failure } : {}),
|
|
1901
|
+
};
|
|
1902
|
+
}
|
|
1903
|
+
/**
|
|
1904
|
+
* Ends the transaction its callback returned from: sends `end` (COMMIT or a savepoint's RELEASE), behind the statements
|
|
1905
|
+
* the callback finished it with, in one request, or where its `begin` request sent the COMMIT already, reports that
|
|
1906
|
+
* COMMIT's failure. A statement that fails there fails the transaction, as the COMMIT does.
|
|
1907
|
+
*/
|
|
1908
|
+
async endTransaction(end, lead, finish) {
|
|
1909
|
+
if (lead?.aborted !== undefined)
|
|
1910
|
+
throw unavailable(this.descriptor, lead.aborted);
|
|
1911
|
+
if (lead?.ended === true) {
|
|
1912
|
+
if (lead.commitFailure !== undefined)
|
|
1913
|
+
throw unavailable(this.descriptor, lead.commitFailure);
|
|
1914
|
+
return;
|
|
1915
|
+
}
|
|
1916
|
+
const statements = finish?.statements;
|
|
1917
|
+
if (statements === undefined || statements.length === 0 || !(this.connection instanceof ThreadConnection)) {
|
|
1918
|
+
await this.executor.exec(end.sql);
|
|
1919
|
+
return;
|
|
1920
|
+
}
|
|
1921
|
+
await this.sendSequence(this.connection, { statements: [...statements, end] }, () => true);
|
|
1922
|
+
}
|
|
1646
1923
|
/**
|
|
1647
1924
|
* Sends `sequence` to the connection's thread: `repeat` with the first statements as one request, and the rest in
|
|
1648
1925
|
* requests of at most `MAX_SEQUENCE_REQUEST_STATEMENTS`, each taken from `statements` and sent once the one before it
|
|
@@ -1834,25 +2111,48 @@ class NodeSqliteDatabase {
|
|
|
1834
2111
|
// The queue's directory outlives its writers: only a live ticket means a writer is waiting. One that cannot be
|
|
1835
2112
|
// read counts as a writer waiting.
|
|
1836
2113
|
const queue = this.writeQueue;
|
|
1837
|
-
if (queue !== undefined && (await queue.contendedOffLoop())) {
|
|
1838
|
-
const waiting = await queue.liveTicketsOffLoop().catch(() => undefined);
|
|
1839
|
-
if (waiting === undefined || waiting.length > 0)
|
|
1840
|
-
return false;
|
|
1841
|
-
}
|
|
1842
2114
|
const start = performance.now();
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
2115
|
+
const threadManaged = this.threadManagesLock();
|
|
2116
|
+
if (threadManaged) {
|
|
2117
|
+
try {
|
|
2118
|
+
let attempt = await this.attemptBegin(undefined, true);
|
|
2119
|
+
if (attempt === BEGIN_CONTENDED && queue !== undefined) {
|
|
2120
|
+
const waiting = await queue.liveTicketsOffLoop().catch(() => undefined);
|
|
2121
|
+
if (waiting === undefined || waiting.length > 0)
|
|
2122
|
+
return false;
|
|
2123
|
+
attempt = await this.attemptBegin();
|
|
2124
|
+
}
|
|
2125
|
+
if (attempt !== undefined) {
|
|
2126
|
+
await this.holderRecord?.free();
|
|
2127
|
+
return false;
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2130
|
+
catch (error) {
|
|
1847
2131
|
await this.holderRecord?.free();
|
|
1848
|
-
|
|
2132
|
+
throw error;
|
|
1849
2133
|
}
|
|
2134
|
+
this.lockUse.acquired(start);
|
|
1850
2135
|
}
|
|
1851
|
-
|
|
1852
|
-
await
|
|
1853
|
-
|
|
2136
|
+
else {
|
|
2137
|
+
if (queue !== undefined && (await queue.contendedOffLoop())) {
|
|
2138
|
+
const waiting = await queue.liveTicketsOffLoop().catch(() => undefined);
|
|
2139
|
+
if (waiting === undefined || waiting.length > 0)
|
|
2140
|
+
return false;
|
|
2141
|
+
}
|
|
2142
|
+
await this.holderRecord?.trying();
|
|
2143
|
+
try {
|
|
2144
|
+
const attempt = this.attemptBegin();
|
|
2145
|
+
if ((attempt instanceof Promise ? await attempt : attempt) !== undefined) {
|
|
2146
|
+
await this.holderRecord?.free();
|
|
2147
|
+
return false;
|
|
2148
|
+
}
|
|
2149
|
+
}
|
|
2150
|
+
catch (error) {
|
|
2151
|
+
await this.holderRecord?.free();
|
|
2152
|
+
throw error;
|
|
2153
|
+
}
|
|
2154
|
+
this.acquired(start);
|
|
1854
2155
|
}
|
|
1855
|
-
this.acquired(start);
|
|
1856
2156
|
return new Promise((resolve, reject) => {
|
|
1857
2157
|
void this.commitAlone({ callback, resolve: () => resolve(true), reject, scope }).catch(reject);
|
|
1858
2158
|
});
|
|
@@ -1895,6 +2195,8 @@ class NodeSqliteDatabase {
|
|
|
1895
2195
|
}
|
|
1896
2196
|
if (this.closing)
|
|
1897
2197
|
return Promise.reject(new StoreClosedError(this.descriptor));
|
|
2198
|
+
// Only a connection thread takes statements with its BEGIN; one on the calling thread runs each call as it is made.
|
|
2199
|
+
const lead = this.connection instanceof ThreadConnection ? writeLead(options) : undefined;
|
|
1898
2200
|
return new Promise((resolve, reject) => {
|
|
1899
2201
|
const queued = {
|
|
1900
2202
|
callback,
|
|
@@ -1902,6 +2204,7 @@ class NodeSqliteDatabase {
|
|
|
1902
2204
|
reject,
|
|
1903
2205
|
lockWaitMs: options?.lockWaitMs,
|
|
1904
2206
|
scope: currentHoldScope(),
|
|
2207
|
+
...(lead === undefined ? {} : { lead }),
|
|
1905
2208
|
};
|
|
1906
2209
|
const last = this.waitingBatches.at(-1);
|
|
1907
2210
|
if (last?.open === true && last.members.length < MAX_GROUP_COMMIT_TRANSACTIONS) {
|
|
@@ -1999,19 +2302,44 @@ class NodeSqliteDatabase {
|
|
|
1999
2302
|
* transactions requested directly behind it while it waited join it: otherwise they would queue for the lock all
|
|
2000
2303
|
* over again once it lets go. Members left after the hold budget take the lock again with nothing new, so other
|
|
2001
2304
|
* connections to the file wait for at most one batch of this one's.
|
|
2305
|
+
*
|
|
2306
|
+
* The first member's leading statements go in the request that takes the lock, and so does its COMMIT where it names
|
|
2307
|
+
* only those (`leadingOnly`) and nothing is queued to join it: that transaction is then one request (#6560).
|
|
2002
2308
|
*/
|
|
2003
2309
|
async runBatch(batch, firstAcquisition) {
|
|
2310
|
+
const first = batch.members[0];
|
|
2311
|
+
const willGroup = batch.members.length > 1 || (firstAcquisition && this.waitingBatches[0]?.position === batch.position + 1);
|
|
2312
|
+
const withCommit = first.lead?.only === true && !willGroup;
|
|
2313
|
+
const withSavepoint = first.lead !== undefined &&
|
|
2314
|
+
willGroup &&
|
|
2315
|
+
this.connection instanceof ThreadConnection &&
|
|
2316
|
+
this.connection.inTransaction !== undefined;
|
|
2317
|
+
const statements = first.lead === undefined
|
|
2318
|
+
? undefined
|
|
2319
|
+
: withCommit
|
|
2320
|
+
? [...first.lead.statements, COMMIT]
|
|
2321
|
+
: withSavepoint
|
|
2322
|
+
? [{ sql: "SAVEPOINT atomic_group_0", params: [] }, ...first.lead.statements]
|
|
2323
|
+
: first.lead.statements;
|
|
2324
|
+
let led;
|
|
2004
2325
|
try {
|
|
2005
|
-
await this.begin(this.lockWait(batch.members));
|
|
2326
|
+
led = await this.begin(this.lockWait(batch.members), statements);
|
|
2006
2327
|
}
|
|
2007
2328
|
catch (cause) {
|
|
2008
2329
|
for (const queued of batch.members.splice(0))
|
|
2009
2330
|
queued.reject(cause);
|
|
2010
2331
|
return;
|
|
2011
2332
|
}
|
|
2012
|
-
|
|
2333
|
+
const savepointRan = withSavepoint && led !== undefined && led.answers.length >= 1;
|
|
2334
|
+
const lead = withSavepoint && led !== undefined && led.answers.length === 0 && led.failure !== undefined
|
|
2335
|
+
? { answered: [], ended: false, ...(led.open === true ? {} : { aborted: led.failure }) }
|
|
2336
|
+
: this.transactionLead(first.lead?.statements, led, withCommit, savepointRan ? 1 : 0);
|
|
2337
|
+
// A transaction its start committed takes nobody along: they wait for the lock once more.
|
|
2338
|
+
if (firstAcquisition && lead?.ended !== true)
|
|
2013
2339
|
this.absorbNext(batch);
|
|
2014
|
-
await (batch.members.length === 1
|
|
2340
|
+
await (batch.members.length === 1
|
|
2341
|
+
? this.commitAlone(batch.members.pop(), lead)
|
|
2342
|
+
: this.commitMembers(batch, lead, savepointRan));
|
|
2015
2343
|
}
|
|
2016
2344
|
/**
|
|
2017
2345
|
* Moves the transactions of the batches queued directly behind this one (no statement between them) into this one,
|
|
@@ -2029,20 +2357,40 @@ class NodeSqliteDatabase {
|
|
|
2029
2357
|
lockWait(batch) {
|
|
2030
2358
|
return Math.max(...batch.map((queued) => queued.lockWaitMs ?? this.lockWaitMs));
|
|
2031
2359
|
}
|
|
2032
|
-
/**
|
|
2033
|
-
|
|
2360
|
+
/**
|
|
2361
|
+
* A transaction with nobody queued with it commits on its own, without savepoints. `lead` answers its first calls; a
|
|
2362
|
+
* COMMIT its start sent already let go of the lock, which is handed on before the callback reads the answers.
|
|
2363
|
+
*/
|
|
2364
|
+
async commitAlone(queued, lead) {
|
|
2034
2365
|
let active = true;
|
|
2366
|
+
const finish = { end: COMMIT };
|
|
2367
|
+
const executor = () => this.createExecutor(() => active, lead, finish, true);
|
|
2368
|
+
if (lead?.ended === true && lead.commitFailure === undefined) {
|
|
2369
|
+
await this.released(true);
|
|
2370
|
+
try {
|
|
2371
|
+
queued.resolve(await runInHold(undefined, queued.scope, () => queued.callback(executor())));
|
|
2372
|
+
}
|
|
2373
|
+
catch (cause) {
|
|
2374
|
+
queued.reject(cause);
|
|
2375
|
+
}
|
|
2376
|
+
finally {
|
|
2377
|
+
active = false;
|
|
2378
|
+
}
|
|
2379
|
+
return;
|
|
2380
|
+
}
|
|
2035
2381
|
try {
|
|
2036
|
-
const value = await runInHold(this.current.hold, queued.scope, () => queued.callback(
|
|
2382
|
+
const value = await runInHold(this.current.hold, queued.scope, () => queued.callback(executor()));
|
|
2037
2383
|
active = false;
|
|
2038
|
-
await this.
|
|
2384
|
+
await this.endTransaction(COMMIT, lead, finish);
|
|
2039
2385
|
await this.released(true);
|
|
2040
2386
|
queued.resolve(value);
|
|
2041
2387
|
}
|
|
2042
2388
|
catch (cause) {
|
|
2043
2389
|
active = false;
|
|
2044
2390
|
try {
|
|
2045
|
-
|
|
2391
|
+
// A failure of its leading statements, or of a bundled COMMIT that SQLite rolled back itself, left nothing to roll back.
|
|
2392
|
+
if (lead?.aborted === undefined && !(lead?.ended === true && lead.commitOpen !== true))
|
|
2393
|
+
await this.executor.exec("ROLLBACK");
|
|
2046
2394
|
}
|
|
2047
2395
|
catch (rollbackCause) {
|
|
2048
2396
|
await this.released(false);
|
|
@@ -2055,21 +2403,83 @@ class NodeSqliteDatabase {
|
|
|
2055
2403
|
}
|
|
2056
2404
|
/**
|
|
2057
2405
|
* Runs the batch's members in one transaction, for at most `groupCommitHoldMs`: members left when it runs out
|
|
2058
|
-
* wait for the lock again, still ahead of anything queued after them.
|
|
2406
|
+
* wait for the lock again, still ahead of anything queued after them. `lead` answers the first member's first calls:
|
|
2407
|
+
* when `firstHasSavepoint` is false, its leading statements ran before any savepoint (later members arrived while
|
|
2408
|
+
* `begin` ran), so its failure rolls back the transaction, in which nothing else has run, and the others take the
|
|
2409
|
+
* lock again. Each member with a savepoint bundles its `SAVEPOINT` with its leading statements in one request when
|
|
2410
|
+
* supported by the connection thread.
|
|
2059
2411
|
*/
|
|
2060
|
-
async commitMembers(batch) {
|
|
2412
|
+
async commitMembers(batch, lead, firstHasSavepoint = false) {
|
|
2061
2413
|
const began = performance.now();
|
|
2062
2414
|
const outcomes = [];
|
|
2063
|
-
|
|
2415
|
+
if (lead !== undefined && !firstHasSavepoint) {
|
|
2416
|
+
const first = batch.members[0];
|
|
2417
|
+
let active = true;
|
|
2418
|
+
try {
|
|
2419
|
+
const value = await runInHold(this.current.hold, first.scope, () => first.callback(this.createExecutor(() => active, lead, undefined, true)));
|
|
2420
|
+
active = false;
|
|
2421
|
+
// A transaction that already ended runs nobody else, whatever the callback made of the failure.
|
|
2422
|
+
if (lead.aborted !== undefined)
|
|
2423
|
+
throw unavailable(this.descriptor, lead.aborted);
|
|
2424
|
+
if (this.connection instanceof ThreadConnection && this.connection.inTransaction === false)
|
|
2425
|
+
throw unavailable(this.descriptor, new Error("SQLite transaction is no longer active"));
|
|
2426
|
+
outcomes.push({ ok: true, value });
|
|
2427
|
+
}
|
|
2428
|
+
catch (cause) {
|
|
2429
|
+
active = false;
|
|
2430
|
+
let failure = cause;
|
|
2431
|
+
try {
|
|
2432
|
+
if (lead.aborted === undefined)
|
|
2433
|
+
await this.executor.exec("ROLLBACK");
|
|
2434
|
+
}
|
|
2435
|
+
catch (rollbackCause) {
|
|
2436
|
+
failure = new StorageRollbackError(cause, rollbackCause);
|
|
2437
|
+
}
|
|
2438
|
+
await this.released(false);
|
|
2439
|
+
batch.members.shift().reject(failure);
|
|
2440
|
+
if (batch.members.length > 0)
|
|
2441
|
+
await this.runBatch(batch, false);
|
|
2442
|
+
return;
|
|
2443
|
+
}
|
|
2444
|
+
}
|
|
2445
|
+
for (const queued of batch.members.slice(outcomes.length)) {
|
|
2064
2446
|
if (outcomes.length > 0 && performance.now() - began >= this.groupCommitHoldMs)
|
|
2065
2447
|
break;
|
|
2066
2448
|
const savepoint = `atomic_group_${outcomes.length}`;
|
|
2449
|
+
const release = { sql: `RELEASE ${savepoint}`, params: [] };
|
|
2450
|
+
const finish = { end: release };
|
|
2067
2451
|
let active = true;
|
|
2452
|
+
let memberLead;
|
|
2068
2453
|
try {
|
|
2069
|
-
|
|
2070
|
-
|
|
2454
|
+
if (outcomes.length === 0 && firstHasSavepoint) {
|
|
2455
|
+
memberLead = lead;
|
|
2456
|
+
}
|
|
2457
|
+
else if (queued.lead !== undefined &&
|
|
2458
|
+
this.connection instanceof ThreadConnection &&
|
|
2459
|
+
this.connection.inTransaction !== undefined) {
|
|
2460
|
+
const led = (await this.connection
|
|
2461
|
+
.request({
|
|
2462
|
+
kind: "lead",
|
|
2463
|
+
statements: [{ sql: `SAVEPOINT ${savepoint}`, params: [] }, ...queued.lead.statements],
|
|
2464
|
+
})
|
|
2465
|
+
.catch((cause) => {
|
|
2466
|
+
throw unavailable(this.descriptor, cause);
|
|
2467
|
+
}));
|
|
2468
|
+
if (led === undefined) {
|
|
2469
|
+
await this.executor.exec(`SAVEPOINT ${savepoint}`);
|
|
2470
|
+
}
|
|
2471
|
+
else {
|
|
2472
|
+
if (led.answers.length === 0 && led.failure !== undefined)
|
|
2473
|
+
throw unavailable(this.descriptor, led.failure);
|
|
2474
|
+
memberLead = this.transactionLead(queued.lead.statements, led, false, 1);
|
|
2475
|
+
}
|
|
2476
|
+
}
|
|
2477
|
+
else {
|
|
2478
|
+
await this.executor.exec(`SAVEPOINT ${savepoint}`);
|
|
2479
|
+
}
|
|
2480
|
+
const value = await runInHold(this.current.hold, queued.scope, () => queued.callback(this.createExecutor(() => active, memberLead, finish, true)));
|
|
2071
2481
|
active = false;
|
|
2072
|
-
await this.
|
|
2482
|
+
await this.endTransaction(release, memberLead, finish);
|
|
2073
2483
|
outcomes.push({ ok: true, value });
|
|
2074
2484
|
}
|
|
2075
2485
|
catch (cause) {
|
|
@@ -2251,6 +2661,8 @@ export async function openNodeSqliteDatabase(path, { busyTimeoutMs = 5000, lockW
|
|
|
2251
2661
|
// the file the open lock names, which is the database's own unless a link takes the open elsewhere.
|
|
2252
2662
|
const likely = readOnly || isInMemoryDatabase(path) ? undefined : heldOpenLock?.target;
|
|
2253
2663
|
const holders = likely === undefined ? undefined : { target: likely, ready: prepareHolderDirectory(holderDirectory(likely)) };
|
|
2664
|
+
if (readOnly && targetFile !== undefined && !isInMemoryDatabase(path))
|
|
2665
|
+
await prepareReadOnlyWal(targetFile);
|
|
2254
2666
|
// A file-backed connection runs on a thread of its own, so opening it, waiting for its locks and its synced
|
|
2255
2667
|
// commits never hold this thread (#5376).
|
|
2256
2668
|
const opened = isInMemoryDatabase(path)
|
|
@@ -2361,7 +2773,7 @@ function __atomicOnDemandFailed(error, feature) {
|
|
|
2361
2773
|
return (async () => {
|
|
2362
2774
|
const root = new URL("../../", import.meta.url);
|
|
2363
2775
|
const releases = (globalThis[Symbol.for("atomic.in-place-update-release.v1")] ??= new Map());
|
|
2364
|
-
const key = `${root.href}#0.10.11-alpha.
|
|
2776
|
+
const key = `${root.href}#0.10.11-alpha.4`;
|
|
2365
2777
|
let release = releases.get(key);
|
|
2366
2778
|
if (release === undefined) {
|
|
2367
2779
|
const current = (async () => {
|
|
@@ -2389,7 +2801,7 @@ function __atomicOnDemandFailed(error, feature) {
|
|
|
2389
2801
|
} catch {
|
|
2390
2802
|
// No installation to read, as in a bundle of the package: the release the process runs decides.
|
|
2391
2803
|
}
|
|
2392
|
-
const updatedTo = typeof installed === "string" && installed !== "0.10.11-alpha.
|
|
2804
|
+
const updatedTo = typeof installed === "string" && installed !== "0.10.11-alpha.4" ? installed : running !== undefined && running.version !== "0.10.11-alpha.4" ? "0.10.11-alpha.4" : undefined;
|
|
2393
2805
|
if (updatedTo === undefined) throw error;
|
|
2394
2806
|
const application = typeof running?.name === "string" ? running.name : "atomic";
|
|
2395
2807
|
const restart = new Error(`${application} was updated to ${updatedTo} while this session was running; restart it to keep using ${feature}.`, {
|