@voltro/database 0.11.3 → 0.12.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 +436 -0
- package/dist/{fileBased-BrYB2u6E.js → fileBased-DEW2BvnP.js} +110 -100
- package/dist/index.d.ts +59 -1
- package/dist/index.js +584 -573
- package/dist/sql.d.ts +13 -0
- package/dist/sql.js +4 -4
- package/package.json +2 -2
|
@@ -2,7 +2,11 @@ import { typeid as e } from "typeid-js";
|
|
|
2
2
|
import { ulid as t } from "ulidx";
|
|
3
3
|
import { Schema as n } from "effect";
|
|
4
4
|
//#region src/columns.ts
|
|
5
|
-
var r =
|
|
5
|
+
var r = (e) => {
|
|
6
|
+
let t = [];
|
|
7
|
+
for (let [n, r] of Object.entries(e.fields)) r.serverOnly === !0 && t.push(n);
|
|
8
|
+
return t;
|
|
9
|
+
}, i = class e {
|
|
6
10
|
definition;
|
|
7
11
|
constructor(e) {
|
|
8
12
|
this.definition = e;
|
|
@@ -22,6 +26,12 @@ var r = class e {
|
|
|
22
26
|
encrypted: !0
|
|
23
27
|
});
|
|
24
28
|
}
|
|
29
|
+
serverOnly() {
|
|
30
|
+
return this.rejectIfRaw("serverOnly"), new e({
|
|
31
|
+
...this.definition,
|
|
32
|
+
serverOnly: !0
|
|
33
|
+
});
|
|
34
|
+
}
|
|
25
35
|
sensitive(t) {
|
|
26
36
|
return new e({
|
|
27
37
|
...this.definition,
|
|
@@ -131,21 +141,21 @@ var r = class e {
|
|
|
131
141
|
__definition() {
|
|
132
142
|
return this.definition;
|
|
133
143
|
}
|
|
134
|
-
},
|
|
144
|
+
}, a = (e) => new i({
|
|
135
145
|
type: e,
|
|
136
146
|
nullable: !1,
|
|
137
147
|
unique: !1,
|
|
138
148
|
hasDefault: !1
|
|
139
|
-
}),
|
|
149
|
+
}), o = (e) => new i({
|
|
140
150
|
type: "id",
|
|
141
151
|
nullable: !1,
|
|
142
152
|
unique: !0,
|
|
143
153
|
hasDefault: !1,
|
|
144
154
|
idSchemeInput: e
|
|
145
|
-
}),
|
|
155
|
+
}), s = () => a("text"), ee = () => a("integer"), te = () => a("real"), c = (e, t = 0) => {
|
|
146
156
|
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)).`);
|
|
147
157
|
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}).`);
|
|
148
|
-
return new
|
|
158
|
+
return new i({
|
|
149
159
|
type: "decimal",
|
|
150
160
|
nullable: !1,
|
|
151
161
|
unique: !1,
|
|
@@ -153,12 +163,12 @@ var r = class e {
|
|
|
153
163
|
precision: e,
|
|
154
164
|
scale: t
|
|
155
165
|
});
|
|
156
|
-
},
|
|
166
|
+
}, ne = c, re = () => a("bigint"), ie = (e, t) => {
|
|
157
167
|
if (t.length === 0) throw Error(`dbEnum('${e}', []): enum must have at least one value`);
|
|
158
168
|
return {
|
|
159
169
|
name: e,
|
|
160
170
|
values: t,
|
|
161
|
-
column: () => new
|
|
171
|
+
column: () => new i({
|
|
162
172
|
type: "enum",
|
|
163
173
|
nullable: !1,
|
|
164
174
|
unique: !1,
|
|
@@ -167,7 +177,7 @@ var r = class e {
|
|
|
167
177
|
enumValues: t
|
|
168
178
|
})
|
|
169
179
|
};
|
|
170
|
-
},
|
|
180
|
+
}, ae = () => a("boolean"), oe = () => a("timestamp"), l = () => a("date"), se = () => a("json"), ce = () => a("bytes"), le = (e, t) => new i({
|
|
171
181
|
type: "reference",
|
|
172
182
|
nullable: !1,
|
|
173
183
|
unique: !1,
|
|
@@ -177,15 +187,15 @@ var r = class e {
|
|
|
177
187
|
refOnUpdate: t?.onUpdate ?? "noAction",
|
|
178
188
|
fkAutoIndex: t?.index ?? !0,
|
|
179
189
|
...t?.orphanPolicy ? { orphanPolicy: t.orphanPolicy } : {}
|
|
180
|
-
}),
|
|
190
|
+
}), ue = () => new i({
|
|
181
191
|
type: "text",
|
|
182
192
|
nullable: !0,
|
|
183
193
|
unique: !1,
|
|
184
194
|
hasDefault: !1,
|
|
185
195
|
dropped: !0
|
|
186
|
-
}),
|
|
196
|
+
}), de = (e, t) => {
|
|
187
197
|
if (!Number.isInteger(e) || e <= 0) throw Error(`vector(${String(e)}): dimension must be a positive integer (the embedding length, e.g. vector(1536)).`);
|
|
188
|
-
return new
|
|
198
|
+
return new i({
|
|
189
199
|
type: "vector",
|
|
190
200
|
nullable: !1,
|
|
191
201
|
unique: !1,
|
|
@@ -193,13 +203,13 @@ var r = class e {
|
|
|
193
203
|
vectorDim: e,
|
|
194
204
|
vectorPrecision: t?.precision ?? "float32"
|
|
195
205
|
});
|
|
196
|
-
},
|
|
206
|
+
}, fe = (e) => new i({
|
|
197
207
|
type: "array",
|
|
198
208
|
nullable: !1,
|
|
199
209
|
unique: !1,
|
|
200
210
|
hasDefault: !1,
|
|
201
211
|
arrayElement: e.__definition().type
|
|
202
|
-
}),
|
|
212
|
+
}), pe = () => a("interval"), me = (e, t = 4326) => new i({
|
|
203
213
|
type: "text",
|
|
204
214
|
nullable: !1,
|
|
205
215
|
unique: !1,
|
|
@@ -209,7 +219,7 @@ var r = class e {
|
|
|
209
219
|
geomKind: e,
|
|
210
220
|
srid: t
|
|
211
221
|
}
|
|
212
|
-
}),
|
|
222
|
+
}), he = (e, t = 4326) => new i({
|
|
213
223
|
type: "text",
|
|
214
224
|
nullable: !1,
|
|
215
225
|
unique: !1,
|
|
@@ -219,7 +229,7 @@ var r = class e {
|
|
|
219
229
|
geomKind: e,
|
|
220
230
|
srid: t
|
|
221
231
|
}
|
|
222
|
-
}),
|
|
232
|
+
}), ge = (e) => new i({
|
|
223
233
|
type: "raw",
|
|
224
234
|
nullable: !1,
|
|
225
235
|
unique: !1,
|
|
@@ -229,7 +239,7 @@ var r = class e {
|
|
|
229
239
|
let t = {};
|
|
230
240
|
for (let [n, r] of Object.entries(e)) t[n] = r.__definition();
|
|
231
241
|
return t;
|
|
232
|
-
}, d = /* @__PURE__ */ new Map(),
|
|
242
|
+
}, d = /* @__PURE__ */ new Map(), _e = (e, t) => {
|
|
233
243
|
if (t.from === t.to) throw Error(`declareEnumRename('${e}'): \`from\` and \`to\` are both '${t.from}' — a rename must change the value.`);
|
|
234
244
|
let n = d.get(e) ?? [];
|
|
235
245
|
for (let r of n) {
|
|
@@ -237,26 +247,26 @@ var r = class e {
|
|
|
237
247
|
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}'.`);
|
|
238
248
|
}
|
|
239
249
|
n.push(t), d.set(e, n);
|
|
240
|
-
},
|
|
250
|
+
}, ve = (e) => d.get(e) ?? [], ye = () => d, f = () => {
|
|
241
251
|
d.clear();
|
|
242
|
-
},
|
|
243
|
-
|
|
252
|
+
}, p = 63, m = 60, h = [], g = (e) => {
|
|
253
|
+
h.includes(e) || h.push(e);
|
|
244
254
|
}, be = () => {
|
|
245
|
-
let e =
|
|
246
|
-
return
|
|
247
|
-
}, xe = /^[a-zA-Z_][a-zA-Z0-9_]*$/,
|
|
255
|
+
let e = h.slice();
|
|
256
|
+
return h.length = 0, e;
|
|
257
|
+
}, xe = /^[a-zA-Z_][a-zA-Z0-9_]*$/, _ = (e, t) => {
|
|
248
258
|
if (t.length === 0) throw Error(`${e} cannot be empty.`);
|
|
249
259
|
if (!xe.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_]*$/.`);
|
|
250
|
-
},
|
|
251
|
-
if (
|
|
252
|
-
e.length > 60 &&
|
|
253
|
-
},
|
|
254
|
-
if (
|
|
255
|
-
t.length > 60 &&
|
|
256
|
-
},
|
|
257
|
-
if (
|
|
258
|
-
t.length > 60 &&
|
|
259
|
-
},
|
|
260
|
+
}, v = (e) => {
|
|
261
|
+
if (_("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.`);
|
|
262
|
+
e.length > 60 && g(`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.`);
|
|
263
|
+
}, y = (e, t) => {
|
|
264
|
+
if (_("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.`);
|
|
265
|
+
t.length > 60 && g(`column '${t}' on table '${e}' is ${t.length} chars — close to the 63-byte limit.`);
|
|
266
|
+
}, b = (e, t, n, r) => {
|
|
267
|
+
if (_("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.`);
|
|
268
|
+
t.length > 60 && g(`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.` : ""}`);
|
|
269
|
+
}, x = (e, t) => {
|
|
260
270
|
if (e.length === 0) throw Error(`typeid prefix on table '${t.tableName}' cannot be empty.`);
|
|
261
271
|
if (!/^[a-z][a-z0-9_]*$/.test(e)) {
|
|
262
272
|
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_]*$/.";
|
|
@@ -266,35 +276,35 @@ var r = class e {
|
|
|
266
276
|
let n = t.kind === "derived" ? "shorten the table name, or supply an explicit short prefix via id({ prefix: '...' })." : "pick a shorter prefix.";
|
|
267
277
|
throw Error(`typeid prefix '${e}' on table '${t.tableName}' is ${e.length} chars — exceeds the 63-byte limit; ${n}`);
|
|
268
278
|
}
|
|
269
|
-
e.length > 60 &&
|
|
270
|
-
}, Se = 1704067200000n, Ce = 10n,
|
|
279
|
+
e.length > 60 && g(`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).`);
|
|
280
|
+
}, Se = 1704067200000n, Ce = 10n, S = 12n, C = (1n << Ce) - 1n, w = (1n << S) - 1n, T = S, E = 22n, D = () => {
|
|
271
281
|
let e = process.env.SNOWFLAKE_MACHINE_ID;
|
|
272
282
|
if (e === void 0 || e === "") return 0n;
|
|
273
283
|
let t = BigInt(e);
|
|
274
|
-
if (t < 0n || t >
|
|
284
|
+
if (t < 0n || t > C) throw Error(`SNOWFLAKE_MACHINE_ID out of range: ${e}. Must be 0..${C}.`);
|
|
275
285
|
return t;
|
|
276
|
-
},
|
|
286
|
+
}, O = () => ({
|
|
277
287
|
lastMs: 0n,
|
|
278
288
|
sequence: 0n,
|
|
279
|
-
machineId:
|
|
280
|
-
}),
|
|
281
|
-
|
|
282
|
-
}, j = () => BigInt(Date.now()),
|
|
289
|
+
machineId: D()
|
|
290
|
+
}), k, A = () => (k === void 0 && (k = O()), k), we = () => {
|
|
291
|
+
k = O();
|
|
292
|
+
}, j = () => BigInt(Date.now()), Te = (e) => {
|
|
283
293
|
let t = j();
|
|
284
294
|
for (; t <= e;) t = j();
|
|
285
295
|
return t;
|
|
286
296
|
}, M = () => {
|
|
287
|
-
let e =
|
|
288
|
-
t === e.lastMs ? (e.sequence = e.sequence + 1n &
|
|
297
|
+
let e = A(), t = j();
|
|
298
|
+
t === e.lastMs ? (e.sequence = e.sequence + 1n & w, e.sequence === 0n && (t = Te(e.lastMs), e.lastMs = t)) : (e.sequence = 0n, e.lastMs = t);
|
|
289
299
|
let n = t - Se;
|
|
290
300
|
if (n < 0n) throw Error("Snowflake timestamp before configured epoch (2024-01-01). System clock is wrong.");
|
|
291
|
-
return (n <<
|
|
301
|
+
return (n << E | e.machineId << T | e.sequence).toString();
|
|
292
302
|
}, N = (e) => {
|
|
293
303
|
let t = e.toLowerCase();
|
|
294
304
|
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.`);
|
|
295
305
|
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: '...' }).`);
|
|
296
306
|
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;
|
|
297
|
-
return
|
|
307
|
+
return x(n, {
|
|
298
308
|
kind: "derived",
|
|
299
309
|
tableName: e
|
|
300
310
|
}), n;
|
|
@@ -303,7 +313,7 @@ var r = class e {
|
|
|
303
313
|
kind: "typeid",
|
|
304
314
|
prefix: N(t)
|
|
305
315
|
};
|
|
306
|
-
if ("prefix" in e && !("scheme" in e)) return
|
|
316
|
+
if ("prefix" in e && !("scheme" in e)) return x(e.prefix, {
|
|
307
317
|
kind: "explicit",
|
|
308
318
|
tableName: t
|
|
309
319
|
}), {
|
|
@@ -314,7 +324,7 @@ var r = class e {
|
|
|
314
324
|
switch (e.scheme) {
|
|
315
325
|
case "typeid": {
|
|
316
326
|
let n = e.prefix ?? N(t);
|
|
317
|
-
return e.prefix !== void 0 &&
|
|
327
|
+
return e.prefix !== void 0 && x(e.prefix, {
|
|
318
328
|
kind: "explicit",
|
|
319
329
|
tableName: t
|
|
320
330
|
}), {
|
|
@@ -330,7 +340,7 @@ var r = class e {
|
|
|
330
340
|
generate: e.generate
|
|
331
341
|
};
|
|
332
342
|
}
|
|
333
|
-
},
|
|
343
|
+
}, Ee = (n, r) => {
|
|
334
344
|
switch (n.kind) {
|
|
335
345
|
case "typeid": return e(n.prefix).toString();
|
|
336
346
|
case "ulid": return t();
|
|
@@ -345,7 +355,7 @@ var r = class e {
|
|
|
345
355
|
...e.indexes === void 0 ? {} : { indexes: e.indexes },
|
|
346
356
|
...e.behaviors === void 0 ? {} : { behaviors: e.behaviors },
|
|
347
357
|
...e.policies === void 0 ? {} : { policies: e.policies }
|
|
348
|
-
}),
|
|
358
|
+
}), De = F, I = (e) => {
|
|
349
359
|
let t = /* @__PURE__ */ new Set(), n = [], r = (e) => {
|
|
350
360
|
let i = e.id ?? e;
|
|
351
361
|
if (!t.has(i)) {
|
|
@@ -355,7 +365,7 @@ var r = class e {
|
|
|
355
365
|
};
|
|
356
366
|
for (let t of e) r(t);
|
|
357
367
|
return n;
|
|
358
|
-
},
|
|
368
|
+
}, Oe = (e, ...t) => {
|
|
359
369
|
if (t.length === 0) throw Error(`jsonIndex("${e}"): at least one path segment is required`);
|
|
360
370
|
let n = (r) => ({
|
|
361
371
|
jsonPath: {
|
|
@@ -366,14 +376,14 @@ var r = class e {
|
|
|
366
376
|
numeric: () => n(!0)
|
|
367
377
|
});
|
|
368
378
|
return n(!1);
|
|
369
|
-
},
|
|
379
|
+
}, ke = (e = "cosine", t = "float32") => {
|
|
370
380
|
let n = t === "half" ? "halfvec" : "vector";
|
|
371
381
|
switch (e) {
|
|
372
382
|
case "cosine": return `${n}_cosine_ops`;
|
|
373
383
|
case "l2": return `${n}_l2_ops`;
|
|
374
384
|
case "inner": return `${n}_ip_ops`;
|
|
375
385
|
}
|
|
376
|
-
},
|
|
386
|
+
}, Ae = [
|
|
377
387
|
"id",
|
|
378
388
|
"tenantId",
|
|
379
389
|
"createdAt",
|
|
@@ -382,7 +392,7 @@ var r = class e {
|
|
|
382
392
|
"updatedBy",
|
|
383
393
|
"deletedAt",
|
|
384
394
|
"deletedBy"
|
|
385
|
-
], L = (e) => e.id ?? `<anonymous mixin: ${Object.keys(e.fields).join(", ")}>`, R = (e, t) => `${e}_${t.join("_")}_idx`,
|
|
395
|
+
], L = (e) => e.id ?? `<anonymous mixin: ${Object.keys(e.fields).join(", ")}>`, R = (e, t) => `${e}_${t.join("_")}_idx`, je = (e, t) => `${e}_${t.join("_")}_uq`, z = (e, t, n, r, i) => {
|
|
386
396
|
if (n !== "hnsw") return;
|
|
387
397
|
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.`);
|
|
388
398
|
let a = r[0];
|
|
@@ -390,7 +400,7 @@ var r = class e {
|
|
|
390
400
|
let o = i[a];
|
|
391
401
|
if (o === void 0) throw Error(`hnsw index '${t}' on table '${e}' references unknown column '${a}'.`);
|
|
392
402
|
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.`);
|
|
393
|
-
},
|
|
403
|
+
}, Me = (e, t) => {
|
|
394
404
|
let n;
|
|
395
405
|
for (let [r, i] of Object.entries(e)) i.type === "id" && i.idScheme === void 0 && (n === void 0 && (n = { ...e }), n[r] = {
|
|
396
406
|
...i,
|
|
@@ -413,7 +423,7 @@ var r = class e {
|
|
|
413
423
|
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema },
|
|
414
424
|
fullTextIndex: ((t, n, r) => {
|
|
415
425
|
if (n.length === 0) throw Error(`fullTextIndex '${t}' on '${e.tableName}' has no columns.`);
|
|
416
|
-
if (
|
|
426
|
+
if (b(e.tableName, t, !1, n), e.appliedFullText.some((e) => e.name === t)) throw Error(`duplicate full-text index '${t}' on table '${e.tableName}'.`);
|
|
417
427
|
return B({
|
|
418
428
|
tableName: e.tableName,
|
|
419
429
|
fields: e.fields,
|
|
@@ -442,12 +452,12 @@ var r = class e {
|
|
|
442
452
|
for (let t of n) for (let [n, a] of Object.entries(t.fields)) {
|
|
443
453
|
let o = i.get(n);
|
|
444
454
|
if (o !== void 0) throw Error(`mixin collision on column '${n}' in table '${e.tableName}': '${L(o)}' and '${L(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.`);
|
|
445
|
-
|
|
455
|
+
y(e.tableName, n), r[n] = a, i.set(n, t);
|
|
446
456
|
}
|
|
447
457
|
let a = [...e.appliedIndexes];
|
|
448
458
|
for (let t of n) for (let n of t.indexes ?? []) {
|
|
449
459
|
let t = n.name ?? R(e.tableName, n.fields);
|
|
450
|
-
a.some((e) => e.name === t) || (
|
|
460
|
+
a.some((e) => e.name === t) || (b(e.tableName, t, n.name === void 0, n.fields), z(e.tableName, t, n.kind, n.fields, r), a.push({
|
|
451
461
|
name: t,
|
|
452
462
|
fields: n.fields,
|
|
453
463
|
...n.kind === void 0 ? {} : { kind: n.kind },
|
|
@@ -472,7 +482,7 @@ var r = class e {
|
|
|
472
482
|
let n, r, i, a = Array.isArray(t[0]);
|
|
473
483
|
if (a ? (r = t[0], i = t[1], n = R(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.`);
|
|
474
484
|
let o = r.filter((e) => typeof e == "string");
|
|
475
|
-
if (
|
|
485
|
+
if (b(e.tableName, n, a, o), z(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.`);
|
|
476
486
|
return B({
|
|
477
487
|
tableName: e.tableName,
|
|
478
488
|
fields: e.fields,
|
|
@@ -496,7 +506,7 @@ var r = class e {
|
|
|
496
506
|
expressionIndex: ((t, n, r) => {
|
|
497
507
|
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.`);
|
|
498
508
|
let i = n.filter((e) => typeof e == "string");
|
|
499
|
-
if (
|
|
509
|
+
if (b(e.tableName, t, !1, i), z(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.`);
|
|
500
510
|
return B({
|
|
501
511
|
tableName: e.tableName,
|
|
502
512
|
fields: e.fields,
|
|
@@ -519,8 +529,8 @@ var r = class e {
|
|
|
519
529
|
}),
|
|
520
530
|
unique: ((...t) => {
|
|
521
531
|
let n, r, i, a = Array.isArray(t[0]);
|
|
522
|
-
if (a ? (r = t[0], i = t[1], n =
|
|
523
|
-
if (
|
|
532
|
+
if (a ? (r = t[0], i = t[1], n = je(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.`);
|
|
533
|
+
if (b(e.tableName, n, a, r), e.appliedUniques.some((e) => e.name === n)) throw Error(a ? `duplicate auto-named UNIQUE '${n}' on table '${e.tableName}' — you've called .unique(${JSON.stringify(r)}) twice. Pass an explicit name to the second one if both are intended (very rare).` : `duplicate UNIQUE '${n}' on table '${e.tableName}': each constraint name must be unique within a table.`);
|
|
524
534
|
return B({
|
|
525
535
|
tableName: e.tableName,
|
|
526
536
|
fields: e.fields,
|
|
@@ -542,7 +552,7 @@ var r = class e {
|
|
|
542
552
|
uniqueActive: ((...t) => {
|
|
543
553
|
let n, r, i, a = Array.isArray(t[0]);
|
|
544
554
|
if (a ? (r = t[0], i = t[1], n = R(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.`);
|
|
545
|
-
if (
|
|
555
|
+
if (b(e.tableName, n, a, r), e.appliedIndexes.some((e) => e.name === n)) throw Error(`duplicate index '${n}' on table '${e.tableName}': each index name must be unique within a table (uniqueActive shares the index namespace).`);
|
|
546
556
|
let o = i?.where ?? "\"deletedAt\" IS NULL";
|
|
547
557
|
return B({
|
|
548
558
|
tableName: e.tableName,
|
|
@@ -565,7 +575,7 @@ var r = class e {
|
|
|
565
575
|
}),
|
|
566
576
|
check: ((t, n) => {
|
|
567
577
|
if (n.trim().length === 0) throw Error(`CHECK '${t}' on table '${e.tableName}' has an empty expression.`);
|
|
568
|
-
if (
|
|
578
|
+
if (b(e.tableName, t, !1, []), e.appliedChecks.some((e) => e.name === t)) throw Error(`duplicate CHECK '${t}' on table '${e.tableName}': each constraint name must be unique within a table.`);
|
|
569
579
|
return B({
|
|
570
580
|
tableName: e.tableName,
|
|
571
581
|
fields: e.fields,
|
|
@@ -647,10 +657,10 @@ var r = class e {
|
|
|
647
657
|
validatePatchSchema: n.partial(t)
|
|
648
658
|
}))
|
|
649
659
|
};
|
|
650
|
-
},
|
|
651
|
-
|
|
652
|
-
let n =
|
|
653
|
-
for (let t of Object.keys(n))
|
|
660
|
+
}, Ne = (e, t) => {
|
|
661
|
+
v(e);
|
|
662
|
+
let n = Me(u(t), e);
|
|
663
|
+
for (let t of Object.keys(n)) y(e, t);
|
|
654
664
|
return B({
|
|
655
665
|
tableName: e,
|
|
656
666
|
fields: n,
|
|
@@ -661,7 +671,7 @@ var r = class e {
|
|
|
661
671
|
appliedFullText: [],
|
|
662
672
|
appliedChecks: []
|
|
663
673
|
});
|
|
664
|
-
},
|
|
674
|
+
}, Pe = (e) => e === "sqlite" || e === "turso", V = (e, t) => {
|
|
665
675
|
switch (t) {
|
|
666
676
|
case "mysql":
|
|
667
677
|
case "mariadb": return `\`${e}\``;
|
|
@@ -677,38 +687,38 @@ var r = class e {
|
|
|
677
687
|
return;
|
|
678
688
|
}
|
|
679
689
|
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.`);
|
|
680
|
-
},
|
|
690
|
+
}, Fe = (e) => {
|
|
681
691
|
W.get(e.tableName) === void 0 && W.set(e.tableName, e);
|
|
682
|
-
},
|
|
692
|
+
}, K = (e) => W.get(e), Ie = (e) => {
|
|
683
693
|
let t = W.get(e);
|
|
684
694
|
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.`);
|
|
685
695
|
return t;
|
|
686
|
-
},
|
|
696
|
+
}, q = () => [...W.values()], Le = () => {
|
|
687
697
|
W.clear();
|
|
688
|
-
},
|
|
698
|
+
}, Re = (e) => ({
|
|
689
699
|
op: "count",
|
|
690
700
|
alias: e ?? "count"
|
|
691
|
-
}),
|
|
701
|
+
}), ze = (e, t) => ({
|
|
692
702
|
op: "count-distinct",
|
|
693
703
|
column: e,
|
|
694
704
|
alias: t ?? `count_distinct_${e}`
|
|
695
|
-
}),
|
|
705
|
+
}), Be = (e, t) => ({
|
|
696
706
|
op: "sum",
|
|
697
707
|
column: e,
|
|
698
708
|
alias: t ?? `sum_${e}`
|
|
699
|
-
}),
|
|
709
|
+
}), Ve = (e, t) => ({
|
|
700
710
|
op: "avg",
|
|
701
711
|
column: e,
|
|
702
712
|
alias: t ?? `avg_${e}`
|
|
703
|
-
}),
|
|
713
|
+
}), He = (e, t) => ({
|
|
704
714
|
op: "min",
|
|
705
715
|
column: e,
|
|
706
716
|
alias: t ?? `min_${e}`
|
|
707
|
-
}),
|
|
717
|
+
}), Ue = (e, t) => ({
|
|
708
718
|
op: "max",
|
|
709
719
|
column: e,
|
|
710
720
|
alias: t ?? `max_${e}`
|
|
711
|
-
}),
|
|
721
|
+
}), We = (e, t) => ({
|
|
712
722
|
op: "column",
|
|
713
723
|
column: e,
|
|
714
724
|
alias: t ?? e
|
|
@@ -726,38 +736,38 @@ var r = class e {
|
|
|
726
736
|
queries: t.map((e) => e.descriptor)
|
|
727
737
|
}
|
|
728
738
|
});
|
|
729
|
-
},
|
|
739
|
+
}, Ge = J("union"), Ke = J("union-all"), qe = J("intersect"), Je = J("except"), Y = (e) => ({ over: (t) => ({
|
|
730
740
|
...e,
|
|
731
741
|
window: t
|
|
732
|
-
}) }),
|
|
742
|
+
}) }), Ye = (e = "rowNumber") => Y({
|
|
733
743
|
op: "window-row-number",
|
|
734
744
|
alias: e
|
|
735
|
-
}),
|
|
745
|
+
}), Xe = (e = "rank") => Y({
|
|
736
746
|
op: "window-rank",
|
|
737
747
|
alias: e
|
|
738
|
-
}),
|
|
748
|
+
}), Ze = (e = "denseRank") => Y({
|
|
739
749
|
op: "window-dense-rank",
|
|
740
750
|
alias: e
|
|
741
|
-
}),
|
|
751
|
+
}), Qe = (e, t = 1, n) => Y({
|
|
742
752
|
op: "window-lag",
|
|
743
753
|
column: e,
|
|
744
754
|
alias: n ?? `lag_${e}`,
|
|
745
755
|
offset: t
|
|
746
|
-
}),
|
|
756
|
+
}), $e = (e, t = 1, n) => Y({
|
|
747
757
|
op: "window-lead",
|
|
748
758
|
column: e,
|
|
749
759
|
alias: n ?? `lead_${e}`,
|
|
750
760
|
offset: t
|
|
751
|
-
}),
|
|
761
|
+
}), et = (e, t) => Y({
|
|
752
762
|
op: "window-sum-over",
|
|
753
763
|
column: e,
|
|
754
764
|
alias: t ?? `sum_${e}_over`
|
|
755
|
-
}),
|
|
765
|
+
}), tt = (e, t) => Y({
|
|
756
766
|
op: "window-avg-over",
|
|
757
767
|
column: e,
|
|
758
768
|
alias: t ?? `avg_${e}_over`
|
|
759
769
|
}), X = (e, t, n) => {
|
|
760
|
-
let r = n?.find((e) => e.name === t) ??
|
|
770
|
+
let r = n?.find((e) => e.name === t) ?? K(e)?.appliedFullText?.find((e) => e.name === t);
|
|
761
771
|
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.`);
|
|
762
772
|
return {
|
|
763
773
|
columns: r.columns,
|
|
@@ -1034,7 +1044,7 @@ function Q(e) {
|
|
|
1034
1044
|
sourceTable: e
|
|
1035
1045
|
});
|
|
1036
1046
|
}
|
|
1037
|
-
var
|
|
1047
|
+
var nt = (e, t, n) => $(e, "id", t, n), $ = (e, t, n, r, i = "asc") => {
|
|
1038
1048
|
let a = [...e.order.filter((e) => e.column !== t), {
|
|
1039
1049
|
column: t,
|
|
1040
1050
|
direction: i
|
|
@@ -1049,21 +1059,21 @@ var tt = (e, t, n) => $(e, "id", t, n), $ = (e, t, n, r, i = "asc") => {
|
|
|
1049
1059
|
order: a,
|
|
1050
1060
|
take: r
|
|
1051
1061
|
};
|
|
1052
|
-
},
|
|
1062
|
+
}, rt = (e) => {
|
|
1053
1063
|
let t = {};
|
|
1054
1064
|
for (let [n, r] of Object.entries(e)) G(r), t[n] = Q(r);
|
|
1055
1065
|
return t;
|
|
1056
|
-
},
|
|
1057
|
-
if (
|
|
1066
|
+
}, it = (e) => e.isView === !0, at = (e, t, n) => {
|
|
1067
|
+
if (v(e), n.trim().length === 0) throw Error(`view('${e}', …): the SELECT body is empty — a view must define a query.`);
|
|
1058
1068
|
let r = u(t);
|
|
1059
|
-
for (let t of Object.keys(r))
|
|
1069
|
+
for (let t of Object.keys(r)) y(e, t);
|
|
1060
1070
|
return {
|
|
1061
1071
|
tableName: e,
|
|
1062
1072
|
fields: r,
|
|
1063
1073
|
isView: !0,
|
|
1064
1074
|
viewSelect: n
|
|
1065
1075
|
};
|
|
1066
|
-
},
|
|
1076
|
+
}, ot = (e) => Q({
|
|
1067
1077
|
...e,
|
|
1068
1078
|
isReactive: !1,
|
|
1069
1079
|
appliedMixins: [],
|
|
@@ -1071,7 +1081,7 @@ var tt = (e, t, n) => $(e, "id", t, n), $ = (e, t, n, r, i = "asc") => {
|
|
|
1071
1081
|
appliedUniques: [],
|
|
1072
1082
|
appliedFullText: [],
|
|
1073
1083
|
appliedChecks: []
|
|
1074
|
-
}),
|
|
1084
|
+
}), st = (e, t, n = null) => {
|
|
1075
1085
|
let r = n === null ? V(e.tableName, t) : `${V(n, t)}.${V(e.tableName, t)}`, i = e.viewSelect.trim();
|
|
1076
1086
|
switch (t) {
|
|
1077
1087
|
case "postgres":
|
|
@@ -1081,16 +1091,16 @@ var tt = (e, t, n) => $(e, "id", t, n), $ = (e, t, n, r, i = "asc") => {
|
|
|
1081
1091
|
case "sqlite":
|
|
1082
1092
|
case "turso": return `DROP VIEW IF EXISTS ${r};\nCREATE VIEW ${r} AS ${i};`;
|
|
1083
1093
|
}
|
|
1084
|
-
},
|
|
1094
|
+
}, ct = /^[A-Za-z_][A-Za-z0-9_]*$/, lt = (e) => "$" + e.map((e) => typeof e == "number" ? `[${e}]` : ct.test(e) ? `.${e}` : `."${e.replace(/"/g, "\\\"")}"`).join(""), ut = (e) => "{" + e.map((e) => {
|
|
1085
1095
|
let t = String(e);
|
|
1086
1096
|
return /^[A-Za-z0-9_]+$/.test(t) ? t : `"${t.replace(/(["\\])/g, "\\$1")}"`;
|
|
1087
|
-
}).join(",") + "}",
|
|
1097
|
+
}).join(",") + "}", dt = (e, t, n, r = {}) => {
|
|
1088
1098
|
let i = V(e, n), a = r.numeric ?? !1;
|
|
1089
1099
|
if (n === "postgres") {
|
|
1090
|
-
let e = `(${i} #>> '${
|
|
1100
|
+
let e = `(${i} #>> '${ut(t)}'::text[])`;
|
|
1091
1101
|
return a ? `${e}::numeric` : e;
|
|
1092
1102
|
}
|
|
1093
|
-
let o =
|
|
1103
|
+
let o = lt(t);
|
|
1094
1104
|
switch (n) {
|
|
1095
1105
|
case "mysql":
|
|
1096
1106
|
case "mariadb": {
|
|
@@ -1107,10 +1117,10 @@ var tt = (e, t, n) => $(e, "id", t, n), $ = (e, t, n, r, i = "asc") => {
|
|
|
1107
1117
|
return a ? `CAST(${e} AS REAL)` : e;
|
|
1108
1118
|
}
|
|
1109
1119
|
}
|
|
1110
|
-
},
|
|
1120
|
+
}, ft = (e) => {
|
|
1111
1121
|
if (!e.id || e.id.length === 0) throw Error("migration: `id` is required + must be non-empty");
|
|
1112
1122
|
if (!e.up || !e.down) throw Error(`migration ${e.id}: both \`up\` and \`down\` must be functions`);
|
|
1113
1123
|
return e;
|
|
1114
|
-
},
|
|
1124
|
+
}, pt = /^\d{8}_\d{6}_[a-z0-9_]+\.ts$/, mt = (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";
|
|
1115
1125
|
//#endregion
|
|
1116
|
-
export {
|
|
1126
|
+
export { m as $, Ge as A, s as At, Ae as B, nt as C, se as Ct, Ye as D, te as Dt, X as E, ge as Et, K as F, F as G, Ne as H, G as I, Ee as J, I as K, Ie as L, q as M, de as Mt, Le as N, Be as O, le as Ot, Fe as P, p as Q, Pe as R, $ as S, pe as St, Xe as T, ne as Tt, ke as U, Oe as V, De as W, M as X, P as Y, we as Z, qe as _, ue as _t, it as a, ye as at, Ue as b, o as bt, st as c, ve as ct, We as d, re as dt, be as et, Re as f, ae as ft, Je as g, c as gt, Ze as h, ie as ht, dt as i, x as it, Ke as j, oe as jt, et as k, r as kt, Ve as l, i as lt, rt as m, l as mt, mt as n, b as nt, ot as o, f as ot, ze as p, ce as pt, N as q, ft as r, v as rt, at as s, _e as st, pt as t, y as tt, tt as u, fe as ut, Qe as v, me as vt, Q as w, u as wt, He as x, ee as xt, $e as y, he as yt, V as z };
|