@voltro/database 0.62.3 → 0.64.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.
@@ -221,19 +221,21 @@ var r = (e) => {
221
221
  enumValues: t
222
222
  })
223
223
  };
224
- }, oe = () => c("boolean"), se = () => c("timestamp"), ce = () => c("date"), le = () => c("json"), ue = () => c("bytes"), d = () => new s({
224
+ }, oe = () => c("boolean"), se = () => c("timestamp"), ce = () => c("date"), le = () => c("json"), ue = () => c("bytes"), de = () => new s({
225
225
  type: "bytes",
226
226
  nullable: !0,
227
227
  unique: !1,
228
228
  hasDefault: !1,
229
229
  crdtManaged: !0
230
- }), de = () => new s({
230
+ }), fe = () => new s({
231
231
  type: "bytes",
232
232
  nullable: !0,
233
233
  unique: !1,
234
234
  hasDefault: !1,
235
235
  crdtManaged: !0
236
- }), fe = (e, t) => new s({
236
+ }), d = () => {
237
+ throw Error("selfReference(): the target is resolved by table() — a column built with selfReference() must be declared inside a table({ … }) literal, not read before the table exists");
238
+ }, pe = (e) => f(d, e), f = (e, t) => new s({
237
239
  type: "reference",
238
240
  nullable: !1,
239
241
  unique: !1,
@@ -241,15 +243,16 @@ var r = (e) => {
241
243
  references: e,
242
244
  onDelete: t?.onDelete ?? "restrict",
243
245
  refOnUpdate: t?.onUpdate ?? "noAction",
246
+ ...t?.onSoftDelete === void 0 ? {} : { refOnSoftDelete: t.onSoftDelete },
244
247
  fkAutoIndex: t?.index ?? !0,
245
248
  ...t?.orphanPolicy ? { orphanPolicy: t.orphanPolicy } : {}
246
- }), pe = () => new s({
249
+ }), me = () => new s({
247
250
  type: "text",
248
251
  nullable: !0,
249
252
  unique: !1,
250
253
  hasDefault: !1,
251
254
  dropped: !0
252
- }), me = (e, t) => {
255
+ }), he = (e, t) => {
253
256
  if (!Number.isInteger(e) || e <= 0) throw Error(`vector(${String(e)}): dimension must be a positive integer (the embedding length, e.g. vector(1536)).`);
254
257
  return new s({
255
258
  type: "vector",
@@ -259,13 +262,13 @@ var r = (e) => {
259
262
  vectorDim: e,
260
263
  vectorPrecision: t?.precision ?? "float32"
261
264
  });
262
- }, he = (e) => new s({
265
+ }, ge = (e) => new s({
263
266
  type: "array",
264
267
  nullable: !1,
265
268
  unique: !1,
266
269
  hasDefault: !1,
267
270
  arrayElement: e.__definition().type
268
- }), ge = () => c("interval"), _e = (e, t = 4326) => new s({
271
+ }), _e = () => c("interval"), ve = (e, t = 4326) => new s({
269
272
  type: "text",
270
273
  nullable: !1,
271
274
  unique: !1,
@@ -275,7 +278,7 @@ var r = (e) => {
275
278
  geomKind: e,
276
279
  srid: t
277
280
  }
278
- }), ve = (e, t = 4326) => new s({
281
+ }), ye = (e, t = 4326) => new s({
279
282
  type: "text",
280
283
  nullable: !1,
281
284
  unique: !1,
@@ -285,51 +288,51 @@ var r = (e) => {
285
288
  geomKind: e,
286
289
  srid: t
287
290
  }
288
- }), ye = (e) => new s({
291
+ }), be = (e) => new s({
289
292
  type: "raw",
290
293
  nullable: !1,
291
294
  unique: !1,
292
295
  hasDefault: !1,
293
296
  rawDdl: e
294
- }), f = (e) => {
297
+ }), p = (e) => {
295
298
  let t = {};
296
299
  for (let [n, r] of Object.entries(e)) t[n] = r.__definition();
297
300
  return t;
298
- }, p = /* @__PURE__ */ new WeakMap(), m = (e) => typeof e == "object" && e ? p.get(e) : void 0, be = (e, t = {}) => {
301
+ }, m = /* @__PURE__ */ new WeakMap(), h = (e) => typeof e == "object" && e ? m.get(e) : void 0, xe = (e, t = {}) => {
299
302
  let n = l();
300
- return p.set(n, {
303
+ return m.set(n, {
301
304
  target: e,
302
305
  orphanPolicy: t.orphanPolicy ?? "keep",
303
306
  onSoftDelete: t.onSoftDelete ?? !1
304
307
  }), n;
305
- }, h = /* @__PURE__ */ new Map(), xe = (e, t) => {
308
+ }, g = /* @__PURE__ */ new Map(), Se = (e, t) => {
306
309
  if (t.from === t.to) throw Error(`declareEnumRename('${e}'): \`from\` and \`to\` are both '${t.from}' — a rename must change the value.`);
307
- let n = h.get(e) ?? [];
310
+ let n = g.get(e) ?? [];
308
311
  for (let r of n) {
309
312
  if (r.from === t.from && r.to === t.to) return;
310
313
  if (r.from === t.from && r.to !== t.to) throw Error(`declareEnumRename('${e}'): value '${t.from}' is already declared as renamed to '${r.to}', cannot also rename it to '${t.to}'.`);
311
314
  }
312
- n.push(t), h.set(e, n);
313
- }, Se = (e) => h.get(e) ?? [], Ce = () => h, we = () => {
314
- h.clear();
315
- }, Te = 63, Ee = 60, g = [], _ = (e) => {
316
- g.includes(e) || g.push(e);
317
- }, De = () => {
318
- let e = g.slice();
319
- return g.length = 0, e;
320
- }, Oe = /^[a-zA-Z_][a-zA-Z0-9_]*$/, v = (e, t) => {
315
+ n.push(t), g.set(e, n);
316
+ }, Ce = (e) => g.get(e) ?? [], we = () => g, Te = () => {
317
+ g.clear();
318
+ }, Ee = 63, De = 60, _ = [], v = (e) => {
319
+ _.includes(e) || _.push(e);
320
+ }, Oe = () => {
321
+ let e = _.slice();
322
+ return _.length = 0, e;
323
+ }, ke = /^[a-zA-Z_][a-zA-Z0-9_]*$/, y = (e, t) => {
321
324
  if (t.length === 0) throw Error(`${e} cannot be empty.`);
322
- if (!Oe.test(t)) throw Error(`${e} '${t}' contains characters outside [A-Za-z0-9_] or starts with a digit. Dialect-portable identifiers must match /^[a-zA-Z_][a-zA-Z0-9_]*$/.`);
323
- }, y = (e) => {
324
- if (v("table name", e), e.length > 63) throw Error(`table name '${e}' is ${e.length} chars — exceeds the 63-byte cross-dialect limit (Postgres floor). Shorten the name; long table names also cascade into auto-named indexes and FK constraints that would themselves exceed the limit.`);
325
- e.length > 60 && _(`table name '${e}' is ${e.length} chars — ${63 - e.length} from the Postgres 63-byte limit. Auto-named indexes on this table will run out of room fast.`);
326
- }, b = (e, t) => {
327
- if (v("column name", t), t.length > 63) throw Error(`column '${t}' on table '${e}' is ${t.length} chars — exceeds the 63-byte cross-dialect limit (Postgres floor). Rename it.`);
328
- t.length > 60 && _(`column '${t}' on table '${e}' is ${t.length} chars — close to the 63-byte limit.`);
329
- }, x = (e, t, n, r) => {
330
- if (v("index name", t), t.length > 63) throw Error(n ? `auto-named index '${t}' on table '${e}' is ${t.length} chars — exceeds the 63-byte cross-dialect limit (Postgres floor). Supply an explicit short name: .index('<shortName>', ${JSON.stringify([...r])}).` : `index name '${t}' on table '${e}' is ${t.length} chars — exceeds the 63-byte cross-dialect limit (Postgres floor). Shorten it.`);
331
- t.length > 60 && _(`index '${t}' on table '${e}' is ${t.length} chars — ${63 - t.length} from the 63-byte limit. ${n ? `Consider .index('<shortName>', ${JSON.stringify([...r])}) before it grows.` : ""}`);
332
- }, S = (e, t) => {
325
+ if (!ke.test(t)) throw Error(`${e} '${t}' contains characters outside [A-Za-z0-9_] or starts with a digit. Dialect-portable identifiers must match /^[a-zA-Z_][a-zA-Z0-9_]*$/.`);
326
+ }, b = (e) => {
327
+ if (y("table name", e), e.length > 63) throw Error(`table name '${e}' is ${e.length} chars — exceeds the 63-byte cross-dialect limit (Postgres floor). Shorten the name; long table names also cascade into auto-named indexes and FK constraints that would themselves exceed the limit.`);
328
+ e.length > 60 && v(`table name '${e}' is ${e.length} chars — ${63 - e.length} from the Postgres 63-byte limit. Auto-named indexes on this table will run out of room fast.`);
329
+ }, x = (e, t) => {
330
+ if (y("column name", t), t.length > 63) throw Error(`column '${t}' on table '${e}' is ${t.length} chars — exceeds the 63-byte cross-dialect limit (Postgres floor). Rename it.`);
331
+ t.length > 60 && v(`column '${t}' on table '${e}' is ${t.length} chars — close to the 63-byte limit.`);
332
+ }, S = (e, t, n, r) => {
333
+ if (y("index name", t), t.length > 63) throw Error(n ? `auto-named index '${t}' on table '${e}' is ${t.length} chars — exceeds the 63-byte cross-dialect limit (Postgres floor). Supply an explicit short name: .index('<shortName>', ${JSON.stringify([...r])}).` : `index name '${t}' on table '${e}' is ${t.length} chars — exceeds the 63-byte cross-dialect limit (Postgres floor). Shorten it.`);
334
+ t.length > 60 && v(`index '${t}' on table '${e}' is ${t.length} chars — ${63 - t.length} from the 63-byte limit. ${n ? `Consider .index('<shortName>', ${JSON.stringify([...r])}) before it grows.` : ""}`);
335
+ }, C = (e, t) => {
333
336
  if (e.length === 0) throw Error(`typeid prefix on table '${t.tableName}' cannot be empty.`);
334
337
  if (!/^[a-z][a-z0-9_]*$/.test(e)) {
335
338
  let n = t.kind === "derived" ? "the derived prefix doesn't match typeid's required shape — supply an explicit one via id({ prefix: '...' })." : "the prefix must match typeid's required shape /^[a-z][a-z0-9_]*$/.";
@@ -339,44 +342,44 @@ var r = (e) => {
339
342
  let n = t.kind === "derived" ? "shorten the table name, or supply an explicit short prefix via id({ prefix: '...' })." : "pick a shorter prefix.";
340
343
  throw Error(`typeid prefix '${e}' on table '${t.tableName}' is ${e.length} chars — exceeds the 63-byte limit; ${n}`);
341
344
  }
342
- e.length > 60 && _(`typeid prefix '${e}' on table '${t.tableName}' is ${e.length} chars — close to the 63-byte limit. Generated ids will be even longer (prefix + '_' + 26).`);
343
- }, ke = 1704067200000n, Ae = 10n, C = 12n, w = (1n << Ae) - 1n, je = (1n << C) - 1n, Me = C, Ne = 22n, Pe = () => {
345
+ e.length > 60 && v(`typeid prefix '${e}' on table '${t.tableName}' is ${e.length} chars — close to the 63-byte limit. Generated ids will be even longer (prefix + '_' + 26).`);
346
+ }, Ae = 1704067200000n, je = 10n, w = 12n, T = (1n << je) - 1n, Me = (1n << w) - 1n, Ne = w, Pe = 22n, Fe = () => {
344
347
  let e = process.env.SNOWFLAKE_MACHINE_ID;
345
348
  if (e === void 0 || e === "") return 0n;
346
349
  let t = BigInt(e);
347
- if (t < 0n || t > w) throw Error(`SNOWFLAKE_MACHINE_ID out of range: ${e}. Must be 0..${w}.`);
350
+ if (t < 0n || t > T) throw Error(`SNOWFLAKE_MACHINE_ID out of range: ${e}. Must be 0..${T}.`);
348
351
  return t;
349
- }, T = () => ({
352
+ }, E = () => ({
350
353
  lastMs: 0n,
351
354
  sequence: 0n,
352
- machineId: Pe()
353
- }), E, Fe = () => (E === void 0 && (E = T()), E), Ie = () => {
354
- E = T();
355
- }, D = () => BigInt(Date.now()), Le = (e) => {
356
- let t = D();
357
- for (; t <= e;) t = D();
355
+ machineId: Fe()
356
+ }), D, Ie = () => (D === void 0 && (D = E()), D), Le = () => {
357
+ D = E();
358
+ }, O = () => BigInt(Date.now()), Re = (e) => {
359
+ let t = O();
360
+ for (; t <= e;) t = O();
358
361
  return t;
359
- }, O = () => {
360
- let e = Fe(), t = D();
361
- t === e.lastMs ? (e.sequence = e.sequence + 1n & je, e.sequence === 0n && (t = Le(e.lastMs), e.lastMs = t)) : (e.sequence = 0n, e.lastMs = t);
362
- let n = t - ke;
362
+ }, k = () => {
363
+ let e = Ie(), t = O();
364
+ t === e.lastMs ? (e.sequence = e.sequence + 1n & Me, e.sequence === 0n && (t = Re(e.lastMs), e.lastMs = t)) : (e.sequence = 0n, e.lastMs = t);
365
+ let n = t - Ae;
363
366
  if (n < 0n) throw Error("Snowflake timestamp before configured epoch (2024-01-01). System clock is wrong.");
364
- return (n << Ne | e.machineId << Me | e.sequence).toString();
365
- }, k = (e) => {
367
+ return (n << Pe | e.machineId << Ne | e.sequence).toString();
368
+ }, A = (e) => {
366
369
  let t = e.toLowerCase();
367
370
  if (t.startsWith("_")) throw Error(`cannot derive a typeid prefix for table '${e}' (table names starting with '_' are not valid typeid prefixes). Pick an explicit prefix via id({ prefix: '...' }) or use a different scheme like id({ scheme: 'numeric' }) for internal tables.`);
368
371
  if (!/^[a-z][a-z0-9_]*$/.test(t)) throw Error(`cannot derive a typeid prefix from table name '${e}' (must match [a-z][a-z0-9_]*). Pick an explicit prefix via id({ prefix: '...' }).`);
369
372
  let n = t.endsWith("ies") && t.length > 3 ? t.slice(0, -3) + "y" : t.endsWith("ses") || t.endsWith("xes") || t.endsWith("zes") || t.endsWith("shes") || t.endsWith("ches") ? t.slice(0, -2) : t.endsWith("s") && t.length > 1 ? t.slice(0, -1) : t;
370
- return S(n, {
373
+ return C(n, {
371
374
  kind: "derived",
372
375
  tableName: e
373
376
  }), n;
374
- }, A = (e, t) => {
377
+ }, j = (e, t) => {
375
378
  if (e === void 0) return {
376
379
  kind: "typeid",
377
- prefix: k(t)
380
+ prefix: A(t)
378
381
  };
379
- if ("prefix" in e && !("scheme" in e)) return S(e.prefix, {
382
+ if ("prefix" in e && !("scheme" in e)) return C(e.prefix, {
380
383
  kind: "explicit",
381
384
  tableName: t
382
385
  }), {
@@ -386,8 +389,8 @@ var r = (e) => {
386
389
  if (!("scheme" in e)) throw Error("invalid id() options: no scheme or prefix");
387
390
  switch (e.scheme) {
388
391
  case "typeid": {
389
- let n = e.prefix ?? k(t);
390
- return e.prefix !== void 0 && S(e.prefix, {
392
+ let n = e.prefix ?? A(t);
393
+ return e.prefix !== void 0 && C(e.prefix, {
391
394
  kind: "explicit",
392
395
  tableName: t
393
396
  }), {
@@ -403,22 +406,22 @@ var r = (e) => {
403
406
  generate: e.generate
404
407
  };
405
408
  }
406
- }, Re = (e, r) => {
409
+ }, ze = (e, r) => {
407
410
  switch (e.kind) {
408
411
  case "typeid": return t(e.prefix).toString();
409
412
  case "ulid": return n();
410
413
  case "numeric": return null;
411
- case "snowflake": return O();
414
+ case "snowflake": return k();
412
415
  case "custom": return e.generate(r);
413
416
  }
414
- }, j = (e) => ({
415
- fields: f(e.fields),
417
+ }, M = (e) => ({
418
+ fields: p(e.fields),
416
419
  ...e.id === void 0 ? {} : { id: e.id },
417
420
  ...e.requires === void 0 ? {} : { requires: e.requires },
418
421
  ...e.indexes === void 0 ? {} : { indexes: e.indexes },
419
422
  ...e.behaviors === void 0 ? {} : { behaviors: e.behaviors },
420
423
  ...e.policies === void 0 ? {} : { policies: e.policies }
421
- }), ze = j, M = (e) => {
424
+ }), Be = M, N = (e) => {
422
425
  let t = /* @__PURE__ */ new Set(), n = [], r = (e) => {
423
426
  let i = e.id ?? e;
424
427
  if (!t.has(i)) {
@@ -428,7 +431,7 @@ var r = (e) => {
428
431
  };
429
432
  for (let t of e) r(t);
430
433
  return n;
431
- }, Be = (e, ...t) => {
434
+ }, Ve = (e, ...t) => {
432
435
  if (t.length === 0) throw Error(`jsonIndex("${e}"): at least one path segment is required`);
433
436
  let n = (r) => ({
434
437
  jsonPath: {
@@ -439,14 +442,14 @@ var r = (e) => {
439
442
  numeric: () => n(!0)
440
443
  });
441
444
  return n(!1);
442
- }, Ve = (e = "cosine", t = "float32") => {
445
+ }, He = (e = "cosine", t = "float32") => {
443
446
  let n = t === "half" ? "halfvec" : "vector";
444
447
  switch (e) {
445
448
  case "cosine": return `${n}_cosine_ops`;
446
449
  case "l2": return `${n}_l2_ops`;
447
450
  case "inner": return `${n}_ip_ops`;
448
451
  }
449
- }, He = [
452
+ }, Ue = [
450
453
  "id",
451
454
  "tenantId",
452
455
  "createdAt",
@@ -455,7 +458,7 @@ var r = (e) => {
455
458
  "updatedBy",
456
459
  "deletedAt",
457
460
  "deletedBy"
458
- ], N = (e) => e.id ?? `<anonymous mixin: ${Object.keys(e.fields).join(", ")}>`, P = (e, t) => `${e}_${t.join("_")}_idx`, Ue = (e, t) => `${e}_${t.join("_")}_uq`, F = (e, t, n, r, i) => {
461
+ ], P = (e) => e.id ?? `<anonymous mixin: ${Object.keys(e.fields).join(", ")}>`, F = (e, t) => `${e}_${t.join("_")}_idx`, We = (e, t) => `${e}_${t.join("_")}_uq`, I = (e, t, n, r, i) => {
459
462
  if (n !== "hnsw") return;
460
463
  if (r.length !== 1) throw Error(`hnsw index '${t}' on table '${e}' must cover exactly one vector column — got ${r.length} fields. pgvector's HNSW access method indexes a single vector column.`);
461
464
  let a = r[0];
@@ -463,14 +466,14 @@ var r = (e) => {
463
466
  let o = i[a];
464
467
  if (o === void 0) throw Error(`hnsw index '${t}' on table '${e}' references unknown column '${a}'.`);
465
468
  if (o.type !== "vector") throw Error(`hnsw index '${t}' on table '${e}' requires a vector() column — column '${a}' is '${o.type}'. HNSW is the pgvector approximate-nearest-neighbour method and only applies to vectors.`);
466
- }, We = (e, t) => {
469
+ }, Ge = (e, t) => {
467
470
  let n;
468
471
  for (let [r, i] of Object.entries(e)) i.type === "id" && i.idScheme === void 0 && (n === void 0 && (n = { ...e }), n[r] = {
469
472
  ...i,
470
- idScheme: A(i.idSchemeInput, t)
473
+ idScheme: j(i.idSchemeInput, t)
471
474
  });
472
475
  return n ?? e;
473
- }, I = (t) => {
476
+ }, L = (t) => {
474
477
  let n = t.appliedPrimaryKey ?? [];
475
478
  return {
476
479
  tableName: t.tableName,
@@ -489,8 +492,8 @@ var r = (e) => {
489
492
  ...t.validatePatchSchema === void 0 ? {} : { validatePatchSchema: t.validatePatchSchema },
490
493
  fullTextIndex: ((e, n, r) => {
491
494
  if (n.length === 0) throw Error(`fullTextIndex '${e}' on '${t.tableName}' has no columns.`);
492
- if (x(t.tableName, e, !1, n), t.appliedFullText.some((t) => t.name === e)) throw Error(`duplicate full-text index '${e}' on table '${t.tableName}'.`);
493
- return I({
495
+ if (S(t.tableName, e, !1, n), t.appliedFullText.some((t) => t.name === e)) throw Error(`duplicate full-text index '${e}' on table '${t.tableName}'.`);
496
+ return L({
494
497
  ...t,
495
498
  tableName: t.tableName,
496
499
  fields: t.fields,
@@ -511,27 +514,27 @@ var r = (e) => {
511
514
  });
512
515
  }),
513
516
  with: ((...e) => {
514
- let n = M(e), r = { ...t.fields }, i = /* @__PURE__ */ new Map();
517
+ let n = N(e), r = { ...t.fields }, i = /* @__PURE__ */ new Map();
515
518
  for (let e of Object.keys(r)) i.set(e, {
516
519
  id: "<table>",
517
520
  fields: {}
518
521
  });
519
522
  for (let e of n) for (let [n, a] of Object.entries(e.fields)) {
520
523
  let o = i.get(n);
521
- if (o !== void 0) throw Error(`mixin collision on column '${n}' in table '${t.tableName}': '${N(o)}' and '${N(e)}' both define it. If they're the same mixin reached via different paths, set a shared 'id' on both. If they're genuinely different concerns, rename one of the columns.`);
522
- b(t.tableName, n), r[n] = a, i.set(n, e);
524
+ if (o !== void 0) throw Error(`mixin collision on column '${n}' in table '${t.tableName}': '${P(o)}' and '${P(e)}' both define it. If they're the same mixin reached via different paths, set a shared 'id' on both. If they're genuinely different concerns, rename one of the columns.`);
525
+ x(t.tableName, n), r[n] = a, i.set(n, e);
523
526
  }
524
527
  let a = [...t.appliedIndexes];
525
528
  for (let e of n) for (let n of e.indexes ?? []) {
526
- let e = n.name ?? P(t.tableName, n.fields);
527
- a.some((t) => t.name === e) || (x(t.tableName, e, n.name === void 0, n.fields), F(t.tableName, e, n.kind, n.fields, r), a.push({
529
+ let e = n.name ?? F(t.tableName, n.fields);
530
+ a.some((t) => t.name === e) || (S(t.tableName, e, n.name === void 0, n.fields), I(t.tableName, e, n.kind, n.fields, r), a.push({
528
531
  name: e,
529
532
  fields: n.fields,
530
533
  ...n.kind === void 0 ? {} : { kind: n.kind },
531
534
  ...n.kindOptions === void 0 ? {} : { kindOptions: n.kindOptions }
532
535
  }));
533
536
  }
534
- return I({
537
+ return L({
535
538
  ...t,
536
539
  tableName: t.tableName,
537
540
  fields: r,
@@ -548,10 +551,10 @@ var r = (e) => {
548
551
  }),
549
552
  index: ((...e) => {
550
553
  let n, r, i, a = Array.isArray(e[0]);
551
- if (a ? (r = e[0], i = e[1], n = P(t.tableName, r)) : (n = e[0], r = e[1], i = e[2]), r.length === 0) throw Error(`index '${n}' on table '${t.tableName}' has no fields — an index must cover at least one column.`);
554
+ if (a ? (r = e[0], i = e[1], n = F(t.tableName, r)) : (n = e[0], r = e[1], i = e[2]), r.length === 0) throw Error(`index '${n}' on table '${t.tableName}' has no fields — an index must cover at least one column.`);
552
555
  let o = r.filter((e) => typeof e == "string");
553
- if (x(t.tableName, n, a, o), F(t.tableName, n, i?.kind, r, t.fields), t.appliedIndexes.some((e) => e.name === n)) throw e.length === 1 ? Error(`duplicate auto-named index '${n}' on table '${t.tableName}' — you've called .index(${JSON.stringify(r)}) twice. Pass an explicit name to the second one if both are intended (rare).`) : Error(`duplicate index '${n}' on table '${t.tableName}': each index name must be unique within a table.`);
554
- return I({
556
+ if (S(t.tableName, n, a, o), I(t.tableName, n, i?.kind, r, t.fields), t.appliedIndexes.some((e) => e.name === n)) throw e.length === 1 ? Error(`duplicate auto-named index '${n}' on table '${t.tableName}' — you've called .index(${JSON.stringify(r)}) twice. Pass an explicit name to the second one if both are intended (rare).`) : Error(`duplicate index '${n}' on table '${t.tableName}': each index name must be unique within a table.`);
557
+ return L({
555
558
  ...t,
556
559
  tableName: t.tableName,
557
560
  fields: t.fields,
@@ -575,8 +578,8 @@ var r = (e) => {
575
578
  expressionIndex: ((e, n, r) => {
576
579
  if (n.length === 0) throw Error(`expressionIndex '${e}' on table '${t.tableName}' has no fields — an index must cover at least one column or expression.`);
577
580
  let i = n.filter((e) => typeof e == "string");
578
- if (x(t.tableName, e, !1, i), F(t.tableName, e, r?.kind, n, t.fields), t.appliedIndexes.some((t) => t.name === e)) throw Error(`duplicate index '${e}' on table '${t.tableName}': each index name must be unique within a table.`);
579
- return I({
581
+ if (S(t.tableName, e, !1, i), I(t.tableName, e, r?.kind, n, t.fields), t.appliedIndexes.some((t) => t.name === e)) throw Error(`duplicate index '${e}' on table '${t.tableName}': each index name must be unique within a table.`);
582
+ return L({
580
583
  ...t,
581
584
  tableName: t.tableName,
582
585
  fields: t.fields,
@@ -599,9 +602,9 @@ var r = (e) => {
599
602
  }),
600
603
  unique: ((...e) => {
601
604
  let n, r, i, a = Array.isArray(e[0]);
602
- if (a ? (r = e[0], i = e[1], n = Ue(t.tableName, r)) : (n = e[0], r = e[1], i = e[2]), r.length === 0) throw Error(`unique '${n}' on table '${t.tableName}' has no fields — a UNIQUE constraint must cover at least one column.`);
603
- if (x(t.tableName, n, a, r), t.appliedUniques.some((e) => e.name === n)) throw Error(a ? `duplicate auto-named UNIQUE '${n}' on table '${t.tableName}' — you've called .unique(${JSON.stringify(r)}) twice. Pass an explicit name to the second one if both are intended (very rare).` : `duplicate UNIQUE '${n}' on table '${t.tableName}': each constraint name must be unique within a table.`);
604
- return I({
605
+ if (a ? (r = e[0], i = e[1], n = We(t.tableName, r)) : (n = e[0], r = e[1], i = e[2]), r.length === 0) throw Error(`unique '${n}' on table '${t.tableName}' has no fields — a UNIQUE constraint must cover at least one column.`);
606
+ if (S(t.tableName, n, a, r), t.appliedUniques.some((e) => e.name === n)) throw Error(a ? `duplicate auto-named UNIQUE '${n}' on table '${t.tableName}' — you've called .unique(${JSON.stringify(r)}) twice. Pass an explicit name to the second one if both are intended (very rare).` : `duplicate UNIQUE '${n}' on table '${t.tableName}': each constraint name must be unique within a table.`);
607
+ return L({
605
608
  ...t,
606
609
  tableName: t.tableName,
607
610
  fields: t.fields,
@@ -622,10 +625,10 @@ var r = (e) => {
622
625
  }),
623
626
  uniqueActive: ((...e) => {
624
627
  let n, r, i, a = Array.isArray(e[0]);
625
- if (a ? (r = e[0], i = e[1], n = P(t.tableName, r)) : (n = e[0], r = e[1], i = e[2]), r.length === 0) throw Error(`uniqueActive '${n}' on table '${t.tableName}' has no fields — a partial UNIQUE must cover at least one column.`);
626
- if (x(t.tableName, n, a, r), t.appliedIndexes.some((e) => e.name === n)) throw Error(`duplicate index '${n}' on table '${t.tableName}': each index name must be unique within a table (uniqueActive shares the index namespace).`);
628
+ if (a ? (r = e[0], i = e[1], n = F(t.tableName, r)) : (n = e[0], r = e[1], i = e[2]), r.length === 0) throw Error(`uniqueActive '${n}' on table '${t.tableName}' has no fields — a partial UNIQUE must cover at least one column.`);
629
+ if (S(t.tableName, n, a, r), t.appliedIndexes.some((e) => e.name === n)) throw Error(`duplicate index '${n}' on table '${t.tableName}': each index name must be unique within a table (uniqueActive shares the index namespace).`);
627
630
  let o = i?.where ?? "\"deletedAt\" IS NULL";
628
- return I({
631
+ return L({
629
632
  ...t,
630
633
  tableName: t.tableName,
631
634
  fields: t.fields,
@@ -647,8 +650,8 @@ var r = (e) => {
647
650
  }),
648
651
  check: ((e, n) => {
649
652
  if (n.trim().length === 0) throw Error(`CHECK '${e}' on table '${t.tableName}' has an empty expression.`);
650
- if (x(t.tableName, e, !1, []), t.appliedChecks.some((t) => t.name === e)) throw Error(`duplicate CHECK '${e}' on table '${t.tableName}': each constraint name must be unique within a table.`);
651
- return I({
653
+ if (S(t.tableName, e, !1, []), t.appliedChecks.some((t) => t.name === e)) throw Error(`duplicate CHECK '${e}' on table '${t.tableName}': each constraint name must be unique within a table.`);
654
+ return L({
652
655
  ...t,
653
656
  tableName: t.tableName,
654
657
  fields: t.fields,
@@ -670,7 +673,7 @@ var r = (e) => {
670
673
  if (e.trim().length === 0) throw Error(`rule on table '${t.tableName}' has an empty name.`);
671
674
  let i = t.appliedRules ?? [];
672
675
  if (i.some((t) => t.name === e)) throw Error(`duplicate rule '${e}' on table '${t.tableName}': each rule name must be unique within a table.`);
673
- return I({
676
+ return L({
674
677
  ...t,
675
678
  appliedRules: [...i, {
676
679
  name: e,
@@ -681,7 +684,7 @@ var r = (e) => {
681
684
  }),
682
685
  renamedFrom: ((e) => {
683
686
  if (e === t.tableName) throw Error(`renamedFrom('${e}') on table '${t.tableName}' names the table itself — drop the marker, there is nothing to rename.`);
684
- return y(e), I({
687
+ return b(e), L({
685
688
  ...t,
686
689
  previousTableName: e
687
690
  });
@@ -696,7 +699,7 @@ var r = (e) => {
696
699
  }
697
700
  if (n.length > 0) throw Error(`primaryKey([...]) declared twice on table '${t.tableName}'.`);
698
701
  for (let [n, r] of Object.entries(t.fields)) if (r.type === "id" && !e.includes(n)) throw Error(`primaryKey([...]) on table '${t.tableName}' conflicts with the id() column '${n}'. A composite primary key IS the key — drop the id() column, or include '${n}' in the composite key.`);
699
- return I({
702
+ return L({
700
703
  ...t,
701
704
  tableName: t.tableName,
702
705
  fields: t.fields,
@@ -711,7 +714,7 @@ var r = (e) => {
711
714
  ...t.validatePatchSchema === void 0 ? {} : { validatePatchSchema: t.validatePatchSchema }
712
715
  });
713
716
  }),
714
- nonReactive: (() => I({
717
+ nonReactive: (() => L({
715
718
  ...t,
716
719
  tableName: t.tableName,
717
720
  fields: t.fields,
@@ -725,7 +728,7 @@ var r = (e) => {
725
728
  ...t.insertSchema === void 0 ? {} : { insertSchema: t.insertSchema },
726
729
  ...t.validatePatchSchema === void 0 ? {} : { validatePatchSchema: t.validatePatchSchema }
727
730
  })),
728
- validate: ((e) => I({
731
+ validate: ((e) => L({
729
732
  ...t,
730
733
  tableName: t.tableName,
731
734
  fields: t.fields,
@@ -739,7 +742,7 @@ var r = (e) => {
739
742
  insertSchema: e,
740
743
  ...t.validatePatchSchema === void 0 ? {} : { validatePatchSchema: t.validatePatchSchema }
741
744
  })),
742
- validatePatch: ((n) => I({
745
+ validatePatch: ((n) => L({
743
746
  ...t,
744
747
  tableName: t.tableName,
745
748
  fields: t.fields,
@@ -754,17 +757,22 @@ var r = (e) => {
754
757
  validatePatchSchema: e.partial(n)
755
758
  }))
756
759
  };
757
- }, Ge = (e, t) => {
758
- y(e);
760
+ }, Ke = (e, t) => {
761
+ b(e);
759
762
  let n = Object.entries(t).flatMap(([e, t]) => {
760
- let n = m(t);
763
+ let n = h(t);
761
764
  return n === void 0 ? [] : [{
762
765
  column: e,
763
766
  ...n
764
767
  }];
765
- }), r = We(f(t), e);
766
- for (let t of Object.keys(r)) b(e, t);
767
- return I({
768
+ }), r = Ge(p(t), e);
769
+ for (let t of Object.keys(r)) x(e, t);
770
+ let i;
771
+ for (let [t, n] of Object.entries(r)) n.references === d && (n.references = () => {
772
+ if (i === void 0) throw Error(`selfReference() on '${e}.${t}' read before table() returned`);
773
+ return i;
774
+ });
775
+ return i = L({
768
776
  appliedPluginRefs: n,
769
777
  tableName: e,
770
778
  fields: r,
@@ -775,8 +783,8 @@ var r = (e) => {
775
783
  appliedFullText: [],
776
784
  appliedChecks: [],
777
785
  appliedRules: []
778
- });
779
- }, Ke = (e) => e === "sqlite" || e === "turso", qe = (e) => e === "mysql" || e === "mariadb", L = (e, t) => {
786
+ }), i;
787
+ }, qe = (e) => e === "sqlite" || e === "turso", Je = (e) => e === "mysql" || e === "mariadb", R = (e, t) => {
780
788
  switch (t) {
781
789
  case "mysql":
782
790
  case "mariadb": return `\`${e}\``;
@@ -785,51 +793,51 @@ var r = (e) => {
785
793
  case "sqlite":
786
794
  case "turso": return `"${e}"`;
787
795
  }
788
- }, Je = 1e4, R = Symbol.for("@voltro/database/tableRegistry"), z = globalThis, B = z[R] ?? (z[R] = /* @__PURE__ */ new Map()), V = (e) => {
789
- let t = B.get(e.tableName);
796
+ }, Ye = 1e4, z = Symbol.for("@voltro/database/tableRegistry"), B = globalThis, V = B[z] ?? (B[z] = /* @__PURE__ */ new Map()), H = (e) => {
797
+ let t = V.get(e.tableName);
790
798
  if (t === void 0) {
791
- B.set(e.tableName, e);
799
+ V.set(e.tableName, e);
792
800
  return;
793
801
  }
794
802
  if (t !== e) throw Error(`duplicate table '${e.tableName}' registration: two different table descriptors claim the same name. Rename one or import the shared module that defines it.`);
795
- }, Ye = (e) => {
796
- B.get(e.tableName) === void 0 && B.set(e.tableName, e);
797
- }, H = (e) => B.get(e), Xe = (e) => {
798
- let t = B.get(e);
803
+ }, Xe = (e) => {
804
+ V.get(e.tableName) === void 0 && V.set(e.tableName, e);
805
+ }, U = (e) => V.get(e), Ze = (e) => {
806
+ let t = V.get(e);
799
807
  if (t === void 0) throw Error(`table '${e}' is not registered. Register it by wrapping it in \`databaseHandle({ ... })\` (the usual path) or call \`registerTable(t)\` explicitly before this runs. Note a \`queryFor(t)\` query carries its own source table, so eager-loads don't hit this — this error means a reconstructed descriptor or by-name tooling reached an unregistered table.`);
800
808
  return t;
801
- }, Ze = () => [...B.values()], Qe = (e) => B.delete(e), $e = () => {
802
- B.clear();
803
- }, et = (e) => B.get(e)?.isReactive !== !1, tt = (e) => e.order ?? [], nt = (e) => ({
809
+ }, Qe = () => [...V.values()], $e = (e) => V.delete(e), et = () => {
810
+ V.clear();
811
+ }, tt = (e) => V.get(e)?.isReactive !== !1, nt = (e) => e.order ?? [], rt = (e) => ({
804
812
  op: "count",
805
813
  alias: e ?? "count"
806
- }), rt = (e, t) => ({
814
+ }), it = (e, t) => ({
807
815
  op: "count-distinct",
808
816
  column: e,
809
817
  alias: t ?? `count_distinct_${e}`
810
- }), it = (e, t) => ({
818
+ }), at = (e, t) => ({
811
819
  op: "sum",
812
820
  column: e,
813
821
  alias: t ?? `sum_${e}`
814
- }), at = (e, t) => ({
822
+ }), ot = (e, t) => ({
815
823
  op: "avg",
816
824
  column: e,
817
825
  alias: t ?? `avg_${e}`
818
- }), ot = (e, t) => ({
826
+ }), st = (e, t) => ({
819
827
  op: "min",
820
828
  column: e,
821
829
  alias: t ?? `min_${e}`
822
- }), st = (e, t) => ({
830
+ }), ct = (e, t) => ({
823
831
  op: "max",
824
832
  column: e,
825
833
  alias: t ?? `max_${e}`
826
- }), ct = (e, t) => ({
834
+ }), lt = (e, t) => ({
827
835
  op: "column",
828
836
  column: e,
829
837
  alias: t ?? e
830
- }), U = (e) => (...t) => {
838
+ }), W = (e) => (...t) => {
831
839
  if (t.length < 2) throw Error(`${e}: requires at least two queries`);
832
- return K({
840
+ return q({
833
841
  table: t[0].descriptor.table,
834
842
  predicate: void 0,
835
843
  order: [],
@@ -841,55 +849,55 @@ var r = (e) => {
841
849
  queries: t.map((e) => e.descriptor)
842
850
  }
843
851
  });
844
- }, lt = U("union"), ut = U("union-all"), dt = U("intersect"), ft = U("except"), W = (e) => ({ over: (t) => ({
852
+ }, ut = W("union"), dt = W("union-all"), ft = W("intersect"), pt = W("except"), G = (e) => ({ over: (t) => ({
845
853
  ...e,
846
854
  window: t
847
- }) }), pt = (e = "rowNumber") => W({
855
+ }) }), mt = (e = "rowNumber") => G({
848
856
  op: "window-row-number",
849
857
  alias: e
850
- }), mt = (e = "rank") => W({
858
+ }), ht = (e = "rank") => G({
851
859
  op: "window-rank",
852
860
  alias: e
853
- }), ht = (e = "denseRank") => W({
861
+ }), gt = (e = "denseRank") => G({
854
862
  op: "window-dense-rank",
855
863
  alias: e
856
- }), gt = (e, t = 1, n) => W({
864
+ }), _t = (e, t = 1, n) => G({
857
865
  op: "window-lag",
858
866
  column: e,
859
867
  alias: n ?? `lag_${e}`,
860
868
  offset: t
861
- }), _t = (e, t = 1, n) => W({
869
+ }), vt = (e, t = 1, n) => G({
862
870
  op: "window-lead",
863
871
  column: e,
864
872
  alias: n ?? `lead_${e}`,
865
873
  offset: t
866
- }), vt = (e, t) => W({
874
+ }), yt = (e, t) => G({
867
875
  op: "window-sum-over",
868
876
  column: e,
869
877
  alias: t ?? `sum_${e}_over`
870
- }), yt = (e, t) => W({
878
+ }), bt = (e, t) => G({
871
879
  op: "window-avg-over",
872
880
  column: e,
873
881
  alias: t ?? `avg_${e}_over`
874
- }), G = (e, t, n) => {
875
- let r = n?.find((e) => e.name === t) ?? H(e)?.appliedFullText?.find((e) => e.name === t);
882
+ }), K = (e, t, n) => {
883
+ let r = n?.find((e) => e.name === t) ?? U(e)?.appliedFullText?.find((e) => e.name === t);
876
884
  if (r === void 0) throw Error(`.matching('${t}', ...): no full-text index named '${t}' is declared on table '${e}'. Declare it with \`table(...).fullTextIndex('${t}', [columns])\` first.`);
877
885
  return {
878
886
  columns: r.columns,
879
887
  ...r.config === void 0 ? {} : { config: r.config },
880
888
  ...r.weights === void 0 ? {} : { weights: r.weights }
881
889
  };
882
- }, K = (e) => ({
890
+ }, q = (e) => ({
883
891
  descriptor: e,
884
892
  where(t) {
885
893
  let n = e.predicate ? { and: [e.predicate, t] } : t;
886
- return K({
894
+ return q({
887
895
  ...e,
888
896
  predicate: n
889
897
  });
890
898
  },
891
899
  orderBy(t, n = "asc") {
892
- return K({
900
+ return q({
893
901
  ...e,
894
902
  order: [...e.order, {
895
903
  column: t,
@@ -898,37 +906,43 @@ var r = (e) => {
898
906
  });
899
907
  },
900
908
  limit(t) {
901
- return K({
909
+ return q({
902
910
  ...e,
903
911
  take: t
904
912
  });
905
913
  },
906
914
  offset(t) {
907
- return K({
915
+ return q({
908
916
  ...e,
909
917
  skip: t
910
918
  });
911
919
  },
912
920
  select(...t) {
913
- return K({
921
+ return q({
914
922
  ...e,
915
923
  projection: t
916
924
  });
917
925
  },
918
926
  using(t) {
919
- return K({
927
+ return q({
920
928
  ...e,
921
929
  usingIndex: t
922
930
  });
923
931
  },
924
932
  withDeleted() {
925
- return K({
933
+ return q({
926
934
  ...e,
927
935
  includeDeleted: !0
928
936
  });
929
937
  },
938
+ forUpdate() {
939
+ return q({
940
+ ...e,
941
+ lock: "update"
942
+ });
943
+ },
930
944
  unscoped() {
931
- return K({
945
+ return q({
932
946
  ...e,
933
947
  crossTenant: !0
934
948
  });
@@ -938,13 +952,13 @@ var r = (e) => {
938
952
  ...e.eager ?? {},
939
953
  ...t
940
954
  };
941
- return K({
955
+ return q({
942
956
  ...e,
943
957
  eager: n
944
958
  });
945
959
  },
946
960
  count() {
947
- return K({
961
+ return q({
948
962
  ...e,
949
963
  projection: void 0,
950
964
  aggregations: [{
@@ -958,15 +972,15 @@ var r = (e) => {
958
972
  ...t,
959
973
  alias: e
960
974
  }));
961
- return K({
975
+ return q({
962
976
  ...e,
963
977
  projection: void 0,
964
978
  aggregations: n
965
979
  });
966
980
  },
967
981
  matching(t, n) {
968
- let r = G(e.table, t, e.fullTextIndexes);
969
- return K({
982
+ let r = K(e.table, t, e.fullTextIndexes);
983
+ return q({
970
984
  ...e,
971
985
  fullTextSearch: {
972
986
  indexName: t,
@@ -980,7 +994,7 @@ var r = (e) => {
980
994
  rankBy(t) {
981
995
  let n = e.fullTextSearch;
982
996
  if (n === void 0) throw Error(".rankBy() requires a preceding .matching(...) clause — there is no full-text search to rank on this query.");
983
- return K({
997
+ return q({
984
998
  ...e,
985
999
  fullTextSearch: {
986
1000
  ...n,
@@ -999,7 +1013,7 @@ var r = (e) => {
999
1013
  distance: r?.distance ?? "cosine",
1000
1014
  ...e.annClause?.ef === void 0 ? {} : { ef: e.annClause.ef }
1001
1015
  };
1002
- return K({
1016
+ return q({
1003
1017
  ...e,
1004
1018
  annClause: i
1005
1019
  });
@@ -1011,7 +1025,7 @@ var r = (e) => {
1011
1025
  distance: "cosine",
1012
1026
  ...e.annClause?.ef === void 0 ? {} : { ef: e.annClause.ef }
1013
1027
  };
1014
- return K({
1028
+ return q({
1015
1029
  ...e,
1016
1030
  annClause: r,
1017
1031
  take: n
@@ -1024,7 +1038,7 @@ var r = (e) => {
1024
1038
  column: "",
1025
1039
  distance: "cosine"
1026
1040
  };
1027
- return K({
1041
+ return q({
1028
1042
  ...e,
1029
1043
  annClause: {
1030
1044
  ...n,
@@ -1033,22 +1047,22 @@ var r = (e) => {
1033
1047
  });
1034
1048
  },
1035
1049
  use(t) {
1036
- return K({ ...t(e) });
1050
+ return q({ ...t(e) });
1037
1051
  },
1038
1052
  distinct() {
1039
- return K({
1053
+ return q({
1040
1054
  ...e,
1041
1055
  distinct: !0
1042
1056
  });
1043
1057
  },
1044
1058
  distinctOn(t) {
1045
- return K({
1059
+ return q({
1046
1060
  ...e,
1047
1061
  distinctOn: [...t]
1048
1062
  });
1049
1063
  },
1050
1064
  as(t) {
1051
- return K({
1065
+ return q({
1052
1066
  ...e,
1053
1067
  alias: t
1054
1068
  });
@@ -1060,7 +1074,7 @@ var r = (e) => {
1060
1074
  alias: n,
1061
1075
  on: r
1062
1076
  }];
1063
- return K({
1077
+ return q({
1064
1078
  ...e,
1065
1079
  joins: a
1066
1080
  });
@@ -1072,7 +1086,7 @@ var r = (e) => {
1072
1086
  alias: n,
1073
1087
  on: r
1074
1088
  }];
1075
- return K({
1089
+ return q({
1076
1090
  ...e,
1077
1091
  joins: a
1078
1092
  });
@@ -1082,7 +1096,7 @@ var r = (e) => {
1082
1096
  outputKey: e,
1083
1097
  source: t
1084
1098
  }));
1085
- return K({
1099
+ return q({
1086
1100
  ...e,
1087
1101
  projection: void 0,
1088
1102
  joinedProjection: n
@@ -1091,7 +1105,7 @@ var r = (e) => {
1091
1105
  withCte(t, n) {
1092
1106
  let r = e.ctes ?? [];
1093
1107
  if (r.some((e) => e.name === t)) throw Error(`Query.withCte: duplicate CTE name '${t}'`);
1094
- return K({
1108
+ return q({
1095
1109
  ...e,
1096
1110
  ctes: [...r, {
1097
1111
  name: t,
@@ -1102,7 +1116,7 @@ var r = (e) => {
1102
1116
  recursiveCte(t, n) {
1103
1117
  let r = e.ctes ?? [];
1104
1118
  if (r.some((e) => e.name === t)) throw Error(`Query.recursiveCte: duplicate CTE name '${t}'`);
1105
- return K({
1119
+ return q({
1106
1120
  ...e,
1107
1121
  ctes: [...r, {
1108
1122
  name: t,
@@ -1113,20 +1127,20 @@ var r = (e) => {
1113
1127
  },
1114
1128
  groupBy(t) {
1115
1129
  let n = e.groupBy ? [...e.groupBy, ...t] : [...t];
1116
- return K({
1130
+ return q({
1117
1131
  ...e,
1118
1132
  groupBy: n
1119
1133
  });
1120
1134
  },
1121
1135
  having(t) {
1122
1136
  let n = e.having ? { and: [e.having, t] } : t;
1123
- return K({
1137
+ return q({
1124
1138
  ...e,
1125
1139
  having: n
1126
1140
  });
1127
1141
  },
1128
1142
  exists() {
1129
- return K({
1143
+ return q({
1130
1144
  ...e,
1131
1145
  projection: void 0,
1132
1146
  aggregations: [{
@@ -1137,8 +1151,8 @@ var r = (e) => {
1137
1151
  });
1138
1152
  }
1139
1153
  });
1140
- function q(e) {
1141
- return K({
1154
+ function J(e) {
1155
+ return q({
1142
1156
  table: e.tableName,
1143
1157
  predicate: void 0,
1144
1158
  order: [],
@@ -1149,7 +1163,7 @@ function q(e) {
1149
1163
  sourceTable: e
1150
1164
  });
1151
1165
  }
1152
- var bt = (e, t, n) => J(e, "id", t, n), J = (e, t, n, r, i = "asc") => {
1166
+ var xt = (e, t, n) => Y(e, "id", t, n), Y = (e, t, n, r, i = "asc") => {
1153
1167
  let a = [...e.order.filter((e) => e.column !== t), {
1154
1168
  column: t,
1155
1169
  direction: i
@@ -1164,21 +1178,21 @@ var bt = (e, t, n) => J(e, "id", t, n), J = (e, t, n, r, i = "asc") => {
1164
1178
  order: a,
1165
1179
  take: r
1166
1180
  };
1167
- }, xt = (e) => {
1181
+ }, St = (e) => {
1168
1182
  let t = {};
1169
- for (let [n, r] of Object.entries(e)) V(r), t[n] = q(r);
1183
+ for (let [n, r] of Object.entries(e)) H(r), t[n] = J(r);
1170
1184
  return t;
1171
- }, St = (e) => e.isView === !0, Ct = (e, t, n) => {
1172
- if (y(e), n.trim().length === 0) throw Error(`view('${e}', …): the SELECT body is empty — a view must define a query.`);
1173
- let r = f(t);
1174
- for (let t of Object.keys(r)) b(e, t);
1185
+ }, Ct = (e) => e.isView === !0, wt = (e, t, n) => {
1186
+ if (b(e), n.trim().length === 0) throw Error(`view('${e}', …): the SELECT body is empty — a view must define a query.`);
1187
+ let r = p(t);
1188
+ for (let t of Object.keys(r)) x(e, t);
1175
1189
  return {
1176
1190
  tableName: e,
1177
1191
  fields: r,
1178
1192
  isView: !0,
1179
1193
  viewSelect: n
1180
1194
  };
1181
- }, wt = (e) => q({
1195
+ }, Tt = (e) => J({
1182
1196
  ...e,
1183
1197
  isReactive: !1,
1184
1198
  appliedMixins: [],
@@ -1186,8 +1200,8 @@ var bt = (e, t, n) => J(e, "id", t, n), J = (e, t, n, r, i = "asc") => {
1186
1200
  appliedUniques: [],
1187
1201
  appliedFullText: [],
1188
1202
  appliedChecks: []
1189
- }), Tt = (e, t, n = null) => {
1190
- let r = n === null ? L(e.tableName, t) : `${L(n, t)}.${L(e.tableName, t)}`, i = e.viewSelect.trim();
1203
+ }), Et = (e, t, n = null) => {
1204
+ let r = n === null ? R(e.tableName, t) : `${R(n, t)}.${R(e.tableName, t)}`, i = e.viewSelect.trim();
1191
1205
  switch (t) {
1192
1206
  case "postgres":
1193
1207
  case "mysql":
@@ -1196,16 +1210,16 @@ var bt = (e, t, n) => J(e, "id", t, n), J = (e, t, n, r, i = "asc") => {
1196
1210
  case "sqlite":
1197
1211
  case "turso": return `DROP VIEW IF EXISTS ${r};\nCREATE VIEW ${r} AS ${i};`;
1198
1212
  }
1199
- }, Et = /^[A-Za-z_][A-Za-z0-9_]*$/, Dt = (e) => "$" + e.map((e) => typeof e == "number" ? `[${e}]` : Et.test(e) ? `.${e}` : `."${e.replace(/"/g, "\\\"")}"`).join(""), Ot = (e) => "{" + e.map((e) => {
1213
+ }, Dt = /^[A-Za-z_][A-Za-z0-9_]*$/, Ot = (e) => "$" + e.map((e) => typeof e == "number" ? `[${e}]` : Dt.test(e) ? `.${e}` : `."${e.replace(/"/g, "\\\"")}"`).join(""), kt = (e) => "{" + e.map((e) => {
1200
1214
  let t = String(e);
1201
1215
  return /^[A-Za-z0-9_]+$/.test(t) ? t : `"${t.replace(/(["\\])/g, "\\$1")}"`;
1202
- }).join(",") + "}", kt = (e, t, n, r = {}) => {
1203
- let i = L(e, n), a = r.numeric ?? !1;
1216
+ }).join(",") + "}", At = (e, t, n, r = {}) => {
1217
+ let i = R(e, n), a = r.numeric ?? !1;
1204
1218
  if (n === "postgres") {
1205
- let e = `(${i} #>> '${Ot(t)}'::text[])`;
1219
+ let e = `(${i} #>> '${kt(t)}'::text[])`;
1206
1220
  return a ? `${e}::numeric` : e;
1207
1221
  }
1208
- let o = Dt(t);
1222
+ let o = Ot(t);
1209
1223
  switch (n) {
1210
1224
  case "mysql":
1211
1225
  case "mariadb": {
@@ -1222,13 +1236,13 @@ var bt = (e, t, n) => J(e, "id", t, n), J = (e, t, n, r, i = "asc") => {
1222
1236
  return a ? `CAST(${e} AS REAL)` : e;
1223
1237
  }
1224
1238
  }
1225
- }, At = (e, t) => ({
1239
+ }, jt = (e, t) => ({
1226
1240
  name: e,
1227
1241
  body: t
1228
- }), Y = (e) => {
1242
+ }), Mt = (e) => {
1229
1243
  if (e.lifecycle === "cron" && !e.cron) throw Error(`seed "${e.id}": lifecycle 'cron' requires a 'cron' field`);
1230
1244
  if (e.lifecycle === "onSchemaChange" && (!e.watchedTables || e.watchedTables.length === 0)) throw Error(`seed "${e.id}": lifecycle 'onSchemaChange' requires at least one entry in 'watchedTables'`);
1231
- let t = e.steps({ step: At });
1245
+ let t = e.steps({ step: jt });
1232
1246
  if (t.length === 0) throw Error(`seed "${e.id}": at least one step is required`);
1233
1247
  return {
1234
1248
  __seed: !0,
@@ -1241,20 +1255,41 @@ var bt = (e, t, n) => J(e, "id", t, n), J = (e, t, n, r, i = "asc") => {
1241
1255
  ...e.fingerprint === void 0 ? {} : { fingerprint: e.fingerprint },
1242
1256
  steps: t
1243
1257
  };
1244
- }, jt = (e) => typeof e == "object" && !!e && "__seed" in e && e.__seed === !0, X = null, Z = null, Mt = (e) => {
1258
+ }, Nt = (e) => typeof e == "object" && !!e && "__seed" in e && e.__seed === !0, X = null, Z = null, Pt = (e) => {
1245
1259
  X = e;
1246
- }, Nt = (e) => {
1260
+ }, Ft = (e) => {
1247
1261
  Z = e;
1248
- }, Pt = async (e) => {
1262
+ }, It = async (e) => {
1249
1263
  let t = X;
1250
1264
  t !== null && await t(e);
1251
- }, Ft = async (e) => {
1265
+ }, Lt = async (e) => {
1252
1266
  let t = Z;
1253
1267
  t !== null && e.changedTables.length !== 0 && await t(e);
1254
- }, It = (e) => {
1268
+ }, Rt = (e) => {
1255
1269
  if (!e.id || e.id.length === 0) throw Error("migration: `id` is required + must be non-empty");
1256
1270
  if (!e.up || !e.down) throw Error(`migration ${e.id}: both \`up\` and \`down\` must be functions`);
1257
1271
  return e;
1258
- }, Lt = /^\d{8}_\d{6}_[a-z0-9_]+\.ts$/, Rt = (e) => typeof e == "object" && !!e && "id" in e && "up" in e && "down" in e && typeof e.id == "string" && typeof e.up == "function" && typeof e.down == "function", Q = /* @__PURE__ */ new Set(["voltro_isr_cache"]), zt = (e) => Q.has(e) || e.startsWith("_voltro_") || e.startsWith("_cloud_") || e.startsWith("cluster_"), $ = "_voltro_staging_", Bt = (e) => e.startsWith($), Vt = /__dropped_\d{14}$/, Ht = (e) => Vt.test(e);
1272
+ }, zt = /^\d{8}_\d{6}_[a-z0-9_]+\.ts$/, Bt = (e) => typeof e == "object" && !!e && "id" in e && "up" in e && "down" in e && typeof e.id == "string" && typeof e.up == "function" && typeof e.down == "function", Q = /* @__PURE__ */ new Set(["voltro_isr_cache"]), Vt = (e) => Q.has(e) || e.startsWith("_voltro_") || e.startsWith("_cloud_") || e.startsWith("cluster_") || e.startsWith("__turso_internal_"), $ = "_voltro_staging_", Ht = (e) => e.startsWith($), Ut = /__dropped_\d{14}$/, Wt = (e) => Ut.test(e), Gt = 7, Kt = (e) => {
1273
+ let t = /__dropped_(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/.exec(e);
1274
+ if (t === null) return;
1275
+ let [, n, r, i, a, o, s] = t;
1276
+ return new Date(Date.UTC(Number(n), Number(r) - 1, Number(i), Number(a), Number(o), Number(s)));
1277
+ }, qt = (e, t = {}) => {
1278
+ let n = t.now ?? /* @__PURE__ */ new Date(), r = t.retentionDays ?? 7, i = [], a = (e, t) => {
1279
+ let a = Kt(e);
1280
+ if (a === void 0) return;
1281
+ let o = Math.floor((n.getTime() - a.getTime()) / 864e5);
1282
+ o >= r && i.push({
1283
+ name: t,
1284
+ droppedAt: a,
1285
+ ageDays: o
1286
+ });
1287
+ };
1288
+ for (let t of e.tables) if (a(t.name, t.name), !Wt(t.name)) for (let e of t.columns ?? []) a(e.name, `${t.name}.${e.name}`);
1289
+ return i;
1290
+ }, Jt = (e, t) => {
1291
+ let n = e.reduce((e, t) => e.ageDays >= t.ageDays ? e : t), r = (/* @__PURE__ */ new Date(Date.now() - t * 864e5)).toISOString().slice(0, 10);
1292
+ return `${e.length} soft-drop snapshot(s) older than ${t} day(s) still hold the dropped data (oldest: ${n.name}, ${n.ageDays}d) — ${e.map((e) => e.name).join(", ")}. Restore with \`voltro db restore-snapshot\` or reclaim with \`voltro db gc-snapshots --before ${r}\`; the window is \`database.softDropRetentionDays\` in app.config.`;
1293
+ };
1259
1294
  //#endregion
1260
- export { qe as $, l as $t, _t as A, oe as At, it as B, _e as Bt, nt as C, xe as Ct, ft as D, s as Dt, ht as E, m as Et, bt as F, d as Ft, $e as G, le as Gt, lt as H, ee as Ht, q as I, ce as It, et as J, ye as Jt, Ye as K, f as Kt, mt as L, ae as Lt, ot as M, de as Mt, tt as N, o as Nt, dt as O, he as Ot, J as P, i as Pt, Je as Q, r as Qt, G as R, u as Rt, ct as S, we as St, xt as T, be as Tt, ut as U, te as Ut, vt as V, ve as Vt, Ze as W, ge as Wt, Xe as X, ne as Xt, V as Y, a as Yt, Qe as Z, fe as Zt, wt as _, b as _t, Bt as a, Ve as at, at as b, S as bt, It as c, M as ct, Pt as d, A as dt, se as en, Ke as et, jt as f, O as ft, St as g, De as gt, kt as h, Ee as ht, Ht as i, Ge as it, st as j, ue as jt, gt as k, ie as kt, Y as l, k as lt, Mt as m, Te as mt, $ as n, He as nt, Lt as o, ze as ot, Nt as p, Ie as pt, H as q, re as qt, zt as r, Be as rt, Rt as s, j as st, Q as t, me as tn, L as tt, Ft as u, Re as ut, Ct as v, x as vt, rt as w, Se as wt, yt as x, Ce as xt, Tt as y, y as yt, pt as z, pe as zt };
1295
+ export { H as $, be as $t, gt as A, h as At, J as B, de as Bt, Et as C, b as Ct, rt as D, Se as Dt, lt as E, Te as Et, ct as F, oe as Ft, yt as G, ve as Gt, K as H, ae as Ht, st as I, ue as It, Qe as J, te as Jt, ut as K, ye as Kt, nt as L, fe as Lt, ft as M, d as Mt, _t as N, ge as Nt, it as O, Ce as Ot, vt as P, ie as Pt, tt as Q, re as Qt, Y as R, o as Rt, wt as S, S as St, bt as T, we as Tt, mt as U, u as Ut, ht as V, ce as Vt, at as W, me as Wt, Xe as X, le as Xt, et as Y, _e as Yt, U as Z, p as Zt, Ft as _, Le as _t, Jt as a, l as an, R as at, Ct as b, Oe as bt, Ht as c, Ke as ct, Bt as d, M as dt, a as en, Ze as et, Rt as f, N as ft, Nt as g, k as gt, It as h, j as ht, qt as i, r as in, qe as it, pt as j, s as jt, St as k, xe as kt, Kt as l, He as lt, Lt as m, ze as mt, Q as n, f as nn, Ye as nt, Vt as o, se as on, Ue as ot, Mt as p, A as pt, dt as q, ee as qt, $ as r, pe as rn, Je as rt, Wt as s, he as sn, Ve as st, Gt as t, ne as tn, $e as tt, zt as u, Be as ut, Pt as v, Ee as vt, ot as w, C as wt, Tt as x, x as xt, At as y, De as yt, xt as z, i as zt };