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