@voltro/database 0.73.0 → 0.75.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 +449 -0
- package/dist/{frameworkLiveTables-C1WjQ_uI.js → frameworkTables-CfWuWeFG.js} +587 -292
- package/dist/index.d.ts +96 -2
- package/dist/index.js +628 -871
- package/dist/sql.d.ts +121 -7
- package/dist/sql.js +1356 -1308
- package/package.json +2 -2
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { typeid as
|
|
3
|
-
import { ulid as
|
|
1
|
+
import { Cause as e, Effect as t, Runtime as n, Schema as r } from "effect";
|
|
2
|
+
import { typeid as i } from "typeid-js";
|
|
3
|
+
import { ulid as a } from "ulidx";
|
|
4
4
|
//#region src/columns.ts
|
|
5
|
-
var
|
|
5
|
+
var o = (e) => {
|
|
6
6
|
let t = [];
|
|
7
7
|
for (let [n, r] of Object.entries(e.fields)) r.serverOnly === !0 && t.push(n);
|
|
8
8
|
return t;
|
|
9
|
-
},
|
|
9
|
+
}, s = (e) => {
|
|
10
10
|
let t = [];
|
|
11
11
|
for (let [n, r] of Object.entries(e.fields)) r.crdtManaged === !0 && t.push(n);
|
|
12
12
|
return t;
|
|
13
|
-
},
|
|
13
|
+
}, c = (e) => {
|
|
14
14
|
let t = [];
|
|
15
15
|
for (let [n, r] of Object.entries(e.fields)) {
|
|
16
16
|
let e = r.readableBy;
|
|
@@ -20,11 +20,11 @@ var i = (e) => {
|
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
22
|
return t;
|
|
23
|
-
},
|
|
23
|
+
}, ee = (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
|
+
}, l = class e {
|
|
28
28
|
definition;
|
|
29
29
|
constructor(e) {
|
|
30
30
|
this.definition = e;
|
|
@@ -185,14 +185,14 @@ var i = (e) => {
|
|
|
185
185
|
__definition() {
|
|
186
186
|
return this.definition;
|
|
187
187
|
}
|
|
188
|
-
},
|
|
188
|
+
}, u = (e) => new l({
|
|
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 d(e) {
|
|
195
|
+
return new l({
|
|
196
196
|
type: "id",
|
|
197
197
|
nullable: !1,
|
|
198
198
|
unique: !0,
|
|
@@ -200,10 +200,10 @@ function ee(e) {
|
|
|
200
200
|
idSchemeInput: e
|
|
201
201
|
});
|
|
202
202
|
}
|
|
203
|
-
var
|
|
203
|
+
var f = () => u("text"), p = () => u("integer"), te = () => u("real"), ne = (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 l({
|
|
207
207
|
type: "decimal",
|
|
208
208
|
nullable: !1,
|
|
209
209
|
unique: !1,
|
|
@@ -211,12 +211,12 @@ var u = () => l("text"), te = () => l("integer"), ne = () => l("real"), re = (e,
|
|
|
211
211
|
precision: e,
|
|
212
212
|
scale: t
|
|
213
213
|
});
|
|
214
|
-
},
|
|
214
|
+
}, re = ne, ie = () => u("bigint"), ae = (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 l({
|
|
220
220
|
type: "enum",
|
|
221
221
|
nullable: !1,
|
|
222
222
|
unique: !1,
|
|
@@ -225,26 +225,26 @@ var u = () => l("text"), te = () => l("integer"), ne = () => l("real"), re = (e,
|
|
|
225
225
|
enumValues: t
|
|
226
226
|
})
|
|
227
227
|
};
|
|
228
|
-
},
|
|
228
|
+
}, oe = () => u("boolean"), m = () => u("timestamp"), se = () => u("date"), h = () => u("json"), ce = () => u("bytes"), le = () => new l({
|
|
229
229
|
type: "bytes",
|
|
230
230
|
nullable: !0,
|
|
231
231
|
unique: !1,
|
|
232
232
|
hasDefault: !1,
|
|
233
233
|
crdtManaged: !0
|
|
234
|
-
}),
|
|
234
|
+
}), ue = () => new l({
|
|
235
235
|
type: "bytes",
|
|
236
236
|
nullable: !0,
|
|
237
237
|
unique: !1,
|
|
238
238
|
hasDefault: !1,
|
|
239
239
|
crdtManaged: !0
|
|
240
|
-
}),
|
|
240
|
+
}), g = () => {
|
|
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 de(e) {
|
|
244
|
+
return fe(g, e);
|
|
245
245
|
}
|
|
246
|
-
function
|
|
247
|
-
return new
|
|
246
|
+
function fe(e, t) {
|
|
247
|
+
return new l({
|
|
248
248
|
type: "reference",
|
|
249
249
|
nullable: !1,
|
|
250
250
|
unique: !1,
|
|
@@ -259,15 +259,15 @@ function he(e, t) {
|
|
|
259
259
|
...t?.orphanPolicy ? { orphanPolicy: t.orphanPolicy } : {}
|
|
260
260
|
});
|
|
261
261
|
}
|
|
262
|
-
var
|
|
262
|
+
var pe = () => new l({
|
|
263
263
|
type: "text",
|
|
264
264
|
nullable: !0,
|
|
265
265
|
unique: !1,
|
|
266
266
|
hasDefault: !1,
|
|
267
267
|
dropped: !0
|
|
268
|
-
}),
|
|
268
|
+
}), me = (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 l({
|
|
271
271
|
type: "vector",
|
|
272
272
|
nullable: !1,
|
|
273
273
|
unique: !1,
|
|
@@ -275,13 +275,13 @@ var ge = () => new c({
|
|
|
275
275
|
vectorDim: e,
|
|
276
276
|
vectorPrecision: t?.precision ?? "float32"
|
|
277
277
|
});
|
|
278
|
-
},
|
|
278
|
+
}, he = (e) => new l({
|
|
279
279
|
type: "array",
|
|
280
280
|
nullable: !1,
|
|
281
281
|
unique: !1,
|
|
282
282
|
hasDefault: !1,
|
|
283
283
|
arrayElement: e.__definition().type
|
|
284
|
-
}),
|
|
284
|
+
}), ge = () => u("interval"), _e = (e, t = 4326) => new l({
|
|
285
285
|
type: "text",
|
|
286
286
|
nullable: !1,
|
|
287
287
|
unique: !1,
|
|
@@ -291,7 +291,7 @@ var ge = () => new c({
|
|
|
291
291
|
geomKind: e,
|
|
292
292
|
srid: t
|
|
293
293
|
}
|
|
294
|
-
}),
|
|
294
|
+
}), ve = (e, t = 4326) => new l({
|
|
295
295
|
type: "text",
|
|
296
296
|
nullable: !1,
|
|
297
297
|
unique: !1,
|
|
@@ -301,51 +301,234 @@ var ge = () => new c({
|
|
|
301
301
|
geomKind: e,
|
|
302
302
|
srid: t
|
|
303
303
|
}
|
|
304
|
-
}),
|
|
304
|
+
}), ye = (e) => new l({
|
|
305
305
|
type: "raw",
|
|
306
306
|
nullable: !1,
|
|
307
307
|
unique: !1,
|
|
308
308
|
hasDefault: !1,
|
|
309
309
|
rawDdl: e
|
|
310
|
-
}),
|
|
310
|
+
}), _ = (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
|
+
}, be = /* @__PURE__ */ new WeakMap(), xe = (e) => typeof e == "object" && e ? be.get(e) : void 0, Se = (e, t = {}) => {
|
|
315
|
+
let n = f();
|
|
316
|
+
return be.set(n, {
|
|
317
317
|
target: e,
|
|
318
318
|
orphanPolicy: t.orphanPolicy ?? "keep",
|
|
319
319
|
onSoftDelete: t.onSoftDelete ?? !1
|
|
320
320
|
}), n;
|
|
321
|
-
},
|
|
321
|
+
}, v = /* @__PURE__ */ new Map(), Ce = (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 = v.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
|
-
},
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
328
|
+
n.push(t), v.set(e, n);
|
|
329
|
+
}, we = (e) => v.get(e) ?? [], Te = () => v, Ee = () => {
|
|
330
|
+
v.clear();
|
|
331
|
+
}, De = (t) => {
|
|
332
|
+
let r = t;
|
|
333
|
+
for (let t = 0; t < 4 && n.isFiberFailure(r); t++) r = e.squash(r[n.FiberFailureCauseId]);
|
|
334
|
+
return r;
|
|
335
|
+
}, y = (t, r = 0) => {
|
|
336
|
+
if (r >= 4 || !n.isFiberFailure(t)) return [t];
|
|
337
|
+
let i = t[n.FiberFailureCauseId], a = [...e.failures(i), ...e.defects(i)];
|
|
338
|
+
if (a.length === 0) return [e.squash(i)];
|
|
339
|
+
let o = [];
|
|
340
|
+
for (let e of a.slice(0, 8)) o.push(...y(e, r + 1));
|
|
341
|
+
return o;
|
|
342
|
+
}, Oe = (e) => e.dbCode !== void 0 || e.dbErrno !== void 0 || e.dbNumber !== void 0 || e.dbSqlState !== void 0 || e.dbConstraint !== void 0, ke = (e) => {
|
|
343
|
+
let t = {}, n = [], r = De(e);
|
|
344
|
+
for (let e = 0; e < 8 && typeof r == "object" && r; e++) {
|
|
345
|
+
let e = r;
|
|
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
|
+
let i = e.sqlMessage ?? e.detail;
|
|
348
|
+
t.dbMessage === void 0 && typeof i == "string" && (t.dbMessage = i);
|
|
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 = De(e.cause);
|
|
351
|
+
}
|
|
352
|
+
return n.length > 0 && (t.dbCauseChain = n.join(" ← "), t.dbMessage === void 0 && (t.dbMessage = n[n.length - 1])), t;
|
|
353
|
+
}, b = (e) => {
|
|
354
|
+
let t = y(e).map(ke);
|
|
355
|
+
if (t.length <= 1) return t[0] ?? {};
|
|
356
|
+
let n = t.find(Oe) ?? t[0], r = t.filter((e) => e !== n).map((e) => e.dbCauseChain).filter((e) => typeof e == "string");
|
|
357
|
+
if (r.length === 0) return n;
|
|
358
|
+
let i = typeof n.dbCauseChain == "string" ? n.dbCauseChain : void 0;
|
|
359
|
+
return {
|
|
360
|
+
...n,
|
|
361
|
+
dbCauseChain: [i, ...r].filter(Boolean).join(" ‖ ")
|
|
362
|
+
};
|
|
363
|
+
}, Ae = (e, t) => {
|
|
364
|
+
let n = b(e), r = w(n, t);
|
|
365
|
+
if (r !== void 0) {
|
|
366
|
+
let e = r.constraint ?? r.column;
|
|
367
|
+
return e === void 0 ? r.kind : `${r.kind}: ${e}`;
|
|
368
|
+
}
|
|
369
|
+
let i = n.dbCode ?? n.dbSqlState ?? n.dbErrno ?? n.dbNumber, a = Ne(e);
|
|
370
|
+
return i !== void 0 && je.test(String(i)) ? `${a} (${String(i)})` : a;
|
|
371
|
+
}, je = /^[A-Za-z0-9_]{1,32}$/, Me = /^[A-Za-z_][A-Za-z0-9_]{0,63}$/, Ne = (e) => {
|
|
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 && Me.test(r) ? r : "unknown";
|
|
374
|
+
}, Pe = /^[A-Za-z_][A-Za-z0-9_$]*$/, x = (e) => e !== void 0 && e.length <= 128 && Pe.test(e) ? e : void 0, S = (e) => e === void 0 ? void 0 : e.split(".").pop() ?? e, C = (e, ...t) => {
|
|
375
|
+
for (let n of t) {
|
|
376
|
+
let t = n.exec(e);
|
|
377
|
+
if (t?.[1] !== void 0) return t[1];
|
|
378
|
+
}
|
|
379
|
+
}, w = (e, t) => {
|
|
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
|
+
if (n === "23503") {
|
|
382
|
+
let t = x(e.dbConstraint);
|
|
383
|
+
return {
|
|
384
|
+
kind: /is still referenced from table/i.test(o) ? "foreignKeyInUse" : "foreignKey",
|
|
385
|
+
...t === void 0 ? {} : { constraint: t }
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
if (n === "23505") {
|
|
389
|
+
let t = x(e.dbConstraint);
|
|
390
|
+
return {
|
|
391
|
+
kind: "unique",
|
|
392
|
+
...t === void 0 ? {} : { constraint: t }
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
if (n === "23502") {
|
|
396
|
+
let t = x(e.dbColumn);
|
|
397
|
+
return {
|
|
398
|
+
kind: "notNull",
|
|
399
|
+
...t === void 0 ? {} : { column: t }
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
if (n === "23514") {
|
|
403
|
+
let t = x(e.dbConstraint);
|
|
404
|
+
return {
|
|
405
|
+
kind: "check",
|
|
406
|
+
...t === void 0 ? {} : { constraint: t }
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
if (r === 1452 || r === 1451) {
|
|
410
|
+
let e = x(C(o, /CONSTRAINT `([^`]+)`/));
|
|
411
|
+
return {
|
|
412
|
+
kind: r === 1451 ? "foreignKeyInUse" : "foreignKey",
|
|
413
|
+
...e === void 0 ? {} : { constraint: e }
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
if (r === 1062) {
|
|
417
|
+
let e = x(S(C(o, /for key '([^']+)'/)));
|
|
418
|
+
return {
|
|
419
|
+
kind: "unique",
|
|
420
|
+
...e === void 0 ? {} : { constraint: e }
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
if (r === 1048 || r === 1364) {
|
|
424
|
+
let e = x(C(o, /Column '([^']+)' cannot be null/, /Field '([^']+)' doesn't have a default value/));
|
|
425
|
+
return {
|
|
426
|
+
kind: "notNull",
|
|
427
|
+
...e === void 0 ? {} : { column: e }
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
if (r === 3819 || r === 4025) {
|
|
431
|
+
let e = x(C(o, /Check constraint '([^']+)'/, /CONSTRAINT `([^`]+)` failed/));
|
|
432
|
+
return {
|
|
433
|
+
kind: "check",
|
|
434
|
+
...e === void 0 ? {} : { constraint: e }
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
if (i === 547) {
|
|
438
|
+
let e = C(o, /(?:FOREIGN KEY|REFERENCE) constraint "([^"]+)"/), t = C(o, /CHECK constraint "([^"]+)"/);
|
|
439
|
+
if (t !== void 0 && e === void 0) {
|
|
440
|
+
let e = x(t);
|
|
441
|
+
return {
|
|
442
|
+
kind: "check",
|
|
443
|
+
...e === void 0 ? {} : { constraint: e }
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
let n = /REFERENCE constraint/.test(o), r = x(e);
|
|
447
|
+
return {
|
|
448
|
+
kind: n ? "foreignKeyInUse" : "foreignKey",
|
|
449
|
+
...r === void 0 ? {} : { constraint: r }
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
if (i === 2627 || i === 2601) {
|
|
453
|
+
let e = x(C(o, /(?:UNIQUE KEY|PRIMARY KEY) constraint '([^']+)'/, /index '([^']+)'/));
|
|
454
|
+
return {
|
|
455
|
+
kind: "unique",
|
|
456
|
+
...e === void 0 ? {} : { constraint: e }
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
if (i === 515) {
|
|
460
|
+
let e = x(C(o, /Cannot insert the value NULL into column '([^']+)'/));
|
|
461
|
+
return {
|
|
462
|
+
kind: "notNull",
|
|
463
|
+
...e === void 0 ? {} : { column: e }
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
if (n === "SQLITE_CONSTRAINT_FOREIGNKEY") return { kind: t === "delete" || t === "deleteMany" || t === "hardDelete" ? "foreignKeyInUse" : "foreignKey" };
|
|
467
|
+
if (n === "SQLITE_CONSTRAINT_UNIQUE" || n === "SQLITE_CONSTRAINT_PRIMARYKEY") {
|
|
468
|
+
let e = x(S(C(o, /UNIQUE constraint failed: ([^,\s]+)/)));
|
|
469
|
+
return {
|
|
470
|
+
kind: "unique",
|
|
471
|
+
...e === void 0 ? {} : { column: e }
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
if (n === "SQLITE_CONSTRAINT_NOTNULL") {
|
|
475
|
+
let e = x(S(C(o, /NOT NULL constraint failed: ([^,\s]+)/)));
|
|
476
|
+
return {
|
|
477
|
+
kind: "notNull",
|
|
478
|
+
...e === void 0 ? {} : { column: e }
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
if (n === "SQLITE_CONSTRAINT_CHECK") {
|
|
482
|
+
let e = x(C(a, /CHECK constraint failed: (.+)$/));
|
|
483
|
+
return {
|
|
484
|
+
kind: "check",
|
|
485
|
+
...e === void 0 ? {} : { constraint: e }
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
}, Fe = (e) => {
|
|
489
|
+
let t = w(e)?.kind;
|
|
490
|
+
return t === "foreignKey" || t === "foreignKeyInUse";
|
|
491
|
+
}, Ie = (e) => {
|
|
492
|
+
let t = e.dbCode, n = e.dbErrno;
|
|
493
|
+
return t === "57014" || n === 3024 || n === 1969 || t === "ETIMEOUT" || t === "SQLITE_INTERRUPT";
|
|
494
|
+
}, Le = (e) => {
|
|
495
|
+
let t = b(e), n = [
|
|
496
|
+
t.dbCode === void 0 ? void 0 : `code=${String(t.dbCode)}`,
|
|
497
|
+
t.dbErrno === void 0 ? void 0 : `errno=${String(t.dbErrno)}`,
|
|
498
|
+
t.dbNumber === void 0 ? void 0 : `number=${String(t.dbNumber)}`,
|
|
499
|
+
t.dbSqlState === void 0 ? void 0 : `sqlState=${String(t.dbSqlState)}`,
|
|
500
|
+
t.dbConstraint === void 0 ? void 0 : `constraint=${String(t.dbConstraint)}`,
|
|
501
|
+
t.dbPlaceholders === void 0 ? void 0 : `placeholders=${String(t.dbPlaceholders)}`
|
|
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
|
+
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
|
+
}, Re = (e) => Object.entries(e).map(([e, t]) => `${e}:${ze(t)}`).join(" "), ze = (e) => {
|
|
505
|
+
if (e === null) return "null";
|
|
506
|
+
if (e === void 0) return "undefined";
|
|
507
|
+
if (typeof e == "bigint") return "bigint";
|
|
508
|
+
if (typeof e != "object") return typeof e;
|
|
509
|
+
if (e instanceof Date) return Number.isNaN(e.getTime()) ? "Date(Invalid)" : "Date";
|
|
510
|
+
if (Array.isArray(e)) return "Array";
|
|
511
|
+
if (globalThis.Buffer !== void 0 && globalThis.Buffer.isBuffer(e)) return "Buffer";
|
|
512
|
+
let t = e.constructor?.name;
|
|
513
|
+
return typeof t == "string" && t !== "" ? t : "Object";
|
|
514
|
+
}, Be = 63, Ve = 60, T = [], E = (e) => {
|
|
515
|
+
T.includes(e) || T.push(e);
|
|
516
|
+
}, He = () => {
|
|
517
|
+
let e = T.slice();
|
|
518
|
+
return T.length = 0, e;
|
|
519
|
+
}, Ue = /^[a-zA-Z_][a-zA-Z0-9_]*$/, D = (e, t) => {
|
|
337
520
|
if (t.length === 0) throw Error(`${e} cannot be empty.`);
|
|
338
|
-
if (!
|
|
339
|
-
},
|
|
340
|
-
if (
|
|
341
|
-
e.length > 60 &&
|
|
342
|
-
},
|
|
343
|
-
if (
|
|
344
|
-
t.length > 60 &&
|
|
345
|
-
},
|
|
346
|
-
if (
|
|
347
|
-
t.length > 60 &&
|
|
348
|
-
},
|
|
521
|
+
if (!Ue.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
|
+
}, O = (e) => {
|
|
523
|
+
if (D("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 && E(`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.`);
|
|
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.` : ""}`);
|
|
531
|
+
}, j = (e, t) => {
|
|
349
532
|
if (e.length === 0) throw Error(`typeid prefix on table '${t.tableName}' cannot be empty.`);
|
|
350
533
|
if (!/^[a-z][a-z0-9_]*$/.test(e)) {
|
|
351
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_]*$/.";
|
|
@@ -355,44 +538,44 @@ var ge = () => new c({
|
|
|
355
538
|
let n = t.kind === "derived" ? "shorten the table name, or supply an explicit short prefix via id({ prefix: '...' })." : "pick a shorter prefix.";
|
|
356
539
|
throw Error(`typeid prefix '${e}' on table '${t.tableName}' is ${e.length} chars — exceeds the 63-byte limit; ${n}`);
|
|
357
540
|
}
|
|
358
|
-
e.length > 60 &&
|
|
359
|
-
},
|
|
541
|
+
e.length > 60 && E(`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
|
+
}, We = 1704067200000n, Ge = 10n, Ke = 12n, qe = (1n << Ge) - 1n, Je = (1n << Ke) - 1n, Ye = Ke, Xe = 22n, Ze = () => {
|
|
360
543
|
let e = process.env.SNOWFLAKE_MACHINE_ID;
|
|
361
544
|
if (e === void 0 || e === "") return 0n;
|
|
362
545
|
let t = BigInt(e);
|
|
363
|
-
if (t < 0n || t >
|
|
546
|
+
if (t < 0n || t > qe) throw Error(`SNOWFLAKE_MACHINE_ID out of range: ${e}. Must be 0..${qe}.`);
|
|
364
547
|
return t;
|
|
365
|
-
},
|
|
548
|
+
}, Qe = () => ({
|
|
366
549
|
lastMs: 0n,
|
|
367
550
|
sequence: 0n,
|
|
368
|
-
machineId:
|
|
369
|
-
}),
|
|
370
|
-
|
|
371
|
-
},
|
|
372
|
-
let t =
|
|
373
|
-
for (; t <= e;) t =
|
|
551
|
+
machineId: Ze()
|
|
552
|
+
}), M, $e = () => (M === void 0 && (M = Qe()), M), et = () => {
|
|
553
|
+
M = Qe();
|
|
554
|
+
}, N = () => BigInt(Date.now()), tt = (e) => {
|
|
555
|
+
let t = N();
|
|
556
|
+
for (; t <= e;) t = N();
|
|
374
557
|
return t;
|
|
375
|
-
},
|
|
376
|
-
let e =
|
|
377
|
-
t === e.lastMs ? (e.sequence = e.sequence + 1n &
|
|
378
|
-
let n = t -
|
|
558
|
+
}, nt = () => {
|
|
559
|
+
let e = $e(), t = N();
|
|
560
|
+
t === e.lastMs ? (e.sequence = e.sequence + 1n & Je, e.sequence === 0n && (t = tt(e.lastMs), e.lastMs = t)) : (e.sequence = 0n, e.lastMs = t);
|
|
561
|
+
let n = t - We;
|
|
379
562
|
if (n < 0n) throw Error("Snowflake timestamp before configured epoch (2024-01-01). System clock is wrong.");
|
|
380
|
-
return (n <<
|
|
381
|
-
},
|
|
563
|
+
return (n << Xe | e.machineId << Ye | e.sequence).toString();
|
|
564
|
+
}, P = (e) => {
|
|
382
565
|
let t = e.toLowerCase();
|
|
383
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.`);
|
|
384
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: '...' }).`);
|
|
385
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;
|
|
386
|
-
return
|
|
569
|
+
return j(n, {
|
|
387
570
|
kind: "derived",
|
|
388
571
|
tableName: e
|
|
389
572
|
}), n;
|
|
390
|
-
},
|
|
573
|
+
}, rt = (e, t) => {
|
|
391
574
|
if (e === void 0) return {
|
|
392
575
|
kind: "typeid",
|
|
393
|
-
prefix:
|
|
576
|
+
prefix: P(t)
|
|
394
577
|
};
|
|
395
|
-
if ("prefix" in e && !("scheme" in e)) return
|
|
578
|
+
if ("prefix" in e && !("scheme" in e)) return j(e.prefix, {
|
|
396
579
|
kind: "explicit",
|
|
397
580
|
tableName: t
|
|
398
581
|
}), {
|
|
@@ -402,8 +585,8 @@ var ge = () => new c({
|
|
|
402
585
|
if (!("scheme" in e)) throw Error("invalid id() options: no scheme or prefix");
|
|
403
586
|
switch (e.scheme) {
|
|
404
587
|
case "typeid": {
|
|
405
|
-
let n = e.prefix ??
|
|
406
|
-
return e.prefix !== void 0 &&
|
|
588
|
+
let n = e.prefix ?? P(t);
|
|
589
|
+
return e.prefix !== void 0 && j(e.prefix, {
|
|
407
590
|
kind: "explicit",
|
|
408
591
|
tableName: t
|
|
409
592
|
}), {
|
|
@@ -419,22 +602,22 @@ var ge = () => new c({
|
|
|
419
602
|
generate: e.generate
|
|
420
603
|
};
|
|
421
604
|
}
|
|
422
|
-
},
|
|
605
|
+
}, it = (e, t) => {
|
|
423
606
|
switch (e.kind) {
|
|
424
|
-
case "typeid": return
|
|
425
|
-
case "ulid": return
|
|
607
|
+
case "typeid": return i(e.prefix).toString();
|
|
608
|
+
case "ulid": return a();
|
|
426
609
|
case "numeric": return null;
|
|
427
|
-
case "snowflake": return
|
|
610
|
+
case "snowflake": return nt();
|
|
428
611
|
case "custom": return e.generate(t);
|
|
429
612
|
}
|
|
430
|
-
},
|
|
431
|
-
fields:
|
|
613
|
+
}, at = (e) => ({
|
|
614
|
+
fields: _(e.fields),
|
|
432
615
|
...e.id === void 0 ? {} : { id: e.id },
|
|
433
616
|
...e.requires === void 0 ? {} : { requires: e.requires },
|
|
434
617
|
...e.indexes === void 0 ? {} : { indexes: e.indexes },
|
|
435
618
|
...e.behaviors === void 0 ? {} : { behaviors: e.behaviors },
|
|
436
619
|
...e.policies === void 0 ? {} : { policies: e.policies }
|
|
437
|
-
}),
|
|
620
|
+
}), ot = at, st = (e) => {
|
|
438
621
|
let t = /* @__PURE__ */ new Set(), n = [], r = (e) => {
|
|
439
622
|
let i = e.id ?? e;
|
|
440
623
|
if (!t.has(i)) {
|
|
@@ -444,7 +627,7 @@ var ge = () => new c({
|
|
|
444
627
|
};
|
|
445
628
|
for (let t of e) r(t);
|
|
446
629
|
return n;
|
|
447
|
-
},
|
|
630
|
+
}, ct = (e, ...t) => {
|
|
448
631
|
if (t.length === 0) throw Error(`jsonIndex("${e}"): at least one path segment is required`);
|
|
449
632
|
let n = (r) => ({
|
|
450
633
|
jsonPath: {
|
|
@@ -455,14 +638,14 @@ var ge = () => new c({
|
|
|
455
638
|
numeric: () => n(!0)
|
|
456
639
|
});
|
|
457
640
|
return n(!1);
|
|
458
|
-
},
|
|
641
|
+
}, lt = (e = "cosine", t = "float32") => {
|
|
459
642
|
let n = t === "half" ? "halfvec" : "vector";
|
|
460
643
|
switch (e) {
|
|
461
644
|
case "cosine": return `${n}_cosine_ops`;
|
|
462
645
|
case "l2": return `${n}_l2_ops`;
|
|
463
646
|
case "inner": return `${n}_ip_ops`;
|
|
464
647
|
}
|
|
465
|
-
},
|
|
648
|
+
}, ut = [
|
|
466
649
|
"id",
|
|
467
650
|
"tenantId",
|
|
468
651
|
"createdAt",
|
|
@@ -471,7 +654,7 @@ var ge = () => new c({
|
|
|
471
654
|
"updatedBy",
|
|
472
655
|
"deletedAt",
|
|
473
656
|
"deletedBy"
|
|
474
|
-
],
|
|
657
|
+
], dt = (e) => e.id ?? `<anonymous mixin: ${Object.keys(e.fields).join(", ")}>`, F = (e, t) => `${e}_${t.join("_")}_idx`, ft = (e, t) => `${e}_${t.join("_")}_uq`, I = (e, t, n, r, i) => {
|
|
475
658
|
if (n !== "hnsw") return;
|
|
476
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.`);
|
|
477
660
|
let a = r[0];
|
|
@@ -479,15 +662,15 @@ var ge = () => new c({
|
|
|
479
662
|
let o = i[a];
|
|
480
663
|
if (o === void 0) throw Error(`hnsw index '${t}' on table '${e}' references unknown column '${a}'.`);
|
|
481
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.`);
|
|
482
|
-
},
|
|
665
|
+
}, pt = (e, t) => {
|
|
483
666
|
let n;
|
|
484
667
|
for (let [r, i] of Object.entries(e)) i.type === "id" && i.idScheme === void 0 && (n === void 0 && (n = { ...e }), n[r] = {
|
|
485
668
|
...i,
|
|
486
|
-
idScheme:
|
|
669
|
+
idScheme: rt(i.idSchemeInput, t)
|
|
487
670
|
});
|
|
488
671
|
return n ?? e;
|
|
489
|
-
},
|
|
490
|
-
let
|
|
672
|
+
}, L = (e) => {
|
|
673
|
+
let t = e.appliedPrimaryKey ?? [];
|
|
491
674
|
return {
|
|
492
675
|
tableName: e.tableName,
|
|
493
676
|
fields: e.fields,
|
|
@@ -499,14 +682,14 @@ var ge = () => new c({
|
|
|
499
682
|
appliedChecks: e.appliedChecks,
|
|
500
683
|
appliedRules: e.appliedRules ?? [],
|
|
501
684
|
appliedPluginRefs: e.appliedPluginRefs ?? [],
|
|
502
|
-
appliedPrimaryKey:
|
|
685
|
+
appliedPrimaryKey: t,
|
|
503
686
|
...e.previousTableName === void 0 ? {} : { previousTableName: e.previousTableName },
|
|
504
687
|
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
505
688
|
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema },
|
|
506
689
|
fullTextIndex: ((t, n, r) => {
|
|
507
690
|
if (n.length === 0) throw Error(`fullTextIndex '${t}' on '${e.tableName}' has no columns.`);
|
|
508
|
-
if (
|
|
509
|
-
return
|
|
691
|
+
if (A(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 L({
|
|
510
693
|
...e,
|
|
511
694
|
tableName: e.tableName,
|
|
512
695
|
fields: e.fields,
|
|
@@ -527,27 +710,27 @@ var ge = () => new c({
|
|
|
527
710
|
});
|
|
528
711
|
}),
|
|
529
712
|
with: ((...t) => {
|
|
530
|
-
let n =
|
|
713
|
+
let n = st(t), r = { ...e.fields }, i = /* @__PURE__ */ new Map();
|
|
531
714
|
for (let e of Object.keys(r)) i.set(e, {
|
|
532
715
|
id: "<table>",
|
|
533
716
|
fields: {}
|
|
534
717
|
});
|
|
535
718
|
for (let t of n) for (let [n, a] of Object.entries(t.fields)) {
|
|
536
719
|
let o = i.get(n);
|
|
537
|
-
if (o !== void 0) throw Error(`mixin collision on column '${n}' in table '${e.tableName}': '${
|
|
538
|
-
|
|
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
|
+
k(e.tableName, n), r[n] = a, i.set(n, t);
|
|
539
722
|
}
|
|
540
723
|
let a = [...e.appliedIndexes];
|
|
541
724
|
for (let t of n) for (let n of t.indexes ?? []) {
|
|
542
|
-
let t = n.name ??
|
|
543
|
-
a.some((e) => e.name === t) || (
|
|
725
|
+
let t = n.name ?? F(e.tableName, n.fields);
|
|
726
|
+
a.some((e) => e.name === t) || (A(e.tableName, t, n.name === void 0, n.fields), I(e.tableName, t, n.kind, n.fields, r), a.push({
|
|
544
727
|
name: t,
|
|
545
728
|
fields: n.fields,
|
|
546
729
|
...n.kind === void 0 ? {} : { kind: n.kind },
|
|
547
730
|
...n.kindOptions === void 0 ? {} : { kindOptions: n.kindOptions }
|
|
548
731
|
}));
|
|
549
732
|
}
|
|
550
|
-
return
|
|
733
|
+
return L({
|
|
551
734
|
...e,
|
|
552
735
|
tableName: e.tableName,
|
|
553
736
|
fields: r,
|
|
@@ -564,10 +747,10 @@ var ge = () => new c({
|
|
|
564
747
|
}),
|
|
565
748
|
index: ((...t) => {
|
|
566
749
|
let n, r, i, a = Array.isArray(t[0]);
|
|
567
|
-
if (a ? (r = t[0], i = t[1], n =
|
|
750
|
+
if (a ? (r = t[0], i = t[1], n = F(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.`);
|
|
568
751
|
let o = r.filter((e) => typeof e == "string");
|
|
569
|
-
if (
|
|
570
|
-
return
|
|
752
|
+
if (A(e.tableName, n, a, o), I(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 L({
|
|
571
754
|
...e,
|
|
572
755
|
tableName: e.tableName,
|
|
573
756
|
fields: e.fields,
|
|
@@ -591,8 +774,8 @@ var ge = () => new c({
|
|
|
591
774
|
expressionIndex: ((t, n, r) => {
|
|
592
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.`);
|
|
593
776
|
let i = n.filter((e) => typeof e == "string");
|
|
594
|
-
if (
|
|
595
|
-
return
|
|
777
|
+
if (A(e.tableName, t, !1, i), I(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 L({
|
|
596
779
|
...e,
|
|
597
780
|
tableName: e.tableName,
|
|
598
781
|
fields: e.fields,
|
|
@@ -615,9 +798,9 @@ var ge = () => new c({
|
|
|
615
798
|
}),
|
|
616
799
|
unique: ((...t) => {
|
|
617
800
|
let n, r, i, a = Array.isArray(t[0]);
|
|
618
|
-
if (a ? (r = t[0], i = t[1], n =
|
|
619
|
-
if (
|
|
620
|
-
return
|
|
801
|
+
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(`unique '${n}' on table '${e.tableName}' has no fields — a UNIQUE constraint must cover at least one column.`);
|
|
802
|
+
if (A(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 L({
|
|
621
804
|
...e,
|
|
622
805
|
tableName: e.tableName,
|
|
623
806
|
fields: e.fields,
|
|
@@ -638,10 +821,10 @@ var ge = () => new c({
|
|
|
638
821
|
}),
|
|
639
822
|
uniqueActive: ((...t) => {
|
|
640
823
|
let n, r, i, a = Array.isArray(t[0]);
|
|
641
|
-
if (a ? (r = t[0], i = t[1], n =
|
|
642
|
-
if (
|
|
824
|
+
if (a ? (r = t[0], i = t[1], n = F(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 (A(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).`);
|
|
643
826
|
let o = i?.where ?? "\"deletedAt\" IS NULL";
|
|
644
|
-
return
|
|
827
|
+
return L({
|
|
645
828
|
...e,
|
|
646
829
|
tableName: e.tableName,
|
|
647
830
|
fields: e.fields,
|
|
@@ -663,8 +846,8 @@ var ge = () => new c({
|
|
|
663
846
|
}),
|
|
664
847
|
check: ((t, n) => {
|
|
665
848
|
if (n.trim().length === 0) throw Error(`CHECK '${t}' on table '${e.tableName}' has an empty expression.`);
|
|
666
|
-
if (
|
|
667
|
-
return
|
|
849
|
+
if (A(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 L({
|
|
668
851
|
...e,
|
|
669
852
|
tableName: e.tableName,
|
|
670
853
|
fields: e.fields,
|
|
@@ -686,7 +869,7 @@ var ge = () => new c({
|
|
|
686
869
|
if (t.trim().length === 0) throw Error(`rule on table '${e.tableName}' has an empty name.`);
|
|
687
870
|
let i = e.appliedRules ?? [];
|
|
688
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.`);
|
|
689
|
-
return
|
|
872
|
+
return L({
|
|
690
873
|
...e,
|
|
691
874
|
appliedRules: [...i, {
|
|
692
875
|
name: t,
|
|
@@ -697,22 +880,22 @@ var ge = () => new c({
|
|
|
697
880
|
}),
|
|
698
881
|
renamedFrom: ((t) => {
|
|
699
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.`);
|
|
700
|
-
return
|
|
883
|
+
return O(t), L({
|
|
701
884
|
...e,
|
|
702
885
|
previousTableName: t
|
|
703
886
|
});
|
|
704
887
|
}),
|
|
705
|
-
primaryKey: ((
|
|
706
|
-
if (
|
|
888
|
+
primaryKey: ((n) => {
|
|
889
|
+
if (n.length === 0) throw Error(`primaryKey([...]) on table '${e.tableName}' needs at least one column.`);
|
|
707
890
|
let r = /* @__PURE__ */ new Set();
|
|
708
|
-
for (let
|
|
709
|
-
if (!(
|
|
710
|
-
if (r.has(
|
|
711
|
-
r.add(
|
|
891
|
+
for (let t of n) {
|
|
892
|
+
if (!(t in e.fields)) throw Error(`primaryKey([...]) on table '${e.tableName}' references unknown column '${t}'.`);
|
|
893
|
+
if (r.has(t)) throw Error(`primaryKey([...]) on table '${e.tableName}' lists column '${t}' twice.`);
|
|
894
|
+
r.add(t);
|
|
712
895
|
}
|
|
713
|
-
if (
|
|
714
|
-
for (let [
|
|
715
|
-
return
|
|
896
|
+
if (t.length > 0) throw Error(`primaryKey([...]) declared twice on table '${e.tableName}'.`);
|
|
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 L({
|
|
716
899
|
...e,
|
|
717
900
|
tableName: e.tableName,
|
|
718
901
|
fields: e.fields,
|
|
@@ -722,12 +905,12 @@ var ge = () => new c({
|
|
|
722
905
|
appliedUniques: e.appliedUniques,
|
|
723
906
|
appliedFullText: e.appliedFullText,
|
|
724
907
|
appliedChecks: e.appliedChecks,
|
|
725
|
-
appliedPrimaryKey: [...
|
|
908
|
+
appliedPrimaryKey: [...n],
|
|
726
909
|
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
727
910
|
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
728
911
|
});
|
|
729
912
|
}),
|
|
730
|
-
nonReactive: (() =>
|
|
913
|
+
nonReactive: (() => L({
|
|
731
914
|
...e,
|
|
732
915
|
tableName: e.tableName,
|
|
733
916
|
fields: e.fields,
|
|
@@ -741,7 +924,7 @@ var ge = () => new c({
|
|
|
741
924
|
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
742
925
|
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
743
926
|
})),
|
|
744
|
-
validate: ((t) =>
|
|
927
|
+
validate: ((t) => L({
|
|
745
928
|
...e,
|
|
746
929
|
tableName: e.tableName,
|
|
747
930
|
fields: e.fields,
|
|
@@ -755,7 +938,7 @@ var ge = () => new c({
|
|
|
755
938
|
insertSchema: t,
|
|
756
939
|
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
757
940
|
})),
|
|
758
|
-
validatePatch: ((
|
|
941
|
+
validatePatch: ((t) => L({
|
|
759
942
|
...e,
|
|
760
943
|
tableName: e.tableName,
|
|
761
944
|
fields: e.fields,
|
|
@@ -767,25 +950,25 @@ var ge = () => new c({
|
|
|
767
950
|
appliedChecks: e.appliedChecks,
|
|
768
951
|
appliedPrimaryKey: e.appliedPrimaryKey,
|
|
769
952
|
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
770
|
-
validatePatchSchema:
|
|
953
|
+
validatePatchSchema: r.partial(t)
|
|
771
954
|
}))
|
|
772
955
|
};
|
|
773
|
-
},
|
|
774
|
-
|
|
956
|
+
}, R = (e, t) => {
|
|
957
|
+
O(e);
|
|
775
958
|
let n = Object.entries(t).flatMap(([e, t]) => {
|
|
776
|
-
let n =
|
|
959
|
+
let n = xe(t);
|
|
777
960
|
return n === void 0 ? [] : [{
|
|
778
961
|
column: e,
|
|
779
962
|
...n
|
|
780
963
|
}];
|
|
781
|
-
}), r =
|
|
782
|
-
for (let t of Object.keys(r))
|
|
964
|
+
}), r = pt(_(t), e);
|
|
965
|
+
for (let t of Object.keys(r)) k(e, t);
|
|
783
966
|
let i;
|
|
784
|
-
for (let [t, n] of Object.entries(r)) n.references ===
|
|
967
|
+
for (let [t, n] of Object.entries(r)) n.references === g && (n.references = () => {
|
|
785
968
|
if (i === void 0) throw Error(`selfReference() on '${e}.${t}' read before table() returned`);
|
|
786
969
|
return i;
|
|
787
970
|
});
|
|
788
|
-
return i =
|
|
971
|
+
return i = L({
|
|
789
972
|
appliedPluginRefs: n,
|
|
790
973
|
tableName: e,
|
|
791
974
|
fields: r,
|
|
@@ -797,7 +980,7 @@ var ge = () => new c({
|
|
|
797
980
|
appliedChecks: [],
|
|
798
981
|
appliedRules: []
|
|
799
982
|
}), i;
|
|
800
|
-
},
|
|
983
|
+
}, mt = (e) => e === "sqlite" || e === "turso", ht = (e) => e === "mysql" || e === "mariadb", z = (e, t) => {
|
|
801
984
|
switch (t) {
|
|
802
985
|
case "mysql":
|
|
803
986
|
case "mariadb": return `\`${e.replace(/`/g, "``")}\``;
|
|
@@ -806,51 +989,51 @@ var ge = () => new c({
|
|
|
806
989
|
case "sqlite":
|
|
807
990
|
case "turso": return `"${e.replace(/"/g, "\"\"")}"`;
|
|
808
991
|
}
|
|
809
|
-
},
|
|
810
|
-
let t =
|
|
992
|
+
}, gt = 1e4, _t = Symbol.for("@voltro/database/tableRegistry"), B = globalThis, V = B[_t] ?? (B[_t] = /* @__PURE__ */ new Map()), vt = (e) => {
|
|
993
|
+
let t = V.get(e.tableName);
|
|
811
994
|
if (t === void 0) {
|
|
812
|
-
|
|
995
|
+
V.set(e.tableName, e);
|
|
813
996
|
return;
|
|
814
997
|
}
|
|
815
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.`);
|
|
816
|
-
},
|
|
817
|
-
|
|
818
|
-
},
|
|
819
|
-
let t =
|
|
999
|
+
}, yt = (e) => {
|
|
1000
|
+
V.get(e.tableName) === void 0 && V.set(e.tableName, e);
|
|
1001
|
+
}, H = (e) => V.get(e), bt = (e) => {
|
|
1002
|
+
let t = V.get(e);
|
|
820
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.`);
|
|
821
1004
|
return t;
|
|
822
|
-
},
|
|
823
|
-
|
|
824
|
-
},
|
|
1005
|
+
}, xt = () => [...V.values()], St = (e) => V.delete(e), Ct = () => {
|
|
1006
|
+
V.clear();
|
|
1007
|
+
}, wt = (e) => V.get(e)?.isReactive !== !1, Tt = (e) => e.order ?? [], Et = (e) => ({
|
|
825
1008
|
op: "count",
|
|
826
1009
|
alias: e ?? "count"
|
|
827
|
-
}),
|
|
1010
|
+
}), Dt = (e, t) => ({
|
|
828
1011
|
op: "count-distinct",
|
|
829
1012
|
column: e,
|
|
830
1013
|
alias: t ?? `count_distinct_${e}`
|
|
831
|
-
}),
|
|
1014
|
+
}), Ot = (e, t) => ({
|
|
832
1015
|
op: "sum",
|
|
833
1016
|
column: e,
|
|
834
1017
|
alias: t ?? `sum_${e}`
|
|
835
|
-
}),
|
|
1018
|
+
}), kt = (e, t) => ({
|
|
836
1019
|
op: "avg",
|
|
837
1020
|
column: e,
|
|
838
1021
|
alias: t ?? `avg_${e}`
|
|
839
|
-
}),
|
|
1022
|
+
}), At = (e, t) => ({
|
|
840
1023
|
op: "min",
|
|
841
1024
|
column: e,
|
|
842
1025
|
alias: t ?? `min_${e}`
|
|
843
|
-
}),
|
|
1026
|
+
}), jt = (e, t) => ({
|
|
844
1027
|
op: "max",
|
|
845
1028
|
column: e,
|
|
846
1029
|
alias: t ?? `max_${e}`
|
|
847
|
-
}),
|
|
1030
|
+
}), Mt = (e, t) => ({
|
|
848
1031
|
op: "column",
|
|
849
1032
|
column: e,
|
|
850
1033
|
alias: t ?? e
|
|
851
|
-
}),
|
|
1034
|
+
}), U = (e) => (...t) => {
|
|
852
1035
|
if (t.length < 2) throw Error(`${e}: requires at least two queries`);
|
|
853
|
-
return
|
|
1036
|
+
return G({
|
|
854
1037
|
table: t[0].descriptor.table,
|
|
855
1038
|
predicate: void 0,
|
|
856
1039
|
order: [],
|
|
@@ -862,55 +1045,55 @@ var ge = () => new c({
|
|
|
862
1045
|
queries: t.map((e) => e.descriptor)
|
|
863
1046
|
}
|
|
864
1047
|
});
|
|
865
|
-
},
|
|
1048
|
+
}, Nt = U("union"), Pt = U("union-all"), Ft = U("intersect"), It = U("except"), W = (e) => ({ over: (t) => ({
|
|
866
1049
|
...e,
|
|
867
1050
|
window: t
|
|
868
|
-
}) }),
|
|
1051
|
+
}) }), Lt = (e = "rowNumber") => W({
|
|
869
1052
|
op: "window-row-number",
|
|
870
1053
|
alias: e
|
|
871
|
-
}),
|
|
1054
|
+
}), Rt = (e = "rank") => W({
|
|
872
1055
|
op: "window-rank",
|
|
873
1056
|
alias: e
|
|
874
|
-
}),
|
|
1057
|
+
}), zt = (e = "denseRank") => W({
|
|
875
1058
|
op: "window-dense-rank",
|
|
876
1059
|
alias: e
|
|
877
|
-
}),
|
|
1060
|
+
}), Bt = (e, t = 1, n) => W({
|
|
878
1061
|
op: "window-lag",
|
|
879
1062
|
column: e,
|
|
880
1063
|
alias: n ?? `lag_${e}`,
|
|
881
1064
|
offset: t
|
|
882
|
-
}),
|
|
1065
|
+
}), Vt = (e, t = 1, n) => W({
|
|
883
1066
|
op: "window-lead",
|
|
884
1067
|
column: e,
|
|
885
1068
|
alias: n ?? `lead_${e}`,
|
|
886
1069
|
offset: t
|
|
887
|
-
}),
|
|
1070
|
+
}), Ht = (e, t) => W({
|
|
888
1071
|
op: "window-sum-over",
|
|
889
1072
|
column: e,
|
|
890
1073
|
alias: t ?? `sum_${e}_over`
|
|
891
|
-
}),
|
|
1074
|
+
}), Ut = (e, t) => W({
|
|
892
1075
|
op: "window-avg-over",
|
|
893
1076
|
column: e,
|
|
894
1077
|
alias: t ?? `avg_${e}_over`
|
|
895
|
-
}),
|
|
896
|
-
let r = n?.find((e) => e.name === t) ??
|
|
1078
|
+
}), Wt = (e, t, n) => {
|
|
1079
|
+
let r = n?.find((e) => e.name === t) ?? H(e)?.appliedFullText?.find((e) => e.name === t);
|
|
897
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.`);
|
|
898
1081
|
return {
|
|
899
1082
|
columns: r.columns,
|
|
900
1083
|
...r.config === void 0 ? {} : { config: r.config },
|
|
901
1084
|
...r.weights === void 0 ? {} : { weights: r.weights }
|
|
902
1085
|
};
|
|
903
|
-
},
|
|
1086
|
+
}, G = (e) => ({
|
|
904
1087
|
descriptor: e,
|
|
905
1088
|
where(t) {
|
|
906
1089
|
let n = e.predicate ? { and: [e.predicate, t] } : t;
|
|
907
|
-
return
|
|
1090
|
+
return G({
|
|
908
1091
|
...e,
|
|
909
1092
|
predicate: n
|
|
910
1093
|
});
|
|
911
1094
|
},
|
|
912
1095
|
orderBy(t, n = "asc") {
|
|
913
|
-
return
|
|
1096
|
+
return G({
|
|
914
1097
|
...e,
|
|
915
1098
|
order: [...e.order, {
|
|
916
1099
|
column: t,
|
|
@@ -919,43 +1102,43 @@ var ge = () => new c({
|
|
|
919
1102
|
});
|
|
920
1103
|
},
|
|
921
1104
|
limit(t) {
|
|
922
|
-
return
|
|
1105
|
+
return G({
|
|
923
1106
|
...e,
|
|
924
1107
|
take: t
|
|
925
1108
|
});
|
|
926
1109
|
},
|
|
927
1110
|
offset(t) {
|
|
928
|
-
return
|
|
1111
|
+
return G({
|
|
929
1112
|
...e,
|
|
930
1113
|
skip: t
|
|
931
1114
|
});
|
|
932
1115
|
},
|
|
933
1116
|
select(...t) {
|
|
934
|
-
return
|
|
1117
|
+
return G({
|
|
935
1118
|
...e,
|
|
936
1119
|
projection: t
|
|
937
1120
|
});
|
|
938
1121
|
},
|
|
939
1122
|
using(t) {
|
|
940
|
-
return
|
|
1123
|
+
return G({
|
|
941
1124
|
...e,
|
|
942
1125
|
usingIndex: t
|
|
943
1126
|
});
|
|
944
1127
|
},
|
|
945
1128
|
withDeleted() {
|
|
946
|
-
return
|
|
1129
|
+
return G({
|
|
947
1130
|
...e,
|
|
948
1131
|
includeDeleted: !0
|
|
949
1132
|
});
|
|
950
1133
|
},
|
|
951
1134
|
forUpdate() {
|
|
952
|
-
return
|
|
1135
|
+
return G({
|
|
953
1136
|
...e,
|
|
954
1137
|
lock: "update"
|
|
955
1138
|
});
|
|
956
1139
|
},
|
|
957
1140
|
unscoped() {
|
|
958
|
-
return
|
|
1141
|
+
return G({
|
|
959
1142
|
...e,
|
|
960
1143
|
crossTenant: !0
|
|
961
1144
|
});
|
|
@@ -965,13 +1148,13 @@ var ge = () => new c({
|
|
|
965
1148
|
...e.eager ?? {},
|
|
966
1149
|
...t
|
|
967
1150
|
};
|
|
968
|
-
return
|
|
1151
|
+
return G({
|
|
969
1152
|
...e,
|
|
970
1153
|
eager: n
|
|
971
1154
|
});
|
|
972
1155
|
},
|
|
973
1156
|
count() {
|
|
974
|
-
return
|
|
1157
|
+
return G({
|
|
975
1158
|
...e,
|
|
976
1159
|
projection: void 0,
|
|
977
1160
|
aggregations: [{
|
|
@@ -985,15 +1168,15 @@ var ge = () => new c({
|
|
|
985
1168
|
...t,
|
|
986
1169
|
alias: e
|
|
987
1170
|
}));
|
|
988
|
-
return
|
|
1171
|
+
return G({
|
|
989
1172
|
...e,
|
|
990
1173
|
projection: void 0,
|
|
991
1174
|
aggregations: n
|
|
992
1175
|
});
|
|
993
1176
|
},
|
|
994
1177
|
matching(t, n) {
|
|
995
|
-
let r =
|
|
996
|
-
return
|
|
1178
|
+
let r = Wt(e.table, t, e.fullTextIndexes);
|
|
1179
|
+
return G({
|
|
997
1180
|
...e,
|
|
998
1181
|
fullTextSearch: {
|
|
999
1182
|
indexName: t,
|
|
@@ -1007,7 +1190,7 @@ var ge = () => new c({
|
|
|
1007
1190
|
rankBy(t) {
|
|
1008
1191
|
let n = e.fullTextSearch;
|
|
1009
1192
|
if (n === void 0) throw Error(".rankBy() requires a preceding .matching(...) clause — there is no full-text search to rank on this query.");
|
|
1010
|
-
return
|
|
1193
|
+
return G({
|
|
1011
1194
|
...e,
|
|
1012
1195
|
fullTextSearch: {
|
|
1013
1196
|
...n,
|
|
@@ -1026,7 +1209,7 @@ var ge = () => new c({
|
|
|
1026
1209
|
distance: r?.distance ?? "cosine",
|
|
1027
1210
|
...e.annClause?.ef === void 0 ? {} : { ef: e.annClause.ef }
|
|
1028
1211
|
};
|
|
1029
|
-
return
|
|
1212
|
+
return G({
|
|
1030
1213
|
...e,
|
|
1031
1214
|
annClause: i
|
|
1032
1215
|
});
|
|
@@ -1038,7 +1221,7 @@ var ge = () => new c({
|
|
|
1038
1221
|
distance: "cosine",
|
|
1039
1222
|
...e.annClause?.ef === void 0 ? {} : { ef: e.annClause.ef }
|
|
1040
1223
|
};
|
|
1041
|
-
return
|
|
1224
|
+
return G({
|
|
1042
1225
|
...e,
|
|
1043
1226
|
annClause: r,
|
|
1044
1227
|
take: n
|
|
@@ -1051,7 +1234,7 @@ var ge = () => new c({
|
|
|
1051
1234
|
column: "",
|
|
1052
1235
|
distance: "cosine"
|
|
1053
1236
|
};
|
|
1054
|
-
return
|
|
1237
|
+
return G({
|
|
1055
1238
|
...e,
|
|
1056
1239
|
annClause: {
|
|
1057
1240
|
...n,
|
|
@@ -1060,22 +1243,22 @@ var ge = () => new c({
|
|
|
1060
1243
|
});
|
|
1061
1244
|
},
|
|
1062
1245
|
use(t) {
|
|
1063
|
-
return
|
|
1246
|
+
return G({ ...t(e) });
|
|
1064
1247
|
},
|
|
1065
1248
|
distinct() {
|
|
1066
|
-
return
|
|
1249
|
+
return G({
|
|
1067
1250
|
...e,
|
|
1068
1251
|
distinct: !0
|
|
1069
1252
|
});
|
|
1070
1253
|
},
|
|
1071
1254
|
distinctOn(t) {
|
|
1072
|
-
return
|
|
1255
|
+
return G({
|
|
1073
1256
|
...e,
|
|
1074
1257
|
distinctOn: [...t]
|
|
1075
1258
|
});
|
|
1076
1259
|
},
|
|
1077
1260
|
as(t) {
|
|
1078
|
-
return
|
|
1261
|
+
return G({
|
|
1079
1262
|
...e,
|
|
1080
1263
|
alias: t
|
|
1081
1264
|
});
|
|
@@ -1087,7 +1270,7 @@ var ge = () => new c({
|
|
|
1087
1270
|
alias: n,
|
|
1088
1271
|
on: r
|
|
1089
1272
|
}];
|
|
1090
|
-
return
|
|
1273
|
+
return G({
|
|
1091
1274
|
...e,
|
|
1092
1275
|
joins: a
|
|
1093
1276
|
});
|
|
@@ -1099,7 +1282,7 @@ var ge = () => new c({
|
|
|
1099
1282
|
alias: n,
|
|
1100
1283
|
on: r
|
|
1101
1284
|
}];
|
|
1102
|
-
return
|
|
1285
|
+
return G({
|
|
1103
1286
|
...e,
|
|
1104
1287
|
joins: a
|
|
1105
1288
|
});
|
|
@@ -1109,7 +1292,7 @@ var ge = () => new c({
|
|
|
1109
1292
|
outputKey: e,
|
|
1110
1293
|
source: t
|
|
1111
1294
|
}));
|
|
1112
|
-
return
|
|
1295
|
+
return G({
|
|
1113
1296
|
...e,
|
|
1114
1297
|
projection: void 0,
|
|
1115
1298
|
joinedProjection: n
|
|
@@ -1118,7 +1301,7 @@ var ge = () => new c({
|
|
|
1118
1301
|
withCte(t, n) {
|
|
1119
1302
|
let r = e.ctes ?? [];
|
|
1120
1303
|
if (r.some((e) => e.name === t)) throw Error(`Query.withCte: duplicate CTE name '${t}'`);
|
|
1121
|
-
return
|
|
1304
|
+
return G({
|
|
1122
1305
|
...e,
|
|
1123
1306
|
ctes: [...r, {
|
|
1124
1307
|
name: t,
|
|
@@ -1129,7 +1312,7 @@ var ge = () => new c({
|
|
|
1129
1312
|
recursiveCte(t, n) {
|
|
1130
1313
|
let r = e.ctes ?? [];
|
|
1131
1314
|
if (r.some((e) => e.name === t)) throw Error(`Query.recursiveCte: duplicate CTE name '${t}'`);
|
|
1132
|
-
return
|
|
1315
|
+
return G({
|
|
1133
1316
|
...e,
|
|
1134
1317
|
ctes: [...r, {
|
|
1135
1318
|
name: t,
|
|
@@ -1140,20 +1323,20 @@ var ge = () => new c({
|
|
|
1140
1323
|
},
|
|
1141
1324
|
groupBy(t) {
|
|
1142
1325
|
let n = e.groupBy ? [...e.groupBy, ...t] : [...t];
|
|
1143
|
-
return
|
|
1326
|
+
return G({
|
|
1144
1327
|
...e,
|
|
1145
1328
|
groupBy: n
|
|
1146
1329
|
});
|
|
1147
1330
|
},
|
|
1148
1331
|
having(t) {
|
|
1149
1332
|
let n = e.having ? { and: [e.having, t] } : t;
|
|
1150
|
-
return
|
|
1333
|
+
return G({
|
|
1151
1334
|
...e,
|
|
1152
1335
|
having: n
|
|
1153
1336
|
});
|
|
1154
1337
|
},
|
|
1155
1338
|
exists() {
|
|
1156
|
-
return
|
|
1339
|
+
return G({
|
|
1157
1340
|
...e,
|
|
1158
1341
|
projection: void 0,
|
|
1159
1342
|
aggregations: [{
|
|
@@ -1164,8 +1347,8 @@ var ge = () => new c({
|
|
|
1164
1347
|
});
|
|
1165
1348
|
}
|
|
1166
1349
|
});
|
|
1167
|
-
function
|
|
1168
|
-
return
|
|
1350
|
+
function K(e) {
|
|
1351
|
+
return G({
|
|
1169
1352
|
table: e.tableName,
|
|
1170
1353
|
predicate: void 0,
|
|
1171
1354
|
order: [],
|
|
@@ -1176,7 +1359,7 @@ function U(e) {
|
|
|
1176
1359
|
sourceTable: e
|
|
1177
1360
|
});
|
|
1178
1361
|
}
|
|
1179
|
-
var
|
|
1362
|
+
var Gt = (e, t, n) => Kt(e, "id", t, n), Kt = (e, t, n, r, i = "asc") => {
|
|
1180
1363
|
let a = [...e.order.filter((e) => e.column !== t), {
|
|
1181
1364
|
column: t,
|
|
1182
1365
|
direction: i
|
|
@@ -1191,21 +1374,21 @@ var Dt = (e, t, n) => W(e, "id", t, n), W = (e, t, n, r, i = "asc") => {
|
|
|
1191
1374
|
order: a,
|
|
1192
1375
|
take: r
|
|
1193
1376
|
};
|
|
1194
|
-
},
|
|
1377
|
+
}, qt = (e) => {
|
|
1195
1378
|
let t = {};
|
|
1196
|
-
for (let [n, r] of Object.entries(e))
|
|
1379
|
+
for (let [n, r] of Object.entries(e)) vt(r), t[n] = K(r);
|
|
1197
1380
|
return t;
|
|
1198
|
-
},
|
|
1199
|
-
if (
|
|
1200
|
-
let r =
|
|
1201
|
-
for (let t of Object.keys(r))
|
|
1381
|
+
}, Jt = (e) => e.isView === !0, Yt = (e, t, n) => {
|
|
1382
|
+
if (O(e), n.trim().length === 0) throw Error(`view('${e}', …): the SELECT body is empty — a view must define a query.`);
|
|
1383
|
+
let r = _(t);
|
|
1384
|
+
for (let t of Object.keys(r)) k(e, t);
|
|
1202
1385
|
return {
|
|
1203
1386
|
tableName: e,
|
|
1204
1387
|
fields: r,
|
|
1205
1388
|
isView: !0,
|
|
1206
1389
|
viewSelect: n
|
|
1207
1390
|
};
|
|
1208
|
-
},
|
|
1391
|
+
}, Xt = (e) => K({
|
|
1209
1392
|
...e,
|
|
1210
1393
|
isReactive: !1,
|
|
1211
1394
|
appliedMixins: [],
|
|
@@ -1213,8 +1396,8 @@ var Dt = (e, t, n) => W(e, "id", t, n), W = (e, t, n, r, i = "asc") => {
|
|
|
1213
1396
|
appliedUniques: [],
|
|
1214
1397
|
appliedFullText: [],
|
|
1215
1398
|
appliedChecks: []
|
|
1216
|
-
}),
|
|
1217
|
-
let r = n === null ?
|
|
1399
|
+
}), Zt = (e, t, n = null) => {
|
|
1400
|
+
let r = n === null ? z(e.tableName, t) : `${z(n, t)}.${z(e.tableName, t)}`, i = e.viewSelect.trim();
|
|
1218
1401
|
switch (t) {
|
|
1219
1402
|
case "postgres":
|
|
1220
1403
|
case "mysql":
|
|
@@ -1223,7 +1406,7 @@ var Dt = (e, t, n) => W(e, "id", t, n), W = (e, t, n, r, i = "asc") => {
|
|
|
1223
1406
|
case "sqlite":
|
|
1224
1407
|
case "turso": return `DROP VIEW IF EXISTS ${r};\nCREATE VIEW ${r} AS ${i};`;
|
|
1225
1408
|
}
|
|
1226
|
-
},
|
|
1409
|
+
}, Qt = (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, q = (e) => {
|
|
1227
1410
|
if (e == null || typeof e != "string") return e;
|
|
1228
1411
|
let t = e.trim();
|
|
1229
1412
|
if (t.length === 0) return e;
|
|
@@ -1234,7 +1417,7 @@ var Dt = (e, t, n) => W(e, "id", t, n), W = (e, t, n, r, i = "asc") => {
|
|
|
1234
1417
|
} catch {
|
|
1235
1418
|
return e;
|
|
1236
1419
|
}
|
|
1237
|
-
},
|
|
1420
|
+
}, $t = (e) => e == null || typeof e == "string" ? e : typeof e == "number" || typeof e == "bigint" ? String(e) : e, en = (e) => {
|
|
1238
1421
|
if (e == null || e instanceof Date) return e;
|
|
1239
1422
|
if (typeof e == "string") {
|
|
1240
1423
|
let t = new Date(e);
|
|
@@ -1245,24 +1428,24 @@ var Dt = (e, t, n) => W(e, "id", t, n), W = (e, t, n, r, i = "asc") => {
|
|
|
1245
1428
|
return isNaN(t.getTime()) ? e : t;
|
|
1246
1429
|
}
|
|
1247
1430
|
return e;
|
|
1248
|
-
},
|
|
1431
|
+
}, tn = (e, t, n) => {
|
|
1249
1432
|
if (e == null) return e;
|
|
1250
1433
|
switch (t) {
|
|
1251
|
-
case "boolean": return n === "postgres" ? e :
|
|
1252
|
-
case "vector": return n === "postgres" ?
|
|
1253
|
-
case "json": return n === "postgres" || n === "mysql" || n === "mariadb" ? e :
|
|
1254
|
-
case "array": return n === "postgres" ? e :
|
|
1434
|
+
case "boolean": return n === "postgres" ? e : Qt(e);
|
|
1435
|
+
case "vector": return n === "postgres" ? q(e) : e;
|
|
1436
|
+
case "json": return n === "postgres" || n === "mysql" || n === "mariadb" ? e : q(e);
|
|
1437
|
+
case "array": return n === "postgres" ? e : q(e);
|
|
1255
1438
|
case "timestamp":
|
|
1256
|
-
case "date": return n === "sqlite" || n === "turso" ?
|
|
1439
|
+
case "date": return n === "sqlite" || n === "turso" ? en(e) : e;
|
|
1257
1440
|
case "decimal":
|
|
1258
|
-
case "bigint": return
|
|
1441
|
+
case "bigint": return $t(e);
|
|
1259
1442
|
default: return e;
|
|
1260
1443
|
}
|
|
1261
|
-
},
|
|
1444
|
+
}, nn = (e, t, n) => {
|
|
1262
1445
|
if (e.length === 0) return e;
|
|
1263
|
-
let r =
|
|
1264
|
-
return r === void 0 ? e :
|
|
1265
|
-
},
|
|
1446
|
+
let r = H(t);
|
|
1447
|
+
return r === void 0 ? e : rn(e, r, n);
|
|
1448
|
+
}, rn = (e, t, n) => {
|
|
1266
1449
|
if (e.length === 0) return e;
|
|
1267
1450
|
let r = t.fields, i = [];
|
|
1268
1451
|
for (let [e, t] of Object.entries(r)) i.push({
|
|
@@ -1271,10 +1454,10 @@ var Dt = (e, t, n) => W(e, "id", t, n), W = (e, t, n, r, i = "asc") => {
|
|
|
1271
1454
|
});
|
|
1272
1455
|
return e.map((e) => {
|
|
1273
1456
|
let t = { ...e };
|
|
1274
|
-
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] = tn(t[e], r, n));
|
|
1275
1458
|
return t;
|
|
1276
1459
|
});
|
|
1277
|
-
},
|
|
1460
|
+
}, an = (e, t) => {
|
|
1278
1461
|
if (e == null) return e;
|
|
1279
1462
|
switch (t) {
|
|
1280
1463
|
case "json": return JSON.stringify(e);
|
|
@@ -1282,25 +1465,25 @@ var Dt = (e, t, n) => W(e, "id", t, n), W = (e, t, n, r, i = "asc") => {
|
|
|
1282
1465
|
case "vector": return typeof e == "string" ? e : JSON.stringify(e);
|
|
1283
1466
|
default: return e;
|
|
1284
1467
|
}
|
|
1285
|
-
},
|
|
1286
|
-
let r =
|
|
1468
|
+
}, on = (e, t, n = ["json", "array"]) => {
|
|
1469
|
+
let r = H(t);
|
|
1287
1470
|
if (r === void 0) return e;
|
|
1288
1471
|
let i = r.fields, a = null;
|
|
1289
1472
|
for (let [t, r] of Object.entries(i)) if (n.includes(r.type) && t in e) {
|
|
1290
|
-
let n =
|
|
1473
|
+
let n = an(e[t], r.type);
|
|
1291
1474
|
n !== e[t] && (a === null && (a = { ...e }), a[t] = n);
|
|
1292
1475
|
}
|
|
1293
1476
|
return a ?? e;
|
|
1294
|
-
},
|
|
1477
|
+
}, sn = /^[A-Za-z_][A-Za-z0-9_]*$/, cn = (e) => "$" + e.map((e) => typeof e == "number" ? `[${e}]` : sn.test(e) ? `.${e}` : `."${e.replace(/"/g, "\\\"")}"`).join(""), ln = (e) => "{" + e.map((e) => {
|
|
1295
1478
|
let t = String(e);
|
|
1296
1479
|
return /^[A-Za-z0-9_]+$/.test(t) ? t : `"${t.replace(/(["\\])/g, "\\$1")}"`;
|
|
1297
|
-
}).join(",") + "}",
|
|
1298
|
-
let i =
|
|
1480
|
+
}).join(",") + "}", un = (e, t, n, r = {}) => {
|
|
1481
|
+
let i = z(e, n), a = r.numeric ?? !1;
|
|
1299
1482
|
if (n === "postgres") {
|
|
1300
|
-
let e = `(${i} #>> '${
|
|
1483
|
+
let e = `(${i} #>> '${ln(t)}'::text[])`;
|
|
1301
1484
|
return a ? `${e}::numeric` : e;
|
|
1302
1485
|
}
|
|
1303
|
-
let o =
|
|
1486
|
+
let o = cn(t);
|
|
1304
1487
|
switch (n) {
|
|
1305
1488
|
case "mysql":
|
|
1306
1489
|
case "mariadb": {
|
|
@@ -1335,73 +1518,73 @@ var Dt = (e, t, n) => W(e, "id", t, n), W = (e, t, n, r, i = "asc") => {
|
|
|
1335
1518
|
a = t === n ? 0 : t > n ? 1 : -1;
|
|
1336
1519
|
}
|
|
1337
1520
|
return a === 0 ? 0 : (a > 0 ? 1 : -1) * (r.negative ? -1 : 1);
|
|
1338
|
-
},
|
|
1521
|
+
}, dn = (e, t) => ({
|
|
1339
1522
|
column: e,
|
|
1340
1523
|
op: "eq",
|
|
1341
1524
|
value: t
|
|
1342
|
-
}),
|
|
1525
|
+
}), fn = (e, t) => ({
|
|
1343
1526
|
column: e,
|
|
1344
1527
|
op: "neq",
|
|
1345
1528
|
value: t
|
|
1346
|
-
}),
|
|
1529
|
+
}), pn = (e, t) => ({
|
|
1347
1530
|
column: e,
|
|
1348
1531
|
op: "gt",
|
|
1349
1532
|
value: t
|
|
1350
|
-
}),
|
|
1533
|
+
}), mn = (e, t) => ({
|
|
1351
1534
|
column: e,
|
|
1352
1535
|
op: "gte",
|
|
1353
1536
|
value: t
|
|
1354
|
-
}),
|
|
1537
|
+
}), hn = (e, t) => ({
|
|
1355
1538
|
column: e,
|
|
1356
1539
|
op: "lt",
|
|
1357
1540
|
value: t
|
|
1358
|
-
}),
|
|
1541
|
+
}), gn = (e, t) => ({
|
|
1359
1542
|
column: e,
|
|
1360
1543
|
op: "lte",
|
|
1361
1544
|
value: t
|
|
1362
|
-
}),
|
|
1545
|
+
}), _n = (e, t) => ({
|
|
1363
1546
|
column: e,
|
|
1364
1547
|
op: "in",
|
|
1365
1548
|
value: t
|
|
1366
|
-
}),
|
|
1549
|
+
}), vn = (e, t) => ({
|
|
1367
1550
|
column: e,
|
|
1368
1551
|
op: "notIn",
|
|
1369
1552
|
value: t
|
|
1370
|
-
}),
|
|
1553
|
+
}), yn = (e, t) => ({
|
|
1371
1554
|
column: e,
|
|
1372
1555
|
op: "contains",
|
|
1373
1556
|
value: t
|
|
1374
|
-
}),
|
|
1557
|
+
}), bn = (e, t) => ({
|
|
1375
1558
|
column: e,
|
|
1376
1559
|
op: "startsWith",
|
|
1377
1560
|
value: t
|
|
1378
|
-
}),
|
|
1561
|
+
}), xn = (e, t) => ({
|
|
1379
1562
|
column: e,
|
|
1380
1563
|
op: "arrayContains",
|
|
1381
1564
|
value: t
|
|
1382
|
-
}),
|
|
1565
|
+
}), Sn = (e, t) => ({
|
|
1383
1566
|
column: e,
|
|
1384
1567
|
op: "arrayOverlaps",
|
|
1385
1568
|
value: t
|
|
1386
|
-
}),
|
|
1569
|
+
}), Cn = (e, t) => ({
|
|
1387
1570
|
column: e,
|
|
1388
1571
|
op: "arrayHas",
|
|
1389
1572
|
value: t
|
|
1390
|
-
}),
|
|
1573
|
+
}), wn = {
|
|
1391
1574
|
column: "id",
|
|
1392
1575
|
op: "in",
|
|
1393
1576
|
value: []
|
|
1394
|
-
},
|
|
1577
|
+
}, Tn = (e) => ({
|
|
1395
1578
|
column: e,
|
|
1396
1579
|
op: "isNull"
|
|
1397
|
-
}),
|
|
1580
|
+
}), En = (e) => ({
|
|
1398
1581
|
column: e,
|
|
1399
1582
|
op: "isNotNull"
|
|
1400
|
-
}),
|
|
1583
|
+
}), Dn = (e, t) => ({
|
|
1401
1584
|
column: e,
|
|
1402
1585
|
op: "spatial",
|
|
1403
1586
|
value: t
|
|
1404
|
-
}),
|
|
1587
|
+
}), On = (...e) => ({ and: e }), kn = (...e) => ({ or: e }), An = (e) => ({ not: e }), jn = (e, ...t) => {
|
|
1405
1588
|
if (t.length === 0) throw Error(`jsonField("${e}"): at least one path segment is required`);
|
|
1406
1589
|
let n = (n, r) => ({
|
|
1407
1590
|
column: e,
|
|
@@ -1423,37 +1606,37 @@ var Dt = (e, t, n) => W(e, "id", t, n), W = (e, t, n, r, i = "asc") => {
|
|
|
1423
1606
|
isNull: () => n("isNull"),
|
|
1424
1607
|
isNotNull: () => n("isNotNull")
|
|
1425
1608
|
};
|
|
1426
|
-
}, Y = (e) => "descriptor" in e ? e.descriptor : e,
|
|
1609
|
+
}, Y = (e) => "descriptor" in e ? e.descriptor : e, Mn = (e, t) => ({
|
|
1427
1610
|
column: e,
|
|
1428
1611
|
op: "subquery-in",
|
|
1429
1612
|
subquery: Y(t)
|
|
1430
|
-
}),
|
|
1613
|
+
}), Nn = (e, t) => ({
|
|
1431
1614
|
column: e,
|
|
1432
1615
|
op: "subquery-not-in",
|
|
1433
1616
|
subquery: Y(t)
|
|
1434
|
-
}),
|
|
1617
|
+
}), Pn = (e) => ({
|
|
1435
1618
|
op: "exists",
|
|
1436
1619
|
subquery: Y(e)
|
|
1437
|
-
}),
|
|
1620
|
+
}), Fn = (e) => ({
|
|
1438
1621
|
op: "not-exists",
|
|
1439
1622
|
subquery: Y(e)
|
|
1440
|
-
}),
|
|
1623
|
+
}), In = /^\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?)?$/, Ln = (e) => {
|
|
1441
1624
|
if (e instanceof Date) return e.getTime();
|
|
1442
|
-
if (typeof e == "string" &&
|
|
1625
|
+
if (typeof e == "string" && In.test(e)) {
|
|
1443
1626
|
let t = Date.parse(e);
|
|
1444
1627
|
return Number.isNaN(t) ? void 0 : t;
|
|
1445
1628
|
}
|
|
1446
|
-
},
|
|
1629
|
+
}, Rn = (e, t) => {
|
|
1447
1630
|
if (!(e instanceof Date) && !(t instanceof Date)) return;
|
|
1448
|
-
let n =
|
|
1631
|
+
let n = Ln(e), r = Ln(t);
|
|
1449
1632
|
return n === void 0 || r === void 0 ? void 0 : [n, r];
|
|
1450
|
-
},
|
|
1633
|
+
}, zn = (e, t) => {
|
|
1451
1634
|
if (e === t) return !0;
|
|
1452
|
-
let n =
|
|
1635
|
+
let n = Rn(e, t);
|
|
1453
1636
|
return n !== void 0 && n[0] === n[1];
|
|
1454
|
-
},
|
|
1637
|
+
}, Bn = (e, t) => {
|
|
1455
1638
|
if (e == null || t == null) return null;
|
|
1456
|
-
let n =
|
|
1639
|
+
let n = Rn(e, t);
|
|
1457
1640
|
if (n !== void 0) return n[0] === n[1] ? 0 : n[0] > n[1] ? 1 : -1;
|
|
1458
1641
|
let r = e instanceof Date ? e.getTime() : e, i = t instanceof Date ? t.getTime() : t;
|
|
1459
1642
|
return typeof r == typeof i ? r === i ? 0 : r > i ? 1 : -1 : null;
|
|
@@ -1480,7 +1663,7 @@ var Dt = (e, t, n) => W(e, "id", t, n), W = (e, t, n, r, i = "asc") => {
|
|
|
1480
1663
|
let t = n.get(e.subquery), r = typeof t == "number" ? t > 0 : t instanceof Set && t.size > 0;
|
|
1481
1664
|
return e.op === "exists" ? r : !r;
|
|
1482
1665
|
}
|
|
1483
|
-
let i = e, a = t[i.column], o = r[i.column]?.type === "decimal", s = (e, t) => o && e != null && t != null ? J(e, t) === 0 :
|
|
1666
|
+
let i = e, a = t[i.column], o = r[i.column]?.type === "decimal", s = (e, t) => o && e != null && t != null ? J(e, t) === 0 : zn(e, t), c = o ? J : Bn;
|
|
1484
1667
|
switch (i.op) {
|
|
1485
1668
|
case "eq": return s(a, i.value);
|
|
1486
1669
|
case "neq": return !s(a, i.value);
|
|
@@ -1542,13 +1725,13 @@ var Dt = (e, t, n) => W(e, "id", t, n), W = (e, t, n, r, i = "asc") => {
|
|
|
1542
1725
|
...e,
|
|
1543
1726
|
conjunctive: t
|
|
1544
1727
|
});
|
|
1545
|
-
},
|
|
1728
|
+
}, Vn = (e, t) => ({
|
|
1546
1729
|
name: e,
|
|
1547
1730
|
body: t
|
|
1548
|
-
}),
|
|
1731
|
+
}), Hn = (e) => {
|
|
1549
1732
|
if (e.lifecycle === "cron" && !e.cron) throw Error(`seed "${e.id}": lifecycle 'cron' requires a 'cron' field`);
|
|
1550
1733
|
if (e.lifecycle === "onSchemaChange" && (!e.watchedTables || e.watchedTables.length === 0)) throw Error(`seed "${e.id}": lifecycle 'onSchemaChange' requires at least one entry in 'watchedTables'`);
|
|
1551
|
-
let t = e.steps({ step:
|
|
1734
|
+
let t = e.steps({ step: Vn });
|
|
1552
1735
|
if (t.length === 0) throw Error(`seed "${e.id}": at least one step is required`);
|
|
1553
1736
|
return {
|
|
1554
1737
|
__seed: !0,
|
|
@@ -1561,68 +1744,68 @@ var Dt = (e, t, n) => W(e, "id", t, n), W = (e, t, n, r, i = "asc") => {
|
|
|
1561
1744
|
...e.fingerprint === void 0 ? {} : { fingerprint: e.fingerprint },
|
|
1562
1745
|
steps: t
|
|
1563
1746
|
};
|
|
1564
|
-
},
|
|
1565
|
-
|
|
1566
|
-
},
|
|
1567
|
-
|
|
1568
|
-
},
|
|
1569
|
-
let t =
|
|
1747
|
+
}, Un = (e) => typeof e == "object" && !!e && "__seed" in e && e.__seed === !0, Wn = null, Gn = null, Kn = (e) => {
|
|
1748
|
+
Wn = e;
|
|
1749
|
+
}, qn = (e) => {
|
|
1750
|
+
Gn = e;
|
|
1751
|
+
}, Jn = async (e) => {
|
|
1752
|
+
let t = Wn;
|
|
1570
1753
|
t !== null && await t(e);
|
|
1571
|
-
},
|
|
1572
|
-
let t =
|
|
1754
|
+
}, Yn = async (e) => {
|
|
1755
|
+
let t = Gn;
|
|
1573
1756
|
t !== null && e.changedTables.length !== 0 && await t(e);
|
|
1574
|
-
},
|
|
1757
|
+
}, Xn = (e) => {
|
|
1575
1758
|
if (!e.id || e.id.length === 0) throw Error("migration: `id` is required + must be non-empty");
|
|
1576
1759
|
if (!e.up || !e.down) throw Error(`migration ${e.id}: both \`up\` and \`down\` must be functions`);
|
|
1577
1760
|
return e;
|
|
1578
|
-
},
|
|
1761
|
+
}, Zn = Symbol.for("voltro.migration.irreversible"), $ = class extends Error {
|
|
1579
1762
|
migrationId;
|
|
1580
1763
|
reason;
|
|
1581
1764
|
_tag = "IrreversibleMigrationError";
|
|
1582
1765
|
constructor(e, t) {
|
|
1583
1766
|
super(`migration ${e} cannot be rolled back: ${t}`), this.migrationId = e, this.reason = t, this.name = "IrreversibleMigrationError";
|
|
1584
1767
|
}
|
|
1585
|
-
},
|
|
1586
|
-
if (!
|
|
1587
|
-
return Object.assign(() =>
|
|
1588
|
-
},
|
|
1589
|
-
let t = e[
|
|
1768
|
+
}, Qn = (e) => {
|
|
1769
|
+
if (!e || e.trim().length === 0) throw Error("irreversible(): a reason is required");
|
|
1770
|
+
return Object.assign(() => t.fail(new $("<unknown>", e)), { [Zn]: e });
|
|
1771
|
+
}, $n = (e) => {
|
|
1772
|
+
let t = e[Zn];
|
|
1590
1773
|
return typeof t == "string" ? t : void 0;
|
|
1591
|
-
},
|
|
1774
|
+
}, er = class {
|
|
1592
1775
|
reason;
|
|
1593
1776
|
_tag = "MigrationSkipped";
|
|
1594
1777
|
constructor(e) {
|
|
1595
1778
|
this.reason = e;
|
|
1596
1779
|
}
|
|
1597
|
-
},
|
|
1780
|
+
}, tr = class extends Error {
|
|
1598
1781
|
migrationId;
|
|
1599
1782
|
failed;
|
|
1600
1783
|
_tag = "MigrationExpectationFailed";
|
|
1601
1784
|
constructor(e, t) {
|
|
1602
1785
|
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";
|
|
1603
1786
|
}
|
|
1604
|
-
},
|
|
1787
|
+
}, nr = class extends Error {
|
|
1605
1788
|
migrationId;
|
|
1606
1789
|
dialect;
|
|
1607
1790
|
_tag = "TransactionBrokenByBodyError";
|
|
1608
1791
|
constructor(e, t) {
|
|
1609
1792
|
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";
|
|
1610
1793
|
}
|
|
1611
|
-
},
|
|
1794
|
+
}, rr = class extends Error {
|
|
1612
1795
|
table;
|
|
1613
1796
|
report;
|
|
1614
1797
|
_tag = "RewriteUnstableError";
|
|
1615
1798
|
constructor(e, t) {
|
|
1616
1799
|
super(`rewrite of ${e} did not stabilise after ${t.passes} pass(es): ${t.rewritten} rewritten, ${t.contended} contended on the last pass. Something is still writing these rows — raise maxPasses, or stop the writer first.`), this.table = e, this.report = t, this.name = "RewriteUnstableError";
|
|
1617
1800
|
}
|
|
1618
|
-
},
|
|
1801
|
+
}, ir = /^\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", or = /* @__PURE__ */ new Set(["voltro_isr_cache"]), sr = (e) => or.has(e) || e.startsWith("_voltro_") || e.startsWith("_cloud_") || e.startsWith("cluster_") || e.startsWith("__turso_internal_"), cr = "_voltro_staging_", lr = (e) => e.startsWith(cr), ur = /__dropped_\d{14}$/, dr = (e) => ur.test(e), fr = 7, pr = (e) => {
|
|
1619
1802
|
let t = /__dropped_(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/.exec(e);
|
|
1620
1803
|
if (t === null) return;
|
|
1621
1804
|
let [, n, r, i, a, o, s] = t;
|
|
1622
1805
|
return new Date(Date.UTC(Number(n), Number(r) - 1, Number(i), Number(a), Number(o), Number(s)));
|
|
1623
|
-
},
|
|
1806
|
+
}, mr = (e, t = {}) => {
|
|
1624
1807
|
let n = t.now ?? /* @__PURE__ */ new Date(), r = t.retentionDays ?? 7, i = [], a = (e, t) => {
|
|
1625
|
-
let a =
|
|
1808
|
+
let a = pr(e);
|
|
1626
1809
|
if (a === void 0) return;
|
|
1627
1810
|
let o = Math.floor((n.getTime() - a.getTime()) / 864e5);
|
|
1628
1811
|
o >= r && i.push({
|
|
@@ -1631,11 +1814,123 @@ var Dt = (e, t, n) => W(e, "id", t, n), W = (e, t, n, r, i = "asc") => {
|
|
|
1631
1814
|
ageDays: o
|
|
1632
1815
|
});
|
|
1633
1816
|
};
|
|
1634
|
-
for (let t of e.tables) if (a(t.name, t.name), !
|
|
1817
|
+
for (let t of e.tables) if (a(t.name, t.name), !dr(t.name)) for (let e of t.columns ?? []) a(e.name, `${t.name}.${e.name}`);
|
|
1635
1818
|
return i;
|
|
1636
|
-
},
|
|
1819
|
+
}, hr = (e, t) => {
|
|
1637
1820
|
let n = e.reduce((e, t) => e.ageDays >= t.ageDays ? e : t), r = (/* @__PURE__ */ new Date(Date.now() - t * 864e5)).toISOString().slice(0, 10);
|
|
1638
1821
|
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.`;
|
|
1639
|
-
}
|
|
1822
|
+
}, gr = R("_voltro_migrations", {
|
|
1823
|
+
id: d({ prefix: "mig" }),
|
|
1824
|
+
name: f(),
|
|
1825
|
+
hash: f(),
|
|
1826
|
+
status: f(),
|
|
1827
|
+
appliedAt: m().nullable(),
|
|
1828
|
+
durationMs: p().nullable(),
|
|
1829
|
+
errorMessage: f().nullable(),
|
|
1830
|
+
errorStack: f().nullable(),
|
|
1831
|
+
workflowRunId: f().nullable(),
|
|
1832
|
+
createdAt: m().default("now"),
|
|
1833
|
+
updatedAt: m().default("now").onUpdate("now")
|
|
1834
|
+
}).index(["status"]), _r = R("_voltro_seeds", {
|
|
1835
|
+
id: d({ prefix: "seed" }),
|
|
1836
|
+
name: f(),
|
|
1837
|
+
lifecycle: f(),
|
|
1838
|
+
fingerprint: f(),
|
|
1839
|
+
cronSchedule: f().nullable(),
|
|
1840
|
+
watchedTables: h().nullable(),
|
|
1841
|
+
nextRunAt: m().nullable(),
|
|
1842
|
+
lastRunStatus: f().nullable(),
|
|
1843
|
+
lastRunAt: m().nullable(),
|
|
1844
|
+
lastRunDurationMs: p().nullable(),
|
|
1845
|
+
lastRunRowsTouched: p().nullable(),
|
|
1846
|
+
lastError: f().nullable(),
|
|
1847
|
+
workflowRunId: f().nullable(),
|
|
1848
|
+
createdAt: m().default("now"),
|
|
1849
|
+
updatedAt: m().default("now").onUpdate("now")
|
|
1850
|
+
}).index(["lifecycle"]).index(["nextRunAt"]), vr = R("_voltro_migration_plans", {
|
|
1851
|
+
id: d({ prefix: "plan" }),
|
|
1852
|
+
fingerprint: f(),
|
|
1853
|
+
liveFingerprint: f().nullable(),
|
|
1854
|
+
operations: h(),
|
|
1855
|
+
rollbackPlan: h().nullable(),
|
|
1856
|
+
appliedBy: f(),
|
|
1857
|
+
environment: f(),
|
|
1858
|
+
source: f(),
|
|
1859
|
+
onlineStrategy: f().nullable(),
|
|
1860
|
+
durationMs: p(),
|
|
1861
|
+
notes: f().nullable(),
|
|
1862
|
+
squashedAt: m().nullable(),
|
|
1863
|
+
appliedAt: m().default("now"),
|
|
1864
|
+
createdAt: m().default("now"),
|
|
1865
|
+
updatedAt: m().default("now").onUpdate("now")
|
|
1866
|
+
}).index(["fingerprint"]).index(["environment"]), yr = R("_voltro_idempotency", {
|
|
1867
|
+
id: d({ prefix: "idem" }),
|
|
1868
|
+
scope: f(),
|
|
1869
|
+
key: f(),
|
|
1870
|
+
status: f(),
|
|
1871
|
+
response: h().nullable(),
|
|
1872
|
+
createdAt: m().default("now")
|
|
1873
|
+
}).unique(["scope", "key"]).index(["createdAt"]), br = R("_voltro_devices", {
|
|
1874
|
+
id: d({ prefix: "device" }),
|
|
1875
|
+
tenantId: f(),
|
|
1876
|
+
name: f(),
|
|
1877
|
+
scopes: h().nullable(),
|
|
1878
|
+
pairingHash: f().maxLength(64).nullable(),
|
|
1879
|
+
pairingExpiresAt: m().nullable(),
|
|
1880
|
+
accessHash: f().maxLength(64).nullable(),
|
|
1881
|
+
accessExpiresAt: m().nullable(),
|
|
1882
|
+
refreshHash: f().maxLength(64).nullable(),
|
|
1883
|
+
refreshExpiresAt: m().nullable(),
|
|
1884
|
+
previousRefreshHash: f().maxLength(64).nullable(),
|
|
1885
|
+
generation: p().default(0),
|
|
1886
|
+
pairedAt: m().nullable(),
|
|
1887
|
+
lastSeenAt: m().nullable(),
|
|
1888
|
+
revokedAt: m().nullable(),
|
|
1889
|
+
revokedReason: f().nullable(),
|
|
1890
|
+
createdBy: f().nullable(),
|
|
1891
|
+
metadata: h().nullable(),
|
|
1892
|
+
createdAt: m()
|
|
1893
|
+
}).index(["tenantId"]).index(["pairingHash"]).index(["accessHash"]).index(["refreshHash"]).index(["previousRefreshHash"]), xr = R("_voltro_tenant_selections", {
|
|
1894
|
+
id: d({ prefix: "tsel" }),
|
|
1895
|
+
subjectType: f().maxLength(32),
|
|
1896
|
+
subjectId: f(),
|
|
1897
|
+
tenantId: f(),
|
|
1898
|
+
selectedAt: m()
|
|
1899
|
+
}).primaryKey(["id"]).nonReactive(), Sr = R("_voltro_kv", {
|
|
1900
|
+
id: d({ prefix: "kv" }),
|
|
1901
|
+
key: f().unique(),
|
|
1902
|
+
value: f().nullable(),
|
|
1903
|
+
expiresAt: m().nullable(),
|
|
1904
|
+
createdAt: m().default("now"),
|
|
1905
|
+
updatedAt: m().default("now").onUpdate("now")
|
|
1906
|
+
}).index(["expiresAt"]), Cr = R("_voltro_api_keys", {
|
|
1907
|
+
id: d({ prefix: "apikey" }),
|
|
1908
|
+
tenantId: f().nullable(),
|
|
1909
|
+
name: f(),
|
|
1910
|
+
hashedKey: f().maxLength(64).unique(),
|
|
1911
|
+
keyPrefix: f(),
|
|
1912
|
+
scopes: h().nullable(),
|
|
1913
|
+
lastUsedAt: m().nullable(),
|
|
1914
|
+
requestCount: p().default(0),
|
|
1915
|
+
expiresAt: m().nullable(),
|
|
1916
|
+
revokedAt: m().nullable(),
|
|
1917
|
+
createdBy: f().nullable(),
|
|
1918
|
+
onBehalfOf: f().nullable(),
|
|
1919
|
+
metadata: h().nullable(),
|
|
1920
|
+
createdAt: m().default("now")
|
|
1921
|
+
}).index("byApiKeyTenant", ["tenantId"]), wr = R("_voltro_replica_observations", {
|
|
1922
|
+
id: d({ prefix: "robs" }),
|
|
1923
|
+
replicaId: f().maxLength(191),
|
|
1924
|
+
startedAt: m(),
|
|
1925
|
+
version: f().maxLength(64).nullable(),
|
|
1926
|
+
kind: f().maxLength(64),
|
|
1927
|
+
payload: f().nullable(),
|
|
1928
|
+
reachableAt: f().maxLength(255).nullable(),
|
|
1929
|
+
writtenAt: m().default("now").onUpdate("now")
|
|
1930
|
+
}).unique(["replicaId", "kind"]).index(["kind"]), Tr = [
|
|
1931
|
+
gr,
|
|
1932
|
+
_r,
|
|
1933
|
+
vr
|
|
1934
|
+
];
|
|
1640
1935
|
//#endregion
|
|
1641
|
-
export {
|
|
1936
|
+
export { hn as $, ge as $n, ht as $t, Hn as A, Ee as An, Vt as At, Sn as B, ce as Bn, Ot as Bt, er as C, Le as Cn, Et as Ct, $n as D, Ie as Dn, It as Dt, Qn as E, Fe as En, zt as Et, Kn as F, l as Fn, Gt as Ft, Pn as G, se as Gn, Ct as Gt, yn as H, ee as Hn, Nt as Ht, wn as I, g as In, K as It, _n as J, pe as Jn, wt as Jt, pn as K, ae as Kn, yt as Kt, On as L, he as Ln, Rt as Lt, Jn as M, we as Mn, At as Mt, Un as N, Se as Nn, Tt as Nt, ar as O, Ae as On, Ft as Ot, qn as P, xe as Pn, Kt as Pt, jn as Q, p as Qn, gt as Qt, xn as R, ie as Rn, Wt as Rt, tr as S, w as Sn, Mt as St, nr as T, b as Tn, qt as Tt, dn as U, s as Un, Pt as Ut, Z as V, ue as Vn, Ht as Vt, X as W, le as Wn, xt as Wt, En as X, ve as Xn, bt as Xt, Mn as Y, _e as Yn, vt as Yt, Tn as Z, d as Zn, St as Zt, dr as _, k as _n, Xt as _t, vr as a, lt as an, te as ar, Nn as at, ir as b, j as bn, kt as bt, _r as c, st as cn, o as cr, bn as ct, fr as d, rt as dn, me as dr, un as dt, mt as en, h as er, gn as et, or as f, nt as fn, tn as ft, sr as g, He as gn, Jt as gt, hr as h, Ve as hn, on as ht, Sr as i, R as in, c as ir, vn as it, Yn as j, Ce as jn, jt, Xn as k, Te as kn, Bt as kt, xr as l, P as ln, f as lr, Q as lt, mr as m, Be as mn, nn as mt, br as n, ut as nn, re as nr, An as nt, gr as o, ot as on, fe as or, kn as ot, cr as p, et as pn, rn as pt, mn as q, ne as qn, H as qt, yr as r, ct as rn, ye as rr, Fn as rt, wr as s, at as sn, de as sr, Dn as st, Cr as t, z as tn, _ as tr, fn as tt, Tr as u, it as un, m as ur, J as ut, lr as v, A as vn, Yt as vt, rr as w, Re as wn, Dt as wt, $ as x, y as xn, Ut as xt, pr as y, O as yn, Zt as yt, Cn as z, oe as zn, Lt as zt };
|