@voltro/database 0.85.0 → 0.87.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 +5987 -0
- package/THIRD-PARTY-NOTICES.md +5 -257
- package/dist/actorSnapshot.js +24 -0
- package/dist/arrayCodec.js +32 -0
- package/dist/branchExecute.js +92 -0
- package/dist/branching.js +106 -0
- package/dist/bulkInsertLimits.js +25 -0
- package/dist/cdcOffsetsTables.js +19 -0
- package/dist/changeEvent.js +41 -0
- package/dist/changeIdentity.js +65 -0
- package/dist/changeListenerCeiling.js +6 -0
- package/dist/columnReference.js +17 -0
- package/dist/columns.js +326 -0
- package/dist/committedChanges.js +12 -0
- package/dist/connectionIdentity.js +36 -0
- package/dist/coreTables.js +16 -0
- package/dist/coreTablesRegistry.js +10 -0
- package/dist/dataTransfers.js +23 -0
- package/dist/dbCause.js +222 -0
- package/dist/dbMetrics.js +65 -0
- package/dist/decimalComparison.js +27 -0
- package/dist/derivedRowId.js +5 -0
- package/dist/dialect.js +13 -0
- package/dist/enumRenames.js +14 -0
- package/dist/expiresMixin.js +10 -0
- package/dist/fieldEncryption.js +121 -0
- package/dist/frameworkTables.js +143 -0
- package/dist/ginIndex.js +10 -0
- package/dist/hybridSearch.js +32 -0
- package/dist/idGenerator.js +57 -0
- package/dist/identifierLimits.js +32 -0
- package/dist/index.d.ts +166 -22
- package/dist/index.js +82 -2183
- package/dist/indexAudit.js +61 -0
- package/dist/indexStorage.js +58 -0
- package/dist/joinCompiler.js +160 -0
- package/dist/jsonEagerCompiler.js +436 -0
- package/dist/jsonPatch.js +78 -0
- package/dist/jsonPatchAssignments.js +13 -0
- package/dist/jsonPath.js +31 -0
- package/dist/localFirstMixin.js +12 -0
- package/dist/migrate.js +644 -0
- package/dist/migration.js +18 -0
- package/dist/migrations/appliedAtValue.js +8 -0
- package/dist/migrations/applier.js +1100 -0
- package/dist/migrations/boot.js +196 -0
- package/dist/migrations/branchRehearsal.js +122 -0
- package/dist/migrations/columnEquivalence.js +85 -0
- package/dist/migrations/ddlError.js +63 -0
- package/dist/migrations/ddlStatements.js +9 -0
- package/dist/migrations/declaredSchema.js +162 -0
- package/dist/migrations/deployLedger.js +19 -0
- package/dist/migrations/fileBased.js +57 -0
- package/dist/migrations/fileContext.js +482 -0
- package/dist/migrations/fileDiscovery.js +332 -0
- package/dist/migrations/fileSkipProbes.js +117 -0
- package/dist/migrations/fingerprint.js +46 -0
- package/dist/migrations/fkCycles.js +13 -0
- package/dist/migrations/frameworkLiveTables.js +25 -0
- package/dist/migrations/idempotentDdl.js +37 -0
- package/dist/migrations/indexPredicate.js +50 -0
- package/dist/migrations/introspect.js +801 -0
- package/dist/migrations/ledgerRows.js +4 -0
- package/dist/migrations/lock.js +91 -0
- package/dist/migrations/migrationTableExists.js +9 -0
- package/dist/migrations/mssqlColumnDependencies.js +76 -0
- package/dist/migrations/mysqlEngine.js +11 -0
- package/dist/migrations/namespaceCharset.js +51 -0
- package/dist/migrations/planner.js +785 -0
- package/dist/migrations/postgresEnumCheck.js +22 -0
- package/dist/migrations/reactiveTriggerDrift.js +58 -0
- package/dist/migrations/reactiveTriggerName.js +7 -0
- package/dist/migrations/renameMssqlCheck.js +21 -0
- package/dist/migrations/restoreSnapshots.js +206 -0
- package/dist/migrations/resumeLedger.js +86 -0
- package/dist/migrations/rollingDeploy.js +106 -0
- package/dist/migrations/schemaOwner.js +46 -0
- package/dist/migrations/schemaOwnerTable.js +4 -0
- package/dist/migrations/softDropSnapshot.js +20 -0
- package/dist/migrations/sqlLimit.js +8 -0
- package/dist/migrations/sqliteCatalogName.js +13 -0
- package/dist/migrations/sqliteConstraintIdentity.js +97 -0
- package/dist/migrations/sqliteDecimalBoot.js +22 -0
- package/dist/migrations/sqliteDecimalPublication.js +257 -0
- package/dist/migrations/sqliteDecimalReview.js +30 -0
- package/dist/migrations/sqliteDecimalReviewStore.js +188 -0
- package/dist/migrations/sqliteDecimalReviewWitness.js +38 -0
- package/dist/migrations/sqliteDecimalSource.js +69 -0
- package/dist/migrations/sqliteDecimalStage.js +135 -0
- package/dist/migrations/sqliteForeignKeys.js +38 -0
- package/dist/migrations/sqliteMigrationBatch.js +37 -0
- package/dist/migrations/sqliteRetainedSource.js +106 -0
- package/dist/migrations/sqliteRowIdentity.js +63 -0
- package/dist/migrations/sqliteSchemaEpoch.js +12 -0
- package/dist/migrations/sqliteSnapshotGuard.js +10 -0
- package/dist/migrations/sqliteTableContents.js +34 -0
- package/dist/migrations/sqliteTableCopy.js +25 -0
- package/dist/migrations/sqliteTableSchema.js +19 -0
- package/dist/migrations/sqliteWitnessProtection.js +8 -0
- package/dist/migrations/squash.js +81 -0
- package/dist/migrations/storeCharset.js +66 -0
- package/dist/migrations/transactionCause.js +10 -0
- package/dist/migrations/undeclaredCharset.js +40 -0
- package/dist/migrations/uniqueActiveLowering.js +39 -0
- package/dist/mixins.js +22 -0
- package/dist/mssqlDecimalDistinct.js +51 -0
- package/dist/mssqlJsonValueCheck.js +42 -0
- package/dist/mssqlTextStorage.js +9 -0
- package/dist/namespace.js +21 -0
- package/dist/{wire-CG2j7J3f.js → optimisticVersion.js} +2 -2
- package/dist/pendingAttribution.js +79 -0
- package/dist/pluginRef.js +17 -0
- package/dist/predicate.js +273 -0
- package/dist/predicateCoercion.js +13 -0
- package/dist/projectedColumn.js +37 -0
- package/dist/queryBuilder.js +388 -0
- package/dist/rawSql.js +8 -0
- package/dist/relations.js +69 -0
- package/dist/relationsRegistry.js +38 -0
- package/dist/replaceInProgress.js +53 -0
- package/dist/requiredColumns.js +26 -0
- package/dist/residency.js +52 -0
- package/dist/retention.js +62 -0
- package/dist/rowDecoder.js +173 -0
- package/dist/rowKey.js +8 -0
- package/dist/rowSchema.js +31 -0
- package/dist/scopeKey.js +8 -0
- package/dist/seed.js +33 -0
- package/dist/snowflake.js +26 -0
- package/dist/sql.d.ts +2792 -3773
- package/dist/sql.js +42 -6905
- package/dist/sqlCompiler.js +360 -0
- package/dist/sqlError.js +8 -0
- package/dist/sqlMutation.js +55 -0
- package/dist/sqlPoolCapacity.js +12 -0
- package/dist/sqliteDecimal.js +22 -0
- package/dist/sqliteDecimalAggregateSql.js +61 -0
- package/dist/sqliteDecimalColumnSql.js +108 -0
- package/dist/sqliteDecimalConversion.js +15 -0
- package/dist/sqliteDecimalCte.js +154 -0
- package/dist/sqliteDecimalEncodeSql.js +32 -0
- package/dist/sqliteDecimalOutputs.js +74 -0
- package/dist/sqliteDecimalPredicate.js +66 -0
- package/dist/sqliteDecimalQuery.js +183 -0
- package/dist/sqliteDecimalQueryPlan.js +37 -0
- package/dist/sqliteDecimalResultSql.js +44 -0
- package/dist/sqliteDecimalRowQuery.js +63 -0
- package/dist/sqliteDecimalSetQuery.js +50 -0
- package/dist/sqliteDecimalSource.js +63 -0
- package/dist/sqliteDecimalStorage.js +29 -0
- package/dist/sqliteDecimalSubquery.js +19 -0
- package/dist/sqliteDecimalWindowQuery.js +196 -0
- package/dist/sqliteValueCoercion.js +4 -0
- package/dist/stampId.js +21 -0
- package/dist/storeErrors.js +9 -0
- package/dist/storeRefusal.js +20 -0
- package/dist/stream.js +36 -0
- package/dist/subjectGraph.js +175 -0
- package/dist/table.js +394 -0
- package/dist/tableRegistry.js +16 -0
- package/dist/tenantSelection.js +27 -0
- package/dist/transactionOutcome.js +100 -0
- package/dist/transientContention.js +36 -0
- package/dist/typeId.js +51 -0
- package/dist/typedStore.js +16 -0
- package/dist/upsertUpdate.js +20 -0
- package/dist/vectorEmbedding.js +31 -0
- package/dist/view.js +39 -0
- package/dist/wire.js +6 -2
- package/dist/writeAttribution.js +16 -0
- package/dist/writeRecorder.js +38 -0
- package/package.json +3 -4
- package/dist/replaceInProgress-DC88Pdiy.js +0 -3735
package/dist/index.js
CHANGED
|
@@ -1,2184 +1,83 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
"url"
|
|
83
|
-
]), ti = (e, t, n, r) => {
|
|
84
|
-
let i = e.decrypt(t, r), a;
|
|
85
|
-
try {
|
|
86
|
-
a = JSON.parse(i);
|
|
87
|
-
} catch {
|
|
88
|
-
return i;
|
|
89
|
-
}
|
|
90
|
-
return typeof a == "string" ? a : n === void 0 || ei.has(n) ? i : a;
|
|
91
|
-
}, ni = (e, t, n, r) => {
|
|
92
|
-
let i = e.decrypt(t, r);
|
|
93
|
-
try {
|
|
94
|
-
return typeof JSON.parse(i) == "string" ? !1 : n === void 0 || ei.has(n) ? !0 : void 0;
|
|
95
|
-
} catch {
|
|
96
|
-
return !0;
|
|
97
|
-
}
|
|
98
|
-
}, ri = (e, t) => e.fields[t]?.type, ii = (e) => {
|
|
99
|
-
let t = [];
|
|
100
|
-
for (let [n, r] of Object.entries(e.fields)) r.encrypted === !0 && t.push(n);
|
|
101
|
-
return t;
|
|
102
|
-
}, ai = "id", oi = (e, t, n, r) => {
|
|
103
|
-
if (!t) return e;
|
|
104
|
-
let i = ii(t);
|
|
105
|
-
return i.length === 0 ? e : ci(e, i, t.tableName ?? "?", n, r);
|
|
106
|
-
}, si = (e, t, n) => {
|
|
107
|
-
if (t === void 0 || e.length === 0) return e;
|
|
108
|
-
let r = ii(t);
|
|
109
|
-
if (r.length === 0) return e;
|
|
110
|
-
let i = t.tableName ?? "?";
|
|
111
|
-
return e.map((e) => ci(e, r, i, n));
|
|
112
|
-
}, ci = (e, t, n, r, i) => {
|
|
113
|
-
let a = i ?? e[ai], o = { ...e };
|
|
114
|
-
for (let e of t) {
|
|
115
|
-
let t = o[e];
|
|
116
|
-
if (!(t == null || Qr(t))) {
|
|
117
|
-
if (!r) throw Error(`column "${n}.${e}" is .encrypted() but no field cipher is registered — set VOLTRO_FIELD_ENCRYPTION_KEY (\`voltro dev\` mints one; \`voltro serve\` refuses to boot without it); in a test, pass \`fieldEncryptionKey\` to makeTestContext`);
|
|
118
|
-
o[e] = $r(r, t, Jr(n, e, a));
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return o;
|
|
122
|
-
}, li = (e, t, n, r) => {
|
|
123
|
-
if (!t) return e;
|
|
124
|
-
let i = ii(t);
|
|
125
|
-
if (i.length === 0 || !n) return e;
|
|
126
|
-
let a = r?.onError ?? "throw", o = t.tableName ?? "?";
|
|
127
|
-
return e.map((e) => {
|
|
128
|
-
let s;
|
|
129
|
-
for (let c of i) {
|
|
130
|
-
let i = e[c];
|
|
131
|
-
if (Qr(i)) {
|
|
132
|
-
s ??= { ...e };
|
|
133
|
-
try {
|
|
134
|
-
s[c] = ti(n, i, ri(t, c), Jr(o, c, r?.rowId ?? e[ai]));
|
|
135
|
-
} catch (e) {
|
|
136
|
-
let t = String(e?.message ?? e);
|
|
137
|
-
if (a === "null") {
|
|
138
|
-
s[c] = null, r?.warn?.({
|
|
139
|
-
table: o,
|
|
140
|
-
column: c,
|
|
141
|
-
reason: t
|
|
142
|
-
});
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
145
|
-
throw new Xr({
|
|
146
|
-
table: o,
|
|
147
|
-
column: c,
|
|
148
|
-
reason: t
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
return s ?? e;
|
|
154
|
-
});
|
|
155
|
-
}, ui = Symbol.for("@voltro/database/storeRefusal"), di = (e) => {
|
|
156
|
-
let t = S(e.detail);
|
|
157
|
-
return Object.defineProperty(t, ui, {
|
|
158
|
-
value: e,
|
|
159
|
-
enumerable: !1
|
|
160
|
-
}), t;
|
|
161
|
-
}, fi = (e) => {
|
|
162
|
-
for (let t of Bt(e)) {
|
|
163
|
-
let e = t;
|
|
164
|
-
for (let t = 0; e != null && t < 8; t += 1) {
|
|
165
|
-
let t = e[ui];
|
|
166
|
-
if (t !== void 0) return t;
|
|
167
|
-
e = e.cause;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}, pi = (e) => {
|
|
171
|
-
let t = (() => {
|
|
172
|
-
switch (e.type) {
|
|
173
|
-
case "id": return e.idScheme?.kind === "numeric" ? k.Number : k.String;
|
|
174
|
-
case "text":
|
|
175
|
-
case "enum": return k.String;
|
|
176
|
-
case "reference": return e.referenceStorage === "numeric" ? k.Number : k.String;
|
|
177
|
-
case "integer":
|
|
178
|
-
case "real":
|
|
179
|
-
case "decimal": return k.Number;
|
|
180
|
-
case "boolean": return k.Boolean;
|
|
181
|
-
case "timestamp":
|
|
182
|
-
case "date": return Or;
|
|
183
|
-
case "bigint": return k.BigIntFromString;
|
|
184
|
-
case "bytes": return k.Uint8ArrayFromBase64;
|
|
185
|
-
case "array": return k.Array(k.Unknown);
|
|
186
|
-
case "interval": return k.String;
|
|
187
|
-
default: return k.Unknown;
|
|
188
|
-
}
|
|
189
|
-
})();
|
|
190
|
-
return e.nullable === !0 ? k.NullOr(t) : t;
|
|
191
|
-
}, mi = (e, t) => {
|
|
192
|
-
let n = new Set(t?.omit ?? []), r = {};
|
|
193
|
-
for (let [t, i] of Object.entries(e.fields)) n.has(t) || (r[t] = pi(i));
|
|
194
|
-
return k.Struct(r);
|
|
195
|
-
}, hi = (e) => typeof e == "function" ? e : () => e, gi = (e, t) => ({
|
|
196
|
-
kind: "one",
|
|
197
|
-
target: hi(e),
|
|
198
|
-
...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
|
|
199
|
-
...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
|
|
200
|
-
}), _i = (e, t) => ({
|
|
201
|
-
kind: "many",
|
|
202
|
-
target: hi(e),
|
|
203
|
-
...t?.foreignKey === void 0 ? {} : { foreignKey: t.foreignKey },
|
|
204
|
-
...t?.sourceKey === void 0 ? {} : { sourceKey: t.sourceKey }
|
|
205
|
-
}), vi = (e, t) => ({
|
|
206
|
-
kind: "manyToMany",
|
|
207
|
-
target: hi(e),
|
|
208
|
-
through: hi(t.through),
|
|
209
|
-
sourceKey: t.sourceKey,
|
|
210
|
-
targetKey: t.targetKey
|
|
211
|
-
}), yi = {
|
|
212
|
-
one: gi,
|
|
213
|
-
many: _i,
|
|
214
|
-
manyToMany: vi
|
|
215
|
-
}, bi = (e, t) => {
|
|
216
|
-
let n = typeof e == "function" ? e : () => e;
|
|
217
|
-
return {
|
|
218
|
-
source: n,
|
|
219
|
-
relations: t(yi, n())
|
|
220
|
-
};
|
|
221
|
-
}, xi = (e) => {
|
|
222
|
-
if (typeof e != "object" || !e) return !1;
|
|
223
|
-
let t = e;
|
|
224
|
-
return typeof t.source != "function" || typeof t.relations != "object" || t.relations === null ? !1 : Object.keys(t.relations).length === 0;
|
|
225
|
-
}, Si = (e) => {
|
|
226
|
-
if (typeof e != "object" || !e) return !1;
|
|
227
|
-
let t = e;
|
|
228
|
-
if (typeof t.source != "function" || typeof t.relations != "object" || t.relations === null) return !1;
|
|
229
|
-
let n = Object.values(t.relations);
|
|
230
|
-
return n.length !== 0 && n.every((e) => {
|
|
231
|
-
let t = e?.kind;
|
|
232
|
-
return t === "one" || t === "many" || t === "manyToMany";
|
|
233
|
-
});
|
|
234
|
-
}, Ci = gi, wi = _i, Ti = vi, Ei = (e, t, n) => {
|
|
235
|
-
let r = [];
|
|
236
|
-
for (let [n, i] of Object.entries(e.fields)) i.type === "reference" && i.references?.()?.tableName === t && r.push(n);
|
|
237
|
-
if (r.length === 0) throw S(`relation '${n}': no reference() column on '${e.tableName}' points at '${t}'. Either add one or pass an explicit { foreignKey: '<column>' }.`);
|
|
238
|
-
if (r.length > 1) throw S(`relation '${n}': multiple reference() columns on '${e.tableName}' point at '${t}' (${r.join(", ")}). Pass an explicit { foreignKey: '<column>' } to disambiguate.`);
|
|
239
|
-
return r[0];
|
|
240
|
-
}, Di = (e) => Object.keys(e.fields), Oi = (e, t) => Object.prototype.hasOwnProperty.call(e.fields, t), ki = (e) => {
|
|
241
|
-
let t = Di(e);
|
|
242
|
-
return t.length === 0 ? "<none>" : t.join(", ");
|
|
243
|
-
}, Ai = (e, t, n) => {
|
|
244
|
-
let r = `relation '${t}' on '${e.tableName}'`, i = n.target();
|
|
245
|
-
if (n.kind === "manyToMany") {
|
|
246
|
-
let t = n.through();
|
|
247
|
-
for (let [a, o] of [["sourceKey", n.sourceKey], ["targetKey", n.targetKey]]) if (!Oi(t, o)) throw S(`${r}: manyToMany ${a} '${o}' is not a column on the junction table '${t.tableName}'. Both keys name columns on the JUNCTION — ${a === "sourceKey" ? `sourceKey points at '${e.tableName}'` : `targetKey points at '${i.tableName}'`}. Columns on '${t.tableName}': ${ki(t)}.`);
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
if (n.sourceKey !== void 0 && n.foreignKey !== void 0) throw S(`${r}: pass EITHER sourceKey OR foreignKey, not both. sourceKey '${n.sourceKey}' names a column on the source ('${e.tableName}') holding the target's id; foreignKey '${n.foreignKey}' names a column on the target ('${i.tableName}') holding the source's id. With both, foreignKey is ignored.`);
|
|
251
|
-
if (n.sourceKey !== void 0 && !Oi(e, n.sourceKey)) {
|
|
252
|
-
let t = Oi(i, n.sourceKey);
|
|
253
|
-
throw S(`${r}: sourceKey '${n.sourceKey}' is not a column on the source table '${e.tableName}'.` + (t ? ` It IS a column on the target '${i.tableName}' — you probably want { foreignKey: '${n.sourceKey}' }, which names the column on the TARGET that holds this table's id.` : ` Columns on '${e.tableName}': ${ki(e)}.`));
|
|
254
|
-
}
|
|
255
|
-
if (n.foreignKey !== void 0 && !Oi(i, n.foreignKey)) {
|
|
256
|
-
let t = Oi(e, n.foreignKey);
|
|
257
|
-
throw S(`${r}: foreignKey '${n.foreignKey}' is not a column on the target table '${i.tableName}'.` + (t ? ` It IS a column on the source '${e.tableName}' — you want { sourceKey: '${n.foreignKey}' }. foreignKey names the column on the TARGET that points back at this table; sourceKey names the column on THIS table that holds the target's id.` : ` Columns on '${i.tableName}': ${ki(i)}.`));
|
|
258
|
-
}
|
|
259
|
-
}, ji = Symbol.for("@voltro/database/relationsRegistry"), Mi = globalThis, j = Mi[ji] ?? (Mi[ji] = /* @__PURE__ */ new Map()), Ni = (e) => {
|
|
260
|
-
let t = e.source(), n = j.get(t.tableName);
|
|
261
|
-
if (n === void 0) {
|
|
262
|
-
j.set(t.tableName, new Map(Object.entries(e.relations)));
|
|
263
|
-
return;
|
|
264
|
-
}
|
|
265
|
-
for (let [r, i] of Object.entries(e.relations)) {
|
|
266
|
-
let e = n.get(r);
|
|
267
|
-
if (e !== i) {
|
|
268
|
-
if (e !== void 0) throw Error(`duplicate relation '${r}' on '${t.tableName}': two relations() blocks both declare it. Pick distinct names or merge them into one block.`);
|
|
269
|
-
n.set(r, i);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}, Pi = (e) => {
|
|
273
|
-
let t = 0;
|
|
274
|
-
for (let n of Object.values(e)) Si(n) && (Ni(n), t += 1);
|
|
275
|
-
return t;
|
|
276
|
-
}, Fi = (e) => {
|
|
277
|
-
let t = j.get(e);
|
|
278
|
-
if (t !== void 0) return Object.fromEntries(t);
|
|
279
|
-
}, Ii = (e, t) => j.get(e)?.get(t), Li = () => {
|
|
280
|
-
let e = [];
|
|
281
|
-
for (let [t, n] of j) for (let [r, i] of n) e.push({
|
|
282
|
-
source: t,
|
|
283
|
-
name: r,
|
|
284
|
-
relation: i
|
|
285
|
-
});
|
|
286
|
-
return e;
|
|
287
|
-
}, Ri = () => {
|
|
288
|
-
for (let [e, t] of j) {
|
|
289
|
-
let n = je(e);
|
|
290
|
-
if (n !== void 0) for (let [e, r] of t) Ai(n, e, r);
|
|
291
|
-
}
|
|
292
|
-
}, zi = () => {
|
|
293
|
-
j.clear();
|
|
294
|
-
}, Bi = 4, Vi = (e) => Object.keys(e.fields), Hi = (e, t) => Object.prototype.hasOwnProperty.call(e.fields, t), Ui = (e, t) => {
|
|
295
|
-
let n = [];
|
|
296
|
-
for (let [r, i] of Object.entries(e.fields)) i.type === "reference" && i.references?.()?.tableName === t && n.push(r);
|
|
297
|
-
return n;
|
|
298
|
-
}, Wi = (e, t) => {
|
|
299
|
-
let n = [];
|
|
300
|
-
for (let r of t) {
|
|
301
|
-
if (r.source !== e) continue;
|
|
302
|
-
let t = r.relation, i;
|
|
303
|
-
try {
|
|
304
|
-
i = t.target();
|
|
305
|
-
} catch {
|
|
306
|
-
continue;
|
|
307
|
-
}
|
|
308
|
-
if (t.kind === "manyToMany") {
|
|
309
|
-
let e;
|
|
310
|
-
try {
|
|
311
|
-
e = t.through();
|
|
312
|
-
} catch {
|
|
313
|
-
continue;
|
|
314
|
-
}
|
|
315
|
-
if (!Hi(e, t.sourceKey)) continue;
|
|
316
|
-
n.push({
|
|
317
|
-
table: e.tableName,
|
|
318
|
-
foreignKey: t.sourceKey,
|
|
319
|
-
parentKey: "id"
|
|
320
|
-
});
|
|
321
|
-
continue;
|
|
322
|
-
}
|
|
323
|
-
if (t.sourceKey !== void 0) continue;
|
|
324
|
-
let a = Ui(i, e), o = t.foreignKey ?? (a.length === 1 ? a[0] : void 0);
|
|
325
|
-
if (o === void 0 || !Hi(i, o)) continue;
|
|
326
|
-
let s = i.fields[o];
|
|
327
|
-
n.push({
|
|
328
|
-
table: i.tableName,
|
|
329
|
-
foreignKey: o,
|
|
330
|
-
parentKey: s?.referenceColumn ?? "id"
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
return n;
|
|
334
|
-
}, Gi = (e, t) => {
|
|
335
|
-
let n = [];
|
|
336
|
-
for (let r of t) if (r.tableName !== e) for (let t of Ui(r, e)) {
|
|
337
|
-
let e = r.fields[t];
|
|
338
|
-
n.push({
|
|
339
|
-
table: r.tableName,
|
|
340
|
-
foreignKey: t,
|
|
341
|
-
parentKey: e?.referenceColumn ?? "id"
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
return n;
|
|
345
|
-
}, Ki = (e) => {
|
|
346
|
-
if (Fr.isProxy(e)) return !1;
|
|
347
|
-
let t = Object.getPrototypeOf(e);
|
|
348
|
-
return (t === Object.prototype || t === null) && Reflect.ownKeys(e).every((t) => "value" in Object.getOwnPropertyDescriptor(e, t));
|
|
349
|
-
}, qi = (e) => !Fr.isProxy(e) && Object.getPrototypeOf(e) === Array.prototype && Reflect.ownKeys(e).every((t) => typeof t == "string" && (t === "length" || /^(0|[1-9][0-9]*)$/.test(t)) && "value" in Object.getOwnPropertyDescriptor(e, t)), Ji = (e) => {
|
|
350
|
-
if (e.length < 32 || !qi(e) || !e.every((e) => Ki(e) && Ki(e.fields) && Object.values(e.fields).every(Ki))) return (t) => Gi(t, e);
|
|
351
|
-
let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
|
|
352
|
-
e.forEach((e, t) => {
|
|
353
|
-
n.has(e) || n.set(e, t);
|
|
354
|
-
});
|
|
355
|
-
let r, i = !1, a = (e) => {
|
|
356
|
-
for (let r of e) {
|
|
357
|
-
let e = n.get(r);
|
|
358
|
-
for (let [n, i] of Object.entries(r.fields)) {
|
|
359
|
-
if (i.type !== "reference") continue;
|
|
360
|
-
let a = i.references?.()?.tableName;
|
|
361
|
-
if (a === void 0) continue;
|
|
362
|
-
let o = {
|
|
363
|
-
order: e,
|
|
364
|
-
hop: {
|
|
365
|
-
table: r.tableName,
|
|
366
|
-
foreignKey: n,
|
|
367
|
-
parentKey: i.referenceColumn ?? "id"
|
|
368
|
-
}
|
|
369
|
-
}, s = t.get(a);
|
|
370
|
-
s ? s.push(o) : t.set(a, [o]);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
};
|
|
374
|
-
return (n) => {
|
|
375
|
-
if (!i) r = e.filter((e) => e.tableName === n), a(e.filter((e) => e.tableName !== n)), i = !0;
|
|
376
|
-
else if (r?.some((e) => e.tableName !== n)) {
|
|
377
|
-
a(r), r = void 0;
|
|
378
|
-
for (let e of t.values()) e.sort((e, t) => e.order - t.order);
|
|
379
|
-
}
|
|
380
|
-
return (t.get(n) ?? []).filter((e) => e.hop.table !== n).map((e) => e.hop);
|
|
381
|
-
};
|
|
382
|
-
}, Yi = (e) => {
|
|
383
|
-
if (e.length < 32 || !qi(e) || !e.every(Ki)) return (t) => Wi(t, e);
|
|
384
|
-
let t = /* @__PURE__ */ new Map();
|
|
385
|
-
for (let n of e) {
|
|
386
|
-
let e = t.get(n.source);
|
|
387
|
-
e ? e.push(n) : t.set(n.source, [n]);
|
|
388
|
-
}
|
|
389
|
-
return (e) => Wi(e, t.get(e) ?? []);
|
|
390
|
-
}, Xi = (e) => `${e.table}\u0000${e.hops.map((e) => `${e.table}.${e.foreignKey}<-${e.parentKey}`).join("|")}`, Zi = (e) => {
|
|
391
|
-
let t = e.tables ?? gn(), n = e.relations ?? Li(), r = e.maxDepth ?? 4, i = new Set(e.exclude ?? []), a = new Map(t.map((e) => [e.tableName, e])), o = [];
|
|
392
|
-
if (!a.has(e.subjectTable)) return {
|
|
393
|
-
subjectTable: e.subjectTable,
|
|
394
|
-
paths: [],
|
|
395
|
-
limitations: [{
|
|
396
|
-
kind: "unreachable",
|
|
397
|
-
table: e.subjectTable,
|
|
398
|
-
detail: `the subject table '${e.subjectTable}' is not registered — no schema was loaded, or the name is wrong. Registered: ${t.length === 0 ? "<none>" : t.map((e) => e.tableName).join(", ")}`
|
|
399
|
-
}]
|
|
400
|
-
};
|
|
401
|
-
let s = {
|
|
402
|
-
table: e.subjectTable,
|
|
403
|
-
hops: [],
|
|
404
|
-
depth: 0,
|
|
405
|
-
via: "relation"
|
|
406
|
-
}, c = Ji(t), l = Yi(n), u = [s], d = /* @__PURE__ */ new Set([Xi(s)]), f = /* @__PURE__ */ new Set(), p = [s];
|
|
407
|
-
for (let e = 1; e <= r; e++) {
|
|
408
|
-
let t = [];
|
|
409
|
-
for (let n of p) {
|
|
410
|
-
let r = l(n.table), a = c(n.table), s = [...r.map((e) => [e, "relation"]), ...a.map((e) => [e, "reference"])];
|
|
411
|
-
for (let [r, a] of s) {
|
|
412
|
-
if (i.has(r.table)) {
|
|
413
|
-
o.push({
|
|
414
|
-
kind: "excluded",
|
|
415
|
-
table: r.table,
|
|
416
|
-
detail: `excluded by configuration (reached from '${n.table}')`
|
|
417
|
-
});
|
|
418
|
-
continue;
|
|
419
|
-
}
|
|
420
|
-
let s = `${r.table}\u0000${r.foreignKey}`;
|
|
421
|
-
if (f.has(s)) continue;
|
|
422
|
-
f.add(s);
|
|
423
|
-
let c = {
|
|
424
|
-
table: r.table,
|
|
425
|
-
hops: [...n.hops, r],
|
|
426
|
-
depth: e,
|
|
427
|
-
via: a
|
|
428
|
-
}, l = Xi(c);
|
|
429
|
-
d.has(l) || (d.add(l), u.push(c), t.push(c));
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
if (t.length === 0) {
|
|
433
|
-
p = [];
|
|
434
|
-
break;
|
|
435
|
-
}
|
|
436
|
-
p = t;
|
|
437
|
-
}
|
|
438
|
-
for (let e of p) (l(e.table).length > 0 || c(e.table).length > 0) && o.push({
|
|
439
|
-
kind: "depth-truncated",
|
|
440
|
-
table: e.table,
|
|
441
|
-
detail: `stopped at maxDepth ${r}; tables linked FROM '${e.table}' were not explored`
|
|
442
|
-
});
|
|
443
|
-
let m = new Set(u.map((e) => e.table));
|
|
444
|
-
for (let n of t) m.has(n.tableName) || i.has(n.tableName) || o.push({
|
|
445
|
-
kind: "unreachable",
|
|
446
|
-
table: n.tableName,
|
|
447
|
-
detail: `no relation() and no reference() column links '${n.tableName}' to '${e.subjectTable}'. If it holds subject data through a plain column, a polymorphic (type,id) pair, JSON or free text, add an explicit subjectScopes entry — this derivation cannot see it. Columns: ${Vi(n).join(", ")}`
|
|
448
|
-
});
|
|
449
|
-
return {
|
|
450
|
-
subjectTable: e.subjectTable,
|
|
451
|
-
paths: u,
|
|
452
|
-
limitations: o
|
|
453
|
-
};
|
|
454
|
-
}, Qi = (e) => {
|
|
455
|
-
let t = [`subject graph · ${e.subjectTable} · ${e.paths.length} table(s) reachable`];
|
|
456
|
-
for (let n of e.paths) {
|
|
457
|
-
let r = n.hops.length === 0 ? `${e.subjectTable} (the subject row itself)` : [e.subjectTable, ...n.hops.map((e) => `${e.table}.${e.foreignKey}`)].join(" → ");
|
|
458
|
-
t.push(` • ${n.table} [depth ${n.depth}, via ${n.via}]`), t.push(` ${r}`);
|
|
459
|
-
}
|
|
460
|
-
let n = e.limitations.filter((e) => e.kind === "depth-truncated"), r = e.limitations.filter((e) => e.kind === "unreachable"), i = e.limitations.filter((e) => e.kind === "excluded");
|
|
461
|
-
return t.push(""), t.push(" WHAT THIS CANNOT SEE — a DSAR is only as complete as this list is short:"), n.length > 0 && t.push(` depth-truncated (${n.length}): ${n.map((e) => e.table).join(", ")}`), i.length > 0 && t.push(` excluded (${i.length}): ${[...new Set(i.map((e) => e.table))].join(", ")}`), t.push(r.length === 0 ? " unreachable: none — every registered table is linked to the subject." : ` unreachable (${r.length}): ${r.map((e) => e.table).join(", ")}`), t.push(" Always outside this graph: object storage / uploaded files, external processors,"), t.push(" log and metric sinks, backups, and any subject id embedded in JSON or free text."), t.join("\n");
|
|
462
|
-
}, $i = (e) => Object.fromEntries(Object.entries(e.updateValues ?? {}).filter(([t, n]) => {
|
|
463
|
-
if (n === void 0) return !1;
|
|
464
|
-
if (t === "id" || e.conflictColumns.includes(t)) throw S(`upsert: updateValues cannot rewrite row identity column '${t}'`);
|
|
465
|
-
return !0;
|
|
466
|
-
})), ea = (e, t, n) => {
|
|
467
|
-
let r = $i(n);
|
|
468
|
-
if (typeof n.update == "function") return {
|
|
469
|
-
...n.update(t),
|
|
470
|
-
...r
|
|
471
|
-
};
|
|
472
|
-
let i = n.update ?? Object.keys(e).filter((e) => e !== "id" && !n.conflictColumns.includes(e));
|
|
473
|
-
return {
|
|
474
|
-
...Object.fromEntries(i.filter((t) => t in e).map((t) => [t, e[t]])),
|
|
475
|
-
...r
|
|
476
|
-
};
|
|
477
|
-
}, ta = (e) => typeof e == "string" ? [["id", e]] : Object.entries(e).map(([e, t]) => [e, t]), na = (e) => {
|
|
478
|
-
if (typeof e == "string") return e;
|
|
479
|
-
let t = Object.entries(e);
|
|
480
|
-
return t.length === 1 ? String(t[0][1]) : t.slice().sort(([e], [t]) => e < t ? -1 : +(e > t)).map(([e, t]) => `${e}=${String(t)}`).join("\0");
|
|
481
|
-
}, ra = (e) => typeof e != "string", ia = (e, t, n) => {
|
|
482
|
-
let r = new Set(ta(e).map(([e]) => e)), i = t.split(".")[0];
|
|
483
|
-
return Object.fromEntries(Object.entries(n ?? {}).filter(([e, t]) => {
|
|
484
|
-
if (t === void 0) return !1;
|
|
485
|
-
if (r.has(e) || e === i) throw S(`patchJson: additionalPatch cannot rewrite the primary key or patched JSON column '${e}'`);
|
|
486
|
-
return !0;
|
|
487
|
-
}));
|
|
488
|
-
}, M = (e) => typeof e == "object" && !!e && !Array.isArray(e), aa = (e) => JSON.parse(JSON.stringify(e ?? null)), oa = (e, t, n) => {
|
|
489
|
-
let [r, ...i] = t.split("."), a = aa(n), o = e[r], s = (e, t) => {
|
|
490
|
-
if (t === i.length) return a;
|
|
491
|
-
let n = M(e) ? e : {}, r = i[t], o = Object.hasOwn(n, r) ? n[r] : void 0;
|
|
492
|
-
return {
|
|
493
|
-
...n,
|
|
494
|
-
[r]: s(o, t + 1)
|
|
495
|
-
};
|
|
496
|
-
};
|
|
497
|
-
return {
|
|
498
|
-
...e,
|
|
499
|
-
[r]: i.length === 0 ? M(o) && M(a) ? {
|
|
500
|
-
...o,
|
|
501
|
-
...a
|
|
502
|
-
} : a : s(o, 0)
|
|
503
|
-
};
|
|
504
|
-
}, sa = (e, t, n, r, i) => {
|
|
505
|
-
let [a, ...o] = n.split("."), s = i ?? e`${e(a)}`, c = aa(r), l = (e) => /["\\\u0000-\u001f]/.test(e);
|
|
506
|
-
if ((t === "sqlite" || t === "turso") && (o.some(l) || o.length === 0 && M(c) && Object.keys(c).some(l))) {
|
|
507
|
-
let t = 0, n = (t) => e`CASE WHEN (SELECT _voltro_json_escape_probe.key FROM json_each(${String.raw`{"\u0061":0}`}) AS _voltro_json_escape_probe) = ${String.raw`\u0061`}
|
|
508
|
-
THEN json_extract('"' || replace(${t}.key, '"', ${String.raw`\"`}) || '"', '$')
|
|
509
|
-
ELSE ${t}.key END`, r = (r) => {
|
|
510
|
-
let i = e`CASE WHEN json_type(${s}) = 'object' THEN ${s} ELSE '{}' END`;
|
|
511
|
-
for (let a of r) {
|
|
512
|
-
let r = e(`_voltro_json_${t++}`);
|
|
513
|
-
i = e`COALESCE((SELECT ${r}.value FROM json_each(${i}) AS ${r} WHERE ${n(r)} = ${a} AND ${r}.type = 'object'), '{}')`;
|
|
514
|
-
}
|
|
515
|
-
return i;
|
|
516
|
-
}, i = (r, i, a) => {
|
|
517
|
-
let o = e(`_voltro_json_${t++}`), s = e(`_voltro_json_${t++}`);
|
|
518
|
-
return e`(SELECT json_group_object(${s}.k, json(${s}.v)) FROM (
|
|
519
|
-
SELECT ${n(o)} AS k, CASE ${o}.type
|
|
520
|
-
WHEN 'true' THEN 'true' WHEN 'false' THEN 'false'
|
|
521
|
-
WHEN 'object' THEN ${o}.value WHEN 'array' THEN ${o}.value
|
|
522
|
-
ELSE json_quote(${o}.value) END AS v
|
|
523
|
-
FROM json_each(${r}) AS ${o} WHERE ${n(o)} <> ${i}
|
|
524
|
-
UNION ALL SELECT ${i}, ${a}
|
|
525
|
-
) AS ${s})`;
|
|
526
|
-
}, l;
|
|
527
|
-
if (o.length === 0) {
|
|
528
|
-
l = r([]);
|
|
529
|
-
for (let [t, n] of Object.entries(c)) l = i(l, t, e`${JSON.stringify(n)}`);
|
|
530
|
-
} else {
|
|
531
|
-
l = e`${JSON.stringify(c)}`;
|
|
532
|
-
for (let e = o.length - 1; e >= 0; e--) l = i(r(o.slice(0, e)), o[e], l);
|
|
533
|
-
}
|
|
534
|
-
return e`${e(a)} = ${l}`;
|
|
535
|
-
}
|
|
536
|
-
let u = (e) => "$" + e.map((e) => `.${JSON.stringify(e)}`).join(""), d = (t) => e`ARRAY[${e.join(", ", !1)(t.map((t) => e`${t}`))}]::text[]`, f = (n) => n.length === 0 ? s : t === "postgres" ? e`${s} #> ${d(n)}` : t === "mssql" ? e`JSON_QUERY(${s}, ${u(n)})` : t === "mysql" || t === "mariadb" ? e`JSON_EXTRACT(${s}, ${u(n)})` : e`json_extract(${s}, ${u(n)})`, p = (n) => t === "postgres" ? e`jsonb_typeof(${f(n)}) = 'object'` : t === "mssql" ? e`LEFT(LTRIM(${f(n)}), 1) = '{'` : t === "mysql" || t === "mariadb" ? e`JSON_TYPE(${f(n)}) = 'OBJECT'` : e`json_type(${s}, ${u(n)}) = 'object'`, m = t === "postgres" ? e`'{}'::jsonb` : e`'{}'`, h = (t) => {
|
|
537
|
-
let n = Array.from({ length: t.length + 1 }, (e, n) => p(t.slice(0, n)));
|
|
538
|
-
return e`CASE WHEN ${e.and(n)} THEN ${f(t)} ELSE ${m} END`;
|
|
539
|
-
}, g = (n) => {
|
|
540
|
-
let r = JSON.stringify(n);
|
|
541
|
-
return t === "postgres" ? e`${r}::jsonb` : e`${r}`;
|
|
542
|
-
}, _ = (n, r, i, a) => {
|
|
543
|
-
if (t === "postgres") return e`jsonb_set(${n}, ${d(r)}, ${i}, true)`;
|
|
544
|
-
let o = u(r);
|
|
545
|
-
return t === "mysql" || t === "mariadb" ? e`JSON_SET(${n}, ${o}, JSON_EXTRACT(${i}, '$'))` : t === "mssql" ? a === null ? e`JSON_MODIFY(JSON_MODIFY(${n}, ${o}, 0), ${`strict ${o}`}, NULL)` : typeof a == "boolean" ? e`JSON_MODIFY(${n}, ${o}, CAST(${+!!a} AS bit))` : typeof a == "string" || typeof a == "number" ? e`JSON_MODIFY(${n}, ${o}, ${a})` : e`JSON_MODIFY(${n}, ${o}, JSON_QUERY(${i}))` : e`json_set(${n}, ${o}, json(${i}))`;
|
|
546
|
-
}, v;
|
|
547
|
-
if (o.length === 0) {
|
|
548
|
-
if (!M(c)) v = g(c);
|
|
549
|
-
else {
|
|
550
|
-
v = h([]);
|
|
551
|
-
for (let [e, t] of Object.entries(c)) v = _(v, [e], g(t), t);
|
|
552
|
-
}
|
|
553
|
-
} else {
|
|
554
|
-
v = h([]);
|
|
555
|
-
for (let e = 1; e < o.length; e++) {
|
|
556
|
-
let t = o.slice(0, e);
|
|
557
|
-
v = _(v, t, h(t));
|
|
558
|
-
}
|
|
559
|
-
v = _(v, o, g(c), c);
|
|
560
|
-
}
|
|
561
|
-
return e`${e(a)} = ${v}`;
|
|
562
|
-
}, ca = class extends Error {
|
|
563
|
-
_tag = "EagerCardinalityError";
|
|
564
|
-
constructor(e) {
|
|
565
|
-
super(e), this.name = "EagerCardinalityError";
|
|
566
|
-
}
|
|
567
|
-
}, la = (e) => {
|
|
568
|
-
let { relationName: t, sourceTableName: n, targetTableName: r, foreignKey: i, sourceKey: a } = e, o = r === n;
|
|
569
|
-
return `relation '${t}' on '${n}' is declared \`one\`, but ${r}.${i} matches MORE than one row for the same ${n}.${a} — so there is no single related row to return.` + (o ? ` Because this relation is self-referential, check which side the key is on: \`foreignKey: '${i}'\` means "rows whose ${i} points AT me" (my children — there can be many). If you meant "the row my ${i} points to" (my parent), that is \`sourceKey: '${i}'\`.` : " Use `many(...)` if several are expected, or narrow the key.");
|
|
570
|
-
}, ua = async (e, t, n, r) => {
|
|
571
|
-
if (e.length === 0) return e;
|
|
572
|
-
let i = Fi(n.tableName);
|
|
573
|
-
if (i === void 0) throw S(`cannot eager-load on '${n.tableName}': no relations registered. Did you forget to declare \`relations(${n.tableName}, ...)\` or import the file that does?`);
|
|
574
|
-
let a = e.map((e) => ({ ...e }));
|
|
575
|
-
for (let [e, o] of Object.entries(t)) {
|
|
576
|
-
let t = i[e];
|
|
577
|
-
if (t === void 0) {
|
|
578
|
-
let t = Object.keys(i).join(", ") || "<none>";
|
|
579
|
-
throw S(`unknown relation '${e}' on '${n.tableName}'. Registered relations: ${t}.`);
|
|
580
|
-
}
|
|
581
|
-
Ai(n, e, t), await da(a, e, t, o === !0 ? {} : o, n, r);
|
|
582
|
-
}
|
|
583
|
-
return a;
|
|
584
|
-
}, da = async (e, t, n, r, i, a) => {
|
|
585
|
-
switch (n.kind) {
|
|
586
|
-
case "one":
|
|
587
|
-
await fa(e, t, n, r, i, a);
|
|
588
|
-
return;
|
|
589
|
-
case "many":
|
|
590
|
-
await pa(e, t, n, r, i, a);
|
|
591
|
-
return;
|
|
592
|
-
case "manyToMany":
|
|
593
|
-
await ha(e, t, n, r, i, a);
|
|
594
|
-
return;
|
|
595
|
-
}
|
|
596
|
-
}, fa = async (e, t, n, r, i, a) => {
|
|
597
|
-
let o = n.target(), s = n.sourceKey ?? ga(i, o.tableName);
|
|
598
|
-
if (s !== void 0) {
|
|
599
|
-
let n = P(e, s), c = n.length === 0 ? [] : await _a(o, "id", n, r, a), l = new Map(c.map((e) => [N(o, "id", e.id), e]));
|
|
600
|
-
for (let n of e) {
|
|
601
|
-
let e = N(i, s, n[s]);
|
|
602
|
-
n[t] = e == null ? null : l.get(e) ?? null;
|
|
603
|
-
}
|
|
604
|
-
await va(c, r.with, o, a);
|
|
605
|
-
return;
|
|
606
|
-
}
|
|
607
|
-
let c = n.foreignKey ?? Ei(o, i.tableName, t), l = n.sourceKey ?? "id", u = P(e, l), d = u.length === 0 ? [] : await _a(o, c, u, r, a), f = /* @__PURE__ */ new Map();
|
|
608
|
-
for (let e of d) {
|
|
609
|
-
let n = N(o, c, e[c]);
|
|
610
|
-
if (f.has(n)) throw new ca(la({
|
|
611
|
-
relationName: t,
|
|
612
|
-
sourceTableName: i.tableName,
|
|
613
|
-
targetTableName: o.tableName,
|
|
614
|
-
foreignKey: c,
|
|
615
|
-
sourceKey: l
|
|
616
|
-
}));
|
|
617
|
-
f.set(n, e);
|
|
618
|
-
}
|
|
619
|
-
for (let n of e) {
|
|
620
|
-
let e = N(i, l, n[l]);
|
|
621
|
-
n[t] = e == null ? null : f.get(e) ?? null;
|
|
622
|
-
}
|
|
623
|
-
await va(d, r.with, o, a);
|
|
624
|
-
}, pa = async (e, t, n, r, i, a) => {
|
|
625
|
-
let o = n.target(), s = n.foreignKey ?? Ei(o, i.tableName, t), c = n.sourceKey ?? "id", l = P(e, c), u = ma(r), d = l.length === 0 ? [] : await _a(o, s, l, u, a), f = /* @__PURE__ */ new Map(), p = r.offset ?? 0, m = Number.isSafeInteger(p) && p >= 0 && (r.limit === void 0 || Number.isSafeInteger(r.limit) && r.limit >= 0), h = /* @__PURE__ */ new Map();
|
|
626
|
-
for (let e of d) {
|
|
627
|
-
let t = N(o, s, e[s]);
|
|
628
|
-
if (m) {
|
|
629
|
-
let e = h.get(t) ?? 0;
|
|
630
|
-
if (h.set(t, e + 1), e < p || r.limit !== void 0 && e - p >= r.limit) continue;
|
|
631
|
-
}
|
|
632
|
-
let n = f.get(t);
|
|
633
|
-
n ? n.push(e) : f.set(t, [e]);
|
|
634
|
-
}
|
|
635
|
-
if (!m && (r.limit !== void 0 || r.offset !== void 0)) {
|
|
636
|
-
let e = r.limit;
|
|
637
|
-
for (let [t, n] of f) {
|
|
638
|
-
let r = e === void 0 ? n.slice(p) : n.slice(p, p + e);
|
|
639
|
-
f.set(t, r);
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
for (let n of e) {
|
|
643
|
-
let e = N(i, c, n[c]);
|
|
644
|
-
n[t] = f.get(e) ?? [];
|
|
645
|
-
}
|
|
646
|
-
r.with !== void 0 && await va([...f.values()].flat(), r.with, o, a);
|
|
647
|
-
}, ma = (e) => {
|
|
648
|
-
let { limit: t, offset: n, ...r } = e;
|
|
649
|
-
return r;
|
|
650
|
-
}, ha = async (e, t, n, r, i, a) => {
|
|
651
|
-
let o = n.target(), s = n.through(), c = P(e, "id");
|
|
652
|
-
if (c.length === 0) {
|
|
653
|
-
for (let n of e) n[t] = [];
|
|
654
|
-
return;
|
|
655
|
-
}
|
|
656
|
-
let l = {
|
|
657
|
-
column: n.sourceKey,
|
|
658
|
-
op: "in",
|
|
659
|
-
value: c
|
|
660
|
-
}, u = r.onJunction === void 0 ? l : { and: [l, r.onJunction] }, d = await a({
|
|
661
|
-
table: s.tableName,
|
|
662
|
-
predicate: u,
|
|
663
|
-
order: [],
|
|
664
|
-
take: void 0,
|
|
665
|
-
skip: void 0,
|
|
666
|
-
projection: void 0
|
|
667
|
-
});
|
|
668
|
-
if (d.length === 0) {
|
|
669
|
-
for (let n of e) n[t] = [];
|
|
670
|
-
return;
|
|
671
|
-
}
|
|
672
|
-
let f = await _a(o, "id", P(d, n.targetKey), r, a), p = new Map(f.map((e) => [N(o, "id", e.id), e]));
|
|
673
|
-
await va(f, r.with, o, a);
|
|
674
|
-
let m = r.junction === void 0 ? void 0 : r.junction === !0 ? C(s) : r.junction, h = /* @__PURE__ */ new Map();
|
|
675
|
-
for (let e of d) {
|
|
676
|
-
let t = N(s, n.sourceKey, e[n.sourceKey]), r = N(s, n.targetKey, e[n.targetKey]), i = p.get(r);
|
|
677
|
-
if (i === void 0) continue;
|
|
678
|
-
let a = m === void 0 ? i : {
|
|
679
|
-
...i,
|
|
680
|
-
_junction: Object.fromEntries(m.map((t) => [t, e[t]]))
|
|
681
|
-
}, o = h.get(t);
|
|
682
|
-
o ? o.push(a) : h.set(t, [a]);
|
|
683
|
-
}
|
|
684
|
-
for (let n of e) n[t] = h.get(N(i, "id", n.id)) ?? [];
|
|
685
|
-
}, N = (e, t, n) => e.fields[t]?.type === "decimal" ? me(n) ?? n : n, ga = (e, t) => {
|
|
686
|
-
for (let [n, r] of Object.entries(e.fields)) if (r.type === "reference" && r.references?.()?.tableName === t) return n;
|
|
687
|
-
}, P = (e, t) => {
|
|
688
|
-
let n = /* @__PURE__ */ new Set();
|
|
689
|
-
for (let r of e) {
|
|
690
|
-
let e = r[t];
|
|
691
|
-
e != null && n.add(e);
|
|
692
|
-
}
|
|
693
|
-
return [...n];
|
|
694
|
-
}, _a = (e, t, n, r, i) => {
|
|
695
|
-
let a = {
|
|
696
|
-
column: t,
|
|
697
|
-
op: "in",
|
|
698
|
-
value: n
|
|
699
|
-
}, o = r.where === void 0 ? a : { and: [r.where, a] };
|
|
700
|
-
return i({
|
|
701
|
-
table: e.tableName,
|
|
702
|
-
predicate: o,
|
|
703
|
-
order: r.orderBy ?? [],
|
|
704
|
-
take: r.limit,
|
|
705
|
-
skip: r.offset,
|
|
706
|
-
projection: void 0
|
|
707
|
-
});
|
|
708
|
-
}, va = async (e, t, n, r) => {
|
|
709
|
-
t !== void 0 && e.length !== 0 && (await ua(e, t, n, r)).forEach((t, n) => {
|
|
710
|
-
let r = e[n];
|
|
711
|
-
for (let [e, n] of Object.entries(t)) e in r || (r[e] = n);
|
|
712
|
-
});
|
|
713
|
-
}, ya = (e) => e.eager !== void 0 && Object.keys(e.eager).length > 0, ba = (e, t, n) => {
|
|
714
|
-
if (e.eager === void 0) return null;
|
|
715
|
-
let r = Ca(e.table, e.eager, e.sourceTable);
|
|
716
|
-
if (r === null || n === "sqlite" && xa(r)) return null;
|
|
717
|
-
let i = Aa(n, e, r, ka(t, n));
|
|
718
|
-
return i === null ? null : {
|
|
719
|
-
fragment: i,
|
|
720
|
-
decode: Na(r, n)
|
|
721
|
-
};
|
|
722
|
-
}, xa = (e) => Object.values(e.table.fields).some(Se) || e.children.some((e) => xa({
|
|
723
|
-
table: e.target,
|
|
724
|
-
children: e.children
|
|
725
|
-
}) || e.relation.kind === "manyToMany" && Object.values(e.relation.through().fields).some(Se)), F = (e) => e.relation.kind === "one" && e.fkSide === "target", Sa = (e) => ({
|
|
726
|
-
...e,
|
|
727
|
-
branch: {
|
|
728
|
-
...e.branch,
|
|
729
|
-
limit: 2
|
|
730
|
-
}
|
|
731
|
-
}), Ca = (e, t, n) => {
|
|
732
|
-
let r = n ?? ie(e), i = Fi(e);
|
|
733
|
-
if (i === void 0) return null;
|
|
734
|
-
let a = [];
|
|
735
|
-
for (let [e, n] of Object.entries(t)) {
|
|
736
|
-
let t = i[e];
|
|
737
|
-
if (t === void 0) return null;
|
|
738
|
-
let o = wa(e, t, r, n === !0 ? {} : n);
|
|
739
|
-
if (o === null) return null;
|
|
740
|
-
a.push(o);
|
|
741
|
-
}
|
|
742
|
-
return {
|
|
743
|
-
table: r,
|
|
744
|
-
children: a
|
|
745
|
-
};
|
|
746
|
-
}, wa = (e, t, n, r) => {
|
|
747
|
-
let i = t.target(), a = (t.kind === "manyToMany" ? void 0 : t.sourceKey) ?? "id", o, s;
|
|
748
|
-
if (t.kind === "manyToMany") o = t.targetKey, s = "target";
|
|
749
|
-
else if (t.kind === "one") {
|
|
750
|
-
let r = t.sourceKey ?? Oa(n, i.tableName);
|
|
751
|
-
if (r !== void 0) o = r, s = "source";
|
|
752
|
-
else try {
|
|
753
|
-
o = t.foreignKey ?? Ei(i, n.tableName, e), s = "target";
|
|
754
|
-
} catch {
|
|
755
|
-
return null;
|
|
756
|
-
}
|
|
757
|
-
} else try {
|
|
758
|
-
o = t.foreignKey ?? Ei(i, n.tableName, e), s = "target";
|
|
759
|
-
} catch {
|
|
760
|
-
return null;
|
|
761
|
-
}
|
|
762
|
-
let c = r.with === void 0 ? [] : (() => {
|
|
763
|
-
let e = Fi(i.tableName);
|
|
764
|
-
if (e === void 0 && Object.keys(r.with).length > 0) return null;
|
|
765
|
-
let t = [];
|
|
766
|
-
for (let [n, a] of Object.entries(r.with)) {
|
|
767
|
-
let r = e?.[n];
|
|
768
|
-
if (r === void 0) return null;
|
|
769
|
-
let o = wa(n, r, i, a === !0 ? {} : a);
|
|
770
|
-
if (o === null) return null;
|
|
771
|
-
t.push(o);
|
|
772
|
-
}
|
|
773
|
-
return t;
|
|
774
|
-
})();
|
|
775
|
-
return c === null ? null : {
|
|
776
|
-
relationName: e,
|
|
777
|
-
relation: t,
|
|
778
|
-
source: n,
|
|
779
|
-
target: i,
|
|
780
|
-
foreignKey: o,
|
|
781
|
-
sourceKey: a,
|
|
782
|
-
fkSide: s,
|
|
783
|
-
branch: r,
|
|
784
|
-
children: c,
|
|
785
|
-
junction: Ta(t, r)
|
|
786
|
-
};
|
|
787
|
-
}, Ta = (e, t) => {
|
|
788
|
-
if (e.kind !== "manyToMany" || t.junction === void 0) return;
|
|
789
|
-
let n = e.through(), r = C(n), i = t.junction === !0 ? r : t.junction, a = t.junction === !0 ? void 0 : new Set(r), o = a === void 0 ? r : i.filter((e) => a.has(e));
|
|
790
|
-
return {
|
|
791
|
-
through: n,
|
|
792
|
-
requested: i,
|
|
793
|
-
present: o,
|
|
794
|
-
dateColumns: o.filter((e) => {
|
|
795
|
-
let t = n.fields[e];
|
|
796
|
-
return t !== void 0 && (t.type === "timestamp" || t.type === "date");
|
|
797
|
-
})
|
|
798
|
-
};
|
|
799
|
-
}, Ea = (e) => `__j_${e}`, Da = "__j", Oa = (e, t) => {
|
|
800
|
-
for (let [n, r] of Object.entries(e.fields)) if (r.type === "reference" && r.references?.()?.tableName === t) return n;
|
|
801
|
-
}, ka = (e, t) => {
|
|
802
|
-
let n = 0;
|
|
803
|
-
return {
|
|
804
|
-
sql: e,
|
|
805
|
-
dialect: t,
|
|
806
|
-
nextAlias: () => `__a${n++}`
|
|
807
|
-
};
|
|
808
|
-
}, Aa = (e, t, n, r) => {
|
|
809
|
-
switch (e) {
|
|
810
|
-
case "postgres": return Ia(t, n, r);
|
|
811
|
-
case "sqlite":
|
|
812
|
-
case "turso": return Wa(t, n, r);
|
|
813
|
-
case "mysql":
|
|
814
|
-
case "mariadb": return eo(t, n, r);
|
|
815
|
-
case "mssql": return so(t, n, r);
|
|
816
|
-
}
|
|
817
|
-
}, ja = (e, t) => t === "mssql" && !Ma.test(e) ? /* @__PURE__ */ new Date(`${e}Z`) : new Date(e), Ma = /(?:Z|[+-]\d{2}:?\d{2})$/, Na = (e, t) => {
|
|
818
|
-
let n = Pa(e.table, e.children, t);
|
|
819
|
-
return (e) => e.map((e) => {
|
|
820
|
-
let t = e.__row, r = typeof t == "string" ? JSON.parse(t) : t;
|
|
821
|
-
return n(r);
|
|
822
|
-
});
|
|
823
|
-
}, Pa = (e, t, n) => {
|
|
824
|
-
let r = [], i = [];
|
|
825
|
-
for (let [t, n] of Object.entries(e.fields)) (n.type === "timestamp" || n.type === "date") && r.push(t), n.type === "vector" && i.push(t);
|
|
826
|
-
let a = t.map((e) => {
|
|
827
|
-
let t = Pa(e.target, e.children, n), r = e.relation.kind === "one", i = F(e), a = i ? la({
|
|
828
|
-
relationName: e.relationName,
|
|
829
|
-
sourceTableName: e.source.tableName,
|
|
830
|
-
targetTableName: e.target.tableName,
|
|
831
|
-
foreignKey: e.foreignKey,
|
|
832
|
-
sourceKey: e.sourceKey
|
|
833
|
-
}) : "";
|
|
834
|
-
return {
|
|
835
|
-
name: e.relationName,
|
|
836
|
-
decode: t,
|
|
837
|
-
isSingle: r,
|
|
838
|
-
fromOverFetch: i,
|
|
839
|
-
cardinalityMessage: a,
|
|
840
|
-
junction: Fa(e.junction, n)
|
|
841
|
-
};
|
|
842
|
-
});
|
|
843
|
-
return (e) => {
|
|
844
|
-
let t = { ...e };
|
|
845
|
-
for (let e of i) e in t && (t[e] = ct(t[e], "vector", n));
|
|
846
|
-
for (let e of r) {
|
|
847
|
-
let r = t[e];
|
|
848
|
-
typeof r == "string" && (t[e] = ja(r, n));
|
|
849
|
-
}
|
|
850
|
-
for (let e of a) {
|
|
851
|
-
let n = t[e.name];
|
|
852
|
-
if (n == null) {
|
|
853
|
-
t[e.name] = e.isSingle ? null : [];
|
|
854
|
-
continue;
|
|
855
|
-
}
|
|
856
|
-
if (e.fromOverFetch) {
|
|
857
|
-
let r = n;
|
|
858
|
-
if (r.length > 1) throw new ca(e.cardinalityMessage);
|
|
859
|
-
t[e.name] = r.length === 0 ? null : e.decode(r[0]);
|
|
860
|
-
continue;
|
|
861
|
-
}
|
|
862
|
-
if (e.isSingle) t[e.name] = e.decode(n);
|
|
863
|
-
else {
|
|
864
|
-
let r = n.map((t) => e.decode(t));
|
|
865
|
-
t[e.name] = e.junction === void 0 ? r : r.map((t) => e.junction(t));
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
return t;
|
|
869
|
-
};
|
|
870
|
-
}, Fa = (e, t) => {
|
|
871
|
-
if (e === void 0) return;
|
|
872
|
-
let n = new Set(e.dateColumns), r = e.requested;
|
|
873
|
-
return (e) => {
|
|
874
|
-
let i = e._junction ?? {}, a = {};
|
|
875
|
-
for (let e of r) {
|
|
876
|
-
let r = i[e];
|
|
877
|
-
a[e] = n.has(e) && typeof r == "string" ? ja(r, t) : r;
|
|
878
|
-
}
|
|
879
|
-
return {
|
|
880
|
-
...e,
|
|
881
|
-
_junction: a
|
|
882
|
-
};
|
|
883
|
-
};
|
|
884
|
-
}, Ia = (e, t, n) => {
|
|
885
|
-
let r = n.sql, i = n.nextAlias(), a = r(t.table.tableName), o = r(i), s = La(i, t.children, n);
|
|
886
|
-
return s === null ? null : r`SELECT ${s} AS "__row" FROM ${a} AS ${o}${e.predicate ? r` WHERE ${V(e.predicate, i, r)}` : r``}${T(e).length > 0 ? r` ORDER BY ${r.join(", ", !1)(T(e).map((e) => e.direction === "desc" ? r`${R(i, e.column, r)} DESC` : r`${R(i, e.column, r)} ASC`))}` : r``}${e.take === void 0 ? r`` : r` LIMIT ${B(e.take, r)}`}${e.skip === void 0 ? r`` : r` OFFSET ${B(e.skip, r)}`}`;
|
|
887
|
-
}, La = (e, t, n, r) => {
|
|
888
|
-
let i = n.sql, a = r === void 0 ? i`to_jsonb(${i(e)}.*)` : i`(to_jsonb(${i(e)}.*) - ${z(Da, i)}::text)`;
|
|
889
|
-
if (t.length === 0 && r === void 0) return a;
|
|
890
|
-
let o = [];
|
|
891
|
-
r !== void 0 && o.push(i`${z("_junction", i)}, ${R(e, Da, i)}`);
|
|
892
|
-
for (let r of t) {
|
|
893
|
-
let t = Ra(r, e, n);
|
|
894
|
-
if (t === null) return null;
|
|
895
|
-
o.push(i`${z(r.relationName, i)}, ${t}`);
|
|
896
|
-
}
|
|
897
|
-
return i`${a} || jsonb_build_object(${i.join(", ", !1)(o)})`;
|
|
898
|
-
}, Ra = (e, t, n) => {
|
|
899
|
-
switch (e.relation.kind) {
|
|
900
|
-
case "one": return F(e) ? Ba(Sa(e), t, n) : za(e, t, n);
|
|
901
|
-
case "many": return Ba(e, t, n);
|
|
902
|
-
case "manyToMany": return Va(e, t, n);
|
|
903
|
-
}
|
|
904
|
-
}, za = (e, t, n) => {
|
|
905
|
-
let r = n.sql, i = n.nextAlias(), a = La(i, e.children, n);
|
|
906
|
-
if (a === null) return null;
|
|
907
|
-
let o = e.fkSide === "source" ? r`${R(i, "id", r)} = ${R(t, e.foreignKey, r)}` : r`${R(i, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${V(e.branch.where, i, r)}`, c = I(i, e.branch.orderBy, r);
|
|
908
|
-
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}${c} LIMIT 1)`;
|
|
909
|
-
}, Ba = (e, t, n) => {
|
|
910
|
-
let r = n.sql, i = n.nextAlias(), a = La(i, e.children, n);
|
|
911
|
-
if (a === null) return null;
|
|
912
|
-
let o = r`${R(void 0, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${y(e.branch.where, r)}`, c = Ua(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${B(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${B(e.branch.offset, r)}`;
|
|
913
|
-
return r`COALESCE((SELECT jsonb_agg(${a}) FROM (SELECT * FROM ${r(e.target.tableName)} WHERE ${o}${s}${c}${l}${u}) AS ${r(i)}), '[]'::jsonb)`;
|
|
914
|
-
}, Va = (e, t, n) => {
|
|
915
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = La(o, e.children, n, e.junction);
|
|
916
|
-
if (c === null) return null;
|
|
917
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${y(e.branch.where, r)}`, u = go(e, s, r), d = I(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${B(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${B(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : r`, ${Ha(e.junction, s, r)} AS ${r(Da)}`;
|
|
918
|
-
return r`COALESCE((SELECT jsonb_agg(${c}) FROM (SELECT ${r(o)}.*${m} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${R(o, "id", r)} = ${R(s, i.targetKey, r)} WHERE ${R(s, i.sourceKey, r)} = ${R(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), '[]'::jsonb)`;
|
|
919
|
-
}, Ha = (e, t, n) => e.present.length === 0 ? n`jsonb_build_object()` : n`jsonb_build_object(${n.join(", ", !1)(e.present.map((e) => n`${z(e, n)}, ${R(t, e, n)}`))})`, I = (e, t, n) => t === void 0 || t.length === 0 ? n`` : n` ORDER BY ${n.join(", ", !1)(t.map((t) => t.direction === "desc" ? n`${R(e, t.column, n)} DESC` : n`${R(e, t.column, n)} ASC`))}`, Ua = (e, t) => e === void 0 || e.length === 0 ? t`` : t` ORDER BY ${t.join(", ", !1)(e.map((e) => e.direction === "desc" ? t`${t(e.column)} DESC` : t`${t(e.column)} ASC`))}`, Wa = (e, t, n) => {
|
|
920
|
-
let r = n.sql, i = n.nextAlias(), a = Ga(i, t.table, t.children, n);
|
|
921
|
-
if (a === null) return null;
|
|
922
|
-
let o = e.predicate ? r` WHERE ${V(e.predicate, i, r)}` : r``, s = T(e).length > 0 ? r` ORDER BY ${r.join(", ", !1)(T(e).map((e) => e.direction === "desc" ? r`${R(i, e.column, r)} DESC` : r`${R(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${B(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${B(e.skip, r)}`;
|
|
923
|
-
return r`SELECT ${a} AS "__row" FROM ${r(t.table.tableName)} AS ${r(i)}${o}${s}${c}${l}`;
|
|
924
|
-
}, Ga = (e, t, n, r, i) => {
|
|
925
|
-
let a = r.sql, o = [];
|
|
926
|
-
for (let n of C(t)) {
|
|
927
|
-
let r = R(e, n, a), i = t.fields[n]?.type === "bigint" ? a`CAST(${r} AS TEXT)` : r;
|
|
928
|
-
o.push(a`${z(n, a)}, ${i}`);
|
|
929
|
-
}
|
|
930
|
-
if (i !== void 0) {
|
|
931
|
-
let e = Ka(i.projection, i.source, a);
|
|
932
|
-
o.push(a`${z("_junction", a)}, json_object(${e})`);
|
|
933
|
-
}
|
|
934
|
-
for (let t of n) {
|
|
935
|
-
let n = Xa(t, e, r);
|
|
936
|
-
if (n === null) return null;
|
|
937
|
-
o.push(a`${z(t.relationName, a)}, ${n}`);
|
|
938
|
-
}
|
|
939
|
-
return a`json_object(${a.join(", ", !1)(o)})`;
|
|
940
|
-
}, Ka = (e, t, n) => e.present.length === 0 ? n`` : n.join(", ", !1)(e.present.map((r) => {
|
|
941
|
-
let i = R(t.alias, t.physical(r), n), a = e.through.fields[r]?.type === "bigint" ? n.onDialectOrElse({
|
|
942
|
-
sqlite: () => n`CAST(${i} AS TEXT)`,
|
|
943
|
-
orElse: () => i
|
|
944
|
-
}) : i;
|
|
945
|
-
return n`${z(r, n)}, ${a}`;
|
|
946
|
-
})), qa = (e, t, n) => e.present.length === 0 ? n`` : n`, ${n.join(", ", !1)(e.present.map((e) => n`${R(t, e, n)} AS ${n(Ea(e))}`))}`, Ja = (e) => ({
|
|
947
|
-
alias: e,
|
|
948
|
-
physical: Ea
|
|
949
|
-
}), Ya = (e) => ({
|
|
950
|
-
alias: e,
|
|
951
|
-
physical: (e) => e
|
|
952
|
-
}), Xa = (e, t, n) => {
|
|
953
|
-
switch (e.relation.kind) {
|
|
954
|
-
case "one": return F(e) ? Qa(Sa(e), t, n) : Za(e, t, n);
|
|
955
|
-
case "many": return Qa(e, t, n);
|
|
956
|
-
case "manyToMany": return $a(e, t, n);
|
|
957
|
-
}
|
|
958
|
-
}, Za = (e, t, n) => {
|
|
959
|
-
let r = n.sql, i = n.nextAlias(), a = Ga(i, e.target, e.children, n);
|
|
960
|
-
if (a === null) return null;
|
|
961
|
-
let o = e.fkSide === "source" ? r`${R(i, "id", r)} = ${R(t, e.foreignKey, r)}` : r`${R(i, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}`;
|
|
962
|
-
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
|
|
963
|
-
}, Qa = (e, t, n) => {
|
|
964
|
-
let r = n.sql, i = n.nextAlias(), a = Ga(i, e.target, e.children, n);
|
|
965
|
-
if (a === null) return null;
|
|
966
|
-
let o = r`${R(void 0, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${y(H(e.branch.where), r)}`, c = Ua(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${B(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${B(e.branch.offset, r)}`;
|
|
967
|
-
return r`COALESCE((SELECT json_group_array(${a}) FROM (SELECT * FROM ${r(e.target.tableName)} WHERE ${o}${s}${c}${l}${u}) AS ${r(i)}), json('[]'))`;
|
|
968
|
-
}, $a = (e, t, n) => {
|
|
969
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = Ga(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
970
|
-
projection: e.junction,
|
|
971
|
-
source: Ja(o)
|
|
972
|
-
});
|
|
973
|
-
if (c === null) return null;
|
|
974
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${y(H(e.branch.where), r)}`, u = go(e, s, r, !0), d = I(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${B(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${B(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : qa(e.junction, s, r);
|
|
975
|
-
return r`COALESCE((SELECT json_group_array(${c}) FROM (SELECT ${r(o)}.*${m} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${R(o, "id", r)} = ${R(s, i.targetKey, r)} WHERE ${R(s, i.sourceKey, r)} = ${R(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), json('[]'))`;
|
|
976
|
-
}, eo = (e, t, n) => {
|
|
977
|
-
let r = n.sql, i = n.nextAlias(), a = L(i, t.table, t.children, n);
|
|
978
|
-
if (a === null) return null;
|
|
979
|
-
let o = e.predicate ? r` WHERE ${V(e.predicate, i, r)}` : r``, s = T(e).length > 0 ? r` ORDER BY ${r.join(", ", !1)(T(e).map((e) => e.direction === "desc" ? r`${R(i, e.column, r)} DESC` : r`${R(i, e.column, r)} ASC`))}` : r``, c = e.take === void 0 ? r`` : r` LIMIT ${B(e.take, r)}`, l = e.skip === void 0 ? r`` : r` OFFSET ${B(e.skip, r)}`;
|
|
980
|
-
return r`SELECT ${a} AS \`__row\` FROM ${r(t.table.tableName)} AS ${r(i)}${o}${s}${c}${l}`;
|
|
981
|
-
}, L = (e, t, n, r, i) => {
|
|
982
|
-
let a = r.sql, o = [];
|
|
983
|
-
for (let n of C(t)) o.push(a`${z(n, a)}, ${R(e, n, a)}`);
|
|
984
|
-
if (i !== void 0) {
|
|
985
|
-
let e = Ka(i.projection, i.source, a);
|
|
986
|
-
o.push(a`${z("_junction", a)}, JSON_OBJECT(${e})`);
|
|
987
|
-
}
|
|
988
|
-
for (let t of n) {
|
|
989
|
-
let n = to(t, e, r);
|
|
990
|
-
if (n === null) return null;
|
|
991
|
-
o.push(a`${z(t.relationName, a)}, ${n}`);
|
|
992
|
-
}
|
|
993
|
-
return a`JSON_OBJECT(${a.join(", ", !1)(o)})`;
|
|
994
|
-
}, to = (e, t, n) => {
|
|
995
|
-
switch (e.relation.kind) {
|
|
996
|
-
case "one":
|
|
997
|
-
if (F(e)) {
|
|
998
|
-
let r = Sa(e);
|
|
999
|
-
return n.dialect === "mariadb" ? ao(r, t, n) : ro(r, t, n);
|
|
1000
|
-
}
|
|
1001
|
-
return no(e, t, n);
|
|
1002
|
-
case "many": return n.dialect === "mariadb" ? ao(e, t, n) : ro(e, t, n);
|
|
1003
|
-
case "manyToMany": return n.dialect === "mariadb" ? oo(e, t, n) : io(e, t, n);
|
|
1004
|
-
}
|
|
1005
|
-
}, no = (e, t, n) => {
|
|
1006
|
-
let r = n.sql, i = n.nextAlias(), a = L(i, e.target, e.children, n);
|
|
1007
|
-
if (a === null) return null;
|
|
1008
|
-
let o = e.fkSide === "source" ? r`${R(i, "id", r)} = ${R(t, e.foreignKey, r)}` : r`${R(i, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}`;
|
|
1009
|
-
return r`(SELECT ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} LIMIT 1)`;
|
|
1010
|
-
}, ro = (e, t, n) => {
|
|
1011
|
-
let r = n.sql, i = n.nextAlias(), a = L(i, e.target, e.children, n);
|
|
1012
|
-
if (a === null) return null;
|
|
1013
|
-
let o = r`${R(void 0, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${y(H(e.branch.where), r)}`, c = Ua(e.branch.orderBy, r), l = e.branch.limit === void 0 ? r`` : r` LIMIT ${B(e.branch.limit, r)}`, u = e.branch.offset === void 0 ? r`` : r` OFFSET ${B(e.branch.offset, r)}`;
|
|
1014
|
-
return r`COALESCE((SELECT JSON_ARRAYAGG(${a}) FROM (SELECT * FROM ${r(e.target.tableName)} WHERE ${o}${s}${c}${l}${u}) AS ${r(i)}), JSON_ARRAY())`;
|
|
1015
|
-
}, io = (e, t, n) => {
|
|
1016
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = L(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
1017
|
-
projection: e.junction,
|
|
1018
|
-
source: Ja(o)
|
|
1019
|
-
});
|
|
1020
|
-
if (c === null) return null;
|
|
1021
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${y(H(e.branch.where), r)}`, u = go(e, s, r, !0), d = I(o, e.branch.orderBy, r), f = e.branch.limit === void 0 ? r`` : r` LIMIT ${B(e.branch.limit, r)}`, p = e.branch.offset === void 0 ? r`` : r` OFFSET ${B(e.branch.offset, r)}`, m = e.junction === void 0 ? r`` : qa(e.junction, s, r);
|
|
1022
|
-
return r`COALESCE((SELECT JSON_ARRAYAGG(${c}) FROM (SELECT ${r(o)}.*${m} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${R(o, "id", r)} = ${R(s, i.targetKey, r)} WHERE ${R(s, i.sourceKey, r)} = ${R(t, "id", r)}${u}${l}${d}${f}${p}) AS ${r(o)}), JSON_ARRAY())`;
|
|
1023
|
-
}, ao = (e, t, n) => {
|
|
1024
|
-
let r = n.sql, i = n.nextAlias(), a = L(i, e.target, e.children, n);
|
|
1025
|
-
if (a === null) return null;
|
|
1026
|
-
let o = r`${R(i, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}`, s = e.branch.where === void 0 ? r`` : r` AND ${y(H(e.branch.where), r)}`, c = e.branch.orderBy ?? [];
|
|
1027
|
-
if (e.branch.limit === void 0 && e.branch.offset === void 0) return r`COALESCE((SELECT JSON_ARRAYAGG(${a}${c.length > 0 ? r` ORDER BY ${r.join(", ", !1)(c.map((e) => e.direction === "desc" ? r`${R(i, e.column, r)} DESC` : r`${R(i, e.column, r)} ASC`))}` : r``}) FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o}${s}), JSON_ARRAY())`;
|
|
1028
|
-
let l = c.length > 0 ? r` ORDER BY ${r.join(", ", !1)(c.map((e) => e.direction === "desc" ? r`${r(e.column)} DESC` : r`${r(e.column)} ASC`))}` : r` ORDER BY ${r("id")}`, u = e.branch.limit, d = e.branch.offset, f = u !== void 0 && d !== void 0 ? r` AND ${R(i, "rn", r)} > ${B(d, r)} AND ${R(i, "rn", r)} <= ${B(d + u, r)}` : u === void 0 ? r` AND ${R(i, "rn", r)} > ${B(d, r)}` : r` AND ${R(i, "rn", r)} <= ${B(u, r)}`;
|
|
1029
|
-
return r`COALESCE((SELECT JSON_ARRAYAGG(${a} ORDER BY ${R(i, "rn", r)}) FROM (SELECT *, ROW_NUMBER() OVER (PARTITION BY ${r(e.foreignKey)}${l}) AS rn FROM ${r(e.target.tableName)}) AS ${r(i)} WHERE ${o}${s}${f}), JSON_ARRAY())`;
|
|
1030
|
-
}, oo = (e, t, n) => {
|
|
1031
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = (t) => e.junction === void 0 ? void 0 : {
|
|
1032
|
-
projection: e.junction,
|
|
1033
|
-
source: t
|
|
1034
|
-
}, l = r`${R(s, i.sourceKey, r)} = ${R(t, "id", r)}`, u = r`${R(o, "id", r)} = ${R(s, i.targetKey, r)}`, d = e.branch.where === void 0 ? r`` : r` AND ${y(H(e.branch.where), r)}`, f = go(e, s, r, !0), p = e.branch.orderBy ?? [];
|
|
1035
|
-
if (e.branch.limit === void 0 && e.branch.offset === void 0) {
|
|
1036
|
-
let t = L(o, e.target, e.children, n, c(Ya(s)));
|
|
1037
|
-
return t === null ? null : r`COALESCE((SELECT JSON_ARRAYAGG(${t}${p.length > 0 ? r` ORDER BY ${r.join(", ", !1)(p.map((e) => e.direction === "desc" ? r`${R(o, e.column, r)} DESC` : r`${R(o, e.column, r)} ASC`))}` : r``}) FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${u} WHERE ${l}${f}${d}), JSON_ARRAY())`;
|
|
1038
|
-
}
|
|
1039
|
-
let m = p.length > 0 ? r` ORDER BY ${r.join(", ", !1)(p.map((e) => e.direction === "desc" ? r`${R(o, e.column, r)} DESC` : r`${R(o, e.column, r)} ASC`))}` : r` ORDER BY ${R(o, "id", r)}`, h = e.branch.limit, g = e.branch.offset, _ = h !== void 0 && g !== void 0 ? r` AND ${R(o, "rn", r)} > ${B(g, r)} AND ${R(o, "rn", r)} <= ${B(g + h, r)}` : h === void 0 ? r` AND ${R(o, "rn", r)} > ${B(g, r)}` : r` AND ${R(o, "rn", r)} <= ${B(h, r)}`, v = e.branch.onJunction === void 0 ? r`` : r` WHERE ${V(H(e.branch.onJunction), s, r)}`, ee = L(o, e.target, e.children, n, c(Ja(o)));
|
|
1040
|
-
if (ee === null) return null;
|
|
1041
|
-
let te = e.junction === void 0 ? r`` : qa(e.junction, s, r);
|
|
1042
|
-
return r`COALESCE((SELECT JSON_ARRAYAGG(${ee} ORDER BY ${R(o, "rn", r)}) FROM (SELECT ${r(o)}.*${te}, ${R(s, i.sourceKey, r)} AS ${r(`__src_${i.sourceKey}`)}, ROW_NUMBER() OVER (PARTITION BY ${R(s, i.sourceKey, r)}${m}) AS rn FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${u}${v}) AS ${r(o)} WHERE ${R(o, `__src_${i.sourceKey}`, r)} = ${R(t, "id", r)}${d}${_}), JSON_ARRAY())`;
|
|
1043
|
-
}, so = (e, t, n) => {
|
|
1044
|
-
let r = n.sql, i = n.nextAlias(), a = co(i, t.table, t.children, n);
|
|
1045
|
-
if (a === null) return null;
|
|
1046
|
-
let o = e.predicate ? r` WHERE ${V(e.predicate, i, r)}` : r``, s = T(e).length > 0 ? r` ORDER BY ${r.join(", ", !1)(T(e).map((e) => e.direction === "desc" ? r`${R(i, e.column, r)} DESC` : r`${R(i, e.column, r)} ASC`))}` : r``, c = r``, l = r``;
|
|
1047
|
-
if (e.skip !== void 0) {
|
|
1048
|
-
let t = T(e).length > 0 ? s : r` ORDER BY (SELECT NULL)`;
|
|
1049
|
-
l = e.take === void 0 ? r`${t} OFFSET ${B(e.skip, r)} ROWS` : r`${t} OFFSET ${B(e.skip, r)} ROWS FETCH NEXT ${B(e.take, r)} ROWS ONLY`;
|
|
1050
|
-
} else e.take !== void 0 && (c = r`TOP ${B(e.take, r)} `);
|
|
1051
|
-
let u = e.skip === void 0 ? s : r``;
|
|
1052
|
-
return r`SELECT ${c}(SELECT ${a} FOR JSON PATH, INCLUDE_NULL_VALUES, WITHOUT_ARRAY_WRAPPER) AS ${r("__row")} FROM ${r(t.table.tableName)} AS ${r(i)}${o}${u}${l}`;
|
|
1053
|
-
}, co = (e, t, n, r, i) => {
|
|
1054
|
-
let a = r.sql, o = [];
|
|
1055
|
-
for (let n of C(t)) o.push(a`${R(e, n, a)} AS ${a(n)}`);
|
|
1056
|
-
if (i !== void 0) for (let e of i.projection.present) o.push(a`${R(i.source.alias, i.source.physical(e), a)} AS ${lo(`_junction.${e}`, a)}`);
|
|
1057
|
-
for (let t of n) {
|
|
1058
|
-
let n = uo(t, e, r);
|
|
1059
|
-
if (n === null) return null;
|
|
1060
|
-
o.push(n);
|
|
1061
|
-
}
|
|
1062
|
-
return a.join(", ", !1)(o);
|
|
1063
|
-
}, lo = (e, t) => t.unsafe(`[${e.replace(/]/g, "]]")}]`), uo = (e, t, n) => {
|
|
1064
|
-
switch (e.relation.kind) {
|
|
1065
|
-
case "one": return F(e) ? mo(Sa(e), t, n) : fo(e, t, n);
|
|
1066
|
-
case "many": return mo(e, t, n);
|
|
1067
|
-
case "manyToMany": return ho(e, t, n);
|
|
1068
|
-
}
|
|
1069
|
-
}, fo = (e, t, n) => {
|
|
1070
|
-
let r = n.sql, i = n.nextAlias(), a = co(i, e.target, e.children, n);
|
|
1071
|
-
if (a === null) return null;
|
|
1072
|
-
let o = e.fkSide === "source" ? r`${R(i, "id", r)} = ${R(t, e.foreignKey, r)}` : r`${R(i, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}`;
|
|
1073
|
-
return r`JSON_QUERY((SELECT TOP 1 ${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${o} FOR JSON PATH, INCLUDE_NULL_VALUES, WITHOUT_ARRAY_WRAPPER)) AS ${r(e.relationName)}`;
|
|
1074
|
-
}, po = (e, t, n) => {
|
|
1075
|
-
if (e.offset !== void 0) {
|
|
1076
|
-
let r = e.orderBy && e.orderBy.length > 0 ? t : n` ORDER BY (SELECT NULL)`, i = e.limit === void 0 ? n`${r} OFFSET ${B(e.offset, n)} ROWS` : n`${r} OFFSET ${B(e.offset, n)} ROWS FETCH NEXT ${B(e.limit, n)} ROWS ONLY`;
|
|
1077
|
-
return {
|
|
1078
|
-
top: n``,
|
|
1079
|
-
pagination: i,
|
|
1080
|
-
finalOrder: n``
|
|
1081
|
-
};
|
|
1082
|
-
}
|
|
1083
|
-
return {
|
|
1084
|
-
top: e.limit === void 0 ? n`` : n`TOP ${B(e.limit, n)} `,
|
|
1085
|
-
pagination: n``,
|
|
1086
|
-
finalOrder: t
|
|
1087
|
-
};
|
|
1088
|
-
}, mo = (e, t, n) => {
|
|
1089
|
-
let r = n.sql, i = n.nextAlias(), a = co(i, e.target, e.children, n);
|
|
1090
|
-
if (a === null) return null;
|
|
1091
|
-
let o = e.branch.where === void 0 ? r`` : r` AND ${V(e.branch.where, i, r)}`, s = I(i, e.branch.orderBy, r), { top: c, pagination: l, finalOrder: u } = po(e.branch, s, r);
|
|
1092
|
-
return r`ISNULL(JSON_QUERY((SELECT ${c}${a} FROM ${r(e.target.tableName)} AS ${r(i)} WHERE ${R(i, e.foreignKey, r)} = ${R(t, e.sourceKey, r)}${o}${u}${l} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
|
|
1093
|
-
}, ho = (e, t, n) => {
|
|
1094
|
-
let r = n.sql, i = e.relation, a = i.through(), o = n.nextAlias(), s = n.nextAlias(), c = co(o, e.target, e.children, n, e.junction === void 0 ? void 0 : {
|
|
1095
|
-
projection: e.junction,
|
|
1096
|
-
source: Ya(s)
|
|
1097
|
-
});
|
|
1098
|
-
if (c === null) return null;
|
|
1099
|
-
let l = e.branch.where === void 0 ? r`` : r` AND ${V(e.branch.where, o, r)}`, u = go(e, s, r), d = I(o, e.branch.orderBy, r), { top: f, pagination: p, finalOrder: m } = po(e.branch, d, r);
|
|
1100
|
-
return r`ISNULL(JSON_QUERY((SELECT ${f}${c} FROM ${r(a.tableName)} AS ${r(s)} INNER JOIN ${r(e.target.tableName)} AS ${r(o)} ON ${R(o, "id", r)} = ${R(s, i.targetKey, r)} WHERE ${R(s, i.sourceKey, r)} = ${R(t, "id", r)}${u}${l}${m}${p} FOR JSON PATH, INCLUDE_NULL_VALUES)), JSON_QUERY('[]')) AS ${r(e.relationName)}`;
|
|
1101
|
-
}, R = (e, t, n) => e === void 0 ? n`${n(t)}` : n`${n(e)}.${n(t)}`, z = (e, t) => t.unsafe(`'${e.replace(/'/g, "''")}'`), B = (e, t) => {
|
|
1102
|
-
if (!Number.isFinite(e) || !Number.isInteger(e) || e < 0) throw S(`literalInt: expected non-negative integer, got ${e}`);
|
|
1103
|
-
return t.unsafe(String(e));
|
|
1104
|
-
}, V = (e, t, n) => {
|
|
1105
|
-
let r = _o(e, t);
|
|
1106
|
-
return y(r, n);
|
|
1107
|
-
}, go = (e, t, n, r = !1) => {
|
|
1108
|
-
let i = e.branch.onJunction;
|
|
1109
|
-
return i === void 0 ? n`` : n` AND ${V(r ? H(i) : i, t, n)}`;
|
|
1110
|
-
}, _o = (e, t) => {
|
|
1111
|
-
if ("not" in e) return { not: _o(e.not, t) };
|
|
1112
|
-
if ("and" in e) return { and: e.and.map((e) => _o(e, t)) };
|
|
1113
|
-
if ("or" in e) return { or: e.or.map((e) => _o(e, t)) };
|
|
1114
|
-
if (e.op === "subquery-in" || e.op === "subquery-not-in") {
|
|
1115
|
-
let n = e;
|
|
1116
|
-
return {
|
|
1117
|
-
...n,
|
|
1118
|
-
column: `${t}.${n.column}`
|
|
1119
|
-
};
|
|
1120
|
-
}
|
|
1121
|
-
if (e.op === "exists" || e.op === "not-exists") return e;
|
|
1122
|
-
let n = e;
|
|
1123
|
-
return {
|
|
1124
|
-
...n,
|
|
1125
|
-
column: `${t}.${n.column}`,
|
|
1126
|
-
...l(n.value) ? { value: xr(`${t}.${n.value.column}`) } : {}
|
|
1127
|
-
};
|
|
1128
|
-
}, H = (e) => {
|
|
1129
|
-
if ("not" in e) return { not: H(e.not) };
|
|
1130
|
-
if ("and" in e) return { and: e.and.map((e) => H(e)) };
|
|
1131
|
-
if ("or" in e) return { or: e.or.map((e) => H(e)) };
|
|
1132
|
-
if (e.op === "subquery-in" || e.op === "subquery-not-in" || e.op === "exists" || e.op === "not-exists") return e;
|
|
1133
|
-
let t = e;
|
|
1134
|
-
return {
|
|
1135
|
-
...t,
|
|
1136
|
-
value: Qe(t.value)
|
|
1137
|
-
};
|
|
1138
|
-
}, vo = Symbol.for("@voltro/database/coreTablesRegistry"), yo = globalThis, bo = yo[vo] ?? (yo[vo] = {}), xo = (e) => {
|
|
1139
|
-
e.actors !== void 0 && (bo.actors = e.actors), e.tenants !== void 0 && (bo.tenants = e.tenants);
|
|
1140
|
-
}, So = (e, t) => () => {
|
|
1141
|
-
let n = e();
|
|
1142
|
-
if (n === void 0) throw Error(`core '${t}' table not registered; expected the framework CLI or your migrate step to call registerCoreTables({ ${t}: () => ${t}Table }) before the database handle is constructed`);
|
|
1143
|
-
return n();
|
|
1144
|
-
}, Co = () => So(() => bo.actors, "actors"), wo = () => So(() => bo.tenants, "tenants"), To = b("actors", {
|
|
1145
|
-
id: dt(),
|
|
1146
|
-
kind: x().oneOf([
|
|
1147
|
-
"user",
|
|
1148
|
-
"serviceAccount",
|
|
1149
|
-
"apiKey",
|
|
1150
|
-
"system"
|
|
1151
|
-
]).safe(),
|
|
1152
|
-
displayName: x().nullable().sensitive("fullName"),
|
|
1153
|
-
createdAt: w().default("now")
|
|
1154
|
-
}), Eo = (e, t) => ({
|
|
1155
|
-
...t,
|
|
1156
|
-
...e,
|
|
1157
|
-
origin: e.origin ?? "injected"
|
|
1158
|
-
}), Do = (e, t, n = {}) => ({
|
|
1159
|
-
table: e,
|
|
1160
|
-
op: "insert",
|
|
1161
|
-
old: null,
|
|
1162
|
-
new: t,
|
|
1163
|
-
...n
|
|
1164
|
-
}), Oo = (e, t, n, r = {}) => ({
|
|
1165
|
-
table: e,
|
|
1166
|
-
op: "update",
|
|
1167
|
-
old: t,
|
|
1168
|
-
new: n,
|
|
1169
|
-
...r
|
|
1170
|
-
}), ko = (e, t, n = {}) => ({
|
|
1171
|
-
table: e,
|
|
1172
|
-
op: "delete",
|
|
1173
|
-
old: t,
|
|
1174
|
-
new: null,
|
|
1175
|
-
...n
|
|
1176
|
-
}), Ao = (e, t, n = {}) => {
|
|
1177
|
-
let { at: r = "2026-01-01T00:00:00.000Z", column: i = "deletedAt", ...a } = n;
|
|
1178
|
-
return {
|
|
1179
|
-
table: e,
|
|
1180
|
-
op: "update",
|
|
1181
|
-
old: {
|
|
1182
|
-
...t,
|
|
1183
|
-
[i]: null
|
|
1184
|
-
},
|
|
1185
|
-
new: {
|
|
1186
|
-
...t,
|
|
1187
|
-
[i]: r
|
|
1188
|
-
},
|
|
1189
|
-
...a
|
|
1190
|
-
};
|
|
1191
|
-
}, jo = Symbol.for("voltro.database.committedChanges"), Mo = globalThis, No = Mo[jo] ??= /* @__PURE__ */ new WeakMap(), Po = (e, t) => {
|
|
1192
|
-
let n = {};
|
|
1193
|
-
for (let t of e) No.set(t, n);
|
|
1194
|
-
try {
|
|
1195
|
-
for (let n of e) t(n);
|
|
1196
|
-
} finally {
|
|
1197
|
-
for (let t of e) No.delete(t);
|
|
1198
|
-
}
|
|
1199
|
-
}, Fo = (e) => No.get(e), Io = (e) => e == null ? "null" : e instanceof Date ? JSON.stringify(e.toISOString()) : typeof e == "bigint" ? JSON.stringify(e.toString()) : Array.isArray(e) ? `[${e.map(Io).join(",")}]` : typeof e == "object" ? `{${Object.entries(e).filter(([, e]) => e !== void 0).sort(([e], [t]) => e < t ? -1 : +(e > t)).map(([e, t]) => `${JSON.stringify(e)}:${Io(t)}`).join(",")}}` : JSON.stringify(e) ?? "null", Lo = (e) => Ir("sha256").update([
|
|
1200
|
-
e.pipe,
|
|
1201
|
-
e.op,
|
|
1202
|
-
e.key,
|
|
1203
|
-
Io(e.next),
|
|
1204
|
-
Io(e.prev)
|
|
1205
|
-
].join("\0")).digest("hex").slice(0, 32), Ro = (e, t) => `${e}:${t}`, zo = (e) => {
|
|
1206
|
-
let t = e.lastIndexOf(":");
|
|
1207
|
-
if (t <= 0) return null;
|
|
1208
|
-
let n = Number(e.slice(t + 1));
|
|
1209
|
-
return !Number.isInteger(n) || n < 0 ? null : {
|
|
1210
|
-
digest: e.slice(0, t),
|
|
1211
|
-
occurrence: n
|
|
1212
|
-
};
|
|
1213
|
-
}, Bo = class {
|
|
1214
|
-
#e = /* @__PURE__ */ new Map();
|
|
1215
|
-
#t;
|
|
1216
|
-
#n;
|
|
1217
|
-
constructor(e) {
|
|
1218
|
-
this.#t = e.windowMs, this.#n = Math.max(1, e.maxEntries);
|
|
1219
|
-
}
|
|
1220
|
-
get size() {
|
|
1221
|
-
return this.#e.size;
|
|
1222
|
-
}
|
|
1223
|
-
next(e, t) {
|
|
1224
|
-
let n = this.#e.get(e);
|
|
1225
|
-
if (n === void 0) return this.#e.set(e, {
|
|
1226
|
-
count: 1,
|
|
1227
|
-
lastMs: t
|
|
1228
|
-
}), this.#r(), 0;
|
|
1229
|
-
n.lastMs = t;
|
|
1230
|
-
let r = n.count;
|
|
1231
|
-
return n.count += 1, this.#e.delete(e), this.#e.set(e, n), r;
|
|
1232
|
-
}
|
|
1233
|
-
seedFromChangeKeys(e, t) {
|
|
1234
|
-
for (let n of e) {
|
|
1235
|
-
let e = zo(n);
|
|
1236
|
-
if (e === null) continue;
|
|
1237
|
-
let r = this.#e.get(e.digest), i = Math.max(r?.count ?? 0, e.occurrence + 1);
|
|
1238
|
-
this.#e.set(e.digest, {
|
|
1239
|
-
count: i,
|
|
1240
|
-
lastMs: r?.lastMs ?? t
|
|
1241
|
-
});
|
|
1242
|
-
}
|
|
1243
|
-
this.#r();
|
|
1244
|
-
}
|
|
1245
|
-
prune(e) {
|
|
1246
|
-
let t = e - this.#t;
|
|
1247
|
-
for (let [e, n] of this.#e) n.lastMs < t && this.#e.delete(e);
|
|
1248
|
-
}
|
|
1249
|
-
#r() {
|
|
1250
|
-
for (; this.#e.size > this.#n;) {
|
|
1251
|
-
let e = this.#e.keys().next();
|
|
1252
|
-
if (e.done === !0) return;
|
|
1253
|
-
this.#e.delete(e.value);
|
|
1254
|
-
}
|
|
1255
|
-
}
|
|
1256
|
-
}, Vo = "VOLTRO_CHANGE_CLAIMS_TTL_HOURS", Ho = 1, Uo = (e = process.env) => {
|
|
1257
|
-
let t = Number(e[Vo]);
|
|
1258
|
-
return (Number.isFinite(t) && t > 0 ? t : 1) * 2 * 36e5;
|
|
1259
|
-
}, Wo = new Lr(), Go = (e, t) => Wo.run(e, t), Ko = () => Wo.getStore(), qo = (e) => {
|
|
1260
|
-
let t = e ?? Wo.getStore();
|
|
1261
|
-
return t === void 0 ? {} : {
|
|
1262
|
-
...t.traceId === void 0 ? {} : { traceId: t.traceId },
|
|
1263
|
-
...t.subjectId === void 0 ? {} : { subjectId: t.subjectId },
|
|
1264
|
-
...t.procedure === void 0 ? {} : { procedure: t.procedure },
|
|
1265
|
-
...t.via === void 0 ? {} : { via: t.via }
|
|
1266
|
-
};
|
|
1267
|
-
}, Jo = (e) => {
|
|
1268
|
-
let t = Wo.getStore();
|
|
1269
|
-
return t === void 0 ? e(void 0) : Wo.run(t, () => e(t));
|
|
1270
|
-
}, Yo = 3e4, Xo = 1e4, U = /* @__PURE__ */ new Map(), W = [], Zo = (e, t) => {
|
|
1271
|
-
let n = W[e];
|
|
1272
|
-
W[e] = W[t], W[t] = n, W[e].heapIndex = e, n.heapIndex = t;
|
|
1273
|
-
}, Qo = (e) => {
|
|
1274
|
-
for (; e > 0;) {
|
|
1275
|
-
let t = Math.floor((e - 1) / 2);
|
|
1276
|
-
if (W[t].at <= W[e].at) break;
|
|
1277
|
-
Zo(t, e), e = t;
|
|
1278
|
-
}
|
|
1279
|
-
return e;
|
|
1280
|
-
}, $o = (e) => {
|
|
1281
|
-
for (; e * 2 + 1 < W.length;) {
|
|
1282
|
-
let t = e * 2 + 1;
|
|
1283
|
-
if (t + 1 < W.length && W[t + 1].at < W[t].at && t++, W[e].at <= W[t].at) break;
|
|
1284
|
-
Zo(e, t), e = t;
|
|
1285
|
-
}
|
|
1286
|
-
}, es = (e) => {
|
|
1287
|
-
let t = U.get(e.key);
|
|
1288
|
-
e.previous ? e.previous.next = e.next : e.next && (t.head = e.next), e.next ? e.next.previous = e.previous : e.previous && (t.tail = e.previous), !e.previous && !e.next && U.delete(e.key);
|
|
1289
|
-
let n = e.heapIndex, r = W.pop();
|
|
1290
|
-
n < W.length && (W[n] = r, r.heapIndex = n, $o(Qo(n)));
|
|
1291
|
-
}, ts = (e, t, n) => `${e}\u0000${t}\u0000${String(n)}`, ns = (e) => {
|
|
1292
|
-
for (; W[0] !== void 0 && e - W[0].at >= Yo;) es(W[0]);
|
|
1293
|
-
}, rs = (e, t) => {
|
|
1294
|
-
if (t.traceId === void 0 && t.subjectId === void 0 && t.procedure === void 0 && t.via === void 0) return;
|
|
1295
|
-
let n = Date.now();
|
|
1296
|
-
if (W.length >= Xo && ns(n), W.length >= Xo) return;
|
|
1297
|
-
let r = U.get(e), i = {
|
|
1298
|
-
key: e,
|
|
1299
|
-
attribution: t,
|
|
1300
|
-
at: n,
|
|
1301
|
-
heapIndex: W.length,
|
|
1302
|
-
previous: r?.tail
|
|
1303
|
-
};
|
|
1304
|
-
r ? (r.tail.next = i, r.tail = i) : U.set(e, {
|
|
1305
|
-
head: i,
|
|
1306
|
-
tail: i
|
|
1307
|
-
}), W.push(i), Qo(i.heapIndex);
|
|
1308
|
-
}, is = (e) => {
|
|
1309
|
-
let t = U.get(e)?.head;
|
|
1310
|
-
if (t !== void 0 && (es(t), !(Date.now() - t.at >= Yo))) return t.attribution;
|
|
1311
|
-
}, as = (e) => U.has(e), G = /* @__PURE__ */ new Map(), os = /* @__PURE__ */ new Map(), ss = /* @__PURE__ */ new Map(), cs = 250, ls = (e) => {
|
|
1312
|
-
let t = os.get(e);
|
|
1313
|
-
if (t === void 0) return;
|
|
1314
|
-
os.delete(e);
|
|
1315
|
-
let n = ss.get(e);
|
|
1316
|
-
n !== void 0 && (clearTimeout(n), ss.delete(e));
|
|
1317
|
-
for (let e of t) e();
|
|
1318
|
-
}, us = (e) => {
|
|
1319
|
-
G.set(e, (G.get(e) ?? 0) + 1);
|
|
1320
|
-
}, ds = (e) => {
|
|
1321
|
-
let t = (G.get(e) ?? 0) - 1;
|
|
1322
|
-
if (t > 0) {
|
|
1323
|
-
G.set(e, t);
|
|
1324
|
-
return;
|
|
1325
|
-
}
|
|
1326
|
-
G.delete(e), ls(e);
|
|
1327
|
-
}, fs = (e, t, n, r) => {
|
|
1328
|
-
let i = n == null ? void 0 : ts(e, t, n), a = () => r(i === void 0 ? void 0 : is(i));
|
|
1329
|
-
if (i === void 0) {
|
|
1330
|
-
a();
|
|
1331
|
-
return;
|
|
1332
|
-
}
|
|
1333
|
-
if (as(i)) {
|
|
1334
|
-
a();
|
|
1335
|
-
return;
|
|
1336
|
-
}
|
|
1337
|
-
let o = os.get(e);
|
|
1338
|
-
if (o === void 0 && (G.get(e) ?? 0) === 0) {
|
|
1339
|
-
a();
|
|
1340
|
-
return;
|
|
1341
|
-
}
|
|
1342
|
-
if (o !== void 0) {
|
|
1343
|
-
o.push(a);
|
|
1344
|
-
return;
|
|
1345
|
-
}
|
|
1346
|
-
os.set(e, [a]);
|
|
1347
|
-
let s = setTimeout(() => ls(e), cs);
|
|
1348
|
-
typeof s == "object" && typeof s.unref == "function" && s.unref(), ss.set(e, s);
|
|
1349
|
-
}, ps = () => {
|
|
1350
|
-
U.clear(), W.length = 0, G.clear();
|
|
1351
|
-
for (let e of ss.values()) clearTimeout(e);
|
|
1352
|
-
ss.clear(), os.clear();
|
|
1353
|
-
}, ms = () => W.length, hs = 64, gs = "\0", _s = 32, vs = (e, ...t) => `${e}_${Ir("sha256").update(t.map(String).join(gs)).digest("hex").slice(0, _s)}`, ys = (e) => e.length + 1 + _s, K = /* @__PURE__ */ new Map(), bs = (e, t) => {
|
|
1354
|
-
K.set(e, {
|
|
1355
|
-
recorder: t.recorder,
|
|
1356
|
-
tables: new Set(t.tables),
|
|
1357
|
-
ownTables: new Set(t.ownTables)
|
|
1358
|
-
});
|
|
1359
|
-
}, xs = (e) => {
|
|
1360
|
-
K.delete(e);
|
|
1361
|
-
}, Ss = () => K.clear(), Cs = new Lr(), ws = (e) => Cs.run({ n: 1 }, e), Ts = (e) => E.suspend(() => {
|
|
1362
|
-
let t = Cs.getStore();
|
|
1363
|
-
if (t !== void 0) return t.n += 1, E.ensuring(e, E.sync(() => {
|
|
1364
|
-
--t.n;
|
|
1365
|
-
}));
|
|
1366
|
-
let n = { n: 1 };
|
|
1367
|
-
return Cs.enterWith(n), E.ensuring(e, E.sync(() => {
|
|
1368
|
-
--n.n;
|
|
1369
|
-
}));
|
|
1370
|
-
}), Es = () => (Cs.getStore()?.n ?? 0) > 0, Ds = (e) => {
|
|
1371
|
-
if (K.size === 0 || (Cs.getStore()?.n ?? 0) > 0) return !1;
|
|
1372
|
-
for (let t of K.values()) if (!t.ownTables.has(e) && t.tables.has(e)) return !0;
|
|
1373
|
-
return !1;
|
|
1374
|
-
}, Os = async (e, t) => {
|
|
1375
|
-
if (K.size !== 0) {
|
|
1376
|
-
for (let [n, r] of K.entries()) if (!r.ownTables.has(t.table) && r.tables.has(t.table)) try {
|
|
1377
|
-
await r.recorder(e, t);
|
|
1378
|
-
} catch (e) {
|
|
1379
|
-
let r = Wt(e);
|
|
1380
|
-
throw r === void 0 ? e : Error(`write recorder '${n}' failed while recording a ${t.op} on '${t.table}': ${r}`, { cause: e });
|
|
1381
|
-
}
|
|
1382
|
-
}
|
|
1383
|
-
}, ks = D.exponentialBoundaries({
|
|
1384
|
-
start: 5e-4,
|
|
1385
|
-
factor: 2,
|
|
1386
|
-
count: 16
|
|
1387
|
-
}), As = D.counter("voltro_db_queries_total", { description: "Database operations executed, by dialect and operation kind." }), js = D.histogram("voltro_db_query_duration_seconds", {
|
|
1388
|
-
boundaries: ks,
|
|
1389
|
-
description: "Database operation duration in seconds, by dialect and operation kind."
|
|
1390
|
-
}), Ms = D.counter("voltro_db_errors_total", { description: "Database operations that threw, by dialect and operation kind." }), Ns = D.gauge("voltro_db_operations_in_flight", { description: "Database operations currently executing, by dialect. An upper bound on connections the framework holds; NOT the driver pool's waiting count." }), Ps = D.counter("voltro_db_eager_fallback_total", { description: "Eager-load queries that degraded from the single-roundtrip JSON-agg path to the multi-query walker, by dialect and reason." }), Fs = Ar.empty(), Is = /* @__PURE__ */ new Map(), Ls = /* @__PURE__ */ new Map(), Rs = /* @__PURE__ */ new Map(), zs = (e, t) => {
|
|
1391
|
-
let n = `${e}\u0000${t}`, r = Is.get(n);
|
|
1392
|
-
if (r !== void 0) return r;
|
|
1393
|
-
let i = (n) => D.withAttributes(D.withAttributes(n, { dialect: e }), { op: t }), a = {
|
|
1394
|
-
count: i(As),
|
|
1395
|
-
duration: i(js),
|
|
1396
|
-
errors: i(Ms)
|
|
1397
|
-
};
|
|
1398
|
-
return Is.set(n, a), a;
|
|
1399
|
-
}, Bs = () => {
|
|
1400
|
-
Is.clear(), Ls.clear(), Rs.clear();
|
|
1401
|
-
}, Vs = () => Is.size + Ls.size + Rs.size, Hs = /* @__PURE__ */ new Map(), Us = (e, t) => {
|
|
1402
|
-
let n = Math.max(0, (Hs.get(e) ?? 0) + t);
|
|
1403
|
-
n === 0 ? Hs.delete(e) : Hs.set(e, n);
|
|
1404
|
-
let r = Ls.get(e);
|
|
1405
|
-
r === void 0 && (r = D.withAttributes(Ns, { dialect: e }), Ls.set(e, r)), r.updateUnsafe(n, Fs);
|
|
1406
|
-
}, Ws = (e) => Hs.get(e) ?? 0, Gs = (e) => {
|
|
1407
|
-
let t = zs(String(e.dialect), e.op);
|
|
1408
|
-
t.count.updateUnsafe(1, Fs), t.duration.updateUnsafe(e.durationMs / 1e3, Fs), e.status === "error" && t.errors.updateUnsafe(1, Fs);
|
|
1409
|
-
}, Ks = async (e, t, n) => {
|
|
1410
|
-
let r = performance.now(), i = String(e);
|
|
1411
|
-
Us(i, 1);
|
|
1412
|
-
let a = "ok";
|
|
1413
|
-
try {
|
|
1414
|
-
return await n();
|
|
1415
|
-
} catch (e) {
|
|
1416
|
-
throw a = "error", e;
|
|
1417
|
-
} finally {
|
|
1418
|
-
Us(i, -1), Gs({
|
|
1419
|
-
dialect: e,
|
|
1420
|
-
op: t,
|
|
1421
|
-
durationMs: performance.now() - r,
|
|
1422
|
-
status: a
|
|
1423
|
-
});
|
|
1424
|
-
}
|
|
1425
|
-
}, qs = 3e5, Js = (e) => {
|
|
1426
|
-
if (e == null || e === "") return;
|
|
1427
|
-
let t = Number(e);
|
|
1428
|
-
return Number.isFinite(t) && t >= 0 ? Math.floor(t) : void 0;
|
|
1429
|
-
}, Ys = (e, t = process.env) => Js(t.VOLTRO_DB_EAGER_FALLBACK_WARN_INTERVAL_MS) ?? Js(e) ?? 3e5, Xs = (e, t = {}) => {
|
|
1430
|
-
let n = Ys(t.warnIntervalMs), r = t.now ?? (() => Date.now()), i = /* @__PURE__ */ new Map();
|
|
1431
|
-
return (t) => {
|
|
1432
|
-
let a = `${t.dialect} ${t.reason}`, o = Rs.get(a);
|
|
1433
|
-
o === void 0 && (o = D.withAttributes(D.withAttributes(Ps, { dialect: String(t.dialect) }), { reason: t.reason }), Rs.set(a, o)), o.updateUnsafe(1, Fs);
|
|
1434
|
-
let s = `${t.table}\u0000${t.reason}`, c = i.get(s), l = c === void 0 || n > 0 && r() - c >= n, u = {
|
|
1435
|
-
table: t.table,
|
|
1436
|
-
dialect: String(t.dialect),
|
|
1437
|
-
reason: t.reason,
|
|
1438
|
-
metric: "voltro_db_eager_fallback_total",
|
|
1439
|
-
...t.error === void 0 ? {} : { err: t.error }
|
|
1440
|
-
};
|
|
1441
|
-
if (!l) {
|
|
1442
|
-
e.debug("eager-load is still running on the walker (rate-limited; the counter is not)", u);
|
|
1443
|
-
return;
|
|
1444
|
-
}
|
|
1445
|
-
i.set(s, r()), e.warn(t.reason === "execute-failed" ? "eager-load JSON-agg statement FAILED and was re-run on the multi-query walker — this query pays both paths on every call. Counted as voltro_db_eager_fallback_total{reason=\"execute-failed\"}." : "eager-load could not be compiled to a single JSON-agg roundtrip and is running on the multi-query walker — one round trip per relation level, on every call. Counted as voltro_db_eager_fallback_total{reason=\"not-compilable\"}.", u);
|
|
1446
|
-
};
|
|
1447
|
-
}, Zs = (e) => {
|
|
1448
|
-
if (Mr.isSuccess(e)) return e.value;
|
|
1449
|
-
let t = kr.squash(e.cause);
|
|
1450
|
-
throw e.cause.reasons.length > 1 && typeof t == "object" && t && Object.isExtensible(t) && Object.defineProperty(t, "voltroCause", {
|
|
1451
|
-
value: e.cause,
|
|
1452
|
-
enumerable: !1,
|
|
1453
|
-
configurable: !0
|
|
1454
|
-
}), t;
|
|
1455
|
-
}, Qs = "10 millis", $s = 3, ec = (e) => Nr.max([Nr.exponential(Qs), Nr.recurs($s)]).pipe(Nr.while(({ input: t }) => e(t))), tc = zr.TransactionConnection(0), nc = /* @__PURE__ */ new WeakMap(), rc = (e, t, n) => {
|
|
1456
|
-
let r = nc.get(n);
|
|
1457
|
-
return r === void 0 ? E.provideService(e, t, n) : E.provideContext(e, r);
|
|
1458
|
-
}, ic = async (e) => {
|
|
1459
|
-
let t = 0, n = E.suspend(() => {
|
|
1460
|
-
let n = ++t;
|
|
1461
|
-
return e.withTransaction(E.flatMap(E.serviceOption(e.transactionService), (t) => {
|
|
1462
|
-
if (O.isNone(t)) return E.fail(/* @__PURE__ */ Error(`${e.label}: TransactionConnection unexpectedly missing inside withTransaction.`));
|
|
1463
|
-
let r = t.value, i = E.tryPromise({
|
|
1464
|
-
try: () => e.body(r, n),
|
|
1465
|
-
catch: (e) => e
|
|
1466
|
-
});
|
|
1467
|
-
return E.flatMap(E.context(), (t) => (nc.set(r, t), e.prepare === void 0 ? i : E.flatMap(e.prepare(r), () => i)));
|
|
1468
|
-
})).pipe(E.catchDefect((t) => e.isRetryable(t) ? E.fail(t) : E.die(t)));
|
|
1469
|
-
}).pipe(E.retry(ec(e.isRetryable)), E.withSpan(e.span.name, { attributes: { ...e.span.attributes } }));
|
|
1470
|
-
return Ks(e.dialect, "transaction", async () => Zs(await e.runPromiseExit(e.wrapProgram === void 0 ? n : e.wrapProgram(n))));
|
|
1471
|
-
}, ac = class extends Error {
|
|
1472
|
-
swallowed;
|
|
1473
|
-
_tag = "TransactionAborted";
|
|
1474
|
-
constructor(e, t) {
|
|
1475
|
-
super(`${e}: a statement failed inside this transaction and the error was caught, but the database had already aborted the transaction — every later statement was refused, and COMMIT would have rolled back ALL of its writes, including the ones that succeeded. Nothing was committed.
|
|
1476
|
-
the caught failure: ${lc(t)}\n to tolerate a failing statement and keep the rest, run it inside \`tx.savepoint(() => …)\` — only that statement is rolled back. To keep all-or-nothing, let the error propagate.`, { cause: t }), this.swallowed = t, this.name = "TransactionAbortedError";
|
|
1477
|
-
}
|
|
1478
|
-
}, oc = (e, t = "transactional()") => {
|
|
1479
|
-
let n = 0, r, i = (e) => {
|
|
1480
|
-
r === void 0 && (r = { error: e });
|
|
1481
|
-
};
|
|
1482
|
-
return {
|
|
1483
|
-
track: (a) => r === void 0 ? n > 0 ? a() : a().catch((t) => {
|
|
1484
|
-
throw e(t) && i(t), t;
|
|
1485
|
-
}) : Promise.reject(new ac(t, r.error)),
|
|
1486
|
-
inSavepoint: async (e) => {
|
|
1487
|
-
n++;
|
|
1488
|
-
try {
|
|
1489
|
-
return await e();
|
|
1490
|
-
} finally {
|
|
1491
|
-
n--;
|
|
1492
|
-
}
|
|
1493
|
-
},
|
|
1494
|
-
record: i,
|
|
1495
|
-
abortedBy: () => r
|
|
1496
|
-
};
|
|
1497
|
-
}, sc = async (e, t) => {
|
|
1498
|
-
let { tracker: n, name: r, exec: i, spelling: a } = e;
|
|
1499
|
-
await n.track(() => i(a === "mssql" ? `SAVE TRANSACTION ${r}` : `SAVEPOINT ${r}`));
|
|
1500
|
-
try {
|
|
1501
|
-
let e = await n.inSavepoint(t);
|
|
1502
|
-
return a === "standard" && await n.track(() => i(`RELEASE SAVEPOINT ${r}`)), e;
|
|
1503
|
-
} catch (e) {
|
|
1504
|
-
throw await i(a === "mssql" ? `ROLLBACK TRANSACTION ${r}` : `ROLLBACK TO SAVEPOINT ${r}`).catch((e) => n.record(e)), a === "standard" && await i(`RELEASE SAVEPOINT ${r}`).catch(() => void 0), e;
|
|
1505
|
-
}
|
|
1506
|
-
}, cc = (e) => e instanceof ac || typeof e == "object" && !!e && e._tag === "TransactionAborted", lc = (e) => {
|
|
1507
|
-
for (let t of Bt(e)) {
|
|
1508
|
-
let e = t;
|
|
1509
|
-
for (let t = 0; t < 5 && typeof e == "object" && e; t++) {
|
|
1510
|
-
let t = e.code, n = e.message;
|
|
1511
|
-
if (typeof t == "string" && typeof n == "string") return `${n} (${t})`;
|
|
1512
|
-
e = e.cause;
|
|
1513
|
-
}
|
|
1514
|
-
}
|
|
1515
|
-
return e instanceof Error ? e.message : String(e);
|
|
1516
|
-
}, uc = async (e) => {
|
|
1517
|
-
let t = Ko(), n = t === void 0 ? (e) => e() : (e) => Go(t, e), r = await ic({
|
|
1518
|
-
...e,
|
|
1519
|
-
body: (r) => {
|
|
1520
|
-
let i = e.makeView(r, t);
|
|
1521
|
-
return n(() => e.work(i)).then((t) => {
|
|
1522
|
-
let n = i.abortedBy?.();
|
|
1523
|
-
if (n !== void 0) throw e.isRetryable(n.error) ? n.error : new ac(e.label, n.error);
|
|
1524
|
-
return {
|
|
1525
|
-
result: t,
|
|
1526
|
-
view: i
|
|
1527
|
-
};
|
|
1528
|
-
}, (t) => {
|
|
1529
|
-
let n = i.abortedBy?.();
|
|
1530
|
-
throw n !== void 0 && e.isRetryable(n.error) ? n.error : t;
|
|
1531
|
-
});
|
|
1532
|
-
}
|
|
1533
|
-
});
|
|
1534
|
-
return r.view.commitEvents(), r.result;
|
|
1535
|
-
}, dc = /* @__PURE__ */ new Set([
|
|
1536
|
-
"1213",
|
|
1537
|
-
"ER_LOCK_DEADLOCK",
|
|
1538
|
-
"1205",
|
|
1539
|
-
"ER_LOCK_WAIT_TIMEOUT",
|
|
1540
|
-
"1020",
|
|
1541
|
-
"ER_CHECKREAD"
|
|
1542
|
-
]), fc = /* @__PURE__ */ new Set(["40001", "40P01"]), pc = /* @__PURE__ */ new Set(["1205"]), mc = /* @__PURE__ */ new Set([
|
|
1543
|
-
"SQLITE_BUSY",
|
|
1544
|
-
"5",
|
|
1545
|
-
"SQLITE_BUSY_SNAPSHOT",
|
|
1546
|
-
"517",
|
|
1547
|
-
"SQLITE_LOCKED",
|
|
1548
|
-
"6"
|
|
1549
|
-
]), hc = /write-write conflict|write-read conflict|database is locked|table is locked|database is busy/i, gc = /* @__PURE__ */ new Set([
|
|
1550
|
-
1213,
|
|
1551
|
-
1205,
|
|
1552
|
-
1020
|
|
1553
|
-
]), _c = /* @__PURE__ */ new Set([
|
|
1554
|
-
...dc,
|
|
1555
|
-
...fc,
|
|
1556
|
-
...pc,
|
|
1557
|
-
...mc
|
|
1558
|
-
]), vc = (e) => Bt(e).some(yc), yc = (e) => {
|
|
1559
|
-
let t = e;
|
|
1560
|
-
for (let e = 0; e < 6 && typeof t == "object" && t; e++) {
|
|
1561
|
-
let e = t;
|
|
1562
|
-
if (typeof e.errno == "number" && gc.has(e.errno) || typeof e.number == "number" && pc.has(String(e.number)) || typeof e.code == "string" && _c.has(e.code) || typeof e.sqlState == "string" && fc.has(e.sqlState) || typeof e.message == "string" && hc.test(e.message)) return !0;
|
|
1563
|
-
t = e.cause;
|
|
1564
|
-
}
|
|
1565
|
-
return !1;
|
|
1566
|
-
}, bc = "voltro/expires", xc = () => ce({
|
|
1567
|
-
id: bc,
|
|
1568
|
-
fields: { expiresAt: w().nullable() },
|
|
1569
|
-
behaviors: { defaultWhere: () => "expiresAt IS NULL OR expiresAt > now()" }
|
|
1570
|
-
}), Sc = "voltro/localFirst", Cc = () => ce({
|
|
1571
|
-
id: Sc,
|
|
1572
|
-
fields: {}
|
|
1573
|
-
}), wc = (e) => e.appliedMixins.some((e) => e.id === Sc), Tc = (e) => {
|
|
1574
|
-
let t = [];
|
|
1575
|
-
for (let n of Object.values(e)) wc(n) && t.push(n.tableName);
|
|
1576
|
-
return t;
|
|
1577
|
-
}, Ec = class extends jr.TaggedError("TableStreamError") {}, Dc = 1e3, Oc = (e, t, n, r) => {
|
|
1578
|
-
let i = O.match(r, {
|
|
1579
|
-
onNone: () => e.where,
|
|
1580
|
-
onSome: (n) => e.where ? Ct(e.where, Pn(t, n)) : Pn(t, n)
|
|
1581
|
-
});
|
|
1582
|
-
return {
|
|
1583
|
-
table: e.table,
|
|
1584
|
-
predicate: i,
|
|
1585
|
-
order: [{
|
|
1586
|
-
column: t,
|
|
1587
|
-
direction: "asc"
|
|
1588
|
-
}],
|
|
1589
|
-
take: n,
|
|
1590
|
-
skip: void 0,
|
|
1591
|
-
projection: e.projection,
|
|
1592
|
-
...e.includeDeleted === void 0 ? {} : { includeDeleted: e.includeDeleted },
|
|
1593
|
-
...e.crossTenant === void 0 ? {} : { crossTenant: e.crossTenant }
|
|
1594
|
-
};
|
|
1595
|
-
}, kc = (e, t) => {
|
|
1596
|
-
let n = t.pk ?? "id", r = t.chunkSize ?? Dc;
|
|
1597
|
-
return Pr.paginate(O.none(), (i) => {
|
|
1598
|
-
let a = E.tryPromise({
|
|
1599
|
-
try: () => e.query(Oc(t, n, r, i)),
|
|
1600
|
-
catch: (e) => new Ec({
|
|
1601
|
-
table: t.table,
|
|
1602
|
-
cause: e
|
|
1603
|
-
})
|
|
1604
|
-
});
|
|
1605
|
-
return (t.retry ? a.pipe(E.retry(t.retry)) : a).pipe(E.map((e) => [e, e.length === r && e.length > 0 ? O.some(O.some(e[e.length - 1][n])) : O.none()]));
|
|
1606
|
-
});
|
|
1607
|
-
}, Ac = (e) => {
|
|
1608
|
-
let t = e.alpha ?? .5;
|
|
1609
|
-
if (t < 0 || t > 1) throw Error(`hybridSearch: alpha must be in [0, 1], got ${t}`);
|
|
1610
|
-
return (n) => {
|
|
1611
|
-
let r = Array.isArray(e.vector.query) ? {
|
|
1612
|
-
column: e.vector.col,
|
|
1613
|
-
queryVector: e.vector.query,
|
|
1614
|
-
distance: e.vector.distance ?? "cosine",
|
|
1615
|
-
alpha: t
|
|
1616
|
-
} : {
|
|
1617
|
-
column: e.vector.col,
|
|
1618
|
-
queryText: e.vector.query,
|
|
1619
|
-
distance: e.vector.distance ?? "cosine",
|
|
1620
|
-
alpha: t
|
|
1621
|
-
}, i = d(n.table, e.fts.indexName, n.fullTextIndexes);
|
|
1622
|
-
return {
|
|
1623
|
-
...n,
|
|
1624
|
-
annClause: r,
|
|
1625
|
-
fullTextSearch: {
|
|
1626
|
-
indexName: e.fts.indexName,
|
|
1627
|
-
query: e.fts.query,
|
|
1628
|
-
columns: i.columns,
|
|
1629
|
-
...i.config === void 0 ? {} : { config: i.config },
|
|
1630
|
-
...i.weights === void 0 ? {} : { weights: i.weights }
|
|
1631
|
-
}
|
|
1632
|
-
};
|
|
1633
|
-
};
|
|
1634
|
-
}, jc = async (e, t) => {
|
|
1635
|
-
let n = e.as ?? "embedding", r = t.row[e.from];
|
|
1636
|
-
if (typeof r != "string" || r.length === 0) return {};
|
|
1637
|
-
let i = await t.embed(r);
|
|
1638
|
-
return { [n]: i };
|
|
1639
|
-
}, Mc = (e) => {
|
|
1640
|
-
if (!Number.isInteger(e.dimensions) || e.dimensions <= 0) throw Error(`vectorEmbedding: dimensions must be a positive integer, got ${String(e.dimensions)}.`);
|
|
1641
|
-
let t = e.as ?? "embedding", n = (t) => jc(e, t);
|
|
1642
|
-
return ce({
|
|
1643
|
-
id: "voltro/vectorEmbedding",
|
|
1644
|
-
fields: { [t]: On(e.dimensions) },
|
|
1645
|
-
...e.index === !1 ? {} : { indexes: [{
|
|
1646
|
-
fields: [t],
|
|
1647
|
-
kind: "hnsw",
|
|
1648
|
-
kindOptions: { hnsw: {
|
|
1649
|
-
...e.index?.m === void 0 ? {} : { m: e.index.m },
|
|
1650
|
-
...e.index?.efConstruction === void 0 ? {} : { efConstruction: e.index.efConstruction },
|
|
1651
|
-
distance: e.distance ?? "cosine"
|
|
1652
|
-
} }
|
|
1653
|
-
}] },
|
|
1654
|
-
behaviors: {
|
|
1655
|
-
beforeInsert: n,
|
|
1656
|
-
beforeUpdate: n
|
|
1657
|
-
}
|
|
1658
|
-
});
|
|
1659
|
-
}, Nc = 63, Pc = "br_pr", q = class extends Error {
|
|
1660
|
-
_tag = "BranchNameInvalid";
|
|
1661
|
-
constructor(e) {
|
|
1662
|
-
super(e), this.name = "BranchNameInvalid";
|
|
1663
|
-
}
|
|
1664
|
-
}, Fc = (e, t) => {
|
|
1665
|
-
if (!Number.isInteger(t) || t < 0) throw new q(`prNumber must be a non-negative integer, got ${String(t)}`);
|
|
1666
|
-
let n = ve(e);
|
|
1667
|
-
if (n.replace(/_/g, "") === "") throw new q(`app slug '${e}' has no usable identifier characters`);
|
|
1668
|
-
let r = `${Pc}${t}_${n}`;
|
|
1669
|
-
if (r.length > Nc) throw new q(`branch namespace '${r}' exceeds the ${Nc}-byte identifier limit — use a shorter app slug`);
|
|
1670
|
-
return r;
|
|
1671
|
-
}, Ic = (e) => e.startsWith(Pc), Lc = {
|
|
1672
|
-
requested: {
|
|
1673
|
-
provision: "provisioning",
|
|
1674
|
-
destroy: "destroying"
|
|
1675
|
-
},
|
|
1676
|
-
provisioning: {
|
|
1677
|
-
provisioned: "ready",
|
|
1678
|
-
fail: "failed"
|
|
1679
|
-
},
|
|
1680
|
-
ready: { destroy: "destroying" },
|
|
1681
|
-
failed: {
|
|
1682
|
-
provision: "provisioning",
|
|
1683
|
-
destroy: "destroying"
|
|
1684
|
-
},
|
|
1685
|
-
destroying: {
|
|
1686
|
-
destroyed: "destroyed",
|
|
1687
|
-
fail: "failed"
|
|
1688
|
-
},
|
|
1689
|
-
destroyed: {}
|
|
1690
|
-
}, Rc = class extends Error {
|
|
1691
|
-
from;
|
|
1692
|
-
event;
|
|
1693
|
-
_tag = "BranchTransitionInvalid";
|
|
1694
|
-
constructor(e, t) {
|
|
1695
|
-
super(`invalid branch transition: ${e} --${t}-->`), this.from = e, this.event = t, this.name = "BranchTransitionInvalid";
|
|
1696
|
-
}
|
|
1697
|
-
}, zc = (e, t) => {
|
|
1698
|
-
let n = Lc[e][t];
|
|
1699
|
-
if (n === void 0) throw new Rc(e, t);
|
|
1700
|
-
return n;
|
|
1701
|
-
}, Bc = (e, t, n, r, i = [], a = []) => {
|
|
1702
|
-
if (n === "copy" && (r === void 0 || r === "")) throw new q("seed 'copy' requires a parentNamespace to snapshot from");
|
|
1703
|
-
let o = [{
|
|
1704
|
-
kind: "create-namespace",
|
|
1705
|
-
detail: e
|
|
1706
|
-
}];
|
|
1707
|
-
for (let n of t) o.push({
|
|
1708
|
-
kind: "create-table",
|
|
1709
|
-
table: n,
|
|
1710
|
-
detail: `${e}.${n}`
|
|
1711
|
-
});
|
|
1712
|
-
for (let t of a) o.push({
|
|
1713
|
-
kind: "restore-index-name",
|
|
1714
|
-
table: t.table,
|
|
1715
|
-
detail: `${e}.${t.table} ${t.unique ? "UNIQUE " : ""}(${t.columns.join(", ")}) → ${t.name}`
|
|
1716
|
-
});
|
|
1717
|
-
if (n === "copy") for (let n of t) o.push({
|
|
1718
|
-
kind: "copy-table",
|
|
1719
|
-
table: n,
|
|
1720
|
-
detail: `${r}.${n} → ${e}.${n}`
|
|
1721
|
-
});
|
|
1722
|
-
for (let t of i) o.push({
|
|
1723
|
-
kind: "copy-foreign-key",
|
|
1724
|
-
table: t.table,
|
|
1725
|
-
detail: `${e}.${t.table}.${t.column} → ${e}.${t.targetTable}.${t.targetColumn}`
|
|
1726
|
-
});
|
|
1727
|
-
return n === "fresh" && o.push({
|
|
1728
|
-
kind: "seed",
|
|
1729
|
-
detail: `run boot seeds into ${e}`
|
|
1730
|
-
}), o;
|
|
1731
|
-
}, Vc = (e) => {
|
|
1732
|
-
if (!Ic(e)) throw new q(`refusing to plan teardown of '${e}' — not a branch namespace`);
|
|
1733
|
-
return [{
|
|
1734
|
-
kind: "drop-namespace",
|
|
1735
|
-
detail: e
|
|
1736
|
-
}];
|
|
1737
|
-
}, Hc = (e) => {
|
|
1738
|
-
if (e === void 0 || e === "") return !1;
|
|
1739
|
-
try {
|
|
1740
|
-
let t = new URL(e).hostname.toLowerCase();
|
|
1741
|
-
return /(^|\.)neon\.(tech|build)$/.test(t);
|
|
1742
|
-
} catch {
|
|
1743
|
-
return /\bneon\.(tech|build)\b/i.test(e);
|
|
1744
|
-
}
|
|
1745
|
-
}, Uc = (e) => e.prefer === void 0 ? e.seed === "copy" && Hc(e.dbUrl) ? "neon-cow" : "namespace" : e.prefer, Wc = (e, t = {}) => [{
|
|
1746
|
-
kind: "neon-branch-create",
|
|
1747
|
-
detail: `${t.parentBranch ?? "main"} → ${e} (copy-on-write)`
|
|
1748
|
-
}], Gc = (e) => {
|
|
1749
|
-
if (!Ic(e)) throw new q(`refusing to plan teardown of '${e}' — not a branch namespace`);
|
|
1750
|
-
return [{
|
|
1751
|
-
kind: "neon-branch-delete",
|
|
1752
|
-
detail: e
|
|
1753
|
-
}];
|
|
1754
|
-
}, Kc = (e) => e.mechanism === "neon-cow" ? Wc(e.branchId, e.neonParentBranch === void 0 ? {} : { parentBranch: e.neonParentBranch }) : Bc(e.branchId, e.tableNames, e.seed, e.parentNamespace, e.foreignKeys, e.indexNames), qc = (e, t) => e === "neon-cow" ? Gc(t) : Vc(t), Jc = (e, t, n) => {
|
|
1755
|
-
let r = e.filter((e) => e.state !== "destroyed" && e.state !== "destroying"), i = r.filter((e) => n - e.createdAtMs > t.ttlMs).map((e) => e.namespace), a = new Set(i);
|
|
1756
|
-
return {
|
|
1757
|
-
evict: i,
|
|
1758
|
-
rejectNew: r.filter((e) => !a.has(e.namespace)).length >= t.maxBranches
|
|
1759
|
-
};
|
|
1760
|
-
}, Yc = async (e, t) => {
|
|
1761
|
-
let n = Fc(e.appSlug, e.prNumber), r = Uc({
|
|
1762
|
-
seed: e.seed,
|
|
1763
|
-
...e.dbUrl === void 0 ? {} : { dbUrl: e.dbUrl },
|
|
1764
|
-
...e.prefer === void 0 ? {} : { prefer: e.prefer }
|
|
1765
|
-
}), i = Kc({
|
|
1766
|
-
mechanism: r,
|
|
1767
|
-
branchId: n,
|
|
1768
|
-
tableNames: e.tableNames,
|
|
1769
|
-
seed: e.seed,
|
|
1770
|
-
...e.parentNamespace === void 0 ? {} : { parentNamespace: e.parentNamespace },
|
|
1771
|
-
...e.foreignKeys === void 0 ? {} : { foreignKeys: e.foreignKeys },
|
|
1772
|
-
...e.indexNames === void 0 ? {} : { indexNames: e.indexNames },
|
|
1773
|
-
...e.neonParentBranch === void 0 ? {} : { neonParentBranch: e.neonParentBranch }
|
|
1774
|
-
});
|
|
1775
|
-
if (r === "neon-cow") return {
|
|
1776
|
-
branchId: n,
|
|
1777
|
-
mechanism: r,
|
|
1778
|
-
steps: i,
|
|
1779
|
-
connectionString: await t.neonBranchCreate(n, e.neonParentBranch ?? "main")
|
|
1780
|
-
};
|
|
1781
|
-
await t.createNamespace(n);
|
|
1782
|
-
for (let r of e.tableNames) await t.createTable(n, r);
|
|
1783
|
-
for (let r of e.indexNames ?? []) await t.restoreIndexName(n, r);
|
|
1784
|
-
if (e.seed === "copy") {
|
|
1785
|
-
if (e.parentNamespace === void 0 || e.parentNamespace === "") throw Error("provisionBranch: seed 'copy' requires parentNamespace");
|
|
1786
|
-
for (let r of e.tableNames) await t.copyTable(e.parentNamespace, n, r);
|
|
1787
|
-
}
|
|
1788
|
-
for (let r of e.foreignKeys ?? []) await t.addForeignKey(n, r);
|
|
1789
|
-
return {
|
|
1790
|
-
branchId: n,
|
|
1791
|
-
mechanism: r,
|
|
1792
|
-
steps: i
|
|
1793
|
-
};
|
|
1794
|
-
}, Xc = async (e, t, n) => {
|
|
1795
|
-
let r = qc(t, e);
|
|
1796
|
-
return t === "neon-cow" ? await n.neonBranchDelete(e) : await n.dropNamespace(e), r;
|
|
1797
|
-
}, Zc = (e, t, n) => Jc(e, t, n), J = (e) => `"${e.replace(/"/g, "\"\"")}"`, Qc = {
|
|
1798
|
-
cascade: "CASCADE",
|
|
1799
|
-
restrict: "RESTRICT",
|
|
1800
|
-
setNull: "SET NULL",
|
|
1801
|
-
noAction: "NO ACTION"
|
|
1802
|
-
}, Y = (e) => `'${e.replace(/'/g, "''")}'`, $c = (e, t) => {
|
|
1803
|
-
let n = t.columns.map(Y).join(", ");
|
|
1804
|
-
return `DO $voltro_branch$
|
|
1805
|
-
DECLARE derived name;
|
|
1806
|
-
BEGIN
|
|
1807
|
-
SELECT i.relname INTO derived
|
|
1808
|
-
FROM pg_index x
|
|
1809
|
-
JOIN pg_class i ON i.oid = x.indexrelid
|
|
1810
|
-
JOIN pg_class c ON c.oid = x.indrelid
|
|
1811
|
-
JOIN pg_namespace nsp ON nsp.oid = c.relnamespace
|
|
1812
|
-
WHERE nsp.nspname = ${Y(e)}
|
|
1813
|
-
AND c.relname = ${Y(t.table)}
|
|
1814
|
-
AND NOT x.indisprimary
|
|
1815
|
-
AND x.indisunique = ${t.unique ? "true" : "false"}
|
|
1816
|
-
AND i.relname <> ${Y(t.name)}
|
|
1817
|
-
AND pg_get_expr(x.indpred, x.indrelid) IS NOT DISTINCT FROM ${t.where === void 0 ? "NULL" : Y(t.where)}
|
|
1818
|
-
AND (
|
|
1819
|
-
SELECT array_agg(att.attname::text ORDER BY k.ord)
|
|
1820
|
-
FROM unnest(x.indkey::int2[]) WITH ORDINALITY AS k(attnum, ord)
|
|
1821
|
-
JOIN pg_attribute att ON att.attrelid = c.oid AND att.attnum = k.attnum
|
|
1822
|
-
) = ARRAY[${n}]::text[]
|
|
1823
|
-
LIMIT 1;
|
|
1824
|
-
IF derived IS NOT NULL THEN
|
|
1825
|
-
EXECUTE format('ALTER INDEX %I.%I RENAME TO %I',
|
|
1826
|
-
${Y(e)}, derived, ${Y(t.name)});
|
|
1827
|
-
END IF;
|
|
1828
|
-
END
|
|
1829
|
-
$voltro_branch$`;
|
|
1830
|
-
}, el = (e, t) => {
|
|
1831
|
-
let n = t.onDelete === void 0 ? "" : ` ON DELETE ${Qc[t.onDelete]}`, r = t.onUpdate === void 0 ? "" : ` ON UPDATE ${Qc[t.onUpdate]}`;
|
|
1832
|
-
return `ALTER TABLE ${J(e)}.${J(t.table)} ADD FOREIGN KEY (${J(t.column)}) REFERENCES ${J(e)}.${J(t.targetTable)} (${J(t.targetColumn)})${n}${r}`;
|
|
1833
|
-
}, tl = (e) => {
|
|
1834
|
-
let t = () => {
|
|
1835
|
-
throw Error("namespace branch executor: Neon ops require a neon-cow executor (use a Neon connection for copy-on-write branches)");
|
|
1836
|
-
};
|
|
1837
|
-
return {
|
|
1838
|
-
createNamespace: (t) => e.run(`CREATE SCHEMA IF NOT EXISTS ${J(t)}`),
|
|
1839
|
-
createTable: (t, n) => e.run(`CREATE TABLE IF NOT EXISTS ${J(t)}.${J(n)} (LIKE ${J(n)} INCLUDING ALL)`),
|
|
1840
|
-
copyTable: (t, n, r) => e.run(`INSERT INTO ${J(n)}.${J(r)} SELECT * FROM ${J(t)}.${J(r)}`),
|
|
1841
|
-
addForeignKey: (t, n) => e.run(el(t, n)),
|
|
1842
|
-
restoreIndexName: (t, n) => e.run($c(t, n)),
|
|
1843
|
-
dropNamespace: (t) => e.run(`DROP SCHEMA IF EXISTS ${J(t)} CASCADE`),
|
|
1844
|
-
neonBranchCreate: t,
|
|
1845
|
-
neonBranchDelete: t
|
|
1846
|
-
};
|
|
1847
|
-
}, nl = class extends Error {
|
|
1848
|
-
_tag = "TenantResidencyUnresolved";
|
|
1849
|
-
constructor(e) {
|
|
1850
|
-
super(e), this.name = "TenantResidencyUnresolved";
|
|
1851
|
-
}
|
|
1852
|
-
}, rl = class extends Error {
|
|
1853
|
-
region;
|
|
1854
|
-
_tag = "TenantRegionUnavailable";
|
|
1855
|
-
constructor(e, t) {
|
|
1856
|
-
super(t), this.region = e, this.name = "TenantRegionUnavailable";
|
|
1857
|
-
}
|
|
1858
|
-
}, il, al = (e) => {
|
|
1859
|
-
if (e.homes === void 0) throw Error("setResidencyConfig: `homes` is required");
|
|
1860
|
-
if (e.servableRegions === void 0 || e.servableRegions.length === 0) throw Error("setResidencyConfig: `servableRegions` must be non-empty (which regions this deployment serves)");
|
|
1861
|
-
let t = /* @__PURE__ */ new Map();
|
|
1862
|
-
for (let n of e.homes) {
|
|
1863
|
-
let e = t.get(n.tenantId);
|
|
1864
|
-
if (e !== void 0 && e !== n.region) throw Error(`residency: tenant '${n.tenantId}' is mapped to two regions ('${e}' and '${n.region}')`);
|
|
1865
|
-
t.set(n.tenantId, n.region);
|
|
1866
|
-
}
|
|
1867
|
-
return il = e, e;
|
|
1868
|
-
}, ol = () => il, sl = () => {
|
|
1869
|
-
il = void 0;
|
|
1870
|
-
}, cl = (e, t) => {
|
|
1871
|
-
if (e == null || e === "") throw new nl("residency is on but the request has no resolvable tenant — refusing to bind a store");
|
|
1872
|
-
let n = t.homes.find((t) => t.tenantId === e);
|
|
1873
|
-
if (n === void 0) throw new nl(`no residency home is mapped for tenant '${e}' — refusing to fall back to a default store (would be a residency violation)`);
|
|
1874
|
-
return n;
|
|
1875
|
-
}, ll = (e, t) => t.servableRegions.includes(e), ul = (e, t) => {
|
|
1876
|
-
let n = cl(e.tenantId, t), r = oe(n.tenantId);
|
|
1877
|
-
return {
|
|
1878
|
-
region: n.region,
|
|
1879
|
-
namespace: r,
|
|
1880
|
-
...n.connectionKey === void 0 ? {} : { connectionKey: n.connectionKey }
|
|
1881
|
-
};
|
|
1882
|
-
}, dl = (e, t, n) => {
|
|
1883
|
-
let r = ul(e, t);
|
|
1884
|
-
if (!ll(r.region, t)) throw new rl(r.region, `tenant homed in region '${r.region}', which this deployment does not serve — route to the home region`);
|
|
1885
|
-
let i = n.get(r.region);
|
|
1886
|
-
if (i === void 0) throw new rl(r.region, `no store handle for home region '${r.region}' (declared servable but not wired) — failing closed`);
|
|
1887
|
-
return {
|
|
1888
|
-
store: i,
|
|
1889
|
-
placement: r
|
|
1890
|
-
};
|
|
1891
|
-
}, fl = async (e, t, n, r) => {
|
|
1892
|
-
let { store: i, placement: a } = dl(e, t, n);
|
|
1893
|
-
return await r(i, a), a;
|
|
1894
|
-
}, X = (e) => {
|
|
1895
|
-
if (typeof e == "string") return e;
|
|
1896
|
-
if ("jsonPath" in e) {
|
|
1897
|
-
let { column: t, path: n, numeric: r } = e.jsonPath;
|
|
1898
|
-
return `(json:${t}->${n.join(".")}${r ? "::num" : ""})`;
|
|
1899
|
-
}
|
|
1900
|
-
return `(${e.expr})`;
|
|
1901
|
-
}, Z = (e) => e.map(X), pl = (e, t) => {
|
|
1902
|
-
if (e.length !== t.length) return !1;
|
|
1903
|
-
for (let n = 0; n < e.length; n++) if (X(e[n]) !== X(t[n])) return !1;
|
|
1904
|
-
return !0;
|
|
1905
|
-
}, ml = (e, t) => {
|
|
1906
|
-
if (e.length >= t.length) return !1;
|
|
1907
|
-
for (let n = 0; n < e.length; n++) if (X(e[n]) !== X(t[n])) return !1;
|
|
1908
|
-
return !0;
|
|
1909
|
-
}, hl = (e) => {
|
|
1910
|
-
let t = [], n = e.appliedIndexes, r = e.tableName;
|
|
1911
|
-
for (let e = 0; e < n.length; e++) {
|
|
1912
|
-
let i = n[e];
|
|
1913
|
-
for (let a = e + 1; a < n.length; a++) {
|
|
1914
|
-
let e = n[a];
|
|
1915
|
-
if (pl(i.fields, e.fields)) {
|
|
1916
|
-
let [n, a] = i.name < e.name ? [i, e] : [e, i];
|
|
1917
|
-
t.push({
|
|
1918
|
-
kind: "duplicate-fields",
|
|
1919
|
-
table: r,
|
|
1920
|
-
redundant: n,
|
|
1921
|
-
coveredBy: a,
|
|
1922
|
-
message: `'${r}' has two indexes on the same fields [${Z(i.fields).join(", ")}]: '${i.name}' and '${e.name}'. The B-tree engine builds both, costing write throughput + disk space for no read benefit. Drop '${n.name}' (or '${a.name}' if you prefer the other name). Applies to every supported dialect (Postgres / MySQL / MariaDB / MSSQL / SQLite).`
|
|
1923
|
-
});
|
|
1924
|
-
continue;
|
|
1925
|
-
}
|
|
1926
|
-
ml(i.fields, e.fields) ? t.push({
|
|
1927
|
-
kind: "redundant-prefix",
|
|
1928
|
-
table: r,
|
|
1929
|
-
redundant: i,
|
|
1930
|
-
coveredBy: e,
|
|
1931
|
-
message: `'${r}' index '${i.name}' on [${Z(i.fields).join(", ")}] is a leading prefix of '${e.name}' on [${Z(e.fields).join(", ")}]. Every B-tree dialect we support (Postgres / MySQL / MariaDB / MSSQL / SQLite) can serve a [${Z(i.fields).join(", ")}] query from '${e.name}' too via the leading-prefix rule, so '${i.name}' adds write cost without read benefit. Drop '${i.name}' — unless you specifically need a smaller index for cache locality on a write-heavy table (rare; profile first).`
|
|
1932
|
-
}) : ml(e.fields, i.fields) && t.push({
|
|
1933
|
-
kind: "redundant-prefix",
|
|
1934
|
-
table: r,
|
|
1935
|
-
redundant: e,
|
|
1936
|
-
coveredBy: i,
|
|
1937
|
-
message: `'${r}' index '${e.name}' on [${Z(e.fields).join(", ")}] is a leading prefix of '${i.name}' on [${Z(i.fields).join(", ")}]. Every B-tree dialect we support (Postgres / MySQL / MariaDB / MSSQL / SQLite) can serve a [${Z(e.fields).join(", ")}] query from '${i.name}' too via the leading-prefix rule, so '${e.name}' adds write cost without read benefit. Drop '${e.name}' — unless you specifically need a smaller index for cache locality on a write-heavy table (rare; profile first).`
|
|
1938
|
-
});
|
|
1939
|
-
}
|
|
1940
|
-
}
|
|
1941
|
-
return t;
|
|
1942
|
-
}, gl = (e) => {
|
|
1943
|
-
let t = [];
|
|
1944
|
-
for (let n of e) t.push(...hl(n));
|
|
1945
|
-
return t;
|
|
1946
|
-
}, _l = "\x1B[", vl = `${_l}38;2;245;158;11m`, yl = `${_l}38;2;16;185;129m`, bl = (e, t) => `${e}${t}${A.reset}`, Q = (e, t, n) => e ? typeof t == "function" ? t(n) : bl(t, n) : n, xl = (e, t = {}) => {
|
|
1947
|
-
let n = t.color ?? !0, r = t.indent ?? " ", i = (e) => Q(n, A.dim, e.padEnd(11)), a = (e) => Q(n, (e) => A.bold(A.brand(e)), e), o = (e) => Q(n, A.brightRed24, e), s = (e) => Q(n, yl, e), c = (e) => Q(n, vl, e), l = (e) => Q(n, A.dim, e), u = `${c("index audit")} ${l("·")} ${Q(n, A.bold, e.kind)}`, d = e.redundant.fields.length, f = Z(e.coveredBy.fields.slice(d)), p = (e, t) => {
|
|
1948
|
-
let n = e.slice(0, t), r = e.slice(t), i = [];
|
|
1949
|
-
return n.length > 0 && i.push(s(`[${n.join(", ")}]`)), r.length > 0 && i.push(c(`+ [${r.join(", ")}]`)), i.join(" ");
|
|
1950
|
-
}, m = [];
|
|
1951
|
-
return m.push(u), m.push(""), m.push(`${i("table")}${a(e.table)}`), m.push(""), m.push(`${i("redundant")}${o(e.redundant.name)}`), m.push(`${i("")}${p(Z(e.redundant.fields), d)}`), m.push(""), m.push(`${i("covered by")}${s(e.coveredBy.name)}`), m.push(`${i("")}${p(Z(e.coveredBy.fields), d)}`), f.length > 0 && m.push(`${i("")}${l(`└ extra columns: ${f.join(", ")}`)}`), m.push(""), e.kind === "redundant-prefix" ? (m.push(`${i("why")}B-tree indexes serve queries that filter on a LEADING PREFIX of`), m.push(`${i("")}their column list. The wider index already covers every`), m.push(`${i("")}query the narrower one can serve.`), m.push(`${i("")}${l("Same rule on Postgres / MySQL / MariaDB / MSSQL / SQLite.")}`)) : (m.push(`${i("why")}Two indexes on the same columns under different names.`), m.push(`${i("")}The B-tree engine builds both — same coverage, double cost.`), m.push(`${i("")}${l("Same rule on Postgres / MySQL / MariaDB / MSSQL / SQLite.")}`)), m.push(""), m.push(`${i("cost")}Every ${a("INSERT")} / ${a("UPDATE")} / ${a("DELETE")} on this table writes`), m.push(`${i("")}to ${Q(n, A.bold, "both")} B-trees. Pure write overhead, zero read benefit.`), m.push(""), m.push(`${i("fix")}Drop ${o(e.redundant.name)}`), m.push(`${i("")}${l("Keep only if profiling shows the smaller index gives a")}`), m.push(`${i("")}${l("measurable cache-locality boost on a write-heavy hot path.")}`), m.push(`${i("")}${l("Silence with VOLTRO_INDEX_AUDIT=off if intentional.")}`), m.map((e) => `${r}${e}`).join("\n");
|
|
1952
|
-
}, Sl = (e, { apply: t, undo: n }) => ({
|
|
1953
|
-
name: e,
|
|
1954
|
-
apply: t,
|
|
1955
|
-
undo: n
|
|
1956
|
-
}), Cl = (e) => {
|
|
1957
|
-
if (!/^\d{14}_/.test(e.id)) throw Error(`migration "${e.id}": id must start with a 14-digit timestamp followed by "_" (convention: <YYYYMMDDHHMMSS>_<slug>)`);
|
|
1958
|
-
let t = e.steps({ step: Sl });
|
|
1959
|
-
if (t.length === 0) throw Error(`migration "${e.id}": at least one step is required`);
|
|
1960
|
-
return {
|
|
1961
|
-
__migration: !0,
|
|
1962
|
-
id: e.id,
|
|
1963
|
-
name: e.name,
|
|
1964
|
-
steps: t
|
|
1965
|
-
};
|
|
1966
|
-
}, wl = (e) => typeof e == "object" && !!e && "__migration" in e && e.__migration === !0, Tl = mr.tableName, El = (e) => Ir("sha256").update(`${e.type}\u0000${e.id}`, "utf8").digest("hex"), Dl = async (e, t) => {
|
|
1967
|
-
let [n] = await e.query({
|
|
1968
|
-
table: Tl,
|
|
1969
|
-
predicate: Wn("id", El(t)),
|
|
1970
|
-
order: [],
|
|
1971
|
-
take: 1,
|
|
1972
|
-
skip: void 0,
|
|
1973
|
-
projection: void 0
|
|
1974
|
-
}), r = n?.tenantId;
|
|
1975
|
-
return typeof r == "string" ? r : null;
|
|
1976
|
-
}, Ol = async (e, t, n) => {
|
|
1977
|
-
await e.upsert(Tl, {
|
|
1978
|
-
id: El(t),
|
|
1979
|
-
subjectType: t.type,
|
|
1980
|
-
subjectId: t.id,
|
|
1981
|
-
tenantId: n,
|
|
1982
|
-
selectedAt: /* @__PURE__ */ new Date()
|
|
1983
|
-
}, { conflictColumns: ["id"] });
|
|
1984
|
-
}, kl = async (e, t) => {
|
|
1985
|
-
await e.delete(Tl, El(t));
|
|
1986
|
-
}, $ = "id", Al = (e, t) => {
|
|
1987
|
-
let n = je(e);
|
|
1988
|
-
if (n === void 0) return t;
|
|
1989
|
-
let r = n.fields[$]?.idScheme;
|
|
1990
|
-
if (r === void 0 || t[$] != null) return t;
|
|
1991
|
-
if (r.kind === "numeric") {
|
|
1992
|
-
if (!($ in t)) return t;
|
|
1993
|
-
let e = { ...t };
|
|
1994
|
-
return delete e[$], e;
|
|
1995
|
-
}
|
|
1996
|
-
let i = xt(r, e);
|
|
1997
|
-
return i === null ? t : {
|
|
1998
|
-
...t,
|
|
1999
|
-
[$]: i
|
|
2000
|
-
};
|
|
2001
|
-
}, jl = (e, t) => t.map((t) => Al(e, t)), Ml = {
|
|
2002
|
-
postgres: { maxBindParameters: 32767 },
|
|
2003
|
-
mysql: { maxBindParameters: 65535 },
|
|
2004
|
-
mariadb: { maxBindParameters: 65535 },
|
|
2005
|
-
mssql: {
|
|
2006
|
-
maxBindParameters: 2098,
|
|
2007
|
-
maxRowsPerStatement: 1e3
|
|
2008
|
-
},
|
|
2009
|
-
sqlite: { maxBindParameters: 32766 },
|
|
2010
|
-
turso: { maxBindParameters: 32766 }
|
|
2011
|
-
}, Nl = (e) => Ml[e], Pl = (e) => {
|
|
2012
|
-
let t = /* @__PURE__ */ new Set();
|
|
2013
|
-
for (let n of e) for (let e of Object.keys(n)) t.add(e);
|
|
2014
|
-
return t.size;
|
|
2015
|
-
}, Fl = (e, t) => {
|
|
2016
|
-
if (t === void 0 || e.length === 0) return [e];
|
|
2017
|
-
let n = Math.max(1, Pl(e)), r = Math.floor(t.maxBindParameters / n), i = t.maxRowsPerStatement ?? Infinity, a = Math.max(1, Math.min(r, i));
|
|
2018
|
-
if (e.length <= a) return [e];
|
|
2019
|
-
let o = [];
|
|
2020
|
-
for (let t = 0; t < e.length; t += a) o.push(e.slice(t, t + a));
|
|
2021
|
-
return o;
|
|
2022
|
-
}, Il = (e, t) => {
|
|
2023
|
-
let n = [], r = t;
|
|
2024
|
-
for (let [t, i] of Object.entries(e.fields)) {
|
|
2025
|
-
let e = i;
|
|
2026
|
-
e.nullable || e.hasDefault || e.idScheme !== void 0 || e.generatedAs !== void 0 || (r[t] === void 0 || r[t] === null) && n.push(t);
|
|
2027
|
-
}
|
|
2028
|
-
return n;
|
|
2029
|
-
}, Ll = (e, t, n) => {
|
|
2030
|
-
let r = n, i = /* @__PURE__ */ new Set();
|
|
2031
|
-
if (e !== void 0) {
|
|
2032
|
-
let n = e.fields;
|
|
2033
|
-
for (let e of new Set(t)) Object.getOwnPropertyDescriptor(n, e)?.enumerable && n[e]?.generatedAs !== void 0 && i.add(e);
|
|
2034
|
-
}
|
|
2035
|
-
let a = [];
|
|
2036
|
-
for (let e of t) i.has(e) || (r[e] === void 0 ? a.push({
|
|
2037
|
-
column: e,
|
|
2038
|
-
reason: "absent"
|
|
2039
|
-
}) : r[e] === null && a.push({
|
|
2040
|
-
column: e,
|
|
2041
|
-
reason: "null"
|
|
2042
|
-
}));
|
|
2043
|
-
return a;
|
|
2044
|
-
}, Rl = (e, t, n) => e.insert(t.tableName, n), zl = (e, t, n) => e.insertMany(t.tableName, n), Bl = (e, t, n, r) => e.upsert(t.tableName, n, {
|
|
2045
|
-
conflictColumns: r.conflictColumns,
|
|
2046
|
-
...r.update === void 0 ? {} : { update: r.update },
|
|
2047
|
-
...r.updateValues === void 0 ? {} : { updateValues: r.updateValues }
|
|
2048
|
-
}), Vl = async (e, t, n, r) => {
|
|
2049
|
-
if (e.upsertWithOutcome === void 0) throw S("upsertRowOutcome: this store does not implement `upsertWithOutcome`. It is provided by the framework's store wrapper, so `ctx.store` has it; a hand-written DataStore must add it.");
|
|
2050
|
-
return e.upsertWithOutcome(t.tableName, n, {
|
|
2051
|
-
conflictColumns: r.conflictColumns,
|
|
2052
|
-
...r.update === void 0 ? {} : { update: r.update },
|
|
2053
|
-
...r.updateValues === void 0 ? {} : { updateValues: r.updateValues }
|
|
2054
|
-
});
|
|
2055
|
-
}, Hl = async (e, t, n, r) => e.insertIgnoreWithOutcome(t.tableName, n, { conflictColumns: r.conflictColumns }), Ul = (e, t, n, r) => e.updateMany(t.tableName, n, { where: r.where }), Wl = 512, Gl = (e) => {
|
|
2056
|
-
e.setMaxListeners(512);
|
|
2057
|
-
}, Kl = (e, t, n) => ({
|
|
2058
|
-
_tag: "PrimaryKeyConflictError",
|
|
2059
|
-
table: e,
|
|
2060
|
-
key: t,
|
|
2061
|
-
cause: n
|
|
2062
|
-
}), ql = (e) => typeof e == "object" && !!e && e._tag === "PrimaryKeyConflictError", Jl = {
|
|
2063
|
-
postgres: 5432,
|
|
2064
|
-
mysql: 3306,
|
|
2065
|
-
mariadb: 3306,
|
|
2066
|
-
mssql: 1433
|
|
2067
|
-
}, Yl = /* @__PURE__ */ new Set([
|
|
2068
|
-
"localhost",
|
|
2069
|
-
"127.0.0.1",
|
|
2070
|
-
"::1",
|
|
2071
|
-
"[::1]",
|
|
2072
|
-
"0.0.0.0"
|
|
2073
|
-
]), Xl = (e) => {
|
|
2074
|
-
let t = e.host, n = e.port, r = e.database;
|
|
2075
|
-
if (e.url !== void 0 && e.url !== "") try {
|
|
2076
|
-
let i = new URL(e.url);
|
|
2077
|
-
t ??= decodeURIComponent(i.hostname), n === void 0 && i.port !== "" && (n = Number(i.port)), r ??= decodeURIComponent(i.pathname.replace(/^\//, ""));
|
|
2078
|
-
} catch {
|
|
2079
|
-
return;
|
|
2080
|
-
}
|
|
2081
|
-
if (t === void 0 || t === "" || r === void 0 || r === "") return;
|
|
2082
|
-
let i = n ?? Jl[(e.dialect ?? "").toLowerCase()];
|
|
2083
|
-
if (i === void 0 || !Number.isFinite(i)) return;
|
|
2084
|
-
let a = t.toLowerCase();
|
|
2085
|
-
return {
|
|
2086
|
-
host: Yl.has(a) ? "localhost" : a,
|
|
2087
|
-
port: i,
|
|
2088
|
-
database: r.toLowerCase()
|
|
2089
|
-
};
|
|
2090
|
-
}, Zl = (e) => {
|
|
2091
|
-
let t = Xl(e);
|
|
2092
|
-
if (t !== void 0) return Ir("sha256").update(`${t.host}\u0000${t.port}\u0000${t.database}`).digest("hex").slice(0, 32);
|
|
2093
|
-
}, Ql = (e, t) => e === void 0 || t === void 0 ? "unknown" : e === t ? "same" : "different", $l = {
|
|
2094
|
-
app: 3,
|
|
2095
|
-
plugin: 2,
|
|
2096
|
-
framework: 1
|
|
2097
|
-
}, eu = /* @__PURE__ */ new Map(), tu = [], nu = () => [...tu], ru = (e) => {
|
|
2098
|
-
if (!e.table || !e.timeColumn) throw Error("registerRetention: table + timeColumn are required");
|
|
2099
|
-
if (!Number.isFinite(e.ttlMs) || e.ttlMs <= 0) throw Error(`registerRetention(${e.table}): ttlMs must be a positive number`);
|
|
2100
|
-
let t = e.source ?? "app", n = eu.get(e.table);
|
|
2101
|
-
if (n !== void 0) {
|
|
2102
|
-
let r = n.source ?? "app", i = n.ttlMs !== e.ttlMs || n.timeColumn !== e.timeColumn || JSON.stringify(n.activityColumns ?? []) !== JSON.stringify(e.activityColumns ?? []) || JSON.stringify(n.where) !== JSON.stringify(e.where);
|
|
2103
|
-
if ($l[t] < $l[r]) {
|
|
2104
|
-
i && tu.push({
|
|
2105
|
-
table: e.table,
|
|
2106
|
-
kept: {
|
|
2107
|
-
source: r,
|
|
2108
|
-
ttlMs: n.ttlMs
|
|
2109
|
-
},
|
|
2110
|
-
dropped: {
|
|
2111
|
-
source: t,
|
|
2112
|
-
ttlMs: e.ttlMs
|
|
2113
|
-
}
|
|
2114
|
-
});
|
|
2115
|
-
return;
|
|
2116
|
-
}
|
|
2117
|
-
i && r !== t && tu.push({
|
|
2118
|
-
table: e.table,
|
|
2119
|
-
kept: {
|
|
2120
|
-
source: t,
|
|
2121
|
-
ttlMs: e.ttlMs
|
|
2122
|
-
},
|
|
2123
|
-
dropped: {
|
|
2124
|
-
source: r,
|
|
2125
|
-
ttlMs: n.ttlMs
|
|
2126
|
-
}
|
|
2127
|
-
});
|
|
2128
|
-
}
|
|
2129
|
-
eu.set(e.table, {
|
|
2130
|
-
...e,
|
|
2131
|
-
source: t
|
|
2132
|
-
});
|
|
2133
|
-
}, iu = () => [...eu.values()], au = () => {
|
|
2134
|
-
eu.clear(), tu.length = 0;
|
|
2135
|
-
}, ou = async (e, t, n, r = 2e4) => {
|
|
2136
|
-
let i = new Date(t - e.ttlMs), a = (e.activityColumns ?? []).map((e) => Lt(Gt(e), Rn(e, i))), o = a.length === 0 ? e.where : Ct(...e.where === void 0 ? [] : [e.where], ...a), s = 0;
|
|
2137
|
-
try {
|
|
2138
|
-
for (;;) {
|
|
2139
|
-
let t = await n(e.table, e.timeColumn, i, r, o);
|
|
2140
|
-
if (s += t, t < r) break;
|
|
2141
|
-
}
|
|
2142
|
-
} catch (t) {
|
|
2143
|
-
throw E.runSync(D.update(D.withAttributes(cu, { table: e.table }), 1)), t;
|
|
2144
|
-
}
|
|
2145
|
-
return s > 0 && E.runSync(D.update(D.withAttributes(su, { table: e.table }), s)), s;
|
|
2146
|
-
}, su = D.counter("voltro_retention_swept_rows_total"), cu = D.counter("voltro_retention_sweep_errors_total"), lu = (e, t) => {
|
|
2147
|
-
let n = Number(e ?? String(t));
|
|
2148
|
-
return (Number.isFinite(n) && n > 0 ? n : t) * 36e5;
|
|
2149
|
-
}, uu = "_voltro_cdc_offsets", du = b(uu, {
|
|
2150
|
-
id: dt({ prefix: "cdcoff" }),
|
|
2151
|
-
replicaId: x(),
|
|
2152
|
-
streamName: x(),
|
|
2153
|
-
binlogFile: x(),
|
|
2154
|
-
binlogPosition: x(),
|
|
2155
|
-
updatedAt: w()
|
|
2156
|
-
}).index(["replicaId"]), fu = b(uu, {
|
|
2157
|
-
id: dt({ prefix: "cdcoff" }),
|
|
2158
|
-
replicaId: x(),
|
|
2159
|
-
streamName: x(),
|
|
2160
|
-
ctVersion: x(),
|
|
2161
|
-
updatedAt: w()
|
|
2162
|
-
}).index(["replicaId"]), pu = "_voltro_data_transfers", mu = b(pu, {
|
|
2163
|
-
id: dt({ prefix: "dimp" }),
|
|
2164
|
-
startedAt: w().default("now"),
|
|
2165
|
-
finishedAt: w().nullable(),
|
|
2166
|
-
direction: x().default("import"),
|
|
2167
|
-
mode: x(),
|
|
2168
|
-
via: x(),
|
|
2169
|
-
bundle: x().nullable(),
|
|
2170
|
-
sourceFingerprint: x().nullable(),
|
|
2171
|
-
tablesWritten: pe().default(0),
|
|
2172
|
-
rowsWritten: pe().default(0),
|
|
2173
|
-
failure: x().nullable(),
|
|
2174
|
-
staged: g().nullable()
|
|
2175
|
-
}).renamedFrom("_voltro_data_imports").nonReactive(), hu = (e) => {
|
|
2176
|
-
let t = Number.isFinite(e.startedAt.getTime()) ? e.startedAt.toISOString() : "an unknown time", n = e.direction === "import" ? e.mode : `${e.direction} ${e.mode}`, r = e.failure === null ? e.finishedAt === null ? `${n} — started and never reported finishing` : e.direction === "backup" || e.direction === "restore" ? `${n} — finished${e.rowsWritten > 0 ? ` (${e.rowsWritten} blob(s))` : ""}` : `${n} — ${e.rowsWritten} row(s) across ${e.tablesWritten} table(s)` : `FAILED ${n} — ${e.failure}`, i = e.staged === null ? "" : e.staged ? " · staged (target untouched until the swap)" : " · NOT staged (target emptied first)";
|
|
2177
|
-
return `${t} · ${r} · via ${e.via}${i}` + (e.bundle === null ? "" : ` · from ${e.bundle}`) + (e.sourceFingerprint === null ? "" : ` · source schema ${e.sourceFingerprint}`);
|
|
2178
|
-
}, gu = 255, _u = (e) => e == null ? "null" : typeof e == "string" || typeof e == "number" || typeof e == "boolean" ? JSON.stringify(e) : Array.isArray(e) ? `[${e.map(_u).join(",")}]` : typeof e == "object" ? `{${Object.entries(e).filter(([, e]) => e !== void 0).sort(([e], [t]) => e < t ? -1 : +(e > t)).map(([e, t]) => `${JSON.stringify(e)}:${_u(t)}`).join(",")}}` : JSON.stringify(String(e)), vu = (e) => {
|
|
2179
|
-
if (e == null) return null;
|
|
2180
|
-
let t = typeof e == "string" ? e : _u(e);
|
|
2181
|
-
return t.length > 255 ? t.slice(0, 255) : t;
|
|
2182
|
-
}, yu = "postgres";
|
|
1
|
+
import { ColumnBuilder as e, SELF_REFERENCE_TARGET as t, array as n, bigint as r, boolean as i, bytes as a, crdtCounter as o, crdtDoc as s, crdtManagedColumns as c, crdtManagedColumnsOf as l, crdtSealed as u, crdtText as d, date as f, dbEnum as p, decimal as m, dropped as h, geography as g, geometry as _, id as v, integer as y, interval as b, json as x, materializeFields as S, numeric as C, persistedColumns as w, raw as T, readableByColumns as E, real as D, reference as O, selfReference as k, serverOnlyColumns as A, text as j, timestamp as M, vector as N } from "./columns.js";
|
|
2
|
+
import { pluginRef as P, pluginRefSpecOf as F } from "./pluginRef.js";
|
|
3
|
+
import { columnRef as I, isColumnReference as L } from "./columnReference.js";
|
|
4
|
+
import { authoredError as R, authoredMessageOf as z, causeBranches as B, classifyConstraintViolation as V, describeCharsetRefusal as H, describeDriverError as U, describeRowBindings as W, extractDbCause as G, isForeignKeyViolation as K, isQueryTimeout as q, wireSafeCause as J } from "./dbCause.js";
|
|
5
|
+
import { compareDecimal as Y, decimalEqualityKey as X } from "./decimalComparison.js";
|
|
6
|
+
import { MATCHES_NO_ROWS as Z, and as Q, arrayContains as $, arrayHas as ee, arrayOverlaps as te, collectSubqueries as ne, contains as re, eq as ie, evaluatePredicate as ae, exists as oe, gt as se, gte as ce, inSet as le, inSubquery as ue, isNotNull as de, isNull as fe, jsonField as pe, lt as me, lte as he, neq as ge, not as _e, notExists as ve, notInSet as ye, notInSubquery as be, or as xe, preparePredicate as Se, spatialPredicate as Ce, startsWith as we, walkLeaves as Te } from "./predicate.js";
|
|
7
|
+
import { resolveActorSnapshot as Ee } from "./actorSnapshot.js";
|
|
8
|
+
import { allEnumRenames as De, clearEnumRenames as Oe, declareEnumRename as ke, getEnumRenames as Ae } from "./enumRenames.js";
|
|
9
|
+
import { deserializeArraysOnRead as je, serializeArraysForWrite as Me } from "./arrayCodec.js";
|
|
10
|
+
import { BOUND_ENCRYPTED_PREFIX as Ne, ENCRYPTED_PREFIX as Pe, FIELD_KEY_ID_PATTERN as Fe, FieldDecryptionError as Ie, ciphertextKeyId as Le, decodeFieldValue as Re, decryptFieldsOnRead as ze, encodeFieldValue as Be, encryptFieldsForWrite as Ve, encryptFieldsForWriteBatch as He, encryptedColumnsOf as Ue, fieldBinding as We, fieldBindingsOf as Ge, isBoundCiphertext as Ke, isEncrypted as qe, isFieldDecryptionError as Je, isRawEncoding as Ye, refuseIdChangeOfSealedRow as Xe } from "./fieldEncryption.js";
|
|
11
|
+
import { refuseWrite as Ze, storeRefusalOf as Qe } from "./storeRefusal.js";
|
|
12
|
+
import { MAX_IDENTIFIER_LENGTH as $e, WARN_IDENTIFIER_LENGTH as et, drainIdentifierWarnings as tt, validateColumnName as nt, validateIndexName as rt, validateTableName as it, validateTypeIdPrefix as at } from "./identifierLimits.js";
|
|
13
|
+
import { encodeTypeIdSuffix as ot, typeId as st, uuidV7Bytes as ct } from "./typeId.js";
|
|
14
|
+
import { generateSnowflake as lt, resetSnowflake as ut } from "./snowflake.js";
|
|
15
|
+
import { deriveTypeIdPrefix as dt, generateId as ft, resolveIdScheme as pt } from "./idGenerator.js";
|
|
16
|
+
import { defineMixin as mt, mixin as ht, resolveMixinGraph as gt } from "./mixins.js";
|
|
17
|
+
import { AUTO_FILLED_COLUMNS as _t, jsonIndex as vt, table as yt, vectorDistanceToOpclass as bt } from "./table.js";
|
|
18
|
+
import { DEFAULT_ACQUIRE_TIMEOUT_MS as xt, isMysqlFamily as St, isSqliteFamily as Ct, quoteIdent as wt } from "./dialect.js";
|
|
19
|
+
import { allRegisteredTables as Tt, clearTableRegistry as Et, ensureTableRegistered as Dt, getTable as Ot, isTableReactive as kt, registerTable as At, requireTable as jt, unregisterTable as Mt } from "./tableRegistry.js";
|
|
20
|
+
import { avg as Nt, avgOver as Pt, column as Ft, count as It, countDistinct as Lt, databaseHandle as Rt, denseRank as zt, except as Bt, intersect as Vt, lag as Ht, lead as Ut, max as Wt, min as Gt, orderClausesOf as Kt, paginateBy as qt, paginateById as Jt, queryFor as Yt, rank as Xt, resolveFullTextIndex as Zt, rowNumber as Qt, sum as $t, sumOver as en, union as tn, unionAll as nn } from "./queryBuilder.js";
|
|
21
|
+
import { isView as rn, queryForView as an, view as on, viewSql as sn } from "./view.js";
|
|
22
|
+
import { INITIAL_VERSION as cn, VersionConflict as ln, planVersionedUpdate as un, settleVersionedUpdate as dn, versionColumnOf as fn } from "./optimisticVersion.js";
|
|
23
|
+
import { timestampMs as pn, timestampMsOrNull as mn } from "./wire.js";
|
|
24
|
+
import { columnSchema as hn, rowSchema as gn } from "./rowSchema.js";
|
|
25
|
+
import { inferForeignKey as _n, isEmptyRelationsSpec as vn, isRelationsSpec as yn, many as bn, manyToMany as xn, one as Sn, relations as Cn, validateRelationConfig as wn } from "./relations.js";
|
|
26
|
+
import { allRegisteredRelations as Tn, clearRelationsRegistry as En, getRelation as Dn, getRelations as On, registerDiscoveredRelations as kn, registerRelations as An, validateRegisteredRelations as jn } from "./relationsRegistry.js";
|
|
27
|
+
import { DEFAULT_SUBJECT_GRAPH_DEPTH as Mn, deriveSubjectGraph as Nn, formatSubjectGraph as Pn } from "./subjectGraph.js";
|
|
28
|
+
import { decodeRowsForTable as Fn, decodeRowsFromSchema as In, decodeSelectRows as Ln, encodeRowForSchema as Rn } from "./rowDecoder.js";
|
|
29
|
+
import { upsertUpdatePatch as zn, upsertUpdateValues as Bn } from "./upsertUpdate.js";
|
|
30
|
+
import { isCompositeRowKey as Vn, rowKeyColumns as Hn, rowKeyIdentity as Un } from "./rowKey.js";
|
|
31
|
+
import { jsonPatchAssignments as Wn } from "./jsonPatchAssignments.js";
|
|
32
|
+
import { applyJsonPatch as Gn, compileJsonPatch as Kn, normalizeJsonPatchValue as qn } from "./jsonPatch.js";
|
|
33
|
+
import { EagerCardinalityError as Jn, attachEagerLoads as Yn, hasEagerLoads as Xn, oneCardinalityMessage as Zn } from "./joinCompiler.js";
|
|
34
|
+
import { coerceValueForSqlite as Qn } from "./sqliteValueCoercion.js";
|
|
35
|
+
import { TenantNamespaceInvalid as $n, TenantNamespaceUnresolved as er, qualifyTable as tr, resolveTenantNamespace as nr, sanitizeIdentifierFragment as rr } from "./namespace.js";
|
|
36
|
+
import { coercePredicateValue as ir, coercePredicateValues as ar } from "./predicateCoercion.js";
|
|
37
|
+
import { compilePredicate as or, compileRawFragment as sr, compileRowProjection as cr, compileSelect as lr, escapeLike as ur } from "./sqlCompiler.js";
|
|
38
|
+
import { coercePredicateForSqlite as dr, compileEagerJson as fr } from "./jsonEagerCompiler.js";
|
|
39
|
+
import { registerCoreTables as pr, requireActors as mr, requireTenants as hr } from "./coreTablesRegistry.js";
|
|
40
|
+
import { actorsTable as gr } from "./coreTables.js";
|
|
41
|
+
import { changeDelete as _r, changeInsert as vr, changeSoftDelete as yr, changeUpdate as br, externalChangeEvent as xr } from "./changeEvent.js";
|
|
42
|
+
import { committedChangeBatchOf as Sr, emitCommittedChanges as Cr } from "./committedChanges.js";
|
|
43
|
+
import { CHANGE_CLAIM_TTL_ENV as wr, DEFAULT_CHANGE_CLAIM_TTL_HOURS as Tr, OccurrenceCounter as Er, changeDigest as Dr, composeChangeKey as Or, occurrenceWindowMs as kr, parseChangeKey as Ar } from "./changeIdentity.js";
|
|
44
|
+
import { attributionFields as jr, currentWriteAttribution as Mr, runWithWriteAttribution as Nr, withCapturedAttribution as Pr } from "./writeAttribution.js";
|
|
45
|
+
import { attributionKey as Fr, beginLocalWrite as Ir, claimPendingAttribution as Lr, clearPendingAttribution as Rr, endLocalWrite as zr, pendingAttributionCount as Br, registerPendingAttribution as Vr, resolveEchoAttribution as Hr } from "./pendingAttribution.js";
|
|
46
|
+
import { ID_COLUMN_MAX_LENGTH as Ur, derivedRowId as Wr, derivedRowIdLength as Gr } from "./derivedRowId.js";
|
|
47
|
+
import { clearWriteRecorders as Kr, recordsTable as qr, registerWriteRecorder as Jr, runWriteRecorders as Yr, suspendWriteRecorders as Xr, suspendWriteRecordersEffect as Zr, unregisterWriteRecorder as Qr, writeImagesObserved as $r, writeRecordersSuspended as ei } from "./writeRecorder.js";
|
|
48
|
+
import { DEFAULT_EAGER_FALLBACK_WARN_INTERVAL_MS as ti, dbMetricTagCacheSizeForTests as ni, dbOperationsInFlight as ri, makeEagerFallbackReporter as ii, observeDbOp as ai, recordDbOp as oi, resetDbMetricTagCacheForTests as si, resolveEagerFallbackWarnIntervalMs as ci } from "./dbMetrics.js";
|
|
49
|
+
import { SHARED_TRANSACTION_SERVICE as li, TransactionAbortedError as ui, isTransactionAbortedError as di, makeTransactionAbortTracker as fi, onTransaction as pi, runRetryingTransaction as mi, runSavepoint as hi, runStoreTransaction as gi, settleTransactionExit as _i, transactionRetrySchedule as vi } from "./transactionOutcome.js";
|
|
50
|
+
import { MSSQL_TRANSIENT_NUMBERS as yi, MYSQL_TRANSIENT_CODES as bi, POSTGRES_TRANSIENT_STATES as xi, SQLITE_TRANSIENT_CODES as Si, TURSO_TRANSIENT_MESSAGE as Ci, isTransientContention as wi } from "./transientContention.js";
|
|
51
|
+
import { VOLTRO_EXPIRES_MIXIN_ID as Ti, expires as Ei } from "./expiresMixin.js";
|
|
52
|
+
import { VOLTRO_LOCAL_FIRST_MIXIN_ID as Di, isLocalFirst as Oi, localFirst as ki, localFirstTables as Ai } from "./localFirstMixin.js";
|
|
53
|
+
import { TableStreamError as ji, streamTable as Mi } from "./stream.js";
|
|
54
|
+
import { hybridSearch as Ni } from "./hybridSearch.js";
|
|
55
|
+
import { computeEmbedding as Pi, vectorEmbedding as Fi } from "./vectorEmbedding.js";
|
|
56
|
+
import { BranchNameInvalid as Ii, BranchTransitionInvalid as Li, branchNamespaceName as Ri, enforceBranchLimits as zi, isBranchNamespace as Bi, isNeonConnection as Vi, nextBranchState as Hi, planBranch as Ui, planBranchProvision as Wi, planBranchTeardown as Gi, planBranchTeardownFor as Ki, planNeonBranchProvision as qi, planNeonBranchTeardown as Ji, resolveBranchMechanism as Yi } from "./branching.js";
|
|
57
|
+
import { admitBranch as Xi, makeNamespaceBranchExecutor as Zi, provisionBranch as Qi, teardownBranch as $i } from "./branchExecute.js";
|
|
58
|
+
import { TenantRegionUnavailable as ea, TenantResidencyUnresolved as ta, bindResidentStore as na, clearResidencyConfig as ra, getResidencyConfig as ia, isRegionServable as aa, provisionResidentTenant as oa, residentPlacement as sa, resolveTenantHome as ca, setResidencyConfig as la } from "./residency.js";
|
|
59
|
+
import { auditAllTableIndexes as ua, auditTableIndexes as da, formatIndexAuditIssue as fa } from "./indexAudit.js";
|
|
60
|
+
import { defineSeed as pa, fireSchemaChangeSeeds as ma, fireTenantCreateSeeds as ha, isSeedDefinition as ga, setSchemaChangeSeedHook as _a, setTenantCreateSeedHook as va } from "./seed.js";
|
|
61
|
+
import { defineMigration as ya, isMigrationDefinition as ba } from "./migration.js";
|
|
62
|
+
import { FILE_MIGRATION_PATTERN as xa, IrreversibleMigrationError as Sa, MIGRATION_PHASES as Ca, MigrationExpectationFailed as wa, MigrationNeedsSqlClient as Ta, MigrationSkipped as Ea, RewriteUnstableError as Da, TransactionBrokenByBodyError as Oa, irreversible as ka, irreversibleReason as Aa, isFileMigration as ja, migration as Ma } from "./migrations/fileBased.js";
|
|
63
|
+
import { DEFAULT_SOFT_DROP_RETENTION_DAYS as Na, FRAMEWORK_LIVE_TABLES as Pa, STAGING_TABLE_PREFIX as Fa, agedSoftDropSnapshots as Ia, describeAgedSoftDropSnapshots as La, isFrameworkOwnedLiveTable as Ra, isSoftDropSnapshotName as za, isStagingTableName as Ba, softDropSnapshotStamp as Va } from "./migrations/frameworkLiveTables.js";
|
|
64
|
+
import { sqlError as Ha } from "./sqlError.js";
|
|
65
|
+
import { _voltroApiKeysTable as Ua, _voltroApiRoleWorkloadBucketsTable as Wa, _voltroDevicesTable as Ga, _voltroIdempotencyTable as Ka, _voltroKvTable as qa, _voltroMigrationPlansTable as Ja, _voltroMigrationsTable as Ya, _voltroPluginMigrationsTable as Xa, _voltroReplicaObservationsTable as Za, _voltroSchemaOwnerTable as Qa, _voltroSeedsTable as $a, _voltroTenantSelectionsTable as eo, frameworkTables as to } from "./frameworkTables.js";
|
|
66
|
+
import { TENANT_SELECTIONS_TABLE as no, deleteTenantSelection as ro, readTenantSelection as io, tenantSelectionId as ao, writeTenantSelection as oo } from "./tenantSelection.js";
|
|
67
|
+
import { REPLACE_IN_PROGRESS_TABLE as so, STAGING_STALE_MINUTES as co, _voltroReplaceInProgressTable as lo, interruptedReplaceRefusal as uo, stagingLeftoverReport as fo, stagingLeftovers as po, stagingNamesOf as mo, stagingStaleAfterMs as ho } from "./replaceInProgress.js";
|
|
68
|
+
import { stampGeneratedId as go, stampGeneratedIds as _o } from "./stampId.js";
|
|
69
|
+
import { BULK_INSERT_LIMITS as vo, bulkInsertLimitsFor as yo, chunkRowsForInsert as bo, columnsPerRow as xo } from "./bulkInsertLimits.js";
|
|
70
|
+
import { missingConflictColumns as So, missingRequiredColumns as Co } from "./requiredColumns.js";
|
|
71
|
+
import { insertIgnoreRowOutcome as wo, insertManyRows as To, insertRow as Eo, updateManyRow as Do, upsertRow as Oo, upsertRowOutcome as ko } from "./typedStore.js";
|
|
72
|
+
import { CHANGE_LISTENER_CEILING as Ao, raiseChangeListenerCeiling as jo } from "./changeListenerCeiling.js";
|
|
73
|
+
import { isPrimaryKeyConflictError as Mo, primaryKeyConflictError as No } from "./storeErrors.js";
|
|
74
|
+
import { connectionIdentity as Po, normaliseTarget as Fo, sameDatabase as Io } from "./connectionIdentity.js";
|
|
75
|
+
import { clearRetentions as Lo, listRetentionConflicts as Ro, listRetentions as zo, registerRetention as Bo, retentionTtlMsFromEnv as Vo, sweepRetention as Ho } from "./retention.js";
|
|
76
|
+
import { CDC_OFFSETS_TABLE as Uo, _voltroCdcOffsetsTable as Wo, _voltroMssqlCdcOffsetsTable as Go } from "./cdcOffsetsTables.js";
|
|
77
|
+
import { DATA_TRANSFERS_TABLE as Ko, _voltroDataTransfersTable as qo, describeTransferRun as Jo } from "./dataTransfers.js";
|
|
78
|
+
import { SCOPE_KEY_MAX_LENGTH as Yo, scopeKeyOf as Xo } from "./scopeKey.js";
|
|
79
|
+
import { SqlClient as Zo } from "effect/sql";
|
|
80
|
+
//#region src/index.ts
|
|
81
|
+
var Qo = "postgres";
|
|
2183
82
|
//#endregion
|
|
2184
|
-
export { ut as AUTO_FILLED_COLUMNS, qr as BOUND_ENCRYPTED_PREFIX, Ml as BULK_INSERT_LIMITS, q as BranchNameInvalid, Rc as BranchTransitionInvalid, uu as CDC_OFFSETS_TABLE, Vo as CHANGE_CLAIM_TTL_ENV, Wl as CHANGE_LISTENER_CEILING, f as ColumnBuilder, pu as DATA_TRANSFERS_TABLE, Oe as DEFAULT_ACQUIRE_TIMEOUT_MS, Ho as DEFAULT_CHANGE_CLAIM_TTL_HOURS, qs as DEFAULT_EAGER_FALLBACK_WARN_INTERVAL_MS, $e as DEFAULT_SOFT_DROP_RETENTION_DAYS, Bi as DEFAULT_SUBJECT_GRAPH_DEPTH, Kr as ENCRYPTED_PREFIX, yu as ENGINE, ca as EagerCardinalityError, Ae as FILE_MIGRATION_PATTERN, u as FRAMEWORK_LIVE_TABLES, Xr as FieldDecryptionError, hs as ID_COLUMN_MAX_LENGTH, Er as INITIAL_VERSION, Pe as IrreversibleMigrationError, _t as MATCHES_NO_ROWS, t as MAX_IDENTIFIER_LENGTH, He as MIGRATION_PHASES, pc as MSSQL_TRANSIENT_NUMBERS, dc as MYSQL_TRANSIENT_CODES, re as MigrationExpectationFailed, he as MigrationNeedsSqlClient, De as MigrationSkipped, Bo as OccurrenceCounter, fc as POSTGRES_TRANSIENT_STATES, Yn as REPLACE_IN_PROGRESS_TABLE, Ye as RewriteUnstableError, gu as SCOPE_KEY_MAX_LENGTH, cr as SELF_REFERENCE_TARGET, tc as SHARED_TRANSACTION_SERVICE, mc as SQLITE_TRANSIENT_CODES, Dn as STAGING_STALE_MINUTES, or as STAGING_TABLE_PREFIX, Rr as SqlClient, Tl as TENANT_SELECTIONS_TABLE, hc as TURSO_TRANSIENT_MESSAGE, Ec as TableStreamError, Ne as TenantNamespaceInvalid, Le as TenantNamespaceUnresolved, rl as TenantRegionUnavailable, nl as TenantResidencyUnresolved, ac as TransactionAbortedError, vr as TransactionBrokenByBodyError, bc as VOLTRO_EXPIRES_MIXIN_ID, Sc as VOLTRO_LOCAL_FIRST_MIXIN_ID, Cr as VersionConflict, Kt as WARN_IDENTIFIER_LENGTH, yn as _voltroApiKeysTable, du as _voltroCdcOffsetsTable, mu as _voltroDataTransfersTable, $n as _voltroDevicesTable, Ht as _voltroIdempotencyTable, Jt as _voltroKvTable, Fn as _voltroMigrationPlansTable, Cn as _voltroMigrationsTable, fu as _voltroMssqlCdcOffsetsTable, nn as _voltroPluginMigrationsTable, Vn as _voltroReplaceInProgressTable, Qt as _voltroReplicaObservationsTable, Et as _voltroSchemaOwnerTable, rr as _voltroSeedsTable, mr as _voltroTenantSelectionsTable, To as actorsTable, Zc as admitBranch, rt as agedSoftDropSnapshots, Ot as allEnumRenames, Li as allRegisteredRelations, gn as allRegisteredTables, Ct as and, oa as applyJsonPatch, at as array, Ke as arrayContains, e as arrayHas, qt as arrayOverlaps, ua as attachEagerLoads, qo as attributionFields, ts as attributionKey, gl as auditAllTableIndexes, hl as auditTableIndexes, S as authoredError, qn as authoredMessageOf, jt as avg, Nn as avgOver, us as beginLocalWrite, te as bigint, dl as bindResidentStore, g as boolean, Fc as branchNamespaceName, Nl as bulkInsertLimitsFor, Be as bytes, Bt as causeBranches, ko as changeDelete, Lo as changeDigest, Do as changeInsert, Ao as changeSoftDelete, Oo as changeUpdate, Fl as chunkRowsForInsert, is as claimPendingAttribution, xn as classifyConstraintViolation, ir as clearEnumRenames, ps as clearPendingAttribution, zi as clearRelationsRegistry, sl as clearResidencyConfig, au as clearRetentions, r as clearTableRegistry, Ss as clearWriteRecorders, H as coercePredicateForSqlite, a as coercePredicateValue, mn as coercePredicateValues, Qe as coerceValueForSqlite, Qn as collectSubqueries, Kn as column, xr as columnRef, pi as columnSchema, Pl as columnsPerRow, Fo as committedChangeBatchOf, ft as compareDecimal, ba as compileEagerJson, sa as compileJsonPatch, y as compilePredicate, ne as compileRawFragment, _ as compileRowProjection, Ve as compileSelect, Ro as composeChangeKey, jc as computeEmbedding, Zl as connectionIdentity, jn as contains, zt as count, bn as countDistinct, _n as crdtCounter, i as crdtDoc, pn as crdtManagedColumns, Me as crdtManagedColumnsOf, Ie as crdtSealed, We as crdtText, Ko as currentWriteAttribution, er as databaseHandle, ae as date, _e as dbEnum, Vs as dbMetricTagCacheSizeForTests, Ws as dbOperationsInFlight, ke as decimal, gr as declareEnumRename, ti as decodeFieldValue, gt as decodeRowsForTable, ue as decodeRowsFromSchema, li as decryptFieldsOnRead, Cl as defineMigration, ce as defineMixin, pt as defineSeed, kl as deleteTenantSelection, Ut as denseRank, Zi as deriveSubjectGraph, be as deriveTypeIdPrefix, vs as derivedRowId, ys as derivedRowIdLength, v as describeAgedSoftDropSnapshots, tr as describeCharsetRefusal, Wt as describeDriverError, Xt as describeRowBindings, hu as describeTransferRun, Gr as deserializeArraysOnRead, Zn as drainIdentifierWarnings, Ze as dropped, Po as emitCommittedChanges, $r as encodeFieldValue, Ee as encodeRowForSchema, oi as encryptFieldsForWrite, si as encryptFieldsForWriteBatch, ii as encryptedColumnsOf, ds as endLocalWrite, Jc as enforceBranchLimits, fn as ensureTableRegistered, Wn as eq, vn as escapeLike, un as evaluatePredicate, Yt as except, Nt as exists, xc as expires, Eo as externalChangeEvent, Ln as extractDbCause, Jr as fieldBinding, se as fireSchemaChangeSeeds, Ce as fireTenantCreateSeeds, xl as formatIndexAuditIssue, Qi as formatSubjectGraph, Pt as frameworkTables, xt as generateId, wt as generateSnowflake, br as geography, c as geometry, It as getEnumRenames, Ii as getRelation, Fi as getRelations, ol as getResidencyConfig, je as getTable, Pn as gt, Jn as gte, ya as hasEagerLoads, Ac as hybridSearch, dt as id, Vt as inSet, Sn as inSubquery, Ei as inferForeignKey, Hl as insertIgnoreRowOutcome, zl as insertManyRows, Rl as insertRow, pe as integer, sn as interruptedReplaceRefusal, In as intersect, st as interval, o as irreversible, lt as irreversibleReason, Yr as isBoundCiphertext, Ic as isBranchNamespace, l as isColumnReference, ra as isCompositeRowKey, xi as isEmptyRelationsSpec, Qr as isEncrypted, Zr as isFieldDecryptionError, de as isFileMigration, Tn as isForeignKeyViolation, m as isFrameworkOwnedLiveTable, wc as isLocalFirst, wl as isMigrationDefinition, Xe as isMysqlFamily, Hc as isNeonConnection, nr as isNotNull, Gt as isNull, ql as isPrimaryKeyConflictError, an as isQueryTimeout, ni as isRawEncoding, ll as isRegionServable, Si as isRelationsSpec, zn as isSeedDefinition, Re as isSoftDropSnapshotName, yr as isSqliteFamily, hn as isStagingTableName, Fe as isTableReactive, cc as isTransactionAbortedError, vc as isTransientContention, Xn as isView, ht as json, Zt as jsonField, fe as jsonIndex, ia as jsonPatchAssignments, wn as lag, rn as lead, nu as listRetentionConflicts, iu as listRetentions, Cc as localFirst, Tc as localFirstTables, Rn as lt, En as lte, Xs as makeEagerFallbackReporter, tl as makeNamespaceBranchExecutor, oc as makeTransactionAbortTracker, wi as many, Ti as manyToMany, le as materializeFields, $t as max, ot as migration, Dt as min, Ll as missingConflictColumns, Il as missingRequiredColumns, we as mixin, on as neq, zc as nextBranchState, Xl as normaliseTarget, aa as normalizeJsonPatchValue, tn as not, kt as notExists, ar as notInSet, _r as notInSubquery, Te as numeric, Ks as observeDbOp, Uo as occurrenceWindowMs, rc as onTransaction, Ci as one, la as oneCardinalityMessage, Lt as or, T as orderClausesOf, hr as paginateBy, Ft as paginateById, zo as parseChangeKey, ms as pendingAttributionCount, C as persistedColumns, Kc as planBranch, Bc as planBranchProvision, Vc as planBranchTeardown, qc as planBranchTeardownFor, Wc as planNeonBranchProvision, Gc as planNeonBranchTeardown, Sr as planVersionedUpdate, fr as pluginRef, tt as pluginRefSpecOf, pr as preparePredicate, Kl as primaryKeyConflictError, Yc as provisionBranch, fl as provisionResidentTenant, Ge as qualifyTable, dr as queryFor, kn as queryForView, s as quoteIdent, Gl as raiseChangeListenerCeiling, et as rank, xe as raw, Dl as readTenantSelection, St as readableByColumns, yt as real, Gs as recordDbOp, Ds as recordsTable, Tt as reference, di as refuseWrite, xo as registerCoreTables, Pi as registerDiscoveredRelations, rs as registerPendingAttribution, Ni as registerRelations, ru as registerRetention, Ue as registerTable, bs as registerWriteRecorder, bi as relations, Co as requireActors, ie as requireTable, wo as requireTenants, Bs as resetDbMetricTagCacheForTests, qe as resetSnowflake, ul as residentPlacement, Vr as resolveActorSnapshot, Uc as resolveBranchMechanism, Ys as resolveEagerFallbackWarnIntervalMs, fs as resolveEchoAttribution, d as resolveFullTextIndex, vt as resolveIdScheme, Bn as resolveMixinGraph, cl as resolveTenantHome, oe as resolveTenantNamespace, lu as retentionTtlMsFromEnv, ta as rowKeyColumns, na as rowKeyIdentity, sr as rowNumber, mi as rowSchema, ic as runRetryingTransaction, sc as runSavepoint, uc as runStoreTransaction, Go as runWithWriteAttribution, Os as runWriteRecorders, Ql as sameDatabase, ve as sanitizeIdentifierFragment, vu as scopeKeyOf, Je as selfReference, Wr as serializeArraysForWrite, n as serverOnlyColumns, al as setResidencyConfig, ye as setSchemaChangeSeedHook, bt as setTenantCreateSeedHook, Zs as settleTransactionExit, Tr as settleVersionedUpdate, dn as softDropSnapshotStamp, nt as spatialPredicate, ur as sqlError, At as stagingLeftoverReport, Mn as stagingLeftovers, Gn as stagingNamesOf, Rt as stagingStaleAfterMs, Al as stampGeneratedId, jl as stampGeneratedIds, p as startsWith, fi as storeRefusalOf, kc as streamTable, it as sum, ee as sumOver, ws as suspendWriteRecorders, Ts as suspendWriteRecordersEffect, ou as sweepRetention, b as table, Xc as teardownBranch, El as tenantSelectionId, x as text, w as timestamp, Or as timestampMs, wr as timestampMsOrNull, ec as transactionRetrySchedule, h as union, ze as unionAll, ge as unregisterTable, xs as unregisterWriteRecorder, Ul as updateManyRow, Bl as upsertRow, Vl as upsertRowOutcome, ea as upsertUpdatePatch, $i as upsertUpdateValues, An as validateColumnName, Un as validateIndexName, Ri as validateRegisteredRelations, Ai as validateRelationConfig, ln as validateTableName, Mt as validateTypeIdPrefix, On as vector, mt as vectorDistanceToOpclass, Mc as vectorEmbedding, Dr as versionColumnOf, Hn as view, cn as viewSql, lr as walkLeaves, en as wireSafeCause, Jo as withCapturedAttribution, Es as writeRecordersSuspended, Ol as writeTenantSelection };
|
|
83
|
+
export { _t as AUTO_FILLED_COLUMNS, Ne as BOUND_ENCRYPTED_PREFIX, vo as BULK_INSERT_LIMITS, Ii as BranchNameInvalid, Li as BranchTransitionInvalid, Uo as CDC_OFFSETS_TABLE, wr as CHANGE_CLAIM_TTL_ENV, Ao as CHANGE_LISTENER_CEILING, e as ColumnBuilder, Ko as DATA_TRANSFERS_TABLE, xt as DEFAULT_ACQUIRE_TIMEOUT_MS, Tr as DEFAULT_CHANGE_CLAIM_TTL_HOURS, ti as DEFAULT_EAGER_FALLBACK_WARN_INTERVAL_MS, Na as DEFAULT_SOFT_DROP_RETENTION_DAYS, Mn as DEFAULT_SUBJECT_GRAPH_DEPTH, Pe as ENCRYPTED_PREFIX, Qo as ENGINE, Jn as EagerCardinalityError, Fe as FIELD_KEY_ID_PATTERN, xa as FILE_MIGRATION_PATTERN, Pa as FRAMEWORK_LIVE_TABLES, Ie as FieldDecryptionError, Ur as ID_COLUMN_MAX_LENGTH, cn as INITIAL_VERSION, Sa as IrreversibleMigrationError, Z as MATCHES_NO_ROWS, $e as MAX_IDENTIFIER_LENGTH, Ca as MIGRATION_PHASES, yi as MSSQL_TRANSIENT_NUMBERS, bi as MYSQL_TRANSIENT_CODES, wa as MigrationExpectationFailed, Ta as MigrationNeedsSqlClient, Ea as MigrationSkipped, Er as OccurrenceCounter, xi as POSTGRES_TRANSIENT_STATES, so as REPLACE_IN_PROGRESS_TABLE, Da as RewriteUnstableError, Yo as SCOPE_KEY_MAX_LENGTH, t as SELF_REFERENCE_TARGET, li as SHARED_TRANSACTION_SERVICE, Si as SQLITE_TRANSIENT_CODES, co as STAGING_STALE_MINUTES, Fa as STAGING_TABLE_PREFIX, Zo as SqlClient, no as TENANT_SELECTIONS_TABLE, Ci as TURSO_TRANSIENT_MESSAGE, ji as TableStreamError, $n as TenantNamespaceInvalid, er as TenantNamespaceUnresolved, ea as TenantRegionUnavailable, ta as TenantResidencyUnresolved, ui as TransactionAbortedError, Oa as TransactionBrokenByBodyError, Ti as VOLTRO_EXPIRES_MIXIN_ID, Di as VOLTRO_LOCAL_FIRST_MIXIN_ID, ln as VersionConflict, et as WARN_IDENTIFIER_LENGTH, Ua as _voltroApiKeysTable, Wa as _voltroApiRoleWorkloadBucketsTable, Wo as _voltroCdcOffsetsTable, qo as _voltroDataTransfersTable, Ga as _voltroDevicesTable, Ka as _voltroIdempotencyTable, qa as _voltroKvTable, Ja as _voltroMigrationPlansTable, Ya as _voltroMigrationsTable, Go as _voltroMssqlCdcOffsetsTable, Xa as _voltroPluginMigrationsTable, lo as _voltroReplaceInProgressTable, Za as _voltroReplicaObservationsTable, Qa as _voltroSchemaOwnerTable, $a as _voltroSeedsTable, eo as _voltroTenantSelectionsTable, gr as actorsTable, Xi as admitBranch, Ia as agedSoftDropSnapshots, De as allEnumRenames, Tn as allRegisteredRelations, Tt as allRegisteredTables, Q as and, Gn as applyJsonPatch, n as array, $ as arrayContains, ee as arrayHas, te as arrayOverlaps, Yn as attachEagerLoads, jr as attributionFields, Fr as attributionKey, ua as auditAllTableIndexes, da as auditTableIndexes, R as authoredError, z as authoredMessageOf, Nt as avg, Pt as avgOver, Ir as beginLocalWrite, r as bigint, na as bindResidentStore, i as boolean, Ri as branchNamespaceName, yo as bulkInsertLimitsFor, a as bytes, B as causeBranches, _r as changeDelete, Dr as changeDigest, vr as changeInsert, yr as changeSoftDelete, br as changeUpdate, bo as chunkRowsForInsert, Le as ciphertextKeyId, Lr as claimPendingAttribution, V as classifyConstraintViolation, Oe as clearEnumRenames, Rr as clearPendingAttribution, En as clearRelationsRegistry, ra as clearResidencyConfig, Lo as clearRetentions, Et as clearTableRegistry, Kr as clearWriteRecorders, dr as coercePredicateForSqlite, ir as coercePredicateValue, ar as coercePredicateValues, Qn as coerceValueForSqlite, ne as collectSubqueries, Ft as column, I as columnRef, hn as columnSchema, xo as columnsPerRow, Sr as committedChangeBatchOf, Y as compareDecimal, fr as compileEagerJson, Kn as compileJsonPatch, or as compilePredicate, sr as compileRawFragment, cr as compileRowProjection, lr as compileSelect, Or as composeChangeKey, Pi as computeEmbedding, Po as connectionIdentity, re as contains, It as count, Lt as countDistinct, o as crdtCounter, s as crdtDoc, c as crdtManagedColumns, l as crdtManagedColumnsOf, u as crdtSealed, d as crdtText, Mr as currentWriteAttribution, Rt as databaseHandle, f as date, p as dbEnum, ni as dbMetricTagCacheSizeForTests, ri as dbOperationsInFlight, m as decimal, X as decimalEqualityKey, ke as declareEnumRename, Re as decodeFieldValue, Fn as decodeRowsForTable, In as decodeRowsFromSchema, Ln as decodeSelectRows, ze as decryptFieldsOnRead, ya as defineMigration, mt as defineMixin, pa as defineSeed, ro as deleteTenantSelection, zt as denseRank, Nn as deriveSubjectGraph, dt as deriveTypeIdPrefix, Wr as derivedRowId, Gr as derivedRowIdLength, La as describeAgedSoftDropSnapshots, H as describeCharsetRefusal, U as describeDriverError, W as describeRowBindings, Jo as describeTransferRun, je as deserializeArraysOnRead, tt as drainIdentifierWarnings, h as dropped, Cr as emitCommittedChanges, Be as encodeFieldValue, Rn as encodeRowForSchema, ot as encodeTypeIdSuffix, Ve as encryptFieldsForWrite, He as encryptFieldsForWriteBatch, Ue as encryptedColumnsOf, zr as endLocalWrite, zi as enforceBranchLimits, Dt as ensureTableRegistered, ie as eq, ur as escapeLike, ae as evaluatePredicate, Bt as except, oe as exists, Ei as expires, xr as externalChangeEvent, G as extractDbCause, We as fieldBinding, Ge as fieldBindingsOf, ma as fireSchemaChangeSeeds, ha as fireTenantCreateSeeds, fa as formatIndexAuditIssue, Pn as formatSubjectGraph, to as frameworkTables, ft as generateId, lt as generateSnowflake, g as geography, _ as geometry, Ae as getEnumRenames, Dn as getRelation, On as getRelations, ia as getResidencyConfig, Ot as getTable, se as gt, ce as gte, Xn as hasEagerLoads, Ni as hybridSearch, v as id, le as inSet, ue as inSubquery, _n as inferForeignKey, wo as insertIgnoreRowOutcome, To as insertManyRows, Eo as insertRow, y as integer, uo as interruptedReplaceRefusal, Vt as intersect, b as interval, ka as irreversible, Aa as irreversibleReason, Ke as isBoundCiphertext, Bi as isBranchNamespace, L as isColumnReference, Vn as isCompositeRowKey, vn as isEmptyRelationsSpec, qe as isEncrypted, Je as isFieldDecryptionError, ja as isFileMigration, K as isForeignKeyViolation, Ra as isFrameworkOwnedLiveTable, Oi as isLocalFirst, ba as isMigrationDefinition, St as isMysqlFamily, Vi as isNeonConnection, de as isNotNull, fe as isNull, Mo as isPrimaryKeyConflictError, q as isQueryTimeout, Ye as isRawEncoding, aa as isRegionServable, yn as isRelationsSpec, ga as isSeedDefinition, za as isSoftDropSnapshotName, Ct as isSqliteFamily, Ba as isStagingTableName, kt as isTableReactive, di as isTransactionAbortedError, wi as isTransientContention, rn as isView, x as json, pe as jsonField, vt as jsonIndex, Wn as jsonPatchAssignments, Ht as lag, Ut as lead, Ro as listRetentionConflicts, zo as listRetentions, ki as localFirst, Ai as localFirstTables, me as lt, he as lte, ii as makeEagerFallbackReporter, Zi as makeNamespaceBranchExecutor, fi as makeTransactionAbortTracker, bn as many, xn as manyToMany, S as materializeFields, Wt as max, Ma as migration, Gt as min, So as missingConflictColumns, Co as missingRequiredColumns, ht as mixin, ge as neq, Hi as nextBranchState, Fo as normaliseTarget, qn as normalizeJsonPatchValue, _e as not, ve as notExists, ye as notInSet, be as notInSubquery, C as numeric, ai as observeDbOp, kr as occurrenceWindowMs, pi as onTransaction, Sn as one, Zn as oneCardinalityMessage, xe as or, Kt as orderClausesOf, qt as paginateBy, Jt as paginateById, Ar as parseChangeKey, Br as pendingAttributionCount, w as persistedColumns, Ui as planBranch, Wi as planBranchProvision, Gi as planBranchTeardown, Ki as planBranchTeardownFor, qi as planNeonBranchProvision, Ji as planNeonBranchTeardown, un as planVersionedUpdate, P as pluginRef, F as pluginRefSpecOf, Se as preparePredicate, No as primaryKeyConflictError, Qi as provisionBranch, oa as provisionResidentTenant, tr as qualifyTable, Yt as queryFor, an as queryForView, wt as quoteIdent, jo as raiseChangeListenerCeiling, Xt as rank, T as raw, io as readTenantSelection, E as readableByColumns, D as real, oi as recordDbOp, qr as recordsTable, O as reference, Xe as refuseIdChangeOfSealedRow, Ze as refuseWrite, pr as registerCoreTables, kn as registerDiscoveredRelations, Vr as registerPendingAttribution, An as registerRelations, Bo as registerRetention, At as registerTable, Jr as registerWriteRecorder, Cn as relations, mr as requireActors, jt as requireTable, hr as requireTenants, si as resetDbMetricTagCacheForTests, ut as resetSnowflake, sa as residentPlacement, Ee as resolveActorSnapshot, Yi as resolveBranchMechanism, ci as resolveEagerFallbackWarnIntervalMs, Hr as resolveEchoAttribution, Zt as resolveFullTextIndex, pt as resolveIdScheme, gt as resolveMixinGraph, ca as resolveTenantHome, nr as resolveTenantNamespace, Vo as retentionTtlMsFromEnv, Hn as rowKeyColumns, Un as rowKeyIdentity, Qt as rowNumber, gn as rowSchema, mi as runRetryingTransaction, hi as runSavepoint, gi as runStoreTransaction, Nr as runWithWriteAttribution, Yr as runWriteRecorders, Io as sameDatabase, rr as sanitizeIdentifierFragment, Xo as scopeKeyOf, k as selfReference, Me as serializeArraysForWrite, A as serverOnlyColumns, la as setResidencyConfig, _a as setSchemaChangeSeedHook, va as setTenantCreateSeedHook, _i as settleTransactionExit, dn as settleVersionedUpdate, Va as softDropSnapshotStamp, Ce as spatialPredicate, Ha as sqlError, fo as stagingLeftoverReport, po as stagingLeftovers, mo as stagingNamesOf, ho as stagingStaleAfterMs, go as stampGeneratedId, _o as stampGeneratedIds, we as startsWith, Qe as storeRefusalOf, Mi as streamTable, $t as sum, en as sumOver, Xr as suspendWriteRecorders, Zr as suspendWriteRecordersEffect, Ho as sweepRetention, yt as table, $i as teardownBranch, ao as tenantSelectionId, j as text, M as timestamp, pn as timestampMs, mn as timestampMsOrNull, vi as transactionRetrySchedule, st as typeId, tn as union, nn as unionAll, Mt as unregisterTable, Qr as unregisterWriteRecorder, Do as updateManyRow, Oo as upsertRow, ko as upsertRowOutcome, zn as upsertUpdatePatch, Bn as upsertUpdateValues, ct as uuidV7Bytes, nt as validateColumnName, rt as validateIndexName, jn as validateRegisteredRelations, wn as validateRelationConfig, it as validateTableName, at as validateTypeIdPrefix, N as vector, bt as vectorDistanceToOpclass, Fi as vectorEmbedding, fn as versionColumnOf, on as view, sn as viewSql, Te as walkLeaves, J as wireSafeCause, Pr as withCapturedAttribution, $r as writeImagesObserved, ei as writeRecordersSuspended, oo as writeTenantSelection };
|