@voltro/database 0.25.0 → 0.27.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 +541 -0
- package/dist/{frameworkLiveTables-BQwB8K6R.js → frameworkLiveTables-CS_Hyhgz.js} +162 -147
- package/dist/index.d.ts +100 -0
- package/dist/index.js +570 -547
- package/dist/sql.d.ts +27 -0
- package/dist/sql.js +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,17 +1,40 @@
|
|
|
1
|
-
import { $ as e, A as t, At as n, B as r, C as i, Ct as a, D as o, Dt as s, E as c, Et as l, F as u, Ft as d, G as f, H as p, I as m, It as h, J as g, K as _, L as ee,
|
|
2
|
-
import { timestampMs as
|
|
3
|
-
import { Cause as
|
|
4
|
-
import { AsyncLocalStorage as
|
|
1
|
+
import { $ as e, A as t, At as n, B as r, C as i, Ct as a, D as o, Dt as s, E as c, Et as l, F as u, Ft as d, G as f, H as p, I as m, It as h, J as g, K as _, L as ee, Lt as v, M as te, Mt as y, N as b, Nt as ne, O as x, Ot as re, P as ie, Pt as ae, Q as oe, R as S, Rt as se, S as ce, St as le, T as ue, Tt as de, U as fe, V as pe, W as me, X as he, Y as ge, Z as _e, _ as ve, _t as ye, a as be, at as xe, b as Se, bt as Ce, c as we, ct as Te, d as Ee, dt as De, et as Oe, f as ke, ft as Ae, g as je, gt as Me, h as Ne, ht as Pe, i as Fe, it as Ie, j as Le, jt as Re, k as ze, kt as C, l as Be, lt as Ve, m as He, mt as Ue, n as We, nt as Ge, o as Ke, ot as qe, p as Je, pt as Ye, q as Xe, rt as Ze, s as w, st as Qe, t as $e, tt as et, u as tt, ut as nt, v as rt, vt as it, w as at, wt as ot, x as st, xt as ct, y as lt, yt as ut, z as dt } from "./frameworkLiveTables-CS_Hyhgz.js";
|
|
2
|
+
import { timestampMs as ft, timestampMsOrNull as pt } from "./wire.js";
|
|
3
|
+
import { Cause as mt, Chunk as ht, Data as gt, Effect as _t, Exit as vt, Option as T, Schema as E, Stream as yt } from "effect";
|
|
4
|
+
import { AsyncLocalStorage as bt } from "node:async_hooks";
|
|
5
5
|
import { ansi as D } from "@voltro/logger";
|
|
6
|
-
import { SqlClient as
|
|
7
|
-
//#region src/
|
|
8
|
-
var
|
|
6
|
+
import { SqlClient as xt } from "@effect/sql";
|
|
7
|
+
//#region src/actorSnapshot.ts
|
|
8
|
+
var St = (e) => typeof e == "string" && e !== "" ? e : null, Ct = async (e, t, n) => {
|
|
9
|
+
if (!(t == null || t === "")) try {
|
|
10
|
+
let r = (await e.query({
|
|
11
|
+
table: "actors",
|
|
12
|
+
predicate: {
|
|
13
|
+
kind: "eq",
|
|
14
|
+
column: "id",
|
|
15
|
+
value: t
|
|
16
|
+
},
|
|
17
|
+
order: void 0,
|
|
18
|
+
take: 1,
|
|
19
|
+
skip: void 0,
|
|
20
|
+
projection: void 0
|
|
21
|
+
}))[0];
|
|
22
|
+
return r === void 0 ? void 0 : {
|
|
23
|
+
id: t,
|
|
24
|
+
type: St(r.kind) ?? n,
|
|
25
|
+
displayName: St(r.displayName),
|
|
26
|
+
email: St(r.email)
|
|
27
|
+
};
|
|
28
|
+
} catch {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
}, wt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqlite", Tt = (e) => {
|
|
9
32
|
let t = [];
|
|
10
33
|
for (let [n, r] of Object.entries(e.fields)) r.type === "array" && t.push(n);
|
|
11
34
|
return t;
|
|
12
|
-
},
|
|
13
|
-
if (!
|
|
14
|
-
let r =
|
|
35
|
+
}, Et = (e, t, n) => {
|
|
36
|
+
if (!wt(n) || !t) return e;
|
|
37
|
+
let r = Tt(t);
|
|
15
38
|
if (r.length === 0) return e;
|
|
16
39
|
let i = { ...e };
|
|
17
40
|
for (let e of r) {
|
|
@@ -19,9 +42,9 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
19
42
|
Array.isArray(t) && (i[e] = JSON.stringify(t));
|
|
20
43
|
}
|
|
21
44
|
return i;
|
|
22
|
-
},
|
|
23
|
-
if (!
|
|
24
|
-
let r =
|
|
45
|
+
}, Dt = (e, t, n) => {
|
|
46
|
+
if (!wt(n) || !t) return e;
|
|
47
|
+
let r = Tt(t);
|
|
25
48
|
return r.length === 0 ? e : e.map((e) => {
|
|
26
49
|
let t;
|
|
27
50
|
for (let n of r) {
|
|
@@ -33,7 +56,7 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
33
56
|
}
|
|
34
57
|
return t ?? e;
|
|
35
58
|
});
|
|
36
|
-
},
|
|
59
|
+
}, Ot = "enc:v1:", kt = class extends Error {
|
|
37
60
|
_tag = "FieldDecryptionError";
|
|
38
61
|
table;
|
|
39
62
|
column;
|
|
@@ -41,33 +64,33 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
41
64
|
constructor(e) {
|
|
42
65
|
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;
|
|
43
66
|
}
|
|
44
|
-
},
|
|
67
|
+
}, At = (e) => typeof e == "object" && !!e && e._tag === "FieldDecryptionError", jt = (e) => typeof e == "string" && e.startsWith("enc:v1:"), Mt = (e) => {
|
|
45
68
|
let t = [];
|
|
46
69
|
for (let [n, r] of Object.entries(e.fields)) r.encrypted === !0 && t.push(n);
|
|
47
70
|
return t;
|
|
48
|
-
},
|
|
71
|
+
}, Nt = (e, t, n) => {
|
|
49
72
|
if (!t) return e;
|
|
50
|
-
let r =
|
|
73
|
+
let r = Mt(t);
|
|
51
74
|
if (r.length === 0) return e;
|
|
52
75
|
let i = { ...e };
|
|
53
76
|
for (let e of r) {
|
|
54
77
|
let r = i[e];
|
|
55
|
-
if (!(r == null ||
|
|
78
|
+
if (!(r == null || jt(r))) {
|
|
56
79
|
if (!n) throw Error(`column "${t.tableName ?? "?"}.${e}" is .encrypted() but no field cipher is registered — wire @voltro/plugin-governance's fieldEncryption (key via the Secrets-Resolver)`);
|
|
57
80
|
i[e] = n.encrypt(JSON.stringify(r));
|
|
58
81
|
}
|
|
59
82
|
}
|
|
60
83
|
return i;
|
|
61
|
-
},
|
|
84
|
+
}, Pt = (e, t, n, r) => {
|
|
62
85
|
if (!t) return e;
|
|
63
|
-
let i =
|
|
86
|
+
let i = Mt(t);
|
|
64
87
|
if (i.length === 0 || !n) return e;
|
|
65
88
|
let a = r?.onError ?? "throw", o = t.tableName ?? "?";
|
|
66
89
|
return e.map((e) => {
|
|
67
90
|
let t;
|
|
68
91
|
for (let s of i) {
|
|
69
92
|
let i = e[s];
|
|
70
|
-
if (
|
|
93
|
+
if (jt(i)) {
|
|
71
94
|
t ??= { ...e };
|
|
72
95
|
try {
|
|
73
96
|
t[s] = JSON.parse(n.decrypt(i));
|
|
@@ -81,7 +104,7 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
81
104
|
});
|
|
82
105
|
continue;
|
|
83
106
|
}
|
|
84
|
-
throw new
|
|
107
|
+
throw new kt({
|
|
85
108
|
table: o,
|
|
86
109
|
column: s,
|
|
87
110
|
reason: n
|
|
@@ -91,7 +114,7 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
91
114
|
}
|
|
92
115
|
return t ?? e;
|
|
93
116
|
});
|
|
94
|
-
},
|
|
117
|
+
}, Ft = (e) => {
|
|
95
118
|
let t = (() => {
|
|
96
119
|
switch (e.type) {
|
|
97
120
|
case "id":
|
|
@@ -103,7 +126,7 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
103
126
|
case "decimal": return E.Number;
|
|
104
127
|
case "boolean": return E.Boolean;
|
|
105
128
|
case "timestamp":
|
|
106
|
-
case "date": return
|
|
129
|
+
case "date": return ft;
|
|
107
130
|
case "bigint": return E.BigInt;
|
|
108
131
|
case "bytes": return E.Uint8ArrayFromSelf;
|
|
109
132
|
case "array": return E.Array(E.Unknown);
|
|
@@ -112,41 +135,41 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
112
135
|
}
|
|
113
136
|
})();
|
|
114
137
|
return e.nullable === !0 ? E.NullOr(t) : t;
|
|
115
|
-
},
|
|
138
|
+
}, It = (e, t) => {
|
|
116
139
|
let n = new Set(t?.omit ?? []), r = {};
|
|
117
|
-
for (let [t, i] of Object.entries(e.fields)) n.has(t) || (r[t] =
|
|
140
|
+
for (let [t, i] of Object.entries(e.fields)) n.has(t) || (r[t] = Ft(i));
|
|
118
141
|
return E.Struct(r);
|
|
119
|
-
},
|
|
142
|
+
}, Lt = (e) => typeof e == "function" ? e : () => e, Rt = (e, t) => ({
|
|
120
143
|
kind: "one",
|
|
121
|
-
target:
|
|
144
|
+
target: Lt(e),
|
|
122
145
|
...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
|
|
123
146
|
...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
|
|
124
|
-
}),
|
|
147
|
+
}), zt = (e, t) => ({
|
|
125
148
|
kind: "many",
|
|
126
|
-
target:
|
|
149
|
+
target: Lt(e),
|
|
127
150
|
...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
|
|
128
151
|
...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
|
|
129
|
-
}),
|
|
152
|
+
}), Bt = (e, t) => ({
|
|
130
153
|
kind: "manyToMany",
|
|
131
|
-
target:
|
|
132
|
-
through:
|
|
154
|
+
target: Lt(e),
|
|
155
|
+
through: Lt(t.through),
|
|
133
156
|
sourceKey: t.sourceKey,
|
|
134
157
|
targetKey: t.targetKey
|
|
135
|
-
}),
|
|
136
|
-
one:
|
|
137
|
-
many:
|
|
138
|
-
manyToMany:
|
|
139
|
-
},
|
|
158
|
+
}), Vt = {
|
|
159
|
+
one: Rt,
|
|
160
|
+
many: zt,
|
|
161
|
+
manyToMany: Bt
|
|
162
|
+
}, Ht = (e, t) => {
|
|
140
163
|
let n = typeof e == "function" ? e : () => e;
|
|
141
164
|
return {
|
|
142
165
|
source: n,
|
|
143
|
-
relations: t(
|
|
166
|
+
relations: t(Vt, n())
|
|
144
167
|
};
|
|
145
|
-
},
|
|
168
|
+
}, Ut = (e) => {
|
|
146
169
|
if (typeof e != "object" || !e) return !1;
|
|
147
170
|
let t = e;
|
|
148
171
|
return typeof t.source != "function" || typeof t.relations != "object" || t.relations === null ? !1 : Object.keys(t.relations).length === 0;
|
|
149
|
-
},
|
|
172
|
+
}, Wt = (e) => {
|
|
150
173
|
if (typeof e != "object" || !e) return !1;
|
|
151
174
|
let t = e;
|
|
152
175
|
if (typeof t.source != "function" || typeof t.relations != "object" || t.relations === null) return !1;
|
|
@@ -155,35 +178,35 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
155
178
|
let t = e?.kind;
|
|
156
179
|
return t === "one" || t === "many" || t === "manyToMany";
|
|
157
180
|
});
|
|
158
|
-
},
|
|
181
|
+
}, Gt = Rt, Kt = zt, qt = Bt, O = (e, t, n) => {
|
|
159
182
|
let r = [];
|
|
160
183
|
for (let [n, i] of Object.entries(e.fields)) i.type === "reference" && i.references?.()?.tableName === t && r.push(n);
|
|
161
184
|
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>' }.`);
|
|
162
185
|
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.`);
|
|
163
186
|
return r[0];
|
|
164
|
-
},
|
|
165
|
-
let t =
|
|
187
|
+
}, Jt = (e) => Object.keys(e.fields), Yt = (e, t) => Object.prototype.hasOwnProperty.call(e.fields, t), Xt = (e) => {
|
|
188
|
+
let t = Jt(e);
|
|
166
189
|
return t.length === 0 ? "<none>" : t.join(", ");
|
|
167
|
-
},
|
|
190
|
+
}, Zt = (e, t, n) => {
|
|
168
191
|
let r = `relation '${t}' on '${e.tableName}'`, i = n.target();
|
|
169
192
|
if (n.kind === "manyToMany") {
|
|
170
193
|
let t = n.through();
|
|
171
|
-
for (let [a, o] of [["sourceKey", n.sourceKey], ["targetKey", n.targetKey]]) if (!
|
|
194
|
+
for (let [a, o] of [["sourceKey", n.sourceKey], ["targetKey", n.targetKey]]) if (!Yt(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}': ${Xt(t)}.`);
|
|
172
195
|
return;
|
|
173
196
|
}
|
|
174
197
|
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.`);
|
|
175
|
-
if (n.sourceKey !== void 0 && !
|
|
176
|
-
let t =
|
|
177
|
-
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}': ${
|
|
198
|
+
if (n.sourceKey !== void 0 && !Yt(e, n.sourceKey)) {
|
|
199
|
+
let t = Yt(i, n.sourceKey);
|
|
200
|
+
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}': ${Xt(e)}.`));
|
|
178
201
|
}
|
|
179
|
-
if (n.foreignKey !== void 0 && !
|
|
180
|
-
let t =
|
|
181
|
-
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}': ${
|
|
202
|
+
if (n.foreignKey !== void 0 && !Yt(i, n.foreignKey)) {
|
|
203
|
+
let t = Yt(e, n.foreignKey);
|
|
204
|
+
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}': ${Xt(i)}.`));
|
|
182
205
|
}
|
|
183
|
-
},
|
|
184
|
-
let t = e.source(), n =
|
|
206
|
+
}, Qt = Symbol.for("@voltro/database/relationsRegistry"), $t = globalThis, k = $t[Qt] ?? ($t[Qt] = /* @__PURE__ */ new Map()), en = (e) => {
|
|
207
|
+
let t = e.source(), n = k.get(t.tableName);
|
|
185
208
|
if (n === void 0) {
|
|
186
|
-
|
|
209
|
+
k.set(t.tableName, new Map(Object.entries(e.relations)));
|
|
187
210
|
return;
|
|
188
211
|
}
|
|
189
212
|
for (let [r, i] of Object.entries(e.relations)) {
|
|
@@ -193,29 +216,29 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
193
216
|
n.set(r, i);
|
|
194
217
|
}
|
|
195
218
|
}
|
|
196
|
-
},
|
|
219
|
+
}, tn = (e) => {
|
|
197
220
|
let t = 0;
|
|
198
|
-
for (let n of Object.values(e))
|
|
221
|
+
for (let n of Object.values(e)) Wt(n) && (en(n), t += 1);
|
|
199
222
|
return t;
|
|
200
|
-
},
|
|
201
|
-
let t =
|
|
223
|
+
}, nn = (e) => {
|
|
224
|
+
let t = k.get(e);
|
|
202
225
|
if (t !== void 0) return Object.fromEntries(t);
|
|
203
|
-
},
|
|
226
|
+
}, rn = (e, t) => k.get(e)?.get(t), an = () => {
|
|
204
227
|
let e = [];
|
|
205
|
-
for (let [t, n] of
|
|
228
|
+
for (let [t, n] of k) for (let [r, i] of n) e.push({
|
|
206
229
|
source: t,
|
|
207
230
|
name: r,
|
|
208
231
|
relation: i
|
|
209
232
|
});
|
|
210
233
|
return e;
|
|
211
|
-
},
|
|
212
|
-
for (let [e, t] of
|
|
234
|
+
}, on = () => {
|
|
235
|
+
for (let [e, t] of k) {
|
|
213
236
|
let n = S(e);
|
|
214
|
-
if (n !== void 0) for (let [e, r] of t)
|
|
237
|
+
if (n !== void 0) for (let [e, r] of t) Zt(n, e, r);
|
|
215
238
|
}
|
|
216
|
-
},
|
|
217
|
-
|
|
218
|
-
},
|
|
239
|
+
}, sn = () => {
|
|
240
|
+
k.clear();
|
|
241
|
+
}, cn = (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, ln = (e) => {
|
|
219
242
|
if (e == null || typeof e != "string") return e;
|
|
220
243
|
let t = e.trim();
|
|
221
244
|
if (t.length === 0) return e;
|
|
@@ -226,7 +249,7 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
226
249
|
} catch {
|
|
227
250
|
return e;
|
|
228
251
|
}
|
|
229
|
-
},
|
|
252
|
+
}, un = (e) => e == null || typeof e == "string" ? e : typeof e == "number" || typeof e == "bigint" ? String(e) : e, dn = (e) => {
|
|
230
253
|
if (e == null || e instanceof Date) return e;
|
|
231
254
|
if (typeof e == "string") {
|
|
232
255
|
let t = new Date(e);
|
|
@@ -237,19 +260,19 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
237
260
|
return isNaN(t.getTime()) ? e : t;
|
|
238
261
|
}
|
|
239
262
|
return e;
|
|
240
|
-
},
|
|
263
|
+
}, fn = (e, t, n) => {
|
|
241
264
|
if (e == null) return e;
|
|
242
265
|
switch (t) {
|
|
243
|
-
case "boolean": return n === "postgres" ? e :
|
|
266
|
+
case "boolean": return n === "postgres" ? e : cn(e);
|
|
244
267
|
case "json":
|
|
245
|
-
case "array": return n === "postgres" ? e :
|
|
268
|
+
case "array": return n === "postgres" ? e : ln(e);
|
|
246
269
|
case "timestamp":
|
|
247
|
-
case "date": return n === "sqlite" || n === "turso" ?
|
|
270
|
+
case "date": return n === "sqlite" || n === "turso" ? dn(e) : e;
|
|
248
271
|
case "decimal":
|
|
249
|
-
case "bigint": return
|
|
272
|
+
case "bigint": return un(e);
|
|
250
273
|
default: return e;
|
|
251
274
|
}
|
|
252
|
-
},
|
|
275
|
+
}, pn = (e, t, n) => {
|
|
253
276
|
if (e.length === 0) return e;
|
|
254
277
|
let r = S(t);
|
|
255
278
|
if (r === void 0) return e;
|
|
@@ -260,36 +283,36 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
260
283
|
});
|
|
261
284
|
return e.map((e) => {
|
|
262
285
|
let t = { ...e };
|
|
263
|
-
for (let { key: e, type: r } of a) e in t && (t[e] =
|
|
286
|
+
for (let { key: e, type: r } of a) e in t && (t[e] = fn(t[e], r, n));
|
|
264
287
|
return t;
|
|
265
288
|
});
|
|
266
|
-
},
|
|
289
|
+
}, mn = (e, t) => {
|
|
267
290
|
if (e == null) return e;
|
|
268
291
|
switch (t) {
|
|
269
292
|
case "json":
|
|
270
293
|
case "array": return typeof e == "string" ? e : JSON.stringify(e);
|
|
271
294
|
default: return e;
|
|
272
295
|
}
|
|
273
|
-
},
|
|
296
|
+
}, hn = (e, t, n = ["json", "array"]) => {
|
|
274
297
|
let r = S(t);
|
|
275
298
|
if (r === void 0) return e;
|
|
276
299
|
let i = r.fields, a = null;
|
|
277
300
|
for (let [t, r] of Object.entries(i)) if (n.includes(r.type) && t in e) {
|
|
278
|
-
let n =
|
|
301
|
+
let n = mn(e[t], r.type);
|
|
279
302
|
n !== e[t] && (a === null && (a = { ...e }), a[t] = n);
|
|
280
303
|
}
|
|
281
304
|
return a ?? e;
|
|
282
|
-
},
|
|
305
|
+
}, gn = class extends Error {
|
|
283
306
|
_tag = "EagerCardinalityError";
|
|
284
307
|
constructor(e) {
|
|
285
308
|
super(e), this.name = "EagerCardinalityError";
|
|
286
309
|
}
|
|
287
|
-
},
|
|
310
|
+
}, _n = (e) => {
|
|
288
311
|
let { relationName: t, sourceTableName: n, targetTableName: r, foreignKey: i, sourceKey: a } = e, o = r === n;
|
|
289
312
|
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.");
|
|
290
|
-
},
|
|
313
|
+
}, vn = async (e, t, n, r) => {
|
|
291
314
|
if (e.length === 0) return e;
|
|
292
|
-
let i =
|
|
315
|
+
let i = nn(n.tableName);
|
|
293
316
|
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?`);
|
|
294
317
|
let a = e.map((e) => ({ ...e }));
|
|
295
318
|
for (let [e, o] of Object.entries(t)) {
|
|
@@ -298,36 +321,36 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
298
321
|
let t = Object.keys(i).join(", ") || "<none>";
|
|
299
322
|
throw Error(`unknown relation '${e}' on '${n.tableName}'. Registered relations: ${t}.`);
|
|
300
323
|
}
|
|
301
|
-
|
|
324
|
+
Zt(n, e, t), await yn(a, e, t, o === !0 ? {} : o, n, r);
|
|
302
325
|
}
|
|
303
326
|
return a;
|
|
304
|
-
},
|
|
327
|
+
}, yn = async (e, t, n, r, i, a) => {
|
|
305
328
|
switch (n.kind) {
|
|
306
329
|
case "one":
|
|
307
|
-
await
|
|
330
|
+
await bn(e, t, n, r, i, a);
|
|
308
331
|
return;
|
|
309
332
|
case "many":
|
|
310
|
-
await
|
|
333
|
+
await xn(e, t, n, r, i, a);
|
|
311
334
|
return;
|
|
312
335
|
case "manyToMany":
|
|
313
|
-
await
|
|
336
|
+
await Cn(e, t, n, r, i, a);
|
|
314
337
|
return;
|
|
315
338
|
}
|
|
316
|
-
},
|
|
317
|
-
let o = n.target(), s = n.sourceKey ??
|
|
339
|
+
}, bn = async (e, t, n, r, i, a) => {
|
|
340
|
+
let o = n.target(), s = n.sourceKey ?? wn(i, o.tableName);
|
|
318
341
|
if (s !== void 0) {
|
|
319
|
-
let n =
|
|
342
|
+
let n = A(e, s), i = n.length === 0 ? [] : await Tn(o, "id", n, r, a), c = new Map(i.map((e) => [e.id, e]));
|
|
320
343
|
for (let n of e) {
|
|
321
344
|
let e = n[s];
|
|
322
345
|
n[t] = e == null ? null : c.get(e) ?? null;
|
|
323
346
|
}
|
|
324
|
-
await
|
|
347
|
+
await En(i, r.with, o, a);
|
|
325
348
|
return;
|
|
326
349
|
}
|
|
327
|
-
let c = n.foreignKey ?? O(o, i.tableName, t), l = n.sourceKey ?? "id", u =
|
|
350
|
+
let c = n.foreignKey ?? O(o, i.tableName, t), l = n.sourceKey ?? "id", u = A(e, l), d = u.length === 0 ? [] : await Tn(o, c, u, r, a), f = /* @__PURE__ */ new Map();
|
|
328
351
|
for (let e of d) {
|
|
329
352
|
let n = e[c];
|
|
330
|
-
if (f.has(n)) throw new
|
|
353
|
+
if (f.has(n)) throw new gn(_n({
|
|
331
354
|
relationName: t,
|
|
332
355
|
sourceTableName: i.tableName,
|
|
333
356
|
targetTableName: o.tableName,
|
|
@@ -340,9 +363,9 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
340
363
|
let e = n[l];
|
|
341
364
|
n[t] = e == null ? null : f.get(e) ?? null;
|
|
342
365
|
}
|
|
343
|
-
await
|
|
344
|
-
},
|
|
345
|
-
let o = n.target(), s = n.foreignKey ?? O(o, i.tableName, t), c = n.sourceKey ?? "id", l =
|
|
366
|
+
await En(d, r.with, o, a);
|
|
367
|
+
}, xn = async (e, t, n, r, i, a) => {
|
|
368
|
+
let o = n.target(), s = n.foreignKey ?? O(o, i.tableName, t), c = n.sourceKey ?? "id", l = A(e, c), u = Sn(r), d = l.length === 0 ? [] : await Tn(o, s, l, u, a), f = /* @__PURE__ */ new Map();
|
|
346
369
|
for (let e of d) {
|
|
347
370
|
let t = e[s], n = f.get(t);
|
|
348
371
|
n ? n.push(e) : f.set(t, [e]);
|
|
@@ -358,12 +381,12 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
358
381
|
let e = n[c];
|
|
359
382
|
n[t] = f.get(e) ?? [];
|
|
360
383
|
}
|
|
361
|
-
await
|
|
362
|
-
},
|
|
384
|
+
await En(d, r.with, o, a);
|
|
385
|
+
}, Sn = (e) => {
|
|
363
386
|
let { limit: t, offset: n, ...r } = e;
|
|
364
387
|
return r;
|
|
365
|
-
},
|
|
366
|
-
let o = n.target(), s = n.through(), c =
|
|
388
|
+
}, Cn = async (e, t, n, r, i, a) => {
|
|
389
|
+
let o = n.target(), s = n.through(), c = A(e, "id");
|
|
367
390
|
if (c.length === 0) {
|
|
368
391
|
for (let n of e) n[t] = [];
|
|
369
392
|
return;
|
|
@@ -384,8 +407,8 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
384
407
|
for (let n of e) n[t] = [];
|
|
385
408
|
return;
|
|
386
409
|
}
|
|
387
|
-
let f = await
|
|
388
|
-
await
|
|
410
|
+
let f = await Tn(o, "id", A(d, n.targetKey), r, a), p = new Map(f.map((e) => [e.id, e]));
|
|
411
|
+
await En(f, r.with, o, a);
|
|
389
412
|
let m = r.junction === void 0 ? void 0 : r.junction === !0 ? Object.keys(s.fields) : r.junction, h = /* @__PURE__ */ new Map();
|
|
390
413
|
for (let e of d) {
|
|
391
414
|
let t = e[n.sourceKey], r = e[n.targetKey], i = p.get(r);
|
|
@@ -397,16 +420,16 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
397
420
|
o ? o.push(a) : h.set(t, [a]);
|
|
398
421
|
}
|
|
399
422
|
for (let n of e) n[t] = h.get(n.id) ?? [];
|
|
400
|
-
},
|
|
423
|
+
}, wn = (e, t) => {
|
|
401
424
|
for (let [n, r] of Object.entries(e.fields)) if (r.type === "reference" && r.references?.()?.tableName === t) return n;
|
|
402
|
-
},
|
|
425
|
+
}, A = (e, t) => {
|
|
403
426
|
let n = /* @__PURE__ */ new Set();
|
|
404
427
|
for (let r of e) {
|
|
405
428
|
let e = r[t];
|
|
406
429
|
e != null && n.add(e);
|
|
407
430
|
}
|
|
408
431
|
return [...n];
|
|
409
|
-
},
|
|
432
|
+
}, Tn = (e, t, n, r, i) => {
|
|
410
433
|
let a = {
|
|
411
434
|
column: t,
|
|
412
435
|
op: "in",
|
|
@@ -420,37 +443,37 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
420
443
|
skip: r.offset,
|
|
421
444
|
projection: void 0
|
|
422
445
|
});
|
|
423
|
-
},
|
|
424
|
-
t !== void 0 && e.length !== 0 && (await
|
|
446
|
+
}, En = async (e, t, n, r) => {
|
|
447
|
+
t !== void 0 && e.length !== 0 && (await vn(e, t, n, r)).forEach((t, n) => {
|
|
425
448
|
let r = e[n];
|
|
426
449
|
for (let [e, n] of Object.entries(t)) e in r || (r[e] = n);
|
|
427
450
|
});
|
|
428
|
-
},
|
|
451
|
+
}, Dn = (e) => e.eager !== void 0 && Object.keys(e.eager).length > 0, On = class extends Error {
|
|
429
452
|
_tag = "TenantNamespaceUnresolved";
|
|
430
453
|
constructor(e) {
|
|
431
454
|
super(e), this.name = "TenantNamespaceUnresolved";
|
|
432
455
|
}
|
|
433
|
-
},
|
|
456
|
+
}, kn = class extends Error {
|
|
434
457
|
_tag = "TenantNamespaceInvalid";
|
|
435
458
|
constructor(e) {
|
|
436
459
|
super(e), this.name = "TenantNamespaceInvalid";
|
|
437
460
|
}
|
|
438
|
-
},
|
|
439
|
-
if (e == null || e === "") throw new
|
|
440
|
-
let t =
|
|
441
|
-
if (t.replace(/_/g, "") === "") throw new
|
|
442
|
-
let n = `${
|
|
443
|
-
if (n.length >
|
|
461
|
+
}, An = 63, jn = "tenant_", Mn = (e) => e.toLowerCase().replace(/[^a-z0-9_]/g, "_"), Nn = (e) => {
|
|
462
|
+
if (e == null || e === "") throw new On("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.");
|
|
463
|
+
let t = Mn(e);
|
|
464
|
+
if (t.replace(/_/g, "") === "") throw new kn(`tenant id '${e}' has no usable identifier characters after sanitisation — cannot derive a distinct namespace.`);
|
|
465
|
+
let n = `${jn}${t}`;
|
|
466
|
+
if (n.length > An) throw new kn(`namespace '${n}' for tenant '${e}' exceeds the ${An}-byte identifier limit. Use a shorter tenant id.`);
|
|
444
467
|
return n;
|
|
445
|
-
},
|
|
446
|
-
if (e === void 0 || t == null || !
|
|
468
|
+
}, Pn = (e, t) => e === null ? t : `${e}.${t}`, Fn = /* @__PURE__ */ new Set(["timestamp", "date"]), In = /^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2})?/, Ln = (e, t) => {
|
|
469
|
+
if (e === void 0 || t == null || !Fn.has(e) || t instanceof Date) return t;
|
|
447
470
|
if (typeof t == "number" && Number.isFinite(t)) return new Date(t);
|
|
448
|
-
if (typeof t == "string" &&
|
|
471
|
+
if (typeof t == "string" && In.test(t)) {
|
|
449
472
|
let e = new Date(t);
|
|
450
473
|
return Number.isNaN(e.getTime()) ? t : e;
|
|
451
474
|
}
|
|
452
475
|
return t;
|
|
453
|
-
},
|
|
476
|
+
}, Rn = (e, t) => e === void 0 || !Fn.has(e) ? t : t.map((t) => Ln(e, t)), zn = (e, t) => {
|
|
454
477
|
let { strings: n, values: r } = e, i = t.unsafe(n[0] ?? "");
|
|
455
478
|
for (let e = 0; e < r.length; e++) i = t`${i}${r[e]}${t.unsafe(n[e + 1] ?? "")}`;
|
|
456
479
|
return t`${i}`;
|
|
@@ -476,7 +499,7 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
476
499
|
mssql: () => t.unsafe(w(i.column, o, "mssql", { numeric: !0 })),
|
|
477
500
|
sqlite: () => t.unsafe(w(i.column, o, "sqlite", { numeric: !0 })),
|
|
478
501
|
orElse: () => t.unsafe(w(i.column, o, "postgres", { numeric: !0 }))
|
|
479
|
-
}), 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) =>
|
|
502
|
+
}), 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) => Ln(m, e);
|
|
480
503
|
switch (i.op) {
|
|
481
504
|
case "eq": return t`${u} = ${f(h(i.value))}`;
|
|
482
505
|
case "neq": return t`${u} <> ${f(h(i.value))}`;
|
|
@@ -550,13 +573,13 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
550
573
|
});
|
|
551
574
|
}
|
|
552
575
|
}
|
|
553
|
-
},
|
|
576
|
+
}, Bn = (e, t) => {
|
|
554
577
|
let n = [];
|
|
555
578
|
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}`);
|
|
556
|
-
},
|
|
579
|
+
}, Vn = (e, t) => t.csv(e.map((e) => {
|
|
557
580
|
let n = e.column === void 0 ? t.unsafe("*") : t`${t(e.column)}`;
|
|
558
581
|
if (e.op.startsWith("window-")) {
|
|
559
|
-
let r =
|
|
582
|
+
let r = Bn(e.window ?? {}, t);
|
|
560
583
|
switch (e.op) {
|
|
561
584
|
case "window-row-number": return t`ROW_NUMBER() OVER (${r}) AS ${t(e.alias)}`;
|
|
562
585
|
case "window-rank": return t`RANK() OVER (${r}) AS ${t(e.alias)}`;
|
|
@@ -580,39 +603,39 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
580
603
|
return t`${t(e.column)} AS ${t(e.alias)}`;
|
|
581
604
|
default: throw Error(`compileAggregateProjection: unknown op '${e.op}'`);
|
|
582
605
|
}
|
|
583
|
-
})),
|
|
606
|
+
})), Hn = (e) => `[${e.join(",")}]`, Un = (e, t) => {
|
|
584
607
|
if (e.queryVector === void 0) return null;
|
|
585
|
-
let n = t(e.column), r =
|
|
608
|
+
let n = t(e.column), r = Hn(e.queryVector), i = e.distance === "cosine" ? "<=>" : e.distance === "l2" ? "<->" : "<#>", a = e.distance === "cosine" ? "VEC_DISTANCE_COSINE" : "VEC_DISTANCE_EUCLIDEAN";
|
|
586
609
|
return t.onDialectOrElse({
|
|
587
610
|
mysql: () => t`${t.unsafe(a)}(${n}, ${r})`,
|
|
588
611
|
mssql: () => t`NULL`,
|
|
589
612
|
sqlite: () => t`NULL`,
|
|
590
613
|
orElse: () => t`${n} ${t.unsafe(i)} ${r}::vector`
|
|
591
614
|
});
|
|
592
|
-
},
|
|
615
|
+
}, Wn = (e, t) => {
|
|
593
616
|
let n = t.unsafe(e.useGeography ? "::geography" : "::geometry");
|
|
594
617
|
return t`ST_Distance(${t(e.column)}${n}, ${e.geom}${n})`;
|
|
595
|
-
},
|
|
618
|
+
}, Gn = (e, t) => t`${t(e.column)} <-> ${e.geom}::geometry`, Kn = (e, t) => t`${t(`${e.indexName}_tsv`)}`, qn = (e, t) => `${t}_${e.indexName}_fts`, Jn = (e, t, n) => {
|
|
596
619
|
let r = n.csv(e.columns.map((e) => n`${n(e)}`)), i = `%${j(e.query)}%`;
|
|
597
620
|
return n.onDialectOrElse({
|
|
598
621
|
mysql: () => n`MATCH(${r}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
|
|
599
622
|
sqlite: () => {
|
|
600
|
-
let r = n(
|
|
623
|
+
let r = n(qn(e, t));
|
|
601
624
|
return n`${n("id")} IN (SELECT ${n("row_id")} FROM ${r} WHERE ${r} MATCH ${e.query})`;
|
|
602
625
|
},
|
|
603
626
|
mssql: () => n.or(e.columns.map((e) => n`LOWER(${n(e)}) LIKE LOWER(${i}) ESCAPE '\\'`)),
|
|
604
|
-
orElse: () => n`${
|
|
627
|
+
orElse: () => n`${Kn(e, n)} @@ plainto_tsquery(${e.config ?? "english"}, ${e.query})`
|
|
605
628
|
});
|
|
606
|
-
},
|
|
629
|
+
}, Yn = (e, t, n) => {
|
|
607
630
|
let r = `%${j(e.query)}%`;
|
|
608
631
|
return n.onDialectOrElse({
|
|
609
632
|
mysql: () => n`MATCH(${n.csv(e.columns.map((e) => n`${n(e)}`))}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
|
|
610
633
|
sqlite: () => {
|
|
611
|
-
let r = n(
|
|
634
|
+
let r = n(qn(e, t));
|
|
612
635
|
return n`COALESCE((SELECT -bm25(${r}) FROM ${r} WHERE ${r} MATCH ${e.query} AND ${r}.${n("row_id")} = ${n("id")}), 0)`;
|
|
613
636
|
},
|
|
614
637
|
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}`),
|
|
615
|
-
orElse: () => n`ts_rank(${
|
|
638
|
+
orElse: () => n`ts_rank(${Kn(e, n)}, plainto_tsquery(${e.config ?? "english"}, ${e.query}))`
|
|
616
639
|
});
|
|
617
640
|
}, N = (e, t, n = null) => {
|
|
618
641
|
if (e.setOp && e.setOp.queries.length >= 2) {
|
|
@@ -627,7 +650,7 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
627
650
|
}
|
|
628
651
|
return t`${i}${a.reduce((e, n) => t`${e}${n}`, t``)}`;
|
|
629
652
|
}
|
|
630
|
-
let r = e.annClause === void 0 ? null :
|
|
653
|
+
let r = e.annClause === void 0 ? null : Un(e.annClause, t);
|
|
631
654
|
e.spatialClause !== void 0 && t.onDialectOrElse({
|
|
632
655
|
mysql: () => {
|
|
633
656
|
throw Error("@voltro/plugin-postgis: spatial distance / KNN ordering is postgres-only");
|
|
@@ -640,57 +663,57 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
640
663
|
},
|
|
641
664
|
orElse: () => t``
|
|
642
665
|
});
|
|
643
|
-
let i = e.spatialClause?.projectAs === void 0 ? null :
|
|
666
|
+
let i = e.spatialClause?.projectAs === void 0 ? null : Wn(e.spatialClause, t), a = e.aggregations && e.aggregations.length > 0 ? Vn(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 ? Yn(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({
|
|
644
667
|
orElse: () => t`DISTINCT ON (${t.csv(e.distinctOn.map((e) => t`${t(e)}`))}) `,
|
|
645
668
|
mysql: () => t`DISTINCT `,
|
|
646
669
|
mssql: () => t`DISTINCT `,
|
|
647
670
|
sqlite: () => t`DISTINCT `
|
|
648
|
-
}) : e.distinct ? t`DISTINCT ` : t``, p = e.alias === void 0 ? t`${t(
|
|
671
|
+
}) : e.distinct ? t`DISTINCT ` : t``, p = e.alias === void 0 ? t`${t(Pn(n, e.table))}` : t`${t(Pn(n, e.table))} AS ${t(e.alias)}`, m = (e.joins ?? []).map((e) => {
|
|
649
672
|
let r = e.kind === "inner" ? "INNER" : "LEFT";
|
|
650
|
-
return t` ${t.unsafe(r)} JOIN ${t(
|
|
651
|
-
}), h = m.length > 0 ? m.reduce((e, n) => t`${e}${n}`, p) : p, g = c === void 0 ? null :
|
|
652
|
-
r !== null &&
|
|
653
|
-
for (let n of e.order)
|
|
654
|
-
let
|
|
673
|
+
return t` ${t.unsafe(r)} JOIN ${t(Pn(n, e.table))} AS ${t(e.alias)} ON ${M(e.on, t, n)}`;
|
|
674
|
+
}), h = m.length > 0 ? m.reduce((e, n) => t`${e}${n}`, p) : p, g = c === void 0 ? null : Jn(c, e.table, t), _ = [e.predicate ? M(e.predicate, t, n, e.table) : null, g].filter((e) => e !== null), ee = _.length > 0 ? t` WHERE ${t.and(_)}` : t``, v = e.groupBy && e.groupBy.length > 0 ? t` GROUP BY ${t.csv(e.groupBy.map((e) => t`${t(e)}`))}` : t``, te = e.having ? t` HAVING ${M(e.having, t, n, e.table)}` : t``, y = e.skip !== void 0, b = [];
|
|
675
|
+
r !== null && b.push(t`${r} ASC`), e.spatialClause?.order !== void 0 && b.push(e.spatialClause.order === "desc" ? t`${Gn(e.spatialClause, t)} DESC` : t`${Gn(e.spatialClause, t)} ASC`), l !== null && c?.rank?.order === !0 && b.push(t`${l} DESC`);
|
|
676
|
+
for (let n of e.order) b.push(n.direction === "desc" ? t`${t(n.column)} DESC` : t`${t(n.column)} ASC`);
|
|
677
|
+
let ne = b.length > 0 ? t` ORDER BY ${t.csv(b)}` : y ? t.onDialectOrElse({
|
|
655
678
|
mssql: () => t` ORDER BY (SELECT NULL)`,
|
|
656
679
|
orElse: () => t``
|
|
657
|
-
}) : t``,
|
|
680
|
+
}) : t``, x = (e) => {
|
|
658
681
|
if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw Error(`compileSelect: expected non-negative integer take/skip, got ${e}`);
|
|
659
682
|
return t.unsafe(String(e));
|
|
660
|
-
},
|
|
683
|
+
}, re = (e.ctes ?? []).map((e) => t`${t(e.name)} AS (${N(e.descriptor, t, n)})`), ie = (e.ctes ?? []).some((e) => e.recursive === !0), ae = re.length > 0 ? t`WITH ${t.unsafe(ie ? "RECURSIVE " : "")}${t.csv(re)} ` : t``;
|
|
661
684
|
return t.onDialectOrElse({
|
|
662
685
|
mssql: () => {
|
|
663
|
-
let n = e.take !== void 0 && !
|
|
664
|
-
return t`${ae}SELECT ${n}${f}${d} FROM ${h}${ee}${v}${te}${
|
|
686
|
+
let n = e.take !== void 0 && !y ? t`TOP ${x(e.take)} ` : t``, r = y ? t` OFFSET ${x(e.skip)} ROWS FETCH NEXT ${x(e.take ?? 2 ** 53 - 1)} ROWS ONLY` : t``;
|
|
687
|
+
return t`${ae}SELECT ${n}${f}${d} FROM ${h}${ee}${v}${te}${ne}${r}`;
|
|
665
688
|
},
|
|
666
689
|
orElse: () => {
|
|
667
|
-
let n = e.take === void 0 ? t`` : t` LIMIT ${
|
|
668
|
-
return t`${ae}SELECT ${f}${d} FROM ${h}${ee}${v}${te}${
|
|
690
|
+
let n = e.take === void 0 ? t`` : t` LIMIT ${x(e.take)}`, r = y ? t` OFFSET ${x(e.skip)}` : t``;
|
|
691
|
+
return t`${ae}SELECT ${f}${d} FROM ${h}${ee}${v}${te}${ne}${n}${r}`;
|
|
669
692
|
}
|
|
670
693
|
});
|
|
671
|
-
},
|
|
694
|
+
}, Xn = (e, t, n) => {
|
|
672
695
|
if (e.eager === void 0) return null;
|
|
673
|
-
let r =
|
|
696
|
+
let r = Qn(e.table, e.eager, e.sourceTable);
|
|
674
697
|
if (r === null) return null;
|
|
675
|
-
let i =
|
|
698
|
+
let i = ar(n, e, r, ir(t, n));
|
|
676
699
|
return i === null ? null : {
|
|
677
700
|
fragment: i,
|
|
678
|
-
decode:
|
|
701
|
+
decode: cr(r, n)
|
|
679
702
|
};
|
|
680
|
-
}, P = (e) => e.relation.kind === "one" && e.fkSide === "target",
|
|
703
|
+
}, P = (e) => e.relation.kind === "one" && e.fkSide === "target", Zn = (e) => ({
|
|
681
704
|
...e,
|
|
682
705
|
branch: {
|
|
683
706
|
...e.branch,
|
|
684
707
|
limit: 2
|
|
685
708
|
}
|
|
686
|
-
}),
|
|
687
|
-
let r = n ??
|
|
709
|
+
}), Qn = (e, t, n) => {
|
|
710
|
+
let r = n ?? pe(e), i = nn(e);
|
|
688
711
|
if (i === void 0) return null;
|
|
689
712
|
let a = [];
|
|
690
713
|
for (let [e, n] of Object.entries(t)) {
|
|
691
714
|
let t = i[e];
|
|
692
715
|
if (t === void 0) return null;
|
|
693
|
-
let o =
|
|
716
|
+
let o = $n(e, t, r, n === !0 ? {} : n);
|
|
694
717
|
if (o === null) return null;
|
|
695
718
|
a.push(o);
|
|
696
719
|
}
|
|
@@ -698,11 +721,11 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
698
721
|
table: r,
|
|
699
722
|
children: a
|
|
700
723
|
};
|
|
701
|
-
},
|
|
724
|
+
}, $n = (e, t, n, r) => {
|
|
702
725
|
let i = t.target(), a = (t.kind === "manyToMany" ? void 0 : t.sourceKey) ?? "id", o, s;
|
|
703
726
|
if (t.kind === "manyToMany") o = t.targetKey, s = "target";
|
|
704
727
|
else if (t.kind === "one") {
|
|
705
|
-
let r = t.sourceKey ??
|
|
728
|
+
let r = t.sourceKey ?? rr(n, i.tableName);
|
|
706
729
|
if (r !== void 0) o = r, s = "source";
|
|
707
730
|
else try {
|
|
708
731
|
o = t.foreignKey ?? O(i, n.tableName, e), s = "target";
|
|
@@ -715,13 +738,13 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
715
738
|
return null;
|
|
716
739
|
}
|
|
717
740
|
let c = r.with === void 0 ? [] : (() => {
|
|
718
|
-
let e =
|
|
741
|
+
let e = nn(i.tableName);
|
|
719
742
|
if (e === void 0 && Object.keys(r.with).length > 0) return null;
|
|
720
743
|
let t = [];
|
|
721
744
|
for (let [n, a] of Object.entries(r.with)) {
|
|
722
745
|
let r = e?.[n];
|
|
723
746
|
if (r === void 0) return null;
|
|
724
|
-
let o =
|
|
747
|
+
let o = $n(n, r, i, a === !0 ? {} : a);
|
|
725
748
|
if (o === null) return null;
|
|
726
749
|
t.push(o);
|
|
727
750
|
}
|
|
@@ -737,9 +760,9 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
737
760
|
fkSide: s,
|
|
738
761
|
branch: r,
|
|
739
762
|
children: c,
|
|
740
|
-
junction:
|
|
763
|
+
junction: er(t, r)
|
|
741
764
|
};
|
|
742
|
-
},
|
|
765
|
+
}, er = (e, t) => {
|
|
743
766
|
if (e.kind !== "manyToMany" || t.junction === void 0) return;
|
|
744
767
|
let n = e.through(), r = t.junction === !0 ? Object.keys(n.fields) : t.junction, i = r.filter((e) => e in n.fields);
|
|
745
768
|
return {
|
|
@@ -751,35 +774,35 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
751
774
|
return t !== void 0 && (t.type === "timestamp" || t.type === "date");
|
|
752
775
|
})
|
|
753
776
|
};
|
|
754
|
-
},
|
|
777
|
+
}, tr = (e) => `__j_${e}`, nr = "__j", rr = (e, t) => {
|
|
755
778
|
for (let [n, r] of Object.entries(e.fields)) if (r.type === "reference" && r.references?.()?.tableName === t) return n;
|
|
756
|
-
},
|
|
779
|
+
}, ir = (e, t) => {
|
|
757
780
|
let n = 0;
|
|
758
781
|
return {
|
|
759
782
|
sql: e,
|
|
760
783
|
dialect: t,
|
|
761
784
|
nextAlias: () => `__a${n++}`
|
|
762
785
|
};
|
|
763
|
-
},
|
|
786
|
+
}, ar = (e, t, n, r) => {
|
|
764
787
|
switch (e) {
|
|
765
|
-
case "postgres": return
|
|
788
|
+
case "postgres": return dr(t, n, r);
|
|
766
789
|
case "sqlite":
|
|
767
|
-
case "turso": return
|
|
790
|
+
case "turso": return yr(t, n, r);
|
|
768
791
|
case "mysql":
|
|
769
|
-
case "mariadb": return
|
|
770
|
-
case "mssql": return
|
|
792
|
+
case "mariadb": return kr(t, n, r);
|
|
793
|
+
case "mssql": return Ir(t, n, r);
|
|
771
794
|
}
|
|
772
|
-
},
|
|
773
|
-
let n =
|
|
795
|
+
}, or = (e, t) => t === "mssql" && !sr.test(e) ? /* @__PURE__ */ new Date(`${e}Z`) : new Date(e), sr = /(?:Z|[+-]\d{2}:?\d{2})$/, cr = (e, t) => {
|
|
796
|
+
let n = lr(e.table, e.children, t);
|
|
774
797
|
return (e) => e.map((e) => {
|
|
775
798
|
let t = e.__row, r = typeof t == "string" ? JSON.parse(t) : t;
|
|
776
799
|
return n(r);
|
|
777
800
|
});
|
|
778
|
-
},
|
|
801
|
+
}, lr = (e, t, n) => {
|
|
779
802
|
let r = [];
|
|
780
803
|
for (let [t, n] of Object.entries(e.fields)) (n.type === "timestamp" || n.type === "date") && r.push(t);
|
|
781
804
|
let i = t.map((e) => {
|
|
782
|
-
let t =
|
|
805
|
+
let t = lr(e.target, e.children, n), r = e.relation.kind === "one", i = P(e), a = i ? _n({
|
|
783
806
|
relationName: e.relationName,
|
|
784
807
|
sourceTableName: e.source.tableName,
|
|
785
808
|
targetTableName: e.target.tableName,
|
|
@@ -792,14 +815,14 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
792
815
|
isSingle: r,
|
|
793
816
|
fromOverFetch: i,
|
|
794
817
|
cardinalityMessage: a,
|
|
795
|
-
junction:
|
|
818
|
+
junction: ur(e.junction, n)
|
|
796
819
|
};
|
|
797
820
|
});
|
|
798
821
|
return (e) => {
|
|
799
822
|
let t = { ...e };
|
|
800
823
|
for (let e of r) {
|
|
801
824
|
let r = t[e];
|
|
802
|
-
typeof r == "string" && (t[e] =
|
|
825
|
+
typeof r == "string" && (t[e] = or(r, n));
|
|
803
826
|
}
|
|
804
827
|
for (let e of i) {
|
|
805
828
|
let n = t[e.name];
|
|
@@ -809,7 +832,7 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
809
832
|
}
|
|
810
833
|
if (e.fromOverFetch) {
|
|
811
834
|
let r = n;
|
|
812
|
-
if (r.length > 1) throw new
|
|
835
|
+
if (r.length > 1) throw new gn(e.cardinalityMessage);
|
|
813
836
|
t[e.name] = r.length === 0 ? null : e.decode(r[0]);
|
|
814
837
|
continue;
|
|
815
838
|
}
|
|
@@ -821,104 +844,104 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
821
844
|
}
|
|
822
845
|
return t;
|
|
823
846
|
};
|
|
824
|
-
},
|
|
847
|
+
}, ur = (e, t) => {
|
|
825
848
|
if (e === void 0) return;
|
|
826
849
|
let n = new Set(e.dateColumns), r = e.requested;
|
|
827
850
|
return (e) => {
|
|
828
851
|
let i = e._junction ?? {}, a = {};
|
|
829
852
|
for (let e of r) {
|
|
830
853
|
let r = i[e];
|
|
831
|
-
a[e] = n.has(e) && typeof r == "string" ?
|
|
854
|
+
a[e] = n.has(e) && typeof r == "string" ? or(r, t) : r;
|
|
832
855
|
}
|
|
833
856
|
return {
|
|
834
857
|
...e,
|
|
835
858
|
_junction: a
|
|
836
859
|
};
|
|
837
860
|
};
|
|
838
|
-
},
|
|
839
|
-
let r = n.sql, i = n.nextAlias(), a = r(t.table.tableName), o = r(i), s =
|
|
861
|
+
}, dr = (e, t, n) => {
|
|
862
|
+
let r = n.sql, i = n.nextAlias(), a = r(t.table.tableName), o = r(i), s = fr(i, t.children, n);
|
|
840
863
|
return s === null ? null : r`SELECT ${s} AS "__row" FROM ${a} AS ${o}${e.predicate ? r` WHERE ${B(e.predicate, i, r)}` : r``}${e.order.length > 0 ? r` ORDER BY ${r.csv(e.order.map((e) => e.direction === "desc" ? r`${L(i, e.column, r)} DESC` : r`${L(i, e.column, r)} ASC`))}` : r``}${e.take === void 0 ? r`` : r` LIMIT ${z(e.take, r)}`}${e.skip === void 0 ? r`` : r` OFFSET ${z(e.skip, r)}`}`;
|
|
841
|
-
},
|
|
842
|
-
let i = n.sql, a = r === void 0 ? i`to_jsonb(${i(e)}.*)` : i`(to_jsonb(${i(e)}.*) - ${R(
|
|
864
|
+
}, fr = (e, t, n, r) => {
|
|
865
|
+
let i = n.sql, a = r === void 0 ? i`to_jsonb(${i(e)}.*)` : i`(to_jsonb(${i(e)}.*) - ${R(nr, i)}::text)`;
|
|
843
866
|
if (t.length === 0 && r === void 0) return a;
|
|
844
867
|
let o = [];
|
|
845
|
-
r !== void 0 && o.push(i`${R("_junction", i)}, ${L(e,
|
|
868
|
+
r !== void 0 && o.push(i`${R("_junction", i)}, ${L(e, nr, i)}`);
|
|
846
869
|
for (let r of t) {
|
|
847
|
-
let t =
|
|
870
|
+
let t = pr(r, e, n);
|
|
848
871
|
if (t === null) return null;
|
|
849
872
|
o.push(i`${R(r.relationName, i)}, ${t}`);
|
|
850
873
|
}
|
|
851
874
|
return i`${a} || jsonb_build_object(${i.csv(o)})`;
|
|
852
|
-
},
|
|
875
|
+
}, pr = (e, t, n) => {
|
|
853
876
|
switch (e.relation.kind) {
|
|
854
|
-
case "one": return P(e) ?
|
|
855
|
-
case "many": return
|
|
856
|
-
case "manyToMany": return
|
|
877
|
+
case "one": return P(e) ? hr(Zn(e), t, n) : mr(e, t, n);
|
|
878
|
+
case "many": return hr(e, t, n);
|
|
879
|
+
case "manyToMany": return gr(e, t, n);
|
|
857
880
|
}
|
|
858
|
-
},
|
|
859
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
881
|
+
}, mr = (e, t, n) => {
|
|
882
|
+
let r = n.sql, i = n.nextAlias(), a = fr(i, e.children, n);
|
|
860
883
|
if (a === null) return null;
|
|
861
884
|
let o = e.fkSide === "source" ? r`${L(i, "id", r)} = ${L(t, e.foreignKey, r)}` : r`${L(i, e.foreignKey, r)} = ${L(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${B(e.branch.where, i, r)}`, c = F(i, e.branch.orderBy, r);
|
|
862
885
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}${c} LIMIT 1)`;
|
|
863
|
-
},
|
|
864
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
886
|
+
}, hr = (e, t, n) => {
|
|
887
|
+
let r = n.sql, i = n.nextAlias(), a = fr(i, e.children, n);
|
|
865
888
|
if (a === null) return null;
|
|
866
|
-
let o = r`${L(void 0, e.foreignKey, r)} = ${L(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${M(e.branch.where, r)}`, c =
|
|
889
|
+
let o = r`${L(void 0, e.foreignKey, r)} = ${L(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${M(e.branch.where, r)}`, c = vr(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${z(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${z(e.branch.offset, r)}`;
|
|
867
890
|
return r`COALESCE((SELECT jsonb_agg(${a}) FROM (SELECT * FROM ${r(e.target.tableName)} WHERE ${o}${s}${c}${l}${u}) AS ${r(i)}), '[]'::jsonb)`;
|
|
868
|
-
},
|
|
869
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
891
|
+
}, gr = (e, t, n) => {
|
|
892
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = fr(o, e.children, n, e.junction);
|
|
870
893
|
if (c === null) return null;
|
|
871
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${M(e.branch.where, r)}`, u = V(e, s, r), d = F(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${z(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${z(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : r`, ${
|
|
894
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${M(e.branch.where, r)}`, u = V(e, s, r), d = F(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${z(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${z(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : r`, ${_r(e.junction, s, r)} AS ${r(nr)}`;
|
|
872
895
|
return r`COALESCE((SELECT jsonb_agg(${c}) FROM (SELECT ${r(o)}.*${m} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${L(o, "id", r)} = ${L(s, i.targetKey, r)} WHERE ${L(s, i.sourceKey, r)} = ${L(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), '[]'::jsonb)`;
|
|
873
|
-
},
|
|
874
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
896
|
+
}, _r = (e, t, n) => e.present.length === 0 ? n`jsonb_build_object()` : n`jsonb_build_object(${n.csv(e.present.map((e) => n`${R(e, n)}, ${L(t, e, n)}`))})`, F = (e, t, n) => t === void 0 || t.length === 0 ? n`` : n` ORDER BY ${n.csv(t.map((t) => t.direction === "desc" ? n`${L(e, t.column, n)} DESC` : n`${L(e, t.column, n)} ASC`))}`, vr = (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`))}`, yr = (e, t, n) => {
|
|
897
|
+
let r = n.sql, i = n.nextAlias(), a = br(i, t.table, t.children, n);
|
|
875
898
|
if (a === null) return null;
|
|
876
899
|
let o = e.predicate ? r` WHERE ${B(e.predicate, i, r)}` : r``, s = e.order.length > 0 ? r` ORDER BY ${r.csv(e.order.map((e) => e.direction === "desc" ? r`${L(i, e.column, r)} DESC` : r`${L(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${z(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${z(e.skip, r)}`;
|
|
877
900
|
return r`SELECT ${a} AS "__row" FROM ${r(t.table.tableName)} AS ${r(i)}${o}${s}${c}${l}`;
|
|
878
|
-
},
|
|
901
|
+
}, br = (e, t, n, r, i) => {
|
|
879
902
|
let a = r.sql, o = [];
|
|
880
903
|
for (let n of Object.keys(t.fields)) o.push(a`${R(n, a)}, ${L(e, n, a)}`);
|
|
881
904
|
if (i !== void 0) {
|
|
882
|
-
let e =
|
|
905
|
+
let e = xr(i.projection, i.source, a);
|
|
883
906
|
o.push(a`${R("_junction", a)}, json_object(${e})`);
|
|
884
907
|
}
|
|
885
908
|
for (let t of n) {
|
|
886
|
-
let n =
|
|
909
|
+
let n = Tr(t, e, r);
|
|
887
910
|
if (n === null) return null;
|
|
888
911
|
o.push(a`${R(t.relationName, a)}, ${n}`);
|
|
889
912
|
}
|
|
890
913
|
return a`json_object(${a.csv(o)})`;
|
|
891
|
-
},
|
|
914
|
+
}, xr = (e, t, n) => e.present.length === 0 ? n`` : n.csv(e.present.map((e) => n`${R(e, n)}, ${L(t.alias, t.physical(e), n)}`)), Sr = (e, t, n) => e.present.length === 0 ? n`` : n`, ${n.csv(e.present.map((e) => n`${L(t, e, n)} AS ${n(tr(e))}`))}`, Cr = (e) => ({
|
|
892
915
|
alias: e,
|
|
893
|
-
physical:
|
|
894
|
-
}),
|
|
916
|
+
physical: tr
|
|
917
|
+
}), wr = (e) => ({
|
|
895
918
|
alias: e,
|
|
896
919
|
physical: (e) => e
|
|
897
|
-
}),
|
|
920
|
+
}), Tr = (e, t, n) => {
|
|
898
921
|
switch (e.relation.kind) {
|
|
899
|
-
case "one": return P(e) ?
|
|
900
|
-
case "many": return
|
|
901
|
-
case "manyToMany": return
|
|
922
|
+
case "one": return P(e) ? Dr(Zn(e), t, n) : Er(e, t, n);
|
|
923
|
+
case "many": return Dr(e, t, n);
|
|
924
|
+
case "manyToMany": return Or(e, t, n);
|
|
902
925
|
}
|
|
903
|
-
},
|
|
904
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
926
|
+
}, Er = (e, t, n) => {
|
|
927
|
+
let r = n.sql, i = n.nextAlias(), a = br(i, e.target, e.children, n);
|
|
905
928
|
if (a === null) return null;
|
|
906
929
|
let o = e.fkSide === "source" ? r`${L(i, "id", r)} = ${L(t, e.foreignKey, r)}` : r`${L(i, e.foreignKey, r)} = ${L(t, e.sourceKey, r)}`;
|
|
907
930
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
|
|
908
|
-
},
|
|
909
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
931
|
+
}, Dr = (e, t, n) => {
|
|
932
|
+
let r = n.sql, i = n.nextAlias(), a = br(i, e.target, e.children, n);
|
|
910
933
|
if (a === null) return null;
|
|
911
|
-
let o = r`${L(void 0, e.foreignKey, r)} = ${L(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${M(H(e.branch.where), r)}`, c =
|
|
934
|
+
let o = r`${L(void 0, e.foreignKey, r)} = ${L(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${M(H(e.branch.where), r)}`, c = vr(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${z(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${z(e.branch.offset, r)}`;
|
|
912
935
|
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('[]'))`;
|
|
913
|
-
},
|
|
914
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
936
|
+
}, Or = (e, t, n) => {
|
|
937
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = br(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
915
938
|
projection: e.junction,
|
|
916
|
-
source:
|
|
939
|
+
source: Cr(o)
|
|
917
940
|
});
|
|
918
941
|
if (c === null) return null;
|
|
919
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${M(H(e.branch.where), r)}`, u = V(e, s, r, !0), d = F(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${z(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${z(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` :
|
|
942
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${M(H(e.branch.where), r)}`, u = V(e, s, r, !0), d = F(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${z(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${z(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : Sr(e.junction, s, r);
|
|
920
943
|
return r`COALESCE((SELECT json_group_array(${c}) FROM (SELECT ${r(o)}.*${m} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${L(o, "id", r)} = ${L(s, i.targetKey, r)} WHERE ${L(s, i.sourceKey, r)} = ${L(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), json('[]'))`;
|
|
921
|
-
},
|
|
944
|
+
}, kr = (e, t, n) => {
|
|
922
945
|
let r = n.sql, i = n.nextAlias(), a = I(i, t.table, t.children, n);
|
|
923
946
|
if (a === null) return null;
|
|
924
947
|
let o = e.predicate ? r` WHERE ${B(e.predicate, i, r)}` : r``, s = e.order.length > 0 ? r` ORDER BY ${r.csv(e.order.map((e) => e.direction === "desc" ? r`${L(i, e.column, r)} DESC` : r`${L(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${z(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${z(e.skip, r)}`;
|
|
@@ -927,66 +950,66 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
927
950
|
let a = r.sql, o = [];
|
|
928
951
|
for (let n of Object.keys(t.fields)) o.push(a`${R(n, a)}, ${L(e, n, a)}`);
|
|
929
952
|
if (i !== void 0) {
|
|
930
|
-
let e =
|
|
953
|
+
let e = xr(i.projection, i.source, a);
|
|
931
954
|
o.push(a`${R("_junction", a)}, JSON_OBJECT(${e})`);
|
|
932
955
|
}
|
|
933
956
|
for (let t of n) {
|
|
934
|
-
let n =
|
|
957
|
+
let n = Ar(t, e, r);
|
|
935
958
|
if (n === null) return null;
|
|
936
959
|
o.push(a`${R(t.relationName, a)}, ${n}`);
|
|
937
960
|
}
|
|
938
961
|
return a`JSON_OBJECT(${a.csv(o)})`;
|
|
939
|
-
},
|
|
962
|
+
}, Ar = (e, t, n) => {
|
|
940
963
|
switch (e.relation.kind) {
|
|
941
964
|
case "one":
|
|
942
965
|
if (P(e)) {
|
|
943
|
-
let r =
|
|
944
|
-
return n.dialect === "mariadb" ?
|
|
966
|
+
let r = Zn(e);
|
|
967
|
+
return n.dialect === "mariadb" ? Pr(r, t, n) : Mr(r, t, n);
|
|
945
968
|
}
|
|
946
|
-
return
|
|
947
|
-
case "many": return n.dialect === "mariadb" ?
|
|
948
|
-
case "manyToMany": return n.dialect === "mariadb" ?
|
|
969
|
+
return jr(e, t, n);
|
|
970
|
+
case "many": return n.dialect === "mariadb" ? Pr(e, t, n) : Mr(e, t, n);
|
|
971
|
+
case "manyToMany": return n.dialect === "mariadb" ? Fr(e, t, n) : Nr(e, t, n);
|
|
949
972
|
}
|
|
950
|
-
},
|
|
973
|
+
}, jr = (e, t, n) => {
|
|
951
974
|
let r = n.sql, i = n.nextAlias(), a = I(i, e.target, e.children, n);
|
|
952
975
|
if (a === null) return null;
|
|
953
976
|
let o = e.fkSide === "source" ? r`${L(i, "id", r)} = ${L(t, e.foreignKey, r)}` : r`${L(i, e.foreignKey, r)} = ${L(t, e.sourceKey, r)}`;
|
|
954
977
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
|
|
955
|
-
},
|
|
978
|
+
}, Mr = (e, t, n) => {
|
|
956
979
|
let r = n.sql, i = n.nextAlias(), a = I(i, e.target, e.children, n);
|
|
957
980
|
if (a === null) return null;
|
|
958
|
-
let o = r`${L(void 0, e.foreignKey, r)} = ${L(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${M(H(e.branch.where), r)}`, c =
|
|
981
|
+
let o = r`${L(void 0, e.foreignKey, r)} = ${L(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${M(H(e.branch.where), r)}`, c = vr(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${z(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${z(e.branch.offset, r)}`;
|
|
959
982
|
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())`;
|
|
960
|
-
},
|
|
983
|
+
}, Nr = (e, t, n) => {
|
|
961
984
|
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = I(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
962
985
|
projection: e.junction,
|
|
963
|
-
source:
|
|
986
|
+
source: Cr(o)
|
|
964
987
|
});
|
|
965
988
|
if (c === null) return null;
|
|
966
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${M(H(e.branch.where), r)}`, u = V(e, s, r, !0), d = F(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${z(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${z(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` :
|
|
989
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${M(H(e.branch.where), r)}`, u = V(e, s, r, !0), d = F(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${z(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${z(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : Sr(e.junction, s, r);
|
|
967
990
|
return r`COALESCE((SELECT JSON_ARRAYAGG(${c}) FROM (SELECT ${r(o)}.*${m} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${L(o, "id", r)} = ${L(s, i.targetKey, r)} WHERE ${L(s, i.sourceKey, r)} = ${L(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), JSON_ARRAY())`;
|
|
968
|
-
},
|
|
991
|
+
}, Pr = (e, t, n) => {
|
|
969
992
|
let r = n.sql, i = n.nextAlias(), a = I(i, e.target, e.children, n);
|
|
970
993
|
if (a === null) return null;
|
|
971
994
|
let o = r`${L(i, e.foreignKey, r)} = ${L(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${M(H(e.branch.where), r)}`, c = e.branch.orderBy ?? [];
|
|
972
995
|
if (!(e.branch.limit !== void 0 || e.branch.offset !== void 0)) return r`COALESCE((SELECT JSON_ARRAYAGG(${a}${c.length > 0 ? r` ORDER BY ${r.csv(c.map((e) => e.direction === "desc" ? r`${L(i, e.column, r)} DESC` : r`${L(i, e.column, r)} ASC`))}` : r``}) FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}), JSON_ARRAY())`;
|
|
973
996
|
let l = c.length > 0 ? r` ORDER BY ${r.csv(c.map((e) => e.direction === "desc" ? r`${r(e.column)} DESC` : r`${r(e.column)} ASC`))}` : r` ORDER BY ${r("id")}`, u = e.branch.limit, d = e.branch.offset, f = u !== void 0 && d !== void 0 ? r` AND ${L(i, "rn", r)} > ${z(d, r)} AND ${L(i, "rn", r)} <= ${z(d + u, r)}` : u === void 0 ? r` AND ${L(i, "rn", r)} > ${z(d, r)}` : r` AND ${L(i, "rn", r)} <= ${z(u, r)}`;
|
|
974
997
|
return r`COALESCE((SELECT JSON_ARRAYAGG(${a} ORDER BY ${L(i, "rn", r)}) FROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY ${r(e.foreignKey)}${l}) AS rn FROM ${r(e.target.tableName)}) AS ${r(i)} WHERE ${o}${s}${f}), JSON_ARRAY())`;
|
|
975
|
-
},
|
|
998
|
+
}, Fr = (e, t, n) => {
|
|
976
999
|
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = (t) => e.junction === void 0 ? void 0 : {
|
|
977
1000
|
projection: e.junction,
|
|
978
1001
|
source: t
|
|
979
1002
|
}, l = r`${L(s, i.sourceKey, r)} = ${L(t, "id", r)}`, u = r`${L(o, "id", r)} = ${L(s, i.targetKey, r)}`, d = e.branch.where === void 0 ? r`` : r` AND ${M(H(e.branch.where), r)}`, f = V(e, s, r, !0), p = e.branch.orderBy ?? [];
|
|
980
1003
|
if (!(e.branch.limit !== void 0 || e.branch.offset !== void 0)) {
|
|
981
|
-
let t = I(o, e.target, e.children, n, c(
|
|
1004
|
+
let t = I(o, e.target, e.children, n, c(wr(s)));
|
|
982
1005
|
return t === null ? null : r`COALESCE((SELECT JSON_ARRAYAGG(${t}${p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${L(o, e.column, r)} DESC` : r`${L(o, e.column, r)} ASC`))}` : r``}) FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${u} WHERE ${l}${f}${d}), JSON_ARRAY())`;
|
|
983
1006
|
}
|
|
984
|
-
let m = p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${L(o, e.column, r)} DESC` : r`${L(o, e.column, r)} ASC`))}` : r` ORDER BY ${L(o, "id", r)}`, h = e.branch.limit, g = e.branch.offset, _ = h !== void 0 && g !== void 0 ? r` AND ${L(o, "rn", r)} > ${z(g, r)} AND ${L(o, "rn", r)} <= ${z(g + h, r)}` : h === void 0 ? r` AND ${L(o, "rn", r)} > ${z(g, r)}` : r` AND ${L(o, "rn", r)} <= ${z(h, r)}`, ee = e.branch.onJunction === void 0 ? r`` : r` WHERE ${B(H(e.branch.onJunction), s, r)}`, v = I(o, e.target, e.children, n, c(
|
|
1007
|
+
let m = p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${L(o, e.column, r)} DESC` : r`${L(o, e.column, r)} ASC`))}` : r` ORDER BY ${L(o, "id", r)}`, h = e.branch.limit, g = e.branch.offset, _ = h !== void 0 && g !== void 0 ? r` AND ${L(o, "rn", r)} > ${z(g, r)} AND ${L(o, "rn", r)} <= ${z(g + h, r)}` : h === void 0 ? r` AND ${L(o, "rn", r)} > ${z(g, r)}` : r` AND ${L(o, "rn", r)} <= ${z(h, r)}`, ee = e.branch.onJunction === void 0 ? r`` : r` WHERE ${B(H(e.branch.onJunction), s, r)}`, v = I(o, e.target, e.children, n, c(Cr(o)));
|
|
985
1008
|
if (v === null) return null;
|
|
986
|
-
let te = e.junction === void 0 ? r`` :
|
|
1009
|
+
let te = e.junction === void 0 ? r`` : Sr(e.junction, s, r);
|
|
987
1010
|
return r`COALESCE((SELECT JSON_ARRAYAGG(${v} ORDER BY ${L(o, "rn", r)}) FROM (SELECT ${r(o)}.*${te}, ${L(s, i.sourceKey, r)} AS ${r(`__src_${i.sourceKey}`)}, ROW_NUMBER() OVER (PARTITION BY ${L(s, i.sourceKey, r)}${m}) AS rn FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${u}${ee}) AS ${r(o)} WHERE ${L(o, `__src_${i.sourceKey}`, r)} = ${L(t, "id", r)}${d}${_}), JSON_ARRAY())`;
|
|
988
|
-
},
|
|
989
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1011
|
+
}, Ir = (e, t, n) => {
|
|
1012
|
+
let r = n.sql, i = n.nextAlias(), a = Lr(i, t.table, t.children, n);
|
|
990
1013
|
if (a === null) return null;
|
|
991
1014
|
let o = e.predicate ? r` WHERE ${B(e.predicate, i, r)}` : r``, s = e.order.length > 0 ? r` ORDER BY ${r.csv(e.order.map((e) => e.direction === "desc" ? r`${L(i, e.column, r)} DESC` : r`${L(i, e.column, r)} ASC`))}` : r``, c = r``, l = r``;
|
|
992
1015
|
if (e.skip !== void 0) {
|
|
@@ -995,28 +1018,28 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
995
1018
|
} else e.take !== void 0 && (c = r`TOP ${z(e.take, r)} `);
|
|
996
1019
|
let u = e.skip === void 0 ? s : r``;
|
|
997
1020
|
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}`;
|
|
998
|
-
},
|
|
1021
|
+
}, Lr = (e, t, n, r, i) => {
|
|
999
1022
|
let a = r.sql, o = [];
|
|
1000
1023
|
for (let n of Object.keys(t.fields)) o.push(a`${L(e, n, a)} AS ${a(n)}`);
|
|
1001
|
-
if (i !== void 0) for (let e of i.projection.present) o.push(a`${L(i.source.alias, i.source.physical(e), a)} AS ${
|
|
1024
|
+
if (i !== void 0) for (let e of i.projection.present) o.push(a`${L(i.source.alias, i.source.physical(e), a)} AS ${Rr(`_junction.${e}`, a)}`);
|
|
1002
1025
|
for (let t of n) {
|
|
1003
|
-
let n =
|
|
1026
|
+
let n = zr(t, e, r);
|
|
1004
1027
|
if (n === null) return null;
|
|
1005
1028
|
o.push(n);
|
|
1006
1029
|
}
|
|
1007
1030
|
return a.csv(o);
|
|
1008
|
-
},
|
|
1031
|
+
}, Rr = (e, t) => t.unsafe(`[${e.replace(/]/g, "]]")}]`), zr = (e, t, n) => {
|
|
1009
1032
|
switch (e.relation.kind) {
|
|
1010
|
-
case "one": return P(e) ?
|
|
1011
|
-
case "many": return
|
|
1012
|
-
case "manyToMany": return
|
|
1033
|
+
case "one": return P(e) ? Hr(Zn(e), t, n) : Br(e, t, n);
|
|
1034
|
+
case "many": return Hr(e, t, n);
|
|
1035
|
+
case "manyToMany": return Ur(e, t, n);
|
|
1013
1036
|
}
|
|
1014
|
-
},
|
|
1015
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1037
|
+
}, Br = (e, t, n) => {
|
|
1038
|
+
let r = n.sql, i = n.nextAlias(), a = Lr(i, e.target, e.children, n);
|
|
1016
1039
|
if (a === null) return null;
|
|
1017
1040
|
let o = e.fkSide === "source" ? r`${L(i, "id", r)} = ${L(t, e.foreignKey, r)}` : r`${L(i, e.foreignKey, r)} = ${L(t, e.sourceKey, r)}`;
|
|
1018
1041
|
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)}`;
|
|
1019
|
-
},
|
|
1042
|
+
}, Vr = (e, t, n) => {
|
|
1020
1043
|
if (e.offset !== void 0) {
|
|
1021
1044
|
let r = e.orderBy && e.orderBy.length > 0 ? t : n` ORDER BY (SELECT NULL)`, i = e.limit === void 0 ? n`${r} OFFSET ${z(e.offset, n)} ROWS` : n`${r} OFFSET ${z(e.offset, n)} ROWS FETCH NEXT ${z(e.limit, n)} ROWS ONLY`;
|
|
1022
1045
|
return {
|
|
@@ -1030,29 +1053,29 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1030
1053
|
pagination: n``,
|
|
1031
1054
|
finalOrder: t
|
|
1032
1055
|
};
|
|
1033
|
-
},
|
|
1034
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1056
|
+
}, Hr = (e, t, n) => {
|
|
1057
|
+
let r = n.sql, i = n.nextAlias(), a = Lr(i, e.target, e.children, n);
|
|
1035
1058
|
if (a === null) return null;
|
|
1036
|
-
let o = e.branch.where === void 0 ? r`` : r` AND ${B(e.branch.where, i, r)}`, s = F(i, e.branch.orderBy, r), { top: c, pagination: l, finalOrder: u } =
|
|
1059
|
+
let o = e.branch.where === void 0 ? r`` : r` AND ${B(e.branch.where, i, r)}`, s = F(i, e.branch.orderBy, r), { top: c, pagination: l, finalOrder: u } = Vr(e.branch, s, r);
|
|
1037
1060
|
return r`ISNULL(JSON_QUERY((SELECT ${c}${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${L(i, e.foreignKey, r)} = ${L(t, e.sourceKey, r)}${o}${u}${l} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
|
|
1038
|
-
},
|
|
1039
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
1061
|
+
}, Ur = (e, t, n) => {
|
|
1062
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = Lr(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
1040
1063
|
projection: e.junction,
|
|
1041
|
-
source:
|
|
1064
|
+
source: wr(s)
|
|
1042
1065
|
});
|
|
1043
1066
|
if (c === null) return null;
|
|
1044
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${B(e.branch.where, o, r)}`, u = V(e, s, r), d = F(o, e.branch.orderBy, r), { top: f, pagination: p, finalOrder: m } =
|
|
1067
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${B(e.branch.where, o, r)}`, u = V(e, s, r), d = F(o, e.branch.orderBy, r), { top: f, pagination: p, finalOrder: m } = Vr(e.branch, d, r);
|
|
1045
1068
|
return r`ISNULL(JSON_QUERY((SELECT ${f}${c} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${L(o, "id", r)} = ${L(s, i.targetKey, r)} WHERE ${L(s, i.sourceKey, r)} = ${L(t, "id", r)}${u}${l}${m}${p} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
|
|
1046
1069
|
}, L = (e, t, n) => e === void 0 ? n`${n(t)}` : n`${n(e)}.${n(t)}`, R = (e, t) => t.unsafe(`'${e.replace(/'/g, "''")}'`), z = (e, t) => {
|
|
1047
1070
|
if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw Error(`literalInt: expected non-negative integer, got ${e}`);
|
|
1048
1071
|
return t.unsafe(String(e));
|
|
1049
|
-
}, B = (e, t, n) => M(
|
|
1072
|
+
}, B = (e, t, n) => M(Wr(e, t), n), V = (e, t, n, r = !1) => {
|
|
1050
1073
|
let i = e.branch.onJunction;
|
|
1051
1074
|
return i === void 0 ? n`` : n` AND ${B(r ? H(i) : i, t, n)}`;
|
|
1052
|
-
},
|
|
1053
|
-
if ("not" in e) return { not:
|
|
1054
|
-
if ("and" in e) return { and: e.and.map((e) =>
|
|
1055
|
-
if ("or" in e) return { or: e.or.map((e) =>
|
|
1075
|
+
}, Wr = (e, t) => {
|
|
1076
|
+
if ("not" in e) return { not: Wr(e.not, t) };
|
|
1077
|
+
if ("and" in e) return { and: e.and.map((e) => Wr(e, t)) };
|
|
1078
|
+
if ("or" in e) return { or: e.or.map((e) => Wr(e, t)) };
|
|
1056
1079
|
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
1057
1080
|
let n = e;
|
|
1058
1081
|
return {
|
|
@@ -1074,91 +1097,91 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1074
1097
|
let t = e;
|
|
1075
1098
|
return {
|
|
1076
1099
|
...t,
|
|
1077
|
-
value:
|
|
1100
|
+
value: Gr(t.value)
|
|
1078
1101
|
};
|
|
1079
|
-
},
|
|
1080
|
-
e.actors !== void 0 && (
|
|
1081
|
-
},
|
|
1102
|
+
}, Gr = (e) => e == null ? e : e instanceof Date ? e.toISOString() : typeof e == "boolean" ? +!!e : Array.isArray(e) ? e.map((e) => Gr(e)) : e, Kr = Symbol.for("@voltro/database/coreTablesRegistry"), qr = globalThis, Jr = qr[Kr] ?? (qr[Kr] = {}), Yr = (e) => {
|
|
1103
|
+
e.actors !== void 0 && (Jr.actors = e.actors), e.tenants !== void 0 && (Jr.tenants = e.tenants);
|
|
1104
|
+
}, Xr = (e, t) => () => {
|
|
1082
1105
|
let n = e();
|
|
1083
1106
|
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`);
|
|
1084
1107
|
return n();
|
|
1085
|
-
},
|
|
1086
|
-
id:
|
|
1087
|
-
kind:
|
|
1108
|
+
}, Zr = () => Xr(() => Jr.actors, "actors"), Qr = () => Xr(() => Jr.tenants, "tenants"), $r = _("actors", {
|
|
1109
|
+
id: l(),
|
|
1110
|
+
kind: h().oneOf([
|
|
1088
1111
|
"user",
|
|
1089
1112
|
"serviceAccount",
|
|
1090
1113
|
"apiKey",
|
|
1091
1114
|
"system"
|
|
1092
1115
|
]),
|
|
1093
|
-
displayName:
|
|
1094
|
-
createdAt:
|
|
1095
|
-
}),
|
|
1116
|
+
displayName: h().nullable(),
|
|
1117
|
+
createdAt: v().default("now")
|
|
1118
|
+
}), ei = (e, t) => ({
|
|
1096
1119
|
column: e,
|
|
1097
1120
|
op: "eq",
|
|
1098
1121
|
value: t
|
|
1099
|
-
}),
|
|
1122
|
+
}), ti = (e, t) => ({
|
|
1100
1123
|
column: e,
|
|
1101
1124
|
op: "neq",
|
|
1102
1125
|
value: t
|
|
1103
|
-
}),
|
|
1126
|
+
}), ni = (e, t) => ({
|
|
1104
1127
|
column: e,
|
|
1105
1128
|
op: "gt",
|
|
1106
1129
|
value: t
|
|
1107
|
-
}),
|
|
1130
|
+
}), ri = (e, t) => ({
|
|
1108
1131
|
column: e,
|
|
1109
1132
|
op: "gte",
|
|
1110
1133
|
value: t
|
|
1111
|
-
}),
|
|
1134
|
+
}), ii = (e, t) => ({
|
|
1112
1135
|
column: e,
|
|
1113
1136
|
op: "lt",
|
|
1114
1137
|
value: t
|
|
1115
|
-
}),
|
|
1138
|
+
}), ai = (e, t) => ({
|
|
1116
1139
|
column: e,
|
|
1117
1140
|
op: "lte",
|
|
1118
1141
|
value: t
|
|
1119
|
-
}),
|
|
1142
|
+
}), oi = (e, t) => ({
|
|
1120
1143
|
column: e,
|
|
1121
1144
|
op: "in",
|
|
1122
1145
|
value: t
|
|
1123
|
-
}),
|
|
1146
|
+
}), si = (e, t) => ({
|
|
1124
1147
|
column: e,
|
|
1125
1148
|
op: "notIn",
|
|
1126
1149
|
value: t
|
|
1127
|
-
}),
|
|
1150
|
+
}), ci = (e, t) => ({
|
|
1128
1151
|
column: e,
|
|
1129
1152
|
op: "contains",
|
|
1130
1153
|
value: t
|
|
1131
|
-
}),
|
|
1154
|
+
}), li = (e, t) => ({
|
|
1132
1155
|
column: e,
|
|
1133
1156
|
op: "startsWith",
|
|
1134
1157
|
value: t
|
|
1135
|
-
}),
|
|
1158
|
+
}), ui = (e, t) => ({
|
|
1136
1159
|
column: e,
|
|
1137
1160
|
op: "arrayContains",
|
|
1138
1161
|
value: t
|
|
1139
|
-
}),
|
|
1162
|
+
}), di = (e, t) => ({
|
|
1140
1163
|
column: e,
|
|
1141
1164
|
op: "arrayOverlaps",
|
|
1142
1165
|
value: t
|
|
1143
|
-
}),
|
|
1166
|
+
}), fi = (e, t) => ({
|
|
1144
1167
|
column: e,
|
|
1145
1168
|
op: "arrayHas",
|
|
1146
1169
|
value: t
|
|
1147
|
-
}),
|
|
1170
|
+
}), pi = {
|
|
1148
1171
|
column: "id",
|
|
1149
1172
|
op: "in",
|
|
1150
1173
|
value: []
|
|
1151
|
-
},
|
|
1174
|
+
}, mi = (e) => ({
|
|
1152
1175
|
column: e,
|
|
1153
1176
|
op: "isNull"
|
|
1154
|
-
}),
|
|
1177
|
+
}), hi = (e) => ({
|
|
1155
1178
|
column: e,
|
|
1156
1179
|
op: "isNotNull"
|
|
1157
|
-
}),
|
|
1180
|
+
}), gi = (e, t) => ({
|
|
1158
1181
|
column: e,
|
|
1159
1182
|
op: "spatial",
|
|
1160
1183
|
value: t
|
|
1161
|
-
}),
|
|
1184
|
+
}), _i = (...e) => ({ and: e }), vi = (...e) => ({ or: e }), yi = (e) => ({ not: e }), bi = (e, ...t) => {
|
|
1162
1185
|
if (t.length === 0) throw Error(`jsonField("${e}"): at least one path segment is required`);
|
|
1163
1186
|
let n = (n, r) => ({
|
|
1164
1187
|
column: e,
|
|
@@ -1180,29 +1203,29 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1180
1203
|
isNull: () => n("isNull"),
|
|
1181
1204
|
isNotNull: () => n("isNotNull")
|
|
1182
1205
|
};
|
|
1183
|
-
},
|
|
1206
|
+
}, xi = (e) => "descriptor" in e ? e.descriptor : e, Si = (e, t) => ({
|
|
1184
1207
|
column: e,
|
|
1185
1208
|
op: "subquery-in",
|
|
1186
|
-
subquery:
|
|
1187
|
-
}),
|
|
1209
|
+
subquery: xi(t)
|
|
1210
|
+
}), Ci = (e, t) => ({
|
|
1188
1211
|
column: e,
|
|
1189
1212
|
op: "subquery-not-in",
|
|
1190
|
-
subquery:
|
|
1191
|
-
}),
|
|
1213
|
+
subquery: xi(t)
|
|
1214
|
+
}), wi = (e) => ({
|
|
1192
1215
|
op: "exists",
|
|
1193
|
-
subquery:
|
|
1194
|
-
}),
|
|
1216
|
+
subquery: xi(e)
|
|
1217
|
+
}), Ti = (e) => ({
|
|
1195
1218
|
op: "not-exists",
|
|
1196
|
-
subquery:
|
|
1197
|
-
}),
|
|
1219
|
+
subquery: xi(e)
|
|
1220
|
+
}), Ei = (e, t) => e == null || t == null ? null : typeof e == typeof t ? e === t ? 0 : e > t ? 1 : -1 : null, Di = (e, t, n = null) => {
|
|
1198
1221
|
if (!t) return !1;
|
|
1199
|
-
if ("not" in e) return !
|
|
1222
|
+
if ("not" in e) return !Di(e.not, t, n);
|
|
1200
1223
|
if ("and" in e) {
|
|
1201
|
-
for (let r of e.and) if (!
|
|
1224
|
+
for (let r of e.and) if (!Di(r, t, n)) return !1;
|
|
1202
1225
|
return !0;
|
|
1203
1226
|
}
|
|
1204
1227
|
if ("or" in e) {
|
|
1205
|
-
for (let r of e.or) if (
|
|
1228
|
+
for (let r of e.or) if (Di(r, t, n)) return !0;
|
|
1206
1229
|
return !1;
|
|
1207
1230
|
}
|
|
1208
1231
|
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
@@ -1221,10 +1244,10 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1221
1244
|
switch (r.op) {
|
|
1222
1245
|
case "eq": return i === r.value;
|
|
1223
1246
|
case "neq": return i !== r.value;
|
|
1224
|
-
case "gt": return (
|
|
1225
|
-
case "gte": return (
|
|
1226
|
-
case "lt": return (
|
|
1227
|
-
case "lte": return (
|
|
1247
|
+
case "gt": return (Ei(i, r.value) ?? -1) > 0;
|
|
1248
|
+
case "gte": return (Ei(i, r.value) ?? -1) >= 0;
|
|
1249
|
+
case "lt": return (Ei(i, r.value) ?? 1) < 0;
|
|
1250
|
+
case "lte": return (Ei(i, r.value) ?? 1) <= 0;
|
|
1228
1251
|
case "in": return Array.isArray(r.value) && r.value.includes(i);
|
|
1229
1252
|
case "notIn": return Array.isArray(r.value) && !r.value.includes(i);
|
|
1230
1253
|
case "contains": return typeof i == "string" && typeof r.value == "string" && i.toLowerCase().includes(r.value.toLowerCase());
|
|
@@ -1242,17 +1265,17 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1242
1265
|
case "isNotNull": return i != null;
|
|
1243
1266
|
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.");
|
|
1244
1267
|
}
|
|
1245
|
-
},
|
|
1268
|
+
}, Oi = function* (e) {
|
|
1246
1269
|
if ("not" in e) {
|
|
1247
|
-
yield*
|
|
1270
|
+
yield* Oi(e.not);
|
|
1248
1271
|
return;
|
|
1249
1272
|
}
|
|
1250
1273
|
if ("and" in e) {
|
|
1251
|
-
for (let t of e.and) yield*
|
|
1274
|
+
for (let t of e.and) yield* Oi(t);
|
|
1252
1275
|
return;
|
|
1253
1276
|
}
|
|
1254
1277
|
if ("or" in e) {
|
|
1255
|
-
for (let t of e.or) yield*
|
|
1278
|
+
for (let t of e.or) yield* Oi(t);
|
|
1256
1279
|
return;
|
|
1257
1280
|
}
|
|
1258
1281
|
e.op === "subquery-in" || e.op === "subquery-not-in" ? yield {
|
|
@@ -1262,42 +1285,42 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1262
1285
|
kind: "exists",
|
|
1263
1286
|
descriptor: e.subquery
|
|
1264
1287
|
});
|
|
1265
|
-
},
|
|
1288
|
+
}, ki = function* (e, t = !0) {
|
|
1266
1289
|
if ("not" in e) {
|
|
1267
|
-
yield*
|
|
1290
|
+
yield* ki(e.not, !1);
|
|
1268
1291
|
return;
|
|
1269
1292
|
}
|
|
1270
1293
|
if ("and" in e) {
|
|
1271
|
-
for (let n of e.and) yield*
|
|
1294
|
+
for (let n of e.and) yield* ki(n, t);
|
|
1272
1295
|
return;
|
|
1273
1296
|
}
|
|
1274
1297
|
if ("or" in e) {
|
|
1275
|
-
for (let t of e.or) yield*
|
|
1298
|
+
for (let t of e.or) yield* ki(t, !1);
|
|
1276
1299
|
return;
|
|
1277
1300
|
}
|
|
1278
1301
|
e.op === "subquery-in" || e.op === "subquery-not-in" || e.op === "exists" || e.op === "not-exists" || (yield {
|
|
1279
1302
|
...e,
|
|
1280
1303
|
conjunctive: t
|
|
1281
1304
|
});
|
|
1282
|
-
}, U = new
|
|
1305
|
+
}, U = new bt(), Ai = (e, t) => U.run(e, t), ji = () => U.getStore(), Mi = (e) => {
|
|
1283
1306
|
let t = e ?? U.getStore();
|
|
1284
1307
|
return t === void 0 ? {} : {
|
|
1285
1308
|
...t.traceId === void 0 ? {} : { traceId: t.traceId },
|
|
1286
1309
|
...t.subjectId === void 0 ? {} : { subjectId: t.subjectId },
|
|
1287
1310
|
...t.procedure === void 0 ? {} : { procedure: t.procedure }
|
|
1288
1311
|
};
|
|
1289
|
-
},
|
|
1312
|
+
}, Ni = (e) => {
|
|
1290
1313
|
let t = U.getStore();
|
|
1291
1314
|
return t === void 0 ? e(void 0) : U.run(t, () => e(t));
|
|
1292
|
-
},
|
|
1315
|
+
}, Pi = 3e4, Fi = 1e4, W = /* @__PURE__ */ new Map(), G = 0, Ii = (e, t, n) => `${e}\u0000${t}\u0000${String(n)}`, Li = (e) => {
|
|
1293
1316
|
for (let [t, n] of W) {
|
|
1294
|
-
let r = n.filter((t) => e - t.at <
|
|
1317
|
+
let r = n.filter((t) => e - t.at < Pi);
|
|
1295
1318
|
G -= n.length - r.length, r.length === 0 ? W.delete(t) : r.length !== n.length && W.set(t, r);
|
|
1296
1319
|
}
|
|
1297
|
-
},
|
|
1320
|
+
}, Ri = (e, t) => {
|
|
1298
1321
|
if (t.traceId === void 0 && t.subjectId === void 0 && t.procedure === void 0) return;
|
|
1299
1322
|
let n = Date.now();
|
|
1300
|
-
if (G >=
|
|
1323
|
+
if (G >= Fi && Li(n), G >= Fi) return;
|
|
1301
1324
|
let r = W.get(e);
|
|
1302
1325
|
r === void 0 ? W.set(e, [{
|
|
1303
1326
|
attribution: t,
|
|
@@ -1306,34 +1329,34 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1306
1329
|
attribution: t,
|
|
1307
1330
|
at: n
|
|
1308
1331
|
}), G += 1;
|
|
1309
|
-
},
|
|
1332
|
+
}, zi = (e) => {
|
|
1310
1333
|
let t = W.get(e);
|
|
1311
1334
|
if (t === void 0 || t.length === 0) return;
|
|
1312
1335
|
let n = t.shift();
|
|
1313
|
-
if (--G, t.length === 0 && W.delete(e), !(Date.now() - n.at >=
|
|
1314
|
-
},
|
|
1336
|
+
if (--G, t.length === 0 && W.delete(e), !(Date.now() - n.at >= Pi)) return n.attribution;
|
|
1337
|
+
}, Bi = (e) => (W.get(e)?.length ?? 0) > 0, K = /* @__PURE__ */ new Map(), q = /* @__PURE__ */ new Map(), J = /* @__PURE__ */ new Map(), Vi = 250, Hi = (e) => {
|
|
1315
1338
|
let t = q.get(e);
|
|
1316
1339
|
if (t === void 0) return;
|
|
1317
1340
|
q.delete(e);
|
|
1318
|
-
let n =
|
|
1319
|
-
n !== void 0 && (clearTimeout(n),
|
|
1341
|
+
let n = J.get(e);
|
|
1342
|
+
n !== void 0 && (clearTimeout(n), J.delete(e));
|
|
1320
1343
|
for (let e of t) e();
|
|
1321
|
-
},
|
|
1344
|
+
}, Ui = (e) => {
|
|
1322
1345
|
K.set(e, (K.get(e) ?? 0) + 1);
|
|
1323
|
-
},
|
|
1346
|
+
}, Wi = (e) => {
|
|
1324
1347
|
let t = (K.get(e) ?? 0) - 1;
|
|
1325
1348
|
if (t > 0) {
|
|
1326
1349
|
K.set(e, t);
|
|
1327
1350
|
return;
|
|
1328
1351
|
}
|
|
1329
|
-
K.delete(e),
|
|
1330
|
-
},
|
|
1331
|
-
let i = n == null ? void 0 :
|
|
1352
|
+
K.delete(e), Hi(e);
|
|
1353
|
+
}, Gi = (e, t, n, r) => {
|
|
1354
|
+
let i = n == null ? void 0 : Ii(e, t, n), a = () => r(i === void 0 ? void 0 : zi(i));
|
|
1332
1355
|
if (i === void 0) {
|
|
1333
1356
|
a();
|
|
1334
1357
|
return;
|
|
1335
1358
|
}
|
|
1336
|
-
if (
|
|
1359
|
+
if (Bi(i)) {
|
|
1337
1360
|
a();
|
|
1338
1361
|
return;
|
|
1339
1362
|
}
|
|
@@ -1347,37 +1370,37 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1347
1370
|
return;
|
|
1348
1371
|
}
|
|
1349
1372
|
q.set(e, [a]);
|
|
1350
|
-
let s = setTimeout(() =>
|
|
1351
|
-
typeof s == "object" && typeof s.unref == "function" && s.unref(),
|
|
1352
|
-
},
|
|
1373
|
+
let s = setTimeout(() => Hi(e), Vi);
|
|
1374
|
+
typeof s == "object" && typeof s.unref == "function" && s.unref(), J.set(e, s);
|
|
1375
|
+
}, Ki = () => {
|
|
1353
1376
|
W.clear(), G = 0, K.clear();
|
|
1354
|
-
for (let e of
|
|
1355
|
-
|
|
1356
|
-
},
|
|
1357
|
-
|
|
1377
|
+
for (let e of J.values()) clearTimeout(e);
|
|
1378
|
+
J.clear(), q.clear();
|
|
1379
|
+
}, qi = () => G, Y = /* @__PURE__ */ new Map(), Ji = (e, t) => {
|
|
1380
|
+
Y.set(e, {
|
|
1358
1381
|
recorder: t.recorder,
|
|
1359
1382
|
tables: new Set(t.tables),
|
|
1360
1383
|
ownTables: new Set(t.ownTables)
|
|
1361
1384
|
});
|
|
1362
|
-
},
|
|
1363
|
-
|
|
1364
|
-
},
|
|
1365
|
-
if (
|
|
1366
|
-
for (let t of
|
|
1385
|
+
}, Yi = (e) => {
|
|
1386
|
+
Y.delete(e);
|
|
1387
|
+
}, Xi = () => Y.clear(), Zi = (e) => {
|
|
1388
|
+
if (Y.size === 0) return !1;
|
|
1389
|
+
for (let t of Y.values()) if (!t.ownTables.has(e) && t.tables.has(e)) return !0;
|
|
1367
1390
|
return !1;
|
|
1368
|
-
},
|
|
1369
|
-
if (
|
|
1370
|
-
},
|
|
1371
|
-
if (
|
|
1372
|
-
throw
|
|
1373
|
-
},
|
|
1391
|
+
}, Qi = async (e, t) => {
|
|
1392
|
+
if (Y.size !== 0) for (let n of Y.values()) n.ownTables.has(t.table) || n.tables.has(t.table) && await n.recorder(e, t);
|
|
1393
|
+
}, $i = (e) => {
|
|
1394
|
+
if (vt.isSuccess(e)) return e.value;
|
|
1395
|
+
throw mt.squash(e.cause);
|
|
1396
|
+
}, ea = class extends E.TaggedError()("VersionConflict", {
|
|
1374
1397
|
table: E.String,
|
|
1375
1398
|
id: E.String,
|
|
1376
1399
|
expected: E.Number,
|
|
1377
1400
|
actual: E.NullOr(E.Number)
|
|
1378
|
-
}) {},
|
|
1401
|
+
}) {}, ta = (e) => {
|
|
1379
1402
|
for (let [t, n] of Object.entries(e)) if (n?.definition?.versionColumn === !0) return t;
|
|
1380
|
-
},
|
|
1403
|
+
}, na = (e) => {
|
|
1381
1404
|
let { versionColumn: t, patch: n } = e;
|
|
1382
1405
|
if (t === void 0) return {
|
|
1383
1406
|
nextVersion: void 0,
|
|
@@ -1390,21 +1413,21 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1390
1413
|
expected: i,
|
|
1391
1414
|
patch: a
|
|
1392
1415
|
};
|
|
1393
|
-
},
|
|
1394
|
-
if (e.expected !== void 0 && !(e.current !== null && e.current === e.expected)) return new
|
|
1416
|
+
}, ra = (e) => {
|
|
1417
|
+
if (e.expected !== void 0 && !(e.current !== null && e.current === e.expected)) return new ea({
|
|
1395
1418
|
table: e.table,
|
|
1396
1419
|
id: e.id,
|
|
1397
1420
|
expected: e.expected,
|
|
1398
1421
|
actual: e.current
|
|
1399
1422
|
});
|
|
1400
|
-
},
|
|
1401
|
-
id:
|
|
1402
|
-
fields: { expiresAt:
|
|
1423
|
+
}, ia = 1, aa = "voltro/expires", oa = () => g({
|
|
1424
|
+
id: aa,
|
|
1425
|
+
fields: { expiresAt: v().nullable() },
|
|
1403
1426
|
behaviors: { defaultWhere: () => "expiresAt IS NULL OR expiresAt > now()" }
|
|
1404
|
-
}),
|
|
1405
|
-
let i =
|
|
1427
|
+
}), sa = class extends gt.TaggedError("TableStreamError") {}, ca = 1e3, la = (e, t, n, r) => {
|
|
1428
|
+
let i = T.match(r, {
|
|
1406
1429
|
onNone: () => e.where,
|
|
1407
|
-
onSome: (n) => e.where ?
|
|
1430
|
+
onSome: (n) => e.where ? _i(e.where, ni(t, n)) : ni(t, n)
|
|
1408
1431
|
});
|
|
1409
1432
|
return {
|
|
1410
1433
|
table: e.table,
|
|
@@ -1419,19 +1442,19 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1419
1442
|
...e.includeDeleted === void 0 ? {} : { includeDeleted: e.includeDeleted },
|
|
1420
1443
|
...e.crossTenant === void 0 ? {} : { crossTenant: e.crossTenant }
|
|
1421
1444
|
};
|
|
1422
|
-
},
|
|
1423
|
-
let n = t.pk ?? "id", r = t.chunkSize ??
|
|
1424
|
-
return
|
|
1425
|
-
let a =
|
|
1426
|
-
try: () => e.query(
|
|
1427
|
-
catch: (e) => new
|
|
1445
|
+
}, ua = (e, t) => {
|
|
1446
|
+
let n = t.pk ?? "id", r = t.chunkSize ?? ca;
|
|
1447
|
+
return yt.paginateChunkEffect(T.none(), (i) => {
|
|
1448
|
+
let a = _t.tryPromise({
|
|
1449
|
+
try: () => e.query(la(t, n, r, i)),
|
|
1450
|
+
catch: (e) => new sa({
|
|
1428
1451
|
table: t.table,
|
|
1429
1452
|
cause: e
|
|
1430
1453
|
})
|
|
1431
1454
|
});
|
|
1432
|
-
return (t.retry ? a.pipe(
|
|
1455
|
+
return (t.retry ? a.pipe(_t.retry(t.retry)) : a).pipe(_t.map((e) => [ht.fromIterable(e), e.length === r && e.length > 0 ? T.some(T.some(e[e.length - 1][n])) : T.none()]));
|
|
1433
1456
|
});
|
|
1434
|
-
},
|
|
1457
|
+
}, da = (e) => {
|
|
1435
1458
|
let t = e.alpha ?? .5;
|
|
1436
1459
|
if (t < 0 || t > 1) throw Error(`hybridSearch: alpha must be in [0, 1], got ${t}`);
|
|
1437
1460
|
return (n) => {
|
|
@@ -1445,7 +1468,7 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1445
1468
|
queryText: e.vector.query,
|
|
1446
1469
|
distance: e.vector.distance ?? "cosine",
|
|
1447
1470
|
alpha: t
|
|
1448
|
-
}, i =
|
|
1471
|
+
}, i = ze(n.table, e.fts.indexName, n.fullTextIndexes);
|
|
1449
1472
|
return {
|
|
1450
1473
|
...n,
|
|
1451
1474
|
annClause: r,
|
|
@@ -1458,17 +1481,17 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1458
1481
|
}
|
|
1459
1482
|
};
|
|
1460
1483
|
};
|
|
1461
|
-
},
|
|
1484
|
+
}, fa = async (e, t) => {
|
|
1462
1485
|
let n = e.as ?? "embedding", r = t.row[e.from];
|
|
1463
1486
|
if (typeof r != "string" || r.length === 0) return {};
|
|
1464
1487
|
let i = await t.embed(r);
|
|
1465
1488
|
return { [n]: i };
|
|
1466
|
-
},
|
|
1489
|
+
}, pa = (e) => {
|
|
1467
1490
|
if (!Number.isInteger(e.dimensions) || e.dimensions <= 0) throw Error(`vectorEmbedding: dimensions must be a positive integer, got ${String(e.dimensions)}.`);
|
|
1468
|
-
let t = e.as ?? "embedding", n = (t) =>
|
|
1491
|
+
let t = e.as ?? "embedding", n = (t) => fa(e, t);
|
|
1469
1492
|
return g({
|
|
1470
1493
|
id: "voltro/vectorEmbedding",
|
|
1471
|
-
fields: { [t]:
|
|
1494
|
+
fields: { [t]: se(e.dimensions) },
|
|
1472
1495
|
...e.index === !1 ? {} : { indexes: [{
|
|
1473
1496
|
fields: [t],
|
|
1474
1497
|
kind: "hnsw",
|
|
@@ -1483,19 +1506,19 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1483
1506
|
beforeUpdate: n
|
|
1484
1507
|
}
|
|
1485
1508
|
});
|
|
1486
|
-
},
|
|
1509
|
+
}, ma = 63, ha = "br_pr", X = class extends Error {
|
|
1487
1510
|
_tag = "BranchNameInvalid";
|
|
1488
1511
|
constructor(e) {
|
|
1489
1512
|
super(e), this.name = "BranchNameInvalid";
|
|
1490
1513
|
}
|
|
1491
|
-
},
|
|
1492
|
-
if (!Number.isInteger(t) || t < 0) throw new
|
|
1493
|
-
let n =
|
|
1494
|
-
if (n.replace(/_/g, "") === "") throw new
|
|
1495
|
-
let r = `${
|
|
1496
|
-
if (r.length >
|
|
1514
|
+
}, ga = (e, t) => {
|
|
1515
|
+
if (!Number.isInteger(t) || t < 0) throw new X(`prNumber must be a non-negative integer, got ${String(t)}`);
|
|
1516
|
+
let n = Mn(e);
|
|
1517
|
+
if (n.replace(/_/g, "") === "") throw new X(`app slug '${e}' has no usable identifier characters`);
|
|
1518
|
+
let r = `${ha}${t}_${n}`;
|
|
1519
|
+
if (r.length > ma) throw new X(`branch namespace '${r}' exceeds the ${ma}-byte identifier limit — use a shorter app slug`);
|
|
1497
1520
|
return r;
|
|
1498
|
-
},
|
|
1521
|
+
}, _a = (e) => e.startsWith(ha), va = {
|
|
1499
1522
|
requested: {
|
|
1500
1523
|
provision: "provisioning",
|
|
1501
1524
|
destroy: "destroying"
|
|
@@ -1514,19 +1537,19 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1514
1537
|
fail: "failed"
|
|
1515
1538
|
},
|
|
1516
1539
|
destroyed: {}
|
|
1517
|
-
},
|
|
1540
|
+
}, ya = class extends Error {
|
|
1518
1541
|
from;
|
|
1519
1542
|
event;
|
|
1520
1543
|
_tag = "BranchTransitionInvalid";
|
|
1521
1544
|
constructor(e, t) {
|
|
1522
1545
|
super(`invalid branch transition: ${e} --${t}-->`), this.from = e, this.event = t, this.name = "BranchTransitionInvalid";
|
|
1523
1546
|
}
|
|
1524
|
-
},
|
|
1525
|
-
let n =
|
|
1526
|
-
if (n === void 0) throw new
|
|
1547
|
+
}, ba = (e, t) => {
|
|
1548
|
+
let n = va[e][t];
|
|
1549
|
+
if (n === void 0) throw new ya(e, t);
|
|
1527
1550
|
return n;
|
|
1528
|
-
},
|
|
1529
|
-
if (n === "copy" && (r === void 0 || r === "")) throw new
|
|
1551
|
+
}, xa = (e, t, n, r) => {
|
|
1552
|
+
if (n === "copy" && (r === void 0 || r === "")) throw new X("seed 'copy' requires a parentNamespace to snapshot from");
|
|
1530
1553
|
let i = [{
|
|
1531
1554
|
kind: "create-namespace",
|
|
1532
1555
|
detail: e
|
|
@@ -1546,13 +1569,13 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1546
1569
|
detail: `run boot seeds into ${e}`
|
|
1547
1570
|
});
|
|
1548
1571
|
return i;
|
|
1549
|
-
},
|
|
1550
|
-
if (!
|
|
1572
|
+
}, Sa = (e) => {
|
|
1573
|
+
if (!_a(e)) throw new X(`refusing to plan teardown of '${e}' — not a branch namespace`);
|
|
1551
1574
|
return [{
|
|
1552
1575
|
kind: "drop-namespace",
|
|
1553
1576
|
detail: e
|
|
1554
1577
|
}];
|
|
1555
|
-
},
|
|
1578
|
+
}, Ca = (e) => {
|
|
1556
1579
|
if (e === void 0 || e === "") return !1;
|
|
1557
1580
|
try {
|
|
1558
1581
|
let t = new URL(e).hostname.toLowerCase();
|
|
@@ -1560,27 +1583,27 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1560
1583
|
} catch {
|
|
1561
1584
|
return /\bneon\.(tech|build)\b/i.test(e);
|
|
1562
1585
|
}
|
|
1563
|
-
},
|
|
1586
|
+
}, wa = (e) => e.prefer === void 0 ? e.seed === "copy" && Ca(e.dbUrl) ? "neon-cow" : "namespace" : e.prefer, Ta = (e, t = {}) => [{
|
|
1564
1587
|
kind: "neon-branch-create",
|
|
1565
1588
|
detail: `${t.parentBranch ?? "main"} → ${e} (copy-on-write)`
|
|
1566
|
-
}],
|
|
1567
|
-
if (!
|
|
1589
|
+
}], Ea = (e) => {
|
|
1590
|
+
if (!_a(e)) throw new X(`refusing to plan teardown of '${e}' — not a branch namespace`);
|
|
1568
1591
|
return [{
|
|
1569
1592
|
kind: "neon-branch-delete",
|
|
1570
1593
|
detail: e
|
|
1571
1594
|
}];
|
|
1572
|
-
},
|
|
1595
|
+
}, Da = (e) => e.mechanism === "neon-cow" ? Ta(e.branchId, e.neonParentBranch === void 0 ? {} : { parentBranch: e.neonParentBranch }) : xa(e.branchId, e.tableNames, e.seed, e.parentNamespace), Oa = (e, t) => e === "neon-cow" ? Ea(t) : Sa(t), ka = (e, t, n) => {
|
|
1573
1596
|
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);
|
|
1574
1597
|
return {
|
|
1575
1598
|
evict: i,
|
|
1576
1599
|
rejectNew: r.filter((e) => !a.has(e.namespace)).length >= t.maxBranches
|
|
1577
1600
|
};
|
|
1578
|
-
},
|
|
1579
|
-
let n =
|
|
1601
|
+
}, Aa = async (e, t) => {
|
|
1602
|
+
let n = ga(e.appSlug, e.prNumber), r = wa({
|
|
1580
1603
|
seed: e.seed,
|
|
1581
1604
|
...e.dbUrl === void 0 ? {} : { dbUrl: e.dbUrl },
|
|
1582
1605
|
...e.prefer === void 0 ? {} : { prefer: e.prefer }
|
|
1583
|
-
}), i =
|
|
1606
|
+
}), i = Da({
|
|
1584
1607
|
mechanism: r,
|
|
1585
1608
|
branchId: n,
|
|
1586
1609
|
tableNames: e.tableNames,
|
|
@@ -1605,33 +1628,33 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1605
1628
|
mechanism: r,
|
|
1606
1629
|
steps: i
|
|
1607
1630
|
};
|
|
1608
|
-
},
|
|
1609
|
-
let r =
|
|
1631
|
+
}, ja = async (e, t, n) => {
|
|
1632
|
+
let r = Oa(t, e);
|
|
1610
1633
|
return t === "neon-cow" ? await n.neonBranchDelete(e) : await n.dropNamespace(e), r;
|
|
1611
|
-
},
|
|
1634
|
+
}, Ma = (e, t, n) => ka(e, t, n), Z = (e) => `"${e.replace(/"/g, "\"\"")}"`, Na = (e) => {
|
|
1612
1635
|
let t = () => {
|
|
1613
1636
|
throw Error("namespace branch executor: Neon ops require a neon-cow executor (use a Neon connection for copy-on-write branches)");
|
|
1614
1637
|
};
|
|
1615
1638
|
return {
|
|
1616
|
-
createNamespace: (t) => e.run(`CREATE SCHEMA IF NOT EXISTS ${
|
|
1617
|
-
createTable: (t, n) => e.run(`CREATE TABLE IF NOT EXISTS ${
|
|
1618
|
-
copyTable: (t, n, r) => e.run(`INSERT INTO ${
|
|
1619
|
-
dropNamespace: (t) => e.run(`DROP SCHEMA IF EXISTS ${
|
|
1639
|
+
createNamespace: (t) => e.run(`CREATE SCHEMA IF NOT EXISTS ${Z(t)}`),
|
|
1640
|
+
createTable: (t, n) => e.run(`CREATE TABLE IF NOT EXISTS ${Z(t)}.${Z(n)} (LIKE ${Z(n)} INCLUDING ALL)`),
|
|
1641
|
+
copyTable: (t, n, r) => e.run(`INSERT INTO ${Z(n)}.${Z(r)} SELECT * FROM ${Z(t)}.${Z(r)}`),
|
|
1642
|
+
dropNamespace: (t) => e.run(`DROP SCHEMA IF EXISTS ${Z(t)} CASCADE`),
|
|
1620
1643
|
neonBranchCreate: t,
|
|
1621
1644
|
neonBranchDelete: t
|
|
1622
1645
|
};
|
|
1623
|
-
},
|
|
1646
|
+
}, Pa = class extends Error {
|
|
1624
1647
|
_tag = "TenantResidencyUnresolved";
|
|
1625
1648
|
constructor(e) {
|
|
1626
1649
|
super(e), this.name = "TenantResidencyUnresolved";
|
|
1627
1650
|
}
|
|
1628
|
-
},
|
|
1651
|
+
}, Fa = class extends Error {
|
|
1629
1652
|
region;
|
|
1630
1653
|
_tag = "TenantRegionUnavailable";
|
|
1631
1654
|
constructor(e, t) {
|
|
1632
1655
|
super(t), this.region = e, this.name = "TenantRegionUnavailable";
|
|
1633
1656
|
}
|
|
1634
|
-
},
|
|
1657
|
+
}, Ia, La = (e) => {
|
|
1635
1658
|
if (e.homes === void 0) throw Error("setResidencyConfig: `homes` is required");
|
|
1636
1659
|
if (e.servableRegions === void 0 || e.servableRegions.length === 0) throw Error("setResidencyConfig: `servableRegions` must be non-empty (which regions this deployment serves)");
|
|
1637
1660
|
let t = /* @__PURE__ */ new Map();
|
|
@@ -1640,98 +1663,98 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1640
1663
|
if (e !== void 0 && e !== n.region) throw Error(`residency: tenant '${n.tenantId}' is mapped to two regions ('${e}' and '${n.region}')`);
|
|
1641
1664
|
t.set(n.tenantId, n.region);
|
|
1642
1665
|
}
|
|
1643
|
-
return
|
|
1644
|
-
},
|
|
1645
|
-
|
|
1646
|
-
},
|
|
1647
|
-
if (e == null || e === "") throw new
|
|
1666
|
+
return Ia = e, e;
|
|
1667
|
+
}, Ra = () => Ia, za = () => {
|
|
1668
|
+
Ia = void 0;
|
|
1669
|
+
}, Ba = (e, t) => {
|
|
1670
|
+
if (e == null || e === "") throw new Pa("residency is on but the request has no resolvable tenant — refusing to bind a store");
|
|
1648
1671
|
let n = t.homes.find((t) => t.tenantId === e);
|
|
1649
|
-
if (n === void 0) throw new
|
|
1672
|
+
if (n === void 0) throw new Pa(`no residency home is mapped for tenant '${e}' — refusing to fall back to a default store (would be a residency violation)`);
|
|
1650
1673
|
return n;
|
|
1651
|
-
},
|
|
1652
|
-
let n =
|
|
1674
|
+
}, Va = (e, t) => t.servableRegions.includes(e), Ha = (e, t) => {
|
|
1675
|
+
let n = Ba(e.tenantId, t), r = Nn(n.tenantId);
|
|
1653
1676
|
return {
|
|
1654
1677
|
region: n.region,
|
|
1655
1678
|
namespace: r,
|
|
1656
1679
|
...n.connectionKey === void 0 ? {} : { connectionKey: n.connectionKey }
|
|
1657
1680
|
};
|
|
1658
|
-
},
|
|
1659
|
-
let r =
|
|
1660
|
-
if (!
|
|
1681
|
+
}, Ua = (e, t, n) => {
|
|
1682
|
+
let r = Ha(e, t);
|
|
1683
|
+
if (!Va(r.region, t)) throw new Fa(r.region, `tenant homed in region '${r.region}', which this deployment does not serve — route to the home region`);
|
|
1661
1684
|
let i = n.get(r.region);
|
|
1662
|
-
if (i === void 0) throw new
|
|
1685
|
+
if (i === void 0) throw new Fa(r.region, `no store handle for home region '${r.region}' (declared servable but not wired) — failing closed`);
|
|
1663
1686
|
return {
|
|
1664
1687
|
store: i,
|
|
1665
1688
|
placement: r
|
|
1666
1689
|
};
|
|
1667
|
-
},
|
|
1668
|
-
let { store: i, placement: a } =
|
|
1690
|
+
}, Wa = async (e, t, n, r) => {
|
|
1691
|
+
let { store: i, placement: a } = Ua(e, t, n);
|
|
1669
1692
|
return await r(i, a), a;
|
|
1670
|
-
},
|
|
1693
|
+
}, Ga = (e) => {
|
|
1671
1694
|
if (typeof e == "string") return e;
|
|
1672
1695
|
if ("jsonPath" in e) {
|
|
1673
1696
|
let { column: t, path: n, numeric: r } = e.jsonPath;
|
|
1674
1697
|
return `(json:${t}->${n.join(".")}${r ? "::num" : ""})`;
|
|
1675
1698
|
}
|
|
1676
1699
|
return `(${e.expr})`;
|
|
1677
|
-
},
|
|
1700
|
+
}, Q = (e) => e.map(Ga), Ka = (e, t) => {
|
|
1678
1701
|
if (e.length !== t.length) return !1;
|
|
1679
|
-
for (let n = 0; n < e.length; n++) if (
|
|
1702
|
+
for (let n = 0; n < e.length; n++) if (Ga(e[n]) !== Ga(t[n])) return !1;
|
|
1680
1703
|
return !0;
|
|
1681
|
-
},
|
|
1704
|
+
}, qa = (e, t) => {
|
|
1682
1705
|
if (e.length >= t.length) return !1;
|
|
1683
|
-
for (let n = 0; n < e.length; n++) if (
|
|
1706
|
+
for (let n = 0; n < e.length; n++) if (Ga(e[n]) !== Ga(t[n])) return !1;
|
|
1684
1707
|
return !0;
|
|
1685
|
-
},
|
|
1708
|
+
}, Ja = (e) => {
|
|
1686
1709
|
let t = [], n = e.appliedIndexes, r = e.tableName;
|
|
1687
1710
|
for (let e = 0; e < n.length; e++) {
|
|
1688
1711
|
let i = n[e];
|
|
1689
1712
|
for (let a = e + 1; a < n.length; a++) {
|
|
1690
1713
|
let e = n[a];
|
|
1691
|
-
if (
|
|
1714
|
+
if (Ka(i.fields, e.fields)) {
|
|
1692
1715
|
let [n, a] = i.name < e.name ? [i, e] : [e, i];
|
|
1693
1716
|
t.push({
|
|
1694
1717
|
kind: "duplicate-fields",
|
|
1695
1718
|
table: r,
|
|
1696
1719
|
redundant: n,
|
|
1697
1720
|
coveredBy: a,
|
|
1698
|
-
message: `'${r}' has two indexes on the same fields [${
|
|
1721
|
+
message: `'${r}' has two indexes on the same fields [${Q(i.fields).join(", ")}]: '${i.name}' and '${e.name}'. The B-tree engine builds both, costing write throughput + disk space for no read benefit. Drop '${n.name}' (or '${a.name}' if you prefer the other name). Applies to every supported dialect (Postgres / MySQL / MariaDB / MSSQL / SQLite).`
|
|
1699
1722
|
});
|
|
1700
1723
|
continue;
|
|
1701
1724
|
}
|
|
1702
|
-
|
|
1725
|
+
qa(i.fields, e.fields) ? t.push({
|
|
1703
1726
|
kind: "redundant-prefix",
|
|
1704
1727
|
table: r,
|
|
1705
1728
|
redundant: i,
|
|
1706
1729
|
coveredBy: e,
|
|
1707
|
-
message: `'${r}' index '${i.name}' on [${
|
|
1708
|
-
}) :
|
|
1730
|
+
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).`
|
|
1731
|
+
}) : qa(e.fields, i.fields) && t.push({
|
|
1709
1732
|
kind: "redundant-prefix",
|
|
1710
1733
|
table: r,
|
|
1711
1734
|
redundant: e,
|
|
1712
1735
|
coveredBy: i,
|
|
1713
|
-
message: `'${r}' index '${e.name}' on [${
|
|
1736
|
+
message: `'${r}' index '${e.name}' on [${Q(e.fields).join(", ")}] is a leading prefix of '${i.name}' on [${Q(i.fields).join(", ")}]. Every B-tree dialect we support (Postgres / MySQL / MariaDB / MSSQL / SQLite) can serve a [${Q(e.fields).join(", ")}] query from '${i.name}' too via the leading-prefix rule, so '${e.name}' adds write cost without read benefit. Drop '${e.name}' — unless you specifically need a smaller index for cache locality on a write-heavy table (rare; profile first).`
|
|
1714
1737
|
});
|
|
1715
1738
|
}
|
|
1716
1739
|
}
|
|
1717
1740
|
return t;
|
|
1718
|
-
},
|
|
1741
|
+
}, Ya = (e) => {
|
|
1719
1742
|
let t = [];
|
|
1720
|
-
for (let n of e) t.push(...
|
|
1743
|
+
for (let n of e) t.push(...Ja(n));
|
|
1721
1744
|
return t;
|
|
1722
|
-
},
|
|
1723
|
-
let n = t.color ?? !0, r = t.indent ?? " ", i = (e) =>
|
|
1745
|
+
}, Xa = "\x1B[", Za = `${Xa}38;2;245;158;11m`, Qa = `${Xa}38;2;16;185;129m`, $a = (e, t) => `${e}${t}${D.reset}`, $ = (e, t, n) => e ? typeof t == "function" ? t(n) : $a(t, n) : n, eo = (e, t = {}) => {
|
|
1746
|
+
let n = t.color ?? !0, r = t.indent ?? " ", i = (e) => $(n, D.dim, e.padEnd(11)), a = (e) => $(n, (e) => D.bold(D.brand(e)), e), o = (e) => $(n, D.brightRed24, e), s = (e) => $(n, Qa, e), c = (e) => $(n, Za, e), l = (e) => $(n, D.dim, e), u = `${c("index audit")} ${l("·")} ${$(n, D.bold, e.kind)}`, d = e.redundant.fields.length, f = Q(e.coveredBy.fields.slice(d)), p = (e, t) => {
|
|
1724
1747
|
let n = e.slice(0, t), r = e.slice(t), i = [];
|
|
1725
1748
|
return n.length > 0 && i.push(s(`[${n.join(", ")}]`)), r.length > 0 && i.push(c(`+ [${r.join(", ")}]`)), i.join(" ");
|
|
1726
1749
|
}, m = [];
|
|
1727
|
-
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(
|
|
1728
|
-
},
|
|
1750
|
+
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, D.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");
|
|
1751
|
+
}, to = (e, t) => ({
|
|
1729
1752
|
name: e,
|
|
1730
1753
|
body: t
|
|
1731
|
-
}),
|
|
1754
|
+
}), no = (e) => {
|
|
1732
1755
|
if (e.lifecycle === "cron" && !e.cron) throw Error(`seed "${e.id}": lifecycle 'cron' requires a 'cron' field`);
|
|
1733
1756
|
if (e.lifecycle === "onSchemaChange" && (!e.watchedTables || e.watchedTables.length === 0)) throw Error(`seed "${e.id}": lifecycle 'onSchemaChange' requires at least one entry in 'watchedTables'`);
|
|
1734
|
-
let t = e.steps({ step:
|
|
1757
|
+
let t = e.steps({ step: to });
|
|
1735
1758
|
if (t.length === 0) throw Error(`seed "${e.id}": at least one step is required`);
|
|
1736
1759
|
return {
|
|
1737
1760
|
__seed: !0,
|
|
@@ -1743,13 +1766,13 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1743
1766
|
...e.fingerprint === void 0 ? {} : { fingerprint: e.fingerprint },
|
|
1744
1767
|
steps: t
|
|
1745
1768
|
};
|
|
1746
|
-
},
|
|
1769
|
+
}, ro = (e) => typeof e == "object" && !!e && "__seed" in e && e.__seed === !0, io = (e, { apply: t, undo: n }) => ({
|
|
1747
1770
|
name: e,
|
|
1748
1771
|
apply: t,
|
|
1749
1772
|
undo: n
|
|
1750
|
-
}),
|
|
1773
|
+
}), ao = (e) => {
|
|
1751
1774
|
if (!/^\d{14}_/.test(e.id)) throw Error(`migration "${e.id}": id must start with a 14-digit timestamp followed by "_" (convention: <YYYYMMDDHHMMSS>_<slug>)`);
|
|
1752
|
-
let t = e.steps({ step:
|
|
1775
|
+
let t = e.steps({ step: io });
|
|
1753
1776
|
if (t.length === 0) throw Error(`migration "${e.id}": at least one step is required`);
|
|
1754
1777
|
return {
|
|
1755
1778
|
__migration: !0,
|
|
@@ -1757,145 +1780,145 @@ var bt = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1757
1780
|
name: e.name,
|
|
1758
1781
|
steps: t
|
|
1759
1782
|
};
|
|
1760
|
-
},
|
|
1761
|
-
id:
|
|
1762
|
-
name:
|
|
1763
|
-
hash:
|
|
1764
|
-
status:
|
|
1765
|
-
appliedAt:
|
|
1766
|
-
durationMs:
|
|
1767
|
-
errorMessage:
|
|
1768
|
-
errorStack:
|
|
1769
|
-
workflowRunId:
|
|
1770
|
-
createdAt:
|
|
1771
|
-
updatedAt:
|
|
1772
|
-
}).index(["status"]),
|
|
1773
|
-
id:
|
|
1774
|
-
name:
|
|
1775
|
-
lifecycle:
|
|
1776
|
-
fingerprint:
|
|
1777
|
-
cronSchedule:
|
|
1778
|
-
watchedTables:
|
|
1779
|
-
nextRunAt:
|
|
1780
|
-
lastRunStatus:
|
|
1781
|
-
lastRunAt:
|
|
1782
|
-
lastRunDurationMs:
|
|
1783
|
-
lastRunRowsTouched:
|
|
1784
|
-
lastError:
|
|
1785
|
-
workflowRunId:
|
|
1786
|
-
createdAt:
|
|
1787
|
-
updatedAt:
|
|
1788
|
-
}).index(["lifecycle"]).index(["nextRunAt"]),
|
|
1789
|
-
id:
|
|
1790
|
-
fingerprint:
|
|
1791
|
-
liveFingerprint:
|
|
1792
|
-
operations:
|
|
1793
|
-
rollbackPlan:
|
|
1794
|
-
appliedBy:
|
|
1795
|
-
environment:
|
|
1796
|
-
source:
|
|
1797
|
-
onlineStrategy:
|
|
1798
|
-
durationMs:
|
|
1799
|
-
notes:
|
|
1800
|
-
squashedAt:
|
|
1801
|
-
appliedAt:
|
|
1802
|
-
createdAt:
|
|
1803
|
-
updatedAt:
|
|
1804
|
-
}).index(["fingerprint"]).index(["environment"]),
|
|
1805
|
-
id:
|
|
1806
|
-
scope:
|
|
1807
|
-
key:
|
|
1808
|
-
status:
|
|
1809
|
-
response:
|
|
1810
|
-
createdAt:
|
|
1811
|
-
}).unique(["scope", "key"]).index(["createdAt"]),
|
|
1812
|
-
id:
|
|
1813
|
-
key:
|
|
1814
|
-
value:
|
|
1815
|
-
expiresAt:
|
|
1816
|
-
createdAt:
|
|
1817
|
-
updatedAt:
|
|
1818
|
-
}).index(["expiresAt"]),
|
|
1819
|
-
id:
|
|
1820
|
-
tenantId:
|
|
1821
|
-
name:
|
|
1822
|
-
hashedKey:
|
|
1823
|
-
keyPrefix:
|
|
1824
|
-
scopes:
|
|
1825
|
-
lastUsedAt:
|
|
1826
|
-
requestCount:
|
|
1827
|
-
expiresAt:
|
|
1828
|
-
revokedAt:
|
|
1829
|
-
createdBy:
|
|
1830
|
-
onBehalfOf:
|
|
1831
|
-
metadata:
|
|
1832
|
-
createdAt:
|
|
1833
|
-
}).index("byApiKeyTenant", ["tenantId"]),
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
],
|
|
1783
|
+
}, oo = (e) => typeof e == "object" && !!e && "__migration" in e && e.__migration === !0, so = _("_voltro_migrations", {
|
|
1784
|
+
id: l({ prefix: "mig" }),
|
|
1785
|
+
name: h(),
|
|
1786
|
+
hash: h(),
|
|
1787
|
+
status: h(),
|
|
1788
|
+
appliedAt: v().nullable(),
|
|
1789
|
+
durationMs: s().nullable(),
|
|
1790
|
+
errorMessage: h().nullable(),
|
|
1791
|
+
errorStack: h().nullable(),
|
|
1792
|
+
workflowRunId: h().nullable(),
|
|
1793
|
+
createdAt: v().default("now"),
|
|
1794
|
+
updatedAt: v().default("now").onUpdate("now")
|
|
1795
|
+
}).index(["status"]), co = _("_voltro_seeds", {
|
|
1796
|
+
id: l({ prefix: "seed" }),
|
|
1797
|
+
name: h(),
|
|
1798
|
+
lifecycle: h(),
|
|
1799
|
+
fingerprint: h(),
|
|
1800
|
+
cronSchedule: h().nullable(),
|
|
1801
|
+
watchedTables: C().nullable(),
|
|
1802
|
+
nextRunAt: v().nullable(),
|
|
1803
|
+
lastRunStatus: h().nullable(),
|
|
1804
|
+
lastRunAt: v().nullable(),
|
|
1805
|
+
lastRunDurationMs: s().nullable(),
|
|
1806
|
+
lastRunRowsTouched: s().nullable(),
|
|
1807
|
+
lastError: h().nullable(),
|
|
1808
|
+
workflowRunId: h().nullable(),
|
|
1809
|
+
createdAt: v().default("now"),
|
|
1810
|
+
updatedAt: v().default("now").onUpdate("now")
|
|
1811
|
+
}).index(["lifecycle"]).index(["nextRunAt"]), lo = _("_voltro_migration_plans", {
|
|
1812
|
+
id: l({ prefix: "plan" }),
|
|
1813
|
+
fingerprint: h(),
|
|
1814
|
+
liveFingerprint: h().nullable(),
|
|
1815
|
+
operations: C(),
|
|
1816
|
+
rollbackPlan: C().nullable(),
|
|
1817
|
+
appliedBy: h(),
|
|
1818
|
+
environment: h(),
|
|
1819
|
+
source: h(),
|
|
1820
|
+
onlineStrategy: h().nullable(),
|
|
1821
|
+
durationMs: s(),
|
|
1822
|
+
notes: h().nullable(),
|
|
1823
|
+
squashedAt: v().nullable(),
|
|
1824
|
+
appliedAt: v().default("now"),
|
|
1825
|
+
createdAt: v().default("now"),
|
|
1826
|
+
updatedAt: v().default("now").onUpdate("now")
|
|
1827
|
+
}).index(["fingerprint"]).index(["environment"]), uo = _("_voltro_idempotency", {
|
|
1828
|
+
id: l({ prefix: "idem" }),
|
|
1829
|
+
scope: h(),
|
|
1830
|
+
key: h(),
|
|
1831
|
+
status: h(),
|
|
1832
|
+
response: C().nullable(),
|
|
1833
|
+
createdAt: v().default("now")
|
|
1834
|
+
}).unique(["scope", "key"]).index(["createdAt"]), fo = _("_voltro_kv", {
|
|
1835
|
+
id: l({ prefix: "kv" }),
|
|
1836
|
+
key: h().unique(),
|
|
1837
|
+
value: h().nullable(),
|
|
1838
|
+
expiresAt: v().nullable(),
|
|
1839
|
+
createdAt: v().default("now"),
|
|
1840
|
+
updatedAt: v().default("now").onUpdate("now")
|
|
1841
|
+
}).index(["expiresAt"]), po = _("_voltro_api_keys", {
|
|
1842
|
+
id: l({ prefix: "apikey" }),
|
|
1843
|
+
tenantId: h().nullable(),
|
|
1844
|
+
name: h(),
|
|
1845
|
+
hashedKey: h().maxLength(64).unique(),
|
|
1846
|
+
keyPrefix: h(),
|
|
1847
|
+
scopes: C().nullable(),
|
|
1848
|
+
lastUsedAt: v().nullable(),
|
|
1849
|
+
requestCount: s().default(0),
|
|
1850
|
+
expiresAt: v().nullable(),
|
|
1851
|
+
revokedAt: v().nullable(),
|
|
1852
|
+
createdBy: h().nullable(),
|
|
1853
|
+
onBehalfOf: h().nullable(),
|
|
1854
|
+
metadata: C().nullable(),
|
|
1855
|
+
createdAt: v().default("now")
|
|
1856
|
+
}).index("byApiKeyTenant", ["tenantId"]), mo = [
|
|
1857
|
+
so,
|
|
1858
|
+
co,
|
|
1859
|
+
lo
|
|
1860
|
+
], ho = "id", go = (e, t) => {
|
|
1838
1861
|
let n = S(e);
|
|
1839
1862
|
if (n === void 0) return t;
|
|
1840
|
-
let r = n.fields[
|
|
1841
|
-
if (r === void 0 || t[
|
|
1863
|
+
let r = n.fields[ho]?.idScheme;
|
|
1864
|
+
if (r === void 0 || t[ho] != null) return t;
|
|
1842
1865
|
if (r.kind === "numeric") {
|
|
1843
|
-
if (!(
|
|
1866
|
+
if (!(ho in t)) return t;
|
|
1844
1867
|
let e = { ...t };
|
|
1845
|
-
return delete e[
|
|
1868
|
+
return delete e[ho], e;
|
|
1846
1869
|
}
|
|
1847
|
-
let i =
|
|
1870
|
+
let i = oe(r, e);
|
|
1848
1871
|
return i === null ? t : {
|
|
1849
1872
|
...t,
|
|
1850
|
-
[
|
|
1873
|
+
[ho]: i
|
|
1851
1874
|
};
|
|
1852
|
-
},
|
|
1875
|
+
}, _o = (e, t) => t.map((t) => go(e, t)), vo = (e, t) => {
|
|
1853
1876
|
let n = [], r = t;
|
|
1854
1877
|
for (let [t, i] of Object.entries(e.fields)) {
|
|
1855
1878
|
let e = i;
|
|
1856
1879
|
e.nullable || e.hasDefault || e.idScheme !== void 0 || e.generatedAs !== void 0 || (r[t] === void 0 || r[t] === null) && n.push(t);
|
|
1857
1880
|
}
|
|
1858
1881
|
return n;
|
|
1859
|
-
},
|
|
1882
|
+
}, yo = (e, t) => {
|
|
1860
1883
|
let n = t;
|
|
1861
1884
|
return e.filter((e) => n[e] === void 0 || n[e] === null);
|
|
1862
|
-
},
|
|
1885
|
+
}, bo = (e, t, n) => e.insert(t.tableName, n), xo = (e, t, n, r) => e.upsert(t.tableName, n, {
|
|
1863
1886
|
conflictColumns: r.conflictColumns,
|
|
1864
1887
|
...r.update === void 0 ? {} : { update: r.update }
|
|
1865
|
-
}),
|
|
1888
|
+
}), So = (e, t, n, r) => e.updateMany(t.tableName, n, { where: r.where }), Co = 512, wo = (e) => {
|
|
1866
1889
|
e.setMaxListeners(512);
|
|
1867
|
-
},
|
|
1890
|
+
}, To = (e, t, n) => ({
|
|
1868
1891
|
_tag: "PrimaryKeyConflictError",
|
|
1869
1892
|
table: e,
|
|
1870
1893
|
key: t,
|
|
1871
1894
|
cause: n
|
|
1872
|
-
}),
|
|
1895
|
+
}), Eo = (e) => typeof e == "object" && !!e && e._tag === "PrimaryKeyConflictError", Do = /* @__PURE__ */ new Map(), Oo = (e) => {
|
|
1873
1896
|
if (!e.table || !e.timeColumn) throw Error("registerRetention: table + timeColumn are required");
|
|
1874
1897
|
if (!Number.isFinite(e.ttlMs) || e.ttlMs <= 0) throw Error(`registerRetention(${e.table}): ttlMs must be a positive number`);
|
|
1875
|
-
|
|
1876
|
-
},
|
|
1898
|
+
Do.set(e.table, e);
|
|
1899
|
+
}, ko = () => [...Do.values()], Ao = () => Do.clear(), jo = async (e, t, n, r = 2e4) => {
|
|
1877
1900
|
let i = new Date(t - e.ttlMs), a = 0;
|
|
1878
1901
|
for (;;) {
|
|
1879
1902
|
let t = await n(e.table, e.timeColumn, i, r, e.where);
|
|
1880
1903
|
if (a += t, t < r) break;
|
|
1881
1904
|
}
|
|
1882
1905
|
return a;
|
|
1883
|
-
},
|
|
1906
|
+
}, Mo = (e, t) => {
|
|
1884
1907
|
let n = Number(e ?? String(t));
|
|
1885
1908
|
return (Number.isFinite(n) && n > 0 ? n : t) * 36e5;
|
|
1886
|
-
},
|
|
1887
|
-
id:
|
|
1888
|
-
replicaId:
|
|
1889
|
-
streamName:
|
|
1890
|
-
binlogFile:
|
|
1891
|
-
binlogPosition:
|
|
1892
|
-
updatedAt:
|
|
1893
|
-
}).index(["replicaId"]),
|
|
1894
|
-
id:
|
|
1895
|
-
replicaId:
|
|
1896
|
-
streamName:
|
|
1897
|
-
ctVersion:
|
|
1898
|
-
updatedAt:
|
|
1899
|
-
}).index(["replicaId"]),
|
|
1909
|
+
}, No = "_voltro_cdc_offsets", Po = _(No, {
|
|
1910
|
+
id: l({ prefix: "cdcoff" }),
|
|
1911
|
+
replicaId: h(),
|
|
1912
|
+
streamName: h(),
|
|
1913
|
+
binlogFile: h(),
|
|
1914
|
+
binlogPosition: h(),
|
|
1915
|
+
updatedAt: v()
|
|
1916
|
+
}).index(["replicaId"]), Fo = _(No, {
|
|
1917
|
+
id: l({ prefix: "cdcoff" }),
|
|
1918
|
+
replicaId: h(),
|
|
1919
|
+
streamName: h(),
|
|
1920
|
+
ctVersion: h(),
|
|
1921
|
+
updatedAt: v()
|
|
1922
|
+
}).index(["replicaId"]), Io = "postgres";
|
|
1900
1923
|
//#endregion
|
|
1901
|
-
export {
|
|
1924
|
+
export { me as AUTO_FILLED_COLUMNS, X as BranchNameInvalid, ya as BranchTransitionInvalid, No as CDC_OFFSETS_TABLE, Co as CHANGE_LISTENER_CEILING, Pe as ColumnBuilder, Ot as ENCRYPTED_PREFIX, Io as ENGINE, gn as EagerCardinalityError, Fe as FILE_MIGRATION_PATTERN, $e as FRAMEWORK_LIVE_TABLES, kt as FieldDecryptionError, ia as INITIAL_VERSION, pi as MATCHES_NO_ROWS, Ge as MAX_IDENTIFIER_LENGTH, xt as SqlClient, sa as TableStreamError, kn as TenantNamespaceInvalid, On as TenantNamespaceUnresolved, Fa as TenantRegionUnavailable, Pa as TenantResidencyUnresolved, aa as VOLTRO_EXPIRES_MIXIN_ID, ea as VersionConflict, Ze as WARN_IDENTIFIER_LENGTH, po as _voltroApiKeysTable, Po as _voltroCdcOffsetsTable, uo as _voltroIdempotencyTable, fo as _voltroKvTable, lo as _voltroMigrationPlansTable, so as _voltroMigrationsTable, Fo as _voltroMssqlCdcOffsetsTable, co as _voltroSeedsTable, $r as actorsTable, Ma as admitBranch, Ve as allEnumRenames, an as allRegisteredRelations, u as allRegisteredTables, _i as and, Me as array, ui as arrayContains, fi as arrayHas, di as arrayOverlaps, vn as attachEagerLoads, Mi as attributionFields, Ii as attributionKey, Ya as auditAllTableIndexes, Ja as auditTableIndexes, ke as avg, Je as avgOver, Ui as beginLocalWrite, ye as bigint, Ua as bindResidentStore, it as boolean, ga as branchNamespaceName, ut as bytes, zi as claimPendingAttribution, nt as clearEnumRenames, Ki as clearPendingAttribution, sn as clearRelationsRegistry, za as clearResidencyConfig, Ao as clearRetentions, m as clearTableRegistry, Xi as clearWriteRecorders, Ln as coercePredicateValue, Rn as coercePredicateValues, Oi as collectSubqueries, He as column, Ft as columnSchema, Xn as compileEagerJson, M as compilePredicate, zn as compileRawFragment, N as compileSelect, fa as computeEmbedding, ci as contains, Ne as count, je as countDistinct, ji as currentWriteAttribution, ve as databaseHandle, Ce as date, ct as dbEnum, le as decimal, De as declareEnumRename, pn as decodeRowsFromSchema, Pt as decryptFieldsOnRead, ao as defineMigration, g as defineMixin, no as defineSeed, rt as denseRank, _e as deriveTypeIdPrefix, Dt as deserializeArraysOnRead, Ie as drainIdentifierWarnings, a as dropped, hn as encodeRowForSchema, Nt as encryptFieldsForWrite, Mt as encryptedColumnsOf, Wi as endLocalWrite, ka as enforceBranchLimits, ee as ensureTableRegistered, ei as eq, j as escapeLike, Di as evaluatePredicate, lt as except, wi as exists, oa as expires, eo as formatIndexAuditIssue, mo as frameworkTables, oe as generateId, Oe as generateSnowflake, ot as geography, de as geometry, Ae as getEnumRenames, rn as getRelation, nn as getRelations, Ra as getResidencyConfig, S as getTable, ni as gt, ri as gte, Dn as hasEagerLoads, da as hybridSearch, l as id, oi as inSet, Si as inSubquery, O as inferForeignKey, bo as insertRow, s as integer, Se as intersect, re as interval, _a as isBranchNamespace, Ut as isEmptyRelationsSpec, jt as isEncrypted, At as isFieldDecryptionError, be as isFileMigration, We as isFrameworkOwnedLiveTable, oo as isMigrationDefinition, Ca as isNeonConnection, hi as isNotNull, mi as isNull, Eo as isPrimaryKeyConflictError, Va as isRegionServable, Wt as isRelationsSpec, ro as isSeedDefinition, p as isSqliteFamily, dt as isTableReactive, we as isView, C as json, bi as jsonField, f as jsonIndex, st as lag, ce as lead, ko as listRetentions, ii as lt, ai as lte, Na as makeNamespaceBranchExecutor, Kt as many, qt as manyToMany, n as materializeFields, i as max, Ke as migration, at as min, yo as missingConflictColumns, vo as missingRequiredColumns, ge as mixin, ti as neq, ba as nextBranchState, yi as not, Ti as notExists, si as notInSet, Ci as notInSubquery, Re as numeric, Gt as one, _n as oneCardinalityMessage, vi as or, ue as paginateBy, c as paginateById, qi as pendingAttributionCount, Da as planBranch, xa as planBranchProvision, Sa as planBranchTeardown, Oa as planBranchTeardownFor, Ta as planNeonBranchProvision, Ea as planNeonBranchTeardown, na as planVersionedUpdate, Ye as pluginRef, Ue as pluginRefSpecOf, To as primaryKeyConflictError, Aa as provisionBranch, Wa as provisionResidentTenant, Pn as qualifyTable, o as queryFor, Be as queryForView, fe as quoteIdent, wo as raiseChangeListenerCeiling, x as rank, y as raw, ne as real, Zi as recordsTable, ae as reference, Yr as registerCoreTables, tn as registerDiscoveredRelations, Ri as registerPendingAttribution, en as registerRelations, Oo as registerRetention, r as registerTable, Ji as registerWriteRecorder, Ht as relations, Zr as requireActors, pe as requireTable, Qr as requireTenants, et as resetSnowflake, Ha as residentPlacement, Ct as resolveActorSnapshot, wa as resolveBranchMechanism, Gi as resolveEchoAttribution, ze as resolveFullTextIndex, e as resolveIdScheme, he as resolveMixinGraph, Ba as resolveTenantHome, Nn as resolveTenantNamespace, Mo as retentionTtlMsFromEnv, t as rowNumber, It as rowSchema, Ai as runWithWriteAttribution, Qi as runWriteRecorders, Mn as sanitizeIdentifierFragment, Et as serializeArraysForWrite, d as serverOnlyColumns, La as setResidencyConfig, $i as settleTransactionExit, ra as settleVersionedUpdate, gi as spatialPredicate, go as stampGeneratedId, _o as stampGeneratedIds, li as startsWith, ua as streamTable, Le as sum, te as sumOver, jo as sweepRetention, _ as table, ja as teardownBranch, h as text, v as timestamp, ft as timestampMs, pt as timestampMsOrNull, b as union, ie as unionAll, Yi as unregisterWriteRecorder, So as updateManyRow, xo as upsertRow, xe as validateColumnName, qe as validateIndexName, on as validateRegisteredRelations, Zt as validateRelationConfig, Qe as validateTableName, Te as validateTypeIdPrefix, se as vector, Xe as vectorDistanceToOpclass, pa as vectorEmbedding, ta as versionColumnOf, tt as view, Ee as viewSql, ki as walkLeaves, Ni as withCapturedAttribution };
|