@voltro/database 0.11.3 → 0.11.4
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 +173 -0
- package/dist/{fileBased-BrYB2u6E.js → fileBased-DEW2BvnP.js} +110 -100
- package/dist/index.d.ts +34 -0
- package/dist/index.js +522 -522
- package/dist/sql.d.ts +13 -0
- package/dist/sql.js +4 -4
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
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, G as d, H as f, I as p, J as m, K as h, L as g, M as
|
|
2
|
-
import { timestampMs as
|
|
3
|
-
import { Chunk as
|
|
4
|
-
import { ansi 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, G as d, H as f, I as p, J as m, K as h, L as g, M as _, Mt as v, N as y, O as b, Ot as x, P as S, Q as ee, R as C, S as te, St as ne, T as re, Tt as ie, U as ae, V as oe, W as se, X as ce, Y as le, Z as ue, _ as de, _t as fe, a as pe, at as me, b as he, bt as w, c as ge, ct as _e, d as ve, dt as ye, et as be, f as xe, ft as Se, g as Ce, gt as we, h as Te, ht as Ee, i as T, it as De, j as Oe, jt as E, k as ke, kt as Ae, l as je, lt as Me, m as Ne, mt as Pe, n as Fe, nt as Ie, o as Le, ot as Re, p as ze, pt as Be, q as Ve, r as He, rt as Ue, s as We, st as Ge, t as Ke, tt as qe, u as Je, ut as Ye, v as Xe, vt as Ze, w as Qe, wt as $e, x as et, xt as D, y as tt, yt as nt, z as rt } from "./fileBased-DEW2BvnP.js";
|
|
2
|
+
import { timestampMs as it, timestampMsOrNull as at } from "./wire.js";
|
|
3
|
+
import { Chunk as ot, Data as st, Effect as ct, Option as O, Schema as k, Stream as lt } from "effect";
|
|
4
|
+
import { ansi as A } from "@voltro/logger";
|
|
5
5
|
//#region src/arrayCodec.ts
|
|
6
|
-
var
|
|
6
|
+
var ut = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqlite", dt = (e) => {
|
|
7
7
|
let t = [];
|
|
8
8
|
for (let [n, r] of Object.entries(e.fields)) r.type === "array" && t.push(n);
|
|
9
9
|
return t;
|
|
10
|
-
},
|
|
11
|
-
if (!
|
|
12
|
-
let r =
|
|
10
|
+
}, ft = (e, t, n) => {
|
|
11
|
+
if (!ut(n) || !t) return e;
|
|
12
|
+
let r = dt(t);
|
|
13
13
|
if (r.length === 0) return e;
|
|
14
14
|
let i = { ...e };
|
|
15
15
|
for (let e of r) {
|
|
@@ -17,9 +17,9 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
17
17
|
Array.isArray(t) && (i[e] = JSON.stringify(t));
|
|
18
18
|
}
|
|
19
19
|
return i;
|
|
20
|
-
},
|
|
21
|
-
if (!
|
|
22
|
-
let r =
|
|
20
|
+
}, pt = (e, t, n) => {
|
|
21
|
+
if (!ut(n) || !t) return e;
|
|
22
|
+
let r = dt(t);
|
|
23
23
|
return r.length === 0 ? e : e.map((e) => {
|
|
24
24
|
let t;
|
|
25
25
|
for (let n of r) {
|
|
@@ -31,7 +31,7 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
31
31
|
}
|
|
32
32
|
return t ?? e;
|
|
33
33
|
});
|
|
34
|
-
},
|
|
34
|
+
}, mt = "enc:v1:", ht = class extends Error {
|
|
35
35
|
_tag = "FieldDecryptionError";
|
|
36
36
|
table;
|
|
37
37
|
column;
|
|
@@ -39,33 +39,33 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
39
39
|
constructor(e) {
|
|
40
40
|
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;
|
|
41
41
|
}
|
|
42
|
-
},
|
|
42
|
+
}, gt = (e) => typeof e == "object" && !!e && e._tag === "FieldDecryptionError", _t = (e) => typeof e == "string" && e.startsWith("enc:v1:"), vt = (e) => {
|
|
43
43
|
let t = [];
|
|
44
44
|
for (let [n, r] of Object.entries(e.fields)) r.encrypted === !0 && t.push(n);
|
|
45
45
|
return t;
|
|
46
|
-
},
|
|
46
|
+
}, yt = (e, t, n) => {
|
|
47
47
|
if (!t) return e;
|
|
48
|
-
let r =
|
|
48
|
+
let r = vt(t);
|
|
49
49
|
if (r.length === 0) return e;
|
|
50
50
|
let i = { ...e };
|
|
51
51
|
for (let e of r) {
|
|
52
52
|
let r = i[e];
|
|
53
|
-
if (!(r == null ||
|
|
53
|
+
if (!(r == null || _t(r))) {
|
|
54
54
|
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)`);
|
|
55
55
|
i[e] = n.encrypt(JSON.stringify(r));
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
return i;
|
|
59
|
-
},
|
|
59
|
+
}, bt = (e, t, n, r) => {
|
|
60
60
|
if (!t) return e;
|
|
61
|
-
let i =
|
|
61
|
+
let i = vt(t);
|
|
62
62
|
if (i.length === 0 || !n) return e;
|
|
63
63
|
let a = r?.onError ?? "throw", o = t.tableName ?? "?";
|
|
64
64
|
return e.map((e) => {
|
|
65
65
|
let t;
|
|
66
66
|
for (let s of i) {
|
|
67
67
|
let i = e[s];
|
|
68
|
-
if (
|
|
68
|
+
if (_t(i)) {
|
|
69
69
|
t ??= { ...e };
|
|
70
70
|
try {
|
|
71
71
|
t[s] = JSON.parse(n.decrypt(i));
|
|
@@ -79,7 +79,7 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
79
79
|
});
|
|
80
80
|
continue;
|
|
81
81
|
}
|
|
82
|
-
throw new
|
|
82
|
+
throw new ht({
|
|
83
83
|
table: o,
|
|
84
84
|
column: s,
|
|
85
85
|
reason: n
|
|
@@ -89,58 +89,58 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
89
89
|
}
|
|
90
90
|
return t ?? e;
|
|
91
91
|
});
|
|
92
|
-
},
|
|
92
|
+
}, xt = (e) => {
|
|
93
93
|
let t = (() => {
|
|
94
94
|
switch (e.type) {
|
|
95
95
|
case "id":
|
|
96
96
|
case "reference":
|
|
97
97
|
case "text":
|
|
98
|
-
case "enum": return
|
|
98
|
+
case "enum": return k.String;
|
|
99
99
|
case "integer":
|
|
100
100
|
case "real":
|
|
101
|
-
case "decimal": return
|
|
102
|
-
case "boolean": return
|
|
101
|
+
case "decimal": return k.Number;
|
|
102
|
+
case "boolean": return k.Boolean;
|
|
103
103
|
case "timestamp":
|
|
104
|
-
case "date": return
|
|
105
|
-
case "bigint": return
|
|
106
|
-
case "bytes": return
|
|
107
|
-
case "array": return
|
|
108
|
-
case "interval": return
|
|
109
|
-
default: return
|
|
104
|
+
case "date": return it;
|
|
105
|
+
case "bigint": return k.BigInt;
|
|
106
|
+
case "bytes": return k.Uint8ArrayFromSelf;
|
|
107
|
+
case "array": return k.Array(k.Unknown);
|
|
108
|
+
case "interval": return k.String;
|
|
109
|
+
default: return k.Unknown;
|
|
110
110
|
}
|
|
111
111
|
})();
|
|
112
|
-
return e.nullable === !0 ?
|
|
113
|
-
},
|
|
112
|
+
return e.nullable === !0 ? k.NullOr(t) : t;
|
|
113
|
+
}, St = (e, t) => {
|
|
114
114
|
let n = new Set(t?.omit ?? []), r = {};
|
|
115
|
-
for (let [t, i] of Object.entries(e.fields)) n.has(t) || (r[t] =
|
|
116
|
-
return
|
|
117
|
-
},
|
|
115
|
+
for (let [t, i] of Object.entries(e.fields)) n.has(t) || (r[t] = xt(i));
|
|
116
|
+
return k.Struct(r);
|
|
117
|
+
}, j = (e) => typeof e == "function" ? e : () => e, Ct = (e, t) => ({
|
|
118
118
|
kind: "one",
|
|
119
|
-
target:
|
|
119
|
+
target: j(e),
|
|
120
120
|
...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
|
|
121
121
|
...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
|
|
122
|
-
}),
|
|
122
|
+
}), wt = (e, t) => ({
|
|
123
123
|
kind: "many",
|
|
124
|
-
target:
|
|
124
|
+
target: j(e),
|
|
125
125
|
...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
|
|
126
126
|
...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
|
|
127
|
-
}),
|
|
127
|
+
}), Tt = (e, t) => ({
|
|
128
128
|
kind: "manyToMany",
|
|
129
|
-
target:
|
|
130
|
-
through:
|
|
129
|
+
target: j(e),
|
|
130
|
+
through: j(t.through),
|
|
131
131
|
sourceKey: t.sourceKey,
|
|
132
132
|
targetKey: t.targetKey
|
|
133
|
-
}),
|
|
134
|
-
one:
|
|
135
|
-
many:
|
|
136
|
-
manyToMany:
|
|
137
|
-
},
|
|
133
|
+
}), Et = {
|
|
134
|
+
one: Ct,
|
|
135
|
+
many: wt,
|
|
136
|
+
manyToMany: Tt
|
|
137
|
+
}, Dt = (e, t) => {
|
|
138
138
|
let n = typeof e == "function" ? e : () => e;
|
|
139
139
|
return {
|
|
140
140
|
source: n,
|
|
141
|
-
relations: t(
|
|
141
|
+
relations: t(Et, n())
|
|
142
142
|
};
|
|
143
|
-
},
|
|
143
|
+
}, Ot = (e) => {
|
|
144
144
|
if (typeof e != "object" || !e) return !1;
|
|
145
145
|
let t = e;
|
|
146
146
|
if (typeof t.source != "function" || typeof t.relations != "object" || t.relations === null) return !1;
|
|
@@ -149,64 +149,64 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
149
149
|
let t = e?.kind;
|
|
150
150
|
return t === "one" || t === "many" || t === "manyToMany";
|
|
151
151
|
});
|
|
152
|
-
},
|
|
152
|
+
}, kt = Ct, At = wt, jt = Tt, M = (e, t, n) => {
|
|
153
153
|
let r = [];
|
|
154
154
|
for (let [n, i] of Object.entries(e.fields)) i.type === "reference" && i.references?.()?.tableName === t && r.push(n);
|
|
155
155
|
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>' }.`);
|
|
156
156
|
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.`);
|
|
157
157
|
return r[0];
|
|
158
|
-
},
|
|
159
|
-
let t =
|
|
158
|
+
}, Mt = (e) => Object.keys(e.fields), N = (e, t) => Object.prototype.hasOwnProperty.call(e.fields, t), Nt = (e) => {
|
|
159
|
+
let t = Mt(e);
|
|
160
160
|
return t.length === 0 ? "<none>" : t.join(", ");
|
|
161
|
-
},
|
|
161
|
+
}, Pt = (e, t, n) => {
|
|
162
162
|
let r = `relation '${t}' on '${e.tableName}'`, i = n.target();
|
|
163
163
|
if (n.kind === "manyToMany") {
|
|
164
164
|
let t = n.through();
|
|
165
|
-
for (let [a, o] of [["sourceKey", n.sourceKey], ["targetKey", n.targetKey]]) if (!
|
|
165
|
+
for (let [a, o] of [["sourceKey", n.sourceKey], ["targetKey", n.targetKey]]) if (!N(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}': ${Nt(t)}.`);
|
|
166
166
|
return;
|
|
167
167
|
}
|
|
168
168
|
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.`);
|
|
169
|
-
if (n.sourceKey !== void 0 && !
|
|
170
|
-
let t =
|
|
171
|
-
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}': ${
|
|
169
|
+
if (n.sourceKey !== void 0 && !N(e, n.sourceKey)) {
|
|
170
|
+
let t = N(i, n.sourceKey);
|
|
171
|
+
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}': ${Nt(e)}.`));
|
|
172
172
|
}
|
|
173
|
-
if (n.foreignKey !== void 0 && !
|
|
174
|
-
let t =
|
|
175
|
-
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}': ${
|
|
173
|
+
if (n.foreignKey !== void 0 && !N(i, n.foreignKey)) {
|
|
174
|
+
let t = N(e, n.foreignKey);
|
|
175
|
+
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}': ${Nt(i)}.`));
|
|
176
176
|
}
|
|
177
|
-
},
|
|
178
|
-
let t = e.source(), n =
|
|
177
|
+
}, Ft = Symbol.for("@voltro/database/relationsRegistry"), It = globalThis, P = It[Ft] ?? (It[Ft] = /* @__PURE__ */ new Map()), Lt = (e) => {
|
|
178
|
+
let t = e.source(), n = P.get(t.tableName);
|
|
179
179
|
if (n === void 0) {
|
|
180
|
-
|
|
180
|
+
P.set(t.tableName, new Map(Object.entries(e.relations)));
|
|
181
181
|
return;
|
|
182
182
|
}
|
|
183
183
|
for (let [r, i] of Object.entries(e.relations)) {
|
|
184
184
|
if (n.has(r)) throw Error(`duplicate relation '${r}' on '${t.tableName}': two relations() blocks both declare it. Pick distinct names or merge them into one block.`);
|
|
185
185
|
n.set(r, i);
|
|
186
186
|
}
|
|
187
|
-
},
|
|
187
|
+
}, Rt = (e) => {
|
|
188
188
|
let t = 0;
|
|
189
|
-
for (let n of Object.values(e))
|
|
189
|
+
for (let n of Object.values(e)) Ot(n) && (Lt(n), t += 1);
|
|
190
190
|
return t;
|
|
191
|
-
},
|
|
192
|
-
let t =
|
|
191
|
+
}, zt = (e) => {
|
|
192
|
+
let t = P.get(e);
|
|
193
193
|
if (t !== void 0) return Object.fromEntries(t);
|
|
194
|
-
},
|
|
194
|
+
}, Bt = (e, t) => P.get(e)?.get(t), Vt = () => {
|
|
195
195
|
let e = [];
|
|
196
|
-
for (let [t, n] of
|
|
196
|
+
for (let [t, n] of P) for (let [r, i] of n) e.push({
|
|
197
197
|
source: t,
|
|
198
198
|
name: r,
|
|
199
199
|
relation: i
|
|
200
200
|
});
|
|
201
201
|
return e;
|
|
202
|
-
},
|
|
203
|
-
for (let [e, t] of
|
|
202
|
+
}, Ht = () => {
|
|
203
|
+
for (let [e, t] of P) {
|
|
204
204
|
let n = u(e);
|
|
205
|
-
if (n !== void 0) for (let [e, r] of t)
|
|
205
|
+
if (n !== void 0) for (let [e, r] of t) Pt(n, e, r);
|
|
206
206
|
}
|
|
207
|
-
},
|
|
208
|
-
|
|
209
|
-
},
|
|
207
|
+
}, Ut = () => {
|
|
208
|
+
P.clear();
|
|
209
|
+
}, Wt = (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, Gt = (e) => {
|
|
210
210
|
if (e == null || typeof e != "string") return e;
|
|
211
211
|
let t = e.trim();
|
|
212
212
|
if (t.length === 0) return e;
|
|
@@ -217,7 +217,7 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
217
217
|
} catch {
|
|
218
218
|
return e;
|
|
219
219
|
}
|
|
220
|
-
},
|
|
220
|
+
}, Kt = (e) => e == null || typeof e == "string" ? e : typeof e == "number" || typeof e == "bigint" ? String(e) : e, qt = (e) => {
|
|
221
221
|
if (e == null || e instanceof Date) return e;
|
|
222
222
|
if (typeof e == "string") {
|
|
223
223
|
let t = new Date(e);
|
|
@@ -228,19 +228,19 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
228
228
|
return isNaN(t.getTime()) ? e : t;
|
|
229
229
|
}
|
|
230
230
|
return e;
|
|
231
|
-
},
|
|
231
|
+
}, Jt = (e, t, n) => {
|
|
232
232
|
if (e == null) return e;
|
|
233
233
|
switch (t) {
|
|
234
|
-
case "boolean": return n === "postgres" ? e :
|
|
234
|
+
case "boolean": return n === "postgres" ? e : Wt(e);
|
|
235
235
|
case "json":
|
|
236
|
-
case "array": return n === "postgres" ? e :
|
|
236
|
+
case "array": return n === "postgres" ? e : Gt(e);
|
|
237
237
|
case "timestamp":
|
|
238
|
-
case "date": return n === "sqlite" || n === "turso" ?
|
|
238
|
+
case "date": return n === "sqlite" || n === "turso" ? qt(e) : e;
|
|
239
239
|
case "decimal":
|
|
240
|
-
case "bigint": return
|
|
240
|
+
case "bigint": return Kt(e);
|
|
241
241
|
default: return e;
|
|
242
242
|
}
|
|
243
|
-
},
|
|
243
|
+
}, Yt = (e, t, n) => {
|
|
244
244
|
if (e.length === 0) return e;
|
|
245
245
|
let r = u(t);
|
|
246
246
|
if (r === void 0) return e;
|
|
@@ -251,36 +251,36 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
251
251
|
});
|
|
252
252
|
return e.map((e) => {
|
|
253
253
|
let t = { ...e };
|
|
254
|
-
for (let { key: e, type: r } of a) e in t && (t[e] =
|
|
254
|
+
for (let { key: e, type: r } of a) e in t && (t[e] = Jt(t[e], r, n));
|
|
255
255
|
return t;
|
|
256
256
|
});
|
|
257
|
-
},
|
|
257
|
+
}, Xt = (e, t) => {
|
|
258
258
|
if (e == null) return e;
|
|
259
259
|
switch (t) {
|
|
260
260
|
case "json":
|
|
261
261
|
case "array": return typeof e == "string" ? e : JSON.stringify(e);
|
|
262
262
|
default: return e;
|
|
263
263
|
}
|
|
264
|
-
},
|
|
264
|
+
}, Zt = (e, t, n = ["json", "array"]) => {
|
|
265
265
|
let r = u(t);
|
|
266
266
|
if (r === void 0) return e;
|
|
267
267
|
let i = r.fields, a = null;
|
|
268
268
|
for (let [t, r] of Object.entries(i)) if (n.includes(r.type) && t in e) {
|
|
269
|
-
let n =
|
|
269
|
+
let n = Xt(e[t], r.type);
|
|
270
270
|
n !== e[t] && (a === null && (a = { ...e }), a[t] = n);
|
|
271
271
|
}
|
|
272
272
|
return a ?? e;
|
|
273
|
-
},
|
|
273
|
+
}, Qt = class extends Error {
|
|
274
274
|
_tag = "EagerCardinalityError";
|
|
275
275
|
constructor(e) {
|
|
276
276
|
super(e), this.name = "EagerCardinalityError";
|
|
277
277
|
}
|
|
278
|
-
},
|
|
278
|
+
}, $t = (e) => {
|
|
279
279
|
let { relationName: t, sourceTableName: n, targetTableName: r, foreignKey: i, sourceKey: a } = e, o = r === n;
|
|
280
280
|
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.");
|
|
281
|
-
},
|
|
281
|
+
}, en = async (e, t, n, r) => {
|
|
282
282
|
if (e.length === 0) return e;
|
|
283
|
-
let i =
|
|
283
|
+
let i = zt(n.tableName);
|
|
284
284
|
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?`);
|
|
285
285
|
let a = e.map((e) => ({ ...e }));
|
|
286
286
|
for (let [e, o] of Object.entries(t)) {
|
|
@@ -289,36 +289,36 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
289
289
|
let t = Object.keys(i).join(", ") || "<none>";
|
|
290
290
|
throw Error(`unknown relation '${e}' on '${n.tableName}'. Registered relations: ${t}.`);
|
|
291
291
|
}
|
|
292
|
-
|
|
292
|
+
Pt(n, e, t), await tn(a, e, t, o === !0 ? {} : o, n, r);
|
|
293
293
|
}
|
|
294
294
|
return a;
|
|
295
|
-
},
|
|
295
|
+
}, tn = async (e, t, n, r, i, a) => {
|
|
296
296
|
switch (n.kind) {
|
|
297
297
|
case "one":
|
|
298
|
-
await
|
|
298
|
+
await nn(e, t, n, r, i, a);
|
|
299
299
|
return;
|
|
300
300
|
case "many":
|
|
301
|
-
await
|
|
301
|
+
await rn(e, t, n, r, i, a);
|
|
302
302
|
return;
|
|
303
303
|
case "manyToMany":
|
|
304
|
-
await
|
|
304
|
+
await on(e, t, n, r, i, a);
|
|
305
305
|
return;
|
|
306
306
|
}
|
|
307
|
-
},
|
|
308
|
-
let o = n.target(), s = n.sourceKey ??
|
|
307
|
+
}, nn = async (e, t, n, r, i, a) => {
|
|
308
|
+
let o = n.target(), s = n.sourceKey ?? sn(i, o.tableName);
|
|
309
309
|
if (s !== void 0) {
|
|
310
|
-
let n =
|
|
310
|
+
let n = F(e, s), i = n.length === 0 ? [] : await cn(o, "id", n, r, a), c = new Map(i.map((e) => [e.id, e]));
|
|
311
311
|
for (let n of e) {
|
|
312
312
|
let e = n[s];
|
|
313
313
|
n[t] = e == null ? null : c.get(e) ?? null;
|
|
314
314
|
}
|
|
315
|
-
await
|
|
315
|
+
await ln(i, r.with, o, a);
|
|
316
316
|
return;
|
|
317
317
|
}
|
|
318
|
-
let c = n.foreignKey ??
|
|
318
|
+
let c = n.foreignKey ?? M(o, i.tableName, t), l = n.sourceKey ?? "id", u = F(e, l), d = u.length === 0 ? [] : await cn(o, c, u, r, a), f = /* @__PURE__ */ new Map();
|
|
319
319
|
for (let e of d) {
|
|
320
320
|
let n = e[c];
|
|
321
|
-
if (f.has(n)) throw new
|
|
321
|
+
if (f.has(n)) throw new Qt($t({
|
|
322
322
|
relationName: t,
|
|
323
323
|
sourceTableName: i.tableName,
|
|
324
324
|
targetTableName: o.tableName,
|
|
@@ -331,9 +331,9 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
331
331
|
let e = n[l];
|
|
332
332
|
n[t] = e == null ? null : f.get(e) ?? null;
|
|
333
333
|
}
|
|
334
|
-
await
|
|
335
|
-
},
|
|
336
|
-
let o = n.target(), s = n.foreignKey ??
|
|
334
|
+
await ln(d, r.with, o, a);
|
|
335
|
+
}, rn = async (e, t, n, r, i, a) => {
|
|
336
|
+
let o = n.target(), s = n.foreignKey ?? M(o, i.tableName, t), c = n.sourceKey ?? "id", l = F(e, c), u = an(r), d = l.length === 0 ? [] : await cn(o, s, l, u, a), f = /* @__PURE__ */ new Map();
|
|
337
337
|
for (let e of d) {
|
|
338
338
|
let t = e[s], n = f.get(t);
|
|
339
339
|
n ? n.push(e) : f.set(t, [e]);
|
|
@@ -349,12 +349,12 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
349
349
|
let e = n[c];
|
|
350
350
|
n[t] = f.get(e) ?? [];
|
|
351
351
|
}
|
|
352
|
-
await
|
|
353
|
-
},
|
|
352
|
+
await ln(d, r.with, o, a);
|
|
353
|
+
}, an = (e) => {
|
|
354
354
|
let { limit: t, offset: n, ...r } = e;
|
|
355
355
|
return r;
|
|
356
|
-
},
|
|
357
|
-
let o = n.target(), s = n.through(), c =
|
|
356
|
+
}, on = async (e, t, n, r, i, a) => {
|
|
357
|
+
let o = n.target(), s = n.through(), c = F(e, "id");
|
|
358
358
|
if (c.length === 0) {
|
|
359
359
|
for (let n of e) n[t] = [];
|
|
360
360
|
return;
|
|
@@ -375,8 +375,8 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
375
375
|
for (let n of e) n[t] = [];
|
|
376
376
|
return;
|
|
377
377
|
}
|
|
378
|
-
let f = await
|
|
379
|
-
await
|
|
378
|
+
let f = await cn(o, "id", F(d, n.targetKey), r, a), p = new Map(f.map((e) => [e.id, e]));
|
|
379
|
+
await ln(f, r.with, o, a);
|
|
380
380
|
let m = r.junction === void 0 ? void 0 : r.junction === !0 ? Object.keys(s.fields) : r.junction, h = /* @__PURE__ */ new Map();
|
|
381
381
|
for (let e of d) {
|
|
382
382
|
let t = e[n.sourceKey], r = e[n.targetKey], i = p.get(r);
|
|
@@ -388,16 +388,16 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
388
388
|
o ? o.push(a) : h.set(t, [a]);
|
|
389
389
|
}
|
|
390
390
|
for (let n of e) n[t] = h.get(n.id) ?? [];
|
|
391
|
-
},
|
|
391
|
+
}, sn = (e, t) => {
|
|
392
392
|
for (let [n, r] of Object.entries(e.fields)) if (r.type === "reference" && r.references?.()?.tableName === t) return n;
|
|
393
|
-
},
|
|
393
|
+
}, F = (e, t) => {
|
|
394
394
|
let n = /* @__PURE__ */ new Set();
|
|
395
395
|
for (let r of e) {
|
|
396
396
|
let e = r[t];
|
|
397
397
|
e != null && n.add(e);
|
|
398
398
|
}
|
|
399
399
|
return [...n];
|
|
400
|
-
},
|
|
400
|
+
}, cn = (e, t, n, r, i) => {
|
|
401
401
|
let a = {
|
|
402
402
|
column: t,
|
|
403
403
|
op: "in",
|
|
@@ -411,54 +411,54 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
411
411
|
skip: r.offset,
|
|
412
412
|
projection: void 0
|
|
413
413
|
});
|
|
414
|
-
},
|
|
415
|
-
t !== void 0 && e.length !== 0 && (await
|
|
414
|
+
}, ln = async (e, t, n, r) => {
|
|
415
|
+
t !== void 0 && e.length !== 0 && (await en(e, t, n, r)).forEach((t, n) => {
|
|
416
416
|
let r = e[n];
|
|
417
417
|
for (let [e, n] of Object.entries(t)) e in r || (r[e] = n);
|
|
418
418
|
});
|
|
419
|
-
},
|
|
419
|
+
}, un = (e) => e.eager !== void 0 && Object.keys(e.eager).length > 0, dn = class extends Error {
|
|
420
420
|
_tag = "TenantNamespaceUnresolved";
|
|
421
421
|
constructor(e) {
|
|
422
422
|
super(e), this.name = "TenantNamespaceUnresolved";
|
|
423
423
|
}
|
|
424
|
-
},
|
|
424
|
+
}, fn = class extends Error {
|
|
425
425
|
_tag = "TenantNamespaceInvalid";
|
|
426
426
|
constructor(e) {
|
|
427
427
|
super(e), this.name = "TenantNamespaceInvalid";
|
|
428
428
|
}
|
|
429
|
-
},
|
|
430
|
-
if (e == null || e === "") throw new
|
|
431
|
-
let t =
|
|
432
|
-
if (t.replace(/_/g, "") === "") throw new
|
|
433
|
-
let n = `${
|
|
434
|
-
if (n.length >
|
|
429
|
+
}, pn = 63, mn = "tenant_", hn = (e) => e.toLowerCase().replace(/[^a-z0-9_]/g, "_"), gn = (e) => {
|
|
430
|
+
if (e == null || e === "") throw new dn("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.");
|
|
431
|
+
let t = hn(e);
|
|
432
|
+
if (t.replace(/_/g, "") === "") throw new fn(`tenant id '${e}' has no usable identifier characters after sanitisation — cannot derive a distinct namespace.`);
|
|
433
|
+
let n = `${mn}${t}`;
|
|
434
|
+
if (n.length > pn) throw new fn(`namespace '${n}' for tenant '${e}' exceeds the ${pn}-byte identifier limit. Use a shorter tenant id.`);
|
|
435
435
|
return n;
|
|
436
|
-
},
|
|
436
|
+
}, _n = (e, t) => e === null ? t : `${e}.${t}`, vn = (e, t) => {
|
|
437
437
|
let { strings: n, values: r } = e, i = t.unsafe(n[0] ?? "");
|
|
438
438
|
for (let e = 0; e < r.length; e++) i = t`${i}${r[e]}${t.unsafe(n[e + 1] ?? "")}`;
|
|
439
439
|
return t`${i}`;
|
|
440
|
-
},
|
|
441
|
-
if ("not" in e) return t`NOT (${
|
|
442
|
-
if ("and" in e) return e.and.length === 0 ? t`TRUE` : t.and(e.and.map((e) =>
|
|
443
|
-
if ("or" in e) return e.or.length === 0 ? t`FALSE` : t.or(e.or.map((e) =>
|
|
440
|
+
}, yn = (e) => e.replace(/[\\%_]/g, (e) => `\\${e}`), I = (e, t, n = null) => {
|
|
441
|
+
if ("not" in e) return t`NOT (${I(e.not, t, n)})`;
|
|
442
|
+
if ("and" in e) return e.and.length === 0 ? t`TRUE` : t.and(e.and.map((e) => I(e, t, n)));
|
|
443
|
+
if ("or" in e) return e.or.length === 0 ? t`FALSE` : t.or(e.or.map((e) => I(e, t, n)));
|
|
444
444
|
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
445
|
-
let r = e, i =
|
|
445
|
+
let r = e, i = L(r.subquery, t, n);
|
|
446
446
|
return r.op === "subquery-in" ? t`${t(r.column)} IN (${i})` : t`${t(r.column)} NOT IN (${i})`;
|
|
447
447
|
}
|
|
448
448
|
if (e.op === "exists" || e.op === "not-exists") {
|
|
449
|
-
let r = e, i =
|
|
449
|
+
let r = e, i = L(r.subquery, t, n);
|
|
450
450
|
return r.op === "exists" ? t`EXISTS (${i})` : t`NOT EXISTS (${i})`;
|
|
451
451
|
}
|
|
452
452
|
let r = e, i = t(r.column), a = r.path, o = a !== void 0 && a.length > 0, s = () => t.onDialectOrElse({
|
|
453
|
-
mysql: () => t.unsafe(
|
|
454
|
-
mssql: () => t.unsafe(
|
|
455
|
-
sqlite: () => t.unsafe(
|
|
456
|
-
orElse: () => t.unsafe(
|
|
453
|
+
mysql: () => t.unsafe(T(r.column, a, "mysql")),
|
|
454
|
+
mssql: () => t.unsafe(T(r.column, a, "mssql")),
|
|
455
|
+
sqlite: () => t.unsafe(T(r.column, a, "sqlite")),
|
|
456
|
+
orElse: () => t.unsafe(T(r.column, a, "postgres"))
|
|
457
457
|
}), c = () => t.onDialectOrElse({
|
|
458
|
-
mysql: () => t.unsafe(
|
|
459
|
-
mssql: () => t.unsafe(
|
|
460
|
-
sqlite: () => t.unsafe(
|
|
461
|
-
orElse: () => t.unsafe(
|
|
458
|
+
mysql: () => t.unsafe(T(r.column, a, "mysql", { numeric: !0 })),
|
|
459
|
+
mssql: () => t.unsafe(T(r.column, a, "mssql", { numeric: !0 })),
|
|
460
|
+
sqlite: () => t.unsafe(T(r.column, a, "sqlite", { numeric: !0 })),
|
|
461
|
+
orElse: () => t.unsafe(T(r.column, a, "postgres", { numeric: !0 }))
|
|
462
462
|
}), l = o ? s() : i, u = o ? c() : i, d = (e) => o && e != null ? String(e) : e, f = (e) => o ? Number(e) : e;
|
|
463
463
|
switch (r.op) {
|
|
464
464
|
case "eq": return t`${l} = ${d(r.value)}`;
|
|
@@ -476,7 +476,7 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
476
476
|
return e.length === 0 ? t`TRUE` : t`${l} NOT IN ${t.in(o ? e.map((e) => d(e)) : e)}`;
|
|
477
477
|
}
|
|
478
478
|
case "contains": {
|
|
479
|
-
let e = `%${
|
|
479
|
+
let e = `%${yn(typeof r.value == "string" ? r.value : String(r.value ?? ""))}%`;
|
|
480
480
|
return t.onDialectOrElse({
|
|
481
481
|
mysql: () => t`LOWER(${l}) LIKE LOWER(${e})`,
|
|
482
482
|
mssql: () => t`LOWER(${l}) LIKE LOWER(${e})`,
|
|
@@ -526,13 +526,13 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
526
526
|
});
|
|
527
527
|
}
|
|
528
528
|
}
|
|
529
|
-
},
|
|
529
|
+
}, bn = (e, t) => {
|
|
530
530
|
let n = [];
|
|
531
531
|
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}`);
|
|
532
|
-
},
|
|
532
|
+
}, xn = (e, t) => t.csv(e.map((e) => {
|
|
533
533
|
let n = e.column === void 0 ? t.unsafe("*") : t`${t(e.column)}`;
|
|
534
534
|
if (e.op.startsWith("window-")) {
|
|
535
|
-
let r =
|
|
535
|
+
let r = bn(e.window ?? {}, t);
|
|
536
536
|
switch (e.op) {
|
|
537
537
|
case "window-row-number": return t`ROW_NUMBER() OVER (${r}) AS ${t(e.alias)}`;
|
|
538
538
|
case "window-rank": return t`RANK() OVER (${r}) AS ${t(e.alias)}`;
|
|
@@ -556,43 +556,43 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
556
556
|
return t`${t(e.column)} AS ${t(e.alias)}`;
|
|
557
557
|
default: throw Error(`compileAggregateProjection: unknown op '${e.op}'`);
|
|
558
558
|
}
|
|
559
|
-
})),
|
|
559
|
+
})), Sn = (e) => `[${e.join(",")}]`, Cn = (e, t) => {
|
|
560
560
|
if (e.queryVector === void 0) return null;
|
|
561
|
-
let n = t(e.column), r =
|
|
561
|
+
let n = t(e.column), r = Sn(e.queryVector), i = e.distance === "cosine" ? "<=>" : e.distance === "l2" ? "<->" : "<#>", a = e.distance === "cosine" ? "VEC_DISTANCE_COSINE" : "VEC_DISTANCE_EUCLIDEAN";
|
|
562
562
|
return t.onDialectOrElse({
|
|
563
563
|
mysql: () => t`${t.unsafe(a)}(${n}, ${r})`,
|
|
564
564
|
mssql: () => t`NULL`,
|
|
565
565
|
sqlite: () => t`NULL`,
|
|
566
566
|
orElse: () => t`${n} ${t.unsafe(i)} ${r}::vector`
|
|
567
567
|
});
|
|
568
|
-
},
|
|
568
|
+
}, wn = (e, t) => {
|
|
569
569
|
let n = t.unsafe(e.useGeography ? "::geography" : "::geometry");
|
|
570
570
|
return t`ST_Distance(${t(e.column)}${n}, ${e.geom}${n})`;
|
|
571
|
-
},
|
|
572
|
-
let r = n.csv(e.columns.map((e) => n`${n(e)}`)), i = `%${
|
|
571
|
+
}, Tn = (e, t) => t`${t(e.column)} <-> ${e.geom}::geometry`, En = (e, t) => t`${t(`${e.indexName}_tsv`)}`, Dn = (e, t) => `${t}_${e.indexName}_fts`, On = (e, t, n) => {
|
|
572
|
+
let r = n.csv(e.columns.map((e) => n`${n(e)}`)), i = `%${yn(e.query)}%`;
|
|
573
573
|
return n.onDialectOrElse({
|
|
574
574
|
mysql: () => n`MATCH(${r}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
|
|
575
575
|
sqlite: () => {
|
|
576
|
-
let r = n(
|
|
576
|
+
let r = n(Dn(e, t));
|
|
577
577
|
return n`${n("id")} IN (SELECT ${n("row_id")} FROM ${r} WHERE ${r} MATCH ${e.query})`;
|
|
578
578
|
},
|
|
579
579
|
mssql: () => n.or(e.columns.map((e) => n`LOWER(${n(e)}) LIKE LOWER(${i}) ESCAPE '\\'`)),
|
|
580
|
-
orElse: () => n`${
|
|
580
|
+
orElse: () => n`${En(e, n)} @@ plainto_tsquery(${e.config ?? "english"}, ${e.query})`
|
|
581
581
|
});
|
|
582
|
-
},
|
|
583
|
-
let r = `%${
|
|
582
|
+
}, kn = (e, t, n) => {
|
|
583
|
+
let r = `%${yn(e.query)}%`;
|
|
584
584
|
return n.onDialectOrElse({
|
|
585
585
|
mysql: () => n`MATCH(${n.csv(e.columns.map((e) => n`${n(e)}`))}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
|
|
586
586
|
sqlite: () => {
|
|
587
|
-
let r = n(
|
|
587
|
+
let r = n(Dn(e, t));
|
|
588
588
|
return n`COALESCE((SELECT -bm25(${r}) FROM ${r} WHERE ${r} MATCH ${e.query} AND ${r}.${n("row_id")} = ${n("id")}), 0)`;
|
|
589
589
|
},
|
|
590
590
|
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}`),
|
|
591
|
-
orElse: () => n`ts_rank(${
|
|
591
|
+
orElse: () => n`ts_rank(${En(e, n)}, plainto_tsquery(${e.config ?? "english"}, ${e.query}))`
|
|
592
592
|
});
|
|
593
|
-
},
|
|
593
|
+
}, L = (e, t, n = null) => {
|
|
594
594
|
if (e.setOp && e.setOp.queries.length >= 2) {
|
|
595
|
-
let r = e.setOp.kind === "union" ? "UNION" : e.setOp.kind === "union-all" ? "UNION ALL" : e.setOp.kind === "intersect" ? "INTERSECT" : "EXCEPT", i = e.setOp.queries.map((e) => t`(${
|
|
595
|
+
let r = e.setOp.kind === "union" ? "UNION" : e.setOp.kind === "union-all" ? "UNION ALL" : e.setOp.kind === "intersect" ? "INTERSECT" : "EXCEPT", i = e.setOp.queries.map((e) => t`(${L(e, t, n)})`).reduce((e, n, i) => i === 0 ? n : t`${e} ${t.unsafe(r)} ${n}`), a = [];
|
|
596
596
|
if (e.order.length > 0 && a.push(t` ORDER BY ${t.csv(e.order.map((e) => e.direction === "desc" ? t`${t(e.column)} DESC` : t`${t(e.column)} ASC`))}`), e.take !== void 0) {
|
|
597
597
|
if (!Number.isInteger(e.take) || e.take < 0) throw Error(`compileSelect: invalid take ${e.take}`);
|
|
598
598
|
a.push(t` LIMIT ${t.unsafe(String(e.take))}`);
|
|
@@ -603,7 +603,7 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
603
603
|
}
|
|
604
604
|
return t`${i}${a.reduce((e, n) => t`${e}${n}`, t``)}`;
|
|
605
605
|
}
|
|
606
|
-
let r = e.annClause === void 0 ? null :
|
|
606
|
+
let r = e.annClause === void 0 ? null : Cn(e.annClause, t);
|
|
607
607
|
e.spatialClause !== void 0 && t.onDialectOrElse({
|
|
608
608
|
mysql: () => {
|
|
609
609
|
throw Error("@voltro/plugin-postgis: spatial distance / KNN ordering is postgres-only");
|
|
@@ -616,35 +616,35 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
616
616
|
},
|
|
617
617
|
orElse: () => t``
|
|
618
618
|
});
|
|
619
|
-
let i = e.spatialClause?.projectAs === void 0 ? null :
|
|
619
|
+
let i = e.spatialClause?.projectAs === void 0 ? null : wn(e.spatialClause, t), a = e.aggregations && e.aggregations.length > 0 ? xn(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 ? kn(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({
|
|
620
620
|
orElse: () => t`DISTINCT ON (${t.csv(e.distinctOn.map((e) => t`${t(e)}`))}) `,
|
|
621
621
|
mysql: () => t`DISTINCT `,
|
|
622
622
|
mssql: () => t`DISTINCT `,
|
|
623
623
|
sqlite: () => t`DISTINCT `
|
|
624
|
-
}) : e.distinct ? t`DISTINCT ` : t``, p = e.alias === void 0 ? t`${t(
|
|
624
|
+
}) : e.distinct ? t`DISTINCT ` : t``, p = e.alias === void 0 ? t`${t(_n(n, e.table))}` : t`${t(_n(n, e.table))} AS ${t(e.alias)}`, m = (e.joins ?? []).map((e) => {
|
|
625
625
|
let r = e.kind === "inner" ? "INNER" : "LEFT";
|
|
626
|
-
return t` ${t.unsafe(r)} JOIN ${t(
|
|
627
|
-
}), h = m.length > 0 ? m.reduce((e, n) => t`${e}${n}`, p) : p, g = c === void 0 ? null :
|
|
628
|
-
r !== null &&
|
|
629
|
-
for (let n of e.order)
|
|
630
|
-
let
|
|
626
|
+
return t` ${t.unsafe(r)} JOIN ${t(_n(n, e.table))} AS ${t(e.alias)} ON ${I(e.on, t, n)}`;
|
|
627
|
+
}), h = m.length > 0 ? m.reduce((e, n) => t`${e}${n}`, p) : p, g = c === void 0 ? null : On(c, e.table, t), _ = [e.predicate ? I(e.predicate, t, n) : null, g].filter((e) => e !== null), v = _.length > 0 ? t` WHERE ${t.and(_)}` : t``, y = e.groupBy && e.groupBy.length > 0 ? t` GROUP BY ${t.csv(e.groupBy.map((e) => t`${t(e)}`))}` : t``, b = e.having ? t` HAVING ${I(e.having, t, n)}` : t``, x = e.skip !== void 0, S = [];
|
|
628
|
+
r !== null && S.push(t`${r} ASC`), e.spatialClause?.order !== void 0 && S.push(e.spatialClause.order === "desc" ? t`${Tn(e.spatialClause, t)} DESC` : t`${Tn(e.spatialClause, t)} ASC`), l !== null && c?.rank?.order === !0 && S.push(t`${l} DESC`);
|
|
629
|
+
for (let n of e.order) S.push(n.direction === "desc" ? t`${t(n.column)} DESC` : t`${t(n.column)} ASC`);
|
|
630
|
+
let ee = S.length > 0 ? t` ORDER BY ${t.csv(S)}` : x ? t.onDialectOrElse({
|
|
631
631
|
mssql: () => t` ORDER BY (SELECT NULL)`,
|
|
632
632
|
orElse: () => t``
|
|
633
|
-
}) : t``,
|
|
633
|
+
}) : t``, C = (e) => {
|
|
634
634
|
if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw Error(`compileSelect: expected non-negative integer take/skip, got ${e}`);
|
|
635
635
|
return t.unsafe(String(e));
|
|
636
|
-
},
|
|
636
|
+
}, te = (e.ctes ?? []).map((e) => t`${t(e.name)} AS (${L(e.descriptor, t, n)})`), ne = (e.ctes ?? []).some((e) => e.recursive === !0), re = te.length > 0 ? t`WITH ${t.unsafe(ne ? "RECURSIVE " : "")}${t.csv(te)} ` : t``;
|
|
637
637
|
return t.onDialectOrElse({
|
|
638
638
|
mssql: () => {
|
|
639
|
-
let n = e.take !== void 0 && !
|
|
640
|
-
return t`${
|
|
639
|
+
let n = e.take !== void 0 && !x ? t`TOP ${C(e.take)} ` : t``, r = x ? t` OFFSET ${C(e.skip)} ROWS FETCH NEXT ${C(e.take ?? 2 ** 53 - 1)} ROWS ONLY` : t``;
|
|
640
|
+
return t`${re}SELECT ${n}${f}${d} FROM ${h}${v}${y}${b}${ee}${r}`;
|
|
641
641
|
},
|
|
642
642
|
orElse: () => {
|
|
643
|
-
let n = e.take === void 0 ? t`` : t` LIMIT ${
|
|
644
|
-
return t`${
|
|
643
|
+
let n = e.take === void 0 ? t`` : t` LIMIT ${C(e.take)}`, r = x ? t` OFFSET ${C(e.skip)}` : t``;
|
|
644
|
+
return t`${re}SELECT ${f}${d} FROM ${h}${v}${y}${b}${ee}${n}${r}`;
|
|
645
645
|
}
|
|
646
646
|
});
|
|
647
|
-
},
|
|
647
|
+
}, An = (e, t, n) => {
|
|
648
648
|
if (e.eager === void 0) return null;
|
|
649
649
|
let r = Mn(e.table, e.eager, e.sourceTable);
|
|
650
650
|
if (r === null) return null;
|
|
@@ -653,14 +653,14 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
653
653
|
fragment: i,
|
|
654
654
|
decode: Hn(r, n)
|
|
655
655
|
};
|
|
656
|
-
},
|
|
656
|
+
}, R = (e) => e.relation.kind === "one" && e.fkSide === "target", jn = (e) => ({
|
|
657
657
|
...e,
|
|
658
658
|
branch: {
|
|
659
659
|
...e.branch,
|
|
660
660
|
limit: 2
|
|
661
661
|
}
|
|
662
662
|
}), Mn = (e, t, n) => {
|
|
663
|
-
let r = n ?? g(e), i =
|
|
663
|
+
let r = n ?? g(e), i = zt(e);
|
|
664
664
|
if (i === void 0) return null;
|
|
665
665
|
let a = [];
|
|
666
666
|
for (let [e, n] of Object.entries(t)) {
|
|
@@ -681,17 +681,17 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
681
681
|
let r = t.sourceKey ?? Ln(n, i.tableName);
|
|
682
682
|
if (r !== void 0) o = r, s = "source";
|
|
683
683
|
else try {
|
|
684
|
-
o = t.foreignKey ??
|
|
684
|
+
o = t.foreignKey ?? M(i, n.tableName, e), s = "target";
|
|
685
685
|
} catch {
|
|
686
686
|
return null;
|
|
687
687
|
}
|
|
688
688
|
} else try {
|
|
689
|
-
o = t.foreignKey ??
|
|
689
|
+
o = t.foreignKey ?? M(i, n.tableName, e), s = "target";
|
|
690
690
|
} catch {
|
|
691
691
|
return null;
|
|
692
692
|
}
|
|
693
693
|
let c = r.with === void 0 ? [] : (() => {
|
|
694
|
-
let e =
|
|
694
|
+
let e = zt(i.tableName);
|
|
695
695
|
if (e === void 0 && Object.keys(r.with).length > 0) return null;
|
|
696
696
|
let t = [];
|
|
697
697
|
for (let [n, a] of Object.entries(r.with)) {
|
|
@@ -740,10 +740,10 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
740
740
|
switch (e) {
|
|
741
741
|
case "postgres": return Gn(t, n, r);
|
|
742
742
|
case "sqlite":
|
|
743
|
-
case "turso": return
|
|
743
|
+
case "turso": return $n(t, n, r);
|
|
744
744
|
case "mysql":
|
|
745
|
-
case "mariadb": return
|
|
746
|
-
case "mssql": return
|
|
745
|
+
case "mariadb": return lr(t, n, r);
|
|
746
|
+
case "mssql": return gr(t, n, r);
|
|
747
747
|
}
|
|
748
748
|
}, Bn = (e, t) => t === "mssql" && !Vn.test(e) ? /* @__PURE__ */ new Date(`${e}Z`) : new Date(e), Vn = /(?:Z|[+-]\d{2}:?\d{2})$/, Hn = (e, t) => {
|
|
749
749
|
let n = Un(e.table, e.children, t);
|
|
@@ -755,7 +755,7 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
755
755
|
let r = [];
|
|
756
756
|
for (let [t, n] of Object.entries(e.fields)) (n.type === "timestamp" || n.type === "date") && r.push(t);
|
|
757
757
|
let i = t.map((e) => {
|
|
758
|
-
let t = Un(e.target, e.children, n), r = e.relation.kind === "one", i =
|
|
758
|
+
let t = Un(e.target, e.children, n), r = e.relation.kind === "one", i = R(e), a = i ? $t({
|
|
759
759
|
relationName: e.relationName,
|
|
760
760
|
sourceTableName: e.source.tableName,
|
|
761
761
|
targetTableName: e.target.tableName,
|
|
@@ -785,7 +785,7 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
785
785
|
}
|
|
786
786
|
if (e.fromOverFetch) {
|
|
787
787
|
let r = n;
|
|
788
|
-
if (r.length > 1) throw new
|
|
788
|
+
if (r.length > 1) throw new Qt(e.cardinalityMessage);
|
|
789
789
|
t[e.name] = r.length === 0 ? null : e.decode(r[0]);
|
|
790
790
|
continue;
|
|
791
791
|
}
|
|
@@ -812,189 +812,189 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
812
812
|
};
|
|
813
813
|
};
|
|
814
814
|
}, Gn = (e, t, n) => {
|
|
815
|
-
let r = n.sql, i = n.nextAlias(), a = r(t.table.tableName), o = r(i), s =
|
|
816
|
-
return s === null ? null : r`SELECT ${s} AS "__row" FROM ${a} AS ${o}${e.predicate ? r` WHERE ${
|
|
817
|
-
},
|
|
818
|
-
let i = n.sql, a = r === void 0 ? i`to_jsonb(${i(e)}.*)` : i`(to_jsonb(${i(e)}.*) - ${
|
|
815
|
+
let r = n.sql, i = n.nextAlias(), a = r(t.table.tableName), o = r(i), s = Kn(i, t.children, n);
|
|
816
|
+
return s === null ? null : r`SELECT ${s} AS "__row" FROM ${a} AS ${o}${e.predicate ? r` WHERE ${W(e.predicate, i, r)}` : r``}${e.order.length > 0 ? r` ORDER BY ${r.csv(e.order.map((e) => e.direction === "desc" ? r`${V(i, e.column, r)} DESC` : r`${V(i, e.column, r)} ASC`))}` : r``}${e.take === void 0 ? r`` : r` LIMIT ${U(e.take, r)}`}${e.skip === void 0 ? r`` : r` OFFSET ${U(e.skip, r)}`}`;
|
|
817
|
+
}, Kn = (e, t, n, r) => {
|
|
818
|
+
let i = n.sql, a = r === void 0 ? i`to_jsonb(${i(e)}.*)` : i`(to_jsonb(${i(e)}.*) - ${H(In, i)}::text)`;
|
|
819
819
|
if (t.length === 0 && r === void 0) return a;
|
|
820
820
|
let o = [];
|
|
821
|
-
r !== void 0 && o.push(i`${
|
|
821
|
+
r !== void 0 && o.push(i`${H("_junction", i)}, ${V(e, In, i)}`);
|
|
822
822
|
for (let r of t) {
|
|
823
|
-
let t =
|
|
823
|
+
let t = qn(r, e, n);
|
|
824
824
|
if (t === null) return null;
|
|
825
|
-
o.push(i`${
|
|
825
|
+
o.push(i`${H(r.relationName, i)}, ${t}`);
|
|
826
826
|
}
|
|
827
827
|
return i`${a} || jsonb_build_object(${i.csv(o)})`;
|
|
828
|
-
},
|
|
828
|
+
}, qn = (e, t, n) => {
|
|
829
829
|
switch (e.relation.kind) {
|
|
830
|
-
case "one": return
|
|
831
|
-
case "many": return
|
|
832
|
-
case "manyToMany": return
|
|
830
|
+
case "one": return R(e) ? Yn(jn(e), t, n) : Jn(e, t, n);
|
|
831
|
+
case "many": return Yn(e, t, n);
|
|
832
|
+
case "manyToMany": return Xn(e, t, n);
|
|
833
833
|
}
|
|
834
|
-
},
|
|
835
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
834
|
+
}, Jn = (e, t, n) => {
|
|
835
|
+
let r = n.sql, i = n.nextAlias(), a = Kn(i, e.children, n);
|
|
836
836
|
if (a === null) return null;
|
|
837
|
-
let o = e.fkSide === "source" ? r`${
|
|
837
|
+
let o = e.fkSide === "source" ? r`${V(i, "id", r)} = ${V(t, e.foreignKey, r)}` : r`${V(i, e.foreignKey, r)} = ${V(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${W(e.branch.where, i, r)}`, c = z(i, e.branch.orderBy, r);
|
|
838
838
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}${c} LIMIT 1)`;
|
|
839
|
-
},
|
|
840
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
839
|
+
}, Yn = (e, t, n) => {
|
|
840
|
+
let r = n.sql, i = n.nextAlias(), a = Kn(i, e.children, n);
|
|
841
841
|
if (a === null) return null;
|
|
842
|
-
let o = r`${
|
|
842
|
+
let o = r`${V(void 0, e.foreignKey, r)} = ${V(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${I(e.branch.where, r)}`, c = Qn(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${U(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${U(e.branch.offset, r)}`;
|
|
843
843
|
return r`COALESCE((SELECT jsonb_agg(${a}) FROM (SELECT * FROM ${r(e.target.tableName)} WHERE ${o}${s}${c}${l}${u}) AS ${r(i)}), '[]'::jsonb)`;
|
|
844
|
-
},
|
|
845
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
844
|
+
}, Xn = (e, t, n) => {
|
|
845
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = Kn(o, e.children, n, e.junction);
|
|
846
846
|
if (c === null) return null;
|
|
847
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
848
|
-
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 ${
|
|
849
|
-
},
|
|
850
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
847
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${I(e.branch.where, r)}`, u = G(e, s, r), d = z(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${U(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${U(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : r`, ${Zn(e.junction, s, r)} AS ${r(In)}`;
|
|
848
|
+
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 ${V(o, "id", r)} = ${V(s, i.targetKey, r)} WHERE ${V(s, i.sourceKey, r)} = ${V(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), '[]'::jsonb)`;
|
|
849
|
+
}, Zn = (e, t, n) => e.present.length === 0 ? n`jsonb_build_object()` : n`jsonb_build_object(${n.csv(e.present.map((e) => n`${H(e, n)}, ${V(t, e, n)}`))})`, z = (e, t, n) => t === void 0 || t.length === 0 ? n`` : n` ORDER BY ${n.csv(t.map((t) => t.direction === "desc" ? n`${V(e, t.column, n)} DESC` : n`${V(e, t.column, n)} ASC`))}`, Qn = (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`))}`, $n = (e, t, n) => {
|
|
850
|
+
let r = n.sql, i = n.nextAlias(), a = er(i, t.table, t.children, n);
|
|
851
851
|
if (a === null) return null;
|
|
852
|
-
let o = e.predicate ? r` WHERE ${
|
|
852
|
+
let o = e.predicate ? r` WHERE ${W(e.predicate, i, r)}` : r``, s = e.order.length > 0 ? r` ORDER BY ${r.csv(e.order.map((e) => e.direction === "desc" ? r`${V(i, e.column, r)} DESC` : r`${V(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${U(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${U(e.skip, r)}`;
|
|
853
853
|
return r`SELECT ${a} AS "__row" FROM ${r(t.table.tableName)} AS ${r(i)}${o}${s}${c}${l}`;
|
|
854
|
-
},
|
|
854
|
+
}, er = (e, t, n, r, i) => {
|
|
855
855
|
let a = r.sql, o = [];
|
|
856
|
-
for (let n of Object.keys(t.fields)) o.push(a`${
|
|
856
|
+
for (let n of Object.keys(t.fields)) o.push(a`${H(n, a)}, ${V(e, n, a)}`);
|
|
857
857
|
if (i !== void 0) {
|
|
858
|
-
let e =
|
|
859
|
-
o.push(a`${
|
|
858
|
+
let e = tr(i.projection, i.source, a);
|
|
859
|
+
o.push(a`${H("_junction", a)}, json_object(${e})`);
|
|
860
860
|
}
|
|
861
861
|
for (let t of n) {
|
|
862
|
-
let n =
|
|
862
|
+
let n = ar(t, e, r);
|
|
863
863
|
if (n === null) return null;
|
|
864
|
-
o.push(a`${
|
|
864
|
+
o.push(a`${H(t.relationName, a)}, ${n}`);
|
|
865
865
|
}
|
|
866
866
|
return a`json_object(${a.csv(o)})`;
|
|
867
|
-
},
|
|
867
|
+
}, tr = (e, t, n) => e.present.length === 0 ? n`` : n.csv(e.present.map((e) => n`${H(e, n)}, ${V(t.alias, t.physical(e), n)}`)), nr = (e, t, n) => e.present.length === 0 ? n`` : n`, ${n.csv(e.present.map((e) => n`${V(t, e, n)} AS ${n(Fn(e))}`))}`, rr = (e) => ({
|
|
868
868
|
alias: e,
|
|
869
869
|
physical: Fn
|
|
870
|
-
}),
|
|
870
|
+
}), ir = (e) => ({
|
|
871
871
|
alias: e,
|
|
872
872
|
physical: (e) => e
|
|
873
|
-
}),
|
|
873
|
+
}), ar = (e, t, n) => {
|
|
874
874
|
switch (e.relation.kind) {
|
|
875
|
-
case "one": return
|
|
876
|
-
case "many": return
|
|
877
|
-
case "manyToMany": return
|
|
875
|
+
case "one": return R(e) ? sr(jn(e), t, n) : or(e, t, n);
|
|
876
|
+
case "many": return sr(e, t, n);
|
|
877
|
+
case "manyToMany": return cr(e, t, n);
|
|
878
878
|
}
|
|
879
|
-
},
|
|
880
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
879
|
+
}, or = (e, t, n) => {
|
|
880
|
+
let r = n.sql, i = n.nextAlias(), a = er(i, e.target, e.children, n);
|
|
881
881
|
if (a === null) return null;
|
|
882
|
-
let o = e.fkSide === "source" ? r`${
|
|
882
|
+
let o = e.fkSide === "source" ? r`${V(i, "id", r)} = ${V(t, e.foreignKey, r)}` : r`${V(i, e.foreignKey, r)} = ${V(t, e.sourceKey, r)}`;
|
|
883
883
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
|
|
884
|
-
},
|
|
885
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
884
|
+
}, sr = (e, t, n) => {
|
|
885
|
+
let r = n.sql, i = n.nextAlias(), a = er(i, e.target, e.children, n);
|
|
886
886
|
if (a === null) return null;
|
|
887
|
-
let o = r`${
|
|
887
|
+
let o = r`${V(void 0, e.foreignKey, r)} = ${V(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${I(K(e.branch.where), r)}`, c = Qn(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${U(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${U(e.branch.offset, r)}`;
|
|
888
888
|
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('[]'))`;
|
|
889
|
-
},
|
|
890
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
889
|
+
}, cr = (e, t, n) => {
|
|
890
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = er(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
891
891
|
projection: e.junction,
|
|
892
|
-
source:
|
|
892
|
+
source: rr(o)
|
|
893
893
|
});
|
|
894
894
|
if (c === null) return null;
|
|
895
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
896
|
-
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 ${
|
|
897
|
-
},
|
|
898
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
895
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${I(K(e.branch.where), r)}`, u = G(e, s, r, !0), d = z(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${U(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${U(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : nr(e.junction, s, r);
|
|
896
|
+
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 ${V(o, "id", r)} = ${V(s, i.targetKey, r)} WHERE ${V(s, i.sourceKey, r)} = ${V(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), json('[]'))`;
|
|
897
|
+
}, lr = (e, t, n) => {
|
|
898
|
+
let r = n.sql, i = n.nextAlias(), a = B(i, t.table, t.children, n);
|
|
899
899
|
if (a === null) return null;
|
|
900
|
-
let o = e.predicate ? r` WHERE ${
|
|
900
|
+
let o = e.predicate ? r` WHERE ${W(e.predicate, i, r)}` : r``, s = e.order.length > 0 ? r` ORDER BY ${r.csv(e.order.map((e) => e.direction === "desc" ? r`${V(i, e.column, r)} DESC` : r`${V(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${U(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${U(e.skip, r)}`;
|
|
901
901
|
return r`SELECT ${a} AS \`__row\` FROM ${r(t.table.tableName)} AS ${r(i)}${o}${s}${c}${l}`;
|
|
902
|
-
},
|
|
902
|
+
}, B = (e, t, n, r, i) => {
|
|
903
903
|
let a = r.sql, o = [];
|
|
904
|
-
for (let n of Object.keys(t.fields)) o.push(a`${
|
|
904
|
+
for (let n of Object.keys(t.fields)) o.push(a`${H(n, a)}, ${V(e, n, a)}`);
|
|
905
905
|
if (i !== void 0) {
|
|
906
|
-
let e =
|
|
907
|
-
o.push(a`${
|
|
906
|
+
let e = tr(i.projection, i.source, a);
|
|
907
|
+
o.push(a`${H("_junction", a)}, JSON_OBJECT(${e})`);
|
|
908
908
|
}
|
|
909
909
|
for (let t of n) {
|
|
910
|
-
let n =
|
|
910
|
+
let n = ur(t, e, r);
|
|
911
911
|
if (n === null) return null;
|
|
912
|
-
o.push(a`${
|
|
912
|
+
o.push(a`${H(t.relationName, a)}, ${n}`);
|
|
913
913
|
}
|
|
914
914
|
return a`JSON_OBJECT(${a.csv(o)})`;
|
|
915
|
-
},
|
|
915
|
+
}, ur = (e, t, n) => {
|
|
916
916
|
switch (e.relation.kind) {
|
|
917
917
|
case "one":
|
|
918
|
-
if (
|
|
919
|
-
let r =
|
|
920
|
-
return n.dialect === "mariadb" ?
|
|
918
|
+
if (R(e)) {
|
|
919
|
+
let r = jn(e);
|
|
920
|
+
return n.dialect === "mariadb" ? mr(r, t, n) : fr(r, t, n);
|
|
921
921
|
}
|
|
922
|
-
return
|
|
923
|
-
case "many": return n.dialect === "mariadb" ?
|
|
924
|
-
case "manyToMany": return n.dialect === "mariadb" ?
|
|
922
|
+
return dr(e, t, n);
|
|
923
|
+
case "many": return n.dialect === "mariadb" ? mr(e, t, n) : fr(e, t, n);
|
|
924
|
+
case "manyToMany": return n.dialect === "mariadb" ? hr(e, t, n) : pr(e, t, n);
|
|
925
925
|
}
|
|
926
|
-
},
|
|
927
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
926
|
+
}, dr = (e, t, n) => {
|
|
927
|
+
let r = n.sql, i = n.nextAlias(), a = B(i, e.target, e.children, n);
|
|
928
928
|
if (a === null) return null;
|
|
929
|
-
let o = e.fkSide === "source" ? r`${
|
|
929
|
+
let o = e.fkSide === "source" ? r`${V(i, "id", r)} = ${V(t, e.foreignKey, r)}` : r`${V(i, e.foreignKey, r)} = ${V(t, e.sourceKey, r)}`;
|
|
930
930
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
|
|
931
|
-
},
|
|
932
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
931
|
+
}, fr = (e, t, n) => {
|
|
932
|
+
let r = n.sql, i = n.nextAlias(), a = B(i, e.target, e.children, n);
|
|
933
933
|
if (a === null) return null;
|
|
934
|
-
let o = r`${
|
|
934
|
+
let o = r`${V(void 0, e.foreignKey, r)} = ${V(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${I(K(e.branch.where), r)}`, c = Qn(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${U(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${U(e.branch.offset, r)}`;
|
|
935
935
|
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())`;
|
|
936
|
-
},
|
|
937
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
936
|
+
}, pr = (e, t, n) => {
|
|
937
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = B(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
938
938
|
projection: e.junction,
|
|
939
|
-
source:
|
|
939
|
+
source: rr(o)
|
|
940
940
|
});
|
|
941
941
|
if (c === null) return null;
|
|
942
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
943
|
-
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 ${
|
|
944
|
-
},
|
|
945
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
942
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${I(K(e.branch.where), r)}`, u = G(e, s, r, !0), d = z(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${U(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${U(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : nr(e.junction, s, r);
|
|
943
|
+
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 ${V(o, "id", r)} = ${V(s, i.targetKey, r)} WHERE ${V(s, i.sourceKey, r)} = ${V(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), JSON_ARRAY())`;
|
|
944
|
+
}, mr = (e, t, n) => {
|
|
945
|
+
let r = n.sql, i = n.nextAlias(), a = B(i, e.target, e.children, n);
|
|
946
946
|
if (a === null) return null;
|
|
947
|
-
let o = r`${
|
|
948
|
-
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`${
|
|
949
|
-
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 ${
|
|
950
|
-
return r`COALESCE((SELECT JSON_ARRAYAGG(${a} ORDER BY ${
|
|
951
|
-
},
|
|
947
|
+
let o = r`${V(i, e.foreignKey, r)} = ${V(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${I(K(e.branch.where), r)}`, c = e.branch.orderBy ?? [];
|
|
948
|
+
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`${V(i, e.column, r)} DESC` : r`${V(i, e.column, r)} ASC`))}` : r``}) FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}), JSON_ARRAY())`;
|
|
949
|
+
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 ${V(i, "rn", r)} > ${U(d, r)} AND ${V(i, "rn", r)} <= ${U(d + u, r)}` : u === void 0 ? r` AND ${V(i, "rn", r)} > ${U(d, r)}` : r` AND ${V(i, "rn", r)} <= ${U(u, r)}`;
|
|
950
|
+
return r`COALESCE((SELECT JSON_ARRAYAGG(${a} ORDER BY ${V(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())`;
|
|
951
|
+
}, hr = (e, t, n) => {
|
|
952
952
|
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = (t) => e.junction === void 0 ? void 0 : {
|
|
953
953
|
projection: e.junction,
|
|
954
954
|
source: t
|
|
955
|
-
}, l = r`${
|
|
955
|
+
}, l = r`${V(s, i.sourceKey, r)} = ${V(t, "id", r)}`, u = r`${V(o, "id", r)} = ${V(s, i.targetKey, r)}`, d = e.branch.where === void 0 ? r`` : r` AND ${I(K(e.branch.where), r)}`, f = G(e, s, r, !0), p = e.branch.orderBy ?? [];
|
|
956
956
|
if (!(e.branch.limit !== void 0 || e.branch.offset !== void 0)) {
|
|
957
|
-
let t =
|
|
958
|
-
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`${
|
|
959
|
-
}
|
|
960
|
-
let m = p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${
|
|
961
|
-
if (
|
|
962
|
-
let
|
|
963
|
-
return r`COALESCE((SELECT JSON_ARRAYAGG(${
|
|
964
|
-
},
|
|
965
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
957
|
+
let t = B(o, e.target, e.children, n, c(ir(s)));
|
|
958
|
+
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`${V(o, e.column, r)} DESC` : r`${V(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())`;
|
|
959
|
+
}
|
|
960
|
+
let m = p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${V(o, e.column, r)} DESC` : r`${V(o, e.column, r)} ASC`))}` : r` ORDER BY ${V(o, "id", r)}`, h = e.branch.limit, g = e.branch.offset, _ = h !== void 0 && g !== void 0 ? r` AND ${V(o, "rn", r)} > ${U(g, r)} AND ${V(o, "rn", r)} <= ${U(g + h, r)}` : h === void 0 ? r` AND ${V(o, "rn", r)} > ${U(g, r)}` : r` AND ${V(o, "rn", r)} <= ${U(h, r)}`, v = e.branch.onJunction === void 0 ? r`` : r` WHERE ${W(K(e.branch.onJunction), s, r)}`, y = B(o, e.target, e.children, n, c(rr(o)));
|
|
961
|
+
if (y === null) return null;
|
|
962
|
+
let b = e.junction === void 0 ? r`` : nr(e.junction, s, r);
|
|
963
|
+
return r`COALESCE((SELECT JSON_ARRAYAGG(${y} ORDER BY ${V(o, "rn", r)}) FROM (SELECT ${r(o)}.*${b}, ${V(s, i.sourceKey, r)} AS ${r(`__src_${i.sourceKey}`)}, ROW_NUMBER() OVER (PARTITION BY ${V(s, i.sourceKey, r)}${m}) AS rn FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${u}${v}) AS ${r(o)} WHERE ${V(o, `__src_${i.sourceKey}`, r)} = ${V(t, "id", r)}${d}${_}), JSON_ARRAY())`;
|
|
964
|
+
}, gr = (e, t, n) => {
|
|
965
|
+
let r = n.sql, i = n.nextAlias(), a = _r(i, t.table, t.children, n);
|
|
966
966
|
if (a === null) return null;
|
|
967
|
-
let o = e.predicate ? r` WHERE ${
|
|
967
|
+
let o = e.predicate ? r` WHERE ${W(e.predicate, i, r)}` : r``, s = e.order.length > 0 ? r` ORDER BY ${r.csv(e.order.map((e) => e.direction === "desc" ? r`${V(i, e.column, r)} DESC` : r`${V(i, e.column, r)} ASC`))}` : r``, c = r``, l = r``;
|
|
968
968
|
if (e.skip !== void 0) {
|
|
969
969
|
let t = e.order.length > 0 ? s : r` ORDER BY (SELECT NULL)`;
|
|
970
|
-
l = e.take === void 0 ? r`${t} OFFSET ${
|
|
971
|
-
} else e.take !== void 0 && (c = r`TOP ${
|
|
970
|
+
l = e.take === void 0 ? r`${t} OFFSET ${U(e.skip, r)} ROWS` : r`${t} OFFSET ${U(e.skip, r)} ROWS FETCH NEXT ${U(e.take, r)} ROWS ONLY`;
|
|
971
|
+
} else e.take !== void 0 && (c = r`TOP ${U(e.take, r)} `);
|
|
972
972
|
let u = e.skip === void 0 ? s : r``;
|
|
973
973
|
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}`;
|
|
974
|
-
},
|
|
974
|
+
}, _r = (e, t, n, r, i) => {
|
|
975
975
|
let a = r.sql, o = [];
|
|
976
|
-
for (let n of Object.keys(t.fields)) o.push(a`${
|
|
977
|
-
if (i !== void 0) for (let e of i.projection.present) o.push(a`${
|
|
976
|
+
for (let n of Object.keys(t.fields)) o.push(a`${V(e, n, a)} AS ${a(n)}`);
|
|
977
|
+
if (i !== void 0) for (let e of i.projection.present) o.push(a`${V(i.source.alias, i.source.physical(e), a)} AS ${vr(`_junction.${e}`, a)}`);
|
|
978
978
|
for (let t of n) {
|
|
979
|
-
let n =
|
|
979
|
+
let n = yr(t, e, r);
|
|
980
980
|
if (n === null) return null;
|
|
981
981
|
o.push(n);
|
|
982
982
|
}
|
|
983
983
|
return a.csv(o);
|
|
984
|
-
},
|
|
984
|
+
}, vr = (e, t) => t.unsafe(`[${e.replace(/]/g, "]]")}]`), yr = (e, t, n) => {
|
|
985
985
|
switch (e.relation.kind) {
|
|
986
|
-
case "one": return
|
|
987
|
-
case "many": return
|
|
988
|
-
case "manyToMany": return
|
|
986
|
+
case "one": return R(e) ? Sr(jn(e), t, n) : br(e, t, n);
|
|
987
|
+
case "many": return Sr(e, t, n);
|
|
988
|
+
case "manyToMany": return Cr(e, t, n);
|
|
989
989
|
}
|
|
990
|
-
},
|
|
991
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
990
|
+
}, br = (e, t, n) => {
|
|
991
|
+
let r = n.sql, i = n.nextAlias(), a = _r(i, e.target, e.children, n);
|
|
992
992
|
if (a === null) return null;
|
|
993
|
-
let o = e.fkSide === "source" ? r`${
|
|
993
|
+
let o = e.fkSide === "source" ? r`${V(i, "id", r)} = ${V(t, e.foreignKey, r)}` : r`${V(i, e.foreignKey, r)} = ${V(t, e.sourceKey, r)}`;
|
|
994
994
|
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)}`;
|
|
995
|
-
},
|
|
995
|
+
}, xr = (e, t, n) => {
|
|
996
996
|
if (e.offset !== void 0) {
|
|
997
|
-
let r = e.orderBy && e.orderBy.length > 0 ? t : n` ORDER BY (SELECT NULL)`, i = e.limit === void 0 ? n`${r} OFFSET ${
|
|
997
|
+
let r = e.orderBy && e.orderBy.length > 0 ? t : n` ORDER BY (SELECT NULL)`, i = e.limit === void 0 ? n`${r} OFFSET ${U(e.offset, n)} ROWS` : n`${r} OFFSET ${U(e.offset, n)} ROWS FETCH NEXT ${U(e.limit, n)} ROWS ONLY`;
|
|
998
998
|
return {
|
|
999
999
|
top: n``,
|
|
1000
1000
|
pagination: i,
|
|
@@ -1002,33 +1002,33 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1002
1002
|
};
|
|
1003
1003
|
}
|
|
1004
1004
|
return {
|
|
1005
|
-
top: e.limit === void 0 ? n`` : n`TOP ${
|
|
1005
|
+
top: e.limit === void 0 ? n`` : n`TOP ${U(e.limit, n)} `,
|
|
1006
1006
|
pagination: n``,
|
|
1007
1007
|
finalOrder: t
|
|
1008
1008
|
};
|
|
1009
|
-
},
|
|
1010
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1009
|
+
}, Sr = (e, t, n) => {
|
|
1010
|
+
let r = n.sql, i = n.nextAlias(), a = _r(i, e.target, e.children, n);
|
|
1011
1011
|
if (a === null) return null;
|
|
1012
|
-
let o = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1013
|
-
return r`ISNULL(JSON_QUERY((SELECT ${c}${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${
|
|
1014
|
-
},
|
|
1015
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
1012
|
+
let o = e.branch.where === void 0 ? r`` : r` AND ${W(e.branch.where, i, r)}`, s = z(i, e.branch.orderBy, r), { top: c, pagination: l, finalOrder: u } = xr(e.branch, s, r);
|
|
1013
|
+
return r`ISNULL(JSON_QUERY((SELECT ${c}${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${V(i, e.foreignKey, r)} = ${V(t, e.sourceKey, r)}${o}${u}${l} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
|
|
1014
|
+
}, Cr = (e, t, n) => {
|
|
1015
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = _r(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
1016
1016
|
projection: e.junction,
|
|
1017
|
-
source:
|
|
1017
|
+
source: ir(s)
|
|
1018
1018
|
});
|
|
1019
1019
|
if (c === null) return null;
|
|
1020
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1021
|
-
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 ${
|
|
1022
|
-
},
|
|
1020
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${W(e.branch.where, o, r)}`, u = G(e, s, r), d = z(o, e.branch.orderBy, r), { top: f, pagination: p, finalOrder: m } = xr(e.branch, d, r);
|
|
1021
|
+
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 ${V(o, "id", r)} = ${V(s, i.targetKey, r)} WHERE ${V(s, i.sourceKey, r)} = ${V(t, "id", r)}${u}${l}${m}${p} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
|
|
1022
|
+
}, V = (e, t, n) => e === void 0 ? n`${n(t)}` : n`${n(e)}.${n(t)}`, H = (e, t) => t.unsafe(`'${e.replace(/'/g, "''")}'`), U = (e, t) => {
|
|
1023
1023
|
if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw Error(`literalInt: expected non-negative integer, got ${e}`);
|
|
1024
1024
|
return t.unsafe(String(e));
|
|
1025
|
-
},
|
|
1025
|
+
}, W = (e, t, n) => I(wr(e, t), n), G = (e, t, n, r = !1) => {
|
|
1026
1026
|
let i = e.branch.onJunction;
|
|
1027
|
-
return i === void 0 ? n`` : n` AND ${
|
|
1028
|
-
},
|
|
1029
|
-
if ("not" in e) return { not:
|
|
1030
|
-
if ("and" in e) return { and: e.and.map((e) =>
|
|
1031
|
-
if ("or" in e) return { or: e.or.map((e) =>
|
|
1027
|
+
return i === void 0 ? n`` : n` AND ${W(r ? K(i) : i, t, n)}`;
|
|
1028
|
+
}, wr = (e, t) => {
|
|
1029
|
+
if ("not" in e) return { not: wr(e.not, t) };
|
|
1030
|
+
if ("and" in e) return { and: e.and.map((e) => wr(e, t)) };
|
|
1031
|
+
if ("or" in e) return { or: e.or.map((e) => wr(e, t)) };
|
|
1032
1032
|
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
1033
1033
|
let n = e;
|
|
1034
1034
|
return {
|
|
@@ -1042,91 +1042,91 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1042
1042
|
...n,
|
|
1043
1043
|
column: `${t}.${n.column}`
|
|
1044
1044
|
};
|
|
1045
|
-
},
|
|
1046
|
-
if ("not" in e) return { not:
|
|
1047
|
-
if ("and" in e) return { and: e.and.map((e) =>
|
|
1048
|
-
if ("or" in e) return { or: e.or.map((e) =>
|
|
1045
|
+
}, K = (e) => {
|
|
1046
|
+
if ("not" in e) return { not: K(e.not) };
|
|
1047
|
+
if ("and" in e) return { and: e.and.map((e) => K(e)) };
|
|
1048
|
+
if ("or" in e) return { or: e.or.map((e) => K(e)) };
|
|
1049
1049
|
if (e.op === "subquery-in" || e.op === "subquery-not-in" || e.op === "exists" || e.op === "not-exists") return e;
|
|
1050
1050
|
let t = e;
|
|
1051
1051
|
return {
|
|
1052
1052
|
...t,
|
|
1053
|
-
value:
|
|
1053
|
+
value: Tr(t.value)
|
|
1054
1054
|
};
|
|
1055
|
-
},
|
|
1056
|
-
e.actors !== void 0 && (
|
|
1057
|
-
},
|
|
1055
|
+
}, Tr = (e) => e == null ? e : e instanceof Date ? e.toISOString() : typeof e == "boolean" ? +!!e : Array.isArray(e) ? e.map((e) => Tr(e)) : e, Er = Symbol.for("@voltro/database/coreTablesRegistry"), Dr = globalThis, Or = Dr[Er] ?? (Dr[Er] = {}), kr = (e) => {
|
|
1056
|
+
e.actors !== void 0 && (Or.actors = e.actors), e.tenants !== void 0 && (Or.tenants = e.tenants);
|
|
1057
|
+
}, Ar = (e, t) => () => {
|
|
1058
1058
|
let n = e();
|
|
1059
1059
|
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`);
|
|
1060
1060
|
return n();
|
|
1061
|
-
},
|
|
1062
|
-
id:
|
|
1063
|
-
kind:
|
|
1061
|
+
}, jr = () => Ar(() => Or.actors, "actors"), Mr = () => Ar(() => Or.tenants, "tenants"), Nr = f("actors", {
|
|
1062
|
+
id: w(),
|
|
1063
|
+
kind: n().oneOf([
|
|
1064
1064
|
"user",
|
|
1065
1065
|
"serviceAccount",
|
|
1066
1066
|
"apiKey",
|
|
1067
1067
|
"system"
|
|
1068
1068
|
]),
|
|
1069
|
-
displayName:
|
|
1070
|
-
createdAt:
|
|
1071
|
-
}),
|
|
1069
|
+
displayName: n().nullable(),
|
|
1070
|
+
createdAt: E().default("now")
|
|
1071
|
+
}), Pr = (e, t) => ({
|
|
1072
1072
|
column: e,
|
|
1073
1073
|
op: "eq",
|
|
1074
1074
|
value: t
|
|
1075
|
-
}),
|
|
1075
|
+
}), Fr = (e, t) => ({
|
|
1076
1076
|
column: e,
|
|
1077
1077
|
op: "neq",
|
|
1078
1078
|
value: t
|
|
1079
|
-
}),
|
|
1079
|
+
}), Ir = (e, t) => ({
|
|
1080
1080
|
column: e,
|
|
1081
1081
|
op: "gt",
|
|
1082
1082
|
value: t
|
|
1083
|
-
}),
|
|
1083
|
+
}), Lr = (e, t) => ({
|
|
1084
1084
|
column: e,
|
|
1085
1085
|
op: "gte",
|
|
1086
1086
|
value: t
|
|
1087
|
-
}),
|
|
1087
|
+
}), Rr = (e, t) => ({
|
|
1088
1088
|
column: e,
|
|
1089
1089
|
op: "lt",
|
|
1090
1090
|
value: t
|
|
1091
|
-
}),
|
|
1091
|
+
}), zr = (e, t) => ({
|
|
1092
1092
|
column: e,
|
|
1093
1093
|
op: "lte",
|
|
1094
1094
|
value: t
|
|
1095
|
-
}),
|
|
1095
|
+
}), Br = (e, t) => ({
|
|
1096
1096
|
column: e,
|
|
1097
1097
|
op: "in",
|
|
1098
1098
|
value: t
|
|
1099
|
-
}),
|
|
1099
|
+
}), Vr = (e, t) => ({
|
|
1100
1100
|
column: e,
|
|
1101
1101
|
op: "notIn",
|
|
1102
1102
|
value: t
|
|
1103
|
-
}),
|
|
1103
|
+
}), Hr = (e, t) => ({
|
|
1104
1104
|
column: e,
|
|
1105
1105
|
op: "contains",
|
|
1106
1106
|
value: t
|
|
1107
|
-
}),
|
|
1107
|
+
}), Ur = (e, t) => ({
|
|
1108
1108
|
column: e,
|
|
1109
1109
|
op: "arrayContains",
|
|
1110
1110
|
value: t
|
|
1111
|
-
}),
|
|
1111
|
+
}), Wr = (e, t) => ({
|
|
1112
1112
|
column: e,
|
|
1113
1113
|
op: "arrayOverlaps",
|
|
1114
1114
|
value: t
|
|
1115
|
-
}),
|
|
1115
|
+
}), Gr = (e, t) => ({
|
|
1116
1116
|
column: e,
|
|
1117
1117
|
op: "arrayHas",
|
|
1118
1118
|
value: t
|
|
1119
|
-
}),
|
|
1119
|
+
}), Kr = (e) => ({
|
|
1120
1120
|
column: e,
|
|
1121
1121
|
op: "isNull"
|
|
1122
|
-
}),
|
|
1122
|
+
}), qr = (e) => ({
|
|
1123
1123
|
column: e,
|
|
1124
1124
|
op: "isNotNull"
|
|
1125
|
-
}),
|
|
1125
|
+
}), Jr = (e, t) => ({
|
|
1126
1126
|
column: e,
|
|
1127
1127
|
op: "spatial",
|
|
1128
1128
|
value: t
|
|
1129
|
-
}),
|
|
1129
|
+
}), Yr = (...e) => ({ and: e }), Xr = (...e) => ({ or: e }), Zr = (e) => ({ not: e }), Qr = (e, ...t) => {
|
|
1130
1130
|
if (t.length === 0) throw Error(`jsonField("${e}"): at least one path segment is required`);
|
|
1131
1131
|
let n = (n, r) => ({
|
|
1132
1132
|
column: e,
|
|
@@ -1147,29 +1147,29 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1147
1147
|
isNull: () => n("isNull"),
|
|
1148
1148
|
isNotNull: () => n("isNotNull")
|
|
1149
1149
|
};
|
|
1150
|
-
},
|
|
1150
|
+
}, $r = (e) => "descriptor" in e ? e.descriptor : e, ei = (e, t) => ({
|
|
1151
1151
|
column: e,
|
|
1152
1152
|
op: "subquery-in",
|
|
1153
|
-
subquery:
|
|
1154
|
-
}),
|
|
1153
|
+
subquery: $r(t)
|
|
1154
|
+
}), ti = (e, t) => ({
|
|
1155
1155
|
column: e,
|
|
1156
1156
|
op: "subquery-not-in",
|
|
1157
|
-
subquery:
|
|
1158
|
-
}),
|
|
1157
|
+
subquery: $r(t)
|
|
1158
|
+
}), ni = (e) => ({
|
|
1159
1159
|
op: "exists",
|
|
1160
|
-
subquery:
|
|
1161
|
-
}),
|
|
1160
|
+
subquery: $r(e)
|
|
1161
|
+
}), ri = (e) => ({
|
|
1162
1162
|
op: "not-exists",
|
|
1163
|
-
subquery:
|
|
1164
|
-
}),
|
|
1163
|
+
subquery: $r(e)
|
|
1164
|
+
}), ii = (e, t) => e == null || t == null ? null : typeof e == typeof t ? e === t ? 0 : e > t ? 1 : -1 : null, ai = (e, t, n = null) => {
|
|
1165
1165
|
if (!t) return !1;
|
|
1166
|
-
if ("not" in e) return !
|
|
1166
|
+
if ("not" in e) return !ai(e.not, t, n);
|
|
1167
1167
|
if ("and" in e) {
|
|
1168
|
-
for (let r of e.and) if (!
|
|
1168
|
+
for (let r of e.and) if (!ai(r, t, n)) return !1;
|
|
1169
1169
|
return !0;
|
|
1170
1170
|
}
|
|
1171
1171
|
if ("or" in e) {
|
|
1172
|
-
for (let r of e.or) if (
|
|
1172
|
+
for (let r of e.or) if (ai(r, t, n)) return !0;
|
|
1173
1173
|
return !1;
|
|
1174
1174
|
}
|
|
1175
1175
|
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
@@ -1188,10 +1188,10 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1188
1188
|
switch (r.op) {
|
|
1189
1189
|
case "eq": return i === r.value;
|
|
1190
1190
|
case "neq": return i !== r.value;
|
|
1191
|
-
case "gt": return (
|
|
1192
|
-
case "gte": return (
|
|
1193
|
-
case "lt": return (
|
|
1194
|
-
case "lte": return (
|
|
1191
|
+
case "gt": return (ii(i, r.value) ?? -1) > 0;
|
|
1192
|
+
case "gte": return (ii(i, r.value) ?? -1) >= 0;
|
|
1193
|
+
case "lt": return (ii(i, r.value) ?? 1) < 0;
|
|
1194
|
+
case "lte": return (ii(i, r.value) ?? 1) <= 0;
|
|
1195
1195
|
case "in": return Array.isArray(r.value) && r.value.includes(i);
|
|
1196
1196
|
case "notIn": return Array.isArray(r.value) && !r.value.includes(i);
|
|
1197
1197
|
case "contains": return typeof i == "string" && typeof r.value == "string" && i.toLowerCase().includes(r.value.toLowerCase());
|
|
@@ -1208,17 +1208,17 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1208
1208
|
case "isNotNull": return i != null;
|
|
1209
1209
|
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.");
|
|
1210
1210
|
}
|
|
1211
|
-
},
|
|
1211
|
+
}, oi = function* (e) {
|
|
1212
1212
|
if ("not" in e) {
|
|
1213
|
-
yield*
|
|
1213
|
+
yield* oi(e.not);
|
|
1214
1214
|
return;
|
|
1215
1215
|
}
|
|
1216
1216
|
if ("and" in e) {
|
|
1217
|
-
for (let t of e.and) yield*
|
|
1217
|
+
for (let t of e.and) yield* oi(t);
|
|
1218
1218
|
return;
|
|
1219
1219
|
}
|
|
1220
1220
|
if ("or" in e) {
|
|
1221
|
-
for (let t of e.or) yield*
|
|
1221
|
+
for (let t of e.or) yield* oi(t);
|
|
1222
1222
|
return;
|
|
1223
1223
|
}
|
|
1224
1224
|
e.op === "subquery-in" || e.op === "subquery-not-in" ? yield {
|
|
@@ -1228,27 +1228,27 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1228
1228
|
kind: "exists",
|
|
1229
1229
|
descriptor: e.subquery
|
|
1230
1230
|
});
|
|
1231
|
-
},
|
|
1231
|
+
}, q = function* (e, t = !0) {
|
|
1232
1232
|
if ("not" in e) {
|
|
1233
|
-
yield*
|
|
1233
|
+
yield* q(e.not, !1);
|
|
1234
1234
|
return;
|
|
1235
1235
|
}
|
|
1236
1236
|
if ("and" in e) {
|
|
1237
|
-
for (let n of e.and) yield*
|
|
1237
|
+
for (let n of e.and) yield* q(n, t);
|
|
1238
1238
|
return;
|
|
1239
1239
|
}
|
|
1240
1240
|
if ("or" in e) {
|
|
1241
|
-
for (let t of e.or) yield*
|
|
1241
|
+
for (let t of e.or) yield* q(t, !1);
|
|
1242
1242
|
return;
|
|
1243
1243
|
}
|
|
1244
1244
|
e.op === "subquery-in" || e.op === "subquery-not-in" || e.op === "exists" || e.op === "not-exists" || (yield {
|
|
1245
1245
|
...e,
|
|
1246
1246
|
conjunctive: t
|
|
1247
1247
|
});
|
|
1248
|
-
},
|
|
1249
|
-
let i =
|
|
1248
|
+
}, si = class extends st.TaggedError("TableStreamError") {}, ci = 1e3, li = (e, t, n, r) => {
|
|
1249
|
+
let i = O.match(r, {
|
|
1250
1250
|
onNone: () => e.where,
|
|
1251
|
-
onSome: (n) => e.where ?
|
|
1251
|
+
onSome: (n) => e.where ? Yr(e.where, Ir(t, n)) : Ir(t, n)
|
|
1252
1252
|
});
|
|
1253
1253
|
return {
|
|
1254
1254
|
table: e.table,
|
|
@@ -1263,19 +1263,19 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1263
1263
|
...e.includeDeleted === void 0 ? {} : { includeDeleted: e.includeDeleted },
|
|
1264
1264
|
...e.crossTenant === void 0 ? {} : { crossTenant: e.crossTenant }
|
|
1265
1265
|
};
|
|
1266
|
-
},
|
|
1267
|
-
let n = t.pk ?? "id", r = t.chunkSize ??
|
|
1268
|
-
return
|
|
1269
|
-
let a =
|
|
1270
|
-
try: () => e.query(
|
|
1271
|
-
catch: (e) => new
|
|
1266
|
+
}, ui = (e, t) => {
|
|
1267
|
+
let n = t.pk ?? "id", r = t.chunkSize ?? ci;
|
|
1268
|
+
return lt.paginateChunkEffect(O.none(), (i) => {
|
|
1269
|
+
let a = ct.tryPromise({
|
|
1270
|
+
try: () => e.query(li(t, n, r, i)),
|
|
1271
|
+
catch: (e) => new si({
|
|
1272
1272
|
table: t.table,
|
|
1273
1273
|
cause: e
|
|
1274
1274
|
})
|
|
1275
1275
|
});
|
|
1276
|
-
return (t.retry ? a.pipe(
|
|
1276
|
+
return (t.retry ? a.pipe(ct.retry(t.retry)) : a).pipe(ct.map((e) => [ot.fromIterable(e), e.length === r && e.length > 0 ? O.some(O.some(e[e.length - 1][n])) : O.none()]));
|
|
1277
1277
|
});
|
|
1278
|
-
},
|
|
1278
|
+
}, di = (e) => {
|
|
1279
1279
|
let t = e.alpha ?? .5;
|
|
1280
1280
|
if (t < 0 || t > 1) throw Error(`hybridSearch: alpha must be in [0, 1], got ${t}`);
|
|
1281
1281
|
return (n) => {
|
|
@@ -1302,17 +1302,17 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1302
1302
|
}
|
|
1303
1303
|
};
|
|
1304
1304
|
};
|
|
1305
|
-
},
|
|
1305
|
+
}, fi = async (e, t) => {
|
|
1306
1306
|
let n = e.as ?? "embedding", r = t.row[e.from];
|
|
1307
1307
|
if (typeof r != "string" || r.length === 0) return {};
|
|
1308
1308
|
let i = await t.embed(r);
|
|
1309
1309
|
return { [n]: i };
|
|
1310
|
-
},
|
|
1310
|
+
}, pi = (e) => {
|
|
1311
1311
|
if (!Number.isInteger(e.dimensions) || e.dimensions <= 0) throw Error(`vectorEmbedding: dimensions must be a positive integer, got ${String(e.dimensions)}.`);
|
|
1312
|
-
let t = e.as ?? "embedding", n = (t) =>
|
|
1313
|
-
return
|
|
1312
|
+
let t = e.as ?? "embedding", n = (t) => fi(e, t);
|
|
1313
|
+
return se({
|
|
1314
1314
|
id: "voltro/vectorEmbedding",
|
|
1315
|
-
fields: { [t]:
|
|
1315
|
+
fields: { [t]: v(e.dimensions) },
|
|
1316
1316
|
...e.index === !1 ? {} : { indexes: [{
|
|
1317
1317
|
fields: [t],
|
|
1318
1318
|
kind: "hnsw",
|
|
@@ -1327,19 +1327,19 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1327
1327
|
beforeUpdate: n
|
|
1328
1328
|
}
|
|
1329
1329
|
});
|
|
1330
|
-
},
|
|
1330
|
+
}, mi = 63, hi = "br_pr", J = class extends Error {
|
|
1331
1331
|
_tag = "BranchNameInvalid";
|
|
1332
1332
|
constructor(e) {
|
|
1333
1333
|
super(e), this.name = "BranchNameInvalid";
|
|
1334
1334
|
}
|
|
1335
|
-
},
|
|
1335
|
+
}, gi = (e, t) => {
|
|
1336
1336
|
if (!Number.isInteger(t) || t < 0) throw new J(`prNumber must be a non-negative integer, got ${String(t)}`);
|
|
1337
|
-
let n =
|
|
1337
|
+
let n = hn(e);
|
|
1338
1338
|
if (n.replace(/_/g, "") === "") throw new J(`app slug '${e}' has no usable identifier characters`);
|
|
1339
|
-
let r = `${
|
|
1340
|
-
if (r.length >
|
|
1339
|
+
let r = `${hi}${t}_${n}`;
|
|
1340
|
+
if (r.length > mi) throw new J(`branch namespace '${r}' exceeds the ${mi}-byte identifier limit — use a shorter app slug`);
|
|
1341
1341
|
return r;
|
|
1342
|
-
},
|
|
1342
|
+
}, _i = (e) => e.startsWith(hi), vi = {
|
|
1343
1343
|
requested: {
|
|
1344
1344
|
provision: "provisioning",
|
|
1345
1345
|
destroy: "destroying"
|
|
@@ -1358,18 +1358,18 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1358
1358
|
fail: "failed"
|
|
1359
1359
|
},
|
|
1360
1360
|
destroyed: {}
|
|
1361
|
-
},
|
|
1361
|
+
}, yi = class extends Error {
|
|
1362
1362
|
from;
|
|
1363
1363
|
event;
|
|
1364
1364
|
_tag = "BranchTransitionInvalid";
|
|
1365
1365
|
constructor(e, t) {
|
|
1366
1366
|
super(`invalid branch transition: ${e} --${t}-->`), this.from = e, this.event = t, this.name = "BranchTransitionInvalid";
|
|
1367
1367
|
}
|
|
1368
|
-
},
|
|
1369
|
-
let n =
|
|
1370
|
-
if (n === void 0) throw new
|
|
1368
|
+
}, bi = (e, t) => {
|
|
1369
|
+
let n = vi[e][t];
|
|
1370
|
+
if (n === void 0) throw new yi(e, t);
|
|
1371
1371
|
return n;
|
|
1372
|
-
},
|
|
1372
|
+
}, xi = (e, t, n, r) => {
|
|
1373
1373
|
if (n === "copy" && (r === void 0 || r === "")) throw new J("seed 'copy' requires a parentNamespace to snapshot from");
|
|
1374
1374
|
let i = [{
|
|
1375
1375
|
kind: "create-namespace",
|
|
@@ -1390,13 +1390,13 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1390
1390
|
detail: `run boot seeds into ${e}`
|
|
1391
1391
|
});
|
|
1392
1392
|
return i;
|
|
1393
|
-
},
|
|
1394
|
-
if (!
|
|
1393
|
+
}, Si = (e) => {
|
|
1394
|
+
if (!_i(e)) throw new J(`refusing to plan teardown of '${e}' — not a branch namespace`);
|
|
1395
1395
|
return [{
|
|
1396
1396
|
kind: "drop-namespace",
|
|
1397
1397
|
detail: e
|
|
1398
1398
|
}];
|
|
1399
|
-
},
|
|
1399
|
+
}, Ci = (e) => {
|
|
1400
1400
|
if (e === void 0 || e === "") return !1;
|
|
1401
1401
|
try {
|
|
1402
1402
|
let t = new URL(e).hostname.toLowerCase();
|
|
@@ -1404,27 +1404,27 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1404
1404
|
} catch {
|
|
1405
1405
|
return /\bneon\.(tech|build)\b/i.test(e);
|
|
1406
1406
|
}
|
|
1407
|
-
},
|
|
1407
|
+
}, wi = (e) => e.prefer === void 0 ? e.seed === "copy" && Ci(e.dbUrl) ? "neon-cow" : "namespace" : e.prefer, Ti = (e, t = {}) => [{
|
|
1408
1408
|
kind: "neon-branch-create",
|
|
1409
1409
|
detail: `${t.parentBranch ?? "main"} → ${e} (copy-on-write)`
|
|
1410
|
-
}],
|
|
1411
|
-
if (!
|
|
1410
|
+
}], Ei = (e) => {
|
|
1411
|
+
if (!_i(e)) throw new J(`refusing to plan teardown of '${e}' — not a branch namespace`);
|
|
1412
1412
|
return [{
|
|
1413
1413
|
kind: "neon-branch-delete",
|
|
1414
1414
|
detail: e
|
|
1415
1415
|
}];
|
|
1416
|
-
},
|
|
1416
|
+
}, Di = (e) => e.mechanism === "neon-cow" ? Ti(e.branchId, e.neonParentBranch === void 0 ? {} : { parentBranch: e.neonParentBranch }) : xi(e.branchId, e.tableNames, e.seed, e.parentNamespace), Oi = (e, t) => e === "neon-cow" ? Ei(t) : Si(t), ki = (e, t, n) => {
|
|
1417
1417
|
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);
|
|
1418
1418
|
return {
|
|
1419
1419
|
evict: i,
|
|
1420
1420
|
rejectNew: r.filter((e) => !a.has(e.namespace)).length >= t.maxBranches
|
|
1421
1421
|
};
|
|
1422
|
-
},
|
|
1423
|
-
let n =
|
|
1422
|
+
}, Ai = async (e, t) => {
|
|
1423
|
+
let n = gi(e.appSlug, e.prNumber), r = wi({
|
|
1424
1424
|
seed: e.seed,
|
|
1425
1425
|
...e.dbUrl === void 0 ? {} : { dbUrl: e.dbUrl },
|
|
1426
1426
|
...e.prefer === void 0 ? {} : { prefer: e.prefer }
|
|
1427
|
-
}), i =
|
|
1427
|
+
}), i = Di({
|
|
1428
1428
|
mechanism: r,
|
|
1429
1429
|
branchId: n,
|
|
1430
1430
|
tableNames: e.tableNames,
|
|
@@ -1449,10 +1449,10 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1449
1449
|
mechanism: r,
|
|
1450
1450
|
steps: i
|
|
1451
1451
|
};
|
|
1452
|
-
},
|
|
1453
|
-
let r =
|
|
1452
|
+
}, ji = async (e, t, n) => {
|
|
1453
|
+
let r = Oi(t, e);
|
|
1454
1454
|
return t === "neon-cow" ? await n.neonBranchDelete(e) : await n.dropNamespace(e), r;
|
|
1455
|
-
},
|
|
1455
|
+
}, Mi = (e, t, n) => ki(e, t, n), Y = (e) => `"${e.replace(/"/g, "\"\"")}"`, Ni = (e) => {
|
|
1456
1456
|
let t = () => {
|
|
1457
1457
|
throw Error("namespace branch executor: Neon ops require a neon-cow executor (use a Neon connection for copy-on-write branches)");
|
|
1458
1458
|
};
|
|
@@ -1464,18 +1464,18 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1464
1464
|
neonBranchCreate: t,
|
|
1465
1465
|
neonBranchDelete: t
|
|
1466
1466
|
};
|
|
1467
|
-
},
|
|
1467
|
+
}, Pi = class extends Error {
|
|
1468
1468
|
_tag = "TenantResidencyUnresolved";
|
|
1469
1469
|
constructor(e) {
|
|
1470
1470
|
super(e), this.name = "TenantResidencyUnresolved";
|
|
1471
1471
|
}
|
|
1472
|
-
},
|
|
1472
|
+
}, Fi = class extends Error {
|
|
1473
1473
|
region;
|
|
1474
1474
|
_tag = "TenantRegionUnavailable";
|
|
1475
1475
|
constructor(e, t) {
|
|
1476
1476
|
super(t), this.region = e, this.name = "TenantRegionUnavailable";
|
|
1477
1477
|
}
|
|
1478
|
-
},
|
|
1478
|
+
}, Ii, Li = (e) => {
|
|
1479
1479
|
if (e.homes === void 0) throw Error("setResidencyConfig: `homes` is required");
|
|
1480
1480
|
if (e.servableRegions === void 0 || e.servableRegions.length === 0) throw Error("setResidencyConfig: `servableRegions` must be non-empty (which regions this deployment serves)");
|
|
1481
1481
|
let t = /* @__PURE__ */ new Map();
|
|
@@ -1484,32 +1484,32 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1484
1484
|
if (e !== void 0 && e !== n.region) throw Error(`residency: tenant '${n.tenantId}' is mapped to two regions ('${e}' and '${n.region}')`);
|
|
1485
1485
|
t.set(n.tenantId, n.region);
|
|
1486
1486
|
}
|
|
1487
|
-
return
|
|
1488
|
-
},
|
|
1489
|
-
|
|
1490
|
-
},
|
|
1491
|
-
if (e == null || e === "") throw new
|
|
1487
|
+
return Ii = e, e;
|
|
1488
|
+
}, Ri = () => Ii, zi = () => {
|
|
1489
|
+
Ii = void 0;
|
|
1490
|
+
}, Bi = (e, t) => {
|
|
1491
|
+
if (e == null || e === "") throw new Pi("residency is on but the request has no resolvable tenant — refusing to bind a store");
|
|
1492
1492
|
let n = t.homes.find((t) => t.tenantId === e);
|
|
1493
|
-
if (n === void 0) throw new
|
|
1493
|
+
if (n === void 0) throw new Pi(`no residency home is mapped for tenant '${e}' — refusing to fall back to a default store (would be a residency violation)`);
|
|
1494
1494
|
return n;
|
|
1495
|
-
},
|
|
1496
|
-
let n =
|
|
1495
|
+
}, Vi = (e, t) => t.servableRegions.includes(e), Hi = (e, t) => {
|
|
1496
|
+
let n = Bi(e.tenantId, t), r = gn(n.tenantId);
|
|
1497
1497
|
return {
|
|
1498
1498
|
region: n.region,
|
|
1499
1499
|
namespace: r,
|
|
1500
1500
|
...n.connectionKey === void 0 ? {} : { connectionKey: n.connectionKey }
|
|
1501
1501
|
};
|
|
1502
|
-
},
|
|
1503
|
-
let r =
|
|
1504
|
-
if (!
|
|
1502
|
+
}, Ui = (e, t, n) => {
|
|
1503
|
+
let r = Hi(e, t);
|
|
1504
|
+
if (!Vi(r.region, t)) throw new Fi(r.region, `tenant homed in region '${r.region}', which this deployment does not serve — route to the home region`);
|
|
1505
1505
|
let i = n.get(r.region);
|
|
1506
|
-
if (i === void 0) throw new
|
|
1506
|
+
if (i === void 0) throw new Fi(r.region, `no store handle for home region '${r.region}' (declared servable but not wired) — failing closed`);
|
|
1507
1507
|
return {
|
|
1508
1508
|
store: i,
|
|
1509
1509
|
placement: r
|
|
1510
1510
|
};
|
|
1511
|
-
},
|
|
1512
|
-
let { store: i, placement: a } =
|
|
1511
|
+
}, Wi = async (e, t, n, r) => {
|
|
1512
|
+
let { store: i, placement: a } = Ui(e, t, n);
|
|
1513
1513
|
return await r(i, a), a;
|
|
1514
1514
|
}, X = (e) => {
|
|
1515
1515
|
if (typeof e == "string") return e;
|
|
@@ -1518,21 +1518,21 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1518
1518
|
return `(json:${t}->${n.join(".")}${r ? "::num" : ""})`;
|
|
1519
1519
|
}
|
|
1520
1520
|
return `(${e.expr})`;
|
|
1521
|
-
}, Z = (e) => e.map(X),
|
|
1521
|
+
}, Z = (e) => e.map(X), Gi = (e, t) => {
|
|
1522
1522
|
if (e.length !== t.length) return !1;
|
|
1523
1523
|
for (let n = 0; n < e.length; n++) if (X(e[n]) !== X(t[n])) return !1;
|
|
1524
1524
|
return !0;
|
|
1525
|
-
},
|
|
1525
|
+
}, Ki = (e, t) => {
|
|
1526
1526
|
if (e.length >= t.length) return !1;
|
|
1527
1527
|
for (let n = 0; n < e.length; n++) if (X(e[n]) !== X(t[n])) return !1;
|
|
1528
1528
|
return !0;
|
|
1529
|
-
},
|
|
1529
|
+
}, qi = (e) => {
|
|
1530
1530
|
let t = [], n = e.appliedIndexes, r = e.tableName;
|
|
1531
1531
|
for (let e = 0; e < n.length; e++) {
|
|
1532
1532
|
let i = n[e];
|
|
1533
1533
|
for (let a = e + 1; a < n.length; a++) {
|
|
1534
1534
|
let e = n[a];
|
|
1535
|
-
if (
|
|
1535
|
+
if (Gi(i.fields, e.fields)) {
|
|
1536
1536
|
let [n, a] = i.name < e.name ? [i, e] : [e, i];
|
|
1537
1537
|
t.push({
|
|
1538
1538
|
kind: "duplicate-fields",
|
|
@@ -1543,13 +1543,13 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1543
1543
|
});
|
|
1544
1544
|
continue;
|
|
1545
1545
|
}
|
|
1546
|
-
|
|
1546
|
+
Ki(i.fields, e.fields) ? t.push({
|
|
1547
1547
|
kind: "redundant-prefix",
|
|
1548
1548
|
table: r,
|
|
1549
1549
|
redundant: i,
|
|
1550
1550
|
coveredBy: e,
|
|
1551
1551
|
message: `'${r}' index '${i.name}' on [${Z(i.fields).join(", ")}] is a leading prefix of '${e.name}' on [${Z(e.fields).join(", ")}]. Every B-tree dialect we support (Postgres / MySQL / MariaDB / MSSQL / SQLite) can serve a [${Z(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).`
|
|
1552
|
-
}) :
|
|
1552
|
+
}) : Ki(e.fields, i.fields) && t.push({
|
|
1553
1553
|
kind: "redundant-prefix",
|
|
1554
1554
|
table: r,
|
|
1555
1555
|
redundant: e,
|
|
@@ -1559,23 +1559,23 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1559
1559
|
}
|
|
1560
1560
|
}
|
|
1561
1561
|
return t;
|
|
1562
|
-
},
|
|
1562
|
+
}, Ji = (e) => {
|
|
1563
1563
|
let t = [];
|
|
1564
|
-
for (let n of e) t.push(...
|
|
1564
|
+
for (let n of e) t.push(...qi(n));
|
|
1565
1565
|
return t;
|
|
1566
|
-
},
|
|
1567
|
-
let n = t.color ?? !0, r = t.indent ?? " ", i = (e) => Q(n,
|
|
1566
|
+
}, Yi = "\x1B[", Xi = `${Yi}38;2;245;158;11m`, Zi = `${Yi}38;2;16;185;129m`, Qi = (e, t) => `${e}${t}${A.reset}`, Q = (e, t, n) => e ? typeof t == "function" ? t(n) : Qi(t, n) : n, $i = (e, t = {}) => {
|
|
1567
|
+
let n = t.color ?? !0, r = t.indent ?? " ", i = (e) => Q(n, A.dim, e.padEnd(11)), a = (e) => Q(n, (e) => A.bold(A.brand(e)), e), o = (e) => Q(n, A.brightRed24, e), s = (e) => Q(n, Zi, e), c = (e) => Q(n, Xi, e), l = (e) => Q(n, A.dim, e), u = `${c("index audit")} ${l("·")} ${Q(n, A.bold, e.kind)}`, d = e.redundant.fields.length, f = Z(e.coveredBy.fields.slice(d)), p = (e, t) => {
|
|
1568
1568
|
let n = e.slice(0, t), r = e.slice(t), i = [];
|
|
1569
1569
|
return n.length > 0 && i.push(s(`[${n.join(", ")}]`)), r.length > 0 && i.push(c(`+ [${r.join(", ")}]`)), i.join(" ");
|
|
1570
1570
|
}, m = [];
|
|
1571
|
-
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(Z(e.redundant.fields), d)}`), m.push(""), m.push(`${i("covered by")}${s(e.coveredBy.name)}`), m.push(`${i("")}${p(Z(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 ${Q(n,
|
|
1572
|
-
},
|
|
1571
|
+
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(Z(e.redundant.fields), d)}`), m.push(""), m.push(`${i("covered by")}${s(e.coveredBy.name)}`), m.push(`${i("")}${p(Z(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 ${Q(n, A.bold, "both")} B-trees. Pure write overhead, zero read benefit.`), m.push(""), m.push(`${i("fix")}Drop ${o(e.redundant.name)}`), m.push(`${i("")}${l("Keep only if profiling shows the smaller index gives a")}`), m.push(`${i("")}${l("measurable cache-locality boost on a write-heavy hot path.")}`), m.push(`${i("")}${l("Silence with VOLTRO_INDEX_AUDIT=off if intentional.")}`), m.map((e) => `${r}${e}`).join("\n");
|
|
1572
|
+
}, ea = (e, t) => ({
|
|
1573
1573
|
name: e,
|
|
1574
1574
|
body: t
|
|
1575
|
-
}),
|
|
1575
|
+
}), ta = (e) => {
|
|
1576
1576
|
if (e.lifecycle === "cron" && !e.cron) throw Error(`seed "${e.id}": lifecycle 'cron' requires a 'cron' field`);
|
|
1577
1577
|
if (e.lifecycle === "onSchemaChange" && (!e.watchedTables || e.watchedTables.length === 0)) throw Error(`seed "${e.id}": lifecycle 'onSchemaChange' requires at least one entry in 'watchedTables'`);
|
|
1578
|
-
let t = e.steps({ step:
|
|
1578
|
+
let t = e.steps({ step: ea });
|
|
1579
1579
|
if (t.length === 0) throw Error(`seed "${e.id}": at least one step is required`);
|
|
1580
1580
|
return {
|
|
1581
1581
|
__seed: !0,
|
|
@@ -1587,13 +1587,13 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1587
1587
|
...e.fingerprint === void 0 ? {} : { fingerprint: e.fingerprint },
|
|
1588
1588
|
steps: t
|
|
1589
1589
|
};
|
|
1590
|
-
},
|
|
1590
|
+
}, na = (e) => typeof e == "object" && !!e && "__seed" in e && e.__seed === !0, ra = (e, { apply: t, undo: n }) => ({
|
|
1591
1591
|
name: e,
|
|
1592
1592
|
apply: t,
|
|
1593
1593
|
undo: n
|
|
1594
|
-
}),
|
|
1594
|
+
}), ia = (e) => {
|
|
1595
1595
|
if (!/^\d{14}_/.test(e.id)) throw Error(`migration "${e.id}": id must start with a 14-digit timestamp followed by "_" (convention: <YYYYMMDDHHMMSS>_<slug>)`);
|
|
1596
|
-
let t = e.steps({ step:
|
|
1596
|
+
let t = e.steps({ step: ra });
|
|
1597
1597
|
if (t.length === 0) throw Error(`migration "${e.id}": at least one step is required`);
|
|
1598
1598
|
return {
|
|
1599
1599
|
__migration: !0,
|
|
@@ -1601,80 +1601,80 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1601
1601
|
name: e.name,
|
|
1602
1602
|
steps: t
|
|
1603
1603
|
};
|
|
1604
|
-
},
|
|
1605
|
-
id:
|
|
1606
|
-
name:
|
|
1607
|
-
hash:
|
|
1608
|
-
status:
|
|
1609
|
-
appliedAt:
|
|
1610
|
-
durationMs:
|
|
1611
|
-
errorMessage:
|
|
1612
|
-
errorStack:
|
|
1613
|
-
workflowRunId:
|
|
1614
|
-
createdAt:
|
|
1615
|
-
updatedAt:
|
|
1616
|
-
}).index(["status"]).reactive(),
|
|
1617
|
-
id:
|
|
1618
|
-
name:
|
|
1619
|
-
lifecycle:
|
|
1620
|
-
fingerprint:
|
|
1621
|
-
cronSchedule:
|
|
1604
|
+
}, aa = (e) => typeof e == "object" && !!e && "__migration" in e && e.__migration === !0, oa = f("_voltro_migrations", {
|
|
1605
|
+
id: w({ prefix: "mig" }),
|
|
1606
|
+
name: n(),
|
|
1607
|
+
hash: n(),
|
|
1608
|
+
status: n(),
|
|
1609
|
+
appliedAt: E().nullable(),
|
|
1610
|
+
durationMs: D().nullable(),
|
|
1611
|
+
errorMessage: n().nullable(),
|
|
1612
|
+
errorStack: n().nullable(),
|
|
1613
|
+
workflowRunId: n().nullable(),
|
|
1614
|
+
createdAt: E().default("now"),
|
|
1615
|
+
updatedAt: E().default("now").onUpdate("now")
|
|
1616
|
+
}).index(["status"]).reactive(), sa = f("_voltro_seeds", {
|
|
1617
|
+
id: w({ prefix: "seed" }),
|
|
1618
|
+
name: n(),
|
|
1619
|
+
lifecycle: n(),
|
|
1620
|
+
fingerprint: n(),
|
|
1621
|
+
cronSchedule: n().nullable(),
|
|
1622
1622
|
watchedTables: a().nullable(),
|
|
1623
|
-
nextRunAt:
|
|
1624
|
-
lastRunStatus:
|
|
1625
|
-
lastRunAt:
|
|
1626
|
-
lastRunDurationMs:
|
|
1627
|
-
lastRunRowsTouched:
|
|
1628
|
-
lastError:
|
|
1629
|
-
workflowRunId:
|
|
1630
|
-
createdAt:
|
|
1631
|
-
updatedAt:
|
|
1632
|
-
}).index(["lifecycle"]).index(["nextRunAt"]).reactive(),
|
|
1633
|
-
id:
|
|
1634
|
-
fingerprint:
|
|
1623
|
+
nextRunAt: E().nullable(),
|
|
1624
|
+
lastRunStatus: n().nullable(),
|
|
1625
|
+
lastRunAt: E().nullable(),
|
|
1626
|
+
lastRunDurationMs: D().nullable(),
|
|
1627
|
+
lastRunRowsTouched: D().nullable(),
|
|
1628
|
+
lastError: n().nullable(),
|
|
1629
|
+
workflowRunId: n().nullable(),
|
|
1630
|
+
createdAt: E().default("now"),
|
|
1631
|
+
updatedAt: E().default("now").onUpdate("now")
|
|
1632
|
+
}).index(["lifecycle"]).index(["nextRunAt"]).reactive(), ca = f("_voltro_migration_plans", {
|
|
1633
|
+
id: w({ prefix: "plan" }),
|
|
1634
|
+
fingerprint: n(),
|
|
1635
1635
|
operations: a(),
|
|
1636
1636
|
rollbackPlan: a().nullable(),
|
|
1637
|
-
appliedBy:
|
|
1638
|
-
environment:
|
|
1639
|
-
source:
|
|
1640
|
-
onlineStrategy:
|
|
1641
|
-
durationMs:
|
|
1642
|
-
notes:
|
|
1643
|
-
squashedAt:
|
|
1644
|
-
appliedAt:
|
|
1645
|
-
createdAt:
|
|
1646
|
-
updatedAt:
|
|
1647
|
-
}).index(["fingerprint"]).index(["environment"]).reactive(),
|
|
1648
|
-
id:
|
|
1649
|
-
scope:
|
|
1650
|
-
key:
|
|
1651
|
-
status:
|
|
1637
|
+
appliedBy: n(),
|
|
1638
|
+
environment: n(),
|
|
1639
|
+
source: n(),
|
|
1640
|
+
onlineStrategy: n().nullable(),
|
|
1641
|
+
durationMs: D(),
|
|
1642
|
+
notes: n().nullable(),
|
|
1643
|
+
squashedAt: E().nullable(),
|
|
1644
|
+
appliedAt: E().default("now"),
|
|
1645
|
+
createdAt: E().default("now"),
|
|
1646
|
+
updatedAt: E().default("now").onUpdate("now")
|
|
1647
|
+
}).index(["fingerprint"]).index(["environment"]).reactive(), la = f("_voltro_idempotency", {
|
|
1648
|
+
id: w({ prefix: "idem" }),
|
|
1649
|
+
scope: n(),
|
|
1650
|
+
key: n(),
|
|
1651
|
+
status: n(),
|
|
1652
1652
|
response: a().nullable(),
|
|
1653
|
-
createdAt:
|
|
1654
|
-
}).unique(["scope", "key"]).index(["createdAt"]).reactive(),
|
|
1655
|
-
id:
|
|
1656
|
-
key:
|
|
1657
|
-
value:
|
|
1658
|
-
expiresAt:
|
|
1659
|
-
createdAt:
|
|
1660
|
-
updatedAt:
|
|
1661
|
-
}).index(["expiresAt"]).reactive(),
|
|
1662
|
-
id:
|
|
1663
|
-
tenantId:
|
|
1664
|
-
name:
|
|
1665
|
-
hashedKey:
|
|
1666
|
-
keyPrefix:
|
|
1653
|
+
createdAt: E().default("now")
|
|
1654
|
+
}).unique(["scope", "key"]).index(["createdAt"]).reactive(), ua = f("_voltro_kv", {
|
|
1655
|
+
id: w({ prefix: "kv" }),
|
|
1656
|
+
key: n().unique(),
|
|
1657
|
+
value: n().nullable(),
|
|
1658
|
+
expiresAt: E().nullable(),
|
|
1659
|
+
createdAt: E().default("now"),
|
|
1660
|
+
updatedAt: E().default("now").onUpdate("now")
|
|
1661
|
+
}).index(["expiresAt"]).reactive(), da = f("_voltro_api_keys", {
|
|
1662
|
+
id: w({ prefix: "apikey" }),
|
|
1663
|
+
tenantId: n().nullable(),
|
|
1664
|
+
name: n(),
|
|
1665
|
+
hashedKey: n().unique(),
|
|
1666
|
+
keyPrefix: n(),
|
|
1667
1667
|
scopes: a().nullable(),
|
|
1668
|
-
lastUsedAt:
|
|
1669
|
-
expiresAt:
|
|
1670
|
-
revokedAt:
|
|
1671
|
-
createdBy:
|
|
1672
|
-
createdAt:
|
|
1673
|
-
}).index("byTenant", ["tenantId"]).reactive(),
|
|
1674
|
-
aa,
|
|
1668
|
+
lastUsedAt: E().nullable(),
|
|
1669
|
+
expiresAt: E().nullable(),
|
|
1670
|
+
revokedAt: E().nullable(),
|
|
1671
|
+
createdBy: n().nullable(),
|
|
1672
|
+
createdAt: E().default("now")
|
|
1673
|
+
}).index("byTenant", ["tenantId"]).reactive(), fa = [
|
|
1675
1674
|
oa,
|
|
1676
|
-
sa
|
|
1677
|
-
|
|
1675
|
+
sa,
|
|
1676
|
+
ca
|
|
1677
|
+
], $ = "id", pa = (e, t) => {
|
|
1678
1678
|
let n = u(e);
|
|
1679
1679
|
if (n === void 0) return t;
|
|
1680
1680
|
let r = n.fields[$]?.idScheme;
|
|
@@ -1689,53 +1689,53 @@ var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1689
1689
|
...t,
|
|
1690
1690
|
[$]: i
|
|
1691
1691
|
};
|
|
1692
|
-
},
|
|
1692
|
+
}, ma = (e, t) => t.map((t) => pa(e, t)), ha = (e, t) => {
|
|
1693
1693
|
let n = [], r = t;
|
|
1694
1694
|
for (let [t, i] of Object.entries(e.fields)) {
|
|
1695
1695
|
let e = i;
|
|
1696
1696
|
e.nullable || e.hasDefault || e.idScheme !== void 0 || e.generatedAs !== void 0 || (r[t] === void 0 || r[t] === null) && n.push(t);
|
|
1697
1697
|
}
|
|
1698
1698
|
return n;
|
|
1699
|
-
},
|
|
1699
|
+
}, ga = (e, t) => {
|
|
1700
1700
|
let n = t;
|
|
1701
1701
|
return e.filter((e) => n[e] === void 0 || n[e] === null);
|
|
1702
|
-
},
|
|
1702
|
+
}, _a = (e, t, n) => e.insert(t.tableName, n), va = (e, t, n, r) => e.upsert(t.tableName, n, {
|
|
1703
1703
|
conflictColumns: r.conflictColumns,
|
|
1704
1704
|
...r.update === void 0 ? {} : { update: r.update }
|
|
1705
|
-
}),
|
|
1705
|
+
}), ya = 512, ba = (e) => {
|
|
1706
1706
|
e.setMaxListeners(512);
|
|
1707
|
-
},
|
|
1707
|
+
}, xa = (e, t, n) => ({
|
|
1708
1708
|
_tag: "PrimaryKeyConflictError",
|
|
1709
1709
|
table: e,
|
|
1710
1710
|
key: t,
|
|
1711
1711
|
cause: n
|
|
1712
|
-
}),
|
|
1712
|
+
}), Sa = (e) => typeof e == "object" && !!e && e._tag === "PrimaryKeyConflictError", Ca = /* @__PURE__ */ new Map(), wa = (e) => {
|
|
1713
1713
|
if (!e.table || !e.timeColumn) throw Error("registerRetention: table + timeColumn are required");
|
|
1714
1714
|
if (!Number.isFinite(e.ttlMs) || e.ttlMs <= 0) throw Error(`registerRetention(${e.table}): ttlMs must be a positive number`);
|
|
1715
|
-
|
|
1716
|
-
},
|
|
1715
|
+
Ca.set(e.table, e);
|
|
1716
|
+
}, Ta = () => [...Ca.values()], Ea = () => Ca.clear(), Da = async (e, t, n, r = 2e4) => {
|
|
1717
1717
|
let i = new Date(t - e.ttlMs), a = 0;
|
|
1718
1718
|
for (;;) {
|
|
1719
1719
|
let t = await n(e.table, e.timeColumn, i, r, e.where);
|
|
1720
1720
|
if (a += t, t < r) break;
|
|
1721
1721
|
}
|
|
1722
1722
|
return a;
|
|
1723
|
-
},
|
|
1723
|
+
}, Oa = (e, t) => {
|
|
1724
1724
|
let n = Number(e ?? String(t));
|
|
1725
1725
|
return (Number.isFinite(n) && n > 0 ? n : t) * 36e5;
|
|
1726
|
-
},
|
|
1727
|
-
id:
|
|
1728
|
-
replicaId:
|
|
1729
|
-
streamName:
|
|
1730
|
-
binlogFile:
|
|
1731
|
-
binlogPosition:
|
|
1732
|
-
updatedAt:
|
|
1733
|
-
}).index(["replicaId"]),
|
|
1734
|
-
id:
|
|
1735
|
-
replicaId:
|
|
1736
|
-
streamName:
|
|
1737
|
-
ctVersion:
|
|
1738
|
-
updatedAt:
|
|
1739
|
-
}).index(["replicaId"]),
|
|
1726
|
+
}, ka = "_voltro_cdc_offsets", Aa = f(ka, {
|
|
1727
|
+
id: w({ prefix: "cdcoff" }),
|
|
1728
|
+
replicaId: n(),
|
|
1729
|
+
streamName: n(),
|
|
1730
|
+
binlogFile: n(),
|
|
1731
|
+
binlogPosition: n(),
|
|
1732
|
+
updatedAt: E()
|
|
1733
|
+
}).index(["replicaId"]), ja = f(ka, {
|
|
1734
|
+
id: w({ prefix: "cdcoff" }),
|
|
1735
|
+
replicaId: n(),
|
|
1736
|
+
streamName: n(),
|
|
1737
|
+
ctVersion: n(),
|
|
1738
|
+
updatedAt: E()
|
|
1739
|
+
}).index(["replicaId"]), Ma = "postgres";
|
|
1740
1740
|
//#endregion
|
|
1741
|
-
export { r as AUTO_FILLED_COLUMNS, J as BranchNameInvalid,
|
|
1741
|
+
export { r as AUTO_FILLED_COLUMNS, J as BranchNameInvalid, yi as BranchTransitionInvalid, ka as CDC_OFFSETS_TABLE, ya as CHANGE_LISTENER_CEILING, Me as ColumnBuilder, mt as ENCRYPTED_PREFIX, Ma as ENGINE, Qt as EagerCardinalityError, Ke as FILE_MIGRATION_PATTERN, ht as FieldDecryptionError, ee as MAX_IDENTIFIER_LENGTH, si as TableStreamError, fn as TenantNamespaceInvalid, dn as TenantNamespaceUnresolved, Fi as TenantRegionUnavailable, Pi as TenantResidencyUnresolved, e as WARN_IDENTIFIER_LENGTH, da as _voltroApiKeysTable, Aa as _voltroCdcOffsetsTable, la as _voltroIdempotencyTable, ua as _voltroKvTable, ca as _voltroMigrationPlansTable, oa as _voltroMigrationsTable, ja as _voltroMssqlCdcOffsetsTable, sa as _voltroSeedsTable, Nr as actorsTable, Mi as admitBranch, me as allEnumRenames, Vt as allRegisteredRelations, _ as allRegisteredTables, Yr as and, Ye as array, Ur as arrayContains, Gr as arrayHas, Wr as arrayOverlaps, en as attachEagerLoads, Ji as auditAllTableIndexes, qi as auditTableIndexes, je as avg, Je as avgOver, ye as bigint, Ui as bindResidentStore, Se as boolean, gi as branchNamespaceName, Be as bytes, Re as clearEnumRenames, Ut as clearRelationsRegistry, zi as clearResidencyConfig, Ea as clearRetentions, y as clearTableRegistry, oi as collectSubqueries, ve as column, xt as columnSchema, An as compileEagerJson, I as compilePredicate, vn as compileRawFragment, L as compileSelect, fi as computeEmbedding, Hr as contains, xe as count, ze as countDistinct, Ne as databaseHandle, Pe as date, Ee as dbEnum, we as decimal, Ge as declareEnumRename, Yt as decodeRowsFromSchema, bt as decryptFieldsOnRead, ia as defineMigration, se as defineMixin, ta as defineSeed, Te as denseRank, Ve as deriveTypeIdPrefix, pt as deserializeArraysOnRead, be as drainIdentifierWarnings, fe as dropped, Zt as encodeRowForSchema, yt as encryptFieldsForWrite, vt as encryptedColumnsOf, ki as enforceBranchLimits, S as ensureTableRegistered, Pr as eq, yn as escapeLike, ai as evaluatePredicate, Ce as except, ni as exists, $i as formatIndexAuditIssue, fa as frameworkTables, m as generateId, ce as generateSnowflake, Ze as geography, nt as geometry, _e as getEnumRenames, Bt as getRelation, zt as getRelations, Ri as getResidencyConfig, u as getTable, Ir as gt, Lr as gte, un as hasEagerLoads, di as hybridSearch, w as id, Br as inSet, ei as inSubquery, M as inferForeignKey, _a as insertRow, D as integer, de as intersect, ne as interval, _i as isBranchNamespace, _t as isEncrypted, gt as isFieldDecryptionError, Fe as isFileMigration, aa as isMigrationDefinition, Ci as isNeonConnection, qr as isNotNull, Kr as isNull, Sa as isPrimaryKeyConflictError, Vi as isRegionServable, Ot as isRelationsSpec, na as isSeedDefinition, C as isSqliteFamily, pe as isView, a as json, Qr as jsonField, oe as jsonIndex, Xe as lag, tt as lead, Ta as listRetentions, Rr as lt, zr as lte, Ni as makeNamespaceBranchExecutor, At as many, jt as manyToMany, $e as materializeFields, he as max, He as migration, et as min, ga as missingConflictColumns, ha as missingRequiredColumns, d as mixin, Fr as neq, bi as nextBranchState, Zr as not, ri as notExists, Vr as notInSet, ti as notInSubquery, ie as numeric, kt as one, $t as oneCardinalityMessage, Xr as or, te as paginateBy, i as paginateById, Di as planBranch, xi as planBranchProvision, Si as planBranchTeardown, Oi as planBranchTeardownFor, Ti as planNeonBranchProvision, Ei as planNeonBranchTeardown, xa as primaryKeyConflictError, Ai as provisionBranch, Wi as provisionResidentTenant, _n as qualifyTable, Qe as queryFor, Le as queryForView, rt as quoteIdent, ba as raiseChangeListenerCeiling, re as rank, l as raw, s as real, x as reference, kr as registerCoreTables, Rt as registerDiscoveredRelations, Lt as registerRelations, wa as registerRetention, p as registerTable, Dt as relations, jr as requireActors, g as requireTable, Mr as requireTenants, ue as resetSnowflake, Hi as residentPlacement, wi as resolveBranchMechanism, c as resolveFullTextIndex, le as resolveIdScheme, h as resolveMixinGraph, Bi as resolveTenantHome, gn as resolveTenantNamespace, Oa as retentionTtlMsFromEnv, o as rowNumber, St as rowSchema, hn as sanitizeIdentifierFragment, ft as serializeArraysForWrite, Ae as serverOnlyColumns, Li as setResidencyConfig, Jr as spatialPredicate, pa as stampGeneratedId, ma as stampGeneratedIds, ui as streamTable, b as sum, ke as sumOver, Da as sweepRetention, f as table, ji as teardownBranch, n as text, E as timestamp, it as timestampMs, at as timestampMsOrNull, t as union, Oe as unionAll, va as upsertRow, qe as validateColumnName, Ie as validateIndexName, Ht as validateRegisteredRelations, Pt as validateRelationConfig, Ue as validateTableName, De as validateTypeIdPrefix, v as vector, ae as vectorDistanceToOpclass, pi as vectorEmbedding, We as view, ge as viewSql, q as walkLeaves };
|