@voltro/database 0.44.0 → 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 +120 -1
- package/dist/index.d.ts +51 -0
- package/dist/index.js +629 -601
- 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 {
|
|
@@ -143,23 +143,40 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
143
143
|
let t = e;
|
|
144
144
|
for (let e = 0; e < 4 && At.isFiberFailure(t); e++) t = Tt.squash(t[At.FiberFailureCauseId]);
|
|
145
145
|
return t;
|
|
146
|
-
}, nn = (e) => {
|
|
146
|
+
}, nn = (e, t = 0) => {
|
|
147
|
+
if (t >= 4 || !At.isFiberFailure(e)) return [e];
|
|
148
|
+
let n = e[At.FiberFailureCauseId], r = [...Tt.failures(n), ...Tt.defects(n)];
|
|
149
|
+
if (r.length === 0) return [Tt.squash(n)];
|
|
150
|
+
let i = [];
|
|
151
|
+
for (let e of r.slice(0, 8)) i.push(...nn(e, t + 1));
|
|
152
|
+
return i;
|
|
153
|
+
}, rn = (e) => e.dbCode !== void 0 || e.dbErrno !== void 0 || e.dbNumber !== void 0 || e.dbSqlState !== void 0 || e.dbConstraint !== void 0, an = (e) => {
|
|
147
154
|
let t = {}, n = [], r = tn(e);
|
|
148
155
|
for (let e = 0; e < 8 && typeof r == "object" && r; e++) {
|
|
149
156
|
let e = r;
|
|
150
|
-
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);
|
|
151
158
|
let i = e.sqlMessage ?? e.detail;
|
|
152
159
|
t.dbMessage === void 0 && typeof i == "string" && (t.dbMessage = i);
|
|
153
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;
|
|
154
|
-
(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);
|
|
155
162
|
}
|
|
156
163
|
return n.length > 0 && (t.dbCauseChain = n.join(" ← "), t.dbMessage === void 0 && (t.dbMessage = n[n.length - 1])), t;
|
|
157
|
-
},
|
|
164
|
+
}, on = (e) => {
|
|
165
|
+
let t = nn(e).map(an);
|
|
166
|
+
if (t.length <= 1) return t[0] ?? {};
|
|
167
|
+
let n = t.find(rn) ?? t[0], r = t.filter((e) => e !== n).map((e) => e.dbCauseChain).filter((e) => typeof e == "string");
|
|
168
|
+
if (r.length === 0) return n;
|
|
169
|
+
let i = typeof n.dbCauseChain == "string" ? n.dbCauseChain : void 0;
|
|
170
|
+
return {
|
|
171
|
+
...n,
|
|
172
|
+
dbCauseChain: [i, ...r].filter(Boolean).join(" ‖ ")
|
|
173
|
+
};
|
|
174
|
+
}, sn = /^[A-Za-z_][A-Za-z0-9_$]*$/, j = (e) => e !== void 0 && e.length <= 128 && sn.test(e) ? e : void 0, cn = (e) => e === void 0 ? void 0 : e.split(".").pop() ?? e, M = (e, ...t) => {
|
|
158
175
|
for (let n of t) {
|
|
159
176
|
let t = n.exec(e);
|
|
160
177
|
if (t?.[1] !== void 0) return t[1];
|
|
161
178
|
}
|
|
162
|
-
},
|
|
179
|
+
}, ln = (e, t) => {
|
|
163
180
|
let n = e.dbCode, r = e.dbErrno, i = e.dbNumber, a = typeof e.dbMessage == "string" ? e.dbMessage : "", o = `${typeof e.dbCauseChain == "string" ? e.dbCauseChain : ""} ${a}`;
|
|
164
181
|
if (n === "23503") {
|
|
165
182
|
let t = j(e.dbConstraint);
|
|
@@ -197,7 +214,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
197
214
|
};
|
|
198
215
|
}
|
|
199
216
|
if (r === 1062) {
|
|
200
|
-
let e = j(
|
|
217
|
+
let e = j(cn(M(o, /for key '([^']+)'/)));
|
|
201
218
|
return {
|
|
202
219
|
kind: "unique",
|
|
203
220
|
...e === void 0 ? {} : { constraint: e }
|
|
@@ -248,14 +265,14 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
248
265
|
}
|
|
249
266
|
if (n === "SQLITE_CONSTRAINT_FOREIGNKEY") return { kind: t === "delete" || t === "deleteMany" || t === "hardDelete" ? "foreignKeyInUse" : "foreignKey" };
|
|
250
267
|
if (n === "SQLITE_CONSTRAINT_UNIQUE" || n === "SQLITE_CONSTRAINT_PRIMARYKEY") {
|
|
251
|
-
let e = j(
|
|
268
|
+
let e = j(cn(M(o, /UNIQUE constraint failed: ([^,\s]+)/)));
|
|
252
269
|
return {
|
|
253
270
|
kind: "unique",
|
|
254
271
|
...e === void 0 ? {} : { column: e }
|
|
255
272
|
};
|
|
256
273
|
}
|
|
257
274
|
if (n === "SQLITE_CONSTRAINT_NOTNULL") {
|
|
258
|
-
let e = j(
|
|
275
|
+
let e = j(cn(M(o, /NOT NULL constraint failed: ([^,\s]+)/)));
|
|
259
276
|
return {
|
|
260
277
|
kind: "notNull",
|
|
261
278
|
...e === void 0 ? {} : { column: e }
|
|
@@ -268,22 +285,33 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
268
285
|
...e === void 0 ? {} : { constraint: e }
|
|
269
286
|
};
|
|
270
287
|
}
|
|
271
|
-
},
|
|
272
|
-
let t =
|
|
288
|
+
}, un = (e) => {
|
|
289
|
+
let t = ln(e)?.kind;
|
|
273
290
|
return t === "foreignKey" || t === "foreignKeyInUse";
|
|
274
|
-
},
|
|
291
|
+
}, dn = (e) => {
|
|
275
292
|
let t = e.dbCode, n = e.dbErrno;
|
|
276
293
|
return t === "57014" || n === 3024 || n === 1969 || t === "ETIMEOUT" || t === "SQLITE_INTERRUPT";
|
|
277
|
-
},
|
|
278
|
-
let t =
|
|
294
|
+
}, fn = (e) => {
|
|
295
|
+
let t = on(e), n = [
|
|
279
296
|
t.dbCode === void 0 ? void 0 : `code=${String(t.dbCode)}`,
|
|
280
297
|
t.dbErrno === void 0 ? void 0 : `errno=${String(t.dbErrno)}`,
|
|
281
298
|
t.dbNumber === void 0 ? void 0 : `number=${String(t.dbNumber)}`,
|
|
282
299
|
t.dbSqlState === void 0 ? void 0 : `sqlState=${String(t.dbSqlState)}`,
|
|
283
|
-
t.dbConstraint === void 0 ? void 0 : `constraint=${String(t.dbConstraint)}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
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) => {
|
|
287
315
|
let t = (() => {
|
|
288
316
|
switch (e.type) {
|
|
289
317
|
case "id":
|
|
@@ -304,41 +332,41 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
304
332
|
}
|
|
305
333
|
})();
|
|
306
334
|
return e.nullable === !0 ? k.NullOr(t) : t;
|
|
307
|
-
},
|
|
335
|
+
}, gn = (e, t) => {
|
|
308
336
|
let n = new Set(t?.omit ?? []), r = {};
|
|
309
|
-
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));
|
|
310
338
|
return k.Struct(r);
|
|
311
|
-
},
|
|
339
|
+
}, _n = (e) => typeof e == "function" ? e : () => e, vn = (e, t) => ({
|
|
312
340
|
kind: "one",
|
|
313
|
-
target:
|
|
341
|
+
target: _n(e),
|
|
314
342
|
...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
|
|
315
343
|
...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
|
|
316
|
-
}),
|
|
344
|
+
}), yn = (e, t) => ({
|
|
317
345
|
kind: "many",
|
|
318
|
-
target:
|
|
346
|
+
target: _n(e),
|
|
319
347
|
...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
|
|
320
348
|
...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
|
|
321
|
-
}),
|
|
349
|
+
}), bn = (e, t) => ({
|
|
322
350
|
kind: "manyToMany",
|
|
323
|
-
target:
|
|
324
|
-
through:
|
|
351
|
+
target: _n(e),
|
|
352
|
+
through: _n(t.through),
|
|
325
353
|
sourceKey: t.sourceKey,
|
|
326
354
|
targetKey: t.targetKey
|
|
327
|
-
}),
|
|
328
|
-
one:
|
|
329
|
-
many:
|
|
330
|
-
manyToMany:
|
|
331
|
-
},
|
|
355
|
+
}), xn = {
|
|
356
|
+
one: vn,
|
|
357
|
+
many: yn,
|
|
358
|
+
manyToMany: bn
|
|
359
|
+
}, Sn = (e, t) => {
|
|
332
360
|
let n = typeof e == "function" ? e : () => e;
|
|
333
361
|
return {
|
|
334
362
|
source: n,
|
|
335
|
-
relations: t(
|
|
363
|
+
relations: t(xn, n())
|
|
336
364
|
};
|
|
337
|
-
},
|
|
365
|
+
}, Cn = (e) => {
|
|
338
366
|
if (typeof e != "object" || !e) return !1;
|
|
339
367
|
let t = e;
|
|
340
368
|
return typeof t.source != "function" || typeof t.relations != "object" || t.relations === null ? !1 : Object.keys(t.relations).length === 0;
|
|
341
|
-
},
|
|
369
|
+
}, wn = (e) => {
|
|
342
370
|
if (typeof e != "object" || !e) return !1;
|
|
343
371
|
let t = e;
|
|
344
372
|
if (typeof t.source != "function" || typeof t.relations != "object" || t.relations === null) return !1;
|
|
@@ -347,35 +375,35 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
347
375
|
let t = e?.kind;
|
|
348
376
|
return t === "one" || t === "many" || t === "manyToMany";
|
|
349
377
|
});
|
|
350
|
-
},
|
|
378
|
+
}, Tn = vn, En = yn, Dn = bn, N = (e, t, n) => {
|
|
351
379
|
let r = [];
|
|
352
380
|
for (let [n, i] of Object.entries(e.fields)) i.type === "reference" && i.references?.()?.tableName === t && r.push(n);
|
|
353
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>' }.`);
|
|
354
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.`);
|
|
355
383
|
return r[0];
|
|
356
|
-
},
|
|
357
|
-
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);
|
|
358
386
|
return t.length === 0 ? "<none>" : t.join(", ");
|
|
359
|
-
},
|
|
387
|
+
}, An = (e, t, n) => {
|
|
360
388
|
let r = `relation '${t}' on '${e.tableName}'`, i = n.target();
|
|
361
389
|
if (n.kind === "manyToMany") {
|
|
362
390
|
let t = n.through();
|
|
363
|
-
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)}.`);
|
|
364
392
|
return;
|
|
365
393
|
}
|
|
366
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.`);
|
|
367
|
-
if (n.sourceKey !== void 0 && !
|
|
368
|
-
let t =
|
|
369
|
-
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)}.`));
|
|
370
398
|
}
|
|
371
|
-
if (n.foreignKey !== void 0 && !
|
|
372
|
-
let t =
|
|
373
|
-
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)}.`));
|
|
374
402
|
}
|
|
375
|
-
},
|
|
376
|
-
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);
|
|
377
405
|
if (n === void 0) {
|
|
378
|
-
|
|
406
|
+
F.set(t.tableName, new Map(Object.entries(e.relations)));
|
|
379
407
|
return;
|
|
380
408
|
}
|
|
381
409
|
for (let [r, i] of Object.entries(e.relations)) {
|
|
@@ -385,33 +413,33 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
385
413
|
n.set(r, i);
|
|
386
414
|
}
|
|
387
415
|
}
|
|
388
|
-
},
|
|
416
|
+
}, Pn = (e) => {
|
|
389
417
|
let t = 0;
|
|
390
|
-
for (let n of Object.values(e))
|
|
418
|
+
for (let n of Object.values(e)) wn(n) && (Nn(n), t += 1);
|
|
391
419
|
return t;
|
|
392
|
-
},
|
|
393
|
-
let t =
|
|
420
|
+
}, Fn = (e) => {
|
|
421
|
+
let t = F.get(e);
|
|
394
422
|
if (t !== void 0) return Object.fromEntries(t);
|
|
395
|
-
},
|
|
423
|
+
}, In = (e, t) => F.get(e)?.get(t), Ln = () => {
|
|
396
424
|
let e = [];
|
|
397
|
-
for (let [t, n] of
|
|
425
|
+
for (let [t, n] of F) for (let [r, i] of n) e.push({
|
|
398
426
|
source: t,
|
|
399
427
|
name: r,
|
|
400
428
|
relation: i
|
|
401
429
|
});
|
|
402
430
|
return e;
|
|
403
|
-
},
|
|
404
|
-
for (let [e, t] of
|
|
431
|
+
}, Rn = () => {
|
|
432
|
+
for (let [e, t] of F) {
|
|
405
433
|
let n = p(e);
|
|
406
|
-
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);
|
|
407
435
|
}
|
|
408
|
-
},
|
|
409
|
-
|
|
410
|
-
},
|
|
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) => {
|
|
411
439
|
let n = [];
|
|
412
440
|
for (let [r, i] of Object.entries(e.fields)) i.type === "reference" && i.references?.()?.tableName === t && n.push(r);
|
|
413
441
|
return n;
|
|
414
|
-
},
|
|
442
|
+
}, Wn = (e, t) => {
|
|
415
443
|
let n = [];
|
|
416
444
|
for (let r of t) {
|
|
417
445
|
if (r.source !== e) continue;
|
|
@@ -428,7 +456,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
428
456
|
} catch {
|
|
429
457
|
continue;
|
|
430
458
|
}
|
|
431
|
-
if (!
|
|
459
|
+
if (!Hn(e, t.sourceKey)) continue;
|
|
432
460
|
n.push({
|
|
433
461
|
table: e.tableName,
|
|
434
462
|
foreignKey: t.sourceKey,
|
|
@@ -437,24 +465,24 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
437
465
|
continue;
|
|
438
466
|
}
|
|
439
467
|
if (t.sourceKey !== void 0) continue;
|
|
440
|
-
let a =
|
|
441
|
-
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({
|
|
442
470
|
table: i.tableName,
|
|
443
471
|
foreignKey: o,
|
|
444
472
|
parentKey: "id"
|
|
445
473
|
});
|
|
446
474
|
}
|
|
447
475
|
return n;
|
|
448
|
-
},
|
|
476
|
+
}, Gn = (e, t) => {
|
|
449
477
|
let n = [];
|
|
450
|
-
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({
|
|
451
479
|
table: r.tableName,
|
|
452
480
|
foreignKey: t,
|
|
453
481
|
parentKey: "id"
|
|
454
482
|
});
|
|
455
483
|
return n;
|
|
456
|
-
},
|
|
457
|
-
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 = [];
|
|
458
486
|
if (!a.has(e.subjectTable)) return {
|
|
459
487
|
subjectTable: e.subjectTable,
|
|
460
488
|
paths: [],
|
|
@@ -469,11 +497,11 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
469
497
|
hops: [],
|
|
470
498
|
depth: 0,
|
|
471
499
|
via: "relation"
|
|
472
|
-
}, c = [s], l = /* @__PURE__ */ new Set([
|
|
500
|
+
}, c = [s], l = /* @__PURE__ */ new Set([Kn(s)]), u = /* @__PURE__ */ new Set(), d = [s];
|
|
473
501
|
for (let e = 1; e <= r; e++) {
|
|
474
502
|
let r = [];
|
|
475
503
|
for (let a of d) {
|
|
476
|
-
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"])];
|
|
477
505
|
for (let [t, n] of f) {
|
|
478
506
|
if (i.has(t.table)) {
|
|
479
507
|
o.push({
|
|
@@ -491,7 +519,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
491
519
|
hops: [...a.hops, t],
|
|
492
520
|
depth: e,
|
|
493
521
|
via: n
|
|
494
|
-
}, f =
|
|
522
|
+
}, f = Kn(d);
|
|
495
523
|
l.has(f) || (l.add(f), c.push(d), r.push(d));
|
|
496
524
|
}
|
|
497
525
|
}
|
|
@@ -501,7 +529,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
501
529
|
}
|
|
502
530
|
d = r;
|
|
503
531
|
}
|
|
504
|
-
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({
|
|
505
533
|
kind: "depth-truncated",
|
|
506
534
|
table: e.table,
|
|
507
535
|
detail: `stopped at maxDepth ${r}; tables linked FROM '${e.table}' were not explored`
|
|
@@ -510,14 +538,14 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
510
538
|
for (let n of t) f.has(n.tableName) || i.has(n.tableName) || o.push({
|
|
511
539
|
kind: "unreachable",
|
|
512
540
|
table: n.tableName,
|
|
513
|
-
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(", ")}`
|
|
514
542
|
});
|
|
515
543
|
return {
|
|
516
544
|
subjectTable: e.subjectTable,
|
|
517
545
|
paths: c,
|
|
518
546
|
limitations: o
|
|
519
547
|
};
|
|
520
|
-
},
|
|
548
|
+
}, Jn = (e) => {
|
|
521
549
|
let t = [`subject graph · ${e.subjectTable} · ${e.paths.length} table(s) reachable`];
|
|
522
550
|
for (let n of e.paths) {
|
|
523
551
|
let r = n.hops.length === 0 ? `${e.subjectTable} (the subject row itself)` : [e.subjectTable, ...n.hops.map((e) => `${e.table}.${e.foreignKey}`)].join(" → ");
|
|
@@ -525,7 +553,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
525
553
|
}
|
|
526
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");
|
|
527
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");
|
|
528
|
-
},
|
|
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) => {
|
|
529
557
|
if (e == null || typeof e != "string") return e;
|
|
530
558
|
let t = e.trim();
|
|
531
559
|
if (t.length === 0) return e;
|
|
@@ -536,7 +564,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
536
564
|
} catch {
|
|
537
565
|
return e;
|
|
538
566
|
}
|
|
539
|
-
},
|
|
567
|
+
}, Zn = (e) => e == null || typeof e == "string" ? e : typeof e == "number" || typeof e == "bigint" ? String(e) : e, Qn = (e) => {
|
|
540
568
|
if (e == null || e instanceof Date) return e;
|
|
541
569
|
if (typeof e == "string") {
|
|
542
570
|
let t = new Date(e);
|
|
@@ -547,19 +575,19 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
547
575
|
return isNaN(t.getTime()) ? e : t;
|
|
548
576
|
}
|
|
549
577
|
return e;
|
|
550
|
-
},
|
|
578
|
+
}, $n = (e, t, n) => {
|
|
551
579
|
if (e == null) return e;
|
|
552
580
|
switch (t) {
|
|
553
|
-
case "boolean": return n === "postgres" ? e :
|
|
581
|
+
case "boolean": return n === "postgres" ? e : Yn(e);
|
|
554
582
|
case "json":
|
|
555
|
-
case "array": return n === "postgres" ? e :
|
|
583
|
+
case "array": return n === "postgres" ? e : Xn(e);
|
|
556
584
|
case "timestamp":
|
|
557
|
-
case "date": return n === "sqlite" || n === "turso" ?
|
|
585
|
+
case "date": return n === "sqlite" || n === "turso" ? Qn(e) : e;
|
|
558
586
|
case "decimal":
|
|
559
|
-
case "bigint": return
|
|
587
|
+
case "bigint": return Zn(e);
|
|
560
588
|
default: return e;
|
|
561
589
|
}
|
|
562
|
-
},
|
|
590
|
+
}, er = (e, t, n) => {
|
|
563
591
|
if (e.length === 0) return e;
|
|
564
592
|
let r = p(t);
|
|
565
593
|
if (r === void 0) return e;
|
|
@@ -570,36 +598,36 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
570
598
|
});
|
|
571
599
|
return e.map((e) => {
|
|
572
600
|
let t = { ...e };
|
|
573
|
-
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));
|
|
574
602
|
return t;
|
|
575
603
|
});
|
|
576
|
-
},
|
|
604
|
+
}, tr = (e, t) => {
|
|
577
605
|
if (e == null) return e;
|
|
578
606
|
switch (t) {
|
|
579
607
|
case "json":
|
|
580
608
|
case "array": return typeof e == "string" ? e : JSON.stringify(e);
|
|
581
609
|
default: return e;
|
|
582
610
|
}
|
|
583
|
-
},
|
|
611
|
+
}, nr = (e, t, n = ["json", "array"]) => {
|
|
584
612
|
let r = p(t);
|
|
585
613
|
if (r === void 0) return e;
|
|
586
614
|
let i = r.fields, a = null;
|
|
587
615
|
for (let [t, r] of Object.entries(i)) if (n.includes(r.type) && t in e) {
|
|
588
|
-
let n =
|
|
616
|
+
let n = tr(e[t], r.type);
|
|
589
617
|
n !== e[t] && (a === null && (a = { ...e }), a[t] = n);
|
|
590
618
|
}
|
|
591
619
|
return a ?? e;
|
|
592
|
-
},
|
|
620
|
+
}, rr = class extends Error {
|
|
593
621
|
_tag = "EagerCardinalityError";
|
|
594
622
|
constructor(e) {
|
|
595
623
|
super(e), this.name = "EagerCardinalityError";
|
|
596
624
|
}
|
|
597
|
-
},
|
|
625
|
+
}, ir = (e) => {
|
|
598
626
|
let { relationName: t, sourceTableName: n, targetTableName: r, foreignKey: i, sourceKey: a } = e, o = r === n;
|
|
599
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.");
|
|
600
|
-
},
|
|
628
|
+
}, ar = async (e, t, n, r) => {
|
|
601
629
|
if (e.length === 0) return e;
|
|
602
|
-
let i =
|
|
630
|
+
let i = Fn(n.tableName);
|
|
603
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?`);
|
|
604
632
|
let a = e.map((e) => ({ ...e }));
|
|
605
633
|
for (let [e, o] of Object.entries(t)) {
|
|
@@ -608,36 +636,36 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
608
636
|
let t = Object.keys(i).join(", ") || "<none>";
|
|
609
637
|
throw Error(`unknown relation '${e}' on '${n.tableName}'. Registered relations: ${t}.`);
|
|
610
638
|
}
|
|
611
|
-
|
|
639
|
+
An(n, e, t), await or(a, e, t, o === !0 ? {} : o, n, r);
|
|
612
640
|
}
|
|
613
641
|
return a;
|
|
614
|
-
},
|
|
642
|
+
}, or = async (e, t, n, r, i, a) => {
|
|
615
643
|
switch (n.kind) {
|
|
616
644
|
case "one":
|
|
617
|
-
await
|
|
645
|
+
await sr(e, t, n, r, i, a);
|
|
618
646
|
return;
|
|
619
647
|
case "many":
|
|
620
|
-
await
|
|
648
|
+
await cr(e, t, n, r, i, a);
|
|
621
649
|
return;
|
|
622
650
|
case "manyToMany":
|
|
623
|
-
await
|
|
651
|
+
await ur(e, t, n, r, i, a);
|
|
624
652
|
return;
|
|
625
653
|
}
|
|
626
|
-
},
|
|
627
|
-
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);
|
|
628
656
|
if (s !== void 0) {
|
|
629
|
-
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]));
|
|
630
658
|
for (let n of e) {
|
|
631
659
|
let e = n[s];
|
|
632
660
|
n[t] = e == null ? null : c.get(e) ?? null;
|
|
633
661
|
}
|
|
634
|
-
await
|
|
662
|
+
await mr(i, r.with, o, a);
|
|
635
663
|
return;
|
|
636
664
|
}
|
|
637
|
-
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();
|
|
638
666
|
for (let e of d) {
|
|
639
667
|
let n = e[c];
|
|
640
|
-
if (f.has(n)) throw new
|
|
668
|
+
if (f.has(n)) throw new rr(ir({
|
|
641
669
|
relationName: t,
|
|
642
670
|
sourceTableName: i.tableName,
|
|
643
671
|
targetTableName: o.tableName,
|
|
@@ -650,9 +678,9 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
650
678
|
let e = n[l];
|
|
651
679
|
n[t] = e == null ? null : f.get(e) ?? null;
|
|
652
680
|
}
|
|
653
|
-
await
|
|
654
|
-
},
|
|
655
|
-
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();
|
|
656
684
|
for (let e of d) {
|
|
657
685
|
let t = e[s], n = f.get(t);
|
|
658
686
|
n ? n.push(e) : f.set(t, [e]);
|
|
@@ -668,12 +696,12 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
668
696
|
let e = n[c];
|
|
669
697
|
n[t] = f.get(e) ?? [];
|
|
670
698
|
}
|
|
671
|
-
await
|
|
672
|
-
},
|
|
699
|
+
await mr(d, r.with, o, a);
|
|
700
|
+
}, lr = (e) => {
|
|
673
701
|
let { limit: t, offset: n, ...r } = e;
|
|
674
702
|
return r;
|
|
675
|
-
},
|
|
676
|
-
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");
|
|
677
705
|
if (c.length === 0) {
|
|
678
706
|
for (let n of e) n[t] = [];
|
|
679
707
|
return;
|
|
@@ -694,8 +722,8 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
694
722
|
for (let n of e) n[t] = [];
|
|
695
723
|
return;
|
|
696
724
|
}
|
|
697
|
-
let f = await
|
|
698
|
-
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);
|
|
699
727
|
let m = r.junction === void 0 ? void 0 : r.junction === !0 ? Object.keys(s.fields) : r.junction, h = /* @__PURE__ */ new Map();
|
|
700
728
|
for (let e of d) {
|
|
701
729
|
let t = e[n.sourceKey], r = e[n.targetKey], i = p.get(r);
|
|
@@ -707,16 +735,16 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
707
735
|
o ? o.push(a) : h.set(t, [a]);
|
|
708
736
|
}
|
|
709
737
|
for (let n of e) n[t] = h.get(n.id) ?? [];
|
|
710
|
-
},
|
|
738
|
+
}, dr = (e, t) => {
|
|
711
739
|
for (let [n, r] of Object.entries(e.fields)) if (r.type === "reference" && r.references?.()?.tableName === t) return n;
|
|
712
|
-
},
|
|
740
|
+
}, fr = (e, t) => {
|
|
713
741
|
let n = /* @__PURE__ */ new Set();
|
|
714
742
|
for (let r of e) {
|
|
715
743
|
let e = r[t];
|
|
716
744
|
e != null && n.add(e);
|
|
717
745
|
}
|
|
718
746
|
return [...n];
|
|
719
|
-
},
|
|
747
|
+
}, pr = (e, t, n, r, i) => {
|
|
720
748
|
let a = {
|
|
721
749
|
column: t,
|
|
722
750
|
op: "in",
|
|
@@ -730,50 +758,50 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
730
758
|
skip: r.offset,
|
|
731
759
|
projection: void 0
|
|
732
760
|
});
|
|
733
|
-
},
|
|
734
|
-
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) => {
|
|
735
763
|
let r = e[n];
|
|
736
764
|
for (let [e, n] of Object.entries(t)) e in r || (r[e] = n);
|
|
737
765
|
});
|
|
738
|
-
},
|
|
766
|
+
}, hr = (e) => e.eager !== void 0 && Object.keys(e.eager).length > 0, gr = class extends Error {
|
|
739
767
|
_tag = "TenantNamespaceUnresolved";
|
|
740
768
|
constructor(e) {
|
|
741
769
|
super(e), this.name = "TenantNamespaceUnresolved";
|
|
742
770
|
}
|
|
743
|
-
},
|
|
771
|
+
}, _r = class extends Error {
|
|
744
772
|
_tag = "TenantNamespaceInvalid";
|
|
745
773
|
constructor(e) {
|
|
746
774
|
super(e), this.name = "TenantNamespaceInvalid";
|
|
747
775
|
}
|
|
748
|
-
},
|
|
749
|
-
if (e == null || e === "") throw new
|
|
750
|
-
let t =
|
|
751
|
-
if (t.replace(/_/g, "") === "") throw new
|
|
752
|
-
let n = `${
|
|
753
|
-
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.`);
|
|
754
782
|
return n;
|
|
755
|
-
},
|
|
756
|
-
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;
|
|
757
785
|
if (typeof t == "number" && Number.isFinite(t)) return new Date(t);
|
|
758
|
-
if (typeof t == "string" &&
|
|
786
|
+
if (typeof t == "string" && wr.test(t)) {
|
|
759
787
|
let e = new Date(t);
|
|
760
788
|
return Number.isNaN(e.getTime()) ? t : e;
|
|
761
789
|
}
|
|
762
790
|
return t;
|
|
763
|
-
},
|
|
791
|
+
}, Er = (e, t) => e === void 0 || !Cr.has(e) ? t : t.map((t) => Tr(e, t)), Dr = (e, t) => {
|
|
764
792
|
let { strings: n, values: r } = e, i = t.unsafe(n[0] ?? "");
|
|
765
793
|
for (let e = 0; e < r.length; e++) i = t`${i}${r[e]}${t.unsafe(n[e + 1] ?? "")}`;
|
|
766
794
|
return t`${i}`;
|
|
767
|
-
},
|
|
768
|
-
if ("not" in e) return t`NOT (${
|
|
769
|
-
if ("and" in e) return e.and.length === 0 ? t`TRUE` : t.and(e.and.map((e) =>
|
|
770
|
-
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)));
|
|
771
799
|
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
772
|
-
let r = e, i =
|
|
800
|
+
let r = e, i = zr(r.subquery, t, n);
|
|
773
801
|
return r.op === "subquery-in" ? t`${t(r.column)} IN (${i})` : t`${t(r.column)} NOT IN (${i})`;
|
|
774
802
|
}
|
|
775
803
|
if (e.op === "exists" || e.op === "not-exists") {
|
|
776
|
-
let r = e, i =
|
|
804
|
+
let r = e, i = zr(r.subquery, t, n);
|
|
777
805
|
return r.op === "exists" ? t`EXISTS (${i})` : t`NOT EXISTS (${i})`;
|
|
778
806
|
}
|
|
779
807
|
let i = e, a = t(i.column), o = i.path, s = o !== void 0 && o.length > 0, c = () => t.onDialectOrElse({
|
|
@@ -786,7 +814,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
786
814
|
mssql: () => t.unsafe(w(i.column, o, "mssql", { numeric: !0 })),
|
|
787
815
|
sqlite: () => t.unsafe(w(i.column, o, "sqlite", { numeric: !0 })),
|
|
788
816
|
orElse: () => t.unsafe(w(i.column, o, "postgres", { numeric: !0 }))
|
|
789
|
-
}), 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);
|
|
790
818
|
switch (i.op) {
|
|
791
819
|
case "eq": return t`${u} = ${f(g(i.value))}`;
|
|
792
820
|
case "neq": return t`${u} <> ${f(g(i.value))}`;
|
|
@@ -803,7 +831,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
803
831
|
return e.length === 0 ? t`TRUE` : t`${u} NOT IN ${t.in(s ? e.map((e) => f(e)) : e)}`;
|
|
804
832
|
}
|
|
805
833
|
case "contains": {
|
|
806
|
-
let e = `%${
|
|
834
|
+
let e = `%${Or(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
|
|
807
835
|
return t.onDialectOrElse({
|
|
808
836
|
mysql: () => t`LOWER(${u}) LIKE LOWER(${e})`,
|
|
809
837
|
mssql: () => t`LOWER(${u}) LIKE LOWER(${e})`,
|
|
@@ -812,7 +840,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
812
840
|
});
|
|
813
841
|
}
|
|
814
842
|
case "startsWith": {
|
|
815
|
-
let e = `${
|
|
843
|
+
let e = `${Or(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
|
|
816
844
|
return t.onDialectOrElse({
|
|
817
845
|
mysql: () => t`${u} LIKE ${e}`,
|
|
818
846
|
orElse: () => t`${u} LIKE ${e} ESCAPE '\\'`
|
|
@@ -860,13 +888,13 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
860
888
|
});
|
|
861
889
|
}
|
|
862
890
|
}
|
|
863
|
-
},
|
|
891
|
+
}, kr = (e, t) => {
|
|
864
892
|
let n = [];
|
|
865
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}`);
|
|
866
|
-
},
|
|
894
|
+
}, Ar = (e, t) => t.csv(e.map((e) => {
|
|
867
895
|
let n = e.column === void 0 ? t.unsafe("*") : t`${t(e.column)}`;
|
|
868
896
|
if (e.op.startsWith("window-")) {
|
|
869
|
-
let r =
|
|
897
|
+
let r = kr(e.window ?? {}, t);
|
|
870
898
|
switch (e.op) {
|
|
871
899
|
case "window-row-number": return t`ROW_NUMBER() OVER (${r}) AS ${t(e.alias)}`;
|
|
872
900
|
case "window-rank": return t`RANK() OVER (${r}) AS ${t(e.alias)}`;
|
|
@@ -890,43 +918,43 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
890
918
|
return t`${t(e.column)} AS ${t(e.alias)}`;
|
|
891
919
|
default: throw Error(`compileAggregateProjection: unknown op '${e.op}'`);
|
|
892
920
|
}
|
|
893
|
-
})),
|
|
921
|
+
})), jr = (e) => `[${e.join(",")}]`, Mr = (e, t) => {
|
|
894
922
|
if (e.queryVector === void 0) return null;
|
|
895
|
-
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";
|
|
896
924
|
return t.onDialectOrElse({
|
|
897
925
|
mysql: () => t`${t.unsafe(a)}(${n}, ${r})`,
|
|
898
926
|
mssql: () => t`NULL`,
|
|
899
927
|
sqlite: () => t`NULL`,
|
|
900
928
|
orElse: () => t`${n} ${t.unsafe(i)} ${r}::vector`
|
|
901
929
|
});
|
|
902
|
-
},
|
|
930
|
+
}, Nr = (e, t) => {
|
|
903
931
|
let n = t.unsafe(e.useGeography ? "::geography" : "::geometry");
|
|
904
932
|
return t`ST_Distance(${t(e.column)}${n}, ${e.geom}${n})`;
|
|
905
|
-
},
|
|
906
|
-
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)}%`;
|
|
907
935
|
return n.onDialectOrElse({
|
|
908
936
|
mysql: () => n`MATCH(${r}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
|
|
909
937
|
sqlite: () => {
|
|
910
|
-
let r = n(
|
|
938
|
+
let r = n(Ir(e, t));
|
|
911
939
|
return n`${n("id")} IN (SELECT ${n("row_id")} FROM ${r} WHERE ${r} MATCH ${e.query})`;
|
|
912
940
|
},
|
|
913
941
|
mssql: () => n.or(e.columns.map((e) => n`LOWER(${n(e)}) LIKE LOWER(${i}) ESCAPE '\\'`)),
|
|
914
|
-
orElse: () => n`${
|
|
942
|
+
orElse: () => n`${Fr(e, n)} @@ plainto_tsquery(${e.config ?? "english"}, ${e.query})`
|
|
915
943
|
});
|
|
916
|
-
},
|
|
917
|
-
let r = `%${
|
|
944
|
+
}, Rr = (e, t, n) => {
|
|
945
|
+
let r = `%${Or(e.query)}%`;
|
|
918
946
|
return n.onDialectOrElse({
|
|
919
947
|
mysql: () => n`MATCH(${n.csv(e.columns.map((e) => n`${n(e)}`))}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
|
|
920
948
|
sqlite: () => {
|
|
921
|
-
let r = n(
|
|
949
|
+
let r = n(Ir(e, t));
|
|
922
950
|
return n`COALESCE((SELECT -bm25(${r}) FROM ${r} WHERE ${r} MATCH ${e.query} AND ${r}.${n("row_id")} = ${n("id")}), 0)`;
|
|
923
951
|
},
|
|
924
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}`),
|
|
925
|
-
orElse: () => n`ts_rank(${
|
|
953
|
+
orElse: () => n`ts_rank(${Fr(e, n)}, plainto_tsquery(${e.config ?? "english"}, ${e.query}))`
|
|
926
954
|
});
|
|
927
|
-
},
|
|
955
|
+
}, zr = (e, t, n = null) => {
|
|
928
956
|
if (e.setOp && e.setOp.queries.length >= 2) {
|
|
929
|
-
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 = [];
|
|
930
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) {
|
|
931
959
|
if (!Number.isInteger(e.take) || e.take < 0) throw Error(`compileSelect: invalid take ${e.take}`);
|
|
932
960
|
a.push(t` LIMIT ${t.unsafe(String(e.take))}`);
|
|
@@ -937,7 +965,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
937
965
|
}
|
|
938
966
|
return t`${i}${a.reduce((e, n) => t`${e}${n}`, t``)}`;
|
|
939
967
|
}
|
|
940
|
-
let r = e.annClause === void 0 ? null :
|
|
968
|
+
let r = e.annClause === void 0 ? null : Mr(e.annClause, t);
|
|
941
969
|
e.spatialClause !== void 0 && t.onDialectOrElse({
|
|
942
970
|
mysql: () => {
|
|
943
971
|
throw Error("@voltro/plugin-postgis: spatial distance / KNN ordering is postgres-only");
|
|
@@ -950,16 +978,16 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
950
978
|
},
|
|
951
979
|
orElse: () => t``
|
|
952
980
|
});
|
|
953
|
-
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({
|
|
954
982
|
orElse: () => t`DISTINCT ON (${t.csv(e.distinctOn.map((e) => t`${t(e)}`))}) `,
|
|
955
983
|
mysql: () => t`DISTINCT `,
|
|
956
984
|
mssql: () => t`DISTINCT `,
|
|
957
985
|
sqlite: () => t`DISTINCT `
|
|
958
|
-
}) : 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) => {
|
|
959
987
|
let r = e.kind === "inner" ? "INNER" : "LEFT";
|
|
960
|
-
return t` ${t.unsafe(r)} JOIN ${t(
|
|
961
|
-
}), h = m.length > 0 ? m.reduce((e, n) => t`${e}${n}`, p) : p, g = c === void 0 ? null :
|
|
962
|
-
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`);
|
|
963
991
|
for (let n of C(e)) y.push(n.direction === "desc" ? t`${t(n.column)} DESC` : t`${t(n.column)} ASC`);
|
|
964
992
|
let re = y.length > 0 ? t` ORDER BY ${t.csv(y)}` : ne ? t.onDialectOrElse({
|
|
965
993
|
mssql: () => t` ORDER BY (SELECT NULL)`,
|
|
@@ -967,7 +995,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
967
995
|
}) : t``, b = (e) => {
|
|
968
996
|
if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw Error(`compileSelect: expected non-negative integer take/skip, got ${e}`);
|
|
969
997
|
return t.unsafe(String(e));
|
|
970
|
-
}, 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``;
|
|
971
999
|
return t.onDialectOrElse({
|
|
972
1000
|
mssql: () => {
|
|
973
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``;
|
|
@@ -978,29 +1006,29 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
978
1006
|
return t`${oe}SELECT ${f}${d} FROM ${h}${te}${_}${v}${re}${n}${r}`;
|
|
979
1007
|
}
|
|
980
1008
|
});
|
|
981
|
-
},
|
|
1009
|
+
}, Br = (e, t, n) => {
|
|
982
1010
|
if (e.eager === void 0) return null;
|
|
983
|
-
let r =
|
|
1011
|
+
let r = Ur(e.table, e.eager, e.sourceTable);
|
|
984
1012
|
if (r === null) return null;
|
|
985
|
-
let i =
|
|
1013
|
+
let i = Xr(n, e, r, Yr(t, n));
|
|
986
1014
|
return i === null ? null : {
|
|
987
1015
|
fragment: i,
|
|
988
|
-
decode:
|
|
1016
|
+
decode: $r(r, n)
|
|
989
1017
|
};
|
|
990
|
-
},
|
|
1018
|
+
}, Vr = (e) => e.relation.kind === "one" && e.fkSide === "target", Hr = (e) => ({
|
|
991
1019
|
...e,
|
|
992
1020
|
branch: {
|
|
993
1021
|
...e.branch,
|
|
994
1022
|
limit: 2
|
|
995
1023
|
}
|
|
996
|
-
}),
|
|
997
|
-
let r = n ?? _(e), i =
|
|
1024
|
+
}), Ur = (e, t, n) => {
|
|
1025
|
+
let r = n ?? _(e), i = Fn(e);
|
|
998
1026
|
if (i === void 0) return null;
|
|
999
1027
|
let a = [];
|
|
1000
1028
|
for (let [e, n] of Object.entries(t)) {
|
|
1001
1029
|
let t = i[e];
|
|
1002
1030
|
if (t === void 0) return null;
|
|
1003
|
-
let o =
|
|
1031
|
+
let o = Wr(e, t, r, n === !0 ? {} : n);
|
|
1004
1032
|
if (o === null) return null;
|
|
1005
1033
|
a.push(o);
|
|
1006
1034
|
}
|
|
@@ -1008,11 +1036,11 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1008
1036
|
table: r,
|
|
1009
1037
|
children: a
|
|
1010
1038
|
};
|
|
1011
|
-
},
|
|
1039
|
+
}, Wr = (e, t, n, r) => {
|
|
1012
1040
|
let i = t.target(), a = (t.kind === "manyToMany" ? void 0 : t.sourceKey) ?? "id", o, s;
|
|
1013
1041
|
if (t.kind === "manyToMany") o = t.targetKey, s = "target";
|
|
1014
1042
|
else if (t.kind === "one") {
|
|
1015
|
-
let r = t.sourceKey ??
|
|
1043
|
+
let r = t.sourceKey ?? Jr(n, i.tableName);
|
|
1016
1044
|
if (r !== void 0) o = r, s = "source";
|
|
1017
1045
|
else try {
|
|
1018
1046
|
o = t.foreignKey ?? N(i, n.tableName, e), s = "target";
|
|
@@ -1025,13 +1053,13 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1025
1053
|
return null;
|
|
1026
1054
|
}
|
|
1027
1055
|
let c = r.with === void 0 ? [] : (() => {
|
|
1028
|
-
let e =
|
|
1056
|
+
let e = Fn(i.tableName);
|
|
1029
1057
|
if (e === void 0 && Object.keys(r.with).length > 0) return null;
|
|
1030
1058
|
let t = [];
|
|
1031
1059
|
for (let [n, a] of Object.entries(r.with)) {
|
|
1032
1060
|
let r = e?.[n];
|
|
1033
1061
|
if (r === void 0) return null;
|
|
1034
|
-
let o =
|
|
1062
|
+
let o = Wr(n, r, i, a === !0 ? {} : a);
|
|
1035
1063
|
if (o === null) return null;
|
|
1036
1064
|
t.push(o);
|
|
1037
1065
|
}
|
|
@@ -1047,9 +1075,9 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1047
1075
|
fkSide: s,
|
|
1048
1076
|
branch: r,
|
|
1049
1077
|
children: c,
|
|
1050
|
-
junction:
|
|
1078
|
+
junction: Gr(t, r)
|
|
1051
1079
|
};
|
|
1052
|
-
},
|
|
1080
|
+
}, Gr = (e, t) => {
|
|
1053
1081
|
if (e.kind !== "manyToMany" || t.junction === void 0) return;
|
|
1054
1082
|
let n = e.through(), r = t.junction === !0 ? Object.keys(n.fields) : t.junction, i = r.filter((e) => e in n.fields);
|
|
1055
1083
|
return {
|
|
@@ -1061,35 +1089,35 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1061
1089
|
return t !== void 0 && (t.type === "timestamp" || t.type === "date");
|
|
1062
1090
|
})
|
|
1063
1091
|
};
|
|
1064
|
-
},
|
|
1092
|
+
}, Kr = (e) => `__j_${e}`, qr = "__j", Jr = (e, t) => {
|
|
1065
1093
|
for (let [n, r] of Object.entries(e.fields)) if (r.type === "reference" && r.references?.()?.tableName === t) return n;
|
|
1066
|
-
},
|
|
1094
|
+
}, Yr = (e, t) => {
|
|
1067
1095
|
let n = 0;
|
|
1068
1096
|
return {
|
|
1069
1097
|
sql: e,
|
|
1070
1098
|
dialect: t,
|
|
1071
1099
|
nextAlias: () => `__a${n++}`
|
|
1072
1100
|
};
|
|
1073
|
-
},
|
|
1101
|
+
}, Xr = (e, t, n, r) => {
|
|
1074
1102
|
switch (e) {
|
|
1075
|
-
case "postgres": return
|
|
1103
|
+
case "postgres": return ni(t, n, r);
|
|
1076
1104
|
case "sqlite":
|
|
1077
|
-
case "turso": return
|
|
1105
|
+
case "turso": return ui(t, n, r);
|
|
1078
1106
|
case "mysql":
|
|
1079
|
-
case "mariadb": return
|
|
1080
|
-
case "mssql": return
|
|
1107
|
+
case "mariadb": return bi(t, n, r);
|
|
1108
|
+
case "mssql": return Di(t, n, r);
|
|
1081
1109
|
}
|
|
1082
|
-
},
|
|
1083
|
-
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);
|
|
1084
1112
|
return (e) => e.map((e) => {
|
|
1085
1113
|
let t = e.__row, r = typeof t == "string" ? JSON.parse(t) : t;
|
|
1086
1114
|
return n(r);
|
|
1087
1115
|
});
|
|
1088
|
-
},
|
|
1116
|
+
}, ei = (e, t, n) => {
|
|
1089
1117
|
let r = [];
|
|
1090
1118
|
for (let [t, n] of Object.entries(e.fields)) (n.type === "timestamp" || n.type === "date") && r.push(t);
|
|
1091
1119
|
let i = t.map((e) => {
|
|
1092
|
-
let t =
|
|
1120
|
+
let t = ei(e.target, e.children, n), r = e.relation.kind === "one", i = Vr(e), a = i ? ir({
|
|
1093
1121
|
relationName: e.relationName,
|
|
1094
1122
|
sourceTableName: e.source.tableName,
|
|
1095
1123
|
targetTableName: e.target.tableName,
|
|
@@ -1102,14 +1130,14 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1102
1130
|
isSingle: r,
|
|
1103
1131
|
fromOverFetch: i,
|
|
1104
1132
|
cardinalityMessage: a,
|
|
1105
|
-
junction:
|
|
1133
|
+
junction: ti(e.junction, n)
|
|
1106
1134
|
};
|
|
1107
1135
|
});
|
|
1108
1136
|
return (e) => {
|
|
1109
1137
|
let t = { ...e };
|
|
1110
1138
|
for (let e of r) {
|
|
1111
1139
|
let r = t[e];
|
|
1112
|
-
typeof r == "string" && (t[e] =
|
|
1140
|
+
typeof r == "string" && (t[e] = Zr(r, n));
|
|
1113
1141
|
}
|
|
1114
1142
|
for (let e of i) {
|
|
1115
1143
|
let n = t[e.name];
|
|
@@ -1119,7 +1147,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1119
1147
|
}
|
|
1120
1148
|
if (e.fromOverFetch) {
|
|
1121
1149
|
let r = n;
|
|
1122
|
-
if (r.length > 1) throw new
|
|
1150
|
+
if (r.length > 1) throw new rr(e.cardinalityMessage);
|
|
1123
1151
|
t[e.name] = r.length === 0 ? null : e.decode(r[0]);
|
|
1124
1152
|
continue;
|
|
1125
1153
|
}
|
|
@@ -1131,204 +1159,204 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1131
1159
|
}
|
|
1132
1160
|
return t;
|
|
1133
1161
|
};
|
|
1134
|
-
},
|
|
1162
|
+
}, ti = (e, t) => {
|
|
1135
1163
|
if (e === void 0) return;
|
|
1136
1164
|
let n = new Set(e.dateColumns), r = e.requested;
|
|
1137
1165
|
return (e) => {
|
|
1138
1166
|
let i = e._junction ?? {}, a = {};
|
|
1139
1167
|
for (let e of r) {
|
|
1140
1168
|
let r = i[e];
|
|
1141
|
-
a[e] = n.has(e) && typeof r == "string" ?
|
|
1169
|
+
a[e] = n.has(e) && typeof r == "string" ? Zr(r, t) : r;
|
|
1142
1170
|
}
|
|
1143
1171
|
return {
|
|
1144
1172
|
...e,
|
|
1145
1173
|
_junction: a
|
|
1146
1174
|
};
|
|
1147
1175
|
};
|
|
1148
|
-
},
|
|
1149
|
-
let r = n.sql, i = n.nextAlias(), a = r(t.table.tableName), o = r(i), s =
|
|
1150
|
-
return s === null ? null : r`SELECT ${s} AS "__row" FROM ${a} AS ${o}${e.predicate ? r` WHERE ${
|
|
1151
|
-
},
|
|
1152
|
-
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)`;
|
|
1153
1181
|
if (t.length === 0 && r === void 0) return a;
|
|
1154
1182
|
let o = [];
|
|
1155
|
-
r !== void 0 && o.push(i`${
|
|
1183
|
+
r !== void 0 && o.push(i`${B("_junction", i)}, ${z(e, qr, i)}`);
|
|
1156
1184
|
for (let r of t) {
|
|
1157
|
-
let t =
|
|
1185
|
+
let t = ii(r, e, n);
|
|
1158
1186
|
if (t === null) return null;
|
|
1159
|
-
o.push(i`${
|
|
1187
|
+
o.push(i`${B(r.relationName, i)}, ${t}`);
|
|
1160
1188
|
}
|
|
1161
1189
|
return i`${a} || jsonb_build_object(${i.csv(o)})`;
|
|
1162
|
-
},
|
|
1190
|
+
}, ii = (e, t, n) => {
|
|
1163
1191
|
switch (e.relation.kind) {
|
|
1164
|
-
case "one": return
|
|
1165
|
-
case "many": return
|
|
1166
|
-
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);
|
|
1167
1195
|
}
|
|
1168
|
-
},
|
|
1169
|
-
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);
|
|
1170
1198
|
if (a === null) return null;
|
|
1171
|
-
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);
|
|
1172
1200
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}${c} LIMIT 1)`;
|
|
1173
|
-
},
|
|
1174
|
-
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);
|
|
1175
1203
|
if (a === null) return null;
|
|
1176
|
-
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)}`;
|
|
1177
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)`;
|
|
1178
|
-
},
|
|
1179
|
-
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);
|
|
1180
1208
|
if (c === null) return null;
|
|
1181
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1182
|
-
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 ${
|
|
1183
|
-
},
|
|
1184
|
-
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);
|
|
1185
1213
|
if (a === null) return null;
|
|
1186
|
-
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)}`;
|
|
1187
1215
|
return r`SELECT ${a} AS "__row" FROM ${r(t.table.tableName)} AS ${r(i)}${o}${s}${c}${l}`;
|
|
1188
|
-
},
|
|
1216
|
+
}, di = (e, t, n, r, i) => {
|
|
1189
1217
|
let a = r.sql, o = [];
|
|
1190
|
-
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)}`);
|
|
1191
1219
|
if (i !== void 0) {
|
|
1192
|
-
let e =
|
|
1193
|
-
o.push(a`${
|
|
1220
|
+
let e = fi(i.projection, i.source, a);
|
|
1221
|
+
o.push(a`${B("_junction", a)}, json_object(${e})`);
|
|
1194
1222
|
}
|
|
1195
1223
|
for (let t of n) {
|
|
1196
|
-
let n =
|
|
1224
|
+
let n = gi(t, e, r);
|
|
1197
1225
|
if (n === null) return null;
|
|
1198
|
-
o.push(a`${
|
|
1226
|
+
o.push(a`${B(t.relationName, a)}, ${n}`);
|
|
1199
1227
|
}
|
|
1200
1228
|
return a`json_object(${a.csv(o)})`;
|
|
1201
|
-
},
|
|
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) => ({
|
|
1202
1230
|
alias: e,
|
|
1203
|
-
physical:
|
|
1204
|
-
}),
|
|
1231
|
+
physical: Kr
|
|
1232
|
+
}), hi = (e) => ({
|
|
1205
1233
|
alias: e,
|
|
1206
1234
|
physical: (e) => e
|
|
1207
|
-
}),
|
|
1235
|
+
}), gi = (e, t, n) => {
|
|
1208
1236
|
switch (e.relation.kind) {
|
|
1209
|
-
case "one": return
|
|
1210
|
-
case "many": return
|
|
1211
|
-
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);
|
|
1212
1240
|
}
|
|
1213
|
-
},
|
|
1214
|
-
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);
|
|
1215
1243
|
if (a === null) return null;
|
|
1216
|
-
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)}`;
|
|
1217
1245
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
|
|
1218
|
-
},
|
|
1219
|
-
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);
|
|
1220
1248
|
if (a === null) return null;
|
|
1221
|
-
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)}`;
|
|
1222
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('[]'))`;
|
|
1223
|
-
},
|
|
1224
|
-
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 : {
|
|
1225
1253
|
projection: e.junction,
|
|
1226
|
-
source:
|
|
1254
|
+
source: mi(o)
|
|
1227
1255
|
});
|
|
1228
1256
|
if (c === null) return null;
|
|
1229
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1230
|
-
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 ${
|
|
1231
|
-
},
|
|
1232
|
-
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);
|
|
1233
1261
|
if (a === null) return null;
|
|
1234
|
-
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)}`;
|
|
1235
1263
|
return r`SELECT ${a} AS \`__row\` FROM ${r(t.table.tableName)} AS ${r(i)}${o}${s}${c}${l}`;
|
|
1236
|
-
},
|
|
1264
|
+
}, R = (e, t, n, r, i) => {
|
|
1237
1265
|
let a = r.sql, o = [];
|
|
1238
|
-
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)}`);
|
|
1239
1267
|
if (i !== void 0) {
|
|
1240
|
-
let e =
|
|
1241
|
-
o.push(a`${
|
|
1268
|
+
let e = fi(i.projection, i.source, a);
|
|
1269
|
+
o.push(a`${B("_junction", a)}, JSON_OBJECT(${e})`);
|
|
1242
1270
|
}
|
|
1243
1271
|
for (let t of n) {
|
|
1244
|
-
let n =
|
|
1272
|
+
let n = xi(t, e, r);
|
|
1245
1273
|
if (n === null) return null;
|
|
1246
|
-
o.push(a`${
|
|
1274
|
+
o.push(a`${B(t.relationName, a)}, ${n}`);
|
|
1247
1275
|
}
|
|
1248
1276
|
return a`JSON_OBJECT(${a.csv(o)})`;
|
|
1249
|
-
},
|
|
1277
|
+
}, xi = (e, t, n) => {
|
|
1250
1278
|
switch (e.relation.kind) {
|
|
1251
1279
|
case "one":
|
|
1252
|
-
if (
|
|
1253
|
-
let r =
|
|
1254
|
-
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);
|
|
1255
1283
|
}
|
|
1256
|
-
return
|
|
1257
|
-
case "many": return n.dialect === "mariadb" ?
|
|
1258
|
-
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);
|
|
1259
1287
|
}
|
|
1260
|
-
},
|
|
1261
|
-
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);
|
|
1262
1290
|
if (a === null) return null;
|
|
1263
|
-
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)}`;
|
|
1264
1292
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
|
|
1265
|
-
},
|
|
1266
|
-
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);
|
|
1267
1295
|
if (a === null) return null;
|
|
1268
|
-
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)}`;
|
|
1269
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())`;
|
|
1270
|
-
},
|
|
1271
|
-
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 : {
|
|
1272
1300
|
projection: e.junction,
|
|
1273
|
-
source:
|
|
1301
|
+
source: mi(o)
|
|
1274
1302
|
});
|
|
1275
1303
|
if (c === null) return null;
|
|
1276
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1277
|
-
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 ${
|
|
1278
|
-
},
|
|
1279
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
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())`;
|
|
1306
|
+
}, Ti = (e, t, n) => {
|
|
1307
|
+
let r = n.sql, i = n.nextAlias(), a = R(i, e.target, e.children, n);
|
|
1280
1308
|
if (a === null) return null;
|
|
1281
|
-
let o = r`${
|
|
1282
|
-
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`${
|
|
1283
|
-
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 ${
|
|
1284
|
-
return r`COALESCE((SELECT JSON_ARRAYAGG(${a} ORDER BY ${
|
|
1285
|
-
},
|
|
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) => {
|
|
1286
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 : {
|
|
1287
1315
|
projection: e.junction,
|
|
1288
1316
|
source: t
|
|
1289
|
-
}, 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 ?? [];
|
|
1290
1318
|
if (e.branch.limit === void 0 && e.branch.offset === void 0) {
|
|
1291
|
-
let t =
|
|
1292
|
-
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())`;
|
|
1293
1321
|
}
|
|
1294
|
-
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)));
|
|
1295
1323
|
if (_ === null) return null;
|
|
1296
|
-
let v = e.junction === void 0 ? r`` :
|
|
1297
|
-
return r`COALESCE((SELECT JSON_ARRAYAGG(${_} ORDER BY ${
|
|
1298
|
-
},
|
|
1299
|
-
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);
|
|
1300
1328
|
if (a === null) return null;
|
|
1301
|
-
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``;
|
|
1302
1330
|
if (e.skip !== void 0) {
|
|
1303
1331
|
let t = C(e).length > 0 ? s : r` ORDER BY (SELECT NULL)`;
|
|
1304
|
-
l = e.take === void 0 ? r`${t} OFFSET ${
|
|
1305
|
-
} 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)} `);
|
|
1306
1334
|
let u = e.skip === void 0 ? s : r``;
|
|
1307
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}`;
|
|
1308
|
-
},
|
|
1336
|
+
}, Oi = (e, t, n, r, i) => {
|
|
1309
1337
|
let a = r.sql, o = [];
|
|
1310
|
-
for (let n of Object.keys(t.fields)) o.push(a`${
|
|
1311
|
-
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)}`);
|
|
1312
1340
|
for (let t of n) {
|
|
1313
|
-
let n =
|
|
1341
|
+
let n = Ai(t, e, r);
|
|
1314
1342
|
if (n === null) return null;
|
|
1315
1343
|
o.push(n);
|
|
1316
1344
|
}
|
|
1317
1345
|
return a.csv(o);
|
|
1318
|
-
},
|
|
1346
|
+
}, ki = (e, t) => t.unsafe(`[${e.replace(/]/g, "]]")}]`), Ai = (e, t, n) => {
|
|
1319
1347
|
switch (e.relation.kind) {
|
|
1320
|
-
case "one": return
|
|
1321
|
-
case "many": return
|
|
1322
|
-
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);
|
|
1323
1351
|
}
|
|
1324
|
-
},
|
|
1325
|
-
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);
|
|
1326
1354
|
if (a === null) return null;
|
|
1327
|
-
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)}`;
|
|
1328
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)}`;
|
|
1329
|
-
},
|
|
1357
|
+
}, Mi = (e, t, n) => {
|
|
1330
1358
|
if (e.offset !== void 0) {
|
|
1331
|
-
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`;
|
|
1332
1360
|
return {
|
|
1333
1361
|
top: n``,
|
|
1334
1362
|
pagination: i,
|
|
@@ -1336,33 +1364,33 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1336
1364
|
};
|
|
1337
1365
|
}
|
|
1338
1366
|
return {
|
|
1339
|
-
top: e.limit === void 0 ? n`` : n`TOP ${
|
|
1367
|
+
top: e.limit === void 0 ? n`` : n`TOP ${V(e.limit, n)} `,
|
|
1340
1368
|
pagination: n``,
|
|
1341
1369
|
finalOrder: t
|
|
1342
1370
|
};
|
|
1343
|
-
},
|
|
1344
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1371
|
+
}, Ni = (e, t, n) => {
|
|
1372
|
+
let r = n.sql, i = n.nextAlias(), a = Oi(i, e.target, e.children, n);
|
|
1345
1373
|
if (a === null) return null;
|
|
1346
|
-
let o = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1347
|
-
return r`ISNULL(JSON_QUERY((SELECT ${c}${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${
|
|
1348
|
-
},
|
|
1349
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
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 : {
|
|
1350
1378
|
projection: e.junction,
|
|
1351
|
-
source:
|
|
1379
|
+
source: hi(s)
|
|
1352
1380
|
});
|
|
1353
1381
|
if (c === null) return null;
|
|
1354
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1355
|
-
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 ${
|
|
1356
|
-
},
|
|
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) => {
|
|
1357
1385
|
if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw Error(`literalInt: expected non-negative integer, got ${e}`);
|
|
1358
1386
|
return t.unsafe(String(e));
|
|
1359
|
-
},
|
|
1387
|
+
}, H = (e, t, n) => I(Ii(e, t), n), Fi = (e, t, n, r = !1) => {
|
|
1360
1388
|
let i = e.branch.onJunction;
|
|
1361
|
-
return i === void 0 ? n`` : n` AND ${
|
|
1362
|
-
},
|
|
1363
|
-
if ("not" in e) return { not:
|
|
1364
|
-
if ("and" in e) return { and: e.and.map((e) =>
|
|
1365
|
-
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)) };
|
|
1366
1394
|
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
1367
1395
|
let n = e;
|
|
1368
1396
|
return {
|
|
@@ -1376,23 +1404,23 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1376
1404
|
...n,
|
|
1377
1405
|
column: `${t}.${n.column}`
|
|
1378
1406
|
};
|
|
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) =>
|
|
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)) };
|
|
1383
1411
|
if (e.op === "subquery-in" || e.op === "subquery-not-in" || e.op === "exists" || e.op === "not-exists") return e;
|
|
1384
1412
|
let t = e;
|
|
1385
1413
|
return {
|
|
1386
1414
|
...t,
|
|
1387
|
-
value:
|
|
1415
|
+
value: Li(t.value)
|
|
1388
1416
|
};
|
|
1389
|
-
},
|
|
1390
|
-
e.actors !== void 0 && (
|
|
1391
|
-
},
|
|
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) => () => {
|
|
1392
1420
|
let n = e();
|
|
1393
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`);
|
|
1394
1422
|
return n();
|
|
1395
|
-
},
|
|
1423
|
+
}, Ui = () => Hi(() => Bi.actors, "actors"), Wi = () => Hi(() => Bi.tenants, "tenants"), Gi = T("actors", {
|
|
1396
1424
|
id: b(),
|
|
1397
1425
|
kind: v().oneOf([
|
|
1398
1426
|
"user",
|
|
@@ -1402,73 +1430,73 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1402
1430
|
]),
|
|
1403
1431
|
displayName: v().nullable(),
|
|
1404
1432
|
createdAt: S().default("now")
|
|
1405
|
-
}),
|
|
1433
|
+
}), Ki = (e, t) => ({
|
|
1406
1434
|
column: e,
|
|
1407
1435
|
op: "eq",
|
|
1408
1436
|
value: t
|
|
1409
|
-
}),
|
|
1437
|
+
}), qi = (e, t) => ({
|
|
1410
1438
|
column: e,
|
|
1411
1439
|
op: "neq",
|
|
1412
1440
|
value: t
|
|
1413
|
-
}),
|
|
1441
|
+
}), Ji = (e, t) => ({
|
|
1414
1442
|
column: e,
|
|
1415
1443
|
op: "gt",
|
|
1416
1444
|
value: t
|
|
1417
|
-
}),
|
|
1445
|
+
}), Yi = (e, t) => ({
|
|
1418
1446
|
column: e,
|
|
1419
1447
|
op: "gte",
|
|
1420
1448
|
value: t
|
|
1421
|
-
}),
|
|
1449
|
+
}), Xi = (e, t) => ({
|
|
1422
1450
|
column: e,
|
|
1423
1451
|
op: "lt",
|
|
1424
1452
|
value: t
|
|
1425
|
-
}),
|
|
1453
|
+
}), Zi = (e, t) => ({
|
|
1426
1454
|
column: e,
|
|
1427
1455
|
op: "lte",
|
|
1428
1456
|
value: t
|
|
1429
|
-
}),
|
|
1457
|
+
}), Qi = (e, t) => ({
|
|
1430
1458
|
column: e,
|
|
1431
1459
|
op: "in",
|
|
1432
1460
|
value: t
|
|
1433
|
-
}),
|
|
1461
|
+
}), $i = (e, t) => ({
|
|
1434
1462
|
column: e,
|
|
1435
1463
|
op: "notIn",
|
|
1436
1464
|
value: t
|
|
1437
|
-
}),
|
|
1465
|
+
}), ea = (e, t) => ({
|
|
1438
1466
|
column: e,
|
|
1439
1467
|
op: "contains",
|
|
1440
1468
|
value: t
|
|
1441
|
-
}),
|
|
1469
|
+
}), ta = (e, t) => ({
|
|
1442
1470
|
column: e,
|
|
1443
1471
|
op: "startsWith",
|
|
1444
1472
|
value: t
|
|
1445
|
-
}),
|
|
1473
|
+
}), na = (e, t) => ({
|
|
1446
1474
|
column: e,
|
|
1447
1475
|
op: "arrayContains",
|
|
1448
1476
|
value: t
|
|
1449
|
-
}),
|
|
1477
|
+
}), ra = (e, t) => ({
|
|
1450
1478
|
column: e,
|
|
1451
1479
|
op: "arrayOverlaps",
|
|
1452
1480
|
value: t
|
|
1453
|
-
}),
|
|
1481
|
+
}), ia = (e, t) => ({
|
|
1454
1482
|
column: e,
|
|
1455
1483
|
op: "arrayHas",
|
|
1456
1484
|
value: t
|
|
1457
|
-
}),
|
|
1485
|
+
}), aa = {
|
|
1458
1486
|
column: "id",
|
|
1459
1487
|
op: "in",
|
|
1460
1488
|
value: []
|
|
1461
|
-
},
|
|
1489
|
+
}, oa = (e) => ({
|
|
1462
1490
|
column: e,
|
|
1463
1491
|
op: "isNull"
|
|
1464
|
-
}),
|
|
1492
|
+
}), sa = (e) => ({
|
|
1465
1493
|
column: e,
|
|
1466
1494
|
op: "isNotNull"
|
|
1467
|
-
}),
|
|
1495
|
+
}), ca = (e, t) => ({
|
|
1468
1496
|
column: e,
|
|
1469
1497
|
op: "spatial",
|
|
1470
1498
|
value: t
|
|
1471
|
-
}),
|
|
1499
|
+
}), la = (...e) => ({ and: e }), ua = (...e) => ({ or: e }), da = (e) => ({ not: e }), fa = (e, ...t) => {
|
|
1472
1500
|
if (t.length === 0) throw Error(`jsonField("${e}"): at least one path segment is required`);
|
|
1473
1501
|
let n = (n, r) => ({
|
|
1474
1502
|
column: e,
|
|
@@ -1490,33 +1518,33 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1490
1518
|
isNull: () => n("isNull"),
|
|
1491
1519
|
isNotNull: () => n("isNotNull")
|
|
1492
1520
|
};
|
|
1493
|
-
},
|
|
1521
|
+
}, pa = (e) => "descriptor" in e ? e.descriptor : e, ma = (e, t) => ({
|
|
1494
1522
|
column: e,
|
|
1495
1523
|
op: "subquery-in",
|
|
1496
|
-
subquery:
|
|
1497
|
-
}),
|
|
1524
|
+
subquery: pa(t)
|
|
1525
|
+
}), ha = (e, t) => ({
|
|
1498
1526
|
column: e,
|
|
1499
1527
|
op: "subquery-not-in",
|
|
1500
|
-
subquery:
|
|
1501
|
-
}),
|
|
1528
|
+
subquery: pa(t)
|
|
1529
|
+
}), ga = (e) => ({
|
|
1502
1530
|
op: "exists",
|
|
1503
|
-
subquery:
|
|
1504
|
-
}),
|
|
1531
|
+
subquery: pa(e)
|
|
1532
|
+
}), _a = (e) => ({
|
|
1505
1533
|
op: "not-exists",
|
|
1506
|
-
subquery:
|
|
1507
|
-
}),
|
|
1534
|
+
subquery: pa(e)
|
|
1535
|
+
}), va = (e, t) => e === t || e instanceof Date && t instanceof Date && e.getTime() === t.getTime(), ya = (e, t) => {
|
|
1508
1536
|
if (e == null || t == null) return null;
|
|
1509
1537
|
let n = e instanceof Date ? e.getTime() : e, r = t instanceof Date ? t.getTime() : t;
|
|
1510
1538
|
return typeof n == typeof r ? n === r ? 0 : n > r ? 1 : -1 : null;
|
|
1511
|
-
},
|
|
1539
|
+
}, ba = (e, t, n = null) => {
|
|
1512
1540
|
if (!t) return !1;
|
|
1513
|
-
if ("not" in e) return !
|
|
1541
|
+
if ("not" in e) return !ba(e.not, t, n);
|
|
1514
1542
|
if ("and" in e) {
|
|
1515
|
-
for (let r of e.and) if (!
|
|
1543
|
+
for (let r of e.and) if (!ba(r, t, n)) return !1;
|
|
1516
1544
|
return !0;
|
|
1517
1545
|
}
|
|
1518
1546
|
if ("or" in e) {
|
|
1519
|
-
for (let r of e.or) if (
|
|
1547
|
+
for (let r of e.or) if (ba(r, t, n)) return !0;
|
|
1520
1548
|
return !1;
|
|
1521
1549
|
}
|
|
1522
1550
|
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
@@ -1533,14 +1561,14 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1533
1561
|
}
|
|
1534
1562
|
let r = e, i = t[r.column];
|
|
1535
1563
|
switch (r.op) {
|
|
1536
|
-
case "eq": return
|
|
1537
|
-
case "neq": return !
|
|
1538
|
-
case "gt": return (
|
|
1539
|
-
case "gte": return (
|
|
1540
|
-
case "lt": return (
|
|
1541
|
-
case "lte": return (
|
|
1542
|
-
case "in": return Array.isArray(r.value) && r.value.some((e) =>
|
|
1543
|
-
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));
|
|
1544
1572
|
case "contains": return typeof i == "string" && typeof r.value == "string" && i.toLowerCase().includes(r.value.toLowerCase());
|
|
1545
1573
|
case "startsWith": return typeof i == "string" && typeof r.value == "string" && i.startsWith(r.value);
|
|
1546
1574
|
case "arrayContains": {
|
|
@@ -1556,17 +1584,17 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1556
1584
|
case "isNotNull": return i != null;
|
|
1557
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.");
|
|
1558
1586
|
}
|
|
1559
|
-
},
|
|
1587
|
+
}, xa = function* (e) {
|
|
1560
1588
|
if ("not" in e) {
|
|
1561
|
-
yield*
|
|
1589
|
+
yield* xa(e.not);
|
|
1562
1590
|
return;
|
|
1563
1591
|
}
|
|
1564
1592
|
if ("and" in e) {
|
|
1565
|
-
for (let t of e.and) yield*
|
|
1593
|
+
for (let t of e.and) yield* xa(t);
|
|
1566
1594
|
return;
|
|
1567
1595
|
}
|
|
1568
1596
|
if ("or" in e) {
|
|
1569
|
-
for (let t of e.or) yield*
|
|
1597
|
+
for (let t of e.or) yield* xa(t);
|
|
1570
1598
|
return;
|
|
1571
1599
|
}
|
|
1572
1600
|
e.op === "subquery-in" || e.op === "subquery-not-in" ? yield {
|
|
@@ -1576,46 +1604,46 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1576
1604
|
kind: "exists",
|
|
1577
1605
|
descriptor: e.subquery
|
|
1578
1606
|
});
|
|
1579
|
-
},
|
|
1607
|
+
}, Sa = function* (e, t = !0) {
|
|
1580
1608
|
if ("not" in e) {
|
|
1581
|
-
yield*
|
|
1609
|
+
yield* Sa(e.not, !1);
|
|
1582
1610
|
return;
|
|
1583
1611
|
}
|
|
1584
1612
|
if ("and" in e) {
|
|
1585
|
-
for (let n of e.and) yield*
|
|
1613
|
+
for (let n of e.and) yield* Sa(n, t);
|
|
1586
1614
|
return;
|
|
1587
1615
|
}
|
|
1588
1616
|
if ("or" in e) {
|
|
1589
|
-
for (let t of e.or) yield*
|
|
1617
|
+
for (let t of e.or) yield* Sa(t, !1);
|
|
1590
1618
|
return;
|
|
1591
1619
|
}
|
|
1592
1620
|
e.op !== "subquery-in" && e.op !== "subquery-not-in" && e.op !== "exists" && e.op !== "not-exists" && (yield {
|
|
1593
1621
|
...e,
|
|
1594
1622
|
conjunctive: t
|
|
1595
1623
|
});
|
|
1596
|
-
},
|
|
1624
|
+
}, Ca = (e, t) => ({
|
|
1597
1625
|
...t,
|
|
1598
1626
|
...e,
|
|
1599
1627
|
origin: e.origin ?? "injected"
|
|
1600
|
-
}),
|
|
1628
|
+
}), wa = (e, t, n = {}) => ({
|
|
1601
1629
|
table: e,
|
|
1602
1630
|
op: "insert",
|
|
1603
1631
|
old: null,
|
|
1604
1632
|
new: t,
|
|
1605
1633
|
...n
|
|
1606
|
-
}),
|
|
1634
|
+
}), Ta = (e, t, n, r = {}) => ({
|
|
1607
1635
|
table: e,
|
|
1608
1636
|
op: "update",
|
|
1609
1637
|
old: t,
|
|
1610
1638
|
new: n,
|
|
1611
1639
|
...r
|
|
1612
|
-
}),
|
|
1640
|
+
}), Ea = (e, t, n = {}) => ({
|
|
1613
1641
|
table: e,
|
|
1614
1642
|
op: "delete",
|
|
1615
1643
|
old: t,
|
|
1616
1644
|
new: null,
|
|
1617
1645
|
...n
|
|
1618
|
-
}),
|
|
1646
|
+
}), Da = (e, t, n = {}) => {
|
|
1619
1647
|
let { at: r = "2026-01-01T00:00:00.000Z", column: i = "deletedAt", ...a } = n;
|
|
1620
1648
|
return {
|
|
1621
1649
|
table: e,
|
|
@@ -1630,67 +1658,67 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1630
1658
|
},
|
|
1631
1659
|
...a
|
|
1632
1660
|
};
|
|
1633
|
-
},
|
|
1634
|
-
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();
|
|
1635
1663
|
return t === void 0 ? {} : {
|
|
1636
1664
|
...t.traceId === void 0 ? {} : { traceId: t.traceId },
|
|
1637
1665
|
...t.subjectId === void 0 ? {} : { subjectId: t.subjectId },
|
|
1638
1666
|
...t.procedure === void 0 ? {} : { procedure: t.procedure },
|
|
1639
1667
|
...t.via === void 0 ? {} : { via: t.via }
|
|
1640
1668
|
};
|
|
1641
|
-
},
|
|
1642
|
-
let t =
|
|
1643
|
-
return t === void 0 ? e(void 0) :
|
|
1644
|
-
},
|
|
1645
|
-
for (let [t, n] of
|
|
1646
|
-
let r = n.filter((t) => e - t.at <
|
|
1647
|
-
|
|
1648
|
-
}
|
|
1649
|
-
},
|
|
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) => {
|
|
1650
1678
|
if (t.traceId === void 0 && t.subjectId === void 0 && t.procedure === void 0) return;
|
|
1651
1679
|
let n = Date.now();
|
|
1652
|
-
if (
|
|
1653
|
-
let r =
|
|
1654
|
-
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, [{
|
|
1655
1683
|
attribution: t,
|
|
1656
1684
|
at: n
|
|
1657
1685
|
}]) : r.push({
|
|
1658
1686
|
attribution: t,
|
|
1659
1687
|
at: n
|
|
1660
|
-
}),
|
|
1661
|
-
},
|
|
1662
|
-
let t =
|
|
1688
|
+
}), G += 1;
|
|
1689
|
+
}, Ra = (e) => {
|
|
1690
|
+
let t = W.get(e);
|
|
1663
1691
|
if (t === void 0 || t.length === 0) return;
|
|
1664
1692
|
let n = t.shift();
|
|
1665
|
-
if (--
|
|
1666
|
-
},
|
|
1667
|
-
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);
|
|
1668
1696
|
if (t === void 0) return;
|
|
1669
|
-
|
|
1670
|
-
let n =
|
|
1671
|
-
n !== void 0 && (clearTimeout(n),
|
|
1697
|
+
Ba.delete(e);
|
|
1698
|
+
let n = Va.get(e);
|
|
1699
|
+
n !== void 0 && (clearTimeout(n), Va.delete(e));
|
|
1672
1700
|
for (let e of t) e();
|
|
1673
|
-
},
|
|
1674
|
-
|
|
1675
|
-
},
|
|
1676
|
-
let t = (
|
|
1701
|
+
}, Wa = (e) => {
|
|
1702
|
+
K.set(e, (K.get(e) ?? 0) + 1);
|
|
1703
|
+
}, Ga = (e) => {
|
|
1704
|
+
let t = (K.get(e) ?? 0) - 1;
|
|
1677
1705
|
if (t > 0) {
|
|
1678
|
-
|
|
1706
|
+
K.set(e, t);
|
|
1679
1707
|
return;
|
|
1680
1708
|
}
|
|
1681
|
-
|
|
1682
|
-
},
|
|
1683
|
-
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));
|
|
1684
1712
|
if (i === void 0) {
|
|
1685
1713
|
a();
|
|
1686
1714
|
return;
|
|
1687
1715
|
}
|
|
1688
|
-
if (
|
|
1716
|
+
if (za(i)) {
|
|
1689
1717
|
a();
|
|
1690
1718
|
return;
|
|
1691
1719
|
}
|
|
1692
|
-
let o =
|
|
1693
|
-
if (o === void 0 && (
|
|
1720
|
+
let o = Ba.get(e);
|
|
1721
|
+
if (o === void 0 && (K.get(e) ?? 0) === 0) {
|
|
1694
1722
|
a();
|
|
1695
1723
|
return;
|
|
1696
1724
|
}
|
|
@@ -1698,82 +1726,82 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1698
1726
|
o.push(a);
|
|
1699
1727
|
return;
|
|
1700
1728
|
}
|
|
1701
|
-
|
|
1702
|
-
let s = setTimeout(() =>
|
|
1703
|
-
typeof s == "object" && typeof s.unref == "function" && s.unref(),
|
|
1704
|
-
},
|
|
1705
|
-
|
|
1706
|
-
for (let e of
|
|
1707
|
-
|
|
1708
|
-
},
|
|
1709
|
-
|
|
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, {
|
|
1710
1738
|
recorder: t.recorder,
|
|
1711
1739
|
tables: new Set(t.tables),
|
|
1712
1740
|
ownTables: new Set(t.ownTables)
|
|
1713
1741
|
});
|
|
1714
|
-
},
|
|
1715
|
-
|
|
1716
|
-
},
|
|
1717
|
-
if (
|
|
1718
|
-
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;
|
|
1719
1747
|
return !1;
|
|
1720
|
-
},
|
|
1721
|
-
if (
|
|
1722
|
-
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 {
|
|
1723
1751
|
await r.recorder(e, t);
|
|
1724
1752
|
} catch (e) {
|
|
1725
|
-
let r =
|
|
1753
|
+
let r = fn(e);
|
|
1726
1754
|
throw r === void 0 ? e : Error(`write recorder '${n}' failed while recording a ${t.op} on '${t.table}': ${r}`, { cause: e });
|
|
1727
1755
|
}
|
|
1728
1756
|
}
|
|
1729
|
-
},
|
|
1757
|
+
}, ao = kt.exponential({
|
|
1730
1758
|
start: 5e-4,
|
|
1731
1759
|
factor: 2,
|
|
1732
1760
|
count: 16
|
|
1733
|
-
}),
|
|
1734
|
-
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);
|
|
1735
1763
|
if (r !== void 0) return r;
|
|
1736
1764
|
let i = (n) => D.tagged(D.tagged(n, "dialect", e), "op", t), a = {
|
|
1737
|
-
count: i(
|
|
1738
|
-
duration: i(
|
|
1739
|
-
errors: i(
|
|
1765
|
+
count: i(oo),
|
|
1766
|
+
duration: i(so),
|
|
1767
|
+
errors: i(co)
|
|
1740
1768
|
};
|
|
1741
|
-
return
|
|
1742
|
-
},
|
|
1743
|
-
|
|
1744
|
-
},
|
|
1745
|
-
let n = Math.max(0, (
|
|
1746
|
-
n === 0 ?
|
|
1747
|
-
let r =
|
|
1748
|
-
r === void 0 && (r = D.tagged(
|
|
1749
|
-
},
|
|
1750
|
-
let t =
|
|
1751
|
-
t.count.unsafeUpdate(1,
|
|
1752
|
-
},
|
|
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) => {
|
|
1753
1781
|
let r = performance.now(), i = String(e);
|
|
1754
|
-
|
|
1782
|
+
bo(i, 1);
|
|
1755
1783
|
let a = "ok";
|
|
1756
1784
|
try {
|
|
1757
1785
|
return await n();
|
|
1758
1786
|
} catch (e) {
|
|
1759
1787
|
throw a = "error", e;
|
|
1760
1788
|
} finally {
|
|
1761
|
-
|
|
1789
|
+
bo(i, -1), So({
|
|
1762
1790
|
dialect: e,
|
|
1763
1791
|
op: t,
|
|
1764
1792
|
durationMs: performance.now() - r,
|
|
1765
1793
|
status: a
|
|
1766
1794
|
});
|
|
1767
1795
|
}
|
|
1768
|
-
},
|
|
1796
|
+
}, wo = 3e5, To = (e) => {
|
|
1769
1797
|
if (e == null || e === "") return;
|
|
1770
1798
|
let t = Number(e);
|
|
1771
1799
|
return Number.isFinite(t) && t >= 0 ? Math.floor(t) : void 0;
|
|
1772
|
-
},
|
|
1773
|
-
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();
|
|
1774
1802
|
return (t) => {
|
|
1775
|
-
let a = `${t.dialect} ${t.reason}`, o =
|
|
1776
|
-
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);
|
|
1777
1805
|
let s = `${t.table}\u0000${t.reason}`, c = i.get(s), l = c === void 0 || n > 0 && r() - c >= n, u = {
|
|
1778
1806
|
table: t.table,
|
|
1779
1807
|
dialect: String(t.dialect),
|
|
@@ -1787,13 +1815,13 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1787
1815
|
}
|
|
1788
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);
|
|
1789
1817
|
};
|
|
1790
|
-
},
|
|
1818
|
+
}, Oo = (e) => {
|
|
1791
1819
|
if (Ot.isSuccess(e)) return e.value;
|
|
1792
1820
|
throw Tt.squash(e.cause);
|
|
1793
|
-
},
|
|
1821
|
+
}, ko = "10 millis", Ao = 3, jo = async (e) => {
|
|
1794
1822
|
let t = 0, n = E.suspend(() => {
|
|
1795
1823
|
let n = ++t;
|
|
1796
|
-
return e.withTransaction(E.flatMap(E.serviceOption(
|
|
1824
|
+
return e.withTransaction(E.flatMap(E.serviceOption(Ft), (t) => {
|
|
1797
1825
|
if (O.isNone(t)) return E.fail(/* @__PURE__ */ Error(`${e.label}: TransactionConnection unexpectedly missing inside withTransaction.`));
|
|
1798
1826
|
let r = t.value, i = E.tryPromise({
|
|
1799
1827
|
try: () => e.body(r, n),
|
|
@@ -1801,10 +1829,10 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1801
1829
|
});
|
|
1802
1830
|
return e.prepare === void 0 ? i : E.flatMap(e.prepare(r), () => i);
|
|
1803
1831
|
})).pipe(E.catchAllDefect((t) => e.isRetryable(t) ? E.fail(t) : E.die(t)));
|
|
1804
|
-
}), r = jt.exponential(
|
|
1805
|
-
return
|
|
1806
|
-
},
|
|
1807
|
-
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({
|
|
1808
1836
|
...e,
|
|
1809
1837
|
body: (r) => {
|
|
1810
1838
|
let i = e.makeView(r, t);
|
|
@@ -1815,14 +1843,14 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1815
1843
|
}
|
|
1816
1844
|
});
|
|
1817
1845
|
return r.view.commitEvents(), r.result;
|
|
1818
|
-
},
|
|
1846
|
+
}, No = class extends k.TaggedError()("VersionConflict", {
|
|
1819
1847
|
table: k.String,
|
|
1820
1848
|
id: k.String,
|
|
1821
1849
|
expected: k.Number,
|
|
1822
1850
|
actual: k.NullOr(k.Number)
|
|
1823
|
-
}) {},
|
|
1851
|
+
}) {}, Po = (e) => {
|
|
1824
1852
|
for (let [t, n] of Object.entries(e)) if (n?.definition?.versionColumn === !0) return t;
|
|
1825
|
-
},
|
|
1853
|
+
}, Fo = (e) => {
|
|
1826
1854
|
let { versionColumn: t, patch: n } = e;
|
|
1827
1855
|
if (t === void 0) return {
|
|
1828
1856
|
nextVersion: void 0,
|
|
@@ -1835,28 +1863,28 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1835
1863
|
expected: i,
|
|
1836
1864
|
patch: a
|
|
1837
1865
|
};
|
|
1838
|
-
},
|
|
1839
|
-
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({
|
|
1840
1868
|
table: e.table,
|
|
1841
1869
|
id: e.id,
|
|
1842
1870
|
expected: e.expected,
|
|
1843
1871
|
actual: e.current
|
|
1844
1872
|
});
|
|
1845
|
-
},
|
|
1846
|
-
id:
|
|
1873
|
+
}, Lo = 1, Ro = "voltro/expires", zo = () => st({
|
|
1874
|
+
id: Ro,
|
|
1847
1875
|
fields: { expiresAt: S().nullable() },
|
|
1848
1876
|
behaviors: { defaultWhere: () => "expiresAt IS NULL OR expiresAt > now()" }
|
|
1849
|
-
}),
|
|
1850
|
-
id:
|
|
1877
|
+
}), Bo = "voltro/localFirst", Vo = () => st({
|
|
1878
|
+
id: Bo,
|
|
1851
1879
|
fields: {}
|
|
1852
|
-
}),
|
|
1880
|
+
}), Ho = (e) => e.appliedMixins.some((e) => e.id === Bo), Uo = (e) => {
|
|
1853
1881
|
let t = [];
|
|
1854
|
-
for (let n of Object.values(e))
|
|
1882
|
+
for (let n of Object.values(e)) Ho(n) && t.push(n.tableName);
|
|
1855
1883
|
return t;
|
|
1856
|
-
},
|
|
1884
|
+
}, Wo = class extends Dt.TaggedError("TableStreamError") {}, Go = 1e3, Ko = (e, t, n, r) => {
|
|
1857
1885
|
let i = O.match(r, {
|
|
1858
1886
|
onNone: () => e.where,
|
|
1859
|
-
onSome: (n) => e.where ?
|
|
1887
|
+
onSome: (n) => e.where ? la(e.where, Ji(t, n)) : Ji(t, n)
|
|
1860
1888
|
});
|
|
1861
1889
|
return {
|
|
1862
1890
|
table: e.table,
|
|
@@ -1871,19 +1899,19 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1871
1899
|
...e.includeDeleted === void 0 ? {} : { includeDeleted: e.includeDeleted },
|
|
1872
1900
|
...e.crossTenant === void 0 ? {} : { crossTenant: e.crossTenant }
|
|
1873
1901
|
};
|
|
1874
|
-
},
|
|
1875
|
-
let n = t.pk ?? "id", r = t.chunkSize ??
|
|
1902
|
+
}, qo = (e, t) => {
|
|
1903
|
+
let n = t.pk ?? "id", r = t.chunkSize ?? Go;
|
|
1876
1904
|
return Mt.paginateChunkEffect(O.none(), (i) => {
|
|
1877
1905
|
let a = E.tryPromise({
|
|
1878
|
-
try: () => e.query(
|
|
1879
|
-
catch: (e) => new
|
|
1906
|
+
try: () => e.query(Ko(t, n, r, i)),
|
|
1907
|
+
catch: (e) => new Wo({
|
|
1880
1908
|
table: t.table,
|
|
1881
1909
|
cause: e
|
|
1882
1910
|
})
|
|
1883
1911
|
});
|
|
1884
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()]));
|
|
1885
1913
|
});
|
|
1886
|
-
},
|
|
1914
|
+
}, Jo = (e) => {
|
|
1887
1915
|
let t = e.alpha ?? .5;
|
|
1888
1916
|
if (t < 0 || t > 1) throw Error(`hybridSearch: alpha must be in [0, 1], got ${t}`);
|
|
1889
1917
|
return (n) => {
|
|
@@ -1910,14 +1938,14 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1910
1938
|
}
|
|
1911
1939
|
};
|
|
1912
1940
|
};
|
|
1913
|
-
},
|
|
1941
|
+
}, Yo = async (e, t) => {
|
|
1914
1942
|
let n = e.as ?? "embedding", r = t.row[e.from];
|
|
1915
1943
|
if (typeof r != "string" || r.length === 0) return {};
|
|
1916
1944
|
let i = await t.embed(r);
|
|
1917
1945
|
return { [n]: i };
|
|
1918
|
-
},
|
|
1946
|
+
}, Xo = (e) => {
|
|
1919
1947
|
if (!Number.isInteger(e.dimensions) || e.dimensions <= 0) throw Error(`vectorEmbedding: dimensions must be a positive integer, got ${String(e.dimensions)}.`);
|
|
1920
|
-
let t = e.as ?? "embedding", n = (t) =>
|
|
1948
|
+
let t = e.as ?? "embedding", n = (t) => Yo(e, t);
|
|
1921
1949
|
return st({
|
|
1922
1950
|
id: "voltro/vectorEmbedding",
|
|
1923
1951
|
fields: { [t]: Te(e.dimensions) },
|
|
@@ -1935,19 +1963,19 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1935
1963
|
beforeUpdate: n
|
|
1936
1964
|
}
|
|
1937
1965
|
});
|
|
1938
|
-
},
|
|
1966
|
+
}, Zo = 63, Qo = "br_pr", J = class extends Error {
|
|
1939
1967
|
_tag = "BranchNameInvalid";
|
|
1940
1968
|
constructor(e) {
|
|
1941
1969
|
super(e), this.name = "BranchNameInvalid";
|
|
1942
1970
|
}
|
|
1943
|
-
},
|
|
1944
|
-
if (!Number.isInteger(t) || t < 0) throw new
|
|
1945
|
-
let n =
|
|
1946
|
-
if (n.replace(/_/g, "") === "") throw new
|
|
1947
|
-
let r = `${
|
|
1948
|
-
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`);
|
|
1949
1977
|
return r;
|
|
1950
|
-
},
|
|
1978
|
+
}, es = (e) => e.startsWith(Qo), ts = {
|
|
1951
1979
|
requested: {
|
|
1952
1980
|
provision: "provisioning",
|
|
1953
1981
|
destroy: "destroying"
|
|
@@ -1966,19 +1994,19 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1966
1994
|
fail: "failed"
|
|
1967
1995
|
},
|
|
1968
1996
|
destroyed: {}
|
|
1969
|
-
},
|
|
1997
|
+
}, ns = class extends Error {
|
|
1970
1998
|
from;
|
|
1971
1999
|
event;
|
|
1972
2000
|
_tag = "BranchTransitionInvalid";
|
|
1973
2001
|
constructor(e, t) {
|
|
1974
2002
|
super(`invalid branch transition: ${e} --${t}-->`), this.from = e, this.event = t, this.name = "BranchTransitionInvalid";
|
|
1975
2003
|
}
|
|
1976
|
-
},
|
|
1977
|
-
let n =
|
|
1978
|
-
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);
|
|
1979
2007
|
return n;
|
|
1980
|
-
},
|
|
1981
|
-
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");
|
|
1982
2010
|
let o = [{
|
|
1983
2011
|
kind: "create-namespace",
|
|
1984
2012
|
detail: e
|
|
@@ -2007,13 +2035,13 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
2007
2035
|
kind: "seed",
|
|
2008
2036
|
detail: `run boot seeds into ${e}`
|
|
2009
2037
|
}), o;
|
|
2010
|
-
},
|
|
2011
|
-
if (!
|
|
2038
|
+
}, as = (e) => {
|
|
2039
|
+
if (!es(e)) throw new J(`refusing to plan teardown of '${e}' — not a branch namespace`);
|
|
2012
2040
|
return [{
|
|
2013
2041
|
kind: "drop-namespace",
|
|
2014
2042
|
detail: e
|
|
2015
2043
|
}];
|
|
2016
|
-
},
|
|
2044
|
+
}, os = (e) => {
|
|
2017
2045
|
if (e === void 0 || e === "") return !1;
|
|
2018
2046
|
try {
|
|
2019
2047
|
let t = new URL(e).hostname.toLowerCase();
|
|
@@ -2021,27 +2049,27 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
2021
2049
|
} catch {
|
|
2022
2050
|
return /\bneon\.(tech|build)\b/i.test(e);
|
|
2023
2051
|
}
|
|
2024
|
-
},
|
|
2052
|
+
}, ss = (e) => e.prefer === void 0 ? e.seed === "copy" && os(e.dbUrl) ? "neon-cow" : "namespace" : e.prefer, cs = (e, t = {}) => [{
|
|
2025
2053
|
kind: "neon-branch-create",
|
|
2026
2054
|
detail: `${t.parentBranch ?? "main"} → ${e} (copy-on-write)`
|
|
2027
|
-
}],
|
|
2028
|
-
if (!
|
|
2055
|
+
}], ls = (e) => {
|
|
2056
|
+
if (!es(e)) throw new J(`refusing to plan teardown of '${e}' — not a branch namespace`);
|
|
2029
2057
|
return [{
|
|
2030
2058
|
kind: "neon-branch-delete",
|
|
2031
2059
|
detail: e
|
|
2032
2060
|
}];
|
|
2033
|
-
},
|
|
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) => {
|
|
2034
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);
|
|
2035
2063
|
return {
|
|
2036
2064
|
evict: i,
|
|
2037
2065
|
rejectNew: r.filter((e) => !a.has(e.namespace)).length >= t.maxBranches
|
|
2038
2066
|
};
|
|
2039
|
-
},
|
|
2040
|
-
let n =
|
|
2067
|
+
}, ps = async (e, t) => {
|
|
2068
|
+
let n = $o(e.appSlug, e.prNumber), r = ss({
|
|
2041
2069
|
seed: e.seed,
|
|
2042
2070
|
...e.dbUrl === void 0 ? {} : { dbUrl: e.dbUrl },
|
|
2043
2071
|
...e.prefer === void 0 ? {} : { prefer: e.prefer }
|
|
2044
|
-
}), i =
|
|
2072
|
+
}), i = us({
|
|
2045
2073
|
mechanism: r,
|
|
2046
2074
|
branchId: n,
|
|
2047
2075
|
tableNames: e.tableNames,
|
|
@@ -2070,16 +2098,16 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
2070
2098
|
mechanism: r,
|
|
2071
2099
|
steps: i
|
|
2072
2100
|
};
|
|
2073
|
-
},
|
|
2074
|
-
let r =
|
|
2101
|
+
}, ms = async (e, t, n) => {
|
|
2102
|
+
let r = ds(t, e);
|
|
2075
2103
|
return t === "neon-cow" ? await n.neonBranchDelete(e) : await n.dropNamespace(e), r;
|
|
2076
|
-
},
|
|
2104
|
+
}, hs = (e, t, n) => fs(e, t, n), Y = (e) => `"${e.replace(/"/g, "\"\"")}"`, gs = {
|
|
2077
2105
|
cascade: "CASCADE",
|
|
2078
2106
|
restrict: "RESTRICT",
|
|
2079
2107
|
setNull: "SET NULL",
|
|
2080
2108
|
noAction: "NO ACTION"
|
|
2081
|
-
},
|
|
2082
|
-
let n = t.columns.map(
|
|
2109
|
+
}, X = (e) => `'${e.replace(/'/g, "''")}'`, _s = (e, t) => {
|
|
2110
|
+
let n = t.columns.map(X).join(", ");
|
|
2083
2111
|
return `DO $voltro_branch$
|
|
2084
2112
|
DECLARE derived name;
|
|
2085
2113
|
BEGIN
|
|
@@ -2088,11 +2116,11 @@ BEGIN
|
|
|
2088
2116
|
JOIN pg_class i ON i.oid = x.indexrelid
|
|
2089
2117
|
JOIN pg_class c ON c.oid = x.indrelid
|
|
2090
2118
|
JOIN pg_namespace nsp ON nsp.oid = c.relnamespace
|
|
2091
|
-
WHERE nsp.nspname = ${
|
|
2092
|
-
AND c.relname = ${
|
|
2119
|
+
WHERE nsp.nspname = ${X(e)}
|
|
2120
|
+
AND c.relname = ${X(t.table)}
|
|
2093
2121
|
AND NOT x.indisprimary
|
|
2094
2122
|
AND x.indisunique = ${t.unique ? "true" : "false"}
|
|
2095
|
-
AND i.relname <> ${
|
|
2123
|
+
AND i.relname <> ${X(t.name)}
|
|
2096
2124
|
AND (
|
|
2097
2125
|
SELECT array_agg(att.attname::text ORDER BY k.ord)
|
|
2098
2126
|
FROM unnest(x.indkey::int2[]) WITH ORDINALITY AS k(attnum, ord)
|
|
@@ -2101,39 +2129,39 @@ BEGIN
|
|
|
2101
2129
|
LIMIT 1;
|
|
2102
2130
|
IF derived IS NOT NULL THEN
|
|
2103
2131
|
EXECUTE format('ALTER INDEX %I.%I RENAME TO %I',
|
|
2104
|
-
${
|
|
2132
|
+
${X(e)}, derived, ${X(t.name)});
|
|
2105
2133
|
END IF;
|
|
2106
2134
|
END
|
|
2107
2135
|
$voltro_branch$`;
|
|
2108
|
-
},
|
|
2109
|
-
let n = t.onDelete === void 0 ? "" : ` ON DELETE ${
|
|
2110
|
-
return `ALTER TABLE ${
|
|
2111
|
-
},
|
|
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) => {
|
|
2112
2140
|
let t = () => {
|
|
2113
2141
|
throw Error("namespace branch executor: Neon ops require a neon-cow executor (use a Neon connection for copy-on-write branches)");
|
|
2114
2142
|
};
|
|
2115
2143
|
return {
|
|
2116
|
-
createNamespace: (t) => e.run(`CREATE SCHEMA IF NOT EXISTS ${
|
|
2117
|
-
createTable: (t, n) => e.run(`CREATE TABLE IF NOT EXISTS ${
|
|
2118
|
-
copyTable: (t, n, r) => e.run(`INSERT INTO ${
|
|
2119
|
-
addForeignKey: (t, n) => e.run(
|
|
2120
|
-
restoreIndexName: (t, n) => e.run(
|
|
2121
|
-
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`),
|
|
2122
2150
|
neonBranchCreate: t,
|
|
2123
2151
|
neonBranchDelete: t
|
|
2124
2152
|
};
|
|
2125
|
-
},
|
|
2153
|
+
}, bs = class extends Error {
|
|
2126
2154
|
_tag = "TenantResidencyUnresolved";
|
|
2127
2155
|
constructor(e) {
|
|
2128
2156
|
super(e), this.name = "TenantResidencyUnresolved";
|
|
2129
2157
|
}
|
|
2130
|
-
},
|
|
2158
|
+
}, xs = class extends Error {
|
|
2131
2159
|
region;
|
|
2132
2160
|
_tag = "TenantRegionUnavailable";
|
|
2133
2161
|
constructor(e, t) {
|
|
2134
2162
|
super(t), this.region = e, this.name = "TenantRegionUnavailable";
|
|
2135
2163
|
}
|
|
2136
|
-
},
|
|
2164
|
+
}, Ss, Cs = (e) => {
|
|
2137
2165
|
if (e.homes === void 0) throw Error("setResidencyConfig: `homes` is required");
|
|
2138
2166
|
if (e.servableRegions === void 0 || e.servableRegions.length === 0) throw Error("setResidencyConfig: `servableRegions` must be non-empty (which regions this deployment serves)");
|
|
2139
2167
|
let t = /* @__PURE__ */ new Map();
|
|
@@ -2142,55 +2170,55 @@ $voltro_branch$`;
|
|
|
2142
2170
|
if (e !== void 0 && e !== n.region) throw Error(`residency: tenant '${n.tenantId}' is mapped to two regions ('${e}' and '${n.region}')`);
|
|
2143
2171
|
t.set(n.tenantId, n.region);
|
|
2144
2172
|
}
|
|
2145
|
-
return
|
|
2146
|
-
},
|
|
2147
|
-
|
|
2148
|
-
},
|
|
2149
|
-
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");
|
|
2150
2178
|
let n = t.homes.find((t) => t.tenantId === e);
|
|
2151
|
-
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)`);
|
|
2152
2180
|
return n;
|
|
2153
|
-
},
|
|
2154
|
-
let n =
|
|
2181
|
+
}, Ds = (e, t) => t.servableRegions.includes(e), Os = (e, t) => {
|
|
2182
|
+
let n = Es(e.tenantId, t), r = xr(n.tenantId);
|
|
2155
2183
|
return {
|
|
2156
2184
|
region: n.region,
|
|
2157
2185
|
namespace: r,
|
|
2158
2186
|
...n.connectionKey === void 0 ? {} : { connectionKey: n.connectionKey }
|
|
2159
2187
|
};
|
|
2160
|
-
},
|
|
2161
|
-
let r =
|
|
2162
|
-
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`);
|
|
2163
2191
|
let i = n.get(r.region);
|
|
2164
|
-
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`);
|
|
2165
2193
|
return {
|
|
2166
2194
|
store: i,
|
|
2167
2195
|
placement: r
|
|
2168
2196
|
};
|
|
2169
|
-
},
|
|
2170
|
-
let { store: i, placement: a } =
|
|
2197
|
+
}, As = async (e, t, n, r) => {
|
|
2198
|
+
let { store: i, placement: a } = ks(e, t, n);
|
|
2171
2199
|
return await r(i, a), a;
|
|
2172
|
-
},
|
|
2200
|
+
}, js = (e) => {
|
|
2173
2201
|
if (typeof e == "string") return e;
|
|
2174
2202
|
if ("jsonPath" in e) {
|
|
2175
2203
|
let { column: t, path: n, numeric: r } = e.jsonPath;
|
|
2176
2204
|
return `(json:${t}->${n.join(".")}${r ? "::num" : ""})`;
|
|
2177
2205
|
}
|
|
2178
2206
|
return `(${e.expr})`;
|
|
2179
|
-
}, Z = (e) => e.map(
|
|
2207
|
+
}, Z = (e) => e.map(js), Ms = (e, t) => {
|
|
2180
2208
|
if (e.length !== t.length) return !1;
|
|
2181
|
-
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;
|
|
2182
2210
|
return !0;
|
|
2183
|
-
},
|
|
2211
|
+
}, Ns = (e, t) => {
|
|
2184
2212
|
if (e.length >= t.length) return !1;
|
|
2185
|
-
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;
|
|
2186
2214
|
return !0;
|
|
2187
|
-
},
|
|
2215
|
+
}, Ps = (e) => {
|
|
2188
2216
|
let t = [], n = e.appliedIndexes, r = e.tableName;
|
|
2189
2217
|
for (let e = 0; e < n.length; e++) {
|
|
2190
2218
|
let i = n[e];
|
|
2191
2219
|
for (let a = e + 1; a < n.length; a++) {
|
|
2192
2220
|
let e = n[a];
|
|
2193
|
-
if (
|
|
2221
|
+
if (Ms(i.fields, e.fields)) {
|
|
2194
2222
|
let [n, a] = i.name < e.name ? [i, e] : [e, i];
|
|
2195
2223
|
t.push({
|
|
2196
2224
|
kind: "duplicate-fields",
|
|
@@ -2201,13 +2229,13 @@ $voltro_branch$`;
|
|
|
2201
2229
|
});
|
|
2202
2230
|
continue;
|
|
2203
2231
|
}
|
|
2204
|
-
|
|
2232
|
+
Ns(i.fields, e.fields) ? t.push({
|
|
2205
2233
|
kind: "redundant-prefix",
|
|
2206
2234
|
table: r,
|
|
2207
2235
|
redundant: i,
|
|
2208
2236
|
coveredBy: e,
|
|
2209
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).`
|
|
2210
|
-
}) :
|
|
2238
|
+
}) : Ns(e.fields, i.fields) && t.push({
|
|
2211
2239
|
kind: "redundant-prefix",
|
|
2212
2240
|
table: r,
|
|
2213
2241
|
redundant: e,
|
|
@@ -2217,23 +2245,23 @@ $voltro_branch$`;
|
|
|
2217
2245
|
}
|
|
2218
2246
|
}
|
|
2219
2247
|
return t;
|
|
2220
|
-
},
|
|
2248
|
+
}, Fs = (e) => {
|
|
2221
2249
|
let t = [];
|
|
2222
|
-
for (let n of e) t.push(...
|
|
2250
|
+
for (let n of e) t.push(...Ps(n));
|
|
2223
2251
|
return t;
|
|
2224
|
-
},
|
|
2225
|
-
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) => {
|
|
2226
2254
|
let n = e.slice(0, t), r = e.slice(t), i = [];
|
|
2227
2255
|
return n.length > 0 && i.push(s(`[${n.join(", ")}]`)), r.length > 0 && i.push(c(`+ [${r.join(", ")}]`)), i.join(" ");
|
|
2228
2256
|
}, m = [];
|
|
2229
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");
|
|
2230
|
-
},
|
|
2258
|
+
}, Vs = (e, { apply: t, undo: n }) => ({
|
|
2231
2259
|
name: e,
|
|
2232
2260
|
apply: t,
|
|
2233
2261
|
undo: n
|
|
2234
|
-
}),
|
|
2262
|
+
}), Hs = (e) => {
|
|
2235
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>)`);
|
|
2236
|
-
let t = e.steps({ step:
|
|
2264
|
+
let t = e.steps({ step: Vs });
|
|
2237
2265
|
if (t.length === 0) throw Error(`migration "${e.id}": at least one step is required`);
|
|
2238
2266
|
return {
|
|
2239
2267
|
__migration: !0,
|
|
@@ -2241,7 +2269,7 @@ $voltro_branch$`;
|
|
|
2241
2269
|
name: e.name,
|
|
2242
2270
|
steps: t
|
|
2243
2271
|
};
|
|
2244
|
-
},
|
|
2272
|
+
}, Us = (e) => typeof e == "object" && !!e && "__migration" in e && e.__migration === !0, Ws = T("_voltro_migrations", {
|
|
2245
2273
|
id: b({ prefix: "mig" }),
|
|
2246
2274
|
name: v(),
|
|
2247
2275
|
hash: v(),
|
|
@@ -2253,7 +2281,7 @@ $voltro_branch$`;
|
|
|
2253
2281
|
workflowRunId: v().nullable(),
|
|
2254
2282
|
createdAt: S().default("now"),
|
|
2255
2283
|
updatedAt: S().default("now").onUpdate("now")
|
|
2256
|
-
}).index(["status"]),
|
|
2284
|
+
}).index(["status"]), Gs = T("_voltro_seeds", {
|
|
2257
2285
|
id: b({ prefix: "seed" }),
|
|
2258
2286
|
name: v(),
|
|
2259
2287
|
lifecycle: v(),
|
|
@@ -2269,7 +2297,7 @@ $voltro_branch$`;
|
|
|
2269
2297
|
workflowRunId: v().nullable(),
|
|
2270
2298
|
createdAt: S().default("now"),
|
|
2271
2299
|
updatedAt: S().default("now").onUpdate("now")
|
|
2272
|
-
}).index(["lifecycle"]).index(["nextRunAt"]),
|
|
2300
|
+
}).index(["lifecycle"]).index(["nextRunAt"]), Ks = T("_voltro_migration_plans", {
|
|
2273
2301
|
id: b({ prefix: "plan" }),
|
|
2274
2302
|
fingerprint: v(),
|
|
2275
2303
|
liveFingerprint: v().nullable(),
|
|
@@ -2285,21 +2313,21 @@ $voltro_branch$`;
|
|
|
2285
2313
|
appliedAt: S().default("now"),
|
|
2286
2314
|
createdAt: S().default("now"),
|
|
2287
2315
|
updatedAt: S().default("now").onUpdate("now")
|
|
2288
|
-
}).index(["fingerprint"]).index(["environment"]),
|
|
2316
|
+
}).index(["fingerprint"]).index(["environment"]), qs = T("_voltro_idempotency", {
|
|
2289
2317
|
id: b({ prefix: "idem" }),
|
|
2290
2318
|
scope: v(),
|
|
2291
2319
|
key: v(),
|
|
2292
2320
|
status: v(),
|
|
2293
2321
|
response: i().nullable(),
|
|
2294
2322
|
createdAt: S().default("now")
|
|
2295
|
-
}).unique(["scope", "key"]).index(["createdAt"]),
|
|
2323
|
+
}).unique(["scope", "key"]).index(["createdAt"]), Js = T("_voltro_kv", {
|
|
2296
2324
|
id: b({ prefix: "kv" }),
|
|
2297
2325
|
key: v().unique(),
|
|
2298
2326
|
value: v().nullable(),
|
|
2299
2327
|
expiresAt: S().nullable(),
|
|
2300
2328
|
createdAt: S().default("now"),
|
|
2301
2329
|
updatedAt: S().default("now").onUpdate("now")
|
|
2302
|
-
}).index(["expiresAt"]),
|
|
2330
|
+
}).index(["expiresAt"]), Ys = T("_voltro_api_keys", {
|
|
2303
2331
|
id: b({ prefix: "apikey" }),
|
|
2304
2332
|
tenantId: v().nullable(),
|
|
2305
2333
|
name: v(),
|
|
@@ -2314,11 +2342,11 @@ $voltro_branch$`;
|
|
|
2314
2342
|
onBehalfOf: v().nullable(),
|
|
2315
2343
|
metadata: i().nullable(),
|
|
2316
2344
|
createdAt: S().default("now")
|
|
2317
|
-
}).index("byApiKeyTenant", ["tenantId"]),
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
], $ = "id",
|
|
2345
|
+
}).index("byApiKeyTenant", ["tenantId"]), Xs = [
|
|
2346
|
+
Ws,
|
|
2347
|
+
Gs,
|
|
2348
|
+
Ks
|
|
2349
|
+
], $ = "id", Zs = (e, t) => {
|
|
2322
2350
|
let n = p(e);
|
|
2323
2351
|
if (n === void 0) return t;
|
|
2324
2352
|
let r = n.fields[$]?.idScheme;
|
|
@@ -2333,7 +2361,7 @@ $voltro_branch$`;
|
|
|
2333
2361
|
...t,
|
|
2334
2362
|
[$]: i
|
|
2335
2363
|
};
|
|
2336
|
-
},
|
|
2364
|
+
}, Qs = (e, t) => t.map((t) => Zs(e, t)), $s = {
|
|
2337
2365
|
postgres: { maxBindParameters: 65535 },
|
|
2338
2366
|
mysql: { maxBindParameters: 65535 },
|
|
2339
2367
|
mariadb: { maxBindParameters: 65535 },
|
|
@@ -2343,49 +2371,49 @@ $voltro_branch$`;
|
|
|
2343
2371
|
},
|
|
2344
2372
|
sqlite: { maxBindParameters: 32766 },
|
|
2345
2373
|
turso: { maxBindParameters: 32766 }
|
|
2346
|
-
},
|
|
2374
|
+
}, ec = (e) => $s[e], tc = (e) => {
|
|
2347
2375
|
let t = /* @__PURE__ */ new Set();
|
|
2348
2376
|
for (let n of e) for (let e of Object.keys(n)) t.add(e);
|
|
2349
2377
|
return t.size;
|
|
2350
|
-
},
|
|
2378
|
+
}, nc = (e, t) => {
|
|
2351
2379
|
if (t === void 0 || e.length === 0) return [e];
|
|
2352
|
-
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));
|
|
2353
2381
|
if (e.length <= a) return [e];
|
|
2354
2382
|
let o = [];
|
|
2355
2383
|
for (let t = 0; t < e.length; t += a) o.push(e.slice(t, t + a));
|
|
2356
2384
|
return o;
|
|
2357
|
-
},
|
|
2385
|
+
}, rc = (e, t) => {
|
|
2358
2386
|
let n = [], r = t;
|
|
2359
2387
|
for (let [t, i] of Object.entries(e.fields)) {
|
|
2360
2388
|
let e = i;
|
|
2361
2389
|
e.nullable || e.hasDefault || e.idScheme !== void 0 || e.generatedAs !== void 0 || (r[t] === void 0 || r[t] === null) && n.push(t);
|
|
2362
2390
|
}
|
|
2363
2391
|
return n;
|
|
2364
|
-
},
|
|
2392
|
+
}, ic = (e, t) => {
|
|
2365
2393
|
let n = t;
|
|
2366
2394
|
return e.filter((e) => n[e] === void 0 || n[e] === null);
|
|
2367
|
-
},
|
|
2395
|
+
}, ac = (e, t, n) => e.insert(t.tableName, n), oc = (e, t, n, r) => e.upsert(t.tableName, n, {
|
|
2368
2396
|
conflictColumns: r.conflictColumns,
|
|
2369
2397
|
...r.update === void 0 ? {} : { update: r.update }
|
|
2370
|
-
}),
|
|
2398
|
+
}), sc = (e, t, n, r) => e.updateMany(t.tableName, n, { where: r.where }), cc = 512, lc = (e) => {
|
|
2371
2399
|
e.setMaxListeners(512);
|
|
2372
|
-
},
|
|
2400
|
+
}, uc = (e, t, n) => ({
|
|
2373
2401
|
_tag: "PrimaryKeyConflictError",
|
|
2374
2402
|
table: e,
|
|
2375
2403
|
key: t,
|
|
2376
2404
|
cause: n
|
|
2377
|
-
}),
|
|
2405
|
+
}), dc = (e) => typeof e == "object" && !!e && e._tag === "PrimaryKeyConflictError", fc = {
|
|
2378
2406
|
postgres: 5432,
|
|
2379
2407
|
mysql: 3306,
|
|
2380
2408
|
mariadb: 3306,
|
|
2381
2409
|
mssql: 1433
|
|
2382
|
-
},
|
|
2410
|
+
}, pc = /* @__PURE__ */ new Set([
|
|
2383
2411
|
"localhost",
|
|
2384
2412
|
"127.0.0.1",
|
|
2385
2413
|
"::1",
|
|
2386
2414
|
"[::1]",
|
|
2387
2415
|
"0.0.0.0"
|
|
2388
|
-
]),
|
|
2416
|
+
]), mc = (e) => {
|
|
2389
2417
|
let t = e.host, n = e.port, r = e.database;
|
|
2390
2418
|
if (e.url !== void 0 && e.url !== "") try {
|
|
2391
2419
|
let i = new URL(e.url);
|
|
@@ -2394,29 +2422,29 @@ $voltro_branch$`;
|
|
|
2394
2422
|
return;
|
|
2395
2423
|
}
|
|
2396
2424
|
if (t === void 0 || t === "" || r === void 0 || r === "") return;
|
|
2397
|
-
let i = n ??
|
|
2425
|
+
let i = n ?? fc[(e.dialect ?? "").toLowerCase()];
|
|
2398
2426
|
if (i === void 0 || !Number.isFinite(i)) return;
|
|
2399
2427
|
let a = t.toLowerCase();
|
|
2400
2428
|
return {
|
|
2401
|
-
host:
|
|
2429
|
+
host: pc.has(a) ? "localhost" : a,
|
|
2402
2430
|
port: i,
|
|
2403
2431
|
database: r.toLowerCase()
|
|
2404
2432
|
};
|
|
2405
|
-
},
|
|
2406
|
-
let t =
|
|
2407
|
-
if (t !== void 0) return
|
|
2408
|
-
},
|
|
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 = {
|
|
2409
2437
|
app: 3,
|
|
2410
2438
|
plugin: 2,
|
|
2411
2439
|
framework: 1
|
|
2412
|
-
},
|
|
2440
|
+
}, vc = /* @__PURE__ */ new Map(), yc = [], bc = () => [...yc], xc = (e) => {
|
|
2413
2441
|
if (!e.table || !e.timeColumn) throw Error("registerRetention: table + timeColumn are required");
|
|
2414
2442
|
if (!Number.isFinite(e.ttlMs) || e.ttlMs <= 0) throw Error(`registerRetention(${e.table}): ttlMs must be a positive number`);
|
|
2415
|
-
let t = e.source ?? "app", n =
|
|
2443
|
+
let t = e.source ?? "app", n = vc.get(e.table);
|
|
2416
2444
|
if (n !== void 0) {
|
|
2417
2445
|
let r = n.source ?? "app", i = n.ttlMs !== e.ttlMs || n.where !== void 0 != (e.where !== void 0);
|
|
2418
|
-
if (
|
|
2419
|
-
i &&
|
|
2446
|
+
if (_c[t] < _c[r]) {
|
|
2447
|
+
i && yc.push({
|
|
2420
2448
|
table: e.table,
|
|
2421
2449
|
kept: {
|
|
2422
2450
|
source: r,
|
|
@@ -2429,7 +2457,7 @@ $voltro_branch$`;
|
|
|
2429
2457
|
});
|
|
2430
2458
|
return;
|
|
2431
2459
|
}
|
|
2432
|
-
i && r !== t &&
|
|
2460
|
+
i && r !== t && yc.push({
|
|
2433
2461
|
table: e.table,
|
|
2434
2462
|
kept: {
|
|
2435
2463
|
source: t,
|
|
@@ -2441,35 +2469,35 @@ $voltro_branch$`;
|
|
|
2441
2469
|
}
|
|
2442
2470
|
});
|
|
2443
2471
|
}
|
|
2444
|
-
|
|
2472
|
+
vc.set(e.table, {
|
|
2445
2473
|
...e,
|
|
2446
2474
|
source: t
|
|
2447
2475
|
});
|
|
2448
|
-
},
|
|
2449
|
-
|
|
2450
|
-
},
|
|
2476
|
+
}, Sc = () => [...vc.values()], Cc = () => {
|
|
2477
|
+
vc.clear(), yc.length = 0;
|
|
2478
|
+
}, wc = async (e, t, n, r = 2e4) => {
|
|
2451
2479
|
let i = new Date(t - e.ttlMs), a = 0;
|
|
2452
2480
|
for (;;) {
|
|
2453
2481
|
let t = await n(e.table, e.timeColumn, i, r, e.where);
|
|
2454
2482
|
if (a += t, t < r) break;
|
|
2455
2483
|
}
|
|
2456
2484
|
return a;
|
|
2457
|
-
},
|
|
2485
|
+
}, Tc = (e, t) => {
|
|
2458
2486
|
let n = Number(e ?? String(t));
|
|
2459
2487
|
return (Number.isFinite(n) && n > 0 ? n : t) * 36e5;
|
|
2460
|
-
},
|
|
2488
|
+
}, Ec = "_voltro_cdc_offsets", Dc = T(Ec, {
|
|
2461
2489
|
id: b({ prefix: "cdcoff" }),
|
|
2462
2490
|
replicaId: v(),
|
|
2463
2491
|
streamName: v(),
|
|
2464
2492
|
binlogFile: v(),
|
|
2465
2493
|
binlogPosition: v(),
|
|
2466
2494
|
updatedAt: S()
|
|
2467
|
-
}).index(["replicaId"]),
|
|
2495
|
+
}).index(["replicaId"]), Oc = T(Ec, {
|
|
2468
2496
|
id: b({ prefix: "cdcoff" }),
|
|
2469
2497
|
replicaId: v(),
|
|
2470
2498
|
streamName: v(),
|
|
2471
2499
|
ctVersion: v(),
|
|
2472
2500
|
updatedAt: S()
|
|
2473
|
-
}).index(["replicaId"]),
|
|
2501
|
+
}).index(["replicaId"]), kc = "postgres";
|
|
2474
2502
|
//#endregion
|
|
2475
|
-
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 };
|