@voltro/database 0.33.0 → 0.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1968 -0
- package/dist/{frameworkLiveTables-DbAgeVOU.js → frameworkLiveTables-CeuTYhWm.js} +159 -130
- package/dist/index.d.ts +807 -11
- package/dist/index.js +1011 -678
- package/dist/sql.d.ts +397 -28
- package/dist/sql.js +1316 -914
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { $ as e, A as t, At as n, B as r, Bt as i, C as a, Ct as o, D as s, Dt as c, E as l, Et as u, F as d, Ft as f, G as p,
|
|
2
|
-
import { timestampMs as
|
|
3
|
-
import { Cause as
|
|
4
|
-
import { AsyncLocalStorage as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { $ as e, A as t, At as n, B as r, Bt as i, C as a, Ct as o, D as s, Dt as c, E as l, Et as u, F as d, Ft as f, G as p, Gt as m, H as h, Ht as g, I as _, It as v, J as y, Jt as b, K as ee, Kt as x, L as te, Lt as S, M as ne, Mt as re, N as ie, Nt as ae, O as oe, Ot as se, P as ce, Pt as le, Q as ue, R as de, Rt as fe, S as pe, St as me, T as he, Tt as ge, U as _e, Ut as ve, V as ye, Vt as be, W as xe, Wt as Se, X as Ce, Y as we, Yt as Te, Z as Ee, _ as De, _t as Oe, a as ke, at as Ae, b as je, bt as Me, c as Ne, ct as Pe, d as Fe, dt as Ie, et as C, f as Le, ft as Re, g as ze, gt as Be, h as Ve, ht as He, i as Ue, it as We, j as w, jt as Ge, k as Ke, kt as qe, l as Je, lt as Ye, m as Xe, mt as Ze, n as Qe, nt as $e, o as et, ot as tt, p as T, pt as nt, q as rt, qt as E, rt as it, s as at, st as ot, t as st, tt as ct, u as lt, ut, v as dt, vt as ft, w as pt, wt as mt, x as ht, xt as gt, y as _t, yt as vt, z as yt, zt as D } from "./frameworkLiveTables-CeuTYhWm.js";
|
|
2
|
+
import { timestampMs as bt, timestampMsOrNull as xt } from "./wire.js";
|
|
3
|
+
import { Cause as St, Chunk as Ct, Data as wt, Effect as O, Exit as Tt, Metric as k, MetricBoundaries as Et, Option as A, Schedule as Dt, Schema as j, Stream as Ot } from "effect";
|
|
4
|
+
import { AsyncLocalStorage as kt } from "node:async_hooks";
|
|
5
|
+
import { TransactionConnection as At } from "@effect/sql/SqlClient";
|
|
6
|
+
import { ansi as M } from "@voltro/logger";
|
|
7
|
+
import { SqlClient as jt } from "@effect/sql";
|
|
8
|
+
import { createHash as Mt } from "node:crypto";
|
|
7
9
|
//#region src/actorSnapshot.ts
|
|
8
|
-
var
|
|
10
|
+
var Nt = (e) => typeof e == "string" && e !== "" ? e : null, Pt = async (e, t, n) => {
|
|
9
11
|
if (!(t == null || t === "")) try {
|
|
10
12
|
let r = (await e.query({
|
|
11
13
|
table: "actors",
|
|
@@ -21,20 +23,20 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
21
23
|
}))[0];
|
|
22
24
|
return r === void 0 ? void 0 : {
|
|
23
25
|
id: t,
|
|
24
|
-
type:
|
|
25
|
-
displayName:
|
|
26
|
-
email:
|
|
26
|
+
type: Nt(r.kind) ?? n,
|
|
27
|
+
displayName: Nt(r.displayName),
|
|
28
|
+
email: Nt(r.email)
|
|
27
29
|
};
|
|
28
30
|
} catch {
|
|
29
31
|
return;
|
|
30
32
|
}
|
|
31
|
-
},
|
|
33
|
+
}, Ft = (e) => e === "mysql" || e === "mariadb" || e === "mssql" || e === "sqlite", It = (e) => {
|
|
32
34
|
let t = [];
|
|
33
35
|
for (let [n, r] of Object.entries(e.fields)) r.type === "array" && t.push(n);
|
|
34
36
|
return t;
|
|
35
|
-
},
|
|
36
|
-
if (!
|
|
37
|
-
let r =
|
|
37
|
+
}, Lt = (e, t, n) => {
|
|
38
|
+
if (!Ft(n) || !t) return e;
|
|
39
|
+
let r = It(t);
|
|
38
40
|
if (r.length === 0) return e;
|
|
39
41
|
let i = { ...e };
|
|
40
42
|
for (let e of r) {
|
|
@@ -42,9 +44,9 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
42
44
|
Array.isArray(t) && (i[e] = JSON.stringify(t));
|
|
43
45
|
}
|
|
44
46
|
return i;
|
|
45
|
-
},
|
|
46
|
-
if (!
|
|
47
|
-
let r =
|
|
47
|
+
}, Rt = (e, t, n) => {
|
|
48
|
+
if (!Ft(n) || !t) return e;
|
|
49
|
+
let r = It(t);
|
|
48
50
|
return r.length === 0 ? e : e.map((e) => {
|
|
49
51
|
let t;
|
|
50
52
|
for (let n of r) {
|
|
@@ -56,7 +58,7 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
56
58
|
}
|
|
57
59
|
return t ?? e;
|
|
58
60
|
});
|
|
59
|
-
},
|
|
61
|
+
}, zt = "enc:v1:", Bt = class extends Error {
|
|
60
62
|
_tag = "FieldDecryptionError";
|
|
61
63
|
table;
|
|
62
64
|
column;
|
|
@@ -64,33 +66,33 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
64
66
|
constructor(e) {
|
|
65
67
|
super(`column "${e.table}.${e.column}" is .encrypted() but could not be decrypted (${e.reason}) — the stored value was most likely encrypted under a different key`), this.name = "FieldDecryptionError", this.table = e.table, this.column = e.column, this.reason = e.reason;
|
|
66
68
|
}
|
|
67
|
-
},
|
|
69
|
+
}, Vt = (e) => typeof e == "object" && !!e && e._tag === "FieldDecryptionError", Ht = (e) => typeof e == "string" && e.startsWith("enc:v1:"), Ut = (e) => {
|
|
68
70
|
let t = [];
|
|
69
71
|
for (let [n, r] of Object.entries(e.fields)) r.encrypted === !0 && t.push(n);
|
|
70
72
|
return t;
|
|
71
|
-
},
|
|
73
|
+
}, Wt = (e, t, n) => {
|
|
72
74
|
if (!t) return e;
|
|
73
|
-
let r =
|
|
75
|
+
let r = Ut(t);
|
|
74
76
|
if (r.length === 0) return e;
|
|
75
77
|
let i = { ...e };
|
|
76
78
|
for (let e of r) {
|
|
77
79
|
let r = i[e];
|
|
78
|
-
if (!(r == null ||
|
|
80
|
+
if (!(r == null || Ht(r))) {
|
|
79
81
|
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)`);
|
|
80
82
|
i[e] = n.encrypt(JSON.stringify(r));
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
85
|
return i;
|
|
84
|
-
},
|
|
86
|
+
}, Gt = (e, t, n, r) => {
|
|
85
87
|
if (!t) return e;
|
|
86
|
-
let i =
|
|
88
|
+
let i = Ut(t);
|
|
87
89
|
if (i.length === 0 || !n) return e;
|
|
88
90
|
let a = r?.onError ?? "throw", o = t.tableName ?? "?";
|
|
89
91
|
return e.map((e) => {
|
|
90
92
|
let t;
|
|
91
93
|
for (let s of i) {
|
|
92
94
|
let i = e[s];
|
|
93
|
-
if (
|
|
95
|
+
if (Ht(i)) {
|
|
94
96
|
t ??= { ...e };
|
|
95
97
|
try {
|
|
96
98
|
t[s] = JSON.parse(n.decrypt(i));
|
|
@@ -104,7 +106,7 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
104
106
|
});
|
|
105
107
|
continue;
|
|
106
108
|
}
|
|
107
|
-
throw new
|
|
109
|
+
throw new Bt({
|
|
108
110
|
table: o,
|
|
109
111
|
column: s,
|
|
110
112
|
reason: n
|
|
@@ -114,62 +116,62 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
114
116
|
}
|
|
115
117
|
return t ?? e;
|
|
116
118
|
});
|
|
117
|
-
},
|
|
119
|
+
}, Kt = (e) => {
|
|
118
120
|
let t = (() => {
|
|
119
121
|
switch (e.type) {
|
|
120
122
|
case "id":
|
|
121
123
|
case "reference":
|
|
122
124
|
case "text":
|
|
123
|
-
case "enum": return
|
|
125
|
+
case "enum": return j.String;
|
|
124
126
|
case "integer":
|
|
125
127
|
case "real":
|
|
126
|
-
case "decimal": return
|
|
127
|
-
case "boolean": return
|
|
128
|
+
case "decimal": return j.Number;
|
|
129
|
+
case "boolean": return j.Boolean;
|
|
128
130
|
case "timestamp":
|
|
129
|
-
case "date": return
|
|
130
|
-
case "bigint": return
|
|
131
|
-
case "bytes": return
|
|
132
|
-
case "array": return
|
|
133
|
-
case "interval": return
|
|
134
|
-
default: return
|
|
131
|
+
case "date": return bt;
|
|
132
|
+
case "bigint": return j.BigInt;
|
|
133
|
+
case "bytes": return j.Uint8ArrayFromBase64;
|
|
134
|
+
case "array": return j.Array(j.Unknown);
|
|
135
|
+
case "interval": return j.String;
|
|
136
|
+
default: return j.Unknown;
|
|
135
137
|
}
|
|
136
138
|
})();
|
|
137
|
-
return e.nullable === !0 ?
|
|
138
|
-
},
|
|
139
|
+
return e.nullable === !0 ? j.NullOr(t) : t;
|
|
140
|
+
}, qt = (e, t) => {
|
|
139
141
|
let n = new Set(t?.omit ?? []), r = {};
|
|
140
|
-
for (let [t, i] of Object.entries(e.fields)) n.has(t) || (r[t] =
|
|
141
|
-
return
|
|
142
|
-
},
|
|
142
|
+
for (let [t, i] of Object.entries(e.fields)) n.has(t) || (r[t] = Kt(i));
|
|
143
|
+
return j.Struct(r);
|
|
144
|
+
}, Jt = (e) => typeof e == "function" ? e : () => e, Yt = (e, t) => ({
|
|
143
145
|
kind: "one",
|
|
144
|
-
target:
|
|
146
|
+
target: Jt(e),
|
|
145
147
|
...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
|
|
146
148
|
...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
|
|
147
|
-
}),
|
|
149
|
+
}), Xt = (e, t) => ({
|
|
148
150
|
kind: "many",
|
|
149
|
-
target:
|
|
151
|
+
target: Jt(e),
|
|
150
152
|
...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
|
|
151
153
|
...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
|
|
152
|
-
}),
|
|
154
|
+
}), Zt = (e, t) => ({
|
|
153
155
|
kind: "manyToMany",
|
|
154
|
-
target:
|
|
155
|
-
through:
|
|
156
|
+
target: Jt(e),
|
|
157
|
+
through: Jt(t.through),
|
|
156
158
|
sourceKey: t.sourceKey,
|
|
157
159
|
targetKey: t.targetKey
|
|
158
|
-
}),
|
|
159
|
-
one:
|
|
160
|
-
many:
|
|
161
|
-
manyToMany:
|
|
162
|
-
},
|
|
160
|
+
}), Qt = {
|
|
161
|
+
one: Yt,
|
|
162
|
+
many: Xt,
|
|
163
|
+
manyToMany: Zt
|
|
164
|
+
}, $t = (e, t) => {
|
|
163
165
|
let n = typeof e == "function" ? e : () => e;
|
|
164
166
|
return {
|
|
165
167
|
source: n,
|
|
166
|
-
relations: t(
|
|
168
|
+
relations: t(Qt, n())
|
|
167
169
|
};
|
|
168
|
-
},
|
|
170
|
+
}, en = (e) => {
|
|
169
171
|
if (typeof e != "object" || !e) return !1;
|
|
170
172
|
let t = e;
|
|
171
173
|
return typeof t.source != "function" || typeof t.relations != "object" || t.relations === null ? !1 : Object.keys(t.relations).length === 0;
|
|
172
|
-
},
|
|
174
|
+
}, tn = (e) => {
|
|
173
175
|
if (typeof e != "object" || !e) return !1;
|
|
174
176
|
let t = e;
|
|
175
177
|
if (typeof t.source != "function" || typeof t.relations != "object" || t.relations === null) return !1;
|
|
@@ -178,35 +180,35 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
178
180
|
let t = e?.kind;
|
|
179
181
|
return t === "one" || t === "many" || t === "manyToMany";
|
|
180
182
|
});
|
|
181
|
-
},
|
|
183
|
+
}, nn = Yt, rn = Xt, an = Zt, on = (e, t, n) => {
|
|
182
184
|
let r = [];
|
|
183
185
|
for (let [n, i] of Object.entries(e.fields)) i.type === "reference" && i.references?.()?.tableName === t && r.push(n);
|
|
184
186
|
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>' }.`);
|
|
185
187
|
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.`);
|
|
186
188
|
return r[0];
|
|
187
|
-
},
|
|
188
|
-
let t =
|
|
189
|
+
}, sn = (e) => Object.keys(e.fields), N = (e, t) => Object.prototype.hasOwnProperty.call(e.fields, t), cn = (e) => {
|
|
190
|
+
let t = sn(e);
|
|
189
191
|
return t.length === 0 ? "<none>" : t.join(", ");
|
|
190
|
-
},
|
|
192
|
+
}, ln = (e, t, n) => {
|
|
191
193
|
let r = `relation '${t}' on '${e.tableName}'`, i = n.target();
|
|
192
194
|
if (n.kind === "manyToMany") {
|
|
193
195
|
let t = n.through();
|
|
194
|
-
for (let [a, o] of [["sourceKey", n.sourceKey], ["targetKey", n.targetKey]]) if (!
|
|
196
|
+
for (let [a, o] of [["sourceKey", n.sourceKey], ["targetKey", n.targetKey]]) if (!N(t, o)) throw Error(`${r}: manyToMany ${a} '${o}' is not a column on the junction table '${t.tableName}'. Both keys name columns on the JUNCTION — ${a === "sourceKey" ? `sourceKey points at '${e.tableName}'` : `targetKey points at '${i.tableName}'`}. Columns on '${t.tableName}': ${cn(t)}.`);
|
|
195
197
|
return;
|
|
196
198
|
}
|
|
197
199
|
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.`);
|
|
198
|
-
if (n.sourceKey !== void 0 && !
|
|
199
|
-
let t =
|
|
200
|
-
throw Error(`${r}: sourceKey '${n.sourceKey}' is not a column on the source table '${e.tableName}'.` + (t ? ` It IS a column on the target '${i.tableName}' — you probably want { foreignKey: '${n.sourceKey}' }, which names the column on the TARGET that holds this table's id.` : ` Columns on '${e.tableName}': ${
|
|
200
|
+
if (n.sourceKey !== void 0 && !N(e, n.sourceKey)) {
|
|
201
|
+
let t = N(i, n.sourceKey);
|
|
202
|
+
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}': ${cn(e)}.`));
|
|
201
203
|
}
|
|
202
|
-
if (n.foreignKey !== void 0 && !
|
|
203
|
-
let t =
|
|
204
|
-
throw Error(`${r}: foreignKey '${n.foreignKey}' is not a column on the target table '${i.tableName}'.` + (t ? ` It IS a column on the source '${e.tableName}' — you want { sourceKey: '${n.foreignKey}' }. foreignKey names the column on the TARGET that points back at this table; sourceKey names the column on THIS table that holds the target's id.` : ` Columns on '${i.tableName}': ${
|
|
204
|
+
if (n.foreignKey !== void 0 && !N(i, n.foreignKey)) {
|
|
205
|
+
let t = N(e, n.foreignKey);
|
|
206
|
+
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}': ${cn(i)}.`));
|
|
205
207
|
}
|
|
206
|
-
},
|
|
207
|
-
let t = e.source(), n =
|
|
208
|
+
}, un = Symbol.for("@voltro/database/relationsRegistry"), dn = globalThis, P = dn[un] ?? (dn[un] = /* @__PURE__ */ new Map()), fn = (e) => {
|
|
209
|
+
let t = e.source(), n = P.get(t.tableName);
|
|
208
210
|
if (n === void 0) {
|
|
209
|
-
|
|
211
|
+
P.set(t.tableName, new Map(Object.entries(e.relations)));
|
|
210
212
|
return;
|
|
211
213
|
}
|
|
212
214
|
for (let [r, i] of Object.entries(e.relations)) {
|
|
@@ -216,29 +218,147 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
216
218
|
n.set(r, i);
|
|
217
219
|
}
|
|
218
220
|
}
|
|
219
|
-
},
|
|
221
|
+
}, pn = (e) => {
|
|
220
222
|
let t = 0;
|
|
221
|
-
for (let n of Object.values(e))
|
|
223
|
+
for (let n of Object.values(e)) tn(n) && (fn(n), t += 1);
|
|
222
224
|
return t;
|
|
223
|
-
},
|
|
224
|
-
let t =
|
|
225
|
+
}, mn = (e) => {
|
|
226
|
+
let t = P.get(e);
|
|
225
227
|
if (t !== void 0) return Object.fromEntries(t);
|
|
226
|
-
},
|
|
228
|
+
}, hn = (e, t) => P.get(e)?.get(t), gn = () => {
|
|
227
229
|
let e = [];
|
|
228
|
-
for (let [t, n] of
|
|
230
|
+
for (let [t, n] of P) for (let [r, i] of n) e.push({
|
|
229
231
|
source: t,
|
|
230
232
|
name: r,
|
|
231
233
|
relation: i
|
|
232
234
|
});
|
|
233
235
|
return e;
|
|
234
|
-
},
|
|
235
|
-
for (let [e, t] of
|
|
236
|
-
let n =
|
|
237
|
-
if (n !== void 0) for (let [e, r] of t)
|
|
238
|
-
}
|
|
239
|
-
},
|
|
240
|
-
|
|
241
|
-
},
|
|
236
|
+
}, _n = () => {
|
|
237
|
+
for (let [e, t] of P) {
|
|
238
|
+
let n = p(e);
|
|
239
|
+
if (n !== void 0) for (let [e, r] of t) ln(n, e, r);
|
|
240
|
+
}
|
|
241
|
+
}, vn = () => {
|
|
242
|
+
P.clear();
|
|
243
|
+
}, yn = 4, bn = (e) => Object.keys(e.fields), xn = (e, t) => Object.prototype.hasOwnProperty.call(e.fields, t), Sn = (e, t) => {
|
|
244
|
+
let n = [];
|
|
245
|
+
for (let [r, i] of Object.entries(e.fields)) i.type === "reference" && i.references?.()?.tableName === t && n.push(r);
|
|
246
|
+
return n;
|
|
247
|
+
}, Cn = (e, t) => {
|
|
248
|
+
let n = [];
|
|
249
|
+
for (let r of t) {
|
|
250
|
+
if (r.source !== e) continue;
|
|
251
|
+
let t = r.relation, i;
|
|
252
|
+
try {
|
|
253
|
+
i = t.target();
|
|
254
|
+
} catch {
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
if (t.kind === "manyToMany") {
|
|
258
|
+
let e;
|
|
259
|
+
try {
|
|
260
|
+
e = t.through();
|
|
261
|
+
} catch {
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
if (!xn(e, t.sourceKey)) continue;
|
|
265
|
+
n.push({
|
|
266
|
+
table: e.tableName,
|
|
267
|
+
foreignKey: t.sourceKey,
|
|
268
|
+
parentKey: "id"
|
|
269
|
+
});
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
if (t.sourceKey !== void 0) continue;
|
|
273
|
+
let a = Sn(i, e), o = t.foreignKey ?? (a.length === 1 ? a[0] : void 0);
|
|
274
|
+
o === void 0 || !xn(i, o) || n.push({
|
|
275
|
+
table: i.tableName,
|
|
276
|
+
foreignKey: o,
|
|
277
|
+
parentKey: "id"
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
return n;
|
|
281
|
+
}, wn = (e, t) => {
|
|
282
|
+
let n = [];
|
|
283
|
+
for (let r of t) if (r.tableName !== e) for (let t of Sn(r, e)) n.push({
|
|
284
|
+
table: r.tableName,
|
|
285
|
+
foreignKey: t,
|
|
286
|
+
parentKey: "id"
|
|
287
|
+
});
|
|
288
|
+
return n;
|
|
289
|
+
}, Tn = (e) => `${e.table}\u0000${e.hops.map((e) => `${e.table}.${e.foreignKey}<-${e.parentKey}`).join("|")}`, En = (e) => {
|
|
290
|
+
let t = e.tables ?? h(), n = e.relations ?? gn(), r = e.maxDepth ?? 4, i = new Set(e.exclude ?? []), a = new Map(t.map((e) => [e.tableName, e])), o = [];
|
|
291
|
+
if (!a.has(e.subjectTable)) return {
|
|
292
|
+
subjectTable: e.subjectTable,
|
|
293
|
+
paths: [],
|
|
294
|
+
limitations: [{
|
|
295
|
+
kind: "unreachable",
|
|
296
|
+
table: e.subjectTable,
|
|
297
|
+
detail: `the subject table '${e.subjectTable}' is not registered — no schema was loaded, or the name is wrong. Registered: ${t.length === 0 ? "<none>" : t.map((e) => e.tableName).join(", ")}`
|
|
298
|
+
}]
|
|
299
|
+
};
|
|
300
|
+
let s = {
|
|
301
|
+
table: e.subjectTable,
|
|
302
|
+
hops: [],
|
|
303
|
+
depth: 0,
|
|
304
|
+
via: "relation"
|
|
305
|
+
}, c = [s], l = /* @__PURE__ */ new Set([Tn(s)]), u = /* @__PURE__ */ new Set(), d = [s];
|
|
306
|
+
for (let e = 1; e <= r; e++) {
|
|
307
|
+
let r = [];
|
|
308
|
+
for (let a of d) {
|
|
309
|
+
let s = Cn(a.table, n), d = wn(a.table, t), f = [...s.map((e) => [e, "relation"]), ...d.map((e) => [e, "reference"])];
|
|
310
|
+
for (let [t, n] of f) {
|
|
311
|
+
if (i.has(t.table)) {
|
|
312
|
+
o.push({
|
|
313
|
+
kind: "excluded",
|
|
314
|
+
table: t.table,
|
|
315
|
+
detail: `excluded by configuration (reached from '${a.table}')`
|
|
316
|
+
});
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
let s = `${t.table}\u0000${t.foreignKey}`;
|
|
320
|
+
if (u.has(s)) continue;
|
|
321
|
+
u.add(s);
|
|
322
|
+
let d = {
|
|
323
|
+
table: t.table,
|
|
324
|
+
hops: [...a.hops, t],
|
|
325
|
+
depth: e,
|
|
326
|
+
via: n
|
|
327
|
+
}, f = Tn(d);
|
|
328
|
+
l.has(f) || (l.add(f), c.push(d), r.push(d));
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
if (r.length === 0) {
|
|
332
|
+
d = [];
|
|
333
|
+
break;
|
|
334
|
+
}
|
|
335
|
+
d = r;
|
|
336
|
+
}
|
|
337
|
+
for (let e of d) (Cn(e.table, n).length > 0 || wn(e.table, t).length > 0) && o.push({
|
|
338
|
+
kind: "depth-truncated",
|
|
339
|
+
table: e.table,
|
|
340
|
+
detail: `stopped at maxDepth ${r}; tables linked FROM '${e.table}' were not explored`
|
|
341
|
+
});
|
|
342
|
+
let f = new Set(c.map((e) => e.table));
|
|
343
|
+
for (let n of t) f.has(n.tableName) || i.has(n.tableName) || o.push({
|
|
344
|
+
kind: "unreachable",
|
|
345
|
+
table: n.tableName,
|
|
346
|
+
detail: `no relation() and no reference() column links '${n.tableName}' to '${e.subjectTable}'. If it holds subject data through a plain column, a polymorphic (type,id) pair, JSON or free text, add an explicit subjectScopes entry — this derivation cannot see it. Columns: ${bn(n).join(", ")}`
|
|
347
|
+
});
|
|
348
|
+
return {
|
|
349
|
+
subjectTable: e.subjectTable,
|
|
350
|
+
paths: c,
|
|
351
|
+
limitations: o
|
|
352
|
+
};
|
|
353
|
+
}, Dn = (e) => {
|
|
354
|
+
let t = [`subject graph · ${e.subjectTable} · ${e.paths.length} table(s) reachable`];
|
|
355
|
+
for (let n of e.paths) {
|
|
356
|
+
let r = n.hops.length === 0 ? `${e.subjectTable} (the subject row itself)` : [e.subjectTable, ...n.hops.map((e) => `${e.table}.${e.foreignKey}`)].join(" → ");
|
|
357
|
+
t.push(` • ${n.table} [depth ${n.depth}, via ${n.via}]`), t.push(` ${r}`);
|
|
358
|
+
}
|
|
359
|
+
let n = e.limitations.filter((e) => e.kind === "depth-truncated"), r = e.limitations.filter((e) => e.kind === "unreachable"), i = e.limitations.filter((e) => e.kind === "excluded");
|
|
360
|
+
return t.push(""), t.push(" WHAT THIS CANNOT SEE — a DSAR is only as complete as this list is short:"), n.length > 0 && t.push(` depth-truncated (${n.length}): ${n.map((e) => e.table).join(", ")}`), i.length > 0 && t.push(` excluded (${i.length}): ${[...new Set(i.map((e) => e.table))].join(", ")}`), t.push(r.length === 0 ? " unreachable: none — every registered table is linked to the subject." : ` unreachable (${r.length}): ${r.map((e) => e.table).join(", ")}`), t.push(" Always outside this graph: object storage / uploaded files, external processors,"), t.push(" log and metric sinks, backups, and any subject id embedded in JSON or free text."), t.join("\n");
|
|
361
|
+
}, On = (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, kn = (e) => {
|
|
242
362
|
if (e == null || typeof e != "string") return e;
|
|
243
363
|
let t = e.trim();
|
|
244
364
|
if (t.length === 0) return e;
|
|
@@ -249,7 +369,7 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
249
369
|
} catch {
|
|
250
370
|
return e;
|
|
251
371
|
}
|
|
252
|
-
},
|
|
372
|
+
}, An = (e) => e == null || typeof e == "string" ? e : typeof e == "number" || typeof e == "bigint" ? String(e) : e, jn = (e) => {
|
|
253
373
|
if (e == null || e instanceof Date) return e;
|
|
254
374
|
if (typeof e == "string") {
|
|
255
375
|
let t = new Date(e);
|
|
@@ -260,21 +380,21 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
260
380
|
return isNaN(t.getTime()) ? e : t;
|
|
261
381
|
}
|
|
262
382
|
return e;
|
|
263
|
-
},
|
|
383
|
+
}, Mn = (e, t, n) => {
|
|
264
384
|
if (e == null) return e;
|
|
265
385
|
switch (t) {
|
|
266
|
-
case "boolean": return n === "postgres" ? e :
|
|
386
|
+
case "boolean": return n === "postgres" ? e : On(e);
|
|
267
387
|
case "json":
|
|
268
|
-
case "array": return n === "postgres" ? e :
|
|
388
|
+
case "array": return n === "postgres" ? e : kn(e);
|
|
269
389
|
case "timestamp":
|
|
270
|
-
case "date": return n === "sqlite" || n === "turso" ?
|
|
390
|
+
case "date": return n === "sqlite" || n === "turso" ? jn(e) : e;
|
|
271
391
|
case "decimal":
|
|
272
|
-
case "bigint": return
|
|
392
|
+
case "bigint": return An(e);
|
|
273
393
|
default: return e;
|
|
274
394
|
}
|
|
275
|
-
},
|
|
395
|
+
}, Nn = (e, t, n) => {
|
|
276
396
|
if (e.length === 0) return e;
|
|
277
|
-
let r =
|
|
397
|
+
let r = p(t);
|
|
278
398
|
if (r === void 0) return e;
|
|
279
399
|
let i = r.fields, a = [];
|
|
280
400
|
for (let [e, t] of Object.entries(i)) a.push({
|
|
@@ -283,36 +403,36 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
283
403
|
});
|
|
284
404
|
return e.map((e) => {
|
|
285
405
|
let t = { ...e };
|
|
286
|
-
for (let { key: e, type: r } of a) e in t && (t[e] =
|
|
406
|
+
for (let { key: e, type: r } of a) e in t && (t[e] = Mn(t[e], r, n));
|
|
287
407
|
return t;
|
|
288
408
|
});
|
|
289
|
-
},
|
|
409
|
+
}, Pn = (e, t) => {
|
|
290
410
|
if (e == null) return e;
|
|
291
411
|
switch (t) {
|
|
292
412
|
case "json":
|
|
293
413
|
case "array": return typeof e == "string" ? e : JSON.stringify(e);
|
|
294
414
|
default: return e;
|
|
295
415
|
}
|
|
296
|
-
},
|
|
297
|
-
let r =
|
|
416
|
+
}, Fn = (e, t, n = ["json", "array"]) => {
|
|
417
|
+
let r = p(t);
|
|
298
418
|
if (r === void 0) return e;
|
|
299
419
|
let i = r.fields, a = null;
|
|
300
420
|
for (let [t, r] of Object.entries(i)) if (n.includes(r.type) && t in e) {
|
|
301
|
-
let n =
|
|
421
|
+
let n = Pn(e[t], r.type);
|
|
302
422
|
n !== e[t] && (a === null && (a = { ...e }), a[t] = n);
|
|
303
423
|
}
|
|
304
424
|
return a ?? e;
|
|
305
|
-
},
|
|
425
|
+
}, In = class extends Error {
|
|
306
426
|
_tag = "EagerCardinalityError";
|
|
307
427
|
constructor(e) {
|
|
308
428
|
super(e), this.name = "EagerCardinalityError";
|
|
309
429
|
}
|
|
310
|
-
},
|
|
430
|
+
}, Ln = (e) => {
|
|
311
431
|
let { relationName: t, sourceTableName: n, targetTableName: r, foreignKey: i, sourceKey: a } = e, o = r === n;
|
|
312
432
|
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.");
|
|
313
|
-
},
|
|
433
|
+
}, Rn = async (e, t, n, r) => {
|
|
314
434
|
if (e.length === 0) return e;
|
|
315
|
-
let i =
|
|
435
|
+
let i = mn(n.tableName);
|
|
316
436
|
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?`);
|
|
317
437
|
let a = e.map((e) => ({ ...e }));
|
|
318
438
|
for (let [e, o] of Object.entries(t)) {
|
|
@@ -321,36 +441,36 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
321
441
|
let t = Object.keys(i).join(", ") || "<none>";
|
|
322
442
|
throw Error(`unknown relation '${e}' on '${n.tableName}'. Registered relations: ${t}.`);
|
|
323
443
|
}
|
|
324
|
-
|
|
444
|
+
ln(n, e, t), await zn(a, e, t, o === !0 ? {} : o, n, r);
|
|
325
445
|
}
|
|
326
446
|
return a;
|
|
327
|
-
},
|
|
447
|
+
}, zn = async (e, t, n, r, i, a) => {
|
|
328
448
|
switch (n.kind) {
|
|
329
449
|
case "one":
|
|
330
|
-
await
|
|
450
|
+
await Bn(e, t, n, r, i, a);
|
|
331
451
|
return;
|
|
332
452
|
case "many":
|
|
333
|
-
await
|
|
453
|
+
await Vn(e, t, n, r, i, a);
|
|
334
454
|
return;
|
|
335
455
|
case "manyToMany":
|
|
336
|
-
await
|
|
456
|
+
await Un(e, t, n, r, i, a);
|
|
337
457
|
return;
|
|
338
458
|
}
|
|
339
|
-
},
|
|
340
|
-
let o = n.target(), s = n.sourceKey ??
|
|
459
|
+
}, Bn = async (e, t, n, r, i, a) => {
|
|
460
|
+
let o = n.target(), s = n.sourceKey ?? Wn(i, o.tableName);
|
|
341
461
|
if (s !== void 0) {
|
|
342
|
-
let n =
|
|
462
|
+
let n = Gn(e, s), i = n.length === 0 ? [] : await Kn(o, "id", n, r, a), c = new Map(i.map((e) => [e.id, e]));
|
|
343
463
|
for (let n of e) {
|
|
344
464
|
let e = n[s];
|
|
345
465
|
n[t] = e == null ? null : c.get(e) ?? null;
|
|
346
466
|
}
|
|
347
|
-
await
|
|
467
|
+
await qn(i, r.with, o, a);
|
|
348
468
|
return;
|
|
349
469
|
}
|
|
350
|
-
let c = n.foreignKey ??
|
|
470
|
+
let c = n.foreignKey ?? on(o, i.tableName, t), l = n.sourceKey ?? "id", u = Gn(e, l), d = u.length === 0 ? [] : await Kn(o, c, u, r, a), f = /* @__PURE__ */ new Map();
|
|
351
471
|
for (let e of d) {
|
|
352
472
|
let n = e[c];
|
|
353
|
-
if (f.has(n)) throw new
|
|
473
|
+
if (f.has(n)) throw new In(Ln({
|
|
354
474
|
relationName: t,
|
|
355
475
|
sourceTableName: i.tableName,
|
|
356
476
|
targetTableName: o.tableName,
|
|
@@ -363,9 +483,9 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
363
483
|
let e = n[l];
|
|
364
484
|
n[t] = e == null ? null : f.get(e) ?? null;
|
|
365
485
|
}
|
|
366
|
-
await
|
|
367
|
-
},
|
|
368
|
-
let o = n.target(), s = n.foreignKey ??
|
|
486
|
+
await qn(d, r.with, o, a);
|
|
487
|
+
}, Vn = async (e, t, n, r, i, a) => {
|
|
488
|
+
let o = n.target(), s = n.foreignKey ?? on(o, i.tableName, t), c = n.sourceKey ?? "id", l = Gn(e, c), u = Hn(r), d = l.length === 0 ? [] : await Kn(o, s, l, u, a), f = /* @__PURE__ */ new Map();
|
|
369
489
|
for (let e of d) {
|
|
370
490
|
let t = e[s], n = f.get(t);
|
|
371
491
|
n ? n.push(e) : f.set(t, [e]);
|
|
@@ -381,12 +501,12 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
381
501
|
let e = n[c];
|
|
382
502
|
n[t] = f.get(e) ?? [];
|
|
383
503
|
}
|
|
384
|
-
await
|
|
385
|
-
},
|
|
504
|
+
await qn(d, r.with, o, a);
|
|
505
|
+
}, Hn = (e) => {
|
|
386
506
|
let { limit: t, offset: n, ...r } = e;
|
|
387
507
|
return r;
|
|
388
|
-
},
|
|
389
|
-
let o = n.target(), s = n.through(), c =
|
|
508
|
+
}, Un = async (e, t, n, r, i, a) => {
|
|
509
|
+
let o = n.target(), s = n.through(), c = Gn(e, "id");
|
|
390
510
|
if (c.length === 0) {
|
|
391
511
|
for (let n of e) n[t] = [];
|
|
392
512
|
return;
|
|
@@ -407,8 +527,8 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
407
527
|
for (let n of e) n[t] = [];
|
|
408
528
|
return;
|
|
409
529
|
}
|
|
410
|
-
let f = await
|
|
411
|
-
await
|
|
530
|
+
let f = await Kn(o, "id", Gn(d, n.targetKey), r, a), p = new Map(f.map((e) => [e.id, e]));
|
|
531
|
+
await qn(f, r.with, o, a);
|
|
412
532
|
let m = r.junction === void 0 ? void 0 : r.junction === !0 ? Object.keys(s.fields) : r.junction, h = /* @__PURE__ */ new Map();
|
|
413
533
|
for (let e of d) {
|
|
414
534
|
let t = e[n.sourceKey], r = e[n.targetKey], i = p.get(r);
|
|
@@ -420,16 +540,16 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
420
540
|
o ? o.push(a) : h.set(t, [a]);
|
|
421
541
|
}
|
|
422
542
|
for (let n of e) n[t] = h.get(n.id) ?? [];
|
|
423
|
-
},
|
|
543
|
+
}, Wn = (e, t) => {
|
|
424
544
|
for (let [n, r] of Object.entries(e.fields)) if (r.type === "reference" && r.references?.()?.tableName === t) return n;
|
|
425
|
-
},
|
|
545
|
+
}, Gn = (e, t) => {
|
|
426
546
|
let n = /* @__PURE__ */ new Set();
|
|
427
547
|
for (let r of e) {
|
|
428
548
|
let e = r[t];
|
|
429
549
|
e != null && n.add(e);
|
|
430
550
|
}
|
|
431
551
|
return [...n];
|
|
432
|
-
},
|
|
552
|
+
}, Kn = (e, t, n, r, i) => {
|
|
433
553
|
let a = {
|
|
434
554
|
column: t,
|
|
435
555
|
op: "in",
|
|
@@ -443,50 +563,50 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
443
563
|
skip: r.offset,
|
|
444
564
|
projection: void 0
|
|
445
565
|
});
|
|
446
|
-
},
|
|
447
|
-
t !== void 0 && e.length !== 0 && (await
|
|
566
|
+
}, qn = async (e, t, n, r) => {
|
|
567
|
+
t !== void 0 && e.length !== 0 && (await Rn(e, t, n, r)).forEach((t, n) => {
|
|
448
568
|
let r = e[n];
|
|
449
569
|
for (let [e, n] of Object.entries(t)) e in r || (r[e] = n);
|
|
450
570
|
});
|
|
451
|
-
},
|
|
571
|
+
}, Jn = (e) => e.eager !== void 0 && Object.keys(e.eager).length > 0, Yn = class extends Error {
|
|
452
572
|
_tag = "TenantNamespaceUnresolved";
|
|
453
573
|
constructor(e) {
|
|
454
574
|
super(e), this.name = "TenantNamespaceUnresolved";
|
|
455
575
|
}
|
|
456
|
-
},
|
|
576
|
+
}, Xn = class extends Error {
|
|
457
577
|
_tag = "TenantNamespaceInvalid";
|
|
458
578
|
constructor(e) {
|
|
459
579
|
super(e), this.name = "TenantNamespaceInvalid";
|
|
460
580
|
}
|
|
461
|
-
},
|
|
462
|
-
if (e == null || e === "") throw new
|
|
463
|
-
let t =
|
|
464
|
-
if (t.replace(/_/g, "") === "") throw new
|
|
465
|
-
let n = `${
|
|
466
|
-
if (n.length >
|
|
581
|
+
}, Zn = 63, Qn = "tenant_", $n = (e) => e.toLowerCase().replace(/[^a-z0-9_]/g, "_"), er = (e) => {
|
|
582
|
+
if (e == null || e === "") throw new Yn("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.");
|
|
583
|
+
let t = $n(e);
|
|
584
|
+
if (t.replace(/_/g, "") === "") throw new Xn(`tenant id '${e}' has no usable identifier characters after sanitisation — cannot derive a distinct namespace.`);
|
|
585
|
+
let n = `${Qn}${t}`;
|
|
586
|
+
if (n.length > Zn) throw new Xn(`namespace '${n}' for tenant '${e}' exceeds the ${Zn}-byte identifier limit. Use a shorter tenant id.`);
|
|
467
587
|
return n;
|
|
468
|
-
},
|
|
469
|
-
if (e === void 0 || t == null || !
|
|
588
|
+
}, tr = (e, t) => e === null ? t : `${e}.${t}`, nr = /* @__PURE__ */ new Set(["timestamp", "date"]), rr = /^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2})?/, ir = (e, t) => {
|
|
589
|
+
if (e === void 0 || t == null || !nr.has(e) || t instanceof Date) return t;
|
|
470
590
|
if (typeof t == "number" && Number.isFinite(t)) return new Date(t);
|
|
471
|
-
if (typeof t == "string" &&
|
|
591
|
+
if (typeof t == "string" && rr.test(t)) {
|
|
472
592
|
let e = new Date(t);
|
|
473
593
|
return Number.isNaN(e.getTime()) ? t : e;
|
|
474
594
|
}
|
|
475
595
|
return t;
|
|
476
|
-
},
|
|
596
|
+
}, ar = (e, t) => e === void 0 || !nr.has(e) ? t : t.map((t) => ir(e, t)), or = (e, t) => {
|
|
477
597
|
let { strings: n, values: r } = e, i = t.unsafe(n[0] ?? "");
|
|
478
598
|
for (let e = 0; e < r.length; e++) i = t`${i}${r[e]}${t.unsafe(n[e + 1] ?? "")}`;
|
|
479
599
|
return t`${i}`;
|
|
480
|
-
},
|
|
481
|
-
if ("not" in e) return t`NOT (${
|
|
482
|
-
if ("and" in e) return e.and.length === 0 ? t`TRUE` : t.and(e.and.map((e) =>
|
|
483
|
-
if ("or" in e) return e.or.length === 0 ? t`FALSE` : t.or(e.or.map((e) =>
|
|
600
|
+
}, sr = (e) => e.replace(/[\\%_]/g, (e) => `\\${e}`), F = (e, t, n = null, r) => {
|
|
601
|
+
if ("not" in e) return t`NOT (${F(e.not, t, n, r)})`;
|
|
602
|
+
if ("and" in e) return e.and.length === 0 ? t`TRUE` : t.and(e.and.map((e) => F(e, t, n, r)));
|
|
603
|
+
if ("or" in e) return e.or.length === 0 ? t`FALSE` : t.or(e.or.map((e) => F(e, t, n, r)));
|
|
484
604
|
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
485
|
-
let r = e, i =
|
|
605
|
+
let r = e, i = vr(r.subquery, t, n);
|
|
486
606
|
return r.op === "subquery-in" ? t`${t(r.column)} IN (${i})` : t`${t(r.column)} NOT IN (${i})`;
|
|
487
607
|
}
|
|
488
608
|
if (e.op === "exists" || e.op === "not-exists") {
|
|
489
|
-
let r = e, i =
|
|
609
|
+
let r = e, i = vr(r.subquery, t, n);
|
|
490
610
|
return r.op === "exists" ? t`EXISTS (${i})` : t`NOT EXISTS (${i})`;
|
|
491
611
|
}
|
|
492
612
|
let i = e, a = t(i.column), o = i.path, s = o !== void 0 && o.length > 0, c = () => t.onDialectOrElse({
|
|
@@ -499,14 +619,14 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
499
619
|
mssql: () => t.unsafe(T(i.column, o, "mssql", { numeric: !0 })),
|
|
500
620
|
sqlite: () => t.unsafe(T(i.column, o, "sqlite", { numeric: !0 })),
|
|
501
621
|
orElse: () => t.unsafe(T(i.column, o, "postgres", { numeric: !0 }))
|
|
502
|
-
}), u = s ? c() : a, d = s ? l() : a, f = (e) => s && e != null ? String(e) : e,
|
|
622
|
+
}), u = s ? c() : a, d = s ? l() : a, f = (e) => s && e != null ? String(e) : e, m = (e) => s ? Number(e) : e, h = s || r === void 0 ? void 0 : p(r)?.fields?.[i.column]?.type, g = (e) => ir(h, e);
|
|
503
623
|
switch (i.op) {
|
|
504
|
-
case "eq": return t`${u} = ${f(
|
|
505
|
-
case "neq": return t`${u} <> ${f(
|
|
506
|
-
case "gt": return t`${d} > ${
|
|
507
|
-
case "gte": return t`${d} >= ${
|
|
508
|
-
case "lt": return t`${d} < ${
|
|
509
|
-
case "lte": return t`${d} <= ${
|
|
624
|
+
case "eq": return t`${u} = ${f(g(i.value))}`;
|
|
625
|
+
case "neq": return t`${u} <> ${f(g(i.value))}`;
|
|
626
|
+
case "gt": return t`${d} > ${m(i.value)}`;
|
|
627
|
+
case "gte": return t`${d} >= ${m(i.value)}`;
|
|
628
|
+
case "lt": return t`${d} < ${m(i.value)}`;
|
|
629
|
+
case "lte": return t`${d} <= ${m(i.value)}`;
|
|
510
630
|
case "in": {
|
|
511
631
|
let e = i.value ?? [];
|
|
512
632
|
return e.length === 0 ? t`FALSE` : t`${u} IN ${t.in(s ? e.map((e) => f(e)) : e)}`;
|
|
@@ -516,7 +636,7 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
516
636
|
return e.length === 0 ? t`TRUE` : t`${u} NOT IN ${t.in(s ? e.map((e) => f(e)) : e)}`;
|
|
517
637
|
}
|
|
518
638
|
case "contains": {
|
|
519
|
-
let e = `%${
|
|
639
|
+
let e = `%${sr(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
|
|
520
640
|
return t.onDialectOrElse({
|
|
521
641
|
mysql: () => t`LOWER(${u}) LIKE LOWER(${e})`,
|
|
522
642
|
mssql: () => t`LOWER(${u}) LIKE LOWER(${e})`,
|
|
@@ -525,7 +645,7 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
525
645
|
});
|
|
526
646
|
}
|
|
527
647
|
case "startsWith": {
|
|
528
|
-
let e = `${
|
|
648
|
+
let e = `${sr(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
|
|
529
649
|
return t.onDialectOrElse({
|
|
530
650
|
mysql: () => t`${u} LIKE ${e}`,
|
|
531
651
|
orElse: () => t`${u} LIKE ${e} ESCAPE '\\'`
|
|
@@ -573,13 +693,13 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
573
693
|
});
|
|
574
694
|
}
|
|
575
695
|
}
|
|
576
|
-
},
|
|
696
|
+
}, cr = (e, t) => {
|
|
577
697
|
let n = [];
|
|
578
698
|
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}`);
|
|
579
|
-
},
|
|
699
|
+
}, lr = (e, t) => t.csv(e.map((e) => {
|
|
580
700
|
let n = e.column === void 0 ? t.unsafe("*") : t`${t(e.column)}`;
|
|
581
701
|
if (e.op.startsWith("window-")) {
|
|
582
|
-
let r =
|
|
702
|
+
let r = cr(e.window ?? {}, t);
|
|
583
703
|
switch (e.op) {
|
|
584
704
|
case "window-row-number": return t`ROW_NUMBER() OVER (${r}) AS ${t(e.alias)}`;
|
|
585
705
|
case "window-rank": return t`RANK() OVER (${r}) AS ${t(e.alias)}`;
|
|
@@ -603,44 +723,44 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
603
723
|
return t`${t(e.column)} AS ${t(e.alias)}`;
|
|
604
724
|
default: throw Error(`compileAggregateProjection: unknown op '${e.op}'`);
|
|
605
725
|
}
|
|
606
|
-
})),
|
|
726
|
+
})), ur = (e) => `[${e.join(",")}]`, dr = (e, t) => {
|
|
607
727
|
if (e.queryVector === void 0) return null;
|
|
608
|
-
let n = t(e.column), r =
|
|
728
|
+
let n = t(e.column), r = ur(e.queryVector), i = e.distance === "cosine" ? "<=>" : e.distance === "l2" ? "<->" : "<#>", a = e.distance === "cosine" ? "VEC_DISTANCE_COSINE" : "VEC_DISTANCE_EUCLIDEAN";
|
|
609
729
|
return t.onDialectOrElse({
|
|
610
730
|
mysql: () => t`${t.unsafe(a)}(${n}, ${r})`,
|
|
611
731
|
mssql: () => t`NULL`,
|
|
612
732
|
sqlite: () => t`NULL`,
|
|
613
733
|
orElse: () => t`${n} ${t.unsafe(i)} ${r}::vector`
|
|
614
734
|
});
|
|
615
|
-
},
|
|
735
|
+
}, fr = (e, t) => {
|
|
616
736
|
let n = t.unsafe(e.useGeography ? "::geography" : "::geometry");
|
|
617
737
|
return t`ST_Distance(${t(e.column)}${n}, ${e.geom}${n})`;
|
|
618
|
-
},
|
|
619
|
-
let r = n.csv(e.columns.map((e) => n`${n(e)}`)), i = `%${
|
|
738
|
+
}, pr = (e, t) => t`${t(e.column)} <-> ${e.geom}::geometry`, mr = (e, t) => t`${t(`${e.indexName}_tsv`)}`, hr = (e, t) => `${t}_${e.indexName}_fts`, gr = (e, t, n) => {
|
|
739
|
+
let r = n.csv(e.columns.map((e) => n`${n(e)}`)), i = `%${sr(e.query)}%`;
|
|
620
740
|
return n.onDialectOrElse({
|
|
621
741
|
mysql: () => n`MATCH(${r}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
|
|
622
742
|
sqlite: () => {
|
|
623
|
-
let r = n(
|
|
743
|
+
let r = n(hr(e, t));
|
|
624
744
|
return n`${n("id")} IN (SELECT ${n("row_id")} FROM ${r} WHERE ${r} MATCH ${e.query})`;
|
|
625
745
|
},
|
|
626
746
|
mssql: () => n.or(e.columns.map((e) => n`LOWER(${n(e)}) LIKE LOWER(${i}) ESCAPE '\\'`)),
|
|
627
|
-
orElse: () => n`${
|
|
747
|
+
orElse: () => n`${mr(e, n)} @@ plainto_tsquery(${e.config ?? "english"}, ${e.query})`
|
|
628
748
|
});
|
|
629
|
-
},
|
|
630
|
-
let r = `%${
|
|
749
|
+
}, _r = (e, t, n) => {
|
|
750
|
+
let r = `%${sr(e.query)}%`;
|
|
631
751
|
return n.onDialectOrElse({
|
|
632
752
|
mysql: () => n`MATCH(${n.csv(e.columns.map((e) => n`${n(e)}`))}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
|
|
633
753
|
sqlite: () => {
|
|
634
|
-
let r = n(
|
|
754
|
+
let r = n(hr(e, t));
|
|
635
755
|
return n`COALESCE((SELECT -bm25(${r}) FROM ${r} WHERE ${r} MATCH ${e.query} AND ${r}.${n("row_id")} = ${n("id")}), 0)`;
|
|
636
756
|
},
|
|
637
757
|
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}`),
|
|
638
|
-
orElse: () => n`ts_rank(${
|
|
758
|
+
orElse: () => n`ts_rank(${mr(e, n)}, plainto_tsquery(${e.config ?? "english"}, ${e.query}))`
|
|
639
759
|
});
|
|
640
|
-
},
|
|
760
|
+
}, vr = (e, t, n = null) => {
|
|
641
761
|
if (e.setOp && e.setOp.queries.length >= 2) {
|
|
642
|
-
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`(${
|
|
643
|
-
if (
|
|
762
|
+
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`(${vr(e, t, n)})`).reduce((e, n, i) => i === 0 ? n : t`${e} ${t.unsafe(r)} ${n}`), a = [];
|
|
763
|
+
if (w(e).length > 0 && a.push(t` ORDER BY ${t.csv(w(e).map((e) => e.direction === "desc" ? t`${t(e.column)} DESC` : t`${t(e.column)} ASC`))}`), e.take !== void 0) {
|
|
644
764
|
if (!Number.isInteger(e.take) || e.take < 0) throw Error(`compileSelect: invalid take ${e.take}`);
|
|
645
765
|
a.push(t` LIMIT ${t.unsafe(String(e.take))}`);
|
|
646
766
|
}
|
|
@@ -650,7 +770,7 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
650
770
|
}
|
|
651
771
|
return t`${i}${a.reduce((e, n) => t`${e}${n}`, t``)}`;
|
|
652
772
|
}
|
|
653
|
-
let r = e.annClause === void 0 ? null :
|
|
773
|
+
let r = e.annClause === void 0 ? null : dr(e.annClause, t);
|
|
654
774
|
e.spatialClause !== void 0 && t.onDialectOrElse({
|
|
655
775
|
mysql: () => {
|
|
656
776
|
throw Error("@voltro/plugin-postgis: spatial distance / KNN ordering is postgres-only");
|
|
@@ -663,57 +783,57 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
663
783
|
},
|
|
664
784
|
orElse: () => t``
|
|
665
785
|
});
|
|
666
|
-
let i = e.spatialClause?.projectAs === void 0 ? null :
|
|
786
|
+
let i = e.spatialClause?.projectAs === void 0 ? null : fr(e.spatialClause, t), a = e.aggregations && e.aggregations.length > 0 ? lr(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 ? _r(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({
|
|
667
787
|
orElse: () => t`DISTINCT ON (${t.csv(e.distinctOn.map((e) => t`${t(e)}`))}) `,
|
|
668
788
|
mysql: () => t`DISTINCT `,
|
|
669
789
|
mssql: () => t`DISTINCT `,
|
|
670
790
|
sqlite: () => t`DISTINCT `
|
|
671
|
-
}) : e.distinct ? t`DISTINCT ` : t``, p = e.alias === void 0 ? t`${t(
|
|
791
|
+
}) : e.distinct ? t`DISTINCT ` : t``, p = e.alias === void 0 ? t`${t(tr(n, e.table))}` : t`${t(tr(n, e.table))} AS ${t(e.alias)}`, m = (e.joins ?? []).map((e) => {
|
|
672
792
|
let r = e.kind === "inner" ? "INNER" : "LEFT";
|
|
673
|
-
return t` ${t.unsafe(r)} JOIN ${t(
|
|
674
|
-
}), h = m.length > 0 ? m.reduce((e, n) => t`${e}${n}`, p) : p, g = c === void 0 ? null :
|
|
675
|
-
r !== null &&
|
|
676
|
-
for (let n of
|
|
677
|
-
let
|
|
793
|
+
return t` ${t.unsafe(r)} JOIN ${t(tr(n, e.table))} AS ${t(e.alias)} ON ${F(e.on, t, n)}`;
|
|
794
|
+
}), h = m.length > 0 ? m.reduce((e, n) => t`${e}${n}`, p) : p, g = c === void 0 ? null : gr(c, e.table, t), _ = [e.predicate ? F(e.predicate, t, n, e.table) : null, g].filter((e) => e !== null), v = _.length > 0 ? t` WHERE ${t.and(_)}` : t``, y = e.groupBy && e.groupBy.length > 0 ? t` GROUP BY ${t.csv(e.groupBy.map((e) => t`${t(e)}`))}` : t``, b = e.having ? t` HAVING ${F(e.having, t, n, e.table)}` : t``, ee = e.skip !== void 0, x = [];
|
|
795
|
+
r !== null && x.push(t`${r} ASC`), e.spatialClause?.order !== void 0 && x.push(e.spatialClause.order === "desc" ? t`${pr(e.spatialClause, t)} DESC` : t`${pr(e.spatialClause, t)} ASC`), l !== null && c?.rank?.order === !0 && x.push(t`${l} DESC`);
|
|
796
|
+
for (let n of w(e)) x.push(n.direction === "desc" ? t`${t(n.column)} DESC` : t`${t(n.column)} ASC`);
|
|
797
|
+
let te = x.length > 0 ? t` ORDER BY ${t.csv(x)}` : ee ? t.onDialectOrElse({
|
|
678
798
|
mssql: () => t` ORDER BY (SELECT NULL)`,
|
|
679
799
|
orElse: () => t``
|
|
680
|
-
}) : t``,
|
|
800
|
+
}) : t``, S = (e) => {
|
|
681
801
|
if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw Error(`compileSelect: expected non-negative integer take/skip, got ${e}`);
|
|
682
802
|
return t.unsafe(String(e));
|
|
683
|
-
},
|
|
803
|
+
}, ne = (e.ctes ?? []).map((e) => t`${t(e.name)} AS (${vr(e.descriptor, t, n)})`), re = (e.ctes ?? []).some((e) => e.recursive === !0), ie = ne.length > 0 ? t`WITH ${t.unsafe(re ? "RECURSIVE " : "")}${t.csv(ne)} ` : t``;
|
|
684
804
|
return t.onDialectOrElse({
|
|
685
805
|
mssql: () => {
|
|
686
|
-
let n = e.take !== void 0 && !
|
|
687
|
-
return t`${
|
|
806
|
+
let n = e.take !== void 0 && !ee ? t`TOP ${S(e.take)} ` : t``, r = ee ? t` OFFSET ${S(e.skip)} ROWS FETCH NEXT ${S(e.take ?? 2 ** 53 - 1)} ROWS ONLY` : t``;
|
|
807
|
+
return t`${ie}SELECT ${n}${f}${d} FROM ${h}${v}${y}${b}${te}${r}`;
|
|
688
808
|
},
|
|
689
809
|
orElse: () => {
|
|
690
|
-
let n = e.take === void 0 ? t`` : t` LIMIT ${
|
|
691
|
-
return t`${
|
|
810
|
+
let n = e.take === void 0 ? t`` : t` LIMIT ${S(e.take)}`, r = ee ? t` OFFSET ${S(e.skip)}` : t``;
|
|
811
|
+
return t`${ie}SELECT ${f}${d} FROM ${h}${v}${y}${b}${te}${n}${r}`;
|
|
692
812
|
}
|
|
693
813
|
});
|
|
694
|
-
},
|
|
814
|
+
}, yr = (e, t, n) => {
|
|
695
815
|
if (e.eager === void 0) return null;
|
|
696
|
-
let r =
|
|
816
|
+
let r = Sr(e.table, e.eager, e.sourceTable);
|
|
697
817
|
if (r === null) return null;
|
|
698
|
-
let i =
|
|
818
|
+
let i = kr(n, e, r, Or(t, n));
|
|
699
819
|
return i === null ? null : {
|
|
700
820
|
fragment: i,
|
|
701
|
-
decode:
|
|
821
|
+
decode: Mr(r, n)
|
|
702
822
|
};
|
|
703
|
-
},
|
|
823
|
+
}, br = (e) => e.relation.kind === "one" && e.fkSide === "target", xr = (e) => ({
|
|
704
824
|
...e,
|
|
705
825
|
branch: {
|
|
706
826
|
...e.branch,
|
|
707
827
|
limit: 2
|
|
708
828
|
}
|
|
709
|
-
}),
|
|
710
|
-
let r = n ??
|
|
829
|
+
}), Sr = (e, t, n) => {
|
|
830
|
+
let r = n ?? y(e), i = mn(e);
|
|
711
831
|
if (i === void 0) return null;
|
|
712
832
|
let a = [];
|
|
713
833
|
for (let [e, n] of Object.entries(t)) {
|
|
714
834
|
let t = i[e];
|
|
715
835
|
if (t === void 0) return null;
|
|
716
|
-
let o =
|
|
836
|
+
let o = Cr(e, t, r, n === !0 ? {} : n);
|
|
717
837
|
if (o === null) return null;
|
|
718
838
|
a.push(o);
|
|
719
839
|
}
|
|
@@ -721,30 +841,30 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
721
841
|
table: r,
|
|
722
842
|
children: a
|
|
723
843
|
};
|
|
724
|
-
},
|
|
844
|
+
}, Cr = (e, t, n, r) => {
|
|
725
845
|
let i = t.target(), a = (t.kind === "manyToMany" ? void 0 : t.sourceKey) ?? "id", o, s;
|
|
726
846
|
if (t.kind === "manyToMany") o = t.targetKey, s = "target";
|
|
727
847
|
else if (t.kind === "one") {
|
|
728
|
-
let r = t.sourceKey ??
|
|
848
|
+
let r = t.sourceKey ?? Dr(n, i.tableName);
|
|
729
849
|
if (r !== void 0) o = r, s = "source";
|
|
730
850
|
else try {
|
|
731
|
-
o = t.foreignKey ??
|
|
851
|
+
o = t.foreignKey ?? on(i, n.tableName, e), s = "target";
|
|
732
852
|
} catch {
|
|
733
853
|
return null;
|
|
734
854
|
}
|
|
735
855
|
} else try {
|
|
736
|
-
o = t.foreignKey ??
|
|
856
|
+
o = t.foreignKey ?? on(i, n.tableName, e), s = "target";
|
|
737
857
|
} catch {
|
|
738
858
|
return null;
|
|
739
859
|
}
|
|
740
860
|
let c = r.with === void 0 ? [] : (() => {
|
|
741
|
-
let e =
|
|
861
|
+
let e = mn(i.tableName);
|
|
742
862
|
if (e === void 0 && Object.keys(r.with).length > 0) return null;
|
|
743
863
|
let t = [];
|
|
744
864
|
for (let [n, a] of Object.entries(r.with)) {
|
|
745
865
|
let r = e?.[n];
|
|
746
866
|
if (r === void 0) return null;
|
|
747
|
-
let o =
|
|
867
|
+
let o = Cr(n, r, i, a === !0 ? {} : a);
|
|
748
868
|
if (o === null) return null;
|
|
749
869
|
t.push(o);
|
|
750
870
|
}
|
|
@@ -760,9 +880,9 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
760
880
|
fkSide: s,
|
|
761
881
|
branch: r,
|
|
762
882
|
children: c,
|
|
763
|
-
junction:
|
|
883
|
+
junction: wr(t, r)
|
|
764
884
|
};
|
|
765
|
-
},
|
|
885
|
+
}, wr = (e, t) => {
|
|
766
886
|
if (e.kind !== "manyToMany" || t.junction === void 0) return;
|
|
767
887
|
let n = e.through(), r = t.junction === !0 ? Object.keys(n.fields) : t.junction, i = r.filter((e) => e in n.fields);
|
|
768
888
|
return {
|
|
@@ -774,35 +894,35 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
774
894
|
return t !== void 0 && (t.type === "timestamp" || t.type === "date");
|
|
775
895
|
})
|
|
776
896
|
};
|
|
777
|
-
},
|
|
897
|
+
}, Tr = (e) => `__j_${e}`, Er = "__j", Dr = (e, t) => {
|
|
778
898
|
for (let [n, r] of Object.entries(e.fields)) if (r.type === "reference" && r.references?.()?.tableName === t) return n;
|
|
779
|
-
},
|
|
899
|
+
}, Or = (e, t) => {
|
|
780
900
|
let n = 0;
|
|
781
901
|
return {
|
|
782
902
|
sql: e,
|
|
783
903
|
dialect: t,
|
|
784
904
|
nextAlias: () => `__a${n++}`
|
|
785
905
|
};
|
|
786
|
-
},
|
|
906
|
+
}, kr = (e, t, n, r) => {
|
|
787
907
|
switch (e) {
|
|
788
|
-
case "postgres": return
|
|
908
|
+
case "postgres": return Fr(t, n, r);
|
|
789
909
|
case "sqlite":
|
|
790
|
-
case "turso": return
|
|
910
|
+
case "turso": return Ur(t, n, r);
|
|
791
911
|
case "mysql":
|
|
792
|
-
case "mariadb": return
|
|
793
|
-
case "mssql": return
|
|
912
|
+
case "mariadb": return $r(t, n, r);
|
|
913
|
+
case "mssql": return oi(t, n, r);
|
|
794
914
|
}
|
|
795
|
-
},
|
|
796
|
-
let n =
|
|
915
|
+
}, Ar = (e, t) => t === "mssql" && !jr.test(e) ? /* @__PURE__ */ new Date(`${e}Z`) : new Date(e), jr = /(?:Z|[+-]\d{2}:?\d{2})$/, Mr = (e, t) => {
|
|
916
|
+
let n = Nr(e.table, e.children, t);
|
|
797
917
|
return (e) => e.map((e) => {
|
|
798
918
|
let t = e.__row, r = typeof t == "string" ? JSON.parse(t) : t;
|
|
799
919
|
return n(r);
|
|
800
920
|
});
|
|
801
|
-
},
|
|
921
|
+
}, Nr = (e, t, n) => {
|
|
802
922
|
let r = [];
|
|
803
923
|
for (let [t, n] of Object.entries(e.fields)) (n.type === "timestamp" || n.type === "date") && r.push(t);
|
|
804
924
|
let i = t.map((e) => {
|
|
805
|
-
let t =
|
|
925
|
+
let t = Nr(e.target, e.children, n), r = e.relation.kind === "one", i = br(e), a = i ? Ln({
|
|
806
926
|
relationName: e.relationName,
|
|
807
927
|
sourceTableName: e.source.tableName,
|
|
808
928
|
targetTableName: e.target.tableName,
|
|
@@ -815,14 +935,14 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
815
935
|
isSingle: r,
|
|
816
936
|
fromOverFetch: i,
|
|
817
937
|
cardinalityMessage: a,
|
|
818
|
-
junction:
|
|
938
|
+
junction: Pr(e.junction, n)
|
|
819
939
|
};
|
|
820
940
|
});
|
|
821
941
|
return (e) => {
|
|
822
942
|
let t = { ...e };
|
|
823
943
|
for (let e of r) {
|
|
824
944
|
let r = t[e];
|
|
825
|
-
typeof r == "string" && (t[e] =
|
|
945
|
+
typeof r == "string" && (t[e] = Ar(r, n));
|
|
826
946
|
}
|
|
827
947
|
for (let e of i) {
|
|
828
948
|
let n = t[e.name];
|
|
@@ -832,7 +952,7 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
832
952
|
}
|
|
833
953
|
if (e.fromOverFetch) {
|
|
834
954
|
let r = n;
|
|
835
|
-
if (r.length > 1) throw new
|
|
955
|
+
if (r.length > 1) throw new In(e.cardinalityMessage);
|
|
836
956
|
t[e.name] = r.length === 0 ? null : e.decode(r[0]);
|
|
837
957
|
continue;
|
|
838
958
|
}
|
|
@@ -844,202 +964,202 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
844
964
|
}
|
|
845
965
|
return t;
|
|
846
966
|
};
|
|
847
|
-
},
|
|
967
|
+
}, Pr = (e, t) => {
|
|
848
968
|
if (e === void 0) return;
|
|
849
969
|
let n = new Set(e.dateColumns), r = e.requested;
|
|
850
970
|
return (e) => {
|
|
851
971
|
let i = e._junction ?? {}, a = {};
|
|
852
972
|
for (let e of r) {
|
|
853
973
|
let r = i[e];
|
|
854
|
-
a[e] = n.has(e) && typeof r == "string" ?
|
|
974
|
+
a[e] = n.has(e) && typeof r == "string" ? Ar(r, t) : r;
|
|
855
975
|
}
|
|
856
976
|
return {
|
|
857
977
|
...e,
|
|
858
978
|
_junction: a
|
|
859
979
|
};
|
|
860
980
|
};
|
|
861
|
-
},
|
|
862
|
-
let r = n.sql, i = n.nextAlias(), a = r(t.table.tableName), o = r(i), s =
|
|
863
|
-
return s === null ? null : r`SELECT ${s} AS "__row" FROM ${a} AS ${o}${e.predicate ? r` WHERE ${V(e.predicate, i, r)}` : r``}${
|
|
864
|
-
},
|
|
865
|
-
let i = n.sql, a = r === void 0 ? i`to_jsonb(${i(e)}.*)` : i`(to_jsonb(${i(e)}.*) - ${z(
|
|
981
|
+
}, Fr = (e, t, n) => {
|
|
982
|
+
let r = n.sql, i = n.nextAlias(), a = r(t.table.tableName), o = r(i), s = Ir(i, t.children, n);
|
|
983
|
+
return s === null ? null : r`SELECT ${s} AS "__row" FROM ${a} AS ${o}${e.predicate ? r` WHERE ${V(e.predicate, i, r)}` : r``}${w(e).length > 0 ? r` ORDER BY ${r.csv(w(e).map((e) => e.direction === "desc" ? r`${R(i, e.column, r)} DESC` : r`${R(i, e.column, r)} ASC`))}` : r``}${e.take === void 0 ? r`` : r` LIMIT ${B(e.take, r)}`}${e.skip === void 0 ? r`` : r` OFFSET ${B(e.skip, r)}`}`;
|
|
984
|
+
}, Ir = (e, t, n, r) => {
|
|
985
|
+
let i = n.sql, a = r === void 0 ? i`to_jsonb(${i(e)}.*)` : i`(to_jsonb(${i(e)}.*) - ${z(Er, i)}::text)`;
|
|
866
986
|
if (t.length === 0 && r === void 0) return a;
|
|
867
987
|
let o = [];
|
|
868
|
-
r !== void 0 && o.push(i`${z("_junction", i)}, ${R(e,
|
|
988
|
+
r !== void 0 && o.push(i`${z("_junction", i)}, ${R(e, Er, i)}`);
|
|
869
989
|
for (let r of t) {
|
|
870
|
-
let t =
|
|
990
|
+
let t = Lr(r, e, n);
|
|
871
991
|
if (t === null) return null;
|
|
872
992
|
o.push(i`${z(r.relationName, i)}, ${t}`);
|
|
873
993
|
}
|
|
874
994
|
return i`${a} || jsonb_build_object(${i.csv(o)})`;
|
|
875
|
-
},
|
|
995
|
+
}, Lr = (e, t, n) => {
|
|
876
996
|
switch (e.relation.kind) {
|
|
877
|
-
case "one": return
|
|
878
|
-
case "many": return
|
|
879
|
-
case "manyToMany": return
|
|
997
|
+
case "one": return br(e) ? zr(xr(e), t, n) : Rr(e, t, n);
|
|
998
|
+
case "many": return zr(e, t, n);
|
|
999
|
+
case "manyToMany": return Br(e, t, n);
|
|
880
1000
|
}
|
|
881
|
-
},
|
|
882
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1001
|
+
}, Rr = (e, t, n) => {
|
|
1002
|
+
let r = n.sql, i = n.nextAlias(), a = Ir(i, e.children, n);
|
|
883
1003
|
if (a === null) return null;
|
|
884
1004
|
let o = e.fkSide === "source" ? r`${R(i, "id", r)} = ${R(t, e.foreignKey, r)}` : r`${R(i, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${V(e.branch.where, i, r)}`, c = I(i, e.branch.orderBy, r);
|
|
885
1005
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}${c} LIMIT 1)`;
|
|
886
|
-
},
|
|
887
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1006
|
+
}, zr = (e, t, n) => {
|
|
1007
|
+
let r = n.sql, i = n.nextAlias(), a = Ir(i, e.children, n);
|
|
888
1008
|
if (a === null) return null;
|
|
889
|
-
let o = r`${R(void 0, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1009
|
+
let o = r`${R(void 0, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${F(e.branch.where, r)}`, c = Hr(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${B(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${B(e.branch.offset, r)}`;
|
|
890
1010
|
return r`COALESCE((SELECT jsonb_agg(${a}) FROM (SELECT * FROM ${r(e.target.tableName)} WHERE ${o}${s}${c}${l}${u}) AS ${r(i)}), '[]'::jsonb)`;
|
|
891
|
-
},
|
|
892
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
1011
|
+
}, Br = (e, t, n) => {
|
|
1012
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = Ir(o, e.children, n, e.junction);
|
|
893
1013
|
if (c === null) return null;
|
|
894
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1014
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${F(e.branch.where, r)}`, u = mi(e, s, r), d = I(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${B(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${B(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : r`, ${Vr(e.junction, s, r)} AS ${r(Er)}`;
|
|
895
1015
|
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 ${R(o, "id", r)} = ${R(s, i.targetKey, r)} WHERE ${R(s, i.sourceKey, r)} = ${R(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), '[]'::jsonb)`;
|
|
896
|
-
},
|
|
897
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1016
|
+
}, Vr = (e, t, n) => e.present.length === 0 ? n`jsonb_build_object()` : n`jsonb_build_object(${n.csv(e.present.map((e) => n`${z(e, n)}, ${R(t, e, n)}`))})`, I = (e, t, n) => t === void 0 || t.length === 0 ? n`` : n` ORDER BY ${n.csv(t.map((t) => t.direction === "desc" ? n`${R(e, t.column, n)} DESC` : n`${R(e, t.column, n)} ASC`))}`, Hr = (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`))}`, Ur = (e, t, n) => {
|
|
1017
|
+
let r = n.sql, i = n.nextAlias(), a = Wr(i, t.table, t.children, n);
|
|
898
1018
|
if (a === null) return null;
|
|
899
|
-
let o = e.predicate ? r` WHERE ${V(e.predicate, i, r)}` : r``, s =
|
|
1019
|
+
let o = e.predicate ? r` WHERE ${V(e.predicate, i, r)}` : r``, s = w(e).length > 0 ? r` ORDER BY ${r.csv(w(e).map((e) => e.direction === "desc" ? r`${R(i, e.column, r)} DESC` : r`${R(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${B(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${B(e.skip, r)}`;
|
|
900
1020
|
return r`SELECT ${a} AS "__row" FROM ${r(t.table.tableName)} AS ${r(i)}${o}${s}${c}${l}`;
|
|
901
|
-
},
|
|
1021
|
+
}, Wr = (e, t, n, r, i) => {
|
|
902
1022
|
let a = r.sql, o = [];
|
|
903
1023
|
for (let n of Object.keys(t.fields)) o.push(a`${z(n, a)}, ${R(e, n, a)}`);
|
|
904
1024
|
if (i !== void 0) {
|
|
905
|
-
let e =
|
|
1025
|
+
let e = Gr(i.projection, i.source, a);
|
|
906
1026
|
o.push(a`${z("_junction", a)}, json_object(${e})`);
|
|
907
1027
|
}
|
|
908
1028
|
for (let t of n) {
|
|
909
|
-
let n =
|
|
1029
|
+
let n = Yr(t, e, r);
|
|
910
1030
|
if (n === null) return null;
|
|
911
1031
|
o.push(a`${z(t.relationName, a)}, ${n}`);
|
|
912
1032
|
}
|
|
913
1033
|
return a`json_object(${a.csv(o)})`;
|
|
914
|
-
},
|
|
1034
|
+
}, Gr = (e, t, n) => e.present.length === 0 ? n`` : n.csv(e.present.map((e) => n`${z(e, n)}, ${R(t.alias, t.physical(e), n)}`)), Kr = (e, t, n) => e.present.length === 0 ? n`` : n`, ${n.csv(e.present.map((e) => n`${R(t, e, n)} AS ${n(Tr(e))}`))}`, qr = (e) => ({
|
|
915
1035
|
alias: e,
|
|
916
|
-
physical:
|
|
917
|
-
}),
|
|
1036
|
+
physical: Tr
|
|
1037
|
+
}), Jr = (e) => ({
|
|
918
1038
|
alias: e,
|
|
919
1039
|
physical: (e) => e
|
|
920
|
-
}),
|
|
1040
|
+
}), Yr = (e, t, n) => {
|
|
921
1041
|
switch (e.relation.kind) {
|
|
922
|
-
case "one": return
|
|
923
|
-
case "many": return
|
|
924
|
-
case "manyToMany": return
|
|
1042
|
+
case "one": return br(e) ? Zr(xr(e), t, n) : Xr(e, t, n);
|
|
1043
|
+
case "many": return Zr(e, t, n);
|
|
1044
|
+
case "manyToMany": return Qr(e, t, n);
|
|
925
1045
|
}
|
|
926
|
-
},
|
|
927
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1046
|
+
}, Xr = (e, t, n) => {
|
|
1047
|
+
let r = n.sql, i = n.nextAlias(), a = Wr(i, e.target, e.children, n);
|
|
928
1048
|
if (a === null) return null;
|
|
929
1049
|
let o = e.fkSide === "source" ? r`${R(i, "id", r)} = ${R(t, e.foreignKey, r)}` : r`${R(i, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}`;
|
|
930
1050
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
|
|
931
|
-
},
|
|
932
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1051
|
+
}, Zr = (e, t, n) => {
|
|
1052
|
+
let r = n.sql, i = n.nextAlias(), a = Wr(i, e.target, e.children, n);
|
|
933
1053
|
if (a === null) return null;
|
|
934
|
-
let o = r`${R(void 0, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1054
|
+
let o = r`${R(void 0, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${F(H(e.branch.where), r)}`, c = Hr(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${B(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${B(e.branch.offset, r)}`;
|
|
935
1055
|
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('[]'))`;
|
|
936
|
-
},
|
|
937
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
1056
|
+
}, Qr = (e, t, n) => {
|
|
1057
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = Wr(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
938
1058
|
projection: e.junction,
|
|
939
|
-
source:
|
|
1059
|
+
source: qr(o)
|
|
940
1060
|
});
|
|
941
1061
|
if (c === null) return null;
|
|
942
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1062
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${F(H(e.branch.where), r)}`, u = mi(e, s, r, !0), d = I(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${B(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${B(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : Kr(e.junction, s, r);
|
|
943
1063
|
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 ${R(o, "id", r)} = ${R(s, i.targetKey, r)} WHERE ${R(s, i.sourceKey, r)} = ${R(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), json('[]'))`;
|
|
944
|
-
},
|
|
1064
|
+
}, $r = (e, t, n) => {
|
|
945
1065
|
let r = n.sql, i = n.nextAlias(), a = L(i, t.table, t.children, n);
|
|
946
1066
|
if (a === null) return null;
|
|
947
|
-
let o = e.predicate ? r` WHERE ${V(e.predicate, i, r)}` : r``, s =
|
|
1067
|
+
let o = e.predicate ? r` WHERE ${V(e.predicate, i, r)}` : r``, s = w(e).length > 0 ? r` ORDER BY ${r.csv(w(e).map((e) => e.direction === "desc" ? r`${R(i, e.column, r)} DESC` : r`${R(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${B(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${B(e.skip, r)}`;
|
|
948
1068
|
return r`SELECT ${a} AS \`__row\` FROM ${r(t.table.tableName)} AS ${r(i)}${o}${s}${c}${l}`;
|
|
949
1069
|
}, L = (e, t, n, r, i) => {
|
|
950
1070
|
let a = r.sql, o = [];
|
|
951
1071
|
for (let n of Object.keys(t.fields)) o.push(a`${z(n, a)}, ${R(e, n, a)}`);
|
|
952
1072
|
if (i !== void 0) {
|
|
953
|
-
let e =
|
|
1073
|
+
let e = Gr(i.projection, i.source, a);
|
|
954
1074
|
o.push(a`${z("_junction", a)}, JSON_OBJECT(${e})`);
|
|
955
1075
|
}
|
|
956
1076
|
for (let t of n) {
|
|
957
|
-
let n =
|
|
1077
|
+
let n = ei(t, e, r);
|
|
958
1078
|
if (n === null) return null;
|
|
959
1079
|
o.push(a`${z(t.relationName, a)}, ${n}`);
|
|
960
1080
|
}
|
|
961
1081
|
return a`JSON_OBJECT(${a.csv(o)})`;
|
|
962
|
-
},
|
|
1082
|
+
}, ei = (e, t, n) => {
|
|
963
1083
|
switch (e.relation.kind) {
|
|
964
1084
|
case "one":
|
|
965
|
-
if (
|
|
966
|
-
let r =
|
|
967
|
-
return n.dialect === "mariadb" ?
|
|
1085
|
+
if (br(e)) {
|
|
1086
|
+
let r = xr(e);
|
|
1087
|
+
return n.dialect === "mariadb" ? ii(r, t, n) : ni(r, t, n);
|
|
968
1088
|
}
|
|
969
|
-
return
|
|
970
|
-
case "many": return n.dialect === "mariadb" ?
|
|
971
|
-
case "manyToMany": return n.dialect === "mariadb" ?
|
|
1089
|
+
return ti(e, t, n);
|
|
1090
|
+
case "many": return n.dialect === "mariadb" ? ii(e, t, n) : ni(e, t, n);
|
|
1091
|
+
case "manyToMany": return n.dialect === "mariadb" ? ai(e, t, n) : ri(e, t, n);
|
|
972
1092
|
}
|
|
973
|
-
},
|
|
1093
|
+
}, ti = (e, t, n) => {
|
|
974
1094
|
let r = n.sql, i = n.nextAlias(), a = L(i, e.target, e.children, n);
|
|
975
1095
|
if (a === null) return null;
|
|
976
1096
|
let o = e.fkSide === "source" ? r`${R(i, "id", r)} = ${R(t, e.foreignKey, r)}` : r`${R(i, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}`;
|
|
977
1097
|
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
|
|
978
|
-
},
|
|
1098
|
+
}, ni = (e, t, n) => {
|
|
979
1099
|
let r = n.sql, i = n.nextAlias(), a = L(i, e.target, e.children, n);
|
|
980
1100
|
if (a === null) return null;
|
|
981
|
-
let o = r`${R(void 0, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1101
|
+
let o = r`${R(void 0, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${F(H(e.branch.where), r)}`, c = Hr(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${B(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${B(e.branch.offset, r)}`;
|
|
982
1102
|
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())`;
|
|
983
|
-
},
|
|
1103
|
+
}, ri = (e, t, n) => {
|
|
984
1104
|
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = L(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
985
1105
|
projection: e.junction,
|
|
986
|
-
source:
|
|
1106
|
+
source: qr(o)
|
|
987
1107
|
});
|
|
988
1108
|
if (c === null) return null;
|
|
989
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1109
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${F(H(e.branch.where), r)}`, u = mi(e, s, r, !0), d = I(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${B(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${B(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : Kr(e.junction, s, r);
|
|
990
1110
|
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 ${R(o, "id", r)} = ${R(s, i.targetKey, r)} WHERE ${R(s, i.sourceKey, r)} = ${R(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), JSON_ARRAY())`;
|
|
991
|
-
},
|
|
1111
|
+
}, ii = (e, t, n) => {
|
|
992
1112
|
let r = n.sql, i = n.nextAlias(), a = L(i, e.target, e.children, n);
|
|
993
1113
|
if (a === null) return null;
|
|
994
|
-
let o = r`${R(i, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1114
|
+
let o = r`${R(i, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${F(H(e.branch.where), r)}`, c = e.branch.orderBy ?? [];
|
|
995
1115
|
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`${R(i, e.column, r)} DESC` : r`${R(i, e.column, r)} ASC`))}` : r``}) FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}), JSON_ARRAY())`;
|
|
996
1116
|
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 ${R(i, "rn", r)} > ${B(d, r)} AND ${R(i, "rn", r)} <= ${B(d + u, r)}` : u === void 0 ? r` AND ${R(i, "rn", r)} > ${B(d, r)}` : r` AND ${R(i, "rn", r)} <= ${B(u, r)}`;
|
|
997
1117
|
return r`COALESCE((SELECT JSON_ARRAYAGG(${a} ORDER BY ${R(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())`;
|
|
998
|
-
},
|
|
1118
|
+
}, ai = (e, t, n) => {
|
|
999
1119
|
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = (t) => e.junction === void 0 ? void 0 : {
|
|
1000
1120
|
projection: e.junction,
|
|
1001
1121
|
source: t
|
|
1002
|
-
}, l = r`${R(s, i.sourceKey, r)} = ${R(t, "id", r)}`, u = r`${R(o, "id", r)} = ${R(s, i.targetKey, r)}`, d = e.branch.where === void 0 ? r`` : r` AND ${
|
|
1122
|
+
}, l = r`${R(s, i.sourceKey, r)} = ${R(t, "id", r)}`, u = r`${R(o, "id", r)} = ${R(s, i.targetKey, r)}`, d = e.branch.where === void 0 ? r`` : r` AND ${F(H(e.branch.where), r)}`, f = mi(e, s, r, !0), p = e.branch.orderBy ?? [];
|
|
1003
1123
|
if (!(e.branch.limit !== void 0 || e.branch.offset !== void 0)) {
|
|
1004
|
-
let t = L(o, e.target, e.children, n, c(
|
|
1124
|
+
let t = L(o, e.target, e.children, n, c(Jr(s)));
|
|
1005
1125
|
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`${R(o, e.column, r)} DESC` : r`${R(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())`;
|
|
1006
1126
|
}
|
|
1007
|
-
let m = p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${R(o, e.column, r)} DESC` : r`${R(o, e.column, r)} ASC`))}` : r` ORDER BY ${R(o, "id", r)}`, h = e.branch.limit, g = e.branch.offset,
|
|
1008
|
-
if (
|
|
1009
|
-
let
|
|
1010
|
-
return r`COALESCE((SELECT JSON_ARRAYAGG(${
|
|
1011
|
-
},
|
|
1012
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1127
|
+
let m = p.length > 0 ? r` ORDER BY ${r.csv(p.map((e) => e.direction === "desc" ? r`${R(o, e.column, r)} DESC` : r`${R(o, e.column, r)} ASC`))}` : r` ORDER BY ${R(o, "id", r)}`, h = e.branch.limit, g = e.branch.offset, _ = h !== void 0 && g !== void 0 ? r` AND ${R(o, "rn", r)} > ${B(g, r)} AND ${R(o, "rn", r)} <= ${B(g + h, r)}` : h === void 0 ? r` AND ${R(o, "rn", r)} > ${B(g, r)}` : r` AND ${R(o, "rn", r)} <= ${B(h, r)}`, v = e.branch.onJunction === void 0 ? r`` : r` WHERE ${V(H(e.branch.onJunction), s, r)}`, y = L(o, e.target, e.children, n, c(qr(o)));
|
|
1128
|
+
if (y === null) return null;
|
|
1129
|
+
let b = e.junction === void 0 ? r`` : Kr(e.junction, s, r);
|
|
1130
|
+
return r`COALESCE((SELECT JSON_ARRAYAGG(${y} ORDER BY ${R(o, "rn", r)}) FROM (SELECT ${r(o)}.*${b}, ${R(s, i.sourceKey, r)} AS ${r(`__src_${i.sourceKey}`)}, ROW_NUMBER() OVER (PARTITION BY ${R(s, i.sourceKey, r)}${m}) AS rn FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${u}${v}) AS ${r(o)} WHERE ${R(o, `__src_${i.sourceKey}`, r)} = ${R(t, "id", r)}${d}${_}), JSON_ARRAY())`;
|
|
1131
|
+
}, oi = (e, t, n) => {
|
|
1132
|
+
let r = n.sql, i = n.nextAlias(), a = si(i, t.table, t.children, n);
|
|
1013
1133
|
if (a === null) return null;
|
|
1014
|
-
let o = e.predicate ? r` WHERE ${V(e.predicate, i, r)}` : r``, s =
|
|
1134
|
+
let o = e.predicate ? r` WHERE ${V(e.predicate, i, r)}` : r``, s = w(e).length > 0 ? r` ORDER BY ${r.csv(w(e).map((e) => e.direction === "desc" ? r`${R(i, e.column, r)} DESC` : r`${R(i, e.column, r)} ASC`))}` : r``, c = r``, l = r``;
|
|
1015
1135
|
if (e.skip !== void 0) {
|
|
1016
|
-
let t =
|
|
1136
|
+
let t = w(e).length > 0 ? s : r` ORDER BY (SELECT NULL)`;
|
|
1017
1137
|
l = e.take === void 0 ? r`${t} OFFSET ${B(e.skip, r)} ROWS` : r`${t} OFFSET ${B(e.skip, r)} ROWS FETCH NEXT ${B(e.take, r)} ROWS ONLY`;
|
|
1018
1138
|
} else e.take !== void 0 && (c = r`TOP ${B(e.take, r)} `);
|
|
1019
1139
|
let u = e.skip === void 0 ? s : r``;
|
|
1020
1140
|
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}`;
|
|
1021
|
-
},
|
|
1141
|
+
}, si = (e, t, n, r, i) => {
|
|
1022
1142
|
let a = r.sql, o = [];
|
|
1023
1143
|
for (let n of Object.keys(t.fields)) o.push(a`${R(e, n, a)} AS ${a(n)}`);
|
|
1024
|
-
if (i !== void 0) for (let e of i.projection.present) o.push(a`${R(i.source.alias, i.source.physical(e), a)} AS ${
|
|
1144
|
+
if (i !== void 0) for (let e of i.projection.present) o.push(a`${R(i.source.alias, i.source.physical(e), a)} AS ${ci(`_junction.${e}`, a)}`);
|
|
1025
1145
|
for (let t of n) {
|
|
1026
|
-
let n =
|
|
1146
|
+
let n = li(t, e, r);
|
|
1027
1147
|
if (n === null) return null;
|
|
1028
1148
|
o.push(n);
|
|
1029
1149
|
}
|
|
1030
1150
|
return a.csv(o);
|
|
1031
|
-
},
|
|
1151
|
+
}, ci = (e, t) => t.unsafe(`[${e.replace(/]/g, "]]")}]`), li = (e, t, n) => {
|
|
1032
1152
|
switch (e.relation.kind) {
|
|
1033
|
-
case "one": return
|
|
1034
|
-
case "many": return
|
|
1035
|
-
case "manyToMany": return
|
|
1153
|
+
case "one": return br(e) ? fi(xr(e), t, n) : ui(e, t, n);
|
|
1154
|
+
case "many": return fi(e, t, n);
|
|
1155
|
+
case "manyToMany": return pi(e, t, n);
|
|
1036
1156
|
}
|
|
1037
|
-
},
|
|
1038
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1157
|
+
}, ui = (e, t, n) => {
|
|
1158
|
+
let r = n.sql, i = n.nextAlias(), a = si(i, e.target, e.children, n);
|
|
1039
1159
|
if (a === null) return null;
|
|
1040
1160
|
let o = e.fkSide === "source" ? r`${R(i, "id", r)} = ${R(t, e.foreignKey, r)}` : r`${R(i, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}`;
|
|
1041
1161
|
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)}`;
|
|
1042
|
-
},
|
|
1162
|
+
}, di = (e, t, n) => {
|
|
1043
1163
|
if (e.offset !== void 0) {
|
|
1044
1164
|
let r = e.orderBy && e.orderBy.length > 0 ? t : n` ORDER BY (SELECT NULL)`, i = e.limit === void 0 ? n`${r} OFFSET ${B(e.offset, n)} ROWS` : n`${r} OFFSET ${B(e.offset, n)} ROWS FETCH NEXT ${B(e.limit, n)} ROWS ONLY`;
|
|
1045
1165
|
return {
|
|
@@ -1053,29 +1173,29 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
1053
1173
|
pagination: n``,
|
|
1054
1174
|
finalOrder: t
|
|
1055
1175
|
};
|
|
1056
|
-
},
|
|
1057
|
-
let r = n.sql, i = n.nextAlias(), a =
|
|
1176
|
+
}, fi = (e, t, n) => {
|
|
1177
|
+
let r = n.sql, i = n.nextAlias(), a = si(i, e.target, e.children, n);
|
|
1058
1178
|
if (a === null) return null;
|
|
1059
|
-
let o = e.branch.where === void 0 ? r`` : r` AND ${V(e.branch.where, i, r)}`, s = I(i, e.branch.orderBy, r), { top: c, pagination: l, finalOrder: u } =
|
|
1179
|
+
let o = e.branch.where === void 0 ? r`` : r` AND ${V(e.branch.where, i, r)}`, s = I(i, e.branch.orderBy, r), { top: c, pagination: l, finalOrder: u } = di(e.branch, s, r);
|
|
1060
1180
|
return r`ISNULL(JSON_QUERY((SELECT ${c}${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${R(i, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}${o}${u}${l} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
|
|
1061
|
-
},
|
|
1062
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c =
|
|
1181
|
+
}, pi = (e, t, n) => {
|
|
1182
|
+
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = si(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
1063
1183
|
projection: e.junction,
|
|
1064
|
-
source:
|
|
1184
|
+
source: Jr(s)
|
|
1065
1185
|
});
|
|
1066
1186
|
if (c === null) return null;
|
|
1067
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${V(e.branch.where, o, r)}`, u =
|
|
1187
|
+
let l = e.branch.where === void 0 ? r`` : r` AND ${V(e.branch.where, o, r)}`, u = mi(e, s, r), d = I(o, e.branch.orderBy, r), { top: f, pagination: p, finalOrder: m } = di(e.branch, d, r);
|
|
1068
1188
|
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 ${R(o, "id", r)} = ${R(s, i.targetKey, r)} WHERE ${R(s, i.sourceKey, r)} = ${R(t, "id", r)}${u}${l}${m}${p} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
|
|
1069
1189
|
}, R = (e, t, n) => e === void 0 ? n`${n(t)}` : n`${n(e)}.${n(t)}`, z = (e, t) => t.unsafe(`'${e.replace(/'/g, "''")}'`), B = (e, t) => {
|
|
1070
1190
|
if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw Error(`literalInt: expected non-negative integer, got ${e}`);
|
|
1071
1191
|
return t.unsafe(String(e));
|
|
1072
|
-
}, V = (e, t, n) =>
|
|
1192
|
+
}, V = (e, t, n) => F(hi(e, t), n), mi = (e, t, n, r = !1) => {
|
|
1073
1193
|
let i = e.branch.onJunction;
|
|
1074
|
-
return i === void 0 ? n`` : n` AND ${V(r ?
|
|
1075
|
-
},
|
|
1076
|
-
if ("not" in e) return { not:
|
|
1077
|
-
if ("and" in e) return { and: e.and.map((e) =>
|
|
1078
|
-
if ("or" in e) return { or: e.or.map((e) =>
|
|
1194
|
+
return i === void 0 ? n`` : n` AND ${V(r ? H(i) : i, t, n)}`;
|
|
1195
|
+
}, hi = (e, t) => {
|
|
1196
|
+
if ("not" in e) return { not: hi(e.not, t) };
|
|
1197
|
+
if ("and" in e) return { and: e.and.map((e) => hi(e, t)) };
|
|
1198
|
+
if ("or" in e) return { or: e.or.map((e) => hi(e, t)) };
|
|
1079
1199
|
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
1080
1200
|
let n = e;
|
|
1081
1201
|
return {
|
|
@@ -1089,99 +1209,99 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
1089
1209
|
...n,
|
|
1090
1210
|
column: `${t}.${n.column}`
|
|
1091
1211
|
};
|
|
1092
|
-
},
|
|
1093
|
-
if ("not" in e) return { not:
|
|
1094
|
-
if ("and" in e) return { and: e.and.map((e) =>
|
|
1095
|
-
if ("or" in e) return { or: e.or.map((e) =>
|
|
1212
|
+
}, H = (e) => {
|
|
1213
|
+
if ("not" in e) return { not: H(e.not) };
|
|
1214
|
+
if ("and" in e) return { and: e.and.map((e) => H(e)) };
|
|
1215
|
+
if ("or" in e) return { or: e.or.map((e) => H(e)) };
|
|
1096
1216
|
if (e.op === "subquery-in" || e.op === "subquery-not-in" || e.op === "exists" || e.op === "not-exists") return e;
|
|
1097
1217
|
let t = e;
|
|
1098
1218
|
return {
|
|
1099
1219
|
...t,
|
|
1100
|
-
value:
|
|
1220
|
+
value: gi(t.value)
|
|
1101
1221
|
};
|
|
1102
|
-
},
|
|
1103
|
-
e.actors !== void 0 && (
|
|
1104
|
-
},
|
|
1222
|
+
}, gi = (e) => e == null ? e : e instanceof Date ? e.toISOString() : typeof e == "boolean" ? +!!e : Array.isArray(e) ? e.map((e) => gi(e)) : e, _i = Symbol.for("@voltro/database/coreTablesRegistry"), vi = globalThis, yi = vi[_i] ?? (vi[_i] = {}), bi = (e) => {
|
|
1223
|
+
e.actors !== void 0 && (yi.actors = e.actors), e.tenants !== void 0 && (yi.tenants = e.tenants);
|
|
1224
|
+
}, xi = (e, t) => () => {
|
|
1105
1225
|
let n = e();
|
|
1106
1226
|
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`);
|
|
1107
1227
|
return n();
|
|
1108
|
-
},
|
|
1109
|
-
id:
|
|
1110
|
-
kind:
|
|
1228
|
+
}, Si = () => xi(() => yi.actors, "actors"), Ci = () => xi(() => yi.tenants, "tenants"), wi = C("actors", {
|
|
1229
|
+
id: v(),
|
|
1230
|
+
kind: E().oneOf([
|
|
1111
1231
|
"user",
|
|
1112
1232
|
"serviceAccount",
|
|
1113
1233
|
"apiKey",
|
|
1114
1234
|
"system"
|
|
1115
1235
|
]),
|
|
1116
|
-
displayName:
|
|
1117
|
-
createdAt:
|
|
1118
|
-
}),
|
|
1236
|
+
displayName: E().nullable(),
|
|
1237
|
+
createdAt: b().default("now")
|
|
1238
|
+
}), Ti = (e, t) => ({
|
|
1119
1239
|
column: e,
|
|
1120
1240
|
op: "eq",
|
|
1121
1241
|
value: t
|
|
1122
|
-
}),
|
|
1242
|
+
}), Ei = (e, t) => ({
|
|
1123
1243
|
column: e,
|
|
1124
1244
|
op: "neq",
|
|
1125
1245
|
value: t
|
|
1126
|
-
}),
|
|
1246
|
+
}), Di = (e, t) => ({
|
|
1127
1247
|
column: e,
|
|
1128
1248
|
op: "gt",
|
|
1129
1249
|
value: t
|
|
1130
|
-
}),
|
|
1250
|
+
}), Oi = (e, t) => ({
|
|
1131
1251
|
column: e,
|
|
1132
1252
|
op: "gte",
|
|
1133
1253
|
value: t
|
|
1134
|
-
}),
|
|
1254
|
+
}), ki = (e, t) => ({
|
|
1135
1255
|
column: e,
|
|
1136
1256
|
op: "lt",
|
|
1137
1257
|
value: t
|
|
1138
|
-
}),
|
|
1258
|
+
}), Ai = (e, t) => ({
|
|
1139
1259
|
column: e,
|
|
1140
1260
|
op: "lte",
|
|
1141
1261
|
value: t
|
|
1142
|
-
}),
|
|
1262
|
+
}), ji = (e, t) => ({
|
|
1143
1263
|
column: e,
|
|
1144
1264
|
op: "in",
|
|
1145
1265
|
value: t
|
|
1146
|
-
}),
|
|
1266
|
+
}), Mi = (e, t) => ({
|
|
1147
1267
|
column: e,
|
|
1148
1268
|
op: "notIn",
|
|
1149
1269
|
value: t
|
|
1150
|
-
}),
|
|
1270
|
+
}), Ni = (e, t) => ({
|
|
1151
1271
|
column: e,
|
|
1152
1272
|
op: "contains",
|
|
1153
1273
|
value: t
|
|
1154
|
-
}),
|
|
1274
|
+
}), Pi = (e, t) => ({
|
|
1155
1275
|
column: e,
|
|
1156
1276
|
op: "startsWith",
|
|
1157
1277
|
value: t
|
|
1158
|
-
}),
|
|
1278
|
+
}), Fi = (e, t) => ({
|
|
1159
1279
|
column: e,
|
|
1160
1280
|
op: "arrayContains",
|
|
1161
1281
|
value: t
|
|
1162
|
-
}),
|
|
1282
|
+
}), Ii = (e, t) => ({
|
|
1163
1283
|
column: e,
|
|
1164
1284
|
op: "arrayOverlaps",
|
|
1165
1285
|
value: t
|
|
1166
|
-
}),
|
|
1286
|
+
}), Li = (e, t) => ({
|
|
1167
1287
|
column: e,
|
|
1168
1288
|
op: "arrayHas",
|
|
1169
1289
|
value: t
|
|
1170
|
-
}),
|
|
1290
|
+
}), Ri = {
|
|
1171
1291
|
column: "id",
|
|
1172
1292
|
op: "in",
|
|
1173
1293
|
value: []
|
|
1174
|
-
},
|
|
1294
|
+
}, zi = (e) => ({
|
|
1175
1295
|
column: e,
|
|
1176
1296
|
op: "isNull"
|
|
1177
|
-
}),
|
|
1297
|
+
}), Bi = (e) => ({
|
|
1178
1298
|
column: e,
|
|
1179
1299
|
op: "isNotNull"
|
|
1180
|
-
}),
|
|
1300
|
+
}), Vi = (e, t) => ({
|
|
1181
1301
|
column: e,
|
|
1182
1302
|
op: "spatial",
|
|
1183
1303
|
value: t
|
|
1184
|
-
}),
|
|
1304
|
+
}), Hi = (...e) => ({ and: e }), Ui = (...e) => ({ or: e }), Wi = (e) => ({ not: e }), Gi = (e, ...t) => {
|
|
1185
1305
|
if (t.length === 0) throw Error(`jsonField("${e}"): at least one path segment is required`);
|
|
1186
1306
|
let n = (n, r) => ({
|
|
1187
1307
|
column: e,
|
|
@@ -1203,33 +1323,33 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
1203
1323
|
isNull: () => n("isNull"),
|
|
1204
1324
|
isNotNull: () => n("isNotNull")
|
|
1205
1325
|
};
|
|
1206
|
-
},
|
|
1326
|
+
}, Ki = (e) => "descriptor" in e ? e.descriptor : e, qi = (e, t) => ({
|
|
1207
1327
|
column: e,
|
|
1208
1328
|
op: "subquery-in",
|
|
1209
|
-
subquery:
|
|
1210
|
-
}),
|
|
1329
|
+
subquery: Ki(t)
|
|
1330
|
+
}), Ji = (e, t) => ({
|
|
1211
1331
|
column: e,
|
|
1212
1332
|
op: "subquery-not-in",
|
|
1213
|
-
subquery:
|
|
1214
|
-
}),
|
|
1333
|
+
subquery: Ki(t)
|
|
1334
|
+
}), Yi = (e) => ({
|
|
1215
1335
|
op: "exists",
|
|
1216
|
-
subquery:
|
|
1217
|
-
}),
|
|
1336
|
+
subquery: Ki(e)
|
|
1337
|
+
}), Xi = (e) => ({
|
|
1218
1338
|
op: "not-exists",
|
|
1219
|
-
subquery:
|
|
1220
|
-
}),
|
|
1339
|
+
subquery: Ki(e)
|
|
1340
|
+
}), Zi = (e, t) => e === t || e instanceof Date && t instanceof Date && e.getTime() === t.getTime(), Qi = (e, t) => {
|
|
1221
1341
|
if (e == null || t == null) return null;
|
|
1222
1342
|
let n = e instanceof Date ? e.getTime() : e, r = t instanceof Date ? t.getTime() : t;
|
|
1223
1343
|
return typeof n == typeof r ? n === r ? 0 : n > r ? 1 : -1 : null;
|
|
1224
|
-
},
|
|
1344
|
+
}, $i = (e, t, n = null) => {
|
|
1225
1345
|
if (!t) return !1;
|
|
1226
|
-
if ("not" in e) return
|
|
1346
|
+
if ("not" in e) return !$i(e.not, t, n);
|
|
1227
1347
|
if ("and" in e) {
|
|
1228
|
-
for (let r of e.and) if (
|
|
1348
|
+
for (let r of e.and) if (!$i(r, t, n)) return !1;
|
|
1229
1349
|
return !0;
|
|
1230
1350
|
}
|
|
1231
1351
|
if ("or" in e) {
|
|
1232
|
-
for (let r of e.or) if (
|
|
1352
|
+
for (let r of e.or) if ($i(r, t, n)) return !0;
|
|
1233
1353
|
return !1;
|
|
1234
1354
|
}
|
|
1235
1355
|
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
@@ -1246,14 +1366,14 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
1246
1366
|
}
|
|
1247
1367
|
let r = e, i = t[r.column];
|
|
1248
1368
|
switch (r.op) {
|
|
1249
|
-
case "eq": return
|
|
1250
|
-
case "neq": return !
|
|
1251
|
-
case "gt": return (
|
|
1252
|
-
case "gte": return (
|
|
1253
|
-
case "lt": return (
|
|
1254
|
-
case "lte": return (
|
|
1255
|
-
case "in": return Array.isArray(r.value) && r.value.some((e) =>
|
|
1256
|
-
case "notIn": return Array.isArray(r.value) && !r.value.some((e) =>
|
|
1369
|
+
case "eq": return Zi(i, r.value);
|
|
1370
|
+
case "neq": return !Zi(i, r.value);
|
|
1371
|
+
case "gt": return (Qi(i, r.value) ?? -1) > 0;
|
|
1372
|
+
case "gte": return (Qi(i, r.value) ?? -1) >= 0;
|
|
1373
|
+
case "lt": return (Qi(i, r.value) ?? 1) < 0;
|
|
1374
|
+
case "lte": return (Qi(i, r.value) ?? 1) <= 0;
|
|
1375
|
+
case "in": return Array.isArray(r.value) && r.value.some((e) => Zi(i, e));
|
|
1376
|
+
case "notIn": return Array.isArray(r.value) && !r.value.some((e) => Zi(i, e));
|
|
1257
1377
|
case "contains": return typeof i == "string" && typeof r.value == "string" && i.toLowerCase().includes(r.value.toLowerCase());
|
|
1258
1378
|
case "startsWith": return typeof i == "string" && typeof r.value == "string" && i.startsWith(r.value);
|
|
1259
1379
|
case "arrayContains": {
|
|
@@ -1269,17 +1389,17 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
1269
1389
|
case "isNotNull": return i != null;
|
|
1270
1390
|
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.");
|
|
1271
1391
|
}
|
|
1272
|
-
},
|
|
1392
|
+
}, ea = function* (e) {
|
|
1273
1393
|
if ("not" in e) {
|
|
1274
|
-
yield*
|
|
1394
|
+
yield* ea(e.not);
|
|
1275
1395
|
return;
|
|
1276
1396
|
}
|
|
1277
1397
|
if ("and" in e) {
|
|
1278
|
-
for (let t of e.and) yield*
|
|
1398
|
+
for (let t of e.and) yield* ea(t);
|
|
1279
1399
|
return;
|
|
1280
1400
|
}
|
|
1281
1401
|
if ("or" in e) {
|
|
1282
|
-
for (let t of e.or) yield*
|
|
1402
|
+
for (let t of e.or) yield* ea(t);
|
|
1283
1403
|
return;
|
|
1284
1404
|
}
|
|
1285
1405
|
e.op === "subquery-in" || e.op === "subquery-not-in" ? yield {
|
|
@@ -1289,42 +1409,46 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
1289
1409
|
kind: "exists",
|
|
1290
1410
|
descriptor: e.subquery
|
|
1291
1411
|
});
|
|
1292
|
-
},
|
|
1412
|
+
}, ta = function* (e, t = !0) {
|
|
1293
1413
|
if ("not" in e) {
|
|
1294
|
-
yield*
|
|
1414
|
+
yield* ta(e.not, !1);
|
|
1295
1415
|
return;
|
|
1296
1416
|
}
|
|
1297
1417
|
if ("and" in e) {
|
|
1298
|
-
for (let n of e.and) yield*
|
|
1418
|
+
for (let n of e.and) yield* ta(n, t);
|
|
1299
1419
|
return;
|
|
1300
1420
|
}
|
|
1301
1421
|
if ("or" in e) {
|
|
1302
|
-
for (let t of e.or) yield*
|
|
1422
|
+
for (let t of e.or) yield* ta(t, !1);
|
|
1303
1423
|
return;
|
|
1304
1424
|
}
|
|
1305
1425
|
e.op === "subquery-in" || e.op === "subquery-not-in" || e.op === "exists" || e.op === "not-exists" || (yield {
|
|
1306
1426
|
...e,
|
|
1307
1427
|
conjunctive: t
|
|
1308
1428
|
});
|
|
1309
|
-
},
|
|
1429
|
+
}, na = (e, t) => ({
|
|
1430
|
+
...t,
|
|
1431
|
+
...e,
|
|
1432
|
+
origin: e.origin ?? "injected"
|
|
1433
|
+
}), ra = (e, t, n = {}) => ({
|
|
1310
1434
|
table: e,
|
|
1311
1435
|
op: "insert",
|
|
1312
1436
|
old: null,
|
|
1313
1437
|
new: t,
|
|
1314
1438
|
...n
|
|
1315
|
-
}),
|
|
1439
|
+
}), ia = (e, t, n, r = {}) => ({
|
|
1316
1440
|
table: e,
|
|
1317
1441
|
op: "update",
|
|
1318
1442
|
old: t,
|
|
1319
1443
|
new: n,
|
|
1320
1444
|
...r
|
|
1321
|
-
}),
|
|
1445
|
+
}), aa = (e, t, n = {}) => ({
|
|
1322
1446
|
table: e,
|
|
1323
1447
|
op: "delete",
|
|
1324
1448
|
old: t,
|
|
1325
1449
|
new: null,
|
|
1326
1450
|
...n
|
|
1327
|
-
}),
|
|
1451
|
+
}), oa = (e, t, n = {}) => {
|
|
1328
1452
|
let { at: r = "2026-01-01T00:00:00.000Z", column: i = "deletedAt", ...a } = n;
|
|
1329
1453
|
return {
|
|
1330
1454
|
table: e,
|
|
@@ -1339,66 +1463,67 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
1339
1463
|
},
|
|
1340
1464
|
...a
|
|
1341
1465
|
};
|
|
1342
|
-
},
|
|
1343
|
-
let t = e ??
|
|
1466
|
+
}, sa = new kt(), ca = (e, t) => sa.run(e, t), la = () => sa.getStore(), ua = (e) => {
|
|
1467
|
+
let t = e ?? sa.getStore();
|
|
1344
1468
|
return t === void 0 ? {} : {
|
|
1345
1469
|
...t.traceId === void 0 ? {} : { traceId: t.traceId },
|
|
1346
1470
|
...t.subjectId === void 0 ? {} : { subjectId: t.subjectId },
|
|
1347
|
-
...t.procedure === void 0 ? {} : { procedure: t.procedure }
|
|
1471
|
+
...t.procedure === void 0 ? {} : { procedure: t.procedure },
|
|
1472
|
+
...t.via === void 0 ? {} : { via: t.via }
|
|
1348
1473
|
};
|
|
1349
|
-
},
|
|
1350
|
-
let t =
|
|
1351
|
-
return t === void 0 ? e(void 0) :
|
|
1352
|
-
},
|
|
1353
|
-
for (let [t, n] of
|
|
1354
|
-
let r = n.filter((t) => e - t.at <
|
|
1355
|
-
|
|
1356
|
-
}
|
|
1357
|
-
},
|
|
1474
|
+
}, da = (e) => {
|
|
1475
|
+
let t = sa.getStore();
|
|
1476
|
+
return t === void 0 ? e(void 0) : sa.run(t, () => e(t));
|
|
1477
|
+
}, fa = 3e4, pa = 1e4, U = /* @__PURE__ */ new Map(), W = 0, ma = (e, t, n) => `${e}\u0000${t}\u0000${String(n)}`, ha = (e) => {
|
|
1478
|
+
for (let [t, n] of U) {
|
|
1479
|
+
let r = n.filter((t) => e - t.at < fa);
|
|
1480
|
+
W -= n.length - r.length, r.length === 0 ? U.delete(t) : r.length !== n.length && U.set(t, r);
|
|
1481
|
+
}
|
|
1482
|
+
}, ga = (e, t) => {
|
|
1358
1483
|
if (t.traceId === void 0 && t.subjectId === void 0 && t.procedure === void 0) return;
|
|
1359
1484
|
let n = Date.now();
|
|
1360
|
-
if (
|
|
1361
|
-
let r =
|
|
1362
|
-
r === void 0 ?
|
|
1485
|
+
if (W >= pa && ha(n), W >= pa) return;
|
|
1486
|
+
let r = U.get(e);
|
|
1487
|
+
r === void 0 ? U.set(e, [{
|
|
1363
1488
|
attribution: t,
|
|
1364
1489
|
at: n
|
|
1365
1490
|
}]) : r.push({
|
|
1366
1491
|
attribution: t,
|
|
1367
1492
|
at: n
|
|
1368
|
-
}),
|
|
1369
|
-
},
|
|
1370
|
-
let t =
|
|
1493
|
+
}), W += 1;
|
|
1494
|
+
}, _a = (e) => {
|
|
1495
|
+
let t = U.get(e);
|
|
1371
1496
|
if (t === void 0 || t.length === 0) return;
|
|
1372
1497
|
let n = t.shift();
|
|
1373
|
-
if (--
|
|
1374
|
-
},
|
|
1375
|
-
let t =
|
|
1498
|
+
if (--W, t.length === 0 && U.delete(e), !(Date.now() - n.at >= fa)) return n.attribution;
|
|
1499
|
+
}, va = (e) => (U.get(e)?.length ?? 0) > 0, G = /* @__PURE__ */ new Map(), K = /* @__PURE__ */ new Map(), ya = /* @__PURE__ */ new Map(), ba = 250, xa = (e) => {
|
|
1500
|
+
let t = K.get(e);
|
|
1376
1501
|
if (t === void 0) return;
|
|
1377
|
-
|
|
1378
|
-
let n =
|
|
1379
|
-
n !== void 0 && (clearTimeout(n),
|
|
1502
|
+
K.delete(e);
|
|
1503
|
+
let n = ya.get(e);
|
|
1504
|
+
n !== void 0 && (clearTimeout(n), ya.delete(e));
|
|
1380
1505
|
for (let e of t) e();
|
|
1381
|
-
},
|
|
1382
|
-
|
|
1383
|
-
},
|
|
1384
|
-
let t = (
|
|
1506
|
+
}, Sa = (e) => {
|
|
1507
|
+
G.set(e, (G.get(e) ?? 0) + 1);
|
|
1508
|
+
}, Ca = (e) => {
|
|
1509
|
+
let t = (G.get(e) ?? 0) - 1;
|
|
1385
1510
|
if (t > 0) {
|
|
1386
|
-
|
|
1511
|
+
G.set(e, t);
|
|
1387
1512
|
return;
|
|
1388
1513
|
}
|
|
1389
|
-
|
|
1390
|
-
},
|
|
1391
|
-
let i = n == null ? void 0 :
|
|
1514
|
+
G.delete(e), xa(e);
|
|
1515
|
+
}, wa = (e, t, n, r) => {
|
|
1516
|
+
let i = n == null ? void 0 : ma(e, t, n), a = () => r(i === void 0 ? void 0 : _a(i));
|
|
1392
1517
|
if (i === void 0) {
|
|
1393
1518
|
a();
|
|
1394
1519
|
return;
|
|
1395
1520
|
}
|
|
1396
|
-
if (
|
|
1521
|
+
if (va(i)) {
|
|
1397
1522
|
a();
|
|
1398
1523
|
return;
|
|
1399
1524
|
}
|
|
1400
|
-
let o =
|
|
1401
|
-
if (o === void 0 && (
|
|
1525
|
+
let o = K.get(e);
|
|
1526
|
+
if (o === void 0 && (G.get(e) ?? 0) === 0) {
|
|
1402
1527
|
a();
|
|
1403
1528
|
return;
|
|
1404
1529
|
}
|
|
@@ -1406,38 +1531,124 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
1406
1531
|
o.push(a);
|
|
1407
1532
|
return;
|
|
1408
1533
|
}
|
|
1409
|
-
|
|
1410
|
-
let s = setTimeout(() =>
|
|
1411
|
-
typeof s == "object" && typeof s.unref == "function" && s.unref(),
|
|
1412
|
-
},
|
|
1413
|
-
|
|
1414
|
-
for (let e of
|
|
1415
|
-
|
|
1416
|
-
},
|
|
1417
|
-
|
|
1534
|
+
K.set(e, [a]);
|
|
1535
|
+
let s = setTimeout(() => xa(e), ba);
|
|
1536
|
+
typeof s == "object" && typeof s.unref == "function" && s.unref(), ya.set(e, s);
|
|
1537
|
+
}, Ta = () => {
|
|
1538
|
+
U.clear(), W = 0, G.clear();
|
|
1539
|
+
for (let e of ya.values()) clearTimeout(e);
|
|
1540
|
+
ya.clear(), K.clear();
|
|
1541
|
+
}, Ea = () => W, q = /* @__PURE__ */ new Map(), Da = (e, t) => {
|
|
1542
|
+
q.set(e, {
|
|
1418
1543
|
recorder: t.recorder,
|
|
1419
1544
|
tables: new Set(t.tables),
|
|
1420
1545
|
ownTables: new Set(t.ownTables)
|
|
1421
1546
|
});
|
|
1422
|
-
},
|
|
1423
|
-
|
|
1424
|
-
},
|
|
1425
|
-
if (
|
|
1426
|
-
for (let t of
|
|
1547
|
+
}, Oa = (e) => {
|
|
1548
|
+
q.delete(e);
|
|
1549
|
+
}, ka = () => q.clear(), Aa = (e) => {
|
|
1550
|
+
if (q.size === 0) return !1;
|
|
1551
|
+
for (let t of q.values()) if (!t.ownTables.has(e) && t.tables.has(e)) return !0;
|
|
1427
1552
|
return !1;
|
|
1428
|
-
},
|
|
1429
|
-
if (
|
|
1430
|
-
},
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1553
|
+
}, ja = async (e, t) => {
|
|
1554
|
+
if (q.size !== 0) for (let n of q.values()) n.ownTables.has(t.table) || n.tables.has(t.table) && await n.recorder(e, t);
|
|
1555
|
+
}, Ma = Et.exponential({
|
|
1556
|
+
start: 5e-4,
|
|
1557
|
+
factor: 2,
|
|
1558
|
+
count: 16
|
|
1559
|
+
}), Na = k.counter("voltro_db_queries_total", { description: "Database operations executed, by dialect and operation kind." }), Pa = k.histogram("voltro_db_query_duration_seconds", Ma, "Database operation duration in seconds, by dialect and operation kind."), Fa = k.counter("voltro_db_errors_total", { description: "Database operations that threw, by dialect and operation kind." }), Ia = k.gauge("voltro_db_operations_in_flight", { description: "Database operations currently executing, by dialect. An upper bound on connections the framework holds; NOT the driver pool's waiting count." }), La = k.counter("voltro_db_eager_fallback_total", { description: "Eager-load queries that degraded from the single-roundtrip JSON-agg path to the multi-query walker, by dialect and reason." }), Ra = [], za = /* @__PURE__ */ new Map(), Ba = /* @__PURE__ */ new Map(), Va = /* @__PURE__ */ new Map(), Ha = (e, t) => {
|
|
1560
|
+
let n = `${e}\u0000${t}`, r = za.get(n);
|
|
1561
|
+
if (r !== void 0) return r;
|
|
1562
|
+
let i = (n) => k.tagged(k.tagged(n, "dialect", e), "op", t), a = {
|
|
1563
|
+
count: i(Na),
|
|
1564
|
+
duration: i(Pa),
|
|
1565
|
+
errors: i(Fa)
|
|
1566
|
+
};
|
|
1567
|
+
return za.set(n, a), a;
|
|
1568
|
+
}, Ua = () => {
|
|
1569
|
+
za.clear(), Ba.clear(), Va.clear();
|
|
1570
|
+
}, Wa = () => za.size + Ba.size + Va.size, Ga = /* @__PURE__ */ new Map(), Ka = (e, t) => {
|
|
1571
|
+
let n = Math.max(0, (Ga.get(e) ?? 0) + t);
|
|
1572
|
+
n === 0 ? Ga.delete(e) : Ga.set(e, n);
|
|
1573
|
+
let r = Ba.get(e);
|
|
1574
|
+
r === void 0 && (r = k.tagged(Ia, "dialect", e), Ba.set(e, r)), r.unsafeUpdate(n, Ra);
|
|
1575
|
+
}, qa = (e) => Ga.get(e) ?? 0, Ja = (e) => {
|
|
1576
|
+
let t = Ha(String(e.dialect), e.op);
|
|
1577
|
+
t.count.unsafeUpdate(1, Ra), t.duration.unsafeUpdate(e.durationMs / 1e3, Ra), e.status === "error" && t.errors.unsafeUpdate(1, Ra);
|
|
1578
|
+
}, Ya = async (e, t, n) => {
|
|
1579
|
+
let r = performance.now(), i = String(e);
|
|
1580
|
+
Ka(i, 1);
|
|
1581
|
+
let a = "ok";
|
|
1582
|
+
try {
|
|
1583
|
+
return await n();
|
|
1584
|
+
} catch (e) {
|
|
1585
|
+
throw a = "error", e;
|
|
1586
|
+
} finally {
|
|
1587
|
+
Ka(i, -1), Ja({
|
|
1588
|
+
dialect: e,
|
|
1589
|
+
op: t,
|
|
1590
|
+
durationMs: performance.now() - r,
|
|
1591
|
+
status: a
|
|
1592
|
+
});
|
|
1593
|
+
}
|
|
1594
|
+
}, Xa = 3e5, Za = (e) => {
|
|
1595
|
+
if (e == null || e === "") return;
|
|
1596
|
+
let t = Number(e);
|
|
1597
|
+
return Number.isFinite(t) && t >= 0 ? Math.floor(t) : void 0;
|
|
1598
|
+
}, Qa = (e, t = process.env) => Za(t.VOLTRO_DB_EAGER_FALLBACK_WARN_INTERVAL_MS) ?? Za(e) ?? 3e5, $a = (e, t = {}) => {
|
|
1599
|
+
let n = Qa(t.warnIntervalMs), r = t.now ?? (() => Date.now()), i = /* @__PURE__ */ new Map();
|
|
1600
|
+
return (t) => {
|
|
1601
|
+
let a = `${t.dialect} ${t.reason}`, o = Va.get(a);
|
|
1602
|
+
o === void 0 && (o = k.tagged(k.tagged(La, "dialect", String(t.dialect)), "reason", t.reason), Va.set(a, o)), o.unsafeUpdate(1, Ra);
|
|
1603
|
+
let s = `${t.table}\u0000${t.reason}`, c = i.get(s), l = c === void 0 || n > 0 && r() - c >= n, u = {
|
|
1604
|
+
table: t.table,
|
|
1605
|
+
dialect: String(t.dialect),
|
|
1606
|
+
reason: t.reason,
|
|
1607
|
+
metric: "voltro_db_eager_fallback_total",
|
|
1608
|
+
...t.error === void 0 ? {} : { err: t.error }
|
|
1609
|
+
};
|
|
1610
|
+
if (!l) {
|
|
1611
|
+
e.debug("eager-load is still running on the walker (rate-limited; the counter is not)", u);
|
|
1612
|
+
return;
|
|
1613
|
+
}
|
|
1614
|
+
i.set(s, r()), e.warn(t.reason === "execute-failed" ? "eager-load JSON-agg statement FAILED and was re-run on the multi-query walker — this query pays both paths on every call. Counted as voltro_db_eager_fallback_total{reason=\"execute-failed\"}." : "eager-load could not be compiled to a single JSON-agg roundtrip and is running on the multi-query walker — one round trip per relation level, on every call. Counted as voltro_db_eager_fallback_total{reason=\"not-compilable\"}.", u);
|
|
1615
|
+
};
|
|
1616
|
+
}, eo = (e) => {
|
|
1617
|
+
if (Tt.isSuccess(e)) return e.value;
|
|
1618
|
+
throw St.squash(e.cause);
|
|
1619
|
+
}, to = "10 millis", no = 3, ro = async (e) => {
|
|
1620
|
+
let t = 0, n = O.suspend(() => {
|
|
1621
|
+
let n = ++t;
|
|
1622
|
+
return e.withTransaction(O.flatMap(O.serviceOption(At), (t) => {
|
|
1623
|
+
if (A.isNone(t)) return O.fail(/* @__PURE__ */ Error(`${e.label}: TransactionConnection unexpectedly missing inside withTransaction.`));
|
|
1624
|
+
let r = t.value, i = O.tryPromise({
|
|
1625
|
+
try: () => e.body(r, n),
|
|
1626
|
+
catch: (e) => e
|
|
1627
|
+
});
|
|
1628
|
+
return e.prepare === void 0 ? i : O.flatMap(e.prepare(r), () => i);
|
|
1629
|
+
})).pipe(O.catchAllDefect((t) => e.isRetryable(t) ? O.fail(t) : O.die(t)));
|
|
1630
|
+
}), r = Dt.exponential(to).pipe(Dt.compose(Dt.recurs(no)), Dt.whileInput(e.isRetryable)), i = n.pipe(O.retry(r), O.withSpan(e.span.name, { attributes: { ...e.span.attributes } }));
|
|
1631
|
+
return Ya(e.dialect, "transaction", async () => eo(await e.runPromiseExit(e.wrapProgram === void 0 ? i : e.wrapProgram(i))));
|
|
1632
|
+
}, io = async (e) => {
|
|
1633
|
+
let t = la(), n = t === void 0 ? (e) => e() : (e) => ca(t, e), r = await ro({
|
|
1634
|
+
...e,
|
|
1635
|
+
body: (r) => {
|
|
1636
|
+
let i = e.makeView(r, t);
|
|
1637
|
+
return n(() => e.work(i)).then((e) => ({
|
|
1638
|
+
result: e,
|
|
1639
|
+
view: i
|
|
1640
|
+
}));
|
|
1641
|
+
}
|
|
1642
|
+
});
|
|
1643
|
+
return r.view.commitEvents(), r.result;
|
|
1644
|
+
}, ao = class extends j.TaggedError()("VersionConflict", {
|
|
1645
|
+
table: j.String,
|
|
1646
|
+
id: j.String,
|
|
1647
|
+
expected: j.Number,
|
|
1648
|
+
actual: j.NullOr(j.Number)
|
|
1649
|
+
}) {}, oo = (e) => {
|
|
1439
1650
|
for (let [t, n] of Object.entries(e)) if (n?.definition?.versionColumn === !0) return t;
|
|
1440
|
-
},
|
|
1651
|
+
}, so = (e) => {
|
|
1441
1652
|
let { versionColumn: t, patch: n } = e;
|
|
1442
1653
|
if (t === void 0) return {
|
|
1443
1654
|
nextVersion: void 0,
|
|
@@ -1450,28 +1661,28 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
1450
1661
|
expected: i,
|
|
1451
1662
|
patch: a
|
|
1452
1663
|
};
|
|
1453
|
-
},
|
|
1454
|
-
if (e.expected !== void 0 && !(e.current !== null && e.current === e.expected)) return new
|
|
1664
|
+
}, co = (e) => {
|
|
1665
|
+
if (e.expected !== void 0 && !(e.current !== null && e.current === e.expected)) return new ao({
|
|
1455
1666
|
table: e.table,
|
|
1456
1667
|
id: e.id,
|
|
1457
1668
|
expected: e.expected,
|
|
1458
1669
|
actual: e.current
|
|
1459
1670
|
});
|
|
1460
|
-
},
|
|
1461
|
-
id:
|
|
1462
|
-
fields: { expiresAt:
|
|
1671
|
+
}, lo = 1, uo = "voltro/expires", fo = () => $e({
|
|
1672
|
+
id: uo,
|
|
1673
|
+
fields: { expiresAt: b().nullable() },
|
|
1463
1674
|
behaviors: { defaultWhere: () => "expiresAt IS NULL OR expiresAt > now()" }
|
|
1464
|
-
}),
|
|
1465
|
-
id:
|
|
1675
|
+
}), po = "voltro/localFirst", mo = () => $e({
|
|
1676
|
+
id: po,
|
|
1466
1677
|
fields: {}
|
|
1467
|
-
}),
|
|
1678
|
+
}), ho = (e) => e.appliedMixins.some((e) => e.id === po), go = (e) => {
|
|
1468
1679
|
let t = [];
|
|
1469
|
-
for (let n of Object.values(e))
|
|
1680
|
+
for (let n of Object.values(e)) ho(n) && t.push(n.tableName);
|
|
1470
1681
|
return t;
|
|
1471
|
-
},
|
|
1472
|
-
let i =
|
|
1682
|
+
}, _o = class extends wt.TaggedError("TableStreamError") {}, vo = 1e3, yo = (e, t, n, r) => {
|
|
1683
|
+
let i = A.match(r, {
|
|
1473
1684
|
onNone: () => e.where,
|
|
1474
|
-
onSome: (n) => e.where ?
|
|
1685
|
+
onSome: (n) => e.where ? Hi(e.where, Di(t, n)) : Di(t, n)
|
|
1475
1686
|
});
|
|
1476
1687
|
return {
|
|
1477
1688
|
table: e.table,
|
|
@@ -1486,56 +1697,56 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
1486
1697
|
...e.includeDeleted === void 0 ? {} : { includeDeleted: e.includeDeleted },
|
|
1487
1698
|
...e.crossTenant === void 0 ? {} : { crossTenant: e.crossTenant }
|
|
1488
1699
|
};
|
|
1489
|
-
},
|
|
1490
|
-
let n = t.pk ?? "id", r = t.chunkSize ??
|
|
1491
|
-
return
|
|
1492
|
-
let a =
|
|
1493
|
-
try: () => e.query(
|
|
1494
|
-
catch: (e) => new
|
|
1700
|
+
}, bo = (e, t) => {
|
|
1701
|
+
let n = t.pk ?? "id", r = t.chunkSize ?? vo;
|
|
1702
|
+
return Ot.paginateChunkEffect(A.none(), (i) => {
|
|
1703
|
+
let a = O.tryPromise({
|
|
1704
|
+
try: () => e.query(yo(t, n, r, i)),
|
|
1705
|
+
catch: (e) => new _o({
|
|
1495
1706
|
table: t.table,
|
|
1496
1707
|
cause: e
|
|
1497
1708
|
})
|
|
1498
1709
|
});
|
|
1499
|
-
return (t.retry ? a.pipe(
|
|
1710
|
+
return (t.retry ? a.pipe(O.retry(t.retry)) : a).pipe(O.map((e) => [Ct.fromIterable(e), e.length === r && e.length > 0 ? A.some(A.some(e[e.length - 1][n])) : A.none()]));
|
|
1500
1711
|
});
|
|
1501
|
-
},
|
|
1502
|
-
let
|
|
1503
|
-
if (
|
|
1504
|
-
return (
|
|
1505
|
-
let
|
|
1712
|
+
}, xo = (e) => {
|
|
1713
|
+
let t = e.alpha ?? .5;
|
|
1714
|
+
if (t < 0 || t > 1) throw Error(`hybridSearch: alpha must be in [0, 1], got ${t}`);
|
|
1715
|
+
return (n) => {
|
|
1716
|
+
let r = Array.isArray(e.vector.query) ? {
|
|
1506
1717
|
column: e.vector.col,
|
|
1507
1718
|
queryVector: e.vector.query,
|
|
1508
1719
|
distance: e.vector.distance ?? "cosine",
|
|
1509
|
-
alpha:
|
|
1720
|
+
alpha: t
|
|
1510
1721
|
} : {
|
|
1511
1722
|
column: e.vector.col,
|
|
1512
1723
|
queryText: e.vector.query,
|
|
1513
1724
|
distance: e.vector.distance ?? "cosine",
|
|
1514
|
-
alpha:
|
|
1515
|
-
},
|
|
1725
|
+
alpha: t
|
|
1726
|
+
}, i = _(n.table, e.fts.indexName, n.fullTextIndexes);
|
|
1516
1727
|
return {
|
|
1517
|
-
...
|
|
1518
|
-
annClause:
|
|
1728
|
+
...n,
|
|
1729
|
+
annClause: r,
|
|
1519
1730
|
fullTextSearch: {
|
|
1520
1731
|
indexName: e.fts.indexName,
|
|
1521
1732
|
query: e.fts.query,
|
|
1522
|
-
columns:
|
|
1523
|
-
...
|
|
1524
|
-
...
|
|
1733
|
+
columns: i.columns,
|
|
1734
|
+
...i.config === void 0 ? {} : { config: i.config },
|
|
1735
|
+
...i.weights === void 0 ? {} : { weights: i.weights }
|
|
1525
1736
|
}
|
|
1526
1737
|
};
|
|
1527
1738
|
};
|
|
1528
|
-
},
|
|
1739
|
+
}, So = async (e, t) => {
|
|
1529
1740
|
let n = e.as ?? "embedding", r = t.row[e.from];
|
|
1530
1741
|
if (typeof r != "string" || r.length === 0) return {};
|
|
1531
1742
|
let i = await t.embed(r);
|
|
1532
1743
|
return { [n]: i };
|
|
1533
|
-
},
|
|
1744
|
+
}, Co = (e) => {
|
|
1534
1745
|
if (!Number.isInteger(e.dimensions) || e.dimensions <= 0) throw Error(`vectorEmbedding: dimensions must be a positive integer, got ${String(e.dimensions)}.`);
|
|
1535
|
-
let t = e.as ?? "embedding", n = (t) =>
|
|
1536
|
-
return
|
|
1746
|
+
let t = e.as ?? "embedding", n = (t) => So(e, t);
|
|
1747
|
+
return $e({
|
|
1537
1748
|
id: "voltro/vectorEmbedding",
|
|
1538
|
-
fields: { [t]:
|
|
1749
|
+
fields: { [t]: Te(e.dimensions) },
|
|
1539
1750
|
...e.index === !1 ? {} : { indexes: [{
|
|
1540
1751
|
fields: [t],
|
|
1541
1752
|
kind: "hnsw",
|
|
@@ -1550,19 +1761,19 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
1550
1761
|
beforeUpdate: n
|
|
1551
1762
|
}
|
|
1552
1763
|
});
|
|
1553
|
-
},
|
|
1764
|
+
}, wo = 63, To = "br_pr", J = class extends Error {
|
|
1554
1765
|
_tag = "BranchNameInvalid";
|
|
1555
1766
|
constructor(e) {
|
|
1556
1767
|
super(e), this.name = "BranchNameInvalid";
|
|
1557
1768
|
}
|
|
1558
|
-
},
|
|
1559
|
-
if (!Number.isInteger(t) || t < 0) throw new
|
|
1560
|
-
let n =
|
|
1561
|
-
if (n.replace(/_/g, "") === "") throw new
|
|
1562
|
-
let r = `${
|
|
1563
|
-
if (r.length >
|
|
1769
|
+
}, Eo = (e, t) => {
|
|
1770
|
+
if (!Number.isInteger(t) || t < 0) throw new J(`prNumber must be a non-negative integer, got ${String(t)}`);
|
|
1771
|
+
let n = $n(e);
|
|
1772
|
+
if (n.replace(/_/g, "") === "") throw new J(`app slug '${e}' has no usable identifier characters`);
|
|
1773
|
+
let r = `${To}${t}_${n}`;
|
|
1774
|
+
if (r.length > wo) throw new J(`branch namespace '${r}' exceeds the ${wo}-byte identifier limit — use a shorter app slug`);
|
|
1564
1775
|
return r;
|
|
1565
|
-
},
|
|
1776
|
+
}, Do = (e) => e.startsWith(To), Oo = {
|
|
1566
1777
|
requested: {
|
|
1567
1778
|
provision: "provisioning",
|
|
1568
1779
|
destroy: "destroying"
|
|
@@ -1581,45 +1792,54 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
1581
1792
|
fail: "failed"
|
|
1582
1793
|
},
|
|
1583
1794
|
destroyed: {}
|
|
1584
|
-
},
|
|
1795
|
+
}, ko = class extends Error {
|
|
1585
1796
|
from;
|
|
1586
1797
|
event;
|
|
1587
1798
|
_tag = "BranchTransitionInvalid";
|
|
1588
1799
|
constructor(e, t) {
|
|
1589
1800
|
super(`invalid branch transition: ${e} --${t}-->`), this.from = e, this.event = t, this.name = "BranchTransitionInvalid";
|
|
1590
1801
|
}
|
|
1591
|
-
},
|
|
1592
|
-
let n =
|
|
1593
|
-
if (n === void 0) throw new
|
|
1802
|
+
}, Ao = (e, t) => {
|
|
1803
|
+
let n = Oo[e][t];
|
|
1804
|
+
if (n === void 0) throw new ko(e, t);
|
|
1594
1805
|
return n;
|
|
1595
|
-
},
|
|
1596
|
-
if (n === "copy" && (r === void 0 || r === "")) throw new
|
|
1597
|
-
let
|
|
1806
|
+
}, jo = (e, t, n, r, i = [], a = []) => {
|
|
1807
|
+
if (n === "copy" && (r === void 0 || r === "")) throw new J("seed 'copy' requires a parentNamespace to snapshot from");
|
|
1808
|
+
let o = [{
|
|
1598
1809
|
kind: "create-namespace",
|
|
1599
1810
|
detail: e
|
|
1600
1811
|
}];
|
|
1601
|
-
for (let n of t)
|
|
1812
|
+
for (let n of t) o.push({
|
|
1602
1813
|
kind: "create-table",
|
|
1603
1814
|
table: n,
|
|
1604
1815
|
detail: `${e}.${n}`
|
|
1605
1816
|
});
|
|
1606
|
-
|
|
1817
|
+
for (let t of a) o.push({
|
|
1818
|
+
kind: "restore-index-name",
|
|
1819
|
+
table: t.table,
|
|
1820
|
+
detail: `${e}.${t.table} ${t.unique ? "UNIQUE " : ""}(${t.columns.join(", ")}) → ${t.name}`
|
|
1821
|
+
});
|
|
1822
|
+
if (n === "copy") for (let n of t) o.push({
|
|
1607
1823
|
kind: "copy-table",
|
|
1608
1824
|
table: n,
|
|
1609
1825
|
detail: `${r}.${n} → ${e}.${n}`
|
|
1610
1826
|
});
|
|
1611
|
-
|
|
1827
|
+
for (let t of i) o.push({
|
|
1828
|
+
kind: "copy-foreign-key",
|
|
1829
|
+
table: t.table,
|
|
1830
|
+
detail: `${e}.${t.table}.${t.column} → ${e}.${t.targetTable}.${t.targetColumn}`
|
|
1831
|
+
});
|
|
1832
|
+
return n === "fresh" && o.push({
|
|
1612
1833
|
kind: "seed",
|
|
1613
1834
|
detail: `run boot seeds into ${e}`
|
|
1614
|
-
});
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
if (!ja(e)) throw new Y(`refusing to plan teardown of '${e}' — not a branch namespace`);
|
|
1835
|
+
}), o;
|
|
1836
|
+
}, Mo = (e) => {
|
|
1837
|
+
if (!Do(e)) throw new J(`refusing to plan teardown of '${e}' — not a branch namespace`);
|
|
1618
1838
|
return [{
|
|
1619
1839
|
kind: "drop-namespace",
|
|
1620
1840
|
detail: e
|
|
1621
1841
|
}];
|
|
1622
|
-
},
|
|
1842
|
+
}, No = (e) => {
|
|
1623
1843
|
if (e === void 0 || e === "") return !1;
|
|
1624
1844
|
try {
|
|
1625
1845
|
let t = new URL(e).hostname.toLowerCase();
|
|
@@ -1627,32 +1847,34 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
1627
1847
|
} catch {
|
|
1628
1848
|
return /\bneon\.(tech|build)\b/i.test(e);
|
|
1629
1849
|
}
|
|
1630
|
-
},
|
|
1850
|
+
}, Po = (e) => e.prefer === void 0 ? e.seed === "copy" && No(e.dbUrl) ? "neon-cow" : "namespace" : e.prefer, Fo = (e, t = {}) => [{
|
|
1631
1851
|
kind: "neon-branch-create",
|
|
1632
1852
|
detail: `${t.parentBranch ?? "main"} → ${e} (copy-on-write)`
|
|
1633
|
-
}],
|
|
1634
|
-
if (!
|
|
1853
|
+
}], Io = (e) => {
|
|
1854
|
+
if (!Do(e)) throw new J(`refusing to plan teardown of '${e}' — not a branch namespace`);
|
|
1635
1855
|
return [{
|
|
1636
1856
|
kind: "neon-branch-delete",
|
|
1637
1857
|
detail: e
|
|
1638
1858
|
}];
|
|
1639
|
-
},
|
|
1859
|
+
}, Lo = (e) => e.mechanism === "neon-cow" ? Fo(e.branchId, e.neonParentBranch === void 0 ? {} : { parentBranch: e.neonParentBranch }) : jo(e.branchId, e.tableNames, e.seed, e.parentNamespace, e.foreignKeys, e.indexNames), Ro = (e, t) => e === "neon-cow" ? Io(t) : Mo(t), zo = (e, t, n) => {
|
|
1640
1860
|
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);
|
|
1641
1861
|
return {
|
|
1642
1862
|
evict: i,
|
|
1643
1863
|
rejectNew: r.filter((e) => !a.has(e.namespace)).length >= t.maxBranches
|
|
1644
1864
|
};
|
|
1645
|
-
},
|
|
1646
|
-
let n =
|
|
1865
|
+
}, Bo = async (e, t) => {
|
|
1866
|
+
let n = Eo(e.appSlug, e.prNumber), r = Po({
|
|
1647
1867
|
seed: e.seed,
|
|
1648
1868
|
...e.dbUrl === void 0 ? {} : { dbUrl: e.dbUrl },
|
|
1649
1869
|
...e.prefer === void 0 ? {} : { prefer: e.prefer }
|
|
1650
|
-
}), i =
|
|
1870
|
+
}), i = Lo({
|
|
1651
1871
|
mechanism: r,
|
|
1652
1872
|
branchId: n,
|
|
1653
1873
|
tableNames: e.tableNames,
|
|
1654
1874
|
seed: e.seed,
|
|
1655
1875
|
...e.parentNamespace === void 0 ? {} : { parentNamespace: e.parentNamespace },
|
|
1876
|
+
...e.foreignKeys === void 0 ? {} : { foreignKeys: e.foreignKeys },
|
|
1877
|
+
...e.indexNames === void 0 ? {} : { indexNames: e.indexNames },
|
|
1656
1878
|
...e.neonParentBranch === void 0 ? {} : { neonParentBranch: e.neonParentBranch }
|
|
1657
1879
|
});
|
|
1658
1880
|
if (r === "neon-cow") return {
|
|
@@ -1663,42 +1885,81 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
1663
1885
|
};
|
|
1664
1886
|
await t.createNamespace(n);
|
|
1665
1887
|
for (let r of e.tableNames) await t.createTable(n, r);
|
|
1888
|
+
for (let r of e.indexNames ?? []) await t.restoreIndexName(n, r);
|
|
1666
1889
|
if (e.seed === "copy") {
|
|
1667
1890
|
if (e.parentNamespace === void 0 || e.parentNamespace === "") throw Error("provisionBranch: seed 'copy' requires parentNamespace");
|
|
1668
1891
|
for (let r of e.tableNames) await t.copyTable(e.parentNamespace, n, r);
|
|
1669
1892
|
}
|
|
1893
|
+
for (let r of e.foreignKeys ?? []) await t.addForeignKey(n, r);
|
|
1670
1894
|
return {
|
|
1671
1895
|
branchId: n,
|
|
1672
1896
|
mechanism: r,
|
|
1673
1897
|
steps: i
|
|
1674
1898
|
};
|
|
1675
|
-
},
|
|
1676
|
-
let r =
|
|
1899
|
+
}, Vo = async (e, t, n) => {
|
|
1900
|
+
let r = Ro(t, e);
|
|
1677
1901
|
return t === "neon-cow" ? await n.neonBranchDelete(e) : await n.dropNamespace(e), r;
|
|
1678
|
-
},
|
|
1902
|
+
}, Ho = (e, t, n) => zo(e, t, n), Y = (e) => `"${e.replace(/"/g, "\"\"")}"`, Uo = {
|
|
1903
|
+
cascade: "CASCADE",
|
|
1904
|
+
restrict: "RESTRICT",
|
|
1905
|
+
setNull: "SET NULL",
|
|
1906
|
+
noAction: "NO ACTION"
|
|
1907
|
+
}, X = (e) => `'${e.replace(/'/g, "''")}'`, Wo = (e, t) => {
|
|
1908
|
+
let n = t.columns.map(X).join(", ");
|
|
1909
|
+
return `DO $voltro_branch$
|
|
1910
|
+
DECLARE derived name;
|
|
1911
|
+
BEGIN
|
|
1912
|
+
SELECT i.relname INTO derived
|
|
1913
|
+
FROM pg_index x
|
|
1914
|
+
JOIN pg_class i ON i.oid = x.indexrelid
|
|
1915
|
+
JOIN pg_class c ON c.oid = x.indrelid
|
|
1916
|
+
JOIN pg_namespace nsp ON nsp.oid = c.relnamespace
|
|
1917
|
+
WHERE nsp.nspname = ${X(e)}
|
|
1918
|
+
AND c.relname = ${X(t.table)}
|
|
1919
|
+
AND NOT x.indisprimary
|
|
1920
|
+
AND x.indisunique = ${t.unique ? "true" : "false"}
|
|
1921
|
+
AND i.relname <> ${X(t.name)}
|
|
1922
|
+
AND (
|
|
1923
|
+
SELECT array_agg(att.attname::text ORDER BY k.ord)
|
|
1924
|
+
FROM unnest(x.indkey::int2[]) WITH ORDINALITY AS k(attnum, ord)
|
|
1925
|
+
JOIN pg_attribute att ON att.attrelid = c.oid AND att.attnum = k.attnum
|
|
1926
|
+
) = ARRAY[${n}]::text[]
|
|
1927
|
+
LIMIT 1;
|
|
1928
|
+
IF derived IS NOT NULL THEN
|
|
1929
|
+
EXECUTE format('ALTER INDEX %I.%I RENAME TO %I',
|
|
1930
|
+
${X(e)}, derived, ${X(t.name)});
|
|
1931
|
+
END IF;
|
|
1932
|
+
END
|
|
1933
|
+
$voltro_branch$`;
|
|
1934
|
+
}, Go = (e, t) => {
|
|
1935
|
+
let n = t.onDelete === void 0 ? "" : ` ON DELETE ${Uo[t.onDelete]}`, r = t.onUpdate === void 0 ? "" : ` ON UPDATE ${Uo[t.onUpdate]}`;
|
|
1936
|
+
return `ALTER TABLE ${Y(e)}.${Y(t.table)} ADD FOREIGN KEY (${Y(t.column)}) REFERENCES ${Y(e)}.${Y(t.targetTable)} (${Y(t.targetColumn)})${n}${r}`;
|
|
1937
|
+
}, Ko = (e) => {
|
|
1679
1938
|
let t = () => {
|
|
1680
1939
|
throw Error("namespace branch executor: Neon ops require a neon-cow executor (use a Neon connection for copy-on-write branches)");
|
|
1681
1940
|
};
|
|
1682
1941
|
return {
|
|
1683
|
-
createNamespace: (t) => e.run(`CREATE SCHEMA IF NOT EXISTS ${
|
|
1684
|
-
createTable: (t, n) => e.run(`CREATE TABLE IF NOT EXISTS ${
|
|
1685
|
-
copyTable: (t, n, r) => e.run(`INSERT INTO ${
|
|
1686
|
-
|
|
1942
|
+
createNamespace: (t) => e.run(`CREATE SCHEMA IF NOT EXISTS ${Y(t)}`),
|
|
1943
|
+
createTable: (t, n) => e.run(`CREATE TABLE IF NOT EXISTS ${Y(t)}.${Y(n)} (LIKE ${Y(n)} INCLUDING ALL)`),
|
|
1944
|
+
copyTable: (t, n, r) => e.run(`INSERT INTO ${Y(n)}.${Y(r)} SELECT * FROM ${Y(t)}.${Y(r)}`),
|
|
1945
|
+
addForeignKey: (t, n) => e.run(Go(t, n)),
|
|
1946
|
+
restoreIndexName: (t, n) => e.run(Wo(t, n)),
|
|
1947
|
+
dropNamespace: (t) => e.run(`DROP SCHEMA IF EXISTS ${Y(t)} CASCADE`),
|
|
1687
1948
|
neonBranchCreate: t,
|
|
1688
1949
|
neonBranchDelete: t
|
|
1689
1950
|
};
|
|
1690
|
-
},
|
|
1951
|
+
}, qo = class extends Error {
|
|
1691
1952
|
_tag = "TenantResidencyUnresolved";
|
|
1692
1953
|
constructor(e) {
|
|
1693
1954
|
super(e), this.name = "TenantResidencyUnresolved";
|
|
1694
1955
|
}
|
|
1695
|
-
},
|
|
1956
|
+
}, Jo = class extends Error {
|
|
1696
1957
|
region;
|
|
1697
1958
|
_tag = "TenantRegionUnavailable";
|
|
1698
1959
|
constructor(e, t) {
|
|
1699
1960
|
super(t), this.region = e, this.name = "TenantRegionUnavailable";
|
|
1700
1961
|
}
|
|
1701
|
-
},
|
|
1962
|
+
}, Yo, Xo = (e) => {
|
|
1702
1963
|
if (e.homes === void 0) throw Error("setResidencyConfig: `homes` is required");
|
|
1703
1964
|
if (e.servableRegions === void 0 || e.servableRegions.length === 0) throw Error("setResidencyConfig: `servableRegions` must be non-empty (which regions this deployment serves)");
|
|
1704
1965
|
let t = /* @__PURE__ */ new Map();
|
|
@@ -1707,116 +1968,98 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
1707
1968
|
if (e !== void 0 && e !== n.region) throw Error(`residency: tenant '${n.tenantId}' is mapped to two regions ('${e}' and '${n.region}')`);
|
|
1708
1969
|
t.set(n.tenantId, n.region);
|
|
1709
1970
|
}
|
|
1710
|
-
return
|
|
1711
|
-
},
|
|
1712
|
-
|
|
1713
|
-
},
|
|
1714
|
-
if (e == null || e === "") throw new
|
|
1971
|
+
return Yo = e, e;
|
|
1972
|
+
}, Zo = () => Yo, Qo = () => {
|
|
1973
|
+
Yo = void 0;
|
|
1974
|
+
}, $o = (e, t) => {
|
|
1975
|
+
if (e == null || e === "") throw new qo("residency is on but the request has no resolvable tenant — refusing to bind a store");
|
|
1715
1976
|
let n = t.homes.find((t) => t.tenantId === e);
|
|
1716
|
-
if (n === void 0) throw new
|
|
1977
|
+
if (n === void 0) throw new qo(`no residency home is mapped for tenant '${e}' — refusing to fall back to a default store (would be a residency violation)`);
|
|
1717
1978
|
return n;
|
|
1718
|
-
},
|
|
1719
|
-
let n =
|
|
1979
|
+
}, es = (e, t) => t.servableRegions.includes(e), ts = (e, t) => {
|
|
1980
|
+
let n = $o(e.tenantId, t), r = er(n.tenantId);
|
|
1720
1981
|
return {
|
|
1721
1982
|
region: n.region,
|
|
1722
1983
|
namespace: r,
|
|
1723
1984
|
...n.connectionKey === void 0 ? {} : { connectionKey: n.connectionKey }
|
|
1724
1985
|
};
|
|
1725
|
-
},
|
|
1726
|
-
let r =
|
|
1727
|
-
if (!
|
|
1986
|
+
}, ns = (e, t, n) => {
|
|
1987
|
+
let r = ts(e, t);
|
|
1988
|
+
if (!es(r.region, t)) throw new Jo(r.region, `tenant homed in region '${r.region}', which this deployment does not serve — route to the home region`);
|
|
1728
1989
|
let i = n.get(r.region);
|
|
1729
|
-
if (i === void 0) throw new
|
|
1990
|
+
if (i === void 0) throw new Jo(r.region, `no store handle for home region '${r.region}' (declared servable but not wired) — failing closed`);
|
|
1730
1991
|
return {
|
|
1731
1992
|
store: i,
|
|
1732
1993
|
placement: r
|
|
1733
1994
|
};
|
|
1734
|
-
},
|
|
1735
|
-
let { store: i, placement: a } =
|
|
1995
|
+
}, rs = async (e, t, n, r) => {
|
|
1996
|
+
let { store: i, placement: a } = ns(e, t, n);
|
|
1736
1997
|
return await r(i, a), a;
|
|
1737
|
-
},
|
|
1998
|
+
}, Z = (e) => {
|
|
1738
1999
|
if (typeof e == "string") return e;
|
|
1739
2000
|
if ("jsonPath" in e) {
|
|
1740
2001
|
let { column: t, path: n, numeric: r } = e.jsonPath;
|
|
1741
2002
|
return `(json:${t}->${n.join(".")}${r ? "::num" : ""})`;
|
|
1742
2003
|
}
|
|
1743
2004
|
return `(${e.expr})`;
|
|
1744
|
-
},
|
|
2005
|
+
}, Q = (e) => e.map(Z), is = (e, t) => {
|
|
1745
2006
|
if (e.length !== t.length) return !1;
|
|
1746
|
-
for (let n = 0; n < e.length; n++) if (
|
|
2007
|
+
for (let n = 0; n < e.length; n++) if (Z(e[n]) !== Z(t[n])) return !1;
|
|
1747
2008
|
return !0;
|
|
1748
|
-
},
|
|
2009
|
+
}, as = (e, t) => {
|
|
1749
2010
|
if (e.length >= t.length) return !1;
|
|
1750
|
-
for (let n = 0; n < e.length; n++) if (
|
|
2011
|
+
for (let n = 0; n < e.length; n++) if (Z(e[n]) !== Z(t[n])) return !1;
|
|
1751
2012
|
return !0;
|
|
1752
|
-
},
|
|
2013
|
+
}, os = (e) => {
|
|
1753
2014
|
let t = [], n = e.appliedIndexes, r = e.tableName;
|
|
1754
2015
|
for (let e = 0; e < n.length; e++) {
|
|
1755
2016
|
let i = n[e];
|
|
1756
2017
|
for (let a = e + 1; a < n.length; a++) {
|
|
1757
2018
|
let e = n[a];
|
|
1758
|
-
if (
|
|
2019
|
+
if (is(i.fields, e.fields)) {
|
|
1759
2020
|
let [n, a] = i.name < e.name ? [i, e] : [e, i];
|
|
1760
2021
|
t.push({
|
|
1761
2022
|
kind: "duplicate-fields",
|
|
1762
2023
|
table: r,
|
|
1763
2024
|
redundant: n,
|
|
1764
2025
|
coveredBy: a,
|
|
1765
|
-
message: `'${r}' has two indexes on the same fields [${
|
|
2026
|
+
message: `'${r}' has two indexes on the same fields [${Q(i.fields).join(", ")}]: '${i.name}' and '${e.name}'. The B-tree engine builds both, costing write throughput + disk space for no read benefit. Drop '${n.name}' (or '${a.name}' if you prefer the other name). Applies to every supported dialect (Postgres / MySQL / MariaDB / MSSQL / SQLite).`
|
|
1766
2027
|
});
|
|
1767
2028
|
continue;
|
|
1768
2029
|
}
|
|
1769
|
-
|
|
2030
|
+
as(i.fields, e.fields) ? t.push({
|
|
1770
2031
|
kind: "redundant-prefix",
|
|
1771
2032
|
table: r,
|
|
1772
2033
|
redundant: i,
|
|
1773
2034
|
coveredBy: e,
|
|
1774
|
-
message: `'${r}' index '${i.name}' on [${
|
|
1775
|
-
}) :
|
|
2035
|
+
message: `'${r}' index '${i.name}' on [${Q(i.fields).join(", ")}] is a leading prefix of '${e.name}' on [${Q(e.fields).join(", ")}]. Every B-tree dialect we support (Postgres / MySQL / MariaDB / MSSQL / SQLite) can serve a [${Q(i.fields).join(", ")}] query from '${e.name}' too via the leading-prefix rule, so '${i.name}' adds write cost without read benefit. Drop '${i.name}' — unless you specifically need a smaller index for cache locality on a write-heavy table (rare; profile first).`
|
|
2036
|
+
}) : as(e.fields, i.fields) && t.push({
|
|
1776
2037
|
kind: "redundant-prefix",
|
|
1777
2038
|
table: r,
|
|
1778
2039
|
redundant: e,
|
|
1779
2040
|
coveredBy: i,
|
|
1780
|
-
message: `'${r}' index '${e.name}' on [${
|
|
2041
|
+
message: `'${r}' index '${e.name}' on [${Q(e.fields).join(", ")}] is a leading prefix of '${i.name}' on [${Q(i.fields).join(", ")}]. Every B-tree dialect we support (Postgres / MySQL / MariaDB / MSSQL / SQLite) can serve a [${Q(e.fields).join(", ")}] query from '${i.name}' too via the leading-prefix rule, so '${e.name}' adds write cost without read benefit. Drop '${e.name}' — unless you specifically need a smaller index for cache locality on a write-heavy table (rare; profile first).`
|
|
1781
2042
|
});
|
|
1782
2043
|
}
|
|
1783
2044
|
}
|
|
1784
2045
|
return t;
|
|
1785
|
-
},
|
|
2046
|
+
}, ss = (e) => {
|
|
1786
2047
|
let t = [];
|
|
1787
|
-
for (let n of e) t.push(...
|
|
2048
|
+
for (let n of e) t.push(...os(n));
|
|
1788
2049
|
return t;
|
|
1789
|
-
},
|
|
1790
|
-
let n = t.color ?? !0, r = t.indent ?? " ", i = (e) =>
|
|
2050
|
+
}, cs = "\x1B[", ls = `${cs}38;2;245;158;11m`, us = `${cs}38;2;16;185;129m`, ds = (e, t) => `${e}${t}${M.reset}`, $ = (e, t, n) => e ? typeof t == "function" ? t(n) : ds(t, n) : n, fs = (e, t = {}) => {
|
|
2051
|
+
let n = t.color ?? !0, r = t.indent ?? " ", i = (e) => $(n, M.dim, e.padEnd(11)), a = (e) => $(n, (e) => M.bold(M.brand(e)), e), o = (e) => $(n, M.brightRed24, e), s = (e) => $(n, us, e), c = (e) => $(n, ls, e), l = (e) => $(n, M.dim, e), u = `${c("index audit")} ${l("·")} ${$(n, M.bold, e.kind)}`, d = e.redundant.fields.length, f = Q(e.coveredBy.fields.slice(d)), p = (e, t) => {
|
|
1791
2052
|
let n = e.slice(0, t), r = e.slice(t), i = [];
|
|
1792
2053
|
return n.length > 0 && i.push(s(`[${n.join(", ")}]`)), r.length > 0 && i.push(c(`+ [${r.join(", ")}]`)), i.join(" ");
|
|
1793
2054
|
}, m = [];
|
|
1794
|
-
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(
|
|
1795
|
-
},
|
|
1796
|
-
name: e,
|
|
1797
|
-
body: t
|
|
1798
|
-
}), _o = (e) => {
|
|
1799
|
-
if (e.lifecycle === "cron" && !e.cron) throw Error(`seed "${e.id}": lifecycle 'cron' requires a 'cron' field`);
|
|
1800
|
-
if (e.lifecycle === "onSchemaChange" && (!e.watchedTables || e.watchedTables.length === 0)) throw Error(`seed "${e.id}": lifecycle 'onSchemaChange' requires at least one entry in 'watchedTables'`);
|
|
1801
|
-
let t = e.steps({ step: go });
|
|
1802
|
-
if (t.length === 0) throw Error(`seed "${e.id}": at least one step is required`);
|
|
1803
|
-
return {
|
|
1804
|
-
__seed: !0,
|
|
1805
|
-
id: e.id,
|
|
1806
|
-
name: e.name,
|
|
1807
|
-
lifecycle: e.lifecycle,
|
|
1808
|
-
...e.cron === void 0 ? {} : { cron: e.cron },
|
|
1809
|
-
...e.watchedTables === void 0 ? {} : { watchedTables: e.watchedTables },
|
|
1810
|
-
...e.fingerprint === void 0 ? {} : { fingerprint: e.fingerprint },
|
|
1811
|
-
steps: t
|
|
1812
|
-
};
|
|
1813
|
-
}, vo = (e) => typeof e == "object" && !!e && "__seed" in e && e.__seed === !0, yo = (e, { apply: t, undo: n }) => ({
|
|
2055
|
+
return m.push(u), m.push(""), m.push(`${i("table")}${a(e.table)}`), m.push(""), m.push(`${i("redundant")}${o(e.redundant.name)}`), m.push(`${i("")}${p(Q(e.redundant.fields), d)}`), m.push(""), m.push(`${i("covered by")}${s(e.coveredBy.name)}`), m.push(`${i("")}${p(Q(e.coveredBy.fields), d)}`), f.length > 0 && m.push(`${i("")}${l(`└ extra columns: ${f.join(", ")}`)}`), m.push(""), e.kind === "redundant-prefix" ? (m.push(`${i("why")}B-tree indexes serve queries that filter on a LEADING PREFIX of`), m.push(`${i("")}their column list. The wider index already covers every`), m.push(`${i("")}query the narrower one can serve.`), m.push(`${i("")}${l("Same rule on Postgres / MySQL / MariaDB / MSSQL / SQLite.")}`)) : (m.push(`${i("why")}Two indexes on the same columns under different names.`), m.push(`${i("")}The B-tree engine builds both — same coverage, double cost.`), m.push(`${i("")}${l("Same rule on Postgres / MySQL / MariaDB / MSSQL / SQLite.")}`)), m.push(""), m.push(`${i("cost")}Every ${a("INSERT")} / ${a("UPDATE")} / ${a("DELETE")} on this table writes`), m.push(`${i("")}to ${$(n, M.bold, "both")} B-trees. Pure write overhead, zero read benefit.`), m.push(""), m.push(`${i("fix")}Drop ${o(e.redundant.name)}`), m.push(`${i("")}${l("Keep only if profiling shows the smaller index gives a")}`), m.push(`${i("")}${l("measurable cache-locality boost on a write-heavy hot path.")}`), m.push(`${i("")}${l("Silence with VOLTRO_INDEX_AUDIT=off if intentional.")}`), m.map((e) => `${r}${e}`).join("\n");
|
|
2056
|
+
}, ps = (e, { apply: t, undo: n }) => ({
|
|
1814
2057
|
name: e,
|
|
1815
2058
|
apply: t,
|
|
1816
2059
|
undo: n
|
|
1817
|
-
}),
|
|
2060
|
+
}), ms = (e) => {
|
|
1818
2061
|
if (!/^\d{14}_/.test(e.id)) throw Error(`migration "${e.id}": id must start with a 14-digit timestamp followed by "_" (convention: <YYYYMMDDHHMMSS>_<slug>)`);
|
|
1819
|
-
let t = e.steps({ step:
|
|
2062
|
+
let t = e.steps({ step: ps });
|
|
1820
2063
|
if (t.length === 0) throw Error(`migration "${e.id}": at least one step is required`);
|
|
1821
2064
|
return {
|
|
1822
2065
|
__migration: !0,
|
|
@@ -1824,145 +2067,235 @@ var wt = (e) => typeof e == "string" && e !== "" ? e : null, Tt = async (e, t, n
|
|
|
1824
2067
|
name: e.name,
|
|
1825
2068
|
steps: t
|
|
1826
2069
|
};
|
|
1827
|
-
},
|
|
1828
|
-
id:
|
|
1829
|
-
name:
|
|
1830
|
-
hash:
|
|
1831
|
-
status:
|
|
1832
|
-
appliedAt:
|
|
1833
|
-
durationMs:
|
|
1834
|
-
errorMessage:
|
|
1835
|
-
errorStack:
|
|
1836
|
-
workflowRunId:
|
|
1837
|
-
createdAt:
|
|
1838
|
-
updatedAt:
|
|
1839
|
-
}).index(["status"]),
|
|
1840
|
-
id:
|
|
1841
|
-
name:
|
|
1842
|
-
lifecycle:
|
|
1843
|
-
fingerprint:
|
|
1844
|
-
cronSchedule:
|
|
1845
|
-
watchedTables:
|
|
1846
|
-
nextRunAt:
|
|
1847
|
-
lastRunStatus:
|
|
1848
|
-
lastRunAt:
|
|
1849
|
-
lastRunDurationMs:
|
|
1850
|
-
lastRunRowsTouched:
|
|
1851
|
-
lastError:
|
|
1852
|
-
workflowRunId:
|
|
1853
|
-
createdAt:
|
|
1854
|
-
updatedAt:
|
|
1855
|
-
}).index(["lifecycle"]).index(["nextRunAt"]),
|
|
1856
|
-
id:
|
|
1857
|
-
fingerprint:
|
|
1858
|
-
liveFingerprint:
|
|
1859
|
-
operations:
|
|
1860
|
-
rollbackPlan:
|
|
1861
|
-
appliedBy:
|
|
1862
|
-
environment:
|
|
1863
|
-
source:
|
|
1864
|
-
onlineStrategy:
|
|
1865
|
-
durationMs:
|
|
1866
|
-
notes:
|
|
1867
|
-
squashedAt:
|
|
1868
|
-
appliedAt:
|
|
1869
|
-
createdAt:
|
|
1870
|
-
updatedAt:
|
|
1871
|
-
}).index(["fingerprint"]).index(["environment"]),
|
|
1872
|
-
id:
|
|
1873
|
-
scope:
|
|
1874
|
-
key:
|
|
1875
|
-
status:
|
|
1876
|
-
response:
|
|
1877
|
-
createdAt:
|
|
1878
|
-
}).unique(["scope", "key"]).index(["createdAt"]),
|
|
1879
|
-
id:
|
|
1880
|
-
key:
|
|
1881
|
-
value:
|
|
1882
|
-
expiresAt:
|
|
1883
|
-
createdAt:
|
|
1884
|
-
updatedAt:
|
|
1885
|
-
}).index(["expiresAt"]),
|
|
1886
|
-
id:
|
|
1887
|
-
tenantId:
|
|
1888
|
-
name:
|
|
1889
|
-
hashedKey:
|
|
1890
|
-
keyPrefix:
|
|
1891
|
-
scopes:
|
|
1892
|
-
lastUsedAt:
|
|
1893
|
-
requestCount:
|
|
1894
|
-
expiresAt:
|
|
1895
|
-
revokedAt:
|
|
1896
|
-
createdBy:
|
|
1897
|
-
onBehalfOf:
|
|
1898
|
-
metadata:
|
|
1899
|
-
createdAt:
|
|
1900
|
-
}).index("byApiKeyTenant", ["tenantId"]),
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
],
|
|
1905
|
-
let
|
|
1906
|
-
if (
|
|
1907
|
-
let
|
|
1908
|
-
if (
|
|
1909
|
-
if (
|
|
1910
|
-
if (!(
|
|
1911
|
-
let e = { ...
|
|
1912
|
-
return delete e[
|
|
1913
|
-
}
|
|
1914
|
-
let
|
|
1915
|
-
return
|
|
1916
|
-
...
|
|
1917
|
-
[
|
|
2070
|
+
}, hs = (e) => typeof e == "object" && !!e && "__migration" in e && e.__migration === !0, gs = C("_voltro_migrations", {
|
|
2071
|
+
id: v({ prefix: "mig" }),
|
|
2072
|
+
name: E(),
|
|
2073
|
+
hash: E(),
|
|
2074
|
+
status: E(),
|
|
2075
|
+
appliedAt: b().nullable(),
|
|
2076
|
+
durationMs: S().nullable(),
|
|
2077
|
+
errorMessage: E().nullable(),
|
|
2078
|
+
errorStack: E().nullable(),
|
|
2079
|
+
workflowRunId: E().nullable(),
|
|
2080
|
+
createdAt: b().default("now"),
|
|
2081
|
+
updatedAt: b().default("now").onUpdate("now")
|
|
2082
|
+
}).index(["status"]), _s = C("_voltro_seeds", {
|
|
2083
|
+
id: v({ prefix: "seed" }),
|
|
2084
|
+
name: E(),
|
|
2085
|
+
lifecycle: E(),
|
|
2086
|
+
fingerprint: E(),
|
|
2087
|
+
cronSchedule: E().nullable(),
|
|
2088
|
+
watchedTables: D().nullable(),
|
|
2089
|
+
nextRunAt: b().nullable(),
|
|
2090
|
+
lastRunStatus: E().nullable(),
|
|
2091
|
+
lastRunAt: b().nullable(),
|
|
2092
|
+
lastRunDurationMs: S().nullable(),
|
|
2093
|
+
lastRunRowsTouched: S().nullable(),
|
|
2094
|
+
lastError: E().nullable(),
|
|
2095
|
+
workflowRunId: E().nullable(),
|
|
2096
|
+
createdAt: b().default("now"),
|
|
2097
|
+
updatedAt: b().default("now").onUpdate("now")
|
|
2098
|
+
}).index(["lifecycle"]).index(["nextRunAt"]), vs = C("_voltro_migration_plans", {
|
|
2099
|
+
id: v({ prefix: "plan" }),
|
|
2100
|
+
fingerprint: E(),
|
|
2101
|
+
liveFingerprint: E().nullable(),
|
|
2102
|
+
operations: D(),
|
|
2103
|
+
rollbackPlan: D().nullable(),
|
|
2104
|
+
appliedBy: E(),
|
|
2105
|
+
environment: E(),
|
|
2106
|
+
source: E(),
|
|
2107
|
+
onlineStrategy: E().nullable(),
|
|
2108
|
+
durationMs: S(),
|
|
2109
|
+
notes: E().nullable(),
|
|
2110
|
+
squashedAt: b().nullable(),
|
|
2111
|
+
appliedAt: b().default("now"),
|
|
2112
|
+
createdAt: b().default("now"),
|
|
2113
|
+
updatedAt: b().default("now").onUpdate("now")
|
|
2114
|
+
}).index(["fingerprint"]).index(["environment"]), ys = C("_voltro_idempotency", {
|
|
2115
|
+
id: v({ prefix: "idem" }),
|
|
2116
|
+
scope: E(),
|
|
2117
|
+
key: E(),
|
|
2118
|
+
status: E(),
|
|
2119
|
+
response: D().nullable(),
|
|
2120
|
+
createdAt: b().default("now")
|
|
2121
|
+
}).unique(["scope", "key"]).index(["createdAt"]), bs = C("_voltro_kv", {
|
|
2122
|
+
id: v({ prefix: "kv" }),
|
|
2123
|
+
key: E().unique(),
|
|
2124
|
+
value: E().nullable(),
|
|
2125
|
+
expiresAt: b().nullable(),
|
|
2126
|
+
createdAt: b().default("now"),
|
|
2127
|
+
updatedAt: b().default("now").onUpdate("now")
|
|
2128
|
+
}).index(["expiresAt"]), xs = C("_voltro_api_keys", {
|
|
2129
|
+
id: v({ prefix: "apikey" }),
|
|
2130
|
+
tenantId: E().nullable(),
|
|
2131
|
+
name: E(),
|
|
2132
|
+
hashedKey: E().maxLength(64).unique(),
|
|
2133
|
+
keyPrefix: E(),
|
|
2134
|
+
scopes: D().nullable(),
|
|
2135
|
+
lastUsedAt: b().nullable(),
|
|
2136
|
+
requestCount: S().default(0),
|
|
2137
|
+
expiresAt: b().nullable(),
|
|
2138
|
+
revokedAt: b().nullable(),
|
|
2139
|
+
createdBy: E().nullable(),
|
|
2140
|
+
onBehalfOf: E().nullable(),
|
|
2141
|
+
metadata: D().nullable(),
|
|
2142
|
+
createdAt: b().default("now")
|
|
2143
|
+
}).index("byApiKeyTenant", ["tenantId"]), Ss = [
|
|
2144
|
+
gs,
|
|
2145
|
+
_s,
|
|
2146
|
+
vs
|
|
2147
|
+
], Cs = "id", ws = (e, t) => {
|
|
2148
|
+
let n = p(e);
|
|
2149
|
+
if (n === void 0) return t;
|
|
2150
|
+
let r = n.fields[Cs]?.idScheme;
|
|
2151
|
+
if (r === void 0 || t[Cs] != null) return t;
|
|
2152
|
+
if (r.kind === "numeric") {
|
|
2153
|
+
if (!(Cs in t)) return t;
|
|
2154
|
+
let e = { ...t };
|
|
2155
|
+
return delete e[Cs], e;
|
|
2156
|
+
}
|
|
2157
|
+
let i = tt(r, e);
|
|
2158
|
+
return i === null ? t : {
|
|
2159
|
+
...t,
|
|
2160
|
+
[Cs]: i
|
|
1918
2161
|
};
|
|
1919
|
-
},
|
|
2162
|
+
}, Ts = (e, t) => t.map((t) => ws(e, t)), Es = {
|
|
2163
|
+
postgres: { maxBindParameters: 65535 },
|
|
2164
|
+
mysql: { maxBindParameters: 65535 },
|
|
2165
|
+
mariadb: { maxBindParameters: 65535 },
|
|
2166
|
+
mssql: {
|
|
2167
|
+
maxBindParameters: 2098,
|
|
2168
|
+
maxRowsPerStatement: 1e3
|
|
2169
|
+
},
|
|
2170
|
+
sqlite: { maxBindParameters: 32766 },
|
|
2171
|
+
turso: { maxBindParameters: 32766 }
|
|
2172
|
+
}, Ds = (e) => Es[e], Os = (e) => {
|
|
2173
|
+
let t = /* @__PURE__ */ new Set();
|
|
2174
|
+
for (let n of e) for (let e of Object.keys(n)) t.add(e);
|
|
2175
|
+
return t.size;
|
|
2176
|
+
}, ks = (e, t) => {
|
|
2177
|
+
if (t === void 0 || e.length === 0) return [e];
|
|
2178
|
+
let n = Math.max(1, Os(e)), r = Math.floor(t.maxBindParameters / n), i = t.maxRowsPerStatement ?? Infinity, a = Math.max(1, Math.min(r, i));
|
|
2179
|
+
if (e.length <= a) return [e];
|
|
2180
|
+
let o = [];
|
|
2181
|
+
for (let t = 0; t < e.length; t += a) o.push(e.slice(t, t + a));
|
|
2182
|
+
return o;
|
|
2183
|
+
}, As = (e, t) => {
|
|
1920
2184
|
let n = [], r = t;
|
|
1921
2185
|
for (let [t, i] of Object.entries(e.fields)) {
|
|
1922
2186
|
let e = i;
|
|
1923
2187
|
e.nullable || e.hasDefault || e.idScheme !== void 0 || e.generatedAs !== void 0 || (r[t] === void 0 || r[t] === null) && n.push(t);
|
|
1924
2188
|
}
|
|
1925
2189
|
return n;
|
|
1926
|
-
},
|
|
2190
|
+
}, js = (e, t) => {
|
|
1927
2191
|
let n = t;
|
|
1928
2192
|
return e.filter((e) => n[e] === void 0 || n[e] === null);
|
|
1929
|
-
},
|
|
2193
|
+
}, Ms = (e, t, n) => e.insert(t.tableName, n), Ns = (e, t, n, r) => e.upsert(t.tableName, n, {
|
|
1930
2194
|
conflictColumns: r.conflictColumns,
|
|
1931
2195
|
...r.update === void 0 ? {} : { update: r.update }
|
|
1932
|
-
}),
|
|
2196
|
+
}), Ps = (e, t, n, r) => e.updateMany(t.tableName, n, { where: r.where }), Fs = 512, Is = (e) => {
|
|
1933
2197
|
e.setMaxListeners(512);
|
|
1934
|
-
},
|
|
2198
|
+
}, Ls = (e, t, n) => ({
|
|
1935
2199
|
_tag: "PrimaryKeyConflictError",
|
|
1936
2200
|
table: e,
|
|
1937
2201
|
key: t,
|
|
1938
2202
|
cause: n
|
|
1939
|
-
}),
|
|
2203
|
+
}), Rs = (e) => typeof e == "object" && !!e && e._tag === "PrimaryKeyConflictError", zs = {
|
|
2204
|
+
postgres: 5432,
|
|
2205
|
+
mysql: 3306,
|
|
2206
|
+
mariadb: 3306,
|
|
2207
|
+
mssql: 1433
|
|
2208
|
+
}, Bs = /* @__PURE__ */ new Set([
|
|
2209
|
+
"localhost",
|
|
2210
|
+
"127.0.0.1",
|
|
2211
|
+
"::1",
|
|
2212
|
+
"[::1]",
|
|
2213
|
+
"0.0.0.0"
|
|
2214
|
+
]), Vs = (e) => {
|
|
2215
|
+
let t = e.host, n = e.port, r = e.database;
|
|
2216
|
+
if (e.url !== void 0 && e.url !== "") try {
|
|
2217
|
+
let i = new URL(e.url);
|
|
2218
|
+
t ??= decodeURIComponent(i.hostname), n === void 0 && i.port !== "" && (n = Number(i.port)), r ??= decodeURIComponent(i.pathname.replace(/^\//, ""));
|
|
2219
|
+
} catch {
|
|
2220
|
+
return;
|
|
2221
|
+
}
|
|
2222
|
+
if (t === void 0 || t === "" || r === void 0 || r === "") return;
|
|
2223
|
+
let i = n ?? zs[(e.dialect ?? "").toLowerCase()];
|
|
2224
|
+
if (i === void 0 || !Number.isFinite(i)) return;
|
|
2225
|
+
let a = t.toLowerCase();
|
|
2226
|
+
return {
|
|
2227
|
+
host: Bs.has(a) ? "localhost" : a,
|
|
2228
|
+
port: i,
|
|
2229
|
+
database: r.toLowerCase()
|
|
2230
|
+
};
|
|
2231
|
+
}, Hs = (e) => {
|
|
2232
|
+
let t = Vs(e);
|
|
2233
|
+
if (t !== void 0) return Mt("sha256").update(`${t.host}\u0000${t.port}\u0000${t.database}`).digest("hex").slice(0, 32);
|
|
2234
|
+
}, Us = (e, t) => e === void 0 || t === void 0 ? "unknown" : e === t ? "same" : "different", Ws = {
|
|
2235
|
+
app: 3,
|
|
2236
|
+
plugin: 2,
|
|
2237
|
+
framework: 1
|
|
2238
|
+
}, Gs = /* @__PURE__ */ new Map(), Ks = [], qs = () => [...Ks], Js = (e) => {
|
|
1940
2239
|
if (!e.table || !e.timeColumn) throw Error("registerRetention: table + timeColumn are required");
|
|
1941
2240
|
if (!Number.isFinite(e.ttlMs) || e.ttlMs <= 0) throw Error(`registerRetention(${e.table}): ttlMs must be a positive number`);
|
|
1942
|
-
|
|
1943
|
-
|
|
2241
|
+
let t = e.source ?? "app", n = Gs.get(e.table);
|
|
2242
|
+
if (n !== void 0) {
|
|
2243
|
+
let r = n.source ?? "app", i = n.ttlMs !== e.ttlMs || n.where !== void 0 != (e.where !== void 0);
|
|
2244
|
+
if (Ws[t] < Ws[r]) {
|
|
2245
|
+
i && Ks.push({
|
|
2246
|
+
table: e.table,
|
|
2247
|
+
kept: {
|
|
2248
|
+
source: r,
|
|
2249
|
+
ttlMs: n.ttlMs
|
|
2250
|
+
},
|
|
2251
|
+
dropped: {
|
|
2252
|
+
source: t,
|
|
2253
|
+
ttlMs: e.ttlMs
|
|
2254
|
+
}
|
|
2255
|
+
});
|
|
2256
|
+
return;
|
|
2257
|
+
}
|
|
2258
|
+
i && r !== t && Ks.push({
|
|
2259
|
+
table: e.table,
|
|
2260
|
+
kept: {
|
|
2261
|
+
source: t,
|
|
2262
|
+
ttlMs: e.ttlMs
|
|
2263
|
+
},
|
|
2264
|
+
dropped: {
|
|
2265
|
+
source: r,
|
|
2266
|
+
ttlMs: n.ttlMs
|
|
2267
|
+
}
|
|
2268
|
+
});
|
|
2269
|
+
}
|
|
2270
|
+
Gs.set(e.table, {
|
|
2271
|
+
...e,
|
|
2272
|
+
source: t
|
|
2273
|
+
});
|
|
2274
|
+
}, Ys = () => [...Gs.values()], Xs = () => {
|
|
2275
|
+
Gs.clear(), Ks.length = 0;
|
|
2276
|
+
}, Zs = async (e, t, n, r = 2e4) => {
|
|
1944
2277
|
let i = new Date(t - e.ttlMs), a = 0;
|
|
1945
2278
|
for (;;) {
|
|
1946
2279
|
let t = await n(e.table, e.timeColumn, i, r, e.where);
|
|
1947
2280
|
if (a += t, t < r) break;
|
|
1948
2281
|
}
|
|
1949
2282
|
return a;
|
|
1950
|
-
},
|
|
2283
|
+
}, Qs = (e, t) => {
|
|
1951
2284
|
let n = Number(e ?? String(t));
|
|
1952
2285
|
return (Number.isFinite(n) && n > 0 ? n : t) * 36e5;
|
|
1953
|
-
},
|
|
1954
|
-
id:
|
|
1955
|
-
replicaId:
|
|
1956
|
-
streamName:
|
|
1957
|
-
binlogFile:
|
|
1958
|
-
binlogPosition:
|
|
1959
|
-
updatedAt:
|
|
1960
|
-
}).index(["replicaId"]),
|
|
1961
|
-
id:
|
|
1962
|
-
replicaId:
|
|
1963
|
-
streamName:
|
|
1964
|
-
ctVersion:
|
|
1965
|
-
updatedAt:
|
|
1966
|
-
}).index(["replicaId"]),
|
|
2286
|
+
}, $s = "_voltro_cdc_offsets", ec = C($s, {
|
|
2287
|
+
id: v({ prefix: "cdcoff" }),
|
|
2288
|
+
replicaId: E(),
|
|
2289
|
+
streamName: E(),
|
|
2290
|
+
binlogFile: E(),
|
|
2291
|
+
binlogPosition: E(),
|
|
2292
|
+
updatedAt: b()
|
|
2293
|
+
}).index(["replicaId"]), tc = C($s, {
|
|
2294
|
+
id: v({ prefix: "cdcoff" }),
|
|
2295
|
+
replicaId: E(),
|
|
2296
|
+
streamName: E(),
|
|
2297
|
+
ctVersion: E(),
|
|
2298
|
+
updatedAt: b()
|
|
2299
|
+
}).index(["replicaId"]), nc = "postgres";
|
|
1967
2300
|
//#endregion
|
|
1968
|
-
export {
|
|
2301
|
+
export { ue as AUTO_FILLED_COLUMNS, Es as BULK_INSERT_LIMITS, J as BranchNameInvalid, ko as BranchTransitionInvalid, $s as CDC_OFFSETS_TABLE, Fs as CHANGE_LISTENER_CEILING, o as ColumnBuilder, we as DEFAULT_ACQUIRE_TIMEOUT_MS, Xa as DEFAULT_EAGER_FALLBACK_WARN_INTERVAL_MS, yn as DEFAULT_SUBJECT_GRAPH_DEPTH, zt as ENCRYPTED_PREFIX, nc as ENGINE, In as EagerCardinalityError, Ue as FILE_MIGRATION_PATTERN, st as FRAMEWORK_LIVE_TABLES, Bt as FieldDecryptionError, lo as INITIAL_VERSION, Ri as MATCHES_NO_ROWS, ut as MAX_IDENTIFIER_LENGTH, jt as SqlClient, _o as TableStreamError, Xn as TenantNamespaceInvalid, Yn as TenantNamespaceUnresolved, Jo as TenantRegionUnavailable, qo as TenantResidencyUnresolved, uo as VOLTRO_EXPIRES_MIXIN_ID, po as VOLTRO_LOCAL_FIRST_MIXIN_ID, ao as VersionConflict, Ie as WARN_IDENTIFIER_LENGTH, xs as _voltroApiKeysTable, ec as _voltroCdcOffsetsTable, ys as _voltroIdempotencyTable, bs as _voltroKvTable, vs as _voltroMigrationPlansTable, gs as _voltroMigrationsTable, tc as _voltroMssqlCdcOffsetsTable, _s as _voltroSeedsTable, wi as actorsTable, Ho as admitBranch, Oe as allEnumRenames, gn as allRegisteredRelations, h as allRegisteredTables, Hi as and, mt as array, Fi as arrayContains, Li as arrayHas, Ii as arrayOverlaps, Rn as attachEagerLoads, ua as attributionFields, ma as attributionKey, ss as auditAllTableIndexes, os as auditTableIndexes, dt as avg, _t as avgOver, Sa as beginLocalWrite, ge as bigint, ns as bindResidentStore, u as boolean, Eo as branchNamespaceName, Ds as bulkInsertLimitsFor, c as bytes, aa as changeDelete, ra as changeInsert, oa as changeSoftDelete, ia as changeUpdate, ks as chunkRowsForInsert, _a as claimPendingAttribution, ft as clearEnumRenames, Ta as clearPendingAttribution, vn as clearRelationsRegistry, Qo as clearResidencyConfig, Xs as clearRetentions, _e as clearTableRegistry, ka as clearWriteRecorders, ir as coercePredicateValue, ar as coercePredicateValues, ea as collectSubqueries, je as column, Kt as columnSchema, Os as columnsPerRow, yr as compileEagerJson, F as compilePredicate, or as compileRawFragment, vr as compileSelect, So as computeEmbedding, Hs as connectionIdentity, Ni as contains, ht as count, pe as countDistinct, se as crdtManagedColumns, qe as crdtText, la as currentWriteAttribution, a as databaseHandle, n as date, Ge as dbEnum, Wa as dbMetricTagCacheSizeForTests, qa as dbOperationsInFlight, re as decimal, vt as declareEnumRename, Nn as decodeRowsFromSchema, Gt as decryptFieldsOnRead, ms as defineMigration, $e as defineMixin, at as defineSeed, pt as denseRank, En as deriveSubjectGraph, Ae as deriveTypeIdPrefix, Rt as deserializeArraysOnRead, Re as drainIdentifierWarnings, ae as dropped, Fn as encodeRowForSchema, Wt as encryptFieldsForWrite, Ut as encryptedColumnsOf, Ca as endLocalWrite, zo as enforceBranchLimits, xe as ensureTableRegistered, Ti as eq, sr as escapeLike, $i as evaluatePredicate, he as except, Yi as exists, fo as expires, na as externalChangeEvent, Ne as fireSchemaChangeSeeds, Je as fireTenantCreateSeeds, fs as formatIndexAuditIssue, Dn as formatSubjectGraph, Ss as frameworkTables, tt as generateId, Pe as generateSnowflake, le as geography, f as geometry, Me as getEnumRenames, hn as getRelation, mn as getRelations, Zo as getResidencyConfig, p as getTable, Di as gt, Oi as gte, Jn as hasEagerLoads, xo as hybridSearch, v as id, ji as inSet, qi as inSubquery, on as inferForeignKey, Ms as insertRow, S as integer, l as intersect, fe as interval, Do as isBranchNamespace, en as isEmptyRelationsSpec, Ht as isEncrypted, Vt as isFieldDecryptionError, ke as isFileMigration, Qe as isFrameworkOwnedLiveTable, ho as isLocalFirst, hs as isMigrationDefinition, No as isNeonConnection, Bi as isNotNull, zi as isNull, Rs as isPrimaryKeyConflictError, es as isRegionServable, tn as isRelationsSpec, lt as isSeedDefinition, Ce as isSqliteFamily, ee as isTableReactive, Xe as isView, D as json, Gi as jsonField, e as jsonIndex, s as lag, oe as lead, qs as listRetentionConflicts, Ys as listRetentions, mo as localFirst, go as localFirstTables, ki as lt, Ai as lte, $a as makeEagerFallbackReporter, Ko as makeNamespaceBranchExecutor, rn as many, an as manyToMany, i as materializeFields, Ke as max, et as migration, t as min, js as missingConflictColumns, As as missingRequiredColumns, it as mixin, Ei as neq, Ao as nextBranchState, Vs as normaliseTarget, Wi as not, Xi as notExists, Mi as notInSet, Ji as notInSubquery, be as numeric, Ya as observeDbOp, nn as one, Ln as oneCardinalityMessage, Ui as or, w as orderClausesOf, ne as paginateBy, ie as paginateById, Ea as pendingAttributionCount, Lo as planBranch, jo as planBranchProvision, Mo as planBranchTeardown, Ro as planBranchTeardownFor, Fo as planNeonBranchProvision, Io as planNeonBranchTeardown, so as planVersionedUpdate, gt as pluginRef, me as pluginRefSpecOf, Ls as primaryKeyConflictError, Bo as provisionBranch, rs as provisionResidentTenant, tr as qualifyTable, ce as queryFor, Ve as queryForView, Ee as quoteIdent, Is as raiseChangeListenerCeiling, d as rank, g as raw, ve as readableByColumns, Se as real, Ja as recordDbOp, Aa as recordsTable, m as reference, bi as registerCoreTables, pn as registerDiscoveredRelations, ga as registerPendingAttribution, fn as registerRelations, Js as registerRetention, rt as registerTable, Da as registerWriteRecorder, $t as relations, Si as requireActors, y as requireTable, Ci as requireTenants, Ua as resetDbMetricTagCacheForTests, Ye as resetSnowflake, ts as residentPlacement, Pt as resolveActorSnapshot, Po as resolveBranchMechanism, Qa as resolveEagerFallbackWarnIntervalMs, wa as resolveEchoAttribution, _ as resolveFullTextIndex, ot as resolveIdScheme, We as resolveMixinGraph, $o as resolveTenantHome, er as resolveTenantNamespace, Qs as retentionTtlMsFromEnv, te as rowNumber, qt as rowSchema, ro as runRetryingTransaction, io as runStoreTransaction, ca as runWithWriteAttribution, ja as runWriteRecorders, Us as sameDatabase, $n as sanitizeIdentifierFragment, Lt as serializeArraysForWrite, x as serverOnlyColumns, Xo as setResidencyConfig, Fe as setSchemaChangeSeedHook, Le as setTenantCreateSeedHook, eo as settleTransactionExit, co as settleVersionedUpdate, Vi as spatialPredicate, ws as stampGeneratedId, Ts as stampGeneratedIds, Pi as startsWith, bo as streamTable, de as sum, yt as sumOver, Zs as sweepRetention, C as table, Vo as teardownBranch, E as text, b as timestamp, bt as timestampMs, xt as timestampMsOrNull, r as union, ye as unionAll, Oa as unregisterWriteRecorder, Ps as updateManyRow, Ns as upsertRow, nt as validateColumnName, Ze as validateIndexName, _n as validateRegisteredRelations, ln as validateRelationConfig, He as validateTableName, Be as validateTypeIdPrefix, Te as vector, ct as vectorDistanceToOpclass, Co as vectorEmbedding, oo as versionColumnOf, ze as view, De as viewSql, ta as walkLeaves, da as withCapturedAttribution };
|