@voltro/database 0.80.0 → 0.82.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 +1610 -6
- package/dist/index.d.ts +83 -26
- package/dist/index.js +592 -583
- package/dist/{replaceInProgress-BmSjNTp0.js → replaceInProgress-BbN7p1Q-.js} +509 -461
- package/dist/sql.d.ts +421 -26
- package/dist/sql.js +1858 -1551
- package/package.json +2 -2
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, Ar as a, At as o, B as s, Bn as c,
|
|
2
|
-
import { a as
|
|
3
|
-
import { Cause as
|
|
4
|
-
import { createHash as
|
|
5
|
-
import { AsyncLocalStorage as
|
|
6
|
-
import { TransactionConnection 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, Br as l, Bt as u, C as d, Cn as f, Cr as p, Ct as m, D as h, Dn as g, Dr as _, Dt as v, E as ee, En as te, Er as y, Et as ne, F as re, Fn as ie, Fr as ae, Ft as oe, G as se, Gn as ce, Gt as le, H as ue, Hn as de, Ht as fe, I as pe, In as me, Ir as he, J as ge, Jn as _e, Jt as ve, K as ye, Kn as be, Kt as xe, L as Se, Ln as Ce, Lr as we, Lt as Te, M as Ee, Mn as De, Mr as Oe, Mt as ke, N as Ae, Nn as je, Nr as Me, Nt as Ne, O as Pe, On as Fe, Or as Ie, Ot as Le, P as Re, Pn as ze, Pr as Be, Pt as Ve, Q as He, Qn as Ue, Qt as We, R as Ge, Rn as Ke, Rr as b, Rt as qe, S as Je, Sn as Ye, Sr as Xe, St as Ze, T as Qe, Tn as $e, Tr as et, Tt as tt, U as nt, Un as rt, Ut as it, V as at, Vn as ot, Vt as st, W as ct, Wn as lt, Wt as ut, X as dt, Xn as ft, Xt as pt, Y as mt, Yn as ht, Yt as gt, Z as _t, Zn as vt, Zt as yt, _ as bt, _n as xt, _r as St, _t as Ct, a as wt, an as x, ar as Tt, at as Et, b as Dt, bn as Ot, br as kt, bt as At, c as jt, cn as Mt, cr as Nt, ct as Pt, d as Ft, dn as It, dr as Lt, dt as Rt, en as zt, er as Bt, et as Vt, f as Ht, fn as Ut, fr as Wt, ft as Gt, g as Kt, gn as qt, gr as Jt, gt as Yt, h as Xt, hn as Zt, hr as Qt, ht as $t, i as en, in as tn, ir as nn, it as rn, j as an, jn as on, jr as sn, jt as cn, kn as ln, kr as un, kt as dn, l as fn, ln as pn, lr as mn, lt as hn, m as gn, mn as _n, mr as vn, mt as yn, n as bn, nn as xn, nr as Sn, nt as Cn, o as wn, on as Tn, or as En, ot as Dn, p as On, pn as kn, pr as An, pt as jn, q as Mn, qn as S, qt as Nn, r as Pn, rn as Fn, rr as In, rt as Ln, s as Rn, sn as zn, sr as Bn, st as Vn, t as Hn, tn as Un, tr as Wn, tt as Gn, u as Kn, un as qn, ur as Jn, ut as Yn, v as Xn, vn as Zn, vr as Qn, vt as $n, w as er, wn as tr, wr as nr, wt as C, x as rr, xn as ir, xr as ar, xt as or, y as sr, yn as cr, yr as lr, yt as ur, z as dr, zn as fr, zr as w, zt as pr } from "./replaceInProgress-BbN7p1Q-.js";
|
|
2
|
+
import { a as mr, i as hr, n as gr, o as _r, r as vr, s as yr, t as br } from "./wire-B28cPjEp.js";
|
|
3
|
+
import { Cause as xr, Chunk as Sr, Data as Cr, Effect as T, Exit as wr, Metric as E, MetricBoundaries as Tr, Option as D, Schedule as Er, Schema as O, Stream as Dr } from "effect";
|
|
4
|
+
import { createHash as Or } from "node:crypto";
|
|
5
|
+
import { AsyncLocalStorage as kr } from "node:async_hooks";
|
|
6
|
+
import { TransactionConnection as Ar } from "@effect/sql/SqlClient";
|
|
7
7
|
import { ansi as k } from "@voltro/logger";
|
|
8
|
-
import { SqlClient as
|
|
8
|
+
import { SqlClient as jr } from "@effect/sql";
|
|
9
9
|
//#region src/actorSnapshot.ts
|
|
10
|
-
var
|
|
10
|
+
var Mr = (e) => typeof e == "string" && e !== "" ? e : null, Nr = 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 Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = 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: Mr(r.kind) ?? n,
|
|
27
|
+
displayName: Mr(r.displayName),
|
|
28
|
+
email: Mr(r.email)
|
|
29
29
|
};
|
|
30
30
|
} catch {
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
|
-
},
|
|
33
|
+
}, Pr = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqlite", Fr = (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
|
+
}, Ir = (e, t, n) => {
|
|
38
|
+
if (!Pr(n) || !t) return e;
|
|
39
|
+
let r = Fr(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 Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = 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
|
+
}, Lr = (e, t, n) => {
|
|
48
|
+
if (!Pr(n) || !t) return e;
|
|
49
|
+
let r = Fr(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 Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
58
58
|
}
|
|
59
59
|
return t ?? e;
|
|
60
60
|
});
|
|
61
|
-
},
|
|
61
|
+
}, Rr = "enc:v1:", zr = "enc:v2:", Br = (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
|
+
}, Vr = (e) => typeof e == "string" && e.startsWith("enc:v2:"), Hr = class extends Error {
|
|
68
68
|
_tag = "FieldDecryptionError";
|
|
69
69
|
table;
|
|
70
70
|
column;
|
|
@@ -72,7 +72,7 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = 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
|
+
}, Ur = (e) => typeof e == "object" && !!e && e._tag === "FieldDecryptionError", Wr = (e) => typeof e == "string" && (e.startsWith("enc:v1:") || e.startsWith("enc:v2:")), Gr = (e, t, n) => e.encrypt(JSON.stringify(t), n), Kr = /* @__PURE__ */ new Set([
|
|
76
76
|
"text",
|
|
77
77
|
"id",
|
|
78
78
|
"reference",
|
|
@@ -80,51 +80,51 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
80
80
|
"uuid",
|
|
81
81
|
"email",
|
|
82
82
|
"url"
|
|
83
|
-
]),
|
|
83
|
+
]), qr = (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 || Kr.has(n) ? i : a;
|
|
91
|
+
}, Jr = (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 || Kr.has(n) ? !0 : void 0;
|
|
95
95
|
} catch {
|
|
96
96
|
return !0;
|
|
97
97
|
}
|
|
98
|
-
},
|
|
98
|
+
}, Yr = (e, t) => e.fields[t]?.type, Xr = (e) => {
|
|
99
99
|
let t = [];
|
|
100
100
|
for (let [n, r] of Object.entries(e.fields)) r.encrypted === !0 && t.push(n);
|
|
101
101
|
return t;
|
|
102
|
-
},
|
|
102
|
+
}, Zr = "id", Qr = (e, t, n, r) => {
|
|
103
103
|
if (!t) return e;
|
|
104
|
-
let i =
|
|
104
|
+
let i = Xr(t);
|
|
105
105
|
if (i.length === 0) return e;
|
|
106
|
-
let a = t.tableName ?? "?", o = r ?? e[
|
|
106
|
+
let a = t.tableName ?? "?", o = r ?? e[Zr], s = { ...e };
|
|
107
107
|
for (let e of i) {
|
|
108
108
|
let t = s[e];
|
|
109
|
-
if (!(t == null ||
|
|
109
|
+
if (!(t == null || Wr(t))) {
|
|
110
110
|
if (!n) throw Error(`column "${a}.${e}" is .encrypted() but no field cipher is registered — set VOLTRO_FIELD_ENCRYPTION_KEY (\`voltro dev\` mints one; \`voltro serve\` refuses to boot without it); in a test, pass \`fieldEncryptionKey\` to makeTestContext`);
|
|
111
|
-
s[e] =
|
|
111
|
+
s[e] = Gr(n, t, Br(a, e, o));
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
return s;
|
|
115
|
-
},
|
|
115
|
+
}, $r = (e, t, n, r) => {
|
|
116
116
|
if (!t) return e;
|
|
117
|
-
let i =
|
|
117
|
+
let i = Xr(t);
|
|
118
118
|
if (i.length === 0 || !n) return e;
|
|
119
119
|
let a = r?.onError ?? "throw", o = t.tableName ?? "?";
|
|
120
120
|
return e.map((e) => {
|
|
121
121
|
let s;
|
|
122
122
|
for (let c of i) {
|
|
123
123
|
let i = e[c];
|
|
124
|
-
if (
|
|
124
|
+
if (Wr(i)) {
|
|
125
125
|
s ??= { ...e };
|
|
126
126
|
try {
|
|
127
|
-
s[c] =
|
|
127
|
+
s[c] = qr(n, i, Yr(t, c), Br(o, c, r?.rowId ?? e[Zr]));
|
|
128
128
|
} catch (e) {
|
|
129
129
|
let t = String(e?.message ?? e);
|
|
130
130
|
if (a === "null") {
|
|
@@ -135,7 +135,7 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
135
135
|
});
|
|
136
136
|
continue;
|
|
137
137
|
}
|
|
138
|
-
throw new
|
|
138
|
+
throw new Hr({
|
|
139
139
|
table: o,
|
|
140
140
|
column: c,
|
|
141
141
|
reason: t
|
|
@@ -145,22 +145,22 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
145
145
|
}
|
|
146
146
|
return s ?? e;
|
|
147
147
|
});
|
|
148
|
-
},
|
|
149
|
-
let t =
|
|
150
|
-
return Object.defineProperty(t,
|
|
148
|
+
}, ei = Symbol.for("@voltro/database/storeRefusal"), ti = (e) => {
|
|
149
|
+
let t = S(e.detail);
|
|
150
|
+
return Object.defineProperty(t, ei, {
|
|
151
151
|
value: e,
|
|
152
152
|
enumerable: !1
|
|
153
153
|
}), t;
|
|
154
|
-
},
|
|
155
|
-
for (let t of
|
|
154
|
+
}, ni = (e) => {
|
|
155
|
+
for (let t of ht(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[ei];
|
|
159
159
|
if (t !== void 0) return t;
|
|
160
160
|
e = e.cause;
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
|
-
},
|
|
163
|
+
}, ri = (e) => {
|
|
164
164
|
let t = (() => {
|
|
165
165
|
switch (e.type) {
|
|
166
166
|
case "id": return e.idScheme?.kind === "numeric" ? O.Number : O.String;
|
|
@@ -172,7 +172,7 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
172
172
|
case "decimal": return O.Number;
|
|
173
173
|
case "boolean": return O.Boolean;
|
|
174
174
|
case "timestamp":
|
|
175
|
-
case "date": return
|
|
175
|
+
case "date": return br;
|
|
176
176
|
case "bigint": return O.BigInt;
|
|
177
177
|
case "bytes": return O.Uint8ArrayFromBase64;
|
|
178
178
|
case "array": return O.Array(O.Unknown);
|
|
@@ -181,41 +181,41 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
181
181
|
}
|
|
182
182
|
})();
|
|
183
183
|
return e.nullable === !0 ? O.NullOr(t) : t;
|
|
184
|
-
},
|
|
184
|
+
}, ii = (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] =
|
|
186
|
+
for (let [t, i] of Object.entries(e.fields)) n.has(t) || (r[t] = ri(i));
|
|
187
187
|
return O.Struct(r);
|
|
188
|
-
},
|
|
188
|
+
}, ai = (e) => typeof e == "function" ? e : () => e, oi = (e, t) => ({
|
|
189
189
|
kind: "one",
|
|
190
|
-
target:
|
|
190
|
+
target: ai(e),
|
|
191
191
|
...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
|
|
192
192
|
...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
|
|
193
|
-
}),
|
|
193
|
+
}), si = (e, t) => ({
|
|
194
194
|
kind: "many",
|
|
195
|
-
target:
|
|
195
|
+
target: ai(e),
|
|
196
196
|
...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
|
|
197
197
|
...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
|
|
198
|
-
}),
|
|
198
|
+
}), ci = (e, t) => ({
|
|
199
199
|
kind: "manyToMany",
|
|
200
|
-
target:
|
|
201
|
-
through:
|
|
200
|
+
target: ai(e),
|
|
201
|
+
through: ai(t.through),
|
|
202
202
|
sourceKey: t.sourceKey,
|
|
203
203
|
targetKey: t.targetKey
|
|
204
|
-
}),
|
|
205
|
-
one:
|
|
206
|
-
many:
|
|
207
|
-
manyToMany:
|
|
208
|
-
},
|
|
204
|
+
}), li = {
|
|
205
|
+
one: oi,
|
|
206
|
+
many: si,
|
|
207
|
+
manyToMany: ci
|
|
208
|
+
}, ui = (e, t) => {
|
|
209
209
|
let n = typeof e == "function" ? e : () => e;
|
|
210
210
|
return {
|
|
211
211
|
source: n,
|
|
212
|
-
relations: t(
|
|
212
|
+
relations: t(li, n())
|
|
213
213
|
};
|
|
214
|
-
},
|
|
214
|
+
}, di = (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
|
+
}, fi = (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,32 +224,32 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
224
224
|
let t = e?.kind;
|
|
225
225
|
return t === "one" || t === "many" || t === "manyToMany";
|
|
226
226
|
});
|
|
227
|
-
},
|
|
227
|
+
}, pi = oi, mi = si, hi = ci, A = (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 S(`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 S(`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
|
+
}, gi = (e) => Object.keys(e.fields), j = (e, t) => Object.prototype.hasOwnProperty.call(e.fields, t), _i = (e) => {
|
|
234
|
+
let t = gi(e);
|
|
235
235
|
return t.length === 0 ? "<none>" : t.join(", ");
|
|
236
|
-
},
|
|
236
|
+
}, vi = (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 (!j(t, o)) throw
|
|
240
|
+
for (let [a, o] of [["sourceKey", n.sourceKey], ["targetKey", n.targetKey]]) if (!j(t, o)) throw S(`${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}': ${_i(t)}.`);
|
|
241
241
|
return;
|
|
242
242
|
}
|
|
243
|
-
if (n.sourceKey !== void 0 && n.foreignKey !== void 0) throw
|
|
243
|
+
if (n.sourceKey !== void 0 && n.foreignKey !== void 0) throw S(`${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
244
|
if (n.sourceKey !== void 0 && !j(e, n.sourceKey)) {
|
|
245
245
|
let t = j(i, n.sourceKey);
|
|
246
|
-
throw
|
|
246
|
+
throw S(`${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}': ${_i(e)}.`));
|
|
247
247
|
}
|
|
248
248
|
if (n.foreignKey !== void 0 && !j(i, n.foreignKey)) {
|
|
249
249
|
let t = j(e, n.foreignKey);
|
|
250
|
-
throw
|
|
250
|
+
throw S(`${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}': ${_i(i)}.`));
|
|
251
251
|
}
|
|
252
|
-
},
|
|
252
|
+
}, yi = Symbol.for("@voltro/database/relationsRegistry"), bi = globalThis, M = bi[yi] ?? (bi[yi] = /* @__PURE__ */ new Map()), xi = (e) => {
|
|
253
253
|
let t = e.source(), n = M.get(t.tableName);
|
|
254
254
|
if (n === void 0) {
|
|
255
255
|
M.set(t.tableName, new Map(Object.entries(e.relations)));
|
|
@@ -262,14 +262,14 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
262
262
|
n.set(r, i);
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
|
-
},
|
|
265
|
+
}, Si = (e) => {
|
|
266
266
|
let t = 0;
|
|
267
|
-
for (let n of Object.values(e))
|
|
267
|
+
for (let n of Object.values(e)) fi(n) && (xi(n), t += 1);
|
|
268
268
|
return t;
|
|
269
|
-
},
|
|
269
|
+
}, Ci = (e) => {
|
|
270
270
|
let t = M.get(e);
|
|
271
271
|
if (t !== void 0) return Object.fromEntries(t);
|
|
272
|
-
},
|
|
272
|
+
}, wi = (e, t) => M.get(e)?.get(t), Ti = () => {
|
|
273
273
|
let e = [];
|
|
274
274
|
for (let [t, n] of M) for (let [r, i] of n) e.push({
|
|
275
275
|
source: t,
|
|
@@ -277,18 +277,18 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
277
277
|
relation: i
|
|
278
278
|
});
|
|
279
279
|
return e;
|
|
280
|
-
},
|
|
280
|
+
}, Ei = () => {
|
|
281
281
|
for (let [e, t] of M) {
|
|
282
|
-
let n =
|
|
283
|
-
if (n !== void 0) for (let [e, r] of t)
|
|
282
|
+
let n = cr(e);
|
|
283
|
+
if (n !== void 0) for (let [e, r] of t) vi(n, e, r);
|
|
284
284
|
}
|
|
285
|
-
},
|
|
285
|
+
}, Di = () => {
|
|
286
286
|
M.clear();
|
|
287
|
-
},
|
|
287
|
+
}, Oi = 4, ki = (e) => Object.keys(e.fields), Ai = (e, t) => Object.prototype.hasOwnProperty.call(e.fields, t), ji = (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
|
+
}, Mi = (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 Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
305
305
|
} catch {
|
|
306
306
|
continue;
|
|
307
307
|
}
|
|
308
|
-
if (!
|
|
308
|
+
if (!Ai(e, t.sourceKey)) continue;
|
|
309
309
|
n.push({
|
|
310
310
|
table: e.tableName,
|
|
311
311
|
foreignKey: t.sourceKey,
|
|
@@ -314,8 +314,8 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = 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 = ji(i, e), o = t.foreignKey ?? (a.length === 1 ? a[0] : void 0);
|
|
318
|
+
if (o === void 0 || !Ai(i, o)) continue;
|
|
319
319
|
let s = i.fields[o];
|
|
320
320
|
n.push({
|
|
321
321
|
table: i.tableName,
|
|
@@ -324,9 +324,9 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
324
324
|
});
|
|
325
325
|
}
|
|
326
326
|
return n;
|
|
327
|
-
},
|
|
327
|
+
}, Ni = (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 ji(r, e)) {
|
|
330
330
|
let e = r.fields[t];
|
|
331
331
|
n.push({
|
|
332
332
|
table: r.tableName,
|
|
@@ -335,8 +335,8 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
335
335
|
});
|
|
336
336
|
}
|
|
337
337
|
return n;
|
|
338
|
-
},
|
|
339
|
-
let t = e.tables ??
|
|
338
|
+
}, Pi = (e) => `${e.table}\u0000${e.hops.map((e) => `${e.table}.${e.foreignKey}<-${e.parentKey}`).join("|")}`, Fi = (e) => {
|
|
339
|
+
let t = e.tables ?? qt(), n = e.relations ?? Ti(), 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 Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = 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([Pi(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 = Mi(a.table, n), d = Ni(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 Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
373
373
|
hops: [...a.hops, t],
|
|
374
374
|
depth: e,
|
|
375
375
|
via: n
|
|
376
|
-
}, f =
|
|
376
|
+
}, f = Pi(d);
|
|
377
377
|
l.has(f) || (l.add(f), c.push(d), r.push(d));
|
|
378
378
|
}
|
|
379
379
|
}
|
|
@@ -383,7 +383,7 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
383
383
|
}
|
|
384
384
|
d = r;
|
|
385
385
|
}
|
|
386
|
-
for (let e of d) (
|
|
386
|
+
for (let e of d) (Mi(e.table, n).length > 0 || Ni(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 Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = 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: ${ki(n).join(", ")}`
|
|
396
396
|
});
|
|
397
397
|
return {
|
|
398
398
|
subjectTable: e.subjectTable,
|
|
399
399
|
paths: c,
|
|
400
400
|
limitations: o
|
|
401
401
|
};
|
|
402
|
-
},
|
|
402
|
+
}, Ii = (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 Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = 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
|
+
}, Li = (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 S(`upsert: updateValues cannot rewrite row identity column '${t}'`);
|
|
413
413
|
return !0;
|
|
414
|
-
})),
|
|
415
|
-
let r =
|
|
414
|
+
})), Ri = (e, t, n) => {
|
|
415
|
+
let r = Li(n);
|
|
416
416
|
if (typeof n.update == "function") return {
|
|
417
417
|
...n.update(t),
|
|
418
418
|
...r
|
|
@@ -422,21 +422,21 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = 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
|
+
}, zi = (e) => typeof e == "string" ? [["id", e]] : Object.entries(e).map(([e, t]) => [e, t]), Bi = (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
|
+
}, Vi = (e) => typeof e != "string", Hi = (e, t, n) => {
|
|
430
|
+
let r = new Set(zi(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 S(`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
|
+
}, Ui = (e) => typeof e == "object" && !!e && !Array.isArray(e), Wi = (e) => JSON.parse(JSON.stringify(e ?? null)), Gi = (e, t, n) => {
|
|
437
|
+
let [r, ...i] = t.split("."), a = Wi(n), o = e[r], s = (e, t) => {
|
|
438
438
|
if (t === i.length) return a;
|
|
439
|
-
let n =
|
|
439
|
+
let n = Ui(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 Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
444
444
|
};
|
|
445
445
|
return {
|
|
446
446
|
...e,
|
|
447
|
-
[r]: i.length === 0 ?
|
|
447
|
+
[r]: i.length === 0 ? Ui(o) && Ui(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
|
+
}, Ki = (e, t, n, r, i) => {
|
|
453
|
+
let [a, ...o] = n.split("."), s = i ?? e`${e(a)}`, c = Wi(r), l = (e) => /["\\\u0000-\u001f]/.test(e);
|
|
454
|
+
if ((t === "sqlite" || t === "turso") && (o.some(l) || o.length === 0 && Ui(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 Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = 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 (!Ui(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 Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
507
507
|
v = _(v, o, g(c), c);
|
|
508
508
|
}
|
|
509
509
|
return e`${e(a)} = ${v}`;
|
|
510
|
-
},
|
|
510
|
+
}, qi = class extends Error {
|
|
511
511
|
_tag = "EagerCardinalityError";
|
|
512
512
|
constructor(e) {
|
|
513
513
|
super(e), this.name = "EagerCardinalityError";
|
|
514
514
|
}
|
|
515
|
-
},
|
|
515
|
+
}, Ji = (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
|
+
}, Yi = 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 = Ci(n.tableName);
|
|
521
|
+
if (i === void 0) throw S(`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 S(`unknown relation '${e}' on '${n.tableName}'. Registered relations: ${t}.`);
|
|
528
528
|
}
|
|
529
|
-
|
|
529
|
+
vi(n, e, t), await Xi(a, e, t, o === !0 ? {} : o, n, r);
|
|
530
530
|
}
|
|
531
531
|
return a;
|
|
532
|
-
},
|
|
532
|
+
}, Xi = async (e, t, n, r, i, a) => {
|
|
533
533
|
switch (n.kind) {
|
|
534
534
|
case "one":
|
|
535
|
-
await
|
|
535
|
+
await Zi(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 ea(e, t, n, r, i, a);
|
|
542
542
|
return;
|
|
543
543
|
}
|
|
544
|
-
},
|
|
545
|
-
let o = n.target(), s = n.sourceKey ??
|
|
544
|
+
}, Zi = async (e, t, n, r, i, a) => {
|
|
545
|
+
let o = n.target(), s = n.sourceKey ?? ta(i, o.tableName);
|
|
546
546
|
if (s !== void 0) {
|
|
547
|
-
let n =
|
|
547
|
+
let n = N(e, s), i = n.length === 0 ? [] : await na(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 ra(i, r.with, o, a);
|
|
553
553
|
return;
|
|
554
554
|
}
|
|
555
|
-
let c = n.foreignKey ?? A(o, i.tableName, t), l = n.sourceKey ?? "id", u =
|
|
555
|
+
let c = n.foreignKey ?? A(o, i.tableName, t), l = n.sourceKey ?? "id", u = N(e, l), d = u.length === 0 ? [] : await na(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 qi(Ji({
|
|
559
559
|
relationName: t,
|
|
560
560
|
sourceTableName: i.tableName,
|
|
561
561
|
targetTableName: o.tableName,
|
|
@@ -568,9 +568,9 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = 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 ?? A(o, i.tableName, t), c = n.sourceKey ?? "id", l =
|
|
571
|
+
await ra(d, r.with, o, a);
|
|
572
|
+
}, Qi = async (e, t, n, r, i, a) => {
|
|
573
|
+
let o = n.target(), s = n.foreignKey ?? A(o, i.tableName, t), c = n.sourceKey ?? "id", l = N(e, c), u = $i(r), d = l.length === 0 ? [] : await na(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 Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
586
586
|
let e = n[c];
|
|
587
587
|
n[t] = f.get(e) ?? [];
|
|
588
588
|
}
|
|
589
|
-
await
|
|
590
|
-
},
|
|
589
|
+
await ra(d, r.with, o, a);
|
|
590
|
+
}, $i = (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
|
+
}, ea = async (e, t, n, r, i, a) => {
|
|
594
|
+
let o = n.target(), s = n.through(), c = N(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 Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = 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 na(o, "id", N(d, n.targetKey), r, a), p = new Map(f.map((e) => [e.id, e]));
|
|
616
|
+
await ra(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 Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = 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
|
+
}, ta = (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
|
+
}, N = (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
|
+
}, na = (e, t, n, r, i) => {
|
|
638
638
|
let a = {
|
|
639
639
|
column: t,
|
|
640
640
|
op: "in",
|
|
@@ -648,34 +648,34 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = 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
|
+
}, ra = async (e, t, n, r) => {
|
|
652
|
+
t !== void 0 && e.length !== 0 && (await Yi(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
|
-
},
|
|
656
|
+
}, ia = (e) => e.eager !== void 0 && Object.keys(e.eager).length > 0, aa = (e, t, n) => {
|
|
657
657
|
if (e.eager === void 0) return null;
|
|
658
|
-
let r =
|
|
658
|
+
let r = sa(e.table, e.eager, e.sourceTable);
|
|
659
659
|
if (r === null) return null;
|
|
660
|
-
let i =
|
|
660
|
+
let i = ma(n, e, r, pa(t, n));
|
|
661
661
|
return i === null ? null : {
|
|
662
662
|
fragment: i,
|
|
663
|
-
decode:
|
|
663
|
+
decode: _a(r, n)
|
|
664
664
|
};
|
|
665
|
-
},
|
|
665
|
+
}, P = (e) => e.relation.kind === "one" && e.fkSide === "target", oa = (e) => ({
|
|
666
666
|
...e,
|
|
667
667
|
branch: {
|
|
668
668
|
...e.branch,
|
|
669
669
|
limit: 2
|
|
670
670
|
}
|
|
671
|
-
}),
|
|
672
|
-
let r = n ??
|
|
671
|
+
}), sa = (e, t, n) => {
|
|
672
|
+
let r = n ?? Ye(e), i = Ci(e);
|
|
673
673
|
if (i === void 0) return null;
|
|
674
674
|
let a = [];
|
|
675
675
|
for (let [e, n] of Object.entries(t)) {
|
|
676
676
|
let t = i[e];
|
|
677
677
|
if (t === void 0) return null;
|
|
678
|
-
let o =
|
|
678
|
+
let o = ca(e, t, r, n === !0 ? {} : n);
|
|
679
679
|
if (o === null) return null;
|
|
680
680
|
a.push(o);
|
|
681
681
|
}
|
|
@@ -683,11 +683,11 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
683
683
|
table: r,
|
|
684
684
|
children: a
|
|
685
685
|
};
|
|
686
|
-
},
|
|
686
|
+
}, ca = (e, t, n, r) => {
|
|
687
687
|
let i = t.target(), a = (t.kind === "manyToMany" ? void 0 : t.sourceKey) ?? "id", o, s;
|
|
688
688
|
if (t.kind === "manyToMany") o = t.targetKey, s = "target";
|
|
689
689
|
else if (t.kind === "one") {
|
|
690
|
-
let r = t.sourceKey ??
|
|
690
|
+
let r = t.sourceKey ?? fa(n, i.tableName);
|
|
691
691
|
if (r !== void 0) o = r, s = "source";
|
|
692
692
|
else try {
|
|
693
693
|
o = t.foreignKey ?? A(i, n.tableName, e), s = "target";
|
|
@@ -700,13 +700,13 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
700
700
|
return null;
|
|
701
701
|
}
|
|
702
702
|
let c = r.with === void 0 ? [] : (() => {
|
|
703
|
-
let e =
|
|
703
|
+
let e = Ci(i.tableName);
|
|
704
704
|
if (e === void 0 && Object.keys(r.with).length > 0) return null;
|
|
705
705
|
let t = [];
|
|
706
706
|
for (let [n, a] of Object.entries(r.with)) {
|
|
707
707
|
let r = e?.[n];
|
|
708
708
|
if (r === void 0) return null;
|
|
709
|
-
let o =
|
|
709
|
+
let o = ca(n, r, i, a === !0 ? {} : a);
|
|
710
710
|
if (o === null) return null;
|
|
711
711
|
t.push(o);
|
|
712
712
|
}
|
|
@@ -722,9 +722,9 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
722
722
|
fkSide: s,
|
|
723
723
|
branch: r,
|
|
724
724
|
children: c,
|
|
725
|
-
junction:
|
|
725
|
+
junction: la(t, r)
|
|
726
726
|
};
|
|
727
|
-
},
|
|
727
|
+
}, la = (e, t) => {
|
|
728
728
|
if (e.kind !== "manyToMany" || t.junction === void 0) return;
|
|
729
729
|
let n = e.through(), r = t.junction === !0 ? Object.keys(n.fields) : t.junction, i = r.filter((e) => e in n.fields);
|
|
730
730
|
return {
|
|
@@ -736,35 +736,35 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
736
736
|
return t !== void 0 && (t.type === "timestamp" || t.type === "date");
|
|
737
737
|
})
|
|
738
738
|
};
|
|
739
|
-
},
|
|
739
|
+
}, ua = (e) => `__j_${e}`, da = "__j", fa = (e, t) => {
|
|
740
740
|
for (let [n, r] of Object.entries(e.fields)) if (r.type === "reference" && r.references?.()?.tableName === t) return n;
|
|
741
|
-
},
|
|
741
|
+
}, pa = (e, t) => {
|
|
742
742
|
let n = 0;
|
|
743
743
|
return {
|
|
744
744
|
sql: e,
|
|
745
745
|
dialect: t,
|
|
746
746
|
nextAlias: () => `__a${n++}`
|
|
747
747
|
};
|
|
748
|
-
},
|
|
748
|
+
}, ma = (e, t, n, r) => {
|
|
749
749
|
switch (e) {
|
|
750
|
-
case "postgres": return
|
|
750
|
+
case "postgres": return ba(t, n, r);
|
|
751
751
|
case "sqlite":
|
|
752
|
-
case "turso": return
|
|
752
|
+
case "turso": return Oa(t, n, r);
|
|
753
753
|
case "mysql":
|
|
754
|
-
case "mariadb": return
|
|
755
|
-
case "mssql": return
|
|
754
|
+
case "mariadb": return Ra(t, n, r);
|
|
755
|
+
case "mssql": return Ga(t, n, r);
|
|
756
756
|
}
|
|
757
|
-
},
|
|
758
|
-
let n =
|
|
757
|
+
}, ha = (e, t) => t === "mssql" && !ga.test(e) ? /* @__PURE__ */ new Date(`${e}Z`) : new Date(e), ga = /(?:Z|[+-]\d{2}:?\d{2})$/, _a = (e, t) => {
|
|
758
|
+
let n = va(e.table, e.children, t);
|
|
759
759
|
return (e) => e.map((e) => {
|
|
760
760
|
let t = e.__row, r = typeof t == "string" ? JSON.parse(t) : t;
|
|
761
761
|
return n(r);
|
|
762
762
|
});
|
|
763
|
-
},
|
|
763
|
+
}, va = (e, t, n) => {
|
|
764
764
|
let r = [], i = [];
|
|
765
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);
|
|
766
766
|
let a = t.map((e) => {
|
|
767
|
-
let t =
|
|
767
|
+
let t = va(e.target, e.children, n), r = e.relation.kind === "one", i = P(e), a = i ? Ji({
|
|
768
768
|
relationName: e.relationName,
|
|
769
769
|
sourceTableName: e.source.tableName,
|
|
770
770
|
targetTableName: e.target.tableName,
|
|
@@ -777,15 +777,15 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
777
777
|
isSingle: r,
|
|
778
778
|
fromOverFetch: i,
|
|
779
779
|
cardinalityMessage: a,
|
|
780
|
-
junction:
|
|
780
|
+
junction: ya(e.junction, n)
|
|
781
781
|
};
|
|
782
782
|
});
|
|
783
783
|
return (e) => {
|
|
784
784
|
let t = { ...e };
|
|
785
|
-
for (let e of i) e in t && (t[e] =
|
|
785
|
+
for (let e of i) e in t && (t[e] = qe(t[e], "vector", n));
|
|
786
786
|
for (let e of r) {
|
|
787
787
|
let r = t[e];
|
|
788
|
-
typeof r == "string" && (t[e] =
|
|
788
|
+
typeof r == "string" && (t[e] = ha(r, n));
|
|
789
789
|
}
|
|
790
790
|
for (let e of a) {
|
|
791
791
|
let n = t[e.name];
|
|
@@ -795,7 +795,7 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
795
795
|
}
|
|
796
796
|
if (e.fromOverFetch) {
|
|
797
797
|
let r = n;
|
|
798
|
-
if (r.length > 1) throw new
|
|
798
|
+
if (r.length > 1) throw new qi(e.cardinalityMessage);
|
|
799
799
|
t[e.name] = r.length === 0 ? null : e.decode(r[0]);
|
|
800
800
|
continue;
|
|
801
801
|
}
|
|
@@ -807,204 +807,213 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
807
807
|
}
|
|
808
808
|
return t;
|
|
809
809
|
};
|
|
810
|
-
},
|
|
810
|
+
}, ya = (e, t) => {
|
|
811
811
|
if (e === void 0) return;
|
|
812
812
|
let n = new Set(e.dateColumns), r = e.requested;
|
|
813
813
|
return (e) => {
|
|
814
814
|
let i = e._junction ?? {}, a = {};
|
|
815
815
|
for (let e of r) {
|
|
816
816
|
let r = i[e];
|
|
817
|
-
a[e] = n.has(e) && typeof r == "string" ?
|
|
817
|
+
a[e] = n.has(e) && typeof r == "string" ? ha(r, t) : r;
|
|
818
818
|
}
|
|
819
819
|
return {
|
|
820
820
|
...e,
|
|
821
821
|
_junction: a
|
|
822
822
|
};
|
|
823
823
|
};
|
|
824
|
-
},
|
|
825
|
-
let r = n.sql, i = n.nextAlias(), a = r(t.table.tableName), o = r(i), s =
|
|
826
|
-
return s === null ? null : r`SELECT ${s} AS "__row" FROM ${a} AS ${o}${e.predicate ? r` WHERE ${
|
|
827
|
-
},
|
|
828
|
-
let i = n.sql, a = r === void 0 ? i`to_jsonb(${i(e)}.*)` : i`(to_jsonb(${i(e)}.*) - ${
|
|
824
|
+
}, ba = (e, t, n) => {
|
|
825
|
+
let r = n.sql, i = n.nextAlias(), a = r(t.table.tableName), o = r(i), s = xa(i, t.children, n);
|
|
826
|
+
return s === null ? null : r`SELECT ${s} AS "__row" FROM ${a} AS ${o}${e.predicate ? r` WHERE ${B(e.predicate, i, r)}` : r``}${x(e).length > 0 ? r` ORDER BY ${r.csv(x(e).map((e) => e.direction === "desc" ? r`${L(i, e.column, r)} DESC` : r`${L(i, e.column, r)} ASC`))}` : r``}${e.take === void 0 ? r`` : r` LIMIT ${z(e.take, r)}`}${e.skip === void 0 ? r`` : r` OFFSET ${z(e.skip, r)}`}`;
|
|
827
|
+
}, xa = (e, t, n, r) => {
|
|
828
|
+
let i = n.sql, a = r === void 0 ? i`to_jsonb(${i(e)}.*)` : i`(to_jsonb(${i(e)}.*) - ${R(da, i)}::text)`;
|
|
829
829
|
if (t.length === 0 && r === void 0) return a;
|
|
830
830
|
let o = [];
|
|
831
|
-
r !== void 0 && o.push(i`${
|
|
831
|
+
r !== void 0 && o.push(i`${R("_junction", i)}, ${L(e, da, i)}`);
|
|
832
832
|
for (let r of t) {
|
|
833
|
-
let t =
|
|
833
|
+
let t = Sa(r, e, n);
|
|
834
834
|
if (t === null) return null;
|
|
835
|
-
o.push(i`${
|
|
835
|
+
o.push(i`${R(r.relationName, i)}, ${t}`);
|
|
836
836
|
}
|
|
837
837
|
return i`${a} || jsonb_build_object(${i.csv(o)})`;
|
|
838
|
-
},
|
|
838
|
+
}, Sa = (e, t, n) => {
|
|
839
839
|
switch (e.relation.kind) {
|
|
840
|
-
case "one": return
|
|
841
|
-
case "many": return
|
|
842
|
-
case "manyToMany": return
|
|
840
|
+
case "one": return P(e) ? wa(oa(e), t, n) : Ca(e, t, n);
|
|
841
|
+
case "many": return wa(e, t, n);
|
|
842
|
+
case "manyToMany": return Ta(e, t, n);
|
|
843
843
|
}
|
|
844
|
-
},
|
|
845
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
844
|
+
}, Ca = (e, t, n) => {
|
|
845
|
+
let r = n.sql, i = n.nextAlias(), a = xa(i, e.children, n);
|
|
846
846
|
if (a === null) return null;
|
|
847
|
-
let o = e.fkSide === "source" ? r`${
|
|
847
|
+
let o = e.fkSide === "source" ? r`${L(i, "id", r)} = ${L(t, e.foreignKey, r)}` : r`${L(i, e.foreignKey, r)} = ${L(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${B(e.branch.where, i, r)}`, c = F(i, e.branch.orderBy, r);
|
|
848
848
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}${c} LIMIT 1)`;
|
|
849
|
-
},
|
|
850
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
849
|
+
}, wa = (e, t, n) => {
|
|
850
|
+
let r = n.sql, i = n.nextAlias(), a = xa(i, e.children, n);
|
|
851
851
|
if (a === null) return null;
|
|
852
|
-
let o = r`${
|
|
852
|
+
let o = r`${L(void 0, e.foreignKey, r)} = ${L(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${C(e.branch.where, r)}`, c = Da(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${z(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${z(e.branch.offset, r)}`;
|
|
853
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)`;
|
|
854
|
-
},
|
|
855
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
854
|
+
}, Ta = (e, t, n) => {
|
|
855
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = xa(o, e.children, n, e.junction);
|
|
856
856
|
if (c === null) return null;
|
|
857
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
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 ${
|
|
859
|
-
},
|
|
860
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
857
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${C(e.branch.where, r)}`, u = V(e, s, r), d = F(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${z(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${z(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : r`, ${Ea(e.junction, s, r)} AS ${r(da)}`;
|
|
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 ${L(o, "id", r)} = ${L(s, i.targetKey, r)} WHERE ${L(s, i.sourceKey, r)} = ${L(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), '[]'::jsonb)`;
|
|
859
|
+
}, Ea = (e, t, n) => e.present.length === 0 ? n`jsonb_build_object()` : n`jsonb_build_object(${n.csv(e.present.map((e) => n`${R(e, n)}, ${L(t, e, n)}`))})`, F = (e, t, n) => t === void 0 || t.length === 0 ? n`` : n` ORDER BY ${n.csv(t.map((t) => t.direction === "desc" ? n`${L(e, t.column, n)} DESC` : n`${L(e, t.column, n)} ASC`))}`, Da = (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`))}`, Oa = (e, t, n) => {
|
|
860
|
+
let r = n.sql, i = n.nextAlias(), a = ka(i, t.table, t.children, n);
|
|
861
861
|
if (a === null) return null;
|
|
862
|
-
let o = e.predicate ? r` WHERE ${
|
|
862
|
+
let o = e.predicate ? r` WHERE ${B(e.predicate, i, r)}` : r``, s = x(e).length > 0 ? r` ORDER BY ${r.csv(x(e).map((e) => e.direction === "desc" ? r`${L(i, e.column, r)} DESC` : r`${L(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${z(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${z(e.skip, r)}`;
|
|
863
863
|
return r`SELECT ${a} AS "__row" FROM ${r(t.table.tableName)} AS ${r(i)}${o}${s}${c}${l}`;
|
|
864
|
-
},
|
|
864
|
+
}, ka = (e, t, n, r, i) => {
|
|
865
865
|
let a = r.sql, o = [];
|
|
866
|
-
for (let n of Object.keys(t.fields))
|
|
866
|
+
for (let n of Object.keys(t.fields)) {
|
|
867
|
+
let r = L(e, n, a), i = t.fields[n]?.type === "bigint" ? a`CAST(${r} AS TEXT)` : r;
|
|
868
|
+
o.push(a`${R(n, a)}, ${i}`);
|
|
869
|
+
}
|
|
867
870
|
if (i !== void 0) {
|
|
868
|
-
let e =
|
|
869
|
-
o.push(a`${
|
|
871
|
+
let e = Aa(i.projection, i.source, a);
|
|
872
|
+
o.push(a`${R("_junction", a)}, json_object(${e})`);
|
|
870
873
|
}
|
|
871
874
|
for (let t of n) {
|
|
872
|
-
let n =
|
|
875
|
+
let n = Pa(t, e, r);
|
|
873
876
|
if (n === null) return null;
|
|
874
|
-
o.push(a`${
|
|
877
|
+
o.push(a`${R(t.relationName, a)}, ${n}`);
|
|
875
878
|
}
|
|
876
879
|
return a`json_object(${a.csv(o)})`;
|
|
877
|
-
},
|
|
880
|
+
}, Aa = (e, t, n) => e.present.length === 0 ? n`` : n.csv(e.present.map((r) => {
|
|
881
|
+
let i = L(t.alias, t.physical(r), n), a = e.through.fields[r]?.type === "bigint" ? n.onDialectOrElse({
|
|
882
|
+
sqlite: () => n`CAST(${i} AS TEXT)`,
|
|
883
|
+
orElse: () => i
|
|
884
|
+
}) : i;
|
|
885
|
+
return n`${R(r, n)}, ${a}`;
|
|
886
|
+
})), ja = (e, t, n) => e.present.length === 0 ? n`` : n`, ${n.csv(e.present.map((e) => n`${L(t, e, n)} AS ${n(ua(e))}`))}`, Ma = (e) => ({
|
|
878
887
|
alias: e,
|
|
879
|
-
physical:
|
|
880
|
-
}),
|
|
888
|
+
physical: ua
|
|
889
|
+
}), Na = (e) => ({
|
|
881
890
|
alias: e,
|
|
882
891
|
physical: (e) => e
|
|
883
|
-
}),
|
|
892
|
+
}), Pa = (e, t, n) => {
|
|
884
893
|
switch (e.relation.kind) {
|
|
885
|
-
case "one": return
|
|
886
|
-
case "many": return
|
|
887
|
-
case "manyToMany": return
|
|
894
|
+
case "one": return P(e) ? Ia(oa(e), t, n) : Fa(e, t, n);
|
|
895
|
+
case "many": return Ia(e, t, n);
|
|
896
|
+
case "manyToMany": return La(e, t, n);
|
|
888
897
|
}
|
|
889
|
-
},
|
|
890
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
898
|
+
}, Fa = (e, t, n) => {
|
|
899
|
+
let r = n.sql, i = n.nextAlias(), a = ka(i, e.target, e.children, n);
|
|
891
900
|
if (a === null) return null;
|
|
892
|
-
let o = e.fkSide === "source" ? r`${
|
|
901
|
+
let o = e.fkSide === "source" ? r`${L(i, "id", r)} = ${L(t, e.foreignKey, r)}` : r`${L(i, e.foreignKey, r)} = ${L(t, e.sourceKey, r)}`;
|
|
893
902
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
|
|
894
|
-
},
|
|
895
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
903
|
+
}, Ia = (e, t, n) => {
|
|
904
|
+
let r = n.sql, i = n.nextAlias(), a = ka(i, e.target, e.children, n);
|
|
896
905
|
if (a === null) return null;
|
|
897
|
-
let o = r`${
|
|
906
|
+
let o = r`${L(void 0, e.foreignKey, r)} = ${L(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${C(H(e.branch.where), r)}`, c = Da(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${z(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${z(e.branch.offset, r)}`;
|
|
898
907
|
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('[]'))`;
|
|
899
|
-
},
|
|
900
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
908
|
+
}, La = (e, t, n) => {
|
|
909
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = ka(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
901
910
|
projection: e.junction,
|
|
902
|
-
source:
|
|
911
|
+
source: Ma(o)
|
|
903
912
|
});
|
|
904
913
|
if (c === null) return null;
|
|
905
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
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 ${
|
|
907
|
-
},
|
|
908
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
914
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${C(H(e.branch.where), r)}`, u = V(e, s, r, !0), d = F(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${z(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${z(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : ja(e.junction, s, r);
|
|
915
|
+
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 ${L(o, "id", r)} = ${L(s, i.targetKey, r)} WHERE ${L(s, i.sourceKey, r)} = ${L(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), json('[]'))`;
|
|
916
|
+
}, Ra = (e, t, n) => {
|
|
917
|
+
let r = n.sql, i = n.nextAlias(), a = I(i, t.table, t.children, n);
|
|
909
918
|
if (a === null) return null;
|
|
910
|
-
let o = e.predicate ? r` WHERE ${
|
|
919
|
+
let o = e.predicate ? r` WHERE ${B(e.predicate, i, r)}` : r``, s = x(e).length > 0 ? r` ORDER BY ${r.csv(x(e).map((e) => e.direction === "desc" ? r`${L(i, e.column, r)} DESC` : r`${L(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${z(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${z(e.skip, r)}`;
|
|
911
920
|
return r`SELECT ${a} AS \`__row\` FROM ${r(t.table.tableName)} AS ${r(i)}${o}${s}${c}${l}`;
|
|
912
|
-
},
|
|
921
|
+
}, I = (e, t, n, r, i) => {
|
|
913
922
|
let a = r.sql, o = [];
|
|
914
|
-
for (let n of Object.keys(t.fields)) o.push(a`${
|
|
923
|
+
for (let n of Object.keys(t.fields)) o.push(a`${R(n, a)}, ${L(e, n, a)}`);
|
|
915
924
|
if (i !== void 0) {
|
|
916
|
-
let e =
|
|
917
|
-
o.push(a`${
|
|
925
|
+
let e = Aa(i.projection, i.source, a);
|
|
926
|
+
o.push(a`${R("_junction", a)}, JSON_OBJECT(${e})`);
|
|
918
927
|
}
|
|
919
928
|
for (let t of n) {
|
|
920
|
-
let n =
|
|
929
|
+
let n = za(t, e, r);
|
|
921
930
|
if (n === null) return null;
|
|
922
|
-
o.push(a`${
|
|
931
|
+
o.push(a`${R(t.relationName, a)}, ${n}`);
|
|
923
932
|
}
|
|
924
933
|
return a`JSON_OBJECT(${a.csv(o)})`;
|
|
925
|
-
},
|
|
934
|
+
}, za = (e, t, n) => {
|
|
926
935
|
switch (e.relation.kind) {
|
|
927
936
|
case "one":
|
|
928
|
-
if (
|
|
929
|
-
let r =
|
|
930
|
-
return n.dialect === "mariadb" ?
|
|
937
|
+
if (P(e)) {
|
|
938
|
+
let r = oa(e);
|
|
939
|
+
return n.dialect === "mariadb" ? Ua(r, t, n) : Va(r, t, n);
|
|
931
940
|
}
|
|
932
|
-
return
|
|
933
|
-
case "many": return n.dialect === "mariadb" ?
|
|
934
|
-
case "manyToMany": return n.dialect === "mariadb" ?
|
|
941
|
+
return Ba(e, t, n);
|
|
942
|
+
case "many": return n.dialect === "mariadb" ? Ua(e, t, n) : Va(e, t, n);
|
|
943
|
+
case "manyToMany": return n.dialect === "mariadb" ? Wa(e, t, n) : Ha(e, t, n);
|
|
935
944
|
}
|
|
936
|
-
},
|
|
937
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
945
|
+
}, Ba = (e, t, n) => {
|
|
946
|
+
let r = n.sql, i = n.nextAlias(), a = I(i, e.target, e.children, n);
|
|
938
947
|
if (a === null) return null;
|
|
939
|
-
let o = e.fkSide === "source" ? r`${
|
|
948
|
+
let o = e.fkSide === "source" ? r`${L(i, "id", r)} = ${L(t, e.foreignKey, r)}` : r`${L(i, e.foreignKey, r)} = ${L(t, e.sourceKey, r)}`;
|
|
940
949
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
|
|
941
|
-
},
|
|
942
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
950
|
+
}, Va = (e, t, n) => {
|
|
951
|
+
let r = n.sql, i = n.nextAlias(), a = I(i, e.target, e.children, n);
|
|
943
952
|
if (a === null) return null;
|
|
944
|
-
let o = r`${
|
|
953
|
+
let o = r`${L(void 0, e.foreignKey, r)} = ${L(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${C(H(e.branch.where), r)}`, c = Da(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${z(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${z(e.branch.offset, r)}`;
|
|
945
954
|
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())`;
|
|
946
|
-
},
|
|
947
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
955
|
+
}, Ha = (e, t, n) => {
|
|
956
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = I(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
948
957
|
projection: e.junction,
|
|
949
|
-
source:
|
|
958
|
+
source: Ma(o)
|
|
950
959
|
});
|
|
951
960
|
if (c === null) return null;
|
|
952
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
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 ${
|
|
954
|
-
},
|
|
955
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
961
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${C(H(e.branch.where), r)}`, u = V(e, s, r, !0), d = F(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${z(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${z(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : ja(e.junction, s, r);
|
|
962
|
+
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 ${L(o, "id", r)} = ${L(s, i.targetKey, r)} WHERE ${L(s, i.sourceKey, r)} = ${L(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), JSON_ARRAY())`;
|
|
963
|
+
}, Ua = (e, t, n) => {
|
|
964
|
+
let r = n.sql, i = n.nextAlias(), a = I(i, e.target, e.children, n);
|
|
956
965
|
if (a === null) return null;
|
|
957
|
-
let o = r`${
|
|
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`${
|
|
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 ${
|
|
960
|
-
return r`COALESCE((SELECT JSON_ARRAYAGG(${a} ORDER BY ${
|
|
961
|
-
},
|
|
966
|
+
let o = r`${L(i, e.foreignKey, r)} = ${L(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${C(H(e.branch.where), r)}`, c = e.branch.orderBy ?? [];
|
|
967
|
+
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`${L(i, e.column, r)} DESC` : r`${L(i, e.column, r)} ASC`))}` : r``}) FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}), JSON_ARRAY())`;
|
|
968
|
+
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 ${L(i, "rn", r)} > ${z(d, r)} AND ${L(i, "rn", r)} <= ${z(d + u, r)}` : u === void 0 ? r` AND ${L(i, "rn", r)} > ${z(d, r)}` : r` AND ${L(i, "rn", r)} <= ${z(u, r)}`;
|
|
969
|
+
return r`COALESCE((SELECT JSON_ARRAYAGG(${a} ORDER BY ${L(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())`;
|
|
970
|
+
}, Wa = (e, t, n) => {
|
|
962
971
|
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = (t) => e.junction === void 0 ? void 0 : {
|
|
963
972
|
projection: e.junction,
|
|
964
973
|
source: t
|
|
965
|
-
}, l = r`${
|
|
974
|
+
}, l = r`${L(s, i.sourceKey, r)} = ${L(t, "id", r)}`, u = r`${L(o, "id", r)} = ${L(s, i.targetKey, r)}`, d = e.branch.where === void 0 ? r`` : r` AND ${C(H(e.branch.where), r)}`, f = V(e, s, r, !0), p = e.branch.orderBy ?? [];
|
|
966
975
|
if (e.branch.limit === void 0 && e.branch.offset === void 0) {
|
|
967
|
-
let t =
|
|
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`${
|
|
976
|
+
let t = I(o, e.target, e.children, n, c(Na(s)));
|
|
977
|
+
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`${L(o, e.column, r)} DESC` : r`${L(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())`;
|
|
969
978
|
}
|
|
970
|
-
let m = p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${
|
|
979
|
+
let m = p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${L(o, e.column, r)} DESC` : r`${L(o, e.column, r)} ASC`))}` : r` ORDER BY ${L(o, "id", r)}`, h = e.branch.limit, g = e.branch.offset, _ = h !== void 0 && g !== void 0 ? r` AND ${L(o, "rn", r)} > ${z(g, r)} AND ${L(o, "rn", r)} <= ${z(g + h, r)}` : h === void 0 ? r` AND ${L(o, "rn", r)} > ${z(g, r)}` : r` AND ${L(o, "rn", r)} <= ${z(h, r)}`, v = e.branch.onJunction === void 0 ? r`` : r` WHERE ${B(H(e.branch.onJunction), s, r)}`, ee = I(o, e.target, e.children, n, c(Ma(o)));
|
|
971
980
|
if (ee === null) return null;
|
|
972
|
-
let te = e.junction === void 0 ? r`` :
|
|
973
|
-
return r`COALESCE((SELECT JSON_ARRAYAGG(${ee} ORDER BY ${
|
|
974
|
-
},
|
|
975
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
981
|
+
let te = e.junction === void 0 ? r`` : ja(e.junction, s, r);
|
|
982
|
+
return r`COALESCE((SELECT JSON_ARRAYAGG(${ee} ORDER BY ${L(o, "rn", r)}) FROM (SELECT ${r(o)}.*${te}, ${L(s, i.sourceKey, r)} AS ${r(`__src_${i.sourceKey}`)}, ROW_NUMBER() OVER (PARTITION BY ${L(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 ${L(o, `__src_${i.sourceKey}`, r)} = ${L(t, "id", r)}${d}${_}), JSON_ARRAY())`;
|
|
983
|
+
}, Ga = (e, t, n) => {
|
|
984
|
+
let r = n.sql, i = n.nextAlias(), a = Ka(i, t.table, t.children, n);
|
|
976
985
|
if (a === null) return null;
|
|
977
|
-
let o = e.predicate ? r` WHERE ${
|
|
986
|
+
let o = e.predicate ? r` WHERE ${B(e.predicate, i, r)}` : r``, s = x(e).length > 0 ? r` ORDER BY ${r.csv(x(e).map((e) => e.direction === "desc" ? r`${L(i, e.column, r)} DESC` : r`${L(i, e.column, r)} ASC`))}` : r``, c = r``, l = r``;
|
|
978
987
|
if (e.skip !== void 0) {
|
|
979
|
-
let t =
|
|
980
|
-
l = e.take === void 0 ? r`${t} OFFSET ${
|
|
981
|
-
} else e.take !== void 0 && (c = r`TOP ${
|
|
988
|
+
let t = x(e).length > 0 ? s : r` ORDER BY (SELECT NULL)`;
|
|
989
|
+
l = e.take === void 0 ? r`${t} OFFSET ${z(e.skip, r)} ROWS` : r`${t} OFFSET ${z(e.skip, r)} ROWS FETCH NEXT ${z(e.take, r)} ROWS ONLY`;
|
|
990
|
+
} else e.take !== void 0 && (c = r`TOP ${z(e.take, r)} `);
|
|
982
991
|
let u = e.skip === void 0 ? s : r``;
|
|
983
992
|
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}`;
|
|
984
|
-
},
|
|
993
|
+
}, Ka = (e, t, n, r, i) => {
|
|
985
994
|
let a = r.sql, o = [];
|
|
986
|
-
for (let n of Object.keys(t.fields)) o.push(a`${
|
|
987
|
-
if (i !== void 0) for (let e of i.projection.present) o.push(a`${
|
|
995
|
+
for (let n of Object.keys(t.fields)) o.push(a`${L(e, n, a)} AS ${a(n)}`);
|
|
996
|
+
if (i !== void 0) for (let e of i.projection.present) o.push(a`${L(i.source.alias, i.source.physical(e), a)} AS ${qa(`_junction.${e}`, a)}`);
|
|
988
997
|
for (let t of n) {
|
|
989
|
-
let n =
|
|
998
|
+
let n = Ja(t, e, r);
|
|
990
999
|
if (n === null) return null;
|
|
991
1000
|
o.push(n);
|
|
992
1001
|
}
|
|
993
1002
|
return a.csv(o);
|
|
994
|
-
},
|
|
1003
|
+
}, qa = (e, t) => t.unsafe(`[${e.replace(/]/g, "]]")}]`), Ja = (e, t, n) => {
|
|
995
1004
|
switch (e.relation.kind) {
|
|
996
|
-
case "one": return
|
|
997
|
-
case "many": return
|
|
998
|
-
case "manyToMany": return
|
|
1005
|
+
case "one": return P(e) ? Za(oa(e), t, n) : Ya(e, t, n);
|
|
1006
|
+
case "many": return Za(e, t, n);
|
|
1007
|
+
case "manyToMany": return Qa(e, t, n);
|
|
999
1008
|
}
|
|
1000
|
-
},
|
|
1001
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1009
|
+
}, Ya = (e, t, n) => {
|
|
1010
|
+
let r = n.sql, i = n.nextAlias(), a = Ka(i, e.target, e.children, n);
|
|
1002
1011
|
if (a === null) return null;
|
|
1003
|
-
let o = e.fkSide === "source" ? r`${
|
|
1012
|
+
let o = e.fkSide === "source" ? r`${L(i, "id", r)} = ${L(t, e.foreignKey, r)}` : r`${L(i, e.foreignKey, r)} = ${L(t, e.sourceKey, r)}`;
|
|
1004
1013
|
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)}`;
|
|
1005
|
-
},
|
|
1014
|
+
}, Xa = (e, t, n) => {
|
|
1006
1015
|
if (e.offset !== void 0) {
|
|
1007
|
-
let r = e.orderBy && e.orderBy.length > 0 ? t : n` ORDER BY (SELECT NULL)`, i = e.limit === void 0 ? n`${r} OFFSET ${
|
|
1016
|
+
let r = e.orderBy && e.orderBy.length > 0 ? t : n` ORDER BY (SELECT NULL)`, i = e.limit === void 0 ? n`${r} OFFSET ${z(e.offset, n)} ROWS` : n`${r} OFFSET ${z(e.offset, n)} ROWS FETCH NEXT ${z(e.limit, n)} ROWS ONLY`;
|
|
1008
1017
|
return {
|
|
1009
1018
|
top: n``,
|
|
1010
1019
|
pagination: i,
|
|
@@ -1012,36 +1021,36 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
1012
1021
|
};
|
|
1013
1022
|
}
|
|
1014
1023
|
return {
|
|
1015
|
-
top: e.limit === void 0 ? n`` : n`TOP ${
|
|
1024
|
+
top: e.limit === void 0 ? n`` : n`TOP ${z(e.limit, n)} `,
|
|
1016
1025
|
pagination: n``,
|
|
1017
1026
|
finalOrder: t
|
|
1018
1027
|
};
|
|
1019
|
-
},
|
|
1020
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1028
|
+
}, Za = (e, t, n) => {
|
|
1029
|
+
let r = n.sql, i = n.nextAlias(), a = Ka(i, e.target, e.children, n);
|
|
1021
1030
|
if (a === null) return null;
|
|
1022
|
-
let o = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1023
|
-
return r`ISNULL(JSON_QUERY((SELECT ${c}${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${
|
|
1024
|
-
},
|
|
1025
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
1031
|
+
let o = e.branch.where === void 0 ? r`` : r` AND ${B(e.branch.where, i, r)}`, s = F(i, e.branch.orderBy, r), { top: c, pagination: l, finalOrder: u } = Xa(e.branch, s, r);
|
|
1032
|
+
return r`ISNULL(JSON_QUERY((SELECT ${c}${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${L(i, e.foreignKey, r)} = ${L(t, e.sourceKey, r)}${o}${u}${l} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
|
|
1033
|
+
}, Qa = (e, t, n) => {
|
|
1034
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = Ka(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
1026
1035
|
projection: e.junction,
|
|
1027
|
-
source:
|
|
1036
|
+
source: Na(s)
|
|
1028
1037
|
});
|
|
1029
1038
|
if (c === null) return null;
|
|
1030
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
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 ${
|
|
1032
|
-
},
|
|
1033
|
-
if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw
|
|
1039
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${B(e.branch.where, o, r)}`, u = V(e, s, r), d = F(o, e.branch.orderBy, r), { top: f, pagination: p, finalOrder: m } = Xa(e.branch, d, r);
|
|
1040
|
+
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 ${L(o, "id", r)} = ${L(s, i.targetKey, r)} WHERE ${L(s, i.sourceKey, r)} = ${L(t, "id", r)}${u}${l}${m}${p} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
|
|
1041
|
+
}, L = (e, t, n) => e === void 0 ? n`${n(t)}` : n`${n(e)}.${n(t)}`, R = (e, t) => t.unsafe(`'${e.replace(/'/g, "''")}'`), z = (e, t) => {
|
|
1042
|
+
if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw S(`literalInt: expected non-negative integer, got ${e}`);
|
|
1034
1043
|
return t.unsafe(String(e));
|
|
1035
|
-
},
|
|
1036
|
-
let r =
|
|
1037
|
-
return
|
|
1038
|
-
},
|
|
1044
|
+
}, B = (e, t, n) => {
|
|
1045
|
+
let r = $a(e, t);
|
|
1046
|
+
return C(r, n);
|
|
1047
|
+
}, V = (e, t, n, r = !1) => {
|
|
1039
1048
|
let i = e.branch.onJunction;
|
|
1040
|
-
return i === void 0 ? n`` : n` AND ${
|
|
1041
|
-
},
|
|
1042
|
-
if ("not" in e) return { not:
|
|
1043
|
-
if ("and" in e) return { and: e.and.map((e) =>
|
|
1044
|
-
if ("or" in e) return { or: e.or.map((e) =>
|
|
1049
|
+
return i === void 0 ? n`` : n` AND ${B(r ? H(i) : i, t, n)}`;
|
|
1050
|
+
}, $a = (e, t) => {
|
|
1051
|
+
if ("not" in e) return { not: $a(e.not, t) };
|
|
1052
|
+
if ("and" in e) return { and: e.and.map((e) => $a(e, t)) };
|
|
1053
|
+
if ("or" in e) return { or: e.or.map((e) => $a(e, t)) };
|
|
1045
1054
|
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
1046
1055
|
let n = e;
|
|
1047
1056
|
return {
|
|
@@ -1055,24 +1064,24 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
1055
1064
|
...n,
|
|
1056
1065
|
column: `${t}.${n.column}`
|
|
1057
1066
|
};
|
|
1058
|
-
},
|
|
1059
|
-
if ("not" in e) return { not:
|
|
1060
|
-
if ("and" in e) return { and: e.and.map((e) =>
|
|
1061
|
-
if ("or" in e) return { or: e.or.map((e) =>
|
|
1067
|
+
}, H = (e) => {
|
|
1068
|
+
if ("not" in e) return { not: H(e.not) };
|
|
1069
|
+
if ("and" in e) return { and: e.and.map((e) => H(e)) };
|
|
1070
|
+
if ("or" in e) return { or: e.or.map((e) => H(e)) };
|
|
1062
1071
|
if (e.op === "subquery-in" || e.op === "subquery-not-in" || e.op === "exists" || e.op === "not-exists") return e;
|
|
1063
1072
|
let t = e;
|
|
1064
1073
|
return {
|
|
1065
1074
|
...t,
|
|
1066
|
-
value:
|
|
1075
|
+
value: Te(t.value)
|
|
1067
1076
|
};
|
|
1068
|
-
},
|
|
1069
|
-
e.actors !== void 0 && (
|
|
1070
|
-
},
|
|
1077
|
+
}, eo = Symbol.for("@voltro/database/coreTablesRegistry"), to = globalThis, no = to[eo] ?? (to[eo] = {}), ro = (e) => {
|
|
1078
|
+
e.actors !== void 0 && (no.actors = e.actors), e.tenants !== void 0 && (no.tenants = e.tenants);
|
|
1079
|
+
}, io = (e, t) => () => {
|
|
1071
1080
|
let n = e();
|
|
1072
1081
|
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`);
|
|
1073
1082
|
return n();
|
|
1074
|
-
},
|
|
1075
|
-
id:
|
|
1083
|
+
}, ao = () => io(() => no.actors, "actors"), oo = () => io(() => no.tenants, "tenants"), so = i("actors", {
|
|
1084
|
+
id: y(),
|
|
1076
1085
|
kind: b().oneOf([
|
|
1077
1086
|
"user",
|
|
1078
1087
|
"serviceAccount",
|
|
@@ -1080,30 +1089,30 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
1080
1089
|
"system"
|
|
1081
1090
|
]).safe(),
|
|
1082
1091
|
displayName: b().nullable().sensitive("fullName"),
|
|
1083
|
-
createdAt:
|
|
1084
|
-
}),
|
|
1092
|
+
createdAt: w().default("now")
|
|
1093
|
+
}), co = (e, t) => ({
|
|
1085
1094
|
...t,
|
|
1086
1095
|
...e,
|
|
1087
1096
|
origin: e.origin ?? "injected"
|
|
1088
|
-
}),
|
|
1097
|
+
}), lo = (e, t, n = {}) => ({
|
|
1089
1098
|
table: e,
|
|
1090
1099
|
op: "insert",
|
|
1091
1100
|
old: null,
|
|
1092
1101
|
new: t,
|
|
1093
1102
|
...n
|
|
1094
|
-
}),
|
|
1103
|
+
}), uo = (e, t, n, r = {}) => ({
|
|
1095
1104
|
table: e,
|
|
1096
1105
|
op: "update",
|
|
1097
1106
|
old: t,
|
|
1098
1107
|
new: n,
|
|
1099
1108
|
...r
|
|
1100
|
-
}),
|
|
1109
|
+
}), fo = (e, t, n = {}) => ({
|
|
1101
1110
|
table: e,
|
|
1102
1111
|
op: "delete",
|
|
1103
1112
|
old: t,
|
|
1104
1113
|
new: null,
|
|
1105
1114
|
...n
|
|
1106
|
-
}),
|
|
1115
|
+
}), po = (e, t, n = {}) => {
|
|
1107
1116
|
let { at: r = "2026-01-01T00:00:00.000Z", column: i = "deletedAt", ...a } = n;
|
|
1108
1117
|
return {
|
|
1109
1118
|
table: e,
|
|
@@ -1118,13 +1127,13 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
1118
1127
|
},
|
|
1119
1128
|
...a
|
|
1120
1129
|
};
|
|
1121
|
-
},
|
|
1130
|
+
}, mo = (e) => e == null ? "null" : e instanceof Date ? JSON.stringify(e.toISOString()) : typeof e == "bigint" ? JSON.stringify(e.toString()) : Array.isArray(e) ? `[${e.map(mo).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)}:${mo(t)}`).join(",")}}` : JSON.stringify(e) ?? "null", ho = (e) => Or("sha256").update([
|
|
1122
1131
|
e.pipe,
|
|
1123
1132
|
e.op,
|
|
1124
1133
|
e.key,
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
].join("\0")).digest("hex").slice(0, 32),
|
|
1134
|
+
mo(e.next),
|
|
1135
|
+
mo(e.prev)
|
|
1136
|
+
].join("\0")).digest("hex").slice(0, 32), go = (e, t) => `${e}:${t}`, _o = (e) => {
|
|
1128
1137
|
let t = e.lastIndexOf(":");
|
|
1129
1138
|
if (t <= 0) return null;
|
|
1130
1139
|
let n = Number(e.slice(t + 1));
|
|
@@ -1132,7 +1141,7 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
1132
1141
|
digest: e.slice(0, t),
|
|
1133
1142
|
occurrence: n
|
|
1134
1143
|
};
|
|
1135
|
-
},
|
|
1144
|
+
}, vo = class {
|
|
1136
1145
|
#e = /* @__PURE__ */ new Map();
|
|
1137
1146
|
#t;
|
|
1138
1147
|
#n;
|
|
@@ -1154,7 +1163,7 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
1154
1163
|
}
|
|
1155
1164
|
seedFromChangeKeys(e, t) {
|
|
1156
1165
|
for (let n of e) {
|
|
1157
|
-
let e =
|
|
1166
|
+
let e = _o(n);
|
|
1158
1167
|
if (e === null) continue;
|
|
1159
1168
|
let r = this.#e.get(e.digest), i = Math.max(r?.count ?? 0, e.occurrence + 1);
|
|
1160
1169
|
this.#e.set(e.digest, {
|
|
@@ -1175,70 +1184,70 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
1175
1184
|
this.#e.delete(e.value);
|
|
1176
1185
|
}
|
|
1177
1186
|
}
|
|
1178
|
-
},
|
|
1179
|
-
let t = Number(e[
|
|
1187
|
+
}, yo = "VOLTRO_CHANGE_CLAIMS_TTL_HOURS", bo = 1, xo = (e = process.env) => {
|
|
1188
|
+
let t = Number(e[yo]);
|
|
1180
1189
|
return (Number.isFinite(t) && t > 0 ? t : 1) * 2 * 36e5;
|
|
1181
|
-
},
|
|
1182
|
-
let t = e ??
|
|
1190
|
+
}, U = new kr(), So = (e, t) => U.run(e, t), Co = () => U.getStore(), wo = (e) => {
|
|
1191
|
+
let t = e ?? U.getStore();
|
|
1183
1192
|
return t === void 0 ? {} : {
|
|
1184
1193
|
...t.traceId === void 0 ? {} : { traceId: t.traceId },
|
|
1185
1194
|
...t.subjectId === void 0 ? {} : { subjectId: t.subjectId },
|
|
1186
1195
|
...t.procedure === void 0 ? {} : { procedure: t.procedure },
|
|
1187
1196
|
...t.via === void 0 ? {} : { via: t.via }
|
|
1188
1197
|
};
|
|
1189
|
-
},
|
|
1190
|
-
let t =
|
|
1191
|
-
return t === void 0 ? e(void 0) :
|
|
1192
|
-
},
|
|
1193
|
-
for (let [t, n] of
|
|
1194
|
-
let r = n.filter((t) => e - t.at <
|
|
1195
|
-
|
|
1196
|
-
}
|
|
1197
|
-
},
|
|
1198
|
+
}, To = (e) => {
|
|
1199
|
+
let t = U.getStore();
|
|
1200
|
+
return t === void 0 ? e(void 0) : U.run(t, () => e(t));
|
|
1201
|
+
}, Eo = 3e4, Do = 1e4, W = /* @__PURE__ */ new Map(), G = 0, Oo = (e, t, n) => `${e}\u0000${t}\u0000${String(n)}`, ko = (e) => {
|
|
1202
|
+
for (let [t, n] of W) {
|
|
1203
|
+
let r = n.filter((t) => e - t.at < Eo);
|
|
1204
|
+
G -= n.length - r.length, r.length === 0 ? W.delete(t) : r.length !== n.length && W.set(t, r);
|
|
1205
|
+
}
|
|
1206
|
+
}, Ao = (e, t) => {
|
|
1198
1207
|
if (t.traceId === void 0 && t.subjectId === void 0 && t.procedure === void 0) return;
|
|
1199
1208
|
let n = Date.now();
|
|
1200
|
-
if (
|
|
1201
|
-
let r =
|
|
1202
|
-
r === void 0 ?
|
|
1209
|
+
if (G >= Do && ko(n), G >= Do) return;
|
|
1210
|
+
let r = W.get(e);
|
|
1211
|
+
r === void 0 ? W.set(e, [{
|
|
1203
1212
|
attribution: t,
|
|
1204
1213
|
at: n
|
|
1205
1214
|
}]) : r.push({
|
|
1206
1215
|
attribution: t,
|
|
1207
1216
|
at: n
|
|
1208
|
-
}),
|
|
1209
|
-
},
|
|
1210
|
-
let t =
|
|
1217
|
+
}), G += 1;
|
|
1218
|
+
}, jo = (e) => {
|
|
1219
|
+
let t = W.get(e);
|
|
1211
1220
|
if (t === void 0 || t.length === 0) return;
|
|
1212
1221
|
let n = t.shift();
|
|
1213
|
-
if (--
|
|
1214
|
-
},
|
|
1215
|
-
let t =
|
|
1222
|
+
if (--G, t.length === 0 && W.delete(e), !(Date.now() - n.at >= Eo)) return n.attribution;
|
|
1223
|
+
}, Mo = (e) => (W.get(e)?.length ?? 0) > 0, K = /* @__PURE__ */ new Map(), q = /* @__PURE__ */ new Map(), No = /* @__PURE__ */ new Map(), Po = 250, Fo = (e) => {
|
|
1224
|
+
let t = q.get(e);
|
|
1216
1225
|
if (t === void 0) return;
|
|
1217
|
-
|
|
1218
|
-
let n =
|
|
1219
|
-
n !== void 0 && (clearTimeout(n),
|
|
1226
|
+
q.delete(e);
|
|
1227
|
+
let n = No.get(e);
|
|
1228
|
+
n !== void 0 && (clearTimeout(n), No.delete(e));
|
|
1220
1229
|
for (let e of t) e();
|
|
1221
|
-
},
|
|
1222
|
-
|
|
1223
|
-
},
|
|
1224
|
-
let t = (
|
|
1230
|
+
}, Io = (e) => {
|
|
1231
|
+
K.set(e, (K.get(e) ?? 0) + 1);
|
|
1232
|
+
}, Lo = (e) => {
|
|
1233
|
+
let t = (K.get(e) ?? 0) - 1;
|
|
1225
1234
|
if (t > 0) {
|
|
1226
|
-
|
|
1235
|
+
K.set(e, t);
|
|
1227
1236
|
return;
|
|
1228
1237
|
}
|
|
1229
|
-
|
|
1230
|
-
},
|
|
1231
|
-
let i = n == null ? void 0 :
|
|
1238
|
+
K.delete(e), Fo(e);
|
|
1239
|
+
}, Ro = (e, t, n, r) => {
|
|
1240
|
+
let i = n == null ? void 0 : Oo(e, t, n), a = () => r(i === void 0 ? void 0 : jo(i));
|
|
1232
1241
|
if (i === void 0) {
|
|
1233
1242
|
a();
|
|
1234
1243
|
return;
|
|
1235
1244
|
}
|
|
1236
|
-
if (
|
|
1245
|
+
if (Mo(i)) {
|
|
1237
1246
|
a();
|
|
1238
1247
|
return;
|
|
1239
1248
|
}
|
|
1240
|
-
let o =
|
|
1241
|
-
if (o === void 0 && (
|
|
1249
|
+
let o = q.get(e);
|
|
1250
|
+
if (o === void 0 && (K.get(e) ?? 0) === 0) {
|
|
1242
1251
|
a();
|
|
1243
1252
|
return;
|
|
1244
1253
|
}
|
|
@@ -1246,91 +1255,91 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
1246
1255
|
o.push(a);
|
|
1247
1256
|
return;
|
|
1248
1257
|
}
|
|
1249
|
-
|
|
1250
|
-
let s = setTimeout(() =>
|
|
1251
|
-
typeof s == "object" && typeof s.unref == "function" && s.unref(),
|
|
1252
|
-
},
|
|
1253
|
-
|
|
1254
|
-
for (let e of
|
|
1255
|
-
|
|
1256
|
-
},
|
|
1258
|
+
q.set(e, [a]);
|
|
1259
|
+
let s = setTimeout(() => Fo(e), Po);
|
|
1260
|
+
typeof s == "object" && typeof s.unref == "function" && s.unref(), No.set(e, s);
|
|
1261
|
+
}, zo = () => {
|
|
1262
|
+
W.clear(), G = 0, K.clear();
|
|
1263
|
+
for (let e of No.values()) clearTimeout(e);
|
|
1264
|
+
No.clear(), q.clear();
|
|
1265
|
+
}, Bo = () => G, Vo = 64, Ho = "\0", Uo = 32, Wo = (e, ...t) => `${e}_${Or("sha256").update(t.map(String).join(Ho)).digest("hex").slice(0, Uo)}`, Go = (e) => e.length + 1 + Uo, J = /* @__PURE__ */ new Map(), Ko = (e, t) => {
|
|
1257
1266
|
J.set(e, {
|
|
1258
1267
|
recorder: t.recorder,
|
|
1259
1268
|
tables: new Set(t.tables),
|
|
1260
1269
|
ownTables: new Set(t.ownTables)
|
|
1261
1270
|
});
|
|
1262
|
-
},
|
|
1271
|
+
}, qo = (e) => {
|
|
1263
1272
|
J.delete(e);
|
|
1264
|
-
},
|
|
1265
|
-
let t =
|
|
1273
|
+
}, Jo = () => J.clear(), Yo = new kr(), Xo = (e) => Yo.run({ n: 1 }, e), Zo = (e) => T.suspend(() => {
|
|
1274
|
+
let t = Yo.getStore();
|
|
1266
1275
|
if (t !== void 0) return t.n += 1, T.ensuring(e, T.sync(() => {
|
|
1267
1276
|
--t.n;
|
|
1268
1277
|
}));
|
|
1269
1278
|
let n = { n: 1 };
|
|
1270
|
-
return
|
|
1279
|
+
return Yo.enterWith(n), T.ensuring(e, T.sync(() => {
|
|
1271
1280
|
--n.n;
|
|
1272
1281
|
}));
|
|
1273
|
-
}),
|
|
1274
|
-
if (J.size === 0 || (
|
|
1282
|
+
}), Qo = () => (Yo.getStore()?.n ?? 0) > 0, $o = (e) => {
|
|
1283
|
+
if (J.size === 0 || (Yo.getStore()?.n ?? 0) > 0) return !1;
|
|
1275
1284
|
for (let t of J.values()) if (!t.ownTables.has(e) && t.tables.has(e)) return !0;
|
|
1276
1285
|
return !1;
|
|
1277
|
-
},
|
|
1286
|
+
}, es = async (e, t) => {
|
|
1278
1287
|
if (J.size !== 0) {
|
|
1279
1288
|
for (let [n, r] of J.entries()) if (!r.ownTables.has(t.table) && r.tables.has(t.table)) try {
|
|
1280
1289
|
await r.recorder(e, t);
|
|
1281
1290
|
} catch (e) {
|
|
1282
|
-
let r =
|
|
1291
|
+
let r = Ue(e);
|
|
1283
1292
|
throw r === void 0 ? e : Error(`write recorder '${n}' failed while recording a ${t.op} on '${t.table}': ${r}`, { cause: e });
|
|
1284
1293
|
}
|
|
1285
1294
|
}
|
|
1286
|
-
},
|
|
1295
|
+
}, ts = Tr.exponential({
|
|
1287
1296
|
start: 5e-4,
|
|
1288
1297
|
factor: 2,
|
|
1289
1298
|
count: 16
|
|
1290
|
-
}),
|
|
1291
|
-
let n = `${e}\u0000${t}`, r =
|
|
1299
|
+
}), ns = E.counter("voltro_db_queries_total", { description: "Database operations executed, by dialect and operation kind." }), rs = E.histogram("voltro_db_query_duration_seconds", ts, "Database operation duration in seconds, by dialect and operation kind."), is = E.counter("voltro_db_errors_total", { description: "Database operations that threw, by dialect and operation kind." }), as = E.gauge("voltro_db_operations_in_flight", { description: "Database operations currently executing, by dialect. An upper bound on connections the framework holds; NOT the driver pool's waiting count." }), os = E.counter("voltro_db_eager_fallback_total", { description: "Eager-load queries that degraded from the single-roundtrip JSON-agg path to the multi-query walker, by dialect and reason." }), ss = [], cs = /* @__PURE__ */ new Map(), ls = /* @__PURE__ */ new Map(), us = /* @__PURE__ */ new Map(), ds = (e, t) => {
|
|
1300
|
+
let n = `${e}\u0000${t}`, r = cs.get(n);
|
|
1292
1301
|
if (r !== void 0) return r;
|
|
1293
1302
|
let i = (n) => E.tagged(E.tagged(n, "dialect", e), "op", t), a = {
|
|
1294
|
-
count: i(
|
|
1295
|
-
duration: i(
|
|
1296
|
-
errors: i(
|
|
1303
|
+
count: i(ns),
|
|
1304
|
+
duration: i(rs),
|
|
1305
|
+
errors: i(is)
|
|
1297
1306
|
};
|
|
1298
|
-
return
|
|
1299
|
-
},
|
|
1300
|
-
|
|
1301
|
-
},
|
|
1302
|
-
let n = Math.max(0, (
|
|
1303
|
-
n === 0 ?
|
|
1304
|
-
let r =
|
|
1305
|
-
r === void 0 && (r = E.tagged(
|
|
1306
|
-
},
|
|
1307
|
-
let t =
|
|
1308
|
-
t.count.unsafeUpdate(1,
|
|
1309
|
-
},
|
|
1307
|
+
return cs.set(n, a), a;
|
|
1308
|
+
}, fs = () => {
|
|
1309
|
+
cs.clear(), ls.clear(), us.clear();
|
|
1310
|
+
}, ps = () => cs.size + ls.size + us.size, ms = /* @__PURE__ */ new Map(), hs = (e, t) => {
|
|
1311
|
+
let n = Math.max(0, (ms.get(e) ?? 0) + t);
|
|
1312
|
+
n === 0 ? ms.delete(e) : ms.set(e, n);
|
|
1313
|
+
let r = ls.get(e);
|
|
1314
|
+
r === void 0 && (r = E.tagged(as, "dialect", e), ls.set(e, r)), r.unsafeUpdate(n, ss);
|
|
1315
|
+
}, gs = (e) => ms.get(e) ?? 0, _s = (e) => {
|
|
1316
|
+
let t = ds(String(e.dialect), e.op);
|
|
1317
|
+
t.count.unsafeUpdate(1, ss), t.duration.unsafeUpdate(e.durationMs / 1e3, ss), e.status === "error" && t.errors.unsafeUpdate(1, ss);
|
|
1318
|
+
}, vs = async (e, t, n) => {
|
|
1310
1319
|
let r = performance.now(), i = String(e);
|
|
1311
|
-
|
|
1320
|
+
hs(i, 1);
|
|
1312
1321
|
let a = "ok";
|
|
1313
1322
|
try {
|
|
1314
1323
|
return await n();
|
|
1315
1324
|
} catch (e) {
|
|
1316
1325
|
throw a = "error", e;
|
|
1317
1326
|
} finally {
|
|
1318
|
-
|
|
1327
|
+
hs(i, -1), _s({
|
|
1319
1328
|
dialect: e,
|
|
1320
1329
|
op: t,
|
|
1321
1330
|
durationMs: performance.now() - r,
|
|
1322
1331
|
status: a
|
|
1323
1332
|
});
|
|
1324
1333
|
}
|
|
1325
|
-
},
|
|
1334
|
+
}, ys = 3e5, bs = (e) => {
|
|
1326
1335
|
if (e == null || e === "") return;
|
|
1327
1336
|
let t = Number(e);
|
|
1328
1337
|
return Number.isFinite(t) && t >= 0 ? Math.floor(t) : void 0;
|
|
1329
|
-
},
|
|
1330
|
-
let n =
|
|
1338
|
+
}, xs = (e, t = process.env) => bs(t.VOLTRO_DB_EAGER_FALLBACK_WARN_INTERVAL_MS) ?? bs(e) ?? 3e5, Ss = (e, t = {}) => {
|
|
1339
|
+
let n = xs(t.warnIntervalMs), r = t.now ?? (() => Date.now()), i = /* @__PURE__ */ new Map();
|
|
1331
1340
|
return (t) => {
|
|
1332
|
-
let a = `${t.dialect} ${t.reason}`, o =
|
|
1333
|
-
o === void 0 && (o = E.tagged(E.tagged(
|
|
1341
|
+
let a = `${t.dialect} ${t.reason}`, o = us.get(a);
|
|
1342
|
+
o === void 0 && (o = E.tagged(E.tagged(os, "dialect", String(t.dialect)), "reason", t.reason), us.set(a, o)), o.unsafeUpdate(1, ss);
|
|
1334
1343
|
let s = `${t.table}\u0000${t.reason}`, c = i.get(s), l = c === void 0 || n > 0 && r() - c >= n, u = {
|
|
1335
1344
|
table: t.table,
|
|
1336
1345
|
dialect: String(t.dialect),
|
|
@@ -1344,13 +1353,13 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
1344
1353
|
}
|
|
1345
1354
|
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);
|
|
1346
1355
|
};
|
|
1347
|
-
},
|
|
1348
|
-
if (
|
|
1349
|
-
throw
|
|
1350
|
-
},
|
|
1356
|
+
}, Cs = (e) => {
|
|
1357
|
+
if (wr.isSuccess(e)) return e.value;
|
|
1358
|
+
throw xr.squash(e.cause);
|
|
1359
|
+
}, ws = "10 millis", Ts = 3, Es = (e) => Er.exponential(ws).pipe(Er.compose(Er.recurs(Ts)), Er.whileInput(e)), Ds = async (e) => {
|
|
1351
1360
|
let t = 0, n = T.suspend(() => {
|
|
1352
1361
|
let n = ++t;
|
|
1353
|
-
return e.withTransaction(T.flatMap(T.serviceOption(
|
|
1362
|
+
return e.withTransaction(T.flatMap(T.serviceOption(Ar), (t) => {
|
|
1354
1363
|
if (D.isNone(t)) return T.fail(/* @__PURE__ */ Error(`${e.label}: TransactionConnection unexpectedly missing inside withTransaction.`));
|
|
1355
1364
|
let r = t.value, i = T.tryPromise({
|
|
1356
1365
|
try: () => e.body(r, n),
|
|
@@ -1358,23 +1367,23 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
1358
1367
|
});
|
|
1359
1368
|
return e.prepare === void 0 ? i : T.flatMap(e.prepare(r), () => i);
|
|
1360
1369
|
})).pipe(T.catchAllDefect((t) => e.isRetryable(t) ? T.fail(t) : T.die(t)));
|
|
1361
|
-
}).pipe(T.retry(
|
|
1362
|
-
return
|
|
1363
|
-
},
|
|
1370
|
+
}).pipe(T.retry(Es(e.isRetryable)), T.withSpan(e.span.name, { attributes: { ...e.span.attributes } }));
|
|
1371
|
+
return vs(e.dialect, "transaction", async () => Cs(await e.runPromiseExit(e.wrapProgram === void 0 ? n : e.wrapProgram(n))));
|
|
1372
|
+
}, Os = class extends Error {
|
|
1364
1373
|
swallowed;
|
|
1365
1374
|
_tag = "TransactionAborted";
|
|
1366
1375
|
constructor(e, t) {
|
|
1367
1376
|
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.
|
|
1368
|
-
the caught failure: ${
|
|
1377
|
+
the caught failure: ${Ms(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";
|
|
1369
1378
|
}
|
|
1370
|
-
},
|
|
1379
|
+
}, ks = (e, t = "transactional()") => {
|
|
1371
1380
|
let n = 0, r, i = (e) => {
|
|
1372
1381
|
r === void 0 && (r = { error: e });
|
|
1373
1382
|
};
|
|
1374
1383
|
return {
|
|
1375
1384
|
track: (a) => r === void 0 ? n > 0 ? a() : a().catch((t) => {
|
|
1376
1385
|
throw e(t) && i(t), t;
|
|
1377
|
-
}) : Promise.reject(new
|
|
1386
|
+
}) : Promise.reject(new Os(t, r.error)),
|
|
1378
1387
|
inSavepoint: async (e) => {
|
|
1379
1388
|
n++;
|
|
1380
1389
|
try {
|
|
@@ -1386,7 +1395,7 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
1386
1395
|
record: i,
|
|
1387
1396
|
abortedBy: () => r
|
|
1388
1397
|
};
|
|
1389
|
-
},
|
|
1398
|
+
}, As = async (e, t) => {
|
|
1390
1399
|
let { tracker: n, name: r, exec: i, spelling: a } = e;
|
|
1391
1400
|
await n.track(() => i(a === "mssql" ? `SAVE TRANSACTION ${r}` : `SAVEPOINT ${r}`));
|
|
1392
1401
|
try {
|
|
@@ -1395,8 +1404,8 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
1395
1404
|
} catch (e) {
|
|
1396
1405
|
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;
|
|
1397
1406
|
}
|
|
1398
|
-
},
|
|
1399
|
-
for (let t of
|
|
1407
|
+
}, js = (e) => e instanceof Os || typeof e == "object" && !!e && e._tag === "TransactionAborted", Ms = (e) => {
|
|
1408
|
+
for (let t of ht(e)) {
|
|
1400
1409
|
let e = t;
|
|
1401
1410
|
for (let t = 0; t < 5 && typeof e == "object" && e; t++) {
|
|
1402
1411
|
let t = e.code, n = e.message;
|
|
@@ -1405,14 +1414,14 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
1405
1414
|
}
|
|
1406
1415
|
}
|
|
1407
1416
|
return e instanceof Error ? e.message : String(e);
|
|
1408
|
-
},
|
|
1409
|
-
let t =
|
|
1417
|
+
}, Ns = async (e) => {
|
|
1418
|
+
let t = Co(), n = t === void 0 ? (e) => e() : (e) => So(t, e), r = await Ds({
|
|
1410
1419
|
...e,
|
|
1411
1420
|
body: (r) => {
|
|
1412
1421
|
let i = e.makeView(r, t);
|
|
1413
1422
|
return n(() => e.work(i)).then((t) => {
|
|
1414
1423
|
let n = i.abortedBy?.();
|
|
1415
|
-
if (n !== void 0) throw e.isRetryable(n.error) ? n.error : new
|
|
1424
|
+
if (n !== void 0) throw e.isRetryable(n.error) ? n.error : new Os(e.label, n.error);
|
|
1416
1425
|
return {
|
|
1417
1426
|
result: t,
|
|
1418
1427
|
view: i
|
|
@@ -1424,50 +1433,50 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
1424
1433
|
}
|
|
1425
1434
|
});
|
|
1426
1435
|
return r.view.commitEvents(), r.result;
|
|
1427
|
-
},
|
|
1436
|
+
}, Ps = /* @__PURE__ */ new Set([
|
|
1428
1437
|
"1213",
|
|
1429
1438
|
"ER_LOCK_DEADLOCK",
|
|
1430
1439
|
"1205",
|
|
1431
1440
|
"ER_LOCK_WAIT_TIMEOUT",
|
|
1432
1441
|
"1020",
|
|
1433
1442
|
"ER_CHECKREAD"
|
|
1434
|
-
]),
|
|
1443
|
+
]), Fs = /* @__PURE__ */ new Set(["40001", "40P01"]), Is = /* @__PURE__ */ new Set(["1205"]), Ls = /* @__PURE__ */ new Set([
|
|
1435
1444
|
"SQLITE_BUSY",
|
|
1436
1445
|
"5",
|
|
1437
1446
|
"SQLITE_LOCKED",
|
|
1438
1447
|
"6"
|
|
1439
|
-
]),
|
|
1448
|
+
]), Rs = /write-write conflict|write-read conflict|database is locked|table is locked|database is busy/i, zs = /* @__PURE__ */ new Set([
|
|
1440
1449
|
1213,
|
|
1441
1450
|
1205,
|
|
1442
1451
|
1020
|
|
1443
|
-
]),
|
|
1444
|
-
...
|
|
1445
|
-
...
|
|
1446
|
-
...
|
|
1447
|
-
...
|
|
1448
|
-
]),
|
|
1452
|
+
]), Bs = /* @__PURE__ */ new Set([
|
|
1453
|
+
...Ps,
|
|
1454
|
+
...Fs,
|
|
1455
|
+
...Is,
|
|
1456
|
+
...Ls
|
|
1457
|
+
]), Vs = (e) => ht(e).some(Hs), Hs = (e) => {
|
|
1449
1458
|
let t = e;
|
|
1450
1459
|
for (let e = 0; e < 6 && typeof t == "object" && t; e++) {
|
|
1451
1460
|
let e = t;
|
|
1452
|
-
if (typeof e.errno == "number" &&
|
|
1461
|
+
if (typeof e.errno == "number" && zs.has(e.errno) || typeof e.number == "number" && Is.has(String(e.number)) || typeof e.code == "string" && Bs.has(e.code) || typeof e.sqlState == "string" && Fs.has(e.sqlState) || typeof e.message == "string" && Rs.test(e.message)) return !0;
|
|
1453
1462
|
t = e.cause;
|
|
1454
1463
|
}
|
|
1455
1464
|
return !1;
|
|
1456
|
-
},
|
|
1457
|
-
id:
|
|
1458
|
-
fields: { expiresAt:
|
|
1465
|
+
}, Us = "voltro/expires", Ws = () => De({
|
|
1466
|
+
id: Us,
|
|
1467
|
+
fields: { expiresAt: w().nullable() },
|
|
1459
1468
|
behaviors: { defaultWhere: () => "expiresAt IS NULL OR expiresAt > now()" }
|
|
1460
|
-
}),
|
|
1461
|
-
id:
|
|
1469
|
+
}), Gs = "voltro/localFirst", Ks = () => De({
|
|
1470
|
+
id: Gs,
|
|
1462
1471
|
fields: {}
|
|
1463
|
-
}),
|
|
1472
|
+
}), qs = (e) => e.appliedMixins.some((e) => e.id === Gs), Js = (e) => {
|
|
1464
1473
|
let t = [];
|
|
1465
|
-
for (let n of Object.values(e))
|
|
1474
|
+
for (let n of Object.values(e)) qs(n) && t.push(n.tableName);
|
|
1466
1475
|
return t;
|
|
1467
|
-
},
|
|
1476
|
+
}, Ys = class extends Cr.TaggedError("TableStreamError") {}, Xs = 1e3, Zs = (e, t, n, r) => {
|
|
1468
1477
|
let i = D.match(r, {
|
|
1469
1478
|
onNone: () => e.where,
|
|
1470
|
-
onSome: (n) => e.where ?
|
|
1479
|
+
onSome: (n) => e.where ? dt(e.where, Et(t, n)) : Et(t, n)
|
|
1471
1480
|
});
|
|
1472
1481
|
return {
|
|
1473
1482
|
table: e.table,
|
|
@@ -1482,19 +1491,19 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
1482
1491
|
...e.includeDeleted === void 0 ? {} : { includeDeleted: e.includeDeleted },
|
|
1483
1492
|
...e.crossTenant === void 0 ? {} : { crossTenant: e.crossTenant }
|
|
1484
1493
|
};
|
|
1485
|
-
},
|
|
1486
|
-
let n = t.pk ?? "id", r = t.chunkSize ??
|
|
1487
|
-
return
|
|
1494
|
+
}, Qs = (e, t) => {
|
|
1495
|
+
let n = t.pk ?? "id", r = t.chunkSize ?? Xs;
|
|
1496
|
+
return Dr.paginateChunkEffect(D.none(), (i) => {
|
|
1488
1497
|
let a = T.tryPromise({
|
|
1489
|
-
try: () => e.query(
|
|
1490
|
-
catch: (e) => new
|
|
1498
|
+
try: () => e.query(Zs(t, n, r, i)),
|
|
1499
|
+
catch: (e) => new Ys({
|
|
1491
1500
|
table: t.table,
|
|
1492
1501
|
cause: e
|
|
1493
1502
|
})
|
|
1494
1503
|
});
|
|
1495
|
-
return (t.retry ? a.pipe(T.retry(t.retry)) : a).pipe(T.map((e) => [
|
|
1504
|
+
return (t.retry ? a.pipe(T.retry(t.retry)) : a).pipe(T.map((e) => [Sr.fromIterable(e), e.length === r && e.length > 0 ? D.some(D.some(e[e.length - 1][n])) : D.none()]));
|
|
1496
1505
|
});
|
|
1497
|
-
},
|
|
1506
|
+
}, $s = (e) => {
|
|
1498
1507
|
let t = e.alpha ?? .5;
|
|
1499
1508
|
if (t < 0 || t > 1) throw Error(`hybridSearch: alpha must be in [0, 1], got ${t}`);
|
|
1500
1509
|
return (n) => {
|
|
@@ -1508,7 +1517,7 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
1508
1517
|
queryText: e.vector.query,
|
|
1509
1518
|
distance: e.vector.distance ?? "cosine",
|
|
1510
1519
|
alpha: t
|
|
1511
|
-
}, i =
|
|
1520
|
+
}, i = qn(n.table, e.fts.indexName, n.fullTextIndexes);
|
|
1512
1521
|
return {
|
|
1513
1522
|
...n,
|
|
1514
1523
|
annClause: r,
|
|
@@ -1521,17 +1530,17 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
1521
1530
|
}
|
|
1522
1531
|
};
|
|
1523
1532
|
};
|
|
1524
|
-
},
|
|
1533
|
+
}, ec = async (e, t) => {
|
|
1525
1534
|
let n = e.as ?? "embedding", r = t.row[e.from];
|
|
1526
1535
|
if (typeof r != "string" || r.length === 0) return {};
|
|
1527
1536
|
let i = await t.embed(r);
|
|
1528
1537
|
return { [n]: i };
|
|
1529
|
-
},
|
|
1538
|
+
}, tc = (e) => {
|
|
1530
1539
|
if (!Number.isInteger(e.dimensions) || e.dimensions <= 0) throw Error(`vectorEmbedding: dimensions must be a positive integer, got ${String(e.dimensions)}.`);
|
|
1531
|
-
let t = e.as ?? "embedding", n = (t) =>
|
|
1532
|
-
return
|
|
1540
|
+
let t = e.as ?? "embedding", n = (t) => ec(e, t);
|
|
1541
|
+
return De({
|
|
1533
1542
|
id: "voltro/vectorEmbedding",
|
|
1534
|
-
fields: { [t]:
|
|
1543
|
+
fields: { [t]: l(e.dimensions) },
|
|
1535
1544
|
...e.index === !1 ? {} : { indexes: [{
|
|
1536
1545
|
fields: [t],
|
|
1537
1546
|
kind: "hnsw",
|
|
@@ -1546,19 +1555,19 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
1546
1555
|
beforeUpdate: n
|
|
1547
1556
|
}
|
|
1548
1557
|
});
|
|
1549
|
-
},
|
|
1558
|
+
}, nc = 63, rc = "br_pr", Y = class extends Error {
|
|
1550
1559
|
_tag = "BranchNameInvalid";
|
|
1551
1560
|
constructor(e) {
|
|
1552
1561
|
super(e), this.name = "BranchNameInvalid";
|
|
1553
1562
|
}
|
|
1554
|
-
},
|
|
1563
|
+
}, ic = (e, t) => {
|
|
1555
1564
|
if (!Number.isInteger(t) || t < 0) throw new Y(`prNumber must be a non-negative integer, got ${String(t)}`);
|
|
1556
|
-
let n =
|
|
1565
|
+
let n = oe(e);
|
|
1557
1566
|
if (n.replace(/_/g, "") === "") throw new Y(`app slug '${e}' has no usable identifier characters`);
|
|
1558
|
-
let r = `${
|
|
1559
|
-
if (r.length >
|
|
1567
|
+
let r = `${rc}${t}_${n}`;
|
|
1568
|
+
if (r.length > nc) throw new Y(`branch namespace '${r}' exceeds the ${nc}-byte identifier limit — use a shorter app slug`);
|
|
1560
1569
|
return r;
|
|
1561
|
-
},
|
|
1570
|
+
}, ac = (e) => e.startsWith(rc), oc = {
|
|
1562
1571
|
requested: {
|
|
1563
1572
|
provision: "provisioning",
|
|
1564
1573
|
destroy: "destroying"
|
|
@@ -1577,18 +1586,18 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
1577
1586
|
fail: "failed"
|
|
1578
1587
|
},
|
|
1579
1588
|
destroyed: {}
|
|
1580
|
-
},
|
|
1589
|
+
}, sc = class extends Error {
|
|
1581
1590
|
from;
|
|
1582
1591
|
event;
|
|
1583
1592
|
_tag = "BranchTransitionInvalid";
|
|
1584
1593
|
constructor(e, t) {
|
|
1585
1594
|
super(`invalid branch transition: ${e} --${t}-->`), this.from = e, this.event = t, this.name = "BranchTransitionInvalid";
|
|
1586
1595
|
}
|
|
1587
|
-
},
|
|
1588
|
-
let n =
|
|
1589
|
-
if (n === void 0) throw new
|
|
1596
|
+
}, cc = (e, t) => {
|
|
1597
|
+
let n = oc[e][t];
|
|
1598
|
+
if (n === void 0) throw new sc(e, t);
|
|
1590
1599
|
return n;
|
|
1591
|
-
},
|
|
1600
|
+
}, lc = (e, t, n, r, i = [], a = []) => {
|
|
1592
1601
|
if (n === "copy" && (r === void 0 || r === "")) throw new Y("seed 'copy' requires a parentNamespace to snapshot from");
|
|
1593
1602
|
let o = [{
|
|
1594
1603
|
kind: "create-namespace",
|
|
@@ -1618,13 +1627,13 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
1618
1627
|
kind: "seed",
|
|
1619
1628
|
detail: `run boot seeds into ${e}`
|
|
1620
1629
|
}), o;
|
|
1621
|
-
},
|
|
1622
|
-
if (!
|
|
1630
|
+
}, uc = (e) => {
|
|
1631
|
+
if (!ac(e)) throw new Y(`refusing to plan teardown of '${e}' — not a branch namespace`);
|
|
1623
1632
|
return [{
|
|
1624
1633
|
kind: "drop-namespace",
|
|
1625
1634
|
detail: e
|
|
1626
1635
|
}];
|
|
1627
|
-
},
|
|
1636
|
+
}, dc = (e) => {
|
|
1628
1637
|
if (e === void 0 || e === "") return !1;
|
|
1629
1638
|
try {
|
|
1630
1639
|
let t = new URL(e).hostname.toLowerCase();
|
|
@@ -1632,27 +1641,27 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
1632
1641
|
} catch {
|
|
1633
1642
|
return /\bneon\.(tech|build)\b/i.test(e);
|
|
1634
1643
|
}
|
|
1635
|
-
},
|
|
1644
|
+
}, fc = (e) => e.prefer === void 0 ? e.seed === "copy" && dc(e.dbUrl) ? "neon-cow" : "namespace" : e.prefer, pc = (e, t = {}) => [{
|
|
1636
1645
|
kind: "neon-branch-create",
|
|
1637
1646
|
detail: `${t.parentBranch ?? "main"} → ${e} (copy-on-write)`
|
|
1638
|
-
}],
|
|
1639
|
-
if (!
|
|
1647
|
+
}], mc = (e) => {
|
|
1648
|
+
if (!ac(e)) throw new Y(`refusing to plan teardown of '${e}' — not a branch namespace`);
|
|
1640
1649
|
return [{
|
|
1641
1650
|
kind: "neon-branch-delete",
|
|
1642
1651
|
detail: e
|
|
1643
1652
|
}];
|
|
1644
|
-
},
|
|
1653
|
+
}, hc = (e) => e.mechanism === "neon-cow" ? pc(e.branchId, e.neonParentBranch === void 0 ? {} : { parentBranch: e.neonParentBranch }) : lc(e.branchId, e.tableNames, e.seed, e.parentNamespace, e.foreignKeys, e.indexNames), gc = (e, t) => e === "neon-cow" ? mc(t) : uc(t), _c = (e, t, n) => {
|
|
1645
1654
|
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);
|
|
1646
1655
|
return {
|
|
1647
1656
|
evict: i,
|
|
1648
1657
|
rejectNew: r.filter((e) => !a.has(e.namespace)).length >= t.maxBranches
|
|
1649
1658
|
};
|
|
1650
|
-
},
|
|
1651
|
-
let n =
|
|
1659
|
+
}, vc = async (e, t) => {
|
|
1660
|
+
let n = ic(e.appSlug, e.prNumber), r = fc({
|
|
1652
1661
|
seed: e.seed,
|
|
1653
1662
|
...e.dbUrl === void 0 ? {} : { dbUrl: e.dbUrl },
|
|
1654
1663
|
...e.prefer === void 0 ? {} : { prefer: e.prefer }
|
|
1655
|
-
}), i =
|
|
1664
|
+
}), i = hc({
|
|
1656
1665
|
mechanism: r,
|
|
1657
1666
|
branchId: n,
|
|
1658
1667
|
tableNames: e.tableNames,
|
|
@@ -1681,15 +1690,15 @@ var Or = (e) => typeof e == "string" && e !== "" ? e : null, kr = async (e, t, n
|
|
|
1681
1690
|
mechanism: r,
|
|
1682
1691
|
steps: i
|
|
1683
1692
|
};
|
|
1684
|
-
},
|
|
1685
|
-
let r =
|
|
1693
|
+
}, yc = async (e, t, n) => {
|
|
1694
|
+
let r = gc(t, e);
|
|
1686
1695
|
return t === "neon-cow" ? await n.neonBranchDelete(e) : await n.dropNamespace(e), r;
|
|
1687
|
-
},
|
|
1696
|
+
}, bc = (e, t, n) => _c(e, t, n), X = (e) => `"${e.replace(/"/g, "\"\"")}"`, xc = {
|
|
1688
1697
|
cascade: "CASCADE",
|
|
1689
1698
|
restrict: "RESTRICT",
|
|
1690
1699
|
setNull: "SET NULL",
|
|
1691
1700
|
noAction: "NO ACTION"
|
|
1692
|
-
}, Z = (e) => `'${e.replace(/'/g, "''")}'`,
|
|
1701
|
+
}, Z = (e) => `'${e.replace(/'/g, "''")}'`, Sc = (e, t) => {
|
|
1693
1702
|
let n = t.columns.map(Z).join(", ");
|
|
1694
1703
|
return `DO $voltro_branch$
|
|
1695
1704
|
DECLARE derived name;
|
|
@@ -1716,10 +1725,10 @@ BEGIN
|
|
|
1716
1725
|
END IF;
|
|
1717
1726
|
END
|
|
1718
1727
|
$voltro_branch$`;
|
|
1719
|
-
},
|
|
1720
|
-
let n = t.onDelete === void 0 ? "" : ` ON DELETE ${
|
|
1728
|
+
}, Cc = (e, t) => {
|
|
1729
|
+
let n = t.onDelete === void 0 ? "" : ` ON DELETE ${xc[t.onDelete]}`, r = t.onUpdate === void 0 ? "" : ` ON UPDATE ${xc[t.onUpdate]}`;
|
|
1721
1730
|
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}`;
|
|
1722
|
-
},
|
|
1731
|
+
}, wc = (e) => {
|
|
1723
1732
|
let t = () => {
|
|
1724
1733
|
throw Error("namespace branch executor: Neon ops require a neon-cow executor (use a Neon connection for copy-on-write branches)");
|
|
1725
1734
|
};
|
|
@@ -1727,24 +1736,24 @@ $voltro_branch$`;
|
|
|
1727
1736
|
createNamespace: (t) => e.run(`CREATE SCHEMA IF NOT EXISTS ${X(t)}`),
|
|
1728
1737
|
createTable: (t, n) => e.run(`CREATE TABLE IF NOT EXISTS ${X(t)}.${X(n)} (LIKE ${X(n)} INCLUDING ALL)`),
|
|
1729
1738
|
copyTable: (t, n, r) => e.run(`INSERT INTO ${X(n)}.${X(r)} SELECT * FROM ${X(t)}.${X(r)}`),
|
|
1730
|
-
addForeignKey: (t, n) => e.run(
|
|
1731
|
-
restoreIndexName: (t, n) => e.run(
|
|
1739
|
+
addForeignKey: (t, n) => e.run(Cc(t, n)),
|
|
1740
|
+
restoreIndexName: (t, n) => e.run(Sc(t, n)),
|
|
1732
1741
|
dropNamespace: (t) => e.run(`DROP SCHEMA IF EXISTS ${X(t)} CASCADE`),
|
|
1733
1742
|
neonBranchCreate: t,
|
|
1734
1743
|
neonBranchDelete: t
|
|
1735
1744
|
};
|
|
1736
|
-
},
|
|
1745
|
+
}, Tc = class extends Error {
|
|
1737
1746
|
_tag = "TenantResidencyUnresolved";
|
|
1738
1747
|
constructor(e) {
|
|
1739
1748
|
super(e), this.name = "TenantResidencyUnresolved";
|
|
1740
1749
|
}
|
|
1741
|
-
},
|
|
1750
|
+
}, Ec = class extends Error {
|
|
1742
1751
|
region;
|
|
1743
1752
|
_tag = "TenantRegionUnavailable";
|
|
1744
1753
|
constructor(e, t) {
|
|
1745
1754
|
super(t), this.region = e, this.name = "TenantRegionUnavailable";
|
|
1746
1755
|
}
|
|
1747
|
-
},
|
|
1756
|
+
}, Dc, Oc = (e) => {
|
|
1748
1757
|
if (e.homes === void 0) throw Error("setResidencyConfig: `homes` is required");
|
|
1749
1758
|
if (e.servableRegions === void 0 || e.servableRegions.length === 0) throw Error("setResidencyConfig: `servableRegions` must be non-empty (which regions this deployment serves)");
|
|
1750
1759
|
let t = /* @__PURE__ */ new Map();
|
|
@@ -1753,55 +1762,55 @@ $voltro_branch$`;
|
|
|
1753
1762
|
if (e !== void 0 && e !== n.region) throw Error(`residency: tenant '${n.tenantId}' is mapped to two regions ('${e}' and '${n.region}')`);
|
|
1754
1763
|
t.set(n.tenantId, n.region);
|
|
1755
1764
|
}
|
|
1756
|
-
return
|
|
1757
|
-
},
|
|
1758
|
-
|
|
1759
|
-
},
|
|
1760
|
-
if (e == null || e === "") throw new
|
|
1765
|
+
return Dc = e, e;
|
|
1766
|
+
}, kc = () => Dc, Ac = () => {
|
|
1767
|
+
Dc = void 0;
|
|
1768
|
+
}, jc = (e, t) => {
|
|
1769
|
+
if (e == null || e === "") throw new Tc("residency is on but the request has no resolvable tenant — refusing to bind a store");
|
|
1761
1770
|
let n = t.homes.find((t) => t.tenantId === e);
|
|
1762
|
-
if (n === void 0) throw new
|
|
1771
|
+
if (n === void 0) throw new Tc(`no residency home is mapped for tenant '${e}' — refusing to fall back to a default store (would be a residency violation)`);
|
|
1763
1772
|
return n;
|
|
1764
|
-
},
|
|
1765
|
-
let n =
|
|
1773
|
+
}, Mc = (e, t) => t.servableRegions.includes(e), Nc = (e, t) => {
|
|
1774
|
+
let n = jc(e.tenantId, t), r = Ve(n.tenantId);
|
|
1766
1775
|
return {
|
|
1767
1776
|
region: n.region,
|
|
1768
1777
|
namespace: r,
|
|
1769
1778
|
...n.connectionKey === void 0 ? {} : { connectionKey: n.connectionKey }
|
|
1770
1779
|
};
|
|
1771
|
-
},
|
|
1772
|
-
let r =
|
|
1773
|
-
if (!
|
|
1780
|
+
}, Pc = (e, t, n) => {
|
|
1781
|
+
let r = Nc(e, t);
|
|
1782
|
+
if (!Mc(r.region, t)) throw new Ec(r.region, `tenant homed in region '${r.region}', which this deployment does not serve — route to the home region`);
|
|
1774
1783
|
let i = n.get(r.region);
|
|
1775
|
-
if (i === void 0) throw new
|
|
1784
|
+
if (i === void 0) throw new Ec(r.region, `no store handle for home region '${r.region}' (declared servable but not wired) — failing closed`);
|
|
1776
1785
|
return {
|
|
1777
1786
|
store: i,
|
|
1778
1787
|
placement: r
|
|
1779
1788
|
};
|
|
1780
|
-
},
|
|
1781
|
-
let { store: i, placement: a } =
|
|
1789
|
+
}, Fc = async (e, t, n, r) => {
|
|
1790
|
+
let { store: i, placement: a } = Pc(e, t, n);
|
|
1782
1791
|
return await r(i, a), a;
|
|
1783
|
-
},
|
|
1792
|
+
}, Ic = (e) => {
|
|
1784
1793
|
if (typeof e == "string") return e;
|
|
1785
1794
|
if ("jsonPath" in e) {
|
|
1786
1795
|
let { column: t, path: n, numeric: r } = e.jsonPath;
|
|
1787
1796
|
return `(json:${t}->${n.join(".")}${r ? "::num" : ""})`;
|
|
1788
1797
|
}
|
|
1789
1798
|
return `(${e.expr})`;
|
|
1790
|
-
}, Q = (e) => e.map(
|
|
1799
|
+
}, Q = (e) => e.map(Ic), Lc = (e, t) => {
|
|
1791
1800
|
if (e.length !== t.length) return !1;
|
|
1792
|
-
for (let n = 0; n < e.length; n++) if (
|
|
1801
|
+
for (let n = 0; n < e.length; n++) if (Ic(e[n]) !== Ic(t[n])) return !1;
|
|
1793
1802
|
return !0;
|
|
1794
|
-
},
|
|
1803
|
+
}, Rc = (e, t) => {
|
|
1795
1804
|
if (e.length >= t.length) return !1;
|
|
1796
|
-
for (let n = 0; n < e.length; n++) if (
|
|
1805
|
+
for (let n = 0; n < e.length; n++) if (Ic(e[n]) !== Ic(t[n])) return !1;
|
|
1797
1806
|
return !0;
|
|
1798
|
-
},
|
|
1807
|
+
}, zc = (e) => {
|
|
1799
1808
|
let t = [], n = e.appliedIndexes, r = e.tableName;
|
|
1800
1809
|
for (let e = 0; e < n.length; e++) {
|
|
1801
1810
|
let i = n[e];
|
|
1802
1811
|
for (let a = e + 1; a < n.length; a++) {
|
|
1803
1812
|
let e = n[a];
|
|
1804
|
-
if (
|
|
1813
|
+
if (Lc(i.fields, e.fields)) {
|
|
1805
1814
|
let [n, a] = i.name < e.name ? [i, e] : [e, i];
|
|
1806
1815
|
t.push({
|
|
1807
1816
|
kind: "duplicate-fields",
|
|
@@ -1812,13 +1821,13 @@ $voltro_branch$`;
|
|
|
1812
1821
|
});
|
|
1813
1822
|
continue;
|
|
1814
1823
|
}
|
|
1815
|
-
|
|
1824
|
+
Rc(i.fields, e.fields) ? t.push({
|
|
1816
1825
|
kind: "redundant-prefix",
|
|
1817
1826
|
table: r,
|
|
1818
1827
|
redundant: i,
|
|
1819
1828
|
coveredBy: e,
|
|
1820
1829
|
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).`
|
|
1821
|
-
}) :
|
|
1830
|
+
}) : Rc(e.fields, i.fields) && t.push({
|
|
1822
1831
|
kind: "redundant-prefix",
|
|
1823
1832
|
table: r,
|
|
1824
1833
|
redundant: e,
|
|
@@ -1828,23 +1837,23 @@ $voltro_branch$`;
|
|
|
1828
1837
|
}
|
|
1829
1838
|
}
|
|
1830
1839
|
return t;
|
|
1831
|
-
},
|
|
1840
|
+
}, Bc = (e) => {
|
|
1832
1841
|
let t = [];
|
|
1833
|
-
for (let n of e) t.push(...
|
|
1842
|
+
for (let n of e) t.push(...zc(n));
|
|
1834
1843
|
return t;
|
|
1835
|
-
},
|
|
1836
|
-
let n = t.color ?? !0, r = t.indent ?? " ", i = (e) => $(n, k.dim, e.padEnd(11)), a = (e) => $(n, (e) => k.bold(k.brand(e)), e), o = (e) => $(n, k.brightRed24, e), s = (e) => $(n,
|
|
1844
|
+
}, Vc = "\x1B[", Hc = `${Vc}38;2;245;158;11m`, Uc = `${Vc}38;2;16;185;129m`, Wc = (e, t) => `${e}${t}${k.reset}`, $ = (e, t, n) => e ? typeof t == "function" ? t(n) : Wc(t, n) : n, Gc = (e, t = {}) => {
|
|
1845
|
+
let n = t.color ?? !0, r = t.indent ?? " ", i = (e) => $(n, k.dim, e.padEnd(11)), a = (e) => $(n, (e) => k.bold(k.brand(e)), e), o = (e) => $(n, k.brightRed24, e), s = (e) => $(n, Uc, e), c = (e) => $(n, Hc, e), l = (e) => $(n, k.dim, e), u = `${c("index audit")} ${l("·")} ${$(n, k.bold, e.kind)}`, d = e.redundant.fields.length, f = Q(e.coveredBy.fields.slice(d)), p = (e, t) => {
|
|
1837
1846
|
let n = e.slice(0, t), r = e.slice(t), i = [];
|
|
1838
1847
|
return n.length > 0 && i.push(s(`[${n.join(", ")}]`)), r.length > 0 && i.push(c(`+ [${r.join(", ")}]`)), i.join(" ");
|
|
1839
1848
|
}, m = [];
|
|
1840
1849
|
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, k.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
|
-
},
|
|
1850
|
+
}, Kc = (e, { apply: t, undo: n }) => ({
|
|
1842
1851
|
name: e,
|
|
1843
1852
|
apply: t,
|
|
1844
1853
|
undo: n
|
|
1845
|
-
}),
|
|
1854
|
+
}), qc = (e) => {
|
|
1846
1855
|
if (!/^\d{14}_/.test(e.id)) throw Error(`migration "${e.id}": id must start with a 14-digit timestamp followed by "_" (convention: <YYYYMMDDHHMMSS>_<slug>)`);
|
|
1847
|
-
let t = e.steps({ step:
|
|
1856
|
+
let t = e.steps({ step: Kc });
|
|
1848
1857
|
if (t.length === 0) throw Error(`migration "${e.id}": at least one step is required`);
|
|
1849
1858
|
return {
|
|
1850
1859
|
__migration: !0,
|
|
@@ -1852,42 +1861,42 @@ $voltro_branch$`;
|
|
|
1852
1861
|
name: e.name,
|
|
1853
1862
|
steps: t
|
|
1854
1863
|
};
|
|
1855
|
-
},
|
|
1864
|
+
}, Jc = (e) => typeof e == "object" && !!e && "__migration" in e && e.__migration === !0, Yc = sr.tableName, Xc = (e) => Or("sha256").update(`${e.type}\u0000${e.id}`, "utf8").digest("hex"), Zc = async (e, t) => {
|
|
1856
1865
|
let [n] = await e.query({
|
|
1857
|
-
table:
|
|
1858
|
-
predicate:
|
|
1866
|
+
table: Yc,
|
|
1867
|
+
predicate: Cn("id", Xc(t)),
|
|
1859
1868
|
order: [],
|
|
1860
1869
|
take: 1,
|
|
1861
1870
|
skip: void 0,
|
|
1862
1871
|
projection: void 0
|
|
1863
1872
|
}), r = n?.tenantId;
|
|
1864
1873
|
return typeof r == "string" ? r : null;
|
|
1865
|
-
},
|
|
1866
|
-
await e.upsert(
|
|
1867
|
-
id:
|
|
1874
|
+
}, Qc = async (e, t, n) => {
|
|
1875
|
+
await e.upsert(Yc, {
|
|
1876
|
+
id: Xc(t),
|
|
1868
1877
|
subjectType: t.type,
|
|
1869
1878
|
subjectId: t.id,
|
|
1870
1879
|
tenantId: n,
|
|
1871
1880
|
selectedAt: /* @__PURE__ */ new Date()
|
|
1872
1881
|
}, { conflictColumns: ["id"] });
|
|
1873
|
-
},
|
|
1874
|
-
await e.delete(
|
|
1875
|
-
},
|
|
1876
|
-
let n =
|
|
1882
|
+
}, $c = async (e, t) => {
|
|
1883
|
+
await e.delete(Yc, Xc(t));
|
|
1884
|
+
}, el = "id", tl = (e, t) => {
|
|
1885
|
+
let n = cr(e);
|
|
1877
1886
|
if (n === void 0) return t;
|
|
1878
|
-
let r = n.fields[
|
|
1879
|
-
if (r === void 0 || t[
|
|
1887
|
+
let r = n.fields[el]?.idScheme;
|
|
1888
|
+
if (r === void 0 || t[el] != null) return t;
|
|
1880
1889
|
if (r.kind === "numeric") {
|
|
1881
|
-
if (!(
|
|
1890
|
+
if (!(el in t)) return t;
|
|
1882
1891
|
let e = { ...t };
|
|
1883
|
-
return delete e[
|
|
1892
|
+
return delete e[el], e;
|
|
1884
1893
|
}
|
|
1885
|
-
let i =
|
|
1894
|
+
let i = me(r, e);
|
|
1886
1895
|
return i === null ? t : {
|
|
1887
1896
|
...t,
|
|
1888
|
-
[
|
|
1897
|
+
[el]: i
|
|
1889
1898
|
};
|
|
1890
|
-
},
|
|
1899
|
+
}, nl = (e, t) => t.map((t) => tl(e, t)), rl = {
|
|
1891
1900
|
postgres: { maxBindParameters: 65535 },
|
|
1892
1901
|
mysql: { maxBindParameters: 65535 },
|
|
1893
1902
|
mariadb: { maxBindParameters: 65535 },
|
|
@@ -1897,25 +1906,25 @@ $voltro_branch$`;
|
|
|
1897
1906
|
},
|
|
1898
1907
|
sqlite: { maxBindParameters: 32766 },
|
|
1899
1908
|
turso: { maxBindParameters: 32766 }
|
|
1900
|
-
},
|
|
1909
|
+
}, il = (e) => rl[e], al = (e) => {
|
|
1901
1910
|
let t = /* @__PURE__ */ new Set();
|
|
1902
1911
|
for (let n of e) for (let e of Object.keys(n)) t.add(e);
|
|
1903
1912
|
return t.size;
|
|
1904
|
-
},
|
|
1913
|
+
}, ol = (e, t) => {
|
|
1905
1914
|
if (t === void 0 || e.length === 0) return [e];
|
|
1906
|
-
let n = Math.max(1,
|
|
1915
|
+
let n = Math.max(1, al(e)), r = Math.floor(t.maxBindParameters / n), i = t.maxRowsPerStatement ?? Infinity, a = Math.max(1, Math.min(r, i));
|
|
1907
1916
|
if (e.length <= a) return [e];
|
|
1908
1917
|
let o = [];
|
|
1909
1918
|
for (let t = 0; t < e.length; t += a) o.push(e.slice(t, t + a));
|
|
1910
1919
|
return o;
|
|
1911
|
-
},
|
|
1920
|
+
}, sl = (e, t) => {
|
|
1912
1921
|
let n = [], r = t;
|
|
1913
1922
|
for (let [t, i] of Object.entries(e.fields)) {
|
|
1914
1923
|
let e = i;
|
|
1915
1924
|
e.nullable || e.hasDefault || e.idScheme !== void 0 || e.generatedAs !== void 0 || (r[t] === void 0 || r[t] === null) && n.push(t);
|
|
1916
1925
|
}
|
|
1917
1926
|
return n;
|
|
1918
|
-
},
|
|
1927
|
+
}, cl = (e, t, n) => {
|
|
1919
1928
|
let r = n, i = new Set(e === void 0 ? [] : Object.entries(e.fields).filter(([, e]) => e.generatedAs !== void 0).map(([e]) => e)), a = [];
|
|
1920
1929
|
for (let e of t) i.has(e) || (r[e] === void 0 ? a.push({
|
|
1921
1930
|
column: e,
|
|
@@ -1925,36 +1934,36 @@ $voltro_branch$`;
|
|
|
1925
1934
|
reason: "null"
|
|
1926
1935
|
}));
|
|
1927
1936
|
return a;
|
|
1928
|
-
},
|
|
1937
|
+
}, ll = (e, t, n) => e.insert(t.tableName, n), ul = (e, t, n) => e.insertMany(t.tableName, n), dl = (e, t, n, r) => e.upsert(t.tableName, n, {
|
|
1929
1938
|
conflictColumns: r.conflictColumns,
|
|
1930
1939
|
...r.update === void 0 ? {} : { update: r.update },
|
|
1931
1940
|
...r.updateValues === void 0 ? {} : { updateValues: r.updateValues }
|
|
1932
|
-
}),
|
|
1933
|
-
if (e.upsertWithOutcome === void 0) throw
|
|
1941
|
+
}), fl = async (e, t, n, r) => {
|
|
1942
|
+
if (e.upsertWithOutcome === void 0) throw S("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.");
|
|
1934
1943
|
return e.upsertWithOutcome(t.tableName, n, {
|
|
1935
1944
|
conflictColumns: r.conflictColumns,
|
|
1936
1945
|
...r.update === void 0 ? {} : { update: r.update },
|
|
1937
1946
|
...r.updateValues === void 0 ? {} : { updateValues: r.updateValues }
|
|
1938
1947
|
});
|
|
1939
|
-
},
|
|
1948
|
+
}, pl = async (e, t, n, r) => e.insertIgnoreWithOutcome(t.tableName, n, { conflictColumns: r.conflictColumns }), ml = (e, t, n, r) => e.updateMany(t.tableName, n, { where: r.where }), hl = 512, gl = (e) => {
|
|
1940
1949
|
e.setMaxListeners(512);
|
|
1941
|
-
},
|
|
1950
|
+
}, _l = (e, t, n) => ({
|
|
1942
1951
|
_tag: "PrimaryKeyConflictError",
|
|
1943
1952
|
table: e,
|
|
1944
1953
|
key: t,
|
|
1945
1954
|
cause: n
|
|
1946
|
-
}),
|
|
1955
|
+
}), vl = (e) => typeof e == "object" && !!e && e._tag === "PrimaryKeyConflictError", yl = {
|
|
1947
1956
|
postgres: 5432,
|
|
1948
1957
|
mysql: 3306,
|
|
1949
1958
|
mariadb: 3306,
|
|
1950
1959
|
mssql: 1433
|
|
1951
|
-
},
|
|
1960
|
+
}, bl = /* @__PURE__ */ new Set([
|
|
1952
1961
|
"localhost",
|
|
1953
1962
|
"127.0.0.1",
|
|
1954
1963
|
"::1",
|
|
1955
1964
|
"[::1]",
|
|
1956
1965
|
"0.0.0.0"
|
|
1957
|
-
]),
|
|
1966
|
+
]), xl = (e) => {
|
|
1958
1967
|
let t = e.host, n = e.port, r = e.database;
|
|
1959
1968
|
if (e.url !== void 0 && e.url !== "") try {
|
|
1960
1969
|
let i = new URL(e.url);
|
|
@@ -1963,29 +1972,29 @@ $voltro_branch$`;
|
|
|
1963
1972
|
return;
|
|
1964
1973
|
}
|
|
1965
1974
|
if (t === void 0 || t === "" || r === void 0 || r === "") return;
|
|
1966
|
-
let i = n ??
|
|
1975
|
+
let i = n ?? yl[(e.dialect ?? "").toLowerCase()];
|
|
1967
1976
|
if (i === void 0 || !Number.isFinite(i)) return;
|
|
1968
1977
|
let a = t.toLowerCase();
|
|
1969
1978
|
return {
|
|
1970
|
-
host:
|
|
1979
|
+
host: bl.has(a) ? "localhost" : a,
|
|
1971
1980
|
port: i,
|
|
1972
1981
|
database: r.toLowerCase()
|
|
1973
1982
|
};
|
|
1974
|
-
},
|
|
1975
|
-
let t =
|
|
1976
|
-
if (t !== void 0) return
|
|
1977
|
-
},
|
|
1983
|
+
}, Sl = (e) => {
|
|
1984
|
+
let t = xl(e);
|
|
1985
|
+
if (t !== void 0) return Or("sha256").update(`${t.host}\u0000${t.port}\u0000${t.database}`).digest("hex").slice(0, 32);
|
|
1986
|
+
}, Cl = (e, t) => e === void 0 || t === void 0 ? "unknown" : e === t ? "same" : "different", wl = {
|
|
1978
1987
|
app: 3,
|
|
1979
1988
|
plugin: 2,
|
|
1980
1989
|
framework: 1
|
|
1981
|
-
},
|
|
1990
|
+
}, Tl = /* @__PURE__ */ new Map(), El = [], Dl = () => [...El], Ol = (e) => {
|
|
1982
1991
|
if (!e.table || !e.timeColumn) throw Error("registerRetention: table + timeColumn are required");
|
|
1983
1992
|
if (!Number.isFinite(e.ttlMs) || e.ttlMs <= 0) throw Error(`registerRetention(${e.table}): ttlMs must be a positive number`);
|
|
1984
|
-
let t = e.source ?? "app", n =
|
|
1993
|
+
let t = e.source ?? "app", n = Tl.get(e.table);
|
|
1985
1994
|
if (n !== void 0) {
|
|
1986
|
-
let r = n.source ?? "app", i = n.ttlMs !== e.ttlMs || n.
|
|
1987
|
-
if (
|
|
1988
|
-
i &&
|
|
1995
|
+
let r = n.source ?? "app", i = n.ttlMs !== e.ttlMs || n.timeColumn !== e.timeColumn || JSON.stringify(n.activityColumns ?? []) !== JSON.stringify(e.activityColumns ?? []) || JSON.stringify(n.where) !== JSON.stringify(e.where);
|
|
1996
|
+
if (wl[t] < wl[r]) {
|
|
1997
|
+
i && El.push({
|
|
1989
1998
|
table: e.table,
|
|
1990
1999
|
kept: {
|
|
1991
2000
|
source: r,
|
|
@@ -1998,7 +2007,7 @@ $voltro_branch$`;
|
|
|
1998
2007
|
});
|
|
1999
2008
|
return;
|
|
2000
2009
|
}
|
|
2001
|
-
i && r !== t &&
|
|
2010
|
+
i && r !== t && El.push({
|
|
2002
2011
|
table: e.table,
|
|
2003
2012
|
kept: {
|
|
2004
2013
|
source: t,
|
|
@@ -2010,59 +2019,59 @@ $voltro_branch$`;
|
|
|
2010
2019
|
}
|
|
2011
2020
|
});
|
|
2012
2021
|
}
|
|
2013
|
-
|
|
2022
|
+
Tl.set(e.table, {
|
|
2014
2023
|
...e,
|
|
2015
2024
|
source: t
|
|
2016
2025
|
});
|
|
2017
|
-
},
|
|
2018
|
-
|
|
2019
|
-
},
|
|
2020
|
-
let i = new Date(t - e.ttlMs), a = 0;
|
|
2026
|
+
}, kl = () => [...Tl.values()], Al = () => {
|
|
2027
|
+
Tl.clear(), El.length = 0;
|
|
2028
|
+
}, jl = async (e, t, n, r = 2e4) => {
|
|
2029
|
+
let i = new Date(t - e.ttlMs), a = (e.activityColumns ?? []).map((e) => ur(Yn(e), Gt(e, i))), o = a.length === 0 ? e.where : dt(...e.where === void 0 ? [] : [e.where], ...a), s = 0;
|
|
2021
2030
|
try {
|
|
2022
2031
|
for (;;) {
|
|
2023
|
-
let t = await n(e.table, e.timeColumn, i, r,
|
|
2024
|
-
if (
|
|
2032
|
+
let t = await n(e.table, e.timeColumn, i, r, o);
|
|
2033
|
+
if (s += t, t < r) break;
|
|
2025
2034
|
}
|
|
2026
2035
|
} catch (t) {
|
|
2027
|
-
throw T.runSync(E.increment(E.tagged(
|
|
2036
|
+
throw T.runSync(E.increment(E.tagged(Nl, "table", e.table))), t;
|
|
2028
2037
|
}
|
|
2029
|
-
return
|
|
2030
|
-
},
|
|
2038
|
+
return s > 0 && T.runSync(E.incrementBy(E.tagged(Ml, "table", e.table), s)), s;
|
|
2039
|
+
}, Ml = E.counter("voltro_retention_swept_rows_total"), Nl = E.counter("voltro_retention_sweep_errors_total"), Pl = (e, t) => {
|
|
2031
2040
|
let n = Number(e ?? String(t));
|
|
2032
2041
|
return (Number.isFinite(n) && n > 0 ? n : t) * 36e5;
|
|
2033
|
-
},
|
|
2034
|
-
id:
|
|
2042
|
+
}, Fl = "_voltro_cdc_offsets", Il = i(Fl, {
|
|
2043
|
+
id: y({ prefix: "cdcoff" }),
|
|
2035
2044
|
replicaId: b(),
|
|
2036
2045
|
streamName: b(),
|
|
2037
2046
|
binlogFile: b(),
|
|
2038
2047
|
binlogPosition: b(),
|
|
2039
|
-
updatedAt:
|
|
2040
|
-
}).index(["replicaId"]),
|
|
2041
|
-
id:
|
|
2048
|
+
updatedAt: w()
|
|
2049
|
+
}).index(["replicaId"]), Ll = i(Fl, {
|
|
2050
|
+
id: y({ prefix: "cdcoff" }),
|
|
2042
2051
|
replicaId: b(),
|
|
2043
2052
|
streamName: b(),
|
|
2044
2053
|
ctVersion: b(),
|
|
2045
|
-
updatedAt:
|
|
2046
|
-
}).index(["replicaId"]),
|
|
2047
|
-
id:
|
|
2048
|
-
startedAt:
|
|
2049
|
-
finishedAt:
|
|
2054
|
+
updatedAt: w()
|
|
2055
|
+
}).index(["replicaId"]), Rl = "_voltro_data_transfers", zl = i(Rl, {
|
|
2056
|
+
id: y({ prefix: "dimp" }),
|
|
2057
|
+
startedAt: w().default("now"),
|
|
2058
|
+
finishedAt: w().nullable(),
|
|
2050
2059
|
direction: b().default("import"),
|
|
2051
2060
|
mode: b(),
|
|
2052
2061
|
via: b(),
|
|
2053
2062
|
bundle: b().nullable(),
|
|
2054
2063
|
sourceFingerprint: b().nullable(),
|
|
2055
|
-
tablesWritten:
|
|
2056
|
-
rowsWritten:
|
|
2064
|
+
tablesWritten: _().default(0),
|
|
2065
|
+
rowsWritten: _().default(0),
|
|
2057
2066
|
failure: b().nullable(),
|
|
2058
|
-
staged:
|
|
2059
|
-
}).renamedFrom("_voltro_data_imports").nonReactive(),
|
|
2067
|
+
staged: vn().nullable()
|
|
2068
|
+
}).renamedFrom("_voltro_data_imports").nonReactive(), Bl = (e) => {
|
|
2060
2069
|
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)";
|
|
2061
2070
|
return `${t} · ${r} · via ${e.via}${i}` + (e.bundle === null ? "" : ` · from ${e.bundle}`) + (e.sourceFingerprint === null ? "" : ` · source schema ${e.sourceFingerprint}`);
|
|
2062
|
-
},
|
|
2071
|
+
}, Vl = 255, Hl = (e) => e == null ? "null" : typeof e == "string" || typeof e == "number" || typeof e == "boolean" ? JSON.stringify(e) : Array.isArray(e) ? `[${e.map(Hl).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)}:${Hl(t)}`).join(",")}}` : JSON.stringify(String(e)), Ul = (e) => {
|
|
2063
2072
|
if (e == null) return null;
|
|
2064
|
-
let t = typeof e == "string" ? e :
|
|
2073
|
+
let t = typeof e == "string" ? e : Hl(e);
|
|
2065
2074
|
return t.length > 255 ? t.slice(0, 255) : t;
|
|
2066
|
-
},
|
|
2075
|
+
}, Wl = "postgres";
|
|
2067
2076
|
//#endregion
|
|
2068
|
-
export {
|
|
2077
|
+
export { Fe as AUTO_FILLED_COLUMNS, zr as BOUND_ENCRYPTED_PREFIX, rl as BULK_INSERT_LIMITS, Y as BranchNameInvalid, sc as BranchTransitionInvalid, Fl as CDC_OFFSETS_TABLE, yo as CHANGE_CLAIM_TTL_ENV, hl as CHANGE_LISTENER_CEILING, Jn as ColumnBuilder, Rl as DATA_TRANSFERS_TABLE, tr as DEFAULT_ACQUIRE_TIMEOUT_MS, bo as DEFAULT_CHANGE_CLAIM_TTL_HOURS, ys as DEFAULT_EAGER_FALLBACK_WARN_INTERVAL_MS, rr as DEFAULT_SOFT_DROP_RETENTION_DAYS, Oi as DEFAULT_SUBJECT_GRAPH_DEPTH, Rr as ENCRYPTED_PREFIX, Wl as ENGINE, qi as EagerCardinalityError, an as FILE_MIGRATION_PATTERN, Je as FRAMEWORK_LIVE_TABLES, Hr as FieldDecryptionError, Vo as ID_COLUMN_MAX_LENGTH, vr as INITIAL_VERSION, Ee as IrreversibleMigrationError, mt as MATCHES_NO_ROWS, c as MAX_IDENTIFIER_LENGTH, Ae as MIGRATION_PHASES, Is as MSSQL_TRANSIENT_NUMBERS, Ps as MYSQL_TRANSIENT_CODES, Re as MigrationExpectationFailed, re as MigrationNeedsSqlClient, pe as MigrationSkipped, vo as OccurrenceCounter, Fs as POSTGRES_TRANSIENT_STATES, Hn as REPLACE_IN_PROGRESS_TABLE, Se as RewriteUnstableError, Vl as SCOPE_KEY_MAX_LENGTH, Lt as SELF_REFERENCE_TARGET, Ls as SQLITE_TRANSIENT_CODES, bn as STAGING_STALE_MINUTES, d as STAGING_TABLE_PREFIX, jr as SqlClient, Yc as TENANT_SELECTIONS_TABLE, Rs as TURSO_TRANSIENT_MESSAGE, Ys as TableStreamError, cn as TenantNamespaceInvalid, ke as TenantNamespaceUnresolved, Ec as TenantRegionUnavailable, Tc as TenantResidencyUnresolved, Os as TransactionAbortedError, Ge as TransactionBrokenByBodyError, Us as VOLTRO_EXPIRES_MIXIN_ID, Gs as VOLTRO_LOCAL_FIRST_MIXIN_ID, hr as VersionConflict, ot as WARN_IDENTIFIER_LENGTH, fn as _voltroApiKeysTable, Il as _voltroCdcOffsetsTable, zl as _voltroDataTransfersTable, Kn as _voltroDevicesTable, Ft as _voltroIdempotencyTable, Ht as _voltroKvTable, On as _voltroMigrationPlansTable, gn as _voltroMigrationsTable, Ll as _voltroMssqlCdcOffsetsTable, Xt as _voltroPluginMigrationsTable, Pn as _voltroReplaceInProgressTable, Kt as _voltroReplicaObservationsTable, bt as _voltroSchemaOwnerTable, Xn as _voltroSeedsTable, sr as _voltroTenantSelectionsTable, so as actorsTable, bc as admitBranch, er as agedSoftDropSnapshots, nn as allEnumRenames, Ti as allRegisteredRelations, qt as allRegisteredTables, dt as and, Gi as applyJsonPatch, Wt as array, _t as arrayContains, He as arrayHas, e as arrayOverlaps, Yi as attachEagerLoads, wo as attributionFields, Oo as attributionKey, Bc as auditAllTableIndexes, zc as auditTableIndexes, S as authoredError, _e as authoredMessageOf, xe as avg, Nn as avgOver, Io as beginLocalWrite, An as bigint, Pc as bindResidentStore, vn as boolean, ic as branchNamespaceName, il as bulkInsertLimitsFor, Qt as bytes, ht as causeBranches, fo as changeDelete, ho as changeDigest, lo as changeInsert, po as changeSoftDelete, uo as changeUpdate, ol as chunkRowsForInsert, jo as claimPendingAttribution, ft as classifyConstraintViolation, Tt as clearEnumRenames, zo as clearPendingAttribution, Di as clearRelationsRegistry, Ac as clearResidencyConfig, Al as clearRetentions, xt as clearTableRegistry, Jo as clearWriteRecorders, H as coercePredicateForSqlite, dn as coercePredicateValue, o as coercePredicateValues, Te as coerceValueForSqlite, Vt as collectSubqueries, ve as column, ri as columnSchema, al as columnsPerRow, m as compareDecimal, aa as compileEagerJson, Ki as compileJsonPatch, C as compilePredicate, tt as compileRawFragment, ne as compileRowProjection, v as compileSelect, go as composeChangeKey, ec as computeEmbedding, Sl as connectionIdentity, Gn as contains, gt as count, pt as countDistinct, Jt as crdtDoc, St as crdtManagedColumns, Qn as crdtManagedColumnsOf, lr as crdtText, Co as currentWriteAttribution, yt as databaseHandle, kt as date, ar as dbEnum, ps as dbMetricTagCacheSizeForTests, gs as dbOperationsInFlight, Xe as decimal, En as declareEnumRename, qr as decodeFieldValue, pr as decodeRowsForTable, u as decodeRowsFromSchema, $r as decryptFieldsOnRead, qc as defineMigration, De as defineMixin, nt as defineSeed, $c as deleteTenantSelection, We as denseRank, Fi as deriveSubjectGraph, ie as deriveTypeIdPrefix, Wo as derivedRowId, Go as derivedRowIdLength, Qe as describeAgedSoftDropSnapshots, vt as describeCharsetRefusal, Ue as describeDriverError, t as describeRowBindings, Bl as describeTransferRun, Lr as deserializeArraysOnRead, de as drainIdentifierWarnings, p as dropped, Gr as encodeFieldValue, st as encodeRowForSchema, Qr as encryptFieldsForWrite, Xr as encryptedColumnsOf, Lo as endLocalWrite, _c as enforceBranchLimits, Zn as ensureTableRegistered, Cn as eq, Le as escapeLike, Ln as evaluatePredicate, n as except, rn as exists, Ws as expires, co as externalChangeEvent, Bt as extractDbCause, Br as fieldBinding, ct as fireSchemaChangeSeeds, se as fireTenantCreateSeeds, Gc as formatIndexAuditIssue, Ii as formatSubjectGraph, Dt as frameworkTables, me as generateId, Ke as generateSnowflake, nr as geography, et as geometry, Bn as getEnumRenames, wi as getRelation, Ci as getRelations, kc as getResidencyConfig, cr as getTable, Et as gt, Dn as gte, ia as hasEagerLoads, $s as hybridSearch, y as id, Vn as inSet, Pt as inSubquery, A as inferForeignKey, pl as insertIgnoreRowOutcome, ul as insertManyRows, ll as insertRow, _ as integer, en as interruptedReplaceRefusal, zt as intersect, Ie as interval, dr as irreversible, s as irreversibleReason, Vr as isBoundCiphertext, ac as isBranchNamespace, Vi as isCompositeRowKey, di as isEmptyRelationsSpec, Wr as isEncrypted, Ur as isFieldDecryptionError, at as isFileMigration, Wn as isForeignKeyViolation, ee as isFrameworkOwnedLiveTable, qs as isLocalFirst, Jc as isMigrationDefinition, $e as isMysqlFamily, dc as isNeonConnection, hn as isNotNull, Yn as isNull, vl as isPrimaryKeyConflictError, Sn as isQueryTimeout, Jr as isRawEncoding, Mc as isRegionServable, fi as isRelationsSpec, ye as isSeedDefinition, h as isSoftDropSnapshotName, te as isSqliteFamily, Pe as isStagingTableName, Ot as isTableReactive, js as isTransactionAbortedError, Vs as isTransientContention, fe as isView, un as json, Rt as jsonField, ln as jsonIndex, Hi as jsonPatchAssignments, Un as lag, xn as lead, Dl as listRetentionConflicts, kl as listRetentions, Ks as localFirst, Js as localFirstTables, Gt as lt, jn as lte, Ss as makeEagerFallbackReporter, wc as makeNamespaceBranchExecutor, ks as makeTransactionAbortTracker, mi as many, hi as manyToMany, a as materializeFields, Fn as max, ue as migration, tn as min, cl as missingConflictColumns, sl as missingRequiredColumns, je as mixin, yn as neq, cc as nextBranchState, xl as normaliseTarget, Wi as normalizeJsonPatchValue, $t as not, Yt as notExists, Ct as notInSet, $n as notInSubquery, sn as numeric, vs as observeDbOp, xo as occurrenceWindowMs, pi as one, Ji as oneCardinalityMessage, ur as or, x as orderClausesOf, Tn as paginateBy, zn as paginateById, _o as parseChangeKey, Bo as pendingAttributionCount, hc as planBranch, lc as planBranchProvision, uc as planBranchTeardown, gc as planBranchTeardownFor, pc as planNeonBranchProvision, mc as planNeonBranchTeardown, mr as planVersionedUpdate, Nt as pluginRef, mn as pluginRefSpecOf, _l as primaryKeyConflictError, vc as provisionBranch, Fc as provisionResidentTenant, Ne as qualifyTable, Mt as queryFor, it as queryForView, g as quoteIdent, gl as raiseChangeListenerCeiling, pn as rank, Oe as raw, Zc as readTenantSelection, Me as readableByColumns, Be as real, _s as recordDbOp, $o as recordsTable, ae as reference, ti as refuseWrite, ro as registerCoreTables, Si as registerDiscoveredRelations, Ao as registerPendingAttribution, xi as registerRelations, Ol as registerRetention, ir as registerTable, Ko as registerWriteRecorder, ui as relations, ao as requireActors, Ye as requireTable, oo as requireTenants, fs as resetDbMetricTagCacheForTests, fr as resetSnowflake, Nc as residentPlacement, Nr as resolveActorSnapshot, fc as resolveBranchMechanism, xs as resolveEagerFallbackWarnIntervalMs, Ro as resolveEchoAttribution, qn as resolveFullTextIndex, Ce as resolveIdScheme, ze as resolveMixinGraph, jc as resolveTenantHome, Ve as resolveTenantNamespace, Pl as retentionTtlMsFromEnv, zi as rowKeyColumns, Bi as rowKeyIdentity, It as rowNumber, ii as rowSchema, Ds as runRetryingTransaction, As as runSavepoint, Ns as runStoreTransaction, So as runWithWriteAttribution, es as runWriteRecorders, Cl as sameDatabase, oe as sanitizeIdentifierFragment, Ul as scopeKeyOf, he as selfReference, Ir as serializeArraysForWrite, we as serverOnlyColumns, Oc as setResidencyConfig, Mn as setSchemaChangeSeedHook, ge as setTenantCreateSeedHook, Cs as settleTransactionExit, _r as settleVersionedUpdate, r as softDropSnapshotStamp, At as spatialPredicate, wt as stagingLeftoverReport, wn as stagingLeftovers, Rn as stagingNamesOf, jt as stagingStaleAfterMs, tl as stampGeneratedId, nl as stampGeneratedIds, or as startsWith, ni as storeRefusalOf, Qs as streamTable, Ut as sum, kn as sumOver, Xo as suspendWriteRecorders, Zo as suspendWriteRecordersEffect, jl as sweepRetention, i as table, yc as teardownBranch, Xc as tenantSelectionId, b as text, w as timestamp, br as timestampMs, gr as timestampMsOrNull, Es as transactionRetrySchedule, _n as union, Zt as unionAll, f as unregisterTable, qo as unregisterWriteRecorder, ml as updateManyRow, dl as upsertRow, fl as upsertRowOutcome, Ri as upsertUpdatePatch, Li as upsertUpdateValues, rt as validateColumnName, lt as validateIndexName, Ei as validateRegisteredRelations, vi as validateRelationConfig, ce as validateTableName, be as validateTypeIdPrefix, l as vector, on as vectorDistanceToOpclass, tc as vectorEmbedding, yr as versionColumnOf, ut as view, le as viewSql, Ze as walkLeaves, In as wireSafeCause, To as withCapturedAttribution, Qo as writeRecordersSuspended, Qc as writeTenantSelection };
|