@voltro/database 0.56.0 → 0.58.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 +395 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.js +624 -609
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -311,7 +311,22 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
311
311
|
if (globalThis.Buffer !== void 0 && globalThis.Buffer.isBuffer(e)) return "Buffer";
|
|
312
312
|
let t = e.constructor?.name;
|
|
313
313
|
return typeof t == "string" && t !== "" ? t : "Object";
|
|
314
|
-
}, yn = (e) => {
|
|
314
|
+
}, yn = Symbol.for("@voltro/database/storeRefusal"), bn = (e) => {
|
|
315
|
+
let t = Error(e.detail);
|
|
316
|
+
return Object.defineProperty(t, yn, {
|
|
317
|
+
value: e,
|
|
318
|
+
enumerable: !1
|
|
319
|
+
}), t;
|
|
320
|
+
}, xn = (e) => {
|
|
321
|
+
for (let t of sn(e)) {
|
|
322
|
+
let e = t;
|
|
323
|
+
for (let t = 0; e != null && t < 8; t += 1) {
|
|
324
|
+
let t = e[yn];
|
|
325
|
+
if (t !== void 0) return t;
|
|
326
|
+
e = e.cause;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}, Sn = (e) => {
|
|
315
330
|
let t = (() => {
|
|
316
331
|
switch (e.type) {
|
|
317
332
|
case "id":
|
|
@@ -332,41 +347,41 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
332
347
|
}
|
|
333
348
|
})();
|
|
334
349
|
return e.nullable === !0 ? A.NullOr(t) : t;
|
|
335
|
-
},
|
|
350
|
+
}, Cn = (e, t) => {
|
|
336
351
|
let n = new Set(t?.omit ?? []), r = {};
|
|
337
|
-
for (let [t, i] of Object.entries(e.fields)) n.has(t) || (r[t] =
|
|
352
|
+
for (let [t, i] of Object.entries(e.fields)) n.has(t) || (r[t] = Sn(i));
|
|
338
353
|
return A.Struct(r);
|
|
339
|
-
},
|
|
354
|
+
}, wn = (e) => typeof e == "function" ? e : () => e, Tn = (e, t) => ({
|
|
340
355
|
kind: "one",
|
|
341
|
-
target:
|
|
356
|
+
target: wn(e),
|
|
342
357
|
...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
|
|
343
358
|
...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
|
|
344
|
-
}),
|
|
359
|
+
}), En = (e, t) => ({
|
|
345
360
|
kind: "many",
|
|
346
|
-
target:
|
|
361
|
+
target: wn(e),
|
|
347
362
|
...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
|
|
348
363
|
...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
|
|
349
|
-
}),
|
|
364
|
+
}), Dn = (e, t) => ({
|
|
350
365
|
kind: "manyToMany",
|
|
351
|
-
target:
|
|
352
|
-
through:
|
|
366
|
+
target: wn(e),
|
|
367
|
+
through: wn(t.through),
|
|
353
368
|
sourceKey: t.sourceKey,
|
|
354
369
|
targetKey: t.targetKey
|
|
355
|
-
}),
|
|
356
|
-
one:
|
|
357
|
-
many:
|
|
358
|
-
manyToMany:
|
|
359
|
-
},
|
|
370
|
+
}), On = {
|
|
371
|
+
one: Tn,
|
|
372
|
+
many: En,
|
|
373
|
+
manyToMany: Dn
|
|
374
|
+
}, kn = (e, t) => {
|
|
360
375
|
let n = typeof e == "function" ? e : () => e;
|
|
361
376
|
return {
|
|
362
377
|
source: n,
|
|
363
|
-
relations: t(
|
|
378
|
+
relations: t(On, n())
|
|
364
379
|
};
|
|
365
|
-
},
|
|
380
|
+
}, An = (e) => {
|
|
366
381
|
if (typeof e != "object" || !e) return !1;
|
|
367
382
|
let t = e;
|
|
368
383
|
return typeof t.source != "function" || typeof t.relations != "object" || t.relations === null ? !1 : Object.keys(t.relations).length === 0;
|
|
369
|
-
},
|
|
384
|
+
}, jn = (e) => {
|
|
370
385
|
if (typeof e != "object" || !e) return !1;
|
|
371
386
|
let t = e;
|
|
372
387
|
if (typeof t.source != "function" || typeof t.relations != "object" || t.relations === null) return !1;
|
|
@@ -375,35 +390,35 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
375
390
|
let t = e?.kind;
|
|
376
391
|
return t === "one" || t === "many" || t === "manyToMany";
|
|
377
392
|
});
|
|
378
|
-
},
|
|
393
|
+
}, Mn = Tn, Nn = En, Pn = Dn, Fn = (e, t, n) => {
|
|
379
394
|
let r = [];
|
|
380
395
|
for (let [n, i] of Object.entries(e.fields)) i.type === "reference" && i.references?.()?.tableName === t && r.push(n);
|
|
381
396
|
if (r.length === 0) throw Error(`relation '${n}': no reference() column on '${e.tableName}' points at '${t}'. Either add one or pass an explicit { foreignKey: '<column>' }.`);
|
|
382
397
|
if (r.length > 1) throw Error(`relation '${n}': multiple reference() columns on '${e.tableName}' point at '${t}' (${r.join(", ")}). Pass an explicit { foreignKey: '<column>' } to disambiguate.`);
|
|
383
398
|
return r[0];
|
|
384
|
-
},
|
|
385
|
-
let t =
|
|
399
|
+
}, In = (e) => Object.keys(e.fields), Ln = (e, t) => Object.prototype.hasOwnProperty.call(e.fields, t), Rn = (e) => {
|
|
400
|
+
let t = In(e);
|
|
386
401
|
return t.length === 0 ? "<none>" : t.join(", ");
|
|
387
|
-
},
|
|
402
|
+
}, zn = (e, t, n) => {
|
|
388
403
|
let r = `relation '${t}' on '${e.tableName}'`, i = n.target();
|
|
389
404
|
if (n.kind === "manyToMany") {
|
|
390
405
|
let t = n.through();
|
|
391
|
-
for (let [a, o] of [["sourceKey", n.sourceKey], ["targetKey", n.targetKey]]) if (!
|
|
406
|
+
for (let [a, o] of [["sourceKey", n.sourceKey], ["targetKey", n.targetKey]]) if (!Ln(t, o)) throw Error(`${r}: manyToMany ${a} '${o}' is not a column on the junction table '${t.tableName}'. Both keys name columns on the JUNCTION — ${a === "sourceKey" ? `sourceKey points at '${e.tableName}'` : `targetKey points at '${i.tableName}'`}. Columns on '${t.tableName}': ${Rn(t)}.`);
|
|
392
407
|
return;
|
|
393
408
|
}
|
|
394
409
|
if (n.sourceKey !== void 0 && n.foreignKey !== void 0) throw Error(`${r}: pass EITHER sourceKey OR foreignKey, not both. sourceKey '${n.sourceKey}' names a column on the source ('${e.tableName}') holding the target's id; foreignKey '${n.foreignKey}' names a column on the target ('${i.tableName}') holding the source's id. With both, foreignKey is ignored.`);
|
|
395
|
-
if (n.sourceKey !== void 0 && !
|
|
396
|
-
let t =
|
|
397
|
-
throw Error(`${r}: sourceKey '${n.sourceKey}' is not a column on the source table '${e.tableName}'.` + (t ? ` It IS a column on the target '${i.tableName}' — you probably want { foreignKey: '${n.sourceKey}' }, which names the column on the TARGET that holds this table's id.` : ` Columns on '${e.tableName}': ${
|
|
410
|
+
if (n.sourceKey !== void 0 && !Ln(e, n.sourceKey)) {
|
|
411
|
+
let t = Ln(i, n.sourceKey);
|
|
412
|
+
throw Error(`${r}: sourceKey '${n.sourceKey}' is not a column on the source table '${e.tableName}'.` + (t ? ` It IS a column on the target '${i.tableName}' — you probably want { foreignKey: '${n.sourceKey}' }, which names the column on the TARGET that holds this table's id.` : ` Columns on '${e.tableName}': ${Rn(e)}.`));
|
|
398
413
|
}
|
|
399
|
-
if (n.foreignKey !== void 0 && !
|
|
400
|
-
let t =
|
|
401
|
-
throw Error(`${r}: foreignKey '${n.foreignKey}' is not a column on the target table '${i.tableName}'.` + (t ? ` It IS a column on the source '${e.tableName}' — you want { sourceKey: '${n.foreignKey}' }. foreignKey names the column on the TARGET that points back at this table; sourceKey names the column on THIS table that holds the target's id.` : ` Columns on '${i.tableName}': ${
|
|
414
|
+
if (n.foreignKey !== void 0 && !Ln(i, n.foreignKey)) {
|
|
415
|
+
let t = Ln(e, n.foreignKey);
|
|
416
|
+
throw Error(`${r}: foreignKey '${n.foreignKey}' is not a column on the target table '${i.tableName}'.` + (t ? ` It IS a column on the source '${e.tableName}' — you want { sourceKey: '${n.foreignKey}' }. foreignKey names the column on the TARGET that points back at this table; sourceKey names the column on THIS table that holds the target's id.` : ` Columns on '${i.tableName}': ${Rn(i)}.`));
|
|
402
417
|
}
|
|
403
|
-
},
|
|
404
|
-
let t = e.source(), n =
|
|
418
|
+
}, Bn = Symbol.for("@voltro/database/relationsRegistry"), Vn = globalThis, P = Vn[Bn] ?? (Vn[Bn] = /* @__PURE__ */ new Map()), Hn = (e) => {
|
|
419
|
+
let t = e.source(), n = P.get(t.tableName);
|
|
405
420
|
if (n === void 0) {
|
|
406
|
-
|
|
421
|
+
P.set(t.tableName, new Map(Object.entries(e.relations)));
|
|
407
422
|
return;
|
|
408
423
|
}
|
|
409
424
|
for (let [r, i] of Object.entries(e.relations)) {
|
|
@@ -413,33 +428,33 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
413
428
|
n.set(r, i);
|
|
414
429
|
}
|
|
415
430
|
}
|
|
416
|
-
},
|
|
431
|
+
}, Un = (e) => {
|
|
417
432
|
let t = 0;
|
|
418
|
-
for (let n of Object.values(e))
|
|
433
|
+
for (let n of Object.values(e)) jn(n) && (Hn(n), t += 1);
|
|
419
434
|
return t;
|
|
420
|
-
},
|
|
421
|
-
let t =
|
|
435
|
+
}, Wn = (e) => {
|
|
436
|
+
let t = P.get(e);
|
|
422
437
|
if (t !== void 0) return Object.fromEntries(t);
|
|
423
|
-
},
|
|
438
|
+
}, Gn = (e, t) => P.get(e)?.get(t), Kn = () => {
|
|
424
439
|
let e = [];
|
|
425
|
-
for (let [t, n] of
|
|
440
|
+
for (let [t, n] of P) for (let [r, i] of n) e.push({
|
|
426
441
|
source: t,
|
|
427
442
|
name: r,
|
|
428
443
|
relation: i
|
|
429
444
|
});
|
|
430
445
|
return e;
|
|
431
|
-
},
|
|
432
|
-
for (let [e, t] of
|
|
446
|
+
}, qn = () => {
|
|
447
|
+
for (let [e, t] of P) {
|
|
433
448
|
let n = E(e);
|
|
434
|
-
if (n !== void 0) for (let [e, r] of t)
|
|
449
|
+
if (n !== void 0) for (let [e, r] of t) zn(n, e, r);
|
|
435
450
|
}
|
|
436
|
-
},
|
|
437
|
-
|
|
438
|
-
},
|
|
451
|
+
}, Jn = () => {
|
|
452
|
+
P.clear();
|
|
453
|
+
}, Yn = 4, Xn = (e) => Object.keys(e.fields), Zn = (e, t) => Object.prototype.hasOwnProperty.call(e.fields, t), Qn = (e, t) => {
|
|
439
454
|
let n = [];
|
|
440
455
|
for (let [r, i] of Object.entries(e.fields)) i.type === "reference" && i.references?.()?.tableName === t && n.push(r);
|
|
441
456
|
return n;
|
|
442
|
-
},
|
|
457
|
+
}, $n = (e, t) => {
|
|
443
458
|
let n = [];
|
|
444
459
|
for (let r of t) {
|
|
445
460
|
if (r.source !== e) continue;
|
|
@@ -456,7 +471,7 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
456
471
|
} catch {
|
|
457
472
|
continue;
|
|
458
473
|
}
|
|
459
|
-
if (!
|
|
474
|
+
if (!Zn(e, t.sourceKey)) continue;
|
|
460
475
|
n.push({
|
|
461
476
|
table: e.tableName,
|
|
462
477
|
foreignKey: t.sourceKey,
|
|
@@ -465,24 +480,24 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
465
480
|
continue;
|
|
466
481
|
}
|
|
467
482
|
if (t.sourceKey !== void 0) continue;
|
|
468
|
-
let a =
|
|
469
|
-
o === void 0 || !
|
|
483
|
+
let a = Qn(i, e), o = t.foreignKey ?? (a.length === 1 ? a[0] : void 0);
|
|
484
|
+
o === void 0 || !Zn(i, o) || n.push({
|
|
470
485
|
table: i.tableName,
|
|
471
486
|
foreignKey: o,
|
|
472
487
|
parentKey: "id"
|
|
473
488
|
});
|
|
474
489
|
}
|
|
475
490
|
return n;
|
|
476
|
-
},
|
|
491
|
+
}, er = (e, t) => {
|
|
477
492
|
let n = [];
|
|
478
|
-
for (let r of t) if (r.tableName !== e) for (let t of
|
|
493
|
+
for (let r of t) if (r.tableName !== e) for (let t of Qn(r, e)) n.push({
|
|
479
494
|
table: r.tableName,
|
|
480
495
|
foreignKey: t,
|
|
481
496
|
parentKey: "id"
|
|
482
497
|
});
|
|
483
498
|
return n;
|
|
484
|
-
},
|
|
485
|
-
let t = e.tables ?? Ce(), n = e.relations ??
|
|
499
|
+
}, tr = (e) => `${e.table}\u0000${e.hops.map((e) => `${e.table}.${e.foreignKey}<-${e.parentKey}`).join("|")}`, nr = (e) => {
|
|
500
|
+
let t = e.tables ?? Ce(), n = e.relations ?? Kn(), r = e.maxDepth ?? 4, i = new Set(e.exclude ?? []), a = new Map(t.map((e) => [e.tableName, e])), o = [];
|
|
486
501
|
if (!a.has(e.subjectTable)) return {
|
|
487
502
|
subjectTable: e.subjectTable,
|
|
488
503
|
paths: [],
|
|
@@ -497,11 +512,11 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
497
512
|
hops: [],
|
|
498
513
|
depth: 0,
|
|
499
514
|
via: "relation"
|
|
500
|
-
}, c = [s], l = /* @__PURE__ */ new Set([
|
|
515
|
+
}, c = [s], l = /* @__PURE__ */ new Set([tr(s)]), u = /* @__PURE__ */ new Set(), d = [s];
|
|
501
516
|
for (let e = 1; e <= r; e++) {
|
|
502
517
|
let r = [];
|
|
503
518
|
for (let a of d) {
|
|
504
|
-
let s =
|
|
519
|
+
let s = $n(a.table, n), d = er(a.table, t), f = [...s.map((e) => [e, "relation"]), ...d.map((e) => [e, "reference"])];
|
|
505
520
|
for (let [t, n] of f) {
|
|
506
521
|
if (i.has(t.table)) {
|
|
507
522
|
o.push({
|
|
@@ -519,7 +534,7 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
519
534
|
hops: [...a.hops, t],
|
|
520
535
|
depth: e,
|
|
521
536
|
via: n
|
|
522
|
-
}, f =
|
|
537
|
+
}, f = tr(d);
|
|
523
538
|
l.has(f) || (l.add(f), c.push(d), r.push(d));
|
|
524
539
|
}
|
|
525
540
|
}
|
|
@@ -529,7 +544,7 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
529
544
|
}
|
|
530
545
|
d = r;
|
|
531
546
|
}
|
|
532
|
-
for (let e of d) (
|
|
547
|
+
for (let e of d) ($n(e.table, n).length > 0 || er(e.table, t).length > 0) && o.push({
|
|
533
548
|
kind: "depth-truncated",
|
|
534
549
|
table: e.table,
|
|
535
550
|
detail: `stopped at maxDepth ${r}; tables linked FROM '${e.table}' were not explored`
|
|
@@ -538,14 +553,14 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
538
553
|
for (let n of t) f.has(n.tableName) || i.has(n.tableName) || o.push({
|
|
539
554
|
kind: "unreachable",
|
|
540
555
|
table: n.tableName,
|
|
541
|
-
detail: `no relation() and no reference() column links '${n.tableName}' to '${e.subjectTable}'. If it holds subject data through a plain column, a polymorphic (type,id) pair, JSON or free text, add an explicit subjectScopes entry — this derivation cannot see it. Columns: ${
|
|
556
|
+
detail: `no relation() and no reference() column links '${n.tableName}' to '${e.subjectTable}'. If it holds subject data through a plain column, a polymorphic (type,id) pair, JSON or free text, add an explicit subjectScopes entry — this derivation cannot see it. Columns: ${Xn(n).join(", ")}`
|
|
542
557
|
});
|
|
543
558
|
return {
|
|
544
559
|
subjectTable: e.subjectTable,
|
|
545
560
|
paths: c,
|
|
546
561
|
limitations: o
|
|
547
562
|
};
|
|
548
|
-
},
|
|
563
|
+
}, rr = (e) => {
|
|
549
564
|
let t = [`subject graph · ${e.subjectTable} · ${e.paths.length} table(s) reachable`];
|
|
550
565
|
for (let n of e.paths) {
|
|
551
566
|
let r = n.hops.length === 0 ? `${e.subjectTable} (the subject row itself)` : [e.subjectTable, ...n.hops.map((e) => `${e.table}.${e.foreignKey}`)].join(" → ");
|
|
@@ -553,7 +568,7 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
553
568
|
}
|
|
554
569
|
let n = e.limitations.filter((e) => e.kind === "depth-truncated"), r = e.limitations.filter((e) => e.kind === "unreachable"), i = e.limitations.filter((e) => e.kind === "excluded");
|
|
555
570
|
return t.push(""), t.push(" WHAT THIS CANNOT SEE — a DSAR is only as complete as this list is short:"), n.length > 0 && t.push(` depth-truncated (${n.length}): ${n.map((e) => e.table).join(", ")}`), i.length > 0 && t.push(` excluded (${i.length}): ${[...new Set(i.map((e) => e.table))].join(", ")}`), t.push(r.length === 0 ? " unreachable: none — every registered table is linked to the subject." : ` unreachable (${r.length}): ${r.map((e) => e.table).join(", ")}`), t.push(" Always outside this graph: object storage / uploaded files, external processors,"), t.push(" log and metric sinks, backups, and any subject id embedded in JSON or free text."), t.join("\n");
|
|
556
|
-
},
|
|
571
|
+
}, ir = (e) => e == null || typeof e == "boolean" ? e : typeof e == "number" ? e !== 0 : typeof e == "bigint" ? e !== 0n : typeof e == "string" ? e === "1" || e.toLowerCase() === "true" : e, ar = (e) => {
|
|
557
572
|
if (e == null || typeof e != "string") return e;
|
|
558
573
|
let t = e.trim();
|
|
559
574
|
if (t.length === 0) return e;
|
|
@@ -564,7 +579,7 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
564
579
|
} catch {
|
|
565
580
|
return e;
|
|
566
581
|
}
|
|
567
|
-
},
|
|
582
|
+
}, or = (e) => e == null || typeof e == "string" ? e : typeof e == "number" || typeof e == "bigint" ? String(e) : e, sr = (e) => {
|
|
568
583
|
if (e == null || e instanceof Date) return e;
|
|
569
584
|
if (typeof e == "string") {
|
|
570
585
|
let t = new Date(e);
|
|
@@ -575,19 +590,19 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
575
590
|
return isNaN(t.getTime()) ? e : t;
|
|
576
591
|
}
|
|
577
592
|
return e;
|
|
578
|
-
},
|
|
593
|
+
}, cr = (e, t, n) => {
|
|
579
594
|
if (e == null) return e;
|
|
580
595
|
switch (t) {
|
|
581
|
-
case "boolean": return n === "postgres" ? e :
|
|
596
|
+
case "boolean": return n === "postgres" ? e : ir(e);
|
|
582
597
|
case "json":
|
|
583
|
-
case "array": return n === "postgres" ? e :
|
|
598
|
+
case "array": return n === "postgres" ? e : ar(e);
|
|
584
599
|
case "timestamp":
|
|
585
|
-
case "date": return n === "sqlite" || n === "turso" ?
|
|
600
|
+
case "date": return n === "sqlite" || n === "turso" ? sr(e) : e;
|
|
586
601
|
case "decimal":
|
|
587
|
-
case "bigint": return
|
|
602
|
+
case "bigint": return or(e);
|
|
588
603
|
default: return e;
|
|
589
604
|
}
|
|
590
|
-
},
|
|
605
|
+
}, lr = (e, t, n) => {
|
|
591
606
|
if (e.length === 0) return e;
|
|
592
607
|
let r = E(t);
|
|
593
608
|
if (r === void 0) return e;
|
|
@@ -598,36 +613,36 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
598
613
|
});
|
|
599
614
|
return e.map((e) => {
|
|
600
615
|
let t = { ...e };
|
|
601
|
-
for (let { key: e, type: r } of a) e in t && (t[e] =
|
|
616
|
+
for (let { key: e, type: r } of a) e in t && (t[e] = cr(t[e], r, n));
|
|
602
617
|
return t;
|
|
603
618
|
});
|
|
604
|
-
},
|
|
619
|
+
}, ur = (e, t) => {
|
|
605
620
|
if (e == null) return e;
|
|
606
621
|
switch (t) {
|
|
607
622
|
case "json":
|
|
608
623
|
case "array": return typeof e == "string" ? e : JSON.stringify(e);
|
|
609
624
|
default: return e;
|
|
610
625
|
}
|
|
611
|
-
},
|
|
626
|
+
}, dr = (e, t, n = ["json", "array"]) => {
|
|
612
627
|
let r = E(t);
|
|
613
628
|
if (r === void 0) return e;
|
|
614
629
|
let i = r.fields, a = null;
|
|
615
630
|
for (let [t, r] of Object.entries(i)) if (n.includes(r.type) && t in e) {
|
|
616
|
-
let n =
|
|
631
|
+
let n = ur(e[t], r.type);
|
|
617
632
|
n !== e[t] && (a === null && (a = { ...e }), a[t] = n);
|
|
618
633
|
}
|
|
619
634
|
return a ?? e;
|
|
620
|
-
},
|
|
635
|
+
}, fr = class extends Error {
|
|
621
636
|
_tag = "EagerCardinalityError";
|
|
622
637
|
constructor(e) {
|
|
623
638
|
super(e), this.name = "EagerCardinalityError";
|
|
624
639
|
}
|
|
625
|
-
},
|
|
640
|
+
}, pr = (e) => {
|
|
626
641
|
let { relationName: t, sourceTableName: n, targetTableName: r, foreignKey: i, sourceKey: a } = e, o = r === n;
|
|
627
642
|
return `relation '${t}' on '${n}' is declared \`one\`, but ${r}.${i} matches MORE than one row for the same ${n}.${a} — so there is no single related row to return.` + (o ? ` Because this relation is self-referential, check which side the key is on: \`foreignKey: '${i}'\` means "rows whose ${i} points AT me" (my children — there can be many). If you meant "the row my ${i} points to" (my parent), that is \`sourceKey: '${i}'\`.` : " Use `many(...)` if several are expected, or narrow the key.");
|
|
628
|
-
},
|
|
643
|
+
}, mr = async (e, t, n, r) => {
|
|
629
644
|
if (e.length === 0) return e;
|
|
630
|
-
let i =
|
|
645
|
+
let i = Wn(n.tableName);
|
|
631
646
|
if (i === void 0) throw Error(`cannot eager-load on '${n.tableName}': no relations registered. Did you forget to declare \`relations(${n.tableName}, ...)\` or import the file that does?`);
|
|
632
647
|
let a = e.map((e) => ({ ...e }));
|
|
633
648
|
for (let [e, o] of Object.entries(t)) {
|
|
@@ -636,36 +651,36 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
636
651
|
let t = Object.keys(i).join(", ") || "<none>";
|
|
637
652
|
throw Error(`unknown relation '${e}' on '${n.tableName}'. Registered relations: ${t}.`);
|
|
638
653
|
}
|
|
639
|
-
|
|
654
|
+
zn(n, e, t), await hr(a, e, t, o === !0 ? {} : o, n, r);
|
|
640
655
|
}
|
|
641
656
|
return a;
|
|
642
|
-
},
|
|
657
|
+
}, hr = async (e, t, n, r, i, a) => {
|
|
643
658
|
switch (n.kind) {
|
|
644
659
|
case "one":
|
|
645
|
-
await
|
|
660
|
+
await gr(e, t, n, r, i, a);
|
|
646
661
|
return;
|
|
647
662
|
case "many":
|
|
648
|
-
await
|
|
663
|
+
await _r(e, t, n, r, i, a);
|
|
649
664
|
return;
|
|
650
665
|
case "manyToMany":
|
|
651
|
-
await
|
|
666
|
+
await yr(e, t, n, r, i, a);
|
|
652
667
|
return;
|
|
653
668
|
}
|
|
654
|
-
},
|
|
655
|
-
let o = n.target(), s = n.sourceKey ??
|
|
669
|
+
}, gr = async (e, t, n, r, i, a) => {
|
|
670
|
+
let o = n.target(), s = n.sourceKey ?? br(i, o.tableName);
|
|
656
671
|
if (s !== void 0) {
|
|
657
|
-
let n =
|
|
672
|
+
let n = xr(e, s), i = n.length === 0 ? [] : await Sr(o, "id", n, r, a), c = new Map(i.map((e) => [e.id, e]));
|
|
658
673
|
for (let n of e) {
|
|
659
674
|
let e = n[s];
|
|
660
675
|
n[t] = e == null ? null : c.get(e) ?? null;
|
|
661
676
|
}
|
|
662
|
-
await
|
|
677
|
+
await Cr(i, r.with, o, a);
|
|
663
678
|
return;
|
|
664
679
|
}
|
|
665
|
-
let c = n.foreignKey ??
|
|
680
|
+
let c = n.foreignKey ?? Fn(o, i.tableName, t), l = n.sourceKey ?? "id", u = xr(e, l), d = u.length === 0 ? [] : await Sr(o, c, u, r, a), f = /* @__PURE__ */ new Map();
|
|
666
681
|
for (let e of d) {
|
|
667
682
|
let n = e[c];
|
|
668
|
-
if (f.has(n)) throw new
|
|
683
|
+
if (f.has(n)) throw new fr(pr({
|
|
669
684
|
relationName: t,
|
|
670
685
|
sourceTableName: i.tableName,
|
|
671
686
|
targetTableName: o.tableName,
|
|
@@ -678,9 +693,9 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
678
693
|
let e = n[l];
|
|
679
694
|
n[t] = e == null ? null : f.get(e) ?? null;
|
|
680
695
|
}
|
|
681
|
-
await
|
|
682
|
-
},
|
|
683
|
-
let o = n.target(), s = n.foreignKey ??
|
|
696
|
+
await Cr(d, r.with, o, a);
|
|
697
|
+
}, _r = async (e, t, n, r, i, a) => {
|
|
698
|
+
let o = n.target(), s = n.foreignKey ?? Fn(o, i.tableName, t), c = n.sourceKey ?? "id", l = xr(e, c), u = vr(r), d = l.length === 0 ? [] : await Sr(o, s, l, u, a), f = /* @__PURE__ */ new Map();
|
|
684
699
|
for (let e of d) {
|
|
685
700
|
let t = e[s], n = f.get(t);
|
|
686
701
|
n ? n.push(e) : f.set(t, [e]);
|
|
@@ -696,12 +711,12 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
696
711
|
let e = n[c];
|
|
697
712
|
n[t] = f.get(e) ?? [];
|
|
698
713
|
}
|
|
699
|
-
await
|
|
700
|
-
},
|
|
714
|
+
await Cr(d, r.with, o, a);
|
|
715
|
+
}, vr = (e) => {
|
|
701
716
|
let { limit: t, offset: n, ...r } = e;
|
|
702
717
|
return r;
|
|
703
|
-
},
|
|
704
|
-
let o = n.target(), s = n.through(), c =
|
|
718
|
+
}, yr = async (e, t, n, r, i, a) => {
|
|
719
|
+
let o = n.target(), s = n.through(), c = xr(e, "id");
|
|
705
720
|
if (c.length === 0) {
|
|
706
721
|
for (let n of e) n[t] = [];
|
|
707
722
|
return;
|
|
@@ -722,8 +737,8 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
722
737
|
for (let n of e) n[t] = [];
|
|
723
738
|
return;
|
|
724
739
|
}
|
|
725
|
-
let f = await
|
|
726
|
-
await
|
|
740
|
+
let f = await Sr(o, "id", xr(d, n.targetKey), r, a), p = new Map(f.map((e) => [e.id, e]));
|
|
741
|
+
await Cr(f, r.with, o, a);
|
|
727
742
|
let m = r.junction === void 0 ? void 0 : r.junction === !0 ? Object.keys(s.fields) : r.junction, h = /* @__PURE__ */ new Map();
|
|
728
743
|
for (let e of d) {
|
|
729
744
|
let t = e[n.sourceKey], r = e[n.targetKey], i = p.get(r);
|
|
@@ -735,16 +750,16 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
735
750
|
o ? o.push(a) : h.set(t, [a]);
|
|
736
751
|
}
|
|
737
752
|
for (let n of e) n[t] = h.get(n.id) ?? [];
|
|
738
|
-
},
|
|
753
|
+
}, br = (e, t) => {
|
|
739
754
|
for (let [n, r] of Object.entries(e.fields)) if (r.type === "reference" && r.references?.()?.tableName === t) return n;
|
|
740
|
-
},
|
|
755
|
+
}, xr = (e, t) => {
|
|
741
756
|
let n = /* @__PURE__ */ new Set();
|
|
742
757
|
for (let r of e) {
|
|
743
758
|
let e = r[t];
|
|
744
759
|
e != null && n.add(e);
|
|
745
760
|
}
|
|
746
761
|
return [...n];
|
|
747
|
-
},
|
|
762
|
+
}, Sr = (e, t, n, r, i) => {
|
|
748
763
|
let a = {
|
|
749
764
|
column: t,
|
|
750
765
|
op: "in",
|
|
@@ -758,50 +773,50 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
758
773
|
skip: r.offset,
|
|
759
774
|
projection: void 0
|
|
760
775
|
});
|
|
761
|
-
},
|
|
762
|
-
t !== void 0 && e.length !== 0 && (await
|
|
776
|
+
}, Cr = async (e, t, n, r) => {
|
|
777
|
+
t !== void 0 && e.length !== 0 && (await mr(e, t, n, r)).forEach((t, n) => {
|
|
763
778
|
let r = e[n];
|
|
764
779
|
for (let [e, n] of Object.entries(t)) e in r || (r[e] = n);
|
|
765
780
|
});
|
|
766
|
-
},
|
|
781
|
+
}, wr = (e) => e.eager !== void 0 && Object.keys(e.eager).length > 0, Tr = class extends Error {
|
|
767
782
|
_tag = "TenantNamespaceUnresolved";
|
|
768
783
|
constructor(e) {
|
|
769
784
|
super(e), this.name = "TenantNamespaceUnresolved";
|
|
770
785
|
}
|
|
771
|
-
},
|
|
786
|
+
}, Er = class extends Error {
|
|
772
787
|
_tag = "TenantNamespaceInvalid";
|
|
773
788
|
constructor(e) {
|
|
774
789
|
super(e), this.name = "TenantNamespaceInvalid";
|
|
775
790
|
}
|
|
776
|
-
},
|
|
777
|
-
if (e == null || e === "") throw new
|
|
778
|
-
let t =
|
|
779
|
-
if (t.replace(/_/g, "") === "") throw new
|
|
780
|
-
let n = `${
|
|
781
|
-
if (n.length >
|
|
791
|
+
}, Dr = 63, Or = "tenant_", kr = (e) => e.toLowerCase().replace(/[^a-z0-9_]/g, "_"), Ar = (e) => {
|
|
792
|
+
if (e == null || e === "") throw new Tr("namespace isolation is on but the request has no resolvable tenant (subject.tenantId is null/empty). Refusing to run against a shared/default namespace — this would be a cross-tenant read. Authenticate with a tenant-scoped subject, or disable namespace isolation for this surface.");
|
|
793
|
+
let t = kr(e);
|
|
794
|
+
if (t.replace(/_/g, "") === "") throw new Er(`tenant id '${e}' has no usable identifier characters after sanitisation — cannot derive a distinct namespace.`);
|
|
795
|
+
let n = `${Or}${t}`;
|
|
796
|
+
if (n.length > Dr) throw new Er(`namespace '${n}' for tenant '${e}' exceeds the ${Dr}-byte identifier limit. Use a shorter tenant id.`);
|
|
782
797
|
return n;
|
|
783
|
-
},
|
|
784
|
-
if (e === void 0 || t == null || !
|
|
798
|
+
}, jr = (e, t) => e === null ? t : `${e}.${t}`, Mr = /* @__PURE__ */ new Set(["timestamp", "date"]), Nr = /^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2})?/, Pr = (e, t) => {
|
|
799
|
+
if (e === void 0 || t == null || !Mr.has(e) || t instanceof Date) return t;
|
|
785
800
|
if (typeof t == "number" && Number.isFinite(t)) return new Date(t);
|
|
786
|
-
if (typeof t == "string" &&
|
|
801
|
+
if (typeof t == "string" && Nr.test(t)) {
|
|
787
802
|
let e = new Date(t);
|
|
788
803
|
return Number.isNaN(e.getTime()) ? t : e;
|
|
789
804
|
}
|
|
790
805
|
return t;
|
|
791
|
-
},
|
|
806
|
+
}, Fr = (e, t) => e === void 0 || !Mr.has(e) ? t : t.map((t) => Pr(e, t)), Ir = (e, t) => {
|
|
792
807
|
let { strings: n, values: r } = e, i = t.unsafe(n[0] ?? "");
|
|
793
808
|
for (let e = 0; e < r.length; e++) i = t`${i}${r[e]}${t.unsafe(n[e + 1] ?? "")}`;
|
|
794
809
|
return t`${i}`;
|
|
795
|
-
},
|
|
796
|
-
if ("not" in e) return t`NOT (${
|
|
797
|
-
if ("and" in e) return e.and.length === 0 ? t`TRUE` : t.and(e.and.map((e) =>
|
|
798
|
-
if ("or" in e) return e.or.length === 0 ? t`FALSE` : t.or(e.or.map((e) =>
|
|
810
|
+
}, Lr = (e) => e.replace(/[\\%_]/g, (e) => `\\${e}`), F = (e, t, n = null, r) => {
|
|
811
|
+
if ("not" in e) return t`NOT (${F(e.not, t, n, r)})`;
|
|
812
|
+
if ("and" in e) return e.and.length === 0 ? t`TRUE` : t.and(e.and.map((e) => F(e, t, n, r)));
|
|
813
|
+
if ("or" in e) return e.or.length === 0 ? t`FALSE` : t.or(e.or.map((e) => F(e, t, n, r)));
|
|
799
814
|
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
800
|
-
let r = e, i =
|
|
815
|
+
let r = e, i = I(r.subquery, t, n);
|
|
801
816
|
return r.op === "subquery-in" ? t`${t(r.column)} IN (${i})` : t`${t(r.column)} NOT IN (${i})`;
|
|
802
817
|
}
|
|
803
818
|
if (e.op === "exists" || e.op === "not-exists") {
|
|
804
|
-
let r = e, i =
|
|
819
|
+
let r = e, i = I(r.subquery, t, n);
|
|
805
820
|
return r.op === "exists" ? t`EXISTS (${i})` : t`NOT EXISTS (${i})`;
|
|
806
821
|
}
|
|
807
822
|
let i = e, a = t(i.column), o = i.path, s = o !== void 0 && o.length > 0, c = () => t.onDialectOrElse({
|
|
@@ -814,7 +829,7 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
814
829
|
mssql: () => t.unsafe(w(i.column, o, "mssql", { numeric: !0 })),
|
|
815
830
|
sqlite: () => t.unsafe(w(i.column, o, "sqlite", { numeric: !0 })),
|
|
816
831
|
orElse: () => t.unsafe(w(i.column, o, "postgres", { numeric: !0 }))
|
|
817
|
-
}), u = s ? c() : a, d = s ? l() : a, f = (e) => s && e != null ? String(e) : e, p = (e) => s ? Number(e) : e, m = s || r === void 0 ? void 0 : E(r)?.fields?.[i.column]?.type, h = (e) =>
|
|
832
|
+
}), u = s ? c() : a, d = s ? l() : a, f = (e) => s && e != null ? String(e) : e, p = (e) => s ? Number(e) : e, m = s || r === void 0 ? void 0 : E(r)?.fields?.[i.column]?.type, h = (e) => Pr(m, e);
|
|
818
833
|
switch (i.op) {
|
|
819
834
|
case "eq": return t`${u} = ${f(h(i.value))}`;
|
|
820
835
|
case "neq": return t`${u} <> ${f(h(i.value))}`;
|
|
@@ -831,7 +846,7 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
831
846
|
return e.length === 0 ? t`TRUE` : t`${u} NOT IN ${t.in(s ? e.map((e) => f(e)) : e)}`;
|
|
832
847
|
}
|
|
833
848
|
case "contains": {
|
|
834
|
-
let e = `%${
|
|
849
|
+
let e = `%${Lr(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
|
|
835
850
|
return t.onDialectOrElse({
|
|
836
851
|
mysql: () => t`LOWER(${u}) LIKE LOWER(${e})`,
|
|
837
852
|
mssql: () => t`LOWER(${u}) LIKE LOWER(${e})`,
|
|
@@ -840,7 +855,7 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
840
855
|
});
|
|
841
856
|
}
|
|
842
857
|
case "startsWith": {
|
|
843
|
-
let e = `${
|
|
858
|
+
let e = `${Lr(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
|
|
844
859
|
return t.onDialectOrElse({
|
|
845
860
|
mysql: () => t`${u} LIKE ${e}`,
|
|
846
861
|
orElse: () => t`${u} LIKE ${e} ESCAPE '\\'`
|
|
@@ -888,13 +903,13 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
888
903
|
});
|
|
889
904
|
}
|
|
890
905
|
}
|
|
891
|
-
},
|
|
906
|
+
}, Rr = (e, t) => {
|
|
892
907
|
let n = [];
|
|
893
908
|
return e.partitionBy && e.partitionBy.length > 0 && n.push(t`PARTITION BY ${t.csv(e.partitionBy.map((e) => t`${t(e)}`))}`), e.orderBy && e.orderBy.length > 0 && n.push(t`ORDER BY ${t.csv(e.orderBy.map((e) => e.direction === "desc" ? t`${t(e.column)} DESC` : t`${t(e.column)} ASC`))}`), n.length === 0 ? t`` : n.length === 1 ? n[0] : n.reduce((e, n, r) => r === 0 ? n : t`${e} ${n}`);
|
|
894
|
-
},
|
|
909
|
+
}, zr = (e, t) => t.csv(e.map((e) => {
|
|
895
910
|
let n = e.column === void 0 ? t.unsafe("*") : t`${t(e.column)}`;
|
|
896
911
|
if (e.op.startsWith("window-")) {
|
|
897
|
-
let r =
|
|
912
|
+
let r = Rr(e.window ?? {}, t);
|
|
898
913
|
switch (e.op) {
|
|
899
914
|
case "window-row-number": return t`ROW_NUMBER() OVER (${r}) AS ${t(e.alias)}`;
|
|
900
915
|
case "window-rank": return t`RANK() OVER (${r}) AS ${t(e.alias)}`;
|
|
@@ -918,43 +933,43 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
918
933
|
return t`${t(e.column)} AS ${t(e.alias)}`;
|
|
919
934
|
default: throw Error(`compileAggregateProjection: unknown op '${e.op}'`);
|
|
920
935
|
}
|
|
921
|
-
})),
|
|
936
|
+
})), Br = (e) => `[${e.join(",")}]`, Vr = (e, t) => {
|
|
922
937
|
if (e.queryVector === void 0) return null;
|
|
923
|
-
let n = t(e.column), r =
|
|
938
|
+
let n = t(e.column), r = Br(e.queryVector), i = e.distance === "cosine" ? "<=>" : e.distance === "l2" ? "<->" : "<#>", a = e.distance === "cosine" ? "VEC_DISTANCE_COSINE" : "VEC_DISTANCE_EUCLIDEAN";
|
|
924
939
|
return t.onDialectOrElse({
|
|
925
940
|
mysql: () => t`${t.unsafe(a)}(${n}, ${r})`,
|
|
926
941
|
mssql: () => t`NULL`,
|
|
927
942
|
sqlite: () => t`NULL`,
|
|
928
943
|
orElse: () => t`${n} ${t.unsafe(i)} ${r}::vector`
|
|
929
944
|
});
|
|
930
|
-
},
|
|
945
|
+
}, Hr = (e, t) => {
|
|
931
946
|
let n = t.unsafe(e.useGeography ? "::geography" : "::geometry");
|
|
932
947
|
return t`ST_Distance(${t(e.column)}${n}, ${e.geom}${n})`;
|
|
933
|
-
},
|
|
934
|
-
let r = n.csv(e.columns.map((e) => n`${n(e)}`)), i = `%${
|
|
948
|
+
}, Ur = (e, t) => t`${t(e.column)} <-> ${e.geom}::geometry`, Wr = (e, t) => t`${t(`${e.indexName}_tsv`)}`, Gr = (e, t) => `${t}_${e.indexName}_fts`, Kr = (e, t, n) => {
|
|
949
|
+
let r = n.csv(e.columns.map((e) => n`${n(e)}`)), i = `%${Lr(e.query)}%`;
|
|
935
950
|
return n.onDialectOrElse({
|
|
936
951
|
mysql: () => n`MATCH(${r}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
|
|
937
952
|
sqlite: () => {
|
|
938
|
-
let r = n(
|
|
953
|
+
let r = n(Gr(e, t));
|
|
939
954
|
return n`${n("id")} IN (SELECT ${n("row_id")} FROM ${r} WHERE ${r} MATCH ${e.query})`;
|
|
940
955
|
},
|
|
941
956
|
mssql: () => n.or(e.columns.map((e) => n`LOWER(${n(e)}) LIKE LOWER(${i}) ESCAPE '\\'`)),
|
|
942
|
-
orElse: () => n`${
|
|
957
|
+
orElse: () => n`${Wr(e, n)} @@ plainto_tsquery(${e.config ?? "english"}, ${e.query})`
|
|
943
958
|
});
|
|
944
|
-
},
|
|
945
|
-
let r = `%${
|
|
959
|
+
}, qr = (e, t, n) => {
|
|
960
|
+
let r = `%${Lr(e.query)}%`;
|
|
946
961
|
return n.onDialectOrElse({
|
|
947
962
|
mysql: () => n`MATCH(${n.csv(e.columns.map((e) => n`${n(e)}`))}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
|
|
948
963
|
sqlite: () => {
|
|
949
|
-
let r = n(
|
|
964
|
+
let r = n(Gr(e, t));
|
|
950
965
|
return n`COALESCE((SELECT -bm25(${r}) FROM ${r} WHERE ${r} MATCH ${e.query} AND ${r}.${n("row_id")} = ${n("id")}), 0)`;
|
|
951
966
|
},
|
|
952
967
|
mssql: () => e.columns.map((e) => n`(CASE WHEN LOWER(${n(e)}) LIKE LOWER(${r}) ESCAPE '\\' THEN 1 ELSE 0 END)`).reduce((e, t, r) => r === 0 ? t : n`${e} + ${t}`),
|
|
953
|
-
orElse: () => n`ts_rank(${
|
|
968
|
+
orElse: () => n`ts_rank(${Wr(e, n)}, plainto_tsquery(${e.config ?? "english"}, ${e.query}))`
|
|
954
969
|
});
|
|
955
|
-
},
|
|
970
|
+
}, I = (e, t, n = null) => {
|
|
956
971
|
if (e.setOp && e.setOp.queries.length >= 2) {
|
|
957
|
-
let r = e.setOp.kind === "union" ? "UNION" : e.setOp.kind === "union-all" ? "UNION ALL" : e.setOp.kind === "intersect" ? "INTERSECT" : "EXCEPT", i = e.setOp.queries.map((e) => t`(${
|
|
972
|
+
let r = e.setOp.kind === "union" ? "UNION" : e.setOp.kind === "union-all" ? "UNION ALL" : e.setOp.kind === "intersect" ? "INTERSECT" : "EXCEPT", i = e.setOp.queries.map((e) => t`(${I(e, t, n)})`).reduce((e, n, i) => i === 0 ? n : t`${e} ${t.unsafe(r)} ${n}`), a = [];
|
|
958
973
|
if (x(e).length > 0 && a.push(t` ORDER BY ${t.csv(x(e).map((e) => e.direction === "desc" ? t`${t(e.column)} DESC` : t`${t(e.column)} ASC`))}`), e.take !== void 0) {
|
|
959
974
|
if (!Number.isInteger(e.take) || e.take < 0) throw Error(`compileSelect: invalid take ${e.take}`);
|
|
960
975
|
a.push(t` LIMIT ${t.unsafe(String(e.take))}`);
|
|
@@ -965,7 +980,7 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
965
980
|
}
|
|
966
981
|
return t`${i}${a.reduce((e, n) => t`${e}${n}`, t``)}`;
|
|
967
982
|
}
|
|
968
|
-
let r = e.annClause === void 0 ? null :
|
|
983
|
+
let r = e.annClause === void 0 ? null : Vr(e.annClause, t);
|
|
969
984
|
e.spatialClause !== void 0 && t.onDialectOrElse({
|
|
970
985
|
mysql: () => {
|
|
971
986
|
throw Error("@voltro/plugin-postgis: spatial distance / KNN ordering is postgres-only");
|
|
@@ -978,16 +993,16 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
978
993
|
},
|
|
979
994
|
orElse: () => t``
|
|
980
995
|
});
|
|
981
|
-
let i = e.spatialClause?.projectAs === void 0 ? null :
|
|
996
|
+
let i = e.spatialClause?.projectAs === void 0 ? null : Hr(e.spatialClause, t), a = e.aggregations && e.aggregations.length > 0 ? zr(e.aggregations, t) : e.joinedProjection && e.joinedProjection.length > 0 ? t.csv(e.joinedProjection.map((e) => t`${t(e.source)} AS ${t(e.outputKey)}`)) : e.projection && e.projection.length > 0 ? t.csv(e.projection.map((e) => t`${t(e)}`)) : t`*`, o = (e.aggregations && e.aggregations.length > 0) === !0, s = r !== null && !o ? t`${a}, ${r} AS ${t("distance")}` : a, c = e.fullTextSearch, l = c?.rank !== void 0 && !o ? qr(c, e.table, t) : null, u = l !== null && c?.rank !== void 0 ? t`${s}, ${l} AS ${t(c.rank.alias)}` : s, d = i !== null && !o && e.spatialClause?.projectAs !== void 0 ? t`${u}, ${i} AS ${t(e.spatialClause.projectAs)}` : u, f = e.distinctOn && e.distinctOn.length > 0 ? t.onDialectOrElse({
|
|
982
997
|
orElse: () => t`DISTINCT ON (${t.csv(e.distinctOn.map((e) => t`${t(e)}`))}) `,
|
|
983
998
|
mysql: () => t`DISTINCT `,
|
|
984
999
|
mssql: () => t`DISTINCT `,
|
|
985
1000
|
sqlite: () => t`DISTINCT `
|
|
986
|
-
}) : e.distinct ? t`DISTINCT ` : t``, p = e.alias === void 0 ? t`${t(
|
|
1001
|
+
}) : e.distinct ? t`DISTINCT ` : t``, p = e.alias === void 0 ? t`${t(jr(n, e.table))}` : t`${t(jr(n, e.table))} AS ${t(e.alias)}`, m = (e.joins ?? []).map((e) => {
|
|
987
1002
|
let r = e.kind === "inner" ? "INNER" : "LEFT";
|
|
988
|
-
return t` ${t.unsafe(r)} JOIN ${t(
|
|
989
|
-
}), h = m.length > 0 ? m.reduce((e, n) => t`${e}${n}`, p) : p, g = c === void 0 ? null :
|
|
990
|
-
r !== null && y.push(t`${r} ASC`), e.spatialClause?.order !== void 0 && y.push(e.spatialClause.order === "desc" ? t`${
|
|
1003
|
+
return t` ${t.unsafe(r)} JOIN ${t(jr(n, e.table))} AS ${t(e.alias)} ON ${F(e.on, t, n)}`;
|
|
1004
|
+
}), h = m.length > 0 ? m.reduce((e, n) => t`${e}${n}`, p) : p, g = c === void 0 ? null : Kr(c, e.table, t), _ = [e.predicate ? F(e.predicate, t, n, e.table) : null, g].filter((e) => e !== null), ee = _.length > 0 ? t` WHERE ${t.and(_)}` : t``, te = e.groupBy && e.groupBy.length > 0 ? t` GROUP BY ${t.csv(e.groupBy.map((e) => t`${t(e)}`))}` : t``, ne = e.having ? t` HAVING ${F(e.having, t, n, e.table)}` : t``, v = e.skip !== void 0, y = [];
|
|
1005
|
+
r !== null && y.push(t`${r} ASC`), e.spatialClause?.order !== void 0 && y.push(e.spatialClause.order === "desc" ? t`${Ur(e.spatialClause, t)} DESC` : t`${Ur(e.spatialClause, t)} ASC`), l !== null && c?.rank?.order === !0 && y.push(t`${l} DESC`);
|
|
991
1006
|
for (let n of x(e)) y.push(n.direction === "desc" ? t`${t(n.column)} DESC` : t`${t(n.column)} ASC`);
|
|
992
1007
|
let re = y.length > 0 ? t` ORDER BY ${t.csv(y)}` : v ? t.onDialectOrElse({
|
|
993
1008
|
mssql: () => t` ORDER BY (SELECT NULL)`,
|
|
@@ -995,7 +1010,7 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
995
1010
|
}) : t``, b = (e) => {
|
|
996
1011
|
if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw Error(`compileSelect: expected non-negative integer take/skip, got ${e}`);
|
|
997
1012
|
return t.unsafe(String(e));
|
|
998
|
-
}, ie = (e.ctes ?? []).map((e) => t`${t(e.name)} AS (${
|
|
1013
|
+
}, ie = (e.ctes ?? []).map((e) => t`${t(e.name)} AS (${I(e.descriptor, t, n)})`), ae = (e.ctes ?? []).some((e) => e.recursive === !0), oe = ie.length > 0 ? t`WITH ${t.unsafe(ae ? "RECURSIVE " : "")}${t.csv(ie)} ` : t``;
|
|
999
1014
|
return t.onDialectOrElse({
|
|
1000
1015
|
mssql: () => {
|
|
1001
1016
|
let n = e.take !== void 0 && !v ? t`TOP ${b(e.take)} ` : t``, r = v ? t` OFFSET ${b(e.skip)} ROWS FETCH NEXT ${b(e.take ?? 2 ** 53 - 1)} ROWS ONLY` : t``;
|
|
@@ -1006,29 +1021,29 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
1006
1021
|
return t`${oe}SELECT ${f}${d} FROM ${h}${ee}${te}${ne}${re}${n}${r}`;
|
|
1007
1022
|
}
|
|
1008
1023
|
});
|
|
1009
|
-
},
|
|
1024
|
+
}, Jr = (e, t, n) => {
|
|
1010
1025
|
if (e.eager === void 0) return null;
|
|
1011
|
-
let r =
|
|
1026
|
+
let r = Xr(e.table, e.eager, e.sourceTable);
|
|
1012
1027
|
if (r === null) return null;
|
|
1013
|
-
let i =
|
|
1028
|
+
let i = ri(n, e, r, ni(t, n));
|
|
1014
1029
|
return i === null ? null : {
|
|
1015
1030
|
fragment: i,
|
|
1016
|
-
decode:
|
|
1031
|
+
decode: oi(r, n)
|
|
1017
1032
|
};
|
|
1018
|
-
},
|
|
1033
|
+
}, L = (e) => e.relation.kind === "one" && e.fkSide === "target", Yr = (e) => ({
|
|
1019
1034
|
...e,
|
|
1020
1035
|
branch: {
|
|
1021
1036
|
...e.branch,
|
|
1022
1037
|
limit: 2
|
|
1023
1038
|
}
|
|
1024
|
-
}),
|
|
1025
|
-
let r = n ?? Te(e), i =
|
|
1039
|
+
}), Xr = (e, t, n) => {
|
|
1040
|
+
let r = n ?? Te(e), i = Wn(e);
|
|
1026
1041
|
if (i === void 0) return null;
|
|
1027
1042
|
let a = [];
|
|
1028
1043
|
for (let [e, n] of Object.entries(t)) {
|
|
1029
1044
|
let t = i[e];
|
|
1030
1045
|
if (t === void 0) return null;
|
|
1031
|
-
let o =
|
|
1046
|
+
let o = Zr(e, t, r, n === !0 ? {} : n);
|
|
1032
1047
|
if (o === null) return null;
|
|
1033
1048
|
a.push(o);
|
|
1034
1049
|
}
|
|
@@ -1036,30 +1051,30 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
1036
1051
|
table: r,
|
|
1037
1052
|
children: a
|
|
1038
1053
|
};
|
|
1039
|
-
},
|
|
1054
|
+
}, Zr = (e, t, n, r) => {
|
|
1040
1055
|
let i = t.target(), a = (t.kind === "manyToMany" ? void 0 : t.sourceKey) ?? "id", o, s;
|
|
1041
1056
|
if (t.kind === "manyToMany") o = t.targetKey, s = "target";
|
|
1042
1057
|
else if (t.kind === "one") {
|
|
1043
|
-
let r = t.sourceKey ??
|
|
1058
|
+
let r = t.sourceKey ?? ti(n, i.tableName);
|
|
1044
1059
|
if (r !== void 0) o = r, s = "source";
|
|
1045
1060
|
else try {
|
|
1046
|
-
o = t.foreignKey ??
|
|
1061
|
+
o = t.foreignKey ?? Fn(i, n.tableName, e), s = "target";
|
|
1047
1062
|
} catch {
|
|
1048
1063
|
return null;
|
|
1049
1064
|
}
|
|
1050
1065
|
} else try {
|
|
1051
|
-
o = t.foreignKey ??
|
|
1066
|
+
o = t.foreignKey ?? Fn(i, n.tableName, e), s = "target";
|
|
1052
1067
|
} catch {
|
|
1053
1068
|
return null;
|
|
1054
1069
|
}
|
|
1055
1070
|
let c = r.with === void 0 ? [] : (() => {
|
|
1056
|
-
let e =
|
|
1071
|
+
let e = Wn(i.tableName);
|
|
1057
1072
|
if (e === void 0 && Object.keys(r.with).length > 0) return null;
|
|
1058
1073
|
let t = [];
|
|
1059
1074
|
for (let [n, a] of Object.entries(r.with)) {
|
|
1060
1075
|
let r = e?.[n];
|
|
1061
1076
|
if (r === void 0) return null;
|
|
1062
|
-
let o =
|
|
1077
|
+
let o = Zr(n, r, i, a === !0 ? {} : a);
|
|
1063
1078
|
if (o === null) return null;
|
|
1064
1079
|
t.push(o);
|
|
1065
1080
|
}
|
|
@@ -1075,9 +1090,9 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
1075
1090
|
fkSide: s,
|
|
1076
1091
|
branch: r,
|
|
1077
1092
|
children: c,
|
|
1078
|
-
junction:
|
|
1093
|
+
junction: Qr(t, r)
|
|
1079
1094
|
};
|
|
1080
|
-
},
|
|
1095
|
+
}, Qr = (e, t) => {
|
|
1081
1096
|
if (e.kind !== "manyToMany" || t.junction === void 0) return;
|
|
1082
1097
|
let n = e.through(), r = t.junction === !0 ? Object.keys(n.fields) : t.junction, i = r.filter((e) => e in n.fields);
|
|
1083
1098
|
return {
|
|
@@ -1089,35 +1104,35 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
1089
1104
|
return t !== void 0 && (t.type === "timestamp" || t.type === "date");
|
|
1090
1105
|
})
|
|
1091
1106
|
};
|
|
1092
|
-
},
|
|
1107
|
+
}, $r = (e) => `__j_${e}`, ei = "__j", ti = (e, t) => {
|
|
1093
1108
|
for (let [n, r] of Object.entries(e.fields)) if (r.type === "reference" && r.references?.()?.tableName === t) return n;
|
|
1094
|
-
},
|
|
1109
|
+
}, ni = (e, t) => {
|
|
1095
1110
|
let n = 0;
|
|
1096
1111
|
return {
|
|
1097
1112
|
sql: e,
|
|
1098
1113
|
dialect: t,
|
|
1099
1114
|
nextAlias: () => `__a${n++}`
|
|
1100
1115
|
};
|
|
1101
|
-
},
|
|
1116
|
+
}, ri = (e, t, n, r) => {
|
|
1102
1117
|
switch (e) {
|
|
1103
|
-
case "postgres": return
|
|
1118
|
+
case "postgres": return li(t, n, r);
|
|
1104
1119
|
case "sqlite":
|
|
1105
|
-
case "turso": return
|
|
1120
|
+
case "turso": return _i(t, n, r);
|
|
1106
1121
|
case "mysql":
|
|
1107
|
-
case "mariadb": return
|
|
1108
|
-
case "mssql": return
|
|
1122
|
+
case "mariadb": return Di(t, n, r);
|
|
1123
|
+
case "mssql": return Pi(t, n, r);
|
|
1109
1124
|
}
|
|
1110
|
-
},
|
|
1111
|
-
let n =
|
|
1125
|
+
}, ii = (e, t) => t === "mssql" && !ai.test(e) ? /* @__PURE__ */ new Date(`${e}Z`) : new Date(e), ai = /(?:Z|[+-]\d{2}:?\d{2})$/, oi = (e, t) => {
|
|
1126
|
+
let n = si(e.table, e.children, t);
|
|
1112
1127
|
return (e) => e.map((e) => {
|
|
1113
1128
|
let t = e.__row, r = typeof t == "string" ? JSON.parse(t) : t;
|
|
1114
1129
|
return n(r);
|
|
1115
1130
|
});
|
|
1116
|
-
},
|
|
1131
|
+
}, si = (e, t, n) => {
|
|
1117
1132
|
let r = [];
|
|
1118
1133
|
for (let [t, n] of Object.entries(e.fields)) (n.type === "timestamp" || n.type === "date") && r.push(t);
|
|
1119
1134
|
let i = t.map((e) => {
|
|
1120
|
-
let t =
|
|
1135
|
+
let t = si(e.target, e.children, n), r = e.relation.kind === "one", i = L(e), a = i ? pr({
|
|
1121
1136
|
relationName: e.relationName,
|
|
1122
1137
|
sourceTableName: e.source.tableName,
|
|
1123
1138
|
targetTableName: e.target.tableName,
|
|
@@ -1130,14 +1145,14 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
1130
1145
|
isSingle: r,
|
|
1131
1146
|
fromOverFetch: i,
|
|
1132
1147
|
cardinalityMessage: a,
|
|
1133
|
-
junction:
|
|
1148
|
+
junction: ci(e.junction, n)
|
|
1134
1149
|
};
|
|
1135
1150
|
});
|
|
1136
1151
|
return (e) => {
|
|
1137
1152
|
let t = { ...e };
|
|
1138
1153
|
for (let e of r) {
|
|
1139
1154
|
let r = t[e];
|
|
1140
|
-
typeof r == "string" && (t[e] =
|
|
1155
|
+
typeof r == "string" && (t[e] = ii(r, n));
|
|
1141
1156
|
}
|
|
1142
1157
|
for (let e of i) {
|
|
1143
1158
|
let n = t[e.name];
|
|
@@ -1147,7 +1162,7 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
1147
1162
|
}
|
|
1148
1163
|
if (e.fromOverFetch) {
|
|
1149
1164
|
let r = n;
|
|
1150
|
-
if (r.length > 1) throw new
|
|
1165
|
+
if (r.length > 1) throw new fr(e.cardinalityMessage);
|
|
1151
1166
|
t[e.name] = r.length === 0 ? null : e.decode(r[0]);
|
|
1152
1167
|
continue;
|
|
1153
1168
|
}
|
|
@@ -1159,204 +1174,204 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
1159
1174
|
}
|
|
1160
1175
|
return t;
|
|
1161
1176
|
};
|
|
1162
|
-
},
|
|
1177
|
+
}, ci = (e, t) => {
|
|
1163
1178
|
if (e === void 0) return;
|
|
1164
1179
|
let n = new Set(e.dateColumns), r = e.requested;
|
|
1165
1180
|
return (e) => {
|
|
1166
1181
|
let i = e._junction ?? {}, a = {};
|
|
1167
1182
|
for (let e of r) {
|
|
1168
1183
|
let r = i[e];
|
|
1169
|
-
a[e] = n.has(e) && typeof r == "string" ?
|
|
1184
|
+
a[e] = n.has(e) && typeof r == "string" ? ii(r, t) : r;
|
|
1170
1185
|
}
|
|
1171
1186
|
return {
|
|
1172
1187
|
...e,
|
|
1173
1188
|
_junction: a
|
|
1174
1189
|
};
|
|
1175
1190
|
};
|
|
1176
|
-
},
|
|
1177
|
-
let r = n.sql, i = n.nextAlias(), a = r(t.table.tableName), o = r(i), s =
|
|
1178
|
-
return s === null ? null : r`SELECT ${s} AS "__row" FROM ${a} AS ${o}${e.predicate ? r` WHERE ${
|
|
1179
|
-
},
|
|
1180
|
-
let i = n.sql, a = r === void 0 ? i`to_jsonb(${i(e)}.*)` : i`(to_jsonb(${i(e)}.*) - ${
|
|
1191
|
+
}, li = (e, t, n) => {
|
|
1192
|
+
let r = n.sql, i = n.nextAlias(), a = r(t.table.tableName), o = r(i), s = ui(i, t.children, n);
|
|
1193
|
+
return s === null ? null : r`SELECT ${s} AS "__row" FROM ${a} AS ${o}${e.predicate ? r` WHERE ${U(e.predicate, i, r)}` : r``}${x(e).length > 0 ? r` ORDER BY ${r.csv(x(e).map((e) => e.direction === "desc" ? r`${B(i, e.column, r)} DESC` : r`${B(i, e.column, r)} ASC`))}` : r``}${e.take === void 0 ? r`` : r` LIMIT ${H(e.take, r)}`}${e.skip === void 0 ? r`` : r` OFFSET ${H(e.skip, r)}`}`;
|
|
1194
|
+
}, ui = (e, t, n, r) => {
|
|
1195
|
+
let i = n.sql, a = r === void 0 ? i`to_jsonb(${i(e)}.*)` : i`(to_jsonb(${i(e)}.*) - ${V(ei, i)}::text)`;
|
|
1181
1196
|
if (t.length === 0 && r === void 0) return a;
|
|
1182
1197
|
let o = [];
|
|
1183
|
-
r !== void 0 && o.push(i`${
|
|
1198
|
+
r !== void 0 && o.push(i`${V("_junction", i)}, ${B(e, ei, i)}`);
|
|
1184
1199
|
for (let r of t) {
|
|
1185
|
-
let t =
|
|
1200
|
+
let t = di(r, e, n);
|
|
1186
1201
|
if (t === null) return null;
|
|
1187
|
-
o.push(i`${
|
|
1202
|
+
o.push(i`${V(r.relationName, i)}, ${t}`);
|
|
1188
1203
|
}
|
|
1189
1204
|
return i`${a} || jsonb_build_object(${i.csv(o)})`;
|
|
1190
|
-
},
|
|
1205
|
+
}, di = (e, t, n) => {
|
|
1191
1206
|
switch (e.relation.kind) {
|
|
1192
|
-
case "one": return
|
|
1193
|
-
case "many": return
|
|
1194
|
-
case "manyToMany": return
|
|
1207
|
+
case "one": return L(e) ? pi(Yr(e), t, n) : fi(e, t, n);
|
|
1208
|
+
case "many": return pi(e, t, n);
|
|
1209
|
+
case "manyToMany": return mi(e, t, n);
|
|
1195
1210
|
}
|
|
1196
|
-
},
|
|
1197
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1211
|
+
}, fi = (e, t, n) => {
|
|
1212
|
+
let r = n.sql, i = n.nextAlias(), a = ui(i, e.children, n);
|
|
1198
1213
|
if (a === null) return null;
|
|
1199
|
-
let o = e.fkSide === "source" ? r`${
|
|
1214
|
+
let o = e.fkSide === "source" ? r`${B(i, "id", r)} = ${B(t, e.foreignKey, r)}` : r`${B(i, e.foreignKey, r)} = ${B(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${U(e.branch.where, i, r)}`, c = R(i, e.branch.orderBy, r);
|
|
1200
1215
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}${c} LIMIT 1)`;
|
|
1201
|
-
},
|
|
1202
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1216
|
+
}, pi = (e, t, n) => {
|
|
1217
|
+
let r = n.sql, i = n.nextAlias(), a = ui(i, e.children, n);
|
|
1203
1218
|
if (a === null) return null;
|
|
1204
|
-
let o = r`${
|
|
1219
|
+
let o = r`${B(void 0, e.foreignKey, r)} = ${B(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${F(e.branch.where, r)}`, c = gi(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${H(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${H(e.branch.offset, r)}`;
|
|
1205
1220
|
return r`COALESCE((SELECT jsonb_agg(${a}) FROM (SELECT * FROM ${r(e.target.tableName)} WHERE ${o}${s}${c}${l}${u}) AS ${r(i)}), '[]'::jsonb)`;
|
|
1206
|
-
},
|
|
1207
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
1221
|
+
}, mi = (e, t, n) => {
|
|
1222
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = ui(o, e.children, n, e.junction);
|
|
1208
1223
|
if (c === null) return null;
|
|
1209
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1210
|
-
return r`COALESCE((SELECT jsonb_agg(${c}) FROM (SELECT ${r(o)}.*${m} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${
|
|
1211
|
-
},
|
|
1212
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1224
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${F(e.branch.where, r)}`, u = Hi(e, s, r), d = R(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${H(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${H(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : r`, ${hi(e.junction, s, r)} AS ${r(ei)}`;
|
|
1225
|
+
return r`COALESCE((SELECT jsonb_agg(${c}) FROM (SELECT ${r(o)}.*${m} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${B(o, "id", r)} = ${B(s, i.targetKey, r)} WHERE ${B(s, i.sourceKey, r)} = ${B(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), '[]'::jsonb)`;
|
|
1226
|
+
}, hi = (e, t, n) => e.present.length === 0 ? n`jsonb_build_object()` : n`jsonb_build_object(${n.csv(e.present.map((e) => n`${V(e, n)}, ${B(t, e, n)}`))})`, R = (e, t, n) => t === void 0 || t.length === 0 ? n`` : n` ORDER BY ${n.csv(t.map((t) => t.direction === "desc" ? n`${B(e, t.column, n)} DESC` : n`${B(e, t.column, n)} ASC`))}`, gi = (e, t) => e === void 0 || e.length === 0 ? t`` : t` ORDER BY ${t.csv(e.map((e) => e.direction === "desc" ? t`${t(e.column)} DESC` : t`${t(e.column)} ASC`))}`, _i = (e, t, n) => {
|
|
1227
|
+
let r = n.sql, i = n.nextAlias(), a = vi(i, t.table, t.children, n);
|
|
1213
1228
|
if (a === null) return null;
|
|
1214
|
-
let o = e.predicate ? r` WHERE ${
|
|
1229
|
+
let o = e.predicate ? r` WHERE ${U(e.predicate, i, r)}` : r``, s = x(e).length > 0 ? r` ORDER BY ${r.csv(x(e).map((e) => e.direction === "desc" ? r`${B(i, e.column, r)} DESC` : r`${B(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${H(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${H(e.skip, r)}`;
|
|
1215
1230
|
return r`SELECT ${a} AS "__row" FROM ${r(t.table.tableName)} AS ${r(i)}${o}${s}${c}${l}`;
|
|
1216
|
-
},
|
|
1231
|
+
}, vi = (e, t, n, r, i) => {
|
|
1217
1232
|
let a = r.sql, o = [];
|
|
1218
|
-
for (let n of Object.keys(t.fields)) o.push(a`${
|
|
1233
|
+
for (let n of Object.keys(t.fields)) o.push(a`${V(n, a)}, ${B(e, n, a)}`);
|
|
1219
1234
|
if (i !== void 0) {
|
|
1220
|
-
let e =
|
|
1221
|
-
o.push(a`${
|
|
1235
|
+
let e = yi(i.projection, i.source, a);
|
|
1236
|
+
o.push(a`${V("_junction", a)}, json_object(${e})`);
|
|
1222
1237
|
}
|
|
1223
1238
|
for (let t of n) {
|
|
1224
|
-
let n =
|
|
1239
|
+
let n = Ci(t, e, r);
|
|
1225
1240
|
if (n === null) return null;
|
|
1226
|
-
o.push(a`${
|
|
1241
|
+
o.push(a`${V(t.relationName, a)}, ${n}`);
|
|
1227
1242
|
}
|
|
1228
1243
|
return a`json_object(${a.csv(o)})`;
|
|
1229
|
-
},
|
|
1244
|
+
}, yi = (e, t, n) => e.present.length === 0 ? n`` : n.csv(e.present.map((e) => n`${V(e, n)}, ${B(t.alias, t.physical(e), n)}`)), bi = (e, t, n) => e.present.length === 0 ? n`` : n`, ${n.csv(e.present.map((e) => n`${B(t, e, n)} AS ${n($r(e))}`))}`, xi = (e) => ({
|
|
1230
1245
|
alias: e,
|
|
1231
|
-
physical:
|
|
1232
|
-
}),
|
|
1246
|
+
physical: $r
|
|
1247
|
+
}), Si = (e) => ({
|
|
1233
1248
|
alias: e,
|
|
1234
1249
|
physical: (e) => e
|
|
1235
|
-
}),
|
|
1250
|
+
}), Ci = (e, t, n) => {
|
|
1236
1251
|
switch (e.relation.kind) {
|
|
1237
|
-
case "one": return
|
|
1238
|
-
case "many": return
|
|
1239
|
-
case "manyToMany": return
|
|
1252
|
+
case "one": return L(e) ? Ti(Yr(e), t, n) : wi(e, t, n);
|
|
1253
|
+
case "many": return Ti(e, t, n);
|
|
1254
|
+
case "manyToMany": return Ei(e, t, n);
|
|
1240
1255
|
}
|
|
1241
|
-
},
|
|
1242
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1256
|
+
}, wi = (e, t, n) => {
|
|
1257
|
+
let r = n.sql, i = n.nextAlias(), a = vi(i, e.target, e.children, n);
|
|
1243
1258
|
if (a === null) return null;
|
|
1244
|
-
let o = e.fkSide === "source" ? r`${
|
|
1259
|
+
let o = e.fkSide === "source" ? r`${B(i, "id", r)} = ${B(t, e.foreignKey, r)}` : r`${B(i, e.foreignKey, r)} = ${B(t, e.sourceKey, r)}`;
|
|
1245
1260
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
|
|
1246
|
-
},
|
|
1247
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1261
|
+
}, Ti = (e, t, n) => {
|
|
1262
|
+
let r = n.sql, i = n.nextAlias(), a = vi(i, e.target, e.children, n);
|
|
1248
1263
|
if (a === null) return null;
|
|
1249
|
-
let o = r`${
|
|
1264
|
+
let o = r`${B(void 0, e.foreignKey, r)} = ${B(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${F(W(e.branch.where), r)}`, c = gi(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${H(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${H(e.branch.offset, r)}`;
|
|
1250
1265
|
return r`COALESCE((SELECT json_group_array(${a}) FROM (SELECT * FROM ${r(e.target.tableName)} WHERE ${o}${s}${c}${l}${u}) AS ${r(i)}), json('[]'))`;
|
|
1251
|
-
},
|
|
1252
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
1266
|
+
}, Ei = (e, t, n) => {
|
|
1267
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = vi(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
1253
1268
|
projection: e.junction,
|
|
1254
|
-
source:
|
|
1269
|
+
source: xi(o)
|
|
1255
1270
|
});
|
|
1256
1271
|
if (c === null) return null;
|
|
1257
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1258
|
-
return r`COALESCE((SELECT json_group_array(${c}) FROM (SELECT ${r(o)}.*${m} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${
|
|
1259
|
-
},
|
|
1260
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1272
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${F(W(e.branch.where), r)}`, u = Hi(e, s, r, !0), d = R(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${H(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${H(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : bi(e.junction, s, r);
|
|
1273
|
+
return r`COALESCE((SELECT json_group_array(${c}) FROM (SELECT ${r(o)}.*${m} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${B(o, "id", r)} = ${B(s, i.targetKey, r)} WHERE ${B(s, i.sourceKey, r)} = ${B(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), json('[]'))`;
|
|
1274
|
+
}, Di = (e, t, n) => {
|
|
1275
|
+
let r = n.sql, i = n.nextAlias(), a = z(i, t.table, t.children, n);
|
|
1261
1276
|
if (a === null) return null;
|
|
1262
|
-
let o = e.predicate ? r` WHERE ${
|
|
1277
|
+
let o = e.predicate ? r` WHERE ${U(e.predicate, i, r)}` : r``, s = x(e).length > 0 ? r` ORDER BY ${r.csv(x(e).map((e) => e.direction === "desc" ? r`${B(i, e.column, r)} DESC` : r`${B(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${H(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${H(e.skip, r)}`;
|
|
1263
1278
|
return r`SELECT ${a} AS \`__row\` FROM ${r(t.table.tableName)} AS ${r(i)}${o}${s}${c}${l}`;
|
|
1264
|
-
},
|
|
1279
|
+
}, z = (e, t, n, r, i) => {
|
|
1265
1280
|
let a = r.sql, o = [];
|
|
1266
|
-
for (let n of Object.keys(t.fields)) o.push(a`${
|
|
1281
|
+
for (let n of Object.keys(t.fields)) o.push(a`${V(n, a)}, ${B(e, n, a)}`);
|
|
1267
1282
|
if (i !== void 0) {
|
|
1268
|
-
let e =
|
|
1269
|
-
o.push(a`${
|
|
1283
|
+
let e = yi(i.projection, i.source, a);
|
|
1284
|
+
o.push(a`${V("_junction", a)}, JSON_OBJECT(${e})`);
|
|
1270
1285
|
}
|
|
1271
1286
|
for (let t of n) {
|
|
1272
|
-
let n =
|
|
1287
|
+
let n = Oi(t, e, r);
|
|
1273
1288
|
if (n === null) return null;
|
|
1274
|
-
o.push(a`${
|
|
1289
|
+
o.push(a`${V(t.relationName, a)}, ${n}`);
|
|
1275
1290
|
}
|
|
1276
1291
|
return a`JSON_OBJECT(${a.csv(o)})`;
|
|
1277
|
-
},
|
|
1292
|
+
}, Oi = (e, t, n) => {
|
|
1278
1293
|
switch (e.relation.kind) {
|
|
1279
1294
|
case "one":
|
|
1280
|
-
if (
|
|
1281
|
-
let r =
|
|
1282
|
-
return n.dialect === "mariadb" ?
|
|
1295
|
+
if (L(e)) {
|
|
1296
|
+
let r = Yr(e);
|
|
1297
|
+
return n.dialect === "mariadb" ? Mi(r, t, n) : Ai(r, t, n);
|
|
1283
1298
|
}
|
|
1284
|
-
return
|
|
1285
|
-
case "many": return n.dialect === "mariadb" ?
|
|
1286
|
-
case "manyToMany": return n.dialect === "mariadb" ?
|
|
1299
|
+
return ki(e, t, n);
|
|
1300
|
+
case "many": return n.dialect === "mariadb" ? Mi(e, t, n) : Ai(e, t, n);
|
|
1301
|
+
case "manyToMany": return n.dialect === "mariadb" ? Ni(e, t, n) : ji(e, t, n);
|
|
1287
1302
|
}
|
|
1288
|
-
},
|
|
1289
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1303
|
+
}, ki = (e, t, n) => {
|
|
1304
|
+
let r = n.sql, i = n.nextAlias(), a = z(i, e.target, e.children, n);
|
|
1290
1305
|
if (a === null) return null;
|
|
1291
|
-
let o = e.fkSide === "source" ? r`${
|
|
1306
|
+
let o = e.fkSide === "source" ? r`${B(i, "id", r)} = ${B(t, e.foreignKey, r)}` : r`${B(i, e.foreignKey, r)} = ${B(t, e.sourceKey, r)}`;
|
|
1292
1307
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
|
|
1293
|
-
},
|
|
1294
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1308
|
+
}, Ai = (e, t, n) => {
|
|
1309
|
+
let r = n.sql, i = n.nextAlias(), a = z(i, e.target, e.children, n);
|
|
1295
1310
|
if (a === null) return null;
|
|
1296
|
-
let o = r`${
|
|
1311
|
+
let o = r`${B(void 0, e.foreignKey, r)} = ${B(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${F(W(e.branch.where), r)}`, c = gi(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${H(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${H(e.branch.offset, r)}`;
|
|
1297
1312
|
return r`COALESCE((SELECT JSON_ARRAYAGG(${a}) FROM (SELECT * FROM ${r(e.target.tableName)} WHERE ${o}${s}${c}${l}${u}) AS ${r(i)}), JSON_ARRAY())`;
|
|
1298
|
-
},
|
|
1299
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
1313
|
+
}, ji = (e, t, n) => {
|
|
1314
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = z(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
1300
1315
|
projection: e.junction,
|
|
1301
|
-
source:
|
|
1316
|
+
source: xi(o)
|
|
1302
1317
|
});
|
|
1303
1318
|
if (c === null) return null;
|
|
1304
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1305
|
-
return r`COALESCE((SELECT JSON_ARRAYAGG(${c}) FROM (SELECT ${r(o)}.*${m} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${
|
|
1306
|
-
},
|
|
1307
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1319
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${F(W(e.branch.where), r)}`, u = Hi(e, s, r, !0), d = R(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${H(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${H(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : bi(e.junction, s, r);
|
|
1320
|
+
return r`COALESCE((SELECT JSON_ARRAYAGG(${c}) FROM (SELECT ${r(o)}.*${m} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${B(o, "id", r)} = ${B(s, i.targetKey, r)} WHERE ${B(s, i.sourceKey, r)} = ${B(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), JSON_ARRAY())`;
|
|
1321
|
+
}, Mi = (e, t, n) => {
|
|
1322
|
+
let r = n.sql, i = n.nextAlias(), a = z(i, e.target, e.children, n);
|
|
1308
1323
|
if (a === null) return null;
|
|
1309
|
-
let o = r`${
|
|
1310
|
-
if (e.branch.limit === void 0 && e.branch.offset === void 0) return r`COALESCE((SELECT JSON_ARRAYAGG(${a}${c.length > 0 ? r` ORDER BY ${r.csv(c.map((e) => e.direction === "desc" ? r`${
|
|
1311
|
-
let l = c.length > 0 ? r` ORDER BY ${r.csv(c.map((e) => e.direction === "desc" ? r`${r(e.column)} DESC` : r`${r(e.column)} ASC`))}` : r` ORDER BY ${r("id")}`, u = e.branch.limit, d = e.branch.offset, f = u !== void 0 && d !== void 0 ? r` AND ${
|
|
1312
|
-
return r`COALESCE((SELECT JSON_ARRAYAGG(${a} ORDER BY ${
|
|
1313
|
-
},
|
|
1324
|
+
let o = r`${B(i, e.foreignKey, r)} = ${B(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${F(W(e.branch.where), r)}`, c = e.branch.orderBy ?? [];
|
|
1325
|
+
if (e.branch.limit === void 0 && e.branch.offset === void 0) return r`COALESCE((SELECT JSON_ARRAYAGG(${a}${c.length > 0 ? r` ORDER BY ${r.csv(c.map((e) => e.direction === "desc" ? r`${B(i, e.column, r)} DESC` : r`${B(i, e.column, r)} ASC`))}` : r``}) FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}), JSON_ARRAY())`;
|
|
1326
|
+
let l = c.length > 0 ? r` ORDER BY ${r.csv(c.map((e) => e.direction === "desc" ? r`${r(e.column)} DESC` : r`${r(e.column)} ASC`))}` : r` ORDER BY ${r("id")}`, u = e.branch.limit, d = e.branch.offset, f = u !== void 0 && d !== void 0 ? r` AND ${B(i, "rn", r)} > ${H(d, r)} AND ${B(i, "rn", r)} <= ${H(d + u, r)}` : u === void 0 ? r` AND ${B(i, "rn", r)} > ${H(d, r)}` : r` AND ${B(i, "rn", r)} <= ${H(u, r)}`;
|
|
1327
|
+
return r`COALESCE((SELECT JSON_ARRAYAGG(${a} ORDER BY ${B(i, "rn", r)}) FROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY ${r(e.foreignKey)}${l}) AS rn FROM ${r(e.target.tableName)}) AS ${r(i)} WHERE ${o}${s}${f}), JSON_ARRAY())`;
|
|
1328
|
+
}, Ni = (e, t, n) => {
|
|
1314
1329
|
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = (t) => e.junction === void 0 ? void 0 : {
|
|
1315
1330
|
projection: e.junction,
|
|
1316
1331
|
source: t
|
|
1317
|
-
}, l = r`${
|
|
1332
|
+
}, l = r`${B(s, i.sourceKey, r)} = ${B(t, "id", r)}`, u = r`${B(o, "id", r)} = ${B(s, i.targetKey, r)}`, d = e.branch.where === void 0 ? r`` : r` AND ${F(W(e.branch.where), r)}`, f = Hi(e, s, r, !0), p = e.branch.orderBy ?? [];
|
|
1318
1333
|
if (e.branch.limit === void 0 && e.branch.offset === void 0) {
|
|
1319
|
-
let t =
|
|
1320
|
-
return t === null ? null : r`COALESCE((SELECT JSON_ARRAYAGG(${t}${p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${
|
|
1334
|
+
let t = z(o, e.target, e.children, n, c(Si(s)));
|
|
1335
|
+
return t === null ? null : r`COALESCE((SELECT JSON_ARRAYAGG(${t}${p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${B(o, e.column, r)} DESC` : r`${B(o, e.column, r)} ASC`))}` : r``}) FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${u} WHERE ${l}${f}${d}), JSON_ARRAY())`;
|
|
1321
1336
|
}
|
|
1322
|
-
let m = p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${
|
|
1337
|
+
let m = p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${B(o, e.column, r)} DESC` : r`${B(o, e.column, r)} ASC`))}` : r` ORDER BY ${B(o, "id", r)}`, h = e.branch.limit, g = e.branch.offset, _ = h !== void 0 && g !== void 0 ? r` AND ${B(o, "rn", r)} > ${H(g, r)} AND ${B(o, "rn", r)} <= ${H(g + h, r)}` : h === void 0 ? r` AND ${B(o, "rn", r)} > ${H(g, r)}` : r` AND ${B(o, "rn", r)} <= ${H(h, r)}`, ee = e.branch.onJunction === void 0 ? r`` : r` WHERE ${U(W(e.branch.onJunction), s, r)}`, te = z(o, e.target, e.children, n, c(xi(o)));
|
|
1323
1338
|
if (te === null) return null;
|
|
1324
|
-
let ne = e.junction === void 0 ? r`` :
|
|
1325
|
-
return r`COALESCE((SELECT JSON_ARRAYAGG(${te} ORDER BY ${
|
|
1326
|
-
},
|
|
1327
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1339
|
+
let ne = e.junction === void 0 ? r`` : bi(e.junction, s, r);
|
|
1340
|
+
return r`COALESCE((SELECT JSON_ARRAYAGG(${te} ORDER BY ${B(o, "rn", r)}) FROM (SELECT ${r(o)}.*${ne}, ${B(s, i.sourceKey, r)} AS ${r(`__src_${i.sourceKey}`)}, ROW_NUMBER() OVER (PARTITION BY ${B(s, i.sourceKey, r)}${m}) AS rn FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${u}${ee}) AS ${r(o)} WHERE ${B(o, `__src_${i.sourceKey}`, r)} = ${B(t, "id", r)}${d}${_}), JSON_ARRAY())`;
|
|
1341
|
+
}, Pi = (e, t, n) => {
|
|
1342
|
+
let r = n.sql, i = n.nextAlias(), a = Fi(i, t.table, t.children, n);
|
|
1328
1343
|
if (a === null) return null;
|
|
1329
|
-
let o = e.predicate ? r` WHERE ${
|
|
1344
|
+
let o = e.predicate ? r` WHERE ${U(e.predicate, i, r)}` : r``, s = x(e).length > 0 ? r` ORDER BY ${r.csv(x(e).map((e) => e.direction === "desc" ? r`${B(i, e.column, r)} DESC` : r`${B(i, e.column, r)} ASC`))}` : r``, c = r``, l = r``;
|
|
1330
1345
|
if (e.skip !== void 0) {
|
|
1331
1346
|
let t = x(e).length > 0 ? s : r` ORDER BY (SELECT NULL)`;
|
|
1332
|
-
l = e.take === void 0 ? r`${t} OFFSET ${
|
|
1333
|
-
} else e.take !== void 0 && (c = r`TOP ${
|
|
1347
|
+
l = e.take === void 0 ? r`${t} OFFSET ${H(e.skip, r)} ROWS` : r`${t} OFFSET ${H(e.skip, r)} ROWS FETCH NEXT ${H(e.take, r)} ROWS ONLY`;
|
|
1348
|
+
} else e.take !== void 0 && (c = r`TOP ${H(e.take, r)} `);
|
|
1334
1349
|
let u = e.skip === void 0 ? s : r``;
|
|
1335
1350
|
return r`SELECT ${c}(SELECT ${a} FOR JSON PATH, INCLUDE_NULL_VALUES, WITHOUT_ARRAY_WRAPPER) AS ${r("__row")} FROM ${r(t.table.tableName)} AS ${r(i)}${o}${u}${l}`;
|
|
1336
|
-
},
|
|
1351
|
+
}, Fi = (e, t, n, r, i) => {
|
|
1337
1352
|
let a = r.sql, o = [];
|
|
1338
|
-
for (let n of Object.keys(t.fields)) o.push(a`${
|
|
1339
|
-
if (i !== void 0) for (let e of i.projection.present) o.push(a`${
|
|
1353
|
+
for (let n of Object.keys(t.fields)) o.push(a`${B(e, n, a)} AS ${a(n)}`);
|
|
1354
|
+
if (i !== void 0) for (let e of i.projection.present) o.push(a`${B(i.source.alias, i.source.physical(e), a)} AS ${Ii(`_junction.${e}`, a)}`);
|
|
1340
1355
|
for (let t of n) {
|
|
1341
|
-
let n =
|
|
1356
|
+
let n = Li(t, e, r);
|
|
1342
1357
|
if (n === null) return null;
|
|
1343
1358
|
o.push(n);
|
|
1344
1359
|
}
|
|
1345
1360
|
return a.csv(o);
|
|
1346
|
-
},
|
|
1361
|
+
}, Ii = (e, t) => t.unsafe(`[${e.replace(/]/g, "]]")}]`), Li = (e, t, n) => {
|
|
1347
1362
|
switch (e.relation.kind) {
|
|
1348
|
-
case "one": return
|
|
1349
|
-
case "many": return
|
|
1350
|
-
case "manyToMany": return
|
|
1363
|
+
case "one": return L(e) ? Bi(Yr(e), t, n) : Ri(e, t, n);
|
|
1364
|
+
case "many": return Bi(e, t, n);
|
|
1365
|
+
case "manyToMany": return Vi(e, t, n);
|
|
1351
1366
|
}
|
|
1352
|
-
},
|
|
1353
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1367
|
+
}, Ri = (e, t, n) => {
|
|
1368
|
+
let r = n.sql, i = n.nextAlias(), a = Fi(i, e.target, e.children, n);
|
|
1354
1369
|
if (a === null) return null;
|
|
1355
|
-
let o = e.fkSide === "source" ? r`${
|
|
1370
|
+
let o = e.fkSide === "source" ? r`${B(i, "id", r)} = ${B(t, e.foreignKey, r)}` : r`${B(i, e.foreignKey, r)} = ${B(t, e.sourceKey, r)}`;
|
|
1356
1371
|
return r`JSON_QUERY((SELECT TOP 1 ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} FOR JSON PATH, INCLUDE_NULL_VALUES, WITHOUT_ARRAY_WRAPPER)) AS ${r(e.relationName)}`;
|
|
1357
|
-
},
|
|
1372
|
+
}, zi = (e, t, n) => {
|
|
1358
1373
|
if (e.offset !== void 0) {
|
|
1359
|
-
let r = e.orderBy && e.orderBy.length > 0 ? t : n` ORDER BY (SELECT NULL)`, i = e.limit === void 0 ? n`${r} OFFSET ${
|
|
1374
|
+
let r = e.orderBy && e.orderBy.length > 0 ? t : n` ORDER BY (SELECT NULL)`, i = e.limit === void 0 ? n`${r} OFFSET ${H(e.offset, n)} ROWS` : n`${r} OFFSET ${H(e.offset, n)} ROWS FETCH NEXT ${H(e.limit, n)} ROWS ONLY`;
|
|
1360
1375
|
return {
|
|
1361
1376
|
top: n``,
|
|
1362
1377
|
pagination: i,
|
|
@@ -1364,33 +1379,33 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
1364
1379
|
};
|
|
1365
1380
|
}
|
|
1366
1381
|
return {
|
|
1367
|
-
top: e.limit === void 0 ? n`` : n`TOP ${
|
|
1382
|
+
top: e.limit === void 0 ? n`` : n`TOP ${H(e.limit, n)} `,
|
|
1368
1383
|
pagination: n``,
|
|
1369
1384
|
finalOrder: t
|
|
1370
1385
|
};
|
|
1371
|
-
},
|
|
1372
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1386
|
+
}, Bi = (e, t, n) => {
|
|
1387
|
+
let r = n.sql, i = n.nextAlias(), a = Fi(i, e.target, e.children, n);
|
|
1373
1388
|
if (a === null) return null;
|
|
1374
|
-
let o = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1375
|
-
return r`ISNULL(JSON_QUERY((SELECT ${c}${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${
|
|
1376
|
-
},
|
|
1377
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
1389
|
+
let o = e.branch.where === void 0 ? r`` : r` AND ${U(e.branch.where, i, r)}`, s = R(i, e.branch.orderBy, r), { top: c, pagination: l, finalOrder: u } = zi(e.branch, s, r);
|
|
1390
|
+
return r`ISNULL(JSON_QUERY((SELECT ${c}${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${B(i, e.foreignKey, r)} = ${B(t, e.sourceKey, r)}${o}${u}${l} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
|
|
1391
|
+
}, Vi = (e, t, n) => {
|
|
1392
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = Fi(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
1378
1393
|
projection: e.junction,
|
|
1379
|
-
source:
|
|
1394
|
+
source: Si(s)
|
|
1380
1395
|
});
|
|
1381
1396
|
if (c === null) return null;
|
|
1382
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1383
|
-
return r`ISNULL(JSON_QUERY((SELECT ${f}${c} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${
|
|
1384
|
-
},
|
|
1397
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${U(e.branch.where, o, r)}`, u = Hi(e, s, r), d = R(o, e.branch.orderBy, r), { top: f, pagination: p, finalOrder: m } = zi(e.branch, d, r);
|
|
1398
|
+
return r`ISNULL(JSON_QUERY((SELECT ${f}${c} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${B(o, "id", r)} = ${B(s, i.targetKey, r)} WHERE ${B(s, i.sourceKey, r)} = ${B(t, "id", r)}${u}${l}${m}${p} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
|
|
1399
|
+
}, B = (e, t, n) => e === void 0 ? n`${n(t)}` : n`${n(e)}.${n(t)}`, V = (e, t) => t.unsafe(`'${e.replace(/'/g, "''")}'`), H = (e, t) => {
|
|
1385
1400
|
if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw Error(`literalInt: expected non-negative integer, got ${e}`);
|
|
1386
1401
|
return t.unsafe(String(e));
|
|
1387
|
-
},
|
|
1402
|
+
}, U = (e, t, n) => F(Ui(e, t), n), Hi = (e, t, n, r = !1) => {
|
|
1388
1403
|
let i = e.branch.onJunction;
|
|
1389
|
-
return i === void 0 ? n`` : n` AND ${
|
|
1390
|
-
},
|
|
1391
|
-
if ("not" in e) return { not:
|
|
1392
|
-
if ("and" in e) return { and: e.and.map((e) =>
|
|
1393
|
-
if ("or" in e) return { or: e.or.map((e) =>
|
|
1404
|
+
return i === void 0 ? n`` : n` AND ${U(r ? W(i) : i, t, n)}`;
|
|
1405
|
+
}, Ui = (e, t) => {
|
|
1406
|
+
if ("not" in e) return { not: Ui(e.not, t) };
|
|
1407
|
+
if ("and" in e) return { and: e.and.map((e) => Ui(e, t)) };
|
|
1408
|
+
if ("or" in e) return { or: e.or.map((e) => Ui(e, t)) };
|
|
1394
1409
|
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
1395
1410
|
let n = e;
|
|
1396
1411
|
return {
|
|
@@ -1404,23 +1419,23 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
1404
1419
|
...n,
|
|
1405
1420
|
column: `${t}.${n.column}`
|
|
1406
1421
|
};
|
|
1407
|
-
},
|
|
1408
|
-
if ("not" in e) return { not:
|
|
1409
|
-
if ("and" in e) return { and: e.and.map((e) =>
|
|
1410
|
-
if ("or" in e) return { or: e.or.map((e) =>
|
|
1422
|
+
}, W = (e) => {
|
|
1423
|
+
if ("not" in e) return { not: W(e.not) };
|
|
1424
|
+
if ("and" in e) return { and: e.and.map((e) => W(e)) };
|
|
1425
|
+
if ("or" in e) return { or: e.or.map((e) => W(e)) };
|
|
1411
1426
|
if (e.op === "subquery-in" || e.op === "subquery-not-in" || e.op === "exists" || e.op === "not-exists") return e;
|
|
1412
1427
|
let t = e;
|
|
1413
1428
|
return {
|
|
1414
1429
|
...t,
|
|
1415
|
-
value:
|
|
1430
|
+
value: Wi(t.value)
|
|
1416
1431
|
};
|
|
1417
|
-
},
|
|
1418
|
-
e.actors !== void 0 && (
|
|
1419
|
-
},
|
|
1432
|
+
}, Wi = (e) => e == null ? e : e instanceof Date ? e.toISOString() : typeof e == "boolean" ? +!!e : Array.isArray(e) ? e.map((e) => Wi(e)) : e, Gi = Symbol.for("@voltro/database/coreTablesRegistry"), Ki = globalThis, qi = Ki[Gi] ?? (Ki[Gi] = {}), Ji = (e) => {
|
|
1433
|
+
e.actors !== void 0 && (qi.actors = e.actors), e.tenants !== void 0 && (qi.tenants = e.tenants);
|
|
1434
|
+
}, Yi = (e, t) => () => {
|
|
1420
1435
|
let n = e();
|
|
1421
1436
|
if (n === void 0) throw Error(`core '${t}' table not registered; expected the framework CLI or your migrate step to call registerCoreTables({ ${t}: () => ${t}Table }) before the database handle is constructed`);
|
|
1422
1437
|
return n();
|
|
1423
|
-
},
|
|
1438
|
+
}, Xi = () => Yi(() => qi.actors, "actors"), Zi = () => Yi(() => qi.tenants, "tenants"), Qi = T("actors", {
|
|
1424
1439
|
id: _(),
|
|
1425
1440
|
kind: t().oneOf([
|
|
1426
1441
|
"user",
|
|
@@ -1430,73 +1445,73 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
1430
1445
|
]),
|
|
1431
1446
|
displayName: t().nullable(),
|
|
1432
1447
|
createdAt: C().default("now")
|
|
1433
|
-
}),
|
|
1448
|
+
}), $i = (e, t) => ({
|
|
1434
1449
|
column: e,
|
|
1435
1450
|
op: "eq",
|
|
1436
1451
|
value: t
|
|
1437
|
-
}),
|
|
1452
|
+
}), ea = (e, t) => ({
|
|
1438
1453
|
column: e,
|
|
1439
1454
|
op: "neq",
|
|
1440
1455
|
value: t
|
|
1441
|
-
}),
|
|
1456
|
+
}), ta = (e, t) => ({
|
|
1442
1457
|
column: e,
|
|
1443
1458
|
op: "gt",
|
|
1444
1459
|
value: t
|
|
1445
|
-
}),
|
|
1460
|
+
}), na = (e, t) => ({
|
|
1446
1461
|
column: e,
|
|
1447
1462
|
op: "gte",
|
|
1448
1463
|
value: t
|
|
1449
|
-
}),
|
|
1464
|
+
}), ra = (e, t) => ({
|
|
1450
1465
|
column: e,
|
|
1451
1466
|
op: "lt",
|
|
1452
1467
|
value: t
|
|
1453
|
-
}),
|
|
1468
|
+
}), ia = (e, t) => ({
|
|
1454
1469
|
column: e,
|
|
1455
1470
|
op: "lte",
|
|
1456
1471
|
value: t
|
|
1457
|
-
}),
|
|
1472
|
+
}), aa = (e, t) => ({
|
|
1458
1473
|
column: e,
|
|
1459
1474
|
op: "in",
|
|
1460
1475
|
value: t
|
|
1461
|
-
}),
|
|
1476
|
+
}), oa = (e, t) => ({
|
|
1462
1477
|
column: e,
|
|
1463
1478
|
op: "notIn",
|
|
1464
1479
|
value: t
|
|
1465
|
-
}),
|
|
1480
|
+
}), sa = (e, t) => ({
|
|
1466
1481
|
column: e,
|
|
1467
1482
|
op: "contains",
|
|
1468
1483
|
value: t
|
|
1469
|
-
}),
|
|
1484
|
+
}), ca = (e, t) => ({
|
|
1470
1485
|
column: e,
|
|
1471
1486
|
op: "startsWith",
|
|
1472
1487
|
value: t
|
|
1473
|
-
}),
|
|
1488
|
+
}), la = (e, t) => ({
|
|
1474
1489
|
column: e,
|
|
1475
1490
|
op: "arrayContains",
|
|
1476
1491
|
value: t
|
|
1477
|
-
}),
|
|
1492
|
+
}), ua = (e, t) => ({
|
|
1478
1493
|
column: e,
|
|
1479
1494
|
op: "arrayOverlaps",
|
|
1480
1495
|
value: t
|
|
1481
|
-
}),
|
|
1496
|
+
}), da = (e, t) => ({
|
|
1482
1497
|
column: e,
|
|
1483
1498
|
op: "arrayHas",
|
|
1484
1499
|
value: t
|
|
1485
|
-
}),
|
|
1500
|
+
}), fa = {
|
|
1486
1501
|
column: "id",
|
|
1487
1502
|
op: "in",
|
|
1488
1503
|
value: []
|
|
1489
|
-
},
|
|
1504
|
+
}, pa = (e) => ({
|
|
1490
1505
|
column: e,
|
|
1491
1506
|
op: "isNull"
|
|
1492
|
-
}),
|
|
1507
|
+
}), ma = (e) => ({
|
|
1493
1508
|
column: e,
|
|
1494
1509
|
op: "isNotNull"
|
|
1495
|
-
}),
|
|
1510
|
+
}), ha = (e, t) => ({
|
|
1496
1511
|
column: e,
|
|
1497
1512
|
op: "spatial",
|
|
1498
1513
|
value: t
|
|
1499
|
-
}),
|
|
1514
|
+
}), ga = (...e) => ({ and: e }), _a = (...e) => ({ or: e }), va = (e) => ({ not: e }), ya = (e, ...t) => {
|
|
1500
1515
|
if (t.length === 0) throw Error(`jsonField("${e}"): at least one path segment is required`);
|
|
1501
1516
|
let n = (n, r) => ({
|
|
1502
1517
|
column: e,
|
|
@@ -1518,33 +1533,33 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
1518
1533
|
isNull: () => n("isNull"),
|
|
1519
1534
|
isNotNull: () => n("isNotNull")
|
|
1520
1535
|
};
|
|
1521
|
-
},
|
|
1536
|
+
}, ba = (e) => "descriptor" in e ? e.descriptor : e, xa = (e, t) => ({
|
|
1522
1537
|
column: e,
|
|
1523
1538
|
op: "subquery-in",
|
|
1524
|
-
subquery:
|
|
1525
|
-
}),
|
|
1539
|
+
subquery: ba(t)
|
|
1540
|
+
}), Sa = (e, t) => ({
|
|
1526
1541
|
column: e,
|
|
1527
1542
|
op: "subquery-not-in",
|
|
1528
|
-
subquery:
|
|
1529
|
-
}),
|
|
1543
|
+
subquery: ba(t)
|
|
1544
|
+
}), Ca = (e) => ({
|
|
1530
1545
|
op: "exists",
|
|
1531
|
-
subquery:
|
|
1532
|
-
}),
|
|
1546
|
+
subquery: ba(e)
|
|
1547
|
+
}), wa = (e) => ({
|
|
1533
1548
|
op: "not-exists",
|
|
1534
|
-
subquery:
|
|
1535
|
-
}),
|
|
1549
|
+
subquery: ba(e)
|
|
1550
|
+
}), Ta = (e, t) => e === t || e instanceof Date && t instanceof Date && e.getTime() === t.getTime(), Ea = (e, t) => {
|
|
1536
1551
|
if (e == null || t == null) return null;
|
|
1537
1552
|
let n = e instanceof Date ? e.getTime() : e, r = t instanceof Date ? t.getTime() : t;
|
|
1538
1553
|
return typeof n == typeof r ? n === r ? 0 : n > r ? 1 : -1 : null;
|
|
1539
|
-
},
|
|
1554
|
+
}, Da = (e, t, n = null) => {
|
|
1540
1555
|
if (!t) return !1;
|
|
1541
|
-
if ("not" in e) return !
|
|
1556
|
+
if ("not" in e) return !Da(e.not, t, n);
|
|
1542
1557
|
if ("and" in e) {
|
|
1543
|
-
for (let r of e.and) if (!
|
|
1558
|
+
for (let r of e.and) if (!Da(r, t, n)) return !1;
|
|
1544
1559
|
return !0;
|
|
1545
1560
|
}
|
|
1546
1561
|
if ("or" in e) {
|
|
1547
|
-
for (let r of e.or) if (
|
|
1562
|
+
for (let r of e.or) if (Da(r, t, n)) return !0;
|
|
1548
1563
|
return !1;
|
|
1549
1564
|
}
|
|
1550
1565
|
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
@@ -1561,14 +1576,14 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
1561
1576
|
}
|
|
1562
1577
|
let r = e, i = t[r.column];
|
|
1563
1578
|
switch (r.op) {
|
|
1564
|
-
case "eq": return
|
|
1565
|
-
case "neq": return !
|
|
1566
|
-
case "gt": return (
|
|
1567
|
-
case "gte": return (
|
|
1568
|
-
case "lt": return (
|
|
1569
|
-
case "lte": return (
|
|
1570
|
-
case "in": return Array.isArray(r.value) && r.value.some((e) =>
|
|
1571
|
-
case "notIn": return Array.isArray(r.value) && !r.value.some((e) =>
|
|
1579
|
+
case "eq": return Ta(i, r.value);
|
|
1580
|
+
case "neq": return !Ta(i, r.value);
|
|
1581
|
+
case "gt": return (Ea(i, r.value) ?? -1) > 0;
|
|
1582
|
+
case "gte": return (Ea(i, r.value) ?? -1) >= 0;
|
|
1583
|
+
case "lt": return (Ea(i, r.value) ?? 1) < 0;
|
|
1584
|
+
case "lte": return (Ea(i, r.value) ?? 1) <= 0;
|
|
1585
|
+
case "in": return Array.isArray(r.value) && r.value.some((e) => Ta(i, e));
|
|
1586
|
+
case "notIn": return Array.isArray(r.value) && !r.value.some((e) => Ta(i, e));
|
|
1572
1587
|
case "contains": return typeof i == "string" && typeof r.value == "string" && i.toLowerCase().includes(r.value.toLowerCase());
|
|
1573
1588
|
case "startsWith": return typeof i == "string" && typeof r.value == "string" && i.startsWith(r.value);
|
|
1574
1589
|
case "arrayContains": {
|
|
@@ -1584,17 +1599,17 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
1584
1599
|
case "isNotNull": return i != null;
|
|
1585
1600
|
case "spatial": throw Error("@voltro/plugin-postgis: spatial predicates (ST_DWithin / ST_Contains / ST_Within / ST_Intersects / bbox &&) are not evaluable in-memory — use them in one-shot ctx.store.query reads, not reactive subscriptions.");
|
|
1586
1601
|
}
|
|
1587
|
-
},
|
|
1602
|
+
}, Oa = function* (e) {
|
|
1588
1603
|
if ("not" in e) {
|
|
1589
|
-
yield*
|
|
1604
|
+
yield* Oa(e.not);
|
|
1590
1605
|
return;
|
|
1591
1606
|
}
|
|
1592
1607
|
if ("and" in e) {
|
|
1593
|
-
for (let t of e.and) yield*
|
|
1608
|
+
for (let t of e.and) yield* Oa(t);
|
|
1594
1609
|
return;
|
|
1595
1610
|
}
|
|
1596
1611
|
if ("or" in e) {
|
|
1597
|
-
for (let t of e.or) yield*
|
|
1612
|
+
for (let t of e.or) yield* Oa(t);
|
|
1598
1613
|
return;
|
|
1599
1614
|
}
|
|
1600
1615
|
e.op === "subquery-in" || e.op === "subquery-not-in" ? yield {
|
|
@@ -1604,46 +1619,46 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
1604
1619
|
kind: "exists",
|
|
1605
1620
|
descriptor: e.subquery
|
|
1606
1621
|
});
|
|
1607
|
-
},
|
|
1622
|
+
}, ka = function* (e, t = !0) {
|
|
1608
1623
|
if ("not" in e) {
|
|
1609
|
-
yield*
|
|
1624
|
+
yield* ka(e.not, !1);
|
|
1610
1625
|
return;
|
|
1611
1626
|
}
|
|
1612
1627
|
if ("and" in e) {
|
|
1613
|
-
for (let n of e.and) yield*
|
|
1628
|
+
for (let n of e.and) yield* ka(n, t);
|
|
1614
1629
|
return;
|
|
1615
1630
|
}
|
|
1616
1631
|
if ("or" in e) {
|
|
1617
|
-
for (let t of e.or) yield*
|
|
1632
|
+
for (let t of e.or) yield* ka(t, !1);
|
|
1618
1633
|
return;
|
|
1619
1634
|
}
|
|
1620
1635
|
e.op !== "subquery-in" && e.op !== "subquery-not-in" && e.op !== "exists" && e.op !== "not-exists" && (yield {
|
|
1621
1636
|
...e,
|
|
1622
1637
|
conjunctive: t
|
|
1623
1638
|
});
|
|
1624
|
-
},
|
|
1639
|
+
}, Aa = (e, t) => ({
|
|
1625
1640
|
...t,
|
|
1626
1641
|
...e,
|
|
1627
1642
|
origin: e.origin ?? "injected"
|
|
1628
|
-
}),
|
|
1643
|
+
}), ja = (e, t, n = {}) => ({
|
|
1629
1644
|
table: e,
|
|
1630
1645
|
op: "insert",
|
|
1631
1646
|
old: null,
|
|
1632
1647
|
new: t,
|
|
1633
1648
|
...n
|
|
1634
|
-
}),
|
|
1649
|
+
}), Ma = (e, t, n, r = {}) => ({
|
|
1635
1650
|
table: e,
|
|
1636
1651
|
op: "update",
|
|
1637
1652
|
old: t,
|
|
1638
1653
|
new: n,
|
|
1639
1654
|
...r
|
|
1640
|
-
}),
|
|
1655
|
+
}), Na = (e, t, n = {}) => ({
|
|
1641
1656
|
table: e,
|
|
1642
1657
|
op: "delete",
|
|
1643
1658
|
old: t,
|
|
1644
1659
|
new: null,
|
|
1645
1660
|
...n
|
|
1646
|
-
}),
|
|
1661
|
+
}), Pa = (e, t, n = {}) => {
|
|
1647
1662
|
let { at: r = "2026-01-01T00:00:00.000Z", column: i = "deletedAt", ...a } = n;
|
|
1648
1663
|
return {
|
|
1649
1664
|
table: e,
|
|
@@ -1658,13 +1673,13 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
1658
1673
|
},
|
|
1659
1674
|
...a
|
|
1660
1675
|
};
|
|
1661
|
-
},
|
|
1676
|
+
}, Fa = (e) => e == null ? "null" : e instanceof Date ? JSON.stringify(e.toISOString()) : typeof e == "bigint" ? JSON.stringify(e.toString()) : Array.isArray(e) ? `[${e.map(Fa).join(",")}]` : typeof e == "object" ? `{${Object.entries(e).filter(([, e]) => e !== void 0).sort(([e], [t]) => e < t ? -1 : +(e > t)).map(([e, t]) => `${JSON.stringify(e)}:${Fa(t)}`).join(",")}}` : JSON.stringify(e) ?? "null", Ia = (e) => Lt("sha256").update([
|
|
1662
1677
|
e.pipe,
|
|
1663
1678
|
e.op,
|
|
1664
1679
|
e.key,
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
].join("\0")).digest("hex").slice(0, 32),
|
|
1680
|
+
Fa(e.next),
|
|
1681
|
+
Fa(e.prev)
|
|
1682
|
+
].join("\0")).digest("hex").slice(0, 32), La = (e, t) => `${e}:${t}`, Ra = (e) => {
|
|
1668
1683
|
let t = e.lastIndexOf(":");
|
|
1669
1684
|
if (t <= 0) return null;
|
|
1670
1685
|
let n = Number(e.slice(t + 1));
|
|
@@ -1672,7 +1687,7 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
1672
1687
|
digest: e.slice(0, t),
|
|
1673
1688
|
occurrence: n
|
|
1674
1689
|
};
|
|
1675
|
-
},
|
|
1690
|
+
}, za = class {
|
|
1676
1691
|
#e = /* @__PURE__ */ new Map();
|
|
1677
1692
|
#t;
|
|
1678
1693
|
#n;
|
|
@@ -1694,7 +1709,7 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
1694
1709
|
}
|
|
1695
1710
|
seedFromChangeKeys(e, t) {
|
|
1696
1711
|
for (let n of e) {
|
|
1697
|
-
let e =
|
|
1712
|
+
let e = Ra(n);
|
|
1698
1713
|
if (e === null) continue;
|
|
1699
1714
|
let r = this.#e.get(e.digest), i = Math.max(r?.count ?? 0, e.occurrence + 1);
|
|
1700
1715
|
this.#e.set(e.digest, {
|
|
@@ -1715,70 +1730,70 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
1715
1730
|
this.#e.delete(e.value);
|
|
1716
1731
|
}
|
|
1717
1732
|
}
|
|
1718
|
-
},
|
|
1719
|
-
let t = Number(e[
|
|
1733
|
+
}, Ba = "VOLTRO_CHANGE_CLAIMS_TTL_HOURS", Va = 1, Ha = (e = process.env) => {
|
|
1734
|
+
let t = Number(e[Ba]);
|
|
1720
1735
|
return (Number.isFinite(t) && t > 0 ? t : 1) * 2 * 36e5;
|
|
1721
|
-
},
|
|
1722
|
-
let t = e ??
|
|
1736
|
+
}, Ua = new Rt(), Wa = (e, t) => Ua.run(e, t), Ga = () => Ua.getStore(), Ka = (e) => {
|
|
1737
|
+
let t = e ?? Ua.getStore();
|
|
1723
1738
|
return t === void 0 ? {} : {
|
|
1724
1739
|
...t.traceId === void 0 ? {} : { traceId: t.traceId },
|
|
1725
1740
|
...t.subjectId === void 0 ? {} : { subjectId: t.subjectId },
|
|
1726
1741
|
...t.procedure === void 0 ? {} : { procedure: t.procedure },
|
|
1727
1742
|
...t.via === void 0 ? {} : { via: t.via }
|
|
1728
1743
|
};
|
|
1729
|
-
},
|
|
1730
|
-
let t =
|
|
1731
|
-
return t === void 0 ? e(void 0) :
|
|
1732
|
-
},
|
|
1733
|
-
for (let [t, n] of
|
|
1734
|
-
let r = n.filter((t) => e - t.at <
|
|
1735
|
-
|
|
1736
|
-
}
|
|
1737
|
-
},
|
|
1744
|
+
}, qa = (e) => {
|
|
1745
|
+
let t = Ua.getStore();
|
|
1746
|
+
return t === void 0 ? e(void 0) : Ua.run(t, () => e(t));
|
|
1747
|
+
}, Ja = 3e4, Ya = 1e4, G = /* @__PURE__ */ new Map(), K = 0, Xa = (e, t, n) => `${e}\u0000${t}\u0000${String(n)}`, Za = (e) => {
|
|
1748
|
+
for (let [t, n] of G) {
|
|
1749
|
+
let r = n.filter((t) => e - t.at < Ja);
|
|
1750
|
+
K -= n.length - r.length, r.length === 0 ? G.delete(t) : r.length !== n.length && G.set(t, r);
|
|
1751
|
+
}
|
|
1752
|
+
}, Qa = (e, t) => {
|
|
1738
1753
|
if (t.traceId === void 0 && t.subjectId === void 0 && t.procedure === void 0) return;
|
|
1739
1754
|
let n = Date.now();
|
|
1740
|
-
if (
|
|
1741
|
-
let r =
|
|
1742
|
-
r === void 0 ?
|
|
1755
|
+
if (K >= Ya && Za(n), K >= Ya) return;
|
|
1756
|
+
let r = G.get(e);
|
|
1757
|
+
r === void 0 ? G.set(e, [{
|
|
1743
1758
|
attribution: t,
|
|
1744
1759
|
at: n
|
|
1745
1760
|
}]) : r.push({
|
|
1746
1761
|
attribution: t,
|
|
1747
1762
|
at: n
|
|
1748
|
-
}),
|
|
1749
|
-
},
|
|
1750
|
-
let t =
|
|
1763
|
+
}), K += 1;
|
|
1764
|
+
}, $a = (e) => {
|
|
1765
|
+
let t = G.get(e);
|
|
1751
1766
|
if (t === void 0 || t.length === 0) return;
|
|
1752
1767
|
let n = t.shift();
|
|
1753
|
-
if (--
|
|
1754
|
-
},
|
|
1755
|
-
let t =
|
|
1768
|
+
if (--K, t.length === 0 && G.delete(e), !(Date.now() - n.at >= Ja)) return n.attribution;
|
|
1769
|
+
}, eo = (e) => (G.get(e)?.length ?? 0) > 0, q = /* @__PURE__ */ new Map(), to = /* @__PURE__ */ new Map(), no = /* @__PURE__ */ new Map(), ro = 250, io = (e) => {
|
|
1770
|
+
let t = to.get(e);
|
|
1756
1771
|
if (t === void 0) return;
|
|
1757
|
-
|
|
1758
|
-
let n =
|
|
1759
|
-
n !== void 0 && (clearTimeout(n),
|
|
1772
|
+
to.delete(e);
|
|
1773
|
+
let n = no.get(e);
|
|
1774
|
+
n !== void 0 && (clearTimeout(n), no.delete(e));
|
|
1760
1775
|
for (let e of t) e();
|
|
1761
|
-
},
|
|
1762
|
-
|
|
1763
|
-
},
|
|
1764
|
-
let t = (
|
|
1776
|
+
}, ao = (e) => {
|
|
1777
|
+
q.set(e, (q.get(e) ?? 0) + 1);
|
|
1778
|
+
}, oo = (e) => {
|
|
1779
|
+
let t = (q.get(e) ?? 0) - 1;
|
|
1765
1780
|
if (t > 0) {
|
|
1766
|
-
|
|
1781
|
+
q.set(e, t);
|
|
1767
1782
|
return;
|
|
1768
1783
|
}
|
|
1769
|
-
|
|
1770
|
-
},
|
|
1771
|
-
let i = n == null ? void 0 :
|
|
1784
|
+
q.delete(e), io(e);
|
|
1785
|
+
}, so = (e, t, n, r) => {
|
|
1786
|
+
let i = n == null ? void 0 : Xa(e, t, n), a = () => r(i === void 0 ? void 0 : $a(i));
|
|
1772
1787
|
if (i === void 0) {
|
|
1773
1788
|
a();
|
|
1774
1789
|
return;
|
|
1775
1790
|
}
|
|
1776
|
-
if (
|
|
1791
|
+
if (eo(i)) {
|
|
1777
1792
|
a();
|
|
1778
1793
|
return;
|
|
1779
1794
|
}
|
|
1780
|
-
let o =
|
|
1781
|
-
if (o === void 0 && (
|
|
1795
|
+
let o = to.get(e);
|
|
1796
|
+
if (o === void 0 && (q.get(e) ?? 0) === 0) {
|
|
1782
1797
|
a();
|
|
1783
1798
|
return;
|
|
1784
1799
|
}
|
|
@@ -1786,91 +1801,91 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
1786
1801
|
o.push(a);
|
|
1787
1802
|
return;
|
|
1788
1803
|
}
|
|
1789
|
-
|
|
1790
|
-
let s = setTimeout(() =>
|
|
1791
|
-
typeof s == "object" && typeof s.unref == "function" && s.unref(),
|
|
1792
|
-
},
|
|
1793
|
-
|
|
1794
|
-
for (let e of
|
|
1795
|
-
|
|
1796
|
-
},
|
|
1797
|
-
|
|
1804
|
+
to.set(e, [a]);
|
|
1805
|
+
let s = setTimeout(() => io(e), ro);
|
|
1806
|
+
typeof s == "object" && typeof s.unref == "function" && s.unref(), no.set(e, s);
|
|
1807
|
+
}, co = () => {
|
|
1808
|
+
G.clear(), K = 0, q.clear();
|
|
1809
|
+
for (let e of no.values()) clearTimeout(e);
|
|
1810
|
+
no.clear(), to.clear();
|
|
1811
|
+
}, lo = () => K, uo = 64, fo = "\0", po = 32, mo = (e, ...t) => `${e}_${Lt("sha256").update(t.map(String).join(fo)).digest("hex").slice(0, po)}`, ho = (e) => e.length + 1 + po, J = /* @__PURE__ */ new Map(), go = (e, t) => {
|
|
1812
|
+
J.set(e, {
|
|
1798
1813
|
recorder: t.recorder,
|
|
1799
1814
|
tables: new Set(t.tables),
|
|
1800
1815
|
ownTables: new Set(t.ownTables)
|
|
1801
1816
|
});
|
|
1802
|
-
},
|
|
1803
|
-
|
|
1804
|
-
},
|
|
1805
|
-
let t =
|
|
1817
|
+
}, _o = (e) => {
|
|
1818
|
+
J.delete(e);
|
|
1819
|
+
}, vo = () => J.clear(), yo = new Rt(), bo = (e) => yo.run({ n: 1 }, e), xo = (e) => D.suspend(() => {
|
|
1820
|
+
let t = yo.getStore();
|
|
1806
1821
|
if (t !== void 0) return t.n += 1, D.ensuring(e, D.sync(() => {
|
|
1807
1822
|
--t.n;
|
|
1808
1823
|
}));
|
|
1809
1824
|
let n = { n: 1 };
|
|
1810
|
-
return
|
|
1825
|
+
return yo.enterWith(n), D.ensuring(e, D.sync(() => {
|
|
1811
1826
|
--n.n;
|
|
1812
1827
|
}));
|
|
1813
|
-
}),
|
|
1814
|
-
if (
|
|
1815
|
-
for (let t of
|
|
1828
|
+
}), So = () => (yo.getStore()?.n ?? 0) > 0, Co = (e) => {
|
|
1829
|
+
if (J.size === 0 || (yo.getStore()?.n ?? 0) > 0) return !1;
|
|
1830
|
+
for (let t of J.values()) if (!t.ownTables.has(e) && t.tables.has(e)) return !0;
|
|
1816
1831
|
return !1;
|
|
1817
|
-
},
|
|
1818
|
-
if (
|
|
1819
|
-
for (let [n, r] of
|
|
1832
|
+
}, wo = async (e, t) => {
|
|
1833
|
+
if (J.size !== 0) {
|
|
1834
|
+
for (let [n, r] of J.entries()) if (!r.ownTables.has(t.table) && r.tables.has(t.table)) try {
|
|
1820
1835
|
await r.recorder(e, t);
|
|
1821
1836
|
} catch (e) {
|
|
1822
1837
|
let r = gn(e);
|
|
1823
1838
|
throw r === void 0 ? e : Error(`write recorder '${n}' failed while recording a ${t.op} on '${t.table}': ${r}`, { cause: e });
|
|
1824
1839
|
}
|
|
1825
1840
|
}
|
|
1826
|
-
},
|
|
1841
|
+
}, To = Nt.exponential({
|
|
1827
1842
|
start: 5e-4,
|
|
1828
1843
|
factor: 2,
|
|
1829
1844
|
count: 16
|
|
1830
|
-
}),
|
|
1831
|
-
let n = `${e}\u0000${t}`, r =
|
|
1845
|
+
}), Eo = O.counter("voltro_db_queries_total", { description: "Database operations executed, by dialect and operation kind." }), Do = O.histogram("voltro_db_query_duration_seconds", To, "Database operation duration in seconds, by dialect and operation kind."), Oo = O.counter("voltro_db_errors_total", { description: "Database operations that threw, by dialect and operation kind." }), ko = O.gauge("voltro_db_operations_in_flight", { description: "Database operations currently executing, by dialect. An upper bound on connections the framework holds; NOT the driver pool's waiting count." }), Ao = O.counter("voltro_db_eager_fallback_total", { description: "Eager-load queries that degraded from the single-roundtrip JSON-agg path to the multi-query walker, by dialect and reason." }), jo = [], Mo = /* @__PURE__ */ new Map(), No = /* @__PURE__ */ new Map(), Po = /* @__PURE__ */ new Map(), Fo = (e, t) => {
|
|
1846
|
+
let n = `${e}\u0000${t}`, r = Mo.get(n);
|
|
1832
1847
|
if (r !== void 0) return r;
|
|
1833
1848
|
let i = (n) => O.tagged(O.tagged(n, "dialect", e), "op", t), a = {
|
|
1834
|
-
count: i(
|
|
1835
|
-
duration: i(
|
|
1836
|
-
errors: i(
|
|
1849
|
+
count: i(Eo),
|
|
1850
|
+
duration: i(Do),
|
|
1851
|
+
errors: i(Oo)
|
|
1837
1852
|
};
|
|
1838
|
-
return
|
|
1839
|
-
},
|
|
1840
|
-
|
|
1841
|
-
},
|
|
1842
|
-
let n = Math.max(0, (
|
|
1843
|
-
n === 0 ?
|
|
1844
|
-
let r =
|
|
1845
|
-
r === void 0 && (r = O.tagged(
|
|
1846
|
-
},
|
|
1847
|
-
let t =
|
|
1848
|
-
t.count.unsafeUpdate(1,
|
|
1849
|
-
},
|
|
1853
|
+
return Mo.set(n, a), a;
|
|
1854
|
+
}, Io = () => {
|
|
1855
|
+
Mo.clear(), No.clear(), Po.clear();
|
|
1856
|
+
}, Lo = () => Mo.size + No.size + Po.size, Ro = /* @__PURE__ */ new Map(), zo = (e, t) => {
|
|
1857
|
+
let n = Math.max(0, (Ro.get(e) ?? 0) + t);
|
|
1858
|
+
n === 0 ? Ro.delete(e) : Ro.set(e, n);
|
|
1859
|
+
let r = No.get(e);
|
|
1860
|
+
r === void 0 && (r = O.tagged(ko, "dialect", e), No.set(e, r)), r.unsafeUpdate(n, jo);
|
|
1861
|
+
}, Bo = (e) => Ro.get(e) ?? 0, Vo = (e) => {
|
|
1862
|
+
let t = Fo(String(e.dialect), e.op);
|
|
1863
|
+
t.count.unsafeUpdate(1, jo), t.duration.unsafeUpdate(e.durationMs / 1e3, jo), e.status === "error" && t.errors.unsafeUpdate(1, jo);
|
|
1864
|
+
}, Ho = async (e, t, n) => {
|
|
1850
1865
|
let r = performance.now(), i = String(e);
|
|
1851
|
-
|
|
1866
|
+
zo(i, 1);
|
|
1852
1867
|
let a = "ok";
|
|
1853
1868
|
try {
|
|
1854
1869
|
return await n();
|
|
1855
1870
|
} catch (e) {
|
|
1856
1871
|
throw a = "error", e;
|
|
1857
1872
|
} finally {
|
|
1858
|
-
|
|
1873
|
+
zo(i, -1), Vo({
|
|
1859
1874
|
dialect: e,
|
|
1860
1875
|
op: t,
|
|
1861
1876
|
durationMs: performance.now() - r,
|
|
1862
1877
|
status: a
|
|
1863
1878
|
});
|
|
1864
1879
|
}
|
|
1865
|
-
},
|
|
1880
|
+
}, Uo = 3e5, Wo = (e) => {
|
|
1866
1881
|
if (e == null || e === "") return;
|
|
1867
1882
|
let t = Number(e);
|
|
1868
1883
|
return Number.isFinite(t) && t >= 0 ? Math.floor(t) : void 0;
|
|
1869
|
-
},
|
|
1870
|
-
let n =
|
|
1884
|
+
}, Go = (e, t = process.env) => Wo(t.VOLTRO_DB_EAGER_FALLBACK_WARN_INTERVAL_MS) ?? Wo(e) ?? 3e5, Ko = (e, t = {}) => {
|
|
1885
|
+
let n = Go(t.warnIntervalMs), r = t.now ?? (() => Date.now()), i = /* @__PURE__ */ new Map();
|
|
1871
1886
|
return (t) => {
|
|
1872
|
-
let a = `${t.dialect} ${t.reason}`, o =
|
|
1873
|
-
o === void 0 && (o = O.tagged(O.tagged(
|
|
1887
|
+
let a = `${t.dialect} ${t.reason}`, o = Po.get(a);
|
|
1888
|
+
o === void 0 && (o = O.tagged(O.tagged(Ao, "dialect", String(t.dialect)), "reason", t.reason), Po.set(a, o)), o.unsafeUpdate(1, jo);
|
|
1874
1889
|
let s = `${t.table}\u0000${t.reason}`, c = i.get(s), l = c === void 0 || n > 0 && r() - c >= n, u = {
|
|
1875
1890
|
table: t.table,
|
|
1876
1891
|
dialect: String(t.dialect),
|
|
@@ -1884,10 +1899,10 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
1884
1899
|
}
|
|
1885
1900
|
i.set(s, r()), e.warn(t.reason === "execute-failed" ? "eager-load JSON-agg statement FAILED and was re-run on the multi-query walker — this query pays both paths on every call. Counted as voltro_db_eager_fallback_total{reason=\"execute-failed\"}." : "eager-load could not be compiled to a single JSON-agg roundtrip and is running on the multi-query walker — one round trip per relation level, on every call. Counted as voltro_db_eager_fallback_total{reason=\"not-compilable\"}.", u);
|
|
1886
1901
|
};
|
|
1887
|
-
},
|
|
1902
|
+
}, qo = (e) => {
|
|
1888
1903
|
if (Mt.isSuccess(e)) return e.value;
|
|
1889
1904
|
throw kt.squash(e.cause);
|
|
1890
|
-
},
|
|
1905
|
+
}, Jo = "10 millis", Yo = 3, Xo = async (e) => {
|
|
1891
1906
|
let t = 0, n = D.suspend(() => {
|
|
1892
1907
|
let n = ++t;
|
|
1893
1908
|
return e.withTransaction(D.flatMap(D.serviceOption(zt), (t) => {
|
|
@@ -1898,10 +1913,10 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
1898
1913
|
});
|
|
1899
1914
|
return e.prepare === void 0 ? i : D.flatMap(e.prepare(r), () => i);
|
|
1900
1915
|
})).pipe(D.catchAllDefect((t) => e.isRetryable(t) ? D.fail(t) : D.die(t)));
|
|
1901
|
-
}), r = Ft.exponential(
|
|
1902
|
-
return
|
|
1903
|
-
},
|
|
1904
|
-
let t =
|
|
1916
|
+
}), r = Ft.exponential(Jo).pipe(Ft.compose(Ft.recurs(Yo)), Ft.whileInput(e.isRetryable)), i = n.pipe(D.retry(r), D.withSpan(e.span.name, { attributes: { ...e.span.attributes } }));
|
|
1917
|
+
return Ho(e.dialect, "transaction", async () => qo(await e.runPromiseExit(e.wrapProgram === void 0 ? i : e.wrapProgram(i))));
|
|
1918
|
+
}, Zo = async (e) => {
|
|
1919
|
+
let t = Ga(), n = t === void 0 ? (e) => e() : (e) => Wa(t, e), r = await Xo({
|
|
1905
1920
|
...e,
|
|
1906
1921
|
body: (r) => {
|
|
1907
1922
|
let i = e.makeView(r, t);
|
|
@@ -1912,14 +1927,14 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
1912
1927
|
}
|
|
1913
1928
|
});
|
|
1914
1929
|
return r.view.commitEvents(), r.result;
|
|
1915
|
-
},
|
|
1930
|
+
}, Qo = class extends A.TaggedError()("VersionConflict", {
|
|
1916
1931
|
table: A.String,
|
|
1917
1932
|
id: A.String,
|
|
1918
1933
|
expected: A.Number,
|
|
1919
1934
|
actual: A.NullOr(A.Number)
|
|
1920
|
-
}) {},
|
|
1935
|
+
}) {}, $o = (e) => {
|
|
1921
1936
|
for (let [t, n] of Object.entries(e)) if (n?.definition?.versionColumn === !0) return t;
|
|
1922
|
-
},
|
|
1937
|
+
}, es = (e) => {
|
|
1923
1938
|
let { versionColumn: t, patch: n } = e;
|
|
1924
1939
|
if (t === void 0) return {
|
|
1925
1940
|
nextVersion: void 0,
|
|
@@ -1932,28 +1947,28 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
1932
1947
|
expected: i,
|
|
1933
1948
|
patch: a
|
|
1934
1949
|
};
|
|
1935
|
-
},
|
|
1936
|
-
if (e.expected !== void 0 && (e.current === null || e.current !== e.expected)) return new
|
|
1950
|
+
}, ts = (e) => {
|
|
1951
|
+
if (e.expected !== void 0 && (e.current === null || e.current !== e.expected)) return new Qo({
|
|
1937
1952
|
table: e.table,
|
|
1938
1953
|
id: e.id,
|
|
1939
1954
|
expected: e.expected,
|
|
1940
1955
|
actual: e.current
|
|
1941
1956
|
});
|
|
1942
|
-
},
|
|
1943
|
-
id:
|
|
1957
|
+
}, ns = 1, rs = "voltro/expires", is = () => it({
|
|
1958
|
+
id: rs,
|
|
1944
1959
|
fields: { expiresAt: C().nullable() },
|
|
1945
1960
|
behaviors: { defaultWhere: () => "expiresAt IS NULL OR expiresAt > now()" }
|
|
1946
|
-
}),
|
|
1947
|
-
id:
|
|
1961
|
+
}), as = "voltro/localFirst", os = () => it({
|
|
1962
|
+
id: as,
|
|
1948
1963
|
fields: {}
|
|
1949
|
-
}),
|
|
1964
|
+
}), ss = (e) => e.appliedMixins.some((e) => e.id === as), cs = (e) => {
|
|
1950
1965
|
let t = [];
|
|
1951
|
-
for (let n of Object.values(e))
|
|
1966
|
+
for (let n of Object.values(e)) ss(n) && t.push(n.tableName);
|
|
1952
1967
|
return t;
|
|
1953
|
-
},
|
|
1968
|
+
}, ls = class extends jt.TaggedError("TableStreamError") {}, us = 1e3, ds = (e, t, n, r) => {
|
|
1954
1969
|
let i = k.match(r, {
|
|
1955
1970
|
onNone: () => e.where,
|
|
1956
|
-
onSome: (n) => e.where ?
|
|
1971
|
+
onSome: (n) => e.where ? ga(e.where, ta(t, n)) : ta(t, n)
|
|
1957
1972
|
});
|
|
1958
1973
|
return {
|
|
1959
1974
|
table: e.table,
|
|
@@ -1968,19 +1983,19 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
1968
1983
|
...e.includeDeleted === void 0 ? {} : { includeDeleted: e.includeDeleted },
|
|
1969
1984
|
...e.crossTenant === void 0 ? {} : { crossTenant: e.crossTenant }
|
|
1970
1985
|
};
|
|
1971
|
-
},
|
|
1972
|
-
let n = t.pk ?? "id", r = t.chunkSize ??
|
|
1986
|
+
}, fs = (e, t) => {
|
|
1987
|
+
let n = t.pk ?? "id", r = t.chunkSize ?? us;
|
|
1973
1988
|
return It.paginateChunkEffect(k.none(), (i) => {
|
|
1974
1989
|
let a = D.tryPromise({
|
|
1975
|
-
try: () => e.query(
|
|
1976
|
-
catch: (e) => new
|
|
1990
|
+
try: () => e.query(ds(t, n, r, i)),
|
|
1991
|
+
catch: (e) => new ls({
|
|
1977
1992
|
table: t.table,
|
|
1978
1993
|
cause: e
|
|
1979
1994
|
})
|
|
1980
1995
|
});
|
|
1981
1996
|
return (t.retry ? a.pipe(D.retry(t.retry)) : a).pipe(D.map((e) => [At.fromIterable(e), e.length === r && e.length > 0 ? k.some(k.some(e[e.length - 1][n])) : k.none()]));
|
|
1982
1997
|
});
|
|
1983
|
-
},
|
|
1998
|
+
}, ps = (e) => {
|
|
1984
1999
|
let t = e.alpha ?? .5;
|
|
1985
2000
|
if (t < 0 || t > 1) throw Error(`hybridSearch: alpha must be in [0, 1], got ${t}`);
|
|
1986
2001
|
return (n) => {
|
|
@@ -2007,14 +2022,14 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
2007
2022
|
}
|
|
2008
2023
|
};
|
|
2009
2024
|
};
|
|
2010
|
-
},
|
|
2025
|
+
}, ms = async (e, t) => {
|
|
2011
2026
|
let n = e.as ?? "embedding", r = t.row[e.from];
|
|
2012
2027
|
if (typeof r != "string" || r.length === 0) return {};
|
|
2013
2028
|
let i = await t.embed(r);
|
|
2014
2029
|
return { [n]: i };
|
|
2015
|
-
},
|
|
2030
|
+
}, hs = (e) => {
|
|
2016
2031
|
if (!Number.isInteger(e.dimensions) || e.dimensions <= 0) throw Error(`vectorEmbedding: dimensions must be a positive integer, got ${String(e.dimensions)}.`);
|
|
2017
|
-
let t = e.as ?? "embedding", n = (t) =>
|
|
2032
|
+
let t = e.as ?? "embedding", n = (t) => ms(e, t);
|
|
2018
2033
|
return it({
|
|
2019
2034
|
id: "voltro/vectorEmbedding",
|
|
2020
2035
|
fields: { [t]: pt(e.dimensions) },
|
|
@@ -2032,19 +2047,19 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
2032
2047
|
beforeUpdate: n
|
|
2033
2048
|
}
|
|
2034
2049
|
});
|
|
2035
|
-
},
|
|
2050
|
+
}, gs = 63, _s = "br_pr", Y = class extends Error {
|
|
2036
2051
|
_tag = "BranchNameInvalid";
|
|
2037
2052
|
constructor(e) {
|
|
2038
2053
|
super(e), this.name = "BranchNameInvalid";
|
|
2039
2054
|
}
|
|
2040
|
-
},
|
|
2041
|
-
if (!Number.isInteger(t) || t < 0) throw new
|
|
2042
|
-
let n =
|
|
2043
|
-
if (n.replace(/_/g, "") === "") throw new
|
|
2044
|
-
let r = `${
|
|
2045
|
-
if (r.length >
|
|
2055
|
+
}, vs = (e, t) => {
|
|
2056
|
+
if (!Number.isInteger(t) || t < 0) throw new Y(`prNumber must be a non-negative integer, got ${String(t)}`);
|
|
2057
|
+
let n = kr(e);
|
|
2058
|
+
if (n.replace(/_/g, "") === "") throw new Y(`app slug '${e}' has no usable identifier characters`);
|
|
2059
|
+
let r = `${_s}${t}_${n}`;
|
|
2060
|
+
if (r.length > gs) throw new Y(`branch namespace '${r}' exceeds the ${gs}-byte identifier limit — use a shorter app slug`);
|
|
2046
2061
|
return r;
|
|
2047
|
-
},
|
|
2062
|
+
}, ys = (e) => e.startsWith(_s), bs = {
|
|
2048
2063
|
requested: {
|
|
2049
2064
|
provision: "provisioning",
|
|
2050
2065
|
destroy: "destroying"
|
|
@@ -2063,19 +2078,19 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
2063
2078
|
fail: "failed"
|
|
2064
2079
|
},
|
|
2065
2080
|
destroyed: {}
|
|
2066
|
-
},
|
|
2081
|
+
}, xs = class extends Error {
|
|
2067
2082
|
from;
|
|
2068
2083
|
event;
|
|
2069
2084
|
_tag = "BranchTransitionInvalid";
|
|
2070
2085
|
constructor(e, t) {
|
|
2071
2086
|
super(`invalid branch transition: ${e} --${t}-->`), this.from = e, this.event = t, this.name = "BranchTransitionInvalid";
|
|
2072
2087
|
}
|
|
2073
|
-
},
|
|
2074
|
-
let n =
|
|
2075
|
-
if (n === void 0) throw new
|
|
2088
|
+
}, Ss = (e, t) => {
|
|
2089
|
+
let n = bs[e][t];
|
|
2090
|
+
if (n === void 0) throw new xs(e, t);
|
|
2076
2091
|
return n;
|
|
2077
|
-
},
|
|
2078
|
-
if (n === "copy" && (r === void 0 || r === "")) throw new
|
|
2092
|
+
}, Cs = (e, t, n, r, i = [], a = []) => {
|
|
2093
|
+
if (n === "copy" && (r === void 0 || r === "")) throw new Y("seed 'copy' requires a parentNamespace to snapshot from");
|
|
2079
2094
|
let o = [{
|
|
2080
2095
|
kind: "create-namespace",
|
|
2081
2096
|
detail: e
|
|
@@ -2104,13 +2119,13 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
2104
2119
|
kind: "seed",
|
|
2105
2120
|
detail: `run boot seeds into ${e}`
|
|
2106
2121
|
}), o;
|
|
2107
|
-
},
|
|
2108
|
-
if (!
|
|
2122
|
+
}, ws = (e) => {
|
|
2123
|
+
if (!ys(e)) throw new Y(`refusing to plan teardown of '${e}' — not a branch namespace`);
|
|
2109
2124
|
return [{
|
|
2110
2125
|
kind: "drop-namespace",
|
|
2111
2126
|
detail: e
|
|
2112
2127
|
}];
|
|
2113
|
-
},
|
|
2128
|
+
}, Ts = (e) => {
|
|
2114
2129
|
if (e === void 0 || e === "") return !1;
|
|
2115
2130
|
try {
|
|
2116
2131
|
let t = new URL(e).hostname.toLowerCase();
|
|
@@ -2118,27 +2133,27 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
2118
2133
|
} catch {
|
|
2119
2134
|
return /\bneon\.(tech|build)\b/i.test(e);
|
|
2120
2135
|
}
|
|
2121
|
-
},
|
|
2136
|
+
}, Es = (e) => e.prefer === void 0 ? e.seed === "copy" && Ts(e.dbUrl) ? "neon-cow" : "namespace" : e.prefer, Ds = (e, t = {}) => [{
|
|
2122
2137
|
kind: "neon-branch-create",
|
|
2123
2138
|
detail: `${t.parentBranch ?? "main"} → ${e} (copy-on-write)`
|
|
2124
|
-
}],
|
|
2125
|
-
if (!
|
|
2139
|
+
}], Os = (e) => {
|
|
2140
|
+
if (!ys(e)) throw new Y(`refusing to plan teardown of '${e}' — not a branch namespace`);
|
|
2126
2141
|
return [{
|
|
2127
2142
|
kind: "neon-branch-delete",
|
|
2128
2143
|
detail: e
|
|
2129
2144
|
}];
|
|
2130
|
-
},
|
|
2145
|
+
}, ks = (e) => e.mechanism === "neon-cow" ? Ds(e.branchId, e.neonParentBranch === void 0 ? {} : { parentBranch: e.neonParentBranch }) : Cs(e.branchId, e.tableNames, e.seed, e.parentNamespace, e.foreignKeys, e.indexNames), As = (e, t) => e === "neon-cow" ? Os(t) : ws(t), js = (e, t, n) => {
|
|
2131
2146
|
let r = e.filter((e) => e.state !== "destroyed" && e.state !== "destroying"), i = r.filter((e) => n - e.createdAtMs > t.ttlMs).map((e) => e.namespace), a = new Set(i);
|
|
2132
2147
|
return {
|
|
2133
2148
|
evict: i,
|
|
2134
2149
|
rejectNew: r.filter((e) => !a.has(e.namespace)).length >= t.maxBranches
|
|
2135
2150
|
};
|
|
2136
|
-
},
|
|
2137
|
-
let n =
|
|
2151
|
+
}, Ms = async (e, t) => {
|
|
2152
|
+
let n = vs(e.appSlug, e.prNumber), r = Es({
|
|
2138
2153
|
seed: e.seed,
|
|
2139
2154
|
...e.dbUrl === void 0 ? {} : { dbUrl: e.dbUrl },
|
|
2140
2155
|
...e.prefer === void 0 ? {} : { prefer: e.prefer }
|
|
2141
|
-
}), i =
|
|
2156
|
+
}), i = ks({
|
|
2142
2157
|
mechanism: r,
|
|
2143
2158
|
branchId: n,
|
|
2144
2159
|
tableNames: e.tableNames,
|
|
@@ -2167,16 +2182,16 @@ var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = async (e, t, n
|
|
|
2167
2182
|
mechanism: r,
|
|
2168
2183
|
steps: i
|
|
2169
2184
|
};
|
|
2170
|
-
},
|
|
2171
|
-
let r =
|
|
2185
|
+
}, Ns = async (e, t, n) => {
|
|
2186
|
+
let r = As(t, e);
|
|
2172
2187
|
return t === "neon-cow" ? await n.neonBranchDelete(e) : await n.dropNamespace(e), r;
|
|
2173
|
-
},
|
|
2188
|
+
}, Ps = (e, t, n) => js(e, t, n), X = (e) => `"${e.replace(/"/g, "\"\"")}"`, Fs = {
|
|
2174
2189
|
cascade: "CASCADE",
|
|
2175
2190
|
restrict: "RESTRICT",
|
|
2176
2191
|
setNull: "SET NULL",
|
|
2177
2192
|
noAction: "NO ACTION"
|
|
2178
|
-
},
|
|
2179
|
-
let n = t.columns.map(
|
|
2193
|
+
}, Z = (e) => `'${e.replace(/'/g, "''")}'`, Is = (e, t) => {
|
|
2194
|
+
let n = t.columns.map(Z).join(", ");
|
|
2180
2195
|
return `DO $voltro_branch$
|
|
2181
2196
|
DECLARE derived name;
|
|
2182
2197
|
BEGIN
|
|
@@ -2185,11 +2200,11 @@ BEGIN
|
|
|
2185
2200
|
JOIN pg_class i ON i.oid = x.indexrelid
|
|
2186
2201
|
JOIN pg_class c ON c.oid = x.indrelid
|
|
2187
2202
|
JOIN pg_namespace nsp ON nsp.oid = c.relnamespace
|
|
2188
|
-
WHERE nsp.nspname = ${
|
|
2189
|
-
AND c.relname = ${
|
|
2203
|
+
WHERE nsp.nspname = ${Z(e)}
|
|
2204
|
+
AND c.relname = ${Z(t.table)}
|
|
2190
2205
|
AND NOT x.indisprimary
|
|
2191
2206
|
AND x.indisunique = ${t.unique ? "true" : "false"}
|
|
2192
|
-
AND i.relname <> ${
|
|
2207
|
+
AND i.relname <> ${Z(t.name)}
|
|
2193
2208
|
AND (
|
|
2194
2209
|
SELECT array_agg(att.attname::text ORDER BY k.ord)
|
|
2195
2210
|
FROM unnest(x.indkey::int2[]) WITH ORDINALITY AS k(attnum, ord)
|
|
@@ -2198,39 +2213,39 @@ BEGIN
|
|
|
2198
2213
|
LIMIT 1;
|
|
2199
2214
|
IF derived IS NOT NULL THEN
|
|
2200
2215
|
EXECUTE format('ALTER INDEX %I.%I RENAME TO %I',
|
|
2201
|
-
${
|
|
2216
|
+
${Z(e)}, derived, ${Z(t.name)});
|
|
2202
2217
|
END IF;
|
|
2203
2218
|
END
|
|
2204
2219
|
$voltro_branch$`;
|
|
2205
|
-
},
|
|
2206
|
-
let n = t.onDelete === void 0 ? "" : ` ON DELETE ${
|
|
2207
|
-
return `ALTER TABLE ${
|
|
2208
|
-
},
|
|
2220
|
+
}, Ls = (e, t) => {
|
|
2221
|
+
let n = t.onDelete === void 0 ? "" : ` ON DELETE ${Fs[t.onDelete]}`, r = t.onUpdate === void 0 ? "" : ` ON UPDATE ${Fs[t.onUpdate]}`;
|
|
2222
|
+
return `ALTER TABLE ${X(e)}.${X(t.table)} ADD FOREIGN KEY (${X(t.column)}) REFERENCES ${X(e)}.${X(t.targetTable)} (${X(t.targetColumn)})${n}${r}`;
|
|
2223
|
+
}, Rs = (e) => {
|
|
2209
2224
|
let t = () => {
|
|
2210
2225
|
throw Error("namespace branch executor: Neon ops require a neon-cow executor (use a Neon connection for copy-on-write branches)");
|
|
2211
2226
|
};
|
|
2212
2227
|
return {
|
|
2213
|
-
createNamespace: (t) => e.run(`CREATE SCHEMA IF NOT EXISTS ${
|
|
2214
|
-
createTable: (t, n) => e.run(`CREATE TABLE IF NOT EXISTS ${
|
|
2215
|
-
copyTable: (t, n, r) => e.run(`INSERT INTO ${
|
|
2216
|
-
addForeignKey: (t, n) => e.run(
|
|
2217
|
-
restoreIndexName: (t, n) => e.run(
|
|
2218
|
-
dropNamespace: (t) => e.run(`DROP SCHEMA IF EXISTS ${
|
|
2228
|
+
createNamespace: (t) => e.run(`CREATE SCHEMA IF NOT EXISTS ${X(t)}`),
|
|
2229
|
+
createTable: (t, n) => e.run(`CREATE TABLE IF NOT EXISTS ${X(t)}.${X(n)} (LIKE ${X(n)} INCLUDING ALL)`),
|
|
2230
|
+
copyTable: (t, n, r) => e.run(`INSERT INTO ${X(n)}.${X(r)} SELECT * FROM ${X(t)}.${X(r)}`),
|
|
2231
|
+
addForeignKey: (t, n) => e.run(Ls(t, n)),
|
|
2232
|
+
restoreIndexName: (t, n) => e.run(Is(t, n)),
|
|
2233
|
+
dropNamespace: (t) => e.run(`DROP SCHEMA IF EXISTS ${X(t)} CASCADE`),
|
|
2219
2234
|
neonBranchCreate: t,
|
|
2220
2235
|
neonBranchDelete: t
|
|
2221
2236
|
};
|
|
2222
|
-
},
|
|
2237
|
+
}, zs = class extends Error {
|
|
2223
2238
|
_tag = "TenantResidencyUnresolved";
|
|
2224
2239
|
constructor(e) {
|
|
2225
2240
|
super(e), this.name = "TenantResidencyUnresolved";
|
|
2226
2241
|
}
|
|
2227
|
-
},
|
|
2242
|
+
}, Bs = class extends Error {
|
|
2228
2243
|
region;
|
|
2229
2244
|
_tag = "TenantRegionUnavailable";
|
|
2230
2245
|
constructor(e, t) {
|
|
2231
2246
|
super(t), this.region = e, this.name = "TenantRegionUnavailable";
|
|
2232
2247
|
}
|
|
2233
|
-
},
|
|
2248
|
+
}, Vs, Hs = (e) => {
|
|
2234
2249
|
if (e.homes === void 0) throw Error("setResidencyConfig: `homes` is required");
|
|
2235
2250
|
if (e.servableRegions === void 0 || e.servableRegions.length === 0) throw Error("setResidencyConfig: `servableRegions` must be non-empty (which regions this deployment serves)");
|
|
2236
2251
|
let t = /* @__PURE__ */ new Map();
|
|
@@ -2239,98 +2254,98 @@ $voltro_branch$`;
|
|
|
2239
2254
|
if (e !== void 0 && e !== n.region) throw Error(`residency: tenant '${n.tenantId}' is mapped to two regions ('${e}' and '${n.region}')`);
|
|
2240
2255
|
t.set(n.tenantId, n.region);
|
|
2241
2256
|
}
|
|
2242
|
-
return
|
|
2243
|
-
},
|
|
2244
|
-
|
|
2245
|
-
},
|
|
2246
|
-
if (e == null || e === "") throw new
|
|
2257
|
+
return Vs = e, e;
|
|
2258
|
+
}, Us = () => Vs, Ws = () => {
|
|
2259
|
+
Vs = void 0;
|
|
2260
|
+
}, Gs = (e, t) => {
|
|
2261
|
+
if (e == null || e === "") throw new zs("residency is on but the request has no resolvable tenant — refusing to bind a store");
|
|
2247
2262
|
let n = t.homes.find((t) => t.tenantId === e);
|
|
2248
|
-
if (n === void 0) throw new
|
|
2263
|
+
if (n === void 0) throw new zs(`no residency home is mapped for tenant '${e}' — refusing to fall back to a default store (would be a residency violation)`);
|
|
2249
2264
|
return n;
|
|
2250
|
-
},
|
|
2251
|
-
let n =
|
|
2265
|
+
}, Ks = (e, t) => t.servableRegions.includes(e), qs = (e, t) => {
|
|
2266
|
+
let n = Gs(e.tenantId, t), r = Ar(n.tenantId);
|
|
2252
2267
|
return {
|
|
2253
2268
|
region: n.region,
|
|
2254
2269
|
namespace: r,
|
|
2255
2270
|
...n.connectionKey === void 0 ? {} : { connectionKey: n.connectionKey }
|
|
2256
2271
|
};
|
|
2257
|
-
},
|
|
2258
|
-
let r =
|
|
2259
|
-
if (!
|
|
2272
|
+
}, Js = (e, t, n) => {
|
|
2273
|
+
let r = qs(e, t);
|
|
2274
|
+
if (!Ks(r.region, t)) throw new Bs(r.region, `tenant homed in region '${r.region}', which this deployment does not serve — route to the home region`);
|
|
2260
2275
|
let i = n.get(r.region);
|
|
2261
|
-
if (i === void 0) throw new
|
|
2276
|
+
if (i === void 0) throw new Bs(r.region, `no store handle for home region '${r.region}' (declared servable but not wired) — failing closed`);
|
|
2262
2277
|
return {
|
|
2263
2278
|
store: i,
|
|
2264
2279
|
placement: r
|
|
2265
2280
|
};
|
|
2266
|
-
},
|
|
2267
|
-
let { store: i, placement: a } =
|
|
2281
|
+
}, Ys = async (e, t, n, r) => {
|
|
2282
|
+
let { store: i, placement: a } = Js(e, t, n);
|
|
2268
2283
|
return await r(i, a), a;
|
|
2269
|
-
},
|
|
2284
|
+
}, Xs = (e) => {
|
|
2270
2285
|
if (typeof e == "string") return e;
|
|
2271
2286
|
if ("jsonPath" in e) {
|
|
2272
2287
|
let { column: t, path: n, numeric: r } = e.jsonPath;
|
|
2273
2288
|
return `(json:${t}->${n.join(".")}${r ? "::num" : ""})`;
|
|
2274
2289
|
}
|
|
2275
2290
|
return `(${e.expr})`;
|
|
2276
|
-
},
|
|
2291
|
+
}, Q = (e) => e.map(Xs), Zs = (e, t) => {
|
|
2277
2292
|
if (e.length !== t.length) return !1;
|
|
2278
|
-
for (let n = 0; n < e.length; n++) if (
|
|
2293
|
+
for (let n = 0; n < e.length; n++) if (Xs(e[n]) !== Xs(t[n])) return !1;
|
|
2279
2294
|
return !0;
|
|
2280
|
-
},
|
|
2295
|
+
}, Qs = (e, t) => {
|
|
2281
2296
|
if (e.length >= t.length) return !1;
|
|
2282
|
-
for (let n = 0; n < e.length; n++) if (
|
|
2297
|
+
for (let n = 0; n < e.length; n++) if (Xs(e[n]) !== Xs(t[n])) return !1;
|
|
2283
2298
|
return !0;
|
|
2284
|
-
},
|
|
2299
|
+
}, $s = (e) => {
|
|
2285
2300
|
let t = [], n = e.appliedIndexes, r = e.tableName;
|
|
2286
2301
|
for (let e = 0; e < n.length; e++) {
|
|
2287
2302
|
let i = n[e];
|
|
2288
2303
|
for (let a = e + 1; a < n.length; a++) {
|
|
2289
2304
|
let e = n[a];
|
|
2290
|
-
if (
|
|
2305
|
+
if (Zs(i.fields, e.fields)) {
|
|
2291
2306
|
let [n, a] = i.name < e.name ? [i, e] : [e, i];
|
|
2292
2307
|
t.push({
|
|
2293
2308
|
kind: "duplicate-fields",
|
|
2294
2309
|
table: r,
|
|
2295
2310
|
redundant: n,
|
|
2296
2311
|
coveredBy: a,
|
|
2297
|
-
message: `'${r}' has two indexes on the same fields [${
|
|
2312
|
+
message: `'${r}' has two indexes on the same fields [${Q(i.fields).join(", ")}]: '${i.name}' and '${e.name}'. The B-tree engine builds both, costing write throughput + disk space for no read benefit. Drop '${n.name}' (or '${a.name}' if you prefer the other name). Applies to every supported dialect (Postgres / MySQL / MariaDB / MSSQL / SQLite).`
|
|
2298
2313
|
});
|
|
2299
2314
|
continue;
|
|
2300
2315
|
}
|
|
2301
|
-
|
|
2316
|
+
Qs(i.fields, e.fields) ? t.push({
|
|
2302
2317
|
kind: "redundant-prefix",
|
|
2303
2318
|
table: r,
|
|
2304
2319
|
redundant: i,
|
|
2305
2320
|
coveredBy: e,
|
|
2306
|
-
message: `'${r}' index '${i.name}' on [${
|
|
2307
|
-
}) :
|
|
2321
|
+
message: `'${r}' index '${i.name}' on [${Q(i.fields).join(", ")}] is a leading prefix of '${e.name}' on [${Q(e.fields).join(", ")}]. Every B-tree dialect we support (Postgres / MySQL / MariaDB / MSSQL / SQLite) can serve a [${Q(i.fields).join(", ")}] query from '${e.name}' too via the leading-prefix rule, so '${i.name}' adds write cost without read benefit. Drop '${i.name}' — unless you specifically need a smaller index for cache locality on a write-heavy table (rare; profile first).`
|
|
2322
|
+
}) : Qs(e.fields, i.fields) && t.push({
|
|
2308
2323
|
kind: "redundant-prefix",
|
|
2309
2324
|
table: r,
|
|
2310
2325
|
redundant: e,
|
|
2311
2326
|
coveredBy: i,
|
|
2312
|
-
message: `'${r}' index '${e.name}' on [${
|
|
2327
|
+
message: `'${r}' index '${e.name}' on [${Q(e.fields).join(", ")}] is a leading prefix of '${i.name}' on [${Q(i.fields).join(", ")}]. Every B-tree dialect we support (Postgres / MySQL / MariaDB / MSSQL / SQLite) can serve a [${Q(e.fields).join(", ")}] query from '${i.name}' too via the leading-prefix rule, so '${e.name}' adds write cost without read benefit. Drop '${e.name}' — unless you specifically need a smaller index for cache locality on a write-heavy table (rare; profile first).`
|
|
2313
2328
|
});
|
|
2314
2329
|
}
|
|
2315
2330
|
}
|
|
2316
2331
|
return t;
|
|
2317
|
-
},
|
|
2332
|
+
}, ec = (e) => {
|
|
2318
2333
|
let t = [];
|
|
2319
|
-
for (let n of e) t.push(
|
|
2334
|
+
for (let n of e) t.push(...$s(n));
|
|
2320
2335
|
return t;
|
|
2321
|
-
},
|
|
2322
|
-
let n = t.color ?? !0, r = t.indent ?? " ", i = (e) =>
|
|
2336
|
+
}, tc = "\x1B[", nc = `${tc}38;2;245;158;11m`, rc = `${tc}38;2;16;185;129m`, ic = (e, t) => `${e}${t}${j.reset}`, $ = (e, t, n) => e ? typeof t == "function" ? t(n) : ic(t, n) : n, ac = (e, t = {}) => {
|
|
2337
|
+
let n = t.color ?? !0, r = t.indent ?? " ", i = (e) => $(n, j.dim, e.padEnd(11)), a = (e) => $(n, (e) => j.bold(j.brand(e)), e), o = (e) => $(n, j.brightRed24, e), s = (e) => $(n, rc, e), c = (e) => $(n, nc, e), l = (e) => $(n, j.dim, e), u = `${c("index audit")} ${l("·")} ${$(n, j.bold, e.kind)}`, d = e.redundant.fields.length, f = Q(e.coveredBy.fields.slice(d)), p = (e, t) => {
|
|
2323
2338
|
let n = e.slice(0, t), r = e.slice(t), i = [];
|
|
2324
2339
|
return n.length > 0 && i.push(s(`[${n.join(", ")}]`)), r.length > 0 && i.push(c(`+ [${r.join(", ")}]`)), i.join(" ");
|
|
2325
2340
|
}, m = [];
|
|
2326
|
-
return m.push(u), m.push(""), m.push(`${i("table")}${a(e.table)}`), m.push(""), m.push(`${i("redundant")}${o(e.redundant.name)}`), m.push(`${i("")}${p(
|
|
2327
|
-
},
|
|
2341
|
+
return m.push(u), m.push(""), m.push(`${i("table")}${a(e.table)}`), m.push(""), m.push(`${i("redundant")}${o(e.redundant.name)}`), m.push(`${i("")}${p(Q(e.redundant.fields), d)}`), m.push(""), m.push(`${i("covered by")}${s(e.coveredBy.name)}`), m.push(`${i("")}${p(Q(e.coveredBy.fields), d)}`), f.length > 0 && m.push(`${i("")}${l(`└ extra columns: ${f.join(", ")}`)}`), m.push(""), e.kind === "redundant-prefix" ? (m.push(`${i("why")}B-tree indexes serve queries that filter on a LEADING PREFIX of`), m.push(`${i("")}their column list. The wider index already covers every`), m.push(`${i("")}query the narrower one can serve.`), m.push(`${i("")}${l("Same rule on Postgres / MySQL / MariaDB / MSSQL / SQLite.")}`)) : (m.push(`${i("why")}Two indexes on the same columns under different names.`), m.push(`${i("")}The B-tree engine builds both — same coverage, double cost.`), m.push(`${i("")}${l("Same rule on Postgres / MySQL / MariaDB / MSSQL / SQLite.")}`)), m.push(""), m.push(`${i("cost")}Every ${a("INSERT")} / ${a("UPDATE")} / ${a("DELETE")} on this table writes`), m.push(`${i("")}to ${$(n, j.bold, "both")} B-trees. Pure write overhead, zero read benefit.`), m.push(""), m.push(`${i("fix")}Drop ${o(e.redundant.name)}`), m.push(`${i("")}${l("Keep only if profiling shows the smaller index gives a")}`), m.push(`${i("")}${l("measurable cache-locality boost on a write-heavy hot path.")}`), m.push(`${i("")}${l("Silence with VOLTRO_INDEX_AUDIT=off if intentional.")}`), m.map((e) => `${r}${e}`).join("\n");
|
|
2342
|
+
}, oc = (e, { apply: t, undo: n }) => ({
|
|
2328
2343
|
name: e,
|
|
2329
2344
|
apply: t,
|
|
2330
2345
|
undo: n
|
|
2331
|
-
}),
|
|
2346
|
+
}), sc = (e) => {
|
|
2332
2347
|
if (!/^\d{14}_/.test(e.id)) throw Error(`migration "${e.id}": id must start with a 14-digit timestamp followed by "_" (convention: <YYYYMMDDHHMMSS>_<slug>)`);
|
|
2333
|
-
let t = e.steps({ step:
|
|
2348
|
+
let t = e.steps({ step: oc });
|
|
2334
2349
|
if (t.length === 0) throw Error(`migration "${e.id}": at least one step is required`);
|
|
2335
2350
|
return {
|
|
2336
2351
|
__migration: !0,
|
|
@@ -2338,7 +2353,7 @@ $voltro_branch$`;
|
|
|
2338
2353
|
name: e.name,
|
|
2339
2354
|
steps: t
|
|
2340
2355
|
};
|
|
2341
|
-
},
|
|
2356
|
+
}, cc = (e) => typeof e == "object" && !!e && "__migration" in e && e.__migration === !0, lc = T("_voltro_migrations", {
|
|
2342
2357
|
id: _({ prefix: "mig" }),
|
|
2343
2358
|
name: t(),
|
|
2344
2359
|
hash: t(),
|
|
@@ -2350,7 +2365,7 @@ $voltro_branch$`;
|
|
|
2350
2365
|
workflowRunId: t().nullable(),
|
|
2351
2366
|
createdAt: C().default("now"),
|
|
2352
2367
|
updatedAt: C().default("now").onUpdate("now")
|
|
2353
|
-
}).index(["status"]),
|
|
2368
|
+
}).index(["status"]), uc = T("_voltro_seeds", {
|
|
2354
2369
|
id: _({ prefix: "seed" }),
|
|
2355
2370
|
name: t(),
|
|
2356
2371
|
lifecycle: t(),
|
|
@@ -2366,7 +2381,7 @@ $voltro_branch$`;
|
|
|
2366
2381
|
workflowRunId: t().nullable(),
|
|
2367
2382
|
createdAt: C().default("now"),
|
|
2368
2383
|
updatedAt: C().default("now").onUpdate("now")
|
|
2369
|
-
}).index(["lifecycle"]).index(["nextRunAt"]),
|
|
2384
|
+
}).index(["lifecycle"]).index(["nextRunAt"]), dc = T("_voltro_migration_plans", {
|
|
2370
2385
|
id: _({ prefix: "plan" }),
|
|
2371
2386
|
fingerprint: t(),
|
|
2372
2387
|
liveFingerprint: t().nullable(),
|
|
@@ -2382,21 +2397,21 @@ $voltro_branch$`;
|
|
|
2382
2397
|
appliedAt: C().default("now"),
|
|
2383
2398
|
createdAt: C().default("now"),
|
|
2384
2399
|
updatedAt: C().default("now").onUpdate("now")
|
|
2385
|
-
}).index(["fingerprint"]).index(["environment"]),
|
|
2400
|
+
}).index(["fingerprint"]).index(["environment"]), fc = T("_voltro_idempotency", {
|
|
2386
2401
|
id: _({ prefix: "idem" }),
|
|
2387
2402
|
scope: t(),
|
|
2388
2403
|
key: t(),
|
|
2389
2404
|
status: t(),
|
|
2390
2405
|
response: h().nullable(),
|
|
2391
2406
|
createdAt: C().default("now")
|
|
2392
|
-
}).unique(["scope", "key"]).index(["createdAt"]),
|
|
2407
|
+
}).unique(["scope", "key"]).index(["createdAt"]), pc = T("_voltro_kv", {
|
|
2393
2408
|
id: _({ prefix: "kv" }),
|
|
2394
2409
|
key: t().unique(),
|
|
2395
2410
|
value: t().nullable(),
|
|
2396
2411
|
expiresAt: C().nullable(),
|
|
2397
2412
|
createdAt: C().default("now"),
|
|
2398
2413
|
updatedAt: C().default("now").onUpdate("now")
|
|
2399
|
-
}).index(["expiresAt"]),
|
|
2414
|
+
}).index(["expiresAt"]), mc = T("_voltro_api_keys", {
|
|
2400
2415
|
id: _({ prefix: "apikey" }),
|
|
2401
2416
|
tenantId: t().nullable(),
|
|
2402
2417
|
name: t(),
|
|
@@ -2411,7 +2426,7 @@ $voltro_branch$`;
|
|
|
2411
2426
|
onBehalfOf: t().nullable(),
|
|
2412
2427
|
metadata: h().nullable(),
|
|
2413
2428
|
createdAt: C().default("now")
|
|
2414
|
-
}).index("byApiKeyTenant", ["tenantId"]),
|
|
2429
|
+
}).index("byApiKeyTenant", ["tenantId"]), hc = T("_voltro_replica_observations", {
|
|
2415
2430
|
id: _({ prefix: "robs" }),
|
|
2416
2431
|
replicaId: t().maxLength(191),
|
|
2417
2432
|
startedAt: C(),
|
|
@@ -2420,11 +2435,11 @@ $voltro_branch$`;
|
|
|
2420
2435
|
payload: t().nullable(),
|
|
2421
2436
|
reachableAt: t().maxLength(255).nullable(),
|
|
2422
2437
|
writtenAt: C().default("now").onUpdate("now")
|
|
2423
|
-
}).unique(["replicaId", "kind"]).index(["kind"]),
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
],
|
|
2438
|
+
}).unique(["replicaId", "kind"]).index(["kind"]), gc = [
|
|
2439
|
+
lc,
|
|
2440
|
+
uc,
|
|
2441
|
+
dc
|
|
2442
|
+
], _c = "_voltro_replace_in_progress", vc = T(_c, {
|
|
2428
2443
|
id: _({ prefix: "repl" }),
|
|
2429
2444
|
startedAt: C().default("now"),
|
|
2430
2445
|
kind: t().default("replace"),
|
|
@@ -2434,10 +2449,10 @@ $voltro_branch$`;
|
|
|
2434
2449
|
staging: t().nullable(),
|
|
2435
2450
|
heartbeatAt: C().nullable(),
|
|
2436
2451
|
resumable: r().nullable()
|
|
2437
|
-
}),
|
|
2452
|
+
}), yc = 30, bc = (e, t) => {
|
|
2438
2453
|
let n = typeof t == "number" && Number.isFinite(t) && t > 0 ? t : 30, r = Number(e.VOLTRO_STAGING_STALE_MINUTES);
|
|
2439
2454
|
return (Number.isFinite(r) && r > 0 ? r : n) * 6e4;
|
|
2440
|
-
},
|
|
2455
|
+
}, xc = (e) => e == null || String(e).length === 0 ? [] : String(e).split(",").map((e) => e.trim()).filter((e) => e.length > 0), Sc = (e) => {
|
|
2441
2456
|
let t = e.filter((e) => e.kind !== "staging");
|
|
2442
2457
|
if (t.length !== 0) return `refusing to start: a destructive data operation did not finish.
|
|
2443
2458
|
${t.map((e) => {
|
|
@@ -2452,7 +2467,7 @@ ${t.map((e) => {
|
|
|
2452
2467
|
|
|
2453
2468
|
When the data is back, or you have decided the current state is correct, clear the marker:
|
|
2454
2469
|
voltro data clear-replace-marker --yes`;
|
|
2455
|
-
},
|
|
2470
|
+
}, Cc = (e, t, n) => {
|
|
2456
2471
|
let r = e.filter((e) => e.kind === "staging");
|
|
2457
2472
|
return {
|
|
2458
2473
|
all: r,
|
|
@@ -2462,7 +2477,7 @@ ${t.map((e) => {
|
|
|
2462
2477
|
return Number.isFinite(r) ? t - r >= n : !1;
|
|
2463
2478
|
})
|
|
2464
2479
|
};
|
|
2465
|
-
},
|
|
2480
|
+
}, wc = (e, t) => {
|
|
2466
2481
|
if (e.all.length === 0) return;
|
|
2467
2482
|
let n = new Set(e.droppable.map((e) => e.id));
|
|
2468
2483
|
return `staged data-import leftovers:
|
|
@@ -2471,22 +2486,22 @@ ${e.all.map((e) => {
|
|
|
2471
2486
|
return n.has(e.id) ? ` - ${a} — DROPPED: the run is not resumable and has been silent long enough that nothing is loading into them.` : e.resumable ? ` - ${a} — KEPT: the run was started \`--no-atomic\`, so these ARE its resume point. Re-run the same\n bundle to continue from them, or drop them with: voltro data clear-staging --yes` : ` - ${a} — KEPT: still beating, so an import is loading into them right now.`;
|
|
2472
2487
|
}).join("\n")}\n The target of a staged \`replace\` is untouched until one short swap at the end, so none of this is
|
|
2473
2488
|
a reason to refuse the boot — it is a reason to know the disk is holding a copy of a bundle.`;
|
|
2474
|
-
},
|
|
2489
|
+
}, Tc = "id", Ec = (e, t) => {
|
|
2475
2490
|
let n = E(e);
|
|
2476
2491
|
if (n === void 0) return t;
|
|
2477
|
-
let r = n.fields[
|
|
2478
|
-
if (r === void 0 || t[
|
|
2492
|
+
let r = n.fields[Tc]?.idScheme;
|
|
2493
|
+
if (r === void 0 || t[Tc] != null) return t;
|
|
2479
2494
|
if (r.kind === "numeric") {
|
|
2480
|
-
if (!(
|
|
2495
|
+
if (!(Tc in t)) return t;
|
|
2481
2496
|
let e = { ...t };
|
|
2482
|
-
return delete e[
|
|
2497
|
+
return delete e[Tc], e;
|
|
2483
2498
|
}
|
|
2484
2499
|
let i = gt(r, e);
|
|
2485
2500
|
return i === null ? t : {
|
|
2486
2501
|
...t,
|
|
2487
|
-
[
|
|
2502
|
+
[Tc]: i
|
|
2488
2503
|
};
|
|
2489
|
-
},
|
|
2504
|
+
}, Dc = (e, t) => t.map((t) => Ec(e, t)), Oc = {
|
|
2490
2505
|
postgres: { maxBindParameters: 65535 },
|
|
2491
2506
|
mysql: { maxBindParameters: 65535 },
|
|
2492
2507
|
mariadb: { maxBindParameters: 65535 },
|
|
@@ -2496,25 +2511,25 @@ ${e.all.map((e) => {
|
|
|
2496
2511
|
},
|
|
2497
2512
|
sqlite: { maxBindParameters: 32766 },
|
|
2498
2513
|
turso: { maxBindParameters: 32766 }
|
|
2499
|
-
},
|
|
2514
|
+
}, kc = (e) => Oc[e], Ac = (e) => {
|
|
2500
2515
|
let t = /* @__PURE__ */ new Set();
|
|
2501
2516
|
for (let n of e) for (let e of Object.keys(n)) t.add(e);
|
|
2502
2517
|
return t.size;
|
|
2503
|
-
},
|
|
2518
|
+
}, jc = (e, t) => {
|
|
2504
2519
|
if (t === void 0 || e.length === 0) return [e];
|
|
2505
|
-
let n = Math.max(1,
|
|
2520
|
+
let n = Math.max(1, Ac(e)), r = Math.floor(t.maxBindParameters / n), i = t.maxRowsPerStatement ?? Infinity, a = Math.max(1, Math.min(r, i));
|
|
2506
2521
|
if (e.length <= a) return [e];
|
|
2507
2522
|
let o = [];
|
|
2508
2523
|
for (let t = 0; t < e.length; t += a) o.push(e.slice(t, t + a));
|
|
2509
2524
|
return o;
|
|
2510
|
-
},
|
|
2525
|
+
}, Mc = (e, t) => {
|
|
2511
2526
|
let n = [], r = t;
|
|
2512
2527
|
for (let [t, i] of Object.entries(e.fields)) {
|
|
2513
2528
|
let e = i;
|
|
2514
2529
|
e.nullable || e.hasDefault || e.idScheme !== void 0 || e.generatedAs !== void 0 || (r[t] === void 0 || r[t] === null) && n.push(t);
|
|
2515
2530
|
}
|
|
2516
2531
|
return n;
|
|
2517
|
-
},
|
|
2532
|
+
}, Nc = (e, t, n) => {
|
|
2518
2533
|
let r = n, i = new Set(e === void 0 ? [] : Object.entries(e.fields).filter(([, e]) => e.generatedAs !== void 0).map(([e]) => e)), a = [];
|
|
2519
2534
|
for (let e of t) i.has(e) || (r[e] === void 0 ? a.push({
|
|
2520
2535
|
column: e,
|
|
@@ -2524,28 +2539,28 @@ ${e.all.map((e) => {
|
|
|
2524
2539
|
reason: "null"
|
|
2525
2540
|
}));
|
|
2526
2541
|
return a;
|
|
2527
|
-
},
|
|
2542
|
+
}, Pc = (e, t, n) => e.insert(t.tableName, n), Fc = (e, t, n, r) => e.upsert(t.tableName, n, {
|
|
2528
2543
|
conflictColumns: r.conflictColumns,
|
|
2529
2544
|
...r.update === void 0 ? {} : { update: r.update }
|
|
2530
|
-
}),
|
|
2545
|
+
}), Ic = (e, t, n, r) => e.updateMany(t.tableName, n, { where: r.where }), Lc = 512, Rc = (e) => {
|
|
2531
2546
|
e.setMaxListeners(512);
|
|
2532
|
-
},
|
|
2547
|
+
}, zc = (e, t, n) => ({
|
|
2533
2548
|
_tag: "PrimaryKeyConflictError",
|
|
2534
2549
|
table: e,
|
|
2535
2550
|
key: t,
|
|
2536
2551
|
cause: n
|
|
2537
|
-
}),
|
|
2552
|
+
}), Bc = (e) => typeof e == "object" && !!e && e._tag === "PrimaryKeyConflictError", Vc = {
|
|
2538
2553
|
postgres: 5432,
|
|
2539
2554
|
mysql: 3306,
|
|
2540
2555
|
mariadb: 3306,
|
|
2541
2556
|
mssql: 1433
|
|
2542
|
-
},
|
|
2557
|
+
}, Hc = /* @__PURE__ */ new Set([
|
|
2543
2558
|
"localhost",
|
|
2544
2559
|
"127.0.0.1",
|
|
2545
2560
|
"::1",
|
|
2546
2561
|
"[::1]",
|
|
2547
2562
|
"0.0.0.0"
|
|
2548
|
-
]),
|
|
2563
|
+
]), Uc = (e) => {
|
|
2549
2564
|
let t = e.host, n = e.port, r = e.database;
|
|
2550
2565
|
if (e.url !== void 0 && e.url !== "") try {
|
|
2551
2566
|
let i = new URL(e.url);
|
|
@@ -2554,29 +2569,29 @@ ${e.all.map((e) => {
|
|
|
2554
2569
|
return;
|
|
2555
2570
|
}
|
|
2556
2571
|
if (t === void 0 || t === "" || r === void 0 || r === "") return;
|
|
2557
|
-
let i = n ??
|
|
2572
|
+
let i = n ?? Vc[(e.dialect ?? "").toLowerCase()];
|
|
2558
2573
|
if (i === void 0 || !Number.isFinite(i)) return;
|
|
2559
2574
|
let a = t.toLowerCase();
|
|
2560
2575
|
return {
|
|
2561
|
-
host:
|
|
2576
|
+
host: Hc.has(a) ? "localhost" : a,
|
|
2562
2577
|
port: i,
|
|
2563
2578
|
database: r.toLowerCase()
|
|
2564
2579
|
};
|
|
2565
|
-
},
|
|
2566
|
-
let t =
|
|
2580
|
+
}, Wc = (e) => {
|
|
2581
|
+
let t = Uc(e);
|
|
2567
2582
|
if (t !== void 0) return Lt("sha256").update(`${t.host}\u0000${t.port}\u0000${t.database}`).digest("hex").slice(0, 32);
|
|
2568
|
-
},
|
|
2583
|
+
}, Gc = (e, t) => e === void 0 || t === void 0 ? "unknown" : e === t ? "same" : "different", Kc = {
|
|
2569
2584
|
app: 3,
|
|
2570
2585
|
plugin: 2,
|
|
2571
2586
|
framework: 1
|
|
2572
|
-
},
|
|
2587
|
+
}, qc = /* @__PURE__ */ new Map(), Jc = [], Yc = () => [...Jc], Xc = (e) => {
|
|
2573
2588
|
if (!e.table || !e.timeColumn) throw Error("registerRetention: table + timeColumn are required");
|
|
2574
2589
|
if (!Number.isFinite(e.ttlMs) || e.ttlMs <= 0) throw Error(`registerRetention(${e.table}): ttlMs must be a positive number`);
|
|
2575
|
-
let t = e.source ?? "app", n =
|
|
2590
|
+
let t = e.source ?? "app", n = qc.get(e.table);
|
|
2576
2591
|
if (n !== void 0) {
|
|
2577
2592
|
let r = n.source ?? "app", i = n.ttlMs !== e.ttlMs || n.where !== void 0 != (e.where !== void 0);
|
|
2578
|
-
if (
|
|
2579
|
-
i &&
|
|
2593
|
+
if (Kc[t] < Kc[r]) {
|
|
2594
|
+
i && Jc.push({
|
|
2580
2595
|
table: e.table,
|
|
2581
2596
|
kept: {
|
|
2582
2597
|
source: r,
|
|
@@ -2589,7 +2604,7 @@ ${e.all.map((e) => {
|
|
|
2589
2604
|
});
|
|
2590
2605
|
return;
|
|
2591
2606
|
}
|
|
2592
|
-
i && r !== t &&
|
|
2607
|
+
i && r !== t && Jc.push({
|
|
2593
2608
|
table: e.table,
|
|
2594
2609
|
kept: {
|
|
2595
2610
|
source: t,
|
|
@@ -2601,36 +2616,36 @@ ${e.all.map((e) => {
|
|
|
2601
2616
|
}
|
|
2602
2617
|
});
|
|
2603
2618
|
}
|
|
2604
|
-
|
|
2619
|
+
qc.set(e.table, {
|
|
2605
2620
|
...e,
|
|
2606
2621
|
source: t
|
|
2607
2622
|
});
|
|
2608
|
-
},
|
|
2609
|
-
|
|
2610
|
-
},
|
|
2623
|
+
}, Zc = () => [...qc.values()], Qc = () => {
|
|
2624
|
+
qc.clear(), Jc.length = 0;
|
|
2625
|
+
}, $c = async (e, t, n, r = 2e4) => {
|
|
2611
2626
|
let i = new Date(t - e.ttlMs), a = 0;
|
|
2612
2627
|
for (;;) {
|
|
2613
2628
|
let t = await n(e.table, e.timeColumn, i, r, e.where);
|
|
2614
2629
|
if (a += t, t < r) break;
|
|
2615
2630
|
}
|
|
2616
2631
|
return a;
|
|
2617
|
-
},
|
|
2632
|
+
}, el = (e, t) => {
|
|
2618
2633
|
let n = Number(e ?? String(t));
|
|
2619
2634
|
return (Number.isFinite(n) && n > 0 ? n : t) * 36e5;
|
|
2620
|
-
},
|
|
2635
|
+
}, tl = "_voltro_cdc_offsets", nl = T(tl, {
|
|
2621
2636
|
id: _({ prefix: "cdcoff" }),
|
|
2622
2637
|
replicaId: t(),
|
|
2623
2638
|
streamName: t(),
|
|
2624
2639
|
binlogFile: t(),
|
|
2625
2640
|
binlogPosition: t(),
|
|
2626
2641
|
updatedAt: C()
|
|
2627
|
-
}).index(["replicaId"]),
|
|
2642
|
+
}).index(["replicaId"]), rl = T(tl, {
|
|
2628
2643
|
id: _({ prefix: "cdcoff" }),
|
|
2629
2644
|
replicaId: t(),
|
|
2630
2645
|
streamName: t(),
|
|
2631
2646
|
ctVersion: t(),
|
|
2632
2647
|
updatedAt: C()
|
|
2633
|
-
}).index(["replicaId"]),
|
|
2648
|
+
}).index(["replicaId"]), il = "_voltro_data_transfers", al = T(il, {
|
|
2634
2649
|
id: _({ prefix: "dimp" }),
|
|
2635
2650
|
startedAt: C().default("now"),
|
|
2636
2651
|
finishedAt: C().nullable(),
|
|
@@ -2643,9 +2658,9 @@ ${e.all.map((e) => {
|
|
|
2643
2658
|
rowsWritten: S().default(0),
|
|
2644
2659
|
failure: t().nullable(),
|
|
2645
2660
|
staged: r().nullable()
|
|
2646
|
-
}).renamedFrom("_voltro_data_imports").nonReactive(),
|
|
2661
|
+
}).renamedFrom("_voltro_data_imports").nonReactive(), ol = (e) => {
|
|
2647
2662
|
let t = Number.isFinite(e.startedAt.getTime()) ? e.startedAt.toISOString() : "an unknown time", n = e.direction === "import" ? e.mode : `${e.direction} ${e.mode}`, r = e.failure === null ? e.finishedAt === null ? `${n} — started and never reported finishing` : e.direction === "backup" || e.direction === "restore" ? `${n} — finished${e.rowsWritten > 0 ? ` (${e.rowsWritten} blob(s))` : ""}` : `${n} — ${e.rowsWritten} row(s) across ${e.tablesWritten} table(s)` : `FAILED ${n} — ${e.failure}`, i = e.staged === null ? "" : e.staged ? " · staged (target untouched until the swap)" : " · NOT staged (target emptied first)";
|
|
2648
2663
|
return `${t} · ${r} · via ${e.via}${i}` + (e.bundle === null ? "" : ` · from ${e.bundle}`) + (e.sourceFingerprint === null ? "" : ` · source schema ${e.sourceFingerprint}`);
|
|
2649
|
-
},
|
|
2664
|
+
}, sl = "postgres";
|
|
2650
2665
|
//#endregion
|
|
2651
|
-
export { nt as AUTO_FILLED_COLUMNS,
|
|
2666
|
+
export { nt as AUTO_FILLED_COLUMNS, Oc as BULK_INSERT_LIMITS, Y as BranchNameInvalid, xs as BranchTransitionInvalid, tl as CDC_OFFSETS_TABLE, Ba as CHANGE_CLAIM_TTL_ENV, Lc as CHANGE_LISTENER_CEILING, l as ColumnBuilder, il as DATA_TRANSFERS_TABLE, fe as DEFAULT_ACQUIRE_TIMEOUT_MS, Va as DEFAULT_CHANGE_CLAIM_TTL_HOURS, Uo as DEFAULT_EAGER_FALLBACK_WARN_INTERVAL_MS, Yn as DEFAULT_SUBJECT_GRAPH_DEPTH, qt as ENCRYPTED_PREFIX, sl as ENGINE, fr as EagerCardinalityError, rt as FILE_MIGRATION_PATTERN, ft as FRAMEWORK_LIVE_TABLES, Jt as FieldDecryptionError, uo as ID_COLUMN_MAX_LENGTH, ns as INITIAL_VERSION, fa as MATCHES_NO_ROWS, et as MAX_IDENTIFIER_LENGTH, za as OccurrenceCounter, _c as REPLACE_IN_PROGRESS_TABLE, yc as STAGING_STALE_MINUTES, tt as STAGING_TABLE_PREFIX, Bt as SqlClient, ls as TableStreamError, Er as TenantNamespaceInvalid, Tr as TenantNamespaceUnresolved, Bs as TenantRegionUnavailable, zs as TenantResidencyUnresolved, rs as VOLTRO_EXPIRES_MIXIN_ID, as as VOLTRO_LOCAL_FIRST_MIXIN_ID, Qo as VersionConflict, Ke as WARN_IDENTIFIER_LENGTH, mc as _voltroApiKeysTable, nl as _voltroCdcOffsetsTable, al as _voltroDataTransfersTable, fc as _voltroIdempotencyTable, pc as _voltroKvTable, dc as _voltroMigrationPlansTable, lc as _voltroMigrationsTable, rl as _voltroMssqlCdcOffsetsTable, vc as _voltroReplaceInProgressTable, hc as _voltroReplicaObservationsTable, uc as _voltroSeedsTable, Qi as actorsTable, Ps as admitBranch, St as allEnumRenames, Kn as allRegisteredRelations, Ce as allRegisteredTables, ga as and, le as array, la as arrayContains, da as arrayHas, ua as arrayOverlaps, mr as attachEagerLoads, Ka as attributionFields, Xa as attributionKey, ec as auditAllTableIndexes, $s as auditTableIndexes, Fe as avg, xt as avgOver, ao as beginLocalWrite, Xe as bigint, Js as bindResidentStore, r as boolean, vs as branchNamespaceName, kc as bulkInsertLimitsFor, Je as bytes, sn as causeBranches, Na as changeDelete, Ia as changeDigest, ja as changeInsert, Pa as changeSoftDelete, Ma as changeUpdate, jc as chunkRowsForInsert, $a as claimPendingAttribution, pn as classifyConstraintViolation, _e as clearEnumRenames, co as clearPendingAttribution, Jn as clearRelationsRegistry, Ws as clearResidencyConfig, Qc as clearRetentions, m as clearTableRegistry, vo as clearWriteRecorders, W as coercePredicateForSqlite, Pr as coercePredicateValue, Fr as coercePredicateValues, Wi as coerceValueForSqlite, Oa as collectSubqueries, ge as column, Sn as columnSchema, Ac as columnsPerRow, Jr as compileEagerJson, F as compilePredicate, Ir as compileRawFragment, I as compileSelect, La as composeChangeKey, ms as computeEmbedding, Wc as connectionIdentity, sa as contains, o as count, yt as countDistinct, oe as crdtDoc, se as crdtManagedColumns, de as crdtManagedColumnsOf, p as crdtText, Ga as currentWriteAttribution, ve as databaseHandle, te as date, ie as dbEnum, Lo as dbMetricTagCacheSizeForTests, Bo as dbOperationsInFlight, he as decimal, s as declareEnumRename, $t as decodeFieldValue, lr as decodeRowsFromSchema, an as decryptFieldsOnRead, sc as defineMigration, it as defineMixin, Ze as defineSeed, u as denseRank, nr as deriveSubjectGraph, Qe as deriveTypeIdPrefix, mo as derivedRowId, ho as derivedRowIdLength, gn as describeDriverError, _n as describeRowBindings, ol as describeTransferRun, Kt as deserializeArraysOnRead, Ge as drainIdentifierWarnings, Et as dropped, Zt as encodeFieldValue, dr as encodeRowForSchema, rn as encryptFieldsForWrite, nn as encryptedColumnsOf, oo as endLocalWrite, js as enforceBranchLimits, y as ensureTableRegistered, $i as eq, Lr as escapeLike, Da as evaluatePredicate, c as except, Ca as exists, is as expires, Aa as externalChangeEvent, un as extractDbCause, ht as fireSchemaChangeSeeds, ze as fireTenantCreateSeeds, ac as formatIndexAuditIssue, rr as formatSubjectGraph, gc as frameworkTables, gt as generateId, Ue as generateSnowflake, a as geography, Se as geometry, bt as getEnumRenames, Gn as getRelation, Wn as getRelations, Us as getResidencyConfig, E as getTable, ta as gt, na as gte, wr as hasEagerLoads, ps as hybridSearch, _ as id, aa as inSet, xa as inSubquery, Fn as inferForeignKey, Pc as insertRow, S as integer, Sc as interruptedReplaceRefusal, ce as intersect, we as interval, ys as isBranchNamespace, An as isEmptyRelationsSpec, Xt as isEncrypted, Yt as isFieldDecryptionError, ut as isFileMigration, mn as isForeignKeyViolation, ct as isFrameworkOwnedLiveTable, ss as isLocalFirst, cc as isMigrationDefinition, e as isMysqlFamily, Ts as isNeonConnection, ma as isNotNull, pa as isNull, Bc as isPrimaryKeyConflictError, hn as isQueryTimeout, en as isRawEncoding, Ks as isRegionServable, jn as isRelationsSpec, He as isSeedDefinition, Ve as isSqliteFamily, Ne as isStagingTableName, ne as isTableReactive, We as isView, h as json, ya as jsonField, lt as jsonIndex, Ye as lag, n as lead, Yc as listRetentionConflicts, Zc as listRetentions, os as localFirst, cs as localFirstTables, ra as lt, ia as lte, Ko as makeEagerFallbackReporter, Rs as makeNamespaceBranchExecutor, Nn as many, Pn as manyToMany, re as materializeFields, qe as max, Le as migration, ae as min, Nc as missingConflictColumns, Mc as missingRequiredColumns, dt as mixin, ea as neq, Ss as nextBranchState, Uc as normaliseTarget, va as not, wa as notExists, oa as notInSet, Sa as notInSubquery, st as numeric, Ho as observeDbOp, Ha as occurrenceWindowMs, Mn as one, pr as oneCardinalityMessage, _a as or, x as orderClausesOf, ue as paginateBy, f as paginateById, Ra as parseChangeKey, lo as pendingAttributionCount, ks as planBranch, Cs as planBranchProvision, ws as planBranchTeardown, As as planBranchTeardownFor, Ds as planNeonBranchProvision, Os as planNeonBranchTeardown, es as planVersionedUpdate, ye as pluginRef, d as pluginRefSpecOf, zc as primaryKeyConflictError, Ms as provisionBranch, Ys as provisionResidentTenant, jr as qualifyTable, ee as queryFor, je as queryForView, mt as quoteIdent, Rc as raiseChangeListenerCeiling, b as rank, v as raw, Oe as readableByColumns, Ee as real, Vo as recordDbOp, Co as recordsTable, Ae as reference, bn as refuseWrite, Ji as registerCoreTables, Un as registerDiscoveredRelations, Qa as registerPendingAttribution, Hn as registerRelations, Xc as registerRetention, De as registerTable, go as registerWriteRecorder, kn as relations, Xi as requireActors, Te as requireTable, Zi as requireTenants, Io as resetDbMetricTagCacheForTests, ot as resetSnowflake, qs as residentPlacement, Ht as resolveActorSnapshot, Es as resolveBranchMechanism, Go as resolveEagerFallbackWarnIntervalMs, so as resolveEchoAttribution, me as resolveFullTextIndex, Be as resolveIdScheme, Re as resolveMixinGraph, Gs as resolveTenantHome, Ar as resolveTenantNamespace, el as retentionTtlMsFromEnv, Tt as rowNumber, Cn as rowSchema, Xo as runRetryingTransaction, Zo as runStoreTransaction, Wa as runWithWriteAttribution, wo as runWriteRecorders, Gc as sameDatabase, kr as sanitizeIdentifierFragment, Gt as serializeArraysForWrite, pe as serverOnlyColumns, Hs as setResidencyConfig, at as setSchemaChangeSeedHook, $e as setTenantCreateSeedHook, qo as settleTransactionExit, ts as settleVersionedUpdate, ha as spatialPredicate, wc as stagingLeftoverReport, Cc as stagingLeftovers, xc as stagingNamesOf, bc as stagingStaleAfterMs, Ec as stampGeneratedId, Dc as stampGeneratedIds, ca as startsWith, xn as storeRefusalOf, fs as streamTable, i as sum, xe as sumOver, bo as suspendWriteRecorders, xo as suspendWriteRecordersEffect, $c as sweepRetention, T as table, Ns as teardownBranch, t as text, C as timestamp, Dt as timestampMs, Ot as timestampMsOrNull, g as union, be as unionAll, ke as unregisterTable, _o as unregisterWriteRecorder, Ic as updateManyRow, Fc as upsertRow, Me as validateColumnName, vt as validateIndexName, qn as validateRegisteredRelations, zn as validateRelationConfig, wt as validateTableName, Ie as validateTypeIdPrefix, pt as vector, Pe as vectorDistanceToOpclass, hs as vectorEmbedding, $o as versionColumnOf, _t as view, Ct as viewSql, ka as walkLeaves, qa as withCapturedAttribution, So as writeRecordersSuspended };
|