@voltro/database 0.52.0 → 0.53.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 +229 -0
- package/dist/{frameworkLiveTables-DNu6F6P8.js → frameworkLiveTables-ChVR-C5F.js} +139 -128
- package/dist/index.d.ts +58 -5
- package/dist/index.js +786 -779
- package/dist/sql.js +136 -136
- package/package.json +2 -2
|
@@ -7,6 +7,10 @@ var r = (e) => {
|
|
|
7
7
|
for (let [n, r] of Object.entries(e.fields)) r.serverOnly === !0 && t.push(n);
|
|
8
8
|
return t;
|
|
9
9
|
}, i = (e) => {
|
|
10
|
+
let t = [];
|
|
11
|
+
for (let [n, r] of Object.entries(e.fields)) r.crdtManaged === !0 && t.push(n);
|
|
12
|
+
return t;
|
|
13
|
+
}, a = (e) => {
|
|
10
14
|
let t = [];
|
|
11
15
|
for (let [n, r] of Object.entries(e.fields)) {
|
|
12
16
|
let e = r.readableBy;
|
|
@@ -16,11 +20,11 @@ var r = (e) => {
|
|
|
16
20
|
});
|
|
17
21
|
}
|
|
18
22
|
return t;
|
|
19
|
-
},
|
|
23
|
+
}, o = (e) => {
|
|
20
24
|
let t = [];
|
|
21
25
|
for (let [n, r] of Object.entries(e.fields)) r.crdtManaged === !0 && t.push(n);
|
|
22
26
|
return t;
|
|
23
|
-
},
|
|
27
|
+
}, s = class e {
|
|
24
28
|
definition;
|
|
25
29
|
constructor(e) {
|
|
26
30
|
this.definition = e;
|
|
@@ -41,7 +45,8 @@ var r = (e) => {
|
|
|
41
45
|
});
|
|
42
46
|
}
|
|
43
47
|
serverOnly() {
|
|
44
|
-
|
|
48
|
+
if (this.rejectIfRaw("serverOnly"), this.definition.crdtManaged === !0) throw Error("serverOnly() on a CRDT column (crdtText()/crdtDoc()) is a contradiction: clients write CRDT updates and must read the merged state back. Remove serverOnly(), or use a plain bytes() column if only the server touches it.");
|
|
49
|
+
return new e({
|
|
45
50
|
...this.definition,
|
|
46
51
|
serverOnly: !0
|
|
47
52
|
});
|
|
@@ -173,21 +178,21 @@ var r = (e) => {
|
|
|
173
178
|
__definition() {
|
|
174
179
|
return this.definition;
|
|
175
180
|
}
|
|
176
|
-
},
|
|
181
|
+
}, c = (e) => new s({
|
|
177
182
|
type: e,
|
|
178
183
|
nullable: !1,
|
|
179
184
|
unique: !1,
|
|
180
185
|
hasDefault: !1
|
|
181
|
-
}), ee = (e) => new
|
|
186
|
+
}), ee = (e) => new s({
|
|
182
187
|
type: "id",
|
|
183
188
|
nullable: !1,
|
|
184
189
|
unique: !0,
|
|
185
190
|
hasDefault: !1,
|
|
186
191
|
idSchemeInput: e
|
|
187
|
-
}),
|
|
192
|
+
}), l = () => c("text"), te = () => c("integer"), ne = () => c("real"), u = (e, t = 0) => {
|
|
188
193
|
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)).`);
|
|
189
194
|
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}).`);
|
|
190
|
-
return new
|
|
195
|
+
return new s({
|
|
191
196
|
type: "decimal",
|
|
192
197
|
nullable: !1,
|
|
193
198
|
unique: !1,
|
|
@@ -195,12 +200,12 @@ var r = (e) => {
|
|
|
195
200
|
precision: e,
|
|
196
201
|
scale: t
|
|
197
202
|
});
|
|
198
|
-
}, re =
|
|
203
|
+
}, re = u, ie = () => c("bigint"), ae = (e, t) => {
|
|
199
204
|
if (t.length === 0) throw Error(`dbEnum('${e}', []): enum must have at least one value`);
|
|
200
205
|
return {
|
|
201
206
|
name: e,
|
|
202
207
|
values: t,
|
|
203
|
-
column: () => new
|
|
208
|
+
column: () => new s({
|
|
204
209
|
type: "enum",
|
|
205
210
|
nullable: !1,
|
|
206
211
|
unique: !1,
|
|
@@ -209,13 +214,19 @@ var r = (e) => {
|
|
|
209
214
|
enumValues: t
|
|
210
215
|
})
|
|
211
216
|
};
|
|
212
|
-
}, oe = () =>
|
|
217
|
+
}, oe = () => c("boolean"), se = () => c("timestamp"), ce = () => c("date"), le = () => c("json"), ue = () => c("bytes"), d = () => new s({
|
|
213
218
|
type: "bytes",
|
|
214
219
|
nullable: !0,
|
|
215
220
|
unique: !1,
|
|
216
221
|
hasDefault: !1,
|
|
217
222
|
crdtManaged: !0
|
|
218
|
-
}),
|
|
223
|
+
}), de = () => new s({
|
|
224
|
+
type: "bytes",
|
|
225
|
+
nullable: !0,
|
|
226
|
+
unique: !1,
|
|
227
|
+
hasDefault: !1,
|
|
228
|
+
crdtManaged: !0
|
|
229
|
+
}), fe = (e, t) => new s({
|
|
219
230
|
type: "reference",
|
|
220
231
|
nullable: !1,
|
|
221
232
|
unique: !1,
|
|
@@ -225,15 +236,15 @@ var r = (e) => {
|
|
|
225
236
|
refOnUpdate: t?.onUpdate ?? "noAction",
|
|
226
237
|
fkAutoIndex: t?.index ?? !0,
|
|
227
238
|
...t?.orphanPolicy ? { orphanPolicy: t.orphanPolicy } : {}
|
|
228
|
-
}),
|
|
239
|
+
}), pe = () => new s({
|
|
229
240
|
type: "text",
|
|
230
241
|
nullable: !0,
|
|
231
242
|
unique: !1,
|
|
232
243
|
hasDefault: !1,
|
|
233
244
|
dropped: !0
|
|
234
|
-
}),
|
|
245
|
+
}), me = (e, t) => {
|
|
235
246
|
if (!Number.isInteger(e) || e <= 0) throw Error(`vector(${String(e)}): dimension must be a positive integer (the embedding length, e.g. vector(1536)).`);
|
|
236
|
-
return new
|
|
247
|
+
return new s({
|
|
237
248
|
type: "vector",
|
|
238
249
|
nullable: !1,
|
|
239
250
|
unique: !1,
|
|
@@ -241,13 +252,13 @@ var r = (e) => {
|
|
|
241
252
|
vectorDim: e,
|
|
242
253
|
vectorPrecision: t?.precision ?? "float32"
|
|
243
254
|
});
|
|
244
|
-
},
|
|
255
|
+
}, he = (e) => new s({
|
|
245
256
|
type: "array",
|
|
246
257
|
nullable: !1,
|
|
247
258
|
unique: !1,
|
|
248
259
|
hasDefault: !1,
|
|
249
260
|
arrayElement: e.__definition().type
|
|
250
|
-
}),
|
|
261
|
+
}), ge = () => c("interval"), _e = (e, t = 4326) => new s({
|
|
251
262
|
type: "text",
|
|
252
263
|
nullable: !1,
|
|
253
264
|
unique: !1,
|
|
@@ -257,7 +268,7 @@ var r = (e) => {
|
|
|
257
268
|
geomKind: e,
|
|
258
269
|
srid: t
|
|
259
270
|
}
|
|
260
|
-
}),
|
|
271
|
+
}), ve = (e, t = 4326) => new s({
|
|
261
272
|
type: "text",
|
|
262
273
|
nullable: !1,
|
|
263
274
|
unique: !1,
|
|
@@ -267,7 +278,7 @@ var r = (e) => {
|
|
|
267
278
|
geomKind: e,
|
|
268
279
|
srid: t
|
|
269
280
|
}
|
|
270
|
-
}),
|
|
281
|
+
}), ye = (e) => new s({
|
|
271
282
|
type: "raw",
|
|
272
283
|
nullable: !1,
|
|
273
284
|
unique: !1,
|
|
@@ -277,14 +288,14 @@ var r = (e) => {
|
|
|
277
288
|
let t = {};
|
|
278
289
|
for (let [n, r] of Object.entries(e)) t[n] = r.__definition();
|
|
279
290
|
return t;
|
|
280
|
-
}, p = /* @__PURE__ */ new WeakMap(), m = (e) => typeof e == "object" && e ? p.get(e) : void 0,
|
|
281
|
-
let n =
|
|
291
|
+
}, p = /* @__PURE__ */ new WeakMap(), m = (e) => typeof e == "object" && e ? p.get(e) : void 0, be = (e, t = {}) => {
|
|
292
|
+
let n = l();
|
|
282
293
|
return p.set(n, {
|
|
283
294
|
target: e,
|
|
284
295
|
orphanPolicy: t.orphanPolicy ?? "keep",
|
|
285
296
|
onSoftDelete: t.onSoftDelete ?? !1
|
|
286
297
|
}), n;
|
|
287
|
-
}, h = /* @__PURE__ */ new Map(),
|
|
298
|
+
}, h = /* @__PURE__ */ new Map(), xe = (e, t) => {
|
|
288
299
|
if (t.from === t.to) throw Error(`declareEnumRename('${e}'): \`from\` and \`to\` are both '${t.from}' — a rename must change the value.`);
|
|
289
300
|
let n = h.get(e) ?? [];
|
|
290
301
|
for (let r of n) {
|
|
@@ -292,16 +303,16 @@ var r = (e) => {
|
|
|
292
303
|
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}'.`);
|
|
293
304
|
}
|
|
294
305
|
n.push(t), h.set(e, n);
|
|
295
|
-
},
|
|
306
|
+
}, Se = (e) => h.get(e) ?? [], Ce = () => h, we = () => {
|
|
296
307
|
h.clear();
|
|
297
|
-
},
|
|
308
|
+
}, Te = 63, Ee = 60, g = [], _ = (e) => {
|
|
298
309
|
g.includes(e) || g.push(e);
|
|
299
|
-
},
|
|
310
|
+
}, De = () => {
|
|
300
311
|
let e = g.slice();
|
|
301
312
|
return g.length = 0, e;
|
|
302
|
-
},
|
|
313
|
+
}, Oe = /^[a-zA-Z_][a-zA-Z0-9_]*$/, v = (e, t) => {
|
|
303
314
|
if (t.length === 0) throw Error(`${e} cannot be empty.`);
|
|
304
|
-
if (!
|
|
315
|
+
if (!Oe.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_]*$/.`);
|
|
305
316
|
}, y = (e) => {
|
|
306
317
|
if (v("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.`);
|
|
307
318
|
e.length > 60 && _(`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.`);
|
|
@@ -322,28 +333,28 @@ var r = (e) => {
|
|
|
322
333
|
throw Error(`typeid prefix '${e}' on table '${t.tableName}' is ${e.length} chars — exceeds the 63-byte limit; ${n}`);
|
|
323
334
|
}
|
|
324
335
|
e.length > 60 && _(`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).`);
|
|
325
|
-
},
|
|
336
|
+
}, ke = 1704067200000n, C = 10n, w = 12n, T = (1n << C) - 1n, Ae = (1n << w) - 1n, je = w, Me = 22n, Ne = () => {
|
|
326
337
|
let e = process.env.SNOWFLAKE_MACHINE_ID;
|
|
327
338
|
if (e === void 0 || e === "") return 0n;
|
|
328
339
|
let t = BigInt(e);
|
|
329
|
-
if (t < 0n || t >
|
|
340
|
+
if (t < 0n || t > T) throw Error(`SNOWFLAKE_MACHINE_ID out of range: ${e}. Must be 0..${T}.`);
|
|
330
341
|
return t;
|
|
331
342
|
}, E = () => ({
|
|
332
343
|
lastMs: 0n,
|
|
333
344
|
sequence: 0n,
|
|
334
|
-
machineId:
|
|
335
|
-
}), D,
|
|
345
|
+
machineId: Ne()
|
|
346
|
+
}), D, Pe = () => (D === void 0 && (D = E()), D), Fe = () => {
|
|
336
347
|
D = E();
|
|
337
|
-
}, O = () => BigInt(Date.now()),
|
|
348
|
+
}, O = () => BigInt(Date.now()), Ie = (e) => {
|
|
338
349
|
let t = O();
|
|
339
350
|
for (; t <= e;) t = O();
|
|
340
351
|
return t;
|
|
341
352
|
}, k = () => {
|
|
342
|
-
let e =
|
|
343
|
-
t === e.lastMs ? (e.sequence = e.sequence + 1n &
|
|
344
|
-
let n = t -
|
|
353
|
+
let e = Pe(), t = O();
|
|
354
|
+
t === e.lastMs ? (e.sequence = e.sequence + 1n & Ae, e.sequence === 0n && (t = Ie(e.lastMs), e.lastMs = t)) : (e.sequence = 0n, e.lastMs = t);
|
|
355
|
+
let n = t - ke;
|
|
345
356
|
if (n < 0n) throw Error("Snowflake timestamp before configured epoch (2024-01-01). System clock is wrong.");
|
|
346
|
-
return (n <<
|
|
357
|
+
return (n << Me | e.machineId << je | e.sequence).toString();
|
|
347
358
|
}, A = (e) => {
|
|
348
359
|
let t = e.toLowerCase();
|
|
349
360
|
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.`);
|
|
@@ -385,7 +396,7 @@ var r = (e) => {
|
|
|
385
396
|
generate: e.generate
|
|
386
397
|
};
|
|
387
398
|
}
|
|
388
|
-
},
|
|
399
|
+
}, Le = (e, r) => {
|
|
389
400
|
switch (e.kind) {
|
|
390
401
|
case "typeid": return t(e.prefix).toString();
|
|
391
402
|
case "ulid": return n();
|
|
@@ -400,7 +411,7 @@ var r = (e) => {
|
|
|
400
411
|
...e.indexes === void 0 ? {} : { indexes: e.indexes },
|
|
401
412
|
...e.behaviors === void 0 ? {} : { behaviors: e.behaviors },
|
|
402
413
|
...e.policies === void 0 ? {} : { policies: e.policies }
|
|
403
|
-
}),
|
|
414
|
+
}), Re = M, N = (e) => {
|
|
404
415
|
let t = /* @__PURE__ */ new Set(), n = [], r = (e) => {
|
|
405
416
|
let i = e.id ?? e;
|
|
406
417
|
if (!t.has(i)) {
|
|
@@ -410,7 +421,7 @@ var r = (e) => {
|
|
|
410
421
|
};
|
|
411
422
|
for (let t of e) r(t);
|
|
412
423
|
return n;
|
|
413
|
-
},
|
|
424
|
+
}, ze = (e, ...t) => {
|
|
414
425
|
if (t.length === 0) throw Error(`jsonIndex("${e}"): at least one path segment is required`);
|
|
415
426
|
let n = (r) => ({
|
|
416
427
|
jsonPath: {
|
|
@@ -421,14 +432,14 @@ var r = (e) => {
|
|
|
421
432
|
numeric: () => n(!0)
|
|
422
433
|
});
|
|
423
434
|
return n(!1);
|
|
424
|
-
},
|
|
435
|
+
}, Be = (e = "cosine", t = "float32") => {
|
|
425
436
|
let n = t === "half" ? "halfvec" : "vector";
|
|
426
437
|
switch (e) {
|
|
427
438
|
case "cosine": return `${n}_cosine_ops`;
|
|
428
439
|
case "l2": return `${n}_l2_ops`;
|
|
429
440
|
case "inner": return `${n}_ip_ops`;
|
|
430
441
|
}
|
|
431
|
-
},
|
|
442
|
+
}, Ve = [
|
|
432
443
|
"id",
|
|
433
444
|
"tenantId",
|
|
434
445
|
"createdAt",
|
|
@@ -437,7 +448,7 @@ var r = (e) => {
|
|
|
437
448
|
"updatedBy",
|
|
438
449
|
"deletedAt",
|
|
439
450
|
"deletedBy"
|
|
440
|
-
], P = (e) => e.id ?? `<anonymous mixin: ${Object.keys(e.fields).join(", ")}>`, F = (e, t) => `${e}_${t.join("_")}_idx`,
|
|
451
|
+
], P = (e) => e.id ?? `<anonymous mixin: ${Object.keys(e.fields).join(", ")}>`, F = (e, t) => `${e}_${t.join("_")}_idx`, He = (e, t) => `${e}_${t.join("_")}_uq`, I = (e, t, n, r, i) => {
|
|
441
452
|
if (n !== "hnsw") return;
|
|
442
453
|
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.`);
|
|
443
454
|
let a = r[0];
|
|
@@ -445,7 +456,7 @@ var r = (e) => {
|
|
|
445
456
|
let o = i[a];
|
|
446
457
|
if (o === void 0) throw Error(`hnsw index '${t}' on table '${e}' references unknown column '${a}'.`);
|
|
447
458
|
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.`);
|
|
448
|
-
},
|
|
459
|
+
}, Ue = (e, t) => {
|
|
449
460
|
let n;
|
|
450
461
|
for (let [r, i] of Object.entries(e)) i.type === "id" && i.idScheme === void 0 && (n === void 0 && (n = { ...e }), n[r] = {
|
|
451
462
|
...i,
|
|
@@ -581,7 +592,7 @@ var r = (e) => {
|
|
|
581
592
|
}),
|
|
582
593
|
unique: ((...e) => {
|
|
583
594
|
let n, r, i, a = Array.isArray(e[0]);
|
|
584
|
-
if (a ? (r = e[0], i = e[1], n =
|
|
595
|
+
if (a ? (r = e[0], i = e[1], n = He(t.tableName, r)) : (n = e[0], r = e[1], i = e[2]), r.length === 0) throw Error(`unique '${n}' on table '${t.tableName}' has no fields — a UNIQUE constraint must cover at least one column.`);
|
|
585
596
|
if (x(t.tableName, n, a, r), t.appliedUniques.some((e) => e.name === n)) throw Error(a ? `duplicate auto-named UNIQUE '${n}' on table '${t.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 '${t.tableName}': each constraint name must be unique within a table.`);
|
|
586
597
|
return L({
|
|
587
598
|
...t,
|
|
@@ -736,7 +747,7 @@ var r = (e) => {
|
|
|
736
747
|
validatePatchSchema: e.partial(n)
|
|
737
748
|
}))
|
|
738
749
|
};
|
|
739
|
-
},
|
|
750
|
+
}, We = (e, t) => {
|
|
740
751
|
y(e);
|
|
741
752
|
let n = Object.entries(t).flatMap(([e, t]) => {
|
|
742
753
|
let n = m(t);
|
|
@@ -744,7 +755,7 @@ var r = (e) => {
|
|
|
744
755
|
column: e,
|
|
745
756
|
...n
|
|
746
757
|
}];
|
|
747
|
-
}), r =
|
|
758
|
+
}), r = Ue(f(t), e);
|
|
748
759
|
for (let t of Object.keys(r)) b(e, t);
|
|
749
760
|
return L({
|
|
750
761
|
appliedPluginRefs: n,
|
|
@@ -758,7 +769,7 @@ var r = (e) => {
|
|
|
758
769
|
appliedChecks: [],
|
|
759
770
|
appliedRules: []
|
|
760
771
|
});
|
|
761
|
-
},
|
|
772
|
+
}, Ge = (e) => e === "sqlite" || e === "turso", Ke = (e) => e === "mysql" || e === "mariadb", R = (e, t) => {
|
|
762
773
|
switch (t) {
|
|
763
774
|
case "mysql":
|
|
764
775
|
case "mariadb": return `\`${e}\``;
|
|
@@ -767,51 +778,51 @@ var r = (e) => {
|
|
|
767
778
|
case "sqlite":
|
|
768
779
|
case "turso": return `"${e}"`;
|
|
769
780
|
}
|
|
770
|
-
},
|
|
771
|
-
let t =
|
|
781
|
+
}, qe = 1e4, z = Symbol.for("@voltro/database/tableRegistry"), B = globalThis, V = B[z] ?? (B[z] = /* @__PURE__ */ new Map()), H = (e) => {
|
|
782
|
+
let t = V.get(e.tableName);
|
|
772
783
|
if (t === void 0) {
|
|
773
|
-
|
|
784
|
+
V.set(e.tableName, e);
|
|
774
785
|
return;
|
|
775
786
|
}
|
|
776
787
|
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.`);
|
|
777
|
-
},
|
|
778
|
-
|
|
779
|
-
},
|
|
780
|
-
let t =
|
|
788
|
+
}, Je = (e) => {
|
|
789
|
+
V.get(e.tableName) === void 0 && V.set(e.tableName, e);
|
|
790
|
+
}, U = (e) => V.get(e), Ye = (e) => {
|
|
791
|
+
let t = V.get(e);
|
|
781
792
|
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.`);
|
|
782
793
|
return t;
|
|
783
|
-
},
|
|
784
|
-
|
|
785
|
-
},
|
|
794
|
+
}, Xe = () => [...V.values()], Ze = (e) => V.delete(e), Qe = () => {
|
|
795
|
+
V.clear();
|
|
796
|
+
}, $e = (e) => V.get(e)?.isReactive !== !1, et = (e) => e.order ?? [], tt = (e) => ({
|
|
786
797
|
op: "count",
|
|
787
798
|
alias: e ?? "count"
|
|
788
|
-
}),
|
|
799
|
+
}), nt = (e, t) => ({
|
|
789
800
|
op: "count-distinct",
|
|
790
801
|
column: e,
|
|
791
802
|
alias: t ?? `count_distinct_${e}`
|
|
792
|
-
}),
|
|
803
|
+
}), rt = (e, t) => ({
|
|
793
804
|
op: "sum",
|
|
794
805
|
column: e,
|
|
795
806
|
alias: t ?? `sum_${e}`
|
|
796
|
-
}),
|
|
807
|
+
}), it = (e, t) => ({
|
|
797
808
|
op: "avg",
|
|
798
809
|
column: e,
|
|
799
810
|
alias: t ?? `avg_${e}`
|
|
800
|
-
}),
|
|
811
|
+
}), at = (e, t) => ({
|
|
801
812
|
op: "min",
|
|
802
813
|
column: e,
|
|
803
814
|
alias: t ?? `min_${e}`
|
|
804
|
-
}),
|
|
815
|
+
}), ot = (e, t) => ({
|
|
805
816
|
op: "max",
|
|
806
817
|
column: e,
|
|
807
818
|
alias: t ?? `max_${e}`
|
|
808
|
-
}),
|
|
819
|
+
}), st = (e, t) => ({
|
|
809
820
|
op: "column",
|
|
810
821
|
column: e,
|
|
811
822
|
alias: t ?? e
|
|
812
|
-
}),
|
|
823
|
+
}), W = (e) => (...t) => {
|
|
813
824
|
if (t.length < 2) throw Error(`${e}: requires at least two queries`);
|
|
814
|
-
return
|
|
825
|
+
return q({
|
|
815
826
|
table: t[0].descriptor.table,
|
|
816
827
|
predicate: void 0,
|
|
817
828
|
order: [],
|
|
@@ -823,55 +834,55 @@ var r = (e) => {
|
|
|
823
834
|
queries: t.map((e) => e.descriptor)
|
|
824
835
|
}
|
|
825
836
|
});
|
|
826
|
-
},
|
|
837
|
+
}, ct = W("union"), lt = W("union-all"), ut = W("intersect"), dt = W("except"), G = (e) => ({ over: (t) => ({
|
|
827
838
|
...e,
|
|
828
839
|
window: t
|
|
829
|
-
}) }),
|
|
840
|
+
}) }), ft = (e = "rowNumber") => G({
|
|
830
841
|
op: "window-row-number",
|
|
831
842
|
alias: e
|
|
832
|
-
}),
|
|
843
|
+
}), pt = (e = "rank") => G({
|
|
833
844
|
op: "window-rank",
|
|
834
845
|
alias: e
|
|
835
|
-
}),
|
|
846
|
+
}), mt = (e = "denseRank") => G({
|
|
836
847
|
op: "window-dense-rank",
|
|
837
848
|
alias: e
|
|
838
|
-
}),
|
|
849
|
+
}), ht = (e, t = 1, n) => G({
|
|
839
850
|
op: "window-lag",
|
|
840
851
|
column: e,
|
|
841
852
|
alias: n ?? `lag_${e}`,
|
|
842
853
|
offset: t
|
|
843
|
-
}),
|
|
854
|
+
}), gt = (e, t = 1, n) => G({
|
|
844
855
|
op: "window-lead",
|
|
845
856
|
column: e,
|
|
846
857
|
alias: n ?? `lead_${e}`,
|
|
847
858
|
offset: t
|
|
848
|
-
}),
|
|
859
|
+
}), _t = (e, t) => G({
|
|
849
860
|
op: "window-sum-over",
|
|
850
861
|
column: e,
|
|
851
862
|
alias: t ?? `sum_${e}_over`
|
|
852
|
-
}),
|
|
863
|
+
}), vt = (e, t) => G({
|
|
853
864
|
op: "window-avg-over",
|
|
854
865
|
column: e,
|
|
855
866
|
alias: t ?? `avg_${e}_over`
|
|
856
|
-
}),
|
|
857
|
-
let r = n?.find((e) => e.name === t) ??
|
|
867
|
+
}), K = (e, t, n) => {
|
|
868
|
+
let r = n?.find((e) => e.name === t) ?? U(e)?.appliedFullText?.find((e) => e.name === t);
|
|
858
869
|
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.`);
|
|
859
870
|
return {
|
|
860
871
|
columns: r.columns,
|
|
861
872
|
...r.config === void 0 ? {} : { config: r.config },
|
|
862
873
|
...r.weights === void 0 ? {} : { weights: r.weights }
|
|
863
874
|
};
|
|
864
|
-
},
|
|
875
|
+
}, q = (e) => ({
|
|
865
876
|
descriptor: e,
|
|
866
877
|
where(t) {
|
|
867
878
|
let n = e.predicate ? { and: [e.predicate, t] } : t;
|
|
868
|
-
return
|
|
879
|
+
return q({
|
|
869
880
|
...e,
|
|
870
881
|
predicate: n
|
|
871
882
|
});
|
|
872
883
|
},
|
|
873
884
|
orderBy(t, n = "asc") {
|
|
874
|
-
return
|
|
885
|
+
return q({
|
|
875
886
|
...e,
|
|
876
887
|
order: [...e.order, {
|
|
877
888
|
column: t,
|
|
@@ -880,37 +891,37 @@ var r = (e) => {
|
|
|
880
891
|
});
|
|
881
892
|
},
|
|
882
893
|
limit(t) {
|
|
883
|
-
return
|
|
894
|
+
return q({
|
|
884
895
|
...e,
|
|
885
896
|
take: t
|
|
886
897
|
});
|
|
887
898
|
},
|
|
888
899
|
offset(t) {
|
|
889
|
-
return
|
|
900
|
+
return q({
|
|
890
901
|
...e,
|
|
891
902
|
skip: t
|
|
892
903
|
});
|
|
893
904
|
},
|
|
894
905
|
select(...t) {
|
|
895
|
-
return
|
|
906
|
+
return q({
|
|
896
907
|
...e,
|
|
897
908
|
projection: t
|
|
898
909
|
});
|
|
899
910
|
},
|
|
900
911
|
using(t) {
|
|
901
|
-
return
|
|
912
|
+
return q({
|
|
902
913
|
...e,
|
|
903
914
|
usingIndex: t
|
|
904
915
|
});
|
|
905
916
|
},
|
|
906
917
|
withDeleted() {
|
|
907
|
-
return
|
|
918
|
+
return q({
|
|
908
919
|
...e,
|
|
909
920
|
includeDeleted: !0
|
|
910
921
|
});
|
|
911
922
|
},
|
|
912
923
|
unscoped() {
|
|
913
|
-
return
|
|
924
|
+
return q({
|
|
914
925
|
...e,
|
|
915
926
|
crossTenant: !0
|
|
916
927
|
});
|
|
@@ -920,13 +931,13 @@ var r = (e) => {
|
|
|
920
931
|
...e.eager ?? {},
|
|
921
932
|
...t
|
|
922
933
|
};
|
|
923
|
-
return
|
|
934
|
+
return q({
|
|
924
935
|
...e,
|
|
925
936
|
eager: n
|
|
926
937
|
});
|
|
927
938
|
},
|
|
928
939
|
count() {
|
|
929
|
-
return
|
|
940
|
+
return q({
|
|
930
941
|
...e,
|
|
931
942
|
projection: void 0,
|
|
932
943
|
aggregations: [{
|
|
@@ -940,15 +951,15 @@ var r = (e) => {
|
|
|
940
951
|
...t,
|
|
941
952
|
alias: e
|
|
942
953
|
}));
|
|
943
|
-
return
|
|
954
|
+
return q({
|
|
944
955
|
...e,
|
|
945
956
|
projection: void 0,
|
|
946
957
|
aggregations: n
|
|
947
958
|
});
|
|
948
959
|
},
|
|
949
960
|
matching(t, n) {
|
|
950
|
-
let r =
|
|
951
|
-
return
|
|
961
|
+
let r = K(e.table, t, e.fullTextIndexes);
|
|
962
|
+
return q({
|
|
952
963
|
...e,
|
|
953
964
|
fullTextSearch: {
|
|
954
965
|
indexName: t,
|
|
@@ -962,7 +973,7 @@ var r = (e) => {
|
|
|
962
973
|
rankBy(t) {
|
|
963
974
|
let n = e.fullTextSearch;
|
|
964
975
|
if (n === void 0) throw Error(".rankBy() requires a preceding .matching(...) clause — there is no full-text search to rank on this query.");
|
|
965
|
-
return
|
|
976
|
+
return q({
|
|
966
977
|
...e,
|
|
967
978
|
fullTextSearch: {
|
|
968
979
|
...n,
|
|
@@ -981,7 +992,7 @@ var r = (e) => {
|
|
|
981
992
|
distance: r?.distance ?? "cosine",
|
|
982
993
|
...e.annClause?.ef === void 0 ? {} : { ef: e.annClause.ef }
|
|
983
994
|
};
|
|
984
|
-
return
|
|
995
|
+
return q({
|
|
985
996
|
...e,
|
|
986
997
|
annClause: i
|
|
987
998
|
});
|
|
@@ -993,7 +1004,7 @@ var r = (e) => {
|
|
|
993
1004
|
distance: "cosine",
|
|
994
1005
|
...e.annClause?.ef === void 0 ? {} : { ef: e.annClause.ef }
|
|
995
1006
|
};
|
|
996
|
-
return
|
|
1007
|
+
return q({
|
|
997
1008
|
...e,
|
|
998
1009
|
annClause: r,
|
|
999
1010
|
take: n
|
|
@@ -1006,7 +1017,7 @@ var r = (e) => {
|
|
|
1006
1017
|
column: "",
|
|
1007
1018
|
distance: "cosine"
|
|
1008
1019
|
};
|
|
1009
|
-
return
|
|
1020
|
+
return q({
|
|
1010
1021
|
...e,
|
|
1011
1022
|
annClause: {
|
|
1012
1023
|
...n,
|
|
@@ -1015,22 +1026,22 @@ var r = (e) => {
|
|
|
1015
1026
|
});
|
|
1016
1027
|
},
|
|
1017
1028
|
use(t) {
|
|
1018
|
-
return
|
|
1029
|
+
return q({ ...t(e) });
|
|
1019
1030
|
},
|
|
1020
1031
|
distinct() {
|
|
1021
|
-
return
|
|
1032
|
+
return q({
|
|
1022
1033
|
...e,
|
|
1023
1034
|
distinct: !0
|
|
1024
1035
|
});
|
|
1025
1036
|
},
|
|
1026
1037
|
distinctOn(t) {
|
|
1027
|
-
return
|
|
1038
|
+
return q({
|
|
1028
1039
|
...e,
|
|
1029
1040
|
distinctOn: [...t]
|
|
1030
1041
|
});
|
|
1031
1042
|
},
|
|
1032
1043
|
as(t) {
|
|
1033
|
-
return
|
|
1044
|
+
return q({
|
|
1034
1045
|
...e,
|
|
1035
1046
|
alias: t
|
|
1036
1047
|
});
|
|
@@ -1042,7 +1053,7 @@ var r = (e) => {
|
|
|
1042
1053
|
alias: n,
|
|
1043
1054
|
on: r
|
|
1044
1055
|
}];
|
|
1045
|
-
return
|
|
1056
|
+
return q({
|
|
1046
1057
|
...e,
|
|
1047
1058
|
joins: a
|
|
1048
1059
|
});
|
|
@@ -1054,7 +1065,7 @@ var r = (e) => {
|
|
|
1054
1065
|
alias: n,
|
|
1055
1066
|
on: r
|
|
1056
1067
|
}];
|
|
1057
|
-
return
|
|
1068
|
+
return q({
|
|
1058
1069
|
...e,
|
|
1059
1070
|
joins: a
|
|
1060
1071
|
});
|
|
@@ -1064,7 +1075,7 @@ var r = (e) => {
|
|
|
1064
1075
|
outputKey: e,
|
|
1065
1076
|
source: t
|
|
1066
1077
|
}));
|
|
1067
|
-
return
|
|
1078
|
+
return q({
|
|
1068
1079
|
...e,
|
|
1069
1080
|
projection: void 0,
|
|
1070
1081
|
joinedProjection: n
|
|
@@ -1073,7 +1084,7 @@ var r = (e) => {
|
|
|
1073
1084
|
withCte(t, n) {
|
|
1074
1085
|
let r = e.ctes ?? [];
|
|
1075
1086
|
if (r.some((e) => e.name === t)) throw Error(`Query.withCte: duplicate CTE name '${t}'`);
|
|
1076
|
-
return
|
|
1087
|
+
return q({
|
|
1077
1088
|
...e,
|
|
1078
1089
|
ctes: [...r, {
|
|
1079
1090
|
name: t,
|
|
@@ -1084,7 +1095,7 @@ var r = (e) => {
|
|
|
1084
1095
|
recursiveCte(t, n) {
|
|
1085
1096
|
let r = e.ctes ?? [];
|
|
1086
1097
|
if (r.some((e) => e.name === t)) throw Error(`Query.recursiveCte: duplicate CTE name '${t}'`);
|
|
1087
|
-
return
|
|
1098
|
+
return q({
|
|
1088
1099
|
...e,
|
|
1089
1100
|
ctes: [...r, {
|
|
1090
1101
|
name: t,
|
|
@@ -1095,20 +1106,20 @@ var r = (e) => {
|
|
|
1095
1106
|
},
|
|
1096
1107
|
groupBy(t) {
|
|
1097
1108
|
let n = e.groupBy ? [...e.groupBy, ...t] : [...t];
|
|
1098
|
-
return
|
|
1109
|
+
return q({
|
|
1099
1110
|
...e,
|
|
1100
1111
|
groupBy: n
|
|
1101
1112
|
});
|
|
1102
1113
|
},
|
|
1103
1114
|
having(t) {
|
|
1104
1115
|
let n = e.having ? { and: [e.having, t] } : t;
|
|
1105
|
-
return
|
|
1116
|
+
return q({
|
|
1106
1117
|
...e,
|
|
1107
1118
|
having: n
|
|
1108
1119
|
});
|
|
1109
1120
|
},
|
|
1110
1121
|
exists() {
|
|
1111
|
-
return
|
|
1122
|
+
return q({
|
|
1112
1123
|
...e,
|
|
1113
1124
|
projection: void 0,
|
|
1114
1125
|
aggregations: [{
|
|
@@ -1119,8 +1130,8 @@ var r = (e) => {
|
|
|
1119
1130
|
});
|
|
1120
1131
|
}
|
|
1121
1132
|
});
|
|
1122
|
-
function
|
|
1123
|
-
return
|
|
1133
|
+
function J(e) {
|
|
1134
|
+
return q({
|
|
1124
1135
|
table: e.tableName,
|
|
1125
1136
|
predicate: void 0,
|
|
1126
1137
|
order: [],
|
|
@@ -1131,7 +1142,7 @@ function Y(e) {
|
|
|
1131
1142
|
sourceTable: e
|
|
1132
1143
|
});
|
|
1133
1144
|
}
|
|
1134
|
-
var
|
|
1145
|
+
var yt = (e, t, n) => Y(e, "id", t, n), Y = (e, t, n, r, i = "asc") => {
|
|
1135
1146
|
let a = [...e.order.filter((e) => e.column !== t), {
|
|
1136
1147
|
column: t,
|
|
1137
1148
|
direction: i
|
|
@@ -1146,11 +1157,11 @@ var gt = (e, t, n) => X(e, "id", t, n), X = (e, t, n, r, i = "asc") => {
|
|
|
1146
1157
|
order: a,
|
|
1147
1158
|
take: r
|
|
1148
1159
|
};
|
|
1149
|
-
},
|
|
1160
|
+
}, bt = (e) => {
|
|
1150
1161
|
let t = {};
|
|
1151
|
-
for (let [n, r] of Object.entries(e))
|
|
1162
|
+
for (let [n, r] of Object.entries(e)) H(r), t[n] = J(r);
|
|
1152
1163
|
return t;
|
|
1153
|
-
},
|
|
1164
|
+
}, xt = (e) => e.isView === !0, St = (e, t, n) => {
|
|
1154
1165
|
if (y(e), n.trim().length === 0) throw Error(`view('${e}', …): the SELECT body is empty — a view must define a query.`);
|
|
1155
1166
|
let r = f(t);
|
|
1156
1167
|
for (let t of Object.keys(r)) b(e, t);
|
|
@@ -1160,7 +1171,7 @@ var gt = (e, t, n) => X(e, "id", t, n), X = (e, t, n, r, i = "asc") => {
|
|
|
1160
1171
|
isView: !0,
|
|
1161
1172
|
viewSelect: n
|
|
1162
1173
|
};
|
|
1163
|
-
},
|
|
1174
|
+
}, Ct = (e) => J({
|
|
1164
1175
|
...e,
|
|
1165
1176
|
isReactive: !1,
|
|
1166
1177
|
appliedMixins: [],
|
|
@@ -1168,8 +1179,8 @@ var gt = (e, t, n) => X(e, "id", t, n), X = (e, t, n, r, i = "asc") => {
|
|
|
1168
1179
|
appliedUniques: [],
|
|
1169
1180
|
appliedFullText: [],
|
|
1170
1181
|
appliedChecks: []
|
|
1171
|
-
}),
|
|
1172
|
-
let r = n === null ?
|
|
1182
|
+
}), wt = (e, t, n = null) => {
|
|
1183
|
+
let r = n === null ? R(e.tableName, t) : `${R(n, t)}.${R(e.tableName, t)}`, i = e.viewSelect.trim();
|
|
1173
1184
|
switch (t) {
|
|
1174
1185
|
case "postgres":
|
|
1175
1186
|
case "mysql":
|
|
@@ -1178,16 +1189,16 @@ var gt = (e, t, n) => X(e, "id", t, n), X = (e, t, n, r, i = "asc") => {
|
|
|
1178
1189
|
case "sqlite":
|
|
1179
1190
|
case "turso": return `DROP VIEW IF EXISTS ${r};\nCREATE VIEW ${r} AS ${i};`;
|
|
1180
1191
|
}
|
|
1181
|
-
},
|
|
1192
|
+
}, Tt = /^[A-Za-z_][A-Za-z0-9_]*$/, Et = (e) => "$" + e.map((e) => typeof e == "number" ? `[${e}]` : Tt.test(e) ? `.${e}` : `."${e.replace(/"/g, "\\\"")}"`).join(""), Dt = (e) => "{" + e.map((e) => {
|
|
1182
1193
|
let t = String(e);
|
|
1183
1194
|
return /^[A-Za-z0-9_]+$/.test(t) ? t : `"${t.replace(/(["\\])/g, "\\$1")}"`;
|
|
1184
|
-
}).join(",") + "}",
|
|
1185
|
-
let i =
|
|
1195
|
+
}).join(",") + "}", Ot = (e, t, n, r = {}) => {
|
|
1196
|
+
let i = R(e, n), a = r.numeric ?? !1;
|
|
1186
1197
|
if (n === "postgres") {
|
|
1187
|
-
let e = `(${i} #>> '${
|
|
1198
|
+
let e = `(${i} #>> '${Dt(t)}'::text[])`;
|
|
1188
1199
|
return a ? `${e}::numeric` : e;
|
|
1189
1200
|
}
|
|
1190
|
-
let o =
|
|
1201
|
+
let o = Et(t);
|
|
1191
1202
|
switch (n) {
|
|
1192
1203
|
case "mysql":
|
|
1193
1204
|
case "mariadb": {
|
|
@@ -1204,13 +1215,13 @@ var gt = (e, t, n) => X(e, "id", t, n), X = (e, t, n, r, i = "asc") => {
|
|
|
1204
1215
|
return a ? `CAST(${e} AS REAL)` : e;
|
|
1205
1216
|
}
|
|
1206
1217
|
}
|
|
1207
|
-
},
|
|
1218
|
+
}, kt = (e, t) => ({
|
|
1208
1219
|
name: e,
|
|
1209
1220
|
body: t
|
|
1210
|
-
}),
|
|
1221
|
+
}), X = (e) => {
|
|
1211
1222
|
if (e.lifecycle === "cron" && !e.cron) throw Error(`seed "${e.id}": lifecycle 'cron' requires a 'cron' field`);
|
|
1212
1223
|
if (e.lifecycle === "onSchemaChange" && (!e.watchedTables || e.watchedTables.length === 0)) throw Error(`seed "${e.id}": lifecycle 'onSchemaChange' requires at least one entry in 'watchedTables'`);
|
|
1213
|
-
let t = e.steps({ step:
|
|
1224
|
+
let t = e.steps({ step: kt });
|
|
1214
1225
|
if (t.length === 0) throw Error(`seed "${e.id}": at least one step is required`);
|
|
1215
1226
|
return {
|
|
1216
1227
|
__seed: !0,
|
|
@@ -1223,20 +1234,20 @@ var gt = (e, t, n) => X(e, "id", t, n), X = (e, t, n, r, i = "asc") => {
|
|
|
1223
1234
|
...e.fingerprint === void 0 ? {} : { fingerprint: e.fingerprint },
|
|
1224
1235
|
steps: t
|
|
1225
1236
|
};
|
|
1226
|
-
},
|
|
1237
|
+
}, At = (e) => typeof e == "object" && !!e && "__seed" in e && e.__seed === !0, Z = null, Q = null, jt = (e) => {
|
|
1227
1238
|
Z = e;
|
|
1228
|
-
},
|
|
1239
|
+
}, Mt = (e) => {
|
|
1229
1240
|
Q = e;
|
|
1230
|
-
},
|
|
1241
|
+
}, Nt = async (e) => {
|
|
1231
1242
|
let t = Z;
|
|
1232
1243
|
t !== null && await t(e);
|
|
1233
|
-
},
|
|
1244
|
+
}, Pt = async (e) => {
|
|
1234
1245
|
let t = Q;
|
|
1235
1246
|
t !== null && e.changedTables.length !== 0 && await t(e);
|
|
1236
|
-
},
|
|
1247
|
+
}, Ft = (e) => {
|
|
1237
1248
|
if (!e.id || e.id.length === 0) throw Error("migration: `id` is required + must be non-empty");
|
|
1238
1249
|
if (!e.up || !e.down) throw Error(`migration ${e.id}: both \`up\` and \`down\` must be functions`);
|
|
1239
1250
|
return e;
|
|
1240
|
-
},
|
|
1251
|
+
}, It = /^\d{8}_\d{6}_[a-z0-9_]+\.ts$/, Lt = (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", $ = /* @__PURE__ */ new Set(["voltro_isr_cache"]), Rt = (e) => $.has(e) || e.startsWith("_voltro_") || e.startsWith("_cloud_") || e.startsWith("cluster_"), zt = /__dropped_\d{14}$/, Bt = (e) => zt.test(e);
|
|
1241
1252
|
//#endregion
|
|
1242
|
-
export {
|
|
1253
|
+
export { R as $, me as $t, at as A, de as At, ct as B, ee as Bt, bt as C, be as Ct, ht as D, ie as Dt, ut as E, he as Et, pt as F, ae as Ft, U as G, re as Gt, Xe as H, ge as Ht, K as I, u as It, Ye as J, ne as Jt, $e as K, ye as Kt, ft as L, pe as Lt, Y as M, i as Mt, yt as N, d as Nt, gt as O, oe as Ot, J as P, ce as Pt, Ge as Q, se as Qt, rt as R, _e as Rt, nt as S, Se as St, dt as T, s as Tt, Qe as U, le as Ut, lt as V, te as Vt, Je as W, f as Wt, qe as X, r as Xt, Ze as Y, fe as Yt, Ke as Z, l as Zt, wt as _, y as _t, Lt as a, M as at, st as b, we as bt, Pt as c, Le as ct, Mt as d, Fe as dt, Ve as et, jt as f, Te as ft, St as g, x as gt, Ct as h, b as ht, It as i, Re as it, et as j, o as jt, ot as k, ue as kt, Nt as l, j as lt, xt as m, De as mt, Rt as n, We as nt, Ft as o, N as ot, Ot as p, Ee as pt, H as q, a as qt, Bt as r, Be as rt, X as s, A as st, $ as t, ze as tt, At as u, k as ut, it as v, S as vt, mt as w, m as wt, tt as x, xe as xt, vt as y, Ce as yt, _t as z, ve as zt };
|