@vibeorm/adapter-mysql 2.0.0-alpha.1 → 2.0.0-alpha.10
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/dist/acquire.d.ts +73 -0
- package/dist/acquire.d.ts.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +529 -34
- package/dist/index.js.map +9 -5
- package/dist/placeholders.d.ts +70 -0
- package/dist/placeholders.d.ts.map +1 -0
- package/dist/savepoint-gate.d.ts +86 -0
- package/dist/savepoint-gate.d.ts.map +1 -0
- package/dist/transaction-budget.d.ts +144 -0
- package/dist/transaction-budget.d.ts.map +1 -0
- package/dist/transaction-sql.d.ts.map +1 -1
- package/package.json +4 -3
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bounded pool acquisition — the adapter's own acquire timeout.
|
|
3
|
+
*
|
|
4
|
+
* mysql2 has NO acquire timeout of its own (verified against mysql2 3.23.3:
|
|
5
|
+
* neither `acquireTimeout` nor `acquire_timeout` exists anywhere in its
|
|
6
|
+
* sources). Its pool backpressure knobs are `waitForConnections`
|
|
7
|
+
* (`node_modules/mysql2/lib/pool_config.js:11-14`, default `true`) and
|
|
8
|
+
* `queueLimit` (`:24-26`, default `0` = unlimited), which bounds queue DEPTH,
|
|
9
|
+
* not TIME; `connectTimeout` is the TCP deadline for establishing a NEW
|
|
10
|
+
* connection, not for waiting on a busy pool. So an exhausted pool queues the
|
|
11
|
+
* caller forever unless something above the driver bounds the wait — which is
|
|
12
|
+
* what this module does.
|
|
13
|
+
*
|
|
14
|
+
* The trap this module exists to get right: when the deadline wins the race,
|
|
15
|
+
* the driver's `getConnection()` promise is STILL PENDING and will later hand
|
|
16
|
+
* back a real connection nobody holds. Dropping it would turn "waits too long"
|
|
17
|
+
* into "the pool is dead forever", so the losing promise is always released.
|
|
18
|
+
*/
|
|
19
|
+
import { VibeError } from "@vibeorm/schema";
|
|
20
|
+
/** Timer handle, as the ambient `setTimeout` returns it. */
|
|
21
|
+
export type TimerHandle = ReturnType<typeof setTimeout>;
|
|
22
|
+
/**
|
|
23
|
+
* Timer seam — a test injects a counting pair to prove the deadline timer is
|
|
24
|
+
* cleared exactly once, rather than asserting on wall-clock luck.
|
|
25
|
+
*/
|
|
26
|
+
export type AcquireTimers = {
|
|
27
|
+
readonly set: (fn: () => void, ms: number) => TimerHandle;
|
|
28
|
+
readonly clear: (handle: TimerHandle) => void;
|
|
29
|
+
};
|
|
30
|
+
/** The ambient timers, used whenever no seam is injected. */
|
|
31
|
+
export declare const DEFAULT_ACQUIRE_TIMERS: AcquireTimers;
|
|
32
|
+
/** The one connection capability the late-release path needs. */
|
|
33
|
+
export type ReleasableConnection = {
|
|
34
|
+
release(): void;
|
|
35
|
+
};
|
|
36
|
+
/** The one pool capability bounded acquisition needs. */
|
|
37
|
+
export type AcquireSource<TConnection extends ReleasableConnection> = {
|
|
38
|
+
getConnection(): Promise<TConnection>;
|
|
39
|
+
};
|
|
40
|
+
/** mysql2's own pool default when `connectionLimit` is unset (`lib/pool_config.js:15-17`). */
|
|
41
|
+
export declare const MYSQL_DEFAULT_CONNECTION_LIMIT: number;
|
|
42
|
+
/**
|
|
43
|
+
* The refusal a bounded acquisition raises. `VIBE_ADAPTER` for parity with
|
|
44
|
+
* `@vibeorm/adapter-pg`, whose `connectionTimeout` surfaces the same way, and
|
|
45
|
+
* `meta.reason: "acquire-timeout"` so a caller can tell an exhausted pool from
|
|
46
|
+
* any other adapter failure without reading message text.
|
|
47
|
+
*/
|
|
48
|
+
export declare function acquireTimeoutError(params: {
|
|
49
|
+
timeoutMs: number;
|
|
50
|
+
poolSize?: number;
|
|
51
|
+
}): VibeError;
|
|
52
|
+
/**
|
|
53
|
+
* Check a connection out of `pool`, refusing with {@link acquireTimeoutError}
|
|
54
|
+
* when it takes longer than `timeoutMs`.
|
|
55
|
+
*
|
|
56
|
+
* Two invariants make this safe:
|
|
57
|
+
*
|
|
58
|
+
* 1. **The lost acquire is released.** When the deadline wins, the pending
|
|
59
|
+
* `getConnection()` is not abandoned: a handler released it as soon as it
|
|
60
|
+
* lands, so a `connectionLimit: 1` pool keeps working after a timeout
|
|
61
|
+
* instead of being permanently starved of its only connection.
|
|
62
|
+
* 2. **The deadline timer never outlives the call.** It is cleared in a
|
|
63
|
+
* `finally`, so a successful acquire leaves nothing pending that could keep
|
|
64
|
+
* the event loop (or a test runner) alive.
|
|
65
|
+
*/
|
|
66
|
+
export declare function acquireWithTimeout<TConnection extends ReleasableConnection>(params: {
|
|
67
|
+
pool: AcquireSource<TConnection>;
|
|
68
|
+
timeoutMs: number;
|
|
69
|
+
/** Effective pool size, named in the refusal; omit when the pool is the caller's. */
|
|
70
|
+
poolSize?: number;
|
|
71
|
+
timers?: AcquireTimers;
|
|
72
|
+
}): Promise<TConnection>;
|
|
73
|
+
//# sourceMappingURL=acquire.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acquire.d.ts","sourceRoot":"","sources":["../src/acquire.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,4DAA4D;AAC5D,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;AAExD;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,MAAM,IAAI,EAAE,EAAE,EAAE,MAAM,KAAK,WAAW,CAAC;IAC1D,QAAQ,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,CAAC;CAC/C,CAAC;AAEF,6DAA6D;AAC7D,eAAO,MAAM,sBAAsB,EAAE,aAGnC,CAAC;AAEH,iEAAiE;AACjE,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,IAAI,IAAI,CAAC;CACjB,CAAC;AAEF,yDAAyD;AACzD,MAAM,MAAM,aAAa,CAAC,WAAW,SAAS,oBAAoB,IAAI;IACpE,aAAa,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC;CACvC,CAAC;AAIF,8FAA8F;AAC9F,eAAO,MAAM,8BAA8B,EAAE,MAAW,CAAC;AAEzD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAkB/F;AAID;;;;;;;;;;;;;GAaG;AACH,wBAAsB,kBAAkB,CAAC,WAAW,SAAS,oBAAoB,EAAE,MAAM,EAAE;IACzF,IAAI,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,qFAAqF;IACrF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB,GAAG,OAAO,CAAC,WAAW,CAAC,CAiCvB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -110,6 +110,26 @@ export type MysqlAdapterOptions = {
|
|
|
110
110
|
readonly timezone?: string;
|
|
111
111
|
/** Connection charset/collation (mysql2 default `utf8mb4_general_ci`). */
|
|
112
112
|
readonly charset?: string;
|
|
113
|
+
/**
|
|
114
|
+
* Milliseconds to wait for a pool connection before refusing with a
|
|
115
|
+
* `VibeError` (`VIBE_ADAPTER`, `meta.reason: "acquire-timeout"`).
|
|
116
|
+
*
|
|
117
|
+
* **Unset (the default) keeps mysql2's own behaviour**: the pool is created
|
|
118
|
+
* with `waitForConnections: true` and no time bound, so a caller whose
|
|
119
|
+
* connections are all busy QUEUES until one frees. Setting this bounds EVERY
|
|
120
|
+
* pool checkout the adapter makes — the caller gets a coded refusal instead
|
|
121
|
+
* of an unbounded wait.
|
|
122
|
+
*
|
|
123
|
+
* Adapter-owned: mysql2 has no acquire timeout at all (its pool knobs are
|
|
124
|
+
* `waitForConnections` and `queueLimit`, which bounds queue DEPTH, not time),
|
|
125
|
+
* so this value is never passed to `mysql2.createPool`.
|
|
126
|
+
*
|
|
127
|
+
* **Not mysql2's `connectTimeout`**, which is the deadline for establishing a
|
|
128
|
+
* NEW connection rather than for waiting on a busy pool. The equivalent
|
|
129
|
+
* option on `@vibeorm/adapter-pg` is `connectionTimeout`; the name differs
|
|
130
|
+
* here precisely because mysql2 already uses that word for something else.
|
|
131
|
+
*/
|
|
132
|
+
readonly acquireTimeout?: number;
|
|
113
133
|
/**
|
|
114
134
|
* Allow multiple statements per `executeUnsafe` call (default false). Leave
|
|
115
135
|
* it off: the ORM never batches, @vibeorm/migrate applies DDL per statement,
|
|
@@ -150,10 +170,14 @@ export type MysqlAdapterOptions = {
|
|
|
150
170
|
* is a string. The adapter forwards values verbatim — no second conversion.
|
|
151
171
|
*/
|
|
152
172
|
export declare function mysqlAdapter(options?: MysqlAdapterOptions): DatabaseAdapter;
|
|
173
|
+
export { DEFAULT_ACQUIRE_TIMERS, MYSQL_DEFAULT_CONNECTION_LIMIT, acquireTimeoutError, acquireWithTimeout, } from "./acquire.ts";
|
|
174
|
+
export type { AcquireSource, AcquireTimers, ReleasableConnection, TimerHandle } from "./acquire.ts";
|
|
153
175
|
export { MYSQL_ERRNO_ERROR_CODES, MYSQL_ERRNO_REASONS, mapMysqlDriverError, mysqlErrorErrno, runMapped, } from "./errors.ts";
|
|
154
176
|
export { isResultSetHeader, normalizeDriverResult } from "./results.ts";
|
|
155
177
|
export { createSavepointCounter, nextSavepointName } from "./savepoints.ts";
|
|
156
178
|
export type { SavepointCounter } from "./savepoints.ts";
|
|
157
179
|
export { ISOLATION_LEVEL_SQL, RESET_MAX_EXECUTION_TIME_SQL, classifyRawTransactionControl, maxExecutionTimeStatement, refuseNestedTransactionOptions, setIsolationLevelStatement, } from "./transaction-sql.ts";
|
|
158
180
|
export type { RawTransactionControl } from "./transaction-sql.ts";
|
|
181
|
+
export { DEFAULT_DEADLINE_CLOCK, engineStatementBudgetMs, isTransactionDeadlineError, startTransactionBudget, transactionClosedError, transactionDeadlineError, transactionOutcomeUnknownError, validateTransactionDeadline, } from "./transaction-budget.ts";
|
|
182
|
+
export type { BudgetStage, DeadlineClock, TransactionBudget, TransactionOutcome } from "./transaction-budget.ts";
|
|
159
183
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAEV,eAAe,EAIhB,MAAM,kBAAkB,CAAC;AAgC1B,gEAAgE;AAChE,MAAM,MAAM,mBAAmB,GAAG;IAChC,8EAA8E;IAC9E,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;IACvE,mEAAmE;IACnE,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;IACrE,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACxB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,OAAO,IAAI,IAAI,CAAC;IAChB,OAAO,IAAI,IAAI,CAAC;CACjB,CAAC;AAEF,8DAA8D;AAC9D,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,CAA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