@voltro/database 0.40.0 → 0.42.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.
@@ -1,6 +1,6 @@
1
- import { typeid as e } from "typeid-js";
2
- import { ulid as t } from "ulidx";
3
- import { Schema as n } from "effect";
1
+ import { Schema as e } from "effect";
2
+ import { typeid as t } from "typeid-js";
3
+ import { ulid as n } from "ulidx";
4
4
  //#region src/columns.ts
5
5
  var r = (e) => {
6
6
  let t = [];
@@ -385,13 +385,13 @@ var r = (e) => {
385
385
  generate: e.generate
386
386
  };
387
387
  }
388
- }, Fe = (n, r) => {
389
- switch (n.kind) {
390
- case "typeid": return e(n.prefix).toString();
391
- case "ulid": return t();
388
+ }, Fe = (e, r) => {
389
+ switch (e.kind) {
390
+ case "typeid": return t(e.prefix).toString();
391
+ case "ulid": return n();
392
392
  case "numeric": return null;
393
393
  case "snowflake": return k();
394
- case "custom": return n.generate(r);
394
+ case "custom": return e.generate(r);
395
395
  }
396
396
  }, M = (e) => ({
397
397
  fields: f(e.fields),
@@ -452,288 +452,288 @@ var r = (e) => {
452
452
  idScheme: j(i.idSchemeInput, t)
453
453
  });
454
454
  return n ?? e;
455
- }, L = (e) => {
456
- let t = e.appliedPrimaryKey ?? [];
455
+ }, L = (t) => {
456
+ let n = t.appliedPrimaryKey ?? [];
457
457
  return {
458
- tableName: e.tableName,
459
- fields: e.fields,
460
- isReactive: e.isReactive,
461
- appliedMixins: e.appliedMixins,
462
- appliedIndexes: e.appliedIndexes,
463
- appliedUniques: e.appliedUniques,
464
- appliedFullText: e.appliedFullText,
465
- appliedChecks: e.appliedChecks,
466
- appliedRules: e.appliedRules ?? [],
467
- appliedPluginRefs: e.appliedPluginRefs ?? [],
468
- appliedPrimaryKey: t,
469
- ...e.previousTableName === void 0 ? {} : { previousTableName: e.previousTableName },
470
- ...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
471
- ...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema },
472
- fullTextIndex: ((t, n, r) => {
473
- if (n.length === 0) throw Error(`fullTextIndex '${t}' on '${e.tableName}' has no columns.`);
474
- if (x(e.tableName, t, !1, n), e.appliedFullText.some((e) => e.name === t)) throw Error(`duplicate full-text index '${t}' on table '${e.tableName}'.`);
458
+ tableName: t.tableName,
459
+ fields: t.fields,
460
+ isReactive: t.isReactive,
461
+ appliedMixins: t.appliedMixins,
462
+ appliedIndexes: t.appliedIndexes,
463
+ appliedUniques: t.appliedUniques,
464
+ appliedFullText: t.appliedFullText,
465
+ appliedChecks: t.appliedChecks,
466
+ appliedRules: t.appliedRules ?? [],
467
+ appliedPluginRefs: t.appliedPluginRefs ?? [],
468
+ appliedPrimaryKey: n,
469
+ ...t.previousTableName === void 0 ? {} : { previousTableName: t.previousTableName },
470
+ ...t.insertSchema === void 0 ? {} : { insertSchema: t.insertSchema },
471
+ ...t.validatePatchSchema === void 0 ? {} : { validatePatchSchema: t.validatePatchSchema },
472
+ fullTextIndex: ((e, n, r) => {
473
+ if (n.length === 0) throw Error(`fullTextIndex '${e}' on '${t.tableName}' has no columns.`);
474
+ 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}'.`);
475
475
  return L({
476
- ...e,
477
- tableName: e.tableName,
478
- fields: e.fields,
479
- isReactive: e.isReactive,
480
- appliedMixins: e.appliedMixins,
481
- appliedIndexes: e.appliedIndexes,
482
- appliedUniques: e.appliedUniques,
483
- appliedChecks: e.appliedChecks,
484
- appliedPrimaryKey: e.appliedPrimaryKey,
485
- appliedFullText: [...e.appliedFullText, {
486
- name: t,
476
+ ...t,
477
+ tableName: t.tableName,
478
+ fields: t.fields,
479
+ isReactive: t.isReactive,
480
+ appliedMixins: t.appliedMixins,
481
+ appliedIndexes: t.appliedIndexes,
482
+ appliedUniques: t.appliedUniques,
483
+ appliedChecks: t.appliedChecks,
484
+ appliedPrimaryKey: t.appliedPrimaryKey,
485
+ appliedFullText: [...t.appliedFullText, {
486
+ name: e,
487
487
  columns: [...n],
488
488
  ...r?.config === void 0 ? {} : { config: r.config },
489
489
  ...r?.weights === void 0 ? {} : { weights: r.weights }
490
490
  }],
491
- ...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
492
- ...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
491
+ ...t.insertSchema === void 0 ? {} : { insertSchema: t.insertSchema },
492
+ ...t.validatePatchSchema === void 0 ? {} : { validatePatchSchema: t.validatePatchSchema }
493
493
  });
494
494
  }),
495
- with: ((...t) => {
496
- let n = N(t), r = { ...e.fields }, i = /* @__PURE__ */ new Map();
495
+ with: ((...e) => {
496
+ let n = N(e), r = { ...t.fields }, i = /* @__PURE__ */ new Map();
497
497
  for (let e of Object.keys(r)) i.set(e, {
498
498
  id: "<table>",
499
499
  fields: {}
500
500
  });
501
- for (let t of n) for (let [n, a] of Object.entries(t.fields)) {
501
+ for (let e of n) for (let [n, a] of Object.entries(e.fields)) {
502
502
  let o = i.get(n);
503
- if (o !== void 0) throw Error(`mixin collision on column '${n}' in table '${e.tableName}': '${P(o)}' and '${P(t)}' 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.`);
504
- b(e.tableName, n), r[n] = a, i.set(n, t);
503
+ 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.`);
504
+ b(t.tableName, n), r[n] = a, i.set(n, e);
505
505
  }
506
- let a = [...e.appliedIndexes];
507
- for (let t of n) for (let n of t.indexes ?? []) {
508
- let t = n.name ?? F(e.tableName, n.fields);
509
- a.some((e) => e.name === t) || (x(e.tableName, t, n.name === void 0, n.fields), I(e.tableName, t, n.kind, n.fields, r), a.push({
510
- name: t,
506
+ let a = [...t.appliedIndexes];
507
+ for (let e of n) for (let n of e.indexes ?? []) {
508
+ let e = n.name ?? F(t.tableName, n.fields);
509
+ a.some((t) => t.name === e) || (x(t.tableName, e, n.name === void 0, n.fields), I(t.tableName, e, n.kind, n.fields, r), a.push({
510
+ name: e,
511
511
  fields: n.fields,
512
512
  ...n.kind === void 0 ? {} : { kind: n.kind },
513
513
  ...n.kindOptions === void 0 ? {} : { kindOptions: n.kindOptions }
514
514
  }));
515
515
  }
516
516
  return L({
517
- ...e,
518
- tableName: e.tableName,
517
+ ...t,
518
+ tableName: t.tableName,
519
519
  fields: r,
520
- isReactive: e.isReactive,
521
- appliedMixins: [...e.appliedMixins, ...n],
520
+ isReactive: t.isReactive,
521
+ appliedMixins: [...t.appliedMixins, ...n],
522
522
  appliedIndexes: a,
523
- appliedUniques: e.appliedUniques,
524
- appliedFullText: e.appliedFullText,
525
- appliedChecks: e.appliedChecks,
526
- appliedPrimaryKey: e.appliedPrimaryKey,
527
- ...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
528
- ...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
523
+ appliedUniques: t.appliedUniques,
524
+ appliedFullText: t.appliedFullText,
525
+ appliedChecks: t.appliedChecks,
526
+ appliedPrimaryKey: t.appliedPrimaryKey,
527
+ ...t.insertSchema === void 0 ? {} : { insertSchema: t.insertSchema },
528
+ ...t.validatePatchSchema === void 0 ? {} : { validatePatchSchema: t.validatePatchSchema }
529
529
  });
530
530
  }),
531
- index: ((...t) => {
532
- let n, r, i, a = Array.isArray(t[0]);
533
- if (a ? (r = t[0], i = t[1], n = F(e.tableName, r)) : (n = t[0], r = t[1], i = t[2]), r.length === 0) throw Error(`index '${n}' on table '${e.tableName}' has no fields — an index must cover at least one column.`);
531
+ index: ((...e) => {
532
+ let n, r, i, a = Array.isArray(e[0]);
533
+ 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.`);
534
534
  let o = r.filter((e) => typeof e == "string");
535
- if (x(e.tableName, n, a, o), I(e.tableName, n, i?.kind, r, e.fields), e.appliedIndexes.some((e) => e.name === n)) throw t.length === 1 ? Error(`duplicate auto-named index '${n}' on table '${e.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 '${e.tableName}': each index name must be unique within a table.`);
535
+ if (x(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.`);
536
536
  return L({
537
- ...e,
538
- tableName: e.tableName,
539
- fields: e.fields,
540
- isReactive: e.isReactive,
541
- appliedMixins: e.appliedMixins,
542
- appliedIndexes: [...e.appliedIndexes, {
537
+ ...t,
538
+ tableName: t.tableName,
539
+ fields: t.fields,
540
+ isReactive: t.isReactive,
541
+ appliedMixins: t.appliedMixins,
542
+ appliedIndexes: [...t.appliedIndexes, {
543
543
  name: n,
544
544
  fields: [...r],
545
545
  ...i?.where === void 0 ? {} : { where: i.where },
546
546
  ...i?.kind === void 0 ? {} : { kind: i.kind },
547
547
  ...i?.kindOptions === void 0 ? {} : { kindOptions: i.kindOptions }
548
548
  }],
549
- appliedUniques: e.appliedUniques,
550
- appliedFullText: e.appliedFullText,
551
- appliedChecks: e.appliedChecks,
552
- appliedPrimaryKey: e.appliedPrimaryKey,
553
- ...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
554
- ...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
549
+ appliedUniques: t.appliedUniques,
550
+ appliedFullText: t.appliedFullText,
551
+ appliedChecks: t.appliedChecks,
552
+ appliedPrimaryKey: t.appliedPrimaryKey,
553
+ ...t.insertSchema === void 0 ? {} : { insertSchema: t.insertSchema },
554
+ ...t.validatePatchSchema === void 0 ? {} : { validatePatchSchema: t.validatePatchSchema }
555
555
  });
556
556
  }),
557
- expressionIndex: ((t, n, r) => {
558
- if (n.length === 0) throw Error(`expressionIndex '${t}' on table '${e.tableName}' has no fields — an index must cover at least one column or expression.`);
557
+ expressionIndex: ((e, n, r) => {
558
+ 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.`);
559
559
  let i = n.filter((e) => typeof e == "string");
560
- if (x(e.tableName, t, !1, i), I(e.tableName, t, r?.kind, n, e.fields), e.appliedIndexes.some((e) => e.name === t)) throw Error(`duplicate index '${t}' on table '${e.tableName}': each index name must be unique within a table.`);
560
+ if (x(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.`);
561
561
  return L({
562
- ...e,
563
- tableName: e.tableName,
564
- fields: e.fields,
565
- isReactive: e.isReactive,
566
- appliedMixins: e.appliedMixins,
567
- appliedIndexes: [...e.appliedIndexes, {
568
- name: t,
562
+ ...t,
563
+ tableName: t.tableName,
564
+ fields: t.fields,
565
+ isReactive: t.isReactive,
566
+ appliedMixins: t.appliedMixins,
567
+ appliedIndexes: [...t.appliedIndexes, {
568
+ name: e,
569
569
  fields: [...n],
570
570
  ...r?.where === void 0 ? {} : { where: r.where },
571
571
  ...r?.kind === void 0 ? {} : { kind: r.kind },
572
572
  ...r?.kindOptions === void 0 ? {} : { kindOptions: r.kindOptions }
573
573
  }],
574
- appliedUniques: e.appliedUniques,
575
- appliedFullText: e.appliedFullText,
576
- appliedChecks: e.appliedChecks,
577
- appliedPrimaryKey: e.appliedPrimaryKey,
578
- ...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
579
- ...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
574
+ appliedUniques: t.appliedUniques,
575
+ appliedFullText: t.appliedFullText,
576
+ appliedChecks: t.appliedChecks,
577
+ appliedPrimaryKey: t.appliedPrimaryKey,
578
+ ...t.insertSchema === void 0 ? {} : { insertSchema: t.insertSchema },
579
+ ...t.validatePatchSchema === void 0 ? {} : { validatePatchSchema: t.validatePatchSchema }
580
580
  });
581
581
  }),
582
- unique: ((...t) => {
583
- let n, r, i, a = Array.isArray(t[0]);
584
- if (a ? (r = t[0], i = t[1], n = Be(e.tableName, r)) : (n = t[0], r = t[1], i = t[2]), r.length === 0) throw Error(`unique '${n}' on table '${e.tableName}' has no fields — a UNIQUE constraint must cover at least one column.`);
585
- if (x(e.tableName, n, a, r), e.appliedUniques.some((e) => e.name === n)) throw Error(a ? `duplicate auto-named UNIQUE '${n}' on table '${e.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 '${e.tableName}': each constraint name must be unique within a table.`);
582
+ unique: ((...e) => {
583
+ let n, r, i, a = Array.isArray(e[0]);
584
+ if (a ? (r = e[0], i = e[1], n = Be(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.`);
585
+ 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.`);
586
586
  return L({
587
- ...e,
588
- tableName: e.tableName,
589
- fields: e.fields,
590
- isReactive: e.isReactive,
591
- appliedMixins: e.appliedMixins,
592
- appliedIndexes: e.appliedIndexes,
593
- appliedUniques: [...e.appliedUniques, {
587
+ ...t,
588
+ tableName: t.tableName,
589
+ fields: t.fields,
590
+ isReactive: t.isReactive,
591
+ appliedMixins: t.appliedMixins,
592
+ appliedIndexes: t.appliedIndexes,
593
+ appliedUniques: [...t.appliedUniques, {
594
594
  name: n,
595
595
  fields: [...r],
596
596
  ...i?.dedup === void 0 ? {} : { dedup: i.dedup }
597
597
  }],
598
- appliedFullText: e.appliedFullText,
599
- appliedChecks: e.appliedChecks,
600
- appliedPrimaryKey: e.appliedPrimaryKey,
601
- ...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
602
- ...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
598
+ appliedFullText: t.appliedFullText,
599
+ appliedChecks: t.appliedChecks,
600
+ appliedPrimaryKey: t.appliedPrimaryKey,
601
+ ...t.insertSchema === void 0 ? {} : { insertSchema: t.insertSchema },
602
+ ...t.validatePatchSchema === void 0 ? {} : { validatePatchSchema: t.validatePatchSchema }
603
603
  });
604
604
  }),
605
- uniqueActive: ((...t) => {
606
- let n, r, i, a = Array.isArray(t[0]);
607
- if (a ? (r = t[0], i = t[1], n = F(e.tableName, r)) : (n = t[0], r = t[1], i = t[2]), r.length === 0) throw Error(`uniqueActive '${n}' on table '${e.tableName}' has no fields — a partial UNIQUE must cover at least one column.`);
608
- if (x(e.tableName, n, a, r), e.appliedIndexes.some((e) => e.name === n)) throw Error(`duplicate index '${n}' on table '${e.tableName}': each index name must be unique within a table (uniqueActive shares the index namespace).`);
605
+ uniqueActive: ((...e) => {
606
+ let n, r, i, a = Array.isArray(e[0]);
607
+ 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.`);
608
+ 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).`);
609
609
  let o = i?.where ?? "\"deletedAt\" IS NULL";
610
610
  return L({
611
- ...e,
612
- tableName: e.tableName,
613
- fields: e.fields,
614
- isReactive: e.isReactive,
615
- appliedMixins: e.appliedMixins,
616
- appliedIndexes: [...e.appliedIndexes, {
611
+ ...t,
612
+ tableName: t.tableName,
613
+ fields: t.fields,
614
+ isReactive: t.isReactive,
615
+ appliedMixins: t.appliedMixins,
616
+ appliedIndexes: [...t.appliedIndexes, {
617
617
  name: n,
618
618
  fields: [...r],
619
619
  where: o,
620
620
  unique: !0
621
621
  }],
622
- appliedUniques: e.appliedUniques,
623
- appliedFullText: e.appliedFullText,
624
- appliedChecks: e.appliedChecks,
625
- appliedPrimaryKey: e.appliedPrimaryKey,
626
- ...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
627
- ...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
622
+ appliedUniques: t.appliedUniques,
623
+ appliedFullText: t.appliedFullText,
624
+ appliedChecks: t.appliedChecks,
625
+ appliedPrimaryKey: t.appliedPrimaryKey,
626
+ ...t.insertSchema === void 0 ? {} : { insertSchema: t.insertSchema },
627
+ ...t.validatePatchSchema === void 0 ? {} : { validatePatchSchema: t.validatePatchSchema }
628
628
  });
629
629
  }),
630
- check: ((t, n) => {
631
- if (n.trim().length === 0) throw Error(`CHECK '${t}' on table '${e.tableName}' has an empty expression.`);
632
- if (x(e.tableName, t, !1, []), e.appliedChecks.some((e) => e.name === t)) throw Error(`duplicate CHECK '${t}' on table '${e.tableName}': each constraint name must be unique within a table.`);
630
+ check: ((e, n) => {
631
+ if (n.trim().length === 0) throw Error(`CHECK '${e}' on table '${t.tableName}' has an empty expression.`);
632
+ 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.`);
633
633
  return L({
634
- ...e,
635
- tableName: e.tableName,
636
- fields: e.fields,
637
- isReactive: e.isReactive,
638
- appliedMixins: e.appliedMixins,
639
- appliedIndexes: e.appliedIndexes,
640
- appliedUniques: e.appliedUniques,
641
- appliedFullText: e.appliedFullText,
642
- appliedChecks: [...e.appliedChecks, {
643
- name: t,
634
+ ...t,
635
+ tableName: t.tableName,
636
+ fields: t.fields,
637
+ isReactive: t.isReactive,
638
+ appliedMixins: t.appliedMixins,
639
+ appliedIndexes: t.appliedIndexes,
640
+ appliedUniques: t.appliedUniques,
641
+ appliedFullText: t.appliedFullText,
642
+ appliedChecks: [...t.appliedChecks, {
643
+ name: e,
644
644
  expr: n
645
645
  }],
646
- appliedPrimaryKey: e.appliedPrimaryKey,
647
- ...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
648
- ...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
646
+ appliedPrimaryKey: t.appliedPrimaryKey,
647
+ ...t.insertSchema === void 0 ? {} : { insertSchema: t.insertSchema },
648
+ ...t.validatePatchSchema === void 0 ? {} : { validatePatchSchema: t.validatePatchSchema }
649
649
  });
650
650
  }),
651
- rule: ((t, n, r) => {
652
- if (t.trim().length === 0) throw Error(`rule on table '${e.tableName}' has an empty name.`);
653
- let i = e.appliedRules ?? [];
654
- if (i.some((e) => e.name === t)) throw Error(`duplicate rule '${t}' on table '${e.tableName}': each rule name must be unique within a table.`);
651
+ rule: ((e, n, r) => {
652
+ if (e.trim().length === 0) throw Error(`rule on table '${t.tableName}' has an empty name.`);
653
+ let i = t.appliedRules ?? [];
654
+ 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.`);
655
655
  return L({
656
- ...e,
656
+ ...t,
657
657
  appliedRules: [...i, {
658
- name: t,
658
+ name: e,
659
659
  predicate: n,
660
660
  severity: r?.severity ?? "error"
661
661
  }]
662
662
  });
663
663
  }),
664
- renamedFrom: ((t) => {
665
- if (t === e.tableName) throw Error(`renamedFrom('${t}') on table '${e.tableName}' names the table itself — drop the marker, there is nothing to rename.`);
666
- return y(t), L({
667
- ...e,
668
- previousTableName: t
664
+ renamedFrom: ((e) => {
665
+ if (e === t.tableName) throw Error(`renamedFrom('${e}') on table '${t.tableName}' names the table itself — drop the marker, there is nothing to rename.`);
666
+ return y(e), L({
667
+ ...t,
668
+ previousTableName: e
669
669
  });
670
670
  }),
671
- primaryKey: ((n) => {
672
- if (n.length < 2) throw Error(`primaryKey([...]) on table '${e.tableName}' needs at least two columns — a single-column key is the default \`id()\` primary key.`);
671
+ primaryKey: ((e) => {
672
+ if (e.length < 2) throw Error(`primaryKey([...]) on table '${t.tableName}' needs at least two columns — a single-column key is the default \`id()\` primary key.`);
673
673
  let r = /* @__PURE__ */ new Set();
674
- for (let t of n) {
675
- if (!(t in e.fields)) throw Error(`primaryKey([...]) on table '${e.tableName}' references unknown column '${t}'.`);
676
- if (r.has(t)) throw Error(`primaryKey([...]) on table '${e.tableName}' lists column '${t}' twice.`);
677
- r.add(t);
674
+ for (let n of e) {
675
+ if (!(n in t.fields)) throw Error(`primaryKey([...]) on table '${t.tableName}' references unknown column '${n}'.`);
676
+ if (r.has(n)) throw Error(`primaryKey([...]) on table '${t.tableName}' lists column '${n}' twice.`);
677
+ r.add(n);
678
678
  }
679
- if (t.length > 0) throw Error(`primaryKey([...]) declared twice on table '${e.tableName}'.`);
680
- for (let [t, r] of Object.entries(e.fields)) if (r.type === "id" && !n.includes(t)) throw Error(`primaryKey([...]) on table '${e.tableName}' conflicts with the id() column '${t}'. A composite primary key IS the key — drop the id() column, or include '${t}' in the composite key.`);
679
+ if (n.length > 0) throw Error(`primaryKey([...]) declared twice on table '${t.tableName}'.`);
680
+ 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.`);
681
681
  return L({
682
- ...e,
683
- tableName: e.tableName,
684
- fields: e.fields,
685
- isReactive: e.isReactive,
686
- appliedMixins: e.appliedMixins,
687
- appliedIndexes: e.appliedIndexes,
688
- appliedUniques: e.appliedUniques,
689
- appliedFullText: e.appliedFullText,
690
- appliedChecks: e.appliedChecks,
691
- appliedPrimaryKey: [...n],
692
- ...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
693
- ...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
682
+ ...t,
683
+ tableName: t.tableName,
684
+ fields: t.fields,
685
+ isReactive: t.isReactive,
686
+ appliedMixins: t.appliedMixins,
687
+ appliedIndexes: t.appliedIndexes,
688
+ appliedUniques: t.appliedUniques,
689
+ appliedFullText: t.appliedFullText,
690
+ appliedChecks: t.appliedChecks,
691
+ appliedPrimaryKey: [...e],
692
+ ...t.insertSchema === void 0 ? {} : { insertSchema: t.insertSchema },
693
+ ...t.validatePatchSchema === void 0 ? {} : { validatePatchSchema: t.validatePatchSchema }
694
694
  });
695
695
  }),
696
696
  nonReactive: (() => L({
697
- ...e,
698
- tableName: e.tableName,
699
- fields: e.fields,
697
+ ...t,
698
+ tableName: t.tableName,
699
+ fields: t.fields,
700
700
  isReactive: !1,
701
- appliedMixins: e.appliedMixins,
702
- appliedIndexes: e.appliedIndexes,
703
- appliedUniques: e.appliedUniques,
704
- appliedFullText: e.appliedFullText,
705
- appliedChecks: e.appliedChecks,
706
- appliedPrimaryKey: e.appliedPrimaryKey,
707
- ...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
708
- ...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
701
+ appliedMixins: t.appliedMixins,
702
+ appliedIndexes: t.appliedIndexes,
703
+ appliedUniques: t.appliedUniques,
704
+ appliedFullText: t.appliedFullText,
705
+ appliedChecks: t.appliedChecks,
706
+ appliedPrimaryKey: t.appliedPrimaryKey,
707
+ ...t.insertSchema === void 0 ? {} : { insertSchema: t.insertSchema },
708
+ ...t.validatePatchSchema === void 0 ? {} : { validatePatchSchema: t.validatePatchSchema }
709
709
  })),
710
- validate: ((t) => L({
711
- ...e,
712
- tableName: e.tableName,
713
- fields: e.fields,
714
- isReactive: e.isReactive,
715
- appliedMixins: e.appliedMixins,
716
- appliedIndexes: e.appliedIndexes,
717
- appliedUniques: e.appliedUniques,
718
- appliedFullText: e.appliedFullText,
719
- appliedChecks: e.appliedChecks,
720
- appliedPrimaryKey: e.appliedPrimaryKey,
721
- insertSchema: t,
722
- ...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
710
+ validate: ((e) => L({
711
+ ...t,
712
+ tableName: t.tableName,
713
+ fields: t.fields,
714
+ isReactive: t.isReactive,
715
+ appliedMixins: t.appliedMixins,
716
+ appliedIndexes: t.appliedIndexes,
717
+ appliedUniques: t.appliedUniques,
718
+ appliedFullText: t.appliedFullText,
719
+ appliedChecks: t.appliedChecks,
720
+ appliedPrimaryKey: t.appliedPrimaryKey,
721
+ insertSchema: e,
722
+ ...t.validatePatchSchema === void 0 ? {} : { validatePatchSchema: t.validatePatchSchema }
723
723
  })),
724
- validatePatch: ((t) => L({
725
- ...e,
726
- tableName: e.tableName,
727
- fields: e.fields,
728
- isReactive: e.isReactive,
729
- appliedMixins: e.appliedMixins,
730
- appliedIndexes: e.appliedIndexes,
731
- appliedUniques: e.appliedUniques,
732
- appliedFullText: e.appliedFullText,
733
- appliedChecks: e.appliedChecks,
734
- appliedPrimaryKey: e.appliedPrimaryKey,
735
- ...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
736
- validatePatchSchema: n.partial(t)
724
+ validatePatch: ((n) => L({
725
+ ...t,
726
+ tableName: t.tableName,
727
+ fields: t.fields,
728
+ isReactive: t.isReactive,
729
+ appliedMixins: t.appliedMixins,
730
+ appliedIndexes: t.appliedIndexes,
731
+ appliedUniques: t.appliedUniques,
732
+ appliedFullText: t.appliedFullText,
733
+ appliedChecks: t.appliedChecks,
734
+ appliedPrimaryKey: t.appliedPrimaryKey,
735
+ ...t.insertSchema === void 0 ? {} : { insertSchema: t.insertSchema },
736
+ validatePatchSchema: e.partial(n)
737
737
  }))
738
738
  };
739
739
  }, R = (e, t) => {
@@ -758,7 +758,7 @@ var r = (e) => {
758
758
  appliedChecks: [],
759
759
  appliedRules: []
760
760
  });
761
- }, He = (e) => e === "sqlite" || e === "turso", z = (e, t) => {
761
+ }, He = (e) => e === "sqlite" || e === "turso", Ue = (e) => e === "mysql" || e === "mariadb", z = (e, t) => {
762
762
  switch (t) {
763
763
  case "mysql":
764
764
  case "mariadb": return `\`${e}\``;
@@ -767,45 +767,45 @@ var r = (e) => {
767
767
  case "sqlite":
768
768
  case "turso": return `"${e}"`;
769
769
  }
770
- }, Ue = 1e4, B = Symbol.for("@voltro/database/tableRegistry"), V = globalThis, H = V[B] ?? (V[B] = /* @__PURE__ */ new Map()), U = (e) => {
770
+ }, We = 1e4, B = Symbol.for("@voltro/database/tableRegistry"), V = globalThis, H = V[B] ?? (V[B] = /* @__PURE__ */ new Map()), U = (e) => {
771
771
  let t = H.get(e.tableName);
772
772
  if (t === void 0) {
773
773
  H.set(e.tableName, e);
774
774
  return;
775
775
  }
776
776
  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.`);
777
- }, We = (e) => {
777
+ }, Ge = (e) => {
778
778
  H.get(e.tableName) === void 0 && H.set(e.tableName, e);
779
- }, W = (e) => H.get(e), Ge = (e) => {
779
+ }, W = (e) => H.get(e), Ke = (e) => {
780
780
  let t = H.get(e);
781
781
  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.`);
782
782
  return t;
783
- }, Ke = () => [...H.values()], qe = () => {
783
+ }, qe = () => [...H.values()], Je = () => {
784
784
  H.clear();
785
- }, Je = (e) => H.get(e)?.isReactive !== !1, Ye = (e) => e.order ?? [], Xe = (e) => ({
785
+ }, Ye = (e) => H.get(e)?.isReactive !== !1, Xe = (e) => e.order ?? [], Ze = (e) => ({
786
786
  op: "count",
787
787
  alias: e ?? "count"
788
- }), Ze = (e, t) => ({
788
+ }), Qe = (e, t) => ({
789
789
  op: "count-distinct",
790
790
  column: e,
791
791
  alias: t ?? `count_distinct_${e}`
792
- }), Qe = (e, t) => ({
792
+ }), $e = (e, t) => ({
793
793
  op: "sum",
794
794
  column: e,
795
795
  alias: t ?? `sum_${e}`
796
- }), $e = (e, t) => ({
796
+ }), et = (e, t) => ({
797
797
  op: "avg",
798
798
  column: e,
799
799
  alias: t ?? `avg_${e}`
800
- }), et = (e, t) => ({
800
+ }), tt = (e, t) => ({
801
801
  op: "min",
802
802
  column: e,
803
803
  alias: t ?? `min_${e}`
804
- }), tt = (e, t) => ({
804
+ }), nt = (e, t) => ({
805
805
  op: "max",
806
806
  column: e,
807
807
  alias: t ?? `max_${e}`
808
- }), nt = (e, t) => ({
808
+ }), rt = (e, t) => ({
809
809
  op: "column",
810
810
  column: e,
811
811
  alias: t ?? e
@@ -823,33 +823,33 @@ var r = (e) => {
823
823
  queries: t.map((e) => e.descriptor)
824
824
  }
825
825
  });
826
- }, rt = G("union"), it = G("union-all"), at = G("intersect"), ot = G("except"), K = (e) => ({ over: (t) => ({
826
+ }, it = G("union"), at = G("union-all"), ot = G("intersect"), st = G("except"), K = (e) => ({ over: (t) => ({
827
827
  ...e,
828
828
  window: t
829
- }) }), st = (e = "rowNumber") => K({
829
+ }) }), ct = (e = "rowNumber") => K({
830
830
  op: "window-row-number",
831
831
  alias: e
832
- }), ct = (e = "rank") => K({
832
+ }), lt = (e = "rank") => K({
833
833
  op: "window-rank",
834
834
  alias: e
835
- }), lt = (e = "denseRank") => K({
835
+ }), ut = (e = "denseRank") => K({
836
836
  op: "window-dense-rank",
837
837
  alias: e
838
- }), ut = (e, t = 1, n) => K({
838
+ }), dt = (e, t = 1, n) => K({
839
839
  op: "window-lag",
840
840
  column: e,
841
841
  alias: n ?? `lag_${e}`,
842
842
  offset: t
843
- }), dt = (e, t = 1, n) => K({
843
+ }), ft = (e, t = 1, n) => K({
844
844
  op: "window-lead",
845
845
  column: e,
846
846
  alias: n ?? `lead_${e}`,
847
847
  offset: t
848
- }), ft = (e, t) => K({
848
+ }), pt = (e, t) => K({
849
849
  op: "window-sum-over",
850
850
  column: e,
851
851
  alias: t ?? `sum_${e}_over`
852
- }), pt = (e, t) => K({
852
+ }), mt = (e, t) => K({
853
853
  op: "window-avg-over",
854
854
  column: e,
855
855
  alias: t ?? `avg_${e}_over`
@@ -1131,7 +1131,7 @@ function Y(e) {
1131
1131
  sourceTable: e
1132
1132
  });
1133
1133
  }
1134
- var mt = (e, t, n) => X(e, "id", t, n), X = (e, t, n, r, i = "asc") => {
1134
+ var ht = (e, t, n) => X(e, "id", t, n), X = (e, t, n, r, i = "asc") => {
1135
1135
  let a = [...e.order.filter((e) => e.column !== t), {
1136
1136
  column: t,
1137
1137
  direction: i
@@ -1146,11 +1146,11 @@ var mt = (e, t, n) => X(e, "id", t, n), X = (e, t, n, r, i = "asc") => {
1146
1146
  order: a,
1147
1147
  take: r
1148
1148
  };
1149
- }, ht = (e) => {
1149
+ }, gt = (e) => {
1150
1150
  let t = {};
1151
1151
  for (let [n, r] of Object.entries(e)) U(r), t[n] = Y(r);
1152
1152
  return t;
1153
- }, gt = (e) => e.isView === !0, _t = (e, t, n) => {
1153
+ }, _t = (e) => e.isView === !0, vt = (e, t, n) => {
1154
1154
  if (y(e), n.trim().length === 0) throw Error(`view('${e}', …): the SELECT body is empty — a view must define a query.`);
1155
1155
  let r = f(t);
1156
1156
  for (let t of Object.keys(r)) b(e, t);
@@ -1160,7 +1160,7 @@ var mt = (e, t, n) => X(e, "id", t, n), X = (e, t, n, r, i = "asc") => {
1160
1160
  isView: !0,
1161
1161
  viewSelect: n
1162
1162
  };
1163
- }, vt = (e) => Y({
1163
+ }, yt = (e) => Y({
1164
1164
  ...e,
1165
1165
  isReactive: !1,
1166
1166
  appliedMixins: [],
@@ -1168,7 +1168,7 @@ var mt = (e, t, n) => X(e, "id", t, n), X = (e, t, n, r, i = "asc") => {
1168
1168
  appliedUniques: [],
1169
1169
  appliedFullText: [],
1170
1170
  appliedChecks: []
1171
- }), yt = (e, t, n = null) => {
1171
+ }), bt = (e, t, n = null) => {
1172
1172
  let r = n === null ? z(e.tableName, t) : `${z(n, t)}.${z(e.tableName, t)}`, i = e.viewSelect.trim();
1173
1173
  switch (t) {
1174
1174
  case "postgres":
@@ -1178,16 +1178,16 @@ var mt = (e, t, n) => X(e, "id", t, n), X = (e, t, n, r, i = "asc") => {
1178
1178
  case "sqlite":
1179
1179
  case "turso": return `DROP VIEW IF EXISTS ${r};\nCREATE VIEW ${r} AS ${i};`;
1180
1180
  }
1181
- }, bt = /^[A-Za-z_][A-Za-z0-9_]*$/, xt = (e) => "$" + e.map((e) => typeof e == "number" ? `[${e}]` : bt.test(e) ? `.${e}` : `."${e.replace(/"/g, "\\\"")}"`).join(""), St = (e) => "{" + e.map((e) => {
1181
+ }, xt = /^[A-Za-z_][A-Za-z0-9_]*$/, St = (e) => "$" + e.map((e) => typeof e == "number" ? `[${e}]` : xt.test(e) ? `.${e}` : `."${e.replace(/"/g, "\\\"")}"`).join(""), Ct = (e) => "{" + e.map((e) => {
1182
1182
  let t = String(e);
1183
1183
  return /^[A-Za-z0-9_]+$/.test(t) ? t : `"${t.replace(/(["\\])/g, "\\$1")}"`;
1184
- }).join(",") + "}", Ct = (e, t, n, r = {}) => {
1184
+ }).join(",") + "}", wt = (e, t, n, r = {}) => {
1185
1185
  let i = z(e, n), a = r.numeric ?? !1;
1186
1186
  if (n === "postgres") {
1187
- let e = `(${i} #>> '${St(t)}'::text[])`;
1187
+ let e = `(${i} #>> '${Ct(t)}'::text[])`;
1188
1188
  return a ? `${e}::numeric` : e;
1189
1189
  }
1190
- let o = xt(t);
1190
+ let o = St(t);
1191
1191
  switch (n) {
1192
1192
  case "mysql":
1193
1193
  case "mariadb": {
@@ -1204,13 +1204,13 @@ var mt = (e, t, n) => X(e, "id", t, n), X = (e, t, n, r, i = "asc") => {
1204
1204
  return a ? `CAST(${e} AS REAL)` : e;
1205
1205
  }
1206
1206
  }
1207
- }, wt = (e, t) => ({
1207
+ }, Tt = (e, t) => ({
1208
1208
  name: e,
1209
1209
  body: t
1210
- }), Tt = (e) => {
1210
+ }), Et = (e) => {
1211
1211
  if (e.lifecycle === "cron" && !e.cron) throw Error(`seed "${e.id}": lifecycle 'cron' requires a 'cron' field`);
1212
1212
  if (e.lifecycle === "onSchemaChange" && (!e.watchedTables || e.watchedTables.length === 0)) throw Error(`seed "${e.id}": lifecycle 'onSchemaChange' requires at least one entry in 'watchedTables'`);
1213
- let t = e.steps({ step: wt });
1213
+ let t = e.steps({ step: Tt });
1214
1214
  if (t.length === 0) throw Error(`seed "${e.id}": at least one step is required`);
1215
1215
  return {
1216
1216
  __seed: !0,
@@ -1223,20 +1223,20 @@ var mt = (e, t, n) => X(e, "id", t, n), X = (e, t, n, r, i = "asc") => {
1223
1223
  ...e.fingerprint === void 0 ? {} : { fingerprint: e.fingerprint },
1224
1224
  steps: t
1225
1225
  };
1226
- }, Et = (e) => typeof e == "object" && !!e && "__seed" in e && e.__seed === !0, Z = null, Q = null, Dt = (e) => {
1226
+ }, Dt = (e) => typeof e == "object" && !!e && "__seed" in e && e.__seed === !0, Z = null, Q = null, Ot = (e) => {
1227
1227
  Z = e;
1228
- }, Ot = (e) => {
1228
+ }, kt = (e) => {
1229
1229
  Q = e;
1230
- }, kt = async (e) => {
1230
+ }, At = async (e) => {
1231
1231
  let t = Z;
1232
1232
  t !== null && await t(e);
1233
- }, At = async (e) => {
1233
+ }, jt = async (e) => {
1234
1234
  let t = Q;
1235
1235
  t !== null && e.changedTables.length !== 0 && await t(e);
1236
- }, jt = (e) => {
1236
+ }, Mt = (e) => {
1237
1237
  if (!e.id || e.id.length === 0) throw Error("migration: `id` is required + must be non-empty");
1238
1238
  if (!e.up || !e.down) throw Error(`migration ${e.id}: both \`up\` and \`down\` must be functions`);
1239
1239
  return e;
1240
- }, Mt = /^\d{8}_\d{6}_[a-z0-9_]+\.ts$/, Nt = (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", $ = /* @__PURE__ */ new Set(["voltro_isr_cache"]), Pt = (e) => $.has(e) || e.startsWith("_voltro_") || e.startsWith("_cloud_") || e.startsWith("cluster_"), Ft = /__dropped_\d{14}$/, It = (e) => Ft.test(e);
1240
+ }, Nt = /^\d{8}_\d{6}_[a-z0-9_]+\.ts$/, Pt = (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", $ = /* @__PURE__ */ new Set(["voltro_isr_cache"]), Ft = (e) => $.has(e) || e.startsWith("_voltro_") || e.startsWith("_cloud_") || e.startsWith("cluster_"), It = /__dropped_\d{14}$/, Lt = (e) => It.test(e);
1241
1241
  //#endregion
1242
- export { Le as $, et as A, ce as At, rt as B, f as Bt, ht as C, o as Ct, ut as D, ue as Dt, at as E, oe as Et, ct as F, ge as Ft, W as G, d as Gt, Ke as H, _e as Ht, q as I, ee as It, Ge as J, se as Jt, Je as K, r as Kt, st as L, te as Lt, X as M, l as Mt, mt as N, de as Nt, dt as O, a as Ot, Y as P, he as Pt, ze as Q, Qe as R, me as Rt, Ze as S, m as St, ot as T, ie as Tt, qe as U, i as Ut, it as V, re as Vt, We as W, ne as Wt, He as X, Ue as Y, fe as Yt, z as Z, yt as _, xe as _t, Nt as a, A as at, nt as b, be as bt, At as c, k as ct, Ot as d, we as dt, R as et, Dt as f, Te as ft, _t as g, S as gt, vt as h, y as ht, Mt as i, N as it, Ye as j, ae as jt, tt as k, u as kt, kt as l, Ne as lt, gt as m, x as mt, Pt as n, Ie as nt, jt as o, Fe as ot, Ct as p, b as pt, U as q, c as qt, It as r, M as rt, Tt as s, j as st, $ as t, Re as tt, Et as u, Ce as ut, $e as v, Se as vt, lt as w, pe as wt, Xe as x, ve as xt, pt as y, ye as yt, ft as z, le as zt };
1242
+ export { ze as $, tt as A, u as At, it as B, le as Bt, gt as C, m as Ct, dt as D, oe as Dt, ot as E, ie as Et, lt as F, he as Ft, W as G, ne as Gt, qe as H, re as Ht, q as I, ge as It, Ke as J, c as Jt, Ye as K, d as Kt, ct as L, ee as Lt, X as M, ae as Mt, ht as N, l as Nt, ft as O, ue as Ot, Y as P, de as Pt, z as Q, $e as R, te as Rt, Qe as S, ve as St, st as T, pe as Tt, Je as U, _e as Ut, at as V, f as Vt, Ge as W, i as Wt, Ue as X, fe as Xt, We as Y, se as Yt, He as Z, bt as _, S as _t, Pt as a, N as at, rt as b, ye as bt, jt as c, j as ct, kt as d, Ce as dt, Le as et, Ot as f, we as ft, vt as g, y as gt, yt as h, x as ht, Nt as i, M as it, Xe as j, ce as jt, nt as k, a as kt, At as l, k as lt, _t as m, b as mt, Ft as n, Re as nt, Mt as o, A as ot, wt as p, Te as pt, U as q, r as qt, Lt as r, Ie as rt, Et as s, Fe as st, $ as t, R as tt, Dt as u, Ne as ut, et as v, xe as vt, ut as w, o as wt, Ze as x, be as xt, mt as y, Se as yt, pt as z, me as zt };