@voltro/database 0.11.1 → 0.11.3
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 +95 -0
- package/dist/{fileBased-Cc-F1oFv.js → fileBased-BrYB2u6E.js} +88 -79
- package/dist/index.d.ts +9 -3
- package/dist/index.js +508 -508
- package/dist/sql.js +100 -100
- 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 ee, N as te, O as _, Ot 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 ee, N as te, O as _, Ot as ne, P as v, Q as y, R as re, S as b, St as ie, T as ae, Tt as oe, U as se, V as ce, W as le, X as ue, Y as de, Z as fe, _ as pe, _t as me, a as he, at as ge, b as _e, bt as x, c as ve, ct as ye, d as be, dt as xe, et as Se, f as Ce, ft as we, g as Te, gt as Ee, h as De, ht as Oe, i as S, it as ke, j as Ae, jt as je, k as Me, kt as C, l as Ne, lt as Pe, m as Fe, mt as Ie, n as Le, nt as Re, o as ze, ot as Be, p as Ve, pt as He, q as Ue, r as We, rt as Ge, s as Ke, st as qe, t as Je, tt as Ye, u as Xe, ut as Ze, v as Qe, vt as $e, w as et, wt as tt, x as nt, xt as w, y as rt, yt as it, z as at } from "./fileBased-BrYB2u6E.js";
|
|
2
|
+
import { timestampMs as ot, timestampMsOrNull as st } from "./wire.js";
|
|
3
|
+
import { Chunk as ct, Data as lt, Effect as ut, Option as T, Schema as E, Stream as dt } from "effect";
|
|
4
|
+
import { ansi as D } from "@voltro/logger";
|
|
5
5
|
//#region src/arrayCodec.ts
|
|
6
|
-
var
|
|
6
|
+
var ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqlite", pt = (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
|
+
}, mt = (e, t, n) => {
|
|
11
|
+
if (!ft(n) || !t) return e;
|
|
12
|
+
let r = pt(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 ct = (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
|
+
}, ht = (e, t, n) => {
|
|
21
|
+
if (!ft(n) || !t) return e;
|
|
22
|
+
let r = pt(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 ct = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
31
31
|
}
|
|
32
32
|
return t ?? e;
|
|
33
33
|
});
|
|
34
|
-
},
|
|
34
|
+
}, gt = "enc:v1:", _t = class extends Error {
|
|
35
35
|
_tag = "FieldDecryptionError";
|
|
36
36
|
table;
|
|
37
37
|
column;
|
|
@@ -39,33 +39,33 @@ var ct = (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
|
+
}, vt = (e) => typeof e == "object" && !!e && e._tag === "FieldDecryptionError", yt = (e) => typeof e == "string" && e.startsWith("enc:v1:"), bt = (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
|
+
}, xt = (e, t, n) => {
|
|
47
47
|
if (!t) return e;
|
|
48
|
-
let r =
|
|
48
|
+
let r = bt(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 || yt(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
|
+
}, St = (e, t, n, r) => {
|
|
60
60
|
if (!t) return e;
|
|
61
|
-
let i =
|
|
61
|
+
let i = bt(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 (yt(i)) {
|
|
69
69
|
t ??= { ...e };
|
|
70
70
|
try {
|
|
71
71
|
t[s] = JSON.parse(n.decrypt(i));
|
|
@@ -79,7 +79,7 @@ var ct = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
79
79
|
});
|
|
80
80
|
continue;
|
|
81
81
|
}
|
|
82
|
-
throw new
|
|
82
|
+
throw new _t({
|
|
83
83
|
table: o,
|
|
84
84
|
column: s,
|
|
85
85
|
reason: n
|
|
@@ -89,58 +89,58 @@ var ct = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
89
89
|
}
|
|
90
90
|
return t ?? e;
|
|
91
91
|
});
|
|
92
|
-
},
|
|
92
|
+
}, Ct = (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 E.String;
|
|
99
99
|
case "integer":
|
|
100
100
|
case "real":
|
|
101
|
-
case "decimal": return
|
|
102
|
-
case "boolean": return
|
|
101
|
+
case "decimal": return E.Number;
|
|
102
|
+
case "boolean": return E.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 ot;
|
|
105
|
+
case "bigint": return E.BigInt;
|
|
106
|
+
case "bytes": return E.Uint8ArrayFromSelf;
|
|
107
|
+
case "array": return E.Array(E.Unknown);
|
|
108
|
+
case "interval": return E.String;
|
|
109
|
+
default: return E.Unknown;
|
|
110
110
|
}
|
|
111
111
|
})();
|
|
112
|
-
return e.nullable === !0 ?
|
|
113
|
-
},
|
|
112
|
+
return e.nullable === !0 ? E.NullOr(t) : t;
|
|
113
|
+
}, wt = (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] = Ct(i));
|
|
116
|
+
return E.Struct(r);
|
|
117
|
+
}, Tt = (e) => typeof e == "function" ? e : () => e, Et = (e, t) => ({
|
|
118
118
|
kind: "one",
|
|
119
|
-
target:
|
|
119
|
+
target: Tt(e),
|
|
120
120
|
...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
|
|
121
121
|
...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
|
|
122
|
-
}),
|
|
122
|
+
}), Dt = (e, t) => ({
|
|
123
123
|
kind: "many",
|
|
124
|
-
target:
|
|
124
|
+
target: Tt(e),
|
|
125
125
|
...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
|
|
126
126
|
...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
|
|
127
|
-
}),
|
|
127
|
+
}), Ot = (e, t) => ({
|
|
128
128
|
kind: "manyToMany",
|
|
129
|
-
target:
|
|
130
|
-
through:
|
|
129
|
+
target: Tt(e),
|
|
130
|
+
through: Tt(t.through),
|
|
131
131
|
sourceKey: t.sourceKey,
|
|
132
132
|
targetKey: t.targetKey
|
|
133
|
-
}),
|
|
134
|
-
one:
|
|
135
|
-
many:
|
|
136
|
-
manyToMany:
|
|
137
|
-
},
|
|
133
|
+
}), kt = {
|
|
134
|
+
one: Et,
|
|
135
|
+
many: Dt,
|
|
136
|
+
manyToMany: Ot
|
|
137
|
+
}, At = (e, t) => {
|
|
138
138
|
let n = typeof e == "function" ? e : () => e;
|
|
139
139
|
return {
|
|
140
140
|
source: n,
|
|
141
|
-
relations: t(
|
|
141
|
+
relations: t(kt, n())
|
|
142
142
|
};
|
|
143
|
-
},
|
|
143
|
+
}, jt = (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 ct = (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
|
+
}, Mt = Et, Nt = Dt, Pt = Ot, O = (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
|
+
}, Ft = (e) => Object.keys(e.fields), k = (e, t) => Object.prototype.hasOwnProperty.call(e.fields, t), It = (e) => {
|
|
159
|
+
let t = Ft(e);
|
|
160
160
|
return t.length === 0 ? "<none>" : t.join(", ");
|
|
161
|
-
},
|
|
161
|
+
}, Lt = (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 (!k(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}': ${It(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 && !k(e, n.sourceKey)) {
|
|
170
|
+
let t = k(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}': ${It(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 && !k(i, n.foreignKey)) {
|
|
174
|
+
let t = k(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}': ${It(i)}.`));
|
|
176
176
|
}
|
|
177
|
-
},
|
|
178
|
-
let t = e.source(), n =
|
|
177
|
+
}, Rt = Symbol.for("@voltro/database/relationsRegistry"), zt = globalThis, A = zt[Rt] ?? (zt[Rt] = /* @__PURE__ */ new Map()), Bt = (e) => {
|
|
178
|
+
let t = e.source(), n = A.get(t.tableName);
|
|
179
179
|
if (n === void 0) {
|
|
180
|
-
|
|
180
|
+
A.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
|
+
}, Vt = (e) => {
|
|
188
188
|
let t = 0;
|
|
189
|
-
for (let n of Object.values(e))
|
|
189
|
+
for (let n of Object.values(e)) jt(n) && (Bt(n), t += 1);
|
|
190
190
|
return t;
|
|
191
|
-
},
|
|
192
|
-
let t =
|
|
191
|
+
}, j = (e) => {
|
|
192
|
+
let t = A.get(e);
|
|
193
193
|
if (t !== void 0) return Object.fromEntries(t);
|
|
194
|
-
},
|
|
194
|
+
}, Ht = (e, t) => A.get(e)?.get(t), Ut = () => {
|
|
195
195
|
let e = [];
|
|
196
|
-
for (let [t, n] of
|
|
196
|
+
for (let [t, n] of A) 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
|
+
}, Wt = () => {
|
|
203
|
+
for (let [e, t] of A) {
|
|
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) Lt(n, e, r);
|
|
206
206
|
}
|
|
207
|
-
},
|
|
208
|
-
|
|
209
|
-
},
|
|
207
|
+
}, Gt = () => {
|
|
208
|
+
A.clear();
|
|
209
|
+
}, Kt = (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, qt = (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 ct = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
217
217
|
} catch {
|
|
218
218
|
return e;
|
|
219
219
|
}
|
|
220
|
-
},
|
|
220
|
+
}, Jt = (e) => e == null || typeof e == "string" ? e : typeof e == "number" || typeof e == "bigint" ? String(e) : e, Yt = (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 ct = (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
|
+
}, Xt = (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 : Kt(e);
|
|
235
235
|
case "json":
|
|
236
|
-
case "array": return n === "postgres" ? e :
|
|
236
|
+
case "array": return n === "postgres" ? e : qt(e);
|
|
237
237
|
case "timestamp":
|
|
238
|
-
case "date": return n === "sqlite" || n === "turso" ?
|
|
238
|
+
case "date": return n === "sqlite" || n === "turso" ? Yt(e) : e;
|
|
239
239
|
case "decimal":
|
|
240
|
-
case "bigint": return
|
|
240
|
+
case "bigint": return Jt(e);
|
|
241
241
|
default: return e;
|
|
242
242
|
}
|
|
243
|
-
},
|
|
243
|
+
}, Zt = (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 ct = (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] = Xt(t[e], r, n));
|
|
255
255
|
return t;
|
|
256
256
|
});
|
|
257
|
-
},
|
|
257
|
+
}, Qt = (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
|
+
}, $t = (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 = Qt(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
|
+
}, en = class extends Error {
|
|
274
274
|
_tag = "EagerCardinalityError";
|
|
275
275
|
constructor(e) {
|
|
276
276
|
super(e), this.name = "EagerCardinalityError";
|
|
277
277
|
}
|
|
278
|
-
},
|
|
278
|
+
}, tn = (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
|
+
}, nn = async (e, t, n, r) => {
|
|
282
282
|
if (e.length === 0) return e;
|
|
283
|
-
let i =
|
|
283
|
+
let i = j(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 ct = (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
|
+
Lt(n, e, t), await rn(a, e, t, o === !0 ? {} : o, n, r);
|
|
293
293
|
}
|
|
294
294
|
return a;
|
|
295
|
-
},
|
|
295
|
+
}, rn = async (e, t, n, r, i, a) => {
|
|
296
296
|
switch (n.kind) {
|
|
297
297
|
case "one":
|
|
298
|
-
await
|
|
298
|
+
await an(e, t, n, r, i, a);
|
|
299
299
|
return;
|
|
300
300
|
case "many":
|
|
301
|
-
await
|
|
301
|
+
await on(e, t, n, r, i, a);
|
|
302
302
|
return;
|
|
303
303
|
case "manyToMany":
|
|
304
|
-
await
|
|
304
|
+
await cn(e, t, n, r, i, a);
|
|
305
305
|
return;
|
|
306
306
|
}
|
|
307
|
-
},
|
|
308
|
-
let o = n.target(), s = n.sourceKey ??
|
|
307
|
+
}, an = async (e, t, n, r, i, a) => {
|
|
308
|
+
let o = n.target(), s = n.sourceKey ?? ln(i, o.tableName);
|
|
309
309
|
if (s !== void 0) {
|
|
310
|
-
let n =
|
|
310
|
+
let n = M(e, s), i = n.length === 0 ? [] : await N(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 un(i, r.with, o, a);
|
|
316
316
|
return;
|
|
317
317
|
}
|
|
318
|
-
let c = n.foreignKey ??
|
|
318
|
+
let c = n.foreignKey ?? O(o, i.tableName, t), l = n.sourceKey ?? "id", u = M(e, l), d = u.length === 0 ? [] : await N(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 en(tn({
|
|
322
322
|
relationName: t,
|
|
323
323
|
sourceTableName: i.tableName,
|
|
324
324
|
targetTableName: o.tableName,
|
|
@@ -331,9 +331,9 @@ var ct = (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 un(d, r.with, o, a);
|
|
335
|
+
}, on = async (e, t, n, r, i, a) => {
|
|
336
|
+
let o = n.target(), s = n.foreignKey ?? O(o, i.tableName, t), c = n.sourceKey ?? "id", l = M(e, c), u = sn(r), d = l.length === 0 ? [] : await N(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 ct = (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 un(d, r.with, o, a);
|
|
353
|
+
}, sn = (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
|
+
}, cn = async (e, t, n, r, i, a) => {
|
|
357
|
+
let o = n.target(), s = n.through(), c = M(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 ct = (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 N(o, "id", M(d, n.targetKey), r, a), p = new Map(f.map((e) => [e.id, e]));
|
|
379
|
+
await un(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 ct = (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
|
+
}, ln = (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
|
+
}, M = (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
|
+
}, N = (e, t, n, r, i) => {
|
|
401
401
|
let a = {
|
|
402
402
|
column: t,
|
|
403
403
|
op: "in",
|
|
@@ -411,54 +411,54 @@ var ct = (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
|
+
}, un = async (e, t, n, r) => {
|
|
415
|
+
t !== void 0 && e.length !== 0 && (await nn(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
|
+
}, dn = (e) => e.eager !== void 0 && Object.keys(e.eager).length > 0, fn = class extends Error {
|
|
420
420
|
_tag = "TenantNamespaceUnresolved";
|
|
421
421
|
constructor(e) {
|
|
422
422
|
super(e), this.name = "TenantNamespaceUnresolved";
|
|
423
423
|
}
|
|
424
|
-
},
|
|
424
|
+
}, pn = 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
|
+
}, mn = 63, hn = "tenant_", gn = (e) => e.toLowerCase().replace(/[^a-z0-9_]/g, "_"), _n = (e) => {
|
|
430
|
+
if (e == null || e === "") throw new fn("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 = gn(e);
|
|
432
|
+
if (t.replace(/_/g, "") === "") throw new pn(`tenant id '${e}' has no usable identifier characters after sanitisation — cannot derive a distinct namespace.`);
|
|
433
|
+
let n = `${hn}${t}`;
|
|
434
|
+
if (n.length > mn) throw new pn(`namespace '${n}' for tenant '${e}' exceeds the ${mn}-byte identifier limit. Use a shorter tenant id.`);
|
|
435
435
|
return n;
|
|
436
|
-
},
|
|
436
|
+
}, vn = (e, t) => e === null ? t : `${e}.${t}`, yn = (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
|
+
}, bn = (e) => e.replace(/[\\%_]/g, (e) => `\\${e}`), P = (e, t, n = null) => {
|
|
441
|
+
if ("not" in e) return t`NOT (${P(e.not, t, n)})`;
|
|
442
|
+
if ("and" in e) return e.and.length === 0 ? t`TRUE` : t.and(e.and.map((e) => P(e, t, n)));
|
|
443
|
+
if ("or" in e) return e.or.length === 0 ? t`FALSE` : t.or(e.or.map((e) => P(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 = F(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 = F(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(S(r.column, a, "mysql")),
|
|
454
|
+
mssql: () => t.unsafe(S(r.column, a, "mssql")),
|
|
455
|
+
sqlite: () => t.unsafe(S(r.column, a, "sqlite")),
|
|
456
|
+
orElse: () => t.unsafe(S(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(S(r.column, a, "mysql", { numeric: !0 })),
|
|
459
|
+
mssql: () => t.unsafe(S(r.column, a, "mssql", { numeric: !0 })),
|
|
460
|
+
sqlite: () => t.unsafe(S(r.column, a, "sqlite", { numeric: !0 })),
|
|
461
|
+
orElse: () => t.unsafe(S(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 ct = (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 = `%${bn(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 ct = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
526
526
|
});
|
|
527
527
|
}
|
|
528
528
|
}
|
|
529
|
-
},
|
|
529
|
+
}, xn = (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
|
+
}, Sn = (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 = xn(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 ct = (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
|
+
})), Cn = (e) => `[${e.join(",")}]`, wn = (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 = Cn(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
|
+
}, Tn = (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
|
+
}, En = (e, t) => t`${t(e.column)} <-> ${e.geom}::geometry`, Dn = (e, t) => t`${t(`${e.indexName}_tsv`)}`, On = (e, t) => `${t}_${e.indexName}_fts`, kn = (e, t, n) => {
|
|
572
|
+
let r = n.csv(e.columns.map((e) => n`${n(e)}`)), i = `%${bn(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(On(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`${Dn(e, n)} @@ plainto_tsquery(${e.config ?? "english"}, ${e.query})`
|
|
581
581
|
});
|
|
582
|
-
},
|
|
583
|
-
let r = `%${
|
|
582
|
+
}, An = (e, t, n) => {
|
|
583
|
+
let r = `%${bn(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(On(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(${Dn(e, n)}, plainto_tsquery(${e.config ?? "english"}, ${e.query}))`
|
|
592
592
|
});
|
|
593
|
-
},
|
|
593
|
+
}, F = (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`(${F(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 ct = (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 : wn(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,57 +616,57 @@ var ct = (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 : Tn(e.spatialClause, t), a = e.aggregations && e.aggregations.length > 0 ? Sn(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 ? An(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(vn(n, e.table))}` : t`${t(vn(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(vn(n, e.table))} AS ${t(e.alias)} ON ${P(e.on, t, n)}`;
|
|
627
|
+
}), h = m.length > 0 ? m.reduce((e, n) => t`${e}${n}`, p) : p, g = c === void 0 ? null : kn(c, e.table, t), ee = [e.predicate ? P(e.predicate, t, n) : null, g].filter((e) => e !== null), te = ee.length > 0 ? t` WHERE ${t.and(ee)}` : t``, _ = e.groupBy && e.groupBy.length > 0 ? t` GROUP BY ${t.csv(e.groupBy.map((e) => t`${t(e)}`))}` : t``, ne = e.having ? t` HAVING ${P(e.having, t, n)}` : t``, v = e.skip !== void 0, y = [];
|
|
628
|
+
r !== null && y.push(t`${r} ASC`), e.spatialClause?.order !== void 0 && y.push(e.spatialClause.order === "desc" ? t`${En(e.spatialClause, t)} DESC` : t`${En(e.spatialClause, t)} ASC`), l !== null && c?.rank?.order === !0 && y.push(t`${l} DESC`);
|
|
629
|
+
for (let n of e.order) y.push(n.direction === "desc" ? t`${t(n.column)} DESC` : t`${t(n.column)} ASC`);
|
|
630
|
+
let re = y.length > 0 ? t` ORDER BY ${t.csv(y)}` : v ? t.onDialectOrElse({
|
|
631
631
|
mssql: () => t` ORDER BY (SELECT NULL)`,
|
|
632
632
|
orElse: () => t``
|
|
633
|
-
}) : t``,
|
|
633
|
+
}) : t``, b = (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
|
+
}, ie = (e.ctes ?? []).map((e) => t`${t(e.name)} AS (${F(e.descriptor, t, n)})`), ae = (e.ctes ?? []).some((e) => e.recursive === !0), oe = ie.length > 0 ? t`WITH ${t.unsafe(ae ? "RECURSIVE " : "")}${t.csv(ie)} ` : 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 && !v ? t`TOP ${b(e.take)} ` : t``, r = v ? t` OFFSET ${b(e.skip)} ROWS FETCH NEXT ${b(e.take ?? 2 ** 53 - 1)} ROWS ONLY` : t``;
|
|
640
|
+
return t`${oe}SELECT ${n}${f}${d} FROM ${h}${te}${_}${ne}${re}${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 ${b(e.take)}`, r = v ? t` OFFSET ${b(e.skip)}` : t``;
|
|
644
|
+
return t`${oe}SELECT ${f}${d} FROM ${h}${te}${_}${ne}${re}${n}${r}`;
|
|
645
645
|
}
|
|
646
646
|
});
|
|
647
|
-
},
|
|
647
|
+
}, jn = (e, t, n) => {
|
|
648
648
|
if (e.eager === void 0) return null;
|
|
649
|
-
let r =
|
|
649
|
+
let r = Mn(e.table, e.eager, e.sourceTable);
|
|
650
650
|
if (r === null) return null;
|
|
651
|
-
let i =
|
|
651
|
+
let i = zn(n, e, r, Rn(t, n));
|
|
652
652
|
return i === null ? null : {
|
|
653
653
|
fragment: i,
|
|
654
|
-
decode:
|
|
654
|
+
decode: Hn(r, n)
|
|
655
655
|
};
|
|
656
|
-
},
|
|
656
|
+
}, I = (e) => e.relation.kind === "one" && e.fkSide === "target", L = (e) => ({
|
|
657
657
|
...e,
|
|
658
658
|
branch: {
|
|
659
659
|
...e.branch,
|
|
660
660
|
limit: 2
|
|
661
661
|
}
|
|
662
|
-
}),
|
|
663
|
-
let r = n ?? g(e), i =
|
|
662
|
+
}), Mn = (e, t, n) => {
|
|
663
|
+
let r = n ?? g(e), i = j(e);
|
|
664
664
|
if (i === void 0) return null;
|
|
665
665
|
let a = [];
|
|
666
666
|
for (let [e, n] of Object.entries(t)) {
|
|
667
667
|
let t = i[e];
|
|
668
668
|
if (t === void 0) return null;
|
|
669
|
-
let o =
|
|
669
|
+
let o = Nn(e, t, r, n === !0 ? {} : n);
|
|
670
670
|
if (o === null) return null;
|
|
671
671
|
a.push(o);
|
|
672
672
|
}
|
|
@@ -674,30 +674,30 @@ var ct = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
674
674
|
table: r,
|
|
675
675
|
children: a
|
|
676
676
|
};
|
|
677
|
-
},
|
|
677
|
+
}, Nn = (e, t, n, r) => {
|
|
678
678
|
let i = t.target(), a = (t.kind === "manyToMany" ? void 0 : t.sourceKey) ?? "id", o, s;
|
|
679
679
|
if (t.kind === "manyToMany") o = t.targetKey, s = "target";
|
|
680
680
|
else if (t.kind === "one") {
|
|
681
|
-
let r = t.sourceKey ??
|
|
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 ?? O(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 ?? O(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 = j(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)) {
|
|
698
698
|
let r = e?.[n];
|
|
699
699
|
if (r === void 0) return null;
|
|
700
|
-
let o =
|
|
700
|
+
let o = Nn(n, r, i, a === !0 ? {} : a);
|
|
701
701
|
if (o === null) return null;
|
|
702
702
|
t.push(o);
|
|
703
703
|
}
|
|
@@ -713,9 +713,9 @@ var ct = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
713
713
|
fkSide: s,
|
|
714
714
|
branch: r,
|
|
715
715
|
children: c,
|
|
716
|
-
junction:
|
|
716
|
+
junction: Pn(t, r)
|
|
717
717
|
};
|
|
718
|
-
},
|
|
718
|
+
}, Pn = (e, t) => {
|
|
719
719
|
if (e.kind !== "manyToMany" || t.junction === void 0) return;
|
|
720
720
|
let n = e.through(), r = t.junction === !0 ? Object.keys(n.fields) : t.junction, i = r.filter((e) => e in n.fields);
|
|
721
721
|
return {
|
|
@@ -727,35 +727,35 @@ var ct = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
727
727
|
return t !== void 0 && (t.type === "timestamp" || t.type === "date");
|
|
728
728
|
})
|
|
729
729
|
};
|
|
730
|
-
},
|
|
730
|
+
}, Fn = (e) => `__j_${e}`, In = "__j", Ln = (e, t) => {
|
|
731
731
|
for (let [n, r] of Object.entries(e.fields)) if (r.type === "reference" && r.references?.()?.tableName === t) return n;
|
|
732
|
-
},
|
|
732
|
+
}, Rn = (e, t) => {
|
|
733
733
|
let n = 0;
|
|
734
734
|
return {
|
|
735
735
|
sql: e,
|
|
736
736
|
dialect: t,
|
|
737
737
|
nextAlias: () => `__a${n++}`
|
|
738
738
|
};
|
|
739
|
-
},
|
|
739
|
+
}, zn = (e, t, n, r) => {
|
|
740
740
|
switch (e) {
|
|
741
|
-
case "postgres": return
|
|
741
|
+
case "postgres": return Gn(t, n, r);
|
|
742
742
|
case "sqlite":
|
|
743
|
-
case "turso": return
|
|
743
|
+
case "turso": return Qn(t, n, r);
|
|
744
744
|
case "mysql":
|
|
745
|
-
case "mariadb": return
|
|
746
|
-
case "mssql": return
|
|
745
|
+
case "mariadb": return sr(t, n, r);
|
|
746
|
+
case "mssql": return mr(t, n, r);
|
|
747
747
|
}
|
|
748
|
-
},
|
|
749
|
-
let n =
|
|
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
|
+
let n = Un(e.table, e.children, t);
|
|
750
750
|
return (e) => e.map((e) => {
|
|
751
751
|
let t = e.__row, r = typeof t == "string" ? JSON.parse(t) : t;
|
|
752
752
|
return n(r);
|
|
753
753
|
});
|
|
754
|
-
},
|
|
754
|
+
}, Un = (e, t, n) => {
|
|
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 =
|
|
758
|
+
let t = Un(e.target, e.children, n), r = e.relation.kind === "one", i = I(e), a = i ? tn({
|
|
759
759
|
relationName: e.relationName,
|
|
760
760
|
sourceTableName: e.source.tableName,
|
|
761
761
|
targetTableName: e.target.tableName,
|
|
@@ -768,14 +768,14 @@ var ct = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
768
768
|
isSingle: r,
|
|
769
769
|
fromOverFetch: i,
|
|
770
770
|
cardinalityMessage: a,
|
|
771
|
-
junction:
|
|
771
|
+
junction: Wn(e.junction, n)
|
|
772
772
|
};
|
|
773
773
|
});
|
|
774
774
|
return (e) => {
|
|
775
775
|
let t = { ...e };
|
|
776
776
|
for (let e of r) {
|
|
777
777
|
let r = t[e];
|
|
778
|
-
typeof r == "string" && (t[e] =
|
|
778
|
+
typeof r == "string" && (t[e] = Bn(r, n));
|
|
779
779
|
}
|
|
780
780
|
for (let e of i) {
|
|
781
781
|
let n = t[e.name];
|
|
@@ -785,7 +785,7 @@ var ct = (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 en(e.cardinalityMessage);
|
|
789
789
|
t[e.name] = r.length === 0 ? null : e.decode(r[0]);
|
|
790
790
|
continue;
|
|
791
791
|
}
|
|
@@ -797,104 +797,104 @@ var ct = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
797
797
|
}
|
|
798
798
|
return t;
|
|
799
799
|
};
|
|
800
|
-
},
|
|
800
|
+
}, Wn = (e, t) => {
|
|
801
801
|
if (e === void 0) return;
|
|
802
802
|
let n = new Set(e.dateColumns), r = e.requested;
|
|
803
803
|
return (e) => {
|
|
804
804
|
let i = e._junction ?? {}, a = {};
|
|
805
805
|
for (let e of r) {
|
|
806
806
|
let r = i[e];
|
|
807
|
-
a[e] = n.has(e) && typeof r == "string" ?
|
|
807
|
+
a[e] = n.has(e) && typeof r == "string" ? Bn(r, t) : r;
|
|
808
808
|
}
|
|
809
809
|
return {
|
|
810
810
|
...e,
|
|
811
811
|
_junction: a
|
|
812
812
|
};
|
|
813
813
|
};
|
|
814
|
-
},
|
|
815
|
-
let r = n.sql, i = n.nextAlias(), a = r(t.table.tableName), o = r(i), s =
|
|
814
|
+
}, Gn = (e, t, n) => {
|
|
815
|
+
let r = n.sql, i = n.nextAlias(), a = r(t.table.tableName), o = r(i), s = R(i, t.children, n);
|
|
816
816
|
return s === null ? null : r`SELECT ${s} AS "__row" FROM ${a} AS ${o}${e.predicate ? r` WHERE ${G(e.predicate, i, r)}` : r``}${e.order.length > 0 ? r` ORDER BY ${r.csv(e.order.map((e) => e.direction === "desc" ? r`${H(i, e.column, r)} DESC` : r`${H(i, e.column, r)} ASC`))}` : r``}${e.take === void 0 ? r`` : r` LIMIT ${W(e.take, r)}`}${e.skip === void 0 ? r`` : r` OFFSET ${W(e.skip, r)}`}`;
|
|
817
|
-
},
|
|
818
|
-
let i = n.sql, a = r === void 0 ? i`to_jsonb(${i(e)}.*)` : i`(to_jsonb(${i(e)}.*) - ${U(
|
|
817
|
+
}, R = (e, t, n, r) => {
|
|
818
|
+
let i = n.sql, a = r === void 0 ? i`to_jsonb(${i(e)}.*)` : i`(to_jsonb(${i(e)}.*) - ${U(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`${U("_junction", i)}, ${H(e,
|
|
821
|
+
r !== void 0 && o.push(i`${U("_junction", i)}, ${H(e, In, i)}`);
|
|
822
822
|
for (let r of t) {
|
|
823
|
-
let t =
|
|
823
|
+
let t = Kn(r, e, n);
|
|
824
824
|
if (t === null) return null;
|
|
825
825
|
o.push(i`${U(r.relationName, i)}, ${t}`);
|
|
826
826
|
}
|
|
827
827
|
return i`${a} || jsonb_build_object(${i.csv(o)})`;
|
|
828
|
-
},
|
|
828
|
+
}, Kn = (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 I(e) ? Jn(L(e), t, n) : qn(e, t, n);
|
|
831
|
+
case "many": return Jn(e, t, n);
|
|
832
|
+
case "manyToMany": return Yn(e, t, n);
|
|
833
833
|
}
|
|
834
|
-
},
|
|
835
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
834
|
+
}, qn = (e, t, n) => {
|
|
835
|
+
let r = n.sql, i = n.nextAlias(), a = R(i, e.children, n);
|
|
836
836
|
if (a === null) return null;
|
|
837
|
-
let o = e.fkSide === "source" ? r`${H(i, "id", r)} = ${H(t, e.foreignKey, r)}` : r`${H(i, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${G(e.branch.where, i, r)}`, c =
|
|
837
|
+
let o = e.fkSide === "source" ? r`${H(i, "id", r)} = ${H(t, e.foreignKey, r)}` : r`${H(i, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${G(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
|
+
}, Jn = (e, t, n) => {
|
|
840
|
+
let r = n.sql, i = n.nextAlias(), a = R(i, e.children, n);
|
|
841
841
|
if (a === null) return null;
|
|
842
|
-
let o = r`${H(void 0, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${
|
|
842
|
+
let o = r`${H(void 0, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${P(e.branch.where, r)}`, c = Zn(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${W(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${W(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
|
+
}, Yn = (e, t, n) => {
|
|
845
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = R(o, e.children, n, e.junction);
|
|
846
846
|
if (c === null) return null;
|
|
847
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
847
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${P(e.branch.where, r)}`, u = K(e, s, r), d = z(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${W(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${W(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : r`, ${Xn(e.junction, s, r)} AS ${r(In)}`;
|
|
848
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 ${H(o, "id", r)} = ${H(s, i.targetKey, r)} WHERE ${H(s, i.sourceKey, r)} = ${H(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), '[]'::jsonb)`;
|
|
849
|
-
},
|
|
850
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
849
|
+
}, Xn = (e, t, n) => e.present.length === 0 ? n`jsonb_build_object()` : n`jsonb_build_object(${n.csv(e.present.map((e) => n`${U(e, n)}, ${H(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`${H(e, t.column, n)} DESC` : n`${H(e, t.column, n)} ASC`))}`, Zn = (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`))}`, Qn = (e, t, n) => {
|
|
850
|
+
let r = n.sql, i = n.nextAlias(), a = B(i, t.table, t.children, n);
|
|
851
851
|
if (a === null) return null;
|
|
852
852
|
let o = e.predicate ? r` WHERE ${G(e.predicate, i, r)}` : r``, s = e.order.length > 0 ? r` ORDER BY ${r.csv(e.order.map((e) => e.direction === "desc" ? r`${H(i, e.column, r)} DESC` : r`${H(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${W(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${W(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
|
+
}, B = (e, t, n, r, i) => {
|
|
855
855
|
let a = r.sql, o = [];
|
|
856
856
|
for (let n of Object.keys(t.fields)) o.push(a`${U(n, a)}, ${H(e, n, a)}`);
|
|
857
857
|
if (i !== void 0) {
|
|
858
|
-
let e =
|
|
858
|
+
let e = $n(i.projection, i.source, a);
|
|
859
859
|
o.push(a`${U("_junction", a)}, json_object(${e})`);
|
|
860
860
|
}
|
|
861
861
|
for (let t of n) {
|
|
862
|
-
let n =
|
|
862
|
+
let n = rr(t, e, r);
|
|
863
863
|
if (n === null) return null;
|
|
864
864
|
o.push(a`${U(t.relationName, a)}, ${n}`);
|
|
865
865
|
}
|
|
866
866
|
return a`json_object(${a.csv(o)})`;
|
|
867
|
-
},
|
|
867
|
+
}, $n = (e, t, n) => e.present.length === 0 ? n`` : n.csv(e.present.map((e) => n`${U(e, n)}, ${H(t.alias, t.physical(e), n)}`)), er = (e, t, n) => e.present.length === 0 ? n`` : n`, ${n.csv(e.present.map((e) => n`${H(t, e, n)} AS ${n(Fn(e))}`))}`, tr = (e) => ({
|
|
868
868
|
alias: e,
|
|
869
|
-
physical:
|
|
870
|
-
}),
|
|
869
|
+
physical: Fn
|
|
870
|
+
}), nr = (e) => ({
|
|
871
871
|
alias: e,
|
|
872
872
|
physical: (e) => e
|
|
873
|
-
}),
|
|
873
|
+
}), rr = (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 I(e) ? ar(L(e), t, n) : ir(e, t, n);
|
|
876
|
+
case "many": return ar(e, t, n);
|
|
877
|
+
case "manyToMany": return or(e, t, n);
|
|
878
878
|
}
|
|
879
|
-
},
|
|
880
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
879
|
+
}, ir = (e, t, n) => {
|
|
880
|
+
let r = n.sql, i = n.nextAlias(), a = B(i, e.target, e.children, n);
|
|
881
881
|
if (a === null) return null;
|
|
882
882
|
let o = e.fkSide === "source" ? r`${H(i, "id", r)} = ${H(t, e.foreignKey, r)}` : r`${H(i, e.foreignKey, r)} = ${H(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
|
+
}, ar = (e, t, n) => {
|
|
885
|
+
let r = n.sql, i = n.nextAlias(), a = B(i, e.target, e.children, n);
|
|
886
886
|
if (a === null) return null;
|
|
887
|
-
let o = r`${H(void 0, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${
|
|
887
|
+
let o = r`${H(void 0, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${P(q(e.branch.where), r)}`, c = Zn(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${W(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${W(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
|
+
}, or = (e, t, n) => {
|
|
890
|
+
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 : {
|
|
891
891
|
projection: e.junction,
|
|
892
|
-
source:
|
|
892
|
+
source: tr(o)
|
|
893
893
|
});
|
|
894
894
|
if (c === null) return null;
|
|
895
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
895
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${P(q(e.branch.where), r)}`, u = K(e, s, r, !0), d = z(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${W(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${W(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : er(e.junction, s, r);
|
|
896
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 ${H(o, "id", r)} = ${H(s, i.targetKey, r)} WHERE ${H(s, i.sourceKey, r)} = ${H(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), json('[]'))`;
|
|
897
|
-
},
|
|
897
|
+
}, sr = (e, t, n) => {
|
|
898
898
|
let r = n.sql, i = n.nextAlias(), a = V(i, t.table, t.children, n);
|
|
899
899
|
if (a === null) return null;
|
|
900
900
|
let o = e.predicate ? r` WHERE ${G(e.predicate, i, r)}` : r``, s = e.order.length > 0 ? r` ORDER BY ${r.csv(e.order.map((e) => e.direction === "desc" ? r`${H(i, e.column, r)} DESC` : r`${H(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${W(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${W(e.skip, r)}`;
|
|
@@ -903,66 +903,66 @@ var ct = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
903
903
|
let a = r.sql, o = [];
|
|
904
904
|
for (let n of Object.keys(t.fields)) o.push(a`${U(n, a)}, ${H(e, n, a)}`);
|
|
905
905
|
if (i !== void 0) {
|
|
906
|
-
let e =
|
|
906
|
+
let e = $n(i.projection, i.source, a);
|
|
907
907
|
o.push(a`${U("_junction", a)}, JSON_OBJECT(${e})`);
|
|
908
908
|
}
|
|
909
909
|
for (let t of n) {
|
|
910
|
-
let n =
|
|
910
|
+
let n = cr(t, e, r);
|
|
911
911
|
if (n === null) return null;
|
|
912
912
|
o.push(a`${U(t.relationName, a)}, ${n}`);
|
|
913
913
|
}
|
|
914
914
|
return a`JSON_OBJECT(${a.csv(o)})`;
|
|
915
|
-
},
|
|
915
|
+
}, cr = (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 (I(e)) {
|
|
919
|
+
let r = L(e);
|
|
920
|
+
return n.dialect === "mariadb" ? fr(r, t, n) : ur(r, t, n);
|
|
921
921
|
}
|
|
922
|
-
return
|
|
923
|
-
case "many": return n.dialect === "mariadb" ?
|
|
924
|
-
case "manyToMany": return n.dialect === "mariadb" ?
|
|
922
|
+
return lr(e, t, n);
|
|
923
|
+
case "many": return n.dialect === "mariadb" ? fr(e, t, n) : ur(e, t, n);
|
|
924
|
+
case "manyToMany": return n.dialect === "mariadb" ? pr(e, t, n) : dr(e, t, n);
|
|
925
925
|
}
|
|
926
|
-
},
|
|
926
|
+
}, lr = (e, t, n) => {
|
|
927
927
|
let r = n.sql, i = n.nextAlias(), a = V(i, e.target, e.children, n);
|
|
928
928
|
if (a === null) return null;
|
|
929
929
|
let o = e.fkSide === "source" ? r`${H(i, "id", r)} = ${H(t, e.foreignKey, r)}` : r`${H(i, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`;
|
|
930
930
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
|
|
931
|
-
},
|
|
931
|
+
}, ur = (e, t, n) => {
|
|
932
932
|
let r = n.sql, i = n.nextAlias(), a = V(i, e.target, e.children, n);
|
|
933
933
|
if (a === null) return null;
|
|
934
|
-
let o = r`${H(void 0, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${
|
|
934
|
+
let o = r`${H(void 0, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${P(q(e.branch.where), r)}`, c = Zn(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${W(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${W(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
|
-
},
|
|
936
|
+
}, dr = (e, t, n) => {
|
|
937
937
|
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = V(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
938
938
|
projection: e.junction,
|
|
939
|
-
source:
|
|
939
|
+
source: tr(o)
|
|
940
940
|
});
|
|
941
941
|
if (c === null) return null;
|
|
942
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
942
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${P(q(e.branch.where), r)}`, u = K(e, s, r, !0), d = z(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${W(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${W(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : er(e.junction, s, r);
|
|
943
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 ${H(o, "id", r)} = ${H(s, i.targetKey, r)} WHERE ${H(s, i.sourceKey, r)} = ${H(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), JSON_ARRAY())`;
|
|
944
|
-
},
|
|
944
|
+
}, fr = (e, t, n) => {
|
|
945
945
|
let r = n.sql, i = n.nextAlias(), a = V(i, e.target, e.children, n);
|
|
946
946
|
if (a === null) return null;
|
|
947
|
-
let o = r`${H(i, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${
|
|
947
|
+
let o = r`${H(i, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${P(q(e.branch.where), r)}`, c = e.branch.orderBy ?? [];
|
|
948
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`${H(i, e.column, r)} DESC` : r`${H(i, e.column, r)} ASC`))}` : r``}) FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}), JSON_ARRAY())`;
|
|
949
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 ${H(i, "rn", r)} > ${W(d, r)} AND ${H(i, "rn", r)} <= ${W(d + u, r)}` : u === void 0 ? r` AND ${H(i, "rn", r)} > ${W(d, r)}` : r` AND ${H(i, "rn", r)} <= ${W(u, r)}`;
|
|
950
950
|
return r`COALESCE((SELECT JSON_ARRAYAGG(${a} ORDER BY ${H(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
|
-
},
|
|
951
|
+
}, pr = (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`${H(s, i.sourceKey, r)} = ${H(t, "id", r)}`, u = r`${H(o, "id", r)} = ${H(s, i.targetKey, r)}`, d = e.branch.where === void 0 ? r`` : r` AND ${
|
|
955
|
+
}, l = r`${H(s, i.sourceKey, r)} = ${H(t, "id", r)}`, u = r`${H(o, "id", r)} = ${H(s, i.targetKey, r)}`, d = e.branch.where === void 0 ? r`` : r` AND ${P(q(e.branch.where), r)}`, f = K(e, s, r, !0), p = e.branch.orderBy ?? [];
|
|
956
956
|
if (!(e.branch.limit !== void 0 || e.branch.offset !== void 0)) {
|
|
957
|
-
let t = V(o, e.target, e.children, n, c(
|
|
957
|
+
let t = V(o, e.target, e.children, n, c(nr(s)));
|
|
958
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`${H(o, e.column, r)} DESC` : r`${H(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
959
|
}
|
|
960
|
-
let m = p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${H(o, e.column, r)} DESC` : r`${H(o, e.column, r)} ASC`))}` : r` ORDER BY ${H(o, "id", r)}`, h = e.branch.limit, g = e.branch.offset, ee = h !== void 0 && g !== void 0 ? r` AND ${H(o, "rn", r)} > ${W(g, r)} AND ${H(o, "rn", r)} <= ${W(g + h, r)}` : h === void 0 ? r` AND ${H(o, "rn", r)} > ${W(g, r)}` : r` AND ${H(o, "rn", r)} <= ${W(h, r)}`, te = e.branch.onJunction === void 0 ? r`` : r` WHERE ${G(q(e.branch.onJunction), s, r)}`, _ = V(o, e.target, e.children, n, c(
|
|
960
|
+
let m = p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${H(o, e.column, r)} DESC` : r`${H(o, e.column, r)} ASC`))}` : r` ORDER BY ${H(o, "id", r)}`, h = e.branch.limit, g = e.branch.offset, ee = h !== void 0 && g !== void 0 ? r` AND ${H(o, "rn", r)} > ${W(g, r)} AND ${H(o, "rn", r)} <= ${W(g + h, r)}` : h === void 0 ? r` AND ${H(o, "rn", r)} > ${W(g, r)}` : r` AND ${H(o, "rn", r)} <= ${W(h, r)}`, te = e.branch.onJunction === void 0 ? r`` : r` WHERE ${G(q(e.branch.onJunction), s, r)}`, _ = V(o, e.target, e.children, n, c(tr(o)));
|
|
961
961
|
if (_ === null) return null;
|
|
962
|
-
let
|
|
963
|
-
return r`COALESCE((SELECT JSON_ARRAYAGG(${_} ORDER BY ${H(o, "rn", r)}) FROM (SELECT ${r(o)}.*${
|
|
964
|
-
},
|
|
965
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
962
|
+
let ne = e.junction === void 0 ? r`` : er(e.junction, s, r);
|
|
963
|
+
return r`COALESCE((SELECT JSON_ARRAYAGG(${_} ORDER BY ${H(o, "rn", r)}) FROM (SELECT ${r(o)}.*${ne}, ${H(s, i.sourceKey, r)} AS ${r(`__src_${i.sourceKey}`)}, ROW_NUMBER() OVER (PARTITION BY ${H(s, i.sourceKey, r)}${m}) AS rn FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${u}${te}) AS ${r(o)} WHERE ${H(o, `__src_${i.sourceKey}`, r)} = ${H(t, "id", r)}${d}${ee}), JSON_ARRAY())`;
|
|
964
|
+
}, mr = (e, t, n) => {
|
|
965
|
+
let r = n.sql, i = n.nextAlias(), a = hr(i, t.table, t.children, n);
|
|
966
966
|
if (a === null) return null;
|
|
967
967
|
let o = e.predicate ? r` WHERE ${G(e.predicate, i, r)}` : r``, s = e.order.length > 0 ? r` ORDER BY ${r.csv(e.order.map((e) => e.direction === "desc" ? r`${H(i, e.column, r)} DESC` : r`${H(i, e.column, r)} ASC`))}` : r``, c = r``, l = r``;
|
|
968
968
|
if (e.skip !== void 0) {
|
|
@@ -971,28 +971,28 @@ var ct = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
971
971
|
} else e.take !== void 0 && (c = r`TOP ${W(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
|
+
}, hr = (e, t, n, r, i) => {
|
|
975
975
|
let a = r.sql, o = [];
|
|
976
976
|
for (let n of Object.keys(t.fields)) o.push(a`${H(e, n, a)} AS ${a(n)}`);
|
|
977
|
-
if (i !== void 0) for (let e of i.projection.present) o.push(a`${H(i.source.alias, i.source.physical(e), a)} AS ${
|
|
977
|
+
if (i !== void 0) for (let e of i.projection.present) o.push(a`${H(i.source.alias, i.source.physical(e), a)} AS ${gr(`_junction.${e}`, a)}`);
|
|
978
978
|
for (let t of n) {
|
|
979
|
-
let n =
|
|
979
|
+
let n = _r(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
|
+
}, gr = (e, t) => t.unsafe(`[${e.replace(/]/g, "]]")}]`), _r = (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 I(e) ? br(L(e), t, n) : vr(e, t, n);
|
|
987
|
+
case "many": return br(e, t, n);
|
|
988
|
+
case "manyToMany": return xr(e, t, n);
|
|
989
989
|
}
|
|
990
|
-
},
|
|
991
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
990
|
+
}, vr = (e, t, n) => {
|
|
991
|
+
let r = n.sql, i = n.nextAlias(), a = hr(i, e.target, e.children, n);
|
|
992
992
|
if (a === null) return null;
|
|
993
993
|
let o = e.fkSide === "source" ? r`${H(i, "id", r)} = ${H(t, e.foreignKey, r)}` : r`${H(i, e.foreignKey, r)} = ${H(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
|
+
}, yr = (e, t, n) => {
|
|
996
996
|
if (e.offset !== void 0) {
|
|
997
997
|
let r = e.orderBy && e.orderBy.length > 0 ? t : n` ORDER BY (SELECT NULL)`, i = e.limit === void 0 ? n`${r} OFFSET ${W(e.offset, n)} ROWS` : n`${r} OFFSET ${W(e.offset, n)} ROWS FETCH NEXT ${W(e.limit, n)} ROWS ONLY`;
|
|
998
998
|
return {
|
|
@@ -1006,29 +1006,29 @@ var ct = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1006
1006
|
pagination: n``,
|
|
1007
1007
|
finalOrder: t
|
|
1008
1008
|
};
|
|
1009
|
-
},
|
|
1010
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1009
|
+
}, br = (e, t, n) => {
|
|
1010
|
+
let r = n.sql, i = n.nextAlias(), a = hr(i, e.target, e.children, n);
|
|
1011
1011
|
if (a === null) return null;
|
|
1012
|
-
let o = e.branch.where === void 0 ? r`` : r` AND ${G(e.branch.where, i, r)}`, s =
|
|
1012
|
+
let o = e.branch.where === void 0 ? r`` : r` AND ${G(e.branch.where, i, r)}`, s = z(i, e.branch.orderBy, r), { top: c, pagination: l, finalOrder: u } = yr(e.branch, s, r);
|
|
1013
1013
|
return r`ISNULL(JSON_QUERY((SELECT ${c}${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${H(i, e.foreignKey, r)} = ${H(t, e.sourceKey, r)}${o}${u}${l} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
|
|
1014
|
-
},
|
|
1015
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
1014
|
+
}, xr = (e, t, n) => {
|
|
1015
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = hr(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
1016
1016
|
projection: e.junction,
|
|
1017
|
-
source:
|
|
1017
|
+
source: nr(s)
|
|
1018
1018
|
});
|
|
1019
1019
|
if (c === null) return null;
|
|
1020
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${G(e.branch.where, o, r)}`, u = K(e, s, r), d =
|
|
1020
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${G(e.branch.where, o, r)}`, u = K(e, s, r), d = z(o, e.branch.orderBy, r), { top: f, pagination: p, finalOrder: m } = yr(e.branch, d, r);
|
|
1021
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 ${H(o, "id", r)} = ${H(s, i.targetKey, r)} WHERE ${H(s, i.sourceKey, r)} = ${H(t, "id", r)}${u}${l}${m}${p} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
|
|
1022
1022
|
}, H = (e, t, n) => e === void 0 ? n`${n(t)}` : n`${n(e)}.${n(t)}`, U = (e, t) => t.unsafe(`'${e.replace(/'/g, "''")}'`), W = (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
|
-
}, G = (e, t, n) =>
|
|
1025
|
+
}, G = (e, t, n) => P(Sr(e, t), n), K = (e, t, n, r = !1) => {
|
|
1026
1026
|
let i = e.branch.onJunction;
|
|
1027
1027
|
return i === void 0 ? n`` : n` AND ${G(r ? q(i) : i, t, n)}`;
|
|
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) =>
|
|
1028
|
+
}, Sr = (e, t) => {
|
|
1029
|
+
if ("not" in e) return { not: Sr(e.not, t) };
|
|
1030
|
+
if ("and" in e) return { and: e.and.map((e) => Sr(e, t)) };
|
|
1031
|
+
if ("or" in e) return { or: e.or.map((e) => Sr(e, t)) };
|
|
1032
1032
|
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
1033
1033
|
let n = e;
|
|
1034
1034
|
return {
|
|
@@ -1050,83 +1050,83 @@ var ct = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1050
1050
|
let t = e;
|
|
1051
1051
|
return {
|
|
1052
1052
|
...t,
|
|
1053
|
-
value:
|
|
1053
|
+
value: Cr(t.value)
|
|
1054
1054
|
};
|
|
1055
|
-
},
|
|
1056
|
-
e.actors !== void 0 && (
|
|
1057
|
-
},
|
|
1055
|
+
}, Cr = (e) => e == null ? e : e instanceof Date ? e.toISOString() : typeof e == "boolean" ? +!!e : Array.isArray(e) ? e.map((e) => Cr(e)) : e, wr = Symbol.for("@voltro/database/coreTablesRegistry"), Tr = globalThis, Er = Tr[wr] ?? (Tr[wr] = {}), Dr = (e) => {
|
|
1056
|
+
e.actors !== void 0 && (Er.actors = e.actors), e.tenants !== void 0 && (Er.tenants = e.tenants);
|
|
1057
|
+
}, Or = (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
|
+
}, kr = () => Or(() => Er.actors, "actors"), Ar = () => Or(() => Er.tenants, "tenants"), jr = f("actors", {
|
|
1062
|
+
id: x(),
|
|
1063
|
+
kind: C().oneOf([
|
|
1064
1064
|
"user",
|
|
1065
1065
|
"serviceAccount",
|
|
1066
1066
|
"apiKey",
|
|
1067
1067
|
"system"
|
|
1068
1068
|
]),
|
|
1069
|
-
displayName:
|
|
1070
|
-
createdAt:
|
|
1071
|
-
}),
|
|
1069
|
+
displayName: C().nullable(),
|
|
1070
|
+
createdAt: n().default("now")
|
|
1071
|
+
}), Mr = (e, t) => ({
|
|
1072
1072
|
column: e,
|
|
1073
1073
|
op: "eq",
|
|
1074
1074
|
value: t
|
|
1075
|
-
}),
|
|
1075
|
+
}), Nr = (e, t) => ({
|
|
1076
1076
|
column: e,
|
|
1077
1077
|
op: "neq",
|
|
1078
1078
|
value: t
|
|
1079
|
-
}),
|
|
1079
|
+
}), Pr = (e, t) => ({
|
|
1080
1080
|
column: e,
|
|
1081
1081
|
op: "gt",
|
|
1082
1082
|
value: t
|
|
1083
|
-
}),
|
|
1083
|
+
}), Fr = (e, t) => ({
|
|
1084
1084
|
column: e,
|
|
1085
1085
|
op: "gte",
|
|
1086
1086
|
value: t
|
|
1087
|
-
}),
|
|
1087
|
+
}), Ir = (e, t) => ({
|
|
1088
1088
|
column: e,
|
|
1089
1089
|
op: "lt",
|
|
1090
1090
|
value: t
|
|
1091
|
-
}),
|
|
1091
|
+
}), Lr = (e, t) => ({
|
|
1092
1092
|
column: e,
|
|
1093
1093
|
op: "lte",
|
|
1094
1094
|
value: t
|
|
1095
|
-
}),
|
|
1095
|
+
}), Rr = (e, t) => ({
|
|
1096
1096
|
column: e,
|
|
1097
1097
|
op: "in",
|
|
1098
1098
|
value: t
|
|
1099
|
-
}),
|
|
1099
|
+
}), zr = (e, t) => ({
|
|
1100
1100
|
column: e,
|
|
1101
1101
|
op: "notIn",
|
|
1102
1102
|
value: t
|
|
1103
|
-
}),
|
|
1103
|
+
}), Br = (e, t) => ({
|
|
1104
1104
|
column: e,
|
|
1105
1105
|
op: "contains",
|
|
1106
1106
|
value: t
|
|
1107
|
-
}),
|
|
1107
|
+
}), Vr = (e, t) => ({
|
|
1108
1108
|
column: e,
|
|
1109
1109
|
op: "arrayContains",
|
|
1110
1110
|
value: t
|
|
1111
|
-
}),
|
|
1111
|
+
}), Hr = (e, t) => ({
|
|
1112
1112
|
column: e,
|
|
1113
1113
|
op: "arrayOverlaps",
|
|
1114
1114
|
value: t
|
|
1115
|
-
}),
|
|
1115
|
+
}), Ur = (e, t) => ({
|
|
1116
1116
|
column: e,
|
|
1117
1117
|
op: "arrayHas",
|
|
1118
1118
|
value: t
|
|
1119
|
-
}),
|
|
1119
|
+
}), Wr = (e) => ({
|
|
1120
1120
|
column: e,
|
|
1121
1121
|
op: "isNull"
|
|
1122
|
-
}),
|
|
1122
|
+
}), Gr = (e) => ({
|
|
1123
1123
|
column: e,
|
|
1124
1124
|
op: "isNotNull"
|
|
1125
|
-
}),
|
|
1125
|
+
}), Kr = (e, t) => ({
|
|
1126
1126
|
column: e,
|
|
1127
1127
|
op: "spatial",
|
|
1128
1128
|
value: t
|
|
1129
|
-
}),
|
|
1129
|
+
}), qr = (...e) => ({ and: e }), Jr = (...e) => ({ or: e }), Yr = (e) => ({ not: e }), Xr = (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 ct = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1147
1147
|
isNull: () => n("isNull"),
|
|
1148
1148
|
isNotNull: () => n("isNotNull")
|
|
1149
1149
|
};
|
|
1150
|
-
},
|
|
1150
|
+
}, Zr = (e) => "descriptor" in e ? e.descriptor : e, Qr = (e, t) => ({
|
|
1151
1151
|
column: e,
|
|
1152
1152
|
op: "subquery-in",
|
|
1153
|
-
subquery:
|
|
1154
|
-
}),
|
|
1153
|
+
subquery: Zr(t)
|
|
1154
|
+
}), $r = (e, t) => ({
|
|
1155
1155
|
column: e,
|
|
1156
1156
|
op: "subquery-not-in",
|
|
1157
|
-
subquery:
|
|
1158
|
-
}), $r = (e) => ({
|
|
1159
|
-
op: "exists",
|
|
1160
|
-
subquery: Xr(e)
|
|
1157
|
+
subquery: Zr(t)
|
|
1161
1158
|
}), ei = (e) => ({
|
|
1159
|
+
op: "exists",
|
|
1160
|
+
subquery: Zr(e)
|
|
1161
|
+
}), ti = (e) => ({
|
|
1162
1162
|
op: "not-exists",
|
|
1163
|
-
subquery:
|
|
1164
|
-
}),
|
|
1163
|
+
subquery: Zr(e)
|
|
1164
|
+
}), ni = (e, t) => e == null || t == null ? null : typeof e == typeof t ? e === t ? 0 : e > t ? 1 : -1 : null, ri = (e, t, n = null) => {
|
|
1165
1165
|
if (!t) return !1;
|
|
1166
|
-
if ("not" in e) return !
|
|
1166
|
+
if ("not" in e) return !ri(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 (!ri(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 (ri(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 ct = (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 (ni(i, r.value) ?? -1) > 0;
|
|
1192
|
+
case "gte": return (ni(i, r.value) ?? -1) >= 0;
|
|
1193
|
+
case "lt": return (ni(i, r.value) ?? 1) < 0;
|
|
1194
|
+
case "lte": return (ni(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 ct = (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
|
+
}, ii = function* (e) {
|
|
1212
1212
|
if ("not" in e) {
|
|
1213
|
-
yield*
|
|
1213
|
+
yield* ii(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* ii(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* ii(t);
|
|
1222
1222
|
return;
|
|
1223
1223
|
}
|
|
1224
1224
|
e.op === "subquery-in" || e.op === "subquery-not-in" ? yield {
|
|
@@ -1228,27 +1228,27 @@ var ct = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1228
1228
|
kind: "exists",
|
|
1229
1229
|
descriptor: e.subquery
|
|
1230
1230
|
});
|
|
1231
|
-
},
|
|
1231
|
+
}, ai = function* (e, t = !0) {
|
|
1232
1232
|
if ("not" in e) {
|
|
1233
|
-
yield*
|
|
1233
|
+
yield* ai(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* ai(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* ai(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
|
+
}, oi = class extends lt.TaggedError("TableStreamError") {}, si = 1e3, ci = (e, t, n, r) => {
|
|
1249
|
+
let i = T.match(r, {
|
|
1250
1250
|
onNone: () => e.where,
|
|
1251
|
-
onSome: (n) => e.where ?
|
|
1251
|
+
onSome: (n) => e.where ? qr(e.where, Pr(t, n)) : Pr(t, n)
|
|
1252
1252
|
});
|
|
1253
1253
|
return {
|
|
1254
1254
|
table: e.table,
|
|
@@ -1263,19 +1263,19 @@ var ct = (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
|
+
}, li = (e, t) => {
|
|
1267
|
+
let n = t.pk ?? "id", r = t.chunkSize ?? si;
|
|
1268
|
+
return dt.paginateChunkEffect(T.none(), (i) => {
|
|
1269
|
+
let a = ut.tryPromise({
|
|
1270
|
+
try: () => e.query(ci(t, n, r, i)),
|
|
1271
|
+
catch: (e) => new oi({
|
|
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(ut.retry(t.retry)) : a).pipe(ut.map((e) => [ct.fromIterable(e), e.length === r && e.length > 0 ? T.some(T.some(e[e.length - 1][n])) : T.none()]));
|
|
1277
1277
|
});
|
|
1278
|
-
},
|
|
1278
|
+
}, ui = (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 ct = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1302
1302
|
}
|
|
1303
1303
|
};
|
|
1304
1304
|
};
|
|
1305
|
-
},
|
|
1305
|
+
}, di = 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
|
+
}, fi = (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",
|
|
1313
|
-
return
|
|
1312
|
+
let t = e.as ?? "embedding", n = (t) => di(e, t);
|
|
1313
|
+
return le({
|
|
1314
1314
|
id: "voltro/vectorEmbedding",
|
|
1315
|
-
fields: { [t]:
|
|
1315
|
+
fields: { [t]: je(e.dimensions) },
|
|
1316
1316
|
...e.index === !1 ? {} : { indexes: [{
|
|
1317
1317
|
fields: [t],
|
|
1318
1318
|
kind: "hnsw",
|
|
@@ -1323,23 +1323,23 @@ var ct = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1323
1323
|
} }
|
|
1324
1324
|
}] },
|
|
1325
1325
|
behaviors: {
|
|
1326
|
-
beforeInsert:
|
|
1327
|
-
beforeUpdate:
|
|
1326
|
+
beforeInsert: n,
|
|
1327
|
+
beforeUpdate: n
|
|
1328
1328
|
}
|
|
1329
1329
|
});
|
|
1330
|
-
},
|
|
1330
|
+
}, pi = 63, mi = "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
|
+
}, hi = (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 = gn(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 = `${mi}${t}_${n}`;
|
|
1340
|
+
if (r.length > pi) throw new J(`branch namespace '${r}' exceeds the ${pi}-byte identifier limit — use a shorter app slug`);
|
|
1341
1341
|
return r;
|
|
1342
|
-
},
|
|
1342
|
+
}, gi = (e) => e.startsWith(mi), _i = {
|
|
1343
1343
|
requested: {
|
|
1344
1344
|
provision: "provisioning",
|
|
1345
1345
|
destroy: "destroying"
|
|
@@ -1358,18 +1358,18 @@ var ct = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1358
1358
|
fail: "failed"
|
|
1359
1359
|
},
|
|
1360
1360
|
destroyed: {}
|
|
1361
|
-
},
|
|
1361
|
+
}, vi = 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
|
+
}, yi = (e, t) => {
|
|
1369
|
+
let n = _i[e][t];
|
|
1370
|
+
if (n === void 0) throw new vi(e, t);
|
|
1371
1371
|
return n;
|
|
1372
|
-
},
|
|
1372
|
+
}, bi = (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 ct = (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
|
+
}, xi = (e) => {
|
|
1394
|
+
if (!gi(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
|
+
}, Si = (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 ct = (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
|
+
}, Ci = (e) => e.prefer === void 0 ? e.seed === "copy" && Si(e.dbUrl) ? "neon-cow" : "namespace" : e.prefer, wi = (e, t = {}) => [{
|
|
1408
1408
|
kind: "neon-branch-create",
|
|
1409
1409
|
detail: `${t.parentBranch ?? "main"} → ${e} (copy-on-write)`
|
|
1410
|
-
}],
|
|
1411
|
-
if (!
|
|
1410
|
+
}], Ti = (e) => {
|
|
1411
|
+
if (!gi(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
|
+
}, Ei = (e) => e.mechanism === "neon-cow" ? wi(e.branchId, e.neonParentBranch === void 0 ? {} : { parentBranch: e.neonParentBranch }) : bi(e.branchId, e.tableNames, e.seed, e.parentNamespace), Di = (e, t) => e === "neon-cow" ? Ti(t) : xi(t), Oi = (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
|
+
}, ki = async (e, t) => {
|
|
1423
|
+
let n = hi(e.appSlug, e.prNumber), r = Ci({
|
|
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 = Ei({
|
|
1428
1428
|
mechanism: r,
|
|
1429
1429
|
branchId: n,
|
|
1430
1430
|
tableNames: e.tableNames,
|
|
@@ -1449,10 +1449,10 @@ var ct = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1449
1449
|
mechanism: r,
|
|
1450
1450
|
steps: i
|
|
1451
1451
|
};
|
|
1452
|
-
},
|
|
1453
|
-
let r =
|
|
1452
|
+
}, Ai = async (e, t, n) => {
|
|
1453
|
+
let r = Di(t, e);
|
|
1454
1454
|
return t === "neon-cow" ? await n.neonBranchDelete(e) : await n.dropNamespace(e), r;
|
|
1455
|
-
},
|
|
1455
|
+
}, ji = (e, t, n) => Oi(e, t, n), Y = (e) => `"${e.replace(/"/g, "\"\"")}"`, Mi = (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 ct = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1464
1464
|
neonBranchCreate: t,
|
|
1465
1465
|
neonBranchDelete: t
|
|
1466
1466
|
};
|
|
1467
|
-
},
|
|
1467
|
+
}, Ni = class extends Error {
|
|
1468
1468
|
_tag = "TenantResidencyUnresolved";
|
|
1469
1469
|
constructor(e) {
|
|
1470
1470
|
super(e), this.name = "TenantResidencyUnresolved";
|
|
1471
1471
|
}
|
|
1472
|
-
},
|
|
1472
|
+
}, Pi = 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
|
+
}, Fi, Ii = (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 ct = (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 Fi = e, e;
|
|
1488
|
+
}, Li = () => Fi, Ri = () => {
|
|
1489
|
+
Fi = void 0;
|
|
1490
|
+
}, zi = (e, t) => {
|
|
1491
|
+
if (e == null || e === "") throw new Ni("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 Ni(`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
|
+
}, Bi = (e, t) => t.servableRegions.includes(e), Vi = (e, t) => {
|
|
1496
|
+
let n = zi(e.tenantId, t), r = _n(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
|
+
}, Hi = (e, t, n) => {
|
|
1503
|
+
let r = Vi(e, t);
|
|
1504
|
+
if (!Bi(r.region, t)) throw new Pi(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 Pi(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
|
+
}, Ui = async (e, t, n, r) => {
|
|
1512
|
+
let { store: i, placement: a } = Hi(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 ct = (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), Wi = (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
|
+
}, Gi = (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
|
+
}, Ki = (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 (Wi(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 ct = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1543
1543
|
});
|
|
1544
1544
|
continue;
|
|
1545
1545
|
}
|
|
1546
|
-
|
|
1546
|
+
Gi(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
|
+
}) : Gi(e.fields, i.fields) && t.push({
|
|
1553
1553
|
kind: "redundant-prefix",
|
|
1554
1554
|
table: r,
|
|
1555
1555
|
redundant: e,
|
|
@@ -1559,23 +1559,23 @@ var ct = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1559
1559
|
}
|
|
1560
1560
|
}
|
|
1561
1561
|
return t;
|
|
1562
|
-
},
|
|
1562
|
+
}, qi = (e) => {
|
|
1563
1563
|
let t = [];
|
|
1564
|
-
for (let n of e) t.push(...
|
|
1564
|
+
for (let n of e) t.push(...Ki(n));
|
|
1565
1565
|
return t;
|
|
1566
|
-
},
|
|
1567
|
-
let n = t.color ?? !0, r = t.indent ?? " ", i = (e) => Q(n,
|
|
1566
|
+
}, Ji = "\x1B[", Yi = `${Ji}38;2;245;158;11m`, Xi = `${Ji}38;2;16;185;129m`, Zi = (e, t) => `${e}${t}${D.reset}`, Q = (e, t, n) => e ? typeof t == "function" ? t(n) : Zi(t, n) : n, Qi = (e, t = {}) => {
|
|
1567
|
+
let n = t.color ?? !0, r = t.indent ?? " ", i = (e) => Q(n, D.dim, e.padEnd(11)), a = (e) => Q(n, (e) => D.bold(D.brand(e)), e), o = (e) => Q(n, D.brightRed24, e), s = (e) => Q(n, Xi, e), c = (e) => Q(n, Yi, e), l = (e) => Q(n, D.dim, e), u = `${c("index audit")} ${l("·")} ${Q(n, D.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, D.bold, "both")} B-trees. Pure write overhead, zero read benefit.`), m.push(""), m.push(`${i("fix")}Drop ${o(e.redundant.name)}`), m.push(`${i("")}${l("Keep only if profiling shows the smaller index gives a")}`), m.push(`${i("")}${l("measurable cache-locality boost on a write-heavy hot path.")}`), m.push(`${i("")}${l("Silence with VOLTRO_INDEX_AUDIT=off if intentional.")}`), m.map((e) => `${r}${e}`).join("\n");
|
|
1572
|
+
}, $i = (e, t) => ({
|
|
1573
1573
|
name: e,
|
|
1574
1574
|
body: t
|
|
1575
|
-
}),
|
|
1575
|
+
}), ea = (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: $i });
|
|
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 ct = (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
|
+
}, ta = (e) => typeof e == "object" && !!e && "__seed" in e && e.__seed === !0, na = (e, { apply: t, undo: n }) => ({
|
|
1591
1591
|
name: e,
|
|
1592
1592
|
apply: t,
|
|
1593
1593
|
undo: n
|
|
1594
|
-
}),
|
|
1594
|
+
}), ra = (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: na });
|
|
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 ct = (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:
|
|
1604
|
+
}, ia = (e) => typeof e == "object" && !!e && "__migration" in e && e.__migration === !0, aa = f("_voltro_migrations", {
|
|
1605
|
+
id: x({ prefix: "mig" }),
|
|
1606
|
+
name: C(),
|
|
1607
|
+
hash: C(),
|
|
1608
|
+
status: C(),
|
|
1609
|
+
appliedAt: n().nullable(),
|
|
1610
1610
|
durationMs: w().nullable(),
|
|
1611
|
-
errorMessage:
|
|
1612
|
-
errorStack:
|
|
1613
|
-
workflowRunId:
|
|
1614
|
-
createdAt:
|
|
1615
|
-
updatedAt:
|
|
1616
|
-
}).index(["status"]).reactive(),
|
|
1617
|
-
id:
|
|
1618
|
-
name:
|
|
1619
|
-
lifecycle:
|
|
1620
|
-
fingerprint:
|
|
1621
|
-
cronSchedule:
|
|
1622
|
-
watchedTables:
|
|
1623
|
-
nextRunAt:
|
|
1624
|
-
lastRunStatus:
|
|
1625
|
-
lastRunAt:
|
|
1611
|
+
errorMessage: C().nullable(),
|
|
1612
|
+
errorStack: C().nullable(),
|
|
1613
|
+
workflowRunId: C().nullable(),
|
|
1614
|
+
createdAt: n().default("now"),
|
|
1615
|
+
updatedAt: n().default("now").onUpdate("now")
|
|
1616
|
+
}).index(["status"]).reactive(), oa = f("_voltro_seeds", {
|
|
1617
|
+
id: x({ prefix: "seed" }),
|
|
1618
|
+
name: C(),
|
|
1619
|
+
lifecycle: C(),
|
|
1620
|
+
fingerprint: C(),
|
|
1621
|
+
cronSchedule: C().nullable(),
|
|
1622
|
+
watchedTables: a().nullable(),
|
|
1623
|
+
nextRunAt: n().nullable(),
|
|
1624
|
+
lastRunStatus: C().nullable(),
|
|
1625
|
+
lastRunAt: n().nullable(),
|
|
1626
1626
|
lastRunDurationMs: w().nullable(),
|
|
1627
1627
|
lastRunRowsTouched: w().nullable(),
|
|
1628
|
-
lastError:
|
|
1629
|
-
workflowRunId:
|
|
1630
|
-
createdAt:
|
|
1631
|
-
updatedAt:
|
|
1632
|
-
}).index(["lifecycle"]).index(["nextRunAt"]).reactive(),
|
|
1633
|
-
id:
|
|
1634
|
-
fingerprint:
|
|
1635
|
-
operations:
|
|
1636
|
-
rollbackPlan:
|
|
1637
|
-
appliedBy:
|
|
1638
|
-
environment:
|
|
1639
|
-
source:
|
|
1640
|
-
onlineStrategy:
|
|
1628
|
+
lastError: C().nullable(),
|
|
1629
|
+
workflowRunId: C().nullable(),
|
|
1630
|
+
createdAt: n().default("now"),
|
|
1631
|
+
updatedAt: n().default("now").onUpdate("now")
|
|
1632
|
+
}).index(["lifecycle"]).index(["nextRunAt"]).reactive(), sa = f("_voltro_migration_plans", {
|
|
1633
|
+
id: x({ prefix: "plan" }),
|
|
1634
|
+
fingerprint: C(),
|
|
1635
|
+
operations: a(),
|
|
1636
|
+
rollbackPlan: a().nullable(),
|
|
1637
|
+
appliedBy: C(),
|
|
1638
|
+
environment: C(),
|
|
1639
|
+
source: C(),
|
|
1640
|
+
onlineStrategy: C().nullable(),
|
|
1641
1641
|
durationMs: w(),
|
|
1642
|
-
notes:
|
|
1643
|
-
squashedAt:
|
|
1644
|
-
appliedAt:
|
|
1645
|
-
createdAt:
|
|
1646
|
-
updatedAt:
|
|
1647
|
-
}).index(["fingerprint"]).index(["environment"]).reactive(),
|
|
1648
|
-
id:
|
|
1649
|
-
scope:
|
|
1650
|
-
key:
|
|
1651
|
-
status:
|
|
1652
|
-
response:
|
|
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:
|
|
1667
|
-
scopes:
|
|
1668
|
-
lastUsedAt:
|
|
1669
|
-
expiresAt:
|
|
1670
|
-
revokedAt:
|
|
1671
|
-
createdBy:
|
|
1672
|
-
createdAt:
|
|
1673
|
-
}).index("byTenant", ["tenantId"]).reactive(),
|
|
1674
|
-
ia,
|
|
1642
|
+
notes: C().nullable(),
|
|
1643
|
+
squashedAt: n().nullable(),
|
|
1644
|
+
appliedAt: n().default("now"),
|
|
1645
|
+
createdAt: n().default("now"),
|
|
1646
|
+
updatedAt: n().default("now").onUpdate("now")
|
|
1647
|
+
}).index(["fingerprint"]).index(["environment"]).reactive(), ca = f("_voltro_idempotency", {
|
|
1648
|
+
id: x({ prefix: "idem" }),
|
|
1649
|
+
scope: C(),
|
|
1650
|
+
key: C(),
|
|
1651
|
+
status: C(),
|
|
1652
|
+
response: a().nullable(),
|
|
1653
|
+
createdAt: n().default("now")
|
|
1654
|
+
}).unique(["scope", "key"]).index(["createdAt"]).reactive(), la = f("_voltro_kv", {
|
|
1655
|
+
id: x({ prefix: "kv" }),
|
|
1656
|
+
key: C().unique(),
|
|
1657
|
+
value: C().nullable(),
|
|
1658
|
+
expiresAt: n().nullable(),
|
|
1659
|
+
createdAt: n().default("now"),
|
|
1660
|
+
updatedAt: n().default("now").onUpdate("now")
|
|
1661
|
+
}).index(["expiresAt"]).reactive(), ua = f("_voltro_api_keys", {
|
|
1662
|
+
id: x({ prefix: "apikey" }),
|
|
1663
|
+
tenantId: C().nullable(),
|
|
1664
|
+
name: C(),
|
|
1665
|
+
hashedKey: C().unique(),
|
|
1666
|
+
keyPrefix: C(),
|
|
1667
|
+
scopes: a().nullable(),
|
|
1668
|
+
lastUsedAt: n().nullable(),
|
|
1669
|
+
expiresAt: n().nullable(),
|
|
1670
|
+
revokedAt: n().nullable(),
|
|
1671
|
+
createdBy: C().nullable(),
|
|
1672
|
+
createdAt: n().default("now")
|
|
1673
|
+
}).index("byTenant", ["tenantId"]).reactive(), da = [
|
|
1675
1674
|
aa,
|
|
1676
|
-
oa
|
|
1677
|
-
|
|
1675
|
+
oa,
|
|
1676
|
+
sa
|
|
1677
|
+
], $ = "id", fa = (e, t) => {
|
|
1678
1678
|
let n = u(e);
|
|
1679
1679
|
if (n === void 0) return t;
|
|
1680
1680
|
let r = n.fields[$]?.idScheme;
|
|
@@ -1684,58 +1684,58 @@ var ct = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqli
|
|
|
1684
1684
|
let e = { ...t };
|
|
1685
1685
|
return delete e[$], e;
|
|
1686
1686
|
}
|
|
1687
|
-
let i =
|
|
1687
|
+
let i = m(r, e);
|
|
1688
1688
|
return i === null ? t : {
|
|
1689
1689
|
...t,
|
|
1690
1690
|
[$]: i
|
|
1691
1691
|
};
|
|
1692
|
-
},
|
|
1692
|
+
}, pa = (e, t) => t.map((t) => fa(e, t)), ma = (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
|
-
e.nullable || e.hasDefault || e.idScheme !== void 0 || (r[t] === void 0 || r[t] === null) && n.push(t);
|
|
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
|
+
}, ha = (e, t) => {
|
|
1700
1700
|
let n = t;
|
|
1701
1701
|
return e.filter((e) => n[e] === void 0 || n[e] === null);
|
|
1702
|
-
},
|
|
1702
|
+
}, ga = (e, t, n) => e.insert(t.tableName, n), _a = (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
|
+
}), va = 512, ya = (e) => {
|
|
1706
1706
|
e.setMaxListeners(512);
|
|
1707
|
-
},
|
|
1707
|
+
}, ba = (e, t, n) => ({
|
|
1708
1708
|
_tag: "PrimaryKeyConflictError",
|
|
1709
1709
|
table: e,
|
|
1710
1710
|
key: t,
|
|
1711
1711
|
cause: n
|
|
1712
|
-
}),
|
|
1712
|
+
}), xa = (e) => typeof e == "object" && !!e && e._tag === "PrimaryKeyConflictError", Sa = /* @__PURE__ */ new Map(), Ca = (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
|
+
Sa.set(e.table, e);
|
|
1716
|
+
}, wa = () => [...Sa.values()], Ta = () => Sa.clear(), Ea = 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
|
+
}, Da = (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
|
+
}, Oa = "_voltro_cdc_offsets", ka = f(Oa, {
|
|
1727
|
+
id: x({ prefix: "cdcoff" }),
|
|
1728
|
+
replicaId: C(),
|
|
1729
|
+
streamName: C(),
|
|
1730
|
+
binlogFile: C(),
|
|
1731
|
+
binlogPosition: C(),
|
|
1732
|
+
updatedAt: n()
|
|
1733
|
+
}).index(["replicaId"]), Aa = f(Oa, {
|
|
1734
|
+
id: x({ prefix: "cdcoff" }),
|
|
1735
|
+
replicaId: C(),
|
|
1736
|
+
streamName: C(),
|
|
1737
|
+
ctVersion: C(),
|
|
1738
|
+
updatedAt: n()
|
|
1739
|
+
}).index(["replicaId"]), ja = "postgres";
|
|
1740
1740
|
//#endregion
|
|
1741
|
-
export { J as BranchNameInvalid,
|
|
1741
|
+
export { r as AUTO_FILLED_COLUMNS, J as BranchNameInvalid, vi as BranchTransitionInvalid, Oa as CDC_OFFSETS_TABLE, va as CHANGE_LISTENER_CEILING, Pe as ColumnBuilder, gt as ENCRYPTED_PREFIX, ja as ENGINE, en as EagerCardinalityError, Je as FILE_MIGRATION_PATTERN, _t as FieldDecryptionError, y as MAX_IDENTIFIER_LENGTH, oi as TableStreamError, pn as TenantNamespaceInvalid, fn as TenantNamespaceUnresolved, Pi as TenantRegionUnavailable, Ni as TenantResidencyUnresolved, e as WARN_IDENTIFIER_LENGTH, ua as _voltroApiKeysTable, ka as _voltroCdcOffsetsTable, ca as _voltroIdempotencyTable, la as _voltroKvTable, sa as _voltroMigrationPlansTable, aa as _voltroMigrationsTable, Aa as _voltroMssqlCdcOffsetsTable, oa as _voltroSeedsTable, jr as actorsTable, ji as admitBranch, ge as allEnumRenames, Ut as allRegisteredRelations, ee as allRegisteredTables, qr as and, Ze as array, Vr as arrayContains, Ur as arrayHas, Hr as arrayOverlaps, nn as attachEagerLoads, qi as auditAllTableIndexes, Ki as auditTableIndexes, Ne as avg, Xe as avgOver, xe as bigint, Hi as bindResidentStore, we as boolean, hi as branchNamespaceName, He as bytes, Be as clearEnumRenames, Gt as clearRelationsRegistry, Ri as clearResidencyConfig, Ta as clearRetentions, te as clearTableRegistry, ii as collectSubqueries, be as column, Ct as columnSchema, jn as compileEagerJson, P as compilePredicate, yn as compileRawFragment, F as compileSelect, di as computeEmbedding, Br as contains, Ce as count, Ve as countDistinct, Fe as databaseHandle, Ie as date, Oe as dbEnum, Ee as decimal, qe as declareEnumRename, Zt as decodeRowsFromSchema, St as decryptFieldsOnRead, ra as defineMigration, le as defineMixin, ea as defineSeed, De as denseRank, Ue as deriveTypeIdPrefix, ht as deserializeArraysOnRead, Se as drainIdentifierWarnings, me as dropped, $t as encodeRowForSchema, xt as encryptFieldsForWrite, bt as encryptedColumnsOf, Oi as enforceBranchLimits, v as ensureTableRegistered, Mr as eq, bn as escapeLike, ri as evaluatePredicate, Te as except, ei as exists, Qi as formatIndexAuditIssue, da as frameworkTables, m as generateId, ue as generateSnowflake, $e as geography, it as geometry, ye as getEnumRenames, Ht as getRelation, j as getRelations, Li as getResidencyConfig, u as getTable, Pr as gt, Fr as gte, dn as hasEagerLoads, ui as hybridSearch, x as id, Rr as inSet, Qr as inSubquery, O as inferForeignKey, ga as insertRow, w as integer, pe as intersect, ie as interval, gi as isBranchNamespace, yt as isEncrypted, vt as isFieldDecryptionError, Le as isFileMigration, ia as isMigrationDefinition, Si as isNeonConnection, Gr as isNotNull, Wr as isNull, xa as isPrimaryKeyConflictError, Bi as isRegionServable, jt as isRelationsSpec, ta as isSeedDefinition, re as isSqliteFamily, he as isView, a as json, Xr as jsonField, ce as jsonIndex, Qe as lag, rt as lead, wa as listRetentions, Ir as lt, Lr as lte, Mi as makeNamespaceBranchExecutor, Nt as many, Pt as manyToMany, tt as materializeFields, _e as max, We as migration, nt as min, ha as missingConflictColumns, ma as missingRequiredColumns, d as mixin, Nr as neq, yi as nextBranchState, Yr as not, ti as notExists, zr as notInSet, $r as notInSubquery, oe as numeric, Mt as one, tn as oneCardinalityMessage, Jr as or, b as paginateBy, i as paginateById, Ei as planBranch, bi as planBranchProvision, xi as planBranchTeardown, Di as planBranchTeardownFor, wi as planNeonBranchProvision, Ti as planNeonBranchTeardown, ba as primaryKeyConflictError, ki as provisionBranch, Ui as provisionResidentTenant, vn as qualifyTable, et as queryFor, ze as queryForView, at as quoteIdent, ya as raiseChangeListenerCeiling, ae as rank, l as raw, s as real, ne as reference, Dr as registerCoreTables, Vt as registerDiscoveredRelations, Bt as registerRelations, Ca as registerRetention, p as registerTable, At as relations, kr as requireActors, g as requireTable, Ar as requireTenants, fe as resetSnowflake, Vi as residentPlacement, Ci as resolveBranchMechanism, c as resolveFullTextIndex, de as resolveIdScheme, h as resolveMixinGraph, zi as resolveTenantHome, _n as resolveTenantNamespace, Da as retentionTtlMsFromEnv, o as rowNumber, wt as rowSchema, gn as sanitizeIdentifierFragment, mt as serializeArraysForWrite, Ii as setResidencyConfig, Kr as spatialPredicate, fa as stampGeneratedId, pa as stampGeneratedIds, li as streamTable, _ as sum, Me as sumOver, Ea as sweepRetention, f as table, Ai as teardownBranch, C as text, n as timestamp, ot as timestampMs, st as timestampMsOrNull, t as union, Ae as unionAll, _a as upsertRow, Ye as validateColumnName, Re as validateIndexName, Wt as validateRegisteredRelations, Lt as validateRelationConfig, Ge as validateTableName, ke as validateTypeIdPrefix, je as vector, se as vectorDistanceToOpclass, fi as vectorEmbedding, Ke as view, ve as viewSql, ai as walkLeaves };
|