@voltro/sql-mssql 0.83.1 → 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,35 +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 O, recordsTable as k, requireTable as se, rowKeyColumns as A, runSavepoint as ce, runStoreTransaction as le, runWriteRecorders as ue, stampGeneratedId as j, stampGeneratedIds as de, upsertUpdatePatch as M, upsertUpdateValues as N, withCapturedAttribution as fe } from "@voltro/database";
5
- import { EventEmitter as pe } from "node:events";
6
- import { createLogger as P } from "@voltro/logger";
7
- import { SqlClient as F, TransactionConnection as I } 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";
8
9
  //#region src/numberParameter.ts
9
- var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.isSafeInteger(e) ? e >= -2147483648 && e <= 2147483647 ? t.Int : t.BigInt : t.Float, me = {
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 = {
10
11
  ...t.Int,
11
12
  declaration: (e) => L(e.value).declaration(e),
12
- generateTypeInfo: (e, t) => L(e.value).generateTypeInfo(e, t),
13
- generateParameterLength: (e, t) => L(e.value).generateParameterLength(e, t),
14
- generateParameterData: (e, t) => L(e.value).generateParameterData(e, t),
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),
15
19
  validate: (e, t, n) => {
16
20
  if (typeof e == "number" && !Number.isFinite(e)) throw TypeError("SQL Server numeric parameters must be finite.");
17
21
  return L(e).validate(e, t, n);
18
22
  }
19
- }, R = {
23
+ }, ve = {
24
+ ...t.VarBinary,
25
+ resolveLength: (e) => Math.max(1, t.VarBinary.resolveLength(e)),
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)
27
+ }, ye = {
20
28
  ...e.defaultParameterTypes,
21
29
  null: t.NVarChar,
22
30
  Date: t.DateTime2,
23
31
  string: t.NVarChar,
24
- number: me
25
- }, z = (e) => {
26
- let t = e.acquireTimeoutMs ?? u;
32
+ number: _e,
33
+ Uint8Array: ve
34
+ }, be = (e) => {
35
+ let t = e.acquireTimeoutMs ?? d;
27
36
  return t > 0 ? t : void 0;
28
- }, B = (t) => {
29
- let i = z(t);
37
+ }, R = (t) => {
38
+ let i = be(t);
30
39
  return e.layerConfig({
40
+ transactionService: n.succeed(m),
31
41
  server: n.succeed(t.server),
32
- parameterTypes: n.succeed(R),
42
+ parameterTypes: n.succeed(ye),
33
43
  ...i === void 0 ? {} : { connectTimeout: n.succeed(r.millis(i)) },
34
44
  ...t.port === void 0 ? {} : { port: n.succeed(t.port) },
35
45
  ...t.database === void 0 ? {} : { database: n.succeed(t.database) },
@@ -39,7 +49,7 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
39
49
  ...t.trustServer === void 0 ? {} : { trustServer: n.succeed(t.trustServer) },
40
50
  ...t.maxConnections === void 0 ? {} : { maxConnections: n.succeed(t.maxConnections) }
41
51
  });
42
- }, he = (e) => {
52
+ }, xe = (e) => {
43
53
  let t = e.get("sslmode");
44
54
  if (t !== null) {
45
55
  if (t === "require") return !0;
@@ -54,7 +64,7 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
54
64
  throw Error(`DB_URL '?${t}=${n}' is not supported by the mssql dialect — use 'true'/'1' or 'false'/'0'.`);
55
65
  }
56
66
  }
