@voltro/database 0.71.0 → 0.72.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 +435 -0
- package/THIRD-PARTY-NOTICES.md +29 -1
- package/dist/frameworkLiveTables-C1WjQ_uI.js +1641 -0
- package/dist/index.d.ts +661 -30
- package/dist/index.js +832 -1061
- package/dist/sql.d.ts +3027 -711
- package/dist/sql.js +2014 -1236
- package/package.json +3 -2
- package/dist/frameworkLiveTables-D53uncZH.js +0 -1308
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { $ as e, $t as t, A as n,
|
|
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, $t as t, A as n, An as r, At as i, B as a, Bn as o, Bt as s, C as c, Cn as l, Ct as u, D as d, Dn as f, Dt as p, E as m, En as h, Et as g, F as _, Fn as v, Ft as ee, G as te, Gn as y, Gt as ne, H as re, Hn as ie, Ht as ae, I as b, In as x, It as S, J as oe, Jt as C, K as se, Kn as w, Kt as ce, L as le, Ln as ue, Lt as de, M as fe, Mn as pe, Mt as me, N as he, Nn as T, Nt as ge, O as _e, On as ve, Ot as ye, P as be, Pn as E, Pt as xe, Q as Se, Qt as Ce, R as we, Rn as Te, Rt as Ee, S as De, Sn as Oe, St as ke, T as Ae, Tn as je, Tt as Me, U as Ne, Un as Pe, Ut as Fe, V as Ie, Vn as Le, Vt as Re, W as ze, Wn as Be, Wt as Ve, X as He, Xt as Ue, Y as We, Yt as Ge, Z as Ke, Zt as qe, _ as Je, _n as Ye, _t as Xe, a as Ze, an as Qe, at as $e, b as et, bn as tt, bt as nt, c as rt, cn as it, ct as at, d as ot, dn as st, dt as ct, en as lt, et as ut, f as dt, fn as ft, ft as pt, g as mt, gn as ht, gt, h as _t, hn as vt, ht as yt, i as bt, in as xt, it as St, j as Ct, jn as wt, jt as Tt, k as Et, kn as Dt, kt as Ot, l as kt, ln as At, lt as jt, m as Mt, mn as Nt, mt as Pt, n as Ft, nn as It, nt as Lt, o as Rt, on as zt, ot as Bt, p as Vt, pn as Ht, pt as Ut, q as Wt, qn as Gt, qt as Kt, r as qt, rn as Jt, rt as Yt, s as Xt, sn as Zt, st as Qt, t as $t, tn as en, tt as D, u as tn, un as nn, ut as rn, v as an, vn as on, vt as sn, w as cn, wn as ln, wt as un, x as dn, xn as fn, xt as pn, y as mn, yn as hn, yt as gn, z as _n, zn as vn, zt as yn } from "./frameworkLiveTables-C1WjQ_uI.js";
|
|
2
|
+
import { a as bn, i as xn, n as Sn, o as Cn, r as wn, s as Tn, t as En } from "./wire-B28cPjEp.js";
|
|
3
|
+
import { Cause as Dn, Chunk as On, Data as kn, Effect as O, Exit as An, Metric as k, MetricBoundaries as jn, Option as A, Runtime as Mn, Schedule as Nn, Schema as j, Stream as Pn } from "effect";
|
|
4
|
+
import { createHash as Fn } from "node:crypto";
|
|
5
|
+
import { AsyncLocalStorage as In } from "node:async_hooks";
|
|
6
|
+
import { TransactionConnection as Ln } from "@effect/sql/SqlClient";
|
|
7
|
+
import { ansi as M } from "@voltro/logger";
|
|
8
|
+
import { SqlClient as Rn } from "@effect/sql";
|
|
9
9
|
//#region src/actorSnapshot.ts
|
|
10
|
-
var
|
|
10
|
+
var zn = (e) => typeof e == "string" && e !== "" ? e : null, Bn = 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 Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = 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: zn(r.kind) ?? n,
|
|
27
|
+
displayName: zn(r.displayName),
|
|
28
|
+
email: zn(r.email)
|
|
29
29
|
};
|
|
30
30
|
} catch {
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
|
-
},
|
|
33
|
+
}, Vn = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqlite", Hn = (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
|
+
}, Un = (e, t, n) => {
|
|
38
|
+
if (!Vn(n) || !t) return e;
|
|
39
|
+
let r = Hn(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 Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = 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
|
+
}, Wn = (e, t, n) => {
|
|
48
|
+
if (!Vn(n) || !t) return e;
|
|
49
|
+
let r = Hn(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 Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
58
58
|
}
|
|
59
59
|
return t ?? e;
|
|
60
60
|
});
|
|
61
|
-
},
|
|
61
|
+
}, Gn = "enc:v1:", Kn = "enc:v2:", qn = (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
|
+
}, Jn = (e) => typeof e == "string" && e.startsWith("enc:v2:"), Yn = class extends Error {
|
|
68
68
|
_tag = "FieldDecryptionError";
|
|
69
69
|
table;
|
|
70
70
|
column;
|
|
@@ -72,7 +72,7 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = 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
|
+
}, Xn = (e) => typeof e == "object" && !!e && e._tag === "FieldDecryptionError", Zn = (e) => typeof e == "string" && (e.startsWith("enc:v1:") || e.startsWith("enc:v2:")), Qn = (e, t, n) => e.encrypt(JSON.stringify(t), n), $n = /* @__PURE__ */ new Set([
|
|
76
76
|
"text",
|
|
77
77
|
"id",
|
|
78
78
|
"reference",
|
|
@@ -80,51 +80,51 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
80
80
|
"uuid",
|
|
81
81
|
"email",
|
|
82
82
|
"url"
|
|
83
|
-
]),
|
|
83
|
+
]), er = (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 || $n.has(n) ? i : a;
|
|
91
|
+
}, tr = (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 || $n.has(n) ? !0 : void 0;
|
|
95
95
|
} catch {
|
|
96
96
|
return !0;
|
|
97
97
|
}
|
|
98
|
-
},
|
|
98
|
+
}, nr = (e, t) => e.fields[t]?.type, rr = (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
|
+
}, ir = "id", ar = (e, t, n, r) => {
|
|
103
103
|
if (!t) return e;
|
|
104
|
-
let i =
|
|
104
|
+
let i = rr(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[ir], s = { ...e };
|
|
107
107
|
for (let e of i) {
|
|
108
108
|
let t = s[e];
|
|
109
|
-
if (!(t == null ||
|
|
109
|
+
if (!(t == null || Zn(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] = Qn(n, t, qn(a, e, o));
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
return s;
|
|
115
|
-
},
|
|
115
|
+
}, or = (e, t, n, r) => {
|
|
116
116
|
if (!t) return e;
|
|
117
|
-
let i =
|
|
117
|
+
let i = rr(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 (Zn(i)) {
|
|
125
125
|
s ??= { ...e };
|
|
126
126
|
try {
|
|
127
|
-
s[c] =
|
|
127
|
+
s[c] = er(n, i, nr(t, c), qn(o, c, r?.rowId ?? e[ir]));
|
|
128
128
|
} catch (e) {
|
|
129
129
|
let t = String(e?.message ?? e);
|
|
130
130
|
if (a === "null") {
|
|
@@ -135,7 +135,7 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
135
135
|
});
|
|
136
136
|
continue;
|
|
137
137
|
}
|
|
138
|
-
throw new
|
|
138
|
+
throw new Yn({
|
|
139
139
|
table: o,
|
|
140
140
|
column: c,
|
|
141
141
|
reason: t
|
|
@@ -145,136 +145,136 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
145
145
|
}
|
|
146
146
|
return s ?? e;
|
|
147
147
|
});
|
|
148
|
-
},
|
|
148
|
+
}, sr = (e) => {
|
|
149
149
|
let t = e;
|
|
150
|
-
for (let e = 0; e < 4 &&
|
|
150
|
+
for (let e = 0; e < 4 && Mn.isFiberFailure(t); e++) t = Dn.squash(t[Mn.FiberFailureCauseId]);
|
|
151
151
|
return t;
|
|
152
|
-
},
|
|
153
|
-
if (t >= 4 || !
|
|
154
|
-
let n = e[
|
|
155
|
-
if (r.length === 0) return [
|
|
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
156
|
let i = [];
|
|
157
|
-
for (let e of r.slice(0, 8)) i.push(...
|
|
157
|
+
for (let e of r.slice(0, 8)) i.push(...cr(e, t + 1));
|
|
158
158
|
return i;
|
|
159
|
-
},
|
|
160
|
-
let t = {}, n = [], r =
|
|
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
161
|
for (let e = 0; e < 8 && typeof r == "object" && r; e++) {
|
|
162
162
|
let e = r;
|
|
163
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
164
|
let i = e.sqlMessage ?? e.detail;
|
|
165
165
|
t.dbMessage === void 0 && typeof i == "string" && (t.dbMessage = i);
|
|
166
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 =
|
|
167
|
+
(o || s) && n.push(`${o || "Error"}${s ? `: ${s.slice(0, 200)}` : ""}`), r = sr(e.cause);
|
|
168
168
|
}
|
|
169
169
|
return n.length > 0 && (t.dbCauseChain = n.join(" ← "), t.dbMessage === void 0 && (t.dbMessage = n[n.length - 1])), t;
|
|
170
|
-
},
|
|
171
|
-
let t =
|
|
170
|
+
}, dr = (e) => {
|
|
171
|
+
let t = cr(e).map(ur);
|
|
172
172
|
if (t.length <= 1) return t[0] ?? {};
|
|
173
|
-
let n = t.find(
|
|
173
|
+
let n = t.find(lr) ?? t[0], r = t.filter((e) => e !== n).map((e) => e.dbCauseChain).filter((e) => typeof e == "string");
|
|
174
174
|
if (r.length === 0) return n;
|
|
175
175
|
let i = typeof n.dbCauseChain == "string" ? n.dbCauseChain : void 0;
|
|
176
176
|
return {
|
|
177
177
|
...n,
|
|
178
178
|
dbCauseChain: [i, ...r].filter(Boolean).join(" ‖ ")
|
|
179
179
|
};
|
|
180
|
-
},
|
|
181
|
-
let n =
|
|
180
|
+
}, fr = (e, t) => {
|
|
181
|
+
let n = dr(e), r = vr(n, t);
|
|
182
182
|
if (r !== void 0) {
|
|
183
183
|
let e = r.constraint ?? r.column;
|
|
184
184
|
return e === void 0 ? r.kind : `${r.kind}: ${e}`;
|
|
185
185
|
}
|
|
186
|
-
let i = n.dbCode ?? n.dbSqlState ?? n.dbErrno ?? n.dbNumber, a =
|
|
187
|
-
return i !== void 0 &&
|
|
188
|
-
},
|
|
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
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 &&
|
|
191
|
-
},
|
|
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
192
|
for (let n of t) {
|
|
193
193
|
let t = n.exec(e);
|
|
194
194
|
if (t?.[1] !== void 0) return t[1];
|
|
195
195
|
}
|
|
196
|
-
},
|
|
196
|
+
}, vr = (e, t) => {
|
|
197
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
198
|
if (n === "23503") {
|
|
199
|
-
let t =
|
|
199
|
+
let t = N(e.dbConstraint);
|
|
200
200
|
return {
|
|
201
201
|
kind: /is still referenced from table/i.test(o) ? "foreignKeyInUse" : "foreignKey",
|
|
202
202
|
...t === void 0 ? {} : { constraint: t }
|
|
203
203
|
};
|
|
204
204
|
}
|
|
205
205
|
if (n === "23505") {
|
|
206
|
-
let t =
|
|
206
|
+
let t = N(e.dbConstraint);
|
|
207
207
|
return {
|
|
208
208
|
kind: "unique",
|
|
209
209
|
...t === void 0 ? {} : { constraint: t }
|
|
210
210
|
};
|
|
211
211
|
}
|
|
212
212
|
if (n === "23502") {
|
|
213
|
-
let t =
|
|
213
|
+
let t = N(e.dbColumn);
|
|
214
214
|
return {
|
|
215
215
|
kind: "notNull",
|
|
216
216
|
...t === void 0 ? {} : { column: t }
|
|
217
217
|
};
|
|
218
218
|
}
|
|
219
219
|
if (n === "23514") {
|
|
220
|
-
let t =
|
|
220
|
+
let t = N(e.dbConstraint);
|
|
221
221
|
return {
|
|
222
222
|
kind: "check",
|
|
223
223
|
...t === void 0 ? {} : { constraint: t }
|
|
224
224
|
};
|
|
225
225
|
}
|
|
226
226
|
if (r === 1452 || r === 1451) {
|
|
227
|
-
let e =
|
|
227
|
+
let e = N(P(o, /CONSTRAINT `([^`]+)`/));
|
|
228
228
|
return {
|
|
229
229
|
kind: r === 1451 ? "foreignKeyInUse" : "foreignKey",
|
|
230
230
|
...e === void 0 ? {} : { constraint: e }
|
|
231
231
|
};
|
|
232
232
|
}
|
|
233
233
|
if (r === 1062) {
|
|
234
|
-
let e =
|
|
234
|
+
let e = N(_r(P(o, /for key '([^']+)'/)));
|
|
235
235
|
return {
|
|
236
236
|
kind: "unique",
|
|
237
237
|
...e === void 0 ? {} : { constraint: e }
|
|
238
238
|
};
|
|
239
239
|
}
|
|
240
240
|
if (r === 1048 || r === 1364) {
|
|
241
|
-
let e =
|
|
241
|
+
let e = N(P(o, /Column '([^']+)' cannot be null/, /Field '([^']+)' doesn't have a default value/));
|
|
242
242
|
return {
|
|
243
243
|
kind: "notNull",
|
|
244
244
|
...e === void 0 ? {} : { column: e }
|
|
245
245
|
};
|
|
246
246
|
}
|
|
247
247
|
if (r === 3819 || r === 4025) {
|
|
248
|
-
let e =
|
|
248
|
+
let e = N(P(o, /Check constraint '([^']+)'/, /CONSTRAINT `([^`]+)` failed/));
|
|
249
249
|
return {
|
|
250
250
|
kind: "check",
|
|
251
251
|
...e === void 0 ? {} : { constraint: e }
|
|
252
252
|
};
|
|
253
253
|
}
|
|
254
254
|
if (i === 547) {
|
|
255
|
-
let e =
|
|
255
|
+
let e = P(o, /(?:FOREIGN KEY|REFERENCE) constraint "([^"]+)"/), t = P(o, /CHECK constraint "([^"]+)"/);
|
|
256
256
|
if (t !== void 0 && e === void 0) {
|
|
257
|
-
let e =
|
|
257
|
+
let e = N(t);
|
|
258
258
|
return {
|
|
259
259
|
kind: "check",
|
|
260
260
|
...e === void 0 ? {} : { constraint: e }
|
|
261
261
|
};
|
|
262
262
|
}
|
|
263
|
-
let n = /REFERENCE constraint/.test(o), r =
|
|
263
|
+
let n = /REFERENCE constraint/.test(o), r = N(e);
|
|
264
264
|
return {
|
|
265
265
|
kind: n ? "foreignKeyInUse" : "foreignKey",
|
|
266
266
|
...r === void 0 ? {} : { constraint: r }
|
|
267
267
|
};
|
|
268
268
|
}
|
|
269
269
|
if (i === 2627 || i === 2601) {
|
|
270
|
-
let e =
|
|
270
|
+
let e = N(P(o, /(?:UNIQUE KEY|PRIMARY KEY) constraint '([^']+)'/, /index '([^']+)'/));
|
|
271
271
|
return {
|
|
272
272
|
kind: "unique",
|
|
273
273
|
...e === void 0 ? {} : { constraint: e }
|
|
274
274
|
};
|
|
275
275
|
}
|
|
276
276
|
if (i === 515) {
|
|
277
|
-
let e =
|
|
277
|
+
let e = N(P(o, /Cannot insert the value NULL into column '([^']+)'/));
|
|
278
278
|
return {
|
|
279
279
|
kind: "notNull",
|
|
280
280
|
...e === void 0 ? {} : { column: e }
|
|
@@ -282,34 +282,34 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
282
282
|
}
|
|
283
283
|
if (n === "SQLITE_CONSTRAINT_FOREIGNKEY") return { kind: t === "delete" || t === "deleteMany" || t === "hardDelete" ? "foreignKeyInUse" : "foreignKey" };
|
|
284
284
|
if (n === "SQLITE_CONSTRAINT_UNIQUE" || n === "SQLITE_CONSTRAINT_PRIMARYKEY") {
|
|
285
|
-
let e =
|
|
285
|
+
let e = N(_r(P(o, /UNIQUE constraint failed: ([^,\s]+)/)));
|
|
286
286
|
return {
|
|
287
287
|
kind: "unique",
|
|
288
288
|
...e === void 0 ? {} : { column: e }
|
|
289
289
|
};
|
|
290
290
|
}
|
|
291
291
|
if (n === "SQLITE_CONSTRAINT_NOTNULL") {
|
|
292
|
-
let e =
|
|
292
|
+
let e = N(_r(P(o, /NOT NULL constraint failed: ([^,\s]+)/)));
|
|
293
293
|
return {
|
|
294
294
|
kind: "notNull",
|
|
295
295
|
...e === void 0 ? {} : { column: e }
|
|
296
296
|
};
|
|
297
297
|
}
|
|
298
298
|
if (n === "SQLITE_CONSTRAINT_CHECK") {
|
|
299
|
-
let e =
|
|
299
|
+
let e = N(P(a, /CHECK constraint failed: (.+)$/));
|
|
300
300
|
return {
|
|
301
301
|
kind: "check",
|
|
302
302
|
...e === void 0 ? {} : { constraint: e }
|
|
303
303
|
};
|
|
304
304
|
}
|
|
305
|
-
},
|
|
306
|
-
let t =
|
|
305
|
+
}, yr = (e) => {
|
|
306
|
+
let t = vr(e)?.kind;
|
|
307
307
|
return t === "foreignKey" || t === "foreignKeyInUse";
|
|
308
|
-
},
|
|
308
|
+
}, br = (e) => {
|
|
309
309
|
let t = e.dbCode, n = e.dbErrno;
|
|
310
310
|
return t === "57014" || n === 3024 || n === 1969 || t === "ETIMEOUT" || t === "SQLITE_INTERRUPT";
|
|
311
|
-
},
|
|
312
|
-
let t =
|
|
311
|
+
}, xr = (e) => {
|
|
312
|
+
let t = dr(e), n = [
|
|
313
313
|
t.dbCode === void 0 ? void 0 : `code=${String(t.dbCode)}`,
|
|
314
314
|
t.dbErrno === void 0 ? void 0 : `errno=${String(t.dbErrno)}`,
|
|
315
315
|
t.dbNumber === void 0 ? void 0 : `number=${String(t.dbNumber)}`,
|
|
@@ -318,7 +318,7 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
318
318
|
t.dbPlaceholders === void 0 ? void 0 : `placeholders=${String(t.dbPlaceholders)}`
|
|
319
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
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
|
-
},
|
|
321
|
+
}, Sr = (e) => Object.entries(e).map(([e, t]) => `${e}:${Cr(t)}`).join(" "), Cr = (e) => {
|
|
322
322
|
if (e === null) return "null";
|
|
323
323
|
if (e === void 0) return "undefined";
|
|
324
324
|
if (typeof e == "bigint") return "bigint";
|
|
@@ -328,77 +328,77 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
328
328
|
if (globalThis.Buffer !== void 0 && globalThis.Buffer.isBuffer(e)) return "Buffer";
|
|
329
329
|
let t = e.constructor?.name;
|
|
330
330
|
return typeof t == "string" && t !== "" ? t : "Object";
|
|
331
|
-
},
|
|
331
|
+
}, wr = Symbol.for("@voltro/database/storeRefusal"), Tr = (e) => {
|
|
332
332
|
let t = Error(e.detail);
|
|
333
|
-
return Object.defineProperty(t,
|
|
333
|
+
return Object.defineProperty(t, wr, {
|
|
334
334
|
value: e,
|
|
335
335
|
enumerable: !1
|
|
336
336
|
}), t;
|
|
337
|
-
},
|
|
338
|
-
for (let t of
|
|
337
|
+
}, Er = (e) => {
|
|
338
|
+
for (let t of cr(e)) {
|
|
339
339
|
let e = t;
|
|
340
340
|
for (let t = 0; e != null && t < 8; t += 1) {
|
|
341
|
-
let t = e[
|
|
341
|
+
let t = e[wr];
|
|
342
342
|
if (t !== void 0) return t;
|
|
343
343
|
e = e.cause;
|
|
344
344
|
}
|
|
345
345
|
}
|
|
346
|
-
},
|
|
346
|
+
}, Dr = (e) => {
|
|
347
347
|
let t = (() => {
|
|
348
348
|
switch (e.type) {
|
|
349
|
-
case "id": return e.idScheme?.kind === "numeric" ?
|
|
349
|
+
case "id": return e.idScheme?.kind === "numeric" ? j.Number : j.String;
|
|
350
350
|
case "text":
|
|
351
|
-
case "enum": return
|
|
352
|
-
case "reference": return e.referenceStorage === "numeric" ?
|
|
351
|
+
case "enum": return j.String;
|
|
352
|
+
case "reference": return e.referenceStorage === "numeric" ? j.Number : j.String;
|
|
353
353
|
case "integer":
|
|
354
354
|
case "real":
|
|
355
|
-
case "decimal": return
|
|
356
|
-
case "boolean": return
|
|
355
|
+
case "decimal": return j.Number;
|
|
356
|
+
case "boolean": return j.Boolean;
|
|
357
357
|
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
|
|
358
|
+
case "date": return En;
|
|
359
|
+
case "bigint": return j.BigInt;
|
|
360
|
+
case "bytes": return j.Uint8ArrayFromBase64;
|
|
361
|
+
case "array": return j.Array(j.Unknown);
|
|
362
|
+
case "interval": return j.String;
|
|
363
|
+
default: return j.Unknown;
|
|
364
364
|
}
|
|
365
365
|
})();
|
|
366
|
-
return e.nullable === !0 ?
|
|
367
|
-
},
|
|
366
|
+
return e.nullable === !0 ? j.NullOr(t) : t;
|
|
367
|
+
}, Or = (e, t) => {
|
|
368
368
|
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
|
-
},
|
|
369
|
+
for (let [t, i] of Object.entries(e.fields)) n.has(t) || (r[t] = Dr(i));
|
|
370
|
+
return j.Struct(r);
|
|
371
|
+
}, kr = (e) => typeof e == "function" ? e : () => e, Ar = (e, t) => ({
|
|
372
372
|
kind: "one",
|
|
373
|
-
target:
|
|
373
|
+
target: kr(e),
|
|
374
374
|
...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
|
|
375
375
|
...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
|
|
376
|
-
}),
|
|
376
|
+
}), jr = (e, t) => ({
|
|
377
377
|
kind: "many",
|
|
378
|
-
target:
|
|
378
|
+
target: kr(e),
|
|
379
379
|
...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
|
|
380
380
|
...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
|
|
381
|
-
}),
|
|
381
|
+
}), Mr = (e, t) => ({
|
|
382
382
|
kind: "manyToMany",
|
|
383
|
-
target:
|
|
384
|
-
through:
|
|
383
|
+
target: kr(e),
|
|
384
|
+
through: kr(t.through),
|
|
385
385
|
sourceKey: t.sourceKey,
|
|
386
386
|
targetKey: t.targetKey
|
|
387
|
-
}),
|
|
388
|
-
one:
|
|
389
|
-
many:
|
|
390
|
-
manyToMany:
|
|
391
|
-
},
|
|
387
|
+
}), Nr = {
|
|
388
|
+
one: Ar,
|
|
389
|
+
many: jr,
|
|
390
|
+
manyToMany: Mr
|
|
391
|
+
}, Pr = (e, t) => {
|
|
392
392
|
let n = typeof e == "function" ? e : () => e;
|
|
393
393
|
return {
|
|
394
394
|
source: n,
|
|
395
|
-
relations: t(
|
|
395
|
+
relations: t(Nr, n())
|
|
396
396
|
};
|
|
397
|
-
},
|
|
397
|
+
}, Fr = (e) => {
|
|
398
398
|
if (typeof e != "object" || !e) return !1;
|
|
399
399
|
let t = e;
|
|
400
400
|
return typeof t.source != "function" || typeof t.relations != "object" || t.relations === null ? !1 : Object.keys(t.relations).length === 0;
|
|
401
|
-
},
|
|
401
|
+
}, Ir = (e) => {
|
|
402
402
|
if (typeof e != "object" || !e) return !1;
|
|
403
403
|
let t = e;
|
|
404
404
|
if (typeof t.source != "function" || typeof t.relations != "object" || t.relations === null) return !1;
|
|
@@ -407,35 +407,35 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
407
407
|
let t = e?.kind;
|
|
408
408
|
return t === "one" || t === "many" || t === "manyToMany";
|
|
409
409
|
});
|
|
410
|
-
},
|
|
410
|
+
}, Lr = Ar, Rr = jr, zr = Mr, Br = (e, t, n) => {
|
|
411
411
|
let r = [];
|
|
412
412
|
for (let [n, i] of Object.entries(e.fields)) i.type === "reference" && i.references?.()?.tableName === t && r.push(n);
|
|
413
413
|
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>' }.`);
|
|
414
414
|
if (r.length > 1) throw Error(`relation '${n}': multiple reference() columns on '${e.tableName}' point at '${t}' (${r.join(", ")}). Pass an explicit { foreignKey: '<column>' } to disambiguate.`);
|
|
415
415
|
return r[0];
|
|
416
|
-
},
|
|
417
|
-
let t =
|
|
416
|
+
}, Vr = (e) => Object.keys(e.fields), Hr = (e, t) => Object.prototype.hasOwnProperty.call(e.fields, t), Ur = (e) => {
|
|
417
|
+
let t = Vr(e);
|
|
418
418
|
return t.length === 0 ? "<none>" : t.join(", ");
|
|
419
|
-
},
|
|
419
|
+
}, Wr = (e, t, n) => {
|
|
420
420
|
let r = `relation '${t}' on '${e.tableName}'`, i = n.target();
|
|
421
421
|
if (n.kind === "manyToMany") {
|
|
422
422
|
let t = n.through();
|
|
423
|
-
for (let [a, o] of [["sourceKey", n.sourceKey], ["targetKey", n.targetKey]]) if (!
|
|
423
|
+
for (let [a, o] of [["sourceKey", n.sourceKey], ["targetKey", n.targetKey]]) if (!Hr(t, o)) throw Error(`${r}: manyToMany ${a} '${o}' is not a column on the junction table '${t.tableName}'. Both keys name columns on the JUNCTION — ${a === "sourceKey" ? `sourceKey points at '${e.tableName}'` : `targetKey points at '${i.tableName}'`}. Columns on '${t.tableName}': ${Ur(t)}.`);
|
|
424
424
|
return;
|
|
425
425
|
}
|
|
426
426
|
if (n.sourceKey !== void 0 && n.foreignKey !== void 0) throw Error(`${r}: pass EITHER sourceKey OR foreignKey, not both. sourceKey '${n.sourceKey}' names a column on the source ('${e.tableName}') holding the target's id; foreignKey '${n.foreignKey}' names a column on the target ('${i.tableName}') holding the source's id. With both, foreignKey is ignored.`);
|
|
427
|
-
if (n.sourceKey !== void 0 && !
|
|
428
|
-
let t =
|
|
429
|
-
throw Error(`${r}: sourceKey '${n.sourceKey}' is not a column on the source table '${e.tableName}'.` + (t ? ` It IS a column on the target '${i.tableName}' — you probably want { foreignKey: '${n.sourceKey}' }, which names the column on the TARGET that holds this table's id.` : ` Columns on '${e.tableName}': ${
|
|
427
|
+
if (n.sourceKey !== void 0 && !Hr(e, n.sourceKey)) {
|
|
428
|
+
let t = Hr(i, n.sourceKey);
|
|
429
|
+
throw Error(`${r}: sourceKey '${n.sourceKey}' is not a column on the source table '${e.tableName}'.` + (t ? ` It IS a column on the target '${i.tableName}' — you probably want { foreignKey: '${n.sourceKey}' }, which names the column on the TARGET that holds this table's id.` : ` Columns on '${e.tableName}': ${Ur(e)}.`));
|
|
430
430
|
}
|
|
431
|
-
if (n.foreignKey !== void 0 && !
|
|
432
|
-
let t =
|
|
433
|
-
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}': ${
|
|
431
|
+
if (n.foreignKey !== void 0 && !Hr(i, n.foreignKey)) {
|
|
432
|
+
let t = Hr(e, n.foreignKey);
|
|
433
|
+
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
434
|
}
|
|
435
|
-
},
|
|
436
|
-
let t = e.source(), n =
|
|
435
|
+
}, Gr = Symbol.for("@voltro/database/relationsRegistry"), Kr = globalThis, F = Kr[Gr] ?? (Kr[Gr] = /* @__PURE__ */ new Map()), qr = (e) => {
|
|
436
|
+
let t = e.source(), n = F.get(t.tableName);
|
|
437
437
|
if (n === void 0) {
|
|
438
|
-
|
|
438
|
+
F.set(t.tableName, new Map(Object.entries(e.relations)));
|
|
439
439
|
return;
|
|
440
440
|
}
|
|
441
441
|
for (let [r, i] of Object.entries(e.relations)) {
|
|
@@ -445,33 +445,33 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
445
445
|
n.set(r, i);
|
|
446
446
|
}
|
|
447
447
|
}
|
|
448
|
-
},
|
|
448
|
+
}, Jr = (e) => {
|
|
449
449
|
let t = 0;
|
|
450
|
-
for (let n of Object.values(e))
|
|
450
|
+
for (let n of Object.values(e)) Ir(n) && (qr(n), t += 1);
|
|
451
451
|
return t;
|
|
452
|
-
},
|
|
453
|
-
let t =
|
|
452
|
+
}, Yr = (e) => {
|
|
453
|
+
let t = F.get(e);
|
|
454
454
|
if (t !== void 0) return Object.fromEntries(t);
|
|
455
|
-
},
|
|
455
|
+
}, Xr = (e, t) => F.get(e)?.get(t), Zr = () => {
|
|
456
456
|
let e = [];
|
|
457
|
-
for (let [t, n] of
|
|
457
|
+
for (let [t, n] of F) for (let [r, i] of n) e.push({
|
|
458
458
|
source: t,
|
|
459
459
|
name: r,
|
|
460
460
|
relation: i
|
|
461
461
|
});
|
|
462
462
|
return e;
|
|
463
|
-
},
|
|
464
|
-
for (let [e, t] of
|
|
465
|
-
let n =
|
|
466
|
-
if (n !== void 0) for (let [e, r] of t)
|
|
467
|
-
}
|
|
468
|
-
},
|
|
469
|
-
|
|
470
|
-
},
|
|
463
|
+
}, Qr = () => {
|
|
464
|
+
for (let [e, t] of F) {
|
|
465
|
+
let n = de(e);
|
|
466
|
+
if (n !== void 0) for (let [e, r] of t) Wr(n, e, r);
|
|
467
|
+
}
|
|
468
|
+
}, $r = () => {
|
|
469
|
+
F.clear();
|
|
470
|
+
}, ei = 4, ti = (e) => Object.keys(e.fields), ni = (e, t) => Object.prototype.hasOwnProperty.call(e.fields, t), ri = (e, t) => {
|
|
471
471
|
let n = [];
|
|
472
472
|
for (let [r, i] of Object.entries(e.fields)) i.type === "reference" && i.references?.()?.tableName === t && n.push(r);
|
|
473
473
|
return n;
|
|
474
|
-
},
|
|
474
|
+
}, ii = (e, t) => {
|
|
475
475
|
let n = [];
|
|
476
476
|
for (let r of t) {
|
|
477
477
|
if (r.source !== e) continue;
|
|
@@ -488,7 +488,7 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
488
488
|
} catch {
|
|
489
489
|
continue;
|
|
490
490
|
}
|
|
491
|
-
if (!
|
|
491
|
+
if (!ni(e, t.sourceKey)) continue;
|
|
492
492
|
n.push({
|
|
493
493
|
table: e.tableName,
|
|
494
494
|
foreignKey: t.sourceKey,
|
|
@@ -497,8 +497,8 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
497
497
|
continue;
|
|
498
498
|
}
|
|
499
499
|
if (t.sourceKey !== void 0) continue;
|
|
500
|
-
let a =
|
|
501
|
-
if (o === void 0 || !
|
|
500
|
+
let a = ri(i, e), o = t.foreignKey ?? (a.length === 1 ? a[0] : void 0);
|
|
501
|
+
if (o === void 0 || !ni(i, o)) continue;
|
|
502
502
|
let s = i.fields[o];
|
|
503
503
|
n.push({
|
|
504
504
|
table: i.tableName,
|
|
@@ -507,9 +507,9 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
507
507
|
});
|
|
508
508
|
}
|
|
509
509
|
return n;
|
|
510
|
-
},
|
|
510
|
+
}, ai = (e, t) => {
|
|
511
511
|
let n = [];
|
|
512
|
-
for (let r of t) if (r.tableName !== e) for (let t of
|
|
512
|
+
for (let r of t) if (r.tableName !== e) for (let t of ri(r, e)) {
|
|
513
513
|
let e = r.fields[t];
|
|
514
514
|
n.push({
|
|
515
515
|
table: r.tableName,
|
|
@@ -518,8 +518,8 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
518
518
|
});
|
|
519
519
|
}
|
|
520
520
|
return n;
|
|
521
|
-
},
|
|
522
|
-
let t = e.tables ??
|
|
521
|
+
}, oi = (e) => `${e.table}\u0000${e.hops.map((e) => `${e.table}.${e.foreignKey}<-${e.parentKey}`).join("|")}`, si = (e) => {
|
|
522
|
+
let t = e.tables ?? xe(), n = e.relations ?? Zr(), r = e.maxDepth ?? 4, i = new Set(e.exclude ?? []), a = new Map(t.map((e) => [e.tableName, e])), o = [];
|
|
523
523
|
if (!a.has(e.subjectTable)) return {
|
|
524
524
|
subjectTable: e.subjectTable,
|
|
525
525
|
paths: [],
|
|
@@ -534,11 +534,11 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
534
534
|
hops: [],
|
|
535
535
|
depth: 0,
|
|
536
536
|
via: "relation"
|
|
537
|
-
}, c = [s], l = /* @__PURE__ */ new Set([
|
|
537
|
+
}, c = [s], l = /* @__PURE__ */ new Set([oi(s)]), u = /* @__PURE__ */ new Set(), d = [s];
|
|
538
538
|
for (let e = 1; e <= r; e++) {
|
|
539
539
|
let r = [];
|
|
540
540
|
for (let a of d) {
|
|
541
|
-
let s =
|
|
541
|
+
let s = ii(a.table, n), d = ai(a.table, t), f = [...s.map((e) => [e, "relation"]), ...d.map((e) => [e, "reference"])];
|
|
542
542
|
for (let [t, n] of f) {
|
|
543
543
|
if (i.has(t.table)) {
|
|
544
544
|
o.push({
|
|
@@ -556,7 +556,7 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
556
556
|
hops: [...a.hops, t],
|
|
557
557
|
depth: e,
|
|
558
558
|
via: n
|
|
559
|
-
}, f =
|
|
559
|
+
}, f = oi(d);
|
|
560
560
|
l.has(f) || (l.add(f), c.push(d), r.push(d));
|
|
561
561
|
}
|
|
562
562
|
}
|
|
@@ -566,7 +566,7 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
566
566
|
}
|
|
567
567
|
d = r;
|
|
568
568
|
}
|
|
569
|
-
for (let e of d) (
|
|
569
|
+
for (let e of d) (ii(e.table, n).length > 0 || ai(e.table, t).length > 0) && o.push({
|
|
570
570
|
kind: "depth-truncated",
|
|
571
571
|
table: e.table,
|
|
572
572
|
detail: `stopped at maxDepth ${r}; tables linked FROM '${e.table}' were not explored`
|
|
@@ -575,14 +575,14 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
575
575
|
for (let n of t) f.has(n.tableName) || i.has(n.tableName) || o.push({
|
|
576
576
|
kind: "unreachable",
|
|
577
577
|
table: n.tableName,
|
|
578
|
-
detail: `no relation() and no reference() column links '${n.tableName}' to '${e.subjectTable}'. If it holds subject data through a plain column, a polymorphic (type,id) pair, JSON or free text, add an explicit subjectScopes entry — this derivation cannot see it. Columns: ${
|
|
578
|
+
detail: `no relation() and no reference() column links '${n.tableName}' to '${e.subjectTable}'. If it holds subject data through a plain column, a polymorphic (type,id) pair, JSON or free text, add an explicit subjectScopes entry — this derivation cannot see it. Columns: ${ti(n).join(", ")}`
|
|
579
579
|
});
|
|
580
580
|
return {
|
|
581
581
|
subjectTable: e.subjectTable,
|
|
582
582
|
paths: c,
|
|
583
583
|
limitations: o
|
|
584
584
|
};
|
|
585
|
-
},
|
|
585
|
+
}, ci = (e) => {
|
|
586
586
|
let t = [`subject graph · ${e.subjectTable} · ${e.paths.length} table(s) reachable`];
|
|
587
587
|
for (let n of e.paths) {
|
|
588
588
|
let r = n.hops.length === 0 ? `${e.subjectTable} (the subject row itself)` : [e.subjectTable, ...n.hops.map((e) => `${e.table}.${e.foreignKey}`)].join(" → ");
|
|
@@ -590,78 +590,12 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
590
590
|
}
|
|
591
591
|
let n = e.limitations.filter((e) => e.kind === "depth-truncated"), r = e.limitations.filter((e) => e.kind === "unreachable"), i = e.limitations.filter((e) => e.kind === "excluded");
|
|
592
592
|
return t.push(""), t.push(" WHAT THIS CANNOT SEE — a DSAR is only as complete as this list is short:"), n.length > 0 && t.push(` depth-truncated (${n.length}): ${n.map((e) => e.table).join(", ")}`), i.length > 0 && t.push(` excluded (${i.length}): ${[...new Set(i.map((e) => e.table))].join(", ")}`), t.push(r.length === 0 ? " unreachable: none — every registered table is linked to the subject." : ` unreachable (${r.length}): ${r.map((e) => e.table).join(", ")}`), t.push(" Always outside this graph: object storage / uploaded files, external processors,"), t.push(" log and metric sinks, backups, and any subject id embedded in JSON or free text."), t.join("\n");
|
|
593
|
-
},
|
|
594
|
-
if (e == null || typeof e != "string") return e;
|
|
595
|
-
let t = e.trim();
|
|
596
|
-
if (t.length === 0) return e;
|
|
597
|
-
let n = t.charAt(0);
|
|
598
|
-
if (n !== "{" && n !== "[" && n !== "\"" && n !== "t" && n !== "f" && n !== "n" && (n < "0" || n > "9") && n !== "-") return e;
|
|
599
|
-
try {
|
|
600
|
-
return JSON.parse(t);
|
|
601
|
-
} catch {
|
|
602
|
-
return e;
|
|
603
|
-
}
|
|
604
|
-
}, Cr = (e) => e == null || typeof e == "string" ? e : typeof e == "number" || typeof e == "bigint" ? String(e) : e, wr = (e) => {
|
|
605
|
-
if (e == null || e instanceof Date) return e;
|
|
606
|
-
if (typeof e == "string") {
|
|
607
|
-
let t = new Date(e);
|
|
608
|
-
return isNaN(t.getTime()) ? e : t;
|
|
609
|
-
}
|
|
610
|
-
if (typeof e == "number") {
|
|
611
|
-
let t = new Date(e);
|
|
612
|
-
return isNaN(t.getTime()) ? e : t;
|
|
613
|
-
}
|
|
614
|
-
return e;
|
|
615
|
-
}, Tr = (e, t, n) => {
|
|
616
|
-
if (e == null) return e;
|
|
617
|
-
switch (t) {
|
|
618
|
-
case "boolean": return n === "postgres" ? e : xr(e);
|
|
619
|
-
case "vector": return n === "postgres" ? Sr(e) : e;
|
|
620
|
-
case "json": return n === "postgres" || n === "mysql" || n === "mariadb" ? e : Sr(e);
|
|
621
|
-
case "array": return n === "postgres" ? e : Sr(e);
|
|
622
|
-
case "timestamp":
|
|
623
|
-
case "date": return n === "sqlite" || n === "turso" ? wr(e) : e;
|
|
624
|
-
case "decimal":
|
|
625
|
-
case "bigint": return Cr(e);
|
|
626
|
-
default: return e;
|
|
627
|
-
}
|
|
628
|
-
}, Er = (e, t, n) => {
|
|
629
|
-
if (e.length === 0) return e;
|
|
630
|
-
let r = w(t);
|
|
631
|
-
if (r === void 0) return e;
|
|
632
|
-
let i = r.fields, a = [];
|
|
633
|
-
for (let [e, t] of Object.entries(i)) a.push({
|
|
634
|
-
key: e,
|
|
635
|
-
type: t.type
|
|
636
|
-
});
|
|
637
|
-
return e.map((e) => {
|
|
638
|
-
let t = { ...e };
|
|
639
|
-
for (let { key: e, type: r } of a) e in t && (t[e] = Tr(t[e], r, n));
|
|
640
|
-
return t;
|
|
641
|
-
});
|
|
642
|
-
}, Dr = (e, t) => {
|
|
643
|
-
if (e == null) return e;
|
|
644
|
-
switch (t) {
|
|
645
|
-
case "json": return JSON.stringify(e);
|
|
646
|
-
case "array":
|
|
647
|
-
case "vector": return typeof e == "string" ? e : JSON.stringify(e);
|
|
648
|
-
default: return e;
|
|
649
|
-
}
|
|
650
|
-
}, Or = (e, t, n = ["json", "array"]) => {
|
|
651
|
-
let r = w(t);
|
|
652
|
-
if (r === void 0) return e;
|
|
653
|
-
let i = r.fields, a = null;
|
|
654
|
-
for (let [t, r] of Object.entries(i)) if (n.includes(r.type) && t in e) {
|
|
655
|
-
let n = Dr(e[t], r.type);
|
|
656
|
-
n !== e[t] && (a === null && (a = { ...e }), a[t] = n);
|
|
657
|
-
}
|
|
658
|
-
return a ?? e;
|
|
659
|
-
}, kr = (e) => Object.fromEntries(Object.entries(e.updateValues ?? {}).filter(([t, n]) => {
|
|
593
|
+
}, li = (e) => Object.fromEntries(Object.entries(e.updateValues ?? {}).filter(([t, n]) => {
|
|
660
594
|
if (n === void 0) return !1;
|
|
661
595
|
if (t === "id" || e.conflictColumns.includes(t)) throw Error(`upsert: updateValues cannot rewrite row identity column '${t}'`);
|
|
662
596
|
return !0;
|
|
663
|
-
})),
|
|
664
|
-
let r =
|
|
597
|
+
})), ui = (e, t, n) => {
|
|
598
|
+
let r = li(n);
|
|
665
599
|
if (typeof n.update == "function") return {
|
|
666
600
|
...n.update(t),
|
|
667
601
|
...r
|
|
@@ -671,21 +605,21 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
671
605
|
...Object.fromEntries(i.filter((t) => t in e).map((t) => [t, e[t]])),
|
|
672
606
|
...r
|
|
673
607
|
};
|
|
674
|
-
},
|
|
608
|
+
}, di = (e) => typeof e == "string" ? [["id", e]] : Object.entries(e).map(([e, t]) => [e, t]), fi = (e) => {
|
|
675
609
|
if (typeof e == "string") return e;
|
|
676
610
|
let t = Object.entries(e);
|
|
677
611
|
return t.length === 1 ? String(t[0][1]) : t.slice().sort(([e], [t]) => e < t ? -1 : +(e > t)).map(([e, t]) => `${e}=${String(t)}`).join("\0");
|
|
678
|
-
},
|
|
679
|
-
let r = new Set(
|
|
612
|
+
}, pi = (e) => typeof e != "string", mi = (e, t, n) => {
|
|
613
|
+
let r = new Set(di(e).map(([e]) => e)), i = t.split(".")[0];
|
|
680
614
|
return Object.fromEntries(Object.entries(n ?? {}).filter(([e, t]) => {
|
|
681
615
|
if (t === void 0) return !1;
|
|
682
616
|
if (r.has(e) || e === i) throw Error(`patchJson: additionalPatch cannot rewrite the primary key or patched JSON column '${e}'`);
|
|
683
617
|
return !0;
|
|
684
618
|
}));
|
|
685
|
-
},
|
|
686
|
-
let [r, ...i] = t.split("."), a =
|
|
619
|
+
}, hi = (e) => typeof e == "object" && !!e && !Array.isArray(e), gi = (e) => JSON.parse(JSON.stringify(e ?? null)), _i = (e, t, n) => {
|
|
620
|
+
let [r, ...i] = t.split("."), a = gi(n), o = e[r], s = (e, t) => {
|
|
687
621
|
if (t === i.length) return a;
|
|
688
|
-
let n =
|
|
622
|
+
let n = hi(e) ? e : {}, r = i[t], o = Object.hasOwn(n, r) ? n[r] : void 0;
|
|
689
623
|
return {
|
|
690
624
|
...n,
|
|
691
625
|
[r]: s(o, t + 1)
|
|
@@ -693,14 +627,14 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
693
627
|
};
|
|
694
628
|
return {
|
|
695
629
|
...e,
|
|
696
|
-
[r]: i.length === 0 ?
|
|
630
|
+
[r]: i.length === 0 ? hi(o) && hi(a) ? {
|
|
697
631
|
...o,
|
|
698
632
|
...a
|
|
699
633
|
} : a : s(o, 0)
|
|
700
634
|
};
|
|
701
|
-
},
|
|
702
|
-
let [a, ...o] = n.split("."), s = i ?? e`${e(a)}`, c =
|
|
703
|
-
if ((t === "sqlite" || t === "turso") && (o.some(l) || o.length === 0 &&
|
|
635
|
+
}, vi = (e, t, n, r, i) => {
|
|
636
|
+
let [a, ...o] = n.split("."), s = i ?? e`${e(a)}`, c = gi(r), l = (e) => /["\\\u0000-\u001f]/.test(e);
|
|
637
|
+
if ((t === "sqlite" || t === "turso") && (o.some(l) || o.length === 0 && hi(c) && Object.keys(c).some(l))) {
|
|
704
638
|
let t = 0, n = (t) => e`CASE WHEN (SELECT _voltro_json_escape_probe.key FROM json_each(${String.raw`{"\u0061":0}`}) AS _voltro_json_escape_probe) = ${String.raw`\u0061`}
|
|
705
639
|
THEN json_extract('"' || replace(${t}.key, '"', ${String.raw`\"`}) || '"', '$')
|
|
706
640
|
ELSE ${t}.key END`, r = (r) => {
|
|
@@ -742,7 +676,7 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
742
676
|
return t === "mysql" || t === "mariadb" ? e`JSON_SET(${n}, ${o}, JSON_EXTRACT(${i}, '$'))` : t === "mssql" ? a === null ? e`JSON_MODIFY(JSON_MODIFY(${n}, ${o}, 0), ${`strict ${o}`}, NULL)` : typeof a == "boolean" ? e`JSON_MODIFY(${n}, ${o}, CAST(${+!!a} AS bit))` : typeof a == "string" || typeof a == "number" ? e`JSON_MODIFY(${n}, ${o}, ${a})` : e`JSON_MODIFY(${n}, ${o}, JSON_QUERY(${i}))` : e`json_set(${n}, ${o}, json(${i}))`;
|
|
743
677
|
}, v;
|
|
744
678
|
if (o.length === 0) {
|
|
745
|
-
if (!
|
|
679
|
+
if (!hi(c)) v = g(c);
|
|
746
680
|
else {
|
|
747
681
|
v = h([]);
|
|
748
682
|
for (let [e, t] of Object.entries(c)) v = _(v, [e], g(t), t);
|
|
@@ -756,17 +690,17 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
756
690
|
v = _(v, o, g(c), c);
|
|
757
691
|
}
|
|
758
692
|
return e`${e(a)} = ${v}`;
|
|
759
|
-
},
|
|
693
|
+
}, yi = class extends Error {
|
|
760
694
|
_tag = "EagerCardinalityError";
|
|
761
695
|
constructor(e) {
|
|
762
696
|
super(e), this.name = "EagerCardinalityError";
|
|
763
697
|
}
|
|
764
|
-
},
|
|
698
|
+
}, bi = (e) => {
|
|
765
699
|
let { relationName: t, sourceTableName: n, targetTableName: r, foreignKey: i, sourceKey: a } = e, o = r === n;
|
|
766
700
|
return `relation '${t}' on '${n}' is declared \`one\`, but ${r}.${i} matches MORE than one row for the same ${n}.${a} — so there is no single related row to return.` + (o ? ` Because this relation is self-referential, check which side the key is on: \`foreignKey: '${i}'\` means "rows whose ${i} points AT me" (my children — there can be many). If you meant "the row my ${i} points to" (my parent), that is \`sourceKey: '${i}'\`.` : " Use `many(...)` if several are expected, or narrow the key.");
|
|
767
|
-
},
|
|
701
|
+
}, xi = async (e, t, n, r) => {
|
|
768
702
|
if (e.length === 0) return e;
|
|
769
|
-
let i =
|
|
703
|
+
let i = Yr(n.tableName);
|
|
770
704
|
if (i === void 0) throw Error(`cannot eager-load on '${n.tableName}': no relations registered. Did you forget to declare \`relations(${n.tableName}, ...)\` or import the file that does?`);
|
|
771
705
|
let a = e.map((e) => ({ ...e }));
|
|
772
706
|
for (let [e, o] of Object.entries(t)) {
|
|
@@ -775,36 +709,36 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
775
709
|
let t = Object.keys(i).join(", ") || "<none>";
|
|
776
710
|
throw Error(`unknown relation '${e}' on '${n.tableName}'. Registered relations: ${t}.`);
|
|
777
711
|
}
|
|
778
|
-
|
|
712
|
+
Wr(n, e, t), await Si(a, e, t, o === !0 ? {} : o, n, r);
|
|
779
713
|
}
|
|
780
714
|
return a;
|
|
781
|
-
},
|
|
715
|
+
}, Si = async (e, t, n, r, i, a) => {
|
|
782
716
|
switch (n.kind) {
|
|
783
717
|
case "one":
|
|
784
|
-
await
|
|
718
|
+
await Ci(e, t, n, r, i, a);
|
|
785
719
|
return;
|
|
786
720
|
case "many":
|
|
787
|
-
await
|
|
721
|
+
await wi(e, t, n, r, i, a);
|
|
788
722
|
return;
|
|
789
723
|
case "manyToMany":
|
|
790
|
-
await
|
|
724
|
+
await Ei(e, t, n, r, i, a);
|
|
791
725
|
return;
|
|
792
726
|
}
|
|
793
|
-
},
|
|
794
|
-
let o = n.target(), s = n.sourceKey ??
|
|
727
|
+
}, Ci = async (e, t, n, r, i, a) => {
|
|
728
|
+
let o = n.target(), s = n.sourceKey ?? Di(i, o.tableName);
|
|
795
729
|
if (s !== void 0) {
|
|
796
|
-
let n =
|
|
730
|
+
let n = Oi(e, s), i = n.length === 0 ? [] : await ki(o, "id", n, r, a), c = new Map(i.map((e) => [e.id, e]));
|
|
797
731
|
for (let n of e) {
|
|
798
732
|
let e = n[s];
|
|
799
733
|
n[t] = e == null ? null : c.get(e) ?? null;
|
|
800
734
|
}
|
|
801
|
-
await
|
|
735
|
+
await Ai(i, r.with, o, a);
|
|
802
736
|
return;
|
|
803
737
|
}
|
|
804
|
-
let c = n.foreignKey ??
|
|
738
|
+
let c = n.foreignKey ?? Br(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();
|
|
805
739
|
for (let e of d) {
|
|
806
740
|
let n = e[c];
|
|
807
|
-
if (f.has(n)) throw new
|
|
741
|
+
if (f.has(n)) throw new yi(bi({
|
|
808
742
|
relationName: t,
|
|
809
743
|
sourceTableName: i.tableName,
|
|
810
744
|
targetTableName: o.tableName,
|
|
@@ -817,9 +751,9 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
817
751
|
let e = n[l];
|
|
818
752
|
n[t] = e == null ? null : f.get(e) ?? null;
|
|
819
753
|
}
|
|
820
|
-
await
|
|
821
|
-
},
|
|
822
|
-
let o = n.target(), s = n.foreignKey ??
|
|
754
|
+
await Ai(d, r.with, o, a);
|
|
755
|
+
}, wi = async (e, t, n, r, i, a) => {
|
|
756
|
+
let o = n.target(), s = n.foreignKey ?? Br(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();
|
|
823
757
|
for (let e of d) {
|
|
824
758
|
let t = e[s], n = f.get(t);
|
|
825
759
|
n ? n.push(e) : f.set(t, [e]);
|
|
@@ -835,12 +769,12 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
835
769
|
let e = n[c];
|
|
836
770
|
n[t] = f.get(e) ?? [];
|
|
837
771
|
}
|
|
838
|
-
await
|
|
839
|
-
},
|
|
772
|
+
await Ai(d, r.with, o, a);
|
|
773
|
+
}, Ti = (e) => {
|
|
840
774
|
let { limit: t, offset: n, ...r } = e;
|
|
841
775
|
return r;
|
|
842
|
-
},
|
|
843
|
-
let o = n.target(), s = n.through(), c =
|
|
776
|
+
}, Ei = async (e, t, n, r, i, a) => {
|
|
777
|
+
let o = n.target(), s = n.through(), c = Oi(e, "id");
|
|
844
778
|
if (c.length === 0) {
|
|
845
779
|
for (let n of e) n[t] = [];
|
|
846
780
|
return;
|
|
@@ -861,8 +795,8 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
861
795
|
for (let n of e) n[t] = [];
|
|
862
796
|
return;
|
|
863
797
|
}
|
|
864
|
-
let f = await
|
|
865
|
-
await
|
|
798
|
+
let f = await ki(o, "id", Oi(d, n.targetKey), r, a), p = new Map(f.map((e) => [e.id, e]));
|
|
799
|
+
await Ai(f, r.with, o, a);
|
|
866
800
|
let m = r.junction === void 0 ? void 0 : r.junction === !0 ? Object.keys(s.fields) : r.junction, h = /* @__PURE__ */ new Map();
|
|
867
801
|
for (let e of d) {
|
|
868
802
|
let t = e[n.sourceKey], r = e[n.targetKey], i = p.get(r);
|
|
@@ -874,16 +808,16 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
874
808
|
o ? o.push(a) : h.set(t, [a]);
|
|
875
809
|
}
|
|
876
810
|
for (let n of e) n[t] = h.get(n.id) ?? [];
|
|
877
|
-
},
|
|
811
|
+
}, Di = (e, t) => {
|
|
878
812
|
for (let [n, r] of Object.entries(e.fields)) if (r.type === "reference" && r.references?.()?.tableName === t) return n;
|
|
879
|
-
},
|
|
813
|
+
}, Oi = (e, t) => {
|
|
880
814
|
let n = /* @__PURE__ */ new Set();
|
|
881
815
|
for (let r of e) {
|
|
882
816
|
let e = r[t];
|
|
883
817
|
e != null && n.add(e);
|
|
884
818
|
}
|
|
885
819
|
return [...n];
|
|
886
|
-
},
|
|
820
|
+
}, ki = (e, t, n, r, i) => {
|
|
887
821
|
let a = {
|
|
888
822
|
column: t,
|
|
889
823
|
op: "in",
|
|
@@ -897,63 +831,63 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
897
831
|
skip: r.offset,
|
|
898
832
|
projection: void 0
|
|
899
833
|
});
|
|
900
|
-
},
|
|
901
|
-
t !== void 0 && e.length !== 0 && (await
|
|
834
|
+
}, Ai = async (e, t, n, r) => {
|
|
835
|
+
t !== void 0 && e.length !== 0 && (await xi(e, t, n, r)).forEach((t, n) => {
|
|
902
836
|
let r = e[n];
|
|
903
837
|
for (let [e, n] of Object.entries(t)) e in r || (r[e] = n);
|
|
904
838
|
});
|
|
905
|
-
},
|
|
839
|
+
}, ji = (e) => e.eager !== void 0 && Object.keys(e.eager).length > 0, Mi = class extends Error {
|
|
906
840
|
_tag = "TenantNamespaceUnresolved";
|
|
907
841
|
constructor(e) {
|
|
908
842
|
super(e), this.name = "TenantNamespaceUnresolved";
|
|
909
843
|
}
|
|
910
|
-
},
|
|
844
|
+
}, Ni = class extends Error {
|
|
911
845
|
_tag = "TenantNamespaceInvalid";
|
|
912
846
|
constructor(e) {
|
|
913
847
|
super(e), this.name = "TenantNamespaceInvalid";
|
|
914
848
|
}
|
|
915
|
-
},
|
|
916
|
-
if (e == null || e === "") throw new
|
|
917
|
-
let t =
|
|
918
|
-
if (t.replace(/_/g, "") === "") throw new
|
|
919
|
-
let n = `${
|
|
920
|
-
if (n.length >
|
|
849
|
+
}, Pi = 63, Fi = "tenant_", Ii = (e) => e.toLowerCase().replace(/[^a-z0-9_]/g, "_"), Li = (e) => {
|
|
850
|
+
if (e == null || e === "") throw new Mi("namespace isolation is on but the request has no resolvable tenant (subject.tenantId is null/empty). Refusing to run against a shared/default namespace — this would be a cross-tenant read. Authenticate with a tenant-scoped subject, or disable namespace isolation for this surface.");
|
|
851
|
+
let t = Ii(e);
|
|
852
|
+
if (t.replace(/_/g, "") === "") throw new Ni(`tenant id '${e}' has no usable identifier characters after sanitisation — cannot derive a distinct namespace.`);
|
|
853
|
+
let n = `${Fi}${t}`;
|
|
854
|
+
if (n.length > Pi) throw new Ni(`namespace '${n}' for tenant '${e}' exceeds the ${Pi}-byte identifier limit. Use a shorter tenant id.`);
|
|
921
855
|
return n;
|
|
922
|
-
},
|
|
923
|
-
if (e === void 0 || t == null || !
|
|
856
|
+
}, Ri = (e, t) => e === null ? t : `${e}.${t}`, zi = /* @__PURE__ */ new Set(["timestamp", "date"]), Bi = /^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2})?/, Vi = (e, t) => {
|
|
857
|
+
if (e === void 0 || t == null || !zi.has(e) || t instanceof Date) return t;
|
|
924
858
|
if (typeof t == "number" && Number.isFinite(t)) return new Date(t);
|
|
925
|
-
if (typeof t == "string" &&
|
|
859
|
+
if (typeof t == "string" && Bi.test(t)) {
|
|
926
860
|
let e = new Date(t);
|
|
927
861
|
return Number.isNaN(e.getTime()) ? t : e;
|
|
928
862
|
}
|
|
929
863
|
return t;
|
|
930
|
-
},
|
|
864
|
+
}, Hi = (e, t) => e === void 0 || !zi.has(e) ? t : t.map((t) => Vi(e, t)), Ui = (e, t) => {
|
|
931
865
|
let { strings: n, values: r } = e, i = t.unsafe(n[0] ?? "");
|
|
932
866
|
for (let e = 0; e < r.length; e++) i = t`${i}${r[e]}${t.unsafe(n[e + 1] ?? "")}`;
|
|
933
867
|
return t`${i}`;
|
|
934
|
-
},
|
|
935
|
-
if ("not" in e) return t`NOT (${
|
|
936
|
-
if ("and" in e) return e.and.length === 0 ? t`TRUE` : t.and(e.and.map((e) =>
|
|
937
|
-
if ("or" in e) return e.or.length === 0 ? t`FALSE` : t.or(e.or.map((e) =>
|
|
868
|
+
}, I = (e) => e.replace(/[\\%_]/g, (e) => `\\${e}`), L = (e, t, n = null, r) => {
|
|
869
|
+
if ("not" in e) return t`NOT (${L(e.not, t, n, r)})`;
|
|
870
|
+
if ("and" in e) return e.and.length === 0 ? t`TRUE` : t.and(e.and.map((e) => L(e, t, n, r)));
|
|
871
|
+
if ("or" in e) return e.or.length === 0 ? t`FALSE` : t.or(e.or.map((e) => L(e, t, n, r)));
|
|
938
872
|
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
939
|
-
let r = e, i =
|
|
873
|
+
let r = e, i = ea(r.subquery, t, n);
|
|
940
874
|
return r.op === "subquery-in" ? t`${t(r.column)} IN (${i})` : t`${t(r.column)} NOT IN (${i})`;
|
|
941
875
|
}
|
|
942
876
|
if (e.op === "exists" || e.op === "not-exists") {
|
|
943
|
-
let r = e, i =
|
|
877
|
+
let r = e, i = ea(r.subquery, t, n);
|
|
944
878
|
return r.op === "exists" ? t`EXISTS (${i})` : t`NOT EXISTS (${i})`;
|
|
945
879
|
}
|
|
946
880
|
let i = e, a = t(i.column), o = i.path, s = o !== void 0 && o.length > 0, c = () => t.onDialectOrElse({
|
|
947
|
-
mysql: () => t.unsafe(
|
|
948
|
-
mssql: () => t.unsafe(
|
|
949
|
-
sqlite: () => t.unsafe(
|
|
950
|
-
orElse: () => t.unsafe(
|
|
881
|
+
mysql: () => t.unsafe(D(i.column, o, "mysql")),
|
|
882
|
+
mssql: () => t.unsafe(D(i.column, o, "mssql")),
|
|
883
|
+
sqlite: () => t.unsafe(D(i.column, o, "sqlite")),
|
|
884
|
+
orElse: () => t.unsafe(D(i.column, o, "postgres"))
|
|
951
885
|
}), l = () => t.onDialectOrElse({
|
|
952
|
-
mysql: () => t.unsafe(
|
|
953
|
-
mssql: () => t.unsafe(
|
|
954
|
-
sqlite: () => t.unsafe(
|
|
955
|
-
orElse: () => t.unsafe(
|
|
956
|
-
}), 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 :
|
|
886
|
+
mysql: () => t.unsafe(D(i.column, o, "mysql", { numeric: !0 })),
|
|
887
|
+
mssql: () => t.unsafe(D(i.column, o, "mssql", { numeric: !0 })),
|
|
888
|
+
sqlite: () => t.unsafe(D(i.column, o, "sqlite", { numeric: !0 })),
|
|
889
|
+
orElse: () => t.unsafe(D(i.column, o, "postgres", { numeric: !0 }))
|
|
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 : de(r)?.fields?.[i.column]?.type, h = (e) => Vi(m, e);
|
|
957
891
|
switch (i.op) {
|
|
958
892
|
case "eq": return t`${u} = ${f(h(i.value))}`;
|
|
959
893
|
case "neq": return t`${u} <> ${f(h(i.value))}`;
|
|
@@ -970,7 +904,7 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
970
904
|
return e.length === 0 ? t`TRUE` : t`${u} NOT IN ${t.in(s ? e.map((e) => f(e)) : e)}`;
|
|
971
905
|
}
|
|
972
906
|
case "contains": {
|
|
973
|
-
let e = `%${
|
|
907
|
+
let e = `%${I(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
|
|
974
908
|
return t.onDialectOrElse({
|
|
975
909
|
mysql: () => t`LOWER(${u}) LIKE LOWER(${e})`,
|
|
976
910
|
mssql: () => t`LOWER(${u}) LIKE LOWER(${e})`,
|
|
@@ -979,7 +913,7 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
979
913
|
});
|
|
980
914
|
}
|
|
981
915
|
case "startsWith": {
|
|
982
|
-
let e = `${
|
|
916
|
+
let e = `${I(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
|
|
983
917
|
return t.onDialectOrElse({
|
|
984
918
|
mysql: () => t`${u} LIKE ${e}`,
|
|
985
919
|
orElse: () => t`${u} LIKE ${e} ESCAPE '\\'`
|
|
@@ -1027,13 +961,13 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
1027
961
|
});
|
|
1028
962
|
}
|
|
1029
963
|
}
|
|
1030
|
-
},
|
|
964
|
+
}, Wi = (e, t) => {
|
|
1031
965
|
let n = [];
|
|
1032
966
|
return e.partitionBy && e.partitionBy.length > 0 && n.push(t`PARTITION BY ${t.csv(e.partitionBy.map((e) => t`${t(e)}`))}`), e.orderBy && e.orderBy.length > 0 && n.push(t`ORDER BY ${t.csv(e.orderBy.map((e) => e.direction === "desc" ? t`${t(e.column)} DESC` : t`${t(e.column)} ASC`))}`), n.length === 0 ? t`` : n.length === 1 ? n[0] : n.reduce((e, n, r) => r === 0 ? n : t`${e} ${n}`);
|
|
1033
|
-
},
|
|
967
|
+
}, Gi = (e, t) => t.csv(e.map((e) => {
|
|
1034
968
|
let n = e.column === void 0 ? t.unsafe("*") : t`${t(e.column)}`;
|
|
1035
969
|
if (e.op.startsWith("window-")) {
|
|
1036
|
-
let r =
|
|
970
|
+
let r = Wi(e.window ?? {}, t);
|
|
1037
971
|
switch (e.op) {
|
|
1038
972
|
case "window-row-number": return t`ROW_NUMBER() OVER (${r}) AS ${t(e.alias)}`;
|
|
1039
973
|
case "window-rank": return t`RANK() OVER (${r}) AS ${t(e.alias)}`;
|
|
@@ -1057,44 +991,44 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
1057
991
|
return t`${t(e.column)} AS ${t(e.alias)}`;
|
|
1058
992
|
default: throw Error(`compileAggregateProjection: unknown op '${e.op}'`);
|
|
1059
993
|
}
|
|
1060
|
-
})),
|
|
994
|
+
})), Ki = (e) => `[${e.join(",")}]`, qi = (e, t) => {
|
|
1061
995
|
if (e.queryVector === void 0) return null;
|
|
1062
|
-
let n = t(e.column), r =
|
|
996
|
+
let n = t(e.column), r = Ki(e.queryVector), i = e.distance === "cosine" ? "<=>" : e.distance === "l2" ? "<->" : "<#>", a = e.distance === "cosine" ? "VEC_DISTANCE_COSINE" : "VEC_DISTANCE_EUCLIDEAN";
|
|
1063
997
|
return t.onDialectOrElse({
|
|
1064
998
|
mysql: () => t`${t.unsafe(a)}(${n}, ${r})`,
|
|
1065
999
|
mssql: () => t`NULL`,
|
|
1066
1000
|
sqlite: () => t`NULL`,
|
|
1067
1001
|
orElse: () => t`${n} ${t.unsafe(i)} ${r}::vector`
|
|
1068
1002
|
});
|
|
1069
|
-
},
|
|
1003
|
+
}, Ji = (e, t) => {
|
|
1070
1004
|
let n = t.unsafe(e.useGeography ? "::geography" : "::geometry");
|
|
1071
1005
|
return t`ST_Distance(${t(e.column)}${n}, ${e.geom}${n})`;
|
|
1072
|
-
},
|
|
1073
|
-
let r = n.csv(e.columns.map((e) => n`${n(e)}`)), i = `%${
|
|
1006
|
+
}, 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 = `%${I(e.query)}%`;
|
|
1074
1008
|
return n.onDialectOrElse({
|
|
1075
1009
|
mysql: () => n`MATCH(${r}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
|
|
1076
1010
|
sqlite: () => {
|
|
1077
|
-
let r = n(
|
|
1011
|
+
let r = n(Zi(e, t));
|
|
1078
1012
|
return n`${n("id")} IN (SELECT ${n("row_id")} FROM ${r} WHERE ${r} MATCH ${e.query})`;
|
|
1079
1013
|
},
|
|
1080
1014
|
mssql: () => n.or(e.columns.map((e) => n`LOWER(${n(e)}) LIKE LOWER(${i}) ESCAPE '\\'`)),
|
|
1081
|
-
orElse: () => n`${
|
|
1015
|
+
orElse: () => n`${Xi(e, n)} @@ plainto_tsquery(${e.config ?? "english"}, ${e.query})`
|
|
1082
1016
|
});
|
|
1083
|
-
},
|
|
1084
|
-
let r = `%${
|
|
1017
|
+
}, $i = (e, t, n) => {
|
|
1018
|
+
let r = `%${I(e.query)}%`;
|
|
1085
1019
|
return n.onDialectOrElse({
|
|
1086
1020
|
mysql: () => n`MATCH(${n.csv(e.columns.map((e) => n`${n(e)}`))}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
|
|
1087
1021
|
sqlite: () => {
|
|
1088
|
-
let r = n(
|
|
1022
|
+
let r = n(Zi(e, t));
|
|
1089
1023
|
return n`COALESCE((SELECT -bm25(${r}) FROM ${r} WHERE ${r} MATCH ${e.query} AND ${r}.${n("row_id")} = ${n("id")}), 0)`;
|
|
1090
1024
|
},
|
|
1091
1025
|
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}`),
|
|
1092
|
-
orElse: () => n`ts_rank(${
|
|
1026
|
+
orElse: () => n`ts_rank(${Xi(e, n)}, plainto_tsquery(${e.config ?? "english"}, ${e.query}))`
|
|
1093
1027
|
});
|
|
1094
|
-
},
|
|
1028
|
+
}, ea = (e, t, n = null) => {
|
|
1095
1029
|
if (e.setOp && e.setOp.queries.length >= 2) {
|
|
1096
|
-
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`(${
|
|
1097
|
-
if (
|
|
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`(${ea(e, t, n)})`).reduce((e, n, i) => i === 0 ? n : t`${e} ${t.unsafe(r)} ${n}`), a = [];
|
|
1031
|
+
if (u(e).length > 0 && a.push(t` ORDER BY ${t.csv(u(e).map((e) => e.direction === "desc" ? t`${t(e.column)} DESC` : t`${t(e.column)} ASC`))}`), e.take !== void 0) {
|
|
1098
1032
|
if (!Number.isInteger(e.take) || e.take < 0) throw Error(`compileSelect: invalid take ${e.take}`);
|
|
1099
1033
|
a.push(t` LIMIT ${t.unsafe(String(e.take))}`);
|
|
1100
1034
|
}
|
|
@@ -1104,7 +1038,7 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
1104
1038
|
}
|
|
1105
1039
|
return t`${i}${a.reduce((e, n) => t`${e}${n}`, t``)}`;
|
|
1106
1040
|
}
|
|
1107
|
-
let r = e.annClause === void 0 ? null :
|
|
1041
|
+
let r = e.annClause === void 0 ? null : qi(e.annClause, t);
|
|
1108
1042
|
e.spatialClause !== void 0 && t.onDialectOrElse({
|
|
1109
1043
|
mysql: () => {
|
|
1110
1044
|
throw Error("@voltro/plugin-postgis: spatial distance / KNN ordering is postgres-only");
|
|
@@ -1117,64 +1051,64 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
1117
1051
|
},
|
|
1118
1052
|
orElse: () => t``
|
|
1119
1053
|
});
|
|
1120
|
-
let i = e.spatialClause?.projectAs === void 0 ? null :
|
|
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, d = l !== null && c?.rank !== void 0 ? t`${s}, ${l} AS ${t(c.rank.alias)}` : s, f = i !== null && !o && e.spatialClause?.projectAs !== void 0 ? t`${d}, ${i} AS ${t(e.spatialClause.projectAs)}` : d, p = e.distinctOn && e.distinctOn.length > 0 ? t.onDialectOrElse({
|
|
1121
1055
|
orElse: () => t`DISTINCT ON (${t.csv(e.distinctOn.map((e) => t`${t(e)}`))}) `,
|
|
1122
1056
|
mysql: () => t`DISTINCT `,
|
|
1123
1057
|
mssql: () => t`DISTINCT `,
|
|
1124
1058
|
sqlite: () => t`DISTINCT `
|
|
1125
|
-
}) : e.distinct ? t`DISTINCT ` : t``,
|
|
1059
|
+
}) : e.distinct ? t`DISTINCT ` : t``, m = e.lock === "update", h = m ? t.onDialectOrElse({
|
|
1126
1060
|
mssql: () => t` WITH (UPDLOCK, ROWLOCK)`,
|
|
1127
1061
|
orElse: () => t``
|
|
1128
|
-
}) : t``,
|
|
1062
|
+
}) : t``, g = m ? t.onDialectOrElse({
|
|
1129
1063
|
mssql: () => t``,
|
|
1130
1064
|
sqlite: () => t``,
|
|
1131
1065
|
orElse: () => t` FOR UPDATE`
|
|
1132
|
-
}) : t``,
|
|
1066
|
+
}) : t``, _ = e.alias === void 0 ? t`${t(Ri(n, e.table))}${h}` : t`${t(Ri(n, e.table))} AS ${t(e.alias)}${h}`, v = (e.joins ?? []).map((e) => {
|
|
1133
1067
|
let r = e.kind === "inner" ? "INNER" : "LEFT";
|
|
1134
|
-
return t` ${t.unsafe(r)} JOIN ${t(
|
|
1135
|
-
}),
|
|
1136
|
-
r !== null &&
|
|
1137
|
-
for (let n of
|
|
1138
|
-
let
|
|
1068
|
+
return t` ${t.unsafe(r)} JOIN ${t(Ri(n, e.table))} AS ${t(e.alias)} ON ${L(e.on, t, n)}`;
|
|
1069
|
+
}), ee = v.length > 0 ? v.reduce((e, n) => t`${e}${n}`, _) : _, te = c === void 0 ? null : Qi(c, e.table, t), y = [e.predicate ? L(e.predicate, t, n, e.table) : null, te].filter((e) => e !== null), ne = y.length > 0 ? t` WHERE ${t.and(y)}` : 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 ${L(e.having, t, n, e.table)}` : t``, ae = e.skip !== void 0, b = [];
|
|
1070
|
+
r !== null && b.push(t`${r} ASC`), e.spatialClause?.order !== void 0 && b.push(e.spatialClause.order === "desc" ? t`${Yi(e.spatialClause, t)} DESC` : t`${Yi(e.spatialClause, t)} ASC`), l !== null && c?.rank?.order === !0 && b.push(t`${l} DESC`);
|
|
1071
|
+
for (let n of u(e)) b.push(n.direction === "desc" ? t`${t(n.column)} DESC` : t`${t(n.column)} ASC`);
|
|
1072
|
+
let x = b.length > 0 ? t` ORDER BY ${t.csv(b)}` : ae ? t.onDialectOrElse({
|
|
1139
1073
|
mssql: () => t` ORDER BY (SELECT NULL)`,
|
|
1140
1074
|
orElse: () => t``
|
|
1141
1075
|
}) : t``, S = (e) => {
|
|
1142
1076
|
if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw Error(`compileSelect: expected non-negative integer take/skip, got ${e}`);
|
|
1143
1077
|
return t.unsafe(String(e));
|
|
1144
|
-
}, oe = (e.ctes ?? []).map((e) => t`${t(e.name)} AS (${
|
|
1078
|
+
}, oe = (e.ctes ?? []).map((e) => t`${t(e.name)} AS (${ea(e.descriptor, t, n)})`), C = (e.ctes ?? []).some((e) => e.recursive === !0), se = oe.length > 0 ? t`WITH ${t.unsafe(C ? "RECURSIVE " : "")}${t.csv(oe)} ` : t``;
|
|
1145
1079
|
return t.onDialectOrElse({
|
|
1146
1080
|
mssql: () => {
|
|
1147
|
-
let n = e.take !== void 0 && !
|
|
1148
|
-
return t`${
|
|
1081
|
+
let n = e.take !== void 0 && !ae ? t`TOP ${S(e.take)} ` : t``, r = ae ? t` OFFSET ${S(e.skip)} ROWS FETCH NEXT ${S(e.take ?? 2 ** 53 - 1)} ROWS ONLY` : t``;
|
|
1082
|
+
return t`${se}SELECT ${n}${p}${f} FROM ${ee}${ne}${re}${ie}${x}${r}`;
|
|
1149
1083
|
},
|
|
1150
1084
|
orElse: () => {
|
|
1151
|
-
let n = e.take === void 0 ? t`` : t` LIMIT ${S(e.take)}`, r =
|
|
1152
|
-
return t`${
|
|
1085
|
+
let n = e.take === void 0 ? t`` : t` LIMIT ${S(e.take)}`, r = ae ? t` OFFSET ${S(e.skip)}` : t``;
|
|
1086
|
+
return t`${se}SELECT ${p}${f} FROM ${ee}${ne}${re}${ie}${x}${n}${r}${g}`;
|
|
1153
1087
|
}
|
|
1154
1088
|
});
|
|
1155
|
-
},
|
|
1089
|
+
}, ta = (e, t, n) => {
|
|
1156
1090
|
if (e.eager === void 0) return null;
|
|
1157
|
-
let r =
|
|
1091
|
+
let r = ia(e.table, e.eager, e.sourceTable);
|
|
1158
1092
|
if (r === null) return null;
|
|
1159
|
-
let i =
|
|
1093
|
+
let i = da(n, e, r, ua(t, n));
|
|
1160
1094
|
return i === null ? null : {
|
|
1161
1095
|
fragment: i,
|
|
1162
|
-
decode:
|
|
1096
|
+
decode: ma(r, n)
|
|
1163
1097
|
};
|
|
1164
|
-
},
|
|
1098
|
+
}, na = (e) => e.relation.kind === "one" && e.fkSide === "target", ra = (e) => ({
|
|
1165
1099
|
...e,
|
|
1166
1100
|
branch: {
|
|
1167
1101
|
...e.branch,
|
|
1168
1102
|
limit: 2
|
|
1169
1103
|
}
|
|
1170
|
-
}),
|
|
1171
|
-
let r = n ??
|
|
1104
|
+
}), ia = (e, t, n) => {
|
|
1105
|
+
let r = n ?? s(e), i = Yr(e);
|
|
1172
1106
|
if (i === void 0) return null;
|
|
1173
1107
|
let a = [];
|
|
1174
1108
|
for (let [e, n] of Object.entries(t)) {
|
|
1175
1109
|
let t = i[e];
|
|
1176
1110
|
if (t === void 0) return null;
|
|
1177
|
-
let o =
|
|
1111
|
+
let o = aa(e, t, r, n === !0 ? {} : n);
|
|
1178
1112
|
if (o === null) return null;
|
|
1179
1113
|
a.push(o);
|
|
1180
1114
|
}
|
|
@@ -1182,30 +1116,30 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
1182
1116
|
table: r,
|
|
1183
1117
|
children: a
|
|
1184
1118
|
};
|
|
1185
|
-
},
|
|
1119
|
+
}, aa = (e, t, n, r) => {
|
|
1186
1120
|
let i = t.target(), a = (t.kind === "manyToMany" ? void 0 : t.sourceKey) ?? "id", o, s;
|
|
1187
1121
|
if (t.kind === "manyToMany") o = t.targetKey, s = "target";
|
|
1188
1122
|
else if (t.kind === "one") {
|
|
1189
|
-
let r = t.sourceKey ??
|
|
1123
|
+
let r = t.sourceKey ?? la(n, i.tableName);
|
|
1190
1124
|
if (r !== void 0) o = r, s = "source";
|
|
1191
1125
|
else try {
|
|
1192
|
-
o = t.foreignKey ??
|
|
1126
|
+
o = t.foreignKey ?? Br(i, n.tableName, e), s = "target";
|
|
1193
1127
|
} catch {
|
|
1194
1128
|
return null;
|
|
1195
1129
|
}
|
|
1196
1130
|
} else try {
|
|
1197
|
-
o = t.foreignKey ??
|
|
1131
|
+
o = t.foreignKey ?? Br(i, n.tableName, e), s = "target";
|
|
1198
1132
|
} catch {
|
|
1199
1133
|
return null;
|
|
1200
1134
|
}
|
|
1201
1135
|
let c = r.with === void 0 ? [] : (() => {
|
|
1202
|
-
let e =
|
|
1136
|
+
let e = Yr(i.tableName);
|
|
1203
1137
|
if (e === void 0 && Object.keys(r.with).length > 0) return null;
|
|
1204
1138
|
let t = [];
|
|
1205
1139
|
for (let [n, a] of Object.entries(r.with)) {
|
|
1206
1140
|
let r = e?.[n];
|
|
1207
1141
|
if (r === void 0) return null;
|
|
1208
|
-
let o =
|
|
1142
|
+
let o = aa(n, r, i, a === !0 ? {} : a);
|
|
1209
1143
|
if (o === null) return null;
|
|
1210
1144
|
t.push(o);
|
|
1211
1145
|
}
|
|
@@ -1221,9 +1155,9 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
1221
1155
|
fkSide: s,
|
|
1222
1156
|
branch: r,
|
|
1223
1157
|
children: c,
|
|
1224
|
-
junction:
|
|
1158
|
+
junction: oa(t, r)
|
|
1225
1159
|
};
|
|
1226
|
-
},
|
|
1160
|
+
}, oa = (e, t) => {
|
|
1227
1161
|
if (e.kind !== "manyToMany" || t.junction === void 0) return;
|
|
1228
1162
|
let n = e.through(), r = t.junction === !0 ? Object.keys(n.fields) : t.junction, i = r.filter((e) => e in n.fields);
|
|
1229
1163
|
return {
|
|
@@ -1235,35 +1169,35 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
1235
1169
|
return t !== void 0 && (t.type === "timestamp" || t.type === "date");
|
|
1236
1170
|
})
|
|
1237
1171
|
};
|
|
1238
|
-
},
|
|
1172
|
+
}, sa = (e) => `__j_${e}`, ca = "__j", la = (e, t) => {
|
|
1239
1173
|
for (let [n, r] of Object.entries(e.fields)) if (r.type === "reference" && r.references?.()?.tableName === t) return n;
|
|
1240
|
-
},
|
|
1174
|
+
}, ua = (e, t) => {
|
|
1241
1175
|
let n = 0;
|
|
1242
1176
|
return {
|
|
1243
1177
|
sql: e,
|
|
1244
1178
|
dialect: t,
|
|
1245
1179
|
nextAlias: () => `__a${n++}`
|
|
1246
1180
|
};
|
|
1247
|
-
},
|
|
1181
|
+
}, da = (e, t, n, r) => {
|
|
1248
1182
|
switch (e) {
|
|
1249
|
-
case "postgres": return
|
|
1183
|
+
case "postgres": return _a(t, n, r);
|
|
1250
1184
|
case "sqlite":
|
|
1251
|
-
case "turso": return
|
|
1185
|
+
case "turso": return Ta(t, n, r);
|
|
1252
1186
|
case "mysql":
|
|
1253
|
-
case "mariadb": return
|
|
1254
|
-
case "mssql": return
|
|
1187
|
+
case "mariadb": return Fa(t, n, r);
|
|
1188
|
+
case "mssql": return Ha(t, n, r);
|
|
1255
1189
|
}
|
|
1256
|
-
},
|
|
1257
|
-
let n =
|
|
1190
|
+
}, fa = (e, t) => t === "mssql" && !pa.test(e) ? /* @__PURE__ */ new Date(`${e}Z`) : new Date(e), pa = /(?:Z|[+-]\d{2}:?\d{2})$/, ma = (e, t) => {
|
|
1191
|
+
let n = ha(e.table, e.children, t);
|
|
1258
1192
|
return (e) => e.map((e) => {
|
|
1259
1193
|
let t = e.__row, r = typeof t == "string" ? JSON.parse(t) : t;
|
|
1260
1194
|
return n(r);
|
|
1261
1195
|
});
|
|
1262
|
-
},
|
|
1196
|
+
}, ha = (e, t, n) => {
|
|
1263
1197
|
let r = [], i = [];
|
|
1264
1198
|
for (let [t, n] of Object.entries(e.fields)) (n.type === "timestamp" || n.type === "date") && r.push(t), n.type === "vector" && i.push(t);
|
|
1265
1199
|
let a = t.map((e) => {
|
|
1266
|
-
let t =
|
|
1200
|
+
let t = ha(e.target, e.children, n), r = e.relation.kind === "one", i = na(e), a = i ? bi({
|
|
1267
1201
|
relationName: e.relationName,
|
|
1268
1202
|
sourceTableName: e.source.tableName,
|
|
1269
1203
|
targetTableName: e.target.tableName,
|
|
@@ -1276,15 +1210,15 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
1276
1210
|
isSingle: r,
|
|
1277
1211
|
fromOverFetch: i,
|
|
1278
1212
|
cardinalityMessage: a,
|
|
1279
|
-
junction:
|
|
1213
|
+
junction: ga(e.junction, n)
|
|
1280
1214
|
};
|
|
1281
1215
|
});
|
|
1282
1216
|
return (e) => {
|
|
1283
1217
|
let t = { ...e };
|
|
1284
|
-
for (let e of i) e in t && (t[e] =
|
|
1218
|
+
for (let e of i) e in t && (t[e] = Lt(t[e], "vector", n));
|
|
1285
1219
|
for (let e of r) {
|
|
1286
1220
|
let r = t[e];
|
|
1287
|
-
typeof r == "string" && (t[e] =
|
|
1221
|
+
typeof r == "string" && (t[e] = fa(r, n));
|
|
1288
1222
|
}
|
|
1289
1223
|
for (let e of a) {
|
|
1290
1224
|
let n = t[e.name];
|
|
@@ -1294,7 +1228,7 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
1294
1228
|
}
|
|
1295
1229
|
if (e.fromOverFetch) {
|
|
1296
1230
|
let r = n;
|
|
1297
|
-
if (r.length > 1) throw new
|
|
1231
|
+
if (r.length > 1) throw new yi(e.cardinalityMessage);
|
|
1298
1232
|
t[e.name] = r.length === 0 ? null : e.decode(r[0]);
|
|
1299
1233
|
continue;
|
|
1300
1234
|
}
|
|
@@ -1306,204 +1240,204 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
1306
1240
|
}
|
|
1307
1241
|
return t;
|
|
1308
1242
|
};
|
|
1309
|
-
},
|
|
1243
|
+
}, ga = (e, t) => {
|
|
1310
1244
|
if (e === void 0) return;
|
|
1311
1245
|
let n = new Set(e.dateColumns), r = e.requested;
|
|
1312
1246
|
return (e) => {
|
|
1313
1247
|
let i = e._junction ?? {}, a = {};
|
|
1314
1248
|
for (let e of r) {
|
|
1315
1249
|
let r = i[e];
|
|
1316
|
-
a[e] = n.has(e) && typeof r == "string" ?
|
|
1250
|
+
a[e] = n.has(e) && typeof r == "string" ? fa(r, t) : r;
|
|
1317
1251
|
}
|
|
1318
1252
|
return {
|
|
1319
1253
|
...e,
|
|
1320
1254
|
_junction: a
|
|
1321
1255
|
};
|
|
1322
1256
|
};
|
|
1323
|
-
},
|
|
1324
|
-
let r = n.sql, i = n.nextAlias(), a = r(t.table.tableName), o = r(i), s =
|
|
1325
|
-
return s === null ? null : r`SELECT ${s} AS "__row" FROM ${a} AS ${o}${e.predicate ? r` WHERE ${
|
|
1326
|
-
},
|
|
1327
|
-
let i = n.sql, a = r === void 0 ? i`to_jsonb(${i(e)}.*)` : i`(to_jsonb(${i(e)}.*) - ${
|
|
1257
|
+
}, _a = (e, t, n) => {
|
|
1258
|
+
let r = n.sql, i = n.nextAlias(), a = r(t.table.tableName), o = r(i), s = va(i, t.children, n);
|
|
1259
|
+
return s === null ? null : r`SELECT ${s} AS "__row" FROM ${a} AS ${o}${e.predicate ? r` WHERE ${U(e.predicate, i, r)}` : r``}${u(e).length > 0 ? r` ORDER BY ${r.csv(u(e).map((e) => e.direction === "desc" ? r`${B(i, e.column, r)} DESC` : r`${B(i, e.column, r)} ASC`))}` : r``}${e.take === void 0 ? r`` : r` LIMIT ${H(e.take, r)}`}${e.skip === void 0 ? r`` : r` OFFSET ${H(e.skip, r)}`}`;
|
|
1260
|
+
}, va = (e, t, n, r) => {
|
|
1261
|
+
let i = n.sql, a = r === void 0 ? i`to_jsonb(${i(e)}.*)` : i`(to_jsonb(${i(e)}.*) - ${V(ca, i)}::text)`;
|
|
1328
1262
|
if (t.length === 0 && r === void 0) return a;
|
|
1329
1263
|
let o = [];
|
|
1330
|
-
r !== void 0 && o.push(i`${
|
|
1264
|
+
r !== void 0 && o.push(i`${V("_junction", i)}, ${B(e, ca, i)}`);
|
|
1331
1265
|
for (let r of t) {
|
|
1332
|
-
let t =
|
|
1266
|
+
let t = ya(r, e, n);
|
|
1333
1267
|
if (t === null) return null;
|
|
1334
|
-
o.push(i`${
|
|
1268
|
+
o.push(i`${V(r.relationName, i)}, ${t}`);
|
|
1335
1269
|
}
|
|
1336
1270
|
return i`${a} || jsonb_build_object(${i.csv(o)})`;
|
|
1337
|
-
},
|
|
1271
|
+
}, ya = (e, t, n) => {
|
|
1338
1272
|
switch (e.relation.kind) {
|
|
1339
|
-
case "one": return
|
|
1340
|
-
case "many": return
|
|
1341
|
-
case "manyToMany": return
|
|
1273
|
+
case "one": return na(e) ? xa(ra(e), t, n) : ba(e, t, n);
|
|
1274
|
+
case "many": return xa(e, t, n);
|
|
1275
|
+
case "manyToMany": return Sa(e, t, n);
|
|
1342
1276
|
}
|
|
1343
|
-
},
|
|
1344
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1277
|
+
}, ba = (e, t, n) => {
|
|
1278
|
+
let r = n.sql, i = n.nextAlias(), a = va(i, e.children, n);
|
|
1345
1279
|
if (a === null) return null;
|
|
1346
|
-
let o = e.fkSide === "source" ? r`${
|
|
1280
|
+
let o = e.fkSide === "source" ? r`${B(i, "id", r)} = ${B(t, e.foreignKey, r)}` : r`${B(i, e.foreignKey, r)} = ${B(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${U(e.branch.where, i, r)}`, c = R(i, e.branch.orderBy, r);
|
|
1347
1281
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}${c} LIMIT 1)`;
|
|
1348
|
-
},
|
|
1349
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1282
|
+
}, xa = (e, t, n) => {
|
|
1283
|
+
let r = n.sql, i = n.nextAlias(), a = va(i, e.children, n);
|
|
1350
1284
|
if (a === null) return null;
|
|
1351
|
-
let o = r`${
|
|
1285
|
+
let o = r`${B(void 0, e.foreignKey, r)} = ${B(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${L(e.branch.where, r)}`, c = wa(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${H(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${H(e.branch.offset, r)}`;
|
|
1352
1286
|
return r`COALESCE((SELECT jsonb_agg(${a}) FROM (SELECT * FROM ${r(e.target.tableName)} WHERE ${o}${s}${c}${l}${u}) AS ${r(i)}), '[]'::jsonb)`;
|
|
1353
|
-
},
|
|
1354
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
1287
|
+
}, Sa = (e, t, n) => {
|
|
1288
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = va(o, e.children, n, e.junction);
|
|
1355
1289
|
if (c === null) return null;
|
|
1356
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1357
|
-
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 ${
|
|
1358
|
-
},
|
|
1359
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1290
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${L(e.branch.where, r)}`, u = Xa(e, s, r), d = R(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${H(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${H(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : r`, ${Ca(e.junction, s, r)} AS ${r(ca)}`;
|
|
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 ${B(o, "id", r)} = ${B(s, i.targetKey, r)} WHERE ${B(s, i.sourceKey, r)} = ${B(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), '[]'::jsonb)`;
|
|
1292
|
+
}, Ca = (e, t, n) => e.present.length === 0 ? n`jsonb_build_object()` : n`jsonb_build_object(${n.csv(e.present.map((e) => n`${V(e, n)}, ${B(t, e, n)}`))})`, R = (e, t, n) => t === void 0 || t.length === 0 ? n`` : n` ORDER BY ${n.csv(t.map((t) => t.direction === "desc" ? n`${B(e, t.column, n)} DESC` : n`${B(e, t.column, n)} ASC`))}`, wa = (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`))}`, Ta = (e, t, n) => {
|
|
1293
|
+
let r = n.sql, i = n.nextAlias(), a = Ea(i, t.table, t.children, n);
|
|
1360
1294
|
if (a === null) return null;
|
|
1361
|
-
let o = e.predicate ? r` WHERE ${
|
|
1295
|
+
let o = e.predicate ? r` WHERE ${U(e.predicate, i, r)}` : r``, s = u(e).length > 0 ? r` ORDER BY ${r.csv(u(e).map((e) => e.direction === "desc" ? r`${B(i, e.column, r)} DESC` : r`${B(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${H(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${H(e.skip, r)}`;
|
|
1362
1296
|
return r`SELECT ${a} AS "__row" FROM ${r(t.table.tableName)} AS ${r(i)}${o}${s}${c}${l}`;
|
|
1363
|
-
},
|
|
1297
|
+
}, Ea = (e, t, n, r, i) => {
|
|
1364
1298
|
let a = r.sql, o = [];
|
|
1365
|
-
for (let n of Object.keys(t.fields)) o.push(a`${
|
|
1299
|
+
for (let n of Object.keys(t.fields)) o.push(a`${V(n, a)}, ${B(e, n, a)}`);
|
|
1366
1300
|
if (i !== void 0) {
|
|
1367
|
-
let e =
|
|
1368
|
-
o.push(a`${
|
|
1301
|
+
let e = Da(i.projection, i.source, a);
|
|
1302
|
+
o.push(a`${V("_junction", a)}, json_object(${e})`);
|
|
1369
1303
|
}
|
|
1370
1304
|
for (let t of n) {
|
|
1371
|
-
let n =
|
|
1305
|
+
let n = ja(t, e, r);
|
|
1372
1306
|
if (n === null) return null;
|
|
1373
|
-
o.push(a`${
|
|
1307
|
+
o.push(a`${V(t.relationName, a)}, ${n}`);
|
|
1374
1308
|
}
|
|
1375
1309
|
return a`json_object(${a.csv(o)})`;
|
|
1376
|
-
},
|
|
1310
|
+
}, Da = (e, t, n) => e.present.length === 0 ? n`` : n.csv(e.present.map((e) => n`${V(e, n)}, ${B(t.alias, t.physical(e), n)}`)), Oa = (e, t, n) => e.present.length === 0 ? n`` : n`, ${n.csv(e.present.map((e) => n`${B(t, e, n)} AS ${n(sa(e))}`))}`, ka = (e) => ({
|
|
1377
1311
|
alias: e,
|
|
1378
|
-
physical:
|
|
1379
|
-
}),
|
|
1312
|
+
physical: sa
|
|
1313
|
+
}), Aa = (e) => ({
|
|
1380
1314
|
alias: e,
|
|
1381
1315
|
physical: (e) => e
|
|
1382
|
-
}),
|
|
1316
|
+
}), ja = (e, t, n) => {
|
|
1383
1317
|
switch (e.relation.kind) {
|
|
1384
|
-
case "one": return
|
|
1385
|
-
case "many": return
|
|
1386
|
-
case "manyToMany": return
|
|
1318
|
+
case "one": return na(e) ? Na(ra(e), t, n) : Ma(e, t, n);
|
|
1319
|
+
case "many": return Na(e, t, n);
|
|
1320
|
+
case "manyToMany": return Pa(e, t, n);
|
|
1387
1321
|
}
|
|
1388
|
-
},
|
|
1389
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1322
|
+
}, Ma = (e, t, n) => {
|
|
1323
|
+
let r = n.sql, i = n.nextAlias(), a = Ea(i, e.target, e.children, n);
|
|
1390
1324
|
if (a === null) return null;
|
|
1391
|
-
let o = e.fkSide === "source" ? r`${
|
|
1325
|
+
let o = e.fkSide === "source" ? r`${B(i, "id", r)} = ${B(t, e.foreignKey, r)}` : r`${B(i, e.foreignKey, r)} = ${B(t, e.sourceKey, r)}`;
|
|
1392
1326
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
|
|
1393
|
-
},
|
|
1394
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1327
|
+
}, Na = (e, t, n) => {
|
|
1328
|
+
let r = n.sql, i = n.nextAlias(), a = Ea(i, e.target, e.children, n);
|
|
1395
1329
|
if (a === null) return null;
|
|
1396
|
-
let o = r`${
|
|
1330
|
+
let o = r`${B(void 0, e.foreignKey, r)} = ${B(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${L(W(e.branch.where), r)}`, c = wa(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${H(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${H(e.branch.offset, r)}`;
|
|
1397
1331
|
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('[]'))`;
|
|
1398
|
-
},
|
|
1399
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
1332
|
+
}, Pa = (e, t, n) => {
|
|
1333
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = Ea(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
1400
1334
|
projection: e.junction,
|
|
1401
|
-
source:
|
|
1335
|
+
source: ka(o)
|
|
1402
1336
|
});
|
|
1403
1337
|
if (c === null) return null;
|
|
1404
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1405
|
-
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 ${
|
|
1406
|
-
},
|
|
1407
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1338
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${L(W(e.branch.where), r)}`, u = Xa(e, s, r, !0), d = R(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${H(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${H(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : Oa(e.junction, s, r);
|
|
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 ${B(o, "id", r)} = ${B(s, i.targetKey, r)} WHERE ${B(s, i.sourceKey, r)} = ${B(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), json('[]'))`;
|
|
1340
|
+
}, Fa = (e, t, n) => {
|
|
1341
|
+
let r = n.sql, i = n.nextAlias(), a = z(i, t.table, t.children, n);
|
|
1408
1342
|
if (a === null) return null;
|
|
1409
|
-
let o = e.predicate ? r` WHERE ${
|
|
1343
|
+
let o = e.predicate ? r` WHERE ${U(e.predicate, i, r)}` : r``, s = u(e).length > 0 ? r` ORDER BY ${r.csv(u(e).map((e) => e.direction === "desc" ? r`${B(i, e.column, r)} DESC` : r`${B(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${H(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${H(e.skip, r)}`;
|
|
1410
1344
|
return r`SELECT ${a} AS \`__row\` FROM ${r(t.table.tableName)} AS ${r(i)}${o}${s}${c}${l}`;
|
|
1411
|
-
},
|
|
1345
|
+
}, z = (e, t, n, r, i) => {
|
|
1412
1346
|
let a = r.sql, o = [];
|
|
1413
|
-
for (let n of Object.keys(t.fields)) o.push(a`${
|
|
1347
|
+
for (let n of Object.keys(t.fields)) o.push(a`${V(n, a)}, ${B(e, n, a)}`);
|
|
1414
1348
|
if (i !== void 0) {
|
|
1415
|
-
let e =
|
|
1416
|
-
o.push(a`${
|
|
1349
|
+
let e = Da(i.projection, i.source, a);
|
|
1350
|
+
o.push(a`${V("_junction", a)}, JSON_OBJECT(${e})`);
|
|
1417
1351
|
}
|
|
1418
1352
|
for (let t of n) {
|
|
1419
|
-
let n =
|
|
1353
|
+
let n = Ia(t, e, r);
|
|
1420
1354
|
if (n === null) return null;
|
|
1421
|
-
o.push(a`${
|
|
1355
|
+
o.push(a`${V(t.relationName, a)}, ${n}`);
|
|
1422
1356
|
}
|
|
1423
1357
|
return a`JSON_OBJECT(${a.csv(o)})`;
|
|
1424
|
-
},
|
|
1358
|
+
}, Ia = (e, t, n) => {
|
|
1425
1359
|
switch (e.relation.kind) {
|
|
1426
1360
|
case "one":
|
|
1427
|
-
if (
|
|
1428
|
-
let r =
|
|
1429
|
-
return n.dialect === "mariadb" ?
|
|
1361
|
+
if (na(e)) {
|
|
1362
|
+
let r = ra(e);
|
|
1363
|
+
return n.dialect === "mariadb" ? Ba(r, t, n) : Ra(r, t, n);
|
|
1430
1364
|
}
|
|
1431
|
-
return
|
|
1432
|
-
case "many": return n.dialect === "mariadb" ?
|
|
1433
|
-
case "manyToMany": return n.dialect === "mariadb" ?
|
|
1365
|
+
return La(e, t, n);
|
|
1366
|
+
case "many": return n.dialect === "mariadb" ? Ba(e, t, n) : Ra(e, t, n);
|
|
1367
|
+
case "manyToMany": return n.dialect === "mariadb" ? Va(e, t, n) : za(e, t, n);
|
|
1434
1368
|
}
|
|
1435
|
-
},
|
|
1436
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1369
|
+
}, La = (e, t, n) => {
|
|
1370
|
+
let r = n.sql, i = n.nextAlias(), a = z(i, e.target, e.children, n);
|
|
1437
1371
|
if (a === null) return null;
|
|
1438
|
-
let o = e.fkSide === "source" ? r`${
|
|
1372
|
+
let o = e.fkSide === "source" ? r`${B(i, "id", r)} = ${B(t, e.foreignKey, r)}` : r`${B(i, e.foreignKey, r)} = ${B(t, e.sourceKey, r)}`;
|
|
1439
1373
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
|
|
1440
|
-
},
|
|
1441
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1374
|
+
}, Ra = (e, t, n) => {
|
|
1375
|
+
let r = n.sql, i = n.nextAlias(), a = z(i, e.target, e.children, n);
|
|
1442
1376
|
if (a === null) return null;
|
|
1443
|
-
let o = r`${
|
|
1377
|
+
let o = r`${B(void 0, e.foreignKey, r)} = ${B(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${L(W(e.branch.where), r)}`, c = wa(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${H(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${H(e.branch.offset, r)}`;
|
|
1444
1378
|
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())`;
|
|
1445
|
-
},
|
|
1446
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
1379
|
+
}, za = (e, t, n) => {
|
|
1380
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = z(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
1447
1381
|
projection: e.junction,
|
|
1448
|
-
source:
|
|
1382
|
+
source: ka(o)
|
|
1449
1383
|
});
|
|
1450
1384
|
if (c === null) return null;
|
|
1451
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1452
|
-
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 ${
|
|
1453
|
-
},
|
|
1454
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1385
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${L(W(e.branch.where), r)}`, u = Xa(e, s, r, !0), d = R(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${H(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${H(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : Oa(e.junction, s, r);
|
|
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 ${B(o, "id", r)} = ${B(s, i.targetKey, r)} WHERE ${B(s, i.sourceKey, r)} = ${B(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), JSON_ARRAY())`;
|
|
1387
|
+
}, Ba = (e, t, n) => {
|
|
1388
|
+
let r = n.sql, i = n.nextAlias(), a = z(i, e.target, e.children, n);
|
|
1455
1389
|
if (a === null) return null;
|
|
1456
|
-
let o = r`${
|
|
1457
|
-
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`${
|
|
1458
|
-
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 ${
|
|
1459
|
-
return r`COALESCE((SELECT JSON_ARRAYAGG(${a} ORDER BY ${
|
|
1460
|
-
},
|
|
1390
|
+
let o = r`${B(i, e.foreignKey, r)} = ${B(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${L(W(e.branch.where), r)}`, c = e.branch.orderBy ?? [];
|
|
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`${B(i, e.column, r)} DESC` : r`${B(i, e.column, r)} ASC`))}` : r``}) FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}), JSON_ARRAY())`;
|
|
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 ${B(i, "rn", r)} > ${H(d, r)} AND ${B(i, "rn", r)} <= ${H(d + u, r)}` : u === void 0 ? r` AND ${B(i, "rn", r)} > ${H(d, r)}` : r` AND ${B(i, "rn", r)} <= ${H(u, r)}`;
|
|
1393
|
+
return r`COALESCE((SELECT JSON_ARRAYAGG(${a} ORDER BY ${B(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())`;
|
|
1394
|
+
}, Va = (e, t, n) => {
|
|
1461
1395
|
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = (t) => e.junction === void 0 ? void 0 : {
|
|
1462
1396
|
projection: e.junction,
|
|
1463
1397
|
source: t
|
|
1464
|
-
}, l = r`${
|
|
1398
|
+
}, l = r`${B(s, i.sourceKey, r)} = ${B(t, "id", r)}`, u = r`${B(o, "id", r)} = ${B(s, i.targetKey, r)}`, d = e.branch.where === void 0 ? r`` : r` AND ${L(W(e.branch.where), r)}`, f = Xa(e, s, r, !0), p = e.branch.orderBy ?? [];
|
|
1465
1399
|
if (e.branch.limit === void 0 && e.branch.offset === void 0) {
|
|
1466
|
-
let t =
|
|
1467
|
-
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`${
|
|
1400
|
+
let t = z(o, e.target, e.children, n, c(Aa(s)));
|
|
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`${B(o, e.column, r)} DESC` : r`${B(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())`;
|
|
1468
1402
|
}
|
|
1469
|
-
let m = p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${
|
|
1403
|
+
let m = p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${B(o, e.column, r)} DESC` : r`${B(o, e.column, r)} ASC`))}` : r` ORDER BY ${B(o, "id", r)}`, h = e.branch.limit, g = e.branch.offset, _ = h !== void 0 && g !== void 0 ? r` AND ${B(o, "rn", r)} > ${H(g, r)} AND ${B(o, "rn", r)} <= ${H(g + h, r)}` : h === void 0 ? r` AND ${B(o, "rn", r)} > ${H(g, r)}` : r` AND ${B(o, "rn", r)} <= ${H(h, r)}`, v = e.branch.onJunction === void 0 ? r`` : r` WHERE ${U(W(e.branch.onJunction), s, r)}`, ee = z(o, e.target, e.children, n, c(ka(o)));
|
|
1470
1404
|
if (ee === null) return null;
|
|
1471
|
-
let te = e.junction === void 0 ? r`` :
|
|
1472
|
-
return r`COALESCE((SELECT JSON_ARRAYAGG(${ee} ORDER BY ${
|
|
1473
|
-
},
|
|
1474
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1405
|
+
let te = e.junction === void 0 ? r`` : Oa(e.junction, s, r);
|
|
1406
|
+
return r`COALESCE((SELECT JSON_ARRAYAGG(${ee} ORDER BY ${B(o, "rn", r)}) FROM (SELECT ${r(o)}.*${te}, ${B(s, i.sourceKey, r)} AS ${r(`__src_${i.sourceKey}`)}, ROW_NUMBER() OVER (PARTITION BY ${B(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 ${B(o, `__src_${i.sourceKey}`, r)} = ${B(t, "id", r)}${d}${_}), JSON_ARRAY())`;
|
|
1407
|
+
}, Ha = (e, t, n) => {
|
|
1408
|
+
let r = n.sql, i = n.nextAlias(), a = Ua(i, t.table, t.children, n);
|
|
1475
1409
|
if (a === null) return null;
|
|
1476
|
-
let o = e.predicate ? r` WHERE ${
|
|
1410
|
+
let o = e.predicate ? r` WHERE ${U(e.predicate, i, r)}` : r``, s = u(e).length > 0 ? r` ORDER BY ${r.csv(u(e).map((e) => e.direction === "desc" ? r`${B(i, e.column, r)} DESC` : r`${B(i, e.column, r)} ASC`))}` : r``, c = r``, l = r``;
|
|
1477
1411
|
if (e.skip !== void 0) {
|
|
1478
|
-
let t =
|
|
1479
|
-
l = e.take === void 0 ? r`${t} OFFSET ${
|
|
1480
|
-
} else e.take !== void 0 && (c = r`TOP ${
|
|
1481
|
-
let
|
|
1482
|
-
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}${
|
|
1483
|
-
},
|
|
1412
|
+
let t = u(e).length > 0 ? s : r` ORDER BY (SELECT NULL)`;
|
|
1413
|
+
l = e.take === void 0 ? r`${t} OFFSET ${H(e.skip, r)} ROWS` : r`${t} OFFSET ${H(e.skip, r)} ROWS FETCH NEXT ${H(e.take, r)} ROWS ONLY`;
|
|
1414
|
+
} else e.take !== void 0 && (c = r`TOP ${H(e.take, r)} `);
|
|
1415
|
+
let d = e.skip === void 0 ? s : r``;
|
|
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}${d}${l}`;
|
|
1417
|
+
}, Ua = (e, t, n, r, i) => {
|
|
1484
1418
|
let a = r.sql, o = [];
|
|
1485
|
-
for (let n of Object.keys(t.fields)) o.push(a`${
|
|
1486
|
-
if (i !== void 0) for (let e of i.projection.present) o.push(a`${
|
|
1419
|
+
for (let n of Object.keys(t.fields)) o.push(a`${B(e, n, a)} AS ${a(n)}`);
|
|
1420
|
+
if (i !== void 0) for (let e of i.projection.present) o.push(a`${B(i.source.alias, i.source.physical(e), a)} AS ${Wa(`_junction.${e}`, a)}`);
|
|
1487
1421
|
for (let t of n) {
|
|
1488
|
-
let n =
|
|
1422
|
+
let n = Ga(t, e, r);
|
|
1489
1423
|
if (n === null) return null;
|
|
1490
1424
|
o.push(n);
|
|
1491
1425
|
}
|
|
1492
1426
|
return a.csv(o);
|
|
1493
|
-
},
|
|
1427
|
+
}, Wa = (e, t) => t.unsafe(`[${e.replace(/]/g, "]]")}]`), Ga = (e, t, n) => {
|
|
1494
1428
|
switch (e.relation.kind) {
|
|
1495
|
-
case "one": return
|
|
1496
|
-
case "many": return
|
|
1497
|
-
case "manyToMany": return
|
|
1429
|
+
case "one": return na(e) ? Ja(ra(e), t, n) : Ka(e, t, n);
|
|
1430
|
+
case "many": return Ja(e, t, n);
|
|
1431
|
+
case "manyToMany": return Ya(e, t, n);
|
|
1498
1432
|
}
|
|
1499
|
-
},
|
|
1500
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1433
|
+
}, Ka = (e, t, n) => {
|
|
1434
|
+
let r = n.sql, i = n.nextAlias(), a = Ua(i, e.target, e.children, n);
|
|
1501
1435
|
if (a === null) return null;
|
|
1502
|
-
let o = e.fkSide === "source" ? r`${
|
|
1436
|
+
let o = e.fkSide === "source" ? r`${B(i, "id", r)} = ${B(t, e.foreignKey, r)}` : r`${B(i, e.foreignKey, r)} = ${B(t, e.sourceKey, r)}`;
|
|
1503
1437
|
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)}`;
|
|
1504
|
-
},
|
|
1438
|
+
}, qa = (e, t, n) => {
|
|
1505
1439
|
if (e.offset !== void 0) {
|
|
1506
|
-
let r = e.orderBy && e.orderBy.length > 0 ? t : n` ORDER BY (SELECT NULL)`, i = e.limit === void 0 ? n`${r} OFFSET ${
|
|
1440
|
+
let r = e.orderBy && e.orderBy.length > 0 ? t : n` ORDER BY (SELECT NULL)`, i = e.limit === void 0 ? n`${r} OFFSET ${H(e.offset, n)} ROWS` : n`${r} OFFSET ${H(e.offset, n)} ROWS FETCH NEXT ${H(e.limit, n)} ROWS ONLY`;
|
|
1507
1441
|
return {
|
|
1508
1442
|
top: n``,
|
|
1509
1443
|
pagination: i,
|
|
@@ -1511,33 +1445,33 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
1511
1445
|
};
|
|
1512
1446
|
}
|
|
1513
1447
|
return {
|
|
1514
|
-
top: e.limit === void 0 ? n`` : n`TOP ${
|
|
1448
|
+
top: e.limit === void 0 ? n`` : n`TOP ${H(e.limit, n)} `,
|
|
1515
1449
|
pagination: n``,
|
|
1516
1450
|
finalOrder: t
|
|
1517
1451
|
};
|
|
1518
|
-
},
|
|
1519
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1452
|
+
}, Ja = (e, t, n) => {
|
|
1453
|
+
let r = n.sql, i = n.nextAlias(), a = Ua(i, e.target, e.children, n);
|
|
1520
1454
|
if (a === null) return null;
|
|
1521
|
-
let o = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1522
|
-
return r`ISNULL(JSON_QUERY((SELECT ${c}${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${
|
|
1523
|
-
},
|
|
1524
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
1455
|
+
let o = e.branch.where === void 0 ? r`` : r` AND ${U(e.branch.where, i, r)}`, s = R(i, e.branch.orderBy, r), { top: c, pagination: l, finalOrder: u } = qa(e.branch, s, r);
|
|
1456
|
+
return r`ISNULL(JSON_QUERY((SELECT ${c}${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${B(i, e.foreignKey, r)} = ${B(t, e.sourceKey, r)}${o}${u}${l} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
|
|
1457
|
+
}, Ya = (e, t, n) => {
|
|
1458
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = Ua(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
1525
1459
|
projection: e.junction,
|
|
1526
|
-
source:
|
|
1460
|
+
source: Aa(s)
|
|
1527
1461
|
});
|
|
1528
1462
|
if (c === null) return null;
|
|
1529
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1530
|
-
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 ${
|
|
1531
|
-
},
|
|
1463
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${U(e.branch.where, o, r)}`, u = Xa(e, s, r), d = R(o, e.branch.orderBy, r), { top: f, pagination: p, finalOrder: m } = qa(e.branch, d, r);
|
|
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 ${B(o, "id", r)} = ${B(s, i.targetKey, r)} WHERE ${B(s, i.sourceKey, r)} = ${B(t, "id", r)}${u}${l}${m}${p} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
|
|
1465
|
+
}, B = (e, t, n) => e === void 0 ? n`${n(t)}` : n`${n(e)}.${n(t)}`, V = (e, t) => t.unsafe(`'${e.replace(/'/g, "''")}'`), H = (e, t) => {
|
|
1532
1466
|
if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw Error(`literalInt: expected non-negative integer, got ${e}`);
|
|
1533
1467
|
return t.unsafe(String(e));
|
|
1534
|
-
},
|
|
1468
|
+
}, U = (e, t, n) => L(Za(e, t), n), Xa = (e, t, n, r = !1) => {
|
|
1535
1469
|
let i = e.branch.onJunction;
|
|
1536
|
-
return i === void 0 ? n`` : n` AND ${
|
|
1537
|
-
},
|
|
1538
|
-
if ("not" in e) return { not:
|
|
1539
|
-
if ("and" in e) return { and: e.and.map((e) =>
|
|
1540
|
-
if ("or" in e) return { or: e.or.map((e) =>
|
|
1470
|
+
return i === void 0 ? n`` : n` AND ${U(r ? W(i) : i, t, n)}`;
|
|
1471
|
+
}, Za = (e, t) => {
|
|
1472
|
+
if ("not" in e) return { not: Za(e.not, t) };
|
|
1473
|
+
if ("and" in e) return { and: e.and.map((e) => Za(e, t)) };
|
|
1474
|
+
if ("or" in e) return { or: e.or.map((e) => Za(e, t)) };
|
|
1541
1475
|
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
1542
1476
|
let n = e;
|
|
1543
1477
|
return {
|
|
@@ -1551,264 +1485,55 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
1551
1485
|
...n,
|
|
1552
1486
|
column: `${t}.${n.column}`
|
|
1553
1487
|
};
|
|
1554
|
-
},
|
|
1555
|
-
if ("not" in e) return { not:
|
|
1556
|
-
if ("and" in e) return { and: e.and.map((e) =>
|
|
1557
|
-
if ("or" in e) return { or: e.or.map((e) =>
|
|
1488
|
+
}, W = (e) => {
|
|
1489
|
+
if ("not" in e) return { not: W(e.not) };
|
|
1490
|
+
if ("and" in e) return { and: e.and.map((e) => W(e)) };
|
|
1491
|
+
if ("or" in e) return { or: e.or.map((e) => W(e)) };
|
|
1558
1492
|
if (e.op === "subquery-in" || e.op === "subquery-not-in" || e.op === "exists" || e.op === "not-exists") return e;
|
|
1559
1493
|
let t = e;
|
|
1560
1494
|
return {
|
|
1561
1495
|
...t,
|
|
1562
|
-
value:
|
|
1496
|
+
value: Qa(t.value)
|
|
1563
1497
|
};
|
|
1564
|
-
},
|
|
1565
|
-
e.actors !== void 0 && (
|
|
1566
|
-
},
|
|
1498
|
+
}, Qa = (e) => e == null ? e : e instanceof Date ? e.toISOString() : typeof e == "boolean" ? +!!e : Array.isArray(e) ? e.map((e) => Qa(e)) : e, $a = Symbol.for("@voltro/database/coreTablesRegistry"), eo = globalThis, to = eo[$a] ?? (eo[$a] = {}), no = (e) => {
|
|
1499
|
+
e.actors !== void 0 && (to.actors = e.actors), e.tenants !== void 0 && (to.tenants = e.tenants);
|
|
1500
|
+
}, ro = (e, t) => () => {
|
|
1567
1501
|
let n = e();
|
|
1568
1502
|
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`);
|
|
1569
1503
|
return n();
|
|
1570
|
-
},
|
|
1571
|
-
id:
|
|
1572
|
-
kind:
|
|
1504
|
+
}, io = () => ro(() => to.actors, "actors"), ao = () => ro(() => to.tenants, "tenants"), oo = C("actors", {
|
|
1505
|
+
id: T(),
|
|
1506
|
+
kind: y().oneOf([
|
|
1573
1507
|
"user",
|
|
1574
1508
|
"serviceAccount",
|
|
1575
1509
|
"apiKey",
|
|
1576
1510
|
"system"
|
|
1577
|
-
]),
|
|
1578
|
-
displayName:
|
|
1579
|
-
createdAt:
|
|
1580
|
-
}),
|
|
1581
|
-
let n = (e) => {
|
|
1582
|
-
if (typeof e != "string" || !/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/.test(e)) return null;
|
|
1583
|
-
let [t = "", n = ""] = e.replace(/^[+-]/, "").split("."), r = t.replace(/^0+/, "") || "0";
|
|
1584
|
-
return {
|
|
1585
|
-
negative: e.startsWith("-") && /[1-9]/.test(r + n),
|
|
1586
|
-
whole: r,
|
|
1587
|
-
fraction: n
|
|
1588
|
-
};
|
|
1589
|
-
}, r = n(e), i = n(t);
|
|
1590
|
-
if (!r || !i) return null;
|
|
1591
|
-
if (r.negative !== i.negative) return r.negative ? -1 : 1;
|
|
1592
|
-
let a = r.whole.length - i.whole.length;
|
|
1593
|
-
if (a === 0 && (a = r.whole === i.whole ? 0 : r.whole > i.whole ? 1 : -1), a === 0) {
|
|
1594
|
-
let e = Math.max(r.fraction.length, i.fraction.length), t = r.fraction.padEnd(e, "0"), n = i.fraction.padEnd(e, "0");
|
|
1595
|
-
a = t === n ? 0 : t > n ? 1 : -1;
|
|
1596
|
-
}
|
|
1597
|
-
return a === 0 ? 0 : (a > 0 ? 1 : -1) * (r.negative ? -1 : 1);
|
|
1598
|
-
}, ka = (e, t) => ({
|
|
1599
|
-
column: e,
|
|
1600
|
-
op: "eq",
|
|
1601
|
-
value: t
|
|
1602
|
-
}), Aa = (e, t) => ({
|
|
1603
|
-
column: e,
|
|
1604
|
-
op: "neq",
|
|
1605
|
-
value: t
|
|
1606
|
-
}), ja = (e, t) => ({
|
|
1607
|
-
column: e,
|
|
1608
|
-
op: "gt",
|
|
1609
|
-
value: t
|
|
1610
|
-
}), Ma = (e, t) => ({
|
|
1611
|
-
column: e,
|
|
1612
|
-
op: "gte",
|
|
1613
|
-
value: t
|
|
1614
|
-
}), Na = (e, t) => ({
|
|
1615
|
-
column: e,
|
|
1616
|
-
op: "lt",
|
|
1617
|
-
value: t
|
|
1618
|
-
}), Pa = (e, t) => ({
|
|
1619
|
-
column: e,
|
|
1620
|
-
op: "lte",
|
|
1621
|
-
value: t
|
|
1622
|
-
}), Fa = (e, t) => ({
|
|
1623
|
-
column: e,
|
|
1624
|
-
op: "in",
|
|
1625
|
-
value: t
|
|
1626
|
-
}), Ia = (e, t) => ({
|
|
1627
|
-
column: e,
|
|
1628
|
-
op: "notIn",
|
|
1629
|
-
value: t
|
|
1630
|
-
}), La = (e, t) => ({
|
|
1631
|
-
column: e,
|
|
1632
|
-
op: "contains",
|
|
1633
|
-
value: t
|
|
1634
|
-
}), Ra = (e, t) => ({
|
|
1635
|
-
column: e,
|
|
1636
|
-
op: "startsWith",
|
|
1637
|
-
value: t
|
|
1638
|
-
}), za = (e, t) => ({
|
|
1639
|
-
column: e,
|
|
1640
|
-
op: "arrayContains",
|
|
1641
|
-
value: t
|
|
1642
|
-
}), Ba = (e, t) => ({
|
|
1643
|
-
column: e,
|
|
1644
|
-
op: "arrayOverlaps",
|
|
1645
|
-
value: t
|
|
1646
|
-
}), Va = (e, t) => ({
|
|
1647
|
-
column: e,
|
|
1648
|
-
op: "arrayHas",
|
|
1649
|
-
value: t
|
|
1650
|
-
}), Ha = {
|
|
1651
|
-
column: "id",
|
|
1652
|
-
op: "in",
|
|
1653
|
-
value: []
|
|
1654
|
-
}, Ua = (e) => ({
|
|
1655
|
-
column: e,
|
|
1656
|
-
op: "isNull"
|
|
1657
|
-
}), Wa = (e) => ({
|
|
1658
|
-
column: e,
|
|
1659
|
-
op: "isNotNull"
|
|
1660
|
-
}), Ga = (e, t) => ({
|
|
1661
|
-
column: e,
|
|
1662
|
-
op: "spatial",
|
|
1663
|
-
value: t
|
|
1664
|
-
}), Ka = (...e) => ({ and: e }), qa = (...e) => ({ or: e }), Ja = (e) => ({ not: e }), Ya = (e, ...t) => {
|
|
1665
|
-
if (t.length === 0) throw Error(`jsonField("${e}"): at least one path segment is required`);
|
|
1666
|
-
let n = (n, r) => ({
|
|
1667
|
-
column: e,
|
|
1668
|
-
path: t,
|
|
1669
|
-
op: n,
|
|
1670
|
-
value: r
|
|
1671
|
-
});
|
|
1672
|
-
return {
|
|
1673
|
-
eq: (e) => n("eq", e),
|
|
1674
|
-
neq: (e) => n("neq", e),
|
|
1675
|
-
gt: (e) => n("gt", e),
|
|
1676
|
-
gte: (e) => n("gte", e),
|
|
1677
|
-
lt: (e) => n("lt", e),
|
|
1678
|
-
lte: (e) => n("lte", e),
|
|
1679
|
-
inSet: (e) => n("in", e),
|
|
1680
|
-
notInSet: (e) => n("notIn", e),
|
|
1681
|
-
contains: (e) => n("contains", e),
|
|
1682
|
-
startsWith: (e) => n("startsWith", e),
|
|
1683
|
-
isNull: () => n("isNull"),
|
|
1684
|
-
isNotNull: () => n("isNotNull")
|
|
1685
|
-
};
|
|
1686
|
-
}, Xa = (e) => "descriptor" in e ? e.descriptor : e, Za = (e, t) => ({
|
|
1687
|
-
column: e,
|
|
1688
|
-
op: "subquery-in",
|
|
1689
|
-
subquery: Xa(t)
|
|
1690
|
-
}), Qa = (e, t) => ({
|
|
1691
|
-
column: e,
|
|
1692
|
-
op: "subquery-not-in",
|
|
1693
|
-
subquery: Xa(t)
|
|
1694
|
-
}), $a = (e) => ({
|
|
1695
|
-
op: "exists",
|
|
1696
|
-
subquery: Xa(e)
|
|
1697
|
-
}), eo = (e) => ({
|
|
1698
|
-
op: "not-exists",
|
|
1699
|
-
subquery: Xa(e)
|
|
1700
|
-
}), to = (e, t) => e === t || e instanceof Date && t instanceof Date && e.getTime() === t.getTime(), no = (e, t) => {
|
|
1701
|
-
if (e == null || t == null) return null;
|
|
1702
|
-
let n = e instanceof Date ? e.getTime() : e, r = t instanceof Date ? t.getTime() : t;
|
|
1703
|
-
return typeof n == typeof r ? n === r ? 0 : n > r ? 1 : -1 : null;
|
|
1704
|
-
}, ro = (e, t, n = null, r = {}) => {
|
|
1705
|
-
if (!t) return !1;
|
|
1706
|
-
if ("not" in e) return !ro(e.not, t, n, r);
|
|
1707
|
-
if ("and" in e) {
|
|
1708
|
-
for (let i of e.and) if (!ro(i, t, n, r)) return !1;
|
|
1709
|
-
return !0;
|
|
1710
|
-
}
|
|
1711
|
-
if ("or" in e) {
|
|
1712
|
-
for (let i of e.or) if (ro(i, t, n, r)) return !0;
|
|
1713
|
-
return !1;
|
|
1714
|
-
}
|
|
1715
|
-
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
1716
|
-
if (!n) return !1;
|
|
1717
|
-
let i = n.get(e.subquery);
|
|
1718
|
-
if (!(i instanceof Set)) return !1;
|
|
1719
|
-
let a = t[e.column], o = r[e.column]?.type === "decimal" ? [...i].some((e) => Oa(a, e) === 0) : i.has(a);
|
|
1720
|
-
return e.op === "subquery-in" ? o : !o;
|
|
1721
|
-
}
|
|
1722
|
-
if (e.op === "exists" || e.op === "not-exists") {
|
|
1723
|
-
if (!n) return !1;
|
|
1724
|
-
let t = n.get(e.subquery), r = typeof t == "number" ? t > 0 : t instanceof Set && t.size > 0;
|
|
1725
|
-
return e.op === "exists" ? r : !r;
|
|
1726
|
-
}
|
|
1727
|
-
let i = e, a = t[i.column], o = r[i.column]?.type === "decimal", s = (e, t) => o && e != null && t != null ? Oa(e, t) === 0 : to(e, t), c = o ? Oa : no;
|
|
1728
|
-
switch (i.op) {
|
|
1729
|
-
case "eq": return s(a, i.value);
|
|
1730
|
-
case "neq": return !s(a, i.value);
|
|
1731
|
-
case "gt": return (c(a, i.value) ?? -1) > 0;
|
|
1732
|
-
case "gte": return (c(a, i.value) ?? -1) >= 0;
|
|
1733
|
-
case "lt": return (c(a, i.value) ?? 1) < 0;
|
|
1734
|
-
case "lte": return (c(a, i.value) ?? 1) <= 0;
|
|
1735
|
-
case "in": return Array.isArray(i.value) && i.value.some((e) => s(a, e));
|
|
1736
|
-
case "notIn": return Array.isArray(i.value) && !i.value.some((e) => s(a, e));
|
|
1737
|
-
case "contains": return typeof a == "string" && typeof i.value == "string" && a.toLowerCase().includes(i.value.toLowerCase());
|
|
1738
|
-
case "startsWith": return typeof a == "string" && typeof i.value == "string" && a.startsWith(i.value);
|
|
1739
|
-
case "arrayContains": {
|
|
1740
|
-
let e = Array.isArray(a) ? a : [];
|
|
1741
|
-
return (Array.isArray(i.value) ? i.value : []).every((t) => e.includes(t));
|
|
1742
|
-
}
|
|
1743
|
-
case "arrayOverlaps": {
|
|
1744
|
-
let e = Array.isArray(a) ? a : [];
|
|
1745
|
-
return (Array.isArray(i.value) ? i.value : []).some((t) => e.includes(t));
|
|
1746
|
-
}
|
|
1747
|
-
case "arrayHas": return Array.isArray(a) && a.includes(i.value);
|
|
1748
|
-
case "isNull": return a == null;
|
|
1749
|
-
case "isNotNull": return a != null;
|
|
1750
|
-
case "spatial": throw Error("@voltro/plugin-postgis: spatial predicates (ST_DWithin / ST_Contains / ST_Within / ST_Intersects / bbox &&) are not evaluable in-memory — use them in one-shot ctx.store.query reads, not reactive subscriptions.");
|
|
1751
|
-
}
|
|
1752
|
-
}, io = function* (e) {
|
|
1753
|
-
if ("not" in e) {
|
|
1754
|
-
yield* io(e.not);
|
|
1755
|
-
return;
|
|
1756
|
-
}
|
|
1757
|
-
if ("and" in e) {
|
|
1758
|
-
for (let t of e.and) yield* io(t);
|
|
1759
|
-
return;
|
|
1760
|
-
}
|
|
1761
|
-
if ("or" in e) {
|
|
1762
|
-
for (let t of e.or) yield* io(t);
|
|
1763
|
-
return;
|
|
1764
|
-
}
|
|
1765
|
-
e.op === "subquery-in" || e.op === "subquery-not-in" ? yield {
|
|
1766
|
-
kind: "in",
|
|
1767
|
-
descriptor: e.subquery
|
|
1768
|
-
} : (e.op === "exists" || e.op === "not-exists") && (yield {
|
|
1769
|
-
kind: "exists",
|
|
1770
|
-
descriptor: e.subquery
|
|
1771
|
-
});
|
|
1772
|
-
}, ao = function* (e, t = !0) {
|
|
1773
|
-
if ("not" in e) {
|
|
1774
|
-
yield* ao(e.not, !1);
|
|
1775
|
-
return;
|
|
1776
|
-
}
|
|
1777
|
-
if ("and" in e) {
|
|
1778
|
-
for (let n of e.and) yield* ao(n, t);
|
|
1779
|
-
return;
|
|
1780
|
-
}
|
|
1781
|
-
if ("or" in e) {
|
|
1782
|
-
for (let t of e.or) yield* ao(t, !1);
|
|
1783
|
-
return;
|
|
1784
|
-
}
|
|
1785
|
-
e.op !== "subquery-in" && e.op !== "subquery-not-in" && e.op !== "exists" && e.op !== "not-exists" && (yield {
|
|
1786
|
-
...e,
|
|
1787
|
-
conjunctive: t
|
|
1788
|
-
});
|
|
1789
|
-
}, oo = (e, t) => ({
|
|
1511
|
+
]).safe(),
|
|
1512
|
+
displayName: y().nullable().sensitive("fullName"),
|
|
1513
|
+
createdAt: w().default("now")
|
|
1514
|
+
}), so = (e, t) => ({
|
|
1790
1515
|
...t,
|
|
1791
1516
|
...e,
|
|
1792
1517
|
origin: e.origin ?? "injected"
|
|
1793
|
-
}),
|
|
1518
|
+
}), co = (e, t, n = {}) => ({
|
|
1794
1519
|
table: e,
|
|
1795
1520
|
op: "insert",
|
|
1796
1521
|
old: null,
|
|
1797
1522
|
new: t,
|
|
1798
1523
|
...n
|
|
1799
|
-
}),
|
|
1524
|
+
}), lo = (e, t, n, r = {}) => ({
|
|
1800
1525
|
table: e,
|
|
1801
1526
|
op: "update",
|
|
1802
1527
|
old: t,
|
|
1803
1528
|
new: n,
|
|
1804
1529
|
...r
|
|
1805
|
-
}),
|
|
1530
|
+
}), uo = (e, t, n = {}) => ({
|
|
1806
1531
|
table: e,
|
|
1807
1532
|
op: "delete",
|
|
1808
1533
|
old: t,
|
|
1809
1534
|
new: null,
|
|
1810
1535
|
...n
|
|
1811
|
-
}),
|
|
1536
|
+
}), fo = (e, t, n = {}) => {
|
|
1812
1537
|
let { at: r = "2026-01-01T00:00:00.000Z", column: i = "deletedAt", ...a } = n;
|
|
1813
1538
|
return {
|
|
1814
1539
|
table: e,
|
|
@@ -1823,13 +1548,13 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
1823
1548
|
},
|
|
1824
1549
|
...a
|
|
1825
1550
|
};
|
|
1826
|
-
},
|
|
1551
|
+
}, po = (e) => e == null ? "null" : e instanceof Date ? JSON.stringify(e.toISOString()) : typeof e == "bigint" ? JSON.stringify(e.toString()) : Array.isArray(e) ? `[${e.map(po).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)}:${po(t)}`).join(",")}}` : JSON.stringify(e) ?? "null", mo = (e) => Fn("sha256").update([
|
|
1827
1552
|
e.pipe,
|
|
1828
1553
|
e.op,
|
|
1829
1554
|
e.key,
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
].join("\0")).digest("hex").slice(0, 32),
|
|
1555
|
+
po(e.next),
|
|
1556
|
+
po(e.prev)
|
|
1557
|
+
].join("\0")).digest("hex").slice(0, 32), ho = (e, t) => `${e}:${t}`, go = (e) => {
|
|
1833
1558
|
let t = e.lastIndexOf(":");
|
|
1834
1559
|
if (t <= 0) return null;
|
|
1835
1560
|
let n = Number(e.slice(t + 1));
|
|
@@ -1837,7 +1562,7 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
1837
1562
|
digest: e.slice(0, t),
|
|
1838
1563
|
occurrence: n
|
|
1839
1564
|
};
|
|
1840
|
-
},
|
|
1565
|
+
}, _o = class {
|
|
1841
1566
|
#e = /* @__PURE__ */ new Map();
|
|
1842
1567
|
#t;
|
|
1843
1568
|
#n;
|
|
@@ -1859,7 +1584,7 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
1859
1584
|
}
|
|
1860
1585
|
seedFromChangeKeys(e, t) {
|
|
1861
1586
|
for (let n of e) {
|
|
1862
|
-
let e =
|
|
1587
|
+
let e = go(n);
|
|
1863
1588
|
if (e === null) continue;
|
|
1864
1589
|
let r = this.#e.get(e.digest), i = Math.max(r?.count ?? 0, e.occurrence + 1);
|
|
1865
1590
|
this.#e.set(e.digest, {
|
|
@@ -1880,70 +1605,70 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
1880
1605
|
this.#e.delete(e.value);
|
|
1881
1606
|
}
|
|
1882
1607
|
}
|
|
1883
|
-
},
|
|
1884
|
-
let t = Number(e[
|
|
1608
|
+
}, vo = "VOLTRO_CHANGE_CLAIMS_TTL_HOURS", yo = 1, bo = (e = process.env) => {
|
|
1609
|
+
let t = Number(e[vo]);
|
|
1885
1610
|
return (Number.isFinite(t) && t > 0 ? t : 1) * 2 * 36e5;
|
|
1886
|
-
},
|
|
1887
|
-
let t = e ??
|
|
1611
|
+
}, xo = new In(), So = (e, t) => xo.run(e, t), Co = () => xo.getStore(), wo = (e) => {
|
|
1612
|
+
let t = e ?? xo.getStore();
|
|
1888
1613
|
return t === void 0 ? {} : {
|
|
1889
1614
|
...t.traceId === void 0 ? {} : { traceId: t.traceId },
|
|
1890
1615
|
...t.subjectId === void 0 ? {} : { subjectId: t.subjectId },
|
|
1891
1616
|
...t.procedure === void 0 ? {} : { procedure: t.procedure },
|
|
1892
1617
|
...t.via === void 0 ? {} : { via: t.via }
|
|
1893
1618
|
};
|
|
1894
|
-
},
|
|
1895
|
-
let t =
|
|
1896
|
-
return t === void 0 ? e(void 0) :
|
|
1897
|
-
},
|
|
1898
|
-
for (let [t, n] of
|
|
1899
|
-
let r = n.filter((t) => e - t.at <
|
|
1900
|
-
|
|
1901
|
-
}
|
|
1902
|
-
},
|
|
1619
|
+
}, To = (e) => {
|
|
1620
|
+
let t = xo.getStore();
|
|
1621
|
+
return t === void 0 ? e(void 0) : xo.run(t, () => e(t));
|
|
1622
|
+
}, Eo = 3e4, Do = 1e4, G = /* @__PURE__ */ new Map(), K = 0, Oo = (e, t, n) => `${e}\u0000${t}\u0000${String(n)}`, ko = (e) => {
|
|
1623
|
+
for (let [t, n] of G) {
|
|
1624
|
+
let r = n.filter((t) => e - t.at < Eo);
|
|
1625
|
+
K -= n.length - r.length, r.length === 0 ? G.delete(t) : r.length !== n.length && G.set(t, r);
|
|
1626
|
+
}
|
|
1627
|
+
}, Ao = (e, t) => {
|
|
1903
1628
|
if (t.traceId === void 0 && t.subjectId === void 0 && t.procedure === void 0) return;
|
|
1904
1629
|
let n = Date.now();
|
|
1905
|
-
if (
|
|
1906
|
-
let r =
|
|
1907
|
-
r === void 0 ?
|
|
1630
|
+
if (K >= Do && ko(n), K >= Do) return;
|
|
1631
|
+
let r = G.get(e);
|
|
1632
|
+
r === void 0 ? G.set(e, [{
|
|
1908
1633
|
attribution: t,
|
|
1909
1634
|
at: n
|
|
1910
1635
|
}]) : r.push({
|
|
1911
1636
|
attribution: t,
|
|
1912
1637
|
at: n
|
|
1913
|
-
}),
|
|
1914
|
-
},
|
|
1915
|
-
let t =
|
|
1638
|
+
}), K += 1;
|
|
1639
|
+
}, jo = (e) => {
|
|
1640
|
+
let t = G.get(e);
|
|
1916
1641
|
if (t === void 0 || t.length === 0) return;
|
|
1917
1642
|
let n = t.shift();
|
|
1918
|
-
if (--
|
|
1919
|
-
},
|
|
1920
|
-
let t =
|
|
1643
|
+
if (--K, t.length === 0 && G.delete(e), !(Date.now() - n.at >= Eo)) return n.attribution;
|
|
1644
|
+
}, Mo = (e) => (G.get(e)?.length ?? 0) > 0, q = /* @__PURE__ */ new Map(), No = /* @__PURE__ */ new Map(), Po = /* @__PURE__ */ new Map(), Fo = 250, Io = (e) => {
|
|
1645
|
+
let t = No.get(e);
|
|
1921
1646
|
if (t === void 0) return;
|
|
1922
|
-
|
|
1923
|
-
let n =
|
|
1924
|
-
n !== void 0 && (clearTimeout(n),
|
|
1647
|
+
No.delete(e);
|
|
1648
|
+
let n = Po.get(e);
|
|
1649
|
+
n !== void 0 && (clearTimeout(n), Po.delete(e));
|
|
1925
1650
|
for (let e of t) e();
|
|
1926
|
-
}, Io = (e) => {
|
|
1927
|
-
J.set(e, (J.get(e) ?? 0) + 1);
|
|
1928
1651
|
}, Lo = (e) => {
|
|
1929
|
-
|
|
1652
|
+
q.set(e, (q.get(e) ?? 0) + 1);
|
|
1653
|
+
}, Ro = (e) => {
|
|
1654
|
+
let t = (q.get(e) ?? 0) - 1;
|
|
1930
1655
|
if (t > 0) {
|
|
1931
|
-
|
|
1656
|
+
q.set(e, t);
|
|
1932
1657
|
return;
|
|
1933
1658
|
}
|
|
1934
|
-
|
|
1935
|
-
},
|
|
1936
|
-
let i = n == null ? void 0 :
|
|
1659
|
+
q.delete(e), Io(e);
|
|
1660
|
+
}, zo = (e, t, n, r) => {
|
|
1661
|
+
let i = n == null ? void 0 : Oo(e, t, n), a = () => r(i === void 0 ? void 0 : jo(i));
|
|
1937
1662
|
if (i === void 0) {
|
|
1938
1663
|
a();
|
|
1939
1664
|
return;
|
|
1940
1665
|
}
|
|
1941
|
-
if (
|
|
1666
|
+
if (Mo(i)) {
|
|
1942
1667
|
a();
|
|
1943
1668
|
return;
|
|
1944
1669
|
}
|
|
1945
|
-
let o =
|
|
1946
|
-
if (o === void 0 && (
|
|
1670
|
+
let o = No.get(e);
|
|
1671
|
+
if (o === void 0 && (q.get(e) ?? 0) === 0) {
|
|
1947
1672
|
a();
|
|
1948
1673
|
return;
|
|
1949
1674
|
}
|
|
@@ -1951,91 +1676,91 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
1951
1676
|
o.push(a);
|
|
1952
1677
|
return;
|
|
1953
1678
|
}
|
|
1954
|
-
|
|
1955
|
-
let s = setTimeout(() =>
|
|
1956
|
-
typeof s == "object" && typeof s.unref == "function" && s.unref(),
|
|
1957
|
-
},
|
|
1958
|
-
|
|
1959
|
-
for (let e of
|
|
1960
|
-
|
|
1961
|
-
},
|
|
1962
|
-
|
|
1679
|
+
No.set(e, [a]);
|
|
1680
|
+
let s = setTimeout(() => Io(e), Fo);
|
|
1681
|
+
typeof s == "object" && typeof s.unref == "function" && s.unref(), Po.set(e, s);
|
|
1682
|
+
}, Bo = () => {
|
|
1683
|
+
G.clear(), K = 0, q.clear();
|
|
1684
|
+
for (let e of Po.values()) clearTimeout(e);
|
|
1685
|
+
Po.clear(), No.clear();
|
|
1686
|
+
}, Vo = () => K, Ho = 64, Uo = "\0", Wo = 32, Go = (e, ...t) => `${e}_${Fn("sha256").update(t.map(String).join(Uo)).digest("hex").slice(0, Wo)}`, Ko = (e) => e.length + 1 + Wo, J = /* @__PURE__ */ new Map(), qo = (e, t) => {
|
|
1687
|
+
J.set(e, {
|
|
1963
1688
|
recorder: t.recorder,
|
|
1964
1689
|
tables: new Set(t.tables),
|
|
1965
1690
|
ownTables: new Set(t.ownTables)
|
|
1966
1691
|
});
|
|
1967
|
-
},
|
|
1968
|
-
|
|
1969
|
-
},
|
|
1970
|
-
let t =
|
|
1971
|
-
if (t !== void 0) return t.n += 1,
|
|
1692
|
+
}, Jo = (e) => {
|
|
1693
|
+
J.delete(e);
|
|
1694
|
+
}, Yo = () => J.clear(), Xo = new In(), Zo = (e) => Xo.run({ n: 1 }, e), Qo = (e) => O.suspend(() => {
|
|
1695
|
+
let t = Xo.getStore();
|
|
1696
|
+
if (t !== void 0) return t.n += 1, O.ensuring(e, O.sync(() => {
|
|
1972
1697
|
--t.n;
|
|
1973
1698
|
}));
|
|
1974
1699
|
let n = { n: 1 };
|
|
1975
|
-
return
|
|
1700
|
+
return Xo.enterWith(n), O.ensuring(e, O.sync(() => {
|
|
1976
1701
|
--n.n;
|
|
1977
1702
|
}));
|
|
1978
|
-
}),
|
|
1979
|
-
if (
|
|
1980
|
-
for (let t of
|
|
1703
|
+
}), $o = () => (Xo.getStore()?.n ?? 0) > 0, es = (e) => {
|
|
1704
|
+
if (J.size === 0 || (Xo.getStore()?.n ?? 0) > 0) return !1;
|
|
1705
|
+
for (let t of J.values()) if (!t.ownTables.has(e) && t.tables.has(e)) return !0;
|
|
1981
1706
|
return !1;
|
|
1982
|
-
},
|
|
1983
|
-
if (
|
|
1984
|
-
for (let [n, r] of
|
|
1707
|
+
}, ts = async (e, t) => {
|
|
1708
|
+
if (J.size !== 0) {
|
|
1709
|
+
for (let [n, r] of J.entries()) if (!r.ownTables.has(t.table) && r.tables.has(t.table)) try {
|
|
1985
1710
|
await r.recorder(e, t);
|
|
1986
1711
|
} catch (e) {
|
|
1987
|
-
let r =
|
|
1712
|
+
let r = xr(e);
|
|
1988
1713
|
throw r === void 0 ? e : Error(`write recorder '${n}' failed while recording a ${t.op} on '${t.table}': ${r}`, { cause: e });
|
|
1989
1714
|
}
|
|
1990
1715
|
}
|
|
1991
|
-
},
|
|
1716
|
+
}, ns = jn.exponential({
|
|
1992
1717
|
start: 5e-4,
|
|
1993
1718
|
factor: 2,
|
|
1994
1719
|
count: 16
|
|
1995
|
-
}),
|
|
1996
|
-
let n = `${e}\u0000${t}`, r =
|
|
1720
|
+
}), rs = k.counter("voltro_db_queries_total", { description: "Database operations executed, by dialect and operation kind." }), is = k.histogram("voltro_db_query_duration_seconds", ns, "Database operation duration in seconds, by dialect and operation kind."), as = k.counter("voltro_db_errors_total", { description: "Database operations that threw, by dialect and operation kind." }), os = k.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." }), ss = k.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." }), cs = [], ls = /* @__PURE__ */ new Map(), us = /* @__PURE__ */ new Map(), ds = /* @__PURE__ */ new Map(), fs = (e, t) => {
|
|
1721
|
+
let n = `${e}\u0000${t}`, r = ls.get(n);
|
|
1997
1722
|
if (r !== void 0) return r;
|
|
1998
|
-
let i = (n) =>
|
|
1999
|
-
count: i(
|
|
2000
|
-
duration: i(
|
|
2001
|
-
errors: i(
|
|
1723
|
+
let i = (n) => k.tagged(k.tagged(n, "dialect", e), "op", t), a = {
|
|
1724
|
+
count: i(rs),
|
|
1725
|
+
duration: i(is),
|
|
1726
|
+
errors: i(as)
|
|
2002
1727
|
};
|
|
2003
|
-
return
|
|
2004
|
-
},
|
|
2005
|
-
|
|
2006
|
-
},
|
|
2007
|
-
let n = Math.max(0, (
|
|
2008
|
-
n === 0 ?
|
|
2009
|
-
let r =
|
|
2010
|
-
r === void 0 && (r =
|
|
2011
|
-
},
|
|
2012
|
-
let t =
|
|
2013
|
-
t.count.unsafeUpdate(1,
|
|
2014
|
-
},
|
|
1728
|
+
return ls.set(n, a), a;
|
|
1729
|
+
}, ps = () => {
|
|
1730
|
+
ls.clear(), us.clear(), ds.clear();
|
|
1731
|
+
}, ms = () => ls.size + us.size + ds.size, hs = /* @__PURE__ */ new Map(), gs = (e, t) => {
|
|
1732
|
+
let n = Math.max(0, (hs.get(e) ?? 0) + t);
|
|
1733
|
+
n === 0 ? hs.delete(e) : hs.set(e, n);
|
|
1734
|
+
let r = us.get(e);
|
|
1735
|
+
r === void 0 && (r = k.tagged(os, "dialect", e), us.set(e, r)), r.unsafeUpdate(n, cs);
|
|
1736
|
+
}, _s = (e) => hs.get(e) ?? 0, vs = (e) => {
|
|
1737
|
+
let t = fs(String(e.dialect), e.op);
|
|
1738
|
+
t.count.unsafeUpdate(1, cs), t.duration.unsafeUpdate(e.durationMs / 1e3, cs), e.status === "error" && t.errors.unsafeUpdate(1, cs);
|
|
1739
|
+
}, ys = async (e, t, n) => {
|
|
2015
1740
|
let r = performance.now(), i = String(e);
|
|
2016
|
-
|
|
1741
|
+
gs(i, 1);
|
|
2017
1742
|
let a = "ok";
|
|
2018
1743
|
try {
|
|
2019
1744
|
return await n();
|
|
2020
1745
|
} catch (e) {
|
|
2021
1746
|
throw a = "error", e;
|
|
2022
1747
|
} finally {
|
|
2023
|
-
|
|
1748
|
+
gs(i, -1), vs({
|
|
2024
1749
|
dialect: e,
|
|
2025
1750
|
op: t,
|
|
2026
1751
|
durationMs: performance.now() - r,
|
|
2027
1752
|
status: a
|
|
2028
1753
|
});
|
|
2029
1754
|
}
|
|
2030
|
-
},
|
|
1755
|
+
}, bs = 3e5, xs = (e) => {
|
|
2031
1756
|
if (e == null || e === "") return;
|
|
2032
1757
|
let t = Number(e);
|
|
2033
1758
|
return Number.isFinite(t) && t >= 0 ? Math.floor(t) : void 0;
|
|
2034
|
-
},
|
|
2035
|
-
let n =
|
|
1759
|
+
}, Ss = (e, t = process.env) => xs(t.VOLTRO_DB_EAGER_FALLBACK_WARN_INTERVAL_MS) ?? xs(e) ?? 3e5, Cs = (e, t = {}) => {
|
|
1760
|
+
let n = Ss(t.warnIntervalMs), r = t.now ?? (() => Date.now()), i = /* @__PURE__ */ new Map();
|
|
2036
1761
|
return (t) => {
|
|
2037
|
-
let a = `${t.dialect} ${t.reason}`, o =
|
|
2038
|
-
o === void 0 && (o =
|
|
1762
|
+
let a = `${t.dialect} ${t.reason}`, o = ds.get(a);
|
|
1763
|
+
o === void 0 && (o = k.tagged(k.tagged(ss, "dialect", String(t.dialect)), "reason", t.reason), ds.set(a, o)), o.unsafeUpdate(1, cs);
|
|
2039
1764
|
let s = `${t.table}\u0000${t.reason}`, c = i.get(s), l = c === void 0 || n > 0 && r() - c >= n, u = {
|
|
2040
1765
|
table: t.table,
|
|
2041
1766
|
dialect: String(t.dialect),
|
|
@@ -2049,24 +1774,24 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
2049
1774
|
}
|
|
2050
1775
|
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);
|
|
2051
1776
|
};
|
|
2052
|
-
},
|
|
2053
|
-
if (
|
|
2054
|
-
throw
|
|
2055
|
-
},
|
|
2056
|
-
let t = 0, n =
|
|
1777
|
+
}, ws = (e) => {
|
|
1778
|
+
if (An.isSuccess(e)) return e.value;
|
|
1779
|
+
throw Dn.squash(e.cause);
|
|
1780
|
+
}, Ts = "10 millis", Es = 3, Ds = (e) => Nn.exponential(Ts).pipe(Nn.compose(Nn.recurs(Es)), Nn.whileInput(e)), Os = async (e) => {
|
|
1781
|
+
let t = 0, n = O.suspend(() => {
|
|
2057
1782
|
let n = ++t;
|
|
2058
|
-
return e.withTransaction(
|
|
2059
|
-
if (
|
|
2060
|
-
let r = t.value, i =
|
|
1783
|
+
return e.withTransaction(O.flatMap(O.serviceOption(Ln), (t) => {
|
|
1784
|
+
if (A.isNone(t)) return O.fail(/* @__PURE__ */ Error(`${e.label}: TransactionConnection unexpectedly missing inside withTransaction.`));
|
|
1785
|
+
let r = t.value, i = O.tryPromise({
|
|
2061
1786
|
try: () => e.body(r, n),
|
|
2062
1787
|
catch: (e) => e
|
|
2063
1788
|
});
|
|
2064
|
-
return e.prepare === void 0 ? i :
|
|
2065
|
-
})).pipe(
|
|
2066
|
-
}).pipe(
|
|
2067
|
-
return
|
|
2068
|
-
},
|
|
2069
|
-
let t =
|
|
1789
|
+
return e.prepare === void 0 ? i : O.flatMap(e.prepare(r), () => i);
|
|
1790
|
+
})).pipe(O.catchAllDefect((t) => e.isRetryable(t) ? O.fail(t) : O.die(t)));
|
|
1791
|
+
}).pipe(O.retry(Ds(e.isRetryable)), O.withSpan(e.span.name, { attributes: { ...e.span.attributes } }));
|
|
1792
|
+
return ys(e.dialect, "transaction", async () => ws(await e.runPromiseExit(e.wrapProgram === void 0 ? n : e.wrapProgram(n))));
|
|
1793
|
+
}, ks = async (e) => {
|
|
1794
|
+
let t = Co(), n = t === void 0 ? (e) => e() : (e) => So(t, e), r = await Os({
|
|
2070
1795
|
...e,
|
|
2071
1796
|
body: (r) => {
|
|
2072
1797
|
let i = e.makeView(r, t);
|
|
@@ -2077,50 +1802,50 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
2077
1802
|
}
|
|
2078
1803
|
});
|
|
2079
1804
|
return r.view.commitEvents(), r.result;
|
|
2080
|
-
},
|
|
1805
|
+
}, As = /* @__PURE__ */ new Set([
|
|
2081
1806
|
"1213",
|
|
2082
1807
|
"ER_LOCK_DEADLOCK",
|
|
2083
1808
|
"1205",
|
|
2084
1809
|
"ER_LOCK_WAIT_TIMEOUT",
|
|
2085
1810
|
"1020",
|
|
2086
1811
|
"ER_CHECKREAD"
|
|
2087
|
-
]),
|
|
1812
|
+
]), js = /* @__PURE__ */ new Set(["40001", "40P01"]), Ms = /* @__PURE__ */ new Set(["1205"]), Ns = /* @__PURE__ */ new Set([
|
|
2088
1813
|
"SQLITE_BUSY",
|
|
2089
1814
|
"5",
|
|
2090
1815
|
"SQLITE_LOCKED",
|
|
2091
1816
|
"6"
|
|
2092
|
-
]),
|
|
1817
|
+
]), Ps = /write-write conflict|write-read conflict|database is locked|table is locked|database is busy/i, Fs = /* @__PURE__ */ new Set([
|
|
2093
1818
|
1213,
|
|
2094
1819
|
1205,
|
|
2095
1820
|
1020
|
|
2096
|
-
]),
|
|
2097
|
-
...ks,
|
|
1821
|
+
]), Is = /* @__PURE__ */ new Set([
|
|
2098
1822
|
...As,
|
|
2099
1823
|
...js,
|
|
2100
|
-
...Ms
|
|
2101
|
-
|
|
1824
|
+
...Ms,
|
|
1825
|
+
...Ns
|
|
1826
|
+
]), Ls = (e) => cr(e).some(Rs), Rs = (e) => {
|
|
2102
1827
|
let t = e;
|
|
2103
1828
|
for (let e = 0; e < 6 && typeof t == "object" && t; e++) {
|
|
2104
1829
|
let e = t;
|
|
2105
|
-
if (typeof e.errno == "number" &&
|
|
1830
|
+
if (typeof e.errno == "number" && Fs.has(e.errno) || typeof e.number == "number" && Ms.has(String(e.number)) || typeof e.code == "string" && Is.has(e.code) || typeof e.sqlState == "string" && js.has(e.sqlState) || typeof e.message == "string" && Ps.test(e.message)) return !0;
|
|
2106
1831
|
t = e.cause;
|
|
2107
1832
|
}
|
|
2108
1833
|
return !1;
|
|
2109
|
-
},
|
|
2110
|
-
id:
|
|
2111
|
-
fields: { expiresAt:
|
|
1834
|
+
}, zs = "voltro/expires", Bs = () => Ue({
|
|
1835
|
+
id: zs,
|
|
1836
|
+
fields: { expiresAt: w().nullable() },
|
|
2112
1837
|
behaviors: { defaultWhere: () => "expiresAt IS NULL OR expiresAt > now()" }
|
|
2113
|
-
}),
|
|
2114
|
-
id:
|
|
1838
|
+
}), Vs = "voltro/localFirst", Hs = () => Ue({
|
|
1839
|
+
id: Vs,
|
|
2115
1840
|
fields: {}
|
|
2116
|
-
}),
|
|
1841
|
+
}), Us = (e) => e.appliedMixins.some((e) => e.id === Vs), Ws = (e) => {
|
|
2117
1842
|
let t = [];
|
|
2118
|
-
for (let n of Object.values(e))
|
|
1843
|
+
for (let n of Object.values(e)) Us(n) && t.push(n.tableName);
|
|
2119
1844
|
return t;
|
|
2120
|
-
},
|
|
2121
|
-
let i =
|
|
1845
|
+
}, Gs = class extends kn.TaggedError("TableStreamError") {}, Ks = 1e3, qs = (e, t, n, r) => {
|
|
1846
|
+
let i = A.match(r, {
|
|
2122
1847
|
onNone: () => e.where,
|
|
2123
|
-
onSome: (n) => e.where ?
|
|
1848
|
+
onSome: (n) => e.where ? d(e.where, b(t, n)) : b(t, n)
|
|
2124
1849
|
});
|
|
2125
1850
|
return {
|
|
2126
1851
|
table: e.table,
|
|
@@ -2135,19 +1860,19 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
2135
1860
|
...e.includeDeleted === void 0 ? {} : { includeDeleted: e.includeDeleted },
|
|
2136
1861
|
...e.crossTenant === void 0 ? {} : { crossTenant: e.crossTenant }
|
|
2137
1862
|
};
|
|
2138
|
-
},
|
|
2139
|
-
let n = t.pk ?? "id", r = t.chunkSize ??
|
|
2140
|
-
return
|
|
2141
|
-
let a =
|
|
2142
|
-
try: () => e.query(
|
|
2143
|
-
catch: (e) => new
|
|
1863
|
+
}, Js = (e, t) => {
|
|
1864
|
+
let n = t.pk ?? "id", r = t.chunkSize ?? Ks;
|
|
1865
|
+
return Pn.paginateChunkEffect(A.none(), (i) => {
|
|
1866
|
+
let a = O.tryPromise({
|
|
1867
|
+
try: () => e.query(qs(t, n, r, i)),
|
|
1868
|
+
catch: (e) => new Gs({
|
|
2144
1869
|
table: t.table,
|
|
2145
1870
|
cause: e
|
|
2146
1871
|
})
|
|
2147
1872
|
});
|
|
2148
|
-
return (t.retry ? a.pipe(
|
|
1873
|
+
return (t.retry ? a.pipe(O.retry(t.retry)) : a).pipe(O.map((e) => [On.fromIterable(e), e.length === r && e.length > 0 ? A.some(A.some(e[e.length - 1][n])) : A.none()]));
|
|
2149
1874
|
});
|
|
2150
|
-
},
|
|
1875
|
+
}, Ys = (e) => {
|
|
2151
1876
|
let t = e.alpha ?? .5;
|
|
2152
1877
|
if (t < 0 || t > 1) throw Error(`hybridSearch: alpha must be in [0, 1], got ${t}`);
|
|
2153
1878
|
return (n) => {
|
|
@@ -2161,7 +1886,7 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
2161
1886
|
queryText: e.vector.query,
|
|
2162
1887
|
distance: e.vector.distance ?? "cosine",
|
|
2163
1888
|
alpha: t
|
|
2164
|
-
}, i =
|
|
1889
|
+
}, i = ye(n.table, e.fts.indexName, n.fullTextIndexes);
|
|
2165
1890
|
return {
|
|
2166
1891
|
...n,
|
|
2167
1892
|
annClause: r,
|
|
@@ -2174,17 +1899,17 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
2174
1899
|
}
|
|
2175
1900
|
};
|
|
2176
1901
|
};
|
|
2177
|
-
},
|
|
1902
|
+
}, Xs = async (e, t) => {
|
|
2178
1903
|
let n = e.as ?? "embedding", r = t.row[e.from];
|
|
2179
1904
|
if (typeof r != "string" || r.length === 0) return {};
|
|
2180
1905
|
let i = await t.embed(r);
|
|
2181
1906
|
return { [n]: i };
|
|
2182
|
-
},
|
|
1907
|
+
}, Zs = (e) => {
|
|
2183
1908
|
if (!Number.isInteger(e.dimensions) || e.dimensions <= 0) throw Error(`vectorEmbedding: dimensions must be a positive integer, got ${String(e.dimensions)}.`);
|
|
2184
|
-
let t = e.as ?? "embedding", n = (t) =>
|
|
2185
|
-
return
|
|
1909
|
+
let t = e.as ?? "embedding", n = (t) => Xs(e, t);
|
|
1910
|
+
return Ue({
|
|
2186
1911
|
id: "voltro/vectorEmbedding",
|
|
2187
|
-
fields: { [t]:
|
|
1912
|
+
fields: { [t]: Gt(e.dimensions) },
|
|
2188
1913
|
...e.index === !1 ? {} : { indexes: [{
|
|
2189
1914
|
fields: [t],
|
|
2190
1915
|
kind: "hnsw",
|
|
@@ -2199,19 +1924,19 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
2199
1924
|
beforeUpdate: n
|
|
2200
1925
|
}
|
|
2201
1926
|
});
|
|
2202
|
-
},
|
|
1927
|
+
}, Qs = 63, $s = "br_pr", Y = class extends Error {
|
|
2203
1928
|
_tag = "BranchNameInvalid";
|
|
2204
1929
|
constructor(e) {
|
|
2205
1930
|
super(e), this.name = "BranchNameInvalid";
|
|
2206
1931
|
}
|
|
2207
|
-
},
|
|
2208
|
-
if (!Number.isInteger(t) || t < 0) throw new
|
|
2209
|
-
let n =
|
|
2210
|
-
if (n.replace(/_/g, "") === "") throw new
|
|
2211
|
-
let r = `${
|
|
2212
|
-
if (r.length >
|
|
1932
|
+
}, ec = (e, t) => {
|
|
1933
|
+
if (!Number.isInteger(t) || t < 0) throw new Y(`prNumber must be a non-negative integer, got ${String(t)}`);
|
|
1934
|
+
let n = Ii(e);
|
|
1935
|
+
if (n.replace(/_/g, "") === "") throw new Y(`app slug '${e}' has no usable identifier characters`);
|
|
1936
|
+
let r = `${$s}${t}_${n}`;
|
|
1937
|
+
if (r.length > Qs) throw new Y(`branch namespace '${r}' exceeds the ${Qs}-byte identifier limit — use a shorter app slug`);
|
|
2213
1938
|
return r;
|
|
2214
|
-
},
|
|
1939
|
+
}, tc = (e) => e.startsWith($s), nc = {
|
|
2215
1940
|
requested: {
|
|
2216
1941
|
provision: "provisioning",
|
|
2217
1942
|
destroy: "destroying"
|
|
@@ -2230,19 +1955,19 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
2230
1955
|
fail: "failed"
|
|
2231
1956
|
},
|
|
2232
1957
|
destroyed: {}
|
|
2233
|
-
},
|
|
1958
|
+
}, rc = class extends Error {
|
|
2234
1959
|
from;
|
|
2235
1960
|
event;
|
|
2236
1961
|
_tag = "BranchTransitionInvalid";
|
|
2237
1962
|
constructor(e, t) {
|
|
2238
1963
|
super(`invalid branch transition: ${e} --${t}-->`), this.from = e, this.event = t, this.name = "BranchTransitionInvalid";
|
|
2239
1964
|
}
|
|
2240
|
-
},
|
|
2241
|
-
let n =
|
|
2242
|
-
if (n === void 0) throw new
|
|
1965
|
+
}, ic = (e, t) => {
|
|
1966
|
+
let n = nc[e][t];
|
|
1967
|
+
if (n === void 0) throw new rc(e, t);
|
|
2243
1968
|
return n;
|
|
2244
|
-
},
|
|
2245
|
-
if (n === "copy" && (r === void 0 || r === "")) throw new
|
|
1969
|
+
}, ac = (e, t, n, r, i = [], a = []) => {
|
|
1970
|
+
if (n === "copy" && (r === void 0 || r === "")) throw new Y("seed 'copy' requires a parentNamespace to snapshot from");
|
|
2246
1971
|
let o = [{
|
|
2247
1972
|
kind: "create-namespace",
|
|
2248
1973
|
detail: e
|
|
@@ -2271,13 +1996,13 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
2271
1996
|
kind: "seed",
|
|
2272
1997
|
detail: `run boot seeds into ${e}`
|
|
2273
1998
|
}), o;
|
|
2274
|
-
},
|
|
2275
|
-
if (!
|
|
1999
|
+
}, oc = (e) => {
|
|
2000
|
+
if (!tc(e)) throw new Y(`refusing to plan teardown of '${e}' — not a branch namespace`);
|
|
2276
2001
|
return [{
|
|
2277
2002
|
kind: "drop-namespace",
|
|
2278
2003
|
detail: e
|
|
2279
2004
|
}];
|
|
2280
|
-
},
|
|
2005
|
+
}, sc = (e) => {
|
|
2281
2006
|
if (e === void 0 || e === "") return !1;
|
|
2282
2007
|
try {
|
|
2283
2008
|
let t = new URL(e).hostname.toLowerCase();
|
|
@@ -2285,27 +2010,27 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
2285
2010
|
} catch {
|
|
2286
2011
|
return /\bneon\.(tech|build)\b/i.test(e);
|
|
2287
2012
|
}
|
|
2288
|
-
},
|
|
2013
|
+
}, cc = (e) => e.prefer === void 0 ? e.seed === "copy" && sc(e.dbUrl) ? "neon-cow" : "namespace" : e.prefer, lc = (e, t = {}) => [{
|
|
2289
2014
|
kind: "neon-branch-create",
|
|
2290
2015
|
detail: `${t.parentBranch ?? "main"} → ${e} (copy-on-write)`
|
|
2291
|
-
}],
|
|
2292
|
-
if (!
|
|
2016
|
+
}], uc = (e) => {
|
|
2017
|
+
if (!tc(e)) throw new Y(`refusing to plan teardown of '${e}' — not a branch namespace`);
|
|
2293
2018
|
return [{
|
|
2294
2019
|
kind: "neon-branch-delete",
|
|
2295
2020
|
detail: e
|
|
2296
2021
|
}];
|
|
2297
|
-
},
|
|
2022
|
+
}, dc = (e) => e.mechanism === "neon-cow" ? lc(e.branchId, e.neonParentBranch === void 0 ? {} : { parentBranch: e.neonParentBranch }) : ac(e.branchId, e.tableNames, e.seed, e.parentNamespace, e.foreignKeys, e.indexNames), fc = (e, t) => e === "neon-cow" ? uc(t) : oc(t), pc = (e, t, n) => {
|
|
2298
2023
|
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);
|
|
2299
2024
|
return {
|
|
2300
2025
|
evict: i,
|
|
2301
2026
|
rejectNew: r.filter((e) => !a.has(e.namespace)).length >= t.maxBranches
|
|
2302
2027
|
};
|
|
2303
|
-
},
|
|
2304
|
-
let n =
|
|
2028
|
+
}, mc = async (e, t) => {
|
|
2029
|
+
let n = ec(e.appSlug, e.prNumber), r = cc({
|
|
2305
2030
|
seed: e.seed,
|
|
2306
2031
|
...e.dbUrl === void 0 ? {} : { dbUrl: e.dbUrl },
|
|
2307
2032
|
...e.prefer === void 0 ? {} : { prefer: e.prefer }
|
|
2308
|
-
}), i =
|
|
2033
|
+
}), i = dc({
|
|
2309
2034
|
mechanism: r,
|
|
2310
2035
|
branchId: n,
|
|
2311
2036
|
tableNames: e.tableNames,
|
|
@@ -2334,16 +2059,16 @@ var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = async (e, t, n
|
|
|
2334
2059
|
mechanism: r,
|
|
2335
2060
|
steps: i
|
|
2336
2061
|
};
|
|
2337
|
-
},
|
|
2338
|
-
let r =
|
|
2062
|
+
}, hc = async (e, t, n) => {
|
|
2063
|
+
let r = fc(t, e);
|
|
2339
2064
|
return t === "neon-cow" ? await n.neonBranchDelete(e) : await n.dropNamespace(e), r;
|
|
2340
|
-
},
|
|
2065
|
+
}, gc = (e, t, n) => pc(e, t, n), X = (e) => `"${e.replace(/"/g, "\"\"")}"`, _c = {
|
|
2341
2066
|
cascade: "CASCADE",
|
|
2342
2067
|
restrict: "RESTRICT",
|
|
2343
2068
|
setNull: "SET NULL",
|
|
2344
2069
|
noAction: "NO ACTION"
|
|
2345
|
-
},
|
|
2346
|
-
let n = t.columns.map(
|
|
2070
|
+
}, Z = (e) => `'${e.replace(/'/g, "''")}'`, vc = (e, t) => {
|
|
2071
|
+
let n = t.columns.map(Z).join(", ");
|
|
2347
2072
|
return `DO $voltro_branch$
|
|
2348
2073
|
DECLARE derived name;
|
|
2349
2074
|
BEGIN
|
|
@@ -2352,11 +2077,11 @@ BEGIN
|
|
|
2352
2077
|
JOIN pg_class i ON i.oid = x.indexrelid
|
|
2353
2078
|
JOIN pg_class c ON c.oid = x.indrelid
|
|
2354
2079
|
JOIN pg_namespace nsp ON nsp.oid = c.relnamespace
|
|
2355
|
-
WHERE nsp.nspname = ${
|
|
2356
|
-
AND c.relname = ${
|
|
2080
|
+
WHERE nsp.nspname = ${Z(e)}
|
|
2081
|
+
AND c.relname = ${Z(t.table)}
|
|
2357
2082
|
AND NOT x.indisprimary
|
|
2358
2083
|
AND x.indisunique = ${t.unique ? "true" : "false"}
|
|
2359
|
-
AND i.relname <> ${
|
|
2084
|
+
AND i.relname <> ${Z(t.name)}
|
|
2360
2085
|
AND (
|
|
2361
2086
|
SELECT array_agg(att.attname::text ORDER BY k.ord)
|
|
2362
2087
|
FROM unnest(x.indkey::int2[]) WITH ORDINALITY AS k(attnum, ord)
|
|
@@ -2365,24 +2090,24 @@ BEGIN
|
|
|
2365
2090
|
LIMIT 1;
|
|
2366
2091
|
IF derived IS NOT NULL THEN
|
|
2367
2092
|
EXECUTE format('ALTER INDEX %I.%I RENAME TO %I',
|
|
2368
|
-
${
|
|
2093
|
+
${Z(e)}, derived, ${Z(t.name)});
|
|
2369
2094
|
END IF;
|
|
2370
2095
|
END
|
|
2371
2096
|
$voltro_branch$`;
|
|
2372
2097
|
}, yc = (e, t) => {
|
|
2373
|
-
let n = t.onDelete === void 0 ? "" : ` ON DELETE ${
|
|
2374
|
-
return `ALTER TABLE ${
|
|
2098
|
+
let n = t.onDelete === void 0 ? "" : ` ON DELETE ${_c[t.onDelete]}`, r = t.onUpdate === void 0 ? "" : ` ON UPDATE ${_c[t.onUpdate]}`;
|
|
2099
|
+
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}`;
|
|
2375
2100
|
}, bc = (e) => {
|
|
2376
2101
|
let t = () => {
|
|
2377
2102
|
throw Error("namespace branch executor: Neon ops require a neon-cow executor (use a Neon connection for copy-on-write branches)");
|
|
2378
2103
|
};
|
|
2379
2104
|
return {
|
|
2380
|
-
createNamespace: (t) => e.run(`CREATE SCHEMA IF NOT EXISTS ${
|
|
2381
|
-
createTable: (t, n) => e.run(`CREATE TABLE IF NOT EXISTS ${
|
|
2382
|
-
copyTable: (t, n, r) => e.run(`INSERT INTO ${
|
|
2105
|
+
createNamespace: (t) => e.run(`CREATE SCHEMA IF NOT EXISTS ${X(t)}`),
|
|
2106
|
+
createTable: (t, n) => e.run(`CREATE TABLE IF NOT EXISTS ${X(t)}.${X(n)} (LIKE ${X(n)} INCLUDING ALL)`),
|
|
2107
|
+
copyTable: (t, n, r) => e.run(`INSERT INTO ${X(n)}.${X(r)} SELECT * FROM ${X(t)}.${X(r)}`),
|
|
2383
2108
|
addForeignKey: (t, n) => e.run(yc(t, n)),
|
|
2384
2109
|
restoreIndexName: (t, n) => e.run(vc(t, n)),
|
|
2385
|
-
dropNamespace: (t) => e.run(`DROP SCHEMA IF EXISTS ${
|
|
2110
|
+
dropNamespace: (t) => e.run(`DROP SCHEMA IF EXISTS ${X(t)} CASCADE`),
|
|
2386
2111
|
neonBranchCreate: t,
|
|
2387
2112
|
neonBranchDelete: t
|
|
2388
2113
|
};
|
|
@@ -2415,7 +2140,7 @@ $voltro_branch$`;
|
|
|
2415
2140
|
if (n === void 0) throw new xc(`no residency home is mapped for tenant '${e}' — refusing to fall back to a default store (would be a residency violation)`);
|
|
2416
2141
|
return n;
|
|
2417
2142
|
}, Oc = (e, t) => t.servableRegions.includes(e), kc = (e, t) => {
|
|
2418
|
-
let n = Dc(e.tenantId, t), r =
|
|
2143
|
+
let n = Dc(e.tenantId, t), r = Li(n.tenantId);
|
|
2419
2144
|
return {
|
|
2420
2145
|
region: n.region,
|
|
2421
2146
|
namespace: r,
|
|
@@ -2485,12 +2210,12 @@ $voltro_branch$`;
|
|
|
2485
2210
|
let t = [];
|
|
2486
2211
|
for (let n of e) t.push(...Fc(n));
|
|
2487
2212
|
return t;
|
|
2488
|
-
}, Lc = "\x1B[", Rc = `${Lc}38;2;245;158;11m`, zc = `${Lc}38;2;16;185;129m`, Bc = (e, t) => `${e}${t}${
|
|
2489
|
-
let n = t.color ?? !0, r = t.indent ?? " ", i = (e) => $(n,
|
|
2213
|
+
}, Lc = "\x1B[", Rc = `${Lc}38;2;245;158;11m`, zc = `${Lc}38;2;16;185;129m`, Bc = (e, t) => `${e}${t}${M.reset}`, $ = (e, t, n) => e ? typeof t == "function" ? t(n) : Bc(t, n) : n, Vc = (e, t = {}) => {
|
|
2214
|
+
let n = t.color ?? !0, r = t.indent ?? " ", i = (e) => $(n, M.dim, e.padEnd(11)), a = (e) => $(n, (e) => M.bold(M.brand(e)), e), o = (e) => $(n, M.brightRed24, e), s = (e) => $(n, zc, e), c = (e) => $(n, Rc, e), l = (e) => $(n, M.dim, e), u = `${c("index audit")} ${l("·")} ${$(n, M.bold, e.kind)}`, d = e.redundant.fields.length, f = Q(e.coveredBy.fields.slice(d)), p = (e, t) => {
|
|
2490
2215
|
let n = e.slice(0, t), r = e.slice(t), i = [];
|
|
2491
2216
|
return n.length > 0 && i.push(s(`[${n.join(", ")}]`)), r.length > 0 && i.push(c(`+ [${r.join(", ")}]`)), i.join(" ");
|
|
2492
2217
|
}, m = [];
|
|
2493
|
-
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,
|
|
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, M.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");
|
|
2494
2219
|
}, Hc = (e, { apply: t, undo: n }) => ({
|
|
2495
2220
|
name: e,
|
|
2496
2221
|
apply: t,
|
|
@@ -2505,106 +2230,152 @@ $voltro_branch$`;
|
|
|
2505
2230
|
name: e.name,
|
|
2506
2231
|
steps: t
|
|
2507
2232
|
};
|
|
2508
|
-
}, Wc = (e) => typeof e == "object" && !!e && "__migration" in e && e.__migration === !0, Gc =
|
|
2509
|
-
id:
|
|
2510
|
-
name:
|
|
2511
|
-
hash:
|
|
2512
|
-
status:
|
|
2513
|
-
appliedAt:
|
|
2514
|
-
durationMs:
|
|
2515
|
-
errorMessage:
|
|
2516
|
-
errorStack:
|
|
2517
|
-
workflowRunId:
|
|
2518
|
-
createdAt:
|
|
2519
|
-
updatedAt:
|
|
2520
|
-
}).index(["status"]), Kc =
|
|
2521
|
-
id:
|
|
2522
|
-
name:
|
|
2523
|
-
lifecycle:
|
|
2524
|
-
fingerprint:
|
|
2525
|
-
cronSchedule:
|
|
2526
|
-
watchedTables:
|
|
2527
|
-
nextRunAt:
|
|
2528
|
-
lastRunStatus:
|
|
2529
|
-
lastRunAt:
|
|
2530
|
-
lastRunDurationMs:
|
|
2531
|
-
lastRunRowsTouched:
|
|
2532
|
-
lastError:
|
|
2533
|
-
workflowRunId:
|
|
2534
|
-
createdAt:
|
|
2535
|
-
updatedAt:
|
|
2536
|
-
}).index(["lifecycle"]).index(["nextRunAt"]), qc =
|
|
2537
|
-
id:
|
|
2538
|
-
fingerprint:
|
|
2539
|
-
liveFingerprint:
|
|
2540
|
-
operations:
|
|
2541
|
-
rollbackPlan:
|
|
2542
|
-
appliedBy:
|
|
2543
|
-
environment:
|
|
2544
|
-
source:
|
|
2545
|
-
onlineStrategy:
|
|
2546
|
-
durationMs:
|
|
2547
|
-
notes:
|
|
2548
|
-
squashedAt:
|
|
2549
|
-
appliedAt:
|
|
2550
|
-
createdAt:
|
|
2551
|
-
updatedAt:
|
|
2552
|
-
}).index(["fingerprint"]).index(["environment"]), Jc =
|
|
2553
|
-
id:
|
|
2554
|
-
scope:
|
|
2555
|
-
key:
|
|
2556
|
-
status:
|
|
2557
|
-
response:
|
|
2558
|
-
createdAt:
|
|
2559
|
-
}).unique(["scope", "key"]).index(["createdAt"]), Yc =
|
|
2560
|
-
id:
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2233
|
+
}, Wc = (e) => typeof e == "object" && !!e && "__migration" in e && e.__migration === !0, Gc = C("_voltro_migrations", {
|
|
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 = [
|
|
2591
2342
|
Gc,
|
|
2592
2343
|
Kc,
|
|
2593
2344
|
qc
|
|
2594
|
-
],
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
}
|
|
2345
|
+
], tl = Xc.tableName, nl = (e) => Fn("sha256").update(`${e.type}\u0000${e.id}`, "utf8").digest("hex"), rl = async (e, t) => {
|
|
2346
|
+
let [n] = await e.query({
|
|
2347
|
+
table: tl,
|
|
2348
|
+
predicate: he("id", nl(t)),
|
|
2349
|
+
order: [],
|
|
2350
|
+
take: 1,
|
|
2351
|
+
skip: void 0,
|
|
2352
|
+
projection: void 0
|
|
2353
|
+
}), r = n?.tenantId;
|
|
2354
|
+
return typeof r == "string" ? r : null;
|
|
2355
|
+
}, il = async (e, t, n) => {
|
|
2356
|
+
await e.upsert(tl, {
|
|
2357
|
+
id: nl(t),
|
|
2358
|
+
subjectType: t.type,
|
|
2359
|
+
subjectId: t.id,
|
|
2360
|
+
tenantId: n,
|
|
2361
|
+
selectedAt: /* @__PURE__ */ new Date()
|
|
2362
|
+
}, { conflictColumns: ["id"] });
|
|
2363
|
+
}, al = async (e, t) => {
|
|
2364
|
+
await e.delete(tl, nl(t));
|
|
2365
|
+
}, ol = "_voltro_replace_in_progress", sl = C(ol, {
|
|
2366
|
+
id: T({ prefix: "repl" }),
|
|
2367
|
+
startedAt: w().default("now"),
|
|
2368
|
+
kind: y().default("replace"),
|
|
2369
|
+
tables: y().nullable(),
|
|
2370
|
+
capture: y().nullable(),
|
|
2371
|
+
via: y(),
|
|
2372
|
+
staging: y().nullable(),
|
|
2373
|
+
heartbeatAt: w().nullable(),
|
|
2374
|
+
resumable: fn().nullable()
|
|
2375
|
+
}), cl = 30, ll = (e, t) => {
|
|
2605
2376
|
let n = typeof t == "number" && Number.isFinite(t) && t > 0 ? t : 30, r = Number(e.VOLTRO_STAGING_STALE_MINUTES);
|
|
2606
2377
|
return (Number.isFinite(r) && r > 0 ? r : n) * 6e4;
|
|
2607
|
-
},
|
|
2378
|
+
}, ul = (e) => e == null || String(e).length === 0 ? [] : String(e).split(",").map((e) => e.trim()).filter((e) => e.length > 0), dl = (e) => {
|
|
2608
2379
|
let t = e.filter((e) => e.kind !== "staging");
|
|
2609
2380
|
if (t.length !== 0) return `refusing to start: a destructive data operation did not finish.
|
|
2610
2381
|
${t.map((e) => {
|
|
@@ -2619,7 +2390,7 @@ ${t.map((e) => {
|
|
|
2619
2390
|
|
|
2620
2391
|
When the data is back, or you have decided the current state is correct, clear the marker:
|
|
2621
2392
|
voltro data clear-replace-marker --yes`;
|
|
2622
|
-
},
|
|
2393
|
+
}, fl = (e, t, n) => {
|
|
2623
2394
|
let r = e.filter((e) => e.kind === "staging");
|
|
2624
2395
|
return {
|
|
2625
2396
|
all: r,
|
|
@@ -2629,7 +2400,7 @@ ${t.map((e) => {
|
|
|
2629
2400
|
return Number.isFinite(r) ? t - r >= n : !1;
|
|
2630
2401
|
})
|
|
2631
2402
|
};
|
|
2632
|
-
},
|
|
2403
|
+
}, pl = (e, t) => {
|
|
2633
2404
|
if (e.all.length === 0) return;
|
|
2634
2405
|
let n = new Set(e.droppable.map((e) => e.id));
|
|
2635
2406
|
return `staged data-import leftovers:
|
|
@@ -2638,22 +2409,22 @@ ${e.all.map((e) => {
|
|
|
2638
2409
|
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.`;
|
|
2639
2410
|
}).join("\n")}\n The target of a staged \`replace\` is untouched until one short swap at the end, so none of this is
|
|
2640
2411
|
a reason to refuse the boot — it is a reason to know the disk is holding a copy of a bundle.`;
|
|
2641
|
-
},
|
|
2642
|
-
let n =
|
|
2412
|
+
}, ml = "id", hl = (e, t) => {
|
|
2413
|
+
let n = de(e);
|
|
2643
2414
|
if (n === void 0) return t;
|
|
2644
|
-
let r = n.fields[
|
|
2645
|
-
if (r === void 0 || t[
|
|
2415
|
+
let r = n.fields[ml]?.idScheme;
|
|
2416
|
+
if (r === void 0 || t[ml] != null) return t;
|
|
2646
2417
|
if (r.kind === "numeric") {
|
|
2647
|
-
if (!(
|
|
2418
|
+
if (!(ml in t)) return t;
|
|
2648
2419
|
let e = { ...t };
|
|
2649
|
-
return delete e[
|
|
2420
|
+
return delete e[ml], e;
|
|
2650
2421
|
}
|
|
2651
|
-
let i =
|
|
2422
|
+
let i = lt(r, e);
|
|
2652
2423
|
return i === null ? t : {
|
|
2653
2424
|
...t,
|
|
2654
|
-
[
|
|
2425
|
+
[ml]: i
|
|
2655
2426
|
};
|
|
2656
|
-
},
|
|
2427
|
+
}, gl = (e, t) => t.map((t) => hl(e, t)), _l = {
|
|
2657
2428
|
postgres: { maxBindParameters: 65535 },
|
|
2658
2429
|
mysql: { maxBindParameters: 65535 },
|
|
2659
2430
|
mariadb: { maxBindParameters: 65535 },
|
|
@@ -2663,25 +2434,25 @@ ${e.all.map((e) => {
|
|
|
2663
2434
|
},
|
|
2664
2435
|
sqlite: { maxBindParameters: 32766 },
|
|
2665
2436
|
turso: { maxBindParameters: 32766 }
|
|
2666
|
-
},
|
|
2437
|
+
}, vl = (e) => _l[e], yl = (e) => {
|
|
2667
2438
|
let t = /* @__PURE__ */ new Set();
|
|
2668
2439
|
for (let n of e) for (let e of Object.keys(n)) t.add(e);
|
|
2669
2440
|
return t.size;
|
|
2670
|
-
},
|
|
2441
|
+
}, bl = (e, t) => {
|
|
2671
2442
|
if (t === void 0 || e.length === 0) return [e];
|
|
2672
|
-
let n = Math.max(1,
|
|
2443
|
+
let n = Math.max(1, yl(e)), r = Math.floor(t.maxBindParameters / n), i = t.maxRowsPerStatement ?? Infinity, a = Math.max(1, Math.min(r, i));
|
|
2673
2444
|
if (e.length <= a) return [e];
|
|
2674
2445
|
let o = [];
|
|
2675
2446
|
for (let t = 0; t < e.length; t += a) o.push(e.slice(t, t + a));
|
|
2676
2447
|
return o;
|
|
2677
|
-
},
|
|
2448
|
+
}, xl = (e, t) => {
|
|
2678
2449
|
let n = [], r = t;
|
|
2679
2450
|
for (let [t, i] of Object.entries(e.fields)) {
|
|
2680
2451
|
let e = i;
|
|
2681
2452
|
e.nullable || e.hasDefault || e.idScheme !== void 0 || e.generatedAs !== void 0 || (r[t] === void 0 || r[t] === null) && n.push(t);
|
|
2682
2453
|
}
|
|
2683
2454
|
return n;
|
|
2684
|
-
},
|
|
2455
|
+
}, Sl = (e, t, n) => {
|
|
2685
2456
|
let r = n, i = new Set(e === void 0 ? [] : Object.entries(e.fields).filter(([, e]) => e.generatedAs !== void 0).map(([e]) => e)), a = [];
|
|
2686
2457
|
for (let e of t) i.has(e) || (r[e] === void 0 ? a.push({
|
|
2687
2458
|
column: e,
|
|
@@ -2691,36 +2462,36 @@ ${e.all.map((e) => {
|
|
|
2691
2462
|
reason: "null"
|
|
2692
2463
|
}));
|
|
2693
2464
|
return a;
|
|
2694
|
-
},
|
|
2465
|
+
}, Cl = (e, t, n) => e.insert(t.tableName, n), wl = (e, t, n) => e.insertMany(t.tableName, n), Tl = (e, t, n, r) => e.upsert(t.tableName, n, {
|
|
2695
2466
|
conflictColumns: r.conflictColumns,
|
|
2696
2467
|
...r.update === void 0 ? {} : { update: r.update },
|
|
2697
2468
|
...r.updateValues === void 0 ? {} : { updateValues: r.updateValues }
|
|
2698
|
-
}),
|
|
2469
|
+
}), El = async (e, t, n, r) => {
|
|
2699
2470
|
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.");
|
|
2700
2471
|
return e.upsertWithOutcome(t.tableName, n, {
|
|
2701
2472
|
conflictColumns: r.conflictColumns,
|
|
2702
2473
|
...r.update === void 0 ? {} : { update: r.update },
|
|
2703
2474
|
...r.updateValues === void 0 ? {} : { updateValues: r.updateValues }
|
|
2704
2475
|
});
|
|
2705
|
-
},
|
|
2476
|
+
}, Dl = async (e, t, n, r) => e.insertIgnoreWithOutcome(t.tableName, n, { conflictColumns: r.conflictColumns }), Ol = (e, t, n, r) => e.updateMany(t.tableName, n, { where: r.where }), kl = 512, Al = (e) => {
|
|
2706
2477
|
e.setMaxListeners(512);
|
|
2707
|
-
},
|
|
2478
|
+
}, jl = (e, t, n) => ({
|
|
2708
2479
|
_tag: "PrimaryKeyConflictError",
|
|
2709
2480
|
table: e,
|
|
2710
2481
|
key: t,
|
|
2711
2482
|
cause: n
|
|
2712
|
-
}),
|
|
2483
|
+
}), Ml = (e) => typeof e == "object" && !!e && e._tag === "PrimaryKeyConflictError", Nl = {
|
|
2713
2484
|
postgres: 5432,
|
|
2714
2485
|
mysql: 3306,
|
|
2715
2486
|
mariadb: 3306,
|
|
2716
2487
|
mssql: 1433
|
|
2717
|
-
},
|
|
2488
|
+
}, Pl = /* @__PURE__ */ new Set([
|
|
2718
2489
|
"localhost",
|
|
2719
2490
|
"127.0.0.1",
|
|
2720
2491
|
"::1",
|
|
2721
2492
|
"[::1]",
|
|
2722
2493
|
"0.0.0.0"
|
|
2723
|
-
]),
|
|
2494
|
+
]), Fl = (e) => {
|
|
2724
2495
|
let t = e.host, n = e.port, r = e.database;
|
|
2725
2496
|
if (e.url !== void 0 && e.url !== "") try {
|
|
2726
2497
|
let i = new URL(e.url);
|
|
@@ -2729,29 +2500,29 @@ ${e.all.map((e) => {
|
|
|
2729
2500
|
return;
|
|
2730
2501
|
}
|
|
2731
2502
|
if (t === void 0 || t === "" || r === void 0 || r === "") return;
|
|
2732
|
-
let i = n ??
|
|
2503
|
+
let i = n ?? Nl[(e.dialect ?? "").toLowerCase()];
|
|
2733
2504
|
if (i === void 0 || !Number.isFinite(i)) return;
|
|
2734
2505
|
let a = t.toLowerCase();
|
|
2735
2506
|
return {
|
|
2736
|
-
host:
|
|
2507
|
+
host: Pl.has(a) ? "localhost" : a,
|
|
2737
2508
|
port: i,
|
|
2738
2509
|
database: r.toLowerCase()
|
|
2739
2510
|
};
|
|
2740
|
-
},
|
|
2741
|
-
let t =
|
|
2742
|
-
if (t !== void 0) return
|
|
2743
|
-
},
|
|
2511
|
+
}, Il = (e) => {
|
|
2512
|
+
let t = Fl(e);
|
|
2513
|
+
if (t !== void 0) return Fn("sha256").update(`${t.host}\u0000${t.port}\u0000${t.database}`).digest("hex").slice(0, 32);
|
|
2514
|
+
}, Ll = (e, t) => e === void 0 || t === void 0 ? "unknown" : e === t ? "same" : "different", Rl = {
|
|
2744
2515
|
app: 3,
|
|
2745
2516
|
plugin: 2,
|
|
2746
2517
|
framework: 1
|
|
2747
|
-
},
|
|
2518
|
+
}, zl = /* @__PURE__ */ new Map(), Bl = [], Vl = () => [...Bl], Hl = (e) => {
|
|
2748
2519
|
if (!e.table || !e.timeColumn) throw Error("registerRetention: table + timeColumn are required");
|
|
2749
2520
|
if (!Number.isFinite(e.ttlMs) || e.ttlMs <= 0) throw Error(`registerRetention(${e.table}): ttlMs must be a positive number`);
|
|
2750
|
-
let t = e.source ?? "app", n =
|
|
2521
|
+
let t = e.source ?? "app", n = zl.get(e.table);
|
|
2751
2522
|
if (n !== void 0) {
|
|
2752
2523
|
let r = n.source ?? "app", i = n.ttlMs !== e.ttlMs || n.where !== void 0 != (e.where !== void 0);
|
|
2753
|
-
if (
|
|
2754
|
-
i &&
|
|
2524
|
+
if (Rl[t] < Rl[r]) {
|
|
2525
|
+
i && Bl.push({
|
|
2755
2526
|
table: e.table,
|
|
2756
2527
|
kept: {
|
|
2757
2528
|
source: r,
|
|
@@ -2764,7 +2535,7 @@ ${e.all.map((e) => {
|
|
|
2764
2535
|
});
|
|
2765
2536
|
return;
|
|
2766
2537
|
}
|
|
2767
|
-
i && r !== t &&
|
|
2538
|
+
i && r !== t && Bl.push({
|
|
2768
2539
|
table: e.table,
|
|
2769
2540
|
kept: {
|
|
2770
2541
|
source: t,
|
|
@@ -2776,13 +2547,13 @@ ${e.all.map((e) => {
|
|
|
2776
2547
|
}
|
|
2777
2548
|
});
|
|
2778
2549
|
}
|
|
2779
|
-
|
|
2550
|
+
zl.set(e.table, {
|
|
2780
2551
|
...e,
|
|
2781
2552
|
source: t
|
|
2782
2553
|
});
|
|
2783
|
-
},
|
|
2784
|
-
|
|
2785
|
-
},
|
|
2554
|
+
}, Ul = () => [...zl.values()], Wl = () => {
|
|
2555
|
+
zl.clear(), Bl.length = 0;
|
|
2556
|
+
}, Gl = async (e, t, n, r = 2e4) => {
|
|
2786
2557
|
let i = new Date(t - e.ttlMs), a = 0;
|
|
2787
2558
|
try {
|
|
2788
2559
|
for (;;) {
|
|
@@ -2790,45 +2561,45 @@ ${e.all.map((e) => {
|
|
|
2790
2561
|
if (a += t, t < r) break;
|
|
2791
2562
|
}
|
|
2792
2563
|
} catch (t) {
|
|
2793
|
-
throw
|
|
2564
|
+
throw O.runSync(k.increment(k.tagged(ql, "table", e.table))), t;
|
|
2794
2565
|
}
|
|
2795
|
-
return a > 0 &&
|
|
2796
|
-
},
|
|
2566
|
+
return a > 0 && O.runSync(k.incrementBy(k.tagged(Kl, "table", e.table), a)), a;
|
|
2567
|
+
}, Kl = k.counter("voltro_retention_swept_rows_total"), ql = k.counter("voltro_retention_sweep_errors_total"), Jl = (e, t) => {
|
|
2797
2568
|
let n = Number(e ?? String(t));
|
|
2798
2569
|
return (Number.isFinite(n) && n > 0 ? n : t) * 36e5;
|
|
2799
|
-
},
|
|
2800
|
-
id:
|
|
2801
|
-
replicaId:
|
|
2802
|
-
streamName:
|
|
2803
|
-
binlogFile:
|
|
2804
|
-
binlogPosition:
|
|
2805
|
-
updatedAt:
|
|
2806
|
-
}).index(["replicaId"]),
|
|
2807
|
-
id:
|
|
2808
|
-
replicaId:
|
|
2809
|
-
streamName:
|
|
2810
|
-
ctVersion:
|
|
2811
|
-
updatedAt:
|
|
2812
|
-
}).index(["replicaId"]),
|
|
2813
|
-
id:
|
|
2814
|
-
startedAt:
|
|
2815
|
-
finishedAt:
|
|
2816
|
-
direction:
|
|
2817
|
-
mode:
|
|
2818
|
-
via:
|
|
2819
|
-
bundle:
|
|
2820
|
-
sourceFingerprint:
|
|
2821
|
-
tablesWritten:
|
|
2822
|
-
rowsWritten:
|
|
2823
|
-
failure:
|
|
2824
|
-
staged:
|
|
2825
|
-
}).renamedFrom("_voltro_data_imports").nonReactive(),
|
|
2570
|
+
}, Yl = "_voltro_cdc_offsets", Xl = C(Yl, {
|
|
2571
|
+
id: T({ prefix: "cdcoff" }),
|
|
2572
|
+
replicaId: y(),
|
|
2573
|
+
streamName: y(),
|
|
2574
|
+
binlogFile: y(),
|
|
2575
|
+
binlogPosition: y(),
|
|
2576
|
+
updatedAt: w()
|
|
2577
|
+
}).index(["replicaId"]), Zl = C(Yl, {
|
|
2578
|
+
id: T({ prefix: "cdcoff" }),
|
|
2579
|
+
replicaId: y(),
|
|
2580
|
+
streamName: y(),
|
|
2581
|
+
ctVersion: y(),
|
|
2582
|
+
updatedAt: w()
|
|
2583
|
+
}).index(["replicaId"]), Ql = "_voltro_data_transfers", $l = C(Ql, {
|
|
2584
|
+
id: T({ prefix: "dimp" }),
|
|
2585
|
+
startedAt: w().default("now"),
|
|
2586
|
+
finishedAt: w().nullable(),
|
|
2587
|
+
direction: y().default("import"),
|
|
2588
|
+
mode: y(),
|
|
2589
|
+
via: y(),
|
|
2590
|
+
bundle: y().nullable(),
|
|
2591
|
+
sourceFingerprint: y().nullable(),
|
|
2592
|
+
tablesWritten: E().default(0),
|
|
2593
|
+
rowsWritten: E().default(0),
|
|
2594
|
+
failure: y().nullable(),
|
|
2595
|
+
staged: fn().nullable()
|
|
2596
|
+
}).renamedFrom("_voltro_data_imports").nonReactive(), eu = (e) => {
|
|
2826
2597
|
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)";
|
|
2827
2598
|
return `${t} · ${r} · via ${e.via}${i}` + (e.bundle === null ? "" : ` · from ${e.bundle}`) + (e.sourceFingerprint === null ? "" : ` · source schema ${e.sourceFingerprint}`);
|
|
2828
|
-
},
|
|
2599
|
+
}, tu = 255, nu = (e) => e == null ? "null" : typeof e == "string" || typeof e == "number" || typeof e == "boolean" ? JSON.stringify(e) : Array.isArray(e) ? `[${e.map(nu).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)}:${nu(t)}`).join(",")}}` : JSON.stringify(String(e)), ru = (e) => {
|
|
2829
2600
|
if (e == null) return null;
|
|
2830
|
-
let t = typeof e == "string" ? e :
|
|
2601
|
+
let t = typeof e == "string" ? e : nu(e);
|
|
2831
2602
|
return t.length > 255 ? t.slice(0, 255) : t;
|
|
2832
|
-
},
|
|
2603
|
+
}, iu = "postgres";
|
|
2833
2604
|
//#endregion
|
|
2834
|
-
export {
|
|
2605
|
+
export { ce as AUTO_FILLED_COLUMNS, Kn as BOUND_ENCRYPTED_PREFIX, _l as BULK_INSERT_LIMITS, Y as BranchNameInvalid, rc as BranchTransitionInvalid, Yl as CDC_OFFSETS_TABLE, vo as CHANGE_CLAIM_TTL_ENV, kl as CHANGE_LISTENER_CEILING, Ye as ColumnBuilder, Ql as DATA_TRANSFERS_TABLE, ae as DEFAULT_ACQUIRE_TIMEOUT_MS, yo as DEFAULT_CHANGE_CLAIM_TTL_HOURS, bs as DEFAULT_EAGER_FALLBACK_WARN_INTERVAL_MS, $t as DEFAULT_SOFT_DROP_RETENTION_DAYS, ei as DEFAULT_SUBJECT_GRAPH_DEPTH, Gn as ENCRYPTED_PREFIX, iu as ENGINE, yi as EagerCardinalityError, tn as FILE_MIGRATION_PATTERN, Ft as FRAMEWORK_LIVE_TABLES, Yn as FieldDecryptionError, Ho as ID_COLUMN_MAX_LENGTH, wn as INITIAL_VERSION, ot as IrreversibleMigrationError, m as MATCHES_NO_ROWS, xt as MAX_IDENTIFIER_LENGTH, Ms as MSSQL_TRANSIENT_NUMBERS, As as MYSQL_TRANSIENT_CODES, dt as MigrationExpectationFailed, Vt as MigrationSkipped, _o as OccurrenceCounter, js as POSTGRES_TRANSIENT_STATES, ol as REPLACE_IN_PROGRESS_TABLE, Mt as RewriteUnstableError, tu as SCOPE_KEY_MAX_LENGTH, on as SELF_REFERENCE_TARGET, Ns as SQLITE_TRANSIENT_CODES, cl as STAGING_STALE_MINUTES, qt as STAGING_TABLE_PREFIX, Rn as SqlClient, tl as TENANT_SELECTIONS_TABLE, Ps as TURSO_TRANSIENT_MESSAGE, Gs as TableStreamError, Ni as TenantNamespaceInvalid, Mi as TenantNamespaceUnresolved, Sc as TenantRegionUnavailable, xc as TenantResidencyUnresolved, _t as TransactionBrokenByBodyError, zs as VOLTRO_EXPIRES_MIXIN_ID, Vs as VOLTRO_LOCAL_FIRST_MIXIN_ID, xn as VersionConflict, Qe as WARN_IDENTIFIER_LENGTH, Qc as _voltroApiKeysTable, Xl as _voltroCdcOffsetsTable, $l as _voltroDataTransfersTable, Yc as _voltroDevicesTable, Jc as _voltroIdempotencyTable, Zc as _voltroKvTable, qc as _voltroMigrationPlansTable, Gc as _voltroMigrationsTable, Zl as _voltroMssqlCdcOffsetsTable, sl as _voltroReplaceInProgressTable, $c as _voltroReplicaObservationsTable, Kc as _voltroSeedsTable, Xc as _voltroTenantSelectionsTable, oo as actorsTable, gc as admitBranch, bt as agedSoftDropSnapshots, st as allEnumRenames, Zr as allRegisteredRelations, xe as allRegisteredTables, d as and, _i as applyJsonPatch, hn as array, _e as arrayContains, Et as arrayHas, n as arrayOverlaps, xi as attachEagerLoads, wo as attributionFields, Oo as attributionKey, Ic as auditAllTableIndexes, Fc as auditTableIndexes, rn as avg, ct as avgOver, Lo as beginLocalWrite, tt as bigint, Ac as bindResidentStore, fn as boolean, ec as branchNamespaceName, vl as bulkInsertLimitsFor, Oe as bytes, cr as causeBranches, uo as changeDelete, mo as changeDigest, co as changeInsert, fo as changeSoftDelete, lo as changeUpdate, bl as chunkRowsForInsert, jo as claimPendingAttribution, vr as classifyConstraintViolation, ft as clearEnumRenames, Bo as clearPendingAttribution, $r as clearRelationsRegistry, Ec as clearResidencyConfig, Wl as clearRetentions, ee as clearTableRegistry, Yo as clearWriteRecorders, W as coercePredicateForSqlite, Vi as coercePredicateValue, Hi as coercePredicateValues, Qa as coerceValueForSqlite, Ct as collectSubqueries, pt as column, Dr as columnSchema, yl as columnsPerRow, ut as compareDecimal, ta as compileEagerJson, vi as compileJsonPatch, L as compilePredicate, Ui as compileRawFragment, ea as compileSelect, ho as composeChangeKey, Xs as computeEmbedding, Il as connectionIdentity, fe as contains, Ut as count, Pt as countDistinct, l as crdtDoc, ln as crdtManagedColumns, je as crdtManagedColumnsOf, h as crdtText, Co as currentWriteAttribution, yt as databaseHandle, f as date, ve as dbEnum, ms as dbMetricTagCacheSizeForTests, _s as dbOperationsInFlight, Dt as decimal, Ht as declareEnumRename, er as decodeFieldValue, Yt as decodeRowsForTable, St as decodeRowsFromSchema, or as decryptFieldsOnRead, Uc as defineMigration, Ue as defineMixin, et as defineSeed, al as deleteTenantSelection, gt as denseRank, si as deriveSubjectGraph, t as deriveTypeIdPrefix, Go as derivedRowId, Ko as derivedRowIdLength, Ze as describeAgedSoftDropSnapshots, xr as describeDriverError, Sr as describeRowBindings, eu as describeTransferRun, Wn as deserializeArraysOnRead, zt as drainIdentifierWarnings, r as dropped, Qn as encodeFieldValue, $e as encodeRowForSchema, ar as encryptFieldsForWrite, rr as encryptedColumnsOf, Ro as endLocalWrite, pc as enforceBranchLimits, S as ensureTableRegistered, he as eq, I as escapeLike, be as evaluatePredicate, Xe as except, _ as exists, Bs as expires, so as externalChangeEvent, dr as extractDbCause, qn as fieldBinding, dn as fireSchemaChangeSeeds, De as fireTenantCreateSeeds, Vc as formatIndexAuditIssue, ci as formatSubjectGraph, el as frameworkTables, lt as generateId, It as generateSnowflake, wt as geography, pe as geometry, Nt as getEnumRenames, Xr as getRelation, Yr as getRelations, Tc as getResidencyConfig, de as getTable, b as gt, le as gte, ji as hasEagerLoads, Ys as hybridSearch, T as id, we as inSet, _n as inSubquery, Br as inferForeignKey, Dl as insertIgnoreRowOutcome, wl as insertManyRows, Cl as insertRow, E as integer, dl as interruptedReplaceRefusal, sn as intersect, v as interval, mt as irreversible, Je as irreversibleReason, Jn as isBoundCiphertext, tc as isBranchNamespace, pi as isCompositeRowKey, Fr as isEmptyRelationsSpec, Zn as isEncrypted, Xn as isFieldDecryptionError, an as isFileMigration, yr as isForeignKeyViolation, Rt as isFrameworkOwnedLiveTable, Us as isLocalFirst, Wc as isMigrationDefinition, Fe as isMysqlFamily, sc as isNeonConnection, a as isNotNull, Ie as isNull, Ml as isPrimaryKeyConflictError, br as isQueryTimeout, tr as isRawEncoding, Oc as isRegionServable, Ir as isRelationsSpec, c as isSeedDefinition, Xt as isSoftDropSnapshotName, Ve as isSqliteFamily, rt as isStagingTableName, Ee as isTableReactive, Ls as isTransientContention, Bt as isView, x as json, re as jsonField, Kt as jsonIndex, mi as jsonPatchAssignments, gn as lag, nt as lead, Vl as listRetentionConflicts, Ul as listRetentions, Hs as localFirst, Ws as localFirstTables, Ne as lt, ze as lte, Cs as makeEagerFallbackReporter, bc as makeNamespaceBranchExecutor, Rr as many, zr as manyToMany, ue as materializeFields, pn as max, mn as migration, ke as min, Sl as missingConflictColumns, xl as missingRequiredColumns, qe as mixin, te as neq, ic as nextBranchState, Fl as normaliseTarget, gi as normalizeJsonPatchValue, se as not, Wt as notExists, oe as notInSet, We as notInSubquery, Te as numeric, ys as observeDbOp, bo as occurrenceWindowMs, Lr as one, bi as oneCardinalityMessage, He as or, u as orderClausesOf, un as paginateBy, Me as paginateById, go as parseChangeKey, Vo as pendingAttributionCount, dc as planBranch, ac as planBranchProvision, oc as planBranchTeardown, fc as planBranchTeardownFor, lc as planNeonBranchProvision, uc as planNeonBranchTeardown, bn as planVersionedUpdate, vt as pluginRef, ht as pluginRefSpecOf, jl as primaryKeyConflictError, mc as provisionBranch, jc as provisionResidentTenant, Ri as qualifyTable, g as queryFor, Qt as queryForView, ne as quoteIdent, Al as raiseChangeListenerCeiling, p as rank, vn as raw, rl as readTenantSelection, o as readableByColumns, Le as real, vs as recordDbOp, es as recordsTable, ie as reference, Tr as refuseWrite, no as registerCoreTables, Jr as registerDiscoveredRelations, Ao as registerPendingAttribution, qr as registerRelations, Hl as registerRetention, yn as registerTable, qo as registerWriteRecorder, Pr as relations, io as requireActors, s as requireTable, ao as requireTenants, ps as resetDbMetricTagCacheForTests, Jt as resetSnowflake, kc as residentPlacement, Bn as resolveActorSnapshot, cc as resolveBranchMechanism, Ss as resolveEagerFallbackWarnIntervalMs, zo as resolveEchoAttribution, ye as resolveFullTextIndex, en as resolveIdScheme, Ce as resolveMixinGraph, Dc as resolveTenantHome, Li as resolveTenantNamespace, Jl as retentionTtlMsFromEnv, di as rowKeyColumns, fi as rowKeyIdentity, Ot as rowNumber, Or as rowSchema, Os as runRetryingTransaction, ks as runStoreTransaction, So as runWithWriteAttribution, ts as runWriteRecorders, Ll as sameDatabase, Ii as sanitizeIdentifierFragment, ru as scopeKeyOf, Pe as selfReference, Un as serializeArraysForWrite, Be as serverOnlyColumns, wc as setResidencyConfig, cn as setSchemaChangeSeedHook, Ae as setTenantCreateSeedHook, ws as settleTransactionExit, Cn as settleVersionedUpdate, kt as softDropSnapshotStamp, Ke as spatialPredicate, pl as stagingLeftoverReport, fl as stagingLeftovers, ul as stagingNamesOf, ll as stagingStaleAfterMs, hl as stampGeneratedId, gl as stampGeneratedIds, Se as startsWith, Er as storeRefusalOf, Js as streamTable, i as sum, Tt as sumOver, Zo as suspendWriteRecorders, Qo as suspendWriteRecordersEffect, Gl as sweepRetention, C as table, hc as teardownBranch, nl as tenantSelectionId, y as text, w as timestamp, En as timestampMs, Sn as timestampMsOrNull, Ds as transactionRetrySchedule, me as union, ge as unionAll, Re as unregisterTable, Jo as unregisterWriteRecorder, Ol as updateManyRow, Tl as upsertRow, El as upsertRowOutcome, ui as upsertUpdatePatch, li as upsertUpdateValues, Zt as validateColumnName, it as validateIndexName, Qr as validateRegisteredRelations, Wr as validateRelationConfig, At as validateTableName, nn as validateTypeIdPrefix, Gt as vector, Ge as vectorDistanceToOpclass, Zs as vectorEmbedding, Tn as versionColumnOf, at as view, jt as viewSql, e as walkLeaves, fr as wireSafeCause, To as withCapturedAttribution, $o as writeRecordersSuspended, il as writeTenantSelection };
|