@bastani/atomic 0.10.11-alpha.3 → 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 +51 -0
- 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 +4 -4
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +4 -4
- package/dist/_shared/mode-shared-2QJSCUM6.js +4 -4
- package/dist/_shared/p1a-prewarm-XIU57JHF.js +3 -3
- package/dist/_shared/p1b-elig-TVB5CBLL.js +22 -6
- package/dist/_shared/p1b-elig-TVB5CBLL.js.map +1 -1
- 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 +2 -2
- package/dist/_shared/sdk-B5LEWGGI.js +899 -515
- package/dist/_shared/sdk-B5LEWGGI.js.map +1 -1
- 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-EZUKEP4Q.js → startup-0-0-XJJDOIEC.js} +6 -12
- package/dist/_shared/{startup-0-0-EZUKEP4Q.js.map → startup-0-0-XJJDOIEC.js.map} +1 -1
- package/dist/_shared/{startup-0-1-RTOHJFDJ.js → startup-0-1-M6OWAYHH.js} +354 -103
- package/dist/_shared/startup-0-1-M6OWAYHH.js.map +1 -0
- package/dist/_shared/startup-0-2-5QHPCEON.js +18 -9
- package/dist/_shared/startup-0-2-5QHPCEON.js.map +1 -1
- package/dist/_shared/startup-0-3-4ZYBYQNM.js +4 -4
- package/dist/_shared/startup-0-4-ZMJV547D.js +4 -4
- package/dist/_shared/startup-0-5-YDW47QX6.js +4 -4
- package/dist/_shared/startup-10-0-TDQNBDDL.js +4 -4
- package/dist/_shared/startup-12-0-55AAXBJZ.js +1 -1
- package/dist/_shared/startup-14-0-MLX36RBG.js +2 -2
- package/dist/_shared/startup-15-0-YUKGAC63.js +2 -2
- package/dist/_shared/startup-15-1-4S7FLMNG.js +4 -4
- package/dist/_shared/startup-8-0-34CBHPZH.js +2114 -235
- package/dist/_shared/startup-8-0-34CBHPZH.js.map +1 -1
- package/dist/_shared/startup-8-1-LZFXSD3Z.js +12 -12
- package/dist/_shared/storage-command-7MGXLJGZ.js +6 -6
- package/dist/_shared/storage-command-7MGXLJGZ.js.map +1 -1
- package/dist/_shared/storage-status-K7PX2RXA.js +2 -2
- package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
- package/dist/_shared/team-DOQKICG2.js +1 -1
- package/dist/_shared/tree-outline-MUEPK5B7.js +2 -2
- package/dist/builtin/intercom/CHANGELOG.md +19 -0
- package/dist/builtin/intercom/broker/broker.bundle.mjs +1020 -108
- package/dist/builtin/intercom/broker/client.ts +8 -0
- package/dist/builtin/intercom/broker/database-wake-up-bus.ts +91 -14
- package/dist/builtin/intercom/broker/multinode-router.ts +102 -17
- package/dist/builtin/intercom/broker/multinode-state-store.ts +41 -2
- package/dist/builtin/intercom/broker/send-order-gate.ts +5 -2
- package/dist/builtin/intercom/broker/sql-add-column.ts +22 -1
- package/dist/builtin/intercom/broker/sql-lease-store.ts +304 -48
- package/dist/builtin/intercom/broker/sql-outbox-store.ts +541 -50
- package/dist/builtin/intercom/broker/sql-restoring-reservation-store.ts +239 -8
- package/dist/builtin/intercom/broker/sql-retention.ts +11 -2
- package/dist/builtin/intercom/broker/sql-schema.ts +42 -8
- package/dist/builtin/intercom/index.bundle.mjs +13 -2
- 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 +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 +2 -2
- package/dist/cli/auth-cli.impl.js +3 -3
- package/dist/cli/auth-cli.js +3 -3
- package/dist/cli/blueprint-command.code.js +1 -1
- 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 +1 -1
- 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 +1 -1
- 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/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 +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/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 +5 -4
- package/dist/core/sdk.code.js +2 -2
- package/dist/core/sdk.impl.js +3 -3
- package/dist/core/sdk.js +3 -3
- package/dist/core/session-manager-core.js +4 -4
- 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.impl.js +3 -3
- package/dist/core/session-storage.js +3 -3
- package/dist/core/storage/database.d.ts +6 -0
- package/dist/core/storage/database.js.map +1 -1
- package/dist/core/storage/fenced-paths.d.ts +7 -6
- package/dist/core/storage/fenced-paths.js +7 -6
- package/dist/core/storage/fenced-paths.js.map +1 -1
- package/dist/core/storage/index.js +2 -2
- package/dist/core/storage/node-sqlite-thread.js +209 -19
- package/dist/core/storage/node-sqlite-thread.js.map +1 -1
- package/dist/core/storage/node-sqlite.js +435 -71
- 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/provider.js +2 -2
- package/dist/core/storage/schema-catalog.d.ts +69 -7
- package/dist/core/storage/schema-catalog.js +352 -61
- package/dist/core/storage/schema-catalog.js.map +1 -1
- package/dist/core/storage/selection.js +2 -2
- 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 +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 +41 -23
- 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 +8 -8
- 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 +9 -1
- 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.d.ts +51 -7
- 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 +6 -0
- package/dist/core/storage/sqlite-facade.js +309 -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.impl.js +3 -3
- package/dist/core/storage/storage-status.js +3 -3
- package/dist/core/storage/team.impl.js +3 -3
- package/dist/core/storage/team.js +3 -3
- 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 +3 -3
- 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.impl.js +3 -3
- package/dist/core/tasks/task-view-source.js +3 -3
- package/dist/core/tools/read-url.code.js +2 -2
- 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 +5 -3
- package/dist/core/worktree-snapshot/blob-store.js +151 -21
- 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-snapshot-index.js +158 -41
- package/dist/core/worktree-snapshot/fork-snapshot-index.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 +1 -1
- package/dist/extensions/codemode/renderer.impl.js +3 -3
- package/dist/extensions/codemode/renderer.js +3 -3
- package/dist/extensions/mcp/cli.code.js +1 -1
- 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.impl.js +3 -3
- package/dist/extensions/mcp/runtime.js +3 -3
- package/dist/index.js +2 -2
- 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/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/package-manager-cli.code.js +4 -4
- 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/3.js +1 -1
- package/dist/startup-stages/5.js +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/docs/changelog.mdx +49 -0
- package/docs/storage/jsonl.md +3 -3
- package/package.json +8 -8
- package/dist/_shared/startup-0-1-RTOHJFDJ.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "../_shared/rolldown-runtime-BGM3D5V3.js";
|
|
2
|
-
import { CURRENT_SESSION_VERSION, getDefaultSessionDir, getDefaultSessionDirPath } from "../_shared/startup-0-0-
|
|
2
|
+
import { CURRENT_SESSION_VERSION, getDefaultSessionDir, getDefaultSessionDirPath } from "../_shared/startup-0-0-XJJDOIEC.js";
|
|
3
3
|
import { buildContextEntries, buildSessionContext, buildSessionProjection, getLatestCompactionBoundaryEntry, getSessionLeafId, sessionEntryToContextMessages } from "../_shared/startup-0-3-4ZYBYQNM.js";
|
|
4
4
|
import { SESSION_ALREADY_OPEN_EXIT_CODE, SessionAlreadyOpenError, SessionDeletedError, SessionEntryError, SessionHistoryNotLoadedError, SessionIdError, SessionOpenElsewhereError } from "../_shared/settings-startup-HXQLSUWM.js";
|
|
5
5
|
import { assertValidSessionId, findMostRecentSession, isInternalHeader, loadEntriesFromFile, parseSessionEntries } from "../_shared/startup-8-0-34CBHPZH.js";
|
|
@@ -6,7 +6,7 @@ try {
|
|
|
6
6
|
} catch (error) {
|
|
7
7
|
const root = new URL("../", import.meta.url);
|
|
8
8
|
const releases = (globalThis[Symbol.for("atomic.in-place-update-release.v1")] ??= new Map());
|
|
9
|
-
const key = `${root.href}#0.10.11-alpha.
|
|
9
|
+
const key = `${root.href}#0.10.11-alpha.4`;
|
|
10
10
|
let release = releases.get(key);
|
|
11
11
|
if (release === undefined) {
|
|
12
12
|
const current = (async () => {
|
|
@@ -27,8 +27,8 @@ try {
|
|
|
27
27
|
release = current;
|
|
28
28
|
}
|
|
29
29
|
const running = await release;
|
|
30
|
-
if (running === undefined || running.version === "0.10.11-alpha.
|
|
31
|
-
throw new Error((typeof running.name === "string" ? running.name : "atomic") + " was updated to 0.10.11-alpha.
|
|
30
|
+
if (running === undefined || running.version === "0.10.11-alpha.4") throw error;
|
|
31
|
+
throw new Error((typeof running.name === "string" ? running.name : "atomic") + " was updated to 0.10.11-alpha.4 while this session was running; restart it to keep using session storage.", {
|
|
32
32
|
cause: error,
|
|
33
33
|
});
|
|
34
34
|
}
|
|
@@ -6,7 +6,7 @@ try {
|
|
|
6
6
|
} catch (error) {
|
|
7
7
|
const root = new URL("../", import.meta.url);
|
|
8
8
|
const releases = (globalThis[Symbol.for("atomic.in-place-update-release.v1")] ??= new Map());
|
|
9
|
-
const key = `${root.href}#0.10.11-alpha.
|
|
9
|
+
const key = `${root.href}#0.10.11-alpha.4`;
|
|
10
10
|
let release = releases.get(key);
|
|
11
11
|
if (release === undefined) {
|
|
12
12
|
const current = (async () => {
|
|
@@ -27,8 +27,8 @@ try {
|
|
|
27
27
|
release = current;
|
|
28
28
|
}
|
|
29
29
|
const running = await release;
|
|
30
|
-
if (running === undefined || running.version === "0.10.11-alpha.
|
|
31
|
-
throw new Error((typeof running.name === "string" ? running.name : "atomic") + " was updated to 0.10.11-alpha.
|
|
30
|
+
if (running === undefined || running.version === "0.10.11-alpha.4") throw error;
|
|
31
|
+
throw new Error((typeof running.name === "string" ? running.name : "atomic") + " was updated to 0.10.11-alpha.4 while this session was running; restart it to keep using session storage.", {
|
|
32
32
|
cause: error,
|
|
33
33
|
});
|
|
34
34
|
}
|
|
@@ -6,7 +6,7 @@ try {
|
|
|
6
6
|
} catch (error) {
|
|
7
7
|
const root = new URL("../", import.meta.url);
|
|
8
8
|
const releases = (globalThis[Symbol.for("atomic.in-place-update-release.v1")] ??= new Map());
|
|
9
|
-
const key = `${root.href}#0.10.11-alpha.
|
|
9
|
+
const key = `${root.href}#0.10.11-alpha.4`;
|
|
10
10
|
let release = releases.get(key);
|
|
11
11
|
if (release === undefined) {
|
|
12
12
|
const current = (async () => {
|
|
@@ -27,8 +27,8 @@ try {
|
|
|
27
27
|
release = current;
|
|
28
28
|
}
|
|
29
29
|
const running = await release;
|
|
30
|
-
if (running === undefined || running.version === "0.10.11-alpha.
|
|
31
|
-
throw new Error((typeof running.name === "string" ? running.name : "atomic") + " was updated to 0.10.11-alpha.
|
|
30
|
+
if (running === undefined || running.version === "0.10.11-alpha.4") throw error;
|
|
31
|
+
throw new Error((typeof running.name === "string" ? running.name : "atomic") + " was updated to 0.10.11-alpha.4 while this session was running; restart it to keep using session storage.", {
|
|
32
32
|
cause: error,
|
|
33
33
|
});
|
|
34
34
|
}
|
|
@@ -6,7 +6,7 @@ try {
|
|
|
6
6
|
} catch (error) {
|
|
7
7
|
const root = new URL("../", import.meta.url);
|
|
8
8
|
const releases = (globalThis[Symbol.for("atomic.in-place-update-release.v1")] ??= new Map());
|
|
9
|
-
const key = `${root.href}#0.10.11-alpha.
|
|
9
|
+
const key = `${root.href}#0.10.11-alpha.4`;
|
|
10
10
|
let release = releases.get(key);
|
|
11
11
|
if (release === undefined) {
|
|
12
12
|
const current = (async () => {
|
|
@@ -27,8 +27,8 @@ try {
|
|
|
27
27
|
release = current;
|
|
28
28
|
}
|
|
29
29
|
const running = await release;
|
|
30
|
-
if (running === undefined || running.version === "0.10.11-alpha.
|
|
31
|
-
throw new Error((typeof running.name === "string" ? running.name : "atomic") + " was updated to 0.10.11-alpha.
|
|
30
|
+
if (running === undefined || running.version === "0.10.11-alpha.4") throw error;
|
|
31
|
+
throw new Error((typeof running.name === "string" ? running.name : "atomic") + " was updated to 0.10.11-alpha.4 while this session was running; restart it to keep using session storage.", {
|
|
32
32
|
cause: error,
|
|
33
33
|
});
|
|
34
34
|
}
|
|
@@ -157,6 +157,12 @@ export interface StorageNotifications {
|
|
|
157
157
|
* adapters send it in the transaction and ignore `unless`.
|
|
158
158
|
*/
|
|
159
159
|
notify(channel: string, payload: string, unless?: SqliteStatement): SqliteStatement;
|
|
160
|
+
/**
|
|
161
|
+
* Optional. Sends already-committed notifications produced by `notify` together, outside the database's serial
|
|
162
|
+
* call queue so post-commit wake-ups never block or wait behind unrelated transactions. Coalesced within the same
|
|
163
|
+
* window as in-transaction notifications, and awaited before the database closes.
|
|
164
|
+
*/
|
|
165
|
+
send?(notices: readonly SqliteStatement[]): Promise<void>;
|
|
160
166
|
/** Delivers `channel`'s events to `listener`, on one listening connection the database shares between channels. */
|
|
161
167
|
listen(channel: string, listener: (event: StorageNotificationEvent) => void): StorageNotificationSubscription;
|
|
162
168
|
/** Opens the listening connection when it is not open, and resolves with its state once the first attempt settled. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../../src/core/storage/database.ts"],"names":[],"mappings":"","sourcesContent":["import type { StorageDialect } from \"./dialect.js\";\n\nexport type SqliteValue = null | number | bigint | string | Uint8Array;\nexport type SqliteRow = Readonly<Record<string, SqliteValue>>;\n\nexport interface SqliteRunResult {\n\treadonly changes: number;\n}\n\nexport interface SqliteExecutor {\n\texec(sql: string): Promise<void>;\n\trun(sql: string, ...params: readonly SqliteValue[]): Promise<SqliteRunResult>;\n\tget<T extends SqliteRow>(sql: string, ...params: readonly SqliteValue[]): Promise<T | undefined>;\n\tall<T extends SqliteRow>(sql: string, ...params: readonly SqliteValue[]): Promise<T[]>;\n}\n\nexport interface StorageDescriptor {\n\treadonly adapter: string;\n\treadonly location: string;\n}\n\n/** One statement of a batch: SQL with positional `?` parameters. */\nexport interface SqliteStatement {\n\treadonly sql: string;\n\treadonly params: readonly SqliteValue[];\n}\n\n/** How a transaction takes its snapshot or write lock, and whether it may run again. */\nexport interface SqliteTransactionOptions {\n\t/** @internal A consistent read snapshot without a writer lock. The callback must only read. */\n\treadonly readOnly?: boolean;\n\t/**\n\t * How long the transaction keeps waiting for the write lock while it is held and no other connection commits,\n\t * instead of the connection's own lock wait. A writer whose work must not fail because another process stalled\n\t * with the lock held (starved of CPU, paused by garbage collection, stopped by a signal) waits longer: the holder\n\t * still commits or rolls back once it runs again. Adapters without a lock wait of their own ignore it.\n\t */\n\treadonly lockWaitMs?: number;\n\t/**\n\t * Lets a database from `createSqliteDatabase` run the callback again, in a new transaction, when a transient\n\t * failure (`StorageTransientError`) ended the transaction before it committed, so nothing of it was written. Set it\n\t * only for a callback that does nothing but use the transaction handle: anything else it does happens once per run.\n\t * Other databases ignore it.\n\t */\n\treadonly retryTransientFailures?: boolean;\n\t/**\n\t * How the transaction excludes other writers; `{ kind: \"serial\" }` when absent. SQLite runs every kind as\n\t * `BEGIN IMMEDIATE` unless `readOnly` is set; only a driver that runs transactions concurrently (Postgres) tells them apart.\n\t */\n\treadonly concurrency?: TransactionConcurrency;\n\t/**\n\t * @internal The statements the callback makes first, in this order, before it acts on any answer. A driver whose\n\t * transactions are pipelined sends them with the transaction's start, so they cost no round trip of their own, and\n\t * starts the callback once they are answered; each call of the callback that makes the next of them gets its answer.\n\t * Name only reads: a call that differs from the next of them ends the lead, and the answers of the rest go unused,\n\t * though they ran. A write may lead only as the callback's first call, made on every run whatever it reads, such as a\n\t * fenced path's one guarded write: it never runs unused. Other drivers ignore it.\n\t */\n\treadonly leading?: readonly SqliteStatement[];\n\t/**\n\t * @internal The callback makes the `leading` calls, all of them in order, and no other. A pipelined driver then sends\n\t * the commit right behind them, so the whole transaction costs one round trip: a call the callback makes after them\n\t * fails without being sent. When a leading statement fails, the transaction rolls back and the callback's call of\n\t * that statement fails. Other drivers ignore it.\n\t */\n\treadonly leadingOnly?: boolean;\n\t/**\n\t * @internal With `leading`, a `serial` transaction of a domain takes its locks in its first leading statement, a read,\n\t * and only when that read returns a row, instead of with its start: a transaction whose first read finds nothing\n\t * takes no lock. Every statement after it starts once the locks are held, so it sees every transaction that held them\n\t * and committed. A driver that ignores it takes the locks with the start. Other drivers ignore it.\n\t */\n\treadonly lockIfLeadingFinds?: boolean;\n\t/**\n\t * The commit returns before the server has written the transaction to disk, so a crash of the database server just\n\t * after it may lose it, though never part of it, and never a transaction that committed after it without this flag.\n\t * Only for writes whose loss is harmless because a later write repeats them, such as a lease renewal. PostgreSQL\n\t * turns `synchronous_commit` off for the transaction; other drivers ignore it.\n\t */\n\treadonly relaxedDurability?: boolean;\n}\n\n/** How one batch waits for a busy write lock, and whether it goes ahead of the database's queued calls. */\nexport interface SqliteBatchOptions {\n\t/**\n\t * How long a batch that found the database's write lock busy keeps sending again, with growing randomized waits\n\t * between tries. A busy batch wrote nothing, so sending it again is safe. Adapters without such a retry ignore it.\n\t */\n\treadonly lockWaitMs?: number;\n\t/**\n\t * Runs the batch before calls queued on this database that do not set it, and outside any limit the adapter puts on\n\t * concurrent writes: for small writes that must not wait behind others, such as a lease renewal.\n\t */\n\treadonly priority?: boolean;\n}\n\n/**\n * An audited fenced write path. Only `fencedPath(name)` in `fenced-paths.ts` makes one; a plain string is not one. The\n * brand is a string key, not a unique symbol, so the published declarations and the sources stay one type.\n */\nexport type FencedPathId = string & { readonly __atomicFencedPath: true };\n\n/**\n * `serial`: the body runs as if it were the only writer of `domain`, or of the whole database when `domain` is absent:\n * `BEGIN IMMEDIATE` on SQLite, `BEGIN` plus that domain's transaction advisory lock on Postgres. Several prefixes may\n * share one database, so `domain` names the scope in full: a store passes one of its prefixed table names.\n * `fenced`: the body runs under READ COMMITTED and takes the row locks it relies on itself. With `excludesSerial`, it\n * also waits for and excludes `serial` transactions without a domain, as a `serial` transaction with a domain does,\n * for a body whose check a whole-database writer (such as snapshot garbage collection) could otherwise race\n * (`StorageDialect.lockClause`); `audit` names the reviewed path. Identical to `serial` on SQLite.\n */\nexport type TransactionConcurrency =\n\t| { readonly kind: \"serial\"; readonly domain?: string }\n\t| { readonly kind: \"fenced\"; readonly audit: FencedPathId; readonly excludesSerial?: boolean };\n\n/**\n * What a database's listening connection is doing: `listening`, notifications arrive; `connecting`, it is not known yet;\n * `unavailable`, none arrive, and pollers find the work: `pooler` when the endpoint is a transaction pooler (a\n * notification sent through the database did not reach the listening session), `connection-failed` when the listening\n * connection could not be opened or broke.\n */\nexport type StorageListenerState =\n\t| { readonly status: \"listening\" }\n\t| { readonly status: \"connecting\" }\n\t| { readonly status: \"unavailable\"; readonly reason: \"pooler\" | \"connection-failed\" };\n\n/**\n * `notification`: a transaction that ran `notify(channel, payload)` committed. `listening`: the listening connection\n * began listening again after it was unavailable, so notifications sent meanwhile were lost.\n */\nexport type StorageNotificationEvent =\n\t| { readonly kind: \"notification\"; readonly payload: string }\n\t| { readonly kind: \"listening\" };\n\nexport interface StorageNotificationSubscription {\n\t/** Stops delivering events to this listener; idempotent. */\n\tclose(): void;\n}\n\n/**\n * Wake-ups through the database (#5103): Postgres `LISTEN`/`NOTIFY`. A notification is only a hint that a poller would\n * find the same work at its next poll; notifications are lost while the listening connection is down, and through a\n * transaction pooler none arrive, so a store that sends them keeps its poll.\n */\nexport interface StorageNotifications {\n\t/**\n\t * A statement that sends `payload` to the listeners of `channel` once the transaction it runs in commits: run it in the\n\t * transaction of the write it announces. `channel` is a name such as `<prefix>pool_ready`; the database shortens a long\n\t * one the same way for `notify` and `listen`. With `unless`, a read, the notification goes out only when that read,\n\t * made as it goes out, returns no row.\n\t *\n\t * Postgres answers the statement at once and sends the notification in a transaction of its own, right behind the\n\t * `COMMIT` in the same round trip: a notifying commit holds a server-wide lock until it is flushed, which would make\n\t * every other notifying commit wait for it. That transaction may also run when the `COMMIT` rolled back, and commits\n\t * that send the same notification within a few milliseconds of each other share one, sent once they committed. Older\n\t * adapters send it in the transaction and ignore `unless`.\n\t */\n\tnotify(channel: string, payload: string, unless?: SqliteStatement): SqliteStatement;\n\t/** Delivers `channel`'s events to `listener`, on one listening connection the database shares between channels. */\n\tlisten(channel: string, listener: (event: StorageNotificationEvent) => void): StorageNotificationSubscription;\n\t/** Opens the listening connection when it is not open, and resolves with its state once the first attempt settled. */\n\tstate(): Promise<StorageListenerState>;\n}\n\n/**\n * @internal What a driver read of its schema in its open's own round trip (#6560): the rows of the catalog read\n * `readStorageSchemaCatalog` makes (`kind` `relation`, `trigger` or `column`, with `name` and `detail`) and the\n * versions `ledger` records, as rows of `domain` and `version`; `versions` is undefined when the ledger did not exist.\n */\nexport interface StorageOpenedCatalog {\n\treadonly ledger: string;\n\treadonly rows: readonly SqliteRow[];\n\treadonly versions: readonly SqliteRow[] | undefined;\n}\n\nexport interface SqliteDatabase extends SqliteExecutor {\n\t/**\n\t * True when the connection refuses writes, as `openNodeSqliteDatabase(path, { readOnly: true })` sets it, so opening a\n\t * session store skips a cleanup write that would fail. Optional: a read-only connection that leaves it unset still\n\t * opens a session store, whose failed cleanup is ignored.\n\t */\n\treadonly readOnly?: boolean;\n\treadonly descriptor: StorageDescriptor;\n\t/**\n\t * @internal Which database this handle reaches, for comparison only: two handles this process opened answer the same\n\t * string only when a transaction of either reads and writes the very tables the other does (the same adapter, server\n\t * or file, database, schema or namespace). Undefined, or absent, where that cannot be told, as for a database in\n\t * memory: such a handle is the same database as itself alone.\n\t */\n\tdatabaseIdentity?(): string | undefined;\n\t/** @internal Checks whether this embedded connection can prepare a JSONB extraction without issuing a read. */\n\tsupportsJsonbExtract?(): Promise<boolean>;\n\t/** The SQL dialect the database speaks; absent means SQLite. Read it through `dialectOf(database)`. */\n\treadonly dialect?: StorageDialect;\n\t/** Wake-ups through the database; present only on a database that delivers them (Postgres). */\n\treadonly notifications?: StorageNotifications;\n\t/**\n\t * The bytes this process may still write on the file system that holds the database's file (where a link to the file\n\t * points, and where its write-ahead log goes), as a SQLite file database reports them. Absent, or resolving\n\t * undefined, when this process cannot see the database's disk (a server, memory) or the file system does not say.\n\t */\n\tfreeBytes?(): Promise<number | undefined>;\n\t/** @internal Run one short maintenance transaction only if this handle, its writer gate and the database lock\n\t * are immediately available. A backend without no-wait admission leaves this absent. */\n\ttryMaintenance?(callback: (transaction: SqliteExecutor) => Promise<void>): Promise<boolean>;\n\t/** Opens a separate handle on this same database for reads. It has its own call queue; the caller must close it. */\n\topenReader?(): Promise<SqliteDatabase>;\n\t/**\n\t * @internal The schema the driver read when it opened, given once: the first store open answers its schema checks\n\t * from it instead of reading the catalog again. Undefined after the first call, and where the driver read none.\n\t */\n\ttakeOpenedCatalog?(): StorageOpenedCatalog | undefined;\n\ttransaction<T>(\n\t\tcallback: (transaction: SqliteExecutor) => Promise<T>,\n\t\toptions?: SqliteTransactionOptions,\n\t): Promise<T>;\n\t/**\n\t * @internal Runs `statement` by itself as one request that commits on its own, queued in this process as a\n\t * transaction of `concurrency` is: behind the calls such a transaction waits for, and ahead of the calls that wait\n\t * for it. The statement takes on the server whatever locks it needs itself, such as a function that takes the\n\t * domain's advisory locks. A transient failure that applied nothing runs it again. Resolves with its rows. Present\n\t * only where the driver runs transactions concurrently (PostgreSQL).\n\t */\n\tautocommit?(statement: SqliteStatement, concurrency: TransactionConcurrency): Promise<SqliteRow[]>;\n\t/**\n\t * Runs the statements in order, in one write transaction, as one call to the database: all of them commit or none\n\t * do. Resolves with each statement's rows. Present only when the driver can send a batch in one request, which\n\t * saves a round trip per statement against a remote database.\n\t */\n\tbatch?(statements: readonly SqliteStatement[], options?: SqliteBatchOptions): Promise<SqliteRow[][]>;\n\tclose(): Promise<void>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../../src/core/storage/database.ts"],"names":[],"mappings":"","sourcesContent":["import type { StorageDialect } from \"./dialect.js\";\n\nexport type SqliteValue = null | number | bigint | string | Uint8Array;\nexport type SqliteRow = Readonly<Record<string, SqliteValue>>;\n\nexport interface SqliteRunResult {\n\treadonly changes: number;\n}\n\nexport interface SqliteExecutor {\n\texec(sql: string): Promise<void>;\n\trun(sql: string, ...params: readonly SqliteValue[]): Promise<SqliteRunResult>;\n\tget<T extends SqliteRow>(sql: string, ...params: readonly SqliteValue[]): Promise<T | undefined>;\n\tall<T extends SqliteRow>(sql: string, ...params: readonly SqliteValue[]): Promise<T[]>;\n}\n\nexport interface StorageDescriptor {\n\treadonly adapter: string;\n\treadonly location: string;\n}\n\n/** One statement of a batch: SQL with positional `?` parameters. */\nexport interface SqliteStatement {\n\treadonly sql: string;\n\treadonly params: readonly SqliteValue[];\n}\n\n/** How a transaction takes its snapshot or write lock, and whether it may run again. */\nexport interface SqliteTransactionOptions {\n\t/** @internal A consistent read snapshot without a writer lock. The callback must only read. */\n\treadonly readOnly?: boolean;\n\t/**\n\t * How long the transaction keeps waiting for the write lock while it is held and no other connection commits,\n\t * instead of the connection's own lock wait. A writer whose work must not fail because another process stalled\n\t * with the lock held (starved of CPU, paused by garbage collection, stopped by a signal) waits longer: the holder\n\t * still commits or rolls back once it runs again. Adapters without a lock wait of their own ignore it.\n\t */\n\treadonly lockWaitMs?: number;\n\t/**\n\t * Lets a database from `createSqliteDatabase` run the callback again, in a new transaction, when a transient\n\t * failure (`StorageTransientError`) ended the transaction before it committed, so nothing of it was written. Set it\n\t * only for a callback that does nothing but use the transaction handle: anything else it does happens once per run.\n\t * Other databases ignore it.\n\t */\n\treadonly retryTransientFailures?: boolean;\n\t/**\n\t * How the transaction excludes other writers; `{ kind: \"serial\" }` when absent. SQLite runs every kind as\n\t * `BEGIN IMMEDIATE` unless `readOnly` is set; only a driver that runs transactions concurrently (Postgres) tells them apart.\n\t */\n\treadonly concurrency?: TransactionConcurrency;\n\t/**\n\t * @internal The statements the callback makes first, in this order, before it acts on any answer. A driver whose\n\t * transactions are pipelined sends them with the transaction's start, so they cost no round trip of their own, and\n\t * starts the callback once they are answered; each call of the callback that makes the next of them gets its answer.\n\t * Name only reads: a call that differs from the next of them ends the lead, and the answers of the rest go unused,\n\t * though they ran. A write may lead only as the callback's first call, made on every run whatever it reads, such as a\n\t * fenced path's one guarded write: it never runs unused. Other drivers ignore it.\n\t */\n\treadonly leading?: readonly SqliteStatement[];\n\t/**\n\t * @internal The callback makes the `leading` calls, all of them in order, and no other. A pipelined driver then sends\n\t * the commit right behind them, so the whole transaction costs one round trip: a call the callback makes after them\n\t * fails without being sent. When a leading statement fails, the transaction rolls back and the callback's call of\n\t * that statement fails. Other drivers ignore it.\n\t */\n\treadonly leadingOnly?: boolean;\n\t/**\n\t * @internal With `leading`, a `serial` transaction of a domain takes its locks in its first leading statement, a read,\n\t * and only when that read returns a row, instead of with its start: a transaction whose first read finds nothing\n\t * takes no lock. Every statement after it starts once the locks are held, so it sees every transaction that held them\n\t * and committed. A driver that ignores it takes the locks with the start. Other drivers ignore it.\n\t */\n\treadonly lockIfLeadingFinds?: boolean;\n\t/**\n\t * The commit returns before the server has written the transaction to disk, so a crash of the database server just\n\t * after it may lose it, though never part of it, and never a transaction that committed after it without this flag.\n\t * Only for writes whose loss is harmless because a later write repeats them, such as a lease renewal. PostgreSQL\n\t * turns `synchronous_commit` off for the transaction; other drivers ignore it.\n\t */\n\treadonly relaxedDurability?: boolean;\n}\n\n/** How one batch waits for a busy write lock, and whether it goes ahead of the database's queued calls. */\nexport interface SqliteBatchOptions {\n\t/**\n\t * How long a batch that found the database's write lock busy keeps sending again, with growing randomized waits\n\t * between tries. A busy batch wrote nothing, so sending it again is safe. Adapters without such a retry ignore it.\n\t */\n\treadonly lockWaitMs?: number;\n\t/**\n\t * Runs the batch before calls queued on this database that do not set it, and outside any limit the adapter puts on\n\t * concurrent writes: for small writes that must not wait behind others, such as a lease renewal.\n\t */\n\treadonly priority?: boolean;\n}\n\n/**\n * An audited fenced write path. Only `fencedPath(name)` in `fenced-paths.ts` makes one; a plain string is not one. The\n * brand is a string key, not a unique symbol, so the published declarations and the sources stay one type.\n */\nexport type FencedPathId = string & { readonly __atomicFencedPath: true };\n\n/**\n * `serial`: the body runs as if it were the only writer of `domain`, or of the whole database when `domain` is absent:\n * `BEGIN IMMEDIATE` on SQLite, `BEGIN` plus that domain's transaction advisory lock on Postgres. Several prefixes may\n * share one database, so `domain` names the scope in full: a store passes one of its prefixed table names.\n * `fenced`: the body runs under READ COMMITTED and takes the row locks it relies on itself. With `excludesSerial`, it\n * also waits for and excludes `serial` transactions without a domain, as a `serial` transaction with a domain does,\n * for a body whose check a whole-database writer (such as snapshot garbage collection) could otherwise race\n * (`StorageDialect.lockClause`); `audit` names the reviewed path. Identical to `serial` on SQLite.\n */\nexport type TransactionConcurrency =\n\t| { readonly kind: \"serial\"; readonly domain?: string }\n\t| { readonly kind: \"fenced\"; readonly audit: FencedPathId; readonly excludesSerial?: boolean };\n\n/**\n * What a database's listening connection is doing: `listening`, notifications arrive; `connecting`, it is not known yet;\n * `unavailable`, none arrive, and pollers find the work: `pooler` when the endpoint is a transaction pooler (a\n * notification sent through the database did not reach the listening session), `connection-failed` when the listening\n * connection could not be opened or broke.\n */\nexport type StorageListenerState =\n\t| { readonly status: \"listening\" }\n\t| { readonly status: \"connecting\" }\n\t| { readonly status: \"unavailable\"; readonly reason: \"pooler\" | \"connection-failed\" };\n\n/**\n * `notification`: a transaction that ran `notify(channel, payload)` committed. `listening`: the listening connection\n * began listening again after it was unavailable, so notifications sent meanwhile were lost.\n */\nexport type StorageNotificationEvent =\n\t| { readonly kind: \"notification\"; readonly payload: string }\n\t| { readonly kind: \"listening\" };\n\nexport interface StorageNotificationSubscription {\n\t/** Stops delivering events to this listener; idempotent. */\n\tclose(): void;\n}\n\n/**\n * Wake-ups through the database (#5103): Postgres `LISTEN`/`NOTIFY`. A notification is only a hint that a poller would\n * find the same work at its next poll; notifications are lost while the listening connection is down, and through a\n * transaction pooler none arrive, so a store that sends them keeps its poll.\n */\nexport interface StorageNotifications {\n\t/**\n\t * A statement that sends `payload` to the listeners of `channel` once the transaction it runs in commits: run it in the\n\t * transaction of the write it announces. `channel` is a name such as `<prefix>pool_ready`; the database shortens a long\n\t * one the same way for `notify` and `listen`. With `unless`, a read, the notification goes out only when that read,\n\t * made as it goes out, returns no row.\n\t *\n\t * Postgres answers the statement at once and sends the notification in a transaction of its own, right behind the\n\t * `COMMIT` in the same round trip: a notifying commit holds a server-wide lock until it is flushed, which would make\n\t * every other notifying commit wait for it. That transaction may also run when the `COMMIT` rolled back, and commits\n\t * that send the same notification within a few milliseconds of each other share one, sent once they committed. Older\n\t * adapters send it in the transaction and ignore `unless`.\n\t */\n\tnotify(channel: string, payload: string, unless?: SqliteStatement): SqliteStatement;\n\t/**\n\t * Optional. Sends already-committed notifications produced by `notify` together, outside the database's serial\n\t * call queue so post-commit wake-ups never block or wait behind unrelated transactions. Coalesced within the same\n\t * window as in-transaction notifications, and awaited before the database closes.\n\t */\n\tsend?(notices: readonly SqliteStatement[]): Promise<void>;\n\t/** Delivers `channel`'s events to `listener`, on one listening connection the database shares between channels. */\n\tlisten(channel: string, listener: (event: StorageNotificationEvent) => void): StorageNotificationSubscription;\n\t/** Opens the listening connection when it is not open, and resolves with its state once the first attempt settled. */\n\tstate(): Promise<StorageListenerState>;\n}\n\n/**\n * @internal What a driver read of its schema in its open's own round trip (#6560): the rows of the catalog read\n * `readStorageSchemaCatalog` makes (`kind` `relation`, `trigger` or `column`, with `name` and `detail`) and the\n * versions `ledger` records, as rows of `domain` and `version`; `versions` is undefined when the ledger did not exist.\n */\nexport interface StorageOpenedCatalog {\n\treadonly ledger: string;\n\treadonly rows: readonly SqliteRow[];\n\treadonly versions: readonly SqliteRow[] | undefined;\n}\n\nexport interface SqliteDatabase extends SqliteExecutor {\n\t/**\n\t * True when the connection refuses writes, as `openNodeSqliteDatabase(path, { readOnly: true })` sets it, so opening a\n\t * session store skips a cleanup write that would fail. Optional: a read-only connection that leaves it unset still\n\t * opens a session store, whose failed cleanup is ignored.\n\t */\n\treadonly readOnly?: boolean;\n\treadonly descriptor: StorageDescriptor;\n\t/**\n\t * @internal Which database this handle reaches, for comparison only: two handles this process opened answer the same\n\t * string only when a transaction of either reads and writes the very tables the other does (the same adapter, server\n\t * or file, database, schema or namespace). Undefined, or absent, where that cannot be told, as for a database in\n\t * memory: such a handle is the same database as itself alone.\n\t */\n\tdatabaseIdentity?(): string | undefined;\n\t/** @internal Checks whether this embedded connection can prepare a JSONB extraction without issuing a read. */\n\tsupportsJsonbExtract?(): Promise<boolean>;\n\t/** The SQL dialect the database speaks; absent means SQLite. Read it through `dialectOf(database)`. */\n\treadonly dialect?: StorageDialect;\n\t/** Wake-ups through the database; present only on a database that delivers them (Postgres). */\n\treadonly notifications?: StorageNotifications;\n\t/**\n\t * The bytes this process may still write on the file system that holds the database's file (where a link to the file\n\t * points, and where its write-ahead log goes), as a SQLite file database reports them. Absent, or resolving\n\t * undefined, when this process cannot see the database's disk (a server, memory) or the file system does not say.\n\t */\n\tfreeBytes?(): Promise<number | undefined>;\n\t/** @internal Run one short maintenance transaction only if this handle, its writer gate and the database lock\n\t * are immediately available. A backend without no-wait admission leaves this absent. */\n\ttryMaintenance?(callback: (transaction: SqliteExecutor) => Promise<void>): Promise<boolean>;\n\t/** Opens a separate handle on this same database for reads. It has its own call queue; the caller must close it. */\n\topenReader?(): Promise<SqliteDatabase>;\n\t/**\n\t * @internal The schema the driver read when it opened, given once: the first store open answers its schema checks\n\t * from it instead of reading the catalog again. Undefined after the first call, and where the driver read none.\n\t */\n\ttakeOpenedCatalog?(): StorageOpenedCatalog | undefined;\n\ttransaction<T>(\n\t\tcallback: (transaction: SqliteExecutor) => Promise<T>,\n\t\toptions?: SqliteTransactionOptions,\n\t): Promise<T>;\n\t/**\n\t * @internal Runs `statement` by itself as one request that commits on its own, queued in this process as a\n\t * transaction of `concurrency` is: behind the calls such a transaction waits for, and ahead of the calls that wait\n\t * for it. The statement takes on the server whatever locks it needs itself, such as a function that takes the\n\t * domain's advisory locks. A transient failure that applied nothing runs it again. Resolves with its rows. Present\n\t * only where the driver runs transactions concurrently (PostgreSQL).\n\t */\n\tautocommit?(statement: SqliteStatement, concurrency: TransactionConcurrency): Promise<SqliteRow[]>;\n\t/**\n\t * Runs the statements in order, in one write transaction, as one call to the database: all of them commit or none\n\t * do. Resolves with each statement's rows. Present only when the driver can send a batch in one request, which\n\t * saves a round trip per statement against a remote database.\n\t */\n\tbatch?(statements: readonly SqliteStatement[], options?: SqliteBatchOptions): Promise<SqliteRow[][]>;\n\tclose(): Promise<void>;\n}\n"]}
|
|
@@ -56,14 +56,15 @@ declare const FENCED_PATHS: {
|
|
|
56
56
|
/**
|
|
57
57
|
* Intercom's outbox rows and sent-message reservations (`openSqlOutboxStore`, `openSqlSentMessageAuthority`), which
|
|
58
58
|
* left the outbox's one lock domain (#6560). A claim reads its recipient's undelivered rows `FOR UPDATE` in sequence
|
|
59
|
-
* order, then claims them; a claim's renewal, saving report, release and settlement are each one `UPDATE`
|
|
60
|
-
* message id, claimant, token and state;
|
|
61
|
-
* subquery; a reservation, an acceptance and a forget
|
|
62
|
-
* digest. Each decides on the rows it locks, never on an
|
|
63
|
-
* older broker runs on these tables (`excludesSerial`).
|
|
59
|
+
* order, then claims them; a single claim's renewal, saving report, release and settlement are each one `UPDATE`
|
|
60
|
+
* guarded by message id, claimant, token and state; batched `markDelivered`, `renewClaims`, `releaseClaims`, expiry
|
|
61
|
+
* and `releaseClaimsOf` lock their rows in sequence order in a subquery; a reservation, an acceptance and a forget
|
|
62
|
+
* are each one statement on the message's row, guarded by its digest. Each decides on the rows it locks, never on an
|
|
63
|
+
* earlier read. They exclude the database-wide transactions an older broker runs on these tables (`excludesSerial`).
|
|
64
|
+
* A send itself is a serial transaction of its recipient's domain.
|
|
64
65
|
*/
|
|
65
66
|
readonly "intercom-outbox-row": {
|
|
66
|
-
readonly fences: readonly ["outbox rows, FOR UPDATE in sequence order (claim, expiry, releaseClaimsOf), or one row by its own guarded UPDATE", "one sent-message row, by its own guarded INSERT, UPDATE or DELETE"];
|
|
67
|
+
readonly fences: readonly ["outbox rows, FOR UPDATE in sequence order (claim, markDelivered batch, renewClaims, releaseClaims, expiry, releaseClaimsOf), or one row by its own guarded UPDATE", "one sent-message row, by its own guarded INSERT, UPDATE or DELETE"];
|
|
67
68
|
readonly conformance: "a send to one recipient does not wait while another recipient's claim holds its rows; sends to one recipient keep their order and suppress duplicates (#6560)";
|
|
68
69
|
};
|
|
69
70
|
/**
|
|
@@ -65,15 +65,16 @@ const FENCED_PATHS = {
|
|
|
65
65
|
/**
|
|
66
66
|
* Intercom's outbox rows and sent-message reservations (`openSqlOutboxStore`, `openSqlSentMessageAuthority`), which
|
|
67
67
|
* left the outbox's one lock domain (#6560). A claim reads its recipient's undelivered rows `FOR UPDATE` in sequence
|
|
68
|
-
* order, then claims them; a claim's renewal, saving report, release and settlement are each one `UPDATE`
|
|
69
|
-
* message id, claimant, token and state;
|
|
70
|
-
* subquery; a reservation, an acceptance and a forget
|
|
71
|
-
* digest. Each decides on the rows it locks, never on an
|
|
72
|
-
* older broker runs on these tables (`excludesSerial`).
|
|
68
|
+
* order, then claims them; a single claim's renewal, saving report, release and settlement are each one `UPDATE`
|
|
69
|
+
* guarded by message id, claimant, token and state; batched `markDelivered`, `renewClaims`, `releaseClaims`, expiry
|
|
70
|
+
* and `releaseClaimsOf` lock their rows in sequence order in a subquery; a reservation, an acceptance and a forget
|
|
71
|
+
* are each one statement on the message's row, guarded by its digest. Each decides on the rows it locks, never on an
|
|
72
|
+
* earlier read. They exclude the database-wide transactions an older broker runs on these tables (`excludesSerial`).
|
|
73
|
+
* A send itself is a serial transaction of its recipient's domain.
|
|
73
74
|
*/
|
|
74
75
|
"intercom-outbox-row": {
|
|
75
76
|
fences: [
|
|
76
|
-
"outbox rows, FOR UPDATE in sequence order (claim, expiry, releaseClaimsOf), or one row by its own guarded UPDATE",
|
|
77
|
+
"outbox rows, FOR UPDATE in sequence order (claim, markDelivered batch, renewClaims, releaseClaims, expiry, releaseClaimsOf), or one row by its own guarded UPDATE",
|
|
77
78
|
"one sent-message row, by its own guarded INSERT, UPDATE or DELETE",
|
|
78
79
|
],
|
|
79
80
|
conformance: "a send to one recipient does not wait while another recipient's claim holds its rows; sends to one recipient keep their order and suppress duplicates (#6560)",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fenced-paths.js","sourceRoot":"","sources":["../../../src/core/storage/fenced-paths.ts"],"names":[],"mappings":"AAUA;;;GAGG;AACH,MAAM,YAAY,GAAG;IACpB,gIAAgI;IAChI,YAAY,EAAE;QACb,MAAM,EAAE;YACP,8BAA8B;YAC9B,2CAA2C;YAC3C,uCAAuC;SACvC;QACD,WAAW,EAAE,6FAA6F;KAC1G;IACD,oHAAoH;IACpH,gBAAgB,EAAE;QACjB,MAAM,EAAE,CAAC,8BAA8B,EAAE,+BAA+B,EAAE,uBAAuB,CAAC;QAClG,WAAW,EAAE,6FAA6F;KAC1G;IACD,qHAAqH;IACrH,aAAa,EAAE;QACd,MAAM,EAAE;YACP,oHAAoH;YACpH,8BAA8B;YAC9B,+BAA+B;YAC/B,yGAAyG;YACzG,uBAAuB;SACvB;QACD,WAAW,EAAE,8EAA8E;KAC3F;IACD,0EAA0E;IAC1E,eAAe,EAAE;QAChB,MAAM,EAAE;YACP,8BAA8B;YAC9B,+BAA+B;YAC/B,2CAA2C;SAC3C;QACD,WAAW,EAAE,6FAA6F;KAC1G;IACD;;;;;;;OAOG;IACH,gBAAgB,EAAE;QACjB,MAAM,EAAE;YACP,4GAA4G;YAC5G,2EAA2E;SAC3E;QACD,WAAW,EACV,6JAA6J;KAC9J;IACD;;;;;OAKG;IACH,sBAAsB,EAAE;QACvB,MAAM,EAAE,CAAC,gDAAgD,CAAC;QAC1D,WAAW,EAAE,oFAAoF;KACjG;IACD
|
|
1
|
+
{"version":3,"file":"fenced-paths.js","sourceRoot":"","sources":["../../../src/core/storage/fenced-paths.ts"],"names":[],"mappings":"AAUA;;;GAGG;AACH,MAAM,YAAY,GAAG;IACpB,gIAAgI;IAChI,YAAY,EAAE;QACb,MAAM,EAAE;YACP,8BAA8B;YAC9B,2CAA2C;YAC3C,uCAAuC;SACvC;QACD,WAAW,EAAE,6FAA6F;KAC1G;IACD,oHAAoH;IACpH,gBAAgB,EAAE;QACjB,MAAM,EAAE,CAAC,8BAA8B,EAAE,+BAA+B,EAAE,uBAAuB,CAAC;QAClG,WAAW,EAAE,6FAA6F;KAC1G;IACD,qHAAqH;IACrH,aAAa,EAAE;QACd,MAAM,EAAE;YACP,oHAAoH;YACpH,8BAA8B;YAC9B,+BAA+B;YAC/B,yGAAyG;YACzG,uBAAuB;SACvB;QACD,WAAW,EAAE,8EAA8E;KAC3F;IACD,0EAA0E;IAC1E,eAAe,EAAE;QAChB,MAAM,EAAE;YACP,8BAA8B;YAC9B,+BAA+B;YAC/B,2CAA2C;SAC3C;QACD,WAAW,EAAE,6FAA6F;KAC1G;IACD;;;;;;;OAOG;IACH,gBAAgB,EAAE;QACjB,MAAM,EAAE;YACP,4GAA4G;YAC5G,2EAA2E;SAC3E;QACD,WAAW,EACV,6JAA6J;KAC9J;IACD;;;;;OAKG;IACH,sBAAsB,EAAE;QACvB,MAAM,EAAE,CAAC,gDAAgD,CAAC;QAC1D,WAAW,EAAE,oFAAoF;KACjG;IACD;;;;;;;;;OASG;IACH,qBAAqB,EAAE;QACtB,MAAM,EAAE;YACP,mKAAmK;YACnK,mEAAmE;SACnE;QACD,WAAW,EACV,+JAA+J;KAChK;IACD;;;;;;;OAOG;IACH,oBAAoB,EAAE;QACrB,MAAM,EAAE,CAAC,4FAA4F,CAAC;QACtG,WAAW,EACV,6GAA6G;KAC9G;IACD;;;;;;OAMG;IACH,cAAc,EAAE;QACf,MAAM,EAAE,CAAC,8EAA8E,CAAC;QACxF,WAAW,EACV,8HAA8H;KAC/H;IACD;;;OAGG;IACH,aAAa,EAAE;QACd,MAAM,EAAE,CAAC,gDAAgD,CAAC;QAC1D,WAAW,EAAE,iGAAiG;KAC9G;CAC4D,CAAC;AAI/D,yCAAyC;AACzC,MAAM,UAAU,eAAe,CAAC,IAAoB;IACnD,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC;AAED,iGAAiG;AACjG,MAAM,UAAU,UAAU,CAAC,IAAoB;IAC9C,OAAO,IAAoB,CAAC;AAC7B,CAAC","sourcesContent":["import type { FencedPathId } from \"./database.js\";\n\n/** What makes a fenced write path correct without the domain's serial lock. */\nexport interface FencedPathAudit {\n\t/** The rows the path locks, in the order it locks them (the same order on every fenced path, so none deadlock). */\n\treadonly fences: readonly string[];\n\t/** The conformance test that runs the path concurrently on every backend. */\n\treadonly conformance: string;\n}\n\n/**\n * Every audited path that may run a `fenced` transaction. A path is added here, with its fences and its test, in the\n * change that makes it fenced; nothing else can name one.\n */\nconst FENCED_PATHS = {\n\t/** `SqlPoolQueue.claim`: one `UPDATE … WHERE id = (SELECT … FOR UPDATE SKIP LOCKED)`, so claimers never wait on one another. */\n\t\"pool-claim\": {\n\t\tfences: [\n\t\t\t\"root lease row FOR KEY SHARE\",\n\t\t\t\"root run row FOR SHARE, then pool control\",\n\t\t\t\"ready work row FOR UPDATE SKIP LOCKED\",\n\t\t],\n\t\tconformance: \"many hosts claim, commit and complete concurrently: no double claim, no lost settle (#5102)\",\n\t},\n\t/** `SqlPoolQueue.renew`, `extend` and `heartbeat`: the attempt's lease, its claim confirmation and usage report. */\n\t\"pool-heartbeat\": {\n\t\tfences: [\"root lease row FOR KEY SHARE\", \"attempt's work row FOR UPDATE\", \"root usage totals row\"],\n\t\tconformance: \"claim, commit, heartbeat, complete and takeover run concurrently without a deadlock (#5102)\",\n\t},\n\t/** `SqlPoolQueue.commit` of a checkpoint or a session: the event takes the run's next sequence under its run row. */\n\t\"pool-commit\": {\n\t\tfences: [\n\t\t\t\"the database-wide serial lock, shared, only when the checkpoint records worktree snapshots (before every row lock)\",\n\t\t\t\"root lease row FOR KEY SHARE\",\n\t\t\t\"attempt's work row FOR UPDATE\",\n\t\t\t\"root run row FOR UPDATE (FOR SHARE without an event), then pool control and the snapshots' stored blobs\",\n\t\t\t\"root usage totals row\",\n\t\t],\n\t\tconformance: \"32 concurrent writers commit one event per key with a dense sequence (#5102)\",\n\t},\n\t/** `SqlPoolQueue.complete`: the result and the work row's final state. */\n\t\"pool-complete\": {\n\t\tfences: [\n\t\t\t\"root lease row FOR KEY SHARE\",\n\t\t\t\"attempt's work row FOR UPDATE\",\n\t\t\t\"root run row FOR SHARE, then pool control\",\n\t\t],\n\t\tconformance: \"many hosts claim, commit and complete concurrently: no double claim, no lost settle (#5102)\",\n\t},\n\t/**\n\t * Intercom's broker leases (`openSqlBrokerLeaseStore`): `acquire` is one upsert whose guard takes the row only while\n\t * it is free, stale or the acquirer's own, `renew` and `release` one `UPDATE` guarded by holder and fencing token, and\n\t * `renewMany` those updates in (kind, key) order. Each decides on its own row lock, never on an earlier read (#6560).\n\t * On PostgreSQL a first acquisition takes its order from the lease order sequence, which waits for nothing; where\n\t * `atomic storage migrate` has not created it yet, `acquire`'s statement first upserts the acquisition-order counter\n\t * row instead, which no other path locks.\n\t */\n\t\"intercom-lease\": {\n\t\tfences: [\n\t\t\t\"acquire only, without the order sequence: the acquisition-order counter row, by the statement's own upsert\",\n\t\t\t\"each lease row, by its own guarded upsert or UPDATE, in (kind, key) order\",\n\t\t],\n\t\tconformance:\n\t\t\t\"many brokers acquire, renew and release one lease concurrently: never two holders, fencing tokens strictly increase, a stale holder's renewal fails (#6560)\",\n\t},\n\t/**\n\t * Intercom's wake-up hint log (`intercom_wakeups`): a hint is a row inserted once and deleted by its id or its age,\n\t * and no write reads the log to decide what to write, so its writers take no lock domain: the bus's `publish`\n\t * inserts a hint and notifies in one transaction that commits both, an outbox enqueue inserts one inside its own\n\t * transaction, and the bus's poll and pruning delete rows in single statements (#6560).\n\t */\n\t\"intercom-wakeup-hint\": {\n\t\tfences: [\"none: the new hint row only, by its own INSERT\"],\n\t\tconformance: \"delivers each hint published at once from several connections exactly once (#6560)\",\n\t},\n\t/**\n\t * Intercom's outbox rows and sent-message reservations (`openSqlOutboxStore`, `openSqlSentMessageAuthority`), which\n\t * left the outbox's one lock domain (#6560). A claim reads its recipient's undelivered rows `FOR UPDATE` in sequence\n\t * order, then claims them; a single claim's renewal, saving report, release and settlement are each one `UPDATE`\n\t * guarded by message id, claimant, token and state; batched `markDelivered`, `renewClaims`, `releaseClaims`, expiry\n\t * and `releaseClaimsOf` lock their rows in sequence order in a subquery; a reservation, an acceptance and a forget\n\t * are each one statement on the message's row, guarded by its digest. Each decides on the rows it locks, never on an\n\t * earlier read. They exclude the database-wide transactions an older broker runs on these tables (`excludesSerial`).\n\t * A send itself is a serial transaction of its recipient's domain.\n\t */\n\t\"intercom-outbox-row\": {\n\t\tfences: [\n\t\t\t\"outbox rows, FOR UPDATE in sequence order (claim, markDelivered batch, renewClaims, releaseClaims, expiry, releaseClaimsOf), or one row by its own guarded UPDATE\",\n\t\t\t\"one sent-message row, by its own guarded INSERT, UPDATE or DELETE\",\n\t\t],\n\t\tconformance:\n\t\t\t\"a send to one recipient does not wait while another recipient's claim holds its rows; sends to one recipient keep their order and suppress duplicates (#6560)\",\n\t},\n\t/**\n\t * A cleanup's claim of a lapsed fork staging transfer (`cleanupForkStaging`): it reads one lapsed lease row `FOR\n\t * UPDATE SKIP LOCKED`, then takes it over with one `UPDATE` guarded by the lease still being lapsed, so it never waits\n\t * for a live transfer whose writer or publication holds its lease, and two claims never take one transfer. Any lapsed\n\t * transfer may be claimed in any order. The claim names no transfer before it reads, so it takes no lock domain; the\n\t * owner's writes and the cleanup's removals are serial transactions of the transfer's own domain, and each decides on\n\t * the lease row it locks by its token first (#6560).\n\t */\n\t\"fork-staging-claim\": {\n\t\tfences: [\"one lapsed lease row of the staging table, FOR UPDATE SKIP LOCKED, then its guarded UPDATE\"],\n\t\tconformance:\n\t\t\t\"concurrent cleanups take each lapsed transfer over once and never a live one, beside staging clones (#6560)\",\n\t},\n\t/**\n\t * A schema setup that hosts opening a new database at once run once (`setUpStorageOnce`): its first statement tries,\n\t * without waiting, the advisory locks every setup of the same objects takes (the prefix's setup lock, and for a\n\t * domain's migration that domain's lock and the database's, shared, as an earlier build's migration takes them), and\n\t * the setup runs only where it took them all. A process that finds one taken waits outside any transaction until the\n\t * setup is recorded, so the hosts never queue for the lock (#6560).\n\t */\n\t\"schema-setup\": {\n\t\tfences: [\"the setup's advisory locks, all tried by its first statement without waiting\"],\n\t\tconformance:\n\t\t\t\"many hosts open a new database at once: each schema is set up once, every host opens, and none waits in a lock queue (#6560)\",\n\t},\n\t/**\n\t * `SqlRateBuckets.acquire` and `cooldown`: one `UPDATE … RETURNING` (or upsert) of the scope's bucket row, which locks\n\t * no pool row, so it orders after none of them (#4768).\n\t */\n\t\"rate-bucket\": {\n\t\tfences: [\"the scope's rate bucket row, by its own UPDATE\"],\n\t\tconformance: \"many hosts acquire from one rate bucket concurrently and never take more than it allows (#4768)\",\n\t},\n} as const satisfies Readonly<Record<string, FencedPathAudit>>;\n\nexport type FencedPathName = keyof typeof FENCED_PATHS;\n\n/** The audit record of a fenced path. */\nexport function fencedPathAudit(name: FencedPathName): FencedPathAudit {\n\treturn FENCED_PATHS[name];\n}\n\n/** The `FencedPathId` that lets an audited path run `{ kind: \"fenced\", audit }` transactions. */\nexport function fencedPath(name: FencedPathName): FencedPathId {\n\treturn name as FencedPathId;\n}\n"]}
|
|
@@ -42,7 +42,7 @@ function __atomicOnDemandFailed(error, feature) {
|
|
|
42
42
|
return (async () => {
|
|
43
43
|
const root = new URL("../../", import.meta.url);
|
|
44
44
|
const releases = (globalThis[Symbol.for("atomic.in-place-update-release.v1")] ??= new Map());
|
|
45
|
-
const key = `${root.href}#0.10.11-alpha.
|
|
45
|
+
const key = `${root.href}#0.10.11-alpha.4`;
|
|
46
46
|
let release = releases.get(key);
|
|
47
47
|
if (release === undefined) {
|
|
48
48
|
const current = (async () => {
|
|
@@ -70,7 +70,7 @@ function __atomicOnDemandFailed(error, feature) {
|
|
|
70
70
|
} catch {
|
|
71
71
|
// No installation to read, as in a bundle of the package: the release the process runs decides.
|
|
72
72
|
}
|
|
73
|
-
const updatedTo = typeof installed === "string" && installed !== "0.10.11-alpha.
|
|
73
|
+
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;
|
|
74
74
|
if (updatedTo === undefined) throw error;
|
|
75
75
|
const application = typeof running?.name === "string" ? running.name : "atomic";
|
|
76
76
|
const restart = new Error(`${application} was updated to ${updatedTo} while this session was running; restart it to keep using ${feature}.`, {
|
|
@@ -12,9 +12,46 @@ import { sqliteDialect } from "./dialect.js";
|
|
|
12
12
|
const CONNECTION_SOURCE = `
|
|
13
13
|
${EVAL_WORKER_BUILTIN}
|
|
14
14
|
const { parentPort, workerData } = builtin("node:worker_threads");
|
|
15
|
+
const fs = builtin("node:fs");
|
|
15
16
|
process.emitWarning = () => {};
|
|
16
17
|
const { DatabaseSync } = builtin("node:sqlite");
|
|
18
|
+
const { statSync } = fs;
|
|
17
19
|
let database;
|
|
20
|
+
let walPath;
|
|
21
|
+
let lastWalSize = -1n;
|
|
22
|
+
let lastWalMtimeNs = -1n;
|
|
23
|
+
const WAL_SIZE_LIMIT_BYTES = BigInt(workerData.walSizeLimit);
|
|
24
|
+
const CHECKPOINT_AFTER = new Set(["exec", "run", "get", "all", "begin", "sequence"]);
|
|
25
|
+
let holderFd;
|
|
26
|
+
let holderActive = false;
|
|
27
|
+
let writersDir;
|
|
28
|
+
let lastFreed = false;
|
|
29
|
+
let lastHasWaiters;
|
|
30
|
+
let pendingHolderError;
|
|
31
|
+
const HOLDER_FREE = "free " + "0".repeat(15) + "\\n";
|
|
32
|
+
|
|
33
|
+
function hasWriters(dir) {
|
|
34
|
+
if (!fs.existsSync(dir)) return false;
|
|
35
|
+
try {
|
|
36
|
+
return fs.readdirSync(dir).length > 0;
|
|
37
|
+
} catch (error) {
|
|
38
|
+
return error?.code !== "ENOENT";
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function writeHolder(record) {
|
|
43
|
+
if (holderFd === undefined) return;
|
|
44
|
+
try {
|
|
45
|
+
fs.writeSync(holderFd, record, 0, "utf8");
|
|
46
|
+
} catch (error) {
|
|
47
|
+
holderFd = undefined;
|
|
48
|
+
pendingHolderError ??= failure(error);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function holderLine(prefix) {
|
|
53
|
+
return prefix + " " + String(Date.now()).padStart(15, "0") + "\\n";
|
|
54
|
+
}
|
|
18
55
|
|
|
19
56
|
const STANDARD_ERRORS = [Error, TypeError, RangeError, SyntaxError, ReferenceError, EvalError, URIError];
|
|
20
57
|
// Bun stamps every error with where it was thrown; the caller's copy gets its own.
|
|
@@ -91,7 +128,19 @@ function table(rows) {
|
|
|
91
128
|
const handlers = {
|
|
92
129
|
open: (request) => {
|
|
93
130
|
database = new DatabaseSync(request.path, { readOnly: request.readOnly });
|
|
94
|
-
|
|
131
|
+
const location = database.location();
|
|
132
|
+
if (!request.readOnly && typeof location === "string" && location.length > 0) {
|
|
133
|
+
walPath = location + "-wal";
|
|
134
|
+
lastWalSize = -1n;
|
|
135
|
+
lastWalMtimeNs = -1n;
|
|
136
|
+
database.exec(
|
|
137
|
+
"PRAGMA wal_autocheckpoint=" +
|
|
138
|
+
workerData.walAutoCheckpoint +
|
|
139
|
+
"; PRAGMA journal_size_limit=" +
|
|
140
|
+
workerData.walSizeLimit,
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
return location;
|
|
95
144
|
},
|
|
96
145
|
exec: (request) => {
|
|
97
146
|
database.exec(request.sql);
|
|
@@ -129,8 +178,18 @@ const handlers = {
|
|
|
129
178
|
throw error;
|
|
130
179
|
}
|
|
131
180
|
},
|
|
132
|
-
// One non-blocking BEGIN IMMEDIATE, the connection's busy timeout restored before answering
|
|
181
|
+
// One non-blocking BEGIN IMMEDIATE, the connection's busy timeout restored before answering, then the transaction's
|
|
182
|
+
// leading statements, if any, in the same request. When writersDir and checkQueue are given, checks the
|
|
183
|
+
// writers' queue directory first and returns { contended: true } without taking the lock if entries are present
|
|
184
|
+
// (or the directory cannot be listed). When holderFd is given, writes the connection's holder record in place
|
|
185
|
+
// around taking and releasing the lock.
|
|
133
186
|
begin: (request) => {
|
|
187
|
+
if (request.writersDir !== undefined) writersDir = request.writersDir;
|
|
188
|
+
if ("holderFd" in request) holderFd = request.holderFd;
|
|
189
|
+
if (request.checkQueue === true && writersDir !== undefined && hasWriters(writersDir)) {
|
|
190
|
+
return { contended: true };
|
|
191
|
+
}
|
|
192
|
+
writeHolder(holderLine("want"));
|
|
134
193
|
// The file's lock word (see FREE in node-sqlite-file-gate.ts): taken before BEGIN, after waiting here for a
|
|
135
194
|
// statement the calling thread runs meanwhile; settleLock gives it back once the transaction ended.
|
|
136
195
|
if (request.lockState !== undefined) {
|
|
@@ -152,6 +211,7 @@ const handlers = {
|
|
|
152
211
|
try {
|
|
153
212
|
database.exec("BEGIN IMMEDIATE");
|
|
154
213
|
began = true;
|
|
214
|
+
holderActive = true;
|
|
155
215
|
} finally {
|
|
156
216
|
try {
|
|
157
217
|
database.exec("PRAGMA busy_timeout=" + configured);
|
|
@@ -160,7 +220,11 @@ const handlers = {
|
|
|
160
220
|
throw restoreFailure;
|
|
161
221
|
}
|
|
162
222
|
}
|
|
223
|
+
const result = request.statements === undefined ? undefined : lead(request.statements);
|
|
224
|
+
if (inTransaction()) writeHolder(holderLine("held"));
|
|
225
|
+
return result;
|
|
163
226
|
},
|
|
227
|
+
lead: (request) => lead(request.statements),
|
|
164
228
|
// \`repeat\`, then each statement, in one request: the statements the caller would send one at a time, in the same
|
|
165
229
|
// order, each prepared when it is reached. The caller's abort flag is read where the caller would check its signal.
|
|
166
230
|
sequence: (request) => {
|
|
@@ -198,29 +262,65 @@ const handlers = {
|
|
|
198
262
|
},
|
|
199
263
|
close: () => {
|
|
200
264
|
prepared.clear();
|
|
265
|
+
walPath = undefined;
|
|
201
266
|
database?.close();
|
|
267
|
+
database = undefined;
|
|
202
268
|
globalThis.Bun?.gc?.(true);
|
|
203
269
|
},
|
|
204
270
|
};
|
|
205
271
|
|
|
272
|
+
// A write transaction's leading statements, run in order once BEGIN IMMEDIATE took the lock: each answers with its rows
|
|
273
|
+
// and the rows it changed, as all and run would, up to the first that fails; nothing after it runs. The answer says
|
|
274
|
+
// whether the transaction is still open after that failure: SQLite rolls back only the statement for most failures, and
|
|
275
|
+
// the whole transaction for a few (a full disk, an I/O error). A script answers nothing.
|
|
276
|
+
function lead(statements) {
|
|
277
|
+
const answers = [];
|
|
278
|
+
for (const { sql, params, script } of statements) {
|
|
279
|
+
try {
|
|
280
|
+
if (script === true) {
|
|
281
|
+
database.exec(sql);
|
|
282
|
+
answers.push({ columns: [], values: [], changes: 0 });
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
const rows = table(statement(sql).all(...params));
|
|
286
|
+
answers.push({ ...rows, changes: Number(statement("SELECT changes() AS changes").get().changes) });
|
|
287
|
+
} catch (error) {
|
|
288
|
+
return { answers, failure: failure(error), open: database.isTransaction === true };
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return { answers };
|
|
292
|
+
}
|
|
293
|
+
|
|
206
294
|
// The file's lock word while this connection takes or holds the lock: held while a transaction is open on it, given
|
|
207
295
|
// back (and the waiting threads woken) once none is, before the request that ended it is answered.
|
|
208
296
|
let lockState;
|
|
209
297
|
|
|
210
|
-
function
|
|
211
|
-
if (lockState === undefined) return;
|
|
212
|
-
const { state, held } = lockState;
|
|
213
|
-
let open = false;
|
|
298
|
+
function inTransaction() {
|
|
214
299
|
try {
|
|
215
|
-
|
|
216
|
-
} catch {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
300
|
+
return database?.isTransaction === true;
|
|
301
|
+
} catch {
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function settleLock() {
|
|
307
|
+
const open = inTransaction();
|
|
308
|
+
if (lockState !== undefined) {
|
|
309
|
+
const { state, held } = lockState;
|
|
310
|
+
if (open) {
|
|
311
|
+
if (Atomics.compareExchange(state, 0, held - 1, held) === held - 1) Atomics.notify(state, 0);
|
|
312
|
+
} else {
|
|
313
|
+
lockState = undefined;
|
|
314
|
+
if (Atomics.compareExchange(state, 0, held, 0) === held || Atomics.compareExchange(state, 0, held - 1, 0) === held - 1)
|
|
315
|
+
Atomics.notify(state, 0);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
if (holderActive && !open) {
|
|
319
|
+
holderActive = false;
|
|
320
|
+
writeHolder(HOLDER_FREE);
|
|
321
|
+
lastFreed = true;
|
|
322
|
+
lastHasWaiters = writersDir !== undefined && fs.existsSync(writersDir);
|
|
220
323
|
}
|
|
221
|
-
lockState = undefined;
|
|
222
|
-
if (Atomics.compareExchange(state, 0, held, 0) === held || Atomics.compareExchange(state, 0, held - 1, 0) === held - 1)
|
|
223
|
-
Atomics.notify(state, 0);
|
|
224
324
|
}
|
|
225
325
|
|
|
226
326
|
function handle(request) {
|
|
@@ -231,12 +331,49 @@ function handle(request) {
|
|
|
231
331
|
}
|
|
232
332
|
}
|
|
233
333
|
|
|
334
|
+
function maybeCheckpoint(kind) {
|
|
335
|
+
if (walPath === undefined || database === undefined || !CHECKPOINT_AFTER.has(kind)) return;
|
|
336
|
+
try {
|
|
337
|
+
if (database.isTransaction !== false) return;
|
|
338
|
+
const stat = statSync(walPath, { bigint: true, throwIfNoEntry: false });
|
|
339
|
+
if (stat === undefined) {
|
|
340
|
+
lastWalSize = -1n;
|
|
341
|
+
lastWalMtimeNs = -1n;
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
if (stat.size <= WAL_SIZE_LIMIT_BYTES) {
|
|
345
|
+
lastWalSize = stat.size;
|
|
346
|
+
lastWalMtimeNs = stat.mtimeNs;
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
if (stat.size === lastWalSize && stat.mtimeNs === lastWalMtimeNs) return;
|
|
350
|
+
lastWalSize = stat.size;
|
|
351
|
+
lastWalMtimeNs = stat.mtimeNs;
|
|
352
|
+
database.exec("PRAGMA wal_checkpoint(PASSIVE)");
|
|
353
|
+
} catch {}
|
|
354
|
+
}
|
|
355
|
+
|
|
234
356
|
parentPort.on("message", (request) => {
|
|
357
|
+
let answered = false;
|
|
358
|
+
lastFreed = false;
|
|
359
|
+
lastHasWaiters = undefined;
|
|
360
|
+
pendingHolderError = undefined;
|
|
235
361
|
try {
|
|
236
|
-
|
|
362
|
+
const value = handle(request);
|
|
363
|
+
const reply = { id: request.id, value, tx: inTransaction() };
|
|
364
|
+
if (lastFreed) reply.freed = true;
|
|
365
|
+
if (lastHasWaiters !== undefined) reply.hasWaiters = lastHasWaiters;
|
|
366
|
+
if (pendingHolderError !== undefined) reply.holderError = pendingHolderError;
|
|
367
|
+
parentPort.postMessage(reply);
|
|
368
|
+
answered = true;
|
|
237
369
|
} catch (error) {
|
|
238
|
-
|
|
370
|
+
const reply = { id: request.id, failure: failure(error), tx: inTransaction() };
|
|
371
|
+
if (lastFreed) reply.freed = true;
|
|
372
|
+
if (lastHasWaiters !== undefined) reply.hasWaiters = lastHasWaiters;
|
|
373
|
+
if (pendingHolderError !== undefined) reply.holderError = pendingHolderError;
|
|
374
|
+
parentPort.postMessage(reply);
|
|
239
375
|
}
|
|
376
|
+
if (answered) maybeCheckpoint(request.kind);
|
|
240
377
|
});
|
|
241
378
|
`;
|
|
242
379
|
const STANDARD_ERRORS = {
|
|
@@ -310,13 +447,41 @@ const WORKER_CODE_OPTIONS = new Set(["--require", "-r", "--import", "--loader",
|
|
|
310
447
|
let spare;
|
|
311
448
|
/** How many prepared statements a connection keeps for reuse, least recently used first out. */
|
|
312
449
|
export const STATEMENT_CACHE_SIZE = 256;
|
|
450
|
+
/** Safety-net automatic WAL checkpoint threshold in pages on writable file connections. */
|
|
451
|
+
const WAL_AUTO_CHECKPOINT = 10_000;
|
|
452
|
+
/** Target write-ahead log size limit in bytes (4 MiB) for journal truncation and post-response checkpoints. */
|
|
453
|
+
const WAL_SIZE_LIMIT = 4 * 1024 * 1024;
|
|
313
454
|
/** A node:sqlite connection running on its own worker thread. */
|
|
314
455
|
export class ThreadConnection {
|
|
315
456
|
worker;
|
|
316
457
|
waiting = new Map();
|
|
317
458
|
nextId = 1;
|
|
459
|
+
_inTransaction;
|
|
460
|
+
_lastFreed = false;
|
|
461
|
+
_lastHasWaiters;
|
|
462
|
+
_holderError;
|
|
318
463
|
ended;
|
|
319
464
|
closing;
|
|
465
|
+
/** Whether SQLite had an open transaction after the thread's last answer; undefined for older connection threads. */
|
|
466
|
+
get inTransaction() {
|
|
467
|
+
return this._inTransaction;
|
|
468
|
+
}
|
|
469
|
+
/** Consumes any connection-thread holder-record write failure reported since the last check. */
|
|
470
|
+
takeHolderError() {
|
|
471
|
+
const error = this._holderError;
|
|
472
|
+
this._holderError = undefined;
|
|
473
|
+
return error;
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Consumes the release metadata reported by the connection thread when the transaction ended: whether the thread
|
|
477
|
+
* already wrote the `"free"` holder record, and whether the writers'-queue directory existed.
|
|
478
|
+
*/
|
|
479
|
+
takeReleaseState() {
|
|
480
|
+
const state = { freed: this._lastFreed, hasWaiters: this._lastHasWaiters };
|
|
481
|
+
this._lastFreed = false;
|
|
482
|
+
this._lastHasWaiters = undefined;
|
|
483
|
+
return state;
|
|
484
|
+
}
|
|
320
485
|
constructor() {
|
|
321
486
|
// None of the process's own flags: the caller's preloads would run again for every connection, and its
|
|
322
487
|
// `--input-type=module` would make this source a module. Whether node:sqlite is available was settled by the
|
|
@@ -324,7 +489,12 @@ export class ThreadConnection {
|
|
|
324
489
|
this.worker = new Worker(CONNECTION_SOURCE, {
|
|
325
490
|
eval: true,
|
|
326
491
|
execArgv: [],
|
|
327
|
-
workerData: {
|
|
492
|
+
workerData: {
|
|
493
|
+
nowSql: `SELECT ${sqliteDialect.nowMs} AS now`,
|
|
494
|
+
statementCacheSize: STATEMENT_CACHE_SIZE,
|
|
495
|
+
walAutoCheckpoint: WAL_AUTO_CHECKPOINT,
|
|
496
|
+
walSizeLimit: WAL_SIZE_LIMIT,
|
|
497
|
+
},
|
|
328
498
|
});
|
|
329
499
|
this.worker.on("message", (reply) => this.receive(reply));
|
|
330
500
|
this.worker.on("error", (error) => this.end(error));
|
|
@@ -405,6 +575,18 @@ export class ThreadConnection {
|
|
|
405
575
|
return answer.then((value) => rowsOf(value));
|
|
406
576
|
if (request.kind === "read")
|
|
407
577
|
return answer.then((value) => value.map(rowsOf));
|
|
578
|
+
if (request.kind === "lead" || (request.kind === "begin" && request.statements !== undefined))
|
|
579
|
+
return answer.then((value) => {
|
|
580
|
+
if (value === undefined)
|
|
581
|
+
return undefined;
|
|
582
|
+
if (typeof value === "object" && value !== null && "contended" in value)
|
|
583
|
+
return value;
|
|
584
|
+
const { answers, failure, open } = value;
|
|
585
|
+
return {
|
|
586
|
+
answers: answers.map((each) => ({ rows: rowsOf(each), changes: each.changes })),
|
|
587
|
+
...(failure === undefined ? {} : { failure: connectionError(failure), open: open === true }),
|
|
588
|
+
};
|
|
589
|
+
});
|
|
408
590
|
return answer;
|
|
409
591
|
}
|
|
410
592
|
send(request) {
|
|
@@ -445,6 +627,14 @@ export class ThreadConnection {
|
|
|
445
627
|
return this.closing;
|
|
446
628
|
}
|
|
447
629
|
receive(reply) {
|
|
630
|
+
if (typeof reply.tx === "boolean")
|
|
631
|
+
this._inTransaction = reply.tx;
|
|
632
|
+
if (reply.freed === true) {
|
|
633
|
+
this._lastFreed = true;
|
|
634
|
+
this._lastHasWaiters = reply.hasWaiters;
|
|
635
|
+
}
|
|
636
|
+
if (reply.holderError !== undefined)
|
|
637
|
+
this._holderError ??= connectionError(reply.holderError);
|
|
448
638
|
const waiter = this.waiting.get(reply.id);
|
|
449
639
|
if (waiter === undefined)
|
|
450
640
|
return;
|
|
@@ -496,7 +686,7 @@ function __atomicOnDemandFailed(error, feature) {
|
|
|
496
686
|
return (async () => {
|
|
497
687
|
const root = new URL("../../", import.meta.url);
|
|
498
688
|
const releases = (globalThis[Symbol.for("atomic.in-place-update-release.v1")] ??= new Map());
|
|
499
|
-
const key = `${root.href}#0.10.11-alpha.
|
|
689
|
+
const key = `${root.href}#0.10.11-alpha.4`;
|
|
500
690
|
let release = releases.get(key);
|
|
501
691
|
if (release === undefined) {
|
|
502
692
|
const current = (async () => {
|
|
@@ -524,7 +714,7 @@ function __atomicOnDemandFailed(error, feature) {
|
|
|
524
714
|
} catch {
|
|
525
715
|
// No installation to read, as in a bundle of the package: the release the process runs decides.
|
|
526
716
|
}
|
|
527
|
-
const updatedTo = typeof installed === "string" && installed !== "0.10.11-alpha.
|
|
717
|
+
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;
|
|
528
718
|
if (updatedTo === undefined) throw error;
|
|
529
719
|
const application = typeof running?.name === "string" ? running.name : "atomic";
|
|
530
720
|
const restart = new Error(`${application} was updated to ${updatedTo} while this session was running; restart it to keep using ${feature}.`, {
|