@voltro/database 0.1.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 +52 -0
- package/LICENSE +57 -0
- package/README.md +26 -0
- package/SECURITY.md +56 -0
- package/THIRD-PARTY-NOTICES.md +319 -0
- package/dist/fileBased-cc9IzIjU.js +1083 -0
- package/dist/index.d.ts +5107 -0
- package/dist/index.js +1505 -0
- package/dist/sql.d.ts +2023 -0
- package/dist/sql.js +2569 -0
- package/package.json +51 -0
|
@@ -0,0 +1,1083 @@
|
|
|
1
|
+
import { typeid as e } from "typeid-js";
|
|
2
|
+
import { ulid as t } from "ulidx";
|
|
3
|
+
import { Schema as n } from "effect";
|
|
4
|
+
//#region src/columns.ts
|
|
5
|
+
var r = class e {
|
|
6
|
+
definition;
|
|
7
|
+
constructor(e) {
|
|
8
|
+
this.definition = e;
|
|
9
|
+
}
|
|
10
|
+
rejectIfRaw(e) {
|
|
11
|
+
if (this.definition.type === "raw") throw Error(`raw(...) column rejects .${e}() — the DDL fragment is the single source of truth for type/nullability/default. Encode ${e === "nullable" ? "NULL" : e === "unique" ? "UNIQUE" : "DEFAULT"} directly in the raw fragment instead.`);
|
|
12
|
+
}
|
|
13
|
+
nullable() {
|
|
14
|
+
return this.rejectIfRaw("nullable"), new e({
|
|
15
|
+
...this.definition,
|
|
16
|
+
nullable: !0
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
encrypted() {
|
|
20
|
+
return this.rejectIfRaw("encrypted"), new e({
|
|
21
|
+
...this.definition,
|
|
22
|
+
encrypted: !0
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
sensitive(t) {
|
|
26
|
+
return new e({
|
|
27
|
+
...this.definition,
|
|
28
|
+
sensitive: { class: t }
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
safe() {
|
|
32
|
+
return new e({
|
|
33
|
+
...this.definition,
|
|
34
|
+
safe: !0
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
unique(t) {
|
|
38
|
+
return this.rejectIfRaw("unique"), t?.dedup === void 0 ? new e({
|
|
39
|
+
...this.definition,
|
|
40
|
+
unique: !0
|
|
41
|
+
}) : new e({
|
|
42
|
+
...this.definition,
|
|
43
|
+
unique: !0,
|
|
44
|
+
uniqueSpec: { dedup: t.dedup }
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
default(t) {
|
|
48
|
+
return this.rejectIfRaw("default"), typeof t == "function" ? new e({
|
|
49
|
+
...this.definition,
|
|
50
|
+
hasDefault: !0,
|
|
51
|
+
defaultFactory: t
|
|
52
|
+
}) : new e({
|
|
53
|
+
...this.definition,
|
|
54
|
+
hasDefault: !0,
|
|
55
|
+
defaultValue: t
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
computed(t) {
|
|
59
|
+
return new e({
|
|
60
|
+
...this.definition,
|
|
61
|
+
computed: t
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
onUpdate(t) {
|
|
65
|
+
return new e({
|
|
66
|
+
...this.definition,
|
|
67
|
+
onUpdate: t
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
generatedAs(t, n) {
|
|
71
|
+
return new e({
|
|
72
|
+
...this.definition,
|
|
73
|
+
generatedAs: {
|
|
74
|
+
expr: t,
|
|
75
|
+
stored: n?.stored ?? !1
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
backfill(t, n) {
|
|
80
|
+
let r = typeof t == "function" ? {
|
|
81
|
+
kind: "js",
|
|
82
|
+
fn: t,
|
|
83
|
+
...n?.batchSize === void 0 ? {} : { batchSize: n.batchSize },
|
|
84
|
+
...n?.sleepMs === void 0 ? {} : { sleepMs: n.sleepMs }
|
|
85
|
+
} : {
|
|
86
|
+
kind: "sql",
|
|
87
|
+
sql: t,
|
|
88
|
+
...n?.batchSize === void 0 ? {} : { batchSize: n.batchSize },
|
|
89
|
+
...n?.sleepMs === void 0 ? {} : { sleepMs: n.sleepMs }
|
|
90
|
+
};
|
|
91
|
+
return new e({
|
|
92
|
+
...this.definition,
|
|
93
|
+
backfill: r
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
renamedFrom(t) {
|
|
97
|
+
return new e({
|
|
98
|
+
...this.definition,
|
|
99
|
+
renamedFrom: t
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
narrowedFrom(t, n) {
|
|
103
|
+
let r = n?.using === void 0 ? { from: t } : {
|
|
104
|
+
from: t,
|
|
105
|
+
using: n.using
|
|
106
|
+
};
|
|
107
|
+
return new e({
|
|
108
|
+
...this.definition,
|
|
109
|
+
narrowedFrom: r
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
oneOf(t) {
|
|
113
|
+
return new e({
|
|
114
|
+
...this.definition,
|
|
115
|
+
oneOf: t
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
maxLength(t) {
|
|
119
|
+
return new e({
|
|
120
|
+
...this.definition,
|
|
121
|
+
maxLength: t
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
check(t) {
|
|
125
|
+
let n = this.definition.checks ? [...this.definition.checks, t] : [t];
|
|
126
|
+
return new e({
|
|
127
|
+
...this.definition,
|
|
128
|
+
checks: n
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
__definition() {
|
|
132
|
+
return this.definition;
|
|
133
|
+
}
|
|
134
|
+
}, i = (e) => new r({
|
|
135
|
+
type: e,
|
|
136
|
+
nullable: !1,
|
|
137
|
+
unique: !1,
|
|
138
|
+
hasDefault: !1
|
|
139
|
+
}), a = (e) => new r({
|
|
140
|
+
type: "id",
|
|
141
|
+
nullable: !1,
|
|
142
|
+
unique: !0,
|
|
143
|
+
hasDefault: !1,
|
|
144
|
+
idSchemeInput: e
|
|
145
|
+
}), o = () => i("text"), ee = () => i("integer"), te = () => i("real"), s = (e, t = 0) => {
|
|
146
|
+
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
|
+
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 r({
|
|
149
|
+
type: "decimal",
|
|
150
|
+
nullable: !1,
|
|
151
|
+
unique: !1,
|
|
152
|
+
hasDefault: !1,
|
|
153
|
+
precision: e,
|
|
154
|
+
scale: t
|
|
155
|
+
});
|
|
156
|
+
}, ne = s, re = () => i("bigint"), ie = (e, t) => {
|
|
157
|
+
if (t.length === 0) throw Error(`dbEnum('${e}', []): enum must have at least one value`);
|
|
158
|
+
return {
|
|
159
|
+
name: e,
|
|
160
|
+
values: t,
|
|
161
|
+
column: () => new r({
|
|
162
|
+
type: "enum",
|
|
163
|
+
nullable: !1,
|
|
164
|
+
unique: !1,
|
|
165
|
+
hasDefault: !1,
|
|
166
|
+
enumName: e,
|
|
167
|
+
enumValues: t
|
|
168
|
+
})
|
|
169
|
+
};
|
|
170
|
+
}, ae = () => i("boolean"), oe = () => i("timestamp"), se = () => i("date"), ce = () => i("json"), c = () => i("bytes"), l = (e, t) => new r({
|
|
171
|
+
type: "reference",
|
|
172
|
+
nullable: !1,
|
|
173
|
+
unique: !1,
|
|
174
|
+
hasDefault: !1,
|
|
175
|
+
references: e,
|
|
176
|
+
onDelete: t?.onDelete ?? "restrict",
|
|
177
|
+
refOnUpdate: t?.onUpdate ?? "noAction",
|
|
178
|
+
fkAutoIndex: t?.index ?? !0,
|
|
179
|
+
...t?.orphanPolicy ? { orphanPolicy: t.orphanPolicy } : {}
|
|
180
|
+
}), u = () => new r({
|
|
181
|
+
type: "text",
|
|
182
|
+
nullable: !0,
|
|
183
|
+
unique: !1,
|
|
184
|
+
hasDefault: !1,
|
|
185
|
+
dropped: !0
|
|
186
|
+
}), d = (e, t) => {
|
|
187
|
+
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 r({
|
|
189
|
+
type: "vector",
|
|
190
|
+
nullable: !1,
|
|
191
|
+
unique: !1,
|
|
192
|
+
hasDefault: !1,
|
|
193
|
+
vectorDim: e,
|
|
194
|
+
vectorPrecision: t?.precision ?? "float32"
|
|
195
|
+
});
|
|
196
|
+
}, le = (e) => new r({
|
|
197
|
+
type: "array",
|
|
198
|
+
nullable: !1,
|
|
199
|
+
unique: !1,
|
|
200
|
+
hasDefault: !1,
|
|
201
|
+
arrayElement: e.__definition().type
|
|
202
|
+
}), ue = () => i("interval"), de = (e, t = 4326) => new r({
|
|
203
|
+
type: "text",
|
|
204
|
+
nullable: !1,
|
|
205
|
+
unique: !1,
|
|
206
|
+
hasDefault: !1,
|
|
207
|
+
spatial: {
|
|
208
|
+
kind: "geography",
|
|
209
|
+
geomKind: e,
|
|
210
|
+
srid: t
|
|
211
|
+
}
|
|
212
|
+
}), fe = (e, t = 4326) => new r({
|
|
213
|
+
type: "text",
|
|
214
|
+
nullable: !1,
|
|
215
|
+
unique: !1,
|
|
216
|
+
hasDefault: !1,
|
|
217
|
+
spatial: {
|
|
218
|
+
kind: "geometry",
|
|
219
|
+
geomKind: e,
|
|
220
|
+
srid: t
|
|
221
|
+
}
|
|
222
|
+
}), pe = (e) => new r({
|
|
223
|
+
type: "raw",
|
|
224
|
+
nullable: !1,
|
|
225
|
+
unique: !1,
|
|
226
|
+
hasDefault: !1,
|
|
227
|
+
rawDdl: e
|
|
228
|
+
}), f = (e) => {
|
|
229
|
+
let t = {};
|
|
230
|
+
for (let [n, r] of Object.entries(e)) t[n] = r.__definition();
|
|
231
|
+
return t;
|
|
232
|
+
}, p = /* @__PURE__ */ new Map(), me = (e, t) => {
|
|
233
|
+
if (t.from === t.to) throw Error(`declareEnumRename('${e}'): \`from\` and \`to\` are both '${t.from}' — a rename must change the value.`);
|
|
234
|
+
let n = p.get(e) ?? [];
|
|
235
|
+
for (let r of n) {
|
|
236
|
+
if (r.from === t.from && r.to === t.to) return;
|
|
237
|
+
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
|
+
}
|
|
239
|
+
n.push(t), p.set(e, n);
|
|
240
|
+
}, he = (e) => p.get(e) ?? [], ge = () => p, _e = () => {
|
|
241
|
+
p.clear();
|
|
242
|
+
}, ve = 63, ye = 60, m = [], h = (e) => {
|
|
243
|
+
m.includes(e) || m.push(e);
|
|
244
|
+
}, be = () => {
|
|
245
|
+
let e = m.slice();
|
|
246
|
+
return m.length = 0, e;
|
|
247
|
+
}, xe = /^[a-zA-Z_][a-zA-Z0-9_]*$/, g = (e, t) => {
|
|
248
|
+
if (t.length === 0) throw Error(`${e} cannot be empty.`);
|
|
249
|
+
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
|
+
}, _ = (e) => {
|
|
251
|
+
if (g("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.`);
|
|
252
|
+
e.length > 60 && h(`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.`);
|
|
253
|
+
}, v = (e, t) => {
|
|
254
|
+
if (g("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.`);
|
|
255
|
+
t.length > 60 && h(`column '${t}' on table '${e}' is ${t.length} chars — close to the 63-byte limit.`);
|
|
256
|
+
}, y = (e, t, n, r) => {
|
|
257
|
+
if (g("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.`);
|
|
258
|
+
t.length > 60 && h(`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.` : ""}`);
|
|
259
|
+
}, b = (e, t) => {
|
|
260
|
+
if (e.length === 0) throw Error(`typeid prefix on table '${t.tableName}' cannot be empty.`);
|
|
261
|
+
if (!/^[a-z][a-z0-9_]*$/.test(e)) {
|
|
262
|
+
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_]*$/.";
|
|
263
|
+
throw Error(`typeid prefix '${e}' on table '${t.tableName}' is invalid — ${n}`);
|
|
264
|
+
}
|
|
265
|
+
if (e.length > 63) {
|
|
266
|
+
let n = t.kind === "derived" ? "shorten the table name, or supply an explicit short prefix via id({ prefix: '...' })." : "pick a shorter prefix.";
|
|
267
|
+
throw Error(`typeid prefix '${e}' on table '${t.tableName}' is ${e.length} chars — exceeds the 63-byte limit; ${n}`);
|
|
268
|
+
}
|
|
269
|
+
e.length > 60 && h(`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).`);
|
|
270
|
+
}, Se = 1704067200000n, x = 10n, S = 12n, C = (1n << x) - 1n, w = (1n << S) - 1n, T = S, E = 22n, D = () => {
|
|
271
|
+
let e = process.env.SNOWFLAKE_MACHINE_ID;
|
|
272
|
+
if (e === void 0 || e === "") return 0n;
|
|
273
|
+
let t = BigInt(e);
|
|
274
|
+
if (t < 0n || t > C) throw Error(`SNOWFLAKE_MACHINE_ID out of range: ${e}. Must be 0..${C}.`);
|
|
275
|
+
return t;
|
|
276
|
+
}, O = () => ({
|
|
277
|
+
lastMs: 0n,
|
|
278
|
+
sequence: 0n,
|
|
279
|
+
machineId: D()
|
|
280
|
+
}), k, A = () => (k === void 0 && (k = O()), k), j = () => {
|
|
281
|
+
k = O();
|
|
282
|
+
}, M = () => BigInt(Date.now()), Ce = (e) => {
|
|
283
|
+
let t = M();
|
|
284
|
+
for (; t <= e;) t = M();
|
|
285
|
+
return t;
|
|
286
|
+
}, N = () => {
|
|
287
|
+
let e = A(), t = M();
|
|
288
|
+
t === e.lastMs ? (e.sequence = e.sequence + 1n & w, e.sequence === 0n && (t = Ce(e.lastMs), e.lastMs = t)) : (e.sequence = 0n, e.lastMs = t);
|
|
289
|
+
let n = t - Se;
|
|
290
|
+
if (n < 0n) throw Error("Snowflake timestamp before configured epoch (2024-01-01). System clock is wrong.");
|
|
291
|
+
return (n << E | e.machineId << T | e.sequence).toString();
|
|
292
|
+
}, P = (e) => {
|
|
293
|
+
let t = e.toLowerCase();
|
|
294
|
+
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
|
+
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
|
+
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 b(n, {
|
|
298
|
+
kind: "derived",
|
|
299
|
+
tableName: e
|
|
300
|
+
}), n;
|
|
301
|
+
}, F = (e, t) => {
|
|
302
|
+
if (e === void 0) return {
|
|
303
|
+
kind: "typeid",
|
|
304
|
+
prefix: P(t)
|
|
305
|
+
};
|
|
306
|
+
if ("prefix" in e && !("scheme" in e)) return b(e.prefix, {
|
|
307
|
+
kind: "explicit",
|
|
308
|
+
tableName: t
|
|
309
|
+
}), {
|
|
310
|
+
kind: "typeid",
|
|
311
|
+
prefix: e.prefix
|
|
312
|
+
};
|
|
313
|
+
if (!("scheme" in e)) throw Error("invalid id() options: no scheme or prefix");
|
|
314
|
+
switch (e.scheme) {
|
|
315
|
+
case "typeid": {
|
|
316
|
+
let n = e.prefix ?? P(t);
|
|
317
|
+
return e.prefix !== void 0 && b(e.prefix, {
|
|
318
|
+
kind: "explicit",
|
|
319
|
+
tableName: t
|
|
320
|
+
}), {
|
|
321
|
+
kind: "typeid",
|
|
322
|
+
prefix: n
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
case "ulid": return { kind: "ulid" };
|
|
326
|
+
case "numeric": return { kind: "numeric" };
|
|
327
|
+
case "snowflake": return { kind: "snowflake" };
|
|
328
|
+
case "custom": return {
|
|
329
|
+
kind: "custom",
|
|
330
|
+
generate: e.generate
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
}, we = (n, r) => {
|
|
334
|
+
switch (n.kind) {
|
|
335
|
+
case "typeid": return e(n.prefix).toString();
|
|
336
|
+
case "ulid": return t();
|
|
337
|
+
case "numeric": return null;
|
|
338
|
+
case "snowflake": return N();
|
|
339
|
+
case "custom": return n.generate(r);
|
|
340
|
+
}
|
|
341
|
+
}, I = (e) => ({
|
|
342
|
+
fields: f(e.fields),
|
|
343
|
+
...e.id === void 0 ? {} : { id: e.id },
|
|
344
|
+
...e.requires === void 0 ? {} : { requires: e.requires },
|
|
345
|
+
...e.indexes === void 0 ? {} : { indexes: e.indexes },
|
|
346
|
+
...e.behaviors === void 0 ? {} : { behaviors: e.behaviors },
|
|
347
|
+
...e.policies === void 0 ? {} : { policies: e.policies }
|
|
348
|
+
}), Te = I, L = (e) => {
|
|
349
|
+
let t = /* @__PURE__ */ new Set(), n = [], r = (e) => {
|
|
350
|
+
let i = e.id ?? e;
|
|
351
|
+
if (!t.has(i)) {
|
|
352
|
+
if (t.add(i), e.requires !== void 0) for (let t of e.requires) r(t);
|
|
353
|
+
n.push(e);
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
for (let t of e) r(t);
|
|
357
|
+
return n;
|
|
358
|
+
}, Ee = (e, ...t) => {
|
|
359
|
+
if (t.length === 0) throw Error(`jsonIndex("${e}"): at least one path segment is required`);
|
|
360
|
+
let n = (r) => ({
|
|
361
|
+
jsonPath: {
|
|
362
|
+
column: e,
|
|
363
|
+
path: t,
|
|
364
|
+
numeric: r
|
|
365
|
+
},
|
|
366
|
+
numeric: () => n(!0)
|
|
367
|
+
});
|
|
368
|
+
return n(!1);
|
|
369
|
+
}, De = (e = "cosine", t = "float32") => {
|
|
370
|
+
let n = t === "half" ? "halfvec" : "vector";
|
|
371
|
+
switch (e) {
|
|
372
|
+
case "cosine": return `${n}_cosine_ops`;
|
|
373
|
+
case "l2": return `${n}_l2_ops`;
|
|
374
|
+
case "inner": return `${n}_ip_ops`;
|
|
375
|
+
}
|
|
376
|
+
}, R = (e) => e.id ?? `<anonymous mixin: ${Object.keys(e.fields).join(", ")}>`, z = (e, t) => `${e}_${t.join("_")}_idx`, Oe = (e, t) => `${e}_${t.join("_")}_uq`, B = (e, t, n, r, i) => {
|
|
377
|
+
if (n !== "hnsw") return;
|
|
378
|
+
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.`);
|
|
379
|
+
let a = r[0];
|
|
380
|
+
if (typeof a != "string") throw Error(`hnsw index '${t}' on table '${e}' must reference a vector COLUMN, not an expression. pgvector's HNSW access method indexes a column directly.`);
|
|
381
|
+
let o = i[a];
|
|
382
|
+
if (o === void 0) throw Error(`hnsw index '${t}' on table '${e}' references unknown column '${a}'.`);
|
|
383
|
+
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.`);
|
|
384
|
+
}, ke = (e, t) => {
|
|
385
|
+
let n;
|
|
386
|
+
for (let [r, i] of Object.entries(e)) i.type === "id" && i.idScheme === void 0 && (n === void 0 && (n = { ...e }), n[r] = {
|
|
387
|
+
...i,
|
|
388
|
+
idScheme: F(i.idSchemeInput, t)
|
|
389
|
+
});
|
|
390
|
+
return n ?? e;
|
|
391
|
+
}, V = (e) => {
|
|
392
|
+
let t = e.appliedPrimaryKey ?? [];
|
|
393
|
+
return {
|
|
394
|
+
tableName: e.tableName,
|
|
395
|
+
fields: e.fields,
|
|
396
|
+
isReactive: e.isReactive,
|
|
397
|
+
appliedMixins: e.appliedMixins,
|
|
398
|
+
appliedIndexes: e.appliedIndexes,
|
|
399
|
+
appliedUniques: e.appliedUniques,
|
|
400
|
+
appliedFullText: e.appliedFullText,
|
|
401
|
+
appliedChecks: e.appliedChecks,
|
|
402
|
+
appliedPrimaryKey: t,
|
|
403
|
+
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
404
|
+
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema },
|
|
405
|
+
fullTextIndex: ((t, n, r) => {
|
|
406
|
+
if (n.length === 0) throw Error(`fullTextIndex '${t}' on '${e.tableName}' has no columns.`);
|
|
407
|
+
if (y(e.tableName, t, !1, n), e.appliedFullText.some((e) => e.name === t)) throw Error(`duplicate full-text index '${t}' on table '${e.tableName}'.`);
|
|
408
|
+
return V({
|
|
409
|
+
tableName: e.tableName,
|
|
410
|
+
fields: e.fields,
|
|
411
|
+
isReactive: e.isReactive,
|
|
412
|
+
appliedMixins: e.appliedMixins,
|
|
413
|
+
appliedIndexes: e.appliedIndexes,
|
|
414
|
+
appliedUniques: e.appliedUniques,
|
|
415
|
+
appliedChecks: e.appliedChecks,
|
|
416
|
+
appliedPrimaryKey: e.appliedPrimaryKey,
|
|
417
|
+
appliedFullText: [...e.appliedFullText, {
|
|
418
|
+
name: t,
|
|
419
|
+
columns: [...n],
|
|
420
|
+
...r?.config === void 0 ? {} : { config: r.config },
|
|
421
|
+
...r?.weights === void 0 ? {} : { weights: r.weights }
|
|
422
|
+
}],
|
|
423
|
+
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
424
|
+
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
425
|
+
});
|
|
426
|
+
}),
|
|
427
|
+
with: ((...t) => {
|
|
428
|
+
let n = L(t), r = { ...e.fields }, i = /* @__PURE__ */ new Map();
|
|
429
|
+
for (let e of Object.keys(r)) i.set(e, {
|
|
430
|
+
id: "<table>",
|
|
431
|
+
fields: {}
|
|
432
|
+
});
|
|
433
|
+
for (let t of n) for (let [n, a] of Object.entries(t.fields)) {
|
|
434
|
+
let o = i.get(n);
|
|
435
|
+
if (o !== void 0) throw Error(`mixin collision on column '${n}' in table '${e.tableName}': '${R(o)}' and '${R(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.`);
|
|
436
|
+
v(e.tableName, n), r[n] = a, i.set(n, t);
|
|
437
|
+
}
|
|
438
|
+
let a = [...e.appliedIndexes];
|
|
439
|
+
for (let t of n) for (let n of t.indexes ?? []) {
|
|
440
|
+
let t = n.name ?? z(e.tableName, n.fields);
|
|
441
|
+
a.some((e) => e.name === t) || (y(e.tableName, t, n.name === void 0, n.fields), B(e.tableName, t, n.kind, n.fields, r), a.push({
|
|
442
|
+
name: t,
|
|
443
|
+
fields: n.fields,
|
|
444
|
+
...n.kind === void 0 ? {} : { kind: n.kind },
|
|
445
|
+
...n.kindOptions === void 0 ? {} : { kindOptions: n.kindOptions }
|
|
446
|
+
}));
|
|
447
|
+
}
|
|
448
|
+
return V({
|
|
449
|
+
tableName: e.tableName,
|
|
450
|
+
fields: r,
|
|
451
|
+
isReactive: e.isReactive,
|
|
452
|
+
appliedMixins: [...e.appliedMixins, ...n],
|
|
453
|
+
appliedIndexes: a,
|
|
454
|
+
appliedUniques: e.appliedUniques,
|
|
455
|
+
appliedFullText: e.appliedFullText,
|
|
456
|
+
appliedChecks: e.appliedChecks,
|
|
457
|
+
appliedPrimaryKey: e.appliedPrimaryKey,
|
|
458
|
+
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
459
|
+
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
460
|
+
});
|
|
461
|
+
}),
|
|
462
|
+
index: ((...t) => {
|
|
463
|
+
let n, r, i, a = Array.isArray(t[0]);
|
|
464
|
+
if (a ? (r = t[0], i = t[1], n = z(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.`);
|
|
465
|
+
let o = r.filter((e) => typeof e == "string");
|
|
466
|
+
if (y(e.tableName, n, a, o), B(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.`);
|
|
467
|
+
return V({
|
|
468
|
+
tableName: e.tableName,
|
|
469
|
+
fields: e.fields,
|
|
470
|
+
isReactive: e.isReactive,
|
|
471
|
+
appliedMixins: e.appliedMixins,
|
|
472
|
+
appliedIndexes: [...e.appliedIndexes, {
|
|
473
|
+
name: n,
|
|
474
|
+
fields: [...r],
|
|
475
|
+
...i?.where === void 0 ? {} : { where: i.where },
|
|
476
|
+
...i?.kind === void 0 ? {} : { kind: i.kind },
|
|
477
|
+
...i?.kindOptions === void 0 ? {} : { kindOptions: i.kindOptions }
|
|
478
|
+
}],
|
|
479
|
+
appliedUniques: e.appliedUniques,
|
|
480
|
+
appliedFullText: e.appliedFullText,
|
|
481
|
+
appliedChecks: e.appliedChecks,
|
|
482
|
+
appliedPrimaryKey: e.appliedPrimaryKey,
|
|
483
|
+
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
484
|
+
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
485
|
+
});
|
|
486
|
+
}),
|
|
487
|
+
expressionIndex: ((t, n, r) => {
|
|
488
|
+
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.`);
|
|
489
|
+
let i = n.filter((e) => typeof e == "string");
|
|
490
|
+
if (y(e.tableName, t, !1, i), B(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.`);
|
|
491
|
+
return V({
|
|
492
|
+
tableName: e.tableName,
|
|
493
|
+
fields: e.fields,
|
|
494
|
+
isReactive: e.isReactive,
|
|
495
|
+
appliedMixins: e.appliedMixins,
|
|
496
|
+
appliedIndexes: [...e.appliedIndexes, {
|
|
497
|
+
name: t,
|
|
498
|
+
fields: [...n],
|
|
499
|
+
...r?.where === void 0 ? {} : { where: r.where },
|
|
500
|
+
...r?.kind === void 0 ? {} : { kind: r.kind },
|
|
501
|
+
...r?.kindOptions === void 0 ? {} : { kindOptions: r.kindOptions }
|
|
502
|
+
}],
|
|
503
|
+
appliedUniques: e.appliedUniques,
|
|
504
|
+
appliedFullText: e.appliedFullText,
|
|
505
|
+
appliedChecks: e.appliedChecks,
|
|
506
|
+
appliedPrimaryKey: e.appliedPrimaryKey,
|
|
507
|
+
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
508
|
+
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
509
|
+
});
|
|
510
|
+
}),
|
|
511
|
+
unique: ((...t) => {
|
|
512
|
+
let n, r, i, a = Array.isArray(t[0]);
|
|
513
|
+
if (a ? (r = t[0], i = t[1], n = Oe(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.`);
|
|
514
|
+
if (y(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.`);
|
|
515
|
+
return V({
|
|
516
|
+
tableName: e.tableName,
|
|
517
|
+
fields: e.fields,
|
|
518
|
+
isReactive: e.isReactive,
|
|
519
|
+
appliedMixins: e.appliedMixins,
|
|
520
|
+
appliedIndexes: e.appliedIndexes,
|
|
521
|
+
appliedUniques: [...e.appliedUniques, {
|
|
522
|
+
name: n,
|
|
523
|
+
fields: [...r],
|
|
524
|
+
...i?.dedup === void 0 ? {} : { dedup: i.dedup }
|
|
525
|
+
}],
|
|
526
|
+
appliedFullText: e.appliedFullText,
|
|
527
|
+
appliedChecks: e.appliedChecks,
|
|
528
|
+
appliedPrimaryKey: e.appliedPrimaryKey,
|
|
529
|
+
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
530
|
+
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
531
|
+
});
|
|
532
|
+
}),
|
|
533
|
+
check: ((t, n) => {
|
|
534
|
+
if (n.trim().length === 0) throw Error(`CHECK '${t}' on table '${e.tableName}' has an empty expression.`);
|
|
535
|
+
if (y(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.`);
|
|
536
|
+
return V({
|
|
537
|
+
tableName: e.tableName,
|
|
538
|
+
fields: e.fields,
|
|
539
|
+
isReactive: e.isReactive,
|
|
540
|
+
appliedMixins: e.appliedMixins,
|
|
541
|
+
appliedIndexes: e.appliedIndexes,
|
|
542
|
+
appliedUniques: e.appliedUniques,
|
|
543
|
+
appliedFullText: e.appliedFullText,
|
|
544
|
+
appliedChecks: [...e.appliedChecks, {
|
|
545
|
+
name: t,
|
|
546
|
+
expr: n
|
|
547
|
+
}],
|
|
548
|
+
appliedPrimaryKey: e.appliedPrimaryKey,
|
|
549
|
+
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
550
|
+
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
551
|
+
});
|
|
552
|
+
}),
|
|
553
|
+
primaryKey: ((n) => {
|
|
554
|
+
if (n.length < 2) throw Error(`primaryKey([...]) on table '${e.tableName}' needs at least two columns — a single-column key is the default \`id()\` primary key.`);
|
|
555
|
+
let r = /* @__PURE__ */ new Set();
|
|
556
|
+
for (let t of n) {
|
|
557
|
+
if (!(t in e.fields)) throw Error(`primaryKey([...]) on table '${e.tableName}' references unknown column '${t}'.`);
|
|
558
|
+
if (r.has(t)) throw Error(`primaryKey([...]) on table '${e.tableName}' lists column '${t}' twice.`);
|
|
559
|
+
r.add(t);
|
|
560
|
+
}
|
|
561
|
+
if (t.length > 0) throw Error(`primaryKey([...]) declared twice on table '${e.tableName}'.`);
|
|
562
|
+
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}'. A composite primary key IS the key — drop the id() column, or include '${t}' in the composite key.`);
|
|
563
|
+
return V({
|
|
564
|
+
tableName: e.tableName,
|
|
565
|
+
fields: e.fields,
|
|
566
|
+
isReactive: e.isReactive,
|
|
567
|
+
appliedMixins: e.appliedMixins,
|
|
568
|
+
appliedIndexes: e.appliedIndexes,
|
|
569
|
+
appliedUniques: e.appliedUniques,
|
|
570
|
+
appliedFullText: e.appliedFullText,
|
|
571
|
+
appliedChecks: e.appliedChecks,
|
|
572
|
+
appliedPrimaryKey: [...n],
|
|
573
|
+
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
574
|
+
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
575
|
+
});
|
|
576
|
+
}),
|
|
577
|
+
reactive: (() => V({
|
|
578
|
+
tableName: e.tableName,
|
|
579
|
+
fields: e.fields,
|
|
580
|
+
isReactive: !0,
|
|
581
|
+
appliedMixins: e.appliedMixins,
|
|
582
|
+
appliedIndexes: e.appliedIndexes,
|
|
583
|
+
appliedUniques: e.appliedUniques,
|
|
584
|
+
appliedFullText: e.appliedFullText,
|
|
585
|
+
appliedChecks: e.appliedChecks,
|
|
586
|
+
appliedPrimaryKey: e.appliedPrimaryKey,
|
|
587
|
+
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
588
|
+
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
589
|
+
})),
|
|
590
|
+
validate: ((t) => V({
|
|
591
|
+
tableName: e.tableName,
|
|
592
|
+
fields: e.fields,
|
|
593
|
+
isReactive: e.isReactive,
|
|
594
|
+
appliedMixins: e.appliedMixins,
|
|
595
|
+
appliedIndexes: e.appliedIndexes,
|
|
596
|
+
appliedUniques: e.appliedUniques,
|
|
597
|
+
appliedFullText: e.appliedFullText,
|
|
598
|
+
appliedChecks: e.appliedChecks,
|
|
599
|
+
appliedPrimaryKey: e.appliedPrimaryKey,
|
|
600
|
+
insertSchema: t,
|
|
601
|
+
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
602
|
+
})),
|
|
603
|
+
validatePatch: ((t) => V({
|
|
604
|
+
tableName: e.tableName,
|
|
605
|
+
fields: e.fields,
|
|
606
|
+
isReactive: e.isReactive,
|
|
607
|
+
appliedMixins: e.appliedMixins,
|
|
608
|
+
appliedIndexes: e.appliedIndexes,
|
|
609
|
+
appliedUniques: e.appliedUniques,
|
|
610
|
+
appliedFullText: e.appliedFullText,
|
|
611
|
+
appliedChecks: e.appliedChecks,
|
|
612
|
+
appliedPrimaryKey: e.appliedPrimaryKey,
|
|
613
|
+
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
614
|
+
validatePatchSchema: n.partial(t)
|
|
615
|
+
}))
|
|
616
|
+
};
|
|
617
|
+
}, Ae = (e, t) => {
|
|
618
|
+
_(e);
|
|
619
|
+
let n = ke(f(t), e);
|
|
620
|
+
for (let t of Object.keys(n)) v(e, t);
|
|
621
|
+
return V({
|
|
622
|
+
tableName: e,
|
|
623
|
+
fields: n,
|
|
624
|
+
isReactive: !1,
|
|
625
|
+
appliedMixins: [],
|
|
626
|
+
appliedIndexes: [],
|
|
627
|
+
appliedUniques: [],
|
|
628
|
+
appliedFullText: [],
|
|
629
|
+
appliedChecks: []
|
|
630
|
+
});
|
|
631
|
+
}, je = (e) => e === "sqlite" || e === "turso", H = (e, t) => {
|
|
632
|
+
switch (t) {
|
|
633
|
+
case "mysql":
|
|
634
|
+
case "mariadb": return `\`${e}\``;
|
|
635
|
+
case "mssql": return `[${e}]`;
|
|
636
|
+
case "postgres":
|
|
637
|
+
case "sqlite":
|
|
638
|
+
case "turso": return `"${e}"`;
|
|
639
|
+
}
|
|
640
|
+
}, U = Symbol.for("@voltro/database/tableRegistry"), W = globalThis, G = W[U] ?? (W[U] = /* @__PURE__ */ new Map()), K = (e) => {
|
|
641
|
+
let t = G.get(e.tableName);
|
|
642
|
+
if (t === void 0) {
|
|
643
|
+
G.set(e.tableName, e);
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
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.`);
|
|
647
|
+
}, Me = (e) => {
|
|
648
|
+
G.get(e.tableName) === void 0 && G.set(e.tableName, e);
|
|
649
|
+
}, q = (e) => G.get(e), Ne = (e) => {
|
|
650
|
+
let t = G.get(e);
|
|
651
|
+
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.`);
|
|
652
|
+
return t;
|
|
653
|
+
}, Pe = () => [...G.values()], Fe = () => {
|
|
654
|
+
G.clear();
|
|
655
|
+
}, Ie = (e) => ({
|
|
656
|
+
op: "count",
|
|
657
|
+
alias: e ?? "count"
|
|
658
|
+
}), Le = (e, t) => ({
|
|
659
|
+
op: "count-distinct",
|
|
660
|
+
column: e,
|
|
661
|
+
alias: t ?? `count_distinct_${e}`
|
|
662
|
+
}), Re = (e, t) => ({
|
|
663
|
+
op: "sum",
|
|
664
|
+
column: e,
|
|
665
|
+
alias: t ?? `sum_${e}`
|
|
666
|
+
}), ze = (e, t) => ({
|
|
667
|
+
op: "avg",
|
|
668
|
+
column: e,
|
|
669
|
+
alias: t ?? `avg_${e}`
|
|
670
|
+
}), Be = (e, t) => ({
|
|
671
|
+
op: "min",
|
|
672
|
+
column: e,
|
|
673
|
+
alias: t ?? `min_${e}`
|
|
674
|
+
}), Ve = (e, t) => ({
|
|
675
|
+
op: "max",
|
|
676
|
+
column: e,
|
|
677
|
+
alias: t ?? `max_${e}`
|
|
678
|
+
}), He = (e, t) => ({
|
|
679
|
+
op: "column",
|
|
680
|
+
column: e,
|
|
681
|
+
alias: t ?? e
|
|
682
|
+
}), J = (e) => (...t) => {
|
|
683
|
+
if (t.length < 2) throw Error(`${e}: requires at least two queries`);
|
|
684
|
+
return Z({
|
|
685
|
+
table: t[0].descriptor.table,
|
|
686
|
+
predicate: void 0,
|
|
687
|
+
order: [],
|
|
688
|
+
take: void 0,
|
|
689
|
+
skip: void 0,
|
|
690
|
+
projection: void 0,
|
|
691
|
+
setOp: {
|
|
692
|
+
kind: e,
|
|
693
|
+
queries: t.map((e) => e.descriptor)
|
|
694
|
+
}
|
|
695
|
+
});
|
|
696
|
+
}, Ue = J("union"), We = J("union-all"), Ge = J("intersect"), Ke = J("except"), Y = (e) => ({ over: (t) => ({
|
|
697
|
+
...e,
|
|
698
|
+
window: t
|
|
699
|
+
}) }), qe = (e = "rowNumber") => Y({
|
|
700
|
+
op: "window-row-number",
|
|
701
|
+
alias: e
|
|
702
|
+
}), Je = (e = "rank") => Y({
|
|
703
|
+
op: "window-rank",
|
|
704
|
+
alias: e
|
|
705
|
+
}), Ye = (e = "denseRank") => Y({
|
|
706
|
+
op: "window-dense-rank",
|
|
707
|
+
alias: e
|
|
708
|
+
}), Xe = (e, t = 1, n) => Y({
|
|
709
|
+
op: "window-lag",
|
|
710
|
+
column: e,
|
|
711
|
+
alias: n ?? `lag_${e}`,
|
|
712
|
+
offset: t
|
|
713
|
+
}), Ze = (e, t = 1, n) => Y({
|
|
714
|
+
op: "window-lead",
|
|
715
|
+
column: e,
|
|
716
|
+
alias: n ?? `lead_${e}`,
|
|
717
|
+
offset: t
|
|
718
|
+
}), Qe = (e, t) => Y({
|
|
719
|
+
op: "window-sum-over",
|
|
720
|
+
column: e,
|
|
721
|
+
alias: t ?? `sum_${e}_over`
|
|
722
|
+
}), $e = (e, t) => Y({
|
|
723
|
+
op: "window-avg-over",
|
|
724
|
+
column: e,
|
|
725
|
+
alias: t ?? `avg_${e}_over`
|
|
726
|
+
}), X = (e, t, n) => {
|
|
727
|
+
let r = n?.find((e) => e.name === t) ?? q(e)?.appliedFullText?.find((e) => e.name === t);
|
|
728
|
+
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.`);
|
|
729
|
+
return {
|
|
730
|
+
columns: r.columns,
|
|
731
|
+
...r.config === void 0 ? {} : { config: r.config },
|
|
732
|
+
...r.weights === void 0 ? {} : { weights: r.weights }
|
|
733
|
+
};
|
|
734
|
+
}, Z = (e) => ({
|
|
735
|
+
descriptor: e,
|
|
736
|
+
where(t) {
|
|
737
|
+
let n = e.predicate ? { and: [e.predicate, t] } : t;
|
|
738
|
+
return Z({
|
|
739
|
+
...e,
|
|
740
|
+
predicate: n
|
|
741
|
+
});
|
|
742
|
+
},
|
|
743
|
+
orderBy(t, n = "asc") {
|
|
744
|
+
return Z({
|
|
745
|
+
...e,
|
|
746
|
+
order: [...e.order, {
|
|
747
|
+
column: t,
|
|
748
|
+
direction: n
|
|
749
|
+
}]
|
|
750
|
+
});
|
|
751
|
+
},
|
|
752
|
+
limit(t) {
|
|
753
|
+
return Z({
|
|
754
|
+
...e,
|
|
755
|
+
take: t
|
|
756
|
+
});
|
|
757
|
+
},
|
|
758
|
+
offset(t) {
|
|
759
|
+
return Z({
|
|
760
|
+
...e,
|
|
761
|
+
skip: t
|
|
762
|
+
});
|
|
763
|
+
},
|
|
764
|
+
select(...t) {
|
|
765
|
+
return Z({
|
|
766
|
+
...e,
|
|
767
|
+
projection: t
|
|
768
|
+
});
|
|
769
|
+
},
|
|
770
|
+
using(t) {
|
|
771
|
+
return Z({
|
|
772
|
+
...e,
|
|
773
|
+
usingIndex: t
|
|
774
|
+
});
|
|
775
|
+
},
|
|
776
|
+
withDeleted() {
|
|
777
|
+
return Z({
|
|
778
|
+
...e,
|
|
779
|
+
includeDeleted: !0
|
|
780
|
+
});
|
|
781
|
+
},
|
|
782
|
+
unscoped() {
|
|
783
|
+
return Z({
|
|
784
|
+
...e,
|
|
785
|
+
crossTenant: !0
|
|
786
|
+
});
|
|
787
|
+
},
|
|
788
|
+
with(t) {
|
|
789
|
+
let n = {
|
|
790
|
+
...e.eager ?? {},
|
|
791
|
+
...t
|
|
792
|
+
};
|
|
793
|
+
return Z({
|
|
794
|
+
...e,
|
|
795
|
+
eager: n
|
|
796
|
+
});
|
|
797
|
+
},
|
|
798
|
+
count() {
|
|
799
|
+
return Z({
|
|
800
|
+
...e,
|
|
801
|
+
projection: void 0,
|
|
802
|
+
aggregations: [{
|
|
803
|
+
op: "count",
|
|
804
|
+
alias: "count"
|
|
805
|
+
}]
|
|
806
|
+
});
|
|
807
|
+
},
|
|
808
|
+
aggregate(t) {
|
|
809
|
+
let n = Object.entries(t).map(([e, t]) => ({
|
|
810
|
+
...t,
|
|
811
|
+
alias: e
|
|
812
|
+
}));
|
|
813
|
+
return Z({
|
|
814
|
+
...e,
|
|
815
|
+
projection: void 0,
|
|
816
|
+
aggregations: n
|
|
817
|
+
});
|
|
818
|
+
},
|
|
819
|
+
matching(t, n) {
|
|
820
|
+
let r = X(e.table, t, e.fullTextIndexes);
|
|
821
|
+
return Z({
|
|
822
|
+
...e,
|
|
823
|
+
fullTextSearch: {
|
|
824
|
+
indexName: t,
|
|
825
|
+
query: n,
|
|
826
|
+
columns: r.columns,
|
|
827
|
+
...r.config === void 0 ? {} : { config: r.config },
|
|
828
|
+
...r.weights === void 0 ? {} : { weights: r.weights }
|
|
829
|
+
}
|
|
830
|
+
});
|
|
831
|
+
},
|
|
832
|
+
rankBy(t) {
|
|
833
|
+
let n = e.fullTextSearch;
|
|
834
|
+
if (n === void 0) throw Error(".rankBy() requires a preceding .matching(...) clause — there is no full-text search to rank on this query.");
|
|
835
|
+
return Z({
|
|
836
|
+
...e,
|
|
837
|
+
fullTextSearch: {
|
|
838
|
+
...n,
|
|
839
|
+
rank: {
|
|
840
|
+
alias: t?.alias ?? "rank",
|
|
841
|
+
order: t?.order ?? !0
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
});
|
|
845
|
+
},
|
|
846
|
+
nearestNeighbours(t, n, r) {
|
|
847
|
+
if (typeof t == "string" && Array.isArray(n)) {
|
|
848
|
+
let i = {
|
|
849
|
+
column: t,
|
|
850
|
+
queryVector: n,
|
|
851
|
+
distance: r?.distance ?? "cosine",
|
|
852
|
+
...e.annClause?.ef === void 0 ? {} : { ef: e.annClause.ef }
|
|
853
|
+
};
|
|
854
|
+
return Z({
|
|
855
|
+
...e,
|
|
856
|
+
annClause: i
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
if (typeof t == "string" && typeof n == "number") {
|
|
860
|
+
let r = {
|
|
861
|
+
column: "",
|
|
862
|
+
queryText: t,
|
|
863
|
+
distance: "cosine",
|
|
864
|
+
...e.annClause?.ef === void 0 ? {} : { ef: e.annClause.ef }
|
|
865
|
+
};
|
|
866
|
+
return Z({
|
|
867
|
+
...e,
|
|
868
|
+
annClause: r,
|
|
869
|
+
take: n
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
throw Error("nearestNeighbours: call as (column, queryVector, options?) or (queryString, k).");
|
|
873
|
+
},
|
|
874
|
+
efSearch(t) {
|
|
875
|
+
let n = e.annClause ?? {
|
|
876
|
+
column: "",
|
|
877
|
+
distance: "cosine"
|
|
878
|
+
};
|
|
879
|
+
return Z({
|
|
880
|
+
...e,
|
|
881
|
+
annClause: {
|
|
882
|
+
...n,
|
|
883
|
+
ef: t
|
|
884
|
+
}
|
|
885
|
+
});
|
|
886
|
+
},
|
|
887
|
+
use(t) {
|
|
888
|
+
return Z({ ...t(e) });
|
|
889
|
+
},
|
|
890
|
+
distinct() {
|
|
891
|
+
return Z({
|
|
892
|
+
...e,
|
|
893
|
+
distinct: !0
|
|
894
|
+
});
|
|
895
|
+
},
|
|
896
|
+
distinctOn(t) {
|
|
897
|
+
return Z({
|
|
898
|
+
...e,
|
|
899
|
+
distinctOn: [...t]
|
|
900
|
+
});
|
|
901
|
+
},
|
|
902
|
+
as(t) {
|
|
903
|
+
return Z({
|
|
904
|
+
...e,
|
|
905
|
+
alias: t
|
|
906
|
+
});
|
|
907
|
+
},
|
|
908
|
+
innerJoin(t, n, r) {
|
|
909
|
+
let i = typeof t == "string" ? t : t.tableName, a = [...e.joins ?? [], {
|
|
910
|
+
kind: "inner",
|
|
911
|
+
table: i,
|
|
912
|
+
alias: n,
|
|
913
|
+
on: r
|
|
914
|
+
}];
|
|
915
|
+
return Z({
|
|
916
|
+
...e,
|
|
917
|
+
joins: a
|
|
918
|
+
});
|
|
919
|
+
},
|
|
920
|
+
leftJoin(t, n, r) {
|
|
921
|
+
let i = typeof t == "string" ? t : t.tableName, a = [...e.joins ?? [], {
|
|
922
|
+
kind: "left",
|
|
923
|
+
table: i,
|
|
924
|
+
alias: n,
|
|
925
|
+
on: r
|
|
926
|
+
}];
|
|
927
|
+
return Z({
|
|
928
|
+
...e,
|
|
929
|
+
joins: a
|
|
930
|
+
});
|
|
931
|
+
},
|
|
932
|
+
selectJoined(t) {
|
|
933
|
+
let n = Object.entries(t).map(([e, t]) => ({
|
|
934
|
+
outputKey: e,
|
|
935
|
+
source: t
|
|
936
|
+
}));
|
|
937
|
+
return Z({
|
|
938
|
+
...e,
|
|
939
|
+
projection: void 0,
|
|
940
|
+
joinedProjection: n
|
|
941
|
+
});
|
|
942
|
+
},
|
|
943
|
+
withCte(t, n) {
|
|
944
|
+
let r = e.ctes ?? [];
|
|
945
|
+
if (r.some((e) => e.name === t)) throw Error(`Query.withCte: duplicate CTE name '${t}'`);
|
|
946
|
+
return Z({
|
|
947
|
+
...e,
|
|
948
|
+
ctes: [...r, {
|
|
949
|
+
name: t,
|
|
950
|
+
descriptor: n
|
|
951
|
+
}]
|
|
952
|
+
});
|
|
953
|
+
},
|
|
954
|
+
recursiveCte(t, n) {
|
|
955
|
+
let r = e.ctes ?? [];
|
|
956
|
+
if (r.some((e) => e.name === t)) throw Error(`Query.recursiveCte: duplicate CTE name '${t}'`);
|
|
957
|
+
return Z({
|
|
958
|
+
...e,
|
|
959
|
+
ctes: [...r, {
|
|
960
|
+
name: t,
|
|
961
|
+
descriptor: n,
|
|
962
|
+
recursive: !0
|
|
963
|
+
}]
|
|
964
|
+
});
|
|
965
|
+
},
|
|
966
|
+
groupBy(t) {
|
|
967
|
+
let n = e.groupBy ? [...e.groupBy, ...t] : [...t];
|
|
968
|
+
return Z({
|
|
969
|
+
...e,
|
|
970
|
+
groupBy: n
|
|
971
|
+
});
|
|
972
|
+
},
|
|
973
|
+
having(t) {
|
|
974
|
+
let n = e.having ? { and: [e.having, t] } : t;
|
|
975
|
+
return Z({
|
|
976
|
+
...e,
|
|
977
|
+
having: n
|
|
978
|
+
});
|
|
979
|
+
},
|
|
980
|
+
exists() {
|
|
981
|
+
return Z({
|
|
982
|
+
...e,
|
|
983
|
+
projection: void 0,
|
|
984
|
+
aggregations: [{
|
|
985
|
+
op: "count",
|
|
986
|
+
alias: "__exists__"
|
|
987
|
+
}],
|
|
988
|
+
take: 1
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
});
|
|
992
|
+
function Q(e) {
|
|
993
|
+
return Z({
|
|
994
|
+
table: e.tableName,
|
|
995
|
+
predicate: void 0,
|
|
996
|
+
order: [],
|
|
997
|
+
take: void 0,
|
|
998
|
+
skip: void 0,
|
|
999
|
+
projection: void 0,
|
|
1000
|
+
fullTextIndexes: e.appliedFullText,
|
|
1001
|
+
sourceTable: e
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
var et = (e, t, n) => {
|
|
1005
|
+
let r = [...e.order.filter((e) => e.column !== "id"), {
|
|
1006
|
+
column: "id",
|
|
1007
|
+
direction: "asc"
|
|
1008
|
+
}], i = t === void 0 ? void 0 : {
|
|
1009
|
+
column: "id",
|
|
1010
|
+
op: "gt",
|
|
1011
|
+
value: t
|
|
1012
|
+
}, a = i === void 0 ? e.predicate : e.predicate === void 0 ? i : { and: [e.predicate, i] };
|
|
1013
|
+
return {
|
|
1014
|
+
...e,
|
|
1015
|
+
predicate: a,
|
|
1016
|
+
order: r,
|
|
1017
|
+
take: n
|
|
1018
|
+
};
|
|
1019
|
+
}, tt = (e) => {
|
|
1020
|
+
let t = {};
|
|
1021
|
+
for (let [n, r] of Object.entries(e)) K(r), t[n] = Q(r);
|
|
1022
|
+
return t;
|
|
1023
|
+
}, nt = (e) => e.isView === !0, rt = (e, t, n) => {
|
|
1024
|
+
if (_(e), n.trim().length === 0) throw Error(`view('${e}', …): the SELECT body is empty — a view must define a query.`);
|
|
1025
|
+
let r = f(t);
|
|
1026
|
+
for (let t of Object.keys(r)) v(e, t);
|
|
1027
|
+
return {
|
|
1028
|
+
tableName: e,
|
|
1029
|
+
fields: r,
|
|
1030
|
+
isView: !0,
|
|
1031
|
+
viewSelect: n
|
|
1032
|
+
};
|
|
1033
|
+
}, it = (e) => Q({
|
|
1034
|
+
...e,
|
|
1035
|
+
isReactive: !1,
|
|
1036
|
+
appliedMixins: [],
|
|
1037
|
+
appliedIndexes: [],
|
|
1038
|
+
appliedUniques: [],
|
|
1039
|
+
appliedFullText: [],
|
|
1040
|
+
appliedChecks: []
|
|
1041
|
+
}), $ = (e, t, n = null) => {
|
|
1042
|
+
let r = n === null ? H(e.tableName, t) : `${H(n, t)}.${H(e.tableName, t)}`, i = e.viewSelect.trim();
|
|
1043
|
+
switch (t) {
|
|
1044
|
+
case "postgres":
|
|
1045
|
+
case "mysql":
|
|
1046
|
+
case "mariadb": return `CREATE OR REPLACE VIEW ${r} AS ${i};`;
|
|
1047
|
+
case "mssql": return `CREATE OR ALTER VIEW ${r} AS ${i};`;
|
|
1048
|
+
case "sqlite":
|
|
1049
|
+
case "turso": return `DROP VIEW IF EXISTS ${r};\nCREATE VIEW ${r} AS ${i};`;
|
|
1050
|
+
}
|
|
1051
|
+
}, at = /^[A-Za-z_][A-Za-z0-9_]*$/, ot = (e) => "$" + e.map((e) => typeof e == "number" ? `[${e}]` : at.test(e) ? `.${e}` : `."${e.replace(/"/g, "\\\"")}"`).join(""), st = (e) => "{" + e.map((e) => {
|
|
1052
|
+
let t = String(e);
|
|
1053
|
+
return /^[A-Za-z0-9_]+$/.test(t) ? t : `"${t.replace(/(["\\])/g, "\\$1")}"`;
|
|
1054
|
+
}).join(",") + "}", ct = (e, t, n, r = {}) => {
|
|
1055
|
+
let i = H(e, n), a = r.numeric ?? !1;
|
|
1056
|
+
if (n === "postgres") {
|
|
1057
|
+
let e = `(${i} #>> '${st(t)}'::text[])`;
|
|
1058
|
+
return a ? `${e}::numeric` : e;
|
|
1059
|
+
}
|
|
1060
|
+
let o = ot(t);
|
|
1061
|
+
switch (n) {
|
|
1062
|
+
case "mysql":
|
|
1063
|
+
case "mariadb": {
|
|
1064
|
+
let e = `JSON_UNQUOTE(JSON_EXTRACT(${i}, '${o}'))`;
|
|
1065
|
+
return a ? `CAST(${e} AS DECIMAL(38,10))` : e;
|
|
1066
|
+
}
|
|
1067
|
+
case "mssql": {
|
|
1068
|
+
let e = `JSON_VALUE(${i}, '${o}')`;
|
|
1069
|
+
return a ? `CAST(${e} AS FLOAT)` : e;
|
|
1070
|
+
}
|
|
1071
|
+
case "sqlite":
|
|
1072
|
+
case "turso": {
|
|
1073
|
+
let e = `json_extract(${i}, '${o}')`;
|
|
1074
|
+
return a ? `CAST(${e} AS REAL)` : e;
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
}, lt = (e) => {
|
|
1078
|
+
if (!e.id || e.id.length === 0) throw Error("migration: `id` is required + must be non-empty");
|
|
1079
|
+
if (!e.up || !e.down) throw Error(`migration ${e.id}: both \`up\` and \`down\` must be functions`);
|
|
1080
|
+
return e;
|
|
1081
|
+
}, ut = /^\d{8}_\d{6}_[a-z0-9_]+\.ts$/, dt = (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";
|
|
1082
|
+
//#endregion
|
|
1083
|
+
export { v as $, We as A, Ae as B, Q as C, ne as Ct, Re as D, o as Dt, qe as E, l as Et, K as F, P as G, Te as H, Ne as I, N as J, we as K, je as L, Fe as M, Me as N, Qe as O, oe as Ot, q as P, be as Q, H as R, et as S, f as St, X as T, te as Tt, I as U, De as V, L as W, ve as X, j as Y, ye as Z, Ge as _, fe as _t, nt as a, me as at, Ve as b, ue as bt, $ as c, le as ct, He as d, c as dt, y as et, Ie as f, se as ft, Ke as g, de as gt, Ye as h, u as ht, ct as i, _e as it, Pe as j, Ue as k, d as kt, ze as l, re as lt, tt as m, s as mt, dt as n, b as nt, it as o, he as ot, Le as p, ie as pt, F as q, lt as r, ge as rt, rt as s, r as st, ut as t, _ as tt, $e as u, ae as ut, Xe as v, a as vt, Je as w, pe as wt, Be as x, ce as xt, Ze as y, ee as yt, Ee as z };
|