@jini-ai/db 0.7.2 → 0.7.3-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +33 -17
- package/dist/core/index.d.ts +1 -2
- package/dist/core/index.js +0 -1
- package/dist/core/pg-types.d.ts +4 -1
- package/dist/core/pg-types.js +1 -1
- package/dist/core/row-values.d.ts +0 -30
- package/dist/core/row-values.js +1 -41
- package/dist/data-modules/data-module.d.ts +260 -4
- package/dist/data-modules/data-module.js +105 -83
- package/dist/data-modules/disk-headroom.js +1 -1
- package/dist/data-modules/index.d.ts +2 -2
- package/dist/data-modules/index.js +2 -2
- package/dist/data-modules/migration-journal.js +6 -6
- package/dist/data-modules/migration-recovery.js +2 -2
- package/dist/data-modules/plugin-identity.js +5 -5
- package/dist/data-modules/plugin-store.d.ts +4 -4
- package/dist/data-modules/restore.js +5 -5
- package/dist/data-modules/snapshot.d.ts +1 -1
- package/dist/data-modules/snapshot.js +3 -3
- package/dist/events/change-set-repo.sql.d.ts +70 -0
- package/dist/events/change-set-repo.sql.js +72 -0
- package/dist/events/index.d.ts +4 -0
- package/dist/events/index.js +3 -0
- package/dist/events/outbox-repo.sql.d.ts +91 -0
- package/dist/events/outbox-repo.sql.js +108 -0
- package/dist/events/repo.rows.d.ts +44 -0
- package/dist/events/repo.rows.js +59 -0
- package/dist/gated-mutations/index.d.ts +3 -0
- package/dist/gated-mutations/index.js +2 -0
- package/dist/gated-mutations/repo.rows.d.ts +19 -0
- package/dist/gated-mutations/repo.rows.js +23 -0
- package/dist/gated-mutations/repo.sql.d.ts +67 -0
- package/dist/gated-mutations/repo.sql.js +71 -0
- package/dist/kernel/dialect.d.ts +53 -31
- package/dist/kernel/dialect.js +14 -36
- package/dist/kernel/index.d.ts +2 -2
- package/dist/kernel/index.js +1 -7
- package/dist/kernel/kernel-core.d.ts +7 -3
- package/dist/kernel/kernel-core.js +75 -66
- package/dist/kernel/ops.d.ts +9 -3
- package/dist/kernel/ops.js +2 -2
- package/dist/kernel/owned-transaction.d.ts +7 -7
- package/dist/kernel/owned-transaction.js +2 -2
- package/dist/kernel/pglite/driver.d.ts +2 -2
- package/dist/kernel/pglite/driver.js +18 -18
- package/dist/kernel/pglite/ops.d.ts +8 -3
- package/dist/kernel/pglite/ops.js +5 -5
- package/dist/kernel/port.d.ts +9 -76
- package/dist/kernel/port.js +1 -10
- package/dist/kernel/postgres/driver.d.ts +4 -2
- package/dist/kernel/postgres/driver.js +17 -17
- package/dist/kernel/postgres/ops.d.ts +5 -3
- package/dist/kernel/postgres/ops.js +3 -3
- package/dist/kernel/postgres/pglite-socket.d.ts +2 -2
- package/dist/kernel/postgres/pglite-socket.js +13 -13
- package/dist/kernel/schema-scope.d.ts +5 -2
- package/dist/kernel/schema-scope.js +1 -1
- package/dist/kernel/schema-shape.d.ts +7 -3
- package/dist/kernel/schema-shape.js +2 -2
- package/dist/kernel/session-lock.d.ts +6 -6
- package/dist/kernel/sqlite/driver.d.ts +16 -8
- package/dist/kernel/sqlite/driver.js +38 -38
- package/dist/kernel/sqlite/index.d.ts +1 -0
- package/dist/kernel/sqlite/index.js +1 -0
- package/dist/kernel/sqlite/ops.d.ts +4 -2
- package/dist/kernel/sqlite/ops.js +3 -3
- package/dist/kernel/sqlite/sqlite-only.d.ts +81 -0
- package/dist/kernel/sqlite/sqlite-only.js +58 -0
- package/dist/kernel/store-copy.d.ts +7 -7
- package/dist/kernel/store-copy.js +22 -14
- package/dist/kernel/typegen.d.ts +5 -3
- package/dist/kernel/typegen.js +1 -1
- package/dist/migrate/checksum.d.ts +3 -1
- package/dist/migrate/checksum.js +1 -1
- package/dist/migrate/index.d.ts +1 -1
- package/dist/migrate/legacy-ledger.d.ts +4 -4
- package/dist/migrate/runner.d.ts +12 -7
- package/dist/migrate/runner.js +7 -6
- package/dist/migrate/step.d.ts +3 -28
- package/dist/migrate/step.js +3 -3
- package/dist/owner-store/index.d.ts +47 -1
- package/dist/owner-store/index.js +28 -1
- package/dist/owner-store/migrations/0000_owner_store.d.ts +3 -2
- package/dist/owner-store/migrations/index.d.ts +1 -1
- package/dist/pglite/owner.d.ts +12 -4
- package/dist/pglite/owner.js +33 -27
- package/dist/pglite/socket-server.d.ts +5 -1
- package/dist/pglite/socket-server.js +5 -4
- package/dist/recovery/deep-link.d.ts +3 -3
- package/dist/recovery/degraded-banners.d.ts +3 -3
- package/dist/recovery/degraded-banners.js +3 -3
- package/dist/recovery/disclosure.d.ts +6 -6
- package/dist/recovery/disclosure.js +6 -6
- package/dist/recovery/evaluate-boot-migration-policy.d.ts +5 -5
- package/dist/recovery/evaluate-boot-migration-policy.js +5 -5
- package/dist/recovery/lookup-adapters.d.ts +1 -1
- package/dist/recovery/lookup-adapters.js +1 -1
- package/dist/recovery/migrate-forward-execute.d.ts +1 -1
- package/dist/recovery/migrate-forward-execute.js +5 -5
- package/dist/recovery/migrate-forward-hooks.d.ts +6 -6
- package/dist/recovery/migrate-forward-hooks.js +5 -5
- package/dist/recovery/operation-lock.d.ts +11 -11
- package/dist/recovery/operation-lock.js +3 -3
- package/dist/recovery/reconcile-interrupted-migration.d.ts +7 -7
- package/dist/recovery/reconcile-interrupted-migration.js +7 -7
- package/dist/recovery/recovery-orchestrator.d.ts +21 -21
- package/dist/recovery/recovery-orchestrator.js +9 -9
- package/dist/recovery/restore-hooks.d.ts +8 -8
- package/dist/recovery/restore-hooks.js +7 -7
- package/dist/recovery/restore-point-create.d.ts +3 -3
- package/dist/secrets-vault/repo.sql.d.ts +3 -3
- package/dist/secrets-vault/repo.sql.js +5 -4
- package/dist/settings/index.d.ts +3 -0
- package/dist/settings/index.js +2 -0
- package/dist/settings/repo.rows.d.ts +117 -0
- package/dist/settings/repo.rows.js +106 -0
- package/dist/settings/repo.sql.d.ts +99 -0
- package/dist/settings/repo.sql.js +219 -0
- package/dist/sqlite/checked-client.d.ts +1 -1
- package/dist/sqlite/checked-state.d.ts +3 -3
- package/dist/sqlite/db-ops.d.ts +1 -1
- package/dist/sqlite/db-ops.js +1 -1
- package/dist/sqlite/index.d.ts +1 -3
- package/dist/sqlite/index.js +2 -0
- package/dist/sqlite/inspect.d.ts +2 -2
- package/dist/sqlite/inspect.js +1 -1
- package/dist/sqlite/open.d.ts +1 -2
- package/dist/sqlite/stopped.d.ts +46 -0
- package/dist/sqlite/stopped.js +86 -0
- package/dist/sqlite/transaction.d.ts +2 -2
- package/dist/tools/database-catalog.d.ts +2 -2
- package/dist/tools/database-catalog.js +13 -3
- package/dist/tools/read-tools.js +70 -59
- package/dist/tools/restore-points.d.ts +1 -1
- package/dist/tools/transfer-tools.d.ts +0 -1
- package/dist/tools/transfer-tools.js +5 -4
- package/dist/transfer/copy-engine.js +10 -10
- package/dist/transfer/copy-order.d.ts +47 -0
- package/dist/transfer/copy-order.js +103 -0
- package/dist/transfer/index.d.ts +1 -0
- package/dist/transfer/index.js +1 -0
- package/dist/transfer/internal-ddl.d.ts +28 -6
- package/dist/transfer/internal-ddl.js +15 -15
- package/dist/transfer/postgres-ddl.js +6 -6
- package/dist/transfer/sqlite-source.d.ts +2 -3
- package/dist/transfer/sqlite-source.js +1 -1
- package/dist/verified-origin/index.d.ts +4 -0
- package/dist/verified-origin/index.js +3 -0
- package/dist/verified-origin/register.d.ts +43 -0
- package/dist/verified-origin/register.js +51 -0
- package/dist/verified-origin/repo.rows.d.ts +42 -0
- package/dist/verified-origin/repo.rows.js +47 -0
- package/dist/verified-origin/repo.sql.d.ts +67 -0
- package/dist/verified-origin/repo.sql.js +34 -0
- package/package.json +39 -12
- package/dist/sqlite/restore-types.d.ts +0 -46
- package/dist/sqlite/restore-types.js +0 -2
- package/dist/sqlite/sync-types.d.ts +0 -34
- package/dist/sqlite/sync-types.js +0 -2
- package/dist/sqlite/types.d.ts +0 -37
- package/dist/sqlite/types.js +0 -8
package/dist/pglite/owner.d.ts
CHANGED
|
@@ -21,7 +21,9 @@ import type { PgliteClass } from "./types.js";
|
|
|
21
21
|
/** The low-memory settings added to `PGlite.defaultStartParams` (`initialMemory` stays at its 128 MB minimum). */
|
|
22
22
|
export declare const PGLITE_LOW_MEMORY_SETTINGS: readonly string[];
|
|
23
23
|
/** `PGlite.defaultStartParams` plus {@link PGLITE_LOW_MEMORY_SETTINGS}, for the consumer's `PGlite` class. */
|
|
24
|
-
export declare function pgliteLowMemoryStartParams(pglite
|
|
24
|
+
export declare function pgliteLowMemoryStartParams({ pglite }: {
|
|
25
|
+
pglite: Pick<PgliteClass, "defaultStartParams">;
|
|
26
|
+
}, _optional?: Record<string, never>): string[];
|
|
25
27
|
export interface PgliteOwner {
|
|
26
28
|
readonly socketPath: string;
|
|
27
29
|
/** Directory to give a Postgres client as `host`. */
|
|
@@ -99,7 +101,9 @@ export interface OwnerPorts {
|
|
|
99
101
|
* The owner THIS process runs for `dataDir`, if any: how an in-process caller (duplicating the site
|
|
100
102
|
* it serves) reaches {@link PgliteOwner.runExclusive} without a second open.
|
|
101
103
|
*/
|
|
102
|
-
export declare function runningPgliteOwner(dataDir
|
|
104
|
+
export declare function runningPgliteOwner({ dataDir }: {
|
|
105
|
+
dataDir: string;
|
|
106
|
+
}, _optional?: Record<string, never>): PgliteOwner | undefined;
|
|
103
107
|
/**
|
|
104
108
|
* Where the owner of `dataDir` puts its socket: `~/.<runDirName>/run/<key>/`, or
|
|
105
109
|
* `/tmp/<runDirName>-<uid>/<key>/` when the home path is too long for a socket.
|
|
@@ -115,7 +119,9 @@ export declare function defaultPgliteSocketDir(required: {
|
|
|
115
119
|
proc?: OwnerProcessPort;
|
|
116
120
|
}): string;
|
|
117
121
|
/** Throws unless `socketPath` fits in `sun_path`. */
|
|
118
|
-
export declare function assertSocketPathFits(socketPath
|
|
122
|
+
export declare function assertSocketPathFits({ socketPath }: {
|
|
123
|
+
socketPath: string;
|
|
124
|
+
}, _optional?: Record<string, never>): void;
|
|
119
125
|
/**
|
|
120
126
|
* Creates `dir` (and missing parents) owner-only, and refuses one that is a symlink or belongs to
|
|
121
127
|
* another user (a pre-created `/tmp/<app>-<uid>` would otherwise let that user reach the socket).
|
|
@@ -124,7 +130,9 @@ export declare function assertSocketPathFits(socketPath: string): void;
|
|
|
124
130
|
* 0700 non-symlink directory of ours (else its owner could swap `dir` for their own). Default:
|
|
125
131
|
* on when the parent sits directly in `/tmp` (the `/tmp/<app>-<uid>` fallback).
|
|
126
132
|
*/
|
|
127
|
-
export declare function ensurePrivateDir(dir:
|
|
133
|
+
export declare function ensurePrivateDir({ dir }: {
|
|
134
|
+
dir: string;
|
|
135
|
+
}, optional?: {
|
|
128
136
|
privateParent?: boolean;
|
|
129
137
|
} & OwnerPorts): void;
|
|
130
138
|
/**
|
package/dist/pglite/owner.js
CHANGED
|
@@ -36,7 +36,7 @@ export const PGLITE_LOW_MEMORY_SETTINGS = [
|
|
|
36
36
|
"max_connections=1",
|
|
37
37
|
];
|
|
38
38
|
/** `PGlite.defaultStartParams` plus {@link PGLITE_LOW_MEMORY_SETTINGS}, for the consumer's `PGlite` class. */
|
|
39
|
-
export function pgliteLowMemoryStartParams(pglite) {
|
|
39
|
+
export function pgliteLowMemoryStartParams({ pglite }, _optional = {}) {
|
|
40
40
|
return [...pglite.defaultStartParams, ...PGLITE_LOW_MEMORY_SETTINGS];
|
|
41
41
|
}
|
|
42
42
|
/** `sun_path` is 104 bytes on macOS including the terminating NUL. */
|
|
@@ -88,7 +88,7 @@ const runningOwners = new Map();
|
|
|
88
88
|
* The owner THIS process runs for `dataDir`, if any: how an in-process caller (duplicating the site
|
|
89
89
|
* it serves) reaches {@link PgliteOwner.runExclusive} without a second open.
|
|
90
90
|
*/
|
|
91
|
-
export function runningPgliteOwner(dataDir) {
|
|
91
|
+
export function runningPgliteOwner({ dataDir }, _optional = {}) {
|
|
92
92
|
return runningOwners.get(resolve(dataDir));
|
|
93
93
|
}
|
|
94
94
|
/** 8 hex characters naming a data dir, stable across runs so clients can find its socket. */
|
|
@@ -121,7 +121,7 @@ function tmpSocketParent(runDirName, proc) {
|
|
|
121
121
|
return join("/tmp", `${runDirName}-${proc.uid() ?? "user"}`);
|
|
122
122
|
}
|
|
123
123
|
/** Throws unless `socketPath` fits in `sun_path`. */
|
|
124
|
-
export function assertSocketPathFits(socketPath) {
|
|
124
|
+
export function assertSocketPathFits({ socketPath }, _optional = {}) {
|
|
125
125
|
const bytes = Buffer.byteLength(socketPath);
|
|
126
126
|
if (bytes > MAX_SOCKET_PATH_BYTES) {
|
|
127
127
|
throw new Error(`socket path is ${bytes} bytes; Unix sockets allow at most ${MAX_SOCKET_PATH_BYTES}: ${socketPath}`);
|
|
@@ -139,7 +139,7 @@ function ownedByOtherUser(uid, proc) {
|
|
|
139
139
|
* 0700 non-symlink directory of ours (else its owner could swap `dir` for their own). Default:
|
|
140
140
|
* on when the parent sits directly in `/tmp` (the `/tmp/<app>-<uid>` fallback).
|
|
141
141
|
*/
|
|
142
|
-
export function ensurePrivateDir(dir, optional = {}) {
|
|
142
|
+
export function ensurePrivateDir({ dir }, optional = {}) {
|
|
143
143
|
const io = ownerIo(optional);
|
|
144
144
|
const parent = dirname(resolve(dir));
|
|
145
145
|
if (optional.privateParent ?? dirname(parent) === "/tmp") {
|
|
@@ -323,28 +323,9 @@ export function acquireOwnerLock(required, optional = {}) {
|
|
|
323
323
|
}
|
|
324
324
|
throw new Error(`could not take the PGlite owner lock ${lockPath}`);
|
|
325
325
|
}
|
|
326
|
-
/**
|
|
327
|
-
|
|
328
|
-
* private Unix socket.
|
|
329
|
-
*
|
|
330
|
-
* @param required.PGlite the consumer's `PGlite` class (pin `@electric-sql/pglite` 0.5.8: the socket
|
|
331
|
-
* server's ReadyForQuery filter is written against it).
|
|
332
|
-
* @param required.lockFileName the pid lock file kept inside `dataDir` (e.g. `myapp-owner.pid`).
|
|
333
|
-
* @param required.runDirName names the default socket dir; see {@link defaultPgliteSocketDir}.
|
|
334
|
-
* @param optional.socketDir default {@link defaultPgliteSocketDir}.
|
|
335
|
-
* @param optional.idleInTransactionTimeoutMs default 30 s; see `PgliteSocketServer`.
|
|
336
|
-
* @param optional.fs / optional.proc see {@link OwnerPorts}; default Node's own.
|
|
337
|
-
* @throws PgliteOwnerLockedError when another live owner holds `dataDir`.
|
|
338
|
-
*/
|
|
339
|
-
export async function startPgliteOwner(required, optional = {}) {
|
|
340
|
-
const io = ownerIo(optional);
|
|
326
|
+
/** Start the PGlite database and its owner-only socket server; any failure tears down everything it opened. */
|
|
327
|
+
async function bootOwnerServer({ required, optional, io, dataDir, socketDir, socketPath, releaseLock }) {
|
|
341
328
|
const { fs } = io;
|
|
342
|
-
const dataDir = resolve(required.dataDir);
|
|
343
|
-
const socketDir = optional.socketDir ?? defaultPgliteSocketDir({ dataDir, runDirName: required.runDirName }, io);
|
|
344
|
-
const socketPath = join(socketDir, PGLITE_SOCKET_FILE);
|
|
345
|
-
assertSocketPathFits(socketPath);
|
|
346
|
-
fs.mkdirSync(dataDir, { recursive: true, mode: 0o700 });
|
|
347
|
-
const releaseLock = acquireOwnerLock({ dataDir, lockFileName: required.lockFileName }, io);
|
|
348
329
|
let db;
|
|
349
330
|
let server;
|
|
350
331
|
// WASM initialization can await native work with no referenced Node handle. Until the socket
|
|
@@ -352,11 +333,11 @@ export async function startPgliteOwner(required, optional = {}) {
|
|
|
352
333
|
// Release on both success and failure, so an idle or refused boot retains no extra timer.
|
|
353
334
|
const startupRef = setInterval(() => { }, 1_000);
|
|
354
335
|
try {
|
|
355
|
-
ensurePrivateDir(socketDir, io);
|
|
336
|
+
ensurePrivateDir({ dir: socketDir }, io);
|
|
356
337
|
// We hold the lock, so a socket file here was left by a dead owner.
|
|
357
338
|
if (fs.existsSync(socketPath))
|
|
358
339
|
fs.unlinkSync(socketPath);
|
|
359
|
-
db = await required.PGlite.create({ dataDir, startParams: pgliteLowMemoryStartParams(required.PGlite) });
|
|
340
|
+
db = await required.PGlite.create({ dataDir, startParams: pgliteLowMemoryStartParams({ pglite: required.PGlite }) });
|
|
360
341
|
server = new PgliteSocketServer({
|
|
361
342
|
db,
|
|
362
343
|
path: socketPath,
|
|
@@ -379,6 +360,31 @@ export async function startPgliteOwner(required, optional = {}) {
|
|
|
379
360
|
finally {
|
|
380
361
|
clearInterval(startupRef);
|
|
381
362
|
}
|
|
363
|
+
return { db, server };
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Opens `dataDir` (creating it on first use — initdb takes several seconds) and serves it on a
|
|
367
|
+
* private Unix socket.
|
|
368
|
+
*
|
|
369
|
+
* @param required.PGlite the consumer's `PGlite` class (pin `@electric-sql/pglite` 0.5.8: the socket
|
|
370
|
+
* server's ReadyForQuery filter is written against it).
|
|
371
|
+
* @param required.lockFileName the pid lock file kept inside `dataDir` (e.g. `myapp-owner.pid`).
|
|
372
|
+
* @param required.runDirName names the default socket dir; see {@link defaultPgliteSocketDir}.
|
|
373
|
+
* @param optional.socketDir default {@link defaultPgliteSocketDir}.
|
|
374
|
+
* @param optional.idleInTransactionTimeoutMs default 30 s; see `PgliteSocketServer`.
|
|
375
|
+
* @param optional.fs / optional.proc see {@link OwnerPorts}; default Node's own.
|
|
376
|
+
* @throws PgliteOwnerLockedError when another live owner holds `dataDir`.
|
|
377
|
+
*/
|
|
378
|
+
export async function startPgliteOwner(required, optional = {}) {
|
|
379
|
+
const io = ownerIo(optional);
|
|
380
|
+
const { fs } = io;
|
|
381
|
+
const dataDir = resolve(required.dataDir);
|
|
382
|
+
const socketDir = optional.socketDir ?? defaultPgliteSocketDir({ dataDir, runDirName: required.runDirName }, io);
|
|
383
|
+
const socketPath = join(socketDir, PGLITE_SOCKET_FILE);
|
|
384
|
+
assertSocketPathFits({ socketPath });
|
|
385
|
+
fs.mkdirSync(dataDir, { recursive: true, mode: 0o700 });
|
|
386
|
+
const releaseLock = acquireOwnerLock({ dataDir, lockFileName: required.lockFileName }, io);
|
|
387
|
+
const { db, server } = await bootOwnerServer({ required, optional, io, dataDir, socketDir, socketPath, releaseLock });
|
|
382
388
|
const serving = server;
|
|
383
389
|
const open = db;
|
|
384
390
|
let closing;
|
|
@@ -38,7 +38,11 @@ export interface PgliteSocketServerOptions {
|
|
|
38
38
|
createServer?: SocketServerFactory | undefined;
|
|
39
39
|
}
|
|
40
40
|
/** A Postgres ErrorResponse frame. */
|
|
41
|
-
export declare function errorResponseFrame(severity
|
|
41
|
+
export declare function errorResponseFrame({ severity, code, message }: {
|
|
42
|
+
severity: "ERROR" | "FATAL";
|
|
43
|
+
code: string;
|
|
44
|
+
message: string;
|
|
45
|
+
}, _optional?: Record<string, never>): Buffer;
|
|
42
46
|
export declare class PgliteSocketServer {
|
|
43
47
|
private readonly options;
|
|
44
48
|
private server;
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* package root for every change from upstream.
|
|
6
6
|
*/
|
|
7
7
|
import { createServer as createNetServer } from "node:net";
|
|
8
|
+
import { describeErrorForLog } from "@jini-ai/core/model-facing-tool-errors";
|
|
8
9
|
/**
|
|
9
10
|
* @file One PGlite served to several processes over a Unix socket, speaking the Postgres wire
|
|
10
11
|
* protocol.
|
|
@@ -48,7 +49,7 @@ function assertClientFrameSize({ size, minimum }, _options = {}) {
|
|
|
48
49
|
throw new Error("Invalid client frame length");
|
|
49
50
|
}
|
|
50
51
|
/** A Postgres ErrorResponse frame. */
|
|
51
|
-
export function errorResponseFrame(severity, code, message) {
|
|
52
|
+
export function errorResponseFrame({ severity, code, message }, _optional = {}) {
|
|
52
53
|
const field = (tag, value) => Buffer.concat([Buffer.from(tag), Buffer.from(`${value}\0`)]);
|
|
53
54
|
const body = Buffer.concat([field("S", severity), field("V", severity), field("C", code), field("M", message), Buffer.from([0])]);
|
|
54
55
|
const head = Buffer.alloc(5);
|
|
@@ -326,7 +327,7 @@ export class PgliteSocketServer {
|
|
|
326
327
|
options.log?.(`connection #${id} idle in transaction; rolling back`);
|
|
327
328
|
this.connections
|
|
328
329
|
.get(id)
|
|
329
|
-
?.terminate(errorResponseFrame("FATAL", "25P03", "terminating connection due to idle-in-transaction timeout"));
|
|
330
|
+
?.terminate(errorResponseFrame({ severity: "FATAL", code: "25P03", message: "terminating connection due to idle-in-transaction timeout" }));
|
|
330
331
|
});
|
|
331
332
|
}
|
|
332
333
|
get path() {
|
|
@@ -345,7 +346,7 @@ export class PgliteSocketServer {
|
|
|
345
346
|
resolve();
|
|
346
347
|
});
|
|
347
348
|
});
|
|
348
|
-
server.on("error", (error) => this.options.log?.(`socket server error: ${error
|
|
349
|
+
server.on("error", (error) => this.options.log?.(`socket server error: ${describeErrorForLog({ err: error })}`));
|
|
349
350
|
}
|
|
350
351
|
/**
|
|
351
352
|
* Runs `fn` with the database to itself: after any open client transaction ends, before the next
|
|
@@ -385,7 +386,7 @@ export class PgliteSocketServer {
|
|
|
385
386
|
}
|
|
386
387
|
accept(socket) {
|
|
387
388
|
if (this.server === null || this.connections.size >= this.maxConnections) {
|
|
388
|
-
socket.write(errorResponseFrame("FATAL", "53300", "sorry, too many clients already"));
|
|
389
|
+
socket.write(errorResponseFrame({ severity: "FATAL", code: "53300", message: "sorry, too many clients already" }));
|
|
389
390
|
endSocket(socket, false);
|
|
390
391
|
return;
|
|
391
392
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { PrincipalKind } from "./recovery-orchestrator.js";
|
|
2
2
|
/**
|
|
3
|
-
* @file
|
|
4
|
-
*
|
|
3
|
+
* @file Deep-link envelope resolution.
|
|
4
|
+
*
|
|
5
5
|
*
|
|
6
6
|
* Purpose:
|
|
7
7
|
* `resolveDeepLinkContext` never trusts a `DatabaseContextEnvelope`'s carried values — every id is
|
|
8
8
|
* independently re-looked-up server-side on arrival (INV-04). A stale, pruned, or outright forged
|
|
9
9
|
* `restorePointId` (even one that is syntactically plausible, e.g. ULID-shaped) resolves to
|
|
10
10
|
* `{found:false}` rather than proceeding with the envelope's own claimed value — the envelope
|
|
11
|
-
* carries display continuity only, never authority (
|
|
11
|
+
* carries display continuity only, never authority (the same rule, restated for this
|
|
12
12
|
* domain's receiving side).
|
|
13
13
|
*
|
|
14
14
|
* How it relates to the project:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @file
|
|
3
|
-
*
|
|
2
|
+
* @file Degraded-state banner precedence resolver (behavior.spec.md).
|
|
3
|
+
*
|
|
4
4
|
*
|
|
5
5
|
* Purpose:
|
|
6
6
|
* Fixed precedence, highest to lowest: `migration.interrupted` > `PENDING_MIGRATION` >
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* this function does not own.
|
|
11
11
|
*
|
|
12
12
|
* `PENDING_MIGRATION`'s action always deep-links to the Database Timeline's own migration ceremony, never a
|
|
13
|
-
* Recovery restore-flow action
|
|
13
|
+
* Recovery restore-flow action — restoring to an older snapshot does
|
|
14
14
|
* not resolve schema drift against the current runtime.
|
|
15
15
|
*/
|
|
16
16
|
export type DegradedBannerKind = "migration-interrupted" | "pending-migration" | "operation-in-flight" | "cost-unavailable" | "watermark-baseline-unavailable";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @file
|
|
3
|
-
*
|
|
2
|
+
* @file Degraded-state banner precedence resolver (behavior.spec.md).
|
|
3
|
+
*
|
|
4
4
|
*
|
|
5
5
|
* Purpose:
|
|
6
6
|
* Fixed precedence, highest to lowest: `migration.interrupted` > `PENDING_MIGRATION` >
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* this function does not own.
|
|
11
11
|
*
|
|
12
12
|
* `PENDING_MIGRATION`'s action always deep-links to the Database Timeline's own migration ceremony, never a
|
|
13
|
-
* Recovery restore-flow action
|
|
13
|
+
* Recovery restore-flow action — restoring to an older snapshot does
|
|
14
14
|
* not resolve schema drift against the current runtime.
|
|
15
15
|
*/
|
|
16
16
|
/**
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @file
|
|
3
|
-
* computation (
|
|
2
|
+
* @file The discarded-write-window disclosure
|
|
3
|
+
* computation (Step 2 of the restore ceremony).
|
|
4
4
|
*
|
|
5
5
|
* Purpose:
|
|
6
6
|
* Never asserts a numeric count for a category outside the versioned `coveredCategories` constant
|
|
7
|
-
*
|
|
7
|
+
* — a category not yet migrated onto the watermark chokepoint (the evolving
|
|
8
8
|
* write-path inventory) simply never appears in the output, even if a caller-supplied count source
|
|
9
9
|
* happens to have data for it (AC-17's `entries` case: Collections' write path is not yet
|
|
10
10
|
* watermark-stamped, so it must never be disclosed as covered here regardless of what any count
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
* watermark baseline itself could not be established, whether because `content.db` was entirely
|
|
13
13
|
* unreadable (AC-19/EC-08) or because the specific restore point predates the
|
|
14
14
|
* `watermarkAtCapture` column (EC-02) — a null baseline must never be silently treated as a
|
|
15
|
-
* zero-baseline
|
|
15
|
+
* zero-baseline.
|
|
16
16
|
*
|
|
17
|
-
* `result.partial` is always `true` — this disclosure is never claimed exhaustive (
|
|
17
|
+
* `result.partial` is always `true` — this disclosure is never claimed exhaustive (the
|
|
18
18
|
* own "no exhaustiveness claim until the automated write-path inventory runs clean" carried
|
|
19
|
-
* verbatim into this domain
|
|
19
|
+
* verbatim into this domain).
|
|
20
20
|
*
|
|
21
21
|
* How it relates to the project:
|
|
22
22
|
* `coveredCategories` is the single, auditable edit point ADR-PIPE-019's File Map names this file
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @file
|
|
3
|
-
* computation (
|
|
2
|
+
* @file The discarded-write-window disclosure
|
|
3
|
+
* computation (Step 2 of the restore ceremony).
|
|
4
4
|
*
|
|
5
5
|
* Purpose:
|
|
6
6
|
* Never asserts a numeric count for a category outside the versioned `coveredCategories` constant
|
|
7
|
-
*
|
|
7
|
+
* — a category not yet migrated onto the watermark chokepoint (the evolving
|
|
8
8
|
* write-path inventory) simply never appears in the output, even if a caller-supplied count source
|
|
9
9
|
* happens to have data for it (AC-17's `entries` case: Collections' write path is not yet
|
|
10
10
|
* watermark-stamped, so it must never be disclosed as covered here regardless of what any count
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
* watermark baseline itself could not be established, whether because `content.db` was entirely
|
|
13
13
|
* unreadable (AC-19/EC-08) or because the specific restore point predates the
|
|
14
14
|
* `watermarkAtCapture` column (EC-02) — a null baseline must never be silently treated as a
|
|
15
|
-
* zero-baseline
|
|
15
|
+
* zero-baseline.
|
|
16
16
|
*
|
|
17
|
-
* `result.partial` is always `true` — this disclosure is never claimed exhaustive (
|
|
17
|
+
* `result.partial` is always `true` — this disclosure is never claimed exhaustive (the
|
|
18
18
|
* own "no exhaustiveness claim until the automated write-path inventory runs clean" carried
|
|
19
|
-
* verbatim into this domain
|
|
19
|
+
* verbatim into this domain).
|
|
20
20
|
*
|
|
21
21
|
* How it relates to the project:
|
|
22
22
|
* `coveredCategories` is the single, auditable edit point ADR-PIPE-019's File Map names this file
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { MigrationRunsRepoPort, SiteStatusPort } from "./reconcile-interrupted-migration.js";
|
|
2
2
|
/**
|
|
3
|
-
* @file
|
|
4
|
-
* migrate policy (
|
|
3
|
+
* @file Cost-gated `SERVE_SITE` auto-
|
|
4
|
+
* migrate policy (amends the original policy).
|
|
5
5
|
*
|
|
6
6
|
* Purpose:
|
|
7
7
|
* Routes serve-time migration through the same snapshot-anchored ceremony as an interactive
|
|
@@ -13,16 +13,16 @@ import type { MigrationRunsRepoPort, SiteStatusPort } from "./reconcile-interrup
|
|
|
13
13
|
*
|
|
14
14
|
* How it relates to the project:
|
|
15
15
|
* Must only ever run AFTER `reconcile-interrupted-migration.ts`'s `reconcileInterruptedMigrationOnBoot`
|
|
16
|
-
* has resolved for this boot cycle
|
|
16
|
+
* has resolved for this boot cycle — the boot composition root's own call-site
|
|
17
17
|
* ordering is what actually enforces that sequencing; this function additionally refuses,
|
|
18
|
-
* defense-in-depth, if it ever observes a still-non-terminal `migration_runs` row itself
|
|
18
|
+
* defense-in-depth, if it ever observes a still-non-terminal `migration_runs` row itself,
|
|
19
19
|
* so an out-of-order wiring bug fails closed rather than silently auto-migrating over an unresolved
|
|
20
20
|
* crash.
|
|
21
21
|
*
|
|
22
22
|
* Architectural role:
|
|
23
23
|
* `features/database` domain logic. Depends only on the injected ports.
|
|
24
24
|
*/
|
|
25
|
-
/** Thrown when a non-terminal `migration_runs` row still exists — defense-in-depth against out-of-order boot wiring
|
|
25
|
+
/** Thrown when a non-terminal `migration_runs` row still exists — defense-in-depth against out-of-order boot wiring. */
|
|
26
26
|
export declare class UnresolvedInterruptedMigrationError extends Error {
|
|
27
27
|
constructor(message: string);
|
|
28
28
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @file
|
|
3
|
-
* migrate policy (
|
|
2
|
+
* @file Cost-gated `SERVE_SITE` auto-
|
|
3
|
+
* migrate policy (amends the original policy).
|
|
4
4
|
*
|
|
5
5
|
* Purpose:
|
|
6
6
|
* Routes serve-time migration through the same snapshot-anchored ceremony as an interactive
|
|
@@ -12,16 +12,16 @@
|
|
|
12
12
|
*
|
|
13
13
|
* How it relates to the project:
|
|
14
14
|
* Must only ever run AFTER `reconcile-interrupted-migration.ts`'s `reconcileInterruptedMigrationOnBoot`
|
|
15
|
-
* has resolved for this boot cycle
|
|
15
|
+
* has resolved for this boot cycle — the boot composition root's own call-site
|
|
16
16
|
* ordering is what actually enforces that sequencing; this function additionally refuses,
|
|
17
|
-
* defense-in-depth, if it ever observes a still-non-terminal `migration_runs` row itself
|
|
17
|
+
* defense-in-depth, if it ever observes a still-non-terminal `migration_runs` row itself,
|
|
18
18
|
* so an out-of-order wiring bug fails closed rather than silently auto-migrating over an unresolved
|
|
19
19
|
* crash.
|
|
20
20
|
*
|
|
21
21
|
* Architectural role:
|
|
22
22
|
* `features/database` domain logic. Depends only on the injected ports.
|
|
23
23
|
*/
|
|
24
|
-
/** Thrown when a non-terminal `migration_runs` row still exists — defense-in-depth against out-of-order boot wiring
|
|
24
|
+
/** Thrown when a non-terminal `migration_runs` row still exists — defense-in-depth against out-of-order boot wiring. */
|
|
25
25
|
export class UnresolvedInterruptedMigrationError extends Error {
|
|
26
26
|
constructor(message) {
|
|
27
27
|
super(message);
|
|
@@ -13,7 +13,7 @@ import type { RestorePointListPort } from "../tools/restore-points.js";
|
|
|
13
13
|
* per-category write-count tracker exists anywhere in this codebase yet (a real one would need to
|
|
14
14
|
* diff `database_write_watermark` against each covered write path's own row-level attribution,
|
|
15
15
|
* which is future work, not something safe to fabricate). Reporting `available: true` with a
|
|
16
|
-
* stubbed-zero count would be the exact false-reassurance failure mode
|
|
16
|
+
* stubbed-zero count would be the exact false-reassurance failure mode the original design's Failure modes
|
|
17
17
|
* section names as this feature's highest-stakes UX risk — this class deliberately does not do
|
|
18
18
|
* that.
|
|
19
19
|
*/
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* per-category write-count tracker exists anywhere in this codebase yet (a real one would need to
|
|
11
11
|
* diff `database_write_watermark` against each covered write path's own row-level attribution,
|
|
12
12
|
* which is future work, not something safe to fabricate). Reporting `available: true` with a
|
|
13
|
-
* stubbed-zero count would be the exact false-reassurance failure mode
|
|
13
|
+
* stubbed-zero count would be the exact false-reassurance failure mode the original design's Failure modes
|
|
14
14
|
* section names as this feature's highest-stakes UX risk — this class deliberately does not do
|
|
15
15
|
* that.
|
|
16
16
|
*/
|
|
@@ -44,7 +44,7 @@ export declare class RestorePointUnavailableError extends Error {
|
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
46
46
|
* Orchestrates a forward-migrate execution: refuses `costClass: 'unavailable'` outright, acquires
|
|
47
|
-
* the shared cross-domain lock
|
|
47
|
+
* the shared cross-domain lock, runs the caller's gated mutation, and always releases
|
|
48
48
|
* the lock afterward.
|
|
49
49
|
*
|
|
50
50
|
* @complexity O(1) plus the lock acquire/release and the injected `gatewayExecute()` call.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @file
|
|
3
|
-
*
|
|
2
|
+
* @file The `executeMigrateForward` orchestration wrapper.
|
|
3
|
+
*
|
|
4
4
|
*
|
|
5
5
|
* Purpose:
|
|
6
6
|
* Wires the cross-domain shared operation lock (`core/operation-lock.ts`, designated/tested by
|
|
7
|
-
*
|
|
7
|
+
* the recovery specification) and the `costClass: 'unavailable'` refusal around the actual gated mutation.
|
|
8
8
|
* This module does not implement or test the lock primitive itself, nor the state machine or
|
|
9
9
|
* `core/gated-mutations.execute()` sequence — `gatewayExecute` is the caller's own composition of
|
|
10
10
|
* those (typically closing over the state machine's `advance()` and the gateway's `execute()`).
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* How it relates to the project:
|
|
13
13
|
* `costClass === 'unavailable'` is checked BEFORE the lock is ever consulted (AC-09) — refusing
|
|
14
14
|
* before any side effect runs, so no lock is ever left held for a migration that was always going
|
|
15
|
-
* to be refused. The lock is acquired strictly before `gatewayExecute()` runs
|
|
15
|
+
* to be refused. The lock is acquired strictly before `gatewayExecute()` runs and
|
|
16
16
|
* released in a `finally`, so a mutation failure never leaks a held site-wide lock.
|
|
17
17
|
*
|
|
18
18
|
* Architectural role:
|
|
@@ -38,7 +38,7 @@ export class RestorePointUnavailableError extends Error {
|
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
40
|
* Orchestrates a forward-migrate execution: refuses `costClass: 'unavailable'` outright, acquires
|
|
41
|
-
* the shared cross-domain lock
|
|
41
|
+
* the shared cross-domain lock, runs the caller's gated mutation, and always releases
|
|
42
42
|
* the lock afterward.
|
|
43
43
|
*
|
|
44
44
|
* @complexity O(1) plus the lock acquire/release and the injected `gatewayExecute()` call.
|
|
@@ -2,8 +2,8 @@ import type { Clock as ClockPort, IdGenerator as IdGeneratorPort } from "@jini-a
|
|
|
2
2
|
import type { GatedMutationHooks } from "@jini-ai/core/gated-mutations";
|
|
3
3
|
import type { RecoveryHookPolicy } from "./hook-policy.js";
|
|
4
4
|
/**
|
|
5
|
-
* @file Database's `GatedMutationHooks` factory for the `migrate-forward` ceremony
|
|
6
|
-
*
|
|
5
|
+
* @file Database's `GatedMutationHooks` factory for the `migrate-forward` ceremony
|
|
6
|
+
* — the domain-specific quarter of what used to be
|
|
7
7
|
* `server/gated-mutations-composition.ts`, split out so Database no longer needs a back-edge into
|
|
8
8
|
* `server/` for its own hook builder. The generic pieces every ceremony shares (`buildGatewayDeps`,
|
|
9
9
|
* `planHashOf`, `resolveActorClassIdentity`, `buildConfirmOnlyHooks`) stayed in
|
|
@@ -72,13 +72,13 @@ export interface BuildMigrateForwardHooksInput extends RecoveryHookPolicy {
|
|
|
72
72
|
databaseLedgerRepo: LedgerAppendPort;
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
75
|
-
*
|
|
75
|
+
* The Database `migrate-forward` ceremony's `GatedMutationHooks`.
|
|
76
76
|
*
|
|
77
77
|
* `computePlan()` reads live `dbOps.getCapabilities()` every call (never cached) — a site whose
|
|
78
78
|
* capability changes between plan and execute (e.g. `cheap` -> `unavailable`) correctly produces a
|
|
79
79
|
* different plan hash.
|
|
80
80
|
*
|
|
81
|
-
* `executeMutation()` performs the two safe, real,
|
|
81
|
+
* `executeMutation()` performs the two safe, real, mandated actions this composition
|
|
82
82
|
* root can perform without inventing an unreviewed live-schema-swap mechanism: it captures a real
|
|
83
83
|
* restore point (`dbOps.captureRestorePoint` — an online-backup file copy in the real SQLite
|
|
84
84
|
* composition, a deterministic double in the hermetic one) and appends a `core.migration`
|
|
@@ -87,7 +87,7 @@ export interface BuildMigrateForwardHooksInput extends RecoveryHookPolicy {
|
|
|
87
87
|
* at `openContentDb()` boot time (`db/sqlite/content-db.ts`), so by the time any ceremony could
|
|
88
88
|
* run, the schema is already at head; re-invoking the migrator here would be a no-op in every
|
|
89
89
|
* environment this dispatch can actually exercise, and this file has no reachable seam into the
|
|
90
|
-
* hermetic (
|
|
90
|
+
* hermetic (a host module) composition's non-existent `content.db` at all. Persisting a
|
|
91
91
|
* `migration_runs` row (the former state machine's attempt ledger) is likewise
|
|
92
92
|
* out of this pass's scope — no composition root wires `SqliteMigrationRunsRepo`/an in-memory
|
|
93
93
|
* counterpart into `RouteDeps` yet; disclosed, not silently skipped.
|
|
@@ -98,7 +98,7 @@ export interface BuildMigrateForwardHooksInput extends RecoveryHookPolicy {
|
|
|
98
98
|
* so the resulting artifact carries every workspace's data, not just the caller's) plus one
|
|
99
99
|
* `restorePointsRepo`/`databaseLedgerRepo` write each. The restore-points subsystem this feeds is
|
|
100
100
|
* itself not workspace-partitioned in practice: the real SQLite repo is nominally `siteId`-scoped
|
|
101
|
-
* but bound to exactly one `siteId` for a whole process's lifetime (
|
|
101
|
+
* but bound to exactly one `siteId` for a whole process's lifetime (a host module), the
|
|
102
102
|
* in-memory test double has no partitioning field at all (`features/database/repo.memory.ts`),
|
|
103
103
|
* and `features/recovery/gated-hooks.ts`'s `buildRestoreHooks` reads `restorePointsRepo.list()`
|
|
104
104
|
* completely unfiltered — so a restore point this ceremony captures is exactly as instance-wide
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { nowIso as clockNowIso } from "@jini-ai/core/primitives";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* The Database `migrate-forward` ceremony's `GatedMutationHooks`.
|
|
4
4
|
*
|
|
5
5
|
* `computePlan()` reads live `dbOps.getCapabilities()` every call (never cached) — a site whose
|
|
6
6
|
* capability changes between plan and execute (e.g. `cheap` -> `unavailable`) correctly produces a
|
|
7
7
|
* different plan hash.
|
|
8
8
|
*
|
|
9
|
-
* `executeMutation()` performs the two safe, real,
|
|
9
|
+
* `executeMutation()` performs the two safe, real, mandated actions this composition
|
|
10
10
|
* root can perform without inventing an unreviewed live-schema-swap mechanism: it captures a real
|
|
11
11
|
* restore point (`dbOps.captureRestorePoint` — an online-backup file copy in the real SQLite
|
|
12
12
|
* composition, a deterministic double in the hermetic one) and appends a `core.migration`
|
|
@@ -15,7 +15,7 @@ import { nowIso as clockNowIso } from "@jini-ai/core/primitives";
|
|
|
15
15
|
* at `openContentDb()` boot time (`db/sqlite/content-db.ts`), so by the time any ceremony could
|
|
16
16
|
* run, the schema is already at head; re-invoking the migrator here would be a no-op in every
|
|
17
17
|
* environment this dispatch can actually exercise, and this file has no reachable seam into the
|
|
18
|
-
* hermetic (
|
|
18
|
+
* hermetic (a host module) composition's non-existent `content.db` at all. Persisting a
|
|
19
19
|
* `migration_runs` row (the former state machine's attempt ledger) is likewise
|
|
20
20
|
* out of this pass's scope — no composition root wires `SqliteMigrationRunsRepo`/an in-memory
|
|
21
21
|
* counterpart into `RouteDeps` yet; disclosed, not silently skipped.
|
|
@@ -26,7 +26,7 @@ import { nowIso as clockNowIso } from "@jini-ai/core/primitives";
|
|
|
26
26
|
* so the resulting artifact carries every workspace's data, not just the caller's) plus one
|
|
27
27
|
* `restorePointsRepo`/`databaseLedgerRepo` write each. The restore-points subsystem this feeds is
|
|
28
28
|
* itself not workspace-partitioned in practice: the real SQLite repo is nominally `siteId`-scoped
|
|
29
|
-
* but bound to exactly one `siteId` for a whole process's lifetime (
|
|
29
|
+
* but bound to exactly one `siteId` for a whole process's lifetime (a host module), the
|
|
30
30
|
* in-memory test double has no partitioning field at all (`features/database/repo.memory.ts`),
|
|
31
31
|
* and `features/recovery/gated-hooks.ts`'s `buildRestoreHooks` reads `restorePointsRepo.list()`
|
|
32
32
|
* completely unfiltered — so a restore point this ceremony captures is exactly as instance-wide
|
|
@@ -50,7 +50,7 @@ export function buildMigrateForwardHooks(input, _optional = {}) {
|
|
|
50
50
|
return { planHash: input.planHashOf({ details }, {}), details };
|
|
51
51
|
},
|
|
52
52
|
executeMutation: async () => {
|
|
53
|
-
// Read fresh, not the `computePlan()` value —
|
|
53
|
+
// Read fresh, not the `computePlan()` value — a capability check cached across the
|
|
54
54
|
// plan/execute boundary can go stale, and the saved row must reflect what was ACTUALLY captured.
|
|
55
55
|
const capabilities = await input.dbOps.getCapabilities();
|
|
56
56
|
const captured = await input.dbOps.captureRestorePoint({ scopeId: input.workspaceId });
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { type Clock as ClockPort } from "@jini-ai/core/primitives";
|
|
2
2
|
/**
|
|
3
|
-
* @file
|
|
4
|
-
* mutual exclusion
|
|
3
|
+
* @file Site-wide gated-operation
|
|
4
|
+
* mutual exclusion.
|
|
5
5
|
*
|
|
6
6
|
* Purpose:
|
|
7
|
-
* The single, shared primitive both `features/database` (
|
|
8
|
-
* `features/recovery` (
|
|
7
|
+
* The single, shared primitive both `features/database` (migrate-forward) and
|
|
8
|
+
* `features/recovery` (restore) MUST consult before starting a gated operation. Two
|
|
9
9
|
* domains racing to mutate the same site's `content.db` must never both be "in flight" — the
|
|
10
10
|
* primitive tracks in-flight state per `siteId` only, never per-domain, so it cannot be defeated
|
|
11
|
-
* by two domain-local checks that happen to look similar
|
|
11
|
+
* by two domain-local checks that happen to look similar.
|
|
12
12
|
*
|
|
13
13
|
* How it relates to the project:
|
|
14
14
|
* `executeMigrateForward` and `executeRestore` both call `acquireOperationLock` as the provably
|
|
15
|
-
* first side-effecting step of their own orchestration
|
|
15
|
+
* first side-effecting step of their own orchestration, and `releaseOperationLock`
|
|
16
16
|
* once the operation concludes (success or failure).
|
|
17
17
|
*
|
|
18
18
|
* Architectural role:
|
|
@@ -20,14 +20,14 @@ import { type Clock as ClockPort } from "@jini-ai/core/primitives";
|
|
|
20
20
|
* serialized to a single process by `content.db`'s own single-writer model; this primitive adds
|
|
21
21
|
* the cross-domain intent-level guard on top of that.
|
|
22
22
|
*
|
|
23
|
-
*
|
|
23
|
+
* Recovery re-audit (2026-07-16, TM-adr041-043-044-045-audit-001, Finding 3):
|
|
24
24
|
* the internal verifier's original claim — "never wired into any composition root" — is false,
|
|
25
|
-
* disproven by direct evidence:
|
|
26
|
-
*
|
|
25
|
+
* disproven by direct evidence: a host module and
|
|
26
|
+
* a host module both import `acquireOperationLock`/
|
|
27
27
|
* `releaseOperationLock` from this file directly and pass them into `executeMigrateForward`/
|
|
28
|
-
* `executeRestore` (their `execute` endpoints only). The mutual-exclusion guarantee
|
|
28
|
+
* `executeRestore` (their `execute` endpoints only). The mutual-exclusion guarantee is
|
|
29
29
|
* real and live for both gated ceremonies today. The actual, narrower gap the re-audit surfaced:
|
|
30
|
-
* this module had no read-only query, so
|
|
30
|
+
* this module had no read-only query, so a host module's capability bar
|
|
31
31
|
* could not reflect live lock state and stubbed `operationInFlight: false` unconditionally.
|
|
32
32
|
* `isOperationInFlight` below closes that display gap without changing the mutual-exclusion
|
|
33
33
|
* mechanism itself.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { nowIso as readNowIso } from "@jini-ai/core/primitives";
|
|
2
2
|
/** Create one shared lock for all gated-operation domains in a host; separate hosts get isolated state. */
|
|
3
3
|
export function createOperationLock(_required, _optional = {}) {
|
|
4
|
-
/** Instance-owned in-flight registry — one entry per `siteId
|
|
4
|
+
/** Instance-owned in-flight registry — one entry per `siteId`. */
|
|
5
5
|
const activeLocksBySiteId = new Map();
|
|
6
6
|
/**
|
|
7
|
-
* Atomic check-and-set
|
|
7
|
+
* Atomic check-and-set: the presence check and the registry write happen in the same
|
|
8
8
|
* synchronous span with no intervening `await`, so concurrent callers on Node's single-threaded
|
|
9
9
|
* event loop (see the cross-domain property tests) cannot race a read-then-write gap — exactly
|
|
10
10
|
* one caller ever observes an empty slot for a given `siteId`.
|
|
@@ -45,7 +45,7 @@ export function createOperationLock(_required, _optional = {}) {
|
|
|
45
45
|
* Read-only peek at whether `siteId` currently holds a lock — never acquires, never mutates the
|
|
46
46
|
* registry. For display/status surfaces only (e.g. Recovery's capability bar); gated ceremonies
|
|
47
47
|
* must keep using `acquireOperationLock`'s atomic check-and-set, never this function, to decide
|
|
48
|
-
* whether they may proceed (a peek-then-acquire pair would reintroduce the TOCTOU gap
|
|
48
|
+
* whether they may proceed (a peek-then-acquire pair would reintroduce the TOCTOU gap this primitive
|
|
49
49
|
* exists to prevent).
|
|
50
50
|
*
|
|
51
51
|
* @complexity O(1).
|