@voltro/runtime 0.86.0 → 0.87.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.
Files changed (70) hide show
  1. package/CHANGELOG.md +5321 -0
  2. package/README.md +43 -0
  3. package/THIRD-PARTY-NOTICES.md +860 -221
  4. package/dist/analyticsSink.js +8 -14
  5. package/dist/apiKeys.js +82 -78
  6. package/dist/apiRoleBucketSampler.js +64 -0
  7. package/dist/apiRoleWorkloadHistory.js +56 -0
  8. package/dist/apiRoleWorkloadMetrics.js +78 -0
  9. package/dist/apiRoleWorkloadStorage.js +95 -0
  10. package/dist/approvals.js +67 -74
  11. package/dist/authMiddlewareLayer.js +7 -6
  12. package/dist/bindEvent.js +48 -28
  13. package/dist/bootListener.js +106 -39
  14. package/dist/bootStoreCodec.js +38 -37
  15. package/dist/circuitBreaker.js +1 -72
  16. package/dist/composeAnalytics.js +31 -10
  17. package/dist/computedQueryCache.js +231 -0
  18. package/dist/connectionsFacade.js +32 -30
  19. package/dist/coordinatedSchedule.js +84 -78
  20. package/dist/dataStore.js +154 -121
  21. package/dist/declaredTablesGuard.js +2 -1
  22. package/dist/dispatcher.js +403 -328
  23. package/dist/effectStore.js +2 -2
  24. package/dist/engineClients.js +24 -0
  25. package/dist/externalizedTasks.js +19 -6
  26. package/dist/fieldCipher.js +109 -40
  27. package/dist/fieldKeyRegistry.js +295 -0
  28. package/dist/fieldKeyRekey.js +286 -0
  29. package/dist/fieldKeyScan.js +136 -0
  30. package/dist/fieldKeyring.js +77 -0
  31. package/dist/hot.d.ts +56 -0
  32. package/dist/hot.js +3 -0
  33. package/dist/hotDataStore.js +148 -0
  34. package/dist/hotDataStoreSnapshot.js +98 -0
  35. package/dist/hotDataStoreTables.js +18 -0
  36. package/dist/http-range.d.ts +53 -0
  37. package/dist/http-range.js +52 -0
  38. package/dist/httpClientSsrf.js +12 -37
  39. package/dist/httpClientTracing.js +12 -9
  40. package/dist/httpCompression.js +17 -17
  41. package/dist/httpInputStream.js +82 -0
  42. package/dist/httpRouteMounts.js +1 -0
  43. package/dist/idempotencyStore.js +92 -52
  44. package/dist/index.d.ts +1164 -451
  45. package/dist/index.js +143 -132
  46. package/dist/kvFacade.js +23 -17
  47. package/dist/memoryQueryJoins.js +16 -16
  48. package/dist/memorySetOperations.js +43 -0
  49. package/dist/metrics.js +38 -24
  50. package/dist/outbox.js +1 -1
  51. package/dist/readRecorder.js +35 -34
  52. package/dist/readScopePredicate.js +12 -0
  53. package/dist/replicatedDataStore.js +22 -4
  54. package/dist/rowFilter.js +56 -39
  55. package/dist/rpcConnections.js +8 -8
  56. package/dist/rpcServer.js +522 -449
  57. package/dist/rpcWorkloadAdmission.js +50 -0
  58. package/dist/rywPositionStore.js +82 -47
  59. package/dist/scheduler.js +6 -1
  60. package/dist/servePipeline.js +215 -146
  61. package/dist/setReadScopes.js +28 -0
  62. package/dist/snapshotValueCodec.js +46 -0
  63. package/dist/sourceResolution.js +34 -24
  64. package/dist/storeMiddleware.js +211 -209
  65. package/dist/subscriber.js +1 -0
  66. package/dist/tenantScope.js +8 -20
  67. package/dist/traceparent.js +8 -19
  68. package/dist/webSocketGatewayRuntime.js +111 -71
  69. package/dist/workflowRuntime.js +9 -9
  70. package/package.json +19 -7
@@ -1,22 +1,24 @@
1
1
  import { isolateRawReadScope as e, rawSqlPreview as t, recordRawRead as n } from "./rawReadScope.js";
2
2
  import { applySealedWrite as r, assertCrdtUpdateAdmissible as i, mergeCrdtColumnsIntoPatch as a, patchTouchesCrdt as o } from "./crdtMerge.js";
3
- import { NO_ROW_FILTER as s, applyRowFilter as c, rowFilterRegistered as l } from "./rowFilter.js";
4
- import { readMaybeOne as u } from "./storeRead.js";
5
- import { CRDT_VERSIONS_TABLE as d } from "./crdtVersionsTable.js";
6
- import { getFieldCipher as f } from "./fieldCipher.js";
7
- import { observeStore as p } from "./observedGraph.js";
8
- import { upsertConflictId as m } from "./upsertBinding.js";
9
- import { applyColumnOnUpdate as h } from "./columnOnUpdate.js";
10
- import { prepareInsertRequiredColumns as g } from "./insertRequiredColumns.js";
11
- import { makeFluentStore as _, missingRowError as v } from "./storeQuery.js";
12
- import { Schema as ee, SchemaIssue as te } from "effect";
13
- import { INITIAL_VERSION as ne, VersionConflict as re, and as y, classifyConstraintViolation as ie, decryptFieldsOnRead as ae, deserializeArraysOnRead as oe, encryptFieldsForWrite as se, encryptFieldsForWriteBatch as ce, encryptedColumnsOf as le, eq as b, extractDbCause as ue, generateId as de, getRelations as fe, getTable as x, gt as pe, inSet as me, isCompositeRowKey as he, isNull as S, jsonPatchAssignments as ge, missingConflictColumns as _e, missingRequiredColumns as ve, or as ye, planVersionedUpdate as be, rowKeyColumns as xe, rowKeyIdentity as C, serializeArraysForWrite as Se, settleVersionedUpdate as Ce, storeRefusalOf as we, upsertUpdateValues as Te } from "@voltro/database";
14
- import { ConstraintViolation as Ee, TableValidationFailed as w, TenantRowNotFound as De, TenantScopeViolation as Oe, ValidationError as ke, isMachineSubject as Ae, subjectAuditActorId as T } from "@voltro/protocol";
15
- import { createLogger as je } from "@voltro/logger";
3
+ import { mapSetReadScopes as s } from "./setReadScopes.js";
4
+ import { NO_ROW_FILTER as c, applyRowFilter as l, rowFilterRegistered as u } from "./rowFilter.js";
5
+ import { addReadScopePredicate as d } from "./readScopePredicate.js";
6
+ import { readMaybeOne as f } from "./storeRead.js";
7
+ import { CRDT_VERSIONS_TABLE as p } from "./crdtVersionsTable.js";
8
+ import { getFieldCipher as m } from "./fieldCipher.js";
9
+ import { observeStore as h } from "./observedGraph.js";
10
+ import { upsertConflictId as g } from "./upsertBinding.js";
11
+ import { applyColumnOnUpdate as _ } from "./columnOnUpdate.js";
12
+ import { prepareInsertRequiredColumns as v } from "./insertRequiredColumns.js";
13
+ import { makeFluentStore as ee, missingRowError as te } from "./storeQuery.js";
14
+ import { Schema as ne, SchemaIssue as re } from "effect";
15
+ import { INITIAL_VERSION as ie, VersionConflict as ae, and as y, classifyConstraintViolation as oe, decryptFieldsOnRead as se, deserializeArraysOnRead as ce, encryptFieldsForWrite as le, encryptFieldsForWriteBatch as ue, encryptedColumnsOf as de, eq as b, extractDbCause as fe, generateId as pe, getRelations as me, getTable as x, gt as he, inSet as ge, isCompositeRowKey as _e, isNull as S, jsonPatchAssignments as ve, missingConflictColumns as ye, missingRequiredColumns as be, or as xe, planVersionedUpdate as Se, refuseIdChangeOfSealedRow as Ce, rowKeyColumns as we, rowKeyIdentity as C, serializeArraysForWrite as Te, settleVersionedUpdate as Ee, storeRefusalOf as De, upsertUpdateValues as Oe } from "@voltro/database";
16
+ import { ConstraintViolation as ke, TableValidationFailed as w, TenantRowNotFound as Ae, TenantScopeViolation as je, ValidationError as Me, isMachineSubject as Ne, subjectAuditActorId as T } from "@voltro/protocol";
17
+ import { createLogger as Pe } from "@voltro/logger";
16
18
  import { defaultCrdtBackend as E } from "@voltro/local-first";
