@voltro/runtime 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/README.md +43 -0
- package/THIRD-PARTY-NOTICES.md +864 -253
- package/dist/aggregate.js +42 -0
- package/dist/aggregateExtrema.js +80 -0
- package/dist/aggregateIvm.js +115 -0
- package/dist/analyticsMirror.js +228 -0
- package/dist/analyticsSink.js +32 -0
- package/dist/apiKeyUsage.js +33 -0
- package/dist/apiKeys.js +227 -0
- package/dist/apiKeysWiring.js +114 -0
- package/dist/apiRoleBucketSampler.js +64 -0
- package/dist/apiRoleWorkloadHistory.js +56 -0
- package/dist/apiRoleWorkloadMetrics.js +78 -0
- package/dist/apiRoleWorkloadStorage.js +95 -0
- package/dist/approvalBuiltins.js +10 -0
- package/dist/approvals.js +262 -0
- package/dist/authMiddlewareLayer.js +48 -0
- package/dist/bindEvent.js +92 -0
- package/dist/bootListener.js +143 -0
- package/dist/bootRefusal.js +7 -0
- package/dist/bootStoreCodec.js +71 -0
- package/dist/businessRules.js +67 -0
- package/dist/changeClaimsTable.js +12 -0
- package/dist/circuitBreaker.js +1 -0
- package/dist/columnOnUpdate.js +23 -0
- package/dist/composeAnalytics.js +129 -0
- package/dist/computedQuery.js +4 -0
- package/dist/computedQueryCache.js +231 -0
- package/dist/connectionBuiltins.js +81 -0
- package/dist/connectionCredentials.js +66 -0
- package/dist/connectionState.js +34 -0
- package/dist/connectionVault.js +410 -0
- package/dist/connectionsFacade.js +56 -0
- package/dist/coordinatedSchedule.js +145 -0
- package/dist/crdtHistory.js +138 -0
- package/dist/crdtMerge.js +179 -0
- package/dist/crdtVersionsTable.js +25 -0
- package/dist/credentialBound.js +12 -0
- package/dist/crud.js +72 -0
- package/dist/dataStore.js +712 -0
- package/dist/dataloader.js +61 -0
- package/dist/declaredTablesGuard.js +49 -0
- package/dist/defineExecutor.js +4 -0
- package/dist/dependencyGraph.js +32 -0
- package/dist/devices.js +228 -0
- package/dist/devicesWiring.js +168 -0
- package/dist/dialectReplicationAdapter.js +29 -0
- package/dist/dispatcher.js +522 -0
- package/dist/effectStore.js +71 -0
- package/dist/engineClients.js +24 -0
- package/dist/eventBus.js +260 -0
- package/dist/eventPublish.js +49 -0
- package/dist/events.js +193 -0
- package/dist/expectation.js +52 -0
- package/dist/expectationEvaluator.js +308 -0
- package/dist/experiment.js +96 -0
- package/dist/experimentEvaluator.js +245 -0
- package/dist/externalizedTasks.js +38 -0
- package/dist/fieldCipher.js +130 -0
- package/dist/fieldKeyRegistry.js +295 -0
- package/dist/fieldKeyRekey.js +286 -0
- package/dist/fieldKeyScan.js +136 -0
- package/dist/fieldKeyring.js +77 -0
- package/dist/fingerprint.js +21 -0
- package/dist/finops.js +42 -0
- package/dist/finopsAccountant.js +216 -0
- package/dist/handlerBody.js +8 -0
- package/dist/healthProbes.js +55 -0
- package/dist/hot.d.ts +56 -0
- package/dist/hot.js +3 -0
- package/dist/hotDataStore.js +148 -0
- package/dist/hotDataStoreSnapshot.js +98 -0
- package/dist/hotDataStoreTables.js +18 -0
- package/dist/http-range.d.ts +53 -0
- package/dist/http-range.js +52 -0
- package/dist/httpClientSsrf.js +24 -0
- package/dist/httpClientTracing.js +14 -0
- package/dist/httpCompression.js +76 -0
- package/dist/httpInputStream.js +82 -0
- package/dist/httpKeepAlive.js +12 -0
- package/dist/httpRouteMounts.js +48 -0
- package/dist/idempotencyStore.js +110 -0
- package/dist/idleDetector.js +21 -0
- package/dist/index.d.ts +1249 -517
- package/dist/index.js +155 -15292
- package/dist/insertRequiredColumns.js +19 -0
- package/dist/inspectWorkflow.js +1 -0
- package/dist/instanceMembership.js +98 -0
- package/dist/ivm.js +125 -0
- package/dist/kvDataStore.js +86 -0
- package/dist/kvFacade.js +38 -0
- package/dist/matcher.js +304 -0
- package/dist/memoryColumnDefaults.js +11 -0
- package/dist/memoryQueryJoins.js +114 -0
- package/dist/memorySetOperations.js +43 -0
- package/dist/metrics.js +175 -0
- package/dist/observability.js +123 -0
- package/dist/observedGraph.js +52 -0
- package/dist/originGuard.js +116 -0
- package/dist/outbox.js +352 -0
- package/dist/pluginRefRules.js +65 -0
- package/dist/policyGuardResolver.js +55 -0
- package/dist/preview.js +62 -0
- package/dist/projectedRows.js +12 -0
- package/dist/provenance.js +63 -0
- package/dist/rangeIndex.js +89 -0
- package/dist/rawReadScope.js +17 -0
- package/dist/reaction.js +85 -0
- package/dist/reactiveConfig.js +11 -0
- package/dist/readClassification.js +57 -0
- package/dist/readRecorder.js +67 -0
- package/dist/readScopePredicate.js +12 -0
- package/dist/rebac.js +104 -0
- package/dist/rebacInterceptor.js +81 -0
- package/dist/registry.js +29 -0
- package/dist/relevantFields.js +65 -0
- package/dist/replicaHealth.js +42 -0
- package/dist/replicaLocality.js +44 -0
- package/dist/replicaObservations.js +121 -0
- package/dist/replicaSelection.js +32 -0
- package/dist/replicatedDataStore.js +257 -0
- package/dist/requestLoader.js +7 -0
- package/dist/resumeCensus.js +28 -0
- package/dist/revalidation.js +22 -0
- package/dist/rowFilter.js +82 -0
- package/dist/rowStateBytes.js +45 -0
- package/dist/rpcBodyCap.js +63 -0
- package/dist/rpcConnections.js +83 -0
- package/dist/rpcDefectDiagnostics.js +15 -0
- package/dist/rpcServer.js +1065 -0
- package/dist/rpcWorkloadAdmission.js +50 -0
- package/dist/runAsSystem.js +23 -0
- package/dist/rywPositionStore.js +119 -0
- package/dist/schedule.js +23 -0
- package/dist/scheduleBackfillRequests.js +151 -0
- package/dist/scheduleClaimsTable.js +11 -0
- package/dist/scheduleRunsTable.js +37 -0
- package/dist/scheduler.js +840 -0
- package/dist/schemaRegistry.js +65 -0
- package/dist/secretsResolver.js +35 -0
- package/dist/securityHeaders.js +33 -0
- package/dist/servePipeline.js +374 -0
- package/dist/serverOnlyAudit.js +66 -0
- package/dist/serverTracer.js +15 -0
- package/dist/serviceCredentials.js +40 -0
- package/dist/setReadScopes.js +28 -0
- package/dist/singleNodeOrchestrator.js +91 -0
- package/dist/snapshotValueCodec.js +46 -0
- package/dist/sourceResolution.js +52 -0
- package/dist/storeMiddleware.js +882 -0
- package/dist/storeQuery.js +204 -0
- package/dist/storeRead.js +10 -0
- package/dist/subscriber.js +8 -0
- package/dist/subscriptionOutbox.js +139 -0
- package/dist/subscriptionRegistry.js +82 -0
- package/dist/subscriptionResume.js +132 -0
- package/dist/subscriptionSocketMetrics.js +65 -0
- package/dist/systemSubject.js +5 -0
- package/dist/tenantScope.js +11 -0
- package/dist/tenantSelection.js +27 -0
- package/dist/timeline.js +105 -0
- package/dist/traceContext.js +5 -0
- package/dist/traceSink.js +63 -0
- package/dist/traceSpansTable.js +29 -0
- package/dist/traceparent.js +23 -0
- package/dist/transactionSubject.js +12 -0
- package/dist/trustedProxy.js +155 -0
- package/dist/undo.js +129 -0
- package/dist/undoBuiltins.js +69 -0
- package/dist/undoCapture.js +74 -0
- package/dist/undoLogTable.js +16 -0
- package/dist/upsertBinding.js +20 -0
- package/dist/wakeOrchestrator.js +34 -0
- package/dist/wakeRegistry.js +71 -0
- package/dist/wakeRouter.js +63 -0
- package/dist/wakeSupervisor.js +62 -0
- package/dist/wakeupsTable.js +12 -0
- package/dist/webSocketGatewayRuntime.js +154 -0
- package/dist/webhookVerification.js +18 -0
- package/dist/wireColumnStrip.js +84 -0
- package/dist/workflowReadBuiltins.js +87 -0
- package/dist/workflowRuntime.js +708 -0
- package/package.json +19 -7
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { createLogger as e } from "@voltro/logger";
|
|
2
|
+
import { processIdentity as t } from "@voltro/protocol/identity";
|
|
3
|
+
//#region src/replicaObservations.ts
|
|
4
|
+
var n = e({ scope: "voltro:replica-observations" }), r = "_voltro_replica_observations", i = (e) => e instanceof Date ? e.getTime() : typeof e == "number" ? e : NaN, a = /* @__PURE__ */ new Set(), o = () => {
|
|
5
|
+
a.clear();
|
|
6
|
+
}, s = async (e, i, o) => {
|
|
7
|
+
let s = t(), c = {
|
|
8
|
+
replicaId: s.replicaId,
|
|
9
|
+
startedAt: new Date(s.startedAt),
|
|
10
|
+
version: s.version ?? null,
|
|
11
|
+
kind: i,
|
|
12
|
+
payload: JSON.stringify(o),
|
|
13
|
+
reachableAt: s.reachable ? s.reachableAt ?? null : null
|
|
14
|
+
};
|
|
15
|
+
try {
|
|
16
|
+
await e.upsert(r, {
|
|
17
|
+
...c,
|
|
18
|
+
writtenAt: /* @__PURE__ */ new Date()
|
|
19
|
+
}, { conflictColumns: ["replicaId", "kind"] });
|
|
20
|
+
} catch (e) {
|
|
21
|
+
let t = {
|
|
22
|
+
kind: i,
|
|
23
|
+
error: String(e)
|
|
24
|
+
};
|
|
25
|
+
a.has(i) ? n.debug("could not record this replica’s observation", t) : (a.add(i), n.warn("could not record this replica’s observation — fleet views will report this replica as stale for as long as this keeps failing", t));
|
|
26
|
+
}
|
|
27
|
+
}, c = async (e, t, n = Date.now()) => {
|
|
28
|
+
try {
|
|
29
|
+
return (await e.query({
|
|
30
|
+
table: r,
|
|
31
|
+
predicate: {
|
|
32
|
+
column: "kind",
|
|
33
|
+
op: "eq",
|
|
34
|
+
value: t
|
|
35
|
+
},
|
|
36
|
+
order: [],
|
|
37
|
+
take: void 0,
|
|
38
|
+
skip: void 0,
|
|
39
|
+
projection: void 0
|
|
40
|
+
})).map((e) => {
|
|
41
|
+
let r = i(e.writtenAt);
|
|
42
|
+
return {
|
|
43
|
+
replicaId: String(e.replicaId ?? ""),
|
|
44
|
+
startedAt: i(e.startedAt),
|
|
45
|
+
version: e.version === null || e.version === void 0 ? void 0 : String(e.version),
|
|
46
|
+
kind: t,
|
|
47
|
+
payload: u(e.payload),
|
|
48
|
+
reachableAt: e.reachableAt === null || e.reachableAt === void 0 ? void 0 : String(e.reachableAt),
|
|
49
|
+
writtenAt: r,
|
|
50
|
+
ageMs: Number.isNaN(r) ? NaN : Math.max(0, n - r)
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
} catch (e) {
|
|
54
|
+
throw new l(String(e));
|
|
55
|
+
}
|
|
56
|
+
}, l = class extends Error {
|
|
57
|
+
detail;
|
|
58
|
+
_tag = "ObservationsUnavailable";
|
|
59
|
+
constructor(e) {
|
|
60
|
+
super("the replica-observation table could not be read"), this.detail = e;
|
|
61
|
+
}
|
|
62
|
+
}, u = (e) => {
|
|
63
|
+
if (typeof e == "string") try {
|
|
64
|
+
return JSON.parse(e);
|
|
65
|
+
} catch {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
}, d = async (e, t) => {
|
|
69
|
+
try {
|
|
70
|
+
await e.deleteMany(r, { where: {
|
|
71
|
+
column: "replicaId",
|
|
72
|
+
op: "eq",
|
|
73
|
+
value: t
|
|
74
|
+
} });
|
|
75
|
+
} catch {}
|
|
76
|
+
}, f = 12e4, p = (e, t, n = f) => {
|
|
77
|
+
let r = /* @__PURE__ */ new Map();
|
|
78
|
+
for (let t of e) {
|
|
79
|
+
if (t.replicaId === "") continue;
|
|
80
|
+
let e = r.get(t.replicaId);
|
|
81
|
+
(e === void 0 || t.startedAt > e.startedAt || t.startedAt === e.startedAt && t.writtenAt > e.writtenAt) && r.set(t.replicaId, t);
|
|
82
|
+
}
|
|
83
|
+
let i = [...r.values()].filter((e) => e.payload !== void 0).map((e) => ({
|
|
84
|
+
replicaId: e.replicaId,
|
|
85
|
+
version: e.version,
|
|
86
|
+
ageMs: e.ageMs,
|
|
87
|
+
reachableAt: e.reachableAt,
|
|
88
|
+
payload: e.payload
|
|
89
|
+
})).sort((e, t) => e.replicaId.localeCompare(t.replicaId)), a = new Set(t.map((e) => e.instanceId.split("@")[0] ?? e.instanceId)), o = a.size > 0, s = (e) => !a.has(e.replicaId) && Number.isFinite(e.ageMs) && e.ageMs > n, c = o ? [] : i, l = [], u = [], d = /* @__PURE__ */ new Set(), p = {};
|
|
90
|
+
for (let e of i) {
|
|
91
|
+
if (o && s(e)) {
|
|
92
|
+
l.push({
|
|
93
|
+
replicaId: e.replicaId,
|
|
94
|
+
ageMs: e.ageMs,
|
|
95
|
+
version: e.version
|
|
96
|
+
});
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
o && c.push(e), d.add(e.replicaId), Number.isFinite(e.ageMs) && e.ageMs > n && u.push({
|
|
100
|
+
replicaId: e.replicaId,
|
|
101
|
+
ageMs: e.ageMs
|
|
102
|
+
});
|
|
103
|
+
let t = e.version ?? "unknown";
|
|
104
|
+
p[t] = (p[t] ?? 0) + 1;
|
|
105
|
+
}
|
|
106
|
+
let m = [];
|
|
107
|
+
for (let e of a) d.has(e) || m.push(e);
|
|
108
|
+
m.sort();
|
|
109
|
+
let h = Object.keys(p).length > 1 ? p : void 0;
|
|
110
|
+
return {
|
|
111
|
+
byReplica: c,
|
|
112
|
+
missing: m,
|
|
113
|
+
responded: c.length,
|
|
114
|
+
expected: Math.max(a.size, c.length),
|
|
115
|
+
stale: u,
|
|
116
|
+
departed: l,
|
|
117
|
+
...h === void 0 ? { versions: void 0 } : { versions: h }
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
//#endregion
|
|
121
|
+
export { f as DEFAULT_STALE_AFTER_MS, l as ObservationsUnavailable, r as REPLICA_OBSERVATIONS_TABLE, d as forgetReplicaObservations, p as mergeFleetObservations, c as readReplicaObservations, o as resetReplicaObservationWarnings, s as writeReplicaObservation };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//#region src/replicaSelection.ts
|
|
2
|
+
var e = (e = {}) => {
|
|
3
|
+
let t = e.random ?? Math.random, n = /* @__PURE__ */ new Map(), r = (e) => n.get(e) ?? 0;
|
|
4
|
+
return {
|
|
5
|
+
pick(e) {
|
|
6
|
+
if (e.length === 0) return null;
|
|
7
|
+
if (e.length === 1) return e[0];
|
|
8
|
+
let n = Math.floor(t() * e.length), i = Math.floor(t() * e.length);
|
|
9
|
+
i === n && (i = (i + 1) % e.length);
|
|
10
|
+
let a = e[n], o = e[i];
|
|
11
|
+
return r(a) <= r(o) ? a : o;
|
|
12
|
+
},
|
|
13
|
+
beforeQuery(e) {
|
|
14
|
+
n.set(e, r(e) + 1);
|
|
15
|
+
},
|
|
16
|
+
afterQuery(e) {
|
|
17
|
+
let t = r(e) - 1;
|
|
18
|
+
t <= 0 ? n.delete(e) : n.set(e, t);
|
|
19
|
+
},
|
|
20
|
+
loadSnapshot() {
|
|
21
|
+
let e = Array(n.size), t = 0;
|
|
22
|
+
return n.forEach((n, r) => {
|
|
23
|
+
e[t++] = {
|
|
24
|
+
replica: r,
|
|
25
|
+
inFlight: n
|
|
26
|
+
};
|
|
27
|
+
}), e;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
//#endregion
|
|
32
|
+
export { e as powerOfTwoSelector };
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { powerOfTwoSelector as e } from "./replicaSelection.js";
|
|
2
|
+
import { replicaHealth as t } from "./replicaHealth.js";
|
|
3
|
+
import { memoryRywPositionStore as n } from "./rywPositionStore.js";
|
|
4
|
+
import { Effect as r, Fiber as i } from "effect";
|
|
5
|
+
import { createLogger as a } from "@voltro/logger";
|
|
6
|
+
import { AsyncLocalStorage as o } from "node:async_hooks";
|
|
7
|
+
//#region src/replicatedDataStore.ts
|
|
8
|
+
var s = a({ scope: "voltro:replication" }), c = new o(), l = (e, t) => c.run(e, t), u = (e, t) => r.flatMap(r.context(), (n) => r.callback((a) => {
|
|
9
|
+
let o = l(e, () => r.runForkWith(n)(t));
|
|
10
|
+
return o.addObserver((e) => {
|
|
11
|
+
a(e);
|
|
12
|
+
}), r.asVoid(i.interrupt(o));
|
|
13
|
+
})), d = () => c.getStore(), f = class {
|
|
14
|
+
integrityQuery;
|
|
15
|
+
primary;
|
|
16
|
+
replicas;
|
|
17
|
+
adapter;
|
|
18
|
+
policy;
|
|
19
|
+
rywTtlMs;
|
|
20
|
+
rywMaxWaitMs;
|
|
21
|
+
rywStore;
|
|
22
|
+
selector;
|
|
23
|
+
health;
|
|
24
|
+
recordRouting;
|
|
25
|
+
now;
|
|
26
|
+
closing;
|
|
27
|
+
constructor(r) {
|
|
28
|
+
this.primary = r.primary, r.primary.integrityQuery !== void 0 && (this.integrityQuery = r.primary.integrityQuery.bind(r.primary)), this.replicas = r.replicas, this.adapter = r.replicationAdapter, this.policy = r.rywPolicy ?? "fallback", this.rywTtlMs = r.rywTtlMs ?? 3e4, this.rywMaxWaitMs = r.rywMaxWaitMs ?? 500, this.now = r.now ?? Date.now, this.rywStore = r.rywStore ?? n({ now: this.now }), this.selector = r.replicaSelector ?? e(), this.health = r.replicaHealth ?? t({ now: this.now }), r.recordRouting !== void 0 && (this.recordRouting = r.recordRouting);
|
|
29
|
+
}
|
|
30
|
+
async query(e) {
|
|
31
|
+
let t = c.getStore(), n = t?.subjectKey ?? "anon:bg";
|
|
32
|
+
if (t?.forcePrimary === !0) return this.emitRouting({
|
|
33
|
+
target: "primary",
|
|
34
|
+
replicaIndex: null,
|
|
35
|
+
policy: this.policy,
|
|
36
|
+
subjectKey: n,
|
|
37
|
+
hadRywPosition: !1,
|
|
38
|
+
waitMs: 0,
|
|
39
|
+
fallbackReason: "transactional-scope"
|
|
40
|
+
}), this.primary.query(e);
|
|
41
|
+
if (this.replicas.length === 0) return this.emitRouting({
|
|
42
|
+
target: "primary",
|
|
43
|
+
replicaIndex: null,
|
|
44
|
+
policy: this.policy,
|
|
45
|
+
subjectKey: n,
|
|
46
|
+
hadRywPosition: !1,
|
|
47
|
+
waitMs: 0,
|
|
48
|
+
fallbackReason: "no-replicas"
|
|
49
|
+
}), this.primary.query(e);
|
|
50
|
+
let r = this.rywStore.get(n), i = r !== void 0;
|
|
51
|
+
return this.policy === "off" ? this.routeToReplica(e, n, i) : this.policy === "fallback" && i ? (this.emitRouting({
|
|
52
|
+
target: "primary",
|
|
53
|
+
replicaIndex: null,
|
|
54
|
+
policy: this.policy,
|
|
55
|
+
subjectKey: n,
|
|
56
|
+
hadRywPosition: !0,
|
|
57
|
+
waitMs: 0,
|
|
58
|
+
fallbackReason: "ryw-pinned-to-primary"
|
|
59
|
+
}), this.primary.query(e)) : this.policy === "wait" && i ? this.routeWaitMode(e, n, r.position) : this.routeToReplica(e, n, i);
|
|
60
|
+
}
|
|
61
|
+
async routeToReplica(e, t, n) {
|
|
62
|
+
let r = this.replicas.filter((e) => this.health.isHealthy(e));
|
|
63
|
+
if (r.length === 0) return this.emitRouting({
|
|
64
|
+
target: "primary",
|
|
65
|
+
replicaIndex: null,
|
|
66
|
+
policy: this.policy,
|
|
67
|
+
subjectKey: t,
|
|
68
|
+
hadRywPosition: n,
|
|
69
|
+
waitMs: 0,
|
|
70
|
+
fallbackReason: "no-healthy-replicas"
|
|
71
|
+
}), this.primary.query(e);
|
|
72
|
+
let i = this.selector.pick(r);
|
|
73
|
+
if (i === null) return this.emitRouting({
|
|
74
|
+
target: "primary",
|
|
75
|
+
replicaIndex: null,
|
|
76
|
+
policy: this.policy,
|
|
77
|
+
subjectKey: t,
|
|
78
|
+
hadRywPosition: n,
|
|
79
|
+
waitMs: 0,
|
|
80
|
+
fallbackReason: "no-healthy-replicas"
|
|
81
|
+
}), this.primary.query(e);
|
|
82
|
+
let a = this.replicas.indexOf(i);
|
|
83
|
+
this.selector.beforeQuery(i);
|
|
84
|
+
try {
|
|
85
|
+
let r = await i.query(e);
|
|
86
|
+
return this.health.reportSuccess(i), this.emitRouting({
|
|
87
|
+
target: "replica",
|
|
88
|
+
replicaIndex: a,
|
|
89
|
+
policy: this.policy,
|
|
90
|
+
subjectKey: t,
|
|
91
|
+
hadRywPosition: n,
|
|
92
|
+
waitMs: 0
|
|
93
|
+
}), r;
|
|
94
|
+
} catch (r) {
|
|
95
|
+
return this.health.reportFailure(i, String(r)), s.warn("replica query failed; falling back to primary", {
|
|
96
|
+
idx: a,
|
|
97
|
+
err: r
|
|
98
|
+
}), this.emitRouting({
|
|
99
|
+
target: "primary",
|
|
100
|
+
replicaIndex: a,
|
|
101
|
+
policy: this.policy,
|
|
102
|
+
subjectKey: t,
|
|
103
|
+
hadRywPosition: n,
|
|
104
|
+
waitMs: 0,
|
|
105
|
+
fallbackReason: "replica-query-failed"
|
|
106
|
+
}), this.primary.query(e);
|
|
107
|
+
} finally {
|
|
108
|
+
this.selector.afterQuery(i);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async routeWaitMode(e, t, n) {
|
|
112
|
+
let r = this.replicas.filter((e) => this.health.isHealthy(e));
|
|
113
|
+
if (r.length === 0) return this.emitRouting({
|
|
114
|
+
target: "primary",
|
|
115
|
+
replicaIndex: null,
|
|
116
|
+
policy: "wait",
|
|
117
|
+
subjectKey: t,
|
|
118
|
+
hadRywPosition: !0,
|
|
119
|
+
waitMs: 0,
|
|
120
|
+
fallbackReason: "no-healthy-replicas"
|
|
121
|
+
}), this.primary.query(e);
|
|
122
|
+
let i = this.selector.pick(r), a = this.replicas.indexOf(i), o = this.now(), s = o + this.rywMaxWaitMs;
|
|
123
|
+
for (;;) {
|
|
124
|
+
let r = await this.adapter.probeReplicaPosition(i);
|
|
125
|
+
if (this.adapter.compare(n, r) === "caught-up") {
|
|
126
|
+
let n = this.now() - o;
|
|
127
|
+
this.selector.beforeQuery(i);
|
|
128
|
+
try {
|
|
129
|
+
let r = await i.query(e);
|
|
130
|
+
return this.health.reportSuccess(i), this.emitRouting({
|
|
131
|
+
target: "replica",
|
|
132
|
+
replicaIndex: a,
|
|
133
|
+
policy: "wait",
|
|
134
|
+
subjectKey: t,
|
|
135
|
+
hadRywPosition: !0,
|
|
136
|
+
waitMs: n
|
|
137
|
+
}), r;
|
|
138
|
+
} catch (r) {
|
|
139
|
+
return this.health.reportFailure(i, String(r)), this.emitRouting({
|
|
140
|
+
target: "primary",
|
|
141
|
+
replicaIndex: a,
|
|
142
|
+
policy: "wait",
|
|
143
|
+
subjectKey: t,
|
|
144
|
+
hadRywPosition: !0,
|
|
145
|
+
waitMs: n,
|
|
146
|
+
fallbackReason: "replica-query-failed"
|
|
147
|
+
}), this.primary.query(e);
|
|
148
|
+
} finally {
|
|
149
|
+
this.selector.afterQuery(i);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (this.now() >= s) {
|
|
153
|
+
let n = this.now() - o;
|
|
154
|
+
return this.emitRouting({
|
|
155
|
+
target: "primary",
|
|
156
|
+
replicaIndex: a,
|
|
157
|
+
policy: "wait",
|
|
158
|
+
subjectKey: t,
|
|
159
|
+
hadRywPosition: !0,
|
|
160
|
+
waitMs: n,
|
|
161
|
+
fallbackReason: "wait-timeout"
|
|
162
|
+
}), this.primary.query(e);
|
|
163
|
+
}
|
|
164
|
+
await p(10);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
async insert(e, t) {
|
|
168
|
+
let n = await this.primary.insert(e, t);
|
|
169
|
+
return await this.stampPostWrite(), n;
|
|
170
|
+
}
|
|
171
|
+
async insertMany(e, t, n) {
|
|
172
|
+
let r = await this.primary.insertMany(e, t, n);
|
|
173
|
+
return await this.stampPostWrite(), r;
|
|
174
|
+
}
|
|
175
|
+
async patchJson(e, t, n, r, i) {
|
|
176
|
+
let a = await this.primary.patchJson(e, t, n, r, i);
|
|
177
|
+
return await this.stampPostWrite(), a;
|
|
178
|
+
}
|
|
179
|
+
async update(e, t, n) {
|
|
180
|
+
let r = await this.primary.update(e, t, n);
|
|
181
|
+
return await this.stampPostWrite(), r;
|
|
182
|
+
}
|
|
183
|
+
async delete(e, t) {
|
|
184
|
+
let n = await this.primary.delete(e, t);
|
|
185
|
+
return await this.stampPostWrite(), n;
|
|
186
|
+
}
|
|
187
|
+
async updateMany(e, t, n) {
|
|
188
|
+
let r = await this.primary.updateMany(e, t, n);
|
|
189
|
+
return await this.stampPostWrite(), r;
|
|
190
|
+
}
|
|
191
|
+
async deleteMany(e, t) {
|
|
192
|
+
let n = await this.primary.deleteMany(e, t);
|
|
193
|
+
return await this.stampPostWrite(), n;
|
|
194
|
+
}
|
|
195
|
+
async upsert(e, t, n) {
|
|
196
|
+
let r = await this.primary.upsert(e, t, n);
|
|
197
|
+
return await this.stampPostWrite(), r;
|
|
198
|
+
}
|
|
199
|
+
async insertIgnore(e, t, n) {
|
|
200
|
+
let r = await this.primary.insertIgnore(e, t, n);
|
|
201
|
+
return await this.stampPostWrite(), r;
|
|
202
|
+
}
|
|
203
|
+
async insertIgnoreWithOutcome(e, t, n) {
|
|
204
|
+
let r = await this.primary.insertIgnoreWithOutcome(e, t, n);
|
|
205
|
+
return await this.stampPostWrite(), r;
|
|
206
|
+
}
|
|
207
|
+
async transactional(e) {
|
|
208
|
+
let t = await l({
|
|
209
|
+
subjectKey: c.getStore()?.subjectKey ?? "anon:bg",
|
|
210
|
+
forcePrimary: !0
|
|
211
|
+
}, () => this.primary.transactional(e));
|
|
212
|
+
return await this.stampPostWrite(), t;
|
|
213
|
+
}
|
|
214
|
+
onChange(e) {
|
|
215
|
+
return this.primary.onChange(e);
|
|
216
|
+
}
|
|
217
|
+
injectExternalChange(e) {
|
|
218
|
+
this.primary.injectExternalChange(e);
|
|
219
|
+
}
|
|
220
|
+
get changeScope() {
|
|
221
|
+
return this.primary.changeScope ?? "local";
|
|
222
|
+
}
|
|
223
|
+
close(e) {
|
|
224
|
+
return this.closing ??= (async () => {
|
|
225
|
+
let t = [];
|
|
226
|
+
try {
|
|
227
|
+
await this.rywStore.close?.();
|
|
228
|
+
} catch (e) {
|
|
229
|
+
t.push(e);
|
|
230
|
+
}
|
|
231
|
+
for (let n of /* @__PURE__ */ new Set([this.primary, ...this.replicas])) try {
|
|
232
|
+
await n.close?.(e);
|
|
233
|
+
} catch (e) {
|
|
234
|
+
t.push(e);
|
|
235
|
+
}
|
|
236
|
+
if (t.length > 0) throw AggregateError(t, "Read replica shutdown failed");
|
|
237
|
+
})();
|
|
238
|
+
}
|
|
239
|
+
async stampPostWrite() {
|
|
240
|
+
if (this.replicas.length === 0) return;
|
|
241
|
+
let e = c.getStore()?.subjectKey ?? "anon:bg";
|
|
242
|
+
try {
|
|
243
|
+
let t = await this.adapter.capturePrimaryPosition(this.primary);
|
|
244
|
+
this.rywStore.set(e, {
|
|
245
|
+
position: t,
|
|
246
|
+
expiresAt: this.now() + this.rywTtlMs
|
|
247
|
+
});
|
|
248
|
+
} catch (e) {
|
|
249
|
+
s.warn("failed to capture primary position; RYW skipped", { err: e });
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
emitRouting(e) {
|
|
253
|
+
this.recordRouting?.(e);
|
|
254
|
+
}
|
|
255
|
+
}, p = (e) => new Promise((t) => setTimeout(t, e));
|
|
256
|
+
//#endregion
|
|
257
|
+
export { f as ReplicatedDataStore, d as currentRoutingContext, l as runWithRoutingContext, u as runWithRoutingContextEffect };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AsyncLocalStorage as e } from "node:async_hooks";
|
|
2
|
+
//#region src/requestLoader.ts
|
|
3
|
+
var t = new e(), n = (e) => {
|
|
4
|
+
t.enterWith(e);
|
|
5
|
+
}, r = () => t.getStore(), i = (e, n) => t.run(e, n);
|
|
6
|
+
//#endregion
|
|
7
|
+
export { r as currentRequestLoader, n as enterRequestLoader, i as runWithRequestLoader };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createLogger as e } from "@voltro/logger";
|
|
2
|
+
//#region src/resumeCensus.ts
|
|
3
|
+
var t = Symbol.for("@voltro/runtime/resumeCensus"), n = globalThis, r = n[t] ?? (n[t] = { byLabel: /* @__PURE__ */ new Map() }), i = e({ scope: "voltro:resume" }), a = (e, t) => {
|
|
4
|
+
let n = e.startsWith("subscription.") ? e.slice(13) : e, a = r.byLabel.get(n) ?? {
|
|
5
|
+
resumable: 0,
|
|
6
|
+
excluded: /* @__PURE__ */ new Map(),
|
|
7
|
+
logged: /* @__PURE__ */ new Set()
|
|
8
|
+
};
|
|
9
|
+
t === !0 ? a.resumable += 1 : a.excluded.set(t, (a.excluded.get(t) ?? 0) + 1), r.byLabel.set(n, a);
|
|
10
|
+
let o = t === !0 ? "resumable" : t;
|
|
11
|
+
a.logged.has(o) || (a.logged.add(o), i.debug("subscription resume decided", {
|
|
12
|
+
query: n,
|
|
13
|
+
resumable: t === !0,
|
|
14
|
+
...t === !0 ? {} : { reason: t }
|
|
15
|
+
}));
|
|
16
|
+
}, o = () => {
|
|
17
|
+
let e = [];
|
|
18
|
+
for (let [t, n] of r.byLabel) e.push({
|
|
19
|
+
label: t,
|
|
20
|
+
resumable: n.resumable,
|
|
21
|
+
excluded: Object.fromEntries(n.excluded)
|
|
22
|
+
});
|
|
23
|
+
return e;
|
|
24
|
+
}, s = () => {
|
|
25
|
+
r.byLabel.clear();
|
|
26
|
+
};
|
|
27
|
+
//#endregion
|
|
28
|
+
export { a as noteResumeVerdict, s as resetResumeCensus, o as resumeCensus };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/revalidation.ts
|
|
2
|
+
var e = Symbol.for("@voltro/runtime/revalidation:publisher"), t = () => {
|
|
3
|
+
let t = globalThis;
|
|
4
|
+
return t[e] ??= { publisher: null };
|
|
5
|
+
}, n = (e) => {
|
|
6
|
+
t().publisher = e;
|
|
7
|
+
}, r = (e) => {
|
|
8
|
+
let n = t().publisher;
|
|
9
|
+
return n === null ? Promise.reject(/* @__PURE__ */ Error("revalidatePath/revalidateTable/revalidateTag: no revalidation publisher is wired in this process. These functions work inside a running Voltro api process (`voltro dev` / `voltro serve`) — the boot path registers the transport. If you see this inside one, the boot wiring is broken; report it.")) : n(e);
|
|
10
|
+
}, i = (e, t = {}) => r({
|
|
11
|
+
kind: "path",
|
|
12
|
+
value: e,
|
|
13
|
+
...t.tenant === void 0 ? {} : { tenant: t.tenant }
|
|
14
|
+
}), a = (e) => r({
|
|
15
|
+
kind: "table",
|
|
16
|
+
value: e
|
|
17
|
+
}), o = (e) => r({
|
|
18
|
+
kind: "tag",
|
|
19
|
+
value: e
|
|
20
|
+
});
|
|
21
|
+
//#endregion
|
|
22
|
+
export { i as revalidatePath, a as revalidateTable, o as revalidateTag, n as setRevalidationPublisher };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { restrictingReadsEffect as e } from "./readRecorder.js";
|
|
2
|
+
import { mapSetReadScopes as t } from "./setReadScopes.js";
|
|
3
|
+
import { Effect as n, Schedule as r, Schema as i } from "effect";
|
|
4
|
+
import { and as a } from "@voltro/database";
|
|
5
|
+
import { currentSubjectAuthority as o, isMachineSubject as s } from "@voltro/protocol";
|
|
6
|
+
import { createLogger as c } from "@voltro/logger";
|
|
7
|
+
//#region src/rowFilter.ts
|
|
8
|
+
var l = class extends i.TaggedError()("RowFilterUnavailable", { cause: i.String }) {}, u = class extends i.TaggedError()("RowFilterDeclarationViolated", {
|
|
9
|
+
table: i.String,
|
|
10
|
+
declared: i.Array(i.String)
|
|
11
|
+
}) {
|
|
12
|
+
get message() {
|
|
13
|
+
return `row filter narrowed '${this.table}', which its declaration does not name (declared: ${this.declared.join(", ") || "none"})`;
|
|
14
|
+
}
|
|
15
|
+
}, d = r.max([r.exponential("20 millis"), r.recurs(2)]), f = Symbol.for("@voltro/runtime/rowFilter"), p = globalThis, m = p[f] ?? (p[f] = {}), h = (e) => {
|
|
16
|
+
m.filter = e;
|
|
17
|
+
}, g = () => m.filter, _ = () => m.filter !== void 0, v = () => void 0, y = c({ scope: "voltro:row-filter" }), b = /* @__PURE__ */ new Set(), x = (e, t) => {
|
|
18
|
+
b.has(e) || (b.add(e), y.info("row filter: RESOLVED on a live read path", {
|
|
19
|
+
arm: e,
|
|
20
|
+
...t === void 0 ? {} : { constrains: t },
|
|
21
|
+
armsSeen: [...b].sort().join(",")
|
|
22
|
+
}));
|
|
23
|
+
}, S = () => [...b].sort(), C = () => {
|
|
24
|
+
b.clear();
|
|
25
|
+
}, w = (e, t) => n.tap(T(g(), e, t), () => n.sync(() => {
|
|
26
|
+
let e = g();
|
|
27
|
+
e !== void 0 && x("request", e.tables?.length);
|
|
28
|
+
})), T = (t, r, i) => {
|
|
29
|
+
if (t === void 0 || s(r)) return n.succeed(v);
|
|
30
|
+
let a = t.retry ?? d, o = e(t.load(r)), c = a === !1 ? o : n.retry(o, a), f = t.tables, p = f === void 0 ? void 0 : new Set(f);
|
|
31
|
+
return c.pipe(n.map((e) => p === void 0 ? (n) => t.predicate(e, n) : (n) => {
|
|
32
|
+
let r = t.predicate(e, n);
|
|
33
|
+
if (r !== void 0 && !p.has(n)) throw new u({
|
|
34
|
+
table: n,
|
|
35
|
+
declared: f ?? []
|
|
36
|
+
});
|
|
37
|
+
return r;
|
|
38
|
+
}), n.catch((e) => n.suspend(() => (i?.(e), t.onLoadError === "deny" ? n.succeed(E) : n.fail(new l({ cause: String(e) }))))));
|
|
39
|
+
}, E = () => ({
|
|
40
|
+
column: "id",
|
|
41
|
+
op: "isNull"
|
|
42
|
+
}), D = (e) => {
|
|
43
|
+
let t = g();
|
|
44
|
+
if (t === void 0) return !1;
|
|
45
|
+
let n = t.tables;
|
|
46
|
+
if (n === void 0) return !0;
|
|
47
|
+
let r = new Set(n);
|
|
48
|
+
return e.some((e) => r.has(e));
|
|
49
|
+
}, O = (e, t, n) => {
|
|
50
|
+
let r = e(t);
|
|
51
|
+
return r === void 0 ? n : n ? a(n, r) : r;
|
|
52
|
+
}, k = (e, n) => {
|
|
53
|
+
let r = n;
|
|
54
|
+
if (r.setOp !== void 0) {
|
|
55
|
+
let i = {
|
|
56
|
+
...r,
|
|
57
|
+
table: n.table,
|
|
58
|
+
predicate: n.predicate,
|
|
59
|
+
order: r.order ?? [],
|
|
60
|
+
projection: r.projection,
|
|
61
|
+
take: r.take,
|
|
62
|
+
skip: r.skip
|
|
63
|
+
}, a = t(i, (t) => k(e, t));
|
|
64
|
+
return {
|
|
65
|
+
...n,
|
|
66
|
+
setOp: a.setOp
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
let i = O(e, n.table, n.predicate);
|
|
70
|
+
return i === n.predicate ? n : {
|
|
71
|
+
...n,
|
|
72
|
+
predicate: i
|
|
73
|
+
};
|
|
74
|
+
}, A = (e, t) => {
|
|
75
|
+
if (g() !== void 0) return async () => {
|
|
76
|
+
let r = await n.runPromise(n.result(w(o(e), t)));
|
|
77
|
+
if (r._tag === "Failure") throw r.failure;
|
|
78
|
+
return r.success;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
//#endregion
|
|
82
|
+
export { d as DEFAULT_ROW_FILTER_RETRY, v as NO_ROW_FILTER, u as RowFilterDeclarationViolated, l as RowFilterUnavailable, O as applyRowFilter, k as applyRowFilterToDescriptor, g as getRowFilter, A as makeDefaultRefilter, x as noteRowFilterResolved, C as resetRowFilterResolvedArms, w as resolveRowFilterScope, T as resolveRowFilterScopeFor, D as rowFilterMayNarrow, _ as rowFilterRegistered, S as rowFilterResolvedArms, h as setRowFilter };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//#region src/rowStateBytes.ts
|
|
2
|
+
var e = (t, n) => {
|
|
3
|
+
if (typeof t != "object" || !t) return typeof t != "bigint";
|
|
4
|
+
if (n.has(t)) return !1;
|
|
5
|
+
let r = Object.getPrototypeOf(t);
|
|
6
|
+
if (r !== Object.prototype && r !== null && r !== Array.prototype || "toJSON" in t) return !1;
|
|
7
|
+
n.add(t);
|
|
8
|
+
try {
|
|
9
|
+
for (let r of Object.values(Object.getOwnPropertyDescriptors(t))) if (r.enumerable && (!("value" in r) || !e(r.value, n))) return !1;
|
|
10
|
+
return !0;
|
|
11
|
+
} finally {
|
|
12
|
+
n.delete(t);
|
|
13
|
+
}
|
|
14
|
+
}, t = () => {
|
|
15
|
+
let t = /* @__PURE__ */ new WeakMap();
|
|
16
|
+
return {
|
|
17
|
+
reset: () => {
|
|
18
|
+
t = /* @__PURE__ */ new WeakMap();
|
|
19
|
+
},
|
|
20
|
+
estimate: (n, r, i = !1) => {
|
|
21
|
+
if (!Array.isArray(n) || Object.getPrototypeOf(n) !== Array.prototype || "toJSON" in n) return r(n);
|
|
22
|
+
let a = 2 + Math.max(0, n.length - 1);
|
|
23
|
+
for (let o = 0; o < n.length; o++) {
|
|
24
|
+
let s = i ? void 0 : Object.getOwnPropertyDescriptor(n, String(o));
|
|
25
|
+
if (!i && (s === void 0 || !("value" in s))) return r(n);
|
|
26
|
+
let c = i ? n[o] : s.value;
|
|
27
|
+
if (typeof c != "object" || !c) return r(n);
|
|
28
|
+
let l = t.get(c);
|
|
29
|
+
if (l === void 0) {
|
|
30
|
+
try {
|
|
31
|
+
l = e(c, /* @__PURE__ */ new Set()) ? JSON.stringify(c).length : null;
|
|
32
|
+
} catch {
|
|
33
|
+
l = null;
|
|
34
|
+
}
|
|
35
|
+
t.set(c, l);
|
|
36
|
+
}
|
|
37
|
+
if (l === null) return r(n);
|
|
38
|
+
a += l;
|
|
39
|
+
}
|
|
40
|
+
return a;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
//#endregion
|
|
45
|
+
export { t as createRowStateByteEstimator };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Effect as e, Stream as t } from "effect";
|
|
2
|
+
import { HttpServerError as n, UrlParams as r } from "effect/http";
|
|
3
|
+
//#region src/rpcBodyCap.ts
|
|
4
|
+
var i = (t, n) => e.callback((r) => {
|
|
5
|
+
let i = [], a = 0, o = !1, s = () => {
|
|
6
|
+
t.off("data", l), t.off("end", u), t.off("error", d), t.off("aborted", d);
|
|
7
|
+
}, c = (t) => {
|
|
8
|
+
o || (o = !0, s(), r(e.succeed(t)));
|
|
9
|
+
};
|
|
10
|
+
function l(e) {
|
|
11
|
+
a += e.length, a > n ? (i.length = 0, c({
|
|
12
|
+
_tag: "too-large",
|
|
13
|
+
received: a
|
|
14
|
+
}), t.resume()) : i.push(e);
|
|
15
|
+
}
|
|
16
|
+
function u() {
|
|
17
|
+
c({
|
|
18
|
+
_tag: "ok",
|
|
19
|
+
bytes: i.length === 1 ? i[0] : Buffer.concat(i)
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function d() {
|
|
23
|
+
c({ _tag: "aborted" });
|
|
24
|
+
}
|
|
25
|
+
return t.on("data", l), t.once("end", u), t.once("error", d), t.once("aborted", d), e.sync(() => {
|
|
26
|
+
o = !0, s();
|
|
27
|
+
});
|
|
28
|
+
}), a = (i, a) => {
|
|
29
|
+
let o = Object.create(i), s = Buffer.from(a.buffer, a.byteOffset, a.byteLength).toString("utf8"), c = (e) => new n.HttpServerError({ reason: new n.RequestParseError({
|
|
30
|
+
request: o,
|
|
31
|
+
cause: e
|
|
32
|
+
}) }), l = a.buffer.slice(a.byteOffset, a.byteOffset + a.byteLength);
|
|
33
|
+
return Object.defineProperties(o, {
|
|
34
|
+
text: {
|
|
35
|
+
get: () => e.succeed(s),
|
|
36
|
+
configurable: !0
|
|
37
|
+
},
|
|
38
|
+
json: {
|
|
39
|
+
get: () => e.try({
|
|
40
|
+
try: () => s === "" ? null : JSON.parse(s),
|
|
41
|
+
catch: c
|
|
42
|
+
}),
|
|
43
|
+
configurable: !0
|
|
44
|
+
},
|
|
45
|
+
urlParamsBody: {
|
|
46
|
+
get: () => e.try({
|
|
47
|
+
try: () => r.fromInput(new URLSearchParams(s)),
|
|
48
|
+
catch: c
|
|
49
|
+
}),
|
|
50
|
+
configurable: !0
|
|
51
|
+
},
|
|
52
|
+
arrayBuffer: {
|
|
53
|
+
get: () => e.succeed(l),
|
|
54
|
+
configurable: !0
|
|
55
|
+
},
|
|
56
|
+
stream: {
|
|
57
|
+
get: () => t.succeed(a),
|
|
58
|
+
configurable: !0
|
|
59
|
+
}
|
|
60
|
+
}), o;
|
|
61
|
+
};
|
|
62
|
+
//#endregion
|
|
63
|
+
export { i as readCappedBody, a as withBufferedBody };
|