@voltro/database 0.45.0 → 0.46.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 +176 -0
- package/dist/{frameworkLiveTables-XPFqj8n3.js → frameworkLiveTables-DNu6F6P8.js} +35 -35
- package/dist/index.d.ts +52 -1
- package/dist/index.js +396 -378
- package/dist/sql.js +256 -256
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { $ as e, A as t, At as n, B as r, Bt as i, C as a, Ct as o, D as s, Dt as c, E as l, Et as u, F as d, Ft as f, G as p, Gt as m, H as h, Ht as g, I as ee, It as te, J as _, Jt as
|
|
2
|
-
import { timestampMs as
|
|
3
|
-
import { Cause as
|
|
4
|
-
import { AsyncLocalStorage as
|
|
5
|
-
import { createHash as
|
|
6
|
-
import { TransactionConnection as
|
|
7
|
-
import { ansi as
|
|
8
|
-
import { SqlClient as
|
|
1
|
+
import { $ as e, A as t, At as n, B as r, Bt as i, C as a, Ct as o, D as s, Dt as c, E as l, Et as u, F as d, Ft as f, G as p, Gt as m, H as h, Ht as g, I as ee, It as te, J as _, Jt as ne, K as re, Kt as v, L as ie, Lt as y, M as ae, Mt as oe, N as se, Nt as ce, O as le, Ot as ue, P as de, Pt as fe, Q as pe, R as me, Rt as b, S as he, St as ge, T as _e, Tt as ve, U as ye, Ut as be, V as xe, Vt as x, W as Se, Wt as Ce, X as we, Xt as S, Y as Te, Yt as C, Z as Ee, Zt as De, _ as Oe, _t as ke, a as Ae, at as je, b as Me, bt as Ne, c as Pe, ct as Fe, d as Ie, dt as Le, et as Re, f as ze, ft as Be, g as Ve, gt as He, h as Ue, ht as We, i as Ge, it as Ke, j as w, jt as qe, k as Je, kt as Ye, l as Xe, lt as Ze, m as Qe, mt as $e, n as et, nt as T, o as tt, ot as nt, p as E, pt as rt, q as it, qt as at, rt as ot, s as st, st as ct, t as lt, tt as ut, u as dt, ut as ft, v as pt, vt as mt, w as ht, wt as gt, x as _t, xt as vt, y as yt, yt as bt, z as xt, zt as D } from "./frameworkLiveTables-DNu6F6P8.js";
|
|
2
|
+
import { timestampMs as St, timestampMsOrNull as Ct } from "./wire.js";
|
|
3
|
+
import { Cause as O, Chunk as wt, Data as Tt, Effect as k, Exit as Et, Metric as A, MetricBoundaries as Dt, Option as j, Runtime as Ot, Schedule as kt, Schema as M, Stream as At } from "effect";
|
|
4
|
+
import { AsyncLocalStorage as jt } from "node:async_hooks";
|
|
5
|
+
import { createHash as Mt } from "node:crypto";
|
|
6
|
+
import { TransactionConnection as Nt } from "@effect/sql/SqlClient";
|
|
7
|
+
import { ansi as N } from "@voltro/logger";
|
|
8
|
+
import { SqlClient as Pt } from "@effect/sql";
|
|
9
9
|
//#region src/actorSnapshot.ts
|
|
10
|
-
var
|
|
10
|
+
var Ft = (e) => typeof e == "string" && e !== "" ? e : null, It = 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 Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = 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: Ft(r.kind) ?? n,
|
|
27
|
+
displayName: Ft(r.displayName),
|
|
28
|
+
email: Ft(r.email)
|
|
29
29
|
};
|
|
30
30
|
} catch {
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
|
-
},
|
|
33
|
+
}, Lt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqlite", Rt = (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
|
+
}, zt = (e, t, n) => {
|
|
38
|
+
if (!Lt(n) || !t) return e;
|
|
39
|
+
let r = Rt(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 Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = 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
|
+
}, Bt = (e, t, n) => {
|
|
48
|
+
if (!Lt(n) || !t) return e;
|
|
49
|
+
let r = Rt(t);
|
|
50
50
|
return r.length === 0 ? e : e.map((e) => {
|
|
51
51
|
let t;
|
|
52
52
|
for (let n of r) {
|
|
@@ -58,7 +58,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
58
58
|
}
|
|
59
59
|
return t ?? e;
|
|
60
60
|
});
|
|
61
|
-
},
|
|
61
|
+
}, Vt = "enc:v1:", Ht = class extends Error {
|
|
62
62
|
_tag = "FieldDecryptionError";
|
|
63
63
|
table;
|
|
64
64
|
column;
|
|
@@ -66,7 +66,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
66
66
|
constructor(e) {
|
|
67
67
|
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;
|
|
68
68
|
}
|
|
69
|
-
},
|
|
69
|
+
}, Ut = (e) => typeof e == "object" && !!e && e._tag === "FieldDecryptionError", Wt = (e) => typeof e == "string" && e.startsWith("enc:v1:"), Gt = (e, t) => e.encrypt(JSON.stringify(t)), Kt = /* @__PURE__ */ new Set([
|
|
70
70
|
"text",
|
|
71
71
|
"id",
|
|
72
72
|
"reference",
|
|
@@ -74,51 +74,51 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
74
74
|
"uuid",
|
|
75
75
|
"email",
|
|
76
76
|
"url"
|
|
77
|
-
]),
|
|
77
|
+
]), qt = (e, t, n) => {
|
|
78
78
|
let r = e.decrypt(t), i;
|
|
79
79
|
try {
|
|
80
80
|
i = JSON.parse(r);
|
|
81
81
|
} catch {
|
|
82
82
|
return r;
|
|
83
83
|
}
|
|
84
|
-
return typeof i == "string" ? i : n === void 0 ||
|
|
85
|
-
},
|
|
84
|
+
return typeof i == "string" ? i : n === void 0 || Kt.has(n) ? r : i;
|
|
85
|
+
}, Jt = (e, t, n) => {
|
|
86
86
|
let r = e.decrypt(t);
|
|
87
87
|
try {
|
|
88
|
-
return typeof JSON.parse(r) == "string" ? !1 : n === void 0 ||
|
|
88
|
+
return typeof JSON.parse(r) == "string" ? !1 : n === void 0 || Kt.has(n) ? !0 : void 0;
|
|
89
89
|
} catch {
|
|
90
90
|
return !0;
|
|
91
91
|
}
|
|
92
|
-
},
|
|
92
|
+
}, Yt = (e, t) => e.fields[t]?.type, Xt = (e) => {
|
|
93
93
|
let t = [];
|
|
94
94
|
for (let [n, r] of Object.entries(e.fields)) r.encrypted === !0 && t.push(n);
|
|
95
95
|
return t;
|
|
96
|
-
},
|
|
96
|
+
}, Zt = (e, t, n) => {
|
|
97
97
|
if (!t) return e;
|
|
98
|
-
let r =
|
|
98
|
+
let r = Xt(t);
|
|
99
99
|
if (r.length === 0) return e;
|
|
100
100
|
let i = { ...e };
|
|
101
101
|
for (let e of r) {
|
|
102
102
|
let r = i[e];
|
|
103
|
-
if (!(r == null ||
|
|
103
|
+
if (!(r == null || Wt(r))) {
|
|
104
104
|
if (!n) throw Error(`column "${t.tableName ?? "?"}.${e}" is .encrypted() but no field cipher is registered — wire @voltro/plugin-governance's fieldEncryption (key via the Secrets-Resolver)`);
|
|
105
|
-
i[e] =
|
|
105
|
+
i[e] = Gt(n, r);
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
return i;
|
|
109
|
-
},
|
|
109
|
+
}, Qt = (e, t, n, r) => {
|
|
110
110
|
if (!t) return e;
|
|
111
|
-
let i =
|
|
111
|
+
let i = Xt(t);
|
|
112
112
|
if (i.length === 0 || !n) return e;
|
|
113
113
|
let a = r?.onError ?? "throw", o = t.tableName ?? "?";
|
|
114
114
|
return e.map((e) => {
|
|
115
115
|
let s;
|
|
116
116
|
for (let c of i) {
|
|
117
117
|
let i = e[c];
|
|
118
|
-
if (
|
|
118
|
+
if (Wt(i)) {
|
|
119
119
|
s ??= { ...e };
|
|
120
120
|
try {
|
|
121
|
-
s[c] =
|
|
121
|
+
s[c] = qt(n, i, Yt(t, c));
|
|
122
122
|
} catch (e) {
|
|
123
123
|
let t = String(e?.message ?? e);
|
|
124
124
|
if (a === "null") {
|
|
@@ -129,7 +129,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
129
129
|
});
|
|
130
130
|
continue;
|
|
131
131
|
}
|
|
132
|
-
throw new
|
|
132
|
+
throw new Ht({
|
|
133
133
|
table: o,
|
|
134
134
|
column: c,
|
|
135
135
|
reason: t
|
|
@@ -139,125 +139,125 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
139
139
|
}
|
|
140
140
|
return s ?? e;
|
|
141
141
|
});
|
|
142
|
-
},
|
|
142
|
+
}, $t = (e) => {
|
|
143
143
|
let t = e;
|
|
144
|
-
for (let e = 0; e < 4 &&
|
|
144
|
+
for (let e = 0; e < 4 && Ot.isFiberFailure(t); e++) t = O.squash(t[Ot.FiberFailureCauseId]);
|
|
145
145
|
return t;
|
|
146
|
-
},
|
|
147
|
-
if (t >= 4 || !
|
|
148
|
-
let n = e[
|
|
149
|
-
if (r.length === 0) return [
|
|
146
|
+
}, en = (e, t = 0) => {
|
|
147
|
+
if (t >= 4 || !Ot.isFiberFailure(e)) return [e];
|
|
148
|
+
let n = e[Ot.FiberFailureCauseId], r = [...O.failures(n), ...O.defects(n)];
|
|
149
|
+
if (r.length === 0) return [O.squash(n)];
|
|
150
150
|
let i = [];
|
|
151
|
-
for (let e of r.slice(0, 8)) i.push(...
|
|
151
|
+
for (let e of r.slice(0, 8)) i.push(...en(e, t + 1));
|
|
152
152
|
return i;
|
|
153
|
-
},
|
|
154
|
-
let t = {}, n = [], r =
|
|
153
|
+
}, tn = (e) => e.dbCode !== void 0 || e.dbErrno !== void 0 || e.dbNumber !== void 0 || e.dbSqlState !== void 0 || e.dbConstraint !== void 0, nn = (e) => {
|
|
154
|
+
let t = {}, n = [], r = $t(e);
|
|
155
155
|
for (let e = 0; e < 8 && typeof r == "object" && r; e++) {
|
|
156
156
|
let e = r;
|
|
157
157
|
t.dbCode === void 0 && (typeof e.code == "string" || typeof e.code == "number") && (t.dbCode = e.code), t.dbErrno === void 0 && typeof e.errno == "number" && (t.dbErrno = e.errno), t.dbNumber === void 0 && typeof e.number == "number" && (t.dbNumber = e.number), t.dbSqlState === void 0 && typeof e.sqlState == "string" && (t.dbSqlState = e.sqlState), t.dbBindings === void 0 && typeof e.voltroBindings == "string" && (t.dbBindings = e.voltroBindings), t.dbStatement === void 0 && typeof e.sql == "string" && e.sql.includes("?") && (t.dbStatement = e.sql, t.dbPlaceholders = (e.sql.match(/\?/g) ?? []).length), t.dbFatal === void 0 && typeof e.fatal == "boolean" && (t.dbFatal = e.fatal), t.dbConstraint === void 0 && typeof e.constraint == "string" && (t.dbConstraint = e.constraint), t.dbTable === void 0 && typeof e.table == "string" && (t.dbTable = e.table), t.dbColumn === void 0 && typeof e.column == "string" && (t.dbColumn = e.column), t.dbSchema === void 0 && typeof e.schema == "string" && (t.dbSchema = e.schema);
|
|
158
158
|
let i = e.sqlMessage ?? e.detail;
|
|
159
159
|
t.dbMessage === void 0 && typeof i == "string" && (t.dbMessage = i);
|
|
160
160
|
let a = typeof e.constructor == "function" ? e.constructor.name : void 0, o = typeof e._tag == "string" && e._tag || typeof e.name == "string" && e.name || (typeof a == "string" && a !== "Object" ? a : void 0), s = typeof e.message == "string" ? e.message : void 0;
|
|
161
|
-
(o || s) && n.push(`${o || "Error"}${s ? `: ${s.slice(0, 200)}` : ""}`), r =
|
|
161
|
+
(o || s) && n.push(`${o || "Error"}${s ? `: ${s.slice(0, 200)}` : ""}`), r = $t(e.cause);
|
|
162
162
|
}
|
|
163
163
|
return n.length > 0 && (t.dbCauseChain = n.join(" ← "), t.dbMessage === void 0 && (t.dbMessage = n[n.length - 1])), t;
|
|
164
|
-
},
|
|
165
|
-
let t =
|
|
164
|
+
}, rn = (e) => {
|
|
165
|
+
let t = en(e).map(nn);
|
|
166
166
|
if (t.length <= 1) return t[0] ?? {};
|
|
167
|
-
let n = t.find(
|
|
167
|
+
let n = t.find(tn) ?? t[0], r = t.filter((e) => e !== n).map((e) => e.dbCauseChain).filter((e) => typeof e == "string");
|
|
168
168
|
if (r.length === 0) return n;
|
|
169
169
|
let i = typeof n.dbCauseChain == "string" ? n.dbCauseChain : void 0;
|
|
170
170
|
return {
|
|
171
171
|
...n,
|
|
172
172
|
dbCauseChain: [i, ...r].filter(Boolean).join(" ‖ ")
|
|
173
173
|
};
|
|
174
|
-
},
|
|
174
|
+
}, an = /^[A-Za-z_][A-Za-z0-9_$]*$/, P = (e) => e !== void 0 && e.length <= 128 && an.test(e) ? e : void 0, on = (e) => e === void 0 ? void 0 : e.split(".").pop() ?? e, F = (e, ...t) => {
|
|
175
175
|
for (let n of t) {
|
|
176
176
|
let t = n.exec(e);
|
|
177
177
|
if (t?.[1] !== void 0) return t[1];
|
|
178
178
|
}
|
|
179
|
-
},
|
|
179
|
+
}, sn = (e, t) => {
|
|
180
180
|
let n = e.dbCode, r = e.dbErrno, i = e.dbNumber, a = typeof e.dbMessage == "string" ? e.dbMessage : "", o = `${typeof e.dbCauseChain == "string" ? e.dbCauseChain : ""} ${a}`;
|
|
181
181
|
if (n === "23503") {
|
|
182
|
-
let t =
|
|
182
|
+
let t = P(e.dbConstraint);
|
|
183
183
|
return {
|
|
184
184
|
kind: /is still referenced from table/i.test(o) ? "foreignKeyInUse" : "foreignKey",
|
|
185
185
|
...t === void 0 ? {} : { constraint: t }
|
|
186
186
|
};
|
|
187
187
|
}
|
|
188
188
|
if (n === "23505") {
|
|
189
|
-
let t =
|
|
189
|
+
let t = P(e.dbConstraint);
|
|
190
190
|
return {
|
|
191
191
|
kind: "unique",
|
|
192
192
|
...t === void 0 ? {} : { constraint: t }
|
|
193
193
|
};
|
|
194
194
|
}
|
|
195
195
|
if (n === "23502") {
|
|
196
|
-
let t =
|
|
196
|
+
let t = P(e.dbColumn);
|
|
197
197
|
return {
|
|
198
198
|
kind: "notNull",
|
|
199
199
|
...t === void 0 ? {} : { column: t }
|
|
200
200
|
};
|
|
201
201
|
}
|
|
202
202
|
if (n === "23514") {
|
|
203
|
-
let t =
|
|
203
|
+
let t = P(e.dbConstraint);
|
|
204
204
|
return {
|
|
205
205
|
kind: "check",
|
|
206
206
|
...t === void 0 ? {} : { constraint: t }
|
|
207
207
|
};
|
|
208
208
|
}
|
|
209
209
|
if (r === 1452 || r === 1451) {
|
|
210
|
-
let e =
|
|
210
|
+
let e = P(F(o, /CONSTRAINT `([^`]+)`/));
|
|
211
211
|
return {
|
|
212
212
|
kind: r === 1451 ? "foreignKeyInUse" : "foreignKey",
|
|
213
213
|
...e === void 0 ? {} : { constraint: e }
|
|
214
214
|
};
|
|
215
215
|
}
|
|
216
216
|
if (r === 1062) {
|
|
217
|
-
let e =
|
|
217
|
+
let e = P(on(F(o, /for key '([^']+)'/)));
|
|
218
218
|
return {
|
|
219
219
|
kind: "unique",
|
|
220
220
|
...e === void 0 ? {} : { constraint: e }
|
|
221
221
|
};
|
|
222
222
|
}
|
|
223
223
|
if (r === 1048 || r === 1364) {
|
|
224
|
-
let e =
|
|
224
|
+
let e = P(F(o, /Column '([^']+)' cannot be null/, /Field '([^']+)' doesn't have a default value/));
|
|
225
225
|
return {
|
|
226
226
|
kind: "notNull",
|
|
227
227
|
...e === void 0 ? {} : { column: e }
|
|
228
228
|
};
|
|
229
229
|
}
|
|
230
230
|
if (r === 3819 || r === 4025) {
|
|
231
|
-
let e =
|
|
231
|
+
let e = P(F(o, /Check constraint '([^']+)'/, /CONSTRAINT `([^`]+)` failed/));
|
|
232
232
|
return {
|
|
233
233
|
kind: "check",
|
|
234
234
|
...e === void 0 ? {} : { constraint: e }
|
|
235
235
|
};
|
|
236
236
|
}
|
|
237
237
|
if (i === 547) {
|
|
238
|
-
let e =
|
|
238
|
+
let e = F(o, /(?:FOREIGN KEY|REFERENCE) constraint "([^"]+)"/), t = F(o, /CHECK constraint "([^"]+)"/);
|
|
239
239
|
if (t !== void 0 && e === void 0) {
|
|
240
|
-
let e =
|
|
240
|
+
let e = P(t);
|
|
241
241
|
return {
|
|
242
242
|
kind: "check",
|
|
243
243
|
...e === void 0 ? {} : { constraint: e }
|
|
244
244
|
};
|
|
245
245
|
}
|
|
246
|
-
let n = /REFERENCE constraint/.test(o), r =
|
|
246
|
+
let n = /REFERENCE constraint/.test(o), r = P(e);
|
|
247
247
|
return {
|
|
248
248
|
kind: n ? "foreignKeyInUse" : "foreignKey",
|
|
249
249
|
...r === void 0 ? {} : { constraint: r }
|
|
250
250
|
};
|
|
251
251
|
}
|
|
252
252
|
if (i === 2627 || i === 2601) {
|
|
253
|
-
let e =
|
|
253
|
+
let e = P(F(o, /(?:UNIQUE KEY|PRIMARY KEY) constraint '([^']+)'/, /index '([^']+)'/));
|
|
254
254
|
return {
|
|
255
255
|
kind: "unique",
|
|
256
256
|
...e === void 0 ? {} : { constraint: e }
|
|
257
257
|
};
|
|
258
258
|
}
|
|
259
259
|
if (i === 515) {
|
|
260
|
-
let e =
|
|
260
|
+
let e = P(F(o, /Cannot insert the value NULL into column '([^']+)'/));
|
|
261
261
|
return {
|
|
262
262
|
kind: "notNull",
|
|
263
263
|
...e === void 0 ? {} : { column: e }
|
|
@@ -265,34 +265,34 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
265
265
|
}
|
|
266
266
|
if (n === "SQLITE_CONSTRAINT_FOREIGNKEY") return { kind: t === "delete" || t === "deleteMany" || t === "hardDelete" ? "foreignKeyInUse" : "foreignKey" };
|
|
267
267
|
if (n === "SQLITE_CONSTRAINT_UNIQUE" || n === "SQLITE_CONSTRAINT_PRIMARYKEY") {
|
|
268
|
-
let e =
|
|
268
|
+
let e = P(on(F(o, /UNIQUE constraint failed: ([^,\s]+)/)));
|
|
269
269
|
return {
|
|
270
270
|
kind: "unique",
|
|
271
271
|
...e === void 0 ? {} : { column: e }
|
|
272
272
|
};
|
|
273
273
|
}
|
|
274
274
|
if (n === "SQLITE_CONSTRAINT_NOTNULL") {
|
|
275
|
-
let e =
|
|
275
|
+
let e = P(on(F(o, /NOT NULL constraint failed: ([^,\s]+)/)));
|
|
276
276
|
return {
|
|
277
277
|
kind: "notNull",
|
|
278
278
|
...e === void 0 ? {} : { column: e }
|
|
279
279
|
};
|
|
280
280
|
}
|
|
281
281
|
if (n === "SQLITE_CONSTRAINT_CHECK") {
|
|
282
|
-
let e =
|
|
282
|
+
let e = P(F(a, /CHECK constraint failed: (.+)$/));
|
|
283
283
|
return {
|
|
284
284
|
kind: "check",
|
|
285
285
|
...e === void 0 ? {} : { constraint: e }
|
|
286
286
|
};
|
|
287
287
|
}
|
|
288
|
-
},
|
|
289
|
-
let t =
|
|
288
|
+
}, cn = (e) => {
|
|
289
|
+
let t = sn(e)?.kind;
|
|
290
290
|
return t === "foreignKey" || t === "foreignKeyInUse";
|
|
291
|
-
},
|
|
291
|
+
}, ln = (e) => {
|
|
292
292
|
let t = e.dbCode, n = e.dbErrno;
|
|
293
293
|
return t === "57014" || n === 3024 || n === 1969 || t === "ETIMEOUT" || t === "SQLITE_INTERRUPT";
|
|
294
|
-
},
|
|
295
|
-
let t =
|
|
294
|
+
}, un = (e) => {
|
|
295
|
+
let t = rn(e), n = [
|
|
296
296
|
t.dbCode === void 0 ? void 0 : `code=${String(t.dbCode)}`,
|
|
297
297
|
t.dbErrno === void 0 ? void 0 : `errno=${String(t.dbErrno)}`,
|
|
298
298
|
t.dbNumber === void 0 ? void 0 : `number=${String(t.dbNumber)}`,
|
|
@@ -301,7 +301,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
301
301
|
t.dbPlaceholders === void 0 ? void 0 : `placeholders=${String(t.dbPlaceholders)}`
|
|
302
302
|
].filter((e) => e !== void 0), r = typeof e?.message == "string" ? e.message : void 0, i = typeof t.dbMessage == "string" ? t.dbMessage : void 0, a = i === void 0 ? void 0 : n.length > 0 || i !== r && i !== `Error: ${String(r)}` ? i : void 0, o = typeof t.dbBindings == "string" ? `\n bindings: ${t.dbBindings}` : "", s = typeof t.dbStatement == "string" ? `\n statement: ${t.dbStatement.length <= 400 ? t.dbStatement : `${t.dbStatement.slice(0, 400)}…`}` : "";
|
|
303
303
|
if (a !== void 0 || n.length !== 0) return [a, n.length > 0 ? `[${n.join(" ")}]` : void 0].filter((e) => e !== void 0 && e !== "").join(" ") + s + o;
|
|
304
|
-
},
|
|
304
|
+
}, dn = (e) => Object.entries(e).map(([e, t]) => `${e}:${fn(t)}`).join(" "), fn = (e) => {
|
|
305
305
|
if (e === null) return "null";
|
|
306
306
|
if (e === void 0) return "undefined";
|
|
307
307
|
if (typeof e == "bigint") return "bigint";
|
|
@@ -311,62 +311,62 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
311
311
|
if (globalThis.Buffer !== void 0 && globalThis.Buffer.isBuffer(e)) return "Buffer";
|
|
312
312
|
let t = e.constructor?.name;
|
|
313
313
|
return typeof t == "string" && t !== "" ? t : "Object";
|
|
314
|
-
},
|
|
314
|
+
}, pn = (e) => {
|
|
315
315
|
let t = (() => {
|
|
316
316
|
switch (e.type) {
|
|
317
317
|
case "id":
|
|
318
318
|
case "reference":
|
|
319
319
|
case "text":
|
|
320
|
-
case "enum": return
|
|
320
|
+
case "enum": return M.String;
|
|
321
321
|
case "integer":
|
|
322
322
|
case "real":
|
|
323
|
-
case "decimal": return
|
|
324
|
-
case "boolean": return
|
|
323
|
+
case "decimal": return M.Number;
|
|
324
|
+
case "boolean": return M.Boolean;
|
|
325
325
|
case "timestamp":
|
|
326
|
-
case "date": return
|
|
327
|
-
case "bigint": return
|
|
328
|
-
case "bytes": return
|
|
329
|
-
case "array": return
|
|
330
|
-
case "interval": return
|
|
331
|
-
default: return
|
|
326
|
+
case "date": return St;
|
|
327
|
+
case "bigint": return M.BigInt;
|
|
328
|
+
case "bytes": return M.Uint8ArrayFromBase64;
|
|
329
|
+
case "array": return M.Array(M.Unknown);
|
|
330
|
+
case "interval": return M.String;
|
|
331
|
+
default: return M.Unknown;
|
|
332
332
|
}
|
|
333
333
|
})();
|
|
334
|
-
return e.nullable === !0 ?
|
|
335
|
-
},
|
|
334
|
+
return e.nullable === !0 ? M.NullOr(t) : t;
|
|
335
|
+
}, mn = (e, t) => {
|
|
336
336
|
let n = new Set(t?.omit ?? []), r = {};
|
|
337
|
-
for (let [t, i] of Object.entries(e.fields)) n.has(t) || (r[t] =
|
|
338
|
-
return
|
|
339
|
-
},
|
|
337
|
+
for (let [t, i] of Object.entries(e.fields)) n.has(t) || (r[t] = pn(i));
|
|
338
|
+
return M.Struct(r);
|
|
339
|
+
}, hn = (e) => typeof e == "function" ? e : () => e, gn = (e, t) => ({
|
|
340
340
|
kind: "one",
|
|
341
|
-
target:
|
|
341
|
+
target: hn(e),
|
|
342
342
|
...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
|
|
343
343
|
...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
|
|
344
|
-
}),
|
|
344
|
+
}), _n = (e, t) => ({
|
|
345
345
|
kind: "many",
|
|
346
|
-
target:
|
|
346
|
+
target: hn(e),
|
|
347
347
|
...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
|
|
348
348
|
...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
|
|
349
|
-
}),
|
|
349
|
+
}), vn = (e, t) => ({
|
|
350
350
|
kind: "manyToMany",
|
|
351
|
-
target:
|
|
352
|
-
through:
|
|
351
|
+
target: hn(e),
|
|
352
|
+
through: hn(t.through),
|
|
353
353
|
sourceKey: t.sourceKey,
|
|
354
354
|
targetKey: t.targetKey
|
|
355
|
-
}),
|
|
356
|
-
one:
|
|
357
|
-
many:
|
|
358
|
-
manyToMany:
|
|
359
|
-
},
|
|
355
|
+
}), yn = {
|
|
356
|
+
one: gn,
|
|
357
|
+
many: _n,
|
|
358
|
+
manyToMany: vn
|
|
359
|
+
}, bn = (e, t) => {
|
|
360
360
|
let n = typeof e == "function" ? e : () => e;
|
|
361
361
|
return {
|
|
362
362
|
source: n,
|
|
363
|
-
relations: t(
|
|
363
|
+
relations: t(yn, n())
|
|
364
364
|
};
|
|
365
|
-
},
|
|
365
|
+
}, xn = (e) => {
|
|
366
366
|
if (typeof e != "object" || !e) return !1;
|
|
367
367
|
let t = e;
|
|
368
368
|
return typeof t.source != "function" || typeof t.relations != "object" || t.relations === null ? !1 : Object.keys(t.relations).length === 0;
|
|
369
|
-
},
|
|
369
|
+
}, Sn = (e) => {
|
|
370
370
|
if (typeof e != "object" || !e) return !1;
|
|
371
371
|
let t = e;
|
|
372
372
|
if (typeof t.source != "function" || typeof t.relations != "object" || t.relations === null) return !1;
|
|
@@ -375,35 +375,35 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
375
375
|
let t = e?.kind;
|
|
376
376
|
return t === "one" || t === "many" || t === "manyToMany";
|
|
377
377
|
});
|
|
378
|
-
},
|
|
378
|
+
}, Cn = gn, wn = _n, Tn = vn, En = (e, t, n) => {
|
|
379
379
|
let r = [];
|
|
380
380
|
for (let [n, i] of Object.entries(e.fields)) i.type === "reference" && i.references?.()?.tableName === t && r.push(n);
|
|
381
381
|
if (r.length === 0) throw Error(`relation '${n}': no reference() column on '${e.tableName}' points at '${t}'. Either add one or pass an explicit { foreignKey: '<column>' }.`);
|
|
382
382
|
if (r.length > 1) throw Error(`relation '${n}': multiple reference() columns on '${e.tableName}' point at '${t}' (${r.join(", ")}). Pass an explicit { foreignKey: '<column>' } to disambiguate.`);
|
|
383
383
|
return r[0];
|
|
384
|
-
},
|
|
385
|
-
let t =
|
|
384
|
+
}, Dn = (e) => Object.keys(e.fields), On = (e, t) => Object.prototype.hasOwnProperty.call(e.fields, t), kn = (e) => {
|
|
385
|
+
let t = Dn(e);
|
|
386
386
|
return t.length === 0 ? "<none>" : t.join(", ");
|
|
387
387
|
}, An = (e, t, n) => {
|
|
388
388
|
let r = `relation '${t}' on '${e.tableName}'`, i = n.target();
|
|
389
389
|
if (n.kind === "manyToMany") {
|
|
390
390
|
let t = n.through();
|
|
391
|
-
for (let [a, o] of [["sourceKey", n.sourceKey], ["targetKey", n.targetKey]]) if (!
|
|
391
|
+
for (let [a, o] of [["sourceKey", n.sourceKey], ["targetKey", n.targetKey]]) if (!On(t, o)) throw Error(`${r}: manyToMany ${a} '${o}' is not a column on the junction table '${t.tableName}'. Both keys name columns on the JUNCTION — ${a === "sourceKey" ? `sourceKey points at '${e.tableName}'` : `targetKey points at '${i.tableName}'`}. Columns on '${t.tableName}': ${kn(t)}.`);
|
|
392
392
|
return;
|
|
393
393
|
}
|
|
394
394
|
if (n.sourceKey !== void 0 && n.foreignKey !== void 0) throw Error(`${r}: pass EITHER sourceKey OR foreignKey, not both. sourceKey '${n.sourceKey}' names a column on the source ('${e.tableName}') holding the target's id; foreignKey '${n.foreignKey}' names a column on the target ('${i.tableName}') holding the source's id. With both, foreignKey is ignored.`);
|
|
395
|
-
if (n.sourceKey !== void 0 && !
|
|
396
|
-
let t =
|
|
395
|
+
if (n.sourceKey !== void 0 && !On(e, n.sourceKey)) {
|
|
396
|
+
let t = On(i, n.sourceKey);
|
|
397
397
|
throw Error(`${r}: sourceKey '${n.sourceKey}' is not a column on the source table '${e.tableName}'.` + (t ? ` It IS a column on the target '${i.tableName}' — you probably want { foreignKey: '${n.sourceKey}' }, which names the column on the TARGET that holds this table's id.` : ` Columns on '${e.tableName}': ${kn(e)}.`));
|
|
398
398
|
}
|
|
399
|
-
if (n.foreignKey !== void 0 && !
|
|
400
|
-
let t =
|
|
399
|
+
if (n.foreignKey !== void 0 && !On(i, n.foreignKey)) {
|
|
400
|
+
let t = On(e, n.foreignKey);
|
|
401
401
|
throw Error(`${r}: foreignKey '${n.foreignKey}' is not a column on the target table '${i.tableName}'.` + (t ? ` It IS a column on the source '${e.tableName}' — you want { sourceKey: '${n.foreignKey}' }. foreignKey names the column on the TARGET that points back at this table; sourceKey names the column on THIS table that holds the target's id.` : ` Columns on '${i.tableName}': ${kn(i)}.`));
|
|
402
402
|
}
|
|
403
|
-
}, jn = Symbol.for("@voltro/database/relationsRegistry"), Mn = globalThis,
|
|
404
|
-
let t = e.source(), n =
|
|
403
|
+
}, jn = Symbol.for("@voltro/database/relationsRegistry"), Mn = globalThis, I = Mn[jn] ?? (Mn[jn] = /* @__PURE__ */ new Map()), Nn = (e) => {
|
|
404
|
+
let t = e.source(), n = I.get(t.tableName);
|
|
405
405
|
if (n === void 0) {
|
|
406
|
-
|
|
406
|
+
I.set(t.tableName, new Map(Object.entries(e.relations)));
|
|
407
407
|
return;
|
|
408
408
|
}
|
|
409
409
|
for (let [r, i] of Object.entries(e.relations)) {
|
|
@@ -415,26 +415,26 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
415
415
|
}
|
|
416
416
|
}, Pn = (e) => {
|
|
417
417
|
let t = 0;
|
|
418
|
-
for (let n of Object.values(e))
|
|
418
|
+
for (let n of Object.values(e)) Sn(n) && (Nn(n), t += 1);
|
|
419
419
|
return t;
|
|
420
420
|
}, Fn = (e) => {
|
|
421
|
-
let t =
|
|
421
|
+
let t = I.get(e);
|
|
422
422
|
if (t !== void 0) return Object.fromEntries(t);
|
|
423
|
-
}, In = (e, t) =>
|
|
423
|
+
}, In = (e, t) => I.get(e)?.get(t), Ln = () => {
|
|
424
424
|
let e = [];
|
|
425
|
-
for (let [t, n] of
|
|
425
|
+
for (let [t, n] of I) for (let [r, i] of n) e.push({
|
|
426
426
|
source: t,
|
|
427
427
|
name: r,
|
|
428
428
|
relation: i
|
|
429
429
|
});
|
|
430
430
|
return e;
|
|
431
431
|
}, Rn = () => {
|
|
432
|
-
for (let [e, t] of
|
|
432
|
+
for (let [e, t] of I) {
|
|
433
433
|
let n = p(e);
|
|
434
434
|
if (n !== void 0) for (let [e, r] of t) An(n, e, r);
|
|
435
435
|
}
|
|
436
436
|
}, zn = () => {
|
|
437
|
-
|
|
437
|
+
I.clear();
|
|
438
438
|
}, Bn = 4, Vn = (e) => Object.keys(e.fields), Hn = (e, t) => Object.prototype.hasOwnProperty.call(e.fields, t), Un = (e, t) => {
|
|
439
439
|
let n = [];
|
|
440
440
|
for (let [r, i] of Object.entries(e.fields)) i.type === "reference" && i.references?.()?.tableName === t && n.push(r);
|
|
@@ -662,7 +662,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
662
662
|
await mr(i, r.with, o, a);
|
|
663
663
|
return;
|
|
664
664
|
}
|
|
665
|
-
let c = n.foreignKey ??
|
|
665
|
+
let c = n.foreignKey ?? En(o, i.tableName, t), l = n.sourceKey ?? "id", u = fr(e, l), d = u.length === 0 ? [] : await pr(o, c, u, r, a), f = /* @__PURE__ */ new Map();
|
|
666
666
|
for (let e of d) {
|
|
667
667
|
let n = e[c];
|
|
668
668
|
if (f.has(n)) throw new rr(ir({
|
|
@@ -680,7 +680,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
680
680
|
}
|
|
681
681
|
await mr(d, r.with, o, a);
|
|
682
682
|
}, cr = async (e, t, n, r, i, a) => {
|
|
683
|
-
let o = n.target(), s = n.foreignKey ??
|
|
683
|
+
let o = n.target(), s = n.foreignKey ?? En(o, i.tableName, t), c = n.sourceKey ?? "id", l = fr(e, c), u = lr(r), d = l.length === 0 ? [] : await pr(o, s, l, u, a), f = /* @__PURE__ */ new Map();
|
|
684
684
|
for (let e of d) {
|
|
685
685
|
let t = e[s], n = f.get(t);
|
|
686
686
|
n ? n.push(e) : f.set(t, [e]);
|
|
@@ -792,10 +792,10 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
792
792
|
let { strings: n, values: r } = e, i = t.unsafe(n[0] ?? "");
|
|
793
793
|
for (let e = 0; e < r.length; e++) i = t`${i}${r[e]}${t.unsafe(n[e + 1] ?? "")}`;
|
|
794
794
|
return t`${i}`;
|
|
795
|
-
}, Or = (e) => e.replace(/[\\%_]/g, (e) => `\\${e}`),
|
|
796
|
-
if ("not" in e) return t`NOT (${
|
|
797
|
-
if ("and" in e) return e.and.length === 0 ? t`TRUE` : t.and(e.and.map((e) =>
|
|
798
|
-
if ("or" in e) return e.or.length === 0 ? t`FALSE` : t.or(e.or.map((e) =>
|
|
795
|
+
}, Or = (e) => e.replace(/[\\%_]/g, (e) => `\\${e}`), L = (e, t, n = null, r) => {
|
|
796
|
+
if ("not" in e) return t`NOT (${L(e.not, t, n, r)})`;
|
|
797
|
+
if ("and" in e) return e.and.length === 0 ? t`TRUE` : t.and(e.and.map((e) => L(e, t, n, r)));
|
|
798
|
+
if ("or" in e) return e.or.length === 0 ? t`FALSE` : t.or(e.or.map((e) => L(e, t, n, r)));
|
|
799
799
|
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
800
800
|
let r = e, i = zr(r.subquery, t, n);
|
|
801
801
|
return r.op === "subquery-in" ? t`${t(r.column)} IN (${i})` : t`${t(r.column)} NOT IN (${i})`;
|
|
@@ -805,15 +805,15 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
805
805
|
return r.op === "exists" ? t`EXISTS (${i})` : t`NOT EXISTS (${i})`;
|
|
806
806
|
}
|
|
807
807
|
let i = e, a = t(i.column), o = i.path, s = o !== void 0 && o.length > 0, c = () => t.onDialectOrElse({
|
|
808
|
-
mysql: () => t.unsafe(
|
|
809
|
-
mssql: () => t.unsafe(
|
|
810
|
-
sqlite: () => t.unsafe(
|
|
811
|
-
orElse: () => t.unsafe(
|
|
808
|
+
mysql: () => t.unsafe(E(i.column, o, "mysql")),
|
|
809
|
+
mssql: () => t.unsafe(E(i.column, o, "mssql")),
|
|
810
|
+
sqlite: () => t.unsafe(E(i.column, o, "sqlite")),
|
|
811
|
+
orElse: () => t.unsafe(E(i.column, o, "postgres"))
|
|
812
812
|
}), l = () => t.onDialectOrElse({
|
|
813
|
-
mysql: () => t.unsafe(
|
|
814
|
-
mssql: () => t.unsafe(
|
|
815
|
-
sqlite: () => t.unsafe(
|
|
816
|
-
orElse: () => t.unsafe(
|
|
813
|
+
mysql: () => t.unsafe(E(i.column, o, "mysql", { numeric: !0 })),
|
|
814
|
+
mssql: () => t.unsafe(E(i.column, o, "mssql", { numeric: !0 })),
|
|
815
|
+
sqlite: () => t.unsafe(E(i.column, o, "sqlite", { numeric: !0 })),
|
|
816
|
+
orElse: () => t.unsafe(E(i.column, o, "postgres", { numeric: !0 }))
|
|
817
817
|
}), u = s ? c() : a, d = s ? l() : a, f = (e) => s && e != null ? String(e) : e, m = (e) => s ? Number(e) : e, h = s || r === void 0 ? void 0 : p(r)?.fields?.[i.column]?.type, g = (e) => Tr(h, e);
|
|
818
818
|
switch (i.op) {
|
|
819
819
|
case "eq": return t`${u} = ${f(g(i.value))}`;
|
|
@@ -955,7 +955,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
955
955
|
}, zr = (e, t, n = null) => {
|
|
956
956
|
if (e.setOp && e.setOp.queries.length >= 2) {
|
|
957
957
|
let r = e.setOp.kind === "union" ? "UNION" : e.setOp.kind === "union-all" ? "UNION ALL" : e.setOp.kind === "intersect" ? "INTERSECT" : "EXCEPT", i = e.setOp.queries.map((e) => t`(${zr(e, t, n)})`).reduce((e, n, i) => i === 0 ? n : t`${e} ${t.unsafe(r)} ${n}`), a = [];
|
|
958
|
-
if (
|
|
958
|
+
if (w(e).length > 0 && a.push(t` ORDER BY ${t.csv(w(e).map((e) => e.direction === "desc" ? t`${t(e.column)} DESC` : t`${t(e.column)} ASC`))}`), e.take !== void 0) {
|
|
959
959
|
if (!Number.isInteger(e.take) || e.take < 0) throw Error(`compileSelect: invalid take ${e.take}`);
|
|
960
960
|
a.push(t` LIMIT ${t.unsafe(String(e.take))}`);
|
|
961
961
|
}
|
|
@@ -985,25 +985,25 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
985
985
|
sqlite: () => t`DISTINCT `
|
|
986
986
|
}) : e.distinct ? t`DISTINCT ` : t``, p = e.alias === void 0 ? t`${t(Sr(n, e.table))}` : t`${t(Sr(n, e.table))} AS ${t(e.alias)}`, m = (e.joins ?? []).map((e) => {
|
|
987
987
|
let r = e.kind === "inner" ? "INNER" : "LEFT";
|
|
988
|
-
return t` ${t.unsafe(r)} JOIN ${t(Sr(n, e.table))} AS ${t(e.alias)} ON ${
|
|
989
|
-
}), h = m.length > 0 ? m.reduce((e, n) => t`${e}${n}`, p) : p, g = c === void 0 ? null : Lr(c, e.table, t), ee = [e.predicate ?
|
|
990
|
-
r !== null &&
|
|
991
|
-
for (let n of
|
|
992
|
-
let
|
|
988
|
+
return t` ${t.unsafe(r)} JOIN ${t(Sr(n, e.table))} AS ${t(e.alias)} ON ${L(e.on, t, n)}`;
|
|
989
|
+
}), h = m.length > 0 ? m.reduce((e, n) => t`${e}${n}`, p) : p, g = c === void 0 ? null : Lr(c, e.table, t), ee = [e.predicate ? L(e.predicate, t, n, e.table) : null, g].filter((e) => e !== null), te = ee.length > 0 ? t` WHERE ${t.and(ee)}` : t``, _ = e.groupBy && e.groupBy.length > 0 ? t` GROUP BY ${t.csv(e.groupBy.map((e) => t`${t(e)}`))}` : t``, ne = e.having ? t` HAVING ${L(e.having, t, n, e.table)}` : t``, re = e.skip !== void 0, v = [];
|
|
990
|
+
r !== null && v.push(t`${r} ASC`), e.spatialClause?.order !== void 0 && v.push(e.spatialClause.order === "desc" ? t`${Pr(e.spatialClause, t)} DESC` : t`${Pr(e.spatialClause, t)} ASC`), l !== null && c?.rank?.order === !0 && v.push(t`${l} DESC`);
|
|
991
|
+
for (let n of w(e)) v.push(n.direction === "desc" ? t`${t(n.column)} DESC` : t`${t(n.column)} ASC`);
|
|
992
|
+
let ie = v.length > 0 ? t` ORDER BY ${t.csv(v)}` : re ? t.onDialectOrElse({
|
|
993
993
|
mssql: () => t` ORDER BY (SELECT NULL)`,
|
|
994
994
|
orElse: () => t``
|
|
995
|
-
}) : t``,
|
|
995
|
+
}) : t``, y = (e) => {
|
|
996
996
|
if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw Error(`compileSelect: expected non-negative integer take/skip, got ${e}`);
|
|
997
997
|
return t.unsafe(String(e));
|
|
998
|
-
},
|
|
998
|
+
}, ae = (e.ctes ?? []).map((e) => t`${t(e.name)} AS (${zr(e.descriptor, t, n)})`), oe = (e.ctes ?? []).some((e) => e.recursive === !0), se = ae.length > 0 ? t`WITH ${t.unsafe(oe ? "RECURSIVE " : "")}${t.csv(ae)} ` : t``;
|
|
999
999
|
return t.onDialectOrElse({
|
|
1000
1000
|
mssql: () => {
|
|
1001
|
-
let n = e.take !== void 0 && !
|
|
1002
|
-
return t`${
|
|
1001
|
+
let n = e.take !== void 0 && !re ? t`TOP ${y(e.take)} ` : t``, r = re ? t` OFFSET ${y(e.skip)} ROWS FETCH NEXT ${y(e.take ?? 2 ** 53 - 1)} ROWS ONLY` : t``;
|
|
1002
|
+
return t`${se}SELECT ${n}${f}${d} FROM ${h}${te}${_}${ne}${ie}${r}`;
|
|
1003
1003
|
},
|
|
1004
1004
|
orElse: () => {
|
|
1005
|
-
let n = e.take === void 0 ? t`` : t` LIMIT ${
|
|
1006
|
-
return t`${
|
|
1005
|
+
let n = e.take === void 0 ? t`` : t` LIMIT ${y(e.take)}`, r = re ? t` OFFSET ${y(e.skip)}` : t``;
|
|
1006
|
+
return t`${se}SELECT ${f}${d} FROM ${h}${te}${_}${ne}${ie}${n}${r}`;
|
|
1007
1007
|
}
|
|
1008
1008
|
});
|
|
1009
1009
|
}, Br = (e, t, n) => {
|
|
@@ -1043,12 +1043,12 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1043
1043
|
let r = t.sourceKey ?? Jr(n, i.tableName);
|
|
1044
1044
|
if (r !== void 0) o = r, s = "source";
|
|
1045
1045
|
else try {
|
|
1046
|
-
o = t.foreignKey ??
|
|
1046
|
+
o = t.foreignKey ?? En(i, n.tableName, e), s = "target";
|
|
1047
1047
|
} catch {
|
|
1048
1048
|
return null;
|
|
1049
1049
|
}
|
|
1050
1050
|
} else try {
|
|
1051
|
-
o = t.foreignKey ??
|
|
1051
|
+
o = t.foreignKey ?? En(i, n.tableName, e), s = "target";
|
|
1052
1052
|
} catch {
|
|
1053
1053
|
return null;
|
|
1054
1054
|
}
|
|
@@ -1175,16 +1175,16 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1175
1175
|
};
|
|
1176
1176
|
}, ni = (e, t, n) => {
|
|
1177
1177
|
let r = n.sql, i = n.nextAlias(), a = r(t.table.tableName), o = r(i), s = ri(i, t.children, n);
|
|
1178
|
-
return s === null ? null : r`SELECT ${s} AS "__row" FROM ${a} AS ${o}${e.predicate ? r` WHERE ${
|
|
1178
|
+
return s === null ? null : r`SELECT ${s} AS "__row" FROM ${a} AS ${o}${e.predicate ? r` WHERE ${U(e.predicate, i, r)}` : r``}${w(e).length > 0 ? r` ORDER BY ${r.csv(w(e).map((e) => e.direction === "desc" ? r`${B(i, e.column, r)} DESC` : r`${B(i, e.column, r)} ASC`))}` : r``}${e.take === void 0 ? r`` : r` LIMIT ${H(e.take, r)}`}${e.skip === void 0 ? r`` : r` OFFSET ${H(e.skip, r)}`}`;
|
|
1179
1179
|
}, ri = (e, t, n, r) => {
|
|
1180
|
-
let i = n.sql, a = r === void 0 ? i`to_jsonb(${i(e)}.*)` : i`(to_jsonb(${i(e)}.*) - ${
|
|
1180
|
+
let i = n.sql, a = r === void 0 ? i`to_jsonb(${i(e)}.*)` : i`(to_jsonb(${i(e)}.*) - ${V(qr, i)}::text)`;
|
|
1181
1181
|
if (t.length === 0 && r === void 0) return a;
|
|
1182
1182
|
let o = [];
|
|
1183
|
-
r !== void 0 && o.push(i`${
|
|
1183
|
+
r !== void 0 && o.push(i`${V("_junction", i)}, ${B(e, qr, i)}`);
|
|
1184
1184
|
for (let r of t) {
|
|
1185
1185
|
let t = ii(r, e, n);
|
|
1186
1186
|
if (t === null) return null;
|
|
1187
|
-
o.push(i`${
|
|
1187
|
+
o.push(i`${V(r.relationName, i)}, ${t}`);
|
|
1188
1188
|
}
|
|
1189
1189
|
return i`${a} || jsonb_build_object(${i.csv(o)})`;
|
|
1190
1190
|
}, ii = (e, t, n) => {
|
|
@@ -1196,37 +1196,37 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1196
1196
|
}, ai = (e, t, n) => {
|
|
1197
1197
|
let r = n.sql, i = n.nextAlias(), a = ri(i, e.children, n);
|
|
1198
1198
|
if (a === null) return null;
|
|
1199
|
-
let o = e.fkSide === "source" ? r`${
|
|
1199
|
+
let o = e.fkSide === "source" ? r`${B(i, "id", r)} = ${B(t, e.foreignKey, r)}` : r`${B(i, e.foreignKey, r)} = ${B(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${U(e.branch.where, i, r)}`, c = R(i, e.branch.orderBy, r);
|
|
1200
1200
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}${c} LIMIT 1)`;
|
|
1201
1201
|
}, oi = (e, t, n) => {
|
|
1202
1202
|
let r = n.sql, i = n.nextAlias(), a = ri(i, e.children, n);
|
|
1203
1203
|
if (a === null) return null;
|
|
1204
|
-
let o = r`${
|
|
1204
|
+
let o = r`${B(void 0, e.foreignKey, r)} = ${B(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${L(e.branch.where, r)}`, c = li(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${H(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${H(e.branch.offset, r)}`;
|
|
1205
1205
|
return r`COALESCE((SELECT jsonb_agg(${a}) FROM (SELECT * FROM ${r(e.target.tableName)} WHERE ${o}${s}${c}${l}${u}) AS ${r(i)}), '[]'::jsonb)`;
|
|
1206
1206
|
}, si = (e, t, n) => {
|
|
1207
1207
|
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = ri(o, e.children, n, e.junction);
|
|
1208
1208
|
if (c === null) return null;
|
|
1209
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1210
|
-
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 ${
|
|
1211
|
-
}, ci = (e, t, n) => e.present.length === 0 ? n`jsonb_build_object()` : n`jsonb_build_object(${n.csv(e.present.map((e) => n`${
|
|
1209
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${L(e.branch.where, r)}`, u = Fi(e, s, r), d = R(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${H(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${H(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : r`, ${ci(e.junction, s, r)} AS ${r(qr)}`;
|
|
1210
|
+
return r`COALESCE((SELECT jsonb_agg(${c}) FROM (SELECT ${r(o)}.*${m} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${B(o, "id", r)} = ${B(s, i.targetKey, r)} WHERE ${B(s, i.sourceKey, r)} = ${B(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), '[]'::jsonb)`;
|
|
1211
|
+
}, ci = (e, t, n) => e.present.length === 0 ? n`jsonb_build_object()` : n`jsonb_build_object(${n.csv(e.present.map((e) => n`${V(e, n)}, ${B(t, e, n)}`))})`, R = (e, t, n) => t === void 0 || t.length === 0 ? n`` : n` ORDER BY ${n.csv(t.map((t) => t.direction === "desc" ? n`${B(e, t.column, n)} DESC` : n`${B(e, t.column, n)} ASC`))}`, li = (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`))}`, ui = (e, t, n) => {
|
|
1212
1212
|
let r = n.sql, i = n.nextAlias(), a = di(i, t.table, t.children, n);
|
|
1213
1213
|
if (a === null) return null;
|
|
1214
|
-
let o = e.predicate ? r` WHERE ${
|
|
1214
|
+
let o = e.predicate ? r` WHERE ${U(e.predicate, i, r)}` : r``, s = w(e).length > 0 ? r` ORDER BY ${r.csv(w(e).map((e) => e.direction === "desc" ? r`${B(i, e.column, r)} DESC` : r`${B(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${H(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${H(e.skip, r)}`;
|
|
1215
1215
|
return r`SELECT ${a} AS "__row" FROM ${r(t.table.tableName)} AS ${r(i)}${o}${s}${c}${l}`;
|
|
1216
1216
|
}, di = (e, t, n, r, i) => {
|
|
1217
1217
|
let a = r.sql, o = [];
|
|
1218
|
-
for (let n of Object.keys(t.fields)) o.push(a`${
|
|
1218
|
+
for (let n of Object.keys(t.fields)) o.push(a`${V(n, a)}, ${B(e, n, a)}`);
|
|
1219
1219
|
if (i !== void 0) {
|
|
1220
1220
|
let e = fi(i.projection, i.source, a);
|
|
1221
|
-
o.push(a`${
|
|
1221
|
+
o.push(a`${V("_junction", a)}, json_object(${e})`);
|
|
1222
1222
|
}
|
|
1223
1223
|
for (let t of n) {
|
|
1224
1224
|
let n = gi(t, e, r);
|
|
1225
1225
|
if (n === null) return null;
|
|
1226
|
-
o.push(a`${
|
|
1226
|
+
o.push(a`${V(t.relationName, a)}, ${n}`);
|
|
1227
1227
|
}
|
|
1228
1228
|
return a`json_object(${a.csv(o)})`;
|
|
1229
|
-
}, fi = (e, t, n) => e.present.length === 0 ? n`` : n.csv(e.present.map((e) => n`${
|
|
1229
|
+
}, fi = (e, t, n) => e.present.length === 0 ? n`` : n.csv(e.present.map((e) => n`${V(e, n)}, ${B(t.alias, t.physical(e), n)}`)), pi = (e, t, n) => e.present.length === 0 ? n`` : n`, ${n.csv(e.present.map((e) => n`${B(t, e, n)} AS ${n(Kr(e))}`))}`, mi = (e) => ({
|
|
1230
1230
|
alias: e,
|
|
1231
1231
|
physical: Kr
|
|
1232
1232
|
}), hi = (e) => ({
|
|
@@ -1241,12 +1241,12 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1241
1241
|
}, _i = (e, t, n) => {
|
|
1242
1242
|
let r = n.sql, i = n.nextAlias(), a = di(i, e.target, e.children, n);
|
|
1243
1243
|
if (a === null) return null;
|
|
1244
|
-
let o = e.fkSide === "source" ? r`${
|
|
1244
|
+
let o = e.fkSide === "source" ? r`${B(i, "id", r)} = ${B(t, e.foreignKey, r)}` : r`${B(i, e.foreignKey, r)} = ${B(t, e.sourceKey, r)}`;
|
|
1245
1245
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
|
|
1246
1246
|
}, vi = (e, t, n) => {
|
|
1247
1247
|
let r = n.sql, i = n.nextAlias(), a = di(i, e.target, e.children, n);
|
|
1248
1248
|
if (a === null) return null;
|
|
1249
|
-
let o = r`${
|
|
1249
|
+
let o = r`${B(void 0, e.foreignKey, r)} = ${B(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${L(W(e.branch.where), r)}`, c = li(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${H(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${H(e.branch.offset, r)}`;
|
|
1250
1250
|
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('[]'))`;
|
|
1251
1251
|
}, yi = (e, t, n) => {
|
|
1252
1252
|
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = di(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
@@ -1254,24 +1254,24 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1254
1254
|
source: mi(o)
|
|
1255
1255
|
});
|
|
1256
1256
|
if (c === null) return null;
|
|
1257
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1258
|
-
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 ${
|
|
1257
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${L(W(e.branch.where), r)}`, u = Fi(e, s, r, !0), d = R(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${H(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${H(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : pi(e.junction, s, r);
|
|
1258
|
+
return r`COALESCE((SELECT json_group_array(${c}) FROM (SELECT ${r(o)}.*${m} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${B(o, "id", r)} = ${B(s, i.targetKey, r)} WHERE ${B(s, i.sourceKey, r)} = ${B(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), json('[]'))`;
|
|
1259
1259
|
}, bi = (e, t, n) => {
|
|
1260
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1260
|
+
let r = n.sql, i = n.nextAlias(), a = z(i, t.table, t.children, n);
|
|
1261
1261
|
if (a === null) return null;
|
|
1262
|
-
let o = e.predicate ? r` WHERE ${
|
|
1262
|
+
let o = e.predicate ? r` WHERE ${U(e.predicate, i, r)}` : r``, s = w(e).length > 0 ? r` ORDER BY ${r.csv(w(e).map((e) => e.direction === "desc" ? r`${B(i, e.column, r)} DESC` : r`${B(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${H(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${H(e.skip, r)}`;
|
|
1263
1263
|
return r`SELECT ${a} AS \`__row\` FROM ${r(t.table.tableName)} AS ${r(i)}${o}${s}${c}${l}`;
|
|
1264
|
-
},
|
|
1264
|
+
}, z = (e, t, n, r, i) => {
|
|
1265
1265
|
let a = r.sql, o = [];
|
|
1266
|
-
for (let n of Object.keys(t.fields)) o.push(a`${
|
|
1266
|
+
for (let n of Object.keys(t.fields)) o.push(a`${V(n, a)}, ${B(e, n, a)}`);
|
|
1267
1267
|
if (i !== void 0) {
|
|
1268
1268
|
let e = fi(i.projection, i.source, a);
|
|
1269
|
-
o.push(a`${
|
|
1269
|
+
o.push(a`${V("_junction", a)}, JSON_OBJECT(${e})`);
|
|
1270
1270
|
}
|
|
1271
1271
|
for (let t of n) {
|
|
1272
1272
|
let n = xi(t, e, r);
|
|
1273
1273
|
if (n === null) return null;
|
|
1274
|
-
o.push(a`${
|
|
1274
|
+
o.push(a`${V(t.relationName, a)}, ${n}`);
|
|
1275
1275
|
}
|
|
1276
1276
|
return a`JSON_OBJECT(${a.csv(o)})`;
|
|
1277
1277
|
}, xi = (e, t, n) => {
|
|
@@ -1286,57 +1286,57 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1286
1286
|
case "manyToMany": return n.dialect === "mariadb" ? Ei(e, t, n) : wi(e, t, n);
|
|
1287
1287
|
}
|
|
1288
1288
|
}, Si = (e, t, n) => {
|
|
1289
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1289
|
+
let r = n.sql, i = n.nextAlias(), a = z(i, e.target, e.children, n);
|
|
1290
1290
|
if (a === null) return null;
|
|
1291
|
-
let o = e.fkSide === "source" ? r`${
|
|
1291
|
+
let o = e.fkSide === "source" ? r`${B(i, "id", r)} = ${B(t, e.foreignKey, r)}` : r`${B(i, e.foreignKey, r)} = ${B(t, e.sourceKey, r)}`;
|
|
1292
1292
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
|
|
1293
1293
|
}, Ci = (e, t, n) => {
|
|
1294
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1294
|
+
let r = n.sql, i = n.nextAlias(), a = z(i, e.target, e.children, n);
|
|
1295
1295
|
if (a === null) return null;
|
|
1296
|
-
let o = r`${
|
|
1296
|
+
let o = r`${B(void 0, e.foreignKey, r)} = ${B(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${L(W(e.branch.where), r)}`, c = li(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${H(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${H(e.branch.offset, r)}`;
|
|
1297
1297
|
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())`;
|
|
1298
1298
|
}, wi = (e, t, n) => {
|
|
1299
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
1299
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = z(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
1300
1300
|
projection: e.junction,
|
|
1301
1301
|
source: mi(o)
|
|
1302
1302
|
});
|
|
1303
1303
|
if (c === null) return null;
|
|
1304
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1305
|
-
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 ${
|
|
1304
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${L(W(e.branch.where), r)}`, u = Fi(e, s, r, !0), d = R(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${H(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${H(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : pi(e.junction, s, r);
|
|
1305
|
+
return r`COALESCE((SELECT JSON_ARRAYAGG(${c}) FROM (SELECT ${r(o)}.*${m} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${B(o, "id", r)} = ${B(s, i.targetKey, r)} WHERE ${B(s, i.sourceKey, r)} = ${B(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), JSON_ARRAY())`;
|
|
1306
1306
|
}, Ti = (e, t, n) => {
|
|
1307
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1307
|
+
let r = n.sql, i = n.nextAlias(), a = z(i, e.target, e.children, n);
|
|
1308
1308
|
if (a === null) return null;
|
|
1309
|
-
let o = r`${
|
|
1310
|
-
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`${
|
|
1311
|
-
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 ${
|
|
1312
|
-
return r`COALESCE((SELECT JSON_ARRAYAGG(${a} ORDER BY ${
|
|
1309
|
+
let o = r`${B(i, e.foreignKey, r)} = ${B(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${L(W(e.branch.where), r)}`, c = e.branch.orderBy ?? [];
|
|
1310
|
+
if (e.branch.limit === void 0 && e.branch.offset === void 0) return r`COALESCE((SELECT JSON_ARRAYAGG(${a}${c.length > 0 ? r` ORDER BY ${r.csv(c.map((e) => e.direction === "desc" ? r`${B(i, e.column, r)} DESC` : r`${B(i, e.column, r)} ASC`))}` : r``}) FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}), JSON_ARRAY())`;
|
|
1311
|
+
let l = c.length > 0 ? r` ORDER BY ${r.csv(c.map((e) => e.direction === "desc" ? r`${r(e.column)} DESC` : r`${r(e.column)} ASC`))}` : r` ORDER BY ${r("id")}`, u = e.branch.limit, d = e.branch.offset, f = u !== void 0 && d !== void 0 ? r` AND ${B(i, "rn", r)} > ${H(d, r)} AND ${B(i, "rn", r)} <= ${H(d + u, r)}` : u === void 0 ? r` AND ${B(i, "rn", r)} > ${H(d, r)}` : r` AND ${B(i, "rn", r)} <= ${H(u, r)}`;
|
|
1312
|
+
return r`COALESCE((SELECT JSON_ARRAYAGG(${a} ORDER BY ${B(i, "rn", r)}) FROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY ${r(e.foreignKey)}${l}) AS rn FROM ${r(e.target.tableName)}) AS ${r(i)} WHERE ${o}${s}${f}), JSON_ARRAY())`;
|
|
1313
1313
|
}, Ei = (e, t, n) => {
|
|
1314
1314
|
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = (t) => e.junction === void 0 ? void 0 : {
|
|
1315
1315
|
projection: e.junction,
|
|
1316
1316
|
source: t
|
|
1317
|
-
}, l = r`${
|
|
1317
|
+
}, l = r`${B(s, i.sourceKey, r)} = ${B(t, "id", r)}`, u = r`${B(o, "id", r)} = ${B(s, i.targetKey, r)}`, d = e.branch.where === void 0 ? r`` : r` AND ${L(W(e.branch.where), r)}`, f = Fi(e, s, r, !0), p = e.branch.orderBy ?? [];
|
|
1318
1318
|
if (e.branch.limit === void 0 && e.branch.offset === void 0) {
|
|
1319
|
-
let t =
|
|
1320
|
-
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`${
|
|
1319
|
+
let t = z(o, e.target, e.children, n, c(hi(s)));
|
|
1320
|
+
return t === null ? null : r`COALESCE((SELECT JSON_ARRAYAGG(${t}${p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${B(o, e.column, r)} DESC` : r`${B(o, e.column, r)} ASC`))}` : r``}) FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${u} WHERE ${l}${f}${d}), JSON_ARRAY())`;
|
|
1321
1321
|
}
|
|
1322
|
-
let m = p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${
|
|
1322
|
+
let m = p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${B(o, e.column, r)} DESC` : r`${B(o, e.column, r)} ASC`))}` : r` ORDER BY ${B(o, "id", r)}`, h = e.branch.limit, g = e.branch.offset, ee = h !== void 0 && g !== void 0 ? r` AND ${B(o, "rn", r)} > ${H(g, r)} AND ${B(o, "rn", r)} <= ${H(g + h, r)}` : h === void 0 ? r` AND ${B(o, "rn", r)} > ${H(g, r)}` : r` AND ${B(o, "rn", r)} <= ${H(h, r)}`, te = e.branch.onJunction === void 0 ? r`` : r` WHERE ${U(W(e.branch.onJunction), s, r)}`, _ = z(o, e.target, e.children, n, c(mi(o)));
|
|
1323
1323
|
if (_ === null) return null;
|
|
1324
|
-
let
|
|
1325
|
-
return r`COALESCE((SELECT JSON_ARRAYAGG(${_} ORDER BY ${
|
|
1324
|
+
let ne = e.junction === void 0 ? r`` : pi(e.junction, s, r);
|
|
1325
|
+
return r`COALESCE((SELECT JSON_ARRAYAGG(${_} ORDER BY ${B(o, "rn", r)}) FROM (SELECT ${r(o)}.*${ne}, ${B(s, i.sourceKey, r)} AS ${r(`__src_${i.sourceKey}`)}, ROW_NUMBER() OVER (PARTITION BY ${B(s, i.sourceKey, r)}${m}) AS rn FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${u}${te}) AS ${r(o)} WHERE ${B(o, `__src_${i.sourceKey}`, r)} = ${B(t, "id", r)}${d}${ee}), JSON_ARRAY())`;
|
|
1326
1326
|
}, Di = (e, t, n) => {
|
|
1327
1327
|
let r = n.sql, i = n.nextAlias(), a = Oi(i, t.table, t.children, n);
|
|
1328
1328
|
if (a === null) return null;
|
|
1329
|
-
let o = e.predicate ? r` WHERE ${
|
|
1329
|
+
let o = e.predicate ? r` WHERE ${U(e.predicate, i, r)}` : r``, s = w(e).length > 0 ? r` ORDER BY ${r.csv(w(e).map((e) => e.direction === "desc" ? r`${B(i, e.column, r)} DESC` : r`${B(i, e.column, r)} ASC`))}` : r``, c = r``, l = r``;
|
|
1330
1330
|
if (e.skip !== void 0) {
|
|
1331
|
-
let t =
|
|
1332
|
-
l = e.take === void 0 ? r`${t} OFFSET ${
|
|
1333
|
-
} else e.take !== void 0 && (c = r`TOP ${
|
|
1331
|
+
let t = w(e).length > 0 ? s : r` ORDER BY (SELECT NULL)`;
|
|
1332
|
+
l = e.take === void 0 ? r`${t} OFFSET ${H(e.skip, r)} ROWS` : r`${t} OFFSET ${H(e.skip, r)} ROWS FETCH NEXT ${H(e.take, r)} ROWS ONLY`;
|
|
1333
|
+
} else e.take !== void 0 && (c = r`TOP ${H(e.take, r)} `);
|
|
1334
1334
|
let u = e.skip === void 0 ? s : r``;
|
|
1335
1335
|
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}`;
|
|
1336
1336
|
}, Oi = (e, t, n, r, i) => {
|
|
1337
1337
|
let a = r.sql, o = [];
|
|
1338
|
-
for (let n of Object.keys(t.fields)) o.push(a`${
|
|
1339
|
-
if (i !== void 0) for (let e of i.projection.present) o.push(a`${
|
|
1338
|
+
for (let n of Object.keys(t.fields)) o.push(a`${B(e, n, a)} AS ${a(n)}`);
|
|
1339
|
+
if (i !== void 0) for (let e of i.projection.present) o.push(a`${B(i.source.alias, i.source.physical(e), a)} AS ${ki(`_junction.${e}`, a)}`);
|
|
1340
1340
|
for (let t of n) {
|
|
1341
1341
|
let n = Ai(t, e, r);
|
|
1342
1342
|
if (n === null) return null;
|
|
@@ -1352,11 +1352,11 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1352
1352
|
}, ji = (e, t, n) => {
|
|
1353
1353
|
let r = n.sql, i = n.nextAlias(), a = Oi(i, e.target, e.children, n);
|
|
1354
1354
|
if (a === null) return null;
|
|
1355
|
-
let o = e.fkSide === "source" ? r`${
|
|
1355
|
+
let o = e.fkSide === "source" ? r`${B(i, "id", r)} = ${B(t, e.foreignKey, r)}` : r`${B(i, e.foreignKey, r)} = ${B(t, e.sourceKey, r)}`;
|
|
1356
1356
|
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)}`;
|
|
1357
1357
|
}, Mi = (e, t, n) => {
|
|
1358
1358
|
if (e.offset !== void 0) {
|
|
1359
|
-
let r = e.orderBy && e.orderBy.length > 0 ? t : n` ORDER BY (SELECT NULL)`, i = e.limit === void 0 ? n`${r} OFFSET ${
|
|
1359
|
+
let r = e.orderBy && e.orderBy.length > 0 ? t : n` ORDER BY (SELECT NULL)`, i = e.limit === void 0 ? n`${r} OFFSET ${H(e.offset, n)} ROWS` : n`${r} OFFSET ${H(e.offset, n)} ROWS FETCH NEXT ${H(e.limit, n)} ROWS ONLY`;
|
|
1360
1360
|
return {
|
|
1361
1361
|
top: n``,
|
|
1362
1362
|
pagination: i,
|
|
@@ -1364,29 +1364,29 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1364
1364
|
};
|
|
1365
1365
|
}
|
|
1366
1366
|
return {
|
|
1367
|
-
top: e.limit === void 0 ? n`` : n`TOP ${
|
|
1367
|
+
top: e.limit === void 0 ? n`` : n`TOP ${H(e.limit, n)} `,
|
|
1368
1368
|
pagination: n``,
|
|
1369
1369
|
finalOrder: t
|
|
1370
1370
|
};
|
|
1371
1371
|
}, Ni = (e, t, n) => {
|
|
1372
1372
|
let r = n.sql, i = n.nextAlias(), a = Oi(i, e.target, e.children, n);
|
|
1373
1373
|
if (a === null) return null;
|
|
1374
|
-
let o = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1375
|
-
return r`ISNULL(JSON_QUERY((SELECT ${c}${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${
|
|
1374
|
+
let o = e.branch.where === void 0 ? r`` : r` AND ${U(e.branch.where, i, r)}`, s = R(i, e.branch.orderBy, r), { top: c, pagination: l, finalOrder: u } = Mi(e.branch, s, r);
|
|
1375
|
+
return r`ISNULL(JSON_QUERY((SELECT ${c}${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${B(i, e.foreignKey, r)} = ${B(t, e.sourceKey, r)}${o}${u}${l} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
|
|
1376
1376
|
}, Pi = (e, t, n) => {
|
|
1377
1377
|
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = Oi(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
1378
1378
|
projection: e.junction,
|
|
1379
1379
|
source: hi(s)
|
|
1380
1380
|
});
|
|
1381
1381
|
if (c === null) return null;
|
|
1382
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1383
|
-
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 ${
|
|
1384
|
-
},
|
|
1382
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${U(e.branch.where, o, r)}`, u = Fi(e, s, r), d = R(o, e.branch.orderBy, r), { top: f, pagination: p, finalOrder: m } = Mi(e.branch, d, r);
|
|
1383
|
+
return r`ISNULL(JSON_QUERY((SELECT ${f}${c} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${B(o, "id", r)} = ${B(s, i.targetKey, r)} WHERE ${B(s, i.sourceKey, r)} = ${B(t, "id", r)}${u}${l}${m}${p} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
|
|
1384
|
+
}, B = (e, t, n) => e === void 0 ? n`${n(t)}` : n`${n(e)}.${n(t)}`, V = (e, t) => t.unsafe(`'${e.replace(/'/g, "''")}'`), H = (e, t) => {
|
|
1385
1385
|
if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw Error(`literalInt: expected non-negative integer, got ${e}`);
|
|
1386
1386
|
return t.unsafe(String(e));
|
|
1387
|
-
},
|
|
1387
|
+
}, U = (e, t, n) => L(Ii(e, t), n), Fi = (e, t, n, r = !1) => {
|
|
1388
1388
|
let i = e.branch.onJunction;
|
|
1389
|
-
return i === void 0 ? n`` : n` AND ${
|
|
1389
|
+
return i === void 0 ? n`` : n` AND ${U(r ? W(i) : i, t, n)}`;
|
|
1390
1390
|
}, Ii = (e, t) => {
|
|
1391
1391
|
if ("not" in e) return { not: Ii(e.not, t) };
|
|
1392
1392
|
if ("and" in e) return { and: e.and.map((e) => Ii(e, t)) };
|
|
@@ -1404,10 +1404,10 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1404
1404
|
...n,
|
|
1405
1405
|
column: `${t}.${n.column}`
|
|
1406
1406
|
};
|
|
1407
|
-
},
|
|
1408
|
-
if ("not" in e) return { not:
|
|
1409
|
-
if ("and" in e) return { and: e.and.map((e) =>
|
|
1410
|
-
if ("or" in e) return { or: e.or.map((e) =>
|
|
1407
|
+
}, W = (e) => {
|
|
1408
|
+
if ("not" in e) return { not: W(e.not) };
|
|
1409
|
+
if ("and" in e) return { and: e.and.map((e) => W(e)) };
|
|
1410
|
+
if ("or" in e) return { or: e.or.map((e) => W(e)) };
|
|
1411
1411
|
if (e.op === "subquery-in" || e.op === "subquery-not-in" || e.op === "exists" || e.op === "not-exists") return e;
|
|
1412
1412
|
let t = e;
|
|
1413
1413
|
return {
|
|
@@ -1422,13 +1422,13 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1422
1422
|
return n();
|
|
1423
1423
|
}, Ui = () => Hi(() => Bi.actors, "actors"), Wi = () => Hi(() => Bi.tenants, "tenants"), Gi = T("actors", {
|
|
1424
1424
|
id: b(),
|
|
1425
|
-
kind:
|
|
1425
|
+
kind: C().oneOf([
|
|
1426
1426
|
"user",
|
|
1427
1427
|
"serviceAccount",
|
|
1428
1428
|
"apiKey",
|
|
1429
1429
|
"system"
|
|
1430
1430
|
]),
|
|
1431
|
-
displayName:
|
|
1431
|
+
displayName: C().nullable(),
|
|
1432
1432
|
createdAt: S().default("now")
|
|
1433
1433
|
}), Ki = (e, t) => ({
|
|
1434
1434
|
column: e,
|
|
@@ -1658,7 +1658,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1658
1658
|
},
|
|
1659
1659
|
...a
|
|
1660
1660
|
};
|
|
1661
|
-
}, Oa = new
|
|
1661
|
+
}, Oa = new jt(), ka = (e, t) => Oa.run(e, t), Aa = () => Oa.getStore(), ja = (e) => {
|
|
1662
1662
|
let t = e ?? Oa.getStore();
|
|
1663
1663
|
return t === void 0 ? {} : {
|
|
1664
1664
|
...t.traceId === void 0 ? {} : { traceId: t.traceId },
|
|
@@ -1669,29 +1669,29 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1669
1669
|
}, Ma = (e) => {
|
|
1670
1670
|
let t = Oa.getStore();
|
|
1671
1671
|
return t === void 0 ? e(void 0) : Oa.run(t, () => e(t));
|
|
1672
|
-
}, Na = 3e4, Pa = 1e4,
|
|
1673
|
-
for (let [t, n] of
|
|
1672
|
+
}, Na = 3e4, Pa = 1e4, G = /* @__PURE__ */ new Map(), K = 0, Fa = (e, t, n) => `${e}\u0000${t}\u0000${String(n)}`, Ia = (e) => {
|
|
1673
|
+
for (let [t, n] of G) {
|
|
1674
1674
|
let r = n.filter((t) => e - t.at < Na);
|
|
1675
|
-
|
|
1675
|
+
K -= n.length - r.length, r.length === 0 ? G.delete(t) : r.length !== n.length && G.set(t, r);
|
|
1676
1676
|
}
|
|
1677
1677
|
}, La = (e, t) => {
|
|
1678
1678
|
if (t.traceId === void 0 && t.subjectId === void 0 && t.procedure === void 0) return;
|
|
1679
1679
|
let n = Date.now();
|
|
1680
|
-
if (
|
|
1681
|
-
let r =
|
|
1682
|
-
r === void 0 ?
|
|
1680
|
+
if (K >= Pa && Ia(n), K >= Pa) return;
|
|
1681
|
+
let r = G.get(e);
|
|
1682
|
+
r === void 0 ? G.set(e, [{
|
|
1683
1683
|
attribution: t,
|
|
1684
1684
|
at: n
|
|
1685
1685
|
}]) : r.push({
|
|
1686
1686
|
attribution: t,
|
|
1687
1687
|
at: n
|
|
1688
|
-
}),
|
|
1688
|
+
}), K += 1;
|
|
1689
1689
|
}, Ra = (e) => {
|
|
1690
|
-
let t =
|
|
1690
|
+
let t = G.get(e);
|
|
1691
1691
|
if (t === void 0 || t.length === 0) return;
|
|
1692
1692
|
let n = t.shift();
|
|
1693
|
-
if (--
|
|
1694
|
-
}, za = (e) => (
|
|
1693
|
+
if (--K, t.length === 0 && G.delete(e), !(Date.now() - n.at >= Na)) return n.attribution;
|
|
1694
|
+
}, za = (e) => (G.get(e)?.length ?? 0) > 0, q = /* @__PURE__ */ new Map(), Ba = /* @__PURE__ */ new Map(), Va = /* @__PURE__ */ new Map(), Ha = 250, Ua = (e) => {
|
|
1695
1695
|
let t = Ba.get(e);
|
|
1696
1696
|
if (t === void 0) return;
|
|
1697
1697
|
Ba.delete(e);
|
|
@@ -1699,14 +1699,14 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1699
1699
|
n !== void 0 && (clearTimeout(n), Va.delete(e));
|
|
1700
1700
|
for (let e of t) e();
|
|
1701
1701
|
}, Wa = (e) => {
|
|
1702
|
-
|
|
1702
|
+
q.set(e, (q.get(e) ?? 0) + 1);
|
|
1703
1703
|
}, Ga = (e) => {
|
|
1704
|
-
let t = (
|
|
1704
|
+
let t = (q.get(e) ?? 0) - 1;
|
|
1705
1705
|
if (t > 0) {
|
|
1706
|
-
|
|
1706
|
+
q.set(e, t);
|
|
1707
1707
|
return;
|
|
1708
1708
|
}
|
|
1709
|
-
|
|
1709
|
+
q.delete(e), Ua(e);
|
|
1710
1710
|
}, Ka = (e, t, n, r) => {
|
|
1711
1711
|
let i = n == null ? void 0 : Fa(e, t, n), a = () => r(i === void 0 ? void 0 : Ra(i));
|
|
1712
1712
|
if (i === void 0) {
|
|
@@ -1718,7 +1718,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1718
1718
|
return;
|
|
1719
1719
|
}
|
|
1720
1720
|
let o = Ba.get(e);
|
|
1721
|
-
if (o === void 0 && (
|
|
1721
|
+
if (o === void 0 && (q.get(e) ?? 0) === 0) {
|
|
1722
1722
|
a();
|
|
1723
1723
|
return;
|
|
1724
1724
|
}
|
|
@@ -1730,38 +1730,38 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1730
1730
|
let s = setTimeout(() => Ua(e), Ha);
|
|
1731
1731
|
typeof s == "object" && typeof s.unref == "function" && s.unref(), Va.set(e, s);
|
|
1732
1732
|
}, qa = () => {
|
|
1733
|
-
|
|
1733
|
+
G.clear(), K = 0, q.clear();
|
|
1734
1734
|
for (let e of Va.values()) clearTimeout(e);
|
|
1735
1735
|
Va.clear(), Ba.clear();
|
|
1736
|
-
}, Ja = () =>
|
|
1737
|
-
|
|
1736
|
+
}, Ja = () => K, Ya = 64, Xa = "\0", Za = 32, Qa = (e, ...t) => `${e}_${Mt("sha256").update(t.map(String).join(Xa)).digest("hex").slice(0, Za)}`, $a = (e) => e.length + 1 + Za, J = /* @__PURE__ */ new Map(), eo = (e, t) => {
|
|
1737
|
+
J.set(e, {
|
|
1738
1738
|
recorder: t.recorder,
|
|
1739
1739
|
tables: new Set(t.tables),
|
|
1740
1740
|
ownTables: new Set(t.ownTables)
|
|
1741
1741
|
});
|
|
1742
1742
|
}, to = (e) => {
|
|
1743
|
-
|
|
1744
|
-
}, no = () =>
|
|
1745
|
-
if (
|
|
1746
|
-
for (let t of
|
|
1743
|
+
J.delete(e);
|
|
1744
|
+
}, no = () => J.clear(), ro = (e) => {
|
|
1745
|
+
if (J.size === 0) return !1;
|
|
1746
|
+
for (let t of J.values()) if (!t.ownTables.has(e) && t.tables.has(e)) return !0;
|
|
1747
1747
|
return !1;
|
|
1748
1748
|
}, io = async (e, t) => {
|
|
1749
|
-
if (
|
|
1750
|
-
for (let [n, r] of
|
|
1749
|
+
if (J.size !== 0) {
|
|
1750
|
+
for (let [n, r] of J.entries()) if (!r.ownTables.has(t.table) && r.tables.has(t.table)) try {
|
|
1751
1751
|
await r.recorder(e, t);
|
|
1752
1752
|
} catch (e) {
|
|
1753
|
-
let r =
|
|
1753
|
+
let r = un(e);
|
|
1754
1754
|
throw r === void 0 ? e : Error(`write recorder '${n}' failed while recording a ${t.op} on '${t.table}': ${r}`, { cause: e });
|
|
1755
1755
|
}
|
|
1756
1756
|
}
|
|
1757
|
-
}, ao =
|
|
1757
|
+
}, ao = Dt.exponential({
|
|
1758
1758
|
start: 5e-4,
|
|
1759
1759
|
factor: 2,
|
|
1760
1760
|
count: 16
|
|
1761
|
-
}), oo =
|
|
1761
|
+
}), oo = A.counter("voltro_db_queries_total", { description: "Database operations executed, by dialect and operation kind." }), so = A.histogram("voltro_db_query_duration_seconds", ao, "Database operation duration in seconds, by dialect and operation kind."), co = A.counter("voltro_db_errors_total", { description: "Database operations that threw, by dialect and operation kind." }), lo = A.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." }), uo = A.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." }), fo = [], po = /* @__PURE__ */ new Map(), mo = /* @__PURE__ */ new Map(), ho = /* @__PURE__ */ new Map(), go = (e, t) => {
|
|
1762
1762
|
let n = `${e}\u0000${t}`, r = po.get(n);
|
|
1763
1763
|
if (r !== void 0) return r;
|
|
1764
|
-
let i = (n) =>
|
|
1764
|
+
let i = (n) => A.tagged(A.tagged(n, "dialect", e), "op", t), a = {
|
|
1765
1765
|
count: i(oo),
|
|
1766
1766
|
duration: i(so),
|
|
1767
1767
|
errors: i(co)
|
|
@@ -1773,7 +1773,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1773
1773
|
let n = Math.max(0, (yo.get(e) ?? 0) + t);
|
|
1774
1774
|
n === 0 ? yo.delete(e) : yo.set(e, n);
|
|
1775
1775
|
let r = mo.get(e);
|
|
1776
|
-
r === void 0 && (r =
|
|
1776
|
+
r === void 0 && (r = A.tagged(lo, "dialect", e), mo.set(e, r)), r.unsafeUpdate(n, fo);
|
|
1777
1777
|
}, xo = (e) => yo.get(e) ?? 0, So = (e) => {
|
|
1778
1778
|
let t = go(String(e.dialect), e.op);
|
|
1779
1779
|
t.count.unsafeUpdate(1, fo), t.duration.unsafeUpdate(e.durationMs / 1e3, fo), e.status === "error" && t.errors.unsafeUpdate(1, fo);
|
|
@@ -1801,7 +1801,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1801
1801
|
let n = Eo(t.warnIntervalMs), r = t.now ?? (() => Date.now()), i = /* @__PURE__ */ new Map();
|
|
1802
1802
|
return (t) => {
|
|
1803
1803
|
let a = `${t.dialect} ${t.reason}`, o = ho.get(a);
|
|
1804
|
-
o === void 0 && (o =
|
|
1804
|
+
o === void 0 && (o = A.tagged(A.tagged(uo, "dialect", String(t.dialect)), "reason", t.reason), ho.set(a, o)), o.unsafeUpdate(1, fo);
|
|
1805
1805
|
let s = `${t.table}\u0000${t.reason}`, c = i.get(s), l = c === void 0 || n > 0 && r() - c >= n, u = {
|
|
1806
1806
|
table: t.table,
|
|
1807
1807
|
dialect: String(t.dialect),
|
|
@@ -1816,20 +1816,20 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1816
1816
|
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);
|
|
1817
1817
|
};
|
|
1818
1818
|
}, Oo = (e) => {
|
|
1819
|
-
if (
|
|
1820
|
-
throw
|
|
1819
|
+
if (Et.isSuccess(e)) return e.value;
|
|
1820
|
+
throw O.squash(e.cause);
|
|
1821
1821
|
}, ko = "10 millis", Ao = 3, jo = async (e) => {
|
|
1822
|
-
let t = 0, n =
|
|
1822
|
+
let t = 0, n = k.suspend(() => {
|
|
1823
1823
|
let n = ++t;
|
|
1824
|
-
return e.withTransaction(
|
|
1825
|
-
if (
|
|
1826
|
-
let r = t.value, i =
|
|
1824
|
+
return e.withTransaction(k.flatMap(k.serviceOption(Nt), (t) => {
|
|
1825
|
+
if (j.isNone(t)) return k.fail(/* @__PURE__ */ Error(`${e.label}: TransactionConnection unexpectedly missing inside withTransaction.`));
|
|
1826
|
+
let r = t.value, i = k.tryPromise({
|
|
1827
1827
|
try: () => e.body(r, n),
|
|
1828
1828
|
catch: (e) => e
|
|
1829
1829
|
});
|
|
1830
|
-
return e.prepare === void 0 ? i :
|
|
1831
|
-
})).pipe(
|
|
1832
|
-
}), r =
|
|
1830
|
+
return e.prepare === void 0 ? i : k.flatMap(e.prepare(r), () => i);
|
|
1831
|
+
})).pipe(k.catchAllDefect((t) => e.isRetryable(t) ? k.fail(t) : k.die(t)));
|
|
1832
|
+
}), r = kt.exponential(ko).pipe(kt.compose(kt.recurs(Ao)), kt.whileInput(e.isRetryable)), i = n.pipe(k.retry(r), k.withSpan(e.span.name, { attributes: { ...e.span.attributes } }));
|
|
1833
1833
|
return Co(e.dialect, "transaction", async () => Oo(await e.runPromiseExit(e.wrapProgram === void 0 ? i : e.wrapProgram(i))));
|
|
1834
1834
|
}, Mo = async (e) => {
|
|
1835
1835
|
let t = Aa(), n = t === void 0 ? (e) => e() : (e) => ka(t, e), r = await jo({
|
|
@@ -1843,11 +1843,11 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1843
1843
|
}
|
|
1844
1844
|
});
|
|
1845
1845
|
return r.view.commitEvents(), r.result;
|
|
1846
|
-
}, No = class extends
|
|
1847
|
-
table:
|
|
1848
|
-
id:
|
|
1849
|
-
expected:
|
|
1850
|
-
actual:
|
|
1846
|
+
}, No = class extends M.TaggedError()("VersionConflict", {
|
|
1847
|
+
table: M.String,
|
|
1848
|
+
id: M.String,
|
|
1849
|
+
expected: M.Number,
|
|
1850
|
+
actual: M.NullOr(M.Number)
|
|
1851
1851
|
}) {}, Po = (e) => {
|
|
1852
1852
|
for (let [t, n] of Object.entries(e)) if (n?.definition?.versionColumn === !0) return t;
|
|
1853
1853
|
}, Fo = (e) => {
|
|
@@ -1870,19 +1870,19 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1870
1870
|
expected: e.expected,
|
|
1871
1871
|
actual: e.current
|
|
1872
1872
|
});
|
|
1873
|
-
}, Lo = 1, Ro = "voltro/expires", zo = () =>
|
|
1873
|
+
}, Lo = 1, Ro = "voltro/expires", zo = () => Ke({
|
|
1874
1874
|
id: Ro,
|
|
1875
1875
|
fields: { expiresAt: S().nullable() },
|
|
1876
1876
|
behaviors: { defaultWhere: () => "expiresAt IS NULL OR expiresAt > now()" }
|
|
1877
|
-
}), Bo = "voltro/localFirst", Vo = () =>
|
|
1877
|
+
}), Bo = "voltro/localFirst", Vo = () => Ke({
|
|
1878
1878
|
id: Bo,
|
|
1879
1879
|
fields: {}
|
|
1880
1880
|
}), Ho = (e) => e.appliedMixins.some((e) => e.id === Bo), Uo = (e) => {
|
|
1881
1881
|
let t = [];
|
|
1882
1882
|
for (let n of Object.values(e)) Ho(n) && t.push(n.tableName);
|
|
1883
1883
|
return t;
|
|
1884
|
-
}, Wo = class extends
|
|
1885
|
-
let i =
|
|
1884
|
+
}, Wo = class extends Tt.TaggedError("TableStreamError") {}, Go = 1e3, Ko = (e, t, n, r) => {
|
|
1885
|
+
let i = j.match(r, {
|
|
1886
1886
|
onNone: () => e.where,
|
|
1887
1887
|
onSome: (n) => e.where ? la(e.where, Ji(t, n)) : Ji(t, n)
|
|
1888
1888
|
});
|
|
@@ -1901,15 +1901,15 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1901
1901
|
};
|
|
1902
1902
|
}, qo = (e, t) => {
|
|
1903
1903
|
let n = t.pk ?? "id", r = t.chunkSize ?? Go;
|
|
1904
|
-
return
|
|
1905
|
-
let a =
|
|
1904
|
+
return At.paginateChunkEffect(j.none(), (i) => {
|
|
1905
|
+
let a = k.tryPromise({
|
|
1906
1906
|
try: () => e.query(Ko(t, n, r, i)),
|
|
1907
1907
|
catch: (e) => new Wo({
|
|
1908
1908
|
table: t.table,
|
|
1909
1909
|
cause: e
|
|
1910
1910
|
})
|
|
1911
1911
|
});
|
|
1912
|
-
return (t.retry ? a.pipe(
|
|
1912
|
+
return (t.retry ? a.pipe(k.retry(t.retry)) : a).pipe(k.map((e) => [wt.fromIterable(e), e.length === r && e.length > 0 ? j.some(j.some(e[e.length - 1][n])) : j.none()]));
|
|
1913
1913
|
});
|
|
1914
1914
|
}, Jo = (e) => {
|
|
1915
1915
|
let t = e.alpha ?? .5;
|
|
@@ -1946,9 +1946,9 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1946
1946
|
}, Xo = (e) => {
|
|
1947
1947
|
if (!Number.isInteger(e.dimensions) || e.dimensions <= 0) throw Error(`vectorEmbedding: dimensions must be a positive integer, got ${String(e.dimensions)}.`);
|
|
1948
1948
|
let t = e.as ?? "embedding", n = (t) => Yo(e, t);
|
|
1949
|
-
return
|
|
1949
|
+
return Ke({
|
|
1950
1950
|
id: "voltro/vectorEmbedding",
|
|
1951
|
-
fields: { [t]:
|
|
1951
|
+
fields: { [t]: De(e.dimensions) },
|
|
1952
1952
|
...e.index === !1 ? {} : { indexes: [{
|
|
1953
1953
|
fields: [t],
|
|
1954
1954
|
kind: "hnsw",
|
|
@@ -1963,17 +1963,17 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
1963
1963
|
beforeUpdate: n
|
|
1964
1964
|
}
|
|
1965
1965
|
});
|
|
1966
|
-
}, Zo = 63, Qo = "br_pr",
|
|
1966
|
+
}, Zo = 63, Qo = "br_pr", Y = class extends Error {
|
|
1967
1967
|
_tag = "BranchNameInvalid";
|
|
1968
1968
|
constructor(e) {
|
|
1969
1969
|
super(e), this.name = "BranchNameInvalid";
|
|
1970
1970
|
}
|
|
1971
1971
|
}, $o = (e, t) => {
|
|
1972
|
-
if (!Number.isInteger(t) || t < 0) throw new
|
|
1972
|
+
if (!Number.isInteger(t) || t < 0) throw new Y(`prNumber must be a non-negative integer, got ${String(t)}`);
|
|
1973
1973
|
let n = br(e);
|
|
1974
|
-
if (n.replace(/_/g, "") === "") throw new
|
|
1974
|
+
if (n.replace(/_/g, "") === "") throw new Y(`app slug '${e}' has no usable identifier characters`);
|
|
1975
1975
|
let r = `${Qo}${t}_${n}`;
|
|
1976
|
-
if (r.length > Zo) throw new
|
|
1976
|
+
if (r.length > Zo) throw new Y(`branch namespace '${r}' exceeds the ${Zo}-byte identifier limit — use a shorter app slug`);
|
|
1977
1977
|
return r;
|
|
1978
1978
|
}, es = (e) => e.startsWith(Qo), ts = {
|
|
1979
1979
|
requested: {
|
|
@@ -2006,7 +2006,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
2006
2006
|
if (n === void 0) throw new ns(e, t);
|
|
2007
2007
|
return n;
|
|
2008
2008
|
}, is = (e, t, n, r, i = [], a = []) => {
|
|
2009
|
-
if (n === "copy" && (r === void 0 || r === "")) throw new
|
|
2009
|
+
if (n === "copy" && (r === void 0 || r === "")) throw new Y("seed 'copy' requires a parentNamespace to snapshot from");
|
|
2010
2010
|
let o = [{
|
|
2011
2011
|
kind: "create-namespace",
|
|
2012
2012
|
detail: e
|
|
@@ -2036,7 +2036,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
2036
2036
|
detail: `run boot seeds into ${e}`
|
|
2037
2037
|
}), o;
|
|
2038
2038
|
}, as = (e) => {
|
|
2039
|
-
if (!es(e)) throw new
|
|
2039
|
+
if (!es(e)) throw new Y(`refusing to plan teardown of '${e}' — not a branch namespace`);
|
|
2040
2040
|
return [{
|
|
2041
2041
|
kind: "drop-namespace",
|
|
2042
2042
|
detail: e
|
|
@@ -2053,7 +2053,7 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
2053
2053
|
kind: "neon-branch-create",
|
|
2054
2054
|
detail: `${t.parentBranch ?? "main"} → ${e} (copy-on-write)`
|
|
2055
2055
|
}], ls = (e) => {
|
|
2056
|
-
if (!es(e)) throw new
|
|
2056
|
+
if (!es(e)) throw new Y(`refusing to plan teardown of '${e}' — not a branch namespace`);
|
|
2057
2057
|
return [{
|
|
2058
2058
|
kind: "neon-branch-delete",
|
|
2059
2059
|
detail: e
|
|
@@ -2101,13 +2101,13 @@ var Lt = (e) => typeof e == "string" && e !== "" ? e : null, Rt = async (e, t, n
|
|
|
2101
2101
|
}, ms = async (e, t, n) => {
|
|
2102
2102
|
let r = ds(t, e);
|
|
2103
2103
|
return t === "neon-cow" ? await n.neonBranchDelete(e) : await n.dropNamespace(e), r;
|
|
2104
|
-
}, hs = (e, t, n) => fs(e, t, n),
|
|
2104
|
+
}, hs = (e, t, n) => fs(e, t, n), X = (e) => `"${e.replace(/"/g, "\"\"")}"`, gs = {
|
|
2105
2105
|
cascade: "CASCADE",
|
|
2106
2106
|
restrict: "RESTRICT",
|
|
2107
2107
|
setNull: "SET NULL",
|
|
2108
2108
|
noAction: "NO ACTION"
|
|
2109
|
-
},
|
|
2110
|
-
let n = t.columns.map(
|
|
2109
|
+
}, Z = (e) => `'${e.replace(/'/g, "''")}'`, _s = (e, t) => {
|
|
2110
|
+
let n = t.columns.map(Z).join(", ");
|
|
2111
2111
|
return `DO $voltro_branch$
|
|
2112
2112
|
DECLARE derived name;
|
|
2113
2113
|
BEGIN
|
|
@@ -2116,11 +2116,11 @@ BEGIN
|
|
|
2116
2116
|
JOIN pg_class i ON i.oid = x.indexrelid
|
|
2117
2117
|
JOIN pg_class c ON c.oid = x.indrelid
|
|
2118
2118
|
JOIN pg_namespace nsp ON nsp.oid = c.relnamespace
|
|
2119
|
-
WHERE nsp.nspname = ${
|
|
2120
|
-
AND c.relname = ${
|
|
2119
|
+
WHERE nsp.nspname = ${Z(e)}
|
|
2120
|
+
AND c.relname = ${Z(t.table)}
|
|
2121
2121
|
AND NOT x.indisprimary
|
|
2122
2122
|
AND x.indisunique = ${t.unique ? "true" : "false"}
|
|
2123
|
-
AND i.relname <> ${
|
|
2123
|
+
AND i.relname <> ${Z(t.name)}
|
|
2124
2124
|
AND (
|
|
2125
2125
|
SELECT array_agg(att.attname::text ORDER BY k.ord)
|
|
2126
2126
|
FROM unnest(x.indkey::int2[]) WITH ORDINALITY AS k(attnum, ord)
|
|
@@ -2129,24 +2129,24 @@ BEGIN
|
|
|
2129
2129
|
LIMIT 1;
|
|
2130
2130
|
IF derived IS NOT NULL THEN
|
|
2131
2131
|
EXECUTE format('ALTER INDEX %I.%I RENAME TO %I',
|
|
2132
|
-
${
|
|
2132
|
+
${Z(e)}, derived, ${Z(t.name)});
|
|
2133
2133
|
END IF;
|
|
2134
2134
|
END
|
|
2135
2135
|
$voltro_branch$`;
|
|
2136
2136
|
}, vs = (e, t) => {
|
|
2137
2137
|
let n = t.onDelete === void 0 ? "" : ` ON DELETE ${gs[t.onDelete]}`, r = t.onUpdate === void 0 ? "" : ` ON UPDATE ${gs[t.onUpdate]}`;
|
|
2138
|
-
return `ALTER TABLE ${
|
|
2138
|
+
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}`;
|
|
2139
2139
|
}, ys = (e) => {
|
|
2140
2140
|
let t = () => {
|
|
2141
2141
|
throw Error("namespace branch executor: Neon ops require a neon-cow executor (use a Neon connection for copy-on-write branches)");
|
|
2142
2142
|
};
|
|
2143
2143
|
return {
|
|
2144
|
-
createNamespace: (t) => e.run(`CREATE SCHEMA IF NOT EXISTS ${
|
|
2145
|
-
createTable: (t, n) => e.run(`CREATE TABLE IF NOT EXISTS ${
|
|
2146
|
-
copyTable: (t, n, r) => e.run(`INSERT INTO ${
|
|
2144
|
+
createNamespace: (t) => e.run(`CREATE SCHEMA IF NOT EXISTS ${X(t)}`),
|
|
2145
|
+
createTable: (t, n) => e.run(`CREATE TABLE IF NOT EXISTS ${X(t)}.${X(n)} (LIKE ${X(n)} INCLUDING ALL)`),
|
|
2146
|
+
copyTable: (t, n, r) => e.run(`INSERT INTO ${X(n)}.${X(r)} SELECT * FROM ${X(t)}.${X(r)}`),
|
|
2147
2147
|
addForeignKey: (t, n) => e.run(vs(t, n)),
|
|
2148
2148
|
restoreIndexName: (t, n) => e.run(_s(t, n)),
|
|
2149
|
-
dropNamespace: (t) => e.run(`DROP SCHEMA IF EXISTS ${
|
|
2149
|
+
dropNamespace: (t) => e.run(`DROP SCHEMA IF EXISTS ${X(t)} CASCADE`),
|
|
2150
2150
|
neonBranchCreate: t,
|
|
2151
2151
|
neonBranchDelete: t
|
|
2152
2152
|
};
|
|
@@ -2204,7 +2204,7 @@ $voltro_branch$`;
|
|
|
2204
2204
|
return `(json:${t}->${n.join(".")}${r ? "::num" : ""})`;
|
|
2205
2205
|
}
|
|
2206
2206
|
return `(${e.expr})`;
|
|
2207
|
-
},
|
|
2207
|
+
}, Q = (e) => e.map(js), Ms = (e, t) => {
|
|
2208
2208
|
if (e.length !== t.length) return !1;
|
|
2209
2209
|
for (let n = 0; n < e.length; n++) if (js(e[n]) !== js(t[n])) return !1;
|
|
2210
2210
|
return !0;
|
|
@@ -2225,7 +2225,7 @@ $voltro_branch$`;
|
|
|
2225
2225
|
table: r,
|
|
2226
2226
|
redundant: n,
|
|
2227
2227
|
coveredBy: a,
|
|
2228
|
-
message: `'${r}' has two indexes on the same fields [${
|
|
2228
|
+
message: `'${r}' has two indexes on the same fields [${Q(i.fields).join(", ")}]: '${i.name}' and '${e.name}'. The B-tree engine builds both, costing write throughput + disk space for no read benefit. Drop '${n.name}' (or '${a.name}' if you prefer the other name). Applies to every supported dialect (Postgres / MySQL / MariaDB / MSSQL / SQLite).`
|
|
2229
2229
|
});
|
|
2230
2230
|
continue;
|
|
2231
2231
|
}
|
|
@@ -2234,13 +2234,13 @@ $voltro_branch$`;
|
|
|
2234
2234
|
table: r,
|
|
2235
2235
|
redundant: i,
|
|
2236
2236
|
coveredBy: e,
|
|
2237
|
-
message: `'${r}' index '${i.name}' on [${
|
|
2237
|
+
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).`
|
|
2238
2238
|
}) : Ns(e.fields, i.fields) && t.push({
|
|
2239
2239
|
kind: "redundant-prefix",
|
|
2240
2240
|
table: r,
|
|
2241
2241
|
redundant: e,
|
|
2242
2242
|
coveredBy: i,
|
|
2243
|
-
message: `'${r}' index '${e.name}' on [${
|
|
2243
|
+
message: `'${r}' index '${e.name}' on [${Q(e.fields).join(", ")}] is a leading prefix of '${i.name}' on [${Q(i.fields).join(", ")}]. Every B-tree dialect we support (Postgres / MySQL / MariaDB / MSSQL / SQLite) can serve a [${Q(e.fields).join(", ")}] query from '${i.name}' too via the leading-prefix rule, so '${e.name}' adds write cost without read benefit. Drop '${e.name}' — unless you specifically need a smaller index for cache locality on a write-heavy table (rare; profile first).`
|
|
2244
2244
|
});
|
|
2245
2245
|
}
|
|
2246
2246
|
}
|
|
@@ -2249,12 +2249,12 @@ $voltro_branch$`;
|
|
|
2249
2249
|
let t = [];
|
|
2250
2250
|
for (let n of e) t.push(...Ps(n));
|
|
2251
2251
|
return t;
|
|
2252
|
-
}, Is = "\x1B[", Ls = `${Is}38;2;245;158;11m`, Rs = `${Is}38;2;16;185;129m`, zs = (e, t) => `${e}${t}${
|
|
2253
|
-
let n = t.color ?? !0, r = t.indent ?? " ", i = (e) =>
|
|
2252
|
+
}, Is = "\x1B[", Ls = `${Is}38;2;245;158;11m`, Rs = `${Is}38;2;16;185;129m`, zs = (e, t) => `${e}${t}${N.reset}`, $ = (e, t, n) => e ? typeof t == "function" ? t(n) : zs(t, n) : n, Bs = (e, t = {}) => {
|
|
2253
|
+
let n = t.color ?? !0, r = t.indent ?? " ", i = (e) => $(n, N.dim, e.padEnd(11)), a = (e) => $(n, (e) => N.bold(N.brand(e)), e), o = (e) => $(n, N.brightRed24, e), s = (e) => $(n, Rs, e), c = (e) => $(n, Ls, e), l = (e) => $(n, N.dim, e), u = `${c("index audit")} ${l("·")} ${$(n, N.bold, e.kind)}`, d = e.redundant.fields.length, f = Q(e.coveredBy.fields.slice(d)), p = (e, t) => {
|
|
2254
2254
|
let n = e.slice(0, t), r = e.slice(t), i = [];
|
|
2255
2255
|
return n.length > 0 && i.push(s(`[${n.join(", ")}]`)), r.length > 0 && i.push(c(`+ [${r.join(", ")}]`)), i.join(" ");
|
|
2256
2256
|
}, m = [];
|
|
2257
|
-
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(
|
|
2257
|
+
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, N.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");
|
|
2258
2258
|
}, Vs = (e, { apply: t, undo: n }) => ({
|
|
2259
2259
|
name: e,
|
|
2260
2260
|
apply: t,
|
|
@@ -2271,97 +2271,115 @@ $voltro_branch$`;
|
|
|
2271
2271
|
};
|
|
2272
2272
|
}, Us = (e) => typeof e == "object" && !!e && "__migration" in e && e.__migration === !0, Ws = T("_voltro_migrations", {
|
|
2273
2273
|
id: b({ prefix: "mig" }),
|
|
2274
|
-
name:
|
|
2275
|
-
hash:
|
|
2276
|
-
status:
|
|
2274
|
+
name: C(),
|
|
2275
|
+
hash: C(),
|
|
2276
|
+
status: C(),
|
|
2277
2277
|
appliedAt: S().nullable(),
|
|
2278
|
-
durationMs:
|
|
2279
|
-
errorMessage:
|
|
2280
|
-
errorStack:
|
|
2281
|
-
workflowRunId:
|
|
2278
|
+
durationMs: D().nullable(),
|
|
2279
|
+
errorMessage: C().nullable(),
|
|
2280
|
+
errorStack: C().nullable(),
|
|
2281
|
+
workflowRunId: C().nullable(),
|
|
2282
2282
|
createdAt: S().default("now"),
|
|
2283
2283
|
updatedAt: S().default("now").onUpdate("now")
|
|
2284
2284
|
}).index(["status"]), Gs = T("_voltro_seeds", {
|
|
2285
2285
|
id: b({ prefix: "seed" }),
|
|
2286
|
-
name:
|
|
2287
|
-
lifecycle:
|
|
2288
|
-
fingerprint:
|
|
2289
|
-
cronSchedule:
|
|
2290
|
-
watchedTables:
|
|
2286
|
+
name: C(),
|
|
2287
|
+
lifecycle: C(),
|
|
2288
|
+
fingerprint: C(),
|
|
2289
|
+
cronSchedule: C().nullable(),
|
|
2290
|
+
watchedTables: x().nullable(),
|
|
2291
2291
|
nextRunAt: S().nullable(),
|
|
2292
|
-
lastRunStatus:
|
|
2292
|
+
lastRunStatus: C().nullable(),
|
|
2293
2293
|
lastRunAt: S().nullable(),
|
|
2294
|
-
lastRunDurationMs:
|
|
2295
|
-
lastRunRowsTouched:
|
|
2296
|
-
lastError:
|
|
2297
|
-
workflowRunId:
|
|
2294
|
+
lastRunDurationMs: D().nullable(),
|
|
2295
|
+
lastRunRowsTouched: D().nullable(),
|
|
2296
|
+
lastError: C().nullable(),
|
|
2297
|
+
workflowRunId: C().nullable(),
|
|
2298
2298
|
createdAt: S().default("now"),
|
|
2299
2299
|
updatedAt: S().default("now").onUpdate("now")
|
|
2300
2300
|
}).index(["lifecycle"]).index(["nextRunAt"]), Ks = T("_voltro_migration_plans", {
|
|
2301
2301
|
id: b({ prefix: "plan" }),
|
|
2302
|
-
fingerprint:
|
|
2303
|
-
liveFingerprint:
|
|
2304
|
-
operations:
|
|
2305
|
-
rollbackPlan:
|
|
2306
|
-
appliedBy:
|
|
2307
|
-
environment:
|
|
2308
|
-
source:
|
|
2309
|
-
onlineStrategy:
|
|
2310
|
-
durationMs:
|
|
2311
|
-
notes:
|
|
2302
|
+
fingerprint: C(),
|
|
2303
|
+
liveFingerprint: C().nullable(),
|
|
2304
|
+
operations: x(),
|
|
2305
|
+
rollbackPlan: x().nullable(),
|
|
2306
|
+
appliedBy: C(),
|
|
2307
|
+
environment: C(),
|
|
2308
|
+
source: C(),
|
|
2309
|
+
onlineStrategy: C().nullable(),
|
|
2310
|
+
durationMs: D(),
|
|
2311
|
+
notes: C().nullable(),
|
|
2312
2312
|
squashedAt: S().nullable(),
|
|
2313
2313
|
appliedAt: S().default("now"),
|
|
2314
2314
|
createdAt: S().default("now"),
|
|
2315
2315
|
updatedAt: S().default("now").onUpdate("now")
|
|
2316
2316
|
}).index(["fingerprint"]).index(["environment"]), qs = T("_voltro_idempotency", {
|
|
2317
2317
|
id: b({ prefix: "idem" }),
|
|
2318
|
-
scope:
|
|
2319
|
-
key:
|
|
2320
|
-
status:
|
|
2321
|
-
response:
|
|
2318
|
+
scope: C(),
|
|
2319
|
+
key: C(),
|
|
2320
|
+
status: C(),
|
|
2321
|
+
response: x().nullable(),
|
|
2322
2322
|
createdAt: S().default("now")
|
|
2323
2323
|
}).unique(["scope", "key"]).index(["createdAt"]), Js = T("_voltro_kv", {
|
|
2324
2324
|
id: b({ prefix: "kv" }),
|
|
2325
|
-
key:
|
|
2326
|
-
value:
|
|
2325
|
+
key: C().unique(),
|
|
2326
|
+
value: C().nullable(),
|
|
2327
2327
|
expiresAt: S().nullable(),
|
|
2328
2328
|
createdAt: S().default("now"),
|
|
2329
2329
|
updatedAt: S().default("now").onUpdate("now")
|
|
2330
2330
|
}).index(["expiresAt"]), Ys = T("_voltro_api_keys", {
|
|
2331
2331
|
id: b({ prefix: "apikey" }),
|
|
2332
|
-
tenantId:
|
|
2333
|
-
name:
|
|
2334
|
-
hashedKey:
|
|
2335
|
-
keyPrefix:
|
|
2336
|
-
scopes:
|
|
2332
|
+
tenantId: C().nullable(),
|
|
2333
|
+
name: C(),
|
|
2334
|
+
hashedKey: C().maxLength(64).unique(),
|
|
2335
|
+
keyPrefix: C(),
|
|
2336
|
+
scopes: x().nullable(),
|
|
2337
2337
|
lastUsedAt: S().nullable(),
|
|
2338
|
-
requestCount:
|
|
2338
|
+
requestCount: D().default(0),
|
|
2339
2339
|
expiresAt: S().nullable(),
|
|
2340
2340
|
revokedAt: S().nullable(),
|
|
2341
|
-
createdBy:
|
|
2342
|
-
onBehalfOf:
|
|
2343
|
-
metadata:
|
|
2341
|
+
createdBy: C().nullable(),
|
|
2342
|
+
onBehalfOf: C().nullable(),
|
|
2343
|
+
metadata: x().nullable(),
|
|
2344
2344
|
createdAt: S().default("now")
|
|
2345
2345
|
}).index("byApiKeyTenant", ["tenantId"]), Xs = [
|
|
2346
2346
|
Ws,
|
|
2347
2347
|
Gs,
|
|
2348
2348
|
Ks
|
|
2349
|
-
],
|
|
2349
|
+
], Zs = "_voltro_replace_in_progress", Qs = T(Zs, {
|
|
2350
|
+
id: b({ prefix: "repl" }),
|
|
2351
|
+
startedAt: S().default("now"),
|
|
2352
|
+
tables: C(),
|
|
2353
|
+
capture: C().nullable(),
|
|
2354
|
+
via: C()
|
|
2355
|
+
}), $s = (e) => {
|
|
2356
|
+
if (e.length !== 0) return `refusing to start: a destructive import did not finish.
|
|
2357
|
+
${e.map((e) => {
|
|
2358
|
+
let t = Number.isFinite(e.startedAt.getTime()) ? `${Math.max(0, Math.round((Date.now() - e.startedAt.getTime()) / 6e4))} minute(s) ago` : "at an unknown time";
|
|
2359
|
+
return ` - a \`replace\` over ${e.via} began emptying ${e.tables} table(s) ${t} and never reported finishing.\n` + (e.capture === null ? " NO capture was taken for that run, so the previous rows are not recoverable from here.\n Restore from your own backup." : ` The target's previous rows were captured first:\n ${e.capture}\n Restore them with: voltro data import ${e.capture} --mode replace`);
|
|
2360
|
+
}).join("\n")}\n
|
|
2361
|
+
A half-replaced database is indistinguishable from an empty one from the inside — every table
|
|
2362
|
+
exists, every constraint holds, and every query returns nothing without erroring. That is why
|
|
2363
|
+
this is a refusal and not a warning.
|
|
2364
|
+
|
|
2365
|
+
When the data is back, or you have decided the current state is correct, clear the marker:
|
|
2366
|
+
voltro data clear-replace-marker --yes`;
|
|
2367
|
+
}, ec = "id", tc = (e, t) => {
|
|
2350
2368
|
let n = p(e);
|
|
2351
2369
|
if (n === void 0) return t;
|
|
2352
|
-
let r = n.fields[
|
|
2353
|
-
if (r === void 0 || t[
|
|
2370
|
+
let r = n.fields[ec]?.idScheme;
|
|
2371
|
+
if (r === void 0 || t[ec] != null) return t;
|
|
2354
2372
|
if (r.kind === "numeric") {
|
|
2355
|
-
if (!(
|
|
2373
|
+
if (!(ec in t)) return t;
|
|
2356
2374
|
let e = { ...t };
|
|
2357
|
-
return delete e[
|
|
2375
|
+
return delete e[ec], e;
|
|
2358
2376
|
}
|
|
2359
|
-
let i =
|
|
2377
|
+
let i = Fe(r, e);
|
|
2360
2378
|
return i === null ? t : {
|
|
2361
2379
|
...t,
|
|
2362
|
-
[
|
|
2380
|
+
[ec]: i
|
|
2363
2381
|
};
|
|
2364
|
-
},
|
|
2382
|
+
}, nc = (e, t) => t.map((t) => tc(e, t)), rc = {
|
|
2365
2383
|
postgres: { maxBindParameters: 65535 },
|
|
2366
2384
|
mysql: { maxBindParameters: 65535 },
|
|
2367
2385
|
mariadb: { maxBindParameters: 65535 },
|
|
@@ -2371,49 +2389,49 @@ $voltro_branch$`;
|
|
|
2371
2389
|
},
|
|
2372
2390
|
sqlite: { maxBindParameters: 32766 },
|
|
2373
2391
|
turso: { maxBindParameters: 32766 }
|
|
2374
|
-
},
|
|
2392
|
+
}, ic = (e) => rc[e], ac = (e) => {
|
|
2375
2393
|
let t = /* @__PURE__ */ new Set();
|
|
2376
2394
|
for (let n of e) for (let e of Object.keys(n)) t.add(e);
|
|
2377
2395
|
return t.size;
|
|
2378
|
-
},
|
|
2396
|
+
}, oc = (e, t) => {
|
|
2379
2397
|
if (t === void 0 || e.length === 0) return [e];
|
|
2380
|
-
let n = Math.max(1,
|
|
2398
|
+
let n = Math.max(1, ac(e)), r = Math.floor(t.maxBindParameters / n), i = t.maxRowsPerStatement ?? Infinity, a = Math.max(1, Math.min(r, i));
|
|
2381
2399
|
if (e.length <= a) return [e];
|
|
2382
2400
|
let o = [];
|
|
2383
2401
|
for (let t = 0; t < e.length; t += a) o.push(e.slice(t, t + a));
|
|
2384
2402
|
return o;
|
|
2385
|
-
},
|
|
2403
|
+
}, sc = (e, t) => {
|
|
2386
2404
|
let n = [], r = t;
|
|
2387
2405
|
for (let [t, i] of Object.entries(e.fields)) {
|
|
2388
2406
|
let e = i;
|
|
2389
2407
|
e.nullable || e.hasDefault || e.idScheme !== void 0 || e.generatedAs !== void 0 || (r[t] === void 0 || r[t] === null) && n.push(t);
|
|
2390
2408
|
}
|
|
2391
2409
|
return n;
|
|
2392
|
-
},
|
|
2410
|
+
}, cc = (e, t) => {
|
|
2393
2411
|
let n = t;
|
|
2394
2412
|
return e.filter((e) => n[e] === void 0 || n[e] === null);
|
|
2395
|
-
},
|
|
2413
|
+
}, lc = (e, t, n) => e.insert(t.tableName, n), uc = (e, t, n, r) => e.upsert(t.tableName, n, {
|
|
2396
2414
|
conflictColumns: r.conflictColumns,
|
|
2397
2415
|
...r.update === void 0 ? {} : { update: r.update }
|
|
2398
|
-
}),
|
|
2416
|
+
}), dc = (e, t, n, r) => e.updateMany(t.tableName, n, { where: r.where }), fc = 512, pc = (e) => {
|
|
2399
2417
|
e.setMaxListeners(512);
|
|
2400
|
-
},
|
|
2418
|
+
}, mc = (e, t, n) => ({
|
|
2401
2419
|
_tag: "PrimaryKeyConflictError",
|
|
2402
2420
|
table: e,
|
|
2403
2421
|
key: t,
|
|
2404
2422
|
cause: n
|
|
2405
|
-
}),
|
|
2423
|
+
}), hc = (e) => typeof e == "object" && !!e && e._tag === "PrimaryKeyConflictError", gc = {
|
|
2406
2424
|
postgres: 5432,
|
|
2407
2425
|
mysql: 3306,
|
|
2408
2426
|
mariadb: 3306,
|
|
2409
2427
|
mssql: 1433
|
|
2410
|
-
},
|
|
2428
|
+
}, _c = /* @__PURE__ */ new Set([
|
|
2411
2429
|
"localhost",
|
|
2412
2430
|
"127.0.0.1",
|
|
2413
2431
|
"::1",
|
|
2414
2432
|
"[::1]",
|
|
2415
2433
|
"0.0.0.0"
|
|
2416
|
-
]),
|
|
2434
|
+
]), vc = (e) => {
|
|
2417
2435
|
let t = e.host, n = e.port, r = e.database;
|
|
2418
2436
|
if (e.url !== void 0 && e.url !== "") try {
|
|
2419
2437
|
let i = new URL(e.url);
|
|
@@ -2422,29 +2440,29 @@ $voltro_branch$`;
|
|
|
2422
2440
|
return;
|
|
2423
2441
|
}
|
|
2424
2442
|
if (t === void 0 || t === "" || r === void 0 || r === "") return;
|
|
2425
|
-
let i = n ??
|
|
2443
|
+
let i = n ?? gc[(e.dialect ?? "").toLowerCase()];
|
|
2426
2444
|
if (i === void 0 || !Number.isFinite(i)) return;
|
|
2427
2445
|
let a = t.toLowerCase();
|
|
2428
2446
|
return {
|
|
2429
|
-
host:
|
|
2447
|
+
host: _c.has(a) ? "localhost" : a,
|
|
2430
2448
|
port: i,
|
|
2431
2449
|
database: r.toLowerCase()
|
|
2432
2450
|
};
|
|
2433
|
-
},
|
|
2434
|
-
let t =
|
|
2435
|
-
if (t !== void 0) return
|
|
2436
|
-
},
|
|
2451
|
+
}, yc = (e) => {
|
|
2452
|
+
let t = vc(e);
|
|
2453
|
+
if (t !== void 0) return Mt("sha256").update(`${t.host}\u0000${t.port}\u0000${t.database}`).digest("hex").slice(0, 32);
|
|
2454
|
+
}, bc = (e, t) => e === void 0 || t === void 0 ? "unknown" : e === t ? "same" : "different", xc = {
|
|
2437
2455
|
app: 3,
|
|
2438
2456
|
plugin: 2,
|
|
2439
2457
|
framework: 1
|
|
2440
|
-
},
|
|
2458
|
+
}, Sc = /* @__PURE__ */ new Map(), Cc = [], wc = () => [...Cc], Tc = (e) => {
|
|
2441
2459
|
if (!e.table || !e.timeColumn) throw Error("registerRetention: table + timeColumn are required");
|
|
2442
2460
|
if (!Number.isFinite(e.ttlMs) || e.ttlMs <= 0) throw Error(`registerRetention(${e.table}): ttlMs must be a positive number`);
|
|
2443
|
-
let t = e.source ?? "app", n =
|
|
2461
|
+
let t = e.source ?? "app", n = Sc.get(e.table);
|
|
2444
2462
|
if (n !== void 0) {
|
|
2445
2463
|
let r = n.source ?? "app", i = n.ttlMs !== e.ttlMs || n.where !== void 0 != (e.where !== void 0);
|
|
2446
|
-
if (
|
|
2447
|
-
i &&
|
|
2464
|
+
if (xc[t] < xc[r]) {
|
|
2465
|
+
i && Cc.push({
|
|
2448
2466
|
table: e.table,
|
|
2449
2467
|
kept: {
|
|
2450
2468
|
source: r,
|
|
@@ -2457,7 +2475,7 @@ $voltro_branch$`;
|
|
|
2457
2475
|
});
|
|
2458
2476
|
return;
|
|
2459
2477
|
}
|
|
2460
|
-
i && r !== t &&
|
|
2478
|
+
i && r !== t && Cc.push({
|
|
2461
2479
|
table: e.table,
|
|
2462
2480
|
kept: {
|
|
2463
2481
|
source: t,
|
|
@@ -2469,35 +2487,35 @@ $voltro_branch$`;
|
|
|
2469
2487
|
}
|
|
2470
2488
|
});
|
|
2471
2489
|
}
|
|
2472
|
-
|
|
2490
|
+
Sc.set(e.table, {
|
|
2473
2491
|
...e,
|
|
2474
2492
|
source: t
|
|
2475
2493
|
});
|
|
2476
|
-
},
|
|
2477
|
-
|
|
2478
|
-
},
|
|
2494
|
+
}, Ec = () => [...Sc.values()], Dc = () => {
|
|
2495
|
+
Sc.clear(), Cc.length = 0;
|
|
2496
|
+
}, Oc = async (e, t, n, r = 2e4) => {
|
|
2479
2497
|
let i = new Date(t - e.ttlMs), a = 0;
|
|
2480
2498
|
for (;;) {
|
|
2481
2499
|
let t = await n(e.table, e.timeColumn, i, r, e.where);
|
|
2482
2500
|
if (a += t, t < r) break;
|
|
2483
2501
|
}
|
|
2484
2502
|
return a;
|
|
2485
|
-
},
|
|
2503
|
+
}, kc = (e, t) => {
|
|
2486
2504
|
let n = Number(e ?? String(t));
|
|
2487
2505
|
return (Number.isFinite(n) && n > 0 ? n : t) * 36e5;
|
|
2488
|
-
},
|
|
2506
|
+
}, Ac = "_voltro_cdc_offsets", jc = T(Ac, {
|
|
2489
2507
|
id: b({ prefix: "cdcoff" }),
|
|
2490
|
-
replicaId:
|
|
2491
|
-
streamName:
|
|
2492
|
-
binlogFile:
|
|
2493
|
-
binlogPosition:
|
|
2508
|
+
replicaId: C(),
|
|
2509
|
+
streamName: C(),
|
|
2510
|
+
binlogFile: C(),
|
|
2511
|
+
binlogPosition: C(),
|
|
2494
2512
|
updatedAt: S()
|
|
2495
|
-
}).index(["replicaId"]),
|
|
2513
|
+
}).index(["replicaId"]), Mc = T(Ac, {
|
|
2496
2514
|
id: b({ prefix: "cdcoff" }),
|
|
2497
|
-
replicaId:
|
|
2498
|
-
streamName:
|
|
2499
|
-
ctVersion:
|
|
2515
|
+
replicaId: C(),
|
|
2516
|
+
streamName: C(),
|
|
2517
|
+
ctVersion: C(),
|
|
2500
2518
|
updatedAt: S()
|
|
2501
|
-
}).index(["replicaId"]),
|
|
2519
|
+
}).index(["replicaId"]), Nc = "postgres";
|
|
2502
2520
|
//#endregion
|
|
2503
|
-
export {
|
|
2521
|
+
export { Re as AUTO_FILLED_COLUMNS, rc as BULK_INSERT_LIMITS, Y as BranchNameInvalid, ns as BranchTransitionInvalid, Ac as CDC_OFFSETS_TABLE, fc as CHANGE_LISTENER_CEILING, ve as ColumnBuilder, we as DEFAULT_ACQUIRE_TIMEOUT_MS, wo as DEFAULT_EAGER_FALLBACK_WARN_INTERVAL_MS, Bn as DEFAULT_SUBJECT_GRAPH_DEPTH, Vt as ENCRYPTED_PREFIX, Nc as ENGINE, rr as EagerCardinalityError, Ge as FILE_MIGRATION_PATTERN, lt as FRAMEWORK_LIVE_TABLES, Ht as FieldDecryptionError, Ya as ID_COLUMN_MAX_LENGTH, Lo as INITIAL_VERSION, aa as MATCHES_NO_ROWS, Be as MAX_IDENTIFIER_LENGTH, Zs as REPLACE_IN_PROGRESS_TABLE, Pt as SqlClient, Wo as TableStreamError, _r as TenantNamespaceInvalid, gr as TenantNamespaceUnresolved, xs as TenantRegionUnavailable, bs as TenantResidencyUnresolved, Ro as VOLTRO_EXPIRES_MIXIN_ID, Bo as VOLTRO_LOCAL_FIRST_MIXIN_ID, No as VersionConflict, rt as WARN_IDENTIFIER_LENGTH, Ys as _voltroApiKeysTable, jc as _voltroCdcOffsetsTable, qs as _voltroIdempotencyTable, Js as _voltroKvTable, Ks as _voltroMigrationPlansTable, Ws as _voltroMigrationsTable, Mc as _voltroMssqlCdcOffsetsTable, Qs as _voltroReplaceInProgressTable, Gs as _voltroSeedsTable, Gi as actorsTable, hs as admitBranch, bt as allEnumRenames, Ln as allRegisteredRelations, h as allRegisteredTables, la as and, u as array, na as arrayContains, ia as arrayHas, ra as arrayOverlaps, ar as attachEagerLoads, ja as attributionFields, Fa as attributionKey, Fs as auditAllTableIndexes, Ps as auditTableIndexes, pt as avg, yt as avgOver, Wa as beginLocalWrite, c as bigint, ks as bindResidentStore, ue as boolean, $o as branchNamespaceName, ic as bulkInsertLimitsFor, Ye as bytes, Ea as changeDelete, wa as changeInsert, Da as changeSoftDelete, Ta as changeUpdate, oc as chunkRowsForInsert, Ra as claimPendingAttribution, sn as classifyConstraintViolation, Ne as clearEnumRenames, qa as clearPendingAttribution, zn as clearRelationsRegistry, Ts as clearResidencyConfig, Dc as clearRetentions, ye as clearTableRegistry, no as clearWriteRecorders, Tr as coercePredicateValue, Er as coercePredicateValues, xa as collectSubqueries, Me as column, pn as columnSchema, ac as columnsPerRow, Br as compileEagerJson, L as compilePredicate, Dr as compileRawFragment, zr as compileSelect, Yo as computeEmbedding, yc as connectionIdentity, ea as contains, _t as count, he as countDistinct, n as crdtManagedColumns, qe as crdtText, Aa as currentWriteAttribution, a as databaseHandle, oe as date, ce as dbEnum, vo as dbMetricTagCacheSizeForTests, xo as dbOperationsInFlight, fe as decimal, vt as declareEnumRename, qt as decodeFieldValue, er as decodeRowsFromSchema, Qt as decryptFieldsOnRead, Hs as defineMigration, Ke as defineMixin, st as defineSeed, ht as denseRank, qn as deriveSubjectGraph, ct as deriveTypeIdPrefix, Qa as derivedRowId, $a as derivedRowIdLength, un as describeDriverError, dn as describeRowBindings, Bt as deserializeArraysOnRead, $e as drainIdentifierWarnings, f as dropped, Gt as encodeFieldValue, nr as encodeRowForSchema, Zt as encryptFieldsForWrite, Xt as encryptedColumnsOf, Ga as endLocalWrite, fs as enforceBranchLimits, Se as ensureTableRegistered, Ki as eq, Or as escapeLike, ba as evaluatePredicate, _e as except, ga as exists, zo as expires, Ca as externalChangeEvent, rn as extractDbCause, Pe as fireSchemaChangeSeeds, Xe as fireTenantCreateSeeds, Bs as formatIndexAuditIssue, Jn as formatSubjectGraph, Xs as frameworkTables, Fe as generateId, ft as generateSnowflake, te as geography, y as geometry, ge as getEnumRenames, In as getRelation, Fn as getRelations, ws as getResidencyConfig, p as getTable, Ji as gt, Yi as gte, hr as hasEagerLoads, Jo as hybridSearch, b as id, Qi as inSet, ma as inSubquery, En as inferForeignKey, lc as insertRow, D as integer, $s as interruptedReplaceRefusal, l as intersect, i as interval, es as isBranchNamespace, xn as isEmptyRelationsSpec, Wt as isEncrypted, Ut as isFieldDecryptionError, Ae as isFileMigration, cn as isForeignKeyViolation, et as isFrameworkOwnedLiveTable, Ho as isLocalFirst, Us as isMigrationDefinition, Ee as isMysqlFamily, os as isNeonConnection, sa as isNotNull, oa as isNull, hc as isPrimaryKeyConflictError, ln as isQueryTimeout, Jt as isRawEncoding, Ds as isRegionServable, Sn as isRelationsSpec, dt as isSeedDefinition, pe as isSqliteFamily, re as isTableReactive, Qe as isView, x as json, fa as jsonField, ut as jsonIndex, s as lag, le as lead, wc as listRetentionConflicts, Ec as listRetentions, Vo as localFirst, Uo as localFirstTables, Xi as lt, Zi as lte, Do as makeEagerFallbackReporter, ys as makeNamespaceBranchExecutor, wn as many, Tn as manyToMany, g as materializeFields, Je as max, tt as migration, t as min, cc as missingConflictColumns, sc as missingRequiredColumns, je as mixin, qi as neq, rs as nextBranchState, vc as normaliseTarget, da as not, _a as notExists, $i as notInSet, ha as notInSubquery, be as numeric, Co as observeDbOp, Cn as one, ir as oneCardinalityMessage, ua as or, w as orderClausesOf, ae as paginateBy, se as paginateById, Ja as pendingAttributionCount, us as planBranch, is as planBranchProvision, as as planBranchTeardown, ds as planBranchTeardownFor, cs as planNeonBranchProvision, ls as planNeonBranchTeardown, Fo as planVersionedUpdate, o as pluginRef, gt as pluginRefSpecOf, mc as primaryKeyConflictError, ps as provisionBranch, As as provisionResidentTenant, Sr as qualifyTable, de as queryFor, Ue as queryForView, e as quoteIdent, pc as raiseChangeListenerCeiling, d as rank, Ce as raw, m as readableByColumns, v as real, So as recordDbOp, ro as recordsTable, at as reference, Vi as registerCoreTables, Pn as registerDiscoveredRelations, La as registerPendingAttribution, Nn as registerRelations, Tc as registerRetention, it as registerTable, eo as registerWriteRecorder, bn as relations, Ui as requireActors, _ as requireTable, Wi as requireTenants, _o as resetDbMetricTagCacheForTests, Le as resetSnowflake, Os as residentPlacement, It as resolveActorSnapshot, ss as resolveBranchMechanism, Eo as resolveEagerFallbackWarnIntervalMs, Ka as resolveEchoAttribution, ee as resolveFullTextIndex, Ze as resolveIdScheme, nt as resolveMixinGraph, Es as resolveTenantHome, xr as resolveTenantNamespace, kc as retentionTtlMsFromEnv, ie as rowNumber, mn as rowSchema, jo as runRetryingTransaction, Mo as runStoreTransaction, ka as runWithWriteAttribution, io as runWriteRecorders, bc as sameDatabase, br as sanitizeIdentifierFragment, zt as serializeArraysForWrite, ne as serverOnlyColumns, Cs as setResidencyConfig, Ie as setSchemaChangeSeedHook, ze as setTenantCreateSeedHook, Oo as settleTransactionExit, Io as settleVersionedUpdate, ca as spatialPredicate, tc as stampGeneratedId, nc as stampGeneratedIds, ta as startsWith, qo as streamTable, me as sum, xt as sumOver, Oc as sweepRetention, T as table, ms as teardownBranch, C as text, S as timestamp, St as timestampMs, Ct as timestampMsOrNull, r as union, xe as unionAll, Te as unregisterTable, to as unregisterWriteRecorder, dc as updateManyRow, uc as upsertRow, We as validateColumnName, He as validateIndexName, Rn as validateRegisteredRelations, An as validateRelationConfig, ke as validateTableName, mt as validateTypeIdPrefix, De as vector, ot as vectorDistanceToOpclass, Xo as vectorEmbedding, Po as versionColumnOf, Ve as view, Oe as viewSql, Sa as walkLeaves, Ma as withCapturedAttribution };
|