@voltro/sql-mysql 0.42.0 → 0.43.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/CHANGELOG.md +91 -0
- package/dist/index.d.ts +24 -1
- package/dist/index.js +165 -127
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -39,6 +39,97 @@ _Changes staged for the next release accumulate here (rolled up from
|
|
|
39
39
|
|
|
40
40
|
---
|
|
41
41
|
|
|
42
|
+
## [0.43.0] — 2026-08-18
|
|
43
|
+
|
|
44
|
+
### ⚠ BREAKING
|
|
45
|
+
|
|
46
|
+
- **@voltro/data-transfer, @voltro/cli** — `DanglingReferenceError` is now `RowsRefusedError`, and it separates the rows that failed from the rows that failed because those rows did.
|
|
47
|
+
|
|
48
|
+
**The name.** The import raised it for EVERY row still refused after deferred-FK resolution, whatever the reason — a NOT NULL violation, a duplicate key, a value the database computes for itself. The tag named ONE possible cause and put it where a reader looks first, so any other refusal arrived mislabelled. The new name states the outcome; each row's `reason` states the cause, which is where a cause can honestly be claimed.
|
|
49
|
+
|
|
50
|
+
**The split.** A row is `derived` when one of its reference columns holds the primary key of another row that also failed in this run: it could not have landed whatever it contained, so its reason describes the parent's problem. The relation is transitive, decided from the DATA (the failed ids against the reference-typed values), so no schema knowledge is needed. `primaryCount` is the number an operator acts on, `rows` lists primary failures FIRST so the cap never spends its budget on consequences, and the CLI leads with both numbers:
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
import refused 300 row(s), of which 1 are the actual failures — the rest could
|
|
54
|
+
not land because a row they reference did not.
|
|
55
|
+
teams t1 foreign key teams_ibfk_1: the referenced row does not exist [1452]
|
|
56
|
+
… and 299 row(s) behind them. Fix the 1 above and re-run; they resolve with
|
|
57
|
+
their parents.
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
In an FK-dense bundle one refused parent takes its whole subtree with it, so the length of a flat list says how connected the data is, not how many problems there are — and the single row that explains all of them sits somewhere in the middle of it.
|
|
61
|
+
|
|
62
|
+
The codemod rewrites the import and every use of the symbol. It does NOT rewrite a tag STRING (`Effect.catchTag('DanglingReferenceError', …)`, `err._tag === '…'`) — change those to `'RowsRefusedError'` — and the payload gained `primaryCount` plus a `derived` flag per row.
|
|
63
|
+
|
|
64
|
+
### Fixed
|
|
65
|
+
|
|
66
|
+
- **@voltro/cli** — `voltro doctor`'s `subject-write-no-guard` rule reads the DESCRIPTOR before it reports. It looked only at the executor, and the access decision is not declared there.
|
|
67
|
+
|
|
68
|
+
Every form of access decision the framework has — `internal: true`, `guards: [...]`, `openAccess:` — is declared on the DESCRIPTOR. So an app that declares them properly got a finding for each one, and on a codebase whose procedures are mostly `internal: true` the rule fires on essentially all of them and is wrong essentially every time.
|
|
69
|
+
|
|
70
|
+
That is worse than a rule that finds nothing: it is the longest line in the report and it reads like a security finding, so it teaches the reader to skim the place a real finding would have appeared.
|
|
71
|
+
|
|
72
|
+
The premise was structurally impossible for most of them, and the framework says so itself: `security.defaultDeny` refuses at boot any wire-exposed procedure declaring neither `guards:` nor `openAccess:`. So "an anonymous caller reaches the write" can only be true of an `openAccess` procedure. That is what the rule looks for now — plus the handler check it always honoured, plus an ownership comparison against `subject.id`, which is the refusal the rule says is missing. Where no descriptor can be read, it says nothing: the claim is about a declaration, and a finding whose evidence was never opened is the failure mode this fixes.
|
|
73
|
+
|
|
74
|
+
The `use:` line changed with it. It recommended `.guard(requireScope('…'))`; the shipped guide teaches declarative `guards:` and calls a hand-written per-executor scope check the thing `guards:` exists to delete. A rule may not recommend the shape the guide argues against.
|
|
75
|
+
- **@voltro/database, @voltro/data-transfer** — A `voltro data` transfer no longer carries GENERATED column values, and no longer loses every row that has one.
|
|
76
|
+
|
|
77
|
+
The export wrote the computed values into the bundle and the import sent them back in the `INSERT` column list. MariaDB refuses that for any value except NULL (`1906: The value specified for generated column 'x' in table 't' has been ignored`); postgres refuses a non-DEFAULT value outright. So the transfer failed per ROW, not per table, and only for the rows whose generated value was non-NULL.
|
|
78
|
+
|
|
79
|
+
That selectivity is the dangerous part. `.uniqueActive()` lowers to exactly such a column on mysql/mariadb — a STORED generated column holding the key while the row is live and NULL once it is soft-deleted — so the refused rows are the LIVE ones and the accepted ones are the tombstones. A table can come out looking like "a few rows failed" or empty, depending only on how many of its rows are deleted, and any table with a foreign key into it fails behind it.
|
|
80
|
+
|
|
81
|
+
Both ends are fixed from one source of truth: **introspection now reports generated columns on every dialect** (`generatedAs`, from `information_schema.generation_expression` on mysql/mariadb, `is_generated` on postgres, `PRAGMA table_xinfo`'s hidden flag on sqlite, `sys.computed_columns` on mssql). It was declared-side only before — invisible to the planner, which does not compare it, and load-bearing for anything that writes rows back.
|
|
82
|
+
|
|
83
|
+
The exporter omits those columns, values and all. The importer strips them from every incoming row using the TARGET's snapshot, because a bundle already written still carries them and a file on disk is data, read where it is.
|
|
84
|
+
|
|
85
|
+
**`voltro serve`'s admin export/import needed a second fix, and without it this one reached only the direct transport.** The running instance hands those handlers `declaredSnapshot(tables)` — no dialect — and `.uniqueActive()` lowers to a generated column only when the snapshot knows the engine. So over `--target api` the snapshot described a schema with no generated columns while the database had several, and the export wrote their values back into the bundle exactly as before. It passes the dialect now (the variable was already on the next line).
|
|
86
|
+
|
|
87
|
+
`generatedAs` is also kept OUT of the schema fingerprint. Introspection can read the fact back but not a comparable value — the engine returns its own normalisation of the expression, never the declared spelling — so hashing it would make declared and live disagree permanently: a schema nobody touched reporting a changed declaration on every boot, and a transfer target that matches its bundle exactly refused as drifted.
|
|
88
|
+
|
|
89
|
+
Covered by a live mariadb→mariadb and mysql→mysql round trip over a `.uniqueActive()` table with live and soft-deleted rows, asserting the target recomputed the value rather than that the row merely arrived.
|
|
90
|
+
- **@voltro/sql-mysql** — On mysql/mariadb, a write REJECTED by the database through `insertIgnore` was reported as a conflict when the caller was not inside a transaction — and never reached the caller as a typed `ConstraintViolation` at all.
|
|
91
|
+
|
|
92
|
+
Two causes, both measured against live MySQL 8.4 and MariaDB 11.
|
|
93
|
+
|
|
94
|
+
**The connection.** `INSERT IGNORE` demotes every error to a warning, so the store reads `SHOW WARNINGS` to tell a rejection from a conflict. That describes the last statement on a CONNECTION, and outside a transaction every statement acquires its own from the pool — so the read was unattributable and came back empty. The rejected write then surfaced as "the insert was skipped as a conflict, but no existing row matches conflictColumns […] the constraint that fired is unknown", whose enumeration lists only conflict causes. A rejection described as a conflict is the exact sentence this path was fixed once already for producing; it survived on the path that had no transaction to read on. The store now pins one connection for the whole decision — the same pinning `insertRecoverAutoId` does for `LAST_INSERT_ID()`.
|
|
95
|
+
|
|
96
|
+
**The classification.** The store swallowed the driver's error and raised a prose one of its own, so `classifyConstraintViolation` had nothing to read: this was the one write path where the typed error could not fire, while every other one produced it. The warning IS the driver's payload — `INSERT IGNORE` only changed how it was delivered — so it is handed on in the shape the driver would have thrown. A rejection now arrives as the same `ConstraintViolation { kind: 'foreignKey', … }` a plain `insert` produces. Nothing new crosses the wire: the classifier extracts the constraint NAME as a delimited group, never the sentence.
|
|
97
|
+
|
|
98
|
+
This is the default `voltro data import` path (`--mode append`, `--on-conflict skip`, without `--atomic`), so a row rejected by a foreign key was reported to the operator as a conflict with an unknown cause.
|
|
99
|
+
|
|
100
|
+
`constraintViolation.integration.test.ts` now asserts the `insertIgnore` seam per dialect against live postgres 17, MySQL 8.4, MariaDB 11 and SQL Server 2022. It was the missing assertion behind a claim derived from the wiring — the classification does sit on all ten write paths, which is not the same as a classifiable error arriving on all ten.
|
|
101
|
+
- **@voltro/protocol, @voltro/runtime** — The framework's store errors — `ConstraintViolation`, `TenantScopeViolation`, `TenantRowNotFound`, `ServerOnlyColumnWrite`, `TableValidationFailed`, `StoreOperationFailed` — are exported from `@voltro/protocol` and can therefore be declared in a descriptor's `error:` union. They could not be.
|
|
102
|
+
|
|
103
|
+
They lived in `@voltro/runtime`, which reaches `node:child_process`, `node:http` and `node:crypto`. A descriptor is loaded VALUE-LEVEL by the web client (the `RpcClient` needs every procedure's Schema), so a descriptor importing from there is refused at boot by the browser-safety guard — correctly. The typed half of these errors was therefore unreachable: the docs told you to declare them, and the boot said no.
|
|
104
|
+
|
|
105
|
+
What that leaves is the untyped half only. The error still arrives as an `InternalError` carrying a readable sentence, so telling `foreignKey` ("the row you picked is gone") from `foreignKeyInUse` ("this row is still referenced") — two different messages for the user — means parsing that sentence. Over a set of generated delete mutations that is a string comparison per procedure, which is the thing the typed error exists to delete.
|
|
106
|
+
|
|
107
|
+
`@voltro/runtime` re-exports all six, so server code is unchanged. The classes have no server dependency of any kind — the file imports `Schema` from `effect` and nothing else, and `browserSafetyGuard.test.ts` now pins a descriptor that declares one, so moving them back reads as a boot failure rather than as a passing rename.
|
|
108
|
+
- **@voltro/database, @voltro/sql-mysql** — A blocked `alter-column-type` told every dialect to write a postgres cast.
|
|
109
|
+
|
|
110
|
+
The refusal is correct — a bare type change may not be value-preserving, so it is refused until acknowledged. Its `fix:` line was not:
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
acknowledge it on the column: `.narrowedFrom('json', { using: 'meta::text' })`
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
`USING <expr>` is postgres syntax and a postgres capability. The mysql arm of the applier emits `MODIFY COLUMN`, the mssql arm `ALTER COLUMN`, and sqlite rebuilds the table — none of them can carry a cast expression and none of them reads `using`. So an operator on any other engine was handed a line to paste into their schema containing syntax their database has never seen, inside an argument that is discarded. A refusal is read as an instruction, and the more carefully it is read the more thoroughly a wrong one is followed.
|
|
117
|
+
|
|
118
|
+
The fix line is dialect-aware now: postgres keeps the `using` half, everything else gets `.narrowedFrom('<type>')` plus the fact that the engine converts in place — because a refusal that offers no expressible fix reads as "the framework cannot do this at all".
|
|
119
|
+
|
|
120
|
+
Covered on live MySQL and MariaDB by both halves at once: what the refusal SAYS, and that following it applies AND converges with the row intact. A message test alone would keep passing over a broken apply; a convergence test alone is what let the wrong message survive this long.
|
|
121
|
+
|
|
122
|
+
Also on the same path: `upsert` with a PARTIAL row (one omitting a NOT NULL column that has no default) failed on MariaDB and succeeded on MySQL. The native `INSERT … ON DUPLICATE KEY UPDATE` validates its insert half even when only the update half runs, so the row was rejected although the target existed and only needed patching. A partial row takes the lookup path on both engines now; the single-statement form still covers the complete-row case, which is what a data transfer and every generated CRUD write send.
|
|
123
|
+
- **@voltro/sql-mysql** — On MariaDB, `upsert` could write a DIFFERENT row than the one it was given and report success.
|
|
124
|
+
|
|
125
|
+
`INSERT … ON DUPLICATE KEY UPDATE` fires on ANY unique key, not on the one named in `conflictColumns`. So an incoming row whose (say) `email` already belonged to a different primary key updated THAT row instead — and since `id` is excluded from the SET list, the row the caller handed over was never written. Measured on a live server: the call returned a row, the target kept the old id, the new row was absent, and the existing row had silently taken the incoming values. A bulk transfer on top of that prints `import complete` over missing data, which is the worst failure shape available: there is nothing to investigate.
|
|
126
|
+
|
|
127
|
+
The two engines of the family disagreed here, which is part of why it survived. The non-RETURNING path (MySQL) looks the row up by `conflictColumns` first, does not find it, and lets the INSERT fail with a duplicate-key error. Loud was always right.
|
|
128
|
+
|
|
129
|
+
Both refuse now, with a message naming both ids and the fact that the collision was on a constraint other than the one named. The check runs inside a transaction — a short one of the store's own when the caller is not already in one — so the wrong row is rolled back rather than reported after the fact: detecting this afterwards still leaves someone else's row overwritten.
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
42
133
|
## [0.42.0] — 2026-08-17
|
|
43
134
|
|
|
44
135
|
### ⚠ BREAKING
|
package/dist/index.d.ts
CHANGED
|
@@ -364,6 +364,20 @@ export declare class MysqlStore implements DataStore {
|
|
|
364
364
|
*/
|
|
365
365
|
private maxInTxn;
|
|
366
366
|
private routeEvent;
|
|
367
|
+
/**
|
|
368
|
+
* Could this row be INSERTed on its own?
|
|
369
|
+
*
|
|
370
|
+
* True when every declared column that is NOT NULL, has no default of any
|
|
371
|
+
* kind, and is not computed by the database carries a value. That is exactly
|
|
372
|
+
* the condition `INSERT … ON DUPLICATE KEY UPDATE` imposes on its insert half
|
|
373
|
+
* — the server validates it even when the update half is the one that runs.
|
|
374
|
+
*
|
|
375
|
+
* Unknown table (a raw handle, a plugin store, a seed against an unregistered
|
|
376
|
+
* name) → treated as complete: the registry is the only source for this, and
|
|
377
|
+
* guessing "partial" would move every such write onto the slower path for a
|
|
378
|
+
* question we cannot answer.
|
|
379
|
+
*/
|
|
380
|
+
private isCompleteInsertRow;
|
|
367
381
|
private executeUpsert;
|
|
368
382
|
/**
|
|
369
383
|
* MariaDB 10.5+ native upsert:
|
|
@@ -375,6 +389,15 @@ export declare class MysqlStore implements DataStore {
|
|
|
375
389
|
*/
|
|
376
390
|
private executeMariadbUpsert;
|
|
377
391
|
private executeInsertIgnore;
|
|
392
|
+
/**
|
|
393
|
+
* The `INSERT IGNORE` itself and what its outcome MEANS, on one connection.
|
|
394
|
+
*
|
|
395
|
+
* Split out from the caller purely so that "one connection" is a property of
|
|
396
|
+
* the signature rather than of whoever remembers to pass one: every read here
|
|
397
|
+
* is about the statement that just ran on `conn`, and a single pooled acquire
|
|
398
|
+
* in the middle makes the diagnosis describe someone else's statement.
|
|
399
|
+
*/
|
|
400
|
+
private decideInsertIgnore;
|
|
378
401
|
/**
|
|
379
402
|
* What a SKIPPED `INSERT IGNORE` means — one decision, both engines.
|
|
380
403
|
*
|
|
@@ -480,7 +503,7 @@ export declare class MysqlStore implements DataStore {
|
|
|
480
503
|
* and `isRetryableMysqlFailure` (deadlock / lock-wait timeout). Retry,
|
|
481
504
|
* commit-defect promotion, attribution threading and exit settling are shared
|
|
482
505
|
* — this store carried its own copy of the last one for a release after
|
|
483
|
-
* postgres was fixed, and a
|
|
506
|
+
* postgres was fixed, and a deployment on MariaDB paid for it. See
|
|
484
507
|
* `transactionOutcome.ts`.
|
|
485
508
|
*/
|
|
486
509
|
private txnSpec;
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { MysqlClient as e } from "@effect/sql-mysql2";
|
|
2
2
|
import { Config as t, Effect as n, Layer as r, ManagedRuntime as i, Option as a, Redacted as o, Schedule as s } from "effect";
|
|
3
|
-
import { CDC_OFFSETS_TABLE as c, DEFAULT_ACQUIRE_TIMEOUT_MS as l, EagerCardinalityError as u, _voltroCdcOffsetsTable as d, attachEagerLoads as f, attributionFields as p, attributionKey as m, beginLocalWrite as h, bulkInsertLimitsFor as g, chunkRowsForInsert as _, compileEagerJson as v, compilePredicate as y, compileRawFragment as b, compileSelect as x, decodeRowsFromSchema as S, encodeRowForSchema as C, endLocalWrite as w, externalChangeEvent as T,
|
|
4
|
-
import { EventEmitter as
|
|
5
|
-
import { createLogger as
|
|
6
|
-
import { SqlClient as
|
|
3
|
+
import { CDC_OFFSETS_TABLE as c, DEFAULT_ACQUIRE_TIMEOUT_MS as l, EagerCardinalityError as u, _voltroCdcOffsetsTable as d, attachEagerLoads as f, attributionFields as p, attributionKey as m, beginLocalWrite as h, bulkInsertLimitsFor as g, chunkRowsForInsert as _, compileEagerJson as v, compilePredicate as y, compileRawFragment as b, compileSelect as x, decodeRowsFromSchema as S, encodeRowForSchema as C, endLocalWrite as w, externalChangeEvent as T, getTable as E, hasEagerLoads as ee, isTableReactive as D, makeEagerFallbackReporter as te, observeDbOp as O, qualifyTable as ne, raiseChangeListenerCeiling as re, recordsTable as ie, registerPendingAttribution as k, requireTable as A, resolveEchoAttribution as j, runStoreTransaction as ae, runWriteRecorders as oe, stampGeneratedId as M, stampGeneratedIds as se, withCapturedAttribution as N } from "@voltro/database";
|
|
4
|
+
import { EventEmitter as ce } from "node:events";
|
|
5
|
+
import { createLogger as P } from "@voltro/logger";
|
|
6
|
+
import { SqlClient as F, TransactionConnection as I } from "@effect/sql/SqlClient";
|
|
7
7
|
//#region src/sqlLayer.ts
|
|
8
|
-
var
|
|
8
|
+
var le = (e) => e ? { rejectUnauthorized: !1 } : void 0, ue = (e) => {
|
|
9
9
|
let t = e.acquireTimeoutMs ?? l;
|
|
10
10
|
return t > 0 ? t : void 0;
|
|
11
|
-
},
|
|
11
|
+
}, L = (e) => {
|
|
12
12
|
let t = e.acquireQueueLimit;
|
|
13
13
|
return t !== void 0 && t > 0 ? t : void 0;
|
|
14
14
|
}, R = (e) => {
|
|
15
|
-
let t = e.ssl === void 0 ? void 0 :
|
|
15
|
+
let t = e.ssl === void 0 ? void 0 : le(e.ssl), n = ue(e), r = L(e);
|
|
16
16
|
return {
|
|
17
17
|
...t === void 0 ? {} : { ssl: t },
|
|
18
18
|
...n === void 0 ? {} : { connectTimeout: n },
|
|
@@ -67,21 +67,21 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
67
67
|
...e.ssl === void 0 ? {} : { ssl: e.ssl },
|
|
68
68
|
...t
|
|
69
69
|
};
|
|
70
|
-
}, H = (e) => z(V(e)), U = (e, t) => e === null ? !1 : t === null ? !0 : e.filename === t.filename ? e.position > t.position : e.filename > t.filename,
|
|
70
|
+
}, H = (e) => z(V(e)), U = (e, t) => e === null ? !1 : t === null ? !0 : e.filename === t.filename ? e.position > t.position : e.filename > t.filename, de = (e) => e.msSinceProgress < e.stallThresholdMs ? "healthy" : e.primary !== null && !U(e.primary, e.reader) ? "idle-caught-up" : "reconnect", fe = (e) => (e instanceof Error ? e.message : String(e ?? "")).includes("schema changed between binlog event and metadata fetch"), pe = (e) => {
|
|
71
71
|
let t = e instanceof Error ? e.message : String(e ?? "");
|
|
72
72
|
return /Table\s+[^\s.]+\.(\S+)\s+schema changed between binlog event and metadata fetch/.exec(t)?.[1] ?? null;
|
|
73
|
-
},
|
|
74
|
-
let n = [...e.filter((e) => t - e <
|
|
73
|
+
}, me = "\n SELECT DISTINCT s.TABLE_NAME AS tableName\n FROM information_schema.STATISTICS s\n JOIN information_schema.COLUMNS c\n ON c.TABLE_SCHEMA = s.TABLE_SCHEMA\n AND c.TABLE_NAME = s.TABLE_NAME\n AND c.COLUMN_NAME = s.COLUMN_NAME\n WHERE s.TABLE_SCHEMA = DATABASE()\n AND s.NON_UNIQUE = 0\n AND s.SUB_PART IS NULL\n AND c.DATA_TYPE IN ('text','tinytext','mediumtext','longtext','blob','tinyblob','mediumblob','longblob')\n", W = (e) => `cdc: table '${e}' is EXCLUDED from binlog capture — its row image carries a hidden column the reader cannot account for. Cause: a UNIQUE constraint on an UNBOUNDED text column, which MariaDB backs with a HASH long-unique index; that index adds a hidden DB_ROW_HASH_n column to the row, present in the binlog and absent from information_schema.COLUMNS. Remedy: bound the column — text().maxLength(n) — so the constraint becomes an ordinary B-tree index with no hidden column. ALTER TABLE FORCE does NOT help: the rebuild recreates the index and the hidden column. Until then, cross-instance change events for this table are lost; own-node reactivity is unaffected (writes still emit inline).`, he = 3e5, ge = 3, _e = (e, t) => {
|
|
74
|
+
let n = [...e.filter((e) => t - e < he), t];
|
|
75
75
|
return {
|
|
76
|
-
verdict: n.length >=
|
|
76
|
+
verdict: n.length >= ge ? "persistent" : "backlog",
|
|
77
77
|
hits: n
|
|
78
78
|
};
|
|
79
|
-
},
|
|
79
|
+
}, ve = /* @__PURE__ */ new Set([
|
|
80
80
|
"writerows",
|
|
81
81
|
"updaterows",
|
|
82
82
|
"deleterows"
|
|
83
|
-
]),
|
|
84
|
-
let t =
|
|
83
|
+
]), ye = /\b(alter|rename|drop|create)\s+(table|column)?/i, G = (e) => new Promise((t) => setTimeout(t, e)), K = async (e) => {
|
|
84
|
+
let t = P({ scope: `voltro:${e.variant}:cdc` }), n;
|
|
85
85
|
try {
|
|
86
86
|
n = (await import("@vlasky/zongji")).default;
|
|
87
87
|
} catch (t) {
|
|
@@ -96,14 +96,14 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
96
96
|
o = n.binlogName;
|
|
97
97
|
return;
|
|
98
98
|
}
|
|
99
|
-
if (r === "query" && n.query &&
|
|
99
|
+
if (r === "query" && n.query && ye.test(n.query)) {
|
|
100
100
|
l && (l.tableMap = {});
|
|
101
101
|
return;
|
|
102
102
|
}
|
|
103
103
|
if (n.nextPosition && o && (s = {
|
|
104
104
|
filename: o,
|
|
105
105
|
position: n.nextPosition
|
|
106
|
-
}, e.onPosition?.(s)), !
|
|
106
|
+
}, e.onPosition?.(s)), !ve.has(r)) return;
|
|
107
107
|
let u = n.tableMap[n.tableId];
|
|
108
108
|
if (!u || u.parentSchema !== a) return;
|
|
109
109
|
let d = u.tableName;
|
|
@@ -181,11 +181,11 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
181
181
|
try {
|
|
182
182
|
l?.stop();
|
|
183
183
|
} catch {}
|
|
184
|
-
if (d++, await
|
|
185
|
-
let i = s, a = C(n), c = !a &&
|
|
184
|
+
if (d++, await G(Math.min(3e4, 500 * 2 ** Math.min(d, 6))), u) return;
|
|
185
|
+
let i = s, a = C(n), c = !a && fe(n), f = !1;
|
|
186
186
|
if (c) {
|
|
187
|
-
let e =
|
|
188
|
-
m.set(i, o), f = a === "persistent", f && !h.has(i) && (h.add(i), e !== null && r.add(e), t.error(
|
|
187
|
+
let e = pe(n), i = e ?? "<unknown>", { verdict: a, hits: o } = _e(m.get(i) ?? [], Date.now());
|
|
188
|
+
m.set(i, o), f = a === "persistent", f && !h.has(i) && (h.add(i), e !== null && r.add(e), t.error(W(i)));
|
|
189
189
|
}
|
|
190
190
|
(a || c) && (f || t.warn(c ? "cdc: un-replayable backlog event (schema moved past it) — jumping to current end + self-heal" : "cdc: binlog gap (purged/failover) — jumping to current end + self-heal"), i = e.resolveStartPosition ? await e.resolveStartPosition().catch(() => null) : null, o = i?.filename ?? null, f || e.onResync?.());
|
|
191
191
|
try {
|
|
@@ -209,14 +209,14 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
209
209
|
l?.stop();
|
|
210
210
|
} catch {}
|
|
211
211
|
let n = e.resolveStartPosition ? await e.resolveStartPosition().catch(() => null) : null;
|
|
212
|
-
o = n?.filename ?? null, e.onResync?.(), await
|
|
212
|
+
o = n?.filename ?? null, e.onResync?.(), await G(500), await w(n);
|
|
213
213
|
} else throw n;
|
|
214
214
|
}
|
|
215
215
|
let E = async () => {
|
|
216
216
|
if (u || p || Date.now() - f < _) return;
|
|
217
217
|
let n = null;
|
|
218
218
|
if (e.resolveStartPosition && (n = await e.resolveStartPosition().catch(() => null)), u || p) return;
|
|
219
|
-
let r =
|
|
219
|
+
let r = de({
|
|
220
220
|
msSinceProgress: Date.now() - f,
|
|
221
221
|
stallThresholdMs: _,
|
|
222
222
|
primary: n,
|
|
@@ -245,7 +245,7 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
245
245
|
},
|
|
246
246
|
currentPosition: () => s
|
|
247
247
|
};
|
|
248
|
-
},
|
|
248
|
+
}, be = /* @__PURE__ */ new Set(["1213", "1205"]), xe = (e) => {
|
|
249
249
|
let t = e;
|
|
250
250
|
for (let e = 0; e < 5 && typeof t == "object" && t; e++) {
|
|
251
251
|
let e = t.errno;
|
|
@@ -254,31 +254,31 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
254
254
|
if (typeof n == "string") return n;
|
|
255
255
|
t = t.cause;
|
|
256
256
|
}
|
|
257
|
-
},
|
|
258
|
-
let t =
|
|
259
|
-
return t !== void 0 &&
|
|
260
|
-
},
|
|
257
|
+
}, q = (e) => {
|
|
258
|
+
let t = xe(e);
|
|
259
|
+
return t !== void 0 && be.has(t);
|
|
260
|
+
}, J = (e) => q(e) ? "retry" : "noRetry", Y = (e) => {
|
|
261
261
|
if (e == null) return "null";
|
|
262
262
|
let t = typeof e;
|
|
263
263
|
if (t === "bigint") return `${e}n`;
|
|
264
264
|
if (t !== "object") return JSON.stringify(e);
|
|
265
265
|
if (e instanceof Date) return `"${e.toISOString()}"`;
|
|
266
|
-
if (Array.isArray(e)) return `[${e.map(
|
|
266
|
+
if (Array.isArray(e)) return `[${e.map(Y).join(",")}]`;
|
|
267
267
|
let n = e;
|
|
268
|
-
return `{${Object.keys(n).sort().map((e) => `${JSON.stringify(e)}:${
|
|
269
|
-
},
|
|
270
|
-
let t =
|
|
268
|
+
return `{${Object.keys(n).sort().map((e) => `${JSON.stringify(e)}:${Y(n[e])}`).join(",")}}`;
|
|
269
|
+
}, Se = (e) => {
|
|
270
|
+
let t = Y(e), n = 2166136261;
|
|
271
271
|
for (let e = 0; e < t.length; e++) n ^= t.charCodeAt(e), n = Math.imul(n, 16777619);
|
|
272
272
|
return (n >>> 0).toString(36);
|
|
273
|
-
},
|
|
273
|
+
}, Ce = (e, t) => {
|
|
274
274
|
let n = setTimeout(e, t);
|
|
275
275
|
typeof n.unref == "function" && n.unref();
|
|
276
|
-
},
|
|
276
|
+
}, we = class {
|
|
277
277
|
variant;
|
|
278
278
|
ttlMs;
|
|
279
279
|
schedule;
|
|
280
280
|
seen = /* @__PURE__ */ new Map();
|
|
281
|
-
constructor(e, t = 6e4, n =
|
|
281
|
+
constructor(e, t = 6e4, n = Ce) {
|
|
282
282
|
this.variant = e, this.ttlMs = t, this.schedule = n;
|
|
283
283
|
}
|
|
284
284
|
key(e) {
|
|
@@ -292,7 +292,7 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
292
292
|
} catch {
|
|
293
293
|
r = t;
|
|
294
294
|
}
|
|
295
|
-
return `${e.table} ${e.op} ${String(n)} ${
|
|
295
|
+
return `${e.table} ${e.op} ${String(n)} ${Se(r)}`;
|
|
296
296
|
}
|
|
297
297
|
admit(e) {
|
|
298
298
|
let t = this.key(e);
|
|
@@ -307,16 +307,16 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
307
307
|
get pending() {
|
|
308
308
|
return this.seen.size;
|
|
309
309
|
}
|
|
310
|
-
},
|
|
310
|
+
}, X = /* @__PURE__ */ new Set([
|
|
311
311
|
1022,
|
|
312
312
|
1062,
|
|
313
313
|
1586
|
|
314
|
-
]),
|
|
315
|
-
let t = e.variant ?? "mysql", n =
|
|
314
|
+
]), Z = async (e) => {
|
|
315
|
+
let t = e.variant ?? "mysql", n = P({ scope: `voltro:${t}` }), a = e.changeStrategy ?? "inline", o = a;
|
|
316
316
|
a === "cdc" && !e.cdcConfig && (n.warn("changeStrategy='cdc' requires cdcConfig (serverId + connection); falling back to 'inline'."), o = "inline");
|
|
317
|
-
let s = e.tracerLayer ? r.mergeAll(e.sqlLayer, e.tracerLayer) : e.sqlLayer, c = i.make(s), l = new
|
|
317
|
+
let s = e.tracerLayer ? r.mergeAll(e.sqlLayer, e.tracerLayer) : e.sqlLayer, c = i.make(s), l = new Q(await c.runPromise(F), c, t, o);
|
|
318
318
|
return o === "cdc" && e.cdcConfig && await l.startCdcConsumer(e.cdcConfig), l;
|
|
319
|
-
},
|
|
319
|
+
}, Q = class e {
|
|
320
320
|
sql;
|
|
321
321
|
runtime;
|
|
322
322
|
variant;
|
|
@@ -333,13 +333,13 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
333
333
|
cdcGate;
|
|
334
334
|
reportEagerFallback;
|
|
335
335
|
constructor(e, t, n, r = "inline", i = null, a, o) {
|
|
336
|
-
this.sql = e, this.runtime = t, this.variant = n, this.changeStrategy = r, this.namespace = i, this.log =
|
|
336
|
+
this.sql = e, this.runtime = t, this.variant = n, this.changeStrategy = r, this.namespace = i, this.log = P({ scope: `voltro:${n}` }), this.reportEagerFallback = te(this.log), this.emitter = a ?? new ce(), re(this.emitter), this.cdcGate = o ?? new we(n);
|
|
337
337
|
}
|
|
338
338
|
withNamespace(t) {
|
|
339
339
|
return t === this.namespace ? this : new e(this.sql, this.runtime, this.variant, this.changeStrategy, t, this.emitter, this.cdcGate);
|
|
340
340
|
}
|
|
341
341
|
nsT(e) {
|
|
342
|
-
return
|
|
342
|
+
return ne(this.namespace, e);
|
|
343
343
|
}
|
|
344
344
|
get dialectId() {
|
|
345
345
|
return this.variant;
|
|
@@ -351,7 +351,7 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
351
351
|
};
|
|
352
352
|
}
|
|
353
353
|
async executeQuery(e, t, r) {
|
|
354
|
-
let i = x(e, this.sql, this.namespace), a = t ? n.provideService(i,
|
|
354
|
+
let i = x(e, this.sql, this.namespace), a = t ? n.provideService(i, I, t) : i, o = await O(this.variant, "select", () => this.runtime.runPromise(a));
|
|
355
355
|
return S(o, e.table, this.variant);
|
|
356
356
|
}
|
|
357
357
|
get supportsInsertReturning() {
|
|
@@ -367,7 +367,7 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
367
367
|
t = M(e, t);
|
|
368
368
|
let o = this.sql;
|
|
369
369
|
if (this.supportsInsertReturning) {
|
|
370
|
-
let s = o`INSERT INTO ${o(this.nsT(e))} ${o.insert(C(t, e))} RETURNING *`, c = r ? n.provideService(s,
|
|
370
|
+
let s = o`INSERT INTO ${o(this.nsT(e))} ${o.insert(C(t, e))} RETURNING *`, c = r ? n.provideService(s, I, r) : s, l = (await this.runtime.runPromise(c))[0];
|
|
371
371
|
if (!l) throw Error(`MysqlStore.insert: no row returned for table '${e}'`);
|
|
372
372
|
return await this.routeEvent({
|
|
373
373
|
table: e,
|
|
@@ -386,9 +386,9 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
386
386
|
new: t
|
|
387
387
|
}, i, r, a), t;
|
|
388
388
|
}
|
|
389
|
-
let l = o`INSERT INTO ${o(this.nsT(e))} ${o.insert(s)}`, u = r ? n.provideService(l,
|
|
389
|
+
let l = o`INSERT INTO ${o(this.nsT(e))} ${o.insert(s)}`, u = r ? n.provideService(l, I, r) : l;
|
|
390
390
|
await this.runtime.runPromise(u);
|
|
391
|
-
let d = o`SELECT * FROM ${o(this.nsT(e))} WHERE ${o("id")} = ${c}`, f = r ? n.provideService(d,
|
|
391
|
+
let d = o`SELECT * FROM ${o(this.nsT(e))} WHERE ${o("id")} = ${c}`, f = r ? n.provideService(d, I, r) : d, p = (await this.runtime.runPromise(f))[0];
|
|
392
392
|
if (!p) throw Error(`MysqlStore.insert: row not found post-insert in '${e}'`);
|
|
393
393
|
return await this.routeEvent({
|
|
394
394
|
table: e,
|
|
@@ -401,16 +401,16 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
401
401
|
let i = this.sql;
|
|
402
402
|
return this.runPinned(r, (r) => n.gen(this, function* () {
|
|
403
403
|
let a = i`INSERT INTO ${i(this.nsT(e))} ${i.insert(t)}`;
|
|
404
|
-
yield* n.provideService(a,
|
|
405
|
-
let o = (yield* n.provideService(i`SELECT LAST_INSERT_ID() AS ${i("lastId")}`,
|
|
406
|
-
return o === void 0 || Number(o) === 0 ? yield* n.fail(/* @__PURE__ */ Error(`MysqlStore.insert: LAST_INSERT_ID() returned no id for '${e}' — is the primary key AUTO_INCREMENT?`)) : (yield* n.provideService(i`SELECT * FROM ${i(this.nsT(e))} WHERE ${i("id")} = ${o}`,
|
|
404
|
+
yield* n.provideService(a, I, r);
|
|
405
|
+
let o = (yield* n.provideService(i`SELECT LAST_INSERT_ID() AS ${i("lastId")}`, I, r))[0]?.lastId;
|
|
406
|
+
return o === void 0 || Number(o) === 0 ? yield* n.fail(/* @__PURE__ */ Error(`MysqlStore.insert: LAST_INSERT_ID() returned no id for '${e}' — is the primary key AUTO_INCREMENT?`)) : (yield* n.provideService(i`SELECT * FROM ${i(this.nsT(e))} WHERE ${i("id")} = ${o}`, I, r))[0] || (yield* n.fail(/* @__PURE__ */ Error(`MysqlStore.insert: row not found post-insert in '${e}'`)));
|
|
407
407
|
}), "insert");
|
|
408
408
|
}
|
|
409
409
|
async runPinned(e, t, r) {
|
|
410
410
|
if (e) return this.runtime.runPromise(t(e));
|
|
411
411
|
this.inflightTxns++;
|
|
412
412
|
try {
|
|
413
|
-
let e = n.suspend(() => this.sql.withTransaction(n.flatMap(n.serviceOption(
|
|
413
|
+
let e = n.suspend(() => this.sql.withTransaction(n.flatMap(n.serviceOption(I), (e) => a.isNone(e) ? n.fail(/* @__PURE__ */ Error(`MysqlStore.${r}: TransactionConnection missing.`)) : t(e.value)))), i = s.exponential("10 millis").pipe(s.compose(s.recurs(3)), s.whileInput(q)), o = e.pipe(n.retry(i), n.withSpan(`store.${r}`, { attributes: {
|
|
414
414
|
"db.system": this.variant,
|
|
415
415
|
"db.operation": r
|
|
416
416
|
} }));
|
|
@@ -420,16 +420,16 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
420
420
|
}
|
|
421
421
|
}
|
|
422
422
|
async executeInsertMany(e, t, r, i, a) {
|
|
423
|
-
if (t =
|
|
423
|
+
if (t = se(e, t), t.length === 0) return [];
|
|
424
424
|
let o = this.sql, s = t.map((t) => C(t, e)), c = _(s, g(this.variant));
|
|
425
425
|
if (this.supportsInsertReturning) {
|
|
426
426
|
let t = (t) => o`INSERT INTO ${o(this.nsT(e))} ${o.insert(t)} RETURNING *`, s;
|
|
427
427
|
if (c.length === 1) {
|
|
428
|
-
let e = t(c[0]), i = r ? n.provideService(e,
|
|
428
|
+
let e = t(c[0]), i = r ? n.provideService(e, I, r) : e;
|
|
429
429
|
s = await this.runtime.runPromise(i);
|
|
430
430
|
} else if (r) {
|
|
431
431
|
let e = [];
|
|
432
|
-
for (let i of c) e.push(...await this.runtime.runPromise(n.provideService(t(i),
|
|
432
|
+
for (let i of c) e.push(...await this.runtime.runPromise(n.provideService(t(i), I, r)));
|
|
433
433
|
s = e;
|
|
434
434
|
} else s = await this.runtime.runPromise(o.withTransaction(n.map(n.forEach(c, t, { concurrency: 1 }), (e) => e.flat())));
|
|
435
435
|
for (let t of s) await this.routeEvent({
|
|
@@ -454,16 +454,16 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
454
454
|
if (l.some((e) => e === void 0)) throw Error("MysqlStore.insertMany: rows mix client-supplied and missing 'id's — supply an id for every row or none (AUTO_INCREMENT recovery).");
|
|
455
455
|
let u = (t) => o`INSERT INTO ${o(this.nsT(e))} ${o.insert(t)}`;
|
|
456
456
|
if (c.length === 1) {
|
|
457
|
-
let e = r ? n.provideService(u(c[0]),
|
|
457
|
+
let e = r ? n.provideService(u(c[0]), I, r) : u(c[0]);
|
|
458
458
|
await this.runtime.runPromise(e);
|
|
459
|
-
} else if (r) for (let e of c) await this.runtime.runPromise(n.provideService(u(e),
|
|
459
|
+
} else if (r) for (let e of c) await this.runtime.runPromise(n.provideService(u(e), I, r));
|
|
460
460
|
else await this.runtime.runPromise(o.withTransaction(n.forEach(c, u, {
|
|
461
461
|
concurrency: 1,
|
|
462
462
|
discard: !0
|
|
463
463
|
})));
|
|
464
464
|
let d = _(l.map((e) => ({ id: e })), g(this.variant)), f = [];
|
|
465
465
|
for (let t of d) {
|
|
466
|
-
let i = o`SELECT * FROM ${o(this.nsT(e))} WHERE ${o("id")} IN ${o.in(t.map((e) => e.id))}`, a = r ? n.provideService(i,
|
|
466
|
+
let i = o`SELECT * FROM ${o(this.nsT(e))} WHERE ${o("id")} IN ${o.in(t.map((e) => e.id))}`, a = r ? n.provideService(i, I, r) : i;
|
|
467
467
|
f.push(...await this.runtime.runPromise(a));
|
|
468
468
|
}
|
|
469
469
|
let p = new Map(f.map((e) => [e.id, e])), m = l.map((e) => p.get(e)).filter((e) => e !== void 0);
|
|
@@ -481,19 +481,19 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
481
481
|
let a = [];
|
|
482
482
|
for (let o of t) {
|
|
483
483
|
let t = i`INSERT INTO ${i(this.nsT(e))} ${i.insert(o)}`;
|
|
484
|
-
yield* n.provideService(t,
|
|
485
|
-
let s = (yield* n.provideService(i`SELECT LAST_INSERT_ID() AS ${i("firstId")}`,
|
|
484
|
+
yield* n.provideService(t, I, r);
|
|
485
|
+
let s = (yield* n.provideService(i`SELECT LAST_INSERT_ID() AS ${i("firstId")}`, I, r))[0]?.firstId;
|
|
486
486
|
if (s === void 0 || Number(s) === 0) return yield* n.fail(/* @__PURE__ */ Error(`MysqlStore.insertMany: LAST_INSERT_ID() returned no id for '${e}' — is the primary key AUTO_INCREMENT?`));
|
|
487
|
-
let c = Number(s), l = yield* n.provideService(i`SELECT * FROM ${i(this.nsT(e))} WHERE ${i("id")} BETWEEN ${c} AND ${c + o.length - 1} ORDER BY ${i("id")} ASC`,
|
|
487
|
+
let c = Number(s), l = yield* n.provideService(i`SELECT * FROM ${i(this.nsT(e))} WHERE ${i("id")} BETWEEN ${c} AND ${c + o.length - 1} ORDER BY ${i("id")} ASC`, I, r);
|
|
488
488
|
a.push(...l);
|
|
489
489
|
}
|
|
490
490
|
return a;
|
|
491
491
|
}), "insert");
|
|
492
492
|
}
|
|
493
493
|
async executePatchJson(e, t, r, i, a, o, s) {
|
|
494
|
-
let c = this.sql, l = r.split("."), u = l[0], d = l.slice(1), f = JSON.stringify(i ?? null), p = d.length === 0 ? "$" : `$.${d.join(".")}`, m = c`UPDATE ${c(this.nsT(e))} SET ${c(u)} = JSON_SET(COALESCE(${c(u)}, '{}'), ${p}, CAST(${f} AS JSON)) WHERE ${c("id")} = ${t}`, h = a ? n.provideService(m,
|
|
494
|
+
let c = this.sql, l = r.split("."), u = l[0], d = l.slice(1), f = JSON.stringify(i ?? null), p = d.length === 0 ? "$" : `$.${d.join(".")}`, m = c`UPDATE ${c(this.nsT(e))} SET ${c(u)} = JSON_SET(COALESCE(${c(u)}, '{}'), ${p}, CAST(${f} AS JSON)) WHERE ${c("id")} = ${t}`, h = a ? n.provideService(m, I, a) : m, g = await this.runtime.runPromise(h);
|
|
495
495
|
if (g && typeof g.affectedRows == "number" && g.affectedRows === 0) return null;
|
|
496
|
-
let _ = c`SELECT * FROM ${c(this.nsT(e))} WHERE ${c("id")} = ${t}`, v = a ? n.provideService(_,
|
|
496
|
+
let _ = c`SELECT * FROM ${c(this.nsT(e))} WHERE ${c("id")} = ${t}`, v = a ? n.provideService(_, I, a) : _, y = (await this.runtime.runPromise(v))[0];
|
|
497
497
|
return y ? (await this.routeEvent({
|
|
498
498
|
table: e,
|
|
499
499
|
op: "update",
|
|
@@ -504,7 +504,7 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
504
504
|
async executeUpdate(e, t, r, i, a, o) {
|
|
505
505
|
let s = this.sql;
|
|
506
506
|
if (this.supportsUpdateReturning) {
|
|
507
|
-
let c = s`UPDATE ${s(this.nsT(e))} SET ${s.update(C(r, e))} WHERE ${s("id")} = ${t} RETURNING *`, l = i ? n.provideService(c,
|
|
507
|
+
let c = s`UPDATE ${s(this.nsT(e))} SET ${s.update(C(r, e))} WHERE ${s("id")} = ${t} RETURNING *`, l = i ? n.provideService(c, I, i) : c, u = (await this.runtime.runPromise(l))[0];
|
|
508
508
|
return u ? (await this.routeEvent({
|
|
509
509
|
table: e,
|
|
510
510
|
op: "update",
|
|
@@ -512,9 +512,9 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
512
512
|
new: u
|
|
513
513
|
}, a, i, o), u) : null;
|
|
514
514
|
}
|
|
515
|
-
let c = s`UPDATE ${s(this.nsT(e))} SET ${s.update(C(r, e))} WHERE ${s("id")} = ${t}`, l = i ? n.provideService(c,
|
|
515
|
+
let c = s`UPDATE ${s(this.nsT(e))} SET ${s.update(C(r, e))} WHERE ${s("id")} = ${t}`, l = i ? n.provideService(c, I, i) : c, u = await this.runtime.runPromise(l);
|
|
516
516
|
if (u && typeof u.affectedRows == "number" && u.affectedRows === 0) return null;
|
|
517
|
-
let d = s`SELECT * FROM ${s(this.nsT(e))} WHERE ${s("id")} = ${t}`, f = i ? n.provideService(d,
|
|
517
|
+
let d = s`SELECT * FROM ${s(this.nsT(e))} WHERE ${s("id")} = ${t}`, f = i ? n.provideService(d, I, i) : d, p = (await this.runtime.runPromise(f))[0];
|
|
518
518
|
return p ? (await this.routeEvent({
|
|
519
519
|
table: e,
|
|
520
520
|
op: "update",
|
|
@@ -525,7 +525,7 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
525
525
|
async executeDelete(e, t, r, i, a) {
|
|
526
526
|
let o = this.sql;
|
|
527
527
|
if (this.supportsDeleteReturning) {
|
|
528
|
-
let s = o`DELETE FROM ${o(this.nsT(e))} WHERE ${o("id")} = ${t} RETURNING *`, c = r ? n.provideService(s,
|
|
528
|
+
let s = o`DELETE FROM ${o(this.nsT(e))} WHERE ${o("id")} = ${t} RETURNING *`, c = r ? n.provideService(s, I, r) : s, l = (await this.runtime.runPromise(c))[0];
|
|
529
529
|
return l ? (await this.routeEvent({
|
|
530
530
|
table: e,
|
|
531
531
|
op: "delete",
|
|
@@ -533,9 +533,9 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
533
533
|
new: null
|
|
534
534
|
}, i, r, a), !0) : !1;
|
|
535
535
|
}
|
|
536
|
-
let s = o`SELECT * FROM ${o(this.nsT(e))} WHERE ${o("id")} = ${t}`, c = r ? n.provideService(s,
|
|
536
|
+
let s = o`SELECT * FROM ${o(this.nsT(e))} WHERE ${o("id")} = ${t}`, c = r ? n.provideService(s, I, r) : s, l = (await this.runtime.runPromise(c))[0];
|
|
537
537
|
if (!l) return !1;
|
|
538
|
-
let u = o`DELETE FROM ${o(this.nsT(e))} WHERE ${o("id")} = ${t}`, d = r ? n.provideService(u,
|
|
538
|
+
let u = o`DELETE FROM ${o(this.nsT(e))} WHERE ${o("id")} = ${t}`, d = r ? n.provideService(u, I, r) : u;
|
|
539
539
|
return await this.runtime.runPromise(d), await this.routeEvent({
|
|
540
540
|
table: e,
|
|
541
541
|
op: "delete",
|
|
@@ -545,17 +545,17 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
545
545
|
}
|
|
546
546
|
async appendInTxn(e, t, r) {
|
|
547
547
|
let i = this.sql, a = i`INSERT INTO ${i(this.nsT(e))} ${i.insert(C(t, e))}`;
|
|
548
|
-
await this.runtime.runPromise(r ? n.provideService(a,
|
|
548
|
+
await this.runtime.runPromise(r ? n.provideService(a, I, r) : a);
|
|
549
549
|
}
|
|
550
550
|
async maxInTxn(e, t, r, i) {
|
|
551
|
-
let a = this.sql, o = Object.entries(r).map(([e, t]) => a`${a(e)} = ${t}`), s = a`SELECT MAX(${a(t)}) AS ${a("m")} FROM ${a(this.nsT(e))} WHERE ${a.and(o)}`, c = (await this.runtime.runPromise(i ? n.provideService(s,
|
|
551
|
+
let a = this.sql, o = Object.entries(r).map(([e, t]) => a`${a(e)} = ${t}`), s = a`SELECT MAX(${a(t)}) AS ${a("m")} FROM ${a(this.nsT(e))} WHERE ${a.and(o)}`, c = (await this.runtime.runPromise(i ? n.provideService(s, I, i) : s))[0]?.m;
|
|
552
552
|
return c == null ? null : Number(c);
|
|
553
553
|
}
|
|
554
554
|
async routeEvent(e, t, n = null, r) {
|
|
555
555
|
if (e = {
|
|
556
556
|
...p(r),
|
|
557
557
|
...e
|
|
558
|
-
},
|
|
558
|
+
}, ie(e.table) && await oe({
|
|
559
559
|
append: (e, t) => this.appendInTxn(e, t, n),
|
|
560
560
|
maxOf: (e, t, r) => this.maxInTxn(e, t, r, n)
|
|
561
561
|
}, {
|
|
@@ -567,7 +567,7 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
567
567
|
subjectId: e.subjectId
|
|
568
568
|
}), this.changeStrategy === "cdc") {
|
|
569
569
|
let t = (e.op === "delete" ? e.old : e.new)?.id;
|
|
570
|
-
t != null &&
|
|
570
|
+
t != null && k(m(e.table, e.op, t), {
|
|
571
571
|
...e.traceId === void 0 ? {} : { traceId: e.traceId },
|
|
572
572
|
...e.subjectId === void 0 ? {} : { subjectId: e.subjectId }
|
|
573
573
|
});
|
|
@@ -578,8 +578,15 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
578
578
|
}
|
|
579
579
|
this.emitChange(e);
|
|
580
580
|
}
|
|
581
|
+
isCompleteInsertRow(e, t) {
|
|
582
|
+
let n = E(e);
|
|
583
|
+
if (n === void 0) return !0;
|
|
584
|
+
let r = n.fields;
|
|
585
|
+
for (let [e, n] of Object.entries(r)) if (n !== void 0 && n.nullable !== !0 && n.hasDefault !== !0 && n.defaultValue === void 0 && n.defaultFactory === void 0 && n.computed === void 0 && n.generatedAs === void 0 && n.idScheme === void 0 && t[e] === void 0) return !1;
|
|
586
|
+
return !0;
|
|
587
|
+
}
|
|
581
588
|
async executeUpsert(e, t, n, r, i, a) {
|
|
582
|
-
if (this.variant === "mariadb" && typeof n.update != "function") return this.executeMariadbUpsert(e, t, {
|
|
589
|
+
if (this.variant === "mariadb" && typeof n.update != "function" && this.isCompleteInsertRow(e, t)) return this.executeMariadbUpsert(e, t, {
|
|
583
590
|
conflictColumns: n.conflictColumns,
|
|
584
591
|
...n.update === void 0 ? {} : { update: n.update }
|
|
585
592
|
}, r, i);
|
|
@@ -601,39 +608,70 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
601
608
|
return N((n) => this.executeInsert(e, t, r, i, n));
|
|
602
609
|
}
|
|
603
610
|
async executeMariadbUpsert(e, t, r, i, a, o) {
|
|
604
|
-
let s = this.sql, c = C(t, e), l = Object.keys(c).filter((e) => c[e] !== void 0), u = r.update === void 0 ? l.filter((e) => e !== "id" && !r.conflictColumns.includes(e)) : r.update, d = u.length > 0 ? s.csv(u.map((e) => s`${s(e)} = VALUES(${s(e)})`)) : s`${s(r.conflictColumns[0])} = VALUES(${s(r.conflictColumns[0])})`, f =
|
|
605
|
-
|
|
606
|
-
|
|
611
|
+
let s = this.sql, c = C(t, e), l = Object.keys(c).filter((e) => c[e] !== void 0), u = r.update === void 0 ? l.filter((e) => e !== "id" && !r.conflictColumns.includes(e)) : r.update, d = u.length > 0 ? s.csv(u.map((e) => s`${s(e)} = VALUES(${s(e)})`)) : s`${s(r.conflictColumns[0])} = VALUES(${s(r.conflictColumns[0])})`, f = await this.runPinned(i, (i) => n.tryPromise({
|
|
612
|
+
try: async () => {
|
|
613
|
+
let a = s`INSERT INTO ${s(this.nsT(e))} ${s.insert(c)} ON DUPLICATE KEY UPDATE ${d} RETURNING *`, o = (await this.runtime.runPromise(n.provideService(a, I, i)))[0];
|
|
614
|
+
if (!o) throw Error(`MysqlStore.upsert: no row returned for table '${e}'`);
|
|
615
|
+
let l = t.id;
|
|
616
|
+
if (l != null && o.id !== l) throw Error(`MysqlStore.upsert: the row written to '${e}' is not the row that was passed in. Upserting id '${String(l)}' matched an existing row with id '${String(o.id)}' on a DIFFERENT unique constraint than the conflictColumns [${r.conflictColumns.join(", ")}] you named, so that row would have been updated and yours never written. Nothing was changed. Name the constraint that actually collides, or resolve the duplicate first.`);
|
|
617
|
+
return o;
|
|
618
|
+
},
|
|
619
|
+
catch: (e) => e
|
|
620
|
+
}), "upsert"), p = t.id !== void 0 && t.id === f.id ? "insert" : "update";
|
|
607
621
|
return await this.routeEvent({
|
|
608
622
|
table: e,
|
|
609
|
-
op:
|
|
623
|
+
op: p,
|
|
610
624
|
old: null,
|
|
611
|
-
new:
|
|
612
|
-
}, a, i, o),
|
|
625
|
+
new: f
|
|
626
|
+
}, a, i, o), f;
|
|
613
627
|
}
|
|
614
628
|
async executeInsertIgnore(e, t, r, i, a, o) {
|
|
615
|
-
t = M(e, t);
|
|
616
|
-
let s =
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
op: "insert",
|
|
622
|
-
old: null,
|
|
623
|
-
new: d
|
|
624
|
-
}, a, i, o), d) : this.resolveSkippedInsertIgnore(e, t, r, await this.readWarnings(i), i);
|
|
625
|
-
await u(c`INSERT IGNORE INTO ${c(this.nsT(e))} ${c.insert(l)}`);
|
|
626
|
-
let f = await this.readWarnings(i);
|
|
627
|
-
return !f.some((e) => Z.has(e.code)) && (d = (await u(c`SELECT * FROM ${c(this.nsT(e))} WHERE ${c("id")} = ${s}`))[0], d) ? (await this.routeEvent({
|
|
629
|
+
if (t = M(e, t), t.id === void 0) return await this.findByConflict(e, t, r.conflictColumns, i) || N((n) => this.executeInsert(e, t, i, a, n));
|
|
630
|
+
let s = await this.runPinned(i, (i) => n.tryPromise({
|
|
631
|
+
try: () => this.decideInsertIgnore(e, t, r, i),
|
|
632
|
+
catch: (e) => e
|
|
633
|
+
}), "insertIgnore");
|
|
634
|
+
return s.kind === "landed" && await this.routeEvent({
|
|
628
635
|
table: e,
|
|
629
636
|
op: "insert",
|
|
630
637
|
old: null,
|
|
631
|
-
new:
|
|
632
|
-
}, a, i, o),
|
|
638
|
+
new: s.row
|
|
639
|
+
}, a, i, o), s.row;
|
|
640
|
+
}
|
|
641
|
+
async decideInsertIgnore(e, t, r, i) {
|
|
642
|
+
let a = this.sql, o = C(t, e), s = (e) => this.runtime.runPromise(n.provideService(e, I, i));
|
|
643
|
+
if (this.supportsInsertReturning) {
|
|
644
|
+
let n = (await s(a`INSERT IGNORE INTO ${a(this.nsT(e))} ${a.insert(o)} RETURNING *`))[0];
|
|
645
|
+
if (n) return {
|
|
646
|
+
kind: "landed",
|
|
647
|
+
row: n
|
|
648
|
+
};
|
|
649
|
+
let c = await this.readWarnings(i);
|
|
650
|
+
return {
|
|
651
|
+
kind: "existing",
|
|
652
|
+
row: await this.resolveSkippedInsertIgnore(e, t, r, c, i)
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
await s(a`INSERT IGNORE INTO ${a(this.nsT(e))} ${a.insert(o)}`);
|
|
656
|
+
let c = await this.readWarnings(i);
|
|
657
|
+
if (!c.some((e) => X.has(e.code))) {
|
|
658
|
+
let n = (await s(a`SELECT * FROM ${a(this.nsT(e))} WHERE ${a("id")} = ${t.id}`))[0];
|
|
659
|
+
if (n) return {
|
|
660
|
+
kind: "landed",
|
|
661
|
+
row: n
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
return {
|
|
665
|
+
kind: "existing",
|
|
666
|
+
row: await this.resolveSkippedInsertIgnore(e, t, r, c, i)
|
|
667
|
+
};
|
|
633
668
|
}
|
|
634
669
|
async resolveSkippedInsertIgnore(e, t, n, r, i) {
|
|
635
|
-
let a = r.find((e) => !
|
|
636
|
-
if (a !== void 0) throw Error(`MysqlStore.insertIgnore: the insert into '${e}' was REJECTED, not skipped as a conflict. INSERT IGNORE downgrades every error to a warning, and the warning was: [${a.code}] ${a.message}. Nothing was written and nothing conflicted — fix the cause above
|
|
670
|
+
let a = r.find((e) => !X.has(e.code));
|
|
671
|
+
if (a !== void 0) throw Error(`MysqlStore.insertIgnore: the insert into '${e}' was REJECTED, not skipped as a conflict. INSERT IGNORE downgrades every error to a warning, and the warning was: [${a.code}] ${a.message}. Nothing was written and nothing conflicted — fix the cause above.`, { cause: {
|
|
672
|
+
errno: a.code,
|
|
673
|
+
sqlMessage: a.message
|
|
674
|
+
} });
|
|
637
675
|
let o = await this.findByConflict(e, t, n.conflictColumns, i);
|
|
638
676
|
if (o) return o;
|
|
639
677
|
let s = r[0];
|
|
@@ -642,7 +680,7 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
642
680
|
async findUndecodableCdcTables(e) {
|
|
643
681
|
if (this.variant !== "mariadb") return [];
|
|
644
682
|
try {
|
|
645
|
-
let t = (await this.runtime.runPromise(this.sql.unsafe(
|
|
683
|
+
let t = (await this.runtime.runPromise(this.sql.unsafe(me))).map((e) => String(e.tableName ?? e.TABLE_NAME ?? "")).filter((e) => e !== "");
|
|
646
684
|
return e === void 0 ? t : t.filter((t) => e.includes(t));
|
|
647
685
|
} catch (e) {
|
|
648
686
|
return this.log.debug(`cdc: could not probe for undecodable tables — ${e?.message ?? String(e)}`), [];
|
|
@@ -652,7 +690,7 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
652
690
|
if (e === null) return [];
|
|
653
691
|
try {
|
|
654
692
|
let t = this.sql`SHOW WARNINGS`.unprepared;
|
|
655
|
-
return (await this.runtime.runPromise(n.provideService(t,
|
|
693
|
+
return (await this.runtime.runPromise(n.provideService(t, I, e))).map((e) => ({
|
|
656
694
|
code: Number(e.Code ?? e.code ?? 0),
|
|
657
695
|
message: String(e.Message ?? e.message ?? "")
|
|
658
696
|
}));
|
|
@@ -662,7 +700,7 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
662
700
|
}
|
|
663
701
|
async findByConflict(e, t, r, i) {
|
|
664
702
|
if (r.length === 0) return;
|
|
665
|
-
let a = this.sql, o = r.map((e) => a`${a(e)} = ${t[e]}`), s = a`SELECT * FROM ${a(this.nsT(e))} WHERE ${a.and(o)} LIMIT 1`, c = i ? n.provideService(s,
|
|
703
|
+
let a = this.sql, o = r.map((e) => a`${a(e)} = ${t[e]}`), s = a`SELECT * FROM ${a(this.nsT(e))} WHERE ${a.and(o)} LIMIT 1`, c = i ? n.provideService(s, I, i) : s;
|
|
666
704
|
return (await this.runtime.runPromise(c))[0];
|
|
667
705
|
}
|
|
668
706
|
query(e) {
|
|
@@ -670,13 +708,13 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
670
708
|
}
|
|
671
709
|
raw(e, t) {
|
|
672
710
|
let n = b(e, this.sql);
|
|
673
|
-
return
|
|
711
|
+
return O(this.variant, "raw", () => this.runtime.runPromise(n));
|
|
674
712
|
}
|
|
675
713
|
async runWithEager(e, t) {
|
|
676
|
-
if (!
|
|
714
|
+
if (!ee(e)) return this.executeQuery(e, t);
|
|
677
715
|
let r = this.variant === "mariadb" ? "mariadb" : "mysql", i = this.namespace === null ? v(e, this.sql, r) : null;
|
|
678
716
|
if (i !== null) try {
|
|
679
|
-
let e = t ? n.provideService(i.fragment,
|
|
717
|
+
let e = t ? n.provideService(i.fragment, I, t) : i.fragment, r = await O(this.variant, "select", () => this.runtime.runPromise(e));
|
|
680
718
|
return i.decode(r);
|
|
681
719
|
} catch (t) {
|
|
682
720
|
if (t instanceof u) throw t;
|
|
@@ -693,13 +731,13 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
693
731
|
reason: "not-compilable"
|
|
694
732
|
});
|
|
695
733
|
let a = await this.executeQuery(e, t);
|
|
696
|
-
return f(a, e.eager, e.sourceTable ??
|
|
734
|
+
return f(a, e.eager, e.sourceTable ?? A(e.table), (e) => this.executeQuery(e, t));
|
|
697
735
|
}
|
|
698
736
|
getInternalRunWithEager() {
|
|
699
737
|
return this.runWithEager.bind(this);
|
|
700
738
|
}
|
|
701
739
|
async localWrite(e, t, n) {
|
|
702
|
-
return
|
|
740
|
+
return O(this.variant, e, async () => {
|
|
703
741
|
if (this.changeStrategy !== "cdc") return N(n);
|
|
704
742
|
h(t);
|
|
705
743
|
try {
|
|
@@ -744,15 +782,15 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
744
782
|
let i = this.sql, o = y(r.where, i, this.namespace);
|
|
745
783
|
this.changeStrategy === "cdc" && h(e), this.inflightTxns++;
|
|
746
784
|
try {
|
|
747
|
-
let r = n.suspend(() => this.sql.withTransaction(n.flatMap(n.serviceOption(
|
|
785
|
+
let r = n.suspend(() => this.sql.withTransaction(n.flatMap(n.serviceOption(I), (r) => {
|
|
748
786
|
if (a.isNone(r)) return n.fail(/* @__PURE__ */ Error("MysqlStore.updateMany: TransactionConnection missing."));
|
|
749
787
|
let s = r.value, c = i`SELECT id FROM ${i(this.nsT(e))} WHERE ${o} FOR UPDATE`, l = i`UPDATE ${i(this.nsT(e))} SET ${i.update(C(t, e))} WHERE ${o}`;
|
|
750
|
-
return n.flatMap(n.provideService(c,
|
|
788
|
+
return n.flatMap(n.provideService(c, I, s), (t) => {
|
|
751
789
|
if (t.length === 0) return n.succeed([]);
|
|
752
790
|
let r = t.map((e) => e.id), a = i`SELECT * FROM ${i(this.nsT(e))} WHERE ${i("id")} IN ${i.in(r)}`;
|
|
753
|
-
return n.flatMap(n.provideService(l,
|
|
791
|
+
return n.flatMap(n.provideService(l, I, s), () => n.provideService(a, I, s));
|
|
754
792
|
});
|
|
755
|
-
}))), c = s.exponential("10 millis").pipe(s.compose(s.recurs(3)), s.whileInput(
|
|
793
|
+
}))), c = s.exponential("10 millis").pipe(s.compose(s.recurs(3)), s.whileInput(q)), l = r.pipe(n.retry(c), n.withSpan("store.updateMany", { attributes: {
|
|
756
794
|
"db.system": this.variant,
|
|
757
795
|
"db.operation": "update"
|
|
758
796
|
} })), u = await this.runtime.runPromise(l);
|
|
@@ -783,11 +821,11 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
783
821
|
}
|
|
784
822
|
this.changeStrategy === "cdc" && h(e), this.inflightTxns++;
|
|
785
823
|
try {
|
|
786
|
-
let t = n.suspend(() => this.sql.withTransaction(n.flatMap(n.serviceOption(
|
|
824
|
+
let t = n.suspend(() => this.sql.withTransaction(n.flatMap(n.serviceOption(I), (t) => {
|
|
787
825
|
if (a.isNone(t)) return n.fail(/* @__PURE__ */ Error("MysqlStore.deleteMany: TransactionConnection missing."));
|
|
788
826
|
let o = t.value, s = r`SELECT * FROM ${r(this.nsT(e))} WHERE ${i} FOR UPDATE`, c = r`DELETE FROM ${r(this.nsT(e))} WHERE ${i}`;
|
|
789
|
-
return n.flatMap(n.provideService(s,
|
|
790
|
-
}))), o = s.exponential("10 millis").pipe(s.compose(s.recurs(3)), s.whileInput(
|
|
827
|
+
return n.flatMap(n.provideService(s, I, o), (e) => e.length === 0 ? n.succeed(e) : n.as(n.provideService(c, I, o), e));
|
|
828
|
+
}))), o = s.exponential("10 millis").pipe(s.compose(s.recurs(3)), s.whileInput(q)), c = t.pipe(n.retry(o), n.withSpan("store.deleteMany", { attributes: {
|
|
791
829
|
"db.system": this.variant,
|
|
792
830
|
"db.operation": "delete"
|
|
793
831
|
} })), l = await this.runtime.runPromise(c);
|
|
@@ -811,8 +849,8 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
811
849
|
if (this.cdcHandle) return;
|
|
812
850
|
await this.assertBinlogConfig(), this.cdcReplicaId = e.replicaId;
|
|
813
851
|
let t = await this.readCdcOffset(e.replicaId) ?? await this.resolveBinlogEnd(), n = await this.findUndecodableCdcTables(e.includeTables);
|
|
814
|
-
for (let e of n) this.log.error(
|
|
815
|
-
this.cdcHandle = await
|
|
852
|
+
for (let e of n) this.log.error(W(e));
|
|
853
|
+
this.cdcHandle = await K({
|
|
816
854
|
connection: e.connection,
|
|
817
855
|
serverId: e.serverId,
|
|
818
856
|
variant: this.variant,
|
|
@@ -930,10 +968,10 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
930
968
|
async transactional(e) {
|
|
931
969
|
this.inflightTxns++;
|
|
932
970
|
try {
|
|
933
|
-
return await
|
|
971
|
+
return await ae({
|
|
934
972
|
...this.txnSpec("MysqlStore.transactional"),
|
|
935
973
|
work: e,
|
|
936
|
-
makeView: (e, t) => new
|
|
974
|
+
makeView: (e, t) => new Te(this, e, t)
|
|
937
975
|
});
|
|
938
976
|
} finally {
|
|
939
977
|
this.inflightTxns--;
|
|
@@ -945,7 +983,7 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
945
983
|
dialect: this.variant === "mariadb" ? "mariadb" : "mysql",
|
|
946
984
|
withTransaction: (e) => this.sql.withTransaction(e),
|
|
947
985
|
runPromiseExit: (e) => this.runtime.runPromiseExit(e),
|
|
948
|
-
isRetryable:
|
|
986
|
+
isRetryable: q,
|
|
949
987
|
span: {
|
|
950
988
|
name: "store.transactional",
|
|
951
989
|
attributes: {
|
|
@@ -966,7 +1004,7 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
966
1004
|
injectExternalChange(e) {
|
|
967
1005
|
if (this.changeStrategy === "cdc" && !this.cdcGate.admit(e) || !D(e.table)) return;
|
|
968
1006
|
let t = (e.op === "delete" ? e.old : e.new)?.id;
|
|
969
|
-
|
|
1007
|
+
j(e.table, e.op, t, (t) => {
|
|
970
1008
|
this.emitter.emit("change", T(e, t));
|
|
971
1009
|
});
|
|
972
1010
|
}
|
|
@@ -991,7 +1029,7 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
991
1029
|
async ping() {
|
|
992
1030
|
await this.runtime.runPromise(this.sql`SELECT 1`);
|
|
993
1031
|
}
|
|
994
|
-
},
|
|
1032
|
+
}, Te = class {
|
|
995
1033
|
parent;
|
|
996
1034
|
txn;
|
|
997
1035
|
attr;
|
|
@@ -1064,12 +1102,12 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
1064
1102
|
this.events.length = 0;
|
|
1065
1103
|
}
|
|
1066
1104
|
}
|
|
1067
|
-
}, $ = (e) => e.__mysqlReplicationFriend ?? null,
|
|
1105
|
+
}, $ = (e) => e.__mysqlReplicationFriend ?? null, Ee = () => ({
|
|
1068
1106
|
async capturePrimaryPosition(e) {
|
|
1069
1107
|
let t = $(e);
|
|
1070
1108
|
if (t === null) throw Error("mysqlReplicationAdapter: primary is not a MysqlStore (missing __mysqlReplicationFriend).");
|
|
1071
1109
|
return t.runEffect(n.gen(function* () {
|
|
1072
|
-
let e = yield*
|
|
1110
|
+
let e = yield* F, r = (t.variant === "mariadb" ? yield* e`SELECT @@global.gtid_current_pos AS gtid` : yield* e`SELECT @@global.gtid_executed AS gtid`)[0]?.gtid;
|
|
1073
1111
|
return typeof r == "string" ? r : yield* n.die("mysql/mariadb did not return a GTID set");
|
|
1074
1112
|
}));
|
|
1075
1113
|
},
|
|
@@ -1077,31 +1115,31 @@ var se = (e) => e ? { rejectUnauthorized: !1 } : void 0, ce = (e) => {
|
|
|
1077
1115
|
let t = $(e);
|
|
1078
1116
|
if (t === null) throw Error("mysqlReplicationAdapter: replica is not a MysqlStore.");
|
|
1079
1117
|
return t.runEffect(n.gen(function* () {
|
|
1080
|
-
let e = yield*
|
|
1118
|
+
let e = yield* F, r = (t.variant === "mariadb" ? yield* e`SELECT @@global.gtid_current_pos AS gtid` : yield* e`SELECT @@global.gtid_executed AS gtid`)[0]?.gtid;
|
|
1081
1119
|
return typeof r == "string" ? r : yield* n.die("mysql/mariadb replica did not return a GTID set");
|
|
1082
1120
|
}));
|
|
1083
1121
|
},
|
|
1084
1122
|
compare(e, t) {
|
|
1085
1123
|
return "behind";
|
|
1086
1124
|
}
|
|
1087
|
-
}),
|
|
1125
|
+
}), De = {
|
|
1088
1126
|
id: "mysql",
|
|
1089
1127
|
makeSqlLayer: (e) => H(e),
|
|
1090
|
-
makeStore: (e) =>
|
|
1128
|
+
makeStore: (e) => Z({
|
|
1091
1129
|
...e,
|
|
1092
1130
|
variant: "mysql"
|
|
1093
1131
|
}),
|
|
1094
1132
|
compileContains: (e, t, n) => n`${e} LIKE ${`%${t.replace(/[\\%_]/g, (e) => `\\${e}`)}%`} ESCAPE '\\'`,
|
|
1095
|
-
retryFilter:
|
|
1096
|
-
},
|
|
1133
|
+
retryFilter: J
|
|
1134
|
+
}, Oe = {
|
|
1097
1135
|
id: "mariadb",
|
|
1098
1136
|
makeSqlLayer: (e) => H(e),
|
|
1099
|
-
makeStore: (e) =>
|
|
1137
|
+
makeStore: (e) => Z({
|
|
1100
1138
|
...e,
|
|
1101
1139
|
variant: "mariadb"
|
|
1102
1140
|
}),
|
|
1103
1141
|
compileContains: (e, t, n) => n`${e} LIKE ${`%${t.replace(/[\\%_]/g, (e) => `\\${e}`)}%`} ESCAPE '\\'`,
|
|
1104
|
-
retryFilter:
|
|
1142
|
+
retryFilter: J
|
|
1105
1143
|
};
|
|
1106
1144
|
//#endregion
|
|
1107
|
-
export { c as CDC_OFFSETS_TABLE, e as MysqlClient, d as _voltroCdcOffsetsTable, V as connectionFromConfig, z as makeMysqlSqlLayer, H as makeMysqlSqlLayerFromConfig,
|
|
1145
|
+
export { c as CDC_OFFSETS_TABLE, e as MysqlClient, d as _voltroCdcOffsetsTable, V as connectionFromConfig, z as makeMysqlSqlLayer, H as makeMysqlSqlLayerFromConfig, Z as makeMysqlStore, Oe as mariadbDialect, De as mysqlDialect, Ee as mysqlReplicationAdapter, J as mysqlRetryFilter, K as startBinlogCdc };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voltro/sql-mysql",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.43.0",
|
|
4
4
|
"description": "MySQL/MariaDB dialect adapter for Voltro's cross-dialect DataStore (mariadb binlog CDC; mysql inline reactivity).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"voltro",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@effect/sql": "^0.52.0",
|
|
37
37
|
"@effect/sql-mysql2": "^0.53.0",
|
|
38
|
-
"@voltro/database": "0.
|
|
39
|
-
"@voltro/logger": "0.
|
|
38
|
+
"@voltro/database": "0.43.0",
|
|
39
|
+
"@voltro/logger": "0.43.0"
|
|
40
40
|
},
|
|
41
41
|
"optionalDependencies": {
|
|
42
42
|
"@vlasky/zongji": "^0.9.0"
|