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