@voltro/sql-mysql 0.20.2 → 0.22.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/dist/index.js CHANGED
@@ -3,16 +3,16 @@ import { Config as t, Effect as n, Layer as r, ManagedRuntime as i, Option as a,
3
3
  import { EventEmitter as c } from "node:events";
4
4
  import { createLogger as l } from "@voltro/logger";
5
5
  import { SqlClient as u, TransactionConnection as d } from "@effect/sql/SqlClient";
6
- import { CDC_OFFSETS_TABLE as f, EagerCardinalityError as p, _voltroCdcOffsetsTable as m, attachEagerLoads as h, attributionFields as g, attributionKey as _, claimPendingAttribution as v, compileEagerJson as y, compilePredicate as b, compileRawFragment as x, compileSelect as S, currentWriteAttribution as C, decodeRowsFromSchema as w, encodeRowForSchema as T, hasEagerLoads as E, isTableReactive as D, qualifyTable as ee, raiseChangeListenerCeiling as O, recordsTable as te, registerPendingAttribution as ne, requireTable as re, runWithWriteAttribution as k, runWriteRecorders as A, settleTransactionExit as j, stampGeneratedId as M, stampGeneratedIds as N } from "@voltro/database";
6
+ import { CDC_OFFSETS_TABLE as f, EagerCardinalityError as p, _voltroCdcOffsetsTable as m, attachEagerLoads as h, attributionFields as g, attributionKey as _, beginLocalWrite as v, compileEagerJson as y, compilePredicate as b, compileRawFragment as x, compileSelect as S, currentWriteAttribution as C, decodeRowsFromSchema as w, encodeRowForSchema as T, endLocalWrite as E, hasEagerLoads as D, isTableReactive as O, qualifyTable as ee, raiseChangeListenerCeiling as te, recordsTable as ne, registerPendingAttribution as re, requireTable as k, resolveEchoAttribution as A, runWithWriteAttribution as ie, runWriteRecorders as ae, settleTransactionExit as oe, stampGeneratedId as j, stampGeneratedIds as se, withCapturedAttribution as M } from "@voltro/database";
7
7
  //#region src/sqlLayer.ts
8
- var P = (n) => e.layerConfig({
8
+ var N = (n) => e.layerConfig({
9
9
  host: t.succeed(n.host),
10
10
  port: t.succeed(n.port),
11
11
  username: t.succeed(n.username),
12
12
  password: t.succeed(o.make(n.password)),
13
13
  database: t.succeed(n.database),
14
14
  ...n.maxConnections === void 0 ? {} : { maxConnections: t.succeed(n.maxConnections) }
15
- }), F = (e) => {
15
+ }), P = (e) => {
16
16
  if (e.url) {
17
17
  let t = new URL(e.url);
18
18
  return {
@@ -32,20 +32,20 @@ var P = (n) => e.layerConfig({
32
32
  database: e.database ?? "app",
33
33
  ...e.maxConnections === void 0 ? {} : { maxConnections: e.maxConnections }
34
34
  };
35
- }, I = (e) => P(F(e)), ie = (e, t) => e === null ? !1 : t === null ? !0 : e.filename === t.filename ? e.position > t.position : e.filename > t.filename, ae = (e) => e.msSinceProgress < e.stallThresholdMs ? "healthy" : e.primary !== null && !ie(e.primary, e.reader) ? "idle-caught-up" : "reconnect", L = (e) => (e instanceof Error ? e.message : String(e ?? "")).includes("schema changed between binlog event and metadata fetch"), R = (e) => {
35
+ }, F = (e) => N(P(e)), I = (e, t) => e === null ? !1 : t === null ? !0 : e.filename === t.filename ? e.position > t.position : e.filename > t.filename, L = (e) => e.msSinceProgress < e.stallThresholdMs ? "healthy" : e.primary !== null && !I(e.primary, e.reader) ? "idle-caught-up" : "reconnect", R = (e) => (e instanceof Error ? e.message : String(e ?? "")).includes("schema changed between binlog event and metadata fetch"), z = (e) => {
36
36
  let t = e instanceof Error ? e.message : String(e ?? "");
37
37
  return /Table\s+[^\s.]+\.(\S+)\s+schema changed between binlog event and metadata fetch/.exec(t)?.[1] ?? null;
38
- }, z = "\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", B = (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).`, V = 5 * 6e4, H = 3, U = (e, t) => {
39
- let n = [...e.filter((e) => t - e < V), t];
38
+ }, B = "\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", V = (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).`, H = 5 * 6e4, U = 3, W = (e, t) => {
39
+ let n = [...e.filter((e) => t - e < H), t];
40
40
  return {
41
- verdict: n.length >= H ? "persistent" : "backlog",
41
+ verdict: n.length >= U ? "persistent" : "backlog",
42
42
  hits: n
43
43
  };
44
- }, W = /* @__PURE__ */ new Set([
44
+ }, G = /* @__PURE__ */ new Set([
45
45
  "writerows",
46
46
  "updaterows",
47
47
  "deleterows"
48
- ]), G = /\b(alter|rename|drop|create)\s+(table|column)?/i, K = (e) => new Promise((t) => setTimeout(t, e)), q = async (e) => {
48
+ ]), ce = /\b(alter|rename|drop|create)\s+(table|column)?/i, K = (e) => new Promise((t) => setTimeout(t, e)), q = async (e) => {
49
49
  let t = l({ scope: `voltro:${e.variant}:cdc` }), n;
50
50
  try {
51
51
  n = (await import("@vlasky/zongji")).default;
@@ -61,14 +61,14 @@ var P = (n) => e.layerConfig({
61
61
  o = n.binlogName;
62
62
  return;
63
63
  }
64
- if (r === "query" && n.query && G.test(n.query)) {
64
+ if (r === "query" && n.query && ce.test(n.query)) {
65
65
  u && (u.tableMap = {});
66
66
  return;
67
67
  }
68
68
  if (n.nextPosition && o && (s = {
69
69
  filename: o,
70
70
  position: n.nextPosition
71
- }, e.onPosition?.(s)), !W.has(r)) return;
71
+ }, e.onPosition?.(s)), !G.has(r)) return;
72
72
  let l = n.tableMap[n.tableId];
73
73
  if (!l || l.parentSchema !== a) return;
74
74
  let d = l.tableName;
@@ -147,10 +147,10 @@ var P = (n) => e.layerConfig({
147
147
  u?.stop();
148
148
  } catch {}
149
149
  if (f++, await K(Math.min(3e4, 500 * 2 ** Math.min(f, 6))), d) return;
150
- let i = s, a = C(n), c = !a && L(n), l = !1;
150
+ let i = s, a = C(n), c = !a && R(n), l = !1;
151
151
  if (c) {
152
- let e = R(n), i = e ?? "<unknown>", { verdict: a, hits: o } = U(h.get(i) ?? [], Date.now());
153
- h.set(i, o), l = a === "persistent", l && !g.has(i) && (g.add(i), e !== null && r.add(e), t.error(B(i)));
152
+ let e = z(n), i = e ?? "<unknown>", { verdict: a, hits: o } = W(h.get(i) ?? [], Date.now());
153
+ h.set(i, o), l = a === "persistent", l && !g.has(i) && (g.add(i), e !== null && r.add(e), t.error(V(i)));
154
154
  }
155
155
  (a || c) && (l || 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, l || e.onResync?.());
156
156
  try {
@@ -181,7 +181,7 @@ var P = (n) => e.layerConfig({
181
181
  if (d || m || Date.now() - p < v) return;
182
182
  let n = null;
183
183
  if (e.resolveStartPosition && (n = await e.resolveStartPosition().catch(() => null)), d || m) return;
184
- let r = ae({
184
+ let r = L({
185
185
  msSinceProgress: Date.now() - p,
186
186
  stallThresholdMs: v,
187
187
  primary: n,
@@ -210,7 +210,7 @@ var P = (n) => e.layerConfig({
210
210
  },
211
211
  currentPosition: () => s
212
212
  };
213
- }, oe = /* @__PURE__ */ new Set(["1213", "1205"]), se = (e) => {
213
+ }, le = /* @__PURE__ */ new Set(["1213", "1205"]), ue = (e) => {
214
214
  let t = e;
215
215
  for (let e = 0; e < 5 && typeof t == "object" && t; e++) {
216
216
  let e = t.errno;
@@ -220,8 +220,8 @@ var P = (n) => e.layerConfig({
220
220
  t = t.cause;
221
221
  }
222
222
  }, J = (e) => {
223
- let t = se(e);
224
- return t !== void 0 && oe.has(t);
223
+ let t = ue(e);
224
+ return t !== void 0 && le.has(t);
225
225
  }, Y = (e) => J(e) ? "retry" : "noRetry", X = (e) => {
226
226
  if (e == null) return "null";
227
227
  let t = typeof e;
@@ -231,19 +231,19 @@ var P = (n) => e.layerConfig({
231
231
  if (Array.isArray(e)) return `[${e.map(X).join(",")}]`;
232
232
  let n = e;
233
233
  return `{${Object.keys(n).sort().map((e) => `${JSON.stringify(e)}:${X(n[e])}`).join(",")}}`;
234
- }, ce = (e) => {
234
+ }, Z = (e) => {
235
235
  let t = X(e), n = 2166136261;
236
236
  for (let e = 0; e < t.length; e++) n ^= t.charCodeAt(e), n = Math.imul(n, 16777619);
237
237
  return (n >>> 0).toString(36);
238
- }, le = (e, t) => {
238
+ }, de = (e, t) => {
239
239
  let n = setTimeout(e, t);
240
240
  typeof n.unref == "function" && n.unref();
241
- }, ue = class {
241
+ }, fe = class {
242
242
  variant;
243
243
  ttlMs;
244
244
  schedule;
245
245
  seen = /* @__PURE__ */ new Map();
246
- constructor(e, t = 6e4, n = le) {
246
+ constructor(e, t = 6e4, n = de) {
247
247
  this.variant = e, this.ttlMs = t, this.schedule = n;
248
248
  }
249
249
  key(e) {
@@ -257,7 +257,7 @@ var P = (n) => e.layerConfig({
257
257
  } catch {
258
258
  r = t;
259
259
  }
260
- return `${e.table} ${e.op} ${String(n)} ${ce(r)}`;
260
+ return `${e.table} ${e.op} ${String(n)} ${Z(r)}`;
261
261
  }
262
262
  admit(e) {
263
263
  let t = this.key(e);
@@ -272,19 +272,19 @@ var P = (n) => e.layerConfig({
272
272
  get pending() {
273
273
  return this.seen.size;
274
274
  }
275
- }, de = /* @__PURE__ */ new Set([
275
+ }, pe = /* @__PURE__ */ new Set([
276
276
  1022,
277
277
  1062,
278
278
  1586
279
- ]), Z = async (e) => {
279
+ ]), Q = async (e) => {
280
280
  let t = e.variant ?? "mysql", n = l({ scope: `voltro:${t}` }), a = e.changeStrategy ?? "inline", o = a;
281
281
  a === "cdc" && !e.cdcConfig && (n.warn("changeStrategy='cdc' requires cdcConfig (serverId + connection); falling back to 'inline'."), o = "inline");
282
- let s = e.tracerLayer ? r.mergeAll(e.sqlLayer, e.tracerLayer) : e.sqlLayer, c = i.make(s), d = new fe(await c.runPromise(u), c, t, o);
282
+ let s = e.tracerLayer ? r.mergeAll(e.sqlLayer, e.tracerLayer) : e.sqlLayer, c = i.make(s), d = new he(await c.runPromise(u), c, t, o);
283
283
  return o === "cdc" && e.cdcConfig && await d.startCdcConsumer(e.cdcConfig), d;
284
- }, Q = () => {
284
+ }, me = () => {
285
285
  let e = C();
286
- return e === void 0 ? (e) => e() : (t) => k(e, t);
287
- }, fe = class e {
286
+ return e === void 0 ? (e) => e() : (t) => ie(e, t);
287
+ }, he = class e {
288
288
  sql;
289
289
  runtime;
290
290
  variant;
@@ -300,7 +300,7 @@ var P = (n) => e.layerConfig({
300
300
  cdcStreamName = "default";
301
301
  cdcGate;
302
302
  constructor(e, t, n, r = "inline", i = null, a, o) {
303
- this.sql = e, this.runtime = t, this.variant = n, this.changeStrategy = r, this.namespace = i, this.log = l({ scope: `voltro:${n}` }), this.emitter = a ?? new c(), O(this.emitter), this.cdcGate = o ?? new ue(n);
303
+ this.sql = e, this.runtime = t, this.variant = n, this.changeStrategy = r, this.namespace = i, this.log = l({ scope: `voltro:${n}` }), this.emitter = a ?? new c(), te(this.emitter), this.cdcGate = o ?? new fe(n);
304
304
  }
305
305
  withNamespace(t) {
306
306
  return t === this.namespace ? this : new e(this.sql, this.runtime, this.variant, this.changeStrategy, t, this.emitter, this.cdcGate);
@@ -317,9 +317,9 @@ var P = (n) => e.layerConfig({
317
317
  variant: this.variant
318
318
  };
319
319
  }
320
- async executeQuery(e, t) {
321
- let r = S(e, this.sql, this.namespace), i = t ? n.provideService(r, d, t) : r;
322
- return w(await this.runtime.runPromise(i), e.table, this.variant);
320
+ async executeQuery(e, t, r) {
321
+ let i = S(e, this.sql, this.namespace), a = t ? n.provideService(i, d, t) : i;
322
+ return w(await this.runtime.runPromise(a), e.table, this.variant);
323
323
  }
324
324
  get supportsInsertReturning() {
325
325
  return this.variant === "mariadb";
@@ -330,39 +330,39 @@ var P = (n) => e.layerConfig({
330
330
  get supportsUpdateReturning() {
331
331
  return !1;
332
332
  }
333
- async executeInsert(e, t, r, i) {
334
- t = M(e, t);
335
- let a = this.sql;
333
+ async executeInsert(e, t, r, i, a) {
334
+ t = j(e, t);
335
+ let o = this.sql;
336
336
  if (this.supportsInsertReturning) {
337
- let o = a`INSERT INTO ${a(this.nsT(e))} ${a.insert(T(t, e))} RETURNING *`, s = r ? n.provideService(o, d, r) : o, c = (await this.runtime.runPromise(s))[0];
338
- if (!c) throw Error(`MysqlStore.insert: no row returned for table '${e}'`);
337
+ let s = o`INSERT INTO ${o(this.nsT(e))} ${o.insert(T(t, e))} RETURNING *`, c = r ? n.provideService(s, d, r) : s, l = (await this.runtime.runPromise(c))[0];
338
+ if (!l) throw Error(`MysqlStore.insert: no row returned for table '${e}'`);
339
339
  return await this.routeEvent({
340
340
  table: e,
341
341
  op: "insert",
342
342
  old: null,
343
- new: c
344
- }, i, r), c;
343
+ new: l
344
+ }, i, r, a), l;
345
345
  }
346
- let o = T(t, e), s = t.id;
347
- if (s === void 0) {
348
- let t = await this.insertRecoverAutoId(e, o, r);
346
+ let s = T(t, e), c = t.id;
347
+ if (c === void 0) {
348
+ let t = await this.insertRecoverAutoId(e, s, r);
349
349
  return await this.routeEvent({
350
350
  table: e,
351
351
  op: "insert",
352
352
  old: null,
353
353
  new: t
354
- }, i, r), t;
354
+ }, i, r, a), t;
355
355
  }
356
- let c = a`INSERT INTO ${a(this.nsT(e))} ${a.insert(o)}`, l = r ? n.provideService(c, d, r) : c;
357
- await this.runtime.runPromise(l);
358
- let u = a`SELECT * FROM ${a(this.nsT(e))} WHERE ${a("id")} = ${s}`, f = r ? n.provideService(u, d, r) : u, p = (await this.runtime.runPromise(f))[0];
359
- if (!p) throw Error(`MysqlStore.insert: row not found post-insert in '${e}'`);
356
+ let l = o`INSERT INTO ${o(this.nsT(e))} ${o.insert(s)}`, u = r ? n.provideService(l, d, r) : l;
357
+ await this.runtime.runPromise(u);
358
+ let f = o`SELECT * FROM ${o(this.nsT(e))} WHERE ${o("id")} = ${c}`, p = r ? n.provideService(f, d, r) : f, m = (await this.runtime.runPromise(p))[0];
359
+ if (!m) throw Error(`MysqlStore.insert: row not found post-insert in '${e}'`);
360
360
  return await this.routeEvent({
361
361
  table: e,
362
362
  op: "insert",
363
363
  old: null,
364
- new: p
365
- }, i, r), p;
364
+ new: m
365
+ }, i, r, a), m;
366
366
  }
367
367
  async insertRecoverAutoId(e, t, r) {
368
368
  let i = this.sql;
@@ -386,41 +386,41 @@ var P = (n) => e.layerConfig({
386
386
  this.inflightTxns--;
387
387
  }
388
388
  }
389
- async executeInsertMany(e, t, r, i) {
390
- if (t = N(e, t), t.length === 0) return [];
391
- let a = this.sql, o = t.map((t) => T(t, e));
389
+ async executeInsertMany(e, t, r, i, a) {
390
+ if (t = se(e, t), t.length === 0) return [];
391
+ let o = this.sql, s = t.map((t) => T(t, e));
392
392
  if (this.supportsInsertReturning) {
393
- let t = a`INSERT INTO ${a(this.nsT(e))} ${a.insert(o)} RETURNING *`, s = r ? n.provideService(t, d, r) : t, c = await this.runtime.runPromise(s);
394
- for (let t of c) await this.routeEvent({
393
+ let t = o`INSERT INTO ${o(this.nsT(e))} ${o.insert(s)} RETURNING *`, c = r ? n.provideService(t, d, r) : t, l = await this.runtime.runPromise(c);
394
+ for (let t of l) await this.routeEvent({
395
395
  table: e,
396
396
  op: "insert",
397
397
  old: null,
398
398
  new: t
399
- }, i, r);
400
- return c;
399
+ }, i, r, a);
400
+ return l;
401
401
  }
402
- let s = t.map((e) => e.id);
403
- if (s.every((e) => e === void 0)) {
404
- let t = await this.insertManyRecoverAutoIds(e, o, r);
402
+ let c = t.map((e) => e.id);
403
+ if (c.every((e) => e === void 0)) {
404
+ let t = await this.insertManyRecoverAutoIds(e, s, r);
405
405
  for (let n of t) await this.routeEvent({
406
406
  table: e,
407
407
  op: "insert",
408
408
  old: null,
409
409
  new: n
410
- }, i, r);
410
+ }, i, r, a);
411
411
  return t;
412
412
  }
413
- if (s.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).");
414
- let c = a`INSERT INTO ${a(this.nsT(e))} ${a.insert(o)}`, l = r ? n.provideService(c, d, r) : c;
415
- await this.runtime.runPromise(l);
416
- let u = a`SELECT * FROM ${a(this.nsT(e))} WHERE ${a("id")} IN ${a.in(s)}`, f = r ? n.provideService(u, d, r) : u, p = await this.runtime.runPromise(f), m = new Map(p.map((e) => [e.id, e])), h = s.map((e) => m.get(e)).filter((e) => e !== void 0);
417
- for (let t of h) await this.routeEvent({
413
+ if (c.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).");
414
+ let l = o`INSERT INTO ${o(this.nsT(e))} ${o.insert(s)}`, u = r ? n.provideService(l, d, r) : l;
415
+ await this.runtime.runPromise(u);
416
+ let f = o`SELECT * FROM ${o(this.nsT(e))} WHERE ${o("id")} IN ${o.in(c)}`, p = r ? n.provideService(f, d, r) : f, m = await this.runtime.runPromise(p), h = new Map(m.map((e) => [e.id, e])), g = c.map((e) => h.get(e)).filter((e) => e !== void 0);
417
+ for (let t of g) await this.routeEvent({
418
418
  table: e,
419
419
  op: "insert",
420
420
  old: null,
421
421
  new: t
422
- }, i, r);
423
- return h;
422
+ }, i, r, a);
423
+ return g;
424
424
  }
425
425
  async insertManyRecoverAutoIds(e, t, r) {
426
426
  let i = this.sql, a = t.length;
@@ -433,58 +433,58 @@ var P = (n) => e.layerConfig({
433
433
  return yield* n.provideService(i`SELECT * FROM ${i(this.nsT(e))} WHERE ${i("id")} BETWEEN ${c} AND ${c + a - 1} ORDER BY ${i("id")} ASC`, d, r);
434
434
  }), "insert");
435
435
  }
436
- async executePatchJson(e, t, r, i, a, o) {
437
- let s = this.sql, c = r.split("."), l = c[0], u = c.slice(1), f = JSON.stringify(i ?? null), p = u.length === 0 ? "$" : `$.${u.join(".")}`, m = s`UPDATE ${s(this.nsT(e))} SET ${s(l)} = JSON_SET(COALESCE(${s(l)}, '{}'), ${p}, CAST(${f} AS JSON)) WHERE ${s("id")} = ${t}`, h = a ? n.provideService(m, d, a) : m, g = await this.runtime.runPromise(h);
438
- if (g && typeof g.affectedRows == "number" && g.affectedRows === 0) return null;
439
- let _ = s`SELECT * FROM ${s(this.nsT(e))} WHERE ${s("id")} = ${t}`, v = a ? n.provideService(_, d, a) : _, y = (await this.runtime.runPromise(v))[0];
440
- return y ? (await this.routeEvent({
436
+ async executePatchJson(e, t, r, i, a, o, s) {
437
+ let c = this.sql, l = r.split("."), u = l[0], f = l.slice(1), p = JSON.stringify(i ?? null), m = f.length === 0 ? "$" : `$.${f.join(".")}`, h = c`UPDATE ${c(this.nsT(e))} SET ${c(u)} = JSON_SET(COALESCE(${c(u)}, '{}'), ${m}, CAST(${p} AS JSON)) WHERE ${c("id")} = ${t}`, g = a ? n.provideService(h, d, a) : h, _ = await this.runtime.runPromise(g);
438
+ if (_ && typeof _.affectedRows == "number" && _.affectedRows === 0) return null;
439
+ let v = c`SELECT * FROM ${c(this.nsT(e))} WHERE ${c("id")} = ${t}`, y = a ? n.provideService(v, d, a) : v, b = (await this.runtime.runPromise(y))[0];
440
+ return b ? (await this.routeEvent({
441
441
  table: e,
442
442
  op: "update",
443
443
  old: null,
444
- new: y
445
- }, o, a), y) : null;
444
+ new: b
445
+ }, o, a, s), b) : null;
446
446
  }
447
- async executeUpdate(e, t, r, i, a) {
448
- let o = this.sql;
447
+ async executeUpdate(e, t, r, i, a, o) {
448
+ let s = this.sql;
449
449
  if (this.supportsUpdateReturning) {
450
- let s = o`UPDATE ${o(this.nsT(e))} SET ${o.update(T(r, e))} WHERE ${o("id")} = ${t} RETURNING *`, c = i ? n.provideService(s, d, i) : s, l = (await this.runtime.runPromise(c))[0];
451
- return l ? (await this.routeEvent({
450
+ let c = s`UPDATE ${s(this.nsT(e))} SET ${s.update(T(r, e))} WHERE ${s("id")} = ${t} RETURNING *`, l = i ? n.provideService(c, d, i) : c, u = (await this.runtime.runPromise(l))[0];
451
+ return u ? (await this.routeEvent({
452
452
  table: e,
453
453
  op: "update",
454
454
  old: null,
455
- new: l
456
- }, a, i), l) : null;
455
+ new: u
456
+ }, a, i, o), u) : null;
457
457
  }
458
- let s = o`UPDATE ${o(this.nsT(e))} SET ${o.update(T(r, e))} WHERE ${o("id")} = ${t}`, c = i ? n.provideService(s, d, i) : s, l = await this.runtime.runPromise(c);
459
- if (l && typeof l.affectedRows == "number" && l.affectedRows === 0) return null;
460
- let u = o`SELECT * FROM ${o(this.nsT(e))} WHERE ${o("id")} = ${t}`, f = i ? n.provideService(u, d, i) : u, p = (await this.runtime.runPromise(f))[0];
461
- return p ? (await this.routeEvent({
458
+ let c = s`UPDATE ${s(this.nsT(e))} SET ${s.update(T(r, e))} WHERE ${s("id")} = ${t}`, l = i ? n.provideService(c, d, i) : c, u = await this.runtime.runPromise(l);
459
+ if (u && typeof u.affectedRows == "number" && u.affectedRows === 0) return null;
460
+ let f = s`SELECT * FROM ${s(this.nsT(e))} WHERE ${s("id")} = ${t}`, p = i ? n.provideService(f, d, i) : f, m = (await this.runtime.runPromise(p))[0];
461
+ return m ? (await this.routeEvent({
462
462
  table: e,
463
463
  op: "update",
464
464
  old: null,
465
- new: p
466
- }, a, i), p) : null;
465
+ new: m
466
+ }, a, i, o), m) : null;
467
467
  }
468
- async executeDelete(e, t, r, i) {
469
- let a = this.sql;
468
+ async executeDelete(e, t, r, i, a) {
469
+ let o = this.sql;
470
470
  if (this.supportsDeleteReturning) {
471
- let o = a`DELETE FROM ${a(this.nsT(e))} WHERE ${a("id")} = ${t} RETURNING *`, s = r ? n.provideService(o, d, r) : o, c = (await this.runtime.runPromise(s))[0];
472
- return c ? (await this.routeEvent({
471
+ let s = o`DELETE FROM ${o(this.nsT(e))} WHERE ${o("id")} = ${t} RETURNING *`, c = r ? n.provideService(s, d, r) : s, l = (await this.runtime.runPromise(c))[0];
472
+ return l ? (await this.routeEvent({
473
473
  table: e,
474
474
  op: "delete",
475
- old: c,
475
+ old: l,
476
476
  new: null
477
- }, i, r), !0) : !1;
477
+ }, i, r, a), !0) : !1;
478
478
  }
479
- let o = a`SELECT * FROM ${a(this.nsT(e))} WHERE ${a("id")} = ${t}`, s = r ? n.provideService(o, d, r) : o, c = (await this.runtime.runPromise(s))[0];
480
- if (!c) return !1;
481
- let l = a`DELETE FROM ${a(this.nsT(e))} WHERE ${a("id")} = ${t}`, u = r ? n.provideService(l, d, r) : l;
482
- return await this.runtime.runPromise(u), await this.routeEvent({
479
+ let s = o`SELECT * FROM ${o(this.nsT(e))} WHERE ${o("id")} = ${t}`, c = r ? n.provideService(s, d, r) : s, l = (await this.runtime.runPromise(c))[0];
480
+ if (!l) return !1;
481
+ let u = o`DELETE FROM ${o(this.nsT(e))} WHERE ${o("id")} = ${t}`, f = r ? n.provideService(u, d, r) : u;
482
+ return await this.runtime.runPromise(f), await this.routeEvent({
483
483
  table: e,
484
484
  op: "delete",
485
- old: c,
485
+ old: l,
486
486
  new: null
487
- }, i, r), !0;
487
+ }, i, r, a), !0;
488
488
  }
489
489
  async appendInTxn(e, t, r) {
490
490
  let i = this.sql, a = i`INSERT INTO ${i(this.nsT(e))} ${i.insert(T(t, e))}`;
@@ -494,11 +494,11 @@ var P = (n) => e.layerConfig({
494
494
  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, d, i) : s))[0]?.m;
495
495
  return c == null ? null : Number(c);
496
496
  }
497
- async routeEvent(e, t, n = null) {
497
+ async routeEvent(e, t, n = null, r) {
498
498
  if (e = {
499
- ...g(),
499
+ ...g(r),
500
500
  ...e
501
- }, te(e.table) && await A({
501
+ }, ne(e.table) && await ae({
502
502
  append: (e, t) => this.appendInTxn(e, t, n),
503
503
  maxOf: (e, t, r) => this.maxInTxn(e, t, r, n)
504
504
  }, {
@@ -510,7 +510,7 @@ var P = (n) => e.layerConfig({
510
510
  subjectId: e.subjectId
511
511
  }), this.changeStrategy === "cdc") {
512
512
  let t = (e.op === "delete" ? e.old : e.new)?.id;
513
- t != null && ne(_(e.table, e.op, t), {
513
+ t != null && re(_(e.table, e.op, t), {
514
514
  ...e.traceId === void 0 ? {} : { traceId: e.traceId },
515
515
  ...e.subjectId === void 0 ? {} : { subjectId: e.subjectId }
516
516
  });
@@ -521,61 +521,61 @@ var P = (n) => e.layerConfig({
521
521
  }
522
522
  this.emitChange(e);
523
523
  }
524
- async executeUpsert(e, t, n, r, i) {
524
+ async executeUpsert(e, t, n, r, i, a) {
525
525
  if (this.variant === "mariadb" && typeof n.update != "function") return this.executeMariadbUpsert(e, t, {
526
526
  conflictColumns: n.conflictColumns,
527
527
  ...n.update === void 0 ? {} : { update: n.update }
528
528
  }, r, i);
529
- let a = await this.findByConflict(e, t, n.conflictColumns, r);
530
- if (a) {
531
- let o;
532
- if (typeof n.update == "function") o = n.update(a);
529
+ let o = await this.findByConflict(e, t, n.conflictColumns, r);
530
+ if (o) {
531
+ let a;
532
+ if (typeof n.update == "function") a = n.update(o);
533
533
  else if (Array.isArray(n.update)) {
534
534
  let e = {};
535
535
  for (let r of n.update) r in t && (e[r] = t[r]);
536
- o = e;
536
+ a = e;
537
537
  } else {
538
538
  let e = {};
539
539
  for (let [r, i] of Object.entries(t)) r !== "id" && (n.conflictColumns.includes(r) || (e[r] = i));
540
- o = e;
540
+ a = e;
541
541
  }
542
- return await this.executeUpdate(e, a.id, o, r, i) ?? a;
542
+ return await this.executeUpdate(e, o.id, a, r, i) ?? o;
543
543
  }
544
- return Q()(() => this.executeInsert(e, t, r, i));
544
+ return M((n) => this.executeInsert(e, t, r, i, n));
545
545
  }
546
- async executeMariadbUpsert(e, t, r, i, a) {
547
- let o = this.sql, s = T(t, e), c = Object.keys(s).filter((e) => s[e] !== void 0), l = r.update === void 0 ? c.filter((e) => e !== "id" && !r.conflictColumns.includes(e)) : r.update, u = l.length > 0 ? o.csv(l.map((e) => o`${o(e)} = VALUES(${o(e)})`)) : o`${o(r.conflictColumns[0])} = VALUES(${o(r.conflictColumns[0])})`, f = o`INSERT INTO ${o(this.nsT(e))} ${o.insert(s)} ON DUPLICATE KEY UPDATE ${u} RETURNING *`, p = i ? n.provideService(f, d, i) : f, m = (await this.runtime.runPromise(p))[0];
548
- if (!m) throw Error(`MysqlStore.upsert: no row returned for table '${e}'`);
549
- let h = t.id !== void 0 && t.id === m.id ? "insert" : "update";
546
+ async executeMariadbUpsert(e, t, r, i, a, o) {
547
+ let s = this.sql, c = T(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, f = u.length > 0 ? s.csv(u.map((e) => s`${s(e)} = VALUES(${s(e)})`)) : s`${s(r.conflictColumns[0])} = VALUES(${s(r.conflictColumns[0])})`, p = s`INSERT INTO ${s(this.nsT(e))} ${s.insert(c)} ON DUPLICATE KEY UPDATE ${f} RETURNING *`, m = i ? n.provideService(p, d, i) : p, h = (await this.runtime.runPromise(m))[0];
548
+ if (!h) throw Error(`MysqlStore.upsert: no row returned for table '${e}'`);
549
+ let g = t.id !== void 0 && t.id === h.id ? "insert" : "update";
550
550
  return await this.routeEvent({
551
551
  table: e,
552
- op: h,
552
+ op: g,
553
553
  old: null,
554
- new: m
555
- }, a, i), m;
554
+ new: h
555
+ }, a, i, o), h;
556
556
  }
557
- async executeInsertIgnore(e, t, r, i, a) {
558
- if (t = M(e, t), this.variant === "mariadb") {
559
- let o = this.sql, s = o`INSERT IGNORE INTO ${o(this.nsT(e))} ${o.insert(T(t, e))} RETURNING *`, c = i ? n.provideService(s, d, i) : s, l = (await this.runtime.runPromise(c))[0];
560
- if (l) return await this.routeEvent({
557
+ async executeInsertIgnore(e, t, r, i, a, o) {
558
+ if (t = j(e, t), this.variant === "mariadb") {
559
+ let s = this.sql, c = s`INSERT IGNORE INTO ${s(this.nsT(e))} ${s.insert(T(t, e))} RETURNING *`, l = i ? n.provideService(c, d, i) : c, u = (await this.runtime.runPromise(l))[0];
560
+ if (u) return await this.routeEvent({
561
561
  table: e,
562
562
  op: "insert",
563
563
  old: null,
564
- new: l
565
- }, a, i), l;
566
- let u = await this.readWarnings(i), f = u.find((e) => !de.has(e.code));
567
- if (f !== 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: [${f.code}] ${f.message}. Nothing was written and nothing conflicted — fix the cause above.`);
568
- let p = await this.findByConflict(e, t, r.conflictColumns, i);
569
- if (p) return p;
570
- let m = u[0];
571
- throw Error(`MysqlStore.insertIgnore: the insert was skipped as a conflict, but no existing row matches conflictColumns [${r.conflictColumns.join(", ")}] on '${e}'. ` + (m === void 0 ? "The warning could not be read on this connection, so the constraint that fired is unknown — it may be a second unique index, or the primary key under another name. " : `The constraint that actually fired: [${m.code}] ${m.message}. `) + "insertIgnore models ONE conflict target: name the columns of the constraint that actually collides, or handle the violation yourself.");
564
+ new: u
565
+ }, a, i, o), u;
566
+ let f = await this.readWarnings(i), p = f.find((e) => !pe.has(e.code));
567
+ if (p !== 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: [${p.code}] ${p.message}. Nothing was written and nothing conflicted — fix the cause above.`);
568
+ let m = await this.findByConflict(e, t, r.conflictColumns, i);
569
+ if (m) return m;
570
+ let h = f[0];
571
+ throw Error(`MysqlStore.insertIgnore: the insert was skipped as a conflict, but no existing row matches conflictColumns [${r.conflictColumns.join(", ")}] on '${e}'. ` + (h === void 0 ? "The warning could not be read on this connection, so the constraint that fired is unknown — it may be a second unique index, or the primary key under another name. " : `The constraint that actually fired: [${h.code}] ${h.message}. `) + "insertIgnore models ONE conflict target: name the columns of the constraint that actually collides, or handle the violation yourself.");
572
572
  }
573
- return await this.findByConflict(e, t, r.conflictColumns, i) || Q()(() => this.executeInsert(e, t, i, a));
573
+ return await this.findByConflict(e, t, r.conflictColumns, i) || M((n) => this.executeInsert(e, t, i, a, n));
574
574
  }
575
575
  async findUndecodableCdcTables(e) {
576
576
  if (this.variant !== "mariadb") return [];
577
577
  try {
578
- let t = (await this.runtime.runPromise(this.sql.unsafe(z))).map((e) => String(e.tableName ?? e.TABLE_NAME ?? "")).filter((e) => e !== "");
578
+ let t = (await this.runtime.runPromise(this.sql.unsafe(B))).map((e) => String(e.tableName ?? e.TABLE_NAME ?? "")).filter((e) => e !== "");
579
579
  return e === void 0 ? t : t.filter((t) => e.includes(t));
580
580
  } catch (e) {
581
581
  return this.log.debug(`cdc: could not probe for undecodable tables — ${e?.message ?? String(e)}`), [];
@@ -606,7 +606,7 @@ var P = (n) => e.layerConfig({
606
606
  return this.runtime.runPromise(n);
607
607
  }
608
608
  async runWithEager(e, t) {
609
- if (!E(e)) return this.executeQuery(e, t);
609
+ if (!D(e)) return this.executeQuery(e, t);
610
610
  let r = this.variant === "mariadb" ? "mariadb" : "mysql", i = this.namespace === null ? y(e, this.sql, r) : null;
611
611
  if (i !== null) try {
612
612
  let e = t ? n.provideService(i.fragment, d, t) : i.fragment, r = await this.runtime.runPromise(e);
@@ -615,31 +615,40 @@ var P = (n) => e.layerConfig({
615
615
  if (e instanceof p) throw e;
616
616
  this.log.warn(`${this.variant} JSON-agg eager-load failed; falling back to walker`, { err: e });
617
617
  }
618
- return h(await this.executeQuery(e, t), e.eager, e.sourceTable ?? re(e.table), (e) => this.executeQuery(e, t));
618
+ return h(await this.executeQuery(e, t), e.eager, e.sourceTable ?? k(e.table), (e) => this.executeQuery(e, t));
619
619
  }
620
620
  getInternalRunWithEager() {
621
621
  return this.runWithEager.bind(this);
622
622
  }
623
+ async localWrite(e, t) {
624
+ if (this.changeStrategy !== "cdc") return M(t);
625
+ v(e);
626
+ try {
627
+ return await M(t);
628
+ } finally {
629
+ E(e);
630
+ }
631
+ }
623
632
  insert(e, t) {
624
- return Q()(() => this.executeInsert(e, t, null, null));
633
+ return this.localWrite(e, (n) => this.executeInsert(e, t, null, null, n));
625
634
  }
626
635
  insertMany(e, t) {
627
- return Q()(() => this.executeInsertMany(e, t, null, null));
636
+ return this.localWrite(e, (n) => this.executeInsertMany(e, t, null, null, n));
628
637
  }
629
638
  patchJson(e, t, n, r) {
630
- return Q()(() => this.executePatchJson(e, t, n, r, null, null));
639
+ return this.localWrite(e, (i) => this.executePatchJson(e, t, n, r, null, null, i));
631
640
  }
632
641
  upsert(e, t, n) {
633
- return Q()(() => this.executeUpsert(e, t, n, null, null));
642
+ return this.localWrite(e, (r) => this.executeUpsert(e, t, n, null, null, r));
634
643
  }
635
644
  insertIgnore(e, t, n) {
636
- return Q()(() => this.executeInsertIgnore(e, t, n, null, null));
645
+ return this.localWrite(e, (r) => this.executeInsertIgnore(e, t, n, null, null, r));
637
646
  }
638
647
  update(e, t, n) {
639
- return Q()(() => this.executeUpdate(e, t, n, null, null));
648
+ return this.localWrite(e, (r) => this.executeUpdate(e, t, n, null, null, r));
640
649
  }
641
650
  delete(e, t) {
642
- return Q()(() => this.executeDelete(e, t, null, null));
651
+ return this.localWrite(e, (n) => this.executeDelete(e, t, null, null, n));
643
652
  }
644
653
  async updateMany(e, t, r) {
645
654
  if (this.supportsUpdateReturning) {
@@ -653,7 +662,7 @@ var P = (n) => e.layerConfig({
653
662
  return o.length;
654
663
  }
655
664
  let i = this.sql, o = b(r.where, i, this.namespace);
656
- this.inflightTxns++;
665
+ this.changeStrategy === "cdc" && v(e), this.inflightTxns++;
657
666
  try {
658
667
  let r = n.suspend(() => this.sql.withTransaction(n.flatMap(n.serviceOption(d), (r) => {
659
668
  if (a.isNone(r)) return n.fail(/* @__PURE__ */ Error("MysqlStore.updateMany: TransactionConnection missing."));
@@ -677,7 +686,7 @@ var P = (n) => e.layerConfig({
677
686
  }, null, null);
678
687
  return f.length;
679
688
  } finally {
680
- this.inflightTxns--;
689
+ this.inflightTxns--, this.changeStrategy === "cdc" && E(e);
681
690
  }
682
691
  }
683
692
  async deleteMany(e, t) {
@@ -692,7 +701,7 @@ var P = (n) => e.layerConfig({
692
701
  }, null, null);
693
702
  return n.length;
694
703
  }
695
- this.inflightTxns++;
704
+ this.changeStrategy === "cdc" && v(e), this.inflightTxns++;
696
705
  try {
697
706
  let t = n.suspend(() => this.sql.withTransaction(n.flatMap(n.serviceOption(d), (t) => {
698
707
  if (a.isNone(t)) return n.fail(/* @__PURE__ */ Error("MysqlStore.deleteMany: TransactionConnection missing."));
@@ -712,17 +721,17 @@ var P = (n) => e.layerConfig({
712
721
  }, null, null);
713
722
  return u.length;
714
723
  } finally {
715
- this.inflightTxns--;
724
+ this.inflightTxns--, this.changeStrategy === "cdc" && E(e);
716
725
  }
717
726
  }
718
727
  emitChange(e) {
719
- D(e.table) && (this.changeStrategy === "cdc" && !this.cdcGate.admit(e) || this.emitter.emit("change", e));
728
+ O(e.table) && (this.changeStrategy === "cdc" && !this.cdcGate.admit(e) || this.emitter.emit("change", e));
720
729
  }
721
730
  async startCdcConsumer(e) {
722
731
  if (this.cdcHandle) return;
723
732
  await this.assertBinlogConfig(), this.cdcReplicaId = e.replicaId;
724
733
  let t = await this.readCdcOffset(e.replicaId) ?? await this.resolveBinlogEnd(), n = await this.findUndecodableCdcTables(e.includeTables);
725
- for (let e of n) this.log.error(B(e));
734
+ for (let e of n) this.log.error(V(e));
726
735
  this.cdcHandle = await q({
727
736
  connection: e.connection,
728
737
  serverId: e.serverId,
@@ -840,26 +849,26 @@ var P = (n) => e.layerConfig({
840
849
  }
841
850
  async transactional(e) {
842
851
  this.inflightTxns++;
843
- let t = Q(), r = 0, i = n.suspend(() => {
844
- let i = ++r;
845
- return this.sql.withTransaction(n.flatMap(n.serviceOption(d), (r) => {
846
- if (a.isNone(r)) return n.fail(/* @__PURE__ */ Error("MysqlStore.transactional: TransactionConnection missing."));
847
- let o = new pe(this, r.value);
852
+ let t = C(), r = me(), i = 0, o = n.suspend(() => {
853
+ let o = ++i;
854
+ return this.sql.withTransaction(n.flatMap(n.serviceOption(d), (i) => {
855
+ if (a.isNone(i)) return n.fail(/* @__PURE__ */ Error("MysqlStore.transactional: TransactionConnection missing."));
856
+ let s = new ge(this, i.value, t);
848
857
  return n.tryPromise({
849
- try: () => t(() => e(o)).then((e) => ({
858
+ try: () => r(() => e(s)).then((e) => ({
850
859
  result: e,
851
- view: o,
852
- attempt: i
860
+ view: s,
861
+ attempt: o
853
862
  })),
854
863
  catch: (e) => e
855
864
  });
856
865
  }));
857
- }), o = s.exponential("10 millis").pipe(s.compose(s.recurs(3)), s.whileInput(J)), c = i.pipe(n.retry(o), n.withSpan("store.transactional", { attributes: {
866
+ }), c = s.exponential("10 millis").pipe(s.compose(s.recurs(3)), s.whileInput(J)), l = o.pipe(n.retry(c), n.withSpan("store.transactional", { attributes: {
858
867
  "db.system": this.variant,
859
868
  "db.operation": "transaction"
860
869
  } }));
861
870
  try {
862
- let e = j(await this.runtime.runPromiseExit(c));
871
+ let e = oe(await this.runtime.runPromiseExit(l));
863
872
  return e.view.commitEvents(), e.result;
864
873
  } finally {
865
874
  this.inflightTxns--;
@@ -874,12 +883,14 @@ var P = (n) => e.layerConfig({
874
883
  return this.changeStrategy === "cdc" ? "fleet" : "local";
875
884
  }
876
885
  injectExternalChange(e) {
877
- if (this.changeStrategy === "cdc" && !this.cdcGate.admit(e) || !D(e.table)) return;
878
- let t = (e.op === "delete" ? e.old : e.new)?.id, n = t == null ? void 0 : v(_(e.table, e.op, t));
879
- this.emitter.emit("change", {
880
- ...n,
881
- ...e,
882
- origin: "injected"
886
+ if (this.changeStrategy === "cdc" && !this.cdcGate.admit(e) || !O(e.table)) return;
887
+ let t = (e.op === "delete" ? e.old : e.new)?.id;
888
+ A(e.table, e.op, t, (t) => {
889
+ this.emitter.emit("change", {
890
+ ...t,
891
+ ...e,
892
+ origin: "injected"
893
+ });
883
894
  });
884
895
  }
885
896
  run(e) {
@@ -903,31 +914,32 @@ var P = (n) => e.layerConfig({
903
914
  async ping() {
904
915
  await this.runtime.runPromise(this.sql`SELECT 1`);
905
916
  }
906
- }, pe = class {
917
+ }, ge = class {
907
918
  parent;
908
919
  txn;
920
+ attr;
909
921
  events = [];
910
922
  committed = !1;
911
- constructor(e, t) {
912
- this.parent = e, this.txn = t;
923
+ constructor(e, t, n = void 0) {
924
+ this.parent = e, this.txn = t, this.attr = n;
913
925
  }
914
926
  query(e) {
915
927
  return this.parent.getInternalRunWithEager()(e, this.txn);
916
928
  }
917
929
  insert(e, t) {
918
- return this.parent.getInternalExecuteInsert()(e, t, this.txn, this.events);
930
+ return this.parent.getInternalExecuteInsert()(e, t, this.txn, this.events, this.attr);
919
931
  }
920
932
  insertMany(e, t) {
921
- return this.parent.getInternalExecuteInsertMany()(e, t, this.txn, this.events);
933
+ return this.parent.getInternalExecuteInsertMany()(e, t, this.txn, this.events, this.attr);
922
934
  }
923
935
  patchJson(e, t, n, r) {
924
- return this.parent.getInternalExecutePatchJson()(e, t, n, r, this.txn, this.events);
936
+ return this.parent.getInternalExecutePatchJson()(e, t, n, r, this.txn, this.events, this.attr);
925
937
  }
926
938
  update(e, t, n) {
927
- return this.parent.getInternalExecuteUpdate()(e, t, n, this.txn, this.events);
939
+ return this.parent.getInternalExecuteUpdate()(e, t, n, this.txn, this.events, this.attr);
928
940
  }
929
941
  delete(e, t) {
930
- return this.parent.getInternalExecuteDelete()(e, t, this.txn, this.events);
942
+ return this.parent.getInternalExecuteDelete()(e, t, this.txn, this.events, this.attr);
931
943
  }
932
944
  async updateMany(e, t, n) {
933
945
  let r = await this.query({
@@ -954,10 +966,10 @@ var P = (n) => e.layerConfig({
954
966
  return r;
955
967
  }
956
968
  upsert(e, t, n) {
957
- return this.parent.getInternalExecuteUpsert()(e, t, n, this.txn, this.events);
969
+ return this.parent.getInternalExecuteUpsert()(e, t, n, this.txn, this.events, this.attr);
958
970
  }
959
971
  insertIgnore(e, t, n) {
960
- return this.parent.getInternalExecuteInsertIgnore()(e, t, n, this.txn, this.events);
972
+ return this.parent.getInternalExecuteInsertIgnore()(e, t, n, this.txn, this.events, this.attr);
961
973
  }
962
974
  transactional(e) {
963
975
  return Promise.reject(/* @__PURE__ */ Error("MysqlStore.transactional: nested transactions are not supported."));
@@ -975,7 +987,7 @@ var P = (n) => e.layerConfig({
975
987
  this.events.length = 0;
976
988
  }
977
989
  }
978
- }, $ = (e) => e.__mysqlReplicationFriend ?? null, me = () => ({
990
+ }, $ = (e) => e.__mysqlReplicationFriend ?? null, _e = () => ({
979
991
  async capturePrimaryPosition(e) {
980
992
  let t = $(e);
981
993
  if (t === null) throw Error("mysqlReplicationAdapter: primary is not a MysqlStore (missing __mysqlReplicationFriend).");
@@ -995,19 +1007,19 @@ var P = (n) => e.layerConfig({
995
1007
  compare(e, t) {
996
1008
  return "behind";
997
1009
  }
998
- }), he = {
1010
+ }), ve = {
999
1011
  id: "mysql",
1000
- makeSqlLayer: (e) => I(e),
1001
- makeStore: (e) => Z({
1012
+ makeSqlLayer: (e) => F(e),
1013
+ makeStore: (e) => Q({
1002
1014
  ...e,
1003
1015
  variant: "mysql"
1004
1016
  }),
1005
1017
  compileContains: (e, t, n) => n`${e} LIKE ${`%${t.replace(/[\\%_]/g, (e) => `\\${e}`)}%`} ESCAPE '\\'`,
1006
1018
  retryFilter: Y
1007
- }, ge = {
1019
+ }, ye = {
1008
1020
  id: "mariadb",
1009
- makeSqlLayer: (e) => I(e),
1010
- makeStore: (e) => Z({
1021
+ makeSqlLayer: (e) => F(e),
1022
+ makeStore: (e) => Q({
1011
1023
  ...e,
1012
1024
  variant: "mariadb"
1013
1025
  }),
@@ -1015,4 +1027,4 @@ var P = (n) => e.layerConfig({
1015
1027
  retryFilter: Y
1016
1028
  };
1017
1029
  //#endregion
1018
- export { f as CDC_OFFSETS_TABLE, e as MysqlClient, m as _voltroCdcOffsetsTable, F as connectionFromConfig, P as makeMysqlSqlLayer, I as makeMysqlSqlLayerFromConfig, Z as makeMysqlStore, ge as mariadbDialect, he as mysqlDialect, me as mysqlReplicationAdapter, Y as mysqlRetryFilter, q as startBinlogCdc };
1030
+ export { f as CDC_OFFSETS_TABLE, e as MysqlClient, m as _voltroCdcOffsetsTable, P as connectionFromConfig, N as makeMysqlSqlLayer, F as makeMysqlSqlLayerFromConfig, Q as makeMysqlStore, ye as mariadbDialect, ve as mysqlDialect, _e as mysqlReplicationAdapter, Y as mysqlRetryFilter, q as startBinlogCdc };