@voltro/sql-mssql 0.84.0 → 0.85.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
@@ -1,41 +1,45 @@
1
1
  import { MssqlClient as e } from "@effect/sql-mssql";
2
2
  import { TYPES as t } from "tedious";
3
3
  import { Config as n, Duration as r, Effect as i, Layer as a, ManagedRuntime as o, Option as s, Redacted as c } from "effect";
4
- import { CDC_OFFSETS_TABLE as l, DEFAULT_ACQUIRE_TIMEOUT_MS as u, EagerCardinalityError as d, MSSQL_TRANSIENT_NUMBERS as f, _voltroMssqlCdcOffsetsTable as p, attachEagerLoads as m, attributionFields as h, bulkInsertLimitsFor as g, causeBranches as _, chunkRowsForInsert as v, compileEagerJson as y, compileJsonPatch as b, compilePredicate as x, compileRawFragment as S, compileSelect as ee, decodeRowsFromSchema as C, encodeRowForSchema as w, externalChangeEvent as T, hasEagerLoads as te, isTableReactive as E, jsonPatchAssignments as ne, makeEagerFallbackReporter as re, makeTransactionAbortTracker as ie, observeDbOp as D, qualifyTable as ae, quoteIdent as oe, raiseChangeListenerCeiling as se, recordsTable as O, requireTable as ce, rowKeyColumns as k, runSavepoint as le, runStoreTransaction as ue, runWriteRecorders as de, stampGeneratedId as A, stampGeneratedIds as fe, upsertUpdatePatch as j, upsertUpdateValues as M, withCapturedAttribution as pe } from "@voltro/database";
5
- import { EventEmitter as me } from "node:events";
6
- import { SqlError as he } from "@effect/sql";
7
- import { createLogger as N } from "@voltro/logger";
8
- import { SqlClient as P, TransactionConnection as F } from "@effect/sql/SqlClient";
4
+ import { resolveParameter as l } from "tedious/lib/data-type";
5
+ import { CDC_OFFSETS_TABLE as u, DEFAULT_ACQUIRE_TIMEOUT_MS as d, EagerCardinalityError as f, MSSQL_TRANSIENT_NUMBERS as p, SHARED_TRANSACTION_SERVICE as m, _voltroMssqlCdcOffsetsTable as h, attachEagerLoads as g, attributionFields as _, bulkInsertLimitsFor as v, causeBranches as y, chunkRowsForInsert as b, compileEagerJson as x, compileJsonPatch as S, compilePredicate as C, compileRawFragment as w, compileSelect as T, decodeRowsFromSchema as E, encodeRowForSchema as D, externalChangeEvent as ee, hasEagerLoads as te, isTableReactive as O, jsonPatchAssignments as ne, makeEagerFallbackReporter as re, makeTransactionAbortTracker as ie, observeDbOp as k, onTransaction as ae, qualifyTable as oe, quoteIdent as se, raiseChangeListenerCeiling as ce, recordsTable as A, requireTable as le, rowKeyColumns as j, runSavepoint as ue, runStoreTransaction as de, runWriteRecorders as fe, sqlError as pe, stampGeneratedId as M, stampGeneratedIds as me, upsertUpdatePatch as N, upsertUpdateValues as P, withCapturedAttribution as he } from "@voltro/database";
6
+ import { EventEmitter as ge } from "node:events";
7
+ import { createLogger as F } from "@voltro/logger";
8
+ import { SqlClient as I } from "effect/sql/SqlClient";
9
9
  //#region src/numberParameter.ts
