@voltro/database 0.75.0 → 0.77.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 +459 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +633 -927
- package/dist/{frameworkTables-CfWuWeFG.js → replaceInProgress-DdjHyYFT.js} +764 -441
- package/dist/sql.d.ts +92 -4
- package/dist/sql.js +1321 -1260
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { $ as e, $n as t, $t as n, A as r, An as i,
|
|
2
|
-
import { a as
|
|
3
|
-
import { Cause as
|
|
4
|
-
import { createHash as
|
|
5
|
-
import { AsyncLocalStorage as
|
|
6
|
-
import { TransactionConnection as
|
|
7
|
-
import { ansi as
|
|
8
|
-
import { SqlClient as
|
|
1
|
+
import { $ as e, $n as t, $t as n, A as r, An as i, Ar as a, At as o, B as s, Bn as c, Bt as l, C as u, Cn as d, Cr as f, Ct as p, Dn as m, Dr as h, Dt as g, E as _, En as v, Er as ee, Et as te, F as ne, Fn as re, Ft as ie, G as ae, Gn as oe, Gt as se, H as ce, Hn as y, Ht as le, I as ue, In as de, It as fe, J as pe, Jn as me, Jt as he, K as ge, Kn as _e, Kt as ve, L as ye, Ln as be, Lt as xe, M as Se, Mn as Ce, Mr as b, N as we, Nn as Te, Nr as x, Nt as Ee, O as De, On as Oe, Or as ke, Ot as Ae, P as je, Pn as Me, Pr as Ne, Pt as Pe, Q as Fe, Qn as Ie, Qt as Le, R as Re, Rn as ze, Rt as Be, S as Ve, Sn as He, Sr as Ue, St as We, T as Ge, Tn as S, Tr as Ke, Tt as qe, U as Je, Un as Ye, Ut as Xe, V as Ze, Vn as Qe, Vt as $e, W as et, Wn as tt, Wt as nt, X as rt, Xn as it, Xt as at, Y as ot, Yn as st, Yt as ct, Z as lt, Zn as ut, Zt as dt, _ as ft, _n as pt, _r as mt, _t as ht, a as gt, an as _t, ar as vt, at as yt, b as bt, bn as xt, br as C, bt as St, c as Ct, cn as wt, cr as Tt, ct as Et, d as Dt, dn as Ot, dr as kt, dt as At, en as w, er as jt, et as Mt, f as Nt, fn as Pt, fr as Ft, ft as It, g as Lt, gn as Rt, gr as zt, gt as Bt, h as Vt, hn as Ht, hr as Ut, ht as Wt, i as Gt, in as Kt, ir as qt, it as Jt, j as Yt, jn as Xt, jr as Zt, jt as Qt, k as $t, kn as en, kr as tn, kt as nn, l as rn, ln as an, lr as on, lt as sn, m as cn, mn as ln, mr as un, mt as dn, n as fn, nn as pn, nr as mn, nt as hn, o as gn, on as _n, or as vn, ot as yn, p as bn, pn as xn, pr as Sn, pt as Cn, q as wn, qn as Tn, qt as En, r as Dn, rn as On, rr as kn, rt as An, s as jn, sn as Mn, sr as Nn, st as Pn, t as Fn, tn as In, tr as Ln, tt as Rn, u as zn, un as Bn, ur as Vn, ut as Hn, v as Un, vn as Wn, vr as Gn, vt as Kn, w as qn, wn as Jn, wr as Yn, wt as Xn, x as Zn, xn as Qn, xr as $n, xt as T, y as er, yn as tr, yr as nr, yt as rr, z as ir, zn as ar, zt as or } from "./replaceInProgress-DdjHyYFT.js";
|
|
2
|
+
import { a as sr, i as cr, n as lr, o as ur, r as dr, s as fr, t as pr } from "./wire-B28cPjEp.js";
|
|
3
|
+
import { Cause as mr, Chunk as hr, Data as gr, Effect as E, Exit as _r, Metric as D, MetricBoundaries as vr, Option as O, Schedule as yr, Schema as k, Stream as br } from "effect";
|
|
4
|
+
import { createHash as xr } from "node:crypto";
|
|
5
|
+
import { AsyncLocalStorage as Sr } from "node:async_hooks";
|
|
6
|
+
import { TransactionConnection as Cr } from "@effect/sql/SqlClient";
|
|
7
|
+
import { ansi as A } from "@voltro/logger";
|
|
8
|
+
import { SqlClient as wr } from "@effect/sql";
|
|
9
9
|
//#region src/actorSnapshot.ts
|
|
10
|
-
var
|
|
10
|
+
var Tr = (e) => typeof e == "string" && e !== "" ? e : null, Er = 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 rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = 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: Tr(r.kind) ?? n,
|
|
27
|
+
displayName: Tr(r.displayName),
|
|
28
|
+
email: Tr(r.email)
|
|
29
29
|
};
|
|
30
30
|
} catch {
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
|
-
},
|
|
33
|
+
}, Dr = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqlite", Or = (e) => {
|
|
34
34
|
let t = [];
|
|
35
35
|
for (let [n, r] of Object.entries(e.fields)) r.type === "array" && t.push(n);
|
|
36
36
|
return t;
|
|
37
|
-
},
|
|
38
|
-
if (!
|
|
39
|
-
let r =
|
|
37
|
+
}, kr = (e, t, n) => {
|
|
38
|
+
if (!Dr(n) || !t) return e;
|
|
39
|
+
let r = Or(t);
|
|
40
40
|
if (r.length === 0) return e;
|
|
41
41
|
let i = { ...e };
|
|
42
42
|
for (let e of r) {
|
|
@@ -44,9 +44,9 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = 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
|
+
}, Ar = (e, t, n) => {
|
|
48
|
+
if (!Dr(n) || !t) return e;
|
|
49
|
+
let r = Or(t);
|
|
50
50
|
return r.length === 0 ? e : e.map((e) => {
|
|
51
51
|
let t;
|
|
52
52
|
for (let n of r) {
|
|
@@ -58,13 +58,13 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
58
58
|
}
|
|
59
59
|
return t ?? e;
|
|
60
60
|
});
|
|
61
|
-
},
|
|
61
|
+
}, jr = "enc:v1:", Mr = "enc:v2:", Nr = (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
|
+
}, Pr = (e) => typeof e == "string" && e.startsWith("enc:v2:"), Fr = class extends Error {
|
|
68
68
|
_tag = "FieldDecryptionError";
|
|
69
69
|
table;
|
|
70
70
|
column;
|
|
@@ -72,7 +72,7 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = 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
|
+
}, Ir = (e) => typeof e == "object" && !!e && e._tag === "FieldDecryptionError", Lr = (e) => typeof e == "string" && (e.startsWith("enc:v1:") || e.startsWith("enc:v2:")), Rr = (e, t, n) => e.encrypt(JSON.stringify(t), n), zr = /* @__PURE__ */ new Set([
|
|
76
76
|
"text",
|
|
77
77
|
"id",
|
|
78
78
|
"reference",
|
|
@@ -80,51 +80,51 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
80
80
|
"uuid",
|
|
81
81
|
"email",
|
|
82
82
|
"url"
|
|
83
|
-
]),
|
|
83
|
+
]), Br = (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 || zr.has(n) ? i : a;
|
|
91
|
+
}, Vr = (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 || zr.has(n) ? !0 : void 0;
|
|
95
95
|
} catch {
|
|
96
96
|
return !0;
|
|
97
97
|
}
|
|
98
|
-
},
|
|
98
|
+
}, Hr = (e, t) => e.fields[t]?.type, Ur = (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
|
+
}, Wr = "id", Gr = (e, t, n, r) => {
|
|
103
103
|
if (!t) return e;
|
|
104
|
-
let i =
|
|
104
|
+
let i = Ur(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[Wr], s = { ...e };
|
|
107
107
|
for (let e of i) {
|
|
108
108
|
let t = s[e];
|
|
109
|
-
if (!(t == null ||
|
|
109
|
+
if (!(t == null || Lr(t))) {
|
|
110
110
|
if (!n) throw Error(`column "${a}.${e}" is .encrypted() but no field cipher is registered — set VOLTRO_FIELD_ENCRYPTION_KEY (\`voltro dev\` mints one; \`voltro serve\` refuses to boot without it); in a test, pass \`fieldEncryptionKey\` to makeTestContext`);
|
|
111
|
-
s[e] =
|
|
111
|
+
s[e] = Rr(n, t, Nr(a, e, o));
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
return s;
|
|
115
|
-
},
|
|
115
|
+
}, Kr = (e, t, n, r) => {
|
|
116
116
|
if (!t) return e;
|
|
117
|
-
let i =
|
|
117
|
+
let i = Ur(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 (Lr(i)) {
|
|
125
125
|
s ??= { ...e };
|
|
126
126
|
try {
|
|
127
|
-
s[c] =
|
|
127
|
+
s[c] = Br(n, i, Hr(t, c), Nr(o, c, r?.rowId ?? e[Wr]));
|
|
128
128
|
} catch (e) {
|
|
129
129
|
let t = String(e?.message ?? e);
|
|
130
130
|
if (a === "null") {
|
|
@@ -135,7 +135,7 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
135
135
|
});
|
|
136
136
|
continue;
|
|
137
137
|
}
|
|
138
|
-
throw new
|
|
138
|
+
throw new Fr({
|
|
139
139
|
table: o,
|
|
140
140
|
column: c,
|
|
141
141
|
reason: t
|
|
@@ -145,77 +145,77 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
145
145
|
}
|
|
146
146
|
return s ?? e;
|
|
147
147
|
});
|
|
148
|
-
},
|
|
149
|
-
let t =
|
|
150
|
-
return Object.defineProperty(t,
|
|
148
|
+
}, qr = Symbol.for("@voltro/database/storeRefusal"), Jr = (e) => {
|
|
149
|
+
let t = y(e.detail);
|
|
150
|
+
return Object.defineProperty(t, qr, {
|
|
151
151
|
value: e,
|
|
152
152
|
enumerable: !1
|
|
153
153
|
}), t;
|
|
154
|
-
},
|
|
155
|
-
for (let t of
|
|
154
|
+
}, Yr = (e) => {
|
|
155
|
+
for (let t of tt(e)) {
|
|
156
156
|
let e = t;
|
|
157
157
|
for (let t = 0; e != null && t < 8; t += 1) {
|
|
158
|
-
let t = e[
|
|
158
|
+
let t = e[qr];
|
|
159
159
|
if (t !== void 0) return t;
|
|
160
160
|
e = e.cause;
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
|
-
},
|
|
163
|
+
}, Xr = (e) => {
|
|
164
164
|
let t = (() => {
|
|
165
165
|
switch (e.type) {
|
|
166
|
-
case "id": return e.idScheme?.kind === "numeric" ?
|
|
166
|
+
case "id": return e.idScheme?.kind === "numeric" ? k.Number : k.String;
|
|
167
167
|
case "text":
|
|
168
|
-
case "enum": return
|
|
169
|
-
case "reference": return e.referenceStorage === "numeric" ?
|
|
168
|
+
case "enum": return k.String;
|
|
169
|
+
case "reference": return e.referenceStorage === "numeric" ? k.Number : k.String;
|
|
170
170
|
case "integer":
|
|
171
171
|
case "real":
|
|
172
|
-
case "decimal": return
|
|
173
|
-
case "boolean": return
|
|
172
|
+
case "decimal": return k.Number;
|
|
173
|
+
case "boolean": return k.Boolean;
|
|
174
174
|
case "timestamp":
|
|
175
|
-
case "date": return
|
|
176
|
-
case "bigint": return
|
|
177
|
-
case "bytes": return
|
|
178
|
-
case "array": return
|
|
179
|
-
case "interval": return
|
|
180
|
-
default: return
|
|
175
|
+
case "date": return pr;
|
|
176
|
+
case "bigint": return k.BigInt;
|
|
177
|
+
case "bytes": return k.Uint8ArrayFromBase64;
|
|
178
|
+
case "array": return k.Array(k.Unknown);
|
|
179
|
+
case "interval": return k.String;
|
|
180
|
+
default: return k.Unknown;
|
|
181
181
|
}
|
|
182
182
|
})();
|
|
183
|
-
return e.nullable === !0 ?
|
|
184
|
-
},
|
|
183
|
+
return e.nullable === !0 ? k.NullOr(t) : t;
|
|
184
|
+
}, Zr = (e, t) => {
|
|
185
185
|
let n = new Set(t?.omit ?? []), r = {};
|
|
186
|
-
for (let [t, i] of Object.entries(e.fields)) n.has(t) || (r[t] =
|
|
187
|
-
return
|
|
188
|
-
},
|
|
186
|
+
for (let [t, i] of Object.entries(e.fields)) n.has(t) || (r[t] = Xr(i));
|
|
187
|
+
return k.Struct(r);
|
|
188
|
+
}, Qr = (e) => typeof e == "function" ? e : () => e, $r = (e, t) => ({
|
|
189
189
|
kind: "one",
|
|
190
|
-
target:
|
|
190
|
+
target: Qr(e),
|
|
191
191
|
...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
|
|
192
192
|
...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
|
|
193
|
-
}),
|
|
193
|
+
}), ei = (e, t) => ({
|
|
194
194
|
kind: "many",
|
|
195
|
-
target:
|
|
195
|
+
target: Qr(e),
|
|
196
196
|
...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
|
|
197
197
|
...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
|
|
198
|
-
}),
|
|
198
|
+
}), ti = (e, t) => ({
|
|
199
199
|
kind: "manyToMany",
|
|
200
|
-
target:
|
|
201
|
-
through:
|
|
200
|
+
target: Qr(e),
|
|
201
|
+
through: Qr(t.through),
|
|
202
202
|
sourceKey: t.sourceKey,
|
|
203
203
|
targetKey: t.targetKey
|
|
204
|
-
}),
|
|
205
|
-
one:
|
|
206
|
-
many:
|
|
207
|
-
manyToMany:
|
|
208
|
-
},
|
|
204
|
+
}), ni = {
|
|
205
|
+
one: $r,
|
|
206
|
+
many: ei,
|
|
207
|
+
manyToMany: ti
|
|
208
|
+
}, ri = (e, t) => {
|
|
209
209
|
let n = typeof e == "function" ? e : () => e;
|
|
210
210
|
return {
|
|
211
211
|
source: n,
|
|
212
|
-
relations: t(
|
|
212
|
+
relations: t(ni, n())
|
|
213
213
|
};
|
|
214
|
-
},
|
|
214
|
+
}, ii = (e) => {
|
|
215
215
|
if (typeof e != "object" || !e) return !1;
|
|
216
216
|
let t = e;
|
|
217
217
|
return typeof t.source != "function" || typeof t.relations != "object" || t.relations === null ? !1 : Object.keys(t.relations).length === 0;
|
|
218
|
-
},
|
|
218
|
+
}, ai = (e) => {
|
|
219
219
|
if (typeof e != "object" || !e) return !1;
|
|
220
220
|
let t = e;
|
|
221
221
|
if (typeof t.source != "function" || typeof t.relations != "object" || t.relations === null) return !1;
|
|
@@ -224,35 +224,35 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
224
224
|
let t = e?.kind;
|
|
225
225
|
return t === "one" || t === "many" || t === "manyToMany";
|
|
226
226
|
});
|
|
227
|
-
},
|
|
227
|
+
}, oi = $r, si = ei, ci = ti, li = (e, t, n) => {
|
|
228
228
|
let r = [];
|
|
229
229
|
for (let [n, i] of Object.entries(e.fields)) i.type === "reference" && i.references?.()?.tableName === t && r.push(n);
|
|
230
|
-
if (r.length === 0) throw
|
|
231
|
-
if (r.length > 1) throw
|
|
230
|
+
if (r.length === 0) throw y(`relation '${n}': no reference() column on '${e.tableName}' points at '${t}'. Either add one or pass an explicit { foreignKey: '<column>' }.`);
|
|
231
|
+
if (r.length > 1) throw y(`relation '${n}': multiple reference() columns on '${e.tableName}' point at '${t}' (${r.join(", ")}). Pass an explicit { foreignKey: '<column>' } to disambiguate.`);
|
|
232
232
|
return r[0];
|
|
233
|
-
},
|
|
234
|
-
let t =
|
|
233
|
+
}, ui = (e) => Object.keys(e.fields), di = (e, t) => Object.prototype.hasOwnProperty.call(e.fields, t), fi = (e) => {
|
|
234
|
+
let t = ui(e);
|
|
235
235
|
return t.length === 0 ? "<none>" : t.join(", ");
|
|
236
|
-
},
|
|
236
|
+
}, pi = (e, t, n) => {
|
|
237
237
|
let r = `relation '${t}' on '${e.tableName}'`, i = n.target();
|
|
238
238
|
if (n.kind === "manyToMany") {
|
|
239
239
|
let t = n.through();
|
|
240
|
-
for (let [a, o] of [["sourceKey", n.sourceKey], ["targetKey", n.targetKey]]) if (!
|
|
240
|
+
for (let [a, o] of [["sourceKey", n.sourceKey], ["targetKey", n.targetKey]]) if (!di(t, o)) throw y(`${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}': ${fi(t)}.`);
|
|
241
241
|
return;
|
|
242
242
|
}
|
|
243
|
-
if (n.sourceKey !== void 0 && n.foreignKey !== void 0) throw
|
|
244
|
-
if (n.sourceKey !== void 0 && !
|
|
245
|
-
let t =
|
|
246
|
-
throw
|
|
243
|
+
if (n.sourceKey !== void 0 && n.foreignKey !== void 0) throw y(`${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.`);
|
|
244
|
+
if (n.sourceKey !== void 0 && !di(e, n.sourceKey)) {
|
|
245
|
+
let t = di(i, n.sourceKey);
|
|
246
|
+
throw y(`${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}': ${fi(e)}.`));
|
|
247
247
|
}
|
|
248
|
-
if (n.foreignKey !== void 0 && !
|
|
249
|
-
let t =
|
|
250
|
-
throw
|
|
248
|
+
if (n.foreignKey !== void 0 && !di(i, n.foreignKey)) {
|
|
249
|
+
let t = di(e, n.foreignKey);
|
|
250
|
+
throw y(`${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}': ${fi(i)}.`));
|
|
251
251
|
}
|
|
252
|
-
},
|
|
253
|
-
let t = e.source(), n =
|
|
252
|
+
}, mi = Symbol.for("@voltro/database/relationsRegistry"), hi = globalThis, j = hi[mi] ?? (hi[mi] = /* @__PURE__ */ new Map()), gi = (e) => {
|
|
253
|
+
let t = e.source(), n = j.get(t.tableName);
|
|
254
254
|
if (n === void 0) {
|
|
255
|
-
|
|
255
|
+
j.set(t.tableName, new Map(Object.entries(e.relations)));
|
|
256
256
|
return;
|
|
257
257
|
}
|
|
258
258
|
for (let [r, i] of Object.entries(e.relations)) {
|
|
@@ -262,33 +262,33 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
262
262
|
n.set(r, i);
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
|
-
},
|
|
265
|
+
}, _i = (e) => {
|
|
266
266
|
let t = 0;
|
|
267
|
-
for (let n of Object.values(e))
|
|
267
|
+
for (let n of Object.values(e)) ai(n) && (gi(n), t += 1);
|
|
268
268
|
return t;
|
|
269
|
-
},
|
|
270
|
-
let t =
|
|
269
|
+
}, vi = (e) => {
|
|
270
|
+
let t = j.get(e);
|
|
271
271
|
if (t !== void 0) return Object.fromEntries(t);
|
|
272
|
-
},
|
|
272
|
+
}, yi = (e, t) => j.get(e)?.get(t), bi = () => {
|
|
273
273
|
let e = [];
|
|
274
|
-
for (let [t, n] of
|
|
274
|
+
for (let [t, n] of j) for (let [r, i] of n) e.push({
|
|
275
275
|
source: t,
|
|
276
276
|
name: r,
|
|
277
277
|
relation: i
|
|
278
278
|
});
|
|
279
279
|
return e;
|
|
280
|
-
},
|
|
281
|
-
for (let [e, t] of
|
|
282
|
-
let n =
|
|
283
|
-
if (n !== void 0) for (let [e, r] of t)
|
|
284
|
-
}
|
|
285
|
-
},
|
|
286
|
-
|
|
287
|
-
},
|
|
280
|
+
}, xi = () => {
|
|
281
|
+
for (let [e, t] of j) {
|
|
282
|
+
let n = ln(e);
|
|
283
|
+
if (n !== void 0) for (let [e, r] of t) pi(n, e, r);
|
|
284
|
+
}
|
|
285
|
+
}, Si = () => {
|
|
286
|
+
j.clear();
|
|
287
|
+
}, Ci = 4, wi = (e) => Object.keys(e.fields), Ti = (e, t) => Object.prototype.hasOwnProperty.call(e.fields, t), Ei = (e, t) => {
|
|
288
288
|
let n = [];
|
|
289
289
|
for (let [r, i] of Object.entries(e.fields)) i.type === "reference" && i.references?.()?.tableName === t && n.push(r);
|
|
290
290
|
return n;
|
|
291
|
-
},
|
|
291
|
+
}, Di = (e, t) => {
|
|
292
292
|
let n = [];
|
|
293
293
|
for (let r of t) {
|
|
294
294
|
if (r.source !== e) continue;
|
|
@@ -305,7 +305,7 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
305
305
|
} catch {
|
|
306
306
|
continue;
|
|
307
307
|
}
|
|
308
|
-
if (!
|
|
308
|
+
if (!Ti(e, t.sourceKey)) continue;
|
|
309
309
|
n.push({
|
|
310
310
|
table: e.tableName,
|
|
311
311
|
foreignKey: t.sourceKey,
|
|
@@ -314,8 +314,8 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
314
314
|
continue;
|
|
315
315
|
}
|
|
316
316
|
if (t.sourceKey !== void 0) continue;
|
|
317
|
-
let a =
|
|
318
|
-
if (o === void 0 || !
|
|
317
|
+
let a = Ei(i, e), o = t.foreignKey ?? (a.length === 1 ? a[0] : void 0);
|
|
318
|
+
if (o === void 0 || !Ti(i, o)) continue;
|
|
319
319
|
let s = i.fields[o];
|
|
320
320
|
n.push({
|
|
321
321
|
table: i.tableName,
|
|
@@ -324,9 +324,9 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
324
324
|
});
|
|
325
325
|
}
|
|
326
326
|
return n;
|
|
327
|
-
},
|
|
327
|
+
}, Oi = (e, t) => {
|
|
328
328
|
let n = [];
|
|
329
|
-
for (let r of t) if (r.tableName !== e) for (let t of
|
|
329
|
+
for (let r of t) if (r.tableName !== e) for (let t of Ei(r, e)) {
|
|
330
330
|
let e = r.fields[t];
|
|
331
331
|
n.push({
|
|
332
332
|
table: r.tableName,
|
|
@@ -335,8 +335,8 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
335
335
|
});
|
|
336
336
|
}
|
|
337
337
|
return n;
|
|
338
|
-
},
|
|
339
|
-
let t = e.tables ??
|
|
338
|
+
}, ki = (e) => `${e.table}\u0000${e.hops.map((e) => `${e.table}.${e.foreignKey}<-${e.parentKey}`).join("|")}`, Ai = (e) => {
|
|
339
|
+
let t = e.tables ?? Ot(), n = e.relations ?? bi(), r = e.maxDepth ?? 4, i = new Set(e.exclude ?? []), a = new Map(t.map((e) => [e.tableName, e])), o = [];
|
|
340
340
|
if (!a.has(e.subjectTable)) return {
|
|
341
341
|
subjectTable: e.subjectTable,
|
|
342
342
|
paths: [],
|
|
@@ -351,11 +351,11 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
351
351
|
hops: [],
|
|
352
352
|
depth: 0,
|
|
353
353
|
via: "relation"
|
|
354
|
-
}, c = [s], l = /* @__PURE__ */ new Set([
|
|
354
|
+
}, c = [s], l = /* @__PURE__ */ new Set([ki(s)]), u = /* @__PURE__ */ new Set(), d = [s];
|
|
355
355
|
for (let e = 1; e <= r; e++) {
|
|
356
356
|
let r = [];
|
|
357
357
|
for (let a of d) {
|
|
358
|
-
let s =
|
|
358
|
+
let s = Di(a.table, n), d = Oi(a.table, t), f = [...s.map((e) => [e, "relation"]), ...d.map((e) => [e, "reference"])];
|
|
359
359
|
for (let [t, n] of f) {
|
|
360
360
|
if (i.has(t.table)) {
|
|
361
361
|
o.push({
|
|
@@ -373,7 +373,7 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
373
373
|
hops: [...a.hops, t],
|
|
374
374
|
depth: e,
|
|
375
375
|
via: n
|
|
376
|
-
}, f =
|
|
376
|
+
}, f = ki(d);
|
|
377
377
|
l.has(f) || (l.add(f), c.push(d), r.push(d));
|
|
378
378
|
}
|
|
379
379
|
}
|
|
@@ -383,7 +383,7 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
383
383
|
}
|
|
384
384
|
d = r;
|
|
385
385
|
}
|
|
386
|
-
for (let e of d) (
|
|
386
|
+
for (let e of d) (Di(e.table, n).length > 0 || Oi(e.table, t).length > 0) && o.push({
|
|
387
387
|
kind: "depth-truncated",
|
|
388
388
|
table: e.table,
|
|
389
389
|
detail: `stopped at maxDepth ${r}; tables linked FROM '${e.table}' were not explored`
|
|
@@ -392,14 +392,14 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
392
392
|
for (let n of t) f.has(n.tableName) || i.has(n.tableName) || o.push({
|
|
393
393
|
kind: "unreachable",
|
|
394
394
|
table: n.tableName,
|
|
395
|
-
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: ${
|
|
395
|
+
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: ${wi(n).join(", ")}`
|
|
396
396
|
});
|
|
397
397
|
return {
|
|
398
398
|
subjectTable: e.subjectTable,
|
|
399
399
|
paths: c,
|
|
400
400
|
limitations: o
|
|
401
401
|
};
|
|
402
|
-
},
|
|
402
|
+
}, ji = (e) => {
|
|
403
403
|
let t = [`subject graph · ${e.subjectTable} · ${e.paths.length} table(s) reachable`];
|
|
404
404
|
for (let n of e.paths) {
|
|
405
405
|
let r = n.hops.length === 0 ? `${e.subjectTable} (the subject row itself)` : [e.subjectTable, ...n.hops.map((e) => `${e.table}.${e.foreignKey}`)].join(" → ");
|
|
@@ -407,12 +407,12 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
407
407
|
}
|
|
408
408
|
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");
|
|
409
409
|
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");
|
|
410
|
-
},
|
|
410
|
+
}, Mi = (e) => Object.fromEntries(Object.entries(e.updateValues ?? {}).filter(([t, n]) => {
|
|
411
411
|
if (n === void 0) return !1;
|
|
412
|
-
if (t === "id" || e.conflictColumns.includes(t)) throw
|
|
412
|
+
if (t === "id" || e.conflictColumns.includes(t)) throw y(`upsert: updateValues cannot rewrite row identity column '${t}'`);
|
|
413
413
|
return !0;
|
|
414
|
-
})),
|
|
415
|
-
let r =
|
|
414
|
+
})), Ni = (e, t, n) => {
|
|
415
|
+
let r = Mi(n);
|
|
416
416
|
if (typeof n.update == "function") return {
|
|
417
417
|
...n.update(t),
|
|
418
418
|
...r
|
|
@@ -422,21 +422,21 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
422
422
|
...Object.fromEntries(i.filter((t) => t in e).map((t) => [t, e[t]])),
|
|
423
423
|
...r
|
|
424
424
|
};
|
|
425
|
-
},
|
|
425
|
+
}, Pi = (e) => typeof e == "string" ? [["id", e]] : Object.entries(e).map(([e, t]) => [e, t]), Fi = (e) => {
|
|
426
426
|
if (typeof e == "string") return e;
|
|
427
427
|
let t = Object.entries(e);
|
|
428
428
|
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");
|
|
429
|
-
},
|
|
430
|
-
let r = new Set(
|
|
429
|
+
}, Ii = (e) => typeof e != "string", Li = (e, t, n) => {
|
|
430
|
+
let r = new Set(Pi(e).map(([e]) => e)), i = t.split(".")[0];
|
|
431
431
|
return Object.fromEntries(Object.entries(n ?? {}).filter(([e, t]) => {
|
|
432
432
|
if (t === void 0) return !1;
|
|
433
|
-
if (r.has(e) || e === i) throw
|
|
433
|
+
if (r.has(e) || e === i) throw y(`patchJson: additionalPatch cannot rewrite the primary key or patched JSON column '${e}'`);
|
|
434
434
|
return !0;
|
|
435
435
|
}));
|
|
436
|
-
},
|
|
437
|
-
let [r, ...i] = t.split("."), a =
|
|
436
|
+
}, Ri = (e) => typeof e == "object" && !!e && !Array.isArray(e), zi = (e) => JSON.parse(JSON.stringify(e ?? null)), Bi = (e, t, n) => {
|
|
437
|
+
let [r, ...i] = t.split("."), a = zi(n), o = e[r], s = (e, t) => {
|
|
438
438
|
if (t === i.length) return a;
|
|
439
|
-
let n =
|
|
439
|
+
let n = Ri(e) ? e : {}, r = i[t], o = Object.hasOwn(n, r) ? n[r] : void 0;
|
|
440
440
|
return {
|
|
441
441
|
...n,
|
|
442
442
|
[r]: s(o, t + 1)
|
|
@@ -444,14 +444,14 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
444
444
|
};
|
|
445
445
|
return {
|
|
446
446
|
...e,
|
|
447
|
-
[r]: i.length === 0 ?
|
|
447
|
+
[r]: i.length === 0 ? Ri(o) && Ri(a) ? {
|
|
448
448
|
...o,
|
|
449
449
|
...a
|
|
450
450
|
} : a : s(o, 0)
|
|
451
451
|
};
|
|
452
|
-
},
|
|
453
|
-
let [a, ...o] = n.split("."), s = i ?? e`${e(a)}`, c =
|
|
454
|
-
if ((t === "sqlite" || t === "turso") && (o.some(l) || o.length === 0 &&
|
|
452
|
+
}, Vi = (e, t, n, r, i) => {
|
|
453
|
+
let [a, ...o] = n.split("."), s = i ?? e`${e(a)}`, c = zi(r), l = (e) => /["\\\u0000-\u001f]/.test(e);
|
|
454
|
+
if ((t === "sqlite" || t === "turso") && (o.some(l) || o.length === 0 && Ri(c) && Object.keys(c).some(l))) {
|
|
455
455
|
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`}
|
|
456
456
|
THEN json_extract('"' || replace(${t}.key, '"', ${String.raw`\"`}) || '"', '$')
|
|
457
457
|
ELSE ${t}.key END`, r = (r) => {
|
|
@@ -493,7 +493,7 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
493
493
|
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}))`;
|
|
494
494
|
}, v;
|
|
495
495
|
if (o.length === 0) {
|
|
496
|
-
if (!
|
|
496
|
+
if (!Ri(c)) v = g(c);
|
|
497
497
|
else {
|
|
498
498
|
v = h([]);
|
|
499
499
|
for (let [e, t] of Object.entries(c)) v = _(v, [e], g(t), t);
|
|
@@ -507,55 +507,55 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
507
507
|
v = _(v, o, g(c), c);
|
|
508
508
|
}
|
|
509
509
|
return e`${e(a)} = ${v}`;
|
|
510
|
-
},
|
|
510
|
+
}, Hi = class extends Error {
|
|
511
511
|
_tag = "EagerCardinalityError";
|
|
512
512
|
constructor(e) {
|
|
513
513
|
super(e), this.name = "EagerCardinalityError";
|
|
514
514
|
}
|
|
515
|
-
},
|
|
515
|
+
}, Ui = (e) => {
|
|
516
516
|
let { relationName: t, sourceTableName: n, targetTableName: r, foreignKey: i, sourceKey: a } = e, o = r === n;
|
|
517
517
|
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.");
|
|
518
|
-
},
|
|
518
|
+
}, Wi = async (e, t, n, r) => {
|
|
519
519
|
if (e.length === 0) return e;
|
|
520
|
-
let i =
|
|
521
|
-
if (i === void 0) throw
|
|
520
|
+
let i = vi(n.tableName);
|
|
521
|
+
if (i === void 0) throw y(`cannot eager-load on '${n.tableName}': no relations registered. Did you forget to declare \`relations(${n.tableName}, ...)\` or import the file that does?`);
|
|
522
522
|
let a = e.map((e) => ({ ...e }));
|
|
523
523
|
for (let [e, o] of Object.entries(t)) {
|
|
524
524
|
let t = i[e];
|
|
525
525
|
if (t === void 0) {
|
|
526
526
|
let t = Object.keys(i).join(", ") || "<none>";
|
|
527
|
-
throw
|
|
527
|
+
throw y(`unknown relation '${e}' on '${n.tableName}'. Registered relations: ${t}.`);
|
|
528
528
|
}
|
|
529
|
-
|
|
529
|
+
pi(n, e, t), await Gi(a, e, t, o === !0 ? {} : o, n, r);
|
|
530
530
|
}
|
|
531
531
|
return a;
|
|
532
|
-
},
|
|
532
|
+
}, Gi = async (e, t, n, r, i, a) => {
|
|
533
533
|
switch (n.kind) {
|
|
534
534
|
case "one":
|
|
535
|
-
await
|
|
535
|
+
await Ki(e, t, n, r, i, a);
|
|
536
536
|
return;
|
|
537
537
|
case "many":
|
|
538
|
-
await
|
|
538
|
+
await qi(e, t, n, r, i, a);
|
|
539
539
|
return;
|
|
540
540
|
case "manyToMany":
|
|
541
|
-
await
|
|
541
|
+
await Yi(e, t, n, r, i, a);
|
|
542
542
|
return;
|
|
543
543
|
}
|
|
544
|
-
},
|
|
545
|
-
let o = n.target(), s = n.sourceKey ??
|
|
544
|
+
}, Ki = async (e, t, n, r, i, a) => {
|
|
545
|
+
let o = n.target(), s = n.sourceKey ?? Xi(i, o.tableName);
|
|
546
546
|
if (s !== void 0) {
|
|
547
|
-
let n =
|
|
547
|
+
let n = M(e, s), i = n.length === 0 ? [] : await Zi(o, "id", n, r, a), c = new Map(i.map((e) => [e.id, e]));
|
|
548
548
|
for (let n of e) {
|
|
549
549
|
let e = n[s];
|
|
550
550
|
n[t] = e == null ? null : c.get(e) ?? null;
|
|
551
551
|
}
|
|
552
|
-
await
|
|
552
|
+
await Qi(i, r.with, o, a);
|
|
553
553
|
return;
|
|
554
554
|
}
|
|
555
|
-
let c = n.foreignKey ??
|
|
555
|
+
let c = n.foreignKey ?? li(o, i.tableName, t), l = n.sourceKey ?? "id", u = M(e, l), d = u.length === 0 ? [] : await Zi(o, c, u, r, a), f = /* @__PURE__ */ new Map();
|
|
556
556
|
for (let e of d) {
|
|
557
557
|
let n = e[c];
|
|
558
|
-
if (f.has(n)) throw new
|
|
558
|
+
if (f.has(n)) throw new Hi(Ui({
|
|
559
559
|
relationName: t,
|
|
560
560
|
sourceTableName: i.tableName,
|
|
561
561
|
targetTableName: o.tableName,
|
|
@@ -568,9 +568,9 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
568
568
|
let e = n[l];
|
|
569
569
|
n[t] = e == null ? null : f.get(e) ?? null;
|
|
570
570
|
}
|
|
571
|
-
await
|
|
572
|
-
},
|
|
573
|
-
let o = n.target(), s = n.foreignKey ??
|
|
571
|
+
await Qi(d, r.with, o, a);
|
|
572
|
+
}, qi = async (e, t, n, r, i, a) => {
|
|
573
|
+
let o = n.target(), s = n.foreignKey ?? li(o, i.tableName, t), c = n.sourceKey ?? "id", l = M(e, c), u = Ji(r), d = l.length === 0 ? [] : await Zi(o, s, l, u, a), f = /* @__PURE__ */ new Map();
|
|
574
574
|
for (let e of d) {
|
|
575
575
|
let t = e[s], n = f.get(t);
|
|
576
576
|
n ? n.push(e) : f.set(t, [e]);
|
|
@@ -586,12 +586,12 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
586
586
|
let e = n[c];
|
|
587
587
|
n[t] = f.get(e) ?? [];
|
|
588
588
|
}
|
|
589
|
-
await
|
|
590
|
-
},
|
|
589
|
+
await Qi(d, r.with, o, a);
|
|
590
|
+
}, Ji = (e) => {
|
|
591
591
|
let { limit: t, offset: n, ...r } = e;
|
|
592
592
|
return r;
|
|
593
|
-
},
|
|
594
|
-
let o = n.target(), s = n.through(), c =
|
|
593
|
+
}, Yi = async (e, t, n, r, i, a) => {
|
|
594
|
+
let o = n.target(), s = n.through(), c = M(e, "id");
|
|
595
595
|
if (c.length === 0) {
|
|
596
596
|
for (let n of e) n[t] = [];
|
|
597
597
|
return;
|
|
@@ -612,8 +612,8 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
612
612
|
for (let n of e) n[t] = [];
|
|
613
613
|
return;
|
|
614
614
|
}
|
|
615
|
-
let f = await
|
|
616
|
-
await
|
|
615
|
+
let f = await Zi(o, "id", M(d, n.targetKey), r, a), p = new Map(f.map((e) => [e.id, e]));
|
|
616
|
+
await Qi(f, r.with, o, a);
|
|
617
617
|
let m = r.junction === void 0 ? void 0 : r.junction === !0 ? Object.keys(s.fields) : r.junction, h = /* @__PURE__ */ new Map();
|
|
618
618
|
for (let e of d) {
|
|
619
619
|
let t = e[n.sourceKey], r = e[n.targetKey], i = p.get(r);
|
|
@@ -625,16 +625,16 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
625
625
|
o ? o.push(a) : h.set(t, [a]);
|
|
626
626
|
}
|
|
627
627
|
for (let n of e) n[t] = h.get(n.id) ?? [];
|
|
628
|
-
},
|
|
628
|
+
}, Xi = (e, t) => {
|
|
629
629
|
for (let [n, r] of Object.entries(e.fields)) if (r.type === "reference" && r.references?.()?.tableName === t) return n;
|
|
630
|
-
},
|
|
630
|
+
}, M = (e, t) => {
|
|
631
631
|
let n = /* @__PURE__ */ new Set();
|
|
632
632
|
for (let r of e) {
|
|
633
633
|
let e = r[t];
|
|
634
634
|
e != null && n.add(e);
|
|
635
635
|
}
|
|
636
636
|
return [...n];
|
|
637
|
-
},
|
|
637
|
+
}, Zi = (e, t, n, r, i) => {
|
|
638
638
|
let a = {
|
|
639
639
|
column: t,
|
|
640
640
|
op: "in",
|
|
@@ -648,284 +648,34 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
648
648
|
skip: r.offset,
|
|
649
649
|
projection: void 0
|
|
650
650
|
});
|
|
651
|
-
},
|
|
652
|
-
t !== void 0 && e.length !== 0 && (await
|
|
651
|
+
}, Qi = async (e, t, n, r) => {
|
|
652
|
+
t !== void 0 && e.length !== 0 && (await Wi(e, t, n, r)).forEach((t, n) => {
|
|
653
653
|
let r = e[n];
|
|
654
654
|
for (let [e, n] of Object.entries(t)) e in r || (r[e] = n);
|
|
655
655
|
});
|
|
656
|
-
},
|
|
657
|
-
_tag = "TenantNamespaceUnresolved";
|
|
658
|
-
constructor(e) {
|
|
659
|
-
super(e), this.name = "TenantNamespaceUnresolved";
|
|
660
|
-
}
|
|
661
|
-
}, Ni = class extends Error {
|
|
662
|
-
_tag = "TenantNamespaceInvalid";
|
|
663
|
-
constructor(e) {
|
|
664
|
-
super(e), this.name = "TenantNamespaceInvalid";
|
|
665
|
-
}
|
|
666
|
-
}, Pi = 63, Fi = "tenant_", Ii = (e) => e.toLowerCase().replace(/[^a-z0-9_]/g, "_"), Li = (e) => {
|
|
667
|
-
if (e == null || e === "") throw new Mi("namespace isolation is on but the request has no resolvable tenant (subject.tenantId is null/empty). Refusing to run against a shared/default namespace — this would be a cross-tenant read. Authenticate with a tenant-scoped subject, or disable namespace isolation for this surface.");
|
|
668
|
-
let t = Ii(e);
|
|
669
|
-
if (t.replace(/_/g, "") === "") throw new Ni(`tenant id '${e}' has no usable identifier characters after sanitisation — cannot derive a distinct namespace.`);
|
|
670
|
-
let n = `${Fi}${t}`;
|
|
671
|
-
if (n.length > Pi) throw new Ni(`namespace '${n}' for tenant '${e}' exceeds the ${Pi}-byte identifier limit. Use a shorter tenant id.`);
|
|
672
|
-
return n;
|
|
673
|
-
}, Ri = (e, t) => e === null ? t : `${e}.${t}`, zi = /* @__PURE__ */ new Set(["timestamp", "date"]), Bi = /^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2})?/, Vi = (e, t) => {
|
|
674
|
-
if (e === void 0 || t == null || !zi.has(e) || t instanceof Date) return t;
|
|
675
|
-
if (typeof t == "number" && Number.isFinite(t)) return new Date(t);
|
|
676
|
-
if (typeof t == "string" && Bi.test(t)) {
|
|
677
|
-
let e = new Date(t);
|
|
678
|
-
return Number.isNaN(e.getTime()) ? t : e;
|
|
679
|
-
}
|
|
680
|
-
return t;
|
|
681
|
-
}, Hi = (e, t) => e === void 0 || !zi.has(e) ? t : t.map((t) => Vi(e, t)), Ui = (e, t) => {
|
|
682
|
-
let { strings: n, values: r } = e, i = t.unsafe(n[0] ?? "");
|
|
683
|
-
for (let e = 0; e < r.length; e++) i = t`${i}${r[e]}${t.unsafe(n[e + 1] ?? "")}`;
|
|
684
|
-
return t`${i}`;
|
|
685
|
-
}, P = (e) => e.replace(/[\\%_]/g, (e) => `\\${e}`), F = (e, t, n = null, r) => {
|
|
686
|
-
if ("not" in e) return t`NOT (${F(e.not, t, n, r)})`;
|
|
687
|
-
if ("and" in e) return e.and.length === 0 ? t`TRUE` : t.and(e.and.map((e) => F(e, t, n, r)));
|
|
688
|
-
if ("or" in e) return e.or.length === 0 ? t`FALSE` : t.or(e.or.map((e) => F(e, t, n, r)));
|
|
689
|
-
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
690
|
-
let r = e, i = I(r.subquery, t, n);
|
|
691
|
-
return r.op === "subquery-in" ? t`${t(r.column)} IN (${i})` : t`${t(r.column)} NOT IN (${i})`;
|
|
692
|
-
}
|
|
693
|
-
if (e.op === "exists" || e.op === "not-exists") {
|
|
694
|
-
let r = e, i = I(r.subquery, t, n);
|
|
695
|
-
return r.op === "exists" ? t`EXISTS (${i})` : t`NOT EXISTS (${i})`;
|
|
696
|
-
}
|
|
697
|
-
let i = e, a = t(i.column), o = i.path, s = o !== void 0 && o.length > 0, c = () => t.onDialectOrElse({
|
|
698
|
-
mysql: () => t.unsafe(C(i.column, o, "mysql")),
|
|
699
|
-
mssql: () => t.unsafe(C(i.column, o, "mssql")),
|
|
700
|
-
sqlite: () => t.unsafe(C(i.column, o, "sqlite")),
|
|
701
|
-
orElse: () => t.unsafe(C(i.column, o, "postgres"))
|
|
702
|
-
}), l = () => t.onDialectOrElse({
|
|
703
|
-
mysql: () => t.unsafe(C(i.column, o, "mysql", { numeric: !0 })),
|
|
704
|
-
mssql: () => t.unsafe(C(i.column, o, "mssql", { numeric: !0 })),
|
|
705
|
-
sqlite: () => t.unsafe(C(i.column, o, "sqlite", { numeric: !0 })),
|
|
706
|
-
orElse: () => t.unsafe(C(i.column, o, "postgres", { numeric: !0 }))
|
|
707
|
-
}), u = s ? c() : a, d = s ? l() : a, f = (e) => s && e != null ? String(e) : e, p = (e) => s ? Number(e) : e, m = s || r === void 0 ? void 0 : cn(r)?.fields?.[i.column]?.type, h = (e) => Vi(m, e);
|
|
708
|
-
switch (i.op) {
|
|
709
|
-
case "eq": return t`${u} = ${f(h(i.value))}`;
|
|
710
|
-
case "neq": return t`${u} <> ${f(h(i.value))}`;
|
|
711
|
-
case "gt": return t`${d} > ${p(i.value)}`;
|
|
712
|
-
case "gte": return t`${d} >= ${p(i.value)}`;
|
|
713
|
-
case "lt": return t`${d} < ${p(i.value)}`;
|
|
714
|
-
case "lte": return t`${d} <= ${p(i.value)}`;
|
|
715
|
-
case "in": {
|
|
716
|
-
let e = i.value ?? [];
|
|
717
|
-
return e.length === 0 ? t`FALSE` : t`${u} IN ${t.in(s ? e.map((e) => f(e)) : e)}`;
|
|
718
|
-
}
|
|
719
|
-
case "notIn": {
|
|
720
|
-
let e = i.value ?? [];
|
|
721
|
-
return e.length === 0 ? t`TRUE` : t`${u} NOT IN ${t.in(s ? e.map((e) => f(e)) : e)}`;
|
|
722
|
-
}
|
|
723
|
-
case "contains": {
|
|
724
|
-
let e = `%${P(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
|
|
725
|
-
return t.onDialectOrElse({
|
|
726
|
-
mysql: () => t`LOWER(${u}) LIKE LOWER(${e})`,
|
|
727
|
-
mssql: () => t`LOWER(${u}) LIKE LOWER(${e})`,
|
|
728
|
-
sqlite: () => t`LOWER(${u}) LIKE LOWER(${e})`,
|
|
729
|
-
orElse: () => t`${u} ILIKE ${e} ESCAPE '\\'`
|
|
730
|
-
});
|
|
731
|
-
}
|
|
732
|
-
case "startsWith": {
|
|
733
|
-
let e = `${P(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
|
|
734
|
-
return t.onDialectOrElse({
|
|
735
|
-
mysql: () => t`${u} LIKE ${e}`,
|
|
736
|
-
orElse: () => t`${u} LIKE ${e} ESCAPE '\\'`
|
|
737
|
-
});
|
|
738
|
-
}
|
|
739
|
-
case "arrayContains": {
|
|
740
|
-
let e = i.value ?? [];
|
|
741
|
-
return e.length === 0 ? t`TRUE` : t.onDialectOrElse({
|
|
742
|
-
mysql: () => t`JSON_CONTAINS(${u}, ${JSON.stringify(e)})`,
|
|
743
|
-
mssql: () => t`(SELECT COUNT(DISTINCT value) FROM OPENJSON(${u}) WHERE value IN ${t.in(e)}) = ${e.length}`,
|
|
744
|
-
sqlite: () => t`(SELECT COUNT(DISTINCT value) FROM json_each(${u}) WHERE value IN ${t.in(e)}) = ${e.length}`,
|
|
745
|
-
orElse: () => t`${u} @> ${e}`
|
|
746
|
-
});
|
|
747
|
-
}
|
|
748
|
-
case "arrayOverlaps": {
|
|
749
|
-
let e = i.value ?? [];
|
|
750
|
-
return e.length === 0 ? t`FALSE` : t.onDialectOrElse({
|
|
751
|
-
mysql: () => t.or(e.map((e) => t`JSON_CONTAINS(${u}, ${JSON.stringify(e)})`)),
|
|
752
|
-
mssql: () => t`EXISTS (SELECT 1 FROM OPENJSON(${u}) WHERE value IN ${t.in(e)})`,
|
|
753
|
-
sqlite: () => t`EXISTS (SELECT 1 FROM json_each(${u}) WHERE value IN ${t.in(e)})`,
|
|
754
|
-
orElse: () => t`${u} && ${e}`
|
|
755
|
-
});
|
|
756
|
-
}
|
|
757
|
-
case "arrayHas": return t.onDialectOrElse({
|
|
758
|
-
mysql: () => t`JSON_CONTAINS(${u}, ${JSON.stringify(i.value)})`,
|
|
759
|
-
mssql: () => t`${i.value} IN (SELECT value FROM OPENJSON(${u}))`,
|
|
760
|
-
sqlite: () => t`EXISTS (SELECT 1 FROM json_each(${u}) WHERE value = ${i.value})`,
|
|
761
|
-
orElse: () => t`${i.value} = ANY(${u})`
|
|
762
|
-
});
|
|
763
|
-
case "isNull": return t`${u} IS NULL`;
|
|
764
|
-
case "isNotNull": return t`${u} IS NOT NULL`;
|
|
765
|
-
case "spatial": {
|
|
766
|
-
let e = i.value, n = t.unsafe("::geometry"), r = e.bufferMeters === void 0 ? t`${e.geom}${n}` : t`ST_Buffer(${e.geom}::geography, ${e.bufferMeters})::geometry`;
|
|
767
|
-
return t.onDialectOrElse({
|
|
768
|
-
mysql: () => {
|
|
769
|
-
throw Error("@voltro/plugin-postgis: spatial predicates are postgres-only");
|
|
770
|
-
},
|
|
771
|
-
mssql: () => {
|
|
772
|
-
throw Error("@voltro/plugin-postgis: spatial predicates are postgres-only");
|
|
773
|
-
},
|
|
774
|
-
sqlite: () => {
|
|
775
|
-
throw Error("@voltro/plugin-postgis: spatial predicates are postgres-only");
|
|
776
|
-
},
|
|
777
|
-
orElse: () => e.fn === "ST_DWithin" ? t`ST_DWithin(${a}::geography, ${e.geom}::geography, ${e.distanceMeters})` : e.fn === "&&" ? t`${a}${n} && ${r}` : t`${t.unsafe(e.fn)}(${a}${n}, ${r})`
|
|
778
|
-
});
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
}, Wi = (e, t) => {
|
|
782
|
-
let n = [];
|
|
783
|
-
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}`);
|
|
784
|
-
}, Gi = (e, t) => t.csv(e.map((e) => {
|
|
785
|
-
let n = e.column === void 0 ? t.unsafe("*") : t`${t(e.column)}`;
|
|
786
|
-
if (e.op.startsWith("window-")) {
|
|
787
|
-
let r = Wi(e.window ?? {}, t);
|
|
788
|
-
switch (e.op) {
|
|
789
|
-
case "window-row-number": return t`ROW_NUMBER() OVER (${r}) AS ${t(e.alias)}`;
|
|
790
|
-
case "window-rank": return t`RANK() OVER (${r}) AS ${t(e.alias)}`;
|
|
791
|
-
case "window-dense-rank": return t`DENSE_RANK() OVER (${r}) AS ${t(e.alias)}`;
|
|
792
|
-
case "window-lag": return t`LAG(${n}, ${t.unsafe(String(e.offset ?? 1))}) OVER (${r}) AS ${t(e.alias)}`;
|
|
793
|
-
case "window-lead": return t`LEAD(${n}, ${t.unsafe(String(e.offset ?? 1))}) OVER (${r}) AS ${t(e.alias)}`;
|
|
794
|
-
case "window-sum-over": return t`SUM(${n}) OVER (${r}) AS ${t(e.alias)}`;
|
|
795
|
-
case "window-avg-over": return t`AVG(${n}) OVER (${r}) AS ${t(e.alias)}`;
|
|
796
|
-
default: throw Error(`compileAggregateProjection: unknown window op '${e.op}'`);
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
switch (e.op) {
|
|
800
|
-
case "count": return t`COUNT(${n}) AS ${t(e.alias)}`;
|
|
801
|
-
case "count-distinct": return t`COUNT(DISTINCT ${n}) AS ${t(e.alias)}`;
|
|
802
|
-
case "sum": return t`SUM(${n}) AS ${t(e.alias)}`;
|
|
803
|
-
case "avg": return t`AVG(${n}) AS ${t(e.alias)}`;
|
|
804
|
-
case "min": return t`MIN(${n}) AS ${t(e.alias)}`;
|
|
805
|
-
case "max": return t`MAX(${n}) AS ${t(e.alias)}`;
|
|
806
|
-
case "column":
|
|
807
|
-
if (e.column === void 0) throw Error(`compileAggregateProjection: 'column' projection requires a column name (alias '${e.alias}')`);
|
|
808
|
-
return t`${t(e.column)} AS ${t(e.alias)}`;
|
|
809
|
-
default: throw Error(`compileAggregateProjection: unknown op '${e.op}'`);
|
|
810
|
-
}
|
|
811
|
-
})), Ki = (e) => `[${e.join(",")}]`, qi = (e, t) => {
|
|
812
|
-
if (e.queryVector === void 0) return null;
|
|
813
|
-
let n = t(e.column), r = Ki(e.queryVector), i = e.distance === "cosine" ? "<=>" : e.distance === "l2" ? "<->" : "<#>", a = e.distance === "cosine" ? "VEC_DISTANCE_COSINE" : "VEC_DISTANCE_EUCLIDEAN";
|
|
814
|
-
return t.onDialectOrElse({
|
|
815
|
-
mysql: () => t`${t.unsafe(a)}(${n}, ${r})`,
|
|
816
|
-
mssql: () => t`NULL`,
|
|
817
|
-
sqlite: () => t`NULL`,
|
|
818
|
-
orElse: () => t`${n} ${t.unsafe(i)} ${r}::vector`
|
|
819
|
-
});
|
|
820
|
-
}, Ji = (e, t) => {
|
|
821
|
-
let n = t.unsafe(e.useGeography ? "::geography" : "::geometry");
|
|
822
|
-
return t`ST_Distance(${t(e.column)}${n}, ${e.geom}${n})`;
|
|
823
|
-
}, Yi = (e, t) => t`${t(e.column)} <-> ${e.geom}::geometry`, Xi = (e, t) => t`${t(`${e.indexName}_tsv`)}`, Zi = (e, t) => `${t}_${e.indexName}_fts`, Qi = (e, t, n) => {
|
|
824
|
-
let r = n.csv(e.columns.map((e) => n`${n(e)}`)), i = `%${P(e.query)}%`;
|
|
825
|
-
return n.onDialectOrElse({
|
|
826
|
-
mysql: () => n`MATCH(${r}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
|
|
827
|
-
sqlite: () => {
|
|
828
|
-
let r = n(Zi(e, t));
|
|
829
|
-
return n`${n("id")} IN (SELECT ${n("row_id")} FROM ${r} WHERE ${r} MATCH ${e.query})`;
|
|
830
|
-
},
|
|
831
|
-
mssql: () => n.or(e.columns.map((e) => n`LOWER(${n(e)}) LIKE LOWER(${i}) ESCAPE '\\'`)),
|
|
832
|
-
orElse: () => n`${Xi(e, n)} @@ plainto_tsquery(${e.config ?? "english"}, ${e.query})`
|
|
833
|
-
});
|
|
834
|
-
}, $i = (e, t, n) => {
|
|
835
|
-
let r = `%${P(e.query)}%`;
|
|
836
|
-
return n.onDialectOrElse({
|
|
837
|
-
mysql: () => n`MATCH(${n.csv(e.columns.map((e) => n`${n(e)}`))}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
|
|
838
|
-
sqlite: () => {
|
|
839
|
-
let r = n(Zi(e, t));
|
|
840
|
-
return n`COALESCE((SELECT -bm25(${r}) FROM ${r} WHERE ${r} MATCH ${e.query} AND ${r}.${n("row_id")} = ${n("id")}), 0)`;
|
|
841
|
-
},
|
|
842
|
-
mssql: () => e.columns.map((e) => n`(CASE WHEN LOWER(${n(e)}) LIKE LOWER(${r}) ESCAPE '\\' THEN 1 ELSE 0 END)`).reduce((e, t, r) => r === 0 ? t : n`${e} + ${t}`),
|
|
843
|
-
orElse: () => n`ts_rank(${Xi(e, n)}, plainto_tsquery(${e.config ?? "english"}, ${e.query}))`
|
|
844
|
-
});
|
|
845
|
-
}, I = (e, t, n = null) => {
|
|
846
|
-
if (e.setOp && e.setOp.queries.length >= 2) {
|
|
847
|
-
let r = e.setOp.kind === "union" ? "UNION" : e.setOp.kind === "union-all" ? "UNION ALL" : e.setOp.kind === "intersect" ? "INTERSECT" : "EXCEPT", i = e.setOp.queries.map((e) => t`(${I(e, t, n)})`).reduce((e, n, i) => i === 0 ? n : t`${e} ${t.unsafe(r)} ${n}`), a = [];
|
|
848
|
-
if (x(e).length > 0 && a.push(t` ORDER BY ${t.csv(x(e).map((e) => e.direction === "desc" ? t`${t(e.column)} DESC` : t`${t(e.column)} ASC`))}`), e.take !== void 0) {
|
|
849
|
-
if (!Number.isInteger(e.take) || e.take < 0) throw Error(`compileSelect: invalid take ${e.take}`);
|
|
850
|
-
a.push(t` LIMIT ${t.unsafe(String(e.take))}`);
|
|
851
|
-
}
|
|
852
|
-
if (e.skip !== void 0) {
|
|
853
|
-
if (!Number.isInteger(e.skip) || e.skip < 0) throw Error(`compileSelect: invalid skip ${e.skip}`);
|
|
854
|
-
a.push(t` OFFSET ${t.unsafe(String(e.skip))}`);
|
|
855
|
-
}
|
|
856
|
-
return t`${i}${a.reduce((e, n) => t`${e}${n}`, t``)}`;
|
|
857
|
-
}
|
|
858
|
-
let r = e.annClause === void 0 ? null : qi(e.annClause, t);
|
|
859
|
-
e.spatialClause !== void 0 && t.onDialectOrElse({
|
|
860
|
-
mysql: () => {
|
|
861
|
-
throw Error("@voltro/plugin-postgis: spatial distance / KNN ordering is postgres-only");
|
|
862
|
-
},
|
|
863
|
-
mssql: () => {
|
|
864
|
-
throw Error("@voltro/plugin-postgis: spatial distance / KNN ordering is postgres-only");
|
|
865
|
-
},
|
|
866
|
-
sqlite: () => {
|
|
867
|
-
throw Error("@voltro/plugin-postgis: spatial distance / KNN ordering is postgres-only");
|
|
868
|
-
},
|
|
869
|
-
orElse: () => t``
|
|
870
|
-
});
|
|
871
|
-
let i = e.spatialClause?.projectAs === void 0 ? null : Ji(e.spatialClause, t), a = e.aggregations && e.aggregations.length > 0 ? Gi(e.aggregations, t) : e.joinedProjection && e.joinedProjection.length > 0 ? t.csv(e.joinedProjection.map((e) => t`${t(e.source)} AS ${t(e.outputKey)}`)) : e.projection && e.projection.length > 0 ? t.csv(e.projection.map((e) => t`${t(e)}`)) : t`*`, o = (e.aggregations && e.aggregations.length > 0) === !0, s = r !== null && !o ? t`${a}, ${r} AS ${t("distance")}` : a, c = e.fullTextSearch, l = c?.rank !== void 0 && !o ? $i(c, e.table, t) : null, u = l !== null && c?.rank !== void 0 ? t`${s}, ${l} AS ${t(c.rank.alias)}` : s, d = i !== null && !o && e.spatialClause?.projectAs !== void 0 ? t`${u}, ${i} AS ${t(e.spatialClause.projectAs)}` : u, f = e.distinctOn && e.distinctOn.length > 0 ? t.onDialectOrElse({
|
|
872
|
-
orElse: () => t`DISTINCT ON (${t.csv(e.distinctOn.map((e) => t`${t(e)}`))}) `,
|
|
873
|
-
mysql: () => t`DISTINCT `,
|
|
874
|
-
mssql: () => t`DISTINCT `,
|
|
875
|
-
sqlite: () => t`DISTINCT `
|
|
876
|
-
}) : e.distinct ? t`DISTINCT ` : t``, p = e.lock === "update", m = p ? t.onDialectOrElse({
|
|
877
|
-
mssql: () => t` WITH (UPDLOCK, ROWLOCK)`,
|
|
878
|
-
orElse: () => t``
|
|
879
|
-
}) : t``, h = p ? t.onDialectOrElse({
|
|
880
|
-
mssql: () => t``,
|
|
881
|
-
sqlite: () => t``,
|
|
882
|
-
orElse: () => t` FOR UPDATE`
|
|
883
|
-
}) : t``, g = e.alias === void 0 ? t`${t(Ri(n, e.table))}${m}` : t`${t(Ri(n, e.table))} AS ${t(e.alias)}${m}`, _ = (e.joins ?? []).map((e) => {
|
|
884
|
-
let r = e.kind === "inner" ? "INNER" : "LEFT";
|
|
885
|
-
return t` ${t.unsafe(r)} JOIN ${t(Ri(n, e.table))} AS ${t(e.alias)} ON ${F(e.on, t, n)}`;
|
|
886
|
-
}), v = _.length > 0 ? _.reduce((e, n) => t`${e}${n}`, g) : g, ee = c === void 0 ? null : Qi(c, e.table, t), te = [e.predicate ? F(e.predicate, t, n, e.table) : null, ee].filter((e) => e !== null), ne = te.length > 0 ? t` WHERE ${t.and(te)}` : t``, re = e.groupBy && e.groupBy.length > 0 ? t` GROUP BY ${t.csv(e.groupBy.map((e) => t`${t(e)}`))}` : t``, ie = e.having ? t` HAVING ${F(e.having, t, n, e.table)}` : t``, ae = e.skip !== void 0, y = [];
|
|
887
|
-
r !== null && y.push(t`${r} ASC`), e.spatialClause?.order !== void 0 && y.push(e.spatialClause.order === "desc" ? t`${Yi(e.spatialClause, t)} DESC` : t`${Yi(e.spatialClause, t)} ASC`), l !== null && c?.rank?.order === !0 && y.push(t`${l} DESC`);
|
|
888
|
-
for (let n of x(e)) y.push(n.direction === "desc" ? t`${t(n.column)} DESC` : t`${t(n.column)} ASC`);
|
|
889
|
-
let oe = y.length > 0 ? t` ORDER BY ${t.csv(y)}` : ae ? t.onDialectOrElse({
|
|
890
|
-
mssql: () => t` ORDER BY (SELECT NULL)`,
|
|
891
|
-
orElse: () => t``
|
|
892
|
-
}) : t``, b = (e) => {
|
|
893
|
-
if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw Error(`compileSelect: expected non-negative integer take/skip, got ${e}`);
|
|
894
|
-
return t.unsafe(String(e));
|
|
895
|
-
}, se = (e.ctes ?? []).map((e) => t`${t(e.name)} AS (${I(e.descriptor, t, n)})`), ce = (e.ctes ?? []).some((e) => e.recursive === !0), le = se.length > 0 ? t`WITH ${t.unsafe(ce ? "RECURSIVE " : "")}${t.csv(se)} ` : t``;
|
|
896
|
-
return t.onDialectOrElse({
|
|
897
|
-
mssql: () => {
|
|
898
|
-
let n = e.take !== void 0 && !ae ? t`TOP ${b(e.take)} ` : t``, r = ae ? t` OFFSET ${b(e.skip)} ROWS FETCH NEXT ${b(e.take ?? 2 ** 53 - 1)} ROWS ONLY` : t``;
|
|
899
|
-
return t`${le}SELECT ${n}${f}${d} FROM ${v}${ne}${re}${ie}${oe}${r}`;
|
|
900
|
-
},
|
|
901
|
-
orElse: () => {
|
|
902
|
-
let n = e.take === void 0 ? t`` : t` LIMIT ${b(e.take)}`, r = ae ? t` OFFSET ${b(e.skip)}` : t``;
|
|
903
|
-
return t`${le}SELECT ${f}${d} FROM ${v}${ne}${re}${ie}${oe}${n}${r}${h}`;
|
|
904
|
-
}
|
|
905
|
-
});
|
|
906
|
-
}, ea = (e, t, n) => {
|
|
656
|
+
}, $i = (e) => e.eager !== void 0 && Object.keys(e.eager).length > 0, ea = (e, t, n) => {
|
|
907
657
|
if (e.eager === void 0) return null;
|
|
908
|
-
let r =
|
|
658
|
+
let r = na(e.table, e.eager, e.sourceTable);
|
|
909
659
|
if (r === null) return null;
|
|
910
|
-
let i =
|
|
660
|
+
let i = la(n, e, r, ca(t, n));
|
|
911
661
|
return i === null ? null : {
|
|
912
662
|
fragment: i,
|
|
913
|
-
decode:
|
|
663
|
+
decode: fa(r, n)
|
|
914
664
|
};
|
|
915
|
-
},
|
|
665
|
+
}, N = (e) => e.relation.kind === "one" && e.fkSide === "target", ta = (e) => ({
|
|
916
666
|
...e,
|
|
917
667
|
branch: {
|
|
918
668
|
...e.branch,
|
|
919
669
|
limit: 2
|
|
920
670
|
}
|
|
921
|
-
}),
|
|
922
|
-
let r = n ??
|
|
671
|
+
}), na = (e, t, n) => {
|
|
672
|
+
let r = n ?? pt(e), i = vi(e);
|
|
923
673
|
if (i === void 0) return null;
|
|
924
674
|
let a = [];
|
|
925
675
|
for (let [e, n] of Object.entries(t)) {
|
|
926
676
|
let t = i[e];
|
|
927
677
|
if (t === void 0) return null;
|
|
928
|
-
let o =
|
|
678
|
+
let o = ra(e, t, r, n === !0 ? {} : n);
|
|
929
679
|
if (o === null) return null;
|
|
930
680
|
a.push(o);
|
|
931
681
|
}
|
|
@@ -933,30 +683,30 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
933
683
|
table: r,
|
|
934
684
|
children: a
|
|
935
685
|
};
|
|
936
|
-
},
|
|
686
|
+
}, ra = (e, t, n, r) => {
|
|
937
687
|
let i = t.target(), a = (t.kind === "manyToMany" ? void 0 : t.sourceKey) ?? "id", o, s;
|
|
938
688
|
if (t.kind === "manyToMany") o = t.targetKey, s = "target";
|
|
939
689
|
else if (t.kind === "one") {
|
|
940
|
-
let r = t.sourceKey ??
|
|
690
|
+
let r = t.sourceKey ?? sa(n, i.tableName);
|
|
941
691
|
if (r !== void 0) o = r, s = "source";
|
|
942
692
|
else try {
|
|
943
|
-
o = t.foreignKey ??
|
|
693
|
+
o = t.foreignKey ?? li(i, n.tableName, e), s = "target";
|
|
944
694
|
} catch {
|
|
945
695
|
return null;
|
|
946
696
|
}
|
|
947
697
|
} else try {
|
|
948
|
-
o = t.foreignKey ??
|
|
698
|
+
o = t.foreignKey ?? li(i, n.tableName, e), s = "target";
|
|
949
699
|
} catch {
|
|
950
700
|
return null;
|
|
951
701
|
}
|
|
952
702
|
let c = r.with === void 0 ? [] : (() => {
|
|
953
|
-
let e =
|
|
703
|
+
let e = vi(i.tableName);
|
|
954
704
|
if (e === void 0 && Object.keys(r.with).length > 0) return null;
|
|
955
705
|
let t = [];
|
|
956
706
|
for (let [n, a] of Object.entries(r.with)) {
|
|
957
707
|
let r = e?.[n];
|
|
958
708
|
if (r === void 0) return null;
|
|
959
|
-
let o =
|
|
709
|
+
let o = ra(n, r, i, a === !0 ? {} : a);
|
|
960
710
|
if (o === null) return null;
|
|
961
711
|
t.push(o);
|
|
962
712
|
}
|
|
@@ -972,9 +722,9 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
972
722
|
fkSide: s,
|
|
973
723
|
branch: r,
|
|
974
724
|
children: c,
|
|
975
|
-
junction:
|
|
725
|
+
junction: ia(t, r)
|
|
976
726
|
};
|
|
977
|
-
},
|
|
727
|
+
}, ia = (e, t) => {
|
|
978
728
|
if (e.kind !== "manyToMany" || t.junction === void 0) return;
|
|
979
729
|
let n = e.through(), r = t.junction === !0 ? Object.keys(n.fields) : t.junction, i = r.filter((e) => e in n.fields);
|
|
980
730
|
return {
|
|
@@ -986,35 +736,35 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
986
736
|
return t !== void 0 && (t.type === "timestamp" || t.type === "date");
|
|
987
737
|
})
|
|
988
738
|
};
|
|
989
|
-
},
|
|
739
|
+
}, aa = (e) => `__j_${e}`, oa = "__j", sa = (e, t) => {
|
|
990
740
|
for (let [n, r] of Object.entries(e.fields)) if (r.type === "reference" && r.references?.()?.tableName === t) return n;
|
|
991
|
-
},
|
|
741
|
+
}, ca = (e, t) => {
|
|
992
742
|
let n = 0;
|
|
993
743
|
return {
|
|
994
744
|
sql: e,
|
|
995
745
|
dialect: t,
|
|
996
746
|
nextAlias: () => `__a${n++}`
|
|
997
747
|
};
|
|
998
|
-
},
|
|
748
|
+
}, la = (e, t, n, r) => {
|
|
999
749
|
switch (e) {
|
|
1000
|
-
case "postgres": return
|
|
750
|
+
case "postgres": return ha(t, n, r);
|
|
1001
751
|
case "sqlite":
|
|
1002
|
-
case "turso": return
|
|
752
|
+
case "turso": return Ca(t, n, r);
|
|
1003
753
|
case "mysql":
|
|
1004
|
-
case "mariadb": return
|
|
1005
|
-
case "mssql": return
|
|
754
|
+
case "mariadb": return Na(t, n, r);
|
|
755
|
+
case "mssql": return Ba(t, n, r);
|
|
1006
756
|
}
|
|
1007
|
-
},
|
|
1008
|
-
let n =
|
|
757
|
+
}, ua = (e, t) => t === "mssql" && !da.test(e) ? /* @__PURE__ */ new Date(`${e}Z`) : new Date(e), da = /(?:Z|[+-]\d{2}:?\d{2})$/, fa = (e, t) => {
|
|
758
|
+
let n = pa(e.table, e.children, t);
|
|
1009
759
|
return (e) => e.map((e) => {
|
|
1010
760
|
let t = e.__row, r = typeof t == "string" ? JSON.parse(t) : t;
|
|
1011
761
|
return n(r);
|
|
1012
762
|
});
|
|
1013
|
-
},
|
|
763
|
+
}, pa = (e, t, n) => {
|
|
1014
764
|
let r = [], i = [];
|
|
1015
765
|
for (let [t, n] of Object.entries(e.fields)) (n.type === "timestamp" || n.type === "date") && r.push(t), n.type === "vector" && i.push(t);
|
|
1016
766
|
let a = t.map((e) => {
|
|
1017
|
-
let t =
|
|
767
|
+
let t = pa(e.target, e.children, n), r = e.relation.kind === "one", i = N(e), a = i ? Ui({
|
|
1018
768
|
relationName: e.relationName,
|
|
1019
769
|
sourceTableName: e.source.tableName,
|
|
1020
770
|
targetTableName: e.target.tableName,
|
|
@@ -1027,15 +777,15 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
1027
777
|
isSingle: r,
|
|
1028
778
|
fromOverFetch: i,
|
|
1029
779
|
cardinalityMessage: a,
|
|
1030
|
-
junction:
|
|
780
|
+
junction: ma(e.junction, n)
|
|
1031
781
|
};
|
|
1032
782
|
});
|
|
1033
783
|
return (e) => {
|
|
1034
784
|
let t = { ...e };
|
|
1035
|
-
for (let e of i) e in t && (t[e] =
|
|
785
|
+
for (let e of i) e in t && (t[e] = Ee(t[e], "vector", n));
|
|
1036
786
|
for (let e of r) {
|
|
1037
787
|
let r = t[e];
|
|
1038
|
-
typeof r == "string" && (t[e] =
|
|
788
|
+
typeof r == "string" && (t[e] = ua(r, n));
|
|
1039
789
|
}
|
|
1040
790
|
for (let e of a) {
|
|
1041
791
|
let n = t[e.name];
|
|
@@ -1045,7 +795,7 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
1045
795
|
}
|
|
1046
796
|
if (e.fromOverFetch) {
|
|
1047
797
|
let r = n;
|
|
1048
|
-
if (r.length > 1) throw new
|
|
798
|
+
if (r.length > 1) throw new Hi(e.cardinalityMessage);
|
|
1049
799
|
t[e.name] = r.length === 0 ? null : e.decode(r[0]);
|
|
1050
800
|
continue;
|
|
1051
801
|
}
|
|
@@ -1057,204 +807,204 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
1057
807
|
}
|
|
1058
808
|
return t;
|
|
1059
809
|
};
|
|
1060
|
-
},
|
|
810
|
+
}, ma = (e, t) => {
|
|
1061
811
|
if (e === void 0) return;
|
|
1062
812
|
let n = new Set(e.dateColumns), r = e.requested;
|
|
1063
813
|
return (e) => {
|
|
1064
814
|
let i = e._junction ?? {}, a = {};
|
|
1065
815
|
for (let e of r) {
|
|
1066
816
|
let r = i[e];
|
|
1067
|
-
a[e] = n.has(e) && typeof r == "string" ?
|
|
817
|
+
a[e] = n.has(e) && typeof r == "string" ? ua(r, t) : r;
|
|
1068
818
|
}
|
|
1069
819
|
return {
|
|
1070
820
|
...e,
|
|
1071
821
|
_junction: a
|
|
1072
822
|
};
|
|
1073
823
|
};
|
|
1074
|
-
},
|
|
1075
|
-
let r = n.sql, i = n.nextAlias(), a = r(t.table.tableName), o = r(i), s =
|
|
1076
|
-
return s === null ? null : r`SELECT ${s} AS "__row" FROM ${a} AS ${o}${e.predicate ? r` WHERE ${
|
|
1077
|
-
},
|
|
1078
|
-
let i = n.sql, a = r === void 0 ? i`to_jsonb(${i(e)}.*)` : i`(to_jsonb(${i(e)}.*) - ${
|
|
824
|
+
}, ha = (e, t, n) => {
|
|
825
|
+
let r = n.sql, i = n.nextAlias(), a = r(t.table.tableName), o = r(i), s = ga(i, t.children, n);
|
|
826
|
+
return s === null ? null : r`SELECT ${s} AS "__row" FROM ${a} AS ${o}${e.predicate ? r` WHERE ${z(e.predicate, i, r)}` : r``}${w(e).length > 0 ? r` ORDER BY ${r.csv(w(e).map((e) => e.direction === "desc" ? r`${I(i, e.column, r)} DESC` : r`${I(i, e.column, r)} ASC`))}` : r``}${e.take === void 0 ? r`` : r` LIMIT ${R(e.take, r)}`}${e.skip === void 0 ? r`` : r` OFFSET ${R(e.skip, r)}`}`;
|
|
827
|
+
}, ga = (e, t, n, r) => {
|
|
828
|
+
let i = n.sql, a = r === void 0 ? i`to_jsonb(${i(e)}.*)` : i`(to_jsonb(${i(e)}.*) - ${L(oa, i)}::text)`;
|
|
1079
829
|
if (t.length === 0 && r === void 0) return a;
|
|
1080
830
|
let o = [];
|
|
1081
|
-
r !== void 0 && o.push(i`${
|
|
831
|
+
r !== void 0 && o.push(i`${L("_junction", i)}, ${I(e, oa, i)}`);
|
|
1082
832
|
for (let r of t) {
|
|
1083
|
-
let t =
|
|
833
|
+
let t = _a(r, e, n);
|
|
1084
834
|
if (t === null) return null;
|
|
1085
|
-
o.push(i`${
|
|
835
|
+
o.push(i`${L(r.relationName, i)}, ${t}`);
|
|
1086
836
|
}
|
|
1087
837
|
return i`${a} || jsonb_build_object(${i.csv(o)})`;
|
|
1088
|
-
},
|
|
838
|
+
}, _a = (e, t, n) => {
|
|
1089
839
|
switch (e.relation.kind) {
|
|
1090
|
-
case "one": return
|
|
1091
|
-
case "many": return
|
|
1092
|
-
case "manyToMany": return
|
|
840
|
+
case "one": return N(e) ? ya(ta(e), t, n) : va(e, t, n);
|
|
841
|
+
case "many": return ya(e, t, n);
|
|
842
|
+
case "manyToMany": return ba(e, t, n);
|
|
1093
843
|
}
|
|
1094
|
-
},
|
|
1095
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
844
|
+
}, va = (e, t, n) => {
|
|
845
|
+
let r = n.sql, i = n.nextAlias(), a = ga(i, e.children, n);
|
|
1096
846
|
if (a === null) return null;
|
|
1097
|
-
let o = e.fkSide === "source" ? r`${
|
|
847
|
+
let o = e.fkSide === "source" ? r`${I(i, "id", r)} = ${I(t, e.foreignKey, r)}` : r`${I(i, e.foreignKey, r)} = ${I(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${z(e.branch.where, i, r)}`, c = P(i, e.branch.orderBy, r);
|
|
1098
848
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}${c} LIMIT 1)`;
|
|
1099
|
-
},
|
|
1100
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
849
|
+
}, ya = (e, t, n) => {
|
|
850
|
+
let r = n.sql, i = n.nextAlias(), a = ga(i, e.children, n);
|
|
1101
851
|
if (a === null) return null;
|
|
1102
|
-
let o = r`${
|
|
852
|
+
let o = r`${I(void 0, e.foreignKey, r)} = ${I(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${T(e.branch.where, r)}`, c = Sa(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${R(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${R(e.branch.offset, r)}`;
|
|
1103
853
|
return r`COALESCE((SELECT jsonb_agg(${a}) FROM (SELECT * FROM ${r(e.target.tableName)} WHERE ${o}${s}${c}${l}${u}) AS ${r(i)}), '[]'::jsonb)`;
|
|
1104
|
-
},
|
|
1105
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
854
|
+
}, ba = (e, t, n) => {
|
|
855
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = ga(o, e.children, n, e.junction);
|
|
1106
856
|
if (c === null) return null;
|
|
1107
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1108
|
-
return r`COALESCE((SELECT jsonb_agg(${c}) FROM (SELECT ${r(o)}.*${m} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${
|
|
1109
|
-
},
|
|
1110
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
857
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${T(e.branch.where, r)}`, u = B(e, s, r), d = P(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${R(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${R(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : r`, ${xa(e.junction, s, r)} AS ${r(oa)}`;
|
|
858
|
+
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 ${I(o, "id", r)} = ${I(s, i.targetKey, r)} WHERE ${I(s, i.sourceKey, r)} = ${I(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), '[]'::jsonb)`;
|
|
859
|
+
}, xa = (e, t, n) => e.present.length === 0 ? n`jsonb_build_object()` : n`jsonb_build_object(${n.csv(e.present.map((e) => n`${L(e, n)}, ${I(t, e, n)}`))})`, P = (e, t, n) => t === void 0 || t.length === 0 ? n`` : n` ORDER BY ${n.csv(t.map((t) => t.direction === "desc" ? n`${I(e, t.column, n)} DESC` : n`${I(e, t.column, n)} ASC`))}`, Sa = (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`))}`, Ca = (e, t, n) => {
|
|
860
|
+
let r = n.sql, i = n.nextAlias(), a = wa(i, t.table, t.children, n);
|
|
1111
861
|
if (a === null) return null;
|
|
1112
|
-
let o = e.predicate ? r` WHERE ${
|
|
862
|
+
let o = e.predicate ? r` WHERE ${z(e.predicate, i, r)}` : r``, s = w(e).length > 0 ? r` ORDER BY ${r.csv(w(e).map((e) => e.direction === "desc" ? r`${I(i, e.column, r)} DESC` : r`${I(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${R(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${R(e.skip, r)}`;
|
|
1113
863
|
return r`SELECT ${a} AS "__row" FROM ${r(t.table.tableName)} AS ${r(i)}${o}${s}${c}${l}`;
|
|
1114
|
-
},
|
|
864
|
+
}, wa = (e, t, n, r, i) => {
|
|
1115
865
|
let a = r.sql, o = [];
|
|
1116
|
-
for (let n of Object.keys(t.fields)) o.push(a`${
|
|
866
|
+
for (let n of Object.keys(t.fields)) o.push(a`${L(n, a)}, ${I(e, n, a)}`);
|
|
1117
867
|
if (i !== void 0) {
|
|
1118
|
-
let e =
|
|
1119
|
-
o.push(a`${
|
|
868
|
+
let e = Ta(i.projection, i.source, a);
|
|
869
|
+
o.push(a`${L("_junction", a)}, json_object(${e})`);
|
|
1120
870
|
}
|
|
1121
871
|
for (let t of n) {
|
|
1122
|
-
let n =
|
|
872
|
+
let n = ka(t, e, r);
|
|
1123
873
|
if (n === null) return null;
|
|
1124
|
-
o.push(a`${
|
|
874
|
+
o.push(a`${L(t.relationName, a)}, ${n}`);
|
|
1125
875
|
}
|
|
1126
876
|
return a`json_object(${a.csv(o)})`;
|
|
1127
|
-
},
|
|
877
|
+
}, Ta = (e, t, n) => e.present.length === 0 ? n`` : n.csv(e.present.map((e) => n`${L(e, n)}, ${I(t.alias, t.physical(e), n)}`)), Ea = (e, t, n) => e.present.length === 0 ? n`` : n`, ${n.csv(e.present.map((e) => n`${I(t, e, n)} AS ${n(aa(e))}`))}`, Da = (e) => ({
|
|
1128
878
|
alias: e,
|
|
1129
|
-
physical:
|
|
1130
|
-
}),
|
|
879
|
+
physical: aa
|
|
880
|
+
}), Oa = (e) => ({
|
|
1131
881
|
alias: e,
|
|
1132
882
|
physical: (e) => e
|
|
1133
|
-
}),
|
|
883
|
+
}), ka = (e, t, n) => {
|
|
1134
884
|
switch (e.relation.kind) {
|
|
1135
|
-
case "one": return
|
|
1136
|
-
case "many": return
|
|
1137
|
-
case "manyToMany": return
|
|
885
|
+
case "one": return N(e) ? ja(ta(e), t, n) : Aa(e, t, n);
|
|
886
|
+
case "many": return ja(e, t, n);
|
|
887
|
+
case "manyToMany": return Ma(e, t, n);
|
|
1138
888
|
}
|
|
1139
|
-
},
|
|
1140
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
889
|
+
}, Aa = (e, t, n) => {
|
|
890
|
+
let r = n.sql, i = n.nextAlias(), a = wa(i, e.target, e.children, n);
|
|
1141
891
|
if (a === null) return null;
|
|
1142
|
-
let o = e.fkSide === "source" ? r`${
|
|
892
|
+
let o = e.fkSide === "source" ? r`${I(i, "id", r)} = ${I(t, e.foreignKey, r)}` : r`${I(i, e.foreignKey, r)} = ${I(t, e.sourceKey, r)}`;
|
|
1143
893
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
|
|
1144
|
-
},
|
|
1145
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
894
|
+
}, ja = (e, t, n) => {
|
|
895
|
+
let r = n.sql, i = n.nextAlias(), a = wa(i, e.target, e.children, n);
|
|
1146
896
|
if (a === null) return null;
|
|
1147
|
-
let o = r`${
|
|
897
|
+
let o = r`${I(void 0, e.foreignKey, r)} = ${I(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${T(V(e.branch.where), r)}`, c = Sa(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${R(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${R(e.branch.offset, r)}`;
|
|
1148
898
|
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('[]'))`;
|
|
1149
|
-
},
|
|
1150
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
899
|
+
}, Ma = (e, t, n) => {
|
|
900
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = wa(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
1151
901
|
projection: e.junction,
|
|
1152
|
-
source:
|
|
902
|
+
source: Da(o)
|
|
1153
903
|
});
|
|
1154
904
|
if (c === null) return null;
|
|
1155
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1156
|
-
return r`COALESCE((SELECT json_group_array(${c}) FROM (SELECT ${r(o)}.*${m} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${
|
|
1157
|
-
},
|
|
1158
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
905
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${T(V(e.branch.where), r)}`, u = B(e, s, r, !0), d = P(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${R(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${R(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : Ea(e.junction, s, r);
|
|
906
|
+
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 ${I(o, "id", r)} = ${I(s, i.targetKey, r)} WHERE ${I(s, i.sourceKey, r)} = ${I(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), json('[]'))`;
|
|
907
|
+
}, Na = (e, t, n) => {
|
|
908
|
+
let r = n.sql, i = n.nextAlias(), a = F(i, t.table, t.children, n);
|
|
1159
909
|
if (a === null) return null;
|
|
1160
|
-
let o = e.predicate ? r` WHERE ${
|
|
910
|
+
let o = e.predicate ? r` WHERE ${z(e.predicate, i, r)}` : r``, s = w(e).length > 0 ? r` ORDER BY ${r.csv(w(e).map((e) => e.direction === "desc" ? r`${I(i, e.column, r)} DESC` : r`${I(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${R(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${R(e.skip, r)}`;
|
|
1161
911
|
return r`SELECT ${a} AS \`__row\` FROM ${r(t.table.tableName)} AS ${r(i)}${o}${s}${c}${l}`;
|
|
1162
|
-
},
|
|
912
|
+
}, F = (e, t, n, r, i) => {
|
|
1163
913
|
let a = r.sql, o = [];
|
|
1164
|
-
for (let n of Object.keys(t.fields)) o.push(a`${
|
|
914
|
+
for (let n of Object.keys(t.fields)) o.push(a`${L(n, a)}, ${I(e, n, a)}`);
|
|
1165
915
|
if (i !== void 0) {
|
|
1166
|
-
let e =
|
|
1167
|
-
o.push(a`${
|
|
916
|
+
let e = Ta(i.projection, i.source, a);
|
|
917
|
+
o.push(a`${L("_junction", a)}, JSON_OBJECT(${e})`);
|
|
1168
918
|
}
|
|
1169
919
|
for (let t of n) {
|
|
1170
|
-
let n =
|
|
920
|
+
let n = Pa(t, e, r);
|
|
1171
921
|
if (n === null) return null;
|
|
1172
|
-
o.push(a`${
|
|
922
|
+
o.push(a`${L(t.relationName, a)}, ${n}`);
|
|
1173
923
|
}
|
|
1174
924
|
return a`JSON_OBJECT(${a.csv(o)})`;
|
|
1175
|
-
},
|
|
925
|
+
}, Pa = (e, t, n) => {
|
|
1176
926
|
switch (e.relation.kind) {
|
|
1177
927
|
case "one":
|
|
1178
|
-
if (
|
|
1179
|
-
let r =
|
|
1180
|
-
return n.dialect === "mariadb" ?
|
|
928
|
+
if (N(e)) {
|
|
929
|
+
let r = ta(e);
|
|
930
|
+
return n.dialect === "mariadb" ? Ra(r, t, n) : Ia(r, t, n);
|
|
1181
931
|
}
|
|
1182
|
-
return
|
|
1183
|
-
case "many": return n.dialect === "mariadb" ?
|
|
1184
|
-
case "manyToMany": return n.dialect === "mariadb" ?
|
|
932
|
+
return Fa(e, t, n);
|
|
933
|
+
case "many": return n.dialect === "mariadb" ? Ra(e, t, n) : Ia(e, t, n);
|
|
934
|
+
case "manyToMany": return n.dialect === "mariadb" ? za(e, t, n) : La(e, t, n);
|
|
1185
935
|
}
|
|
1186
|
-
},
|
|
1187
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
936
|
+
}, Fa = (e, t, n) => {
|
|
937
|
+
let r = n.sql, i = n.nextAlias(), a = F(i, e.target, e.children, n);
|
|
1188
938
|
if (a === null) return null;
|
|
1189
|
-
let o = e.fkSide === "source" ? r`${
|
|
939
|
+
let o = e.fkSide === "source" ? r`${I(i, "id", r)} = ${I(t, e.foreignKey, r)}` : r`${I(i, e.foreignKey, r)} = ${I(t, e.sourceKey, r)}`;
|
|
1190
940
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
|
|
1191
|
-
},
|
|
1192
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
941
|
+
}, Ia = (e, t, n) => {
|
|
942
|
+
let r = n.sql, i = n.nextAlias(), a = F(i, e.target, e.children, n);
|
|
1193
943
|
if (a === null) return null;
|
|
1194
|
-
let o = r`${
|
|
944
|
+
let o = r`${I(void 0, e.foreignKey, r)} = ${I(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${T(V(e.branch.where), r)}`, c = Sa(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${R(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${R(e.branch.offset, r)}`;
|
|
1195
945
|
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())`;
|
|
1196
|
-
},
|
|
1197
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
946
|
+
}, La = (e, t, n) => {
|
|
947
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = F(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
1198
948
|
projection: e.junction,
|
|
1199
|
-
source:
|
|
949
|
+
source: Da(o)
|
|
1200
950
|
});
|
|
1201
951
|
if (c === null) return null;
|
|
1202
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1203
|
-
return r`COALESCE((SELECT JSON_ARRAYAGG(${c}) FROM (SELECT ${r(o)}.*${m} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${
|
|
1204
|
-
},
|
|
1205
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
952
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${T(V(e.branch.where), r)}`, u = B(e, s, r, !0), d = P(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${R(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${R(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : Ea(e.junction, s, r);
|
|
953
|
+
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 ${I(o, "id", r)} = ${I(s, i.targetKey, r)} WHERE ${I(s, i.sourceKey, r)} = ${I(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), JSON_ARRAY())`;
|
|
954
|
+
}, Ra = (e, t, n) => {
|
|
955
|
+
let r = n.sql, i = n.nextAlias(), a = F(i, e.target, e.children, n);
|
|
1206
956
|
if (a === null) return null;
|
|
1207
|
-
let o = r`${
|
|
1208
|
-
if (e.branch.limit === void 0 && e.branch.offset === void 0) return r`COALESCE((SELECT JSON_ARRAYAGG(${a}${c.length > 0 ? r` ORDER BY ${r.csv(c.map((e) => e.direction === "desc" ? r`${
|
|
1209
|
-
let l = c.length > 0 ? r` ORDER BY ${r.csv(c.map((e) => e.direction === "desc" ? r`${r(e.column)} DESC` : r`${r(e.column)} ASC`))}` : r` ORDER BY ${r("id")}`, u = e.branch.limit, d = e.branch.offset, f = u !== void 0 && d !== void 0 ? r` AND ${
|
|
1210
|
-
return r`COALESCE((SELECT JSON_ARRAYAGG(${a} ORDER BY ${
|
|
1211
|
-
},
|
|
957
|
+
let o = r`${I(i, e.foreignKey, r)} = ${I(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${T(V(e.branch.where), r)}`, c = e.branch.orderBy ?? [];
|
|
958
|
+
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`${I(i, e.column, r)} DESC` : r`${I(i, e.column, r)} ASC`))}` : r``}) FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}), JSON_ARRAY())`;
|
|
959
|
+
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 ${I(i, "rn", r)} > ${R(d, r)} AND ${I(i, "rn", r)} <= ${R(d + u, r)}` : u === void 0 ? r` AND ${I(i, "rn", r)} > ${R(d, r)}` : r` AND ${I(i, "rn", r)} <= ${R(u, r)}`;
|
|
960
|
+
return r`COALESCE((SELECT JSON_ARRAYAGG(${a} ORDER BY ${I(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())`;
|
|
961
|
+
}, za = (e, t, n) => {
|
|
1212
962
|
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = (t) => e.junction === void 0 ? void 0 : {
|
|
1213
963
|
projection: e.junction,
|
|
1214
964
|
source: t
|
|
1215
|
-
}, l = r`${
|
|
965
|
+
}, l = r`${I(s, i.sourceKey, r)} = ${I(t, "id", r)}`, u = r`${I(o, "id", r)} = ${I(s, i.targetKey, r)}`, d = e.branch.where === void 0 ? r`` : r` AND ${T(V(e.branch.where), r)}`, f = B(e, s, r, !0), p = e.branch.orderBy ?? [];
|
|
1216
966
|
if (e.branch.limit === void 0 && e.branch.offset === void 0) {
|
|
1217
|
-
let t =
|
|
1218
|
-
return t === null ? null : r`COALESCE((SELECT JSON_ARRAYAGG(${t}${p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${
|
|
967
|
+
let t = F(o, e.target, e.children, n, c(Oa(s)));
|
|
968
|
+
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`${I(o, e.column, r)} DESC` : r`${I(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())`;
|
|
1219
969
|
}
|
|
1220
|
-
let m = p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${
|
|
970
|
+
let m = p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${I(o, e.column, r)} DESC` : r`${I(o, e.column, r)} ASC`))}` : r` ORDER BY ${I(o, "id", r)}`, h = e.branch.limit, g = e.branch.offset, _ = h !== void 0 && g !== void 0 ? r` AND ${I(o, "rn", r)} > ${R(g, r)} AND ${I(o, "rn", r)} <= ${R(g + h, r)}` : h === void 0 ? r` AND ${I(o, "rn", r)} > ${R(g, r)}` : r` AND ${I(o, "rn", r)} <= ${R(h, r)}`, v = e.branch.onJunction === void 0 ? r`` : r` WHERE ${z(V(e.branch.onJunction), s, r)}`, ee = F(o, e.target, e.children, n, c(Da(o)));
|
|
1221
971
|
if (ee === null) return null;
|
|
1222
|
-
let te = e.junction === void 0 ? r`` :
|
|
1223
|
-
return r`COALESCE((SELECT JSON_ARRAYAGG(${ee} ORDER BY ${
|
|
1224
|
-
},
|
|
1225
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
972
|
+
let te = e.junction === void 0 ? r`` : Ea(e.junction, s, r);
|
|
973
|
+
return r`COALESCE((SELECT JSON_ARRAYAGG(${ee} ORDER BY ${I(o, "rn", r)}) FROM (SELECT ${r(o)}.*${te}, ${I(s, i.sourceKey, r)} AS ${r(`__src_${i.sourceKey}`)}, ROW_NUMBER() OVER (PARTITION BY ${I(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 ${I(o, `__src_${i.sourceKey}`, r)} = ${I(t, "id", r)}${d}${_}), JSON_ARRAY())`;
|
|
974
|
+
}, Ba = (e, t, n) => {
|
|
975
|
+
let r = n.sql, i = n.nextAlias(), a = Va(i, t.table, t.children, n);
|
|
1226
976
|
if (a === null) return null;
|
|
1227
|
-
let o = e.predicate ? r` WHERE ${
|
|
977
|
+
let o = e.predicate ? r` WHERE ${z(e.predicate, i, r)}` : r``, s = w(e).length > 0 ? r` ORDER BY ${r.csv(w(e).map((e) => e.direction === "desc" ? r`${I(i, e.column, r)} DESC` : r`${I(i, e.column, r)} ASC`))}` : r``, c = r``, l = r``;
|
|
1228
978
|
if (e.skip !== void 0) {
|
|
1229
|
-
let t =
|
|
1230
|
-
l = e.take === void 0 ? r`${t} OFFSET ${
|
|
1231
|
-
} else e.take !== void 0 && (c = r`TOP ${
|
|
979
|
+
let t = w(e).length > 0 ? s : r` ORDER BY (SELECT NULL)`;
|
|
980
|
+
l = e.take === void 0 ? r`${t} OFFSET ${R(e.skip, r)} ROWS` : r`${t} OFFSET ${R(e.skip, r)} ROWS FETCH NEXT ${R(e.take, r)} ROWS ONLY`;
|
|
981
|
+
} else e.take !== void 0 && (c = r`TOP ${R(e.take, r)} `);
|
|
1232
982
|
let u = e.skip === void 0 ? s : r``;
|
|
1233
983
|
return r`SELECT ${c}(SELECT ${a} FOR JSON PATH, INCLUDE_NULL_VALUES, WITHOUT_ARRAY_WRAPPER) AS ${r("__row")} FROM ${r(t.table.tableName)} AS ${r(i)}${o}${u}${l}`;
|
|
1234
|
-
},
|
|
984
|
+
}, Va = (e, t, n, r, i) => {
|
|
1235
985
|
let a = r.sql, o = [];
|
|
1236
|
-
for (let n of Object.keys(t.fields)) o.push(a`${
|
|
1237
|
-
if (i !== void 0) for (let e of i.projection.present) o.push(a`${
|
|
986
|
+
for (let n of Object.keys(t.fields)) o.push(a`${I(e, n, a)} AS ${a(n)}`);
|
|
987
|
+
if (i !== void 0) for (let e of i.projection.present) o.push(a`${I(i.source.alias, i.source.physical(e), a)} AS ${Ha(`_junction.${e}`, a)}`);
|
|
1238
988
|
for (let t of n) {
|
|
1239
|
-
let n =
|
|
989
|
+
let n = Ua(t, e, r);
|
|
1240
990
|
if (n === null) return null;
|
|
1241
991
|
o.push(n);
|
|
1242
992
|
}
|
|
1243
993
|
return a.csv(o);
|
|
1244
|
-
},
|
|
994
|
+
}, Ha = (e, t) => t.unsafe(`[${e.replace(/]/g, "]]")}]`), Ua = (e, t, n) => {
|
|
1245
995
|
switch (e.relation.kind) {
|
|
1246
|
-
case "one": return
|
|
1247
|
-
case "many": return
|
|
1248
|
-
case "manyToMany": return
|
|
996
|
+
case "one": return N(e) ? Ka(ta(e), t, n) : Wa(e, t, n);
|
|
997
|
+
case "many": return Ka(e, t, n);
|
|
998
|
+
case "manyToMany": return qa(e, t, n);
|
|
1249
999
|
}
|
|
1250
|
-
},
|
|
1251
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1000
|
+
}, Wa = (e, t, n) => {
|
|
1001
|
+
let r = n.sql, i = n.nextAlias(), a = Va(i, e.target, e.children, n);
|
|
1252
1002
|
if (a === null) return null;
|
|
1253
|
-
let o = e.fkSide === "source" ? r`${
|
|
1003
|
+
let o = e.fkSide === "source" ? r`${I(i, "id", r)} = ${I(t, e.foreignKey, r)}` : r`${I(i, e.foreignKey, r)} = ${I(t, e.sourceKey, r)}`;
|
|
1254
1004
|
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)}`;
|
|
1255
|
-
},
|
|
1005
|
+
}, Ga = (e, t, n) => {
|
|
1256
1006
|
if (e.offset !== void 0) {
|
|
1257
|
-
let r = e.orderBy && e.orderBy.length > 0 ? t : n` ORDER BY (SELECT NULL)`, i = e.limit === void 0 ? n`${r} OFFSET ${
|
|
1007
|
+
let r = e.orderBy && e.orderBy.length > 0 ? t : n` ORDER BY (SELECT NULL)`, i = e.limit === void 0 ? n`${r} OFFSET ${R(e.offset, n)} ROWS` : n`${r} OFFSET ${R(e.offset, n)} ROWS FETCH NEXT ${R(e.limit, n)} ROWS ONLY`;
|
|
1258
1008
|
return {
|
|
1259
1009
|
top: n``,
|
|
1260
1010
|
pagination: i,
|
|
@@ -1262,33 +1012,36 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
1262
1012
|
};
|
|
1263
1013
|
}
|
|
1264
1014
|
return {
|
|
1265
|
-
top: e.limit === void 0 ? n`` : n`TOP ${
|
|
1015
|
+
top: e.limit === void 0 ? n`` : n`TOP ${R(e.limit, n)} `,
|
|
1266
1016
|
pagination: n``,
|
|
1267
1017
|
finalOrder: t
|
|
1268
1018
|
};
|
|
1269
|
-
},
|
|
1270
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1019
|
+
}, Ka = (e, t, n) => {
|
|
1020
|
+
let r = n.sql, i = n.nextAlias(), a = Va(i, e.target, e.children, n);
|
|
1271
1021
|
if (a === null) return null;
|
|
1272
|
-
let o = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1273
|
-
return r`ISNULL(JSON_QUERY((SELECT ${c}${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${
|
|
1274
|
-
},
|
|
1275
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
1022
|
+
let o = e.branch.where === void 0 ? r`` : r` AND ${z(e.branch.where, i, r)}`, s = P(i, e.branch.orderBy, r), { top: c, pagination: l, finalOrder: u } = Ga(e.branch, s, r);
|
|
1023
|
+
return r`ISNULL(JSON_QUERY((SELECT ${c}${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${I(i, e.foreignKey, r)} = ${I(t, e.sourceKey, r)}${o}${u}${l} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
|
|
1024
|
+
}, qa = (e, t, n) => {
|
|
1025
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = Va(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
1276
1026
|
projection: e.junction,
|
|
1277
|
-
source:
|
|
1027
|
+
source: Oa(s)
|
|
1278
1028
|
});
|
|
1279
1029
|
if (c === null) return null;
|
|
1280
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1281
|
-
return r`ISNULL(JSON_QUERY((SELECT ${f}${c} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${
|
|
1282
|
-
},
|
|
1283
|
-
if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw
|
|
1030
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${z(e.branch.where, o, r)}`, u = B(e, s, r), d = P(o, e.branch.orderBy, r), { top: f, pagination: p, finalOrder: m } = Ga(e.branch, d, r);
|
|
1031
|
+
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 ${I(o, "id", r)} = ${I(s, i.targetKey, r)} WHERE ${I(s, i.sourceKey, r)} = ${I(t, "id", r)}${u}${l}${m}${p} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
|
|
1032
|
+
}, I = (e, t, n) => e === void 0 ? n`${n(t)}` : n`${n(e)}.${n(t)}`, L = (e, t) => t.unsafe(`'${e.replace(/'/g, "''")}'`), R = (e, t) => {
|
|
1033
|
+
if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw y(`literalInt: expected non-negative integer, got ${e}`);
|
|
1284
1034
|
return t.unsafe(String(e));
|
|
1285
|
-
},
|
|
1035
|
+
}, z = (e, t, n) => {
|
|
1036
|
+
let r = Ja(e, t);
|
|
1037
|
+
return T(r, n);
|
|
1038
|
+
}, B = (e, t, n, r = !1) => {
|
|
1286
1039
|
let i = e.branch.onJunction;
|
|
1287
|
-
return i === void 0 ? n`` : n` AND ${
|
|
1288
|
-
},
|
|
1289
|
-
if ("not" in e) return { not:
|
|
1290
|
-
if ("and" in e) return { and: e.and.map((e) =>
|
|
1291
|
-
if ("or" in e) return { or: e.or.map((e) =>
|
|
1040
|
+
return i === void 0 ? n`` : n` AND ${z(r ? V(i) : i, t, n)}`;
|
|
1041
|
+
}, Ja = (e, t) => {
|
|
1042
|
+
if ("not" in e) return { not: Ja(e.not, t) };
|
|
1043
|
+
if ("and" in e) return { and: e.and.map((e) => Ja(e, t)) };
|
|
1044
|
+
if ("or" in e) return { or: e.or.map((e) => Ja(e, t)) };
|
|
1292
1045
|
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
1293
1046
|
let n = e;
|
|
1294
1047
|
return {
|
|
@@ -1302,55 +1055,55 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
1302
1055
|
...n,
|
|
1303
1056
|
column: `${t}.${n.column}`
|
|
1304
1057
|
};
|
|
1305
|
-
},
|
|
1306
|
-
if ("not" in e) return { not:
|
|
1307
|
-
if ("and" in e) return { and: e.and.map((e) =>
|
|
1308
|
-
if ("or" in e) return { or: e.or.map((e) =>
|
|
1058
|
+
}, V = (e) => {
|
|
1059
|
+
if ("not" in e) return { not: V(e.not) };
|
|
1060
|
+
if ("and" in e) return { and: e.and.map((e) => V(e)) };
|
|
1061
|
+
if ("or" in e) return { or: e.or.map((e) => V(e)) };
|
|
1309
1062
|
if (e.op === "subquery-in" || e.op === "subquery-not-in" || e.op === "exists" || e.op === "not-exists") return e;
|
|
1310
1063
|
let t = e;
|
|
1311
1064
|
return {
|
|
1312
1065
|
...t,
|
|
1313
|
-
value:
|
|
1066
|
+
value: Ya(t.value)
|
|
1314
1067
|
};
|
|
1315
|
-
},
|
|
1316
|
-
e.actors !== void 0 && (
|
|
1317
|
-
},
|
|
1068
|
+
}, Ya = (e) => e == null ? e : e instanceof Date ? e.toISOString() : typeof e == "boolean" ? +!!e : Array.isArray(e) ? e.map((e) => Ya(e)) : e, Xa = Symbol.for("@voltro/database/coreTablesRegistry"), Za = globalThis, Qa = Za[Xa] ?? (Za[Xa] = {}), $a = (e) => {
|
|
1069
|
+
e.actors !== void 0 && (Qa.actors = e.actors), e.tenants !== void 0 && (Qa.tenants = e.tenants);
|
|
1070
|
+
}, eo = (e, t) => () => {
|
|
1318
1071
|
let n = e();
|
|
1319
1072
|
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`);
|
|
1320
1073
|
return n();
|
|
1321
|
-
},
|
|
1322
|
-
id:
|
|
1323
|
-
kind:
|
|
1074
|
+
}, to = () => eo(() => Qa.actors, "actors"), no = () => eo(() => Qa.tenants, "tenants"), ro = S("actors", {
|
|
1075
|
+
id: C(),
|
|
1076
|
+
kind: b().oneOf([
|
|
1324
1077
|
"user",
|
|
1325
1078
|
"serviceAccount",
|
|
1326
1079
|
"apiKey",
|
|
1327
1080
|
"system"
|
|
1328
1081
|
]).safe(),
|
|
1329
|
-
displayName:
|
|
1330
|
-
createdAt:
|
|
1331
|
-
}),
|
|
1082
|
+
displayName: b().nullable().sensitive("fullName"),
|
|
1083
|
+
createdAt: x().default("now")
|
|
1084
|
+
}), io = (e, t) => ({
|
|
1332
1085
|
...t,
|
|
1333
1086
|
...e,
|
|
1334
1087
|
origin: e.origin ?? "injected"
|
|
1335
|
-
}),
|
|
1088
|
+
}), ao = (e, t, n = {}) => ({
|
|
1336
1089
|
table: e,
|
|
1337
1090
|
op: "insert",
|
|
1338
1091
|
old: null,
|
|
1339
1092
|
new: t,
|
|
1340
1093
|
...n
|
|
1341
|
-
}),
|
|
1094
|
+
}), oo = (e, t, n, r = {}) => ({
|
|
1342
1095
|
table: e,
|
|
1343
1096
|
op: "update",
|
|
1344
1097
|
old: t,
|
|
1345
1098
|
new: n,
|
|
1346
1099
|
...r
|
|
1347
|
-
}),
|
|
1100
|
+
}), so = (e, t, n = {}) => ({
|
|
1348
1101
|
table: e,
|
|
1349
1102
|
op: "delete",
|
|
1350
1103
|
old: t,
|
|
1351
1104
|
new: null,
|
|
1352
1105
|
...n
|
|
1353
|
-
}),
|
|
1106
|
+
}), co = (e, t, n = {}) => {
|
|
1354
1107
|
let { at: r = "2026-01-01T00:00:00.000Z", column: i = "deletedAt", ...a } = n;
|
|
1355
1108
|
return {
|
|
1356
1109
|
table: e,
|
|
@@ -1365,13 +1118,13 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
1365
1118
|
},
|
|
1366
1119
|
...a
|
|
1367
1120
|
};
|
|
1368
|
-
},
|
|
1121
|
+
}, lo = (e) => e == null ? "null" : e instanceof Date ? JSON.stringify(e.toISOString()) : typeof e == "bigint" ? JSON.stringify(e.toString()) : Array.isArray(e) ? `[${e.map(lo).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)}:${lo(t)}`).join(",")}}` : JSON.stringify(e) ?? "null", uo = (e) => xr("sha256").update([
|
|
1369
1122
|
e.pipe,
|
|
1370
1123
|
e.op,
|
|
1371
1124
|
e.key,
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
].join("\0")).digest("hex").slice(0, 32),
|
|
1125
|
+
lo(e.next),
|
|
1126
|
+
lo(e.prev)
|
|
1127
|
+
].join("\0")).digest("hex").slice(0, 32), fo = (e, t) => `${e}:${t}`, po = (e) => {
|
|
1375
1128
|
let t = e.lastIndexOf(":");
|
|
1376
1129
|
if (t <= 0) return null;
|
|
1377
1130
|
let n = Number(e.slice(t + 1));
|
|
@@ -1379,7 +1132,7 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
1379
1132
|
digest: e.slice(0, t),
|
|
1380
1133
|
occurrence: n
|
|
1381
1134
|
};
|
|
1382
|
-
},
|
|
1135
|
+
}, mo = class {
|
|
1383
1136
|
#e = /* @__PURE__ */ new Map();
|
|
1384
1137
|
#t;
|
|
1385
1138
|
#n;
|
|
@@ -1401,7 +1154,7 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
1401
1154
|
}
|
|
1402
1155
|
seedFromChangeKeys(e, t) {
|
|
1403
1156
|
for (let n of e) {
|
|
1404
|
-
let e =
|
|
1157
|
+
let e = po(n);
|
|
1405
1158
|
if (e === null) continue;
|
|
1406
1159
|
let r = this.#e.get(e.digest), i = Math.max(r?.count ?? 0, e.occurrence + 1);
|
|
1407
1160
|
this.#e.set(e.digest, {
|
|
@@ -1422,70 +1175,70 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
1422
1175
|
this.#e.delete(e.value);
|
|
1423
1176
|
}
|
|
1424
1177
|
}
|
|
1425
|
-
},
|
|
1426
|
-
let t = Number(e[
|
|
1178
|
+
}, ho = "VOLTRO_CHANGE_CLAIMS_TTL_HOURS", go = 1, _o = (e = process.env) => {
|
|
1179
|
+
let t = Number(e[ho]);
|
|
1427
1180
|
return (Number.isFinite(t) && t > 0 ? t : 1) * 2 * 36e5;
|
|
1428
|
-
},
|
|
1429
|
-
let t = e ??
|
|
1181
|
+
}, H = new Sr(), vo = (e, t) => H.run(e, t), yo = () => H.getStore(), bo = (e) => {
|
|
1182
|
+
let t = e ?? H.getStore();
|
|
1430
1183
|
return t === void 0 ? {} : {
|
|
1431
1184
|
...t.traceId === void 0 ? {} : { traceId: t.traceId },
|
|
1432
1185
|
...t.subjectId === void 0 ? {} : { subjectId: t.subjectId },
|
|
1433
1186
|
...t.procedure === void 0 ? {} : { procedure: t.procedure },
|
|
1434
1187
|
...t.via === void 0 ? {} : { via: t.via }
|
|
1435
1188
|
};
|
|
1436
|
-
},
|
|
1437
|
-
let t =
|
|
1438
|
-
return t === void 0 ? e(void 0) :
|
|
1439
|
-
},
|
|
1440
|
-
for (let [t, n] of
|
|
1441
|
-
let r = n.filter((t) => e - t.at <
|
|
1442
|
-
|
|
1443
|
-
}
|
|
1444
|
-
},
|
|
1189
|
+
}, xo = (e) => {
|
|
1190
|
+
let t = H.getStore();
|
|
1191
|
+
return t === void 0 ? e(void 0) : H.run(t, () => e(t));
|
|
1192
|
+
}, So = 3e4, Co = 1e4, U = /* @__PURE__ */ new Map(), W = 0, wo = (e, t, n) => `${e}\u0000${t}\u0000${String(n)}`, To = (e) => {
|
|
1193
|
+
for (let [t, n] of U) {
|
|
1194
|
+
let r = n.filter((t) => e - t.at < So);
|
|
1195
|
+
W -= n.length - r.length, r.length === 0 ? U.delete(t) : r.length !== n.length && U.set(t, r);
|
|
1196
|
+
}
|
|
1197
|
+
}, Eo = (e, t) => {
|
|
1445
1198
|
if (t.traceId === void 0 && t.subjectId === void 0 && t.procedure === void 0) return;
|
|
1446
1199
|
let n = Date.now();
|
|
1447
|
-
if (
|
|
1448
|
-
let r =
|
|
1449
|
-
r === void 0 ?
|
|
1200
|
+
if (W >= Co && To(n), W >= Co) return;
|
|
1201
|
+
let r = U.get(e);
|
|
1202
|
+
r === void 0 ? U.set(e, [{
|
|
1450
1203
|
attribution: t,
|
|
1451
1204
|
at: n
|
|
1452
1205
|
}]) : r.push({
|
|
1453
1206
|
attribution: t,
|
|
1454
1207
|
at: n
|
|
1455
|
-
}),
|
|
1456
|
-
},
|
|
1457
|
-
let t =
|
|
1208
|
+
}), W += 1;
|
|
1209
|
+
}, Do = (e) => {
|
|
1210
|
+
let t = U.get(e);
|
|
1458
1211
|
if (t === void 0 || t.length === 0) return;
|
|
1459
1212
|
let n = t.shift();
|
|
1460
|
-
if (--
|
|
1461
|
-
},
|
|
1462
|
-
let t =
|
|
1213
|
+
if (--W, t.length === 0 && U.delete(e), !(Date.now() - n.at >= So)) return n.attribution;
|
|
1214
|
+
}, Oo = (e) => (U.get(e)?.length ?? 0) > 0, G = /* @__PURE__ */ new Map(), K = /* @__PURE__ */ new Map(), q = /* @__PURE__ */ new Map(), ko = 250, Ao = (e) => {
|
|
1215
|
+
let t = K.get(e);
|
|
1463
1216
|
if (t === void 0) return;
|
|
1464
|
-
|
|
1465
|
-
let n =
|
|
1466
|
-
n !== void 0 && (clearTimeout(n),
|
|
1217
|
+
K.delete(e);
|
|
1218
|
+
let n = q.get(e);
|
|
1219
|
+
n !== void 0 && (clearTimeout(n), q.delete(e));
|
|
1467
1220
|
for (let e of t) e();
|
|
1468
|
-
},
|
|
1469
|
-
|
|
1470
|
-
},
|
|
1471
|
-
let t = (
|
|
1221
|
+
}, jo = (e) => {
|
|
1222
|
+
G.set(e, (G.get(e) ?? 0) + 1);
|
|
1223
|
+
}, Mo = (e) => {
|
|
1224
|
+
let t = (G.get(e) ?? 0) - 1;
|
|
1472
1225
|
if (t > 0) {
|
|
1473
|
-
|
|
1226
|
+
G.set(e, t);
|
|
1474
1227
|
return;
|
|
1475
1228
|
}
|
|
1476
|
-
|
|
1477
|
-
},
|
|
1478
|
-
let i = n == null ? void 0 :
|
|
1229
|
+
G.delete(e), Ao(e);
|
|
1230
|
+
}, No = (e, t, n, r) => {
|
|
1231
|
+
let i = n == null ? void 0 : wo(e, t, n), a = () => r(i === void 0 ? void 0 : Do(i));
|
|
1479
1232
|
if (i === void 0) {
|
|
1480
1233
|
a();
|
|
1481
1234
|
return;
|
|
1482
1235
|
}
|
|
1483
|
-
if (
|
|
1236
|
+
if (Oo(i)) {
|
|
1484
1237
|
a();
|
|
1485
1238
|
return;
|
|
1486
1239
|
}
|
|
1487
|
-
let o =
|
|
1488
|
-
if (o === void 0 && (
|
|
1240
|
+
let o = K.get(e);
|
|
1241
|
+
if (o === void 0 && (G.get(e) ?? 0) === 0) {
|
|
1489
1242
|
a();
|
|
1490
1243
|
return;
|
|
1491
1244
|
}
|
|
@@ -1493,91 +1246,91 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
1493
1246
|
o.push(a);
|
|
1494
1247
|
return;
|
|
1495
1248
|
}
|
|
1496
|
-
|
|
1497
|
-
let s = setTimeout(() =>
|
|
1498
|
-
typeof s == "object" && typeof s.unref == "function" && s.unref(),
|
|
1499
|
-
},
|
|
1500
|
-
|
|
1501
|
-
for (let e of
|
|
1502
|
-
|
|
1503
|
-
},
|
|
1249
|
+
K.set(e, [a]);
|
|
1250
|
+
let s = setTimeout(() => Ao(e), ko);
|
|
1251
|
+
typeof s == "object" && typeof s.unref == "function" && s.unref(), q.set(e, s);
|
|
1252
|
+
}, Po = () => {
|
|
1253
|
+
U.clear(), W = 0, G.clear();
|
|
1254
|
+
for (let e of q.values()) clearTimeout(e);
|
|
1255
|
+
q.clear(), K.clear();
|
|
1256
|
+
}, Fo = () => W, Io = 64, Lo = "\0", Ro = 32, zo = (e, ...t) => `${e}_${xr("sha256").update(t.map(String).join(Lo)).digest("hex").slice(0, Ro)}`, Bo = (e) => e.length + 1 + Ro, J = /* @__PURE__ */ new Map(), Vo = (e, t) => {
|
|
1504
1257
|
J.set(e, {
|
|
1505
1258
|
recorder: t.recorder,
|
|
1506
1259
|
tables: new Set(t.tables),
|
|
1507
1260
|
ownTables: new Set(t.ownTables)
|
|
1508
1261
|
});
|
|
1509
|
-
},
|
|
1262
|
+
}, Ho = (e) => {
|
|
1510
1263
|
J.delete(e);
|
|
1511
|
-
},
|
|
1512
|
-
let t =
|
|
1513
|
-
if (t !== void 0) return t.n += 1,
|
|
1264
|
+
}, Uo = () => J.clear(), Wo = new Sr(), Go = (e) => Wo.run({ n: 1 }, e), Ko = (e) => E.suspend(() => {
|
|
1265
|
+
let t = Wo.getStore();
|
|
1266
|
+
if (t !== void 0) return t.n += 1, E.ensuring(e, E.sync(() => {
|
|
1514
1267
|
--t.n;
|
|
1515
1268
|
}));
|
|
1516
1269
|
let n = { n: 1 };
|
|
1517
|
-
return
|
|
1270
|
+
return Wo.enterWith(n), E.ensuring(e, E.sync(() => {
|
|
1518
1271
|
--n.n;
|
|
1519
1272
|
}));
|
|
1520
|
-
}),
|
|
1521
|
-
if (J.size === 0 || (
|
|
1273
|
+
}), qo = () => (Wo.getStore()?.n ?? 0) > 0, Jo = (e) => {
|
|
1274
|
+
if (J.size === 0 || (Wo.getStore()?.n ?? 0) > 0) return !1;
|
|
1522
1275
|
for (let t of J.values()) if (!t.ownTables.has(e) && t.tables.has(e)) return !0;
|
|
1523
1276
|
return !1;
|
|
1524
|
-
},
|
|
1277
|
+
}, Yo = async (e, t) => {
|
|
1525
1278
|
if (J.size !== 0) {
|
|
1526
1279
|
for (let [n, r] of J.entries()) if (!r.ownTables.has(t.table) && r.tables.has(t.table)) try {
|
|
1527
1280
|
await r.recorder(e, t);
|
|
1528
1281
|
} catch (e) {
|
|
1529
|
-
let r =
|
|
1282
|
+
let r = _e(e);
|
|
1530
1283
|
throw r === void 0 ? e : Error(`write recorder '${n}' failed while recording a ${t.op} on '${t.table}': ${r}`, { cause: e });
|
|
1531
1284
|
}
|
|
1532
1285
|
}
|
|
1533
|
-
},
|
|
1286
|
+
}, Xo = vr.exponential({
|
|
1534
1287
|
start: 5e-4,
|
|
1535
1288
|
factor: 2,
|
|
1536
1289
|
count: 16
|
|
1537
|
-
}),
|
|
1538
|
-
let n = `${e}\u0000${t}`, r =
|
|
1290
|
+
}), Zo = D.counter("voltro_db_queries_total", { description: "Database operations executed, by dialect and operation kind." }), Qo = D.histogram("voltro_db_query_duration_seconds", Xo, "Database operation duration in seconds, by dialect and operation kind."), $o = D.counter("voltro_db_errors_total", { description: "Database operations that threw, by dialect and operation kind." }), es = D.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." }), ts = D.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." }), ns = [], rs = /* @__PURE__ */ new Map(), is = /* @__PURE__ */ new Map(), as = /* @__PURE__ */ new Map(), os = (e, t) => {
|
|
1291
|
+
let n = `${e}\u0000${t}`, r = rs.get(n);
|
|
1539
1292
|
if (r !== void 0) return r;
|
|
1540
|
-
let i = (n) =>
|
|
1541
|
-
count: i(
|
|
1542
|
-
duration: i(
|
|
1543
|
-
errors: i(
|
|
1293
|
+
let i = (n) => D.tagged(D.tagged(n, "dialect", e), "op", t), a = {
|
|
1294
|
+
count: i(Zo),
|
|
1295
|
+
duration: i(Qo),
|
|
1296
|
+
errors: i($o)
|
|
1544
1297
|
};
|
|
1545
|
-
return
|
|
1546
|
-
},
|
|
1547
|
-
|
|
1548
|
-
},
|
|
1549
|
-
let n = Math.max(0, (
|
|
1550
|
-
n === 0 ?
|
|
1551
|
-
let r =
|
|
1552
|
-
r === void 0 && (r =
|
|
1553
|
-
},
|
|
1554
|
-
let t =
|
|
1555
|
-
t.count.unsafeUpdate(1,
|
|
1556
|
-
},
|
|
1298
|
+
return rs.set(n, a), a;
|
|
1299
|
+
}, ss = () => {
|
|
1300
|
+
rs.clear(), is.clear(), as.clear();
|
|
1301
|
+
}, cs = () => rs.size + is.size + as.size, ls = /* @__PURE__ */ new Map(), us = (e, t) => {
|
|
1302
|
+
let n = Math.max(0, (ls.get(e) ?? 0) + t);
|
|
1303
|
+
n === 0 ? ls.delete(e) : ls.set(e, n);
|
|
1304
|
+
let r = is.get(e);
|
|
1305
|
+
r === void 0 && (r = D.tagged(es, "dialect", e), is.set(e, r)), r.unsafeUpdate(n, ns);
|
|
1306
|
+
}, ds = (e) => ls.get(e) ?? 0, fs = (e) => {
|
|
1307
|
+
let t = os(String(e.dialect), e.op);
|
|
1308
|
+
t.count.unsafeUpdate(1, ns), t.duration.unsafeUpdate(e.durationMs / 1e3, ns), e.status === "error" && t.errors.unsafeUpdate(1, ns);
|
|
1309
|
+
}, ps = async (e, t, n) => {
|
|
1557
1310
|
let r = performance.now(), i = String(e);
|
|
1558
|
-
|
|
1311
|
+
us(i, 1);
|
|
1559
1312
|
let a = "ok";
|
|
1560
1313
|
try {
|
|
1561
1314
|
return await n();
|
|
1562
1315
|
} catch (e) {
|
|
1563
1316
|
throw a = "error", e;
|
|
1564
1317
|
} finally {
|
|
1565
|
-
|
|
1318
|
+
us(i, -1), fs({
|
|
1566
1319
|
dialect: e,
|
|
1567
1320
|
op: t,
|
|
1568
1321
|
durationMs: performance.now() - r,
|
|
1569
1322
|
status: a
|
|
1570
1323
|
});
|
|
1571
1324
|
}
|
|
1572
|
-
},
|
|
1325
|
+
}, ms = 3e5, hs = (e) => {
|
|
1573
1326
|
if (e == null || e === "") return;
|
|
1574
1327
|
let t = Number(e);
|
|
1575
1328
|
return Number.isFinite(t) && t >= 0 ? Math.floor(t) : void 0;
|
|
1576
|
-
},
|
|
1577
|
-
let n =
|
|
1329
|
+
}, gs = (e, t = process.env) => hs(t.VOLTRO_DB_EAGER_FALLBACK_WARN_INTERVAL_MS) ?? hs(e) ?? 3e5, _s = (e, t = {}) => {
|
|
1330
|
+
let n = gs(t.warnIntervalMs), r = t.now ?? (() => Date.now()), i = /* @__PURE__ */ new Map();
|
|
1578
1331
|
return (t) => {
|
|
1579
|
-
let a = `${t.dialect} ${t.reason}`, o =
|
|
1580
|
-
o === void 0 && (o =
|
|
1332
|
+
let a = `${t.dialect} ${t.reason}`, o = as.get(a);
|
|
1333
|
+
o === void 0 && (o = D.tagged(D.tagged(ts, "dialect", String(t.dialect)), "reason", t.reason), as.set(a, o)), o.unsafeUpdate(1, ns);
|
|
1581
1334
|
let s = `${t.table}\u0000${t.reason}`, c = i.get(s), l = c === void 0 || n > 0 && r() - c >= n, u = {
|
|
1582
1335
|
table: t.table,
|
|
1583
1336
|
dialect: String(t.dialect),
|
|
@@ -1591,37 +1344,37 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
1591
1344
|
}
|
|
1592
1345
|
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);
|
|
1593
1346
|
};
|
|
1594
|
-
},
|
|
1595
|
-
if (
|
|
1596
|
-
throw
|
|
1597
|
-
},
|
|
1598
|
-
let t = 0, n =
|
|
1347
|
+
}, vs = (e) => {
|
|
1348
|
+
if (_r.isSuccess(e)) return e.value;
|
|
1349
|
+
throw mr.squash(e.cause);
|
|
1350
|
+
}, ys = "10 millis", bs = 3, xs = (e) => yr.exponential(ys).pipe(yr.compose(yr.recurs(bs)), yr.whileInput(e)), Ss = async (e) => {
|
|
1351
|
+
let t = 0, n = E.suspend(() => {
|
|
1599
1352
|
let n = ++t;
|
|
1600
|
-
return e.withTransaction(
|
|
1601
|
-
if (
|
|
1602
|
-
let r = t.value, i =
|
|
1353
|
+
return e.withTransaction(E.flatMap(E.serviceOption(Cr), (t) => {
|
|
1354
|
+
if (O.isNone(t)) return E.fail(/* @__PURE__ */ Error(`${e.label}: TransactionConnection unexpectedly missing inside withTransaction.`));
|
|
1355
|
+
let r = t.value, i = E.tryPromise({
|
|
1603
1356
|
try: () => e.body(r, n),
|
|
1604
1357
|
catch: (e) => e
|
|
1605
1358
|
});
|
|
1606
|
-
return e.prepare === void 0 ? i :
|
|
1607
|
-
})).pipe(
|
|
1608
|
-
}).pipe(
|
|
1609
|
-
return
|
|
1610
|
-
},
|
|
1359
|
+
return e.prepare === void 0 ? i : E.flatMap(e.prepare(r), () => i);
|
|
1360
|
+
})).pipe(E.catchAllDefect((t) => e.isRetryable(t) ? E.fail(t) : E.die(t)));
|
|
1361
|
+
}).pipe(E.retry(xs(e.isRetryable)), E.withSpan(e.span.name, { attributes: { ...e.span.attributes } }));
|
|
1362
|
+
return ps(e.dialect, "transaction", async () => vs(await e.runPromiseExit(e.wrapProgram === void 0 ? n : e.wrapProgram(n))));
|
|
1363
|
+
}, Cs = class extends Error {
|
|
1611
1364
|
swallowed;
|
|
1612
1365
|
_tag = "TransactionAborted";
|
|
1613
1366
|
constructor(e, t) {
|
|
1614
1367
|
super(`${e}: a statement failed inside this transaction and the error was caught, but the database had already aborted the transaction — every later statement was refused, and COMMIT would have rolled back ALL of its writes, including the ones that succeeded. Nothing was committed.
|
|
1615
|
-
the caught failure: ${
|
|
1368
|
+
the caught failure: ${Ds(t)}\n to tolerate a failing statement and keep the rest, run it inside \`tx.savepoint(() => …)\` — only that statement is rolled back. To keep all-or-nothing, let the error propagate.`, { cause: t }), this.swallowed = t, this.name = "TransactionAbortedError";
|
|
1616
1369
|
}
|
|
1617
|
-
},
|
|
1370
|
+
}, ws = (e, t = "transactional()") => {
|
|
1618
1371
|
let n = 0, r, i = (e) => {
|
|
1619
1372
|
r === void 0 && (r = { error: e });
|
|
1620
1373
|
};
|
|
1621
1374
|
return {
|
|
1622
1375
|
track: (a) => r === void 0 ? n > 0 ? a() : a().catch((t) => {
|
|
1623
1376
|
throw e(t) && i(t), t;
|
|
1624
|
-
}) : Promise.reject(new
|
|
1377
|
+
}) : Promise.reject(new Cs(t, r.error)),
|
|
1625
1378
|
inSavepoint: async (e) => {
|
|
1626
1379
|
n++;
|
|
1627
1380
|
try {
|
|
@@ -1633,7 +1386,7 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
1633
1386
|
record: i,
|
|
1634
1387
|
abortedBy: () => r
|
|
1635
1388
|
};
|
|
1636
|
-
},
|
|
1389
|
+
}, Ts = async (e, t) => {
|
|
1637
1390
|
let { tracker: n, name: r, exec: i, spelling: a } = e;
|
|
1638
1391
|
await n.track(() => i(a === "mssql" ? `SAVE TRANSACTION ${r}` : `SAVEPOINT ${r}`));
|
|
1639
1392
|
try {
|
|
@@ -1642,8 +1395,8 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
1642
1395
|
} catch (e) {
|
|
1643
1396
|
throw await i(a === "mssql" ? `ROLLBACK TRANSACTION ${r}` : `ROLLBACK TO SAVEPOINT ${r}`).catch((e) => n.record(e)), a === "standard" && await i(`RELEASE SAVEPOINT ${r}`).catch(() => void 0), e;
|
|
1644
1397
|
}
|
|
1645
|
-
},
|
|
1646
|
-
for (let t of
|
|
1398
|
+
}, Es = (e) => e instanceof Cs || typeof e == "object" && !!e && e._tag === "TransactionAborted", Ds = (e) => {
|
|
1399
|
+
for (let t of tt(e)) {
|
|
1647
1400
|
let e = t;
|
|
1648
1401
|
for (let t = 0; t < 5 && typeof e == "object" && e; t++) {
|
|
1649
1402
|
let t = e.code, n = e.message;
|
|
@@ -1652,14 +1405,14 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
1652
1405
|
}
|
|
1653
1406
|
}
|
|
1654
1407
|
return e instanceof Error ? e.message : String(e);
|
|
1655
|
-
},
|
|
1656
|
-
let t =
|
|
1408
|
+
}, Os = async (e) => {
|
|
1409
|
+
let t = yo(), n = t === void 0 ? (e) => e() : (e) => vo(t, e), r = await Ss({
|
|
1657
1410
|
...e,
|
|
1658
1411
|
body: (r) => {
|
|
1659
1412
|
let i = e.makeView(r, t);
|
|
1660
1413
|
return n(() => e.work(i)).then((t) => {
|
|
1661
1414
|
let n = i.abortedBy?.();
|
|
1662
|
-
if (n !== void 0) throw e.isRetryable(n.error) ? n.error : new
|
|
1415
|
+
if (n !== void 0) throw e.isRetryable(n.error) ? n.error : new Cs(e.label, n.error);
|
|
1663
1416
|
return {
|
|
1664
1417
|
result: t,
|
|
1665
1418
|
view: i
|
|
@@ -1671,50 +1424,50 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
1671
1424
|
}
|
|
1672
1425
|
});
|
|
1673
1426
|
return r.view.commitEvents(), r.result;
|
|
1674
|
-
},
|
|
1427
|
+
}, ks = /* @__PURE__ */ new Set([
|
|
1675
1428
|
"1213",
|
|
1676
1429
|
"ER_LOCK_DEADLOCK",
|
|
1677
1430
|
"1205",
|
|
1678
1431
|
"ER_LOCK_WAIT_TIMEOUT",
|
|
1679
1432
|
"1020",
|
|
1680
1433
|
"ER_CHECKREAD"
|
|
1681
|
-
]),
|
|
1434
|
+
]), As = /* @__PURE__ */ new Set(["40001", "40P01"]), js = /* @__PURE__ */ new Set(["1205"]), Ms = /* @__PURE__ */ new Set([
|
|
1682
1435
|
"SQLITE_BUSY",
|
|
1683
1436
|
"5",
|
|
1684
1437
|
"SQLITE_LOCKED",
|
|
1685
1438
|
"6"
|
|
1686
|
-
]),
|
|
1439
|
+
]), Ns = /write-write conflict|write-read conflict|database is locked|table is locked|database is busy/i, Ps = /* @__PURE__ */ new Set([
|
|
1687
1440
|
1213,
|
|
1688
1441
|
1205,
|
|
1689
1442
|
1020
|
|
1690
|
-
]),
|
|
1691
|
-
...
|
|
1692
|
-
...
|
|
1693
|
-
...
|
|
1694
|
-
...
|
|
1695
|
-
]),
|
|
1443
|
+
]), Fs = /* @__PURE__ */ new Set([
|
|
1444
|
+
...ks,
|
|
1445
|
+
...As,
|
|
1446
|
+
...js,
|
|
1447
|
+
...Ms
|
|
1448
|
+
]), Is = (e) => tt(e).some(Ls), Ls = (e) => {
|
|
1696
1449
|
let t = e;
|
|
1697
1450
|
for (let e = 0; e < 6 && typeof t == "object" && t; e++) {
|
|
1698
1451
|
let e = t;
|
|
1699
|
-
if (typeof e.errno == "number" &&
|
|
1452
|
+
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;
|
|
1700
1453
|
t = e.cause;
|
|
1701
1454
|
}
|
|
1702
1455
|
return !1;
|
|
1703
|
-
},
|
|
1704
|
-
id:
|
|
1705
|
-
fields: { expiresAt:
|
|
1456
|
+
}, Rs = "voltro/expires", zs = () => m({
|
|
1457
|
+
id: Rs,
|
|
1458
|
+
fields: { expiresAt: x().nullable() },
|
|
1706
1459
|
behaviors: { defaultWhere: () => "expiresAt IS NULL OR expiresAt > now()" }
|
|
1707
|
-
}),
|
|
1708
|
-
id:
|
|
1460
|
+
}), Bs = "voltro/localFirst", Vs = () => m({
|
|
1461
|
+
id: Bs,
|
|
1709
1462
|
fields: {}
|
|
1710
|
-
}),
|
|
1463
|
+
}), Hs = (e) => e.appliedMixins.some((e) => e.id === Bs), Us = (e) => {
|
|
1711
1464
|
let t = [];
|
|
1712
|
-
for (let n of Object.values(e))
|
|
1465
|
+
for (let n of Object.values(e)) Hs(n) && t.push(n.tableName);
|
|
1713
1466
|
return t;
|
|
1714
|
-
},
|
|
1715
|
-
let i =
|
|
1467
|
+
}, Ws = class extends gr.TaggedError("TableStreamError") {}, Gs = 1e3, Ks = (e, t, n, r) => {
|
|
1468
|
+
let i = O.match(r, {
|
|
1716
1469
|
onNone: () => e.where,
|
|
1717
|
-
onSome: (n) => e.where ?
|
|
1470
|
+
onSome: (n) => e.where ? wn(e.where, hn(t, n)) : hn(t, n)
|
|
1718
1471
|
});
|
|
1719
1472
|
return {
|
|
1720
1473
|
table: e.table,
|
|
@@ -1729,19 +1482,19 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
1729
1482
|
...e.includeDeleted === void 0 ? {} : { includeDeleted: e.includeDeleted },
|
|
1730
1483
|
...e.crossTenant === void 0 ? {} : { crossTenant: e.crossTenant }
|
|
1731
1484
|
};
|
|
1732
|
-
},
|
|
1733
|
-
let n = t.pk ?? "id", r = t.chunkSize ??
|
|
1734
|
-
return
|
|
1735
|
-
let a =
|
|
1736
|
-
try: () => e.query(
|
|
1737
|
-
catch: (e) => new
|
|
1485
|
+
}, qs = (e, t) => {
|
|
1486
|
+
let n = t.pk ?? "id", r = t.chunkSize ?? Gs;
|
|
1487
|
+
return br.paginateChunkEffect(O.none(), (i) => {
|
|
1488
|
+
let a = E.tryPromise({
|
|
1489
|
+
try: () => e.query(Ks(t, n, r, i)),
|
|
1490
|
+
catch: (e) => new Ws({
|
|
1738
1491
|
table: t.table,
|
|
1739
1492
|
cause: e
|
|
1740
1493
|
})
|
|
1741
1494
|
});
|
|
1742
|
-
return (t.retry ? a.pipe(
|
|
1495
|
+
return (t.retry ? a.pipe(E.retry(t.retry)) : a).pipe(E.map((e) => [hr.fromIterable(e), e.length === r && e.length > 0 ? O.some(O.some(e[e.length - 1][n])) : O.none()]));
|
|
1743
1496
|
});
|
|
1744
|
-
},
|
|
1497
|
+
}, Js = (e) => {
|
|
1745
1498
|
let t = e.alpha ?? .5;
|
|
1746
1499
|
if (t < 0 || t > 1) throw Error(`hybridSearch: alpha must be in [0, 1], got ${t}`);
|
|
1747
1500
|
return (n) => {
|
|
@@ -1755,7 +1508,7 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
1755
1508
|
queryText: e.vector.query,
|
|
1756
1509
|
distance: e.vector.distance ?? "cosine",
|
|
1757
1510
|
alpha: t
|
|
1758
|
-
}, i =
|
|
1511
|
+
}, i = _t(n.table, e.fts.indexName, n.fullTextIndexes);
|
|
1759
1512
|
return {
|
|
1760
1513
|
...n,
|
|
1761
1514
|
annClause: r,
|
|
@@ -1768,17 +1521,17 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
1768
1521
|
}
|
|
1769
1522
|
};
|
|
1770
1523
|
};
|
|
1771
|
-
},
|
|
1524
|
+
}, Ys = async (e, t) => {
|
|
1772
1525
|
let n = e.as ?? "embedding", r = t.row[e.from];
|
|
1773
1526
|
if (typeof r != "string" || r.length === 0) return {};
|
|
1774
1527
|
let i = await t.embed(r);
|
|
1775
1528
|
return { [n]: i };
|
|
1776
|
-
},
|
|
1529
|
+
}, Xs = (e) => {
|
|
1777
1530
|
if (!Number.isInteger(e.dimensions) || e.dimensions <= 0) throw Error(`vectorEmbedding: dimensions must be a positive integer, got ${String(e.dimensions)}.`);
|
|
1778
|
-
let t = e.as ?? "embedding", n = (t) =>
|
|
1779
|
-
return
|
|
1531
|
+
let t = e.as ?? "embedding", n = (t) => Ys(e, t);
|
|
1532
|
+
return m({
|
|
1780
1533
|
id: "voltro/vectorEmbedding",
|
|
1781
|
-
fields: { [t]:
|
|
1534
|
+
fields: { [t]: Ne(e.dimensions) },
|
|
1782
1535
|
...e.index === !1 ? {} : { indexes: [{
|
|
1783
1536
|
fields: [t],
|
|
1784
1537
|
kind: "hnsw",
|
|
@@ -1793,19 +1546,19 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
1793
1546
|
beforeUpdate: n
|
|
1794
1547
|
}
|
|
1795
1548
|
});
|
|
1796
|
-
},
|
|
1549
|
+
}, Zs = 63, Qs = "br_pr", Y = class extends Error {
|
|
1797
1550
|
_tag = "BranchNameInvalid";
|
|
1798
1551
|
constructor(e) {
|
|
1799
1552
|
super(e), this.name = "BranchNameInvalid";
|
|
1800
1553
|
}
|
|
1801
|
-
},
|
|
1554
|
+
}, $s = (e, t) => {
|
|
1802
1555
|
if (!Number.isInteger(t) || t < 0) throw new Y(`prNumber must be a non-negative integer, got ${String(t)}`);
|
|
1803
|
-
let n =
|
|
1556
|
+
let n = Qt(e);
|
|
1804
1557
|
if (n.replace(/_/g, "") === "") throw new Y(`app slug '${e}' has no usable identifier characters`);
|
|
1805
|
-
let r = `${
|
|
1806
|
-
if (r.length >
|
|
1558
|
+
let r = `${Qs}${t}_${n}`;
|
|
1559
|
+
if (r.length > Zs) throw new Y(`branch namespace '${r}' exceeds the ${Zs}-byte identifier limit — use a shorter app slug`);
|
|
1807
1560
|
return r;
|
|
1808
|
-
},
|
|
1561
|
+
}, ec = (e) => e.startsWith(Qs), tc = {
|
|
1809
1562
|
requested: {
|
|
1810
1563
|
provision: "provisioning",
|
|
1811
1564
|
destroy: "destroying"
|
|
@@ -1824,18 +1577,18 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
1824
1577
|
fail: "failed"
|
|
1825
1578
|
},
|
|
1826
1579
|
destroyed: {}
|
|
1827
|
-
},
|
|
1580
|
+
}, nc = class extends Error {
|
|
1828
1581
|
from;
|
|
1829
1582
|
event;
|
|
1830
1583
|
_tag = "BranchTransitionInvalid";
|
|
1831
1584
|
constructor(e, t) {
|
|
1832
1585
|
super(`invalid branch transition: ${e} --${t}-->`), this.from = e, this.event = t, this.name = "BranchTransitionInvalid";
|
|
1833
1586
|
}
|
|
1834
|
-
},
|
|
1835
|
-
let n =
|
|
1836
|
-
if (n === void 0) throw new
|
|
1587
|
+
}, rc = (e, t) => {
|
|
1588
|
+
let n = tc[e][t];
|
|
1589
|
+
if (n === void 0) throw new nc(e, t);
|
|
1837
1590
|
return n;
|
|
1838
|
-
},
|
|
1591
|
+
}, ic = (e, t, n, r, i = [], a = []) => {
|
|
1839
1592
|
if (n === "copy" && (r === void 0 || r === "")) throw new Y("seed 'copy' requires a parentNamespace to snapshot from");
|
|
1840
1593
|
let o = [{
|
|
1841
1594
|
kind: "create-namespace",
|
|
@@ -1865,13 +1618,13 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
1865
1618
|
kind: "seed",
|
|
1866
1619
|
detail: `run boot seeds into ${e}`
|
|
1867
1620
|
}), o;
|
|
1868
|
-
},
|
|
1869
|
-
if (!
|
|
1621
|
+
}, ac = (e) => {
|
|
1622
|
+
if (!ec(e)) throw new Y(`refusing to plan teardown of '${e}' — not a branch namespace`);
|
|
1870
1623
|
return [{
|
|
1871
1624
|
kind: "drop-namespace",
|
|
1872
1625
|
detail: e
|
|
1873
1626
|
}];
|
|
1874
|
-
},
|
|
1627
|
+
}, oc = (e) => {
|
|
1875
1628
|
if (e === void 0 || e === "") return !1;
|
|
1876
1629
|
try {
|
|
1877
1630
|
let t = new URL(e).hostname.toLowerCase();
|
|
@@ -1879,27 +1632,27 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
1879
1632
|
} catch {
|
|
1880
1633
|
return /\bneon\.(tech|build)\b/i.test(e);
|
|
1881
1634
|
}
|
|
1882
|
-
},
|
|
1635
|
+
}, sc = (e) => e.prefer === void 0 ? e.seed === "copy" && oc(e.dbUrl) ? "neon-cow" : "namespace" : e.prefer, cc = (e, t = {}) => [{
|
|
1883
1636
|
kind: "neon-branch-create",
|
|
1884
1637
|
detail: `${t.parentBranch ?? "main"} → ${e} (copy-on-write)`
|
|
1885
|
-
}],
|
|
1886
|
-
if (!
|
|
1638
|
+
}], lc = (e) => {
|
|
1639
|
+
if (!ec(e)) throw new Y(`refusing to plan teardown of '${e}' — not a branch namespace`);
|
|
1887
1640
|
return [{
|
|
1888
1641
|
kind: "neon-branch-delete",
|
|
1889
1642
|
detail: e
|
|
1890
1643
|
}];
|
|
1891
|
-
},
|
|
1644
|
+
}, 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) => {
|
|
1892
1645
|
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);
|
|
1893
1646
|
return {
|
|
1894
1647
|
evict: i,
|
|
1895
1648
|
rejectNew: r.filter((e) => !a.has(e.namespace)).length >= t.maxBranches
|
|
1896
1649
|
};
|
|
1897
|
-
},
|
|
1898
|
-
let n =
|
|
1650
|
+
}, pc = async (e, t) => {
|
|
1651
|
+
let n = $s(e.appSlug, e.prNumber), r = sc({
|
|
1899
1652
|
seed: e.seed,
|
|
1900
1653
|
...e.dbUrl === void 0 ? {} : { dbUrl: e.dbUrl },
|
|
1901
1654
|
...e.prefer === void 0 ? {} : { prefer: e.prefer }
|
|
1902
|
-
}), i =
|
|
1655
|
+
}), i = uc({
|
|
1903
1656
|
mechanism: r,
|
|
1904
1657
|
branchId: n,
|
|
1905
1658
|
tableNames: e.tableNames,
|
|
@@ -1928,15 +1681,15 @@ var rr = (e) => typeof e == "string" && e !== "" ? e : null, ir = async (e, t, n
|
|
|
1928
1681
|
mechanism: r,
|
|
1929
1682
|
steps: i
|
|
1930
1683
|
};
|
|
1931
|
-
},
|
|
1932
|
-
let r =
|
|
1684
|
+
}, mc = async (e, t, n) => {
|
|
1685
|
+
let r = dc(t, e);
|
|
1933
1686
|
return t === "neon-cow" ? await n.neonBranchDelete(e) : await n.dropNamespace(e), r;
|
|
1934
|
-
},
|
|
1687
|
+
}, hc = (e, t, n) => fc(e, t, n), X = (e) => `"${e.replace(/"/g, "\"\"")}"`, gc = {
|
|
1935
1688
|
cascade: "CASCADE",
|
|
1936
1689
|
restrict: "RESTRICT",
|
|
1937
1690
|
setNull: "SET NULL",
|
|
1938
1691
|
noAction: "NO ACTION"
|
|
1939
|
-
}, Z = (e) => `'${e.replace(/'/g, "''")}'`,
|
|
1692
|
+
}, Z = (e) => `'${e.replace(/'/g, "''")}'`, _c = (e, t) => {
|
|
1940
1693
|
let n = t.columns.map(Z).join(", ");
|
|
1941
1694
|
return `DO $voltro_branch$
|
|
1942
1695
|
DECLARE derived name;
|
|
@@ -1963,10 +1716,10 @@ BEGIN
|
|
|
1963
1716
|
END IF;
|
|
1964
1717
|
END
|
|
1965
1718
|
$voltro_branch$`;
|
|
1966
|
-
},
|
|
1967
|
-
let n = t.onDelete === void 0 ? "" : ` ON DELETE ${
|
|
1719
|
+
}, vc = (e, t) => {
|
|
1720
|
+
let n = t.onDelete === void 0 ? "" : ` ON DELETE ${gc[t.onDelete]}`, r = t.onUpdate === void 0 ? "" : ` ON UPDATE ${gc[t.onUpdate]}`;
|
|
1968
1721
|
return `ALTER TABLE ${X(e)}.${X(t.table)} ADD FOREIGN KEY (${X(t.column)}) REFERENCES ${X(e)}.${X(t.targetTable)} (${X(t.targetColumn)})${n}${r}`;
|
|
1969
|
-
},
|
|
1722
|
+
}, yc = (e) => {
|
|
1970
1723
|
let t = () => {
|
|
1971
1724
|
throw Error("namespace branch executor: Neon ops require a neon-cow executor (use a Neon connection for copy-on-write branches)");
|
|
1972
1725
|
};
|
|
@@ -1974,24 +1727,24 @@ $voltro_branch$`;
|
|
|
1974
1727
|
createNamespace: (t) => e.run(`CREATE SCHEMA IF NOT EXISTS ${X(t)}`),
|
|
1975
1728
|
createTable: (t, n) => e.run(`CREATE TABLE IF NOT EXISTS ${X(t)}.${X(n)} (LIKE ${X(n)} INCLUDING ALL)`),
|
|
1976
1729
|
copyTable: (t, n, r) => e.run(`INSERT INTO ${X(n)}.${X(r)} SELECT * FROM ${X(t)}.${X(r)}`),
|
|
1977
|
-
addForeignKey: (t, n) => e.run(
|
|
1978
|
-
restoreIndexName: (t, n) => e.run(
|
|
1730
|
+
addForeignKey: (t, n) => e.run(vc(t, n)),
|
|
1731
|
+
restoreIndexName: (t, n) => e.run(_c(t, n)),
|
|
1979
1732
|
dropNamespace: (t) => e.run(`DROP SCHEMA IF EXISTS ${X(t)} CASCADE`),
|
|
1980
1733
|
neonBranchCreate: t,
|
|
1981
1734
|
neonBranchDelete: t
|
|
1982
1735
|
};
|
|
1983
|
-
},
|
|
1736
|
+
}, bc = class extends Error {
|
|
1984
1737
|
_tag = "TenantResidencyUnresolved";
|
|
1985
1738
|
constructor(e) {
|
|
1986
1739
|
super(e), this.name = "TenantResidencyUnresolved";
|
|
1987
1740
|
}
|
|
1988
|
-
},
|
|
1741
|
+
}, xc = class extends Error {
|
|
1989
1742
|
region;
|
|
1990
1743
|
_tag = "TenantRegionUnavailable";
|
|
1991
1744
|
constructor(e, t) {
|
|
1992
1745
|
super(t), this.region = e, this.name = "TenantRegionUnavailable";
|
|
1993
1746
|
}
|
|
1994
|
-
},
|
|
1747
|
+
}, Sc, Cc = (e) => {
|
|
1995
1748
|
if (e.homes === void 0) throw Error("setResidencyConfig: `homes` is required");
|
|
1996
1749
|
if (e.servableRegions === void 0 || e.servableRegions.length === 0) throw Error("setResidencyConfig: `servableRegions` must be non-empty (which regions this deployment serves)");
|
|
1997
1750
|
let t = /* @__PURE__ */ new Map();
|
|
@@ -2000,55 +1753,55 @@ $voltro_branch$`;
|
|
|
2000
1753
|
if (e !== void 0 && e !== n.region) throw Error(`residency: tenant '${n.tenantId}' is mapped to two regions ('${e}' and '${n.region}')`);
|
|
2001
1754
|
t.set(n.tenantId, n.region);
|
|
2002
1755
|
}
|
|
2003
|
-
return
|
|
2004
|
-
},
|
|
2005
|
-
|
|
2006
|
-
},
|
|
2007
|
-
if (e == null || e === "") throw new
|
|
1756
|
+
return Sc = e, e;
|
|
1757
|
+
}, wc = () => Sc, Tc = () => {
|
|
1758
|
+
Sc = void 0;
|
|
1759
|
+
}, Ec = (e, t) => {
|
|
1760
|
+
if (e == null || e === "") throw new bc("residency is on but the request has no resolvable tenant — refusing to bind a store");
|
|
2008
1761
|
let n = t.homes.find((t) => t.tenantId === e);
|
|
2009
|
-
if (n === void 0) throw new
|
|
1762
|
+
if (n === void 0) throw new bc(`no residency home is mapped for tenant '${e}' — refusing to fall back to a default store (would be a residency violation)`);
|
|
2010
1763
|
return n;
|
|
2011
|
-
},
|
|
2012
|
-
let n =
|
|
1764
|
+
}, Dc = (e, t) => t.servableRegions.includes(e), Oc = (e, t) => {
|
|
1765
|
+
let n = Ec(e.tenantId, t), r = o(n.tenantId);
|
|
2013
1766
|
return {
|
|
2014
1767
|
region: n.region,
|
|
2015
1768
|
namespace: r,
|
|
2016
1769
|
...n.connectionKey === void 0 ? {} : { connectionKey: n.connectionKey }
|
|
2017
1770
|
};
|
|
2018
|
-
},
|
|
2019
|
-
let r =
|
|
2020
|
-
if (!
|
|
1771
|
+
}, kc = (e, t, n) => {
|
|
1772
|
+
let r = Oc(e, t);
|
|
1773
|
+
if (!Dc(r.region, t)) throw new xc(r.region, `tenant homed in region '${r.region}', which this deployment does not serve — route to the home region`);
|
|
2021
1774
|
let i = n.get(r.region);
|
|
2022
|
-
if (i === void 0) throw new
|
|
1775
|
+
if (i === void 0) throw new xc(r.region, `no store handle for home region '${r.region}' (declared servable but not wired) — failing closed`);
|
|
2023
1776
|
return {
|
|
2024
1777
|
store: i,
|
|
2025
1778
|
placement: r
|
|
2026
1779
|
};
|
|
2027
|
-
},
|
|
2028
|
-
let { store: i, placement: a } =
|
|
1780
|
+
}, Ac = async (e, t, n, r) => {
|
|
1781
|
+
let { store: i, placement: a } = kc(e, t, n);
|
|
2029
1782
|
return await r(i, a), a;
|
|
2030
|
-
},
|
|
1783
|
+
}, jc = (e) => {
|
|
2031
1784
|
if (typeof e == "string") return e;
|
|
2032
1785
|
if ("jsonPath" in e) {
|
|
2033
1786
|
let { column: t, path: n, numeric: r } = e.jsonPath;
|
|
2034
1787
|
return `(json:${t}->${n.join(".")}${r ? "::num" : ""})`;
|
|
2035
1788
|
}
|
|
2036
1789
|
return `(${e.expr})`;
|
|
2037
|
-
}, Q = (e) => e.map(
|
|
1790
|
+
}, Q = (e) => e.map(jc), Mc = (e, t) => {
|
|
2038
1791
|
if (e.length !== t.length) return !1;
|
|
2039
|
-
for (let n = 0; n < e.length; n++) if (
|
|
1792
|
+
for (let n = 0; n < e.length; n++) if (jc(e[n]) !== jc(t[n])) return !1;
|
|
2040
1793
|
return !0;
|
|
2041
|
-
},
|
|
1794
|
+
}, Nc = (e, t) => {
|
|
2042
1795
|
if (e.length >= t.length) return !1;
|
|
2043
|
-
for (let n = 0; n < e.length; n++) if (
|
|
1796
|
+
for (let n = 0; n < e.length; n++) if (jc(e[n]) !== jc(t[n])) return !1;
|
|
2044
1797
|
return !0;
|
|
2045
|
-
},
|
|
1798
|
+
}, Pc = (e) => {
|
|
2046
1799
|
let t = [], n = e.appliedIndexes, r = e.tableName;
|
|
2047
1800
|
for (let e = 0; e < n.length; e++) {
|
|
2048
1801
|
let i = n[e];
|
|
2049
1802
|
for (let a = e + 1; a < n.length; a++) {
|
|
2050
1803
|
let e = n[a];
|
|
2051
|
-
if (
|
|
1804
|
+
if (Mc(i.fields, e.fields)) {
|
|
2052
1805
|
let [n, a] = i.name < e.name ? [i, e] : [e, i];
|
|
2053
1806
|
t.push({
|
|
2054
1807
|
kind: "duplicate-fields",
|
|
@@ -2059,13 +1812,13 @@ $voltro_branch$`;
|
|
|
2059
1812
|
});
|
|
2060
1813
|
continue;
|
|
2061
1814
|
}
|
|
2062
|
-
|
|
1815
|
+
Nc(i.fields, e.fields) ? t.push({
|
|
2063
1816
|
kind: "redundant-prefix",
|
|
2064
1817
|
table: r,
|
|
2065
1818
|
redundant: i,
|
|
2066
1819
|
coveredBy: e,
|
|
2067
1820
|
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).`
|
|
2068
|
-
}) :
|
|
1821
|
+
}) : Nc(e.fields, i.fields) && t.push({
|
|
2069
1822
|
kind: "redundant-prefix",
|
|
2070
1823
|
table: r,
|
|
2071
1824
|
redundant: e,
|
|
@@ -2075,23 +1828,23 @@ $voltro_branch$`;
|
|
|
2075
1828
|
}
|
|
2076
1829
|
}
|
|
2077
1830
|
return t;
|
|
2078
|
-
},
|
|
1831
|
+
}, Fc = (e) => {
|
|
2079
1832
|
let t = [];
|
|
2080
|
-
for (let n of e) t.push(...
|
|
1833
|
+
for (let n of e) t.push(...Pc(n));
|
|
2081
1834
|
return t;
|
|
2082
|
-
},
|
|
2083
|
-
let n = t.color ?? !0, r = t.indent ?? " ", i = (e) => $(n,
|
|
1835
|
+
}, Ic = "\x1B[", Lc = `${Ic}38;2;245;158;11m`, Rc = `${Ic}38;2;16;185;129m`, zc = (e, t) => `${e}${t}${A.reset}`, $ = (e, t, n) => e ? typeof t == "function" ? t(n) : zc(t, n) : n, Bc = (e, t = {}) => {
|
|
1836
|
+
let n = t.color ?? !0, r = t.indent ?? " ", i = (e) => $(n, A.dim, e.padEnd(11)), a = (e) => $(n, (e) => A.bold(A.brand(e)), e), o = (e) => $(n, A.brightRed24, e), s = (e) => $(n, Rc, e), c = (e) => $(n, Lc, e), l = (e) => $(n, A.dim, e), u = `${c("index audit")} ${l("·")} ${$(n, A.bold, e.kind)}`, d = e.redundant.fields.length, f = Q(e.coveredBy.fields.slice(d)), p = (e, t) => {
|
|
2084
1837
|
let n = e.slice(0, t), r = e.slice(t), i = [];
|
|
2085
1838
|
return n.length > 0 && i.push(s(`[${n.join(", ")}]`)), r.length > 0 && i.push(c(`+ [${r.join(", ")}]`)), i.join(" ");
|
|
2086
1839
|
}, m = [];
|
|
2087
|
-
return m.push(u), m.push(""), m.push(`${i("table")}${a(e.table)}`), m.push(""), m.push(`${i("redundant")}${o(e.redundant.name)}`), m.push(`${i("")}${p(Q(e.redundant.fields), d)}`), m.push(""), m.push(`${i("covered by")}${s(e.coveredBy.name)}`), m.push(`${i("")}${p(Q(e.coveredBy.fields), d)}`), f.length > 0 && m.push(`${i("")}${l(`└ extra columns: ${f.join(", ")}`)}`), m.push(""), e.kind === "redundant-prefix" ? (m.push(`${i("why")}B-tree indexes serve queries that filter on a LEADING PREFIX of`), m.push(`${i("")}their column list. The wider index already covers every`), m.push(`${i("")}query the narrower one can serve.`), m.push(`${i("")}${l("Same rule on Postgres / MySQL / MariaDB / MSSQL / SQLite.")}`)) : (m.push(`${i("why")}Two indexes on the same columns under different names.`), m.push(`${i("")}The B-tree engine builds both — same coverage, double cost.`), m.push(`${i("")}${l("Same rule on Postgres / MySQL / MariaDB / MSSQL / SQLite.")}`)), m.push(""), m.push(`${i("cost")}Every ${a("INSERT")} / ${a("UPDATE")} / ${a("DELETE")} on this table writes`), m.push(`${i("")}to ${$(n,
|
|
2088
|
-
},
|
|
1840
|
+
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, A.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");
|
|
1841
|
+
}, Vc = (e, { apply: t, undo: n }) => ({
|
|
2089
1842
|
name: e,
|
|
2090
1843
|
apply: t,
|
|
2091
1844
|
undo: n
|
|
2092
|
-
}),
|
|
1845
|
+
}), Hc = (e) => {
|
|
2093
1846
|
if (!/^\d{14}_/.test(e.id)) throw Error(`migration "${e.id}": id must start with a 14-digit timestamp followed by "_" (convention: <YYYYMMDDHHMMSS>_<slug>)`);
|
|
2094
|
-
let t = e.steps({ step:
|
|
1847
|
+
let t = e.steps({ step: Vc });
|
|
2095
1848
|
if (t.length === 0) throw Error(`migration "${e.id}": at least one step is required`);
|
|
2096
1849
|
return {
|
|
2097
1850
|
__migration: !0,
|
|
@@ -2099,89 +1852,42 @@ $voltro_branch$`;
|
|
|
2099
1852
|
name: e.name,
|
|
2100
1853
|
steps: t
|
|
2101
1854
|
};
|
|
2102
|
-
},
|
|
2103
|
-
let [
|
|
2104
|
-
table:
|
|
2105
|
-
predicate:
|
|
1855
|
+
}, Uc = (e) => typeof e == "object" && !!e && "__migration" in e && e.__migration === !0, Wc = ft.tableName, Gc = (e) => xr("sha256").update(`${e.type}\u0000${e.id}`, "utf8").digest("hex"), Kc = async (t, n) => {
|
|
1856
|
+
let [r] = await t.query({
|
|
1857
|
+
table: Wc,
|
|
1858
|
+
predicate: e("id", Gc(n)),
|
|
2106
1859
|
order: [],
|
|
2107
1860
|
take: 1,
|
|
2108
1861
|
skip: void 0,
|
|
2109
1862
|
projection: void 0
|
|
2110
|
-
}),
|
|
2111
|
-
return typeof
|
|
2112
|
-
},
|
|
2113
|
-
await e.upsert(
|
|
2114
|
-
id:
|
|
1863
|
+
}), i = r?.tenantId;
|
|
1864
|
+
return typeof i == "string" ? i : null;
|
|
1865
|
+
}, qc = async (e, t, n) => {
|
|
1866
|
+
await e.upsert(Wc, {
|
|
1867
|
+
id: Gc(t),
|
|
2115
1868
|
subjectType: t.type,
|
|
2116
1869
|
subjectId: t.id,
|
|
2117
1870
|
tenantId: n,
|
|
2118
1871
|
selectedAt: /* @__PURE__ */ new Date()
|
|
2119
1872
|
}, { conflictColumns: ["id"] });
|
|
2120
|
-
},
|
|
2121
|
-
await e.delete(
|
|
2122
|
-
},
|
|
2123
|
-
|
|
2124
|
-
startedAt: E().default("now"),
|
|
2125
|
-
kind: T().default("replace"),
|
|
2126
|
-
tables: T().nullable(),
|
|
2127
|
-
capture: T().nullable(),
|
|
2128
|
-
via: T(),
|
|
2129
|
-
staging: T().nullable(),
|
|
2130
|
-
heartbeatAt: E().nullable(),
|
|
2131
|
-
resumable: Ln().nullable()
|
|
2132
|
-
}), tl = 30, nl = (e, t) => {
|
|
2133
|
-
let n = typeof t == "number" && Number.isFinite(t) && t > 0 ? t : 30, r = Number(e.VOLTRO_STAGING_STALE_MINUTES);
|
|
2134
|
-
return (Number.isFinite(r) && r > 0 ? r : n) * 6e4;
|
|
2135
|
-
}, rl = (e) => e == null || String(e).length === 0 ? [] : String(e).split(",").map((e) => e.trim()).filter((e) => e.length > 0), il = (e) => {
|
|
2136
|
-
let t = e.filter((e) => e.kind !== "staging");
|
|
2137
|
-
if (t.length !== 0) return `refusing to start: a destructive data operation did not finish.
|
|
2138
|
-
${t.map((e) => {
|
|
2139
|
-
let t = Number.isFinite(e.startedAt.getTime()) ? `${Math.max(0, Math.round((Date.now() - e.startedAt.getTime()) / 6e4))} minute(s) ago` : "at an unknown time";
|
|
2140
|
-
if (e.kind === "restore") return ` - a native \`restore\` over ${e.via} began loading an artefact over this database ${t}\n and never reported finishing.\n` + (e.capture === null ? " The artefact it was loading was not recorded. Re-run the restore from your backup\n directory, or restore from another backup." : ` The artefact it was loading:\n ${e.capture}\n Re-run it to completion with: voltro data restore ${e.capture} --allow-live`);
|
|
2141
|
-
let n = e.tables === null ? "this database" : `${e.tables} table(s)`;
|
|
2142
|
-
return ` - a \`replace\` over ${e.via} began emptying ${n} ${t} and never reported finishing.\n` + (e.capture === null ? " NO capture was taken for that run, so the previous rows are not recoverable from here.\n Restore from your own backup." : ` The target's previous rows were captured first:\n ${e.capture}\n Restore them with: voltro data import ${e.capture} --mode replace`);
|
|
2143
|
-
}).join("\n")}\n
|
|
2144
|
-
A half-replaced database is indistinguishable from an empty one from the inside — every table
|
|
2145
|
-
exists, every constraint holds, and every query returns nothing without erroring. That is why
|
|
2146
|
-
this is a refusal and not a warning.
|
|
2147
|
-
|
|
2148
|
-
When the data is back, or you have decided the current state is correct, clear the marker:
|
|
2149
|
-
voltro data clear-replace-marker --yes`;
|
|
2150
|
-
}, al = (e, t, n) => {
|
|
2151
|
-
let r = e.filter((e) => e.kind === "staging");
|
|
2152
|
-
return {
|
|
2153
|
-
all: r,
|
|
2154
|
-
droppable: r.filter((e) => {
|
|
2155
|
-
if (e.resumable) return !1;
|
|
2156
|
-
let r = (e.heartbeatAt ?? e.startedAt).getTime();
|
|
2157
|
-
return Number.isFinite(r) ? t - r >= n : !1;
|
|
2158
|
-
})
|
|
2159
|
-
};
|
|
2160
|
-
}, ol = (e, t) => {
|
|
2161
|
-
if (e.all.length === 0) return;
|
|
2162
|
-
let n = new Set(e.droppable.map((e) => e.id));
|
|
2163
|
-
return `staged data-import leftovers:
|
|
2164
|
-
${e.all.map((e) => {
|
|
2165
|
-
let r = e.heartbeatAt ?? e.startedAt, i = Number.isFinite(r.getTime()) ? `${Math.max(0, Math.round((t - r.getTime()) / 6e4))} minute(s) ago` : "at an unknown time", a = `${e.staging.length} staging table(s) from a \`replace\` over ${e.via}, last active ${i}`;
|
|
2166
|
-
return n.has(e.id) ? ` - ${a} — DROPPED: the run is not resumable and has been silent long enough that nothing is loading into them.` : e.resumable ? ` - ${a} — KEPT: the run was started \`--no-atomic\`, so these ARE its resume point. Re-run the same\n bundle to continue from them, or drop them with: voltro data clear-staging --yes` : ` - ${a} — KEPT: still beating, so an import is loading into them right now.`;
|
|
2167
|
-
}).join("\n")}\n The target of a staged \`replace\` is untouched until one short swap at the end, so none of this is
|
|
2168
|
-
a reason to refuse the boot — it is a reason to know the disk is holding a copy of a bundle.`;
|
|
2169
|
-
}, sl = "id", cl = (e, t) => {
|
|
2170
|
-
let n = cn(e);
|
|
1873
|
+
}, Jc = async (e, t) => {
|
|
1874
|
+
await e.delete(Wc, Gc(t));
|
|
1875
|
+
}, Yc = "id", Xc = (e, t) => {
|
|
1876
|
+
let n = ln(e);
|
|
2171
1877
|
if (n === void 0) return t;
|
|
2172
|
-
let r = n.fields[
|
|
2173
|
-
if (r === void 0 || t[
|
|
1878
|
+
let r = n.fields[Yc]?.idScheme;
|
|
1879
|
+
if (r === void 0 || t[Yc] != null) return t;
|
|
2174
1880
|
if (r.kind === "numeric") {
|
|
2175
|
-
if (!(
|
|
1881
|
+
if (!(Yc in t)) return t;
|
|
2176
1882
|
let e = { ...t };
|
|
2177
|
-
return delete e[
|
|
1883
|
+
return delete e[Yc], e;
|
|
2178
1884
|
}
|
|
2179
|
-
let i =
|
|
1885
|
+
let i = Xt(r, e);
|
|
2180
1886
|
return i === null ? t : {
|
|
2181
1887
|
...t,
|
|
2182
|
-
[
|
|
1888
|
+
[Yc]: i
|
|
2183
1889
|
};
|
|
2184
|
-
},
|
|
1890
|
+
}, Zc = (e, t) => t.map((t) => Xc(e, t)), Qc = {
|
|
2185
1891
|
postgres: { maxBindParameters: 65535 },
|
|
2186
1892
|
mysql: { maxBindParameters: 65535 },
|
|
2187
1893
|
mariadb: { maxBindParameters: 65535 },
|
|
@@ -2191,25 +1897,25 @@ ${e.all.map((e) => {
|
|
|
2191
1897
|
},
|
|
2192
1898
|
sqlite: { maxBindParameters: 32766 },
|
|
2193
1899
|
turso: { maxBindParameters: 32766 }
|
|
2194
|
-
},
|
|
1900
|
+
}, $c = (e) => Qc[e], el = (e) => {
|
|
2195
1901
|
let t = /* @__PURE__ */ new Set();
|
|
2196
1902
|
for (let n of e) for (let e of Object.keys(n)) t.add(e);
|
|
2197
1903
|
return t.size;
|
|
2198
|
-
},
|
|
1904
|
+
}, tl = (e, t) => {
|
|
2199
1905
|
if (t === void 0 || e.length === 0) return [e];
|
|
2200
|
-
let n = Math.max(1,
|
|
1906
|
+
let n = Math.max(1, el(e)), r = Math.floor(t.maxBindParameters / n), i = t.maxRowsPerStatement ?? Infinity, a = Math.max(1, Math.min(r, i));
|
|
2201
1907
|
if (e.length <= a) return [e];
|
|
2202
1908
|
let o = [];
|
|
2203
1909
|
for (let t = 0; t < e.length; t += a) o.push(e.slice(t, t + a));
|
|
2204
1910
|
return o;
|
|
2205
|
-
},
|
|
1911
|
+
}, nl = (e, t) => {
|
|
2206
1912
|
let n = [], r = t;
|
|
2207
1913
|
for (let [t, i] of Object.entries(e.fields)) {
|
|
2208
1914
|
let e = i;
|
|
2209
1915
|
e.nullable || e.hasDefault || e.idScheme !== void 0 || e.generatedAs !== void 0 || (r[t] === void 0 || r[t] === null) && n.push(t);
|
|
2210
1916
|
}
|
|
2211
1917
|
return n;
|
|
2212
|
-
},
|
|
1918
|
+
}, rl = (e, t, n) => {
|
|
2213
1919
|
let r = n, i = new Set(e === void 0 ? [] : Object.entries(e.fields).filter(([, e]) => e.generatedAs !== void 0).map(([e]) => e)), a = [];
|
|
2214
1920
|
for (let e of t) i.has(e) || (r[e] === void 0 ? a.push({
|
|
2215
1921
|
column: e,
|
|
@@ -2219,36 +1925,36 @@ ${e.all.map((e) => {
|
|
|
2219
1925
|
reason: "null"
|
|
2220
1926
|
}));
|
|
2221
1927
|
return a;
|
|
2222
|
-
},
|
|
1928
|
+
}, il = (e, t, n) => e.insert(t.tableName, n), al = (e, t, n) => e.insertMany(t.tableName, n), ol = (e, t, n, r) => e.upsert(t.tableName, n, {
|
|
2223
1929
|
conflictColumns: r.conflictColumns,
|
|
2224
1930
|
...r.update === void 0 ? {} : { update: r.update },
|
|
2225
1931
|
...r.updateValues === void 0 ? {} : { updateValues: r.updateValues }
|
|
2226
|
-
}),
|
|
2227
|
-
if (e.upsertWithOutcome === void 0) throw
|
|
1932
|
+
}), sl = async (e, t, n, r) => {
|
|
1933
|
+
if (e.upsertWithOutcome === void 0) throw y("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.");
|
|
2228
1934
|
return e.upsertWithOutcome(t.tableName, n, {
|
|
2229
1935
|
conflictColumns: r.conflictColumns,
|
|
2230
1936
|
...r.update === void 0 ? {} : { update: r.update },
|
|
2231
1937
|
...r.updateValues === void 0 ? {} : { updateValues: r.updateValues }
|
|
2232
1938
|
});
|
|
2233
|
-
},
|
|
1939
|
+
}, cl = async (e, t, n, r) => e.insertIgnoreWithOutcome(t.tableName, n, { conflictColumns: r.conflictColumns }), ll = (e, t, n, r) => e.updateMany(t.tableName, n, { where: r.where }), ul = 512, dl = (e) => {
|
|
2234
1940
|
e.setMaxListeners(512);
|
|
2235
|
-
},
|
|
1941
|
+
}, fl = (e, t, n) => ({
|
|
2236
1942
|
_tag: "PrimaryKeyConflictError",
|
|
2237
1943
|
table: e,
|
|
2238
1944
|
key: t,
|
|
2239
1945
|
cause: n
|
|
2240
|
-
}),
|
|
1946
|
+
}), pl = (e) => typeof e == "object" && !!e && e._tag === "PrimaryKeyConflictError", ml = {
|
|
2241
1947
|
postgres: 5432,
|
|
2242
1948
|
mysql: 3306,
|
|
2243
1949
|
mariadb: 3306,
|
|
2244
1950
|
mssql: 1433
|
|
2245
|
-
},
|
|
1951
|
+
}, hl = /* @__PURE__ */ new Set([
|
|
2246
1952
|
"localhost",
|
|
2247
1953
|
"127.0.0.1",
|
|
2248
1954
|
"::1",
|
|
2249
1955
|
"[::1]",
|
|
2250
1956
|
"0.0.0.0"
|
|
2251
|
-
]),
|
|
1957
|
+
]), gl = (e) => {
|
|
2252
1958
|
let t = e.host, n = e.port, r = e.database;
|
|
2253
1959
|
if (e.url !== void 0 && e.url !== "") try {
|
|
2254
1960
|
let i = new URL(e.url);
|
|
@@ -2257,29 +1963,29 @@ ${e.all.map((e) => {
|
|
|
2257
1963
|
return;
|
|
2258
1964
|
}
|
|
2259
1965
|
if (t === void 0 || t === "" || r === void 0 || r === "") return;
|
|
2260
|
-
let i = n ??
|
|
1966
|
+
let i = n ?? ml[(e.dialect ?? "").toLowerCase()];
|
|
2261
1967
|
if (i === void 0 || !Number.isFinite(i)) return;
|
|
2262
1968
|
let a = t.toLowerCase();
|
|
2263
1969
|
return {
|
|
2264
|
-
host:
|
|
1970
|
+
host: hl.has(a) ? "localhost" : a,
|
|
2265
1971
|
port: i,
|
|
2266
1972
|
database: r.toLowerCase()
|
|
2267
1973
|
};
|
|
2268
|
-
},
|
|
2269
|
-
let t =
|
|
2270
|
-
if (t !== void 0) return
|
|
2271
|
-
},
|
|
1974
|
+
}, _l = (e) => {
|
|
1975
|
+
let t = gl(e);
|
|
1976
|
+
if (t !== void 0) return xr("sha256").update(`${t.host}\u0000${t.port}\u0000${t.database}`).digest("hex").slice(0, 32);
|
|
1977
|
+
}, vl = (e, t) => e === void 0 || t === void 0 ? "unknown" : e === t ? "same" : "different", yl = {
|
|
2272
1978
|
app: 3,
|
|
2273
1979
|
plugin: 2,
|
|
2274
1980
|
framework: 1
|
|
2275
|
-
},
|
|
1981
|
+
}, bl = /* @__PURE__ */ new Map(), xl = [], Sl = () => [...xl], Cl = (e) => {
|
|
2276
1982
|
if (!e.table || !e.timeColumn) throw Error("registerRetention: table + timeColumn are required");
|
|
2277
1983
|
if (!Number.isFinite(e.ttlMs) || e.ttlMs <= 0) throw Error(`registerRetention(${e.table}): ttlMs must be a positive number`);
|
|
2278
|
-
let t = e.source ?? "app", n =
|
|
1984
|
+
let t = e.source ?? "app", n = bl.get(e.table);
|
|
2279
1985
|
if (n !== void 0) {
|
|
2280
1986
|
let r = n.source ?? "app", i = n.ttlMs !== e.ttlMs || n.where !== void 0 != (e.where !== void 0);
|
|
2281
|
-
if (
|
|
2282
|
-
i &&
|
|
1987
|
+
if (yl[t] < yl[r]) {
|
|
1988
|
+
i && xl.push({
|
|
2283
1989
|
table: e.table,
|
|
2284
1990
|
kept: {
|
|
2285
1991
|
source: r,
|
|
@@ -2292,7 +1998,7 @@ ${e.all.map((e) => {
|
|
|
2292
1998
|
});
|
|
2293
1999
|
return;
|
|
2294
2000
|
}
|
|
2295
|
-
i && r !== t &&
|
|
2001
|
+
i && r !== t && xl.push({
|
|
2296
2002
|
table: e.table,
|
|
2297
2003
|
kept: {
|
|
2298
2004
|
source: t,
|
|
@@ -2304,13 +2010,13 @@ ${e.all.map((e) => {
|
|
|
2304
2010
|
}
|
|
2305
2011
|
});
|
|
2306
2012
|
}
|
|
2307
|
-
|
|
2013
|
+
bl.set(e.table, {
|
|
2308
2014
|
...e,
|
|
2309
2015
|
source: t
|
|
2310
2016
|
});
|
|
2311
|
-
},
|
|
2312
|
-
|
|
2313
|
-
},
|
|
2017
|
+
}, wl = () => [...bl.values()], Tl = () => {
|
|
2018
|
+
bl.clear(), xl.length = 0;
|
|
2019
|
+
}, El = async (e, t, n, r = 2e4) => {
|
|
2314
2020
|
let i = new Date(t - e.ttlMs), a = 0;
|
|
2315
2021
|
try {
|
|
2316
2022
|
for (;;) {
|
|
@@ -2318,45 +2024,45 @@ ${e.all.map((e) => {
|
|
|
2318
2024
|
if (a += t, t < r) break;
|
|
2319
2025
|
}
|
|
2320
2026
|
} catch (t) {
|
|
2321
|
-
throw
|
|
2027
|
+
throw E.runSync(D.increment(D.tagged(Ol, "table", e.table))), t;
|
|
2322
2028
|
}
|
|
2323
|
-
return a > 0 &&
|
|
2324
|
-
},
|
|
2029
|
+
return a > 0 && E.runSync(D.incrementBy(D.tagged(Dl, "table", e.table), a)), a;
|
|
2030
|
+
}, Dl = D.counter("voltro_retention_swept_rows_total"), Ol = D.counter("voltro_retention_sweep_errors_total"), kl = (e, t) => {
|
|
2325
2031
|
let n = Number(e ?? String(t));
|
|
2326
2032
|
return (Number.isFinite(n) && n > 0 ? n : t) * 36e5;
|
|
2327
|
-
},
|
|
2328
|
-
id:
|
|
2329
|
-
replicaId:
|
|
2330
|
-
streamName:
|
|
2331
|
-
binlogFile:
|
|
2332
|
-
binlogPosition:
|
|
2333
|
-
updatedAt:
|
|
2334
|
-
}).index(["replicaId"]),
|
|
2335
|
-
id:
|
|
2336
|
-
replicaId:
|
|
2337
|
-
streamName:
|
|
2338
|
-
ctVersion:
|
|
2339
|
-
updatedAt:
|
|
2340
|
-
}).index(["replicaId"]),
|
|
2341
|
-
id:
|
|
2342
|
-
startedAt:
|
|
2343
|
-
finishedAt:
|
|
2344
|
-
direction:
|
|
2345
|
-
mode:
|
|
2346
|
-
via:
|
|
2347
|
-
bundle:
|
|
2348
|
-
sourceFingerprint:
|
|
2349
|
-
tablesWritten:
|
|
2350
|
-
rowsWritten:
|
|
2351
|
-
failure:
|
|
2352
|
-
staged:
|
|
2353
|
-
}).renamedFrom("_voltro_data_imports").nonReactive(),
|
|
2033
|
+
}, Al = "_voltro_cdc_offsets", jl = S(Al, {
|
|
2034
|
+
id: C({ prefix: "cdcoff" }),
|
|
2035
|
+
replicaId: b(),
|
|
2036
|
+
streamName: b(),
|
|
2037
|
+
binlogFile: b(),
|
|
2038
|
+
binlogPosition: b(),
|
|
2039
|
+
updatedAt: x()
|
|
2040
|
+
}).index(["replicaId"]), Ml = S(Al, {
|
|
2041
|
+
id: C({ prefix: "cdcoff" }),
|
|
2042
|
+
replicaId: b(),
|
|
2043
|
+
streamName: b(),
|
|
2044
|
+
ctVersion: b(),
|
|
2045
|
+
updatedAt: x()
|
|
2046
|
+
}).index(["replicaId"]), Nl = "_voltro_data_transfers", Pl = S(Nl, {
|
|
2047
|
+
id: C({ prefix: "dimp" }),
|
|
2048
|
+
startedAt: x().default("now"),
|
|
2049
|
+
finishedAt: x().nullable(),
|
|
2050
|
+
direction: b().default("import"),
|
|
2051
|
+
mode: b(),
|
|
2052
|
+
via: b(),
|
|
2053
|
+
bundle: b().nullable(),
|
|
2054
|
+
sourceFingerprint: b().nullable(),
|
|
2055
|
+
tablesWritten: $n().default(0),
|
|
2056
|
+
rowsWritten: $n().default(0),
|
|
2057
|
+
failure: b().nullable(),
|
|
2058
|
+
staged: Tt().nullable()
|
|
2059
|
+
}).renamedFrom("_voltro_data_imports").nonReactive(), Fl = (e) => {
|
|
2354
2060
|
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)";
|
|
2355
2061
|
return `${t} · ${r} · via ${e.via}${i}` + (e.bundle === null ? "" : ` · from ${e.bundle}`) + (e.sourceFingerprint === null ? "" : ` · source schema ${e.sourceFingerprint}`);
|
|
2356
|
-
},
|
|
2062
|
+
}, Il = 255, Ll = (e) => e == null ? "null" : typeof e == "string" || typeof e == "number" || typeof e == "boolean" ? JSON.stringify(e) : Array.isArray(e) ? `[${e.map(Ll).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)}:${Ll(t)}`).join(",")}}` : JSON.stringify(String(e)), Rl = (e) => {
|
|
2357
2063
|
if (e == null) return null;
|
|
2358
|
-
let t = typeof e == "string" ? e :
|
|
2064
|
+
let t = typeof e == "string" ? e : Ll(e);
|
|
2359
2065
|
return t.length > 255 ? t.slice(0, 255) : t;
|
|
2360
|
-
},
|
|
2066
|
+
}, zl = "postgres";
|
|
2361
2067
|
//#endregion
|
|
2362
|
-
export {
|
|
2068
|
+
export { d as AUTO_FILLED_COLUMNS, Mr as BOUND_ENCRYPTED_PREFIX, Qc as BULK_INSERT_LIMITS, Y as BranchNameInvalid, nc as BranchTransitionInvalid, Al as CDC_OFFSETS_TABLE, ho as CHANGE_CLAIM_TTL_ENV, ul as CHANGE_LISTENER_CEILING, qt as ColumnBuilder, Nl as DATA_TRANSFERS_TABLE, tr as DEFAULT_ACQUIRE_TIMEOUT_MS, go as DEFAULT_CHANGE_CLAIM_TTL_HOURS, ms as DEFAULT_EAGER_FALLBACK_WARN_INTERVAL_MS, er as DEFAULT_SOFT_DROP_RETENTION_DAYS, Ci as DEFAULT_SUBJECT_GRAPH_DEPTH, jr as ENCRYPTED_PREFIX, zl as ENGINE, Hi as EagerCardinalityError, $t as FILE_MIGRATION_PATTERN, bt as FRAMEWORK_LIVE_TABLES, Fr as FieldDecryptionError, Io as ID_COLUMN_MAX_LENGTH, dr as INITIAL_VERSION, r as IrreversibleMigrationError, ge as MATCHES_NO_ROWS, re as MAX_IDENTIFIER_LENGTH, js as MSSQL_TRANSIENT_NUMBERS, ks as MYSQL_TRANSIENT_CODES, Yt as MigrationExpectationFailed, Se as MigrationNeedsSqlClient, we as MigrationSkipped, mo as OccurrenceCounter, As as POSTGRES_TRANSIENT_STATES, Fn as REPLACE_IN_PROGRESS_TABLE, je as RewriteUnstableError, Il as SCOPE_KEY_MAX_LENGTH, vt as SELF_REFERENCE_TARGET, Ms as SQLITE_TRANSIENT_CODES, fn as STAGING_STALE_MINUTES, Zn as STAGING_TABLE_PREFIX, wr as SqlClient, Wc as TENANT_SELECTIONS_TABLE, Ns as TURSO_TRANSIENT_MESSAGE, Ws as TableStreamError, g as TenantNamespaceInvalid, Ae as TenantNamespaceUnresolved, xc as TenantRegionUnavailable, bc as TenantResidencyUnresolved, Cs as TransactionAbortedError, ne as TransactionBrokenByBodyError, Rs as VOLTRO_EXPIRES_MIXIN_ID, Bs as VOLTRO_LOCAL_FIRST_MIXIN_ID, cr as VersionConflict, de as WARN_IDENTIFIER_LENGTH, rn as _voltroApiKeysTable, jl as _voltroCdcOffsetsTable, Pl as _voltroDataTransfersTable, zn as _voltroDevicesTable, Dt as _voltroIdempotencyTable, Nt as _voltroKvTable, bn as _voltroMigrationPlansTable, cn as _voltroMigrationsTable, Ml as _voltroMssqlCdcOffsetsTable, Dn as _voltroReplaceInProgressTable, Vt as _voltroReplicaObservationsTable, Lt as _voltroSeedsTable, ft as _voltroTenantSelectionsTable, ro as actorsTable, hc as admitBranch, Ve as agedSoftDropSnapshots, Ie as allEnumRenames, bi as allRegisteredRelations, Ot as allRegisteredTables, wn as and, Bi as applyJsonPatch, vn as array, pe as arrayContains, ot as arrayHas, rt as arrayOverlaps, Wi as attachEagerLoads, bo as attributionFields, wo as attributionKey, Fc as auditAllTableIndexes, Pc as auditTableIndexes, y as authoredError, Ye as authoredMessageOf, $e as avg, le as avgOver, jo as beginLocalWrite, Nn as bigint, kc as bindResidentStore, Tt as boolean, $s as branchNamespaceName, $c as bulkInsertLimitsFor, on as bytes, tt as causeBranches, so as changeDelete, uo as changeDigest, ao as changeInsert, co as changeSoftDelete, oo as changeUpdate, tl as chunkRowsForInsert, Do as claimPendingAttribution, oe as classifyConstraintViolation, t as clearEnumRenames, Po as clearPendingAttribution, Si as clearRelationsRegistry, Tc as clearResidencyConfig, Tl as clearRetentions, Pt as clearTableRegistry, Uo as clearWriteRecorders, V as coercePredicateForSqlite, qe as coercePredicateValue, te as coercePredicateValues, Ya as coerceValueForSqlite, lt as collectSubqueries, Xe as column, Xr as columnSchema, el as columnsPerRow, St as compareDecimal, ea as compileEagerJson, Vi as compileJsonPatch, T as compilePredicate, We as compileRawFragment, p as compileSelect, fo as composeChangeKey, Ys as computeEmbedding, _l as connectionIdentity, Fe as contains, nt as count, se as countDistinct, Vn as crdtDoc, kt as crdtManagedColumns, Ft as crdtManagedColumnsOf, Sn as crdtText, yo as currentWriteAttribution, ve as databaseHandle, un as date, Ut as dbEnum, cs as dbMetricTagCacheSizeForTests, ds as dbOperationsInFlight, zt as decimal, jt as declareEnumRename, Br as decodeFieldValue, Pe as decodeRowsForTable, ie as decodeRowsFromSchema, Kr as decryptFieldsOnRead, Hc as defineMigration, m as defineMixin, s as defineSeed, Jc as deleteTenantSelection, En as denseRank, Ai as deriveSubjectGraph, i as deriveTypeIdPrefix, zo as derivedRowId, Bo as derivedRowIdLength, u as describeAgedSoftDropSnapshots, _e as describeDriverError, Tn as describeRowBindings, Fl as describeTransferRun, Ar as deserializeArraysOnRead, be as drainIdentifierWarnings, mt as dropped, Rr as encodeFieldValue, fe as encodeRowForSchema, Gr as encryptFieldsForWrite, Ur as encryptedColumnsOf, Mo as endLocalWrite, fc as enforceBranchLimits, xn as ensureTableRegistered, e as eq, Xn as escapeLike, Mt as evaluatePredicate, he as except, Rn as exists, zs as expires, io as externalChangeEvent, me as extractDbCause, Nr as fieldBinding, Ze as fireSchemaChangeSeeds, ce as fireTenantCreateSeeds, Bc as formatIndexAuditIssue, ji as formatSubjectGraph, Un as frameworkTables, Xt as generateId, Te as generateSnowflake, Gn as geography, nr as geometry, Ln as getEnumRenames, yi as getRelation, vi as getRelations, wc as getResidencyConfig, ln as getTable, hn as gt, An as gte, $i as hasEagerLoads, Js as hybridSearch, C as id, Jt as inSet, yt as inSubquery, li as inferForeignKey, cl as insertIgnoreRowOutcome, al as insertManyRows, il as insertRow, $n as integer, Gt as interruptedReplaceRefusal, ct as intersect, Ue as interval, ue as irreversible, ye as irreversibleReason, Pr as isBoundCiphertext, ec as isBranchNamespace, Ii as isCompositeRowKey, ii as isEmptyRelationsSpec, Lr as isEncrypted, Ir as isFieldDecryptionError, Re as isFileMigration, st as isForeignKeyViolation, qn as isFrameworkOwnedLiveTable, Hs as isLocalFirst, Uc as isMigrationDefinition, xt as isMysqlFamily, oc as isNeonConnection, yn as isNotNull, Pn as isNull, pl as isPrimaryKeyConflictError, it as isQueryTimeout, Vr as isRawEncoding, Dc as isRegionServable, ai as isRelationsSpec, Je as isSeedDefinition, Ge as isSoftDropSnapshotName, Qn as isSqliteFamily, _ as isStagingTableName, Ht as isTableReactive, Es as isTransactionAbortedError, Is as isTransientContention, xe as isView, f as json, Et as jsonField, Jn as jsonIndex, Li as jsonPatchAssignments, at as lag, dt as lead, Sl as listRetentionConflicts, wl as listRetentions, Vs as localFirst, Us as localFirstTables, sn as lt, Hn as lte, _s as makeEagerFallbackReporter, yc as makeNamespaceBranchExecutor, ws as makeTransactionAbortTracker, si as many, ci as manyToMany, Yn as materializeFields, Le as max, ir as migration, n as min, rl as missingConflictColumns, nl as missingRequiredColumns, Oe as mixin, At as neq, rc as nextBranchState, gl as normaliseTarget, zi as normalizeJsonPatchValue, It as not, Cn as notExists, dn as notInSet, Wt as notInSubquery, Ke as numeric, ps as observeDbOp, _o as occurrenceWindowMs, oi as one, Ui as oneCardinalityMessage, Bt as or, w as orderClausesOf, In as paginateBy, pn as paginateById, po as parseChangeKey, Fo as pendingAttributionCount, uc as planBranch, ic as planBranchProvision, ac as planBranchTeardown, dc as planBranchTeardownFor, cc as planNeonBranchProvision, lc as planNeonBranchTeardown, sr as planVersionedUpdate, mn as pluginRef, kn as pluginRefSpecOf, fl as primaryKeyConflictError, pc as provisionBranch, Ac as provisionResidentTenant, nn as qualifyTable, On as queryFor, Be as queryForView, He as quoteIdent, dl as raiseChangeListenerCeiling, Kt as rank, ee as raw, Kc as readTenantSelection, h as readableByColumns, ke as real, fs as recordDbOp, Jo as recordsTable, tn as reference, Jr as refuseWrite, $a as registerCoreTables, _i as registerDiscoveredRelations, Eo as registerPendingAttribution, gi as registerRelations, Cl as registerRetention, Rt as registerTable, Vo as registerWriteRecorder, ri as relations, to as requireActors, pt as requireTable, no as requireTenants, ss as resetDbMetricTagCacheForTests, Me as resetSnowflake, Oc as residentPlacement, Er as resolveActorSnapshot, sc as resolveBranchMechanism, gs as resolveEagerFallbackWarnIntervalMs, No as resolveEchoAttribution, _t as resolveFullTextIndex, Ce as resolveIdScheme, en as resolveMixinGraph, Ec as resolveTenantHome, o as resolveTenantNamespace, kl as retentionTtlMsFromEnv, Pi as rowKeyColumns, Fi as rowKeyIdentity, _n as rowNumber, Zr as rowSchema, Ss as runRetryingTransaction, Ts as runSavepoint, Os as runStoreTransaction, vo as runWithWriteAttribution, Yo as runWriteRecorders, vl as sameDatabase, Qt as sanitizeIdentifierFragment, Rl as scopeKeyOf, a as selfReference, kr as serializeArraysForWrite, Zt as serverOnlyColumns, Cc as setResidencyConfig, et as setSchemaChangeSeedHook, ae as setTenantCreateSeedHook, vs as settleTransactionExit, ur as settleVersionedUpdate, De as softDropSnapshotStamp, ht as spatialPredicate, gt as stagingLeftoverReport, gn as stagingLeftovers, jn as stagingNamesOf, Ct as stagingStaleAfterMs, Xc as stampGeneratedId, Zc as stampGeneratedIds, Kn as startsWith, Yr as storeRefusalOf, qs as streamTable, Mn as sum, wt as sumOver, Go as suspendWriteRecorders, Ko as suspendWriteRecordersEffect, El as sweepRetention, S as table, mc as teardownBranch, Gc as tenantSelectionId, b as text, x as timestamp, pr as timestampMs, lr as timestampMsOrNull, xs as transactionRetrySchedule, an as union, Bn as unionAll, Wn as unregisterTable, Ho as unregisterWriteRecorder, ll as updateManyRow, ol as upsertRow, sl as upsertRowOutcome, Ni as upsertUpdatePatch, Mi as upsertUpdateValues, ze as validateColumnName, ar as validateIndexName, xi as validateRegisteredRelations, pi as validateRelationConfig, c as validateTableName, Qe as validateTypeIdPrefix, Ne as vector, v as vectorDistanceToOpclass, Xs as vectorEmbedding, fr as versionColumnOf, or as view, l as viewSql, rr as walkLeaves, ut as wireSafeCause, xo as withCapturedAttribution, qo as writeRecordersSuspended, qc as writeTenantSelection };
|