@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/dbCause.js
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { Cause as e, Exit as t } from "effect";
|
|
2
|
+
//#region src/dbCause.ts
|
|
3
|
+
var n = (n) => e.isCause(n) ? n : t.isExit(n) && t.isFailure(n) ? n.cause : typeof n == "object" && n && e.isCause(n.voltroCause) ? n.voltroCause : void 0, r = (t) => {
|
|
4
|
+
let r = n(t);
|
|
5
|
+
return r === void 0 ? t : e.squash(r);
|
|
6
|
+
}, i = (t, r = 0) => {
|
|
7
|
+
let a = r >= 4 ? void 0 : n(t);
|
|
8
|
+
if (a === void 0) return [t];
|
|
9
|
+
let o = a.reasons.flatMap((t) => e.isFailReason(t) ? [t.error] : e.isDieReason(t) ? [t.defect] : []);
|
|
10
|
+
if (o.length === 0) return [e.squash(a)];
|
|
11
|
+
let s = [];
|
|
12
|
+
for (let e of o.slice(0, 8)) s.push(...i(e, r + 1));
|
|
13
|
+
return s;
|
|
14
|
+
}, a = (e) => e.dbCode !== void 0 || e.dbErrno !== void 0 || e.dbNumber !== void 0 || e.dbSqlState !== void 0 || e.dbConstraint !== void 0, o = {
|
|
15
|
+
9: "SQLITE_INTERRUPT",
|
|
16
|
+
275: "SQLITE_CONSTRAINT_CHECK",
|
|
17
|
+
787: "SQLITE_CONSTRAINT_FOREIGNKEY",
|
|
18
|
+
1299: "SQLITE_CONSTRAINT_NOTNULL",
|
|
19
|
+
1555: "SQLITE_CONSTRAINT_PRIMARYKEY",
|
|
20
|
+
2067: "SQLITE_CONSTRAINT_UNIQUE"
|
|
21
|
+
}, s = (e) => {
|
|
22
|
+
let t = {}, n = [], i = r(e);
|
|
23
|
+
for (let e = 0; e < 8 && typeof i == "object" && i; e++) {
|
|
24
|
+
let e = i;
|
|
25
|
+
t.dbCode === void 0 && (typeof e.code == "string" || typeof e.code == "number") && (t.dbCode = e.code), t.dbErrno === void 0 && typeof e.errno == "number" && (t.dbErrno = e.errno), t.dbErrno === void 0 && typeof e.errcode == "number" && (t.dbErrno = e.errcode), t.dbCode === "ERR_SQLITE_ERROR" && typeof t.dbErrno == "number" && (t.dbCode = o[t.dbErrno] ?? t.dbCode), t.dbNumber === void 0 && typeof e.number == "number" && (t.dbNumber = e.number), t.dbSqlState === void 0 && typeof e.sqlState == "string" && (t.dbSqlState = e.sqlState), t.dbBindings === void 0 && typeof e.voltroBindings == "string" && (t.dbBindings = e.voltroBindings), t.dbStatement === void 0 && typeof e.sql == "string" && e.sql.includes("?") && (t.dbStatement = e.sql, t.dbPlaceholders = (e.sql.match(/\?/g) ?? []).length), t.dbFatal === void 0 && typeof e.fatal == "boolean" && (t.dbFatal = e.fatal), t.dbConstraint === void 0 && typeof e.constraint == "string" && (t.dbConstraint = e.constraint), t.dbTable === void 0 && typeof e.table == "string" && (t.dbTable = e.table), t.dbColumn === void 0 && typeof e.column == "string" && (t.dbColumn = e.column), t.dbSchema === void 0 && typeof e.schema == "string" && (t.dbSchema = e.schema);
|
|
26
|
+
let a = e.sqlMessage ?? e.detail;
|
|
27
|
+
t.dbMessage === void 0 && typeof a == "string" && (t.dbMessage = a);
|
|
28
|
+
let s = typeof e.constructor == "function" ? e.constructor.name : void 0, c = typeof e._tag == "string" && e._tag || typeof e.name == "string" && e.name || (typeof s == "string" && s !== "Object" ? s : void 0), l = typeof e.message == "string" ? e.message : void 0;
|
|
29
|
+
(c || l) && n.push(`${c || "Error"}${l ? `: ${l.slice(0, 200)}` : ""}`), i = r(e.reason ?? e.cause);
|
|
30
|
+
}
|
|
31
|
+
return n.length > 0 && (t.dbCauseChain = n.join(" ← "), t.dbMessage === void 0 && (t.dbMessage = n[n.length - 1])), t;
|
|
32
|
+
}, c = (e) => {
|
|
33
|
+
let t = i(e).map(s);
|
|
34
|
+
if (t.length <= 1) return t[0] ?? {};
|
|
35
|
+
let n = t.find(a) ?? t[0], r = t.filter((e) => e !== n).map((e) => e.dbCauseChain).filter((e) => typeof e == "string");
|
|
36
|
+
if (r.length === 0) return n;
|
|
37
|
+
let o = typeof n.dbCauseChain == "string" ? n.dbCauseChain : void 0;
|
|
38
|
+
return {
|
|
39
|
+
...n,
|
|
40
|
+
dbCauseChain: [o, ...r].filter(Boolean).join(" ‖ ")
|
|
41
|
+
};
|
|
42
|
+
}, l = (e, t) => {
|
|
43
|
+
let n = f(e);
|
|
44
|
+
if (n !== void 0) return n;
|
|
45
|
+
let r = c(e), i = b(r, t);
|
|
46
|
+
if (i !== void 0) {
|
|
47
|
+
let e = i.constraint ?? i.column;
|
|
48
|
+
return e === void 0 ? i.kind : `${i.kind}: ${e}`;
|
|
49
|
+
}
|
|
50
|
+
let a = r.dbCode ?? r.dbSqlState ?? r.dbErrno ?? r.dbNumber, o = h(e);
|
|
51
|
+
return a !== void 0 && p.test(String(a)) ? `${o} (${String(a)})` : o;
|
|
52
|
+
}, u = Symbol.for("@voltro/database/authoredMessage"), d = (e, t) => {
|
|
53
|
+
let n = t === void 0 ? Error(e) : Error(e, t);
|
|
54
|
+
return Object.defineProperty(n, u, {
|
|
55
|
+
value: !0,
|
|
56
|
+
enumerable: !1
|
|
57
|
+
}), n;
|
|
58
|
+
}, f = (e) => {
|
|
59
|
+
for (let t of i(e)) {
|
|
60
|
+
let e = t;
|
|
61
|
+
for (let t = 0; typeof e == "object" && e && t < 8; t += 1) {
|
|
62
|
+
if (e[u] === !0) {
|
|
63
|
+
let t = e.message;
|
|
64
|
+
if (typeof t == "string" && t.length > 0) return t;
|
|
65
|
+
}
|
|
66
|
+
e = e.cause;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}, p = /^[A-Za-z0-9_]{1,32}$/, m = /^[A-Za-z_][A-Za-z0-9_]{0,63}$/, h = (e) => {
|
|
70
|
+
let t = e?._tag, n = e?.name, r = (typeof t == "string" ? t : typeof n == "string" ? n : "").split(/[^A-Za-z0-9_]+/).filter(Boolean).pop();
|
|
71
|
+
return r !== void 0 && m.test(r) ? r : "unknown";
|
|
72
|
+
}, g = /^[A-Za-z_][A-Za-z0-9_$]*$/, _ = (e) => e !== void 0 && e.length <= 128 && g.test(e) ? e : void 0, v = (e) => e === void 0 ? void 0 : e.split(".").pop() ?? e, y = (e, ...t) => {
|
|
73
|
+
for (let n of t) {
|
|
74
|
+
let t = n.exec(e);
|
|
75
|
+
if (t?.[1] !== void 0) return t[1];
|
|
76
|
+
}
|
|
77
|
+
}, b = (e, t) => {
|
|
78
|
+
let n = e.dbCode, r = e.dbErrno, i = e.dbNumber, a = typeof e.dbMessage == "string" ? e.dbMessage : "", o = `${typeof e.dbCauseChain == "string" ? e.dbCauseChain : ""} ${a}`;
|
|
79
|
+
if (n === "23503") {
|
|
80
|
+
let t = _(e.dbConstraint);
|
|
81
|
+
return {
|
|
82
|
+
kind: /is still referenced from table/i.test(o) ? "foreignKeyInUse" : "foreignKey",
|
|
83
|
+
...t === void 0 ? {} : { constraint: t }
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
if (n === "23505") {
|
|
87
|
+
let t = _(e.dbConstraint);
|
|
88
|
+
return {
|
|
89
|
+
kind: "unique",
|
|
90
|
+
...t === void 0 ? {} : { constraint: t }
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
if (n === "23502") {
|
|
94
|
+
let t = _(e.dbColumn);
|
|
95
|
+
return {
|
|
96
|
+
kind: "notNull",
|
|
97
|
+
...t === void 0 ? {} : { column: t }
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
if (n === "23514") {
|
|
101
|
+
let t = _(e.dbConstraint);
|
|
102
|
+
return {
|
|
103
|
+
kind: "check",
|
|
104
|
+
...t === void 0 ? {} : { constraint: t }
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
if (r === 1452 || r === 1451) {
|
|
108
|
+
let e = _(y(o, /CONSTRAINT `([^`]+)`/));
|
|
109
|
+
return {
|
|
110
|
+
kind: r === 1451 ? "foreignKeyInUse" : "foreignKey",
|
|
111
|
+
...e === void 0 ? {} : { constraint: e }
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
if (r === 1062) {
|
|
115
|
+
let e = _(v(y(o, /for key '([^']+)'/)));
|
|
116
|
+
return {
|
|
117
|
+
kind: "unique",
|
|
118
|
+
...e === void 0 ? {} : { constraint: e }
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
if (r === 1048 || r === 1364) {
|
|
122
|
+
let e = _(y(o, /Column '([^']+)' cannot be null/, /Field '([^']+)' doesn't have a default value/));
|
|
123
|
+
return {
|
|
124
|
+
kind: "notNull",
|
|
125
|
+
...e === void 0 ? {} : { column: e }
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
if (r === 3819 || r === 4025) {
|
|
129
|
+
let e = _(y(o, /Check constraint '([^']+)'/, /CONSTRAINT `([^`]+)` failed/));
|
|
130
|
+
return {
|
|
131
|
+
kind: "check",
|
|
132
|
+
...e === void 0 ? {} : { constraint: e }
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
if (i === 547) {
|
|
136
|
+
let e = y(o, /(?:FOREIGN KEY|REFERENCE) constraint "([^"]+)"/), t = y(o, /CHECK constraint "([^"]+)"/);
|
|
137
|
+
if (t !== void 0 && e === void 0) {
|
|
138
|
+
let e = _(t);
|
|
139
|
+
return {
|
|
140
|
+
kind: "check",
|
|
141
|
+
...e === void 0 ? {} : { constraint: e }
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
let n = /REFERENCE constraint/.test(o), r = _(e);
|
|
145
|
+
return {
|
|
146
|
+
kind: n ? "foreignKeyInUse" : "foreignKey",
|
|
147
|
+
...r === void 0 ? {} : { constraint: r }
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
if (i === 2627 || i === 2601) {
|
|
151
|
+
let e = _(y(o, /(?:UNIQUE KEY|PRIMARY KEY) constraint '([^']+)'/, /index '([^']+)'/));
|
|
152
|
+
return {
|
|
153
|
+
kind: "unique",
|
|
154
|
+
...e === void 0 ? {} : { constraint: e }
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
if (i === 515) {
|
|
158
|
+
let e = _(y(o, /Cannot insert the value NULL into column '([^']+)'/));
|
|
159
|
+
return {
|
|
160
|
+
kind: "notNull",
|
|
161
|
+
...e === void 0 ? {} : { column: e }
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
if (n === "SQLITE_CONSTRAINT_FOREIGNKEY") return { kind: t === "delete" || t === "deleteMany" || t === "hardDelete" ? "foreignKeyInUse" : "foreignKey" };
|
|
165
|
+
if (n === "SQLITE_CONSTRAINT_UNIQUE" || n === "SQLITE_CONSTRAINT_PRIMARYKEY") {
|
|
166
|
+
let e = _(v(y(o, /UNIQUE constraint failed: ([^,\s]+)/)));
|
|
167
|
+
return {
|
|
168
|
+
kind: "unique",
|
|
169
|
+
...e === void 0 ? {} : { column: e }
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
if (n === "SQLITE_CONSTRAINT_NOTNULL") {
|
|
173
|
+
let e = _(v(y(o, /NOT NULL constraint failed: ([^,\s]+)/)));
|
|
174
|
+
return {
|
|
175
|
+
kind: "notNull",
|
|
176
|
+
...e === void 0 ? {} : { column: e }
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
if (n === "SQLITE_CONSTRAINT_CHECK") {
|
|
180
|
+
let e = _(y(a, /CHECK constraint failed: (.+)$/));
|
|
181
|
+
return {
|
|
182
|
+
kind: "check",
|
|
183
|
+
...e === void 0 ? {} : { constraint: e }
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
}, x = (e) => {
|
|
187
|
+
let t = b(e)?.kind;
|
|
188
|
+
return t === "foreignKey" || t === "foreignKeyInUse";
|
|
189
|
+
}, S = (e) => {
|
|
190
|
+
let t = e.dbCode, n = e.dbErrno;
|
|
191
|
+
return t === "57014" || n === 3024 || n === 1969 || t === "ETIMEOUT" || t === "SQLITE_INTERRUPT";
|
|
192
|
+
}, C = (e) => {
|
|
193
|
+
if (e.dbErrno !== 1366) return;
|
|
194
|
+
let t = `${typeof e.dbCauseChain == "string" ? e.dbCauseChain : ""} ${typeof e.dbMessage == "string" ? e.dbMessage : ""}`;
|
|
195
|
+
if (/Incorrect string value: '\\x(F[0-4])/i.exec(t) === null) return;
|
|
196
|
+
let n = y(t, /for column [`']?(?:[^`'.]+[`']?\.[`']?)*([^`'.]+)[`']? at row/);
|
|
197
|
+
return `${n === void 0 ? "the column" : `column '${n}'`} is stored in a character set that cannot hold a 4-byte character (utf8mb3). Declare the store's character set in app.config.ts — store: { dialect: 'mariadb' | 'mysql', charset: 'utf8mb4' } — and run \`voltro db plan\`: every declared table is created with it and converted to it.`;
|
|
198
|
+
}, w = (e) => {
|
|
199
|
+
let t = c(e), n = [
|
|
200
|
+
t.dbCode === void 0 ? void 0 : `code=${String(t.dbCode)}`,
|
|
201
|
+
t.dbErrno === void 0 ? void 0 : `errno=${String(t.dbErrno)}`,
|
|
202
|
+
t.dbNumber === void 0 ? void 0 : `number=${String(t.dbNumber)}`,
|
|
203
|
+
t.dbSqlState === void 0 ? void 0 : `sqlState=${String(t.dbSqlState)}`,
|
|
204
|
+
t.dbConstraint === void 0 ? void 0 : `constraint=${String(t.dbConstraint)}`,
|
|
205
|
+
t.dbPlaceholders === void 0 ? void 0 : `placeholders=${String(t.dbPlaceholders)}`
|
|
206
|
+
].filter((e) => e !== void 0), r = typeof e?.message == "string" ? e.message : void 0, i = typeof t.dbMessage == "string" ? t.dbMessage : void 0, a = i === void 0 ? void 0 : n.length > 0 || i !== r && i !== `Error: ${String(r)}` ? i : void 0, o = typeof t.dbBindings == "string" ? `\n bindings: ${t.dbBindings}` : "", s = typeof t.dbStatement == "string" ? `\n statement: ${t.dbStatement.length <= 400 ? t.dbStatement : `${t.dbStatement.slice(0, 400)}…`}` : "";
|
|
207
|
+
if (a === void 0 && n.length === 0) return;
|
|
208
|
+
let l = C(t), u = l === void 0 ? "" : `\n hint: ${l}`;
|
|
209
|
+
return [a, n.length > 0 ? `[${n.join(" ")}]` : void 0].filter((e) => e !== void 0 && e !== "").join(" ") + u + s + o;
|
|
210
|
+
}, T = (e) => Object.entries(e).map(([e, t]) => `${e}:${E(t)}`).join(" "), E = (e) => {
|
|
211
|
+
if (e === null) return "null";
|
|
212
|
+
if (e === void 0) return "undefined";
|
|
213
|
+
if (typeof e == "bigint") return "bigint";
|
|
214
|
+
if (typeof e != "object") return typeof e;
|
|
215
|
+
if (e instanceof Date) return Number.isNaN(e.getTime()) ? "Date(Invalid)" : "Date";
|
|
216
|
+
if (Array.isArray(e)) return "Array";
|
|
217
|
+
if (globalThis.Buffer !== void 0 && globalThis.Buffer.isBuffer(e)) return "Buffer";
|
|
218
|
+
let t = e.constructor?.name;
|
|
219
|
+
return typeof t == "string" && t !== "" ? t : "Object";
|
|
220
|
+
};
|
|
221
|
+
//#endregion
|
|
222
|
+
export { d as authoredError, f as authoredMessageOf, i as causeBranches, b as classifyConstraintViolation, C as describeCharsetRefusal, w as describeDriverError, T as describeRowBindings, c as extractDbCause, x as isForeignKeyViolation, S as isQueryTimeout, l as wireSafeCause };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Context as e, Metric as t } from "effect";
|
|
2
|
+
//#region src/dbMetrics.ts
|
|
3
|
+
var n = t.exponentialBoundaries({
|
|
4
|
+
start: 5e-4,
|
|
5
|
+
factor: 2,
|
|
6
|
+
count: 16
|
|
7
|
+
}), r = t.counter("voltro_db_queries_total", { description: "Database operations executed, by dialect and operation kind." }), i = t.histogram("voltro_db_query_duration_seconds", {
|
|
8
|
+
boundaries: n,
|
|
9
|
+
description: "Database operation duration in seconds, by dialect and operation kind."
|
|
10
|
+
}), a = t.counter("voltro_db_errors_total", { description: "Database operations that threw, by dialect and operation kind." }), o = t.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." }), s = t.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." }), c = e.empty(), l = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map(), f = (e, n) => {
|
|
11
|
+
let o = `${e}\u0000${n}`, s = l.get(o);
|
|
12
|
+
if (s !== void 0) return s;
|
|
13
|
+
let c = (r) => t.withAttributes(t.withAttributes(r, { dialect: e }), { op: n }), u = {
|
|
14
|
+
count: c(r),
|
|
15
|
+
duration: c(i),
|
|
16
|
+
errors: c(a)
|
|
17
|
+
};
|
|
18
|
+
return l.set(o, u), u;
|
|
19
|
+
}, p = () => {
|
|
20
|
+
l.clear(), u.clear(), d.clear();
|
|
21
|
+
}, m = () => l.size + u.size + d.size, h = /* @__PURE__ */ new Map(), g = (e, n) => {
|
|
22
|
+
let r = Math.max(0, (h.get(e) ?? 0) + n);
|
|
23
|
+
r === 0 ? h.delete(e) : h.set(e, r);
|
|
24
|
+
let i = u.get(e);
|
|
25
|
+
i === void 0 && (i = t.withAttributes(o, { dialect: e }), u.set(e, i)), i.updateUnsafe(r, c);
|
|
26
|
+
}, _ = (e) => h.get(e) ?? 0, v = (e) => {
|
|
27
|
+
let t = f(String(e.dialect), e.op);
|
|
28
|
+
t.count.updateUnsafe(1, c), t.duration.updateUnsafe(e.durationMs / 1e3, c), e.status === "error" && t.errors.updateUnsafe(1, c);
|
|
29
|
+
}, y = async (e, t, n) => {
|
|
30
|
+
let r = performance.now(), i = String(e);
|
|
31
|
+
g(i, 1);
|
|
32
|
+
let a = "ok";
|
|
33
|
+
try {
|
|
34
|
+
return await n();
|
|
35
|
+
} catch (e) {
|
|
36
|
+
throw a = "error", e;
|
|
37
|
+
} finally {
|
|
38
|
+
g(i, -1), v({
|
|
39
|
+
dialect: e,
|
|
40
|
+
op: t,
|
|
41
|
+
durationMs: performance.now() - r,
|
|
42
|
+
status: a
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}, b = 3e5, x = (e) => {
|
|
46
|
+
if (e == null || e === "") return;
|
|
47
|
+
let t = Number(e);
|
|
48
|
+
return Number.isFinite(t) && t >= 0 ? Math.floor(t) : void 0;
|
|
49
|
+
}, S = (e, t = process.env) => x(t.VOLTRO_DB_EAGER_FALLBACK_WARN_INTERVAL_MS) ?? x(e) ?? 3e5, C = (e, n = {}) => {
|
|
50
|
+
let r = S(n.warnIntervalMs), i = n.now ?? (() => Date.now()), a = /* @__PURE__ */ new Map();
|
|
51
|
+
return (n) => {
|
|
52
|
+
let o = `${n.dialect} ${n.reason}`, l = d.get(o);
|
|
53
|
+
l === void 0 && (l = t.withAttributes(t.withAttributes(s, { dialect: String(n.dialect) }), { reason: n.reason }), d.set(o, l)), l.updateUnsafe(1, c);
|
|
54
|
+
let u = `${n.table}\u0000${n.reason}`, f = a.get(u), p = f === void 0 || r > 0 && i() - f >= r, m = {
|
|
55
|
+
table: n.table,
|
|
56
|
+
dialect: String(n.dialect),
|
|
57
|
+
reason: n.reason,
|
|
58
|
+
metric: "voltro_db_eager_fallback_total",
|
|
59
|
+
...n.error === void 0 ? {} : { err: n.error }
|
|
60
|
+
};
|
|
61
|
+
p ? (a.set(u, i()), e.warn(n.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\"}.", m)) : e.debug("eager-load is still running on the walker (rate-limited; the counter is not)", m);
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
//#endregion
|
|
65
|
+
export { b as DEFAULT_EAGER_FALLBACK_WARN_INTERVAL_MS, m as dbMetricTagCacheSizeForTests, _ as dbOperationsInFlight, C as makeEagerFallbackReporter, y as observeDbOp, v as recordDbOp, p as resetDbMetricTagCacheForTests, S as resolveEagerFallbackWarnIntervalMs };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/decimalComparison.ts
|
|
2
|
+
var e = (e) => {
|
|
3
|
+
if (typeof e != "string" || !/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/.test(e)) return null;
|
|
4
|
+
let [t = "", n = ""] = e.replace(/^[+-]/, "").split("."), r = t.replace(/^0+/, "") || "0";
|
|
5
|
+
return {
|
|
6
|
+
negative: e.startsWith("-") && /[1-9]/.test(r + n),
|
|
7
|
+
whole: r,
|
|
8
|
+
fraction: n
|
|
9
|
+
};
|
|
10
|
+
}, t = (t, n) => {
|
|
11
|
+
let r = e(t), i = e(n);
|
|
12
|
+
if (!r || !i) return null;
|
|
13
|
+
if (r.negative !== i.negative) return r.negative ? -1 : 1;
|
|
14
|
+
let a = r.whole.length - i.whole.length;
|
|
15
|
+
if (a === 0 && (a = r.whole === i.whole ? 0 : r.whole > i.whole ? 1 : -1), a === 0) {
|
|
16
|
+
let e = Math.max(r.fraction.length, i.fraction.length), t = r.fraction.padEnd(e, "0"), n = i.fraction.padEnd(e, "0");
|
|
17
|
+
a = t === n ? 0 : t > n ? 1 : -1;
|
|
18
|
+
}
|
|
19
|
+
return a === 0 ? 0 : (a > 0 ? 1 : -1) * (r.negative ? -1 : 1);
|
|
20
|
+
}, n = (t) => {
|
|
21
|
+
let n = e(t);
|
|
22
|
+
if (n === null) return null;
|
|
23
|
+
let r = n.fraction.replace(/0+$/, "");
|
|
24
|
+
return `${n.negative ? "-" : ""}${n.whole}${r ? "." + r : ""}`;
|
|
25
|
+
};
|
|
26
|
+
//#endregion
|
|
27
|
+
export { t as compareDecimal, n as decimalEqualityKey };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { createHash as e } from "node:crypto";
|
|
2
|
+
//#region src/derivedRowId.ts
|
|
3
|
+
var t = 64, n = "\0", r = 32, i = (t, ...i) => `${t}_${e("sha256").update(i.map(String).join(n)).digest("hex").slice(0, r)}`, a = (e) => e.length + 1 + r;
|
|
4
|
+
//#endregion
|
|
5
|
+
export { t as ID_COLUMN_MAX_LENGTH, i as derivedRowId, a as derivedRowIdLength };
|
package/dist/dialect.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/dialect.ts
|
|
2
|
+
var e = (e) => e === "sqlite" || e === "turso", t = (e) => e === "mysql" || e === "mariadb", n = (e, t) => {
|
|
3
|
+
switch (t) {
|
|
4
|
+
case "mysql":
|
|
5
|
+
case "mariadb": return `\`${e.replace(/`/g, "``")}\``;
|
|
6
|
+
case "mssql": return `[${e.replace(/\]/g, "]]")}]`;
|
|
7
|
+
case "postgres":
|
|
8
|
+
case "sqlite":
|
|
9
|
+
case "turso": return `"${e.replace(/"/g, "\"\"")}"`;
|
|
10
|
+
}
|
|
11
|
+
}, r = 1e4;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { r as DEFAULT_ACQUIRE_TIMEOUT_MS, t as isMysqlFamily, e as isSqliteFamily, n as quoteIdent };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/enumRenames.ts
|
|
2
|
+
var e = /* @__PURE__ */ new Map(), t = (t, n) => {
|
|
3
|
+
if (n.from === n.to) throw Error(`declareEnumRename('${t}'): \`from\` and \`to\` are both '${n.from}' — a rename must change the value.`);
|
|
4
|
+
let r = e.get(t) ?? [];
|
|
5
|
+
for (let e of r) {
|
|
6
|
+
if (e.from === n.from && e.to === n.to) return;
|
|
7
|
+
if (e.from === n.from && e.to !== n.to) throw Error(`declareEnumRename('${t}'): value '${n.from}' is already declared as renamed to '${e.to}', cannot also rename it to '${n.to}'.`);
|
|
8
|
+
}
|
|
9
|
+
r.push(n), e.set(t, r);
|
|
10
|
+
}, n = (t) => e.get(t) ?? [], r = () => e, i = () => {
|
|
11
|
+
e.clear();
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { r as allEnumRenames, i as clearEnumRenames, t as declareEnumRename, n as getEnumRenames };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { timestamp as e } from "./columns.js";
|
|
2
|
+
import { defineMixin as t } from "./mixins.js";
|
|
3
|
+
//#region src/expiresMixin.ts
|
|
4
|
+
var n = "voltro/expires", r = () => t({
|
|
5
|
+
id: n,
|
|
6
|
+
fields: { expiresAt: e().nullable() },
|
|
7
|
+
behaviors: { defaultWhere: () => "expiresAt IS NULL OR expiresAt > now()" }
|
|
8
|
+
});
|
|
9
|
+
//#endregion
|
|
10
|
+
export { n as VOLTRO_EXPIRES_MIXIN_ID, r as expires };
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
//#region src/fieldEncryption.ts
|
|
2
|
+
var e = /^[a-z0-9][a-z0-9-]{0,15}$/, t = (t) => {
|
|
3
|
+
if (!c(t)) return;
|
|
4
|
+
let i = t.startsWith(r), a = t.slice(i ? r.length : n.length).split(":")[i ? 4 : 3];
|
|
5
|
+
return a !== void 0 && e.test(a) ? a : void 0;
|
|
6
|
+
}, n = "enc:v1:", r = "enc:v2:", i = (e, t, n) => {
|
|
7
|
+
let r = `${e}:${t}`, i = n == null || n === "" ? void 0 : String(n);
|
|
8
|
+
return i === void 0 ? { column: r } : {
|
|
9
|
+
column: r,
|
|
10
|
+
row: `${r}:${i}`
|
|
11
|
+
};
|
|
12
|
+
}, a = (e) => typeof e == "string" && e.startsWith("enc:v2:"), o = class extends Error {
|
|
13
|
+
_tag = "FieldDecryptionError";
|
|
14
|
+
table;
|
|
15
|
+
column;
|
|
16
|
+
reason;
|
|
17
|
+
constructor(e) {
|
|
18
|
+
super(`column "${e.table}.${e.column}" is .encrypted() but could not be decrypted (${e.reason}) — the stored value was sealed under a key this process does not hold, or it is not where it was sealed: a value opens only at the table, column and row it was written for (a rename needs .renamedFrom(); an id changed outside the store leaves it bound to the old id)`), this.name = "FieldDecryptionError", this.table = e.table, this.column = e.column, this.reason = e.reason;
|
|
19
|
+
}
|
|
20
|
+
}, s = (e) => typeof e == "object" && !!e && e._tag === "FieldDecryptionError", c = (e) => typeof e == "string" && (e.startsWith("enc:v1:") || e.startsWith("enc:v2:")), l = (e, t, n) => e.encrypt(JSON.stringify(t), n), u = /* @__PURE__ */ new Set([
|
|
21
|
+
"text",
|
|
22
|
+
"id",
|
|
23
|
+
"reference",
|
|
24
|
+
"enum",
|
|
25
|
+
"uuid",
|
|
26
|
+
"email",
|
|
27
|
+
"url"
|
|
28
|
+
]), d = (e, t, n, r) => {
|
|
29
|
+
let i = e.decrypt(t, r), a;
|
|
30
|
+
try {
|
|
31
|
+
a = JSON.parse(i);
|
|
32
|
+
} catch {
|
|
33
|
+
return i;
|
|
34
|
+
}
|
|
35
|
+
return typeof a == "string" ? a : n === void 0 || u.has(n) ? i : a;
|
|
36
|
+
}, f = (e, t, n, r) => {
|
|
37
|
+
let i = e.decrypt(t, r);
|
|
38
|
+
try {
|
|
39
|
+
return typeof JSON.parse(i) == "string" ? !1 : n === void 0 || u.has(n) ? !0 : void 0;
|
|
40
|
+
} catch {
|
|
41
|
+
return !0;
|
|
42
|
+
}
|
|
43
|
+
}, p = (e, t) => e.fields[t]?.type, m = (e) => {
|
|
44
|
+
let t = [];
|
|
45
|
+
for (let [n, r] of Object.entries(e.fields)) r.encrypted === !0 && t.push(n);
|
|
46
|
+
return t;
|
|
47
|
+
}, h = "id", g = (e, t, n) => {
|
|
48
|
+
let r = e.tableName ?? "?", a = e.previousTableName, o = e.fields[t]?.renamedFrom, s = a === void 0 ? [r] : [r, a], c = o === void 0 ? [t] : [t, o];
|
|
49
|
+
return s.flatMap((e) => c.map((t) => i(e, t, n)));
|
|
50
|
+
}, _ = (e, t, n, r) => {
|
|
51
|
+
let i;
|
|
52
|
+
for (let a of r) try {
|
|
53
|
+
return d(e, t, n, a);
|
|
54
|
+
} catch (e) {
|
|
55
|
+
i ??= e;
|
|
56
|
+
}
|
|
57
|
+
throw i;
|
|
58
|
+
}, v = (e, t, n, r) => {
|
|
59
|
+
if (!t) return e;
|
|
60
|
+
let i = m(t);
|
|
61
|
+
return i.length === 0 ? e : x(e, i, t.tableName ?? "?", n, r);
|
|
62
|
+
}, y = (e, t, n) => {
|
|
63
|
+
if (t === void 0 || n == null) return;
|
|
64
|
+
let r = e[h];
|
|
65
|
+
if (r === void 0 || String(r) === String(n)) return;
|
|
66
|
+
let i = m(t);
|
|
67
|
+
if (i.length === 0) return;
|
|
68
|
+
let a = t.tableName ?? "?";
|
|
69
|
+
throw Error(`${a}: an update may not change the id of a row with .encrypted() columns (${i.join(", ")}) — each sealed value is bound to the id it was written under, so ${String(n)} → ${String(r)} would leave every one of them unreadable. Write the row under the new id (insert it, then delete the old one); the store seals its values there.`);
|
|
70
|
+
}, b = (e, t, n) => {
|
|
71
|
+
if (t === void 0 || e.length === 0) return e;
|
|
72
|
+
let r = m(t);
|
|
73
|
+
if (r.length === 0) return e;
|
|
74
|
+
let i = t.tableName ?? "?";
|
|
75
|
+
return e.map((e) => x(e, r, i, n));
|
|
76
|
+
}, x = (e, t, n, r, a) => {
|
|
77
|
+
let o = a ?? e[h], s = { ...e };
|
|
78
|
+
for (let e of t) {
|
|
79
|
+
let t = s[e];
|
|
80
|
+
if (!(t == null || c(t))) {
|
|
81
|
+
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`);
|
|
82
|
+
s[e] = l(r, t, i(n, e, o));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return s;
|
|
86
|
+
}, S = (e, t, n, r) => {
|
|
87
|
+
if (!t) return e;
|
|
88
|
+
let i = m(t);
|
|
89
|
+
if (i.length === 0 || !n) return e;
|
|
90
|
+
let a = r?.onError ?? "throw", s = t.tableName ?? "?";
|
|
91
|
+
return e.map((e) => {
|
|
92
|
+
let l;
|
|
93
|
+
for (let u of i) {
|
|
94
|
+
let i = e[u];
|
|
95
|
+
if (c(i)) {
|
|
96
|
+
l ??= { ...e };
|
|
97
|
+
try {
|
|
98
|
+
l[u] = _(n, i, p(t, u), g(t, u, r?.rowId ?? e[h]));
|
|
99
|
+
} catch (e) {
|
|
100
|
+
let t = String(e?.message ?? e);
|
|
101
|
+
if (a === "null") {
|
|
102
|
+
l[u] = null, r?.warn?.({
|
|
103
|
+
table: s,
|
|
104
|
+
column: u,
|
|
105
|
+
reason: t
|
|
106
|
+
});
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
throw new o({
|
|
110
|
+
table: s,
|
|
111
|
+
column: u,
|
|
112
|
+
reason: t
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return l ?? e;
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
//#endregion
|
|
121
|
+
export { r as BOUND_ENCRYPTED_PREFIX, n as ENCRYPTED_PREFIX, e as FIELD_KEY_ID_PATTERN, o as FieldDecryptionError, t as ciphertextKeyId, d as decodeFieldValue, S as decryptFieldsOnRead, l as encodeFieldValue, v as encryptFieldsForWrite, b as encryptFieldsForWriteBatch, m as encryptedColumnsOf, i as fieldBinding, g as fieldBindingsOf, a as isBoundCiphertext, c as isEncrypted, s as isFieldDecryptionError, f as isRawEncoding, y as refuseIdChangeOfSealedRow };
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { id as e, integer as t, json as n, text as r, timestamp as i } from "./columns.js";
|
|
2
|
+
import { table as a } from "./table.js";
|
|
3
|
+
//#region src/frameworkTables.ts
|
|
4
|
+
var o = a("_voltro_migrations", {
|
|
5
|
+
id: e({ prefix: "mig" }),
|
|
6
|
+
name: r(),
|
|
7
|
+
hash: r(),
|
|
8
|
+
status: r(),
|
|
9
|
+
appliedAt: i().nullable(),
|
|
10
|
+
durationMs: t().nullable(),
|
|
11
|
+
errorMessage: r().nullable(),
|
|
12
|
+
errorStack: r().nullable(),
|
|
13
|
+
workflowRunId: r().nullable(),
|
|
14
|
+
createdAt: i().default("now"),
|
|
15
|
+
updatedAt: i().default("now").onUpdate("now")
|
|
16
|
+
}).index(["status"]), s = a("_voltro_seeds", {
|
|
17
|
+
id: e({ prefix: "seed" }),
|
|
18
|
+
name: r(),
|
|
19
|
+
lifecycle: r(),
|
|
20
|
+
fingerprint: r(),
|
|
21
|
+
cronSchedule: r().nullable(),
|
|
22
|
+
watchedTables: n().nullable(),
|
|
23
|
+
nextRunAt: i().nullable(),
|
|
24
|
+
lastRunStatus: r().nullable(),
|
|
25
|
+
lastRunAt: i().nullable(),
|
|
26
|
+
lastRunDurationMs: t().nullable(),
|
|
27
|
+
lastRunRowsTouched: t().nullable(),
|
|
28
|
+
lastError: r().nullable(),
|
|
29
|
+
workflowRunId: r().nullable(),
|
|
30
|
+
createdAt: i().default("now"),
|
|
31
|
+
updatedAt: i().default("now").onUpdate("now")
|
|
32
|
+
}).index(["lifecycle"]).index(["nextRunAt"]), c = a("_voltro_schema_owner", {
|
|
33
|
+
id: e({ prefix: "own" }),
|
|
34
|
+
appName: r(),
|
|
35
|
+
projectName: r().nullable(),
|
|
36
|
+
frameworkVersion: r().nullable(),
|
|
37
|
+
claimedAt: i().default("now")
|
|
38
|
+
}), l = a("_voltro_plugin_migrations", {
|
|
39
|
+
id: e({ prefix: "plm" }),
|
|
40
|
+
plugin_name: r(),
|
|
41
|
+
migration_id: r(),
|
|
42
|
+
description: r().nullable(),
|
|
43
|
+
applied_at: r()
|
|
44
|
+
}), u = a("_voltro_migration_plans", {
|
|
45
|
+
id: e({ prefix: "plan" }),
|
|
46
|
+
fingerprint: r(),
|
|
47
|
+
liveFingerprint: r().nullable(),
|
|
48
|
+
operations: n(),
|
|
49
|
+
rollbackPlan: n().nullable(),
|
|
50
|
+
appliedBy: r(),
|
|
51
|
+
environment: r(),
|
|
52
|
+
source: r(),
|
|
53
|
+
onlineStrategy: r().nullable(),
|
|
54
|
+
durationMs: t(),
|
|
55
|
+
notes: r().nullable(),
|
|
56
|
+
squashedAt: i().nullable(),
|
|
57
|
+
appliedAt: i().default("now"),
|
|
58
|
+
createdAt: i().default("now"),
|
|
59
|
+
updatedAt: i().default("now").onUpdate("now")
|
|
60
|
+
}).index(["fingerprint"]).index(["environment"]), d = a("_voltro_idempotency", {
|
|
61
|
+
id: e({ prefix: "idem" }),
|
|
62
|
+
scope: r(),
|
|
63
|
+
key: r(),
|
|
64
|
+
inputHash: r().nullable(),
|
|
65
|
+
status: r(),
|
|
66
|
+
response: n().nullable(),
|
|
67
|
+
createdAt: i().default("now")
|
|
68
|
+
}).unique(["scope", "key"]).index(["createdAt"]), f = a("_voltro_devices", {
|
|
69
|
+
id: e({ prefix: "device" }),
|
|
70
|
+
tenantId: r(),
|
|
71
|
+
name: r(),
|
|
72
|
+
scopes: n().nullable(),
|
|
73
|
+
pairingHash: r().maxLength(64).nullable(),
|
|
74
|
+
pairingExpiresAt: i().nullable(),
|
|
75
|
+
accessHash: r().maxLength(64).nullable(),
|
|
76
|
+
accessExpiresAt: i().nullable(),
|
|
77
|
+
refreshHash: r().maxLength(64).nullable(),
|
|
78
|
+
refreshExpiresAt: i().nullable(),
|
|
79
|
+
previousRefreshHash: r().maxLength(64).nullable(),
|
|
80
|
+
generation: t().default(0),
|
|
81
|
+
pairedAt: i().nullable(),
|
|
82
|
+
lastSeenAt: i().nullable(),
|
|
83
|
+
revokedAt: i().nullable(),
|
|
84
|
+
revokedReason: r().nullable(),
|
|
85
|
+
createdBy: r().nullable(),
|
|
86
|
+
metadata: n().nullable(),
|
|
87
|
+
createdAt: i()
|
|
88
|
+
}).index(["tenantId"]).index(["pairingHash"]).index(["accessHash"]).index(["refreshHash"]).index(["previousRefreshHash"]), p = a("_voltro_tenant_selections", {
|
|
89
|
+
id: e({ prefix: "tsel" }),
|
|
90
|
+
subjectType: r().maxLength(32),
|
|
91
|
+
subjectId: r(),
|
|
92
|
+
tenantId: r(),
|
|
93
|
+
selectedAt: i()
|
|
94
|
+
}).primaryKey(["id"]).nonReactive(), m = a("_voltro_kv", {
|
|
95
|
+
id: e({ prefix: "kv" }),
|
|
96
|
+
key: r().unique(),
|
|
97
|
+
value: r().nullable(),
|
|
98
|
+
expiresAt: i().nullable(),
|
|
99
|
+
createdAt: i().default("now"),
|
|
100
|
+
updatedAt: i().default("now").onUpdate("now")
|
|
101
|
+
}).index(["expiresAt"]), h = a("_voltro_api_keys", {
|
|
102
|
+
id: e({ prefix: "apikey" }),
|
|
103
|
+
tenantId: r().nullable(),
|
|
104
|
+
name: r(),
|
|
105
|
+
hashedKey: r().maxLength(64).unique(),
|
|
106
|
+
keyPrefix: r(),
|
|
107
|
+
scopes: n().nullable(),
|
|
108
|
+
lastUsedAt: i().nullable(),
|
|
109
|
+
requestCount: t().default(0),
|
|
110
|
+
expiresAt: i().nullable(),
|
|
111
|
+
revokedAt: i().nullable(),
|
|
112
|
+
createdBy: r().nullable(),
|
|
113
|
+
onBehalfOf: r().nullable(),
|
|
114
|
+
metadata: n().nullable(),
|
|
115
|
+
createdAt: i().default("now")
|
|
116
|
+
}).index("byApiKeyTenant", ["tenantId"]), g = a("_voltro_replica_observations", {
|
|
117
|
+
id: e({ prefix: "robs" }),
|
|
118
|
+
replicaId: r().maxLength(191),
|
|
119
|
+
startedAt: i(),
|
|
120
|
+
version: r().maxLength(64).nullable(),
|
|
121
|
+
kind: r().maxLength(64),
|
|
122
|
+
payload: r().nullable(),
|
|
123
|
+
reachableAt: r().maxLength(255).nullable(),
|
|
124
|
+
writtenAt: i().default("now").onUpdate("now")
|
|
125
|
+
}).unique(["replicaId", "kind"]).index(["kind"]), _ = a("_voltro_api_role_workload_buckets", {
|
|
126
|
+
id: e({ prefix: "arwb" }),
|
|
127
|
+
replicaId: r().maxLength(191),
|
|
128
|
+
startedAt: i(),
|
|
129
|
+
role: r().maxLength(2080),
|
|
130
|
+
bucketFrom: i(),
|
|
131
|
+
bucketUntil: i(),
|
|
132
|
+
payload: r()
|
|
133
|
+
}).unique("_voltro_arwb_replica_bucket_uq", [
|
|
134
|
+
"replicaId",
|
|
135
|
+
"startedAt",
|
|
136
|
+
"bucketFrom"
|
|
137
|
+
]).index(["bucketUntil"]), v = [
|
|
138
|
+
o,
|
|
139
|
+
s,
|
|
140
|
+
u
|
|
141
|
+
];
|
|
142
|
+
//#endregion
|
|
143
|
+
export { h as _voltroApiKeysTable, _ as _voltroApiRoleWorkloadBucketsTable, f as _voltroDevicesTable, d as _voltroIdempotencyTable, m as _voltroKvTable, u as _voltroMigrationPlansTable, o as _voltroMigrationsTable, l as _voltroPluginMigrationsTable, g as _voltroReplicaObservationsTable, c as _voltroSchemaOwnerTable, s as _voltroSeedsTable, p as _voltroTenantSelectionsTable, v as frameworkTables };
|
package/dist/ginIndex.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/ginIndex.ts
|
|
2
|
+
var e = (e) => {
|
|
3
|
+
let t = e?.gin?.opclass;
|
|
4
|
+
if (t !== void 0) {
|
|
5
|
+
if (!/^[a-z_][a-z0-9_$]*(?:\.[a-z_][a-z0-9_$]*)?$/i.test(t)) throw Error("GIN opclass must be an unquoted, optionally schema-qualified identifier");
|
|
6
|
+
return t.toLowerCase().replace(/^public\./, "");
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
//#endregion
|
|
10
|
+
export { e as resolveGinOpclass };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { resolveFullTextIndex as e } from "./queryBuilder.js";
|
|
2
|
+
//#region src/hybridSearch.ts
|
|
3
|
+
var t = (t) => {
|
|
4
|
+
let n = t.alpha ?? .5;
|
|
5
|
+
if (n < 0 || n > 1) throw Error(`hybridSearch: alpha must be in [0, 1], got ${n}`);
|
|
6
|
+
return (r) => {
|
|
7
|
+
let i = Array.isArray(t.vector.query) ? {
|
|
8
|
+
column: t.vector.col,
|
|
9
|
+
queryVector: t.vector.query,
|
|
10
|
+
distance: t.vector.distance ?? "cosine",
|
|
11
|
+
alpha: n
|
|
12
|
+
} : {
|
|
13
|
+
column: t.vector.col,
|
|
14
|
+
queryText: t.vector.query,
|
|
15
|
+
distance: t.vector.distance ?? "cosine",
|
|
16
|
+
alpha: n
|
|
17
|
+
}, a = e(r.table, t.fts.indexName, r.fullTextIndexes);
|
|
18
|
+
return {
|
|
19
|
+
...r,
|
|
20
|
+
annClause: i,
|
|
21
|
+
fullTextSearch: {
|
|
22
|
+
indexName: t.fts.indexName,
|
|
23
|
+
query: t.fts.query,
|
|
24
|
+
columns: a.columns,
|
|
25
|
+
...a.config === void 0 ? {} : { config: a.config },
|
|
26
|
+
...a.weights === void 0 ? {} : { weights: a.weights }
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
//#endregion
|
|
32
|
+
export { t as hybridSearch };
|