@voltro/database 0.73.0 → 0.75.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 +449 -0
- package/dist/{frameworkLiveTables-C1WjQ_uI.js → frameworkTables-CfWuWeFG.js} +587 -292
- package/dist/index.d.ts +96 -2
- package/dist/index.js +628 -871
- package/dist/sql.d.ts +121 -7
- package/dist/sql.js +1356 -1308
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { $ as e, $
|
|
2
|
-
import { a as
|
|
3
|
-
import { Cause as
|
|
4
|
-
import { createHash as
|
|
5
|
-
import { AsyncLocalStorage as
|
|
6
|
-
import { TransactionConnection as
|
|
7
|
-
import { ansi as
|
|
8
|
-
import { SqlClient as
|
|
1
|
+
import { $ as e, $n as t, $t as n, A as r, An as i, At as a, B as o, Bn as s, Bt as c, C as l, Cn as u, Ct as d, D as f, Dn as p, Dt as m, E as h, En as g, Et as _, F as v, Fn as ee, Ft as te, G as ne, Gn as re, Gt as ie, H as ae, Hn as y, Ht as oe, I as b, In as se, It as ce, J as le, Jn as ue, Jt as de, K as fe, Kn as pe, Kt as me, L as he, Ln as ge, Lt as _e, M as ve, Mn as ye, Mt as be, N as xe, Nn as Se, Nt as x, O as Ce, On as we, Ot as Te, P as Ee, Pn as De, Pt as Oe, Q as ke, Qn as Ae, Qt as je, R as Me, Rn as Ne, Rt as Pe, S as Fe, Sn as Ie, St as Le, T as Re, Tn as ze, Tt as Be, U as Ve, Un as He, Ut as Ue, V as We, Vn as Ge, Vt as Ke, W as qe, Wn as Je, Wt as Ye, X as Xe, Xn as Ze, Xt as Qe, Y as $e, Yn as et, Yt as tt, Z as nt, Zn as S, Zt as rt, _ as it, _n as at, _t as ot, a as st, an as ct, ar as lt, at as ut, b as dt, bn as ft, bt as pt, c as mt, cn as ht, cr as gt, ct as _t, d as vt, dn as yt, dr as bt, dt as C, en as xt, er as St, et as Ct, f as wt, fn as Tt, ft as Et, g as Dt, gn as Ot, gt as kt, h as At, hn as jt, ht as Mt, i as Nt, in as w, ir as Pt, it as Ft, j as It, jn as Lt, jt as Rt, k as zt, kn as Bt, kt as Vt, l as Ht, ln as Ut, lr as T, lt as Wt, m as Gt, mn as Kt, mt as qt, n as Jt, nn as Yt, nr as Xt, nt as Zt, o as Qt, on as $t, or as en, ot as tn, p as nn, pn as rn, pt as an, q as on, qn as sn, qt as cn, r as ln, rn as un, rr as dn, rt as fn, s as pn, sn as mn, sr as hn, st as gn, t as _n, tn as vn, tr as yn, tt as bn, u as xn, un as Sn, ur as E, ut as Cn, v as wn, vn as Tn, vt as En, w as Dn, wn as On, wt as kn, x as An, xn as jn, xt as Mn, y as Nn, yn as Pn, yt as Fn, z as In, zn as Ln, zt as Rn } from "./frameworkTables-CfWuWeFG.js";
|
|
2
|
+
import { a as zn, i as Bn, n as Vn, o as Hn, r as Un, s as Wn, t as Gn } from "./wire-B28cPjEp.js";
|
|
3
|
+
import { Cause as Kn, Chunk as qn, Data as Jn, Effect as D, Exit as Yn, Metric as O, MetricBoundaries as Xn, Option as k, Schedule as Zn, Schema as A, Stream as Qn } from "effect";
|
|
4
|
+
import { createHash as $n } from "node:crypto";
|
|
5
|
+
import { AsyncLocalStorage as er } from "node:async_hooks";
|
|
6
|
+
import { TransactionConnection as tr } from "@effect/sql/SqlClient";
|
|
7
|
+
import { ansi as j } from "@voltro/logger";
|
|
8
|
+
import { SqlClient as nr } from "@effect/sql";
|
|
9
9
|
//#region src/actorSnapshot.ts
|
|
10
|
-
var
|
|
10
|
+
var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = 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 zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = 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: rr(r.kind) ?? n,
|
|
27
|
+
displayName: rr(r.displayName),
|
|
28
|
+
email: rr(r.email)
|
|
29
29
|
};
|
|
30
30
|
} catch {
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
|
-
},
|
|
33
|
+
}, ar = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqlite", or = (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
|
+
}, sr = (e, t, n) => {
|
|
38
|
+
if (!ar(n) || !t) return e;
|
|
39
|
+
let r = or(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 zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = 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
|
+
}, cr = (e, t, n) => {
|
|
48
|
+
if (!ar(n) || !t) return e;
|
|
49
|
+
let r = or(t);
|
|
50
50
|
return r.length === 0 ? e : e.map((e) => {
|
|
51
51
|
let t;
|
|
52
52
|
for (let n of r) {
|
|
@@ -58,13 +58,13 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
58
58
|
}
|
|
59
59
|
return t ?? e;
|
|
60
60
|
});
|
|
61
|
-
},
|
|
61
|
+
}, lr = "enc:v1:", ur = "enc:v2:", dr = (e, t, n) => {
|
|
62
62
|
let r = `${e}:${t}`, i = n == null || n === "" ? void 0 : String(n);
|
|
63
63
|
return i === void 0 ? { column: r } : {
|
|
64
64
|
column: r,
|
|
65
65
|
row: `${r}:${i}`
|
|
66
66
|
};
|
|
67
|
-
},
|
|
67
|
+
}, fr = (e) => typeof e == "string" && e.startsWith("enc:v2:"), pr = class extends Error {
|
|
68
68
|
_tag = "FieldDecryptionError";
|
|
69
69
|
table;
|
|
70
70
|
column;
|
|
@@ -72,7 +72,7 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
72
72
|
constructor(e) {
|
|
73
73
|
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;
|
|
74
74
|
}
|
|
75
|
-
},
|
|
75
|
+
}, mr = (e) => typeof e == "object" && !!e && e._tag === "FieldDecryptionError", hr = (e) => typeof e == "string" && (e.startsWith("enc:v1:") || e.startsWith("enc:v2:")), gr = (e, t, n) => e.encrypt(JSON.stringify(t), n), _r = /* @__PURE__ */ new Set([
|
|
76
76
|
"text",
|
|
77
77
|
"id",
|
|
78
78
|
"reference",
|
|
@@ -80,51 +80,51 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
80
80
|
"uuid",
|
|
81
81
|
"email",
|
|
82
82
|
"url"
|
|
83
|
-
]),
|
|
83
|
+
]), vr = (e, t, n, r) => {
|
|
84
84
|
let i = e.decrypt(t, r), a;
|
|
85
85
|
try {
|
|
86
86
|
a = JSON.parse(i);
|
|
87
87
|
} catch {
|
|
88
88
|
return i;
|
|
89
89
|
}
|
|
90
|
-
return typeof a == "string" ? a : n === void 0 ||
|
|
91
|
-
},
|
|
90
|
+
return typeof a == "string" ? a : n === void 0 || _r.has(n) ? i : a;
|
|
91
|
+
}, yr = (e, t, n, r) => {
|
|
92
92
|
let i = e.decrypt(t, r);
|
|
93
93
|
try {
|
|
94
|
-
return typeof JSON.parse(i) == "string" ? !1 : n === void 0 ||
|
|
94
|
+
return typeof JSON.parse(i) == "string" ? !1 : n === void 0 || _r.has(n) ? !0 : void 0;
|
|
95
95
|
} catch {
|
|
96
96
|
return !0;
|
|
97
97
|
}
|
|
98
|
-
},
|
|
98
|
+
}, br = (e, t) => e.fields[t]?.type, xr = (e) => {
|
|
99
99
|
let t = [];
|
|
100
100
|
for (let [n, r] of Object.entries(e.fields)) r.encrypted === !0 && t.push(n);
|
|
101
101
|
return t;
|
|
102
|
-
},
|
|
102
|
+
}, Sr = "id", Cr = (e, t, n, r) => {
|
|
103
103
|
if (!t) return e;
|
|
104
|
-
let i =
|
|
104
|
+
let i = xr(t);
|
|
105
105
|
if (i.length === 0) return e;
|
|
106
|
-
let a = t.tableName ?? "?", o = r ?? e[
|
|
106
|
+
let a = t.tableName ?? "?", o = r ?? e[Sr], s = { ...e };
|
|
107
107
|
for (let e of i) {
|
|
108
108
|
let t = s[e];
|
|
109
|
-
if (!(t == null ||
|
|
109
|
+
if (!(t == null || hr(t))) {
|
|
110
110
|
if (!n) throw Error(`column "${a}.${e}" is .encrypted() but no field cipher is registered — set VOLTRO_FIELD_ENCRYPTION_KEY (\`voltro dev\` mints one; \`voltro serve\` refuses to boot without it); in a test, pass \`fieldEncryptionKey\` to makeTestContext`);
|
|
111
|
-
s[e] =
|
|
111
|
+
s[e] = gr(n, t, dr(a, e, o));
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
return s;
|
|
115
|
-
},
|
|
115
|
+
}, wr = (e, t, n, r) => {
|
|
116
116
|
if (!t) return e;
|
|
117
|
-
let i =
|
|
117
|
+
let i = xr(t);
|
|
118
118
|
if (i.length === 0 || !n) return e;
|
|
119
119
|
let a = r?.onError ?? "throw", o = t.tableName ?? "?";
|
|
120
120
|
return e.map((e) => {
|
|
121
121
|
let s;
|
|
122
122
|
for (let c of i) {
|
|
123
123
|
let i = e[c];
|
|
124
|
-
if (
|
|
124
|
+
if (hr(i)) {
|
|
125
125
|
s ??= { ...e };
|
|
126
126
|
try {
|
|
127
|
-
s[c] =
|
|
127
|
+
s[c] = vr(n, i, br(t, c), dr(o, c, r?.rowId ?? e[Sr]));
|
|
128
128
|
} catch (e) {
|
|
129
129
|
let t = String(e?.message ?? e);
|
|
130
130
|
if (a === "null") {
|
|
@@ -135,7 +135,7 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
135
135
|
});
|
|
136
136
|
continue;
|
|
137
137
|
}
|
|
138
|
-
throw new
|
|
138
|
+
throw new pr({
|
|
139
139
|
table: o,
|
|
140
140
|
column: c,
|
|
141
141
|
reason: t
|
|
@@ -145,260 +145,77 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
145
145
|
}
|
|
146
146
|
return s ?? e;
|
|
147
147
|
});
|
|
148
|
-
},
|
|
149
|
-
let t = e;
|
|
150
|
-
for (let e = 0; e < 4 && Mn.isFiberFailure(t); e++) t = Dn.squash(t[Mn.FiberFailureCauseId]);
|
|
151
|
-
return t;
|
|
152
|
-
}, cr = (e, t = 0) => {
|
|
153
|
-
if (t >= 4 || !Mn.isFiberFailure(e)) return [e];
|
|
154
|
-
let n = e[Mn.FiberFailureCauseId], r = [...Dn.failures(n), ...Dn.defects(n)];
|
|
155
|
-
if (r.length === 0) return [Dn.squash(n)];
|
|
156
|
-
let i = [];
|
|
157
|
-
for (let e of r.slice(0, 8)) i.push(...cr(e, t + 1));
|
|
158
|
-
return i;
|
|
159
|
-
}, lr = (e) => e.dbCode !== void 0 || e.dbErrno !== void 0 || e.dbNumber !== void 0 || e.dbSqlState !== void 0 || e.dbConstraint !== void 0, ur = (e) => {
|
|
160
|
-
let t = {}, n = [], r = sr(e);
|
|
161
|
-
for (let e = 0; e < 8 && typeof r == "object" && r; e++) {
|
|
162
|
-
let e = r;
|
|
163
|
-
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);
|
|
164
|
-
let i = e.sqlMessage ?? e.detail;
|
|
165
|
-
t.dbMessage === void 0 && typeof i == "string" && (t.dbMessage = i);
|
|
166
|
-
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;
|
|
167
|
-
(o || s) && n.push(`${o || "Error"}${s ? `: ${s.slice(0, 200)}` : ""}`), r = sr(e.cause);
|
|
168
|
-
}
|
|
169
|
-
return n.length > 0 && (t.dbCauseChain = n.join(" ← "), t.dbMessage === void 0 && (t.dbMessage = n[n.length - 1])), t;
|
|
170
|
-
}, dr = (e) => {
|
|
171
|
-
let t = cr(e).map(ur);
|
|
172
|
-
if (t.length <= 1) return t[0] ?? {};
|
|
173
|
-
let n = t.find(lr) ?? t[0], r = t.filter((e) => e !== n).map((e) => e.dbCauseChain).filter((e) => typeof e == "string");
|
|
174
|
-
if (r.length === 0) return n;
|
|
175
|
-
let i = typeof n.dbCauseChain == "string" ? n.dbCauseChain : void 0;
|
|
176
|
-
return {
|
|
177
|
-
...n,
|
|
178
|
-
dbCauseChain: [i, ...r].filter(Boolean).join(" ‖ ")
|
|
179
|
-
};
|
|
180
|
-
}, fr = (e, t) => {
|
|
181
|
-
let n = dr(e), r = vr(n, t);
|
|
182
|
-
if (r !== void 0) {
|
|
183
|
-
let e = r.constraint ?? r.column;
|
|
184
|
-
return e === void 0 ? r.kind : `${r.kind}: ${e}`;
|
|
185
|
-
}
|
|
186
|
-
let i = n.dbCode ?? n.dbSqlState ?? n.dbErrno ?? n.dbNumber, a = hr(e);
|
|
187
|
-
return i !== void 0 && pr.test(String(i)) ? `${a} (${String(i)})` : a;
|
|
188
|
-
}, pr = /^[A-Za-z0-9_]{1,32}$/, mr = /^[A-Za-z_][A-Za-z0-9_]{0,63}$/, hr = (e) => {
|
|
189
|
-
let t = e?._tag, n = e?.name, r = (typeof t == "string" ? t : typeof n == "string" ? n : "").split(/[^A-Za-z0-9_]+/).filter(Boolean).pop();
|
|
190
|
-
return r !== void 0 && mr.test(r) ? r : "unknown";
|
|
191
|
-
}, gr = /^[A-Za-z_][A-Za-z0-9_$]*$/, N = (e) => e !== void 0 && e.length <= 128 && gr.test(e) ? e : void 0, _r = (e) => e === void 0 ? void 0 : e.split(".").pop() ?? e, P = (e, ...t) => {
|
|
192
|
-
for (let n of t) {
|
|
193
|
-
let t = n.exec(e);
|
|
194
|
-
if (t?.[1] !== void 0) return t[1];
|
|
195
|
-
}
|
|
196
|
-
}, vr = (e, t) => {
|
|
197
|
-
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}`;
|
|
198
|
-
if (n === "23503") {
|
|
199
|
-
let t = N(e.dbConstraint);
|
|
200
|
-
return {
|
|
201
|
-
kind: /is still referenced from table/i.test(o) ? "foreignKeyInUse" : "foreignKey",
|
|
202
|
-
...t === void 0 ? {} : { constraint: t }
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
if (n === "23505") {
|
|
206
|
-
let t = N(e.dbConstraint);
|
|
207
|
-
return {
|
|
208
|
-
kind: "unique",
|
|
209
|
-
...t === void 0 ? {} : { constraint: t }
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
if (n === "23502") {
|
|
213
|
-
let t = N(e.dbColumn);
|
|
214
|
-
return {
|
|
215
|
-
kind: "notNull",
|
|
216
|
-
...t === void 0 ? {} : { column: t }
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
if (n === "23514") {
|
|
220
|
-
let t = N(e.dbConstraint);
|
|
221
|
-
return {
|
|
222
|
-
kind: "check",
|
|
223
|
-
...t === void 0 ? {} : { constraint: t }
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
if (r === 1452 || r === 1451) {
|
|
227
|
-
let e = N(P(o, /CONSTRAINT `([^`]+)`/));
|
|
228
|
-
return {
|
|
229
|
-
kind: r === 1451 ? "foreignKeyInUse" : "foreignKey",
|
|
230
|
-
...e === void 0 ? {} : { constraint: e }
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
if (r === 1062) {
|
|
234
|
-
let e = N(_r(P(o, /for key '([^']+)'/)));
|
|
235
|
-
return {
|
|
236
|
-
kind: "unique",
|
|
237
|
-
...e === void 0 ? {} : { constraint: e }
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
if (r === 1048 || r === 1364) {
|
|
241
|
-
let e = N(P(o, /Column '([^']+)' cannot be null/, /Field '([^']+)' doesn't have a default value/));
|
|
242
|
-
return {
|
|
243
|
-
kind: "notNull",
|
|
244
|
-
...e === void 0 ? {} : { column: e }
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
if (r === 3819 || r === 4025) {
|
|
248
|
-
let e = N(P(o, /Check constraint '([^']+)'/, /CONSTRAINT `([^`]+)` failed/));
|
|
249
|
-
return {
|
|
250
|
-
kind: "check",
|
|
251
|
-
...e === void 0 ? {} : { constraint: e }
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
if (i === 547) {
|
|
255
|
-
let e = P(o, /(?:FOREIGN KEY|REFERENCE) constraint "([^"]+)"/), t = P(o, /CHECK constraint "([^"]+)"/);
|
|
256
|
-
if (t !== void 0 && e === void 0) {
|
|
257
|
-
let e = N(t);
|
|
258
|
-
return {
|
|
259
|
-
kind: "check",
|
|
260
|
-
...e === void 0 ? {} : { constraint: e }
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
let n = /REFERENCE constraint/.test(o), r = N(e);
|
|
264
|
-
return {
|
|
265
|
-
kind: n ? "foreignKeyInUse" : "foreignKey",
|
|
266
|
-
...r === void 0 ? {} : { constraint: r }
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
if (i === 2627 || i === 2601) {
|
|
270
|
-
let e = N(P(o, /(?:UNIQUE KEY|PRIMARY KEY) constraint '([^']+)'/, /index '([^']+)'/));
|
|
271
|
-
return {
|
|
272
|
-
kind: "unique",
|
|
273
|
-
...e === void 0 ? {} : { constraint: e }
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
if (i === 515) {
|
|
277
|
-
let e = N(P(o, /Cannot insert the value NULL into column '([^']+)'/));
|
|
278
|
-
return {
|
|
279
|
-
kind: "notNull",
|
|
280
|
-
...e === void 0 ? {} : { column: e }
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
if (n === "SQLITE_CONSTRAINT_FOREIGNKEY") return { kind: t === "delete" || t === "deleteMany" || t === "hardDelete" ? "foreignKeyInUse" : "foreignKey" };
|
|
284
|
-
if (n === "SQLITE_CONSTRAINT_UNIQUE" || n === "SQLITE_CONSTRAINT_PRIMARYKEY") {
|
|
285
|
-
let e = N(_r(P(o, /UNIQUE constraint failed: ([^,\s]+)/)));
|
|
286
|
-
return {
|
|
287
|
-
kind: "unique",
|
|
288
|
-
...e === void 0 ? {} : { column: e }
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
if (n === "SQLITE_CONSTRAINT_NOTNULL") {
|
|
292
|
-
let e = N(_r(P(o, /NOT NULL constraint failed: ([^,\s]+)/)));
|
|
293
|
-
return {
|
|
294
|
-
kind: "notNull",
|
|
295
|
-
...e === void 0 ? {} : { column: e }
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
if (n === "SQLITE_CONSTRAINT_CHECK") {
|
|
299
|
-
let e = N(P(a, /CHECK constraint failed: (.+)$/));
|
|
300
|
-
return {
|
|
301
|
-
kind: "check",
|
|
302
|
-
...e === void 0 ? {} : { constraint: e }
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
}, yr = (e) => {
|
|
306
|
-
let t = vr(e)?.kind;
|
|
307
|
-
return t === "foreignKey" || t === "foreignKeyInUse";
|
|
308
|
-
}, br = (e) => {
|
|
309
|
-
let t = e.dbCode, n = e.dbErrno;
|
|
310
|
-
return t === "57014" || n === 3024 || n === 1969 || t === "ETIMEOUT" || t === "SQLITE_INTERRUPT";
|
|
311
|
-
}, xr = (e) => {
|
|
312
|
-
let t = dr(e), n = [
|
|
313
|
-
t.dbCode === void 0 ? void 0 : `code=${String(t.dbCode)}`,
|
|
314
|
-
t.dbErrno === void 0 ? void 0 : `errno=${String(t.dbErrno)}`,
|
|
315
|
-
t.dbNumber === void 0 ? void 0 : `number=${String(t.dbNumber)}`,
|
|
316
|
-
t.dbSqlState === void 0 ? void 0 : `sqlState=${String(t.dbSqlState)}`,
|
|
317
|
-
t.dbConstraint === void 0 ? void 0 : `constraint=${String(t.dbConstraint)}`,
|
|
318
|
-
t.dbPlaceholders === void 0 ? void 0 : `placeholders=${String(t.dbPlaceholders)}`
|
|
319
|
-
].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)}…`}` : "";
|
|
320
|
-
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;
|
|
321
|
-
}, Sr = (e) => Object.entries(e).map(([e, t]) => `${e}:${Cr(t)}`).join(" "), Cr = (e) => {
|
|
322
|
-
if (e === null) return "null";
|
|
323
|
-
if (e === void 0) return "undefined";
|
|
324
|
-
if (typeof e == "bigint") return "bigint";
|
|
325
|
-
if (typeof e != "object") return typeof e;
|
|
326
|
-
if (e instanceof Date) return Number.isNaN(e.getTime()) ? "Date(Invalid)" : "Date";
|
|
327
|
-
if (Array.isArray(e)) return "Array";
|
|
328
|
-
if (globalThis.Buffer !== void 0 && globalThis.Buffer.isBuffer(e)) return "Buffer";
|
|
329
|
-
let t = e.constructor?.name;
|
|
330
|
-
return typeof t == "string" && t !== "" ? t : "Object";
|
|
331
|
-
}, wr = Symbol.for("@voltro/database/storeRefusal"), Tr = (e) => {
|
|
148
|
+
}, Tr = Symbol.for("@voltro/database/storeRefusal"), Er = (e) => {
|
|
332
149
|
let t = Error(e.detail);
|
|
333
|
-
return Object.defineProperty(t,
|
|
150
|
+
return Object.defineProperty(t, Tr, {
|
|
334
151
|
value: e,
|
|
335
152
|
enumerable: !1
|
|
336
153
|
}), t;
|
|
337
|
-
},
|
|
338
|
-
for (let t of
|
|
154
|
+
}, Dr = (e) => {
|
|
155
|
+
for (let t of jn(e)) {
|
|
339
156
|
let e = t;
|
|
340
157
|
for (let t = 0; e != null && t < 8; t += 1) {
|
|
341
|
-
let t = e[
|
|
158
|
+
let t = e[Tr];
|
|
342
159
|
if (t !== void 0) return t;
|
|
343
160
|
e = e.cause;
|
|
344
161
|
}
|
|
345
162
|
}
|
|
346
|
-
},
|
|
163
|
+
}, Or = (e) => {
|
|
347
164
|
let t = (() => {
|
|
348
165
|
switch (e.type) {
|
|
349
|
-
case "id": return e.idScheme?.kind === "numeric" ?
|
|
166
|
+
case "id": return e.idScheme?.kind === "numeric" ? A.Number : A.String;
|
|
350
167
|
case "text":
|
|
351
|
-
case "enum": return
|
|
352
|
-
case "reference": return e.referenceStorage === "numeric" ?
|
|
168
|
+
case "enum": return A.String;
|
|
169
|
+
case "reference": return e.referenceStorage === "numeric" ? A.Number : A.String;
|
|
353
170
|
case "integer":
|
|
354
171
|
case "real":
|
|
355
|
-
case "decimal": return
|
|
356
|
-
case "boolean": return
|
|
172
|
+
case "decimal": return A.Number;
|
|
173
|
+
case "boolean": return A.Boolean;
|
|
357
174
|
case "timestamp":
|
|
358
|
-
case "date": return
|
|
359
|
-
case "bigint": return
|
|
360
|
-
case "bytes": return
|
|
361
|
-
case "array": return
|
|
362
|
-
case "interval": return
|
|
363
|
-
default: return
|
|
175
|
+
case "date": return Gn;
|
|
176
|
+
case "bigint": return A.BigInt;
|
|
177
|
+
case "bytes": return A.Uint8ArrayFromBase64;
|
|
178
|
+
case "array": return A.Array(A.Unknown);
|
|
179
|
+
case "interval": return A.String;
|
|
180
|
+
default: return A.Unknown;
|
|
364
181
|
}
|
|
365
182
|
})();
|
|
366
|
-
return e.nullable === !0 ?
|
|
367
|
-
},
|
|
183
|
+
return e.nullable === !0 ? A.NullOr(t) : t;
|
|
184
|
+
}, kr = (e, t) => {
|
|
368
185
|
let n = new Set(t?.omit ?? []), r = {};
|
|
369
|
-
for (let [t, i] of Object.entries(e.fields)) n.has(t) || (r[t] =
|
|
370
|
-
return
|
|
371
|
-
},
|
|
186
|
+
for (let [t, i] of Object.entries(e.fields)) n.has(t) || (r[t] = Or(i));
|
|
187
|
+
return A.Struct(r);
|
|
188
|
+
}, Ar = (e) => typeof e == "function" ? e : () => e, jr = (e, t) => ({
|
|
372
189
|
kind: "one",
|
|
373
|
-
target:
|
|
190
|
+
target: Ar(e),
|
|
374
191
|
...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
|
|
375
192
|
...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
|
|
376
|
-
}),
|
|
193
|
+
}), Mr = (e, t) => ({
|
|
377
194
|
kind: "many",
|
|
378
|
-
target:
|
|
195
|
+
target: Ar(e),
|
|
379
196
|
...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
|
|
380
197
|
...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
|
|
381
|
-
}),
|
|
198
|
+
}), Nr = (e, t) => ({
|
|
382
199
|
kind: "manyToMany",
|
|
383
|
-
target:
|
|
384
|
-
through:
|
|
200
|
+
target: Ar(e),
|
|
201
|
+
through: Ar(t.through),
|
|
385
202
|
sourceKey: t.sourceKey,
|
|
386
203
|
targetKey: t.targetKey
|
|
387
|
-
}),
|
|
388
|
-
one:
|
|
389
|
-
many:
|
|
390
|
-
manyToMany:
|
|
391
|
-
},
|
|
204
|
+
}), Pr = {
|
|
205
|
+
one: jr,
|
|
206
|
+
many: Mr,
|
|
207
|
+
manyToMany: Nr
|
|
208
|
+
}, Fr = (e, t) => {
|
|
392
209
|
let n = typeof e == "function" ? e : () => e;
|
|
393
210
|
return {
|
|
394
211
|
source: n,
|
|
395
|
-
relations: t(
|
|
212
|
+
relations: t(Pr, n())
|
|
396
213
|
};
|
|
397
|
-
},
|
|
214
|
+
}, Ir = (e) => {
|
|
398
215
|
if (typeof e != "object" || !e) return !1;
|
|
399
216
|
let t = e;
|
|
400
217
|
return typeof t.source != "function" || typeof t.relations != "object" || t.relations === null ? !1 : Object.keys(t.relations).length === 0;
|
|
401
|
-
},
|
|
218
|
+
}, Lr = (e) => {
|
|
402
219
|
if (typeof e != "object" || !e) return !1;
|
|
403
220
|
let t = e;
|
|
404
221
|
if (typeof t.source != "function" || typeof t.relations != "object" || t.relations === null) return !1;
|
|
@@ -407,7 +224,7 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
407
224
|
let t = e?.kind;
|
|
408
225
|
return t === "one" || t === "many" || t === "manyToMany";
|
|
409
226
|
});
|
|
410
|
-
},
|
|
227
|
+
}, Rr = jr, zr = Mr, Br = Nr, M = (e, t, n) => {
|
|
411
228
|
let r = [];
|
|
412
229
|
for (let [n, i] of Object.entries(e.fields)) i.type === "reference" && i.references?.()?.tableName === t && r.push(n);
|
|
413
230
|
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>' }.`);
|
|
@@ -432,10 +249,10 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
432
249
|
let t = Hr(e, n.foreignKey);
|
|
433
250
|
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}': ${Ur(i)}.`));
|
|
434
251
|
}
|
|
435
|
-
}, Gr = Symbol.for("@voltro/database/relationsRegistry"), Kr = globalThis,
|
|
436
|
-
let t = e.source(), n =
|
|
252
|
+
}, Gr = Symbol.for("@voltro/database/relationsRegistry"), Kr = globalThis, N = Kr[Gr] ?? (Kr[Gr] = /* @__PURE__ */ new Map()), qr = (e) => {
|
|
253
|
+
let t = e.source(), n = N.get(t.tableName);
|
|
437
254
|
if (n === void 0) {
|
|
438
|
-
|
|
255
|
+
N.set(t.tableName, new Map(Object.entries(e.relations)));
|
|
439
256
|
return;
|
|
440
257
|
}
|
|
441
258
|
for (let [r, i] of Object.entries(e.relations)) {
|
|
@@ -447,26 +264,26 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
447
264
|
}
|
|
448
265
|
}, Jr = (e) => {
|
|
449
266
|
let t = 0;
|
|
450
|
-
for (let n of Object.values(e))
|
|
267
|
+
for (let n of Object.values(e)) Lr(n) && (qr(n), t += 1);
|
|
451
268
|
return t;
|
|
452
269
|
}, Yr = (e) => {
|
|
453
|
-
let t =
|
|
270
|
+
let t = N.get(e);
|
|
454
271
|
if (t !== void 0) return Object.fromEntries(t);
|
|
455
|
-
}, Xr = (e, t) =>
|
|
272
|
+
}, Xr = (e, t) => N.get(e)?.get(t), Zr = () => {
|
|
456
273
|
let e = [];
|
|
457
|
-
for (let [t, n] of
|
|
274
|
+
for (let [t, n] of N) for (let [r, i] of n) e.push({
|
|
458
275
|
source: t,
|
|
459
276
|
name: r,
|
|
460
277
|
relation: i
|
|
461
278
|
});
|
|
462
279
|
return e;
|
|
463
280
|
}, Qr = () => {
|
|
464
|
-
for (let [e, t] of
|
|
465
|
-
let n =
|
|
281
|
+
for (let [e, t] of N) {
|
|
282
|
+
let n = cn(e);
|
|
466
283
|
if (n !== void 0) for (let [e, r] of t) Wr(n, e, r);
|
|
467
284
|
}
|
|
468
285
|
}, $r = () => {
|
|
469
|
-
|
|
286
|
+
N.clear();
|
|
470
287
|
}, ei = 4, ti = (e) => Object.keys(e.fields), ni = (e, t) => Object.prototype.hasOwnProperty.call(e.fields, t), ri = (e, t) => {
|
|
471
288
|
let n = [];
|
|
472
289
|
for (let [r, i] of Object.entries(e.fields)) i.type === "reference" && i.references?.()?.tableName === t && n.push(r);
|
|
@@ -519,7 +336,7 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
519
336
|
}
|
|
520
337
|
return n;
|
|
521
338
|
}, oi = (e) => `${e.table}\u0000${e.hops.map((e) => `${e.table}.${e.foreignKey}<-${e.parentKey}`).join("|")}`, si = (e) => {
|
|
522
|
-
let t = e.tables ??
|
|
339
|
+
let t = e.tables ?? Ye(), n = e.relations ?? Zr(), r = e.maxDepth ?? 4, i = new Set(e.exclude ?? []), a = new Map(t.map((e) => [e.tableName, e])), o = [];
|
|
523
340
|
if (!a.has(e.subjectTable)) return {
|
|
524
341
|
subjectTable: e.subjectTable,
|
|
525
342
|
paths: [],
|
|
@@ -735,7 +552,7 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
735
552
|
await Ai(i, r.with, o, a);
|
|
736
553
|
return;
|
|
737
554
|
}
|
|
738
|
-
let c = n.foreignKey ??
|
|
555
|
+
let c = n.foreignKey ?? M(o, i.tableName, t), l = n.sourceKey ?? "id", u = Oi(e, l), d = u.length === 0 ? [] : await ki(o, c, u, r, a), f = /* @__PURE__ */ new Map();
|
|
739
556
|
for (let e of d) {
|
|
740
557
|
let n = e[c];
|
|
741
558
|
if (f.has(n)) throw new yi(bi({
|
|
@@ -753,7 +570,7 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
753
570
|
}
|
|
754
571
|
await Ai(d, r.with, o, a);
|
|
755
572
|
}, wi = async (e, t, n, r, i, a) => {
|
|
756
|
-
let o = n.target(), s = n.foreignKey ??
|
|
573
|
+
let o = n.target(), s = n.foreignKey ?? M(o, i.tableName, t), c = n.sourceKey ?? "id", l = Oi(e, c), u = Ti(r), d = l.length === 0 ? [] : await ki(o, s, l, u, a), f = /* @__PURE__ */ new Map();
|
|
757
574
|
for (let e of d) {
|
|
758
575
|
let t = e[s], n = f.get(t);
|
|
759
576
|
n ? n.push(e) : f.set(t, [e]);
|
|
@@ -865,29 +682,29 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
865
682
|
let { strings: n, values: r } = e, i = t.unsafe(n[0] ?? "");
|
|
866
683
|
for (let e = 0; e < r.length; e++) i = t`${i}${r[e]}${t.unsafe(n[e + 1] ?? "")}`;
|
|
867
684
|
return t`${i}`;
|
|
868
|
-
},
|
|
869
|
-
if ("not" in e) return t`NOT (${
|
|
870
|
-
if ("and" in e) return e.and.length === 0 ? t`TRUE` : t.and(e.and.map((e) =>
|
|
871
|
-
if ("or" in e) return e.or.length === 0 ? t`FALSE` : t.or(e.or.map((e) =>
|
|
685
|
+
}, P = (e) => e.replace(/[\\%_]/g, (e) => `\\${e}`), F = (e, t, n = null, r) => {
|
|
686
|
+
if ("not" in e) return t`NOT (${F(e.not, t, n, r)})`;
|
|
687
|
+
if ("and" in e) return e.and.length === 0 ? t`TRUE` : t.and(e.and.map((e) => F(e, t, n, r)));
|
|
688
|
+
if ("or" in e) return e.or.length === 0 ? t`FALSE` : t.or(e.or.map((e) => F(e, t, n, r)));
|
|
872
689
|
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
873
|
-
let r = e, i =
|
|
690
|
+
let r = e, i = I(r.subquery, t, n);
|
|
874
691
|
return r.op === "subquery-in" ? t`${t(r.column)} IN (${i})` : t`${t(r.column)} NOT IN (${i})`;
|
|
875
692
|
}
|
|
876
693
|
if (e.op === "exists" || e.op === "not-exists") {
|
|
877
|
-
let r = e, i =
|
|
694
|
+
let r = e, i = I(r.subquery, t, n);
|
|
878
695
|
return r.op === "exists" ? t`EXISTS (${i})` : t`NOT EXISTS (${i})`;
|
|
879
696
|
}
|
|
880
697
|
let i = e, a = t(i.column), o = i.path, s = o !== void 0 && o.length > 0, c = () => t.onDialectOrElse({
|
|
881
|
-
mysql: () => t.unsafe(
|
|
882
|
-
mssql: () => t.unsafe(
|
|
883
|
-
sqlite: () => t.unsafe(
|
|
884
|
-
orElse: () => t.unsafe(
|
|
698
|
+
mysql: () => t.unsafe(C(i.column, o, "mysql")),
|
|
699
|
+
mssql: () => t.unsafe(C(i.column, o, "mssql")),
|
|
700
|
+
sqlite: () => t.unsafe(C(i.column, o, "sqlite")),
|
|
701
|
+
orElse: () => t.unsafe(C(i.column, o, "postgres"))
|
|
885
702
|
}), l = () => t.onDialectOrElse({
|
|
886
|
-
mysql: () => t.unsafe(
|
|
887
|
-
mssql: () => t.unsafe(
|
|
888
|
-
sqlite: () => t.unsafe(
|
|
889
|
-
orElse: () => t.unsafe(
|
|
890
|
-
}), 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 :
|
|
703
|
+
mysql: () => t.unsafe(C(i.column, o, "mysql", { numeric: !0 })),
|
|
704
|
+
mssql: () => t.unsafe(C(i.column, o, "mssql", { numeric: !0 })),
|
|
705
|
+
sqlite: () => t.unsafe(C(i.column, o, "sqlite", { numeric: !0 })),
|
|
706
|
+
orElse: () => t.unsafe(C(i.column, o, "postgres", { numeric: !0 }))
|
|
707
|
+
}), 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 : cn(r)?.fields?.[i.column]?.type, h = (e) => Vi(m, e);
|
|
891
708
|
switch (i.op) {
|
|
892
709
|
case "eq": return t`${u} = ${f(h(i.value))}`;
|
|
893
710
|
case "neq": return t`${u} <> ${f(h(i.value))}`;
|
|
@@ -904,7 +721,7 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
904
721
|
return e.length === 0 ? t`TRUE` : t`${u} NOT IN ${t.in(s ? e.map((e) => f(e)) : e)}`;
|
|
905
722
|
}
|
|
906
723
|
case "contains": {
|
|
907
|
-
let e = `%${
|
|
724
|
+
let e = `%${P(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
|
|
908
725
|
return t.onDialectOrElse({
|
|
909
726
|
mysql: () => t`LOWER(${u}) LIKE LOWER(${e})`,
|
|
910
727
|
mssql: () => t`LOWER(${u}) LIKE LOWER(${e})`,
|
|
@@ -913,7 +730,7 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
913
730
|
});
|
|
914
731
|
}
|
|
915
732
|
case "startsWith": {
|
|
916
|
-
let e = `${
|
|
733
|
+
let e = `${P(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
|
|
917
734
|
return t.onDialectOrElse({
|
|
918
735
|
mysql: () => t`${u} LIKE ${e}`,
|
|
919
736
|
orElse: () => t`${u} LIKE ${e} ESCAPE '\\'`
|
|
@@ -1004,7 +821,7 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
1004
821
|
let n = t.unsafe(e.useGeography ? "::geography" : "::geometry");
|
|
1005
822
|
return t`ST_Distance(${t(e.column)}${n}, ${e.geom}${n})`;
|
|
1006
823
|
}, Yi = (e, t) => t`${t(e.column)} <-> ${e.geom}::geometry`, Xi = (e, t) => t`${t(`${e.indexName}_tsv`)}`, Zi = (e, t) => `${t}_${e.indexName}_fts`, Qi = (e, t, n) => {
|
|
1007
|
-
let r = n.csv(e.columns.map((e) => n`${n(e)}`)), i = `%${
|
|
824
|
+
let r = n.csv(e.columns.map((e) => n`${n(e)}`)), i = `%${P(e.query)}%`;
|
|
1008
825
|
return n.onDialectOrElse({
|
|
1009
826
|
mysql: () => n`MATCH(${r}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
|
|
1010
827
|
sqlite: () => {
|
|
@@ -1015,7 +832,7 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
1015
832
|
orElse: () => n`${Xi(e, n)} @@ plainto_tsquery(${e.config ?? "english"}, ${e.query})`
|
|
1016
833
|
});
|
|
1017
834
|
}, $i = (e, t, n) => {
|
|
1018
|
-
let r = `%${
|
|
835
|
+
let r = `%${P(e.query)}%`;
|
|
1019
836
|
return n.onDialectOrElse({
|
|
1020
837
|
mysql: () => n`MATCH(${n.csv(e.columns.map((e) => n`${n(e)}`))}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
|
|
1021
838
|
sqlite: () => {
|
|
@@ -1025,10 +842,10 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
1025
842
|
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}`),
|
|
1026
843
|
orElse: () => n`ts_rank(${Xi(e, n)}, plainto_tsquery(${e.config ?? "english"}, ${e.query}))`
|
|
1027
844
|
});
|
|
1028
|
-
},
|
|
845
|
+
}, I = (e, t, n = null) => {
|
|
1029
846
|
if (e.setOp && e.setOp.queries.length >= 2) {
|
|
1030
|
-
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`(${
|
|
1031
|
-
if (
|
|
847
|
+
let r = e.setOp.kind === "union" ? "UNION" : e.setOp.kind === "union-all" ? "UNION ALL" : e.setOp.kind === "intersect" ? "INTERSECT" : "EXCEPT", i = e.setOp.queries.map((e) => t`(${I(e, t, n)})`).reduce((e, n, i) => i === 0 ? n : t`${e} ${t.unsafe(r)} ${n}`), a = [];
|
|
848
|
+
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) {
|
|
1032
849
|
if (!Number.isInteger(e.take) || e.take < 0) throw Error(`compileSelect: invalid take ${e.take}`);
|
|
1033
850
|
a.push(t` LIMIT ${t.unsafe(String(e.take))}`);
|
|
1034
851
|
}
|
|
@@ -1051,64 +868,64 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
1051
868
|
},
|
|
1052
869
|
orElse: () => t``
|
|
1053
870
|
});
|
|
1054
|
-
let i = e.spatialClause?.projectAs === void 0 ? null : Ji(e.spatialClause, t), a = e.aggregations && e.aggregations.length > 0 ? Gi(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 ? $i(c, e.table, t) : null,
|
|
871
|
+
let i = e.spatialClause?.projectAs === void 0 ? null : Ji(e.spatialClause, t), a = e.aggregations && e.aggregations.length > 0 ? Gi(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 ? $i(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({
|
|
1055
872
|
orElse: () => t`DISTINCT ON (${t.csv(e.distinctOn.map((e) => t`${t(e)}`))}) `,
|
|
1056
873
|
mysql: () => t`DISTINCT `,
|
|
1057
874
|
mssql: () => t`DISTINCT `,
|
|
1058
875
|
sqlite: () => t`DISTINCT `
|
|
1059
|
-
}) : e.distinct ? t`DISTINCT ` : t``,
|
|
876
|
+
}) : e.distinct ? t`DISTINCT ` : t``, p = e.lock === "update", m = p ? t.onDialectOrElse({
|
|
1060
877
|
mssql: () => t` WITH (UPDLOCK, ROWLOCK)`,
|
|
1061
878
|
orElse: () => t``
|
|
1062
|
-
}) : t``,
|
|
879
|
+
}) : t``, h = p ? t.onDialectOrElse({
|
|
1063
880
|
mssql: () => t``,
|
|
1064
881
|
sqlite: () => t``,
|
|
1065
882
|
orElse: () => t` FOR UPDATE`
|
|
1066
|
-
}) : t``,
|
|
883
|
+
}) : t``, g = e.alias === void 0 ? t`${t(Ri(n, e.table))}${m}` : t`${t(Ri(n, e.table))} AS ${t(e.alias)}${m}`, _ = (e.joins ?? []).map((e) => {
|
|
1067
884
|
let r = e.kind === "inner" ? "INNER" : "LEFT";
|
|
1068
|
-
return t` ${t.unsafe(r)} JOIN ${t(Ri(n, e.table))} AS ${t(e.alias)} ON ${
|
|
1069
|
-
}),
|
|
1070
|
-
r !== null &&
|
|
1071
|
-
for (let n of
|
|
1072
|
-
let
|
|
885
|
+
return t` ${t.unsafe(r)} JOIN ${t(Ri(n, e.table))} AS ${t(e.alias)} ON ${F(e.on, t, n)}`;
|
|
886
|
+
}), v = _.length > 0 ? _.reduce((e, n) => t`${e}${n}`, g) : g, ee = c === void 0 ? null : Qi(c, e.table, t), te = [e.predicate ? F(e.predicate, t, n, e.table) : null, ee].filter((e) => e !== null), ne = te.length > 0 ? t` WHERE ${t.and(te)}` : t``, re = e.groupBy && e.groupBy.length > 0 ? t` GROUP BY ${t.csv(e.groupBy.map((e) => t`${t(e)}`))}` : t``, ie = e.having ? t` HAVING ${F(e.having, t, n, e.table)}` : t``, ae = e.skip !== void 0, y = [];
|
|
887
|
+
r !== null && y.push(t`${r} ASC`), e.spatialClause?.order !== void 0 && y.push(e.spatialClause.order === "desc" ? t`${Yi(e.spatialClause, t)} DESC` : t`${Yi(e.spatialClause, t)} ASC`), l !== null && c?.rank?.order === !0 && y.push(t`${l} DESC`);
|
|
888
|
+
for (let n of x(e)) y.push(n.direction === "desc" ? t`${t(n.column)} DESC` : t`${t(n.column)} ASC`);
|
|
889
|
+
let oe = y.length > 0 ? t` ORDER BY ${t.csv(y)}` : ae ? t.onDialectOrElse({
|
|
1073
890
|
mssql: () => t` ORDER BY (SELECT NULL)`,
|
|
1074
891
|
orElse: () => t``
|
|
1075
|
-
}) : t``,
|
|
892
|
+
}) : t``, b = (e) => {
|
|
1076
893
|
if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw Error(`compileSelect: expected non-negative integer take/skip, got ${e}`);
|
|
1077
894
|
return t.unsafe(String(e));
|
|
1078
|
-
},
|
|
895
|
+
}, se = (e.ctes ?? []).map((e) => t`${t(e.name)} AS (${I(e.descriptor, t, n)})`), ce = (e.ctes ?? []).some((e) => e.recursive === !0), le = se.length > 0 ? t`WITH ${t.unsafe(ce ? "RECURSIVE " : "")}${t.csv(se)} ` : t``;
|
|
1079
896
|
return t.onDialectOrElse({
|
|
1080
897
|
mssql: () => {
|
|
1081
|
-
let n = e.take !== void 0 && !ae ? t`TOP ${
|
|
1082
|
-
return t`${
|
|
898
|
+
let n = e.take !== void 0 && !ae ? t`TOP ${b(e.take)} ` : t``, r = ae ? t` OFFSET ${b(e.skip)} ROWS FETCH NEXT ${b(e.take ?? 2 ** 53 - 1)} ROWS ONLY` : t``;
|
|
899
|
+
return t`${le}SELECT ${n}${f}${d} FROM ${v}${ne}${re}${ie}${oe}${r}`;
|
|
1083
900
|
},
|
|
1084
901
|
orElse: () => {
|
|
1085
|
-
let n = e.take === void 0 ? t`` : t` LIMIT ${
|
|
1086
|
-
return t`${
|
|
902
|
+
let n = e.take === void 0 ? t`` : t` LIMIT ${b(e.take)}`, r = ae ? t` OFFSET ${b(e.skip)}` : t``;
|
|
903
|
+
return t`${le}SELECT ${f}${d} FROM ${v}${ne}${re}${ie}${oe}${n}${r}${h}`;
|
|
1087
904
|
}
|
|
1088
905
|
});
|
|
1089
|
-
},
|
|
906
|
+
}, ea = (e, t, n) => {
|
|
1090
907
|
if (e.eager === void 0) return null;
|
|
1091
|
-
let r =
|
|
908
|
+
let r = ra(e.table, e.eager, e.sourceTable);
|
|
1092
909
|
if (r === null) return null;
|
|
1093
|
-
let i =
|
|
910
|
+
let i = ua(n, e, r, la(t, n));
|
|
1094
911
|
return i === null ? null : {
|
|
1095
912
|
fragment: i,
|
|
1096
|
-
decode:
|
|
913
|
+
decode: pa(r, n)
|
|
1097
914
|
};
|
|
1098
|
-
},
|
|
915
|
+
}, ta = (e) => e.relation.kind === "one" && e.fkSide === "target", na = (e) => ({
|
|
1099
916
|
...e,
|
|
1100
917
|
branch: {
|
|
1101
918
|
...e.branch,
|
|
1102
919
|
limit: 2
|
|
1103
920
|
}
|
|
1104
|
-
}),
|
|
1105
|
-
let r = n ??
|
|
921
|
+
}), ra = (e, t, n) => {
|
|
922
|
+
let r = n ?? Qe(e), i = Yr(e);
|
|
1106
923
|
if (i === void 0) return null;
|
|
1107
924
|
let a = [];
|
|
1108
925
|
for (let [e, n] of Object.entries(t)) {
|
|
1109
926
|
let t = i[e];
|
|
1110
927
|
if (t === void 0) return null;
|
|
1111
|
-
let o =
|
|
928
|
+
let o = ia(e, t, r, n === !0 ? {} : n);
|
|
1112
929
|
if (o === null) return null;
|
|
1113
930
|
a.push(o);
|
|
1114
931
|
}
|
|
@@ -1116,19 +933,19 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
1116
933
|
table: r,
|
|
1117
934
|
children: a
|
|
1118
935
|
};
|
|
1119
|
-
},
|
|
936
|
+
}, ia = (e, t, n, r) => {
|
|
1120
937
|
let i = t.target(), a = (t.kind === "manyToMany" ? void 0 : t.sourceKey) ?? "id", o, s;
|
|
1121
938
|
if (t.kind === "manyToMany") o = t.targetKey, s = "target";
|
|
1122
939
|
else if (t.kind === "one") {
|
|
1123
|
-
let r = t.sourceKey ??
|
|
940
|
+
let r = t.sourceKey ?? ca(n, i.tableName);
|
|
1124
941
|
if (r !== void 0) o = r, s = "source";
|
|
1125
942
|
else try {
|
|
1126
|
-
o = t.foreignKey ??
|
|
943
|
+
o = t.foreignKey ?? M(i, n.tableName, e), s = "target";
|
|
1127
944
|
} catch {
|
|
1128
945
|
return null;
|
|
1129
946
|
}
|
|
1130
947
|
} else try {
|
|
1131
|
-
o = t.foreignKey ??
|
|
948
|
+
o = t.foreignKey ?? M(i, n.tableName, e), s = "target";
|
|
1132
949
|
} catch {
|
|
1133
950
|
return null;
|
|
1134
951
|
}
|
|
@@ -1139,7 +956,7 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
1139
956
|
for (let [n, a] of Object.entries(r.with)) {
|
|
1140
957
|
let r = e?.[n];
|
|
1141
958
|
if (r === void 0) return null;
|
|
1142
|
-
let o =
|
|
959
|
+
let o = ia(n, r, i, a === !0 ? {} : a);
|
|
1143
960
|
if (o === null) return null;
|
|
1144
961
|
t.push(o);
|
|
1145
962
|
}
|
|
@@ -1155,9 +972,9 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
1155
972
|
fkSide: s,
|
|
1156
973
|
branch: r,
|
|
1157
974
|
children: c,
|
|
1158
|
-
junction:
|
|
975
|
+
junction: aa(t, r)
|
|
1159
976
|
};
|
|
1160
|
-
},
|
|
977
|
+
}, aa = (e, t) => {
|
|
1161
978
|
if (e.kind !== "manyToMany" || t.junction === void 0) return;
|
|
1162
979
|
let n = e.through(), r = t.junction === !0 ? Object.keys(n.fields) : t.junction, i = r.filter((e) => e in n.fields);
|
|
1163
980
|
return {
|
|
@@ -1169,35 +986,35 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
1169
986
|
return t !== void 0 && (t.type === "timestamp" || t.type === "date");
|
|
1170
987
|
})
|
|
1171
988
|
};
|
|
1172
|
-
},
|
|
989
|
+
}, oa = (e) => `__j_${e}`, sa = "__j", ca = (e, t) => {
|
|
1173
990
|
for (let [n, r] of Object.entries(e.fields)) if (r.type === "reference" && r.references?.()?.tableName === t) return n;
|
|
1174
|
-
},
|
|
991
|
+
}, la = (e, t) => {
|
|
1175
992
|
let n = 0;
|
|
1176
993
|
return {
|
|
1177
994
|
sql: e,
|
|
1178
995
|
dialect: t,
|
|
1179
996
|
nextAlias: () => `__a${n++}`
|
|
1180
997
|
};
|
|
1181
|
-
},
|
|
998
|
+
}, ua = (e, t, n, r) => {
|
|
1182
999
|
switch (e) {
|
|
1183
|
-
case "postgres": return
|
|
1000
|
+
case "postgres": return ga(t, n, r);
|
|
1184
1001
|
case "sqlite":
|
|
1185
|
-
case "turso": return
|
|
1002
|
+
case "turso": return wa(t, n, r);
|
|
1186
1003
|
case "mysql":
|
|
1187
|
-
case "mariadb": return
|
|
1188
|
-
case "mssql": return
|
|
1004
|
+
case "mariadb": return Pa(t, n, r);
|
|
1005
|
+
case "mssql": return Va(t, n, r);
|
|
1189
1006
|
}
|
|
1190
|
-
},
|
|
1191
|
-
let n =
|
|
1007
|
+
}, da = (e, t) => t === "mssql" && !fa.test(e) ? /* @__PURE__ */ new Date(`${e}Z`) : new Date(e), fa = /(?:Z|[+-]\d{2}:?\d{2})$/, pa = (e, t) => {
|
|
1008
|
+
let n = ma(e.table, e.children, t);
|
|
1192
1009
|
return (e) => e.map((e) => {
|
|
1193
1010
|
let t = e.__row, r = typeof t == "string" ? JSON.parse(t) : t;
|
|
1194
1011
|
return n(r);
|
|
1195
1012
|
});
|
|
1196
|
-
},
|
|
1013
|
+
}, ma = (e, t, n) => {
|
|
1197
1014
|
let r = [], i = [];
|
|
1198
1015
|
for (let [t, n] of Object.entries(e.fields)) (n.type === "timestamp" || n.type === "date") && r.push(t), n.type === "vector" && i.push(t);
|
|
1199
1016
|
let a = t.map((e) => {
|
|
1200
|
-
let t =
|
|
1017
|
+
let t = ma(e.target, e.children, n), r = e.relation.kind === "one", i = ta(e), a = i ? bi({
|
|
1201
1018
|
relationName: e.relationName,
|
|
1202
1019
|
sourceTableName: e.source.tableName,
|
|
1203
1020
|
targetTableName: e.target.tableName,
|
|
@@ -1210,15 +1027,15 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
1210
1027
|
isSingle: r,
|
|
1211
1028
|
fromOverFetch: i,
|
|
1212
1029
|
cardinalityMessage: a,
|
|
1213
|
-
junction:
|
|
1030
|
+
junction: ha(e.junction, n)
|
|
1214
1031
|
};
|
|
1215
1032
|
});
|
|
1216
1033
|
return (e) => {
|
|
1217
1034
|
let t = { ...e };
|
|
1218
|
-
for (let e of i) e in t && (t[e] =
|
|
1035
|
+
for (let e of i) e in t && (t[e] = Et(t[e], "vector", n));
|
|
1219
1036
|
for (let e of r) {
|
|
1220
1037
|
let r = t[e];
|
|
1221
|
-
typeof r == "string" && (t[e] =
|
|
1038
|
+
typeof r == "string" && (t[e] = da(r, n));
|
|
1222
1039
|
}
|
|
1223
1040
|
for (let e of a) {
|
|
1224
1041
|
let n = t[e.name];
|
|
@@ -1240,204 +1057,204 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
1240
1057
|
}
|
|
1241
1058
|
return t;
|
|
1242
1059
|
};
|
|
1243
|
-
},
|
|
1060
|
+
}, ha = (e, t) => {
|
|
1244
1061
|
if (e === void 0) return;
|
|
1245
1062
|
let n = new Set(e.dateColumns), r = e.requested;
|
|
1246
1063
|
return (e) => {
|
|
1247
1064
|
let i = e._junction ?? {}, a = {};
|
|
1248
1065
|
for (let e of r) {
|
|
1249
1066
|
let r = i[e];
|
|
1250
|
-
a[e] = n.has(e) && typeof r == "string" ?
|
|
1067
|
+
a[e] = n.has(e) && typeof r == "string" ? da(r, t) : r;
|
|
1251
1068
|
}
|
|
1252
1069
|
return {
|
|
1253
1070
|
...e,
|
|
1254
1071
|
_junction: a
|
|
1255
1072
|
};
|
|
1256
1073
|
};
|
|
1257
|
-
},
|
|
1258
|
-
let r = n.sql, i = n.nextAlias(), a = r(t.table.tableName), o = r(i), s =
|
|
1259
|
-
return s === null ? null : r`SELECT ${s} AS "__row" FROM ${a} AS ${o}${e.predicate ? r` WHERE ${
|
|
1260
|
-
},
|
|
1261
|
-
let i = n.sql, a = r === void 0 ? i`to_jsonb(${i(e)}.*)` : i`(to_jsonb(${i(e)}.*) - ${
|
|
1074
|
+
}, ga = (e, t, n) => {
|
|
1075
|
+
let r = n.sql, i = n.nextAlias(), a = r(t.table.tableName), o = r(i), s = _a(i, t.children, n);
|
|
1076
|
+
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)}`}`;
|
|
1077
|
+
}, _a = (e, t, n, r) => {
|
|
1078
|
+
let i = n.sql, a = r === void 0 ? i`to_jsonb(${i(e)}.*)` : i`(to_jsonb(${i(e)}.*) - ${B(sa, i)}::text)`;
|
|
1262
1079
|
if (t.length === 0 && r === void 0) return a;
|
|
1263
1080
|
let o = [];
|
|
1264
|
-
r !== void 0 && o.push(i`${
|
|
1081
|
+
r !== void 0 && o.push(i`${B("_junction", i)}, ${z(e, sa, i)}`);
|
|
1265
1082
|
for (let r of t) {
|
|
1266
|
-
let t =
|
|
1083
|
+
let t = va(r, e, n);
|
|
1267
1084
|
if (t === null) return null;
|
|
1268
|
-
o.push(i`${
|
|
1085
|
+
o.push(i`${B(r.relationName, i)}, ${t}`);
|
|
1269
1086
|
}
|
|
1270
1087
|
return i`${a} || jsonb_build_object(${i.csv(o)})`;
|
|
1271
|
-
},
|
|
1088
|
+
}, va = (e, t, n) => {
|
|
1272
1089
|
switch (e.relation.kind) {
|
|
1273
|
-
case "one": return
|
|
1274
|
-
case "many": return
|
|
1275
|
-
case "manyToMany": return
|
|
1090
|
+
case "one": return ta(e) ? ba(na(e), t, n) : ya(e, t, n);
|
|
1091
|
+
case "many": return ba(e, t, n);
|
|
1092
|
+
case "manyToMany": return xa(e, t, n);
|
|
1276
1093
|
}
|
|
1277
|
-
},
|
|
1278
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1094
|
+
}, ya = (e, t, n) => {
|
|
1095
|
+
let r = n.sql, i = n.nextAlias(), a = _a(i, e.children, n);
|
|
1279
1096
|
if (a === null) return null;
|
|
1280
|
-
let o = e.fkSide === "source" ? r`${
|
|
1097
|
+
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);
|
|
1281
1098
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}${c} LIMIT 1)`;
|
|
1282
|
-
},
|
|
1283
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1099
|
+
}, ba = (e, t, n) => {
|
|
1100
|
+
let r = n.sql, i = n.nextAlias(), a = _a(i, e.children, n);
|
|
1284
1101
|
if (a === null) return null;
|
|
1285
|
-
let o = r`${
|
|
1102
|
+
let o = r`${z(void 0, e.foreignKey, r)} = ${z(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${F(e.branch.where, r)}`, c = Ca(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${V(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${V(e.branch.offset, r)}`;
|
|
1286
1103
|
return r`COALESCE((SELECT jsonb_agg(${a}) FROM (SELECT * FROM ${r(e.target.tableName)} WHERE ${o}${s}${c}${l}${u}) AS ${r(i)}), '[]'::jsonb)`;
|
|
1287
|
-
},
|
|
1288
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
1104
|
+
}, xa = (e, t, n) => {
|
|
1105
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = _a(o, e.children, n, e.junction);
|
|
1289
1106
|
if (c === null) return null;
|
|
1290
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1291
|
-
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 ${
|
|
1292
|
-
},
|
|
1293
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1107
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${F(e.branch.where, r)}`, u = U(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`, ${Sa(e.junction, s, r)} AS ${r(sa)}`;
|
|
1108
|
+
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)`;
|
|
1109
|
+
}, Sa = (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`))}`, Ca = (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`))}`, wa = (e, t, n) => {
|
|
1110
|
+
let r = n.sql, i = n.nextAlias(), a = Ta(i, t.table, t.children, n);
|
|
1294
1111
|
if (a === null) return null;
|
|
1295
|
-
let o = e.predicate ? r` WHERE ${
|
|
1112
|
+
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)}`;
|
|
1296
1113
|
return r`SELECT ${a} AS "__row" FROM ${r(t.table.tableName)} AS ${r(i)}${o}${s}${c}${l}`;
|
|
1297
|
-
},
|
|
1114
|
+
}, Ta = (e, t, n, r, i) => {
|
|
1298
1115
|
let a = r.sql, o = [];
|
|
1299
|
-
for (let n of Object.keys(t.fields)) o.push(a`${
|
|
1116
|
+
for (let n of Object.keys(t.fields)) o.push(a`${B(n, a)}, ${z(e, n, a)}`);
|
|
1300
1117
|
if (i !== void 0) {
|
|
1301
|
-
let e =
|
|
1302
|
-
o.push(a`${
|
|
1118
|
+
let e = Ea(i.projection, i.source, a);
|
|
1119
|
+
o.push(a`${B("_junction", a)}, json_object(${e})`);
|
|
1303
1120
|
}
|
|
1304
1121
|
for (let t of n) {
|
|
1305
|
-
let n =
|
|
1122
|
+
let n = Aa(t, e, r);
|
|
1306
1123
|
if (n === null) return null;
|
|
1307
|
-
o.push(a`${
|
|
1124
|
+
o.push(a`${B(t.relationName, a)}, ${n}`);
|
|
1308
1125
|
}
|
|
1309
1126
|
return a`json_object(${a.csv(o)})`;
|
|
1310
|
-
},
|
|
1127
|
+
}, Ea = (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)}`)), Da = (e, t, n) => e.present.length === 0 ? n`` : n`, ${n.csv(e.present.map((e) => n`${z(t, e, n)} AS ${n(oa(e))}`))}`, Oa = (e) => ({
|
|
1311
1128
|
alias: e,
|
|
1312
|
-
physical:
|
|
1313
|
-
}),
|
|
1129
|
+
physical: oa
|
|
1130
|
+
}), ka = (e) => ({
|
|
1314
1131
|
alias: e,
|
|
1315
1132
|
physical: (e) => e
|
|
1316
|
-
}),
|
|
1133
|
+
}), Aa = (e, t, n) => {
|
|
1317
1134
|
switch (e.relation.kind) {
|
|
1318
|
-
case "one": return
|
|
1319
|
-
case "many": return
|
|
1320
|
-
case "manyToMany": return
|
|
1135
|
+
case "one": return ta(e) ? Ma(na(e), t, n) : ja(e, t, n);
|
|
1136
|
+
case "many": return Ma(e, t, n);
|
|
1137
|
+
case "manyToMany": return Na(e, t, n);
|
|
1321
1138
|
}
|
|
1322
|
-
},
|
|
1323
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1139
|
+
}, ja = (e, t, n) => {
|
|
1140
|
+
let r = n.sql, i = n.nextAlias(), a = Ta(i, e.target, e.children, n);
|
|
1324
1141
|
if (a === null) return null;
|
|
1325
|
-
let o = e.fkSide === "source" ? r`${
|
|
1142
|
+
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)}`;
|
|
1326
1143
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
|
|
1327
|
-
},
|
|
1328
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1144
|
+
}, Ma = (e, t, n) => {
|
|
1145
|
+
let r = n.sql, i = n.nextAlias(), a = Ta(i, e.target, e.children, n);
|
|
1329
1146
|
if (a === null) return null;
|
|
1330
|
-
let o = r`${
|
|
1147
|
+
let o = r`${z(void 0, e.foreignKey, r)} = ${z(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${F(W(e.branch.where), r)}`, c = Ca(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)}`;
|
|
1331
1148
|
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('[]'))`;
|
|
1332
|
-
},
|
|
1333
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
1149
|
+
}, Na = (e, t, n) => {
|
|
1150
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = Ta(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
1334
1151
|
projection: e.junction,
|
|
1335
|
-
source:
|
|
1152
|
+
source: Oa(o)
|
|
1336
1153
|
});
|
|
1337
1154
|
if (c === null) return null;
|
|
1338
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1339
|
-
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 ${
|
|
1340
|
-
},
|
|
1341
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1155
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${F(W(e.branch.where), r)}`, u = U(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`` : Da(e.junction, s, r);
|
|
1156
|
+
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('[]'))`;
|
|
1157
|
+
}, Pa = (e, t, n) => {
|
|
1158
|
+
let r = n.sql, i = n.nextAlias(), a = R(i, t.table, t.children, n);
|
|
1342
1159
|
if (a === null) return null;
|
|
1343
|
-
let o = e.predicate ? r` WHERE ${
|
|
1160
|
+
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)}`;
|
|
1344
1161
|
return r`SELECT ${a} AS \`__row\` FROM ${r(t.table.tableName)} AS ${r(i)}${o}${s}${c}${l}`;
|
|
1345
|
-
},
|
|
1162
|
+
}, R = (e, t, n, r, i) => {
|
|
1346
1163
|
let a = r.sql, o = [];
|
|
1347
|
-
for (let n of Object.keys(t.fields)) o.push(a`${
|
|
1164
|
+
for (let n of Object.keys(t.fields)) o.push(a`${B(n, a)}, ${z(e, n, a)}`);
|
|
1348
1165
|
if (i !== void 0) {
|
|
1349
|
-
let e =
|
|
1350
|
-
o.push(a`${
|
|
1166
|
+
let e = Ea(i.projection, i.source, a);
|
|
1167
|
+
o.push(a`${B("_junction", a)}, JSON_OBJECT(${e})`);
|
|
1351
1168
|
}
|
|
1352
1169
|
for (let t of n) {
|
|
1353
|
-
let n =
|
|
1170
|
+
let n = Fa(t, e, r);
|
|
1354
1171
|
if (n === null) return null;
|
|
1355
|
-
o.push(a`${
|
|
1172
|
+
o.push(a`${B(t.relationName, a)}, ${n}`);
|
|
1356
1173
|
}
|
|
1357
1174
|
return a`JSON_OBJECT(${a.csv(o)})`;
|
|
1358
|
-
},
|
|
1175
|
+
}, Fa = (e, t, n) => {
|
|
1359
1176
|
switch (e.relation.kind) {
|
|
1360
1177
|
case "one":
|
|
1361
|
-
if (
|
|
1362
|
-
let r =
|
|
1363
|
-
return n.dialect === "mariadb" ?
|
|
1178
|
+
if (ta(e)) {
|
|
1179
|
+
let r = na(e);
|
|
1180
|
+
return n.dialect === "mariadb" ? za(r, t, n) : La(r, t, n);
|
|
1364
1181
|
}
|
|
1365
|
-
return
|
|
1366
|
-
case "many": return n.dialect === "mariadb" ?
|
|
1367
|
-
case "manyToMany": return n.dialect === "mariadb" ?
|
|
1182
|
+
return Ia(e, t, n);
|
|
1183
|
+
case "many": return n.dialect === "mariadb" ? za(e, t, n) : La(e, t, n);
|
|
1184
|
+
case "manyToMany": return n.dialect === "mariadb" ? Ba(e, t, n) : Ra(e, t, n);
|
|
1368
1185
|
}
|
|
1369
|
-
},
|
|
1370
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1186
|
+
}, Ia = (e, t, n) => {
|
|
1187
|
+
let r = n.sql, i = n.nextAlias(), a = R(i, e.target, e.children, n);
|
|
1371
1188
|
if (a === null) return null;
|
|
1372
|
-
let o = e.fkSide === "source" ? r`${
|
|
1189
|
+
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)}`;
|
|
1373
1190
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
|
|
1374
|
-
},
|
|
1375
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1191
|
+
}, La = (e, t, n) => {
|
|
1192
|
+
let r = n.sql, i = n.nextAlias(), a = R(i, e.target, e.children, n);
|
|
1376
1193
|
if (a === null) return null;
|
|
1377
|
-
let o = r`${
|
|
1194
|
+
let o = r`${z(void 0, e.foreignKey, r)} = ${z(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${F(W(e.branch.where), r)}`, c = Ca(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)}`;
|
|
1378
1195
|
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())`;
|
|
1379
|
-
},
|
|
1380
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
1196
|
+
}, Ra = (e, t, n) => {
|
|
1197
|
+
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 : {
|
|
1381
1198
|
projection: e.junction,
|
|
1382
|
-
source:
|
|
1199
|
+
source: Oa(o)
|
|
1383
1200
|
});
|
|
1384
1201
|
if (c === null) return null;
|
|
1385
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1386
|
-
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 ${
|
|
1387
|
-
},
|
|
1388
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1202
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${F(W(e.branch.where), r)}`, u = U(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`` : Da(e.junction, s, r);
|
|
1203
|
+
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())`;
|
|
1204
|
+
}, za = (e, t, n) => {
|
|
1205
|
+
let r = n.sql, i = n.nextAlias(), a = R(i, e.target, e.children, n);
|
|
1389
1206
|
if (a === null) return null;
|
|
1390
|
-
let o = r`${
|
|
1391
|
-
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`${
|
|
1392
|
-
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 ${
|
|
1393
|
-
return r`COALESCE((SELECT JSON_ARRAYAGG(${a} ORDER BY ${
|
|
1394
|
-
},
|
|
1207
|
+
let o = r`${z(i, e.foreignKey, r)} = ${z(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${F(W(e.branch.where), r)}`, c = e.branch.orderBy ?? [];
|
|
1208
|
+
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())`;
|
|
1209
|
+
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)}`;
|
|
1210
|
+
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())`;
|
|
1211
|
+
}, Ba = (e, t, n) => {
|
|
1395
1212
|
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = (t) => e.junction === void 0 ? void 0 : {
|
|
1396
1213
|
projection: e.junction,
|
|
1397
1214
|
source: t
|
|
1398
|
-
}, l = r`${
|
|
1215
|
+
}, 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 ${F(W(e.branch.where), r)}`, f = U(e, s, r, !0), p = e.branch.orderBy ?? [];
|
|
1399
1216
|
if (e.branch.limit === void 0 && e.branch.offset === void 0) {
|
|
1400
|
-
let t =
|
|
1401
|
-
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`${
|
|
1217
|
+
let t = R(o, e.target, e.children, n, c(ka(s)));
|
|
1218
|
+
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())`;
|
|
1402
1219
|
}
|
|
1403
|
-
let m = p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${
|
|
1220
|
+
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)}`, v = e.branch.onJunction === void 0 ? r`` : r` WHERE ${H(W(e.branch.onJunction), s, r)}`, ee = R(o, e.target, e.children, n, c(Oa(o)));
|
|
1404
1221
|
if (ee === null) return null;
|
|
1405
|
-
let te = e.junction === void 0 ? r`` :
|
|
1406
|
-
return r`COALESCE((SELECT JSON_ARRAYAGG(${ee} ORDER BY ${
|
|
1407
|
-
},
|
|
1408
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1222
|
+
let te = e.junction === void 0 ? r`` : Da(e.junction, s, r);
|
|
1223
|
+
return r`COALESCE((SELECT JSON_ARRAYAGG(${ee} ORDER BY ${z(o, "rn", r)}) FROM (SELECT ${r(o)}.*${te}, ${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}${v}) AS ${r(o)} WHERE ${z(o, `__src_${i.sourceKey}`, r)} = ${z(t, "id", r)}${d}${_}), JSON_ARRAY())`;
|
|
1224
|
+
}, Va = (e, t, n) => {
|
|
1225
|
+
let r = n.sql, i = n.nextAlias(), a = Ha(i, t.table, t.children, n);
|
|
1409
1226
|
if (a === null) return null;
|
|
1410
|
-
let o = e.predicate ? r` WHERE ${
|
|
1227
|
+
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``;
|
|
1411
1228
|
if (e.skip !== void 0) {
|
|
1412
|
-
let t =
|
|
1413
|
-
l = e.take === void 0 ? r`${t} OFFSET ${
|
|
1414
|
-
} else e.take !== void 0 && (c = r`TOP ${
|
|
1415
|
-
let
|
|
1416
|
-
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}${
|
|
1417
|
-
},
|
|
1229
|
+
let t = x(e).length > 0 ? s : r` ORDER BY (SELECT NULL)`;
|
|
1230
|
+
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`;
|
|
1231
|
+
} else e.take !== void 0 && (c = r`TOP ${V(e.take, r)} `);
|
|
1232
|
+
let u = e.skip === void 0 ? s : r``;
|
|
1233
|
+
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}`;
|
|
1234
|
+
}, Ha = (e, t, n, r, i) => {
|
|
1418
1235
|
let a = r.sql, o = [];
|
|
1419
|
-
for (let n of Object.keys(t.fields)) o.push(a`${
|
|
1420
|
-
if (i !== void 0) for (let e of i.projection.present) o.push(a`${
|
|
1236
|
+
for (let n of Object.keys(t.fields)) o.push(a`${z(e, n, a)} AS ${a(n)}`);
|
|
1237
|
+
if (i !== void 0) for (let e of i.projection.present) o.push(a`${z(i.source.alias, i.source.physical(e), a)} AS ${Ua(`_junction.${e}`, a)}`);
|
|
1421
1238
|
for (let t of n) {
|
|
1422
|
-
let n =
|
|
1239
|
+
let n = Wa(t, e, r);
|
|
1423
1240
|
if (n === null) return null;
|
|
1424
1241
|
o.push(n);
|
|
1425
1242
|
}
|
|
1426
1243
|
return a.csv(o);
|
|
1427
|
-
},
|
|
1244
|
+
}, Ua = (e, t) => t.unsafe(`[${e.replace(/]/g, "]]")}]`), Wa = (e, t, n) => {
|
|
1428
1245
|
switch (e.relation.kind) {
|
|
1429
|
-
case "one": return
|
|
1430
|
-
case "many": return
|
|
1431
|
-
case "manyToMany": return
|
|
1246
|
+
case "one": return ta(e) ? qa(na(e), t, n) : Ga(e, t, n);
|
|
1247
|
+
case "many": return qa(e, t, n);
|
|
1248
|
+
case "manyToMany": return Ja(e, t, n);
|
|
1432
1249
|
}
|
|
1433
|
-
},
|
|
1434
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1250
|
+
}, Ga = (e, t, n) => {
|
|
1251
|
+
let r = n.sql, i = n.nextAlias(), a = Ha(i, e.target, e.children, n);
|
|
1435
1252
|
if (a === null) return null;
|
|
1436
|
-
let o = e.fkSide === "source" ? r`${
|
|
1253
|
+
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)}`;
|
|
1437
1254
|
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)}`;
|
|
1438
|
-
},
|
|
1255
|
+
}, Ka = (e, t, n) => {
|
|
1439
1256
|
if (e.offset !== void 0) {
|
|
1440
|
-
let r = e.orderBy && e.orderBy.length > 0 ? t : n` ORDER BY (SELECT NULL)`, i = e.limit === void 0 ? n`${r} OFFSET ${
|
|
1257
|
+
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`;
|
|
1441
1258
|
return {
|
|
1442
1259
|
top: n``,
|
|
1443
1260
|
pagination: i,
|
|
@@ -1445,33 +1262,33 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
1445
1262
|
};
|
|
1446
1263
|
}
|
|
1447
1264
|
return {
|
|
1448
|
-
top: e.limit === void 0 ? n`` : n`TOP ${
|
|
1265
|
+
top: e.limit === void 0 ? n`` : n`TOP ${V(e.limit, n)} `,
|
|
1449
1266
|
pagination: n``,
|
|
1450
1267
|
finalOrder: t
|
|
1451
1268
|
};
|
|
1452
|
-
},
|
|
1453
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1269
|
+
}, qa = (e, t, n) => {
|
|
1270
|
+
let r = n.sql, i = n.nextAlias(), a = Ha(i, e.target, e.children, n);
|
|
1454
1271
|
if (a === null) return null;
|
|
1455
|
-
let o = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1456
|
-
return r`ISNULL(JSON_QUERY((SELECT ${c}${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${
|
|
1457
|
-
},
|
|
1458
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
1272
|
+
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 } = Ka(e.branch, s, r);
|
|
1273
|
+
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)}`;
|
|
1274
|
+
}, Ja = (e, t, n) => {
|
|
1275
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = Ha(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
1459
1276
|
projection: e.junction,
|
|
1460
|
-
source:
|
|
1277
|
+
source: ka(s)
|
|
1461
1278
|
});
|
|
1462
1279
|
if (c === null) return null;
|
|
1463
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1464
|
-
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 ${
|
|
1465
|
-
},
|
|
1280
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${H(e.branch.where, o, r)}`, u = U(e, s, r), d = L(o, e.branch.orderBy, r), { top: f, pagination: p, finalOrder: m } = Ka(e.branch, d, r);
|
|
1281
|
+
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)}`;
|
|
1282
|
+
}, 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) => {
|
|
1466
1283
|
if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw Error(`literalInt: expected non-negative integer, got ${e}`);
|
|
1467
1284
|
return t.unsafe(String(e));
|
|
1468
|
-
},
|
|
1285
|
+
}, H = (e, t, n) => F(Ya(e, t), n), U = (e, t, n, r = !1) => {
|
|
1469
1286
|
let i = e.branch.onJunction;
|
|
1470
|
-
return i === void 0 ? n`` : n` AND ${
|
|
1471
|
-
},
|
|
1472
|
-
if ("not" in e) return { not:
|
|
1473
|
-
if ("and" in e) return { and: e.and.map((e) =>
|
|
1474
|
-
if ("or" in e) return { or: e.or.map((e) =>
|
|
1287
|
+
return i === void 0 ? n`` : n` AND ${H(r ? W(i) : i, t, n)}`;
|
|
1288
|
+
}, Ya = (e, t) => {
|
|
1289
|
+
if ("not" in e) return { not: Ya(e.not, t) };
|
|
1290
|
+
if ("and" in e) return { and: e.and.map((e) => Ya(e, t)) };
|
|
1291
|
+
if ("or" in e) return { or: e.or.map((e) => Ya(e, t)) };
|
|
1475
1292
|
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
1476
1293
|
let n = e;
|
|
1477
1294
|
return {
|
|
@@ -1493,47 +1310,47 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
1493
1310
|
let t = e;
|
|
1494
1311
|
return {
|
|
1495
1312
|
...t,
|
|
1496
|
-
value:
|
|
1313
|
+
value: Xa(t.value)
|
|
1497
1314
|
};
|
|
1498
|
-
},
|
|
1499
|
-
e.actors !== void 0 && (
|
|
1500
|
-
},
|
|
1315
|
+
}, Xa = (e) => e == null ? e : e instanceof Date ? e.toISOString() : typeof e == "boolean" ? +!!e : Array.isArray(e) ? e.map((e) => Xa(e)) : e, Za = Symbol.for("@voltro/database/coreTablesRegistry"), Qa = globalThis, $a = Qa[Za] ?? (Qa[Za] = {}), eo = (e) => {
|
|
1316
|
+
e.actors !== void 0 && ($a.actors = e.actors), e.tenants !== void 0 && ($a.tenants = e.tenants);
|
|
1317
|
+
}, to = (e, t) => () => {
|
|
1501
1318
|
let n = e();
|
|
1502
1319
|
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`);
|
|
1503
1320
|
return n();
|
|
1504
|
-
},
|
|
1505
|
-
id:
|
|
1506
|
-
kind:
|
|
1321
|
+
}, no = () => to(() => $a.actors, "actors"), ro = () => to(() => $a.tenants, "tenants"), io = w("actors", {
|
|
1322
|
+
id: S(),
|
|
1323
|
+
kind: T().oneOf([
|
|
1507
1324
|
"user",
|
|
1508
1325
|
"serviceAccount",
|
|
1509
1326
|
"apiKey",
|
|
1510
1327
|
"system"
|
|
1511
1328
|
]).safe(),
|
|
1512
|
-
displayName:
|
|
1513
|
-
createdAt:
|
|
1514
|
-
}),
|
|
1329
|
+
displayName: T().nullable().sensitive("fullName"),
|
|
1330
|
+
createdAt: E().default("now")
|
|
1331
|
+
}), ao = (e, t) => ({
|
|
1515
1332
|
...t,
|
|
1516
1333
|
...e,
|
|
1517
1334
|
origin: e.origin ?? "injected"
|
|
1518
|
-
}),
|
|
1335
|
+
}), oo = (e, t, n = {}) => ({
|
|
1519
1336
|
table: e,
|
|
1520
1337
|
op: "insert",
|
|
1521
1338
|
old: null,
|
|
1522
1339
|
new: t,
|
|
1523
1340
|
...n
|
|
1524
|
-
}),
|
|
1341
|
+
}), so = (e, t, n, r = {}) => ({
|
|
1525
1342
|
table: e,
|
|
1526
1343
|
op: "update",
|
|
1527
1344
|
old: t,
|
|
1528
1345
|
new: n,
|
|
1529
1346
|
...r
|
|
1530
|
-
}),
|
|
1347
|
+
}), co = (e, t, n = {}) => ({
|
|
1531
1348
|
table: e,
|
|
1532
1349
|
op: "delete",
|
|
1533
1350
|
old: t,
|
|
1534
1351
|
new: null,
|
|
1535
1352
|
...n
|
|
1536
|
-
}),
|
|
1353
|
+
}), lo = (e, t, n = {}) => {
|
|
1537
1354
|
let { at: r = "2026-01-01T00:00:00.000Z", column: i = "deletedAt", ...a } = n;
|
|
1538
1355
|
return {
|
|
1539
1356
|
table: e,
|
|
@@ -1548,13 +1365,13 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
1548
1365
|
},
|
|
1549
1366
|
...a
|
|
1550
1367
|
};
|
|
1551
|
-
},
|
|
1368
|
+
}, uo = (e) => e == null ? "null" : e instanceof Date ? JSON.stringify(e.toISOString()) : typeof e == "bigint" ? JSON.stringify(e.toString()) : Array.isArray(e) ? `[${e.map(uo).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)}:${uo(t)}`).join(",")}}` : JSON.stringify(e) ?? "null", fo = (e) => $n("sha256").update([
|
|
1552
1369
|
e.pipe,
|
|
1553
1370
|
e.op,
|
|
1554
1371
|
e.key,
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
].join("\0")).digest("hex").slice(0, 32),
|
|
1372
|
+
uo(e.next),
|
|
1373
|
+
uo(e.prev)
|
|
1374
|
+
].join("\0")).digest("hex").slice(0, 32), po = (e, t) => `${e}:${t}`, mo = (e) => {
|
|
1558
1375
|
let t = e.lastIndexOf(":");
|
|
1559
1376
|
if (t <= 0) return null;
|
|
1560
1377
|
let n = Number(e.slice(t + 1));
|
|
@@ -1562,7 +1379,7 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
1562
1379
|
digest: e.slice(0, t),
|
|
1563
1380
|
occurrence: n
|
|
1564
1381
|
};
|
|
1565
|
-
},
|
|
1382
|
+
}, ho = class {
|
|
1566
1383
|
#e = /* @__PURE__ */ new Map();
|
|
1567
1384
|
#t;
|
|
1568
1385
|
#n;
|
|
@@ -1584,7 +1401,7 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
1584
1401
|
}
|
|
1585
1402
|
seedFromChangeKeys(e, t) {
|
|
1586
1403
|
for (let n of e) {
|
|
1587
|
-
let e =
|
|
1404
|
+
let e = mo(n);
|
|
1588
1405
|
if (e === null) continue;
|
|
1589
1406
|
let r = this.#e.get(e.digest), i = Math.max(r?.count ?? 0, e.occurrence + 1);
|
|
1590
1407
|
this.#e.set(e.digest, {
|
|
@@ -1605,29 +1422,29 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
1605
1422
|
this.#e.delete(e.value);
|
|
1606
1423
|
}
|
|
1607
1424
|
}
|
|
1608
|
-
},
|
|
1609
|
-
let t = Number(e[
|
|
1425
|
+
}, go = "VOLTRO_CHANGE_CLAIMS_TTL_HOURS", _o = 1, vo = (e = process.env) => {
|
|
1426
|
+
let t = Number(e[go]);
|
|
1610
1427
|
return (Number.isFinite(t) && t > 0 ? t : 1) * 2 * 36e5;
|
|
1611
|
-
},
|
|
1612
|
-
let t = e ??
|
|
1428
|
+
}, yo = new er(), bo = (e, t) => yo.run(e, t), xo = () => yo.getStore(), So = (e) => {
|
|
1429
|
+
let t = e ?? yo.getStore();
|
|
1613
1430
|
return t === void 0 ? {} : {
|
|
1614
1431
|
...t.traceId === void 0 ? {} : { traceId: t.traceId },
|
|
1615
1432
|
...t.subjectId === void 0 ? {} : { subjectId: t.subjectId },
|
|
1616
1433
|
...t.procedure === void 0 ? {} : { procedure: t.procedure },
|
|
1617
1434
|
...t.via === void 0 ? {} : { via: t.via }
|
|
1618
1435
|
};
|
|
1619
|
-
},
|
|
1620
|
-
let t =
|
|
1621
|
-
return t === void 0 ? e(void 0) :
|
|
1622
|
-
},
|
|
1436
|
+
}, Co = (e) => {
|
|
1437
|
+
let t = yo.getStore();
|
|
1438
|
+
return t === void 0 ? e(void 0) : yo.run(t, () => e(t));
|
|
1439
|
+
}, wo = 3e4, To = 1e4, G = /* @__PURE__ */ new Map(), K = 0, Eo = (e, t, n) => `${e}\u0000${t}\u0000${String(n)}`, Do = (e) => {
|
|
1623
1440
|
for (let [t, n] of G) {
|
|
1624
|
-
let r = n.filter((t) => e - t.at <
|
|
1441
|
+
let r = n.filter((t) => e - t.at < wo);
|
|
1625
1442
|
K -= n.length - r.length, r.length === 0 ? G.delete(t) : r.length !== n.length && G.set(t, r);
|
|
1626
1443
|
}
|
|
1627
|
-
},
|
|
1444
|
+
}, Oo = (e, t) => {
|
|
1628
1445
|
if (t.traceId === void 0 && t.subjectId === void 0 && t.procedure === void 0) return;
|
|
1629
1446
|
let n = Date.now();
|
|
1630
|
-
if (K >=
|
|
1447
|
+
if (K >= To && Do(n), K >= To) return;
|
|
1631
1448
|
let r = G.get(e);
|
|
1632
1449
|
r === void 0 ? G.set(e, [{
|
|
1633
1450
|
attribution: t,
|
|
@@ -1636,38 +1453,38 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
1636
1453
|
attribution: t,
|
|
1637
1454
|
at: n
|
|
1638
1455
|
}), K += 1;
|
|
1639
|
-
},
|
|
1456
|
+
}, ko = (e) => {
|
|
1640
1457
|
let t = G.get(e);
|
|
1641
1458
|
if (t === void 0 || t.length === 0) return;
|
|
1642
1459
|
let n = t.shift();
|
|
1643
|
-
if (--K, t.length === 0 && G.delete(e), !(Date.now() - n.at >=
|
|
1644
|
-
},
|
|
1645
|
-
let t =
|
|
1460
|
+
if (--K, t.length === 0 && G.delete(e), !(Date.now() - n.at >= wo)) return n.attribution;
|
|
1461
|
+
}, Ao = (e) => (G.get(e)?.length ?? 0) > 0, q = /* @__PURE__ */ new Map(), jo = /* @__PURE__ */ new Map(), Mo = /* @__PURE__ */ new Map(), No = 250, Po = (e) => {
|
|
1462
|
+
let t = jo.get(e);
|
|
1646
1463
|
if (t === void 0) return;
|
|
1647
|
-
|
|
1648
|
-
let n =
|
|
1649
|
-
n !== void 0 && (clearTimeout(n),
|
|
1464
|
+
jo.delete(e);
|
|
1465
|
+
let n = Mo.get(e);
|
|
1466
|
+
n !== void 0 && (clearTimeout(n), Mo.delete(e));
|
|
1650
1467
|
for (let e of t) e();
|
|
1651
|
-
},
|
|
1468
|
+
}, Fo = (e) => {
|
|
1652
1469
|
q.set(e, (q.get(e) ?? 0) + 1);
|
|
1653
|
-
},
|
|
1470
|
+
}, Io = (e) => {
|
|
1654
1471
|
let t = (q.get(e) ?? 0) - 1;
|
|
1655
1472
|
if (t > 0) {
|
|
1656
1473
|
q.set(e, t);
|
|
1657
1474
|
return;
|
|
1658
1475
|
}
|
|
1659
|
-
q.delete(e),
|
|
1660
|
-
},
|
|
1661
|
-
let i = n == null ? void 0 :
|
|
1476
|
+
q.delete(e), Po(e);
|
|
1477
|
+
}, Lo = (e, t, n, r) => {
|
|
1478
|
+
let i = n == null ? void 0 : Eo(e, t, n), a = () => r(i === void 0 ? void 0 : ko(i));
|
|
1662
1479
|
if (i === void 0) {
|
|
1663
1480
|
a();
|
|
1664
1481
|
return;
|
|
1665
1482
|
}
|
|
1666
|
-
if (
|
|
1483
|
+
if (Ao(i)) {
|
|
1667
1484
|
a();
|
|
1668
1485
|
return;
|
|
1669
1486
|
}
|
|
1670
|
-
let o =
|
|
1487
|
+
let o = jo.get(e);
|
|
1671
1488
|
if (o === void 0 && (q.get(e) ?? 0) === 0) {
|
|
1672
1489
|
a();
|
|
1673
1490
|
return;
|
|
@@ -1676,91 +1493,91 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
1676
1493
|
o.push(a);
|
|
1677
1494
|
return;
|
|
1678
1495
|
}
|
|
1679
|
-
|
|
1680
|
-
let s = setTimeout(() =>
|
|
1681
|
-
typeof s == "object" && typeof s.unref == "function" && s.unref(),
|
|
1682
|
-
},
|
|
1496
|
+
jo.set(e, [a]);
|
|
1497
|
+
let s = setTimeout(() => Po(e), No);
|
|
1498
|
+
typeof s == "object" && typeof s.unref == "function" && s.unref(), Mo.set(e, s);
|
|
1499
|
+
}, Ro = () => {
|
|
1683
1500
|
G.clear(), K = 0, q.clear();
|
|
1684
|
-
for (let e of
|
|
1685
|
-
|
|
1686
|
-
},
|
|
1501
|
+
for (let e of Mo.values()) clearTimeout(e);
|
|
1502
|
+
Mo.clear(), jo.clear();
|
|
1503
|
+
}, zo = () => K, Bo = 64, Vo = "\0", Ho = 32, Uo = (e, ...t) => `${e}_${$n("sha256").update(t.map(String).join(Vo)).digest("hex").slice(0, Ho)}`, Wo = (e) => e.length + 1 + Ho, J = /* @__PURE__ */ new Map(), Go = (e, t) => {
|
|
1687
1504
|
J.set(e, {
|
|
1688
1505
|
recorder: t.recorder,
|
|
1689
1506
|
tables: new Set(t.tables),
|
|
1690
1507
|
ownTables: new Set(t.ownTables)
|
|
1691
1508
|
});
|
|
1692
|
-
},
|
|
1509
|
+
}, Ko = (e) => {
|
|
1693
1510
|
J.delete(e);
|
|
1694
|
-
},
|
|
1695
|
-
let t =
|
|
1696
|
-
if (t !== void 0) return t.n += 1,
|
|
1511
|
+
}, qo = () => J.clear(), Jo = new er(), Yo = (e) => Jo.run({ n: 1 }, e), Xo = (e) => D.suspend(() => {
|
|
1512
|
+
let t = Jo.getStore();
|
|
1513
|
+
if (t !== void 0) return t.n += 1, D.ensuring(e, D.sync(() => {
|
|
1697
1514
|
--t.n;
|
|
1698
1515
|
}));
|
|
1699
1516
|
let n = { n: 1 };
|
|
1700
|
-
return
|
|
1517
|
+
return Jo.enterWith(n), D.ensuring(e, D.sync(() => {
|
|
1701
1518
|
--n.n;
|
|
1702
1519
|
}));
|
|
1703
|
-
}),
|
|
1704
|
-
if (J.size === 0 || (
|
|
1520
|
+
}), Zo = () => (Jo.getStore()?.n ?? 0) > 0, Qo = (e) => {
|
|
1521
|
+
if (J.size === 0 || (Jo.getStore()?.n ?? 0) > 0) return !1;
|
|
1705
1522
|
for (let t of J.values()) if (!t.ownTables.has(e) && t.tables.has(e)) return !0;
|
|
1706
1523
|
return !1;
|
|
1707
|
-
},
|
|
1524
|
+
}, $o = async (e, t) => {
|
|
1708
1525
|
if (J.size !== 0) {
|
|
1709
1526
|
for (let [n, r] of J.entries()) if (!r.ownTables.has(t.table) && r.tables.has(t.table)) try {
|
|
1710
1527
|
await r.recorder(e, t);
|
|
1711
1528
|
} catch (e) {
|
|
1712
|
-
let r =
|
|
1529
|
+
let r = u(e);
|
|
1713
1530
|
throw r === void 0 ? e : Error(`write recorder '${n}' failed while recording a ${t.op} on '${t.table}': ${r}`, { cause: e });
|
|
1714
1531
|
}
|
|
1715
1532
|
}
|
|
1716
|
-
},
|
|
1533
|
+
}, es = Xn.exponential({
|
|
1717
1534
|
start: 5e-4,
|
|
1718
1535
|
factor: 2,
|
|
1719
1536
|
count: 16
|
|
1720
|
-
}),
|
|
1721
|
-
let n = `${e}\u0000${t}`, r =
|
|
1537
|
+
}), ts = O.counter("voltro_db_queries_total", { description: "Database operations executed, by dialect and operation kind." }), ns = O.histogram("voltro_db_query_duration_seconds", es, "Database operation duration in seconds, by dialect and operation kind."), rs = O.counter("voltro_db_errors_total", { description: "Database operations that threw, by dialect and operation kind." }), is = 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." }), as = 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." }), os = [], ss = /* @__PURE__ */ new Map(), cs = /* @__PURE__ */ new Map(), ls = /* @__PURE__ */ new Map(), us = (e, t) => {
|
|
1538
|
+
let n = `${e}\u0000${t}`, r = ss.get(n);
|
|
1722
1539
|
if (r !== void 0) return r;
|
|
1723
|
-
let i = (n) =>
|
|
1724
|
-
count: i(
|
|
1725
|
-
duration: i(
|
|
1726
|
-
errors: i(
|
|
1540
|
+
let i = (n) => O.tagged(O.tagged(n, "dialect", e), "op", t), a = {
|
|
1541
|
+
count: i(ts),
|
|
1542
|
+
duration: i(ns),
|
|
1543
|
+
errors: i(rs)
|
|
1727
1544
|
};
|
|
1728
|
-
return
|
|
1729
|
-
},
|
|
1730
|
-
|
|
1731
|
-
},
|
|
1732
|
-
let n = Math.max(0, (
|
|
1733
|
-
n === 0 ?
|
|
1734
|
-
let r =
|
|
1735
|
-
r === void 0 && (r =
|
|
1736
|
-
},
|
|
1737
|
-
let t =
|
|
1738
|
-
t.count.unsafeUpdate(1,
|
|
1739
|
-
},
|
|
1545
|
+
return ss.set(n, a), a;
|
|
1546
|
+
}, ds = () => {
|
|
1547
|
+
ss.clear(), cs.clear(), ls.clear();
|
|
1548
|
+
}, fs = () => ss.size + cs.size + ls.size, ps = /* @__PURE__ */ new Map(), ms = (e, t) => {
|
|
1549
|
+
let n = Math.max(0, (ps.get(e) ?? 0) + t);
|
|
1550
|
+
n === 0 ? ps.delete(e) : ps.set(e, n);
|
|
1551
|
+
let r = cs.get(e);
|
|
1552
|
+
r === void 0 && (r = O.tagged(is, "dialect", e), cs.set(e, r)), r.unsafeUpdate(n, os);
|
|
1553
|
+
}, hs = (e) => ps.get(e) ?? 0, gs = (e) => {
|
|
1554
|
+
let t = us(String(e.dialect), e.op);
|
|
1555
|
+
t.count.unsafeUpdate(1, os), t.duration.unsafeUpdate(e.durationMs / 1e3, os), e.status === "error" && t.errors.unsafeUpdate(1, os);
|
|
1556
|
+
}, _s = async (e, t, n) => {
|
|
1740
1557
|
let r = performance.now(), i = String(e);
|
|
1741
|
-
|
|
1558
|
+
ms(i, 1);
|
|
1742
1559
|
let a = "ok";
|
|
1743
1560
|
try {
|
|
1744
1561
|
return await n();
|
|
1745
1562
|
} catch (e) {
|
|
1746
1563
|
throw a = "error", e;
|
|
1747
1564
|
} finally {
|
|
1748
|
-
|
|
1565
|
+
ms(i, -1), gs({
|
|
1749
1566
|
dialect: e,
|
|
1750
1567
|
op: t,
|
|
1751
1568
|
durationMs: performance.now() - r,
|
|
1752
1569
|
status: a
|
|
1753
1570
|
});
|
|
1754
1571
|
}
|
|
1755
|
-
},
|
|
1572
|
+
}, vs = 3e5, ys = (e) => {
|
|
1756
1573
|
if (e == null || e === "") return;
|
|
1757
1574
|
let t = Number(e);
|
|
1758
1575
|
return Number.isFinite(t) && t >= 0 ? Math.floor(t) : void 0;
|
|
1759
|
-
},
|
|
1760
|
-
let n =
|
|
1576
|
+
}, bs = (e, t = process.env) => ys(t.VOLTRO_DB_EAGER_FALLBACK_WARN_INTERVAL_MS) ?? ys(e) ?? 3e5, xs = (e, t = {}) => {
|
|
1577
|
+
let n = bs(t.warnIntervalMs), r = t.now ?? (() => Date.now()), i = /* @__PURE__ */ new Map();
|
|
1761
1578
|
return (t) => {
|
|
1762
|
-
let a = `${t.dialect} ${t.reason}`, o =
|
|
1763
|
-
o === void 0 && (o =
|
|
1579
|
+
let a = `${t.dialect} ${t.reason}`, o = ls.get(a);
|
|
1580
|
+
o === void 0 && (o = O.tagged(O.tagged(as, "dialect", String(t.dialect)), "reason", t.reason), ls.set(a, o)), o.unsafeUpdate(1, os);
|
|
1764
1581
|
let s = `${t.table}\u0000${t.reason}`, c = i.get(s), l = c === void 0 || n > 0 && r() - c >= n, u = {
|
|
1765
1582
|
table: t.table,
|
|
1766
1583
|
dialect: String(t.dialect),
|
|
@@ -1774,78 +1591,130 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
1774
1591
|
}
|
|
1775
1592
|
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);
|
|
1776
1593
|
};
|
|
1777
|
-
},
|
|
1778
|
-
if (
|
|
1779
|
-
throw
|
|
1780
|
-
},
|
|
1781
|
-
let t = 0, n =
|
|
1594
|
+
}, Ss = (e) => {
|
|
1595
|
+
if (Yn.isSuccess(e)) return e.value;
|
|
1596
|
+
throw Kn.squash(e.cause);
|
|
1597
|
+
}, Cs = "10 millis", ws = 3, Ts = (e) => Zn.exponential(Cs).pipe(Zn.compose(Zn.recurs(ws)), Zn.whileInput(e)), Es = async (e) => {
|
|
1598
|
+
let t = 0, n = D.suspend(() => {
|
|
1782
1599
|
let n = ++t;
|
|
1783
|
-
return e.withTransaction(
|
|
1784
|
-
if (
|
|
1785
|
-
let r = t.value, i =
|
|
1600
|
+
return e.withTransaction(D.flatMap(D.serviceOption(tr), (t) => {
|
|
1601
|
+
if (k.isNone(t)) return D.fail(/* @__PURE__ */ Error(`${e.label}: TransactionConnection unexpectedly missing inside withTransaction.`));
|
|
1602
|
+
let r = t.value, i = D.tryPromise({
|
|
1786
1603
|
try: () => e.body(r, n),
|
|
1787
1604
|
catch: (e) => e
|
|
1788
1605
|
});
|
|
1789
|
-
return e.prepare === void 0 ? i :
|
|
1790
|
-
})).pipe(
|
|
1791
|
-
}).pipe(
|
|
1792
|
-
return
|
|
1793
|
-
},
|
|
1794
|
-
|
|
1606
|
+
return e.prepare === void 0 ? i : D.flatMap(e.prepare(r), () => i);
|
|
1607
|
+
})).pipe(D.catchAllDefect((t) => e.isRetryable(t) ? D.fail(t) : D.die(t)));
|
|
1608
|
+
}).pipe(D.retry(Ts(e.isRetryable)), D.withSpan(e.span.name, { attributes: { ...e.span.attributes } }));
|
|
1609
|
+
return _s(e.dialect, "transaction", async () => Ss(await e.runPromiseExit(e.wrapProgram === void 0 ? n : e.wrapProgram(n))));
|
|
1610
|
+
}, Ds = class extends Error {
|
|
1611
|
+
swallowed;
|
|
1612
|
+
_tag = "TransactionAborted";
|
|
1613
|
+
constructor(e, t) {
|
|
1614
|
+
super(`${e}: a statement failed inside this transaction and the error was caught, but the database had already aborted the transaction — every later statement was refused, and COMMIT would have rolled back ALL of its writes, including the ones that succeeded. Nothing was committed.
|
|
1615
|
+
the caught failure: ${js(t)}\n to tolerate a failing statement and keep the rest, run it inside \`tx.savepoint(() => …)\` — only that statement is rolled back. To keep all-or-nothing, let the error propagate.`, { cause: t }), this.swallowed = t, this.name = "TransactionAbortedError";
|
|
1616
|
+
}
|
|
1617
|
+
}, Os = (e, t = "transactional()") => {
|
|
1618
|
+
let n = 0, r, i = (e) => {
|
|
1619
|
+
r === void 0 && (r = { error: e });
|
|
1620
|
+
};
|
|
1621
|
+
return {
|
|
1622
|
+
track: (a) => r === void 0 ? n > 0 ? a() : a().catch((t) => {
|
|
1623
|
+
throw e(t) && i(t), t;
|
|
1624
|
+
}) : Promise.reject(new Ds(t, r.error)),
|
|
1625
|
+
inSavepoint: async (e) => {
|
|
1626
|
+
n++;
|
|
1627
|
+
try {
|
|
1628
|
+
return await e();
|
|
1629
|
+
} finally {
|
|
1630
|
+
n--;
|
|
1631
|
+
}
|
|
1632
|
+
},
|
|
1633
|
+
record: i,
|
|
1634
|
+
abortedBy: () => r
|
|
1635
|
+
};
|
|
1636
|
+
}, ks = async (e, t) => {
|
|
1637
|
+
let { tracker: n, name: r, exec: i, spelling: a } = e;
|
|
1638
|
+
await n.track(() => i(a === "mssql" ? `SAVE TRANSACTION ${r}` : `SAVEPOINT ${r}`));
|
|
1639
|
+
try {
|
|
1640
|
+
let e = await n.inSavepoint(t);
|
|
1641
|
+
return a === "standard" && await n.track(() => i(`RELEASE SAVEPOINT ${r}`)), e;
|
|
1642
|
+
} catch (e) {
|
|
1643
|
+
throw await i(a === "mssql" ? `ROLLBACK TRANSACTION ${r}` : `ROLLBACK TO SAVEPOINT ${r}`).catch((e) => n.record(e)), a === "standard" && await i(`RELEASE SAVEPOINT ${r}`).catch(() => void 0), e;
|
|
1644
|
+
}
|
|
1645
|
+
}, As = (e) => e instanceof Ds || typeof e == "object" && !!e && e._tag === "TransactionAborted", js = (e) => {
|
|
1646
|
+
for (let t of jn(e)) {
|
|
1647
|
+
let e = t;
|
|
1648
|
+
for (let t = 0; t < 5 && typeof e == "object" && e; t++) {
|
|
1649
|
+
let t = e.code, n = e.message;
|
|
1650
|
+
if (typeof t == "string" && typeof n == "string") return `${n} (${t})`;
|
|
1651
|
+
e = e.cause;
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
return e instanceof Error ? e.message : String(e);
|
|
1655
|
+
}, Ms = async (e) => {
|
|
1656
|
+
let t = xo(), n = t === void 0 ? (e) => e() : (e) => bo(t, e), r = await Es({
|
|
1795
1657
|
...e,
|
|
1796
1658
|
body: (r) => {
|
|
1797
1659
|
let i = e.makeView(r, t);
|
|
1798
|
-
return n(() => e.work(i)).then((
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1660
|
+
return n(() => e.work(i)).then((t) => {
|
|
1661
|
+
let n = i.abortedBy?.();
|
|
1662
|
+
if (n !== void 0) throw e.isRetryable(n.error) ? n.error : new Ds(e.label, n.error);
|
|
1663
|
+
return {
|
|
1664
|
+
result: t,
|
|
1665
|
+
view: i
|
|
1666
|
+
};
|
|
1667
|
+
}, (t) => {
|
|
1668
|
+
let n = i.abortedBy?.();
|
|
1669
|
+
throw n !== void 0 && e.isRetryable(n.error) ? n.error : t;
|
|
1670
|
+
});
|
|
1802
1671
|
}
|
|
1803
1672
|
});
|
|
1804
1673
|
return r.view.commitEvents(), r.result;
|
|
1805
|
-
},
|
|
1674
|
+
}, Ns = /* @__PURE__ */ new Set([
|
|
1806
1675
|
"1213",
|
|
1807
1676
|
"ER_LOCK_DEADLOCK",
|
|
1808
1677
|
"1205",
|
|
1809
1678
|
"ER_LOCK_WAIT_TIMEOUT",
|
|
1810
1679
|
"1020",
|
|
1811
1680
|
"ER_CHECKREAD"
|
|
1812
|
-
]),
|
|
1681
|
+
]), Ps = /* @__PURE__ */ new Set(["40001", "40P01"]), Fs = /* @__PURE__ */ new Set(["1205"]), Is = /* @__PURE__ */ new Set([
|
|
1813
1682
|
"SQLITE_BUSY",
|
|
1814
1683
|
"5",
|
|
1815
1684
|
"SQLITE_LOCKED",
|
|
1816
1685
|
"6"
|
|
1817
|
-
]),
|
|
1686
|
+
]), Ls = /write-write conflict|write-read conflict|database is locked|table is locked|database is busy/i, Rs = /* @__PURE__ */ new Set([
|
|
1818
1687
|
1213,
|
|
1819
1688
|
1205,
|
|
1820
1689
|
1020
|
|
1821
|
-
]),
|
|
1822
|
-
...
|
|
1823
|
-
...
|
|
1824
|
-
...
|
|
1825
|
-
...
|
|
1826
|
-
]),
|
|
1690
|
+
]), zs = /* @__PURE__ */ new Set([
|
|
1691
|
+
...Ns,
|
|
1692
|
+
...Ps,
|
|
1693
|
+
...Fs,
|
|
1694
|
+
...Is
|
|
1695
|
+
]), Bs = (e) => jn(e).some(Vs), Vs = (e) => {
|
|
1827
1696
|
let t = e;
|
|
1828
1697
|
for (let e = 0; e < 6 && typeof t == "object" && t; e++) {
|
|
1829
1698
|
let e = t;
|
|
1830
|
-
if (typeof e.errno == "number" &&
|
|
1699
|
+
if (typeof e.errno == "number" && Rs.has(e.errno) || typeof e.number == "number" && Fs.has(String(e.number)) || typeof e.code == "string" && zs.has(e.code) || typeof e.sqlState == "string" && Ps.has(e.sqlState) || typeof e.message == "string" && Ls.test(e.message)) return !0;
|
|
1831
1700
|
t = e.cause;
|
|
1832
1701
|
}
|
|
1833
1702
|
return !1;
|
|
1834
|
-
},
|
|
1835
|
-
id:
|
|
1836
|
-
fields: { expiresAt:
|
|
1703
|
+
}, Hs = "voltro/expires", Us = () => $t({
|
|
1704
|
+
id: Hs,
|
|
1705
|
+
fields: { expiresAt: E().nullable() },
|
|
1837
1706
|
behaviors: { defaultWhere: () => "expiresAt IS NULL OR expiresAt > now()" }
|
|
1838
|
-
}),
|
|
1839
|
-
id:
|
|
1707
|
+
}), Ws = "voltro/localFirst", Gs = () => $t({
|
|
1708
|
+
id: Ws,
|
|
1840
1709
|
fields: {}
|
|
1841
|
-
}),
|
|
1710
|
+
}), Ks = (e) => e.appliedMixins.some((e) => e.id === Ws), qs = (e) => {
|
|
1842
1711
|
let t = [];
|
|
1843
|
-
for (let n of Object.values(e))
|
|
1712
|
+
for (let n of Object.values(e)) Ks(n) && t.push(n.tableName);
|
|
1844
1713
|
return t;
|
|
1845
|
-
},
|
|
1846
|
-
let i =
|
|
1714
|
+
}, Js = class extends Jn.TaggedError("TableStreamError") {}, Ys = 1e3, Xs = (e, t, n, r) => {
|
|
1715
|
+
let i = k.match(r, {
|
|
1847
1716
|
onNone: () => e.where,
|
|
1848
|
-
onSome: (n) => e.where ?
|
|
1717
|
+
onSome: (n) => e.where ? he(e.where, fe(t, n)) : fe(t, n)
|
|
1849
1718
|
});
|
|
1850
1719
|
return {
|
|
1851
1720
|
table: e.table,
|
|
@@ -1860,19 +1729,19 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
1860
1729
|
...e.includeDeleted === void 0 ? {} : { includeDeleted: e.includeDeleted },
|
|
1861
1730
|
...e.crossTenant === void 0 ? {} : { crossTenant: e.crossTenant }
|
|
1862
1731
|
};
|
|
1863
|
-
},
|
|
1864
|
-
let n = t.pk ?? "id", r = t.chunkSize ??
|
|
1865
|
-
return
|
|
1866
|
-
let a =
|
|
1867
|
-
try: () => e.query(
|
|
1868
|
-
catch: (e) => new
|
|
1732
|
+
}, Zs = (e, t) => {
|
|
1733
|
+
let n = t.pk ?? "id", r = t.chunkSize ?? Ys;
|
|
1734
|
+
return Qn.paginateChunkEffect(k.none(), (i) => {
|
|
1735
|
+
let a = D.tryPromise({
|
|
1736
|
+
try: () => e.query(Xs(t, n, r, i)),
|
|
1737
|
+
catch: (e) => new Js({
|
|
1869
1738
|
table: t.table,
|
|
1870
1739
|
cause: e
|
|
1871
1740
|
})
|
|
1872
1741
|
});
|
|
1873
|
-
return (t.retry ? a.pipe(
|
|
1742
|
+
return (t.retry ? a.pipe(D.retry(t.retry)) : a).pipe(D.map((e) => [qn.fromIterable(e), e.length === r && e.length > 0 ? k.some(k.some(e[e.length - 1][n])) : k.none()]));
|
|
1874
1743
|
});
|
|
1875
|
-
},
|
|
1744
|
+
}, Qs = (e) => {
|
|
1876
1745
|
let t = e.alpha ?? .5;
|
|
1877
1746
|
if (t < 0 || t > 1) throw Error(`hybridSearch: alpha must be in [0, 1], got ${t}`);
|
|
1878
1747
|
return (n) => {
|
|
@@ -1886,7 +1755,7 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
1886
1755
|
queryText: e.vector.query,
|
|
1887
1756
|
distance: e.vector.distance ?? "cosine",
|
|
1888
1757
|
alpha: t
|
|
1889
|
-
}, i =
|
|
1758
|
+
}, i = Pe(n.table, e.fts.indexName, n.fullTextIndexes);
|
|
1890
1759
|
return {
|
|
1891
1760
|
...n,
|
|
1892
1761
|
annClause: r,
|
|
@@ -1899,17 +1768,17 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
1899
1768
|
}
|
|
1900
1769
|
};
|
|
1901
1770
|
};
|
|
1902
|
-
},
|
|
1771
|
+
}, $s = async (e, t) => {
|
|
1903
1772
|
let n = e.as ?? "embedding", r = t.row[e.from];
|
|
1904
1773
|
if (typeof r != "string" || r.length === 0) return {};
|
|
1905
1774
|
let i = await t.embed(r);
|
|
1906
1775
|
return { [n]: i };
|
|
1907
|
-
},
|
|
1776
|
+
}, ec = (e) => {
|
|
1908
1777
|
if (!Number.isInteger(e.dimensions) || e.dimensions <= 0) throw Error(`vectorEmbedding: dimensions must be a positive integer, got ${String(e.dimensions)}.`);
|
|
1909
|
-
let t = e.as ?? "embedding", n = (t) =>
|
|
1910
|
-
return
|
|
1778
|
+
let t = e.as ?? "embedding", n = (t) => $s(e, t);
|
|
1779
|
+
return $t({
|
|
1911
1780
|
id: "voltro/vectorEmbedding",
|
|
1912
|
-
fields: { [t]:
|
|
1781
|
+
fields: { [t]: bt(e.dimensions) },
|
|
1913
1782
|
...e.index === !1 ? {} : { indexes: [{
|
|
1914
1783
|
fields: [t],
|
|
1915
1784
|
kind: "hnsw",
|
|
@@ -1924,19 +1793,19 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
1924
1793
|
beforeUpdate: n
|
|
1925
1794
|
}
|
|
1926
1795
|
});
|
|
1927
|
-
},
|
|
1796
|
+
}, tc = 63, nc = "br_pr", Y = class extends Error {
|
|
1928
1797
|
_tag = "BranchNameInvalid";
|
|
1929
1798
|
constructor(e) {
|
|
1930
1799
|
super(e), this.name = "BranchNameInvalid";
|
|
1931
1800
|
}
|
|
1932
|
-
},
|
|
1801
|
+
}, rc = (e, t) => {
|
|
1933
1802
|
if (!Number.isInteger(t) || t < 0) throw new Y(`prNumber must be a non-negative integer, got ${String(t)}`);
|
|
1934
1803
|
let n = Ii(e);
|
|
1935
1804
|
if (n.replace(/_/g, "") === "") throw new Y(`app slug '${e}' has no usable identifier characters`);
|
|
1936
|
-
let r = `${
|
|
1937
|
-
if (r.length >
|
|
1805
|
+
let r = `${nc}${t}_${n}`;
|
|
1806
|
+
if (r.length > tc) throw new Y(`branch namespace '${r}' exceeds the ${tc}-byte identifier limit — use a shorter app slug`);
|
|
1938
1807
|
return r;
|
|
1939
|
-
},
|
|
1808
|
+
}, ic = (e) => e.startsWith(nc), ac = {
|
|
1940
1809
|
requested: {
|
|
1941
1810
|
provision: "provisioning",
|
|
1942
1811
|
destroy: "destroying"
|
|
@@ -1955,18 +1824,18 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
1955
1824
|
fail: "failed"
|
|
1956
1825
|
},
|
|
1957
1826
|
destroyed: {}
|
|
1958
|
-
},
|
|
1827
|
+
}, oc = class extends Error {
|
|
1959
1828
|
from;
|
|
1960
1829
|
event;
|
|
1961
1830
|
_tag = "BranchTransitionInvalid";
|
|
1962
1831
|
constructor(e, t) {
|
|
1963
1832
|
super(`invalid branch transition: ${e} --${t}-->`), this.from = e, this.event = t, this.name = "BranchTransitionInvalid";
|
|
1964
1833
|
}
|
|
1965
|
-
},
|
|
1966
|
-
let n =
|
|
1967
|
-
if (n === void 0) throw new
|
|
1834
|
+
}, sc = (e, t) => {
|
|
1835
|
+
let n = ac[e][t];
|
|
1836
|
+
if (n === void 0) throw new oc(e, t);
|
|
1968
1837
|
return n;
|
|
1969
|
-
},
|
|
1838
|
+
}, cc = (e, t, n, r, i = [], a = []) => {
|
|
1970
1839
|
if (n === "copy" && (r === void 0 || r === "")) throw new Y("seed 'copy' requires a parentNamespace to snapshot from");
|
|
1971
1840
|
let o = [{
|
|
1972
1841
|
kind: "create-namespace",
|
|
@@ -1996,13 +1865,13 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
1996
1865
|
kind: "seed",
|
|
1997
1866
|
detail: `run boot seeds into ${e}`
|
|
1998
1867
|
}), o;
|
|
1999
|
-
},
|
|
2000
|
-
if (!
|
|
1868
|
+
}, lc = (e) => {
|
|
1869
|
+
if (!ic(e)) throw new Y(`refusing to plan teardown of '${e}' — not a branch namespace`);
|
|
2001
1870
|
return [{
|
|
2002
1871
|
kind: "drop-namespace",
|
|
2003
1872
|
detail: e
|
|
2004
1873
|
}];
|
|
2005
|
-
},
|
|
1874
|
+
}, uc = (e) => {
|
|
2006
1875
|
if (e === void 0 || e === "") return !1;
|
|
2007
1876
|
try {
|
|
2008
1877
|
let t = new URL(e).hostname.toLowerCase();
|
|
@@ -2010,27 +1879,27 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
2010
1879
|
} catch {
|
|
2011
1880
|
return /\bneon\.(tech|build)\b/i.test(e);
|
|
2012
1881
|
}
|
|
2013
|
-
},
|
|
1882
|
+
}, dc = (e) => e.prefer === void 0 ? e.seed === "copy" && uc(e.dbUrl) ? "neon-cow" : "namespace" : e.prefer, fc = (e, t = {}) => [{
|
|
2014
1883
|
kind: "neon-branch-create",
|
|
2015
1884
|
detail: `${t.parentBranch ?? "main"} → ${e} (copy-on-write)`
|
|
2016
|
-
}],
|
|
2017
|
-
if (!
|
|
1885
|
+
}], pc = (e) => {
|
|
1886
|
+
if (!ic(e)) throw new Y(`refusing to plan teardown of '${e}' — not a branch namespace`);
|
|
2018
1887
|
return [{
|
|
2019
1888
|
kind: "neon-branch-delete",
|
|
2020
1889
|
detail: e
|
|
2021
1890
|
}];
|
|
2022
|
-
},
|
|
1891
|
+
}, mc = (e) => e.mechanism === "neon-cow" ? fc(e.branchId, e.neonParentBranch === void 0 ? {} : { parentBranch: e.neonParentBranch }) : cc(e.branchId, e.tableNames, e.seed, e.parentNamespace, e.foreignKeys, e.indexNames), hc = (e, t) => e === "neon-cow" ? pc(t) : lc(t), gc = (e, t, n) => {
|
|
2023
1892
|
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);
|
|
2024
1893
|
return {
|
|
2025
1894
|
evict: i,
|
|
2026
1895
|
rejectNew: r.filter((e) => !a.has(e.namespace)).length >= t.maxBranches
|
|
2027
1896
|
};
|
|
2028
|
-
},
|
|
2029
|
-
let n =
|
|
1897
|
+
}, _c = async (e, t) => {
|
|
1898
|
+
let n = rc(e.appSlug, e.prNumber), r = dc({
|
|
2030
1899
|
seed: e.seed,
|
|
2031
1900
|
...e.dbUrl === void 0 ? {} : { dbUrl: e.dbUrl },
|
|
2032
1901
|
...e.prefer === void 0 ? {} : { prefer: e.prefer }
|
|
2033
|
-
}), i =
|
|
1902
|
+
}), i = mc({
|
|
2034
1903
|
mechanism: r,
|
|
2035
1904
|
branchId: n,
|
|
2036
1905
|
tableNames: e.tableNames,
|
|
@@ -2059,15 +1928,15 @@ var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = async (e, t, n
|
|
|
2059
1928
|
mechanism: r,
|
|
2060
1929
|
steps: i
|
|
2061
1930
|
};
|
|
2062
|
-
},
|
|
2063
|
-
let r =
|
|
1931
|
+
}, vc = async (e, t, n) => {
|
|
1932
|
+
let r = hc(t, e);
|
|
2064
1933
|
return t === "neon-cow" ? await n.neonBranchDelete(e) : await n.dropNamespace(e), r;
|
|
2065
|
-
},
|
|
1934
|
+
}, yc = (e, t, n) => gc(e, t, n), X = (e) => `"${e.replace(/"/g, "\"\"")}"`, bc = {
|
|
2066
1935
|
cascade: "CASCADE",
|
|
2067
1936
|
restrict: "RESTRICT",
|
|
2068
1937
|
setNull: "SET NULL",
|
|
2069
1938
|
noAction: "NO ACTION"
|
|
2070
|
-
}, Z = (e) => `'${e.replace(/'/g, "''")}'`,
|
|
1939
|
+
}, Z = (e) => `'${e.replace(/'/g, "''")}'`, xc = (e, t) => {
|
|
2071
1940
|
let n = t.columns.map(Z).join(", ");
|
|
2072
1941
|
return `DO $voltro_branch$
|
|
2073
1942
|
DECLARE derived name;
|
|
@@ -2094,10 +1963,10 @@ BEGIN
|
|
|
2094
1963
|
END IF;
|
|
2095
1964
|
END
|
|
2096
1965
|
$voltro_branch$`;
|
|
2097
|
-
},
|
|
2098
|
-
let n = t.onDelete === void 0 ? "" : ` ON DELETE ${
|
|
1966
|
+
}, Sc = (e, t) => {
|
|
1967
|
+
let n = t.onDelete === void 0 ? "" : ` ON DELETE ${bc[t.onDelete]}`, r = t.onUpdate === void 0 ? "" : ` ON UPDATE ${bc[t.onUpdate]}`;
|
|
2099
1968
|
return `ALTER TABLE ${X(e)}.${X(t.table)} ADD FOREIGN KEY (${X(t.column)}) REFERENCES ${X(e)}.${X(t.targetTable)} (${X(t.targetColumn)})${n}${r}`;
|
|
2100
|
-
},
|
|
1969
|
+
}, Cc = (e) => {
|
|
2101
1970
|
let t = () => {
|
|
2102
1971
|
throw Error("namespace branch executor: Neon ops require a neon-cow executor (use a Neon connection for copy-on-write branches)");
|
|
2103
1972
|
};
|
|
@@ -2105,24 +1974,24 @@ $voltro_branch$`;
|
|
|
2105
1974
|
createNamespace: (t) => e.run(`CREATE SCHEMA IF NOT EXISTS ${X(t)}`),
|
|
2106
1975
|
createTable: (t, n) => e.run(`CREATE TABLE IF NOT EXISTS ${X(t)}.${X(n)} (LIKE ${X(n)} INCLUDING ALL)`),
|
|
2107
1976
|
copyTable: (t, n, r) => e.run(`INSERT INTO ${X(n)}.${X(r)} SELECT * FROM ${X(t)}.${X(r)}`),
|
|
2108
|
-
addForeignKey: (t, n) => e.run(
|
|
2109
|
-
restoreIndexName: (t, n) => e.run(
|
|
1977
|
+
addForeignKey: (t, n) => e.run(Sc(t, n)),
|
|
1978
|
+
restoreIndexName: (t, n) => e.run(xc(t, n)),
|
|
2110
1979
|
dropNamespace: (t) => e.run(`DROP SCHEMA IF EXISTS ${X(t)} CASCADE`),
|
|
2111
1980
|
neonBranchCreate: t,
|
|
2112
1981
|
neonBranchDelete: t
|
|
2113
1982
|
};
|
|
2114
|
-
},
|
|
1983
|
+
}, wc = class extends Error {
|
|
2115
1984
|
_tag = "TenantResidencyUnresolved";
|
|
2116
1985
|
constructor(e) {
|
|
2117
1986
|
super(e), this.name = "TenantResidencyUnresolved";
|
|
2118
1987
|
}
|
|
2119
|
-
},
|
|
1988
|
+
}, Tc = class extends Error {
|
|
2120
1989
|
region;
|
|
2121
1990
|
_tag = "TenantRegionUnavailable";
|
|
2122
1991
|
constructor(e, t) {
|
|
2123
1992
|
super(t), this.region = e, this.name = "TenantRegionUnavailable";
|
|
2124
1993
|
}
|
|
2125
|
-
},
|
|
1994
|
+
}, Ec, Dc = (e) => {
|
|
2126
1995
|
if (e.homes === void 0) throw Error("setResidencyConfig: `homes` is required");
|
|
2127
1996
|
if (e.servableRegions === void 0 || e.servableRegions.length === 0) throw Error("setResidencyConfig: `servableRegions` must be non-empty (which regions this deployment serves)");
|
|
2128
1997
|
let t = /* @__PURE__ */ new Map();
|
|
@@ -2131,55 +2000,55 @@ $voltro_branch$`;
|
|
|
2131
2000
|
if (e !== void 0 && e !== n.region) throw Error(`residency: tenant '${n.tenantId}' is mapped to two regions ('${e}' and '${n.region}')`);
|
|
2132
2001
|
t.set(n.tenantId, n.region);
|
|
2133
2002
|
}
|
|
2134
|
-
return
|
|
2135
|
-
},
|
|
2136
|
-
|
|
2137
|
-
},
|
|
2138
|
-
if (e == null || e === "") throw new
|
|
2003
|
+
return Ec = e, e;
|
|
2004
|
+
}, Oc = () => Ec, kc = () => {
|
|
2005
|
+
Ec = void 0;
|
|
2006
|
+
}, Ac = (e, t) => {
|
|
2007
|
+
if (e == null || e === "") throw new wc("residency is on but the request has no resolvable tenant — refusing to bind a store");
|
|
2139
2008
|
let n = t.homes.find((t) => t.tenantId === e);
|
|
2140
|
-
if (n === void 0) throw new
|
|
2009
|
+
if (n === void 0) throw new wc(`no residency home is mapped for tenant '${e}' — refusing to fall back to a default store (would be a residency violation)`);
|
|
2141
2010
|
return n;
|
|
2142
|
-
},
|
|
2143
|
-
let n =
|
|
2011
|
+
}, jc = (e, t) => t.servableRegions.includes(e), Mc = (e, t) => {
|
|
2012
|
+
let n = Ac(e.tenantId, t), r = Li(n.tenantId);
|
|
2144
2013
|
return {
|
|
2145
2014
|
region: n.region,
|
|
2146
2015
|
namespace: r,
|
|
2147
2016
|
...n.connectionKey === void 0 ? {} : { connectionKey: n.connectionKey }
|
|
2148
2017
|
};
|
|
2149
|
-
},
|
|
2150
|
-
let r =
|
|
2151
|
-
if (!
|
|
2018
|
+
}, Nc = (e, t, n) => {
|
|
2019
|
+
let r = Mc(e, t);
|
|
2020
|
+
if (!jc(r.region, t)) throw new Tc(r.region, `tenant homed in region '${r.region}', which this deployment does not serve — route to the home region`);
|
|
2152
2021
|
let i = n.get(r.region);
|
|
2153
|
-
if (i === void 0) throw new
|
|
2022
|
+
if (i === void 0) throw new Tc(r.region, `no store handle for home region '${r.region}' (declared servable but not wired) — failing closed`);
|
|
2154
2023
|
return {
|
|
2155
2024
|
store: i,
|
|
2156
2025
|
placement: r
|
|
2157
2026
|
};
|
|
2158
|
-
},
|
|
2159
|
-
let { store: i, placement: a } =
|
|
2027
|
+
}, Pc = async (e, t, n, r) => {
|
|
2028
|
+
let { store: i, placement: a } = Nc(e, t, n);
|
|
2160
2029
|
return await r(i, a), a;
|
|
2161
|
-
},
|
|
2030
|
+
}, Fc = (e) => {
|
|
2162
2031
|
if (typeof e == "string") return e;
|
|
2163
2032
|
if ("jsonPath" in e) {
|
|
2164
2033
|
let { column: t, path: n, numeric: r } = e.jsonPath;
|
|
2165
2034
|
return `(json:${t}->${n.join(".")}${r ? "::num" : ""})`;
|
|
2166
2035
|
}
|
|
2167
2036
|
return `(${e.expr})`;
|
|
2168
|
-
}, Q = (e) => e.map(
|
|
2037
|
+
}, Q = (e) => e.map(Fc), Ic = (e, t) => {
|
|
2169
2038
|
if (e.length !== t.length) return !1;
|
|
2170
|
-
for (let n = 0; n < e.length; n++) if (
|
|
2039
|
+
for (let n = 0; n < e.length; n++) if (Fc(e[n]) !== Fc(t[n])) return !1;
|
|
2171
2040
|
return !0;
|
|
2172
|
-
},
|
|
2041
|
+
}, Lc = (e, t) => {
|
|
2173
2042
|
if (e.length >= t.length) return !1;
|
|
2174
|
-
for (let n = 0; n < e.length; n++) if (
|
|
2043
|
+
for (let n = 0; n < e.length; n++) if (Fc(e[n]) !== Fc(t[n])) return !1;
|
|
2175
2044
|
return !0;
|
|
2176
|
-
},
|
|
2045
|
+
}, Rc = (e) => {
|
|
2177
2046
|
let t = [], n = e.appliedIndexes, r = e.tableName;
|
|
2178
2047
|
for (let e = 0; e < n.length; e++) {
|
|
2179
2048
|
let i = n[e];
|
|
2180
2049
|
for (let a = e + 1; a < n.length; a++) {
|
|
2181
2050
|
let e = n[a];
|
|
2182
|
-
if (
|
|
2051
|
+
if (Ic(i.fields, e.fields)) {
|
|
2183
2052
|
let [n, a] = i.name < e.name ? [i, e] : [e, i];
|
|
2184
2053
|
t.push({
|
|
2185
2054
|
kind: "duplicate-fields",
|
|
@@ -2190,13 +2059,13 @@ $voltro_branch$`;
|
|
|
2190
2059
|
});
|
|
2191
2060
|
continue;
|
|
2192
2061
|
}
|
|
2193
|
-
|
|
2062
|
+
Lc(i.fields, e.fields) ? t.push({
|
|
2194
2063
|
kind: "redundant-prefix",
|
|
2195
2064
|
table: r,
|
|
2196
2065
|
redundant: i,
|
|
2197
2066
|
coveredBy: e,
|
|
2198
2067
|
message: `'${r}' index '${i.name}' on [${Q(i.fields).join(", ")}] is a leading prefix of '${e.name}' on [${Q(e.fields).join(", ")}]. Every B-tree dialect we support (Postgres / MySQL / MariaDB / MSSQL / SQLite) can serve a [${Q(i.fields).join(", ")}] query from '${e.name}' too via the leading-prefix rule, so '${i.name}' adds write cost without read benefit. Drop '${i.name}' — unless you specifically need a smaller index for cache locality on a write-heavy table (rare; profile first).`
|
|
2199
|
-
}) :
|
|
2068
|
+
}) : Lc(e.fields, i.fields) && t.push({
|
|
2200
2069
|
kind: "redundant-prefix",
|
|
2201
2070
|
table: r,
|
|
2202
2071
|
redundant: e,
|
|
@@ -2206,23 +2075,23 @@ $voltro_branch$`;
|
|
|
2206
2075
|
}
|
|
2207
2076
|
}
|
|
2208
2077
|
return t;
|
|
2209
|
-
},
|
|
2078
|
+
}, zc = (e) => {
|
|
2210
2079
|
let t = [];
|
|
2211
|
-
for (let n of e) t.push(...
|
|
2080
|
+
for (let n of e) t.push(...Rc(n));
|
|
2212
2081
|
return t;
|
|
2213
|
-
},
|
|
2214
|
-
let n = t.color ?? !0, r = t.indent ?? " ", i = (e) => $(n,
|
|
2082
|
+
}, Bc = "\x1B[", Vc = `${Bc}38;2;245;158;11m`, Hc = `${Bc}38;2;16;185;129m`, Uc = (e, t) => `${e}${t}${j.reset}`, $ = (e, t, n) => e ? typeof t == "function" ? t(n) : Uc(t, n) : n, Wc = (e, t = {}) => {
|
|
2083
|
+
let n = t.color ?? !0, r = t.indent ?? " ", i = (e) => $(n, j.dim, e.padEnd(11)), a = (e) => $(n, (e) => j.bold(j.brand(e)), e), o = (e) => $(n, j.brightRed24, e), s = (e) => $(n, Hc, e), c = (e) => $(n, Vc, e), l = (e) => $(n, j.dim, e), u = `${c("index audit")} ${l("·")} ${$(n, j.bold, e.kind)}`, d = e.redundant.fields.length, f = Q(e.coveredBy.fields.slice(d)), p = (e, t) => {
|
|
2215
2084
|
let n = e.slice(0, t), r = e.slice(t), i = [];
|
|
2216
2085
|
return n.length > 0 && i.push(s(`[${n.join(", ")}]`)), r.length > 0 && i.push(c(`+ [${r.join(", ")}]`)), i.join(" ");
|
|
2217
2086
|
}, m = [];
|
|
2218
|
-
return m.push(u), m.push(""), m.push(`${i("table")}${a(e.table)}`), m.push(""), m.push(`${i("redundant")}${o(e.redundant.name)}`), m.push(`${i("")}${p(Q(e.redundant.fields), d)}`), m.push(""), m.push(`${i("covered by")}${s(e.coveredBy.name)}`), m.push(`${i("")}${p(Q(e.coveredBy.fields), d)}`), f.length > 0 && m.push(`${i("")}${l(`└ extra columns: ${f.join(", ")}`)}`), m.push(""), e.kind === "redundant-prefix" ? (m.push(`${i("why")}B-tree indexes serve queries that filter on a LEADING PREFIX of`), m.push(`${i("")}their column list. The wider index already covers every`), m.push(`${i("")}query the narrower one can serve.`), m.push(`${i("")}${l("Same rule on Postgres / MySQL / MariaDB / MSSQL / SQLite.")}`)) : (m.push(`${i("why")}Two indexes on the same columns under different names.`), m.push(`${i("")}The B-tree engine builds both — same coverage, double cost.`), m.push(`${i("")}${l("Same rule on Postgres / MySQL / MariaDB / MSSQL / SQLite.")}`)), m.push(""), m.push(`${i("cost")}Every ${a("INSERT")} / ${a("UPDATE")} / ${a("DELETE")} on this table writes`), m.push(`${i("")}to ${$(n,
|
|
2219
|
-
},
|
|
2087
|
+
return m.push(u), m.push(""), m.push(`${i("table")}${a(e.table)}`), m.push(""), m.push(`${i("redundant")}${o(e.redundant.name)}`), m.push(`${i("")}${p(Q(e.redundant.fields), d)}`), m.push(""), m.push(`${i("covered by")}${s(e.coveredBy.name)}`), m.push(`${i("")}${p(Q(e.coveredBy.fields), d)}`), f.length > 0 && m.push(`${i("")}${l(`└ extra columns: ${f.join(", ")}`)}`), m.push(""), e.kind === "redundant-prefix" ? (m.push(`${i("why")}B-tree indexes serve queries that filter on a LEADING PREFIX of`), m.push(`${i("")}their column list. The wider index already covers every`), m.push(`${i("")}query the narrower one can serve.`), m.push(`${i("")}${l("Same rule on Postgres / MySQL / MariaDB / MSSQL / SQLite.")}`)) : (m.push(`${i("why")}Two indexes on the same columns under different names.`), m.push(`${i("")}The B-tree engine builds both — same coverage, double cost.`), m.push(`${i("")}${l("Same rule on Postgres / MySQL / MariaDB / MSSQL / SQLite.")}`)), m.push(""), m.push(`${i("cost")}Every ${a("INSERT")} / ${a("UPDATE")} / ${a("DELETE")} on this table writes`), m.push(`${i("")}to ${$(n, j.bold, "both")} B-trees. Pure write overhead, zero read benefit.`), m.push(""), m.push(`${i("fix")}Drop ${o(e.redundant.name)}`), m.push(`${i("")}${l("Keep only if profiling shows the smaller index gives a")}`), m.push(`${i("")}${l("measurable cache-locality boost on a write-heavy hot path.")}`), m.push(`${i("")}${l("Silence with VOLTRO_INDEX_AUDIT=off if intentional.")}`), m.map((e) => `${r}${e}`).join("\n");
|
|
2088
|
+
}, Gc = (e, { apply: t, undo: n }) => ({
|
|
2220
2089
|
name: e,
|
|
2221
2090
|
apply: t,
|
|
2222
2091
|
undo: n
|
|
2223
|
-
}),
|
|
2092
|
+
}), Kc = (e) => {
|
|
2224
2093
|
if (!/^\d{14}_/.test(e.id)) throw Error(`migration "${e.id}": id must start with a 14-digit timestamp followed by "_" (convention: <YYYYMMDDHHMMSS>_<slug>)`);
|
|
2225
|
-
let t = e.steps({ step:
|
|
2094
|
+
let t = e.steps({ step: Gc });
|
|
2226
2095
|
if (t.length === 0) throw Error(`migration "${e.id}": at least one step is required`);
|
|
2227
2096
|
return {
|
|
2228
2097
|
__migration: !0,
|
|
@@ -2230,152 +2099,40 @@ $voltro_branch$`;
|
|
|
2230
2099
|
name: e.name,
|
|
2231
2100
|
steps: t
|
|
2232
2101
|
};
|
|
2233
|
-
},
|
|
2234
|
-
id: T({ prefix: "mig" }),
|
|
2235
|
-
name: y(),
|
|
2236
|
-
hash: y(),
|
|
2237
|
-
status: y(),
|
|
2238
|
-
appliedAt: w().nullable(),
|
|
2239
|
-
durationMs: E().nullable(),
|
|
2240
|
-
errorMessage: y().nullable(),
|
|
2241
|
-
errorStack: y().nullable(),
|
|
2242
|
-
workflowRunId: y().nullable(),
|
|
2243
|
-
createdAt: w().default("now"),
|
|
2244
|
-
updatedAt: w().default("now").onUpdate("now")
|
|
2245
|
-
}).index(["status"]), Kc = C("_voltro_seeds", {
|
|
2246
|
-
id: T({ prefix: "seed" }),
|
|
2247
|
-
name: y(),
|
|
2248
|
-
lifecycle: y(),
|
|
2249
|
-
fingerprint: y(),
|
|
2250
|
-
cronSchedule: y().nullable(),
|
|
2251
|
-
watchedTables: x().nullable(),
|
|
2252
|
-
nextRunAt: w().nullable(),
|
|
2253
|
-
lastRunStatus: y().nullable(),
|
|
2254
|
-
lastRunAt: w().nullable(),
|
|
2255
|
-
lastRunDurationMs: E().nullable(),
|
|
2256
|
-
lastRunRowsTouched: E().nullable(),
|
|
2257
|
-
lastError: y().nullable(),
|
|
2258
|
-
workflowRunId: y().nullable(),
|
|
2259
|
-
createdAt: w().default("now"),
|
|
2260
|
-
updatedAt: w().default("now").onUpdate("now")
|
|
2261
|
-
}).index(["lifecycle"]).index(["nextRunAt"]), qc = C("_voltro_migration_plans", {
|
|
2262
|
-
id: T({ prefix: "plan" }),
|
|
2263
|
-
fingerprint: y(),
|
|
2264
|
-
liveFingerprint: y().nullable(),
|
|
2265
|
-
operations: x(),
|
|
2266
|
-
rollbackPlan: x().nullable(),
|
|
2267
|
-
appliedBy: y(),
|
|
2268
|
-
environment: y(),
|
|
2269
|
-
source: y(),
|
|
2270
|
-
onlineStrategy: y().nullable(),
|
|
2271
|
-
durationMs: E(),
|
|
2272
|
-
notes: y().nullable(),
|
|
2273
|
-
squashedAt: w().nullable(),
|
|
2274
|
-
appliedAt: w().default("now"),
|
|
2275
|
-
createdAt: w().default("now"),
|
|
2276
|
-
updatedAt: w().default("now").onUpdate("now")
|
|
2277
|
-
}).index(["fingerprint"]).index(["environment"]), Jc = C("_voltro_idempotency", {
|
|
2278
|
-
id: T({ prefix: "idem" }),
|
|
2279
|
-
scope: y(),
|
|
2280
|
-
key: y(),
|
|
2281
|
-
status: y(),
|
|
2282
|
-
response: x().nullable(),
|
|
2283
|
-
createdAt: w().default("now")
|
|
2284
|
-
}).unique(["scope", "key"]).index(["createdAt"]), Yc = C("_voltro_devices", {
|
|
2285
|
-
id: T({ prefix: "device" }),
|
|
2286
|
-
tenantId: y(),
|
|
2287
|
-
name: y(),
|
|
2288
|
-
scopes: x().nullable(),
|
|
2289
|
-
pairingHash: y().maxLength(64).nullable(),
|
|
2290
|
-
pairingExpiresAt: w().nullable(),
|
|
2291
|
-
accessHash: y().maxLength(64).nullable(),
|
|
2292
|
-
accessExpiresAt: w().nullable(),
|
|
2293
|
-
refreshHash: y().maxLength(64).nullable(),
|
|
2294
|
-
refreshExpiresAt: w().nullable(),
|
|
2295
|
-
previousRefreshHash: y().maxLength(64).nullable(),
|
|
2296
|
-
generation: E().default(0),
|
|
2297
|
-
pairedAt: w().nullable(),
|
|
2298
|
-
lastSeenAt: w().nullable(),
|
|
2299
|
-
revokedAt: w().nullable(),
|
|
2300
|
-
revokedReason: y().nullable(),
|
|
2301
|
-
createdBy: y().nullable(),
|
|
2302
|
-
metadata: x().nullable(),
|
|
2303
|
-
createdAt: w()
|
|
2304
|
-
}).index(["tenantId"]).index(["pairingHash"]).index(["accessHash"]).index(["refreshHash"]).index(["previousRefreshHash"]), Xc = C("_voltro_tenant_selections", {
|
|
2305
|
-
id: T({ prefix: "tsel" }),
|
|
2306
|
-
subjectType: y().maxLength(32),
|
|
2307
|
-
subjectId: y(),
|
|
2308
|
-
tenantId: y(),
|
|
2309
|
-
selectedAt: w()
|
|
2310
|
-
}).primaryKey(["id"]).nonReactive(), Zc = C("_voltro_kv", {
|
|
2311
|
-
id: T({ prefix: "kv" }),
|
|
2312
|
-
key: y().unique(),
|
|
2313
|
-
value: y().nullable(),
|
|
2314
|
-
expiresAt: w().nullable(),
|
|
2315
|
-
createdAt: w().default("now"),
|
|
2316
|
-
updatedAt: w().default("now").onUpdate("now")
|
|
2317
|
-
}).index(["expiresAt"]), Qc = C("_voltro_api_keys", {
|
|
2318
|
-
id: T({ prefix: "apikey" }),
|
|
2319
|
-
tenantId: y().nullable(),
|
|
2320
|
-
name: y(),
|
|
2321
|
-
hashedKey: y().maxLength(64).unique(),
|
|
2322
|
-
keyPrefix: y(),
|
|
2323
|
-
scopes: x().nullable(),
|
|
2324
|
-
lastUsedAt: w().nullable(),
|
|
2325
|
-
requestCount: E().default(0),
|
|
2326
|
-
expiresAt: w().nullable(),
|
|
2327
|
-
revokedAt: w().nullable(),
|
|
2328
|
-
createdBy: y().nullable(),
|
|
2329
|
-
onBehalfOf: y().nullable(),
|
|
2330
|
-
metadata: x().nullable(),
|
|
2331
|
-
createdAt: w().default("now")
|
|
2332
|
-
}).index("byApiKeyTenant", ["tenantId"]), $c = C("_voltro_replica_observations", {
|
|
2333
|
-
id: T({ prefix: "robs" }),
|
|
2334
|
-
replicaId: y().maxLength(191),
|
|
2335
|
-
startedAt: w(),
|
|
2336
|
-
version: y().maxLength(64).nullable(),
|
|
2337
|
-
kind: y().maxLength(64),
|
|
2338
|
-
payload: y().nullable(),
|
|
2339
|
-
reachableAt: y().maxLength(255).nullable(),
|
|
2340
|
-
writtenAt: w().default("now").onUpdate("now")
|
|
2341
|
-
}).unique(["replicaId", "kind"]).index(["kind"]), el = [
|
|
2342
|
-
Gc,
|
|
2343
|
-
Kc,
|
|
2344
|
-
qc
|
|
2345
|
-
], tl = Xc.tableName, nl = (e) => Fn("sha256").update(`${e.type}\u0000${e.id}`, "utf8").digest("hex"), rl = async (e, t) => {
|
|
2102
|
+
}, qc = (e) => typeof e == "object" && !!e && "__migration" in e && e.__migration === !0, Jc = Ht.tableName, Yc = (e) => $n("sha256").update(`${e.type}\u0000${e.id}`, "utf8").digest("hex"), Xc = async (e, t) => {
|
|
2346
2103
|
let [n] = await e.query({
|
|
2347
|
-
table:
|
|
2348
|
-
predicate:
|
|
2104
|
+
table: Jc,
|
|
2105
|
+
predicate: Ve("id", Yc(t)),
|
|
2349
2106
|
order: [],
|
|
2350
2107
|
take: 1,
|
|
2351
2108
|
skip: void 0,
|
|
2352
2109
|
projection: void 0
|
|
2353
2110
|
}), r = n?.tenantId;
|
|
2354
2111
|
return typeof r == "string" ? r : null;
|
|
2355
|
-
},
|
|
2356
|
-
await e.upsert(
|
|
2357
|
-
id:
|
|
2112
|
+
}, Zc = async (e, t, n) => {
|
|
2113
|
+
await e.upsert(Jc, {
|
|
2114
|
+
id: Yc(t),
|
|
2358
2115
|
subjectType: t.type,
|
|
2359
2116
|
subjectId: t.id,
|
|
2360
2117
|
tenantId: n,
|
|
2361
2118
|
selectedAt: /* @__PURE__ */ new Date()
|
|
2362
2119
|
}, { conflictColumns: ["id"] });
|
|
2363
|
-
},
|
|
2364
|
-
await e.delete(
|
|
2365
|
-
},
|
|
2366
|
-
id:
|
|
2367
|
-
startedAt:
|
|
2368
|
-
kind:
|
|
2369
|
-
tables:
|
|
2370
|
-
capture:
|
|
2371
|
-
via:
|
|
2372
|
-
staging:
|
|
2373
|
-
heartbeatAt:
|
|
2374
|
-
resumable:
|
|
2375
|
-
}),
|
|
2120
|
+
}, Qc = async (e, t) => {
|
|
2121
|
+
await e.delete(Jc, Yc(t));
|
|
2122
|
+
}, $c = "_voltro_replace_in_progress", el = w($c, {
|
|
2123
|
+
id: S({ prefix: "repl" }),
|
|
2124
|
+
startedAt: E().default("now"),
|
|
2125
|
+
kind: T().default("replace"),
|
|
2126
|
+
tables: T().nullable(),
|
|
2127
|
+
capture: T().nullable(),
|
|
2128
|
+
via: T(),
|
|
2129
|
+
staging: T().nullable(),
|
|
2130
|
+
heartbeatAt: E().nullable(),
|
|
2131
|
+
resumable: Ln().nullable()
|
|
2132
|
+
}), tl = 30, nl = (e, t) => {
|
|
2376
2133
|
let n = typeof t == "number" && Number.isFinite(t) && t > 0 ? t : 30, r = Number(e.VOLTRO_STAGING_STALE_MINUTES);
|
|
2377
2134
|
return (Number.isFinite(r) && r > 0 ? r : n) * 6e4;
|
|
2378
|
-
},
|
|
2135
|
+
}, rl = (e) => e == null || String(e).length === 0 ? [] : String(e).split(",").map((e) => e.trim()).filter((e) => e.length > 0), il = (e) => {
|
|
2379
2136
|
let t = e.filter((e) => e.kind !== "staging");
|
|
2380
2137
|
if (t.length !== 0) return `refusing to start: a destructive data operation did not finish.
|
|
2381
2138
|
${t.map((e) => {
|
|
@@ -2390,7 +2147,7 @@ ${t.map((e) => {
|
|
|
2390
2147
|
|
|
2391
2148
|
When the data is back, or you have decided the current state is correct, clear the marker:
|
|
2392
2149
|
voltro data clear-replace-marker --yes`;
|
|
2393
|
-
},
|
|
2150
|
+
}, al = (e, t, n) => {
|
|
2394
2151
|
let r = e.filter((e) => e.kind === "staging");
|
|
2395
2152
|
return {
|
|
2396
2153
|
all: r,
|
|
@@ -2400,7 +2157,7 @@ ${t.map((e) => {
|
|
|
2400
2157
|
return Number.isFinite(r) ? t - r >= n : !1;
|
|
2401
2158
|
})
|
|
2402
2159
|
};
|
|
2403
|
-
},
|
|
2160
|
+
}, ol = (e, t) => {
|
|
2404
2161
|
if (e.all.length === 0) return;
|
|
2405
2162
|
let n = new Set(e.droppable.map((e) => e.id));
|
|
2406
2163
|
return `staged data-import leftovers:
|
|
@@ -2409,22 +2166,22 @@ ${e.all.map((e) => {
|
|
|
2409
2166
|
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.`;
|
|
2410
2167
|
}).join("\n")}\n The target of a staged \`replace\` is untouched until one short swap at the end, so none of this is
|
|
2411
2168
|
a reason to refuse the boot — it is a reason to know the disk is holding a copy of a bundle.`;
|
|
2412
|
-
},
|
|
2413
|
-
let n =
|
|
2169
|
+
}, sl = "id", cl = (e, t) => {
|
|
2170
|
+
let n = cn(e);
|
|
2414
2171
|
if (n === void 0) return t;
|
|
2415
|
-
let r = n.fields[
|
|
2416
|
-
if (r === void 0 || t[
|
|
2172
|
+
let r = n.fields[sl]?.idScheme;
|
|
2173
|
+
if (r === void 0 || t[sl] != null) return t;
|
|
2417
2174
|
if (r.kind === "numeric") {
|
|
2418
|
-
if (!(
|
|
2175
|
+
if (!(sl in t)) return t;
|
|
2419
2176
|
let e = { ...t };
|
|
2420
|
-
return delete e[
|
|
2177
|
+
return delete e[sl], e;
|
|
2421
2178
|
}
|
|
2422
|
-
let i =
|
|
2179
|
+
let i = Sn(r, e);
|
|
2423
2180
|
return i === null ? t : {
|
|
2424
2181
|
...t,
|
|
2425
|
-
[
|
|
2182
|
+
[sl]: i
|
|
2426
2183
|
};
|
|
2427
|
-
},
|
|
2184
|
+
}, ll = (e, t) => t.map((t) => cl(e, t)), ul = {
|
|
2428
2185
|
postgres: { maxBindParameters: 65535 },
|
|
2429
2186
|
mysql: { maxBindParameters: 65535 },
|
|
2430
2187
|
mariadb: { maxBindParameters: 65535 },
|
|
@@ -2434,25 +2191,25 @@ ${e.all.map((e) => {
|
|
|
2434
2191
|
},
|
|
2435
2192
|
sqlite: { maxBindParameters: 32766 },
|
|
2436
2193
|
turso: { maxBindParameters: 32766 }
|
|
2437
|
-
},
|
|
2194
|
+
}, dl = (e) => ul[e], fl = (e) => {
|
|
2438
2195
|
let t = /* @__PURE__ */ new Set();
|
|
2439
2196
|
for (let n of e) for (let e of Object.keys(n)) t.add(e);
|
|
2440
2197
|
return t.size;
|
|
2441
|
-
},
|
|
2198
|
+
}, pl = (e, t) => {
|
|
2442
2199
|
if (t === void 0 || e.length === 0) return [e];
|
|
2443
|
-
let n = Math.max(1,
|
|
2200
|
+
let n = Math.max(1, fl(e)), r = Math.floor(t.maxBindParameters / n), i = t.maxRowsPerStatement ?? Infinity, a = Math.max(1, Math.min(r, i));
|
|
2444
2201
|
if (e.length <= a) return [e];
|
|
2445
2202
|
let o = [];
|
|
2446
2203
|
for (let t = 0; t < e.length; t += a) o.push(e.slice(t, t + a));
|
|
2447
2204
|
return o;
|
|
2448
|
-
},
|
|
2205
|
+
}, ml = (e, t) => {
|
|
2449
2206
|
let n = [], r = t;
|
|
2450
2207
|
for (let [t, i] of Object.entries(e.fields)) {
|
|
2451
2208
|
let e = i;
|
|
2452
2209
|
e.nullable || e.hasDefault || e.idScheme !== void 0 || e.generatedAs !== void 0 || (r[t] === void 0 || r[t] === null) && n.push(t);
|
|
2453
2210
|
}
|
|
2454
2211
|
return n;
|
|
2455
|
-
},
|
|
2212
|
+
}, hl = (e, t, n) => {
|
|
2456
2213
|
let r = n, i = new Set(e === void 0 ? [] : Object.entries(e.fields).filter(([, e]) => e.generatedAs !== void 0).map(([e]) => e)), a = [];
|
|
2457
2214
|
for (let e of t) i.has(e) || (r[e] === void 0 ? a.push({
|
|
2458
2215
|
column: e,
|
|
@@ -2462,36 +2219,36 @@ ${e.all.map((e) => {
|
|
|
2462
2219
|
reason: "null"
|
|
2463
2220
|
}));
|
|
2464
2221
|
return a;
|
|
2465
|
-
},
|
|
2222
|
+
}, gl = (e, t, n) => e.insert(t.tableName, n), _l = (e, t, n) => e.insertMany(t.tableName, n), vl = (e, t, n, r) => e.upsert(t.tableName, n, {
|
|
2466
2223
|
conflictColumns: r.conflictColumns,
|
|
2467
2224
|
...r.update === void 0 ? {} : { update: r.update },
|
|
2468
2225
|
...r.updateValues === void 0 ? {} : { updateValues: r.updateValues }
|
|
2469
|
-
}),
|
|
2226
|
+
}), yl = async (e, t, n, r) => {
|
|
2470
2227
|
if (e.upsertWithOutcome === void 0) throw Error("upsertRowOutcome: this store does not implement `upsertWithOutcome`. It is provided by the framework's store wrapper, so `ctx.store` has it; a hand-written DataStore must add it.");
|
|
2471
2228
|
return e.upsertWithOutcome(t.tableName, n, {
|
|
2472
2229
|
conflictColumns: r.conflictColumns,
|
|
2473
2230
|
...r.update === void 0 ? {} : { update: r.update },
|
|
2474
2231
|
...r.updateValues === void 0 ? {} : { updateValues: r.updateValues }
|
|
2475
2232
|
});
|
|
2476
|
-
},
|
|
2233
|
+
}, bl = async (e, t, n, r) => e.insertIgnoreWithOutcome(t.tableName, n, { conflictColumns: r.conflictColumns }), xl = (e, t, n, r) => e.updateMany(t.tableName, n, { where: r.where }), Sl = 512, Cl = (e) => {
|
|
2477
2234
|
e.setMaxListeners(512);
|
|
2478
|
-
},
|
|
2235
|
+
}, wl = (e, t, n) => ({
|
|
2479
2236
|
_tag: "PrimaryKeyConflictError",
|
|
2480
2237
|
table: e,
|
|
2481
2238
|
key: t,
|
|
2482
2239
|
cause: n
|
|
2483
|
-
}),
|
|
2240
|
+
}), Tl = (e) => typeof e == "object" && !!e && e._tag === "PrimaryKeyConflictError", El = {
|
|
2484
2241
|
postgres: 5432,
|
|
2485
2242
|
mysql: 3306,
|
|
2486
2243
|
mariadb: 3306,
|
|
2487
2244
|
mssql: 1433
|
|
2488
|
-
},
|
|
2245
|
+
}, Dl = /* @__PURE__ */ new Set([
|
|
2489
2246
|
"localhost",
|
|
2490
2247
|
"127.0.0.1",
|
|
2491
2248
|
"::1",
|
|
2492
2249
|
"[::1]",
|
|
2493
2250
|
"0.0.0.0"
|
|
2494
|
-
]),
|
|
2251
|
+
]), Ol = (e) => {
|
|
2495
2252
|
let t = e.host, n = e.port, r = e.database;
|
|
2496
2253
|
if (e.url !== void 0 && e.url !== "") try {
|
|
2497
2254
|
let i = new URL(e.url);
|
|
@@ -2500,29 +2257,29 @@ ${e.all.map((e) => {
|
|
|
2500
2257
|
return;
|
|
2501
2258
|
}
|
|
2502
2259
|
if (t === void 0 || t === "" || r === void 0 || r === "") return;
|
|
2503
|
-
let i = n ??
|
|
2260
|
+
let i = n ?? El[(e.dialect ?? "").toLowerCase()];
|
|
2504
2261
|
if (i === void 0 || !Number.isFinite(i)) return;
|
|
2505
2262
|
let a = t.toLowerCase();
|
|
2506
2263
|
return {
|
|
2507
|
-
host:
|
|
2264
|
+
host: Dl.has(a) ? "localhost" : a,
|
|
2508
2265
|
port: i,
|
|
2509
2266
|
database: r.toLowerCase()
|
|
2510
2267
|
};
|
|
2511
|
-
},
|
|
2512
|
-
let t =
|
|
2513
|
-
if (t !== void 0) return
|
|
2514
|
-
},
|
|
2268
|
+
}, kl = (e) => {
|
|
2269
|
+
let t = Ol(e);
|
|
2270
|
+
if (t !== void 0) return $n("sha256").update(`${t.host}\u0000${t.port}\u0000${t.database}`).digest("hex").slice(0, 32);
|
|
2271
|
+
}, Al = (e, t) => e === void 0 || t === void 0 ? "unknown" : e === t ? "same" : "different", jl = {
|
|
2515
2272
|
app: 3,
|
|
2516
2273
|
plugin: 2,
|
|
2517
2274
|
framework: 1
|
|
2518
|
-
},
|
|
2275
|
+
}, Ml = /* @__PURE__ */ new Map(), Nl = [], Pl = () => [...Nl], Fl = (e) => {
|
|
2519
2276
|
if (!e.table || !e.timeColumn) throw Error("registerRetention: table + timeColumn are required");
|
|
2520
2277
|
if (!Number.isFinite(e.ttlMs) || e.ttlMs <= 0) throw Error(`registerRetention(${e.table}): ttlMs must be a positive number`);
|
|
2521
|
-
let t = e.source ?? "app", n =
|
|
2278
|
+
let t = e.source ?? "app", n = Ml.get(e.table);
|
|
2522
2279
|
if (n !== void 0) {
|
|
2523
2280
|
let r = n.source ?? "app", i = n.ttlMs !== e.ttlMs || n.where !== void 0 != (e.where !== void 0);
|
|
2524
|
-
if (
|
|
2525
|
-
i &&
|
|
2281
|
+
if (jl[t] < jl[r]) {
|
|
2282
|
+
i && Nl.push({
|
|
2526
2283
|
table: e.table,
|
|
2527
2284
|
kept: {
|
|
2528
2285
|
source: r,
|
|
@@ -2535,7 +2292,7 @@ ${e.all.map((e) => {
|
|
|
2535
2292
|
});
|
|
2536
2293
|
return;
|
|
2537
2294
|
}
|
|
2538
|
-
i && r !== t &&
|
|
2295
|
+
i && r !== t && Nl.push({
|
|
2539
2296
|
table: e.table,
|
|
2540
2297
|
kept: {
|
|
2541
2298
|
source: t,
|
|
@@ -2547,13 +2304,13 @@ ${e.all.map((e) => {
|
|
|
2547
2304
|
}
|
|
2548
2305
|
});
|
|
2549
2306
|
}
|
|
2550
|
-
|
|
2307
|
+
Ml.set(e.table, {
|
|
2551
2308
|
...e,
|
|
2552
2309
|
source: t
|
|
2553
2310
|
});
|
|
2554
|
-
},
|
|
2555
|
-
|
|
2556
|
-
},
|
|
2311
|
+
}, Il = () => [...Ml.values()], Ll = () => {
|
|
2312
|
+
Ml.clear(), Nl.length = 0;
|
|
2313
|
+
}, Rl = async (e, t, n, r = 2e4) => {
|
|
2557
2314
|
let i = new Date(t - e.ttlMs), a = 0;
|
|
2558
2315
|
try {
|
|
2559
2316
|
for (;;) {
|
|
@@ -2561,45 +2318,45 @@ ${e.all.map((e) => {
|
|
|
2561
2318
|
if (a += t, t < r) break;
|
|
2562
2319
|
}
|
|
2563
2320
|
} catch (t) {
|
|
2564
|
-
throw
|
|
2321
|
+
throw D.runSync(O.increment(O.tagged(Bl, "table", e.table))), t;
|
|
2565
2322
|
}
|
|
2566
|
-
return a > 0 &&
|
|
2567
|
-
},
|
|
2323
|
+
return a > 0 && D.runSync(O.incrementBy(O.tagged(zl, "table", e.table), a)), a;
|
|
2324
|
+
}, zl = O.counter("voltro_retention_swept_rows_total"), Bl = O.counter("voltro_retention_sweep_errors_total"), Vl = (e, t) => {
|
|
2568
2325
|
let n = Number(e ?? String(t));
|
|
2569
2326
|
return (Number.isFinite(n) && n > 0 ? n : t) * 36e5;
|
|
2570
|
-
},
|
|
2571
|
-
id:
|
|
2572
|
-
replicaId:
|
|
2573
|
-
streamName:
|
|
2574
|
-
binlogFile:
|
|
2575
|
-
binlogPosition:
|
|
2576
|
-
updatedAt:
|
|
2577
|
-
}).index(["replicaId"]),
|
|
2578
|
-
id:
|
|
2579
|
-
replicaId:
|
|
2580
|
-
streamName:
|
|
2581
|
-
ctVersion:
|
|
2582
|
-
updatedAt:
|
|
2583
|
-
}).index(["replicaId"]),
|
|
2584
|
-
id:
|
|
2585
|
-
startedAt:
|
|
2586
|
-
finishedAt:
|
|
2587
|
-
direction:
|
|
2588
|
-
mode:
|
|
2589
|
-
via:
|
|
2590
|
-
bundle:
|
|
2591
|
-
sourceFingerprint:
|
|
2592
|
-
tablesWritten:
|
|
2593
|
-
rowsWritten:
|
|
2594
|
-
failure:
|
|
2595
|
-
staged:
|
|
2596
|
-
}).renamedFrom("_voltro_data_imports").nonReactive(),
|
|
2327
|
+
}, Hl = "_voltro_cdc_offsets", Ul = w(Hl, {
|
|
2328
|
+
id: S({ prefix: "cdcoff" }),
|
|
2329
|
+
replicaId: T(),
|
|
2330
|
+
streamName: T(),
|
|
2331
|
+
binlogFile: T(),
|
|
2332
|
+
binlogPosition: T(),
|
|
2333
|
+
updatedAt: E()
|
|
2334
|
+
}).index(["replicaId"]), Wl = w(Hl, {
|
|
2335
|
+
id: S({ prefix: "cdcoff" }),
|
|
2336
|
+
replicaId: T(),
|
|
2337
|
+
streamName: T(),
|
|
2338
|
+
ctVersion: T(),
|
|
2339
|
+
updatedAt: E()
|
|
2340
|
+
}).index(["replicaId"]), Gl = "_voltro_data_transfers", Kl = w(Gl, {
|
|
2341
|
+
id: S({ prefix: "dimp" }),
|
|
2342
|
+
startedAt: E().default("now"),
|
|
2343
|
+
finishedAt: E().nullable(),
|
|
2344
|
+
direction: T().default("import"),
|
|
2345
|
+
mode: T(),
|
|
2346
|
+
via: T(),
|
|
2347
|
+
bundle: T().nullable(),
|
|
2348
|
+
sourceFingerprint: T().nullable(),
|
|
2349
|
+
tablesWritten: Ae().default(0),
|
|
2350
|
+
rowsWritten: Ae().default(0),
|
|
2351
|
+
failure: T().nullable(),
|
|
2352
|
+
staged: Ln().nullable()
|
|
2353
|
+
}).renamedFrom("_voltro_data_imports").nonReactive(), ql = (e) => {
|
|
2597
2354
|
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)";
|
|
2598
2355
|
return `${t} · ${r} · via ${e.via}${i}` + (e.bundle === null ? "" : ` · from ${e.bundle}`) + (e.sourceFingerprint === null ? "" : ` · source schema ${e.sourceFingerprint}`);
|
|
2599
|
-
},
|
|
2356
|
+
}, Jl = 255, Yl = (e) => e == null ? "null" : typeof e == "string" || typeof e == "number" || typeof e == "boolean" ? JSON.stringify(e) : Array.isArray(e) ? `[${e.map(Yl).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)}:${Yl(t)}`).join(",")}}` : JSON.stringify(String(e)), Xl = (e) => {
|
|
2600
2357
|
if (e == null) return null;
|
|
2601
|
-
let t = typeof e == "string" ? e :
|
|
2358
|
+
let t = typeof e == "string" ? e : Yl(e);
|
|
2602
2359
|
return t.length > 255 ? t.slice(0, 255) : t;
|
|
2603
|
-
},
|
|
2360
|
+
}, Zl = "postgres";
|
|
2604
2361
|
//#endregion
|
|
2605
|
-
export {
|
|
2362
|
+
export { Yt as AUTO_FILLED_COLUMNS, ur as BOUND_ENCRYPTED_PREFIX, ul as BULK_INSERT_LIMITS, Y as BranchNameInvalid, oc as BranchTransitionInvalid, Hl as CDC_OFFSETS_TABLE, go as CHANGE_CLAIM_TTL_ENV, Sl as CHANGE_LISTENER_CEILING, ee as ColumnBuilder, Gl as DATA_TRANSFERS_TABLE, je as DEFAULT_ACQUIRE_TIMEOUT_MS, _o as DEFAULT_CHANGE_CLAIM_TTL_HOURS, vs as DEFAULT_EAGER_FALLBACK_WARN_INTERVAL_MS, vt as DEFAULT_SOFT_DROP_RETENTION_DAYS, ei as DEFAULT_SUBJECT_GRAPH_DEPTH, lr as ENCRYPTED_PREFIX, Zl as ENGINE, yi as EagerCardinalityError, dt as FILE_MIGRATION_PATTERN, wt as FRAMEWORK_LIVE_TABLES, pr as FieldDecryptionError, Bo as ID_COLUMN_MAX_LENGTH, Un as INITIAL_VERSION, An as IrreversibleMigrationError, b as MATCHES_NO_ROWS, Kt as MAX_IDENTIFIER_LENGTH, Fs as MSSQL_TRANSIENT_NUMBERS, Ns as MYSQL_TRANSIENT_CODES, Fe as MigrationExpectationFailed, l as MigrationSkipped, ho as OccurrenceCounter, Ps as POSTGRES_TRANSIENT_STATES, $c as REPLACE_IN_PROGRESS_TABLE, Dn as RewriteUnstableError, Jl as SCOPE_KEY_MAX_LENGTH, se as SELF_REFERENCE_TARGET, Is as SQLITE_TRANSIENT_CODES, tl as STAGING_STALE_MINUTES, nn as STAGING_TABLE_PREFIX, nr as SqlClient, Jc as TENANT_SELECTIONS_TABLE, Ls as TURSO_TRANSIENT_MESSAGE, Js as TableStreamError, Ni as TenantNamespaceInvalid, Mi as TenantNamespaceUnresolved, Tc as TenantRegionUnavailable, wc as TenantResidencyUnresolved, Ds as TransactionAbortedError, Re as TransactionBrokenByBodyError, Hs as VOLTRO_EXPIRES_MIXIN_ID, Ws as VOLTRO_LOCAL_FIRST_MIXIN_ID, Bn as VersionConflict, jt as WARN_IDENTIFIER_LENGTH, _n as _voltroApiKeysTable, Ul as _voltroCdcOffsetsTable, Kl as _voltroDataTransfersTable, Jt as _voltroDevicesTable, ln as _voltroIdempotencyTable, Nt as _voltroKvTable, st as _voltroMigrationPlansTable, Qt as _voltroMigrationsTable, Wl as _voltroMssqlCdcOffsetsTable, el as _voltroReplaceInProgressTable, pn as _voltroReplicaObservationsTable, mt as _voltroSeedsTable, Ht as _voltroTenantSelectionsTable, io as actorsTable, yc as admitBranch, Gt as agedSoftDropSnapshots, Bt as allEnumRenames, Zr as allRegisteredRelations, Ye as allRegisteredTables, he as and, _i as applyJsonPatch, ge as array, Me as arrayContains, In as arrayHas, o as arrayOverlaps, xi as attachEagerLoads, So as attributionFields, Eo as attributionKey, zc as auditAllTableIndexes, Rc as auditTableIndexes, pt as avg, Mn as avgOver, Fo as beginLocalWrite, Ne as bigint, Nc as bindResidentStore, Ln as boolean, rc as branchNamespaceName, dl as bulkInsertLimitsFor, s as bytes, jn as causeBranches, co as changeDelete, fo as changeDigest, oo as changeInsert, lo as changeSoftDelete, so as changeUpdate, pl as chunkRowsForInsert, ko as claimPendingAttribution, Ie as classifyConstraintViolation, i as clearEnumRenames, Ro as clearPendingAttribution, $r as clearRelationsRegistry, kc as clearResidencyConfig, Ll as clearRetentions, ie as clearTableRegistry, qo as clearWriteRecorders, W as coercePredicateForSqlite, Vi as coercePredicateValue, Hi as coercePredicateValues, Xa as coerceValueForSqlite, We as collectSubqueries, Le as column, Or as columnSchema, fl as columnsPerRow, Cn as compareDecimal, ea as compileEagerJson, vi as compileJsonPatch, F as compilePredicate, Ui as compileRawFragment, I as compileSelect, po as composeChangeKey, $s as computeEmbedding, kl as connectionIdentity, ae as contains, d as count, kn as countDistinct, Ge as crdtDoc, y as crdtManagedColumns, He as crdtManagedColumnsOf, Je as crdtText, xo as currentWriteAttribution, Be as databaseHandle, re as date, pe as dbEnum, fs as dbMetricTagCacheSizeForTests, hs as dbOperationsInFlight, sn as decimal, Lt as declareEnumRename, vr as decodeFieldValue, an as decodeRowsForTable, qt as decodeRowsFromSchema, wr as decryptFieldsOnRead, Kc as defineMigration, $t as defineMixin, r as defineSeed, Qc as deleteTenantSelection, _ as denseRank, si as deriveSubjectGraph, Ut as deriveTypeIdPrefix, Uo as derivedRowId, Wo as derivedRowIdLength, At as describeAgedSoftDropSnapshots, u as describeDriverError, On as describeRowBindings, ql as describeTransferRun, cr as deserializeArraysOnRead, Ot as drainIdentifierWarnings, ue as dropped, gr as encodeFieldValue, Mt as encodeRowForSchema, Cr as encryptFieldsForWrite, xr as encryptedColumnsOf, Io as endLocalWrite, gc as enforceBranchLimits, me as ensureTableRegistered, Ve as eq, P as escapeLike, qe as evaluatePredicate, m as except, ne as exists, Us as expires, ao as externalChangeEvent, ze as extractDbCause, dr as fieldBinding, It as fireSchemaChangeSeeds, ve as fireTenantCreateSeeds, Wc as formatIndexAuditIssue, ci as formatSubjectGraph, xn as frameworkTables, Sn as generateId, Tt as generateSnowflake, et as geography, Ze as geometry, ye as getEnumRenames, Xr as getRelation, Yr as getRelations, Oc as getResidencyConfig, cn as getTable, fe as gt, on as gte, ji as hasEagerLoads, Qs as hybridSearch, S as id, le as inSet, $e as inSubquery, M as inferForeignKey, bl as insertIgnoreRowOutcome, _l as insertManyRows, gl as insertRow, Ae as integer, il as interruptedReplaceRefusal, Te as intersect, t as interval, h as irreversible, f as irreversibleReason, fr as isBoundCiphertext, ic as isBranchNamespace, pi as isCompositeRowKey, Ir as isEmptyRelationsSpec, hr as isEncrypted, mr as isFieldDecryptionError, Ce as isFileMigration, g as isForeignKeyViolation, Dt as isFrameworkOwnedLiveTable, Ks as isLocalFirst, qc as isMigrationDefinition, n as isMysqlFamily, uc as isNeonConnection, Xe as isNotNull, nt as isNull, Tl as isPrimaryKeyConflictError, p as isQueryTimeout, yr as isRawEncoding, jc as isRegionServable, Lr as isRelationsSpec, xe as isSeedDefinition, it as isSoftDropSnapshotName, xt as isSqliteFamily, wn as isStagingTableName, de as isTableReactive, As as isTransactionAbortedError, Bs as isTransientContention, kt as isView, St as json, ke as jsonField, un as jsonIndex, mi as jsonPatchAssignments, Vt as lag, a as lead, Pl as listRetentionConflicts, Il as listRetentions, Gs as localFirst, qs as localFirstTables, e as lt, Ct as lte, xs as makeEagerFallbackReporter, Cc as makeNamespaceBranchExecutor, Os as makeTransactionAbortTracker, zr as many, Br as manyToMany, yn as materializeFields, Rt as max, zt as migration, be as min, hl as missingConflictColumns, ml as missingRequiredColumns, mn as mixin, bn as neq, sc as nextBranchState, Ol as normaliseTarget, gi as normalizeJsonPatchValue, Zt as not, fn as notExists, Ft as notInSet, ut as notInSubquery, Xt as numeric, _s as observeDbOp, vo as occurrenceWindowMs, Rr as one, bi as oneCardinalityMessage, tn as or, x as orderClausesOf, Oe as paginateBy, te as paginateById, mo as parseChangeKey, zo as pendingAttributionCount, mc as planBranch, cc as planBranchProvision, lc as planBranchTeardown, hc as planBranchTeardownFor, fc as planNeonBranchProvision, pc as planNeonBranchTeardown, zn as planVersionedUpdate, Se as pluginRef, De as pluginRefSpecOf, wl as primaryKeyConflictError, _c as provisionBranch, Pc as provisionResidentTenant, Ri as qualifyTable, ce as queryFor, ot as queryForView, vn as quoteIdent, Cl as raiseChangeListenerCeiling, _e as rank, dn as raw, Xc as readTenantSelection, Pt as readableByColumns, lt as real, gs as recordDbOp, Qo as recordsTable, en as reference, Er as refuseWrite, eo as registerCoreTables, Jr as registerDiscoveredRelations, Oo as registerPendingAttribution, qr as registerRelations, Fl as registerRetention, tt as registerTable, Go as registerWriteRecorder, Fr as relations, no as requireActors, Qe as requireTable, ro as requireTenants, ds as resetDbMetricTagCacheForTests, rn as resetSnowflake, Mc as residentPlacement, ir as resolveActorSnapshot, dc as resolveBranchMechanism, bs as resolveEagerFallbackWarnIntervalMs, Lo as resolveEchoAttribution, Pe as resolveFullTextIndex, yt as resolveIdScheme, ht as resolveMixinGraph, Ac as resolveTenantHome, Li as resolveTenantNamespace, Vl as retentionTtlMsFromEnv, di as rowKeyColumns, fi as rowKeyIdentity, Rn as rowNumber, kr as rowSchema, Es as runRetryingTransaction, ks as runSavepoint, Ms as runStoreTransaction, bo as runWithWriteAttribution, $o as runWriteRecorders, Al as sameDatabase, Ii as sanitizeIdentifierFragment, Xl as scopeKeyOf, hn as selfReference, sr as serializeArraysForWrite, gt as serverOnlyColumns, Dc as setResidencyConfig, Ee as setSchemaChangeSeedHook, v as setTenantCreateSeedHook, Ss as settleTransactionExit, Hn as settleVersionedUpdate, Nn as softDropSnapshotStamp, gn as spatialPredicate, ol as stagingLeftoverReport, al as stagingLeftovers, rl as stagingNamesOf, nl as stagingStaleAfterMs, cl as stampGeneratedId, ll as stampGeneratedIds, _t as startsWith, Dr as storeRefusalOf, Zs as streamTable, c as sum, Ke as sumOver, Yo as suspendWriteRecorders, Xo as suspendWriteRecordersEffect, Rl as sweepRetention, w as table, vc as teardownBranch, Yc as tenantSelectionId, T as text, E as timestamp, Gn as timestampMs, Vn as timestampMsOrNull, Ts as transactionRetrySchedule, oe as union, Ue as unionAll, rt as unregisterTable, Ko as unregisterWriteRecorder, xl as updateManyRow, vl as upsertRow, yl as upsertRowOutcome, ui as upsertUpdatePatch, li as upsertUpdateValues, at as validateColumnName, Tn as validateIndexName, Qr as validateRegisteredRelations, Wr as validateRelationConfig, Pn as validateTableName, ft as validateTypeIdPrefix, bt as vector, ct as vectorDistanceToOpclass, ec as vectorEmbedding, Wn as versionColumnOf, En as view, Fn as viewSql, Wt as walkLeaves, we as wireSafeCause, Co as withCapturedAttribution, Zo as writeRecordersSuspended, Zc as writeTenantSelection };
|