@vibeorm/runtime 2.4.1 → 2.6.0
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/README.md +7 -0
- package/dist/adapter-kit/index.d.ts +2 -1
- package/dist/adapter-kit/index.d.ts.map +1 -1
- package/dist/adapter-kit/index.js +53 -3
- package/dist/adapter-kit/index.js.map +5 -4
- package/dist/adapter-kit/row-changes.d.ts +29 -0
- package/dist/adapter-kit/row-changes.d.ts.map +1 -0
- package/dist/adapter-kit/savepoint-gate.d.ts +8 -0
- package/dist/adapter-kit/savepoint-gate.d.ts.map +1 -1
- package/dist/adapter.d.ts +14 -0
- package/dist/adapter.d.ts.map +1 -1
- package/dist/advisory-key.d.ts +10 -0
- package/dist/advisory-key.d.ts.map +1 -0
- package/dist/advisory-lock.d.ts +3 -3
- package/dist/client.d.ts +3 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/codecs.d.ts.map +1 -1
- package/dist/database-module.d.ts.map +1 -1
- package/dist/find-page.d.ts +35 -0
- package/dist/find-page.d.ts.map +1 -0
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +544 -276
- package/dist/index.js.map +26 -22
- package/dist/keyset-iterator.d.ts.map +1 -1
- package/dist/keyset-projection.d.ts +12 -0
- package/dist/keyset-projection.d.ts.map +1 -0
- package/dist/keyset.d.ts +7 -6
- package/dist/keyset.d.ts.map +1 -1
- package/dist/model-meta.d.ts +5 -1
- package/dist/model-meta.d.ts.map +1 -1
- package/dist/policy.d.ts.map +1 -1
- package/dist/query-builder.d.ts +8 -1
- package/dist/query-builder.d.ts.map +1 -1
- package/dist/read-only.d.ts +17 -1
- package/dist/read-only.d.ts.map +1 -1
- package/dist/relation-plan.d.ts +1 -0
- package/dist/relation-plan.d.ts.map +1 -1
- package/dist/render-cache.d.ts.map +1 -1
- package/dist/rls-readiness.d.ts.map +1 -1
- package/dist/scoped.d.ts.map +1 -1
- package/dist/transaction-row-changes.d.ts +28 -0
- package/dist/transaction-row-changes.d.ts.map +1 -0
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -52,11 +52,18 @@ const adapter: DatabaseAdapter = {
|
|
|
52
52
|
- Adapters never let raw driver errors escape. Each maps its driver's failures to `VibeError` codes (`VIBE_UNIQUE_VIOLATION`, `VIBE_FK_VIOLATION`, `VIBE_TRANSACTION`, `VIBE_ADAPTER`) through a per-driver table, with the driver error as `cause`.
|
|
53
53
|
- `formatArrayParam` converts a JS array into the driver's preferred scalar-array representation; the ORM path binds arrays through it, the raw path does not.
|
|
54
54
|
- The optional `wire` declaration (`WireFidelity`) tells the runtime what the driver already delivers for non-list scalars, so provably no-op decoders can be skipped.
|
|
55
|
+
- The optional `rowChanges()` member reports the surviving direct row changes of the adapter's active transaction as a number or `"unknown"`; it backs `transactionRowChanges`. An adapter without it reports `"unknown"`. The kit's `statementRowChanges`, `observeRowChanges` and `readRowChanges` implement it for the shipped adapters.
|
|
55
56
|
|
|
56
57
|
`toSqlExecutor({ adapter })` bridges an adapter to the `SqlExecutor` shape `@vibeorm/migrate` runs on.
|
|
57
58
|
|
|
58
59
|
`@vibeorm/runtime/adapter-kit` carries the transaction helpers every shipped adapter is built on, so a custom adapter does not re-implement them: savepoint naming (`createSavepointCounter`), the savepoint lifetime gate that serialises overlapping sibling `transaction()` calls on one connection (`createSavepointScope`, `runRootScope`, `runNestedSavepoint`, `scopeTurn`), and the transaction budget behind `TransactionOptions.deadline` (`validateTransactionDeadline`, `startTransactionBudget`, `engineStatementBudgetMs` and the typed refusals). The shipped adapters re-export them unchanged.
|
|
59
60
|
|
|
61
|
+
## Helpers for frameworks
|
|
62
|
+
|
|
63
|
+
- `transactionRowChanges({ db })` returns the direct row changes that survive in the transaction behind a handle, or `"unknown"` when some statement could not be observed ([queries.md](https://github.com/vibeorm/vibeorm/blob/master/docs/queries.md#rows-changed-so-far-transactionrowchanges)).
|
|
64
|
+
- `createDelegateMethodClassifier({ db })` returns `({ method, model? }) => "read" | "write" | undefined` for that handle's core and configured extension methods; `undefined` means denied ([queries.md](https://github.com/vibeorm/vibeorm/blob/master/docs/queries.md#read-only-clients-readonly)).
|
|
65
|
+
- `advisoryKeyOf({ text })` maps a string to a signed 64-bit `bigint` advisory-lock key (SHA-256 of the UTF-8 bytes, first eight bytes, big-endian). Different strings can map to the same key ([queries.md](https://github.com/vibeorm/vibeorm/blob/master/docs/queries.md#advisory-locks-advisorylock-tryadvisorylock)).
|
|
66
|
+
|
|
60
67
|
## Relation strategies
|
|
61
68
|
|
|
62
69
|
```ts
|
|
@@ -13,11 +13,12 @@
|
|
|
13
13
|
*/
|
|
14
14
|
export { createSavepointCounter, nextSavepointName } from "./savepoints.ts";
|
|
15
15
|
export type { SavepointCounter } from "./savepoints.ts";
|
|
16
|
-
export { abortTransactionOnServerFailure, createSavepointScope, isSavepointRollbackFailedError, isTransactionAbortedError, markTransactionAborted, runNestedSavepoint, runRootScope, savepointRollbackFailedError, scopeTurn, transactionAbortedError, } from "./savepoint-gate.ts";
|
|
16
|
+
export { abortTransactionOnServerFailure, createSavepointScope, isSavepointRollbackFailedError, isTransactionAbortedError, markTransactionAborted, markSavepointOpened, runNestedSavepoint, runRootScope, savepointRollbackFailedError, scopeTurn, transactionAbortedError, } from "./savepoint-gate.ts";
|
|
17
17
|
export type { AbortedTransaction, SavepointScope, SavepointState } from "./savepoint-gate.ts";
|
|
18
18
|
export { refuseNestedTransactionOptions } from "./nested-options.ts";
|
|
19
19
|
export { DEFAULT_DEADLINE_CLOCK, engineStatementBudgetMs, isTransactionDeadlineError, startTransactionBudget, transactionClosedError, transactionDeadlineError, transactionOutcomeUnknownError, validateTransactionDeadline, } from "./transaction-budget.ts";
|
|
20
20
|
export type { BudgetStage, DeadlineClock, TransactionBudget, TransactionOutcome } from "./transaction-budget.ts";
|
|
21
|
+
export { dispatchSynchronousRowChanges, observeRowChanges, readRowChanges, statementRowChanges } from "./row-changes.ts";
|
|
21
22
|
export { runPinnedSession } from "./session.ts";
|
|
22
23
|
export { runSqliteSession } from "./sqlite-session.ts";
|
|
23
24
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapter-kit/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC5E,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,EACL,+BAA+B,EAC/B,oBAAoB,EACpB,8BAA8B,EAC9B,yBAAyB,EACzB,sBAAsB,EACtB,kBAAkB,EAClB,YAAY,EACZ,4BAA4B,EAC5B,SAAS,EACT,uBAAuB,GACxB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EAAE,kBAAkB,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE9F,OAAO,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AAErE,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,0BAA0B,EAC1B,sBAAsB,EACtB,sBAAsB,EACtB,wBAAwB,EACxB,8BAA8B,EAC9B,2BAA2B,GAC5B,MAAM,yBAAyB,CAAC;AACjC,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAEjH,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapter-kit/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC5E,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,EACL,+BAA+B,EAC/B,oBAAoB,EACpB,8BAA8B,EAC9B,yBAAyB,EACzB,sBAAsB,EACtB,mBAAmB,EACnB,kBAAkB,EAClB,YAAY,EACZ,4BAA4B,EAC5B,SAAS,EACT,uBAAuB,GACxB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EAAE,kBAAkB,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE9F,OAAO,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AAErE,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,0BAA0B,EAC1B,sBAAsB,EACtB,sBAAsB,EACtB,wBAAwB,EACxB,8BAA8B,EAC9B,2BAA2B,GAC5B,MAAM,yBAAyB,CAAC;AACjC,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAEjH,OAAO,EAAE,6BAA6B,EAAE,iBAAiB,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEzH,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -11,7 +11,7 @@ import { AsyncLocalStorage } from "async_hooks";
|
|
|
11
11
|
import { VibeError } from "@vibeorm/schema";
|
|
12
12
|
var CURRENT = new AsyncLocalStorage;
|
|
13
13
|
function createSavepointScope() {
|
|
14
|
-
return { depth: 0, state: { counter: createSavepointCounter(), open: null, poisoned: null, aborted: null } };
|
|
14
|
+
return { depth: 0, state: { counter: createSavepointCounter(), open: null, poisoned: null, aborted: null, rowChanges: 0 } };
|
|
15
15
|
}
|
|
16
16
|
function markTransactionAborted(params) {
|
|
17
17
|
const state = params.scope.state;
|
|
@@ -50,6 +50,7 @@ async function runNestedSavepoint(params) {
|
|
|
50
50
|
try {
|
|
51
51
|
if (execute !== undefined)
|
|
52
52
|
await execute(`SAVEPOINT ${node.name}`);
|
|
53
|
+
markSavepointOpened({ scope: node.scope });
|
|
53
54
|
const result = await CURRENT.run(node.scope, () => body(node.scope));
|
|
54
55
|
await drainDescendants({ node });
|
|
55
56
|
assertNotPoisoned({ state: scope.state });
|
|
@@ -70,12 +71,18 @@ async function runNestedSavepoint(params) {
|
|
|
70
71
|
}
|
|
71
72
|
}
|
|
72
73
|
clearAbortedAtOrBelow({ state: scope.state, depth: node.scope.depth });
|
|
74
|
+
scope.state.rowChanges = node.rowChangesOnEntry;
|
|
73
75
|
throw error;
|
|
74
76
|
}
|
|
75
77
|
} finally {
|
|
76
78
|
closeNode({ node });
|
|
77
79
|
}
|
|
78
80
|
}
|
|
81
|
+
function markSavepointOpened(params) {
|
|
82
|
+
const node = params.scope.state.open;
|
|
83
|
+
if (node !== null && node.scope === params.scope)
|
|
84
|
+
node.rowChangesOnEntry = params.scope.state.rowChanges;
|
|
85
|
+
}
|
|
79
86
|
function savepointRollbackFailedError(params) {
|
|
80
87
|
const { cause, rollbackFailure } = params;
|
|
81
88
|
const rollbackErrorCode = rollbackFailure instanceof VibeError ? rollbackFailure.code : undefined;
|
|
@@ -172,7 +179,8 @@ function pushNode(params) {
|
|
|
172
179
|
name: nextSavepointName({ counter: state.counter }),
|
|
173
180
|
parent,
|
|
174
181
|
settled,
|
|
175
|
-
settle
|
|
182
|
+
settle,
|
|
183
|
+
rowChangesOnEntry: state.rowChanges
|
|
176
184
|
};
|
|
177
185
|
state.open = node;
|
|
178
186
|
return node;
|
|
@@ -339,6 +347,43 @@ function isTransactionDeadlineError(error) {
|
|
|
339
347
|
const reason = error?.meta?.reason;
|
|
340
348
|
return reason === "transaction-deadline";
|
|
341
349
|
}
|
|
350
|
+
// packages/runtime/src/adapter-kit/row-changes.ts
|
|
351
|
+
function statementRowChanges(params) {
|
|
352
|
+
const { effect, count } = params;
|
|
353
|
+
if (effect === "read")
|
|
354
|
+
return 0;
|
|
355
|
+
if (effect !== "write")
|
|
356
|
+
return "unknown";
|
|
357
|
+
return typeof count === "number" && Number.isSafeInteger(count) && count >= 0 ? count : "unknown";
|
|
358
|
+
}
|
|
359
|
+
function observeRowChanges(params) {
|
|
360
|
+
const state = params.scope.state;
|
|
361
|
+
if (state.rowChanges === "unknown")
|
|
362
|
+
return;
|
|
363
|
+
const count = params.count;
|
|
364
|
+
if (count === "unknown" || !Number.isSafeInteger(count) || count < 0 || !Number.isSafeInteger(state.rowChanges + count)) {
|
|
365
|
+
state.rowChanges = "unknown";
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
state.rowChanges += count;
|
|
369
|
+
}
|
|
370
|
+
function dispatchSynchronousRowChanges(params) {
|
|
371
|
+
const { scope } = params;
|
|
372
|
+
if (scope === undefined)
|
|
373
|
+
return params.run();
|
|
374
|
+
const before = scope.state.rowChanges;
|
|
375
|
+
if (params.effect !== "read")
|
|
376
|
+
scope.state.rowChanges = "unknown";
|
|
377
|
+
const result = params.run();
|
|
378
|
+
const count = params.count(result);
|
|
379
|
+
scope.state.rowChanges = before;
|
|
380
|
+
observeRowChanges({ scope, count });
|
|
381
|
+
return result;
|
|
382
|
+
}
|
|
383
|
+
function readRowChanges(params) {
|
|
384
|
+
const state = params.scope.state;
|
|
385
|
+
return state.poisoned !== null || state.aborted !== null ? "unknown" : state.rowChanges;
|
|
386
|
+
}
|
|
342
387
|
// packages/runtime/src/adapter-kit/session.ts
|
|
343
388
|
import { VibeError as VibeError4 } from "@vibeorm/schema";
|
|
344
389
|
function runPinnedSession(params) {
|
|
@@ -458,12 +503,16 @@ export {
|
|
|
458
503
|
abortTransactionOnServerFailure,
|
|
459
504
|
createSavepointCounter,
|
|
460
505
|
createSavepointScope,
|
|
506
|
+
dispatchSynchronousRowChanges,
|
|
461
507
|
engineStatementBudgetMs,
|
|
462
508
|
isSavepointRollbackFailedError,
|
|
463
509
|
isTransactionAbortedError,
|
|
464
510
|
isTransactionDeadlineError,
|
|
511
|
+
markSavepointOpened,
|
|
465
512
|
markTransactionAborted,
|
|
466
513
|
nextSavepointName,
|
|
514
|
+
observeRowChanges,
|
|
515
|
+
readRowChanges,
|
|
467
516
|
refuseNestedTransactionOptions,
|
|
468
517
|
runNestedSavepoint,
|
|
469
518
|
runPinnedSession,
|
|
@@ -472,6 +521,7 @@ export {
|
|
|
472
521
|
savepointRollbackFailedError,
|
|
473
522
|
scopeTurn,
|
|
474
523
|
startTransactionBudget,
|
|
524
|
+
statementRowChanges,
|
|
475
525
|
transactionAbortedError,
|
|
476
526
|
transactionClosedError,
|
|
477
527
|
transactionDeadlineError,
|
|
@@ -479,4 +529,4 @@ export {
|
|
|
479
529
|
validateTransactionDeadline
|
|
480
530
|
};
|
|
481
531
|
|
|
482
|
-
//# debugId=
|
|
532
|
+
//# debugId=9043FC0FD9D8EA9E64756E2164756E21
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/adapter-kit/savepoints.ts", "../src/adapter-kit/savepoint-gate.ts", "../src/adapter-kit/nested-options.ts", "../src/adapter-kit/transaction-budget.ts", "../src/adapter-kit/session.ts", "../src/adapter-kit/sqlite-session.ts"],
|
|
3
|
+
"sources": ["../src/adapter-kit/savepoints.ts", "../src/adapter-kit/savepoint-gate.ts", "../src/adapter-kit/nested-options.ts", "../src/adapter-kit/transaction-budget.ts", "../src/adapter-kit/row-changes.ts", "../src/adapter-kit/session.ts", "../src/adapter-kit/sqlite-session.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"/**\n * Savepoint naming for nested transactions.\n *\n * v1 lesson (LEARNINGS.md): the counter is shared **by reference** across every\n * adapter created for one top-level transaction, so sibling and deeply nested\n * savepoints can never collide on a name.\n */\n\n/** Mutable counter shared by reference across one top-level transaction. */\nexport type SavepointCounter = { n: number };\n\n/** Fresh counter — one per top-level transaction. */\nexport function createSavepointCounter(): SavepointCounter {\n return { n: 0 };\n}\n\n/**\n * Allocate the next savepoint name (`vibeorm_sp_0`, `vibeorm_sp_1`, …) and\n * advance the shared counter. The name is an identifier by construction, so it\n * is safe to interpolate into `SAVEPOINT` / `RELEASE` / `ROLLBACK TO` SQL.\n */\nexport function nextSavepointName(params: { counter: SavepointCounter }): string {\n return `vibeorm_sp_${params.counter.n++}`;\n}\n",
|
|
6
|
-
"/**\n * Savepoint lifetimes inside one top-level transaction (F14).\n *\n * A savepoint stack lives on ONE connection: `ROLLBACK TO SAVEPOINT s` undoes\n * everything done after `s`, including work a LATER savepoint already released.\n * Two `transaction()` callbacks opened from the same handle and overlapping in\n * time therefore share that one stack, and the earlier one's rollback silently\n * erases the later one's already committed work. Unique savepoint names do not\n * help — the names never collided, the lifetimes did.\n *\n * The rule enforced here, on every handle of a transaction:\n *\n * > A handle runs when nothing deeper than itself is open. Otherwise it waits\n * > for the innermost open savepoint to settle — unless the call is being made\n * > from INSIDE that savepoint's own callback, which is genuine nesting and\n * > proceeds immediately.\n *\n * The \"from inside\" test is an {@link AsyncLocalStorage} lookup, so the common\n * nesting shapes never wait on themselves: a child opened from its parent's\n * callback, and the parent handle used from within an open child's callback,\n * both proceed. Only genuinely concurrent siblings serialize.\n *\n * Not covered: a callback that awaits a sibling it did not start. That\n * arrangement asks for two savepoints to be open at once, which is exactly what\n * loses work; it now blocks instead. Deliberate — see the notes for this fix.\n *\n * A FAILED `ROLLBACK TO SAVEPOINT` poisons the whole transaction. When the\n * engine cannot undo a savepoint — InnoDB has already rolled the entire\n * transaction back after a deadlock, an implicit-commit DDL cleared every\n * savepoint, the connection dropped — the transaction's outcome is unknown and\n * no handle of it may send another statement: a parent callback that caught\n * the nested error and \"continued\" would otherwise run in autocommit and the\n * final COMMIT would succeed vacuously. Every later turn refuses with the same\n * typed error.\n *\n * An ABORTED transaction (postgres) is tracked here too. PostgreSQL puts the\n * whole transaction into the aborted state after ANY statement error; every\n * later statement fails with 25P02 and `COMMIT` is answered with a `ROLLBACK`\n * command tag and NO error. A callback that catches one statement error and\n * returns normally would therefore \"commit\" nothing while the adapter\n * reported success. The postgres adapters record each driver-reported\n * statement failure at the connection's current savepoint depth\n * ({@link markTransactionAborted}); a `ROLLBACK TO SAVEPOINT` at or above that\n * depth restores the transaction (postgres semantics), and otherwise every\n * later statement, nested savepoint and the commit itself are refused with one\n * typed error carrying the original failure as `cause`. Engines whose\n * transactions survive a statement error (mysql, sqlite) never mark.\n */\n\nimport { AsyncLocalStorage } from \"node:async_hooks\";\nimport { VibeError } from \"@vibeorm/schema\";\nimport { type SavepointCounter, createSavepointCounter, nextSavepointName } from \"./savepoints.ts\";\n\n// ─── Types ────────────────────────────────────────────────────────\n\n/**\n * One handle's position in the savepoint stack of a top-level transaction.\n * `state` is shared by reference across every handle of that transaction.\n */\nexport type SavepointScope = {\n /** Physical savepoint depth; 0 is the top-level transaction itself. */\n readonly depth: number;\n /** Shared state: name allocation plus the innermost open savepoint. */\n readonly state: SavepointState;\n};\n\n/** Mutable state shared by every scope of one top-level transaction. */\nexport type SavepointState = {\n /** Savepoint name counter (shared, so names never collide). */\n readonly counter: SavepointCounter;\n /** The innermost savepoint currently open, or `null` when none is. */\n open: OpenSavepoint | null;\n /**\n * Set once a `ROLLBACK TO SAVEPOINT` has failed: the savepoint stack no\n * longer describes the connection, so every later statement and nested\n * savepoint on ANY handle of this transaction is refused with this error.\n */\n poisoned: VibeError | null;\n /**\n * Set once a statement failed on an engine that aborts the whole transaction\n * (postgres): the depth of the innermost savepoint that was open when it\n * failed, and the failure. Cleared by a `ROLLBACK TO SAVEPOINT` at or above\n * that depth; otherwise the commit is refused.\n */\n aborted: AbortedTransaction | null;\n};\n\n/** The recorded statement failure that left a postgres transaction aborted. */\nexport type AbortedTransaction = {\n /** Connection depth at the time of the failure; 0 is the top-level transaction. */\n readonly depth: number;\n /** The driver-reported statement failure. */\n readonly cause: unknown;\n};\n\n/** An open savepoint: its handle, its name, and when it finished. */\ntype OpenSavepoint = {\n readonly scope: SavepointScope;\n readonly name: string;\n readonly parent: OpenSavepoint | null;\n readonly settled: Promise<void>;\n readonly settle: () => void;\n};\n\n/**\n * The savepoint whose callback the current async context is running inside.\n * This is the discriminator between genuine nesting (proceed) and an\n * overlapping sibling (wait).\n */\nconst CURRENT = new AsyncLocalStorage<SavepointScope>();\n\n// ─── Public API ───────────────────────────────────────────────────\n\n/** Fresh scope for one top-level transaction: depth 0, nothing open. */\nexport function createSavepointScope(): SavepointScope {\n return { depth: 0, state: { counter: createSavepointCounter(), open: null, poisoned: null, aborted: null } };\n}\n\n/**\n * Record that a statement failed on an engine that aborts the transaction\n * (postgres). The failure is recorded at the connection's CURRENT depth — the\n * innermost open savepoint, whichever handle sent the statement — because that\n * is the subtransaction postgres marks as failed. The first failure is kept: a\n * later 25P02 is a consequence, not a cause.\n */\nexport function markTransactionAborted(params: { scope: SavepointScope; cause: unknown }): void {\n const state = params.scope.state;\n if (state.aborted !== null) return;\n state.aborted = { depth: state.open?.scope.depth ?? 0, cause: params.cause };\n}\n\n/**\n * The postgres adapters' statement failure path: a SERVER-reported failure (a\n * mapped `VibeError` carrying `meta.sqlstate`) aborts the transaction; a\n * client-side refusal that never reached the server (a budget, a parameter\n * that could not be serialized) leaves it usable. Rethrows either way.\n */\nexport function abortTransactionOnServerFailure(params: { scope: SavepointScope; error: unknown }): never {\n const { scope, error } = params;\n if (error instanceof VibeError && typeof error.meta.sqlstate === \"string\") {\n markTransactionAborted({ scope, cause: error });\n }\n throw error;\n}\n\n/**\n * Run a top-level transaction callback inside its scope's async context, so\n * nested calls made from it can be told apart from calls made inside an open\n * child.\n */\nexport function runRootScope<T>(params: { scope: SavepointScope; body: () => Promise<T> }): Promise<T> {\n return CURRENT.run(params.scope, async () => {\n assertNotPoisoned({ state: params.scope.state });\n const result = await params.body();\n // Adapters commit after this resolves. Catching a nested failure must not\n // allow a poisoned transaction to report successful completion, and a\n // swallowed statement error must not let an ABORTED transaction commit —\n // postgres would answer that COMMIT with a silent ROLLBACK.\n assertNotPoisoned({ state: params.scope.state });\n assertNotAborted({ state: params.scope.state });\n return result;\n });\n}\n\n/**\n * The wait a statement on `scope` owes before it may run, or `undefined` when\n * it may run now. Returning `undefined` keeps the uncontended path — nothing\n * deeper open — free of an extra promise and microtask.\n */\nexport function scopeTurn(params: { scope: SavepointScope }): Promise<void> | undefined {\n assertNotPoisoned({ state: params.scope.state });\n // Postgres would answer with 25P02; refusing here names the ORIGINAL failure\n // and spends no round trip.\n assertNotAborted({ state: params.scope.state });\n const open = params.scope.state.open;\n if (mayProceed({ scope: params.scope, open })) return undefined;\n return waitForTurn({ scope: params.scope });\n}\n\n/**\n * Open a nested savepoint under `scope`, run `body` inside it and release it —\n * rolling back to it if `body` throws, exactly as before this gate existed.\n *\n * `execute` runs the savepoint control SQL (already wrapped in the adapter's\n * own driver-error mapping). Omit it when the driver manages the savepoint\n * itself (bun:sql's `savepoint()`), in which case only the lifetime is gated.\n */\nexport async function runNestedSavepoint<T>(params: {\n readonly scope: SavepointScope;\n readonly execute?: (statement: string) => Promise<unknown> | unknown;\n readonly body: (scope: SavepointScope) => Promise<T>;\n}): Promise<T> {\n const { scope, execute, body } = params;\n const node = await acquire({ scope });\n try {\n try {\n if (execute !== undefined) await execute(`SAVEPOINT ${node.name}`);\n const result = await CURRENT.run(node.scope, () => body(node.scope));\n await drainDescendants({ node });\n assertNotPoisoned({ state: scope.state });\n // A failure swallowed inside this callback left the savepoint aborted:\n // RELEASE would fail with 25P02, so roll it back below and report the\n // abort instead of letting the parent continue on a failed subtransaction.\n assertNotAborted({ state: scope.state });\n if (execute !== undefined) await execute(`RELEASE SAVEPOINT ${node.name}`);\n return result;\n } catch (error) {\n // A descendant the callback started but never awaited must finish before\n // this savepoint may be rolled back — releasing out of order corrupts\n // the stack.\n await drainDescendants({ node });\n assertNotPoisoned({ state: scope.state });\n if (execute !== undefined) {\n try {\n await execute(`ROLLBACK TO SAVEPOINT ${node.name}`);\n } catch (rollbackFailure) {\n // The savepoint could not be undone, so the connection's real state is\n // unknown. Poison the transaction (every handle, every later turn) and\n // surface THAT, with the body failure as the cause — rethrowing the\n // body error alone would let the parent callback continue.\n const poisoned = savepointRollbackFailedError({ cause: error, rollbackFailure });\n scope.state.poisoned = poisoned;\n throw poisoned;\n }\n }\n // The savepoint was undone (by the statement above, or by the driver\n // when it manages savepoints itself — a driver-side rollback failure\n // poisons the scope before reaching here). Postgres restores the\n // transaction to the state at this savepoint, which clears an abort that\n // happened at or below it.\n clearAbortedAtOrBelow({ state: scope.state, depth: node.scope.depth });\n throw error;\n }\n } finally {\n closeNode({ node });\n }\n}\n\n// ─── Errors ───────────────────────────────────────────────────────\n\n/**\n * The refusal raised when `ROLLBACK TO SAVEPOINT` itself fails, and repeated\n * for every later statement on the poisoned transaction. `VIBE_TRANSACTION`\n * with `meta.reason = \"savepoint-rollback-failed\"` and `meta.outcome =\n * \"unknown\"`; `cause` is the body failure that triggered the rollback. The\n * rollback failure's own code (when it is a `VibeError`) rides along as\n * `meta.rollbackErrorCode` — its message is not copied, because a raw driver\n * failure can carry statement text and this error is meant to be logged.\n */\nexport function savepointRollbackFailedError(params: { cause: unknown; rollbackFailure: unknown }): VibeError {\n const { cause, rollbackFailure } = params;\n const rollbackErrorCode =\n rollbackFailure instanceof VibeError ? rollbackFailure.code : undefined;\n return new VibeError({\n code: \"VIBE_TRANSACTION\",\n message:\n \"a nested transaction failed and the ROLLBACK TO SAVEPOINT that should have undone it failed too — \" +\n \"the savepoint stack no longer describes this connection, so the commit state of the whole transaction \" +\n \"is UNKNOWN and no further statement is accepted on any of its handles. The top-level transaction is \" +\n \"being rolled back; nothing is retried automatically.\",\n meta: {\n reason: \"savepoint-rollback-failed\",\n outcome: \"unknown\",\n rollbackFailed: true,\n ...(rollbackErrorCode === undefined ? {} : { rollbackErrorCode }),\n },\n cause,\n });\n}\n\n/** Whether `error` is this module's poison refusal (used to pick the cleanup path). */\nexport function isSavepointRollbackFailedError(error: unknown): boolean {\n const reason = (error as { meta?: { reason?: unknown } } | null)?.meta?.reason;\n return reason === \"savepoint-rollback-failed\";\n}\n\n/**\n * The refusal raised for every statement, nested savepoint and the commit of\n * an aborted postgres transaction. `VIBE_TRANSACTION` with `meta.reason =\n * \"aborted\"` and `meta.outcome = \"rolled-back\"` — the outcome is CERTAIN: the\n * server discards an aborted transaction whatever the client sends. `cause`\n * is the statement failure that aborted it, and its `code`/`sqlstate` ride\n * along in `meta` so a log line names the real defect.\n */\nexport function transactionAbortedError(params: { cause?: unknown }): VibeError {\n const cause = params.cause;\n const causeCode = cause instanceof VibeError ? cause.code : undefined;\n const sqlstate = cause instanceof VibeError && typeof cause.meta.sqlstate === \"string\" ? cause.meta.sqlstate : undefined;\n return new VibeError({\n code: \"VIBE_TRANSACTION\",\n message:\n \"the transaction is aborted: a statement inside it failed and PostgreSQL discards every later statement and the COMMIT itself \" +\n \"(the server answers COMMIT with ROLLBACK and no error). Nothing from this transaction was committed. \" +\n \"Let the failure propagate out of the callback, or run the statement that may fail inside a nested transaction so its savepoint is rolled back.\",\n meta: {\n reason: \"aborted\",\n outcome: \"rolled-back\",\n ...(causeCode === undefined ? {} : { causeCode }),\n ...(sqlstate === undefined ? {} : { sqlstate }),\n },\n ...(cause === undefined ? {} : { cause }),\n });\n}\n\n/** Whether `error` is the aborted-transaction refusal. */\nexport function isTransactionAbortedError(error: unknown): boolean {\n const reason = (error as { meta?: { reason?: unknown } } | null)?.meta?.reason;\n return reason === \"aborted\";\n}\n\n// ─── Internals ────────────────────────────────────────────────────\n\nfunction assertNotPoisoned(params: { state: SavepointState }): void {\n if (params.state.poisoned !== null) throw params.state.poisoned;\n}\n\nfunction assertNotAborted(params: { state: SavepointState }): void {\n if (params.state.aborted !== null) throw transactionAbortedError({ cause: params.state.aborted.cause });\n}\n\n/** `ROLLBACK TO SAVEPOINT` at `depth` undoes everything at or below it. */\nfunction clearAbortedAtOrBelow(params: { state: SavepointState; depth: number }): void {\n const aborted = params.state.aborted;\n if (aborted !== null && aborted.depth >= params.depth) params.state.aborted = null;\n}\n\n/** Whether `scope` may act while `open` is the innermost open savepoint. */\nfunction mayProceed(params: { scope: SavepointScope; open: OpenSavepoint | null }): boolean {\n const { scope, open } = params;\n if (open === null) return true;\n // This handle IS the innermost open savepoint.\n if (open.scope === scope) return true;\n // This handle's own savepoint has already closed (a retained child handle):\n // it can only act at the connection's current depth, and waiting for a\n // shallower savepoint it does not own would never resolve.\n if (open.scope.depth < scope.depth) return true;\n // Genuine nesting: the call is being made from inside the open callback.\n return CURRENT.getStore() === open.scope;\n}\n\nasync function waitForTurn(params: { scope: SavepointScope }): Promise<void> {\n for (;;) {\n assertNotPoisoned({ state: params.scope.state });\n const open = params.scope.state.open;\n if (open === null || mayProceed({ scope: params.scope, open })) return;\n await open.settled;\n }\n}\n\n/**\n * Wait for this handle's turn and take it in the SAME synchronous step — the\n * check and the push must not be separated by an await, or two waiters woken\n * together would both open a savepoint.\n */\nasync function acquire(params: { scope: SavepointScope }): Promise<OpenSavepoint> {\n const { scope } = params;\n for (;;) {\n assertNotPoisoned({ state: scope.state });\n // SAVEPOINT itself fails with 25P02 on an aborted transaction.\n assertNotAborted({ state: scope.state });\n const open = scope.state.open;\n if (mayProceed({ scope, open })) return pushNode({ scope, parent: open });\n // `mayProceed` returns true for a null `open`, so this is never null here.\n await (open as OpenSavepoint).settled;\n }\n}\n\nfunction pushNode(params: { scope: SavepointScope; parent: OpenSavepoint | null }): OpenSavepoint {\n const { scope, parent } = params;\n const state = scope.state;\n let settle: () => void = () => undefined;\n const settled = new Promise<void>((resolve) => {\n settle = () => resolve();\n });\n // Physical depth follows the connection's stack, not the handle that opened\n // it: a savepoint opened from an outer handle inside a child's callback still\n // nests inside that child.\n const node: OpenSavepoint = {\n scope: { depth: (parent === null ? 0 : parent.scope.depth) + 1, state },\n name: nextSavepointName({ counter: state.counter }),\n parent,\n settled,\n settle,\n };\n state.open = node;\n return node;\n}\n\nfunction closeNode(params: { node: OpenSavepoint }): void {\n const { node } = params;\n const state = node.scope.state;\n if (state.open === node) state.open = node.parent;\n node.settle();\n}\n\n/** Wait out savepoints a callback opened below this node and never awaited. */\nasync function drainDescendants(params: { node: OpenSavepoint }): Promise<void> {\n const state = params.node.scope.state;\n for (;;) {\n const open = state.open;\n if (open === null || open === params.node || open.scope.depth <= params.node.scope.depth) return;\n await open.settled;\n }\n}\n",
|
|
6
|
+
"/**\n * Savepoint lifetimes inside one top-level transaction (F14).\n *\n * A savepoint stack lives on ONE connection: `ROLLBACK TO SAVEPOINT s` undoes\n * everything done after `s`, including work a LATER savepoint already released.\n * Two `transaction()` callbacks opened from the same handle and overlapping in\n * time therefore share that one stack, and the earlier one's rollback silently\n * erases the later one's already committed work. Unique savepoint names do not\n * help — the names never collided, the lifetimes did.\n *\n * The rule enforced here, on every handle of a transaction:\n *\n * > A handle runs when nothing deeper than itself is open. Otherwise it waits\n * > for the innermost open savepoint to settle — unless the call is being made\n * > from INSIDE that savepoint's own callback, which is genuine nesting and\n * > proceeds immediately.\n *\n * The \"from inside\" test is an {@link AsyncLocalStorage} lookup, so the common\n * nesting shapes never wait on themselves: a child opened from its parent's\n * callback, and the parent handle used from within an open child's callback,\n * both proceed. Only genuinely concurrent siblings serialize.\n *\n * Not covered: a callback that awaits a sibling it did not start. That\n * arrangement asks for two savepoints to be open at once, which is exactly what\n * loses work; it now blocks instead. Deliberate — see the notes for this fix.\n *\n * A FAILED `ROLLBACK TO SAVEPOINT` poisons the whole transaction. When the\n * engine cannot undo a savepoint — InnoDB has already rolled the entire\n * transaction back after a deadlock, an implicit-commit DDL cleared every\n * savepoint, the connection dropped — the transaction's outcome is unknown and\n * no handle of it may send another statement: a parent callback that caught\n * the nested error and \"continued\" would otherwise run in autocommit and the\n * final COMMIT would succeed vacuously. Every later turn refuses with the same\n * typed error.\n *\n * An ABORTED transaction (postgres) is tracked here too. PostgreSQL puts the\n * whole transaction into the aborted state after ANY statement error; every\n * later statement fails with 25P02 and `COMMIT` is answered with a `ROLLBACK`\n * command tag and NO error. A callback that catches one statement error and\n * returns normally would therefore \"commit\" nothing while the adapter\n * reported success. The postgres adapters record each driver-reported\n * statement failure at the connection's current savepoint depth\n * ({@link markTransactionAborted}); a `ROLLBACK TO SAVEPOINT` at or above that\n * depth restores the transaction (postgres semantics), and otherwise every\n * later statement, nested savepoint and the commit itself are refused with one\n * typed error carrying the original failure as `cause`. Engines whose\n * transactions survive a statement error (mysql, sqlite) never mark.\n */\n\nimport { AsyncLocalStorage } from \"node:async_hooks\";\nimport { VibeError } from \"@vibeorm/schema\";\nimport { type SavepointCounter, createSavepointCounter, nextSavepointName } from \"./savepoints.ts\";\nimport type { RowChangeCount } from \"../adapter.ts\";\n\n// ─── Types ────────────────────────────────────────────────────────\n\n/**\n * One handle's position in the savepoint stack of a top-level transaction.\n * `state` is shared by reference across every handle of that transaction.\n */\nexport type SavepointScope = {\n /** Physical savepoint depth; 0 is the top-level transaction itself. */\n readonly depth: number;\n /** Shared state: name allocation plus the innermost open savepoint. */\n readonly state: SavepointState;\n};\n\n/** Mutable state shared by every scope of one top-level transaction. */\nexport type SavepointState = {\n /** Savepoint name counter (shared, so names never collide). */\n readonly counter: SavepointCounter;\n /** The innermost savepoint currently open, or `null` when none is. */\n open: OpenSavepoint | null;\n /**\n * Set once a `ROLLBACK TO SAVEPOINT` has failed: the savepoint stack no\n * longer describes the connection, so every later statement and nested\n * savepoint on ANY handle of this transaction is refused with this error.\n */\n poisoned: VibeError | null;\n /**\n * Set once a statement failed on an engine that aborts the whole transaction\n * (postgres): the depth of the innermost savepoint that was open when it\n * failed, and the failure. Cleared by a `ROLLBACK TO SAVEPOINT` at or above\n * that depth; otherwise the commit is refused.\n */\n aborted: AbortedTransaction | null;\n /** Direct effects surviving in this physical transaction, shared by every nested adapter. */\n rowChanges: RowChangeCount;\n};\n\n/** The recorded statement failure that left a postgres transaction aborted. */\nexport type AbortedTransaction = {\n /** Connection depth at the time of the failure; 0 is the top-level transaction. */\n readonly depth: number;\n /** The driver-reported statement failure. */\n readonly cause: unknown;\n};\n\n/** An open savepoint: its handle, its name, and when it finished. */\ntype OpenSavepoint = {\n readonly scope: SavepointScope;\n readonly name: string;\n readonly parent: OpenSavepoint | null;\n readonly settled: Promise<void>;\n readonly settle: () => void;\n rowChangesOnEntry: RowChangeCount;\n};\n\n/**\n * The savepoint whose callback the current async context is running inside.\n * This is the discriminator between genuine nesting (proceed) and an\n * overlapping sibling (wait).\n */\nconst CURRENT = new AsyncLocalStorage<SavepointScope>();\n\n// ─── Public API ───────────────────────────────────────────────────\n\n/** Fresh scope for one top-level transaction: depth 0, nothing open. */\nexport function createSavepointScope(): SavepointScope {\n return { depth: 0, state: { counter: createSavepointCounter(), open: null, poisoned: null, aborted: null, rowChanges: 0 } };\n}\n\n/**\n * Record that a statement failed on an engine that aborts the transaction\n * (postgres). The failure is recorded at the connection's CURRENT depth — the\n * innermost open savepoint, whichever handle sent the statement — because that\n * is the subtransaction postgres marks as failed. The first failure is kept: a\n * later 25P02 is a consequence, not a cause.\n */\nexport function markTransactionAborted(params: { scope: SavepointScope; cause: unknown }): void {\n const state = params.scope.state;\n if (state.aborted !== null) return;\n state.aborted = { depth: state.open?.scope.depth ?? 0, cause: params.cause };\n}\n\n/**\n * The postgres adapters' statement failure path: a SERVER-reported failure (a\n * mapped `VibeError` carrying `meta.sqlstate`) aborts the transaction; a\n * client-side refusal that never reached the server (a budget, a parameter\n * that could not be serialized) leaves it usable. Rethrows either way.\n */\nexport function abortTransactionOnServerFailure(params: { scope: SavepointScope; error: unknown }): never {\n const { scope, error } = params;\n if (error instanceof VibeError && typeof error.meta.sqlstate === \"string\") {\n markTransactionAborted({ scope, cause: error });\n }\n throw error;\n}\n\n/**\n * Run a top-level transaction callback inside its scope's async context, so\n * nested calls made from it can be told apart from calls made inside an open\n * child.\n */\nexport function runRootScope<T>(params: { scope: SavepointScope; body: () => Promise<T> }): Promise<T> {\n return CURRENT.run(params.scope, async () => {\n assertNotPoisoned({ state: params.scope.state });\n const result = await params.body();\n // Adapters commit after this resolves. Catching a nested failure must not\n // allow a poisoned transaction to report successful completion, and a\n // swallowed statement error must not let an ABORTED transaction commit —\n // postgres would answer that COMMIT with a silent ROLLBACK.\n assertNotPoisoned({ state: params.scope.state });\n assertNotAborted({ state: params.scope.state });\n return result;\n });\n}\n\n/**\n * The wait a statement on `scope` owes before it may run, or `undefined` when\n * it may run now. Returning `undefined` keeps the uncontended path — nothing\n * deeper open — free of an extra promise and microtask.\n */\nexport function scopeTurn(params: { scope: SavepointScope }): Promise<void> | undefined {\n assertNotPoisoned({ state: params.scope.state });\n // Postgres would answer with 25P02; refusing here names the ORIGINAL failure\n // and spends no round trip.\n assertNotAborted({ state: params.scope.state });\n const open = params.scope.state.open;\n if (mayProceed({ scope: params.scope, open })) return undefined;\n return waitForTurn({ scope: params.scope });\n}\n\n/**\n * Open a nested savepoint under `scope`, run `body` inside it and release it —\n * rolling back to it if `body` throws, exactly as before this gate existed.\n *\n * `execute` runs the savepoint control SQL (already wrapped in the adapter's\n * own driver-error mapping). Omit it when the driver manages the savepoint\n * itself (bun:sql's `savepoint()`), in which case only the lifetime is gated.\n */\nexport async function runNestedSavepoint<T>(params: {\n readonly scope: SavepointScope;\n readonly execute?: (statement: string) => Promise<unknown> | unknown;\n readonly body: (scope: SavepointScope) => Promise<T>;\n}): Promise<T> {\n const { scope, execute, body } = params;\n const node = await acquire({ scope });\n try {\n try {\n if (execute !== undefined) await execute(`SAVEPOINT ${node.name}`);\n markSavepointOpened({ scope: node.scope });\n const result = await CURRENT.run(node.scope, () => body(node.scope));\n await drainDescendants({ node });\n assertNotPoisoned({ state: scope.state });\n // A failure swallowed inside this callback left the savepoint aborted:\n // RELEASE would fail with 25P02, so roll it back below and report the\n // abort instead of letting the parent continue on a failed subtransaction.\n assertNotAborted({ state: scope.state });\n if (execute !== undefined) await execute(`RELEASE SAVEPOINT ${node.name}`);\n return result;\n } catch (error) {\n // A descendant the callback started but never awaited must finish before\n // this savepoint may be rolled back — releasing out of order corrupts\n // the stack.\n await drainDescendants({ node });\n assertNotPoisoned({ state: scope.state });\n if (execute !== undefined) {\n try {\n await execute(`ROLLBACK TO SAVEPOINT ${node.name}`);\n } catch (rollbackFailure) {\n // The savepoint could not be undone, so the connection's real state is\n // unknown. Poison the transaction (every handle, every later turn) and\n // surface THAT, with the body failure as the cause — rethrowing the\n // body error alone would let the parent callback continue.\n const poisoned = savepointRollbackFailedError({ cause: error, rollbackFailure });\n scope.state.poisoned = poisoned;\n throw poisoned;\n }\n }\n // The savepoint was undone (by the statement above, or by the driver\n // when it manages savepoints itself — a driver-side rollback failure\n // poisons the scope before reaching here). Postgres restores the\n // transaction to the state at this savepoint, which clears an abort that\n // happened at or below it.\n clearAbortedAtOrBelow({ state: scope.state, depth: node.scope.depth });\n scope.state.rowChanges = node.rowChangesOnEntry;\n throw error;\n }\n } finally {\n closeNode({ node });\n }\n}\n\n/** Snapshot after actual SAVEPOINT establishment, including driver-managed savepoint callbacks. */\nexport function markSavepointOpened(params: { readonly scope: SavepointScope }): void {\n const node = params.scope.state.open;\n if (node !== null && node.scope === params.scope) node.rowChangesOnEntry = params.scope.state.rowChanges;\n}\n\n// ─── Errors ───────────────────────────────────────────────────────\n\n/**\n * The refusal raised when `ROLLBACK TO SAVEPOINT` itself fails, and repeated\n * for every later statement on the poisoned transaction. `VIBE_TRANSACTION`\n * with `meta.reason = \"savepoint-rollback-failed\"` and `meta.outcome =\n * \"unknown\"`; `cause` is the body failure that triggered the rollback. The\n * rollback failure's own code (when it is a `VibeError`) rides along as\n * `meta.rollbackErrorCode` — its message is not copied, because a raw driver\n * failure can carry statement text and this error is meant to be logged.\n */\nexport function savepointRollbackFailedError(params: { cause: unknown; rollbackFailure: unknown }): VibeError {\n const { cause, rollbackFailure } = params;\n const rollbackErrorCode =\n rollbackFailure instanceof VibeError ? rollbackFailure.code : undefined;\n return new VibeError({\n code: \"VIBE_TRANSACTION\",\n message:\n \"a nested transaction failed and the ROLLBACK TO SAVEPOINT that should have undone it failed too — \" +\n \"the savepoint stack no longer describes this connection, so the commit state of the whole transaction \" +\n \"is UNKNOWN and no further statement is accepted on any of its handles. The top-level transaction is \" +\n \"being rolled back; nothing is retried automatically.\",\n meta: {\n reason: \"savepoint-rollback-failed\",\n outcome: \"unknown\",\n rollbackFailed: true,\n ...(rollbackErrorCode === undefined ? {} : { rollbackErrorCode }),\n },\n cause,\n });\n}\n\n/** Whether `error` is this module's poison refusal (used to pick the cleanup path). */\nexport function isSavepointRollbackFailedError(error: unknown): boolean {\n const reason = (error as { meta?: { reason?: unknown } } | null)?.meta?.reason;\n return reason === \"savepoint-rollback-failed\";\n}\n\n/**\n * The refusal raised for every statement, nested savepoint and the commit of\n * an aborted postgres transaction. `VIBE_TRANSACTION` with `meta.reason =\n * \"aborted\"` and `meta.outcome = \"rolled-back\"` — the outcome is CERTAIN: the\n * server discards an aborted transaction whatever the client sends. `cause`\n * is the statement failure that aborted it, and its `code`/`sqlstate` ride\n * along in `meta` so a log line names the real defect.\n */\nexport function transactionAbortedError(params: { cause?: unknown }): VibeError {\n const cause = params.cause;\n const causeCode = cause instanceof VibeError ? cause.code : undefined;\n const sqlstate = cause instanceof VibeError && typeof cause.meta.sqlstate === \"string\" ? cause.meta.sqlstate : undefined;\n return new VibeError({\n code: \"VIBE_TRANSACTION\",\n message:\n \"the transaction is aborted: a statement inside it failed and PostgreSQL discards every later statement and the COMMIT itself \" +\n \"(the server answers COMMIT with ROLLBACK and no error). Nothing from this transaction was committed. \" +\n \"Let the failure propagate out of the callback, or run the statement that may fail inside a nested transaction so its savepoint is rolled back.\",\n meta: {\n reason: \"aborted\",\n outcome: \"rolled-back\",\n ...(causeCode === undefined ? {} : { causeCode }),\n ...(sqlstate === undefined ? {} : { sqlstate }),\n },\n ...(cause === undefined ? {} : { cause }),\n });\n}\n\n/** Whether `error` is the aborted-transaction refusal. */\nexport function isTransactionAbortedError(error: unknown): boolean {\n const reason = (error as { meta?: { reason?: unknown } } | null)?.meta?.reason;\n return reason === \"aborted\";\n}\n\n// ─── Internals ────────────────────────────────────────────────────\n\nfunction assertNotPoisoned(params: { state: SavepointState }): void {\n if (params.state.poisoned !== null) throw params.state.poisoned;\n}\n\nfunction assertNotAborted(params: { state: SavepointState }): void {\n if (params.state.aborted !== null) throw transactionAbortedError({ cause: params.state.aborted.cause });\n}\n\n/** `ROLLBACK TO SAVEPOINT` at `depth` undoes everything at or below it. */\nfunction clearAbortedAtOrBelow(params: { state: SavepointState; depth: number }): void {\n const aborted = params.state.aborted;\n if (aborted !== null && aborted.depth >= params.depth) params.state.aborted = null;\n}\n\n/** Whether `scope` may act while `open` is the innermost open savepoint. */\nfunction mayProceed(params: { scope: SavepointScope; open: OpenSavepoint | null }): boolean {\n const { scope, open } = params;\n if (open === null) return true;\n // This handle IS the innermost open savepoint.\n if (open.scope === scope) return true;\n // This handle's own savepoint has already closed (a retained child handle):\n // it can only act at the connection's current depth, and waiting for a\n // shallower savepoint it does not own would never resolve.\n if (open.scope.depth < scope.depth) return true;\n // Genuine nesting: the call is being made from inside the open callback.\n return CURRENT.getStore() === open.scope;\n}\n\nasync function waitForTurn(params: { scope: SavepointScope }): Promise<void> {\n for (;;) {\n assertNotPoisoned({ state: params.scope.state });\n const open = params.scope.state.open;\n if (open === null || mayProceed({ scope: params.scope, open })) return;\n await open.settled;\n }\n}\n\n/**\n * Wait for this handle's turn and take it in the SAME synchronous step — the\n * check and the push must not be separated by an await, or two waiters woken\n * together would both open a savepoint.\n */\nasync function acquire(params: { scope: SavepointScope }): Promise<OpenSavepoint> {\n const { scope } = params;\n for (;;) {\n assertNotPoisoned({ state: scope.state });\n // SAVEPOINT itself fails with 25P02 on an aborted transaction.\n assertNotAborted({ state: scope.state });\n const open = scope.state.open;\n if (mayProceed({ scope, open })) return pushNode({ scope, parent: open });\n // `mayProceed` returns true for a null `open`, so this is never null here.\n await (open as OpenSavepoint).settled;\n }\n}\n\nfunction pushNode(params: { scope: SavepointScope; parent: OpenSavepoint | null }): OpenSavepoint {\n const { scope, parent } = params;\n const state = scope.state;\n let settle: () => void = () => undefined;\n const settled = new Promise<void>((resolve) => {\n settle = () => resolve();\n });\n // Physical depth follows the connection's stack, not the handle that opened\n // it: a savepoint opened from an outer handle inside a child's callback still\n // nests inside that child.\n const node: OpenSavepoint = {\n scope: { depth: (parent === null ? 0 : parent.scope.depth) + 1, state },\n name: nextSavepointName({ counter: state.counter }),\n parent,\n settled,\n settle,\n rowChangesOnEntry: state.rowChanges,\n };\n state.open = node;\n return node;\n}\n\nfunction closeNode(params: { node: OpenSavepoint }): void {\n const { node } = params;\n const state = node.scope.state;\n if (state.open === node) state.open = node.parent;\n node.settle();\n}\n\n/** Wait out savepoints a callback opened below this node and never awaited. */\nasync function drainDescendants(params: { node: OpenSavepoint }): Promise<void> {\n const state = params.node.scope.state;\n for (;;) {\n const open = state.open;\n if (open === null || open === params.node || open.scope.depth <= params.node.scope.depth) return;\n await open.settled;\n }\n}\n",
|
|
7
7
|
"/**\n * The nested-transaction option contract — ONE copy, shared by every adapter\n * through `@vibeorm/runtime/adapter-kit` (CORE-B-03). It used to live as six\n * hand-synchronised copies, one per adapter; a fourth option would have had\n * to be refused six times.\n */\n\nimport { VibeError } from \"@vibeorm/schema\";\nimport type { TransactionOptions } from \"../adapter.ts\";\n\n/**\n * Refuse options on a NESTED `transaction()` call — the same contract on every\n * adapter (see the `DatabaseAdapter.transaction` JSDoc in `adapter.ts`): a\n * nested transaction is a SAVEPOINT, and a savepoint can neither change the\n * isolation level of the transaction it joins, enforce its own timeout, nor\n * carry its own deadline. Silently dropping the option hid exactly that.\n *\n * @throws VibeError `VIBE_VALIDATION` when `isolationLevel`, `timeout` or\n * `deadline` is present (an `undefined` or empty options object is accepted).\n */\nexport function refuseNestedTransactionOptions(params: {\n options?: TransactionOptions;\n provider: string;\n}): void {\n const { options, provider } = params;\n if (options === undefined) return;\n\n const passed: string[] = [];\n if (options.isolationLevel !== undefined) passed.push(\"isolationLevel\");\n if (options.timeout !== undefined) passed.push(\"timeout\");\n if (options.deadline !== undefined) passed.push(\"deadline\");\n if (passed.length === 0) return;\n\n const meta: Record<string, unknown> = { provider, nested: true };\n if (options.isolationLevel !== undefined) meta.isolationLevel = options.isolationLevel;\n if (options.timeout !== undefined) meta.timeout = options.timeout;\n if (options.deadline !== undefined) meta.deadline = options.deadline;\n\n throw new VibeError({\n code: \"VIBE_VALIDATION\",\n message: `nested transactions run as savepoints and cannot honor ${passed.join(\" or \")} — a savepoint cannot change the isolation level of the transaction it joins, a nested timeout is not enforceable, and a nested deadline would need its own session setting on a connection it does not own (it inherits the top-level one instead); pass options on the top-level $transaction`,\n meta,\n });\n}\n",
|
|
8
8
|
"/**\n * Transaction budgets — the total-deadline clock and the handle-closure gate.\n *\n * ONE copy, shared by every adapter package through the\n * `@vibeorm/runtime/adapter-kit` subpath (like `savepoint-gate.ts`), so a\n * change here reaches all engines at once — a per-adapter copy would drift\n * into a silent per-engine behaviour difference.\n *\n * WHAT A DEADLINE IS, AND IS NOT\n *\n * `TransactionOptions.timeout` is unchanged: a PER-STATEMENT engine-side bound.\n * `TransactionOptions.deadline` is new and different — a TOTAL wall-clock bound\n * on one top-level transaction. Its clock starts immediately before `BEGIN` is\n * sent, so connection acquisition (which has its own budget on the pooled\n * adapters) is deliberately NOT counted.\n *\n * Enforcement is never `Promise.race` over a statement that keeps running:\n *\n * - `\"between-statements\"` (the default, and all six adapters can deliver it):\n * before every statement, every nested `transaction()` and the `COMMIT`, an\n * expired budget refuses. The statement is never sent and the transaction is\n * rolled back. A statement ALREADY IN FLIGHT is not interrupted.\n * - `\"cancel-running-statements\"` (postgres servers only): additionally hands\n * the engine the remaining budget as `statement_timeout`, so the SERVER\n * cancels an over-long statement. An adapter that cannot do this refuses the\n * request outright rather than quietly delivering the weaker level.\n *\n * JavaScript cannot forcibly stop a running callback. A callback that keeps\n * going past the deadline finds its later database calls refused; work it does\n * outside the database (an HTTP call, an SMS) is not stopped and cannot be.\n * There is no automatic retry: a deadline failure is terminal for that\n * transaction, because external side effects may already have happened.\n */\n\nimport { VibeError } from \"@vibeorm/schema\";\nimport type {\n TransactionDeadlineEnforcement,\n TransactionDeadlineSupport,\n TransactionOptions,\n} from \"../adapter.ts\";\n\n// ─── Types ────────────────────────────────────────────────────────\n\n/** Where a budget check happened, reported as `meta.stage`. */\nexport type BudgetStage = \"statement\" | \"nested\" | \"commit\";\n\n/**\n * What is known about a finished transaction. `\"unknown\"` is a first-class\n * outcome, not a failure to decide: when a rollback itself fails the commit\n * state genuinely cannot be asserted, and claiming \"rolled back\" would be a lie.\n */\nexport type TransactionOutcome = \"committed\" | \"rolled-back\" | \"unknown\";\n\n/** Wall clock, injectable so tests are deterministic instead of sleep-timed. */\nexport type DeadlineClock = () => number;\n\n/** The ambient clock, used whenever no seam is injected. */\nexport const DEFAULT_DEADLINE_CLOCK: DeadlineClock = (): number => Date.now();\n\n/**\n * One top-level transaction's budget. Nested savepoint handles share this\n * object BY REFERENCE — they never get an independent clock, connection or\n * session setting.\n */\nexport type TransactionBudget = {\n /** The enforcement level in force, or `null` when no deadline was requested. */\n readonly enforcement: TransactionDeadlineEnforcement | null;\n /** The requested total budget in milliseconds, or `null` when none was. */\n readonly totalMs: number | null;\n /** Existing per-statement limit, independent of the total deadline. Zero disables it. */\n readonly statementTimeoutMs: number | null;\n /** Milliseconds left (never negative), or `null` when no deadline is set. */\n remainingMs(): number | null;\n /** True only when a deadline is set and has passed. */\n expired(): boolean;\n /** Refuse a closed handle or an expired budget. Called BEFORE anything is sent. */\n assertUsable(params: { stage: BudgetStage }): void;\n /** Record the terminal outcome; the first call wins and later ones are ignored. */\n close(params: { outcome: TransactionOutcome }): void;\n /** The recorded outcome, or `null` while the transaction is still open. */\n readonly outcome: TransactionOutcome | null;\n};\n\n// ─── Validation (before BEGIN, before any write) ──────────────────\n\n/**\n * Check `options.deadline` against what this adapter can honestly deliver.\n * Called BEFORE `BEGIN` — a budget this engine cannot honour must never leave\n * a transaction open behind it.\n *\n * @throws VibeError `VIBE_VALIDATION` when `totalMs` is not a positive integer.\n * @throws VibeError `VIBE_UNSUPPORTED_CAPABILITY` when the requested\n * `enforcement` is stronger than `support` — refused, never silently degraded.\n */\nexport function validateTransactionDeadline(params: {\n options?: TransactionOptions;\n support: TransactionDeadlineSupport;\n provider: string;\n}): void {\n const { options, support, provider } = params;\n const deadline = options?.deadline;\n if (deadline === undefined) return;\n\n if (support === \"unsupported\") {\n throw new VibeError({\n code: \"VIBE_UNSUPPORTED_CAPABILITY\",\n message: `${provider} cannot enforce a transaction deadline — remove the \\`deadline\\` option`,\n meta: { provider, feature: \"transactionDeadline\", supported: support },\n });\n }\n\n if (!Number.isInteger(deadline.totalMs) || deadline.totalMs <= 0) {\n throw new VibeError({\n code: \"VIBE_VALIDATION\",\n message: `transaction deadline \\`totalMs\\` must be a positive integer of milliseconds, received ${String(deadline.totalMs)}`,\n meta: { provider, feature: \"transactionDeadline\", totalMs: deadline.totalMs },\n });\n }\n\n const requested: TransactionDeadlineEnforcement = deadline.enforcement ?? \"between-statements\";\n if (requested === \"cancel-running-statements\" && support !== \"cancel-running-statements\") {\n throw new VibeError({\n code: \"VIBE_UNSUPPORTED_CAPABILITY\",\n message:\n `${provider} cannot cancel a statement that is already running, so the requested ` +\n \"`cancel-running-statements` deadline guarantee is refused rather than silently downgraded — \" +\n 'ask for \"between-statements\" if a budget checked between statements is enough',\n meta: { provider, feature: \"transactionDeadline\", requested, supported: support },\n });\n }\n}\n\n// ─── The budget ───────────────────────────────────────────────────\n\n/**\n * Start the clock for one top-level transaction. Call it immediately before\n * `BEGIN`; {@link validateTransactionDeadline} must already have run.\n */\nexport function startTransactionBudget(params: {\n options?: TransactionOptions;\n provider: string;\n clock?: DeadlineClock;\n}): TransactionBudget {\n const { options, provider } = params;\n const clock = params.clock ?? DEFAULT_DEADLINE_CLOCK;\n const deadline = options?.deadline;\n const totalMs = deadline === undefined ? null : deadline.totalMs;\n const enforcement: TransactionDeadlineEnforcement | null =\n deadline === undefined ? null : (deadline.enforcement ?? \"between-statements\");\n const expiresAt = totalMs === null ? null : clock() + totalMs;\n let outcome: TransactionOutcome | null = null;\n\n const budget: TransactionBudget = {\n enforcement,\n totalMs,\n statementTimeoutMs: options?.timeout ?? null,\n remainingMs(): number | null {\n return expiresAt === null ? null : Math.max(0, expiresAt - clock());\n },\n expired(): boolean {\n return expiresAt !== null && clock() >= expiresAt;\n },\n assertUsable(assertParams: { stage: BudgetStage }): void {\n if (outcome !== null) {\n throw transactionClosedError({ provider, outcome, stage: assertParams.stage });\n }\n if (expiresAt !== null && clock() >= expiresAt) {\n throw transactionDeadlineError({\n provider,\n stage: assertParams.stage,\n totalMs: totalMs as number,\n overdueMs: clock() - expiresAt,\n });\n }\n },\n close(closeParams: { outcome: TransactionOutcome }): void {\n if (outcome === null) outcome = closeParams.outcome;\n },\n get outcome(): TransactionOutcome | null {\n return outcome;\n },\n };\n return budget;\n}\n\n/**\n * The engine-side bound for the NEXT statement, or `null` when the caller did\n * not buy `\"cancel-running-statements\"`. Floored at 1 ms: on postgres `0` means\n * \"no limit\", so a spent budget must never be handed over as a zero.\n */\nexport function engineStatementBudgetMs(params: { budget: TransactionBudget }): number | null {\n const { budget } = params;\n if (budget.enforcement !== \"cancel-running-statements\") return null;\n const remaining = budget.remainingMs();\n if (remaining === null) return null;\n const totalBound = Math.max(1, Math.ceil(remaining));\n return budget.statementTimeoutMs !== null && budget.statementTimeoutMs > 0\n ? Math.min(totalBound, budget.statementTimeoutMs) : totalBound;\n}\n\n// ─── Errors ───────────────────────────────────────────────────────\n\n/**\n * The refusal an expired budget raises. `VIBE_TRANSACTION` with a stable\n * `meta.reason` — no SQL text, no parameter values, no credentials.\n */\nexport function transactionDeadlineError(params: {\n provider: string;\n stage: BudgetStage;\n totalMs: number;\n overdueMs: number;\n}): VibeError {\n const { provider, stage, totalMs, overdueMs } = params;\n const what =\n stage === \"commit\"\n ? \"the transaction was rolled back instead of committed\"\n : \"the statement was never sent and the transaction is being rolled back\";\n return new VibeError({\n code: \"VIBE_TRANSACTION\",\n message:\n `transaction deadline of ${totalMs} ms expired ${Math.max(0, Math.round(overdueMs))} ms ago — ${what}. ` +\n \"Nothing is retried automatically: work the callback did outside the database may already have happened.\",\n meta: { provider, reason: \"transaction-deadline\", stage, totalMs, overdueMs: Math.max(0, Math.round(overdueMs)) },\n });\n}\n\n/**\n * The refusal an ESCAPED transaction handle raises — a transactional adapter\n * kept past the end of its transaction. Without this it would run on a\n * connection that is back in the pool, outside any transaction.\n */\nexport function transactionClosedError(params: {\n provider: string;\n outcome: TransactionOutcome;\n stage: BudgetStage;\n}): VibeError {\n const { provider, outcome, stage } = params;\n return new VibeError({\n code: \"VIBE_TRANSACTION\",\n message:\n `this transaction has already finished (${outcome}), so its client can no longer be used — ` +\n \"a handle kept past the end of `$transaction` would run outside the transaction, on a connection \" +\n \"that now belongs to someone else\",\n meta: { provider, reason: \"transaction-closed\", outcome, stage },\n });\n}\n\n/**\n * The stable typed outcome for \"the deadline expired and the rollback that was\n * supposed to clean up failed too\". Promising a rollback here would be false;\n * promising a retry would be worse.\n *\n * `cause` is the CAUSAL error (the deadline refusal), so the reason the\n * transaction was being abandoned survives. The rollback failure itself is\n * reported only as `meta.rollbackFailed`: a raw driver failure can carry\n * statement text, and this error is meant to be logged.\n */\nexport function transactionOutcomeUnknownError(params: {\n provider: string;\n totalMs: number;\n cause: unknown;\n}): VibeError {\n const { provider, totalMs, cause } = params;\n return new VibeError({\n code: \"VIBE_TRANSACTION\",\n message:\n `transaction deadline of ${totalMs} ms expired and the rollback that should have cleaned up failed — ` +\n \"the commit state of this transaction is UNKNOWN. It is not retried automatically; inspect the data \" +\n \"before deciding.\",\n meta: {\n provider,\n reason: \"transaction-outcome-unknown\",\n outcome: \"unknown\",\n totalMs,\n rollbackFailed: true,\n },\n cause,\n });\n}\n\n/** Whether `error` is this module's deadline refusal (used to pick the cleanup path). */\nexport function isTransactionDeadlineError(error: unknown): boolean {\n const reason = (error as { meta?: { reason?: unknown } } | null)?.meta?.reason;\n return reason === \"transaction-deadline\";\n}\n",
|
|
9
|
+
"import type { RowChangeCount, StatementEffect } from \"../adapter.ts\";\nimport type { SavepointScope } from \"./savepoint-gate.ts\";\n\n/** Only structured intent attests complete direct effects; raw command tags do not. */\nexport function statementRowChanges(params: {\n readonly effect?: StatementEffect;\n readonly count?: unknown;\n readonly command?: string;\n}): RowChangeCount {\n const { effect, count } = params;\n if (effect === \"read\") return 0;\n if (effect !== \"write\") return \"unknown\";\n return typeof count === \"number\" && Number.isSafeInteger(count) && count >= 0 ? count : \"unknown\";\n}\n\n/** Fold one successfully executed direct effect into its physical transaction's surviving tally. */\nexport function observeRowChanges(params: { readonly scope: SavepointScope; readonly count: RowChangeCount }): void {\n const state = params.scope.state;\n if (state.rowChanges === \"unknown\") return;\n const count = params.count;\n if (count === \"unknown\" || !Number.isSafeInteger(count) || count < 0 || !Number.isSafeInteger(state.rowChanges + count)) {\n state.rowChanges = \"unknown\";\n return;\n }\n state.rowChanges += count;\n}\n\n/**\n * Observe one synchronous driver dispatch that forbids reentrant writes on the\n * same connection. Failed writes can retain partial effects, so mark unknown\n * before stepping and restore the snapshot only after successful attestation.\n */\nexport function dispatchSynchronousRowChanges<T>(params: {\n readonly scope?: SavepointScope;\n readonly effect?: StatementEffect;\n readonly run: () => T;\n readonly count: (result: T) => RowChangeCount;\n}): T {\n const { scope } = params;\n if (scope === undefined) return params.run();\n const before = scope.state.rowChanges;\n if (params.effect !== \"read\") scope.state.rowChanges = \"unknown\";\n const result = params.run();\n const count = params.count(result);\n scope.state.rowChanges = before;\n observeRowChanges({ scope, count });\n return result;\n}\n\n/** Tentative surviving effects; poisoned/aborted transactions cannot supply a trusted numeric sample. */\nexport function readRowChanges(params: { readonly scope: SavepointScope }): RowChangeCount {\n const state = params.scope.state;\n return state.poisoned !== null || state.aborted !== null ? \"unknown\" : state.rowChanges;\n}\n",
|
|
9
10
|
"import { VibeError } from \"@vibeorm/schema\";\nimport type { SqlExecutor } from \"../adapter.ts\";\n\n/** Own one physical session until the callback and dispatched work have settled. */\nexport function runPinnedSession<T>(params: {\n readonly execute: SqlExecutor;\n readonly run: (executor: SqlExecutor) => Promise<T>;\n readonly release: () => Promise<void>;\n readonly isLost: (error: unknown) => boolean;\n}): Promise<T> {\n let active = true;\n let lost: VibeError | undefined;\n let tail: Promise<void> = Promise.resolve();\n const executor: SqlExecutor = (query) => {\n const result = tail.then(async () => {\n if (lost !== undefined) throw lost;\n if (!active) throw new VibeError({\n code: \"VIBE_ADAPTER\",\n message: \"The reserved database session has finished; acquire a new session before executing SQL.\",\n meta: { reason: \"session-closed\" },\n });\n return params.execute(query).catch((cause: unknown) => {\n if (params.isLost(cause)) {\n lost = new VibeError({\n code: \"VIBE_ADAPTER\",\n message: \"The reserved database session was lost. No further SQL will be sent; inspect migration progress before retrying.\",\n meta: { reason: \"session-lost\", outcome: \"unknown\" },\n cause,\n });\n throw lost;\n }\n throw cause;\n });\n });\n tail = result.then(() => undefined, () => undefined);\n return result;\n };\n const settle = async (): Promise<void> => {\n active = false;\n await tail;\n };\n // The migration's own failure stays the primary outcome (the e643012 rule):\n // the operator acts on ITS verdict — session-lost, outcome unknown — not on\n // cleanup. A release failure rides along as evidence.\n const fail = async (cause: unknown): Promise<never> => {\n await params.release().catch((cleanupCause: unknown) => {\n throw withCleanupCause({ cause, cleanupCause });\n });\n throw cause;\n };\n return Promise.resolve().then(() => params.run(executor)).then(\n async (result) => {\n await settle();\n if (lost !== undefined) return fail(lost);\n await params.release();\n return result;\n },\n async (cause: unknown) => {\n await settle();\n return fail(cause);\n },\n );\n}\n\n/**\n * Rethrow `cause` with `cleanupCause` attached as `meta.cleanupCause` when it\n * is a `VibeError`; a foreign failure is rethrown as is (its identity matters\n * more than the evidence — callers matched it, never the cleanup).\n */\nexport function withCleanupCause(params: { cause: unknown; cleanupCause: unknown }): unknown {\n const { cause, cleanupCause } = params;\n if (cause instanceof VibeError) {\n return new VibeError({ code: cause.code, message: cause.message, meta: { ...cause.meta, cleanupCause }, cause });\n }\n return cause;\n}\n",
|
|
10
11
|
"import { VibeError } from \"@vibeorm/schema\";\nimport { SQLITE_SESSION_SQL } from \"@vibeorm/sql\";\nimport type { SqlExecutor } from \"../adapter.ts\";\nimport { runPinnedSession, withCleanupCause } from \"./session.ts\";\n\n/** Hold SQLite's native file lock across transaction boundaries, then restore it. */\nexport async function runSqliteSession<T>(params: {\n readonly execute: SqlExecutor;\n readonly run: (executor: SqlExecutor) => Promise<T>;\n readonly inTransaction: () => boolean;\n}): Promise<T> {\n if (params.inTransaction()) throw new VibeError({\n code: \"VIBE_TRANSACTION\",\n message: \"A migration session cannot borrow a SQLite connection with an open transaction.\",\n meta: { reason: \"session-in-transaction\" },\n });\n const rows = await params.execute({ text: SQLITE_SESSION_SQL.lockingMode, values: [] });\n const mode = rows[0]?.locking_mode;\n if (mode !== \"normal\" && mode !== \"exclusive\") throw new VibeError({\n code: \"VIBE_ADAPTER\",\n message: \"SQLite did not report its locking mode; no migration was started.\",\n meta: { reason: \"session-lock-mode\" },\n });\n await params.execute({ text: SQLITE_SESSION_SQL.exclusive });\n const restore = async (): Promise<void> => {\n if (params.inTransaction()) await params.execute({ text: SQLITE_SESSION_SQL.rollback });\n await params.execute({ text: SQLITE_SESSION_SQL.foreignKeysOn });\n if (mode === \"normal\") {\n await params.execute({ text: SQLITE_SESSION_SQL.normal });\n // NORMAL alone does not release the lock: SQLite requires a database read.\n await params.execute({ text: SQLITE_SESSION_SQL.touch, values: [] });\n }\n };\n return Promise.resolve().then(async () => {\n // The transaction acquires the file lock; EXCLUSIVE retains it after COMMIT.\n await params.execute({ text: SQLITE_SESSION_SQL.acquire });\n await params.execute({ text: SQLITE_SESSION_SQL.commit });\n return runPinnedSession({\n execute: params.execute,\n run: params.run,\n isLost: () => false, // The captured native handle never reconnects.\n release: async () => {\n if (params.inTransaction()) await params.execute({ text: SQLITE_SESSION_SQL.rollback });\n },\n });\n }).then(\n async (result) => {\n await restore();\n return result;\n },\n async (cause: unknown) => {\n // The migration's own failure stays primary; a restore failure (the\n // database is locked or read-only by now) rides along as evidence.\n await restore().catch((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SAAS,CAAC;AAAA,IACtF,MAAM,OAAO,QAAQ,EAAE,MAAM,mBAAmB,cAAc,CAAC;AAAA,IAC/D,IAAI,SAAS,UAAU;AAAA,MACrB,MAAM,OAAO,QAAQ,EAAE,MAAM,mBAAmB,OAAO,CAAC;AAAA,MAExD,MAAM,OAAO,QAAQ,EAAE,MAAM,mBAAmB,OAAO,QAAQ,CAAC,EAAE,CAAC;AAAA,IACrE;AAAA;AAAA,EAEF,OAAO,QAAQ,QAAQ,EAAE,KAAK,YAAY;AAAA,IAExC,MAAM,OAAO,QAAQ,EAAE,MAAM,mBAAmB,QAAQ,CAAC;AAAA,IACzD,MAAM,OAAO,QAAQ,EAAE,MAAM,mBAAmB,OAAO,CAAC;AAAA,IACxD,OAAO,iBAAiB;AAAA,MACtB,SAAS,OAAO;AAAA,MAChB,KAAK,OAAO;AAAA,MACZ,QAAQ,MAAM;AAAA,MACd,SAAS,YAAY;AAAA,QACnB,IAAI,OAAO,cAAc;AAAA,UAAG,MAAM,OAAO,QAAQ,EAAE,MAAM,mBAAmB,SAAS,CAAC;AAAA;AAAA,IAE1F,CAAC;AAAA,GACF,EAAE,KACD,OAAO,WAAW;AAAA,IAChB,MAAM,QAAQ;AAAA,IACd,OAAO;AAAA,KAET,OAAO,UAAmB;AAAA,IAGxB,MAAM,QAAQ,EAAE,MAAM,CAAC,iBAA0B;AAAA,MAC/C,MAAM,iBAAiB,EAAE,OAAO,aAAa,CAAC;AAAA,KAC/C;AAAA,IACD,MAAM;AAAA,GAEV;AAAA;",
|
|
14
|
+
"debugId": "9043FC0FD9D8EA9E64756E2164756E21",
|
|
14
15
|
"names": []
|
|
15
16
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { RowChangeCount, StatementEffect } from "../adapter.ts";
|
|
2
|
+
import type { SavepointScope } from "./savepoint-gate.ts";
|
|
3
|
+
/** Only structured intent attests complete direct effects; raw command tags do not. */
|
|
4
|
+
export declare function statementRowChanges(params: {
|
|
5
|
+
readonly effect?: StatementEffect;
|
|
6
|
+
readonly count?: unknown;
|
|
7
|
+
readonly command?: string;
|
|
8
|
+
}): RowChangeCount;
|
|
9
|
+
/** Fold one successfully executed direct effect into its physical transaction's surviving tally. */
|
|
10
|
+
export declare function observeRowChanges(params: {
|
|
11
|
+
readonly scope: SavepointScope;
|
|
12
|
+
readonly count: RowChangeCount;
|
|
13
|
+
}): void;
|
|
14
|
+
/**
|
|
15
|
+
* Observe one synchronous driver dispatch that forbids reentrant writes on the
|
|
16
|
+
* same connection. Failed writes can retain partial effects, so mark unknown
|
|
17
|
+
* before stepping and restore the snapshot only after successful attestation.
|
|
18
|
+
*/
|
|
19
|
+
export declare function dispatchSynchronousRowChanges<T>(params: {
|
|
20
|
+
readonly scope?: SavepointScope;
|
|
21
|
+
readonly effect?: StatementEffect;
|
|
22
|
+
readonly run: () => T;
|
|
23
|
+
readonly count: (result: T) => RowChangeCount;
|
|
24
|
+
}): T;
|
|
25
|
+
/** Tentative surviving effects; poisoned/aborted transactions cannot supply a trusted numeric sample. */
|
|
26
|
+
export declare function readRowChanges(params: {
|
|
27
|
+
readonly scope: SavepointScope;
|
|
28
|
+
}): RowChangeCount;
|
|
29
|
+
//# sourceMappingURL=row-changes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"row-changes.d.ts","sourceRoot":"","sources":["../../src/adapter-kit/row-changes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,uFAAuF;AACvF,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAC1C,QAAQ,CAAC,MAAM,CAAC,EAAE,eAAe,CAAC;IAClC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B,GAAG,cAAc,CAKjB;AAED,oGAAoG;AACpG,wBAAgB,iBAAiB,CAAC,MAAM,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAA;CAAE,GAAG,IAAI,CASlH;AAED;;;;GAIG;AACH,wBAAgB,6BAA6B,CAAC,CAAC,EAAE,MAAM,EAAE;IACvD,QAAQ,CAAC,KAAK,CAAC,EAAE,cAAc,CAAC;IAChC,QAAQ,CAAC,MAAM,CAAC,EAAE,eAAe,CAAC;IAClC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,cAAc,CAAC;CAC/C,GAAG,CAAC,CAUJ;AAED,yGAAyG;AACzG,wBAAgB,cAAc,CAAC,MAAM,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAA;CAAE,GAAG,cAAc,CAGzF"}
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
*/
|
|
49
49
|
import { VibeError } from "@vibeorm/schema";
|
|
50
50
|
import { type SavepointCounter } from "./savepoints.ts";
|
|
51
|
+
import type { RowChangeCount } from "../adapter.ts";
|
|
51
52
|
/**
|
|
52
53
|
* One handle's position in the savepoint stack of a top-level transaction.
|
|
53
54
|
* `state` is shared by reference across every handle of that transaction.
|
|
@@ -77,6 +78,8 @@ export type SavepointState = {
|
|
|
77
78
|
* that depth; otherwise the commit is refused.
|
|
78
79
|
*/
|
|
79
80
|
aborted: AbortedTransaction | null;
|
|
81
|
+
/** Direct effects surviving in this physical transaction, shared by every nested adapter. */
|
|
82
|
+
rowChanges: RowChangeCount;
|
|
80
83
|
};
|
|
81
84
|
/** The recorded statement failure that left a postgres transaction aborted. */
|
|
82
85
|
export type AbortedTransaction = {
|
|
@@ -92,6 +95,7 @@ type OpenSavepoint = {
|
|
|
92
95
|
readonly parent: OpenSavepoint | null;
|
|
93
96
|
readonly settled: Promise<void>;
|
|
94
97
|
readonly settle: () => void;
|
|
98
|
+
rowChangesOnEntry: RowChangeCount;
|
|
95
99
|
};
|
|
96
100
|
/** Fresh scope for one top-level transaction: depth 0, nothing open. */
|
|
97
101
|
export declare function createSavepointScope(): SavepointScope;
|
|
@@ -146,6 +150,10 @@ export declare function runNestedSavepoint<T>(params: {
|
|
|
146
150
|
readonly execute?: (statement: string) => Promise<unknown> | unknown;
|
|
147
151
|
readonly body: (scope: SavepointScope) => Promise<T>;
|
|
148
152
|
}): Promise<T>;
|
|
153
|
+
/** Snapshot after actual SAVEPOINT establishment, including driver-managed savepoint callbacks. */
|
|
154
|
+
export declare function markSavepointOpened(params: {
|
|
155
|
+
readonly scope: SavepointScope;
|
|
156
|
+
}): void;
|
|
149
157
|
/**
|
|
150
158
|
* The refusal raised when `ROLLBACK TO SAVEPOINT` itself fails, and repeated
|
|
151
159
|
* for every later statement on the poisoned transaction. `VIBE_TRANSACTION`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"savepoint-gate.d.ts","sourceRoot":"","sources":["../../src/adapter-kit/savepoint-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,KAAK,gBAAgB,EAA6C,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"savepoint-gate.d.ts","sourceRoot":"","sources":["../../src/adapter-kit/savepoint-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,KAAK,gBAAgB,EAA6C,MAAM,iBAAiB,CAAC;AACnG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAIpD;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AAK,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,SAAS,CAkB9E;AAED,0DAA0D;AAC1D,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAGjE"}
|
package/dist/adapter.d.ts
CHANGED
|
@@ -101,6 +101,10 @@ export type AdapterBudgetSupport = {
|
|
|
101
101
|
/** What `TransactionOptions.deadline.enforcement` may ask for on this engine. */
|
|
102
102
|
readonly transactionDeadline: TransactionDeadlineSupport;
|
|
103
103
|
};
|
|
104
|
+
/** Surviving direct DML effects, or an honest unknown when observation is incomplete. */
|
|
105
|
+
export type RowChangeCount = number | "unknown";
|
|
106
|
+
/** Internal structured execution intent. Never accepted as an ORM/raw query argument. */
|
|
107
|
+
export type StatementEffect = "read" | "write" | "unknown";
|
|
104
108
|
/** Result of an unsafe/raw execution: rows plus affected-row count. */
|
|
105
109
|
export type QueryResult = {
|
|
106
110
|
rows: Record<string, unknown>[];
|
|
@@ -136,6 +140,7 @@ export type DatabaseAdapter = {
|
|
|
136
140
|
execute(params: {
|
|
137
141
|
text: string;
|
|
138
142
|
values: unknown[];
|
|
143
|
+
effect?: StatementEffect;
|
|
139
144
|
}): Promise<Record<string, unknown>[]>;
|
|
140
145
|
/**
|
|
141
146
|
* Execute a raw query (`$queryRaw*`, `$executeRaw*`, DDL). No statement
|
|
@@ -156,6 +161,7 @@ export type DatabaseAdapter = {
|
|
|
156
161
|
executeUnsafe(params: {
|
|
157
162
|
text: string;
|
|
158
163
|
values?: unknown[];
|
|
164
|
+
effect?: StatementEffect;
|
|
159
165
|
}): Promise<QueryResult>;
|
|
160
166
|
/**
|
|
161
167
|
* ORM-path execution (same protocol and parameter serialization as
|
|
@@ -178,6 +184,7 @@ export type DatabaseAdapter = {
|
|
|
178
184
|
executeAffected?(params: {
|
|
179
185
|
text: string;
|
|
180
186
|
values: unknown[];
|
|
187
|
+
effect?: StatementEffect;
|
|
181
188
|
}): Promise<QueryResult>;
|
|
182
189
|
/**
|
|
183
190
|
* Bound raw execution with raw-path serialization and raw-session affinity.
|
|
@@ -188,7 +195,14 @@ export type DatabaseAdapter = {
|
|
|
188
195
|
executeRawBound?(params: {
|
|
189
196
|
text: string;
|
|
190
197
|
values: unknown[];
|
|
198
|
+
effect?: StatementEffect;
|
|
191
199
|
}): Promise<QueryResult>;
|
|
200
|
+
/**
|
|
201
|
+
* Optional active physical-transaction observation. Reads add zero, direct
|
|
202
|
+
* effects accumulate and confirmed savepoint rollback restores its entry tally.
|
|
203
|
+
* A numeric sample is tentative until confirmed commit. Missing support is unknown.
|
|
204
|
+
*/
|
|
205
|
+
readonly rowChanges?: () => RowChangeCount;
|
|
192
206
|
/**
|
|
193
207
|
* What timing budgets this adapter actually enforces (EPIC 6).
|
|
194
208
|
*
|
package/dist/adapter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAa,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAIjD,wEAAwE;AACxE,MAAM,MAAM,cAAc,GAAG,eAAe,GAAG,gBAAgB,GAAG,cAAc,CAAC;AAEjF;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,8BAA8B,GAAG,oBAAoB,GAAG,2BAA2B,CAAC;AAEhG;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,6CAA6C;IAC7C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,0CAA0C;IAC1C,QAAQ,CAAC,WAAW,CAAC,EAAE,8BAA8B,CAAC;CACvD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC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,CAAC;AAErF;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE;IAAE,OAAO,EAAE,eAAe,CAAA;CAAE,GAAG,WAAW,CAe/E"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Map well-formed text to a signed 64-bit advisory-lock key: SHA-256 of exact
|
|
3
|
+
* UTF-8 bytes, first eight digest bytes, big-endian two's complement. No Unicode
|
|
4
|
+
* normalization is applied. Hash collisions remain possible; prefix resource
|
|
5
|
+
* families explicitly. This does not change the existing numeric/two-key spaces.
|
|
6
|
+
*/
|
|
7
|
+
export declare function advisoryKeyOf(params: {
|
|
8
|
+
readonly text: string;
|
|
9
|
+
}): bigint;
|
|
10
|
+
//# sourceMappingURL=advisory-key.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"advisory-key.d.ts","sourceRoot":"","sources":["../src/advisory-key.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAkBvE"}
|
package/dist/advisory-lock.d.ts
CHANGED
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
* runs — the lock is taken and gone (probe-verified: a second session took
|
|
21
21
|
* the same key immediately afterwards). That is a silent no-op, so the call
|
|
22
22
|
* is refused instead.
|
|
23
|
-
* 3. **Numeric
|
|
24
|
-
*
|
|
25
|
-
*
|
|
23
|
+
* 3. **Numeric lock methods.** Text hashing is explicit through advisoryKeyOf;
|
|
24
|
+
* its stable mapping can collide. Prefix resource families and own the key
|
|
25
|
+
* space deliberately rather than implicitly hashing every supplied string.
|
|
26
26
|
*/
|
|
27
27
|
import type { AdvisoryLockMode } from "@vibeorm/schema";
|
|
28
28
|
import type { AdvisoryLockStatement, SqlDialect } from "@vibeorm/sql";
|
package/dist/client.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { KeysetPage } from "./find-page.ts";
|
|
1
2
|
import type { SqlFragment, ResultDecoder } from "@vibeorm/sql";
|
|
2
3
|
import type { SchemaIR } from "@vibeorm/schema";
|
|
3
4
|
import type { AdvisoryLockOptions } from "./advisory-lock.ts";
|
|
@@ -120,6 +121,7 @@ export type BatchResult = {
|
|
|
120
121
|
*/
|
|
121
122
|
export type ModelDelegate = {
|
|
122
123
|
readonly findMany: (args?: ClientRow) => Promise<ClientRow[]>;
|
|
124
|
+
readonly findPage: (args: ClientRow) => Promise<KeysetPage<ClientRow>>;
|
|
123
125
|
readonly findFirst: (args?: ClientRow) => Promise<ClientRow | null>;
|
|
124
126
|
readonly findFirstOrThrow: (args?: ClientRow) => Promise<ClientRow>;
|
|
125
127
|
readonly findUnique: (args: ClientRow) => Promise<ClientRow | null>;
|
|
@@ -157,6 +159,7 @@ export type ModelDelegate = {
|
|
|
157
159
|
*/
|
|
158
160
|
export type ReadOnlyModelDelegate = {
|
|
159
161
|
readonly findMany: (args?: ClientRow) => Promise<ClientRow[]>;
|
|
162
|
+
readonly findPage: (args: ClientRow) => Promise<KeysetPage<ClientRow>>;
|
|
160
163
|
readonly findFirst: (args?: ClientRow) => Promise<ClientRow | null>;
|
|
161
164
|
readonly findFirstOrThrow: (args?: ClientRow) => Promise<ClientRow>;
|
|
162
165
|
readonly findUnique: (args: ClientRow) => Promise<ClientRow | null>;
|