57
- }, V = (e) => {
67
+ }, z = (e) => {
58
68
  let t = e.acquireTimeoutMs === void 0 ? {} : { acquireTimeoutMs: e.acquireTimeoutMs }, n = (e) => e === void 0 ? {} : {
59
69
  encrypt: e,
60
70
  ...e ? { trustServer: !0 } : {}
@@ -67,7 +77,7 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
67
77
  username: decodeURIComponent(r.username || "sa"),
68
78
  password: decodeURIComponent(r.password || ""),
69
79
  database: r.pathname.replace(/^\//, "") || "master",
70
- ...n(e.ssl ?? he(r.searchParams)),
80
+ ...n(e.ssl ?? xe(r.searchParams)),
71
81
  ...e.maxConnections === void 0 ? {} : { maxConnections: e.maxConnections },
72
82
  ...t
73
83
  };
@@ -82,7 +92,29 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
82
92
  ...e.maxConnections === void 0 ? {} : { maxConnections: e.maxConnections },
83
93
  ...t
84
94
  };
85
- }, H = (e) => B(V(e)), ge = f, U = (e) => {
95
+ }, B = (e) => R(z(e)), V = (e, t) => i.gen(function* () {
96
+ let n = yield* e`
97
+ SELECT name, system_type_id FROM sys.columns
98
+ WHERE object_id = OBJECT_ID(${e`${e(t)}`.compile()[0]}, 'U')
99
+ ORDER BY column_id
100
+ `.withoutTransform;
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) => {
103
+ let r = e.literal(`[${t.name.replaceAll("]", "]]")}]`), i = n ? e`${e(n)}.${r}` : r;
104
+ return t.system_type_id === 106 || t.system_type_id === 108 ? e`CONVERT(varchar(80), ${i}) AS ${r}` : i;
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) => {
107
+ let n = e.literal(`[${t.name.replaceAll("]", "]]")}]`);
108
+ return t.system_type_id === 189 ? e`CONVERT(binary(8), ${n}) AS ${n}` : n;
109
+ })), s = H(e, a);
110
+ return yield* e`
111
+ SELECT TOP (0) ${r ? e.literal("CAST(NULL AS nvarchar(10)) AS [__action],") : e.literal("")} source.* INTO ${i}
112
+ FROM (SELECT ${o} FROM ${e(t)} UNION ALL SELECT ${o} FROM ${e(t)}) AS source;
113
+ ${n(i)};
114
+ SELECT ${r ? e.literal("[__action],") : e.literal("")}${s} FROM ${i};
115
+ DROP TABLE ${i};
116
+ `;
117
+ })), Se = p, W = (e) => {
86
118
  let t = e;
87
119
  for (let e = 0; e < 5 && typeof t == "object" && t; e++) {
88
120
  let e = t.number;
@@ -91,18 +123,18 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
91
123
  if (typeof n == "string") return n;
92
124
  t = t.cause;
93
125
  }
94
- }, W = (e) => _(e).some((e) => {
95
- let t = U(e);
96
- return t !== void 0 && ge.has(t);
97
- }), _e = /* @__PURE__ */ new Set(["2601", "2627"]), G = (e) => _(e).some((e) => {
98
- let t = U(e);
99
- return t !== void 0 && _e.has(t);
100
- }), K = (e) => W(e) ? "retry" : "noRetry", ve = {
126
+ }, G = (e) => y(e).some((e) => {
127
+ let t = W(e);
128
+ return t !== void 0 && Se.has(t);
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 = {
101
133
  I: "insert",
102
134
  U: "update",
103
135
  D: "delete"
104
- }, q = (e, t) => e(i.gen(function* () {
105
- let e = yield* F;
136
+ }, J = (e, t) => e(i.gen(function* () {
137
+ let e = yield* I;
106
138
  if (((yield* e`
107
139
  SELECT COUNT(*) AS ${e("on")}
108
140
  FROM sys.change_tracking_databases
@@ -116,18 +148,18 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
116
148
  }
117
149
  yield* e.unsafe(`IF NOT EXISTS (
118
150
  SELECT 1 FROM sys.change_tracking_tables
119
- WHERE object_id = OBJECT_ID(${J(r)})
151
+ WHERE object_id = OBJECT_ID(${Y(r)})
120
152
  )
121
- 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)`);
122
154
  }
123
155
  return n;
124
- })), J = (e) => `'${e.replace(/'/g, "''")}'`, Y = (e) => `[${e.replace(/\]/g, "]]")}]`, X = async (e) => {
125
- let t = P({ 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* () {
126
- return yield* (yield* F)`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`;
127
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) => {
128
160
  let c = await e.run(i.gen(function* () {
129
- let e = yield* F, t = e.unsafe(Y(n)), i = (yield* e`
130
- 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;
131
163
  if (i != null && BigInt(r) < BigInt(i)) {
132
164
  if (!a.has(n)) return {
133
165
  resync: !0,
@@ -138,7 +170,7 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
138
170
  return {
139
171
  resync: !1,
140
172
  rows: yield* e`
141
- SELECT ct.SYS_CHANGE_OPERATION AS __ct_op, ct.id AS __ct_id, t.*
173
+ SELECT ct.SYS_CHANGE_OPERATION AS __ct_op, ct.id AS __ct_id, ${H(e, yield* V(e, n), "t")}
142
174
  FROM CHANGETABLE(CHANGES ${t}, ${BigInt(o)}) AS ct
143
175
  LEFT JOIN ${t} AS t ON t.id = ct.id
144
176
  ORDER BY ct.SYS_CHANGE_VERSION`.unprepared
@@ -149,7 +181,7 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
149
181
  return;
150
182
  }
151
183
  for (let t of c.rows) {
152
- let r = ve[t.__ct_op];
184
+ let r = we[t.__ct_op];
153
185
  if (!r) continue;
154
186
  let { __ct_op: i, __ct_id: a, ...o } = t;
155
187
  if (r === "delete") e.onChange({
@@ -160,7 +192,7 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
160
192
  netChange: !0
161
193
  });
162
194
  else {
163
- let t = C([o], n, "mssql")[0];
195
+ let t = E([o], n, "mssql")[0];
164
196
  e.onChange({
165
197
  table: n,
166
198
  op: r,
@@ -176,7 +208,7 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
176
208
  try {
177
209
  if (r.length > 0) {
178
210
  let t = r;
179
- r = await q(e.run, t);
211
+ r = await J(e.run, t);
180
212
  for (let e of t) r.includes(e) || a.add(e);
181
213
  }
182
214
  let t = await o();
@@ -188,7 +220,7 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
188
220
  s = d(t, s) ? t : s, e.onVersion?.(s);
189
221
  }
190
222
  } catch (n) {
191
- t.warn("cdc: poll cycle failed — retrying next tick", {}, n), e.onError?.(n);
223
+ c || (t.warn("cdc: poll cycle failed — retrying next tick", {}, n), e.onError?.(n));
192
224
  } finally {
193
225
  u = !1, c || (l = setTimeout(() => {
194
226
  p();
@@ -207,26 +239,26 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
207
239
  },
208
240
  currentVersion: () => s
209
241
  };
210
- }, Z = P({ scope: "voltro:mssql" }), Q = async (e) => {
242
+ }, Q = F({ scope: "voltro:mssql" }), $ = async (e) => {
211
243
  let t = e.changeStrategy ?? "inline", n = t;
212
- t === "cdc" && !e.cdcConfig && (Z.warn("changeStrategy='cdc' requires cdcConfig (replicaId + includeTables); falling back to 'inline'."), n = "inline");
213
- let r = e.tracerLayer ? a.mergeAll(e.sqlLayer, e.tracerLayer) : e.sqlLayer, i = o.make(r), s = new ye(await i.runPromise(F), 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);
214
246
  return n === "cdc" && e.cdcConfig && await s.startCdcConsumer(e.cdcConfig), s;
215
- }, ye = class e {
247
+ }, Te = class e {
216
248
  sql;
217
249
  runtime;
218
250
  changeStrategy;
219
251
  namespace;
220
252
  emitter;
221
253
  inflightTxns = 0;
222
- reportEagerFallback = re(Z);
254
+ reportEagerFallback = re(Q);
223
255
  cdcHandle = null;
224
256
  cdcCheckpointTimer = null;
225
257
  cdcPendingVersion = null;
226
258
  cdcReplicaId = "";
227
259
  cdcStreamName = "default";
228
260
  constructor(e, t, n = "inline", r = null, i) {
229
- this.sql = e, this.runtime = t, this.changeStrategy = n, this.namespace = r, this.emitter = i ?? new pe(), O(this.emitter);
261
+ this.sql = e, this.runtime = t, this.changeStrategy = n, this.namespace = r, this.emitter = i ?? new ge(), ce(this.emitter);
230
262
  }
231
263
  get inlineEmit() {
232
264
  return this.changeStrategy === "inline";
@@ -235,19 +267,19 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
235
267
  return t === this.namespace ? this : new e(this.sql, this.runtime, this.changeStrategy, t, this.emitter);
236
268
  }
237
269
  nsT(e) {
238
- return ae(this.namespace, e);
270
+ return oe(this.namespace, e);
239
271
  }
240
272
  __mssqlReplicationFriend = { runEffect: (e) => this.runtime.runPromise(e) };
241
273
  async executeQuery(e, t) {
242
- let n = ee(e, this.sql, this.namespace), r = t ? i.provideService(n, I, t) : n, a = await D("mssql", "select", () => this.runtime.runPromise(r));
243
- 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");
244
276
  }
245
277
  decodeWritten(e, t) {
246
- return C([t], e, "mssql")[0] ?? t;
278
+ return E([t], e, "mssql")[0] ?? t;
247
279
  }
248
280
  async executeInsert(e, t, n, r, a) {
249
- t = j(e, t);
250
- let o = this.sql, s = o`INSERT INTO ${o(this.nsT(e))} ${o.insert(w(t, e)).returning("*")}`, c = n ? i.provideService(s, I, 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];
251
283
  if (!l) throw Error(`MssqlStore.insert: row not returned post-insert in '${e}'`);
252
284
  let u = this.decodeWritten(e, l);
253
285
  return await this.routeEvent({
@@ -258,7 +290,7 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
258
290
  }, r, n, a), u;
259
291
  }
260
292
  async executeUpdate(e, t, n, r, a, o) {
261
- let s = this.sql, c = s`UPDATE ${s(this.nsT(e))} SET ${s.update(w(n, e)).returning("*")} WHERE ${s.and(A(t).map(([e, t]) => s`${s(e)} = ${t}`))}`, l = r ? i.provideService(c, I, 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];
262
294
  if (!u) return null;
263
295
  let d = this.decodeWritten(e, u);
264
296
  return await this.routeEvent({
@@ -269,17 +301,17 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
269
301
  }, a, r, o), d;
270
302
  }
271
303
  async executeInsertMany(e, t, n, r, a) {
272
- if (t = de(e, t), t.length === 0) return [];
273
- let o = this.sql, s = v(t, g("mssql")), c = (t) => o`INSERT INTO ${o(this.nsT(e))} ${o.insert(t.map((t) => w(t, e))).returning("*")}`, 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;
274
306
  if (s.length === 1) {
275
- let e = c(s[0]), t = n ? i.provideService(e, I, n) : e;
307
+ let e = c(s[0]), t = n ? i.provideService(e, this.sql.transactionService, n) : e;
276
308
  l = await this.runtime.runPromise(t);
277
309
  } else if (n) {
278
310
  let e = [];
279
- for (let t of s) e.push(...await this.runtime.runPromise(i.provideService(c(t), I, n)));
311
+ for (let t of s) e.push(...await this.runtime.runPromise(i.provideService(c(t), this.sql.transactionService, n)));
280
312
  l = e;
281
313
  } else l = await this.runtime.runPromise(o.withTransaction(i.map(i.forEach(s, c, { concurrency: 1 }), (e) => e.flat())));
282
- 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;
283
315
  for (let t of m) await this.routeEvent({
284
316
  table: e,
285
317
  op: "insert",
@@ -289,7 +321,7 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
289
321
  return m;
290
322
  }
291
323
  async executePatchJson(e, t, n, r, a, o, s, c) {
292
- 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 = l`UPDATE ${l(this.nsT(e))} SET ${d} OUTPUT INSERTED.* WHERE ${l.and(A(t).map(([e, t]) => l`${l(e)} = ${t}`))}`, p = a ? i.provideService(f, I, 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];
293
325
  if (!m) return null;
294
326
  let h = this.decodeWritten(e, m);
295
327
  return await this.routeEvent({
@@ -300,7 +332,7 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
300
332
  }, o, a, s), h;
301
333
  }
302
334
  async executeDelete(e, t, n, r, a) {
303
- let o = this.sql, s = o`DELETE FROM ${o(this.nsT(e))} OUTPUT DELETED.* WHERE ${o.and(A(t).map(([e, t]) => o`${o(e)} = ${t}`))}`, c = n ? i.provideService(s, I, 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];
304
336
  if (!l) return !1;
305
337
  let u = this.decodeWritten(e, l);
306
338
  return await this.routeEvent({
@@ -311,18 +343,18 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
311
343
  }, r, n, a), !0;
312
344
  }
313
345
  async appendInTxn(e, t, n) {
314
- let r = this.sql, a = r`INSERT INTO ${r(this.nsT(e))} ${r.insert(w(t, e))}`;
315
- await this.runtime.runPromise(n ? i.provideService(a, I, 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);
316
348
  }
317
349
  async maxInTxn(e, t, n, r) {
318
- 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, I, 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;
319
351
  return c == null ? null : Number(c);
320
352
  }
321
353
  async routeEvent(e, t, n = null, r) {
322
354
  e = {
323
- ...h(r),
355
+ ..._(r),
324
356
  ...e
325
- }, k(e.table) && await ue({
357
+ }, A(e.table) && await fe({
326
358
  append: (e, t) => this.appendInTxn(e, t, n),
327
359
  maxOf: (e, t, r) => this.maxInTxn(e, t, r, n)
328
360
  }, {
@@ -332,7 +364,7 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
332
364
  prev: e.old,
333
365
  traceId: e.traceId,
334
366
  subjectId: e.subjectId
335
- }), 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));
336
368
  }
337
369
  query(e) {
338
370
  return this.runWithEager(e, null);
@@ -341,17 +373,17 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
341
373
  return this.rawOn(e, null);
342
374
  }
343
375
  rawOn(e, t) {
344
- let n = S(e, this.sql), r = t ? i.provideService(n, I, t) : n;
345
- 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));
346
378
  }
347
379
  async runWithEager(e, t) {
348
380
  if (!te(e)) return this.executeQuery(e, t);
349
- let n = this.namespace === null ? y(e, this.sql, "mssql") : null;
381
+ let n = this.namespace === null ? x(e, this.sql, "mssql") : null;
350
382
  if (n !== null) try {
351
- let e = t ? i.provideService(n.fragment, I, 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));
352
384
  return n.decode(r);
353
385
  } catch (t) {
354
- if (t instanceof d) throw t;
386
+ if (t instanceof f) throw t;
355
387
  this.reportEagerFallback({
356
388
  dialect: "mssql",
357
389
  table: e.table,
@@ -365,17 +397,17 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
365
397
  reason: "not-compilable"
366
398
  });
367
399
  let r = await this.executeQuery(e, t);
368
- return m(r, e.eager, e.sourceTable ?? se(e.table), (e) => this.executeQuery(e, t));
400
+ return g(r, e.eager, e.sourceTable ?? le(e.table), (e) => this.executeQuery(e, t));
369
401
  }
370
402
  getInternalRunWithEager() {
371
403
  return this.runWithEager.bind(this);
372
404
  }
373
405
  localWrite(e, t, n) {
374
- let r = (e) => k(t) ? this.writeWithRecorders(n, e) : n(e, null, null);
375
- return D("mssql", e, () => fe(r));
406
+ let r = (e) => A(t) ? this.writeWithRecorders(n, e) : n(e, null, null);
407
+ return k("mssql", e, () => he(r));
376
408
  }
377
409
  async writeWithRecorders(e, t) {
378
- let n = [], r = this.sql, a = await this.runtime.runPromise(r.withTransaction(i.flatMap(i.serviceOption(I), (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({
379
411
  try: () => e(t, r.value, n),
380
412
  catch: (e) => e
381
413
  }))));
@@ -404,8 +436,8 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
404
436
  return this.executeDeleteMany(e, t, null, null);
405
437
  }
406
438
  async executeUpdateMany(e, t, n, r, a, o) {
407
- let s = this.sql, c = x(n.where, s, this.namespace), l = s`UPDATE ${s(this.nsT(e))} SET ${s.update(w(t, e))} OUTPUT INSERTED.* WHERE ${c}`, u = r ? i.provideService(l, I, r) : l, d = await D("mssql", "update", () => this.runtime.runPromise(u));
408
- 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({
409
441
  table: e,
410
442
  op: "update",
411
443
  old: null,
@@ -414,8 +446,8 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
414
446
  return d.length;
415
447
  }
416
448
  async executeDeleteMany(e, t, n, r, a) {
417
- let o = this.sql, s = x(t.where, o, this.namespace), c = o`DELETE FROM ${o(this.nsT(e))} OUTPUT DELETED.* WHERE ${s}`, l = n ? i.provideService(c, I, n) : c, u = await D("mssql", "delete", () => this.runtime.runPromise(l));
418
- 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({
419
451
  table: e,
420
452
  op: "delete",
421
453
  old: t,
@@ -433,34 +465,34 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
433
465
  return this.localWrite("upsert", e, (r, i, a) => this.executeInsertIgnore(e, t, n, i, a, r));
434
466
  }
435
467
  async executeUpsert(e, t, n, r, i, a) {
436
- if (N(n), t = j(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, {
437
469
  conflictColumns: n.conflictColumns,
438
470
  ...n.update === void 0 ? {} : { update: n.update },
439
471
  ...n.updateValues === void 0 ? {} : { updateValues: n.updateValues }
440
472
  }, r, i, a);
441
473
  let o = await this.findByConflict(e, t, n.conflictColumns, r);
442
- if (o) return await this.executeUpdate(e, o.id, M(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;
443
475
  try {
444
476
  return await this.executeInsert(e, t, r, i, a);
445
477
  } catch (o) {
446
- if (!G(o)) throw o;
478
+ if (!K(o)) throw o;
447
479
  let s = await this.findByConflict(e, t, n.conflictColumns, r);
448
480
  if (!s) throw o;
449
- return await this.executeUpdate(e, s.id, M(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;
450
482
  }
451
483
  }
452
484
  async mergeUpsert(e, t, n, r, a, o) {
453
- 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 = N(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}`)];
454
486
  v.length === 0 && v.push(s`tgt.${s(n.conflictColumns[0])} = src.${s(n.conflictColumns[0])}`);
455
- let y = s`
487
+ let y = U(s, this.nsT(e), (t) => s`
456
488
  MERGE ${s(this.nsT(e))} WITH (HOLDLOCK) AS tgt
457
489
  USING (VALUES (${s.csv(d)})) AS src (${s.csv(f)})
458
490
  ON ${s.and(p)}
459
491
  WHEN MATCHED THEN UPDATE SET ${s.csv(v)}
460
492
  WHEN NOT MATCHED THEN INSERT (${s.csv(m)}) VALUES (${s.csv(h)})
461
- OUTPUT $action AS ${s("__action")}, INSERTED.*;`, b = r ? i.provideService(y, I, 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];
462
494
  if (!x) throw Error(`MssqlStore.upsert: MERGE returned no row for '${e}'`);
463
- 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);
464
496
  return await this.routeEvent({
465
497
  table: e,
466
498
  op: S === "INSERT" ? "insert" : "update",
@@ -469,7 +501,7 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
469
501
  }, a, r, o), T;
470
502
  }
471
503
  async executeInsertIgnore(e, t, n, r, i, a) {
472
- t = j(e, t);
504
+ t = M(e, t);
473
505
  let o = await this.findByConflict(e, t, n.conflictColumns, r);
474
506
  if (o) return {
475
507
  row: o,
@@ -481,7 +513,7 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
481
513
  outcome: "inserted"
482
514
  };
483
515
  } catch (i) {
484
- if (!G(i)) throw i;
516
+ if (!K(i)) throw i;
485
517
  let a = await this.findByConflict(e, t, n.conflictColumns, r);
486
518
  if (!a) throw i;
487
519
  return {
@@ -492,7 +524,7 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
492
524
  }
493
525
  async findByConflict(e, t, n, r) {
494
526
  if (n.length === 0) return;
495
- 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, I, 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];
496
528
  return l ? this.decodeWritten(e, l) : void 0;
497
529
  }
498
530
  emitChange(e) {
@@ -502,9 +534,9 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
502
534
  if (this.cdcHandle) return;
503
535
  this.cdcReplicaId = e.replicaId;
504
536
  let t = e.includeTables ?? [];
505
- 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.");
506
538
  let n = await this.readCdcOffset(e.replicaId);
507
- this.cdcHandle = await X({
539
+ this.cdcHandle = await Z({
508
540
  run: this.__mssqlReplicationFriend.runEffect,
509
541
  tables: t,
510
542
  startVersion: n,
@@ -512,9 +544,9 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
512
544
  onVersion: (e) => {
513
545
  this.cdcPendingVersion = e;
514
546
  },
515
- onError: (e) => Z.warn("cdc: consumer error", {}, e),
547
+ onError: (e) => Q.warn("cdc: consumer error", {}, e),
516
548
  onResync: () => {
517
- 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");
518
550
  }
519
551
  }), this.cdcCheckpointTimer = setInterval(() => {
520
552
  this.flushCdcOffset();
@@ -523,14 +555,14 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
523
555
  async readCdcOffset(e) {
524
556
  try {
525
557
  let t = this.sql, n = (await this.runtime.runPromise(t`
526
- SELECT TOP 1 ${t("ctVersion")} FROM ${t(l)}
558
+ SELECT TOP 1 ${t("ctVersion")} FROM ${t(u)}
527
559
  WHERE ${t("id")} = ${e}`))[0]?.ctVersion;
528
- return n ? (Z.info("cdc: resuming from persisted CT version", {
560
+ return n ? (Q.info("cdc: resuming from persisted CT version", {
529
561
  replicaId: e,
530
562
  version: n
531
563
  }), n) : null;
532
564
  } catch (t) {
533
- 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;
534
566
  }
535
567
  }
536
568
  async flushCdcOffset() {
@@ -539,7 +571,7 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
539
571
  this.cdcPendingVersion = null;
540
572
  try {
541
573
  let t = this.cdcReplicaId;
542
- await this.executeUpsert(l, {
574
+ await this.executeUpsert(u, {
543
575
  id: t,
544
576
  replicaId: t,
545
577
  streamName: this.cdcStreamName,
@@ -550,7 +582,7 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
550
582
  update: ["ctVersion", "updatedAt"]
551
583
  }, null, null);
552
584
  } catch (t) {
553
- this.cdcPendingVersion = e, Z.warn("cdc: checkpoint write failed", {}, t);
585
+ this.cdcPendingVersion = e, Q.warn("cdc: checkpoint write failed", {}, t);
554
586
  }
555
587
  }
556
588
  }
@@ -605,28 +637,32 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
605
637
  }
606
638
  async emptyTablesOn(e, t) {
607
639
  if (e.length === 0) return;
608
- 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, I, 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);
609
641
  await this.runtime.runPromise(s);
610
642
  }
611
643
  async transactional(e) {
612
644
  this.inflightTxns++;
613
645
  try {
614
- return await le({
646
+ return await de({
615
647
  ...this.txnSpec("MssqlStore.transactional"),
616
648
  work: e,
617
- makeView: (e, t) => new be(this, e, t)
649
+ makeView: (e, t) => new Ee(this, e, t)
618
650
  });
619
651
  } finally {
620
652
  this.inflightTxns--;
621
653
  }
622
654
  }
655
+ get transactionService() {
656
+ return this.sql.transactionService;
657
+ }
623
658
  txnSpec(e) {
624
659
  return {
625
660
  label: e,
626
661
  dialect: "mssql",
627
662
  withTransaction: (e) => this.sql.withTransaction(e),
663
+ transactionService: this.sql.transactionService,
628
664
  runPromiseExit: (e) => this.runtime.runPromiseExit(e),
629
- isRetryable: W,
665
+ isRetryable: G,
630
666
  span: {
631
667
  name: "store.transactional",
632
668
  attributes: {
@@ -645,7 +681,7 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
645
681
  return this.changeStrategy === "cdc" ? "fleet" : "local";
646
682
  }
647
683
  injectExternalChange(e) {
648
- E(e.table) && this.emitter.emit("change", T(e));
684
+ O(e.table) && this.emitter.emit("change", ee(e));
649
685
  }
650
686
  run(e) {
651
687
  return this.runtime.runPromise(e);
@@ -658,7 +694,7 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
658
694
  if (this.inflightTxns > 0) {
659
695
  let t = Date.now() + e;
660
696
  for (; this.inflightTxns > 0 && Date.now() < t;) await new Promise((e) => setTimeout(e, 25));
661
- 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", {
662
698
  gracePeriodMs: e,
663
699
  inflight: this.inflightTxns
664
700
  });
@@ -668,27 +704,27 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
668
704
  async ping() {
669
705
  await this.runtime.runPromise(this.sql`SELECT 1`);
670
706
  }
671
- }, be = class {
707
+ }, Ee = class {
672
708
  parent;
673
709
  txn;
674
710
  attr;
675
711
  events = [];
676
- aborts = ie((e) => W(e));
712
+ aborts = ie((e) => G(e));
677
713
  committed = !1;
678
714
  constructor(e, t, n = void 0) {
679
715
  this.parent = e, this.txn = t, this.attr = n;
680
716
  }
681
717
  savepoint(e) {
682
- return ce({
718
+ return ue({
683
719
  tracker: this.aborts,
684
720
  name: `voltro_sp_${++this.savepointCounter}`,
685
721
  spelling: "mssql",
686
- exec: (e) => this.parent.run(i.provideService(F.pipe(i.flatMap((t) => t.unsafe(e))), I, this.txn))
722
+ exec: (e) => this.parent.run(i.provideService(I.pipe(i.flatMap((t) => t.unsafe(e))), this.parent.transactionService, this.txn))
687
723
  }, e);
688
724
  }
689
725
  savepointCounter = 0;
690
726
  run(e) {
691
- return this.aborts.track(() => this.parent.run(i.provideService(e, I, this.txn)));
727
+ return this.aborts.track(() => this.parent.run(ae(e, this.parent.transactionService, this.txn)));
692
728
  }
693
729
  abortedBy() {
694
730
  return this.aborts.abortedBy();
@@ -748,12 +784,12 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
748
784
  this.events.length = 0;
749
785
  }
750
786
  }
751
- }, $ = (e) => e.__mssqlReplicationFriend ?? null, xe = (e, t) => e === t ? 0 : e < t ? -1 : 1, Se = () => ({
787
+ }, De = (e) => e.__mssqlReplicationFriend ?? null, Oe = (e, t) => e === t ? 0 : e < t ? -1 : 1, ke = () => ({
752
788
  async capturePrimaryPosition(e) {
753
- let t = $(e);
789
+ let t = De(e);
754
790
  if (t === null) throw Error("mssqlReplicationAdapter: primary is not an MssqlStore (missing __mssqlReplicationFriend).");
755
791
  return t.runEffect(i.gen(function* () {
756
- return (yield* (yield* F)`
792
+ return (yield* (yield* I)`
757
793
  SELECT CONVERT(VARCHAR(40), end_of_log_lsn) AS lsn
758
794
  FROM sys.dm_hadr_database_replica_states
759
795
  WHERE database_id = DB_ID()
@@ -763,10 +799,10 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
763
799
  }));
764
800
  },
765
801
  async probeReplicaPosition(e) {
766
- let t = $(e);
802
+ let t = De(e);
767
803
  if (t === null) throw Error("mssqlReplicationAdapter: replica is not an MssqlStore.");
768
804
  return t.runEffect(i.gen(function* () {
769
- return (yield* (yield* F)`
805
+ return (yield* (yield* I)`
770
806
  SELECT CONVERT(VARCHAR(40), last_hardened_lsn) AS lsn
771
807
  FROM sys.dm_hadr_database_replica_states
772
808
  WHERE database_id = DB_ID()
@@ -775,14 +811,14 @@ var L = (e) => typeof e == "bigint" ? t.BigInt : typeof e == "number" && Number.
775
811
  }));
776
812
  },
777
813
  compare(e, t) {
778
- return xe(t, e) >= 0 ? "caught-up" : "behind";
814
+ return Oe(t, e) >= 0 ? "caught-up" : "behind";
779
815
  }
780
- }), Ce = {
816
+ }), Ae = {
781
817
  id: "mssql",
782
- makeSqlLayer: (e) => H(e),
783
- makeStore: (e) => Q(e),
818
+ makeSqlLayer: (e) => B(e),
819
+ makeStore: (e) => $(e),
784
820
  compileContains: (e, t, n) => n`${e} LIKE ${`%${t.replace(/[\\%_[\]]/g, (e) => `\\${e}`)}%`} ESCAPE '\\'`,
785
- retryFilter: K
821
+ retryFilter: q
786
822
  };
787
823
  //#endregion
788
- export { l as CDC_OFFSETS_TABLE, e as MssqlClient, p as _voltroMssqlCdcOffsetsTable, V as connectionFromConfig, q as ensureChangeTracking, B as makeMssqlSqlLayer, H as makeMssqlSqlLayerFromConfig, Q as makeMssqlStore, Ce as mssqlDialect, Se 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 };