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