@voltro/database 0.41.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.
- package/CHANGELOG.md +97 -0
- package/dist/{frameworkLiveTables-BS6FuivX.js → frameworkLiveTables-XPFqj8n3.js} +247 -247
- package/dist/index.d.ts +87 -0
- package/dist/index.js +786 -651
- package/dist/sql.d.ts +44 -4
- package/dist/sql.js +854 -796
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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 = (
|
|
389
|
-
switch (
|
|
390
|
-
case "typeid": return e
|
|
391
|
-
case "ulid": return
|
|
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
|
|
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 = (
|
|
456
|
-
let
|
|
455
|
+
}, L = (t) => {
|
|
456
|
+
let n = t.appliedPrimaryKey ?? [];
|
|
457
457
|
return {
|
|
458
|
-
tableName:
|
|
459
|
-
fields:
|
|
460
|
-
isReactive:
|
|
461
|
-
appliedMixins:
|
|
462
|
-
appliedIndexes:
|
|
463
|
-
appliedUniques:
|
|
464
|
-
appliedFullText:
|
|
465
|
-
appliedChecks:
|
|
466
|
-
appliedRules:
|
|
467
|
-
appliedPluginRefs:
|
|
468
|
-
appliedPrimaryKey:
|
|
469
|
-
...
|
|
470
|
-
...
|
|
471
|
-
...
|
|
472
|
-
fullTextIndex: ((
|
|
473
|
-
if (n.length === 0) throw Error(`fullTextIndex '${
|
|
474
|
-
if (x(
|
|
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
|
-
...
|
|
477
|
-
tableName:
|
|
478
|
-
fields:
|
|
479
|
-
isReactive:
|
|
480
|
-
appliedMixins:
|
|
481
|
-
appliedIndexes:
|
|
482
|
-
appliedUniques:
|
|
483
|
-
appliedChecks:
|
|
484
|
-
appliedPrimaryKey:
|
|
485
|
-
appliedFullText: [...
|
|
486
|
-
name:
|
|
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
|
-
...
|
|
492
|
-
...
|
|
491
|
+
...t.insertSchema === void 0 ? {} : { insertSchema: t.insertSchema },
|
|
492
|
+
...t.validatePatchSchema === void 0 ? {} : { validatePatchSchema: t.validatePatchSchema }
|
|
493
493
|
});
|
|
494
494
|
}),
|
|
495
|
-
with: ((...
|
|
496
|
-
let n = N(
|
|
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
|
|
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 '${
|
|
504
|
-
b(
|
|
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 = [...
|
|
507
|
-
for (let
|
|
508
|
-
let
|
|
509
|
-
a.some((
|
|
510
|
-
name:
|
|
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
|
-
...
|
|
518
|
-
tableName:
|
|
517
|
+
...t,
|
|
518
|
+
tableName: t.tableName,
|
|
519
519
|
fields: r,
|
|
520
|
-
isReactive:
|
|
521
|
-
appliedMixins: [...
|
|
520
|
+
isReactive: t.isReactive,
|
|
521
|
+
appliedMixins: [...t.appliedMixins, ...n],
|
|
522
522
|
appliedIndexes: a,
|
|
523
|
-
appliedUniques:
|
|
524
|
-
appliedFullText:
|
|
525
|
-
appliedChecks:
|
|
526
|
-
appliedPrimaryKey:
|
|
527
|
-
...
|
|
528
|
-
...
|
|
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: ((...
|
|
532
|
-
let n, r, i, a = Array.isArray(
|
|
533
|
-
if (a ? (r =
|
|
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(
|
|
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
|
-
...
|
|
538
|
-
tableName:
|
|
539
|
-
fields:
|
|
540
|
-
isReactive:
|
|
541
|
-
appliedMixins:
|
|
542
|
-
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:
|
|
550
|
-
appliedFullText:
|
|
551
|
-
appliedChecks:
|
|
552
|
-
appliedPrimaryKey:
|
|
553
|
-
...
|
|
554
|
-
...
|
|
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: ((
|
|
558
|
-
if (n.length === 0) throw Error(`expressionIndex '${
|
|
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(
|
|
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
|
-
...
|
|
563
|
-
tableName:
|
|
564
|
-
fields:
|
|
565
|
-
isReactive:
|
|
566
|
-
appliedMixins:
|
|
567
|
-
appliedIndexes: [...
|
|
568
|
-
name:
|
|
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:
|
|
575
|
-
appliedFullText:
|
|
576
|
-
appliedChecks:
|
|
577
|
-
appliedPrimaryKey:
|
|
578
|
-
...
|
|
579
|
-
...
|
|
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: ((...
|
|
583
|
-
let n, r, i, a = Array.isArray(
|
|
584
|
-
if (a ? (r =
|
|
585
|
-
if (x(
|
|
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
|
-
...
|
|
588
|
-
tableName:
|
|
589
|
-
fields:
|
|
590
|
-
isReactive:
|
|
591
|
-
appliedMixins:
|
|
592
|
-
appliedIndexes:
|
|
593
|
-
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:
|
|
599
|
-
appliedChecks:
|
|
600
|
-
appliedPrimaryKey:
|
|
601
|
-
...
|
|
602
|
-
...
|
|
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: ((...
|
|
606
|
-
let n, r, i, a = Array.isArray(
|
|
607
|
-
if (a ? (r =
|
|
608
|
-
if (x(
|
|
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
|
-
...
|
|
612
|
-
tableName:
|
|
613
|
-
fields:
|
|
614
|
-
isReactive:
|
|
615
|
-
appliedMixins:
|
|
616
|
-
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:
|
|
623
|
-
appliedFullText:
|
|
624
|
-
appliedChecks:
|
|
625
|
-
appliedPrimaryKey:
|
|
626
|
-
...
|
|
627
|
-
...
|
|
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: ((
|
|
631
|
-
if (n.trim().length === 0) throw Error(`CHECK '${
|
|
632
|
-
if (x(
|
|
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
|
-
...
|
|
635
|
-
tableName:
|
|
636
|
-
fields:
|
|
637
|
-
isReactive:
|
|
638
|
-
appliedMixins:
|
|
639
|
-
appliedIndexes:
|
|
640
|
-
appliedUniques:
|
|
641
|
-
appliedFullText:
|
|
642
|
-
appliedChecks: [...
|
|
643
|
-
name:
|
|
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:
|
|
647
|
-
...
|
|
648
|
-
...
|
|
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: ((
|
|
652
|
-
if (
|
|
653
|
-
let i =
|
|
654
|
-
if (i.some((
|
|
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
|
-
...
|
|
656
|
+
...t,
|
|
657
657
|
appliedRules: [...i, {
|
|
658
|
-
name:
|
|
658
|
+
name: e,
|
|
659
659
|
predicate: n,
|
|
660
660
|
severity: r?.severity ?? "error"
|
|
661
661
|
}]
|
|
662
662
|
});
|
|
663
663
|
}),
|
|
664
|
-
renamedFrom: ((
|
|
665
|
-
if (
|
|
666
|
-
return y(
|
|
667
|
-
...
|
|
668
|
-
previousTableName:
|
|
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: ((
|
|
672
|
-
if (
|
|
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
|
|
675
|
-
if (!(
|
|
676
|
-
if (r.has(
|
|
677
|
-
r.add(
|
|
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 (
|
|
680
|
-
for (let [
|
|
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
|
-
...
|
|
683
|
-
tableName:
|
|
684
|
-
fields:
|
|
685
|
-
isReactive:
|
|
686
|
-
appliedMixins:
|
|
687
|
-
appliedIndexes:
|
|
688
|
-
appliedUniques:
|
|
689
|
-
appliedFullText:
|
|
690
|
-
appliedChecks:
|
|
691
|
-
appliedPrimaryKey: [...
|
|
692
|
-
...
|
|
693
|
-
...
|
|
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
|
-
...
|
|
698
|
-
tableName:
|
|
699
|
-
fields:
|
|
697
|
+
...t,
|
|
698
|
+
tableName: t.tableName,
|
|
699
|
+
fields: t.fields,
|
|
700
700
|
isReactive: !1,
|
|
701
|
-
appliedMixins:
|
|
702
|
-
appliedIndexes:
|
|
703
|
-
appliedUniques:
|
|
704
|
-
appliedFullText:
|
|
705
|
-
appliedChecks:
|
|
706
|
-
appliedPrimaryKey:
|
|
707
|
-
...
|
|
708
|
-
...
|
|
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: ((
|
|
711
|
-
...
|
|
712
|
-
tableName:
|
|
713
|
-
fields:
|
|
714
|
-
isReactive:
|
|
715
|
-
appliedMixins:
|
|
716
|
-
appliedIndexes:
|
|
717
|
-
appliedUniques:
|
|
718
|
-
appliedFullText:
|
|
719
|
-
appliedChecks:
|
|
720
|
-
appliedPrimaryKey:
|
|
721
|
-
insertSchema:
|
|
722
|
-
...
|
|
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: ((
|
|
725
|
-
...
|
|
726
|
-
tableName:
|
|
727
|
-
fields:
|
|
728
|
-
isReactive:
|
|
729
|
-
appliedMixins:
|
|
730
|
-
appliedIndexes:
|
|
731
|
-
appliedUniques:
|
|
732
|
-
appliedFullText:
|
|
733
|
-
appliedChecks:
|
|
734
|
-
appliedPrimaryKey:
|
|
735
|
-
...
|
|
736
|
-
validatePatchSchema:
|
|
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
|
-
},
|
|
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
|
-
},
|
|
777
|
+
}, Ge = (e) => {
|
|
778
778
|
H.get(e.tableName) === void 0 && H.set(e.tableName, e);
|
|
779
|
-
}, W = (e) => H.get(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
|
-
},
|
|
783
|
+
}, qe = () => [...H.values()], Je = () => {
|
|
784
784
|
H.clear();
|
|
785
|
-
},
|
|
785
|
+
}, Ye = (e) => H.get(e)?.isReactive !== !1, Xe = (e) => e.order ?? [], Ze = (e) => ({
|
|
786
786
|
op: "count",
|
|
787
787
|
alias: e ?? "count"
|
|
788
|
-
}),
|
|
788
|
+
}), Qe = (e, t) => ({
|
|
789
789
|
op: "count-distinct",
|
|
790
790
|
column: e,
|
|
791
791
|
alias: t ?? `count_distinct_${e}`
|
|
792
|
-
}),
|
|
792
|
+
}), $e = (e, t) => ({
|
|
793
793
|
op: "sum",
|
|
794
794
|
column: e,
|
|
795
795
|
alias: t ?? `sum_${e}`
|
|
796
|
-
}),
|
|
796
|
+
}), et = (e, t) => ({
|
|
797
797
|
op: "avg",
|
|
798
798
|
column: e,
|
|
799
799
|
alias: t ?? `avg_${e}`
|
|
800
|
-
}),
|
|
800
|
+
}), tt = (e, t) => ({
|
|
801
801
|
op: "min",
|
|
802
802
|
column: e,
|
|
803
803
|
alias: t ?? `min_${e}`
|
|
804
|
-
}),
|
|
804
|
+
}), nt = (e, t) => ({
|
|
805
805
|
op: "max",
|
|
806
806
|
column: e,
|
|
807
807
|
alias: t ?? `max_${e}`
|
|
808
|
-
}),
|
|
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
|
-
},
|
|
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
|
-
}) }),
|
|
829
|
+
}) }), ct = (e = "rowNumber") => K({
|
|
830
830
|
op: "window-row-number",
|
|
831
831
|
alias: e
|
|
832
|
-
}),
|
|
832
|
+
}), lt = (e = "rank") => K({
|
|
833
833
|
op: "window-rank",
|
|
834
834
|
alias: e
|
|
835
|
-
}),
|
|
835
|
+
}), ut = (e = "denseRank") => K({
|
|
836
836
|
op: "window-dense-rank",
|
|
837
837
|
alias: e
|
|
838
|
-
}),
|
|
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
|
-
}),
|
|
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
|
-
}),
|
|
848
|
+
}), pt = (e, t) => K({
|
|
849
849
|
op: "window-sum-over",
|
|
850
850
|
column: e,
|
|
851
851
|
alias: t ?? `sum_${e}_over`
|
|
852
|
-
}),
|
|
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
|
|
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
|
-
},
|
|
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
|
-
},
|
|
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
|
-
},
|
|
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
|
-
}),
|
|
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
|
-
},
|
|
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(",") + "}",
|
|
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} #>> '${
|
|
1187
|
+
let e = `(${i} #>> '${Ct(t)}'::text[])`;
|
|
1188
1188
|
return a ? `${e}::numeric` : e;
|
|
1189
1189
|
}
|
|
1190
|
-
let o =
|
|
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
|
-
},
|
|
1207
|
+
}, Tt = (e, t) => ({
|
|
1208
1208
|
name: e,
|
|
1209
1209
|
body: t
|
|
1210
|
-
}),
|
|
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:
|
|
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
|
-
},
|
|
1226
|
+
}, Dt = (e) => typeof e == "object" && !!e && "__seed" in e && e.__seed === !0, Z = null, Q = null, Ot = (e) => {
|
|
1227
1227
|
Z = e;
|
|
1228
|
-
},
|
|
1228
|
+
}, kt = (e) => {
|
|
1229
1229
|
Q = e;
|
|
1230
|
-
},
|
|
1230
|
+
}, At = async (e) => {
|
|
1231
1231
|
let t = Z;
|
|
1232
1232
|
t !== null && await t(e);
|
|
1233
|
-
},
|
|
1233
|
+
}, jt = async (e) => {
|
|
1234
1234
|
let t = Q;
|
|
1235
1235
|
t !== null && e.changedTables.length !== 0 && await t(e);
|
|
1236
|
-
},
|
|
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
|
-
},
|
|
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 {
|
|
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 };
|