@voltro/database 0.69.1 → 0.71.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 +1369 -111
- package/dist/{frameworkLiveTables-CWbTSnjk.js → frameworkLiveTables-D53uncZH.js} +3 -3
- package/dist/index.d.ts +85 -18
- package/dist/index.js +812 -791
- package/dist/sql.d.ts +41 -7
- package/dist/sql.js +1144 -955
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { $ as e, $t as t, A as n, At as r, B as i, Bt as a, C as o, Ct as s, D as c, Dt as l, E as u, Et as d, F as f, Ft as p, G as m, Gt as h, H as g, Ht as _, I as v, It as ee, J as te, Jt as y, K as ne, Kt as re, L as b, Lt as ie, M as x, Mt as ae, N as
|
|
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, At as r, B as i, Bt as a, C as o, Ct as s, D as c, Dt as l, E as u, Et as d, F as f, Ft as p, G as m, Gt as h, H as g, Ht as _, I as v, It as ee, J as te, Jt as y, K as ne, Kt as re, L as b, Lt as ie, M as x, Mt as ae, N as S, Nt as oe, O as se, Ot as ce, P as le, Pt as ue, Q as de, Qt as fe, R as pe, Rt as me, S as he, St as ge, T as _e, Tt as ve, U as ye, Ut as be, V as xe, Vt as Se, W as Ce, Wt as we, X as Te, Xt as C, Y as Ee, Yt as De, Z as w, Zt as Oe, _ as ke, _t as Ae, a as je, an as T, at as Me, b as Ne, bt as Pe, c as Fe, ct as E, d as Ie, dt as Le, en as Re, et as ze, f as Be, ft as Ve, g as He, gt as Ue, h as We, ht as Ge, i as Ke, in as qe, it as Je, j as Ye, jt as Xe, k as Ze, kt as Qe, l as $e, lt as et, m as tt, mt as nt, n as rt, nn as it, nt as at, o as ot, on as D, ot as st, p as ct, pt as lt, q as ut, qt as O, r as dt, rn as ft, rt as pt, s as mt, sn as ht, st as gt, t as _t, tn as vt, tt as yt, u as bt, ut as xt, v as St, vt as Ct, w as wt, wt as Tt, x as Et, xt as Dt, y as k, yt as Ot, z as kt, zt as At } from "./frameworkLiveTables-D53uncZH.js";
|
|
2
|
+
import { a as jt, i as Mt, n as Nt, o as Pt, r as Ft, s as It, t as Lt } from "./wire-B28cPjEp.js";
|
|
3
|
+
import { Cause as Rt, Chunk as zt, Data as Bt, Effect as A, Exit as Vt, Metric as j, MetricBoundaries as Ht, Option as M, Runtime as Ut, Schedule as Wt, Schema as N, Stream as Gt } from "effect";
|
|
4
|
+
import { createHash as Kt } from "node:crypto";
|
|
5
|
+
import { AsyncLocalStorage as qt } from "node:async_hooks";
|
|
6
|
+
import { TransactionConnection as Jt } from "@effect/sql/SqlClient";
|
|
7
|
+
import { ansi as P } from "@voltro/logger";
|
|
8
|
+
import { SqlClient as Yt } from "@effect/sql";
|
|
9
9
|
//#region src/actorSnapshot.ts
|
|
10
|
-
var
|
|
10
|
+
var Xt = (e) => typeof e == "string" && e !== "" ? e : null, Zt = 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 Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = 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: Xt(r.kind) ?? n,
|
|
27
|
+
displayName: Xt(r.displayName),
|
|
28
|
+
email: Xt(r.email)
|
|
29
29
|
};
|
|
30
30
|
} catch {
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
|
-
},
|
|
33
|
+
}, Qt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqlite", $t = (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
|
+
}, en = (e, t, n) => {
|
|
38
|
+
if (!Qt(n) || !t) return e;
|
|
39
|
+
let r = $t(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 Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = 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
|
+
}, tn = (e, t, n) => {
|
|
48
|
+
if (!Qt(n) || !t) return e;
|
|
49
|
+
let r = $t(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 Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
58
58
|
}
|
|
59
59
|
return t ?? e;
|
|
60
60
|
});
|
|
61
|
-
},
|
|
61
|
+
}, nn = "enc:v1:", rn = "enc:v2:", an = (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
|
+
}, on = (e) => typeof e == "string" && e.startsWith("enc:v2:"), sn = class extends Error {
|
|
68
68
|
_tag = "FieldDecryptionError";
|
|
69
69
|
table;
|
|
70
70
|
column;
|
|
@@ -72,7 +72,7 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = 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
|
+
}, cn = (e) => typeof e == "object" && !!e && e._tag === "FieldDecryptionError", ln = (e) => typeof e == "string" && (e.startsWith("enc:v1:") || e.startsWith("enc:v2:")), un = (e, t, n) => e.encrypt(JSON.stringify(t), n), dn = /* @__PURE__ */ new Set([
|
|
76
76
|
"text",
|
|
77
77
|
"id",
|
|
78
78
|
"reference",
|
|
@@ -80,51 +80,51 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
80
80
|
"uuid",
|
|
81
81
|
"email",
|
|
82
82
|
"url"
|
|
83
|
-
]),
|
|
83
|
+
]), fn = (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 || dn.has(n) ? i : a;
|
|
91
|
+
}, pn = (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 || dn.has(n) ? !0 : void 0;
|
|
95
95
|
} catch {
|
|
96
96
|
return !0;
|
|
97
97
|
}
|
|
98
|
-
},
|
|
98
|
+
}, mn = (e, t) => e.fields[t]?.type, hn = (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
|
+
}, gn = "id", _n = (e, t, n, r) => {
|
|
103
103
|
if (!t) return e;
|
|
104
|
-
let i =
|
|
104
|
+
let i = hn(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[gn], s = { ...e };
|
|
107
107
|
for (let e of i) {
|
|
108
108
|
let t = s[e];
|
|
109
|
-
if (!(t == null ||
|
|
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)`);
|
|
111
|
-
s[e] =
|
|
109
|
+
if (!(t == null || ln(t))) {
|
|
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] = un(n, t, an(a, e, o));
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
return s;
|
|
115
|
-
},
|
|
115
|
+
}, vn = (e, t, n, r) => {
|
|
116
116
|
if (!t) return e;
|
|
117
|
-
let i =
|
|
117
|
+
let i = hn(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 (ln(i)) {
|
|
125
125
|
s ??= { ...e };
|
|
126
126
|
try {
|
|
127
|
-
s[c] =
|
|
127
|
+
s[c] = fn(n, i, mn(t, c), an(o, c, r?.rowId ?? e[gn]));
|
|
128
128
|
} catch (e) {
|
|
129
129
|
let t = String(e?.message ?? e);
|
|
130
130
|
if (a === "null") {
|
|
@@ -135,7 +135,7 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
135
135
|
});
|
|
136
136
|
continue;
|
|
137
137
|
}
|
|
138
|
-
throw new
|
|
138
|
+
throw new sn({
|
|
139
139
|
table: o,
|
|
140
140
|
column: c,
|
|
141
141
|
reason: t
|
|
@@ -145,136 +145,136 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
145
145
|
}
|
|
146
146
|
return s ?? e;
|
|
147
147
|
});
|
|
148
|
-
},
|
|
148
|
+
}, yn = (e) => {
|
|
149
149
|
let t = e;
|
|
150
|
-
for (let e = 0; e < 4 &&
|
|
150
|
+
for (let e = 0; e < 4 && Ut.isFiberFailure(t); e++) t = Rt.squash(t[Ut.FiberFailureCauseId]);
|
|
151
151
|
return t;
|
|
152
|
-
},
|
|
153
|
-
if (t >= 4 || !
|
|
154
|
-
let n = e[
|
|
155
|
-
if (r.length === 0) return [
|
|
152
|
+
}, bn = (e, t = 0) => {
|
|
153
|
+
if (t >= 4 || !Ut.isFiberFailure(e)) return [e];
|
|
154
|
+
let n = e[Ut.FiberFailureCauseId], r = [...Rt.failures(n), ...Rt.defects(n)];
|
|
155
|
+
if (r.length === 0) return [Rt.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(...bn(e, t + 1));
|
|
158
158
|
return i;
|
|
159
|
-
},
|
|
160
|
-
let t = {}, n = [], r =
|
|
159
|
+
}, xn = (e) => e.dbCode !== void 0 || e.dbErrno !== void 0 || e.dbNumber !== void 0 || e.dbSqlState !== void 0 || e.dbConstraint !== void 0, Sn = (e) => {
|
|
160
|
+
let t = {}, n = [], r = yn(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 = yn(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
|
+
}, Cn = (e) => {
|
|
171
|
+
let t = bn(e).map(Sn);
|
|
172
172
|
if (t.length <= 1) return t[0] ?? {};
|
|
173
|
-
let n = t.find(
|
|
173
|
+
let n = t.find(xn) ?? 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
|
+
}, wn = (e, t) => {
|
|
181
|
+
let n = Cn(e), r = An(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 = Dn(e);
|
|
187
|
+
return i !== void 0 && Tn.test(String(i)) ? `${a} (${String(i)})` : a;
|
|
188
|
+
}, Tn = /^[A-Za-z0-9_]{1,32}$/, En = /^[A-Za-z_][A-Za-z0-9_]{0,63}$/, Dn = (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 && En.test(r) ? r : "unknown";
|
|
191
|
+
}, On = /^[A-Za-z_][A-Za-z0-9_$]*$/, F = (e) => e !== void 0 && e.length <= 128 && On.test(e) ? e : void 0, kn = (e) => e === void 0 ? void 0 : e.split(".").pop() ?? e, I = (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
|
+
}, An = (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 = F(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 = F(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 = F(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 = F(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 = F(I(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 = F(kn(I(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 = F(I(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 = F(I(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 = I(o, /(?:FOREIGN KEY|REFERENCE) constraint "([^"]+)"/), t = I(o, /CHECK constraint "([^"]+)"/);
|
|
256
256
|
if (t !== void 0 && e === void 0) {
|
|
257
|
-
let e =
|
|
257
|
+
let e = F(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 = F(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 = F(I(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 = F(I(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 Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = 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 = F(kn(I(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 = F(kn(I(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 = F(I(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
|
+
}, jn = (e) => {
|
|
306
|
+
let t = An(e)?.kind;
|
|
307
307
|
return t === "foreignKey" || t === "foreignKeyInUse";
|
|
308
|
-
},
|
|
308
|
+
}, Mn = (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
|
+
}, Nn = (e) => {
|
|
312
|
+
let t = Cn(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 Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = 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
|
+
}, Pn = (e) => Object.entries(e).map(([e, t]) => `${e}:${Fn(t)}`).join(" "), Fn = (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 Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = 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
|
+
}, In = Symbol.for("@voltro/database/storeRefusal"), Ln = (e) => {
|
|
332
332
|
let t = Error(e.detail);
|
|
333
|
-
return Object.defineProperty(t,
|
|
333
|
+
return Object.defineProperty(t, In, {
|
|
334
334
|
value: e,
|
|
335
335
|
enumerable: !1
|
|
336
336
|
}), t;
|
|
337
|
-
},
|
|
338
|
-
for (let t of
|
|
337
|
+
}, Rn = (e) => {
|
|
338
|
+
for (let t of bn(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[In];
|
|
342
342
|
if (t !== void 0) return t;
|
|
343
343
|
e = e.cause;
|
|
344
344
|
}
|
|
345
345
|
}
|
|
346
|
-
},
|
|
346
|
+
}, zn = (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" ? N.Number : N.String;
|
|
350
350
|
case "text":
|
|
351
|
-
case "enum": return
|
|
352
|
-
case "reference": return e.referenceStorage === "numeric" ?
|
|
351
|
+
case "enum": return N.String;
|
|
352
|
+
case "reference": return e.referenceStorage === "numeric" ? N.Number : N.String;
|
|
353
353
|
case "integer":
|
|
354
354
|
case "real":
|
|
355
|
-
case "decimal": return
|
|
356
|
-
case "boolean": return
|
|
355
|
+
case "decimal": return N.Number;
|
|
356
|
+
case "boolean": return N.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 Lt;
|
|
359
|
+
case "bigint": return N.BigInt;
|
|
360
|
+
case "bytes": return N.Uint8ArrayFromBase64;
|
|
361
|
+
case "array": return N.Array(N.Unknown);
|
|
362
|
+
case "interval": return N.String;
|
|
363
|
+
default: return N.Unknown;
|
|
364
364
|
}
|
|
365
365
|
})();
|
|
366
|
-
return e.nullable === !0 ?
|
|
367
|
-
},
|
|
366
|
+
return e.nullable === !0 ? N.NullOr(t) : t;
|
|
367
|
+
}, Bn = (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] = zn(i));
|
|
370
|
+
return N.Struct(r);
|
|
371
|
+
}, Vn = (e) => typeof e == "function" ? e : () => e, Hn = (e, t) => ({
|
|
372
372
|
kind: "one",
|
|
373
|
-
target:
|
|
373
|
+
target: Vn(e),
|
|
374
374
|
...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
|
|
375
375
|
...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
|
|
376
|
-
}),
|
|
376
|
+
}), Un = (e, t) => ({
|
|
377
377
|
kind: "many",
|
|
378
|
-
target:
|
|
378
|
+
target: Vn(e),
|
|
379
379
|
...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
|
|
380
380
|
...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
|
|
381
|
-
}),
|
|
381
|
+
}), Wn = (e, t) => ({
|
|
382
382
|
kind: "manyToMany",
|
|
383
|
-
target:
|
|
384
|
-
through:
|
|
383
|
+
target: Vn(e),
|
|
384
|
+
through: Vn(t.through),
|
|
385
385
|
sourceKey: t.sourceKey,
|
|
386
386
|
targetKey: t.targetKey
|
|
387
|
-
}),
|
|
388
|
-
one:
|
|
389
|
-
many:
|
|
390
|
-
manyToMany:
|
|
391
|
-
},
|
|
387
|
+
}), Gn = {
|
|
388
|
+
one: Hn,
|
|
389
|
+
many: Un,
|
|
390
|
+
manyToMany: Wn
|
|
391
|
+
}, Kn = (e, t) => {
|
|
392
392
|
let n = typeof e == "function" ? e : () => e;
|
|
393
393
|
return {
|
|
394
394
|
source: n,
|
|
395
|
-
relations: t(
|
|
395
|
+
relations: t(Gn, n())
|
|
396
396
|
};
|
|
397
|
-
},
|
|
397
|
+
}, qn = (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
|
+
}, Jn = (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 Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
407
407
|
let t = e?.kind;
|
|
408
408
|
return t === "one" || t === "many" || t === "manyToMany";
|
|
409
409
|
});
|
|
410
|
-
}, Xn = Un, Zn = Wn, Qn =
|
|
410
|
+
}, Yn = Hn, Xn = Un, Zn = Wn, Qn = (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
|
+
}, $n = (e) => Object.keys(e.fields), er = (e, t) => Object.prototype.hasOwnProperty.call(e.fields, t), tr = (e) => {
|
|
417
|
+
let t = $n(e);
|
|
418
418
|
return t.length === 0 ? "<none>" : t.join(", ");
|
|
419
|
-
},
|
|
419
|
+
}, nr = (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 (!er(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}': ${tr(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 && !er(e, n.sourceKey)) {
|
|
428
|
+
let t = er(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}': ${tr(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 && !er(i, n.foreignKey)) {
|
|
432
|
+
let t = er(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}': ${tr(i)}.`));
|
|
434
434
|
}
|
|
435
|
-
},
|
|
436
|
-
let t = e.source(), n =
|
|
435
|
+
}, rr = Symbol.for("@voltro/database/relationsRegistry"), ir = globalThis, L = ir[rr] ?? (ir[rr] = /* @__PURE__ */ new Map()), ar = (e) => {
|
|
436
|
+
let t = e.source(), n = L.get(t.tableName);
|
|
437
437
|
if (n === void 0) {
|
|
438
|
-
|
|
438
|
+
L.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 Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
445
445
|
n.set(r, i);
|
|
446
446
|
}
|
|
447
447
|
}
|
|
448
|
-
},
|
|
448
|
+
}, or = (e) => {
|
|
449
449
|
let t = 0;
|
|
450
|
-
for (let n of Object.values(e))
|
|
450
|
+
for (let n of Object.values(e)) Jn(n) && (ar(n), t += 1);
|
|
451
451
|
return t;
|
|
452
|
-
},
|
|
453
|
-
let t =
|
|
452
|
+
}, sr = (e) => {
|
|
453
|
+
let t = L.get(e);
|
|
454
454
|
if (t !== void 0) return Object.fromEntries(t);
|
|
455
|
-
},
|
|
455
|
+
}, cr = (e, t) => L.get(e)?.get(t), lr = () => {
|
|
456
456
|
let e = [];
|
|
457
|
-
for (let [t, n] of
|
|
457
|
+
for (let [t, n] of L) 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)
|
|
463
|
+
}, ur = () => {
|
|
464
|
+
for (let [e, t] of L) {
|
|
465
|
+
let n = w(e);
|
|
466
|
+
if (n !== void 0) for (let [e, r] of t) nr(n, e, r);
|
|
467
467
|
}
|
|
468
|
-
},
|
|
469
|
-
|
|
470
|
-
},
|
|
468
|
+
}, dr = () => {
|
|
469
|
+
L.clear();
|
|
470
|
+
}, fr = 4, pr = (e) => Object.keys(e.fields), mr = (e, t) => Object.prototype.hasOwnProperty.call(e.fields, t), hr = (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
|
+
}, gr = (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 Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
488
488
|
} catch {
|
|
489
489
|
continue;
|
|
490
490
|
}
|
|
491
|
-
if (!
|
|
491
|
+
if (!mr(e, t.sourceKey)) continue;
|
|
492
492
|
n.push({
|
|
493
493
|
table: e.tableName,
|
|
494
494
|
foreignKey: t.sourceKey,
|
|
@@ -497,8 +497,8 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = 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 = hr(i, e), o = t.foreignKey ?? (a.length === 1 ? a[0] : void 0);
|
|
501
|
+
if (o === void 0 || !mr(i, o)) continue;
|
|
502
502
|
let s = i.fields[o];
|
|
503
503
|
n.push({
|
|
504
504
|
table: i.tableName,
|
|
@@ -507,9 +507,9 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
507
507
|
});
|
|
508
508
|
}
|
|
509
509
|
return n;
|
|
510
|
-
},
|
|
510
|
+
}, _r = (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 hr(r, e)) {
|
|
513
513
|
let e = r.fields[t];
|
|
514
514
|
n.push({
|
|
515
515
|
table: r.tableName,
|
|
@@ -518,8 +518,8 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
518
518
|
});
|
|
519
519
|
}
|
|
520
520
|
return n;
|
|
521
|
-
},
|
|
522
|
-
let t = e.tables ?? te(), n = e.relations ??
|
|
521
|
+
}, vr = (e) => `${e.table}\u0000${e.hops.map((e) => `${e.table}.${e.foreignKey}<-${e.parentKey}`).join("|")}`, yr = (e) => {
|
|
522
|
+
let t = e.tables ?? te(), n = e.relations ?? lr(), 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 Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = 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([vr(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 = gr(a.table, n), d = _r(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 Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
556
556
|
hops: [...a.hops, t],
|
|
557
557
|
depth: e,
|
|
558
558
|
via: n
|
|
559
|
-
}, f =
|
|
559
|
+
}, f = vr(d);
|
|
560
560
|
l.has(f) || (l.add(f), c.push(d), r.push(d));
|
|
561
561
|
}
|
|
562
562
|
}
|
|
@@ -566,7 +566,7 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
566
566
|
}
|
|
567
567
|
d = r;
|
|
568
568
|
}
|
|
569
|
-
for (let e of d) (
|
|
569
|
+
for (let e of d) (gr(e.table, n).length > 0 || _r(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 Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = 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: ${pr(n).join(", ")}`
|
|
579
579
|
});
|
|
580
580
|
return {
|
|
581
581
|
subjectTable: e.subjectTable,
|
|
582
582
|
paths: c,
|
|
583
583
|
limitations: o
|
|
584
584
|
};
|
|
585
|
-
},
|
|
585
|
+
}, br = (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,7 +590,7 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = 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
|
-
},
|
|
593
|
+
}, xr = (e) => e == null || typeof e == "boolean" ? e : typeof e == "number" ? e !== 0 : typeof e == "bigint" ? e !== 0n : typeof e == "string" ? e === "1" || e.toLowerCase() === "true" : e, Sr = (e) => {
|
|
594
594
|
if (e == null || typeof e != "string") return e;
|
|
595
595
|
let t = e.trim();
|
|
596
596
|
if (t.length === 0) return e;
|
|
@@ -601,7 +601,7 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
601
601
|
} catch {
|
|
602
602
|
return e;
|
|
603
603
|
}
|
|
604
|
-
},
|
|
604
|
+
}, Cr = (e) => e == null || typeof e == "string" ? e : typeof e == "number" || typeof e == "bigint" ? String(e) : e, wr = (e) => {
|
|
605
605
|
if (e == null || e instanceof Date) return e;
|
|
606
606
|
if (typeof e == "string") {
|
|
607
607
|
let t = new Date(e);
|
|
@@ -612,21 +612,22 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
612
612
|
return isNaN(t.getTime()) ? e : t;
|
|
613
613
|
}
|
|
614
614
|
return e;
|
|
615
|
-
},
|
|
615
|
+
}, Tr = (e, t, n) => {
|
|
616
616
|
if (e == null) return e;
|
|
617
617
|
switch (t) {
|
|
618
|
-
case "boolean": return n === "postgres" ? e :
|
|
619
|
-
case "
|
|
620
|
-
case "
|
|
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);
|
|
621
622
|
case "timestamp":
|
|
622
|
-
case "date": return n === "sqlite" || n === "turso" ?
|
|
623
|
+
case "date": return n === "sqlite" || n === "turso" ? wr(e) : e;
|
|
623
624
|
case "decimal":
|
|
624
|
-
case "bigint": return
|
|
625
|
+
case "bigint": return Cr(e);
|
|
625
626
|
default: return e;
|
|
626
627
|
}
|
|
627
|
-
},
|
|
628
|
+
}, Er = (e, t, n) => {
|
|
628
629
|
if (e.length === 0) return e;
|
|
629
|
-
let r =
|
|
630
|
+
let r = w(t);
|
|
630
631
|
if (r === void 0) return e;
|
|
631
632
|
let i = r.fields, a = [];
|
|
632
633
|
for (let [e, t] of Object.entries(i)) a.push({
|
|
@@ -635,31 +636,32 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
635
636
|
});
|
|
636
637
|
return e.map((e) => {
|
|
637
638
|
let t = { ...e };
|
|
638
|
-
for (let { key: e, type: r } of a) e in t && (t[e] =
|
|
639
|
+
for (let { key: e, type: r } of a) e in t && (t[e] = Tr(t[e], r, n));
|
|
639
640
|
return t;
|
|
640
641
|
});
|
|
641
|
-
},
|
|
642
|
+
}, Dr = (e, t) => {
|
|
642
643
|
if (e == null) return e;
|
|
643
644
|
switch (t) {
|
|
644
|
-
case "json":
|
|
645
|
-
case "array":
|
|
645
|
+
case "json": return JSON.stringify(e);
|
|
646
|
+
case "array":
|
|
647
|
+
case "vector": return typeof e == "string" ? e : JSON.stringify(e);
|
|
646
648
|
default: return e;
|
|
647
649
|
}
|
|
648
|
-
},
|
|
649
|
-
let r =
|
|
650
|
+
}, Or = (e, t, n = ["json", "array"]) => {
|
|
651
|
+
let r = w(t);
|
|
650
652
|
if (r === void 0) return e;
|
|
651
653
|
let i = r.fields, a = null;
|
|
652
654
|
for (let [t, r] of Object.entries(i)) if (n.includes(r.type) && t in e) {
|
|
653
|
-
let n =
|
|
655
|
+
let n = Dr(e[t], r.type);
|
|
654
656
|
n !== e[t] && (a === null && (a = { ...e }), a[t] = n);
|
|
655
657
|
}
|
|
656
658
|
return a ?? e;
|
|
657
|
-
},
|
|
659
|
+
}, kr = (e) => Object.fromEntries(Object.entries(e.updateValues ?? {}).filter(([t, n]) => {
|
|
658
660
|
if (n === void 0) return !1;
|
|
659
661
|
if (t === "id" || e.conflictColumns.includes(t)) throw Error(`upsert: updateValues cannot rewrite row identity column '${t}'`);
|
|
660
662
|
return !0;
|
|
661
|
-
})),
|
|
662
|
-
let r =
|
|
663
|
+
})), Ar = (e, t, n) => {
|
|
664
|
+
let r = kr(n);
|
|
663
665
|
if (typeof n.update == "function") return {
|
|
664
666
|
...n.update(t),
|
|
665
667
|
...r
|
|
@@ -669,21 +671,21 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
669
671
|
...Object.fromEntries(i.filter((t) => t in e).map((t) => [t, e[t]])),
|
|
670
672
|
...r
|
|
671
673
|
};
|
|
672
|
-
},
|
|
674
|
+
}, jr = (e) => typeof e == "string" ? [["id", e]] : Object.entries(e).map(([e, t]) => [e, t]), Mr = (e) => {
|
|
673
675
|
if (typeof e == "string") return e;
|
|
674
676
|
let t = Object.entries(e);
|
|
675
677
|
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");
|
|
676
|
-
},
|
|
677
|
-
let r = new Set(
|
|
678
|
+
}, Nr = (e) => typeof e != "string", Pr = (e, t, n) => {
|
|
679
|
+
let r = new Set(jr(e).map(([e]) => e)), i = t.split(".")[0];
|
|
678
680
|
return Object.fromEntries(Object.entries(n ?? {}).filter(([e, t]) => {
|
|
679
681
|
if (t === void 0) return !1;
|
|
680
682
|
if (r.has(e) || e === i) throw Error(`patchJson: additionalPatch cannot rewrite the primary key or patched JSON column '${e}'`);
|
|
681
683
|
return !0;
|
|
682
684
|
}));
|
|
683
|
-
},
|
|
684
|
-
let [r, ...i] = t.split("."), a =
|
|
685
|
+
}, Fr = (e) => typeof e == "object" && !!e && !Array.isArray(e), Ir = (e) => JSON.parse(JSON.stringify(e ?? null)), Lr = (e, t, n) => {
|
|
686
|
+
let [r, ...i] = t.split("."), a = Ir(n), o = e[r], s = (e, t) => {
|
|
685
687
|
if (t === i.length) return a;
|
|
686
|
-
let n =
|
|
688
|
+
let n = Fr(e) ? e : {}, r = i[t], o = Object.hasOwn(n, r) ? n[r] : void 0;
|
|
687
689
|
return {
|
|
688
690
|
...n,
|
|
689
691
|
[r]: s(o, t + 1)
|
|
@@ -691,14 +693,14 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
691
693
|
};
|
|
692
694
|
return {
|
|
693
695
|
...e,
|
|
694
|
-
[r]: i.length === 0 ?
|
|
696
|
+
[r]: i.length === 0 ? Fr(o) && Fr(a) ? {
|
|
695
697
|
...o,
|
|
696
698
|
...a
|
|
697
699
|
} : a : s(o, 0)
|
|
698
700
|
};
|
|
699
|
-
},
|
|
700
|
-
let [a, ...o] = n.split("."), s = i ?? e`${e(a)}`, c =
|
|
701
|
-
if ((t === "sqlite" || t === "turso") && (o.some(l) || o.length === 0 &&
|
|
701
|
+
}, Rr = (e, t, n, r, i) => {
|
|
702
|
+
let [a, ...o] = n.split("."), s = i ?? e`${e(a)}`, c = Ir(r), l = (e) => /["\\\u0000-\u001f]/.test(e);
|
|
703
|
+
if ((t === "sqlite" || t === "turso") && (o.some(l) || o.length === 0 && Fr(c) && Object.keys(c).some(l))) {
|
|
702
704
|
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`}
|
|
703
705
|
THEN json_extract('"' || replace(${t}.key, '"', ${String.raw`\"`}) || '"', '$')
|
|
704
706
|
ELSE ${t}.key END`, r = (r) => {
|
|
@@ -740,7 +742,7 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
740
742
|
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}))`;
|
|
741
743
|
}, v;
|
|
742
744
|
if (o.length === 0) {
|
|
743
|
-
if (!
|
|
745
|
+
if (!Fr(c)) v = g(c);
|
|
744
746
|
else {
|
|
745
747
|
v = h([]);
|
|
746
748
|
for (let [e, t] of Object.entries(c)) v = _(v, [e], g(t), t);
|
|
@@ -754,17 +756,17 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
754
756
|
v = _(v, o, g(c), c);
|
|
755
757
|
}
|
|
756
758
|
return e`${e(a)} = ${v}`;
|
|
757
|
-
},
|
|
759
|
+
}, zr = class extends Error {
|
|
758
760
|
_tag = "EagerCardinalityError";
|
|
759
761
|
constructor(e) {
|
|
760
762
|
super(e), this.name = "EagerCardinalityError";
|
|
761
763
|
}
|
|
762
|
-
},
|
|
764
|
+
}, Br = (e) => {
|
|
763
765
|
let { relationName: t, sourceTableName: n, targetTableName: r, foreignKey: i, sourceKey: a } = e, o = r === n;
|
|
764
766
|
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.");
|
|
765
|
-
},
|
|
767
|
+
}, Vr = async (e, t, n, r) => {
|
|
766
768
|
if (e.length === 0) return e;
|
|
767
|
-
let i =
|
|
769
|
+
let i = sr(n.tableName);
|
|
768
770
|
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?`);
|
|
769
771
|
let a = e.map((e) => ({ ...e }));
|
|
770
772
|
for (let [e, o] of Object.entries(t)) {
|
|
@@ -773,36 +775,36 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
773
775
|
let t = Object.keys(i).join(", ") || "<none>";
|
|
774
776
|
throw Error(`unknown relation '${e}' on '${n.tableName}'. Registered relations: ${t}.`);
|
|
775
777
|
}
|
|
776
|
-
|
|
778
|
+
nr(n, e, t), await Hr(a, e, t, o === !0 ? {} : o, n, r);
|
|
777
779
|
}
|
|
778
780
|
return a;
|
|
779
|
-
},
|
|
781
|
+
}, Hr = async (e, t, n, r, i, a) => {
|
|
780
782
|
switch (n.kind) {
|
|
781
783
|
case "one":
|
|
782
|
-
await
|
|
784
|
+
await Ur(e, t, n, r, i, a);
|
|
783
785
|
return;
|
|
784
786
|
case "many":
|
|
785
|
-
await
|
|
787
|
+
await Wr(e, t, n, r, i, a);
|
|
786
788
|
return;
|
|
787
789
|
case "manyToMany":
|
|
788
|
-
await
|
|
790
|
+
await Kr(e, t, n, r, i, a);
|
|
789
791
|
return;
|
|
790
792
|
}
|
|
791
|
-
},
|
|
792
|
-
let o = n.target(), s = n.sourceKey ??
|
|
793
|
+
}, Ur = async (e, t, n, r, i, a) => {
|
|
794
|
+
let o = n.target(), s = n.sourceKey ?? qr(i, o.tableName);
|
|
793
795
|
if (s !== void 0) {
|
|
794
|
-
let n =
|
|
796
|
+
let n = Jr(e, s), i = n.length === 0 ? [] : await Yr(o, "id", n, r, a), c = new Map(i.map((e) => [e.id, e]));
|
|
795
797
|
for (let n of e) {
|
|
796
798
|
let e = n[s];
|
|
797
799
|
n[t] = e == null ? null : c.get(e) ?? null;
|
|
798
800
|
}
|
|
799
|
-
await
|
|
801
|
+
await Xr(i, r.with, o, a);
|
|
800
802
|
return;
|
|
801
803
|
}
|
|
802
|
-
let c = n.foreignKey ??
|
|
804
|
+
let c = n.foreignKey ?? Qn(o, i.tableName, t), l = n.sourceKey ?? "id", u = Jr(e, l), d = u.length === 0 ? [] : await Yr(o, c, u, r, a), f = /* @__PURE__ */ new Map();
|
|
803
805
|
for (let e of d) {
|
|
804
806
|
let n = e[c];
|
|
805
|
-
if (f.has(n)) throw new Br(
|
|
807
|
+
if (f.has(n)) throw new zr(Br({
|
|
806
808
|
relationName: t,
|
|
807
809
|
sourceTableName: i.tableName,
|
|
808
810
|
targetTableName: o.tableName,
|
|
@@ -815,9 +817,9 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
815
817
|
let e = n[l];
|
|
816
818
|
n[t] = e == null ? null : f.get(e) ?? null;
|
|
817
819
|
}
|
|
818
|
-
await
|
|
819
|
-
},
|
|
820
|
-
let o = n.target(), s = n.foreignKey ??
|
|
820
|
+
await Xr(d, r.with, o, a);
|
|
821
|
+
}, Wr = async (e, t, n, r, i, a) => {
|
|
822
|
+
let o = n.target(), s = n.foreignKey ?? Qn(o, i.tableName, t), c = n.sourceKey ?? "id", l = Jr(e, c), u = Gr(r), d = l.length === 0 ? [] : await Yr(o, s, l, u, a), f = /* @__PURE__ */ new Map();
|
|
821
823
|
for (let e of d) {
|
|
822
824
|
let t = e[s], n = f.get(t);
|
|
823
825
|
n ? n.push(e) : f.set(t, [e]);
|
|
@@ -833,12 +835,12 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
833
835
|
let e = n[c];
|
|
834
836
|
n[t] = f.get(e) ?? [];
|
|
835
837
|
}
|
|
836
|
-
await
|
|
837
|
-
},
|
|
838
|
+
await Xr(d, r.with, o, a);
|
|
839
|
+
}, Gr = (e) => {
|
|
838
840
|
let { limit: t, offset: n, ...r } = e;
|
|
839
841
|
return r;
|
|
840
|
-
},
|
|
841
|
-
let o = n.target(), s = n.through(), c =
|
|
842
|
+
}, Kr = async (e, t, n, r, i, a) => {
|
|
843
|
+
let o = n.target(), s = n.through(), c = Jr(e, "id");
|
|
842
844
|
if (c.length === 0) {
|
|
843
845
|
for (let n of e) n[t] = [];
|
|
844
846
|
return;
|
|
@@ -859,8 +861,8 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
859
861
|
for (let n of e) n[t] = [];
|
|
860
862
|
return;
|
|
861
863
|
}
|
|
862
|
-
let f = await
|
|
863
|
-
await
|
|
864
|
+
let f = await Yr(o, "id", Jr(d, n.targetKey), r, a), p = new Map(f.map((e) => [e.id, e]));
|
|
865
|
+
await Xr(f, r.with, o, a);
|
|
864
866
|
let m = r.junction === void 0 ? void 0 : r.junction === !0 ? Object.keys(s.fields) : r.junction, h = /* @__PURE__ */ new Map();
|
|
865
867
|
for (let e of d) {
|
|
866
868
|
let t = e[n.sourceKey], r = e[n.targetKey], i = p.get(r);
|
|
@@ -872,16 +874,16 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
872
874
|
o ? o.push(a) : h.set(t, [a]);
|
|
873
875
|
}
|
|
874
876
|
for (let n of e) n[t] = h.get(n.id) ?? [];
|
|
875
|
-
},
|
|
877
|
+
}, qr = (e, t) => {
|
|
876
878
|
for (let [n, r] of Object.entries(e.fields)) if (r.type === "reference" && r.references?.()?.tableName === t) return n;
|
|
877
|
-
},
|
|
879
|
+
}, Jr = (e, t) => {
|
|
878
880
|
let n = /* @__PURE__ */ new Set();
|
|
879
881
|
for (let r of e) {
|
|
880
882
|
let e = r[t];
|
|
881
883
|
e != null && n.add(e);
|
|
882
884
|
}
|
|
883
885
|
return [...n];
|
|
884
|
-
},
|
|
886
|
+
}, Yr = (e, t, n, r, i) => {
|
|
885
887
|
let a = {
|
|
886
888
|
column: t,
|
|
887
889
|
op: "in",
|
|
@@ -895,63 +897,63 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
895
897
|
skip: r.offset,
|
|
896
898
|
projection: void 0
|
|
897
899
|
});
|
|
898
|
-
},
|
|
899
|
-
t !== void 0 && e.length !== 0 && (await
|
|
900
|
+
}, Xr = async (e, t, n, r) => {
|
|
901
|
+
t !== void 0 && e.length !== 0 && (await Vr(e, t, n, r)).forEach((t, n) => {
|
|
900
902
|
let r = e[n];
|
|
901
903
|
for (let [e, n] of Object.entries(t)) e in r || (r[e] = n);
|
|
902
904
|
});
|
|
903
|
-
},
|
|
905
|
+
}, Zr = (e) => e.eager !== void 0 && Object.keys(e.eager).length > 0, Qr = class extends Error {
|
|
904
906
|
_tag = "TenantNamespaceUnresolved";
|
|
905
907
|
constructor(e) {
|
|
906
908
|
super(e), this.name = "TenantNamespaceUnresolved";
|
|
907
909
|
}
|
|
908
|
-
},
|
|
910
|
+
}, $r = class extends Error {
|
|
909
911
|
_tag = "TenantNamespaceInvalid";
|
|
910
912
|
constructor(e) {
|
|
911
913
|
super(e), this.name = "TenantNamespaceInvalid";
|
|
912
914
|
}
|
|
913
|
-
},
|
|
914
|
-
if (e == null || e === "") throw new
|
|
915
|
-
let t =
|
|
916
|
-
if (t.replace(/_/g, "") === "") throw new
|
|
917
|
-
let n = `${
|
|
918
|
-
if (n.length >
|
|
915
|
+
}, ei = 63, ti = "tenant_", ni = (e) => e.toLowerCase().replace(/[^a-z0-9_]/g, "_"), ri = (e) => {
|
|
916
|
+
if (e == null || e === "") throw new Qr("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.");
|
|
917
|
+
let t = ni(e);
|
|
918
|
+
if (t.replace(/_/g, "") === "") throw new $r(`tenant id '${e}' has no usable identifier characters after sanitisation — cannot derive a distinct namespace.`);
|
|
919
|
+
let n = `${ti}${t}`;
|
|
920
|
+
if (n.length > ei) throw new $r(`namespace '${n}' for tenant '${e}' exceeds the ${ei}-byte identifier limit. Use a shorter tenant id.`);
|
|
919
921
|
return n;
|
|
920
|
-
},
|
|
921
|
-
if (e === void 0 || t == null || !
|
|
922
|
+
}, ii = (e, t) => e === null ? t : `${e}.${t}`, ai = /* @__PURE__ */ new Set(["timestamp", "date"]), oi = /^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2})?/, si = (e, t) => {
|
|
923
|
+
if (e === void 0 || t == null || !ai.has(e) || t instanceof Date) return t;
|
|
922
924
|
if (typeof t == "number" && Number.isFinite(t)) return new Date(t);
|
|
923
|
-
if (typeof t == "string" &&
|
|
925
|
+
if (typeof t == "string" && oi.test(t)) {
|
|
924
926
|
let e = new Date(t);
|
|
925
927
|
return Number.isNaN(e.getTime()) ? t : e;
|
|
926
928
|
}
|
|
927
929
|
return t;
|
|
928
|
-
},
|
|
930
|
+
}, ci = (e, t) => e === void 0 || !ai.has(e) ? t : t.map((t) => si(e, t)), li = (e, t) => {
|
|
929
931
|
let { strings: n, values: r } = e, i = t.unsafe(n[0] ?? "");
|
|
930
932
|
for (let e = 0; e < r.length; e++) i = t`${i}${r[e]}${t.unsafe(n[e + 1] ?? "")}`;
|
|
931
933
|
return t`${i}`;
|
|
932
|
-
},
|
|
933
|
-
if ("not" in e) return t`NOT (${
|
|
934
|
-
if ("and" in e) return e.and.length === 0 ? t`TRUE` : t.and(e.and.map((e) =>
|
|
935
|
-
if ("or" in e) return e.or.length === 0 ? t`FALSE` : t.or(e.or.map((e) =>
|
|
934
|
+
}, ui = (e) => e.replace(/[\\%_]/g, (e) => `\\${e}`), R = (e, t, n = null, r) => {
|
|
935
|
+
if ("not" in e) return t`NOT (${R(e.not, t, n, r)})`;
|
|
936
|
+
if ("and" in e) return e.and.length === 0 ? t`TRUE` : t.and(e.and.map((e) => R(e, t, n, r)));
|
|
937
|
+
if ("or" in e) return e.or.length === 0 ? t`FALSE` : t.or(e.or.map((e) => R(e, t, n, r)));
|
|
936
938
|
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
937
|
-
let r = e, i =
|
|
939
|
+
let r = e, i = xi(r.subquery, t, n);
|
|
938
940
|
return r.op === "subquery-in" ? t`${t(r.column)} IN (${i})` : t`${t(r.column)} NOT IN (${i})`;
|
|
939
941
|
}
|
|
940
942
|
if (e.op === "exists" || e.op === "not-exists") {
|
|
941
|
-
let r = e, i =
|
|
943
|
+
let r = e, i = xi(r.subquery, t, n);
|
|
942
944
|
return r.op === "exists" ? t`EXISTS (${i})` : t`NOT EXISTS (${i})`;
|
|
943
945
|
}
|
|
944
946
|
let i = e, a = t(i.column), o = i.path, s = o !== void 0 && o.length > 0, c = () => t.onDialectOrElse({
|
|
945
|
-
mysql: () => t.unsafe(
|
|
946
|
-
mssql: () => t.unsafe(
|
|
947
|
-
sqlite: () => t.unsafe(
|
|
948
|
-
orElse: () => t.unsafe(
|
|
947
|
+
mysql: () => t.unsafe(k(i.column, o, "mysql")),
|
|
948
|
+
mssql: () => t.unsafe(k(i.column, o, "mssql")),
|
|
949
|
+
sqlite: () => t.unsafe(k(i.column, o, "sqlite")),
|
|
950
|
+
orElse: () => t.unsafe(k(i.column, o, "postgres"))
|
|
949
951
|
}), l = () => t.onDialectOrElse({
|
|
950
|
-
mysql: () => t.unsafe(
|
|
951
|
-
mssql: () => t.unsafe(
|
|
952
|
-
sqlite: () => t.unsafe(
|
|
953
|
-
orElse: () => t.unsafe(
|
|
954
|
-
}), 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 :
|
|
952
|
+
mysql: () => t.unsafe(k(i.column, o, "mysql", { numeric: !0 })),
|
|
953
|
+
mssql: () => t.unsafe(k(i.column, o, "mssql", { numeric: !0 })),
|
|
954
|
+
sqlite: () => t.unsafe(k(i.column, o, "sqlite", { numeric: !0 })),
|
|
955
|
+
orElse: () => t.unsafe(k(i.column, o, "postgres", { numeric: !0 }))
|
|
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 : w(r)?.fields?.[i.column]?.type, h = (e) => si(m, e);
|
|
955
957
|
switch (i.op) {
|
|
956
958
|
case "eq": return t`${u} = ${f(h(i.value))}`;
|
|
957
959
|
case "neq": return t`${u} <> ${f(h(i.value))}`;
|
|
@@ -968,7 +970,7 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
968
970
|
return e.length === 0 ? t`TRUE` : t`${u} NOT IN ${t.in(s ? e.map((e) => f(e)) : e)}`;
|
|
969
971
|
}
|
|
970
972
|
case "contains": {
|
|
971
|
-
let e = `%${
|
|
973
|
+
let e = `%${ui(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
|
|
972
974
|
return t.onDialectOrElse({
|
|
973
975
|
mysql: () => t`LOWER(${u}) LIKE LOWER(${e})`,
|
|
974
976
|
mssql: () => t`LOWER(${u}) LIKE LOWER(${e})`,
|
|
@@ -977,7 +979,7 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
977
979
|
});
|
|
978
980
|
}
|
|
979
981
|
case "startsWith": {
|
|
980
|
-
let e = `${
|
|
982
|
+
let e = `${ui(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
|
|
981
983
|
return t.onDialectOrElse({
|
|
982
984
|
mysql: () => t`${u} LIKE ${e}`,
|
|
983
985
|
orElse: () => t`${u} LIKE ${e} ESCAPE '\\'`
|
|
@@ -1025,13 +1027,13 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
1025
1027
|
});
|
|
1026
1028
|
}
|
|
1027
1029
|
}
|
|
1028
|
-
},
|
|
1030
|
+
}, di = (e, t) => {
|
|
1029
1031
|
let n = [];
|
|
1030
1032
|
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}`);
|
|
1031
|
-
},
|
|
1033
|
+
}, fi = (e, t) => t.csv(e.map((e) => {
|
|
1032
1034
|
let n = e.column === void 0 ? t.unsafe("*") : t`${t(e.column)}`;
|
|
1033
1035
|
if (e.op.startsWith("window-")) {
|
|
1034
|
-
let r =
|
|
1036
|
+
let r = di(e.window ?? {}, t);
|
|
1035
1037
|
switch (e.op) {
|
|
1036
1038
|
case "window-row-number": return t`ROW_NUMBER() OVER (${r}) AS ${t(e.alias)}`;
|
|
1037
1039
|
case "window-rank": return t`RANK() OVER (${r}) AS ${t(e.alias)}`;
|
|
@@ -1055,43 +1057,43 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
1055
1057
|
return t`${t(e.column)} AS ${t(e.alias)}`;
|
|
1056
1058
|
default: throw Error(`compileAggregateProjection: unknown op '${e.op}'`);
|
|
1057
1059
|
}
|
|
1058
|
-
})),
|
|
1060
|
+
})), pi = (e) => `[${e.join(",")}]`, mi = (e, t) => {
|
|
1059
1061
|
if (e.queryVector === void 0) return null;
|
|
1060
|
-
let n = t(e.column), r =
|
|
1062
|
+
let n = t(e.column), r = pi(e.queryVector), i = e.distance === "cosine" ? "<=>" : e.distance === "l2" ? "<->" : "<#>", a = e.distance === "cosine" ? "VEC_DISTANCE_COSINE" : "VEC_DISTANCE_EUCLIDEAN";
|
|
1061
1063
|
return t.onDialectOrElse({
|
|
1062
1064
|
mysql: () => t`${t.unsafe(a)}(${n}, ${r})`,
|
|
1063
1065
|
mssql: () => t`NULL`,
|
|
1064
1066
|
sqlite: () => t`NULL`,
|
|
1065
1067
|
orElse: () => t`${n} ${t.unsafe(i)} ${r}::vector`
|
|
1066
1068
|
});
|
|
1067
|
-
},
|
|
1069
|
+
}, hi = (e, t) => {
|
|
1068
1070
|
let n = t.unsafe(e.useGeography ? "::geography" : "::geometry");
|
|
1069
1071
|
return t`ST_Distance(${t(e.column)}${n}, ${e.geom}${n})`;
|
|
1070
|
-
},
|
|
1071
|
-
let r = n.csv(e.columns.map((e) => n`${n(e)}`)), i = `%${
|
|
1072
|
+
}, gi = (e, t) => t`${t(e.column)} <-> ${e.geom}::geometry`, _i = (e, t) => t`${t(`${e.indexName}_tsv`)}`, vi = (e, t) => `${t}_${e.indexName}_fts`, yi = (e, t, n) => {
|
|
1073
|
+
let r = n.csv(e.columns.map((e) => n`${n(e)}`)), i = `%${ui(e.query)}%`;
|
|
1072
1074
|
return n.onDialectOrElse({
|
|
1073
1075
|
mysql: () => n`MATCH(${r}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
|
|
1074
1076
|
sqlite: () => {
|
|
1075
|
-
let r = n(
|
|
1077
|
+
let r = n(vi(e, t));
|
|
1076
1078
|
return n`${n("id")} IN (SELECT ${n("row_id")} FROM ${r} WHERE ${r} MATCH ${e.query})`;
|
|
1077
1079
|
},
|
|
1078
1080
|
mssql: () => n.or(e.columns.map((e) => n`LOWER(${n(e)}) LIKE LOWER(${i}) ESCAPE '\\'`)),
|
|
1079
|
-
orElse: () => n`${
|
|
1081
|
+
orElse: () => n`${_i(e, n)} @@ plainto_tsquery(${e.config ?? "english"}, ${e.query})`
|
|
1080
1082
|
});
|
|
1081
|
-
},
|
|
1082
|
-
let r = `%${
|
|
1083
|
+
}, bi = (e, t, n) => {
|
|
1084
|
+
let r = `%${ui(e.query)}%`;
|
|
1083
1085
|
return n.onDialectOrElse({
|
|
1084
1086
|
mysql: () => n`MATCH(${n.csv(e.columns.map((e) => n`${n(e)}`))}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
|
|
1085
1087
|
sqlite: () => {
|
|
1086
|
-
let r = n(
|
|
1088
|
+
let r = n(vi(e, t));
|
|
1087
1089
|
return n`COALESCE((SELECT -bm25(${r}) FROM ${r} WHERE ${r} MATCH ${e.query} AND ${r}.${n("row_id")} = ${n("id")}), 0)`;
|
|
1088
1090
|
},
|
|
1089
1091
|
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}`),
|
|
1090
|
-
orElse: () => n`ts_rank(${
|
|
1092
|
+
orElse: () => n`ts_rank(${_i(e, n)}, plainto_tsquery(${e.config ?? "english"}, ${e.query}))`
|
|
1091
1093
|
});
|
|
1092
|
-
},
|
|
1094
|
+
}, xi = (e, t, n = null) => {
|
|
1093
1095
|
if (e.setOp && e.setOp.queries.length >= 2) {
|
|
1094
|
-
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`(${
|
|
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`(${xi(e, t, n)})`).reduce((e, n, i) => i === 0 ? n : t`${e} ${t.unsafe(r)} ${n}`), a = [];
|
|
1095
1097
|
if (b(e).length > 0 && a.push(t` ORDER BY ${t.csv(b(e).map((e) => e.direction === "desc" ? t`${t(e.column)} DESC` : t`${t(e.column)} ASC`))}`), e.take !== void 0) {
|
|
1096
1098
|
if (!Number.isInteger(e.take) || e.take < 0) throw Error(`compileSelect: invalid take ${e.take}`);
|
|
1097
1099
|
a.push(t` LIMIT ${t.unsafe(String(e.take))}`);
|
|
@@ -1102,7 +1104,7 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
1102
1104
|
}
|
|
1103
1105
|
return t`${i}${a.reduce((e, n) => t`${e}${n}`, t``)}`;
|
|
1104
1106
|
}
|
|
1105
|
-
let r = e.annClause === void 0 ? null :
|
|
1107
|
+
let r = e.annClause === void 0 ? null : mi(e.annClause, t);
|
|
1106
1108
|
e.spatialClause !== void 0 && t.onDialectOrElse({
|
|
1107
1109
|
mysql: () => {
|
|
1108
1110
|
throw Error("@voltro/plugin-postgis: spatial distance / KNN ordering is postgres-only");
|
|
@@ -1115,7 +1117,7 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
1115
1117
|
},
|
|
1116
1118
|
orElse: () => t``
|
|
1117
1119
|
});
|
|
1118
|
-
let i = e.spatialClause?.projectAs === void 0 ? null :
|
|
1120
|
+
let i = e.spatialClause?.projectAs === void 0 ? null : hi(e.spatialClause, t), a = e.aggregations && e.aggregations.length > 0 ? fi(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 ? bi(c, e.table, t) : null, u = l !== null && c?.rank !== void 0 ? t`${s}, ${l} AS ${t(c.rank.alias)}` : s, d = i !== null && !o && e.spatialClause?.projectAs !== void 0 ? t`${u}, ${i} AS ${t(e.spatialClause.projectAs)}` : u, f = e.distinctOn && e.distinctOn.length > 0 ? t.onDialectOrElse({
|
|
1119
1121
|
orElse: () => t`DISTINCT ON (${t.csv(e.distinctOn.map((e) => t`${t(e)}`))}) `,
|
|
1120
1122
|
mysql: () => t`DISTINCT `,
|
|
1121
1123
|
mssql: () => t`DISTINCT `,
|
|
@@ -1127,52 +1129,52 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
1127
1129
|
mssql: () => t``,
|
|
1128
1130
|
sqlite: () => t``,
|
|
1129
1131
|
orElse: () => t` FOR UPDATE`
|
|
1130
|
-
}) : t``, g = e.alias === void 0 ? t`${t(
|
|
1132
|
+
}) : t``, g = e.alias === void 0 ? t`${t(ii(n, e.table))}${m}` : t`${t(ii(n, e.table))} AS ${t(e.alias)}${m}`, _ = (e.joins ?? []).map((e) => {
|
|
1131
1133
|
let r = e.kind === "inner" ? "INNER" : "LEFT";
|
|
1132
|
-
return t` ${t.unsafe(r)} JOIN ${t(
|
|
1133
|
-
}), v = _.length > 0 ? _.reduce((e, n) => t`${e}${n}`, g) : g, ee = c === void 0 ? null :
|
|
1134
|
-
r !== null && x.push(t`${r} ASC`), e.spatialClause?.order !== void 0 && x.push(e.spatialClause.order === "desc" ? t`${
|
|
1134
|
+
return t` ${t.unsafe(r)} JOIN ${t(ii(n, e.table))} AS ${t(e.alias)} ON ${R(e.on, t, n)}`;
|
|
1135
|
+
}), v = _.length > 0 ? _.reduce((e, n) => t`${e}${n}`, g) : g, ee = c === void 0 ? null : yi(c, e.table, t), te = [e.predicate ? R(e.predicate, t, n, e.table) : null, ee].filter((e) => e !== null), y = te.length > 0 ? t` WHERE ${t.and(te)}` : t``, ne = e.groupBy && e.groupBy.length > 0 ? t` GROUP BY ${t.csv(e.groupBy.map((e) => t`${t(e)}`))}` : t``, re = e.having ? t` HAVING ${R(e.having, t, n, e.table)}` : t``, ie = e.skip !== void 0, x = [];
|
|
1136
|
+
r !== null && x.push(t`${r} ASC`), e.spatialClause?.order !== void 0 && x.push(e.spatialClause.order === "desc" ? t`${gi(e.spatialClause, t)} DESC` : t`${gi(e.spatialClause, t)} ASC`), l !== null && c?.rank?.order === !0 && x.push(t`${l} DESC`);
|
|
1135
1137
|
for (let n of b(e)) x.push(n.direction === "desc" ? t`${t(n.column)} DESC` : t`${t(n.column)} ASC`);
|
|
1136
1138
|
let ae = x.length > 0 ? t` ORDER BY ${t.csv(x)}` : ie ? t.onDialectOrElse({
|
|
1137
1139
|
mssql: () => t` ORDER BY (SELECT NULL)`,
|
|
1138
1140
|
orElse: () => t``
|
|
1139
|
-
}) : t``,
|
|
1141
|
+
}) : t``, S = (e) => {
|
|
1140
1142
|
if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw Error(`compileSelect: expected non-negative integer take/skip, got ${e}`);
|
|
1141
1143
|
return t.unsafe(String(e));
|
|
1142
|
-
},
|
|
1144
|
+
}, oe = (e.ctes ?? []).map((e) => t`${t(e.name)} AS (${xi(e.descriptor, t, n)})`), se = (e.ctes ?? []).some((e) => e.recursive === !0), ce = oe.length > 0 ? t`WITH ${t.unsafe(se ? "RECURSIVE " : "")}${t.csv(oe)} ` : t``;
|
|
1143
1145
|
return t.onDialectOrElse({
|
|
1144
1146
|
mssql: () => {
|
|
1145
|
-
let n = e.take !== void 0 && !ie ? t`TOP ${
|
|
1146
|
-
return t`${
|
|
1147
|
+
let n = e.take !== void 0 && !ie ? t`TOP ${S(e.take)} ` : t``, r = ie ? t` OFFSET ${S(e.skip)} ROWS FETCH NEXT ${S(e.take ?? 2 ** 53 - 1)} ROWS ONLY` : t``;
|
|
1148
|
+
return t`${ce}SELECT ${n}${f}${d} FROM ${v}${y}${ne}${re}${ae}${r}`;
|
|
1147
1149
|
},
|
|
1148
1150
|
orElse: () => {
|
|
1149
|
-
let n = e.take === void 0 ? t`` : t` LIMIT ${
|
|
1150
|
-
return t`${
|
|
1151
|
+
let n = e.take === void 0 ? t`` : t` LIMIT ${S(e.take)}`, r = ie ? t` OFFSET ${S(e.skip)}` : t``;
|
|
1152
|
+
return t`${ce}SELECT ${f}${d} FROM ${v}${y}${ne}${re}${ae}${n}${r}${h}`;
|
|
1151
1153
|
}
|
|
1152
1154
|
});
|
|
1153
|
-
},
|
|
1155
|
+
}, Si = (e, t, n) => {
|
|
1154
1156
|
if (e.eager === void 0) return null;
|
|
1155
|
-
let r =
|
|
1157
|
+
let r = Ti(e.table, e.eager, e.sourceTable);
|
|
1156
1158
|
if (r === null) return null;
|
|
1157
|
-
let i =
|
|
1159
|
+
let i = Mi(n, e, r, ji(t, n));
|
|
1158
1160
|
return i === null ? null : {
|
|
1159
1161
|
fragment: i,
|
|
1160
|
-
decode:
|
|
1162
|
+
decode: Fi(r, n)
|
|
1161
1163
|
};
|
|
1162
|
-
},
|
|
1164
|
+
}, Ci = (e) => e.relation.kind === "one" && e.fkSide === "target", wi = (e) => ({
|
|
1163
1165
|
...e,
|
|
1164
1166
|
branch: {
|
|
1165
1167
|
...e.branch,
|
|
1166
1168
|
limit: 2
|
|
1167
1169
|
}
|
|
1168
|
-
}),
|
|
1169
|
-
let r = n ??
|
|
1170
|
+
}), Ti = (e, t, n) => {
|
|
1171
|
+
let r = n ?? ze(e), i = sr(e);
|
|
1170
1172
|
if (i === void 0) return null;
|
|
1171
1173
|
let a = [];
|
|
1172
1174
|
for (let [e, n] of Object.entries(t)) {
|
|
1173
1175
|
let t = i[e];
|
|
1174
1176
|
if (t === void 0) return null;
|
|
1175
|
-
let o =
|
|
1177
|
+
let o = Ei(e, t, r, n === !0 ? {} : n);
|
|
1176
1178
|
if (o === null) return null;
|
|
1177
1179
|
a.push(o);
|
|
1178
1180
|
}
|
|
@@ -1180,30 +1182,30 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
1180
1182
|
table: r,
|
|
1181
1183
|
children: a
|
|
1182
1184
|
};
|
|
1183
|
-
},
|
|
1185
|
+
}, Ei = (e, t, n, r) => {
|
|
1184
1186
|
let i = t.target(), a = (t.kind === "manyToMany" ? void 0 : t.sourceKey) ?? "id", o, s;
|
|
1185
1187
|
if (t.kind === "manyToMany") o = t.targetKey, s = "target";
|
|
1186
1188
|
else if (t.kind === "one") {
|
|
1187
|
-
let r = t.sourceKey ??
|
|
1189
|
+
let r = t.sourceKey ?? Ai(n, i.tableName);
|
|
1188
1190
|
if (r !== void 0) o = r, s = "source";
|
|
1189
1191
|
else try {
|
|
1190
|
-
o = t.foreignKey ??
|
|
1192
|
+
o = t.foreignKey ?? Qn(i, n.tableName, e), s = "target";
|
|
1191
1193
|
} catch {
|
|
1192
1194
|
return null;
|
|
1193
1195
|
}
|
|
1194
1196
|
} else try {
|
|
1195
|
-
o = t.foreignKey ??
|
|
1197
|
+
o = t.foreignKey ?? Qn(i, n.tableName, e), s = "target";
|
|
1196
1198
|
} catch {
|
|
1197
1199
|
return null;
|
|
1198
1200
|
}
|
|
1199
1201
|
let c = r.with === void 0 ? [] : (() => {
|
|
1200
|
-
let e =
|
|
1202
|
+
let e = sr(i.tableName);
|
|
1201
1203
|
if (e === void 0 && Object.keys(r.with).length > 0) return null;
|
|
1202
1204
|
let t = [];
|
|
1203
1205
|
for (let [n, a] of Object.entries(r.with)) {
|
|
1204
1206
|
let r = e?.[n];
|
|
1205
1207
|
if (r === void 0) return null;
|
|
1206
|
-
let o =
|
|
1208
|
+
let o = Ei(n, r, i, a === !0 ? {} : a);
|
|
1207
1209
|
if (o === null) return null;
|
|
1208
1210
|
t.push(o);
|
|
1209
1211
|
}
|
|
@@ -1219,9 +1221,9 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
1219
1221
|
fkSide: s,
|
|
1220
1222
|
branch: r,
|
|
1221
1223
|
children: c,
|
|
1222
|
-
junction:
|
|
1224
|
+
junction: Di(t, r)
|
|
1223
1225
|
};
|
|
1224
|
-
},
|
|
1226
|
+
}, Di = (e, t) => {
|
|
1225
1227
|
if (e.kind !== "manyToMany" || t.junction === void 0) return;
|
|
1226
1228
|
let n = e.through(), r = t.junction === !0 ? Object.keys(n.fields) : t.junction, i = r.filter((e) => e in n.fields);
|
|
1227
1229
|
return {
|
|
@@ -1233,35 +1235,35 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
1233
1235
|
return t !== void 0 && (t.type === "timestamp" || t.type === "date");
|
|
1234
1236
|
})
|
|
1235
1237
|
};
|
|
1236
|
-
},
|
|
1238
|
+
}, Oi = (e) => `__j_${e}`, ki = "__j", Ai = (e, t) => {
|
|
1237
1239
|
for (let [n, r] of Object.entries(e.fields)) if (r.type === "reference" && r.references?.()?.tableName === t) return n;
|
|
1238
|
-
},
|
|
1240
|
+
}, ji = (e, t) => {
|
|
1239
1241
|
let n = 0;
|
|
1240
1242
|
return {
|
|
1241
1243
|
sql: e,
|
|
1242
1244
|
dialect: t,
|
|
1243
1245
|
nextAlias: () => `__a${n++}`
|
|
1244
1246
|
};
|
|
1245
|
-
},
|
|
1247
|
+
}, Mi = (e, t, n, r) => {
|
|
1246
1248
|
switch (e) {
|
|
1247
|
-
case "postgres": return
|
|
1249
|
+
case "postgres": return Ri(t, n, r);
|
|
1248
1250
|
case "sqlite":
|
|
1249
|
-
case "turso": return
|
|
1251
|
+
case "turso": return Ki(t, n, r);
|
|
1250
1252
|
case "mysql":
|
|
1251
|
-
case "mariadb": return
|
|
1252
|
-
case "mssql": return
|
|
1253
|
+
case "mariadb": return na(t, n, r);
|
|
1254
|
+
case "mssql": return la(t, n, r);
|
|
1253
1255
|
}
|
|
1254
|
-
},
|
|
1255
|
-
let n =
|
|
1256
|
+
}, Ni = (e, t) => t === "mssql" && !Pi.test(e) ? /* @__PURE__ */ new Date(`${e}Z`) : new Date(e), Pi = /(?:Z|[+-]\d{2}:?\d{2})$/, Fi = (e, t) => {
|
|
1257
|
+
let n = Ii(e.table, e.children, t);
|
|
1256
1258
|
return (e) => e.map((e) => {
|
|
1257
1259
|
let t = e.__row, r = typeof t == "string" ? JSON.parse(t) : t;
|
|
1258
1260
|
return n(r);
|
|
1259
1261
|
});
|
|
1260
|
-
},
|
|
1261
|
-
let r = [];
|
|
1262
|
-
for (let [t, n] of Object.entries(e.fields)) (n.type === "timestamp" || n.type === "date") && r.push(t);
|
|
1263
|
-
let
|
|
1264
|
-
let t =
|
|
1262
|
+
}, Ii = (e, t, n) => {
|
|
1263
|
+
let r = [], i = [];
|
|
1264
|
+
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
|
+
let a = t.map((e) => {
|
|
1266
|
+
let t = Ii(e.target, e.children, n), r = e.relation.kind === "one", i = Ci(e), a = i ? Br({
|
|
1265
1267
|
relationName: e.relationName,
|
|
1266
1268
|
sourceTableName: e.source.tableName,
|
|
1267
1269
|
targetTableName: e.target.tableName,
|
|
@@ -1274,16 +1276,17 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
1274
1276
|
isSingle: r,
|
|
1275
1277
|
fromOverFetch: i,
|
|
1276
1278
|
cardinalityMessage: a,
|
|
1277
|
-
junction:
|
|
1279
|
+
junction: Li(e.junction, n)
|
|
1278
1280
|
};
|
|
1279
1281
|
});
|
|
1280
1282
|
return (e) => {
|
|
1281
1283
|
let t = { ...e };
|
|
1284
|
+
for (let e of i) e in t && (t[e] = Tr(t[e], "vector", n));
|
|
1282
1285
|
for (let e of r) {
|
|
1283
1286
|
let r = t[e];
|
|
1284
|
-
typeof r == "string" && (t[e] =
|
|
1287
|
+
typeof r == "string" && (t[e] = Ni(r, n));
|
|
1285
1288
|
}
|
|
1286
|
-
for (let e of
|
|
1289
|
+
for (let e of a) {
|
|
1287
1290
|
let n = t[e.name];
|
|
1288
1291
|
if (n == null) {
|
|
1289
1292
|
t[e.name] = e.isSingle ? null : [];
|
|
@@ -1291,7 +1294,7 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
1291
1294
|
}
|
|
1292
1295
|
if (e.fromOverFetch) {
|
|
1293
1296
|
let r = n;
|
|
1294
|
-
if (r.length > 1) throw new
|
|
1297
|
+
if (r.length > 1) throw new zr(e.cardinalityMessage);
|
|
1295
1298
|
t[e.name] = r.length === 0 ? null : e.decode(r[0]);
|
|
1296
1299
|
continue;
|
|
1297
1300
|
}
|
|
@@ -1303,204 +1306,204 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
1303
1306
|
}
|
|
1304
1307
|
return t;
|
|
1305
1308
|
};
|
|
1306
|
-
},
|
|
1309
|
+
}, Li = (e, t) => {
|
|
1307
1310
|
if (e === void 0) return;
|
|
1308
1311
|
let n = new Set(e.dateColumns), r = e.requested;
|
|
1309
1312
|
return (e) => {
|
|
1310
1313
|
let i = e._junction ?? {}, a = {};
|
|
1311
1314
|
for (let e of r) {
|
|
1312
1315
|
let r = i[e];
|
|
1313
|
-
a[e] = n.has(e) && typeof r == "string" ?
|
|
1316
|
+
a[e] = n.has(e) && typeof r == "string" ? Ni(r, t) : r;
|
|
1314
1317
|
}
|
|
1315
1318
|
return {
|
|
1316
1319
|
...e,
|
|
1317
1320
|
_junction: a
|
|
1318
1321
|
};
|
|
1319
1322
|
};
|
|
1320
|
-
},
|
|
1321
|
-
let r = n.sql, i = n.nextAlias(), a = r(t.table.tableName), o = r(i), s =
|
|
1322
|
-
return s === null ? null : r`SELECT ${s} AS "__row" FROM ${a} AS ${o}${e.predicate ? r` WHERE ${
|
|
1323
|
-
},
|
|
1324
|
-
let i = n.sql, a = r === void 0 ? i`to_jsonb(${i(e)}.*)` : i`(to_jsonb(${i(e)}.*) - ${
|
|
1323
|
+
}, Ri = (e, t, n) => {
|
|
1324
|
+
let r = n.sql, i = n.nextAlias(), a = r(t.table.tableName), o = r(i), s = zi(i, t.children, n);
|
|
1325
|
+
return s === null ? null : r`SELECT ${s} AS "__row" FROM ${a} AS ${o}${e.predicate ? r` WHERE ${W(e.predicate, i, r)}` : r``}${b(e).length > 0 ? r` ORDER BY ${r.csv(b(e).map((e) => e.direction === "desc" ? r`${V(i, e.column, r)} DESC` : r`${V(i, e.column, r)} ASC`))}` : r``}${e.take === void 0 ? r`` : r` LIMIT ${U(e.take, r)}`}${e.skip === void 0 ? r`` : r` OFFSET ${U(e.skip, r)}`}`;
|
|
1326
|
+
}, zi = (e, t, n, r) => {
|
|
1327
|
+
let i = n.sql, a = r === void 0 ? i`to_jsonb(${i(e)}.*)` : i`(to_jsonb(${i(e)}.*) - ${H(ki, i)}::text)`;
|
|
1325
1328
|
if (t.length === 0 && r === void 0) return a;
|
|
1326
1329
|
let o = [];
|
|
1327
|
-
r !== void 0 && o.push(i`${
|
|
1330
|
+
r !== void 0 && o.push(i`${H("_junction", i)}, ${V(e, ki, i)}`);
|
|
1328
1331
|
for (let r of t) {
|
|
1329
|
-
let t =
|
|
1332
|
+
let t = Bi(r, e, n);
|
|
1330
1333
|
if (t === null) return null;
|
|
1331
|
-
o.push(i`${
|
|
1334
|
+
o.push(i`${H(r.relationName, i)}, ${t}`);
|
|
1332
1335
|
}
|
|
1333
1336
|
return i`${a} || jsonb_build_object(${i.csv(o)})`;
|
|
1334
|
-
},
|
|
1337
|
+
}, Bi = (e, t, n) => {
|
|
1335
1338
|
switch (e.relation.kind) {
|
|
1336
|
-
case "one": return
|
|
1337
|
-
case "many": return
|
|
1338
|
-
case "manyToMany": return
|
|
1339
|
+
case "one": return Ci(e) ? Hi(wi(e), t, n) : Vi(e, t, n);
|
|
1340
|
+
case "many": return Hi(e, t, n);
|
|
1341
|
+
case "manyToMany": return Ui(e, t, n);
|
|
1339
1342
|
}
|
|
1340
|
-
},
|
|
1341
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1343
|
+
}, Vi = (e, t, n) => {
|
|
1344
|
+
let r = n.sql, i = n.nextAlias(), a = zi(i, e.children, n);
|
|
1342
1345
|
if (a === null) return null;
|
|
1343
|
-
let o = e.fkSide === "source" ? r`${
|
|
1346
|
+
let o = e.fkSide === "source" ? r`${V(i, "id", r)} = ${V(t, e.foreignKey, r)}` : r`${V(i, e.foreignKey, r)} = ${V(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${W(e.branch.where, i, r)}`, c = z(i, e.branch.orderBy, r);
|
|
1344
1347
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}${c} LIMIT 1)`;
|
|
1345
|
-
},
|
|
1346
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1348
|
+
}, Hi = (e, t, n) => {
|
|
1349
|
+
let r = n.sql, i = n.nextAlias(), a = zi(i, e.children, n);
|
|
1347
1350
|
if (a === null) return null;
|
|
1348
|
-
let o = r`${
|
|
1351
|
+
let o = r`${V(void 0, e.foreignKey, r)} = ${V(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${R(e.branch.where, r)}`, c = Gi(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${U(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${U(e.branch.offset, r)}`;
|
|
1349
1352
|
return r`COALESCE((SELECT jsonb_agg(${a}) FROM (SELECT * FROM ${r(e.target.tableName)} WHERE ${o}${s}${c}${l}${u}) AS ${r(i)}), '[]'::jsonb)`;
|
|
1350
|
-
},
|
|
1351
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
1353
|
+
}, Ui = (e, t, n) => {
|
|
1354
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = zi(o, e.children, n, e.junction);
|
|
1352
1355
|
if (c === null) return null;
|
|
1353
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1354
|
-
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 ${
|
|
1355
|
-
},
|
|
1356
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1356
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${R(e.branch.where, r)}`, u = _a(e, s, r), d = z(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${U(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${U(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : r`, ${Wi(e.junction, s, r)} AS ${r(ki)}`;
|
|
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 ${V(o, "id", r)} = ${V(s, i.targetKey, r)} WHERE ${V(s, i.sourceKey, r)} = ${V(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), '[]'::jsonb)`;
|
|
1358
|
+
}, Wi = (e, t, n) => e.present.length === 0 ? n`jsonb_build_object()` : n`jsonb_build_object(${n.csv(e.present.map((e) => n`${H(e, n)}, ${V(t, e, n)}`))})`, z = (e, t, n) => t === void 0 || t.length === 0 ? n`` : n` ORDER BY ${n.csv(t.map((t) => t.direction === "desc" ? n`${V(e, t.column, n)} DESC` : n`${V(e, t.column, n)} ASC`))}`, Gi = (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`))}`, Ki = (e, t, n) => {
|
|
1359
|
+
let r = n.sql, i = n.nextAlias(), a = qi(i, t.table, t.children, n);
|
|
1357
1360
|
if (a === null) return null;
|
|
1358
|
-
let o = e.predicate ? r` WHERE ${
|
|
1361
|
+
let o = e.predicate ? r` WHERE ${W(e.predicate, i, r)}` : r``, s = b(e).length > 0 ? r` ORDER BY ${r.csv(b(e).map((e) => e.direction === "desc" ? r`${V(i, e.column, r)} DESC` : r`${V(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${U(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${U(e.skip, r)}`;
|
|
1359
1362
|
return r`SELECT ${a} AS "__row" FROM ${r(t.table.tableName)} AS ${r(i)}${o}${s}${c}${l}`;
|
|
1360
|
-
},
|
|
1363
|
+
}, qi = (e, t, n, r, i) => {
|
|
1361
1364
|
let a = r.sql, o = [];
|
|
1362
|
-
for (let n of Object.keys(t.fields)) o.push(a`${
|
|
1365
|
+
for (let n of Object.keys(t.fields)) o.push(a`${H(n, a)}, ${V(e, n, a)}`);
|
|
1363
1366
|
if (i !== void 0) {
|
|
1364
|
-
let e =
|
|
1365
|
-
o.push(a`${
|
|
1367
|
+
let e = Ji(i.projection, i.source, a);
|
|
1368
|
+
o.push(a`${H("_junction", a)}, json_object(${e})`);
|
|
1366
1369
|
}
|
|
1367
1370
|
for (let t of n) {
|
|
1368
|
-
let n =
|
|
1371
|
+
let n = Qi(t, e, r);
|
|
1369
1372
|
if (n === null) return null;
|
|
1370
|
-
o.push(a`${
|
|
1373
|
+
o.push(a`${H(t.relationName, a)}, ${n}`);
|
|
1371
1374
|
}
|
|
1372
1375
|
return a`json_object(${a.csv(o)})`;
|
|
1373
|
-
},
|
|
1376
|
+
}, Ji = (e, t, n) => e.present.length === 0 ? n`` : n.csv(e.present.map((e) => n`${H(e, n)}, ${V(t.alias, t.physical(e), n)}`)), Yi = (e, t, n) => e.present.length === 0 ? n`` : n`, ${n.csv(e.present.map((e) => n`${V(t, e, n)} AS ${n(Oi(e))}`))}`, Xi = (e) => ({
|
|
1374
1377
|
alias: e,
|
|
1375
|
-
physical:
|
|
1376
|
-
}),
|
|
1378
|
+
physical: Oi
|
|
1379
|
+
}), Zi = (e) => ({
|
|
1377
1380
|
alias: e,
|
|
1378
1381
|
physical: (e) => e
|
|
1379
|
-
}),
|
|
1382
|
+
}), Qi = (e, t, n) => {
|
|
1380
1383
|
switch (e.relation.kind) {
|
|
1381
|
-
case "one": return
|
|
1382
|
-
case "many": return
|
|
1383
|
-
case "manyToMany": return
|
|
1384
|
+
case "one": return Ci(e) ? ea(wi(e), t, n) : $i(e, t, n);
|
|
1385
|
+
case "many": return ea(e, t, n);
|
|
1386
|
+
case "manyToMany": return ta(e, t, n);
|
|
1384
1387
|
}
|
|
1385
|
-
},
|
|
1386
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1388
|
+
}, $i = (e, t, n) => {
|
|
1389
|
+
let r = n.sql, i = n.nextAlias(), a = qi(i, e.target, e.children, n);
|
|
1387
1390
|
if (a === null) return null;
|
|
1388
|
-
let o = e.fkSide === "source" ? r`${
|
|
1391
|
+
let o = e.fkSide === "source" ? r`${V(i, "id", r)} = ${V(t, e.foreignKey, r)}` : r`${V(i, e.foreignKey, r)} = ${V(t, e.sourceKey, r)}`;
|
|
1389
1392
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
|
|
1390
|
-
},
|
|
1391
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1393
|
+
}, ea = (e, t, n) => {
|
|
1394
|
+
let r = n.sql, i = n.nextAlias(), a = qi(i, e.target, e.children, n);
|
|
1392
1395
|
if (a === null) return null;
|
|
1393
|
-
let o = r`${
|
|
1396
|
+
let o = r`${V(void 0, e.foreignKey, r)} = ${V(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${R(G(e.branch.where), r)}`, c = Gi(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${U(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${U(e.branch.offset, r)}`;
|
|
1394
1397
|
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('[]'))`;
|
|
1395
|
-
},
|
|
1396
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
1398
|
+
}, ta = (e, t, n) => {
|
|
1399
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = qi(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
1397
1400
|
projection: e.junction,
|
|
1398
|
-
source:
|
|
1401
|
+
source: Xi(o)
|
|
1399
1402
|
});
|
|
1400
1403
|
if (c === null) return null;
|
|
1401
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1402
|
-
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 ${
|
|
1403
|
-
},
|
|
1404
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1404
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${R(G(e.branch.where), r)}`, u = _a(e, s, r, !0), d = z(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${U(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${U(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : Yi(e.junction, s, r);
|
|
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 ${V(o, "id", r)} = ${V(s, i.targetKey, r)} WHERE ${V(s, i.sourceKey, r)} = ${V(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), json('[]'))`;
|
|
1406
|
+
}, na = (e, t, n) => {
|
|
1407
|
+
let r = n.sql, i = n.nextAlias(), a = B(i, t.table, t.children, n);
|
|
1405
1408
|
if (a === null) return null;
|
|
1406
|
-
let o = e.predicate ? r` WHERE ${
|
|
1409
|
+
let o = e.predicate ? r` WHERE ${W(e.predicate, i, r)}` : r``, s = b(e).length > 0 ? r` ORDER BY ${r.csv(b(e).map((e) => e.direction === "desc" ? r`${V(i, e.column, r)} DESC` : r`${V(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${U(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${U(e.skip, r)}`;
|
|
1407
1410
|
return r`SELECT ${a} AS \`__row\` FROM ${r(t.table.tableName)} AS ${r(i)}${o}${s}${c}${l}`;
|
|
1408
|
-
},
|
|
1411
|
+
}, B = (e, t, n, r, i) => {
|
|
1409
1412
|
let a = r.sql, o = [];
|
|
1410
|
-
for (let n of Object.keys(t.fields)) o.push(a`${
|
|
1413
|
+
for (let n of Object.keys(t.fields)) o.push(a`${H(n, a)}, ${V(e, n, a)}`);
|
|
1411
1414
|
if (i !== void 0) {
|
|
1412
|
-
let e =
|
|
1413
|
-
o.push(a`${
|
|
1415
|
+
let e = Ji(i.projection, i.source, a);
|
|
1416
|
+
o.push(a`${H("_junction", a)}, JSON_OBJECT(${e})`);
|
|
1414
1417
|
}
|
|
1415
1418
|
for (let t of n) {
|
|
1416
|
-
let n =
|
|
1419
|
+
let n = ra(t, e, r);
|
|
1417
1420
|
if (n === null) return null;
|
|
1418
|
-
o.push(a`${
|
|
1421
|
+
o.push(a`${H(t.relationName, a)}, ${n}`);
|
|
1419
1422
|
}
|
|
1420
1423
|
return a`JSON_OBJECT(${a.csv(o)})`;
|
|
1421
|
-
},
|
|
1424
|
+
}, ra = (e, t, n) => {
|
|
1422
1425
|
switch (e.relation.kind) {
|
|
1423
1426
|
case "one":
|
|
1424
|
-
if (
|
|
1425
|
-
let r =
|
|
1426
|
-
return n.dialect === "mariadb" ?
|
|
1427
|
+
if (Ci(e)) {
|
|
1428
|
+
let r = wi(e);
|
|
1429
|
+
return n.dialect === "mariadb" ? sa(r, t, n) : aa(r, t, n);
|
|
1427
1430
|
}
|
|
1428
|
-
return
|
|
1429
|
-
case "many": return n.dialect === "mariadb" ?
|
|
1430
|
-
case "manyToMany": return n.dialect === "mariadb" ?
|
|
1431
|
+
return ia(e, t, n);
|
|
1432
|
+
case "many": return n.dialect === "mariadb" ? sa(e, t, n) : aa(e, t, n);
|
|
1433
|
+
case "manyToMany": return n.dialect === "mariadb" ? ca(e, t, n) : oa(e, t, n);
|
|
1431
1434
|
}
|
|
1432
|
-
},
|
|
1433
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1435
|
+
}, ia = (e, t, n) => {
|
|
1436
|
+
let r = n.sql, i = n.nextAlias(), a = B(i, e.target, e.children, n);
|
|
1434
1437
|
if (a === null) return null;
|
|
1435
|
-
let o = e.fkSide === "source" ? r`${
|
|
1438
|
+
let o = e.fkSide === "source" ? r`${V(i, "id", r)} = ${V(t, e.foreignKey, r)}` : r`${V(i, e.foreignKey, r)} = ${V(t, e.sourceKey, r)}`;
|
|
1436
1439
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
|
|
1437
|
-
},
|
|
1438
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1440
|
+
}, aa = (e, t, n) => {
|
|
1441
|
+
let r = n.sql, i = n.nextAlias(), a = B(i, e.target, e.children, n);
|
|
1439
1442
|
if (a === null) return null;
|
|
1440
|
-
let o = r`${
|
|
1443
|
+
let o = r`${V(void 0, e.foreignKey, r)} = ${V(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${R(G(e.branch.where), r)}`, c = Gi(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${U(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${U(e.branch.offset, r)}`;
|
|
1441
1444
|
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())`;
|
|
1442
|
-
},
|
|
1443
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
1445
|
+
}, oa = (e, t, n) => {
|
|
1446
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = B(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
1444
1447
|
projection: e.junction,
|
|
1445
|
-
source:
|
|
1448
|
+
source: Xi(o)
|
|
1446
1449
|
});
|
|
1447
1450
|
if (c === null) return null;
|
|
1448
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1449
|
-
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 ${
|
|
1450
|
-
},
|
|
1451
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1451
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${R(G(e.branch.where), r)}`, u = _a(e, s, r, !0), d = z(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${U(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${U(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : Yi(e.junction, s, r);
|
|
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 ${V(o, "id", r)} = ${V(s, i.targetKey, r)} WHERE ${V(s, i.sourceKey, r)} = ${V(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), JSON_ARRAY())`;
|
|
1453
|
+
}, sa = (e, t, n) => {
|
|
1454
|
+
let r = n.sql, i = n.nextAlias(), a = B(i, e.target, e.children, n);
|
|
1452
1455
|
if (a === null) return null;
|
|
1453
|
-
let o = r`${
|
|
1454
|
-
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`${
|
|
1455
|
-
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 ${
|
|
1456
|
-
return r`COALESCE((SELECT JSON_ARRAYAGG(${a} ORDER BY ${
|
|
1457
|
-
},
|
|
1456
|
+
let o = r`${V(i, e.foreignKey, r)} = ${V(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${R(G(e.branch.where), r)}`, c = e.branch.orderBy ?? [];
|
|
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`${V(i, e.column, r)} DESC` : r`${V(i, e.column, r)} ASC`))}` : r``}) FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}), JSON_ARRAY())`;
|
|
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 ${V(i, "rn", r)} > ${U(d, r)} AND ${V(i, "rn", r)} <= ${U(d + u, r)}` : u === void 0 ? r` AND ${V(i, "rn", r)} > ${U(d, r)}` : r` AND ${V(i, "rn", r)} <= ${U(u, r)}`;
|
|
1459
|
+
return r`COALESCE((SELECT JSON_ARRAYAGG(${a} ORDER BY ${V(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())`;
|
|
1460
|
+
}, ca = (e, t, n) => {
|
|
1458
1461
|
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = (t) => e.junction === void 0 ? void 0 : {
|
|
1459
1462
|
projection: e.junction,
|
|
1460
1463
|
source: t
|
|
1461
|
-
}, l = r`${
|
|
1464
|
+
}, l = r`${V(s, i.sourceKey, r)} = ${V(t, "id", r)}`, u = r`${V(o, "id", r)} = ${V(s, i.targetKey, r)}`, d = e.branch.where === void 0 ? r`` : r` AND ${R(G(e.branch.where), r)}`, f = _a(e, s, r, !0), p = e.branch.orderBy ?? [];
|
|
1462
1465
|
if (e.branch.limit === void 0 && e.branch.offset === void 0) {
|
|
1463
|
-
let t =
|
|
1464
|
-
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`${
|
|
1466
|
+
let t = B(o, e.target, e.children, n, c(Zi(s)));
|
|
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`${V(o, e.column, r)} DESC` : r`${V(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())`;
|
|
1465
1468
|
}
|
|
1466
|
-
let m = p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${
|
|
1469
|
+
let m = p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${V(o, e.column, r)} DESC` : r`${V(o, e.column, r)} ASC`))}` : r` ORDER BY ${V(o, "id", r)}`, h = e.branch.limit, g = e.branch.offset, _ = h !== void 0 && g !== void 0 ? r` AND ${V(o, "rn", r)} > ${U(g, r)} AND ${V(o, "rn", r)} <= ${U(g + h, r)}` : h === void 0 ? r` AND ${V(o, "rn", r)} > ${U(g, r)}` : r` AND ${V(o, "rn", r)} <= ${U(h, r)}`, v = e.branch.onJunction === void 0 ? r`` : r` WHERE ${W(G(e.branch.onJunction), s, r)}`, ee = B(o, e.target, e.children, n, c(Xi(o)));
|
|
1467
1470
|
if (ee === null) return null;
|
|
1468
|
-
let te = e.junction === void 0 ? r`` :
|
|
1469
|
-
return r`COALESCE((SELECT JSON_ARRAYAGG(${ee} ORDER BY ${
|
|
1470
|
-
},
|
|
1471
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1471
|
+
let te = e.junction === void 0 ? r`` : Yi(e.junction, s, r);
|
|
1472
|
+
return r`COALESCE((SELECT JSON_ARRAYAGG(${ee} ORDER BY ${V(o, "rn", r)}) FROM (SELECT ${r(o)}.*${te}, ${V(s, i.sourceKey, r)} AS ${r(`__src_${i.sourceKey}`)}, ROW_NUMBER() OVER (PARTITION BY ${V(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 ${V(o, `__src_${i.sourceKey}`, r)} = ${V(t, "id", r)}${d}${_}), JSON_ARRAY())`;
|
|
1473
|
+
}, la = (e, t, n) => {
|
|
1474
|
+
let r = n.sql, i = n.nextAlias(), a = ua(i, t.table, t.children, n);
|
|
1472
1475
|
if (a === null) return null;
|
|
1473
|
-
let o = e.predicate ? r` WHERE ${
|
|
1476
|
+
let o = e.predicate ? r` WHERE ${W(e.predicate, i, r)}` : r``, s = b(e).length > 0 ? r` ORDER BY ${r.csv(b(e).map((e) => e.direction === "desc" ? r`${V(i, e.column, r)} DESC` : r`${V(i, e.column, r)} ASC`))}` : r``, c = r``, l = r``;
|
|
1474
1477
|
if (e.skip !== void 0) {
|
|
1475
1478
|
let t = b(e).length > 0 ? s : r` ORDER BY (SELECT NULL)`;
|
|
1476
|
-
l = e.take === void 0 ? r`${t} OFFSET ${
|
|
1477
|
-
} else e.take !== void 0 && (c = r`TOP ${
|
|
1479
|
+
l = e.take === void 0 ? r`${t} OFFSET ${U(e.skip, r)} ROWS` : r`${t} OFFSET ${U(e.skip, r)} ROWS FETCH NEXT ${U(e.take, r)} ROWS ONLY`;
|
|
1480
|
+
} else e.take !== void 0 && (c = r`TOP ${U(e.take, r)} `);
|
|
1478
1481
|
let u = e.skip === void 0 ? s : r``;
|
|
1479
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}${u}${l}`;
|
|
1480
|
-
},
|
|
1483
|
+
}, ua = (e, t, n, r, i) => {
|
|
1481
1484
|
let a = r.sql, o = [];
|
|
1482
|
-
for (let n of Object.keys(t.fields)) o.push(a`${
|
|
1483
|
-
if (i !== void 0) for (let e of i.projection.present) o.push(a`${
|
|
1485
|
+
for (let n of Object.keys(t.fields)) o.push(a`${V(e, n, a)} AS ${a(n)}`);
|
|
1486
|
+
if (i !== void 0) for (let e of i.projection.present) o.push(a`${V(i.source.alias, i.source.physical(e), a)} AS ${da(`_junction.${e}`, a)}`);
|
|
1484
1487
|
for (let t of n) {
|
|
1485
|
-
let n =
|
|
1488
|
+
let n = fa(t, e, r);
|
|
1486
1489
|
if (n === null) return null;
|
|
1487
1490
|
o.push(n);
|
|
1488
1491
|
}
|
|
1489
1492
|
return a.csv(o);
|
|
1490
|
-
},
|
|
1493
|
+
}, da = (e, t) => t.unsafe(`[${e.replace(/]/g, "]]")}]`), fa = (e, t, n) => {
|
|
1491
1494
|
switch (e.relation.kind) {
|
|
1492
|
-
case "one": return
|
|
1493
|
-
case "many": return
|
|
1494
|
-
case "manyToMany": return
|
|
1495
|
+
case "one": return Ci(e) ? ha(wi(e), t, n) : pa(e, t, n);
|
|
1496
|
+
case "many": return ha(e, t, n);
|
|
1497
|
+
case "manyToMany": return ga(e, t, n);
|
|
1495
1498
|
}
|
|
1496
|
-
},
|
|
1497
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1499
|
+
}, pa = (e, t, n) => {
|
|
1500
|
+
let r = n.sql, i = n.nextAlias(), a = ua(i, e.target, e.children, n);
|
|
1498
1501
|
if (a === null) return null;
|
|
1499
|
-
let o = e.fkSide === "source" ? r`${
|
|
1502
|
+
let o = e.fkSide === "source" ? r`${V(i, "id", r)} = ${V(t, e.foreignKey, r)}` : r`${V(i, e.foreignKey, r)} = ${V(t, e.sourceKey, r)}`;
|
|
1500
1503
|
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)}`;
|
|
1501
|
-
},
|
|
1504
|
+
}, ma = (e, t, n) => {
|
|
1502
1505
|
if (e.offset !== void 0) {
|
|
1503
|
-
let r = e.orderBy && e.orderBy.length > 0 ? t : n` ORDER BY (SELECT NULL)`, i = e.limit === void 0 ? n`${r} OFFSET ${
|
|
1506
|
+
let r = e.orderBy && e.orderBy.length > 0 ? t : n` ORDER BY (SELECT NULL)`, i = e.limit === void 0 ? n`${r} OFFSET ${U(e.offset, n)} ROWS` : n`${r} OFFSET ${U(e.offset, n)} ROWS FETCH NEXT ${U(e.limit, n)} ROWS ONLY`;
|
|
1504
1507
|
return {
|
|
1505
1508
|
top: n``,
|
|
1506
1509
|
pagination: i,
|
|
@@ -1508,33 +1511,33 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
1508
1511
|
};
|
|
1509
1512
|
}
|
|
1510
1513
|
return {
|
|
1511
|
-
top: e.limit === void 0 ? n`` : n`TOP ${
|
|
1514
|
+
top: e.limit === void 0 ? n`` : n`TOP ${U(e.limit, n)} `,
|
|
1512
1515
|
pagination: n``,
|
|
1513
1516
|
finalOrder: t
|
|
1514
1517
|
};
|
|
1515
|
-
},
|
|
1516
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1518
|
+
}, ha = (e, t, n) => {
|
|
1519
|
+
let r = n.sql, i = n.nextAlias(), a = ua(i, e.target, e.children, n);
|
|
1517
1520
|
if (a === null) return null;
|
|
1518
|
-
let o = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1519
|
-
return r`ISNULL(JSON_QUERY((SELECT ${c}${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${
|
|
1520
|
-
},
|
|
1521
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
1521
|
+
let o = e.branch.where === void 0 ? r`` : r` AND ${W(e.branch.where, i, r)}`, s = z(i, e.branch.orderBy, r), { top: c, pagination: l, finalOrder: u } = ma(e.branch, s, r);
|
|
1522
|
+
return r`ISNULL(JSON_QUERY((SELECT ${c}${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${V(i, e.foreignKey, r)} = ${V(t, e.sourceKey, r)}${o}${u}${l} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
|
|
1523
|
+
}, ga = (e, t, n) => {
|
|
1524
|
+
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 : {
|
|
1522
1525
|
projection: e.junction,
|
|
1523
|
-
source:
|
|
1526
|
+
source: Zi(s)
|
|
1524
1527
|
});
|
|
1525
1528
|
if (c === null) return null;
|
|
1526
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1527
|
-
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 ${
|
|
1528
|
-
},
|
|
1529
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${W(e.branch.where, o, r)}`, u = _a(e, s, r), d = z(o, e.branch.orderBy, r), { top: f, pagination: p, finalOrder: m } = ma(e.branch, d, r);
|
|
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 ${V(o, "id", r)} = ${V(s, i.targetKey, r)} WHERE ${V(s, i.sourceKey, r)} = ${V(t, "id", r)}${u}${l}${m}${p} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
|
|
1531
|
+
}, V = (e, t, n) => e === void 0 ? n`${n(t)}` : n`${n(e)}.${n(t)}`, H = (e, t) => t.unsafe(`'${e.replace(/'/g, "''")}'`), U = (e, t) => {
|
|
1529
1532
|
if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw Error(`literalInt: expected non-negative integer, got ${e}`);
|
|
1530
1533
|
return t.unsafe(String(e));
|
|
1531
|
-
},
|
|
1534
|
+
}, W = (e, t, n) => R(va(e, t), n), _a = (e, t, n, r = !1) => {
|
|
1532
1535
|
let i = e.branch.onJunction;
|
|
1533
|
-
return i === void 0 ? n`` : n` AND ${
|
|
1534
|
-
},
|
|
1535
|
-
if ("not" in e) return { not:
|
|
1536
|
-
if ("and" in e) return { and: e.and.map((e) =>
|
|
1537
|
-
if ("or" in e) return { or: e.or.map((e) =>
|
|
1536
|
+
return i === void 0 ? n`` : n` AND ${W(r ? G(i) : i, t, n)}`;
|
|
1537
|
+
}, va = (e, t) => {
|
|
1538
|
+
if ("not" in e) return { not: va(e.not, t) };
|
|
1539
|
+
if ("and" in e) return { and: e.and.map((e) => va(e, t)) };
|
|
1540
|
+
if ("or" in e) return { or: e.or.map((e) => va(e, t)) };
|
|
1538
1541
|
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
1539
1542
|
let n = e;
|
|
1540
1543
|
return {
|
|
@@ -1548,33 +1551,51 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
1548
1551
|
...n,
|
|
1549
1552
|
column: `${t}.${n.column}`
|
|
1550
1553
|
};
|
|
1551
|
-
},
|
|
1552
|
-
if ("not" in e) return { not:
|
|
1553
|
-
if ("and" in e) return { and: e.and.map((e) =>
|
|
1554
|
-
if ("or" in e) return { or: e.or.map((e) =>
|
|
1554
|
+
}, G = (e) => {
|
|
1555
|
+
if ("not" in e) return { not: G(e.not) };
|
|
1556
|
+
if ("and" in e) return { and: e.and.map((e) => G(e)) };
|
|
1557
|
+
if ("or" in e) return { or: e.or.map((e) => G(e)) };
|
|
1555
1558
|
if (e.op === "subquery-in" || e.op === "subquery-not-in" || e.op === "exists" || e.op === "not-exists") return e;
|
|
1556
1559
|
let t = e;
|
|
1557
1560
|
return {
|
|
1558
1561
|
...t,
|
|
1559
|
-
value:
|
|
1562
|
+
value: ya(t.value)
|
|
1560
1563
|
};
|
|
1561
|
-
},
|
|
1562
|
-
e.actors !== void 0 && (
|
|
1563
|
-
},
|
|
1564
|
+
}, ya = (e) => e == null ? e : e instanceof Date ? e.toISOString() : typeof e == "boolean" ? +!!e : Array.isArray(e) ? e.map((e) => ya(e)) : e, ba = Symbol.for("@voltro/database/coreTablesRegistry"), xa = globalThis, Sa = xa[ba] ?? (xa[ba] = {}), Ca = (e) => {
|
|
1565
|
+
e.actors !== void 0 && (Sa.actors = e.actors), e.tenants !== void 0 && (Sa.tenants = e.tenants);
|
|
1566
|
+
}, wa = (e, t) => () => {
|
|
1564
1567
|
let n = e();
|
|
1565
1568
|
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`);
|
|
1566
1569
|
return n();
|
|
1567
|
-
},
|
|
1568
|
-
id:
|
|
1569
|
-
kind:
|
|
1570
|
+
}, Ta = () => wa(() => Sa.actors, "actors"), Ea = () => wa(() => Sa.tenants, "tenants"), Da = E("actors", {
|
|
1571
|
+
id: O(),
|
|
1572
|
+
kind: T().oneOf([
|
|
1570
1573
|
"user",
|
|
1571
1574
|
"serviceAccount",
|
|
1572
1575
|
"apiKey",
|
|
1573
1576
|
"system"
|
|
1574
1577
|
]),
|
|
1575
|
-
displayName:
|
|
1576
|
-
createdAt:
|
|
1577
|
-
}),
|
|
1578
|
+
displayName: T().nullable(),
|
|
1579
|
+
createdAt: D().default("now")
|
|
1580
|
+
}), Oa = (e, t) => {
|
|
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) => ({
|
|
1578
1599
|
column: e,
|
|
1579
1600
|
op: "eq",
|
|
1580
1601
|
value: t
|
|
@@ -1680,52 +1701,52 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
1680
1701
|
if (e == null || t == null) return null;
|
|
1681
1702
|
let n = e instanceof Date ? e.getTime() : e, r = t instanceof Date ? t.getTime() : t;
|
|
1682
1703
|
return typeof n == typeof r ? n === r ? 0 : n > r ? 1 : -1 : null;
|
|
1683
|
-
}, ro = (e, t, n = null) => {
|
|
1704
|
+
}, ro = (e, t, n = null, r = {}) => {
|
|
1684
1705
|
if (!t) return !1;
|
|
1685
|
-
if ("not" in e) return !ro(e.not, t, n);
|
|
1706
|
+
if ("not" in e) return !ro(e.not, t, n, r);
|
|
1686
1707
|
if ("and" in e) {
|
|
1687
|
-
for (let
|
|
1708
|
+
for (let i of e.and) if (!ro(i, t, n, r)) return !1;
|
|
1688
1709
|
return !0;
|
|
1689
1710
|
}
|
|
1690
1711
|
if ("or" in e) {
|
|
1691
|
-
for (let
|
|
1712
|
+
for (let i of e.or) if (ro(i, t, n, r)) return !0;
|
|
1692
1713
|
return !1;
|
|
1693
1714
|
}
|
|
1694
1715
|
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
1695
1716
|
if (!n) return !1;
|
|
1696
|
-
let
|
|
1697
|
-
if (!(
|
|
1698
|
-
let
|
|
1699
|
-
return e.op === "subquery-in" ?
|
|
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;
|
|
1700
1721
|
}
|
|
1701
1722
|
if (e.op === "exists" || e.op === "not-exists") {
|
|
1702
1723
|
if (!n) return !1;
|
|
1703
1724
|
let t = n.get(e.subquery), r = typeof t == "number" ? t > 0 : t instanceof Set && t.size > 0;
|
|
1704
1725
|
return e.op === "exists" ? r : !r;
|
|
1705
1726
|
}
|
|
1706
|
-
let
|
|
1707
|
-
switch (
|
|
1708
|
-
case "eq": return
|
|
1709
|
-
case "neq": return !
|
|
1710
|
-
case "gt": return (
|
|
1711
|
-
case "gte": return (
|
|
1712
|
-
case "lt": return (
|
|
1713
|
-
case "lte": return (
|
|
1714
|
-
case "in": return Array.isArray(
|
|
1715
|
-
case "notIn": return Array.isArray(
|
|
1716
|
-
case "contains": return typeof
|
|
1717
|
-
case "startsWith": return typeof
|
|
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);
|
|
1718
1739
|
case "arrayContains": {
|
|
1719
|
-
let e = Array.isArray(
|
|
1720
|
-
return (Array.isArray(
|
|
1740
|
+
let e = Array.isArray(a) ? a : [];
|
|
1741
|
+
return (Array.isArray(i.value) ? i.value : []).every((t) => e.includes(t));
|
|
1721
1742
|
}
|
|
1722
1743
|
case "arrayOverlaps": {
|
|
1723
|
-
let e = Array.isArray(
|
|
1724
|
-
return (Array.isArray(
|
|
1744
|
+
let e = Array.isArray(a) ? a : [];
|
|
1745
|
+
return (Array.isArray(i.value) ? i.value : []).some((t) => e.includes(t));
|
|
1725
1746
|
}
|
|
1726
|
-
case "arrayHas": return Array.isArray(
|
|
1727
|
-
case "isNull": return
|
|
1728
|
-
case "isNotNull": return
|
|
1747
|
+
case "arrayHas": return Array.isArray(a) && a.includes(i.value);
|
|
1748
|
+
case "isNull": return a == null;
|
|
1749
|
+
case "isNotNull": return a != null;
|
|
1729
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.");
|
|
1730
1751
|
}
|
|
1731
1752
|
}, io = function* (e) {
|
|
@@ -1802,7 +1823,7 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
1802
1823
|
},
|
|
1803
1824
|
...a
|
|
1804
1825
|
};
|
|
1805
|
-
}, fo = (e) => e == null ? "null" : e instanceof Date ? JSON.stringify(e.toISOString()) : typeof e == "bigint" ? JSON.stringify(e.toString()) : Array.isArray(e) ? `[${e.map(fo).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)}:${fo(t)}`).join(",")}}` : JSON.stringify(e) ?? "null", po = (e) =>
|
|
1826
|
+
}, fo = (e) => e == null ? "null" : e instanceof Date ? JSON.stringify(e.toISOString()) : typeof e == "bigint" ? JSON.stringify(e.toString()) : Array.isArray(e) ? `[${e.map(fo).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)}:${fo(t)}`).join(",")}}` : JSON.stringify(e) ?? "null", po = (e) => Kt("sha256").update([
|
|
1806
1827
|
e.pipe,
|
|
1807
1828
|
e.op,
|
|
1808
1829
|
e.key,
|
|
@@ -1862,7 +1883,7 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
1862
1883
|
}, _o = "VOLTRO_CHANGE_CLAIMS_TTL_HOURS", vo = 1, yo = (e = process.env) => {
|
|
1863
1884
|
let t = Number(e[_o]);
|
|
1864
1885
|
return (Number.isFinite(t) && t > 0 ? t : 1) * 2 * 36e5;
|
|
1865
|
-
}, bo = new
|
|
1886
|
+
}, bo = new qt(), xo = (e, t) => bo.run(e, t), So = () => bo.getStore(), Co = (e) => {
|
|
1866
1887
|
let t = e ?? bo.getStore();
|
|
1867
1888
|
return t === void 0 ? {} : {
|
|
1868
1889
|
...t.traceId === void 0 ? {} : { traceId: t.traceId },
|
|
@@ -1873,29 +1894,29 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
1873
1894
|
}, wo = (e) => {
|
|
1874
1895
|
let t = bo.getStore();
|
|
1875
1896
|
return t === void 0 ? e(void 0) : bo.run(t, () => e(t));
|
|
1876
|
-
}, To = 3e4, Eo = 1e4,
|
|
1877
|
-
for (let [t, n] of
|
|
1897
|
+
}, To = 3e4, Eo = 1e4, K = /* @__PURE__ */ new Map(), q = 0, Do = (e, t, n) => `${e}\u0000${t}\u0000${String(n)}`, Oo = (e) => {
|
|
1898
|
+
for (let [t, n] of K) {
|
|
1878
1899
|
let r = n.filter((t) => e - t.at < To);
|
|
1879
|
-
|
|
1900
|
+
q -= n.length - r.length, r.length === 0 ? K.delete(t) : r.length !== n.length && K.set(t, r);
|
|
1880
1901
|
}
|
|
1881
1902
|
}, ko = (e, t) => {
|
|
1882
1903
|
if (t.traceId === void 0 && t.subjectId === void 0 && t.procedure === void 0) return;
|
|
1883
1904
|
let n = Date.now();
|
|
1884
|
-
if (
|
|
1885
|
-
let r =
|
|
1886
|
-
r === void 0 ?
|
|
1905
|
+
if (q >= Eo && Oo(n), q >= Eo) return;
|
|
1906
|
+
let r = K.get(e);
|
|
1907
|
+
r === void 0 ? K.set(e, [{
|
|
1887
1908
|
attribution: t,
|
|
1888
1909
|
at: n
|
|
1889
1910
|
}]) : r.push({
|
|
1890
1911
|
attribution: t,
|
|
1891
1912
|
at: n
|
|
1892
|
-
}),
|
|
1913
|
+
}), q += 1;
|
|
1893
1914
|
}, Ao = (e) => {
|
|
1894
|
-
let t =
|
|
1915
|
+
let t = K.get(e);
|
|
1895
1916
|
if (t === void 0 || t.length === 0) return;
|
|
1896
1917
|
let n = t.shift();
|
|
1897
|
-
if (--
|
|
1898
|
-
}, jo = (e) => (
|
|
1918
|
+
if (--q, t.length === 0 && K.delete(e), !(Date.now() - n.at >= To)) return n.attribution;
|
|
1919
|
+
}, jo = (e) => (K.get(e)?.length ?? 0) > 0, J = /* @__PURE__ */ new Map(), Mo = /* @__PURE__ */ new Map(), No = /* @__PURE__ */ new Map(), Po = 250, Fo = (e) => {
|
|
1899
1920
|
let t = Mo.get(e);
|
|
1900
1921
|
if (t === void 0) return;
|
|
1901
1922
|
Mo.delete(e);
|
|
@@ -1903,14 +1924,14 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
1903
1924
|
n !== void 0 && (clearTimeout(n), No.delete(e));
|
|
1904
1925
|
for (let e of t) e();
|
|
1905
1926
|
}, Io = (e) => {
|
|
1906
|
-
|
|
1927
|
+
J.set(e, (J.get(e) ?? 0) + 1);
|
|
1907
1928
|
}, Lo = (e) => {
|
|
1908
|
-
let t = (
|
|
1929
|
+
let t = (J.get(e) ?? 0) - 1;
|
|
1909
1930
|
if (t > 0) {
|
|
1910
|
-
|
|
1931
|
+
J.set(e, t);
|
|
1911
1932
|
return;
|
|
1912
1933
|
}
|
|
1913
|
-
|
|
1934
|
+
J.delete(e), Fo(e);
|
|
1914
1935
|
}, Ro = (e, t, n, r) => {
|
|
1915
1936
|
let i = n == null ? void 0 : Do(e, t, n), a = () => r(i === void 0 ? void 0 : Ao(i));
|
|
1916
1937
|
if (i === void 0) {
|
|
@@ -1922,7 +1943,7 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
1922
1943
|
return;
|
|
1923
1944
|
}
|
|
1924
1945
|
let o = Mo.get(e);
|
|
1925
|
-
if (o === void 0 && (
|
|
1946
|
+
if (o === void 0 && (J.get(e) ?? 0) === 0) {
|
|
1926
1947
|
a();
|
|
1927
1948
|
return;
|
|
1928
1949
|
}
|
|
@@ -1934,47 +1955,47 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
1934
1955
|
let s = setTimeout(() => Fo(e), Po);
|
|
1935
1956
|
typeof s == "object" && typeof s.unref == "function" && s.unref(), No.set(e, s);
|
|
1936
1957
|
}, zo = () => {
|
|
1937
|
-
|
|
1958
|
+
K.clear(), q = 0, J.clear();
|
|
1938
1959
|
for (let e of No.values()) clearTimeout(e);
|
|
1939
1960
|
No.clear(), Mo.clear();
|
|
1940
|
-
}, Bo = () =>
|
|
1941
|
-
|
|
1961
|
+
}, Bo = () => q, Vo = 64, Ho = "\0", Uo = 32, Wo = (e, ...t) => `${e}_${Kt("sha256").update(t.map(String).join(Ho)).digest("hex").slice(0, Uo)}`, Go = (e) => e.length + 1 + Uo, Y = /* @__PURE__ */ new Map(), Ko = (e, t) => {
|
|
1962
|
+
Y.set(e, {
|
|
1942
1963
|
recorder: t.recorder,
|
|
1943
1964
|
tables: new Set(t.tables),
|
|
1944
1965
|
ownTables: new Set(t.ownTables)
|
|
1945
1966
|
});
|
|
1946
1967
|
}, qo = (e) => {
|
|
1947
|
-
|
|
1948
|
-
}, Jo = () =>
|
|
1968
|
+
Y.delete(e);
|
|
1969
|
+
}, Jo = () => Y.clear(), Yo = new qt(), Xo = (e) => Yo.run({ n: 1 }, e), Zo = (e) => A.suspend(() => {
|
|
1949
1970
|
let t = Yo.getStore();
|
|
1950
|
-
if (t !== void 0) return t.n += 1,
|
|
1971
|
+
if (t !== void 0) return t.n += 1, A.ensuring(e, A.sync(() => {
|
|
1951
1972
|
--t.n;
|
|
1952
1973
|
}));
|
|
1953
1974
|
let n = { n: 1 };
|
|
1954
|
-
return Yo.enterWith(n),
|
|
1975
|
+
return Yo.enterWith(n), A.ensuring(e, A.sync(() => {
|
|
1955
1976
|
--n.n;
|
|
1956
1977
|
}));
|
|
1957
1978
|
}), Qo = () => (Yo.getStore()?.n ?? 0) > 0, $o = (e) => {
|
|
1958
|
-
if (
|
|
1959
|
-
for (let t of
|
|
1979
|
+
if (Y.size === 0 || (Yo.getStore()?.n ?? 0) > 0) return !1;
|
|
1980
|
+
for (let t of Y.values()) if (!t.ownTables.has(e) && t.tables.has(e)) return !0;
|
|
1960
1981
|
return !1;
|
|
1961
1982
|
}, es = async (e, t) => {
|
|
1962
|
-
if (
|
|
1963
|
-
for (let [n, r] of
|
|
1983
|
+
if (Y.size !== 0) {
|
|
1984
|
+
for (let [n, r] of Y.entries()) if (!r.ownTables.has(t.table) && r.tables.has(t.table)) try {
|
|
1964
1985
|
await r.recorder(e, t);
|
|
1965
1986
|
} catch (e) {
|
|
1966
|
-
let r =
|
|
1987
|
+
let r = Nn(e);
|
|
1967
1988
|
throw r === void 0 ? e : Error(`write recorder '${n}' failed while recording a ${t.op} on '${t.table}': ${r}`, { cause: e });
|
|
1968
1989
|
}
|
|
1969
1990
|
}
|
|
1970
|
-
}, ts =
|
|
1991
|
+
}, ts = Ht.exponential({
|
|
1971
1992
|
start: 5e-4,
|
|
1972
1993
|
factor: 2,
|
|
1973
1994
|
count: 16
|
|
1974
|
-
}), ns =
|
|
1995
|
+
}), ns = j.counter("voltro_db_queries_total", { description: "Database operations executed, by dialect and operation kind." }), rs = j.histogram("voltro_db_query_duration_seconds", ts, "Database operation duration in seconds, by dialect and operation kind."), is = j.counter("voltro_db_errors_total", { description: "Database operations that threw, by dialect and operation kind." }), as = j.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." }), os = j.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." }), ss = [], cs = /* @__PURE__ */ new Map(), ls = /* @__PURE__ */ new Map(), us = /* @__PURE__ */ new Map(), ds = (e, t) => {
|
|
1975
1996
|
let n = `${e}\u0000${t}`, r = cs.get(n);
|
|
1976
1997
|
if (r !== void 0) return r;
|
|
1977
|
-
let i = (n) =>
|
|
1998
|
+
let i = (n) => j.tagged(j.tagged(n, "dialect", e), "op", t), a = {
|
|
1978
1999
|
count: i(ns),
|
|
1979
2000
|
duration: i(rs),
|
|
1980
2001
|
errors: i(is)
|
|
@@ -1986,7 +2007,7 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
1986
2007
|
let n = Math.max(0, (ms.get(e) ?? 0) + t);
|
|
1987
2008
|
n === 0 ? ms.delete(e) : ms.set(e, n);
|
|
1988
2009
|
let r = ls.get(e);
|
|
1989
|
-
r === void 0 && (r =
|
|
2010
|
+
r === void 0 && (r = j.tagged(as, "dialect", e), ls.set(e, r)), r.unsafeUpdate(n, ss);
|
|
1990
2011
|
}, gs = (e) => ms.get(e) ?? 0, _s = (e) => {
|
|
1991
2012
|
let t = ds(String(e.dialect), e.op);
|
|
1992
2013
|
t.count.unsafeUpdate(1, ss), t.duration.unsafeUpdate(e.durationMs / 1e3, ss), e.status === "error" && t.errors.unsafeUpdate(1, ss);
|
|
@@ -2014,7 +2035,7 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
2014
2035
|
let n = xs(t.warnIntervalMs), r = t.now ?? (() => Date.now()), i = /* @__PURE__ */ new Map();
|
|
2015
2036
|
return (t) => {
|
|
2016
2037
|
let a = `${t.dialect} ${t.reason}`, o = us.get(a);
|
|
2017
|
-
o === void 0 && (o =
|
|
2038
|
+
o === void 0 && (o = j.tagged(j.tagged(os, "dialect", String(t.dialect)), "reason", t.reason), us.set(a, o)), o.unsafeUpdate(1, ss);
|
|
2018
2039
|
let s = `${t.table}\u0000${t.reason}`, c = i.get(s), l = c === void 0 || n > 0 && r() - c >= n, u = {
|
|
2019
2040
|
table: t.table,
|
|
2020
2041
|
dialect: String(t.dialect),
|
|
@@ -2029,23 +2050,23 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
2029
2050
|
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);
|
|
2030
2051
|
};
|
|
2031
2052
|
}, Cs = (e) => {
|
|
2032
|
-
if (
|
|
2033
|
-
throw
|
|
2034
|
-
}, ws = "10 millis", Ts = 3, Es = async (e) => {
|
|
2035
|
-
let t = 0, n =
|
|
2053
|
+
if (Vt.isSuccess(e)) return e.value;
|
|
2054
|
+
throw Rt.squash(e.cause);
|
|
2055
|
+
}, ws = "10 millis", Ts = 3, Es = (e) => Wt.exponential(ws).pipe(Wt.compose(Wt.recurs(Ts)), Wt.whileInput(e)), Ds = async (e) => {
|
|
2056
|
+
let t = 0, n = A.suspend(() => {
|
|
2036
2057
|
let n = ++t;
|
|
2037
|
-
return e.withTransaction(
|
|
2038
|
-
if (
|
|
2039
|
-
let r = t.value, i =
|
|
2058
|
+
return e.withTransaction(A.flatMap(A.serviceOption(Jt), (t) => {
|
|
2059
|
+
if (M.isNone(t)) return A.fail(/* @__PURE__ */ Error(`${e.label}: TransactionConnection unexpectedly missing inside withTransaction.`));
|
|
2060
|
+
let r = t.value, i = A.tryPromise({
|
|
2040
2061
|
try: () => e.body(r, n),
|
|
2041
2062
|
catch: (e) => e
|
|
2042
2063
|
});
|
|
2043
|
-
return e.prepare === void 0 ? i :
|
|
2044
|
-
})).pipe(
|
|
2045
|
-
})
|
|
2046
|
-
return vs(e.dialect, "transaction", async () => Cs(await e.runPromiseExit(e.wrapProgram === void 0 ?
|
|
2047
|
-
},
|
|
2048
|
-
let t = So(), n = t === void 0 ? (e) => e() : (e) => xo(t, e), r = await
|
|
2064
|
+
return e.prepare === void 0 ? i : A.flatMap(e.prepare(r), () => i);
|
|
2065
|
+
})).pipe(A.catchAllDefect((t) => e.isRetryable(t) ? A.fail(t) : A.die(t)));
|
|
2066
|
+
}).pipe(A.retry(Es(e.isRetryable)), A.withSpan(e.span.name, { attributes: { ...e.span.attributes } }));
|
|
2067
|
+
return vs(e.dialect, "transaction", async () => Cs(await e.runPromiseExit(e.wrapProgram === void 0 ? n : e.wrapProgram(n))));
|
|
2068
|
+
}, Os = async (e) => {
|
|
2069
|
+
let t = So(), n = t === void 0 ? (e) => e() : (e) => xo(t, e), r = await Ds({
|
|
2049
2070
|
...e,
|
|
2050
2071
|
body: (r) => {
|
|
2051
2072
|
let i = e.makeView(r, t);
|
|
@@ -2056,48 +2077,48 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
2056
2077
|
}
|
|
2057
2078
|
});
|
|
2058
2079
|
return r.view.commitEvents(), r.result;
|
|
2059
|
-
},
|
|
2080
|
+
}, ks = /* @__PURE__ */ new Set([
|
|
2060
2081
|
"1213",
|
|
2061
2082
|
"ER_LOCK_DEADLOCK",
|
|
2062
2083
|
"1205",
|
|
2063
2084
|
"ER_LOCK_WAIT_TIMEOUT",
|
|
2064
2085
|
"1020",
|
|
2065
2086
|
"ER_CHECKREAD"
|
|
2066
|
-
]),
|
|
2087
|
+
]), As = /* @__PURE__ */ new Set(["40001", "40P01"]), js = /* @__PURE__ */ new Set(["1205"]), Ms = /* @__PURE__ */ new Set([
|
|
2067
2088
|
"SQLITE_BUSY",
|
|
2068
2089
|
"5",
|
|
2069
2090
|
"SQLITE_LOCKED",
|
|
2070
2091
|
"6"
|
|
2071
|
-
]),
|
|
2092
|
+
]), Ns = /write-write conflict|write-read conflict|database is locked|table is locked|database is busy/i, Ps = /* @__PURE__ */ new Set([
|
|
2072
2093
|
1213,
|
|
2073
2094
|
1205,
|
|
2074
2095
|
1020
|
|
2075
|
-
]),
|
|
2076
|
-
...Os,
|
|
2096
|
+
]), Fs = /* @__PURE__ */ new Set([
|
|
2077
2097
|
...ks,
|
|
2078
2098
|
...As,
|
|
2079
|
-
...js
|
|
2080
|
-
|
|
2099
|
+
...js,
|
|
2100
|
+
...Ms
|
|
2101
|
+
]), Is = (e) => bn(e).some(Ls), Ls = (e) => {
|
|
2081
2102
|
let t = e;
|
|
2082
2103
|
for (let e = 0; e < 6 && typeof t == "object" && t; e++) {
|
|
2083
2104
|
let e = t;
|
|
2084
|
-
if (typeof e.errno == "number" &&
|
|
2105
|
+
if (typeof e.errno == "number" && Ps.has(e.errno) || typeof e.number == "number" && js.has(String(e.number)) || typeof e.code == "string" && Fs.has(e.code) || typeof e.sqlState == "string" && As.has(e.sqlState) || typeof e.message == "string" && Ns.test(e.message)) return !0;
|
|
2085
2106
|
t = e.cause;
|
|
2086
2107
|
}
|
|
2087
2108
|
return !1;
|
|
2088
|
-
},
|
|
2089
|
-
id:
|
|
2090
|
-
fields: { expiresAt:
|
|
2109
|
+
}, Rs = "voltro/expires", zs = () => xt({
|
|
2110
|
+
id: Rs,
|
|
2111
|
+
fields: { expiresAt: D().nullable() },
|
|
2091
2112
|
behaviors: { defaultWhere: () => "expiresAt IS NULL OR expiresAt > now()" }
|
|
2092
|
-
}),
|
|
2093
|
-
id:
|
|
2113
|
+
}), Bs = "voltro/localFirst", Vs = () => xt({
|
|
2114
|
+
id: Bs,
|
|
2094
2115
|
fields: {}
|
|
2095
|
-
}),
|
|
2116
|
+
}), Hs = (e) => e.appliedMixins.some((e) => e.id === Bs), Us = (e) => {
|
|
2096
2117
|
let t = [];
|
|
2097
|
-
for (let n of Object.values(e))
|
|
2118
|
+
for (let n of Object.values(e)) Hs(n) && t.push(n.tableName);
|
|
2098
2119
|
return t;
|
|
2099
|
-
},
|
|
2100
|
-
let i =
|
|
2120
|
+
}, Ws = class extends Bt.TaggedError("TableStreamError") {}, Gs = 1e3, Ks = (e, t, n, r) => {
|
|
2121
|
+
let i = M.match(r, {
|
|
2101
2122
|
onNone: () => e.where,
|
|
2102
2123
|
onSome: (n) => e.where ? Ka(e.where, ja(t, n)) : ja(t, n)
|
|
2103
2124
|
});
|
|
@@ -2114,19 +2135,19 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
2114
2135
|
...e.includeDeleted === void 0 ? {} : { includeDeleted: e.includeDeleted },
|
|
2115
2136
|
...e.crossTenant === void 0 ? {} : { crossTenant: e.crossTenant }
|
|
2116
2137
|
};
|
|
2117
|
-
},
|
|
2118
|
-
let n = t.pk ?? "id", r = t.chunkSize ??
|
|
2119
|
-
return
|
|
2120
|
-
let a =
|
|
2121
|
-
try: () => e.query(
|
|
2122
|
-
catch: (e) => new
|
|
2138
|
+
}, qs = (e, t) => {
|
|
2139
|
+
let n = t.pk ?? "id", r = t.chunkSize ?? Gs;
|
|
2140
|
+
return Gt.paginateChunkEffect(M.none(), (i) => {
|
|
2141
|
+
let a = A.tryPromise({
|
|
2142
|
+
try: () => e.query(Ks(t, n, r, i)),
|
|
2143
|
+
catch: (e) => new Ws({
|
|
2123
2144
|
table: t.table,
|
|
2124
2145
|
cause: e
|
|
2125
2146
|
})
|
|
2126
2147
|
});
|
|
2127
|
-
return (t.retry ? a.pipe(
|
|
2148
|
+
return (t.retry ? a.pipe(A.retry(t.retry)) : a).pipe(A.map((e) => [zt.fromIterable(e), e.length === r && e.length > 0 ? M.some(M.some(e[e.length - 1][n])) : M.none()]));
|
|
2128
2149
|
});
|
|
2129
|
-
},
|
|
2150
|
+
}, Js = (e) => {
|
|
2130
2151
|
let t = e.alpha ?? .5;
|
|
2131
2152
|
if (t < 0 || t > 1) throw Error(`hybridSearch: alpha must be in [0, 1], got ${t}`);
|
|
2132
2153
|
return (n) => {
|
|
@@ -2153,17 +2174,17 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
2153
2174
|
}
|
|
2154
2175
|
};
|
|
2155
2176
|
};
|
|
2156
|
-
},
|
|
2177
|
+
}, Ys = async (e, t) => {
|
|
2157
2178
|
let n = e.as ?? "embedding", r = t.row[e.from];
|
|
2158
2179
|
if (typeof r != "string" || r.length === 0) return {};
|
|
2159
2180
|
let i = await t.embed(r);
|
|
2160
2181
|
return { [n]: i };
|
|
2161
|
-
},
|
|
2182
|
+
}, Xs = (e) => {
|
|
2162
2183
|
if (!Number.isInteger(e.dimensions) || e.dimensions <= 0) throw Error(`vectorEmbedding: dimensions must be a positive integer, got ${String(e.dimensions)}.`);
|
|
2163
|
-
let t = e.as ?? "embedding", n = (t) =>
|
|
2164
|
-
return
|
|
2184
|
+
let t = e.as ?? "embedding", n = (t) => Ys(e, t);
|
|
2185
|
+
return xt({
|
|
2165
2186
|
id: "voltro/vectorEmbedding",
|
|
2166
|
-
fields: { [t]:
|
|
2187
|
+
fields: { [t]: ht(e.dimensions) },
|
|
2167
2188
|
...e.index === !1 ? {} : { indexes: [{
|
|
2168
2189
|
fields: [t],
|
|
2169
2190
|
kind: "hnsw",
|
|
@@ -2178,19 +2199,19 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
2178
2199
|
beforeUpdate: n
|
|
2179
2200
|
}
|
|
2180
2201
|
});
|
|
2181
|
-
},
|
|
2202
|
+
}, Zs = 63, Qs = "br_pr", X = class extends Error {
|
|
2182
2203
|
_tag = "BranchNameInvalid";
|
|
2183
2204
|
constructor(e) {
|
|
2184
2205
|
super(e), this.name = "BranchNameInvalid";
|
|
2185
2206
|
}
|
|
2186
|
-
},
|
|
2187
|
-
if (!Number.isInteger(t) || t < 0) throw new
|
|
2188
|
-
let n =
|
|
2189
|
-
if (n.replace(/_/g, "") === "") throw new
|
|
2190
|
-
let r = `${
|
|
2191
|
-
if (r.length >
|
|
2207
|
+
}, $s = (e, t) => {
|
|
2208
|
+
if (!Number.isInteger(t) || t < 0) throw new X(`prNumber must be a non-negative integer, got ${String(t)}`);
|
|
2209
|
+
let n = ni(e);
|
|
2210
|
+
if (n.replace(/_/g, "") === "") throw new X(`app slug '${e}' has no usable identifier characters`);
|
|
2211
|
+
let r = `${Qs}${t}_${n}`;
|
|
2212
|
+
if (r.length > Zs) throw new X(`branch namespace '${r}' exceeds the ${Zs}-byte identifier limit — use a shorter app slug`);
|
|
2192
2213
|
return r;
|
|
2193
|
-
},
|
|
2214
|
+
}, ec = (e) => e.startsWith(Qs), tc = {
|
|
2194
2215
|
requested: {
|
|
2195
2216
|
provision: "provisioning",
|
|
2196
2217
|
destroy: "destroying"
|
|
@@ -2209,19 +2230,19 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
2209
2230
|
fail: "failed"
|
|
2210
2231
|
},
|
|
2211
2232
|
destroyed: {}
|
|
2212
|
-
},
|
|
2233
|
+
}, nc = class extends Error {
|
|
2213
2234
|
from;
|
|
2214
2235
|
event;
|
|
2215
2236
|
_tag = "BranchTransitionInvalid";
|
|
2216
2237
|
constructor(e, t) {
|
|
2217
2238
|
super(`invalid branch transition: ${e} --${t}-->`), this.from = e, this.event = t, this.name = "BranchTransitionInvalid";
|
|
2218
2239
|
}
|
|
2219
|
-
},
|
|
2220
|
-
let n =
|
|
2221
|
-
if (n === void 0) throw new
|
|
2240
|
+
}, rc = (e, t) => {
|
|
2241
|
+
let n = tc[e][t];
|
|
2242
|
+
if (n === void 0) throw new nc(e, t);
|
|
2222
2243
|
return n;
|
|
2223
|
-
},
|
|
2224
|
-
if (n === "copy" && (r === void 0 || r === "")) throw new
|
|
2244
|
+
}, ic = (e, t, n, r, i = [], a = []) => {
|
|
2245
|
+
if (n === "copy" && (r === void 0 || r === "")) throw new X("seed 'copy' requires a parentNamespace to snapshot from");
|
|
2225
2246
|
let o = [{
|
|
2226
2247
|
kind: "create-namespace",
|
|
2227
2248
|
detail: e
|
|
@@ -2250,13 +2271,13 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
2250
2271
|
kind: "seed",
|
|
2251
2272
|
detail: `run boot seeds into ${e}`
|
|
2252
2273
|
}), o;
|
|
2253
|
-
},
|
|
2254
|
-
if (
|
|
2274
|
+
}, ac = (e) => {
|
|
2275
|
+
if (!ec(e)) throw new X(`refusing to plan teardown of '${e}' — not a branch namespace`);
|
|
2255
2276
|
return [{
|
|
2256
2277
|
kind: "drop-namespace",
|
|
2257
2278
|
detail: e
|
|
2258
2279
|
}];
|
|
2259
|
-
},
|
|
2280
|
+
}, oc = (e) => {
|
|
2260
2281
|
if (e === void 0 || e === "") return !1;
|
|
2261
2282
|
try {
|
|
2262
2283
|
let t = new URL(e).hostname.toLowerCase();
|
|
@@ -2264,27 +2285,27 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
2264
2285
|
} catch {
|
|
2265
2286
|
return /\bneon\.(tech|build)\b/i.test(e);
|
|
2266
2287
|
}
|
|
2267
|
-
},
|
|
2288
|
+
}, sc = (e) => e.prefer === void 0 ? e.seed === "copy" && oc(e.dbUrl) ? "neon-cow" : "namespace" : e.prefer, cc = (e, t = {}) => [{
|
|
2268
2289
|
kind: "neon-branch-create",
|
|
2269
2290
|
detail: `${t.parentBranch ?? "main"} → ${e} (copy-on-write)`
|
|
2270
|
-
}],
|
|
2271
|
-
if (
|
|
2291
|
+
}], lc = (e) => {
|
|
2292
|
+
if (!ec(e)) throw new X(`refusing to plan teardown of '${e}' — not a branch namespace`);
|
|
2272
2293
|
return [{
|
|
2273
2294
|
kind: "neon-branch-delete",
|
|
2274
2295
|
detail: e
|
|
2275
2296
|
}];
|
|
2276
|
-
},
|
|
2297
|
+
}, uc = (e) => e.mechanism === "neon-cow" ? cc(e.branchId, e.neonParentBranch === void 0 ? {} : { parentBranch: e.neonParentBranch }) : ic(e.branchId, e.tableNames, e.seed, e.parentNamespace, e.foreignKeys, e.indexNames), dc = (e, t) => e === "neon-cow" ? lc(t) : ac(t), fc = (e, t, n) => {
|
|
2277
2298
|
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);
|
|
2278
2299
|
return {
|
|
2279
2300
|
evict: i,
|
|
2280
2301
|
rejectNew: r.filter((e) => !a.has(e.namespace)).length >= t.maxBranches
|
|
2281
2302
|
};
|
|
2282
|
-
},
|
|
2283
|
-
let n =
|
|
2303
|
+
}, pc = async (e, t) => {
|
|
2304
|
+
let n = $s(e.appSlug, e.prNumber), r = sc({
|
|
2284
2305
|
seed: e.seed,
|
|
2285
2306
|
...e.dbUrl === void 0 ? {} : { dbUrl: e.dbUrl },
|
|
2286
2307
|
...e.prefer === void 0 ? {} : { prefer: e.prefer }
|
|
2287
|
-
}), i =
|
|
2308
|
+
}), i = uc({
|
|
2288
2309
|
mechanism: r,
|
|
2289
2310
|
branchId: n,
|
|
2290
2311
|
tableNames: e.tableNames,
|
|
@@ -2313,16 +2334,16 @@ var Zt = (e) => typeof e == "string" && e !== "" ? e : null, Qt = async (e, t, n
|
|
|
2313
2334
|
mechanism: r,
|
|
2314
2335
|
steps: i
|
|
2315
2336
|
};
|
|
2316
|
-
},
|
|
2317
|
-
let r =
|
|
2337
|
+
}, mc = async (e, t, n) => {
|
|
2338
|
+
let r = dc(t, e);
|
|
2318
2339
|
return t === "neon-cow" ? await n.neonBranchDelete(e) : await n.dropNamespace(e), r;
|
|
2319
|
-
},
|
|
2340
|
+
}, hc = (e, t, n) => fc(e, t, n), Z = (e) => `"${e.replace(/"/g, "\"\"")}"`, gc = {
|
|
2320
2341
|
cascade: "CASCADE",
|
|
2321
2342
|
restrict: "RESTRICT",
|
|
2322
2343
|
setNull: "SET NULL",
|
|
2323
2344
|
noAction: "NO ACTION"
|
|
2324
|
-
},
|
|
2325
|
-
let n = t.columns.map(
|
|
2345
|
+
}, _c = (e) => `'${e.replace(/'/g, "''")}'`, vc = (e, t) => {
|
|
2346
|
+
let n = t.columns.map(_c).join(", ");
|
|
2326
2347
|
return `DO $voltro_branch$
|
|
2327
2348
|
DECLARE derived name;
|
|
2328
2349
|
BEGIN
|
|
@@ -2331,11 +2352,11 @@ BEGIN
|
|
|
2331
2352
|
JOIN pg_class i ON i.oid = x.indexrelid
|
|
2332
2353
|
JOIN pg_class c ON c.oid = x.indrelid
|
|
2333
2354
|
JOIN pg_namespace nsp ON nsp.oid = c.relnamespace
|
|
2334
|
-
WHERE nsp.nspname = ${
|
|
2335
|
-
AND c.relname = ${
|
|
2355
|
+
WHERE nsp.nspname = ${_c(e)}
|
|
2356
|
+
AND c.relname = ${_c(t.table)}
|
|
2336
2357
|
AND NOT x.indisprimary
|
|
2337
2358
|
AND x.indisunique = ${t.unique ? "true" : "false"}
|
|
2338
|
-
AND i.relname <> ${
|
|
2359
|
+
AND i.relname <> ${_c(t.name)}
|
|
2339
2360
|
AND (
|
|
2340
2361
|
SELECT array_agg(att.attname::text ORDER BY k.ord)
|
|
2341
2362
|
FROM unnest(x.indkey::int2[]) WITH ORDINALITY AS k(attnum, ord)
|
|
@@ -2344,39 +2365,39 @@ BEGIN
|
|
|
2344
2365
|
LIMIT 1;
|
|
2345
2366
|
IF derived IS NOT NULL THEN
|
|
2346
2367
|
EXECUTE format('ALTER INDEX %I.%I RENAME TO %I',
|
|
2347
|
-
${
|
|
2368
|
+
${_c(e)}, derived, ${_c(t.name)});
|
|
2348
2369
|
END IF;
|
|
2349
2370
|
END
|
|
2350
2371
|
$voltro_branch$`;
|
|
2351
|
-
},
|
|
2352
|
-
let n = t.onDelete === void 0 ? "" : ` ON DELETE ${
|
|
2353
|
-
return `ALTER TABLE ${
|
|
2354
|
-
},
|
|
2372
|
+
}, yc = (e, t) => {
|
|
2373
|
+
let n = t.onDelete === void 0 ? "" : ` ON DELETE ${gc[t.onDelete]}`, r = t.onUpdate === void 0 ? "" : ` ON UPDATE ${gc[t.onUpdate]}`;
|
|
2374
|
+
return `ALTER TABLE ${Z(e)}.${Z(t.table)} ADD FOREIGN KEY (${Z(t.column)}) REFERENCES ${Z(e)}.${Z(t.targetTable)} (${Z(t.targetColumn)})${n}${r}`;
|
|
2375
|
+
}, bc = (e) => {
|
|
2355
2376
|
let t = () => {
|
|
2356
2377
|
throw Error("namespace branch executor: Neon ops require a neon-cow executor (use a Neon connection for copy-on-write branches)");
|
|
2357
2378
|
};
|
|
2358
2379
|
return {
|
|
2359
|
-
createNamespace: (t) => e.run(`CREATE SCHEMA IF NOT EXISTS ${
|
|
2360
|
-
createTable: (t, n) => e.run(`CREATE TABLE IF NOT EXISTS ${
|
|
2361
|
-
copyTable: (t, n, r) => e.run(`INSERT INTO ${
|
|
2362
|
-
addForeignKey: (t, n) => e.run(
|
|
2363
|
-
restoreIndexName: (t, n) => e.run(
|
|
2364
|
-
dropNamespace: (t) => e.run(`DROP SCHEMA IF EXISTS ${
|
|
2380
|
+
createNamespace: (t) => e.run(`CREATE SCHEMA IF NOT EXISTS ${Z(t)}`),
|
|
2381
|
+
createTable: (t, n) => e.run(`CREATE TABLE IF NOT EXISTS ${Z(t)}.${Z(n)} (LIKE ${Z(n)} INCLUDING ALL)`),
|
|
2382
|
+
copyTable: (t, n, r) => e.run(`INSERT INTO ${Z(n)}.${Z(r)} SELECT * FROM ${Z(t)}.${Z(r)}`),
|
|
2383
|
+
addForeignKey: (t, n) => e.run(yc(t, n)),
|
|
2384
|
+
restoreIndexName: (t, n) => e.run(vc(t, n)),
|
|
2385
|
+
dropNamespace: (t) => e.run(`DROP SCHEMA IF EXISTS ${Z(t)} CASCADE`),
|
|
2365
2386
|
neonBranchCreate: t,
|
|
2366
2387
|
neonBranchDelete: t
|
|
2367
2388
|
};
|
|
2368
|
-
},
|
|
2389
|
+
}, xc = class extends Error {
|
|
2369
2390
|
_tag = "TenantResidencyUnresolved";
|
|
2370
2391
|
constructor(e) {
|
|
2371
2392
|
super(e), this.name = "TenantResidencyUnresolved";
|
|
2372
2393
|
}
|
|
2373
|
-
},
|
|
2394
|
+
}, Sc = class extends Error {
|
|
2374
2395
|
region;
|
|
2375
2396
|
_tag = "TenantRegionUnavailable";
|
|
2376
2397
|
constructor(e, t) {
|
|
2377
2398
|
super(t), this.region = e, this.name = "TenantRegionUnavailable";
|
|
2378
2399
|
}
|
|
2379
|
-
},
|
|
2400
|
+
}, Cc, wc = (e) => {
|
|
2380
2401
|
if (e.homes === void 0) throw Error("setResidencyConfig: `homes` is required");
|
|
2381
2402
|
if (e.servableRegions === void 0 || e.servableRegions.length === 0) throw Error("setResidencyConfig: `servableRegions` must be non-empty (which regions this deployment serves)");
|
|
2382
2403
|
let t = /* @__PURE__ */ new Map();
|
|
@@ -2385,55 +2406,55 @@ $voltro_branch$`;
|
|
|
2385
2406
|
if (e !== void 0 && e !== n.region) throw Error(`residency: tenant '${n.tenantId}' is mapped to two regions ('${e}' and '${n.region}')`);
|
|
2386
2407
|
t.set(n.tenantId, n.region);
|
|
2387
2408
|
}
|
|
2388
|
-
return
|
|
2389
|
-
},
|
|
2390
|
-
|
|
2391
|
-
},
|
|
2392
|
-
if (e == null || e === "") throw new
|
|
2409
|
+
return Cc = e, e;
|
|
2410
|
+
}, Tc = () => Cc, Ec = () => {
|
|
2411
|
+
Cc = void 0;
|
|
2412
|
+
}, Dc = (e, t) => {
|
|
2413
|
+
if (e == null || e === "") throw new xc("residency is on but the request has no resolvable tenant — refusing to bind a store");
|
|
2393
2414
|
let n = t.homes.find((t) => t.tenantId === e);
|
|
2394
|
-
if (n === void 0) throw new
|
|
2415
|
+
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)`);
|
|
2395
2416
|
return n;
|
|
2396
|
-
},
|
|
2397
|
-
let n =
|
|
2417
|
+
}, Oc = (e, t) => t.servableRegions.includes(e), kc = (e, t) => {
|
|
2418
|
+
let n = Dc(e.tenantId, t), r = ri(n.tenantId);
|
|
2398
2419
|
return {
|
|
2399
2420
|
region: n.region,
|
|
2400
2421
|
namespace: r,
|
|
2401
2422
|
...n.connectionKey === void 0 ? {} : { connectionKey: n.connectionKey }
|
|
2402
2423
|
};
|
|
2403
|
-
},
|
|
2404
|
-
let r =
|
|
2405
|
-
if (!
|
|
2424
|
+
}, Ac = (e, t, n) => {
|
|
2425
|
+
let r = kc(e, t);
|
|
2426
|
+
if (!Oc(r.region, t)) throw new Sc(r.region, `tenant homed in region '${r.region}', which this deployment does not serve — route to the home region`);
|
|
2406
2427
|
let i = n.get(r.region);
|
|
2407
|
-
if (i === void 0) throw new
|
|
2428
|
+
if (i === void 0) throw new Sc(r.region, `no store handle for home region '${r.region}' (declared servable but not wired) — failing closed`);
|
|
2408
2429
|
return {
|
|
2409
2430
|
store: i,
|
|
2410
2431
|
placement: r
|
|
2411
2432
|
};
|
|
2412
|
-
},
|
|
2413
|
-
let { store: i, placement: a } =
|
|
2433
|
+
}, jc = async (e, t, n, r) => {
|
|
2434
|
+
let { store: i, placement: a } = Ac(e, t, n);
|
|
2414
2435
|
return await r(i, a), a;
|
|
2415
|
-
},
|
|
2436
|
+
}, Mc = (e) => {
|
|
2416
2437
|
if (typeof e == "string") return e;
|
|
2417
2438
|
if ("jsonPath" in e) {
|
|
2418
2439
|
let { column: t, path: n, numeric: r } = e.jsonPath;
|
|
2419
2440
|
return `(json:${t}->${n.join(".")}${r ? "::num" : ""})`;
|
|
2420
2441
|
}
|
|
2421
2442
|
return `(${e.expr})`;
|
|
2422
|
-
}, Q = (e) => e.map(
|
|
2443
|
+
}, Q = (e) => e.map(Mc), Nc = (e, t) => {
|
|
2423
2444
|
if (e.length !== t.length) return !1;
|
|
2424
|
-
for (let n = 0; n < e.length; n++) if (
|
|
2445
|
+
for (let n = 0; n < e.length; n++) if (Mc(e[n]) !== Mc(t[n])) return !1;
|
|
2425
2446
|
return !0;
|
|
2426
|
-
},
|
|
2447
|
+
}, Pc = (e, t) => {
|
|
2427
2448
|
if (e.length >= t.length) return !1;
|
|
2428
|
-
for (let n = 0; n < e.length; n++) if (
|
|
2449
|
+
for (let n = 0; n < e.length; n++) if (Mc(e[n]) !== Mc(t[n])) return !1;
|
|
2429
2450
|
return !0;
|
|
2430
|
-
},
|
|
2451
|
+
}, Fc = (e) => {
|
|
2431
2452
|
let t = [], n = e.appliedIndexes, r = e.tableName;
|
|
2432
2453
|
for (let e = 0; e < n.length; e++) {
|
|
2433
2454
|
let i = n[e];
|
|
2434
2455
|
for (let a = e + 1; a < n.length; a++) {
|
|
2435
2456
|
let e = n[a];
|
|
2436
|
-
if (
|
|
2457
|
+
if (Nc(i.fields, e.fields)) {
|
|
2437
2458
|
let [n, a] = i.name < e.name ? [i, e] : [e, i];
|
|
2438
2459
|
t.push({
|
|
2439
2460
|
kind: "duplicate-fields",
|
|
@@ -2444,13 +2465,13 @@ $voltro_branch$`;
|
|
|
2444
2465
|
});
|
|
2445
2466
|
continue;
|
|
2446
2467
|
}
|
|
2447
|
-
|
|
2468
|
+
Pc(i.fields, e.fields) ? t.push({
|
|
2448
2469
|
kind: "redundant-prefix",
|
|
2449
2470
|
table: r,
|
|
2450
2471
|
redundant: i,
|
|
2451
2472
|
coveredBy: e,
|
|
2452
2473
|
message: `'${r}' index '${i.name}' on [${Q(i.fields).join(", ")}] is a leading prefix of '${e.name}' on [${Q(e.fields).join(", ")}]. Every B-tree dialect we support (Postgres / MySQL / MariaDB / MSSQL / SQLite) can serve a [${Q(i.fields).join(", ")}] query from '${e.name}' too via the leading-prefix rule, so '${i.name}' adds write cost without read benefit. Drop '${i.name}' — unless you specifically need a smaller index for cache locality on a write-heavy table (rare; profile first).`
|
|
2453
|
-
}) :
|
|
2474
|
+
}) : Pc(e.fields, i.fields) && t.push({
|
|
2454
2475
|
kind: "redundant-prefix",
|
|
2455
2476
|
table: r,
|
|
2456
2477
|
redundant: e,
|
|
@@ -2460,23 +2481,23 @@ $voltro_branch$`;
|
|
|
2460
2481
|
}
|
|
2461
2482
|
}
|
|
2462
2483
|
return t;
|
|
2463
|
-
},
|
|
2484
|
+
}, Ic = (e) => {
|
|
2464
2485
|
let t = [];
|
|
2465
|
-
for (let n of e) t.push(...
|
|
2486
|
+
for (let n of e) t.push(...Fc(n));
|
|
2466
2487
|
return t;
|
|
2467
|
-
},
|
|
2468
|
-
let n = t.color ?? !0, r = t.indent ?? " ", i = (e) => $(n,
|
|
2488
|
+
}, Lc = "\x1B[", Rc = `${Lc}38;2;245;158;11m`, zc = `${Lc}38;2;16;185;129m`, Bc = (e, t) => `${e}${t}${P.reset}`, $ = (e, t, n) => e ? typeof t == "function" ? t(n) : Bc(t, n) : n, Vc = (e, t = {}) => {
|
|
2489
|
+
let n = t.color ?? !0, r = t.indent ?? " ", i = (e) => $(n, P.dim, e.padEnd(11)), a = (e) => $(n, (e) => P.bold(P.brand(e)), e), o = (e) => $(n, P.brightRed24, e), s = (e) => $(n, zc, e), c = (e) => $(n, Rc, e), l = (e) => $(n, P.dim, e), u = `${c("index audit")} ${l("·")} ${$(n, P.bold, e.kind)}`, d = e.redundant.fields.length, f = Q(e.coveredBy.fields.slice(d)), p = (e, t) => {
|
|
2469
2490
|
let n = e.slice(0, t), r = e.slice(t), i = [];
|
|
2470
2491
|
return n.length > 0 && i.push(s(`[${n.join(", ")}]`)), r.length > 0 && i.push(c(`+ [${r.join(", ")}]`)), i.join(" ");
|
|
2471
2492
|
}, m = [];
|
|
2472
|
-
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,
|
|
2473
|
-
},
|
|
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, P.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
|
+
}, Hc = (e, { apply: t, undo: n }) => ({
|
|
2474
2495
|
name: e,
|
|
2475
2496
|
apply: t,
|
|
2476
2497
|
undo: n
|
|
2477
|
-
}),
|
|
2498
|
+
}), Uc = (e) => {
|
|
2478
2499
|
if (!/^\d{14}_/.test(e.id)) throw Error(`migration "${e.id}": id must start with a 14-digit timestamp followed by "_" (convention: <YYYYMMDDHHMMSS>_<slug>)`);
|
|
2479
|
-
let t = e.steps({ step:
|
|
2500
|
+
let t = e.steps({ step: Hc });
|
|
2480
2501
|
if (t.length === 0) throw Error(`migration "${e.id}": at least one step is required`);
|
|
2481
2502
|
return {
|
|
2482
2503
|
__migration: !0,
|
|
@@ -2484,106 +2505,106 @@ $voltro_branch$`;
|
|
|
2484
2505
|
name: e.name,
|
|
2485
2506
|
steps: t
|
|
2486
2507
|
};
|
|
2487
|
-
},
|
|
2488
|
-
id:
|
|
2489
|
-
name:
|
|
2490
|
-
hash:
|
|
2491
|
-
status:
|
|
2492
|
-
appliedAt:
|
|
2508
|
+
}, Wc = (e) => typeof e == "object" && !!e && "__migration" in e && e.__migration === !0, Gc = E("_voltro_migrations", {
|
|
2509
|
+
id: O({ prefix: "mig" }),
|
|
2510
|
+
name: T(),
|
|
2511
|
+
hash: T(),
|
|
2512
|
+
status: T(),
|
|
2513
|
+
appliedAt: D().nullable(),
|
|
2493
2514
|
durationMs: y().nullable(),
|
|
2494
|
-
errorMessage:
|
|
2495
|
-
errorStack:
|
|
2496
|
-
workflowRunId:
|
|
2497
|
-
createdAt:
|
|
2498
|
-
updatedAt:
|
|
2499
|
-
}).index(["status"]),
|
|
2500
|
-
id:
|
|
2501
|
-
name:
|
|
2502
|
-
lifecycle:
|
|
2503
|
-
fingerprint:
|
|
2504
|
-
cronSchedule:
|
|
2505
|
-
watchedTables:
|
|
2506
|
-
nextRunAt:
|
|
2507
|
-
lastRunStatus:
|
|
2508
|
-
lastRunAt:
|
|
2515
|
+
errorMessage: T().nullable(),
|
|
2516
|
+
errorStack: T().nullable(),
|
|
2517
|
+
workflowRunId: T().nullable(),
|
|
2518
|
+
createdAt: D().default("now"),
|
|
2519
|
+
updatedAt: D().default("now").onUpdate("now")
|
|
2520
|
+
}).index(["status"]), Kc = E("_voltro_seeds", {
|
|
2521
|
+
id: O({ prefix: "seed" }),
|
|
2522
|
+
name: T(),
|
|
2523
|
+
lifecycle: T(),
|
|
2524
|
+
fingerprint: T(),
|
|
2525
|
+
cronSchedule: T().nullable(),
|
|
2526
|
+
watchedTables: C().nullable(),
|
|
2527
|
+
nextRunAt: D().nullable(),
|
|
2528
|
+
lastRunStatus: T().nullable(),
|
|
2529
|
+
lastRunAt: D().nullable(),
|
|
2509
2530
|
lastRunDurationMs: y().nullable(),
|
|
2510
2531
|
lastRunRowsTouched: y().nullable(),
|
|
2511
|
-
lastError:
|
|
2512
|
-
workflowRunId:
|
|
2513
|
-
createdAt:
|
|
2514
|
-
updatedAt:
|
|
2515
|
-
}).index(["lifecycle"]).index(["nextRunAt"]),
|
|
2516
|
-
id:
|
|
2517
|
-
fingerprint:
|
|
2518
|
-
liveFingerprint:
|
|
2519
|
-
operations:
|
|
2520
|
-
rollbackPlan:
|
|
2521
|
-
appliedBy:
|
|
2522
|
-
environment:
|
|
2523
|
-
source:
|
|
2524
|
-
onlineStrategy:
|
|
2532
|
+
lastError: T().nullable(),
|
|
2533
|
+
workflowRunId: T().nullable(),
|
|
2534
|
+
createdAt: D().default("now"),
|
|
2535
|
+
updatedAt: D().default("now").onUpdate("now")
|
|
2536
|
+
}).index(["lifecycle"]).index(["nextRunAt"]), qc = E("_voltro_migration_plans", {
|
|
2537
|
+
id: O({ prefix: "plan" }),
|
|
2538
|
+
fingerprint: T(),
|
|
2539
|
+
liveFingerprint: T().nullable(),
|
|
2540
|
+
operations: C(),
|
|
2541
|
+
rollbackPlan: C().nullable(),
|
|
2542
|
+
appliedBy: T(),
|
|
2543
|
+
environment: T(),
|
|
2544
|
+
source: T(),
|
|
2545
|
+
onlineStrategy: T().nullable(),
|
|
2525
2546
|
durationMs: y(),
|
|
2526
|
-
notes:
|
|
2527
|
-
squashedAt:
|
|
2528
|
-
appliedAt:
|
|
2529
|
-
createdAt:
|
|
2530
|
-
updatedAt:
|
|
2531
|
-
}).index(["fingerprint"]).index(["environment"]),
|
|
2532
|
-
id:
|
|
2533
|
-
scope:
|
|
2534
|
-
key:
|
|
2535
|
-
status:
|
|
2536
|
-
response:
|
|
2537
|
-
createdAt:
|
|
2538
|
-
}).unique(["scope", "key"]).index(["createdAt"]),
|
|
2539
|
-
id:
|
|
2540
|
-
key:
|
|
2541
|
-
value:
|
|
2542
|
-
expiresAt:
|
|
2543
|
-
createdAt:
|
|
2544
|
-
updatedAt:
|
|
2545
|
-
}).index(["expiresAt"]),
|
|
2546
|
-
id:
|
|
2547
|
-
tenantId:
|
|
2548
|
-
name:
|
|
2549
|
-
hashedKey:
|
|
2550
|
-
keyPrefix:
|
|
2551
|
-
scopes:
|
|
2552
|
-
lastUsedAt:
|
|
2547
|
+
notes: T().nullable(),
|
|
2548
|
+
squashedAt: D().nullable(),
|
|
2549
|
+
appliedAt: D().default("now"),
|
|
2550
|
+
createdAt: D().default("now"),
|
|
2551
|
+
updatedAt: D().default("now").onUpdate("now")
|
|
2552
|
+
}).index(["fingerprint"]).index(["environment"]), Jc = E("_voltro_idempotency", {
|
|
2553
|
+
id: O({ prefix: "idem" }),
|
|
2554
|
+
scope: T(),
|
|
2555
|
+
key: T(),
|
|
2556
|
+
status: T(),
|
|
2557
|
+
response: C().nullable(),
|
|
2558
|
+
createdAt: D().default("now")
|
|
2559
|
+
}).unique(["scope", "key"]).index(["createdAt"]), Yc = E("_voltro_kv", {
|
|
2560
|
+
id: O({ prefix: "kv" }),
|
|
2561
|
+
key: T().unique(),
|
|
2562
|
+
value: T().nullable(),
|
|
2563
|
+
expiresAt: D().nullable(),
|
|
2564
|
+
createdAt: D().default("now"),
|
|
2565
|
+
updatedAt: D().default("now").onUpdate("now")
|
|
2566
|
+
}).index(["expiresAt"]), Xc = E("_voltro_api_keys", {
|
|
2567
|
+
id: O({ prefix: "apikey" }),
|
|
2568
|
+
tenantId: T().nullable(),
|
|
2569
|
+
name: T(),
|
|
2570
|
+
hashedKey: T().maxLength(64).unique(),
|
|
2571
|
+
keyPrefix: T(),
|
|
2572
|
+
scopes: C().nullable(),
|
|
2573
|
+
lastUsedAt: D().nullable(),
|
|
2553
2574
|
requestCount: y().default(0),
|
|
2554
|
-
expiresAt:
|
|
2555
|
-
revokedAt:
|
|
2556
|
-
createdBy:
|
|
2557
|
-
onBehalfOf:
|
|
2558
|
-
metadata:
|
|
2559
|
-
createdAt:
|
|
2560
|
-
}).index("byApiKeyTenant", ["tenantId"]),
|
|
2561
|
-
id:
|
|
2562
|
-
replicaId:
|
|
2563
|
-
startedAt:
|
|
2564
|
-
version:
|
|
2565
|
-
kind:
|
|
2566
|
-
payload:
|
|
2567
|
-
reachableAt:
|
|
2568
|
-
writtenAt:
|
|
2569
|
-
}).unique(["replicaId", "kind"]).index(["kind"]),
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
],
|
|
2574
|
-
id:
|
|
2575
|
-
startedAt:
|
|
2576
|
-
kind:
|
|
2577
|
-
tables:
|
|
2578
|
-
capture:
|
|
2579
|
-
via:
|
|
2580
|
-
staging:
|
|
2581
|
-
heartbeatAt:
|
|
2575
|
+
expiresAt: D().nullable(),
|
|
2576
|
+
revokedAt: D().nullable(),
|
|
2577
|
+
createdBy: T().nullable(),
|
|
2578
|
+
onBehalfOf: T().nullable(),
|
|
2579
|
+
metadata: C().nullable(),
|
|
2580
|
+
createdAt: D().default("now")
|
|
2581
|
+
}).index("byApiKeyTenant", ["tenantId"]), Zc = E("_voltro_replica_observations", {
|
|
2582
|
+
id: O({ prefix: "robs" }),
|
|
2583
|
+
replicaId: T().maxLength(191),
|
|
2584
|
+
startedAt: D(),
|
|
2585
|
+
version: T().maxLength(64).nullable(),
|
|
2586
|
+
kind: T().maxLength(64),
|
|
2587
|
+
payload: T().nullable(),
|
|
2588
|
+
reachableAt: T().maxLength(255).nullable(),
|
|
2589
|
+
writtenAt: D().default("now").onUpdate("now")
|
|
2590
|
+
}).unique(["replicaId", "kind"]).index(["kind"]), Qc = [
|
|
2591
|
+
Gc,
|
|
2592
|
+
Kc,
|
|
2593
|
+
qc
|
|
2594
|
+
], $c = "_voltro_replace_in_progress", el = E($c, {
|
|
2595
|
+
id: O({ prefix: "repl" }),
|
|
2596
|
+
startedAt: D().default("now"),
|
|
2597
|
+
kind: T().default("replace"),
|
|
2598
|
+
tables: T().nullable(),
|
|
2599
|
+
capture: T().nullable(),
|
|
2600
|
+
via: T(),
|
|
2601
|
+
staging: T().nullable(),
|
|
2602
|
+
heartbeatAt: D().nullable(),
|
|
2582
2603
|
resumable: p().nullable()
|
|
2583
|
-
}),
|
|
2604
|
+
}), tl = 30, nl = (e, t) => {
|
|
2584
2605
|
let n = typeof t == "number" && Number.isFinite(t) && t > 0 ? t : 30, r = Number(e.VOLTRO_STAGING_STALE_MINUTES);
|
|
2585
2606
|
return (Number.isFinite(r) && r > 0 ? r : n) * 6e4;
|
|
2586
|
-
},
|
|
2607
|
+
}, rl = (e) => e == null || String(e).length === 0 ? [] : String(e).split(",").map((e) => e.trim()).filter((e) => e.length > 0), il = (e) => {
|
|
2587
2608
|
let t = e.filter((e) => e.kind !== "staging");
|
|
2588
2609
|
if (t.length !== 0) return `refusing to start: a destructive data operation did not finish.
|
|
2589
2610
|
${t.map((e) => {
|
|
@@ -2598,7 +2619,7 @@ ${t.map((e) => {
|
|
|
2598
2619
|
|
|
2599
2620
|
When the data is back, or you have decided the current state is correct, clear the marker:
|
|
2600
2621
|
voltro data clear-replace-marker --yes`;
|
|
2601
|
-
},
|
|
2622
|
+
}, al = (e, t, n) => {
|
|
2602
2623
|
let r = e.filter((e) => e.kind === "staging");
|
|
2603
2624
|
return {
|
|
2604
2625
|
all: r,
|
|
@@ -2608,7 +2629,7 @@ ${t.map((e) => {
|
|
|
2608
2629
|
return Number.isFinite(r) ? t - r >= n : !1;
|
|
2609
2630
|
})
|
|
2610
2631
|
};
|
|
2611
|
-
},
|
|
2632
|
+
}, ol = (e, t) => {
|
|
2612
2633
|
if (e.all.length === 0) return;
|
|
2613
2634
|
let n = new Set(e.droppable.map((e) => e.id));
|
|
2614
2635
|
return `staged data-import leftovers:
|
|
@@ -2617,22 +2638,22 @@ ${e.all.map((e) => {
|
|
|
2617
2638
|
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.`;
|
|
2618
2639
|
}).join("\n")}\n The target of a staged \`replace\` is untouched until one short swap at the end, so none of this is
|
|
2619
2640
|
a reason to refuse the boot — it is a reason to know the disk is holding a copy of a bundle.`;
|
|
2620
|
-
},
|
|
2621
|
-
let n =
|
|
2641
|
+
}, sl = "id", cl = (e, t) => {
|
|
2642
|
+
let n = w(e);
|
|
2622
2643
|
if (n === void 0) return t;
|
|
2623
|
-
let r = n.fields[
|
|
2624
|
-
if (r === void 0 || t[
|
|
2644
|
+
let r = n.fields[sl]?.idScheme;
|
|
2645
|
+
if (r === void 0 || t[sl] != null) return t;
|
|
2625
2646
|
if (r.kind === "numeric") {
|
|
2626
|
-
if (!(
|
|
2647
|
+
if (!(sl in t)) return t;
|
|
2627
2648
|
let e = { ...t };
|
|
2628
|
-
return delete e[
|
|
2649
|
+
return delete e[sl], e;
|
|
2629
2650
|
}
|
|
2630
|
-
let i =
|
|
2651
|
+
let i = nt(r, e);
|
|
2631
2652
|
return i === null ? t : {
|
|
2632
2653
|
...t,
|
|
2633
|
-
[
|
|
2654
|
+
[sl]: i
|
|
2634
2655
|
};
|
|
2635
|
-
},
|
|
2656
|
+
}, ll = (e, t) => t.map((t) => cl(e, t)), ul = {
|
|
2636
2657
|
postgres: { maxBindParameters: 65535 },
|
|
2637
2658
|
mysql: { maxBindParameters: 65535 },
|
|
2638
2659
|
mariadb: { maxBindParameters: 65535 },
|
|
@@ -2642,25 +2663,25 @@ ${e.all.map((e) => {
|
|
|
2642
2663
|
},
|
|
2643
2664
|
sqlite: { maxBindParameters: 32766 },
|
|
2644
2665
|
turso: { maxBindParameters: 32766 }
|
|
2645
|
-
},
|
|
2666
|
+
}, dl = (e) => ul[e], fl = (e) => {
|
|
2646
2667
|
let t = /* @__PURE__ */ new Set();
|
|
2647
2668
|
for (let n of e) for (let e of Object.keys(n)) t.add(e);
|
|
2648
2669
|
return t.size;
|
|
2649
|
-
},
|
|
2670
|
+
}, pl = (e, t) => {
|
|
2650
2671
|
if (t === void 0 || e.length === 0) return [e];
|
|
2651
|
-
let n = Math.max(1,
|
|
2672
|
+
let n = Math.max(1, fl(e)), r = Math.floor(t.maxBindParameters / n), i = t.maxRowsPerStatement ?? Infinity, a = Math.max(1, Math.min(r, i));
|
|
2652
2673
|
if (e.length <= a) return [e];
|
|
2653
2674
|
let o = [];
|
|
2654
2675
|
for (let t = 0; t < e.length; t += a) o.push(e.slice(t, t + a));
|
|
2655
2676
|
return o;
|
|
2656
|
-
},
|
|
2677
|
+
}, ml = (e, t) => {
|
|
2657
2678
|
let n = [], r = t;
|
|
2658
2679
|
for (let [t, i] of Object.entries(e.fields)) {
|
|
2659
2680
|
let e = i;
|
|
2660
2681
|
e.nullable || e.hasDefault || e.idScheme !== void 0 || e.generatedAs !== void 0 || (r[t] === void 0 || r[t] === null) && n.push(t);
|
|
2661
2682
|
}
|
|
2662
2683
|
return n;
|
|
2663
|
-
},
|
|
2684
|
+
}, hl = (e, t, n) => {
|
|
2664
2685
|
let r = n, i = new Set(e === void 0 ? [] : Object.entries(e.fields).filter(([, e]) => e.generatedAs !== void 0).map(([e]) => e)), a = [];
|
|
2665
2686
|
for (let e of t) i.has(e) || (r[e] === void 0 ? a.push({
|
|
2666
2687
|
column: e,
|
|
@@ -2670,36 +2691,36 @@ ${e.all.map((e) => {
|
|
|
2670
2691
|
reason: "null"
|
|
2671
2692
|
}));
|
|
2672
2693
|
return a;
|
|
2673
|
-
},
|
|
2694
|
+
}, gl = (e, t, n) => e.insert(t.tableName, n), _l = (e, t, n) => e.insertMany(t.tableName, n), vl = (e, t, n, r) => e.upsert(t.tableName, n, {
|
|
2674
2695
|
conflictColumns: r.conflictColumns,
|
|
2675
2696
|
...r.update === void 0 ? {} : { update: r.update },
|
|
2676
2697
|
...r.updateValues === void 0 ? {} : { updateValues: r.updateValues }
|
|
2677
|
-
}),
|
|
2698
|
+
}), yl = async (e, t, n, r) => {
|
|
2678
2699
|
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.");
|
|
2679
2700
|
return e.upsertWithOutcome(t.tableName, n, {
|
|
2680
2701
|
conflictColumns: r.conflictColumns,
|
|
2681
2702
|
...r.update === void 0 ? {} : { update: r.update },
|
|
2682
2703
|
...r.updateValues === void 0 ? {} : { updateValues: r.updateValues }
|
|
2683
2704
|
});
|
|
2684
|
-
},
|
|
2705
|
+
}, bl = async (e, t, n, r) => e.insertIgnoreWithOutcome(t.tableName, n, { conflictColumns: r.conflictColumns }), xl = (e, t, n, r) => e.updateMany(t.tableName, n, { where: r.where }), Sl = 512, Cl = (e) => {
|
|
2685
2706
|
e.setMaxListeners(512);
|
|
2686
|
-
},
|
|
2707
|
+
}, wl = (e, t, n) => ({
|
|
2687
2708
|
_tag: "PrimaryKeyConflictError",
|
|
2688
2709
|
table: e,
|
|
2689
2710
|
key: t,
|
|
2690
2711
|
cause: n
|
|
2691
|
-
}),
|
|
2712
|
+
}), Tl = (e) => typeof e == "object" && !!e && e._tag === "PrimaryKeyConflictError", El = {
|
|
2692
2713
|
postgres: 5432,
|
|
2693
2714
|
mysql: 3306,
|
|
2694
2715
|
mariadb: 3306,
|
|
2695
2716
|
mssql: 1433
|
|
2696
|
-
},
|
|
2717
|
+
}, Dl = /* @__PURE__ */ new Set([
|
|
2697
2718
|
"localhost",
|
|
2698
2719
|
"127.0.0.1",
|
|
2699
2720
|
"::1",
|
|
2700
2721
|
"[::1]",
|
|
2701
2722
|
"0.0.0.0"
|
|
2702
|
-
]),
|
|
2723
|
+
]), Ol = (e) => {
|
|
2703
2724
|
let t = e.host, n = e.port, r = e.database;
|
|
2704
2725
|
if (e.url !== void 0 && e.url !== "") try {
|
|
2705
2726
|
let i = new URL(e.url);
|
|
@@ -2708,29 +2729,29 @@ ${e.all.map((e) => {
|
|
|
2708
2729
|
return;
|
|
2709
2730
|
}
|
|
2710
2731
|
if (t === void 0 || t === "" || r === void 0 || r === "") return;
|
|
2711
|
-
let i = n ??
|
|
2732
|
+
let i = n ?? El[(e.dialect ?? "").toLowerCase()];
|
|
2712
2733
|
if (i === void 0 || !Number.isFinite(i)) return;
|
|
2713
2734
|
let a = t.toLowerCase();
|
|
2714
2735
|
return {
|
|
2715
|
-
host:
|
|
2736
|
+
host: Dl.has(a) ? "localhost" : a,
|
|
2716
2737
|
port: i,
|
|
2717
2738
|
database: r.toLowerCase()
|
|
2718
2739
|
};
|
|
2719
|
-
},
|
|
2720
|
-
let t =
|
|
2721
|
-
if (t !== void 0) return
|
|
2722
|
-
},
|
|
2740
|
+
}, kl = (e) => {
|
|
2741
|
+
let t = Ol(e);
|
|
2742
|
+
if (t !== void 0) return Kt("sha256").update(`${t.host}\u0000${t.port}\u0000${t.database}`).digest("hex").slice(0, 32);
|
|
2743
|
+
}, Al = (e, t) => e === void 0 || t === void 0 ? "unknown" : e === t ? "same" : "different", jl = {
|
|
2723
2744
|
app: 3,
|
|
2724
2745
|
plugin: 2,
|
|
2725
2746
|
framework: 1
|
|
2726
|
-
},
|
|
2747
|
+
}, Ml = /* @__PURE__ */ new Map(), Nl = [], Pl = () => [...Nl], Fl = (e) => {
|
|
2727
2748
|
if (!e.table || !e.timeColumn) throw Error("registerRetention: table + timeColumn are required");
|
|
2728
2749
|
if (!Number.isFinite(e.ttlMs) || e.ttlMs <= 0) throw Error(`registerRetention(${e.table}): ttlMs must be a positive number`);
|
|
2729
|
-
let t = e.source ?? "app", n =
|
|
2750
|
+
let t = e.source ?? "app", n = Ml.get(e.table);
|
|
2730
2751
|
if (n !== void 0) {
|
|
2731
2752
|
let r = n.source ?? "app", i = n.ttlMs !== e.ttlMs || n.where !== void 0 != (e.where !== void 0);
|
|
2732
|
-
if (
|
|
2733
|
-
i &&
|
|
2753
|
+
if (jl[t] < jl[r]) {
|
|
2754
|
+
i && Nl.push({
|
|
2734
2755
|
table: e.table,
|
|
2735
2756
|
kept: {
|
|
2736
2757
|
source: r,
|
|
@@ -2743,7 +2764,7 @@ ${e.all.map((e) => {
|
|
|
2743
2764
|
});
|
|
2744
2765
|
return;
|
|
2745
2766
|
}
|
|
2746
|
-
i && r !== t &&
|
|
2767
|
+
i && r !== t && Nl.push({
|
|
2747
2768
|
table: e.table,
|
|
2748
2769
|
kept: {
|
|
2749
2770
|
source: t,
|
|
@@ -2755,13 +2776,13 @@ ${e.all.map((e) => {
|
|
|
2755
2776
|
}
|
|
2756
2777
|
});
|
|
2757
2778
|
}
|
|
2758
|
-
|
|
2779
|
+
Ml.set(e.table, {
|
|
2759
2780
|
...e,
|
|
2760
2781
|
source: t
|
|
2761
2782
|
});
|
|
2762
|
-
},
|
|
2763
|
-
|
|
2764
|
-
},
|
|
2783
|
+
}, Il = () => [...Ml.values()], Ll = () => {
|
|
2784
|
+
Ml.clear(), Nl.length = 0;
|
|
2785
|
+
}, Rl = async (e, t, n, r = 2e4) => {
|
|
2765
2786
|
let i = new Date(t - e.ttlMs), a = 0;
|
|
2766
2787
|
try {
|
|
2767
2788
|
for (;;) {
|
|
@@ -2769,45 +2790,45 @@ ${e.all.map((e) => {
|
|
|
2769
2790
|
if (a += t, t < r) break;
|
|
2770
2791
|
}
|
|
2771
2792
|
} catch (t) {
|
|
2772
|
-
throw
|
|
2793
|
+
throw A.runSync(j.increment(j.tagged(Bl, "table", e.table))), t;
|
|
2773
2794
|
}
|
|
2774
|
-
return a > 0 &&
|
|
2775
|
-
},
|
|
2795
|
+
return a > 0 && A.runSync(j.incrementBy(j.tagged(zl, "table", e.table), a)), a;
|
|
2796
|
+
}, zl = j.counter("voltro_retention_swept_rows_total"), Bl = j.counter("voltro_retention_sweep_errors_total"), Vl = (e, t) => {
|
|
2776
2797
|
let n = Number(e ?? String(t));
|
|
2777
2798
|
return (Number.isFinite(n) && n > 0 ? n : t) * 36e5;
|
|
2778
|
-
},
|
|
2779
|
-
id:
|
|
2780
|
-
replicaId:
|
|
2781
|
-
streamName:
|
|
2782
|
-
binlogFile:
|
|
2783
|
-
binlogPosition:
|
|
2784
|
-
updatedAt:
|
|
2785
|
-
}).index(["replicaId"]),
|
|
2786
|
-
id:
|
|
2787
|
-
replicaId:
|
|
2788
|
-
streamName:
|
|
2789
|
-
ctVersion:
|
|
2790
|
-
updatedAt:
|
|
2791
|
-
}).index(["replicaId"]),
|
|
2792
|
-
id:
|
|
2793
|
-
startedAt:
|
|
2794
|
-
finishedAt:
|
|
2795
|
-
direction:
|
|
2796
|
-
mode:
|
|
2797
|
-
via:
|
|
2798
|
-
bundle:
|
|
2799
|
-
sourceFingerprint:
|
|
2799
|
+
}, Hl = "_voltro_cdc_offsets", Ul = E(Hl, {
|
|
2800
|
+
id: O({ prefix: "cdcoff" }),
|
|
2801
|
+
replicaId: T(),
|
|
2802
|
+
streamName: T(),
|
|
2803
|
+
binlogFile: T(),
|
|
2804
|
+
binlogPosition: T(),
|
|
2805
|
+
updatedAt: D()
|
|
2806
|
+
}).index(["replicaId"]), Wl = E(Hl, {
|
|
2807
|
+
id: O({ prefix: "cdcoff" }),
|
|
2808
|
+
replicaId: T(),
|
|
2809
|
+
streamName: T(),
|
|
2810
|
+
ctVersion: T(),
|
|
2811
|
+
updatedAt: D()
|
|
2812
|
+
}).index(["replicaId"]), Gl = "_voltro_data_transfers", Kl = E(Gl, {
|
|
2813
|
+
id: O({ prefix: "dimp" }),
|
|
2814
|
+
startedAt: D().default("now"),
|
|
2815
|
+
finishedAt: D().nullable(),
|
|
2816
|
+
direction: T().default("import"),
|
|
2817
|
+
mode: T(),
|
|
2818
|
+
via: T(),
|
|
2819
|
+
bundle: T().nullable(),
|
|
2820
|
+
sourceFingerprint: T().nullable(),
|
|
2800
2821
|
tablesWritten: y().default(0),
|
|
2801
2822
|
rowsWritten: y().default(0),
|
|
2802
|
-
failure:
|
|
2823
|
+
failure: T().nullable(),
|
|
2803
2824
|
staged: p().nullable()
|
|
2804
|
-
}).renamedFrom("_voltro_data_imports").nonReactive(),
|
|
2825
|
+
}).renamedFrom("_voltro_data_imports").nonReactive(), ql = (e) => {
|
|
2805
2826
|
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)";
|
|
2806
2827
|
return `${t} · ${r} · via ${e.via}${i}` + (e.bundle === null ? "" : ` · from ${e.bundle}`) + (e.sourceFingerprint === null ? "" : ` · source schema ${e.sourceFingerprint}`);
|
|
2807
|
-
},
|
|
2828
|
+
}, Jl = 255, Yl = (e) => e == null ? "null" : typeof e == "string" || typeof e == "number" || typeof e == "boolean" ? JSON.stringify(e) : Array.isArray(e) ? `[${e.map(Yl).join(",")}]` : typeof e == "object" ? `{${Object.entries(e).filter(([, e]) => e !== void 0).sort(([e], [t]) => e < t ? -1 : +(e > t)).map(([e, t]) => `${JSON.stringify(e)}:${Yl(t)}`).join(",")}}` : JSON.stringify(String(e)), Xl = (e) => {
|
|
2808
2829
|
if (e == null) return null;
|
|
2809
|
-
let t = typeof e == "string" ? e :
|
|
2830
|
+
let t = typeof e == "string" ? e : Yl(e);
|
|
2810
2831
|
return t.length > 255 ? t.slice(0, 255) : t;
|
|
2811
|
-
},
|
|
2832
|
+
}, Zl = "postgres";
|
|
2812
2833
|
//#endregion
|
|
2813
|
-
export {
|
|
2834
|
+
export { st as AUTO_FILLED_COLUMNS, rn as BOUND_ENCRYPTED_PREFIX, ul as BULK_INSERT_LIMITS, X as BranchNameInvalid, nc as BranchTransitionInvalid, Hl as CDC_OFFSETS_TABLE, _o as CHANGE_CLAIM_TTL_ENV, Sl as CHANGE_LISTENER_CEILING, Xe as ColumnBuilder, Gl as DATA_TRANSFERS_TABLE, at as DEFAULT_ACQUIRE_TIMEOUT_MS, vo as DEFAULT_CHANGE_CLAIM_TTL_HOURS, ys as DEFAULT_EAGER_FALLBACK_WARN_INTERVAL_MS, _t as DEFAULT_SOFT_DROP_RETENTION_DAYS, fr as DEFAULT_SUBJECT_GRAPH_DEPTH, nn as ENCRYPTED_PREFIX, Zl as ENGINE, zr as EagerCardinalityError, bt as FILE_MIGRATION_PATTERN, rt as FRAMEWORK_LIVE_TABLES, sn as FieldDecryptionError, Vo as ID_COLUMN_MAX_LENGTH, Ft as INITIAL_VERSION, Ha as MATCHES_NO_ROWS, Ct as MAX_IDENTIFIER_LENGTH, js as MSSQL_TRANSIENT_NUMBERS, ks as MYSQL_TRANSIENT_CODES, go as OccurrenceCounter, As as POSTGRES_TRANSIENT_STATES, $c as REPLACE_IN_PROGRESS_TABLE, Jl as SCOPE_KEY_MAX_LENGTH, ae as SELF_REFERENCE_TARGET, Ms as SQLITE_TRANSIENT_CODES, tl as STAGING_STALE_MINUTES, dt as STAGING_TABLE_PREFIX, Yt as SqlClient, Ns as TURSO_TRANSIENT_MESSAGE, Ws as TableStreamError, $r as TenantNamespaceInvalid, Qr as TenantNamespaceUnresolved, Sc as TenantRegionUnavailable, xc as TenantResidencyUnresolved, Rs as VOLTRO_EXPIRES_MIXIN_ID, Bs as VOLTRO_LOCAL_FIRST_MIXIN_ID, Mt as VersionConflict, Ot as WARN_IDENTIFIER_LENGTH, Xc as _voltroApiKeysTable, Ul as _voltroCdcOffsetsTable, Kl as _voltroDataTransfersTable, Jc as _voltroIdempotencyTable, Yc as _voltroKvTable, qc as _voltroMigrationPlansTable, Gc as _voltroMigrationsTable, Wl as _voltroMssqlCdcOffsetsTable, el as _voltroReplaceInProgressTable, Zc as _voltroReplicaObservationsTable, Kc as _voltroSeedsTable, Da as actorsTable, hc as admitBranch, Ke as agedSoftDropSnapshots, ve as allEnumRenames, lr as allRegisteredRelations, te as allRegisteredTables, Ka as and, Lr as applyJsonPatch, oe as array, za as arrayContains, Va as arrayHas, Ba as arrayOverlaps, Vr as attachEagerLoads, Co as attributionFields, Do as attributionKey, Ic as auditAllTableIndexes, Fc as auditTableIndexes, wt as avg, _e as avgOver, Io as beginLocalWrite, ue as bigint, Ac as bindResidentStore, p as boolean, $s as branchNamespaceName, dl as bulkInsertLimitsFor, ee as bytes, bn as causeBranches, lo as changeDelete, po as changeDigest, so as changeInsert, uo as changeSoftDelete, co as changeUpdate, pl as chunkRowsForInsert, Ao as claimPendingAttribution, An as classifyConstraintViolation, d as clearEnumRenames, zo as clearPendingAttribution, dr as clearRelationsRegistry, Ec as clearResidencyConfig, Ll as clearRetentions, Ee as clearTableRegistry, Jo as clearWriteRecorders, G as coercePredicateForSqlite, si as coercePredicateValue, ci as coercePredicateValues, ya as coerceValueForSqlite, io as collectSubqueries, u as column, zn as columnSchema, fl as columnsPerRow, Oa as compareDecimal, Si as compileEagerJson, Rr as compileJsonPatch, R as compilePredicate, li as compileRawFragment, xi as compileSelect, mo as composeChangeKey, Ys as computeEmbedding, kl as connectionIdentity, La as contains, c as count, se as countDistinct, ie as crdtDoc, me as crdtManagedColumns, At as crdtManagedColumnsOf, a as crdtText, So as currentWriteAttribution, Ze as databaseHandle, Se as date, _ as dbEnum, ps as dbMetricTagCacheSizeForTests, gs as dbOperationsInFlight, be as decimal, l as declareEnumRename, fn as decodeFieldValue, Er as decodeRowsFromSchema, vn as decryptFieldsOnRead, Uc as defineMigration, xt as defineMixin, ct as defineSeed, n as denseRank, yr as deriveSubjectGraph, lt as deriveTypeIdPrefix, Wo as derivedRowId, Go as derivedRowIdLength, je as describeAgedSoftDropSnapshots, Nn as describeDriverError, Pn as describeRowBindings, ql as describeTransferRun, tn as deserializeArraysOnRead, Pe as drainIdentifierWarnings, we as dropped, un as encodeFieldValue, Or as encodeRowForSchema, _n as encryptFieldsForWrite, hn as encryptedColumnsOf, Lo as endLocalWrite, fc as enforceBranchLimits, Te as ensureTableRegistered, ka as eq, ui as escapeLike, ro as evaluatePredicate, Ye as except, $a as exists, zs as expires, oo as externalChangeEvent, Cn as extractDbCause, an as fieldBinding, tt as fireSchemaChangeSeeds, We as fireTenantCreateSeeds, Vc as formatIndexAuditIssue, br as formatSubjectGraph, Qc as frameworkTables, nt as generateId, Ue as generateSnowflake, h as geography, re as geometry, ce as getEnumRenames, cr as getRelation, sr as getRelations, Tc as getResidencyConfig, w as getTable, ja as gt, Ma as gte, Zr as hasEagerLoads, Js as hybridSearch, O as id, Fa as inSet, Za as inSubquery, Qn as inferForeignKey, bl as insertIgnoreRowOutcome, _l as insertManyRows, gl as insertRow, y as integer, il as interruptedReplaceRefusal, x as intersect, De as interval, on as isBoundCiphertext, ec as isBranchNamespace, Nr as isCompositeRowKey, qn as isEmptyRelationsSpec, ln as isEncrypted, cn as isFieldDecryptionError, Ie as isFileMigration, jn as isForeignKeyViolation, ot as isFrameworkOwnedLiveTable, Hs as isLocalFirst, Wc as isMigrationDefinition, pt as isMysqlFamily, oc as isNeonConnection, Wa as isNotNull, Ua as isNull, Tl as isPrimaryKeyConflictError, Mn as isQueryTimeout, pn as isRawEncoding, Oc as isRegionServable, Jn as isRelationsSpec, He as isSeedDefinition, mt as isSoftDropSnapshotName, Je as isSqliteFamily, Fe as isStagingTableName, de as isTableReactive, Is as isTransientContention, Ne as isView, C as json, Ya as jsonField, gt as jsonIndex, Pr as jsonPatchAssignments, S as lag, le as lead, Pl as listRetentionConflicts, Il as listRetentions, Vs as localFirst, Us as localFirstTables, Na as lt, Pa as lte, Ss as makeEagerFallbackReporter, bc as makeNamespaceBranchExecutor, Xn as many, Zn as manyToMany, Oe as materializeFields, f as max, Be as migration, v as min, hl as missingConflictColumns, ml as missingRequiredColumns, Le as mixin, Aa as neq, rc as nextBranchState, Ol as normaliseTarget, Ir as normalizeJsonPatchValue, Ja as not, eo as notExists, Ia as notInSet, Qa as notInSubquery, fe as numeric, vs as observeDbOp, yo as occurrenceWindowMs, Yn as one, Br as oneCardinalityMessage, qa as or, b as orderClausesOf, pe as paginateBy, kt as paginateById, ho as parseChangeKey, Bo as pendingAttributionCount, uc as planBranch, ic as planBranchProvision, ac as planBranchTeardown, dc as planBranchTeardownFor, cc as planNeonBranchProvision, lc as planNeonBranchTeardown, jt as planVersionedUpdate, Qe as pluginRef, r as pluginRefSpecOf, wl as primaryKeyConflictError, pc as provisionBranch, jc as provisionResidentTenant, ii as qualifyTable, i as queryFor, Et as queryForView, Me as quoteIdent, Cl as raiseChangeListenerCeiling, xe as rank, t as raw, Re as readableByColumns, vt as real, _s as recordDbOp, $o as recordsTable, it as reference, Ln as refuseWrite, Ca as registerCoreTables, or as registerDiscoveredRelations, ko as registerPendingAttribution, ar as registerRelations, Fl as registerRetention, e as registerTable, Ko as registerWriteRecorder, Kn as relations, Ta as requireActors, ze as requireTable, Ea as requireTenants, fs as resetDbMetricTagCacheForTests, Ae as resetSnowflake, kc as residentPlacement, Zt as resolveActorSnapshot, sc as resolveBranchMechanism, xs as resolveEagerFallbackWarnIntervalMs, Ro as resolveEchoAttribution, g as resolveFullTextIndex, Ge as resolveIdScheme, Ve as resolveMixinGraph, Dc as resolveTenantHome, ri as resolveTenantNamespace, Vl as retentionTtlMsFromEnv, jr as rowKeyColumns, Mr as rowKeyIdentity, ye as rowNumber, Bn as rowSchema, Ds as runRetryingTransaction, Os as runStoreTransaction, xo as runWithWriteAttribution, es as runWriteRecorders, Al as sameDatabase, ni as sanitizeIdentifierFragment, Xl as scopeKeyOf, ft as selfReference, en as serializeArraysForWrite, qe as serverOnlyColumns, wc as setResidencyConfig, ke as setSchemaChangeSeedHook, St as setTenantCreateSeedHook, Cs as settleTransactionExit, Pt as settleVersionedUpdate, $e as softDropSnapshotStamp, Ga as spatialPredicate, ol as stagingLeftoverReport, al as stagingLeftovers, rl as stagingNamesOf, nl as stagingStaleAfterMs, cl as stampGeneratedId, ll as stampGeneratedIds, Ra as startsWith, Rn as storeRefusalOf, qs as streamTable, Ce as sum, m as sumOver, Xo as suspendWriteRecorders, Zo as suspendWriteRecordersEffect, Rl as sweepRetention, E as table, mc as teardownBranch, T as text, D as timestamp, Lt as timestampMs, Nt as timestampMsOrNull, Es as transactionRetrySchedule, ne as union, ut as unionAll, yt as unregisterTable, qo as unregisterWriteRecorder, xl as updateManyRow, vl as upsertRow, yl as upsertRowOutcome, Ar as upsertUpdatePatch, kr as upsertUpdateValues, Dt as validateColumnName, ge as validateIndexName, ur as validateRegisteredRelations, nr as validateRelationConfig, s as validateTableName, Tt as validateTypeIdPrefix, ht as vector, et as vectorDistanceToOpclass, Xs as vectorEmbedding, It as versionColumnOf, he as view, o as viewSql, ao as walkLeaves, wn as wireSafeCause, wo as withCapturedAttribution, Qo as writeRecordersSuspended };
|