@voltro/runtime 0.85.0 → 0.86.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.
Files changed (160) hide show
  1. package/CHANGELOG.md +666 -0
  2. package/THIRD-PARTY-NOTICES.md +5 -33
  3. package/dist/aggregate.js +42 -0
  4. package/dist/aggregateExtrema.js +80 -0
  5. package/dist/aggregateIvm.js +115 -0
  6. package/dist/analyticsMirror.js +228 -0
  7. package/dist/analyticsSink.js +38 -0
  8. package/dist/apiKeyUsage.js +33 -0
  9. package/dist/apiKeys.js +223 -0
  10. package/dist/apiKeysWiring.js +114 -0
  11. package/dist/approvalBuiltins.js +10 -0
  12. package/dist/approvals.js +269 -0
  13. package/dist/authMiddlewareLayer.js +47 -0
  14. package/dist/bindEvent.js +72 -0
  15. package/dist/bootListener.js +76 -0
  16. package/dist/bootRefusal.js +7 -0
  17. package/dist/bootStoreCodec.js +70 -0
  18. package/dist/businessRules.js +67 -0
  19. package/dist/changeClaimsTable.js +12 -0
  20. package/dist/circuitBreaker.js +72 -0
  21. package/dist/columnOnUpdate.js +23 -0
  22. package/dist/composeAnalytics.js +108 -0
  23. package/dist/computedQuery.js +4 -0
  24. package/dist/connectionBuiltins.js +81 -0
  25. package/dist/connectionCredentials.js +66 -0
  26. package/dist/connectionState.js +34 -0
  27. package/dist/connectionVault.js +410 -0
  28. package/dist/connectionsFacade.js +54 -0
  29. package/dist/coordinatedSchedule.js +139 -0
  30. package/dist/crdtHistory.js +138 -0
  31. package/dist/crdtMerge.js +179 -0
  32. package/dist/crdtVersionsTable.js +25 -0
  33. package/dist/credentialBound.js +12 -0
  34. package/dist/crud.js +72 -0
  35. package/dist/dataStore.js +679 -0
  36. package/dist/dataloader.js +61 -0
  37. package/dist/declaredTablesGuard.js +48 -0
  38. package/dist/defineExecutor.js +4 -0
  39. package/dist/dependencyGraph.js +32 -0
  40. package/dist/devices.js +228 -0
  41. package/dist/devicesWiring.js +168 -0
  42. package/dist/dialectReplicationAdapter.js +29 -0
  43. package/dist/dispatcher.js +447 -0
  44. package/dist/effectStore.js +71 -0
  45. package/dist/eventBus.js +260 -0
  46. package/dist/eventPublish.js +49 -0
  47. package/dist/events.js +193 -0
  48. package/dist/expectation.js +52 -0
  49. package/dist/expectationEvaluator.js +308 -0
  50. package/dist/experiment.js +96 -0
  51. package/dist/experimentEvaluator.js +245 -0
  52. package/dist/externalizedTasks.js +25 -0
  53. package/dist/fieldCipher.js +61 -0
  54. package/dist/fingerprint.js +21 -0
  55. package/dist/finops.js +42 -0
  56. package/dist/finopsAccountant.js +216 -0
  57. package/dist/handlerBody.js +8 -0
  58. package/dist/healthProbes.js +55 -0
  59. package/dist/httpClientSsrf.js +49 -0
  60. package/dist/httpClientTracing.js +11 -0
  61. package/dist/httpCompression.js +76 -0
  62. package/dist/httpKeepAlive.js +12 -0
  63. package/dist/httpRouteMounts.js +47 -0
  64. package/dist/idempotencyStore.js +70 -0
  65. package/dist/idleDetector.js +21 -0
  66. package/dist/index.d.ts +88 -69
  67. package/dist/index.js +144 -15292
  68. package/dist/insertRequiredColumns.js +19 -0
  69. package/dist/inspectWorkflow.js +1 -0
  70. package/dist/instanceMembership.js +98 -0
  71. package/dist/ivm.js +125 -0
  72. package/dist/kvDataStore.js +86 -0
  73. package/dist/kvFacade.js +32 -0
  74. package/dist/matcher.js +304 -0
  75. package/dist/memoryColumnDefaults.js +11 -0
  76. package/dist/memoryQueryJoins.js +114 -0
  77. package/dist/metrics.js +161 -0
  78. package/dist/observability.js +123 -0
  79. package/dist/observedGraph.js +52 -0
  80. package/dist/originGuard.js +116 -0
  81. package/dist/outbox.js +352 -0
  82. package/dist/pluginRefRules.js +65 -0
  83. package/dist/policyGuardResolver.js +55 -0
  84. package/dist/preview.js +62 -0
  85. package/dist/projectedRows.js +12 -0
  86. package/dist/provenance.js +63 -0
  87. package/dist/rangeIndex.js +89 -0
  88. package/dist/rawReadScope.js +17 -0
  89. package/dist/reaction.js +85 -0
  90. package/dist/reactiveConfig.js +11 -0
  91. package/dist/readClassification.js +57 -0
  92. package/dist/readRecorder.js +66 -0
  93. package/dist/rebac.js +104 -0
  94. package/dist/rebacInterceptor.js +81 -0
  95. package/dist/registry.js +29 -0
  96. package/dist/relevantFields.js +65 -0
  97. package/dist/replicaHealth.js +42 -0
  98. package/dist/replicaLocality.js +44 -0
  99. package/dist/replicaObservations.js +121 -0
  100. package/dist/replicaSelection.js +32 -0
  101. package/dist/replicatedDataStore.js +239 -0
  102. package/dist/requestLoader.js +7 -0
  103. package/dist/resumeCensus.js +28 -0
  104. package/dist/revalidation.js +22 -0
  105. package/dist/rowFilter.js +65 -0
  106. package/dist/rowStateBytes.js +45 -0
  107. package/dist/rpcBodyCap.js +63 -0
  108. package/dist/rpcConnections.js +83 -0
  109. package/dist/rpcDefectDiagnostics.js +15 -0
  110. package/dist/rpcServer.js +992 -0
  111. package/dist/runAsSystem.js +23 -0
  112. package/dist/rywPositionStore.js +84 -0
  113. package/dist/schedule.js +23 -0
  114. package/dist/scheduleBackfillRequests.js +151 -0
  115. package/dist/scheduleClaimsTable.js +11 -0
  116. package/dist/scheduleRunsTable.js +37 -0
  117. package/dist/scheduler.js +835 -0
  118. package/dist/schemaRegistry.js +65 -0
  119. package/dist/secretsResolver.js +35 -0
  120. package/dist/securityHeaders.js +33 -0
  121. package/dist/servePipeline.js +305 -0
  122. package/dist/serverOnlyAudit.js +66 -0
  123. package/dist/serverTracer.js +15 -0
  124. package/dist/serviceCredentials.js +40 -0
  125. package/dist/singleNodeOrchestrator.js +91 -0
  126. package/dist/sourceResolution.js +42 -0
  127. package/dist/storeMiddleware.js +880 -0
  128. package/dist/storeQuery.js +204 -0
  129. package/dist/storeRead.js +10 -0
  130. package/dist/subscriber.js +7 -0
  131. package/dist/subscriptionOutbox.js +139 -0
  132. package/dist/subscriptionRegistry.js +82 -0
  133. package/dist/subscriptionResume.js +132 -0
  134. package/dist/subscriptionSocketMetrics.js +65 -0
  135. package/dist/systemSubject.js +5 -0
  136. package/dist/tenantScope.js +23 -0
  137. package/dist/tenantSelection.js +27 -0
  138. package/dist/timeline.js +105 -0
  139. package/dist/traceContext.js +5 -0
  140. package/dist/traceSink.js +63 -0
  141. package/dist/traceSpansTable.js +29 -0
  142. package/dist/traceparent.js +34 -0
  143. package/dist/transactionSubject.js +12 -0
  144. package/dist/trustedProxy.js +155 -0
  145. package/dist/undo.js +129 -0
  146. package/dist/undoBuiltins.js +69 -0
  147. package/dist/undoCapture.js +74 -0
  148. package/dist/undoLogTable.js +16 -0
  149. package/dist/upsertBinding.js +20 -0
  150. package/dist/wakeOrchestrator.js +34 -0
  151. package/dist/wakeRegistry.js +71 -0
  152. package/dist/wakeRouter.js +63 -0
  153. package/dist/wakeSupervisor.js +62 -0
  154. package/dist/wakeupsTable.js +12 -0
  155. package/dist/webSocketGatewayRuntime.js +114 -0
  156. package/dist/webhookVerification.js +18 -0
  157. package/dist/wireColumnStrip.js +84 -0
  158. package/dist/workflowReadBuiltins.js +87 -0
  159. package/dist/workflowRuntime.js +708 -0
  160. package/package.json +7 -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,239 @@
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
+ primary;
15
+ replicas;
16
+ adapter;
17
+ policy;
18
+ rywTtlMs;
19
+ rywMaxWaitMs;
20
+ rywStore;
21
+ selector;
22
+ health;
23
+ recordRouting;
24
+ now;
25
+ constructor(r) {
26
+ this.primary = 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);
27
+ }
28
+ async query(e) {
29
+ let t = c.getStore(), n = t?.subjectKey ?? "anon:bg";
30
+ if (t?.forcePrimary === !0) return this.emitRouting({
31
+ target: "primary",
32
+ replicaIndex: null,
33
+ policy: this.policy,
34
+ subjectKey: n,
35
+ hadRywPosition: !1,
36
+ waitMs: 0,
37
+ fallbackReason: "transactional-scope"
38
+ }), this.primary.query(e);
39
+ if (this.replicas.length === 0) return this.emitRouting({
40
+ target: "primary",
41
+ replicaIndex: null,
42
+ policy: this.policy,
43
+ subjectKey: n,
44
+ hadRywPosition: !1,
45
+ waitMs: 0,
46
+ fallbackReason: "no-replicas"
47
+ }), this.primary.query(e);
48
+ let r = this.rywStore.get(n), i = r !== void 0;
49
+ return this.policy === "off" ? this.routeToReplica(e, n, i) : this.policy === "fallback" && i ? (this.emitRouting({
50
+ target: "primary",
51
+ replicaIndex: null,
52
+ policy: this.policy,
53
+ subjectKey: n,
54
+ hadRywPosition: !0,
55
+ waitMs: 0,
56
+ fallbackReason: "ryw-pinned-to-primary"
57
+ }), this.primary.query(e)) : this.policy === "wait" && i ? this.routeWaitMode(e, n, r.position) : this.routeToReplica(e, n, i);
58
+ }
59
+ async routeToReplica(e, t, n) {
60
+ let r = this.replicas.filter((e) => this.health.isHealthy(e));
61
+ if (r.length === 0) return this.emitRouting({
62
+ target: "primary",
63
+ replicaIndex: null,
64
+ policy: this.policy,
65
+ subjectKey: t,
66
+ hadRywPosition: n,
67
+ waitMs: 0,
68
+ fallbackReason: "no-healthy-replicas"
69
+ }), this.primary.query(e);
70
+ let i = this.selector.pick(r);
71
+ if (i === null) return this.emitRouting({
72
+ target: "primary",
73
+ replicaIndex: null,
74
+ policy: this.policy,
75
+ subjectKey: t,
76
+ hadRywPosition: n,
77
+ waitMs: 0,
78
+ fallbackReason: "no-healthy-replicas"
79
+ }), this.primary.query(e);
80
+ let a = this.replicas.indexOf(i);
81
+ this.selector.beforeQuery(i);
82
+ try {
83
+ let r = await i.query(e);
84
+ return this.health.reportSuccess(i), this.emitRouting({
85
+ target: "replica",
86
+ replicaIndex: a,
87
+ policy: this.policy,
88
+ subjectKey: t,
89
+ hadRywPosition: n,
90
+ waitMs: 0
91
+ }), r;
92
+ } catch (r) {
93
+ return this.health.reportFailure(i, String(r)), s.warn("replica query failed; falling back to primary", {
94
+ idx: a,
95
+ err: r
96
+ }), this.emitRouting({
97
+ target: "primary",
98
+ replicaIndex: a,
99
+ policy: this.policy,
100
+ subjectKey: t,
101
+ hadRywPosition: n,
102
+ waitMs: 0,
103
+ fallbackReason: "replica-query-failed"
104
+ }), this.primary.query(e);
105
+ } finally {
106
+ this.selector.afterQuery(i);
107
+ }
108
+ }
109
+ async routeWaitMode(e, t, n) {
110
+ let r = this.replicas.filter((e) => this.health.isHealthy(e));
111
+ if (r.length === 0) return this.emitRouting({
112
+ target: "primary",
113
+ replicaIndex: null,
114
+ policy: "wait",
115
+ subjectKey: t,
116
+ hadRywPosition: !0,
117
+ waitMs: 0,
118
+ fallbackReason: "no-healthy-replicas"
119
+ }), this.primary.query(e);
120
+ let i = this.selector.pick(r), a = this.replicas.indexOf(i), o = this.now(), s = o + this.rywMaxWaitMs;
121
+ for (;;) {
122
+ let r = await this.adapter.probeReplicaPosition(i);
123
+ if (this.adapter.compare(n, r) === "caught-up") {
124
+ let n = this.now() - o;
125
+ this.selector.beforeQuery(i);
126
+ try {
127
+ let r = await i.query(e);
128
+ return this.health.reportSuccess(i), this.emitRouting({
129
+ target: "replica",
130
+ replicaIndex: a,
131
+ policy: "wait",
132
+ subjectKey: t,
133
+ hadRywPosition: !0,
134
+ waitMs: n
135
+ }), r;
136
+ } catch (r) {
137
+ return this.health.reportFailure(i, String(r)), this.emitRouting({
138
+ target: "primary",
139
+ replicaIndex: a,
140
+ policy: "wait",
141
+ subjectKey: t,
142
+ hadRywPosition: !0,
143
+ waitMs: n,
144
+ fallbackReason: "replica-query-failed"
145
+ }), this.primary.query(e);
146
+ } finally {
147
+ this.selector.afterQuery(i);
148
+ }
149
+ }
150
+ if (this.now() >= s) {
151
+ let n = this.now() - o;
152
+ return this.emitRouting({
153
+ target: "primary",
154
+ replicaIndex: a,
155
+ policy: "wait",
156
+ subjectKey: t,
157
+ hadRywPosition: !0,
158
+ waitMs: n,
159
+ fallbackReason: "wait-timeout"
160
+ }), this.primary.query(e);
161
+ }
162
+ await p(10);
163
+ }
164
+ }
165
+ async insert(e, t) {
166
+ let n = await this.primary.insert(e, t);
167
+ return await this.stampPostWrite(), n;
168
+ }
169
+ async insertMany(e, t) {
170
+ let n = await this.primary.insertMany(e, t);
171
+ return await this.stampPostWrite(), n;
172
+ }
173
+ async patchJson(e, t, n, r, i) {
174
+ let a = await this.primary.patchJson(e, t, n, r, i);
175
+ return await this.stampPostWrite(), a;
176
+ }
177
+ async update(e, t, n) {
178
+ let r = await this.primary.update(e, t, n);
179
+ return await this.stampPostWrite(), r;
180
+ }
181
+ async delete(e, t) {
182
+ let n = await this.primary.delete(e, t);
183
+ return await this.stampPostWrite(), n;
184
+ }
185
+ async updateMany(e, t, n) {
186
+ let r = await this.primary.updateMany(e, t, n);
187
+ return await this.stampPostWrite(), r;
188
+ }
189
+ async deleteMany(e, t) {
190
+ let n = await this.primary.deleteMany(e, t);
191
+ return await this.stampPostWrite(), n;
192
+ }
193
+ async upsert(e, t, n) {
194
+ let r = await this.primary.upsert(e, t, n);
195
+ return await this.stampPostWrite(), r;
196
+ }
197
+ async insertIgnore(e, t, n) {
198
+ let r = await this.primary.insertIgnore(e, t, n);
199
+ return await this.stampPostWrite(), r;
200
+ }
201
+ async insertIgnoreWithOutcome(e, t, n) {
202
+ let r = await this.primary.insertIgnoreWithOutcome(e, t, n);
203
+ return await this.stampPostWrite(), r;
204
+ }
205
+ async transactional(e) {
206
+ let t = await l({
207
+ subjectKey: c.getStore()?.subjectKey ?? "anon:bg",
208
+ forcePrimary: !0
209
+ }, () => this.primary.transactional(e));
210
+ return await this.stampPostWrite(), t;
211
+ }
212
+ onChange(e) {
213
+ return this.primary.onChange(e);
214
+ }
215
+ injectExternalChange(e) {
216
+ this.primary.injectExternalChange(e);
217
+ }
218
+ get changeScope() {
219
+ return this.primary.changeScope ?? "local";
220
+ }
221
+ async stampPostWrite() {
222
+ if (this.replicas.length === 0) return;
223
+ let e = c.getStore()?.subjectKey ?? "anon:bg";
224
+ try {
225
+ let t = await this.adapter.capturePrimaryPosition(this.primary);
226
+ this.rywStore.set(e, {
227
+ position: t,
228
+ expiresAt: this.now() + this.rywTtlMs
229
+ });
230
+ } catch (e) {
231
+ s.warn("failed to capture primary position; RYW skipped", { err: e });
232
+ }
233
+ }
234
+ emitRouting(e) {
235
+ this.recordRouting?.(e);
236
+ }
237
+ }, p = (e) => new Promise((t) => setTimeout(t, e));
238
+ //#endregion
239
+ 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,65 @@
1
+ import { restrictingReadsEffect as e } from "./readRecorder.js";
2
+ import { Effect as t, Schedule as n, Schema as r } from "effect";
3
+ import { and as i } from "@voltro/database";
4
+ import { currentSubjectAuthority as a, isMachineSubject as o } from "@voltro/protocol";
5
+ import { createLogger as s } from "@voltro/logger";
6
+ //#region src/rowFilter.ts
7
+ var c = class extends r.TaggedError()("RowFilterUnavailable", { cause: r.String }) {}, l = class extends r.TaggedError()("RowFilterDeclarationViolated", {
8
+ table: r.String,
9
+ declared: r.Array(r.String)
10
+ }) {
11
+ get message() {
12
+ return `row filter narrowed '${this.table}', which its declaration does not name (declared: ${this.declared.join(", ") || "none"})`;
13
+ }
14
+ }, u = n.max([n.exponential("20 millis"), n.recurs(2)]), d = Symbol.for("@voltro/runtime/rowFilter"), f = globalThis, p = f[d] ?? (f[d] = {}), m = (e) => {
15
+ p.filter = e;
16
+ }, h = () => p.filter, g = () => p.filter !== void 0, _ = () => void 0, v = s({ scope: "voltro:row-filter" }), y = /* @__PURE__ */ new Set(), b = (e, t) => {
17
+ y.has(e) || (y.add(e), v.info("row filter: RESOLVED on a live read path", {
18
+ arm: e,
19
+ ...t === void 0 ? {} : { constrains: t },
20
+ armsSeen: [...y].sort().join(",")
21
+ }));
22
+ }, x = () => [...y].sort(), S = () => {
23
+ y.clear();
24
+ }, C = (e, n) => t.tap(w(h(), e, n), () => t.sync(() => {
25
+ let e = h();
26
+ e !== void 0 && b("request", e.tables?.length);
27
+ })), w = (n, r, i) => {
28
+ if (n === void 0 || o(r)) return t.succeed(_);
29
+ let a = n.retry ?? u, s = e(n.load(r)), d = a === !1 ? s : t.retry(s, a), f = n.tables, p = f === void 0 ? void 0 : new Set(f);
30
+ return d.pipe(t.map((e) => p === void 0 ? (t) => n.predicate(e, t) : (t) => {
31
+ let r = n.predicate(e, t);
32
+ if (r !== void 0 && !p.has(t)) throw new l({
33
+ table: t,
34
+ declared: f ?? []
35
+ });
36
+ return r;
37
+ }), t.catch((e) => t.suspend(() => (i?.(e), n.onLoadError === "deny" ? t.succeed(T) : t.fail(new c({ cause: String(e) }))))));
38
+ }, T = () => ({
39
+ column: "id",
40
+ op: "isNull"
41
+ }), E = (e) => {
42
+ let t = h();
43
+ if (t === void 0) return !1;
44
+ let n = t.tables;
45
+ if (n === void 0) return !0;
46
+ let r = new Set(n);
47
+ return e.some((e) => r.has(e));
48
+ }, D = (e, t, n) => {
49
+ let r = e(t);
50
+ return r === void 0 ? n : n ? i(n, r) : r;
51
+ }, O = (e, t) => {
52
+ let n = D(e, t.table, t.predicate);
53
+ return n === t.predicate ? t : {
54
+ ...t,
55
+ predicate: n
56
+ };
57
+ }, k = (e, n) => {
58
+ if (h() !== void 0) return async () => {
59
+ let r = await t.runPromise(t.result(C(a(e), n)));
60
+ if (r._tag === "Failure") throw r.failure;
61
+ return r.success;
62
+ };
63
+ };
64
+ //#endregion
65
+ export { u as DEFAULT_ROW_FILTER_RETRY, _ as NO_ROW_FILTER, l as RowFilterDeclarationViolated, c as RowFilterUnavailable, D as applyRowFilter, O as applyRowFilterToDescriptor, h as getRowFilter, k as makeDefaultRefilter, b as noteRowFilterResolved, S as resetRowFilterResolvedArms, C as resolveRowFilterScope, w as resolveRowFilterScopeFor, E as rowFilterMayNarrow, g as rowFilterRegistered, x as rowFilterResolvedArms, m 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 };