@bastani/atomic 0.10.10 → 0.10.11-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +83 -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 +8 -10
- package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js.map +1 -1
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +6 -6
- package/dist/_shared/mode-shared-2QJSCUM6.js +52 -15
- 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 +3 -3
- package/dist/_shared/{sdk-RRLVN7ER.js → sdk-AVFII7NK.js} +757 -233
- package/dist/_shared/sdk-AVFII7NK.js.map +1 -0
- package/dist/_shared/session-data-AHTU7IS6.js +3 -3
- package/dist/_shared/session-manager-list-2BLEEZVG.js +1 -1
- package/dist/_shared/{startup-0-0-4VG2G44V.js → startup-0-0-57KF6LZH.js} +94 -42
- package/dist/_shared/startup-0-0-57KF6LZH.js.map +1 -0
- package/dist/_shared/{startup-0-1-XTIL65D4.js → startup-0-1-GIY75K46.js} +75 -13
- package/dist/_shared/startup-0-1-GIY75K46.js.map +1 -0
- package/dist/_shared/startup-0-2-27OWFHV6.js +72 -7
- package/dist/_shared/startup-0-2-27OWFHV6.js.map +1 -1
- package/dist/_shared/startup-0-3-T4DVFYWX.js +4 -4
- package/dist/_shared/startup-0-4-ZMJV547D.js +4 -4
- package/dist/_shared/{startup-0-5-FD2P735I.js → startup-0-5-YDW47QX6.js} +27 -69
- package/dist/_shared/startup-0-5-YDW47QX6.js.map +1 -0
- package/dist/_shared/startup-10-0-TDQNBDDL.js +6 -6
- package/dist/_shared/startup-12-0-55AAXBJZ.js +3 -3
- package/dist/_shared/startup-14-0-MLX36RBG.js +4 -4
- package/dist/_shared/startup-15-0-YUKGAC63.js +31 -7
- package/dist/_shared/startup-15-0-YUKGAC63.js.map +1 -1
- package/dist/_shared/startup-15-1-4S7FLMNG.js +7 -6
- package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
- package/dist/_shared/startup-8-0-34CBHPZH.js +4 -4
- package/dist/_shared/{startup-8-1-4KANEHRA.js → startup-8-1-X32CYSXB.js} +1219 -714
- package/dist/_shared/startup-8-1-X32CYSXB.js.map +1 -0
- package/dist/_shared/storage-command-7MGXLJGZ.js +14 -8
- 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 +2 -2
- package/dist/builtin/intercom/CHANGELOG.md +18 -0
- package/dist/builtin/intercom/broker/broker.bundle.mjs +993 -362
- 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 +375 -65
- package/dist/builtin/intercom/broker/sql-outbox-store.ts +270 -101
- 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 +139 -1
- 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 +12 -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 +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 +2 -2
- 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 +2 -2
- package/dist/cli/team-command.impl.js +3 -3
- package/dist/cli/team-command.js +3 -3
- package/dist/cli.js +2 -2
- package/dist/core/agent-session-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 +1 -1
- package/dist/core/export-html/oversized-render-inputs.impl.js +3 -3
- package/dist/core/export-html/oversized-render-inputs.js +3 -3
- package/dist/core/export-html/tool-renderer.impl.js +3 -3
- package/dist/core/export-html/tool-renderer.js +3 -3
- package/dist/core/extensions/jiti-loader.impl.js +3 -3
- package/dist/core/extensions/jiti-loader.js +3 -3
- package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
- package/dist/core/extensions/jiti-static-loader.js +3 -3
- package/dist/core/extensions/loader-host-modules.code.js +1 -1
- package/dist/core/extensions/loader-host-modules.impl.js +3 -3
- package/dist/core/extensions/loader-host-modules.js +3 -3
- package/dist/core/extensions/loader-virtual-modules.js +2 -2
- package/dist/core/extensions/runner-context.js +3 -3
- 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 +3 -4
- 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 +17 -13
- 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 +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/storage/added-exports.d.ts +6 -0
- package/dist/core/storage/added-exports.js +16 -0
- package/dist/core/storage/added-exports.js.map +1 -0
- package/dist/core/storage/database.d.ts +16 -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 +3 -0
- package/dist/core/storage/index.js +5 -2
- package/dist/core/storage/index.js.map +1 -1
- package/dist/core/storage/migrations.d.ts +22 -0
- package/dist/core/storage/migrations.js +55 -0
- package/dist/core/storage/migrations.js.map +1 -1
- package/dist/core/storage/node-sqlite-thread.js +19 -6
- package/dist/core/storage/node-sqlite-thread.js.map +1 -1
- package/dist/core/storage/node-sqlite.js +53 -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 +18 -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 +42 -0
- package/dist/core/storage/schema-catalog.js +141 -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 +41 -20
- 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 +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.code.js +1 -1
- package/dist/core/storage/session/chunked-resume-projection.impl.js +3 -3
- package/dist/core/storage/session/chunked-resume-projection.js +3 -3
- package/dist/core/storage/session/expanded-child-details.code.js +3 -3
- package/dist/core/storage/session/expanded-child-details.impl.js +3 -3
- package/dist/core/storage/session/expanded-child-details.js +3 -3
- package/dist/core/storage/session/fork-row-bytes.impl.js +3 -3
- package/dist/core/storage/session/fork-row-bytes.js +3 -3
- package/dist/core/storage/session/fork-row-index.impl.js +3 -3
- package/dist/core/storage/session/fork-row-index.js +3 -3
- package/dist/core/storage/session/fork-staging.code.js +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-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-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 +2 -2
- 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 +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 +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-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 +102 -5
- 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 +14 -0
- package/dist/core/storage/sqlite-facade.d.ts +37 -5
- package/dist/core/storage/sqlite-facade.js +351 -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 +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/bash.d.ts +8 -4
- package/dist/core/tools/history-session.d.ts +5 -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 +14 -2
- package/dist/core/worktree-snapshot/blob-store.js +69 -16
- 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/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 +2 -2
- 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 +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/agent-panel.d.ts +1 -0
- 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/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 +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/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 +8 -1
- package/dist/startup-stages/3.js +1 -6
- package/dist/startup-stages/5.js +1 -1
- package/dist/startup-stages/7.js +1 -5
- 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/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 +339 -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 +58 -2
- package/docs/settings.md +20 -1
- package/docs/skills/authoring.md +1 -1
- package/docs/skills.md +79 -6
- package/docs/storage.md +262 -12
- 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/startup-0-0-4VG2G44V.js.map +0 -1
- package/dist/_shared/startup-0-1-XTIL65D4.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,20 +576,42 @@ class DriverDatabase {
|
|
|
342
576
|
batch;
|
|
343
577
|
notifications;
|
|
344
578
|
freeBytes;
|
|
345
|
-
|
|
579
|
+
databaseIdentity;
|
|
580
|
+
openReader;
|
|
581
|
+
/** Readers this database opened and that are not closed; closing closes them. */
|
|
582
|
+
readers = new Set();
|
|
583
|
+
closed;
|
|
584
|
+
constructor(driver, redact, closed) {
|
|
346
585
|
this.driver = driver;
|
|
586
|
+
this.closed = closed;
|
|
587
|
+
const openReader = driver.openReader?.bind(driver);
|
|
588
|
+
if (openReader)
|
|
589
|
+
this.openReader = () => this.startReader(openReader);
|
|
347
590
|
if (driver.notifications !== undefined)
|
|
348
591
|
this.notifications = driver.notifications;
|
|
349
592
|
const freeBytes = driver.freeBytes?.bind(driver);
|
|
350
593
|
if (freeBytes)
|
|
351
594
|
this.freeBytes = async () => freeBytes();
|
|
595
|
+
const databaseIdentity = driver.databaseIdentity?.bind(driver);
|
|
596
|
+
if (databaseIdentity)
|
|
597
|
+
this.databaseIdentity = databaseIdentity;
|
|
352
598
|
this.redact = redact;
|
|
353
599
|
this.descriptor = { adapter: driver.descriptor.adapter, location: redact(driver.descriptor.location) };
|
|
600
|
+
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`);
|
|
601
|
+
const maxReads = concurrentReads(driver);
|
|
602
|
+
this.queue =
|
|
603
|
+
driver.concurrentTransactions === true || maxReads !== undefined
|
|
604
|
+
? new ScopeQueue(stalled, maxReads)
|
|
605
|
+
: new LaneQueue(stalled);
|
|
354
606
|
this.dialect = driver.dialect ?? sqliteDialect;
|
|
355
|
-
|
|
607
|
+
const readsOnly = driver.readsOnly?.bind(driver);
|
|
608
|
+
const scopeOf = readsOnly !== undefined && (driver.concurrentTransactions === true || maxReads !== undefined)
|
|
609
|
+
? (sql) => (readsOnly(sql) ? READ_SCOPE : PLAIN_SCOPE)
|
|
610
|
+
: () => PLAIN_SCOPE;
|
|
611
|
+
this.executor = this.createExecutor(driver, (operation, sql) => {
|
|
356
612
|
if (this.closePromise)
|
|
357
613
|
return Promise.reject(new StoreClosedError(this.descriptor));
|
|
358
|
-
return this.queue.push(() => this.retrying(operation, true));
|
|
614
|
+
return this.queue.push(() => this.retrying(operation, true), false, sql === undefined ? PLAIN_SCOPE : scopeOf(sql));
|
|
359
615
|
}, true);
|
|
360
616
|
const batch = driver.batch?.bind(driver);
|
|
361
617
|
if (batch)
|
|
@@ -469,7 +725,7 @@ class DriverDatabase {
|
|
|
469
725
|
if (transient !== undefined) {
|
|
470
726
|
const failure = new StorageTransientError(this.descriptor, {
|
|
471
727
|
code: transient.code,
|
|
472
|
-
outcome: applies ? transient.outcome : "not-applied",
|
|
728
|
+
outcome: applies || attempt.committing === true ? transient.outcome : "not-applied",
|
|
473
729
|
attempts: attempt.number,
|
|
474
730
|
...(transient.hop === undefined
|
|
475
731
|
? {}
|
|
@@ -495,7 +751,7 @@ class DriverDatabase {
|
|
|
495
751
|
if (invalidIndex !== -1)
|
|
496
752
|
throw new StorageInvalidTextError(invalidIndex);
|
|
497
753
|
return this.call(() => connection.execute(sql, bound), attempt, applies, bound);
|
|
498
|
-
});
|
|
754
|
+
}, sql);
|
|
499
755
|
};
|
|
500
756
|
return {
|
|
501
757
|
exec: (sql) => admit((attempt) => this.call(() => connection.executeMultiple(sql), attempt, applies)),
|
|
@@ -535,14 +791,17 @@ class DriverDatabase {
|
|
|
535
791
|
catch (error) {
|
|
536
792
|
return Promise.reject(error);
|
|
537
793
|
}
|
|
794
|
+
const leading = this.driver.pipelinedTransactions === true ? leadingStatements(options?.leading) : [];
|
|
538
795
|
const begin = {
|
|
539
796
|
concurrency,
|
|
540
797
|
...(options?.lockWaitMs === undefined ? {} : { lockWaitMs: options.lockWaitMs }),
|
|
541
798
|
...(options?.readOnly === true ? { readOnly: true } : {}),
|
|
799
|
+
...(leading.length === 0 ? {} : { leading }),
|
|
542
800
|
};
|
|
543
801
|
const run = () => this.retrying((attempt) => this.runTransaction(callback, attempt, begin), replay);
|
|
544
|
-
|
|
545
|
-
|
|
802
|
+
const concurrentWrites = this.driver.concurrentTransactions === true;
|
|
803
|
+
if (concurrency.kind === "serial" || !concurrentWrites)
|
|
804
|
+
return this.queue.push(run, false, transactionScope(concurrency, options?.readOnly === true, concurrentWrites));
|
|
546
805
|
const result = run();
|
|
547
806
|
const settled = result.then(() => { }, () => { });
|
|
548
807
|
this.concurrent.add(settled);
|
|
@@ -555,22 +814,48 @@ class DriverDatabase {
|
|
|
555
814
|
const handleQueue = pipelined ? new PipelineQueue() : new CallQueue();
|
|
556
815
|
let active = true;
|
|
557
816
|
let result;
|
|
558
|
-
|
|
817
|
+
/** Set once `finish` sent the callback's last calls: the transaction takes no more. */
|
|
818
|
+
let finished = false;
|
|
819
|
+
const handle = this.createExecutor(connection, (operation) => active && !finished
|
|
820
|
+
? handleQueue.push(() => operation(attempt))
|
|
821
|
+
: Promise.reject(new StorageTransactionClosedError()), false);
|
|
822
|
+
if (pipelined) {
|
|
823
|
+
offerSequences(handle, (sequence) => pipelineSequence(handle, sequence));
|
|
824
|
+
offerFinish(handle, (statements) => {
|
|
825
|
+
if (!active || finished)
|
|
826
|
+
return false;
|
|
827
|
+
if (statements.length > MAX_SEQUENCE_REQUEST_STATEMENTS || statements.some(hasInvalidText))
|
|
828
|
+
return false;
|
|
829
|
+
// Their failures are the transaction's, reported once the commit is answered.
|
|
830
|
+
for (const statement of statements) {
|
|
831
|
+
const sent = statement.script === true
|
|
832
|
+
? handle.exec(statement.sql)
|
|
833
|
+
: handle.run(statement.sql, ...statement.params);
|
|
834
|
+
sent.catch(() => { });
|
|
835
|
+
}
|
|
836
|
+
finished = true;
|
|
837
|
+
return true;
|
|
838
|
+
});
|
|
839
|
+
}
|
|
559
840
|
const close = () => this.call(() => connection.close?.());
|
|
560
841
|
// Once the callback has returned, the commit's own failure decides whether the transaction runs again: a commit
|
|
561
842
|
// that may have applied, or that failed for a reason the driver does not recognize, never does, whatever the
|
|
562
843
|
// callback met before it. A committed transaction never runs again either.
|
|
563
844
|
const commit = () => {
|
|
564
845
|
attempt.transient = undefined;
|
|
846
|
+
attempt.committing = true;
|
|
565
847
|
return this.call(() => connection.commit(), attempt, true);
|
|
566
848
|
};
|
|
849
|
+
let returned = false;
|
|
567
850
|
try {
|
|
568
851
|
let committing;
|
|
569
852
|
try {
|
|
570
853
|
result = await callback(handle);
|
|
571
|
-
|
|
572
|
-
//
|
|
573
|
-
//
|
|
854
|
+
returned = true;
|
|
855
|
+
// A pipelined connection takes the commit behind statements the callback left unanswered, such as those sent by
|
|
856
|
+
// `finish`, so locks they take are held for one round trip. The driver's commit fails when one of them failed,
|
|
857
|
+
// so nothing commits then, and the first of them to fail is the failure. One that the server refused lets the
|
|
858
|
+
// transaction run again, having written nothing; one whose connection broke may have committed, so it does not.
|
|
574
859
|
if (pipelined) {
|
|
575
860
|
committing = commit();
|
|
576
861
|
committing.catch(() => { });
|
|
@@ -580,10 +865,25 @@ class DriverDatabase {
|
|
|
580
865
|
active = false;
|
|
581
866
|
await handleQueue.drained();
|
|
582
867
|
}
|
|
868
|
+
// A read-only transaction on a connection of its own has its answer once its reads are answered: its commit only
|
|
869
|
+
// ends the snapshot, so the connection goes back once the commit is answered, while the caller goes on.
|
|
870
|
+
if (begin.readOnly === true &&
|
|
871
|
+
(this.driver.concurrentTransactions === true || concurrentReads(this.driver) !== undefined)) {
|
|
872
|
+
this.endInBackground(committing ?? commit(), connection, close);
|
|
873
|
+
return result;
|
|
874
|
+
}
|
|
583
875
|
await (committing ?? commit());
|
|
584
876
|
}
|
|
585
877
|
catch (cause) {
|
|
586
878
|
let failure = cause;
|
|
879
|
+
// A commit that came back as a rollback names no reason: the statement that failed is the transaction's failure,
|
|
880
|
+
// and whether it may run again is that failure's, as when the callback awaited it.
|
|
881
|
+
const unanswered = returned && handleQueue instanceof PipelineQueue ? await handleQueue.firstFailure() : undefined;
|
|
882
|
+
if (unanswered !== undefined) {
|
|
883
|
+
failure = unanswered;
|
|
884
|
+
if (unanswered instanceof StorageTransientError)
|
|
885
|
+
attempt.transient = unanswered;
|
|
886
|
+
}
|
|
587
887
|
try {
|
|
588
888
|
await this.call(() => connection.rollback());
|
|
589
889
|
}
|
|
@@ -597,8 +897,40 @@ class DriverDatabase {
|
|
|
597
897
|
await close();
|
|
598
898
|
return result;
|
|
599
899
|
}
|
|
900
|
+
/**
|
|
901
|
+
* Ends a read-only transaction whose reads were all answered once `committing` settles: rolls it back when the commit
|
|
902
|
+
* failed, then closes it. Closing the database waits for it.
|
|
903
|
+
*/
|
|
904
|
+
endInBackground(committing, connection, close) {
|
|
905
|
+
const ended = committing
|
|
906
|
+
.catch(() => this.call(() => connection.rollback()).catch(() => { }))
|
|
907
|
+
.then(close)
|
|
908
|
+
.catch(() => { });
|
|
909
|
+
this.concurrent.add(ended);
|
|
910
|
+
void ended.then(() => this.concurrent.delete(ended));
|
|
911
|
+
}
|
|
912
|
+
startReader(openReader) {
|
|
913
|
+
if (this.closePromise)
|
|
914
|
+
return Promise.reject(new StoreClosedError(this.descriptor));
|
|
915
|
+
const opening = this.call(openReader).then((driver) => {
|
|
916
|
+
const reader = new DriverDatabase(driver, this.redact, () => this.readers.delete(reader));
|
|
917
|
+
this.readers.add(reader);
|
|
918
|
+
if (this.closePromise)
|
|
919
|
+
throw new StoreClosedError(this.descriptor);
|
|
920
|
+
return reader;
|
|
921
|
+
});
|
|
922
|
+
const settled = opening.then(() => { }, () => { });
|
|
923
|
+
this.concurrent.add(settled);
|
|
924
|
+
void settled.then(() => this.concurrent.delete(settled));
|
|
925
|
+
return opening;
|
|
926
|
+
}
|
|
600
927
|
close() {
|
|
601
|
-
|
|
928
|
+
const closeReaders = () => Promise.allSettled([...this.readers].map((reader) => reader.close()));
|
|
929
|
+
// Readers stop taking calls now; one that finished opening meanwhile is closed after the drain.
|
|
930
|
+
this.closePromise ??= Promise.all([this.queue.drained(), ...this.concurrent, closeReaders()])
|
|
931
|
+
.then(closeReaders)
|
|
932
|
+
.then(() => this.call(() => this.driver.close()))
|
|
933
|
+
.finally(() => this.closed?.());
|
|
602
934
|
for (const wake of this.wakeRetries)
|
|
603
935
|
wake();
|
|
604
936
|
return this.closePromise;
|
|
@@ -606,7 +938,8 @@ class DriverDatabase {
|
|
|
606
938
|
}
|
|
607
939
|
/**
|
|
608
940
|
* Wraps a SQLite-compatible driver as a `SqliteDatabase`. The facade queues operations in call order and keeps them
|
|
609
|
-
* outside active transactions
|
|
941
|
+
* outside active transactions (on a driver that runs transactions concurrently, only operations that conflict wait for
|
|
942
|
+
* each other), snapshots binary parameters at call time, rejects NUL text, returns safe-range integers
|
|
610
943
|
* as numbers and blobs as `Uint8Array` copies, expires transaction handles when their callback settles, maps driver
|
|
611
944
|
* failures to `StorageUnavailableError` with credentials redacted, and reports failed rollbacks with
|
|
612
945
|
* `StorageRollbackError`. A failure the driver recognizes as transient is a `StorageTransientError`; a statement, a
|