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