@voltro/database 0.74.0 → 0.76.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +723 -0
- package/dist/frameworkTables-CSY95jCs.js +2186 -0
- package/dist/index.d.ts +87 -0
- package/dist/index.js +699 -1189
- package/dist/sql.d.ts +31 -8
- package/dist/sql.js +1347 -1309
- package/package.json +3 -3
- package/dist/frameworkLiveTables-C1WjQ_uI.js +0 -1641
|
@@ -1,1641 +0,0 @@
|
|
|
1
|
-
import { Effect as e, Schema as t } from "effect";
|
|
2
|
-
import { typeid as n } from "typeid-js";
|
|
3
|
-
import { ulid as r } from "ulidx";
|
|
4
|
-
//#region src/columns.ts
|
|
5
|
-
var i = (e) => {
|
|
6
|
-
let t = [];
|
|
7
|
-
for (let [n, r] of Object.entries(e.fields)) r.serverOnly === !0 && t.push(n);
|
|
8
|
-
return t;
|
|
9
|
-
}, a = (e) => {
|
|
10
|
-
let t = [];
|
|
11
|
-
for (let [n, r] of Object.entries(e.fields)) r.crdtManaged === !0 && t.push(n);
|
|
12
|
-
return t;
|
|
13
|
-
}, o = (e) => {
|
|
14
|
-
let t = [];
|
|
15
|
-
for (let [n, r] of Object.entries(e.fields)) {
|
|
16
|
-
let e = r.readableBy;
|
|
17
|
-
e !== void 0 && e.length > 0 && t.push({
|
|
18
|
-
column: n,
|
|
19
|
-
scopes: e
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
return t;
|
|
23
|
-
}, s = (e) => {
|
|
24
|
-
let t = [];
|
|
25
|
-
for (let [n, r] of Object.entries(e.fields)) r.crdtManaged === !0 && t.push(n);
|
|
26
|
-
return t;
|
|
27
|
-
}, c = class e {
|
|
28
|
-
definition;
|
|
29
|
-
constructor(e) {
|
|
30
|
-
this.definition = e;
|
|
31
|
-
}
|
|
32
|
-
rejectIfRaw(e) {
|
|
33
|
-
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.`);
|
|
34
|
-
}
|
|
35
|
-
nullable() {
|
|
36
|
-
return this.rejectIfRaw("nullable"), new e({
|
|
37
|
-
...this.definition,
|
|
38
|
-
nullable: !0
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
externalId() {
|
|
42
|
-
if (this.rejectIfRaw("externalId"), this.definition.type === "reference" || this.definition.type === "id") throw Error(`.externalId() requires a scalar non-primary-key column (got ${this.definition.type}) — \`reference()\` is local by definition and \`id()\` identifies this row.`);
|
|
43
|
-
return new e({
|
|
44
|
-
...this.definition,
|
|
45
|
-
externalId: !0
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
encrypted() {
|
|
49
|
-
return this.rejectIfRaw("encrypted"), new e({
|
|
50
|
-
...this.definition,
|
|
51
|
-
encrypted: !0
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
serverOnly() {
|
|
55
|
-
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.");
|
|
56
|
-
return new e({
|
|
57
|
-
...this.definition,
|
|
58
|
-
serverOnly: !0
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
readableBy(...t) {
|
|
62
|
-
if (this.rejectIfRaw("readableBy"), t.length === 0) throw Error(".readableBy() needs at least one scope — a column readable by nobody is .serverOnly(). List the scopes that may read it, e.g. .readableBy('billing:read').");
|
|
63
|
-
if (t.find((e) => typeof e != "string" || e.trim() === "") !== void 0) throw Error(`.readableBy(...) rejects a blank scope — every scope must be a non-empty string (a blank scope can never be held, so it would hide the column from everyone). Got: ${JSON.stringify(t)}.`);
|
|
64
|
-
let n = [...new Set(t)];
|
|
65
|
-
return new e({
|
|
66
|
-
...this.definition,
|
|
67
|
-
readableBy: n
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
version() {
|
|
71
|
-
if (this.rejectIfRaw("version"), this.definition.type !== "integer") throw Error(`.version() requires an integer() column (got ${this.definition.type}). The store increments it, so it has to be a number — and a timestamp version reintroduces exactly the clock problem optimistic locking exists to avoid: two writes in the same millisecond are indistinguishable, and replica clocks disagree.`);
|
|
72
|
-
return new e({
|
|
73
|
-
...this.definition,
|
|
74
|
-
versionColumn: !0,
|
|
75
|
-
hasDefault: !0,
|
|
76
|
-
defaultValue: 1
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
sensitive(t) {
|
|
80
|
-
return new e({
|
|
81
|
-
...this.definition,
|
|
82
|
-
sensitive: { class: t }
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
safe() {
|
|
86
|
-
return new e({
|
|
87
|
-
...this.definition,
|
|
88
|
-
safe: !0
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
unique(t) {
|
|
92
|
-
return this.rejectIfRaw("unique"), t?.dedup === void 0 ? new e({
|
|
93
|
-
...this.definition,
|
|
94
|
-
unique: !0
|
|
95
|
-
}) : new e({
|
|
96
|
-
...this.definition,
|
|
97
|
-
unique: !0,
|
|
98
|
-
uniqueSpec: { dedup: t.dedup }
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
default(t) {
|
|
102
|
-
return this.rejectIfRaw("default"), typeof t == "function" ? new e({
|
|
103
|
-
...this.definition,
|
|
104
|
-
hasDefault: !0,
|
|
105
|
-
defaultFactory: t
|
|
106
|
-
}) : new e({
|
|
107
|
-
...this.definition,
|
|
108
|
-
hasDefault: !0,
|
|
109
|
-
defaultValue: t
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
computed(t) {
|
|
113
|
-
return new e({
|
|
114
|
-
...this.definition,
|
|
115
|
-
computed: t
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
onUpdate(t) {
|
|
119
|
-
return new e({
|
|
120
|
-
...this.definition,
|
|
121
|
-
onUpdate: t
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
generatedAs(t, n) {
|
|
125
|
-
return new e({
|
|
126
|
-
...this.definition,
|
|
127
|
-
generatedAs: {
|
|
128
|
-
expr: t,
|
|
129
|
-
stored: n?.stored ?? !1
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
backfill(t, n) {
|
|
134
|
-
let r = typeof t == "function" ? {
|
|
135
|
-
kind: "js",
|
|
136
|
-
fn: t,
|
|
137
|
-
...n?.batchSize === void 0 ? {} : { batchSize: n.batchSize },
|
|
138
|
-
...n?.sleepMs === void 0 ? {} : { sleepMs: n.sleepMs }
|
|
139
|
-
} : {
|
|
140
|
-
kind: "sql",
|
|
141
|
-
sql: t,
|
|
142
|
-
...n?.batchSize === void 0 ? {} : { batchSize: n.batchSize },
|
|
143
|
-
...n?.sleepMs === void 0 ? {} : { sleepMs: n.sleepMs }
|
|
144
|
-
};
|
|
145
|
-
return new e({
|
|
146
|
-
...this.definition,
|
|
147
|
-
backfill: r
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
renamedFrom(t) {
|
|
151
|
-
return new e({
|
|
152
|
-
...this.definition,
|
|
153
|
-
renamedFrom: t
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
narrowedFrom(t, n) {
|
|
157
|
-
let r = n?.using === void 0 ? { from: t } : {
|
|
158
|
-
from: t,
|
|
159
|
-
using: n.using
|
|
160
|
-
};
|
|
161
|
-
return new e({
|
|
162
|
-
...this.definition,
|
|
163
|
-
narrowedFrom: r
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
oneOf(t) {
|
|
167
|
-
return new e({
|
|
168
|
-
...this.definition,
|
|
169
|
-
oneOf: t
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
maxLength(t) {
|
|
173
|
-
return new e({
|
|
174
|
-
...this.definition,
|
|
175
|
-
maxLength: t
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
check(t) {
|
|
179
|
-
let n = this.definition.checks ? [...this.definition.checks, t] : [t];
|
|
180
|
-
return new e({
|
|
181
|
-
...this.definition,
|
|
182
|
-
checks: n
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
__definition() {
|
|
186
|
-
return this.definition;
|
|
187
|
-
}
|
|
188
|
-
}, l = (e) => new c({
|
|
189
|
-
type: e,
|
|
190
|
-
nullable: !1,
|
|
191
|
-
unique: !1,
|
|
192
|
-
hasDefault: !1
|
|
193
|
-
});
|
|
194
|
-
function ee(e) {
|
|
195
|
-
return new c({
|
|
196
|
-
type: "id",
|
|
197
|
-
nullable: !1,
|
|
198
|
-
unique: !0,
|
|
199
|
-
hasDefault: !1,
|
|
200
|
-
idSchemeInput: e
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
var u = () => l("text"), te = () => l("integer"), ne = () => l("real"), re = (e, t = 0) => {
|
|
204
|
-
if (!Number.isInteger(e) || e <= 0) throw Error(`decimal(${String(e)}, ${String(t)}): precision must be a positive integer (the total number of significant digits, e.g. decimal(12, 2)).`);
|
|
205
|
-
if (!Number.isInteger(t) || t < 0 || t > e) throw Error(`decimal(${String(e)}, ${String(t)}): scale must be an integer between 0 and precision (${e}).`);
|
|
206
|
-
return new c({
|
|
207
|
-
type: "decimal",
|
|
208
|
-
nullable: !1,
|
|
209
|
-
unique: !1,
|
|
210
|
-
hasDefault: !1,
|
|
211
|
-
precision: e,
|
|
212
|
-
scale: t
|
|
213
|
-
});
|
|
214
|
-
}, ie = re, ae = () => l("bigint"), oe = (e, t) => {
|
|
215
|
-
if (t.length === 0) throw Error(`dbEnum('${e}', []): enum must have at least one value`);
|
|
216
|
-
return {
|
|
217
|
-
name: e,
|
|
218
|
-
values: t,
|
|
219
|
-
column: () => new c({
|
|
220
|
-
type: "enum",
|
|
221
|
-
nullable: !1,
|
|
222
|
-
unique: !1,
|
|
223
|
-
hasDefault: !1,
|
|
224
|
-
enumName: e,
|
|
225
|
-
enumValues: t
|
|
226
|
-
})
|
|
227
|
-
};
|
|
228
|
-
}, se = () => l("boolean"), ce = () => l("timestamp"), le = () => l("date"), ue = () => l("json"), de = () => l("bytes"), fe = () => new c({
|
|
229
|
-
type: "bytes",
|
|
230
|
-
nullable: !0,
|
|
231
|
-
unique: !1,
|
|
232
|
-
hasDefault: !1,
|
|
233
|
-
crdtManaged: !0
|
|
234
|
-
}), pe = () => new c({
|
|
235
|
-
type: "bytes",
|
|
236
|
-
nullable: !0,
|
|
237
|
-
unique: !1,
|
|
238
|
-
hasDefault: !1,
|
|
239
|
-
crdtManaged: !0
|
|
240
|
-
}), d = () => {
|
|
241
|
-
throw Error("selfReference(): the target is resolved by table() — a column built with selfReference() must be declared inside a table({ … }) literal, not read before the table exists");
|
|
242
|
-
};
|
|
243
|
-
function me(e) {
|
|
244
|
-
return he(d, e);
|
|
245
|
-
}
|
|
246
|
-
function he(e, t) {
|
|
247
|
-
return new c({
|
|
248
|
-
type: "reference",
|
|
249
|
-
nullable: !1,
|
|
250
|
-
unique: !1,
|
|
251
|
-
hasDefault: !1,
|
|
252
|
-
references: e,
|
|
253
|
-
referenceStorage: t?.storage ?? "text",
|
|
254
|
-
referenceColumn: t?.column ?? "id",
|
|
255
|
-
onDelete: t?.onDelete ?? "restrict",
|
|
256
|
-
refOnUpdate: t?.onUpdate ?? "noAction",
|
|
257
|
-
...t?.onSoftDelete === void 0 ? {} : { refOnSoftDelete: t.onSoftDelete },
|
|
258
|
-
fkAutoIndex: t?.index ?? !0,
|
|
259
|
-
...t?.orphanPolicy ? { orphanPolicy: t.orphanPolicy } : {}
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
var ge = () => new c({
|
|
263
|
-
type: "text",
|
|
264
|
-
nullable: !0,
|
|
265
|
-
unique: !1,
|
|
266
|
-
hasDefault: !1,
|
|
267
|
-
dropped: !0
|
|
268
|
-
}), _e = (e, t) => {
|
|
269
|
-
if (!Number.isInteger(e) || e <= 0) throw Error(`vector(${String(e)}): dimension must be a positive integer (the embedding length, e.g. vector(1536)).`);
|
|
270
|
-
return new c({
|
|
271
|
-
type: "vector",
|
|
272
|
-
nullable: !1,
|
|
273
|
-
unique: !1,
|
|
274
|
-
hasDefault: !1,
|
|
275
|
-
vectorDim: e,
|
|
276
|
-
vectorPrecision: t?.precision ?? "float32"
|
|
277
|
-
});
|
|
278
|
-
}, ve = (e) => new c({
|
|
279
|
-
type: "array",
|
|
280
|
-
nullable: !1,
|
|
281
|
-
unique: !1,
|
|
282
|
-
hasDefault: !1,
|
|
283
|
-
arrayElement: e.__definition().type
|
|
284
|
-
}), ye = () => l("interval"), be = (e, t = 4326) => new c({
|
|
285
|
-
type: "text",
|
|
286
|
-
nullable: !1,
|
|
287
|
-
unique: !1,
|
|
288
|
-
hasDefault: !1,
|
|
289
|
-
spatial: {
|
|
290
|
-
kind: "geography",
|
|
291
|
-
geomKind: e,
|
|
292
|
-
srid: t
|
|
293
|
-
}
|
|
294
|
-
}), xe = (e, t = 4326) => new c({
|
|
295
|
-
type: "text",
|
|
296
|
-
nullable: !1,
|
|
297
|
-
unique: !1,
|
|
298
|
-
hasDefault: !1,
|
|
299
|
-
spatial: {
|
|
300
|
-
kind: "geometry",
|
|
301
|
-
geomKind: e,
|
|
302
|
-
srid: t
|
|
303
|
-
}
|
|
304
|
-
}), Se = (e) => new c({
|
|
305
|
-
type: "raw",
|
|
306
|
-
nullable: !1,
|
|
307
|
-
unique: !1,
|
|
308
|
-
hasDefault: !1,
|
|
309
|
-
rawDdl: e
|
|
310
|
-
}), f = (e) => {
|
|
311
|
-
let t = {};
|
|
312
|
-
for (let [n, r] of Object.entries(e)) t[n] = r.__definition();
|
|
313
|
-
return t;
|
|
314
|
-
}, p = /* @__PURE__ */ new WeakMap(), m = (e) => typeof e == "object" && e ? p.get(e) : void 0, Ce = (e, t = {}) => {
|
|
315
|
-
let n = u();
|
|
316
|
-
return p.set(n, {
|
|
317
|
-
target: e,
|
|
318
|
-
orphanPolicy: t.orphanPolicy ?? "keep",
|
|
319
|
-
onSoftDelete: t.onSoftDelete ?? !1
|
|
320
|
-
}), n;
|
|
321
|
-
}, h = /* @__PURE__ */ new Map(), we = (e, t) => {
|
|
322
|
-
if (t.from === t.to) throw Error(`declareEnumRename('${e}'): \`from\` and \`to\` are both '${t.from}' — a rename must change the value.`);
|
|
323
|
-
let n = h.get(e) ?? [];
|
|
324
|
-
for (let r of n) {
|
|
325
|
-
if (r.from === t.from && r.to === t.to) return;
|
|
326
|
-
if (r.from === t.from && r.to !== t.to) throw Error(`declareEnumRename('${e}'): value '${t.from}' is already declared as renamed to '${r.to}', cannot also rename it to '${t.to}'.`);
|
|
327
|
-
}
|
|
328
|
-
n.push(t), h.set(e, n);
|
|
329
|
-
}, Te = (e) => h.get(e) ?? [], Ee = () => h, De = () => {
|
|
330
|
-
h.clear();
|
|
331
|
-
}, Oe = 63, ke = 60, g = [], _ = (e) => {
|
|
332
|
-
g.includes(e) || g.push(e);
|
|
333
|
-
}, Ae = () => {
|
|
334
|
-
let e = g.slice();
|
|
335
|
-
return g.length = 0, e;
|
|
336
|
-
}, je = /^[a-zA-Z_][a-zA-Z0-9_]*$/, v = (e, t) => {
|
|
337
|
-
if (t.length === 0) throw Error(`${e} cannot be empty.`);
|
|
338
|
-
if (!je.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_]*$/.`);
|
|
339
|
-
}, y = (e) => {
|
|
340
|
-
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.`);
|
|
341
|
-
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.`);
|
|
342
|
-
}, b = (e, t) => {
|
|
343
|
-
if (v("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.`);
|
|
344
|
-
t.length > 60 && _(`column '${t}' on table '${e}' is ${t.length} chars — close to the 63-byte limit.`);
|
|
345
|
-
}, x = (e, t, n, r) => {
|
|
346
|
-
if (v("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.`);
|
|
347
|
-
t.length > 60 && _(`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.` : ""}`);
|
|
348
|
-
}, S = (e, t) => {
|
|
349
|
-
if (e.length === 0) throw Error(`typeid prefix on table '${t.tableName}' cannot be empty.`);
|
|
350
|
-
if (!/^[a-z][a-z0-9_]*$/.test(e)) {
|
|
351
|
-
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_]*$/.";
|
|
352
|
-
throw Error(`typeid prefix '${e}' on table '${t.tableName}' is invalid — ${n}`);
|
|
353
|
-
}
|
|
354
|
-
if (e.length > 63) {
|
|
355
|
-
let n = t.kind === "derived" ? "shorten the table name, or supply an explicit short prefix via id({ prefix: '...' })." : "pick a shorter prefix.";
|
|
356
|
-
throw Error(`typeid prefix '${e}' on table '${t.tableName}' is ${e.length} chars — exceeds the 63-byte limit; ${n}`);
|
|
357
|
-
}
|
|
358
|
-
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).`);
|
|
359
|
-
}, Me = 1704067200000n, Ne = 10n, Pe = 12n, Fe = (1n << Ne) - 1n, Ie = (1n << Pe) - 1n, Le = Pe, Re = 22n, ze = () => {
|
|
360
|
-
let e = process.env.SNOWFLAKE_MACHINE_ID;
|
|
361
|
-
if (e === void 0 || e === "") return 0n;
|
|
362
|
-
let t = BigInt(e);
|
|
363
|
-
if (t < 0n || t > Fe) throw Error(`SNOWFLAKE_MACHINE_ID out of range: ${e}. Must be 0..${Fe}.`);
|
|
364
|
-
return t;
|
|
365
|
-
}, C = () => ({
|
|
366
|
-
lastMs: 0n,
|
|
367
|
-
sequence: 0n,
|
|
368
|
-
machineId: ze()
|
|
369
|
-
}), w, Be = () => (w === void 0 && (w = C()), w), Ve = () => {
|
|
370
|
-
w = C();
|
|
371
|
-
}, T = () => BigInt(Date.now()), He = (e) => {
|
|
372
|
-
let t = T();
|
|
373
|
-
for (; t <= e;) t = T();
|
|
374
|
-
return t;
|
|
375
|
-
}, E = () => {
|
|
376
|
-
let e = Be(), t = T();
|
|
377
|
-
t === e.lastMs ? (e.sequence = e.sequence + 1n & Ie, e.sequence === 0n && (t = He(e.lastMs), e.lastMs = t)) : (e.sequence = 0n, e.lastMs = t);
|
|
378
|
-
let n = t - Me;
|
|
379
|
-
if (n < 0n) throw Error("Snowflake timestamp before configured epoch (2024-01-01). System clock is wrong.");
|
|
380
|
-
return (n << Re | e.machineId << Le | e.sequence).toString();
|
|
381
|
-
}, D = (e) => {
|
|
382
|
-
let t = e.toLowerCase();
|
|
383
|
-
if (t.startsWith("_")) throw Error(`cannot derive a typeid prefix for table '${e}' (table names starting with '_' are not valid typeid prefixes). Pick an explicit prefix via id({ prefix: '...' }) or use a different scheme like id({ scheme: 'numeric' }) for internal tables.`);
|
|
384
|
-
if (!/^[a-z][a-z0-9_]*$/.test(t)) throw Error(`cannot derive a typeid prefix from table name '${e}' (must match [a-z][a-z0-9_]*). Pick an explicit prefix via id({ prefix: '...' }).`);
|
|
385
|
-
let n = t.endsWith("ies") && t.length > 3 ? t.slice(0, -3) + "y" : t.endsWith("ses") || t.endsWith("xes") || t.endsWith("zes") || t.endsWith("shes") || t.endsWith("ches") ? t.slice(0, -2) : t.endsWith("s") && t.length > 1 ? t.slice(0, -1) : t;
|
|
386
|
-
return S(n, {
|
|
387
|
-
kind: "derived",
|
|
388
|
-
tableName: e
|
|
389
|
-
}), n;
|
|
390
|
-
}, O = (e, t) => {
|
|
391
|
-
if (e === void 0) return {
|
|
392
|
-
kind: "typeid",
|
|
393
|
-
prefix: D(t)
|
|
394
|
-
};
|
|
395
|
-
if ("prefix" in e && !("scheme" in e)) return S(e.prefix, {
|
|
396
|
-
kind: "explicit",
|
|
397
|
-
tableName: t
|
|
398
|
-
}), {
|
|
399
|
-
kind: "typeid",
|
|
400
|
-
prefix: e.prefix
|
|
401
|
-
};
|
|
402
|
-
if (!("scheme" in e)) throw Error("invalid id() options: no scheme or prefix");
|
|
403
|
-
switch (e.scheme) {
|
|
404
|
-
case "typeid": {
|
|
405
|
-
let n = e.prefix ?? D(t);
|
|
406
|
-
return e.prefix !== void 0 && S(e.prefix, {
|
|
407
|
-
kind: "explicit",
|
|
408
|
-
tableName: t
|
|
409
|
-
}), {
|
|
410
|
-
kind: "typeid",
|
|
411
|
-
prefix: n
|
|
412
|
-
};
|
|
413
|
-
}
|
|
414
|
-
case "ulid": return { kind: "ulid" };
|
|
415
|
-
case "numeric": return { kind: "numeric" };
|
|
416
|
-
case "snowflake": return { kind: "snowflake" };
|
|
417
|
-
case "custom": return {
|
|
418
|
-
kind: "custom",
|
|
419
|
-
generate: e.generate
|
|
420
|
-
};
|
|
421
|
-
}
|
|
422
|
-
}, Ue = (e, t) => {
|
|
423
|
-
switch (e.kind) {
|
|
424
|
-
case "typeid": return n(e.prefix).toString();
|
|
425
|
-
case "ulid": return r();
|
|
426
|
-
case "numeric": return null;
|
|
427
|
-
case "snowflake": return E();
|
|
428
|
-
case "custom": return e.generate(t);
|
|
429
|
-
}
|
|
430
|
-
}, k = (e) => ({
|
|
431
|
-
fields: f(e.fields),
|
|
432
|
-
...e.id === void 0 ? {} : { id: e.id },
|
|
433
|
-
...e.requires === void 0 ? {} : { requires: e.requires },
|
|
434
|
-
...e.indexes === void 0 ? {} : { indexes: e.indexes },
|
|
435
|
-
...e.behaviors === void 0 ? {} : { behaviors: e.behaviors },
|
|
436
|
-
...e.policies === void 0 ? {} : { policies: e.policies }
|
|
437
|
-
}), We = k, A = (e) => {
|
|
438
|
-
let t = /* @__PURE__ */ new Set(), n = [], r = (e) => {
|
|
439
|
-
let i = e.id ?? e;
|
|
440
|
-
if (!t.has(i)) {
|
|
441
|
-
if (t.add(i), e.requires !== void 0) for (let t of e.requires) r(t);
|
|
442
|
-
n.push(e);
|
|
443
|
-
}
|
|
444
|
-
};
|
|
445
|
-
for (let t of e) r(t);
|
|
446
|
-
return n;
|
|
447
|
-
}, Ge = (e, ...t) => {
|
|
448
|
-
if (t.length === 0) throw Error(`jsonIndex("${e}"): at least one path segment is required`);
|
|
449
|
-
let n = (r) => ({
|
|
450
|
-
jsonPath: {
|
|
451
|
-
column: e,
|
|
452
|
-
path: t,
|
|
453
|
-
numeric: r
|
|
454
|
-
},
|
|
455
|
-
numeric: () => n(!0)
|
|
456
|
-
});
|
|
457
|
-
return n(!1);
|
|
458
|
-
}, Ke = (e = "cosine", t = "float32") => {
|
|
459
|
-
let n = t === "half" ? "halfvec" : "vector";
|
|
460
|
-
switch (e) {
|
|
461
|
-
case "cosine": return `${n}_cosine_ops`;
|
|
462
|
-
case "l2": return `${n}_l2_ops`;
|
|
463
|
-
case "inner": return `${n}_ip_ops`;
|
|
464
|
-
}
|
|
465
|
-
}, qe = [
|
|
466
|
-
"id",
|
|
467
|
-
"tenantId",
|
|
468
|
-
"createdAt",
|
|
469
|
-
"updatedAt",
|
|
470
|
-
"createdBy",
|
|
471
|
-
"updatedBy",
|
|
472
|
-
"deletedAt",
|
|
473
|
-
"deletedBy"
|
|
474
|
-
], Je = (e) => e.id ?? `<anonymous mixin: ${Object.keys(e.fields).join(", ")}>`, j = (e, t) => `${e}_${t.join("_")}_idx`, Ye = (e, t) => `${e}_${t.join("_")}_uq`, M = (e, t, n, r, i) => {
|
|
475
|
-
if (n !== "hnsw") return;
|
|
476
|
-
if (r.length !== 1) throw Error(`hnsw index '${t}' on table '${e}' must cover exactly one vector column — got ${r.length} fields. pgvector's HNSW access method indexes a single vector column.`);
|
|
477
|
-
let a = r[0];
|
|
478
|
-
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.`);
|
|
479
|
-
let o = i[a];
|
|
480
|
-
if (o === void 0) throw Error(`hnsw index '${t}' on table '${e}' references unknown column '${a}'.`);
|
|
481
|
-
if (o.type !== "vector") throw Error(`hnsw index '${t}' on table '${e}' requires a vector() column — column '${a}' is '${o.type}'. HNSW is the pgvector approximate-nearest-neighbour method and only applies to vectors.`);
|
|
482
|
-
}, Xe = (e, t) => {
|
|
483
|
-
let n;
|
|
484
|
-
for (let [r, i] of Object.entries(e)) i.type === "id" && i.idScheme === void 0 && (n === void 0 && (n = { ...e }), n[r] = {
|
|
485
|
-
...i,
|
|
486
|
-
idScheme: O(i.idSchemeInput, t)
|
|
487
|
-
});
|
|
488
|
-
return n ?? e;
|
|
489
|
-
}, N = (e) => {
|
|
490
|
-
let n = e.appliedPrimaryKey ?? [];
|
|
491
|
-
return {
|
|
492
|
-
tableName: e.tableName,
|
|
493
|
-
fields: e.fields,
|
|
494
|
-
isReactive: e.isReactive,
|
|
495
|
-
appliedMixins: e.appliedMixins,
|
|
496
|
-
appliedIndexes: e.appliedIndexes,
|
|
497
|
-
appliedUniques: e.appliedUniques,
|
|
498
|
-
appliedFullText: e.appliedFullText,
|
|
499
|
-
appliedChecks: e.appliedChecks,
|
|
500
|
-
appliedRules: e.appliedRules ?? [],
|
|
501
|
-
appliedPluginRefs: e.appliedPluginRefs ?? [],
|
|
502
|
-
appliedPrimaryKey: n,
|
|
503
|
-
...e.previousTableName === void 0 ? {} : { previousTableName: e.previousTableName },
|
|
504
|
-
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
505
|
-
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema },
|
|
506
|
-
fullTextIndex: ((t, n, r) => {
|
|
507
|
-
if (n.length === 0) throw Error(`fullTextIndex '${t}' on '${e.tableName}' has no columns.`);
|
|
508
|
-
if (x(e.tableName, t, !1, n), e.appliedFullText.some((e) => e.name === t)) throw Error(`duplicate full-text index '${t}' on table '${e.tableName}'.`);
|
|
509
|
-
return N({
|
|
510
|
-
...e,
|
|
511
|
-
tableName: e.tableName,
|
|
512
|
-
fields: e.fields,
|
|
513
|
-
isReactive: e.isReactive,
|
|
514
|
-
appliedMixins: e.appliedMixins,
|
|
515
|
-
appliedIndexes: e.appliedIndexes,
|
|
516
|
-
appliedUniques: e.appliedUniques,
|
|
517
|
-
appliedChecks: e.appliedChecks,
|
|
518
|
-
appliedPrimaryKey: e.appliedPrimaryKey,
|
|
519
|
-
appliedFullText: [...e.appliedFullText, {
|
|
520
|
-
name: t,
|
|
521
|
-
columns: [...n],
|
|
522
|
-
...r?.config === void 0 ? {} : { config: r.config },
|
|
523
|
-
...r?.weights === void 0 ? {} : { weights: r.weights }
|
|
524
|
-
}],
|
|
525
|
-
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
526
|
-
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
527
|
-
});
|
|
528
|
-
}),
|
|
529
|
-
with: ((...t) => {
|
|
530
|
-
let n = A(t), r = { ...e.fields }, i = /* @__PURE__ */ new Map();
|
|
531
|
-
for (let e of Object.keys(r)) i.set(e, {
|
|
532
|
-
id: "<table>",
|
|
533
|
-
fields: {}
|
|
534
|
-
});
|
|
535
|
-
for (let t of n) for (let [n, a] of Object.entries(t.fields)) {
|
|
536
|
-
let o = i.get(n);
|
|
537
|
-
if (o !== void 0) throw Error(`mixin collision on column '${n}' in table '${e.tableName}': '${Je(o)}' and '${Je(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.`);
|
|
538
|
-
b(e.tableName, n), r[n] = a, i.set(n, t);
|
|
539
|
-
}
|
|
540
|
-
let a = [...e.appliedIndexes];
|
|
541
|
-
for (let t of n) for (let n of t.indexes ?? []) {
|
|
542
|
-
let t = n.name ?? j(e.tableName, n.fields);
|
|
543
|
-
a.some((e) => e.name === t) || (x(e.tableName, t, n.name === void 0, n.fields), M(e.tableName, t, n.kind, n.fields, r), a.push({
|
|
544
|
-
name: t,
|
|
545
|
-
fields: n.fields,
|
|
546
|
-
...n.kind === void 0 ? {} : { kind: n.kind },
|
|
547
|
-
...n.kindOptions === void 0 ? {} : { kindOptions: n.kindOptions }
|
|
548
|
-
}));
|
|
549
|
-
}
|
|
550
|
-
return N({
|
|
551
|
-
...e,
|
|
552
|
-
tableName: e.tableName,
|
|
553
|
-
fields: r,
|
|
554
|
-
isReactive: e.isReactive,
|
|
555
|
-
appliedMixins: [...e.appliedMixins, ...n],
|
|
556
|
-
appliedIndexes: a,
|
|
557
|
-
appliedUniques: e.appliedUniques,
|
|
558
|
-
appliedFullText: e.appliedFullText,
|
|
559
|
-
appliedChecks: e.appliedChecks,
|
|
560
|
-
appliedPrimaryKey: e.appliedPrimaryKey,
|
|
561
|
-
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
562
|
-
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
563
|
-
});
|
|
564
|
-
}),
|
|
565
|
-
index: ((...t) => {
|
|
566
|
-
let n, r, i, a = Array.isArray(t[0]);
|
|
567
|
-
if (a ? (r = t[0], i = t[1], n = j(e.tableName, r)) : (n = t[0], r = t[1], i = t[2]), r.length === 0) throw Error(`index '${n}' on table '${e.tableName}' has no fields — an index must cover at least one column.`);
|
|
568
|
-
let o = r.filter((e) => typeof e == "string");
|
|
569
|
-
if (x(e.tableName, n, a, o), M(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.`);
|
|
570
|
-
return N({
|
|
571
|
-
...e,
|
|
572
|
-
tableName: e.tableName,
|
|
573
|
-
fields: e.fields,
|
|
574
|
-
isReactive: e.isReactive,
|
|
575
|
-
appliedMixins: e.appliedMixins,
|
|
576
|
-
appliedIndexes: [...e.appliedIndexes, {
|
|
577
|
-
name: n,
|
|
578
|
-
fields: [...r],
|
|
579
|
-
...i?.where === void 0 ? {} : { where: i.where },
|
|
580
|
-
...i?.kind === void 0 ? {} : { kind: i.kind },
|
|
581
|
-
...i?.kindOptions === void 0 ? {} : { kindOptions: i.kindOptions }
|
|
582
|
-
}],
|
|
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
|
-
}),
|
|
591
|
-
expressionIndex: ((t, n, r) => {
|
|
592
|
-
if (n.length === 0) throw Error(`expressionIndex '${t}' on table '${e.tableName}' has no fields — an index must cover at least one column or expression.`);
|
|
593
|
-
let i = n.filter((e) => typeof e == "string");
|
|
594
|
-
if (x(e.tableName, t, !1, i), M(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.`);
|
|
595
|
-
return N({
|
|
596
|
-
...e,
|
|
597
|
-
tableName: e.tableName,
|
|
598
|
-
fields: e.fields,
|
|
599
|
-
isReactive: e.isReactive,
|
|
600
|
-
appliedMixins: e.appliedMixins,
|
|
601
|
-
appliedIndexes: [...e.appliedIndexes, {
|
|
602
|
-
name: t,
|
|
603
|
-
fields: [...n],
|
|
604
|
-
...r?.where === void 0 ? {} : { where: r.where },
|
|
605
|
-
...r?.kind === void 0 ? {} : { kind: r.kind },
|
|
606
|
-
...r?.kindOptions === void 0 ? {} : { kindOptions: r.kindOptions }
|
|
607
|
-
}],
|
|
608
|
-
appliedUniques: e.appliedUniques,
|
|
609
|
-
appliedFullText: e.appliedFullText,
|
|
610
|
-
appliedChecks: e.appliedChecks,
|
|
611
|
-
appliedPrimaryKey: e.appliedPrimaryKey,
|
|
612
|
-
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
613
|
-
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
614
|
-
});
|
|
615
|
-
}),
|
|
616
|
-
unique: ((...t) => {
|
|
617
|
-
let n, r, i, a = Array.isArray(t[0]);
|
|
618
|
-
if (a ? (r = t[0], i = t[1], n = Ye(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.`);
|
|
619
|
-
if (x(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.`);
|
|
620
|
-
return N({
|
|
621
|
-
...e,
|
|
622
|
-
tableName: e.tableName,
|
|
623
|
-
fields: e.fields,
|
|
624
|
-
isReactive: e.isReactive,
|
|
625
|
-
appliedMixins: e.appliedMixins,
|
|
626
|
-
appliedIndexes: e.appliedIndexes,
|
|
627
|
-
appliedUniques: [...e.appliedUniques, {
|
|
628
|
-
name: n,
|
|
629
|
-
fields: [...r],
|
|
630
|
-
...i?.dedup === void 0 ? {} : { dedup: i.dedup }
|
|
631
|
-
}],
|
|
632
|
-
appliedFullText: e.appliedFullText,
|
|
633
|
-
appliedChecks: e.appliedChecks,
|
|
634
|
-
appliedPrimaryKey: e.appliedPrimaryKey,
|
|
635
|
-
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
636
|
-
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
637
|
-
});
|
|
638
|
-
}),
|
|
639
|
-
uniqueActive: ((...t) => {
|
|
640
|
-
let n, r, i, a = Array.isArray(t[0]);
|
|
641
|
-
if (a ? (r = t[0], i = t[1], n = j(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.`);
|
|
642
|
-
if (x(e.tableName, n, a, r), e.appliedIndexes.some((e) => e.name === n)) throw Error(`duplicate index '${n}' on table '${e.tableName}': each index name must be unique within a table (uniqueActive shares the index namespace).`);
|
|
643
|
-
let o = i?.where ?? "\"deletedAt\" IS NULL";
|
|
644
|
-
return N({
|
|
645
|
-
...e,
|
|
646
|
-
tableName: e.tableName,
|
|
647
|
-
fields: e.fields,
|
|
648
|
-
isReactive: e.isReactive,
|
|
649
|
-
appliedMixins: e.appliedMixins,
|
|
650
|
-
appliedIndexes: [...e.appliedIndexes, {
|
|
651
|
-
name: n,
|
|
652
|
-
fields: [...r],
|
|
653
|
-
where: o,
|
|
654
|
-
unique: !0
|
|
655
|
-
}],
|
|
656
|
-
appliedUniques: e.appliedUniques,
|
|
657
|
-
appliedFullText: e.appliedFullText,
|
|
658
|
-
appliedChecks: e.appliedChecks,
|
|
659
|
-
appliedPrimaryKey: e.appliedPrimaryKey,
|
|
660
|
-
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
661
|
-
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
662
|
-
});
|
|
663
|
-
}),
|
|
664
|
-
check: ((t, n) => {
|
|
665
|
-
if (n.trim().length === 0) throw Error(`CHECK '${t}' on table '${e.tableName}' has an empty expression.`);
|
|
666
|
-
if (x(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.`);
|
|
667
|
-
return N({
|
|
668
|
-
...e,
|
|
669
|
-
tableName: e.tableName,
|
|
670
|
-
fields: e.fields,
|
|
671
|
-
isReactive: e.isReactive,
|
|
672
|
-
appliedMixins: e.appliedMixins,
|
|
673
|
-
appliedIndexes: e.appliedIndexes,
|
|
674
|
-
appliedUniques: e.appliedUniques,
|
|
675
|
-
appliedFullText: e.appliedFullText,
|
|
676
|
-
appliedChecks: [...e.appliedChecks, {
|
|
677
|
-
name: t,
|
|
678
|
-
expr: n
|
|
679
|
-
}],
|
|
680
|
-
appliedPrimaryKey: e.appliedPrimaryKey,
|
|
681
|
-
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
682
|
-
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
683
|
-
});
|
|
684
|
-
}),
|
|
685
|
-
rule: ((t, n, r) => {
|
|
686
|
-
if (t.trim().length === 0) throw Error(`rule on table '${e.tableName}' has an empty name.`);
|
|
687
|
-
let i = e.appliedRules ?? [];
|
|
688
|
-
if (i.some((e) => e.name === t)) throw Error(`duplicate rule '${t}' on table '${e.tableName}': each rule name must be unique within a table.`);
|
|
689
|
-
return N({
|
|
690
|
-
...e,
|
|
691
|
-
appliedRules: [...i, {
|
|
692
|
-
name: t,
|
|
693
|
-
predicate: n,
|
|
694
|
-
severity: r?.severity ?? "error"
|
|
695
|
-
}]
|
|
696
|
-
});
|
|
697
|
-
}),
|
|
698
|
-
renamedFrom: ((t) => {
|
|
699
|
-
if (t === e.tableName) throw Error(`renamedFrom('${t}') on table '${e.tableName}' names the table itself — drop the marker, there is nothing to rename.`);
|
|
700
|
-
return y(t), N({
|
|
701
|
-
...e,
|
|
702
|
-
previousTableName: t
|
|
703
|
-
});
|
|
704
|
-
}),
|
|
705
|
-
primaryKey: ((t) => {
|
|
706
|
-
if (t.length === 0) throw Error(`primaryKey([...]) on table '${e.tableName}' needs at least one column.`);
|
|
707
|
-
let r = /* @__PURE__ */ new Set();
|
|
708
|
-
for (let n of t) {
|
|
709
|
-
if (!(n in e.fields)) throw Error(`primaryKey([...]) on table '${e.tableName}' references unknown column '${n}'.`);
|
|
710
|
-
if (r.has(n)) throw Error(`primaryKey([...]) on table '${e.tableName}' lists column '${n}' twice.`);
|
|
711
|
-
r.add(n);
|
|
712
|
-
}
|
|
713
|
-
if (n.length > 0) throw Error(`primaryKey([...]) declared twice on table '${e.tableName}'.`);
|
|
714
|
-
for (let [n, r] of Object.entries(e.fields)) if (r.type === "id" && !t.includes(n)) throw Error(`primaryKey([...]) on table '${e.tableName}' conflicts with the id() column '${n}'. The explicit primary key IS the key — drop the id() column, or include '${n}' in the composite key.`);
|
|
715
|
-
return N({
|
|
716
|
-
...e,
|
|
717
|
-
tableName: e.tableName,
|
|
718
|
-
fields: e.fields,
|
|
719
|
-
isReactive: e.isReactive,
|
|
720
|
-
appliedMixins: e.appliedMixins,
|
|
721
|
-
appliedIndexes: e.appliedIndexes,
|
|
722
|
-
appliedUniques: e.appliedUniques,
|
|
723
|
-
appliedFullText: e.appliedFullText,
|
|
724
|
-
appliedChecks: e.appliedChecks,
|
|
725
|
-
appliedPrimaryKey: [...t],
|
|
726
|
-
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
727
|
-
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
728
|
-
});
|
|
729
|
-
}),
|
|
730
|
-
nonReactive: (() => N({
|
|
731
|
-
...e,
|
|
732
|
-
tableName: e.tableName,
|
|
733
|
-
fields: e.fields,
|
|
734
|
-
isReactive: !1,
|
|
735
|
-
appliedMixins: e.appliedMixins,
|
|
736
|
-
appliedIndexes: e.appliedIndexes,
|
|
737
|
-
appliedUniques: e.appliedUniques,
|
|
738
|
-
appliedFullText: e.appliedFullText,
|
|
739
|
-
appliedChecks: e.appliedChecks,
|
|
740
|
-
appliedPrimaryKey: e.appliedPrimaryKey,
|
|
741
|
-
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
742
|
-
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
743
|
-
})),
|
|
744
|
-
validate: ((t) => N({
|
|
745
|
-
...e,
|
|
746
|
-
tableName: e.tableName,
|
|
747
|
-
fields: e.fields,
|
|
748
|
-
isReactive: e.isReactive,
|
|
749
|
-
appliedMixins: e.appliedMixins,
|
|
750
|
-
appliedIndexes: e.appliedIndexes,
|
|
751
|
-
appliedUniques: e.appliedUniques,
|
|
752
|
-
appliedFullText: e.appliedFullText,
|
|
753
|
-
appliedChecks: e.appliedChecks,
|
|
754
|
-
appliedPrimaryKey: e.appliedPrimaryKey,
|
|
755
|
-
insertSchema: t,
|
|
756
|
-
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
757
|
-
})),
|
|
758
|
-
validatePatch: ((n) => N({
|
|
759
|
-
...e,
|
|
760
|
-
tableName: e.tableName,
|
|
761
|
-
fields: e.fields,
|
|
762
|
-
isReactive: e.isReactive,
|
|
763
|
-
appliedMixins: e.appliedMixins,
|
|
764
|
-
appliedIndexes: e.appliedIndexes,
|
|
765
|
-
appliedUniques: e.appliedUniques,
|
|
766
|
-
appliedFullText: e.appliedFullText,
|
|
767
|
-
appliedChecks: e.appliedChecks,
|
|
768
|
-
appliedPrimaryKey: e.appliedPrimaryKey,
|
|
769
|
-
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
770
|
-
validatePatchSchema: t.partial(n)
|
|
771
|
-
}))
|
|
772
|
-
};
|
|
773
|
-
}, Ze = (e, t) => {
|
|
774
|
-
y(e);
|
|
775
|
-
let n = Object.entries(t).flatMap(([e, t]) => {
|
|
776
|
-
let n = m(t);
|
|
777
|
-
return n === void 0 ? [] : [{
|
|
778
|
-
column: e,
|
|
779
|
-
...n
|
|
780
|
-
}];
|
|
781
|
-
}), r = Xe(f(t), e);
|
|
782
|
-
for (let t of Object.keys(r)) b(e, t);
|
|
783
|
-
let i;
|
|
784
|
-
for (let [t, n] of Object.entries(r)) n.references === d && (n.references = () => {
|
|
785
|
-
if (i === void 0) throw Error(`selfReference() on '${e}.${t}' read before table() returned`);
|
|
786
|
-
return i;
|
|
787
|
-
});
|
|
788
|
-
return i = N({
|
|
789
|
-
appliedPluginRefs: n,
|
|
790
|
-
tableName: e,
|
|
791
|
-
fields: r,
|
|
792
|
-
isReactive: !0,
|
|
793
|
-
appliedMixins: [],
|
|
794
|
-
appliedIndexes: [],
|
|
795
|
-
appliedUniques: [],
|
|
796
|
-
appliedFullText: [],
|
|
797
|
-
appliedChecks: [],
|
|
798
|
-
appliedRules: []
|
|
799
|
-
}), i;
|
|
800
|
-
}, Qe = (e) => e === "sqlite" || e === "turso", $e = (e) => e === "mysql" || e === "mariadb", P = (e, t) => {
|
|
801
|
-
switch (t) {
|
|
802
|
-
case "mysql":
|
|
803
|
-
case "mariadb": return `\`${e.replace(/`/g, "``")}\``;
|
|
804
|
-
case "mssql": return `[${e.replace(/\]/g, "]]")}]`;
|
|
805
|
-
case "postgres":
|
|
806
|
-
case "sqlite":
|
|
807
|
-
case "turso": return `"${e.replace(/"/g, "\"\"")}"`;
|
|
808
|
-
}
|
|
809
|
-
}, et = 1e4, tt = Symbol.for("@voltro/database/tableRegistry"), F = globalThis, I = F[tt] ?? (F[tt] = /* @__PURE__ */ new Map()), L = (e) => {
|
|
810
|
-
let t = I.get(e.tableName);
|
|
811
|
-
if (t === void 0) {
|
|
812
|
-
I.set(e.tableName, e);
|
|
813
|
-
return;
|
|
814
|
-
}
|
|
815
|
-
if (t !== e) throw Error(`duplicate table '${e.tableName}' registration: two different table descriptors claim the same name. Rename one or import the shared module that defines it.`);
|
|
816
|
-
}, nt = (e) => {
|
|
817
|
-
I.get(e.tableName) === void 0 && I.set(e.tableName, e);
|
|
818
|
-
}, R = (e) => I.get(e), rt = (e) => {
|
|
819
|
-
let t = I.get(e);
|
|
820
|
-
if (t === void 0) throw Error(`table '${e}' is not registered. Register it by wrapping it in \`databaseHandle({ ... })\` (the usual path) or call \`registerTable(t)\` explicitly before this runs. Note a \`queryFor(t)\` query carries its own source table, so eager-loads don't hit this — this error means a reconstructed descriptor or by-name tooling reached an unregistered table.`);
|
|
821
|
-
return t;
|
|
822
|
-
}, it = () => [...I.values()], at = (e) => I.delete(e), ot = () => {
|
|
823
|
-
I.clear();
|
|
824
|
-
}, st = (e) => I.get(e)?.isReactive !== !1, ct = (e) => e.order ?? [], lt = (e) => ({
|
|
825
|
-
op: "count",
|
|
826
|
-
alias: e ?? "count"
|
|
827
|
-
}), ut = (e, t) => ({
|
|
828
|
-
op: "count-distinct",
|
|
829
|
-
column: e,
|
|
830
|
-
alias: t ?? `count_distinct_${e}`
|
|
831
|
-
}), dt = (e, t) => ({
|
|
832
|
-
op: "sum",
|
|
833
|
-
column: e,
|
|
834
|
-
alias: t ?? `sum_${e}`
|
|
835
|
-
}), ft = (e, t) => ({
|
|
836
|
-
op: "avg",
|
|
837
|
-
column: e,
|
|
838
|
-
alias: t ?? `avg_${e}`
|
|
839
|
-
}), pt = (e, t) => ({
|
|
840
|
-
op: "min",
|
|
841
|
-
column: e,
|
|
842
|
-
alias: t ?? `min_${e}`
|
|
843
|
-
}), mt = (e, t) => ({
|
|
844
|
-
op: "max",
|
|
845
|
-
column: e,
|
|
846
|
-
alias: t ?? `max_${e}`
|
|
847
|
-
}), ht = (e, t) => ({
|
|
848
|
-
op: "column",
|
|
849
|
-
column: e,
|
|
850
|
-
alias: t ?? e
|
|
851
|
-
}), z = (e) => (...t) => {
|
|
852
|
-
if (t.length < 2) throw Error(`${e}: requires at least two queries`);
|
|
853
|
-
return H({
|
|
854
|
-
table: t[0].descriptor.table,
|
|
855
|
-
predicate: void 0,
|
|
856
|
-
order: [],
|
|
857
|
-
take: void 0,
|
|
858
|
-
skip: void 0,
|
|
859
|
-
projection: void 0,
|
|
860
|
-
setOp: {
|
|
861
|
-
kind: e,
|
|
862
|
-
queries: t.map((e) => e.descriptor)
|
|
863
|
-
}
|
|
864
|
-
});
|
|
865
|
-
}, gt = z("union"), _t = z("union-all"), vt = z("intersect"), yt = z("except"), B = (e) => ({ over: (t) => ({
|
|
866
|
-
...e,
|
|
867
|
-
window: t
|
|
868
|
-
}) }), bt = (e = "rowNumber") => B({
|
|
869
|
-
op: "window-row-number",
|
|
870
|
-
alias: e
|
|
871
|
-
}), xt = (e = "rank") => B({
|
|
872
|
-
op: "window-rank",
|
|
873
|
-
alias: e
|
|
874
|
-
}), St = (e = "denseRank") => B({
|
|
875
|
-
op: "window-dense-rank",
|
|
876
|
-
alias: e
|
|
877
|
-
}), Ct = (e, t = 1, n) => B({
|
|
878
|
-
op: "window-lag",
|
|
879
|
-
column: e,
|
|
880
|
-
alias: n ?? `lag_${e}`,
|
|
881
|
-
offset: t
|
|
882
|
-
}), wt = (e, t = 1, n) => B({
|
|
883
|
-
op: "window-lead",
|
|
884
|
-
column: e,
|
|
885
|
-
alias: n ?? `lead_${e}`,
|
|
886
|
-
offset: t
|
|
887
|
-
}), Tt = (e, t) => B({
|
|
888
|
-
op: "window-sum-over",
|
|
889
|
-
column: e,
|
|
890
|
-
alias: t ?? `sum_${e}_over`
|
|
891
|
-
}), Et = (e, t) => B({
|
|
892
|
-
op: "window-avg-over",
|
|
893
|
-
column: e,
|
|
894
|
-
alias: t ?? `avg_${e}_over`
|
|
895
|
-
}), V = (e, t, n) => {
|
|
896
|
-
let r = n?.find((e) => e.name === t) ?? R(e)?.appliedFullText?.find((e) => e.name === t);
|
|
897
|
-
if (r === void 0) throw Error(`.matching('${t}', ...): no full-text index named '${t}' is declared on table '${e}'. Declare it with \`table(...).fullTextIndex('${t}', [columns])\` first.`);
|
|
898
|
-
return {
|
|
899
|
-
columns: r.columns,
|
|
900
|
-
...r.config === void 0 ? {} : { config: r.config },
|
|
901
|
-
...r.weights === void 0 ? {} : { weights: r.weights }
|
|
902
|
-
};
|
|
903
|
-
}, H = (e) => ({
|
|
904
|
-
descriptor: e,
|
|
905
|
-
where(t) {
|
|
906
|
-
let n = e.predicate ? { and: [e.predicate, t] } : t;
|
|
907
|
-
return H({
|
|
908
|
-
...e,
|
|
909
|
-
predicate: n
|
|
910
|
-
});
|
|
911
|
-
},
|
|
912
|
-
orderBy(t, n = "asc") {
|
|
913
|
-
return H({
|
|
914
|
-
...e,
|
|
915
|
-
order: [...e.order, {
|
|
916
|
-
column: t,
|
|
917
|
-
direction: n
|
|
918
|
-
}]
|
|
919
|
-
});
|
|
920
|
-
},
|
|
921
|
-
limit(t) {
|
|
922
|
-
return H({
|
|
923
|
-
...e,
|
|
924
|
-
take: t
|
|
925
|
-
});
|
|
926
|
-
},
|
|
927
|
-
offset(t) {
|
|
928
|
-
return H({
|
|
929
|
-
...e,
|
|
930
|
-
skip: t
|
|
931
|
-
});
|
|
932
|
-
},
|
|
933
|
-
select(...t) {
|
|
934
|
-
return H({
|
|
935
|
-
...e,
|
|
936
|
-
projection: t
|
|
937
|
-
});
|
|
938
|
-
},
|
|
939
|
-
using(t) {
|
|
940
|
-
return H({
|
|
941
|
-
...e,
|
|
942
|
-
usingIndex: t
|
|
943
|
-
});
|
|
944
|
-
},
|
|
945
|
-
withDeleted() {
|
|
946
|
-
return H({
|
|
947
|
-
...e,
|
|
948
|
-
includeDeleted: !0
|
|
949
|
-
});
|
|
950
|
-
},
|
|
951
|
-
forUpdate() {
|
|
952
|
-
return H({
|
|
953
|
-
...e,
|
|
954
|
-
lock: "update"
|
|
955
|
-
});
|
|
956
|
-
},
|
|
957
|
-
unscoped() {
|
|
958
|
-
return H({
|
|
959
|
-
...e,
|
|
960
|
-
crossTenant: !0
|
|
961
|
-
});
|
|
962
|
-
},
|
|
963
|
-
with(t) {
|
|
964
|
-
let n = {
|
|
965
|
-
...e.eager ?? {},
|
|
966
|
-
...t
|
|
967
|
-
};
|
|
968
|
-
return H({
|
|
969
|
-
...e,
|
|
970
|
-
eager: n
|
|
971
|
-
});
|
|
972
|
-
},
|
|
973
|
-
count() {
|
|
974
|
-
return H({
|
|
975
|
-
...e,
|
|
976
|
-
projection: void 0,
|
|
977
|
-
aggregations: [{
|
|
978
|
-
op: "count",
|
|
979
|
-
alias: "count"
|
|
980
|
-
}]
|
|
981
|
-
});
|
|
982
|
-
},
|
|
983
|
-
aggregate(t) {
|
|
984
|
-
let n = Object.entries(t).map(([e, t]) => ({
|
|
985
|
-
...t,
|
|
986
|
-
alias: e
|
|
987
|
-
}));
|
|
988
|
-
return H({
|
|
989
|
-
...e,
|
|
990
|
-
projection: void 0,
|
|
991
|
-
aggregations: n
|
|
992
|
-
});
|
|
993
|
-
},
|
|
994
|
-
matching(t, n) {
|
|
995
|
-
let r = V(e.table, t, e.fullTextIndexes);
|
|
996
|
-
return H({
|
|
997
|
-
...e,
|
|
998
|
-
fullTextSearch: {
|
|
999
|
-
indexName: t,
|
|
1000
|
-
query: n,
|
|
1001
|
-
columns: r.columns,
|
|
1002
|
-
...r.config === void 0 ? {} : { config: r.config },
|
|
1003
|
-
...r.weights === void 0 ? {} : { weights: r.weights }
|
|
1004
|
-
}
|
|
1005
|
-
});
|
|
1006
|
-
},
|
|
1007
|
-
rankBy(t) {
|
|
1008
|
-
let n = e.fullTextSearch;
|
|
1009
|
-
if (n === void 0) throw Error(".rankBy() requires a preceding .matching(...) clause — there is no full-text search to rank on this query.");
|
|
1010
|
-
return H({
|
|
1011
|
-
...e,
|
|
1012
|
-
fullTextSearch: {
|
|
1013
|
-
...n,
|
|
1014
|
-
rank: {
|
|
1015
|
-
alias: t?.alias ?? "rank",
|
|
1016
|
-
order: t?.order ?? !0
|
|
1017
|
-
}
|
|
1018
|
-
}
|
|
1019
|
-
});
|
|
1020
|
-
},
|
|
1021
|
-
nearestNeighbours(t, n, r) {
|
|
1022
|
-
if (typeof t == "string" && Array.isArray(n)) {
|
|
1023
|
-
let i = {
|
|
1024
|
-
column: t,
|
|
1025
|
-
queryVector: n,
|
|
1026
|
-
distance: r?.distance ?? "cosine",
|
|
1027
|
-
...e.annClause?.ef === void 0 ? {} : { ef: e.annClause.ef }
|
|
1028
|
-
};
|
|
1029
|
-
return H({
|
|
1030
|
-
...e,
|
|
1031
|
-
annClause: i
|
|
1032
|
-
});
|
|
1033
|
-
}
|
|
1034
|
-
if (typeof t == "string" && typeof n == "number") {
|
|
1035
|
-
let r = {
|
|
1036
|
-
column: "",
|
|
1037
|
-
queryText: t,
|
|
1038
|
-
distance: "cosine",
|
|
1039
|
-
...e.annClause?.ef === void 0 ? {} : { ef: e.annClause.ef }
|
|
1040
|
-
};
|
|
1041
|
-
return H({
|
|
1042
|
-
...e,
|
|
1043
|
-
annClause: r,
|
|
1044
|
-
take: n
|
|
1045
|
-
});
|
|
1046
|
-
}
|
|
1047
|
-
throw Error("nearestNeighbours: call as (column, queryVector, options?) or (queryString, k).");
|
|
1048
|
-
},
|
|
1049
|
-
efSearch(t) {
|
|
1050
|
-
let n = e.annClause ?? {
|
|
1051
|
-
column: "",
|
|
1052
|
-
distance: "cosine"
|
|
1053
|
-
};
|
|
1054
|
-
return H({
|
|
1055
|
-
...e,
|
|
1056
|
-
annClause: {
|
|
1057
|
-
...n,
|
|
1058
|
-
ef: t
|
|
1059
|
-
}
|
|
1060
|
-
});
|
|
1061
|
-
},
|
|
1062
|
-
use(t) {
|
|
1063
|
-
return H({ ...t(e) });
|
|
1064
|
-
},
|
|
1065
|
-
distinct() {
|
|
1066
|
-
return H({
|
|
1067
|
-
...e,
|
|
1068
|
-
distinct: !0
|
|
1069
|
-
});
|
|
1070
|
-
},
|
|
1071
|
-
distinctOn(t) {
|
|
1072
|
-
return H({
|
|
1073
|
-
...e,
|
|
1074
|
-
distinctOn: [...t]
|
|
1075
|
-
});
|
|
1076
|
-
},
|
|
1077
|
-
as(t) {
|
|
1078
|
-
return H({
|
|
1079
|
-
...e,
|
|
1080
|
-
alias: t
|
|
1081
|
-
});
|
|
1082
|
-
},
|
|
1083
|
-
innerJoin(t, n, r) {
|
|
1084
|
-
let i = typeof t == "string" ? t : t.tableName, a = [...e.joins ?? [], {
|
|
1085
|
-
kind: "inner",
|
|
1086
|
-
table: i,
|
|
1087
|
-
alias: n,
|
|
1088
|
-
on: r
|
|
1089
|
-
}];
|
|
1090
|
-
return H({
|
|
1091
|
-
...e,
|
|
1092
|
-
joins: a
|
|
1093
|
-
});
|
|
1094
|
-
},
|
|
1095
|
-
leftJoin(t, n, r) {
|
|
1096
|
-
let i = typeof t == "string" ? t : t.tableName, a = [...e.joins ?? [], {
|
|
1097
|
-
kind: "left",
|
|
1098
|
-
table: i,
|
|
1099
|
-
alias: n,
|
|
1100
|
-
on: r
|
|
1101
|
-
}];
|
|
1102
|
-
return H({
|
|
1103
|
-
...e,
|
|
1104
|
-
joins: a
|
|
1105
|
-
});
|
|
1106
|
-
},
|
|
1107
|
-
selectJoined(t) {
|
|
1108
|
-
let n = Object.entries(t).map(([e, t]) => ({
|
|
1109
|
-
outputKey: e,
|
|
1110
|
-
source: t
|
|
1111
|
-
}));
|
|
1112
|
-
return H({
|
|
1113
|
-
...e,
|
|
1114
|
-
projection: void 0,
|
|
1115
|
-
joinedProjection: n
|
|
1116
|
-
});
|
|
1117
|
-
},
|
|
1118
|
-
withCte(t, n) {
|
|
1119
|
-
let r = e.ctes ?? [];
|
|
1120
|
-
if (r.some((e) => e.name === t)) throw Error(`Query.withCte: duplicate CTE name '${t}'`);
|
|
1121
|
-
return H({
|
|
1122
|
-
...e,
|
|
1123
|
-
ctes: [...r, {
|
|
1124
|
-
name: t,
|
|
1125
|
-
descriptor: n
|
|
1126
|
-
}]
|
|
1127
|
-
});
|
|
1128
|
-
},
|
|
1129
|
-
recursiveCte(t, n) {
|
|
1130
|
-
let r = e.ctes ?? [];
|
|
1131
|
-
if (r.some((e) => e.name === t)) throw Error(`Query.recursiveCte: duplicate CTE name '${t}'`);
|
|
1132
|
-
return H({
|
|
1133
|
-
...e,
|
|
1134
|
-
ctes: [...r, {
|
|
1135
|
-
name: t,
|
|
1136
|
-
descriptor: n,
|
|
1137
|
-
recursive: !0
|
|
1138
|
-
}]
|
|
1139
|
-
});
|
|
1140
|
-
},
|
|
1141
|
-
groupBy(t) {
|
|
1142
|
-
let n = e.groupBy ? [...e.groupBy, ...t] : [...t];
|
|
1143
|
-
return H({
|
|
1144
|
-
...e,
|
|
1145
|
-
groupBy: n
|
|
1146
|
-
});
|
|
1147
|
-
},
|
|
1148
|
-
having(t) {
|
|
1149
|
-
let n = e.having ? { and: [e.having, t] } : t;
|
|
1150
|
-
return H({
|
|
1151
|
-
...e,
|
|
1152
|
-
having: n
|
|
1153
|
-
});
|
|
1154
|
-
},
|
|
1155
|
-
exists() {
|
|
1156
|
-
return H({
|
|
1157
|
-
...e,
|
|
1158
|
-
projection: void 0,
|
|
1159
|
-
aggregations: [{
|
|
1160
|
-
op: "count",
|
|
1161
|
-
alias: "__exists__"
|
|
1162
|
-
}],
|
|
1163
|
-
take: 1
|
|
1164
|
-
});
|
|
1165
|
-
}
|
|
1166
|
-
});
|
|
1167
|
-
function U(e) {
|
|
1168
|
-
return H({
|
|
1169
|
-
table: e.tableName,
|
|
1170
|
-
predicate: void 0,
|
|
1171
|
-
order: [],
|
|
1172
|
-
take: void 0,
|
|
1173
|
-
skip: void 0,
|
|
1174
|
-
projection: void 0,
|
|
1175
|
-
fullTextIndexes: e.appliedFullText,
|
|
1176
|
-
sourceTable: e
|
|
1177
|
-
});
|
|
1178
|
-
}
|
|
1179
|
-
var Dt = (e, t, n) => W(e, "id", t, n), W = (e, t, n, r, i = "asc") => {
|
|
1180
|
-
let a = [...e.order.filter((e) => e.column !== t), {
|
|
1181
|
-
column: t,
|
|
1182
|
-
direction: i
|
|
1183
|
-
}], o = n === void 0 ? void 0 : {
|
|
1184
|
-
column: t,
|
|
1185
|
-
op: i === "desc" ? "lt" : "gt",
|
|
1186
|
-
value: n
|
|
1187
|
-
}, s = o === void 0 ? e.predicate : e.predicate === void 0 ? o : { and: [e.predicate, o] };
|
|
1188
|
-
return {
|
|
1189
|
-
...e,
|
|
1190
|
-
predicate: s,
|
|
1191
|
-
order: a,
|
|
1192
|
-
take: r
|
|
1193
|
-
};
|
|
1194
|
-
}, Ot = (e) => {
|
|
1195
|
-
let t = {};
|
|
1196
|
-
for (let [n, r] of Object.entries(e)) L(r), t[n] = U(r);
|
|
1197
|
-
return t;
|
|
1198
|
-
}, kt = (e) => e.isView === !0, At = (e, t, n) => {
|
|
1199
|
-
if (y(e), n.trim().length === 0) throw Error(`view('${e}', …): the SELECT body is empty — a view must define a query.`);
|
|
1200
|
-
let r = f(t);
|
|
1201
|
-
for (let t of Object.keys(r)) b(e, t);
|
|
1202
|
-
return {
|
|
1203
|
-
tableName: e,
|
|
1204
|
-
fields: r,
|
|
1205
|
-
isView: !0,
|
|
1206
|
-
viewSelect: n
|
|
1207
|
-
};
|
|
1208
|
-
}, jt = (e) => U({
|
|
1209
|
-
...e,
|
|
1210
|
-
isReactive: !1,
|
|
1211
|
-
appliedMixins: [],
|
|
1212
|
-
appliedIndexes: [],
|
|
1213
|
-
appliedUniques: [],
|
|
1214
|
-
appliedFullText: [],
|
|
1215
|
-
appliedChecks: []
|
|
1216
|
-
}), Mt = (e, t, n = null) => {
|
|
1217
|
-
let r = n === null ? P(e.tableName, t) : `${P(n, t)}.${P(e.tableName, t)}`, i = e.viewSelect.trim();
|
|
1218
|
-
switch (t) {
|
|
1219
|
-
case "postgres":
|
|
1220
|
-
case "mysql":
|
|
1221
|
-
case "mariadb": return `CREATE OR REPLACE VIEW ${r} AS ${i};`;
|
|
1222
|
-
case "mssql": return `CREATE OR ALTER VIEW ${r} AS ${i};`;
|
|
1223
|
-
case "sqlite":
|
|
1224
|
-
case "turso": return `DROP VIEW IF EXISTS ${r};\nCREATE VIEW ${r} AS ${i};`;
|
|
1225
|
-
}
|
|
1226
|
-
}, Nt = (e) => e == null || typeof e == "boolean" ? e : typeof e == "number" ? e !== 0 : typeof e == "bigint" ? e !== 0n : typeof e == "string" ? e === "1" || e.toLowerCase() === "true" : e, G = (e) => {
|
|
1227
|
-
if (e == null || typeof e != "string") return e;
|
|
1228
|
-
let t = e.trim();
|
|
1229
|
-
if (t.length === 0) return e;
|
|
1230
|
-
let n = t.charAt(0);
|
|
1231
|
-
if (n !== "{" && n !== "[" && n !== "\"" && n !== "t" && n !== "f" && n !== "n" && (n < "0" || n > "9") && n !== "-") return e;
|
|
1232
|
-
try {
|
|
1233
|
-
return JSON.parse(t);
|
|
1234
|
-
} catch {
|
|
1235
|
-
return e;
|
|
1236
|
-
}
|
|
1237
|
-
}, Pt = (e) => e == null || typeof e == "string" ? e : typeof e == "number" || typeof e == "bigint" ? String(e) : e, Ft = (e) => {
|
|
1238
|
-
if (e == null || e instanceof Date) return e;
|
|
1239
|
-
if (typeof e == "string") {
|
|
1240
|
-
let t = new Date(e);
|
|
1241
|
-
return isNaN(t.getTime()) ? e : t;
|
|
1242
|
-
}
|
|
1243
|
-
if (typeof e == "number") {
|
|
1244
|
-
let t = new Date(e);
|
|
1245
|
-
return isNaN(t.getTime()) ? e : t;
|
|
1246
|
-
}
|
|
1247
|
-
return e;
|
|
1248
|
-
}, K = (e, t, n) => {
|
|
1249
|
-
if (e == null) return e;
|
|
1250
|
-
switch (t) {
|
|
1251
|
-
case "boolean": return n === "postgres" ? e : Nt(e);
|
|
1252
|
-
case "vector": return n === "postgres" ? G(e) : e;
|
|
1253
|
-
case "json": return n === "postgres" || n === "mysql" || n === "mariadb" ? e : G(e);
|
|
1254
|
-
case "array": return n === "postgres" ? e : G(e);
|
|
1255
|
-
case "timestamp":
|
|
1256
|
-
case "date": return n === "sqlite" || n === "turso" ? Ft(e) : e;
|
|
1257
|
-
case "decimal":
|
|
1258
|
-
case "bigint": return Pt(e);
|
|
1259
|
-
default: return e;
|
|
1260
|
-
}
|
|
1261
|
-
}, It = (e, t, n) => {
|
|
1262
|
-
if (e.length === 0) return e;
|
|
1263
|
-
let r = R(t);
|
|
1264
|
-
return r === void 0 ? e : q(e, r, n);
|
|
1265
|
-
}, q = (e, t, n) => {
|
|
1266
|
-
if (e.length === 0) return e;
|
|
1267
|
-
let r = t.fields, i = [];
|
|
1268
|
-
for (let [e, t] of Object.entries(r)) i.push({
|
|
1269
|
-
key: e,
|
|
1270
|
-
type: t.type
|
|
1271
|
-
});
|
|
1272
|
-
return e.map((e) => {
|
|
1273
|
-
let t = { ...e };
|
|
1274
|
-
for (let { key: e, type: r } of i) e in t && (t[e] = K(t[e], r, n));
|
|
1275
|
-
return t;
|
|
1276
|
-
});
|
|
1277
|
-
}, Lt = (e, t) => {
|
|
1278
|
-
if (e == null) return e;
|
|
1279
|
-
switch (t) {
|
|
1280
|
-
case "json": return JSON.stringify(e);
|
|
1281
|
-
case "array":
|
|
1282
|
-
case "vector": return typeof e == "string" ? e : JSON.stringify(e);
|
|
1283
|
-
default: return e;
|
|
1284
|
-
}
|
|
1285
|
-
}, Rt = (e, t, n = ["json", "array"]) => {
|
|
1286
|
-
let r = R(t);
|
|
1287
|
-
if (r === void 0) return e;
|
|
1288
|
-
let i = r.fields, a = null;
|
|
1289
|
-
for (let [t, r] of Object.entries(i)) if (n.includes(r.type) && t in e) {
|
|
1290
|
-
let n = Lt(e[t], r.type);
|
|
1291
|
-
n !== e[t] && (a === null && (a = { ...e }), a[t] = n);
|
|
1292
|
-
}
|
|
1293
|
-
return a ?? e;
|
|
1294
|
-
}, zt = /^[A-Za-z_][A-Za-z0-9_]*$/, Bt = (e) => "$" + e.map((e) => typeof e == "number" ? `[${e}]` : zt.test(e) ? `.${e}` : `."${e.replace(/"/g, "\\\"")}"`).join(""), Vt = (e) => "{" + e.map((e) => {
|
|
1295
|
-
let t = String(e);
|
|
1296
|
-
return /^[A-Za-z0-9_]+$/.test(t) ? t : `"${t.replace(/(["\\])/g, "\\$1")}"`;
|
|
1297
|
-
}).join(",") + "}", Ht = (e, t, n, r = {}) => {
|
|
1298
|
-
let i = P(e, n), a = r.numeric ?? !1;
|
|
1299
|
-
if (n === "postgres") {
|
|
1300
|
-
let e = `(${i} #>> '${Vt(t)}'::text[])`;
|
|
1301
|
-
return a ? `${e}::numeric` : e;
|
|
1302
|
-
}
|
|
1303
|
-
let o = Bt(t);
|
|
1304
|
-
switch (n) {
|
|
1305
|
-
case "mysql":
|
|
1306
|
-
case "mariadb": {
|
|
1307
|
-
let e = `JSON_UNQUOTE(JSON_EXTRACT(${i}, '${o}'))`;
|
|
1308
|
-
return a ? `CAST(${e} AS DECIMAL(38,10))` : e;
|
|
1309
|
-
}
|
|
1310
|
-
case "mssql": {
|
|
1311
|
-
let e = `JSON_VALUE(${i}, '${o}')`;
|
|
1312
|
-
return a ? `CAST(${e} AS FLOAT)` : e;
|
|
1313
|
-
}
|
|
1314
|
-
case "sqlite":
|
|
1315
|
-
case "turso": {
|
|
1316
|
-
let e = `json_extract(${i}, '${o}')`;
|
|
1317
|
-
return a ? `CAST(${e} AS REAL)` : e;
|
|
1318
|
-
}
|
|
1319
|
-
}
|
|
1320
|
-
}, J = (e, t) => {
|
|
1321
|
-
let n = (e) => {
|
|
1322
|
-
if (typeof e != "string" || !/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/.test(e)) return null;
|
|
1323
|
-
let [t = "", n = ""] = e.replace(/^[+-]/, "").split("."), r = t.replace(/^0+/, "") || "0";
|
|
1324
|
-
return {
|
|
1325
|
-
negative: e.startsWith("-") && /[1-9]/.test(r + n),
|
|
1326
|
-
whole: r,
|
|
1327
|
-
fraction: n
|
|
1328
|
-
};
|
|
1329
|
-
}, r = n(e), i = n(t);
|
|
1330
|
-
if (!r || !i) return null;
|
|
1331
|
-
if (r.negative !== i.negative) return r.negative ? -1 : 1;
|
|
1332
|
-
let a = r.whole.length - i.whole.length;
|
|
1333
|
-
if (a === 0 && (a = r.whole === i.whole ? 0 : r.whole > i.whole ? 1 : -1), a === 0) {
|
|
1334
|
-
let e = Math.max(r.fraction.length, i.fraction.length), t = r.fraction.padEnd(e, "0"), n = i.fraction.padEnd(e, "0");
|
|
1335
|
-
a = t === n ? 0 : t > n ? 1 : -1;
|
|
1336
|
-
}
|
|
1337
|
-
return a === 0 ? 0 : (a > 0 ? 1 : -1) * (r.negative ? -1 : 1);
|
|
1338
|
-
}, Ut = (e, t) => ({
|
|
1339
|
-
column: e,
|
|
1340
|
-
op: "eq",
|
|
1341
|
-
value: t
|
|
1342
|
-
}), Wt = (e, t) => ({
|
|
1343
|
-
column: e,
|
|
1344
|
-
op: "neq",
|
|
1345
|
-
value: t
|
|
1346
|
-
}), Gt = (e, t) => ({
|
|
1347
|
-
column: e,
|
|
1348
|
-
op: "gt",
|
|
1349
|
-
value: t
|
|
1350
|
-
}), Kt = (e, t) => ({
|
|
1351
|
-
column: e,
|
|
1352
|
-
op: "gte",
|
|
1353
|
-
value: t
|
|
1354
|
-
}), qt = (e, t) => ({
|
|
1355
|
-
column: e,
|
|
1356
|
-
op: "lt",
|
|
1357
|
-
value: t
|
|
1358
|
-
}), Jt = (e, t) => ({
|
|
1359
|
-
column: e,
|
|
1360
|
-
op: "lte",
|
|
1361
|
-
value: t
|
|
1362
|
-
}), Yt = (e, t) => ({
|
|
1363
|
-
column: e,
|
|
1364
|
-
op: "in",
|
|
1365
|
-
value: t
|
|
1366
|
-
}), Xt = (e, t) => ({
|
|
1367
|
-
column: e,
|
|
1368
|
-
op: "notIn",
|
|
1369
|
-
value: t
|
|
1370
|
-
}), Zt = (e, t) => ({
|
|
1371
|
-
column: e,
|
|
1372
|
-
op: "contains",
|
|
1373
|
-
value: t
|
|
1374
|
-
}), Qt = (e, t) => ({
|
|
1375
|
-
column: e,
|
|
1376
|
-
op: "startsWith",
|
|
1377
|
-
value: t
|
|
1378
|
-
}), $t = (e, t) => ({
|
|
1379
|
-
column: e,
|
|
1380
|
-
op: "arrayContains",
|
|
1381
|
-
value: t
|
|
1382
|
-
}), en = (e, t) => ({
|
|
1383
|
-
column: e,
|
|
1384
|
-
op: "arrayOverlaps",
|
|
1385
|
-
value: t
|
|
1386
|
-
}), tn = (e, t) => ({
|
|
1387
|
-
column: e,
|
|
1388
|
-
op: "arrayHas",
|
|
1389
|
-
value: t
|
|
1390
|
-
}), nn = {
|
|
1391
|
-
column: "id",
|
|
1392
|
-
op: "in",
|
|
1393
|
-
value: []
|
|
1394
|
-
}, rn = (e) => ({
|
|
1395
|
-
column: e,
|
|
1396
|
-
op: "isNull"
|
|
1397
|
-
}), an = (e) => ({
|
|
1398
|
-
column: e,
|
|
1399
|
-
op: "isNotNull"
|
|
1400
|
-
}), on = (e, t) => ({
|
|
1401
|
-
column: e,
|
|
1402
|
-
op: "spatial",
|
|
1403
|
-
value: t
|
|
1404
|
-
}), sn = (...e) => ({ and: e }), cn = (...e) => ({ or: e }), ln = (e) => ({ not: e }), un = (e, ...t) => {
|
|
1405
|
-
if (t.length === 0) throw Error(`jsonField("${e}"): at least one path segment is required`);
|
|
1406
|
-
let n = (n, r) => ({
|
|
1407
|
-
column: e,
|
|
1408
|
-
path: t,
|
|
1409
|
-
op: n,
|
|
1410
|
-
value: r
|
|
1411
|
-
});
|
|
1412
|
-
return {
|
|
1413
|
-
eq: (e) => n("eq", e),
|
|
1414
|
-
neq: (e) => n("neq", e),
|
|
1415
|
-
gt: (e) => n("gt", e),
|
|
1416
|
-
gte: (e) => n("gte", e),
|
|
1417
|
-
lt: (e) => n("lt", e),
|
|
1418
|
-
lte: (e) => n("lte", e),
|
|
1419
|
-
inSet: (e) => n("in", e),
|
|
1420
|
-
notInSet: (e) => n("notIn", e),
|
|
1421
|
-
contains: (e) => n("contains", e),
|
|
1422
|
-
startsWith: (e) => n("startsWith", e),
|
|
1423
|
-
isNull: () => n("isNull"),
|
|
1424
|
-
isNotNull: () => n("isNotNull")
|
|
1425
|
-
};
|
|
1426
|
-
}, Y = (e) => "descriptor" in e ? e.descriptor : e, dn = (e, t) => ({
|
|
1427
|
-
column: e,
|
|
1428
|
-
op: "subquery-in",
|
|
1429
|
-
subquery: Y(t)
|
|
1430
|
-
}), fn = (e, t) => ({
|
|
1431
|
-
column: e,
|
|
1432
|
-
op: "subquery-not-in",
|
|
1433
|
-
subquery: Y(t)
|
|
1434
|
-
}), pn = (e) => ({
|
|
1435
|
-
op: "exists",
|
|
1436
|
-
subquery: Y(e)
|
|
1437
|
-
}), mn = (e) => ({
|
|
1438
|
-
op: "not-exists",
|
|
1439
|
-
subquery: Y(e)
|
|
1440
|
-
}), hn = /^\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?)?$/, gn = (e) => {
|
|
1441
|
-
if (e instanceof Date) return e.getTime();
|
|
1442
|
-
if (typeof e == "string" && hn.test(e)) {
|
|
1443
|
-
let t = Date.parse(e);
|
|
1444
|
-
return Number.isNaN(t) ? void 0 : t;
|
|
1445
|
-
}
|
|
1446
|
-
}, _n = (e, t) => {
|
|
1447
|
-
if (!(e instanceof Date) && !(t instanceof Date)) return;
|
|
1448
|
-
let n = gn(e), r = gn(t);
|
|
1449
|
-
return n === void 0 || r === void 0 ? void 0 : [n, r];
|
|
1450
|
-
}, vn = (e, t) => {
|
|
1451
|
-
if (e === t) return !0;
|
|
1452
|
-
let n = _n(e, t);
|
|
1453
|
-
return n !== void 0 && n[0] === n[1];
|
|
1454
|
-
}, yn = (e, t) => {
|
|
1455
|
-
if (e == null || t == null) return null;
|
|
1456
|
-
let n = _n(e, t);
|
|
1457
|
-
if (n !== void 0) return n[0] === n[1] ? 0 : n[0] > n[1] ? 1 : -1;
|
|
1458
|
-
let r = e instanceof Date ? e.getTime() : e, i = t instanceof Date ? t.getTime() : t;
|
|
1459
|
-
return typeof r == typeof i ? r === i ? 0 : r > i ? 1 : -1 : null;
|
|
1460
|
-
}, X = (e, t, n = null, r = {}) => {
|
|
1461
|
-
if (!t) return !1;
|
|
1462
|
-
if ("not" in e) return !X(e.not, t, n, r);
|
|
1463
|
-
if ("and" in e) {
|
|
1464
|
-
for (let i of e.and) if (!X(i, t, n, r)) return !1;
|
|
1465
|
-
return !0;
|
|
1466
|
-
}
|
|
1467
|
-
if ("or" in e) {
|
|
1468
|
-
for (let i of e.or) if (X(i, t, n, r)) return !0;
|
|
1469
|
-
return !1;
|
|
1470
|
-
}
|
|
1471
|
-
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
1472
|
-
if (!n) return !1;
|
|
1473
|
-
let i = n.get(e.subquery);
|
|
1474
|
-
if (!(i instanceof Set)) return !1;
|
|
1475
|
-
let a = t[e.column], o = r[e.column]?.type === "decimal" ? [...i].some((e) => J(a, e) === 0) : i.has(a);
|
|
1476
|
-
return e.op === "subquery-in" ? o : !o;
|
|
1477
|
-
}
|
|
1478
|
-
if (e.op === "exists" || e.op === "not-exists") {
|
|
1479
|
-
if (!n) return !1;
|
|
1480
|
-
let t = n.get(e.subquery), r = typeof t == "number" ? t > 0 : t instanceof Set && t.size > 0;
|
|
1481
|
-
return e.op === "exists" ? r : !r;
|
|
1482
|
-
}
|
|
1483
|
-
let i = e, a = t[i.column], o = r[i.column]?.type === "decimal", s = (e, t) => o && e != null && t != null ? J(e, t) === 0 : vn(e, t), c = o ? J : yn;
|
|
1484
|
-
switch (i.op) {
|
|
1485
|
-
case "eq": return s(a, i.value);
|
|
1486
|
-
case "neq": return !s(a, i.value);
|
|
1487
|
-
case "gt": return (c(a, i.value) ?? -1) > 0;
|
|
1488
|
-
case "gte": return (c(a, i.value) ?? -1) >= 0;
|
|
1489
|
-
case "lt": return (c(a, i.value) ?? 1) < 0;
|
|
1490
|
-
case "lte": return (c(a, i.value) ?? 1) <= 0;
|
|
1491
|
-
case "in": return Array.isArray(i.value) && i.value.some((e) => s(a, e));
|
|
1492
|
-
case "notIn": return Array.isArray(i.value) && !i.value.some((e) => s(a, e));
|
|
1493
|
-
case "contains": return typeof a == "string" && typeof i.value == "string" && a.toLowerCase().includes(i.value.toLowerCase());
|
|
1494
|
-
case "startsWith": return typeof a == "string" && typeof i.value == "string" && a.startsWith(i.value);
|
|
1495
|
-
case "arrayContains": {
|
|
1496
|
-
let e = Array.isArray(a) ? a : [];
|
|
1497
|
-
return (Array.isArray(i.value) ? i.value : []).every((t) => e.includes(t));
|
|
1498
|
-
}
|
|
1499
|
-
case "arrayOverlaps": {
|
|
1500
|
-
let e = Array.isArray(a) ? a : [];
|
|
1501
|
-
return (Array.isArray(i.value) ? i.value : []).some((t) => e.includes(t));
|
|
1502
|
-
}
|
|
1503
|
-
case "arrayHas": return Array.isArray(a) && a.includes(i.value);
|
|
1504
|
-
case "isNull": return a == null;
|
|
1505
|
-
case "isNotNull": return a != null;
|
|
1506
|
-
case "spatial": throw Error("@voltro/plugin-postgis: spatial predicates (ST_DWithin / ST_Contains / ST_Within / ST_Intersects / bbox &&) are not evaluable in-memory — use them in one-shot ctx.store.query reads, not reactive subscriptions.");
|
|
1507
|
-
}
|
|
1508
|
-
}, Z = function* (e) {
|
|
1509
|
-
if ("not" in e) {
|
|
1510
|
-
yield* Z(e.not);
|
|
1511
|
-
return;
|
|
1512
|
-
}
|
|
1513
|
-
if ("and" in e) {
|
|
1514
|
-
for (let t of e.and) yield* Z(t);
|
|
1515
|
-
return;
|
|
1516
|
-
}
|
|
1517
|
-
if ("or" in e) {
|
|
1518
|
-
for (let t of e.or) yield* Z(t);
|
|
1519
|
-
return;
|
|
1520
|
-
}
|
|
1521
|
-
e.op === "subquery-in" || e.op === "subquery-not-in" ? yield {
|
|
1522
|
-
kind: "in",
|
|
1523
|
-
descriptor: e.subquery
|
|
1524
|
-
} : (e.op === "exists" || e.op === "not-exists") && (yield {
|
|
1525
|
-
kind: "exists",
|
|
1526
|
-
descriptor: e.subquery
|
|
1527
|
-
});
|
|
1528
|
-
}, Q = function* (e, t = !0) {
|
|
1529
|
-
if ("not" in e) {
|
|
1530
|
-
yield* Q(e.not, !1);
|
|
1531
|
-
return;
|
|
1532
|
-
}
|
|
1533
|
-
if ("and" in e) {
|
|
1534
|
-
for (let n of e.and) yield* Q(n, t);
|
|
1535
|
-
return;
|
|
1536
|
-
}
|
|
1537
|
-
if ("or" in e) {
|
|
1538
|
-
for (let t of e.or) yield* Q(t, !1);
|
|
1539
|
-
return;
|
|
1540
|
-
}
|
|
1541
|
-
e.op !== "subquery-in" && e.op !== "subquery-not-in" && e.op !== "exists" && e.op !== "not-exists" && (yield {
|
|
1542
|
-
...e,
|
|
1543
|
-
conjunctive: t
|
|
1544
|
-
});
|
|
1545
|
-
}, bn = (e, t) => ({
|
|
1546
|
-
name: e,
|
|
1547
|
-
body: t
|
|
1548
|
-
}), xn = (e) => {
|
|
1549
|
-
if (e.lifecycle === "cron" && !e.cron) throw Error(`seed "${e.id}": lifecycle 'cron' requires a 'cron' field`);
|
|
1550
|
-
if (e.lifecycle === "onSchemaChange" && (!e.watchedTables || e.watchedTables.length === 0)) throw Error(`seed "${e.id}": lifecycle 'onSchemaChange' requires at least one entry in 'watchedTables'`);
|
|
1551
|
-
let t = e.steps({ step: bn });
|
|
1552
|
-
if (t.length === 0) throw Error(`seed "${e.id}": at least one step is required`);
|
|
1553
|
-
return {
|
|
1554
|
-
__seed: !0,
|
|
1555
|
-
id: e.id,
|
|
1556
|
-
name: e.name,
|
|
1557
|
-
lifecycle: e.lifecycle,
|
|
1558
|
-
...e.cron === void 0 ? {} : { cron: e.cron },
|
|
1559
|
-
...e.timezone === void 0 ? {} : { timezone: e.timezone },
|
|
1560
|
-
...e.watchedTables === void 0 ? {} : { watchedTables: e.watchedTables },
|
|
1561
|
-
...e.fingerprint === void 0 ? {} : { fingerprint: e.fingerprint },
|
|
1562
|
-
steps: t
|
|
1563
|
-
};
|
|
1564
|
-
}, Sn = (e) => typeof e == "object" && !!e && "__seed" in e && e.__seed === !0, Cn = null, wn = null, Tn = (e) => {
|
|
1565
|
-
Cn = e;
|
|
1566
|
-
}, En = (e) => {
|
|
1567
|
-
wn = e;
|
|
1568
|
-
}, Dn = async (e) => {
|
|
1569
|
-
let t = Cn;
|
|
1570
|
-
t !== null && await t(e);
|
|
1571
|
-
}, On = async (e) => {
|
|
1572
|
-
let t = wn;
|
|
1573
|
-
t !== null && e.changedTables.length !== 0 && await t(e);
|
|
1574
|
-
}, kn = (e) => {
|
|
1575
|
-
if (!e.id || e.id.length === 0) throw Error("migration: `id` is required + must be non-empty");
|
|
1576
|
-
if (!e.up || !e.down) throw Error(`migration ${e.id}: both \`up\` and \`down\` must be functions`);
|
|
1577
|
-
return e;
|
|
1578
|
-
}, $ = Symbol.for("voltro.migration.irreversible"), An = class extends Error {
|
|
1579
|
-
migrationId;
|
|
1580
|
-
reason;
|
|
1581
|
-
_tag = "IrreversibleMigrationError";
|
|
1582
|
-
constructor(e, t) {
|
|
1583
|
-
super(`migration ${e} cannot be rolled back: ${t}`), this.migrationId = e, this.reason = t, this.name = "IrreversibleMigrationError";
|
|
1584
|
-
}
|
|
1585
|
-
}, jn = (t) => {
|
|
1586
|
-
if (!t || t.trim().length === 0) throw Error("irreversible(): a reason is required");
|
|
1587
|
-
return Object.assign(() => e.fail(new An("<unknown>", t)), { [$]: t });
|
|
1588
|
-
}, Mn = (e) => {
|
|
1589
|
-
let t = e[$];
|
|
1590
|
-
return typeof t == "string" ? t : void 0;
|
|
1591
|
-
}, Nn = class {
|
|
1592
|
-
reason;
|
|
1593
|
-
_tag = "MigrationSkipped";
|
|
1594
|
-
constructor(e) {
|
|
1595
|
-
this.reason = e;
|
|
1596
|
-
}
|
|
1597
|
-
}, Pn = class extends Error {
|
|
1598
|
-
migrationId;
|
|
1599
|
-
failed;
|
|
1600
|
-
_tag = "MigrationExpectationFailed";
|
|
1601
|
-
constructor(e, t) {
|
|
1602
|
-
super(`migration ${e}: ${t.length} post-condition(s) did not hold after up():\n` + t.map((e) => ` - ${e}`).join("\n") + "\n The migration is NOT recorded; the next run applies it again."), this.migrationId = e, this.failed = t, this.name = "MigrationExpectationFailed";
|
|
1603
|
-
}
|
|
1604
|
-
}, Fn = class extends Error {
|
|
1605
|
-
migrationId;
|
|
1606
|
-
dialect;
|
|
1607
|
-
_tag = "TransactionBrokenByBodyError";
|
|
1608
|
-
constructor(e, t) {
|
|
1609
|
-
super(`migration ${e} is transactional, and its body COMMITTED the transaction from inside — on ${t} a DDL statement commits everything before it. The work is in the database and the migration is recorded; it will not run again. What did not hold is the all-or-nothing guarantee. Either mark it \`transactional: false\` (per-statement, resumable through your own idempotency) or move the schema change into \`ctx.schema\` in a migration of its own and keep this one to data.`), this.migrationId = e, this.dialect = t, this.name = "TransactionBrokenByBodyError";
|
|
1610
|
-
}
|
|
1611
|
-
}, In = class extends Error {
|
|
1612
|
-
table;
|
|
1613
|
-
report;
|
|
1614
|
-
_tag = "RewriteUnstableError";
|
|
1615
|
-
constructor(e, t) {
|
|
1616
|
-
super(`rewrite of ${e} did not stabilise after ${t.passes} pass(es): ${t.rewritten} rewritten, ${t.contended} contended on the last pass. Something is still writing these rows — raise maxPasses, or stop the writer first.`), this.table = e, this.report = t, this.name = "RewriteUnstableError";
|
|
1617
|
-
}
|
|
1618
|
-
}, Ln = /^\d{8}_\d{6}_[a-z0-9_]+\.ts$/, Rn = (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", zn = /* @__PURE__ */ new Set(["voltro_isr_cache"]), Bn = (e) => zn.has(e) || e.startsWith("_voltro_") || e.startsWith("_cloud_") || e.startsWith("cluster_") || e.startsWith("__turso_internal_"), Vn = "_voltro_staging_", Hn = (e) => e.startsWith(Vn), Un = /__dropped_\d{14}$/, Wn = (e) => Un.test(e), Gn = 7, Kn = (e) => {
|
|
1619
|
-
let t = /__dropped_(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/.exec(e);
|
|
1620
|
-
if (t === null) return;
|
|
1621
|
-
let [, n, r, i, a, o, s] = t;
|
|
1622
|
-
return new Date(Date.UTC(Number(n), Number(r) - 1, Number(i), Number(a), Number(o), Number(s)));
|
|
1623
|
-
}, qn = (e, t = {}) => {
|
|
1624
|
-
let n = t.now ?? /* @__PURE__ */ new Date(), r = t.retentionDays ?? 7, i = [], a = (e, t) => {
|
|
1625
|
-
let a = Kn(e);
|
|
1626
|
-
if (a === void 0) return;
|
|
1627
|
-
let o = Math.floor((n.getTime() - a.getTime()) / 864e5);
|
|
1628
|
-
o >= r && i.push({
|
|
1629
|
-
name: t,
|
|
1630
|
-
droppedAt: a,
|
|
1631
|
-
ageDays: o
|
|
1632
|
-
});
|
|
1633
|
-
};
|
|
1634
|
-
for (let t of e.tables) if (a(t.name, t.name), !Wn(t.name)) for (let e of t.columns ?? []) a(e.name, `${t.name}.${e.name}`);
|
|
1635
|
-
return i;
|
|
1636
|
-
}, Jn = (e, t) => {
|
|
1637
|
-
let n = e.reduce((e, t) => e.ageDays >= t.ageDays ? e : t), r = (/* @__PURE__ */ new Date(Date.now() - t * 864e5)).toISOString().slice(0, 10);
|
|
1638
|
-
return `${e.length} soft-drop snapshot(s) older than ${t} day(s) still hold the dropped data (oldest: ${n.name}, ${n.ageDays}d) — ${e.map((e) => e.name).join(", ")}. Restore with \`voltro db restore-snapshot\` or reclaim with \`voltro db gc-snapshots --before ${r}\`; the window is \`database.softDropRetentionDays\` in app.config.`;
|
|
1639
|
-
};
|
|
1640
|
-
//#endregion
|
|
1641
|
-
export { Q as $, D as $t, en as A, ge as An, dt as At, an as B, o as Bn, rt as Bt, Sn as C, pe as Cn, ct as Ct, sn as D, le as Dn, xt as Dt, nn as E, fe as En, U as Et, pn as F, ye as Fn, ot as Ft, Wt as G, u as Gn, P as Gt, un as H, he as Hn, et as Ht, Gt as I, ue as In, nt as It, Xt as J, Ze as Jt, ln as K, ce as Kn, qe as Kt, Kt as L, f as Ln, R as Lt, Zt as M, xe as Mn, gt as Mt, Ut as N, ee as Nn, _t as Nt, $t as O, oe as On, V as Ot, X as P, te as Pn, it as Pt, Qt as Q, A as Qt, Yt as R, ie as Rn, st as Rt, Dn as S, de as Sn, pt as St, Tn as T, a as Tn, Dt as Tt, qt as U, me as Un, $e as Ut, rn as V, ne as Vn, at as Vt, Jt as W, i as Wn, Qe as Wt, cn as X, We as Xt, fn as Y, Ke as Yt, on as Z, k as Zt, Mn as _, c as _n, yt as _t, Jn as a, ke as an, Rt as at, xn as b, ae as bn, wt as bt, Hn as c, x as cn, At as ct, An as d, Ee as dn, Et as dt, Ue as en, J as et, Pn as f, De as fn, ht as ft, jn as g, m as gn, St as gt, Fn as h, Ce as hn, Ot as ht, qn as i, Oe as in, It as it, Z as j, be as jn, Tt as jt, tn as k, re as kn, bt as kt, Kn as l, y as ln, Mt as lt, In as m, Te as mn, ut as mt, zn as n, E as nn, K as nt, Bn as o, Ae as on, kt as ot, Nn as p, we as pn, lt as pt, mn as q, _e as qn, Ge as qt, Vn as r, Ve as rn, q as rt, Wn as s, b as sn, jt as st, Gn as t, O as tn, Ht as tt, Ln as u, S as un, ft as ut, Rn as v, d as vn, vt, En as w, s as wn, W as wt, On as x, se as xn, mt as xt, kn as y, ve as yn, Ct as yt, dn as z, Se as zn, L as zt };
|