17
19
  //#region src/storeMiddleware.ts
18
- var Me = (e, t, n) => {
19
- let r = fe(e);
20
+ var Fe = (e, t, n) => {
21
+ let r = me(e);
20
22
  if (r === void 0) return t;
21
23
  let i = {};
22
24
  for (let [a, o] of Object.entries(t)) {
@@ -53,44 +55,44 @@ var Me = (e, t, n) => {
53
55
  l.where = t === void 0 ? e : y(t, e);
54
56
  }
55
57
  let t = l.with;
56
- t !== void 0 && (l.with = Me(c, t, n));
58
+ t !== void 0 && (l.with = Fe(c, t, n));
57
59
  }
58
60
  i[a] = l;
59
61
  }
60
62
  return i;
61
- }, D = "id", Ne = 3, O = 8, Pe = (e) => "descriptor" in e ? e.descriptor : e, Fe = (e, t) => {
63
+ }, D = "id", Ie = 3, O = 8, Le = (e) => "descriptor" in e ? e.descriptor : e, Re = (e, t) => {
62
64
  let n = {};
63
65
  for (let r of t) e[r] !== void 0 && (n[r] = e[r]);
64
66
  return n;
65
- }, k = "cannot insert into tenant-scoped table without an authenticated tenant — subject.tenantId is null. Either authenticate first or pass tenantId explicitly in the row (admin tooling).", Ie = (e) => {
66
- throw new Oe({
67
+ }, k = "cannot insert into tenant-scoped table without an authenticated tenant — subject.tenantId is null. Either authenticate first or pass tenantId explicitly in the row (admin tooling).", ze = (e) => {
68
+ throw new je({
67
69
  table: e,
68
70
  reason: k
69
71
  });
70
- }, Le = (e) => T(e), Re = (fe, T) => {
71
- let k = p(fe);
72
+ }, Be = (e) => T(e), Ve = (me, T) => {
73
+ let k = h(me);
72
74
  e();
73
- let A = Le(T.subject), M = T.subject.tenantId;
74
- if (T.rowFilter === void 0 && !Ae(T.subject) && l()) throw Error("row filter registered, but this store was scoped without one — refusing to serve an unfiltered read.\n\nThis app called `setRowFilter`, so every scoped store must receive a resolved `rowFilter` (the serve pipeline's `withRowFilter` does this per request). Reaching here with none means a read path was built outside that spine, and continuing would serve rows the filter exists to hide — silently, which is how this was found in the first place.\n\nIf this path is deliberately unfiltered (a system sweep, a migration), pass `rowFilter: NO_ROW_FILTER` explicitly.");
75
- let N = T.rowFilter ?? s, P = (e, t) => {
75
+ let A = Be(T.subject), M = T.subject.tenantId;
76
+ if (T.rowFilter === void 0 && !Ne(T.subject) && u()) throw Error("row filter registered, but this store was scoped without one — refusing to serve an unfiltered read.\n\nThis app called `setRowFilter`, so every scoped store must receive a resolved `rowFilter` (the serve pipeline's `withRowFilter` does this per request). Reaching here with none means a read path was built outside that spine, and continuing would serve rows the filter exists to hide — silently, which is how this was found in the first place.\n\nIf this path is deliberately unfiltered (a system sweep, a migration), pass `rowFilter: NO_ROW_FILTER` explicitly.");
77
+ let N = T.rowFilter ?? c, P = (e, t) => {
76
78
  let n = { ...t }, r = T.schemaRegistry, i = r.idScheme(e);
77
79
  if (i !== void 0 && n[D] == null) {
78
80
  if (i.kind === "numeric") delete n[D];
79
81
  else {
80
- let t = de(i, e);
82
+ let t = pe(i, e);
81
83
  t !== null && (n[D] = t);
82
84
  }
83
85
  }
84
86
  let a = r.versionColumn(e);
85
87
  if (a !== void 0) {
86
88
  let e = n[a];
87
- (typeof e != "number" || !Number.isFinite(e)) && (n[a] = ne);
89
+ (typeof e != "number" || !Number.isFinite(e)) && (n[a] = ie);
88
90
  }
89
91
  if (r.hasAudit(e)) {
90
92
  let e = /* @__PURE__ */ new Date();
91
93
  "createdAt" in n || (n.createdAt = e), "updatedAt" in n || (n.updatedAt = e), A !== null && ("createdBy" in n || (n.createdBy = A), "updatedBy" in n || (n.updatedBy = A));
92
94
  }
93
- r.hasTenant(e) && ("tenantId" in n || (M === null && Ie(e), n.tenantId = M));
95
+ r.hasTenant(e) && ("tenantId" in n || (M === null && ze(e), n.tenantId = M));
94
96
  let o = r.defaultFactories(e);
95
97
  if (o.size > 0) for (let [e, t] of o) (!(e in n) || n[e] === void 0) && (n[e] = t());
96
98
  let s = r.computedFields(e);
@@ -99,7 +101,7 @@ var Me = (e, t, n) => {
99
101
  if (c.size > 0) for (let e of c) delete n[e];
100
102
  return n;
101
103
  }, F = (e, t, n = []) => {
102
- let r = h(T.schemaRegistry, e, t, n);
104
+ let r = _(T.schemaRegistry, e, t, n);
103
105
  if (!T.schemaRegistry.hasAudit(e)) return r;
104
106
  let i = { ...r };
105
107
  return "updatedAt" in i || (i.updatedAt = /* @__PURE__ */ new Date()), A !== null && !("updatedBy" in i) && (i.updatedBy = A), i;
@@ -107,8 +109,8 @@ var Me = (e, t, n) => {
107
109
  try {
108
110
  return await r();
109
111
  } catch (r) {
110
- let i = we(r);
111
- if (i !== void 0) throw new Ee({
112
+ let i = De(r);
113
+ if (i !== void 0) throw new ke({
112
114
  kind: i.kind,
113
115
  table: e,
114
116
  operation: t,
@@ -116,16 +118,16 @@ var Me = (e, t, n) => {
116
118
  ...i.column === void 0 ? {} : { column: i.column },
117
119
  detail: i.detail
118
120
  });
119
- let a = ue(r), o = ie(a, t);
121
+ let a = fe(r), o = oe(a, t);
120
122
  if (o === void 0) throw r;
121
123
  if (T.schemaRegistry.hasTenant(e) && (o.kind === "foreignKey" || o.kind === "foreignKeyInUse")) {
122
124
  let t = n?.tenantId, r = `${a.dbConstraint ?? ""} ${a.dbColumn ?? ""} ${a.dbMessage ?? ""} ${a.dbCauseChain ?? ""}`.toLowerCase();
123
- if (r.includes("tenantid") || /\btenants\b/.test(r) || t != null && r.includes(String(t).toLowerCase())) throw new Oe({
125
+ if (r.includes("tenantid") || /\btenants\b/.test(r) || t != null && r.includes(String(t).toLowerCase())) throw new je({
124
126
  table: e,
125
127
  reason: t == null ? "write references a tenant that does not exist" : `tenant '${String(t)}' does not exist — seed the row in \`tenants\`, or fix how the request resolved this tenant (subject.tenantId / the x-tenant header / the dev TENANT fallback)`
126
128
  });
127
129
  }
128
- throw new Ee({
130
+ throw new ke({
129
131
  kind: o.kind,
130
132
  table: e,
131
133
  operation: t,
@@ -133,7 +135,7 @@ var Me = (e, t, n) => {
133
135
  ...o.column === void 0 ? {} : { column: o.column }
134
136
  });
135
137
  }
136
- }, ze = (e, t, n) => {
138
+ }, He = (e, t, n) => {
137
139
  let r = T.schemaRegistry.computedFields(e);
138
140
  if (r.size === 0) return n;
139
141
  let i = {
@@ -145,9 +147,9 @@ var Me = (e, t, n) => {
145
147
  }, L = (e, t) => {
146
148
  let n = T.schemaRegistry.validatePatchSchema(e);
147
149
  if (n === void 0) return t;
148
- let r = ee.decodeUnknownResult(n)(t);
150
+ let r = ne.decodeUnknownResult(n)(t);
149
151
  if (r._tag === "Success") return t;
150
- let i = te.makeFormatterStandardSchemaV1()(r.failure.issue).issues.map((e) => ({
152
+ let i = re.makeFormatterStandardSchemaV1()(r.failure.issue).issues.map((e) => ({
151
153
  path: (e.path ?? []).length === 0 ? "<root>" : (e.path ?? []).join("."),
152
154
  message: e.message
153
155
  })), a = i[0];
@@ -156,11 +158,11 @@ var Me = (e, t, n) => {
156
158
  summary: a === void 0 ? "patch validation failed" : `${a.path}: ${a.message}`,
157
159
  issues: i
158
160
  });
159
- }, Be = () => {
161
+ }, Ue = () => {
160
162
  let e = { deletedAt: /* @__PURE__ */ new Date() };
161
163
  return A !== null && (e.deletedBy = A), e;
162
- }, Ve = (e, t, n) => {
163
- let r = _e(x(e), n, t);
164
+ }, We = (e, t, n) => {
165
+ let r = ye(x(e), n, t);
164
166
  if (r.length !== 0) throw new w({
165
167
  table: e,
166
168
  summary: `upsert conflictColumns [${n.map((e) => `'${e}'`).join(", ")}] cannot match: ` + r.map((e) => e.reason === "null" ? `'${e.column}' is NULL` : `'${e.column}' is absent`).join(", "),
@@ -181,7 +183,7 @@ var Me = (e, t, n) => {
181
183
  }
182
184
  let s = x(e);
183
185
  if (s !== void 0) {
184
- let r = n === void 0 ? ve(s, t) : n.filter((e) => t[e] === void 0 || t[e] === null);
186
+ let r = n === void 0 ? be(s, t) : n.filter((e) => t[e] === void 0 || t[e] === null);
185
187
  if (r.length > 0) throw new w({
186
188
  table: e,
187
189
  summary: `missing required column${r.length > 1 ? "s" : ""} ${r.map((e) => `'${e}'`).join(", ")} — NOT NULL with no default and not auto-stamped`,
@@ -193,9 +195,9 @@ var Me = (e, t, n) => {
193
195
  }
194
196
  let c = T.schemaRegistry.insertSchema(e);
195
197
  if (c === void 0) return t;
196
- let l = ee.decodeUnknownResult(c)(t);
198
+ let l = ne.decodeUnknownResult(c)(t);
197
199
  if (l._tag === "Success") return t;
198
- let u = te.makeFormatterStandardSchemaV1()(l.failure.issue).issues.map((e) => ({
200
+ let u = re.makeFormatterStandardSchemaV1()(l.failure.issue).issues.map((e) => ({
199
201
  path: (e.path ?? []).length === 0 ? "<root>" : (e.path ?? []).join("."),
200
202
  message: e.message
201
203
  })), d = u[0];
@@ -205,19 +207,19 @@ var Me = (e, t, n) => {
205
207
  issues: u
206
208
  });
207
209
  }, z = T.dialect, B = (e, t, n) => {
208
- let r = x(e), i = z ? Se(t, r, z) : t;
209
- return se(i, r, f(), n);
210
- }, V = (e, t) => {
210
+ let r = x(e), i = z ? Te(t, r, z) : t;
211
+ return le(i, r, m(), n);
212
+ }, V = (e, t, n) => (Ce(t, x(e), n), B(e, t, n)), H = (e, t) => {
211
213
  let n = x(e);
212
- return n !== void 0 && le(n).some((e) => t[e] !== void 0 && t[e] !== null);
213
- }, He = (e) => {
214
+ return n !== void 0 && de(n).some((e) => t[e] !== void 0 && t[e] !== null);
215
+ }, Ge = (e) => {
214
216
  let t = e.projection;
215
217
  if (t === void 0 || t.includes(D)) return {
216
218
  descriptor: e,
217
219
  stripId: !1
218
220
  };
219
221
  let n = x(e.table);
220
- return n === void 0 || le(n).length === 0 ? {
222
+ return n === void 0 || de(n).length === 0 ? {
221
223
  descriptor: e,
222
224
  stripId: !1
223
225
  } : {
@@ -227,105 +229,99 @@ var Me = (e, t, n) => {
227
229
  },
228
230
  stripId: !0
229
231
  };
230
- }, Ue = process.env.VOLTRO_FIELD_DECRYPT_ON_ERROR === "null" ? "null" : "throw", We = je({ scope: "store.fieldEncryption" }), Ge = /* @__PURE__ */ new Set(), Ke = (e) => {
232
+ }, Ke = process.env.VOLTRO_FIELD_DECRYPT_ON_ERROR === "null" ? "null" : "throw", qe = Pe({ scope: "store.fieldEncryption" }), Je = /* @__PURE__ */ new Set(), Ye = (e) => {
231
233
  let t = `${e.table}.${e.column}`;
232
- Ge.has(t) || (Ge.add(t), We.warn("encrypted column degraded to null — could not decrypt with the active key", {
234
+ Je.has(t) || (Je.add(t), qe.warn("encrypted column degraded to null — could not decrypt with the active key", {
233
235
  table: e.table,
234
236
  column: e.column,
235
237
  reason: e.reason,
236
238
  hint: "VOLTRO_FIELD_DECRYPT_ON_ERROR=null is set — this row was likely encrypted under a different key"
237
239
  }));
238
- }, H = (e, t, n) => {
239
- let r = x(e), i = ae(t, r, f(), {
240
- onError: Ue,
241
- ...Ue === "null" ? { warn: Ke } : {},
240
+ }, U = (e, t, n) => {
241
+ let r = x(e), i = se(t, r, m(), {
242
+ onError: Ke,
243
+ ...Ke === "null" ? { warn: Ye } : {},
242
244
  ...n === void 0 ? {} : { rowId: n }
243
245
  });
244
- return z ? oe(i, r, z) : i;
245
- }, qe = (e) => {
246
- let t = e.table, n = e.predicate;
247
- if (!e.crossTenant && M != null && T.schemaRegistry.hasTenant(t)) {
248
- let e = b("tenantId", M);
249
- n = n ? y(n, e) : e;
250
- }
251
- if (!e.includeDeleted && T.schemaRegistry.hasSoftDelete(t)) {
252
- let e = S("deletedAt");
253
- n = n ? y(n, e) : e;
254
- }
255
- if (!e.includeExpired && T.schemaRegistry.hasExpires(t)) {
256
- let e = ye(S("expiresAt"), pe("expiresAt", /* @__PURE__ */ new Date()));
257
- n = n ? y(n, e) : e;
258
- }
259
- n = c(N, t, n);
260
- let r = e.eager === void 0 ? void 0 : Me(t, e.eager, N);
261
- return r === void 0 ? n === e.predicate ? e : {
262
- ...e,
263
- predicate: n
246
+ return z ? ce(i, r, z) : i;
247
+ }, Xe = (e, t, n = N) => {
248
+ let r = e, i = r.table;
249
+ !r.crossTenant && M != null && T.schemaRegistry.hasTenant(i) && (r = d(r, (e) => b(e("tenantId"), M))), !r.includeDeleted && T.schemaRegistry.hasSoftDelete(i) && (r = d(r, (e) => S(e("deletedAt")))), !r.includeExpired && T.schemaRegistry.hasExpires(i) && (r = d(r, (e) => xe(S(e("expiresAt")), he(e("expiresAt"), t))));
250
+ let a = r.predicate;
251
+ a = l(n, i, a);
252
+ let o = r.eager === void 0 ? void 0 : Fe(i, r.eager, n);
253
+ return o === void 0 ? a === r.predicate ? r : {
254
+ ...r,
255
+ predicate: a
264
256
  } : {
265
- ...e,
266
- predicate: n,
267
- eager: r
257
+ ...r,
258
+ predicate: a,
259
+ eager: o
268
260
  };
269
- }, Je = async (e) => {
270
- let t = He(e), n = await k.query(t.descriptor), r = H(e.table, n);
271
- return Ye(e.table, r), t.stripId ? r.map((e) => {
261
+ }, Ze = (e, t = N) => {
262
+ let n = /* @__PURE__ */ new Date();
263
+ return s(e, (e) => Xe(e, n, t));
264
+ }, Qe = async (e, t, n) => {
265
+ let r = Ge(e), i = await t(r.descriptor), a = U(e.table, i);
266
+ return n && et(e.table, a), r.stripId ? a.map((e) => {
272
267
  let { [D]: t, ...n } = e;
273
268
  return n;
274
- }) : r;
275
- }, U = async (e) => Je(qe(e)), W = (e, t, n) => {
276
- if (he(n)) return;
269
+ }) : a;
270
+ }, $e = (e) => Qe(e, k.query.bind(k), !0), W = (e) => $e(Ze(e)), G = (e, t, n) => {
271
+ if (_e(n)) return;
277
272
  let r = T.schemaRegistry.declaredPrimaryKey(e);
278
273
  if (r.length === 0 || r.length === 1 && r[0] === "id") return;
279
274
  let i = r.map((e) => `${e}: …`).join(", ");
280
275
  throw Error(`${t}('${e}', <${typeof n}>, …) cannot address a row: '${e}' has no \`id\` column — its primary key is (${r.join(", ")}). Pass those columns instead:\n store.${t}('${e}', { ${i} }${t === "delete" ? "" : ", patch"})\nThis used to return ${t === "delete" ? "`false`" : "`null`"}, which is also what a missing row returns.`);
281
- }, G = async (e, t) => {
276
+ }, K = async (e, t) => {
282
277
  if (M === null || !T.schemaRegistry.hasTenant(e)) return;
283
- let n = xe(t).map(([e, t]) => b(e, t)).reduce((e, t) => e === void 0 ? t : y(e, t), void 0);
278
+ let n = we(t).map(([e, t]) => b(e, t)).reduce((e, t) => e === void 0 ? t : y(e, t), void 0);
284
279
  if (!((await k.query({
285
280
  table: e,
281
+ lock: "update",
286
282
  predicate: y(n, b("tenantId", M)),
287
283
  order: [],
288
284
  take: 1,
289
285
  skip: void 0,
290
- projection: xe(t).map(([e]) => e)
291
- })).length > 0)) throw new De({
286
+ projection: we(t).map(([e]) => e)
287
+ })).length > 0)) throw new Ae({
292
288
  table: e,
293
289
  id: C(t),
294
290
  reason: "no row with this id in your tenant — it does not exist, or it belongs to another tenant. These are deliberately indistinguishable: reporting them differently would let a caller probe for row ids in other tenants."
295
291
  });
296
- }, K = Symbol.for("@voltro/runtime:tx-fold-releases"), q = Symbol.for("@voltro/runtime:tx-read-versions"), J = (e) => e[q], Y = (e, t) => `${e}\u0000${String(t)}`, Ye = (e, t) => {
297
- let n = J(k);
292
+ }, q = Symbol.for("@voltro/runtime:tx-fold-releases"), J = Symbol.for("@voltro/runtime:tx-read-versions"), Y = (e) => e[J], X = (e, t) => `${e}\u0000${String(t)}`, et = (e, t) => {
293
+ let n = Y(k);
298
294
  if (n === void 0 || t.length === 0) return;
299
295
  let r = T.schemaRegistry.versionColumn(e);
300
296
  if (r !== void 0) for (let i of t) {
301
297
  let t = i[D], a = i[r];
302
- typeof t == "string" && typeof a == "number" && Number.isFinite(a) && n.set(Y(e, t), a);
298
+ typeof t == "string" && typeof a == "number" && Number.isFinite(a) && n.set(X(e, t), a);
303
299
  }
304
- }, X = (() => {
300
+ }, Z = (() => {
305
301
  let e = globalThis, t = Symbol.for("@voltro/runtime:crdt-fold-locks");
306
302
  return e[t] ??= /* @__PURE__ */ new Map();
307
- })(), Xe = async (e, t, n) => {
308
- let r = `${e}\u0000${C(t)}`, i = X.get(r) ?? Promise.resolve(), a, o = new Promise((e) => {
303
+ })(), tt = async (e, t, n) => {
304
+ let r = `${e}\u0000${C(t)}`, i = Z.get(r) ?? Promise.resolve(), a, o = new Promise((e) => {
309
305
  a = e;
310
306
  });
311
- X.set(r, i.then(() => o)), await i;
307
+ Z.set(r, i.then(() => o)), await i;
312
308
  try {
313
309
  return await n();
314
310
  } finally {
315
- a(), X.get(r) === o && X.delete(r);
311
+ a(), Z.get(r) === o && Z.delete(r);
316
312
  }
317
- }, Z = async (e, t, n) => {
313
+ }, Q = async (e, t, n) => {
318
314
  let r = T.schemaRegistry.sealedColumns(e);
319
315
  if (o(r, n)) {
320
316
  let i = {}, a = {};
321
317
  for (let [e, t] of Object.entries(n)) (r.has(e) ? i : a)[e] = t;
322
- let o = await et(e, t, i);
323
- return o === null || Object.keys(a).length === 0 ? o : Z(e, t, a);
318
+ let o = await at(e, t, i);
319
+ return o === null || Object.keys(a).length === 0 ? o : Q(e, t, a);
324
320
  }
325
321
  let a = T.schemaRegistry.crdtColumns(e);
326
322
  if (o(a, n)) {
327
323
  for (let t of a) t in n && i(e, t, n[t]);
328
- let r = k[K];
324
+ let r = k[q];
329
325
  if (r !== void 0) {
330
326
  let i = {}, o = {};
331
327
  for (let [e, t] of Object.entries(n)) a.has(e) ? i[e] = t : o[e] = t;
@@ -333,8 +329,8 @@ var Me = (e, t, n) => {
333
329
  table: e,
334
330
  pk: t,
335
331
  patch: i
336
- }), Object.keys(o).length > 0) return Q(e, t, o);
337
- await G(e, t);
332
+ }), Object.keys(o).length > 0) return $(e, t, o);
333
+ await K(e, t);
338
334
  let s = await k.query({
339
335
  table: e,
340
336
  predicate: {
@@ -347,15 +343,15 @@ var Me = (e, t, n) => {
347
343
  skip: void 0,
348
344
  projection: void 0
349
345
  });
350
- return s[0] === void 0 ? null : H(e, [s[0]])[0];
346
+ return s[0] === void 0 ? null : U(e, [s[0]])[0];
351
347
  }
352
- return Xe(e, t, () => Q(e, t, n));
348
+ return tt(e, t, () => $(e, t, n));
353
349
  }
354
- return Q(e, t, n);
355
- }, Q = async (e, t, n) => {
356
- W(e, "update", t), await G(e, t);
350
+ return $(e, t, n);
351
+ }, $ = async (e, t, n) => {
352
+ G(e, "update", t), await K(e, t);
357
353
  let r = F(e, n), i = T.schemaRegistry.crdtColumns(e);
358
- if (o(i, r)) return tt(e, t, r, i);
354
+ if (o(i, r)) return ot(e, t, r, i);
359
355
  if (T.schemaRegistry.computedFields(e).size > 0) {
360
356
  let n = (await k.query({
361
357
  table: e,
@@ -370,16 +366,16 @@ var Me = (e, t, n) => {
370
366
  projection: void 0
371
367
  }))[0];
372
368
  if (n === void 0) return null;
373
- let i = H(e, [n])[0];
374
- r = ze(e, i, r);
369
+ let i = U(e, [n])[0];
370
+ r = He(e, i, r);
375
371
  }
376
372
  r = L(e, r);
377
373
  let a = T.schemaRegistry.versionColumn(e), s;
378
374
  if (a !== void 0) {
379
- let n = be({
375
+ let n = Se({
380
376
  versionColumn: a,
381
377
  patch: r
382
- }), i = J(k)?.get(Y(e, C(t))), o = n.expected === void 0 && i !== void 0, c = n.expected ?? i, l = (e) => {
378
+ }), i = Y(k)?.get(X(e, C(t))), o = n.expected === void 0 && i !== void 0, c = n.expected ?? i, l = (e) => {
383
379
  throw o ? new j(e) : e;
384
380
  }, u = async () => {
385
381
  let n = await k.query({
@@ -395,7 +391,7 @@ var Me = (e, t, n) => {
395
391
  projection: void 0
396
392
  }), r = n[0] === void 0 ? void 0 : n[0][a];
397
393
  return typeof r == "number" && Number.isFinite(r) ? r : null;
398
- }, d = await u(), f = Ce({
394
+ }, d = await u(), f = Ee({
399
395
  table: e,
400
396
  id: C(t),
401
397
  expected: c,
@@ -408,7 +404,7 @@ var Me = (e, t, n) => {
408
404
  if (r = {
409
405
  ...n.patch,
410
406
  [a]: o + 1
411
- }, await I(e, "update", r, () => k.updateMany(e, B(e, r, t), { where: y(b(D, t), b(a, o)) })) > 0) {
407
+ }, await I(e, "update", r, () => k.updateMany(e, V(e, r, t), { where: y(b(D, t), b(a, o)) })) > 0) {
412
408
  s = (await k.query({
413
409
  table: e,
414
410
  predicate: {
@@ -420,22 +416,22 @@ var Me = (e, t, n) => {
420
416
  take: 1,
421
417
  skip: void 0,
422
418
  projection: void 0
423
- }))[0] ?? null, J(k)?.set(Y(e, C(t)), o + 1);
419
+ }))[0] ?? null, Y(k)?.set(X(e, C(t)), o + 1);
424
420
  break;
425
421
  }
426
422
  let f = await u();
427
- (c !== void 0 || f === null || i >= Ne) && l(new re({
423
+ (c !== void 0 || f === null || i >= Ie) && l(new ae({
428
424
  table: e,
429
425
  id: C(t),
430
426
  expected: c ?? o,
431
427
  actual: f
432
428
  })), d = f;
433
429
  }
434
- } else s = await I(e, "update", r, () => k.update(e, t, B(e, r, t)));
435
- return s === null ? null : H(e, [s], t)[0];
436
- }, Ze = async (e, t, n) => {
430
+ } else s = await I(e, "update", r, () => k.update(e, t, V(e, r, t)));
431
+ return s === null ? null : U(e, [s], t)[0];
432
+ }, nt = async (e, t, n) => {
437
433
  let r = await k.query({
438
- table: d,
434
+ table: p,
439
435
  predicate: y(b("tableName", e), b("rowId", C(t)), b("columnName", n), b("reason", "rebase")),
440
436
  order: [{
441
437
  column: "createdAt",
@@ -445,9 +441,9 @@ var Me = (e, t, n) => {
445
441
  skip: void 0,
446
442
  projection: void 0
447
443
  });
448
- return H(d, r).map((e) => e.state).filter((e) => e instanceof Uint8Array);
449
- }, Qe = async (e, t, n, r, i) => {
450
- let a = P(d, {
444
+ return U(p, r).map((e) => e.state).filter((e) => e instanceof Uint8Array);
445
+ }, rt = async (e, t, n, r, i) => {
446
+ let a = P(p, {
451
447
  tableName: e,
452
448
  rowId: C(t),
453
449
  columnName: n,
@@ -457,16 +453,16 @@ var Me = (e, t, n) => {
457
453
  epoch: i === void 0 ? E.epochOf(r) ?? null : i,
458
454
  createdBy: null
459
455
  });
460
- await I(d, "insert", a, () => k.insert(d, B(d, R(d, a))));
461
- }, $e = async (e, t, n, r, i) => {
456
+ await I(p, "insert", a, () => k.insert(p, B(p, R(p, a))));
457
+ }, it = async (e, t, n, r, i) => {
462
458
  if (!(r instanceof Uint8Array) || !(i instanceof Uint8Array) || r.length === 0) return i;
463
459
  let a = E.authorsOf(r), o = [...E.authorsOf(i)].filter((e) => !a.has(e));
464
460
  if (o.length === 0 || E.epochOf(r) === void 0) return i;
465
- for (let a of await Ze(e, t, n)) {
461
+ for (let a of await nt(e, t, n)) {
466
462
  let t = E.authorsOf(a);
467
463
  if (!o.some((e) => t.has(e))) continue;
468
464
  let s = E.translate(a, i, r);
469
- if (s === void 0) throw new ke({
465
+ if (s === void 0) throw new Me({
470
466
  field: n,
471
467
  message: "crdt.staleLineage",
472
468
  params: { table: e }
@@ -474,8 +470,8 @@ var Me = (e, t, n) => {
474
470
  return s;
475
471
  }
476
472
  return i;
477
- }, et = async (e, t, n) => {
478
- await G(e, t);
473
+ }, at = async (e, t, n) => {
474
+ await K(e, t);
479
475
  for (let i = 0;; i += 1) {
480
476
  let a = (await k.query({
481
477
  table: e,
@@ -490,7 +486,7 @@ var Me = (e, t, n) => {
490
486
  projection: void 0
491
487
  }))[0];
492
488
  if (a === void 0) return null;
493
- let o = H(e, [a])[0], s = {}, c = [b(D, t)], l = [];
489
+ let o = U(e, [a])[0], s = {}, c = [b(D, t)], l = [];
494
490
  for (let [t, i] of Object.entries(n)) {
495
491
  if (i === null) s[t] = null;
496
492
  else {
@@ -504,8 +500,8 @@ var Me = (e, t, n) => {
504
500
  c.push(n == null ? S(t) : b(t, n));
505
501
  }
506
502
  let u = F(e, s);
507
- if (await I(e, "update", u, () => k.updateMany(e, B(e, u, t), { where: y(...c) })) > 0) {
508
- for (let n of l) await Qe(e, t, n.column, n.log, n.epoch === "" ? null : n.epoch);
503
+ if (await I(e, "update", u, () => k.updateMany(e, V(e, u, t), { where: y(...c) })) > 0) {
504
+ for (let n of l) await rt(e, t, n.column, n.log, n.epoch === "" ? null : n.epoch);
509
505
  let n = await k.query({
510
506
  table: e,
511
507
  predicate: {
@@ -518,12 +514,12 @@ var Me = (e, t, n) => {
518
514
  skip: void 0,
519
515
  projection: void 0
520
516
  });
521
- return n[0] === void 0 ? null : H(e, [n[0]], t)[0];
517
+ return n[0] === void 0 ? null : U(e, [n[0]], t)[0];
522
518
  }
523
519
  if (i + 1 >= O) throw Error(`sealed crdt append on ${e} lost ${O} compare-and-swap rounds to concurrent writers; the frame was not written and can be retried`);
524
520
  await new Promise((e) => setTimeout(e, Math.random() * 5 * (i + 1)));
525
521
  }
526
- }, tt = async (e, t, n, r) => {
522
+ }, ot = async (e, t, n, r) => {
527
523
  let i = async () => (await k.query({
528
524
  table: e,
529
525
  predicate: {
@@ -535,15 +531,15 @@ var Me = (e, t, n) => {
535
531
  take: 1,
536
532
  skip: void 0,
537
533
  projection: void 0
538
- }))[0], o = [...r].filter((e) => e in n), s = T.schemaRegistry.versionColumn(e), c = s === void 0 ? void 0 : be({
534
+ }))[0], o = [...r].filter((e) => e in n), s = T.schemaRegistry.versionColumn(e), c = s === void 0 ? void 0 : Se({
539
535
  versionColumn: s,
540
536
  patch: n
541
- }), l = s === void 0 ? void 0 : J(k)?.get(Y(e, C(t))), u = c !== void 0 && c.expected === void 0 && l !== void 0, d = c?.expected ?? l, f = c?.patch ?? n, p = await i();
537
+ }), l = s === void 0 ? void 0 : Y(k)?.get(X(e, C(t))), u = c !== void 0 && c.expected === void 0 && l !== void 0, d = c?.expected ?? l, f = c?.patch ?? n, p = await i();
542
538
  for (let n = 0;; n += 1) {
543
539
  if (p === void 0) return null;
544
- let c = H(e, [p])[0], l = f;
540
+ let c = U(e, [p])[0], l = f;
545
541
  for (let n of o) {
546
- let r = await $e(e, t, n, c[n], f[n]);
542
+ let r = await it(e, t, n, c[n], f[n]);
547
543
  r !== f[n] && (l = {
548
544
  ...l,
549
545
  [n]: r
@@ -555,7 +551,7 @@ var Me = (e, t, n) => {
555
551
  archived: t
556
552
  });
557
553
  });
558
- T.schemaRegistry.computedFields(e).size > 0 && (h = ze(e, c, h));
554
+ T.schemaRegistry.computedFields(e).size > 0 && (h = He(e, c, h));
559
555
  let g = [b(D, t)];
560
556
  for (let e of o) {
561
557
  let t = p[e];
@@ -565,7 +561,7 @@ var Me = (e, t, n) => {
565
561
  if (s !== void 0) {
566
562
  let n = p[s];
567
563
  _ = typeof n == "number" && Number.isFinite(n) ? n : void 0;
568
- let r = Ce({
564
+ let r = Ee({
569
565
  table: e,
570
566
  id: C(t),
571
567
  expected: d,
@@ -579,18 +575,18 @@ var Me = (e, t, n) => {
579
575
  }
580
576
  h = L(e, h);
581
577
  let v = h;
582
- if (await I(e, "update", v, () => k.updateMany(e, B(e, v, t), { where: y(...g) })) > 0) {
583
- for (let { column: n, archived: r } of m) await Qe(e, t, n, r);
578
+ if (await I(e, "update", v, () => k.updateMany(e, V(e, v, t), { where: y(...g) })) > 0) {
579
+ for (let { column: n, archived: r } of m) await rt(e, t, n, r);
584
580
  let n = await i();
585
- return n === void 0 ? null : (s !== void 0 && _ !== void 0 && J(k)?.set(Y(e, C(t)), _ + 1), H(e, [n], t)[0]);
581
+ return n === void 0 ? null : (s !== void 0 && _ !== void 0 && Y(k)?.set(X(e, C(t)), _ + 1), U(e, [n], t)[0]);
586
582
  }
587
583
  if (n + 1 >= O) throw Error(`crdt fold on ${e} lost ${O} compare-and-swap rounds to concurrent writers; the update was not written and can be retried`);
588
584
  await new Promise((e) => setTimeout(e, Math.random() * 5 * (n + 1))), p = await i();
589
585
  }
590
- }, nt = async (e, t) => (W(e, "delete", t), await G(e, t), T.schemaRegistry.hasSoftDelete(e) ? await Z(e, t, Be()) !== null : I(e, "delete", void 0, () => k.delete(e, t))), rt = async (e, t, n) => {
586
+ }, st = async (e, t) => (G(e, "delete", t), await K(e, t), T.schemaRegistry.hasSoftDelete(e) ? await Q(e, t, Ue()) !== null : I(e, "delete", void 0, () => k.delete(e, t))), ct = async (e, t, n) => {
591
587
  let r = F(e, t), i = T.schemaRegistry.versionColumn(e);
592
588
  if (i === void 0) {
593
- if (!V(e, r)) return I(e, "updateMany", r, () => k.updateMany(e, B(e, r), n));
589
+ if (!H(e, r)) return I(e, "updateMany", r, () => k.updateMany(e, B(e, r), n));
594
590
  let t = await k.query({
595
591
  table: e,
596
592
  predicate: n.where,
@@ -601,7 +597,7 @@ var Me = (e, t, n) => {
601
597
  }), i = 0;
602
598
  for (let a of t) {
603
599
  let t = a[D];
604
- t != null && (i += await I(e, "updateMany", r, () => k.updateMany(e, B(e, r, t), { where: y(n.where, b(D, t)) })));
600
+ t != null && (i += await I(e, "updateMany", r, () => k.updateMany(e, V(e, r, t), { where: y(n.where, b(D, t)) })));
605
601
  }
606
602
  return i;
607
603
  }
@@ -621,12 +617,12 @@ var Me = (e, t, n) => {
621
617
  let o = a, l = {
622
618
  ...s,
623
619
  [i]: o + 1
624
- }, u = await I(e, "updateMany", l, () => k.updateMany(e, B(e, l, r), { where: y(n.where, b(D, r), b(i, o)) }));
620
+ }, u = await I(e, "updateMany", l, () => k.updateMany(e, V(e, l, r), { where: y(n.where, b(D, r), b(i, o)) }));
625
621
  if (u > 0) {
626
622
  c += u;
627
623
  break;
628
624
  }
629
- if (t >= Ne) throw new re({
625
+ if (t >= Ie) throw new ae({
630
626
  table: e,
631
627
  id: r,
632
628
  expected: o,
@@ -643,25 +639,25 @@ var Me = (e, t, n) => {
643
639
  }
644
640
  }
645
641
  return c;
646
- }, it = async (e, t) => I(e, "deleteMany", void 0, () => k.deleteMany(e, t)), at = (e, t) => M != null && T.schemaRegistry.hasTenant(e) ? y(t, b("tenantId", M)) : t, ot = async (e, t, n) => rt(e, t, {
642
+ }, lt = async (e, t) => I(e, "deleteMany", void 0, () => k.deleteMany(e, t)), ut = (e, t) => M != null && T.schemaRegistry.hasTenant(e) ? y(t, b("tenantId", M)) : t, dt = async (e, t, n) => ct(e, t, {
647
643
  ...n,
648
- where: at(e, n.where)
649
- }), st = async (e, t) => it(e, {
644
+ where: ut(e, n.where)
645
+ }), ft = async (e, t) => lt(e, {
650
646
  ...t,
651
- where: at(e, t.where)
652
- }), $ = _({
653
- query: Je,
654
- updateMany: rt,
655
- deleteMany: it,
647
+ where: ut(e, t.where)
648
+ }), pt = ee({
649
+ query: $e,
650
+ updateMany: ct,
651
+ deleteMany: lt,
656
652
  delete: (e, t) => k.delete(e, t)
657
653
  }, {
658
654
  subject: T.subject,
659
655
  schemaRegistry: T.schemaRegistry,
660
656
  rowFilter: N
661
- }), ct = ((e, t, n) => t === void 0 ? $.updateWhere(e) : Z(e, t, n)), lt = ((e, t) => t === void 0 ? $.deleteWhere(e) : nt(e, t)), ut = async (e, t) => {
662
- let n = t.map((t) => P(e, t)), r = x(e), i = t.length >= 32 && r !== void 0 && T.schemaRegistry.insertSchema(e) === void 0 && T.schemaRegistry.crdtColumns(e).size === 0 && T.schemaRegistry.sealedColumns(e).size === 0 ? g(r) : void 0, a = n.map((t) => R(e, t, i)), o = z ? a.map((e) => Se(e, r, z)) : a, s = ce(o, r, f()), c = await I(e, "insertMany", n[0], () => k.insertMany(e, s));
663
- return H(e, c);
664
- }, dt = (e, t) => {
657
+ }), mt = ((e, t, n) => t === void 0 ? pt.updateWhere(e) : Q(e, t, n)), ht = ((e, t) => t === void 0 ? pt.deleteWhere(e) : st(e, t)), gt = async (e, t, n) => {
658
+ let r = t.map((t) => P(e, t)), i = x(e), a = t.length >= 32 && i !== void 0 && T.schemaRegistry.insertSchema(e) === void 0 && T.schemaRegistry.crdtColumns(e).size === 0 && T.schemaRegistry.sealedColumns(e).size === 0 ? v(i) : void 0, o = r.map((t) => R(e, t, a)), s = z ? o.map((e) => Te(e, i, z)) : o, c = ue(s, i, m()), l = await I(e, "insertMany", r[0], () => k.insertMany(e, c, n));
659
+ return U(e, l);
660
+ }, _t = (e, t) => {
665
661
  let n = Object.keys(t);
666
662
  if (n.length !== 1) throw Error(`store.links('${e}'): anchor must name exactly one source column, got [${n.join(", ")}]`);
667
663
  let r = n[0], i = t[r], a = x(e);
@@ -674,7 +670,7 @@ var Me = (e, t, n) => {
674
670
  sourceId: i,
675
671
  targetCol: o.find((e) => e !== r)
676
672
  };
677
- }, ft = (e, t) => {
673
+ }, vt = (e, t) => {
678
674
  let n = x(e);
679
675
  if (n === void 0) throw Error(`store.relationLinks('${e}'): unknown table (not registered) — declare it and its relation first`);
680
676
  let r = Object.entries(n.fields).filter(([, e]) => e.type === "reference").filter(([, e]) => {
@@ -687,8 +683,8 @@ var Me = (e, t, n) => {
687
683
  }).map(([e]) => e);
688
684
  if (r.length === 1) return r[0];
689
685
  throw r.length === 0 ? Error(`store.relationLinks('${e}'): no reference column points at '${t}' — the junction's reference() targets decide the anchor, and none matches.`) : Error(`store.relationLinks('${e}'): ${r.length} reference columns point at '${t}' [${r.join(", ")}] — a self-junction is ambiguous; use store.links('${e}', { <column>: id }) and name the side.`);
690
- }, pt = (e, t) => {
691
- let { sourceCol: n, sourceId: r, targetCol: i } = dt(e, t), a = async () => (await U({
686
+ }, yt = (e, t) => {
687
+ let { sourceCol: n, sourceId: r, targetCol: i } = _t(e, t), a = async () => (await W({
692
688
  table: e,
693
689
  predicate: b(n, r),
694
690
  order: [],
@@ -696,12 +692,12 @@ var Me = (e, t, n) => {
696
692
  skip: void 0,
697
693
  take: void 0
698
694
  })).map((e) => String(e[i])), o = async (t) => {
699
- t.length !== 0 && await ut(e, t.map((e) => ({
695
+ t.length !== 0 && await gt(e, t.map((e) => ({
700
696
  [n]: r,
701
697
  [i]: e
702
- })));
698
+ })), { returning: "none" });
703
699
  }, s = async (t) => {
704
- t.length !== 0 && await st(e, { where: y(b(n, r), me(i, t)) });
700
+ t.length !== 0 && await ft(e, { where: y(b(n, r), ge(i, t)) });
705
701
  };
706
702
  return {
707
703
  columns: {
@@ -725,7 +721,7 @@ var Me = (e, t, n) => {
725
721
  return await s(n), n;
726
722
  },
727
723
  setRows: async (t) => {
728
- let a = /* @__PURE__ */ new Map(), o = await U({
724
+ let a = /* @__PURE__ */ new Map(), o = await W({
729
725
  table: e,
730
726
  predicate: b(n, r),
731
727
  order: [],
@@ -747,27 +743,27 @@ var Me = (e, t, n) => {
747
743
  else {
748
744
  let s = a.get(t), c = {}, l = !1;
749
745
  for (let [e, t] of Object.entries(o)) e !== n && e !== i && s[e] !== t && (c[e] = t, l = !0);
750
- l && (d.push(t), await ot(e, c, { where: y(b(n, r), b(i, t)) }));
746
+ l && (d.push(t), await dt(e, c, { where: y(b(n, r), b(i, t)) }));
751
747
  }
752
- return f.length > 0 && await ut(e, f), {
748
+ return f.length > 0 && await gt(e, f, { returning: "none" }), {
753
749
  added: u,
754
750
  removed: l,
755
751
  updated: d
756
752
  };
757
753
  }
758
754
  };
759
- }, mt = async (e, t, n, r) => {
760
- let i = t[D] !== void 0 && t[D] !== null, a = P(e, t), o = Te(n), s = n;
761
- if (Ve(e, a, n.conflictColumns), typeof n.update == "function") {
755
+ }, bt = async (e, t, n, r) => {
756
+ let i = t[D] !== void 0 && t[D] !== null, a = P(e, t), o = Oe(n), s = n;
757
+ if (We(e, a, n.conflictColumns), typeof n.update == "function") {
762
758
  let t = n.update;
763
759
  s = {
764
760
  conflictColumns: n.conflictColumns,
765
761
  update: (n) => {
766
- let r = n.id, i = H(e, [n], r)[0], a = F(e, {
762
+ let r = n.id, i = U(e, [n], r)[0], a = F(e, {
767
763
  ...t(i),
768
764
  ...o
769
765
  });
770
- return B(e, L(e, a), r);
766
+ return V(e, L(e, a), r);
771
767
  }
772
768
  };
773
769
  } else {
@@ -780,7 +776,7 @@ var Me = (e, t, n) => {
780
776
  ...Object.fromEntries(r.filter((e) => e in t).map((e) => [e, t[e]])),
781
777
  ...o
782
778
  }, a = F(e, i);
783
- o = Te({
779
+ o = Oe({
784
780
  conflictColumns: n.conflictColumns,
785
781
  updateValues: {
786
782
  ...o,
@@ -788,74 +784,80 @@ var Me = (e, t, n) => {
788
784
  }
789
785
  });
790
786
  }
791
- let c = !i && typeof a[D] == "string" ? a[D] : void 0, l = V(e, a) || V(e, o) || r && c === void 0, u = l ? await m(k, e, a, n.conflictColumns) : void 0, d = l ? u === void 0 ? a[D] : u : void 0, f = l ? u === void 0 ? "inserted" : "updated" : void 0, p = await I(e, "upsert", a, () => k.upsert(e, B(e, R(e, a), d), {
787
+ let c = !i && typeof a[D] == "string" ? a[D] : void 0, l = H(e, a) || H(e, o) || r && c === void 0, u = l ? await g(k, e, a, n.conflictColumns) : void 0, d = l ? u === void 0 ? a[D] : u : void 0, f = l ? u === void 0 ? "inserted" : "updated" : void 0, p = await I(e, "upsert", a, () => k.upsert(e, B(e, R(e, a), d), {
792
788
  ...s,
793
789
  ...typeof n.update != "function" && (n.updateValues !== void 0 || Object.keys(o).length > 0) ? { updateValues: B(e, L(e, o), d) } : {}
794
790
  }));
795
791
  return {
796
- row: H(e, [p], d)[0],
792
+ row: U(e, [p], d)[0],
797
793
  outcome: f ?? (c !== void 0 && p[D] !== c ? "updated" : "inserted")
798
794
  };
799
- }, ht = async (e, t, n) => {
795
+ }, xt = async (e, t, n) => {
800
796
  let r = P(e, t);
801
- Ve(e, r, n.conflictColumns);
797
+ We(e, r, n.conflictColumns);
802
798
  let i = await I(e, "insertIgnore", r, () => k.insertIgnoreWithOutcome(e, B(e, R(e, r)), n));
803
799
  return {
804
- row: H(e, [i.row])[0],
800
+ row: U(e, [i.row])[0],
805
801
  outcome: i.outcome
806
802
  };
807
803
  };
808
804
  return {
809
- query: U,
805
+ query: W,
806
+ ...k.integrityQuery === void 0 ? {} : { integrityQuery: (e) => Qe(Ze({
807
+ ...e,
808
+ crossTenant: !1,
809
+ includeDeleted: !1,
810
+ includeExpired: !1
811
+ }, c), k.integrityQuery.bind(k), !1) },
810
812
  one: (async (e, t) => {
811
- let n = Pe(e), r = await U({
813
+ let n = Le(e), r = await W({
812
814
  ...n,
813
815
  take: 2
814
816
  }), i = r[0];
815
- if (i === void 0) throw v({
817
+ if (i === void 0) throw te({
816
818
  table: n.table,
817
819
  found: 0
818
820
  }, t);
819
- if (r.length > 1) throw v({
821
+ if (r.length > 1) throw te({
820
822
  table: n.table,
821
823
  found: r.length
822
824
  }, t);
823
825
  return i;
824
826
  }),
825
- first: ((e) => u({ query: U }, e)),
826
- maybeOne: ((e) => u({ query: U }, e)),
827
+ first: ((e) => f({ query: W }, e)),
828
+ maybeOne: ((e) => f({ query: W }, e)),
827
829
  insert: async (e, t) => {
828
830
  let n = P(e, t), r = await I(e, "insert", n, () => k.insert(e, B(e, R(e, n))));
829
- return H(e, [r])[0];
831
+ return U(e, [r])[0];
830
832
  },
831
- insertMany: (async (e, t) => ut(e, t)),
832
- links: pt,
833
- relationLinks: (e, t, n) => pt(e, { [ft(e, t)]: n }),
833
+ insertMany: (async (e, t, n) => gt(e, t, n)),
834
+ links: yt,
835
+ relationLinks: (e, t, n) => yt(e, { [vt(e, t)]: n }),
834
836
  patchJson: async (e, t, n, r, i) => {
835
- W(e, "patchJson", t), await G(e, t);
836
- let a = ge(t, n, F(e, ge(t, n, i), [n.split(".")[0]])), o = await I(e, "patchJson", a, () => k.patchJson(e, t, n, r, B(e, L(e, a), t)));
837
- return o === null ? null : H(e, [o], t)[0];
837
+ G(e, "patchJson", t), await K(e, t);
838
+ let a = ve(t, n, F(e, ve(t, n, i), [n.split(".")[0]])), o = await I(e, "patchJson", a, () => k.patchJson(e, t, n, r, V(e, L(e, a), t)));
839
+ return o === null ? null : U(e, [o], t)[0];
838
840
  },
839
- select: $.select,
840
- update: ct,
841
- delete: lt,
842
- applyDefined: Fe,
843
- hardDelete: async (e, t) => (W(e, "hardDelete", t), await G(e, t), I(e, "hardDelete", void 0, () => k.delete(e, t))),
844
- updateMany: ot,
845
- deleteMany: st,
846
- upsert: async (e, t, n) => (await mt(e, t, n, !1)).row,
847
- upsertWithOutcome: (e, t, n) => mt(e, t, n, !0),
848
- insertIgnore: async (e, t, n) => (await ht(e, t, n)).row,
849
- insertIgnoreWithOutcome: (e, t, n) => ht(e, t, n),
841
+ select: pt.select,
842
+ update: mt,
843
+ delete: ht,
844
+ applyDefined: Re,
845
+ hardDelete: async (e, t) => (G(e, "hardDelete", t), await K(e, t), I(e, "hardDelete", void 0, () => k.delete(e, t))),
846
+ updateMany: dt,
847
+ deleteMany: ft,
848
+ upsert: async (e, t, n) => (await bt(e, t, n, !1)).row,
849
+ upsertWithOutcome: (e, t, n) => bt(e, t, n, !0),
850
+ insertIgnore: async (e, t, n) => (await xt(e, t, n)).row,
851
+ insertIgnoreWithOutcome: (e, t, n) => xt(e, t, n),
850
852
  transactional: async (e) => {
851
853
  let t = await k.transactional(async (t) => {
852
854
  let n = [];
853
- return t[K] = n, t[q] = /* @__PURE__ */ new Map(), {
854
- result: await e(Re(t, T)),
855
+ return t[q] = n, t[J] = /* @__PURE__ */ new Map(), {
856
+ result: await e(Ve(t, T)),
855
857
  jobs: n
856
858
  };
857
859
  });
858
- for (let e of t.jobs) await Z(e.table, e.pk, e.patch);
860
+ for (let e of t.jobs) await Q(e.table, e.pk, e.patch);
859
861
  return t.result;
860
862
  },
861
863
  ...k.raw ? { raw: ((e, r) => (n(Object.freeze({
@@ -866,8 +868,8 @@ var Me = (e, t, n) => {
866
868
  onChange: (e) => k.onChange(e),
867
869
  injectExternalChange: (e) => k.injectExternalChange(e),
868
870
  ...k.changeScope === void 0 ? {} : { changeScope: k.changeScope },
869
- ...k[K] === void 0 ? {} : { [K]: k[K] },
870
- ...J(k) === void 0 ? {} : { [q]: J(k) }
871
+ ...k[q] === void 0 ? {} : { [q]: k[q] },
872
+ ...Y(k) === void 0 ? {} : { [J]: Y(k) }
871
873
  };
872
874
  }, A = "VoltroTransactionReadConflict", j = class extends Error {
873
875
  conflict;
@@ -877,4 +879,4 @@ var Me = (e, t, n) => {
877
879
  }
878
880
  }, M = (e) => typeof e == "object" && !!e && e.name === "VoltroTransactionReadConflict" && "conflict" in e, N = Symbol.for("@voltro/runtime:tx-read-versions");
879
881
  //#endregion
880
- export { A as TRANSACTION_READ_CONFLICT_NAME, N as TX_READ_VERSIONS_KEY, j as TransactionReadConflict, Le as actingUserId, Fe as applyDefined, M as isTransactionReadConflict, Re as wrapStoreWithMixinBehaviour };
882
+ export { A as TRANSACTION_READ_CONFLICT_NAME, N as TX_READ_VERSIONS_KEY, j as TransactionReadConflict, Be as actingUserId, Re as applyDefined, M as isTransactionReadConflict, Ve as wrapStoreWithMixinBehaviour };