10
- var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.isSafeInteger(e) ? e >= -2147483648 && e <= 2147483647 ? t.Int : t.BigInt : t.Float, ge = {
10
+ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.isSafeInteger(e) ? e >= -2147483648 && e <= 2147483647 ? t.Int : t.BigInt : t.Float, _e = {
11
11
  ...t.Int,
12
- declaration: (e) => I(e.value).declaration(e),
13
- generateTypeInfo: (e, t) => I(e.value).generateTypeInfo(e, t),
14
- generateParameterLength: (e, t) => I(e.value).generateParameterLength(e, t),
15
- generateParameterData: (e, t) => I(e.value).generateParameterData(e, t),
12
+ declaration: (e) => L(e.value).declaration(e),
13
+ resolve: (e, t, n) => l({
14
+ ...e,
15
+ type: L(e.value)
16
+ }, t, n).data,
17
+ writeTypeInfo: (e, t, n) => L(t.value).writeTypeInfo(e, t, n),
18
+ writeValue: (e, t, n) => L(t.value).writeValue(e, t, n),
16
19
  validate: (e, t, n) => {
17
20
  if (typeof e == "number" && !Number.isFinite(e)) throw TypeError("SQL Server numeric parameters must be finite.");
18
- return I(e).validate(e, t, n);
21
+ return L(e).validate(e, t, n);
19
22
  }
20
- }, _e = {
23
+ }, ve = {
21
24
  ...t.VarBinary,
22
25
  resolveLength: (e) => Math.max(1, t.VarBinary.resolveLength(e)),
23
26
  validate: (e, n, r) => t.VarBinary.validate(e instanceof Uint8Array && !Buffer.isBuffer(e) ? Buffer.from(e.buffer, e.byteOffset, e.byteLength) : e, n, r)
24
- }, ve = {
27
+ }, ye = {
25
28
  ...e.defaultParameterTypes,
26
29
  null: t.NVarChar,
27
30
  Date: t.DateTime2,
28
31
  string: t.NVarChar,
29
- number: ge,
30
- Uint8Array: _e
31
- }, ye = (e) => {
32
- let t = e.acquireTimeoutMs ?? u;
32
+ number: _e,
33
+ Uint8Array: ve
34
+ }, be = (e) => {
35
+ let t = e.acquireTimeoutMs ?? d;
33
36
  return t > 0 ? t : void 0;
34
- }, L = (t) => {
35
- let i = ye(t);
37
+ }, R = (t) => {
38
+ let i = be(t);
36
39
  return e.layerConfig({
40
+ transactionService: n.succeed(m),
37
41
  server: n.succeed(t.server),
38
- parameterTypes: n.succeed(ve),
42
+ parameterTypes: n.succeed(ye),
39
43
  ...i === void 0 ? {} : { connectTimeout: n.succeed(r.millis(i)) },
40
44
  ...t.port === void 0 ? {} : { port: n.succeed(t.port) },
41
45
  ...t.database === void 0 ? {} : { database: n.succeed(t.database) },
@@ -45,7 +49,7 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
45
49
  ...t.trustServer === void 0 ? {} : { trustServer: n.succeed(t.trustServer) },
46
50
  ...t.maxConnections === void 0 ? {} : { maxConnections: n.succeed(t.maxConnections) }
47
51
  });
48
- }, be = (e) => {
52
+ }, xe = (e) => {
49
53
  let t = e.get("sslmode");
50
54
  if (t !== null) {
51
55
  if (t === "require") return !0;
@@ -60,7 +64,7 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
60
64
  throw Error(`DB_URL '?${t}=${n}' is not supported by the mssql dialect — use 'true'/'1' or 'false'/'0'.`);
61
65
  }
62
66
  }
63
- }, R = (e) => {
67
+ }, z = (e) => {
64
68
  let t = e.acquireTimeoutMs === void 0 ? {} : { acquireTimeoutMs: e.acquireTimeoutMs }, n = (e) => e === void 0 ? {} : {
65
69
  encrypt: e,
66
70
  ...e ? { trustServer: !0 } : {}
@@ -73,7 +77,7 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
73
77
  username: decodeURIComponent(r.username || "sa"),
74
78
  password: decodeURIComponent(r.password || ""),
75
79
  database: r.pathname.replace(/^\//, "") || "master",
76
- ...n(e.ssl ?? be(r.searchParams)),
80
+ ...n(e.ssl ?? xe(r.searchParams)),
77
81
  ...e.maxConnections === void 0 ? {} : { maxConnections: e.maxConnections },
78
82
  ...t
79
83
  };
@@ -88,21 +92,21 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
88
92
  ...e.maxConnections === void 0 ? {} : { maxConnections: e.maxConnections },
89
93
  ...t
90
94
  };
91
- }, z = (e) => L(R(e)), B = (e, t) => i.gen(function* () {
95
+ }, B = (e) => R(z(e)), V = (e, t) => i.gen(function* () {
92
96
  let n = yield* e`
93
97
  SELECT name, system_type_id FROM sys.columns
94
98
  WHERE object_id = OBJECT_ID(${e`${e(t)}`.compile()[0]}, 'U')
95
99
  ORDER BY column_id
96
100
  `.withoutTransform;
97
- return n.length === 0 ? yield* new he.SqlError({ message: `Cannot inspect result columns for ${t}` }) : n;
98
- }), V = (e, t, n) => e.join(", ", !1)(t.map((t) => {
101
+ return n.length === 0 ? yield* pe(`Cannot inspect result columns for ${t}`) : n;
102
+ }), H = (e, t, n) => e.join(", ", !1)(t.map((t) => {
99
103
  let r = e.literal(`[${t.name.replaceAll("]", "]]")}]`), i = n ? e`${e(n)}.${r}` : r;
100
104
  return t.system_type_id === 106 || t.system_type_id === 108 ? e`CONVERT(varchar(80), ${i}) AS ${r}` : i;
101
- })), H = (e, t, n, r = !1) => i.uninterruptible(i.gen(function* () {
102
- let i = e.literal("[#voltro_write_output]"), a = yield* B(e, t), o = e.join(", ", !1)(a.map((t) => {
105
+ })), U = (e, t, n, r = !1) => i.uninterruptible(i.gen(function* () {
106
+ let i = e.literal("[#voltro_write_output]"), a = yield* V(e, t), o = e.join(", ", !1)(a.map((t) => {
103
107
  let n = e.literal(`[${t.name.replaceAll("]", "]]")}]`);
104
108
  return t.system_type_id === 189 ? e`CONVERT(binary(8), ${n}) AS ${n}` : n;
105
- })), s = V(e, a);
109
+ })), s = H(e, a);
106
110
  return yield* e`
107
111
  SELECT TOP (0) ${r ? e.literal("CAST(NULL AS nvarchar(10)) AS [__action],") : e.literal("")} source.* INTO ${i}
108
112
  FROM (SELECT ${o} FROM ${e(t)} UNION ALL SELECT ${o} FROM ${e(t)}) AS source;
@@ -110,7 +114,7 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
110
114
  SELECT ${r ? e.literal("[__action],") : e.literal("")}${s} FROM ${i};
111
115
  DROP TABLE ${i};
112
116
  `;
113
- })), xe = f, U = (e) => {
117
+ })), Se = p, W = (e) => {
114
118
  let t = e;
115
119
  for (let e = 0; e < 5 && typeof t == "object" && t; e++) {
116
120
  let e = t.number;
@@ -119,18 +123,18 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
119
123
  if (typeof n == "string") return n;
120
124
  t = t.cause;
121
125
  }
122
- }, W = (e) => _(e).some((e) => {
123
- let t = U(e);
124
- return t !== void 0 && xe.has(t);
125
- }), Se = /* @__PURE__ */ new Set(["2601", "2627"]), G = (e) => _(e).some((e) => {
126
- let t = U(e);
126
+ }, G = (e) => y(e).some((e) => {
127
+ let t = W(e);
127
128
  return t !== void 0 && Se.has(t);
128
- }), K = (e) => W(e) ? "retry" : "noRetry", Ce = {
129
+ }), Ce = /* @__PURE__ */ new Set(["2601", "2627"]), K = (e) => y(e).some((e) => {
130
+ let t = W(e);
131
+ return t !== void 0 && Ce.has(t);
132
+ }), q = (e) => G(e) ? "retry" : "noRetry", we = {
129
133
  I: "insert",
130
134
  U: "update",
131
135
  D: "delete"
132
- }, q = (e, t) => e(i.gen(function* () {
133
- let e = yield* P;
136
+ }, J = (e, t) => e(i.gen(function* () {
137
+ let e = yield* I;
134
138
  if (((yield* e`
135
139
  SELECT COUNT(*) AS ${e("on")}
136
140
  FROM sys.change_tracking_databases
@@ -144,18 +148,18 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
144
148
  }
145
149
  yield* e.unsafe(`IF NOT EXISTS (
146
150
  SELECT 1 FROM sys.change_tracking_tables
147
- WHERE object_id = OBJECT_ID(${J(r)})
151
+ WHERE object_id = OBJECT_ID(${Y(r)})
148
152
  )
149
- ALTER TABLE ${Y(r)} ENABLE CHANGE_TRACKING WITH (TRACK_COLUMNS_UPDATED = OFF)`);
153
+ ALTER TABLE ${X(r)} ENABLE CHANGE_TRACKING WITH (TRACK_COLUMNS_UPDATED = OFF)`);
150
154
  }
151
155
  return n;
152
- })), J = (e) => `'${e.replace(/'/g, "''")}'`, Y = (e) => `[${e.replace(/\]/g, "]]")}]`, X = async (e) => {
153
- let t = N({ scope: "voltro:mssql:cdc" }), n = e.pollIntervalMs ?? 500, r = await q(e.run, e.tables), a = /* @__PURE__ */ new Set(), o = async () => (await e.run(i.gen(function* () {
154
- return yield* (yield* P)`SELECT CONVERT(VARCHAR(40), CHANGE_TRACKING_CURRENT_VERSION()) AS v`;
156
+ })), Y = (e) => `'${e.replace(/'/g, "''")}'`, X = (e) => `[${e.replace(/\]/g, "]]")}]`, Z = async (e) => {
157
+ let t = F({ scope: "voltro:mssql:cdc" }), n = e.pollIntervalMs ?? 500, r = await J(e.run, e.tables), a = /* @__PURE__ */ new Set(), o = async () => (await e.run(i.gen(function* () {
158
+ return yield* (yield* I)`SELECT CONVERT(VARCHAR(40), CHANGE_TRACKING_CURRENT_VERSION()) AS v`;
155
159
  })))[0]?.v ?? "0", s = e.startVersion ?? await o(), c = !1, l = null, u = !1, d = (e, t) => BigInt(e) > BigInt(t), f = async (n, r) => {
156
160
  let c = await e.run(i.gen(function* () {
157
- let e = yield* P, t = e.unsafe(Y(n)), i = (yield* e`
158
- SELECT CONVERT(VARCHAR(40), CHANGE_TRACKING_MIN_VALID_VERSION(OBJECT_ID(${e.unsafe(J(n))}))) AS floor`)[0]?.floor, o = r;
161
+ let e = yield* I, t = e.unsafe(X(n)), i = (yield* e`
162
+ SELECT CONVERT(VARCHAR(40), CHANGE_TRACKING_MIN_VALID_VERSION(OBJECT_ID(${e.unsafe(Y(n))}))) AS floor`)[0]?.floor, o = r;
159
163
  if (i != null && BigInt(r) < BigInt(i)) {
160
164
  if (!a.has(n)) return {
161
165
  resync: !0,
@@ -166,7 +170,7 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
166
170
  return {
167
171
  resync: !1,
168
172
  rows: yield* e`
169
- SELECT ct.SYS_CHANGE_OPERATION AS __ct_op, ct.id AS __ct_id, ${V(e, yield* B(e, n), "t")}
173
+ SELECT ct.SYS_CHANGE_OPERATION AS __ct_op, ct.id AS __ct_id, ${H(e, yield* V(e, n), "t")}
170
174
  FROM CHANGETABLE(CHANGES ${t}, ${BigInt(o)}) AS ct
171
175
  LEFT JOIN ${t} AS t ON t.id = ct.id
172
176
  ORDER BY ct.SYS_CHANGE_VERSION`.unprepared
@@ -177,7 +181,7 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
177
181
  return;
178
182
  }
179
183
  for (let t of c.rows) {
180
- let r = Ce[t.__ct_op];
184
+ let r = we[t.__ct_op];
181
185
  if (!r) continue;
182
186
  let { __ct_op: i, __ct_id: a, ...o } = t;
183
187
  if (r === "delete") e.onChange({
@@ -188,7 +192,7 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
188
192
  netChange: !0
189
193
  });
190
194
  else {
191
- let t = C([o], n, "mssql")[0];
195
+ let t = E([o], n, "mssql")[0];
192
196
  e.onChange({
193
197
  table: n,
194
198
  op: r,
@@ -204,7 +208,7 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
204
208
  try {
205
209
  if (r.length > 0) {
206
210
  let t = r;
207
- r = await q(e.run, t);
211
+ r = await J(e.run, t);
208
212
  for (let e of t) r.includes(e) || a.add(e);
209
213
  }
210
214
  let t = await o();
@@ -235,26 +239,26 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
235
239
  },
236
240
  currentVersion: () => s
237
241
  };
238
- }, Z = N({ scope: "voltro:mssql" }), Q = async (e) => {
242
+ }, Q = F({ scope: "voltro:mssql" }), $ = async (e) => {
239
243
  let t = e.changeStrategy ?? "inline", n = t;
240
- t === "cdc" && !e.cdcConfig && (Z.warn("changeStrategy='cdc' requires cdcConfig (replicaId + includeTables); falling back to 'inline'."), n = "inline");
241
- let r = e.tracerLayer ? a.mergeAll(e.sqlLayer, e.tracerLayer) : e.sqlLayer, i = o.make(r), s = new we(await i.runPromise(P), i, n);
244
+ t === "cdc" && !e.cdcConfig && (Q.warn("changeStrategy='cdc' requires cdcConfig (replicaId + includeTables); falling back to 'inline'."), n = "inline");
245
+ let r = e.tracerLayer ? a.mergeAll(e.sqlLayer, e.tracerLayer) : e.sqlLayer, i = o.make(r), s = new Te(await i.runPromise(I), i, n);
242
246
  return n === "cdc" && e.cdcConfig && await s.startCdcConsumer(e.cdcConfig), s;
243
- }, we = class e {
247
+ }, Te = class e {
244
248
  sql;
245
249
  runtime;
246
250
  changeStrategy;
247
251
  namespace;
248
252
  emitter;
249
253
  inflightTxns = 0;
250
- reportEagerFallback = re(Z);
254
+ reportEagerFallback = re(Q);
251
255
  cdcHandle = null;
252
256
  cdcCheckpointTimer = null;
253
257
  cdcPendingVersion = null;
254
258
  cdcReplicaId = "";
255
259
  cdcStreamName = "default";
256
260
  constructor(e, t, n = "inline", r = null, i) {
257
- this.sql = e, this.runtime = t, this.changeStrategy = n, this.namespace = r, this.emitter = i ?? new me(), se(this.emitter);
261
+ this.sql = e, this.runtime = t, this.changeStrategy = n, this.namespace = r, this.emitter = i ?? new ge(), ce(this.emitter);
258
262
  }
259
263
  get inlineEmit() {
260
264
  return this.changeStrategy === "inline";
@@ -263,19 +267,19 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
263
267
  return t === this.namespace ? this : new e(this.sql, this.runtime, this.changeStrategy, t, this.emitter);
264
268
  }
265
269
  nsT(e) {
266
- return ae(this.namespace, e);
270
+ return oe(this.namespace, e);
267
271
  }
268
272
  __mssqlReplicationFriend = { runEffect: (e) => this.runtime.runPromise(e) };
269
273
  async executeQuery(e, t) {
270
- let n = ee(e, this.sql, this.namespace), r = t ? i.provideService(n, F, t) : n, a = await D("mssql", "select", () => this.runtime.runPromise(r));
271
- return C(a, e.table, "mssql");
274
+ let n = T(e, this.sql, this.namespace), r = t ? i.provideService(n, this.sql.transactionService, t) : n, a = await k("mssql", "select", () => this.runtime.runPromise(r));
275
+ return E(a, e.table, "mssql");
272
276
  }
273
277
  decodeWritten(e, t) {
274
- return C([t], e, "mssql")[0] ?? t;
278
+ return E([t], e, "mssql")[0] ?? t;
275
279
  }
276
280
  async executeInsert(e, t, n, r, a) {
277
- t = A(e, t);
278
- let o = this.sql, s = H(o, this.nsT(e), (n) => o`INSERT INTO ${o(this.nsT(e))} ${o.insert(w(t, e)).returning(o`INSERTED.* INTO ${n}`)}`), c = n ? i.provideService(s, F, n) : s, l = (await this.runtime.runPromise(c))[0];
281
+ t = M(e, t);
282
+ let o = this.sql, s = U(o, this.nsT(e), (n) => o`INSERT INTO ${o(this.nsT(e))} ${o.insert(D(t, e)).returning(o`INSERTED.* INTO ${n}`)}`), c = n ? i.provideService(s, this.sql.transactionService, n) : s, l = (await this.runtime.runPromise(c))[0];
279
283
  if (!l) throw Error(`MssqlStore.insert: row not returned post-insert in '${e}'`);
280
284
  let u = this.decodeWritten(e, l);
281
285
  return await this.routeEvent({
@@ -286,7 +290,7 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
286
290
  }, r, n, a), u;
287
291
  }
288
292
  async executeUpdate(e, t, n, r, a, o) {
289
- let s = this.sql, c = H(s, this.nsT(e), (r) => s`UPDATE ${s(this.nsT(e))} SET ${s.update(w(n, e)).returning(s`INSERTED.* INTO ${r}`)} WHERE ${s.and(k(t).map(([e, t]) => s`${s(e)} = ${t}`))}`), l = r ? i.provideService(c, F, r) : c, u = (await this.runtime.runPromise(l))[0];
293
+ let s = this.sql, c = U(s, this.nsT(e), (r) => s`UPDATE ${s(this.nsT(e))} SET ${s.update(D(n, e)).returning(s`INSERTED.* INTO ${r}`)} WHERE ${s.and(j(t).map(([e, t]) => s`${s(e)} = ${t}`))}`), l = r ? i.provideService(c, this.sql.transactionService, r) : c, u = (await this.runtime.runPromise(l))[0];
290
294
  if (!u) return null;
291
295
  let d = this.decodeWritten(e, u);
292
296
  return await this.routeEvent({
@@ -297,17 +301,17 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
297
301
  }, a, r, o), d;
298
302
  }
299
303
  async executeInsertMany(e, t, n, r, a) {
300
- if (t = fe(e, t), t.length === 0) return [];
301
- let o = this.sql, s = v(t, g("mssql")), c = (t) => H(o, this.nsT(e), (n) => o`INSERT INTO ${o(this.nsT(e))} ${o.insert(t.map((t) => w(t, e))).returning(o`INSERTED.* INTO ${n}`)}`), l;
304
+ if (t = me(e, t), t.length === 0) return [];
305
+ let o = this.sql, s = b(t, v("mssql")), c = (t) => U(o, this.nsT(e), (n) => o`INSERT INTO ${o(this.nsT(e))} ${o.insert(t.map((t) => D(t, e))).returning(o`INSERTED.* INTO ${n}`)}`), l;
302
306
  if (s.length === 1) {
303
- let e = c(s[0]), t = n ? i.provideService(e, F, n) : e;
307
+ let e = c(s[0]), t = n ? i.provideService(e, this.sql.transactionService, n) : e;
304
308
  l = await this.runtime.runPromise(t);
305
309
  } else if (n) {
306
310
  let e = [];
307
- for (let t of s) e.push(...await this.runtime.runPromise(i.provideService(c(t), F, n)));
311
+ for (let t of s) e.push(...await this.runtime.runPromise(i.provideService(c(t), this.sql.transactionService, n)));
308
312
  l = e;
309
313
  } else l = await this.runtime.runPromise(o.withTransaction(i.map(i.forEach(s, c, { concurrency: 1 }), (e) => e.flat())));
310
- let u = t.map((e) => e.id), d = C(l, e, "mssql"), f = new Map(d.map((e) => [e.id, e])), p = u.map((e) => f.get(e)).filter((e) => e !== void 0), m = p.length === l.length ? p : d;
314
+ let u = t.map((e) => e.id), d = E(l, e, "mssql"), f = new Map(d.map((e) => [e.id, e])), p = u.map((e) => f.get(e)).filter((e) => e !== void 0), m = p.length === l.length ? p : d;
311
315
  for (let t of m) await this.routeEvent({
312
316
  table: e,
313
317
  op: "insert",
@@ -317,7 +321,7 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
317
321
  return m;
318
322
  }
319
323
  async executePatchJson(e, t, n, r, a, o, s, c) {
320
- let l = this.sql, u = w(ne(t, n, c), e), d = l.csv([b(l, "mssql", n, r), ...Object.entries(u).map(([e, t]) => l`${l(e)} = ${t}`)]), f = H(l, this.nsT(e), (n) => l`UPDATE ${l(this.nsT(e))} SET ${d} OUTPUT INSERTED.* INTO ${n} WHERE ${l.and(k(t).map(([e, t]) => l`${l(e)} = ${t}`))}`), p = a ? i.provideService(f, F, a) : f, m = (await this.runtime.runPromise(p))[0];
324
+ let l = this.sql, u = D(ne(t, n, c), e), d = l.csv([S(l, "mssql", n, r), ...Object.entries(u).map(([e, t]) => l`${l(e)} = ${t}`)]), f = U(l, this.nsT(e), (n) => l`UPDATE ${l(this.nsT(e))} SET ${d} OUTPUT INSERTED.* INTO ${n} WHERE ${l.and(j(t).map(([e, t]) => l`${l(e)} = ${t}`))}`), p = a ? i.provideService(f, this.sql.transactionService, a) : f, m = (await this.runtime.runPromise(p))[0];
321
325
  if (!m) return null;
322
326
  let h = this.decodeWritten(e, m);
323
327
  return await this.routeEvent({
@@ -328,7 +332,7 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
328
332
  }, o, a, s), h;
329
333
  }
330
334
  async executeDelete(e, t, n, r, a) {
331
- let o = this.sql, s = H(o, this.nsT(e), (n) => o`DELETE FROM ${o(this.nsT(e))} OUTPUT DELETED.* INTO ${n} WHERE ${o.and(k(t).map(([e, t]) => o`${o(e)} = ${t}`))}`), c = n ? i.provideService(s, F, n) : s, l = (await this.runtime.runPromise(c))[0];
335
+ let o = this.sql, s = U(o, this.nsT(e), (n) => o`DELETE FROM ${o(this.nsT(e))} OUTPUT DELETED.* INTO ${n} WHERE ${o.and(j(t).map(([e, t]) => o`${o(e)} = ${t}`))}`), c = n ? i.provideService(s, this.sql.transactionService, n) : s, l = (await this.runtime.runPromise(c))[0];
332
336
  if (!l) return !1;
333
337
  let u = this.decodeWritten(e, l);
334
338
  return await this.routeEvent({
@@ -339,18 +343,18 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
339
343
  }, r, n, a), !0;
340
344
  }
341
345
  async appendInTxn(e, t, n) {
342
- let r = this.sql, a = r`INSERT INTO ${r(this.nsT(e))} ${r.insert(w(t, e))}`;
343
- await this.runtime.runPromise(n ? i.provideService(a, F, n) : a);
346
+ let r = this.sql, a = r`INSERT INTO ${r(this.nsT(e))} ${r.insert(D(t, e))}`;
347
+ await this.runtime.runPromise(n ? i.provideService(a, this.sql.transactionService, n) : a);
344
348
  }
345
349
  async maxInTxn(e, t, n, r) {
346
- let a = this.sql, o = Object.entries(n).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(r ? i.provideService(s, F, r) : s))[0]?.m;
350
+ let a = this.sql, o = Object.entries(n).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(r ? i.provideService(s, this.sql.transactionService, r) : s))[0]?.m;
347
351
  return c == null ? null : Number(c);
348
352
  }
349
353
  async routeEvent(e, t, n = null, r) {
350
354
  e = {
351
- ...h(r),
355
+ ..._(r),
352
356
  ...e
353
- }, O(e.table) && await de({
357
+ }, A(e.table) && await fe({
354
358
  append: (e, t) => this.appendInTxn(e, t, n),
355
359
  maxOf: (e, t, r) => this.maxInTxn(e, t, r, n)
356
360
  }, {
@@ -360,7 +364,7 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
360
364
  prev: e.old,
361
365
  traceId: e.traceId,
362
366
  subjectId: e.subjectId
363
- }), E(e.table) && (t === null ? this.inlineEmit && this.emitter.emit("change", e) : t.push(e));
367
+ }), O(e.table) && (t === null ? this.inlineEmit && this.emitter.emit("change", e) : t.push(e));
364
368
  }
365
369
  query(e) {
366
370
  return this.runWithEager(e, null);
@@ -369,17 +373,17 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
369
373
  return this.rawOn(e, null);
370
374
  }
371
375
  rawOn(e, t) {
372
- let n = S(e, this.sql), r = t ? i.provideService(n, F, t) : n;
373
- return D("mssql", "raw", () => this.runtime.runPromise(r));
376
+ let n = w(e, this.sql), r = t ? i.provideService(n, this.sql.transactionService, t) : n;
377
+ return k("mssql", "raw", () => this.runtime.runPromise(r));
374
378
  }
375
379
  async runWithEager(e, t) {
376
380
  if (!te(e)) return this.executeQuery(e, t);
377
- let n = this.namespace === null ? y(e, this.sql, "mssql") : null;
381
+ let n = this.namespace === null ? x(e, this.sql, "mssql") : null;
378
382
  if (n !== null) try {
379
- let e = t ? i.provideService(n.fragment, F, t) : n.fragment, r = await D("mssql", "select", () => this.runtime.runPromise(e));
383
+ let e = t ? i.provideService(n.fragment, this.sql.transactionService, t) : n.fragment, r = await k("mssql", "select", () => this.runtime.runPromise(e));
380
384
  return n.decode(r);
381
385
  } catch (t) {
382
- if (t instanceof d) throw t;
386
+ if (t instanceof f) throw t;
383
387
  this.reportEagerFallback({
384
388
  dialect: "mssql",
385
389
  table: e.table,
@@ -393,17 +397,17 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
393
397
  reason: "not-compilable"
394
398
  });
395
399
  let r = await this.executeQuery(e, t);
396
- return m(r, e.eager, e.sourceTable ?? ce(e.table), (e) => this.executeQuery(e, t));
400
+ return g(r, e.eager, e.sourceTable ?? le(e.table), (e) => this.executeQuery(e, t));
397
401
  }
398
402
  getInternalRunWithEager() {
399
403
  return this.runWithEager.bind(this);
400
404
  }
401
405
  localWrite(e, t, n) {
402
- let r = (e) => O(t) ? this.writeWithRecorders(n, e) : n(e, null, null);
403
- return D("mssql", e, () => pe(r));
406
+ let r = (e) => A(t) ? this.writeWithRecorders(n, e) : n(e, null, null);
407
+ return k("mssql", e, () => he(r));
404
408
  }
405
409
  async writeWithRecorders(e, t) {
406
- let n = [], r = this.sql, a = await this.runtime.runPromise(r.withTransaction(i.flatMap(i.serviceOption(F), (r) => s.isNone(r) ? i.fail(/* @__PURE__ */ Error("MssqlStore.write: TransactionConnection missing.")) : i.tryPromise({
410
+ let n = [], r = this.sql, a = await this.runtime.runPromise(r.withTransaction(i.flatMap(i.serviceOption(this.sql.transactionService), (r) => s.isNone(r) ? i.fail(/* @__PURE__ */ Error("MssqlStore.write: TransactionConnection missing.")) : i.tryPromise({
407
411
  try: () => e(t, r.value, n),
408
412
  catch: (e) => e
409
413
  }))));
@@ -432,8 +436,8 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
432
436
  return this.executeDeleteMany(e, t, null, null);
433
437
  }
434
438
  async executeUpdateMany(e, t, n, r, a, o) {
435
- let s = this.sql, c = x(n.where, s, this.namespace), l = H(s, this.nsT(e), (n) => s`UPDATE ${s(this.nsT(e))} SET ${s.update(w(t, e))} OUTPUT INSERTED.* INTO ${n} WHERE ${c}`), u = r ? i.provideService(l, F, r) : l, d = await D("mssql", "update", () => this.runtime.runPromise(u));
436
- for (let t of C(d, e, "mssql")) await this.routeEvent({
439
+ let s = this.sql, c = C(n.where, s, this.namespace), l = U(s, this.nsT(e), (n) => s`UPDATE ${s(this.nsT(e))} SET ${s.update(D(t, e))} OUTPUT INSERTED.* INTO ${n} WHERE ${c}`), u = r ? i.provideService(l, this.sql.transactionService, r) : l, d = await k("mssql", "update", () => this.runtime.runPromise(u));
440
+ for (let t of E(d, e, "mssql")) await this.routeEvent({
437
441
  table: e,
438
442
  op: "update",
439
443
  old: null,
@@ -442,8 +446,8 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
442
446
  return d.length;
443
447
  }
444
448
  async executeDeleteMany(e, t, n, r, a) {
445
- let o = this.sql, s = x(t.where, o, this.namespace), c = H(o, this.nsT(e), (t) => o`DELETE FROM ${o(this.nsT(e))} OUTPUT DELETED.* INTO ${t} WHERE ${s}`), l = n ? i.provideService(c, F, n) : c, u = await D("mssql", "delete", () => this.runtime.runPromise(l));
446
- for (let t of C(u, e, "mssql")) await this.routeEvent({
449
+ let o = this.sql, s = C(t.where, o, this.namespace), c = U(o, this.nsT(e), (t) => o`DELETE FROM ${o(this.nsT(e))} OUTPUT DELETED.* INTO ${t} WHERE ${s}`), l = n ? i.provideService(c, this.sql.transactionService, n) : c, u = await k("mssql", "delete", () => this.runtime.runPromise(l));
450
+ for (let t of E(u, e, "mssql")) await this.routeEvent({
447
451
  table: e,
448
452
  op: "delete",
449
453
  old: t,
@@ -461,34 +465,34 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
461
465
  return this.localWrite("upsert", e, (r, i, a) => this.executeInsertIgnore(e, t, n, i, a, r));
462
466
  }
463
467
  async executeUpsert(e, t, n, r, i, a) {
464
- if (M(n), t = A(e, t), typeof n.update != "function" && n.conflictColumns.length > 0) return this.mergeUpsert(e, t, {
468
+ if (P(n), t = M(e, t), typeof n.update != "function" && n.conflictColumns.length > 0) return this.mergeUpsert(e, t, {
465
469
  conflictColumns: n.conflictColumns,
466
470
  ...n.update === void 0 ? {} : { update: n.update },
467
471
  ...n.updateValues === void 0 ? {} : { updateValues: n.updateValues }
468
472
  }, r, i, a);
469
473
  let o = await this.findByConflict(e, t, n.conflictColumns, r);
470
- if (o) return await this.executeUpdate(e, Object.fromEntries(n.conflictColumns.map((e) => [e, o[e]])), j(t, o, n), r, i, a) ?? o;
474
+ if (o) return await this.executeUpdate(e, Object.fromEntries(n.conflictColumns.map((e) => [e, o[e]])), N(t, o, n), r, i, a) ?? o;
471
475
  try {
472
476
  return await this.executeInsert(e, t, r, i, a);
473
477
  } catch (o) {
474
- if (!G(o)) throw o;
478
+ if (!K(o)) throw o;
475
479
  let s = await this.findByConflict(e, t, n.conflictColumns, r);
476
480
  if (!s) throw o;
477
- return await this.executeUpdate(e, Object.fromEntries(n.conflictColumns.map((e) => [e, s[e]])), j(t, s, n), r, i, a) ?? s;
481
+ return await this.executeUpdate(e, Object.fromEntries(n.conflictColumns.map((e) => [e, s[e]])), N(t, s, n), r, i, a) ?? s;
478
482
  }
479
483
  }
480
484
  async mergeUpsert(e, t, n, r, a, o) {
481
- let s = this.sql, c = Object.keys(t), l = Array.isArray(n.update) ? n.update.filter((e) => c.includes(e)) : c.filter((e) => e !== "id" && !n.conflictColumns.includes(e)), u = w(t, e), d = c.map((e) => s`${u[e]}`), f = c.map((e) => s`${s(e)}`), p = n.conflictColumns.map((e) => s`tgt.${s(e)} = src.${s(e)}`), m = c.map((e) => s`${s(e)}`), h = c.map((e) => s`src.${s(e)}`), g = M(n), _ = w(g, e), v = [...l.filter((e) => !Object.hasOwn(g, e)).map((e) => s`tgt.${s(e)} = src.${s(e)}`), ...Object.entries(_).map(([e, t]) => s`tgt.${s(e)} = ${t}`)];
485
+ let s = this.sql, c = Object.keys(t), l = Array.isArray(n.update) ? n.update.filter((e) => c.includes(e)) : c.filter((e) => e !== "id" && !n.conflictColumns.includes(e)), u = D(t, e), d = c.map((e) => s`${u[e]}`), f = c.map((e) => s`${s(e)}`), p = n.conflictColumns.map((e) => s`tgt.${s(e)} = src.${s(e)}`), m = c.map((e) => s`${s(e)}`), h = c.map((e) => s`src.${s(e)}`), g = P(n), _ = D(g, e), v = [...l.filter((e) => !Object.hasOwn(g, e)).map((e) => s`tgt.${s(e)} = src.${s(e)}`), ...Object.entries(_).map(([e, t]) => s`tgt.${s(e)} = ${t}`)];
482
486
  v.length === 0 && v.push(s`tgt.${s(n.conflictColumns[0])} = src.${s(n.conflictColumns[0])}`);
483
- let y = H(s, this.nsT(e), (t) => s`
487
+ let y = U(s, this.nsT(e), (t) => s`
484
488
  MERGE ${s(this.nsT(e))} WITH (HOLDLOCK) AS tgt
485
489
  USING (VALUES (${s.csv(d)})) AS src (${s.csv(f)})
486
490
  ON ${s.and(p)}
487
491
  WHEN MATCHED THEN UPDATE SET ${s.csv(v)}
488
492
  WHEN NOT MATCHED THEN INSERT (${s.csv(m)}) VALUES (${s.csv(h)})
489
- OUTPUT $action AS ${s("__action")}, INSERTED.* INTO ${t};`, !0), b = r ? i.provideService(y, F, r) : y, x = (await this.runtime.runPromise(b))[0];
493
+ OUTPUT $action AS ${s("__action")}, INSERTED.* INTO ${t};`, !0), b = r ? i.provideService(y, this.sql.transactionService, r) : y, x = (await this.runtime.runPromise(b))[0];
490
494
  if (!x) throw Error(`MssqlStore.upsert: MERGE returned no row for '${e}'`);
491
- let S = x.__action, { __action: ee, ...C } = x, T = this.decodeWritten(e, C);
495
+ let S = x.__action, { __action: C, ...w } = x, T = this.decodeWritten(e, w);
492
496
  return await this.routeEvent({
493
497
  table: e,
494
498
  op: S === "INSERT" ? "insert" : "update",
@@ -497,7 +501,7 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
497
501
  }, a, r, o), T;
498
502
  }
499
503
  async executeInsertIgnore(e, t, n, r, i, a) {
500
- t = A(e, t);
504
+ t = M(e, t);
501
505
  let o = await this.findByConflict(e, t, n.conflictColumns, r);
502
506
  if (o) return {
503
507
  row: o,
@@ -509,7 +513,7 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
509
513
  outcome: "inserted"
510
514
  };
511
515
  } catch (i) {
512
- if (!G(i)) throw i;
516
+ if (!K(i)) throw i;
513
517
  let a = await this.findByConflict(e, t, n.conflictColumns, r);
514
518
  if (!a) throw i;
515
519
  return {
@@ -520,7 +524,7 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
520
524
  }
521
525
  async findByConflict(e, t, n, r) {
522
526
  if (n.length === 0) return;
523
- let a = this.sql, o = n.map((e) => a`${a(e)} = ${t[e]}`), s = a`SELECT TOP 1 * FROM ${a(this.nsT(e))} WHERE ${a.and(o)}`, c = r ? i.provideService(s, F, r) : s, l = (await this.runtime.runPromise(c))[0];
527
+ let a = this.sql, o = n.map((e) => a`${a(e)} = ${t[e]}`), s = a`SELECT TOP 1 * FROM ${a(this.nsT(e))} WHERE ${a.and(o)}`, c = r ? i.provideService(s, this.sql.transactionService, r) : s, l = (await this.runtime.runPromise(c))[0];
524
528
  return l ? this.decodeWritten(e, l) : void 0;
525
529
  }
526
530
  emitChange(e) {
@@ -530,9 +534,9 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
530
534
  if (this.cdcHandle) return;
531
535
  this.cdcReplicaId = e.replicaId;
532
536
  let t = e.includeTables ?? [];
533
- t.length === 0 && Z.warn("cdc: no reactive tables to tail; Change Tracking reader idle. Set includeTables to enable.");
537
+ t.length === 0 && Q.warn("cdc: no reactive tables to tail; Change Tracking reader idle. Set includeTables to enable.");
534
538
  let n = await this.readCdcOffset(e.replicaId);
535
- this.cdcHandle = await X({
539
+ this.cdcHandle = await Z({
536
540
  run: this.__mssqlReplicationFriend.runEffect,
537
541
  tables: t,
538
542
  startVersion: n,
@@ -540,9 +544,9 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
540
544
  onVersion: (e) => {
541
545
  this.cdcPendingVersion = e;
542
546
  },
543
- onError: (e) => Z.warn("cdc: consumer error", {}, e),
547
+ onError: (e) => Q.warn("cdc: consumer error", {}, e),
544
548
  onResync: () => {
545
- Z.warn("cdc: resynced to current CT version after retention gap — subscriptions self-heal on the next change");
549
+ Q.warn("cdc: resynced to current CT version after retention gap — subscriptions self-heal on the next change");
546
550
  }
547
551
  }), this.cdcCheckpointTimer = setInterval(() => {
548
552
  this.flushCdcOffset();
@@ -551,14 +555,14 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
551
555
  async readCdcOffset(e) {
552
556
  try {
553
557
  let t = this.sql, n = (await this.runtime.runPromise(t`
554
- SELECT TOP 1 ${t("ctVersion")} FROM ${t(l)}
558
+ SELECT TOP 1 ${t("ctVersion")} FROM ${t(u)}
555
559
  WHERE ${t("id")} = ${e}`))[0]?.ctVersion;
556
- return n ? (Z.info("cdc: resuming from persisted CT version", {
560
+ return n ? (Q.info("cdc: resuming from persisted CT version", {
557
561
  replicaId: e,
558
562
  version: n
559
563
  }), n) : null;
560
564
  } catch (t) {
561
- return Z.warn("cdc: no readable offset; starting at current CT version", { replicaId: e }, t), null;
565
+ return Q.warn("cdc: no readable offset; starting at current CT version", { replicaId: e }, t), null;
562
566
  }
563
567
  }
564
568
  async flushCdcOffset() {
@@ -567,7 +571,7 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
567
571
  this.cdcPendingVersion = null;
568
572
  try {
569
573
  let t = this.cdcReplicaId;
570
- await this.executeUpsert(l, {
574
+ await this.executeUpsert(u, {
571
575
  id: t,
572
576
  replicaId: t,
573
577
  streamName: this.cdcStreamName,
@@ -578,7 +582,7 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
578
582
  update: ["ctVersion", "updatedAt"]
579
583
  }, null, null);
580
584
  } catch (t) {
581
- this.cdcPendingVersion = e, Z.warn("cdc: checkpoint write failed", {}, t);
585
+ this.cdcPendingVersion = e, Q.warn("cdc: checkpoint write failed", {}, t);
582
586
  }
583
587
  }
584
588
  }
@@ -633,28 +637,32 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
633
637
  }
634
638
  async emptyTablesOn(e, t) {
635
639
  if (e.length === 0) return;
636
- let n = this.sql, r = (e) => this.nsT(e), a = (e, t) => n.unsafe(`ALTER TABLE ${oe(r(e), "mssql")} ${t ? "WITH CHECK CHECK" : "NOCHECK"} CONSTRAINT ALL`), o = i.acquireUseRelease(i.forEach(e, (e) => a(e, !1), { discard: !0 }), () => i.forEach(e, (e) => n`DELETE FROM ${n(r(e))}`, { discard: !0 }), () => i.orDie(i.ignore(i.forEach(e, (e) => a(e, !0), { discard: !0 })))), s = t === null ? n.withTransaction(o) : i.provideService(o, F, t);
640
+ let n = this.sql, r = (e) => this.nsT(e), a = (e, t) => n.unsafe(`ALTER TABLE ${se(r(e), "mssql")} ${t ? "WITH CHECK CHECK" : "NOCHECK"} CONSTRAINT ALL`), o = i.acquireUseRelease(i.forEach(e, (e) => a(e, !1), { discard: !0 }), () => i.forEach(e, (e) => n`DELETE FROM ${n(r(e))}`, { discard: !0 }), () => i.orDie(i.ignore(i.forEach(e, (e) => a(e, !0), { discard: !0 })))), s = t === null ? n.withTransaction(o) : i.provideService(o, this.sql.transactionService, t);
637
641
  await this.runtime.runPromise(s);
638
642
  }
639
643
  async transactional(e) {
640
644
  this.inflightTxns++;
641
645
  try {
642
- return await ue({
646
+ return await de({
643
647
  ...this.txnSpec("MssqlStore.transactional"),
644
648
  work: e,
645
- makeView: (e, t) => new Te(this, e, t)
649
+ makeView: (e, t) => new Ee(this, e, t)
646
650
  });
647
651
  } finally {
648
652
  this.inflightTxns--;
649
653
  }
650
654
  }
655
+ get transactionService() {
656
+ return this.sql.transactionService;
657
+ }
651
658
  txnSpec(e) {
652
659
  return {
653
660
  label: e,
654
661
  dialect: "mssql",
655
662
  withTransaction: (e) => this.sql.withTransaction(e),
663
+ transactionService: this.sql.transactionService,
656
664
  runPromiseExit: (e) => this.runtime.runPromiseExit(e),
657
- isRetryable: W,
665
+ isRetryable: G,
658
666
  span: {
659
667
  name: "store.transactional",
660
668
  attributes: {
@@ -673,7 +681,7 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
673
681
  return this.changeStrategy === "cdc" ? "fleet" : "local";
674
682
  }
675
683
  injectExternalChange(e) {
676
- E(e.table) && this.emitter.emit("change", T(e));
684
+ O(e.table) && this.emitter.emit("change", ee(e));
677
685
  }
678
686
  run(e) {
679
687
  return this.runtime.runPromise(e);
@@ -686,7 +694,7 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
686
694
  if (this.inflightTxns > 0) {
687
695
  let t = Date.now() + e;
688
696
  for (; this.inflightTxns > 0 && Date.now() < t;) await new Promise((e) => setTimeout(e, 25));
689
- this.inflightTxns > 0 && Z.warn("close: grace period expired with in-flight transactions", {
697
+ this.inflightTxns > 0 && Q.warn("close: grace period expired with in-flight transactions", {
690
698
  gracePeriodMs: e,
691
699
  inflight: this.inflightTxns
692
700
  });
@@ -696,27 +704,27 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
696
704
  async ping() {
697
705
  await this.runtime.runPromise(this.sql`SELECT 1`);
698
706
  }
699
- }, Te = class {
707
+ }, Ee = class {
700
708
  parent;
701
709
  txn;
702
710
  attr;
703
711
  events = [];
704
- aborts = ie((e) => W(e));
712
+ aborts = ie((e) => G(e));
705
713
  committed = !1;
706
714
  constructor(e, t, n = void 0) {
707
715
  this.parent = e, this.txn = t, this.attr = n;
708
716
  }
709
717
  savepoint(e) {
710
- return le({
718
+ return ue({
711
719
  tracker: this.aborts,
712
720
  name: `voltro_sp_${++this.savepointCounter}`,
713
721
  spelling: "mssql",
714
- exec: (e) => this.parent.run(i.provideService(P.pipe(i.flatMap((t) => t.unsafe(e))), F, this.txn))
722
+ exec: (e) => this.parent.run(i.provideService(I.pipe(i.flatMap((t) => t.unsafe(e))), this.parent.transactionService, this.txn))
715
723
  }, e);
716
724
  }
717
725
  savepointCounter = 0;
718
726
  run(e) {
719
- return this.aborts.track(() => this.parent.run(i.provideService(e, F, this.txn)));
727
+ return this.aborts.track(() => this.parent.run(ae(e, this.parent.transactionService, this.txn)));
720
728
  }
721
729
  abortedBy() {
722
730
  return this.aborts.abortedBy();
@@ -776,12 +784,12 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
776
784
  this.events.length = 0;
777
785
  }
778
786
  }
779
- }, $ = (e) => e.__mssqlReplicationFriend ?? null, Ee = (e, t) => e === t ? 0 : e < t ? -1 : 1, De = () => ({
787
+ }, De = (e) => e.__mssqlReplicationFriend ?? null, Oe = (e, t) => e === t ? 0 : e < t ? -1 : 1, ke = () => ({
780
788
  async capturePrimaryPosition(e) {
781
- let t = $(e);
789
+ let t = De(e);
782
790
  if (t === null) throw Error("mssqlReplicationAdapter: primary is not an MssqlStore (missing __mssqlReplicationFriend).");
783
791
  return t.runEffect(i.gen(function* () {
784
- return (yield* (yield* P)`
792
+ return (yield* (yield* I)`
785
793
  SELECT CONVERT(VARCHAR(40), end_of_log_lsn) AS lsn
786
794
  FROM sys.dm_hadr_database_replica_states
787
795
  WHERE database_id = DB_ID()
@@ -791,10 +799,10 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
791
799
  }));
792
800
  },
793
801
  async probeReplicaPosition(e) {
794
- let t = $(e);
802
+ let t = De(e);
795
803
  if (t === null) throw Error("mssqlReplicationAdapter: replica is not an MssqlStore.");
796
804
  return t.runEffect(i.gen(function* () {
797
- return (yield* (yield* P)`
805
+ return (yield* (yield* I)`
798
806
  SELECT CONVERT(VARCHAR(40), last_hardened_lsn) AS lsn
799
807
  FROM sys.dm_hadr_database_replica_states
800
808
  WHERE database_id = DB_ID()
@@ -803,14 +811,14 @@ var I = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
803
811
  }));
804
812
  },
805
813
  compare(e, t) {
806
- return Ee(t, e) >= 0 ? "caught-up" : "behind";
814
+ return Oe(t, e) >= 0 ? "caught-up" : "behind";
807
815
  }
808
- }), Oe = {
816
+ }), Ae = {
809
817
  id: "mssql",
810
- makeSqlLayer: (e) => z(e),
811
- makeStore: (e) => Q(e),
818
+ makeSqlLayer: (e) => B(e),
819
+ makeStore: (e) => $(e),
812
820
  compileContains: (e, t, n) => n`${e} LIKE ${`%${t.replace(/[\\%_[\]]/g, (e) => `\\${e}`)}%`} ESCAPE '\\'`,
813
- retryFilter: K
821
+ retryFilter: q
814
822
  };
815
823
  //#endregion
816
- export { l as CDC_OFFSETS_TABLE, e as MssqlClient, p as _voltroMssqlCdcOffsetsTable, R as connectionFromConfig, q as ensureChangeTracking, L as makeMssqlSqlLayer, z as makeMssqlSqlLayerFromConfig, Q as makeMssqlStore, Oe as mssqlDialect, De as mssqlReplicationAdapter, K as mssqlRetryFilter, X as startChangeTrackingCdc };
824
+ export { u as CDC_OFFSETS_TABLE, e as MssqlClient, h as _voltroMssqlCdcOffsetsTable, z as connectionFromConfig, J as ensureChangeTracking, R as makeMssqlSqlLayer, B as makeMssqlSqlLayerFromConfig, $ as makeMssqlStore, Ae as mssqlDialect, ke as mssqlReplicationAdapter, q as mssqlRetryFilter, Z as startChangeTrackingCdc };