@voltro/database 0.75.0 → 0.76.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 +404 -0
- package/dist/{frameworkTables-CfWuWeFG.js → frameworkTables-CSY95jCs.js} +679 -429
- package/dist/index.d.ts +2 -0
- package/dist/index.js +644 -891
- package/dist/sql.d.ts +11 -0
- package/dist/sql.js +1225 -1196
- package/package.json +3 -3
|
@@ -20,11 +20,11 @@ var o = (e) => {
|
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
22
|
return t;
|
|
23
|
-
},
|
|
23
|
+
}, l = (e) => {
|
|
24
24
|
let t = [];
|
|
25
25
|
for (let [n, r] of Object.entries(e.fields)) r.crdtManaged === !0 && t.push(n);
|
|
26
26
|
return t;
|
|
27
|
-
},
|
|
27
|
+
}, u = class e {
|
|
28
28
|
definition;
|
|
29
29
|
constructor(e) {
|
|
30
30
|
this.definition = e;
|
|
@@ -185,14 +185,14 @@ var o = (e) => {
|
|
|
185
185
|
__definition() {
|
|
186
186
|
return this.definition;
|
|
187
187
|
}
|
|
188
|
-
},
|
|
188
|
+
}, d = (e) => new u({
|
|
189
189
|
type: e,
|
|
190
190
|
nullable: !1,
|
|
191
191
|
unique: !1,
|
|
192
192
|
hasDefault: !1
|
|
193
193
|
});
|
|
194
|
-
function
|
|
195
|
-
return new
|
|
194
|
+
function f(e) {
|
|
195
|
+
return new u({
|
|
196
196
|
type: "id",
|
|
197
197
|
nullable: !1,
|
|
198
198
|
unique: !0,
|
|
@@ -200,10 +200,10 @@ function d(e) {
|
|
|
200
200
|
idSchemeInput: e
|
|
201
201
|
});
|
|
202
202
|
}
|
|
203
|
-
var
|
|
203
|
+
var p = () => d("text"), m = () => d("integer"), h = () => d("real"), g = (e, t = 0) => {
|
|
204
204
|
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
205
|
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
|
|
206
|
+
return new u({
|
|
207
207
|
type: "decimal",
|
|
208
208
|
nullable: !1,
|
|
209
209
|
unique: !1,
|
|
@@ -211,12 +211,12 @@ var f = () => u("text"), p = () => u("integer"), te = () => u("real"), ne = (e,
|
|
|
211
211
|
precision: e,
|
|
212
212
|
scale: t
|
|
213
213
|
});
|
|
214
|
-
},
|
|
214
|
+
}, ee = g, te = () => d("bigint"), ne = (e, t) => {
|
|
215
215
|
if (t.length === 0) throw Error(`dbEnum('${e}', []): enum must have at least one value`);
|
|
216
216
|
return {
|
|
217
217
|
name: e,
|
|
218
218
|
values: t,
|
|
219
|
-
column: () => new
|
|
219
|
+
column: () => new u({
|
|
220
220
|
type: "enum",
|
|
221
221
|
nullable: !1,
|
|
222
222
|
unique: !1,
|
|
@@ -225,26 +225,26 @@ var f = () => u("text"), p = () => u("integer"), te = () => u("real"), ne = (e,
|
|
|
225
225
|
enumValues: t
|
|
226
226
|
})
|
|
227
227
|
};
|
|
228
|
-
},
|
|
228
|
+
}, re = () => d("boolean"), _ = () => d("timestamp"), ie = () => d("date"), v = () => d("json"), y = () => d("bytes"), b = () => new u({
|
|
229
229
|
type: "bytes",
|
|
230
230
|
nullable: !0,
|
|
231
231
|
unique: !1,
|
|
232
232
|
hasDefault: !1,
|
|
233
233
|
crdtManaged: !0
|
|
234
|
-
}),
|
|
234
|
+
}), ae = () => new u({
|
|
235
235
|
type: "bytes",
|
|
236
236
|
nullable: !0,
|
|
237
237
|
unique: !1,
|
|
238
238
|
hasDefault: !1,
|
|
239
239
|
crdtManaged: !0
|
|
240
|
-
}),
|
|
240
|
+
}), x = () => {
|
|
241
241
|
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");
|
|
242
242
|
};
|
|
243
|
-
function
|
|
244
|
-
return
|
|
243
|
+
function S(e) {
|
|
244
|
+
return C(x, e);
|
|
245
245
|
}
|
|
246
|
-
function
|
|
247
|
-
return new
|
|
246
|
+
function C(e, t) {
|
|
247
|
+
return new u({
|
|
248
248
|
type: "reference",
|
|
249
249
|
nullable: !1,
|
|
250
250
|
unique: !1,
|
|
@@ -259,15 +259,15 @@ function fe(e, t) {
|
|
|
259
259
|
...t?.orphanPolicy ? { orphanPolicy: t.orphanPolicy } : {}
|
|
260
260
|
});
|
|
261
261
|
}
|
|
262
|
-
var
|
|
262
|
+
var oe = () => new u({
|
|
263
263
|
type: "text",
|
|
264
264
|
nullable: !0,
|
|
265
265
|
unique: !1,
|
|
266
266
|
hasDefault: !1,
|
|
267
267
|
dropped: !0
|
|
268
|
-
}),
|
|
268
|
+
}), se = (e, t) => {
|
|
269
269
|
if (!Number.isInteger(e) || e <= 0) throw Error(`vector(${String(e)}): dimension must be a positive integer (the embedding length, e.g. vector(1536)).`);
|
|
270
|
-
return new
|
|
270
|
+
return new u({
|
|
271
271
|
type: "vector",
|
|
272
272
|
nullable: !1,
|
|
273
273
|
unique: !1,
|
|
@@ -275,13 +275,13 @@ var pe = () => new l({
|
|
|
275
275
|
vectorDim: e,
|
|
276
276
|
vectorPrecision: t?.precision ?? "float32"
|
|
277
277
|
});
|
|
278
|
-
},
|
|
278
|
+
}, ce = (e) => new u({
|
|
279
279
|
type: "array",
|
|
280
280
|
nullable: !1,
|
|
281
281
|
unique: !1,
|
|
282
282
|
hasDefault: !1,
|
|
283
283
|
arrayElement: e.__definition().type
|
|
284
|
-
}),
|
|
284
|
+
}), le = () => d("interval"), ue = (e, t = 4326) => new u({
|
|
285
285
|
type: "text",
|
|
286
286
|
nullable: !1,
|
|
287
287
|
unique: !1,
|
|
@@ -291,7 +291,7 @@ var pe = () => new l({
|
|
|
291
291
|
geomKind: e,
|
|
292
292
|
srid: t
|
|
293
293
|
}
|
|
294
|
-
}),
|
|
294
|
+
}), de = (e, t = 4326) => new u({
|
|
295
295
|
type: "text",
|
|
296
296
|
nullable: !1,
|
|
297
297
|
unique: !1,
|
|
@@ -301,163 +301,163 @@ var pe = () => new l({
|
|
|
301
301
|
geomKind: e,
|
|
302
302
|
srid: t
|
|
303
303
|
}
|
|
304
|
-
}),
|
|
304
|
+
}), fe = (e) => new u({
|
|
305
305
|
type: "raw",
|
|
306
306
|
nullable: !1,
|
|
307
307
|
unique: !1,
|
|
308
308
|
hasDefault: !1,
|
|
309
309
|
rawDdl: e
|
|
310
|
-
}),
|
|
310
|
+
}), w = (e) => {
|
|
311
311
|
let t = {};
|
|
312
312
|
for (let [n, r] of Object.entries(e)) t[n] = r.__definition();
|
|
313
313
|
return t;
|
|
314
|
-
},
|
|
315
|
-
let n =
|
|
316
|
-
return
|
|
314
|
+
}, pe = /* @__PURE__ */ new WeakMap(), me = (e) => typeof e == "object" && e ? pe.get(e) : void 0, he = (e, t = {}) => {
|
|
315
|
+
let n = p();
|
|
316
|
+
return pe.set(n, {
|
|
317
317
|
target: e,
|
|
318
318
|
orphanPolicy: t.orphanPolicy ?? "keep",
|
|
319
319
|
onSoftDelete: t.onSoftDelete ?? !1
|
|
320
320
|
}), n;
|
|
321
|
-
},
|
|
321
|
+
}, T = /* @__PURE__ */ new Map(), ge = (e, t) => {
|
|
322
322
|
if (t.from === t.to) throw Error(`declareEnumRename('${e}'): \`from\` and \`to\` are both '${t.from}' — a rename must change the value.`);
|
|
323
|
-
let n =
|
|
323
|
+
let n = T.get(e) ?? [];
|
|
324
324
|
for (let r of n) {
|
|
325
325
|
if (r.from === t.from && r.to === t.to) return;
|
|
326
326
|
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}'.`);
|
|
327
327
|
}
|
|
328
|
-
n.push(t),
|
|
329
|
-
},
|
|
330
|
-
|
|
331
|
-
},
|
|
328
|
+
n.push(t), T.set(e, n);
|
|
329
|
+
}, _e = (e) => T.get(e) ?? [], ve = () => T, ye = () => {
|
|
330
|
+
T.clear();
|
|
331
|
+
}, be = (t) => {
|
|
332
332
|
let r = t;
|
|
333
333
|
for (let t = 0; t < 4 && n.isFiberFailure(r); t++) r = e.squash(r[n.FiberFailureCauseId]);
|
|
334
334
|
return r;
|
|
335
|
-
},
|
|
335
|
+
}, xe = (t, r = 0) => {
|
|
336
336
|
if (r >= 4 || !n.isFiberFailure(t)) return [t];
|
|
337
337
|
let i = t[n.FiberFailureCauseId], a = [...e.failures(i), ...e.defects(i)];
|
|
338
338
|
if (a.length === 0) return [e.squash(i)];
|
|
339
339
|
let o = [];
|
|
340
|
-
for (let e of a.slice(0, 8)) o.push(...
|
|
340
|
+
for (let e of a.slice(0, 8)) o.push(...xe(e, r + 1));
|
|
341
341
|
return o;
|
|
342
|
-
},
|
|
343
|
-
let t = {}, n = [], r =
|
|
342
|
+
}, Se = (e) => e.dbCode !== void 0 || e.dbErrno !== void 0 || e.dbNumber !== void 0 || e.dbSqlState !== void 0 || e.dbConstraint !== void 0, Ce = (e) => {
|
|
343
|
+
let t = {}, n = [], r = be(e);
|
|
344
344
|
for (let e = 0; e < 8 && typeof r == "object" && r; e++) {
|
|
345
345
|
let e = r;
|
|
346
346
|
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);
|
|
347
347
|
let i = e.sqlMessage ?? e.detail;
|
|
348
348
|
t.dbMessage === void 0 && typeof i == "string" && (t.dbMessage = i);
|
|
349
349
|
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;
|
|
350
|
-
(o || s) && n.push(`${o || "Error"}${s ? `: ${s.slice(0, 200)}` : ""}`), r =
|
|
350
|
+
(o || s) && n.push(`${o || "Error"}${s ? `: ${s.slice(0, 200)}` : ""}`), r = be(e.cause);
|
|
351
351
|
}
|
|
352
352
|
return n.length > 0 && (t.dbCauseChain = n.join(" ← "), t.dbMessage === void 0 && (t.dbMessage = n[n.length - 1])), t;
|
|
353
|
-
},
|
|
354
|
-
let t =
|
|
353
|
+
}, we = (e) => {
|
|
354
|
+
let t = xe(e).map(Ce);
|
|
355
355
|
if (t.length <= 1) return t[0] ?? {};
|
|
356
|
-
let n = t.find(
|
|
356
|
+
let n = t.find(Se) ?? t[0], r = t.filter((e) => e !== n).map((e) => e.dbCauseChain).filter((e) => typeof e == "string");
|
|
357
357
|
if (r.length === 0) return n;
|
|
358
358
|
let i = typeof n.dbCauseChain == "string" ? n.dbCauseChain : void 0;
|
|
359
359
|
return {
|
|
360
360
|
...n,
|
|
361
361
|
dbCauseChain: [i, ...r].filter(Boolean).join(" ‖ ")
|
|
362
362
|
};
|
|
363
|
-
},
|
|
364
|
-
let n =
|
|
363
|
+
}, Te = (e, t) => {
|
|
364
|
+
let n = we(e), r = je(n, t);
|
|
365
365
|
if (r !== void 0) {
|
|
366
366
|
let e = r.constraint ?? r.column;
|
|
367
367
|
return e === void 0 ? r.kind : `${r.kind}: ${e}`;
|
|
368
368
|
}
|
|
369
|
-
let i = n.dbCode ?? n.dbSqlState ?? n.dbErrno ?? n.dbNumber, a =
|
|
370
|
-
return i !== void 0 &&
|
|
371
|
-
},
|
|
369
|
+
let i = n.dbCode ?? n.dbSqlState ?? n.dbErrno ?? n.dbNumber, a = Oe(e);
|
|
370
|
+
return i !== void 0 && Ee.test(String(i)) ? `${a} (${String(i)})` : a;
|
|
371
|
+
}, Ee = /^[A-Za-z0-9_]{1,32}$/, De = /^[A-Za-z_][A-Za-z0-9_]{0,63}$/, Oe = (e) => {
|
|
372
372
|
let t = e?._tag, n = e?.name, r = (typeof t == "string" ? t : typeof n == "string" ? n : "").split(/[^A-Za-z0-9_]+/).filter(Boolean).pop();
|
|
373
|
-
return r !== void 0 &&
|
|
374
|
-
},
|
|
373
|
+
return r !== void 0 && De.test(r) ? r : "unknown";
|
|
374
|
+
}, ke = /^[A-Za-z_][A-Za-z0-9_$]*$/, E = (e) => e !== void 0 && e.length <= 128 && ke.test(e) ? e : void 0, Ae = (e) => e === void 0 ? void 0 : e.split(".").pop() ?? e, D = (e, ...t) => {
|
|
375
375
|
for (let n of t) {
|
|
376
376
|
let t = n.exec(e);
|
|
377
377
|
if (t?.[1] !== void 0) return t[1];
|
|
378
378
|
}
|
|
379
|
-
},
|
|
379
|
+
}, je = (e, t) => {
|
|
380
380
|
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}`;
|
|
381
381
|
if (n === "23503") {
|
|
382
|
-
let t =
|
|
382
|
+
let t = E(e.dbConstraint);
|
|
383
383
|
return {
|
|
384
384
|
kind: /is still referenced from table/i.test(o) ? "foreignKeyInUse" : "foreignKey",
|
|
385
385
|
...t === void 0 ? {} : { constraint: t }
|
|
386
386
|
};
|
|
387
387
|
}
|
|
388
388
|
if (n === "23505") {
|
|
389
|
-
let t =
|
|
389
|
+
let t = E(e.dbConstraint);
|
|
390
390
|
return {
|
|
391
391
|
kind: "unique",
|
|
392
392
|
...t === void 0 ? {} : { constraint: t }
|
|
393
393
|
};
|
|
394
394
|
}
|
|
395
395
|
if (n === "23502") {
|
|
396
|
-
let t =
|
|
396
|
+
let t = E(e.dbColumn);
|
|
397
397
|
return {
|
|
398
398
|
kind: "notNull",
|
|
399
399
|
...t === void 0 ? {} : { column: t }
|
|
400
400
|
};
|
|
401
401
|
}
|
|
402
402
|
if (n === "23514") {
|
|
403
|
-
let t =
|
|
403
|
+
let t = E(e.dbConstraint);
|
|
404
404
|
return {
|
|
405
405
|
kind: "check",
|
|
406
406
|
...t === void 0 ? {} : { constraint: t }
|
|
407
407
|
};
|
|
408
408
|
}
|
|
409
409
|
if (r === 1452 || r === 1451) {
|
|
410
|
-
let e =
|
|
410
|
+
let e = E(D(o, /CONSTRAINT `([^`]+)`/));
|
|
411
411
|
return {
|
|
412
412
|
kind: r === 1451 ? "foreignKeyInUse" : "foreignKey",
|
|
413
413
|
...e === void 0 ? {} : { constraint: e }
|
|
414
414
|
};
|
|
415
415
|
}
|
|
416
416
|
if (r === 1062) {
|
|
417
|
-
let e =
|
|
417
|
+
let e = E(Ae(D(o, /for key '([^']+)'/)));
|
|
418
418
|
return {
|
|
419
419
|
kind: "unique",
|
|
420
420
|
...e === void 0 ? {} : { constraint: e }
|
|
421
421
|
};
|
|
422
422
|
}
|
|
423
423
|
if (r === 1048 || r === 1364) {
|
|
424
|
-
let e =
|
|
424
|
+
let e = E(D(o, /Column '([^']+)' cannot be null/, /Field '([^']+)' doesn't have a default value/));
|
|
425
425
|
return {
|
|
426
426
|
kind: "notNull",
|
|
427
427
|
...e === void 0 ? {} : { column: e }
|
|
428
428
|
};
|
|
429
429
|
}
|
|
430
430
|
if (r === 3819 || r === 4025) {
|
|
431
|
-
let e =
|
|
431
|
+
let e = E(D(o, /Check constraint '([^']+)'/, /CONSTRAINT `([^`]+)` failed/));
|
|
432
432
|
return {
|
|
433
433
|
kind: "check",
|
|
434
434
|
...e === void 0 ? {} : { constraint: e }
|
|
435
435
|
};
|
|
436
436
|
}
|
|
437
437
|
if (i === 547) {
|
|
438
|
-
let e =
|
|
438
|
+
let e = D(o, /(?:FOREIGN KEY|REFERENCE) constraint "([^"]+)"/), t = D(o, /CHECK constraint "([^"]+)"/);
|
|
439
439
|
if (t !== void 0 && e === void 0) {
|
|
440
|
-
let e =
|
|
440
|
+
let e = E(t);
|
|
441
441
|
return {
|
|
442
442
|
kind: "check",
|
|
443
443
|
...e === void 0 ? {} : { constraint: e }
|
|
444
444
|
};
|
|
445
445
|
}
|
|
446
|
-
let n = /REFERENCE constraint/.test(o), r =
|
|
446
|
+
let n = /REFERENCE constraint/.test(o), r = E(e);
|
|
447
447
|
return {
|
|
448
448
|
kind: n ? "foreignKeyInUse" : "foreignKey",
|
|
449
449
|
...r === void 0 ? {} : { constraint: r }
|
|
450
450
|
};
|
|
451
451
|
}
|
|
452
452
|
if (i === 2627 || i === 2601) {
|
|
453
|
-
let e =
|
|
453
|
+
let e = E(D(o, /(?:UNIQUE KEY|PRIMARY KEY) constraint '([^']+)'/, /index '([^']+)'/));
|
|
454
454
|
return {
|
|
455
455
|
kind: "unique",
|
|
456
456
|
...e === void 0 ? {} : { constraint: e }
|
|
457
457
|
};
|
|
458
458
|
}
|
|
459
459
|
if (i === 515) {
|
|
460
|
-
let e =
|
|
460
|
+
let e = E(D(o, /Cannot insert the value NULL into column '([^']+)'/));
|
|
461
461
|
return {
|
|
462
462
|
kind: "notNull",
|
|
463
463
|
...e === void 0 ? {} : { column: e }
|
|
@@ -465,34 +465,34 @@ var pe = () => new l({
|
|
|
465
465
|
}
|
|
466
466
|
if (n === "SQLITE_CONSTRAINT_FOREIGNKEY") return { kind: t === "delete" || t === "deleteMany" || t === "hardDelete" ? "foreignKeyInUse" : "foreignKey" };
|
|
467
467
|
if (n === "SQLITE_CONSTRAINT_UNIQUE" || n === "SQLITE_CONSTRAINT_PRIMARYKEY") {
|
|
468
|
-
let e =
|
|
468
|
+
let e = E(Ae(D(o, /UNIQUE constraint failed: ([^,\s]+)/)));
|
|
469
469
|
return {
|
|
470
470
|
kind: "unique",
|
|
471
471
|
...e === void 0 ? {} : { column: e }
|
|
472
472
|
};
|
|
473
473
|
}
|
|
474
474
|
if (n === "SQLITE_CONSTRAINT_NOTNULL") {
|
|
475
|
-
let e =
|
|
475
|
+
let e = E(Ae(D(o, /NOT NULL constraint failed: ([^,\s]+)/)));
|
|
476
476
|
return {
|
|
477
477
|
kind: "notNull",
|
|
478
478
|
...e === void 0 ? {} : { column: e }
|
|
479
479
|
};
|
|
480
480
|
}
|
|
481
481
|
if (n === "SQLITE_CONSTRAINT_CHECK") {
|
|
482
|
-
let e =
|
|
482
|
+
let e = E(D(a, /CHECK constraint failed: (.+)$/));
|
|
483
483
|
return {
|
|
484
484
|
kind: "check",
|
|
485
485
|
...e === void 0 ? {} : { constraint: e }
|
|
486
486
|
};
|
|
487
487
|
}
|
|
488
|
-
},
|
|
489
|
-
let t =
|
|
488
|
+
}, Me = (e) => {
|
|
489
|
+
let t = je(e)?.kind;
|
|
490
490
|
return t === "foreignKey" || t === "foreignKeyInUse";
|
|
491
|
-
},
|
|
491
|
+
}, Ne = (e) => {
|
|
492
492
|
let t = e.dbCode, n = e.dbErrno;
|
|
493
493
|
return t === "57014" || n === 3024 || n === 1969 || t === "ETIMEOUT" || t === "SQLITE_INTERRUPT";
|
|
494
|
-
},
|
|
495
|
-
let t =
|
|
494
|
+
}, Pe = (e) => {
|
|
495
|
+
let t = we(e), n = [
|
|
496
496
|
t.dbCode === void 0 ? void 0 : `code=${String(t.dbCode)}`,
|
|
497
497
|
t.dbErrno === void 0 ? void 0 : `errno=${String(t.dbErrno)}`,
|
|
498
498
|
t.dbNumber === void 0 ? void 0 : `number=${String(t.dbNumber)}`,
|
|
@@ -501,7 +501,7 @@ var pe = () => new l({
|
|
|
501
501
|
t.dbPlaceholders === void 0 ? void 0 : `placeholders=${String(t.dbPlaceholders)}`
|
|
502
502
|
].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)}…`}` : "";
|
|
503
503
|
if (a !== void 0 || n.length !== 0) return [a, n.length > 0 ? `[${n.join(" ")}]` : void 0].filter((e) => e !== void 0 && e !== "").join(" ") + s + o;
|
|
504
|
-
},
|
|
504
|
+
}, Fe = (e) => Object.entries(e).map(([e, t]) => `${e}:${Ie(t)}`).join(" "), Ie = (e) => {
|
|
505
505
|
if (e === null) return "null";
|
|
506
506
|
if (e === void 0) return "undefined";
|
|
507
507
|
if (typeof e == "bigint") return "bigint";
|
|
@@ -511,24 +511,24 @@ var pe = () => new l({
|
|
|
511
511
|
if (globalThis.Buffer !== void 0 && globalThis.Buffer.isBuffer(e)) return "Buffer";
|
|
512
512
|
let t = e.constructor?.name;
|
|
513
513
|
return typeof t == "string" && t !== "" ? t : "Object";
|
|
514
|
-
},
|
|
515
|
-
|
|
516
|
-
},
|
|
517
|
-
let e =
|
|
518
|
-
return
|
|
519
|
-
},
|
|
514
|
+
}, Le = 63, Re = 60, O = [], k = (e) => {
|
|
515
|
+
O.includes(e) || O.push(e);
|
|
516
|
+
}, ze = () => {
|
|
517
|
+
let e = O.slice();
|
|
518
|
+
return O.length = 0, e;
|
|
519
|
+
}, Be = /^[a-zA-Z_][a-zA-Z0-9_]*$/, Ve = (e, t) => {
|
|
520
520
|
if (t.length === 0) throw Error(`${e} cannot be empty.`);
|
|
521
|
-
if (!
|
|
522
|
-
},
|
|
523
|
-
if (
|
|
524
|
-
e.length > 60 &&
|
|
525
|
-
}, k = (e, t) => {
|
|
526
|
-
if (D("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.`);
|
|
527
|
-
t.length > 60 && E(`column '${t}' on table '${e}' is ${t.length} chars — close to the 63-byte limit.`);
|
|
528
|
-
}, A = (e, t, n, r) => {
|
|
529
|
-
if (D("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.`);
|
|
530
|
-
t.length > 60 && E(`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.` : ""}`);
|
|
521
|
+
if (!Be.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_]*$/.`);
|
|
522
|
+
}, A = (e) => {
|
|
523
|
+
if (Ve("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.`);
|
|
524
|
+
e.length > 60 && k(`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.`);
|
|
531
525
|
}, j = (e, t) => {
|
|
526
|
+
if (Ve("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.`);
|
|
527
|
+
t.length > 60 && k(`column '${t}' on table '${e}' is ${t.length} chars — close to the 63-byte limit.`);
|
|
528
|
+
}, M = (e, t, n, r) => {
|
|
529
|
+
if (Ve("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.`);
|
|
530
|
+
t.length > 60 && k(`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.` : ""}`);
|
|
531
|
+
}, N = (e, t) => {
|
|
532
532
|
if (e.length === 0) throw Error(`typeid prefix on table '${t.tableName}' cannot be empty.`);
|
|
533
533
|
if (!/^[a-z][a-z0-9_]*$/.test(e)) {
|
|
534
534
|
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_]*$/.";
|
|
@@ -538,44 +538,44 @@ var pe = () => new l({
|
|
|
538
538
|
let n = t.kind === "derived" ? "shorten the table name, or supply an explicit short prefix via id({ prefix: '...' })." : "pick a shorter prefix.";
|
|
539
539
|
throw Error(`typeid prefix '${e}' on table '${t.tableName}' is ${e.length} chars — exceeds the 63-byte limit; ${n}`);
|
|
540
540
|
}
|
|
541
|
-
e.length > 60 &&
|
|
542
|
-
},
|
|
541
|
+
e.length > 60 && k(`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).`);
|
|
542
|
+
}, He = 1704067200000n, Ue = 10n, We = 12n, Ge = (1n << Ue) - 1n, Ke = (1n << We) - 1n, qe = We, Je = 22n, Ye = () => {
|
|
543
543
|
let e = process.env.SNOWFLAKE_MACHINE_ID;
|
|
544
544
|
if (e === void 0 || e === "") return 0n;
|
|
545
545
|
let t = BigInt(e);
|
|
546
|
-
if (t < 0n || t >
|
|
546
|
+
if (t < 0n || t > Ge) throw Error(`SNOWFLAKE_MACHINE_ID out of range: ${e}. Must be 0..${Ge}.`);
|
|
547
547
|
return t;
|
|
548
|
-
},
|
|
548
|
+
}, Xe = () => ({
|
|
549
549
|
lastMs: 0n,
|
|
550
550
|
sequence: 0n,
|
|
551
|
-
machineId:
|
|
552
|
-
}),
|
|
553
|
-
|
|
554
|
-
},
|
|
555
|
-
let t =
|
|
556
|
-
for (; t <= e;) t =
|
|
551
|
+
machineId: Ye()
|
|
552
|
+
}), P, Ze = () => (P === void 0 && (P = Xe()), P), Qe = () => {
|
|
553
|
+
P = Xe();
|
|
554
|
+
}, $e = () => BigInt(Date.now()), et = (e) => {
|
|
555
|
+
let t = $e();
|
|
556
|
+
for (; t <= e;) t = $e();
|
|
557
557
|
return t;
|
|
558
|
-
},
|
|
559
|
-
let e =
|
|
560
|
-
t === e.lastMs ? (e.sequence = e.sequence + 1n &
|
|
561
|
-
let n = t -
|
|
558
|
+
}, tt = () => {
|
|
559
|
+
let e = Ze(), t = $e();
|
|
560
|
+
t === e.lastMs ? (e.sequence = e.sequence + 1n & Ke, e.sequence === 0n && (t = et(e.lastMs), e.lastMs = t)) : (e.sequence = 0n, e.lastMs = t);
|
|
561
|
+
let n = t - He;
|
|
562
562
|
if (n < 0n) throw Error("Snowflake timestamp before configured epoch (2024-01-01). System clock is wrong.");
|
|
563
|
-
return (n <<
|
|
564
|
-
},
|
|
563
|
+
return (n << Je | e.machineId << qe | e.sequence).toString();
|
|
564
|
+
}, nt = (e) => {
|
|
565
565
|
let t = e.toLowerCase();
|
|
566
566
|
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.`);
|
|
567
567
|
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: '...' }).`);
|
|
568
568
|
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;
|
|
569
|
-
return
|
|
569
|
+
return N(n, {
|
|
570
570
|
kind: "derived",
|
|
571
571
|
tableName: e
|
|
572
572
|
}), n;
|
|
573
573
|
}, rt = (e, t) => {
|
|
574
574
|
if (e === void 0) return {
|
|
575
575
|
kind: "typeid",
|
|
576
|
-
prefix:
|
|
576
|
+
prefix: nt(t)
|
|
577
577
|
};
|
|
578
|
-
if ("prefix" in e && !("scheme" in e)) return
|
|
578
|
+
if ("prefix" in e && !("scheme" in e)) return N(e.prefix, {
|
|
579
579
|
kind: "explicit",
|
|
580
580
|
tableName: t
|
|
581
581
|
}), {
|
|
@@ -585,8 +585,8 @@ var pe = () => new l({
|
|
|
585
585
|
if (!("scheme" in e)) throw Error("invalid id() options: no scheme or prefix");
|
|
586
586
|
switch (e.scheme) {
|
|
587
587
|
case "typeid": {
|
|
588
|
-
let n = e.prefix ??
|
|
589
|
-
return e.prefix !== void 0 &&
|
|
588
|
+
let n = e.prefix ?? nt(t);
|
|
589
|
+
return e.prefix !== void 0 && N(e.prefix, {
|
|
590
590
|
kind: "explicit",
|
|
591
591
|
tableName: t
|
|
592
592
|
}), {
|
|
@@ -607,11 +607,11 @@ var pe = () => new l({
|
|
|
607
607
|
case "typeid": return i(e.prefix).toString();
|
|
608
608
|
case "ulid": return a();
|
|
609
609
|
case "numeric": return null;
|
|
610
|
-
case "snowflake": return
|
|
610
|
+
case "snowflake": return tt();
|
|
611
611
|
case "custom": return e.generate(t);
|
|
612
612
|
}
|
|
613
613
|
}, at = (e) => ({
|
|
614
|
-
fields:
|
|
614
|
+
fields: w(e.fields),
|
|
615
615
|
...e.id === void 0 ? {} : { id: e.id },
|
|
616
616
|
...e.requires === void 0 ? {} : { requires: e.requires },
|
|
617
617
|
...e.indexes === void 0 ? {} : { indexes: e.indexes },
|
|
@@ -654,7 +654,7 @@ var pe = () => new l({
|
|
|
654
654
|
"updatedBy",
|
|
655
655
|
"deletedAt",
|
|
656
656
|
"deletedBy"
|
|
657
|
-
], dt = (e) => e.id ?? `<anonymous mixin: ${Object.keys(e.fields).join(", ")}>`,
|
|
657
|
+
], dt = (e) => e.id ?? `<anonymous mixin: ${Object.keys(e.fields).join(", ")}>`, ft = (e, t) => `${e}_${t.join("_")}_idx`, pt = (e, t) => `${e}_${t.join("_")}_uq`, mt = (e, t, n, r, i) => {
|
|
658
658
|
if (n !== "hnsw") return;
|
|
659
659
|
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.`);
|
|
660
660
|
let a = r[0];
|
|
@@ -662,14 +662,14 @@ var pe = () => new l({
|
|
|
662
662
|
let o = i[a];
|
|
663
663
|
if (o === void 0) throw Error(`hnsw index '${t}' on table '${e}' references unknown column '${a}'.`);
|
|
664
664
|
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.`);
|
|
665
|
-
},
|
|
665
|
+
}, ht = (e, t) => {
|
|
666
666
|
let n;
|
|
667
667
|
for (let [r, i] of Object.entries(e)) i.type === "id" && i.idScheme === void 0 && (n === void 0 && (n = { ...e }), n[r] = {
|
|
668
668
|
...i,
|
|
669
669
|
idScheme: rt(i.idSchemeInput, t)
|
|
670
670
|
});
|
|
671
671
|
return n ?? e;
|
|
672
|
-
},
|
|
672
|
+
}, F = (e) => {
|
|
673
673
|
let t = e.appliedPrimaryKey ?? [];
|
|
674
674
|
return {
|
|
675
675
|
tableName: e.tableName,
|
|
@@ -688,8 +688,8 @@ var pe = () => new l({
|
|
|
688
688
|
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema },
|
|
689
689
|
fullTextIndex: ((t, n, r) => {
|
|
690
690
|
if (n.length === 0) throw Error(`fullTextIndex '${t}' on '${e.tableName}' has no columns.`);
|
|
691
|
-
if (
|
|
692
|
-
return
|
|
691
|
+
if (M(e.tableName, t, !1, n), e.appliedFullText.some((e) => e.name === t)) throw Error(`duplicate full-text index '${t}' on table '${e.tableName}'.`);
|
|
692
|
+
return F({
|
|
693
693
|
...e,
|
|
694
694
|
tableName: e.tableName,
|
|
695
695
|
fields: e.fields,
|
|
@@ -718,19 +718,19 @@ var pe = () => new l({
|
|
|
718
718
|
for (let t of n) for (let [n, a] of Object.entries(t.fields)) {
|
|
719
719
|
let o = i.get(n);
|
|
720
720
|
if (o !== void 0) throw Error(`mixin collision on column '${n}' in table '${e.tableName}': '${dt(o)}' and '${dt(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.`);
|
|
721
|
-
|
|
721
|
+
j(e.tableName, n), r[n] = a, i.set(n, t);
|
|
722
722
|
}
|
|
723
723
|
let a = [...e.appliedIndexes];
|
|
724
724
|
for (let t of n) for (let n of t.indexes ?? []) {
|
|
725
|
-
let t = n.name ??
|
|
726
|
-
a.some((e) => e.name === t) || (
|
|
725
|
+
let t = n.name ?? ft(e.tableName, n.fields);
|
|
726
|
+
a.some((e) => e.name === t) || (M(e.tableName, t, n.name === void 0, n.fields), mt(e.tableName, t, n.kind, n.fields, r), a.push({
|
|
727
727
|
name: t,
|
|
728
728
|
fields: n.fields,
|
|
729
729
|
...n.kind === void 0 ? {} : { kind: n.kind },
|
|
730
730
|
...n.kindOptions === void 0 ? {} : { kindOptions: n.kindOptions }
|
|
731
731
|
}));
|
|
732
732
|
}
|
|
733
|
-
return
|
|
733
|
+
return F({
|
|
734
734
|
...e,
|
|
735
735
|
tableName: e.tableName,
|
|
736
736
|
fields: r,
|
|
@@ -747,10 +747,10 @@ var pe = () => new l({
|
|
|
747
747
|
}),
|
|
748
748
|
index: ((...t) => {
|
|
749
749
|
let n, r, i, a = Array.isArray(t[0]);
|
|
750
|
-
if (a ? (r = t[0], i = t[1], n =
|
|
750
|
+
if (a ? (r = t[0], i = t[1], n = ft(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.`);
|
|
751
751
|
let o = r.filter((e) => typeof e == "string");
|
|
752
|
-
if (
|
|
753
|
-
return
|
|
752
|
+
if (M(e.tableName, n, a, o), mt(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.`);
|
|
753
|
+
return F({
|
|
754
754
|
...e,
|
|
755
755
|
tableName: e.tableName,
|
|
756
756
|
fields: e.fields,
|
|
@@ -774,8 +774,8 @@ var pe = () => new l({
|
|
|
774
774
|
expressionIndex: ((t, n, r) => {
|
|
775
775
|
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.`);
|
|
776
776
|
let i = n.filter((e) => typeof e == "string");
|
|
777
|
-
if (
|
|
778
|
-
return
|
|
777
|
+
if (M(e.tableName, t, !1, i), mt(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.`);
|
|
778
|
+
return F({
|
|
779
779
|
...e,
|
|
780
780
|
tableName: e.tableName,
|
|
781
781
|
fields: e.fields,
|
|
@@ -798,9 +798,9 @@ var pe = () => new l({
|
|
|
798
798
|
}),
|
|
799
799
|
unique: ((...t) => {
|
|
800
800
|
let n, r, i, a = Array.isArray(t[0]);
|
|
801
|
-
if (a ? (r = t[0], i = t[1], n =
|
|
802
|
-
if (
|
|
803
|
-
return
|
|
801
|
+
if (a ? (r = t[0], i = t[1], n = pt(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.`);
|
|
802
|
+
if (M(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.`);
|
|
803
|
+
return F({
|
|
804
804
|
...e,
|
|
805
805
|
tableName: e.tableName,
|
|
806
806
|
fields: e.fields,
|
|
@@ -821,10 +821,10 @@ var pe = () => new l({
|
|
|
821
821
|
}),
|
|
822
822
|
uniqueActive: ((...t) => {
|
|
823
823
|
let n, r, i, a = Array.isArray(t[0]);
|
|
824
|
-
if (a ? (r = t[0], i = t[1], n =
|
|
825
|
-
if (
|
|
824
|
+
if (a ? (r = t[0], i = t[1], n = ft(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.`);
|
|
825
|
+
if (M(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).`);
|
|
826
826
|
let o = i?.where ?? "\"deletedAt\" IS NULL";
|
|
827
|
-
return
|
|
827
|
+
return F({
|
|
828
828
|
...e,
|
|
829
829
|
tableName: e.tableName,
|
|
830
830
|
fields: e.fields,
|
|
@@ -846,8 +846,8 @@ var pe = () => new l({
|
|
|
846
846
|
}),
|
|
847
847
|
check: ((t, n) => {
|
|
848
848
|
if (n.trim().length === 0) throw Error(`CHECK '${t}' on table '${e.tableName}' has an empty expression.`);
|
|
849
|
-
if (
|
|
850
|
-
return
|
|
849
|
+
if (M(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.`);
|
|
850
|
+
return F({
|
|
851
851
|
...e,
|
|
852
852
|
tableName: e.tableName,
|
|
853
853
|
fields: e.fields,
|
|
@@ -869,7 +869,7 @@ var pe = () => new l({
|
|
|
869
869
|
if (t.trim().length === 0) throw Error(`rule on table '${e.tableName}' has an empty name.`);
|
|
870
870
|
let i = e.appliedRules ?? [];
|
|
871
871
|
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.`);
|
|
872
|
-
return
|
|
872
|
+
return F({
|
|
873
873
|
...e,
|
|
874
874
|
appliedRules: [...i, {
|
|
875
875
|
name: t,
|
|
@@ -880,7 +880,7 @@ var pe = () => new l({
|
|
|
880
880
|
}),
|
|
881
881
|
renamedFrom: ((t) => {
|
|
882
882
|
if (t === e.tableName) throw Error(`renamedFrom('${t}') on table '${e.tableName}' names the table itself — drop the marker, there is nothing to rename.`);
|
|
883
|
-
return
|
|
883
|
+
return A(t), F({
|
|
884
884
|
...e,
|
|
885
885
|
previousTableName: t
|
|
886
886
|
});
|
|
@@ -895,7 +895,7 @@ var pe = () => new l({
|
|
|
895
895
|
}
|
|
896
896
|
if (t.length > 0) throw Error(`primaryKey([...]) declared twice on table '${e.tableName}'.`);
|
|
897
897
|
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.`);
|
|
898
|
-
return
|
|
898
|
+
return F({
|
|
899
899
|
...e,
|
|
900
900
|
tableName: e.tableName,
|
|
901
901
|
fields: e.fields,
|
|
@@ -910,7 +910,7 @@ var pe = () => new l({
|
|
|
910
910
|
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
911
911
|
});
|
|
912
912
|
}),
|
|
913
|
-
nonReactive: (() =>
|
|
913
|
+
nonReactive: (() => F({
|
|
914
914
|
...e,
|
|
915
915
|
tableName: e.tableName,
|
|
916
916
|
fields: e.fields,
|
|
@@ -924,7 +924,7 @@ var pe = () => new l({
|
|
|
924
924
|
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
925
925
|
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
926
926
|
})),
|
|
927
|
-
validate: ((t) =>
|
|
927
|
+
validate: ((t) => F({
|
|
928
928
|
...e,
|
|
929
929
|
tableName: e.tableName,
|
|
930
930
|
fields: e.fields,
|
|
@@ -938,7 +938,7 @@ var pe = () => new l({
|
|
|
938
938
|
insertSchema: t,
|
|
939
939
|
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
940
940
|
})),
|
|
941
|
-
validatePatch: ((t) =>
|
|
941
|
+
validatePatch: ((t) => F({
|
|
942
942
|
...e,
|
|
943
943
|
tableName: e.tableName,
|
|
944
944
|
fields: e.fields,
|
|
@@ -953,22 +953,22 @@ var pe = () => new l({
|
|
|
953
953
|
validatePatchSchema: r.partial(t)
|
|
954
954
|
}))
|
|
955
955
|
};
|
|
956
|
-
},
|
|
957
|
-
|
|
956
|
+
}, I = (e, t) => {
|
|
957
|
+
A(e);
|
|
958
958
|
let n = Object.entries(t).flatMap(([e, t]) => {
|
|
959
|
-
let n =
|
|
959
|
+
let n = me(t);
|
|
960
960
|
return n === void 0 ? [] : [{
|
|
961
961
|
column: e,
|
|
962
962
|
...n
|
|
963
963
|
}];
|
|
964
|
-
}), r =
|
|
965
|
-
for (let t of Object.keys(r))
|
|
964
|
+
}), r = ht(w(t), e);
|
|
965
|
+
for (let t of Object.keys(r)) j(e, t);
|
|
966
966
|
let i;
|
|
967
|
-
for (let [t, n] of Object.entries(r)) n.references ===
|
|
967
|
+
for (let [t, n] of Object.entries(r)) n.references === x && (n.references = () => {
|
|
968
968
|
if (i === void 0) throw Error(`selfReference() on '${e}.${t}' read before table() returned`);
|
|
969
969
|
return i;
|
|
970
970
|
});
|
|
971
|
-
return i =
|
|
971
|
+
return i = F({
|
|
972
972
|
appliedPluginRefs: n,
|
|
973
973
|
tableName: e,
|
|
974
974
|
fields: r,
|
|
@@ -980,7 +980,7 @@ var pe = () => new l({
|
|
|
980
980
|
appliedChecks: [],
|
|
981
981
|
appliedRules: []
|
|
982
982
|
}), i;
|
|
983
|
-
},
|
|
983
|
+
}, gt = (e) => e === "sqlite" || e === "turso", _t = (e) => e === "mysql" || e === "mariadb", L = (e, t) => {
|
|
984
984
|
switch (t) {
|
|
985
985
|
case "mysql":
|
|
986
986
|
case "mariadb": return `\`${e.replace(/`/g, "``")}\``;
|
|
@@ -989,51 +989,51 @@ var pe = () => new l({
|
|
|
989
989
|
case "sqlite":
|
|
990
990
|
case "turso": return `"${e.replace(/"/g, "\"\"")}"`;
|
|
991
991
|
}
|
|
992
|
-
},
|
|
993
|
-
let t =
|
|
992
|
+
}, vt = 1e4, yt = Symbol.for("@voltro/database/tableRegistry"), bt = globalThis, R = bt[yt] ?? (bt[yt] = /* @__PURE__ */ new Map()), xt = (e) => {
|
|
993
|
+
let t = R.get(e.tableName);
|
|
994
994
|
if (t === void 0) {
|
|
995
|
-
|
|
995
|
+
R.set(e.tableName, e);
|
|
996
996
|
return;
|
|
997
997
|
}
|
|
998
998
|
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.`);
|
|
999
|
-
},
|
|
1000
|
-
|
|
1001
|
-
},
|
|
1002
|
-
let t =
|
|
999
|
+
}, St = (e) => {
|
|
1000
|
+
R.get(e.tableName) === void 0 && R.set(e.tableName, e);
|
|
1001
|
+
}, z = (e) => R.get(e), Ct = (e) => {
|
|
1002
|
+
let t = R.get(e);
|
|
1003
1003
|
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.`);
|
|
1004
1004
|
return t;
|
|
1005
|
-
},
|
|
1006
|
-
|
|
1007
|
-
},
|
|
1005
|
+
}, wt = () => [...R.values()], Tt = (e) => R.delete(e), Et = () => {
|
|
1006
|
+
R.clear();
|
|
1007
|
+
}, Dt = (e) => R.get(e)?.isReactive !== !1, B = (e) => e.order ?? [], Ot = (e) => ({
|
|
1008
1008
|
op: "count",
|
|
1009
1009
|
alias: e ?? "count"
|
|
1010
|
-
}),
|
|
1010
|
+
}), kt = (e, t) => ({
|
|
1011
1011
|
op: "count-distinct",
|
|
1012
1012
|
column: e,
|
|
1013
1013
|
alias: t ?? `count_distinct_${e}`
|
|
1014
|
-
}),
|
|
1014
|
+
}), At = (e, t) => ({
|
|
1015
1015
|
op: "sum",
|
|
1016
1016
|
column: e,
|
|
1017
1017
|
alias: t ?? `sum_${e}`
|
|
1018
|
-
}),
|
|
1018
|
+
}), jt = (e, t) => ({
|
|
1019
1019
|
op: "avg",
|
|
1020
1020
|
column: e,
|
|
1021
1021
|
alias: t ?? `avg_${e}`
|
|
1022
|
-
}),
|
|
1022
|
+
}), Mt = (e, t) => ({
|
|
1023
1023
|
op: "min",
|
|
1024
1024
|
column: e,
|
|
1025
1025
|
alias: t ?? `min_${e}`
|
|
1026
|
-
}),
|
|
1026
|
+
}), Nt = (e, t) => ({
|
|
1027
1027
|
op: "max",
|
|
1028
1028
|
column: e,
|
|
1029
1029
|
alias: t ?? `max_${e}`
|
|
1030
|
-
}),
|
|
1030
|
+
}), Pt = (e, t) => ({
|
|
1031
1031
|
op: "column",
|
|
1032
1032
|
column: e,
|
|
1033
1033
|
alias: t ?? e
|
|
1034
|
-
}),
|
|
1034
|
+
}), V = (e) => (...t) => {
|
|
1035
1035
|
if (t.length < 2) throw Error(`${e}: requires at least two queries`);
|
|
1036
|
-
return
|
|
1036
|
+
return U({
|
|
1037
1037
|
table: t[0].descriptor.table,
|
|
1038
1038
|
predicate: void 0,
|
|
1039
1039
|
order: [],
|
|
@@ -1045,55 +1045,55 @@ var pe = () => new l({
|
|
|
1045
1045
|
queries: t.map((e) => e.descriptor)
|
|
1046
1046
|
}
|
|
1047
1047
|
});
|
|
1048
|
-
},
|
|
1048
|
+
}, Ft = V("union"), It = V("union-all"), Lt = V("intersect"), Rt = V("except"), H = (e) => ({ over: (t) => ({
|
|
1049
1049
|
...e,
|
|
1050
1050
|
window: t
|
|
1051
|
-
}) }),
|
|
1051
|
+
}) }), zt = (e = "rowNumber") => H({
|
|
1052
1052
|
op: "window-row-number",
|
|
1053
1053
|
alias: e
|
|
1054
|
-
}),
|
|
1054
|
+
}), Bt = (e = "rank") => H({
|
|
1055
1055
|
op: "window-rank",
|
|
1056
1056
|
alias: e
|
|
1057
|
-
}),
|
|
1057
|
+
}), Vt = (e = "denseRank") => H({
|
|
1058
1058
|
op: "window-dense-rank",
|
|
1059
1059
|
alias: e
|
|
1060
|
-
}),
|
|
1060
|
+
}), Ht = (e, t = 1, n) => H({
|
|
1061
1061
|
op: "window-lag",
|
|
1062
1062
|
column: e,
|
|
1063
1063
|
alias: n ?? `lag_${e}`,
|
|
1064
1064
|
offset: t
|
|
1065
|
-
}),
|
|
1065
|
+
}), Ut = (e, t = 1, n) => H({
|
|
1066
1066
|
op: "window-lead",
|
|
1067
1067
|
column: e,
|
|
1068
1068
|
alias: n ?? `lead_${e}`,
|
|
1069
1069
|
offset: t
|
|
1070
|
-
}),
|
|
1070
|
+
}), Wt = (e, t) => H({
|
|
1071
1071
|
op: "window-sum-over",
|
|
1072
1072
|
column: e,
|
|
1073
1073
|
alias: t ?? `sum_${e}_over`
|
|
1074
|
-
}),
|
|
1074
|
+
}), Gt = (e, t) => H({
|
|
1075
1075
|
op: "window-avg-over",
|
|
1076
1076
|
column: e,
|
|
1077
1077
|
alias: t ?? `avg_${e}_over`
|
|
1078
|
-
}),
|
|
1079
|
-
let r = n?.find((e) => e.name === t) ??
|
|
1078
|
+
}), Kt = (e, t, n) => {
|
|
1079
|
+
let r = n?.find((e) => e.name === t) ?? z(e)?.appliedFullText?.find((e) => e.name === t);
|
|
1080
1080
|
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.`);
|
|
1081
1081
|
return {
|
|
1082
1082
|
columns: r.columns,
|
|
1083
1083
|
...r.config === void 0 ? {} : { config: r.config },
|
|
1084
1084
|
...r.weights === void 0 ? {} : { weights: r.weights }
|
|
1085
1085
|
};
|
|
1086
|
-
},
|
|
1086
|
+
}, U = (e) => ({
|
|
1087
1087
|
descriptor: e,
|
|
1088
1088
|
where(t) {
|
|
1089
1089
|
let n = e.predicate ? { and: [e.predicate, t] } : t;
|
|
1090
|
-
return
|
|
1090
|
+
return U({
|
|
1091
1091
|
...e,
|
|
1092
1092
|
predicate: n
|
|
1093
1093
|
});
|
|
1094
1094
|
},
|
|
1095
1095
|
orderBy(t, n = "asc") {
|
|
1096
|
-
return
|
|
1096
|
+
return U({
|
|
1097
1097
|
...e,
|
|
1098
1098
|
order: [...e.order, {
|
|
1099
1099
|
column: t,
|
|
@@ -1102,43 +1102,43 @@ var pe = () => new l({
|
|
|
1102
1102
|
});
|
|
1103
1103
|
},
|
|
1104
1104
|
limit(t) {
|
|
1105
|
-
return
|
|
1105
|
+
return U({
|
|
1106
1106
|
...e,
|
|
1107
1107
|
take: t
|
|
1108
1108
|
});
|
|
1109
1109
|
},
|
|
1110
1110
|
offset(t) {
|
|
1111
|
-
return
|
|
1111
|
+
return U({
|
|
1112
1112
|
...e,
|
|
1113
1113
|
skip: t
|
|
1114
1114
|
});
|
|
1115
1115
|
},
|
|
1116
1116
|
select(...t) {
|
|
1117
|
-
return
|
|
1117
|
+
return U({
|
|
1118
1118
|
...e,
|
|
1119
1119
|
projection: t
|
|
1120
1120
|
});
|
|
1121
1121
|
},
|
|
1122
1122
|
using(t) {
|
|
1123
|
-
return
|
|
1123
|
+
return U({
|
|
1124
1124
|
...e,
|
|
1125
1125
|
usingIndex: t
|
|
1126
1126
|
});
|
|
1127
1127
|
},
|
|
1128
1128
|
withDeleted() {
|
|
1129
|
-
return
|
|
1129
|
+
return U({
|
|
1130
1130
|
...e,
|
|
1131
1131
|
includeDeleted: !0
|
|
1132
1132
|
});
|
|
1133
1133
|
},
|
|
1134
1134
|
forUpdate() {
|
|
1135
|
-
return
|
|
1135
|
+
return U({
|
|
1136
1136
|
...e,
|
|
1137
1137
|
lock: "update"
|
|
1138
1138
|
});
|
|
1139
1139
|
},
|
|
1140
1140
|
unscoped() {
|
|
1141
|
-
return
|
|
1141
|
+
return U({
|
|
1142
1142
|
...e,
|
|
1143
1143
|
crossTenant: !0
|
|
1144
1144
|
});
|
|
@@ -1148,13 +1148,13 @@ var pe = () => new l({
|
|
|
1148
1148
|
...e.eager ?? {},
|
|
1149
1149
|
...t
|
|
1150
1150
|
};
|
|
1151
|
-
return
|
|
1151
|
+
return U({
|
|
1152
1152
|
...e,
|
|
1153
1153
|
eager: n
|
|
1154
1154
|
});
|
|
1155
1155
|
},
|
|
1156
1156
|
count() {
|
|
1157
|
-
return
|
|
1157
|
+
return U({
|
|
1158
1158
|
...e,
|
|
1159
1159
|
projection: void 0,
|
|
1160
1160
|
aggregations: [{
|
|
@@ -1168,15 +1168,15 @@ var pe = () => new l({
|
|
|
1168
1168
|
...t,
|
|
1169
1169
|
alias: e
|
|
1170
1170
|
}));
|
|
1171
|
-
return
|
|
1171
|
+
return U({
|
|
1172
1172
|
...e,
|
|
1173
1173
|
projection: void 0,
|
|
1174
1174
|
aggregations: n
|
|
1175
1175
|
});
|
|
1176
1176
|
},
|
|
1177
1177
|
matching(t, n) {
|
|
1178
|
-
let r =
|
|
1179
|
-
return
|
|
1178
|
+
let r = Kt(e.table, t, e.fullTextIndexes);
|
|
1179
|
+
return U({
|
|
1180
1180
|
...e,
|
|
1181
1181
|
fullTextSearch: {
|
|
1182
1182
|
indexName: t,
|
|
@@ -1190,7 +1190,7 @@ var pe = () => new l({
|
|
|
1190
1190
|
rankBy(t) {
|
|
1191
1191
|
let n = e.fullTextSearch;
|
|
1192
1192
|
if (n === void 0) throw Error(".rankBy() requires a preceding .matching(...) clause — there is no full-text search to rank on this query.");
|
|
1193
|
-
return
|
|
1193
|
+
return U({
|
|
1194
1194
|
...e,
|
|
1195
1195
|
fullTextSearch: {
|
|
1196
1196
|
...n,
|
|
@@ -1209,7 +1209,7 @@ var pe = () => new l({
|
|
|
1209
1209
|
distance: r?.distance ?? "cosine",
|
|
1210
1210
|
...e.annClause?.ef === void 0 ? {} : { ef: e.annClause.ef }
|
|
1211
1211
|
};
|
|
1212
|
-
return
|
|
1212
|
+
return U({
|
|
1213
1213
|
...e,
|
|
1214
1214
|
annClause: i
|
|
1215
1215
|
});
|
|
@@ -1221,7 +1221,7 @@ var pe = () => new l({
|
|
|
1221
1221
|
distance: "cosine",
|
|
1222
1222
|
...e.annClause?.ef === void 0 ? {} : { ef: e.annClause.ef }
|
|
1223
1223
|
};
|
|
1224
|
-
return
|
|
1224
|
+
return U({
|
|
1225
1225
|
...e,
|
|
1226
1226
|
annClause: r,
|
|
1227
1227
|
take: n
|
|
@@ -1234,7 +1234,7 @@ var pe = () => new l({
|
|
|
1234
1234
|
column: "",
|
|
1235
1235
|
distance: "cosine"
|
|
1236
1236
|
};
|
|
1237
|
-
return
|
|
1237
|
+
return U({
|
|
1238
1238
|
...e,
|
|
1239
1239
|
annClause: {
|
|
1240
1240
|
...n,
|
|
@@ -1243,22 +1243,22 @@ var pe = () => new l({
|
|
|
1243
1243
|
});
|
|
1244
1244
|
},
|
|
1245
1245
|
use(t) {
|
|
1246
|
-
return
|
|
1246
|
+
return U({ ...t(e) });
|
|
1247
1247
|
},
|
|
1248
1248
|
distinct() {
|
|
1249
|
-
return
|
|
1249
|
+
return U({
|
|
1250
1250
|
...e,
|
|
1251
1251
|
distinct: !0
|
|
1252
1252
|
});
|
|
1253
1253
|
},
|
|
1254
1254
|
distinctOn(t) {
|
|
1255
|
-
return
|
|
1255
|
+
return U({
|
|
1256
1256
|
...e,
|
|
1257
1257
|
distinctOn: [...t]
|
|
1258
1258
|
});
|
|
1259
1259
|
},
|
|
1260
1260
|
as(t) {
|
|
1261
|
-
return
|
|
1261
|
+
return U({
|
|
1262
1262
|
...e,
|
|
1263
1263
|
alias: t
|
|
1264
1264
|
});
|
|
@@ -1270,7 +1270,7 @@ var pe = () => new l({
|
|
|
1270
1270
|
alias: n,
|
|
1271
1271
|
on: r
|
|
1272
1272
|
}];
|
|
1273
|
-
return
|
|
1273
|
+
return U({
|
|
1274
1274
|
...e,
|
|
1275
1275
|
joins: a
|
|
1276
1276
|
});
|
|
@@ -1282,7 +1282,7 @@ var pe = () => new l({
|
|
|
1282
1282
|
alias: n,
|
|
1283
1283
|
on: r
|
|
1284
1284
|
}];
|
|
1285
|
-
return
|
|
1285
|
+
return U({
|
|
1286
1286
|
...e,
|
|
1287
1287
|
joins: a
|
|
1288
1288
|
});
|
|
@@ -1292,7 +1292,7 @@ var pe = () => new l({
|
|
|
1292
1292
|
outputKey: e,
|
|
1293
1293
|
source: t
|
|
1294
1294
|
}));
|
|
1295
|
-
return
|
|
1295
|
+
return U({
|
|
1296
1296
|
...e,
|
|
1297
1297
|
projection: void 0,
|
|
1298
1298
|
joinedProjection: n
|
|
@@ -1301,7 +1301,7 @@ var pe = () => new l({
|
|
|
1301
1301
|
withCte(t, n) {
|
|
1302
1302
|
let r = e.ctes ?? [];
|
|
1303
1303
|
if (r.some((e) => e.name === t)) throw Error(`Query.withCte: duplicate CTE name '${t}'`);
|
|
1304
|
-
return
|
|
1304
|
+
return U({
|
|
1305
1305
|
...e,
|
|
1306
1306
|
ctes: [...r, {
|
|
1307
1307
|
name: t,
|
|
@@ -1312,7 +1312,7 @@ var pe = () => new l({
|
|
|
1312
1312
|
recursiveCte(t, n) {
|
|
1313
1313
|
let r = e.ctes ?? [];
|
|
1314
1314
|
if (r.some((e) => e.name === t)) throw Error(`Query.recursiveCte: duplicate CTE name '${t}'`);
|
|
1315
|
-
return
|
|
1315
|
+
return U({
|
|
1316
1316
|
...e,
|
|
1317
1317
|
ctes: [...r, {
|
|
1318
1318
|
name: t,
|
|
@@ -1323,20 +1323,20 @@ var pe = () => new l({
|
|
|
1323
1323
|
},
|
|
1324
1324
|
groupBy(t) {
|
|
1325
1325
|
let n = e.groupBy ? [...e.groupBy, ...t] : [...t];
|
|
1326
|
-
return
|
|
1326
|
+
return U({
|
|
1327
1327
|
...e,
|
|
1328
1328
|
groupBy: n
|
|
1329
1329
|
});
|
|
1330
1330
|
},
|
|
1331
1331
|
having(t) {
|
|
1332
1332
|
let n = e.having ? { and: [e.having, t] } : t;
|
|
1333
|
-
return
|
|
1333
|
+
return U({
|
|
1334
1334
|
...e,
|
|
1335
1335
|
having: n
|
|
1336
1336
|
});
|
|
1337
1337
|
},
|
|
1338
1338
|
exists() {
|
|
1339
|
-
return
|
|
1339
|
+
return U({
|
|
1340
1340
|
...e,
|
|
1341
1341
|
projection: void 0,
|
|
1342
1342
|
aggregations: [{
|
|
@@ -1347,8 +1347,8 @@ var pe = () => new l({
|
|
|
1347
1347
|
});
|
|
1348
1348
|
}
|
|
1349
1349
|
});
|
|
1350
|
-
function
|
|
1351
|
-
return
|
|
1350
|
+
function qt(e) {
|
|
1351
|
+
return U({
|
|
1352
1352
|
table: e.tableName,
|
|
1353
1353
|
predicate: void 0,
|
|
1354
1354
|
order: [],
|
|
@@ -1359,7 +1359,7 @@ function K(e) {
|
|
|
1359
1359
|
sourceTable: e
|
|
1360
1360
|
});
|
|
1361
1361
|
}
|
|
1362
|
-
var
|
|
1362
|
+
var Jt = (e, t, n) => Yt(e, "id", t, n), Yt = (e, t, n, r, i = "asc") => {
|
|
1363
1363
|
let a = [...e.order.filter((e) => e.column !== t), {
|
|
1364
1364
|
column: t,
|
|
1365
1365
|
direction: i
|
|
@@ -1374,21 +1374,21 @@ var Gt = (e, t, n) => Kt(e, "id", t, n), Kt = (e, t, n, r, i = "asc") => {
|
|
|
1374
1374
|
order: a,
|
|
1375
1375
|
take: r
|
|
1376
1376
|
};
|
|
1377
|
-
},
|
|
1377
|
+
}, Xt = (e) => {
|
|
1378
1378
|
let t = {};
|
|
1379
|
-
for (let [n, r] of Object.entries(e))
|
|
1379
|
+
for (let [n, r] of Object.entries(e)) xt(r), t[n] = qt(r);
|
|
1380
1380
|
return t;
|
|
1381
|
-
},
|
|
1382
|
-
if (
|
|
1383
|
-
let r =
|
|
1384
|
-
for (let t of Object.keys(r))
|
|
1381
|
+
}, Zt = (e) => e.isView === !0, Qt = (e, t, n) => {
|
|
1382
|
+
if (A(e), n.trim().length === 0) throw Error(`view('${e}', …): the SELECT body is empty — a view must define a query.`);
|
|
1383
|
+
let r = w(t);
|
|
1384
|
+
for (let t of Object.keys(r)) j(e, t);
|
|
1385
1385
|
return {
|
|
1386
1386
|
tableName: e,
|
|
1387
1387
|
fields: r,
|
|
1388
1388
|
isView: !0,
|
|
1389
1389
|
viewSelect: n
|
|
1390
1390
|
};
|
|
1391
|
-
},
|
|
1391
|
+
}, $t = (e) => qt({
|
|
1392
1392
|
...e,
|
|
1393
1393
|
isReactive: !1,
|
|
1394
1394
|
appliedMixins: [],
|
|
@@ -1396,8 +1396,8 @@ var Gt = (e, t, n) => Kt(e, "id", t, n), Kt = (e, t, n, r, i = "asc") => {
|
|
|
1396
1396
|
appliedUniques: [],
|
|
1397
1397
|
appliedFullText: [],
|
|
1398
1398
|
appliedChecks: []
|
|
1399
|
-
}),
|
|
1400
|
-
let r = n === null ?
|
|
1399
|
+
}), en = (e, t, n = null) => {
|
|
1400
|
+
let r = n === null ? L(e.tableName, t) : `${L(n, t)}.${L(e.tableName, t)}`, i = e.viewSelect.trim();
|
|
1401
1401
|
switch (t) {
|
|
1402
1402
|
case "postgres":
|
|
1403
1403
|
case "mysql":
|
|
@@ -1406,7 +1406,7 @@ var Gt = (e, t, n) => Kt(e, "id", t, n), Kt = (e, t, n, r, i = "asc") => {
|
|
|
1406
1406
|
case "sqlite":
|
|
1407
1407
|
case "turso": return `DROP VIEW IF EXISTS ${r};\nCREATE VIEW ${r} AS ${i};`;
|
|
1408
1408
|
}
|
|
1409
|
-
},
|
|
1409
|
+
}, tn = (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, nn = (e) => {
|
|
1410
1410
|
if (e == null || typeof e != "string") return e;
|
|
1411
1411
|
let t = e.trim();
|
|
1412
1412
|
if (t.length === 0) return e;
|
|
@@ -1417,7 +1417,7 @@ var Gt = (e, t, n) => Kt(e, "id", t, n), Kt = (e, t, n, r, i = "asc") => {
|
|
|
1417
1417
|
} catch {
|
|
1418
1418
|
return e;
|
|
1419
1419
|
}
|
|
1420
|
-
},
|
|
1420
|
+
}, rn = (e) => e == null || typeof e == "string" ? e : typeof e == "number" || typeof e == "bigint" ? String(e) : e, an = (e) => {
|
|
1421
1421
|
if (e == null || e instanceof Date) return e;
|
|
1422
1422
|
if (typeof e == "string") {
|
|
1423
1423
|
let t = new Date(e);
|
|
@@ -1428,24 +1428,24 @@ var Gt = (e, t, n) => Kt(e, "id", t, n), Kt = (e, t, n, r, i = "asc") => {
|
|
|
1428
1428
|
return isNaN(t.getTime()) ? e : t;
|
|
1429
1429
|
}
|
|
1430
1430
|
return e;
|
|
1431
|
-
},
|
|
1431
|
+
}, on = (e, t, n) => {
|
|
1432
1432
|
if (e == null) return e;
|
|
1433
1433
|
switch (t) {
|
|
1434
|
-
case "boolean": return n === "postgres" ? e :
|
|
1435
|
-
case "vector": return n === "postgres" ?
|
|
1436
|
-
case "json": return n === "postgres" || n === "mysql" || n === "mariadb" ? e :
|
|
1437
|
-
case "array": return n === "postgres" ? e :
|
|
1434
|
+
case "boolean": return n === "postgres" ? e : tn(e);
|
|
1435
|
+
case "vector": return n === "postgres" ? nn(e) : e;
|
|
1436
|
+
case "json": return n === "postgres" || n === "mysql" || n === "mariadb" ? e : nn(e);
|
|
1437
|
+
case "array": return n === "postgres" ? e : nn(e);
|
|
1438
1438
|
case "timestamp":
|
|
1439
|
-
case "date": return n === "sqlite" || n === "turso" ?
|
|
1439
|
+
case "date": return n === "sqlite" || n === "turso" ? an(e) : e;
|
|
1440
1440
|
case "decimal":
|
|
1441
|
-
case "bigint": return
|
|
1441
|
+
case "bigint": return rn(e);
|
|
1442
1442
|
default: return e;
|
|
1443
1443
|
}
|
|
1444
|
-
},
|
|
1444
|
+
}, sn = (e, t, n) => {
|
|
1445
1445
|
if (e.length === 0) return e;
|
|
1446
|
-
let r =
|
|
1447
|
-
return r === void 0 ? e :
|
|
1448
|
-
},
|
|
1446
|
+
let r = z(t);
|
|
1447
|
+
return r === void 0 ? e : cn(e, r, n);
|
|
1448
|
+
}, cn = (e, t, n) => {
|
|
1449
1449
|
if (e.length === 0) return e;
|
|
1450
1450
|
let r = t.fields, i = [];
|
|
1451
1451
|
for (let [e, t] of Object.entries(r)) i.push({
|
|
@@ -1454,10 +1454,10 @@ var Gt = (e, t, n) => Kt(e, "id", t, n), Kt = (e, t, n, r, i = "asc") => {
|
|
|
1454
1454
|
});
|
|
1455
1455
|
return e.map((e) => {
|
|
1456
1456
|
let t = { ...e };
|
|
1457
|
-
for (let { key: e, type: r } of i) e in t && (t[e] =
|
|
1457
|
+
for (let { key: e, type: r } of i) e in t && (t[e] = on(t[e], r, n));
|
|
1458
1458
|
return t;
|
|
1459
1459
|
});
|
|
1460
|
-
},
|
|
1460
|
+
}, ln = (e, t) => {
|
|
1461
1461
|
if (e == null) return e;
|
|
1462
1462
|
switch (t) {
|
|
1463
1463
|
case "json": return JSON.stringify(e);
|
|
@@ -1465,25 +1465,25 @@ var Gt = (e, t, n) => Kt(e, "id", t, n), Kt = (e, t, n, r, i = "asc") => {
|
|
|
1465
1465
|
case "vector": return typeof e == "string" ? e : JSON.stringify(e);
|
|
1466
1466
|
default: return e;
|
|
1467
1467
|
}
|
|
1468
|
-
},
|
|
1469
|
-
let r =
|
|
1468
|
+
}, un = (e, t, n = ["json", "array"]) => {
|
|
1469
|
+
let r = z(t);
|
|
1470
1470
|
if (r === void 0) return e;
|
|
1471
1471
|
let i = r.fields, a = null;
|
|
1472
1472
|
for (let [t, r] of Object.entries(i)) if (n.includes(r.type) && t in e) {
|
|
1473
|
-
let n =
|
|
1473
|
+
let n = ln(e[t], r.type);
|
|
1474
1474
|
n !== e[t] && (a === null && (a = { ...e }), a[t] = n);
|
|
1475
1475
|
}
|
|
1476
1476
|
return a ?? e;
|
|
1477
|
-
},
|
|
1477
|
+
}, dn = /^[A-Za-z_][A-Za-z0-9_]*$/, fn = (e) => "$" + e.map((e) => typeof e == "number" ? `[${e}]` : dn.test(e) ? `.${e}` : `."${e.replace(/"/g, "\\\"")}"`).join(""), pn = (e) => "{" + e.map((e) => {
|
|
1478
1478
|
let t = String(e);
|
|
1479
1479
|
return /^[A-Za-z0-9_]+$/.test(t) ? t : `"${t.replace(/(["\\])/g, "\\$1")}"`;
|
|
1480
|
-
}).join(",") + "}",
|
|
1481
|
-
let i =
|
|
1480
|
+
}).join(",") + "}", W = (e, t, n, r = {}) => {
|
|
1481
|
+
let i = L(e, n), a = r.numeric ?? !1;
|
|
1482
1482
|
if (n === "postgres") {
|
|
1483
|
-
let e = `(${i} #>> '${
|
|
1483
|
+
let e = `(${i} #>> '${pn(t)}'::text[])`;
|
|
1484
1484
|
return a ? `${e}::numeric` : e;
|
|
1485
1485
|
}
|
|
1486
|
-
let o =
|
|
1486
|
+
let o = fn(t);
|
|
1487
1487
|
switch (n) {
|
|
1488
1488
|
case "mysql":
|
|
1489
1489
|
case "mariadb": {
|
|
@@ -1500,7 +1500,257 @@ var Gt = (e, t, n) => Kt(e, "id", t, n), Kt = (e, t, n, r, i = "asc") => {
|
|
|
1500
1500
|
return a ? `CAST(${e} AS REAL)` : e;
|
|
1501
1501
|
}
|
|
1502
1502
|
}
|
|
1503
|
-
},
|
|
1503
|
+
}, mn = class extends Error {
|
|
1504
|
+
_tag = "TenantNamespaceUnresolved";
|
|
1505
|
+
constructor(e) {
|
|
1506
|
+
super(e), this.name = "TenantNamespaceUnresolved";
|
|
1507
|
+
}
|
|
1508
|
+
}, hn = class extends Error {
|
|
1509
|
+
_tag = "TenantNamespaceInvalid";
|
|
1510
|
+
constructor(e) {
|
|
1511
|
+
super(e), this.name = "TenantNamespaceInvalid";
|
|
1512
|
+
}
|
|
1513
|
+
}, gn = 63, _n = "tenant_", vn = (e) => e.toLowerCase().replace(/[^a-z0-9_]/g, "_"), yn = (e) => {
|
|
1514
|
+
if (e == null || e === "") throw new mn("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.");
|
|
1515
|
+
let t = vn(e);
|
|
1516
|
+
if (t.replace(/_/g, "") === "") throw new hn(`tenant id '${e}' has no usable identifier characters after sanitisation — cannot derive a distinct namespace.`);
|
|
1517
|
+
let n = `${_n}${t}`;
|
|
1518
|
+
if (n.length > gn) throw new hn(`namespace '${n}' for tenant '${e}' exceeds the ${gn}-byte identifier limit. Use a shorter tenant id.`);
|
|
1519
|
+
return n;
|
|
1520
|
+
}, G = (e, t) => e === null ? t : `${e}.${t}`, bn = /* @__PURE__ */ new Set(["timestamp", "date"]), xn = /^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2})?/, Sn = (e, t) => {
|
|
1521
|
+
if (e === void 0 || t == null || !bn.has(e) || t instanceof Date) return t;
|
|
1522
|
+
if (typeof t == "number" && Number.isFinite(t)) return new Date(t);
|
|
1523
|
+
if (typeof t == "string" && xn.test(t)) {
|
|
1524
|
+
let e = new Date(t);
|
|
1525
|
+
return Number.isNaN(e.getTime()) ? t : e;
|
|
1526
|
+
}
|
|
1527
|
+
return t;
|
|
1528
|
+
}, Cn = (e, t) => e === void 0 || !bn.has(e) ? t : t.map((t) => Sn(e, t)), wn = (e, t) => {
|
|
1529
|
+
let { strings: n, values: r } = e, i = t.unsafe(n[0] ?? "");
|
|
1530
|
+
for (let e = 0; e < r.length; e++) i = t`${i}${r[e]}${t.unsafe(n[e + 1] ?? "")}`;
|
|
1531
|
+
return t`${i}`;
|
|
1532
|
+
}, K = (e) => e.replace(/[\\%_]/g, (e) => `\\${e}`), q = (e, t, n = null, r) => {
|
|
1533
|
+
if ("not" in e) return t`NOT (${q(e.not, t, n, r)})`;
|
|
1534
|
+
if ("and" in e) return e.and.length === 0 ? t`TRUE` : t.and(e.and.map((e) => q(e, t, n, r)));
|
|
1535
|
+
if ("or" in e) return e.or.length === 0 ? t`FALSE` : t.or(e.or.map((e) => q(e, t, n, r)));
|
|
1536
|
+
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
1537
|
+
let r = e, i = J(r.subquery, t, n);
|
|
1538
|
+
return r.op === "subquery-in" ? t`${t(r.column)} IN (${i})` : t`${t(r.column)} NOT IN (${i})`;
|
|
1539
|
+
}
|
|
1540
|
+
if (e.op === "exists" || e.op === "not-exists") {
|
|
1541
|
+
let r = e, i = J(r.subquery, t, n);
|
|
1542
|
+
return r.op === "exists" ? t`EXISTS (${i})` : t`NOT EXISTS (${i})`;
|
|
1543
|
+
}
|
|
1544
|
+
let i = e, a = t(i.column), o = i.path, s = o !== void 0 && o.length > 0, c = () => t.onDialectOrElse({
|
|
1545
|
+
mysql: () => t.unsafe(W(i.column, o, "mysql")),
|
|
1546
|
+
mssql: () => t.unsafe(W(i.column, o, "mssql")),
|
|
1547
|
+
sqlite: () => t.unsafe(W(i.column, o, "sqlite")),
|
|
1548
|
+
orElse: () => t.unsafe(W(i.column, o, "postgres"))
|
|
1549
|
+
}), l = () => t.onDialectOrElse({
|
|
1550
|
+
mysql: () => t.unsafe(W(i.column, o, "mysql", { numeric: !0 })),
|
|
1551
|
+
mssql: () => t.unsafe(W(i.column, o, "mssql", { numeric: !0 })),
|
|
1552
|
+
sqlite: () => t.unsafe(W(i.column, o, "sqlite", { numeric: !0 })),
|
|
1553
|
+
orElse: () => t.unsafe(W(i.column, o, "postgres", { numeric: !0 }))
|
|
1554
|
+
}), u = s ? c() : a, d = s ? l() : a, f = (e) => s && e != null ? String(e) : e, p = (e) => s ? Number(e) : e, m = s || r === void 0 ? void 0 : z(r)?.fields?.[i.column]?.type, h = (e) => Sn(m, e);
|
|
1555
|
+
switch (i.op) {
|
|
1556
|
+
case "eq": return t`${u} = ${f(h(i.value))}`;
|
|
1557
|
+
case "neq": return t`${u} <> ${f(h(i.value))}`;
|
|
1558
|
+
case "gt": return t`${d} > ${p(i.value)}`;
|
|
1559
|
+
case "gte": return t`${d} >= ${p(i.value)}`;
|
|
1560
|
+
case "lt": return t`${d} < ${p(i.value)}`;
|
|
1561
|
+
case "lte": return t`${d} <= ${p(i.value)}`;
|
|
1562
|
+
case "in": {
|
|
1563
|
+
let e = i.value ?? [];
|
|
1564
|
+
return e.length === 0 ? t`FALSE` : t`${u} IN ${t.in(s ? e.map((e) => f(e)) : e)}`;
|
|
1565
|
+
}
|
|
1566
|
+
case "notIn": {
|
|
1567
|
+
let e = i.value ?? [];
|
|
1568
|
+
return e.length === 0 ? t`TRUE` : t`${u} NOT IN ${t.in(s ? e.map((e) => f(e)) : e)}`;
|
|
1569
|
+
}
|
|
1570
|
+
case "contains": {
|
|
1571
|
+
let e = `%${K(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
|
|
1572
|
+
return t.onDialectOrElse({
|
|
1573
|
+
mysql: () => t`LOWER(${u}) LIKE LOWER(${e})`,
|
|
1574
|
+
mssql: () => t`LOWER(${u}) LIKE LOWER(${e})`,
|
|
1575
|
+
sqlite: () => t`LOWER(${u}) LIKE LOWER(${e})`,
|
|
1576
|
+
orElse: () => t`${u} ILIKE ${e} ESCAPE '\\'`
|
|
1577
|
+
});
|
|
1578
|
+
}
|
|
1579
|
+
case "startsWith": {
|
|
1580
|
+
let e = `${K(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
|
|
1581
|
+
return t.onDialectOrElse({
|
|
1582
|
+
mysql: () => t`${u} LIKE ${e}`,
|
|
1583
|
+
orElse: () => t`${u} LIKE ${e} ESCAPE '\\'`
|
|
1584
|
+
});
|
|
1585
|
+
}
|
|
1586
|
+
case "arrayContains": {
|
|
1587
|
+
let e = i.value ?? [];
|
|
1588
|
+
return e.length === 0 ? t`TRUE` : t.onDialectOrElse({
|
|
1589
|
+
mysql: () => t`JSON_CONTAINS(${u}, ${JSON.stringify(e)})`,
|
|
1590
|
+
mssql: () => t`(SELECT COUNT(DISTINCT value) FROM OPENJSON(${u}) WHERE value IN ${t.in(e)}) = ${e.length}`,
|
|
1591
|
+
sqlite: () => t`(SELECT COUNT(DISTINCT value) FROM json_each(${u}) WHERE value IN ${t.in(e)}) = ${e.length}`,
|
|
1592
|
+
orElse: () => t`${u} @> ${e}`
|
|
1593
|
+
});
|
|
1594
|
+
}
|
|
1595
|
+
case "arrayOverlaps": {
|
|
1596
|
+
let e = i.value ?? [];
|
|
1597
|
+
return e.length === 0 ? t`FALSE` : t.onDialectOrElse({
|
|
1598
|
+
mysql: () => t.or(e.map((e) => t`JSON_CONTAINS(${u}, ${JSON.stringify(e)})`)),
|
|
1599
|
+
mssql: () => t`EXISTS (SELECT 1 FROM OPENJSON(${u}) WHERE value IN ${t.in(e)})`,
|
|
1600
|
+
sqlite: () => t`EXISTS (SELECT 1 FROM json_each(${u}) WHERE value IN ${t.in(e)})`,
|
|
1601
|
+
orElse: () => t`${u} && ${e}`
|
|
1602
|
+
});
|
|
1603
|
+
}
|
|
1604
|
+
case "arrayHas": return t.onDialectOrElse({
|
|
1605
|
+
mysql: () => t`JSON_CONTAINS(${u}, ${JSON.stringify(i.value)})`,
|
|
1606
|
+
mssql: () => t`${i.value} IN (SELECT value FROM OPENJSON(${u}))`,
|
|
1607
|
+
sqlite: () => t`EXISTS (SELECT 1 FROM json_each(${u}) WHERE value = ${i.value})`,
|
|
1608
|
+
orElse: () => t`${i.value} = ANY(${u})`
|
|
1609
|
+
});
|
|
1610
|
+
case "isNull": return t`${u} IS NULL`;
|
|
1611
|
+
case "isNotNull": return t`${u} IS NOT NULL`;
|
|
1612
|
+
case "spatial": {
|
|
1613
|
+
let e = i.value, n = t.unsafe("::geometry"), r = e.bufferMeters === void 0 ? t`${e.geom}${n}` : t`ST_Buffer(${e.geom}::geography, ${e.bufferMeters})::geometry`;
|
|
1614
|
+
return t.onDialectOrElse({
|
|
1615
|
+
mysql: () => {
|
|
1616
|
+
throw Error("@voltro/plugin-postgis: spatial predicates are postgres-only");
|
|
1617
|
+
},
|
|
1618
|
+
mssql: () => {
|
|
1619
|
+
throw Error("@voltro/plugin-postgis: spatial predicates are postgres-only");
|
|
1620
|
+
},
|
|
1621
|
+
sqlite: () => {
|
|
1622
|
+
throw Error("@voltro/plugin-postgis: spatial predicates are postgres-only");
|
|
1623
|
+
},
|
|
1624
|
+
orElse: () => e.fn === "ST_DWithin" ? t`ST_DWithin(${a}::geography, ${e.geom}::geography, ${e.distanceMeters})` : e.fn === "&&" ? t`${a}${n} && ${r}` : t`${t.unsafe(e.fn)}(${a}${n}, ${r})`
|
|
1625
|
+
});
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
}, Tn = (e, t) => {
|
|
1629
|
+
let n = [];
|
|
1630
|
+
return e.partitionBy && e.partitionBy.length > 0 && n.push(t`PARTITION BY ${t.csv(e.partitionBy.map((e) => t`${t(e)}`))}`), e.orderBy && e.orderBy.length > 0 && n.push(t`ORDER BY ${t.csv(e.orderBy.map((e) => e.direction === "desc" ? t`${t(e.column)} DESC` : t`${t(e.column)} ASC`))}`), n.length === 0 ? t`` : n.length === 1 ? n[0] : n.reduce((e, n, r) => r === 0 ? n : t`${e} ${n}`);
|
|
1631
|
+
}, En = (e, t) => t.csv(e.map((e) => {
|
|
1632
|
+
let n = e.column === void 0 ? t.unsafe("*") : t`${t(e.column)}`;
|
|
1633
|
+
if (e.op.startsWith("window-")) {
|
|
1634
|
+
let r = Tn(e.window ?? {}, t);
|
|
1635
|
+
switch (e.op) {
|
|
1636
|
+
case "window-row-number": return t`ROW_NUMBER() OVER (${r}) AS ${t(e.alias)}`;
|
|
1637
|
+
case "window-rank": return t`RANK() OVER (${r}) AS ${t(e.alias)}`;
|
|
1638
|
+
case "window-dense-rank": return t`DENSE_RANK() OVER (${r}) AS ${t(e.alias)}`;
|
|
1639
|
+
case "window-lag": return t`LAG(${n}, ${t.unsafe(String(e.offset ?? 1))}) OVER (${r}) AS ${t(e.alias)}`;
|
|
1640
|
+
case "window-lead": return t`LEAD(${n}, ${t.unsafe(String(e.offset ?? 1))}) OVER (${r}) AS ${t(e.alias)}`;
|
|
1641
|
+
case "window-sum-over": return t`SUM(${n}) OVER (${r}) AS ${t(e.alias)}`;
|
|
1642
|
+
case "window-avg-over": return t`AVG(${n}) OVER (${r}) AS ${t(e.alias)}`;
|
|
1643
|
+
default: throw Error(`compileAggregateProjection: unknown window op '${e.op}'`);
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
switch (e.op) {
|
|
1647
|
+
case "count": return t`COUNT(${n}) AS ${t(e.alias)}`;
|
|
1648
|
+
case "count-distinct": return t`COUNT(DISTINCT ${n}) AS ${t(e.alias)}`;
|
|
1649
|
+
case "sum": return t`SUM(${n}) AS ${t(e.alias)}`;
|
|
1650
|
+
case "avg": return t`AVG(${n}) AS ${t(e.alias)}`;
|
|
1651
|
+
case "min": return t`MIN(${n}) AS ${t(e.alias)}`;
|
|
1652
|
+
case "max": return t`MAX(${n}) AS ${t(e.alias)}`;
|
|
1653
|
+
case "column":
|
|
1654
|
+
if (e.column === void 0) throw Error(`compileAggregateProjection: 'column' projection requires a column name (alias '${e.alias}')`);
|
|
1655
|
+
return t`${t(e.column)} AS ${t(e.alias)}`;
|
|
1656
|
+
default: throw Error(`compileAggregateProjection: unknown op '${e.op}'`);
|
|
1657
|
+
}
|
|
1658
|
+
})), Dn = (e) => `[${e.join(",")}]`, On = (e, t) => {
|
|
1659
|
+
if (e.queryVector === void 0) return null;
|
|
1660
|
+
let n = t(e.column), r = Dn(e.queryVector), i = e.distance === "cosine" ? "<=>" : e.distance === "l2" ? "<->" : "<#>", a = e.distance === "cosine" ? "VEC_DISTANCE_COSINE" : "VEC_DISTANCE_EUCLIDEAN";
|
|
1661
|
+
return t.onDialectOrElse({
|
|
1662
|
+
mysql: () => t`${t.unsafe(a)}(${n}, ${r})`,
|
|
1663
|
+
mssql: () => t`NULL`,
|
|
1664
|
+
sqlite: () => t`NULL`,
|
|
1665
|
+
orElse: () => t`${n} ${t.unsafe(i)} ${r}::vector`
|
|
1666
|
+
});
|
|
1667
|
+
}, kn = (e, t) => {
|
|
1668
|
+
let n = t.unsafe(e.useGeography ? "::geography" : "::geometry");
|
|
1669
|
+
return t`ST_Distance(${t(e.column)}${n}, ${e.geom}${n})`;
|
|
1670
|
+
}, An = (e, t) => t`${t(e.column)} <-> ${e.geom}::geometry`, jn = (e, t) => t`${t(`${e.indexName}_tsv`)}`, Mn = (e, t) => `${t}_${e.indexName}_fts`, Nn = (e, t, n) => {
|
|
1671
|
+
let r = n.csv(e.columns.map((e) => n`${n(e)}`)), i = `%${K(e.query)}%`;
|
|
1672
|
+
return n.onDialectOrElse({
|
|
1673
|
+
mysql: () => n`MATCH(${r}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
|
|
1674
|
+
sqlite: () => {
|
|
1675
|
+
let r = n(Mn(e, t));
|
|
1676
|
+
return n`${n("id")} IN (SELECT ${n("row_id")} FROM ${r} WHERE ${r} MATCH ${e.query})`;
|
|
1677
|
+
},
|
|
1678
|
+
mssql: () => n.or(e.columns.map((e) => n`LOWER(${n(e)}) LIKE LOWER(${i}) ESCAPE '\\'`)),
|
|
1679
|
+
orElse: () => n`${jn(e, n)} @@ plainto_tsquery(${e.config ?? "english"}, ${e.query})`
|
|
1680
|
+
});
|
|
1681
|
+
}, Pn = (e, t, n) => {
|
|
1682
|
+
let r = `%${K(e.query)}%`;
|
|
1683
|
+
return n.onDialectOrElse({
|
|
1684
|
+
mysql: () => n`MATCH(${n.csv(e.columns.map((e) => n`${n(e)}`))}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
|
|
1685
|
+
sqlite: () => {
|
|
1686
|
+
let r = n(Mn(e, t));
|
|
1687
|
+
return n`COALESCE((SELECT -bm25(${r}) FROM ${r} WHERE ${r} MATCH ${e.query} AND ${r}.${n("row_id")} = ${n("id")}), 0)`;
|
|
1688
|
+
},
|
|
1689
|
+
mssql: () => e.columns.map((e) => n`(CASE WHEN LOWER(${n(e)}) LIKE LOWER(${r}) ESCAPE '\\' THEN 1 ELSE 0 END)`).reduce((e, t, r) => r === 0 ? t : n`${e} + ${t}`),
|
|
1690
|
+
orElse: () => n`ts_rank(${jn(e, n)}, plainto_tsquery(${e.config ?? "english"}, ${e.query}))`
|
|
1691
|
+
});
|
|
1692
|
+
}, J = (e, t, n = null) => {
|
|
1693
|
+
if (e.setOp && e.setOp.queries.length >= 2) {
|
|
1694
|
+
let r = e.setOp.kind === "union" ? "UNION" : e.setOp.kind === "union-all" ? "UNION ALL" : e.setOp.kind === "intersect" ? "INTERSECT" : "EXCEPT", i = e.setOp.queries.map((e) => t`(${J(e, t, n)})`).reduce((e, n, i) => i === 0 ? n : t`${e} ${t.unsafe(r)} ${n}`), a = [];
|
|
1695
|
+
if (B(e).length > 0 && a.push(t` ORDER BY ${t.csv(B(e).map((e) => e.direction === "desc" ? t`${t(e.column)} DESC` : t`${t(e.column)} ASC`))}`), e.take !== void 0) {
|
|
1696
|
+
if (!Number.isInteger(e.take) || e.take < 0) throw Error(`compileSelect: invalid take ${e.take}`);
|
|
1697
|
+
a.push(t` LIMIT ${t.unsafe(String(e.take))}`);
|
|
1698
|
+
}
|
|
1699
|
+
if (e.skip !== void 0) {
|
|
1700
|
+
if (!Number.isInteger(e.skip) || e.skip < 0) throw Error(`compileSelect: invalid skip ${e.skip}`);
|
|
1701
|
+
a.push(t` OFFSET ${t.unsafe(String(e.skip))}`);
|
|
1702
|
+
}
|
|
1703
|
+
return t`${i}${a.reduce((e, n) => t`${e}${n}`, t``)}`;
|
|
1704
|
+
}
|
|
1705
|
+
let r = e.annClause === void 0 ? null : On(e.annClause, t);
|
|
1706
|
+
e.spatialClause !== void 0 && t.onDialectOrElse({
|
|
1707
|
+
mysql: () => {
|
|
1708
|
+
throw Error("@voltro/plugin-postgis: spatial distance / KNN ordering is postgres-only");
|
|
1709
|
+
},
|
|
1710
|
+
mssql: () => {
|
|
1711
|
+
throw Error("@voltro/plugin-postgis: spatial distance / KNN ordering is postgres-only");
|
|
1712
|
+
},
|
|
1713
|
+
sqlite: () => {
|
|
1714
|
+
throw Error("@voltro/plugin-postgis: spatial distance / KNN ordering is postgres-only");
|
|
1715
|
+
},
|
|
1716
|
+
orElse: () => t``
|
|
1717
|
+
});
|
|
1718
|
+
let i = e.spatialClause?.projectAs === void 0 ? null : kn(e.spatialClause, t), a = e.aggregations && e.aggregations.length > 0 ? En(e.aggregations, t) : e.joinedProjection && e.joinedProjection.length > 0 ? t.csv(e.joinedProjection.map((e) => t`${t(e.source)} AS ${t(e.outputKey)}`)) : e.projection && e.projection.length > 0 ? t.csv(e.projection.map((e) => t`${t(e)}`)) : t`*`, o = (e.aggregations && e.aggregations.length > 0) === !0, s = r !== null && !o ? t`${a}, ${r} AS ${t("distance")}` : a, c = e.fullTextSearch, l = c?.rank !== void 0 && !o ? Pn(c, e.table, t) : null, u = l !== null && c?.rank !== void 0 ? t`${s}, ${l} AS ${t(c.rank.alias)}` : s, d = i !== null && !o && e.spatialClause?.projectAs !== void 0 ? t`${u}, ${i} AS ${t(e.spatialClause.projectAs)}` : u, f = e.distinctOn && e.distinctOn.length > 0 ? t.onDialectOrElse({
|
|
1719
|
+
orElse: () => t`DISTINCT ON (${t.csv(e.distinctOn.map((e) => t`${t(e)}`))}) `,
|
|
1720
|
+
mysql: () => t`DISTINCT `,
|
|
1721
|
+
mssql: () => t`DISTINCT `,
|
|
1722
|
+
sqlite: () => t`DISTINCT `
|
|
1723
|
+
}) : e.distinct ? t`DISTINCT ` : t``, p = e.lock === "update", m = p ? t.onDialectOrElse({
|
|
1724
|
+
mssql: () => t` WITH (UPDLOCK, ROWLOCK)`,
|
|
1725
|
+
orElse: () => t``
|
|
1726
|
+
}) : t``, h = p ? t.onDialectOrElse({
|
|
1727
|
+
mssql: () => t``,
|
|
1728
|
+
sqlite: () => t``,
|
|
1729
|
+
orElse: () => t` FOR UPDATE`
|
|
1730
|
+
}) : t``, g = e.alias === void 0 ? t`${t(G(n, e.table))}${m}` : t`${t(G(n, e.table))} AS ${t(e.alias)}${m}`, ee = (e.joins ?? []).map((e) => {
|
|
1731
|
+
let r = e.kind === "inner" ? "INNER" : "LEFT";
|
|
1732
|
+
return t` ${t.unsafe(r)} JOIN ${t(G(n, e.table))} AS ${t(e.alias)} ON ${q(e.on, t, n)}`;
|
|
1733
|
+
}), te = ee.length > 0 ? ee.reduce((e, n) => t`${e}${n}`, g) : g, ne = c === void 0 ? null : Nn(c, e.table, t), re = [e.predicate ? q(e.predicate, t, n, e.table) : null, ne].filter((e) => e !== null), _ = re.length > 0 ? t` WHERE ${t.and(re)}` : t``, ie = e.groupBy && e.groupBy.length > 0 ? t` GROUP BY ${t.csv(e.groupBy.map((e) => t`${t(e)}`))}` : t``, v = e.having ? t` HAVING ${q(e.having, t, n, e.table)}` : t``, y = e.skip !== void 0, b = [];
|
|
1734
|
+
r !== null && b.push(t`${r} ASC`), e.spatialClause?.order !== void 0 && b.push(e.spatialClause.order === "desc" ? t`${An(e.spatialClause, t)} DESC` : t`${An(e.spatialClause, t)} ASC`), l !== null && c?.rank?.order === !0 && b.push(t`${l} DESC`);
|
|
1735
|
+
for (let n of B(e)) b.push(n.direction === "desc" ? t`${t(n.column)} DESC` : t`${t(n.column)} ASC`);
|
|
1736
|
+
let ae = b.length > 0 ? t` ORDER BY ${t.csv(b)}` : y ? t.onDialectOrElse({
|
|
1737
|
+
mssql: () => t` ORDER BY (SELECT NULL)`,
|
|
1738
|
+
orElse: () => t``
|
|
1739
|
+
}) : t``, x = (e) => {
|
|
1740
|
+
if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw Error(`compileSelect: expected non-negative integer take/skip, got ${e}`);
|
|
1741
|
+
return t.unsafe(String(e));
|
|
1742
|
+
}, S = (e.ctes ?? []).map((e) => t`${t(e.name)} AS (${J(e.descriptor, t, n)})`), C = (e.ctes ?? []).some((e) => e.recursive === !0), oe = S.length > 0 ? t`WITH ${t.unsafe(C ? "RECURSIVE " : "")}${t.csv(S)} ` : t``;
|
|
1743
|
+
return t.onDialectOrElse({
|
|
1744
|
+
mssql: () => {
|
|
1745
|
+
let n = e.take !== void 0 && !y ? t`TOP ${x(e.take)} ` : t``, r = y ? t` OFFSET ${x(e.skip)} ROWS FETCH NEXT ${x(e.take ?? 2 ** 53 - 1)} ROWS ONLY` : t``;
|
|
1746
|
+
return t`${oe}SELECT ${n}${f}${d} FROM ${te}${_}${ie}${v}${ae}${r}`;
|
|
1747
|
+
},
|
|
1748
|
+
orElse: () => {
|
|
1749
|
+
let n = e.take === void 0 ? t`` : t` LIMIT ${x(e.take)}`, r = y ? t` OFFSET ${x(e.skip)}` : t``;
|
|
1750
|
+
return t`${oe}SELECT ${f}${d} FROM ${te}${_}${ie}${v}${ae}${n}${r}${h}`;
|
|
1751
|
+
}
|
|
1752
|
+
});
|
|
1753
|
+
}, Y = (e, t) => {
|
|
1504
1754
|
let n = (e) => {
|
|
1505
1755
|
if (typeof e != "string" || !/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/.test(e)) return null;
|
|
1506
1756
|
let [t = "", n = ""] = e.replace(/^[+-]/, "").split("."), r = t.replace(/^0+/, "") || "0";
|
|
@@ -1518,73 +1768,73 @@ var Gt = (e, t, n) => Kt(e, "id", t, n), Kt = (e, t, n, r, i = "asc") => {
|
|
|
1518
1768
|
a = t === n ? 0 : t > n ? 1 : -1;
|
|
1519
1769
|
}
|
|
1520
1770
|
return a === 0 ? 0 : (a > 0 ? 1 : -1) * (r.negative ? -1 : 1);
|
|
1521
|
-
},
|
|
1771
|
+
}, Fn = (e, t) => ({
|
|
1522
1772
|
column: e,
|
|
1523
1773
|
op: "eq",
|
|
1524
1774
|
value: t
|
|
1525
|
-
}),
|
|
1775
|
+
}), In = (e, t) => ({
|
|
1526
1776
|
column: e,
|
|
1527
1777
|
op: "neq",
|
|
1528
1778
|
value: t
|
|
1529
|
-
}),
|
|
1779
|
+
}), Ln = (e, t) => ({
|
|
1530
1780
|
column: e,
|
|
1531
1781
|
op: "gt",
|
|
1532
1782
|
value: t
|
|
1533
|
-
}),
|
|
1783
|
+
}), Rn = (e, t) => ({
|
|
1534
1784
|
column: e,
|
|
1535
1785
|
op: "gte",
|
|
1536
1786
|
value: t
|
|
1537
|
-
}),
|
|
1787
|
+
}), zn = (e, t) => ({
|
|
1538
1788
|
column: e,
|
|
1539
1789
|
op: "lt",
|
|
1540
1790
|
value: t
|
|
1541
|
-
}),
|
|
1791
|
+
}), Bn = (e, t) => ({
|
|
1542
1792
|
column: e,
|
|
1543
1793
|
op: "lte",
|
|
1544
1794
|
value: t
|
|
1545
|
-
}),
|
|
1795
|
+
}), Vn = (e, t) => ({
|
|
1546
1796
|
column: e,
|
|
1547
1797
|
op: "in",
|
|
1548
1798
|
value: t
|
|
1549
|
-
}),
|
|
1799
|
+
}), Hn = (e, t) => ({
|
|
1550
1800
|
column: e,
|
|
1551
1801
|
op: "notIn",
|
|
1552
1802
|
value: t
|
|
1553
|
-
}),
|
|
1803
|
+
}), Un = (e, t) => ({
|
|
1554
1804
|
column: e,
|
|
1555
1805
|
op: "contains",
|
|
1556
1806
|
value: t
|
|
1557
|
-
}),
|
|
1807
|
+
}), Wn = (e, t) => ({
|
|
1558
1808
|
column: e,
|
|
1559
1809
|
op: "startsWith",
|
|
1560
1810
|
value: t
|
|
1561
|
-
}),
|
|
1811
|
+
}), Gn = (e, t) => ({
|
|
1562
1812
|
column: e,
|
|
1563
1813
|
op: "arrayContains",
|
|
1564
1814
|
value: t
|
|
1565
|
-
}),
|
|
1815
|
+
}), Kn = (e, t) => ({
|
|
1566
1816
|
column: e,
|
|
1567
1817
|
op: "arrayOverlaps",
|
|
1568
1818
|
value: t
|
|
1569
|
-
}),
|
|
1819
|
+
}), qn = (e, t) => ({
|
|
1570
1820
|
column: e,
|
|
1571
1821
|
op: "arrayHas",
|
|
1572
1822
|
value: t
|
|
1573
|
-
}),
|
|
1823
|
+
}), Jn = {
|
|
1574
1824
|
column: "id",
|
|
1575
1825
|
op: "in",
|
|
1576
1826
|
value: []
|
|
1577
|
-
},
|
|
1827
|
+
}, Yn = (e) => ({
|
|
1578
1828
|
column: e,
|
|
1579
1829
|
op: "isNull"
|
|
1580
|
-
}),
|
|
1830
|
+
}), Xn = (e) => ({
|
|
1581
1831
|
column: e,
|
|
1582
1832
|
op: "isNotNull"
|
|
1583
|
-
}),
|
|
1833
|
+
}), Zn = (e, t) => ({
|
|
1584
1834
|
column: e,
|
|
1585
1835
|
op: "spatial",
|
|
1586
1836
|
value: t
|
|
1587
|
-
}),
|
|
1837
|
+
}), Qn = (...e) => ({ and: e }), $n = (...e) => ({ or: e }), er = (e) => ({ not: e }), tr = (e, ...t) => {
|
|
1588
1838
|
if (t.length === 0) throw Error(`jsonField("${e}"): at least one path segment is required`);
|
|
1589
1839
|
let n = (n, r) => ({
|
|
1590
1840
|
column: e,
|
|
@@ -1606,56 +1856,56 @@ var Gt = (e, t, n) => Kt(e, "id", t, n), Kt = (e, t, n, r, i = "asc") => {
|
|
|
1606
1856
|
isNull: () => n("isNull"),
|
|
1607
1857
|
isNotNull: () => n("isNotNull")
|
|
1608
1858
|
};
|
|
1609
|
-
},
|
|
1859
|
+
}, X = (e) => "descriptor" in e ? e.descriptor : e, nr = (e, t) => ({
|
|
1610
1860
|
column: e,
|
|
1611
1861
|
op: "subquery-in",
|
|
1612
|
-
subquery:
|
|
1613
|
-
}),
|
|
1862
|
+
subquery: X(t)
|
|
1863
|
+
}), rr = (e, t) => ({
|
|
1614
1864
|
column: e,
|
|
1615
1865
|
op: "subquery-not-in",
|
|
1616
|
-
subquery:
|
|
1617
|
-
}),
|
|
1866
|
+
subquery: X(t)
|
|
1867
|
+
}), ir = (e) => ({
|
|
1618
1868
|
op: "exists",
|
|
1619
|
-
subquery:
|
|
1620
|
-
}),
|
|
1869
|
+
subquery: X(e)
|
|
1870
|
+
}), ar = (e) => ({
|
|
1621
1871
|
op: "not-exists",
|
|
1622
|
-
subquery:
|
|
1623
|
-
}),
|
|
1872
|
+
subquery: X(e)
|
|
1873
|
+
}), or = /^\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?)?$/, sr = (e) => {
|
|
1624
1874
|
if (e instanceof Date) return e.getTime();
|
|
1625
|
-
if (typeof e == "string" &&
|
|
1875
|
+
if (typeof e == "string" && or.test(e)) {
|
|
1626
1876
|
let t = Date.parse(e);
|
|
1627
1877
|
return Number.isNaN(t) ? void 0 : t;
|
|
1628
1878
|
}
|
|
1629
|
-
},
|
|
1879
|
+
}, cr = (e, t) => {
|
|
1630
1880
|
if (!(e instanceof Date) && !(t instanceof Date)) return;
|
|
1631
|
-
let n =
|
|
1881
|
+
let n = sr(e), r = sr(t);
|
|
1632
1882
|
return n === void 0 || r === void 0 ? void 0 : [n, r];
|
|
1633
|
-
},
|
|
1883
|
+
}, lr = (e, t) => {
|
|
1634
1884
|
if (e === t) return !0;
|
|
1635
|
-
let n =
|
|
1885
|
+
let n = cr(e, t);
|
|
1636
1886
|
return n !== void 0 && n[0] === n[1];
|
|
1637
|
-
},
|
|
1887
|
+
}, ur = (e, t) => {
|
|
1638
1888
|
if (e == null || t == null) return null;
|
|
1639
|
-
let n =
|
|
1889
|
+
let n = cr(e, t);
|
|
1640
1890
|
if (n !== void 0) return n[0] === n[1] ? 0 : n[0] > n[1] ? 1 : -1;
|
|
1641
1891
|
let r = e instanceof Date ? e.getTime() : e, i = t instanceof Date ? t.getTime() : t;
|
|
1642
1892
|
return typeof r == typeof i ? r === i ? 0 : r > i ? 1 : -1 : null;
|
|
1643
|
-
},
|
|
1893
|
+
}, Z = (e, t, n = null, r = {}) => {
|
|
1644
1894
|
if (!t) return !1;
|
|
1645
|
-
if ("not" in e) return !
|
|
1895
|
+
if ("not" in e) return !Z(e.not, t, n, r);
|
|
1646
1896
|
if ("and" in e) {
|
|
1647
|
-
for (let i of e.and) if (!
|
|
1897
|
+
for (let i of e.and) if (!Z(i, t, n, r)) return !1;
|
|
1648
1898
|
return !0;
|
|
1649
1899
|
}
|
|
1650
1900
|
if ("or" in e) {
|
|
1651
|
-
for (let i of e.or) if (
|
|
1901
|
+
for (let i of e.or) if (Z(i, t, n, r)) return !0;
|
|
1652
1902
|
return !1;
|
|
1653
1903
|
}
|
|
1654
1904
|
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
1655
1905
|
if (!n) return !1;
|
|
1656
1906
|
let i = n.get(e.subquery);
|
|
1657
1907
|
if (!(i instanceof Set)) return !1;
|
|
1658
|
-
let a = t[e.column], o = r[e.column]?.type === "decimal" ? [...i].some((e) =>
|
|
1908
|
+
let a = t[e.column], o = r[e.column]?.type === "decimal" ? [...i].some((e) => Y(a, e) === 0) : i.has(a);
|
|
1659
1909
|
return e.op === "subquery-in" ? o : !o;
|
|
1660
1910
|
}
|
|
1661
1911
|
if (e.op === "exists" || e.op === "not-exists") {
|
|
@@ -1663,7 +1913,7 @@ var Gt = (e, t, n) => Kt(e, "id", t, n), Kt = (e, t, n, r, i = "asc") => {
|
|
|
1663
1913
|
let t = n.get(e.subquery), r = typeof t == "number" ? t > 0 : t instanceof Set && t.size > 0;
|
|
1664
1914
|
return e.op === "exists" ? r : !r;
|
|
1665
1915
|
}
|
|
1666
|
-
let i = e, a = t[i.column], o = r[i.column]?.type === "decimal", s = (e, t) => o && e != null && t != null ?
|
|
1916
|
+
let i = e, a = t[i.column], o = r[i.column]?.type === "decimal", s = (e, t) => o && e != null && t != null ? Y(e, t) === 0 : lr(e, t), c = o ? Y : ur;
|
|
1667
1917
|
switch (i.op) {
|
|
1668
1918
|
case "eq": return s(a, i.value);
|
|
1669
1919
|
case "neq": return !s(a, i.value);
|
|
@@ -1688,17 +1938,17 @@ var Gt = (e, t, n) => Kt(e, "id", t, n), Kt = (e, t, n, r, i = "asc") => {
|
|
|
1688
1938
|
case "isNotNull": return a != null;
|
|
1689
1939
|
case "spatial": throw Error("@voltro/plugin-postgis: spatial predicates (ST_DWithin / ST_Contains / ST_Within / ST_Intersects / bbox &&) are not evaluable in-memory — use them in one-shot ctx.store.query reads, not reactive subscriptions.");
|
|
1690
1940
|
}
|
|
1691
|
-
},
|
|
1941
|
+
}, Q = function* (e) {
|
|
1692
1942
|
if ("not" in e) {
|
|
1693
|
-
yield*
|
|
1943
|
+
yield* Q(e.not);
|
|
1694
1944
|
return;
|
|
1695
1945
|
}
|
|
1696
1946
|
if ("and" in e) {
|
|
1697
|
-
for (let t of e.and) yield*
|
|
1947
|
+
for (let t of e.and) yield* Q(t);
|
|
1698
1948
|
return;
|
|
1699
1949
|
}
|
|
1700
1950
|
if ("or" in e) {
|
|
1701
|
-
for (let t of e.or) yield*
|
|
1951
|
+
for (let t of e.or) yield* Q(t);
|
|
1702
1952
|
return;
|
|
1703
1953
|
}
|
|
1704
1954
|
e.op === "subquery-in" || e.op === "subquery-not-in" ? yield {
|
|
@@ -1708,30 +1958,30 @@ var Gt = (e, t, n) => Kt(e, "id", t, n), Kt = (e, t, n, r, i = "asc") => {
|
|
|
1708
1958
|
kind: "exists",
|
|
1709
1959
|
descriptor: e.subquery
|
|
1710
1960
|
});
|
|
1711
|
-
},
|
|
1961
|
+
}, $ = function* (e, t = !0) {
|
|
1712
1962
|
if ("not" in e) {
|
|
1713
|
-
yield*
|
|
1963
|
+
yield* $(e.not, !1);
|
|
1714
1964
|
return;
|
|
1715
1965
|
}
|
|
1716
1966
|
if ("and" in e) {
|
|
1717
|
-
for (let n of e.and) yield*
|
|
1967
|
+
for (let n of e.and) yield* $(n, t);
|
|
1718
1968
|
return;
|
|
1719
1969
|
}
|
|
1720
1970
|
if ("or" in e) {
|
|
1721
|
-
for (let t of e.or) yield*
|
|
1971
|
+
for (let t of e.or) yield* $(t, !1);
|
|
1722
1972
|
return;
|
|
1723
1973
|
}
|
|
1724
1974
|
e.op !== "subquery-in" && e.op !== "subquery-not-in" && e.op !== "exists" && e.op !== "not-exists" && (yield {
|
|
1725
1975
|
...e,
|
|
1726
1976
|
conjunctive: t
|
|
1727
1977
|
});
|
|
1728
|
-
},
|
|
1978
|
+
}, dr = (e, t) => ({
|
|
1729
1979
|
name: e,
|
|
1730
1980
|
body: t
|
|
1731
|
-
}),
|
|
1981
|
+
}), fr = (e) => {
|
|
1732
1982
|
if (e.lifecycle === "cron" && !e.cron) throw Error(`seed "${e.id}": lifecycle 'cron' requires a 'cron' field`);
|
|
1733
1983
|
if (e.lifecycle === "onSchemaChange" && (!e.watchedTables || e.watchedTables.length === 0)) throw Error(`seed "${e.id}": lifecycle 'onSchemaChange' requires at least one entry in 'watchedTables'`);
|
|
1734
|
-
let t = e.steps({ step:
|
|
1984
|
+
let t = e.steps({ step: dr });
|
|
1735
1985
|
if (t.length === 0) throw Error(`seed "${e.id}": at least one step is required`);
|
|
1736
1986
|
return {
|
|
1737
1987
|
__seed: !0,
|
|
@@ -1744,68 +1994,68 @@ var Gt = (e, t, n) => Kt(e, "id", t, n), Kt = (e, t, n, r, i = "asc") => {
|
|
|
1744
1994
|
...e.fingerprint === void 0 ? {} : { fingerprint: e.fingerprint },
|
|
1745
1995
|
steps: t
|
|
1746
1996
|
};
|
|
1747
|
-
},
|
|
1748
|
-
|
|
1749
|
-
},
|
|
1750
|
-
|
|
1751
|
-
},
|
|
1752
|
-
let t =
|
|
1997
|
+
}, pr = (e) => typeof e == "object" && !!e && "__seed" in e && e.__seed === !0, mr = null, hr = null, gr = (e) => {
|
|
1998
|
+
mr = e;
|
|
1999
|
+
}, _r = (e) => {
|
|
2000
|
+
hr = e;
|
|
2001
|
+
}, vr = async (e) => {
|
|
2002
|
+
let t = mr;
|
|
1753
2003
|
t !== null && await t(e);
|
|
1754
|
-
},
|
|
1755
|
-
let t =
|
|
2004
|
+
}, yr = async (e) => {
|
|
2005
|
+
let t = hr;
|
|
1756
2006
|
t !== null && e.changedTables.length !== 0 && await t(e);
|
|
1757
|
-
},
|
|
2007
|
+
}, br = (e) => {
|
|
1758
2008
|
if (!e.id || e.id.length === 0) throw Error("migration: `id` is required + must be non-empty");
|
|
1759
2009
|
if (!e.up || !e.down) throw Error(`migration ${e.id}: both \`up\` and \`down\` must be functions`);
|
|
1760
2010
|
return e;
|
|
1761
|
-
},
|
|
2011
|
+
}, xr = Symbol.for("voltro.migration.irreversible"), Sr = class extends Error {
|
|
1762
2012
|
migrationId;
|
|
1763
2013
|
reason;
|
|
1764
2014
|
_tag = "IrreversibleMigrationError";
|
|
1765
2015
|
constructor(e, t) {
|
|
1766
2016
|
super(`migration ${e} cannot be rolled back: ${t}`), this.migrationId = e, this.reason = t, this.name = "IrreversibleMigrationError";
|
|
1767
2017
|
}
|
|
1768
|
-
},
|
|
2018
|
+
}, Cr = (e) => {
|
|
1769
2019
|
if (!e || e.trim().length === 0) throw Error("irreversible(): a reason is required");
|
|
1770
|
-
return Object.assign(() => t.fail(new
|
|
1771
|
-
},
|
|
1772
|
-
let t = e[
|
|
2020
|
+
return Object.assign(() => t.fail(new Sr("<unknown>", e)), { [xr]: e });
|
|
2021
|
+
}, wr = (e) => {
|
|
2022
|
+
let t = e[xr];
|
|
1773
2023
|
return typeof t == "string" ? t : void 0;
|
|
1774
|
-
},
|
|
2024
|
+
}, Tr = class {
|
|
1775
2025
|
reason;
|
|
1776
2026
|
_tag = "MigrationSkipped";
|
|
1777
2027
|
constructor(e) {
|
|
1778
2028
|
this.reason = e;
|
|
1779
2029
|
}
|
|
1780
|
-
},
|
|
2030
|
+
}, Er = class extends Error {
|
|
1781
2031
|
migrationId;
|
|
1782
2032
|
failed;
|
|
1783
2033
|
_tag = "MigrationExpectationFailed";
|
|
1784
2034
|
constructor(e, t) {
|
|
1785
2035
|
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";
|
|
1786
2036
|
}
|
|
1787
|
-
},
|
|
2037
|
+
}, Dr = class extends Error {
|
|
1788
2038
|
migrationId;
|
|
1789
2039
|
dialect;
|
|
1790
2040
|
_tag = "TransactionBrokenByBodyError";
|
|
1791
2041
|
constructor(e, t) {
|
|
1792
2042
|
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";
|
|
1793
2043
|
}
|
|
1794
|
-
},
|
|
2044
|
+
}, Or = class extends Error {
|
|
1795
2045
|
table;
|
|
1796
2046
|
report;
|
|
1797
2047
|
_tag = "RewriteUnstableError";
|
|
1798
2048
|
constructor(e, t) {
|
|
1799
|
-
super(`rewrite of ${e} did not stabilise after ${t.passes} pass(es): ${t.rewritten} rewritten, ${t.contended} contended on the last pass.
|
|
2049
|
+
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";
|
|
1800
2050
|
}
|
|
1801
|
-
},
|
|
2051
|
+
}, kr = /^\d{8}_\d{6}_[a-z0-9_]+\.ts$/, Ar = (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", jr = /* @__PURE__ */ new Set(["voltro_isr_cache"]), Mr = (e) => jr.has(e) || e.startsWith("_voltro_") || e.startsWith("_cloud_") || e.startsWith("cluster_") || e.startsWith("__turso_internal_"), Nr = "_voltro_staging_", Pr = (e) => e.startsWith(Nr), Fr = /__dropped_\d{14}$/, Ir = (e) => Fr.test(e), Lr = 7, Rr = (e) => {
|
|
1802
2052
|
let t = /__dropped_(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/.exec(e);
|
|
1803
2053
|
if (t === null) return;
|
|
1804
2054
|
let [, n, r, i, a, o, s] = t;
|
|
1805
2055
|
return new Date(Date.UTC(Number(n), Number(r) - 1, Number(i), Number(a), Number(o), Number(s)));
|
|
1806
|
-
},
|
|
2056
|
+
}, zr = (e, t = {}) => {
|
|
1807
2057
|
let n = t.now ?? /* @__PURE__ */ new Date(), r = t.retentionDays ?? 7, i = [], a = (e, t) => {
|
|
1808
|
-
let a =
|
|
2058
|
+
let a = Rr(e);
|
|
1809
2059
|
if (a === void 0) return;
|
|
1810
2060
|
let o = Math.floor((n.getTime() - a.getTime()) / 864e5);
|
|
1811
2061
|
o >= r && i.push({
|
|
@@ -1814,123 +2064,123 @@ var Gt = (e, t, n) => Kt(e, "id", t, n), Kt = (e, t, n, r, i = "asc") => {
|
|
|
1814
2064
|
ageDays: o
|
|
1815
2065
|
});
|
|
1816
2066
|
};
|
|
1817
|
-
for (let t of e.tables) if (a(t.name, t.name), !
|
|
2067
|
+
for (let t of e.tables) if (a(t.name, t.name), !Ir(t.name)) for (let e of t.columns ?? []) a(e.name, `${t.name}.${e.name}`);
|
|
1818
2068
|
return i;
|
|
1819
|
-
},
|
|
2069
|
+
}, Br = (e, t) => {
|
|
1820
2070
|
let n = e.reduce((e, t) => e.ageDays >= t.ageDays ? e : t), r = (/* @__PURE__ */ new Date(Date.now() - t * 864e5)).toISOString().slice(0, 10);
|
|
1821
2071
|
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.`;
|
|
1822
|
-
},
|
|
1823
|
-
id:
|
|
1824
|
-
name:
|
|
1825
|
-
hash:
|
|
1826
|
-
status:
|
|
1827
|
-
appliedAt:
|
|
1828
|
-
durationMs:
|
|
1829
|
-
errorMessage:
|
|
1830
|
-
errorStack:
|
|
1831
|
-
workflowRunId:
|
|
1832
|
-
createdAt:
|
|
1833
|
-
updatedAt:
|
|
1834
|
-
}).index(["status"]),
|
|
1835
|
-
id:
|
|
1836
|
-
name:
|
|
1837
|
-
lifecycle:
|
|
1838
|
-
fingerprint:
|
|
1839
|
-
cronSchedule:
|
|
1840
|
-
watchedTables:
|
|
1841
|
-
nextRunAt:
|
|
1842
|
-
lastRunStatus:
|
|
1843
|
-
lastRunAt:
|
|
1844
|
-
lastRunDurationMs:
|
|
1845
|
-
lastRunRowsTouched:
|
|
1846
|
-
lastError:
|
|
1847
|
-
workflowRunId:
|
|
1848
|
-
createdAt:
|
|
1849
|
-
updatedAt:
|
|
1850
|
-
}).index(["lifecycle"]).index(["nextRunAt"]),
|
|
1851
|
-
id:
|
|
1852
|
-
fingerprint:
|
|
1853
|
-
liveFingerprint:
|
|
1854
|
-
operations:
|
|
1855
|
-
rollbackPlan:
|
|
1856
|
-
appliedBy:
|
|
1857
|
-
environment:
|
|
1858
|
-
source:
|
|
1859
|
-
onlineStrategy:
|
|
1860
|
-
durationMs:
|
|
1861
|
-
notes:
|
|
1862
|
-
squashedAt:
|
|
1863
|
-
appliedAt:
|
|
1864
|
-
createdAt:
|
|
1865
|
-
updatedAt:
|
|
1866
|
-
}).index(["fingerprint"]).index(["environment"]),
|
|
1867
|
-
id:
|
|
1868
|
-
scope:
|
|
1869
|
-
key:
|
|
1870
|
-
status:
|
|
1871
|
-
response:
|
|
1872
|
-
createdAt:
|
|
1873
|
-
}).unique(["scope", "key"]).index(["createdAt"]),
|
|
1874
|
-
id:
|
|
1875
|
-
tenantId:
|
|
1876
|
-
name:
|
|
1877
|
-
scopes:
|
|
1878
|
-
pairingHash:
|
|
1879
|
-
pairingExpiresAt:
|
|
1880
|
-
accessHash:
|
|
1881
|
-
accessExpiresAt:
|
|
1882
|
-
refreshHash:
|
|
1883
|
-
refreshExpiresAt:
|
|
1884
|
-
previousRefreshHash:
|
|
1885
|
-
generation:
|
|
1886
|
-
pairedAt:
|
|
1887
|
-
lastSeenAt:
|
|
1888
|
-
revokedAt:
|
|
1889
|
-
revokedReason:
|
|
1890
|
-
createdBy:
|
|
1891
|
-
metadata:
|
|
1892
|
-
createdAt:
|
|
1893
|
-
}).index(["tenantId"]).index(["pairingHash"]).index(["accessHash"]).index(["refreshHash"]).index(["previousRefreshHash"]),
|
|
1894
|
-
id:
|
|
1895
|
-
subjectType:
|
|
1896
|
-
subjectId:
|
|
1897
|
-
tenantId:
|
|
1898
|
-
selectedAt:
|
|
1899
|
-
}).primaryKey(["id"]).nonReactive(),
|
|
1900
|
-
id:
|
|
1901
|
-
key:
|
|
1902
|
-
value:
|
|
1903
|
-
expiresAt:
|
|
1904
|
-
createdAt:
|
|
1905
|
-
updatedAt:
|
|
1906
|
-
}).index(["expiresAt"]),
|
|
1907
|
-
id:
|
|
1908
|
-
tenantId:
|
|
1909
|
-
name:
|
|
1910
|
-
hashedKey:
|
|
1911
|
-
keyPrefix:
|
|
1912
|
-
scopes:
|
|
1913
|
-
lastUsedAt:
|
|
1914
|
-
requestCount:
|
|
1915
|
-
expiresAt:
|
|
1916
|
-
revokedAt:
|
|
1917
|
-
createdBy:
|
|
1918
|
-
onBehalfOf:
|
|
1919
|
-
metadata:
|
|
1920
|
-
createdAt:
|
|
1921
|
-
}).index("byApiKeyTenant", ["tenantId"]),
|
|
1922
|
-
id:
|
|
1923
|
-
replicaId:
|
|
1924
|
-
startedAt:
|
|
1925
|
-
version:
|
|
1926
|
-
kind:
|
|
1927
|
-
payload:
|
|
1928
|
-
reachableAt:
|
|
1929
|
-
writtenAt:
|
|
1930
|
-
}).unique(["replicaId", "kind"]).index(["kind"]),
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
2072
|
+
}, Vr = (e, t) => e.filter((e) => !Mr(e.name) || t.has(e.name)), Hr = I("_voltro_migrations", {
|
|
2073
|
+
id: f({ prefix: "mig" }),
|
|
2074
|
+
name: p(),
|
|
2075
|
+
hash: p(),
|
|
2076
|
+
status: p(),
|
|
2077
|
+
appliedAt: _().nullable(),
|
|
2078
|
+
durationMs: m().nullable(),
|
|
2079
|
+
errorMessage: p().nullable(),
|
|
2080
|
+
errorStack: p().nullable(),
|
|
2081
|
+
workflowRunId: p().nullable(),
|
|
2082
|
+
createdAt: _().default("now"),
|
|
2083
|
+
updatedAt: _().default("now").onUpdate("now")
|
|
2084
|
+
}).index(["status"]), Ur = I("_voltro_seeds", {
|
|
2085
|
+
id: f({ prefix: "seed" }),
|
|
2086
|
+
name: p(),
|
|
2087
|
+
lifecycle: p(),
|
|
2088
|
+
fingerprint: p(),
|
|
2089
|
+
cronSchedule: p().nullable(),
|
|
2090
|
+
watchedTables: v().nullable(),
|
|
2091
|
+
nextRunAt: _().nullable(),
|
|
2092
|
+
lastRunStatus: p().nullable(),
|
|
2093
|
+
lastRunAt: _().nullable(),
|
|
2094
|
+
lastRunDurationMs: m().nullable(),
|
|
2095
|
+
lastRunRowsTouched: m().nullable(),
|
|
2096
|
+
lastError: p().nullable(),
|
|
2097
|
+
workflowRunId: p().nullable(),
|
|
2098
|
+
createdAt: _().default("now"),
|
|
2099
|
+
updatedAt: _().default("now").onUpdate("now")
|
|
2100
|
+
}).index(["lifecycle"]).index(["nextRunAt"]), Wr = I("_voltro_migration_plans", {
|
|
2101
|
+
id: f({ prefix: "plan" }),
|
|
2102
|
+
fingerprint: p(),
|
|
2103
|
+
liveFingerprint: p().nullable(),
|
|
2104
|
+
operations: v(),
|
|
2105
|
+
rollbackPlan: v().nullable(),
|
|
2106
|
+
appliedBy: p(),
|
|
2107
|
+
environment: p(),
|
|
2108
|
+
source: p(),
|
|
2109
|
+
onlineStrategy: p().nullable(),
|
|
2110
|
+
durationMs: m(),
|
|
2111
|
+
notes: p().nullable(),
|
|
2112
|
+
squashedAt: _().nullable(),
|
|
2113
|
+
appliedAt: _().default("now"),
|
|
2114
|
+
createdAt: _().default("now"),
|
|
2115
|
+
updatedAt: _().default("now").onUpdate("now")
|
|
2116
|
+
}).index(["fingerprint"]).index(["environment"]), Gr = I("_voltro_idempotency", {
|
|
2117
|
+
id: f({ prefix: "idem" }),
|
|
2118
|
+
scope: p(),
|
|
2119
|
+
key: p(),
|
|
2120
|
+
status: p(),
|
|
2121
|
+
response: v().nullable(),
|
|
2122
|
+
createdAt: _().default("now")
|
|
2123
|
+
}).unique(["scope", "key"]).index(["createdAt"]), Kr = I("_voltro_devices", {
|
|
2124
|
+
id: f({ prefix: "device" }),
|
|
2125
|
+
tenantId: p(),
|
|
2126
|
+
name: p(),
|
|
2127
|
+
scopes: v().nullable(),
|
|
2128
|
+
pairingHash: p().maxLength(64).nullable(),
|
|
2129
|
+
pairingExpiresAt: _().nullable(),
|
|
2130
|
+
accessHash: p().maxLength(64).nullable(),
|
|
2131
|
+
accessExpiresAt: _().nullable(),
|
|
2132
|
+
refreshHash: p().maxLength(64).nullable(),
|
|
2133
|
+
refreshExpiresAt: _().nullable(),
|
|
2134
|
+
previousRefreshHash: p().maxLength(64).nullable(),
|
|
2135
|
+
generation: m().default(0),
|
|
2136
|
+
pairedAt: _().nullable(),
|
|
2137
|
+
lastSeenAt: _().nullable(),
|
|
2138
|
+
revokedAt: _().nullable(),
|
|
2139
|
+
revokedReason: p().nullable(),
|
|
2140
|
+
createdBy: p().nullable(),
|
|
2141
|
+
metadata: v().nullable(),
|
|
2142
|
+
createdAt: _()
|
|
2143
|
+
}).index(["tenantId"]).index(["pairingHash"]).index(["accessHash"]).index(["refreshHash"]).index(["previousRefreshHash"]), qr = I("_voltro_tenant_selections", {
|
|
2144
|
+
id: f({ prefix: "tsel" }),
|
|
2145
|
+
subjectType: p().maxLength(32),
|
|
2146
|
+
subjectId: p(),
|
|
2147
|
+
tenantId: p(),
|
|
2148
|
+
selectedAt: _()
|
|
2149
|
+
}).primaryKey(["id"]).nonReactive(), Jr = I("_voltro_kv", {
|
|
2150
|
+
id: f({ prefix: "kv" }),
|
|
2151
|
+
key: p().unique(),
|
|
2152
|
+
value: p().nullable(),
|
|
2153
|
+
expiresAt: _().nullable(),
|
|
2154
|
+
createdAt: _().default("now"),
|
|
2155
|
+
updatedAt: _().default("now").onUpdate("now")
|
|
2156
|
+
}).index(["expiresAt"]), Yr = I("_voltro_api_keys", {
|
|
2157
|
+
id: f({ prefix: "apikey" }),
|
|
2158
|
+
tenantId: p().nullable(),
|
|
2159
|
+
name: p(),
|
|
2160
|
+
hashedKey: p().maxLength(64).unique(),
|
|
2161
|
+
keyPrefix: p(),
|
|
2162
|
+
scopes: v().nullable(),
|
|
2163
|
+
lastUsedAt: _().nullable(),
|
|
2164
|
+
requestCount: m().default(0),
|
|
2165
|
+
expiresAt: _().nullable(),
|
|
2166
|
+
revokedAt: _().nullable(),
|
|
2167
|
+
createdBy: p().nullable(),
|
|
2168
|
+
onBehalfOf: p().nullable(),
|
|
2169
|
+
metadata: v().nullable(),
|
|
2170
|
+
createdAt: _().default("now")
|
|
2171
|
+
}).index("byApiKeyTenant", ["tenantId"]), Xr = I("_voltro_replica_observations", {
|
|
2172
|
+
id: f({ prefix: "robs" }),
|
|
2173
|
+
replicaId: p().maxLength(191),
|
|
2174
|
+
startedAt: _(),
|
|
2175
|
+
version: p().maxLength(64).nullable(),
|
|
2176
|
+
kind: p().maxLength(64),
|
|
2177
|
+
payload: p().nullable(),
|
|
2178
|
+
reachableAt: p().maxLength(255).nullable(),
|
|
2179
|
+
writtenAt: _().default("now").onUpdate("now")
|
|
2180
|
+
}).unique(["replicaId", "kind"]).index(["kind"]), Zr = [
|
|
2181
|
+
Hr,
|
|
2182
|
+
Ur,
|
|
2183
|
+
Wr
|
|
1934
2184
|
];
|
|
1935
2185
|
//#endregion
|
|
1936
|
-
export {
|
|
2186
|
+
export { tr as $, ae as $n, Wt as $t, br as A, M as An, Qt as At, qn as B, Te as Bn, Lt as Bt, Er as C, rt as Cn, se as Cr, W as Ct, Cr as D, Re as Dn, un as Dt, Dr as E, Le as En, sn as Et, _r as F, Pe as Fn, Ot as Ft, Z as G, he as Gn, B as Gt, Q as H, ye as Hn, Ut as Ht, gr as I, Fe as In, kt as It, Rn as J, x as Jn, qt as Jt, ir as K, me as Kn, Yt as Kt, Jn as L, we as Ln, Xt as Lt, yr as M, N as Mn, jt as Mt, vr as N, xe as Nn, Gt as Nt, wr as O, ze as On, Zt as Ot, pr as P, je as Pn, Pt, Yn as Q, y as Qn, At as Qt, Qn as R, Me as Rn, Vt as Rt, Sr as S, it as Sn, _ as Sr, vn as St, Or as T, Qe as Tn, cn as Tt, Un as U, ge as Un, Nt as Ut, Kn as V, ve as Vn, Ht as Vt, Fn as W, _e as Wn, Mt as Wt, nr as X, te as Xn, Kt as Xt, Vn as Y, ce as Yn, Bt as Yt, Xn as Z, re as Zn, zt as Zt, Ir as _, lt as _n, h as _r, Cn as _t, Wr as a, z as an, g as ar, Hn as at, Rr as b, st as bn, o as br, G as bt, Ur as c, Ct as cn, de as cr, Zn as ct, Lr as d, _t as dn, le as dr, Y as dt, Ft as en, l as er, zn as et, jr as f, gt as fn, v as fr, q as ft, Mr as g, I as gn, c as gr, Sn as gt, Br as h, ct as hn, fe as hr, K as ht, Jr as i, St as in, ne as ir, ar as it, fr as j, A as jn, en as jt, Ar as k, j as kn, $t as kt, qr as l, Tt as ln, f as lr, Wn as lt, zr as m, ut as mn, ee as mr, J as mt, Kr as n, wt as nn, b as nr, In as nt, Hr as o, Dt as on, oe as or, rr as ot, Nr as p, L as pn, w as pr, wn as pt, Ln as q, u as qn, Jt as qt, Gr as r, Et as rn, ie as rr, er as rt, Xr as s, xt as sn, ue as sr, $n as st, Yr as t, It as tn, s as tr, Bn as tt, Zr as u, vt as un, m as ur, $ as ut, Pr as v, ot as vn, C as vr, hn as vt, Tr as w, tt as wn, on as wt, kr as x, nt as xn, p as xr, yn as xt, Vr as y, at as yn, S as yr, mn as yt, Gn as z, Ne as zn, Rt as zt };
|