@voltro/runtime 0.86.0 → 0.88.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 +5484 -0
- package/README.md +43 -0
- package/THIRD-PARTY-NOTICES.md +1511 -276
- package/dist/aggregate.js +1 -2
- package/dist/aggregateExtrema.js +1 -2
- package/dist/aggregateIvm.js +1 -2
- package/dist/analyticsMirror.js +1 -2
- package/dist/analyticsSink.js +9 -16
- package/dist/apiKeyUsage.js +1 -2
- package/dist/apiKeys.js +83 -80
- package/dist/apiKeysWiring.js +1 -2
- package/dist/apiRoleBucketSampler.js +63 -0
- package/dist/apiRoleWorkloadHistory.js +55 -0
- package/dist/apiRoleWorkloadMetrics.js +77 -0
- package/dist/apiRoleWorkloadStorage.js +94 -0
- package/dist/approvalBuiltins.js +1 -2
- package/dist/approvals.js +68 -76
- package/dist/authMiddlewareLayer.js +8 -8
- package/dist/bindEvent.js +49 -30
- package/dist/boot-refusal.d.ts +10 -0
- package/dist/{bootRefusal.js → boot-refusal.js} +1 -2
- package/dist/bootListener.js +203 -47
- package/dist/bootStoreCodec.js +39 -39
- package/dist/businessRules.js +1 -2
- package/dist/changeClaimsTable.js +1 -2
- package/dist/circuitBreaker.js +1 -72
- package/dist/columnOnUpdate.js +1 -2
- package/dist/composeAnalytics.js +32 -12
- package/dist/computedQuery.js +1 -2
- package/dist/computedQueryCache.js +289 -0
- package/dist/connectionBuiltins.js +1 -2
- package/dist/connectionCredentials.js +1 -2
- package/dist/connectionState.js +1 -2
- package/dist/connectionVault.js +1 -2
- package/dist/connectionsFacade.js +33 -32
- package/dist/coordinatedSchedule.js +85 -80
- package/dist/crdtHistory.js +1 -2
- package/dist/crdtMerge.js +1 -2
- package/dist/crdtVersionsTable.js +1 -2
- package/dist/credentialBound.js +1 -2
- package/dist/crud.js +1 -2
- package/dist/dataStore.js +155 -123
- package/dist/dataloader.js +1 -2
- package/dist/declaredTablesGuard.js +3 -3
- package/dist/defineExecutor.js +1 -2
- package/dist/dependencyGraph.js +1 -2
- package/dist/devices.js +1 -2
- package/dist/devicesWiring.js +1 -2
- package/dist/dialectReplicationAdapter.js +1 -2
- package/dist/dispatcher.js +404 -330
- package/dist/effectStore.js +3 -4
- package/dist/engineClients.js +23 -0
- package/dist/eventBus.js +1 -2
- package/dist/eventPublish.js +1 -2
- package/dist/events.js +1 -2
- package/dist/expectation.js +1 -2
- package/dist/expectationEvaluator.js +2 -3
- package/dist/experiment.js +1 -2
- package/dist/experimentEvaluator.js +1 -2
- package/dist/externalizedTasks.js +20 -8
- package/dist/fieldCipher.js +110 -42
- package/dist/fieldKeyRegistry.js +294 -0
- package/dist/fieldKeyRekey.js +285 -0
- package/dist/fieldKeyScan.js +135 -0
- package/dist/fieldKeyring.js +76 -0
- package/dist/fingerprint.js +1 -2
- package/dist/finops.js +1 -2
- package/dist/finopsAccountant.js +1 -2
- package/dist/handlerBody.js +1 -2
- package/dist/healthProbes.js +1 -2
- package/dist/hot.d.ts +56 -0
- package/dist/hot.js +3 -0
- package/dist/hotDataStore.js +147 -0
- package/dist/hotDataStoreSnapshot.js +97 -0
- package/dist/hotDataStoreTables.js +17 -0
- package/dist/http-range.d.ts +53 -0
- package/dist/http-range.js +51 -0
- package/dist/httpClientSsrf.js +13 -39
- package/dist/httpClientTracing.js +13 -11
- package/dist/httpCompression.js +18 -19
- package/dist/httpInputStream.js +81 -0
- package/dist/httpKeepAlive.js +1 -2
- package/dist/httpRouteMounts.js +2 -2
- package/dist/idempotencyStore.js +93 -54
- package/dist/idleDetector.js +1 -2
- package/dist/index.d.ts +1185 -452
- package/dist/index.js +144 -134
- package/dist/insertRequiredColumns.js +1 -2
- package/dist/instanceMembership.js +1 -2
- package/dist/ivm.js +1 -2
- package/dist/kvDataStore.js +1 -2
- package/dist/kvFacade.js +24 -19
- package/dist/matcher.js +1 -2
- package/dist/memoryColumnDefaults.js +1 -2
- package/dist/memoryQueryJoins.js +17 -18
- package/dist/memorySetOperations.js +42 -0
- package/dist/metrics.js +39 -26
- package/dist/observability.js +2 -3
- package/dist/observedGraph.js +1 -2
- package/dist/originGuard.js +1 -2
- package/dist/outbox.js +2 -3
- package/dist/pluginRefRules.js +1 -2
- package/dist/policyGuardResolver.js +1 -2
- package/dist/preview.js +1 -2
- package/dist/projectedRows.js +1 -2
- package/dist/provenance.js +1 -2
- package/dist/rangeIndex.js +1 -2
- package/dist/rawReadScope.js +2 -3
- package/dist/reaction.js +1 -2
- package/dist/reactiveConfig.js +1 -2
- package/dist/readClassification.js +1 -2
- package/dist/readRecorder.js +36 -36
- package/dist/readScopePredicate.js +11 -0
- package/dist/rebac.js +1 -2
- package/dist/rebacInterceptor.js +1 -2
- package/dist/registry.js +1 -2
- package/dist/relevantFields.js +1 -2
- package/dist/replicaHealth.js +1 -2
- package/dist/replicaLocality.js +1 -2
- package/dist/replicaObservations.js +1 -2
- package/dist/replicaSelection.js +1 -2
- package/dist/replicatedDataStore.js +23 -6
- package/dist/requestLoader.js +1 -2
- package/dist/resumeCensus.js +1 -2
- package/dist/revalidation.js +1 -2
- package/dist/rowFilter.js +57 -41
- package/dist/rowStateBytes.js +1 -2
- package/dist/rpcBodyCap.js +1 -2
- package/dist/rpcConnections.js +9 -10
- package/dist/rpcDefectDiagnostics.js +1 -2
- package/dist/rpcServer.js +523 -451
- package/dist/rpcWorkloadAdmission.js +49 -0
- package/dist/runAsSystem.js +1 -2
- package/dist/rywPositionStore.js +83 -49
- package/dist/schedule.js +1 -2
- package/dist/scheduleBackfillRequests.js +1 -2
- package/dist/scheduleClaimsTable.js +1 -2
- package/dist/scheduleRunsTable.js +1 -2
- package/dist/scheduler.js +7 -3
- package/dist/schemaRegistry.js +1 -2
- package/dist/secretsResolver.js +1 -2
- package/dist/securityHeaders.js +1 -2
- package/dist/servePipeline.js +238 -154
- package/dist/serverOnlyAudit.js +1 -2
- package/dist/serverTracer.js +1 -2
- package/dist/serviceCredentials.js +1 -2
- package/dist/setReadScopes.js +27 -0
- package/dist/singleNodeOrchestrator.js +1 -2
- package/dist/snapshotValueCodec.js +45 -0
- package/dist/sourceResolution.js +35 -26
- package/dist/storeMiddleware.js +213 -212
- package/dist/storeQuery.js +1 -2
- package/dist/storeRead.js +1 -2
- package/dist/subscriber.js +2 -2
- package/dist/subscriptionOutbox.js +1 -2
- package/dist/subscriptionRegistry.js +1 -2
- package/dist/subscriptionResume.js +1 -2
- package/dist/subscriptionSocketMetrics.js +1 -2
- package/dist/systemSubject.js +1 -2
- package/dist/tenantScope.js +9 -22
- package/dist/tenantSelection.js +1 -2
- package/dist/timeline.js +1 -2
- package/dist/traceContext.js +1 -2
- package/dist/traceSink.js +1 -2
- package/dist/traceSpansTable.js +1 -2
- package/dist/traceparent.js +9 -21
- package/dist/transactionSubject.js +1 -2
- package/dist/trustedProxy.js +2 -3
- package/dist/undo.js +1 -2
- package/dist/undoBuiltins.js +1 -2
- package/dist/undoCapture.js +1 -2
- package/dist/undoLogTable.js +1 -2
- package/dist/upsertBinding.js +1 -2
- package/dist/wakeOrchestrator.js +1 -2
- package/dist/wakeRegistry.js +1 -2
- package/dist/wakeRouter.js +1 -2
- package/dist/wakeSupervisor.js +1 -2
- package/dist/wakeupsTable.js +1 -2
- package/dist/webSocketGatewayRuntime.js +112 -73
- package/dist/webhookVerification.js +1 -2
- package/dist/wireColumnStrip.js +1 -2
- package/dist/workflowReadBuiltins.js +1 -2
- package/dist/workflowRuntime.js +10 -11
- package/package.json +36 -17
package/dist/storeMiddleware.js
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import { isolateRawReadScope as e, rawSqlPreview as t, recordRawRead as n } from "./rawReadScope.js";
|
|
2
2
|
import { applySealedWrite as r, assertCrdtUpdateAdmissible as i, mergeCrdtColumnsIntoPatch as a, patchTouchesCrdt as o } from "./crdtMerge.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
3
|
+
import { mapSetReadScopes as s } from "./setReadScopes.js";
|
|
4
|
+
import { NO_ROW_FILTER as c, applyRowFilter as l, rowFilterRegistered as u } from "./rowFilter.js";
|
|
5
|
+
import { addReadScopePredicate as d } from "./readScopePredicate.js";
|
|
6
|
+
import { readMaybeOne as f } from "./storeRead.js";
|
|
7
|
+
import { CRDT_VERSIONS_TABLE as p } from "./crdtVersionsTable.js";
|
|
8
|
+
import { getFieldCipher as m } from "./fieldCipher.js";
|
|
9
|
+
import { observeStore as h } from "./observedGraph.js";
|
|
10
|
+
import { upsertConflictId as g } from "./upsertBinding.js";
|
|
11
|
+
import { applyColumnOnUpdate as _ } from "./columnOnUpdate.js";
|
|
12
|
+
import { prepareInsertRequiredColumns as v } from "./insertRequiredColumns.js";
|
|
13
|
+
import { makeFluentStore as ee, missingRowError as te } from "./storeQuery.js";
|
|
14
|
+
import { Schema as ne, SchemaIssue as re } from "effect";
|
|
15
|
+
import { INITIAL_VERSION as ie, VersionConflict as ae, and as y, classifyConstraintViolation as oe, decryptFieldsOnRead as se, deserializeArraysOnRead as ce, encryptFieldsForWrite as le, encryptFieldsForWriteBatch as ue, encryptedColumnsOf as de, eq as b, extractDbCause as fe, generateId as pe, getRelations as me, getTable as x, gt as he, inSet as ge, isCompositeRowKey as _e, isNull as S, jsonPatchAssignments as ve, missingConflictColumns as ye, missingRequiredColumns as be, or as xe, planVersionedUpdate as Se, refuseIdChangeOfSealedRow as Ce, rowKeyColumns as we, rowKeyIdentity as C, serializeArraysForWrite as Te, settleVersionedUpdate as Ee, storeRefusalOf as De, upsertUpdateValues as Oe } from "@voltro/database";
|
|
16
|
+
import { ConstraintViolation as ke, TableValidationFailed as w, TenantRowNotFound as Ae, TenantScopeViolation as je, ValidationError as Me, isMachineSubject as Ne, subjectAuditActorId as T } from "@voltro/protocol";
|
|
17
|
+
import { createLogger as Pe } from "@voltro/logger";
|
|
16
18
|
import { defaultCrdtBackend as E } from "@voltro/local-first";
|
|
17
|
-
|
|
18
|
-
var
|
|
19
|
-
let r =
|
|
19
|
+
// src/storeMiddleware.ts
|
|
20
|
+
var Fe = (e, t, n) => {
|
|
21
|
+
let r = me(e);
|
|
20
22
|
if (r === void 0) return t;
|
|
21
23
|
let i = {};
|
|
22
24
|
for (let [a, o] of Object.entries(t)) {
|
|
@@ -53,53 +55,53 @@ var Me = (e, t, n) => {
|
|
|
53
55
|
l.where = t === void 0 ? e : y(t, e);
|
|
54
56
|
}
|
|
55
57
|
let t = l.with;
|
|
56
|
-
t !== void 0 && (l.with =
|
|
58
|
+
t !== void 0 && (l.with = Fe(c, t, n));
|
|
57
59
|
}
|
|
58
60
|
i[a] = l;
|
|
59
61
|
}
|
|
60
62
|
return i;
|
|
61
|
-
}, D = "id",
|
|
63
|
+
}, D = "id", Ie = 3, O = 8, Le = (e) => "descriptor" in e ? e.descriptor : e, Re = (e, t) => {
|
|
62
64
|
let n = {};
|
|
63
65
|
for (let r of t) e[r] !== void 0 && (n[r] = e[r]);
|
|
64
66
|
return n;
|
|
65
|
-
}, k = "cannot insert into tenant-scoped table without an authenticated tenant — subject.tenantId is null. Either authenticate first or pass tenantId explicitly in the row (admin tooling).",
|
|
66
|
-
throw new
|
|
67
|
+
}, k = "cannot insert into tenant-scoped table without an authenticated tenant — subject.tenantId is null. Either authenticate first or pass tenantId explicitly in the row (admin tooling).", ze = (e) => {
|
|
68
|
+
throw new je({
|
|
67
69
|
table: e,
|
|
68
70
|
reason: k
|
|
69
71
|
});
|
|
70
|
-
},
|
|
71
|
-
let k =
|
|
72
|
+
}, Be = (e) => T(e), Ve = (me, T) => {
|
|
73
|
+
let k = h(me);
|
|
72
74
|
e();
|
|
73
|
-
let A =
|
|
74
|
-
if (T.rowFilter === void 0 && !
|
|
75
|
-
let N = T.rowFilter ??
|
|
75
|
+
let A = Be(T.subject), M = T.subject.tenantId;
|
|
76
|
+
if (T.rowFilter === void 0 && !Ne(T.subject) && u()) throw Error("row filter registered, but this store was scoped without one — refusing to serve an unfiltered read.\n\nThis app called `setRowFilter`, so every scoped store must receive a resolved `rowFilter` (the serve pipeline's `withRowFilter` does this per request). Reaching here with none means a read path was built outside that spine, and continuing would serve rows the filter exists to hide — silently, which is how this was found in the first place.\n\nIf this path is deliberately unfiltered (a system sweep, a migration), pass `rowFilter: NO_ROW_FILTER` explicitly.");
|
|
77
|
+
let N = T.rowFilter ?? c, P = (e, t) => {
|
|
76
78
|
let n = { ...t }, r = T.schemaRegistry, i = r.idScheme(e);
|
|
77
79
|
if (i !== void 0 && n[D] == null) {
|
|
78
80
|
if (i.kind === "numeric") delete n[D];
|
|
79
81
|
else {
|
|
80
|
-
let t =
|
|
82
|
+
let t = pe(i, e);
|
|
81
83
|
t !== null && (n[D] = t);
|
|
82
84
|
}
|
|
83
85
|
}
|
|
84
86
|
let a = r.versionColumn(e);
|
|
85
87
|
if (a !== void 0) {
|
|
86
88
|
let e = n[a];
|
|
87
|
-
|
|
89
|
+
typeof e == "number" && Number.isFinite(e) || (n[a] = ie);
|
|
88
90
|
}
|
|
89
91
|
if (r.hasAudit(e)) {
|
|
90
92
|
let e = /* @__PURE__ */ new Date();
|
|
91
93
|
"createdAt" in n || (n.createdAt = e), "updatedAt" in n || (n.updatedAt = e), A !== null && ("createdBy" in n || (n.createdBy = A), "updatedBy" in n || (n.updatedBy = A));
|
|
92
94
|
}
|
|
93
|
-
r.hasTenant(e) && ("tenantId" in n || (M === null &&
|
|
95
|
+
r.hasTenant(e) && ("tenantId" in n || (M === null && ze(e), n.tenantId = M));
|
|
94
96
|
let o = r.defaultFactories(e);
|
|
95
|
-
if (o.size > 0) for (let [e, t] of o)
|
|
97
|
+
if (o.size > 0) for (let [e, t] of o) e in n && n[e] !== void 0 || (n[e] = t());
|
|
96
98
|
let s = r.computedFields(e);
|
|
97
99
|
if (s.size > 0) for (let [e, t] of s) n[e] = t(n);
|
|
98
100
|
let c = r.generatedColumns(e);
|
|
99
101
|
if (c.size > 0) for (let e of c) delete n[e];
|
|
100
102
|
return n;
|
|
101
103
|
}, F = (e, t, n = []) => {
|
|
102
|
-
let r =
|
|
104
|
+
let r = _(T.schemaRegistry, e, t, n);
|
|
103
105
|
if (!T.schemaRegistry.hasAudit(e)) return r;
|
|
104
106
|
let i = { ...r };
|
|
105
107
|
return "updatedAt" in i || (i.updatedAt = /* @__PURE__ */ new Date()), A !== null && !("updatedBy" in i) && (i.updatedBy = A), i;
|
|
@@ -107,8 +109,8 @@ var Me = (e, t, n) => {
|
|
|
107
109
|
try {
|
|
108
110
|
return await r();
|
|
109
111
|
} catch (r) {
|
|
110
|
-
let i =
|
|
111
|
-
if (i !== void 0) throw new
|
|
112
|
+
let i = De(r);
|
|
113
|
+
if (i !== void 0) throw new ke({
|
|
112
114
|
kind: i.kind,
|
|
113
115
|
table: e,
|
|
114
116
|
operation: t,
|
|
@@ -116,16 +118,16 @@ var Me = (e, t, n) => {
|
|
|
116
118
|
...i.column === void 0 ? {} : { column: i.column },
|
|
117
119
|
detail: i.detail
|
|
118
120
|
});
|
|
119
|
-
let a =
|
|
121
|
+
let a = fe(r), o = oe(a, t);
|
|
120
122
|
if (o === void 0) throw r;
|
|
121
123
|
if (T.schemaRegistry.hasTenant(e) && (o.kind === "foreignKey" || o.kind === "foreignKeyInUse")) {
|
|
122
124
|
let t = n?.tenantId, r = `${a.dbConstraint ?? ""} ${a.dbColumn ?? ""} ${a.dbMessage ?? ""} ${a.dbCauseChain ?? ""}`.toLowerCase();
|
|
123
|
-
if (r.includes("tenantid") || /\btenants\b/.test(r) || t != null && r.includes(String(t).toLowerCase())) throw new
|
|
125
|
+
if (r.includes("tenantid") || /\btenants\b/.test(r) || t != null && r.includes(String(t).toLowerCase())) throw new je({
|
|
124
126
|
table: e,
|
|
125
127
|
reason: t == null ? "write references a tenant that does not exist" : `tenant '${String(t)}' does not exist — seed the row in \`tenants\`, or fix how the request resolved this tenant (subject.tenantId / the x-tenant header / the dev TENANT fallback)`
|
|
126
128
|
});
|
|
127
129
|
}
|
|
128
|
-
throw new
|
|
130
|
+
throw new ke({
|
|
129
131
|
kind: o.kind,
|
|
130
132
|
table: e,
|
|
131
133
|
operation: t,
|
|
@@ -133,7 +135,7 @@ var Me = (e, t, n) => {
|
|
|
133
135
|
...o.column === void 0 ? {} : { column: o.column }
|
|
134
136
|
});
|
|
135
137
|
}
|
|
136
|
-
},
|
|
138
|
+
}, He = (e, t, n) => {
|
|
137
139
|
let r = T.schemaRegistry.computedFields(e);
|
|
138
140
|
if (r.size === 0) return n;
|
|
139
141
|
let i = {
|
|
@@ -145,9 +147,9 @@ var Me = (e, t, n) => {
|
|
|
145
147
|
}, L = (e, t) => {
|
|
146
148
|
let n = T.schemaRegistry.validatePatchSchema(e);
|
|
147
149
|
if (n === void 0) return t;
|
|
148
|
-
let r =
|
|
150
|
+
let r = ne.decodeUnknownResult(n)(t);
|
|
149
151
|
if (r._tag === "Success") return t;
|
|
150
|
-
let i =
|
|
152
|
+
let i = re.makeFormatterStandardSchemaV1()(r.failure.issue).issues.map((e) => ({
|
|
151
153
|
path: (e.path ?? []).length === 0 ? "<root>" : (e.path ?? []).join("."),
|
|
152
154
|
message: e.message
|
|
153
155
|
})), a = i[0];
|
|
@@ -156,11 +158,11 @@ var Me = (e, t, n) => {
|
|
|
156
158
|
summary: a === void 0 ? "patch validation failed" : `${a.path}: ${a.message}`,
|
|
157
159
|
issues: i
|
|
158
160
|
});
|
|
159
|
-
},
|
|
161
|
+
}, Ue = () => {
|
|
160
162
|
let e = { deletedAt: /* @__PURE__ */ new Date() };
|
|
161
163
|
return A !== null && (e.deletedBy = A), e;
|
|
162
|
-
},
|
|
163
|
-
let r =
|
|
164
|
+
}, We = (e, t, n) => {
|
|
165
|
+
let r = ye(x(e), n, t);
|
|
164
166
|
if (r.length !== 0) throw new w({
|
|
165
167
|
table: e,
|
|
166
168
|
summary: `upsert conflictColumns [${n.map((e) => `'${e}'`).join(", ")}] cannot match: ` + r.map((e) => e.reason === "null" ? `'${e.column}' is NULL` : `'${e.column}' is absent`).join(", "),
|
|
@@ -181,7 +183,7 @@ var Me = (e, t, n) => {
|
|
|
181
183
|
}
|
|
182
184
|
let s = x(e);
|
|
183
185
|
if (s !== void 0) {
|
|
184
|
-
let r = n === void 0 ?
|
|
186
|
+
let r = n === void 0 ? be(s, t) : n.filter((e) => t[e] === void 0 || t[e] === null);
|
|
185
187
|
if (r.length > 0) throw new w({
|
|
186
188
|
table: e,
|
|
187
189
|
summary: `missing required column${r.length > 1 ? "s" : ""} ${r.map((e) => `'${e}'`).join(", ")} — NOT NULL with no default and not auto-stamped`,
|
|
@@ -193,9 +195,9 @@ var Me = (e, t, n) => {
|
|
|
193
195
|
}
|
|
194
196
|
let c = T.schemaRegistry.insertSchema(e);
|
|
195
197
|
if (c === void 0) return t;
|
|
196
|
-
let l =
|
|
198
|
+
let l = ne.decodeUnknownResult(c)(t);
|
|
197
199
|
if (l._tag === "Success") return t;
|
|
198
|
-
let u =
|
|
200
|
+
let u = re.makeFormatterStandardSchemaV1()(l.failure.issue).issues.map((e) => ({
|
|
199
201
|
path: (e.path ?? []).length === 0 ? "<root>" : (e.path ?? []).join("."),
|
|
200
202
|
message: e.message
|
|
201
203
|
})), d = u[0];
|
|
@@ -205,19 +207,19 @@ var Me = (e, t, n) => {
|
|
|
205
207
|
issues: u
|
|
206
208
|
});
|
|
207
209
|
}, z = T.dialect, B = (e, t, n) => {
|
|
208
|
-
let r = x(e), i = z ?
|
|
209
|
-
return
|
|
210
|
-
}, V = (e, t) => {
|
|
210
|
+
let r = x(e), i = z ? Te(t, r, z) : t;
|
|
211
|
+
return le(i, r, m(), n);
|
|
212
|
+
}, V = (e, t, n) => (Ce(t, x(e), n), B(e, t, n)), H = (e, t) => {
|
|
211
213
|
let n = x(e);
|
|
212
|
-
return n !== void 0 &&
|
|
213
|
-
},
|
|
214
|
+
return n !== void 0 && de(n).some((e) => t[e] !== void 0 && t[e] !== null);
|
|
215
|
+
}, Ge = (e) => {
|
|
214
216
|
let t = e.projection;
|
|
215
217
|
if (t === void 0 || t.includes(D)) return {
|
|
216
218
|
descriptor: e,
|
|
217
219
|
stripId: !1
|
|
218
220
|
};
|
|
219
221
|
let n = x(e.table);
|
|
220
|
-
return n === void 0 ||
|
|
222
|
+
return n === void 0 || de(n).length === 0 ? {
|
|
221
223
|
descriptor: e,
|
|
222
224
|
stripId: !1
|
|
223
225
|
} : {
|
|
@@ -227,105 +229,99 @@ var Me = (e, t, n) => {
|
|
|
227
229
|
},
|
|
228
230
|
stripId: !0
|
|
229
231
|
};
|
|
230
|
-
},
|
|
232
|
+
}, Ke = process.env.VOLTRO_FIELD_DECRYPT_ON_ERROR === "null" ? "null" : "throw", qe = Pe({ scope: "store.fieldEncryption" }), Je = /* @__PURE__ */ new Set(), Ye = (e) => {
|
|
231
233
|
let t = `${e.table}.${e.column}`;
|
|
232
|
-
|
|
234
|
+
Je.has(t) || (Je.add(t), qe.warn("encrypted column degraded to null — could not decrypt with the active key", {
|
|
233
235
|
table: e.table,
|
|
234
236
|
column: e.column,
|
|
235
237
|
reason: e.reason,
|
|
236
238
|
hint: "VOLTRO_FIELD_DECRYPT_ON_ERROR=null is set — this row was likely encrypted under a different key"
|
|
237
239
|
}));
|
|
238
|
-
},
|
|
239
|
-
let r = x(e), i =
|
|
240
|
-
onError:
|
|
241
|
-
...
|
|
240
|
+
}, U = (e, t, n) => {
|
|
241
|
+
let r = x(e), i = se(t, r, m(), {
|
|
242
|
+
onError: Ke,
|
|
243
|
+
...Ke === "null" ? { warn: Ye } : {},
|
|
242
244
|
...n === void 0 ? {} : { rowId: n }
|
|
243
245
|
});
|
|
244
|
-
return z ?
|
|
245
|
-
},
|
|
246
|
-
let
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
-
if (!e.includeExpired && T.schemaRegistry.hasExpires(t)) {
|
|
256
|
-
let e = ye(S("expiresAt"), pe("expiresAt", /* @__PURE__ */ new Date()));
|
|
257
|
-
n = n ? y(n, e) : e;
|
|
258
|
-
}
|
|
259
|
-
n = c(N, t, n);
|
|
260
|
-
let r = e.eager === void 0 ? void 0 : Me(t, e.eager, N);
|
|
261
|
-
return r === void 0 ? n === e.predicate ? e : {
|
|
262
|
-
...e,
|
|
263
|
-
predicate: n
|
|
246
|
+
return z ? ce(i, r, z) : i;
|
|
247
|
+
}, Xe = (e, t, n = N) => {
|
|
248
|
+
let r = e, i = r.table;
|
|
249
|
+
!r.crossTenant && M != null && T.schemaRegistry.hasTenant(i) && (r = d(r, (e) => b(e("tenantId"), M))), !r.includeDeleted && T.schemaRegistry.hasSoftDelete(i) && (r = d(r, (e) => S(e("deletedAt")))), !r.includeExpired && T.schemaRegistry.hasExpires(i) && (r = d(r, (e) => xe(S(e("expiresAt")), he(e("expiresAt"), t))));
|
|
250
|
+
let a = r.predicate;
|
|
251
|
+
a = l(n, i, a);
|
|
252
|
+
let o = r.eager === void 0 ? void 0 : Fe(i, r.eager, n);
|
|
253
|
+
return o === void 0 ? a === r.predicate ? r : {
|
|
254
|
+
...r,
|
|
255
|
+
predicate: a
|
|
264
256
|
} : {
|
|
265
|
-
...
|
|
266
|
-
predicate:
|
|
267
|
-
eager:
|
|
257
|
+
...r,
|
|
258
|
+
predicate: a,
|
|
259
|
+
eager: o
|
|
268
260
|
};
|
|
269
|
-
},
|
|
270
|
-
let
|
|
271
|
-
return
|
|
261
|
+
}, Ze = (e, t = N) => {
|
|
262
|
+
let n = /* @__PURE__ */ new Date();
|
|
263
|
+
return s(e, (e) => Xe(e, n, t));
|
|
264
|
+
}, Qe = async (e, t, n) => {
|
|
265
|
+
let r = Ge(e), i = await t(r.descriptor), a = U(e.table, i);
|
|
266
|
+
return n && et(e.table, a), r.stripId ? a.map((e) => {
|
|
272
267
|
let { [D]: t, ...n } = e;
|
|
273
268
|
return n;
|
|
274
|
-
}) :
|
|
275
|
-
},
|
|
276
|
-
if (
|
|
269
|
+
}) : a;
|
|
270
|
+
}, $e = (e) => Qe(e, k.query.bind(k), !0), W = (e) => $e(Ze(e)), G = (e, t, n) => {
|
|
271
|
+
if (_e(n)) return;
|
|
277
272
|
let r = T.schemaRegistry.declaredPrimaryKey(e);
|
|
278
273
|
if (r.length === 0 || r.length === 1 && r[0] === "id") return;
|
|
279
274
|
let i = r.map((e) => `${e}: …`).join(", ");
|
|
280
275
|
throw Error(`${t}('${e}', <${typeof n}>, …) cannot address a row: '${e}' has no \`id\` column — its primary key is (${r.join(", ")}). Pass those columns instead:\n store.${t}('${e}', { ${i} }${t === "delete" ? "" : ", patch"})\nThis used to return ${t === "delete" ? "`false`" : "`null`"}, which is also what a missing row returns.`);
|
|
281
|
-
},
|
|
276
|
+
}, K = async (e, t) => {
|
|
282
277
|
if (M === null || !T.schemaRegistry.hasTenant(e)) return;
|
|
283
|
-
let n =
|
|
278
|
+
let n = we(t).map(([e, t]) => b(e, t)).reduce((e, t) => e === void 0 ? t : y(e, t), void 0);
|
|
284
279
|
if (!((await k.query({
|
|
285
280
|
table: e,
|
|
281
|
+
lock: "update",
|
|
286
282
|
predicate: y(n, b("tenantId", M)),
|
|
287
283
|
order: [],
|
|
288
284
|
take: 1,
|
|
289
285
|
skip: void 0,
|
|
290
|
-
projection:
|
|
291
|
-
})).length > 0)) throw new
|
|
286
|
+
projection: we(t).map(([e]) => e)
|
|
287
|
+
})).length > 0)) throw new Ae({
|
|
292
288
|
table: e,
|
|
293
289
|
id: C(t),
|
|
294
290
|
reason: "no row with this id in your tenant — it does not exist, or it belongs to another tenant. These are deliberately indistinguishable: reporting them differently would let a caller probe for row ids in other tenants."
|
|
295
291
|
});
|
|
296
|
-
},
|
|
297
|
-
let n =
|
|
292
|
+
}, q = Symbol.for("@voltro/runtime:tx-fold-releases"), J = Symbol.for("@voltro/runtime:tx-read-versions"), Y = (e) => e[J], X = (e, t) => `${e}\u0000${String(t)}`, et = (e, t) => {
|
|
293
|
+
let n = Y(k);
|
|
298
294
|
if (n === void 0 || t.length === 0) return;
|
|
299
295
|
let r = T.schemaRegistry.versionColumn(e);
|
|
300
296
|
if (r !== void 0) for (let i of t) {
|
|
301
297
|
let t = i[D], a = i[r];
|
|
302
|
-
typeof t == "string" && typeof a == "number" && Number.isFinite(a) && n.set(
|
|
298
|
+
typeof t == "string" && typeof a == "number" && Number.isFinite(a) && n.set(X(e, t), a);
|
|
303
299
|
}
|
|
304
|
-
},
|
|
300
|
+
}, Z = (() => {
|
|
305
301
|
let e = globalThis, t = Symbol.for("@voltro/runtime:crdt-fold-locks");
|
|
306
302
|
return e[t] ??= /* @__PURE__ */ new Map();
|
|
307
|
-
})(),
|
|
308
|
-
let r = `${e}\u0000${C(t)}`, i =
|
|
303
|
+
})(), tt = async (e, t, n) => {
|
|
304
|
+
let r = `${e}\u0000${C(t)}`, i = Z.get(r) ?? Promise.resolve(), a, o = new Promise((e) => {
|
|
309
305
|
a = e;
|
|
310
306
|
});
|
|
311
|
-
|
|
307
|
+
Z.set(r, i.then(() => o)), await i;
|
|
312
308
|
try {
|
|
313
309
|
return await n();
|
|
314
310
|
} finally {
|
|
315
|
-
a(),
|
|
311
|
+
a(), Z.get(r) === o && Z.delete(r);
|
|
316
312
|
}
|
|
317
|
-
},
|
|
313
|
+
}, Q = async (e, t, n) => {
|
|
318
314
|
let r = T.schemaRegistry.sealedColumns(e);
|
|
319
315
|
if (o(r, n)) {
|
|
320
316
|
let i = {}, a = {};
|
|
321
317
|
for (let [e, t] of Object.entries(n)) (r.has(e) ? i : a)[e] = t;
|
|
322
|
-
let o = await
|
|
323
|
-
return o === null || Object.keys(a).length === 0 ? o :
|
|
318
|
+
let o = await at(e, t, i);
|
|
319
|
+
return o === null || Object.keys(a).length === 0 ? o : Q(e, t, a);
|
|
324
320
|
}
|
|
325
321
|
let a = T.schemaRegistry.crdtColumns(e);
|
|
326
322
|
if (o(a, n)) {
|
|
327
323
|
for (let t of a) t in n && i(e, t, n[t]);
|
|
328
|
-
let r = k[
|
|
324
|
+
let r = k[q];
|
|
329
325
|
if (r !== void 0) {
|
|
330
326
|
let i = {}, o = {};
|
|
331
327
|
for (let [e, t] of Object.entries(n)) a.has(e) ? i[e] = t : o[e] = t;
|
|
@@ -333,8 +329,8 @@ var Me = (e, t, n) => {
|
|
|
333
329
|
table: e,
|
|
334
330
|
pk: t,
|
|
335
331
|
patch: i
|
|
336
|
-
}), Object.keys(o).length > 0) return
|
|
337
|
-
await
|
|
332
|
+
}), Object.keys(o).length > 0) return $(e, t, o);
|
|
333
|
+
await K(e, t);
|
|
338
334
|
let s = await k.query({
|
|
339
335
|
table: e,
|
|
340
336
|
predicate: {
|
|
@@ -347,15 +343,15 @@ var Me = (e, t, n) => {
|
|
|
347
343
|
skip: void 0,
|
|
348
344
|
projection: void 0
|
|
349
345
|
});
|
|
350
|
-
return s[0] === void 0 ? null :
|
|
346
|
+
return s[0] === void 0 ? null : U(e, [s[0]])[0];
|
|
351
347
|
}
|
|
352
|
-
return
|
|
348
|
+
return tt(e, t, () => $(e, t, n));
|
|
353
349
|
}
|
|
354
|
-
return
|
|
355
|
-
},
|
|
356
|
-
|
|
350
|
+
return $(e, t, n);
|
|
351
|
+
}, $ = async (e, t, n) => {
|
|
352
|
+
G(e, "update", t), await K(e, t);
|
|
357
353
|
let r = F(e, n), i = T.schemaRegistry.crdtColumns(e);
|
|
358
|
-
if (o(i, r)) return
|
|
354
|
+
if (o(i, r)) return ot(e, t, r, i);
|
|
359
355
|
if (T.schemaRegistry.computedFields(e).size > 0) {
|
|
360
356
|
let n = (await k.query({
|
|
361
357
|
table: e,
|
|
@@ -370,16 +366,16 @@ var Me = (e, t, n) => {
|
|
|
370
366
|
projection: void 0
|
|
371
367
|
}))[0];
|
|
372
368
|
if (n === void 0) return null;
|
|
373
|
-
let i =
|
|
374
|
-
r =
|
|
369
|
+
let i = U(e, [n])[0];
|
|
370
|
+
r = He(e, i, r);
|
|
375
371
|
}
|
|
376
372
|
r = L(e, r);
|
|
377
373
|
let a = T.schemaRegistry.versionColumn(e), s;
|
|
378
374
|
if (a !== void 0) {
|
|
379
|
-
let n =
|
|
375
|
+
let n = Se({
|
|
380
376
|
versionColumn: a,
|
|
381
377
|
patch: r
|
|
382
|
-
}), i =
|
|
378
|
+
}), i = Y(k)?.get(X(e, C(t))), o = n.expected === void 0 && i !== void 0, c = n.expected ?? i, l = (e) => {
|
|
383
379
|
throw o ? new j(e) : e;
|
|
384
380
|
}, u = async () => {
|
|
385
381
|
let n = await k.query({
|
|
@@ -395,7 +391,7 @@ var Me = (e, t, n) => {
|
|
|
395
391
|
projection: void 0
|
|
396
392
|
}), r = n[0] === void 0 ? void 0 : n[0][a];
|
|
397
393
|
return typeof r == "number" && Number.isFinite(r) ? r : null;
|
|
398
|
-
}, d = await u(), f =
|
|
394
|
+
}, d = await u(), f = Ee({
|
|
399
395
|
table: e,
|
|
400
396
|
id: C(t),
|
|
401
397
|
expected: c,
|
|
@@ -408,7 +404,7 @@ var Me = (e, t, n) => {
|
|
|
408
404
|
if (r = {
|
|
409
405
|
...n.patch,
|
|
410
406
|
[a]: o + 1
|
|
411
|
-
}, await I(e, "update", r, () => k.updateMany(e,
|
|
407
|
+
}, await I(e, "update", r, () => k.updateMany(e, V(e, r, t), { where: y(b(D, t), b(a, o)) })) > 0) {
|
|
412
408
|
s = (await k.query({
|
|
413
409
|
table: e,
|
|
414
410
|
predicate: {
|
|
@@ -420,22 +416,22 @@ var Me = (e, t, n) => {
|
|
|
420
416
|
take: 1,
|
|
421
417
|
skip: void 0,
|
|
422
418
|
projection: void 0
|
|
423
|
-
}))[0] ?? null,
|
|
419
|
+
}))[0] ?? null, Y(k)?.set(X(e, C(t)), o + 1);
|
|
424
420
|
break;
|
|
425
421
|
}
|
|
426
422
|
let f = await u();
|
|
427
|
-
(c !== void 0 || f === null || i >=
|
|
423
|
+
(c !== void 0 || f === null || i >= Ie) && l(new ae({
|
|
428
424
|
table: e,
|
|
429
425
|
id: C(t),
|
|
430
426
|
expected: c ?? o,
|
|
431
427
|
actual: f
|
|
432
428
|
})), d = f;
|
|
433
429
|
}
|
|
434
|
-
} else s = await I(e, "update", r, () => k.update(e, t,
|
|
435
|
-
return s === null ? null :
|
|
436
|
-
},
|
|
430
|
+
} else s = await I(e, "update", r, () => k.update(e, t, V(e, r, t)));
|
|
431
|
+
return s === null ? null : U(e, [s], t)[0];
|
|
432
|
+
}, nt = async (e, t, n) => {
|
|
437
433
|
let r = await k.query({
|
|
438
|
-
table:
|
|
434
|
+
table: p,
|
|
439
435
|
predicate: y(b("tableName", e), b("rowId", C(t)), b("columnName", n), b("reason", "rebase")),
|
|
440
436
|
order: [{
|
|
441
437
|
column: "createdAt",
|
|
@@ -445,9 +441,9 @@ var Me = (e, t, n) => {
|
|
|
445
441
|
skip: void 0,
|
|
446
442
|
projection: void 0
|
|
447
443
|
});
|
|
448
|
-
return
|
|
449
|
-
},
|
|
450
|
-
let a = P(
|
|
444
|
+
return U(p, r).map((e) => e.state).filter((e) => e instanceof Uint8Array);
|
|
445
|
+
}, rt = async (e, t, n, r, i) => {
|
|
446
|
+
let a = P(p, {
|
|
451
447
|
tableName: e,
|
|
452
448
|
rowId: C(t),
|
|
453
449
|
columnName: n,
|
|
@@ -457,16 +453,16 @@ var Me = (e, t, n) => {
|
|
|
457
453
|
epoch: i === void 0 ? E.epochOf(r) ?? null : i,
|
|
458
454
|
createdBy: null
|
|
459
455
|
});
|
|
460
|
-
await I(
|
|
461
|
-
},
|
|
456
|
+
await I(p, "insert", a, () => k.insert(p, B(p, R(p, a))));
|
|
457
|
+
}, it = async (e, t, n, r, i) => {
|
|
462
458
|
if (!(r instanceof Uint8Array) || !(i instanceof Uint8Array) || r.length === 0) return i;
|
|
463
459
|
let a = E.authorsOf(r), o = [...E.authorsOf(i)].filter((e) => !a.has(e));
|
|
464
460
|
if (o.length === 0 || E.epochOf(r) === void 0) return i;
|
|
465
|
-
for (let a of await
|
|
461
|
+
for (let a of await nt(e, t, n)) {
|
|
466
462
|
let t = E.authorsOf(a);
|
|
467
463
|
if (!o.some((e) => t.has(e))) continue;
|
|
468
464
|
let s = E.translate(a, i, r);
|
|
469
|
-
if (s === void 0) throw new
|
|
465
|
+
if (s === void 0) throw new Me({
|
|
470
466
|
field: n,
|
|
471
467
|
message: "crdt.staleLineage",
|
|
472
468
|
params: { table: e }
|
|
@@ -474,8 +470,8 @@ var Me = (e, t, n) => {
|
|
|
474
470
|
return s;
|
|
475
471
|
}
|
|
476
472
|
return i;
|
|
477
|
-
},
|
|
478
|
-
await
|
|
473
|
+
}, at = async (e, t, n) => {
|
|
474
|
+
await K(e, t);
|
|
479
475
|
for (let i = 0;; i += 1) {
|
|
480
476
|
let a = (await k.query({
|
|
481
477
|
table: e,
|
|
@@ -490,7 +486,7 @@ var Me = (e, t, n) => {
|
|
|
490
486
|
projection: void 0
|
|
491
487
|
}))[0];
|
|
492
488
|
if (a === void 0) return null;
|
|
493
|
-
let o =
|
|
489
|
+
let o = U(e, [a])[0], s = {}, c = [b(D, t)], l = [];
|
|
494
490
|
for (let [t, i] of Object.entries(n)) {
|
|
495
491
|
if (i === null) s[t] = null;
|
|
496
492
|
else {
|
|
@@ -504,8 +500,8 @@ var Me = (e, t, n) => {
|
|
|
504
500
|
c.push(n == null ? S(t) : b(t, n));
|
|
505
501
|
}
|
|
506
502
|
let u = F(e, s);
|
|
507
|
-
if (await I(e, "update", u, () => k.updateMany(e,
|
|
508
|
-
for (let n of l) await
|
|
503
|
+
if (await I(e, "update", u, () => k.updateMany(e, V(e, u, t), { where: y(...c) })) > 0) {
|
|
504
|
+
for (let n of l) await rt(e, t, n.column, n.log, n.epoch === "" ? null : n.epoch);
|
|
509
505
|
let n = await k.query({
|
|
510
506
|
table: e,
|
|
511
507
|
predicate: {
|
|
@@ -518,12 +514,12 @@ var Me = (e, t, n) => {
|
|
|
518
514
|
skip: void 0,
|
|
519
515
|
projection: void 0
|
|
520
516
|
});
|
|
521
|
-
return n[0] === void 0 ? null :
|
|
517
|
+
return n[0] === void 0 ? null : U(e, [n[0]], t)[0];
|
|
522
518
|
}
|
|
523
519
|
if (i + 1 >= O) throw Error(`sealed crdt append on ${e} lost ${O} compare-and-swap rounds to concurrent writers; the frame was not written and can be retried`);
|
|
524
520
|
await new Promise((e) => setTimeout(e, Math.random() * 5 * (i + 1)));
|
|
525
521
|
}
|
|
526
|
-
},
|
|
522
|
+
}, ot = async (e, t, n, r) => {
|
|
527
523
|
let i = async () => (await k.query({
|
|
528
524
|
table: e,
|
|
529
525
|
predicate: {
|
|
@@ -535,15 +531,15 @@ var Me = (e, t, n) => {
|
|
|
535
531
|
take: 1,
|
|
536
532
|
skip: void 0,
|
|
537
533
|
projection: void 0
|
|
538
|
-
}))[0], o = [...r].filter((e) => e in n), s = T.schemaRegistry.versionColumn(e), c = s === void 0 ? void 0 :
|
|
534
|
+
}))[0], o = [...r].filter((e) => e in n), s = T.schemaRegistry.versionColumn(e), c = s === void 0 ? void 0 : Se({
|
|
539
535
|
versionColumn: s,
|
|
540
536
|
patch: n
|
|
541
|
-
}), l = s === void 0 ? void 0 :
|
|
537
|
+
}), l = s === void 0 ? void 0 : Y(k)?.get(X(e, C(t))), u = c !== void 0 && c.expected === void 0 && l !== void 0, d = c?.expected ?? l, f = c?.patch ?? n, p = await i();
|
|
542
538
|
for (let n = 0;; n += 1) {
|
|
543
539
|
if (p === void 0) return null;
|
|
544
|
-
let c =
|
|
540
|
+
let c = U(e, [p])[0], l = f;
|
|
545
541
|
for (let n of o) {
|
|
546
|
-
let r = await
|
|
542
|
+
let r = await it(e, t, n, c[n], f[n]);
|
|
547
543
|
r !== f[n] && (l = {
|
|
548
544
|
...l,
|
|
549
545
|
[n]: r
|
|
@@ -555,7 +551,7 @@ var Me = (e, t, n) => {
|
|
|
555
551
|
archived: t
|
|
556
552
|
});
|
|
557
553
|
});
|
|
558
|
-
T.schemaRegistry.computedFields(e).size > 0 && (h =
|
|
554
|
+
T.schemaRegistry.computedFields(e).size > 0 && (h = He(e, c, h));
|
|
559
555
|
let g = [b(D, t)];
|
|
560
556
|
for (let e of o) {
|
|
561
557
|
let t = p[e];
|
|
@@ -565,7 +561,7 @@ var Me = (e, t, n) => {
|
|
|
565
561
|
if (s !== void 0) {
|
|
566
562
|
let n = p[s];
|
|
567
563
|
_ = typeof n == "number" && Number.isFinite(n) ? n : void 0;
|
|
568
|
-
let r =
|
|
564
|
+
let r = Ee({
|
|
569
565
|
table: e,
|
|
570
566
|
id: C(t),
|
|
571
567
|
expected: d,
|
|
@@ -579,18 +575,18 @@ var Me = (e, t, n) => {
|
|
|
579
575
|
}
|
|
580
576
|
h = L(e, h);
|
|
581
577
|
let v = h;
|
|
582
|
-
if (await I(e, "update", v, () => k.updateMany(e,
|
|
583
|
-
for (let { column: n, archived: r } of m) await
|
|
578
|
+
if (await I(e, "update", v, () => k.updateMany(e, V(e, v, t), { where: y(...g) })) > 0) {
|
|
579
|
+
for (let { column: n, archived: r } of m) await rt(e, t, n, r);
|
|
584
580
|
let n = await i();
|
|
585
|
-
return n === void 0 ? null : (s !== void 0 && _ !== void 0 &&
|
|
581
|
+
return n === void 0 ? null : (s !== void 0 && _ !== void 0 && Y(k)?.set(X(e, C(t)), _ + 1), U(e, [n], t)[0]);
|
|
586
582
|
}
|
|
587
583
|
if (n + 1 >= O) throw Error(`crdt fold on ${e} lost ${O} compare-and-swap rounds to concurrent writers; the update was not written and can be retried`);
|
|
588
584
|
await new Promise((e) => setTimeout(e, Math.random() * 5 * (n + 1))), p = await i();
|
|
589
585
|
}
|
|
590
|
-
},
|
|
586
|
+
}, st = async (e, t) => (G(e, "delete", t), await K(e, t), T.schemaRegistry.hasSoftDelete(e) ? await Q(e, t, Ue()) !== null : I(e, "delete", void 0, () => k.delete(e, t))), ct = async (e, t, n) => {
|
|
591
587
|
let r = F(e, t), i = T.schemaRegistry.versionColumn(e);
|
|
592
588
|
if (i === void 0) {
|
|
593
|
-
if (!
|
|
589
|
+
if (!H(e, r)) return I(e, "updateMany", r, () => k.updateMany(e, B(e, r), n));
|
|
594
590
|
let t = await k.query({
|
|
595
591
|
table: e,
|
|
596
592
|
predicate: n.where,
|
|
@@ -601,7 +597,7 @@ var Me = (e, t, n) => {
|
|
|
601
597
|
}), i = 0;
|
|
602
598
|
for (let a of t) {
|
|
603
599
|
let t = a[D];
|
|
604
|
-
t != null && (i += await I(e, "updateMany", r, () => k.updateMany(e,
|
|
600
|
+
t != null && (i += await I(e, "updateMany", r, () => k.updateMany(e, V(e, r, t), { where: y(n.where, b(D, t)) })));
|
|
605
601
|
}
|
|
606
602
|
return i;
|
|
607
603
|
}
|
|
@@ -621,12 +617,12 @@ var Me = (e, t, n) => {
|
|
|
621
617
|
let o = a, l = {
|
|
622
618
|
...s,
|
|
623
619
|
[i]: o + 1
|
|
624
|
-
}, u = await I(e, "updateMany", l, () => k.updateMany(e,
|
|
620
|
+
}, u = await I(e, "updateMany", l, () => k.updateMany(e, V(e, l, r), { where: y(n.where, b(D, r), b(i, o)) }));
|
|
625
621
|
if (u > 0) {
|
|
626
622
|
c += u;
|
|
627
623
|
break;
|
|
628
624
|
}
|
|
629
|
-
if (t >=
|
|
625
|
+
if (t >= Ie) throw new ae({
|
|
630
626
|
table: e,
|
|
631
627
|
id: r,
|
|
632
628
|
expected: o,
|
|
@@ -643,25 +639,25 @@ var Me = (e, t, n) => {
|
|
|
643
639
|
}
|
|
644
640
|
}
|
|
645
641
|
return c;
|
|
646
|
-
},
|
|
642
|
+
}, lt = async (e, t) => I(e, "deleteMany", void 0, () => k.deleteMany(e, t)), ut = (e, t) => M != null && T.schemaRegistry.hasTenant(e) ? y(t, b("tenantId", M)) : t, dt = async (e, t, n) => ct(e, t, {
|
|
647
643
|
...n,
|
|
648
|
-
where:
|
|
649
|
-
}),
|
|
644
|
+
where: ut(e, n.where)
|
|
645
|
+
}), ft = async (e, t) => lt(e, {
|
|
650
646
|
...t,
|
|
651
|
-
where:
|
|
652
|
-
}),
|
|
653
|
-
query:
|
|
654
|
-
updateMany:
|
|
655
|
-
deleteMany:
|
|
647
|
+
where: ut(e, t.where)
|
|
648
|
+
}), pt = ee({
|
|
649
|
+
query: $e,
|
|
650
|
+
updateMany: ct,
|
|
651
|
+
deleteMany: lt,
|
|
656
652
|
delete: (e, t) => k.delete(e, t)
|
|
657
653
|
}, {
|
|
658
654
|
subject: T.subject,
|
|
659
655
|
schemaRegistry: T.schemaRegistry,
|
|
660
656
|
rowFilter: N
|
|
661
|
-
}),
|
|
662
|
-
let
|
|
663
|
-
return
|
|
664
|
-
},
|
|
657
|
+
}), mt = ((e, t, n) => t === void 0 ? pt.updateWhere(e) : Q(e, t, n)), ht = ((e, t) => t === void 0 ? pt.deleteWhere(e) : st(e, t)), gt = async (e, t, n) => {
|
|
658
|
+
let r = t.map((t) => P(e, t)), i = x(e), a = t.length >= 32 && i !== void 0 && T.schemaRegistry.insertSchema(e) === void 0 && T.schemaRegistry.crdtColumns(e).size === 0 && T.schemaRegistry.sealedColumns(e).size === 0 ? v(i) : void 0, o = r.map((t) => R(e, t, a)), s = z ? o.map((e) => Te(e, i, z)) : o, c = ue(s, i, m()), l = await I(e, "insertMany", r[0], () => k.insertMany(e, c, n));
|
|
659
|
+
return U(e, l);
|
|
660
|
+
}, _t = (e, t) => {
|
|
665
661
|
let n = Object.keys(t);
|
|
666
662
|
if (n.length !== 1) throw Error(`store.links('${e}'): anchor must name exactly one source column, got [${n.join(", ")}]`);
|
|
667
663
|
let r = n[0], i = t[r], a = x(e);
|
|
@@ -674,7 +670,7 @@ var Me = (e, t, n) => {
|
|
|
674
670
|
sourceId: i,
|
|
675
671
|
targetCol: o.find((e) => e !== r)
|
|
676
672
|
};
|
|
677
|
-
},
|
|
673
|
+
}, vt = (e, t) => {
|
|
678
674
|
let n = x(e);
|
|
679
675
|
if (n === void 0) throw Error(`store.relationLinks('${e}'): unknown table (not registered) — declare it and its relation first`);
|
|
680
676
|
let r = Object.entries(n.fields).filter(([, e]) => e.type === "reference").filter(([, e]) => {
|
|
@@ -687,8 +683,8 @@ var Me = (e, t, n) => {
|
|
|
687
683
|
}).map(([e]) => e);
|
|
688
684
|
if (r.length === 1) return r[0];
|
|
689
685
|
throw r.length === 0 ? Error(`store.relationLinks('${e}'): no reference column points at '${t}' — the junction's reference() targets decide the anchor, and none matches.`) : Error(`store.relationLinks('${e}'): ${r.length} reference columns point at '${t}' [${r.join(", ")}] — a self-junction is ambiguous; use store.links('${e}', { <column>: id }) and name the side.`);
|
|
690
|
-
},
|
|
691
|
-
let { sourceCol: n, sourceId: r, targetCol: i } =
|
|
686
|
+
}, yt = (e, t) => {
|
|
687
|
+
let { sourceCol: n, sourceId: r, targetCol: i } = _t(e, t), a = async () => (await W({
|
|
692
688
|
table: e,
|
|
693
689
|
predicate: b(n, r),
|
|
694
690
|
order: [],
|
|
@@ -696,12 +692,12 @@ var Me = (e, t, n) => {
|
|
|
696
692
|
skip: void 0,
|
|
697
693
|
take: void 0
|
|
698
694
|
})).map((e) => String(e[i])), o = async (t) => {
|
|
699
|
-
t.length !== 0 && await
|
|
695
|
+
t.length !== 0 && await gt(e, t.map((e) => ({
|
|
700
696
|
[n]: r,
|
|
701
697
|
[i]: e
|
|
702
|
-
})));
|
|
698
|
+
})), { returning: "none" });
|
|
703
699
|
}, s = async (t) => {
|
|
704
|
-
t.length !== 0 && await
|
|
700
|
+
t.length !== 0 && await ft(e, { where: y(b(n, r), ge(i, t)) });
|
|
705
701
|
};
|
|
706
702
|
return {
|
|
707
703
|
columns: {
|
|
@@ -725,7 +721,7 @@ var Me = (e, t, n) => {
|
|
|
725
721
|
return await s(n), n;
|
|
726
722
|
},
|
|
727
723
|
setRows: async (t) => {
|
|
728
|
-
let a = /* @__PURE__ */ new Map(), o = await
|
|
724
|
+
let a = /* @__PURE__ */ new Map(), o = await W({
|
|
729
725
|
table: e,
|
|
730
726
|
predicate: b(n, r),
|
|
731
727
|
order: [],
|
|
@@ -747,27 +743,27 @@ var Me = (e, t, n) => {
|
|
|
747
743
|
else {
|
|
748
744
|
let s = a.get(t), c = {}, l = !1;
|
|
749
745
|
for (let [e, t] of Object.entries(o)) e !== n && e !== i && s[e] !== t && (c[e] = t, l = !0);
|
|
750
|
-
l && (d.push(t), await
|
|
746
|
+
l && (d.push(t), await dt(e, c, { where: y(b(n, r), b(i, t)) }));
|
|
751
747
|
}
|
|
752
|
-
return f.length > 0 && await
|
|
748
|
+
return f.length > 0 && await gt(e, f, { returning: "none" }), {
|
|
753
749
|
added: u,
|
|
754
750
|
removed: l,
|
|
755
751
|
updated: d
|
|
756
752
|
};
|
|
757
753
|
}
|
|
758
754
|
};
|
|
759
|
-
},
|
|
760
|
-
let i = t[D] !== void 0 && t[D] !== null, a = P(e, t), o =
|
|
761
|
-
if (
|
|
755
|
+
}, bt = async (e, t, n, r) => {
|
|
756
|
+
let i = t[D] !== void 0 && t[D] !== null, a = P(e, t), o = Oe(n), s = n;
|
|
757
|
+
if (We(e, a, n.conflictColumns), typeof n.update == "function") {
|
|
762
758
|
let t = n.update;
|
|
763
759
|
s = {
|
|
764
760
|
conflictColumns: n.conflictColumns,
|
|
765
761
|
update: (n) => {
|
|
766
|
-
let r = n.id, i =
|
|
762
|
+
let r = n.id, i = U(e, [n], r)[0], a = F(e, {
|
|
767
763
|
...t(i),
|
|
768
764
|
...o
|
|
769
765
|
});
|
|
770
|
-
return
|
|
766
|
+
return V(e, L(e, a), r);
|
|
771
767
|
}
|
|
772
768
|
};
|
|
773
769
|
} else {
|
|
@@ -780,7 +776,7 @@ var Me = (e, t, n) => {
|
|
|
780
776
|
...Object.fromEntries(r.filter((e) => e in t).map((e) => [e, t[e]])),
|
|
781
777
|
...o
|
|
782
778
|
}, a = F(e, i);
|
|
783
|
-
o =
|
|
779
|
+
o = Oe({
|
|
784
780
|
conflictColumns: n.conflictColumns,
|
|
785
781
|
updateValues: {
|
|
786
782
|
...o,
|
|
@@ -788,74 +784,80 @@ var Me = (e, t, n) => {
|
|
|
788
784
|
}
|
|
789
785
|
});
|
|
790
786
|
}
|
|
791
|
-
let c = !i && typeof a[D] == "string" ? a[D] : void 0, l =
|
|
787
|
+
let c = !i && typeof a[D] == "string" ? a[D] : void 0, l = H(e, a) || H(e, o) || r && c === void 0, u = l ? await g(k, e, a, n.conflictColumns) : void 0, d = l ? u === void 0 ? a[D] : u : void 0, f = l ? u === void 0 ? "inserted" : "updated" : void 0, p = await I(e, "upsert", a, () => k.upsert(e, B(e, R(e, a), d), {
|
|
792
788
|
...s,
|
|
793
789
|
...typeof n.update != "function" && (n.updateValues !== void 0 || Object.keys(o).length > 0) ? { updateValues: B(e, L(e, o), d) } : {}
|
|
794
790
|
}));
|
|
795
791
|
return {
|
|
796
|
-
row:
|
|
792
|
+
row: U(e, [p], d)[0],
|
|
797
793
|
outcome: f ?? (c !== void 0 && p[D] !== c ? "updated" : "inserted")
|
|
798
794
|
};
|
|
799
|
-
},
|
|
795
|
+
}, xt = async (e, t, n) => {
|
|
800
796
|
let r = P(e, t);
|
|
801
|
-
|
|
797
|
+
We(e, r, n.conflictColumns);
|
|
802
798
|
let i = await I(e, "insertIgnore", r, () => k.insertIgnoreWithOutcome(e, B(e, R(e, r)), n));
|
|
803
799
|
return {
|
|
804
|
-
row:
|
|
800
|
+
row: U(e, [i.row])[0],
|
|
805
801
|
outcome: i.outcome
|
|
806
802
|
};
|
|
807
803
|
};
|
|
808
804
|
return {
|
|
809
|
-
query:
|
|
805
|
+
query: W,
|
|
806
|
+
...k.integrityQuery === void 0 ? {} : { integrityQuery: (e) => Qe(Ze({
|
|
807
|
+
...e,
|
|
808
|
+
crossTenant: !1,
|
|
809
|
+
includeDeleted: !1,
|
|
810
|
+
includeExpired: !1
|
|
811
|
+
}, c), k.integrityQuery.bind(k), !1) },
|
|
810
812
|
one: (async (e, t) => {
|
|
811
|
-
let n =
|
|
813
|
+
let n = Le(e), r = await W({
|
|
812
814
|
...n,
|
|
813
815
|
take: 2
|
|
814
816
|
}), i = r[0];
|
|
815
|
-
if (i === void 0) throw
|
|
817
|
+
if (i === void 0) throw te({
|
|
816
818
|
table: n.table,
|
|
817
819
|
found: 0
|
|
818
820
|
}, t);
|
|
819
|
-
if (r.length > 1) throw
|
|
821
|
+
if (r.length > 1) throw te({
|
|
820
822
|
table: n.table,
|
|
821
823
|
found: r.length
|
|
822
824
|
}, t);
|
|
823
825
|
return i;
|
|
824
826
|
}),
|
|
825
|
-
first: ((e) =>
|
|
826
|
-
maybeOne: ((e) =>
|
|
827
|
+
first: ((e) => f({ query: W }, e)),
|
|
828
|
+
maybeOne: ((e) => f({ query: W }, e)),
|
|
827
829
|
insert: async (e, t) => {
|
|
828
830
|
let n = P(e, t), r = await I(e, "insert", n, () => k.insert(e, B(e, R(e, n))));
|
|
829
|
-
return
|
|
831
|
+
return U(e, [r])[0];
|
|
830
832
|
},
|
|
831
|
-
insertMany: (async (e, t) =>
|
|
832
|
-
links:
|
|
833
|
-
relationLinks: (e, t, n) =>
|
|
833
|
+
insertMany: (async (e, t, n) => gt(e, t, n)),
|
|
834
|
+
links: yt,
|
|
835
|
+
relationLinks: (e, t, n) => yt(e, { [vt(e, t)]: n }),
|
|
834
836
|
patchJson: async (e, t, n, r, i) => {
|
|
835
|
-
|
|
836
|
-
let a =
|
|
837
|
-
return o === null ? null :
|
|
837
|
+
G(e, "patchJson", t), await K(e, t);
|
|
838
|
+
let a = ve(t, n, F(e, ve(t, n, i), [n.split(".")[0]])), o = await I(e, "patchJson", a, () => k.patchJson(e, t, n, r, V(e, L(e, a), t)));
|
|
839
|
+
return o === null ? null : U(e, [o], t)[0];
|
|
838
840
|
},
|
|
839
|
-
select:
|
|
840
|
-
update:
|
|
841
|
-
delete:
|
|
842
|
-
applyDefined:
|
|
843
|
-
hardDelete: async (e, t) => (
|
|
844
|
-
updateMany:
|
|
845
|
-
deleteMany:
|
|
846
|
-
upsert: async (e, t, n) => (await
|
|
847
|
-
upsertWithOutcome: (e, t, n) =>
|
|
848
|
-
insertIgnore: async (e, t, n) => (await
|
|
849
|
-
insertIgnoreWithOutcome: (e, t, n) =>
|
|
841
|
+
select: pt.select,
|
|
842
|
+
update: mt,
|
|
843
|
+
delete: ht,
|
|
844
|
+
applyDefined: Re,
|
|
845
|
+
hardDelete: async (e, t) => (G(e, "hardDelete", t), await K(e, t), I(e, "hardDelete", void 0, () => k.delete(e, t))),
|
|
846
|
+
updateMany: dt,
|
|
847
|
+
deleteMany: ft,
|
|
848
|
+
upsert: async (e, t, n) => (await bt(e, t, n, !1)).row,
|
|
849
|
+
upsertWithOutcome: (e, t, n) => bt(e, t, n, !0),
|
|
850
|
+
insertIgnore: async (e, t, n) => (await xt(e, t, n)).row,
|
|
851
|
+
insertIgnoreWithOutcome: (e, t, n) => xt(e, t, n),
|
|
850
852
|
transactional: async (e) => {
|
|
851
853
|
let t = await k.transactional(async (t) => {
|
|
852
854
|
let n = [];
|
|
853
|
-
return t[
|
|
854
|
-
result: await e(
|
|
855
|
+
return t[q] = n, t[J] = /* @__PURE__ */ new Map(), {
|
|
856
|
+
result: await e(Ve(t, T)),
|
|
855
857
|
jobs: n
|
|
856
858
|
};
|
|
857
859
|
});
|
|
858
|
-
for (let e of t.jobs) await
|
|
860
|
+
for (let e of t.jobs) await Q(e.table, e.pk, e.patch);
|
|
859
861
|
return t.result;
|
|
860
862
|
},
|
|
861
863
|
...k.raw ? { raw: ((e, r) => (n(Object.freeze({
|
|
@@ -866,8 +868,8 @@ var Me = (e, t, n) => {
|
|
|
866
868
|
onChange: (e) => k.onChange(e),
|
|
867
869
|
injectExternalChange: (e) => k.injectExternalChange(e),
|
|
868
870
|
...k.changeScope === void 0 ? {} : { changeScope: k.changeScope },
|
|
869
|
-
...k[
|
|
870
|
-
...
|
|
871
|
+
...k[q] === void 0 ? {} : { [q]: k[q] },
|
|
872
|
+
...Y(k) === void 0 ? {} : { [J]: Y(k) }
|
|
871
873
|
};
|
|
872
874
|
}, A = "VoltroTransactionReadConflict", j = class extends Error {
|
|
873
875
|
conflict;
|
|
@@ -876,5 +878,4 @@ var Me = (e, t, n) => {
|
|
|
876
878
|
super(e.message), this.conflict = e;
|
|
877
879
|
}
|
|
878
880
|
}, M = (e) => typeof e == "object" && !!e && e.name === "VoltroTransactionReadConflict" && "conflict" in e, N = Symbol.for("@voltro/runtime:tx-read-versions");
|
|
879
|
-
|
|
880
|
-
export { A as TRANSACTION_READ_CONFLICT_NAME, N as TX_READ_VERSIONS_KEY, j as TransactionReadConflict, Le as actingUserId, Fe as applyDefined, M as isTransactionReadConflict, Re as wrapStoreWithMixinBehaviour };
|
|
881
|
+
export { A as TRANSACTION_READ_CONFLICT_NAME, N as TX_READ_VERSIONS_KEY, j as TransactionReadConflict, Be as actingUserId, Re as applyDefined, M as isTransactionReadConflict, Ve as wrapStoreWithMixinBehaviour };
|