@voltro/database 0.54.0 → 0.56.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 +639 -2
- package/dist/{frameworkLiveTables-ChVR-C5F.js → frameworkLiveTables-CwDemhjW.js} +139 -139
- package/dist/index.d.ts +328 -3
- package/dist/index.js +788 -693
- package/dist/sql.d.ts +15 -24
- package/dist/sql.js +873 -853
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { $ as e, $t as t, A as n, At as r, B as i, Bt as a, C as o, Ct as s, D as c, Dt as l, E as u, Et as d, F as f, Ft as p, G as m, Gt as h, H as g, Ht as
|
|
2
|
-
import { timestampMs as
|
|
3
|
-
import { Cause as
|
|
4
|
-
import { AsyncLocalStorage as It } from "node:async_hooks";
|
|
1
|
+
import { $ as e, $t as t, A as n, At as r, B as i, Bt as a, C as o, Ct as s, D as c, Dt as l, E as u, Et as d, F as f, Ft as p, G as m, Gt as h, H as g, Ht as _, I as ee, It as te, J as ne, Jt as v, K as y, Kt as re, L as b, Lt as ie, M as ae, Mt as oe, N as x, Nt as se, O as ce, Ot as le, P as ue, Pt as de, Q as fe, Qt as pe, R as me, Rt as he, S as ge, St as _e, T as ve, Tt as ye, U as be, Ut as S, V as xe, Vt as Se, W as Ce, Wt as we, X as Te, Xt as Ee, Y as De, Yt as Oe, Z as ke, Zt as Ae, _ as je, _t as Me, a as Ne, at as Pe, b as Fe, bt as Ie, c as Le, ct as Re, d as ze, dt as Be, en as C, et as Ve, f as He, ft as Ue, g as We, gt as Ge, h as w, ht as Ke, it as T, j as qe, jt as Je, k as Ye, kt as Xe, l as Ze, lt as Qe, m as $e, mt as et, n as tt, nt, o as rt, ot as it, p as at, pt as ot, q as E, qt as st, r as ct, rt as lt, s as ut, st as dt, t as ft, tn as pt, tt as mt, u as ht, ut as gt, v as _t, vt, w as yt, wt as bt, x as xt, xt as St, y as Ct, yt as wt, z as Tt, zt as Et } from "./frameworkLiveTables-CwDemhjW.js";
|
|
2
|
+
import { timestampMs as Dt, timestampMsOrNull as Ot } from "./wire.js";
|
|
3
|
+
import { Cause as kt, Chunk as At, Data as jt, Effect as D, Exit as Mt, Metric as O, MetricBoundaries as Nt, Option as k, Runtime as Pt, Schedule as Ft, Schema as A, Stream as It } from "effect";
|
|
5
4
|
import { createHash as Lt } from "node:crypto";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
5
|
+
import { AsyncLocalStorage as Rt } from "node:async_hooks";
|
|
6
|
+
import { TransactionConnection as zt } from "@effect/sql/SqlClient";
|
|
7
|
+
import { ansi as j } from "@voltro/logger";
|
|
8
|
+
import { SqlClient as Bt } from "@effect/sql";
|
|
9
9
|
//#region src/actorSnapshot.ts
|
|
10
|
-
var
|
|
10
|
+
var Vt = (e) => typeof e == "string" && e !== "" ? e : null, Ht = 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 Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = 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: Vt(r.kind) ?? n,
|
|
27
|
+
displayName: Vt(r.displayName),
|
|
28
|
+
email: Vt(r.email)
|
|
29
29
|
};
|
|
30
30
|
} catch {
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
|
-
},
|
|
33
|
+
}, Ut = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqlite", Wt = (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
|
+
}, Gt = (e, t, n) => {
|
|
38
|
+
if (!Ut(n) || !t) return e;
|
|
39
|
+
let r = Wt(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 Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = 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
|
+
}, Kt = (e, t, n) => {
|
|
48
|
+
if (!Ut(n) || !t) return e;
|
|
49
|
+
let r = Wt(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 Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
58
58
|
}
|
|
59
59
|
return t ?? e;
|
|
60
60
|
});
|
|
61
|
-
},
|
|
61
|
+
}, qt = "enc:v1:", Jt = class extends Error {
|
|
62
62
|
_tag = "FieldDecryptionError";
|
|
63
63
|
table;
|
|
64
64
|
column;
|
|
@@ -66,7 +66,7 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = 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
|
+
}, Yt = (e) => typeof e == "object" && !!e && e._tag === "FieldDecryptionError", Xt = (e) => typeof e == "string" && e.startsWith("enc:v1:"), Zt = (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 Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
74
74
|
"uuid",
|
|
75
75
|
"email",
|
|
76
76
|
"url"
|
|
77
|
-
]),
|
|
77
|
+
]), $t = (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
|
+
}, en = (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
|
+
}, tn = (e, t) => e.fields[t]?.type, nn = (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
|
+
}, rn = (e, t, n) => {
|
|
97
97
|
if (!t) return e;
|
|
98
|
-
let r =
|
|
98
|
+
let r = nn(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 || Xt(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] = Zt(n, r);
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
return i;
|
|
109
|
-
},
|
|
109
|
+
}, an = (e, t, n, r) => {
|
|
110
110
|
if (!t) return e;
|
|
111
|
-
let i =
|
|
111
|
+
let i = nn(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 (Xt(i)) {
|
|
119
119
|
s ??= { ...e };
|
|
120
120
|
try {
|
|
121
|
-
s[c] =
|
|
121
|
+
s[c] = $t(n, i, tn(t, c));
|
|
122
122
|
} catch (e) {
|
|
123
123
|
let t = String(e?.message ?? e);
|
|
124
124
|
if (a === "null") {
|
|
@@ -129,7 +129,7 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
129
129
|
});
|
|
130
130
|
continue;
|
|
131
131
|
}
|
|
132
|
-
throw new
|
|
132
|
+
throw new Jt({
|
|
133
133
|
table: o,
|
|
134
134
|
column: c,
|
|
135
135
|
reason: t
|
|
@@ -139,125 +139,125 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
139
139
|
}
|
|
140
140
|
return s ?? e;
|
|
141
141
|
});
|
|
142
|
-
},
|
|
142
|
+
}, on = (e) => {
|
|
143
143
|
let t = e;
|
|
144
|
-
for (let e = 0; e < 4 &&
|
|
144
|
+
for (let e = 0; e < 4 && Pt.isFiberFailure(t); e++) t = kt.squash(t[Pt.FiberFailureCauseId]);
|
|
145
145
|
return t;
|
|
146
|
-
},
|
|
147
|
-
if (t >= 4 || !
|
|
148
|
-
let n = e[
|
|
149
|
-
if (r.length === 0) return [
|
|
146
|
+
}, sn = (e, t = 0) => {
|
|
147
|
+
if (t >= 4 || !Pt.isFiberFailure(e)) return [e];
|
|
148
|
+
let n = e[Pt.FiberFailureCauseId], r = [...kt.failures(n), ...kt.defects(n)];
|
|
149
|
+
if (r.length === 0) return [kt.squash(n)];
|
|
150
150
|
let i = [];
|
|
151
|
-
for (let e of r.slice(0, 8)) i.push(...
|
|
151
|
+
for (let e of r.slice(0, 8)) i.push(...sn(e, t + 1));
|
|
152
152
|
return i;
|
|
153
|
-
},
|
|
154
|
-
let t = {}, n = [], r =
|
|
153
|
+
}, cn = (e) => e.dbCode !== void 0 || e.dbErrno !== void 0 || e.dbNumber !== void 0 || e.dbSqlState !== void 0 || e.dbConstraint !== void 0, ln = (e) => {
|
|
154
|
+
let t = {}, n = [], r = on(e);
|
|
155
155
|
for (let e = 0; e < 8 && typeof r == "object" && r; e++) {
|
|
156
156
|
let e = r;
|
|
157
157
|
t.dbCode === void 0 && (typeof e.code == "string" || typeof e.code == "number") && (t.dbCode = e.code), t.dbErrno === void 0 && typeof e.errno == "number" && (t.dbErrno = e.errno), t.dbNumber === void 0 && typeof e.number == "number" && (t.dbNumber = e.number), t.dbSqlState === void 0 && typeof e.sqlState == "string" && (t.dbSqlState = e.sqlState), t.dbBindings === void 0 && typeof e.voltroBindings == "string" && (t.dbBindings = e.voltroBindings), t.dbStatement === void 0 && typeof e.sql == "string" && e.sql.includes("?") && (t.dbStatement = e.sql, t.dbPlaceholders = (e.sql.match(/\?/g) ?? []).length), t.dbFatal === void 0 && typeof e.fatal == "boolean" && (t.dbFatal = e.fatal), t.dbConstraint === void 0 && typeof e.constraint == "string" && (t.dbConstraint = e.constraint), t.dbTable === void 0 && typeof e.table == "string" && (t.dbTable = e.table), t.dbColumn === void 0 && typeof e.column == "string" && (t.dbColumn = e.column), t.dbSchema === void 0 && typeof e.schema == "string" && (t.dbSchema = e.schema);
|
|
158
158
|
let i = e.sqlMessage ?? e.detail;
|
|
159
159
|
t.dbMessage === void 0 && typeof i == "string" && (t.dbMessage = i);
|
|
160
160
|
let a = typeof e.constructor == "function" ? e.constructor.name : void 0, o = typeof e._tag == "string" && e._tag || typeof e.name == "string" && e.name || (typeof a == "string" && a !== "Object" ? a : void 0), s = typeof e.message == "string" ? e.message : void 0;
|
|
161
|
-
(o || s) && n.push(`${o || "Error"}${s ? `: ${s.slice(0, 200)}` : ""}`), r =
|
|
161
|
+
(o || s) && n.push(`${o || "Error"}${s ? `: ${s.slice(0, 200)}` : ""}`), r = on(e.cause);
|
|
162
162
|
}
|
|
163
163
|
return n.length > 0 && (t.dbCauseChain = n.join(" ← "), t.dbMessage === void 0 && (t.dbMessage = n[n.length - 1])), t;
|
|
164
|
-
},
|
|
165
|
-
let t =
|
|
164
|
+
}, un = (e) => {
|
|
165
|
+
let t = sn(e).map(ln);
|
|
166
166
|
if (t.length <= 1) return t[0] ?? {};
|
|
167
|
-
let n = t.find(
|
|
167
|
+
let n = t.find(cn) ?? t[0], r = t.filter((e) => e !== n).map((e) => e.dbCauseChain).filter((e) => typeof e == "string");
|
|
168
168
|
if (r.length === 0) return n;
|
|
169
169
|
let i = typeof n.dbCauseChain == "string" ? n.dbCauseChain : void 0;
|
|
170
170
|
return {
|
|
171
171
|
...n,
|
|
172
172
|
dbCauseChain: [i, ...r].filter(Boolean).join(" ‖ ")
|
|
173
173
|
};
|
|
174
|
-
},
|
|
174
|
+
}, dn = /^[A-Za-z_][A-Za-z0-9_$]*$/, M = (e) => e !== void 0 && e.length <= 128 && dn.test(e) ? e : void 0, fn = (e) => e === void 0 ? void 0 : e.split(".").pop() ?? e, N = (e, ...t) => {
|
|
175
175
|
for (let n of t) {
|
|
176
176
|
let t = n.exec(e);
|
|
177
177
|
if (t?.[1] !== void 0) return t[1];
|
|
178
178
|
}
|
|
179
|
-
},
|
|
179
|
+
}, pn = (e, t) => {
|
|
180
180
|
let n = e.dbCode, r = e.dbErrno, i = e.dbNumber, a = typeof e.dbMessage == "string" ? e.dbMessage : "", o = `${typeof e.dbCauseChain == "string" ? e.dbCauseChain : ""} ${a}`;
|
|
181
181
|
if (n === "23503") {
|
|
182
|
-
let t =
|
|
182
|
+
let t = M(e.dbConstraint);
|
|
183
183
|
return {
|
|
184
184
|
kind: /is still referenced from table/i.test(o) ? "foreignKeyInUse" : "foreignKey",
|
|
185
185
|
...t === void 0 ? {} : { constraint: t }
|
|
186
186
|
};
|
|
187
187
|
}
|
|
188
188
|
if (n === "23505") {
|
|
189
|
-
let t =
|
|
189
|
+
let t = M(e.dbConstraint);
|
|
190
190
|
return {
|
|
191
191
|
kind: "unique",
|
|
192
192
|
...t === void 0 ? {} : { constraint: t }
|
|
193
193
|
};
|
|
194
194
|
}
|
|
195
195
|
if (n === "23502") {
|
|
196
|
-
let t =
|
|
196
|
+
let t = M(e.dbColumn);
|
|
197
197
|
return {
|
|
198
198
|
kind: "notNull",
|
|
199
199
|
...t === void 0 ? {} : { column: t }
|
|
200
200
|
};
|
|
201
201
|
}
|
|
202
202
|
if (n === "23514") {
|
|
203
|
-
let t =
|
|
203
|
+
let t = M(e.dbConstraint);
|
|
204
204
|
return {
|
|
205
205
|
kind: "check",
|
|
206
206
|
...t === void 0 ? {} : { constraint: t }
|
|
207
207
|
};
|
|
208
208
|
}
|
|
209
209
|
if (r === 1452 || r === 1451) {
|
|
210
|
-
let e =
|
|
210
|
+
let e = M(N(o, /CONSTRAINT `([^`]+)`/));
|
|
211
211
|
return {
|
|
212
212
|
kind: r === 1451 ? "foreignKeyInUse" : "foreignKey",
|
|
213
213
|
...e === void 0 ? {} : { constraint: e }
|
|
214
214
|
};
|
|
215
215
|
}
|
|
216
216
|
if (r === 1062) {
|
|
217
|
-
let e =
|
|
217
|
+
let e = M(fn(N(o, /for key '([^']+)'/)));
|
|
218
218
|
return {
|
|
219
219
|
kind: "unique",
|
|
220
220
|
...e === void 0 ? {} : { constraint: e }
|
|
221
221
|
};
|
|
222
222
|
}
|
|
223
223
|
if (r === 1048 || r === 1364) {
|
|
224
|
-
let e =
|
|
224
|
+
let e = M(N(o, /Column '([^']+)' cannot be null/, /Field '([^']+)' doesn't have a default value/));
|
|
225
225
|
return {
|
|
226
226
|
kind: "notNull",
|
|
227
227
|
...e === void 0 ? {} : { column: e }
|
|
228
228
|
};
|
|
229
229
|
}
|
|
230
230
|
if (r === 3819 || r === 4025) {
|
|
231
|
-
let e =
|
|
231
|
+
let e = M(N(o, /Check constraint '([^']+)'/, /CONSTRAINT `([^`]+)` failed/));
|
|
232
232
|
return {
|
|
233
233
|
kind: "check",
|
|
234
234
|
...e === void 0 ? {} : { constraint: e }
|
|
235
235
|
};
|
|
236
236
|
}
|
|
237
237
|
if (i === 547) {
|
|
238
|
-
let e =
|
|
238
|
+
let e = N(o, /(?:FOREIGN KEY|REFERENCE) constraint "([^"]+)"/), t = N(o, /CHECK constraint "([^"]+)"/);
|
|
239
239
|
if (t !== void 0 && e === void 0) {
|
|
240
|
-
let e =
|
|
240
|
+
let e = M(t);
|
|
241
241
|
return {
|
|
242
242
|
kind: "check",
|
|
243
243
|
...e === void 0 ? {} : { constraint: e }
|
|
244
244
|
};
|
|
245
245
|
}
|
|
246
|
-
let n = /REFERENCE constraint/.test(o), r =
|
|
246
|
+
let n = /REFERENCE constraint/.test(o), r = M(e);
|
|
247
247
|
return {
|
|
248
248
|
kind: n ? "foreignKeyInUse" : "foreignKey",
|
|
249
249
|
...r === void 0 ? {} : { constraint: r }
|
|
250
250
|
};
|
|
251
251
|
}
|
|
252
252
|
if (i === 2627 || i === 2601) {
|
|
253
|
-
let e =
|
|
253
|
+
let e = M(N(o, /(?:UNIQUE KEY|PRIMARY KEY) constraint '([^']+)'/, /index '([^']+)'/));
|
|
254
254
|
return {
|
|
255
255
|
kind: "unique",
|
|
256
256
|
...e === void 0 ? {} : { constraint: e }
|
|
257
257
|
};
|
|
258
258
|
}
|
|
259
259
|
if (i === 515) {
|
|
260
|
-
let e =
|
|
260
|
+
let e = M(N(o, /Cannot insert the value NULL into column '([^']+)'/));
|
|
261
261
|
return {
|
|
262
262
|
kind: "notNull",
|
|
263
263
|
...e === void 0 ? {} : { column: e }
|
|
@@ -265,34 +265,34 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
265
265
|
}
|
|
266
266
|
if (n === "SQLITE_CONSTRAINT_FOREIGNKEY") return { kind: t === "delete" || t === "deleteMany" || t === "hardDelete" ? "foreignKeyInUse" : "foreignKey" };
|
|
267
267
|
if (n === "SQLITE_CONSTRAINT_UNIQUE" || n === "SQLITE_CONSTRAINT_PRIMARYKEY") {
|
|
268
|
-
let e =
|
|
268
|
+
let e = M(fn(N(o, /UNIQUE constraint failed: ([^,\s]+)/)));
|
|
269
269
|
return {
|
|
270
270
|
kind: "unique",
|
|
271
271
|
...e === void 0 ? {} : { column: e }
|
|
272
272
|
};
|
|
273
273
|
}
|
|
274
274
|
if (n === "SQLITE_CONSTRAINT_NOTNULL") {
|
|
275
|
-
let e =
|
|
275
|
+
let e = M(fn(N(o, /NOT NULL constraint failed: ([^,\s]+)/)));
|
|
276
276
|
return {
|
|
277
277
|
kind: "notNull",
|
|
278
278
|
...e === void 0 ? {} : { column: e }
|
|
279
279
|
};
|
|
280
280
|
}
|
|
281
281
|
if (n === "SQLITE_CONSTRAINT_CHECK") {
|
|
282
|
-
let e =
|
|
282
|
+
let e = M(N(a, /CHECK constraint failed: (.+)$/));
|
|
283
283
|
return {
|
|
284
284
|
kind: "check",
|
|
285
285
|
...e === void 0 ? {} : { constraint: e }
|
|
286
286
|
};
|
|
287
287
|
}
|
|
288
|
-
}, pn = (e) => {
|
|
289
|
-
let t = fn(e)?.kind;
|
|
290
|
-
return t === "foreignKey" || t === "foreignKeyInUse";
|
|
291
288
|
}, mn = (e) => {
|
|
289
|
+
let t = pn(e)?.kind;
|
|
290
|
+
return t === "foreignKey" || t === "foreignKeyInUse";
|
|
291
|
+
}, hn = (e) => {
|
|
292
292
|
let t = e.dbCode, n = e.dbErrno;
|
|
293
293
|
return t === "57014" || n === 3024 || n === 1969 || t === "ETIMEOUT" || t === "SQLITE_INTERRUPT";
|
|
294
|
-
},
|
|
295
|
-
let t =
|
|
294
|
+
}, gn = (e) => {
|
|
295
|
+
let t = un(e), n = [
|
|
296
296
|
t.dbCode === void 0 ? void 0 : `code=${String(t.dbCode)}`,
|
|
297
297
|
t.dbErrno === void 0 ? void 0 : `errno=${String(t.dbErrno)}`,
|
|
298
298
|
t.dbNumber === void 0 ? void 0 : `number=${String(t.dbNumber)}`,
|
|
@@ -301,7 +301,7 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
301
301
|
t.dbPlaceholders === void 0 ? void 0 : `placeholders=${String(t.dbPlaceholders)}`
|
|
302
302
|
].filter((e) => e !== void 0), r = typeof e?.message == "string" ? e.message : void 0, i = typeof t.dbMessage == "string" ? t.dbMessage : void 0, a = i === void 0 ? void 0 : n.length > 0 || i !== r && i !== `Error: ${String(r)}` ? i : void 0, o = typeof t.dbBindings == "string" ? `\n bindings: ${t.dbBindings}` : "", s = typeof t.dbStatement == "string" ? `\n statement: ${t.dbStatement.length <= 400 ? t.dbStatement : `${t.dbStatement.slice(0, 400)}…`}` : "";
|
|
303
303
|
if (a !== void 0 || n.length !== 0) return [a, n.length > 0 ? `[${n.join(" ")}]` : void 0].filter((e) => e !== void 0 && e !== "").join(" ") + s + o;
|
|
304
|
-
},
|
|
304
|
+
}, _n = (e) => Object.entries(e).map(([e, t]) => `${e}:${vn(t)}`).join(" "), vn = (e) => {
|
|
305
305
|
if (e === null) return "null";
|
|
306
306
|
if (e === void 0) return "undefined";
|
|
307
307
|
if (typeof e == "bigint") return "bigint";
|
|
@@ -311,62 +311,62 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
311
311
|
if (globalThis.Buffer !== void 0 && globalThis.Buffer.isBuffer(e)) return "Buffer";
|
|
312
312
|
let t = e.constructor?.name;
|
|
313
313
|
return typeof t == "string" && t !== "" ? t : "Object";
|
|
314
|
-
},
|
|
314
|
+
}, yn = (e) => {
|
|
315
315
|
let t = (() => {
|
|
316
316
|
switch (e.type) {
|
|
317
317
|
case "id":
|
|
318
318
|
case "reference":
|
|
319
319
|
case "text":
|
|
320
|
-
case "enum": return
|
|
320
|
+
case "enum": return A.String;
|
|
321
321
|
case "integer":
|
|
322
322
|
case "real":
|
|
323
|
-
case "decimal": return
|
|
324
|
-
case "boolean": return
|
|
323
|
+
case "decimal": return A.Number;
|
|
324
|
+
case "boolean": return A.Boolean;
|
|
325
325
|
case "timestamp":
|
|
326
|
-
case "date": return
|
|
327
|
-
case "bigint": return
|
|
328
|
-
case "bytes": return
|
|
329
|
-
case "array": return
|
|
330
|
-
case "interval": return
|
|
331
|
-
default: return
|
|
326
|
+
case "date": return Dt;
|
|
327
|
+
case "bigint": return A.BigInt;
|
|
328
|
+
case "bytes": return A.Uint8ArrayFromBase64;
|
|
329
|
+
case "array": return A.Array(A.Unknown);
|
|
330
|
+
case "interval": return A.String;
|
|
331
|
+
default: return A.Unknown;
|
|
332
332
|
}
|
|
333
333
|
})();
|
|
334
|
-
return e.nullable === !0 ?
|
|
335
|
-
},
|
|
334
|
+
return e.nullable === !0 ? A.NullOr(t) : t;
|
|
335
|
+
}, bn = (e, t) => {
|
|
336
336
|
let n = new Set(t?.omit ?? []), r = {};
|
|
337
|
-
for (let [t, i] of Object.entries(e.fields)) n.has(t) || (r[t] =
|
|
338
|
-
return
|
|
339
|
-
},
|
|
337
|
+
for (let [t, i] of Object.entries(e.fields)) n.has(t) || (r[t] = yn(i));
|
|
338
|
+
return A.Struct(r);
|
|
339
|
+
}, xn = (e) => typeof e == "function" ? e : () => e, Sn = (e, t) => ({
|
|
340
340
|
kind: "one",
|
|
341
|
-
target:
|
|
341
|
+
target: xn(e),
|
|
342
342
|
...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
|
|
343
343
|
...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
|
|
344
|
-
}),
|
|
344
|
+
}), Cn = (e, t) => ({
|
|
345
345
|
kind: "many",
|
|
346
|
-
target:
|
|
346
|
+
target: xn(e),
|
|
347
347
|
...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
|
|
348
348
|
...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
|
|
349
|
-
}),
|
|
349
|
+
}), wn = (e, t) => ({
|
|
350
350
|
kind: "manyToMany",
|
|
351
|
-
target:
|
|
352
|
-
through:
|
|
351
|
+
target: xn(e),
|
|
352
|
+
through: xn(t.through),
|
|
353
353
|
sourceKey: t.sourceKey,
|
|
354
354
|
targetKey: t.targetKey
|
|
355
|
-
}),
|
|
356
|
-
one:
|
|
357
|
-
many:
|
|
358
|
-
manyToMany:
|
|
359
|
-
},
|
|
355
|
+
}), Tn = {
|
|
356
|
+
one: Sn,
|
|
357
|
+
many: Cn,
|
|
358
|
+
manyToMany: wn
|
|
359
|
+
}, En = (e, t) => {
|
|
360
360
|
let n = typeof e == "function" ? e : () => e;
|
|
361
361
|
return {
|
|
362
362
|
source: n,
|
|
363
|
-
relations: t(
|
|
363
|
+
relations: t(Tn, n())
|
|
364
364
|
};
|
|
365
|
-
},
|
|
365
|
+
}, Dn = (e) => {
|
|
366
366
|
if (typeof e != "object" || !e) return !1;
|
|
367
367
|
let t = e;
|
|
368
368
|
return typeof t.source != "function" || typeof t.relations != "object" || t.relations === null ? !1 : Object.keys(t.relations).length === 0;
|
|
369
|
-
},
|
|
369
|
+
}, On = (e) => {
|
|
370
370
|
if (typeof e != "object" || !e) return !1;
|
|
371
371
|
let t = e;
|
|
372
372
|
if (typeof t.source != "function" || typeof t.relations != "object" || t.relations === null) return !1;
|
|
@@ -375,7 +375,7 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
375
375
|
let t = e?.kind;
|
|
376
376
|
return t === "one" || t === "many" || t === "manyToMany";
|
|
377
377
|
});
|
|
378
|
-
},
|
|
378
|
+
}, kn = Sn, An = Cn, jn = wn, P = (e, t, n) => {
|
|
379
379
|
let r = [];
|
|
380
380
|
for (let [n, i] of Object.entries(e.fields)) i.type === "reference" && i.references?.()?.tableName === t && r.push(n);
|
|
381
381
|
if (r.length === 0) throw Error(`relation '${n}': no reference() column on '${e.tableName}' points at '${t}'. Either add one or pass an explicit { foreignKey: '<column>' }.`);
|
|
@@ -400,10 +400,10 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
400
400
|
let t = Nn(e, n.foreignKey);
|
|
401
401
|
throw Error(`${r}: foreignKey '${n.foreignKey}' is not a column on the target table '${i.tableName}'.` + (t ? ` It IS a column on the source '${e.tableName}' — you want { sourceKey: '${n.foreignKey}' }. foreignKey names the column on the TARGET that points back at this table; sourceKey names the column on THIS table that holds the target's id.` : ` Columns on '${i.tableName}': ${Pn(i)}.`));
|
|
402
402
|
}
|
|
403
|
-
}, In = Symbol.for("@voltro/database/relationsRegistry"), Ln = globalThis,
|
|
404
|
-
let t = e.source(), n =
|
|
403
|
+
}, In = Symbol.for("@voltro/database/relationsRegistry"), Ln = globalThis, F = Ln[In] ?? (Ln[In] = /* @__PURE__ */ new Map()), Rn = (e) => {
|
|
404
|
+
let t = e.source(), n = F.get(t.tableName);
|
|
405
405
|
if (n === void 0) {
|
|
406
|
-
|
|
406
|
+
F.set(t.tableName, new Map(Object.entries(e.relations)));
|
|
407
407
|
return;
|
|
408
408
|
}
|
|
409
409
|
for (let [r, i] of Object.entries(e.relations)) {
|
|
@@ -415,26 +415,26 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
415
415
|
}
|
|
416
416
|
}, zn = (e) => {
|
|
417
417
|
let t = 0;
|
|
418
|
-
for (let n of Object.values(e))
|
|
418
|
+
for (let n of Object.values(e)) On(n) && (Rn(n), t += 1);
|
|
419
419
|
return t;
|
|
420
420
|
}, Bn = (e) => {
|
|
421
|
-
let t =
|
|
421
|
+
let t = F.get(e);
|
|
422
422
|
if (t !== void 0) return Object.fromEntries(t);
|
|
423
|
-
}, Vn = (e, t) =>
|
|
423
|
+
}, Vn = (e, t) => F.get(e)?.get(t), Hn = () => {
|
|
424
424
|
let e = [];
|
|
425
|
-
for (let [t, n] of
|
|
425
|
+
for (let [t, n] of F) for (let [r, i] of n) e.push({
|
|
426
426
|
source: t,
|
|
427
427
|
name: r,
|
|
428
428
|
relation: i
|
|
429
429
|
});
|
|
430
430
|
return e;
|
|
431
431
|
}, Un = () => {
|
|
432
|
-
for (let [e, t] of
|
|
433
|
-
let n =
|
|
432
|
+
for (let [e, t] of F) {
|
|
433
|
+
let n = E(e);
|
|
434
434
|
if (n !== void 0) for (let [e, r] of t) Fn(n, e, r);
|
|
435
435
|
}
|
|
436
436
|
}, Wn = () => {
|
|
437
|
-
|
|
437
|
+
F.clear();
|
|
438
438
|
}, Gn = 4, Kn = (e) => Object.keys(e.fields), qn = (e, t) => Object.prototype.hasOwnProperty.call(e.fields, t), Jn = (e, t) => {
|
|
439
439
|
let n = [];
|
|
440
440
|
for (let [r, i] of Object.entries(e.fields)) i.type === "reference" && i.references?.()?.tableName === t && n.push(r);
|
|
@@ -482,7 +482,7 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
482
482
|
});
|
|
483
483
|
return n;
|
|
484
484
|
}, Zn = (e) => `${e.table}\u0000${e.hops.map((e) => `${e.table}.${e.foreignKey}<-${e.parentKey}`).join("|")}`, Qn = (e) => {
|
|
485
|
-
let t = e.tables ??
|
|
485
|
+
let t = e.tables ?? Ce(), n = e.relations ?? Hn(), r = e.maxDepth ?? 4, i = new Set(e.exclude ?? []), a = new Map(t.map((e) => [e.tableName, e])), o = [];
|
|
486
486
|
if (!a.has(e.subjectTable)) return {
|
|
487
487
|
subjectTable: e.subjectTable,
|
|
488
488
|
paths: [],
|
|
@@ -589,7 +589,7 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
589
589
|
}
|
|
590
590
|
}, ar = (e, t, n) => {
|
|
591
591
|
if (e.length === 0) return e;
|
|
592
|
-
let r =
|
|
592
|
+
let r = E(t);
|
|
593
593
|
if (r === void 0) return e;
|
|
594
594
|
let i = r.fields, a = [];
|
|
595
595
|
for (let [e, t] of Object.entries(i)) a.push({
|
|
@@ -609,7 +609,7 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
609
609
|
default: return e;
|
|
610
610
|
}
|
|
611
611
|
}, sr = (e, t, n = ["json", "array"]) => {
|
|
612
|
-
let r =
|
|
612
|
+
let r = E(t);
|
|
613
613
|
if (r === void 0) return e;
|
|
614
614
|
let i = r.fields, a = null;
|
|
615
615
|
for (let [t, r] of Object.entries(i)) if (n.includes(r.type) && t in e) {
|
|
@@ -654,15 +654,15 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
654
654
|
}, fr = async (e, t, n, r, i, a) => {
|
|
655
655
|
let o = n.target(), s = n.sourceKey ?? gr(i, o.tableName);
|
|
656
656
|
if (s !== void 0) {
|
|
657
|
-
let n =
|
|
657
|
+
let n = _r(e, s), i = n.length === 0 ? [] : await vr(o, "id", n, r, a), c = new Map(i.map((e) => [e.id, e]));
|
|
658
658
|
for (let n of e) {
|
|
659
659
|
let e = n[s];
|
|
660
660
|
n[t] = e == null ? null : c.get(e) ?? null;
|
|
661
661
|
}
|
|
662
|
-
await
|
|
662
|
+
await yr(i, r.with, o, a);
|
|
663
663
|
return;
|
|
664
664
|
}
|
|
665
|
-
let c = n.foreignKey ??
|
|
665
|
+
let c = n.foreignKey ?? P(o, i.tableName, t), l = n.sourceKey ?? "id", u = _r(e, l), d = u.length === 0 ? [] : await vr(o, c, u, r, a), f = /* @__PURE__ */ new Map();
|
|
666
666
|
for (let e of d) {
|
|
667
667
|
let n = e[c];
|
|
668
668
|
if (f.has(n)) throw new cr(lr({
|
|
@@ -678,9 +678,9 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
678
678
|
let e = n[l];
|
|
679
679
|
n[t] = e == null ? null : f.get(e) ?? null;
|
|
680
680
|
}
|
|
681
|
-
await
|
|
681
|
+
await yr(d, r.with, o, a);
|
|
682
682
|
}, pr = async (e, t, n, r, i, a) => {
|
|
683
|
-
let o = n.target(), s = n.foreignKey ??
|
|
683
|
+
let o = n.target(), s = n.foreignKey ?? P(o, i.tableName, t), c = n.sourceKey ?? "id", l = _r(e, c), u = mr(r), d = l.length === 0 ? [] : await vr(o, s, l, u, a), f = /* @__PURE__ */ new Map();
|
|
684
684
|
for (let e of d) {
|
|
685
685
|
let t = e[s], n = f.get(t);
|
|
686
686
|
n ? n.push(e) : f.set(t, [e]);
|
|
@@ -696,12 +696,12 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
696
696
|
let e = n[c];
|
|
697
697
|
n[t] = f.get(e) ?? [];
|
|
698
698
|
}
|
|
699
|
-
await
|
|
699
|
+
await yr(d, r.with, o, a);
|
|
700
700
|
}, mr = (e) => {
|
|
701
701
|
let { limit: t, offset: n, ...r } = e;
|
|
702
702
|
return r;
|
|
703
703
|
}, hr = async (e, t, n, r, i, a) => {
|
|
704
|
-
let o = n.target(), s = n.through(), c =
|
|
704
|
+
let o = n.target(), s = n.through(), c = _r(e, "id");
|
|
705
705
|
if (c.length === 0) {
|
|
706
706
|
for (let n of e) n[t] = [];
|
|
707
707
|
return;
|
|
@@ -722,8 +722,8 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
722
722
|
for (let n of e) n[t] = [];
|
|
723
723
|
return;
|
|
724
724
|
}
|
|
725
|
-
let f = await
|
|
726
|
-
await
|
|
725
|
+
let f = await vr(o, "id", _r(d, n.targetKey), r, a), p = new Map(f.map((e) => [e.id, e]));
|
|
726
|
+
await yr(f, r.with, o, a);
|
|
727
727
|
let m = r.junction === void 0 ? void 0 : r.junction === !0 ? Object.keys(s.fields) : r.junction, h = /* @__PURE__ */ new Map();
|
|
728
728
|
for (let e of d) {
|
|
729
729
|
let t = e[n.sourceKey], r = e[n.targetKey], i = p.get(r);
|
|
@@ -737,14 +737,14 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
737
737
|
for (let n of e) n[t] = h.get(n.id) ?? [];
|
|
738
738
|
}, gr = (e, t) => {
|
|
739
739
|
for (let [n, r] of Object.entries(e.fields)) if (r.type === "reference" && r.references?.()?.tableName === t) return n;
|
|
740
|
-
},
|
|
740
|
+
}, _r = (e, t) => {
|
|
741
741
|
let n = /* @__PURE__ */ new Set();
|
|
742
742
|
for (let r of e) {
|
|
743
743
|
let e = r[t];
|
|
744
744
|
e != null && n.add(e);
|
|
745
745
|
}
|
|
746
746
|
return [...n];
|
|
747
|
-
},
|
|
747
|
+
}, vr = (e, t, n, r, i) => {
|
|
748
748
|
let a = {
|
|
749
749
|
column: t,
|
|
750
750
|
op: "in",
|
|
@@ -758,66 +758,66 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
758
758
|
skip: r.offset,
|
|
759
759
|
projection: void 0
|
|
760
760
|
});
|
|
761
|
-
},
|
|
761
|
+
}, yr = async (e, t, n, r) => {
|
|
762
762
|
t !== void 0 && e.length !== 0 && (await ur(e, t, n, r)).forEach((t, n) => {
|
|
763
763
|
let r = e[n];
|
|
764
764
|
for (let [e, n] of Object.entries(t)) e in r || (r[e] = n);
|
|
765
765
|
});
|
|
766
|
-
},
|
|
766
|
+
}, br = (e) => e.eager !== void 0 && Object.keys(e.eager).length > 0, xr = class extends Error {
|
|
767
767
|
_tag = "TenantNamespaceUnresolved";
|
|
768
768
|
constructor(e) {
|
|
769
769
|
super(e), this.name = "TenantNamespaceUnresolved";
|
|
770
770
|
}
|
|
771
|
-
},
|
|
771
|
+
}, Sr = class extends Error {
|
|
772
772
|
_tag = "TenantNamespaceInvalid";
|
|
773
773
|
constructor(e) {
|
|
774
774
|
super(e), this.name = "TenantNamespaceInvalid";
|
|
775
775
|
}
|
|
776
|
-
},
|
|
777
|
-
if (e == null || e === "") throw new
|
|
778
|
-
let t =
|
|
779
|
-
if (t.replace(/_/g, "") === "") throw new
|
|
780
|
-
let n = `${
|
|
781
|
-
if (n.length >
|
|
776
|
+
}, Cr = 63, wr = "tenant_", Tr = (e) => e.toLowerCase().replace(/[^a-z0-9_]/g, "_"), Er = (e) => {
|
|
777
|
+
if (e == null || e === "") throw new xr("namespace isolation is on but the request has no resolvable tenant (subject.tenantId is null/empty). Refusing to run against a shared/default namespace — this would be a cross-tenant read. Authenticate with a tenant-scoped subject, or disable namespace isolation for this surface.");
|
|
778
|
+
let t = Tr(e);
|
|
779
|
+
if (t.replace(/_/g, "") === "") throw new Sr(`tenant id '${e}' has no usable identifier characters after sanitisation — cannot derive a distinct namespace.`);
|
|
780
|
+
let n = `${wr}${t}`;
|
|
781
|
+
if (n.length > Cr) throw new Sr(`namespace '${n}' for tenant '${e}' exceeds the ${Cr}-byte identifier limit. Use a shorter tenant id.`);
|
|
782
782
|
return n;
|
|
783
|
-
},
|
|
784
|
-
if (e === void 0 || t == null || !
|
|
783
|
+
}, Dr = (e, t) => e === null ? t : `${e}.${t}`, Or = /* @__PURE__ */ new Set(["timestamp", "date"]), kr = /^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2})?/, Ar = (e, t) => {
|
|
784
|
+
if (e === void 0 || t == null || !Or.has(e) || t instanceof Date) return t;
|
|
785
785
|
if (typeof t == "number" && Number.isFinite(t)) return new Date(t);
|
|
786
|
-
if (typeof t == "string" &&
|
|
786
|
+
if (typeof t == "string" && kr.test(t)) {
|
|
787
787
|
let e = new Date(t);
|
|
788
788
|
return Number.isNaN(e.getTime()) ? t : e;
|
|
789
789
|
}
|
|
790
790
|
return t;
|
|
791
|
-
},
|
|
791
|
+
}, jr = (e, t) => e === void 0 || !Or.has(e) ? t : t.map((t) => Ar(e, t)), Mr = (e, t) => {
|
|
792
792
|
let { strings: n, values: r } = e, i = t.unsafe(n[0] ?? "");
|
|
793
793
|
for (let e = 0; e < r.length; e++) i = t`${i}${r[e]}${t.unsafe(n[e + 1] ?? "")}`;
|
|
794
794
|
return t`${i}`;
|
|
795
|
-
},
|
|
795
|
+
}, Nr = (e) => e.replace(/[\\%_]/g, (e) => `\\${e}`), I = (e, t, n = null, r) => {
|
|
796
796
|
if ("not" in e) return t`NOT (${I(e.not, t, n, r)})`;
|
|
797
797
|
if ("and" in e) return e.and.length === 0 ? t`TRUE` : t.and(e.and.map((e) => I(e, t, n, r)));
|
|
798
798
|
if ("or" in e) return e.or.length === 0 ? t`FALSE` : t.or(e.or.map((e) => I(e, t, n, r)));
|
|
799
799
|
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
800
|
-
let r = e, i =
|
|
800
|
+
let r = e, i = Wr(r.subquery, t, n);
|
|
801
801
|
return r.op === "subquery-in" ? t`${t(r.column)} IN (${i})` : t`${t(r.column)} NOT IN (${i})`;
|
|
802
802
|
}
|
|
803
803
|
if (e.op === "exists" || e.op === "not-exists") {
|
|
804
|
-
let r = e, i =
|
|
804
|
+
let r = e, i = Wr(r.subquery, t, n);
|
|
805
805
|
return r.op === "exists" ? t`EXISTS (${i})` : t`NOT EXISTS (${i})`;
|
|
806
806
|
}
|
|
807
807
|
let i = e, a = t(i.column), o = i.path, s = o !== void 0 && o.length > 0, c = () => t.onDialectOrElse({
|
|
808
|
-
mysql: () => t.unsafe(
|
|
809
|
-
mssql: () => t.unsafe(
|
|
810
|
-
sqlite: () => t.unsafe(
|
|
811
|
-
orElse: () => t.unsafe(
|
|
808
|
+
mysql: () => t.unsafe(w(i.column, o, "mysql")),
|
|
809
|
+
mssql: () => t.unsafe(w(i.column, o, "mssql")),
|
|
810
|
+
sqlite: () => t.unsafe(w(i.column, o, "sqlite")),
|
|
811
|
+
orElse: () => t.unsafe(w(i.column, o, "postgres"))
|
|
812
812
|
}), l = () => t.onDialectOrElse({
|
|
813
|
-
mysql: () => t.unsafe(
|
|
814
|
-
mssql: () => t.unsafe(
|
|
815
|
-
sqlite: () => t.unsafe(
|
|
816
|
-
orElse: () => t.unsafe(
|
|
817
|
-
}), u = s ? c() : a, d = s ? l() : a, f = (e) => s && e != null ? String(e) : e, p = (e) => s ? Number(e) : e,
|
|
813
|
+
mysql: () => t.unsafe(w(i.column, o, "mysql", { numeric: !0 })),
|
|
814
|
+
mssql: () => t.unsafe(w(i.column, o, "mssql", { numeric: !0 })),
|
|
815
|
+
sqlite: () => t.unsafe(w(i.column, o, "sqlite", { numeric: !0 })),
|
|
816
|
+
orElse: () => t.unsafe(w(i.column, o, "postgres", { numeric: !0 }))
|
|
817
|
+
}), u = s ? c() : a, d = s ? l() : a, f = (e) => s && e != null ? String(e) : e, p = (e) => s ? Number(e) : e, m = s || r === void 0 ? void 0 : E(r)?.fields?.[i.column]?.type, h = (e) => Ar(m, e);
|
|
818
818
|
switch (i.op) {
|
|
819
|
-
case "eq": return t`${u} = ${f(
|
|
820
|
-
case "neq": return t`${u} <> ${f(
|
|
819
|
+
case "eq": return t`${u} = ${f(h(i.value))}`;
|
|
820
|
+
case "neq": return t`${u} <> ${f(h(i.value))}`;
|
|
821
821
|
case "gt": return t`${d} > ${p(i.value)}`;
|
|
822
822
|
case "gte": return t`${d} >= ${p(i.value)}`;
|
|
823
823
|
case "lt": return t`${d} < ${p(i.value)}`;
|
|
@@ -831,7 +831,7 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
831
831
|
return e.length === 0 ? t`TRUE` : t`${u} NOT IN ${t.in(s ? e.map((e) => f(e)) : e)}`;
|
|
832
832
|
}
|
|
833
833
|
case "contains": {
|
|
834
|
-
let e = `%${
|
|
834
|
+
let e = `%${Nr(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
|
|
835
835
|
return t.onDialectOrElse({
|
|
836
836
|
mysql: () => t`LOWER(${u}) LIKE LOWER(${e})`,
|
|
837
837
|
mssql: () => t`LOWER(${u}) LIKE LOWER(${e})`,
|
|
@@ -840,7 +840,7 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
840
840
|
});
|
|
841
841
|
}
|
|
842
842
|
case "startsWith": {
|
|
843
|
-
let e = `${
|
|
843
|
+
let e = `${Nr(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
|
|
844
844
|
return t.onDialectOrElse({
|
|
845
845
|
mysql: () => t`${u} LIKE ${e}`,
|
|
846
846
|
orElse: () => t`${u} LIKE ${e} ESCAPE '\\'`
|
|
@@ -888,13 +888,13 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
888
888
|
});
|
|
889
889
|
}
|
|
890
890
|
}
|
|
891
|
-
},
|
|
891
|
+
}, Pr = (e, t) => {
|
|
892
892
|
let n = [];
|
|
893
893
|
return e.partitionBy && e.partitionBy.length > 0 && n.push(t`PARTITION BY ${t.csv(e.partitionBy.map((e) => t`${t(e)}`))}`), e.orderBy && e.orderBy.length > 0 && n.push(t`ORDER BY ${t.csv(e.orderBy.map((e) => e.direction === "desc" ? t`${t(e.column)} DESC` : t`${t(e.column)} ASC`))}`), n.length === 0 ? t`` : n.length === 1 ? n[0] : n.reduce((e, n, r) => r === 0 ? n : t`${e} ${n}`);
|
|
894
|
-
},
|
|
894
|
+
}, Fr = (e, t) => t.csv(e.map((e) => {
|
|
895
895
|
let n = e.column === void 0 ? t.unsafe("*") : t`${t(e.column)}`;
|
|
896
896
|
if (e.op.startsWith("window-")) {
|
|
897
|
-
let r =
|
|
897
|
+
let r = Pr(e.window ?? {}, t);
|
|
898
898
|
switch (e.op) {
|
|
899
899
|
case "window-row-number": return t`ROW_NUMBER() OVER (${r}) AS ${t(e.alias)}`;
|
|
900
900
|
case "window-rank": return t`RANK() OVER (${r}) AS ${t(e.alias)}`;
|
|
@@ -918,44 +918,44 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
918
918
|
return t`${t(e.column)} AS ${t(e.alias)}`;
|
|
919
919
|
default: throw Error(`compileAggregateProjection: unknown op '${e.op}'`);
|
|
920
920
|
}
|
|
921
|
-
})),
|
|
921
|
+
})), Ir = (e) => `[${e.join(",")}]`, Lr = (e, t) => {
|
|
922
922
|
if (e.queryVector === void 0) return null;
|
|
923
|
-
let n = t(e.column), r =
|
|
923
|
+
let n = t(e.column), r = Ir(e.queryVector), i = e.distance === "cosine" ? "<=>" : e.distance === "l2" ? "<->" : "<#>", a = e.distance === "cosine" ? "VEC_DISTANCE_COSINE" : "VEC_DISTANCE_EUCLIDEAN";
|
|
924
924
|
return t.onDialectOrElse({
|
|
925
925
|
mysql: () => t`${t.unsafe(a)}(${n}, ${r})`,
|
|
926
926
|
mssql: () => t`NULL`,
|
|
927
927
|
sqlite: () => t`NULL`,
|
|
928
928
|
orElse: () => t`${n} ${t.unsafe(i)} ${r}::vector`
|
|
929
929
|
});
|
|
930
|
-
},
|
|
930
|
+
}, Rr = (e, t) => {
|
|
931
931
|
let n = t.unsafe(e.useGeography ? "::geography" : "::geometry");
|
|
932
932
|
return t`ST_Distance(${t(e.column)}${n}, ${e.geom}${n})`;
|
|
933
|
-
},
|
|
934
|
-
let r = n.csv(e.columns.map((e) => n`${n(e)}`)), i = `%${
|
|
933
|
+
}, zr = (e, t) => t`${t(e.column)} <-> ${e.geom}::geometry`, Br = (e, t) => t`${t(`${e.indexName}_tsv`)}`, Vr = (e, t) => `${t}_${e.indexName}_fts`, Hr = (e, t, n) => {
|
|
934
|
+
let r = n.csv(e.columns.map((e) => n`${n(e)}`)), i = `%${Nr(e.query)}%`;
|
|
935
935
|
return n.onDialectOrElse({
|
|
936
936
|
mysql: () => n`MATCH(${r}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
|
|
937
937
|
sqlite: () => {
|
|
938
|
-
let r = n(
|
|
938
|
+
let r = n(Vr(e, t));
|
|
939
939
|
return n`${n("id")} IN (SELECT ${n("row_id")} FROM ${r} WHERE ${r} MATCH ${e.query})`;
|
|
940
940
|
},
|
|
941
941
|
mssql: () => n.or(e.columns.map((e) => n`LOWER(${n(e)}) LIKE LOWER(${i}) ESCAPE '\\'`)),
|
|
942
|
-
orElse: () => n`${
|
|
942
|
+
orElse: () => n`${Br(e, n)} @@ plainto_tsquery(${e.config ?? "english"}, ${e.query})`
|
|
943
943
|
});
|
|
944
|
-
},
|
|
945
|
-
let r = `%${
|
|
944
|
+
}, Ur = (e, t, n) => {
|
|
945
|
+
let r = `%${Nr(e.query)}%`;
|
|
946
946
|
return n.onDialectOrElse({
|
|
947
947
|
mysql: () => n`MATCH(${n.csv(e.columns.map((e) => n`${n(e)}`))}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
|
|
948
948
|
sqlite: () => {
|
|
949
|
-
let r = n(
|
|
949
|
+
let r = n(Vr(e, t));
|
|
950
950
|
return n`COALESCE((SELECT -bm25(${r}) FROM ${r} WHERE ${r} MATCH ${e.query} AND ${r}.${n("row_id")} = ${n("id")}), 0)`;
|
|
951
951
|
},
|
|
952
952
|
mssql: () => e.columns.map((e) => n`(CASE WHEN LOWER(${n(e)}) LIKE LOWER(${r}) ESCAPE '\\' THEN 1 ELSE 0 END)`).reduce((e, t, r) => r === 0 ? t : n`${e} + ${t}`),
|
|
953
|
-
orElse: () => n`ts_rank(${
|
|
953
|
+
orElse: () => n`ts_rank(${Br(e, n)}, plainto_tsquery(${e.config ?? "english"}, ${e.query}))`
|
|
954
954
|
});
|
|
955
|
-
},
|
|
955
|
+
}, Wr = (e, t, n = null) => {
|
|
956
956
|
if (e.setOp && e.setOp.queries.length >= 2) {
|
|
957
|
-
let r = e.setOp.kind === "union" ? "UNION" : e.setOp.kind === "union-all" ? "UNION ALL" : e.setOp.kind === "intersect" ? "INTERSECT" : "EXCEPT", i = e.setOp.queries.map((e) => t`(${
|
|
958
|
-
if (
|
|
957
|
+
let r = e.setOp.kind === "union" ? "UNION" : e.setOp.kind === "union-all" ? "UNION ALL" : e.setOp.kind === "intersect" ? "INTERSECT" : "EXCEPT", i = e.setOp.queries.map((e) => t`(${Wr(e, t, n)})`).reduce((e, n, i) => i === 0 ? n : t`${e} ${t.unsafe(r)} ${n}`), a = [];
|
|
958
|
+
if (x(e).length > 0 && a.push(t` ORDER BY ${t.csv(x(e).map((e) => e.direction === "desc" ? t`${t(e.column)} DESC` : t`${t(e.column)} ASC`))}`), e.take !== void 0) {
|
|
959
959
|
if (!Number.isInteger(e.take) || e.take < 0) throw Error(`compileSelect: invalid take ${e.take}`);
|
|
960
960
|
a.push(t` LIMIT ${t.unsafe(String(e.take))}`);
|
|
961
961
|
}
|
|
@@ -965,7 +965,7 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
965
965
|
}
|
|
966
966
|
return t`${i}${a.reduce((e, n) => t`${e}${n}`, t``)}`;
|
|
967
967
|
}
|
|
968
|
-
let r = e.annClause === void 0 ? null :
|
|
968
|
+
let r = e.annClause === void 0 ? null : Lr(e.annClause, t);
|
|
969
969
|
e.spatialClause !== void 0 && t.onDialectOrElse({
|
|
970
970
|
mysql: () => {
|
|
971
971
|
throw Error("@voltro/plugin-postgis: spatial distance / KNN ordering is postgres-only");
|
|
@@ -978,57 +978,57 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
978
978
|
},
|
|
979
979
|
orElse: () => t``
|
|
980
980
|
});
|
|
981
|
-
let i = e.spatialClause?.projectAs === void 0 ? null :
|
|
981
|
+
let i = e.spatialClause?.projectAs === void 0 ? null : Rr(e.spatialClause, t), a = e.aggregations && e.aggregations.length > 0 ? Fr(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 ? Ur(c, e.table, t) : null, u = l !== null && c?.rank !== void 0 ? t`${s}, ${l} AS ${t(c.rank.alias)}` : s, d = i !== null && !o && e.spatialClause?.projectAs !== void 0 ? t`${u}, ${i} AS ${t(e.spatialClause.projectAs)}` : u, f = e.distinctOn && e.distinctOn.length > 0 ? t.onDialectOrElse({
|
|
982
982
|
orElse: () => t`DISTINCT ON (${t.csv(e.distinctOn.map((e) => t`${t(e)}`))}) `,
|
|
983
983
|
mysql: () => t`DISTINCT `,
|
|
984
984
|
mssql: () => t`DISTINCT `,
|
|
985
985
|
sqlite: () => t`DISTINCT `
|
|
986
|
-
}) : e.distinct ? t`DISTINCT ` : t``, p = e.alias === void 0 ? t`${t(
|
|
986
|
+
}) : e.distinct ? t`DISTINCT ` : t``, p = e.alias === void 0 ? t`${t(Dr(n, e.table))}` : t`${t(Dr(n, e.table))} AS ${t(e.alias)}`, m = (e.joins ?? []).map((e) => {
|
|
987
987
|
let r = e.kind === "inner" ? "INNER" : "LEFT";
|
|
988
|
-
return t` ${t.unsafe(r)} JOIN ${t(
|
|
989
|
-
}), h = m.length > 0 ? m.reduce((e, n) => t`${e}${n}`, p) : p, g = c === void 0 ? null :
|
|
990
|
-
r !== null &&
|
|
991
|
-
for (let n of
|
|
992
|
-
let
|
|
988
|
+
return t` ${t.unsafe(r)} JOIN ${t(Dr(n, e.table))} AS ${t(e.alias)} ON ${I(e.on, t, n)}`;
|
|
989
|
+
}), h = m.length > 0 ? m.reduce((e, n) => t`${e}${n}`, p) : p, g = c === void 0 ? null : Hr(c, e.table, t), _ = [e.predicate ? I(e.predicate, t, n, e.table) : null, g].filter((e) => e !== null), ee = _.length > 0 ? t` WHERE ${t.and(_)}` : t``, te = e.groupBy && e.groupBy.length > 0 ? t` GROUP BY ${t.csv(e.groupBy.map((e) => t`${t(e)}`))}` : t``, ne = e.having ? t` HAVING ${I(e.having, t, n, e.table)}` : t``, v = e.skip !== void 0, y = [];
|
|
990
|
+
r !== null && y.push(t`${r} ASC`), e.spatialClause?.order !== void 0 && y.push(e.spatialClause.order === "desc" ? t`${zr(e.spatialClause, t)} DESC` : t`${zr(e.spatialClause, t)} ASC`), l !== null && c?.rank?.order === !0 && y.push(t`${l} DESC`);
|
|
991
|
+
for (let n of x(e)) y.push(n.direction === "desc" ? t`${t(n.column)} DESC` : t`${t(n.column)} ASC`);
|
|
992
|
+
let re = y.length > 0 ? t` ORDER BY ${t.csv(y)}` : v ? t.onDialectOrElse({
|
|
993
993
|
mssql: () => t` ORDER BY (SELECT NULL)`,
|
|
994
994
|
orElse: () => t``
|
|
995
|
-
}) : t``,
|
|
995
|
+
}) : t``, b = (e) => {
|
|
996
996
|
if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw Error(`compileSelect: expected non-negative integer take/skip, got ${e}`);
|
|
997
997
|
return t.unsafe(String(e));
|
|
998
|
-
},
|
|
998
|
+
}, ie = (e.ctes ?? []).map((e) => t`${t(e.name)} AS (${Wr(e.descriptor, t, n)})`), ae = (e.ctes ?? []).some((e) => e.recursive === !0), oe = ie.length > 0 ? t`WITH ${t.unsafe(ae ? "RECURSIVE " : "")}${t.csv(ie)} ` : t``;
|
|
999
999
|
return t.onDialectOrElse({
|
|
1000
1000
|
mssql: () => {
|
|
1001
|
-
let n = e.take !== void 0 && !
|
|
1002
|
-
return t`${
|
|
1001
|
+
let n = e.take !== void 0 && !v ? t`TOP ${b(e.take)} ` : t``, r = v ? t` OFFSET ${b(e.skip)} ROWS FETCH NEXT ${b(e.take ?? 2 ** 53 - 1)} ROWS ONLY` : t``;
|
|
1002
|
+
return t`${oe}SELECT ${n}${f}${d} FROM ${h}${ee}${te}${ne}${re}${r}`;
|
|
1003
1003
|
},
|
|
1004
1004
|
orElse: () => {
|
|
1005
|
-
let n = e.take === void 0 ? t`` : t` LIMIT ${
|
|
1006
|
-
return t`${
|
|
1005
|
+
let n = e.take === void 0 ? t`` : t` LIMIT ${b(e.take)}`, r = v ? t` OFFSET ${b(e.skip)}` : t``;
|
|
1006
|
+
return t`${oe}SELECT ${f}${d} FROM ${h}${ee}${te}${ne}${re}${n}${r}`;
|
|
1007
1007
|
}
|
|
1008
1008
|
});
|
|
1009
|
-
},
|
|
1009
|
+
}, Gr = (e, t, n) => {
|
|
1010
1010
|
if (e.eager === void 0) return null;
|
|
1011
|
-
let r =
|
|
1011
|
+
let r = Jr(e.table, e.eager, e.sourceTable);
|
|
1012
1012
|
if (r === null) return null;
|
|
1013
|
-
let i =
|
|
1013
|
+
let i = ti(n, e, r, ei(t, n));
|
|
1014
1014
|
return i === null ? null : {
|
|
1015
1015
|
fragment: i,
|
|
1016
|
-
decode:
|
|
1016
|
+
decode: ii(r, n)
|
|
1017
1017
|
};
|
|
1018
|
-
},
|
|
1018
|
+
}, Kr = (e) => e.relation.kind === "one" && e.fkSide === "target", qr = (e) => ({
|
|
1019
1019
|
...e,
|
|
1020
1020
|
branch: {
|
|
1021
1021
|
...e.branch,
|
|
1022
1022
|
limit: 2
|
|
1023
1023
|
}
|
|
1024
|
-
}),
|
|
1025
|
-
let r = n ??
|
|
1024
|
+
}), Jr = (e, t, n) => {
|
|
1025
|
+
let r = n ?? Te(e), i = Bn(e);
|
|
1026
1026
|
if (i === void 0) return null;
|
|
1027
1027
|
let a = [];
|
|
1028
1028
|
for (let [e, n] of Object.entries(t)) {
|
|
1029
1029
|
let t = i[e];
|
|
1030
1030
|
if (t === void 0) return null;
|
|
1031
|
-
let o =
|
|
1031
|
+
let o = Yr(e, t, r, n === !0 ? {} : n);
|
|
1032
1032
|
if (o === null) return null;
|
|
1033
1033
|
a.push(o);
|
|
1034
1034
|
}
|
|
@@ -1036,19 +1036,19 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
1036
1036
|
table: r,
|
|
1037
1037
|
children: a
|
|
1038
1038
|
};
|
|
1039
|
-
},
|
|
1039
|
+
}, Yr = (e, t, n, r) => {
|
|
1040
1040
|
let i = t.target(), a = (t.kind === "manyToMany" ? void 0 : t.sourceKey) ?? "id", o, s;
|
|
1041
1041
|
if (t.kind === "manyToMany") o = t.targetKey, s = "target";
|
|
1042
1042
|
else if (t.kind === "one") {
|
|
1043
|
-
let r = t.sourceKey ??
|
|
1043
|
+
let r = t.sourceKey ?? $r(n, i.tableName);
|
|
1044
1044
|
if (r !== void 0) o = r, s = "source";
|
|
1045
1045
|
else try {
|
|
1046
|
-
o = t.foreignKey ??
|
|
1046
|
+
o = t.foreignKey ?? P(i, n.tableName, e), s = "target";
|
|
1047
1047
|
} catch {
|
|
1048
1048
|
return null;
|
|
1049
1049
|
}
|
|
1050
1050
|
} else try {
|
|
1051
|
-
o = t.foreignKey ??
|
|
1051
|
+
o = t.foreignKey ?? P(i, n.tableName, e), s = "target";
|
|
1052
1052
|
} catch {
|
|
1053
1053
|
return null;
|
|
1054
1054
|
}
|
|
@@ -1059,7 +1059,7 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
1059
1059
|
for (let [n, a] of Object.entries(r.with)) {
|
|
1060
1060
|
let r = e?.[n];
|
|
1061
1061
|
if (r === void 0) return null;
|
|
1062
|
-
let o =
|
|
1062
|
+
let o = Yr(n, r, i, a === !0 ? {} : a);
|
|
1063
1063
|
if (o === null) return null;
|
|
1064
1064
|
t.push(o);
|
|
1065
1065
|
}
|
|
@@ -1075,9 +1075,9 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
1075
1075
|
fkSide: s,
|
|
1076
1076
|
branch: r,
|
|
1077
1077
|
children: c,
|
|
1078
|
-
junction:
|
|
1078
|
+
junction: Xr(t, r)
|
|
1079
1079
|
};
|
|
1080
|
-
},
|
|
1080
|
+
}, Xr = (e, t) => {
|
|
1081
1081
|
if (e.kind !== "manyToMany" || t.junction === void 0) return;
|
|
1082
1082
|
let n = e.through(), r = t.junction === !0 ? Object.keys(n.fields) : t.junction, i = r.filter((e) => e in n.fields);
|
|
1083
1083
|
return {
|
|
@@ -1089,35 +1089,35 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
1089
1089
|
return t !== void 0 && (t.type === "timestamp" || t.type === "date");
|
|
1090
1090
|
})
|
|
1091
1091
|
};
|
|
1092
|
-
},
|
|
1092
|
+
}, Zr = (e) => `__j_${e}`, Qr = "__j", $r = (e, t) => {
|
|
1093
1093
|
for (let [n, r] of Object.entries(e.fields)) if (r.type === "reference" && r.references?.()?.tableName === t) return n;
|
|
1094
|
-
},
|
|
1094
|
+
}, ei = (e, t) => {
|
|
1095
1095
|
let n = 0;
|
|
1096
1096
|
return {
|
|
1097
1097
|
sql: e,
|
|
1098
1098
|
dialect: t,
|
|
1099
1099
|
nextAlias: () => `__a${n++}`
|
|
1100
1100
|
};
|
|
1101
|
-
},
|
|
1101
|
+
}, ti = (e, t, n, r) => {
|
|
1102
1102
|
switch (e) {
|
|
1103
|
-
case "postgres": return
|
|
1103
|
+
case "postgres": return si(t, n, r);
|
|
1104
1104
|
case "sqlite":
|
|
1105
|
-
case "turso": return
|
|
1105
|
+
case "turso": return hi(t, n, r);
|
|
1106
1106
|
case "mysql":
|
|
1107
|
-
case "mariadb": return
|
|
1108
|
-
case "mssql": return
|
|
1107
|
+
case "mariadb": return Ti(t, n, r);
|
|
1108
|
+
case "mssql": return Mi(t, n, r);
|
|
1109
1109
|
}
|
|
1110
|
-
},
|
|
1111
|
-
let n =
|
|
1110
|
+
}, ni = (e, t) => t === "mssql" && !ri.test(e) ? /* @__PURE__ */ new Date(`${e}Z`) : new Date(e), ri = /(?:Z|[+-]\d{2}:?\d{2})$/, ii = (e, t) => {
|
|
1111
|
+
let n = ai(e.table, e.children, t);
|
|
1112
1112
|
return (e) => e.map((e) => {
|
|
1113
1113
|
let t = e.__row, r = typeof t == "string" ? JSON.parse(t) : t;
|
|
1114
1114
|
return n(r);
|
|
1115
1115
|
});
|
|
1116
|
-
},
|
|
1116
|
+
}, ai = (e, t, n) => {
|
|
1117
1117
|
let r = [];
|
|
1118
1118
|
for (let [t, n] of Object.entries(e.fields)) (n.type === "timestamp" || n.type === "date") && r.push(t);
|
|
1119
1119
|
let i = t.map((e) => {
|
|
1120
|
-
let t =
|
|
1120
|
+
let t = ai(e.target, e.children, n), r = e.relation.kind === "one", i = Kr(e), a = i ? lr({
|
|
1121
1121
|
relationName: e.relationName,
|
|
1122
1122
|
sourceTableName: e.source.tableName,
|
|
1123
1123
|
targetTableName: e.target.tableName,
|
|
@@ -1130,14 +1130,14 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
1130
1130
|
isSingle: r,
|
|
1131
1131
|
fromOverFetch: i,
|
|
1132
1132
|
cardinalityMessage: a,
|
|
1133
|
-
junction:
|
|
1133
|
+
junction: oi(e.junction, n)
|
|
1134
1134
|
};
|
|
1135
1135
|
});
|
|
1136
1136
|
return (e) => {
|
|
1137
1137
|
let t = { ...e };
|
|
1138
1138
|
for (let e of r) {
|
|
1139
1139
|
let r = t[e];
|
|
1140
|
-
typeof r == "string" && (t[e] =
|
|
1140
|
+
typeof r == "string" && (t[e] = ni(r, n));
|
|
1141
1141
|
}
|
|
1142
1142
|
for (let e of i) {
|
|
1143
1143
|
let n = t[e.name];
|
|
@@ -1159,202 +1159,202 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
1159
1159
|
}
|
|
1160
1160
|
return t;
|
|
1161
1161
|
};
|
|
1162
|
-
},
|
|
1162
|
+
}, oi = (e, t) => {
|
|
1163
1163
|
if (e === void 0) return;
|
|
1164
1164
|
let n = new Set(e.dateColumns), r = e.requested;
|
|
1165
1165
|
return (e) => {
|
|
1166
1166
|
let i = e._junction ?? {}, a = {};
|
|
1167
1167
|
for (let e of r) {
|
|
1168
1168
|
let r = i[e];
|
|
1169
|
-
a[e] = n.has(e) && typeof r == "string" ?
|
|
1169
|
+
a[e] = n.has(e) && typeof r == "string" ? ni(r, t) : r;
|
|
1170
1170
|
}
|
|
1171
1171
|
return {
|
|
1172
1172
|
...e,
|
|
1173
1173
|
_junction: a
|
|
1174
1174
|
};
|
|
1175
1175
|
};
|
|
1176
|
-
},
|
|
1177
|
-
let r = n.sql, i = n.nextAlias(), a = r(t.table.tableName), o = r(i), s =
|
|
1178
|
-
return s === null ? null : r`SELECT ${s} AS "__row" FROM ${a} AS ${o}${e.predicate ? r` WHERE ${H(e.predicate, i, r)}` : r``}${
|
|
1179
|
-
},
|
|
1180
|
-
let i = n.sql, a = r === void 0 ? i`to_jsonb(${i(e)}.*)` : i`(to_jsonb(${i(e)}.*) - ${B(
|
|
1176
|
+
}, si = (e, t, n) => {
|
|
1177
|
+
let r = n.sql, i = n.nextAlias(), a = r(t.table.tableName), o = r(i), s = ci(i, t.children, n);
|
|
1178
|
+
return s === null ? null : r`SELECT ${s} AS "__row" FROM ${a} AS ${o}${e.predicate ? r` WHERE ${H(e.predicate, i, r)}` : r``}${x(e).length > 0 ? r` ORDER BY ${r.csv(x(e).map((e) => e.direction === "desc" ? r`${z(i, e.column, r)} DESC` : r`${z(i, e.column, r)} ASC`))}` : r``}${e.take === void 0 ? r`` : r` LIMIT ${V(e.take, r)}`}${e.skip === void 0 ? r`` : r` OFFSET ${V(e.skip, r)}`}`;
|
|
1179
|
+
}, ci = (e, t, n, r) => {
|
|
1180
|
+
let i = n.sql, a = r === void 0 ? i`to_jsonb(${i(e)}.*)` : i`(to_jsonb(${i(e)}.*) - ${B(Qr, i)}::text)`;
|
|
1181
1181
|
if (t.length === 0 && r === void 0) return a;
|
|
1182
1182
|
let o = [];
|
|
1183
|
-
r !== void 0 && o.push(i`${B("_junction", i)}, ${z(e,
|
|
1183
|
+
r !== void 0 && o.push(i`${B("_junction", i)}, ${z(e, Qr, i)}`);
|
|
1184
1184
|
for (let r of t) {
|
|
1185
|
-
let t =
|
|
1185
|
+
let t = li(r, e, n);
|
|
1186
1186
|
if (t === null) return null;
|
|
1187
1187
|
o.push(i`${B(r.relationName, i)}, ${t}`);
|
|
1188
1188
|
}
|
|
1189
1189
|
return i`${a} || jsonb_build_object(${i.csv(o)})`;
|
|
1190
|
-
},
|
|
1190
|
+
}, li = (e, t, n) => {
|
|
1191
1191
|
switch (e.relation.kind) {
|
|
1192
|
-
case "one": return
|
|
1193
|
-
case "many": return
|
|
1194
|
-
case "manyToMany": return
|
|
1192
|
+
case "one": return Kr(e) ? di(qr(e), t, n) : ui(e, t, n);
|
|
1193
|
+
case "many": return di(e, t, n);
|
|
1194
|
+
case "manyToMany": return fi(e, t, n);
|
|
1195
1195
|
}
|
|
1196
|
-
},
|
|
1197
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1196
|
+
}, ui = (e, t, n) => {
|
|
1197
|
+
let r = n.sql, i = n.nextAlias(), a = ci(i, e.children, n);
|
|
1198
1198
|
if (a === null) return null;
|
|
1199
1199
|
let o = e.fkSide === "source" ? r`${z(i, "id", r)} = ${z(t, e.foreignKey, r)}` : r`${z(i, e.foreignKey, r)} = ${z(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${H(e.branch.where, i, r)}`, c = L(i, e.branch.orderBy, r);
|
|
1200
1200
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}${c} LIMIT 1)`;
|
|
1201
|
-
},
|
|
1202
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1201
|
+
}, di = (e, t, n) => {
|
|
1202
|
+
let r = n.sql, i = n.nextAlias(), a = ci(i, e.children, n);
|
|
1203
1203
|
if (a === null) return null;
|
|
1204
|
-
let o = r`${z(void 0, e.foreignKey, r)} = ${z(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${I(e.branch.where, r)}`, c =
|
|
1204
|
+
let o = r`${z(void 0, e.foreignKey, r)} = ${z(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${I(e.branch.where, r)}`, c = mi(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${V(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${V(e.branch.offset, r)}`;
|
|
1205
1205
|
return r`COALESCE((SELECT jsonb_agg(${a}) FROM (SELECT * FROM ${r(e.target.tableName)} WHERE ${o}${s}${c}${l}${u}) AS ${r(i)}), '[]'::jsonb)`;
|
|
1206
|
-
},
|
|
1207
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
1206
|
+
}, fi = (e, t, n) => {
|
|
1207
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = ci(o, e.children, n, e.junction);
|
|
1208
1208
|
if (c === null) return null;
|
|
1209
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${I(e.branch.where, r)}`, u =
|
|
1209
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${I(e.branch.where, r)}`, u = Bi(e, s, r), d = L(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${V(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${V(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : r`, ${pi(e.junction, s, r)} AS ${r(Qr)}`;
|
|
1210
1210
|
return r`COALESCE((SELECT jsonb_agg(${c}) FROM (SELECT ${r(o)}.*${m} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${z(o, "id", r)} = ${z(s, i.targetKey, r)} WHERE ${z(s, i.sourceKey, r)} = ${z(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), '[]'::jsonb)`;
|
|
1211
|
-
},
|
|
1212
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1211
|
+
}, pi = (e, t, n) => e.present.length === 0 ? n`jsonb_build_object()` : n`jsonb_build_object(${n.csv(e.present.map((e) => n`${B(e, n)}, ${z(t, e, n)}`))})`, L = (e, t, n) => t === void 0 || t.length === 0 ? n`` : n` ORDER BY ${n.csv(t.map((t) => t.direction === "desc" ? n`${z(e, t.column, n)} DESC` : n`${z(e, t.column, n)} ASC`))}`, mi = (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`))}`, hi = (e, t, n) => {
|
|
1212
|
+
let r = n.sql, i = n.nextAlias(), a = gi(i, t.table, t.children, n);
|
|
1213
1213
|
if (a === null) return null;
|
|
1214
|
-
let o = e.predicate ? r` WHERE ${H(e.predicate, i, r)}` : r``, s =
|
|
1214
|
+
let o = e.predicate ? r` WHERE ${H(e.predicate, i, r)}` : r``, s = x(e).length > 0 ? r` ORDER BY ${r.csv(x(e).map((e) => e.direction === "desc" ? r`${z(i, e.column, r)} DESC` : r`${z(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${V(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${V(e.skip, r)}`;
|
|
1215
1215
|
return r`SELECT ${a} AS "__row" FROM ${r(t.table.tableName)} AS ${r(i)}${o}${s}${c}${l}`;
|
|
1216
|
-
},
|
|
1216
|
+
}, gi = (e, t, n, r, i) => {
|
|
1217
1217
|
let a = r.sql, o = [];
|
|
1218
1218
|
for (let n of Object.keys(t.fields)) o.push(a`${B(n, a)}, ${z(e, n, a)}`);
|
|
1219
1219
|
if (i !== void 0) {
|
|
1220
|
-
let e =
|
|
1220
|
+
let e = _i(i.projection, i.source, a);
|
|
1221
1221
|
o.push(a`${B("_junction", a)}, json_object(${e})`);
|
|
1222
1222
|
}
|
|
1223
1223
|
for (let t of n) {
|
|
1224
|
-
let n =
|
|
1224
|
+
let n = xi(t, e, r);
|
|
1225
1225
|
if (n === null) return null;
|
|
1226
1226
|
o.push(a`${B(t.relationName, a)}, ${n}`);
|
|
1227
1227
|
}
|
|
1228
1228
|
return a`json_object(${a.csv(o)})`;
|
|
1229
|
-
},
|
|
1229
|
+
}, _i = (e, t, n) => e.present.length === 0 ? n`` : n.csv(e.present.map((e) => n`${B(e, n)}, ${z(t.alias, t.physical(e), n)}`)), vi = (e, t, n) => e.present.length === 0 ? n`` : n`, ${n.csv(e.present.map((e) => n`${z(t, e, n)} AS ${n(Zr(e))}`))}`, yi = (e) => ({
|
|
1230
1230
|
alias: e,
|
|
1231
|
-
physical:
|
|
1232
|
-
}),
|
|
1231
|
+
physical: Zr
|
|
1232
|
+
}), bi = (e) => ({
|
|
1233
1233
|
alias: e,
|
|
1234
1234
|
physical: (e) => e
|
|
1235
|
-
}),
|
|
1235
|
+
}), xi = (e, t, n) => {
|
|
1236
1236
|
switch (e.relation.kind) {
|
|
1237
|
-
case "one": return
|
|
1238
|
-
case "many": return
|
|
1239
|
-
case "manyToMany": return
|
|
1237
|
+
case "one": return Kr(e) ? Ci(qr(e), t, n) : Si(e, t, n);
|
|
1238
|
+
case "many": return Ci(e, t, n);
|
|
1239
|
+
case "manyToMany": return wi(e, t, n);
|
|
1240
1240
|
}
|
|
1241
|
-
},
|
|
1242
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1241
|
+
}, Si = (e, t, n) => {
|
|
1242
|
+
let r = n.sql, i = n.nextAlias(), a = gi(i, e.target, e.children, n);
|
|
1243
1243
|
if (a === null) return null;
|
|
1244
1244
|
let o = e.fkSide === "source" ? r`${z(i, "id", r)} = ${z(t, e.foreignKey, r)}` : r`${z(i, e.foreignKey, r)} = ${z(t, e.sourceKey, r)}`;
|
|
1245
1245
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
|
|
1246
|
-
},
|
|
1247
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1246
|
+
}, Ci = (e, t, n) => {
|
|
1247
|
+
let r = n.sql, i = n.nextAlias(), a = gi(i, e.target, e.children, n);
|
|
1248
1248
|
if (a === null) return null;
|
|
1249
|
-
let o = r`${z(void 0, e.foreignKey, r)} = ${z(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${I(U(e.branch.where), r)}`, c =
|
|
1249
|
+
let o = r`${z(void 0, e.foreignKey, r)} = ${z(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${I(U(e.branch.where), r)}`, c = mi(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${V(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${V(e.branch.offset, r)}`;
|
|
1250
1250
|
return r`COALESCE((SELECT json_group_array(${a}) FROM (SELECT * FROM ${r(e.target.tableName)} WHERE ${o}${s}${c}${l}${u}) AS ${r(i)}), json('[]'))`;
|
|
1251
|
-
},
|
|
1252
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
1251
|
+
}, wi = (e, t, n) => {
|
|
1252
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = gi(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
1253
1253
|
projection: e.junction,
|
|
1254
|
-
source:
|
|
1254
|
+
source: yi(o)
|
|
1255
1255
|
});
|
|
1256
1256
|
if (c === null) return null;
|
|
1257
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${I(U(e.branch.where), r)}`, u =
|
|
1257
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${I(U(e.branch.where), r)}`, u = Bi(e, s, r, !0), d = L(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${V(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${V(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : vi(e.junction, s, r);
|
|
1258
1258
|
return r`COALESCE((SELECT json_group_array(${c}) FROM (SELECT ${r(o)}.*${m} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${z(o, "id", r)} = ${z(s, i.targetKey, r)} WHERE ${z(s, i.sourceKey, r)} = ${z(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), json('[]'))`;
|
|
1259
|
-
},
|
|
1259
|
+
}, Ti = (e, t, n) => {
|
|
1260
1260
|
let r = n.sql, i = n.nextAlias(), a = R(i, t.table, t.children, n);
|
|
1261
1261
|
if (a === null) return null;
|
|
1262
|
-
let o = e.predicate ? r` WHERE ${H(e.predicate, i, r)}` : r``, s =
|
|
1262
|
+
let o = e.predicate ? r` WHERE ${H(e.predicate, i, r)}` : r``, s = x(e).length > 0 ? r` ORDER BY ${r.csv(x(e).map((e) => e.direction === "desc" ? r`${z(i, e.column, r)} DESC` : r`${z(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${V(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${V(e.skip, r)}`;
|
|
1263
1263
|
return r`SELECT ${a} AS \`__row\` FROM ${r(t.table.tableName)} AS ${r(i)}${o}${s}${c}${l}`;
|
|
1264
1264
|
}, R = (e, t, n, r, i) => {
|
|
1265
1265
|
let a = r.sql, o = [];
|
|
1266
1266
|
for (let n of Object.keys(t.fields)) o.push(a`${B(n, a)}, ${z(e, n, a)}`);
|
|
1267
1267
|
if (i !== void 0) {
|
|
1268
|
-
let e =
|
|
1268
|
+
let e = _i(i.projection, i.source, a);
|
|
1269
1269
|
o.push(a`${B("_junction", a)}, JSON_OBJECT(${e})`);
|
|
1270
1270
|
}
|
|
1271
1271
|
for (let t of n) {
|
|
1272
|
-
let n =
|
|
1272
|
+
let n = Ei(t, e, r);
|
|
1273
1273
|
if (n === null) return null;
|
|
1274
1274
|
o.push(a`${B(t.relationName, a)}, ${n}`);
|
|
1275
1275
|
}
|
|
1276
1276
|
return a`JSON_OBJECT(${a.csv(o)})`;
|
|
1277
|
-
},
|
|
1277
|
+
}, Ei = (e, t, n) => {
|
|
1278
1278
|
switch (e.relation.kind) {
|
|
1279
1279
|
case "one":
|
|
1280
|
-
if (
|
|
1281
|
-
let r =
|
|
1282
|
-
return n.dialect === "mariadb" ?
|
|
1280
|
+
if (Kr(e)) {
|
|
1281
|
+
let r = qr(e);
|
|
1282
|
+
return n.dialect === "mariadb" ? Ai(r, t, n) : Oi(r, t, n);
|
|
1283
1283
|
}
|
|
1284
|
-
return
|
|
1285
|
-
case "many": return n.dialect === "mariadb" ?
|
|
1286
|
-
case "manyToMany": return n.dialect === "mariadb" ?
|
|
1284
|
+
return Di(e, t, n);
|
|
1285
|
+
case "many": return n.dialect === "mariadb" ? Ai(e, t, n) : Oi(e, t, n);
|
|
1286
|
+
case "manyToMany": return n.dialect === "mariadb" ? ji(e, t, n) : ki(e, t, n);
|
|
1287
1287
|
}
|
|
1288
|
-
},
|
|
1288
|
+
}, Di = (e, t, n) => {
|
|
1289
1289
|
let r = n.sql, i = n.nextAlias(), a = R(i, e.target, e.children, n);
|
|
1290
1290
|
if (a === null) return null;
|
|
1291
1291
|
let o = e.fkSide === "source" ? r`${z(i, "id", r)} = ${z(t, e.foreignKey, r)}` : r`${z(i, e.foreignKey, r)} = ${z(t, e.sourceKey, r)}`;
|
|
1292
1292
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
|
|
1293
|
-
},
|
|
1293
|
+
}, Oi = (e, t, n) => {
|
|
1294
1294
|
let r = n.sql, i = n.nextAlias(), a = R(i, e.target, e.children, n);
|
|
1295
1295
|
if (a === null) return null;
|
|
1296
|
-
let o = r`${z(void 0, e.foreignKey, r)} = ${z(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${I(U(e.branch.where), r)}`, c =
|
|
1296
|
+
let o = r`${z(void 0, e.foreignKey, r)} = ${z(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${I(U(e.branch.where), r)}`, c = mi(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${V(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${V(e.branch.offset, r)}`;
|
|
1297
1297
|
return r`COALESCE((SELECT JSON_ARRAYAGG(${a}) FROM (SELECT * FROM ${r(e.target.tableName)} WHERE ${o}${s}${c}${l}${u}) AS ${r(i)}), JSON_ARRAY())`;
|
|
1298
|
-
},
|
|
1298
|
+
}, ki = (e, t, n) => {
|
|
1299
1299
|
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = R(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
1300
1300
|
projection: e.junction,
|
|
1301
|
-
source:
|
|
1301
|
+
source: yi(o)
|
|
1302
1302
|
});
|
|
1303
1303
|
if (c === null) return null;
|
|
1304
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${I(U(e.branch.where), r)}`, u =
|
|
1304
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${I(U(e.branch.where), r)}`, u = Bi(e, s, r, !0), d = L(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${V(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${V(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : vi(e.junction, s, r);
|
|
1305
1305
|
return r`COALESCE((SELECT JSON_ARRAYAGG(${c}) FROM (SELECT ${r(o)}.*${m} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${z(o, "id", r)} = ${z(s, i.targetKey, r)} WHERE ${z(s, i.sourceKey, r)} = ${z(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), JSON_ARRAY())`;
|
|
1306
|
-
},
|
|
1306
|
+
}, Ai = (e, t, n) => {
|
|
1307
1307
|
let r = n.sql, i = n.nextAlias(), a = R(i, e.target, e.children, n);
|
|
1308
1308
|
if (a === null) return null;
|
|
1309
1309
|
let o = r`${z(i, e.foreignKey, r)} = ${z(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${I(U(e.branch.where), r)}`, c = e.branch.orderBy ?? [];
|
|
1310
1310
|
if (e.branch.limit === void 0 && e.branch.offset === void 0) return r`COALESCE((SELECT JSON_ARRAYAGG(${a}${c.length > 0 ? r` ORDER BY ${r.csv(c.map((e) => e.direction === "desc" ? r`${z(i, e.column, r)} DESC` : r`${z(i, e.column, r)} ASC`))}` : r``}) FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}), JSON_ARRAY())`;
|
|
1311
1311
|
let l = c.length > 0 ? r` ORDER BY ${r.csv(c.map((e) => e.direction === "desc" ? r`${r(e.column)} DESC` : r`${r(e.column)} ASC`))}` : r` ORDER BY ${r("id")}`, u = e.branch.limit, d = e.branch.offset, f = u !== void 0 && d !== void 0 ? r` AND ${z(i, "rn", r)} > ${V(d, r)} AND ${z(i, "rn", r)} <= ${V(d + u, r)}` : u === void 0 ? r` AND ${z(i, "rn", r)} > ${V(d, r)}` : r` AND ${z(i, "rn", r)} <= ${V(u, r)}`;
|
|
1312
1312
|
return r`COALESCE((SELECT JSON_ARRAYAGG(${a} ORDER BY ${z(i, "rn", r)}) FROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY ${r(e.foreignKey)}${l}) AS rn FROM ${r(e.target.tableName)}) AS ${r(i)} WHERE ${o}${s}${f}), JSON_ARRAY())`;
|
|
1313
|
-
},
|
|
1313
|
+
}, ji = (e, t, n) => {
|
|
1314
1314
|
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = (t) => e.junction === void 0 ? void 0 : {
|
|
1315
1315
|
projection: e.junction,
|
|
1316
1316
|
source: t
|
|
1317
|
-
}, l = r`${z(s, i.sourceKey, r)} = ${z(t, "id", r)}`, u = r`${z(o, "id", r)} = ${z(s, i.targetKey, r)}`, d = e.branch.where === void 0 ? r`` : r` AND ${I(U(e.branch.where), r)}`, f =
|
|
1317
|
+
}, l = r`${z(s, i.sourceKey, r)} = ${z(t, "id", r)}`, u = r`${z(o, "id", r)} = ${z(s, i.targetKey, r)}`, d = e.branch.where === void 0 ? r`` : r` AND ${I(U(e.branch.where), r)}`, f = Bi(e, s, r, !0), p = e.branch.orderBy ?? [];
|
|
1318
1318
|
if (e.branch.limit === void 0 && e.branch.offset === void 0) {
|
|
1319
|
-
let t = R(o, e.target, e.children, n, c(
|
|
1319
|
+
let t = R(o, e.target, e.children, n, c(bi(s)));
|
|
1320
1320
|
return t === null ? null : r`COALESCE((SELECT JSON_ARRAYAGG(${t}${p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${z(o, e.column, r)} DESC` : r`${z(o, e.column, r)} ASC`))}` : r``}) FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${u} WHERE ${l}${f}${d}), JSON_ARRAY())`;
|
|
1321
1321
|
}
|
|
1322
|
-
let m = p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${z(o, e.column, r)} DESC` : r`${z(o, e.column, r)} ASC`))}` : r` ORDER BY ${z(o, "id", r)}`, h = e.branch.limit, g = e.branch.offset,
|
|
1323
|
-
if (
|
|
1324
|
-
let
|
|
1325
|
-
return r`COALESCE((SELECT JSON_ARRAYAGG(${
|
|
1326
|
-
},
|
|
1327
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1322
|
+
let m = p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${z(o, e.column, r)} DESC` : r`${z(o, e.column, r)} ASC`))}` : r` ORDER BY ${z(o, "id", r)}`, h = e.branch.limit, g = e.branch.offset, _ = h !== void 0 && g !== void 0 ? r` AND ${z(o, "rn", r)} > ${V(g, r)} AND ${z(o, "rn", r)} <= ${V(g + h, r)}` : h === void 0 ? r` AND ${z(o, "rn", r)} > ${V(g, r)}` : r` AND ${z(o, "rn", r)} <= ${V(h, r)}`, ee = e.branch.onJunction === void 0 ? r`` : r` WHERE ${H(U(e.branch.onJunction), s, r)}`, te = R(o, e.target, e.children, n, c(yi(o)));
|
|
1323
|
+
if (te === null) return null;
|
|
1324
|
+
let ne = e.junction === void 0 ? r`` : vi(e.junction, s, r);
|
|
1325
|
+
return r`COALESCE((SELECT JSON_ARRAYAGG(${te} ORDER BY ${z(o, "rn", r)}) FROM (SELECT ${r(o)}.*${ne}, ${z(s, i.sourceKey, r)} AS ${r(`__src_${i.sourceKey}`)}, ROW_NUMBER() OVER (PARTITION BY ${z(s, i.sourceKey, r)}${m}) AS rn FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${u}${ee}) AS ${r(o)} WHERE ${z(o, `__src_${i.sourceKey}`, r)} = ${z(t, "id", r)}${d}${_}), JSON_ARRAY())`;
|
|
1326
|
+
}, Mi = (e, t, n) => {
|
|
1327
|
+
let r = n.sql, i = n.nextAlias(), a = Ni(i, t.table, t.children, n);
|
|
1328
1328
|
if (a === null) return null;
|
|
1329
|
-
let o = e.predicate ? r` WHERE ${H(e.predicate, i, r)}` : r``, s =
|
|
1329
|
+
let o = e.predicate ? r` WHERE ${H(e.predicate, i, r)}` : r``, s = x(e).length > 0 ? r` ORDER BY ${r.csv(x(e).map((e) => e.direction === "desc" ? r`${z(i, e.column, r)} DESC` : r`${z(i, e.column, r)} ASC`))}` : r``, c = r``, l = r``;
|
|
1330
1330
|
if (e.skip !== void 0) {
|
|
1331
|
-
let t =
|
|
1331
|
+
let t = x(e).length > 0 ? s : r` ORDER BY (SELECT NULL)`;
|
|
1332
1332
|
l = e.take === void 0 ? r`${t} OFFSET ${V(e.skip, r)} ROWS` : r`${t} OFFSET ${V(e.skip, r)} ROWS FETCH NEXT ${V(e.take, r)} ROWS ONLY`;
|
|
1333
1333
|
} else e.take !== void 0 && (c = r`TOP ${V(e.take, r)} `);
|
|
1334
1334
|
let u = e.skip === void 0 ? s : r``;
|
|
1335
1335
|
return r`SELECT ${c}(SELECT ${a} FOR JSON PATH, INCLUDE_NULL_VALUES, WITHOUT_ARRAY_WRAPPER) AS ${r("__row")} FROM ${r(t.table.tableName)} AS ${r(i)}${o}${u}${l}`;
|
|
1336
|
-
},
|
|
1336
|
+
}, Ni = (e, t, n, r, i) => {
|
|
1337
1337
|
let a = r.sql, o = [];
|
|
1338
1338
|
for (let n of Object.keys(t.fields)) o.push(a`${z(e, n, a)} AS ${a(n)}`);
|
|
1339
|
-
if (i !== void 0) for (let e of i.projection.present) o.push(a`${z(i.source.alias, i.source.physical(e), a)} AS ${
|
|
1339
|
+
if (i !== void 0) for (let e of i.projection.present) o.push(a`${z(i.source.alias, i.source.physical(e), a)} AS ${Pi(`_junction.${e}`, a)}`);
|
|
1340
1340
|
for (let t of n) {
|
|
1341
|
-
let n =
|
|
1341
|
+
let n = Fi(t, e, r);
|
|
1342
1342
|
if (n === null) return null;
|
|
1343
1343
|
o.push(n);
|
|
1344
1344
|
}
|
|
1345
1345
|
return a.csv(o);
|
|
1346
|
-
},
|
|
1346
|
+
}, Pi = (e, t) => t.unsafe(`[${e.replace(/]/g, "]]")}]`), Fi = (e, t, n) => {
|
|
1347
1347
|
switch (e.relation.kind) {
|
|
1348
|
-
case "one": return
|
|
1349
|
-
case "many": return
|
|
1350
|
-
case "manyToMany": return
|
|
1348
|
+
case "one": return Kr(e) ? Ri(qr(e), t, n) : Ii(e, t, n);
|
|
1349
|
+
case "many": return Ri(e, t, n);
|
|
1350
|
+
case "manyToMany": return zi(e, t, n);
|
|
1351
1351
|
}
|
|
1352
|
-
},
|
|
1353
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1352
|
+
}, Ii = (e, t, n) => {
|
|
1353
|
+
let r = n.sql, i = n.nextAlias(), a = Ni(i, e.target, e.children, n);
|
|
1354
1354
|
if (a === null) return null;
|
|
1355
1355
|
let o = e.fkSide === "source" ? r`${z(i, "id", r)} = ${z(t, e.foreignKey, r)}` : r`${z(i, e.foreignKey, r)} = ${z(t, e.sourceKey, r)}`;
|
|
1356
1356
|
return r`JSON_QUERY((SELECT TOP 1 ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} FOR JSON PATH, INCLUDE_NULL_VALUES, WITHOUT_ARRAY_WRAPPER)) AS ${r(e.relationName)}`;
|
|
1357
|
-
},
|
|
1357
|
+
}, Li = (e, t, n) => {
|
|
1358
1358
|
if (e.offset !== void 0) {
|
|
1359
1359
|
let r = e.orderBy && e.orderBy.length > 0 ? t : n` ORDER BY (SELECT NULL)`, i = e.limit === void 0 ? n`${r} OFFSET ${V(e.offset, n)} ROWS` : n`${r} OFFSET ${V(e.offset, n)} ROWS FETCH NEXT ${V(e.limit, n)} ROWS ONLY`;
|
|
1360
1360
|
return {
|
|
@@ -1368,29 +1368,29 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
1368
1368
|
pagination: n``,
|
|
1369
1369
|
finalOrder: t
|
|
1370
1370
|
};
|
|
1371
|
-
},
|
|
1372
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1371
|
+
}, Ri = (e, t, n) => {
|
|
1372
|
+
let r = n.sql, i = n.nextAlias(), a = Ni(i, e.target, e.children, n);
|
|
1373
1373
|
if (a === null) return null;
|
|
1374
|
-
let o = e.branch.where === void 0 ? r`` : r` AND ${H(e.branch.where, i, r)}`, s = L(i, e.branch.orderBy, r), { top: c, pagination: l, finalOrder: u } =
|
|
1374
|
+
let o = e.branch.where === void 0 ? r`` : r` AND ${H(e.branch.where, i, r)}`, s = L(i, e.branch.orderBy, r), { top: c, pagination: l, finalOrder: u } = Li(e.branch, s, r);
|
|
1375
1375
|
return r`ISNULL(JSON_QUERY((SELECT ${c}${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${z(i, e.foreignKey, r)} = ${z(t, e.sourceKey, r)}${o}${u}${l} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
|
|
1376
|
-
},
|
|
1377
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
1376
|
+
}, zi = (e, t, n) => {
|
|
1377
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = Ni(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
1378
1378
|
projection: e.junction,
|
|
1379
|
-
source:
|
|
1379
|
+
source: bi(s)
|
|
1380
1380
|
});
|
|
1381
1381
|
if (c === null) return null;
|
|
1382
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${H(e.branch.where, o, r)}`, u =
|
|
1382
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${H(e.branch.where, o, r)}`, u = Bi(e, s, r), d = L(o, e.branch.orderBy, r), { top: f, pagination: p, finalOrder: m } = Li(e.branch, d, r);
|
|
1383
1383
|
return r`ISNULL(JSON_QUERY((SELECT ${f}${c} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${z(o, "id", r)} = ${z(s, i.targetKey, r)} WHERE ${z(s, i.sourceKey, r)} = ${z(t, "id", r)}${u}${l}${m}${p} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
|
|
1384
1384
|
}, z = (e, t, n) => e === void 0 ? n`${n(t)}` : n`${n(e)}.${n(t)}`, B = (e, t) => t.unsafe(`'${e.replace(/'/g, "''")}'`), V = (e, t) => {
|
|
1385
1385
|
if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw Error(`literalInt: expected non-negative integer, got ${e}`);
|
|
1386
1386
|
return t.unsafe(String(e));
|
|
1387
|
-
}, H = (e, t, n) => I(
|
|
1387
|
+
}, H = (e, t, n) => I(Vi(e, t), n), Bi = (e, t, n, r = !1) => {
|
|
1388
1388
|
let i = e.branch.onJunction;
|
|
1389
1389
|
return i === void 0 ? n`` : n` AND ${H(r ? U(i) : i, t, n)}`;
|
|
1390
|
-
},
|
|
1391
|
-
if ("not" in e) return { not:
|
|
1392
|
-
if ("and" in e) return { and: e.and.map((e) =>
|
|
1393
|
-
if ("or" in e) return { or: e.or.map((e) =>
|
|
1390
|
+
}, Vi = (e, t) => {
|
|
1391
|
+
if ("not" in e) return { not: Vi(e.not, t) };
|
|
1392
|
+
if ("and" in e) return { and: e.and.map((e) => Vi(e, t)) };
|
|
1393
|
+
if ("or" in e) return { or: e.or.map((e) => Vi(e, t)) };
|
|
1394
1394
|
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
1395
1395
|
let n = e;
|
|
1396
1396
|
return {
|
|
@@ -1412,91 +1412,91 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
1412
1412
|
let t = e;
|
|
1413
1413
|
return {
|
|
1414
1414
|
...t,
|
|
1415
|
-
value:
|
|
1415
|
+
value: Hi(t.value)
|
|
1416
1416
|
};
|
|
1417
|
-
},
|
|
1418
|
-
e.actors !== void 0 && (
|
|
1419
|
-
},
|
|
1417
|
+
}, Hi = (e) => e == null ? e : e instanceof Date ? e.toISOString() : typeof e == "boolean" ? +!!e : Array.isArray(e) ? e.map((e) => Hi(e)) : e, Ui = Symbol.for("@voltro/database/coreTablesRegistry"), Wi = globalThis, Gi = Wi[Ui] ?? (Wi[Ui] = {}), Ki = (e) => {
|
|
1418
|
+
e.actors !== void 0 && (Gi.actors = e.actors), e.tenants !== void 0 && (Gi.tenants = e.tenants);
|
|
1419
|
+
}, qi = (e, t) => () => {
|
|
1420
1420
|
let n = e();
|
|
1421
1421
|
if (n === void 0) throw Error(`core '${t}' table not registered; expected the framework CLI or your migrate step to call registerCoreTables({ ${t}: () => ${t}Table }) before the database handle is constructed`);
|
|
1422
1422
|
return n();
|
|
1423
|
-
},
|
|
1424
|
-
id:
|
|
1425
|
-
kind:
|
|
1423
|
+
}, Ji = () => qi(() => Gi.actors, "actors"), Yi = () => qi(() => Gi.tenants, "tenants"), Xi = T("actors", {
|
|
1424
|
+
id: _(),
|
|
1425
|
+
kind: t().oneOf([
|
|
1426
1426
|
"user",
|
|
1427
1427
|
"serviceAccount",
|
|
1428
1428
|
"apiKey",
|
|
1429
1429
|
"system"
|
|
1430
1430
|
]),
|
|
1431
|
-
displayName:
|
|
1432
|
-
createdAt:
|
|
1433
|
-
}),
|
|
1431
|
+
displayName: t().nullable(),
|
|
1432
|
+
createdAt: C().default("now")
|
|
1433
|
+
}), Zi = (e, t) => ({
|
|
1434
1434
|
column: e,
|
|
1435
1435
|
op: "eq",
|
|
1436
1436
|
value: t
|
|
1437
|
-
}),
|
|
1437
|
+
}), Qi = (e, t) => ({
|
|
1438
1438
|
column: e,
|
|
1439
1439
|
op: "neq",
|
|
1440
1440
|
value: t
|
|
1441
|
-
}),
|
|
1441
|
+
}), $i = (e, t) => ({
|
|
1442
1442
|
column: e,
|
|
1443
1443
|
op: "gt",
|
|
1444
1444
|
value: t
|
|
1445
|
-
}),
|
|
1445
|
+
}), ea = (e, t) => ({
|
|
1446
1446
|
column: e,
|
|
1447
1447
|
op: "gte",
|
|
1448
1448
|
value: t
|
|
1449
|
-
}),
|
|
1449
|
+
}), ta = (e, t) => ({
|
|
1450
1450
|
column: e,
|
|
1451
1451
|
op: "lt",
|
|
1452
1452
|
value: t
|
|
1453
|
-
}),
|
|
1453
|
+
}), na = (e, t) => ({
|
|
1454
1454
|
column: e,
|
|
1455
1455
|
op: "lte",
|
|
1456
1456
|
value: t
|
|
1457
|
-
}),
|
|
1457
|
+
}), ra = (e, t) => ({
|
|
1458
1458
|
column: e,
|
|
1459
1459
|
op: "in",
|
|
1460
1460
|
value: t
|
|
1461
|
-
}),
|
|
1461
|
+
}), ia = (e, t) => ({
|
|
1462
1462
|
column: e,
|
|
1463
1463
|
op: "notIn",
|
|
1464
1464
|
value: t
|
|
1465
|
-
}),
|
|
1465
|
+
}), aa = (e, t) => ({
|
|
1466
1466
|
column: e,
|
|
1467
1467
|
op: "contains",
|
|
1468
1468
|
value: t
|
|
1469
|
-
}),
|
|
1469
|
+
}), oa = (e, t) => ({
|
|
1470
1470
|
column: e,
|
|
1471
1471
|
op: "startsWith",
|
|
1472
1472
|
value: t
|
|
1473
|
-
}),
|
|
1473
|
+
}), sa = (e, t) => ({
|
|
1474
1474
|
column: e,
|
|
1475
1475
|
op: "arrayContains",
|
|
1476
1476
|
value: t
|
|
1477
|
-
}),
|
|
1477
|
+
}), ca = (e, t) => ({
|
|
1478
1478
|
column: e,
|
|
1479
1479
|
op: "arrayOverlaps",
|
|
1480
1480
|
value: t
|
|
1481
|
-
}),
|
|
1481
|
+
}), la = (e, t) => ({
|
|
1482
1482
|
column: e,
|
|
1483
1483
|
op: "arrayHas",
|
|
1484
1484
|
value: t
|
|
1485
|
-
}),
|
|
1485
|
+
}), ua = {
|
|
1486
1486
|
column: "id",
|
|
1487
1487
|
op: "in",
|
|
1488
1488
|
value: []
|
|
1489
|
-
},
|
|
1489
|
+
}, da = (e) => ({
|
|
1490
1490
|
column: e,
|
|
1491
1491
|
op: "isNull"
|
|
1492
|
-
}),
|
|
1492
|
+
}), fa = (e) => ({
|
|
1493
1493
|
column: e,
|
|
1494
1494
|
op: "isNotNull"
|
|
1495
|
-
}),
|
|
1495
|
+
}), pa = (e, t) => ({
|
|
1496
1496
|
column: e,
|
|
1497
1497
|
op: "spatial",
|
|
1498
1498
|
value: t
|
|
1499
|
-
}),
|
|
1499
|
+
}), ma = (...e) => ({ and: e }), ha = (...e) => ({ or: e }), ga = (e) => ({ not: e }), _a = (e, ...t) => {
|
|
1500
1500
|
if (t.length === 0) throw Error(`jsonField("${e}"): at least one path segment is required`);
|
|
1501
1501
|
let n = (n, r) => ({
|
|
1502
1502
|
column: e,
|
|
@@ -1518,33 +1518,33 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
1518
1518
|
isNull: () => n("isNull"),
|
|
1519
1519
|
isNotNull: () => n("isNotNull")
|
|
1520
1520
|
};
|
|
1521
|
-
},
|
|
1521
|
+
}, va = (e) => "descriptor" in e ? e.descriptor : e, ya = (e, t) => ({
|
|
1522
1522
|
column: e,
|
|
1523
1523
|
op: "subquery-in",
|
|
1524
|
-
subquery:
|
|
1525
|
-
}),
|
|
1524
|
+
subquery: va(t)
|
|
1525
|
+
}), ba = (e, t) => ({
|
|
1526
1526
|
column: e,
|
|
1527
1527
|
op: "subquery-not-in",
|
|
1528
|
-
subquery:
|
|
1529
|
-
}),
|
|
1528
|
+
subquery: va(t)
|
|
1529
|
+
}), xa = (e) => ({
|
|
1530
1530
|
op: "exists",
|
|
1531
|
-
subquery:
|
|
1532
|
-
}),
|
|
1531
|
+
subquery: va(e)
|
|
1532
|
+
}), Sa = (e) => ({
|
|
1533
1533
|
op: "not-exists",
|
|
1534
|
-
subquery:
|
|
1535
|
-
}),
|
|
1534
|
+
subquery: va(e)
|
|
1535
|
+
}), Ca = (e, t) => e === t || e instanceof Date && t instanceof Date && e.getTime() === t.getTime(), wa = (e, t) => {
|
|
1536
1536
|
if (e == null || t == null) return null;
|
|
1537
1537
|
let n = e instanceof Date ? e.getTime() : e, r = t instanceof Date ? t.getTime() : t;
|
|
1538
1538
|
return typeof n == typeof r ? n === r ? 0 : n > r ? 1 : -1 : null;
|
|
1539
|
-
},
|
|
1539
|
+
}, Ta = (e, t, n = null) => {
|
|
1540
1540
|
if (!t) return !1;
|
|
1541
|
-
if ("not" in e) return !
|
|
1541
|
+
if ("not" in e) return !Ta(e.not, t, n);
|
|
1542
1542
|
if ("and" in e) {
|
|
1543
|
-
for (let r of e.and) if (!
|
|
1543
|
+
for (let r of e.and) if (!Ta(r, t, n)) return !1;
|
|
1544
1544
|
return !0;
|
|
1545
1545
|
}
|
|
1546
1546
|
if ("or" in e) {
|
|
1547
|
-
for (let r of e.or) if (
|
|
1547
|
+
for (let r of e.or) if (Ta(r, t, n)) return !0;
|
|
1548
1548
|
return !1;
|
|
1549
1549
|
}
|
|
1550
1550
|
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
@@ -1561,14 +1561,14 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
1561
1561
|
}
|
|
1562
1562
|
let r = e, i = t[r.column];
|
|
1563
1563
|
switch (r.op) {
|
|
1564
|
-
case "eq": return
|
|
1565
|
-
case "neq": return !
|
|
1566
|
-
case "gt": return (
|
|
1567
|
-
case "gte": return (
|
|
1568
|
-
case "lt": return (
|
|
1569
|
-
case "lte": return (
|
|
1570
|
-
case "in": return Array.isArray(r.value) && r.value.some((e) =>
|
|
1571
|
-
case "notIn": return Array.isArray(r.value) && !r.value.some((e) =>
|
|
1564
|
+
case "eq": return Ca(i, r.value);
|
|
1565
|
+
case "neq": return !Ca(i, r.value);
|
|
1566
|
+
case "gt": return (wa(i, r.value) ?? -1) > 0;
|
|
1567
|
+
case "gte": return (wa(i, r.value) ?? -1) >= 0;
|
|
1568
|
+
case "lt": return (wa(i, r.value) ?? 1) < 0;
|
|
1569
|
+
case "lte": return (wa(i, r.value) ?? 1) <= 0;
|
|
1570
|
+
case "in": return Array.isArray(r.value) && r.value.some((e) => Ca(i, e));
|
|
1571
|
+
case "notIn": return Array.isArray(r.value) && !r.value.some((e) => Ca(i, e));
|
|
1572
1572
|
case "contains": return typeof i == "string" && typeof r.value == "string" && i.toLowerCase().includes(r.value.toLowerCase());
|
|
1573
1573
|
case "startsWith": return typeof i == "string" && typeof r.value == "string" && i.startsWith(r.value);
|
|
1574
1574
|
case "arrayContains": {
|
|
@@ -1584,17 +1584,17 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
1584
1584
|
case "isNotNull": return i != null;
|
|
1585
1585
|
case "spatial": throw Error("@voltro/plugin-postgis: spatial predicates (ST_DWithin / ST_Contains / ST_Within / ST_Intersects / bbox &&) are not evaluable in-memory — use them in one-shot ctx.store.query reads, not reactive subscriptions.");
|
|
1586
1586
|
}
|
|
1587
|
-
},
|
|
1587
|
+
}, Ea = function* (e) {
|
|
1588
1588
|
if ("not" in e) {
|
|
1589
|
-
yield*
|
|
1589
|
+
yield* Ea(e.not);
|
|
1590
1590
|
return;
|
|
1591
1591
|
}
|
|
1592
1592
|
if ("and" in e) {
|
|
1593
|
-
for (let t of e.and) yield*
|
|
1593
|
+
for (let t of e.and) yield* Ea(t);
|
|
1594
1594
|
return;
|
|
1595
1595
|
}
|
|
1596
1596
|
if ("or" in e) {
|
|
1597
|
-
for (let t of e.or) yield*
|
|
1597
|
+
for (let t of e.or) yield* Ea(t);
|
|
1598
1598
|
return;
|
|
1599
1599
|
}
|
|
1600
1600
|
e.op === "subquery-in" || e.op === "subquery-not-in" ? yield {
|
|
@@ -1604,46 +1604,46 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
1604
1604
|
kind: "exists",
|
|
1605
1605
|
descriptor: e.subquery
|
|
1606
1606
|
});
|
|
1607
|
-
},
|
|
1607
|
+
}, Da = function* (e, t = !0) {
|
|
1608
1608
|
if ("not" in e) {
|
|
1609
|
-
yield*
|
|
1609
|
+
yield* Da(e.not, !1);
|
|
1610
1610
|
return;
|
|
1611
1611
|
}
|
|
1612
1612
|
if ("and" in e) {
|
|
1613
|
-
for (let n of e.and) yield*
|
|
1613
|
+
for (let n of e.and) yield* Da(n, t);
|
|
1614
1614
|
return;
|
|
1615
1615
|
}
|
|
1616
1616
|
if ("or" in e) {
|
|
1617
|
-
for (let t of e.or) yield*
|
|
1617
|
+
for (let t of e.or) yield* Da(t, !1);
|
|
1618
1618
|
return;
|
|
1619
1619
|
}
|
|
1620
1620
|
e.op !== "subquery-in" && e.op !== "subquery-not-in" && e.op !== "exists" && e.op !== "not-exists" && (yield {
|
|
1621
1621
|
...e,
|
|
1622
1622
|
conjunctive: t
|
|
1623
1623
|
});
|
|
1624
|
-
},
|
|
1624
|
+
}, Oa = (e, t) => ({
|
|
1625
1625
|
...t,
|
|
1626
1626
|
...e,
|
|
1627
1627
|
origin: e.origin ?? "injected"
|
|
1628
|
-
}),
|
|
1628
|
+
}), ka = (e, t, n = {}) => ({
|
|
1629
1629
|
table: e,
|
|
1630
1630
|
op: "insert",
|
|
1631
1631
|
old: null,
|
|
1632
1632
|
new: t,
|
|
1633
1633
|
...n
|
|
1634
|
-
}),
|
|
1634
|
+
}), Aa = (e, t, n, r = {}) => ({
|
|
1635
1635
|
table: e,
|
|
1636
1636
|
op: "update",
|
|
1637
1637
|
old: t,
|
|
1638
1638
|
new: n,
|
|
1639
1639
|
...r
|
|
1640
|
-
}),
|
|
1640
|
+
}), ja = (e, t, n = {}) => ({
|
|
1641
1641
|
table: e,
|
|
1642
1642
|
op: "delete",
|
|
1643
1643
|
old: t,
|
|
1644
1644
|
new: null,
|
|
1645
1645
|
...n
|
|
1646
|
-
}),
|
|
1646
|
+
}), Ma = (e, t, n = {}) => {
|
|
1647
1647
|
let { at: r = "2026-01-01T00:00:00.000Z", column: i = "deletedAt", ...a } = n;
|
|
1648
1648
|
return {
|
|
1649
1649
|
table: e,
|
|
@@ -1658,26 +1658,86 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
1658
1658
|
},
|
|
1659
1659
|
...a
|
|
1660
1660
|
};
|
|
1661
|
-
},
|
|
1662
|
-
|
|
1661
|
+
}, Na = (e) => e == null ? "null" : e instanceof Date ? JSON.stringify(e.toISOString()) : typeof e == "bigint" ? JSON.stringify(e.toString()) : Array.isArray(e) ? `[${e.map(Na).join(",")}]` : typeof e == "object" ? `{${Object.entries(e).filter(([, e]) => e !== void 0).sort(([e], [t]) => e < t ? -1 : +(e > t)).map(([e, t]) => `${JSON.stringify(e)}:${Na(t)}`).join(",")}}` : JSON.stringify(e) ?? "null", Pa = (e) => Lt("sha256").update([
|
|
1662
|
+
e.pipe,
|
|
1663
|
+
e.op,
|
|
1664
|
+
e.key,
|
|
1665
|
+
Na(e.next),
|
|
1666
|
+
Na(e.prev)
|
|
1667
|
+
].join("\0")).digest("hex").slice(0, 32), Fa = (e, t) => `${e}:${t}`, Ia = (e) => {
|
|
1668
|
+
let t = e.lastIndexOf(":");
|
|
1669
|
+
if (t <= 0) return null;
|
|
1670
|
+
let n = Number(e.slice(t + 1));
|
|
1671
|
+
return !Number.isInteger(n) || n < 0 ? null : {
|
|
1672
|
+
digest: e.slice(0, t),
|
|
1673
|
+
occurrence: n
|
|
1674
|
+
};
|
|
1675
|
+
}, La = class {
|
|
1676
|
+
#e = /* @__PURE__ */ new Map();
|
|
1677
|
+
#t;
|
|
1678
|
+
#n;
|
|
1679
|
+
constructor(e) {
|
|
1680
|
+
this.#t = e.windowMs, this.#n = Math.max(1, e.maxEntries);
|
|
1681
|
+
}
|
|
1682
|
+
get size() {
|
|
1683
|
+
return this.#e.size;
|
|
1684
|
+
}
|
|
1685
|
+
next(e, t) {
|
|
1686
|
+
let n = this.#e.get(e);
|
|
1687
|
+
if (n === void 0) return this.#e.set(e, {
|
|
1688
|
+
count: 1,
|
|
1689
|
+
lastMs: t
|
|
1690
|
+
}), this.#r(), 0;
|
|
1691
|
+
n.lastMs = t;
|
|
1692
|
+
let r = n.count;
|
|
1693
|
+
return n.count += 1, this.#e.delete(e), this.#e.set(e, n), r;
|
|
1694
|
+
}
|
|
1695
|
+
seedFromChangeKeys(e, t) {
|
|
1696
|
+
for (let n of e) {
|
|
1697
|
+
let e = Ia(n);
|
|
1698
|
+
if (e === null) continue;
|
|
1699
|
+
let r = this.#e.get(e.digest), i = Math.max(r?.count ?? 0, e.occurrence + 1);
|
|
1700
|
+
this.#e.set(e.digest, {
|
|
1701
|
+
count: i,
|
|
1702
|
+
lastMs: r?.lastMs ?? t
|
|
1703
|
+
});
|
|
1704
|
+
}
|
|
1705
|
+
this.#r();
|
|
1706
|
+
}
|
|
1707
|
+
prune(e) {
|
|
1708
|
+
let t = e - this.#t;
|
|
1709
|
+
for (let [e, n] of this.#e) n.lastMs < t && this.#e.delete(e);
|
|
1710
|
+
}
|
|
1711
|
+
#r() {
|
|
1712
|
+
for (; this.#e.size > this.#n;) {
|
|
1713
|
+
let e = this.#e.keys().next();
|
|
1714
|
+
if (e.done === !0) return;
|
|
1715
|
+
this.#e.delete(e.value);
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
}, Ra = "VOLTRO_CHANGE_CLAIMS_TTL_HOURS", za = 1, Ba = (e = process.env) => {
|
|
1719
|
+
let t = Number(e[Ra]);
|
|
1720
|
+
return (Number.isFinite(t) && t > 0 ? t : 1) * 2 * 36e5;
|
|
1721
|
+
}, Va = new Rt(), Ha = (e, t) => Va.run(e, t), Ua = () => Va.getStore(), Wa = (e) => {
|
|
1722
|
+
let t = e ?? Va.getStore();
|
|
1663
1723
|
return t === void 0 ? {} : {
|
|
1664
1724
|
...t.traceId === void 0 ? {} : { traceId: t.traceId },
|
|
1665
1725
|
...t.subjectId === void 0 ? {} : { subjectId: t.subjectId },
|
|
1666
1726
|
...t.procedure === void 0 ? {} : { procedure: t.procedure },
|
|
1667
1727
|
...t.via === void 0 ? {} : { via: t.via }
|
|
1668
1728
|
};
|
|
1669
|
-
},
|
|
1670
|
-
let t =
|
|
1671
|
-
return t === void 0 ? e(void 0) :
|
|
1672
|
-
},
|
|
1729
|
+
}, Ga = (e) => {
|
|
1730
|
+
let t = Va.getStore();
|
|
1731
|
+
return t === void 0 ? e(void 0) : Va.run(t, () => e(t));
|
|
1732
|
+
}, Ka = 3e4, qa = 1e4, W = /* @__PURE__ */ new Map(), G = 0, Ja = (e, t, n) => `${e}\u0000${t}\u0000${String(n)}`, Ya = (e) => {
|
|
1673
1733
|
for (let [t, n] of W) {
|
|
1674
|
-
let r = n.filter((t) => e - t.at <
|
|
1734
|
+
let r = n.filter((t) => e - t.at < Ka);
|
|
1675
1735
|
G -= n.length - r.length, r.length === 0 ? W.delete(t) : r.length !== n.length && W.set(t, r);
|
|
1676
1736
|
}
|
|
1677
|
-
},
|
|
1737
|
+
}, Xa = (e, t) => {
|
|
1678
1738
|
if (t.traceId === void 0 && t.subjectId === void 0 && t.procedure === void 0) return;
|
|
1679
1739
|
let n = Date.now();
|
|
1680
|
-
if (G >=
|
|
1740
|
+
if (G >= qa && Ya(n), G >= qa) return;
|
|
1681
1741
|
let r = W.get(e);
|
|
1682
1742
|
r === void 0 ? W.set(e, [{
|
|
1683
1743
|
attribution: t,
|
|
@@ -1686,38 +1746,38 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
1686
1746
|
attribution: t,
|
|
1687
1747
|
at: n
|
|
1688
1748
|
}), G += 1;
|
|
1689
|
-
},
|
|
1749
|
+
}, Za = (e) => {
|
|
1690
1750
|
let t = W.get(e);
|
|
1691
1751
|
if (t === void 0 || t.length === 0) return;
|
|
1692
1752
|
let n = t.shift();
|
|
1693
|
-
if (--G, t.length === 0 && W.delete(e), !(Date.now() - n.at >=
|
|
1694
|
-
},
|
|
1695
|
-
let t =
|
|
1753
|
+
if (--G, t.length === 0 && W.delete(e), !(Date.now() - n.at >= Ka)) return n.attribution;
|
|
1754
|
+
}, Qa = (e) => (W.get(e)?.length ?? 0) > 0, K = /* @__PURE__ */ new Map(), $a = /* @__PURE__ */ new Map(), eo = /* @__PURE__ */ new Map(), to = 250, no = (e) => {
|
|
1755
|
+
let t = $a.get(e);
|
|
1696
1756
|
if (t === void 0) return;
|
|
1697
|
-
|
|
1698
|
-
let n =
|
|
1699
|
-
n !== void 0 && (clearTimeout(n),
|
|
1757
|
+
$a.delete(e);
|
|
1758
|
+
let n = eo.get(e);
|
|
1759
|
+
n !== void 0 && (clearTimeout(n), eo.delete(e));
|
|
1700
1760
|
for (let e of t) e();
|
|
1701
|
-
},
|
|
1761
|
+
}, ro = (e) => {
|
|
1702
1762
|
K.set(e, (K.get(e) ?? 0) + 1);
|
|
1703
|
-
},
|
|
1763
|
+
}, io = (e) => {
|
|
1704
1764
|
let t = (K.get(e) ?? 0) - 1;
|
|
1705
1765
|
if (t > 0) {
|
|
1706
1766
|
K.set(e, t);
|
|
1707
1767
|
return;
|
|
1708
1768
|
}
|
|
1709
|
-
K.delete(e),
|
|
1710
|
-
},
|
|
1711
|
-
let i = n == null ? void 0 :
|
|
1769
|
+
K.delete(e), no(e);
|
|
1770
|
+
}, ao = (e, t, n, r) => {
|
|
1771
|
+
let i = n == null ? void 0 : Ja(e, t, n), a = () => r(i === void 0 ? void 0 : Za(i));
|
|
1712
1772
|
if (i === void 0) {
|
|
1713
1773
|
a();
|
|
1714
1774
|
return;
|
|
1715
1775
|
}
|
|
1716
|
-
if (
|
|
1776
|
+
if (Qa(i)) {
|
|
1717
1777
|
a();
|
|
1718
1778
|
return;
|
|
1719
1779
|
}
|
|
1720
|
-
let o =
|
|
1780
|
+
let o = $a.get(e);
|
|
1721
1781
|
if (o === void 0 && (K.get(e) ?? 0) === 0) {
|
|
1722
1782
|
a();
|
|
1723
1783
|
return;
|
|
@@ -1726,91 +1786,91 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
1726
1786
|
o.push(a);
|
|
1727
1787
|
return;
|
|
1728
1788
|
}
|
|
1729
|
-
|
|
1730
|
-
let s = setTimeout(() =>
|
|
1731
|
-
typeof s == "object" && typeof s.unref == "function" && s.unref(),
|
|
1732
|
-
},
|
|
1789
|
+
$a.set(e, [a]);
|
|
1790
|
+
let s = setTimeout(() => no(e), to);
|
|
1791
|
+
typeof s == "object" && typeof s.unref == "function" && s.unref(), eo.set(e, s);
|
|
1792
|
+
}, oo = () => {
|
|
1733
1793
|
W.clear(), G = 0, K.clear();
|
|
1734
|
-
for (let e of
|
|
1735
|
-
|
|
1736
|
-
},
|
|
1794
|
+
for (let e of eo.values()) clearTimeout(e);
|
|
1795
|
+
eo.clear(), $a.clear();
|
|
1796
|
+
}, so = () => G, co = 64, lo = "\0", uo = 32, fo = (e, ...t) => `${e}_${Lt("sha256").update(t.map(String).join(lo)).digest("hex").slice(0, uo)}`, po = (e) => e.length + 1 + uo, q = /* @__PURE__ */ new Map(), mo = (e, t) => {
|
|
1737
1797
|
q.set(e, {
|
|
1738
1798
|
recorder: t.recorder,
|
|
1739
1799
|
tables: new Set(t.tables),
|
|
1740
1800
|
ownTables: new Set(t.ownTables)
|
|
1741
1801
|
});
|
|
1742
|
-
},
|
|
1802
|
+
}, ho = (e) => {
|
|
1743
1803
|
q.delete(e);
|
|
1744
|
-
},
|
|
1745
|
-
let t =
|
|
1746
|
-
if (t !== void 0) return t.n += 1,
|
|
1804
|
+
}, go = () => q.clear(), _o = new Rt(), vo = (e) => _o.run({ n: 1 }, e), yo = (e) => D.suspend(() => {
|
|
1805
|
+
let t = _o.getStore();
|
|
1806
|
+
if (t !== void 0) return t.n += 1, D.ensuring(e, D.sync(() => {
|
|
1747
1807
|
--t.n;
|
|
1748
1808
|
}));
|
|
1749
1809
|
let n = { n: 1 };
|
|
1750
|
-
return
|
|
1810
|
+
return _o.enterWith(n), D.ensuring(e, D.sync(() => {
|
|
1751
1811
|
--n.n;
|
|
1752
1812
|
}));
|
|
1753
|
-
}),
|
|
1754
|
-
if (q.size === 0 || (
|
|
1813
|
+
}), bo = () => (_o.getStore()?.n ?? 0) > 0, xo = (e) => {
|
|
1814
|
+
if (q.size === 0 || (_o.getStore()?.n ?? 0) > 0) return !1;
|
|
1755
1815
|
for (let t of q.values()) if (!t.ownTables.has(e) && t.tables.has(e)) return !0;
|
|
1756
1816
|
return !1;
|
|
1757
|
-
},
|
|
1817
|
+
}, So = async (e, t) => {
|
|
1758
1818
|
if (q.size !== 0) {
|
|
1759
1819
|
for (let [n, r] of q.entries()) if (!r.ownTables.has(t.table) && r.tables.has(t.table)) try {
|
|
1760
1820
|
await r.recorder(e, t);
|
|
1761
1821
|
} catch (e) {
|
|
1762
|
-
let r =
|
|
1822
|
+
let r = gn(e);
|
|
1763
1823
|
throw r === void 0 ? e : Error(`write recorder '${n}' failed while recording a ${t.op} on '${t.table}': ${r}`, { cause: e });
|
|
1764
1824
|
}
|
|
1765
1825
|
}
|
|
1766
|
-
},
|
|
1826
|
+
}, Co = Nt.exponential({
|
|
1767
1827
|
start: 5e-4,
|
|
1768
1828
|
factor: 2,
|
|
1769
1829
|
count: 16
|
|
1770
|
-
}),
|
|
1771
|
-
let n = `${e}\u0000${t}`, r =
|
|
1830
|
+
}), wo = O.counter("voltro_db_queries_total", { description: "Database operations executed, by dialect and operation kind." }), To = O.histogram("voltro_db_query_duration_seconds", Co, "Database operation duration in seconds, by dialect and operation kind."), Eo = O.counter("voltro_db_errors_total", { description: "Database operations that threw, by dialect and operation kind." }), Do = 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." }), Oo = 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." }), ko = [], Ao = /* @__PURE__ */ new Map(), jo = /* @__PURE__ */ new Map(), Mo = /* @__PURE__ */ new Map(), No = (e, t) => {
|
|
1831
|
+
let n = `${e}\u0000${t}`, r = Ao.get(n);
|
|
1772
1832
|
if (r !== void 0) return r;
|
|
1773
|
-
let i = (n) =>
|
|
1774
|
-
count: i(
|
|
1775
|
-
duration: i(
|
|
1776
|
-
errors: i(
|
|
1833
|
+
let i = (n) => O.tagged(O.tagged(n, "dialect", e), "op", t), a = {
|
|
1834
|
+
count: i(wo),
|
|
1835
|
+
duration: i(To),
|
|
1836
|
+
errors: i(Eo)
|
|
1777
1837
|
};
|
|
1778
|
-
return
|
|
1779
|
-
},
|
|
1780
|
-
|
|
1781
|
-
},
|
|
1782
|
-
let n = Math.max(0, (
|
|
1783
|
-
n === 0 ?
|
|
1784
|
-
let r =
|
|
1785
|
-
r === void 0 && (r =
|
|
1786
|
-
},
|
|
1787
|
-
let t =
|
|
1788
|
-
t.count.unsafeUpdate(1,
|
|
1789
|
-
},
|
|
1838
|
+
return Ao.set(n, a), a;
|
|
1839
|
+
}, Po = () => {
|
|
1840
|
+
Ao.clear(), jo.clear(), Mo.clear();
|
|
1841
|
+
}, Fo = () => Ao.size + jo.size + Mo.size, Io = /* @__PURE__ */ new Map(), Lo = (e, t) => {
|
|
1842
|
+
let n = Math.max(0, (Io.get(e) ?? 0) + t);
|
|
1843
|
+
n === 0 ? Io.delete(e) : Io.set(e, n);
|
|
1844
|
+
let r = jo.get(e);
|
|
1845
|
+
r === void 0 && (r = O.tagged(Do, "dialect", e), jo.set(e, r)), r.unsafeUpdate(n, ko);
|
|
1846
|
+
}, Ro = (e) => Io.get(e) ?? 0, zo = (e) => {
|
|
1847
|
+
let t = No(String(e.dialect), e.op);
|
|
1848
|
+
t.count.unsafeUpdate(1, ko), t.duration.unsafeUpdate(e.durationMs / 1e3, ko), e.status === "error" && t.errors.unsafeUpdate(1, ko);
|
|
1849
|
+
}, Bo = async (e, t, n) => {
|
|
1790
1850
|
let r = performance.now(), i = String(e);
|
|
1791
|
-
|
|
1851
|
+
Lo(i, 1);
|
|
1792
1852
|
let a = "ok";
|
|
1793
1853
|
try {
|
|
1794
1854
|
return await n();
|
|
1795
1855
|
} catch (e) {
|
|
1796
1856
|
throw a = "error", e;
|
|
1797
1857
|
} finally {
|
|
1798
|
-
|
|
1858
|
+
Lo(i, -1), zo({
|
|
1799
1859
|
dialect: e,
|
|
1800
1860
|
op: t,
|
|
1801
1861
|
durationMs: performance.now() - r,
|
|
1802
1862
|
status: a
|
|
1803
1863
|
});
|
|
1804
1864
|
}
|
|
1805
|
-
},
|
|
1865
|
+
}, Vo = 3e5, Ho = (e) => {
|
|
1806
1866
|
if (e == null || e === "") return;
|
|
1807
1867
|
let t = Number(e);
|
|
1808
1868
|
return Number.isFinite(t) && t >= 0 ? Math.floor(t) : void 0;
|
|
1809
|
-
},
|
|
1810
|
-
let n =
|
|
1869
|
+
}, Uo = (e, t = process.env) => Ho(t.VOLTRO_DB_EAGER_FALLBACK_WARN_INTERVAL_MS) ?? Ho(e) ?? 3e5, Wo = (e, t = {}) => {
|
|
1870
|
+
let n = Uo(t.warnIntervalMs), r = t.now ?? (() => Date.now()), i = /* @__PURE__ */ new Map();
|
|
1811
1871
|
return (t) => {
|
|
1812
|
-
let a = `${t.dialect} ${t.reason}`, o =
|
|
1813
|
-
o === void 0 && (o =
|
|
1872
|
+
let a = `${t.dialect} ${t.reason}`, o = Mo.get(a);
|
|
1873
|
+
o === void 0 && (o = O.tagged(O.tagged(Oo, "dialect", String(t.dialect)), "reason", t.reason), Mo.set(a, o)), o.unsafeUpdate(1, ko);
|
|
1814
1874
|
let s = `${t.table}\u0000${t.reason}`, c = i.get(s), l = c === void 0 || n > 0 && r() - c >= n, u = {
|
|
1815
1875
|
table: t.table,
|
|
1816
1876
|
dialect: String(t.dialect),
|
|
@@ -1824,24 +1884,24 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
1824
1884
|
}
|
|
1825
1885
|
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);
|
|
1826
1886
|
};
|
|
1827
|
-
},
|
|
1828
|
-
if (
|
|
1829
|
-
throw
|
|
1830
|
-
},
|
|
1831
|
-
let t = 0, n =
|
|
1887
|
+
}, Go = (e) => {
|
|
1888
|
+
if (Mt.isSuccess(e)) return e.value;
|
|
1889
|
+
throw kt.squash(e.cause);
|
|
1890
|
+
}, Ko = "10 millis", qo = 3, Jo = async (e) => {
|
|
1891
|
+
let t = 0, n = D.suspend(() => {
|
|
1832
1892
|
let n = ++t;
|
|
1833
|
-
return e.withTransaction(
|
|
1834
|
-
if (
|
|
1835
|
-
let r = t.value, i =
|
|
1893
|
+
return e.withTransaction(D.flatMap(D.serviceOption(zt), (t) => {
|
|
1894
|
+
if (k.isNone(t)) return D.fail(/* @__PURE__ */ Error(`${e.label}: TransactionConnection unexpectedly missing inside withTransaction.`));
|
|
1895
|
+
let r = t.value, i = D.tryPromise({
|
|
1836
1896
|
try: () => e.body(r, n),
|
|
1837
1897
|
catch: (e) => e
|
|
1838
1898
|
});
|
|
1839
|
-
return e.prepare === void 0 ? i :
|
|
1840
|
-
})).pipe(
|
|
1841
|
-
}), r =
|
|
1842
|
-
return
|
|
1843
|
-
},
|
|
1844
|
-
let t =
|
|
1899
|
+
return e.prepare === void 0 ? i : D.flatMap(e.prepare(r), () => i);
|
|
1900
|
+
})).pipe(D.catchAllDefect((t) => e.isRetryable(t) ? D.fail(t) : D.die(t)));
|
|
1901
|
+
}), r = Ft.exponential(Ko).pipe(Ft.compose(Ft.recurs(qo)), Ft.whileInput(e.isRetryable)), i = n.pipe(D.retry(r), D.withSpan(e.span.name, { attributes: { ...e.span.attributes } }));
|
|
1902
|
+
return Bo(e.dialect, "transaction", async () => Go(await e.runPromiseExit(e.wrapProgram === void 0 ? i : e.wrapProgram(i))));
|
|
1903
|
+
}, Yo = async (e) => {
|
|
1904
|
+
let t = Ua(), n = t === void 0 ? (e) => e() : (e) => Ha(t, e), r = await Jo({
|
|
1845
1905
|
...e,
|
|
1846
1906
|
body: (r) => {
|
|
1847
1907
|
let i = e.makeView(r, t);
|
|
@@ -1852,14 +1912,14 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
1852
1912
|
}
|
|
1853
1913
|
});
|
|
1854
1914
|
return r.view.commitEvents(), r.result;
|
|
1855
|
-
},
|
|
1856
|
-
table:
|
|
1857
|
-
id:
|
|
1858
|
-
expected:
|
|
1859
|
-
actual:
|
|
1860
|
-
}) {},
|
|
1915
|
+
}, Xo = class extends A.TaggedError()("VersionConflict", {
|
|
1916
|
+
table: A.String,
|
|
1917
|
+
id: A.String,
|
|
1918
|
+
expected: A.Number,
|
|
1919
|
+
actual: A.NullOr(A.Number)
|
|
1920
|
+
}) {}, Zo = (e) => {
|
|
1861
1921
|
for (let [t, n] of Object.entries(e)) if (n?.definition?.versionColumn === !0) return t;
|
|
1862
|
-
},
|
|
1922
|
+
}, Qo = (e) => {
|
|
1863
1923
|
let { versionColumn: t, patch: n } = e;
|
|
1864
1924
|
if (t === void 0) return {
|
|
1865
1925
|
nextVersion: void 0,
|
|
@@ -1872,28 +1932,28 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
1872
1932
|
expected: i,
|
|
1873
1933
|
patch: a
|
|
1874
1934
|
};
|
|
1875
|
-
},
|
|
1876
|
-
if (e.expected !== void 0 && (e.current === null || e.current !== e.expected)) return new
|
|
1935
|
+
}, $o = (e) => {
|
|
1936
|
+
if (e.expected !== void 0 && (e.current === null || e.current !== e.expected)) return new Xo({
|
|
1877
1937
|
table: e.table,
|
|
1878
1938
|
id: e.id,
|
|
1879
1939
|
expected: e.expected,
|
|
1880
1940
|
actual: e.current
|
|
1881
1941
|
});
|
|
1882
|
-
},
|
|
1883
|
-
id:
|
|
1884
|
-
fields: { expiresAt:
|
|
1942
|
+
}, es = 1, ts = "voltro/expires", ns = () => it({
|
|
1943
|
+
id: ts,
|
|
1944
|
+
fields: { expiresAt: C().nullable() },
|
|
1885
1945
|
behaviors: { defaultWhere: () => "expiresAt IS NULL OR expiresAt > now()" }
|
|
1886
|
-
}),
|
|
1887
|
-
id:
|
|
1946
|
+
}), rs = "voltro/localFirst", is = () => it({
|
|
1947
|
+
id: rs,
|
|
1888
1948
|
fields: {}
|
|
1889
|
-
}),
|
|
1949
|
+
}), as = (e) => e.appliedMixins.some((e) => e.id === rs), os = (e) => {
|
|
1890
1950
|
let t = [];
|
|
1891
|
-
for (let n of Object.values(e))
|
|
1951
|
+
for (let n of Object.values(e)) as(n) && t.push(n.tableName);
|
|
1892
1952
|
return t;
|
|
1893
|
-
},
|
|
1894
|
-
let i =
|
|
1953
|
+
}, ss = class extends jt.TaggedError("TableStreamError") {}, cs = 1e3, ls = (e, t, n, r) => {
|
|
1954
|
+
let i = k.match(r, {
|
|
1895
1955
|
onNone: () => e.where,
|
|
1896
|
-
onSome: (n) => e.where ?
|
|
1956
|
+
onSome: (n) => e.where ? ma(e.where, $i(t, n)) : $i(t, n)
|
|
1897
1957
|
});
|
|
1898
1958
|
return {
|
|
1899
1959
|
table: e.table,
|
|
@@ -1908,19 +1968,19 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
1908
1968
|
...e.includeDeleted === void 0 ? {} : { includeDeleted: e.includeDeleted },
|
|
1909
1969
|
...e.crossTenant === void 0 ? {} : { crossTenant: e.crossTenant }
|
|
1910
1970
|
};
|
|
1911
|
-
},
|
|
1912
|
-
let n = t.pk ?? "id", r = t.chunkSize ??
|
|
1913
|
-
return
|
|
1914
|
-
let a =
|
|
1915
|
-
try: () => e.query(
|
|
1916
|
-
catch: (e) => new
|
|
1971
|
+
}, us = (e, t) => {
|
|
1972
|
+
let n = t.pk ?? "id", r = t.chunkSize ?? cs;
|
|
1973
|
+
return It.paginateChunkEffect(k.none(), (i) => {
|
|
1974
|
+
let a = D.tryPromise({
|
|
1975
|
+
try: () => e.query(ls(t, n, r, i)),
|
|
1976
|
+
catch: (e) => new ss({
|
|
1917
1977
|
table: t.table,
|
|
1918
1978
|
cause: e
|
|
1919
1979
|
})
|
|
1920
1980
|
});
|
|
1921
|
-
return (t.retry ? a.pipe(
|
|
1981
|
+
return (t.retry ? a.pipe(D.retry(t.retry)) : a).pipe(D.map((e) => [At.fromIterable(e), e.length === r && e.length > 0 ? k.some(k.some(e[e.length - 1][n])) : k.none()]));
|
|
1922
1982
|
});
|
|
1923
|
-
},
|
|
1983
|
+
}, ds = (e) => {
|
|
1924
1984
|
let t = e.alpha ?? .5;
|
|
1925
1985
|
if (t < 0 || t > 1) throw Error(`hybridSearch: alpha must be in [0, 1], got ${t}`);
|
|
1926
1986
|
return (n) => {
|
|
@@ -1934,7 +1994,7 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
1934
1994
|
queryText: e.vector.query,
|
|
1935
1995
|
distance: e.vector.distance ?? "cosine",
|
|
1936
1996
|
alpha: t
|
|
1937
|
-
}, i =
|
|
1997
|
+
}, i = me(n.table, e.fts.indexName, n.fullTextIndexes);
|
|
1938
1998
|
return {
|
|
1939
1999
|
...n,
|
|
1940
2000
|
annClause: r,
|
|
@@ -1947,19 +2007,19 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
1947
2007
|
}
|
|
1948
2008
|
};
|
|
1949
2009
|
};
|
|
1950
|
-
},
|
|
2010
|
+
}, fs = async (e, t) => {
|
|
1951
2011
|
let n = e.as ?? "embedding", r = t.row[e.from];
|
|
1952
2012
|
if (typeof r != "string" || r.length === 0) return {};
|
|
1953
2013
|
let i = await t.embed(r);
|
|
1954
2014
|
return { [n]: i };
|
|
1955
|
-
},
|
|
2015
|
+
}, ps = (e) => {
|
|
1956
2016
|
if (!Number.isInteger(e.dimensions) || e.dimensions <= 0) throw Error(`vectorEmbedding: dimensions must be a positive integer, got ${String(e.dimensions)}.`);
|
|
1957
|
-
let
|
|
1958
|
-
return
|
|
2017
|
+
let t = e.as ?? "embedding", n = (t) => fs(e, t);
|
|
2018
|
+
return it({
|
|
1959
2019
|
id: "voltro/vectorEmbedding",
|
|
1960
|
-
fields: { [
|
|
2020
|
+
fields: { [t]: pt(e.dimensions) },
|
|
1961
2021
|
...e.index === !1 ? {} : { indexes: [{
|
|
1962
|
-
fields: [
|
|
2022
|
+
fields: [t],
|
|
1963
2023
|
kind: "hnsw",
|
|
1964
2024
|
kindOptions: { hnsw: {
|
|
1965
2025
|
...e.index?.m === void 0 ? {} : { m: e.index.m },
|
|
@@ -1968,23 +2028,23 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
1968
2028
|
} }
|
|
1969
2029
|
}] },
|
|
1970
2030
|
behaviors: {
|
|
1971
|
-
beforeInsert:
|
|
1972
|
-
beforeUpdate:
|
|
2031
|
+
beforeInsert: n,
|
|
2032
|
+
beforeUpdate: n
|
|
1973
2033
|
}
|
|
1974
2034
|
});
|
|
1975
|
-
},
|
|
2035
|
+
}, ms = 63, hs = "br_pr", J = class extends Error {
|
|
1976
2036
|
_tag = "BranchNameInvalid";
|
|
1977
2037
|
constructor(e) {
|
|
1978
2038
|
super(e), this.name = "BranchNameInvalid";
|
|
1979
2039
|
}
|
|
1980
|
-
},
|
|
2040
|
+
}, gs = (e, t) => {
|
|
1981
2041
|
if (!Number.isInteger(t) || t < 0) throw new J(`prNumber must be a non-negative integer, got ${String(t)}`);
|
|
1982
|
-
let n =
|
|
2042
|
+
let n = Tr(e);
|
|
1983
2043
|
if (n.replace(/_/g, "") === "") throw new J(`app slug '${e}' has no usable identifier characters`);
|
|
1984
|
-
let r = `${
|
|
1985
|
-
if (r.length >
|
|
2044
|
+
let r = `${hs}${t}_${n}`;
|
|
2045
|
+
if (r.length > ms) throw new J(`branch namespace '${r}' exceeds the ${ms}-byte identifier limit — use a shorter app slug`);
|
|
1986
2046
|
return r;
|
|
1987
|
-
},
|
|
2047
|
+
}, _s = (e) => e.startsWith(hs), vs = {
|
|
1988
2048
|
requested: {
|
|
1989
2049
|
provision: "provisioning",
|
|
1990
2050
|
destroy: "destroying"
|
|
@@ -2003,18 +2063,18 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
2003
2063
|
fail: "failed"
|
|
2004
2064
|
},
|
|
2005
2065
|
destroyed: {}
|
|
2006
|
-
},
|
|
2066
|
+
}, ys = class extends Error {
|
|
2007
2067
|
from;
|
|
2008
2068
|
event;
|
|
2009
2069
|
_tag = "BranchTransitionInvalid";
|
|
2010
2070
|
constructor(e, t) {
|
|
2011
2071
|
super(`invalid branch transition: ${e} --${t}-->`), this.from = e, this.event = t, this.name = "BranchTransitionInvalid";
|
|
2012
2072
|
}
|
|
2013
|
-
},
|
|
2014
|
-
let n =
|
|
2015
|
-
if (n === void 0) throw new
|
|
2073
|
+
}, bs = (e, t) => {
|
|
2074
|
+
let n = vs[e][t];
|
|
2075
|
+
if (n === void 0) throw new ys(e, t);
|
|
2016
2076
|
return n;
|
|
2017
|
-
},
|
|
2077
|
+
}, xs = (e, t, n, r, i = [], a = []) => {
|
|
2018
2078
|
if (n === "copy" && (r === void 0 || r === "")) throw new J("seed 'copy' requires a parentNamespace to snapshot from");
|
|
2019
2079
|
let o = [{
|
|
2020
2080
|
kind: "create-namespace",
|
|
@@ -2044,13 +2104,13 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
2044
2104
|
kind: "seed",
|
|
2045
2105
|
detail: `run boot seeds into ${e}`
|
|
2046
2106
|
}), o;
|
|
2047
|
-
},
|
|
2048
|
-
if (!
|
|
2107
|
+
}, Ss = (e) => {
|
|
2108
|
+
if (!_s(e)) throw new J(`refusing to plan teardown of '${e}' — not a branch namespace`);
|
|
2049
2109
|
return [{
|
|
2050
2110
|
kind: "drop-namespace",
|
|
2051
2111
|
detail: e
|
|
2052
2112
|
}];
|
|
2053
|
-
},
|
|
2113
|
+
}, Cs = (e) => {
|
|
2054
2114
|
if (e === void 0 || e === "") return !1;
|
|
2055
2115
|
try {
|
|
2056
2116
|
let t = new URL(e).hostname.toLowerCase();
|
|
@@ -2058,27 +2118,27 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
2058
2118
|
} catch {
|
|
2059
2119
|
return /\bneon\.(tech|build)\b/i.test(e);
|
|
2060
2120
|
}
|
|
2061
|
-
},
|
|
2121
|
+
}, ws = (e) => e.prefer === void 0 ? e.seed === "copy" && Cs(e.dbUrl) ? "neon-cow" : "namespace" : e.prefer, Ts = (e, t = {}) => [{
|
|
2062
2122
|
kind: "neon-branch-create",
|
|
2063
2123
|
detail: `${t.parentBranch ?? "main"} → ${e} (copy-on-write)`
|
|
2064
|
-
}],
|
|
2065
|
-
if (!
|
|
2124
|
+
}], Es = (e) => {
|
|
2125
|
+
if (!_s(e)) throw new J(`refusing to plan teardown of '${e}' — not a branch namespace`);
|
|
2066
2126
|
return [{
|
|
2067
2127
|
kind: "neon-branch-delete",
|
|
2068
2128
|
detail: e
|
|
2069
2129
|
}];
|
|
2070
|
-
},
|
|
2130
|
+
}, Ds = (e) => e.mechanism === "neon-cow" ? Ts(e.branchId, e.neonParentBranch === void 0 ? {} : { parentBranch: e.neonParentBranch }) : xs(e.branchId, e.tableNames, e.seed, e.parentNamespace, e.foreignKeys, e.indexNames), Os = (e, t) => e === "neon-cow" ? Es(t) : Ss(t), ks = (e, t, n) => {
|
|
2071
2131
|
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);
|
|
2072
2132
|
return {
|
|
2073
2133
|
evict: i,
|
|
2074
2134
|
rejectNew: r.filter((e) => !a.has(e.namespace)).length >= t.maxBranches
|
|
2075
2135
|
};
|
|
2076
|
-
},
|
|
2077
|
-
let n =
|
|
2136
|
+
}, As = async (e, t) => {
|
|
2137
|
+
let n = gs(e.appSlug, e.prNumber), r = ws({
|
|
2078
2138
|
seed: e.seed,
|
|
2079
2139
|
...e.dbUrl === void 0 ? {} : { dbUrl: e.dbUrl },
|
|
2080
2140
|
...e.prefer === void 0 ? {} : { prefer: e.prefer }
|
|
2081
|
-
}), i =
|
|
2141
|
+
}), i = Ds({
|
|
2082
2142
|
mechanism: r,
|
|
2083
2143
|
branchId: n,
|
|
2084
2144
|
tableNames: e.tableNames,
|
|
@@ -2107,15 +2167,15 @@ var Bt = (e) => typeof e == "string" && e !== "" ? e : null, Vt = async (e, t, n
|
|
|
2107
2167
|
mechanism: r,
|
|
2108
2168
|
steps: i
|
|
2109
2169
|
};
|
|
2110
|
-
},
|
|
2111
|
-
let r =
|
|
2170
|
+
}, js = async (e, t, n) => {
|
|
2171
|
+
let r = Os(t, e);
|
|
2112
2172
|
return t === "neon-cow" ? await n.neonBranchDelete(e) : await n.dropNamespace(e), r;
|
|
2113
|
-
},
|
|
2173
|
+
}, Ms = (e, t, n) => ks(e, t, n), Y = (e) => `"${e.replace(/"/g, "\"\"")}"`, Ns = {
|
|
2114
2174
|
cascade: "CASCADE",
|
|
2115
2175
|
restrict: "RESTRICT",
|
|
2116
2176
|
setNull: "SET NULL",
|
|
2117
2177
|
noAction: "NO ACTION"
|
|
2118
|
-
}, X = (e) => `'${e.replace(/'/g, "''")}'`,
|
|
2178
|
+
}, X = (e) => `'${e.replace(/'/g, "''")}'`, Ps = (e, t) => {
|
|
2119
2179
|
let n = t.columns.map(X).join(", ");
|
|
2120
2180
|
return `DO $voltro_branch$
|
|
2121
2181
|
DECLARE derived name;
|
|
@@ -2142,10 +2202,10 @@ BEGIN
|
|
|
2142
2202
|
END IF;
|
|
2143
2203
|
END
|
|
2144
2204
|
$voltro_branch$`;
|
|
2145
|
-
},
|
|
2146
|
-
let n = t.onDelete === void 0 ? "" : ` ON DELETE ${
|
|
2205
|
+
}, Fs = (e, t) => {
|
|
2206
|
+
let n = t.onDelete === void 0 ? "" : ` ON DELETE ${Ns[t.onDelete]}`, r = t.onUpdate === void 0 ? "" : ` ON UPDATE ${Ns[t.onUpdate]}`;
|
|
2147
2207
|
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}`;
|
|
2148
|
-
},
|
|
2208
|
+
}, Is = (e) => {
|
|
2149
2209
|
let t = () => {
|
|
2150
2210
|
throw Error("namespace branch executor: Neon ops require a neon-cow executor (use a Neon connection for copy-on-write branches)");
|
|
2151
2211
|
};
|
|
@@ -2153,24 +2213,24 @@ $voltro_branch$`;
|
|
|
2153
2213
|
createNamespace: (t) => e.run(`CREATE SCHEMA IF NOT EXISTS ${Y(t)}`),
|
|
2154
2214
|
createTable: (t, n) => e.run(`CREATE TABLE IF NOT EXISTS ${Y(t)}.${Y(n)} (LIKE ${Y(n)} INCLUDING ALL)`),
|
|
2155
2215
|
copyTable: (t, n, r) => e.run(`INSERT INTO ${Y(n)}.${Y(r)} SELECT * FROM ${Y(t)}.${Y(r)}`),
|
|
2156
|
-
addForeignKey: (t, n) => e.run(
|
|
2157
|
-
restoreIndexName: (t, n) => e.run(
|
|
2216
|
+
addForeignKey: (t, n) => e.run(Fs(t, n)),
|
|
2217
|
+
restoreIndexName: (t, n) => e.run(Ps(t, n)),
|
|
2158
2218
|
dropNamespace: (t) => e.run(`DROP SCHEMA IF EXISTS ${Y(t)} CASCADE`),
|
|
2159
2219
|
neonBranchCreate: t,
|
|
2160
2220
|
neonBranchDelete: t
|
|
2161
2221
|
};
|
|
2162
|
-
},
|
|
2222
|
+
}, Ls = class extends Error {
|
|
2163
2223
|
_tag = "TenantResidencyUnresolved";
|
|
2164
2224
|
constructor(e) {
|
|
2165
2225
|
super(e), this.name = "TenantResidencyUnresolved";
|
|
2166
2226
|
}
|
|
2167
|
-
},
|
|
2227
|
+
}, Rs = class extends Error {
|
|
2168
2228
|
region;
|
|
2169
2229
|
_tag = "TenantRegionUnavailable";
|
|
2170
2230
|
constructor(e, t) {
|
|
2171
2231
|
super(t), this.region = e, this.name = "TenantRegionUnavailable";
|
|
2172
2232
|
}
|
|
2173
|
-
},
|
|
2233
|
+
}, zs, Bs = (e) => {
|
|
2174
2234
|
if (e.homes === void 0) throw Error("setResidencyConfig: `homes` is required");
|
|
2175
2235
|
if (e.servableRegions === void 0 || e.servableRegions.length === 0) throw Error("setResidencyConfig: `servableRegions` must be non-empty (which regions this deployment serves)");
|
|
2176
2236
|
let t = /* @__PURE__ */ new Map();
|
|
@@ -2179,55 +2239,55 @@ $voltro_branch$`;
|
|
|
2179
2239
|
if (e !== void 0 && e !== n.region) throw Error(`residency: tenant '${n.tenantId}' is mapped to two regions ('${e}' and '${n.region}')`);
|
|
2180
2240
|
t.set(n.tenantId, n.region);
|
|
2181
2241
|
}
|
|
2182
|
-
return
|
|
2183
|
-
},
|
|
2184
|
-
|
|
2185
|
-
},
|
|
2186
|
-
if (e == null || e === "") throw new
|
|
2242
|
+
return zs = e, e;
|
|
2243
|
+
}, Vs = () => zs, Hs = () => {
|
|
2244
|
+
zs = void 0;
|
|
2245
|
+
}, Us = (e, t) => {
|
|
2246
|
+
if (e == null || e === "") throw new Ls("residency is on but the request has no resolvable tenant — refusing to bind a store");
|
|
2187
2247
|
let n = t.homes.find((t) => t.tenantId === e);
|
|
2188
|
-
if (n === void 0) throw new
|
|
2248
|
+
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)`);
|
|
2189
2249
|
return n;
|
|
2190
|
-
},
|
|
2191
|
-
let n =
|
|
2250
|
+
}, Ws = (e, t) => t.servableRegions.includes(e), Gs = (e, t) => {
|
|
2251
|
+
let n = Us(e.tenantId, t), r = Er(n.tenantId);
|
|
2192
2252
|
return {
|
|
2193
2253
|
region: n.region,
|
|
2194
2254
|
namespace: r,
|
|
2195
2255
|
...n.connectionKey === void 0 ? {} : { connectionKey: n.connectionKey }
|
|
2196
2256
|
};
|
|
2197
|
-
},
|
|
2198
|
-
let r =
|
|
2199
|
-
if (!
|
|
2257
|
+
}, Ks = (e, t, n) => {
|
|
2258
|
+
let r = Gs(e, t);
|
|
2259
|
+
if (!Ws(r.region, t)) throw new Rs(r.region, `tenant homed in region '${r.region}', which this deployment does not serve — route to the home region`);
|
|
2200
2260
|
let i = n.get(r.region);
|
|
2201
|
-
if (i === void 0) throw new
|
|
2261
|
+
if (i === void 0) throw new Rs(r.region, `no store handle for home region '${r.region}' (declared servable but not wired) — failing closed`);
|
|
2202
2262
|
return {
|
|
2203
2263
|
store: i,
|
|
2204
2264
|
placement: r
|
|
2205
2265
|
};
|
|
2206
|
-
},
|
|
2207
|
-
let { store: i, placement: a } =
|
|
2266
|
+
}, qs = async (e, t, n, r) => {
|
|
2267
|
+
let { store: i, placement: a } = Ks(e, t, n);
|
|
2208
2268
|
return await r(i, a), a;
|
|
2209
|
-
},
|
|
2269
|
+
}, Js = (e) => {
|
|
2210
2270
|
if (typeof e == "string") return e;
|
|
2211
2271
|
if ("jsonPath" in e) {
|
|
2212
2272
|
let { column: t, path: n, numeric: r } = e.jsonPath;
|
|
2213
2273
|
return `(json:${t}->${n.join(".")}${r ? "::num" : ""})`;
|
|
2214
2274
|
}
|
|
2215
2275
|
return `(${e.expr})`;
|
|
2216
|
-
}, Z = (e) => e.map(
|
|
2276
|
+
}, Z = (e) => e.map(Js), Ys = (e, t) => {
|
|
2217
2277
|
if (e.length !== t.length) return !1;
|
|
2218
|
-
for (let n = 0; n < e.length; n++) if (
|
|
2278
|
+
for (let n = 0; n < e.length; n++) if (Js(e[n]) !== Js(t[n])) return !1;
|
|
2219
2279
|
return !0;
|
|
2220
|
-
},
|
|
2280
|
+
}, Xs = (e, t) => {
|
|
2221
2281
|
if (e.length >= t.length) return !1;
|
|
2222
|
-
for (let n = 0; n < e.length; n++) if (
|
|
2282
|
+
for (let n = 0; n < e.length; n++) if (Js(e[n]) !== Js(t[n])) return !1;
|
|
2223
2283
|
return !0;
|
|
2224
|
-
},
|
|
2284
|
+
}, Zs = (e) => {
|
|
2225
2285
|
let t = [], n = e.appliedIndexes, r = e.tableName;
|
|
2226
2286
|
for (let e = 0; e < n.length; e++) {
|
|
2227
2287
|
let i = n[e];
|
|
2228
2288
|
for (let a = e + 1; a < n.length; a++) {
|
|
2229
2289
|
let e = n[a];
|
|
2230
|
-
if (
|
|
2290
|
+
if (Ys(i.fields, e.fields)) {
|
|
2231
2291
|
let [n, a] = i.name < e.name ? [i, e] : [e, i];
|
|
2232
2292
|
t.push({
|
|
2233
2293
|
kind: "duplicate-fields",
|
|
@@ -2238,13 +2298,13 @@ $voltro_branch$`;
|
|
|
2238
2298
|
});
|
|
2239
2299
|
continue;
|
|
2240
2300
|
}
|
|
2241
|
-
|
|
2301
|
+
Xs(i.fields, e.fields) ? t.push({
|
|
2242
2302
|
kind: "redundant-prefix",
|
|
2243
2303
|
table: r,
|
|
2244
2304
|
redundant: i,
|
|
2245
2305
|
coveredBy: e,
|
|
2246
2306
|
message: `'${r}' index '${i.name}' on [${Z(i.fields).join(", ")}] is a leading prefix of '${e.name}' on [${Z(e.fields).join(", ")}]. Every B-tree dialect we support (Postgres / MySQL / MariaDB / MSSQL / SQLite) can serve a [${Z(i.fields).join(", ")}] query from '${e.name}' too via the leading-prefix rule, so '${i.name}' adds write cost without read benefit. Drop '${i.name}' — unless you specifically need a smaller index for cache locality on a write-heavy table (rare; profile first).`
|
|
2247
|
-
}) :
|
|
2307
|
+
}) : Xs(e.fields, i.fields) && t.push({
|
|
2248
2308
|
kind: "redundant-prefix",
|
|
2249
2309
|
table: r,
|
|
2250
2310
|
redundant: e,
|
|
@@ -2254,23 +2314,23 @@ $voltro_branch$`;
|
|
|
2254
2314
|
}
|
|
2255
2315
|
}
|
|
2256
2316
|
return t;
|
|
2257
|
-
},
|
|
2317
|
+
}, Qs = (e) => {
|
|
2258
2318
|
let t = [];
|
|
2259
|
-
for (let n of e) t.push(...
|
|
2319
|
+
for (let n of e) t.push(...Zs(n));
|
|
2260
2320
|
return t;
|
|
2261
|
-
},
|
|
2262
|
-
let n = t.color ?? !0, r = t.indent ?? " ", i = (e) => Q(n,
|
|
2321
|
+
}, $s = "\x1B[", ec = `${$s}38;2;245;158;11m`, tc = `${$s}38;2;16;185;129m`, nc = (e, t) => `${e}${t}${j.reset}`, Q = (e, t, n) => e ? typeof t == "function" ? t(n) : nc(t, n) : n, rc = (e, t = {}) => {
|
|
2322
|
+
let n = t.color ?? !0, r = t.indent ?? " ", i = (e) => Q(n, j.dim, e.padEnd(11)), a = (e) => Q(n, (e) => j.bold(j.brand(e)), e), o = (e) => Q(n, j.brightRed24, e), s = (e) => Q(n, tc, e), c = (e) => Q(n, ec, e), l = (e) => Q(n, j.dim, e), u = `${c("index audit")} ${l("·")} ${Q(n, j.bold, e.kind)}`, d = e.redundant.fields.length, f = Z(e.coveredBy.fields.slice(d)), p = (e, t) => {
|
|
2263
2323
|
let n = e.slice(0, t), r = e.slice(t), i = [];
|
|
2264
2324
|
return n.length > 0 && i.push(s(`[${n.join(", ")}]`)), r.length > 0 && i.push(c(`+ [${r.join(", ")}]`)), i.join(" ");
|
|
2265
2325
|
}, m = [];
|
|
2266
|
-
return m.push(u), m.push(""), m.push(`${i("table")}${a(e.table)}`), m.push(""), m.push(`${i("redundant")}${o(e.redundant.name)}`), m.push(`${i("")}${p(Z(e.redundant.fields), d)}`), m.push(""), m.push(`${i("covered by")}${s(e.coveredBy.name)}`), m.push(`${i("")}${p(Z(e.coveredBy.fields), d)}`), f.length > 0 && m.push(`${i("")}${l(`└ extra columns: ${f.join(", ")}`)}`), m.push(""), e.kind === "redundant-prefix" ? (m.push(`${i("why")}B-tree indexes serve queries that filter on a LEADING PREFIX of`), m.push(`${i("")}their column list. The wider index already covers every`), m.push(`${i("")}query the narrower one can serve.`), m.push(`${i("")}${l("Same rule on Postgres / MySQL / MariaDB / MSSQL / SQLite.")}`)) : (m.push(`${i("why")}Two indexes on the same columns under different names.`), m.push(`${i("")}The B-tree engine builds both — same coverage, double cost.`), m.push(`${i("")}${l("Same rule on Postgres / MySQL / MariaDB / MSSQL / SQLite.")}`)), m.push(""), m.push(`${i("cost")}Every ${a("INSERT")} / ${a("UPDATE")} / ${a("DELETE")} on this table writes`), m.push(`${i("")}to ${Q(n,
|
|
2267
|
-
},
|
|
2326
|
+
return m.push(u), m.push(""), m.push(`${i("table")}${a(e.table)}`), m.push(""), m.push(`${i("redundant")}${o(e.redundant.name)}`), m.push(`${i("")}${p(Z(e.redundant.fields), d)}`), m.push(""), m.push(`${i("covered by")}${s(e.coveredBy.name)}`), m.push(`${i("")}${p(Z(e.coveredBy.fields), d)}`), f.length > 0 && m.push(`${i("")}${l(`└ extra columns: ${f.join(", ")}`)}`), m.push(""), e.kind === "redundant-prefix" ? (m.push(`${i("why")}B-tree indexes serve queries that filter on a LEADING PREFIX of`), m.push(`${i("")}their column list. The wider index already covers every`), m.push(`${i("")}query the narrower one can serve.`), m.push(`${i("")}${l("Same rule on Postgres / MySQL / MariaDB / MSSQL / SQLite.")}`)) : (m.push(`${i("why")}Two indexes on the same columns under different names.`), m.push(`${i("")}The B-tree engine builds both — same coverage, double cost.`), m.push(`${i("")}${l("Same rule on Postgres / MySQL / MariaDB / MSSQL / SQLite.")}`)), m.push(""), m.push(`${i("cost")}Every ${a("INSERT")} / ${a("UPDATE")} / ${a("DELETE")} on this table writes`), m.push(`${i("")}to ${Q(n, 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");
|
|
2327
|
+
}, ic = (e, { apply: t, undo: n }) => ({
|
|
2268
2328
|
name: e,
|
|
2269
2329
|
apply: t,
|
|
2270
2330
|
undo: n
|
|
2271
|
-
}),
|
|
2331
|
+
}), ac = (e) => {
|
|
2272
2332
|
if (!/^\d{14}_/.test(e.id)) throw Error(`migration "${e.id}": id must start with a 14-digit timestamp followed by "_" (convention: <YYYYMMDDHHMMSS>_<slug>)`);
|
|
2273
|
-
let t = e.steps({ step:
|
|
2333
|
+
let t = e.steps({ step: ic });
|
|
2274
2334
|
if (t.length === 0) throw Error(`migration "${e.id}": at least one step is required`);
|
|
2275
2335
|
return {
|
|
2276
2336
|
__migration: !0,
|
|
@@ -2278,93 +2338,109 @@ $voltro_branch$`;
|
|
|
2278
2338
|
name: e.name,
|
|
2279
2339
|
steps: t
|
|
2280
2340
|
};
|
|
2281
|
-
},
|
|
2282
|
-
id:
|
|
2283
|
-
name:
|
|
2284
|
-
hash:
|
|
2285
|
-
status:
|
|
2286
|
-
appliedAt:
|
|
2287
|
-
durationMs:
|
|
2288
|
-
errorMessage:
|
|
2289
|
-
errorStack:
|
|
2290
|
-
workflowRunId:
|
|
2291
|
-
createdAt:
|
|
2292
|
-
updatedAt:
|
|
2293
|
-
}).index(["status"]),
|
|
2294
|
-
id:
|
|
2295
|
-
name:
|
|
2296
|
-
lifecycle:
|
|
2297
|
-
fingerprint:
|
|
2298
|
-
cronSchedule:
|
|
2299
|
-
watchedTables:
|
|
2300
|
-
nextRunAt:
|
|
2301
|
-
lastRunStatus:
|
|
2302
|
-
lastRunAt:
|
|
2303
|
-
lastRunDurationMs:
|
|
2304
|
-
lastRunRowsTouched:
|
|
2305
|
-
lastError:
|
|
2306
|
-
workflowRunId:
|
|
2307
|
-
createdAt:
|
|
2308
|
-
updatedAt:
|
|
2309
|
-
}).index(["lifecycle"]).index(["nextRunAt"]),
|
|
2310
|
-
id:
|
|
2311
|
-
fingerprint:
|
|
2312
|
-
liveFingerprint:
|
|
2313
|
-
operations:
|
|
2314
|
-
rollbackPlan:
|
|
2315
|
-
appliedBy:
|
|
2316
|
-
environment:
|
|
2317
|
-
source:
|
|
2318
|
-
onlineStrategy:
|
|
2319
|
-
durationMs:
|
|
2320
|
-
notes:
|
|
2321
|
-
squashedAt:
|
|
2322
|
-
appliedAt:
|
|
2323
|
-
createdAt:
|
|
2324
|
-
updatedAt:
|
|
2325
|
-
}).index(["fingerprint"]).index(["environment"]),
|
|
2326
|
-
id:
|
|
2327
|
-
scope:
|
|
2328
|
-
key:
|
|
2329
|
-
status:
|
|
2330
|
-
response:
|
|
2331
|
-
createdAt:
|
|
2332
|
-
}).unique(["scope", "key"]).index(["createdAt"]),
|
|
2333
|
-
id:
|
|
2334
|
-
key:
|
|
2335
|
-
value:
|
|
2336
|
-
expiresAt:
|
|
2337
|
-
createdAt:
|
|
2338
|
-
updatedAt:
|
|
2339
|
-
}).index(["expiresAt"]),
|
|
2340
|
-
id:
|
|
2341
|
-
tenantId:
|
|
2342
|
-
name:
|
|
2343
|
-
hashedKey:
|
|
2344
|
-
keyPrefix:
|
|
2345
|
-
scopes:
|
|
2346
|
-
lastUsedAt:
|
|
2347
|
-
requestCount:
|
|
2348
|
-
expiresAt:
|
|
2349
|
-
revokedAt:
|
|
2350
|
-
createdBy:
|
|
2351
|
-
onBehalfOf:
|
|
2352
|
-
metadata:
|
|
2353
|
-
createdAt:
|
|
2354
|
-
}).index("byApiKeyTenant", ["tenantId"]),
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2341
|
+
}, oc = (e) => typeof e == "object" && !!e && "__migration" in e && e.__migration === !0, sc = T("_voltro_migrations", {
|
|
2342
|
+
id: _({ prefix: "mig" }),
|
|
2343
|
+
name: t(),
|
|
2344
|
+
hash: t(),
|
|
2345
|
+
status: t(),
|
|
2346
|
+
appliedAt: C().nullable(),
|
|
2347
|
+
durationMs: S().nullable(),
|
|
2348
|
+
errorMessage: t().nullable(),
|
|
2349
|
+
errorStack: t().nullable(),
|
|
2350
|
+
workflowRunId: t().nullable(),
|
|
2351
|
+
createdAt: C().default("now"),
|
|
2352
|
+
updatedAt: C().default("now").onUpdate("now")
|
|
2353
|
+
}).index(["status"]), cc = T("_voltro_seeds", {
|
|
2354
|
+
id: _({ prefix: "seed" }),
|
|
2355
|
+
name: t(),
|
|
2356
|
+
lifecycle: t(),
|
|
2357
|
+
fingerprint: t(),
|
|
2358
|
+
cronSchedule: t().nullable(),
|
|
2359
|
+
watchedTables: h().nullable(),
|
|
2360
|
+
nextRunAt: C().nullable(),
|
|
2361
|
+
lastRunStatus: t().nullable(),
|
|
2362
|
+
lastRunAt: C().nullable(),
|
|
2363
|
+
lastRunDurationMs: S().nullable(),
|
|
2364
|
+
lastRunRowsTouched: S().nullable(),
|
|
2365
|
+
lastError: t().nullable(),
|
|
2366
|
+
workflowRunId: t().nullable(),
|
|
2367
|
+
createdAt: C().default("now"),
|
|
2368
|
+
updatedAt: C().default("now").onUpdate("now")
|
|
2369
|
+
}).index(["lifecycle"]).index(["nextRunAt"]), lc = T("_voltro_migration_plans", {
|
|
2370
|
+
id: _({ prefix: "plan" }),
|
|
2371
|
+
fingerprint: t(),
|
|
2372
|
+
liveFingerprint: t().nullable(),
|
|
2373
|
+
operations: h(),
|
|
2374
|
+
rollbackPlan: h().nullable(),
|
|
2375
|
+
appliedBy: t(),
|
|
2376
|
+
environment: t(),
|
|
2377
|
+
source: t(),
|
|
2378
|
+
onlineStrategy: t().nullable(),
|
|
2379
|
+
durationMs: S(),
|
|
2380
|
+
notes: t().nullable(),
|
|
2381
|
+
squashedAt: C().nullable(),
|
|
2382
|
+
appliedAt: C().default("now"),
|
|
2383
|
+
createdAt: C().default("now"),
|
|
2384
|
+
updatedAt: C().default("now").onUpdate("now")
|
|
2385
|
+
}).index(["fingerprint"]).index(["environment"]), uc = T("_voltro_idempotency", {
|
|
2386
|
+
id: _({ prefix: "idem" }),
|
|
2387
|
+
scope: t(),
|
|
2388
|
+
key: t(),
|
|
2389
|
+
status: t(),
|
|
2390
|
+
response: h().nullable(),
|
|
2391
|
+
createdAt: C().default("now")
|
|
2392
|
+
}).unique(["scope", "key"]).index(["createdAt"]), dc = T("_voltro_kv", {
|
|
2393
|
+
id: _({ prefix: "kv" }),
|
|
2394
|
+
key: t().unique(),
|
|
2395
|
+
value: t().nullable(),
|
|
2396
|
+
expiresAt: C().nullable(),
|
|
2397
|
+
createdAt: C().default("now"),
|
|
2398
|
+
updatedAt: C().default("now").onUpdate("now")
|
|
2399
|
+
}).index(["expiresAt"]), fc = T("_voltro_api_keys", {
|
|
2400
|
+
id: _({ prefix: "apikey" }),
|
|
2401
|
+
tenantId: t().nullable(),
|
|
2402
|
+
name: t(),
|
|
2403
|
+
hashedKey: t().maxLength(64).unique(),
|
|
2404
|
+
keyPrefix: t(),
|
|
2405
|
+
scopes: h().nullable(),
|
|
2406
|
+
lastUsedAt: C().nullable(),
|
|
2407
|
+
requestCount: S().default(0),
|
|
2408
|
+
expiresAt: C().nullable(),
|
|
2409
|
+
revokedAt: C().nullable(),
|
|
2410
|
+
createdBy: t().nullable(),
|
|
2411
|
+
onBehalfOf: t().nullable(),
|
|
2412
|
+
metadata: h().nullable(),
|
|
2413
|
+
createdAt: C().default("now")
|
|
2414
|
+
}).index("byApiKeyTenant", ["tenantId"]), pc = T("_voltro_replica_observations", {
|
|
2415
|
+
id: _({ prefix: "robs" }),
|
|
2416
|
+
replicaId: t().maxLength(191),
|
|
2417
|
+
startedAt: C(),
|
|
2418
|
+
version: t().maxLength(64).nullable(),
|
|
2419
|
+
kind: t().maxLength(64),
|
|
2420
|
+
payload: t().nullable(),
|
|
2421
|
+
reachableAt: t().maxLength(255).nullable(),
|
|
2422
|
+
writtenAt: C().default("now").onUpdate("now")
|
|
2423
|
+
}).unique(["replicaId", "kind"]).index(["kind"]), mc = [
|
|
2424
|
+
sc,
|
|
2425
|
+
cc,
|
|
2426
|
+
lc
|
|
2427
|
+
], hc = "_voltro_replace_in_progress", gc = T(hc, {
|
|
2428
|
+
id: _({ prefix: "repl" }),
|
|
2429
|
+
startedAt: C().default("now"),
|
|
2430
|
+
kind: t().default("replace"),
|
|
2431
|
+
tables: t().nullable(),
|
|
2432
|
+
capture: t().nullable(),
|
|
2433
|
+
via: t(),
|
|
2434
|
+
staging: t().nullable(),
|
|
2435
|
+
heartbeatAt: C().nullable(),
|
|
2436
|
+
resumable: r().nullable()
|
|
2437
|
+
}), _c = 30, vc = (e, t) => {
|
|
2438
|
+
let n = typeof t == "number" && Number.isFinite(t) && t > 0 ? t : 30, r = Number(e.VOLTRO_STAGING_STALE_MINUTES);
|
|
2439
|
+
return (Number.isFinite(r) && r > 0 ? r : n) * 6e4;
|
|
2440
|
+
}, yc = (e) => e == null || String(e).length === 0 ? [] : String(e).split(",").map((e) => e.trim()).filter((e) => e.length > 0), bc = (e) => {
|
|
2441
|
+
let t = e.filter((e) => e.kind !== "staging");
|
|
2442
|
+
if (t.length !== 0) return `refusing to start: a destructive data operation did not finish.
|
|
2443
|
+
${t.map((e) => {
|
|
2368
2444
|
let t = Number.isFinite(e.startedAt.getTime()) ? `${Math.max(0, Math.round((Date.now() - e.startedAt.getTime()) / 6e4))} minute(s) ago` : "at an unknown time";
|
|
2369
2445
|
if (e.kind === "restore") return ` - a native \`restore\` over ${e.via} began loading an artefact over this database ${t}\n and never reported finishing.\n` + (e.capture === null ? " The artefact it was loading was not recorded. Re-run the restore from your backup\n directory, or restore from another backup." : ` The artefact it was loading:\n ${e.capture}\n Re-run it to completion with: voltro data restore ${e.capture} --allow-live`);
|
|
2370
2446
|
let n = e.tables === null ? "this database" : `${e.tables} table(s)`;
|
|
@@ -2376,8 +2452,27 @@ ${e.map((e) => {
|
|
|
2376
2452
|
|
|
2377
2453
|
When the data is back, or you have decided the current state is correct, clear the marker:
|
|
2378
2454
|
voltro data clear-replace-marker --yes`;
|
|
2379
|
-
},
|
|
2380
|
-
let
|
|
2455
|
+
}, xc = (e, t, n) => {
|
|
2456
|
+
let r = e.filter((e) => e.kind === "staging");
|
|
2457
|
+
return {
|
|
2458
|
+
all: r,
|
|
2459
|
+
droppable: r.filter((e) => {
|
|
2460
|
+
if (e.resumable) return !1;
|
|
2461
|
+
let r = (e.heartbeatAt ?? e.startedAt).getTime();
|
|
2462
|
+
return Number.isFinite(r) ? t - r >= n : !1;
|
|
2463
|
+
})
|
|
2464
|
+
};
|
|
2465
|
+
}, Sc = (e, t) => {
|
|
2466
|
+
if (e.all.length === 0) return;
|
|
2467
|
+
let n = new Set(e.droppable.map((e) => e.id));
|
|
2468
|
+
return `staged data-import leftovers:
|
|
2469
|
+
${e.all.map((e) => {
|
|
2470
|
+
let r = e.heartbeatAt ?? e.startedAt, i = Number.isFinite(r.getTime()) ? `${Math.max(0, Math.round((t - r.getTime()) / 6e4))} minute(s) ago` : "at an unknown time", a = `${e.staging.length} staging table(s) from a \`replace\` over ${e.via}, last active ${i}`;
|
|
2471
|
+
return n.has(e.id) ? ` - ${a} — DROPPED: the run is not resumable and has been silent long enough that nothing is loading into them.` : e.resumable ? ` - ${a} — KEPT: the run was started \`--no-atomic\`, so these ARE its resume point. Re-run the same\n bundle to continue from them, or drop them with: voltro data clear-staging --yes` : ` - ${a} — KEPT: still beating, so an import is loading into them right now.`;
|
|
2472
|
+
}).join("\n")}\n The target of a staged \`replace\` is untouched until one short swap at the end, so none of this is
|
|
2473
|
+
a reason to refuse the boot — it is a reason to know the disk is holding a copy of a bundle.`;
|
|
2474
|
+
}, $ = "id", Cc = (e, t) => {
|
|
2475
|
+
let n = E(e);
|
|
2381
2476
|
if (n === void 0) return t;
|
|
2382
2477
|
let r = n.fields[$]?.idScheme;
|
|
2383
2478
|
if (r === void 0 || t[$] != null) return t;
|
|
@@ -2386,12 +2481,12 @@ ${e.map((e) => {
|
|
|
2386
2481
|
let e = { ...t };
|
|
2387
2482
|
return delete e[$], e;
|
|
2388
2483
|
}
|
|
2389
|
-
let i =
|
|
2484
|
+
let i = gt(r, e);
|
|
2390
2485
|
return i === null ? t : {
|
|
2391
2486
|
...t,
|
|
2392
2487
|
[$]: i
|
|
2393
2488
|
};
|
|
2394
|
-
},
|
|
2489
|
+
}, wc = (e, t) => t.map((t) => Cc(e, t)), Tc = {
|
|
2395
2490
|
postgres: { maxBindParameters: 65535 },
|
|
2396
2491
|
mysql: { maxBindParameters: 65535 },
|
|
2397
2492
|
mariadb: { maxBindParameters: 65535 },
|
|
@@ -2401,25 +2496,25 @@ ${e.map((e) => {
|
|
|
2401
2496
|
},
|
|
2402
2497
|
sqlite: { maxBindParameters: 32766 },
|
|
2403
2498
|
turso: { maxBindParameters: 32766 }
|
|
2404
|
-
},
|
|
2499
|
+
}, Ec = (e) => Tc[e], Dc = (e) => {
|
|
2405
2500
|
let t = /* @__PURE__ */ new Set();
|
|
2406
2501
|
for (let n of e) for (let e of Object.keys(n)) t.add(e);
|
|
2407
2502
|
return t.size;
|
|
2408
|
-
},
|
|
2503
|
+
}, Oc = (e, t) => {
|
|
2409
2504
|
if (t === void 0 || e.length === 0) return [e];
|
|
2410
|
-
let n = Math.max(1,
|
|
2505
|
+
let n = Math.max(1, Dc(e)), r = Math.floor(t.maxBindParameters / n), i = t.maxRowsPerStatement ?? Infinity, a = Math.max(1, Math.min(r, i));
|
|
2411
2506
|
if (e.length <= a) return [e];
|
|
2412
2507
|
let o = [];
|
|
2413
2508
|
for (let t = 0; t < e.length; t += a) o.push(e.slice(t, t + a));
|
|
2414
2509
|
return o;
|
|
2415
|
-
},
|
|
2510
|
+
}, kc = (e, t) => {
|
|
2416
2511
|
let n = [], r = t;
|
|
2417
2512
|
for (let [t, i] of Object.entries(e.fields)) {
|
|
2418
2513
|
let e = i;
|
|
2419
2514
|
e.nullable || e.hasDefault || e.idScheme !== void 0 || e.generatedAs !== void 0 || (r[t] === void 0 || r[t] === null) && n.push(t);
|
|
2420
2515
|
}
|
|
2421
2516
|
return n;
|
|
2422
|
-
},
|
|
2517
|
+
}, Ac = (e, t, n) => {
|
|
2423
2518
|
let r = n, i = new Set(e === void 0 ? [] : Object.entries(e.fields).filter(([, e]) => e.generatedAs !== void 0).map(([e]) => e)), a = [];
|
|
2424
2519
|
for (let e of t) i.has(e) || (r[e] === void 0 ? a.push({
|
|
2425
2520
|
column: e,
|
|
@@ -2429,28 +2524,28 @@ ${e.map((e) => {
|
|
|
2429
2524
|
reason: "null"
|
|
2430
2525
|
}));
|
|
2431
2526
|
return a;
|
|
2432
|
-
},
|
|
2527
|
+
}, jc = (e, t, n) => e.insert(t.tableName, n), Mc = (e, t, n, r) => e.upsert(t.tableName, n, {
|
|
2433
2528
|
conflictColumns: r.conflictColumns,
|
|
2434
2529
|
...r.update === void 0 ? {} : { update: r.update }
|
|
2435
|
-
}),
|
|
2530
|
+
}), Nc = (e, t, n, r) => e.updateMany(t.tableName, n, { where: r.where }), Pc = 512, Fc = (e) => {
|
|
2436
2531
|
e.setMaxListeners(512);
|
|
2437
|
-
},
|
|
2532
|
+
}, Ic = (e, t, n) => ({
|
|
2438
2533
|
_tag: "PrimaryKeyConflictError",
|
|
2439
2534
|
table: e,
|
|
2440
2535
|
key: t,
|
|
2441
2536
|
cause: n
|
|
2442
|
-
}),
|
|
2537
|
+
}), Lc = (e) => typeof e == "object" && !!e && e._tag === "PrimaryKeyConflictError", Rc = {
|
|
2443
2538
|
postgres: 5432,
|
|
2444
2539
|
mysql: 3306,
|
|
2445
2540
|
mariadb: 3306,
|
|
2446
2541
|
mssql: 1433
|
|
2447
|
-
},
|
|
2542
|
+
}, zc = /* @__PURE__ */ new Set([
|
|
2448
2543
|
"localhost",
|
|
2449
2544
|
"127.0.0.1",
|
|
2450
2545
|
"::1",
|
|
2451
2546
|
"[::1]",
|
|
2452
2547
|
"0.0.0.0"
|
|
2453
|
-
]),
|
|
2548
|
+
]), Bc = (e) => {
|
|
2454
2549
|
let t = e.host, n = e.port, r = e.database;
|
|
2455
2550
|
if (e.url !== void 0 && e.url !== "") try {
|
|
2456
2551
|
let i = new URL(e.url);
|
|
@@ -2459,29 +2554,29 @@ ${e.map((e) => {
|
|
|
2459
2554
|
return;
|
|
2460
2555
|
}
|
|
2461
2556
|
if (t === void 0 || t === "" || r === void 0 || r === "") return;
|
|
2462
|
-
let i = n ??
|
|
2557
|
+
let i = n ?? Rc[(e.dialect ?? "").toLowerCase()];
|
|
2463
2558
|
if (i === void 0 || !Number.isFinite(i)) return;
|
|
2464
2559
|
let a = t.toLowerCase();
|
|
2465
2560
|
return {
|
|
2466
|
-
host:
|
|
2561
|
+
host: zc.has(a) ? "localhost" : a,
|
|
2467
2562
|
port: i,
|
|
2468
2563
|
database: r.toLowerCase()
|
|
2469
2564
|
};
|
|
2470
|
-
},
|
|
2471
|
-
let t =
|
|
2565
|
+
}, Vc = (e) => {
|
|
2566
|
+
let t = Bc(e);
|
|
2472
2567
|
if (t !== void 0) return Lt("sha256").update(`${t.host}\u0000${t.port}\u0000${t.database}`).digest("hex").slice(0, 32);
|
|
2473
|
-
},
|
|
2568
|
+
}, Hc = (e, t) => e === void 0 || t === void 0 ? "unknown" : e === t ? "same" : "different", Uc = {
|
|
2474
2569
|
app: 3,
|
|
2475
2570
|
plugin: 2,
|
|
2476
2571
|
framework: 1
|
|
2477
|
-
},
|
|
2572
|
+
}, Wc = /* @__PURE__ */ new Map(), Gc = [], Kc = () => [...Gc], qc = (e) => {
|
|
2478
2573
|
if (!e.table || !e.timeColumn) throw Error("registerRetention: table + timeColumn are required");
|
|
2479
2574
|
if (!Number.isFinite(e.ttlMs) || e.ttlMs <= 0) throw Error(`registerRetention(${e.table}): ttlMs must be a positive number`);
|
|
2480
|
-
let t = e.source ?? "app", n =
|
|
2575
|
+
let t = e.source ?? "app", n = Wc.get(e.table);
|
|
2481
2576
|
if (n !== void 0) {
|
|
2482
2577
|
let r = n.source ?? "app", i = n.ttlMs !== e.ttlMs || n.where !== void 0 != (e.where !== void 0);
|
|
2483
|
-
if (
|
|
2484
|
-
i &&
|
|
2578
|
+
if (Uc[t] < Uc[r]) {
|
|
2579
|
+
i && Gc.push({
|
|
2485
2580
|
table: e.table,
|
|
2486
2581
|
kept: {
|
|
2487
2582
|
source: r,
|
|
@@ -2494,7 +2589,7 @@ ${e.map((e) => {
|
|
|
2494
2589
|
});
|
|
2495
2590
|
return;
|
|
2496
2591
|
}
|
|
2497
|
-
i && r !== t &&
|
|
2592
|
+
i && r !== t && Gc.push({
|
|
2498
2593
|
table: e.table,
|
|
2499
2594
|
kept: {
|
|
2500
2595
|
source: t,
|
|
@@ -2506,51 +2601,51 @@ ${e.map((e) => {
|
|
|
2506
2601
|
}
|
|
2507
2602
|
});
|
|
2508
2603
|
}
|
|
2509
|
-
|
|
2604
|
+
Wc.set(e.table, {
|
|
2510
2605
|
...e,
|
|
2511
2606
|
source: t
|
|
2512
2607
|
});
|
|
2513
|
-
},
|
|
2514
|
-
|
|
2515
|
-
},
|
|
2608
|
+
}, Jc = () => [...Wc.values()], Yc = () => {
|
|
2609
|
+
Wc.clear(), Gc.length = 0;
|
|
2610
|
+
}, Xc = async (e, t, n, r = 2e4) => {
|
|
2516
2611
|
let i = new Date(t - e.ttlMs), a = 0;
|
|
2517
2612
|
for (;;) {
|
|
2518
2613
|
let t = await n(e.table, e.timeColumn, i, r, e.where);
|
|
2519
2614
|
if (a += t, t < r) break;
|
|
2520
2615
|
}
|
|
2521
2616
|
return a;
|
|
2522
|
-
},
|
|
2617
|
+
}, Zc = (e, t) => {
|
|
2523
2618
|
let n = Number(e ?? String(t));
|
|
2524
2619
|
return (Number.isFinite(n) && n > 0 ? n : t) * 36e5;
|
|
2525
|
-
},
|
|
2526
|
-
id:
|
|
2527
|
-
replicaId:
|
|
2528
|
-
streamName:
|
|
2529
|
-
binlogFile:
|
|
2530
|
-
binlogPosition:
|
|
2531
|
-
updatedAt:
|
|
2532
|
-
}).index(["replicaId"]),
|
|
2533
|
-
id:
|
|
2534
|
-
replicaId:
|
|
2535
|
-
streamName:
|
|
2536
|
-
ctVersion:
|
|
2537
|
-
updatedAt:
|
|
2538
|
-
}).index(["replicaId"]),
|
|
2539
|
-
id:
|
|
2540
|
-
startedAt:
|
|
2541
|
-
finishedAt:
|
|
2542
|
-
direction:
|
|
2543
|
-
mode:
|
|
2544
|
-
via:
|
|
2545
|
-
bundle:
|
|
2546
|
-
sourceFingerprint:
|
|
2547
|
-
tablesWritten:
|
|
2548
|
-
rowsWritten:
|
|
2549
|
-
failure:
|
|
2550
|
-
staged:
|
|
2551
|
-
}).renamedFrom("_voltro_data_imports").nonReactive(),
|
|
2620
|
+
}, Qc = "_voltro_cdc_offsets", $c = T(Qc, {
|
|
2621
|
+
id: _({ prefix: "cdcoff" }),
|
|
2622
|
+
replicaId: t(),
|
|
2623
|
+
streamName: t(),
|
|
2624
|
+
binlogFile: t(),
|
|
2625
|
+
binlogPosition: t(),
|
|
2626
|
+
updatedAt: C()
|
|
2627
|
+
}).index(["replicaId"]), el = T(Qc, {
|
|
2628
|
+
id: _({ prefix: "cdcoff" }),
|
|
2629
|
+
replicaId: t(),
|
|
2630
|
+
streamName: t(),
|
|
2631
|
+
ctVersion: t(),
|
|
2632
|
+
updatedAt: C()
|
|
2633
|
+
}).index(["replicaId"]), tl = "_voltro_data_transfers", nl = T(tl, {
|
|
2634
|
+
id: _({ prefix: "dimp" }),
|
|
2635
|
+
startedAt: C().default("now"),
|
|
2636
|
+
finishedAt: C().nullable(),
|
|
2637
|
+
direction: t().default("import"),
|
|
2638
|
+
mode: t(),
|
|
2639
|
+
via: t(),
|
|
2640
|
+
bundle: t().nullable(),
|
|
2641
|
+
sourceFingerprint: t().nullable(),
|
|
2642
|
+
tablesWritten: S().default(0),
|
|
2643
|
+
rowsWritten: S().default(0),
|
|
2644
|
+
failure: t().nullable(),
|
|
2645
|
+
staged: r().nullable()
|
|
2646
|
+
}).renamedFrom("_voltro_data_imports").nonReactive(), rl = (e) => {
|
|
2552
2647
|
let t = Number.isFinite(e.startedAt.getTime()) ? e.startedAt.toISOString() : "an unknown time", n = e.direction === "import" ? e.mode : `${e.direction} ${e.mode}`, r = e.failure === null ? e.finishedAt === null ? `${n} — started and never reported finishing` : e.direction === "backup" || e.direction === "restore" ? `${n} — finished${e.rowsWritten > 0 ? ` (${e.rowsWritten} blob(s))` : ""}` : `${n} — ${e.rowsWritten} row(s) across ${e.tablesWritten} table(s)` : `FAILED ${n} — ${e.failure}`, i = e.staged === null ? "" : e.staged ? " · staged (target untouched until the swap)" : " · NOT staged (target emptied first)";
|
|
2553
2648
|
return `${t} · ${r} · via ${e.via}${i}` + (e.bundle === null ? "" : ` · from ${e.bundle}`) + (e.sourceFingerprint === null ? "" : ` · source schema ${e.sourceFingerprint}`);
|
|
2554
|
-
},
|
|
2649
|
+
}, il = "postgres";
|
|
2555
2650
|
//#endregion
|
|
2556
|
-
export {
|
|
2651
|
+
export { nt as AUTO_FILLED_COLUMNS, Tc as BULK_INSERT_LIMITS, J as BranchNameInvalid, ys as BranchTransitionInvalid, Qc as CDC_OFFSETS_TABLE, Ra as CHANGE_CLAIM_TTL_ENV, Pc as CHANGE_LISTENER_CEILING, l as ColumnBuilder, tl as DATA_TRANSFERS_TABLE, fe as DEFAULT_ACQUIRE_TIMEOUT_MS, za as DEFAULT_CHANGE_CLAIM_TTL_HOURS, Vo as DEFAULT_EAGER_FALLBACK_WARN_INTERVAL_MS, Gn as DEFAULT_SUBJECT_GRAPH_DEPTH, qt as ENCRYPTED_PREFIX, il as ENGINE, cr as EagerCardinalityError, rt as FILE_MIGRATION_PATTERN, ft as FRAMEWORK_LIVE_TABLES, Jt as FieldDecryptionError, co as ID_COLUMN_MAX_LENGTH, es as INITIAL_VERSION, ua as MATCHES_NO_ROWS, et as MAX_IDENTIFIER_LENGTH, La as OccurrenceCounter, hc as REPLACE_IN_PROGRESS_TABLE, _c as STAGING_STALE_MINUTES, tt as STAGING_TABLE_PREFIX, Bt as SqlClient, ss as TableStreamError, Sr as TenantNamespaceInvalid, xr as TenantNamespaceUnresolved, Rs as TenantRegionUnavailable, Ls as TenantResidencyUnresolved, ts as VOLTRO_EXPIRES_MIXIN_ID, rs as VOLTRO_LOCAL_FIRST_MIXIN_ID, Xo as VersionConflict, Ke as WARN_IDENTIFIER_LENGTH, fc as _voltroApiKeysTable, $c as _voltroCdcOffsetsTable, nl as _voltroDataTransfersTable, uc as _voltroIdempotencyTable, dc as _voltroKvTable, lc as _voltroMigrationPlansTable, sc as _voltroMigrationsTable, el as _voltroMssqlCdcOffsetsTable, gc as _voltroReplaceInProgressTable, pc as _voltroReplicaObservationsTable, cc as _voltroSeedsTable, Xi as actorsTable, Ms as admitBranch, St as allEnumRenames, Hn as allRegisteredRelations, Ce as allRegisteredTables, ma as and, le as array, sa as arrayContains, la as arrayHas, ca as arrayOverlaps, ur as attachEagerLoads, Wa as attributionFields, Ja as attributionKey, Qs as auditAllTableIndexes, Zs as auditTableIndexes, Fe as avg, xt as avgOver, ro as beginLocalWrite, Xe as bigint, Ks as bindResidentStore, r as boolean, gs as branchNamespaceName, Ec as bulkInsertLimitsFor, Je as bytes, ja as changeDelete, Pa as changeDigest, ka as changeInsert, Ma as changeSoftDelete, Aa as changeUpdate, Oc as chunkRowsForInsert, Za as claimPendingAttribution, pn as classifyConstraintViolation, _e as clearEnumRenames, oo as clearPendingAttribution, Wn as clearRelationsRegistry, Hs as clearResidencyConfig, Yc as clearRetentions, m as clearTableRegistry, go as clearWriteRecorders, U as coercePredicateForSqlite, Ar as coercePredicateValue, jr as coercePredicateValues, Hi as coerceValueForSqlite, Ea as collectSubqueries, ge as column, yn as columnSchema, Dc as columnsPerRow, Gr as compileEagerJson, I as compilePredicate, Mr as compileRawFragment, Wr as compileSelect, Fa as composeChangeKey, fs as computeEmbedding, Vc as connectionIdentity, aa as contains, o as count, yt as countDistinct, oe as crdtDoc, se as crdtManagedColumns, de as crdtManagedColumnsOf, p as crdtText, Ua as currentWriteAttribution, ve as databaseHandle, te as date, ie as dbEnum, Fo as dbMetricTagCacheSizeForTests, Ro as dbOperationsInFlight, he as decimal, s as declareEnumRename, $t as decodeFieldValue, ar as decodeRowsFromSchema, an as decryptFieldsOnRead, ac as defineMigration, it as defineMixin, Ze as defineSeed, u as denseRank, Qn as deriveSubjectGraph, Qe as deriveTypeIdPrefix, fo as derivedRowId, po as derivedRowIdLength, gn as describeDriverError, _n as describeRowBindings, rl as describeTransferRun, Kt as deserializeArraysOnRead, Ge as drainIdentifierWarnings, Et as dropped, Zt as encodeFieldValue, sr as encodeRowForSchema, rn as encryptFieldsForWrite, nn as encryptedColumnsOf, io as endLocalWrite, ks as enforceBranchLimits, y as ensureTableRegistered, Zi as eq, Nr as escapeLike, Ta as evaluatePredicate, c as except, xa as exists, ns as expires, Oa as externalChangeEvent, un as extractDbCause, ht as fireSchemaChangeSeeds, ze as fireTenantCreateSeeds, rc as formatIndexAuditIssue, $n as formatSubjectGraph, mc as frameworkTables, gt as generateId, Ue as generateSnowflake, a as geography, Se as geometry, bt as getEnumRenames, Vn as getRelation, Bn as getRelations, Vs as getResidencyConfig, E as getTable, $i as gt, ea as gte, br as hasEagerLoads, ds as hybridSearch, _ as id, ra as inSet, ya as inSubquery, P as inferForeignKey, jc as insertRow, S as integer, bc as interruptedReplaceRefusal, ce as intersect, we as interval, _s as isBranchNamespace, Dn as isEmptyRelationsSpec, Xt as isEncrypted, Yt as isFieldDecryptionError, ut as isFileMigration, mn as isForeignKeyViolation, ct as isFrameworkOwnedLiveTable, as as isLocalFirst, oc as isMigrationDefinition, e as isMysqlFamily, Cs as isNeonConnection, fa as isNotNull, da as isNull, Lc as isPrimaryKeyConflictError, hn as isQueryTimeout, en as isRawEncoding, Ws as isRegionServable, On as isRelationsSpec, He as isSeedDefinition, Ve as isSqliteFamily, Ne as isStagingTableName, ne as isTableReactive, We as isView, h as json, _a as jsonField, lt as jsonIndex, Ye as lag, n as lead, Kc as listRetentionConflicts, Jc as listRetentions, is as localFirst, os as localFirstTables, ta as lt, na as lte, Wo as makeEagerFallbackReporter, Is as makeNamespaceBranchExecutor, An as many, jn as manyToMany, re as materializeFields, qe as max, Le as migration, ae as min, Ac as missingConflictColumns, kc as missingRequiredColumns, dt as mixin, Qi as neq, bs as nextBranchState, Bc as normaliseTarget, ga as not, Sa as notExists, ia as notInSet, ba as notInSubquery, st as numeric, Bo as observeDbOp, Ba as occurrenceWindowMs, kn as one, lr as oneCardinalityMessage, ha as or, x as orderClausesOf, ue as paginateBy, f as paginateById, Ia as parseChangeKey, so as pendingAttributionCount, Ds as planBranch, xs as planBranchProvision, Ss as planBranchTeardown, Os as planBranchTeardownFor, Ts as planNeonBranchProvision, Es as planNeonBranchTeardown, Qo as planVersionedUpdate, ye as pluginRef, d as pluginRefSpecOf, Ic as primaryKeyConflictError, As as provisionBranch, qs as provisionResidentTenant, Dr as qualifyTable, ee as queryFor, je as queryForView, mt as quoteIdent, Fc as raiseChangeListenerCeiling, b as rank, v as raw, Oe as readableByColumns, Ee as real, zo as recordDbOp, xo as recordsTable, Ae as reference, Ki as registerCoreTables, zn as registerDiscoveredRelations, Xa as registerPendingAttribution, Rn as registerRelations, qc as registerRetention, De as registerTable, mo as registerWriteRecorder, En as relations, Ji as requireActors, Te as requireTable, Yi as requireTenants, Po as resetDbMetricTagCacheForTests, ot as resetSnowflake, Gs as residentPlacement, Ht as resolveActorSnapshot, ws as resolveBranchMechanism, Uo as resolveEagerFallbackWarnIntervalMs, ao as resolveEchoAttribution, me as resolveFullTextIndex, Be as resolveIdScheme, Re as resolveMixinGraph, Us as resolveTenantHome, Er as resolveTenantNamespace, Zc as retentionTtlMsFromEnv, Tt as rowNumber, bn as rowSchema, Jo as runRetryingTransaction, Yo as runStoreTransaction, Ha as runWithWriteAttribution, So as runWriteRecorders, Hc as sameDatabase, Tr as sanitizeIdentifierFragment, Gt as serializeArraysForWrite, pe as serverOnlyColumns, Bs as setResidencyConfig, at as setSchemaChangeSeedHook, $e as setTenantCreateSeedHook, Go as settleTransactionExit, $o as settleVersionedUpdate, pa as spatialPredicate, Sc as stagingLeftoverReport, xc as stagingLeftovers, yc as stagingNamesOf, vc as stagingStaleAfterMs, Cc as stampGeneratedId, wc as stampGeneratedIds, oa as startsWith, us as streamTable, i as sum, xe as sumOver, vo as suspendWriteRecorders, yo as suspendWriteRecordersEffect, Xc as sweepRetention, T as table, js as teardownBranch, t as text, C as timestamp, Dt as timestampMs, Ot as timestampMsOrNull, g as union, be as unionAll, ke as unregisterTable, ho as unregisterWriteRecorder, Nc as updateManyRow, Mc as upsertRow, Me as validateColumnName, vt as validateIndexName, Un as validateRegisteredRelations, Fn as validateRelationConfig, wt as validateTableName, Ie as validateTypeIdPrefix, pt as vector, Pe as vectorDistanceToOpclass, ps as vectorEmbedding, Zo as versionColumnOf, _t as view, Ct as viewSql, Da as walkLeaves, Ga as withCapturedAttribution, bo as writeRecordersSuspended };
|