@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
|
@@ -0,0 +1,2186 @@
|
|
|
1
|
+
import { Cause as e, Effect as t, Runtime as n, Schema as r } from "effect";
|
|
2
|
+
import { typeid as i } from "typeid-js";
|
|
3
|
+
import { ulid as a } from "ulidx";
|
|
4
|
+
//#region src/columns.ts
|
|
5
|
+
var o = (e) => {
|
|
6
|
+
let t = [];
|
|
7
|
+
for (let [n, r] of Object.entries(e.fields)) r.serverOnly === !0 && t.push(n);
|
|
8
|
+
return t;
|
|
9
|
+
}, s = (e) => {
|
|
10
|
+
let t = [];
|
|
11
|
+
for (let [n, r] of Object.entries(e.fields)) r.crdtManaged === !0 && t.push(n);
|
|
12
|
+
return t;
|
|
13
|
+
}, c = (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
|
+
}, l = (e) => {
|
|
24
|
+
let t = [];
|
|
25
|
+
for (let [n, r] of Object.entries(e.fields)) r.crdtManaged === !0 && t.push(n);
|
|
26
|
+
return t;
|
|
27
|
+
}, u = 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
|
+
}, d = (e) => new u({
|
|
189
|
+
type: e,
|
|
190
|
+
nullable: !1,
|
|
191
|
+
unique: !1,
|
|
192
|
+
hasDefault: !1
|
|
193
|
+
});
|
|
194
|
+
function f(e) {
|
|
195
|
+
return new u({
|
|
196
|
+
type: "id",
|
|
197
|
+
nullable: !1,
|
|
198
|
+
unique: !0,
|
|
199
|
+
hasDefault: !1,
|
|
200
|
+
idSchemeInput: e
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
var p = () => d("text"), m = () => d("integer"), h = () => d("real"), g = (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 u({
|
|
207
|
+
type: "decimal",
|
|
208
|
+
nullable: !1,
|
|
209
|
+
unique: !1,
|
|
210
|
+
hasDefault: !1,
|
|
211
|
+
precision: e,
|
|
212
|
+
scale: t
|
|
213
|
+
});
|
|
214
|
+
}, ee = g, te = () => d("bigint"), ne = (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 u({
|
|
220
|
+
type: "enum",
|
|
221
|
+
nullable: !1,
|
|
222
|
+
unique: !1,
|
|
223
|
+
hasDefault: !1,
|
|
224
|
+
enumName: e,
|
|
225
|
+
enumValues: t
|
|
226
|
+
})
|
|
227
|
+
};
|
|
228
|
+
}, re = () => d("boolean"), _ = () => d("timestamp"), ie = () => d("date"), v = () => d("json"), y = () => d("bytes"), b = () => new u({
|
|
229
|
+
type: "bytes",
|
|
230
|
+
nullable: !0,
|
|
231
|
+
unique: !1,
|
|
232
|
+
hasDefault: !1,
|
|
233
|
+
crdtManaged: !0
|
|
234
|
+
}), ae = () => new u({
|
|
235
|
+
type: "bytes",
|
|
236
|
+
nullable: !0,
|
|
237
|
+
unique: !1,
|
|
238
|
+
hasDefault: !1,
|
|
239
|
+
crdtManaged: !0
|
|
240
|
+
}), x = () => {
|
|
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 S(e) {
|
|
244
|
+
return C(x, e);
|
|
245
|
+
}
|
|
246
|
+
function C(e, t) {
|
|
247
|
+
return new u({
|
|
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 oe = () => new u({
|
|
263
|
+
type: "text",
|
|
264
|
+
nullable: !0,
|
|
265
|
+
unique: !1,
|
|
266
|
+
hasDefault: !1,
|
|
267
|
+
dropped: !0
|
|
268
|
+
}), se = (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 u({
|
|
271
|
+
type: "vector",
|
|
272
|
+
nullable: !1,
|
|
273
|
+
unique: !1,
|
|
274
|
+
hasDefault: !1,
|
|
275
|
+
vectorDim: e,
|
|
276
|
+
vectorPrecision: t?.precision ?? "float32"
|
|
277
|
+
});
|
|
278
|
+
}, ce = (e) => new u({
|
|
279
|
+
type: "array",
|
|
280
|
+
nullable: !1,
|
|
281
|
+
unique: !1,
|
|
282
|
+
hasDefault: !1,
|
|
283
|
+
arrayElement: e.__definition().type
|
|
284
|
+
}), le = () => d("interval"), ue = (e, t = 4326) => new u({
|
|
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
|
+
}), de = (e, t = 4326) => new u({
|
|
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
|
+
}), fe = (e) => new u({
|
|
305
|
+
type: "raw",
|
|
306
|
+
nullable: !1,
|
|
307
|
+
unique: !1,
|
|
308
|
+
hasDefault: !1,
|
|
309
|
+
rawDdl: e
|
|
310
|
+
}), w = (e) => {
|
|
311
|
+
let t = {};
|
|
312
|
+
for (let [n, r] of Object.entries(e)) t[n] = r.__definition();
|
|
313
|
+
return t;
|
|
314
|
+
}, pe = /* @__PURE__ */ new WeakMap(), me = (e) => typeof e == "object" && e ? pe.get(e) : void 0, he = (e, t = {}) => {
|
|
315
|
+
let n = p();
|
|
316
|
+
return pe.set(n, {
|
|
317
|
+
target: e,
|
|
318
|
+
orphanPolicy: t.orphanPolicy ?? "keep",
|
|
319
|
+
onSoftDelete: t.onSoftDelete ?? !1
|
|
320
|
+
}), n;
|
|
321
|
+
}, T = /* @__PURE__ */ new Map(), ge = (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 = T.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), T.set(e, n);
|
|
329
|
+
}, _e = (e) => T.get(e) ?? [], ve = () => T, ye = () => {
|
|
330
|
+
T.clear();
|
|
331
|
+
}, be = (t) => {
|
|
332
|
+
let r = t;
|
|
333
|
+
for (let t = 0; t < 4 && n.isFiberFailure(r); t++) r = e.squash(r[n.FiberFailureCauseId]);
|
|
334
|
+
return r;
|
|
335
|
+
}, xe = (t, r = 0) => {
|
|
336
|
+
if (r >= 4 || !n.isFiberFailure(t)) return [t];
|
|
337
|
+
let i = t[n.FiberFailureCauseId], a = [...e.failures(i), ...e.defects(i)];
|
|
338
|
+
if (a.length === 0) return [e.squash(i)];
|
|
339
|
+
let o = [];
|
|
340
|
+
for (let e of a.slice(0, 8)) o.push(...xe(e, r + 1));
|
|
341
|
+
return o;
|
|
342
|
+
}, Se = (e) => e.dbCode !== void 0 || e.dbErrno !== void 0 || e.dbNumber !== void 0 || e.dbSqlState !== void 0 || e.dbConstraint !== void 0, Ce = (e) => {
|
|
343
|
+
let t = {}, n = [], r = be(e);
|
|
344
|
+
for (let e = 0; e < 8 && typeof r == "object" && r; e++) {
|
|
345
|
+
let e = r;
|
|
346
|
+
t.dbCode === void 0 && (typeof e.code == "string" || typeof e.code == "number") && (t.dbCode = e.code), t.dbErrno === void 0 && typeof e.errno == "number" && (t.dbErrno = e.errno), t.dbNumber === void 0 && typeof e.number == "number" && (t.dbNumber = e.number), t.dbSqlState === void 0 && typeof e.sqlState == "string" && (t.dbSqlState = e.sqlState), t.dbBindings === void 0 && typeof e.voltroBindings == "string" && (t.dbBindings = e.voltroBindings), t.dbStatement === void 0 && typeof e.sql == "string" && e.sql.includes("?") && (t.dbStatement = e.sql, t.dbPlaceholders = (e.sql.match(/\?/g) ?? []).length), t.dbFatal === void 0 && typeof e.fatal == "boolean" && (t.dbFatal = e.fatal), t.dbConstraint === void 0 && typeof e.constraint == "string" && (t.dbConstraint = e.constraint), t.dbTable === void 0 && typeof e.table == "string" && (t.dbTable = e.table), t.dbColumn === void 0 && typeof e.column == "string" && (t.dbColumn = e.column), t.dbSchema === void 0 && typeof e.schema == "string" && (t.dbSchema = e.schema);
|
|
347
|
+
let i = e.sqlMessage ?? e.detail;
|
|
348
|
+
t.dbMessage === void 0 && typeof i == "string" && (t.dbMessage = i);
|
|
349
|
+
let a = typeof e.constructor == "function" ? e.constructor.name : void 0, o = typeof e._tag == "string" && e._tag || typeof e.name == "string" && e.name || (typeof a == "string" && a !== "Object" ? a : void 0), s = typeof e.message == "string" ? e.message : void 0;
|
|
350
|
+
(o || s) && n.push(`${o || "Error"}${s ? `: ${s.slice(0, 200)}` : ""}`), r = be(e.cause);
|
|
351
|
+
}
|
|
352
|
+
return n.length > 0 && (t.dbCauseChain = n.join(" ← "), t.dbMessage === void 0 && (t.dbMessage = n[n.length - 1])), t;
|
|
353
|
+
}, we = (e) => {
|
|
354
|
+
let t = xe(e).map(Ce);
|
|
355
|
+
if (t.length <= 1) return t[0] ?? {};
|
|
356
|
+
let n = t.find(Se) ?? t[0], r = t.filter((e) => e !== n).map((e) => e.dbCauseChain).filter((e) => typeof e == "string");
|
|
357
|
+
if (r.length === 0) return n;
|
|
358
|
+
let i = typeof n.dbCauseChain == "string" ? n.dbCauseChain : void 0;
|
|
359
|
+
return {
|
|
360
|
+
...n,
|
|
361
|
+
dbCauseChain: [i, ...r].filter(Boolean).join(" ‖ ")
|
|
362
|
+
};
|
|
363
|
+
}, Te = (e, t) => {
|
|
364
|
+
let n = we(e), r = je(n, t);
|
|
365
|
+
if (r !== void 0) {
|
|
366
|
+
let e = r.constraint ?? r.column;
|
|
367
|
+
return e === void 0 ? r.kind : `${r.kind}: ${e}`;
|
|
368
|
+
}
|
|
369
|
+
let i = n.dbCode ?? n.dbSqlState ?? n.dbErrno ?? n.dbNumber, a = Oe(e);
|
|
370
|
+
return i !== void 0 && Ee.test(String(i)) ? `${a} (${String(i)})` : a;
|
|
371
|
+
}, Ee = /^[A-Za-z0-9_]{1,32}$/, De = /^[A-Za-z_][A-Za-z0-9_]{0,63}$/, Oe = (e) => {
|
|
372
|
+
let t = e?._tag, n = e?.name, r = (typeof t == "string" ? t : typeof n == "string" ? n : "").split(/[^A-Za-z0-9_]+/).filter(Boolean).pop();
|
|
373
|
+
return r !== void 0 && De.test(r) ? r : "unknown";
|
|
374
|
+
}, ke = /^[A-Za-z_][A-Za-z0-9_$]*$/, E = (e) => e !== void 0 && e.length <= 128 && ke.test(e) ? e : void 0, Ae = (e) => e === void 0 ? void 0 : e.split(".").pop() ?? e, D = (e, ...t) => {
|
|
375
|
+
for (let n of t) {
|
|
376
|
+
let t = n.exec(e);
|
|
377
|
+
if (t?.[1] !== void 0) return t[1];
|
|
378
|
+
}
|
|
379
|
+
}, je = (e, t) => {
|
|
380
|
+
let n = e.dbCode, r = e.dbErrno, i = e.dbNumber, a = typeof e.dbMessage == "string" ? e.dbMessage : "", o = `${typeof e.dbCauseChain == "string" ? e.dbCauseChain : ""} ${a}`;
|
|
381
|
+
if (n === "23503") {
|
|
382
|
+
let t = E(e.dbConstraint);
|
|
383
|
+
return {
|
|
384
|
+
kind: /is still referenced from table/i.test(o) ? "foreignKeyInUse" : "foreignKey",
|
|
385
|
+
...t === void 0 ? {} : { constraint: t }
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
if (n === "23505") {
|
|
389
|
+
let t = E(e.dbConstraint);
|
|
390
|
+
return {
|
|
391
|
+
kind: "unique",
|
|
392
|
+
...t === void 0 ? {} : { constraint: t }
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
if (n === "23502") {
|
|
396
|
+
let t = E(e.dbColumn);
|
|
397
|
+
return {
|
|
398
|
+
kind: "notNull",
|
|
399
|
+
...t === void 0 ? {} : { column: t }
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
if (n === "23514") {
|
|
403
|
+
let t = E(e.dbConstraint);
|
|
404
|
+
return {
|
|
405
|
+
kind: "check",
|
|
406
|
+
...t === void 0 ? {} : { constraint: t }
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
if (r === 1452 || r === 1451) {
|
|
410
|
+
let e = E(D(o, /CONSTRAINT `([^`]+)`/));
|
|
411
|
+
return {
|
|
412
|
+
kind: r === 1451 ? "foreignKeyInUse" : "foreignKey",
|
|
413
|
+
...e === void 0 ? {} : { constraint: e }
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
if (r === 1062) {
|
|
417
|
+
let e = E(Ae(D(o, /for key '([^']+)'/)));
|
|
418
|
+
return {
|
|
419
|
+
kind: "unique",
|
|
420
|
+
...e === void 0 ? {} : { constraint: e }
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
if (r === 1048 || r === 1364) {
|
|
424
|
+
let e = E(D(o, /Column '([^']+)' cannot be null/, /Field '([^']+)' doesn't have a default value/));
|
|
425
|
+
return {
|
|
426
|
+
kind: "notNull",
|
|
427
|
+
...e === void 0 ? {} : { column: e }
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
if (r === 3819 || r === 4025) {
|
|
431
|
+
let e = E(D(o, /Check constraint '([^']+)'/, /CONSTRAINT `([^`]+)` failed/));
|
|
432
|
+
return {
|
|
433
|
+
kind: "check",
|
|
434
|
+
...e === void 0 ? {} : { constraint: e }
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
if (i === 547) {
|
|
438
|
+
let e = D(o, /(?:FOREIGN KEY|REFERENCE) constraint "([^"]+)"/), t = D(o, /CHECK constraint "([^"]+)"/);
|
|
439
|
+
if (t !== void 0 && e === void 0) {
|
|
440
|
+
let e = E(t);
|
|
441
|
+
return {
|
|
442
|
+
kind: "check",
|
|
443
|
+
...e === void 0 ? {} : { constraint: e }
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
let n = /REFERENCE constraint/.test(o), r = E(e);
|
|
447
|
+
return {
|
|
448
|
+
kind: n ? "foreignKeyInUse" : "foreignKey",
|
|
449
|
+
...r === void 0 ? {} : { constraint: r }
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
if (i === 2627 || i === 2601) {
|
|
453
|
+
let e = E(D(o, /(?:UNIQUE KEY|PRIMARY KEY) constraint '([^']+)'/, /index '([^']+)'/));
|
|
454
|
+
return {
|
|
455
|
+
kind: "unique",
|
|
456
|
+
...e === void 0 ? {} : { constraint: e }
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
if (i === 515) {
|
|
460
|
+
let e = E(D(o, /Cannot insert the value NULL into column '([^']+)'/));
|
|
461
|
+
return {
|
|
462
|
+
kind: "notNull",
|
|
463
|
+
...e === void 0 ? {} : { column: e }
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
if (n === "SQLITE_CONSTRAINT_FOREIGNKEY") return { kind: t === "delete" || t === "deleteMany" || t === "hardDelete" ? "foreignKeyInUse" : "foreignKey" };
|
|
467
|
+
if (n === "SQLITE_CONSTRAINT_UNIQUE" || n === "SQLITE_CONSTRAINT_PRIMARYKEY") {
|
|
468
|
+
let e = E(Ae(D(o, /UNIQUE constraint failed: ([^,\s]+)/)));
|
|
469
|
+
return {
|
|
470
|
+
kind: "unique",
|
|
471
|
+
...e === void 0 ? {} : { column: e }
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
if (n === "SQLITE_CONSTRAINT_NOTNULL") {
|
|
475
|
+
let e = E(Ae(D(o, /NOT NULL constraint failed: ([^,\s]+)/)));
|
|
476
|
+
return {
|
|
477
|
+
kind: "notNull",
|
|
478
|
+
...e === void 0 ? {} : { column: e }
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
if (n === "SQLITE_CONSTRAINT_CHECK") {
|
|
482
|
+
let e = E(D(a, /CHECK constraint failed: (.+)$/));
|
|
483
|
+
return {
|
|
484
|
+
kind: "check",
|
|
485
|
+
...e === void 0 ? {} : { constraint: e }
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
}, Me = (e) => {
|
|
489
|
+
let t = je(e)?.kind;
|
|
490
|
+
return t === "foreignKey" || t === "foreignKeyInUse";
|
|
491
|
+
}, Ne = (e) => {
|
|
492
|
+
let t = e.dbCode, n = e.dbErrno;
|
|
493
|
+
return t === "57014" || n === 3024 || n === 1969 || t === "ETIMEOUT" || t === "SQLITE_INTERRUPT";
|
|
494
|
+
}, Pe = (e) => {
|
|
495
|
+
let t = we(e), n = [
|
|
496
|
+
t.dbCode === void 0 ? void 0 : `code=${String(t.dbCode)}`,
|
|
497
|
+
t.dbErrno === void 0 ? void 0 : `errno=${String(t.dbErrno)}`,
|
|
498
|
+
t.dbNumber === void 0 ? void 0 : `number=${String(t.dbNumber)}`,
|
|
499
|
+
t.dbSqlState === void 0 ? void 0 : `sqlState=${String(t.dbSqlState)}`,
|
|
500
|
+
t.dbConstraint === void 0 ? void 0 : `constraint=${String(t.dbConstraint)}`,
|
|
501
|
+
t.dbPlaceholders === void 0 ? void 0 : `placeholders=${String(t.dbPlaceholders)}`
|
|
502
|
+
].filter((e) => e !== void 0), r = typeof e?.message == "string" ? e.message : void 0, i = typeof t.dbMessage == "string" ? t.dbMessage : void 0, a = i === void 0 ? void 0 : n.length > 0 || i !== r && i !== `Error: ${String(r)}` ? i : void 0, o = typeof t.dbBindings == "string" ? `\n bindings: ${t.dbBindings}` : "", s = typeof t.dbStatement == "string" ? `\n statement: ${t.dbStatement.length <= 400 ? t.dbStatement : `${t.dbStatement.slice(0, 400)}…`}` : "";
|
|
503
|
+
if (a !== void 0 || n.length !== 0) return [a, n.length > 0 ? `[${n.join(" ")}]` : void 0].filter((e) => e !== void 0 && e !== "").join(" ") + s + o;
|
|
504
|
+
}, Fe = (e) => Object.entries(e).map(([e, t]) => `${e}:${Ie(t)}`).join(" "), Ie = (e) => {
|
|
505
|
+
if (e === null) return "null";
|
|
506
|
+
if (e === void 0) return "undefined";
|
|
507
|
+
if (typeof e == "bigint") return "bigint";
|
|
508
|
+
if (typeof e != "object") return typeof e;
|
|
509
|
+
if (e instanceof Date) return Number.isNaN(e.getTime()) ? "Date(Invalid)" : "Date";
|
|
510
|
+
if (Array.isArray(e)) return "Array";
|
|
511
|
+
if (globalThis.Buffer !== void 0 && globalThis.Buffer.isBuffer(e)) return "Buffer";
|
|
512
|
+
let t = e.constructor?.name;
|
|
513
|
+
return typeof t == "string" && t !== "" ? t : "Object";
|
|
514
|
+
}, Le = 63, Re = 60, O = [], k = (e) => {
|
|
515
|
+
O.includes(e) || O.push(e);
|
|
516
|
+
}, ze = () => {
|
|
517
|
+
let e = O.slice();
|
|
518
|
+
return O.length = 0, e;
|
|
519
|
+
}, Be = /^[a-zA-Z_][a-zA-Z0-9_]*$/, Ve = (e, t) => {
|
|
520
|
+
if (t.length === 0) throw Error(`${e} cannot be empty.`);
|
|
521
|
+
if (!Be.test(t)) throw Error(`${e} '${t}' contains characters outside [A-Za-z0-9_] or starts with a digit. Dialect-portable identifiers must match /^[a-zA-Z_][a-zA-Z0-9_]*$/.`);
|
|
522
|
+
}, A = (e) => {
|
|
523
|
+
if (Ve("table name", e), e.length > 63) throw Error(`table name '${e}' is ${e.length} chars — exceeds the 63-byte cross-dialect limit (Postgres floor). Shorten the name; long table names also cascade into auto-named indexes and FK constraints that would themselves exceed the limit.`);
|
|
524
|
+
e.length > 60 && k(`table name '${e}' is ${e.length} chars — ${63 - e.length} from the Postgres 63-byte limit. Auto-named indexes on this table will run out of room fast.`);
|
|
525
|
+
}, j = (e, t) => {
|
|
526
|
+
if (Ve("column name", t), t.length > 63) throw Error(`column '${t}' on table '${e}' is ${t.length} chars — exceeds the 63-byte cross-dialect limit (Postgres floor). Rename it.`);
|
|
527
|
+
t.length > 60 && k(`column '${t}' on table '${e}' is ${t.length} chars — close to the 63-byte limit.`);
|
|
528
|
+
}, M = (e, t, n, r) => {
|
|
529
|
+
if (Ve("index name", t), t.length > 63) throw Error(n ? `auto-named index '${t}' on table '${e}' is ${t.length} chars — exceeds the 63-byte cross-dialect limit (Postgres floor). Supply an explicit short name: .index('<shortName>', ${JSON.stringify([...r])}).` : `index name '${t}' on table '${e}' is ${t.length} chars — exceeds the 63-byte cross-dialect limit (Postgres floor). Shorten it.`);
|
|
530
|
+
t.length > 60 && k(`index '${t}' on table '${e}' is ${t.length} chars — ${63 - t.length} from the 63-byte limit. ${n ? `Consider .index('<shortName>', ${JSON.stringify([...r])}) before it grows.` : ""}`);
|
|
531
|
+
}, N = (e, t) => {
|
|
532
|
+
if (e.length === 0) throw Error(`typeid prefix on table '${t.tableName}' cannot be empty.`);
|
|
533
|
+
if (!/^[a-z][a-z0-9_]*$/.test(e)) {
|
|
534
|
+
let n = t.kind === "derived" ? "the derived prefix doesn't match typeid's required shape — supply an explicit one via id({ prefix: '...' })." : "the prefix must match typeid's required shape /^[a-z][a-z0-9_]*$/.";
|
|
535
|
+
throw Error(`typeid prefix '${e}' on table '${t.tableName}' is invalid — ${n}`);
|
|
536
|
+
}
|
|
537
|
+
if (e.length > 63) {
|
|
538
|
+
let n = t.kind === "derived" ? "shorten the table name, or supply an explicit short prefix via id({ prefix: '...' })." : "pick a shorter prefix.";
|
|
539
|
+
throw Error(`typeid prefix '${e}' on table '${t.tableName}' is ${e.length} chars — exceeds the 63-byte limit; ${n}`);
|
|
540
|
+
}
|
|
541
|
+
e.length > 60 && k(`typeid prefix '${e}' on table '${t.tableName}' is ${e.length} chars — close to the 63-byte limit. Generated ids will be even longer (prefix + '_' + 26).`);
|
|
542
|
+
}, He = 1704067200000n, Ue = 10n, We = 12n, Ge = (1n << Ue) - 1n, Ke = (1n << We) - 1n, qe = We, Je = 22n, Ye = () => {
|
|
543
|
+
let e = process.env.SNOWFLAKE_MACHINE_ID;
|
|
544
|
+
if (e === void 0 || e === "") return 0n;
|
|
545
|
+
let t = BigInt(e);
|
|
546
|
+
if (t < 0n || t > Ge) throw Error(`SNOWFLAKE_MACHINE_ID out of range: ${e}. Must be 0..${Ge}.`);
|
|
547
|
+
return t;
|
|
548
|
+
}, Xe = () => ({
|
|
549
|
+
lastMs: 0n,
|
|
550
|
+
sequence: 0n,
|
|
551
|
+
machineId: Ye()
|
|
552
|
+
}), P, Ze = () => (P === void 0 && (P = Xe()), P), Qe = () => {
|
|
553
|
+
P = Xe();
|
|
554
|
+
}, $e = () => BigInt(Date.now()), et = (e) => {
|
|
555
|
+
let t = $e();
|
|
556
|
+
for (; t <= e;) t = $e();
|
|
557
|
+
return t;
|
|
558
|
+
}, tt = () => {
|
|
559
|
+
let e = Ze(), t = $e();
|
|
560
|
+
t === e.lastMs ? (e.sequence = e.sequence + 1n & Ke, e.sequence === 0n && (t = et(e.lastMs), e.lastMs = t)) : (e.sequence = 0n, e.lastMs = t);
|
|
561
|
+
let n = t - He;
|
|
562
|
+
if (n < 0n) throw Error("Snowflake timestamp before configured epoch (2024-01-01). System clock is wrong.");
|
|
563
|
+
return (n << Je | e.machineId << qe | e.sequence).toString();
|
|
564
|
+
}, nt = (e) => {
|
|
565
|
+
let t = e.toLowerCase();
|
|
566
|
+
if (t.startsWith("_")) throw Error(`cannot derive a typeid prefix for table '${e}' (table names starting with '_' are not valid typeid prefixes). Pick an explicit prefix via id({ prefix: '...' }) or use a different scheme like id({ scheme: 'numeric' }) for internal tables.`);
|
|
567
|
+
if (!/^[a-z][a-z0-9_]*$/.test(t)) throw Error(`cannot derive a typeid prefix from table name '${e}' (must match [a-z][a-z0-9_]*). Pick an explicit prefix via id({ prefix: '...' }).`);
|
|
568
|
+
let n = t.endsWith("ies") && t.length > 3 ? t.slice(0, -3) + "y" : t.endsWith("ses") || t.endsWith("xes") || t.endsWith("zes") || t.endsWith("shes") || t.endsWith("ches") ? t.slice(0, -2) : t.endsWith("s") && t.length > 1 ? t.slice(0, -1) : t;
|
|
569
|
+
return N(n, {
|
|
570
|
+
kind: "derived",
|
|
571
|
+
tableName: e
|
|
572
|
+
}), n;
|
|
573
|
+
}, rt = (e, t) => {
|
|
574
|
+
if (e === void 0) return {
|
|
575
|
+
kind: "typeid",
|
|
576
|
+
prefix: nt(t)
|
|
577
|
+
};
|
|
578
|
+
if ("prefix" in e && !("scheme" in e)) return N(e.prefix, {
|
|
579
|
+
kind: "explicit",
|
|
580
|
+
tableName: t
|
|
581
|
+
}), {
|
|
582
|
+
kind: "typeid",
|
|
583
|
+
prefix: e.prefix
|
|
584
|
+
};
|
|
585
|
+
if (!("scheme" in e)) throw Error("invalid id() options: no scheme or prefix");
|
|
586
|
+
switch (e.scheme) {
|
|
587
|
+
case "typeid": {
|
|
588
|
+
let n = e.prefix ?? nt(t);
|
|
589
|
+
return e.prefix !== void 0 && N(e.prefix, {
|
|
590
|
+
kind: "explicit",
|
|
591
|
+
tableName: t
|
|
592
|
+
}), {
|
|
593
|
+
kind: "typeid",
|
|
594
|
+
prefix: n
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
case "ulid": return { kind: "ulid" };
|
|
598
|
+
case "numeric": return { kind: "numeric" };
|
|
599
|
+
case "snowflake": return { kind: "snowflake" };
|
|
600
|
+
case "custom": return {
|
|
601
|
+
kind: "custom",
|
|
602
|
+
generate: e.generate
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
}, it = (e, t) => {
|
|
606
|
+
switch (e.kind) {
|
|
607
|
+
case "typeid": return i(e.prefix).toString();
|
|
608
|
+
case "ulid": return a();
|
|
609
|
+
case "numeric": return null;
|
|
610
|
+
case "snowflake": return tt();
|
|
611
|
+
case "custom": return e.generate(t);
|
|
612
|
+
}
|
|
613
|
+
}, at = (e) => ({
|
|
614
|
+
fields: w(e.fields),
|
|
615
|
+
...e.id === void 0 ? {} : { id: e.id },
|
|
616
|
+
...e.requires === void 0 ? {} : { requires: e.requires },
|
|
617
|
+
...e.indexes === void 0 ? {} : { indexes: e.indexes },
|
|
618
|
+
...e.behaviors === void 0 ? {} : { behaviors: e.behaviors },
|
|
619
|
+
...e.policies === void 0 ? {} : { policies: e.policies }
|
|
620
|
+
}), ot = at, st = (e) => {
|
|
621
|
+
let t = /* @__PURE__ */ new Set(), n = [], r = (e) => {
|
|
622
|
+
let i = e.id ?? e;
|
|
623
|
+
if (!t.has(i)) {
|
|
624
|
+
if (t.add(i), e.requires !== void 0) for (let t of e.requires) r(t);
|
|
625
|
+
n.push(e);
|
|
626
|
+
}
|
|
627
|
+
};
|
|
628
|
+
for (let t of e) r(t);
|
|
629
|
+
return n;
|
|
630
|
+
}, ct = (e, ...t) => {
|
|
631
|
+
if (t.length === 0) throw Error(`jsonIndex("${e}"): at least one path segment is required`);
|
|
632
|
+
let n = (r) => ({
|
|
633
|
+
jsonPath: {
|
|
634
|
+
column: e,
|
|
635
|
+
path: t,
|
|
636
|
+
numeric: r
|
|
637
|
+
},
|
|
638
|
+
numeric: () => n(!0)
|
|
639
|
+
});
|
|
640
|
+
return n(!1);
|
|
641
|
+
}, lt = (e = "cosine", t = "float32") => {
|
|
642
|
+
let n = t === "half" ? "halfvec" : "vector";
|
|
643
|
+
switch (e) {
|
|
644
|
+
case "cosine": return `${n}_cosine_ops`;
|
|
645
|
+
case "l2": return `${n}_l2_ops`;
|
|
646
|
+
case "inner": return `${n}_ip_ops`;
|
|
647
|
+
}
|
|
648
|
+
}, ut = [
|
|
649
|
+
"id",
|
|
650
|
+
"tenantId",
|
|
651
|
+
"createdAt",
|
|
652
|
+
"updatedAt",
|
|
653
|
+
"createdBy",
|
|
654
|
+
"updatedBy",
|
|
655
|
+
"deletedAt",
|
|
656
|
+
"deletedBy"
|
|
657
|
+
], dt = (e) => e.id ?? `<anonymous mixin: ${Object.keys(e.fields).join(", ")}>`, ft = (e, t) => `${e}_${t.join("_")}_idx`, pt = (e, t) => `${e}_${t.join("_")}_uq`, mt = (e, t, n, r, i) => {
|
|
658
|
+
if (n !== "hnsw") return;
|
|
659
|
+
if (r.length !== 1) throw Error(`hnsw index '${t}' on table '${e}' must cover exactly one vector column — got ${r.length} fields. pgvector's HNSW access method indexes a single vector column.`);
|
|
660
|
+
let a = r[0];
|
|
661
|
+
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.`);
|
|
662
|
+
let o = i[a];
|
|
663
|
+
if (o === void 0) throw Error(`hnsw index '${t}' on table '${e}' references unknown column '${a}'.`);
|
|
664
|
+
if (o.type !== "vector") throw Error(`hnsw index '${t}' on table '${e}' requires a vector() column — column '${a}' is '${o.type}'. HNSW is the pgvector approximate-nearest-neighbour method and only applies to vectors.`);
|
|
665
|
+
}, ht = (e, t) => {
|
|
666
|
+
let n;
|
|
667
|
+
for (let [r, i] of Object.entries(e)) i.type === "id" && i.idScheme === void 0 && (n === void 0 && (n = { ...e }), n[r] = {
|
|
668
|
+
...i,
|
|
669
|
+
idScheme: rt(i.idSchemeInput, t)
|
|
670
|
+
});
|
|
671
|
+
return n ?? e;
|
|
672
|
+
}, F = (e) => {
|
|
673
|
+
let t = e.appliedPrimaryKey ?? [];
|
|
674
|
+
return {
|
|
675
|
+
tableName: e.tableName,
|
|
676
|
+
fields: e.fields,
|
|
677
|
+
isReactive: e.isReactive,
|
|
678
|
+
appliedMixins: e.appliedMixins,
|
|
679
|
+
appliedIndexes: e.appliedIndexes,
|
|
680
|
+
appliedUniques: e.appliedUniques,
|
|
681
|
+
appliedFullText: e.appliedFullText,
|
|
682
|
+
appliedChecks: e.appliedChecks,
|
|
683
|
+
appliedRules: e.appliedRules ?? [],
|
|
684
|
+
appliedPluginRefs: e.appliedPluginRefs ?? [],
|
|
685
|
+
appliedPrimaryKey: t,
|
|
686
|
+
...e.previousTableName === void 0 ? {} : { previousTableName: e.previousTableName },
|
|
687
|
+
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
688
|
+
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema },
|
|
689
|
+
fullTextIndex: ((t, n, r) => {
|
|
690
|
+
if (n.length === 0) throw Error(`fullTextIndex '${t}' on '${e.tableName}' has no columns.`);
|
|
691
|
+
if (M(e.tableName, t, !1, n), e.appliedFullText.some((e) => e.name === t)) throw Error(`duplicate full-text index '${t}' on table '${e.tableName}'.`);
|
|
692
|
+
return F({
|
|
693
|
+
...e,
|
|
694
|
+
tableName: e.tableName,
|
|
695
|
+
fields: e.fields,
|
|
696
|
+
isReactive: e.isReactive,
|
|
697
|
+
appliedMixins: e.appliedMixins,
|
|
698
|
+
appliedIndexes: e.appliedIndexes,
|
|
699
|
+
appliedUniques: e.appliedUniques,
|
|
700
|
+
appliedChecks: e.appliedChecks,
|
|
701
|
+
appliedPrimaryKey: e.appliedPrimaryKey,
|
|
702
|
+
appliedFullText: [...e.appliedFullText, {
|
|
703
|
+
name: t,
|
|
704
|
+
columns: [...n],
|
|
705
|
+
...r?.config === void 0 ? {} : { config: r.config },
|
|
706
|
+
...r?.weights === void 0 ? {} : { weights: r.weights }
|
|
707
|
+
}],
|
|
708
|
+
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
709
|
+
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
710
|
+
});
|
|
711
|
+
}),
|
|
712
|
+
with: ((...t) => {
|
|
713
|
+
let n = st(t), r = { ...e.fields }, i = /* @__PURE__ */ new Map();
|
|
714
|
+
for (let e of Object.keys(r)) i.set(e, {
|
|
715
|
+
id: "<table>",
|
|
716
|
+
fields: {}
|
|
717
|
+
});
|
|
718
|
+
for (let t of n) for (let [n, a] of Object.entries(t.fields)) {
|
|
719
|
+
let o = i.get(n);
|
|
720
|
+
if (o !== void 0) throw Error(`mixin collision on column '${n}' in table '${e.tableName}': '${dt(o)}' and '${dt(t)}' both define it. If they're the same mixin reached via different paths, set a shared 'id' on both. If they're genuinely different concerns, rename one of the columns.`);
|
|
721
|
+
j(e.tableName, n), r[n] = a, i.set(n, t);
|
|
722
|
+
}
|
|
723
|
+
let a = [...e.appliedIndexes];
|
|
724
|
+
for (let t of n) for (let n of t.indexes ?? []) {
|
|
725
|
+
let t = n.name ?? ft(e.tableName, n.fields);
|
|
726
|
+
a.some((e) => e.name === t) || (M(e.tableName, t, n.name === void 0, n.fields), mt(e.tableName, t, n.kind, n.fields, r), a.push({
|
|
727
|
+
name: t,
|
|
728
|
+
fields: n.fields,
|
|
729
|
+
...n.kind === void 0 ? {} : { kind: n.kind },
|
|
730
|
+
...n.kindOptions === void 0 ? {} : { kindOptions: n.kindOptions }
|
|
731
|
+
}));
|
|
732
|
+
}
|
|
733
|
+
return F({
|
|
734
|
+
...e,
|
|
735
|
+
tableName: e.tableName,
|
|
736
|
+
fields: r,
|
|
737
|
+
isReactive: e.isReactive,
|
|
738
|
+
appliedMixins: [...e.appliedMixins, ...n],
|
|
739
|
+
appliedIndexes: a,
|
|
740
|
+
appliedUniques: e.appliedUniques,
|
|
741
|
+
appliedFullText: e.appliedFullText,
|
|
742
|
+
appliedChecks: e.appliedChecks,
|
|
743
|
+
appliedPrimaryKey: e.appliedPrimaryKey,
|
|
744
|
+
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
745
|
+
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
746
|
+
});
|
|
747
|
+
}),
|
|
748
|
+
index: ((...t) => {
|
|
749
|
+
let n, r, i, a = Array.isArray(t[0]);
|
|
750
|
+
if (a ? (r = t[0], i = t[1], n = ft(e.tableName, r)) : (n = t[0], r = t[1], i = t[2]), r.length === 0) throw Error(`index '${n}' on table '${e.tableName}' has no fields — an index must cover at least one column.`);
|
|
751
|
+
let o = r.filter((e) => typeof e == "string");
|
|
752
|
+
if (M(e.tableName, n, a, o), mt(e.tableName, n, i?.kind, r, e.fields), e.appliedIndexes.some((e) => e.name === n)) throw t.length === 1 ? Error(`duplicate auto-named index '${n}' on table '${e.tableName}' — you've called .index(${JSON.stringify(r)}) twice. Pass an explicit name to the second one if both are intended (rare).`) : Error(`duplicate index '${n}' on table '${e.tableName}': each index name must be unique within a table.`);
|
|
753
|
+
return F({
|
|
754
|
+
...e,
|
|
755
|
+
tableName: e.tableName,
|
|
756
|
+
fields: e.fields,
|
|
757
|
+
isReactive: e.isReactive,
|
|
758
|
+
appliedMixins: e.appliedMixins,
|
|
759
|
+
appliedIndexes: [...e.appliedIndexes, {
|
|
760
|
+
name: n,
|
|
761
|
+
fields: [...r],
|
|
762
|
+
...i?.where === void 0 ? {} : { where: i.where },
|
|
763
|
+
...i?.kind === void 0 ? {} : { kind: i.kind },
|
|
764
|
+
...i?.kindOptions === void 0 ? {} : { kindOptions: i.kindOptions }
|
|
765
|
+
}],
|
|
766
|
+
appliedUniques: e.appliedUniques,
|
|
767
|
+
appliedFullText: e.appliedFullText,
|
|
768
|
+
appliedChecks: e.appliedChecks,
|
|
769
|
+
appliedPrimaryKey: e.appliedPrimaryKey,
|
|
770
|
+
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
771
|
+
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
772
|
+
});
|
|
773
|
+
}),
|
|
774
|
+
expressionIndex: ((t, n, r) => {
|
|
775
|
+
if (n.length === 0) throw Error(`expressionIndex '${t}' on table '${e.tableName}' has no fields — an index must cover at least one column or expression.`);
|
|
776
|
+
let i = n.filter((e) => typeof e == "string");
|
|
777
|
+
if (M(e.tableName, t, !1, i), mt(e.tableName, t, r?.kind, n, e.fields), e.appliedIndexes.some((e) => e.name === t)) throw Error(`duplicate index '${t}' on table '${e.tableName}': each index name must be unique within a table.`);
|
|
778
|
+
return F({
|
|
779
|
+
...e,
|
|
780
|
+
tableName: e.tableName,
|
|
781
|
+
fields: e.fields,
|
|
782
|
+
isReactive: e.isReactive,
|
|
783
|
+
appliedMixins: e.appliedMixins,
|
|
784
|
+
appliedIndexes: [...e.appliedIndexes, {
|
|
785
|
+
name: t,
|
|
786
|
+
fields: [...n],
|
|
787
|
+
...r?.where === void 0 ? {} : { where: r.where },
|
|
788
|
+
...r?.kind === void 0 ? {} : { kind: r.kind },
|
|
789
|
+
...r?.kindOptions === void 0 ? {} : { kindOptions: r.kindOptions }
|
|
790
|
+
}],
|
|
791
|
+
appliedUniques: e.appliedUniques,
|
|
792
|
+
appliedFullText: e.appliedFullText,
|
|
793
|
+
appliedChecks: e.appliedChecks,
|
|
794
|
+
appliedPrimaryKey: e.appliedPrimaryKey,
|
|
795
|
+
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
796
|
+
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
797
|
+
});
|
|
798
|
+
}),
|
|
799
|
+
unique: ((...t) => {
|
|
800
|
+
let n, r, i, a = Array.isArray(t[0]);
|
|
801
|
+
if (a ? (r = t[0], i = t[1], n = pt(e.tableName, r)) : (n = t[0], r = t[1], i = t[2]), r.length === 0) throw Error(`unique '${n}' on table '${e.tableName}' has no fields — a UNIQUE constraint must cover at least one column.`);
|
|
802
|
+
if (M(e.tableName, n, a, r), e.appliedUniques.some((e) => e.name === n)) throw Error(a ? `duplicate auto-named UNIQUE '${n}' on table '${e.tableName}' — you've called .unique(${JSON.stringify(r)}) twice. Pass an explicit name to the second one if both are intended (very rare).` : `duplicate UNIQUE '${n}' on table '${e.tableName}': each constraint name must be unique within a table.`);
|
|
803
|
+
return F({
|
|
804
|
+
...e,
|
|
805
|
+
tableName: e.tableName,
|
|
806
|
+
fields: e.fields,
|
|
807
|
+
isReactive: e.isReactive,
|
|
808
|
+
appliedMixins: e.appliedMixins,
|
|
809
|
+
appliedIndexes: e.appliedIndexes,
|
|
810
|
+
appliedUniques: [...e.appliedUniques, {
|
|
811
|
+
name: n,
|
|
812
|
+
fields: [...r],
|
|
813
|
+
...i?.dedup === void 0 ? {} : { dedup: i.dedup }
|
|
814
|
+
}],
|
|
815
|
+
appliedFullText: e.appliedFullText,
|
|
816
|
+
appliedChecks: e.appliedChecks,
|
|
817
|
+
appliedPrimaryKey: e.appliedPrimaryKey,
|
|
818
|
+
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
819
|
+
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
820
|
+
});
|
|
821
|
+
}),
|
|
822
|
+
uniqueActive: ((...t) => {
|
|
823
|
+
let n, r, i, a = Array.isArray(t[0]);
|
|
824
|
+
if (a ? (r = t[0], i = t[1], n = ft(e.tableName, r)) : (n = t[0], r = t[1], i = t[2]), r.length === 0) throw Error(`uniqueActive '${n}' on table '${e.tableName}' has no fields — a partial UNIQUE must cover at least one column.`);
|
|
825
|
+
if (M(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).`);
|
|
826
|
+
let o = i?.where ?? "\"deletedAt\" IS NULL";
|
|
827
|
+
return F({
|
|
828
|
+
...e,
|
|
829
|
+
tableName: e.tableName,
|
|
830
|
+
fields: e.fields,
|
|
831
|
+
isReactive: e.isReactive,
|
|
832
|
+
appliedMixins: e.appliedMixins,
|
|
833
|
+
appliedIndexes: [...e.appliedIndexes, {
|
|
834
|
+
name: n,
|
|
835
|
+
fields: [...r],
|
|
836
|
+
where: o,
|
|
837
|
+
unique: !0
|
|
838
|
+
}],
|
|
839
|
+
appliedUniques: e.appliedUniques,
|
|
840
|
+
appliedFullText: e.appliedFullText,
|
|
841
|
+
appliedChecks: e.appliedChecks,
|
|
842
|
+
appliedPrimaryKey: e.appliedPrimaryKey,
|
|
843
|
+
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
844
|
+
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
845
|
+
});
|
|
846
|
+
}),
|
|
847
|
+
check: ((t, n) => {
|
|
848
|
+
if (n.trim().length === 0) throw Error(`CHECK '${t}' on table '${e.tableName}' has an empty expression.`);
|
|
849
|
+
if (M(e.tableName, t, !1, []), e.appliedChecks.some((e) => e.name === t)) throw Error(`duplicate CHECK '${t}' on table '${e.tableName}': each constraint name must be unique within a table.`);
|
|
850
|
+
return F({
|
|
851
|
+
...e,
|
|
852
|
+
tableName: e.tableName,
|
|
853
|
+
fields: e.fields,
|
|
854
|
+
isReactive: e.isReactive,
|
|
855
|
+
appliedMixins: e.appliedMixins,
|
|
856
|
+
appliedIndexes: e.appliedIndexes,
|
|
857
|
+
appliedUniques: e.appliedUniques,
|
|
858
|
+
appliedFullText: e.appliedFullText,
|
|
859
|
+
appliedChecks: [...e.appliedChecks, {
|
|
860
|
+
name: t,
|
|
861
|
+
expr: n
|
|
862
|
+
}],
|
|
863
|
+
appliedPrimaryKey: e.appliedPrimaryKey,
|
|
864
|
+
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
865
|
+
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
866
|
+
});
|
|
867
|
+
}),
|
|
868
|
+
rule: ((t, n, r) => {
|
|
869
|
+
if (t.trim().length === 0) throw Error(`rule on table '${e.tableName}' has an empty name.`);
|
|
870
|
+
let i = e.appliedRules ?? [];
|
|
871
|
+
if (i.some((e) => e.name === t)) throw Error(`duplicate rule '${t}' on table '${e.tableName}': each rule name must be unique within a table.`);
|
|
872
|
+
return F({
|
|
873
|
+
...e,
|
|
874
|
+
appliedRules: [...i, {
|
|
875
|
+
name: t,
|
|
876
|
+
predicate: n,
|
|
877
|
+
severity: r?.severity ?? "error"
|
|
878
|
+
}]
|
|
879
|
+
});
|
|
880
|
+
}),
|
|
881
|
+
renamedFrom: ((t) => {
|
|
882
|
+
if (t === e.tableName) throw Error(`renamedFrom('${t}') on table '${e.tableName}' names the table itself — drop the marker, there is nothing to rename.`);
|
|
883
|
+
return A(t), F({
|
|
884
|
+
...e,
|
|
885
|
+
previousTableName: t
|
|
886
|
+
});
|
|
887
|
+
}),
|
|
888
|
+
primaryKey: ((n) => {
|
|
889
|
+
if (n.length === 0) throw Error(`primaryKey([...]) on table '${e.tableName}' needs at least one column.`);
|
|
890
|
+
let r = /* @__PURE__ */ new Set();
|
|
891
|
+
for (let t of n) {
|
|
892
|
+
if (!(t in e.fields)) throw Error(`primaryKey([...]) on table '${e.tableName}' references unknown column '${t}'.`);
|
|
893
|
+
if (r.has(t)) throw Error(`primaryKey([...]) on table '${e.tableName}' lists column '${t}' twice.`);
|
|
894
|
+
r.add(t);
|
|
895
|
+
}
|
|
896
|
+
if (t.length > 0) throw Error(`primaryKey([...]) declared twice on table '${e.tableName}'.`);
|
|
897
|
+
for (let [t, r] of Object.entries(e.fields)) if (r.type === "id" && !n.includes(t)) throw Error(`primaryKey([...]) on table '${e.tableName}' conflicts with the id() column '${t}'. The explicit primary key IS the key — drop the id() column, or include '${t}' in the composite key.`);
|
|
898
|
+
return F({
|
|
899
|
+
...e,
|
|
900
|
+
tableName: e.tableName,
|
|
901
|
+
fields: e.fields,
|
|
902
|
+
isReactive: e.isReactive,
|
|
903
|
+
appliedMixins: e.appliedMixins,
|
|
904
|
+
appliedIndexes: e.appliedIndexes,
|
|
905
|
+
appliedUniques: e.appliedUniques,
|
|
906
|
+
appliedFullText: e.appliedFullText,
|
|
907
|
+
appliedChecks: e.appliedChecks,
|
|
908
|
+
appliedPrimaryKey: [...n],
|
|
909
|
+
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
910
|
+
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
911
|
+
});
|
|
912
|
+
}),
|
|
913
|
+
nonReactive: (() => F({
|
|
914
|
+
...e,
|
|
915
|
+
tableName: e.tableName,
|
|
916
|
+
fields: e.fields,
|
|
917
|
+
isReactive: !1,
|
|
918
|
+
appliedMixins: e.appliedMixins,
|
|
919
|
+
appliedIndexes: e.appliedIndexes,
|
|
920
|
+
appliedUniques: e.appliedUniques,
|
|
921
|
+
appliedFullText: e.appliedFullText,
|
|
922
|
+
appliedChecks: e.appliedChecks,
|
|
923
|
+
appliedPrimaryKey: e.appliedPrimaryKey,
|
|
924
|
+
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
925
|
+
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
926
|
+
})),
|
|
927
|
+
validate: ((t) => F({
|
|
928
|
+
...e,
|
|
929
|
+
tableName: e.tableName,
|
|
930
|
+
fields: e.fields,
|
|
931
|
+
isReactive: e.isReactive,
|
|
932
|
+
appliedMixins: e.appliedMixins,
|
|
933
|
+
appliedIndexes: e.appliedIndexes,
|
|
934
|
+
appliedUniques: e.appliedUniques,
|
|
935
|
+
appliedFullText: e.appliedFullText,
|
|
936
|
+
appliedChecks: e.appliedChecks,
|
|
937
|
+
appliedPrimaryKey: e.appliedPrimaryKey,
|
|
938
|
+
insertSchema: t,
|
|
939
|
+
...e.validatePatchSchema === void 0 ? {} : { validatePatchSchema: e.validatePatchSchema }
|
|
940
|
+
})),
|
|
941
|
+
validatePatch: ((t) => F({
|
|
942
|
+
...e,
|
|
943
|
+
tableName: e.tableName,
|
|
944
|
+
fields: e.fields,
|
|
945
|
+
isReactive: e.isReactive,
|
|
946
|
+
appliedMixins: e.appliedMixins,
|
|
947
|
+
appliedIndexes: e.appliedIndexes,
|
|
948
|
+
appliedUniques: e.appliedUniques,
|
|
949
|
+
appliedFullText: e.appliedFullText,
|
|
950
|
+
appliedChecks: e.appliedChecks,
|
|
951
|
+
appliedPrimaryKey: e.appliedPrimaryKey,
|
|
952
|
+
...e.insertSchema === void 0 ? {} : { insertSchema: e.insertSchema },
|
|
953
|
+
validatePatchSchema: r.partial(t)
|
|
954
|
+
}))
|
|
955
|
+
};
|
|
956
|
+
}, I = (e, t) => {
|
|
957
|
+
A(e);
|
|
958
|
+
let n = Object.entries(t).flatMap(([e, t]) => {
|
|
959
|
+
let n = me(t);
|
|
960
|
+
return n === void 0 ? [] : [{
|
|
961
|
+
column: e,
|
|
962
|
+
...n
|
|
963
|
+
}];
|
|
964
|
+
}), r = ht(w(t), e);
|
|
965
|
+
for (let t of Object.keys(r)) j(e, t);
|
|
966
|
+
let i;
|
|
967
|
+
for (let [t, n] of Object.entries(r)) n.references === x && (n.references = () => {
|
|
968
|
+
if (i === void 0) throw Error(`selfReference() on '${e}.${t}' read before table() returned`);
|
|
969
|
+
return i;
|
|
970
|
+
});
|
|
971
|
+
return i = F({
|
|
972
|
+
appliedPluginRefs: n,
|
|
973
|
+
tableName: e,
|
|
974
|
+
fields: r,
|
|
975
|
+
isReactive: !0,
|
|
976
|
+
appliedMixins: [],
|
|
977
|
+
appliedIndexes: [],
|
|
978
|
+
appliedUniques: [],
|
|
979
|
+
appliedFullText: [],
|
|
980
|
+
appliedChecks: [],
|
|
981
|
+
appliedRules: []
|
|
982
|
+
}), i;
|
|
983
|
+
}, gt = (e) => e === "sqlite" || e === "turso", _t = (e) => e === "mysql" || e === "mariadb", L = (e, t) => {
|
|
984
|
+
switch (t) {
|
|
985
|
+
case "mysql":
|
|
986
|
+
case "mariadb": return `\`${e.replace(/`/g, "``")}\``;
|
|
987
|
+
case "mssql": return `[${e.replace(/\]/g, "]]")}]`;
|
|
988
|
+
case "postgres":
|
|
989
|
+
case "sqlite":
|
|
990
|
+
case "turso": return `"${e.replace(/"/g, "\"\"")}"`;
|
|
991
|
+
}
|
|
992
|
+
}, vt = 1e4, yt = Symbol.for("@voltro/database/tableRegistry"), bt = globalThis, R = bt[yt] ?? (bt[yt] = /* @__PURE__ */ new Map()), xt = (e) => {
|
|
993
|
+
let t = R.get(e.tableName);
|
|
994
|
+
if (t === void 0) {
|
|
995
|
+
R.set(e.tableName, e);
|
|
996
|
+
return;
|
|
997
|
+
}
|
|
998
|
+
if (t !== e) throw Error(`duplicate table '${e.tableName}' registration: two different table descriptors claim the same name. Rename one or import the shared module that defines it.`);
|
|
999
|
+
}, St = (e) => {
|
|
1000
|
+
R.get(e.tableName) === void 0 && R.set(e.tableName, e);
|
|
1001
|
+
}, z = (e) => R.get(e), Ct = (e) => {
|
|
1002
|
+
let t = R.get(e);
|
|
1003
|
+
if (t === void 0) throw Error(`table '${e}' is not registered. Register it by wrapping it in \`databaseHandle({ ... })\` (the usual path) or call \`registerTable(t)\` explicitly before this runs. Note a \`queryFor(t)\` query carries its own source table, so eager-loads don't hit this — this error means a reconstructed descriptor or by-name tooling reached an unregistered table.`);
|
|
1004
|
+
return t;
|
|
1005
|
+
}, wt = () => [...R.values()], Tt = (e) => R.delete(e), Et = () => {
|
|
1006
|
+
R.clear();
|
|
1007
|
+
}, Dt = (e) => R.get(e)?.isReactive !== !1, B = (e) => e.order ?? [], Ot = (e) => ({
|
|
1008
|
+
op: "count",
|
|
1009
|
+
alias: e ?? "count"
|
|
1010
|
+
}), kt = (e, t) => ({
|
|
1011
|
+
op: "count-distinct",
|
|
1012
|
+
column: e,
|
|
1013
|
+
alias: t ?? `count_distinct_${e}`
|
|
1014
|
+
}), At = (e, t) => ({
|
|
1015
|
+
op: "sum",
|
|
1016
|
+
column: e,
|
|
1017
|
+
alias: t ?? `sum_${e}`
|
|
1018
|
+
}), jt = (e, t) => ({
|
|
1019
|
+
op: "avg",
|
|
1020
|
+
column: e,
|
|
1021
|
+
alias: t ?? `avg_${e}`
|
|
1022
|
+
}), Mt = (e, t) => ({
|
|
1023
|
+
op: "min",
|
|
1024
|
+
column: e,
|
|
1025
|
+
alias: t ?? `min_${e}`
|
|
1026
|
+
}), Nt = (e, t) => ({
|
|
1027
|
+
op: "max",
|
|
1028
|
+
column: e,
|
|
1029
|
+
alias: t ?? `max_${e}`
|
|
1030
|
+
}), Pt = (e, t) => ({
|
|
1031
|
+
op: "column",
|
|
1032
|
+
column: e,
|
|
1033
|
+
alias: t ?? e
|
|
1034
|
+
}), V = (e) => (...t) => {
|
|
1035
|
+
if (t.length < 2) throw Error(`${e}: requires at least two queries`);
|
|
1036
|
+
return U({
|
|
1037
|
+
table: t[0].descriptor.table,
|
|
1038
|
+
predicate: void 0,
|
|
1039
|
+
order: [],
|
|
1040
|
+
take: void 0,
|
|
1041
|
+
skip: void 0,
|
|
1042
|
+
projection: void 0,
|
|
1043
|
+
setOp: {
|
|
1044
|
+
kind: e,
|
|
1045
|
+
queries: t.map((e) => e.descriptor)
|
|
1046
|
+
}
|
|
1047
|
+
});
|
|
1048
|
+
}, Ft = V("union"), It = V("union-all"), Lt = V("intersect"), Rt = V("except"), H = (e) => ({ over: (t) => ({
|
|
1049
|
+
...e,
|
|
1050
|
+
window: t
|
|
1051
|
+
}) }), zt = (e = "rowNumber") => H({
|
|
1052
|
+
op: "window-row-number",
|
|
1053
|
+
alias: e
|
|
1054
|
+
}), Bt = (e = "rank") => H({
|
|
1055
|
+
op: "window-rank",
|
|
1056
|
+
alias: e
|
|
1057
|
+
}), Vt = (e = "denseRank") => H({
|
|
1058
|
+
op: "window-dense-rank",
|
|
1059
|
+
alias: e
|
|
1060
|
+
}), Ht = (e, t = 1, n) => H({
|
|
1061
|
+
op: "window-lag",
|
|
1062
|
+
column: e,
|
|
1063
|
+
alias: n ?? `lag_${e}`,
|
|
1064
|
+
offset: t
|
|
1065
|
+
}), Ut = (e, t = 1, n) => H({
|
|
1066
|
+
op: "window-lead",
|
|
1067
|
+
column: e,
|
|
1068
|
+
alias: n ?? `lead_${e}`,
|
|
1069
|
+
offset: t
|
|
1070
|
+
}), Wt = (e, t) => H({
|
|
1071
|
+
op: "window-sum-over",
|
|
1072
|
+
column: e,
|
|
1073
|
+
alias: t ?? `sum_${e}_over`
|
|
1074
|
+
}), Gt = (e, t) => H({
|
|
1075
|
+
op: "window-avg-over",
|
|
1076
|
+
column: e,
|
|
1077
|
+
alias: t ?? `avg_${e}_over`
|
|
1078
|
+
}), Kt = (e, t, n) => {
|
|
1079
|
+
let r = n?.find((e) => e.name === t) ?? z(e)?.appliedFullText?.find((e) => e.name === t);
|
|
1080
|
+
if (r === void 0) throw Error(`.matching('${t}', ...): no full-text index named '${t}' is declared on table '${e}'. Declare it with \`table(...).fullTextIndex('${t}', [columns])\` first.`);
|
|
1081
|
+
return {
|
|
1082
|
+
columns: r.columns,
|
|
1083
|
+
...r.config === void 0 ? {} : { config: r.config },
|
|
1084
|
+
...r.weights === void 0 ? {} : { weights: r.weights }
|
|
1085
|
+
};
|
|
1086
|
+
}, U = (e) => ({
|
|
1087
|
+
descriptor: e,
|
|
1088
|
+
where(t) {
|
|
1089
|
+
let n = e.predicate ? { and: [e.predicate, t] } : t;
|
|
1090
|
+
return U({
|
|
1091
|
+
...e,
|
|
1092
|
+
predicate: n
|
|
1093
|
+
});
|
|
1094
|
+
},
|
|
1095
|
+
orderBy(t, n = "asc") {
|
|
1096
|
+
return U({
|
|
1097
|
+
...e,
|
|
1098
|
+
order: [...e.order, {
|
|
1099
|
+
column: t,
|
|
1100
|
+
direction: n
|
|
1101
|
+
}]
|
|
1102
|
+
});
|
|
1103
|
+
},
|
|
1104
|
+
limit(t) {
|
|
1105
|
+
return U({
|
|
1106
|
+
...e,
|
|
1107
|
+
take: t
|
|
1108
|
+
});
|
|
1109
|
+
},
|
|
1110
|
+
offset(t) {
|
|
1111
|
+
return U({
|
|
1112
|
+
...e,
|
|
1113
|
+
skip: t
|
|
1114
|
+
});
|
|
1115
|
+
},
|
|
1116
|
+
select(...t) {
|
|
1117
|
+
return U({
|
|
1118
|
+
...e,
|
|
1119
|
+
projection: t
|
|
1120
|
+
});
|
|
1121
|
+
},
|
|
1122
|
+
using(t) {
|
|
1123
|
+
return U({
|
|
1124
|
+
...e,
|
|
1125
|
+
usingIndex: t
|
|
1126
|
+
});
|
|
1127
|
+
},
|
|
1128
|
+
withDeleted() {
|
|
1129
|
+
return U({
|
|
1130
|
+
...e,
|
|
1131
|
+
includeDeleted: !0
|
|
1132
|
+
});
|
|
1133
|
+
},
|
|
1134
|
+
forUpdate() {
|
|
1135
|
+
return U({
|
|
1136
|
+
...e,
|
|
1137
|
+
lock: "update"
|
|
1138
|
+
});
|
|
1139
|
+
},
|
|
1140
|
+
unscoped() {
|
|
1141
|
+
return U({
|
|
1142
|
+
...e,
|
|
1143
|
+
crossTenant: !0
|
|
1144
|
+
});
|
|
1145
|
+
},
|
|
1146
|
+
with(t) {
|
|
1147
|
+
let n = {
|
|
1148
|
+
...e.eager ?? {},
|
|
1149
|
+
...t
|
|
1150
|
+
};
|
|
1151
|
+
return U({
|
|
1152
|
+
...e,
|
|
1153
|
+
eager: n
|
|
1154
|
+
});
|
|
1155
|
+
},
|
|
1156
|
+
count() {
|
|
1157
|
+
return U({
|
|
1158
|
+
...e,
|
|
1159
|
+
projection: void 0,
|
|
1160
|
+
aggregations: [{
|
|
1161
|
+
op: "count",
|
|
1162
|
+
alias: "count"
|
|
1163
|
+
}]
|
|
1164
|
+
});
|
|
1165
|
+
},
|
|
1166
|
+
aggregate(t) {
|
|
1167
|
+
let n = Object.entries(t).map(([e, t]) => ({
|
|
1168
|
+
...t,
|
|
1169
|
+
alias: e
|
|
1170
|
+
}));
|
|
1171
|
+
return U({
|
|
1172
|
+
...e,
|
|
1173
|
+
projection: void 0,
|
|
1174
|
+
aggregations: n
|
|
1175
|
+
});
|
|
1176
|
+
},
|
|
1177
|
+
matching(t, n) {
|
|
1178
|
+
let r = Kt(e.table, t, e.fullTextIndexes);
|
|
1179
|
+
return U({
|
|
1180
|
+
...e,
|
|
1181
|
+
fullTextSearch: {
|
|
1182
|
+
indexName: t,
|
|
1183
|
+
query: n,
|
|
1184
|
+
columns: r.columns,
|
|
1185
|
+
...r.config === void 0 ? {} : { config: r.config },
|
|
1186
|
+
...r.weights === void 0 ? {} : { weights: r.weights }
|
|
1187
|
+
}
|
|
1188
|
+
});
|
|
1189
|
+
},
|
|
1190
|
+
rankBy(t) {
|
|
1191
|
+
let n = e.fullTextSearch;
|
|
1192
|
+
if (n === void 0) throw Error(".rankBy() requires a preceding .matching(...) clause — there is no full-text search to rank on this query.");
|
|
1193
|
+
return U({
|
|
1194
|
+
...e,
|
|
1195
|
+
fullTextSearch: {
|
|
1196
|
+
...n,
|
|
1197
|
+
rank: {
|
|
1198
|
+
alias: t?.alias ?? "rank",
|
|
1199
|
+
order: t?.order ?? !0
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
});
|
|
1203
|
+
},
|
|
1204
|
+
nearestNeighbours(t, n, r) {
|
|
1205
|
+
if (typeof t == "string" && Array.isArray(n)) {
|
|
1206
|
+
let i = {
|
|
1207
|
+
column: t,
|
|
1208
|
+
queryVector: n,
|
|
1209
|
+
distance: r?.distance ?? "cosine",
|
|
1210
|
+
...e.annClause?.ef === void 0 ? {} : { ef: e.annClause.ef }
|
|
1211
|
+
};
|
|
1212
|
+
return U({
|
|
1213
|
+
...e,
|
|
1214
|
+
annClause: i
|
|
1215
|
+
});
|
|
1216
|
+
}
|
|
1217
|
+
if (typeof t == "string" && typeof n == "number") {
|
|
1218
|
+
let r = {
|
|
1219
|
+
column: "",
|
|
1220
|
+
queryText: t,
|
|
1221
|
+
distance: "cosine",
|
|
1222
|
+
...e.annClause?.ef === void 0 ? {} : { ef: e.annClause.ef }
|
|
1223
|
+
};
|
|
1224
|
+
return U({
|
|
1225
|
+
...e,
|
|
1226
|
+
annClause: r,
|
|
1227
|
+
take: n
|
|
1228
|
+
});
|
|
1229
|
+
}
|
|
1230
|
+
throw Error("nearestNeighbours: call as (column, queryVector, options?) or (queryString, k).");
|
|
1231
|
+
},
|
|
1232
|
+
efSearch(t) {
|
|
1233
|
+
let n = e.annClause ?? {
|
|
1234
|
+
column: "",
|
|
1235
|
+
distance: "cosine"
|
|
1236
|
+
};
|
|
1237
|
+
return U({
|
|
1238
|
+
...e,
|
|
1239
|
+
annClause: {
|
|
1240
|
+
...n,
|
|
1241
|
+
ef: t
|
|
1242
|
+
}
|
|
1243
|
+
});
|
|
1244
|
+
},
|
|
1245
|
+
use(t) {
|
|
1246
|
+
return U({ ...t(e) });
|
|
1247
|
+
},
|
|
1248
|
+
distinct() {
|
|
1249
|
+
return U({
|
|
1250
|
+
...e,
|
|
1251
|
+
distinct: !0
|
|
1252
|
+
});
|
|
1253
|
+
},
|
|
1254
|
+
distinctOn(t) {
|
|
1255
|
+
return U({
|
|
1256
|
+
...e,
|
|
1257
|
+
distinctOn: [...t]
|
|
1258
|
+
});
|
|
1259
|
+
},
|
|
1260
|
+
as(t) {
|
|
1261
|
+
return U({
|
|
1262
|
+
...e,
|
|
1263
|
+
alias: t
|
|
1264
|
+
});
|
|
1265
|
+
},
|
|
1266
|
+
innerJoin(t, n, r) {
|
|
1267
|
+
let i = typeof t == "string" ? t : t.tableName, a = [...e.joins ?? [], {
|
|
1268
|
+
kind: "inner",
|
|
1269
|
+
table: i,
|
|
1270
|
+
alias: n,
|
|
1271
|
+
on: r
|
|
1272
|
+
}];
|
|
1273
|
+
return U({
|
|
1274
|
+
...e,
|
|
1275
|
+
joins: a
|
|
1276
|
+
});
|
|
1277
|
+
},
|
|
1278
|
+
leftJoin(t, n, r) {
|
|
1279
|
+
let i = typeof t == "string" ? t : t.tableName, a = [...e.joins ?? [], {
|
|
1280
|
+
kind: "left",
|
|
1281
|
+
table: i,
|
|
1282
|
+
alias: n,
|
|
1283
|
+
on: r
|
|
1284
|
+
}];
|
|
1285
|
+
return U({
|
|
1286
|
+
...e,
|
|
1287
|
+
joins: a
|
|
1288
|
+
});
|
|
1289
|
+
},
|
|
1290
|
+
selectJoined(t) {
|
|
1291
|
+
let n = Object.entries(t).map(([e, t]) => ({
|
|
1292
|
+
outputKey: e,
|
|
1293
|
+
source: t
|
|
1294
|
+
}));
|
|
1295
|
+
return U({
|
|
1296
|
+
...e,
|
|
1297
|
+
projection: void 0,
|
|
1298
|
+
joinedProjection: n
|
|
1299
|
+
});
|
|
1300
|
+
},
|
|
1301
|
+
withCte(t, n) {
|
|
1302
|
+
let r = e.ctes ?? [];
|
|
1303
|
+
if (r.some((e) => e.name === t)) throw Error(`Query.withCte: duplicate CTE name '${t}'`);
|
|
1304
|
+
return U({
|
|
1305
|
+
...e,
|
|
1306
|
+
ctes: [...r, {
|
|
1307
|
+
name: t,
|
|
1308
|
+
descriptor: n
|
|
1309
|
+
}]
|
|
1310
|
+
});
|
|
1311
|
+
},
|
|
1312
|
+
recursiveCte(t, n) {
|
|
1313
|
+
let r = e.ctes ?? [];
|
|
1314
|
+
if (r.some((e) => e.name === t)) throw Error(`Query.recursiveCte: duplicate CTE name '${t}'`);
|
|
1315
|
+
return U({
|
|
1316
|
+
...e,
|
|
1317
|
+
ctes: [...r, {
|
|
1318
|
+
name: t,
|
|
1319
|
+
descriptor: n,
|
|
1320
|
+
recursive: !0
|
|
1321
|
+
}]
|
|
1322
|
+
});
|
|
1323
|
+
},
|
|
1324
|
+
groupBy(t) {
|
|
1325
|
+
let n = e.groupBy ? [...e.groupBy, ...t] : [...t];
|
|
1326
|
+
return U({
|
|
1327
|
+
...e,
|
|
1328
|
+
groupBy: n
|
|
1329
|
+
});
|
|
1330
|
+
},
|
|
1331
|
+
having(t) {
|
|
1332
|
+
let n = e.having ? { and: [e.having, t] } : t;
|
|
1333
|
+
return U({
|
|
1334
|
+
...e,
|
|
1335
|
+
having: n
|
|
1336
|
+
});
|
|
1337
|
+
},
|
|
1338
|
+
exists() {
|
|
1339
|
+
return U({
|
|
1340
|
+
...e,
|
|
1341
|
+
projection: void 0,
|
|
1342
|
+
aggregations: [{
|
|
1343
|
+
op: "count",
|
|
1344
|
+
alias: "__exists__"
|
|
1345
|
+
}],
|
|
1346
|
+
take: 1
|
|
1347
|
+
});
|
|
1348
|
+
}
|
|
1349
|
+
});
|
|
1350
|
+
function qt(e) {
|
|
1351
|
+
return U({
|
|
1352
|
+
table: e.tableName,
|
|
1353
|
+
predicate: void 0,
|
|
1354
|
+
order: [],
|
|
1355
|
+
take: void 0,
|
|
1356
|
+
skip: void 0,
|
|
1357
|
+
projection: void 0,
|
|
1358
|
+
fullTextIndexes: e.appliedFullText,
|
|
1359
|
+
sourceTable: e
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
1362
|
+
var Jt = (e, t, n) => Yt(e, "id", t, n), Yt = (e, t, n, r, i = "asc") => {
|
|
1363
|
+
let a = [...e.order.filter((e) => e.column !== t), {
|
|
1364
|
+
column: t,
|
|
1365
|
+
direction: i
|
|
1366
|
+
}], o = n === void 0 ? void 0 : {
|
|
1367
|
+
column: t,
|
|
1368
|
+
op: i === "desc" ? "lt" : "gt",
|
|
1369
|
+
value: n
|
|
1370
|
+
}, s = o === void 0 ? e.predicate : e.predicate === void 0 ? o : { and: [e.predicate, o] };
|
|
1371
|
+
return {
|
|
1372
|
+
...e,
|
|
1373
|
+
predicate: s,
|
|
1374
|
+
order: a,
|
|
1375
|
+
take: r
|
|
1376
|
+
};
|
|
1377
|
+
}, Xt = (e) => {
|
|
1378
|
+
let t = {};
|
|
1379
|
+
for (let [n, r] of Object.entries(e)) xt(r), t[n] = qt(r);
|
|
1380
|
+
return t;
|
|
1381
|
+
}, Zt = (e) => e.isView === !0, Qt = (e, t, n) => {
|
|
1382
|
+
if (A(e), n.trim().length === 0) throw Error(`view('${e}', …): the SELECT body is empty — a view must define a query.`);
|
|
1383
|
+
let r = w(t);
|
|
1384
|
+
for (let t of Object.keys(r)) j(e, t);
|
|
1385
|
+
return {
|
|
1386
|
+
tableName: e,
|
|
1387
|
+
fields: r,
|
|
1388
|
+
isView: !0,
|
|
1389
|
+
viewSelect: n
|
|
1390
|
+
};
|
|
1391
|
+
}, $t = (e) => qt({
|
|
1392
|
+
...e,
|
|
1393
|
+
isReactive: !1,
|
|
1394
|
+
appliedMixins: [],
|
|
1395
|
+
appliedIndexes: [],
|
|
1396
|
+
appliedUniques: [],
|
|
1397
|
+
appliedFullText: [],
|
|
1398
|
+
appliedChecks: []
|
|
1399
|
+
}), en = (e, t, n = null) => {
|
|
1400
|
+
let r = n === null ? L(e.tableName, t) : `${L(n, t)}.${L(e.tableName, t)}`, i = e.viewSelect.trim();
|
|
1401
|
+
switch (t) {
|
|
1402
|
+
case "postgres":
|
|
1403
|
+
case "mysql":
|
|
1404
|
+
case "mariadb": return `CREATE OR REPLACE VIEW ${r} AS ${i};`;
|
|
1405
|
+
case "mssql": return `CREATE OR ALTER VIEW ${r} AS ${i};`;
|
|
1406
|
+
case "sqlite":
|
|
1407
|
+
case "turso": return `DROP VIEW IF EXISTS ${r};\nCREATE VIEW ${r} AS ${i};`;
|
|
1408
|
+
}
|
|
1409
|
+
}, tn = (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, nn = (e) => {
|
|
1410
|
+
if (e == null || typeof e != "string") return e;
|
|
1411
|
+
let t = e.trim();
|
|
1412
|
+
if (t.length === 0) return e;
|
|
1413
|
+
let n = t.charAt(0);
|
|
1414
|
+
if (n !== "{" && n !== "[" && n !== "\"" && n !== "t" && n !== "f" && n !== "n" && (n < "0" || n > "9") && n !== "-") return e;
|
|
1415
|
+
try {
|
|
1416
|
+
return JSON.parse(t);
|
|
1417
|
+
} catch {
|
|
1418
|
+
return e;
|
|
1419
|
+
}
|
|
1420
|
+
}, rn = (e) => e == null || typeof e == "string" ? e : typeof e == "number" || typeof e == "bigint" ? String(e) : e, an = (e) => {
|
|
1421
|
+
if (e == null || e instanceof Date) return e;
|
|
1422
|
+
if (typeof e == "string") {
|
|
1423
|
+
let t = new Date(e);
|
|
1424
|
+
return isNaN(t.getTime()) ? e : t;
|
|
1425
|
+
}
|
|
1426
|
+
if (typeof e == "number") {
|
|
1427
|
+
let t = new Date(e);
|
|
1428
|
+
return isNaN(t.getTime()) ? e : t;
|
|
1429
|
+
}
|
|
1430
|
+
return e;
|
|
1431
|
+
}, on = (e, t, n) => {
|
|
1432
|
+
if (e == null) return e;
|
|
1433
|
+
switch (t) {
|
|
1434
|
+
case "boolean": return n === "postgres" ? e : tn(e);
|
|
1435
|
+
case "vector": return n === "postgres" ? nn(e) : e;
|
|
1436
|
+
case "json": return n === "postgres" || n === "mysql" || n === "mariadb" ? e : nn(e);
|
|
1437
|
+
case "array": return n === "postgres" ? e : nn(e);
|
|
1438
|
+
case "timestamp":
|
|
1439
|
+
case "date": return n === "sqlite" || n === "turso" ? an(e) : e;
|
|
1440
|
+
case "decimal":
|
|
1441
|
+
case "bigint": return rn(e);
|
|
1442
|
+
default: return e;
|
|
1443
|
+
}
|
|
1444
|
+
}, sn = (e, t, n) => {
|
|
1445
|
+
if (e.length === 0) return e;
|
|
1446
|
+
let r = z(t);
|
|
1447
|
+
return r === void 0 ? e : cn(e, r, n);
|
|
1448
|
+
}, cn = (e, t, n) => {
|
|
1449
|
+
if (e.length === 0) return e;
|
|
1450
|
+
let r = t.fields, i = [];
|
|
1451
|
+
for (let [e, t] of Object.entries(r)) i.push({
|
|
1452
|
+
key: e,
|
|
1453
|
+
type: t.type
|
|
1454
|
+
});
|
|
1455
|
+
return e.map((e) => {
|
|
1456
|
+
let t = { ...e };
|
|
1457
|
+
for (let { key: e, type: r } of i) e in t && (t[e] = on(t[e], r, n));
|
|
1458
|
+
return t;
|
|
1459
|
+
});
|
|
1460
|
+
}, ln = (e, t) => {
|
|
1461
|
+
if (e == null) return e;
|
|
1462
|
+
switch (t) {
|
|
1463
|
+
case "json": return JSON.stringify(e);
|
|
1464
|
+
case "array":
|
|
1465
|
+
case "vector": return typeof e == "string" ? e : JSON.stringify(e);
|
|
1466
|
+
default: return e;
|
|
1467
|
+
}
|
|
1468
|
+
}, un = (e, t, n = ["json", "array"]) => {
|
|
1469
|
+
let r = z(t);
|
|
1470
|
+
if (r === void 0) return e;
|
|
1471
|
+
let i = r.fields, a = null;
|
|
1472
|
+
for (let [t, r] of Object.entries(i)) if (n.includes(r.type) && t in e) {
|
|
1473
|
+
let n = ln(e[t], r.type);
|
|
1474
|
+
n !== e[t] && (a === null && (a = { ...e }), a[t] = n);
|
|
1475
|
+
}
|
|
1476
|
+
return a ?? e;
|
|
1477
|
+
}, dn = /^[A-Za-z_][A-Za-z0-9_]*$/, fn = (e) => "$" + e.map((e) => typeof e == "number" ? `[${e}]` : dn.test(e) ? `.${e}` : `."${e.replace(/"/g, "\\\"")}"`).join(""), pn = (e) => "{" + e.map((e) => {
|
|
1478
|
+
let t = String(e);
|
|
1479
|
+
return /^[A-Za-z0-9_]+$/.test(t) ? t : `"${t.replace(/(["\\])/g, "\\$1")}"`;
|
|
1480
|
+
}).join(",") + "}", W = (e, t, n, r = {}) => {
|
|
1481
|
+
let i = L(e, n), a = r.numeric ?? !1;
|
|
1482
|
+
if (n === "postgres") {
|
|
1483
|
+
let e = `(${i} #>> '${pn(t)}'::text[])`;
|
|
1484
|
+
return a ? `${e}::numeric` : e;
|
|
1485
|
+
}
|
|
1486
|
+
let o = fn(t);
|
|
1487
|
+
switch (n) {
|
|
1488
|
+
case "mysql":
|
|
1489
|
+
case "mariadb": {
|
|
1490
|
+
let e = `JSON_UNQUOTE(JSON_EXTRACT(${i}, '${o}'))`;
|
|
1491
|
+
return a ? `CAST(${e} AS DECIMAL(38,10))` : e;
|
|
1492
|
+
}
|
|
1493
|
+
case "mssql": {
|
|
1494
|
+
let e = `JSON_VALUE(${i}, '${o}')`;
|
|
1495
|
+
return a ? `CAST(${e} AS FLOAT)` : e;
|
|
1496
|
+
}
|
|
1497
|
+
case "sqlite":
|
|
1498
|
+
case "turso": {
|
|
1499
|
+
let e = `json_extract(${i}, '${o}')`;
|
|
1500
|
+
return a ? `CAST(${e} AS REAL)` : e;
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
}, mn = class extends Error {
|
|
1504
|
+
_tag = "TenantNamespaceUnresolved";
|
|
1505
|
+
constructor(e) {
|
|
1506
|
+
super(e), this.name = "TenantNamespaceUnresolved";
|
|
1507
|
+
}
|
|
1508
|
+
}, hn = class extends Error {
|
|
1509
|
+
_tag = "TenantNamespaceInvalid";
|
|
1510
|
+
constructor(e) {
|
|
1511
|
+
super(e), this.name = "TenantNamespaceInvalid";
|
|
1512
|
+
}
|
|
1513
|
+
}, gn = 63, _n = "tenant_", vn = (e) => e.toLowerCase().replace(/[^a-z0-9_]/g, "_"), yn = (e) => {
|
|
1514
|
+
if (e == null || e === "") throw new mn("namespace isolation is on but the request has no resolvable tenant (subject.tenantId is null/empty). Refusing to run against a shared/default namespace — this would be a cross-tenant read. Authenticate with a tenant-scoped subject, or disable namespace isolation for this surface.");
|
|
1515
|
+
let t = vn(e);
|
|
1516
|
+
if (t.replace(/_/g, "") === "") throw new hn(`tenant id '${e}' has no usable identifier characters after sanitisation — cannot derive a distinct namespace.`);
|
|
1517
|
+
let n = `${_n}${t}`;
|
|
1518
|
+
if (n.length > gn) throw new hn(`namespace '${n}' for tenant '${e}' exceeds the ${gn}-byte identifier limit. Use a shorter tenant id.`);
|
|
1519
|
+
return n;
|
|
1520
|
+
}, G = (e, t) => e === null ? t : `${e}.${t}`, bn = /* @__PURE__ */ new Set(["timestamp", "date"]), xn = /^\d{4}-\d{2}-\d{2}([T ]\d{2}:\d{2})?/, Sn = (e, t) => {
|
|
1521
|
+
if (e === void 0 || t == null || !bn.has(e) || t instanceof Date) return t;
|
|
1522
|
+
if (typeof t == "number" && Number.isFinite(t)) return new Date(t);
|
|
1523
|
+
if (typeof t == "string" && xn.test(t)) {
|
|
1524
|
+
let e = new Date(t);
|
|
1525
|
+
return Number.isNaN(e.getTime()) ? t : e;
|
|
1526
|
+
}
|
|
1527
|
+
return t;
|
|
1528
|
+
}, Cn = (e, t) => e === void 0 || !bn.has(e) ? t : t.map((t) => Sn(e, t)), wn = (e, t) => {
|
|
1529
|
+
let { strings: n, values: r } = e, i = t.unsafe(n[0] ?? "");
|
|
1530
|
+
for (let e = 0; e < r.length; e++) i = t`${i}${r[e]}${t.unsafe(n[e + 1] ?? "")}`;
|
|
1531
|
+
return t`${i}`;
|
|
1532
|
+
}, K = (e) => e.replace(/[\\%_]/g, (e) => `\\${e}`), q = (e, t, n = null, r) => {
|
|
1533
|
+
if ("not" in e) return t`NOT (${q(e.not, t, n, r)})`;
|
|
1534
|
+
if ("and" in e) return e.and.length === 0 ? t`TRUE` : t.and(e.and.map((e) => q(e, t, n, r)));
|
|
1535
|
+
if ("or" in e) return e.or.length === 0 ? t`FALSE` : t.or(e.or.map((e) => q(e, t, n, r)));
|
|
1536
|
+
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
1537
|
+
let r = e, i = J(r.subquery, t, n);
|
|
1538
|
+
return r.op === "subquery-in" ? t`${t(r.column)} IN (${i})` : t`${t(r.column)} NOT IN (${i})`;
|
|
1539
|
+
}
|
|
1540
|
+
if (e.op === "exists" || e.op === "not-exists") {
|
|
1541
|
+
let r = e, i = J(r.subquery, t, n);
|
|
1542
|
+
return r.op === "exists" ? t`EXISTS (${i})` : t`NOT EXISTS (${i})`;
|
|
1543
|
+
}
|
|
1544
|
+
let i = e, a = t(i.column), o = i.path, s = o !== void 0 && o.length > 0, c = () => t.onDialectOrElse({
|
|
1545
|
+
mysql: () => t.unsafe(W(i.column, o, "mysql")),
|
|
1546
|
+
mssql: () => t.unsafe(W(i.column, o, "mssql")),
|
|
1547
|
+
sqlite: () => t.unsafe(W(i.column, o, "sqlite")),
|
|
1548
|
+
orElse: () => t.unsafe(W(i.column, o, "postgres"))
|
|
1549
|
+
}), l = () => t.onDialectOrElse({
|
|
1550
|
+
mysql: () => t.unsafe(W(i.column, o, "mysql", { numeric: !0 })),
|
|
1551
|
+
mssql: () => t.unsafe(W(i.column, o, "mssql", { numeric: !0 })),
|
|
1552
|
+
sqlite: () => t.unsafe(W(i.column, o, "sqlite", { numeric: !0 })),
|
|
1553
|
+
orElse: () => t.unsafe(W(i.column, o, "postgres", { numeric: !0 }))
|
|
1554
|
+
}), u = s ? c() : a, d = s ? l() : a, f = (e) => s && e != null ? String(e) : e, p = (e) => s ? Number(e) : e, m = s || r === void 0 ? void 0 : z(r)?.fields?.[i.column]?.type, h = (e) => Sn(m, e);
|
|
1555
|
+
switch (i.op) {
|
|
1556
|
+
case "eq": return t`${u} = ${f(h(i.value))}`;
|
|
1557
|
+
case "neq": return t`${u} <> ${f(h(i.value))}`;
|
|
1558
|
+
case "gt": return t`${d} > ${p(i.value)}`;
|
|
1559
|
+
case "gte": return t`${d} >= ${p(i.value)}`;
|
|
1560
|
+
case "lt": return t`${d} < ${p(i.value)}`;
|
|
1561
|
+
case "lte": return t`${d} <= ${p(i.value)}`;
|
|
1562
|
+
case "in": {
|
|
1563
|
+
let e = i.value ?? [];
|
|
1564
|
+
return e.length === 0 ? t`FALSE` : t`${u} IN ${t.in(s ? e.map((e) => f(e)) : e)}`;
|
|
1565
|
+
}
|
|
1566
|
+
case "notIn": {
|
|
1567
|
+
let e = i.value ?? [];
|
|
1568
|
+
return e.length === 0 ? t`TRUE` : t`${u} NOT IN ${t.in(s ? e.map((e) => f(e)) : e)}`;
|
|
1569
|
+
}
|
|
1570
|
+
case "contains": {
|
|
1571
|
+
let e = `%${K(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
|
|
1572
|
+
return t.onDialectOrElse({
|
|
1573
|
+
mysql: () => t`LOWER(${u}) LIKE LOWER(${e})`,
|
|
1574
|
+
mssql: () => t`LOWER(${u}) LIKE LOWER(${e})`,
|
|
1575
|
+
sqlite: () => t`LOWER(${u}) LIKE LOWER(${e})`,
|
|
1576
|
+
orElse: () => t`${u} ILIKE ${e} ESCAPE '\\'`
|
|
1577
|
+
});
|
|
1578
|
+
}
|
|
1579
|
+
case "startsWith": {
|
|
1580
|
+
let e = `${K(typeof i.value == "string" ? i.value : String(i.value ?? ""))}%`;
|
|
1581
|
+
return t.onDialectOrElse({
|
|
1582
|
+
mysql: () => t`${u} LIKE ${e}`,
|
|
1583
|
+
orElse: () => t`${u} LIKE ${e} ESCAPE '\\'`
|
|
1584
|
+
});
|
|
1585
|
+
}
|
|
1586
|
+
case "arrayContains": {
|
|
1587
|
+
let e = i.value ?? [];
|
|
1588
|
+
return e.length === 0 ? t`TRUE` : t.onDialectOrElse({
|
|
1589
|
+
mysql: () => t`JSON_CONTAINS(${u}, ${JSON.stringify(e)})`,
|
|
1590
|
+
mssql: () => t`(SELECT COUNT(DISTINCT value) FROM OPENJSON(${u}) WHERE value IN ${t.in(e)}) = ${e.length}`,
|
|
1591
|
+
sqlite: () => t`(SELECT COUNT(DISTINCT value) FROM json_each(${u}) WHERE value IN ${t.in(e)}) = ${e.length}`,
|
|
1592
|
+
orElse: () => t`${u} @> ${e}`
|
|
1593
|
+
});
|
|
1594
|
+
}
|
|
1595
|
+
case "arrayOverlaps": {
|
|
1596
|
+
let e = i.value ?? [];
|
|
1597
|
+
return e.length === 0 ? t`FALSE` : t.onDialectOrElse({
|
|
1598
|
+
mysql: () => t.or(e.map((e) => t`JSON_CONTAINS(${u}, ${JSON.stringify(e)})`)),
|
|
1599
|
+
mssql: () => t`EXISTS (SELECT 1 FROM OPENJSON(${u}) WHERE value IN ${t.in(e)})`,
|
|
1600
|
+
sqlite: () => t`EXISTS (SELECT 1 FROM json_each(${u}) WHERE value IN ${t.in(e)})`,
|
|
1601
|
+
orElse: () => t`${u} && ${e}`
|
|
1602
|
+
});
|
|
1603
|
+
}
|
|
1604
|
+
case "arrayHas": return t.onDialectOrElse({
|
|
1605
|
+
mysql: () => t`JSON_CONTAINS(${u}, ${JSON.stringify(i.value)})`,
|
|
1606
|
+
mssql: () => t`${i.value} IN (SELECT value FROM OPENJSON(${u}))`,
|
|
1607
|
+
sqlite: () => t`EXISTS (SELECT 1 FROM json_each(${u}) WHERE value = ${i.value})`,
|
|
1608
|
+
orElse: () => t`${i.value} = ANY(${u})`
|
|
1609
|
+
});
|
|
1610
|
+
case "isNull": return t`${u} IS NULL`;
|
|
1611
|
+
case "isNotNull": return t`${u} IS NOT NULL`;
|
|
1612
|
+
case "spatial": {
|
|
1613
|
+
let e = i.value, n = t.unsafe("::geometry"), r = e.bufferMeters === void 0 ? t`${e.geom}${n}` : t`ST_Buffer(${e.geom}::geography, ${e.bufferMeters})::geometry`;
|
|
1614
|
+
return t.onDialectOrElse({
|
|
1615
|
+
mysql: () => {
|
|
1616
|
+
throw Error("@voltro/plugin-postgis: spatial predicates are postgres-only");
|
|
1617
|
+
},
|
|
1618
|
+
mssql: () => {
|
|
1619
|
+
throw Error("@voltro/plugin-postgis: spatial predicates are postgres-only");
|
|
1620
|
+
},
|
|
1621
|
+
sqlite: () => {
|
|
1622
|
+
throw Error("@voltro/plugin-postgis: spatial predicates are postgres-only");
|
|
1623
|
+
},
|
|
1624
|
+
orElse: () => e.fn === "ST_DWithin" ? t`ST_DWithin(${a}::geography, ${e.geom}::geography, ${e.distanceMeters})` : e.fn === "&&" ? t`${a}${n} && ${r}` : t`${t.unsafe(e.fn)}(${a}${n}, ${r})`
|
|
1625
|
+
});
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
}, Tn = (e, t) => {
|
|
1629
|
+
let n = [];
|
|
1630
|
+
return e.partitionBy && e.partitionBy.length > 0 && n.push(t`PARTITION BY ${t.csv(e.partitionBy.map((e) => t`${t(e)}`))}`), e.orderBy && e.orderBy.length > 0 && n.push(t`ORDER BY ${t.csv(e.orderBy.map((e) => e.direction === "desc" ? t`${t(e.column)} DESC` : t`${t(e.column)} ASC`))}`), n.length === 0 ? t`` : n.length === 1 ? n[0] : n.reduce((e, n, r) => r === 0 ? n : t`${e} ${n}`);
|
|
1631
|
+
}, En = (e, t) => t.csv(e.map((e) => {
|
|
1632
|
+
let n = e.column === void 0 ? t.unsafe("*") : t`${t(e.column)}`;
|
|
1633
|
+
if (e.op.startsWith("window-")) {
|
|
1634
|
+
let r = Tn(e.window ?? {}, t);
|
|
1635
|
+
switch (e.op) {
|
|
1636
|
+
case "window-row-number": return t`ROW_NUMBER() OVER (${r}) AS ${t(e.alias)}`;
|
|
1637
|
+
case "window-rank": return t`RANK() OVER (${r}) AS ${t(e.alias)}`;
|
|
1638
|
+
case "window-dense-rank": return t`DENSE_RANK() OVER (${r}) AS ${t(e.alias)}`;
|
|
1639
|
+
case "window-lag": return t`LAG(${n}, ${t.unsafe(String(e.offset ?? 1))}) OVER (${r}) AS ${t(e.alias)}`;
|
|
1640
|
+
case "window-lead": return t`LEAD(${n}, ${t.unsafe(String(e.offset ?? 1))}) OVER (${r}) AS ${t(e.alias)}`;
|
|
1641
|
+
case "window-sum-over": return t`SUM(${n}) OVER (${r}) AS ${t(e.alias)}`;
|
|
1642
|
+
case "window-avg-over": return t`AVG(${n}) OVER (${r}) AS ${t(e.alias)}`;
|
|
1643
|
+
default: throw Error(`compileAggregateProjection: unknown window op '${e.op}'`);
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
switch (e.op) {
|
|
1647
|
+
case "count": return t`COUNT(${n}) AS ${t(e.alias)}`;
|
|
1648
|
+
case "count-distinct": return t`COUNT(DISTINCT ${n}) AS ${t(e.alias)}`;
|
|
1649
|
+
case "sum": return t`SUM(${n}) AS ${t(e.alias)}`;
|
|
1650
|
+
case "avg": return t`AVG(${n}) AS ${t(e.alias)}`;
|
|
1651
|
+
case "min": return t`MIN(${n}) AS ${t(e.alias)}`;
|
|
1652
|
+
case "max": return t`MAX(${n}) AS ${t(e.alias)}`;
|
|
1653
|
+
case "column":
|
|
1654
|
+
if (e.column === void 0) throw Error(`compileAggregateProjection: 'column' projection requires a column name (alias '${e.alias}')`);
|
|
1655
|
+
return t`${t(e.column)} AS ${t(e.alias)}`;
|
|
1656
|
+
default: throw Error(`compileAggregateProjection: unknown op '${e.op}'`);
|
|
1657
|
+
}
|
|
1658
|
+
})), Dn = (e) => `[${e.join(",")}]`, On = (e, t) => {
|
|
1659
|
+
if (e.queryVector === void 0) return null;
|
|
1660
|
+
let n = t(e.column), r = Dn(e.queryVector), i = e.distance === "cosine" ? "<=>" : e.distance === "l2" ? "<->" : "<#>", a = e.distance === "cosine" ? "VEC_DISTANCE_COSINE" : "VEC_DISTANCE_EUCLIDEAN";
|
|
1661
|
+
return t.onDialectOrElse({
|
|
1662
|
+
mysql: () => t`${t.unsafe(a)}(${n}, ${r})`,
|
|
1663
|
+
mssql: () => t`NULL`,
|
|
1664
|
+
sqlite: () => t`NULL`,
|
|
1665
|
+
orElse: () => t`${n} ${t.unsafe(i)} ${r}::vector`
|
|
1666
|
+
});
|
|
1667
|
+
}, kn = (e, t) => {
|
|
1668
|
+
let n = t.unsafe(e.useGeography ? "::geography" : "::geometry");
|
|
1669
|
+
return t`ST_Distance(${t(e.column)}${n}, ${e.geom}${n})`;
|
|
1670
|
+
}, An = (e, t) => t`${t(e.column)} <-> ${e.geom}::geometry`, jn = (e, t) => t`${t(`${e.indexName}_tsv`)}`, Mn = (e, t) => `${t}_${e.indexName}_fts`, Nn = (e, t, n) => {
|
|
1671
|
+
let r = n.csv(e.columns.map((e) => n`${n(e)}`)), i = `%${K(e.query)}%`;
|
|
1672
|
+
return n.onDialectOrElse({
|
|
1673
|
+
mysql: () => n`MATCH(${r}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
|
|
1674
|
+
sqlite: () => {
|
|
1675
|
+
let r = n(Mn(e, t));
|
|
1676
|
+
return n`${n("id")} IN (SELECT ${n("row_id")} FROM ${r} WHERE ${r} MATCH ${e.query})`;
|
|
1677
|
+
},
|
|
1678
|
+
mssql: () => n.or(e.columns.map((e) => n`LOWER(${n(e)}) LIKE LOWER(${i}) ESCAPE '\\'`)),
|
|
1679
|
+
orElse: () => n`${jn(e, n)} @@ plainto_tsquery(${e.config ?? "english"}, ${e.query})`
|
|
1680
|
+
});
|
|
1681
|
+
}, Pn = (e, t, n) => {
|
|
1682
|
+
let r = `%${K(e.query)}%`;
|
|
1683
|
+
return n.onDialectOrElse({
|
|
1684
|
+
mysql: () => n`MATCH(${n.csv(e.columns.map((e) => n`${n(e)}`))}) AGAINST(${e.query} IN NATURAL LANGUAGE MODE)`,
|
|
1685
|
+
sqlite: () => {
|
|
1686
|
+
let r = n(Mn(e, t));
|
|
1687
|
+
return n`COALESCE((SELECT -bm25(${r}) FROM ${r} WHERE ${r} MATCH ${e.query} AND ${r}.${n("row_id")} = ${n("id")}), 0)`;
|
|
1688
|
+
},
|
|
1689
|
+
mssql: () => e.columns.map((e) => n`(CASE WHEN LOWER(${n(e)}) LIKE LOWER(${r}) ESCAPE '\\' THEN 1 ELSE 0 END)`).reduce((e, t, r) => r === 0 ? t : n`${e} + ${t}`),
|
|
1690
|
+
orElse: () => n`ts_rank(${jn(e, n)}, plainto_tsquery(${e.config ?? "english"}, ${e.query}))`
|
|
1691
|
+
});
|
|
1692
|
+
}, J = (e, t, n = null) => {
|
|
1693
|
+
if (e.setOp && e.setOp.queries.length >= 2) {
|
|
1694
|
+
let r = e.setOp.kind === "union" ? "UNION" : e.setOp.kind === "union-all" ? "UNION ALL" : e.setOp.kind === "intersect" ? "INTERSECT" : "EXCEPT", i = e.setOp.queries.map((e) => t`(${J(e, t, n)})`).reduce((e, n, i) => i === 0 ? n : t`${e} ${t.unsafe(r)} ${n}`), a = [];
|
|
1695
|
+
if (B(e).length > 0 && a.push(t` ORDER BY ${t.csv(B(e).map((e) => e.direction === "desc" ? t`${t(e.column)} DESC` : t`${t(e.column)} ASC`))}`), e.take !== void 0) {
|
|
1696
|
+
if (!Number.isInteger(e.take) || e.take < 0) throw Error(`compileSelect: invalid take ${e.take}`);
|
|
1697
|
+
a.push(t` LIMIT ${t.unsafe(String(e.take))}`);
|
|
1698
|
+
}
|
|
1699
|
+
if (e.skip !== void 0) {
|
|
1700
|
+
if (!Number.isInteger(e.skip) || e.skip < 0) throw Error(`compileSelect: invalid skip ${e.skip}`);
|
|
1701
|
+
a.push(t` OFFSET ${t.unsafe(String(e.skip))}`);
|
|
1702
|
+
}
|
|
1703
|
+
return t`${i}${a.reduce((e, n) => t`${e}${n}`, t``)}`;
|
|
1704
|
+
}
|
|
1705
|
+
let r = e.annClause === void 0 ? null : On(e.annClause, t);
|
|
1706
|
+
e.spatialClause !== void 0 && t.onDialectOrElse({
|
|
1707
|
+
mysql: () => {
|
|
1708
|
+
throw Error("@voltro/plugin-postgis: spatial distance / KNN ordering is postgres-only");
|
|
1709
|
+
},
|
|
1710
|
+
mssql: () => {
|
|
1711
|
+
throw Error("@voltro/plugin-postgis: spatial distance / KNN ordering is postgres-only");
|
|
1712
|
+
},
|
|
1713
|
+
sqlite: () => {
|
|
1714
|
+
throw Error("@voltro/plugin-postgis: spatial distance / KNN ordering is postgres-only");
|
|
1715
|
+
},
|
|
1716
|
+
orElse: () => t``
|
|
1717
|
+
});
|
|
1718
|
+
let i = e.spatialClause?.projectAs === void 0 ? null : kn(e.spatialClause, t), a = e.aggregations && e.aggregations.length > 0 ? En(e.aggregations, t) : e.joinedProjection && e.joinedProjection.length > 0 ? t.csv(e.joinedProjection.map((e) => t`${t(e.source)} AS ${t(e.outputKey)}`)) : e.projection && e.projection.length > 0 ? t.csv(e.projection.map((e) => t`${t(e)}`)) : t`*`, o = (e.aggregations && e.aggregations.length > 0) === !0, s = r !== null && !o ? t`${a}, ${r} AS ${t("distance")}` : a, c = e.fullTextSearch, l = c?.rank !== void 0 && !o ? Pn(c, e.table, t) : null, u = l !== null && c?.rank !== void 0 ? t`${s}, ${l} AS ${t(c.rank.alias)}` : s, d = i !== null && !o && e.spatialClause?.projectAs !== void 0 ? t`${u}, ${i} AS ${t(e.spatialClause.projectAs)}` : u, f = e.distinctOn && e.distinctOn.length > 0 ? t.onDialectOrElse({
|
|
1719
|
+
orElse: () => t`DISTINCT ON (${t.csv(e.distinctOn.map((e) => t`${t(e)}`))}) `,
|
|
1720
|
+
mysql: () => t`DISTINCT `,
|
|
1721
|
+
mssql: () => t`DISTINCT `,
|
|
1722
|
+
sqlite: () => t`DISTINCT `
|
|
1723
|
+
}) : e.distinct ? t`DISTINCT ` : t``, p = e.lock === "update", m = p ? t.onDialectOrElse({
|
|
1724
|
+
mssql: () => t` WITH (UPDLOCK, ROWLOCK)`,
|
|
1725
|
+
orElse: () => t``
|
|
1726
|
+
}) : t``, h = p ? t.onDialectOrElse({
|
|
1727
|
+
mssql: () => t``,
|
|
1728
|
+
sqlite: () => t``,
|
|
1729
|
+
orElse: () => t` FOR UPDATE`
|
|
1730
|
+
}) : t``, g = e.alias === void 0 ? t`${t(G(n, e.table))}${m}` : t`${t(G(n, e.table))} AS ${t(e.alias)}${m}`, ee = (e.joins ?? []).map((e) => {
|
|
1731
|
+
let r = e.kind === "inner" ? "INNER" : "LEFT";
|
|
1732
|
+
return t` ${t.unsafe(r)} JOIN ${t(G(n, e.table))} AS ${t(e.alias)} ON ${q(e.on, t, n)}`;
|
|
1733
|
+
}), te = ee.length > 0 ? ee.reduce((e, n) => t`${e}${n}`, g) : g, ne = c === void 0 ? null : Nn(c, e.table, t), re = [e.predicate ? q(e.predicate, t, n, e.table) : null, ne].filter((e) => e !== null), _ = re.length > 0 ? t` WHERE ${t.and(re)}` : t``, ie = e.groupBy && e.groupBy.length > 0 ? t` GROUP BY ${t.csv(e.groupBy.map((e) => t`${t(e)}`))}` : t``, v = e.having ? t` HAVING ${q(e.having, t, n, e.table)}` : t``, y = e.skip !== void 0, b = [];
|
|
1734
|
+
r !== null && b.push(t`${r} ASC`), e.spatialClause?.order !== void 0 && b.push(e.spatialClause.order === "desc" ? t`${An(e.spatialClause, t)} DESC` : t`${An(e.spatialClause, t)} ASC`), l !== null && c?.rank?.order === !0 && b.push(t`${l} DESC`);
|
|
1735
|
+
for (let n of B(e)) b.push(n.direction === "desc" ? t`${t(n.column)} DESC` : t`${t(n.column)} ASC`);
|
|
1736
|
+
let ae = b.length > 0 ? t` ORDER BY ${t.csv(b)}` : y ? t.onDialectOrElse({
|
|
1737
|
+
mssql: () => t` ORDER BY (SELECT NULL)`,
|
|
1738
|
+
orElse: () => t``
|
|
1739
|
+
}) : t``, x = (e) => {
|
|
1740
|
+
if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw Error(`compileSelect: expected non-negative integer take/skip, got ${e}`);
|
|
1741
|
+
return t.unsafe(String(e));
|
|
1742
|
+
}, S = (e.ctes ?? []).map((e) => t`${t(e.name)} AS (${J(e.descriptor, t, n)})`), C = (e.ctes ?? []).some((e) => e.recursive === !0), oe = S.length > 0 ? t`WITH ${t.unsafe(C ? "RECURSIVE " : "")}${t.csv(S)} ` : t``;
|
|
1743
|
+
return t.onDialectOrElse({
|
|
1744
|
+
mssql: () => {
|
|
1745
|
+
let n = e.take !== void 0 && !y ? t`TOP ${x(e.take)} ` : t``, r = y ? t` OFFSET ${x(e.skip)} ROWS FETCH NEXT ${x(e.take ?? 2 ** 53 - 1)} ROWS ONLY` : t``;
|
|
1746
|
+
return t`${oe}SELECT ${n}${f}${d} FROM ${te}${_}${ie}${v}${ae}${r}`;
|
|
1747
|
+
},
|
|
1748
|
+
orElse: () => {
|
|
1749
|
+
let n = e.take === void 0 ? t`` : t` LIMIT ${x(e.take)}`, r = y ? t` OFFSET ${x(e.skip)}` : t``;
|
|
1750
|
+
return t`${oe}SELECT ${f}${d} FROM ${te}${_}${ie}${v}${ae}${n}${r}${h}`;
|
|
1751
|
+
}
|
|
1752
|
+
});
|
|
1753
|
+
}, Y = (e, t) => {
|
|
1754
|
+
let n = (e) => {
|
|
1755
|
+
if (typeof e != "string" || !/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/.test(e)) return null;
|
|
1756
|
+
let [t = "", n = ""] = e.replace(/^[+-]/, "").split("."), r = t.replace(/^0+/, "") || "0";
|
|
1757
|
+
return {
|
|
1758
|
+
negative: e.startsWith("-") && /[1-9]/.test(r + n),
|
|
1759
|
+
whole: r,
|
|
1760
|
+
fraction: n
|
|
1761
|
+
};
|
|
1762
|
+
}, r = n(e), i = n(t);
|
|
1763
|
+
if (!r || !i) return null;
|
|
1764
|
+
if (r.negative !== i.negative) return r.negative ? -1 : 1;
|
|
1765
|
+
let a = r.whole.length - i.whole.length;
|
|
1766
|
+
if (a === 0 && (a = r.whole === i.whole ? 0 : r.whole > i.whole ? 1 : -1), a === 0) {
|
|
1767
|
+
let e = Math.max(r.fraction.length, i.fraction.length), t = r.fraction.padEnd(e, "0"), n = i.fraction.padEnd(e, "0");
|
|
1768
|
+
a = t === n ? 0 : t > n ? 1 : -1;
|
|
1769
|
+
}
|
|
1770
|
+
return a === 0 ? 0 : (a > 0 ? 1 : -1) * (r.negative ? -1 : 1);
|
|
1771
|
+
}, Fn = (e, t) => ({
|
|
1772
|
+
column: e,
|
|
1773
|
+
op: "eq",
|
|
1774
|
+
value: t
|
|
1775
|
+
}), In = (e, t) => ({
|
|
1776
|
+
column: e,
|
|
1777
|
+
op: "neq",
|
|
1778
|
+
value: t
|
|
1779
|
+
}), Ln = (e, t) => ({
|
|
1780
|
+
column: e,
|
|
1781
|
+
op: "gt",
|
|
1782
|
+
value: t
|
|
1783
|
+
}), Rn = (e, t) => ({
|
|
1784
|
+
column: e,
|
|
1785
|
+
op: "gte",
|
|
1786
|
+
value: t
|
|
1787
|
+
}), zn = (e, t) => ({
|
|
1788
|
+
column: e,
|
|
1789
|
+
op: "lt",
|
|
1790
|
+
value: t
|
|
1791
|
+
}), Bn = (e, t) => ({
|
|
1792
|
+
column: e,
|
|
1793
|
+
op: "lte",
|
|
1794
|
+
value: t
|
|
1795
|
+
}), Vn = (e, t) => ({
|
|
1796
|
+
column: e,
|
|
1797
|
+
op: "in",
|
|
1798
|
+
value: t
|
|
1799
|
+
}), Hn = (e, t) => ({
|
|
1800
|
+
column: e,
|
|
1801
|
+
op: "notIn",
|
|
1802
|
+
value: t
|
|
1803
|
+
}), Un = (e, t) => ({
|
|
1804
|
+
column: e,
|
|
1805
|
+
op: "contains",
|
|
1806
|
+
value: t
|
|
1807
|
+
}), Wn = (e, t) => ({
|
|
1808
|
+
column: e,
|
|
1809
|
+
op: "startsWith",
|
|
1810
|
+
value: t
|
|
1811
|
+
}), Gn = (e, t) => ({
|
|
1812
|
+
column: e,
|
|
1813
|
+
op: "arrayContains",
|
|
1814
|
+
value: t
|
|
1815
|
+
}), Kn = (e, t) => ({
|
|
1816
|
+
column: e,
|
|
1817
|
+
op: "arrayOverlaps",
|
|
1818
|
+
value: t
|
|
1819
|
+
}), qn = (e, t) => ({
|
|
1820
|
+
column: e,
|
|
1821
|
+
op: "arrayHas",
|
|
1822
|
+
value: t
|
|
1823
|
+
}), Jn = {
|
|
1824
|
+
column: "id",
|
|
1825
|
+
op: "in",
|
|
1826
|
+
value: []
|
|
1827
|
+
}, Yn = (e) => ({
|
|
1828
|
+
column: e,
|
|
1829
|
+
op: "isNull"
|
|
1830
|
+
}), Xn = (e) => ({
|
|
1831
|
+
column: e,
|
|
1832
|
+
op: "isNotNull"
|
|
1833
|
+
}), Zn = (e, t) => ({
|
|
1834
|
+
column: e,
|
|
1835
|
+
op: "spatial",
|
|
1836
|
+
value: t
|
|
1837
|
+
}), Qn = (...e) => ({ and: e }), $n = (...e) => ({ or: e }), er = (e) => ({ not: e }), tr = (e, ...t) => {
|
|
1838
|
+
if (t.length === 0) throw Error(`jsonField("${e}"): at least one path segment is required`);
|
|
1839
|
+
let n = (n, r) => ({
|
|
1840
|
+
column: e,
|
|
1841
|
+
path: t,
|
|
1842
|
+
op: n,
|
|
1843
|
+
value: r
|
|
1844
|
+
});
|
|
1845
|
+
return {
|
|
1846
|
+
eq: (e) => n("eq", e),
|
|
1847
|
+
neq: (e) => n("neq", e),
|
|
1848
|
+
gt: (e) => n("gt", e),
|
|
1849
|
+
gte: (e) => n("gte", e),
|
|
1850
|
+
lt: (e) => n("lt", e),
|
|
1851
|
+
lte: (e) => n("lte", e),
|
|
1852
|
+
inSet: (e) => n("in", e),
|
|
1853
|
+
notInSet: (e) => n("notIn", e),
|
|
1854
|
+
contains: (e) => n("contains", e),
|
|
1855
|
+
startsWith: (e) => n("startsWith", e),
|
|
1856
|
+
isNull: () => n("isNull"),
|
|
1857
|
+
isNotNull: () => n("isNotNull")
|
|
1858
|
+
};
|
|
1859
|
+
}, X = (e) => "descriptor" in e ? e.descriptor : e, nr = (e, t) => ({
|
|
1860
|
+
column: e,
|
|
1861
|
+
op: "subquery-in",
|
|
1862
|
+
subquery: X(t)
|
|
1863
|
+
}), rr = (e, t) => ({
|
|
1864
|
+
column: e,
|
|
1865
|
+
op: "subquery-not-in",
|
|
1866
|
+
subquery: X(t)
|
|
1867
|
+
}), ir = (e) => ({
|
|
1868
|
+
op: "exists",
|
|
1869
|
+
subquery: X(e)
|
|
1870
|
+
}), ar = (e) => ({
|
|
1871
|
+
op: "not-exists",
|
|
1872
|
+
subquery: X(e)
|
|
1873
|
+
}), or = /^\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?)?$/, sr = (e) => {
|
|
1874
|
+
if (e instanceof Date) return e.getTime();
|
|
1875
|
+
if (typeof e == "string" && or.test(e)) {
|
|
1876
|
+
let t = Date.parse(e);
|
|
1877
|
+
return Number.isNaN(t) ? void 0 : t;
|
|
1878
|
+
}
|
|
1879
|
+
}, cr = (e, t) => {
|
|
1880
|
+
if (!(e instanceof Date) && !(t instanceof Date)) return;
|
|
1881
|
+
let n = sr(e), r = sr(t);
|
|
1882
|
+
return n === void 0 || r === void 0 ? void 0 : [n, r];
|
|
1883
|
+
}, lr = (e, t) => {
|
|
1884
|
+
if (e === t) return !0;
|
|
1885
|
+
let n = cr(e, t);
|
|
1886
|
+
return n !== void 0 && n[0] === n[1];
|
|
1887
|
+
}, ur = (e, t) => {
|
|
1888
|
+
if (e == null || t == null) return null;
|
|
1889
|
+
let n = cr(e, t);
|
|
1890
|
+
if (n !== void 0) return n[0] === n[1] ? 0 : n[0] > n[1] ? 1 : -1;
|
|
1891
|
+
let r = e instanceof Date ? e.getTime() : e, i = t instanceof Date ? t.getTime() : t;
|
|
1892
|
+
return typeof r == typeof i ? r === i ? 0 : r > i ? 1 : -1 : null;
|
|
1893
|
+
}, Z = (e, t, n = null, r = {}) => {
|
|
1894
|
+
if (!t) return !1;
|
|
1895
|
+
if ("not" in e) return !Z(e.not, t, n, r);
|
|
1896
|
+
if ("and" in e) {
|
|
1897
|
+
for (let i of e.and) if (!Z(i, t, n, r)) return !1;
|
|
1898
|
+
return !0;
|
|
1899
|
+
}
|
|
1900
|
+
if ("or" in e) {
|
|
1901
|
+
for (let i of e.or) if (Z(i, t, n, r)) return !0;
|
|
1902
|
+
return !1;
|
|
1903
|
+
}
|
|
1904
|
+
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
1905
|
+
if (!n) return !1;
|
|
1906
|
+
let i = n.get(e.subquery);
|
|
1907
|
+
if (!(i instanceof Set)) return !1;
|
|
1908
|
+
let a = t[e.column], o = r[e.column]?.type === "decimal" ? [...i].some((e) => Y(a, e) === 0) : i.has(a);
|
|
1909
|
+
return e.op === "subquery-in" ? o : !o;
|
|
1910
|
+
}
|
|
1911
|
+
if (e.op === "exists" || e.op === "not-exists") {
|
|
1912
|
+
if (!n) return !1;
|
|
1913
|
+
let t = n.get(e.subquery), r = typeof t == "number" ? t > 0 : t instanceof Set && t.size > 0;
|
|
1914
|
+
return e.op === "exists" ? r : !r;
|
|
1915
|
+
}
|
|
1916
|
+
let i = e, a = t[i.column], o = r[i.column]?.type === "decimal", s = (e, t) => o && e != null && t != null ? Y(e, t) === 0 : lr(e, t), c = o ? Y : ur;
|
|
1917
|
+
switch (i.op) {
|
|
1918
|
+
case "eq": return s(a, i.value);
|
|
1919
|
+
case "neq": return !s(a, i.value);
|
|
1920
|
+
case "gt": return (c(a, i.value) ?? -1) > 0;
|
|
1921
|
+
case "gte": return (c(a, i.value) ?? -1) >= 0;
|
|
1922
|
+
case "lt": return (c(a, i.value) ?? 1) < 0;
|
|
1923
|
+
case "lte": return (c(a, i.value) ?? 1) <= 0;
|
|
1924
|
+
case "in": return Array.isArray(i.value) && i.value.some((e) => s(a, e));
|
|
1925
|
+
case "notIn": return Array.isArray(i.value) && !i.value.some((e) => s(a, e));
|
|
1926
|
+
case "contains": return typeof a == "string" && typeof i.value == "string" && a.toLowerCase().includes(i.value.toLowerCase());
|
|
1927
|
+
case "startsWith": return typeof a == "string" && typeof i.value == "string" && a.startsWith(i.value);
|
|
1928
|
+
case "arrayContains": {
|
|
1929
|
+
let e = Array.isArray(a) ? a : [];
|
|
1930
|
+
return (Array.isArray(i.value) ? i.value : []).every((t) => e.includes(t));
|
|
1931
|
+
}
|
|
1932
|
+
case "arrayOverlaps": {
|
|
1933
|
+
let e = Array.isArray(a) ? a : [];
|
|
1934
|
+
return (Array.isArray(i.value) ? i.value : []).some((t) => e.includes(t));
|
|
1935
|
+
}
|
|
1936
|
+
case "arrayHas": return Array.isArray(a) && a.includes(i.value);
|
|
1937
|
+
case "isNull": return a == null;
|
|
1938
|
+
case "isNotNull": return a != null;
|
|
1939
|
+
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.");
|
|
1940
|
+
}
|
|
1941
|
+
}, Q = function* (e) {
|
|
1942
|
+
if ("not" in e) {
|
|
1943
|
+
yield* Q(e.not);
|
|
1944
|
+
return;
|
|
1945
|
+
}
|
|
1946
|
+
if ("and" in e) {
|
|
1947
|
+
for (let t of e.and) yield* Q(t);
|
|
1948
|
+
return;
|
|
1949
|
+
}
|
|
1950
|
+
if ("or" in e) {
|
|
1951
|
+
for (let t of e.or) yield* Q(t);
|
|
1952
|
+
return;
|
|
1953
|
+
}
|
|
1954
|
+
e.op === "subquery-in" || e.op === "subquery-not-in" ? yield {
|
|
1955
|
+
kind: "in",
|
|
1956
|
+
descriptor: e.subquery
|
|
1957
|
+
} : (e.op === "exists" || e.op === "not-exists") && (yield {
|
|
1958
|
+
kind: "exists",
|
|
1959
|
+
descriptor: e.subquery
|
|
1960
|
+
});
|
|
1961
|
+
}, $ = function* (e, t = !0) {
|
|
1962
|
+
if ("not" in e) {
|
|
1963
|
+
yield* $(e.not, !1);
|
|
1964
|
+
return;
|
|
1965
|
+
}
|
|
1966
|
+
if ("and" in e) {
|
|
1967
|
+
for (let n of e.and) yield* $(n, t);
|
|
1968
|
+
return;
|
|
1969
|
+
}
|
|
1970
|
+
if ("or" in e) {
|
|
1971
|
+
for (let t of e.or) yield* $(t, !1);
|
|
1972
|
+
return;
|
|
1973
|
+
}
|
|
1974
|
+
e.op !== "subquery-in" && e.op !== "subquery-not-in" && e.op !== "exists" && e.op !== "not-exists" && (yield {
|
|
1975
|
+
...e,
|
|
1976
|
+
conjunctive: t
|
|
1977
|
+
});
|
|
1978
|
+
}, dr = (e, t) => ({
|
|
1979
|
+
name: e,
|
|
1980
|
+
body: t
|
|
1981
|
+
}), fr = (e) => {
|
|
1982
|
+
if (e.lifecycle === "cron" && !e.cron) throw Error(`seed "${e.id}": lifecycle 'cron' requires a 'cron' field`);
|
|
1983
|
+
if (e.lifecycle === "onSchemaChange" && (!e.watchedTables || e.watchedTables.length === 0)) throw Error(`seed "${e.id}": lifecycle 'onSchemaChange' requires at least one entry in 'watchedTables'`);
|
|
1984
|
+
let t = e.steps({ step: dr });
|
|
1985
|
+
if (t.length === 0) throw Error(`seed "${e.id}": at least one step is required`);
|
|
1986
|
+
return {
|
|
1987
|
+
__seed: !0,
|
|
1988
|
+
id: e.id,
|
|
1989
|
+
name: e.name,
|
|
1990
|
+
lifecycle: e.lifecycle,
|
|
1991
|
+
...e.cron === void 0 ? {} : { cron: e.cron },
|
|
1992
|
+
...e.timezone === void 0 ? {} : { timezone: e.timezone },
|
|
1993
|
+
...e.watchedTables === void 0 ? {} : { watchedTables: e.watchedTables },
|
|
1994
|
+
...e.fingerprint === void 0 ? {} : { fingerprint: e.fingerprint },
|
|
1995
|
+
steps: t
|
|
1996
|
+
};
|
|
1997
|
+
}, pr = (e) => typeof e == "object" && !!e && "__seed" in e && e.__seed === !0, mr = null, hr = null, gr = (e) => {
|
|
1998
|
+
mr = e;
|
|
1999
|
+
}, _r = (e) => {
|
|
2000
|
+
hr = e;
|
|
2001
|
+
}, vr = async (e) => {
|
|
2002
|
+
let t = mr;
|
|
2003
|
+
t !== null && await t(e);
|
|
2004
|
+
}, yr = async (e) => {
|
|
2005
|
+
let t = hr;
|
|
2006
|
+
t !== null && e.changedTables.length !== 0 && await t(e);
|
|
2007
|
+
}, br = (e) => {
|
|
2008
|
+
if (!e.id || e.id.length === 0) throw Error("migration: `id` is required + must be non-empty");
|
|
2009
|
+
if (!e.up || !e.down) throw Error(`migration ${e.id}: both \`up\` and \`down\` must be functions`);
|
|
2010
|
+
return e;
|
|
2011
|
+
}, xr = Symbol.for("voltro.migration.irreversible"), Sr = class extends Error {
|
|
2012
|
+
migrationId;
|
|
2013
|
+
reason;
|
|
2014
|
+
_tag = "IrreversibleMigrationError";
|
|
2015
|
+
constructor(e, t) {
|
|
2016
|
+
super(`migration ${e} cannot be rolled back: ${t}`), this.migrationId = e, this.reason = t, this.name = "IrreversibleMigrationError";
|
|
2017
|
+
}
|
|
2018
|
+
}, Cr = (e) => {
|
|
2019
|
+
if (!e || e.trim().length === 0) throw Error("irreversible(): a reason is required");
|
|
2020
|
+
return Object.assign(() => t.fail(new Sr("<unknown>", e)), { [xr]: e });
|
|
2021
|
+
}, wr = (e) => {
|
|
2022
|
+
let t = e[xr];
|
|
2023
|
+
return typeof t == "string" ? t : void 0;
|
|
2024
|
+
}, Tr = class {
|
|
2025
|
+
reason;
|
|
2026
|
+
_tag = "MigrationSkipped";
|
|
2027
|
+
constructor(e) {
|
|
2028
|
+
this.reason = e;
|
|
2029
|
+
}
|
|
2030
|
+
}, Er = class extends Error {
|
|
2031
|
+
migrationId;
|
|
2032
|
+
failed;
|
|
2033
|
+
_tag = "MigrationExpectationFailed";
|
|
2034
|
+
constructor(e, t) {
|
|
2035
|
+
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";
|
|
2036
|
+
}
|
|
2037
|
+
}, Dr = class extends Error {
|
|
2038
|
+
migrationId;
|
|
2039
|
+
dialect;
|
|
2040
|
+
_tag = "TransactionBrokenByBodyError";
|
|
2041
|
+
constructor(e, t) {
|
|
2042
|
+
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";
|
|
2043
|
+
}
|
|
2044
|
+
}, Or = class extends Error {
|
|
2045
|
+
table;
|
|
2046
|
+
report;
|
|
2047
|
+
_tag = "RewriteUnstableError";
|
|
2048
|
+
constructor(e, t) {
|
|
2049
|
+
super(`rewrite of ${e} did not stabilise after ${t.passes} pass(es): ${t.rewritten} rewritten, ${t.contended} contended on the last pass. Check for concurrent writes and guard values that cannot round-trip exactly before raising maxPasses.`), this.table = e, this.report = t, this.name = "RewriteUnstableError";
|
|
2050
|
+
}
|
|
2051
|
+
}, kr = /^\d{8}_\d{6}_[a-z0-9_]+\.ts$/, Ar = (e) => typeof e == "object" && !!e && "id" in e && "up" in e && "down" in e && typeof e.id == "string" && typeof e.up == "function" && typeof e.down == "function", jr = /* @__PURE__ */ new Set(["voltro_isr_cache"]), Mr = (e) => jr.has(e) || e.startsWith("_voltro_") || e.startsWith("_cloud_") || e.startsWith("cluster_") || e.startsWith("__turso_internal_"), Nr = "_voltro_staging_", Pr = (e) => e.startsWith(Nr), Fr = /__dropped_\d{14}$/, Ir = (e) => Fr.test(e), Lr = 7, Rr = (e) => {
|
|
2052
|
+
let t = /__dropped_(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/.exec(e);
|
|
2053
|
+
if (t === null) return;
|
|
2054
|
+
let [, n, r, i, a, o, s] = t;
|
|
2055
|
+
return new Date(Date.UTC(Number(n), Number(r) - 1, Number(i), Number(a), Number(o), Number(s)));
|
|
2056
|
+
}, zr = (e, t = {}) => {
|
|
2057
|
+
let n = t.now ?? /* @__PURE__ */ new Date(), r = t.retentionDays ?? 7, i = [], a = (e, t) => {
|
|
2058
|
+
let a = Rr(e);
|
|
2059
|
+
if (a === void 0) return;
|
|
2060
|
+
let o = Math.floor((n.getTime() - a.getTime()) / 864e5);
|
|
2061
|
+
o >= r && i.push({
|
|
2062
|
+
name: t,
|
|
2063
|
+
droppedAt: a,
|
|
2064
|
+
ageDays: o
|
|
2065
|
+
});
|
|
2066
|
+
};
|
|
2067
|
+
for (let t of e.tables) if (a(t.name, t.name), !Ir(t.name)) for (let e of t.columns ?? []) a(e.name, `${t.name}.${e.name}`);
|
|
2068
|
+
return i;
|
|
2069
|
+
}, Br = (e, t) => {
|
|
2070
|
+
let n = e.reduce((e, t) => e.ageDays >= t.ageDays ? e : t), r = (/* @__PURE__ */ new Date(Date.now() - t * 864e5)).toISOString().slice(0, 10);
|
|
2071
|
+
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.`;
|
|
2072
|
+
}, Vr = (e, t) => e.filter((e) => !Mr(e.name) || t.has(e.name)), Hr = I("_voltro_migrations", {
|
|
2073
|
+
id: f({ prefix: "mig" }),
|
|
2074
|
+
name: p(),
|
|
2075
|
+
hash: p(),
|
|
2076
|
+
status: p(),
|
|
2077
|
+
appliedAt: _().nullable(),
|
|
2078
|
+
durationMs: m().nullable(),
|
|
2079
|
+
errorMessage: p().nullable(),
|
|
2080
|
+
errorStack: p().nullable(),
|
|
2081
|
+
workflowRunId: p().nullable(),
|
|
2082
|
+
createdAt: _().default("now"),
|
|
2083
|
+
updatedAt: _().default("now").onUpdate("now")
|
|
2084
|
+
}).index(["status"]), Ur = I("_voltro_seeds", {
|
|
2085
|
+
id: f({ prefix: "seed" }),
|
|
2086
|
+
name: p(),
|
|
2087
|
+
lifecycle: p(),
|
|
2088
|
+
fingerprint: p(),
|
|
2089
|
+
cronSchedule: p().nullable(),
|
|
2090
|
+
watchedTables: v().nullable(),
|
|
2091
|
+
nextRunAt: _().nullable(),
|
|
2092
|
+
lastRunStatus: p().nullable(),
|
|
2093
|
+
lastRunAt: _().nullable(),
|
|
2094
|
+
lastRunDurationMs: m().nullable(),
|
|
2095
|
+
lastRunRowsTouched: m().nullable(),
|
|
2096
|
+
lastError: p().nullable(),
|
|
2097
|
+
workflowRunId: p().nullable(),
|
|
2098
|
+
createdAt: _().default("now"),
|
|
2099
|
+
updatedAt: _().default("now").onUpdate("now")
|
|
2100
|
+
}).index(["lifecycle"]).index(["nextRunAt"]), Wr = I("_voltro_migration_plans", {
|
|
2101
|
+
id: f({ prefix: "plan" }),
|
|
2102
|
+
fingerprint: p(),
|
|
2103
|
+
liveFingerprint: p().nullable(),
|
|
2104
|
+
operations: v(),
|
|
2105
|
+
rollbackPlan: v().nullable(),
|
|
2106
|
+
appliedBy: p(),
|
|
2107
|
+
environment: p(),
|
|
2108
|
+
source: p(),
|
|
2109
|
+
onlineStrategy: p().nullable(),
|
|
2110
|
+
durationMs: m(),
|
|
2111
|
+
notes: p().nullable(),
|
|
2112
|
+
squashedAt: _().nullable(),
|
|
2113
|
+
appliedAt: _().default("now"),
|
|
2114
|
+
createdAt: _().default("now"),
|
|
2115
|
+
updatedAt: _().default("now").onUpdate("now")
|
|
2116
|
+
}).index(["fingerprint"]).index(["environment"]), Gr = I("_voltro_idempotency", {
|
|
2117
|
+
id: f({ prefix: "idem" }),
|
|
2118
|
+
scope: p(),
|
|
2119
|
+
key: p(),
|
|
2120
|
+
status: p(),
|
|
2121
|
+
response: v().nullable(),
|
|
2122
|
+
createdAt: _().default("now")
|
|
2123
|
+
}).unique(["scope", "key"]).index(["createdAt"]), Kr = I("_voltro_devices", {
|
|
2124
|
+
id: f({ prefix: "device" }),
|
|
2125
|
+
tenantId: p(),
|
|
2126
|
+
name: p(),
|
|
2127
|
+
scopes: v().nullable(),
|
|
2128
|
+
pairingHash: p().maxLength(64).nullable(),
|
|
2129
|
+
pairingExpiresAt: _().nullable(),
|
|
2130
|
+
accessHash: p().maxLength(64).nullable(),
|
|
2131
|
+
accessExpiresAt: _().nullable(),
|
|
2132
|
+
refreshHash: p().maxLength(64).nullable(),
|
|
2133
|
+
refreshExpiresAt: _().nullable(),
|
|
2134
|
+
previousRefreshHash: p().maxLength(64).nullable(),
|
|
2135
|
+
generation: m().default(0),
|
|
2136
|
+
pairedAt: _().nullable(),
|
|
2137
|
+
lastSeenAt: _().nullable(),
|
|
2138
|
+
revokedAt: _().nullable(),
|
|
2139
|
+
revokedReason: p().nullable(),
|
|
2140
|
+
createdBy: p().nullable(),
|
|
2141
|
+
metadata: v().nullable(),
|
|
2142
|
+
createdAt: _()
|
|
2143
|
+
}).index(["tenantId"]).index(["pairingHash"]).index(["accessHash"]).index(["refreshHash"]).index(["previousRefreshHash"]), qr = I("_voltro_tenant_selections", {
|
|
2144
|
+
id: f({ prefix: "tsel" }),
|
|
2145
|
+
subjectType: p().maxLength(32),
|
|
2146
|
+
subjectId: p(),
|
|
2147
|
+
tenantId: p(),
|
|
2148
|
+
selectedAt: _()
|
|
2149
|
+
}).primaryKey(["id"]).nonReactive(), Jr = I("_voltro_kv", {
|
|
2150
|
+
id: f({ prefix: "kv" }),
|
|
2151
|
+
key: p().unique(),
|
|
2152
|
+
value: p().nullable(),
|
|
2153
|
+
expiresAt: _().nullable(),
|
|
2154
|
+
createdAt: _().default("now"),
|
|
2155
|
+
updatedAt: _().default("now").onUpdate("now")
|
|
2156
|
+
}).index(["expiresAt"]), Yr = I("_voltro_api_keys", {
|
|
2157
|
+
id: f({ prefix: "apikey" }),
|
|
2158
|
+
tenantId: p().nullable(),
|
|
2159
|
+
name: p(),
|
|
2160
|
+
hashedKey: p().maxLength(64).unique(),
|
|
2161
|
+
keyPrefix: p(),
|
|
2162
|
+
scopes: v().nullable(),
|
|
2163
|
+
lastUsedAt: _().nullable(),
|
|
2164
|
+
requestCount: m().default(0),
|
|
2165
|
+
expiresAt: _().nullable(),
|
|
2166
|
+
revokedAt: _().nullable(),
|
|
2167
|
+
createdBy: p().nullable(),
|
|
2168
|
+
onBehalfOf: p().nullable(),
|
|
2169
|
+
metadata: v().nullable(),
|
|
2170
|
+
createdAt: _().default("now")
|
|
2171
|
+
}).index("byApiKeyTenant", ["tenantId"]), Xr = I("_voltro_replica_observations", {
|
|
2172
|
+
id: f({ prefix: "robs" }),
|
|
2173
|
+
replicaId: p().maxLength(191),
|
|
2174
|
+
startedAt: _(),
|
|
2175
|
+
version: p().maxLength(64).nullable(),
|
|
2176
|
+
kind: p().maxLength(64),
|
|
2177
|
+
payload: p().nullable(),
|
|
2178
|
+
reachableAt: p().maxLength(255).nullable(),
|
|
2179
|
+
writtenAt: _().default("now").onUpdate("now")
|
|
2180
|
+
}).unique(["replicaId", "kind"]).index(["kind"]), Zr = [
|
|
2181
|
+
Hr,
|
|
2182
|
+
Ur,
|
|
2183
|
+
Wr
|
|
2184
|
+
];
|
|
2185
|
+
//#endregion
|
|
2186
|
+
export { tr as $, ae as $n, Wt as $t, br as A, M as An, Qt as At, qn as B, Te as Bn, Lt as Bt, Er as C, rt as Cn, se as Cr, W as Ct, Cr as D, Re as Dn, un as Dt, Dr as E, Le as En, sn as Et, _r as F, Pe as Fn, Ot as Ft, Z as G, he as Gn, B as Gt, Q as H, ye as Hn, Ut as Ht, gr as I, Fe as In, kt as It, Rn as J, x as Jn, qt as Jt, ir as K, me as Kn, Yt as Kt, Jn as L, we as Ln, Xt as Lt, yr as M, N as Mn, jt as Mt, vr as N, xe as Nn, Gt as Nt, wr as O, ze as On, Zt as Ot, pr as P, je as Pn, Pt, Yn as Q, y as Qn, At as Qt, Qn as R, Me as Rn, Vt as Rt, Sr as S, it as Sn, _ as Sr, vn as St, Or as T, Qe as Tn, cn as Tt, Un as U, ge as Un, Nt as Ut, Kn as V, ve as Vn, Ht as Vt, Fn as W, _e as Wn, Mt as Wt, nr as X, te as Xn, Kt as Xt, Vn as Y, ce as Yn, Bt as Yt, Xn as Z, re as Zn, zt as Zt, Ir as _, lt as _n, h as _r, Cn as _t, Wr as a, z as an, g as ar, Hn as at, Rr as b, st as bn, o as br, G as bt, Ur as c, Ct as cn, de as cr, Zn as ct, Lr as d, _t as dn, le as dr, Y as dt, Ft as en, l as er, zn as et, jr as f, gt as fn, v as fr, q as ft, Mr as g, I as gn, c as gr, Sn as gt, Br as h, ct as hn, fe as hr, K as ht, Jr as i, St as in, ne as ir, ar as it, fr as j, A as jn, en as jt, Ar as k, j as kn, $t as kt, qr as l, Tt as ln, f as lr, Wn as lt, zr as m, ut as mn, ee as mr, J as mt, Kr as n, wt as nn, b as nr, In as nt, Hr as o, Dt as on, oe as or, rr as ot, Nr as p, L as pn, w as pr, wn as pt, Ln as q, u as qn, Jt as qt, Gr as r, Et as rn, ie as rr, er as rt, Xr as s, xt as sn, ue as sr, $n as st, Yr as t, It as tn, s as tr, Bn as tt, Zr as u, vt as un, m as ur, $ as ut, Pr as v, ot as vn, C as vr, hn as vt, Tr as w, tt as wn, on as wt, kr as x, nt as xn, p as xr, yn as xt, Vr as y, at as yn, S as yr, mn as yt, Gn as z, Ne as zn, Rt as zt };
|