@vibeorm/adapter-mysql 2.0.0-alpha.8 → 2.0.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.
@@ -0,0 +1,144 @@
1
+ /**
2
+ * Transaction budgets — the total-deadline clock and the handle-closure gate.
3
+ *
4
+ * BYTE-IDENTICAL in all six adapter packages, exactly like `savepoint-gate.ts`:
5
+ * adapters depend on `@vibeorm/runtime` for TYPES only, so a shared value
6
+ * module there would invert the dependency direction, and `@vibeorm/schema` is
7
+ * the IR package, not a home for a transaction clock. Keep the six copies in
8
+ * lockstep — a divergence here is a silent per-engine behaviour difference.
9
+ *
10
+ * WHAT A DEADLINE IS, AND IS NOT
11
+ *
12
+ * `TransactionOptions.timeout` is unchanged: a PER-STATEMENT engine-side bound.
13
+ * `TransactionOptions.deadline` is new and different — a TOTAL wall-clock bound
14
+ * on one top-level transaction. Its clock starts immediately before `BEGIN` is
15
+ * sent, so connection acquisition (which has its own budget on the pooled
16
+ * adapters) is deliberately NOT counted.
17
+ *
18
+ * Enforcement is never `Promise.race` over a statement that keeps running:
19
+ *
20
+ * - `"between-statements"` (the default, and all six adapters can deliver it):
21
+ * before every statement, every nested `transaction()` and the `COMMIT`, an
22
+ * expired budget refuses. The statement is never sent and the transaction is
23
+ * rolled back. A statement ALREADY IN FLIGHT is not interrupted.
24
+ * - `"cancel-running-statements"` (postgres servers only): additionally hands
25
+ * the engine the remaining budget as `statement_timeout`, so the SERVER
26
+ * cancels an over-long statement. An adapter that cannot do this refuses the
27
+ * request outright rather than quietly delivering the weaker level.
28
+ *
29
+ * JavaScript cannot forcibly stop a running callback. A callback that keeps
30
+ * going past the deadline finds its later database calls refused; work it does
31
+ * outside the database (an HTTP call, an SMS) is not stopped and cannot be.
32
+ * There is no automatic retry: a deadline failure is terminal for that
33
+ * transaction, because external side effects may already have happened.
34
+ */
35
+ import type { TransactionDeadlineEnforcement, TransactionDeadlineSupport, TransactionOptions } from "@vibeorm/runtime";
36
+ import { VibeError } from "@vibeorm/schema";
37
+ /** Where a budget check happened, reported as `meta.stage`. */
38
+ export type BudgetStage = "statement" | "nested" | "commit";
39
+ /**
40
+ * What is known about a finished transaction. `"unknown"` is a first-class
41
+ * outcome, not a failure to decide: when a rollback itself fails the commit
42
+ * state genuinely cannot be asserted, and claiming "rolled back" would be a lie.
43
+ */
44
+ export type TransactionOutcome = "committed" | "rolled-back" | "unknown";
45
+ /** Wall clock, injectable so tests are deterministic instead of sleep-timed. */
46
+ export type DeadlineClock = () => number;
47
+ /** The ambient clock, used whenever no seam is injected. */
48
+ export declare const DEFAULT_DEADLINE_CLOCK: DeadlineClock;
49
+ /**
50
+ * One top-level transaction's budget. Nested savepoint handles share this
51
+ * object BY REFERENCE — they never get an independent clock, connection or
52
+ * session setting.
53
+ */
54
+ export type TransactionBudget = {
55
+ /** The enforcement level in force, or `null` when no deadline was requested. */
56
+ readonly enforcement: TransactionDeadlineEnforcement | null;
57
+ /** The requested total budget in milliseconds, or `null` when none was. */
58
+ readonly totalMs: number | null;
59
+ /** Existing per-statement limit, independent of the total deadline. Zero disables it. */
60
+ readonly statementTimeoutMs: number | null;
61
+ /** Milliseconds left (never negative), or `null` when no deadline is set. */
62
+ remainingMs(): number | null;
63
+ /** True only when a deadline is set and has passed. */
64
+ expired(): boolean;
65
+ /** Refuse a closed handle or an expired budget. Called BEFORE anything is sent. */
66
+ assertUsable(params: {
67
+ stage: BudgetStage;
68
+ }): void;
69
+ /** Record the terminal outcome; the first call wins and later ones are ignored. */
70
+ close(params: {
71
+ outcome: TransactionOutcome;
72
+ }): void;
73
+ /** The recorded outcome, or `null` while the transaction is still open. */
74
+ readonly outcome: TransactionOutcome | null;
75
+ };
76
+ /**
77
+ * Check `options.deadline` against what this adapter can honestly deliver.
78
+ * Called BEFORE `BEGIN` — a budget this engine cannot honour must never leave
79
+ * a transaction open behind it.
80
+ *
81
+ * @throws VibeError `VIBE_VALIDATION` when `totalMs` is not a positive integer.
82
+ * @throws VibeError `VIBE_UNSUPPORTED_CAPABILITY` when the requested
83
+ * `enforcement` is stronger than `support` — refused, never silently degraded.
84
+ */
85
+ export declare function validateTransactionDeadline(params: {
86
+ options?: TransactionOptions;
87
+ support: TransactionDeadlineSupport;
88
+ provider: string;
89
+ }): void;
90
+ /**
91
+ * Start the clock for one top-level transaction. Call it immediately before
92
+ * `BEGIN`; {@link validateTransactionDeadline} must already have run.
93
+ */
94
+ export declare function startTransactionBudget(params: {
95
+ options?: TransactionOptions;
96
+ provider: string;
97
+ clock?: DeadlineClock;
98
+ }): TransactionBudget;
99
+ /**
100
+ * The engine-side bound for the NEXT statement, or `null` when the caller did
101
+ * not buy `"cancel-running-statements"`. Floored at 1 ms: on postgres `0` means
102
+ * "no limit", so a spent budget must never be handed over as a zero.
103
+ */
104
+ export declare function engineStatementBudgetMs(params: {
105
+ budget: TransactionBudget;
106
+ }): number | null;
107
+ /**
108
+ * The refusal an expired budget raises. `VIBE_TRANSACTION` with a stable
109
+ * `meta.reason` — no SQL text, no parameter values, no credentials.
110
+ */
111
+ export declare function transactionDeadlineError(params: {
112
+ provider: string;
113
+ stage: BudgetStage;
114
+ totalMs: number;
115
+ overdueMs: number;
116
+ }): VibeError;
117
+ /**
118
+ * The refusal an ESCAPED transaction handle raises — a transactional adapter
119
+ * kept past the end of its transaction. Without this it would run on a
120
+ * connection that is back in the pool, outside any transaction.
121
+ */
122
+ export declare function transactionClosedError(params: {
123
+ provider: string;
124
+ outcome: TransactionOutcome;
125
+ stage: BudgetStage;
126
+ }): VibeError;
127
+ /**
128
+ * The stable typed outcome for "the deadline expired and the rollback that was
129
+ * supposed to clean up failed too". Promising a rollback here would be false;
130
+ * promising a retry would be worse.
131
+ *
132
+ * `cause` is the CAUSAL error (the deadline refusal), so the reason the
133
+ * transaction was being abandoned survives. The rollback failure itself is
134
+ * reported only as `meta.rollbackFailed`: a raw driver failure can carry
135
+ * statement text, and this error is meant to be logged.
136
+ */
137
+ export declare function transactionOutcomeUnknownError(params: {
138
+ provider: string;
139
+ totalMs: number;
140
+ cause: unknown;
141
+ }): VibeError;
142
+ /** Whether `error` is this module's deadline refusal (used to pick the cleanup path). */
143
+ export declare function isTransactionDeadlineError(error: unknown): boolean;
144
+ //# sourceMappingURL=transaction-budget.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction-budget.d.ts","sourceRoot":"","sources":["../src/transaction-budget.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,KAAK,EACV,8BAA8B,EAC9B,0BAA0B,EAC1B,kBAAkB,EACnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,+DAA+D;AAC/D,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE5D;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,WAAW,GAAG,aAAa,GAAG,SAAS,CAAC;AAEzE,gFAAgF;AAChF,MAAM,MAAM,aAAa,GAAG,MAAM,MAAM,CAAC;AAEzC,4DAA4D;AAC5D,eAAO,MAAM,sBAAsB,EAAE,aAAwC,CAAC;AAE9E;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,gFAAgF;IAChF,QAAQ,CAAC,WAAW,EAAE,8BAA8B,GAAG,IAAI,CAAC;IAC5D,2EAA2E;IAC3E,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,yFAAyF;IACzF,QAAQ,CAAC,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3C,6EAA6E;IAC7E,WAAW,IAAI,MAAM,GAAG,IAAI,CAAC;IAC7B,uDAAuD;IACvD,OAAO,IAAI,OAAO,CAAC;IACnB,mFAAmF;IACnF,YAAY,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,WAAW,CAAA;KAAE,GAAG,IAAI,CAAC;IACn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,CAiBZ;AAED,yFAAyF;AACzF,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAGlE"}
@@ -1 +1 @@
1
- {"version":3,"file":"transaction-sql.d.ts","sourceRoot":"","sources":["../src/transaction-sql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAG3E,+DAA+D;AAC/D,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,CAIvE,CAAC;AAEH;;;;;;;;;;;;GAYG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE;IAAE,cAAc,EAAE,cAAc,CAAA;CAAE,GAAG,MAAM,CAE7F;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAU7E;AAED;;;;GAIG;AACH,eAAO,MAAM,4BAA4B,EAAE,MAAmD,CAAC;AAI/F,+EAA+E;AAC/E,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAK5D;;;;;;;;;;;GAWG;AACH,wBAAgB,6BAA6B,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,qBAAqB,CAI7F;AAID;;;;;;;;;GASG;AACH,wBAAgB,8BAA8B,CAAC,MAAM,EAAE;IACrD,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,IAAI,CAkBP"}
1
+ {"version":3,"file":"transaction-sql.d.ts","sourceRoot":"","sources":["../src/transaction-sql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAG3E,+DAA+D;AAC/D,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,CAIvE,CAAC;AAEH;;;;;;;;;;;;GAYG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE;IAAE,cAAc,EAAE,cAAc,CAAA;CAAE,GAAG,MAAM,CAE7F;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAU7E;AAED;;;;GAIG;AACH,eAAO,MAAM,4BAA4B,EAAE,MAAmD,CAAC;AAI/F,+EAA+E;AAC/E,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAK5D;;;;;;;;;;;GAWG;AACH,wBAAgB,6BAA6B,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,qBAAqB,CAI7F;AAID;;;;;;;;;GASG;AACH,wBAAgB,8BAA8B,CAAC,MAAM,EAAE;IACrD,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,IAAI,CAoBP"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibeorm/adapter-mysql",
3
- "version": "2.0.0-alpha.8",
3
+ "version": "2.0.0",
4
4
  "description": "mysql2 adapter for VibeORM v2",
5
5
  "keywords": [
6
6
  "orm",
@@ -42,8 +42,8 @@
42
42
  "bun": ">=1.2.0"
43
43
  },
44
44
  "dependencies": {
45
- "@vibeorm/runtime": "2.0.0-alpha.8",
46
- "@vibeorm/schema": "2.0.0-alpha.6",
45
+ "@vibeorm/runtime": "2.0.0",
46
+ "@vibeorm/schema": "2.0.0",
47
47
  "mysql2": "^3.15.0"
48
48
  },
49
49
  "publishConfig": {