@voltro/database 0.84.0 → 0.85.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 +549 -0
- package/THIRD-PARTY-NOTICES.md +1 -57
- package/dist/index.d.ts +104 -57
- package/dist/index.js +783 -680
- package/dist/{replaceInProgress-DUHl5JEz.js → replaceInProgress-DC88Pdiy.js} +1222 -1044
- package/dist/sql.d.ts +31 -23
- package/dist/sql.js +2408 -2164
- package/dist/{wire-B28cPjEp.js → wire-CG2j7J3f.js} +1 -1
- package/dist/wire.d.ts +9 -10
- package/dist/wire.js +1 -1
- package/package.json +3 -5
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { Cause as e, Effect as t,
|
|
2
|
-
import { typeid as
|
|
3
|
-
import { ulid as
|
|
1
|
+
import { Cause as e, Effect as t, Exit as n, Schema as r, Struct as i } from "effect";
|
|
2
|
+
import { typeid as a } from "typeid-js";
|
|
3
|
+
import { ulid as o } from "ulidx";
|
|
4
|
+
import { SqlError as s, UnknownError as c } from "effect/sql/SqlError";
|
|
4
5
|
//#region src/columns.ts
|
|
5
|
-
var
|
|
6
|
+
var l = (e) => {
|
|
6
7
|
let t = [];
|
|
7
8
|
for (let [n, r] of Object.entries(e.fields)) r.serverOnly === !0 && t.push(n);
|
|
8
9
|
return t;
|
|
9
|
-
},
|
|
10
|
+
}, u = (e) => {
|
|
10
11
|
let t = [];
|
|
11
12
|
for (let [n, r] of Object.entries(e.fields)) r.crdtManaged === !0 && t.push(n);
|
|
12
13
|
return t;
|
|
13
|
-
},
|
|
14
|
+
}, d = (e) => {
|
|
14
15
|
let t = [];
|
|
15
16
|
for (let [n, r] of Object.entries(e.fields)) {
|
|
16
17
|
let e = r.readableBy;
|
|
@@ -20,11 +21,11 @@ var o = (e) => {
|
|
|
20
21
|
});
|
|
21
22
|
}
|
|
22
23
|
return t;
|
|
23
|
-
},
|
|
24
|
+
}, f = (e) => {
|
|
24
25
|
let t = [];
|
|
25
26
|
for (let [n, r] of Object.entries(e.fields)) r.crdtManaged === !0 && t.push(n);
|
|
26
27
|
return t;
|
|
27
|
-
},
|
|
28
|
+
}, p = class e {
|
|
28
29
|
definition;
|
|
29
30
|
constructor(e) {
|
|
30
31
|
this.definition = e;
|
|
@@ -185,14 +186,14 @@ var o = (e) => {
|
|
|
185
186
|
__definition() {
|
|
186
187
|
return this.definition;
|
|
187
188
|
}
|
|
188
|
-
},
|
|
189
|
+
}, m = (e) => new p({
|
|
189
190
|
type: e,
|
|
190
191
|
nullable: !1,
|
|
191
192
|
unique: !1,
|
|
192
193
|
hasDefault: !1
|
|
193
194
|
});
|
|
194
|
-
function
|
|
195
|
-
return new
|
|
195
|
+
function h(e) {
|
|
196
|
+
return new p({
|
|
196
197
|
type: "id",
|
|
197
198
|
nullable: !1,
|
|
198
199
|
unique: !0,
|
|
@@ -200,10 +201,10 @@ function f(e) {
|
|
|
200
201
|
idSchemeInput: e
|
|
201
202
|
});
|
|
202
203
|
}
|
|
203
|
-
var
|
|
204
|
+
var g = () => m("text"), _ = () => m("integer"), v = () => m("real"), y = (e, t = 0) => {
|
|
204
205
|
if (!Number.isInteger(e) || e <= 0) throw Error(`decimal(${String(e)}, ${String(t)}): precision must be a positive integer (the total number of significant digits, e.g. decimal(12, 2)).`);
|
|
205
206
|
if (!Number.isInteger(t) || t < 0 || t > e) throw Error(`decimal(${String(e)}, ${String(t)}): scale must be an integer between 0 and precision (${e}).`);
|
|
206
|
-
return new
|
|
207
|
+
return new p({
|
|
207
208
|
type: "decimal",
|
|
208
209
|
nullable: !1,
|
|
209
210
|
unique: !1,
|
|
@@ -212,12 +213,12 @@ var p = () => d("text"), m = () => d("integer"), h = () => d("real"), g = (e, t
|
|
|
212
213
|
scale: t,
|
|
213
214
|
sqliteDecimalEncoding: "sortable-v1"
|
|
214
215
|
});
|
|
215
|
-
},
|
|
216
|
+
}, b = y, x = () => m("bigint"), S = (e, t) => {
|
|
216
217
|
if (t.length === 0) throw Error(`dbEnum('${e}', []): enum must have at least one value`);
|
|
217
218
|
return {
|
|
218
219
|
name: e,
|
|
219
220
|
values: t,
|
|
220
|
-
column: () => new
|
|
221
|
+
column: () => new p({
|
|
221
222
|
type: "enum",
|
|
222
223
|
nullable: !1,
|
|
223
224
|
unique: !1,
|
|
@@ -226,38 +227,38 @@ var p = () => d("text"), m = () => d("integer"), h = () => d("real"), g = (e, t
|
|
|
226
227
|
enumValues: t
|
|
227
228
|
})
|
|
228
229
|
};
|
|
229
|
-
},
|
|
230
|
+
}, C = () => m("boolean"), w = () => m("timestamp"), T = () => m("date"), E = () => m("json"), D = () => m("bytes"), O = () => new p({
|
|
230
231
|
type: "bytes",
|
|
231
232
|
nullable: !0,
|
|
232
233
|
unique: !1,
|
|
233
234
|
hasDefault: !1,
|
|
234
235
|
crdtManaged: !0
|
|
235
|
-
}),
|
|
236
|
+
}), k = () => new p({
|
|
236
237
|
type: "bytes",
|
|
237
238
|
nullable: !0,
|
|
238
239
|
unique: !1,
|
|
239
240
|
hasDefault: !1,
|
|
240
241
|
crdtManaged: !0
|
|
241
|
-
}),
|
|
242
|
+
}), ee = () => new p({
|
|
242
243
|
type: "bytes",
|
|
243
244
|
nullable: !0,
|
|
244
245
|
unique: !1,
|
|
245
246
|
hasDefault: !1,
|
|
246
247
|
crdtSealed: !0
|
|
247
|
-
}),
|
|
248
|
+
}), A = () => new p({
|
|
248
249
|
type: "bytes",
|
|
249
250
|
nullable: !0,
|
|
250
251
|
unique: !1,
|
|
251
252
|
hasDefault: !1,
|
|
252
253
|
crdtManaged: !0
|
|
253
|
-
}),
|
|
254
|
+
}), j = () => {
|
|
254
255
|
throw Error("selfReference(): the target is resolved by table() — a column built with selfReference() must be declared inside a table({ … }) literal, not read before the table exists");
|
|
255
256
|
};
|
|
256
|
-
function
|
|
257
|
-
return
|
|
257
|
+
function M(e) {
|
|
258
|
+
return N(j, e);
|
|
258
259
|
}
|
|
259
|
-
function
|
|
260
|
-
return new
|
|
260
|
+
function N(e, t) {
|
|
261
|
+
return new p({
|
|
261
262
|
type: "reference",
|
|
262
263
|
nullable: !1,
|
|
263
264
|
unique: !1,
|
|
@@ -272,15 +273,15 @@ function k(e, t) {
|
|
|
272
273
|
...t?.orphanPolicy ? { orphanPolicy: t.orphanPolicy } : {}
|
|
273
274
|
});
|
|
274
275
|
}
|
|
275
|
-
var
|
|
276
|
+
var P = () => new p({
|
|
276
277
|
type: "text",
|
|
277
278
|
nullable: !0,
|
|
278
279
|
unique: !1,
|
|
279
280
|
hasDefault: !1,
|
|
280
281
|
dropped: !0
|
|
281
|
-
}),
|
|
282
|
+
}), F = (e) => Object.keys(e.fields).filter((t) => e.fields[t]?.dropped !== !0), te = (e, t) => {
|
|
282
283
|
if (!Number.isInteger(e) || e <= 0) throw Error(`vector(${String(e)}): dimension must be a positive integer (the embedding length, e.g. vector(1536)).`);
|
|
283
|
-
return new
|
|
284
|
+
return new p({
|
|
284
285
|
type: "vector",
|
|
285
286
|
nullable: !1,
|
|
286
287
|
unique: !1,
|
|
@@ -288,13 +289,13 @@ var A = () => new u({
|
|
|
288
289
|
vectorDim: e,
|
|
289
290
|
vectorPrecision: t?.precision ?? "float32"
|
|
290
291
|
});
|
|
291
|
-
},
|
|
292
|
+
}, I = (e) => new p({
|
|
292
293
|
type: "array",
|
|
293
294
|
nullable: !1,
|
|
294
295
|
unique: !1,
|
|
295
296
|
hasDefault: !1,
|
|
296
297
|
arrayElement: e.__definition().type
|
|
297
|
-
}),
|
|
298
|
+
}), ne = () => m("interval"), re = (e, t = 4326) => new p({
|
|
298
299
|
type: "text",
|
|
299
300
|
nullable: !1,
|
|
300
301
|
unique: !1,
|
|
@@ -304,7 +305,7 @@ var A = () => new u({
|
|
|
304
305
|
geomKind: e,
|
|
305
306
|
srid: t
|
|
306
307
|
}
|
|
307
|
-
}),
|
|
308
|
+
}), ie = (e, t = 4326) => new p({
|
|
308
309
|
type: "text",
|
|
309
310
|
nullable: !1,
|
|
310
311
|
unique: !1,
|
|
@@ -314,182 +315,194 @@ var A = () => new u({
|
|
|
314
315
|
geomKind: e,
|
|
315
316
|
srid: t
|
|
316
317
|
}
|
|
317
|
-
}),
|
|
318
|
+
}), ae = (e) => new p({
|
|
318
319
|
type: "raw",
|
|
319
320
|
nullable: !1,
|
|
320
321
|
unique: !1,
|
|
321
322
|
hasDefault: !1,
|
|
322
323
|
rawDdl: e
|
|
323
|
-
}),
|
|
324
|
+
}), oe = (e) => {
|
|
324
325
|
let t = {};
|
|
325
326
|
for (let [n, r] of Object.entries(e)) t[n] = r.__definition();
|
|
326
327
|
return t;
|
|
327
|
-
},
|
|
328
|
-
|
|
329
|
-
|
|
328
|
+
}, se = Symbol.for("@voltro/database/pluginRefSpec"), ce = (e) => {
|
|
329
|
+
if (typeof e == "object" && e) return ("__definition" in e && typeof e.__definition == "function" ? e.__definition() : e)[se];
|
|
330
|
+
}, le = (e, t = {}) => {
|
|
331
|
+
let n = {
|
|
330
332
|
target: e,
|
|
331
333
|
orphanPolicy: t.orphanPolicy ?? "keep",
|
|
332
334
|
onSoftDelete: t.onSoftDelete ?? !1
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
+
};
|
|
336
|
+
return new p({
|
|
337
|
+
...g().__definition(),
|
|
338
|
+
[se]: n
|
|
339
|
+
});
|
|
340
|
+
}, ue = /* @__PURE__ */ new Map(), de = (e, t) => {
|
|
335
341
|
if (t.from === t.to) throw Error(`declareEnumRename('${e}'): \`from\` and \`to\` are both '${t.from}' — a rename must change the value.`);
|
|
336
|
-
let n =
|
|
342
|
+
let n = ue.get(e) ?? [];
|
|
337
343
|
for (let r of n) {
|
|
338
344
|
if (r.from === t.from && r.to === t.to) return;
|
|
339
345
|
if (r.from === t.from && r.to !== t.to) throw Error(`declareEnumRename('${e}'): value '${t.from}' is already declared as renamed to '${r.to}', cannot also rename it to '${t.to}'.`);
|
|
340
346
|
}
|
|
341
|
-
n.push(t),
|
|
342
|
-
}, fe = (e) =>
|
|
343
|
-
|
|
344
|
-
}, he = (t) => {
|
|
345
|
-
let
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
if (r
|
|
350
|
-
let i = t[
|
|
351
|
-
if (
|
|
352
|
-
let
|
|
353
|
-
for (let e of
|
|
354
|
-
return
|
|
355
|
-
},
|
|
356
|
-
|
|
347
|
+
n.push(t), ue.set(e, n);
|
|
348
|
+
}, fe = (e) => ue.get(e) ?? [], pe = () => ue, me = () => {
|
|
349
|
+
ue.clear();
|
|
350
|
+
}, he = (t) => e.isCause(t) ? t : n.isExit(t) && n.isFailure(t) ? t.cause : typeof t == "object" && t && e.isCause(t.voltroCause) ? t.voltroCause : void 0, ge = (t) => {
|
|
351
|
+
let n = he(t);
|
|
352
|
+
return n === void 0 ? t : e.squash(n);
|
|
353
|
+
}, _e = (t, n = 0) => {
|
|
354
|
+
let r = n >= 4 ? void 0 : he(t);
|
|
355
|
+
if (r === void 0) return [t];
|
|
356
|
+
let i = r.reasons.flatMap((t) => e.isFailReason(t) ? [t.error] : e.isDieReason(t) ? [t.defect] : []);
|
|
357
|
+
if (i.length === 0) return [e.squash(r)];
|
|
358
|
+
let a = [];
|
|
359
|
+
for (let e of i.slice(0, 8)) a.push(..._e(e, n + 1));
|
|
360
|
+
return a;
|
|
361
|
+
}, ve = (e) => e.dbCode !== void 0 || e.dbErrno !== void 0 || e.dbNumber !== void 0 || e.dbSqlState !== void 0 || e.dbConstraint !== void 0, ye = {
|
|
362
|
+
9: "SQLITE_INTERRUPT",
|
|
363
|
+
275: "SQLITE_CONSTRAINT_CHECK",
|
|
364
|
+
787: "SQLITE_CONSTRAINT_FOREIGNKEY",
|
|
365
|
+
1299: "SQLITE_CONSTRAINT_NOTNULL",
|
|
366
|
+
1555: "SQLITE_CONSTRAINT_PRIMARYKEY",
|
|
367
|
+
2067: "SQLITE_CONSTRAINT_UNIQUE"
|
|
368
|
+
}, be = (e) => {
|
|
369
|
+
let t = {}, n = [], r = ge(e);
|
|
357
370
|
for (let e = 0; e < 8 && typeof r == "object" && r; e++) {
|
|
358
371
|
let e = r;
|
|
359
|
-
t.dbCode === void 0 && (typeof e.code == "string" || typeof e.code == "number") && (t.dbCode = e.code), t.dbErrno === void 0 && typeof e.errno == "number" && (t.dbErrno = e.errno), t.dbNumber === void 0 && typeof e.number == "number" && (t.dbNumber = e.number), t.dbSqlState === void 0 && typeof e.sqlState == "string" && (t.dbSqlState = e.sqlState), t.dbBindings === void 0 && typeof e.voltroBindings == "string" && (t.dbBindings = e.voltroBindings), t.dbStatement === void 0 && typeof e.sql == "string" && e.sql.includes("?") && (t.dbStatement = e.sql, t.dbPlaceholders = (e.sql.match(/\?/g) ?? []).length), t.dbFatal === void 0 && typeof e.fatal == "boolean" && (t.dbFatal = e.fatal), t.dbConstraint === void 0 && typeof e.constraint == "string" && (t.dbConstraint = e.constraint), t.dbTable === void 0 && typeof e.table == "string" && (t.dbTable = e.table), t.dbColumn === void 0 && typeof e.column == "string" && (t.dbColumn = e.column), t.dbSchema === void 0 && typeof e.schema == "string" && (t.dbSchema = e.schema);
|
|
372
|
+
t.dbCode === void 0 && (typeof e.code == "string" || typeof e.code == "number") && (t.dbCode = e.code), t.dbErrno === void 0 && typeof e.errno == "number" && (t.dbErrno = e.errno), t.dbErrno === void 0 && typeof e.errcode == "number" && (t.dbErrno = e.errcode), t.dbCode === "ERR_SQLITE_ERROR" && typeof t.dbErrno == "number" && (t.dbCode = ye[t.dbErrno] ?? t.dbCode), t.dbNumber === void 0 && typeof e.number == "number" && (t.dbNumber = e.number), t.dbSqlState === void 0 && typeof e.sqlState == "string" && (t.dbSqlState = e.sqlState), t.dbBindings === void 0 && typeof e.voltroBindings == "string" && (t.dbBindings = e.voltroBindings), t.dbStatement === void 0 && typeof e.sql == "string" && e.sql.includes("?") && (t.dbStatement = e.sql, t.dbPlaceholders = (e.sql.match(/\?/g) ?? []).length), t.dbFatal === void 0 && typeof e.fatal == "boolean" && (t.dbFatal = e.fatal), t.dbConstraint === void 0 && typeof e.constraint == "string" && (t.dbConstraint = e.constraint), t.dbTable === void 0 && typeof e.table == "string" && (t.dbTable = e.table), t.dbColumn === void 0 && typeof e.column == "string" && (t.dbColumn = e.column), t.dbSchema === void 0 && typeof e.schema == "string" && (t.dbSchema = e.schema);
|
|
360
373
|
let i = e.sqlMessage ?? e.detail;
|
|
361
374
|
t.dbMessage === void 0 && typeof i == "string" && (t.dbMessage = i);
|
|
362
375
|
let a = typeof e.constructor == "function" ? e.constructor.name : void 0, o = typeof e._tag == "string" && e._tag || typeof e.name == "string" && e.name || (typeof a == "string" && a !== "Object" ? a : void 0), s = typeof e.message == "string" ? e.message : void 0;
|
|
363
|
-
(o || s) && n.push(`${o || "Error"}${s ? `: ${s.slice(0, 200)}` : ""}`), r =
|
|
376
|
+
(o || s) && n.push(`${o || "Error"}${s ? `: ${s.slice(0, 200)}` : ""}`), r = ge(e.reason ?? e.cause);
|
|
364
377
|
}
|
|
365
378
|
return n.length > 0 && (t.dbCauseChain = n.join(" ← "), t.dbMessage === void 0 && (t.dbMessage = n[n.length - 1])), t;
|
|
366
|
-
},
|
|
367
|
-
let t =
|
|
379
|
+
}, xe = (e) => {
|
|
380
|
+
let t = _e(e).map(be);
|
|
368
381
|
if (t.length <= 1) return t[0] ?? {};
|
|
369
|
-
let n = t.find(
|
|
382
|
+
let n = t.find(ve) ?? t[0], r = t.filter((e) => e !== n).map((e) => e.dbCauseChain).filter((e) => typeof e == "string");
|
|
370
383
|
if (r.length === 0) return n;
|
|
371
384
|
let i = typeof n.dbCauseChain == "string" ? n.dbCauseChain : void 0;
|
|
372
385
|
return {
|
|
373
386
|
...n,
|
|
374
387
|
dbCauseChain: [i, ...r].filter(Boolean).join(" ‖ ")
|
|
375
388
|
};
|
|
376
|
-
},
|
|
377
|
-
let n =
|
|
389
|
+
}, Se = (e, t) => {
|
|
390
|
+
let n = we(e);
|
|
378
391
|
if (n !== void 0) return n;
|
|
379
|
-
let r =
|
|
392
|
+
let r = xe(e), i = Ae(r, t);
|
|
380
393
|
if (i !== void 0) {
|
|
381
394
|
let e = i.constraint ?? i.column;
|
|
382
395
|
return e === void 0 ? i.kind : `${i.kind}: ${e}`;
|
|
383
396
|
}
|
|
384
|
-
let a = r.dbCode ?? r.dbSqlState ?? r.dbErrno ?? r.dbNumber, o =
|
|
385
|
-
return a !== void 0 &&
|
|
386
|
-
},
|
|
397
|
+
let a = r.dbCode ?? r.dbSqlState ?? r.dbErrno ?? r.dbNumber, o = De(e);
|
|
398
|
+
return a !== void 0 && Te.test(String(a)) ? `${o} (${String(a)})` : o;
|
|
399
|
+
}, Ce = Symbol.for("@voltro/database/authoredMessage"), L = (e, t) => {
|
|
387
400
|
let n = t === void 0 ? Error(e) : Error(e, t);
|
|
388
|
-
return Object.defineProperty(n,
|
|
401
|
+
return Object.defineProperty(n, Ce, {
|
|
389
402
|
value: !0,
|
|
390
403
|
enumerable: !1
|
|
391
404
|
}), n;
|
|
392
|
-
},
|
|
393
|
-
for (let t of
|
|
405
|
+
}, we = (e) => {
|
|
406
|
+
for (let t of _e(e)) {
|
|
394
407
|
let e = t;
|
|
395
408
|
for (let t = 0; typeof e == "object" && e && t < 8; t += 1) {
|
|
396
|
-
if (e[
|
|
409
|
+
if (e[Ce] === !0) {
|
|
397
410
|
let t = e.message;
|
|
398
411
|
if (typeof t == "string" && t.length > 0) return t;
|
|
399
412
|
}
|
|
400
413
|
e = e.cause;
|
|
401
414
|
}
|
|
402
415
|
}
|
|
403
|
-
},
|
|
416
|
+
}, Te = /^[A-Za-z0-9_]{1,32}$/, Ee = /^[A-Za-z_][A-Za-z0-9_]{0,63}$/, De = (e) => {
|
|
404
417
|
let t = e?._tag, n = e?.name, r = (typeof t == "string" ? t : typeof n == "string" ? n : "").split(/[^A-Za-z0-9_]+/).filter(Boolean).pop();
|
|
405
|
-
return r !== void 0 &&
|
|
406
|
-
},
|
|
418
|
+
return r !== void 0 && Ee.test(r) ? r : "unknown";
|
|
419
|
+
}, Oe = /^[A-Za-z_][A-Za-z0-9_$]*$/, R = (e) => e !== void 0 && e.length <= 128 && Oe.test(e) ? e : void 0, ke = (e) => e === void 0 ? void 0 : e.split(".").pop() ?? e, z = (e, ...t) => {
|
|
407
420
|
for (let n of t) {
|
|
408
421
|
let t = n.exec(e);
|
|
409
422
|
if (t?.[1] !== void 0) return t[1];
|
|
410
423
|
}
|
|
411
|
-
},
|
|
424
|
+
}, Ae = (e, t) => {
|
|
412
425
|
let n = e.dbCode, r = e.dbErrno, i = e.dbNumber, a = typeof e.dbMessage == "string" ? e.dbMessage : "", o = `${typeof e.dbCauseChain == "string" ? e.dbCauseChain : ""} ${a}`;
|
|
413
426
|
if (n === "23503") {
|
|
414
|
-
let t =
|
|
427
|
+
let t = R(e.dbConstraint);
|
|
415
428
|
return {
|
|
416
429
|
kind: /is still referenced from table/i.test(o) ? "foreignKeyInUse" : "foreignKey",
|
|
417
430
|
...t === void 0 ? {} : { constraint: t }
|
|
418
431
|
};
|
|
419
432
|
}
|
|
420
433
|
if (n === "23505") {
|
|
421
|
-
let t =
|
|
434
|
+
let t = R(e.dbConstraint);
|
|
422
435
|
return {
|
|
423
436
|
kind: "unique",
|
|
424
437
|
...t === void 0 ? {} : { constraint: t }
|
|
425
438
|
};
|
|
426
439
|
}
|
|
427
440
|
if (n === "23502") {
|
|
428
|
-
let t =
|
|
441
|
+
let t = R(e.dbColumn);
|
|
429
442
|
return {
|
|
430
443
|
kind: "notNull",
|
|
431
444
|
...t === void 0 ? {} : { column: t }
|
|
432
445
|
};
|
|
433
446
|
}
|
|
434
447
|
if (n === "23514") {
|
|
435
|
-
let t =
|
|
448
|
+
let t = R(e.dbConstraint);
|
|
436
449
|
return {
|
|
437
450
|
kind: "check",
|
|
438
451
|
...t === void 0 ? {} : { constraint: t }
|
|
439
452
|
};
|
|
440
453
|
}
|
|
441
454
|
if (r === 1452 || r === 1451) {
|
|
442
|
-
let e =
|
|
455
|
+
let e = R(z(o, /CONSTRAINT `([^`]+)`/));
|
|
443
456
|
return {
|
|
444
457
|
kind: r === 1451 ? "foreignKeyInUse" : "foreignKey",
|
|
445
458
|
...e === void 0 ? {} : { constraint: e }
|
|
446
459
|
};
|
|
447
460
|
}
|
|
448
461
|
if (r === 1062) {
|
|
449
|
-
let e =
|
|
462
|
+
let e = R(ke(z(o, /for key '([^']+)'/)));
|
|
450
463
|
return {
|
|
451
464
|
kind: "unique",
|
|
452
465
|
...e === void 0 ? {} : { constraint: e }
|
|
453
466
|
};
|
|
454
467
|
}
|
|
455
468
|
if (r === 1048 || r === 1364) {
|
|
456
|
-
let e =
|
|
469
|
+
let e = R(z(o, /Column '([^']+)' cannot be null/, /Field '([^']+)' doesn't have a default value/));
|
|
457
470
|
return {
|
|
458
471
|
kind: "notNull",
|
|
459
472
|
...e === void 0 ? {} : { column: e }
|
|
460
473
|
};
|
|
461
474
|
}
|
|
462
475
|
if (r === 3819 || r === 4025) {
|
|
463
|
-
let e =
|
|
476
|
+
let e = R(z(o, /Check constraint '([^']+)'/, /CONSTRAINT `([^`]+)` failed/));
|
|
464
477
|
return {
|
|
465
478
|
kind: "check",
|
|
466
479
|
...e === void 0 ? {} : { constraint: e }
|
|
467
480
|
};
|
|
468
481
|
}
|
|
469
482
|
if (i === 547) {
|
|
470
|
-
let e =
|
|
483
|
+
let e = z(o, /(?:FOREIGN KEY|REFERENCE) constraint "([^"]+)"/), t = z(o, /CHECK constraint "([^"]+)"/);
|
|
471
484
|
if (t !== void 0 && e === void 0) {
|
|
472
|
-
let e =
|
|
485
|
+
let e = R(t);
|
|
473
486
|
return {
|
|
474
487
|
kind: "check",
|
|
475
488
|
...e === void 0 ? {} : { constraint: e }
|
|
476
489
|
};
|
|
477
490
|
}
|
|
478
|
-
let n = /REFERENCE constraint/.test(o), r =
|
|
491
|
+
let n = /REFERENCE constraint/.test(o), r = R(e);
|
|
479
492
|
return {
|
|
480
493
|
kind: n ? "foreignKeyInUse" : "foreignKey",
|
|
481
494
|
...r === void 0 ? {} : { constraint: r }
|
|
482
495
|
};
|
|
483
496
|
}
|
|
484
497
|
if (i === 2627 || i === 2601) {
|
|
485
|
-
let e =
|
|
498
|
+
let e = R(z(o, /(?:UNIQUE KEY|PRIMARY KEY) constraint '([^']+)'/, /index '([^']+)'/));
|
|
486
499
|
return {
|
|
487
500
|
kind: "unique",
|
|
488
501
|
...e === void 0 ? {} : { constraint: e }
|
|
489
502
|
};
|
|
490
503
|
}
|
|
491
504
|
if (i === 515) {
|
|
492
|
-
let e =
|
|
505
|
+
let e = R(z(o, /Cannot insert the value NULL into column '([^']+)'/));
|
|
493
506
|
return {
|
|
494
507
|
kind: "notNull",
|
|
495
508
|
...e === void 0 ? {} : { column: e }
|
|
@@ -497,40 +510,40 @@ var A = () => new u({
|
|
|
497
510
|
}
|
|
498
511
|
if (n === "SQLITE_CONSTRAINT_FOREIGNKEY") return { kind: t === "delete" || t === "deleteMany" || t === "hardDelete" ? "foreignKeyInUse" : "foreignKey" };
|
|
499
512
|
if (n === "SQLITE_CONSTRAINT_UNIQUE" || n === "SQLITE_CONSTRAINT_PRIMARYKEY") {
|
|
500
|
-
let e =
|
|
513
|
+
let e = R(ke(z(o, /UNIQUE constraint failed: ([^,\s]+)/)));
|
|
501
514
|
return {
|
|
502
515
|
kind: "unique",
|
|
503
516
|
...e === void 0 ? {} : { column: e }
|
|
504
517
|
};
|
|
505
518
|
}
|
|
506
519
|
if (n === "SQLITE_CONSTRAINT_NOTNULL") {
|
|
507
|
-
let e =
|
|
520
|
+
let e = R(ke(z(o, /NOT NULL constraint failed: ([^,\s]+)/)));
|
|
508
521
|
return {
|
|
509
522
|
kind: "notNull",
|
|
510
523
|
...e === void 0 ? {} : { column: e }
|
|
511
524
|
};
|
|
512
525
|
}
|
|
513
526
|
if (n === "SQLITE_CONSTRAINT_CHECK") {
|
|
514
|
-
let e =
|
|
527
|
+
let e = R(z(a, /CHECK constraint failed: (.+)$/));
|
|
515
528
|
return {
|
|
516
529
|
kind: "check",
|
|
517
530
|
...e === void 0 ? {} : { constraint: e }
|
|
518
531
|
};
|
|
519
532
|
}
|
|
520
|
-
},
|
|
521
|
-
let t =
|
|
533
|
+
}, je = (e) => {
|
|
534
|
+
let t = Ae(e)?.kind;
|
|
522
535
|
return t === "foreignKey" || t === "foreignKeyInUse";
|
|
523
|
-
},
|
|
536
|
+
}, Me = (e) => {
|
|
524
537
|
let t = e.dbCode, n = e.dbErrno;
|
|
525
538
|
return t === "57014" || n === 3024 || n === 1969 || t === "ETIMEOUT" || t === "SQLITE_INTERRUPT";
|
|
526
|
-
},
|
|
539
|
+
}, Ne = (e) => {
|
|
527
540
|
if (e.dbErrno !== 1366) return;
|
|
528
541
|
let t = `${typeof e.dbCauseChain == "string" ? e.dbCauseChain : ""} ${typeof e.dbMessage == "string" ? e.dbMessage : ""}`;
|
|
529
542
|
if (/Incorrect string value: '\\x(F[0-4])/i.exec(t) === null) return;
|
|
530
|
-
let n =
|
|
543
|
+
let n = z(t, /for column [`']?(?:[^`'.]+[`']?\.[`']?)*([^`'.]+)[`']? at row/);
|
|
531
544
|
return `${n === void 0 ? "the column" : `column '${n}'`} is stored in a character set that cannot hold a 4-byte character (utf8mb3). Declare the store's character set in app.config.ts — store: { dialect: 'mariadb' | 'mysql', charset: 'utf8mb4' } — and run \`voltro db plan\`: every declared table is created with it and converted to it.`;
|
|
532
|
-
},
|
|
533
|
-
let t =
|
|
545
|
+
}, Pe = (e) => {
|
|
546
|
+
let t = xe(e), n = [
|
|
534
547
|
t.dbCode === void 0 ? void 0 : `code=${String(t.dbCode)}`,
|
|
535
548
|
t.dbErrno === void 0 ? void 0 : `errno=${String(t.dbErrno)}`,
|
|
536
549
|
t.dbNumber === void 0 ? void 0 : `number=${String(t.dbNumber)}`,
|
|
@@ -539,9 +552,9 @@ var A = () => new u({
|
|
|
539
552
|
t.dbPlaceholders === void 0 ? void 0 : `placeholders=${String(t.dbPlaceholders)}`
|
|
540
553
|
].filter((e) => e !== void 0), r = typeof e?.message == "string" ? e.message : void 0, i = typeof t.dbMessage == "string" ? t.dbMessage : void 0, a = i === void 0 ? void 0 : n.length > 0 || i !== r && i !== `Error: ${String(r)}` ? i : void 0, o = typeof t.dbBindings == "string" ? `\n bindings: ${t.dbBindings}` : "", s = typeof t.dbStatement == "string" ? `\n statement: ${t.dbStatement.length <= 400 ? t.dbStatement : `${t.dbStatement.slice(0, 400)}…`}` : "";
|
|
541
554
|
if (a === void 0 && n.length === 0) return;
|
|
542
|
-
let c =
|
|
555
|
+
let c = Ne(t), l = c === void 0 ? "" : `\n hint: ${c}`;
|
|
543
556
|
return [a, n.length > 0 ? `[${n.join(" ")}]` : void 0].filter((e) => e !== void 0 && e !== "").join(" ") + l + s + o;
|
|
544
|
-
},
|
|
557
|
+
}, Fe = (e) => Object.entries(e).map(([e, t]) => `${e}:${Ie(t)}`).join(" "), Ie = (e) => {
|
|
545
558
|
if (e === null) return "null";
|
|
546
559
|
if (e === void 0) return "undefined";
|
|
547
560
|
if (typeof e == "bigint") return "bigint";
|
|
@@ -551,24 +564,24 @@ var A = () => new u({
|
|
|
551
564
|
if (globalThis.Buffer !== void 0 && globalThis.Buffer.isBuffer(e)) return "Buffer";
|
|
552
565
|
let t = e.constructor?.name;
|
|
553
566
|
return typeof t == "string" && t !== "" ? t : "Object";
|
|
554
|
-
},
|
|
555
|
-
|
|
556
|
-
},
|
|
557
|
-
let e =
|
|
558
|
-
return
|
|
559
|
-
},
|
|
567
|
+
}, Le = 63, Re = 60, ze = /* @__PURE__ */ new Set(), Be = (e) => {
|
|
568
|
+
ze.add(e);
|
|
569
|
+
}, Ve = () => {
|
|
570
|
+
let e = [...ze];
|
|
571
|
+
return ze.clear(), e;
|
|
572
|
+
}, He = /^[a-zA-Z_][a-zA-Z0-9_]*$/, Ue = (e, t) => {
|
|
560
573
|
if (t.length === 0) throw Error(`${e} cannot be empty.`);
|
|
561
|
-
if (!
|
|
562
|
-
},
|
|
563
|
-
if (
|
|
564
|
-
e.length > 60 &&
|
|
565
|
-
},
|
|
566
|
-
if (
|
|
567
|
-
t.length > 60 &&
|
|
568
|
-
},
|
|
569
|
-
if (
|
|
570
|
-
t.length > 60 &&
|
|
571
|
-
},
|
|
574
|
+
if (!He.test(t)) throw Error(`${e} '${t}' contains characters outside [A-Za-z0-9_] or starts with a digit. Dialect-portable identifiers must match /^[a-zA-Z_][a-zA-Z0-9_]*$/.`);
|
|
575
|
+
}, We = (e) => {
|
|
576
|
+
if (Ue("table name", e), e.length > 63) throw Error(`table name '${e}' is ${e.length} chars — exceeds the 63-byte cross-dialect limit (Postgres floor). Shorten the name; long table names also cascade into auto-named indexes and FK constraints that would themselves exceed the limit.`);
|
|
577
|
+
e.length > 60 && Be(`table name '${e}' is ${e.length} chars — ${63 - e.length} from the Postgres 63-byte limit. Auto-named indexes on this table will run out of room fast.`);
|
|
578
|
+
}, Ge = (e, t) => {
|
|
579
|
+
if (Ue("column name", t), t.length > 63) throw Error(`column '${t}' on table '${e}' is ${t.length} chars — exceeds the 63-byte cross-dialect limit (Postgres floor). Rename it.`);
|
|
580
|
+
t.length > 60 && Be(`column '${t}' on table '${e}' is ${t.length} chars — close to the 63-byte limit.`);
|
|
581
|
+
}, B = (e, t, n, r) => {
|
|
582
|
+
if (Ue("index name", t), t.length > 63) throw Error(n ? `auto-named index '${t}' on table '${e}' is ${t.length} chars — exceeds the 63-byte cross-dialect limit (Postgres floor). Supply an explicit short name: .index('<shortName>', ${JSON.stringify([...r])}).` : `index name '${t}' on table '${e}' is ${t.length} chars — exceeds the 63-byte cross-dialect limit (Postgres floor). Shorten it.`);
|
|
583
|
+
t.length > 60 && Be(`index '${t}' on table '${e}' is ${t.length} chars — ${63 - t.length} from the 63-byte limit. ${n ? `Consider .index('<shortName>', ${JSON.stringify([...r])}) before it grows.` : ""}`);
|
|
584
|
+
}, Ke = (e, t) => {
|
|
572
585
|
if (e.length === 0) throw Error(`typeid prefix on table '${t.tableName}' cannot be empty.`);
|
|
573
586
|
if (!/^[a-z][a-z0-9_]*$/.test(e)) {
|
|
574
587
|
let n = t.kind === "derived" ? "the derived prefix doesn't match typeid's required shape — supply an explicit one via id({ prefix: '...' })." : "the prefix must match typeid's required shape /^[a-z][a-z0-9_]*$/.";
|
|
@@ -578,44 +591,44 @@ var A = () => new u({
|
|
|
578
591
|
let n = t.kind === "derived" ? "shorten the table name, or supply an explicit short prefix via id({ prefix: '...' })." : "pick a shorter prefix.";
|
|
579
592
|
throw Error(`typeid prefix '${e}' on table '${t.tableName}' is ${e.length} chars — exceeds the 63-byte limit; ${n}`);
|
|
580
593
|
}
|
|
581
|
-
e.length > 60 &&
|
|
582
|
-
},
|
|
594
|
+
e.length > 60 && Be(`typeid prefix '${e}' on table '${t.tableName}' is ${e.length} chars — close to the 63-byte limit. Generated ids will be even longer (prefix + '_' + 26).`);
|
|
595
|
+
}, qe = 1704067200000n, Je = 10n, Ye = 12n, Xe = (1n << Je) - 1n, Ze = (1n << Ye) - 1n, Qe = Ye, $e = 22n, et = () => {
|
|
583
596
|
let e = process.env.SNOWFLAKE_MACHINE_ID;
|
|
584
597
|
if (e === void 0 || e === "") return 0n;
|
|
585
598
|
let t = BigInt(e);
|
|
586
|
-
if (t < 0n || t >
|
|
599
|
+
if (t < 0n || t > Xe) throw Error(`SNOWFLAKE_MACHINE_ID out of range: ${e}. Must be 0..${Xe}.`);
|
|
587
600
|
return t;
|
|
588
|
-
},
|
|
601
|
+
}, tt = () => ({
|
|
589
602
|
lastMs: 0n,
|
|
590
603
|
sequence: 0n,
|
|
591
|
-
machineId:
|
|
592
|
-
}),
|
|
593
|
-
|
|
594
|
-
},
|
|
595
|
-
let t =
|
|
596
|
-
for (; t <= e;) t =
|
|
604
|
+
machineId: et()
|
|
605
|
+
}), nt, rt = () => (nt === void 0 && (nt = tt()), nt), it = () => {
|
|
606
|
+
nt = tt();
|
|
607
|
+
}, at = () => BigInt(Date.now()), ot = (e) => {
|
|
608
|
+
let t = at();
|
|
609
|
+
for (; t <= e;) t = at();
|
|
597
610
|
return t;
|
|
598
|
-
},
|
|
599
|
-
let e =
|
|
600
|
-
t === e.lastMs ? (e.sequence = e.sequence + 1n &
|
|
601
|
-
let n = t -
|
|
611
|
+
}, st = () => {
|
|
612
|
+
let e = rt(), t = at();
|
|
613
|
+
t === e.lastMs ? (e.sequence = e.sequence + 1n & Ze, e.sequence === 0n && (t = ot(e.lastMs), e.lastMs = t)) : (e.sequence = 0n, e.lastMs = t);
|
|
614
|
+
let n = t - qe;
|
|
602
615
|
if (n < 0n) throw Error("Snowflake timestamp before configured epoch (2024-01-01). System clock is wrong.");
|
|
603
|
-
return (n <<
|
|
604
|
-
},
|
|
616
|
+
return (n << $e | e.machineId << Qe | e.sequence).toString();
|
|
617
|
+
}, ct = (e) => {
|
|
605
618
|
let t = e.toLowerCase();
|
|
606
619
|
if (t.startsWith("_")) throw Error(`cannot derive a typeid prefix for table '${e}' (table names starting with '_' are not valid typeid prefixes). Pick an explicit prefix via id({ prefix: '...' }) or use a different scheme like id({ scheme: 'numeric' }) for internal tables.`);
|
|
607
620
|
if (!/^[a-z][a-z0-9_]*$/.test(t)) throw Error(`cannot derive a typeid prefix from table name '${e}' (must match [a-z][a-z0-9_]*). Pick an explicit prefix via id({ prefix: '...' }).`);
|
|
608
621
|
let n = t.endsWith("ies") && t.length > 3 ? t.slice(0, -3) + "y" : t.endsWith("ses") || t.endsWith("xes") || t.endsWith("zes") || t.endsWith("shes") || t.endsWith("ches") ? t.slice(0, -2) : t.endsWith("s") && t.length > 1 ? t.slice(0, -1) : t;
|
|
609
|
-
return
|
|
622
|
+
return Ke(n, {
|
|
610
623
|
kind: "derived",
|
|
611
624
|
tableName: e
|
|
612
625
|
}), n;
|
|
613
|
-
},
|
|
626
|
+
}, lt = (e, t) => {
|
|
614
627
|
if (e === void 0) return {
|
|
615
628
|
kind: "typeid",
|
|
616
|
-
prefix:
|
|
629
|
+
prefix: ct(t)
|
|
617
630
|
};
|
|
618
|
-
if ("prefix" in e && !("scheme" in e)) return
|
|
631
|
+
if ("prefix" in e && !("scheme" in e)) return Ke(e.prefix, {
|
|
619
632
|
kind: "explicit",
|
|
620
633
|
tableName: t
|
|
621
634
|
}), {
|
|
@@ -625,8 +638,8 @@ var A = () => new u({
|
|
|
625
638
|
if (!("scheme" in e)) throw Error("invalid id() options: no scheme or prefix");
|
|
626
639
|
switch (e.scheme) {
|
|
627
640
|
case "typeid": {
|
|
628
|
-
let n = e.prefix ??
|
|
629
|
-
return e.prefix !== void 0 &&
|
|
641
|
+
let n = e.prefix ?? ct(t);
|
|
642
|
+
return e.prefix !== void 0 && Ke(e.prefix, {
|
|
630
643
|
kind: "explicit",
|
|
631
644
|
tableName: t
|
|
632
645
|
}), {
|
|
@@ -642,22 +655,22 @@ var A = () => new u({
|
|
|
642
655
|
generate: e.generate
|
|
643
656
|
};
|
|
644
657
|
}
|
|
645
|
-
},
|
|
658
|
+
}, ut = (e, t) => {
|
|
646
659
|
switch (e.kind) {
|
|
647
|
-
case "typeid": return
|
|
648
|
-
case "ulid": return
|
|
660
|
+
case "typeid": return a(e.prefix).toString();
|
|
661
|
+
case "ulid": return o();
|
|
649
662
|
case "numeric": return null;
|
|
650
|
-
case "snowflake": return
|
|
663
|
+
case "snowflake": return st();
|
|
651
664
|
case "custom": return e.generate(t);
|
|
652
665
|
}
|
|
653
|
-
},
|
|
654
|
-
fields:
|
|
666
|
+
}, dt = (e) => ({
|
|
667
|
+
fields: oe(e.fields),
|
|
655
668
|
...e.id === void 0 ? {} : { id: e.id },
|
|
656
669
|
...e.requires === void 0 ? {} : { requires: e.requires },
|
|
657
670
|
...e.indexes === void 0 ? {} : { indexes: e.indexes },
|
|
658
671
|
...e.behaviors === void 0 ? {} : { behaviors: e.behaviors },
|
|
659
672
|
...e.policies === void 0 ? {} : { policies: e.policies }
|
|
660
|
-
}),
|
|
673
|
+
}), ft = dt, pt = (e) => {
|
|
661
674
|
let t = /* @__PURE__ */ new Set(), n = [], r = (e) => {
|
|
662
675
|
let i = e.id ?? e;
|
|
663
676
|
if (!t.has(i)) {
|
|
@@ -667,7 +680,7 @@ var A = () => new u({
|
|
|
667
680
|
};
|
|
668
681
|
for (let t of e) r(t);
|
|
669
682
|
return n;
|
|
670
|
-
},
|
|
683
|
+
}, mt = (e, ...t) => {
|
|
671
684
|
if (t.length === 0) throw Error(`jsonIndex("${e}"): at least one path segment is required`);
|
|
672
685
|
let n = (r) => ({
|
|
673
686
|
jsonPath: {
|
|
@@ -678,14 +691,14 @@ var A = () => new u({
|
|
|
678
691
|
numeric: () => n(!0)
|
|
679
692
|
});
|
|
680
693
|
return n(!1);
|
|
681
|
-
},
|
|
694
|
+
}, ht = (e = "cosine", t = "float32") => {
|
|
682
695
|
let n = t === "half" ? "halfvec" : "vector";
|
|
683
696
|
switch (e) {
|
|
684
697
|
case "cosine": return `${n}_cosine_ops`;
|
|
685
698
|
case "l2": return `${n}_l2_ops`;
|
|
686
699
|
case "inner": return `${n}_ip_ops`;
|
|
687
700
|
}
|
|
688
|
-
},
|
|
701
|
+
}, gt = [
|
|
689
702
|
"id",
|
|
690
703
|
"tenantId",
|
|
691
704
|
"createdAt",
|
|
@@ -694,7 +707,7 @@ var A = () => new u({
|
|
|
694
707
|
"updatedBy",
|
|
695
708
|
"deletedAt",
|
|
696
709
|
"deletedBy"
|
|
697
|
-
],
|
|
710
|
+
], _t = (e) => e.id ?? `<anonymous mixin: ${Object.keys(e.fields).join(", ")}>`, vt = (e, t) => `${e}_${t.join("_")}_idx`, yt = (e, t) => `${e}_${t.join("_")}_uq`, bt = (e, t, n, r, i) => {
|
|
698
711
|
if (n !== "hnsw") return;
|
|
699
712
|
if (r.length !== 1) throw Error(`hnsw index '${t}' on table '${e}' must cover exactly one vector column — got ${r.length} fields. pgvector's HNSW access method indexes a single vector column.`);
|
|
700
713
|
let a = r[0];
|
|
@@ -702,15 +715,48 @@ var A = () => new u({
|
|
|
702
715
|
let o = i[a];
|
|
703
716
|
if (o === void 0) throw Error(`hnsw index '${t}' on table '${e}' references unknown column '${a}'.`);
|
|
704
717
|
if (o.type !== "vector") throw Error(`hnsw index '${t}' on table '${e}' requires a vector() column — column '${a}' is '${o.type}'. HNSW is the pgvector approximate-nearest-neighbour method and only applies to vectors.`);
|
|
705
|
-
},
|
|
718
|
+
}, xt = (e, t) => {
|
|
706
719
|
let n;
|
|
707
720
|
for (let [r, i] of Object.entries(e)) i.type === "id" && i.idScheme === void 0 && (n === void 0 && (n = { ...e }), n[r] = {
|
|
708
721
|
...i,
|
|
709
|
-
idScheme:
|
|
722
|
+
idScheme: lt(i.idSchemeInput, t)
|
|
710
723
|
});
|
|
711
724
|
return n ?? e;
|
|
712
|
-
},
|
|
713
|
-
let
|
|
725
|
+
}, St = (e, t) => {
|
|
726
|
+
let n = (e) => Object.getPrototypeOf(e) === Object.prototype && Object.values(Object.getOwnPropertyDescriptors(e)).every((e) => "value" in e), r = (e) => {
|
|
727
|
+
if (Object.getPrototypeOf(e) !== Array.prototype || Object.hasOwn(e, Symbol.iterator)) return !1;
|
|
728
|
+
for (let t = 0; t < e.length; t++) {
|
|
729
|
+
let n = Object.getOwnPropertyDescriptor(e, String(t));
|
|
730
|
+
if (!n || !("value" in n) || typeof n.value != "string") return !1;
|
|
731
|
+
}
|
|
732
|
+
return !0;
|
|
733
|
+
}, i = 0, a = t.every((e) => {
|
|
734
|
+
let t = Object.getOwnPropertyDescriptor(e, "indexes");
|
|
735
|
+
if (t === void 0) return Object.getPrototypeOf(e) === Object.prototype;
|
|
736
|
+
if (!("value" in t)) return !1;
|
|
737
|
+
let n = t.value;
|
|
738
|
+
return n === void 0 ? !0 : Object.getPrototypeOf(n) !== Array.prototype || Object.hasOwn(n, Symbol.iterator) ? !1 : (i += n.length, !0);
|
|
739
|
+
});
|
|
740
|
+
if (!(i < 32 || !a)) {
|
|
741
|
+
for (let e of t) {
|
|
742
|
+
let t = e.indexes ?? [];
|
|
743
|
+
for (let e = 0; e < t.length; e++) {
|
|
744
|
+
let i = Object.getOwnPropertyDescriptor(t, String(e));
|
|
745
|
+
if (!i || !("value" in i) || !n(i.value) || !r(i.value.fields)) return;
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
return e.every(n) ? new Set(e.map((e) => e.name)) : void 0;
|
|
749
|
+
}
|
|
750
|
+
}, V = (e) => {
|
|
751
|
+
let t = e.appliedPrimaryKey ?? [], n = Object.entries(e.fields).flatMap(([t, n]) => {
|
|
752
|
+
let r = ce(n);
|
|
753
|
+
if (r === void 0) return [];
|
|
754
|
+
if (r.orphanPolicy === "null" && n.nullable !== !0) throw Error(`pluginRef: ${e.tableName}.${t} orphanPolicy: 'null' requires .nullable().`);
|
|
755
|
+
return [{
|
|
756
|
+
column: t,
|
|
757
|
+
...r
|
|
758
|
+
}];
|
|
759
|
+
});
|
|
714
760
|
return {
|
|
715
761
|
tableName: e.tableName,
|
|
716
762
|
fields: e.fields,
|
|
@@ -721,15 +767,15 @@ var A = () => new u({
|
|
|
721
767
|
appliedFullText: e.appliedFullText,
|
|
722
768
|
appliedChecks: e.appliedChecks,
|
|
723
769
|
appliedRules: e.appliedRules ?? [],
|
|
724
|
-
appliedPluginRefs:
|
|
770
|
+
appliedPluginRefs: n,
|
|
725
771
|
appliedPrimaryKey: t,
|
|
726
772
|
...e.previousTableName === void 0 ? {} : { previousTableName: e.previousTableName },
|
|
727
773
|
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
728
774
|
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema },
|
|
729
775
|
fullTextIndex: ((t, n, r) => {
|
|
730
776
|
if (n.length === 0) throw Error(`fullTextIndex '${t}' on '${e.tableName}' has no columns.`);
|
|
731
|
-
if (
|
|
732
|
-
return
|
|
777
|
+
if (B(e.tableName, t, !1, n), e.appliedFullText.some((e) => e.name === t)) throw Error(`duplicate full-text index '${t}' on table '${e.tableName}'.`);
|
|
778
|
+
return V({
|
|
733
779
|
...e,
|
|
734
780
|
tableName: e.tableName,
|
|
735
781
|
fields: e.fields,
|
|
@@ -750,27 +796,27 @@ var A = () => new u({
|
|
|
750
796
|
});
|
|
751
797
|
}),
|
|
752
798
|
with: ((...t) => {
|
|
753
|
-
let n =
|
|
799
|
+
let n = pt(t), r = { ...e.fields }, i = /* @__PURE__ */ new Map();
|
|
754
800
|
for (let e of Object.keys(r)) i.set(e, {
|
|
755
801
|
id: "<table>",
|
|
756
802
|
fields: {}
|
|
757
803
|
});
|
|
758
804
|
for (let t of n) for (let [n, a] of Object.entries(t.fields)) {
|
|
759
805
|
let o = i.get(n);
|
|
760
|
-
if (o !== void 0) throw Error(`mixin collision on column '${n}' in table '${e.tableName}': '${
|
|
761
|
-
|
|
806
|
+
if (o !== void 0) throw Error(`mixin collision on column '${n}' in table '${e.tableName}': '${_t(o)}' and '${_t(t)}' both define it. If they're the same mixin reached via different paths, set a shared 'id' on both. If they're genuinely different concerns, rename one of the columns.`);
|
|
807
|
+
Ge(e.tableName, n), r[n] = a, i.set(n, t);
|
|
762
808
|
}
|
|
763
|
-
let a = [...e.appliedIndexes];
|
|
809
|
+
let a = [...e.appliedIndexes], o = St(a, n);
|
|
764
810
|
for (let t of n) for (let n of t.indexes ?? []) {
|
|
765
|
-
let t = n.name ??
|
|
766
|
-
a.some((e) => e.name === t) || (
|
|
811
|
+
let t = n.name ?? vt(e.tableName, n.fields);
|
|
812
|
+
(o?.has(t) ?? a.some((e) => e.name === t)) || (B(e.tableName, t, n.name === void 0, n.fields), bt(e.tableName, t, n.kind, n.fields, r), a.push({
|
|
767
813
|
name: t,
|
|
768
814
|
fields: n.fields,
|
|
769
815
|
...n.kind === void 0 ? {} : { kind: n.kind },
|
|
770
816
|
...n.kindOptions === void 0 ? {} : { kindOptions: n.kindOptions }
|
|
771
|
-
}));
|
|
817
|
+
}), o?.add(t));
|
|
772
818
|
}
|
|
773
|
-
return
|
|
819
|
+
return V({
|
|
774
820
|
...e,
|
|
775
821
|
tableName: e.tableName,
|
|
776
822
|
fields: r,
|
|
@@ -787,10 +833,10 @@ var A = () => new u({
|
|
|
787
833
|
}),
|
|
788
834
|
index: ((...t) => {
|
|
789
835
|
let n, r, i, a = Array.isArray(t[0]);
|
|
790
|
-
if (a ? (r = t[0], i = t[1], n =
|
|
836
|
+
if (a ? (r = t[0], i = t[1], n = vt(e.tableName, r)) : (n = t[0], r = t[1], i = t[2]), r.length === 0) throw Error(`index '${n}' on table '${e.tableName}' has no fields — an index must cover at least one column.`);
|
|
791
837
|
let o = r.filter((e) => typeof e == "string");
|
|
792
|
-
if (
|
|
793
|
-
return
|
|
838
|
+
if (B(e.tableName, n, a, o), bt(e.tableName, n, i?.kind, r, e.fields), e.appliedIndexes.some((e) => e.name === n)) throw t.length === 1 ? Error(`duplicate auto-named index '${n}' on table '${e.tableName}' — you've called .index(${JSON.stringify(r)}) twice. Pass an explicit name to the second one if both are intended (rare).`) : Error(`duplicate index '${n}' on table '${e.tableName}': each index name must be unique within a table.`);
|
|
839
|
+
return V({
|
|
794
840
|
...e,
|
|
795
841
|
tableName: e.tableName,
|
|
796
842
|
fields: e.fields,
|
|
@@ -814,8 +860,8 @@ var A = () => new u({
|
|
|
814
860
|
expressionIndex: ((t, n, r) => {
|
|
815
861
|
if (n.length === 0) throw Error(`expressionIndex '${t}' on table '${e.tableName}' has no fields — an index must cover at least one column or expression.`);
|
|
816
862
|
let i = n.filter((e) => typeof e == "string");
|
|
817
|
-
if (
|
|
818
|
-
return
|
|
863
|
+
if (B(e.tableName, t, !1, i), bt(e.tableName, t, r?.kind, n, e.fields), e.appliedIndexes.some((e) => e.name === t)) throw Error(`duplicate index '${t}' on table '${e.tableName}': each index name must be unique within a table.`);
|
|
864
|
+
return V({
|
|
819
865
|
...e,
|
|
820
866
|
tableName: e.tableName,
|
|
821
867
|
fields: e.fields,
|
|
@@ -838,9 +884,9 @@ var A = () => new u({
|
|
|
838
884
|
}),
|
|
839
885
|
unique: ((...t) => {
|
|
840
886
|
let n, r, i, a = Array.isArray(t[0]);
|
|
841
|
-
if (a ? (r = t[0], i = t[1], n =
|
|
842
|
-
if (
|
|
843
|
-
return
|
|
887
|
+
if (a ? (r = t[0], i = t[1], n = yt(e.tableName, r)) : (n = t[0], r = t[1], i = t[2]), r.length === 0) throw Error(`unique '${n}' on table '${e.tableName}' has no fields — a UNIQUE constraint must cover at least one column.`);
|
|
888
|
+
if (B(e.tableName, n, a, r), e.appliedUniques.some((e) => e.name === n)) throw Error(a ? `duplicate auto-named UNIQUE '${n}' on table '${e.tableName}' — you've called .unique(${JSON.stringify(r)}) twice. Pass an explicit name to the second one if both are intended (very rare).` : `duplicate UNIQUE '${n}' on table '${e.tableName}': each constraint name must be unique within a table.`);
|
|
889
|
+
return V({
|
|
844
890
|
...e,
|
|
845
891
|
tableName: e.tableName,
|
|
846
892
|
fields: e.fields,
|
|
@@ -861,10 +907,10 @@ var A = () => new u({
|
|
|
861
907
|
}),
|
|
862
908
|
uniqueActive: ((...t) => {
|
|
863
909
|
let n, r, i, a = Array.isArray(t[0]);
|
|
864
|
-
if (a ? (r = t[0], i = t[1], n =
|
|
865
|
-
if (
|
|
910
|
+
if (a ? (r = t[0], i = t[1], n = vt(e.tableName, r)) : (n = t[0], r = t[1], i = t[2]), r.length === 0) throw Error(`uniqueActive '${n}' on table '${e.tableName}' has no fields — a partial UNIQUE must cover at least one column.`);
|
|
911
|
+
if (B(e.tableName, n, a, r), e.appliedIndexes.some((e) => e.name === n)) throw Error(`duplicate index '${n}' on table '${e.tableName}': each index name must be unique within a table (uniqueActive shares the index namespace).`);
|
|
866
912
|
let o = i?.where ?? "\"deletedAt\" IS NULL";
|
|
867
|
-
return
|
|
913
|
+
return V({
|
|
868
914
|
...e,
|
|
869
915
|
tableName: e.tableName,
|
|
870
916
|
fields: e.fields,
|
|
@@ -886,8 +932,8 @@ var A = () => new u({
|
|
|
886
932
|
}),
|
|
887
933
|
check: ((t, n) => {
|
|
888
934
|
if (n.trim().length === 0) throw Error(`CHECK '${t}' on table '${e.tableName}' has an empty expression.`);
|
|
889
|
-
if (
|
|
890
|
-
return
|
|
935
|
+
if (B(e.tableName, t, !1, []), e.appliedChecks.some((e) => e.name === t)) throw Error(`duplicate CHECK '${t}' on table '${e.tableName}': each constraint name must be unique within a table.`);
|
|
936
|
+
return V({
|
|
891
937
|
...e,
|
|
892
938
|
tableName: e.tableName,
|
|
893
939
|
fields: e.fields,
|
|
@@ -909,7 +955,7 @@ var A = () => new u({
|
|
|
909
955
|
if (t.trim().length === 0) throw Error(`rule on table '${e.tableName}' has an empty name.`);
|
|
910
956
|
let i = e.appliedRules ?? [];
|
|
911
957
|
if (i.some((e) => e.name === t)) throw Error(`duplicate rule '${t}' on table '${e.tableName}': each rule name must be unique within a table.`);
|
|
912
|
-
return
|
|
958
|
+
return V({
|
|
913
959
|
...e,
|
|
914
960
|
appliedRules: [...i, {
|
|
915
961
|
name: t,
|
|
@@ -920,7 +966,7 @@ var A = () => new u({
|
|
|
920
966
|
}),
|
|
921
967
|
renamedFrom: ((t) => {
|
|
922
968
|
if (t === e.tableName) throw Error(`renamedFrom('${t}') on table '${e.tableName}' names the table itself — drop the marker, there is nothing to rename.`);
|
|
923
|
-
return
|
|
969
|
+
return We(t), V({
|
|
924
970
|
...e,
|
|
925
971
|
previousTableName: t
|
|
926
972
|
});
|
|
@@ -935,7 +981,7 @@ var A = () => new u({
|
|
|
935
981
|
}
|
|
936
982
|
if (t.length > 0) throw Error(`primaryKey([...]) declared twice on table '${e.tableName}'.`);
|
|
937
983
|
for (let [t, r] of Object.entries(e.fields)) if (r.type === "id" && !n.includes(t)) throw Error(`primaryKey([...]) on table '${e.tableName}' conflicts with the id() column '${t}'. The explicit primary key IS the key — drop the id() column, or include '${t}' in the composite key.`);
|
|
938
|
-
return
|
|
984
|
+
return V({
|
|
939
985
|
...e,
|
|
940
986
|
tableName: e.tableName,
|
|
941
987
|
fields: e.fields,
|
|
@@ -950,7 +996,7 @@ var A = () => new u({
|
|
|
950
996
|
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
951
997
|
});
|
|
952
998
|
}),
|
|
953
|
-
nonReactive: (() =>
|
|
999
|
+
nonReactive: (() => V({
|
|
954
1000
|
...e,
|
|
955
1001
|
tableName: e.tableName,
|
|
956
1002
|
fields: e.fields,
|
|
@@ -964,7 +1010,7 @@ var A = () => new u({
|
|
|
964
1010
|
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
965
1011
|
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
966
1012
|
})),
|
|
967
|
-
validate: ((t) =>
|
|
1013
|
+
validate: ((t) => V({
|
|
968
1014
|
...e,
|
|
969
1015
|
tableName: e.tableName,
|
|
970
1016
|
fields: e.fields,
|
|
@@ -978,7 +1024,7 @@ var A = () => new u({
|
|
|
978
1024
|
insertSchema: t,
|
|
979
1025
|
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
980
1026
|
})),
|
|
981
|
-
validatePatch: ((t) =>
|
|
1027
|
+
validatePatch: ((t) => V({
|
|
982
1028
|
...e,
|
|
983
1029
|
tableName: e.tableName,
|
|
984
1030
|
fields: e.fields,
|
|
@@ -990,28 +1036,21 @@ var A = () => new u({
|
|
|
990
1036
|
appliedChecks: e.appliedChecks,
|
|
991
1037
|
appliedPrimaryKey: e.appliedPrimaryKey,
|
|
992
1038
|
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
993
|
-
validatePatchSchema: r.
|
|
1039
|
+
validatePatchSchema: t.mapFields(i.map(r.optional))
|
|
994
1040
|
}))
|
|
995
1041
|
};
|
|
996
|
-
},
|
|
997
|
-
|
|
998
|
-
let n =
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
}), r = yt(se(t), e);
|
|
1005
|
-
for (let t of Object.keys(r)) Ue(e, t);
|
|
1006
|
-
let i;
|
|
1007
|
-
for (let [t, n] of Object.entries(r)) n.references === O && (n.references = () => {
|
|
1008
|
-
if (i === void 0) throw Error(`selfReference() on '${e}.${t}' read before table() returned`);
|
|
1009
|
-
return i;
|
|
1042
|
+
}, H = (e, t) => {
|
|
1043
|
+
We(e);
|
|
1044
|
+
let n = xt(oe(t), e);
|
|
1045
|
+
for (let t of Object.keys(n)) Ge(e, t);
|
|
1046
|
+
let r;
|
|
1047
|
+
for (let [t, i] of Object.entries(n)) i.references === j && (i.references = () => {
|
|
1048
|
+
if (r === void 0) throw Error(`selfReference() on '${e}.${t}' read before table() returned`);
|
|
1049
|
+
return r;
|
|
1010
1050
|
});
|
|
1011
|
-
return
|
|
1012
|
-
appliedPluginRefs: n,
|
|
1051
|
+
return r = V({
|
|
1013
1052
|
tableName: e,
|
|
1014
|
-
fields:
|
|
1053
|
+
fields: n,
|
|
1015
1054
|
isReactive: !0,
|
|
1016
1055
|
appliedMixins: [],
|
|
1017
1056
|
appliedIndexes: [],
|
|
@@ -1019,8 +1058,8 @@ var A = () => new u({
|
|
|
1019
1058
|
appliedFullText: [],
|
|
1020
1059
|
appliedChecks: [],
|
|
1021
1060
|
appliedRules: []
|
|
1022
|
-
}),
|
|
1023
|
-
},
|
|
1061
|
+
}), r;
|
|
1062
|
+
}, Ct = (e) => e === "sqlite" || e === "turso", wt = (e) => e === "mysql" || e === "mariadb", Tt = (e, t) => {
|
|
1024
1063
|
switch (t) {
|
|
1025
1064
|
case "mysql":
|
|
1026
1065
|
case "mariadb": return `\`${e.replace(/`/g, "``")}\``;
|
|
@@ -1029,51 +1068,51 @@ var A = () => new u({
|
|
|
1029
1068
|
case "sqlite":
|
|
1030
1069
|
case "turso": return `"${e.replace(/"/g, "\"\"")}"`;
|
|
1031
1070
|
}
|
|
1032
|
-
},
|
|
1033
|
-
let t =
|
|
1071
|
+
}, Et = 1e4, Dt = Symbol.for("@voltro/database/tableRegistry"), Ot = globalThis, U = Ot[Dt] ?? (Ot[Dt] = /* @__PURE__ */ new Map()), kt = (e) => {
|
|
1072
|
+
let t = U.get(e.tableName);
|
|
1034
1073
|
if (t === void 0) {
|
|
1035
|
-
|
|
1074
|
+
U.set(e.tableName, e);
|
|
1036
1075
|
return;
|
|
1037
1076
|
}
|
|
1038
1077
|
if (t !== e) throw Error(`duplicate table '${e.tableName}' registration: two different table descriptors claim the same name. Rename one or import the shared module that defines it.`);
|
|
1039
|
-
},
|
|
1040
|
-
|
|
1041
|
-
},
|
|
1042
|
-
let t =
|
|
1078
|
+
}, At = (e) => {
|
|
1079
|
+
U.get(e.tableName) === void 0 && U.set(e.tableName, e);
|
|
1080
|
+
}, W = (e) => U.get(e), jt = (e) => {
|
|
1081
|
+
let t = U.get(e);
|
|
1043
1082
|
if (t === void 0) throw Error(`table '${e}' is not registered. Register it by wrapping it in \`databaseHandle({ ... })\` (the usual path) or call \`registerTable(t)\` explicitly before this runs. Note a \`queryFor(t)\` query carries its own source table, so eager-loads don't hit this — this error means a reconstructed descriptor or by-name tooling reached an unregistered table.`);
|
|
1044
1083
|
return t;
|
|
1045
|
-
},
|
|
1046
|
-
|
|
1047
|
-
},
|
|
1084
|
+
}, Mt = () => [...U.values()], Nt = (e) => U.delete(e), Pt = () => {
|
|
1085
|
+
U.clear();
|
|
1086
|
+
}, Ft = (e) => U.get(e)?.isReactive !== !1, It = (e) => e.order ?? [], Lt = (e) => ({
|
|
1048
1087
|
op: "count",
|
|
1049
1088
|
alias: e ?? "count"
|
|
1050
|
-
}),
|
|
1089
|
+
}), Rt = (e, t) => ({
|
|
1051
1090
|
op: "count-distinct",
|
|
1052
1091
|
column: e,
|
|
1053
1092
|
alias: t ?? `count_distinct_${e}`
|
|
1054
|
-
}),
|
|
1093
|
+
}), zt = (e, t) => ({
|
|
1055
1094
|
op: "sum",
|
|
1056
1095
|
column: e,
|
|
1057
1096
|
alias: t ?? `sum_${e}`
|
|
1058
|
-
}),
|
|
1097
|
+
}), Bt = (e, t) => ({
|
|
1059
1098
|
op: "avg",
|
|
1060
1099
|
column: e,
|
|
1061
1100
|
alias: t ?? `avg_${e}`
|
|
1062
|
-
}),
|
|
1101
|
+
}), Vt = (e, t) => ({
|
|
1063
1102
|
op: "min",
|
|
1064
1103
|
column: e,
|
|
1065
1104
|
alias: t ?? `min_${e}`
|
|
1066
|
-
}),
|
|
1105
|
+
}), Ht = (e, t) => ({
|
|
1067
1106
|
op: "max",
|
|
1068
1107
|
column: e,
|
|
1069
1108
|
alias: t ?? `max_${e}`
|
|
1070
|
-
}),
|
|
1109
|
+
}), Ut = (e, t) => ({
|
|
1071
1110
|
op: "column",
|
|
1072
1111
|
column: e,
|
|
1073
1112
|
alias: t ?? e
|
|
1074
|
-
}),
|
|
1113
|
+
}), Wt = (e) => (...t) => {
|
|
1075
1114
|
if (t.length < 2) throw Error(`${e}: requires at least two queries`);
|
|
1076
|
-
return
|
|
1115
|
+
return K({
|
|
1077
1116
|
table: t[0].descriptor.table,
|
|
1078
1117
|
predicate: void 0,
|
|
1079
1118
|
order: [],
|
|
@@ -1085,55 +1124,55 @@ var A = () => new u({
|
|
|
1085
1124
|
queries: t.map((e) => e.descriptor)
|
|
1086
1125
|
}
|
|
1087
1126
|
});
|
|
1088
|
-
},
|
|
1127
|
+
}, Gt = Wt("union"), Kt = Wt("union-all"), qt = Wt("intersect"), Jt = Wt("except"), G = (e) => ({ over: (t) => ({
|
|
1089
1128
|
...e,
|
|
1090
1129
|
window: t
|
|
1091
|
-
}) }),
|
|
1130
|
+
}) }), Yt = (e = "rowNumber") => G({
|
|
1092
1131
|
op: "window-row-number",
|
|
1093
1132
|
alias: e
|
|
1094
|
-
}),
|
|
1133
|
+
}), Xt = (e = "rank") => G({
|
|
1095
1134
|
op: "window-rank",
|
|
1096
1135
|
alias: e
|
|
1097
|
-
}),
|
|
1136
|
+
}), Zt = (e = "denseRank") => G({
|
|
1098
1137
|
op: "window-dense-rank",
|
|
1099
1138
|
alias: e
|
|
1100
|
-
}),
|
|
1139
|
+
}), Qt = (e, t = 1, n) => G({
|
|
1101
1140
|
op: "window-lag",
|
|
1102
1141
|
column: e,
|
|
1103
1142
|
alias: n ?? `lag_${e}`,
|
|
1104
1143
|
offset: t
|
|
1105
|
-
}),
|
|
1144
|
+
}), $t = (e, t = 1, n) => G({
|
|
1106
1145
|
op: "window-lead",
|
|
1107
1146
|
column: e,
|
|
1108
1147
|
alias: n ?? `lead_${e}`,
|
|
1109
1148
|
offset: t
|
|
1110
|
-
}),
|
|
1149
|
+
}), en = (e, t) => G({
|
|
1111
1150
|
op: "window-sum-over",
|
|
1112
1151
|
column: e,
|
|
1113
1152
|
alias: t ?? `sum_${e}_over`
|
|
1114
|
-
}),
|
|
1153
|
+
}), tn = (e, t) => G({
|
|
1115
1154
|
op: "window-avg-over",
|
|
1116
1155
|
column: e,
|
|
1117
1156
|
alias: t ?? `avg_${e}_over`
|
|
1118
|
-
}),
|
|
1119
|
-
let r = n?.find((e) => e.name === t) ??
|
|
1157
|
+
}), nn = (e, t, n) => {
|
|
1158
|
+
let r = n?.find((e) => e.name === t) ?? W(e)?.appliedFullText?.find((e) => e.name === t);
|
|
1120
1159
|
if (r === void 0) throw Error(`.matching('${t}', ...): no full-text index named '${t}' is declared on table '${e}'. Declare it with \`table(...).fullTextIndex('${t}', [columns])\` first.`);
|
|
1121
1160
|
return {
|
|
1122
1161
|
columns: r.columns,
|
|
1123
1162
|
...r.config === void 0 ? {} : { config: r.config },
|
|
1124
1163
|
...r.weights === void 0 ? {} : { weights: r.weights }
|
|
1125
1164
|
};
|
|
1126
|
-
},
|
|
1165
|
+
}, K = (e) => ({
|
|
1127
1166
|
descriptor: e,
|
|
1128
1167
|
where(t) {
|
|
1129
1168
|
let n = e.predicate ? { and: [e.predicate, t] } : t;
|
|
1130
|
-
return
|
|
1169
|
+
return K({
|
|
1131
1170
|
...e,
|
|
1132
1171
|
predicate: n
|
|
1133
1172
|
});
|
|
1134
1173
|
},
|
|
1135
1174
|
orderBy(t, n = "asc") {
|
|
1136
|
-
return
|
|
1175
|
+
return K({
|
|
1137
1176
|
...e,
|
|
1138
1177
|
order: [...e.order, {
|
|
1139
1178
|
column: t,
|
|
@@ -1142,43 +1181,43 @@ var A = () => new u({
|
|
|
1142
1181
|
});
|
|
1143
1182
|
},
|
|
1144
1183
|
limit(t) {
|
|
1145
|
-
return
|
|
1184
|
+
return K({
|
|
1146
1185
|
...e,
|
|
1147
1186
|
take: t
|
|
1148
1187
|
});
|
|
1149
1188
|
},
|
|
1150
1189
|
offset(t) {
|
|
1151
|
-
return
|
|
1190
|
+
return K({
|
|
1152
1191
|
...e,
|
|
1153
1192
|
skip: t
|
|
1154
1193
|
});
|
|
1155
1194
|
},
|
|
1156
1195
|
select(...t) {
|
|
1157
|
-
return
|
|
1196
|
+
return K({
|
|
1158
1197
|
...e,
|
|
1159
1198
|
projection: t
|
|
1160
1199
|
});
|
|
1161
1200
|
},
|
|
1162
1201
|
using(t) {
|
|
1163
|
-
return
|
|
1202
|
+
return K({
|
|
1164
1203
|
...e,
|
|
1165
1204
|
usingIndex: t
|
|
1166
1205
|
});
|
|
1167
1206
|
},
|
|
1168
1207
|
withDeleted() {
|
|
1169
|
-
return
|
|
1208
|
+
return K({
|
|
1170
1209
|
...e,
|
|
1171
1210
|
includeDeleted: !0
|
|
1172
1211
|
});
|
|
1173
1212
|
},
|
|
1174
1213
|
forUpdate() {
|
|
1175
|
-
return
|
|
1214
|
+
return K({
|
|
1176
1215
|
...e,
|
|
1177
1216
|
lock: "update"
|
|
1178
1217
|
});
|
|
1179
1218
|
},
|
|
1180
1219
|
unscoped() {
|
|
1181
|
-
return
|
|
1220
|
+
return K({
|
|
1182
1221
|
...e,
|
|
1183
1222
|
crossTenant: !0
|
|
1184
1223
|
});
|
|
@@ -1188,13 +1227,13 @@ var A = () => new u({
|
|
|
1188
1227
|
...e.eager ?? {},
|
|
1189
1228
|
...t
|
|
1190
1229
|
};
|
|
1191
|
-
return
|
|
1230
|
+
return K({
|
|
1192
1231
|
...e,
|
|
1193
1232
|
eager: n
|
|
1194
1233
|
});
|
|
1195
1234
|
},
|
|
1196
1235
|
count() {
|
|
1197
|
-
return
|
|
1236
|
+
return K({
|
|
1198
1237
|
...e,
|
|
1199
1238
|
projection: void 0,
|
|
1200
1239
|
aggregations: [{
|
|
@@ -1208,15 +1247,15 @@ var A = () => new u({
|
|
|
1208
1247
|
...t,
|
|
1209
1248
|
alias: e
|
|
1210
1249
|
}));
|
|
1211
|
-
return
|
|
1250
|
+
return K({
|
|
1212
1251
|
...e,
|
|
1213
1252
|
projection: void 0,
|
|
1214
1253
|
aggregations: n
|
|
1215
1254
|
});
|
|
1216
1255
|
},
|
|
1217
1256
|
matching(t, n, r) {
|
|
1218
|
-
let i =
|
|
1219
|
-
return
|
|
1257
|
+
let i = nn(e.table, t, e.fullTextIndexes);
|
|
1258
|
+
return K({
|
|
1220
1259
|
...e,
|
|
1221
1260
|
fullTextSearch: {
|
|
1222
1261
|
indexName: t,
|
|
@@ -1231,7 +1270,7 @@ var A = () => new u({
|
|
|
1231
1270
|
rankBy(t) {
|
|
1232
1271
|
let n = e.fullTextSearch;
|
|
1233
1272
|
if (n === void 0) throw Error(".rankBy() requires a preceding .matching(...) clause — there is no full-text search to rank on this query.");
|
|
1234
|
-
return
|
|
1273
|
+
return K({
|
|
1235
1274
|
...e,
|
|
1236
1275
|
fullTextSearch: {
|
|
1237
1276
|
...n,
|
|
@@ -1250,7 +1289,7 @@ var A = () => new u({
|
|
|
1250
1289
|
distance: r?.distance ?? "cosine",
|
|
1251
1290
|
...e.annClause?.ef === void 0 ? {} : { ef: e.annClause.ef }
|
|
1252
1291
|
};
|
|
1253
|
-
return
|
|
1292
|
+
return K({
|
|
1254
1293
|
...e,
|
|
1255
1294
|
annClause: i
|
|
1256
1295
|
});
|
|
@@ -1262,7 +1301,7 @@ var A = () => new u({
|
|
|
1262
1301
|
distance: "cosine",
|
|
1263
1302
|
...e.annClause?.ef === void 0 ? {} : { ef: e.annClause.ef }
|
|
1264
1303
|
};
|
|
1265
|
-
return
|
|
1304
|
+
return K({
|
|
1266
1305
|
...e,
|
|
1267
1306
|
annClause: r,
|
|
1268
1307
|
take: n
|
|
@@ -1275,7 +1314,7 @@ var A = () => new u({
|
|
|
1275
1314
|
column: "",
|
|
1276
1315
|
distance: "cosine"
|
|
1277
1316
|
};
|
|
1278
|
-
return
|
|
1317
|
+
return K({
|
|
1279
1318
|
...e,
|
|
1280
1319
|
annClause: {
|
|
1281
1320
|
...n,
|
|
@@ -1284,22 +1323,22 @@ var A = () => new u({
|
|
|
1284
1323
|
});
|
|
1285
1324
|
},
|
|
1286
1325
|
use(t) {
|
|
1287
|
-
return
|
|
1326
|
+
return K({ ...t(e) });
|
|
1288
1327
|
},
|
|
1289
1328
|
distinct() {
|
|
1290
|
-
return
|
|
1329
|
+
return K({
|
|
1291
1330
|
...e,
|
|
1292
1331
|
distinct: !0
|
|
1293
1332
|
});
|
|
1294
1333
|
},
|
|
1295
1334
|
distinctOn(t) {
|
|
1296
|
-
return
|
|
1335
|
+
return K({
|
|
1297
1336
|
...e,
|
|
1298
1337
|
distinctOn: [...t]
|
|
1299
1338
|
});
|
|
1300
1339
|
},
|
|
1301
1340
|
as(t) {
|
|
1302
|
-
return
|
|
1341
|
+
return K({
|
|
1303
1342
|
...e,
|
|
1304
1343
|
alias: t
|
|
1305
1344
|
});
|
|
@@ -1312,7 +1351,7 @@ var A = () => new u({
|
|
|
1312
1351
|
on: r,
|
|
1313
1352
|
...typeof t == "string" ? {} : { sourceTable: t }
|
|
1314
1353
|
}];
|
|
1315
|
-
return
|
|
1354
|
+
return K({
|
|
1316
1355
|
...e,
|
|
1317
1356
|
joins: a
|
|
1318
1357
|
});
|
|
@@ -1325,7 +1364,7 @@ var A = () => new u({
|
|
|
1325
1364
|
on: r,
|
|
1326
1365
|
...typeof t == "string" ? {} : { sourceTable: t }
|
|
1327
1366
|
}];
|
|
1328
|
-
return
|
|
1367
|
+
return K({
|
|
1329
1368
|
...e,
|
|
1330
1369
|
joins: a
|
|
1331
1370
|
});
|
|
@@ -1335,7 +1374,7 @@ var A = () => new u({
|
|
|
1335
1374
|
outputKey: e,
|
|
1336
1375
|
source: t
|
|
1337
1376
|
}));
|
|
1338
|
-
return
|
|
1377
|
+
return K({
|
|
1339
1378
|
...e,
|
|
1340
1379
|
projection: void 0,
|
|
1341
1380
|
joinedProjection: n
|
|
@@ -1344,7 +1383,7 @@ var A = () => new u({
|
|
|
1344
1383
|
withCte(t, n) {
|
|
1345
1384
|
let r = e.ctes ?? [];
|
|
1346
1385
|
if (r.some((e) => e.name === t)) throw Error(`Query.withCte: duplicate CTE name '${t}'`);
|
|
1347
|
-
return
|
|
1386
|
+
return K({
|
|
1348
1387
|
...e,
|
|
1349
1388
|
ctes: [...r, {
|
|
1350
1389
|
name: t,
|
|
@@ -1355,7 +1394,7 @@ var A = () => new u({
|
|
|
1355
1394
|
recursiveCte(t, n) {
|
|
1356
1395
|
let r = e.ctes ?? [];
|
|
1357
1396
|
if (r.some((e) => e.name === t)) throw Error(`Query.recursiveCte: duplicate CTE name '${t}'`);
|
|
1358
|
-
return
|
|
1397
|
+
return K({
|
|
1359
1398
|
...e,
|
|
1360
1399
|
ctes: [...r, {
|
|
1361
1400
|
name: t,
|
|
@@ -1366,20 +1405,20 @@ var A = () => new u({
|
|
|
1366
1405
|
},
|
|
1367
1406
|
groupBy(t) {
|
|
1368
1407
|
let n = e.groupBy ? [...e.groupBy, ...t] : [...t];
|
|
1369
|
-
return
|
|
1408
|
+
return K({
|
|
1370
1409
|
...e,
|
|
1371
1410
|
groupBy: n
|
|
1372
1411
|
});
|
|
1373
1412
|
},
|
|
1374
1413
|
having(t) {
|
|
1375
1414
|
let n = e.having ? { and: [e.having, t] } : t;
|
|
1376
|
-
return
|
|
1415
|
+
return K({
|
|
1377
1416
|
...e,
|
|
1378
1417
|
having: n
|
|
1379
1418
|
});
|
|
1380
1419
|
},
|
|
1381
1420
|
exists() {
|
|
1382
|
-
return
|
|
1421
|
+
return K({
|
|
1383
1422
|
...e,
|
|
1384
1423
|
projection: void 0,
|
|
1385
1424
|
aggregations: [{
|
|
@@ -1390,8 +1429,8 @@ var A = () => new u({
|
|
|
1390
1429
|
});
|
|
1391
1430
|
}
|
|
1392
1431
|
});
|
|
1393
|
-
function
|
|
1394
|
-
return
|
|
1432
|
+
function rn(e) {
|
|
1433
|
+
return K({
|
|
1395
1434
|
table: e.tableName,
|
|
1396
1435
|
predicate: void 0,
|
|
1397
1436
|
order: [],
|
|
@@ -1402,7 +1441,7 @@ function en(e) {
|
|
|
1402
1441
|
sourceTable: e
|
|
1403
1442
|
});
|
|
1404
1443
|
}
|
|
1405
|
-
var
|
|
1444
|
+
var an = (e, t, n) => on(e, "id", t, n), on = (e, t, n, r, i = "asc") => {
|
|
1406
1445
|
let a = [...e.order.filter((e) => e.column !== t), {
|
|
1407
1446
|
column: t,
|
|
1408
1447
|
direction: i
|
|
@@ -1417,21 +1456,21 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
1417
1456
|
order: a,
|
|
1418
1457
|
take: r
|
|
1419
1458
|
};
|
|
1420
|
-
},
|
|
1459
|
+
}, sn = (e) => {
|
|
1421
1460
|
let t = {};
|
|
1422
|
-
for (let [n, r] of Object.entries(e))
|
|
1461
|
+
for (let [n, r] of Object.entries(e)) kt(r), t[n] = rn(r);
|
|
1423
1462
|
return t;
|
|
1424
|
-
},
|
|
1425
|
-
if (
|
|
1426
|
-
let r =
|
|
1427
|
-
for (let t of Object.keys(r))
|
|
1463
|
+
}, cn = (e) => e.isView === !0, ln = (e, t, n) => {
|
|
1464
|
+
if (We(e), n.trim().length === 0) throw Error(`view('${e}', …): the SELECT body is empty — a view must define a query.`);
|
|
1465
|
+
let r = oe(t);
|
|
1466
|
+
for (let t of Object.keys(r)) Ge(e, t);
|
|
1428
1467
|
return {
|
|
1429
1468
|
tableName: e,
|
|
1430
1469
|
fields: r,
|
|
1431
1470
|
isView: !0,
|
|
1432
1471
|
viewSelect: n
|
|
1433
1472
|
};
|
|
1434
|
-
},
|
|
1473
|
+
}, un = (e) => rn({
|
|
1435
1474
|
...e,
|
|
1436
1475
|
isReactive: !1,
|
|
1437
1476
|
appliedMixins: [],
|
|
@@ -1439,8 +1478,8 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
1439
1478
|
appliedUniques: [],
|
|
1440
1479
|
appliedFullText: [],
|
|
1441
1480
|
appliedChecks: []
|
|
1442
|
-
}),
|
|
1443
|
-
let r = n === null ?
|
|
1481
|
+
}), dn = (e, t, n = null) => {
|
|
1482
|
+
let r = n === null ? Tt(e.tableName, t) : `${Tt(n, t)}.${Tt(e.tableName, t)}`, i = e.viewSelect.trim();
|
|
1444
1483
|
switch (t) {
|
|
1445
1484
|
case "postgres":
|
|
1446
1485
|
case "mysql":
|
|
@@ -1449,64 +1488,114 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
1449
1488
|
case "sqlite":
|
|
1450
1489
|
case "turso": return `DROP VIEW IF EXISTS ${r};\nCREATE VIEW ${r} AS ${i};`;
|
|
1451
1490
|
}
|
|
1452
|
-
},
|
|
1491
|
+
}, fn = ({ precision: e, scale: t }) => {
|
|
1453
1492
|
if (!Number.isSafeInteger(e) || e <= 0 || !Number.isSafeInteger(t) || t < 0 || t > e) throw RangeError("Invalid fixed-point decimal precision or scale");
|
|
1454
1493
|
return 10n ** BigInt(e);
|
|
1455
|
-
},
|
|
1456
|
-
let n =
|
|
1494
|
+
}, q = (e, t) => {
|
|
1495
|
+
let n = fn(t);
|
|
1457
1496
|
if (typeof e != "string" || !/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/.test(e)) throw TypeError("Expected a fixed-point decimal string");
|
|
1458
1497
|
let [r = "", i = ""] = e.replace(/^[+-]/, "").split(".");
|
|
1459
1498
|
if (/[1-9]/.test(i.slice(t.scale))) throw RangeError("Decimal value exceeds the declared scale");
|
|
1460
1499
|
let a = BigInt((r || "0") + i.slice(0, t.scale).padEnd(t.scale, "0"));
|
|
1461
1500
|
if (a >= n) throw RangeError("Decimal value exceeds the declared precision");
|
|
1462
1501
|
return "D" + ((e.startsWith("-") ? -a : a) + n).toString().padStart(t.precision + 1, "0");
|
|
1463
|
-
},
|
|
1464
|
-
let n =
|
|
1502
|
+
}, pn = (e, t) => {
|
|
1503
|
+
let n = fn(t);
|
|
1465
1504
|
if (typeof e != "string" || e.length !== t.precision + 2 || !/^D\d+$/.test(e)) throw TypeError("Expected an encoded fixed-point decimal value");
|
|
1466
1505
|
let r = BigInt(e.slice(1)) - n;
|
|
1467
1506
|
if (r <= -n || r >= n) throw RangeError("Encoded decimal value exceeds the declared precision");
|
|
1468
1507
|
let i = (r < 0n ? -r : r).toString().padStart(t.scale + 1, "0"), a = t.scale === 0 ? i : i.slice(0, -t.scale) + "." + i.slice(-t.scale);
|
|
1469
1508
|
return (r < 0n ? "-" : "") + a;
|
|
1470
|
-
},
|
|
1509
|
+
}, J = (e) => e?.type === "decimal" && mn(e) !== void 0, mn = (e) => {
|
|
1471
1510
|
if (e.sqliteDecimalEncoding === void 0) return;
|
|
1472
1511
|
if (e.precision === void 0 || e.scale === void 0) throw Error("Encoded SQLite decimal metadata requires precision and scale");
|
|
1473
1512
|
let t = {
|
|
1474
1513
|
precision: e.precision,
|
|
1475
1514
|
scale: e.scale
|
|
1476
1515
|
};
|
|
1477
|
-
return
|
|
1478
|
-
},
|
|
1516
|
+
return q("0", t), t;
|
|
1517
|
+
}, hn = (e) => (q("0", e), `VOLTRO_DECIMAL_V1_P${e.precision}_S${e.scale}_TEXT`), gn = (e) => {
|
|
1479
1518
|
let t = /^\s*VOLTRO_DECIMAL_V1_P(\d+)_S(\d+)_TEXT\s*$/i.exec(e);
|
|
1480
1519
|
if (!t) return;
|
|
1481
1520
|
let n = {
|
|
1482
1521
|
precision: Number(t[1]),
|
|
1483
1522
|
scale: Number(t[2])
|
|
1484
1523
|
};
|
|
1485
|
-
return
|
|
1486
|
-
},
|
|
1487
|
-
|
|
1524
|
+
return q("0", n), n;
|
|
1525
|
+
}, _n = (e, t) => {
|
|
1526
|
+
q("0", t);
|
|
1488
1527
|
let n = "D" + "0".repeat(t.precision + 1), r = "D2" + "0".repeat(t.precision);
|
|
1489
1528
|
return `(${e} IS NULL OR (typeof(${e}) = 'text' AND length(${e}) = ${t.precision + 2} AND substr(${e}, 1, 1) = 'D' AND substr(${e}, 2) NOT GLOB '*[^0-9]*' AND instr(${e}, char(0)) = 0 AND ${e} COLLATE BINARY > '${n}' AND ${e} COLLATE BINARY < '${r}'))`;
|
|
1490
|
-
},
|
|
1529
|
+
}, vn = (e, t) => {
|
|
1491
1530
|
if (e == null) return e;
|
|
1492
1531
|
if (typeof e != "string") throw TypeError("SQLite decimal defaults require exact strings");
|
|
1493
|
-
return
|
|
1494
|
-
},
|
|
1532
|
+
return q(e, t);
|
|
1533
|
+
}, Y = (e, t) => {
|
|
1495
1534
|
let n = e.lastIndexOf("."), r = n < 0 ? e : e.slice(n + 1), i = n < 0 ? void 0 : e.slice(0, n), a = i === void 0 || i === t.alias || i === t.table, o = a ? void 0 : t.joins?.find((e) => e.alias === i), s = a ? t.table : o?.table, c = a ? t.sourceTable : o?.sourceTable;
|
|
1496
|
-
return (c?.tableName === s ? c : s === void 0 ? void 0 :
|
|
1497
|
-
},
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1535
|
+
return (c?.tableName === s ? c : s === void 0 ? void 0 : W(s))?.fields[r];
|
|
1536
|
+
}, yn = (e) => {
|
|
1537
|
+
for (let t of [
|
|
1538
|
+
"joins",
|
|
1539
|
+
"alias",
|
|
1540
|
+
"table",
|
|
1541
|
+
"sourceTable"
|
|
1542
|
+
]) {
|
|
1543
|
+
let n = Object.getOwnPropertyDescriptor(e, t);
|
|
1544
|
+
if (n === void 0 ? t in e : !("value" in n)) return (t) => Y(t, e);
|
|
1545
|
+
}
|
|
1546
|
+
let t = e.joins;
|
|
1547
|
+
if (t === void 0 || t.length < 8 || Object.getPrototypeOf(t) !== Array.prototype || t.find !== Array.prototype.find || t[Symbol.iterator] !== Array.prototype[Symbol.iterator]) return (t) => Y(t, e);
|
|
1548
|
+
let n = /* @__PURE__ */ new Map();
|
|
1549
|
+
for (let r = 0; r < t.length; r++) {
|
|
1550
|
+
let i = Object.getOwnPropertyDescriptor(t, r);
|
|
1551
|
+
if (i === void 0 || !("value" in i)) return (t) => Y(t, e);
|
|
1552
|
+
let a = i.value;
|
|
1553
|
+
for (let t of ["table", "sourceTable"]) {
|
|
1554
|
+
let n = Object.getOwnPropertyDescriptor(a, t);
|
|
1555
|
+
if (n === void 0 ? t in a : !("value" in n)) return (t) => Y(t, e);
|
|
1556
|
+
}
|
|
1557
|
+
let o = Object.getOwnPropertyDescriptor(a, "alias");
|
|
1558
|
+
if (o === void 0 || !("value" in o) || typeof o.value != "string") return (t) => Y(t, e);
|
|
1559
|
+
n.has(o.value) || n.set(o.value, a);
|
|
1560
|
+
}
|
|
1561
|
+
return (t) => {
|
|
1562
|
+
let r = t.lastIndexOf("."), i = r < 0 ? t : t.slice(r + 1), a = r < 0 ? void 0 : t.slice(0, r), o = a === void 0 || a === e.alias || a === e.table, s = o ? void 0 : n.get(a), c = o ? e.table : s?.table, l = o ? e.sourceTable : s?.sourceTable;
|
|
1563
|
+
return (l?.tableName === c ? l : c === void 0 ? void 0 : W(c))?.fields[i];
|
|
1564
|
+
};
|
|
1565
|
+
}, bn = (e) => e.replace(/[A-Z]/g, (e) => e.toLowerCase()), xn = (e) => {
|
|
1566
|
+
if (Object.getPrototypeOf(e) !== Object.prototype) return !1;
|
|
1567
|
+
for (let t of Object.values(Object.getOwnPropertyDescriptors(e))) {
|
|
1568
|
+
if (!("value" in t) || !t.value || Object.getPrototypeOf(t.value) !== Object.prototype) return !1;
|
|
1569
|
+
for (let e of [
|
|
1570
|
+
"type",
|
|
1571
|
+
"sqliteDecimalEncoding",
|
|
1572
|
+
"precision",
|
|
1573
|
+
"scale"
|
|
1574
|
+
]) {
|
|
1575
|
+
let n = Object.getOwnPropertyDescriptor(t.value, e);
|
|
1576
|
+
if (n && !("value" in n)) return !1;
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
return !0;
|
|
1580
|
+
}, Sn = (e) => {
|
|
1581
|
+
let t, n = !1, r, i = (e, t) => e ? "and" in e ? e.and.some((e) => i(e, t)) : "or" in e ? e.or.some((e) => i(e, t)) : "not" in e ? i(e.not, t) : "subquery" in e && a(e.subquery, t) : !1, a = (e, o) => {
|
|
1582
|
+
let s = /* @__PURE__ */ new Set([...o, ...(e.ctes ?? []).map((e) => bn(e.name))]), c = (e, i) => {
|
|
1583
|
+
if (s.has(bn(e))) return !1;
|
|
1584
|
+
let a = i?.tableName === e ? i : W(e);
|
|
1585
|
+
if (a === void 0) return !1;
|
|
1586
|
+
if (t === void 0) return t = a, n = Object.values(a.fields).some(J), n;
|
|
1587
|
+
r ??= /* @__PURE__ */ new Map([[t, { result: n }]]);
|
|
1588
|
+
let o = r.get(a);
|
|
1589
|
+
if (o !== void 0 && (o.ordinary ??= xn(a.fields), o.ordinary)) return o.result;
|
|
1590
|
+
let c = Object.values(a.fields).some(J);
|
|
1591
|
+
return o === void 0 && r.set(a, { result: c }), c;
|
|
1503
1592
|
};
|
|
1504
|
-
return
|
|
1593
|
+
return c(e.table, e.sourceTable) || (e.joins ?? []).some((e) => c(e.table, e.sourceTable) || i(e.on, s)) || (e.ctes ?? []).some((e) => a(e.descriptor, s)) || (e.setOp?.queries ?? []).some((e) => a(e, s)) || i(e.predicate, s) || i(e.having, s);
|
|
1505
1594
|
};
|
|
1506
|
-
return
|
|
1507
|
-
},
|
|
1595
|
+
return a(e, /* @__PURE__ */ new Set());
|
|
1596
|
+
}, X = (e, t) => {
|
|
1508
1597
|
if (e.setOp) {
|
|
1509
|
-
let n = e.setOp.queries.map((e) =>
|
|
1598
|
+
let n = e.setOp.queries.map((e) => X(e, t));
|
|
1510
1599
|
if (n.length < 2) throw Error("Exact set operations require at least two inputs");
|
|
1511
1600
|
let r = n[0];
|
|
1512
1601
|
if (n.some((e) => e.length !== r.length)) throw Error("Exact set operation column counts differ");
|
|
@@ -1526,8 +1615,8 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
1526
1615
|
}
|
|
1527
1616
|
let n = e.aggregations ?? [];
|
|
1528
1617
|
if (n.length) return n.map((n) => {
|
|
1529
|
-
let r =
|
|
1530
|
-
if (!
|
|
1618
|
+
let r = Y(n.column ?? "", e);
|
|
1619
|
+
if (!J(r) || n.op.startsWith("count") || [
|
|
1531
1620
|
"window-row-number",
|
|
1532
1621
|
"window-rank",
|
|
1533
1622
|
"window-dense-rank"
|
|
@@ -1537,7 +1626,7 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
1537
1626
|
"window-row-number",
|
|
1538
1627
|
"window-rank",
|
|
1539
1628
|
"window-dense-rank"
|
|
1540
|
-
].includes(n.op) ?
|
|
1629
|
+
].includes(n.op) ? _().__definition() : r ?? _().__definition()
|
|
1541
1630
|
};
|
|
1542
1631
|
let i = ["avg", "window-avg-over"].includes(n.op) ? t ?? r.scale : r.scale, a = [
|
|
1543
1632
|
"sum",
|
|
@@ -1553,25 +1642,25 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
1553
1642
|
}
|
|
1554
1643
|
};
|
|
1555
1644
|
});
|
|
1556
|
-
let r = e.sourceTable?.tableName === e.table ? e.sourceTable :
|
|
1645
|
+
let r = e.sourceTable?.tableName === e.table ? e.sourceTable : W(e.table), i = e.joinedProjection ?? (e.projection?.length ? e.projection : Object.keys(r?.fields ?? {})).map((e) => ({
|
|
1557
1646
|
source: e,
|
|
1558
1647
|
outputKey: e.split(".").at(-1)
|
|
1559
1648
|
}));
|
|
1560
1649
|
if (!i.length) throw Error("Exact set operation requires declared output columns");
|
|
1561
1650
|
return i.map((t) => {
|
|
1562
|
-
let n =
|
|
1651
|
+
let n = Y(t.source, e);
|
|
1563
1652
|
if (!n) throw Error("Exact set operation requires declared output columns");
|
|
1564
1653
|
return {
|
|
1565
1654
|
name: t.outputKey,
|
|
1566
1655
|
definition: n,
|
|
1567
|
-
...
|
|
1656
|
+
...J(n) ? { decimal: {
|
|
1568
1657
|
precision: n.precision,
|
|
1569
1658
|
scale: n.scale
|
|
1570
1659
|
} } : {}
|
|
1571
1660
|
};
|
|
1572
1661
|
});
|
|
1573
|
-
},
|
|
1574
|
-
|
|
1662
|
+
}, Cn = (e, t, n = [], r) => {
|
|
1663
|
+
q("0", t);
|
|
1575
1664
|
let i = /* @__PURE__ */ new Set([
|
|
1576
1665
|
"value",
|
|
1577
1666
|
"negative",
|
|
@@ -1597,13 +1686,13 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
1597
1686
|
d("input", `SELECT * FROM (${e}) LIMIT -1 OFFSET 0`), d("sign", `SELECT *,substr(value,1,1)='-' AS negative,CASE WHEN substr(value,1,1) IN ('-','+') THEN substr(value,2) ELSE value END AS unsigned FROM ${u("input")} LIMIT -1 OFFSET 0`), d("parts", `SELECT *,CASE WHEN instr(unsigned,'.')=0 THEN unsigned ELSE substr(unsigned,1,instr(unsigned,'.')-1) END AS integer_part,CASE WHEN instr(unsigned,'.')=0 THEN '' ELSE substr(unsigned,instr(unsigned,'.')+1) END AS fraction FROM ${u("sign")} LIMIT -1 OFFSET 0`), d("magnitude", `SELECT *,coalesce(nullif(ltrim(integer_part||substr(fraction||'${"0".repeat(t.scale)}',1,${t.scale}),'0'),''),'0') AS magnitude FROM ${u("parts")} LIMIT -1 OFFSET 0`), d("padded", `SELECT *,substr('${o}'||magnitude,-${t.precision}) AS padded FROM ${u("magnitude")} LIMIT -1 OFFSET 0`), d("trimmed", `SELECT *,rtrim(padded,'0') AS trimmed FROM ${u("padded")} LIMIT -1 OFFSET 0`), d("alphabetic", `SELECT *,${c} AS alphabetic FROM ${u("trimmed")} LIMIT -1 OFFSET 0`), d("complement", `SELECT *,${s} AS complement FROM ${u("alphabetic")} LIMIT -1 OFFSET 0`);
|
|
1598
1687
|
let f = `typeof(value)<>'text' OR instr(value,char(0))<>0 OR unsigned GLOB '*[^0-9.]*' OR instr(fraction,'.')<>0 OR length(integer_part)+length(fraction)=0 OR length(magnitude)>${t.precision} OR substr(fraction,${t.scale + 1}) GLOB '*[1-9]*'`;
|
|
1599
1688
|
return `(${r ? "" : `WITH ${l.join(",")} `}SELECT ${n.map((e) => `"${e}",`).join("")}CASE WHEN value IS NULL THEN NULL WHEN ${f} THEN abs(-9223372036854775808) WHEN negative AND magnitude<>'0' THEN 'D0'||complement||CAST(10-CAST(substr(trimmed,-1) AS INTEGER) AS TEXT)||substr(padded,length(trimmed)+1) ELSE 'D1'||padded END AS value FROM ${u("complement")})`;
|
|
1600
|
-
},
|
|
1689
|
+
}, Z = (e) => e.replace(/[A-Z]/g, (e) => e.toLowerCase()), wn = (e) => {
|
|
1601
1690
|
let t = /* @__PURE__ */ new Set(), n = (e) => {
|
|
1602
1691
|
"and" in e ? e.and.forEach(n) : "or" in e ? e.or.forEach(n) : "not" in e ? n(e.not) : "subquery" in e && r(e.subquery);
|
|
1603
1692
|
}, r = (e) => {
|
|
1604
|
-
t.add(
|
|
1605
|
-
for (let r of e.joins ?? []) t.add(
|
|
1606
|
-
for (let n of e.ctes ?? []) t.add(
|
|
1693
|
+
t.add(Z(e.table));
|
|
1694
|
+
for (let r of e.joins ?? []) t.add(Z(r.table)), n(r.on);
|
|
1695
|
+
for (let n of e.ctes ?? []) t.add(Z(n.name)), r(n.descriptor);
|
|
1607
1696
|
e.setOp?.queries.forEach(r), e.predicate && n(e.predicate), e.having && n(e.having);
|
|
1608
1697
|
};
|
|
1609
1698
|
r(e);
|
|
@@ -1615,40 +1704,40 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
1615
1704
|
while (t.has(e));
|
|
1616
1705
|
return t.add(e), e;
|
|
1617
1706
|
};
|
|
1618
|
-
},
|
|
1707
|
+
}, Tn = (e, t, n = () => void 0, r = wn(e)) => {
|
|
1619
1708
|
let i = /* @__PURE__ */ new Map();
|
|
1620
1709
|
for (let t of e.ctes ?? []) {
|
|
1621
|
-
let e =
|
|
1710
|
+
let e = Z(t.name);
|
|
1622
1711
|
if (i.has(e)) throw Error("Duplicate exact decimal CTE name");
|
|
1623
1712
|
i.set(e, t);
|
|
1624
1713
|
}
|
|
1625
1714
|
let a = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set(), s = [], c = (e) => {
|
|
1626
|
-
let l =
|
|
1715
|
+
let l = Z(e), u = i.get(l);
|
|
1627
1716
|
if (!u) return n(l);
|
|
1628
1717
|
let d = a.get(l);
|
|
1629
1718
|
if (d) return d;
|
|
1630
1719
|
if (u.recursive) throw Error("Recursive exact decimal CTE composition is not integrated yet");
|
|
1631
1720
|
if (o.has(l)) throw Error(`Circular exact decimal CTE dependency: ${u.name}`);
|
|
1632
1721
|
o.add(l);
|
|
1633
|
-
let f =
|
|
1634
|
-
if (new Set(
|
|
1635
|
-
let
|
|
1636
|
-
tableName:
|
|
1637
|
-
fields: Object.fromEntries(
|
|
1638
|
-
...
|
|
1722
|
+
let f = Tn(u.descriptor, t, c, r), p = X(f, t);
|
|
1723
|
+
if (new Set(p.map((e) => Z(e.name))).size !== p.length) throw Error("Duplicate exact decimal CTE output");
|
|
1724
|
+
let m = r(), h = {
|
|
1725
|
+
tableName: m,
|
|
1726
|
+
fields: Object.fromEntries(p.map((e) => [e.name, e.decimal ? {
|
|
1727
|
+
...y(e.decimal.precision, e.decimal.scale).__definition(),
|
|
1639
1728
|
sqliteDecimalEncoding: "sortable-v1"
|
|
1640
|
-
} : e.definition ??
|
|
1729
|
+
} : e.definition ?? g().__definition()]))
|
|
1641
1730
|
};
|
|
1642
|
-
return a.set(l,
|
|
1731
|
+
return a.set(l, h), o.delete(l), s.push({
|
|
1643
1732
|
...u,
|
|
1644
|
-
name:
|
|
1733
|
+
name: m,
|
|
1645
1734
|
descriptor: f
|
|
1646
|
-
}),
|
|
1735
|
+
}), h;
|
|
1647
1736
|
};
|
|
1648
1737
|
for (let e of i.keys()) c(e);
|
|
1649
1738
|
let l = (e) => "and" in e ? { and: e.and.map(l) } : "or" in e ? { or: e.or.map(l) } : "not" in e ? { not: l(e.not) } : "subquery" in e ? {
|
|
1650
1739
|
...e,
|
|
1651
|
-
subquery:
|
|
1740
|
+
subquery: Tn(e.subquery, t, c, r)
|
|
1652
1741
|
} : e, u = c(e.table), { ctes: d, ...f } = e;
|
|
1653
1742
|
return {
|
|
1654
1743
|
...f,
|
|
@@ -1673,10 +1762,10 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
1673
1762
|
...e.having ? { having: l(e.having) } : {},
|
|
1674
1763
|
...e.setOp ? { setOp: {
|
|
1675
1764
|
...e.setOp,
|
|
1676
|
-
queries: e.setOp.queries.map((e) =>
|
|
1765
|
+
queries: e.setOp.queries.map((e) => Tn(e, t, c, r))
|
|
1677
1766
|
} } : {}
|
|
1678
1767
|
};
|
|
1679
|
-
},
|
|
1768
|
+
}, En = (e, t) => {
|
|
1680
1769
|
let n = [], r = (e) => "and" in e ? { and: e.and.map(r) } : "or" in e ? { or: e.or.map(r) } : "not" in e ? { not: r(e.not) } : "subquery" in e ? {
|
|
1681
1770
|
...e,
|
|
1682
1771
|
subquery: i(e.subquery)
|
|
@@ -1702,49 +1791,49 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
1702
1791
|
queries: a.setOp.queries.map(i)
|
|
1703
1792
|
} } : {}
|
|
1704
1793
|
};
|
|
1705
|
-
}, a = i(
|
|
1794
|
+
}, a = i(Tn(e, t));
|
|
1706
1795
|
return n.length ? {
|
|
1707
1796
|
...a,
|
|
1708
1797
|
ctes: n
|
|
1709
1798
|
} : a;
|
|
1710
|
-
},
|
|
1799
|
+
}, Dn = (e, t, n, r) => {
|
|
1711
1800
|
let i = (e.ctes ?? []).flatMap((e, i) => {
|
|
1712
|
-
let a =
|
|
1713
|
-
for (;
|
|
1714
|
-
let
|
|
1801
|
+
let a = X(e.descriptor, n), [o] = r(e.descriptor).compile(), s = (e) => "\"" + e.replaceAll("\"", "\"\"") + "\"", c = `decimal_cte_${i}_`, l = Z(o + e.name);
|
|
1802
|
+
for (; l.includes(c);) c += "_";
|
|
1803
|
+
let u = a.map((e, t) => `${c}column_${t}`), d = [], f = /* @__PURE__ */ new Set(), [p, m] = r(e.descriptor, {
|
|
1715
1804
|
prefix: `${c}window_`,
|
|
1716
1805
|
append: (e, t) => {
|
|
1717
|
-
|
|
1806
|
+
d.push(`${e} AS MATERIALIZED (${t})`);
|
|
1718
1807
|
},
|
|
1719
1808
|
encodedOutput: (e) => {
|
|
1720
|
-
|
|
1809
|
+
f.add(e);
|
|
1721
1810
|
}
|
|
1722
1811
|
}).compile();
|
|
1723
|
-
|
|
1724
|
-
let
|
|
1725
|
-
|
|
1726
|
-
},
|
|
1727
|
-
|
|
1812
|
+
d.push(`${c}input AS (${p})`);
|
|
1813
|
+
let h = (e, t) => {
|
|
1814
|
+
d.push(`${e} AS (${t})`);
|
|
1815
|
+
}, g = `${c}columns`;
|
|
1816
|
+
h(g, `SELECT ${a.map((e, t) => `${s(e.name)} AS ${u[t]}`).join(",")} FROM ${c}input`);
|
|
1728
1817
|
for (let [e, t] of a.entries()) {
|
|
1729
|
-
if (!t.decimal ||
|
|
1730
|
-
let n =
|
|
1818
|
+
if (!t.decimal || f.has(t.name)) continue;
|
|
1819
|
+
let n = u.filter((t, n) => n !== e), r = Cn(`SELECT ${u[e]} AS value${n.map((e) => "," + e).join("")} FROM ${g}`, t.decimal, n, {
|
|
1731
1820
|
prefix: `${c}${e}_`,
|
|
1732
|
-
append:
|
|
1821
|
+
append: h
|
|
1733
1822
|
});
|
|
1734
|
-
|
|
1823
|
+
g = `${c}encoded_${e}`, h(g, `SELECT ${u.map((t, n) => n === e ? `value AS ${t}` : t).join(",")} FROM ${r}`);
|
|
1735
1824
|
}
|
|
1736
|
-
let
|
|
1737
|
-
return [t.unsafe(
|
|
1738
|
-
}), { ctes: a, ...o } = e, [s] = r(o).compile(), c = "decimal_cte_result_";
|
|
1739
|
-
for (;
|
|
1740
|
-
let
|
|
1825
|
+
let _ = a.map((e, t) => `${u[t]} AS ${s(e.name)}`).join(",");
|
|
1826
|
+
return [t.unsafe(d.join(","), m), t`${t(e.name)} AS (${t.unsafe(`SELECT ${_} FROM ${g}`)})`];
|
|
1827
|
+
}), { ctes: a, ...o } = e, [s] = r(o).compile(), c = "decimal_cte_result_", l = Z(s + i.map((e) => e.compile()[0]).join(""));
|
|
1828
|
+
for (; l.includes(c);) c += "_";
|
|
1829
|
+
let u = [], [d, f] = r(o, void 0, {
|
|
1741
1830
|
prefix: c,
|
|
1742
1831
|
append: (e, t) => {
|
|
1743
|
-
|
|
1832
|
+
u.push(`${e} AS MATERIALIZED (${t})`);
|
|
1744
1833
|
}
|
|
1745
|
-
}).compile(),
|
|
1746
|
-
return t.unsafe(...
|
|
1747
|
-
},
|
|
1834
|
+
}).compile(), p = u.length ? t`WITH ${t.join(", ", !1)([...i, t.unsafe(u.join(","), f)])} ${t.unsafe(d)}` : t`WITH ${t.join(", ", !1)(i)} SELECT * FROM (${t.unsafe(d, f)})`;
|
|
1835
|
+
return t.unsafe(...p.compile());
|
|
1836
|
+
}, On = (e) => e == null || typeof e == "boolean" ? e : typeof e == "number" ? e !== 0 : typeof e == "bigint" ? e !== 0n : typeof e == "string" ? e === "1" || e.toLowerCase() === "true" : e, kn = (e) => {
|
|
1748
1837
|
if (e == null || typeof e != "string") return e;
|
|
1749
1838
|
let t = e.trim();
|
|
1750
1839
|
if (t.length === 0) return e;
|
|
@@ -1755,7 +1844,7 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
1755
1844
|
} catch {
|
|
1756
1845
|
return e;
|
|
1757
1846
|
}
|
|
1758
|
-
},
|
|
1847
|
+
}, An = (e) => e == null || typeof e == "string" ? e : typeof e == "number" || typeof e == "bigint" ? String(e) : e, jn = (e) => {
|
|
1759
1848
|
if (e == null || e instanceof Date) return e;
|
|
1760
1849
|
if (typeof e == "string") {
|
|
1761
1850
|
let t = new Date(e);
|
|
@@ -1766,61 +1855,76 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
1766
1855
|
return isNaN(t.getTime()) ? e : t;
|
|
1767
1856
|
}
|
|
1768
1857
|
return e;
|
|
1769
|
-
},
|
|
1858
|
+
}, Mn = (e, t, n) => {
|
|
1770
1859
|
if (e == null) return e;
|
|
1771
1860
|
switch (t) {
|
|
1772
|
-
case "boolean": return n === "postgres" ? e :
|
|
1773
|
-
case "vector": return n === "postgres" ?
|
|
1774
|
-
case "json": return n === "postgres" || n === "mysql" || n === "mariadb" ? e :
|
|
1775
|
-
case "array": return n === "postgres" ? e :
|
|
1861
|
+
case "boolean": return n === "postgres" ? e : On(e);
|
|
1862
|
+
case "vector": return n === "postgres" ? kn(e) : e;
|
|
1863
|
+
case "json": return n === "postgres" || n === "mysql" || n === "mariadb" ? e : kn(e);
|
|
1864
|
+
case "array": return n === "postgres" ? e : kn(e);
|
|
1776
1865
|
case "timestamp":
|
|
1777
|
-
case "date": return n === "sqlite" || n === "turso" ?
|
|
1866
|
+
case "date": return n === "sqlite" || n === "turso" ? jn(e) : e;
|
|
1778
1867
|
case "decimal":
|
|
1779
1868
|
if ((n === "sqlite" || n === "turso") && typeof e == "string" && /^D\d+$/.test(e)) throw TypeError("Decimal storage representation does not match the application schema; stop access and complete the verified storage migration before reading this column");
|
|
1780
|
-
return
|
|
1781
|
-
case "bigint": return
|
|
1869
|
+
return An(e);
|
|
1870
|
+
case "bigint": return An(e);
|
|
1782
1871
|
default: return e;
|
|
1783
1872
|
}
|
|
1784
|
-
},
|
|
1873
|
+
}, Nn = (e, t) => {
|
|
1874
|
+
switch (e) {
|
|
1875
|
+
case "boolean": return t !== "postgres";
|
|
1876
|
+
case "vector": return t === "postgres";
|
|
1877
|
+
case "json": return t !== "postgres" && t !== "mysql" && t !== "mariadb";
|
|
1878
|
+
case "array": return t !== "postgres";
|
|
1879
|
+
case "timestamp":
|
|
1880
|
+
case "date": return t === "sqlite" || t === "turso";
|
|
1881
|
+
case "decimal":
|
|
1882
|
+
case "bigint": return !0;
|
|
1883
|
+
default: return !1;
|
|
1884
|
+
}
|
|
1885
|
+
}, Pn = (e, t, n, r) => {
|
|
1785
1886
|
if (e.length === 0) return e;
|
|
1786
|
-
if (r && (n === "sqlite" || n === "turso") &&
|
|
1787
|
-
let t =
|
|
1887
|
+
if (r && (n === "sqlite" || n === "turso") && Sn(r)) {
|
|
1888
|
+
let t = X(En(r, void 0), void 0);
|
|
1788
1889
|
return e.map((e) => {
|
|
1789
1890
|
let r = { ...e };
|
|
1790
1891
|
for (let e of t) {
|
|
1791
1892
|
let t = e.decimal ? "decimal" : e.definition?.type;
|
|
1792
|
-
t && e.name in r && (r[e.name] =
|
|
1893
|
+
t && e.name in r && (r[e.name] = Mn(r[e.name], t, n));
|
|
1793
1894
|
}
|
|
1794
1895
|
return r;
|
|
1795
1896
|
});
|
|
1796
1897
|
}
|
|
1797
|
-
if (r?.joinedProjection?.length)
|
|
1798
|
-
let t =
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
}
|
|
1898
|
+
if (r?.joinedProjection?.length) {
|
|
1899
|
+
let t = r.joinedProjection.map((e) => ({
|
|
1900
|
+
outputKey: e.outputKey,
|
|
1901
|
+
definition: Y(e.source, r)
|
|
1902
|
+
}));
|
|
1903
|
+
return e.map((e) => {
|
|
1904
|
+
let r = { ...e };
|
|
1905
|
+
for (let { outputKey: e, definition: i } of t) i && e in r && (r[e] = Mn(r[e], i.type, n));
|
|
1906
|
+
return r;
|
|
1907
|
+
});
|
|
1908
|
+
}
|
|
1909
|
+
let i = r?.sourceTable?.tableName === t ? r.sourceTable : W(t);
|
|
1910
|
+
return i === void 0 ? e : Fn(e, i, n);
|
|
1911
|
+
}, Fn = (e, t, n) => {
|
|
1808
1912
|
if (e.length === 0) return e;
|
|
1809
1913
|
let r = t.fields, i = [];
|
|
1810
1914
|
for (let [e, t] of Object.entries(r)) {
|
|
1811
|
-
let r = n === "sqlite" || n === "turso" ?
|
|
1812
|
-
i.push({
|
|
1915
|
+
let r = n === "sqlite" || n === "turso" ? mn(t) : void 0, a = t.type;
|
|
1916
|
+
(r || Nn(a, n) || e in Object.prototype) && i.push({
|
|
1813
1917
|
key: e,
|
|
1814
|
-
type:
|
|
1918
|
+
type: a,
|
|
1815
1919
|
...r ? { decimalShape: r } : {}
|
|
1816
1920
|
});
|
|
1817
1921
|
}
|
|
1818
1922
|
return e.map((e) => {
|
|
1819
1923
|
let t = { ...e };
|
|
1820
|
-
for (let { key: e, type: r, decimalShape: a } of i) e in t && (t[e] = a && t[e] !== null && t[e] !== void 0 ?
|
|
1924
|
+
for (let { key: e, type: r, decimalShape: a } of i) e in t && (t[e] = a && t[e] !== null && t[e] !== void 0 ? pn(t[e], a) : Mn(t[e], r, n));
|
|
1821
1925
|
return t;
|
|
1822
1926
|
});
|
|
1823
|
-
},
|
|
1927
|
+
}, In = (e, t) => {
|
|
1824
1928
|
if (e == null) return e;
|
|
1825
1929
|
switch (t) {
|
|
1826
1930
|
case "json": return JSON.stringify(e);
|
|
@@ -1828,18 +1932,18 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
1828
1932
|
case "vector": return typeof e == "string" ? e : JSON.stringify(e);
|
|
1829
1933
|
default: return e;
|
|
1830
1934
|
}
|
|
1831
|
-
},
|
|
1832
|
-
let r =
|
|
1935
|
+
}, Ln = (e, t, n = ["json", "array"]) => {
|
|
1936
|
+
let r = W(t);
|
|
1833
1937
|
if (r === void 0) return e;
|
|
1834
1938
|
let i = r.fields, a = null;
|
|
1835
1939
|
for (let [t, r] of Object.entries(i)) if (n.includes(r.type) && t in e) {
|
|
1836
|
-
let n = r.type === "decimal" ?
|
|
1940
|
+
let n = r.type === "decimal" ? mn(r) : void 0, i = e[t];
|
|
1837
1941
|
if (n && i != null && typeof i != "string") throw TypeError("Encoded decimal writes require exact decimal strings");
|
|
1838
|
-
let o = n && typeof i == "string" ?
|
|
1942
|
+
let o = n && typeof i == "string" ? q(i, n) : In(i, r.type);
|
|
1839
1943
|
o !== e[t] && (a === null && (a = { ...e }), a[t] = o);
|
|
1840
1944
|
}
|
|
1841
1945
|
return a ?? e;
|
|
1842
|
-
},
|
|
1946
|
+
}, Rn = (e) => {
|
|
1843
1947
|
if (typeof e != "string" || !/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/.test(e)) return null;
|
|
1844
1948
|
let [t = "", n = ""] = e.replace(/^[+-]/, "").split("."), r = t.replace(/^0+/, "") || "0";
|
|
1845
1949
|
return {
|
|
@@ -1847,8 +1951,8 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
1847
1951
|
whole: r,
|
|
1848
1952
|
fraction: n
|
|
1849
1953
|
};
|
|
1850
|
-
},
|
|
1851
|
-
let n =
|
|
1954
|
+
}, zn = (e, t) => {
|
|
1955
|
+
let n = Rn(e), r = Rn(t);
|
|
1852
1956
|
if (!n || !r) return null;
|
|
1853
1957
|
if (n.negative !== r.negative) return n.negative ? -1 : 1;
|
|
1854
1958
|
let i = n.whole.length - r.whole.length;
|
|
@@ -1857,34 +1961,34 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
1857
1961
|
i = t === a ? 0 : t > a ? 1 : -1;
|
|
1858
1962
|
}
|
|
1859
1963
|
return i === 0 ? 0 : (i > 0 ? 1 : -1) * (n.negative ? -1 : 1);
|
|
1860
|
-
},
|
|
1861
|
-
let t =
|
|
1964
|
+
}, Bn = (e) => {
|
|
1965
|
+
let t = Rn(e);
|
|
1862
1966
|
if (t === null) return null;
|
|
1863
1967
|
let n = t.fraction.replace(/0+$/, "");
|
|
1864
1968
|
return `${t.negative ? "-" : ""}${t.whole}${n ? "." + n : ""}`;
|
|
1865
|
-
},
|
|
1969
|
+
}, Vn = (e) => {
|
|
1866
1970
|
if (e.length === 0) throw RangeError("Column reference must not be empty");
|
|
1867
1971
|
return {
|
|
1868
1972
|
_tag: "ColumnReference",
|
|
1869
1973
|
column: e
|
|
1870
1974
|
};
|
|
1871
|
-
},
|
|
1975
|
+
}, Hn = (e) => typeof e == "object" && !!e && "_tag" in e && e._tag === "ColumnReference" && "column" in e && typeof e.column == "string", Un = [
|
|
1872
1976
|
"eq",
|
|
1873
1977
|
"neq",
|
|
1874
1978
|
"gt",
|
|
1875
1979
|
"gte",
|
|
1876
1980
|
"lt",
|
|
1877
1981
|
"lte"
|
|
1878
|
-
],
|
|
1982
|
+
], Wn = (e) => e == null ? e : e instanceof Date ? e.toISOString() : typeof e == "boolean" ? +!!e : Array.isArray(e) ? e.map((e) => Wn(e)) : e, Gn = /^[A-Za-z_][A-Za-z0-9_]*$/, Kn = (e) => "$" + e.map((e) => typeof e == "number" ? `[${e}]` : Gn.test(e) ? `.${e}` : `."${e.replace(/"/g, "\\\"")}"`).join(""), qn = (e) => "{" + e.map((e) => {
|
|
1879
1983
|
let t = String(e);
|
|
1880
1984
|
return /^[A-Za-z0-9_]+$/.test(t) ? t : `"${t.replace(/(["\\])/g, "\\$1")}"`;
|
|
1881
|
-
}).join(",") + "}",
|
|
1882
|
-
let i =
|
|
1985
|
+
}).join(",") + "}", Q = (e, t, n, r = {}) => {
|
|
1986
|
+
let i = Tt(e, n), a = r.numeric ?? !1;
|
|
1883
1987
|
if (n === "postgres") {
|
|
1884
|
-
let e = `(${i} #>> '${
|
|
1988
|
+
let e = `(${i} #>> '${qn(t)}'::text[])`;
|
|
1885
1989
|
return a ? `${e}::numeric` : e;
|
|
1886
1990
|
}
|
|
1887
|
-
let o =
|
|
1991
|
+
let o = Kn(t);
|
|
1888
1992
|
switch (n) {
|
|
1889
1993
|
case "mysql":
|
|
1890
1994
|
case "mariadb": {
|
|
@@ -1901,66 +2005,68 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
1901
2005
|
return a ? `CAST(${e} AS REAL)` : e;
|
|
1902
2006
|
}
|
|
1903
2007
|
}
|
|
1904
|
-
},
|
|
2008
|
+
}, Jn = class extends Error {
|
|
1905
2009
|
_tag = "TenantNamespaceUnresolved";
|
|
1906
2010
|
constructor(e) {
|
|
1907
2011
|
super(e), this.name = "TenantNamespaceUnresolved";
|
|
1908
2012
|
}
|
|
1909
|
-
},
|
|
2013
|
+
}, Yn = class extends Error {
|
|
1910
2014
|
_tag = "TenantNamespaceInvalid";
|
|
1911
2015
|
constructor(e) {
|
|
1912
2016
|
super(e), this.name = "TenantNamespaceInvalid";
|
|
1913
2017
|
}
|
|
1914
|
-
},
|
|
1915
|
-
if (e == null || e === "") throw new
|
|
1916
|
-
let t =
|
|
1917
|
-
if (t.replace(/_/g, "") === "") throw new
|
|
1918
|
-
let n = `${
|
|
1919
|
-
if (n.length >
|
|
2018
|
+
}, Xn = 63, Zn = "tenant_", Qn = (e) => e.toLowerCase().replace(/[^a-z0-9_]/g, "_"), $n = (e) => {
|
|
2019
|
+
if (e == null || e === "") throw new Jn("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.");
|
|
2020
|
+
let t = Qn(e);
|
|
2021
|
+
if (t.replace(/_/g, "") === "") throw new Yn(`tenant id '${e}' has no usable identifier characters after sanitisation — cannot derive a distinct namespace.`);
|
|
2022
|
+
let n = `${Zn}${t}`;
|
|
2023
|
+
if (n.length > Xn) throw new Yn(`namespace '${n}' for tenant '${e}' exceeds the ${Xn}-byte identifier limit. Use a shorter tenant id.`);
|
|
1920
2024
|
return n;
|
|
1921
|
-
},
|
|
1922
|
-
if (e === void 0 || t == null || !
|
|
2025
|
+
}, er = (e, t) => e === null ? t : `${e}.${t}`, tr = /* @__PURE__ */ new Set(["timestamp", "date"]), nr = /^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2})?/, rr = (e, t) => {
|
|
2026
|
+
if (e === void 0 || t == null || !tr.has(e) || t instanceof Date) return t;
|
|
1923
2027
|
if (typeof t == "number" && Number.isFinite(t)) return new Date(t);
|
|
1924
|
-
if (typeof t == "string" &&
|
|
2028
|
+
if (typeof t == "string" && nr.test(t)) {
|
|
1925
2029
|
if (/:\d{2}\.\d{4,}/.test(t)) return t;
|
|
1926
2030
|
let e = new Date(t);
|
|
1927
2031
|
return Number.isNaN(e.getTime()) ? t : e;
|
|
1928
2032
|
}
|
|
1929
2033
|
return t;
|
|
1930
|
-
},
|
|
2034
|
+
}, ir = (e, t) => e === void 0 || !tr.has(e) ? t : t.map((t) => rr(e, t)), ar = (e) => {
|
|
1931
2035
|
if (!e.distinct && !e.distinctOn?.length || e.aggregations?.length || e.setOp) return;
|
|
1932
|
-
let t = e.sourceTable?.tableName === e.table ? e.sourceTable :
|
|
2036
|
+
let t = yn(e), n = e.sourceTable?.tableName === e.table ? e.sourceTable : W(e.table), r = e.joinedProjection ?? (e.projection?.length ? e.projection : Object.keys(n?.fields ?? {})).map((e) => ({
|
|
1933
2037
|
source: e,
|
|
1934
2038
|
outputKey: e.split(".").at(-1)
|
|
1935
|
-
})),
|
|
1936
|
-
for (let
|
|
1937
|
-
let n =
|
|
2039
|
+
})), i = {};
|
|
2040
|
+
for (let e of r) {
|
|
2041
|
+
let n = t(e.source);
|
|
1938
2042
|
if (!n) return;
|
|
1939
|
-
|
|
2043
|
+
i[e.outputKey] = n;
|
|
1940
2044
|
}
|
|
1941
|
-
if (!Object.values(
|
|
1942
|
-
let
|
|
2045
|
+
if (!Object.values(i).some((e) => e.type === "decimal")) return;
|
|
2046
|
+
let a = new Set([
|
|
1943
2047
|
e.table,
|
|
1944
2048
|
...(e.ctes ?? []).map((e) => e.name),
|
|
1945
2049
|
...(e.joins ?? []).map((e) => e.table)
|
|
1946
|
-
].map((e) => e.toLowerCase())),
|
|
1947
|
-
for (;
|
|
2050
|
+
].map((e) => e.toLowerCase())), o = "__voltro_mssql_decimal_result";
|
|
2051
|
+
for (; a.has(o.toLowerCase());) o += "_";
|
|
2052
|
+
let s = e.order.length >= 8 && r.length >= 8 ? /* @__PURE__ */ new Map() : void 0;
|
|
2053
|
+
if (s) for (let e of r) s.has(e.source) || s.set(e.source, e.outputKey);
|
|
1948
2054
|
return {
|
|
1949
|
-
table:
|
|
2055
|
+
table: o,
|
|
1950
2056
|
sourceTable: {
|
|
1951
|
-
tableName:
|
|
1952
|
-
fields:
|
|
2057
|
+
tableName: o,
|
|
2058
|
+
fields: i
|
|
1953
2059
|
},
|
|
1954
2060
|
predicate: void 0,
|
|
1955
2061
|
projection: void 0,
|
|
1956
2062
|
order: e.order.map((e) => ({
|
|
1957
2063
|
...e,
|
|
1958
|
-
column:
|
|
2064
|
+
column: (s === void 0 ? r.find((t) => t.source === e.column)?.outputKey : s.get(e.column)) ?? e.column
|
|
1959
2065
|
})),
|
|
1960
2066
|
take: e.take,
|
|
1961
2067
|
skip: e.skip,
|
|
1962
2068
|
ctes: [...e.ctes ?? [], {
|
|
1963
|
-
name:
|
|
2069
|
+
name: o,
|
|
1964
2070
|
descriptor: {
|
|
1965
2071
|
...e,
|
|
1966
2072
|
ctes: [],
|
|
@@ -1970,11 +2076,11 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
1970
2076
|
}
|
|
1971
2077
|
}]
|
|
1972
2078
|
};
|
|
1973
|
-
},
|
|
2079
|
+
}, or = (e, t, n, r) => {
|
|
1974
2080
|
let i = n.compile(e.subquery);
|
|
1975
2081
|
if (e.op === "exists") return t`EXISTS (${i})`;
|
|
1976
2082
|
if (e.op === "not-exists") return t`NOT EXISTS (${i})`;
|
|
1977
|
-
let a =
|
|
2083
|
+
let a = X(e.subquery, n.resultScale);
|
|
1978
2084
|
if (a.length !== 1) throw Error("Exact IN subquery must project exactly one column");
|
|
1979
2085
|
if (!("column" in e)) throw Error("Unsupported exact subquery predicate");
|
|
1980
2086
|
let o = r(e.column), s = a[0];
|
|
@@ -1984,7 +2090,7 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
1984
2090
|
return r ? t`${e} || ${(n === 0 ? "." : "") + "0".repeat(r)}` : e;
|
|
1985
2091
|
}, u = l(o.value, o.scale ?? 0), d = t`SELECT ${l(t`${t(s.name)}`, s.decimal?.scale ?? 0)} FROM (${i})`;
|
|
1986
2092
|
return e.op === "subquery-in" ? t`${u} IN (${d})` : t`${u} NOT IN (${d})`;
|
|
1987
|
-
},
|
|
2093
|
+
}, sr = (e, t, n, r) => {
|
|
1988
2094
|
let i = (e) => [
|
|
1989
2095
|
e.table,
|
|
1990
2096
|
...(e.joins ?? []).map((e) => e.table),
|
|
@@ -1997,7 +2103,7 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
1997
2103
|
}, c = (e) => {
|
|
1998
2104
|
if (!e.setOp) throw Error("Missing exact set operation");
|
|
1999
2105
|
if (e.ctes || e.distinctOn || e.annClause || e.spatialClause || e.fullTextSearch) throw Error("Unsupported exact set query clause");
|
|
2000
|
-
let i =
|
|
2106
|
+
let i = X(e, n.resultScale);
|
|
2001
2107
|
if (new Set(i.map((e) => e.name)).size !== i.length) throw Error("Duplicate exact set output name");
|
|
2002
2108
|
let a = {
|
|
2003
2109
|
union: "UNION",
|
|
@@ -2005,12 +2111,12 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
2005
2111
|
intersect: "INTERSECT",
|
|
2006
2112
|
except: "EXCEPT"
|
|
2007
2113
|
}[e.setOp.kind], o = e.setOp.queries.map((e) => {
|
|
2008
|
-
let a =
|
|
2114
|
+
let a = X(e, n.resultScale), o = i.map((e, n) => {
|
|
2009
2115
|
let r = t`${t(a[n].name)}`, i = (e.decimal?.scale ?? 0) - (a[n].decimal?.scale ?? 0), o = i > 0 ? (a[n].decimal.scale === 0 ? "." : "") + "0".repeat(i) : "";
|
|
2010
2116
|
return t`${o ? t`${r} || ${o}` : r} AS ${t(`v${n}`)}`;
|
|
2011
2117
|
}), l = s(e.setOp ? c(e) : r(e));
|
|
2012
|
-
return t`SELECT ${t.
|
|
2013
|
-
}).reduce((e, n) => t`${e} ${t.unsafe(a)} ${n}`), l = s(o), u = e.order.length ? t` ORDER BY ${t.
|
|
2118
|
+
return t`SELECT ${t.join(", ", !1)(o)} FROM ${t(l)}`;
|
|
2119
|
+
}).reduce((e, n) => t`${e} ${t.unsafe(a)} ${n}`), l = s(o), u = e.order.length ? t` ORDER BY ${t.join(", ", !1)(e.order.flatMap((e) => {
|
|
2014
2120
|
let n = i.findIndex((t) => t.name === e.column);
|
|
2015
2121
|
if (n < 0) throw Error("Exact set ordering references an unknown output");
|
|
2016
2122
|
let r = t`${t(`v${n}`)}`, a = e.direction !== "desc", o = (e, n) => n ? t`${e} ASC` : t`${e} DESC`;
|
|
@@ -2026,34 +2132,34 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
2026
2132
|
}))}` : t``;
|
|
2027
2133
|
for (let t of [e.take, e.skip]) if (t !== void 0 && (!Number.isSafeInteger(t) || t < 0)) throw Error("Invalid exact set pagination");
|
|
2028
2134
|
let d = e.take === void 0 ? e.skip === void 0 ? t`` : t` LIMIT -1` : t` LIMIT ${e.take}`, f = e.skip === void 0 ? t`` : t` OFFSET ${e.skip}`;
|
|
2029
|
-
return t`SELECT ${t.
|
|
2135
|
+
return t`SELECT ${t.join(", ", !1)(i.map((e, n) => t`${t(`v${n}`)} AS ${t(e.name)}`))} FROM ${t(l)}${u}${d}${f}`;
|
|
2030
2136
|
}, l = c(e);
|
|
2031
|
-
return t`WITH ${t.
|
|
2032
|
-
},
|
|
2137
|
+
return t`WITH ${t.join(", ", !1)(o)} ${l}`;
|
|
2138
|
+
}, cr = {
|
|
2033
2139
|
eq: "=",
|
|
2034
2140
|
neq: "<>",
|
|
2035
2141
|
gt: ">",
|
|
2036
2142
|
gte: ">=",
|
|
2037
2143
|
lt: "<",
|
|
2038
2144
|
lte: "<="
|
|
2039
|
-
},
|
|
2040
|
-
|
|
2041
|
-
let r =
|
|
2145
|
+
}, lr = (e, t, n) => {
|
|
2146
|
+
q("0", e.shape), q("0", n.shape);
|
|
2147
|
+
let r = cr[t];
|
|
2042
2148
|
if (r === void 0) throw RangeError("Invalid decimal column comparison");
|
|
2043
2149
|
let i = Math.max(e.shape.scale, n.shape.scale), a = Math.max(e.shape.precision - e.shape.scale, n.shape.precision - n.shape.scale), o = ({ expression: e, shape: t }) => {
|
|
2044
2150
|
let n = a - (t.precision - t.scale), r = "0".repeat(i - t.scale);
|
|
2045
2151
|
return `(CASE WHEN substr((${e}), 2, 1) = '1' THEN '1${"0".repeat(n)}' ELSE '0${"9".repeat(n)}' END || substr((${e}), 3) || '${r}') COLLATE BINARY`;
|
|
2046
2152
|
};
|
|
2047
2153
|
return `(${o(e)} ${r} ${o(n)})`;
|
|
2048
|
-
},
|
|
2049
|
-
let n =
|
|
2154
|
+
}, ur = ({ expression: e, shape: t }) => {
|
|
2155
|
+
let n = dr(t, (e) => e), r = [`decimal_decode_input AS (SELECT (${e}) AS encoded LIMIT -1 OFFSET 0)`], i = "decimal_decode_input";
|
|
2050
2156
|
for (let [e, t] of n.steps) {
|
|
2051
2157
|
let n = `decimal_decode_${e}`;
|
|
2052
2158
|
r.push(`${n} AS (SELECT *,${t.join(",")} FROM ${i} LIMIT -1 OFFSET 0)`), i = n;
|
|
2053
2159
|
}
|
|
2054
2160
|
return `(WITH ${r.join(",")} SELECT ${n.value} AS value FROM ${i})`;
|
|
2055
|
-
},
|
|
2056
|
-
|
|
2161
|
+
}, dr = (e, t) => {
|
|
2162
|
+
q("0", e);
|
|
2057
2163
|
let n = t("encoded"), r = t("payload"), i = t("negative"), a = t("trimmed"), o = t("units"), s = t("magnitude"), c = t("padded"), l = `substr(${a},1,length(${a})-1)`;
|
|
2058
2164
|
for (let e = 0; e < 10; e++) l = `replace(${l},'${e}','${String.fromCharCode(97 + e)}')`;
|
|
2059
2165
|
let u = t("alphabetic");
|
|
@@ -2107,40 +2213,41 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
2107
2213
|
],
|
|
2108
2214
|
value: `CASE WHEN ${n} IS NULL THEN NULL WHEN ${`typeof(${n})<>'text' OR length(${n})<>${e.precision + 2} OR substr(${n},1,1)<>'D' OR substr(${n},2,1) NOT IN ('0','1') OR substr(${n},2) GLOB '*[^0-9]*' OR (${i} AND length(${a})=0)`} THEN abs(-9223372036854775808) ELSE (CASE WHEN ${i} THEN '-' ELSE '' END)||${f} END`
|
|
2109
2215
|
};
|
|
2110
|
-
},
|
|
2216
|
+
}, fr = (e, t, n, r) => {
|
|
2111
2217
|
if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r.prefix)) throw Error("Invalid decimal decoder stage prefix");
|
|
2112
2218
|
if (new Set(t.map((e) => e.name)).size !== t.length || t.some((e) => !/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e.name))) throw Error("Invalid decimal decoder columns");
|
|
2113
|
-
|
|
2114
|
-
|
|
2219
|
+
let i = new Set(n);
|
|
2220
|
+
if (i.size !== n.length || n.some((e) => !/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)) || t.some((e) => !i.has(e.name))) throw Error("Invalid decimal decoder input columns");
|
|
2221
|
+
let a = t.map((e, t) => {
|
|
2115
2222
|
let n = (n) => n === "encoded" ? e.name : `${r.prefix}d${t}_${n}`;
|
|
2116
2223
|
return {
|
|
2117
2224
|
column: e,
|
|
2118
2225
|
ref: n,
|
|
2119
|
-
plan:
|
|
2226
|
+
plan: dr(e.shape, n)
|
|
2120
2227
|
};
|
|
2121
2228
|
});
|
|
2122
|
-
for (let t = 0; t < (
|
|
2123
|
-
let
|
|
2124
|
-
r.append(
|
|
2229
|
+
for (let t = 0; t < (a[0]?.plan.steps.length ?? 0); t++) {
|
|
2230
|
+
let i = `${r.prefix}decode_${t}`, o = a.flatMap(({ plan: e }) => e.steps[t][1]), s = a.flatMap(({ plan: e, ref: n }) => t === 0 ? [] : e.retained[t - 1].filter((n) => e.retained[t].includes(n)).map(n));
|
|
2231
|
+
r.append(i, `SELECT ${[
|
|
2125
2232
|
...n,
|
|
2126
2233
|
...s,
|
|
2127
2234
|
...o
|
|
2128
|
-
].join(",")} FROM ${e} LIMIT -1 OFFSET 0`), e =
|
|
2235
|
+
].join(",")} FROM ${e} LIMIT -1 OFFSET 0`), e = i;
|
|
2129
2236
|
}
|
|
2130
2237
|
return {
|
|
2131
2238
|
source: e,
|
|
2132
|
-
values: new Map(
|
|
2239
|
+
values: new Map(a.map(({ column: e, plan: t }) => [e.name, t.value]))
|
|
2133
2240
|
};
|
|
2134
|
-
},
|
|
2241
|
+
}, pr = (e, t) => {
|
|
2135
2242
|
if (!Number.isSafeInteger(e) || e < 1 || !Number.isSafeInteger(t) || t < 0 || t > e) throw RangeError("Invalid decimal result shape");
|
|
2136
|
-
},
|
|
2137
|
-
if (
|
|
2243
|
+
}, mr = (e, t) => {
|
|
2244
|
+
if (pr(t, 0), !/^-?(?:0|[1-9]\d*)$/.test(e)) throw TypeError("Expected canonical decimal units");
|
|
2138
2245
|
let n = e.replace(/^-/, "");
|
|
2139
2246
|
if (n.length > t) throw RangeError("Decimal result exceeds declared width");
|
|
2140
2247
|
let r = n.padStart(t, "0");
|
|
2141
2248
|
return e.startsWith("-") && n !== "0" ? "0" + r.replace(/\d/g, (e) => String(9 - Number(e))) : "1" + r;
|
|
2142
|
-
},
|
|
2143
|
-
|
|
2249
|
+
}, hr = ({ sourceSql: e, digits: t, scale: n, materialized: r = !1, stages: i }) => {
|
|
2250
|
+
pr(t, n);
|
|
2144
2251
|
let a = "0".repeat(t), o = "ltrim(units,'-')", s = `substr('${a}'||${o},-${t})`, c = s;
|
|
2145
2252
|
for (let e = 0; e < 10; e++) c = `replace(${c},'${e}','${String.fromCharCode(97 + e)}')`;
|
|
2146
2253
|
let l = c;
|
|
@@ -2155,8 +2262,8 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
2155
2262
|
CASE WHEN units IS NULL THEN NULL ${m} ELSE ${d} END AS decimal_key,
|
|
2156
2263
|
CASE WHEN units IS NULL THEN NULL ${m} ELSE (CASE WHEN ${u} THEN '-' ELSE '' END)||${p} END AS decimal_value
|
|
2157
2264
|
FROM ${v(_)}`;
|
|
2158
|
-
},
|
|
2159
|
-
|
|
2265
|
+
}, gr = (e, t, n) => {
|
|
2266
|
+
pr(e.digits, e.scale), pr(n.digits, n.scale);
|
|
2160
2267
|
let r = {
|
|
2161
2268
|
eq: "=",
|
|
2162
2269
|
neq: "<>",
|
|
@@ -2171,8 +2278,8 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
2171
2278
|
return `(CASE WHEN substr((${e}),1,1)='0' THEN '0${"9".repeat(r)}'||substr((${e}),2)||'${"9".repeat(o)}' ELSE '1${"0".repeat(r)}'||substr((${e}),2)||'${"0".repeat(o)}' END) COLLATE BINARY`;
|
|
2172
2279
|
};
|
|
2173
2280
|
return `(${o(e)} ${r} ${o(n)})`;
|
|
2174
|
-
},
|
|
2175
|
-
if (
|
|
2281
|
+
}, _r = (e, t, n) => {
|
|
2282
|
+
if (q("0", t), e.path?.length) throw Error("Decimal JSON-path predicates are unsupported");
|
|
2176
2283
|
if (e.op === "isNull" || e.op === "isNotNull") return e;
|
|
2177
2284
|
if (![
|
|
2178
2285
|
"eq",
|
|
@@ -2184,7 +2291,7 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
2184
2291
|
"in",
|
|
2185
2292
|
"notIn"
|
|
2186
2293
|
].includes(e.op)) throw Error("Unsupported exact decimal predicate");
|
|
2187
|
-
let r = 10n ** BigInt(t.precision), i = -r + 1n, a = r - 1n, o = (e) => n === "aggregate" ?
|
|
2294
|
+
let r = 10n ** BigInt(t.precision), i = -r + 1n, a = r - 1n, o = (e) => n === "aggregate" ? mr(String(e), t.precision) : "D" + (e + r).toString().padStart(t.precision + 1, "0"), s = (e) => {
|
|
2188
2295
|
if (typeof e != "string" || !/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/.test(e)) throw TypeError("Exact decimal predicate requires a fixed-point decimal string");
|
|
2189
2296
|
let [n = "", r = ""] = e.replace(/^[+-]/, "").split("."), i = BigInt((n || "0") + r.slice(0, t.scale).padEnd(t.scale, "0")), a = /[1-9]/.test(r.slice(t.scale)), o = e.startsWith("-"), s = o ? -i : i;
|
|
2190
2297
|
return {
|
|
@@ -2231,17 +2338,17 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
2231
2338
|
...e,
|
|
2232
2339
|
value: o(u)
|
|
2233
2340
|
};
|
|
2234
|
-
},
|
|
2341
|
+
}, vr = (e, t, n, r) => {
|
|
2235
2342
|
let i = (r) => {
|
|
2236
2343
|
if ("not" in r) return t`NOT (${i(r.not)})`;
|
|
2237
2344
|
if ("and" in r) return r.and.length ? t.and(r.and.map(i)) : t`TRUE`;
|
|
2238
2345
|
if ("or" in r) return r.or.length ? t.or(r.or.map(i)) : t`FALSE`;
|
|
2239
|
-
if ("subquery" in r) return
|
|
2240
|
-
let r =
|
|
2346
|
+
if ("subquery" in r) return or(r, t, n, (n) => {
|
|
2347
|
+
let r = Y(n, e);
|
|
2241
2348
|
if (!r) throw Error("Exact IN subquery requires a declared outer column");
|
|
2242
2349
|
let i = t`${t(n)}`;
|
|
2243
|
-
return
|
|
2244
|
-
value: t.unsafe(
|
|
2350
|
+
return J(r) ? {
|
|
2351
|
+
value: t.unsafe(ur({
|
|
2245
2352
|
expression: i.compile()[0],
|
|
2246
2353
|
shape: {
|
|
2247
2354
|
precision: r.precision,
|
|
@@ -2251,19 +2358,19 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
2251
2358
|
scale: r.scale
|
|
2252
2359
|
} : { value: i };
|
|
2253
2360
|
});
|
|
2254
|
-
if (!("value" in r) || !
|
|
2361
|
+
if (!("value" in r) || !Hn(r.value)) {
|
|
2255
2362
|
if (!("column" in r)) throw Error("Decimal subquery predicates are not integrated yet");
|
|
2256
|
-
let n =
|
|
2257
|
-
return
|
|
2363
|
+
let n = Y(r.column, e);
|
|
2364
|
+
return qr(J(n) ? _r(r, {
|
|
2258
2365
|
precision: n.precision,
|
|
2259
2366
|
scale: n.scale
|
|
2260
2367
|
}, "column") : r, t, null, e.table);
|
|
2261
2368
|
}
|
|
2262
|
-
let a =
|
|
2369
|
+
let a = Y(r.column, e), o = Y(r.value.column, e);
|
|
2263
2370
|
if (!a || !o) throw Error("Column comparisons require declared source columns");
|
|
2264
|
-
if (!
|
|
2265
|
-
if (!
|
|
2266
|
-
if (!
|
|
2371
|
+
if (!J(a) && !J(o)) return qr(r, t);
|
|
2372
|
+
if (!J(a) || !J(o)) throw Error("Encoded decimal comparisons require two decimal columns");
|
|
2373
|
+
if (!Un.includes(r.op) || r.path?.length) throw Error("Unsupported exact decimal column comparison");
|
|
2267
2374
|
let s = (e, n) => {
|
|
2268
2375
|
if (n.precision === void 0 || n.scale === void 0) throw Error("Decimal comparison requires declared precision and scale");
|
|
2269
2376
|
return {
|
|
@@ -2274,78 +2381,78 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
2274
2381
|
}
|
|
2275
2382
|
};
|
|
2276
2383
|
};
|
|
2277
|
-
return t.unsafe(
|
|
2384
|
+
return t.unsafe(lr(s(r.column, a), r.op, s(r.value.column, o)));
|
|
2278
2385
|
};
|
|
2279
2386
|
return i(r);
|
|
2280
|
-
},
|
|
2281
|
-
let r = (r) =>
|
|
2387
|
+
}, yr = (e, t, n) => {
|
|
2388
|
+
let r = (r) => vr(e, t, n, r), i = n.sourceTable ?? ((e) => e), a = e.alias === void 0 ? t`${t(i(e.table))}` : t`${t(i(e.table))} AS ${t(e.alias)}`;
|
|
2282
2389
|
return {
|
|
2283
2390
|
from: (e.joins ?? []).reduce((e, n) => t`${e} ${n.kind === "inner" ? t`INNER` : t`LEFT`} JOIN ${t(i(n.table))} AS ${t(n.alias)} ON ${r(n.on)}`, a),
|
|
2284
2391
|
where: e.predicate === void 0 ? t`` : t` WHERE ${r(e.predicate)}`
|
|
2285
2392
|
};
|
|
2286
|
-
},
|
|
2393
|
+
}, br = (e, t, n, r, i) => {
|
|
2287
2394
|
if (e.groupBy?.length || e.having) throw Error("Row queries cannot contain aggregate clauses");
|
|
2288
|
-
let a = e.sourceTable?.tableName === e.table ? e.sourceTable :
|
|
2395
|
+
let a = yn(e), o = e.sourceTable?.tableName === e.table ? e.sourceTable : W(e.table), s = e.joinedProjection ?? (e.projection?.length ? e.projection : Object.keys(o?.fields ?? {})).map((t) => ({
|
|
2289
2396
|
source: t.includes(".") ? t : `${e.alias ?? e.table}.${t}`,
|
|
2290
2397
|
outputKey: t.split(".").at(-1)
|
|
2291
2398
|
}));
|
|
2292
|
-
if (!
|
|
2293
|
-
if (new Set(
|
|
2294
|
-
let s =
|
|
2295
|
-
let
|
|
2296
|
-
if (!
|
|
2399
|
+
if (!s.length) throw Error("Exact row projection requires declared source columns");
|
|
2400
|
+
if (new Set(s.map((e) => e.outputKey)).size !== s.length) throw Error("Duplicate exact row output key");
|
|
2401
|
+
let c = e.order.length >= 8 && s.length >= 8 ? new Map(s.map((e) => [e.outputKey, e.source])) : void 0, l = s.map((e, t) => {
|
|
2402
|
+
let n = a(e.source);
|
|
2403
|
+
if (!n) throw Error("Exact row projection requires declared source columns");
|
|
2297
2404
|
return {
|
|
2298
|
-
...
|
|
2299
|
-
field:
|
|
2300
|
-
internal: `v${
|
|
2405
|
+
...e,
|
|
2406
|
+
field: n,
|
|
2407
|
+
internal: `v${t}`
|
|
2301
2408
|
};
|
|
2302
|
-
}),
|
|
2303
|
-
let
|
|
2304
|
-
if (!
|
|
2409
|
+
}), u = e.order.map((e, t) => {
|
|
2410
|
+
let n = (c === void 0 ? s.find((t) => t.outputKey === e.column)?.source : c.get(e.column)) ?? e.column, r = a(n);
|
|
2411
|
+
if (!r) throw Error("Exact row order requires a declared source column");
|
|
2305
2412
|
return {
|
|
2306
|
-
...
|
|
2307
|
-
source:
|
|
2308
|
-
field:
|
|
2309
|
-
internal: `o${
|
|
2413
|
+
...e,
|
|
2414
|
+
source: n,
|
|
2415
|
+
field: r,
|
|
2416
|
+
internal: `o${t}`
|
|
2310
2417
|
};
|
|
2311
2418
|
});
|
|
2312
2419
|
for (let t of [e.take, e.skip]) if (t !== void 0 && (!Number.isSafeInteger(t) || t < 0)) throw Error("Invalid exact decimal pagination");
|
|
2313
|
-
let { from:
|
|
2314
|
-
for (;
|
|
2315
|
-
let
|
|
2316
|
-
|
|
2317
|
-
},
|
|
2318
|
-
|
|
2319
|
-
let
|
|
2320
|
-
if (r) for (let e of
|
|
2321
|
-
let
|
|
2420
|
+
let { from: d, where: f } = yr(e, t, n), p = [...l, ...u], [m, h] = t`SELECT ${t.join(", ", !1)(p.map((e) => t`${t(e.source)} AS ${t(e.internal)}`))} FROM ${d}${f}`.compile(), g = i ?? r, _ = g?.prefix ?? "__voltro_decimal_rows_";
|
|
2421
|
+
for (; m.toLowerCase().includes(_.toLowerCase());) _ += "_";
|
|
2422
|
+
let v = [], y = (e, t) => {
|
|
2423
|
+
g ? g.append(e, t) : v.push(`${e} AS MATERIALIZED (${t})`);
|
|
2424
|
+
}, b = `${_}input`;
|
|
2425
|
+
y(b, m);
|
|
2426
|
+
let x = l.filter((e) => J(e.field));
|
|
2427
|
+
if (r) for (let e of x) r.encodedOutput(e.outputKey);
|
|
2428
|
+
let S = fr(b, r ? [] : x.map((e) => ({
|
|
2322
2429
|
name: e.internal,
|
|
2323
2430
|
shape: {
|
|
2324
2431
|
precision: e.field.precision,
|
|
2325
2432
|
scale: e.field.scale
|
|
2326
2433
|
}
|
|
2327
|
-
})),
|
|
2328
|
-
prefix:
|
|
2329
|
-
append:
|
|
2434
|
+
})), p.map((e) => e.internal), {
|
|
2435
|
+
prefix: _,
|
|
2436
|
+
append: y
|
|
2330
2437
|
});
|
|
2331
|
-
|
|
2332
|
-
let
|
|
2333
|
-
let n =
|
|
2438
|
+
b = S.source;
|
|
2439
|
+
let C = l.map((e) => {
|
|
2440
|
+
let n = S.values.get(e.internal);
|
|
2334
2441
|
return t`${n ? t.unsafe(n) : e.field.type === "bigint" ? t`CAST(${t(e.internal)} AS TEXT)` : t`${t(e.internal)}`} AS ${t(e.outputKey)}`;
|
|
2335
|
-
}),
|
|
2336
|
-
let n =
|
|
2442
|
+
}), w = u.length ? t` ORDER BY ${t.join(", ", !1)(u.map((e) => {
|
|
2443
|
+
let n = J(e.field) ? t`${t(e.internal)} COLLATE BINARY` : t`${t(e.internal)}`;
|
|
2337
2444
|
return e.direction === "desc" ? t`${n} DESC` : t`${n} ASC`;
|
|
2338
|
-
}))}` : t``,
|
|
2339
|
-
return t.unsafe(
|
|
2340
|
-
},
|
|
2445
|
+
}))}` : t``, T = e.take === void 0 ? e.skip === void 0 ? t`` : t` LIMIT -1` : t` LIMIT ${e.take}`, E = e.skip === void 0 ? t`` : t` OFFSET ${e.skip}`, D = v.length ? `WITH ${v.join(",")} ` : "", O = t`SELECT ${e.distinct ? t`DISTINCT ` : t``}${t.join(", ", !1)(C)} FROM ${t(b)}${w}${T}${E}`.compile();
|
|
2446
|
+
return t.unsafe(D + O[0], [...h, ...O[1]]);
|
|
2447
|
+
}, xr = (e, t, n) => {
|
|
2341
2448
|
let r = n ? t : `SELECT * FROM (${t}) LIMIT -1 OFFSET 0`;
|
|
2342
2449
|
return `${e} AS${n ? " MATERIALIZED" : ""} (${r})`;
|
|
2343
|
-
},
|
|
2450
|
+
}, Sr = ({ sourceSql: e, precision: t, scope: n, materialized: r = !1, stages: i }) => {
|
|
2344
2451
|
if (!Number.isSafeInteger(t) || t <= 0) throw RangeError("Invalid decimal aggregate precision");
|
|
2345
2452
|
let a = 1e6, o = (9223372036854775807n / BigInt(a)).toString(), s = Math.ceil((t + 1) / 6), c = Math.ceil((t + 20) / 6) * 6, l = [];
|
|
2346
2453
|
if (i && !/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i.prefix)) throw Error("Invalid decimal stage prefix");
|
|
2347
2454
|
let u = (e) => (i?.prefix ?? "") + e, d = (e) => i?.reference?.(u(e)) ?? u(e), f = (e, t) => {
|
|
2348
|
-
i ? i.append(u(e), t, r) : l.push(
|
|
2455
|
+
i ? i.append(u(e), t, r) : l.push(xr(e, t, r));
|
|
2349
2456
|
}, p = (e) => "\"" + e.replace(/"/g, "\"\"") + "\"", m = n?.kind === "group" ? n.columns.map((e, t) => `key${t}`) : n?.kind === "window" ? ["identity", ...(n.carryColumns ?? []).map((e, t) => `carry${t}`)] : [], h = m.length === 0 ? "" : m.join(",") + ",", g = n?.kind === "group" ? n.columns.map((e, t) => `${p(e)} AS key${t}`).join(",") : n?.kind === "window" ? [`${p(n.identity)} AS identity`, ...(n.carryColumns ?? []).map((e, t) => `${p(e)} AS carry${t}`)].join(",") : "", _ = n?.kind === "group" && n.columns.length > 0 ? ` GROUP BY ${n.columns.map(p).join(",")}` : "", v = n?.kind === "window" ? [...n.partitionBy?.length ? [`PARTITION BY ${n.partitionBy.map(p).join(",")}`] : [], ...n.orderBy?.length ? [`ORDER BY ${n.orderBy.map((e) => `${p(e.column)} ${e.direction === "desc" ? "DESC" : "ASC"}`).join(",")}`] : []] : [], y = n?.kind === "window" ? ` OVER (${v.join(" ")})` : "";
|
|
2350
2457
|
f("decimal_source", e);
|
|
2351
2458
|
let b = Array.from({ length: s }, (e, t) => `d${t}`), x = b.map((e, n) => {
|
|
@@ -2368,13 +2475,13 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
2368
2475
|
f(`decimal_sub${e + 1}`, `SELECT ${h}hi,lo,sign,n,CASE WHEN ${n}<0 THEN 1 ELSE 0 END AS borrow,printf('%06d',(${n}+${a})%${a})||result AS result FROM ${d(`decimal_sub${e}`)}`);
|
|
2369
2476
|
}
|
|
2370
2477
|
return `${l.length ? `WITH ${l.join(",\n")} ` : ""}SELECT ${h}CASE WHEN n=0 THEN NULL WHEN ltrim(result,'0')='' THEN '0' ELSE sign||ltrim(result,'0') END AS units,CAST(n AS TEXT) AS count FROM ${d(`decimal_sub${E}`)}`;
|
|
2371
|
-
},
|
|
2478
|
+
}, Cr = (e) => {
|
|
2372
2479
|
let { precision: t, inputScale: n, resultScale: r, rounding: i, scope: a, materialized: o = !1, stages: s } = e;
|
|
2373
2480
|
if (!Number.isSafeInteger(n) || n < 0 || n > t || !Number.isSafeInteger(r) || r < 0) throw RangeError("Invalid decimal average scale");
|
|
2374
|
-
let c =
|
|
2481
|
+
let c = Sr(e), l = a?.kind === "group" ? a.columns.map((e, t) => `key${t}`) : a?.kind === "window" ? ["identity", ...(a.carryColumns ?? []).map((e, t) => `carry${t}`)] : [], u = l.length === 0 ? "" : l.join(",") + ",", d = r - n, f = Math.ceil((t + 20) / 6) * 6 + Math.max(d, 0), p = f + Math.min(d, 0), m = Math.ceil(p / 6) * 6, h = [];
|
|
2375
2482
|
if (s && !/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s.prefix)) throw Error("Invalid decimal stage prefix");
|
|
2376
2483
|
let g = (e) => (s?.prefix ?? "") + e, _ = (e) => s?.reference?.(g(e)) ?? g(e), v = (e, t) => {
|
|
2377
|
-
s ? s.append(g(e), t, o) : h.push(
|
|
2484
|
+
s ? s.append(g(e), t, o) : h.push(xr(e, t, o));
|
|
2378
2485
|
};
|
|
2379
2486
|
v("decimal_avg_sum", c), v("decimal_avg_input", `SELECT ${u}count,CASE WHEN substr(units,1,1)='-' THEN '-' ELSE '' END AS sign,${`COALESCE(ltrim(units,'-'),'0')||'${"0".repeat(Math.max(d, 0))}'`} AS magnitude FROM ${_("decimal_avg_sum")}`), v("decimal_avg_div0", `SELECT ${u}count,sign,substr('${"0".repeat(f)}',1,${f}-length(magnitude))||magnitude AS digits,CASE WHEN count='0' THEN 1 ELSE CAST(count AS INTEGER) END AS denominator,0 AS remainder,'' AS result FROM ${_("decimal_avg_input")}`);
|
|
2380
2487
|
let y = 0;
|
|
@@ -2394,8 +2501,8 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
2394
2501
|
v(`decimal_avg_round${e}`, `SELECT ${u}count,sign,quotient,${t}/1000000 AS carry,printf('%06d',${t}%1000000)||result AS result FROM ${_(`decimal_avg_round${e - 1}`)}`);
|
|
2395
2502
|
}
|
|
2396
2503
|
return `${h.length ? `WITH ${h.join(",\n")} ` : ""}SELECT ${u}CASE WHEN count='0' THEN NULL WHEN ltrim(result,'0')='' THEN '0' ELSE sign||ltrim(result,'0') END AS units,count FROM ${_(`decimal_avg_round${C}`)}`;
|
|
2397
|
-
},
|
|
2398
|
-
let o = e.aggregations ?? [],
|
|
2504
|
+
}, wr = (e, t, n, r, i, a) => {
|
|
2505
|
+
let o = yn(e), s = e.aggregations ?? [], c = {
|
|
2399
2506
|
"window-row-number": "ROW_NUMBER",
|
|
2400
2507
|
"window-rank": "RANK",
|
|
2401
2508
|
"window-dense-rank": "DENSE_RANK",
|
|
@@ -2404,179 +2511,194 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
2404
2511
|
"window-sum-over": "SUM",
|
|
2405
2512
|
"window-avg-over": "AVG"
|
|
2406
2513
|
};
|
|
2407
|
-
if (e.groupBy?.length || e.having || e.setOp || e.ctes || e.distinctOn || e.annClause || e.spatialClause || e.fullTextSearch ||
|
|
2408
|
-
if (new Set(
|
|
2409
|
-
let
|
|
2514
|
+
if (e.groupBy?.length || e.having || e.setOp || e.ctes || e.distinctOn || e.annClause || e.spatialClause || e.fullTextSearch || s.some((e) => e.op !== "column" && !(e.op in c))) throw Error("Exact window queries require supported ungrouped window projections");
|
|
2515
|
+
if (new Set(s.map((e) => e.alias)).size !== s.length) throw Error("Duplicate decimal result alias");
|
|
2516
|
+
let l = [...new Set(s.flatMap((e) => [
|
|
2410
2517
|
...e.column === void 0 ? [] : [e.column],
|
|
2411
2518
|
...e.window?.partitionBy ?? [],
|
|
2412
2519
|
...(e.window?.orderBy ?? []).map((e) => e.column)
|
|
2413
|
-
]))].map((
|
|
2414
|
-
let
|
|
2415
|
-
if (!
|
|
2520
|
+
]))].map((e, t) => {
|
|
2521
|
+
let n = o(e);
|
|
2522
|
+
if (!n) throw Error("Exact window requires declared source columns");
|
|
2416
2523
|
return {
|
|
2417
|
-
source:
|
|
2418
|
-
name: `c${
|
|
2419
|
-
field:
|
|
2524
|
+
source: e,
|
|
2525
|
+
name: `c${t}`,
|
|
2526
|
+
field: n
|
|
2420
2527
|
};
|
|
2421
|
-
}), l = (e) => {
|
|
2422
|
-
let t =
|
|
2528
|
+
}), u = new Map(l.map((e) => [e.source, e])), d = (e) => {
|
|
2529
|
+
let t = u.get(e);
|
|
2423
2530
|
if (!t) throw Error("Unknown exact window source column");
|
|
2424
2531
|
return t.name;
|
|
2425
|
-
},
|
|
2426
|
-
for (;
|
|
2427
|
-
let
|
|
2428
|
-
|
|
2532
|
+
}, f = (e) => "\"" + e.replace(/"/g, "\"\"") + "\"", { from: p, where: m } = yr(e, t, r), [h, g] = t`SELECT ${t.join(", ", !1)([t`ROW_NUMBER() OVER () AS identity`, ...l.map((e) => t`${t(e.source)} AS ${t(e.name)}`)])} FROM ${p}${m}`.compile(), _ = i ?? a, v = _?.prefix ?? "__voltro_decimal_window_", y = [e.table, ...(e.joins ?? []).map((e) => e.table)];
|
|
2533
|
+
for (; y.some((e) => e.toLowerCase().startsWith(v));) v += "_";
|
|
2534
|
+
let b = [], x = (e, t, n) => {
|
|
2535
|
+
_ ? _.append(e, t) : b.push(`${e} AS MATERIALIZED (${t})`);
|
|
2536
|
+
};
|
|
2537
|
+
x(v + "source", h, n.materialized);
|
|
2538
|
+
let S = [], C = /* @__PURE__ */ new Map(), w, T = !1, E = (t) => {
|
|
2539
|
+
if (!T) {
|
|
2540
|
+
T = !0;
|
|
2541
|
+
let t = e.order;
|
|
2542
|
+
if (t.length >= 32 && Object.getPrototypeOf(t) === Array.prototype && !Object.hasOwn(t, "some") && !Object.hasOwn(t, Symbol.iterator)) {
|
|
2543
|
+
let e = [];
|
|
2544
|
+
for (let n = 0; n < t.length; n++) {
|
|
2545
|
+
let r = Object.getOwnPropertyDescriptor(t, String(n)), i = r && "value" in r ? Object.getOwnPropertyDescriptor(r.value, "column") : void 0;
|
|
2546
|
+
if (!i || !("value" in i) || typeof i.value != "string") break;
|
|
2547
|
+
e.push(i.value);
|
|
2548
|
+
}
|
|
2549
|
+
e.length === t.length && (w = new Set(e));
|
|
2550
|
+
}
|
|
2551
|
+
}
|
|
2552
|
+
return w?.has(t) ?? e.order.some((e) => e.column === t);
|
|
2429
2553
|
};
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
key: o.name,
|
|
2439
|
-
encoded: o.field
|
|
2554
|
+
for (let [e, t] of s.entries()) {
|
|
2555
|
+
let r = `SELECT * FROM ${v}source`, a = t.column === void 0 ? void 0 : u.get(t.column);
|
|
2556
|
+
if (t.op === "column") {
|
|
2557
|
+
if (!a) throw Error("Window column projection requires a source column");
|
|
2558
|
+
C.set(t.alias, {
|
|
2559
|
+
value: a.name,
|
|
2560
|
+
key: a.name,
|
|
2561
|
+
encoded: a.field
|
|
2440
2562
|
});
|
|
2441
2563
|
continue;
|
|
2442
2564
|
}
|
|
2443
|
-
let
|
|
2565
|
+
let o = [
|
|
2444
2566
|
"window-lag",
|
|
2445
2567
|
"window-lead",
|
|
2446
2568
|
"window-sum-over",
|
|
2447
2569
|
"window-avg-over"
|
|
2448
|
-
].includes(
|
|
2449
|
-
if (
|
|
2450
|
-
let
|
|
2570
|
+
].includes(t.op);
|
|
2571
|
+
if (o && !a) throw Error("Window operation requires a source column");
|
|
2572
|
+
let s = t.window?.partitionBy?.map(d), l = t.window?.orderBy?.map((e) => ({
|
|
2451
2573
|
...e,
|
|
2452
|
-
column:
|
|
2453
|
-
})),
|
|
2454
|
-
if (
|
|
2455
|
-
let
|
|
2574
|
+
column: d(e.column)
|
|
2575
|
+
})), p = `w${e}`, m = J(a?.field) && ["window-sum-over", "window-avg-over"].includes(t.op);
|
|
2576
|
+
if (m) {
|
|
2577
|
+
let o = a.field.precision, c = a.field.scale, u = t.op === "window-avg-over" ? n.resultScale ?? c : c, d = o + 20 + Math.max(0, u - c), m = {
|
|
2456
2578
|
kind: "window",
|
|
2457
2579
|
identity: "identity",
|
|
2458
|
-
partitionBy:
|
|
2459
|
-
orderBy:
|
|
2460
|
-
},
|
|
2461
|
-
prefix: `${
|
|
2580
|
+
partitionBy: s ?? [],
|
|
2581
|
+
orderBy: l ?? []
|
|
2582
|
+
}, h = /* @__PURE__ */ new Map(), g = 0, _ = {
|
|
2583
|
+
prefix: `${v}${e}_`,
|
|
2462
2584
|
reference: (e) => {
|
|
2463
|
-
let t =
|
|
2585
|
+
let t = h.get(e);
|
|
2464
2586
|
return t === void 0 ? e : `(${t}${t.endsWith("LIMIT -1 OFFSET 0") ? "" : " LIMIT -1 OFFSET 0"}) AS ${e}`;
|
|
2465
2587
|
},
|
|
2466
2588
|
append: (e, t, r) => {
|
|
2467
|
-
n.materialized || ++
|
|
2589
|
+
n.materialized || ++g % 4 == 0 ? x(e, t, r) : h.set(e, t);
|
|
2468
2590
|
}
|
|
2469
|
-
},
|
|
2470
|
-
stages:
|
|
2471
|
-
sourceSql: `SELECT *,${
|
|
2472
|
-
precision:
|
|
2473
|
-
scope:
|
|
2591
|
+
}, y = {
|
|
2592
|
+
stages: _,
|
|
2593
|
+
sourceSql: `SELECT *,${f(a.name)} AS value FROM (${r})`,
|
|
2594
|
+
precision: o,
|
|
2595
|
+
scope: m,
|
|
2474
2596
|
materialized: n.materialized
|
|
2475
|
-
},
|
|
2476
|
-
...
|
|
2597
|
+
}, b = t.op === "window-avg-over" ? Cr({
|
|
2598
|
+
...y,
|
|
2477
2599
|
inputScale: c,
|
|
2478
|
-
resultScale:
|
|
2600
|
+
resultScale: u,
|
|
2479
2601
|
rounding: n.rounding ?? "half-even"
|
|
2480
|
-
}) :
|
|
2602
|
+
}) : Sr(y);
|
|
2481
2603
|
if (i) {
|
|
2482
|
-
let e =
|
|
2604
|
+
let e = Cn(`SELECT identity,units AS value FROM (${b})`, {
|
|
2483
2605
|
precision: d,
|
|
2484
2606
|
scale: 0
|
|
2485
2607
|
}, ["identity"], {
|
|
2486
|
-
prefix:
|
|
2487
|
-
reference:
|
|
2488
|
-
append: (e, t) =>
|
|
2608
|
+
prefix: _.prefix,
|
|
2609
|
+
reference: _.reference,
|
|
2610
|
+
append: (e, t) => _.append(e, t, n.materialized)
|
|
2489
2611
|
});
|
|
2490
|
-
|
|
2491
|
-
value:
|
|
2492
|
-
key:
|
|
2612
|
+
r = `SELECT identity,value AS ${f(p)} FROM ${e}`, C.set(t.alias, {
|
|
2613
|
+
value: p,
|
|
2614
|
+
key: p,
|
|
2493
2615
|
encoded: {
|
|
2494
|
-
...
|
|
2616
|
+
...a.field,
|
|
2495
2617
|
precision: d,
|
|
2496
|
-
scale:
|
|
2618
|
+
scale: u
|
|
2497
2619
|
}
|
|
2498
2620
|
});
|
|
2499
2621
|
} else {
|
|
2500
|
-
let
|
|
2501
|
-
sourceSql:
|
|
2622
|
+
let e = hr({
|
|
2623
|
+
sourceSql: b,
|
|
2502
2624
|
digits: d,
|
|
2503
|
-
scale:
|
|
2625
|
+
scale: u,
|
|
2504
2626
|
materialized: n.materialized,
|
|
2505
|
-
stages:
|
|
2506
|
-
}), i =
|
|
2507
|
-
|
|
2508
|
-
value:
|
|
2509
|
-
key: i ?
|
|
2627
|
+
stages: _
|
|
2628
|
+
}), i = E(t.alias);
|
|
2629
|
+
r = `SELECT identity,decimal_value AS ${f(p)}${i ? `,decimal_key AS ${f(p + "_key")}` : ""} FROM (${e})`, C.set(t.alias, {
|
|
2630
|
+
value: p,
|
|
2631
|
+
key: i ? p + "_key" : p
|
|
2510
2632
|
});
|
|
2511
2633
|
}
|
|
2512
2634
|
} else {
|
|
2513
|
-
let
|
|
2514
|
-
if (
|
|
2515
|
-
let
|
|
2516
|
-
if (
|
|
2517
|
-
let
|
|
2518
|
-
if (
|
|
2635
|
+
let i = [...s?.length ? [`PARTITION BY ${s.map(f).join(",")}`] : [], ...l?.length ? [`ORDER BY ${l.map((e) => `${f(e.column)} ${e.direction === "desc" ? "DESC" : "ASC"}`).join(",")}`] : []].join(" "), u = t.op === "window-lag" || t.op === "window-lead", d = t.offset ?? 1;
|
|
2636
|
+
if (u && (!Number.isSafeInteger(d) || d < 0)) throw Error("Invalid exact window offset");
|
|
2637
|
+
let m = o ? f(a.name) + (u ? `,${d}` : "") : "";
|
|
2638
|
+
if (t.op === "window-rank" || t.op === "window-dense-rank") {
|
|
2639
|
+
let a = [.../* @__PURE__ */ new Set([...s ?? [], ...(l ?? []).map((e) => e.column)])], o = a.length ? `PARTITION BY ${a.map(f).join(",")}` : "";
|
|
2640
|
+
if (t.op === "window-rank") r = `SELECT *,COUNT(*) OVER (${i})-COUNT(*) OVER (${o})+1 AS ${f(p)} FROM (${r})`;
|
|
2519
2641
|
else {
|
|
2520
|
-
let
|
|
2521
|
-
|
|
2642
|
+
let t = `${p}_peer`, a = `${v}peer${e}`;
|
|
2643
|
+
x(a, `SELECT *,CASE WHEN ROW_NUMBER() OVER (${o})=1 THEN 1 ELSE 0 END AS ${f(t)} FROM (${r})`, n.materialized), r = `SELECT *,SUM(${f(t)}) OVER (${i}) AS ${f(p)} FROM ${a}`;
|
|
2522
2644
|
}
|
|
2523
|
-
} else if (
|
|
2524
|
-
let
|
|
2525
|
-
|
|
2526
|
-
let
|
|
2527
|
-
|
|
2528
|
-
} else
|
|
2529
|
-
|
|
2530
|
-
value:
|
|
2531
|
-
key:
|
|
2532
|
-
...
|
|
2645
|
+
} else if (u) {
|
|
2646
|
+
let i = `${p}_position`, o = `${v}shift${e}`;
|
|
2647
|
+
x(o, `SELECT *,ROW_NUMBER() OVER (${[...s?.length ? [`PARTITION BY ${s.map(f).join(",")}`] : [], `ORDER BY ${[...(l ?? []).map((e) => `${f(e.column)} ${e.direction === "desc" ? "DESC" : "ASC"}`), "identity ASC"].join(",")}`].join(" ")}) AS ${f(i)} FROM (${r})`, n.materialized);
|
|
2648
|
+
let c = [...(s ?? []).map((e) => `shifted.${f(e)} IS current.${f(e)}`), `shifted.${f(i)}=current.${f(i)}${t.op === "window-lag" ? "-" : "+"}${d}`].join(" AND ");
|
|
2649
|
+
r = `SELECT current.*,(SELECT shifted.${f(a.name)} FROM ${o} AS shifted WHERE ${c}) AS ${f(p)} FROM ${o} AS current`;
|
|
2650
|
+
} else r = `SELECT *,${c[t.op]}(${m}) OVER (${i}) AS ${f(p)} FROM (${r}) LIMIT -1 OFFSET 0`;
|
|
2651
|
+
C.set(t.alias, {
|
|
2652
|
+
value: p,
|
|
2653
|
+
key: p,
|
|
2654
|
+
...u ? { encoded: a.field } : {}
|
|
2533
2655
|
});
|
|
2534
2656
|
}
|
|
2535
|
-
let
|
|
2536
|
-
|
|
2537
|
-
stage:
|
|
2538
|
-
values:
|
|
2657
|
+
let h = `${v}stage${e}`, g = m && C.get(t.alias).key !== p ? [p, p + "_key"] : [p];
|
|
2658
|
+
x(h, m ? r : `SELECT identity,${g.map(f).join(",")} FROM (${r})`, n.materialized), S.push({
|
|
2659
|
+
stage: h,
|
|
2660
|
+
values: g
|
|
2539
2661
|
});
|
|
2540
2662
|
}
|
|
2541
|
-
let
|
|
2542
|
-
|
|
2543
|
-
let
|
|
2663
|
+
let D = `${v}output`;
|
|
2664
|
+
x(D, `SELECT ${["input.*", ...S.flatMap((e) => e.values.map((t) => `(SELECT result.${f(t)} FROM ${e.stage} AS result WHERE result.identity=input.identity) AS ${f(t)}`))].join(",")} FROM ${v}source AS input`, n.materialized);
|
|
2665
|
+
let O = new Map([...C.values()].flatMap((e) => J(e.encoded) ? [[e.value, {
|
|
2544
2666
|
name: e.value,
|
|
2545
2667
|
shape: {
|
|
2546
2668
|
precision: e.encoded.precision,
|
|
2547
2669
|
scale: e.encoded.scale
|
|
2548
2670
|
}
|
|
2549
|
-
}]] : [])),
|
|
2671
|
+
}]] : [])), k = fr(D, i ? [] : [...O.values()], [
|
|
2550
2672
|
"identity",
|
|
2551
|
-
...
|
|
2552
|
-
...
|
|
2673
|
+
...l.map((e) => e.name),
|
|
2674
|
+
...S.flatMap((e) => e.values)
|
|
2553
2675
|
], {
|
|
2554
|
-
prefix: `${
|
|
2555
|
-
append: (e, t) =>
|
|
2556
|
-
}),
|
|
2557
|
-
let t =
|
|
2558
|
-
return i &&
|
|
2559
|
-
}),
|
|
2560
|
-
let t =
|
|
2676
|
+
prefix: `${v}result_`,
|
|
2677
|
+
append: (e, t) => x(e, t, n.materialized)
|
|
2678
|
+
}), ee = s.map((e) => {
|
|
2679
|
+
let t = C.get(e.alias), n = `window_output.${f(t.value)}`;
|
|
2680
|
+
return i && J(t.encoded) ? (i.encodedOutput(e.alias), `${n} AS ${f(e.alias)}`) : `${k.values.get(t.value) ?? (t.encoded?.type === "bigint" ? `CAST(${n} AS TEXT)` : n)} AS ${f(e.alias)}`;
|
|
2681
|
+
}), A = e.order.length ? " ORDER BY " + e.order.map((e) => {
|
|
2682
|
+
let t = C.get(e.column);
|
|
2561
2683
|
if (!t) throw Error("Ordering references an unknown window result");
|
|
2562
|
-
return `window_output.${
|
|
2684
|
+
return `window_output.${f(t.key)} ${e.direction === "desc" ? "DESC" : "ASC"}`;
|
|
2563
2685
|
}).join(",") : "";
|
|
2564
2686
|
for (let t of [e.take, e.skip]) if (t !== void 0 && (!Number.isSafeInteger(t) || t < 0)) throw Error("Invalid exact decimal pagination");
|
|
2565
|
-
let
|
|
2566
|
-
return t.unsafe(`${
|
|
2567
|
-
},
|
|
2687
|
+
let j = e.take === void 0 ? e.skip === void 0 ? "" : " LIMIT -1" : ` LIMIT ${e.take}`, M = e.skip === void 0 ? "" : ` OFFSET ${e.skip}`;
|
|
2688
|
+
return t.unsafe(`${_ ? "" : `WITH ${b.join(",")} `}SELECT ${e.distinct ? "DISTINCT " : ""}${ee.join(",")} FROM ${k.source} AS window_output${A}${j}${M}`, g);
|
|
2689
|
+
}, Tr = (e, t, n, r, i, a) => {
|
|
2568
2690
|
if (!t.onDialectOrElse({
|
|
2569
2691
|
sqlite: () => !0,
|
|
2570
2692
|
orElse: () => !1
|
|
2571
2693
|
})) throw Error("Encoded decimal query integration requires a SQLite-family compiler");
|
|
2572
|
-
if (e.ctes?.length) return
|
|
2573
|
-
if (e.setOp) return
|
|
2694
|
+
if (e.ctes?.length) return Dn(e, t, n.resultScale, (e, i, a) => Tr(e, t, n, r, i, a));
|
|
2695
|
+
if (e.setOp) return sr(e, t, n, (e) => Tr(e, t, n, r));
|
|
2574
2696
|
let o = {
|
|
2575
|
-
compile: (e) =>
|
|
2697
|
+
compile: (e) => Tr(e, t, n, r),
|
|
2576
2698
|
resultScale: n.resultScale,
|
|
2577
2699
|
sourceTable: r
|
|
2578
2700
|
}, s = e.aggregations ?? [];
|
|
2579
|
-
if (s.length > 0 && s.every((e) => e.op === "column") && !e.groupBy?.length && !e.having || s.some((e) => e.op.startsWith("window-"))) return
|
|
2701
|
+
if (s.length > 0 && s.every((e) => e.op === "column") && !e.groupBy?.length && !e.having || s.some((e) => e.op.startsWith("window-"))) return wr(e, t, n, o, i, a);
|
|
2580
2702
|
let c = s.length === 0, l = s.filter((e) => e.op !== "column"), u = !c && l.length === 0, d = {
|
|
2581
2703
|
sum: "SUM",
|
|
2582
2704
|
avg: "AVG",
|
|
@@ -2587,55 +2709,58 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
2587
2709
|
};
|
|
2588
2710
|
if (u && !e.groupBy?.length || l.some((e) => !(e.op in d)) || e.setOp || e.distinctOn || e.ctes || e.annClause || e.spatialClause || e.fullTextSearch) throw Error("Exact decimal query integration requires supported grouped aggregate projections");
|
|
2589
2711
|
if (new Set(s.map((e) => e.alias)).size !== s.length) throw Error("Duplicate decimal result alias");
|
|
2590
|
-
let f = e.groupBy ?? [];
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
for (
|
|
2595
|
-
let m
|
|
2712
|
+
let f = yn(e), p = e.groupBy ?? [], m = /* @__PURE__ */ new Map();
|
|
2713
|
+
p.forEach((e, t) => {
|
|
2714
|
+
m.has(e) || m.set(e, t);
|
|
2715
|
+
});
|
|
2716
|
+
for (let e of p) if (f(e) === void 0) throw Error("Exact decimal grouping requires declared source columns");
|
|
2717
|
+
for (let e of s) if (e.op === "column" && !m.has(e.column ?? "")) throw Error("Projected group column is absent from GROUP BY");
|
|
2718
|
+
let h = "__decimal_group_identity";
|
|
2719
|
+
for (; s.some((e) => e.alias === h);) h += "_";
|
|
2720
|
+
let g = [...(u ? [{
|
|
2596
2721
|
op: "count",
|
|
2597
|
-
alias:
|
|
2722
|
+
alias: h
|
|
2598
2723
|
}] : l).map((e) => ({
|
|
2599
2724
|
aggregate: e,
|
|
2600
2725
|
projection: e
|
|
2601
|
-
})), ...s.filter((
|
|
2726
|
+
})), ...s.filter((e) => e.op === "column" && J(f(e.column ?? ""))).map((e) => ({
|
|
2602
2727
|
aggregate: {
|
|
2603
2728
|
...e,
|
|
2604
2729
|
op: "min"
|
|
2605
2730
|
},
|
|
2606
2731
|
projection: e
|
|
2607
|
-
}))].map(({ aggregate:
|
|
2608
|
-
if (
|
|
2609
|
-
let
|
|
2610
|
-
if (
|
|
2611
|
-
let
|
|
2612
|
-
if (
|
|
2613
|
-
let
|
|
2732
|
+
}))].map(({ aggregate: e, projection: t }, r) => {
|
|
2733
|
+
if (e.column === void 0 && e.op !== "count") throw Error("Aggregate requires a source column");
|
|
2734
|
+
let i = f(e.column ?? "");
|
|
2735
|
+
if (e.column !== void 0 && i === void 0) throw Error("Aggregate requires a declared source column");
|
|
2736
|
+
let a = J(i) && !e.op.startsWith("count");
|
|
2737
|
+
if (a && (i.precision === void 0 || i.scale === void 0)) throw Error("Exact decimal aggregate requires declared precision and scale");
|
|
2738
|
+
let o = a ? i.precision : 0, s = a ? i.scale : 0, c = e.op === "avg" ? n.resultScale ?? s : s;
|
|
2614
2739
|
return {
|
|
2615
|
-
aggregate:
|
|
2616
|
-
projection:
|
|
2617
|
-
index:
|
|
2618
|
-
exact:
|
|
2619
|
-
precision:
|
|
2620
|
-
inputScale:
|
|
2621
|
-
scale:
|
|
2622
|
-
digits:
|
|
2740
|
+
aggregate: e,
|
|
2741
|
+
projection: t,
|
|
2742
|
+
index: r,
|
|
2743
|
+
exact: a,
|
|
2744
|
+
precision: o,
|
|
2745
|
+
inputScale: s,
|
|
2746
|
+
scale: c,
|
|
2747
|
+
digits: o + 20 + Math.max(0, c - s)
|
|
2623
2748
|
};
|
|
2624
|
-
}),
|
|
2625
|
-
let n =
|
|
2626
|
-
if (n) return
|
|
2627
|
-
let r =
|
|
2749
|
+
}), _ = new Map(g.map((e) => [e.projection, e])), v = new Map(g.map((e) => [e.projection.alias, e])), y = /* @__PURE__ */ new Map(), b = s.map((e) => {
|
|
2750
|
+
let n = _.get(e);
|
|
2751
|
+
if (n) return y.set(e.alias, `result${n.index}.${n.exact ? "decimal_key" : "result_value"}`), t`${t(`result${n.index}.${n.exact ? "decimal_value" : "result_value"}`)} AS ${t(e.alias)}`;
|
|
2752
|
+
let r = m.get(e.column ?? "") ?? -1;
|
|
2628
2753
|
if (r < 0) throw Error("Projected group column is absent from GROUP BY");
|
|
2629
|
-
return
|
|
2630
|
-
}),
|
|
2631
|
-
if ("and" in e) return { and: e.and.map(
|
|
2632
|
-
if ("or" in e) return { or: e.or.map(
|
|
2633
|
-
if ("not" in e) return { not:
|
|
2754
|
+
return y.set(e.alias, `result0.key${r}`), t`${t(`result0.key${r}`)} AS ${t(e.alias)}`;
|
|
2755
|
+
}), x = (e) => {
|
|
2756
|
+
if ("and" in e) return { and: e.and.map(x) };
|
|
2757
|
+
if ("or" in e) return { or: e.or.map(x) };
|
|
2758
|
+
if ("not" in e) return { not: x(e.not) };
|
|
2634
2759
|
if ("subquery" in e || !("column" in e) || !("op" in e)) throw Error("Decimal subquery predicates are not integrated yet");
|
|
2635
|
-
if (
|
|
2636
|
-
let t =
|
|
2760
|
+
if (Hn(e.value)) throw Error("Column references require result comparison lowering");
|
|
2761
|
+
let t = v.get(e.column), n = y.get(e.column);
|
|
2637
2762
|
if (n === void 0) throw Error("HAVING references an unknown projected aggregate or group key");
|
|
2638
|
-
return t?.exact ?
|
|
2763
|
+
return t?.exact ? _r({
|
|
2639
2764
|
...e,
|
|
2640
2765
|
column: n
|
|
2641
2766
|
}, {
|
|
@@ -2645,58 +2770,58 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
2645
2770
|
...e,
|
|
2646
2771
|
column: n
|
|
2647
2772
|
};
|
|
2648
|
-
},
|
|
2773
|
+
}, S = [...g.flatMap((e) => e.aggregate.column === void 0 ? [] : [{
|
|
2649
2774
|
source: e.aggregate.column,
|
|
2650
2775
|
outputKey: `value${e.index}`
|
|
2651
|
-
}]), ...
|
|
2776
|
+
}]), ...p.map((e, t) => ({
|
|
2652
2777
|
source: e,
|
|
2653
2778
|
outputKey: `group${t}`
|
|
2654
|
-
}))],
|
|
2655
|
-
if (c) return
|
|
2656
|
-
let
|
|
2657
|
-
let { aggregate: t, index: r, precision: i, inputScale: a, scale: o, digits: s } = e, c = t.column === void 0 ? "*" :
|
|
2658
|
-
if (!e.exact) return `SELECT ${
|
|
2779
|
+
}))], C = S.length ? t.join(", ", !1)(S.map((e) => t`${t(e.source)} AS ${t(e.outputKey)}`)) : t`1 AS decimal_query_row`, { from: w, where: T } = yr(e, t, o);
|
|
2780
|
+
if (c) return br(e, t, o, i, a);
|
|
2781
|
+
let E = t`SELECT ${C} FROM ${w}${T}`.compile(), D = (e) => "\"" + e.replace(/"/g, "\"\"") + "\"", O = p.map((e, t) => `group${t}`), k = O.map((e, t) => `${D(e)} AS ${D(`key${t}`)}`).join(","), ee = O.length ? ` GROUP BY ${O.map(D).join(",")}` : "", A = n.materialized ? "decimal_query_source" : `(${E[0]})`, j = g.map((e) => {
|
|
2782
|
+
let { aggregate: t, index: r, precision: i, inputScale: a, scale: o, digits: s } = e, c = t.column === void 0 ? "*" : D(`value${r}`);
|
|
2783
|
+
if (!e.exact) return `SELECT ${k ? k + "," : ""}${d[t.op]}(${t.op === "count-distinct" ? "DISTINCT " : ""}${c}) AS result_value FROM ${A}${ee}`;
|
|
2659
2784
|
let l = {
|
|
2660
|
-
sourceSql: t.op === "min" || t.op === "max" ? `SELECT ${
|
|
2785
|
+
sourceSql: t.op === "min" || t.op === "max" ? `SELECT ${O.length ? O.map(D).join(",") + "," : ""}${d[t.op]}(${c}) AS value FROM ${A}${ee}` : `SELECT ${O.length ? O.map(D).join(",") + "," : ""}${c} AS value FROM ${A}`,
|
|
2661
2786
|
precision: i,
|
|
2662
2787
|
materialized: n.materialized,
|
|
2663
|
-
...
|
|
2788
|
+
...p.length ? { scope: {
|
|
2664
2789
|
kind: "group",
|
|
2665
|
-
columns:
|
|
2790
|
+
columns: O
|
|
2666
2791
|
} } : {}
|
|
2667
2792
|
};
|
|
2668
|
-
return
|
|
2669
|
-
sourceSql: t.op === "avg" ?
|
|
2793
|
+
return hr({
|
|
2794
|
+
sourceSql: t.op === "avg" ? Cr({
|
|
2670
2795
|
...l,
|
|
2671
2796
|
inputScale: a,
|
|
2672
2797
|
resultScale: o,
|
|
2673
2798
|
rounding: n.rounding ?? "half-even"
|
|
2674
|
-
}) :
|
|
2799
|
+
}) : Sr(l),
|
|
2675
2800
|
digits: s,
|
|
2676
2801
|
scale: o,
|
|
2677
2802
|
materialized: n.materialized
|
|
2678
2803
|
});
|
|
2679
|
-
}),
|
|
2804
|
+
}), M = [...n.materialized ? [`decimal_query_source AS MATERIALIZED (${E[0]})`] : [], ...j.map((e, t) => {
|
|
2680
2805
|
let r = n.materialized ? e : `SELECT * FROM (${e}) LIMIT -1 OFFSET 0`;
|
|
2681
2806
|
return `result${t} AS${n.materialized ? " MATERIALIZED" : ""} (${r})`;
|
|
2682
|
-
})].join(","),
|
|
2683
|
-
if ("not" in e) return t`NOT (${
|
|
2684
|
-
if ("and" in e) return e.and.length ? t.and(e.and.map(
|
|
2685
|
-
if ("or" in e) return e.or.length ? t.or(e.or.map(
|
|
2686
|
-
if ("subquery" in e) return
|
|
2687
|
-
let n =
|
|
2807
|
+
})].join(","), N = g.slice(1).map((e) => p.length ? ` JOIN result${e.index} ON ${p.map((t, n) => `result0.${D(`key${n}`)} IS result${e.index}.${D(`key${n}`)}`).join(" AND ")}` : ` CROSS JOIN result${e.index}`).join(""), P = (e) => {
|
|
2808
|
+
if ("not" in e) return t`NOT (${P(e.not)})`;
|
|
2809
|
+
if ("and" in e) return e.and.length ? t.and(e.and.map(P)) : t`TRUE`;
|
|
2810
|
+
if ("or" in e) return e.or.length ? t.or(e.or.map(P)) : t`FALSE`;
|
|
2811
|
+
if ("subquery" in e) return or(e, t, o, (e) => {
|
|
2812
|
+
let n = y.get(e);
|
|
2688
2813
|
if (!n) throw Error("HAVING references an unknown projected aggregate or group key");
|
|
2689
|
-
let r =
|
|
2814
|
+
let r = v.get(e);
|
|
2690
2815
|
return r?.exact ? {
|
|
2691
2816
|
value: t`${t(`result${r.index}.decimal_value`)}`,
|
|
2692
2817
|
scale: r.scale
|
|
2693
2818
|
} : { value: t`${t(n)}` };
|
|
2694
2819
|
});
|
|
2695
|
-
if (!("value" in e) || !
|
|
2696
|
-
let n =
|
|
2820
|
+
if (!("value" in e) || !Hn(e.value)) return Kr(x(e), t);
|
|
2821
|
+
let n = y.get(e.column), r = y.get(e.value.column);
|
|
2697
2822
|
if (n === void 0 || r === void 0) throw Error("HAVING references an unknown projected aggregate or group key");
|
|
2698
|
-
let i =
|
|
2699
|
-
if (!i?.exact && !s?.exact) return
|
|
2823
|
+
let i = v.get(e.column), a = e.value.column, s = v.get(a);
|
|
2824
|
+
if (!i?.exact && !s?.exact) return Kr({
|
|
2700
2825
|
...e,
|
|
2701
2826
|
column: n,
|
|
2702
2827
|
value: {
|
|
@@ -2705,8 +2830,8 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
2705
2830
|
}
|
|
2706
2831
|
}, t);
|
|
2707
2832
|
if (!i?.exact || !s?.exact) throw Error("Exact aggregate comparisons require two decimal results");
|
|
2708
|
-
if (!
|
|
2709
|
-
return t.unsafe(
|
|
2833
|
+
if (!Un.includes(e.op) || e.path?.length) throw Error("Unsupported exact decimal result comparison");
|
|
2834
|
+
return t.unsafe(gr({
|
|
2710
2835
|
expression: t`${t(n)}`.compile()[0],
|
|
2711
2836
|
digits: i.digits,
|
|
2712
2837
|
scale: i.scale
|
|
@@ -2715,36 +2840,36 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
2715
2840
|
digits: s.digits,
|
|
2716
2841
|
scale: s.scale
|
|
2717
2842
|
}));
|
|
2718
|
-
},
|
|
2719
|
-
let n =
|
|
2843
|
+
}, F = e.having === void 0 ? t`` : t` WHERE ${P(e.having)}`, te = e.order.length === 0 ? t`` : t` ORDER BY ${t.join(", ", !1)(e.order.map((e) => {
|
|
2844
|
+
let n = y.get(e.column);
|
|
2720
2845
|
if (n === void 0) throw Error("Ordering references an unknown decimal result projection");
|
|
2721
2846
|
return e.direction === "desc" ? t`${t(n)} DESC` : t`${t(n)} ASC`;
|
|
2722
2847
|
}))}`;
|
|
2723
2848
|
for (let t of [e.take, e.skip]) if (t !== void 0 && (!Number.isSafeInteger(t) || t < 0)) throw Error("Invalid exact decimal pagination");
|
|
2724
|
-
let
|
|
2849
|
+
let I = e.take === void 0 ? e.skip === void 0 ? t`` : t` LIMIT -1` : t` LIMIT ${e.take}`, ne = e.skip === void 0 ? t`` : t` OFFSET ${e.skip}`, re = t`WITH ${t.unsafe(M)} SELECT ${e.distinct ? t`DISTINCT ` : t``}${t.join(", ", !1)(b)} FROM result0${t.unsafe(N)}${F}${te}${I}${ne}`.compile(), ie = n.materialized ? E[1] : g.flatMap(() => E[1]);
|
|
2725
2850
|
return t.unsafe(re[0], [...ie, ...re[1]]);
|
|
2726
|
-
},
|
|
2727
|
-
let i =
|
|
2728
|
-
return
|
|
2729
|
-
},
|
|
2851
|
+
}, Er = (e, t, n, r = null) => {
|
|
2852
|
+
let i = En(e, n.resultScale), a = new Set((i.ctes ?? []).map((e) => e.name));
|
|
2853
|
+
return Tr(i, t, n, (e) => a.has(e) ? e : er(r, e));
|
|
2854
|
+
}, Dr = (e) => e.replace(/[A-Z]/g, (e) => e.toLowerCase()), Or = (e, t) => {
|
|
2730
2855
|
let { strings: n, values: r } = e, i = t.unsafe(n[0] ?? "");
|
|
2731
2856
|
for (let e = 0; e < r.length; e++) i = t`${i}${r[e]}${t.unsafe(n[e + 1] ?? "")}`;
|
|
2732
2857
|
return t`${i}`;
|
|
2733
|
-
},
|
|
2734
|
-
if ("not" in e) return t`NOT (${
|
|
2735
|
-
if ("and" in e) return e.and.length === 0 ? t`TRUE` : t.and(e.and.map((e) =>
|
|
2736
|
-
if ("or" in e) return e.or.length === 0 ? t`FALSE` : t.or(e.or.map((e) =>
|
|
2858
|
+
}, kr = (e) => e.replace(/[\\%_]/g, (e) => `\\${e}`), $ = (e, t, n = null, r, i = /* @__PURE__ */ new Set()) => {
|
|
2859
|
+
if ("not" in e) return t`NOT (${$(e.not, t, n, r, i)})`;
|
|
2860
|
+
if ("and" in e) return e.and.length === 0 ? t`TRUE` : t.and(e.and.map((e) => $(e, t, n, r, i)));
|
|
2861
|
+
if ("or" in e) return e.or.length === 0 ? t`FALSE` : t.or(e.or.map((e) => $(e, t, n, r, i)));
|
|
2737
2862
|
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
2738
|
-
let r = e, a =
|
|
2863
|
+
let r = e, a = Wr(r.subquery, t, n, void 0, i);
|
|
2739
2864
|
return r.op === "subquery-in" ? t`${t(r.column)} IN (${a})` : t`${t(r.column)} NOT IN (${a})`;
|
|
2740
2865
|
}
|
|
2741
2866
|
if (e.op === "exists" || e.op === "not-exists") {
|
|
2742
|
-
let r = e, a =
|
|
2867
|
+
let r = e, a = Wr(r.subquery, t, n, void 0, i);
|
|
2743
2868
|
return r.op === "exists" ? t`EXISTS (${a})` : t`NOT EXISTS (${a})`;
|
|
2744
2869
|
}
|
|
2745
2870
|
let a = e;
|
|
2746
|
-
if (
|
|
2747
|
-
if (!
|
|
2871
|
+
if (Hn(a.value)) {
|
|
2872
|
+
if (!Un.some((e) => e === a.op) || a.path !== void 0) throw L("Column references require a scalar comparison without a JSON path");
|
|
2748
2873
|
let e = t(a.value.column), n = t(a.column);
|
|
2749
2874
|
switch (a.op) {
|
|
2750
2875
|
case "eq": return t`${n} = ${e}`;
|
|
@@ -2756,19 +2881,19 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
2756
2881
|
}
|
|
2757
2882
|
}
|
|
2758
2883
|
let o = t(a.column), s = a.path, c = s !== void 0 && s.length > 0, l = () => t.onDialectOrElse({
|
|
2759
|
-
mysql: () => t.unsafe(
|
|
2760
|
-
mssql: () => t.unsafe(
|
|
2761
|
-
sqlite: () => t.unsafe(
|
|
2762
|
-
orElse: () => t.unsafe(
|
|
2884
|
+
mysql: () => t.unsafe(Q(a.column, s, "mysql")),
|
|
2885
|
+
mssql: () => t.unsafe(Q(a.column, s, "mssql")),
|
|
2886
|
+
sqlite: () => t.unsafe(Q(a.column, s, "sqlite")),
|
|
2887
|
+
orElse: () => t.unsafe(Q(a.column, s, "postgres"))
|
|
2763
2888
|
}), u = () => t.onDialectOrElse({
|
|
2764
|
-
mysql: () => t.unsafe(
|
|
2765
|
-
mssql: () => t.unsafe(
|
|
2766
|
-
sqlite: () => t.unsafe(
|
|
2767
|
-
orElse: () => t.unsafe(
|
|
2768
|
-
}), d = c ? l() : o, f = c ? u() : o, p = (e) => c && e != null ? String(e) : e, m = (e) => c ? Number(e) : e, h = c || r === void 0 ? void 0 :
|
|
2769
|
-
let n =
|
|
2889
|
+
mysql: () => t.unsafe(Q(a.column, s, "mysql", { numeric: !0 })),
|
|
2890
|
+
mssql: () => t.unsafe(Q(a.column, s, "mssql", { numeric: !0 })),
|
|
2891
|
+
sqlite: () => t.unsafe(Q(a.column, s, "sqlite", { numeric: !0 })),
|
|
2892
|
+
orElse: () => t.unsafe(Q(a.column, s, "postgres", { numeric: !0 }))
|
|
2893
|
+
}), d = c ? l() : o, f = c ? u() : o, p = (e) => c && e != null ? String(e) : e, m = (e) => c ? Number(e) : e, h = c || r === void 0 ? void 0 : W(r)?.fields?.[a.column]?.type, g = (e) => {
|
|
2894
|
+
let n = rr(h, e);
|
|
2770
2895
|
return n instanceof Date ? t.onDialectOrElse({
|
|
2771
|
-
sqlite: () =>
|
|
2896
|
+
sqlite: () => Wn(n),
|
|
2772
2897
|
orElse: () => n
|
|
2773
2898
|
}) : n;
|
|
2774
2899
|
};
|
|
@@ -2788,7 +2913,7 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
2788
2913
|
return e.length === 0 ? t`TRUE` : t`${d} NOT IN ${t.in(c ? e.map((e) => p(e)) : e.map(g))}`;
|
|
2789
2914
|
}
|
|
2790
2915
|
case "contains": {
|
|
2791
|
-
let e = `%${
|
|
2916
|
+
let e = `%${kr(typeof a.value == "string" ? a.value : String(a.value ?? ""))}%`;
|
|
2792
2917
|
return t.onDialectOrElse({
|
|
2793
2918
|
mysql: () => t`LOWER(${d}) LIKE LOWER(${e})`,
|
|
2794
2919
|
mssql: () => t`LOWER(${d}) LIKE LOWER(${e})`,
|
|
@@ -2797,7 +2922,7 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
2797
2922
|
});
|
|
2798
2923
|
}
|
|
2799
2924
|
case "startsWith": {
|
|
2800
|
-
let e = `${
|
|
2925
|
+
let e = `${kr(typeof a.value == "string" ? a.value : String(a.value ?? ""))}%`;
|
|
2801
2926
|
return t.onDialectOrElse({
|
|
2802
2927
|
mysql: () => t`${d} LIKE ${e}`,
|
|
2803
2928
|
orElse: () => t`${d} LIKE ${e} ESCAPE '\\'`
|
|
@@ -2833,25 +2958,25 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
2833
2958
|
let e = a.value, n = t.unsafe("::geometry"), r = e.bufferMeters === void 0 ? t`${e.geom}${n}` : t`ST_Buffer(${e.geom}::geography, ${e.bufferMeters})::geometry`;
|
|
2834
2959
|
return t.onDialectOrElse({
|
|
2835
2960
|
mysql: () => {
|
|
2836
|
-
throw
|
|
2961
|
+
throw L("@voltro/plugin-postgis: spatial predicates are postgres-only");
|
|
2837
2962
|
},
|
|
2838
2963
|
mssql: () => {
|
|
2839
|
-
throw
|
|
2964
|
+
throw L("@voltro/plugin-postgis: spatial predicates are postgres-only");
|
|
2840
2965
|
},
|
|
2841
2966
|
sqlite: () => {
|
|
2842
|
-
throw
|
|
2967
|
+
throw L("@voltro/plugin-postgis: spatial predicates are postgres-only");
|
|
2843
2968
|
},
|
|
2844
2969
|
orElse: () => e.fn === "ST_DWithin" ? t`ST_DWithin(${o}::geography, ${e.geom}::geography, ${e.distanceMeters})` : e.fn === "&&" ? t`${o}${n} && ${r}` : t`${t.unsafe(e.fn)}(${o}${n}, ${r})`
|
|
2845
2970
|
});
|
|
2846
2971
|
}
|
|
2847
2972
|
}
|
|
2848
|
-
},
|
|
2973
|
+
}, Ar = (e, t) => {
|
|
2849
2974
|
let n = [];
|
|
2850
|
-
return e.partitionBy && e.partitionBy.length > 0 && n.push(t`PARTITION BY ${t.
|
|
2851
|
-
},
|
|
2975
|
+
return e.partitionBy && e.partitionBy.length > 0 && n.push(t`PARTITION BY ${t.join(", ", !1)(e.partitionBy.map((e) => t`${t(e)}`))}`), e.orderBy && e.orderBy.length > 0 && n.push(t`ORDER BY ${t.join(", ", !1)(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}`);
|
|
2976
|
+
}, jr = (e, t) => t.join(", ", !1)(e.map((e) => {
|
|
2852
2977
|
let n = e.column === void 0 ? t.unsafe("*") : t`${t(e.column)}`;
|
|
2853
2978
|
if (e.op.startsWith("window-")) {
|
|
2854
|
-
let r =
|
|
2979
|
+
let r = Ar(e.window ?? {}, t);
|
|
2855
2980
|
switch (e.op) {
|
|
2856
2981
|
case "window-row-number": return t`ROW_NUMBER() OVER (${r}) AS ${t(e.alias)}`;
|
|
2857
2982
|
case "window-rank": return t`RANK() OVER (${r}) AS ${t(e.alias)}`;
|
|
@@ -2860,7 +2985,7 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
2860
2985
|
case "window-lead": return t`LEAD(${n}, ${t.unsafe(String(e.offset ?? 1))}) OVER (${r}) AS ${t(e.alias)}`;
|
|
2861
2986
|
case "window-sum-over": return t`SUM(${n}) OVER (${r}) AS ${t(e.alias)}`;
|
|
2862
2987
|
case "window-avg-over": return t`AVG(${n}) OVER (${r}) AS ${t(e.alias)}`;
|
|
2863
|
-
default: throw
|
|
2988
|
+
default: throw L(`compileAggregateProjection: unknown window op '${e.op}'`);
|
|
2864
2989
|
}
|
|
2865
2990
|
}
|
|
2866
2991
|
switch (e.op) {
|
|
@@ -2871,167 +2996,169 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
2871
2996
|
case "min": return t`MIN(${n}) AS ${t(e.alias)}`;
|
|
2872
2997
|
case "max": return t`MAX(${n}) AS ${t(e.alias)}`;
|
|
2873
2998
|
case "column":
|
|
2874
|
-
if (e.column === void 0) throw
|
|
2999
|
+
if (e.column === void 0) throw L(`compileAggregateProjection: 'column' projection requires a column name (alias '${e.alias}')`);
|
|
2875
3000
|
return t`${t(e.column)} AS ${t(e.alias)}`;
|
|
2876
|
-
default: throw
|
|
3001
|
+
default: throw L(`compileAggregateProjection: unknown op '${e.op}'`);
|
|
2877
3002
|
}
|
|
2878
|
-
})),
|
|
3003
|
+
})), Mr = (e) => `[${e.join(",")}]`, Nr = (e, t) => {
|
|
2879
3004
|
if (e.queryVector === void 0) return null;
|
|
2880
|
-
let n = t(e.column), r =
|
|
3005
|
+
let n = t(e.column), r = Mr(e.queryVector), i = e.distance === "cosine" ? "<=>" : e.distance === "l2" ? "<->" : "<#>", a = e.distance === "cosine" ? "VEC_DISTANCE_COSINE" : "VEC_DISTANCE_EUCLIDEAN";
|
|
2881
3006
|
return t.onDialectOrElse({
|
|
2882
3007
|
mysql: () => t`${t.unsafe(a)}(${n}, ${r})`,
|
|
2883
3008
|
mssql: () => t`NULL`,
|
|
2884
3009
|
sqlite: () => t`NULL`,
|
|
2885
3010
|
orElse: () => t`${n} ${t.unsafe(i)} ${r}::vector`
|
|
2886
3011
|
});
|
|
2887
|
-
},
|
|
3012
|
+
}, Pr = (e, t) => {
|
|
2888
3013
|
let n = t.unsafe(e.useGeography ? "::geography" : "::geometry");
|
|
2889
3014
|
return t`ST_Distance(${t(e.column)}${n}, ${e.geom}${n})`;
|
|
2890
|
-
},
|
|
3015
|
+
}, Fr = (e, t) => t`${t(e.column)} <-> ${e.geom}::geometry`, Ir = (e, t) => t`${t(`${e.indexName}_tsv`)}`, Lr = (e, t) => `${t}_${e.indexName}_fts`, Rr = (e) => e.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter((e) => e !== ""), zr = (e) => {
|
|
2891
3016
|
if (e.prefix !== !0) return;
|
|
2892
|
-
let t =
|
|
3017
|
+
let t = Rr(e.query);
|
|
2893
3018
|
if (t.length !== 0) return {
|
|
2894
3019
|
pg: t.map((e) => `${e}:*`).join(" & "),
|
|
2895
3020
|
mysql: t.map((e) => `+${e}*`).join(" "),
|
|
2896
3021
|
sqlite: t.map((e) => `"${e}"*`).join(" ")
|
|
2897
3022
|
};
|
|
2898
|
-
},
|
|
2899
|
-
let r = n.
|
|
3023
|
+
}, Br = (e, t, n) => {
|
|
3024
|
+
let r = n.join(", ", !1)(e.columns.map((e) => n`${n(e)}`)), i = `%${kr(e.query)}%`, a = zr(e), o = () => n.or(e.columns.map((e) => n`LOWER(${n(e)}) LIKE LOWER(${i}) ESCAPE '\\'`));
|
|
2900
3025
|
return e.fallback === "like" ? o() : n.onDialectOrElse({
|
|
2901
3026
|
mysql: () => a === void 0 ? n`MATCH(${r}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)` : n`MATCH(${r}) AGAINST(${a.mysql} IN BOOLEAN MODE)`,
|
|
2902
3027
|
sqlite: () => {
|
|
2903
|
-
let r = n(
|
|
3028
|
+
let r = n(Lr(e, t));
|
|
2904
3029
|
return n`${n("id")} IN (SELECT ${n("row_id")} FROM ${r} WHERE ${r} MATCH ${a?.sqlite ?? e.query})`;
|
|
2905
3030
|
},
|
|
2906
3031
|
mssql: o,
|
|
2907
|
-
orElse: () => a === void 0 ? n`${
|
|
3032
|
+
orElse: () => a === void 0 ? n`${Ir(e, n)} @@ plainto_tsquery(${e.config ?? "english"}, ${e.query})` : n`${Ir(e, n)} @@ to_tsquery(${e.config ?? "english"}, ${a.pg})`
|
|
2908
3033
|
});
|
|
2909
|
-
},
|
|
2910
|
-
let r = `%${
|
|
3034
|
+
}, Vr = (e, t, n) => {
|
|
3035
|
+
let r = `%${kr(e.query)}%`, i = zr(e), a = () => 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}`);
|
|
2911
3036
|
return e.fallback === "like" ? a() : n.onDialectOrElse({
|
|
2912
|
-
mysql: () => i === void 0 ? n`MATCH(${n.
|
|
3037
|
+
mysql: () => i === void 0 ? n`MATCH(${n.join(", ", !1)(e.columns.map((e) => n`${n(e)}`))}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)` : n`MATCH(${n.join(", ", !1)(e.columns.map((e) => n`${n(e)}`))}) AGAINST(${i.mysql} IN BOOLEAN MODE)`,
|
|
2913
3038
|
sqlite: () => {
|
|
2914
|
-
let r = n(
|
|
3039
|
+
let r = n(Lr(e, t));
|
|
2915
3040
|
return n`COALESCE((SELECT -bm25(${r}) FROM ${r} WHERE ${r} MATCH ${i?.sqlite ?? e.query} AND ${r}.${n("row_id")} = ${n("id")}), 0)`;
|
|
2916
3041
|
},
|
|
2917
3042
|
mssql: a,
|
|
2918
|
-
orElse: () => i === void 0 ? n`ts_rank(${
|
|
3043
|
+
orElse: () => i === void 0 ? n`ts_rank(${Ir(e, n)}, plainto_tsquery(${e.config ?? "english"}, ${e.query}))` : n`ts_rank(${Ir(e, n)}, to_tsquery(${e.config ?? "english"}, ${i.pg}))`
|
|
2919
3044
|
});
|
|
2920
|
-
},
|
|
2921
|
-
let a = (e) => t(r && !e.includes(".") ? `${r}.${e}` : e), o = () => n?.length ? t.
|
|
3045
|
+
}, Hr = (e, t, n, r, i = !1) => {
|
|
3046
|
+
let a = (e) => t(r && !e.includes(".") ? `${r}.${e}` : e), o = () => n?.length ? t.join(", ", !1)(n.map((e) => t`${a(e)}`)) : r ? t`${t(r)}.*` : t`*`, s = i && t.onDialectOrElse({
|
|
2922
3047
|
mssql: () => !0,
|
|
2923
3048
|
orElse: () => !1
|
|
2924
3049
|
});
|
|
2925
3050
|
return !e || !Object.values(e).some((e) => e.type === "bigint" || s && e.type === "decimal") ? o() : t.onDialectOrElse({
|
|
2926
|
-
sqlite: () => t.
|
|
2927
|
-
mssql: () => s && Object.values(e).some((e) => e.type === "decimal") ? t.
|
|
3051
|
+
sqlite: () => t.join(", ", !1)((n?.length ? n : Object.keys(e)).map((n) => e[n]?.type === "bigint" ? t`CAST(${a(n)} AS TEXT) AS ${t(n)}` : t`${a(n)}`)),
|
|
3052
|
+
mssql: () => s && Object.values(e).some((e) => e.type === "decimal") ? t.join(", ", !1)((n?.length ? n : Object.keys(e)).map((n) => e[n]?.type === "decimal" ? t`CONVERT(varchar(80), ${a(n)}) AS ${t(n)}` : t`${a(n)}`)) : o(),
|
|
2928
3053
|
orElse: o
|
|
2929
3054
|
});
|
|
2930
|
-
},
|
|
2931
|
-
let o = /* @__PURE__ */ new Set([...i, ...(e.ctes ?? []).map((e) =>
|
|
3055
|
+
}, Ur = (e, t, n) => Hr(W(e)?.fields, t, n), Wr = (e, t, n = null, r, i = /* @__PURE__ */ new Set(), a = !1) => {
|
|
3056
|
+
let o = yn(e), s = /* @__PURE__ */ new Set([...i, ...(e.ctes ?? []).map((e) => Dr(e.name))]), c = (e) => s.has(Dr(e)) ? e : er(n, e), l = (e.ctes ?? []).map((e) => t`${t(e.name)} AS (${Wr(e.descriptor, t, n, e.recursive && t.onDialectOrElse({
|
|
2932
3057
|
sqlite: () => !0,
|
|
2933
3058
|
orElse: () => !1
|
|
2934
|
-
}) ? e.name : void 0,
|
|
3059
|
+
}) ? e.name : void 0, s)})`), u = (e.ctes ?? []).some((e) => e.recursive === !0), d = l.length > 0 ? t`WITH ${t.unsafe(u ? "RECURSIVE " : "")}${t.join(", ", !1)(l)} ` : t``;
|
|
2935
3060
|
if (e.setOp && e.setOp.queries.length >= 2) {
|
|
2936
3061
|
let i = e.setOp.kind === "union" ? "UNION" : e.setOp.kind === "union-all" ? "UNION ALL" : e.setOp.kind === "intersect" ? "INTERSECT" : "EXCEPT", a = t.onDialectOrElse({
|
|
2937
3062
|
sqlite: () => !0,
|
|
2938
3063
|
orElse: () => !1
|
|
2939
|
-
}),
|
|
2940
|
-
if (!a) return t`(${
|
|
3064
|
+
}), o = e.setOp.queries.map((e) => {
|
|
3065
|
+
if (!a) return t`(${Wr(e, t, n, void 0, s)})`;
|
|
2941
3066
|
if (r !== void 0) {
|
|
2942
|
-
if (!(
|
|
3067
|
+
if (!(It(e).length > 0 || e.take !== void 0 || e.skip !== void 0 || e.setOp !== void 0 || (e.ctes?.length ?? 0) > 0)) return Wr(e, t, n, void 0, s);
|
|
2943
3068
|
let i = (e) => e.replace(/[A-Z]/g, (e) => e.toLowerCase()), a = (e) => i(e) === i(r);
|
|
2944
|
-
if (a(e.table) || e.joins?.some((e) => a(e.table))) throw
|
|
3069
|
+
if (a(e.table) || e.joins?.some((e) => a(e.table))) throw L("Recursive SQLite terms cannot use branch-local ordering, pagination or nested compounds; apply ordering and pagination to the recursive compound or its outer query");
|
|
2945
3070
|
}
|
|
2946
|
-
return t`SELECT * FROM (${
|
|
3071
|
+
return t`SELECT * FROM (${Wr(e, t, n, void 0, s)})`;
|
|
2947
3072
|
}).reduce((e, n, r) => r === 0 ? n : t`${e} ${t.unsafe(i)} ${n}`), c = [];
|
|
2948
|
-
if (
|
|
2949
|
-
if (!Number.isInteger(e.take) || e.take < 0) throw
|
|
3073
|
+
if (It(e).length > 0 && c.push(t` ORDER BY ${t.join(", ", !1)(It(e).map((e) => e.direction === "desc" ? t`${t(e.column)} DESC` : t`${t(e.column)} ASC`))}`), e.take !== void 0) {
|
|
3074
|
+
if (!Number.isInteger(e.take) || e.take < 0) throw L(`compileSelect: invalid take ${e.take}`);
|
|
2950
3075
|
c.push(t` LIMIT ${t.unsafe(String(e.take))}`);
|
|
2951
3076
|
}
|
|
2952
3077
|
if (e.skip !== void 0) {
|
|
2953
|
-
if (a && e.take === void 0 && c.push(t` LIMIT -1`), !Number.isInteger(e.skip) || e.skip < 0) throw
|
|
3078
|
+
if (a && e.take === void 0 && c.push(t` LIMIT -1`), !Number.isInteger(e.skip) || e.skip < 0) throw L(`compileSelect: invalid skip ${e.skip}`);
|
|
2954
3079
|
c.push(t` OFFSET ${t.unsafe(String(e.skip))}`);
|
|
2955
3080
|
}
|
|
2956
|
-
return t`${
|
|
3081
|
+
return t`${d}${o}${c.reduce((e, n) => t`${e}${n}`, t``)}`;
|
|
2957
3082
|
}
|
|
2958
|
-
let
|
|
3083
|
+
let f = e.annClause === void 0 ? null : Nr(e.annClause, t);
|
|
2959
3084
|
e.spatialClause !== void 0 && t.onDialectOrElse({
|
|
2960
3085
|
mysql: () => {
|
|
2961
|
-
throw
|
|
3086
|
+
throw L("@voltro/plugin-postgis: spatial distance / KNN ordering is postgres-only");
|
|
2962
3087
|
},
|
|
2963
3088
|
mssql: () => {
|
|
2964
|
-
throw
|
|
3089
|
+
throw L("@voltro/plugin-postgis: spatial distance / KNN ordering is postgres-only");
|
|
2965
3090
|
},
|
|
2966
3091
|
sqlite: () => {
|
|
2967
|
-
throw
|
|
3092
|
+
throw L("@voltro/plugin-postgis: spatial distance / KNN ordering is postgres-only");
|
|
2968
3093
|
},
|
|
2969
3094
|
orElse: () => t``
|
|
2970
3095
|
});
|
|
2971
|
-
let
|
|
2972
|
-
let
|
|
2973
|
-
return t`${a &&
|
|
2974
|
-
mssql: () => t`CONVERT(varchar(80), ${
|
|
2975
|
-
orElse: () =>
|
|
2976
|
-
}) :
|
|
2977
|
-
sqlite: () => t`CAST(${
|
|
2978
|
-
orElse: () =>
|
|
2979
|
-
}) :
|
|
2980
|
-
})) :
|
|
2981
|
-
orElse: () => t`DISTINCT ON (${t.
|
|
3096
|
+
let p = e.spatialClause?.projectAs === void 0 ? null : Pr(e.spatialClause, t), m = e.aggregations && e.aggregations.length > 0 ? jr(e.aggregations, t) : e.joinedProjection && e.joinedProjection.length > 0 ? t.join(", ", !1)(e.joinedProjection.map((e) => {
|
|
3097
|
+
let n = t`${t(e.source)}`, r = o(e.source);
|
|
3098
|
+
return t`${a && r?.type === "decimal" ? t.onDialectOrElse({
|
|
3099
|
+
mssql: () => t`CONVERT(varchar(80), ${n})`,
|
|
3100
|
+
orElse: () => n
|
|
3101
|
+
}) : r?.type === "bigint" ? t.onDialectOrElse({
|
|
3102
|
+
sqlite: () => t`CAST(${n} AS TEXT)`,
|
|
3103
|
+
orElse: () => n
|
|
3104
|
+
}) : n} AS ${t(e.outputKey)}`;
|
|
3105
|
+
})) : Hr((e.sourceTable?.tableName === e.table ? e.sourceTable : W(e.table))?.fields, t, e.projection, (e.joins?.length ?? 0) > 0 ? e.alias ?? e.table : void 0, a), h = (e.aggregations && e.aggregations.length > 0) === !0, g = f !== null && !h ? t`${m}, ${f} AS ${t("distance")}` : m, _ = e.fullTextSearch, v = _?.rank !== void 0 && !h ? Vr(_, e.table, t) : null, y = v !== null && _?.rank !== void 0 ? t`${g}, ${v} AS ${t(_.rank.alias)}` : g, b = p !== null && !h && e.spatialClause?.projectAs !== void 0 ? t`${y}, ${p} AS ${t(e.spatialClause.projectAs)}` : y, x = e.distinctOn && e.distinctOn.length > 0 ? t.onDialectOrElse({
|
|
3106
|
+
orElse: () => t`DISTINCT ON (${t.join(", ", !1)(e.distinctOn.map((e) => t`${t(e)}`))}) `,
|
|
2982
3107
|
mysql: () => t`DISTINCT `,
|
|
2983
3108
|
mssql: () => t`DISTINCT `,
|
|
2984
3109
|
sqlite: () => t`DISTINCT `
|
|
2985
|
-
}) : e.distinct ? t`DISTINCT ` : t``,
|
|
3110
|
+
}) : e.distinct ? t`DISTINCT ` : t``, S = e.lock === "update", C = S ? t.onDialectOrElse({
|
|
2986
3111
|
mssql: () => t` WITH (UPDLOCK, ROWLOCK)`,
|
|
2987
3112
|
orElse: () => t``
|
|
2988
|
-
}) : t``,
|
|
3113
|
+
}) : t``, w = S ? t.onDialectOrElse({
|
|
2989
3114
|
mssql: () => t``,
|
|
2990
3115
|
sqlite: () => t``,
|
|
2991
3116
|
orElse: () => t` FOR UPDATE`
|
|
2992
|
-
}) : t``,
|
|
3117
|
+
}) : t``, T = e.alias === void 0 ? t`${t(c(e.table))}${C}` : t`${t(c(e.table))} AS ${t(e.alias)}${C}`, E = (e.joins ?? []).map((e) => {
|
|
2993
3118
|
let r = e.kind === "inner" ? "INNER" : "LEFT";
|
|
2994
|
-
return t` ${t.unsafe(r)} JOIN ${t(
|
|
2995
|
-
}),
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
3119
|
+
return t` ${t.unsafe(r)} JOIN ${t(c(e.table))} AS ${t(e.alias)} ON ${$(e.on, t, n, void 0, s)}`;
|
|
3120
|
+
}), D = E.length > 0 ? E.reduce((e, n) => t`${e}${n}`, T) : T, O = _ === void 0 ? null : Br(_, e.table, t), k = [e.predicate ? $(e.predicate, t, n, e.table, s) : null, O].filter((e) => e !== null), ee = k.length > 0 ? t` WHERE ${t.and(k)}` : t``, A = e.groupBy && e.groupBy.length > 0 ? t` GROUP BY ${t.join(", ", !1)(e.groupBy.map((e) => t`${t(e)}`))}` : t``, j = e.having ? t` HAVING ${$(e.having, t, n, e.table, s)}` : t``, M = e.skip !== void 0, N = [];
|
|
3121
|
+
f !== null && N.push(t`${f} ASC`), e.spatialClause?.order !== void 0 && N.push(e.spatialClause.order === "desc" ? t`${Fr(e.spatialClause, t)} DESC` : t`${Fr(e.spatialClause, t)} ASC`), v !== null && _?.rank?.order === !0 && N.push(t`${v} DESC`);
|
|
3122
|
+
let P = It(e), F = P.length >= 8 && (e.joinedProjection?.length ?? 0) >= 8 ? /* @__PURE__ */ new Map() : void 0;
|
|
3123
|
+
if (F) for (let t of e.joinedProjection ?? []) F.has(t.outputKey) || F.set(t.outputKey, t.source);
|
|
3124
|
+
for (let n of P) {
|
|
3125
|
+
let r = (F === void 0 ? e.joinedProjection?.find((e) => e.outputKey === n.column)?.source : F.get(n.column)) ?? n.column, i = a && !h && o(r)?.type === "decimal" ? t.onDialectOrElse({
|
|
2999
3126
|
mssql: () => t`${t(r.includes(".") ? r : `${e.alias ?? e.table}.${r}`)}`,
|
|
3000
3127
|
orElse: () => t`${t(n.column)}`
|
|
3001
|
-
}) : !
|
|
3128
|
+
}) : !h && o(r)?.type === "bigint" ? t.onDialectOrElse({
|
|
3002
3129
|
sqlite: () => t`${t(r.includes(".") ? r : `${e.alias ?? e.table}.${r}`)}`,
|
|
3003
3130
|
orElse: () => t`${t(n.column)}`
|
|
3004
3131
|
}) : t`${t(n.column)}`;
|
|
3005
|
-
|
|
3132
|
+
N.push(n.direction === "desc" ? t`${i} DESC` : t`${i} ASC`);
|
|
3006
3133
|
}
|
|
3007
|
-
let
|
|
3134
|
+
let te = N.length > 0 ? t` ORDER BY ${t.join(", ", !1)(N)}` : M ? t.onDialectOrElse({
|
|
3008
3135
|
mssql: () => t` ORDER BY (SELECT NULL)`,
|
|
3009
3136
|
orElse: () => t``
|
|
3010
|
-
}) : t``,
|
|
3011
|
-
if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw
|
|
3137
|
+
}) : t``, I = (e) => {
|
|
3138
|
+
if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw L(`compileSelect: expected non-negative integer take/skip, got ${e}`);
|
|
3012
3139
|
return t.unsafe(String(e));
|
|
3013
3140
|
};
|
|
3014
3141
|
return t.onDialectOrElse({
|
|
3015
3142
|
mssql: () => {
|
|
3016
|
-
let n = e.take !== void 0 && !
|
|
3017
|
-
return t`${
|
|
3143
|
+
let n = e.take !== void 0 && !M ? t`TOP ${I(e.take)} ` : t``, r = M ? t` OFFSET ${I(e.skip)} ROWS FETCH NEXT ${I(e.take ?? 2 ** 53 - 1)} ROWS ONLY` : t``;
|
|
3144
|
+
return t`${d}SELECT ${n}${x}${b} FROM ${D}${ee}${A}${j}${te}${r}`;
|
|
3018
3145
|
},
|
|
3019
3146
|
orElse: () => {
|
|
3020
|
-
let n = e.take === void 0 ?
|
|
3147
|
+
let n = e.take === void 0 ? M ? t.onDialectOrElse({
|
|
3021
3148
|
sqlite: () => t` LIMIT -1`,
|
|
3022
3149
|
mysql: () => t` LIMIT 18446744073709551615`,
|
|
3023
3150
|
orElse: () => t``
|
|
3024
|
-
}) : t`` : t` LIMIT ${
|
|
3025
|
-
return t`${
|
|
3151
|
+
}) : t`` : t` LIMIT ${I(e.take)}`, r = M ? t` OFFSET ${I(e.skip)}` : t``;
|
|
3152
|
+
return t`${d}SELECT ${x}${b} FROM ${D}${ee}${A}${j}${te}${n}${r}${w}`;
|
|
3026
3153
|
}
|
|
3027
3154
|
});
|
|
3028
|
-
},
|
|
3155
|
+
}, Gr = (e, t, n = null) => t.onDialectOrElse({
|
|
3029
3156
|
sqlite: () => !0,
|
|
3030
3157
|
orElse: () => !1
|
|
3031
|
-
}) &&
|
|
3032
|
-
mssql: () =>
|
|
3158
|
+
}) && Sn(e) ? t`${Er(e, t, { materialized: !1 }, n)}` : Wr(t.onDialectOrElse({
|
|
3159
|
+
mssql: () => ar(e) ?? e,
|
|
3033
3160
|
orElse: () => e
|
|
3034
|
-
}), t, n, void 0, /* @__PURE__ */ new Set(), !0),
|
|
3161
|
+
}), t, n, void 0, /* @__PURE__ */ new Set(), !0), Kr = (e, t, n = null, r) => {
|
|
3035
3162
|
if (r !== void 0 && t.onDialectOrElse({
|
|
3036
3163
|
sqlite: () => !0,
|
|
3037
3164
|
orElse: () => !1
|
|
@@ -3044,80 +3171,80 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
3044
3171
|
take: void 0,
|
|
3045
3172
|
skip: void 0
|
|
3046
3173
|
};
|
|
3047
|
-
if (
|
|
3048
|
-
compile: (e) =>
|
|
3174
|
+
if (Sn(i)) return vr(i, t, {
|
|
3175
|
+
compile: (e) => Gr(e, t, n),
|
|
3049
3176
|
resultScale: void 0
|
|
3050
3177
|
}, e);
|
|
3051
3178
|
}
|
|
3052
|
-
return
|
|
3053
|
-
},
|
|
3179
|
+
return $(e, t, n, r);
|
|
3180
|
+
}, qr = (e, t, n = null, r) => $(e, t, n, r), Jr = (e, t) => ({
|
|
3054
3181
|
column: e,
|
|
3055
3182
|
op: "eq",
|
|
3056
3183
|
value: t
|
|
3057
|
-
}),
|
|
3184
|
+
}), Yr = (e, t) => ({
|
|
3058
3185
|
column: e,
|
|
3059
3186
|
op: "neq",
|
|
3060
3187
|
value: t
|
|
3061
|
-
}),
|
|
3188
|
+
}), Xr = (e, t) => ({
|
|
3062
3189
|
column: e,
|
|
3063
3190
|
op: "gt",
|
|
3064
3191
|
value: t
|
|
3065
|
-
}),
|
|
3192
|
+
}), Zr = (e, t) => ({
|
|
3066
3193
|
column: e,
|
|
3067
3194
|
op: "gte",
|
|
3068
3195
|
value: t
|
|
3069
|
-
}),
|
|
3196
|
+
}), Qr = (e, t) => ({
|
|
3070
3197
|
column: e,
|
|
3071
3198
|
op: "lt",
|
|
3072
3199
|
value: t
|
|
3073
|
-
}),
|
|
3200
|
+
}), $r = (e, t) => ({
|
|
3074
3201
|
column: e,
|
|
3075
3202
|
op: "lte",
|
|
3076
3203
|
value: t
|
|
3077
|
-
}),
|
|
3204
|
+
}), ei = (e, t) => ({
|
|
3078
3205
|
column: e,
|
|
3079
3206
|
op: "in",
|
|
3080
3207
|
value: t
|
|
3081
|
-
}),
|
|
3208
|
+
}), ti = (e, t) => ({
|
|
3082
3209
|
column: e,
|
|
3083
3210
|
op: "notIn",
|
|
3084
3211
|
value: t
|
|
3085
|
-
}),
|
|
3212
|
+
}), ni = (e, t) => ({
|
|
3086
3213
|
column: e,
|
|
3087
3214
|
op: "contains",
|
|
3088
3215
|
value: t
|
|
3089
|
-
}),
|
|
3216
|
+
}), ri = (e, t) => ({
|
|
3090
3217
|
column: e,
|
|
3091
3218
|
op: "startsWith",
|
|
3092
3219
|
value: t
|
|
3093
|
-
}),
|
|
3220
|
+
}), ii = (e, t) => ({
|
|
3094
3221
|
column: e,
|
|
3095
3222
|
op: "arrayContains",
|
|
3096
3223
|
value: t
|
|
3097
|
-
}),
|
|
3224
|
+
}), ai = (e, t) => ({
|
|
3098
3225
|
column: e,
|
|
3099
3226
|
op: "arrayOverlaps",
|
|
3100
3227
|
value: t
|
|
3101
|
-
}),
|
|
3228
|
+
}), oi = (e, t) => ({
|
|
3102
3229
|
column: e,
|
|
3103
3230
|
op: "arrayHas",
|
|
3104
3231
|
value: t
|
|
3105
|
-
}),
|
|
3232
|
+
}), si = {
|
|
3106
3233
|
column: "id",
|
|
3107
3234
|
op: "in",
|
|
3108
3235
|
value: []
|
|
3109
|
-
},
|
|
3236
|
+
}, ci = (e) => ({
|
|
3110
3237
|
column: e,
|
|
3111
3238
|
op: "isNull"
|
|
3112
|
-
}),
|
|
3239
|
+
}), li = (e) => ({
|
|
3113
3240
|
column: e,
|
|
3114
3241
|
op: "isNotNull"
|
|
3115
|
-
}),
|
|
3242
|
+
}), ui = (e, t) => ({
|
|
3116
3243
|
column: e,
|
|
3117
3244
|
op: "spatial",
|
|
3118
3245
|
value: t
|
|
3119
|
-
}),
|
|
3120
|
-
if (t.length === 0) throw
|
|
3246
|
+
}), di = (...e) => ({ and: e }), fi = (...e) => ({ or: e }), pi = (e) => ({ not: e }), mi = (e, ...t) => {
|
|
3247
|
+
if (t.length === 0) throw L(`jsonField("${e}"): at least one path segment is required`);
|
|
3121
3248
|
let n = (n, r) => ({
|
|
3122
3249
|
column: e,
|
|
3123
3250
|
path: t,
|
|
@@ -3138,74 +3265,113 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
3138
3265
|
isNull: () => n("isNull"),
|
|
3139
3266
|
isNotNull: () => n("isNotNull")
|
|
3140
3267
|
};
|
|
3141
|
-
},
|
|
3268
|
+
}, hi = (e) => "descriptor" in e ? e.descriptor : e, gi = (e, t) => ({
|
|
3142
3269
|
column: e,
|
|
3143
3270
|
op: "subquery-in",
|
|
3144
|
-
subquery:
|
|
3145
|
-
}),
|
|
3271
|
+
subquery: hi(t)
|
|
3272
|
+
}), _i = (e, t) => ({
|
|
3146
3273
|
column: e,
|
|
3147
3274
|
op: "subquery-not-in",
|
|
3148
|
-
subquery:
|
|
3149
|
-
}),
|
|
3275
|
+
subquery: hi(t)
|
|
3276
|
+
}), vi = (e) => ({
|
|
3150
3277
|
op: "exists",
|
|
3151
|
-
subquery:
|
|
3152
|
-
}),
|
|
3278
|
+
subquery: hi(e)
|
|
3279
|
+
}), yi = (e) => ({
|
|
3153
3280
|
op: "not-exists",
|
|
3154
|
-
subquery:
|
|
3155
|
-
}),
|
|
3281
|
+
subquery: hi(e)
|
|
3282
|
+
}), bi = /^\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?)?$/, xi = (e) => {
|
|
3156
3283
|
if (e instanceof Date) return e.getTime();
|
|
3157
|
-
if (typeof e == "string" &&
|
|
3284
|
+
if (typeof e == "string" && bi.test(e)) {
|
|
3158
3285
|
let t = Date.parse(e);
|
|
3159
3286
|
return Number.isNaN(t) ? void 0 : t;
|
|
3160
3287
|
}
|
|
3161
|
-
},
|
|
3288
|
+
}, Si = (e, t) => {
|
|
3162
3289
|
if (!(e instanceof Date) && !(t instanceof Date)) return;
|
|
3163
|
-
let n =
|
|
3290
|
+
let n = xi(e), r = xi(t);
|
|
3164
3291
|
return n === void 0 || r === void 0 ? void 0 : [n, r];
|
|
3165
|
-
},
|
|
3292
|
+
}, Ci = (e, t) => {
|
|
3166
3293
|
if (e === t) return !0;
|
|
3167
3294
|
if (e instanceof Uint8Array && t instanceof Uint8Array) {
|
|
3168
3295
|
if (e.length !== t.length) return !1;
|
|
3169
3296
|
for (let n = 0; n < e.length; n += 1) if (e[n] !== t[n]) return !1;
|
|
3170
3297
|
return !0;
|
|
3171
3298
|
}
|
|
3172
|
-
let n =
|
|
3299
|
+
let n = Si(e, t);
|
|
3173
3300
|
return n !== void 0 && n[0] === n[1];
|
|
3174
|
-
},
|
|
3301
|
+
}, wi = (e, t) => {
|
|
3175
3302
|
if (e == null || t == null) return null;
|
|
3176
|
-
let n =
|
|
3303
|
+
let n = Si(e, t);
|
|
3177
3304
|
if (n !== void 0) return n[0] === n[1] ? 0 : n[0] > n[1] ? 1 : -1;
|
|
3178
3305
|
let r = e instanceof Date ? e.getTime() : e, i = t instanceof Date ? t.getTime() : t;
|
|
3179
3306
|
return typeof r == typeof i ? r === i ? 0 : r > i ? 1 : -1 : null;
|
|
3180
|
-
},
|
|
3307
|
+
}, Ti = (e, t, n = null, r = {}) => Oi(e, t, n, r) === !0, Ei = (e, t = null, n = {}) => {
|
|
3308
|
+
let r = /* @__PURE__ */ new Map(), i = (e) => {
|
|
3309
|
+
if ("not" in e) {
|
|
3310
|
+
i(e.not);
|
|
3311
|
+
return;
|
|
3312
|
+
}
|
|
3313
|
+
if ("and" in e) {
|
|
3314
|
+
e.and.forEach(i);
|
|
3315
|
+
return;
|
|
3316
|
+
}
|
|
3317
|
+
if ("or" in e) {
|
|
3318
|
+
e.or.forEach(i);
|
|
3319
|
+
return;
|
|
3320
|
+
}
|
|
3321
|
+
if (e.op !== "in" && e.op !== "notIn" || n[e.column]?.type === "decimal") return;
|
|
3322
|
+
let t = Object.getOwnPropertyDescriptor(e, "value");
|
|
3323
|
+
if (t === void 0 || !("value" in t)) return;
|
|
3324
|
+
let a = t.value;
|
|
3325
|
+
if (!Array.isArray(a) || a.length < 16 || Object.getPrototypeOf(a) !== Array.prototype) return;
|
|
3326
|
+
let o = Object.getOwnPropertyDescriptor(a, "some");
|
|
3327
|
+
if (o !== void 0 && (!("value" in o) || o.value !== Array.prototype.some)) return;
|
|
3328
|
+
for (let e = 0; e < a.length; e++) {
|
|
3329
|
+
let t = Object.getOwnPropertyDescriptor(a, e);
|
|
3330
|
+
if (t !== void 0 && !("value" in t)) return;
|
|
3331
|
+
}
|
|
3332
|
+
if (a.some((e) => typeof e == "object" && !!e)) return;
|
|
3333
|
+
let s = Array.prototype.filter.call(a, (e) => !(typeof e == "number" && Number.isNaN(e)));
|
|
3334
|
+
r.set(e, new Set(s));
|
|
3335
|
+
};
|
|
3336
|
+
return i(e), (i) => Oi(e, i, t, n, r) === !0;
|
|
3337
|
+
}, Di = (e, t, n) => {
|
|
3338
|
+
if (e.length < 128 || t.length < 16 || Object.getPrototypeOf(e) !== Array.prototype || Object.getPrototypeOf(t) !== Array.prototype || Object.getOwnPropertyDescriptor(e, "includes") !== void 0 || Object.getOwnPropertyDescriptor(t, n) !== void 0) return;
|
|
3339
|
+
for (let n of [e, t]) for (let e = 0; e < n.length; e += 1) {
|
|
3340
|
+
let t = Object.getOwnPropertyDescriptor(n, String(e));
|
|
3341
|
+
if (t === void 0 || !("value" in t)) return;
|
|
3342
|
+
}
|
|
3343
|
+
let r = /* @__PURE__ */ new Set();
|
|
3344
|
+
for (let t = 0; t < e.length; t += 1) r.add(e[t]);
|
|
3345
|
+
return r;
|
|
3346
|
+
}, Oi = (e, t, n = null, r = {}, i) => {
|
|
3181
3347
|
if (!t) return !1;
|
|
3182
3348
|
if ("not" in e) {
|
|
3183
|
-
let
|
|
3184
|
-
return
|
|
3349
|
+
let a = Oi(e.not, t, n, r, i);
|
|
3350
|
+
return a === null ? null : !a;
|
|
3185
3351
|
}
|
|
3186
3352
|
if ("and" in e) {
|
|
3187
|
-
let
|
|
3188
|
-
for (let
|
|
3189
|
-
let e =
|
|
3353
|
+
let a = !1;
|
|
3354
|
+
for (let o of e.and) {
|
|
3355
|
+
let e = Oi(o, t, n, r, i);
|
|
3190
3356
|
if (e === !1) return !1;
|
|
3191
|
-
e === null && (
|
|
3357
|
+
e === null && (a = !0);
|
|
3192
3358
|
}
|
|
3193
|
-
return !
|
|
3359
|
+
return !a || null;
|
|
3194
3360
|
}
|
|
3195
3361
|
if ("or" in e) {
|
|
3196
|
-
let
|
|
3197
|
-
for (let
|
|
3198
|
-
let e =
|
|
3362
|
+
let a = !1;
|
|
3363
|
+
for (let o of e.or) {
|
|
3364
|
+
let e = Oi(o, t, n, r, i);
|
|
3199
3365
|
if (e === !0) return !0;
|
|
3200
|
-
e === null && (
|
|
3366
|
+
e === null && (a = !0);
|
|
3201
3367
|
}
|
|
3202
|
-
return
|
|
3368
|
+
return a ? null : !1;
|
|
3203
3369
|
}
|
|
3204
3370
|
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
3205
3371
|
if (!n) return !1;
|
|
3206
3372
|
let i = n.get(e.subquery);
|
|
3207
3373
|
if (!(i instanceof Set)) return !1;
|
|
3208
|
-
let a = t[e.column], o = r[e.column]?.type === "decimal" ? [...i].some((e) =>
|
|
3374
|
+
let a = t[e.column], o = r[e.column]?.type === "decimal" ? [...i].some((e) => zn(a, e) === 0) : i.has(a);
|
|
3209
3375
|
return e.op === "subquery-in" ? o : !o;
|
|
3210
3376
|
}
|
|
3211
3377
|
if (e.op === "exists" || e.op === "not-exists") {
|
|
@@ -3213,46 +3379,55 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
3213
3379
|
let t = n.get(e.subquery), r = typeof t == "number" ? t > 0 : t instanceof Set && t.size > 0;
|
|
3214
3380
|
return e.op === "exists" ? r : !r;
|
|
3215
3381
|
}
|
|
3216
|
-
let
|
|
3217
|
-
if (
|
|
3218
|
-
let
|
|
3219
|
-
if (
|
|
3220
|
-
let
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
case "
|
|
3228
|
-
case "
|
|
3229
|
-
case "
|
|
3230
|
-
case "
|
|
3231
|
-
case "
|
|
3382
|
+
let a = e, o = t[a.column], s = Hn(a.value) ? a.value : void 0;
|
|
3383
|
+
if (s !== void 0 && (!Un.some((e) => e === a.op) || a.path !== void 0)) throw L("Column references require a scalar comparison without a JSON path");
|
|
3384
|
+
let c = s === void 0 ? a.value : t[s.column];
|
|
3385
|
+
if (s !== void 0 && (o == null || c == null)) return null;
|
|
3386
|
+
let l = r[a.column]?.type === "decimal", u = i?.get(e);
|
|
3387
|
+
if (u !== void 0 && !(o instanceof Date) && !(o instanceof Uint8Array)) {
|
|
3388
|
+
let e = typeof o == "number" && Number.isNaN(o) ? !1 : u.has(o);
|
|
3389
|
+
return a.op === "in" ? e : !e;
|
|
3390
|
+
}
|
|
3391
|
+
let d = (e, t) => l && e != null && t != null ? zn(e, t) === 0 : Ci(e, t), f = l ? zn : wi;
|
|
3392
|
+
switch (a.op) {
|
|
3393
|
+
case "eq": return d(o, c);
|
|
3394
|
+
case "neq": return !d(o, c);
|
|
3395
|
+
case "gt": return (f(o, c) ?? -1) > 0;
|
|
3396
|
+
case "gte": return (f(o, c) ?? -1) >= 0;
|
|
3397
|
+
case "lt": return (f(o, c) ?? 1) < 0;
|
|
3398
|
+
case "lte": return (f(o, c) ?? 1) <= 0;
|
|
3399
|
+
case "in": return Array.isArray(c) && c.some((e) => d(o, e));
|
|
3400
|
+
case "notIn": return Array.isArray(c) && !c.some((e) => d(o, e));
|
|
3401
|
+
case "contains": return typeof o == "string" && typeof c == "string" && o.toLowerCase().includes(c.toLowerCase());
|
|
3402
|
+
case "startsWith": return typeof o == "string" && typeof c == "string" && o.startsWith(c);
|
|
3232
3403
|
case "arrayContains": {
|
|
3233
|
-
let e = Array.isArray(
|
|
3234
|
-
|
|
3404
|
+
let e = Array.isArray(o) ? o : [], t = Array.isArray(c) ? c : [];
|
|
3405
|
+
if (e.length < 128 || t.length < 16) return t.every((t) => e.includes(t));
|
|
3406
|
+
let n, r = 0;
|
|
3407
|
+
return t.every((i) => (++r === 5 && (n = Di(e, t, "every")), n === void 0 ? e.includes(i) : n.has(i)));
|
|
3235
3408
|
}
|
|
3236
3409
|
case "arrayOverlaps": {
|
|
3237
|
-
let e = Array.isArray(
|
|
3238
|
-
|
|
3410
|
+
let e = Array.isArray(o) ? o : [], t = Array.isArray(c) ? c : [];
|
|
3411
|
+
if (e.length < 128 || t.length < 16) return t.some((t) => e.includes(t));
|
|
3412
|
+
let n, r = 0;
|
|
3413
|
+
return t.some((i) => (++r === 5 && (n = Di(e, t, "some")), n === void 0 ? e.includes(i) : n.has(i)));
|
|
3239
3414
|
}
|
|
3240
|
-
case "arrayHas": return Array.isArray(
|
|
3241
|
-
case "isNull": return
|
|
3242
|
-
case "isNotNull": return
|
|
3243
|
-
case "spatial": throw
|
|
3415
|
+
case "arrayHas": return Array.isArray(o) && o.includes(c);
|
|
3416
|
+
case "isNull": return o == null;
|
|
3417
|
+
case "isNotNull": return o != null;
|
|
3418
|
+
case "spatial": throw L("@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.");
|
|
3244
3419
|
}
|
|
3245
|
-
},
|
|
3420
|
+
}, ki = function* (e) {
|
|
3246
3421
|
if ("not" in e) {
|
|
3247
|
-
yield*
|
|
3422
|
+
yield* ki(e.not);
|
|
3248
3423
|
return;
|
|
3249
3424
|
}
|
|
3250
3425
|
if ("and" in e) {
|
|
3251
|
-
for (let t of e.and) yield*
|
|
3426
|
+
for (let t of e.and) yield* ki(t);
|
|
3252
3427
|
return;
|
|
3253
3428
|
}
|
|
3254
3429
|
if ("or" in e) {
|
|
3255
|
-
for (let t of e.or) yield*
|
|
3430
|
+
for (let t of e.or) yield* ki(t);
|
|
3256
3431
|
return;
|
|
3257
3432
|
}
|
|
3258
3433
|
e.op === "subquery-in" || e.op === "subquery-not-in" ? yield {
|
|
@@ -3262,30 +3437,30 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
3262
3437
|
kind: "exists",
|
|
3263
3438
|
descriptor: e.subquery
|
|
3264
3439
|
});
|
|
3265
|
-
},
|
|
3440
|
+
}, Ai = function* (e, t = !0) {
|
|
3266
3441
|
if ("not" in e) {
|
|
3267
|
-
yield*
|
|
3442
|
+
yield* Ai(e.not, !1);
|
|
3268
3443
|
return;
|
|
3269
3444
|
}
|
|
3270
3445
|
if ("and" in e) {
|
|
3271
|
-
for (let n of e.and) yield*
|
|
3446
|
+
for (let n of e.and) yield* Ai(n, t);
|
|
3272
3447
|
return;
|
|
3273
3448
|
}
|
|
3274
3449
|
if ("or" in e) {
|
|
3275
|
-
for (let t of e.or) yield*
|
|
3450
|
+
for (let t of e.or) yield* Ai(t, !1);
|
|
3276
3451
|
return;
|
|
3277
3452
|
}
|
|
3278
3453
|
e.op !== "subquery-in" && e.op !== "subquery-not-in" && e.op !== "exists" && e.op !== "not-exists" && (yield {
|
|
3279
3454
|
...e,
|
|
3280
|
-
conjunctive: t && !
|
|
3455
|
+
conjunctive: t && !Hn(e.value)
|
|
3281
3456
|
});
|
|
3282
|
-
},
|
|
3457
|
+
}, ji = (e, t) => ({
|
|
3283
3458
|
name: e,
|
|
3284
3459
|
body: t
|
|
3285
|
-
}),
|
|
3460
|
+
}), Mi = (e) => {
|
|
3286
3461
|
if (e.lifecycle === "cron" && !e.cron) throw Error(`seed "${e.id}": lifecycle 'cron' requires a 'cron' field`);
|
|
3287
3462
|
if (e.lifecycle === "onSchemaChange" && (!e.watchedTables || e.watchedTables.length === 0)) throw Error(`seed "${e.id}": lifecycle 'onSchemaChange' requires at least one entry in 'watchedTables'`);
|
|
3288
|
-
let t = e.steps({ step:
|
|
3463
|
+
let t = e.steps({ step: ji });
|
|
3289
3464
|
if (t.length === 0) throw Error(`seed "${e.id}": at least one step is required`);
|
|
3290
3465
|
return {
|
|
3291
3466
|
__seed: !0,
|
|
@@ -3298,76 +3473,76 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
3298
3473
|
...e.fingerprint === void 0 ? {} : { fingerprint: e.fingerprint },
|
|
3299
3474
|
steps: t
|
|
3300
3475
|
};
|
|
3301
|
-
},
|
|
3302
|
-
|
|
3303
|
-
},
|
|
3304
|
-
|
|
3305
|
-
},
|
|
3306
|
-
let t =
|
|
3476
|
+
}, Ni = (e) => typeof e == "object" && !!e && "__seed" in e && e.__seed === !0, Pi = null, Fi = null, Ii = (e) => {
|
|
3477
|
+
Pi = e;
|
|
3478
|
+
}, Li = (e) => {
|
|
3479
|
+
Fi = e;
|
|
3480
|
+
}, Ri = async (e) => {
|
|
3481
|
+
let t = Pi;
|
|
3307
3482
|
t !== null && await t(e);
|
|
3308
|
-
},
|
|
3309
|
-
let t =
|
|
3483
|
+
}, zi = async (e) => {
|
|
3484
|
+
let t = Fi;
|
|
3310
3485
|
t !== null && e.changedTables.length !== 0 && await t(e);
|
|
3311
|
-
},
|
|
3486
|
+
}, Bi = ["before-schema", "after-schema"], Vi = (e) => {
|
|
3312
3487
|
if (!e.id || e.id.length === 0) throw Error("migration: `id` is required + must be non-empty");
|
|
3313
3488
|
if (!e.up || !e.down) throw Error(`migration ${e.id}: both \`up\` and \`down\` must be functions`);
|
|
3314
|
-
if (!
|
|
3489
|
+
if (!Bi.includes(e.phase)) throw Error(`migration ${e.id}: \`phase\` is required and must be one of ${Bi.map((e) => `'${e}'`).join(" | ")} — 'before-schema' runs before the declarative apply (a shape change the planner must not compute against), 'after-schema' runs after it (a body that needs the new shape, such as a back-fill into a table this deploy creates)`);
|
|
3315
3490
|
return e;
|
|
3316
|
-
},
|
|
3491
|
+
}, Hi = Symbol.for("voltro.migration.irreversible"), Ui = class extends Error {
|
|
3317
3492
|
migrationId;
|
|
3318
3493
|
reason;
|
|
3319
3494
|
_tag = "IrreversibleMigrationError";
|
|
3320
3495
|
constructor(e, t) {
|
|
3321
3496
|
super(`migration ${e} cannot be rolled back: ${t}`), this.migrationId = e, this.reason = t, this.name = "IrreversibleMigrationError";
|
|
3322
3497
|
}
|
|
3323
|
-
},
|
|
3498
|
+
}, Wi = (e) => {
|
|
3324
3499
|
if (!e || e.trim().length === 0) throw Error("irreversible(): a reason is required");
|
|
3325
|
-
return Object.assign(() => t.fail(new
|
|
3326
|
-
},
|
|
3327
|
-
let t = e[
|
|
3500
|
+
return Object.assign(() => t.fail(new Ui("<unknown>", e)), { [Hi]: e });
|
|
3501
|
+
}, Gi = (e) => {
|
|
3502
|
+
let t = e[Hi];
|
|
3328
3503
|
return typeof t == "string" ? t : void 0;
|
|
3329
|
-
},
|
|
3504
|
+
}, Ki = class {
|
|
3330
3505
|
reason;
|
|
3331
3506
|
_tag = "MigrationSkipped";
|
|
3332
3507
|
constructor(e) {
|
|
3333
3508
|
this.reason = e;
|
|
3334
3509
|
}
|
|
3335
|
-
},
|
|
3510
|
+
}, qi = class extends Error {
|
|
3336
3511
|
migrationId;
|
|
3337
3512
|
failed;
|
|
3338
3513
|
_tag = "MigrationExpectationFailed";
|
|
3339
3514
|
constructor(e, t) {
|
|
3340
3515
|
super(`migration ${e}: ${t.length} post-condition(s) did not hold after up():\n` + t.map((e) => ` - ${e}`).join("\n") + "\n The migration is NOT recorded; the next run applies it again."), this.migrationId = e, this.failed = t, this.name = "MigrationExpectationFailed";
|
|
3341
3516
|
}
|
|
3342
|
-
},
|
|
3517
|
+
}, Ji = class extends Error {
|
|
3343
3518
|
migrationId;
|
|
3344
3519
|
dialect;
|
|
3345
3520
|
_tag = "TransactionBrokenByBodyError";
|
|
3346
3521
|
constructor(e, t) {
|
|
3347
3522
|
super(`migration ${e} is transactional, and its body COMMITTED the transaction from inside — on ${t} a DDL statement commits everything before it. The work is in the database and the migration is recorded; it will not run again. What did not hold is the all-or-nothing guarantee. Either mark it \`transactional: false\` (per-statement, resumable through your own idempotency) or move the schema change into \`ctx.schema\` in a migration of its own and keep this one to data.`), this.migrationId = e, this.dialect = t, this.name = "TransactionBrokenByBodyError";
|
|
3348
3523
|
}
|
|
3349
|
-
},
|
|
3524
|
+
}, Yi = class extends Error {
|
|
3350
3525
|
migrationId;
|
|
3351
3526
|
operation;
|
|
3352
3527
|
_tag = "MigrationNeedsSqlClient";
|
|
3353
3528
|
constructor(e, t, n) {
|
|
3354
3529
|
super(`migration ${e}: ${t} — ${n}`), this.migrationId = e, this.operation = t, this.name = "MigrationNeedsSqlClient";
|
|
3355
3530
|
}
|
|
3356
|
-
},
|
|
3531
|
+
}, Xi = class extends Error {
|
|
3357
3532
|
table;
|
|
3358
3533
|
report;
|
|
3359
3534
|
_tag = "RewriteUnstableError";
|
|
3360
3535
|
constructor(e, t) {
|
|
3361
3536
|
super(`rewrite of ${e} did not stabilise after ${t.passes} pass(es): ${t.rewritten} rewritten, ${t.contended} contended on the last pass. Check for concurrent writes and guard values that cannot round-trip exactly before raising maxPasses.`), this.table = e, this.report = t, this.name = "RewriteUnstableError";
|
|
3362
3537
|
}
|
|
3363
|
-
},
|
|
3538
|
+
}, Zi = /^\d{8}_\d{6}_[a-z0-9_]+\.ts$/, Qi = (e) => typeof e == "object" && !!e && "id" in e && "up" in e && "down" in e && typeof e.id == "string" && typeof e.up == "function" && typeof e.down == "function", $i = /* @__PURE__ */ new Set(["voltro_isr_cache"]), ea = (e) => $i.has(e) || e.startsWith("_voltro_") || e.startsWith("_cloud_") || e.startsWith("cluster_") || e.startsWith("__turso_internal_"), ta = "_voltro_staging_", na = (e) => e.startsWith(ta), ra = /__dropped_\d{14}$/, ia = (e) => ra.test(e), aa = 7, oa = (e) => {
|
|
3364
3539
|
let t = /__dropped_(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/.exec(e);
|
|
3365
3540
|
if (t === null) return;
|
|
3366
3541
|
let [, n, r, i, a, o, s] = t;
|
|
3367
3542
|
return new Date(Date.UTC(Number(n), Number(r) - 1, Number(i), Number(a), Number(o), Number(s)));
|
|
3368
|
-
},
|
|
3543
|
+
}, sa = (e, t = {}) => {
|
|
3369
3544
|
let n = t.now ?? /* @__PURE__ */ new Date(), r = t.retentionDays ?? 7, i = [], a = (e, t) => {
|
|
3370
|
-
let a =
|
|
3545
|
+
let a = oa(e);
|
|
3371
3546
|
if (a === void 0) return;
|
|
3372
3547
|
let o = Math.floor((n.getTime() - a.getTime()) / 864e5);
|
|
3373
3548
|
o >= r && i.push({
|
|
@@ -3376,149 +3551,152 @@ var tn = (e, t, n) => nn(e, "id", t, n), nn = (e, t, n, r, i = "asc") => {
|
|
|
3376
3551
|
ageDays: o
|
|
3377
3552
|
});
|
|
3378
3553
|
};
|
|
3379
|
-
for (let t of e.tables) if (a(t.name, t.name), !
|
|
3554
|
+
for (let t of e.tables) if (a(t.name, t.name), !ia(t.name)) for (let e of t.columns ?? []) a(e.name, `${t.name}.${e.name}`);
|
|
3380
3555
|
return i;
|
|
3381
|
-
},
|
|
3556
|
+
}, ca = (e, t) => {
|
|
3382
3557
|
let n = e.reduce((e, t) => e.ageDays >= t.ageDays ? e : t), r = (/* @__PURE__ */ new Date(Date.now() - t * 864e5)).toISOString().slice(0, 10);
|
|
3383
3558
|
return `${e.length} soft-drop snapshot(s) older than ${t} day(s) still hold the dropped data (oldest: ${n.name}, ${n.ageDays}d) — ${e.map((e) => e.name).join(", ")}. Restore with \`voltro db restore-snapshot\` or reclaim with \`voltro db gc-snapshots --before ${r}\`; the window is \`database.softDropRetentionDays\` in app.config.`;
|
|
3384
|
-
},
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3559
|
+
}, la = (e, t) => e.filter((e) => !ea(e.name) || t.has(e.name)), ua = (e, t) => new s({ reason: new c({
|
|
3560
|
+
cause: t ?? Error(e),
|
|
3561
|
+
message: e
|
|
3562
|
+
}) }), da = H("_voltro_migrations", {
|
|
3563
|
+
id: h({ prefix: "mig" }),
|
|
3564
|
+
name: g(),
|
|
3565
|
+
hash: g(),
|
|
3566
|
+
status: g(),
|
|
3567
|
+
appliedAt: w().nullable(),
|
|
3568
|
+
durationMs: _().nullable(),
|
|
3569
|
+
errorMessage: g().nullable(),
|
|
3570
|
+
errorStack: g().nullable(),
|
|
3571
|
+
workflowRunId: g().nullable(),
|
|
3572
|
+
createdAt: w().default("now"),
|
|
3573
|
+
updatedAt: w().default("now").onUpdate("now")
|
|
3574
|
+
}).index(["status"]), fa = H("_voltro_seeds", {
|
|
3575
|
+
id: h({ prefix: "seed" }),
|
|
3576
|
+
name: g(),
|
|
3577
|
+
lifecycle: g(),
|
|
3578
|
+
fingerprint: g(),
|
|
3579
|
+
cronSchedule: g().nullable(),
|
|
3580
|
+
watchedTables: E().nullable(),
|
|
3581
|
+
nextRunAt: w().nullable(),
|
|
3582
|
+
lastRunStatus: g().nullable(),
|
|
3583
|
+
lastRunAt: w().nullable(),
|
|
3584
|
+
lastRunDurationMs: _().nullable(),
|
|
3585
|
+
lastRunRowsTouched: _().nullable(),
|
|
3586
|
+
lastError: g().nullable(),
|
|
3587
|
+
workflowRunId: g().nullable(),
|
|
3588
|
+
createdAt: w().default("now"),
|
|
3589
|
+
updatedAt: w().default("now").onUpdate("now")
|
|
3590
|
+
}).index(["lifecycle"]).index(["nextRunAt"]), pa = H("_voltro_schema_owner", {
|
|
3591
|
+
id: h({ prefix: "own" }),
|
|
3592
|
+
appName: g(),
|
|
3593
|
+
projectName: g().nullable(),
|
|
3594
|
+
frameworkVersion: g().nullable(),
|
|
3595
|
+
claimedAt: w().default("now")
|
|
3596
|
+
}), ma = H("_voltro_plugin_migrations", {
|
|
3597
|
+
id: h({ prefix: "plm" }),
|
|
3598
|
+
plugin_name: g(),
|
|
3599
|
+
migration_id: g(),
|
|
3600
|
+
description: g().nullable(),
|
|
3601
|
+
applied_at: g()
|
|
3602
|
+
}), ha = H("_voltro_migration_plans", {
|
|
3603
|
+
id: h({ prefix: "plan" }),
|
|
3604
|
+
fingerprint: g(),
|
|
3605
|
+
liveFingerprint: g().nullable(),
|
|
3606
|
+
operations: E(),
|
|
3607
|
+
rollbackPlan: E().nullable(),
|
|
3608
|
+
appliedBy: g(),
|
|
3609
|
+
environment: g(),
|
|
3610
|
+
source: g(),
|
|
3611
|
+
onlineStrategy: g().nullable(),
|
|
3612
|
+
durationMs: _(),
|
|
3613
|
+
notes: g().nullable(),
|
|
3614
|
+
squashedAt: w().nullable(),
|
|
3615
|
+
appliedAt: w().default("now"),
|
|
3616
|
+
createdAt: w().default("now"),
|
|
3617
|
+
updatedAt: w().default("now").onUpdate("now")
|
|
3618
|
+
}).index(["fingerprint"]).index(["environment"]), ga = H("_voltro_idempotency", {
|
|
3619
|
+
id: h({ prefix: "idem" }),
|
|
3620
|
+
scope: g(),
|
|
3621
|
+
key: g(),
|
|
3622
|
+
status: g(),
|
|
3623
|
+
response: E().nullable(),
|
|
3624
|
+
createdAt: w().default("now")
|
|
3625
|
+
}).unique(["scope", "key"]).index(["createdAt"]), _a = H("_voltro_devices", {
|
|
3626
|
+
id: h({ prefix: "device" }),
|
|
3627
|
+
tenantId: g(),
|
|
3628
|
+
name: g(),
|
|
3629
|
+
scopes: E().nullable(),
|
|
3630
|
+
pairingHash: g().maxLength(64).nullable(),
|
|
3631
|
+
pairingExpiresAt: w().nullable(),
|
|
3632
|
+
accessHash: g().maxLength(64).nullable(),
|
|
3633
|
+
accessExpiresAt: w().nullable(),
|
|
3634
|
+
refreshHash: g().maxLength(64).nullable(),
|
|
3635
|
+
refreshExpiresAt: w().nullable(),
|
|
3636
|
+
previousRefreshHash: g().maxLength(64).nullable(),
|
|
3637
|
+
generation: _().default(0),
|
|
3638
|
+
pairedAt: w().nullable(),
|
|
3639
|
+
lastSeenAt: w().nullable(),
|
|
3640
|
+
revokedAt: w().nullable(),
|
|
3641
|
+
revokedReason: g().nullable(),
|
|
3642
|
+
createdBy: g().nullable(),
|
|
3643
|
+
metadata: E().nullable(),
|
|
3644
|
+
createdAt: w()
|
|
3645
|
+
}).index(["tenantId"]).index(["pairingHash"]).index(["accessHash"]).index(["refreshHash"]).index(["previousRefreshHash"]), va = H("_voltro_tenant_selections", {
|
|
3646
|
+
id: h({ prefix: "tsel" }),
|
|
3647
|
+
subjectType: g().maxLength(32),
|
|
3648
|
+
subjectId: g(),
|
|
3649
|
+
tenantId: g(),
|
|
3650
|
+
selectedAt: w()
|
|
3651
|
+
}).primaryKey(["id"]).nonReactive(), ya = H("_voltro_kv", {
|
|
3652
|
+
id: h({ prefix: "kv" }),
|
|
3653
|
+
key: g().unique(),
|
|
3654
|
+
value: g().nullable(),
|
|
3655
|
+
expiresAt: w().nullable(),
|
|
3656
|
+
createdAt: w().default("now"),
|
|
3657
|
+
updatedAt: w().default("now").onUpdate("now")
|
|
3658
|
+
}).index(["expiresAt"]), ba = H("_voltro_api_keys", {
|
|
3659
|
+
id: h({ prefix: "apikey" }),
|
|
3660
|
+
tenantId: g().nullable(),
|
|
3661
|
+
name: g(),
|
|
3662
|
+
hashedKey: g().maxLength(64).unique(),
|
|
3663
|
+
keyPrefix: g(),
|
|
3664
|
+
scopes: E().nullable(),
|
|
3665
|
+
lastUsedAt: w().nullable(),
|
|
3666
|
+
requestCount: _().default(0),
|
|
3667
|
+
expiresAt: w().nullable(),
|
|
3668
|
+
revokedAt: w().nullable(),
|
|
3669
|
+
createdBy: g().nullable(),
|
|
3670
|
+
onBehalfOf: g().nullable(),
|
|
3671
|
+
metadata: E().nullable(),
|
|
3672
|
+
createdAt: w().default("now")
|
|
3673
|
+
}).index("byApiKeyTenant", ["tenantId"]), xa = H("_voltro_replica_observations", {
|
|
3674
|
+
id: h({ prefix: "robs" }),
|
|
3675
|
+
replicaId: g().maxLength(191),
|
|
3676
|
+
startedAt: w(),
|
|
3677
|
+
version: g().maxLength(64).nullable(),
|
|
3678
|
+
kind: g().maxLength(64),
|
|
3679
|
+
payload: g().nullable(),
|
|
3680
|
+
reachableAt: g().maxLength(255).nullable(),
|
|
3681
|
+
writtenAt: w().default("now").onUpdate("now")
|
|
3682
|
+
}).unique(["replicaId", "kind"]).index(["kind"]), Sa = [
|
|
3683
|
+
da,
|
|
3684
|
+
fa,
|
|
3685
|
+
ha
|
|
3686
|
+
], Ca = "_voltro_replace_in_progress", wa = H(Ca, {
|
|
3687
|
+
id: h({ prefix: "repl" }),
|
|
3688
|
+
startedAt: w().default("now"),
|
|
3689
|
+
kind: g().default("replace"),
|
|
3690
|
+
tables: g().nullable(),
|
|
3691
|
+
capture: g().nullable(),
|
|
3692
|
+
via: g(),
|
|
3693
|
+
staging: g().nullable(),
|
|
3694
|
+
heartbeatAt: w().nullable(),
|
|
3695
|
+
resumable: C().nullable()
|
|
3696
|
+
}).nonReactive(), Ta = 30, Ea = (e, t) => {
|
|
3519
3697
|
let n = typeof t == "number" && Number.isFinite(t) && t > 0 ? t : 30, r = Number(e.VOLTRO_STAGING_STALE_MINUTES);
|
|
3520
3698
|
return (Number.isFinite(r) && r > 0 ? r : n) * 6e4;
|
|
3521
|
-
},
|
|
3699
|
+
}, Da = (e) => e == null || String(e).length === 0 ? [] : String(e).split(",").map((e) => e.trim()).filter((e) => e.length > 0), Oa = (e) => {
|
|
3522
3700
|
let t = e.filter((e) => e.kind !== "staging");
|
|
3523
3701
|
if (t.length !== 0) return `refusing to start: a destructive data operation did not finish.
|
|
3524
3702
|
${t.map((e) => {
|
|
@@ -3533,7 +3711,7 @@ ${t.map((e) => {
|
|
|
3533
3711
|
|
|
3534
3712
|
When the data is back, or you have decided the current state is correct, clear the marker:
|
|
3535
3713
|
voltro data clear-replace-marker --yes`;
|
|
3536
|
-
},
|
|
3714
|
+
}, ka = (e, t, n) => {
|
|
3537
3715
|
let r = e.filter((e) => e.kind === "staging");
|
|
3538
3716
|
return {
|
|
3539
3717
|
all: r,
|
|
@@ -3543,7 +3721,7 @@ ${t.map((e) => {
|
|
|
3543
3721
|
return Number.isFinite(r) ? t - r >= n : !1;
|
|
3544
3722
|
})
|
|
3545
3723
|
};
|
|
3546
|
-
},
|
|
3724
|
+
}, Aa = (e, t) => {
|
|
3547
3725
|
if (e.all.length === 0) return;
|
|
3548
3726
|
let n = new Set(e.droppable.map((e) => e.id));
|
|
3549
3727
|
return `staged data-import leftovers:
|
|
@@ -3554,4 +3732,4 @@ ${e.all.map((e) => {
|
|
|
3554
3732
|
a reason to refuse the boot — it is a reason to know the disk is holding a copy of a bundle.`;
|
|
3555
3733
|
};
|
|
3556
3734
|
//#endregion
|
|
3557
|
-
export {
|
|
3735
|
+
export { oi as $, Le as $n, l as $r, pn as $t, la as A, Pt as An, A as Ar, rr as At, Wi as B, Tt as Bn, ie as Br, Hn as Bt, $i as C, nn as Cn, p as Cr, ri as Ct, ea as D, Gt as Dn, C as Dr, Ur as Dt, ca as E, en as En, x as Er, Or as Et, qi as F, jt as Fn, T as Fr, $n as Ft, zi as G, ft as Gn, oe as Gr, Pn as Gt, Qi as H, mt as Hn, _ as Hr, Bn as Ht, Yi as I, Nt as In, S as Ir, Qn as It, Li as J, ct as Jn, ae as Jr, J as Jt, Ri as K, dt as Kn, b as Kr, Ln as Kt, Ki as L, Et as Ln, y as Lr, Q as Lt, Zi as M, W as Mn, u as Mr, Yn as Mt, Ui as N, Ft as Nn, ee as Nr, Jn as Nt, ia as O, Kt as On, D as Or, Gr as Ot, Bi as P, kt as Pn, O as Pr, er as Pt, ii as Q, it as Qn, M as Qr, hn as Qt, Xi as R, wt as Rn, P as Rr, Wn as Rt, aa as S, Xt as Sn, ce as Sr, ui as St, sa as T, zt as Tn, I as Tr, Kr as Tt, Vi as U, H as Un, ne as Ur, Mn as Ut, Gi as V, gt as Vn, h as Vr, zn as Vt, Mi as W, ht as Wn, E as Wr, Fn as Wt, si as X, lt as Xn, v as Xr, _n as Xt, Ii as Y, ut as Yn, d as Yr, gn as Yt, di as Z, st as Zn, N as Zr, mn as Zt, pa as _, Vt as _n, pe as _r, yi as _t, Aa as a, Bt as an, Ke as ar, vi as at, Sa as b, an as bn, fe as br, fi as bt, Ea as c, Lt as cn, _e as cr, ei as ct, ga as d, Zt as dn, Pe as dr, ci as dt, g as ei, q as en, Re as er, ai as et, ya as f, Jt as fn, Fe as fr, mi as ft, xa as g, Ht as gn, Se as gr, pi as gt, ma as h, $t as hn, Me as hr, Yr as ht, Oa as i, dn as in, We as ir, Ti as it, oa as j, At as jn, f as jr, ir as jt, na as k, Mt as kn, k as kr, kr as kt, ba as l, Rt as ln, Ae as lr, gi as lt, da as m, Qt as mn, je as mr, $r as mt, Ta as n, te as ni, un as nn, Ge as nr, ni as nt, ka as o, tn as on, L as or, Xr as ot, ha as p, qt as pn, xe as pr, Qr as pt, Ni as q, pt as qn, F as qr, vn as qt, wa as r, ln as rn, B as rr, Jr as rt, Da as s, Ut as sn, we as sr, Zr as st, Ca as t, w as ti, cn as tn, Ve as tr, ki as tt, _a as u, sn as un, Ne as ur, li as ut, fa as v, It as vn, me as vr, ti as vt, ta as w, Yt as wn, j as wr, Ai as wt, ua as x, rn as xn, le as xr, Ei as xt, va as y, on as yn, de as yr, _i as yt, Ji as z, Ct as zn, re as zr, Vn as zt };
|