@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.
Files changed (184) hide show
  1. package/CHANGELOG.md +5484 -0
  2. package/README.md +43 -0
  3. package/THIRD-PARTY-NOTICES.md +1511 -276
  4. package/dist/aggregate.js +1 -2
  5. package/dist/aggregateExtrema.js +1 -2
  6. package/dist/aggregateIvm.js +1 -2
  7. package/dist/analyticsMirror.js +1 -2
  8. package/dist/analyticsSink.js +9 -16
  9. package/dist/apiKeyUsage.js +1 -2
  10. package/dist/apiKeys.js +83 -80
  11. package/dist/apiKeysWiring.js +1 -2
  12. package/dist/apiRoleBucketSampler.js +63 -0
  13. package/dist/apiRoleWorkloadHistory.js +55 -0
  14. package/dist/apiRoleWorkloadMetrics.js +77 -0
  15. package/dist/apiRoleWorkloadStorage.js +94 -0
  16. package/dist/approvalBuiltins.js +1 -2
  17. package/dist/approvals.js +68 -76
  18. package/dist/authMiddlewareLayer.js +8 -8
  19. package/dist/bindEvent.js +49 -30
  20. package/dist/boot-refusal.d.ts +10 -0
  21. package/dist/{bootRefusal.js → boot-refusal.js} +1 -2
  22. package/dist/bootListener.js +203 -47
  23. package/dist/bootStoreCodec.js +39 -39
  24. package/dist/businessRules.js +1 -2
  25. package/dist/changeClaimsTable.js +1 -2
  26. package/dist/circuitBreaker.js +1 -72
  27. package/dist/columnOnUpdate.js +1 -2
  28. package/dist/composeAnalytics.js +32 -12
  29. package/dist/computedQuery.js +1 -2
  30. package/dist/computedQueryCache.js +289 -0
  31. package/dist/connectionBuiltins.js +1 -2
  32. package/dist/connectionCredentials.js +1 -2
  33. package/dist/connectionState.js +1 -2
  34. package/dist/connectionVault.js +1 -2
  35. package/dist/connectionsFacade.js +33 -32
  36. package/dist/coordinatedSchedule.js +85 -80
  37. package/dist/crdtHistory.js +1 -2
  38. package/dist/crdtMerge.js +1 -2
  39. package/dist/crdtVersionsTable.js +1 -2
  40. package/dist/credentialBound.js +1 -2
  41. package/dist/crud.js +1 -2
  42. package/dist/dataStore.js +155 -123
  43. package/dist/dataloader.js +1 -2
  44. package/dist/declaredTablesGuard.js +3 -3
  45. package/dist/defineExecutor.js +1 -2
  46. package/dist/dependencyGraph.js +1 -2
  47. package/dist/devices.js +1 -2
  48. package/dist/devicesWiring.js +1 -2
  49. package/dist/dialectReplicationAdapter.js +1 -2
  50. package/dist/dispatcher.js +404 -330
  51. package/dist/effectStore.js +3 -4
  52. package/dist/engineClients.js +23 -0
  53. package/dist/eventBus.js +1 -2
  54. package/dist/eventPublish.js +1 -2
  55. package/dist/events.js +1 -2
  56. package/dist/expectation.js +1 -2
  57. package/dist/expectationEvaluator.js +2 -3
  58. package/dist/experiment.js +1 -2
  59. package/dist/experimentEvaluator.js +1 -2
  60. package/dist/externalizedTasks.js +20 -8
  61. package/dist/fieldCipher.js +110 -42
  62. package/dist/fieldKeyRegistry.js +294 -0
  63. package/dist/fieldKeyRekey.js +285 -0
  64. package/dist/fieldKeyScan.js +135 -0
  65. package/dist/fieldKeyring.js +76 -0
  66. package/dist/fingerprint.js +1 -2
  67. package/dist/finops.js +1 -2
  68. package/dist/finopsAccountant.js +1 -2
  69. package/dist/handlerBody.js +1 -2
  70. package/dist/healthProbes.js +1 -2
  71. package/dist/hot.d.ts +56 -0
  72. package/dist/hot.js +3 -0
  73. package/dist/hotDataStore.js +147 -0
  74. package/dist/hotDataStoreSnapshot.js +97 -0
  75. package/dist/hotDataStoreTables.js +17 -0
  76. package/dist/http-range.d.ts +53 -0
  77. package/dist/http-range.js +51 -0
  78. package/dist/httpClientSsrf.js +13 -39
  79. package/dist/httpClientTracing.js +13 -11
  80. package/dist/httpCompression.js +18 -19
  81. package/dist/httpInputStream.js +81 -0
  82. package/dist/httpKeepAlive.js +1 -2
  83. package/dist/httpRouteMounts.js +2 -2
  84. package/dist/idempotencyStore.js +93 -54
  85. package/dist/idleDetector.js +1 -2
  86. package/dist/index.d.ts +1185 -452
  87. package/dist/index.js +144 -134
  88. package/dist/insertRequiredColumns.js +1 -2
  89. package/dist/instanceMembership.js +1 -2
  90. package/dist/ivm.js +1 -2
  91. package/dist/kvDataStore.js +1 -2
  92. package/dist/kvFacade.js +24 -19
  93. package/dist/matcher.js +1 -2
  94. package/dist/memoryColumnDefaults.js +1 -2
  95. package/dist/memoryQueryJoins.js +17 -18
  96. package/dist/memorySetOperations.js +42 -0
  97. package/dist/metrics.js +39 -26
  98. package/dist/observability.js +2 -3
  99. package/dist/observedGraph.js +1 -2
  100. package/dist/originGuard.js +1 -2
  101. package/dist/outbox.js +2 -3
  102. package/dist/pluginRefRules.js +1 -2
  103. package/dist/policyGuardResolver.js +1 -2
  104. package/dist/preview.js +1 -2
  105. package/dist/projectedRows.js +1 -2
  106. package/dist/provenance.js +1 -2
  107. package/dist/rangeIndex.js +1 -2
  108. package/dist/rawReadScope.js +2 -3
  109. package/dist/reaction.js +1 -2
  110. package/dist/reactiveConfig.js +1 -2
  111. package/dist/readClassification.js +1 -2
  112. package/dist/readRecorder.js +36 -36
  113. package/dist/readScopePredicate.js +11 -0
  114. package/dist/rebac.js +1 -2
  115. package/dist/rebacInterceptor.js +1 -2
  116. package/dist/registry.js +1 -2
  117. package/dist/relevantFields.js +1 -2
  118. package/dist/replicaHealth.js +1 -2
  119. package/dist/replicaLocality.js +1 -2
  120. package/dist/replicaObservations.js +1 -2
  121. package/dist/replicaSelection.js +1 -2
  122. package/dist/replicatedDataStore.js +23 -6
  123. package/dist/requestLoader.js +1 -2
  124. package/dist/resumeCensus.js +1 -2
  125. package/dist/revalidation.js +1 -2
  126. package/dist/rowFilter.js +57 -41
  127. package/dist/rowStateBytes.js +1 -2
  128. package/dist/rpcBodyCap.js +1 -2
  129. package/dist/rpcConnections.js +9 -10
  130. package/dist/rpcDefectDiagnostics.js +1 -2
  131. package/dist/rpcServer.js +523 -451
  132. package/dist/rpcWorkloadAdmission.js +49 -0
  133. package/dist/runAsSystem.js +1 -2
  134. package/dist/rywPositionStore.js +83 -49
  135. package/dist/schedule.js +1 -2
  136. package/dist/scheduleBackfillRequests.js +1 -2
  137. package/dist/scheduleClaimsTable.js +1 -2
  138. package/dist/scheduleRunsTable.js +1 -2
  139. package/dist/scheduler.js +7 -3
  140. package/dist/schemaRegistry.js +1 -2
  141. package/dist/secretsResolver.js +1 -2
  142. package/dist/securityHeaders.js +1 -2
  143. package/dist/servePipeline.js +238 -154
  144. package/dist/serverOnlyAudit.js +1 -2
  145. package/dist/serverTracer.js +1 -2
  146. package/dist/serviceCredentials.js +1 -2
  147. package/dist/setReadScopes.js +27 -0
  148. package/dist/singleNodeOrchestrator.js +1 -2
  149. package/dist/snapshotValueCodec.js +45 -0
  150. package/dist/sourceResolution.js +35 -26
  151. package/dist/storeMiddleware.js +213 -212
  152. package/dist/storeQuery.js +1 -2
  153. package/dist/storeRead.js +1 -2
  154. package/dist/subscriber.js +2 -2
  155. package/dist/subscriptionOutbox.js +1 -2
  156. package/dist/subscriptionRegistry.js +1 -2
  157. package/dist/subscriptionResume.js +1 -2
  158. package/dist/subscriptionSocketMetrics.js +1 -2
  159. package/dist/systemSubject.js +1 -2
  160. package/dist/tenantScope.js +9 -22
  161. package/dist/tenantSelection.js +1 -2
  162. package/dist/timeline.js +1 -2
  163. package/dist/traceContext.js +1 -2
  164. package/dist/traceSink.js +1 -2
  165. package/dist/traceSpansTable.js +1 -2
  166. package/dist/traceparent.js +9 -21
  167. package/dist/transactionSubject.js +1 -2
  168. package/dist/trustedProxy.js +2 -3
  169. package/dist/undo.js +1 -2
  170. package/dist/undoBuiltins.js +1 -2
  171. package/dist/undoCapture.js +1 -2
  172. package/dist/undoLogTable.js +1 -2
  173. package/dist/upsertBinding.js +1 -2
  174. package/dist/wakeOrchestrator.js +1 -2
  175. package/dist/wakeRegistry.js +1 -2
  176. package/dist/wakeRouter.js +1 -2
  177. package/dist/wakeSupervisor.js +1 -2
  178. package/dist/wakeupsTable.js +1 -2
  179. package/dist/webSocketGatewayRuntime.js +112 -73
  180. package/dist/webhookVerification.js +1 -2
  181. package/dist/wireColumnStrip.js +1 -2
  182. package/dist/workflowReadBuiltins.js +1 -2
  183. package/dist/workflowRuntime.js +10 -11
  184. package/package.json +36 -17
@@ -1,26 +1,28 @@
1
- import { enterReadRecording as e } from "./readRecorder.js";
2
- import { getRowFilter as t, makeDefaultRefilter as n, resolveRowFilterScope as r } from "./rowFilter.js";
3
- import { isComputedQuery as i } from "./computedQuery.js";
4
- import { TX_READ_VERSIONS_KEY as a, isTransactionReadConflict as o } from "./storeMiddleware.js";
5
- import { evaluateTouchedRules as s, makeRuleCapture as c } from "./businessRules.js";
6
- import { enforceApproval as l } from "./approvals.js";
7
- import { Cause as u, Effect as d, Exit as f, Option as p } from "effect";
8
- import { isTransientContention as m } from "@voltro/database";
9
- import { SubjectService as h, checkGuardsEffect as g, currentSubjectAuthority as _, recheckGuardsEffect as v } from "@voltro/protocol";
10
- import { createLogger as y } from "@voltro/logger";
11
- //#region src/servePipeline.ts
12
- var b = (e, t) => d.runPromiseExit(e, t).then((e) => {
13
- if (f.isSuccess(e)) return e.value;
14
- let t = u.findErrorOption(e.cause);
15
- throw p.isSome(t) ? t.value : u.squash(e.cause);
16
- }), x = (e) => b(e), S = (e, t) => e.pipe(d.provideService(h, t)), C = async (e, t, n, r) => {
17
- let i = await d.runPromise(g(t, e.guards, n, {
1
+ import { cachedComputedCall as e, computedAuthorityRefusal as t, computedCacheKey as n, computedSubjectIdentity as r, currentQueryDependencies as i, enterQueryDependencies as a } from "./computedQueryCache.js";
2
+ import { enterReadRecording as o } from "./readRecorder.js";
3
+ import { getRowFilter as s, makeDefaultRefilter as c, resolveRowFilterScope as l } from "./rowFilter.js";
4
+ import { isComputedQuery as u } from "./computedQuery.js";
5
+ import { TX_READ_VERSIONS_KEY as d, isTransactionReadConflict as f } from "./storeMiddleware.js";
6
+ import { evaluateTouchedRules as p, makeRuleCapture as m } from "./businessRules.js";
7
+ import { enforceApproval as h } from "./approvals.js";
8
+ import { observeApiRoleEffect as g } from "./apiRoleWorkloadMetrics.js";
9
+ import { Cause as _, Effect as v, Exit as y, Option as b } from "effect";
10
+ import { isTransientContention as x } from "@voltro/database";
11
+ import { SubjectService as S, checkGuardsEffect as C, currentSubjectAuthority as w, recheckGuardsEffect as T } from "@voltro/protocol";
12
+ import { createLogger as E } from "@voltro/logger";
13
+ // src/servePipeline.ts
14
+ var D = (e, t) => v.runPromiseExit(e, t).then((e) => {
15
+ if (y.isSuccess(e)) return e.value;
16
+ let t = _.findErrorOption(e.cause);
17
+ throw b.isSome(t) ? t.value : _.squash(e.cause);
18
+ }), O = (e) => D(e), k = (e, t) => e.pipe(v.provideService(S, t)), A = async (e, t, n, r) => {
19
+ let i = await v.runPromise(C(t, e.guards, n, {
18
20
  defaultDeny: r === !0,
19
21
  procedure: e.name
20
22
  }));
21
23
  if (i) throw i;
22
- }, w = async (e, t, n, r) => {
23
- e.requiresApproval !== void 0 && await l({
24
+ }, j = async (e, t, n, r) => {
25
+ e.requiresApproval !== void 0 && await h({
24
26
  procedure: e.name,
25
27
  kind: t,
26
28
  policy: e.requiresApproval,
@@ -28,20 +30,20 @@ var b = (e, t) => d.runPromiseExit(e, t).then((e) => {
28
30
  input: r,
29
31
  traceId: n.traceId
30
32
  });
31
- }, T = y({ scope: "voltro:rpc" }), E = async (e) => {
32
- if (t() === void 0) return e;
33
- let n = await x(r(e.subject, (e) => {
34
- T.error("row filter failed to load", {}, e instanceof Error ? e : Error(String(e)));
33
+ }, M = E({ scope: "voltro:rpc" }), N = async (e) => {
34
+ if (s() === void 0) return e;
35
+ let t = await O(l(e.subject, (e) => {
36
+ M.error("row filter failed to load", {}, e instanceof Error ? e : Error(String(e)));
35
37
  }));
36
38
  return {
37
39
  ...e,
38
- rowFilter: n
40
+ rowFilter: t
39
41
  };
40
- }, D = (e) => ({
42
+ }, P = (e) => ({
41
43
  ...e.surface === void 0 ? {} : { surface: e.surface },
42
44
  ...e.publicApi === void 0 ? {} : { publicApi: e.publicApi },
43
45
  ...e.remoteAddr === void 0 ? {} : { remoteAddr: e.remoteAddr }
44
- }), O = (e) => {
46
+ }), F = (e) => {
45
47
  let t = e.descriptor.target;
46
48
  if (t == null) return [];
47
49
  let n = Array.isArray(t) ? t : [t], r = /* @__PURE__ */ new Set();
@@ -50,7 +52,7 @@ var b = (e, t) => d.runPromiseExit(e, t).then((e) => {
50
52
  typeof t == "string" && t.length > 0 && r.add(t);
51
53
  }
52
54
  return [...r];
53
- }, k = async (e) => {
55
+ }, I = async (e) => {
54
56
  let { store: t, target: n, procedure: r, input: i, output: a } = e;
55
57
  if (n == null) return;
56
58
  let o = Array.isArray(n) ? n : [n];
@@ -67,15 +69,15 @@ var b = (e, t) => d.runPromiseExit(e, t).then((e) => {
67
69
  await u.set(c.map((e) => String(e)));
68
70
  }
69
71
  }
70
- }, A = (e, t) => e === void 0 ? {} : { enqueueOutcome: async (n, r, i) => {
72
+ }, L = (e, t) => e === void 0 ? {} : { enqueueOutcome: async (n, r, i) => {
71
73
  let a = e(t);
72
74
  if (a === void 0) throw TypeError("Invocation outcome outbox is unavailable");
73
75
  return a.enqueue(n, r, i);
74
- } }, j = async (e) => {
76
+ } }, R = async (e) => {
75
77
  let t = `${e.kind}.${e.name}`, n = Date.now(), r = "ok";
76
78
  try {
77
79
  if (e.interceptor) {
78
- let t = d.tryPromise({
80
+ let t = v.tryPromise({
79
81
  try: () => e.runExecutor(),
80
82
  catch: (e) => e
81
83
  }), n = e.interceptor(t, {
@@ -87,10 +89,10 @@ var b = (e, t) => d.runPromiseExit(e, t).then((e) => {
87
89
  ...e.enqueueOutcome === void 0 ? {} : { enqueueOutcome: e.enqueueOutcome },
88
90
  ...e.requestContext.spanId === void 0 ? {} : { spanId: e.requestContext.spanId },
89
91
  ...e.target !== void 0 && e.target.length > 0 ? { target: e.target } : {},
90
- ...D(e.requestContext)
91
- }), r = await d.runPromiseExit(n, e.requestContext.signal === void 0 ? void 0 : { signal: e.requestContext.signal });
92
- if (f.isSuccess(r)) return r.value;
93
- throw u.squash(r.cause);
92
+ ...P(e.requestContext)
93
+ }), r = await v.runPromiseExit(n, e.requestContext.signal === void 0 ? void 0 : { signal: e.requestContext.signal });
94
+ if (y.isSuccess(r)) return r.value;
95
+ throw _.squash(r.cause);
94
96
  }
95
97
  return await e.runExecutor();
96
98
  } catch (e) {
@@ -103,177 +105,255 @@ var b = (e, t) => d.runPromiseExit(e, t).then((e) => {
103
105
  status: r
104
106
  });
105
107
  }
106
- }, M = (e) => m(e) || o(e), N = 3, P = (e) => new Promise((t) => setTimeout(t, e)), F = async (e, t) => {
107
- let n = t?.delay ?? ((e) => P(e * 20 + Math.floor(Math.random() * 30))), r = t?.attempts ?? 3;
108
+ }, z = (e) => x(e) || f(e), B = 3, V = (e) => new Promise((t) => setTimeout(t, e)), H = async (e, t) => {
109
+ let n = t?.delay ?? ((e) => V(e * 20 + Math.floor(Math.random() * 30))), r = t?.attempts ?? 3;
108
110
  for (let t = 1;; t++) try {
109
111
  return await e();
110
112
  } catch (e) {
111
- if (t >= r || !M(e)) throw o(e) ? e.conflict : e;
113
+ if (t >= r || !z(e)) throw f(e) ? e.conflict : e;
112
114
  await n(t);
113
115
  }
114
- }, I = (e) => (t, n, r) => j({
116
+ }, U = (e) => (t, n, r) => R({
115
117
  name: t.descriptor.name,
116
118
  kind: "mutation",
117
119
  input: n,
118
120
  requestContext: r,
119
- ...A(e.outcomeOutbox, r),
120
- target: O(t),
121
+ ...L(e.outcomeOutbox, r),
122
+ target: F(t),
121
123
  ...e.interceptor ? { interceptor: e.interceptor } : {},
122
124
  ...e.recordMetric ? { recordMetric: e.recordMetric } : {},
123
125
  runExecutor: async () => {
124
126
  let i = Date.now();
125
- await C(t.descriptor, r.subject, n, e.defaultDeny), await w(t.descriptor, "mutation", r, n);
126
- let o = await E(r), l = e.resolveStore === void 0 ? e.store : await e.resolveStore(o), u = [], f = [], p = await F(async () => l.transactional(async (p) => {
127
- u.length = 0, f.length = 0, p[Symbol.for("@voltro/runtime:tx-fold-releases")] = f, p[a] = /* @__PURE__ */ new Map();
128
- let m = e.undoCapture?.(p), h = m ? m.tx : p, g = c(h), _ = e.buildContext(o, g.tx, {
129
- committedStore: l,
127
+ await Y(t, "mutation", { defaultDeny: e.defaultDeny === !0 })(n, r);
128
+ let a = {
129
+ ...r,
130
+ subject: w(r.subject)
131
+ };
132
+ await j(t.descriptor, "mutation", a, n);
133
+ let o = await N(a), s = e.resolveStore === void 0 ? e.store : await e.resolveStore(o), c = [], l = [], u = await H(async () => s.transactional(async (a) => {
134
+ c.length = 0, l.length = 0, a[Symbol.for("@voltro/runtime:tx-fold-releases")] = l, a[d] = /* @__PURE__ */ new Map();
135
+ let u = t.descriptor.undo?.capture === !1 ? void 0 : e.undoCapture?.(a), f = u ? u.tx : a, h = m(f), g = e.buildContext(o, h.tx, {
136
+ committedStore: s,
130
137
  afterCommit: (e) => {
131
- u.push(e);
138
+ c.push(e);
132
139
  }
133
- }), v = t.executor(n, _), y = d.isEffect(v) ? await e.runEffect(S(v, r.subject), _.store) : await v;
134
- if (await k({
135
- store: _.store,
140
+ }), _ = e.measureSync ? e.measureSync(() => t.executor(n, g)) : t.executor(n, g), y = v.isEffect(_) ? await e.runEffect(k(_, o.subject), g.store) : await _;
141
+ if (await I({
142
+ store: g.store,
136
143
  target: t.descriptor.target,
137
144
  procedure: t.descriptor.name,
138
145
  input: n,
139
146
  output: y
140
- }), m && await m.persist(_.store, {
147
+ }), u && await u.persist(g.store, {
141
148
  tag: t.descriptor.name,
142
- subject: r.subject,
149
+ subject: o.subject,
143
150
  traceId: r.traceId
144
- }), await s({
145
- touched: g.drain(),
146
- store: _.store,
147
- subject: r.subject
151
+ }), await p({
152
+ touched: h.drain(),
153
+ store: g.store,
154
+ subject: o.subject
148
155
  }), e.beforeMutationCommit !== void 0) {
149
- let a = O(t), s = e.beforeMutationCommit({
156
+ let r = F(t), a = e.beforeMutationCommit({
150
157
  tag: t.descriptor.name,
151
158
  kind: "mutation",
152
159
  input: n,
153
160
  output: y,
154
161
  subject: o.subject,
155
162
  traceId: o.traceId,
156
- store: _.store,
157
- ..._.outbox === void 0 ? {} : { outbox: _.outbox },
163
+ store: g.store,
164
+ ...g.outbox === void 0 ? {} : { outbox: g.outbox },
158
165
  startedAt: i,
159
166
  durationMs: Math.max(0, Date.now() - i),
160
167
  ...o.spanId === void 0 ? {} : { spanId: o.spanId },
161
- ...a.length > 0 ? { target: a } : {},
162
- ...D(o)
168
+ ...r.length > 0 ? { target: r } : {},
169
+ ...P(o)
163
170
  });
164
- await e.runEffect(S(s, r.subject), _.store);
171
+ await e.runEffect(k(a, o.subject), g.store);
165
172
  }
166
173
  return y;
167
174
  }), { ...e.replayAttempts === void 0 ? {} : { attempts: e.replayAttempts } });
168
- if (f.length > 0) {
169
- let t = e.buildContext(o, l, {
170
- committedStore: l,
175
+ if (l.length > 0) {
176
+ let t = e.buildContext(o, s, {
177
+ committedStore: s,
171
178
  afterCommit: () => {}
172
179
  }).store;
173
- for (let e of f.splice(0)) await t.update(e.table, e.pk, e.patch);
180
+ for (let e of l.splice(0)) await t.update(e.table, e.pk, e.patch);
174
181
  }
175
- for (let e of u) await e();
176
- return p;
182
+ for (let e of c) await e();
183
+ return e.settleCacheInvalidations !== void 0 && await e.settleCacheInvalidations(), u;
177
184
  }
178
- }), L = (e) => (t, n, r, i) => j({
185
+ }), W = (e) => (t, n, r, i) => R({
179
186
  name: t.name,
180
187
  kind: "workflow",
181
188
  input: n,
182
189
  requestContext: r,
183
- ...A(e.outcomeOutbox, r),
190
+ ...L(e.outcomeOutbox, r),
184
191
  ...e.interceptor ? { interceptor: e.interceptor } : {},
185
192
  ...e.recordMetric ? { recordMetric: e.recordMetric } : {},
186
- runExecutor: async () => (await C(t, r.subject, n, e.defaultDeny), i())
187
- }), R = (e) => e && typeof e == "object" && "descriptor" in e ? e.descriptor : e, z = (e) => typeof e == "object" && !!e && !Array.isArray(e) && "table" in e && "order" in e, B = (e) => {
193
+ runExecutor: async () => (await A(t, r.subject, n, e.defaultDeny), i())
194
+ }), G = (e) => e && typeof e == "object" && "descriptor" in e ? e.descriptor : e, K = (e) => typeof e == "object" && !!e && !Array.isArray(e) && "table" in e && "order" in e, q = (e) => {
188
195
  let t = e.descriptor.source;
189
196
  return t == null ? [] : typeof t == "string" ? [t] : [...t];
190
- }, V = (e, t, n) => (r) => () => d.runPromise(v(r, e.descriptor.guards, t, {
197
+ }, J = (e, t, n) => (r) => () => v.runPromise(T(r, e.descriptor.guards, t, {
191
198
  defaultDeny: n === !0,
192
199
  procedure: e.descriptor.name
193
- })), H = (e, n) => e.rowFilter !== void 0 || t() === void 0 ? n(e) : d.promise(() => E(e)).pipe(d.flatMap((e) => {
194
- let t = n(e);
195
- return d.isEffect(t) ? t : d.succeed(t);
196
- })), U = (n) => (r, a) => (o) => {
197
- if (o.rowFilter === void 0 && t() !== void 0) return H(o, (e) => U(n)(r, a)(e));
198
- let s = n.buildContext(o), c = V(r, a, n.defaultDeny)(o.subject), l = async () => {
199
- let e = await c();
200
+ })), Y = (e, t, n = {}) => async (r, i) => {
201
+ let a = i.subject;
202
+ n.bindReplayAuthority?.({
203
+ tag: e.descriptor.name,
204
+ kind: t,
205
+ input: r,
206
+ subject: a,
207
+ traceId: i.traceId,
208
+ ...i.surface === void 0 ? {} : { surface: i.surface },
209
+ ...i.publicApi === void 0 ? {} : { publicApi: i.publicApi },
210
+ ...i.remoteAddr === void 0 ? {} : { remoteAddr: i.remoteAddr }
211
+ });
212
+ let o = await J(e, r, n.defaultDeny)(a)();
213
+ if (o) throw o;
214
+ }, X = (e, t) => e.rowFilter !== void 0 || s() === void 0 ? t(e) : v.promise(() => N(e)).pipe(v.flatMap((e) => {
215
+ let n = t(e);
216
+ return v.isEffect(n) ? n : v.succeed(n);
217
+ })), Z = (e, t) => Q(e, t, /* @__PURE__ */ new Set()), Q = (c, l, d) => (f, p) => (m) => {
218
+ if (m.rowFilter === void 0 && s() !== void 0) return X(m, (e) => Q(c, l, d)(f, p)(e));
219
+ let h = l ?? (m.connection?.transport === "http" ? "rpc" : "subscriptions"), _ = (e) => c.workloadMetrics ? c.workloadMetrics.measureSync(h, e) : e(), y = (e, t) => {
220
+ let n = c.provideEffect(e, t);
221
+ return c.workloadMetrics ? g(n, c.workloadMetrics, h) : n;
222
+ }, b = c.buildContext(m), x = J(f, p, c.defaultDeny)(m.subject), S = async () => {
223
+ let e = await x();
200
224
  if (e) throw e;
201
225
  let t = {
202
- ...o,
203
- subject: _(o.subject)
204
- }, i = n.buildContext(await E(t)), s = r.executor(a, i), l = d.isEffect(s) ? await b(n.provideEffect(S(s, t.subject), i.store), o.signal === void 0 ? void 0 : { signal: o.signal }) : R(await Promise.resolve(s)), u = await c();
205
- if (u) throw u;
206
- return l;
207
- }, u = (e) => {
208
- let t = R(e);
209
- if (z(t)) {
210
- let e = n.finalize(t, o), i = B(r);
211
- if (i.length === 0) return e;
212
- let a = e.dependentTables ?? [];
226
+ ...m,
227
+ subject: w(m.subject)
228
+ }, n = c.buildContext(await N(t)), r = _(() => f.executor(p, n)), i = v.isEffect(r) ? await D(y(k(r, t.subject), n.store), m.signal === void 0 ? void 0 : { signal: m.signal }) : G(await Promise.resolve(r)), a = await x();
229
+ if (a) throw a;
230
+ return i;
231
+ }, T = (e, t = i()) => {
232
+ let n = G(e);
233
+ if (K(n)) {
234
+ let e = c.finalize(n, m), t = q(f);
235
+ if (t.length === 0) return e;
236
+ let r = e.dependentTables ?? [];
213
237
  return {
214
238
  ...e,
215
- dependentTables: [.../* @__PURE__ */ new Set([...a, ...i])]
239
+ dependentTables: [.../* @__PURE__ */ new Set([...r, ...t])]
216
240
  };
217
241
  }
218
242
  return {
219
243
  __voltroComputed: !0,
220
- value: t,
221
- dependentTables: B(r),
222
- tenantId: o.subject?.tenantId ?? null,
223
- recompute: l
244
+ value: n,
245
+ dependentTables: [.../* @__PURE__ */ new Set([...q(f), ...t])],
246
+ tenantId: m.subject?.tenantId ?? null,
247
+ recompute: S
224
248
  };
225
- }, f = (e) => {
226
- let t = u(e);
227
- return i(t) ? d.tryPromise({
228
- try: c,
249
+ }, E = (e, t) => {
250
+ let n = T(e, t);
251
+ return u(n) ? v.tryPromise({
252
+ try: x,
229
253
  catch: (e) => e
230
- }).pipe(d.flatMap((e) => e ? d.fail(e) : d.succeed(t))) : t;
231
- }, p = (e) => {
232
- let t = f(e);
233
- return d.isEffect(t) ? t : d.succeed(t);
234
- }, m = () => {
235
- e(r.descriptor.name, B(r));
236
- let t = r.executor(a, s);
237
- return d.isEffect(t) ? n.provideEffect(S(t, o.subject), s.store).pipe(d.flatMap(p)) : t instanceof Promise ? d.promise(() => t).pipe(d.flatMap(p)) : f(t);
238
- }, h = () => {
239
- let e = r.descriptor.guards;
240
- return (!e || e.length === 0) && n.defaultDeny !== !0 && o.subject.type !== "service" ? m() : g(o.subject, e, a, {
241
- defaultDeny: n.defaultDeny === !0,
242
- procedure: r.descriptor.name
243
- }).pipe(d.flatMap((e) => {
244
- if (e) return d.fail(e);
245
- let t = m();
246
- return d.isEffect(t) ? t : d.succeed(t);
254
+ }).pipe(v.flatMap((e) => e ? v.fail(e) : v.succeed(n))) : n;
255
+ }, O = (e, t) => {
256
+ let n = E(e, t);
257
+ return v.isEffect(n) ? n : v.succeed(n);
258
+ }, A = () => {
259
+ let i = c.computedCache, a = f.descriptor.cache;
260
+ if (i === void 0 || a === void 0 || d.has(f.descriptor.name)) return;
261
+ let o = i.policyFor(a);
262
+ if (o !== void 0) return v.tryPromise({
263
+ try: async () => {
264
+ let e = await x();
265
+ if (e) throw e;
266
+ return N({
267
+ ...m,
268
+ subject: w(m.subject)
269
+ });
270
+ },
271
+ catch: (e) => e
272
+ }).pipe(v.flatMap((a) => {
273
+ let s = a.subject, l = c.buildContext(a), u = r(s), h = q(f), g = n({
274
+ name: f.descriptor.name,
275
+ codeIdentity: i.codeIdentity,
276
+ output: f.descriptor.output,
277
+ input: f.descriptor.input,
278
+ decodedInput: p,
279
+ scope: o.scope,
280
+ subject: s,
281
+ rowFilter: a.rowFilter,
282
+ declaredSources: h
283
+ });
284
+ return "bypass" in g ? (g.bypass === "input-not-encodable" && i.notice(f.descriptor.name, g.bypass, `${f.descriptor.name}: \`cache:\` NOT applied — the input does not encode through its \`input\` schema, so it has no key.`), g.bypass === "subject-not-encodable" && i.notice(f.descriptor.name, g.bypass, `${f.descriptor.name}: \`cache:\` NOT applied — the subject contains claims that cannot be keyed as data. Keep subject claims as plain data, or drop \`cache:\`.`), v.tryPromise({
285
+ try: S,
286
+ catch: (e) => e
287
+ }).pipe(v.flatMap((e) => O(e)))) : e({
288
+ cache: i,
289
+ policy: o,
290
+ key: g.key,
291
+ name: f.descriptor.name,
292
+ sources: h,
293
+ output: f.descriptor.output,
294
+ subject: s,
295
+ rowFilter: a.rowFilter,
296
+ ctx: l,
297
+ ...m.signal === void 0 ? {} : { signal: m.signal },
298
+ execute: (e, t) => {
299
+ let n = _(() => f.executor(p, e));
300
+ return v.isEffect(n) ? D(y(k(n, t), l.store), m.signal === void 0 ? void 0 : { signal: m.signal }) : Promise.resolve(n);
301
+ },
302
+ onDescriptor: () => {
303
+ d.add(f.descriptor.name);
304
+ },
305
+ isDescriptor: (e) => K(G(e)),
306
+ unwrap: (e) => G(e)
307
+ }).pipe(v.flatMap(({ value: e, dependencies: t }) => O(e, t)), v.flatMap((e) => {
308
+ let n = r(w(m.subject));
309
+ return u === n ? v.succeed(e) : v.fail(t());
310
+ }));
311
+ }));
312
+ }, j = () => {
313
+ o(f.descriptor.name, q(f)), a();
314
+ let e = A();
315
+ if (e !== void 0) return e;
316
+ let t = _(() => f.executor(p, b));
317
+ return v.isEffect(t) ? y(k(t, m.subject), b.store).pipe(v.flatMap(O)) : t instanceof Promise ? v.promise(() => t).pipe(v.flatMap(O)) : E(t);
318
+ }, M = () => {
319
+ let e = f.descriptor.guards;
320
+ return (!e || e.length === 0) && c.defaultDeny !== !0 && m.subject.type !== "service" ? j() : C(m.subject, e, p, {
321
+ defaultDeny: c.defaultDeny === !0,
322
+ procedure: f.descriptor.name
323
+ }).pipe(v.flatMap((e) => {
324
+ if (e) return v.fail(e);
325
+ let t = j();
326
+ return v.isEffect(t) ? t : v.succeed(t);
247
327
  }));
248
328
  };
249
- if (!n.interceptor) return h();
250
- let v = d.suspend(() => {
251
- let e = h();
252
- return d.isEffect(e) ? e : d.succeed(e);
329
+ if (!c.interceptor) return M();
330
+ let F = v.suspend(() => {
331
+ let e = M();
332
+ return v.isEffect(e) ? e : v.succeed(e);
253
333
  });
254
- return n.interceptor(v, {
255
- tag: r.descriptor.name,
334
+ return c.interceptor(F, {
335
+ tag: f.descriptor.name,
256
336
  kind: "query",
257
- input: a,
258
- subject: o.subject,
259
- traceId: o.traceId,
260
- ...o.spanId === void 0 ? {} : { spanId: o.spanId },
261
- ...D(o)
337
+ input: p,
338
+ subject: m.subject,
339
+ traceId: m.traceId,
340
+ ...m.spanId === void 0 ? {} : { spanId: m.spanId },
341
+ ...P(m)
262
342
  });
263
- }, W = (e) => async (t, n, r) => {
264
- let a = await E(r), o = U(e)(t, n)(a), s = d.isEffect(o) ? await x(o) : o;
265
- if (i(s)) return s.value;
266
- let c = e.buildContext(a), l = await e.queryRows(s, a, c.store), u = await V(t, n, e.defaultDeny)(a.subject)();
267
- if (u) throw u;
268
- return l;
269
- }, G = (e) => (t, r, a, o) => {
270
- let s = !1, c;
343
+ }, $ = (e) => async (t, n, r) => {
344
+ let i = await N(r), a = Z(e, "rpc")(t, n)(i), o = v.isEffect(a) ? await O(a) : a;
345
+ if (u(o)) return o.value;
346
+ let s = e.buildContext(i), c = await e.queryRows(o, i, s.store), l = await J(t, n, e.defaultDeny)(i.subject)();
347
+ if (l) throw l;
348
+ return c;
349
+ }, ee = (e) => (t, n, r, i) => {
350
+ let a = !1, o;
271
351
  return (async () => {
272
352
  try {
273
- let l = await E(a), u = U(e)(t, r)(l), f = d.isEffect(u) ? await x(u) : u, p = (e) => o(e), m = i(f) ? await e.subscribeComputed(f, p, l) : await e.subscribeDescriptor(f, p, l, V(t, r, e.defaultDeny)(l.subject), n(l.subject));
274
- s ? m() : c = m;
353
+ let s = await N(r), l = Z(e, "subscriptions")(t, n)(s), d = v.isEffect(l) ? await O(l) : l, f = (e) => i(e), p = u(d) ? await e.subscribeComputed(d, f, s) : await e.subscribeDescriptor(d, f, s, J(t, n, e.defaultDeny)(s.subject), c(s.subject));
354
+ a ? p() : o = p;
275
355
  } catch (e) {
276
- o({
356
+ i({
277
357
  _tag: "error",
278
358
  error: e instanceof Error ? {
279
359
  message: e.message,
@@ -282,24 +362,28 @@ var b = (e, t) => d.runPromiseExit(e, t).then((e) => {
282
362
  });
283
363
  }
284
364
  })(), () => {
285
- s = !0, c?.();
365
+ a = !0, o?.();
286
366
  };
287
- }, K = (t) => (n, r, i) => j({
288
- name: n.descriptor.name,
367
+ }, te = (e) => (t, n, r) => R({
368
+ name: t.descriptor.name,
289
369
  kind: "action",
290
- input: r,
291
- requestContext: i,
292
- ...A(t.outcomeOutbox, i),
293
- target: O(n),
294
- ...t.interceptor ? { interceptor: t.interceptor } : {},
295
- ...t.recordMetric ? { recordMetric: t.recordMetric } : {},
370
+ input: n,
371
+ requestContext: r,
372
+ ...L(e.outcomeOutbox, r),
373
+ target: F(t),
374
+ ...e.interceptor ? { interceptor: e.interceptor } : {},
375
+ ...e.recordMetric ? { recordMetric: e.recordMetric } : {},
296
376
  runExecutor: async () => {
297
- await C(n.descriptor, i.subject, r, t.defaultDeny), await w(n.descriptor, "action", i, r);
298
- let a = t.buildContext(await E(i));
299
- e(n.descriptor.name, B(n));
300
- let o = n.executor(r, a);
301
- return d.isEffect(o) ? t.runEffect(S(o, i.subject), a.store) : o;
377
+ await Y(t, "action", { defaultDeny: e.defaultDeny === !0 })(n, r);
378
+ let i = {
379
+ ...r,
380
+ subject: w(r.subject)
381
+ };
382
+ await j(t.descriptor, "action", i, n);
383
+ let a = e.buildContext(await N(i));
384
+ o(t.descriptor.name, q(t));
385
+ let s = e.measureSync ? e.measureSync(() => t.executor(n, a)) : t.executor(n, a), c = v.isEffect(s) ? await e.runEffect(k(s, i.subject), a.store) : await s;
386
+ return e.settleCacheInvalidations !== void 0 && await e.settleCacheInvalidations(), c;
302
387
  }
303
388
  });
304
- //#endregion
305
- export { N as DEFAULT_MUTATION_REPLAY_ATTEMPTS, k as applyDeclaredRelations, K as makeActionRunner, I as makeMutationRunner, W as makeOneShotQueryRunner, U as makeQueryDescriptorProducer, V as makeQueryReauthorizer, G as makeQuerySubscriber, L as makeWorkflowStartRunner, x as runProvidedEffect, F as runWithDeadlockRetry, E as withRowFilter, H as withScopedRequest };
389
+ export { B as DEFAULT_MUTATION_REPLAY_ATTEMPTS, I as applyDeclaredRelations, te as makeActionRunner, Y as makeMutationReplayAdmission, U as makeMutationRunner, $ as makeOneShotQueryRunner, Z as makeQueryDescriptorProducer, J as makeQueryReauthorizer, ee as makeQuerySubscriber, W as makeWorkflowStartRunner, O as runProvidedEffect, H as runWithDeadlockRetry, N as withRowFilter, X as withScopedRequest };
@@ -1,5 +1,5 @@
1
1
  import { SchemaAST as e } from "effect";
2
- //#region src/serverOnlyAudit.ts
2
+ // src/serverOnlyAudit.ts
3
3
  var t = (t) => {
4
4
  let n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), i = (t) => {
5
5
  if (!r.has(t)) switch (r.add(t), t.encoding !== void 0 && i(e.toEncoded(t)), t._tag) {
@@ -62,5 +62,4 @@ var t = (t) => {
62
62
  })) : [], o = (e) => {
63
63
  if (e.length !== 0) return `A cached query shares one entry across tenants:\n${e.map((e) => ` • query '${e.query}' caches scope:'global' while reading '${e.table}', a tenant()-scoped table`).join("\n")}\n\nscope:'global' stores ONE entry for every caller. On a tenant-scoped table the\nrows depend on who asked, so the first caller's rows are served to the next one.\n\nUse scope:'tenant' — one entry per org, none shared across orgs. Use 'subject'\nif the result also depends on WHICH person is asking, and 'global' only for data\nthat depends on neither.`;
64
64
  };
65
- //#endregion
66
65
  export { a as cacheScopeLeaks, o as formatCacheScopeLeaks, i as formatServerOnlyLeaks, t as schemaPropertyNames, r as serverOnlyLeaks };
@@ -1,5 +1,5 @@
1
1
  import { Effect as e, Layer as t } from "effect";
2
- //#region src/serverTracer.ts
2
+ // src/serverTracer.ts
3
3
  var n = Symbol.for("@voltro/runtime:serverTracer"), r = (() => {
4
4
  let e = globalThis;
5
5
  return e[n] ??= {};
@@ -11,5 +11,4 @@ var n = Symbol.for("@voltro/runtime:serverTracer"), r = (() => {
11
11
  let n = r.tracer;
12
12
  return n === void 0 ? t : e.withTracer(t, n);
13
13
  };
14
- //#endregion
15
14
  export { o as publishServerTracerLayer, a as serverTracer, i as setServerTracer, s as withServerTracer };
@@ -1,6 +1,6 @@
1
1
  import { createHash as e, randomBytes as t, timingSafeEqual as n } from "node:crypto";
2
2
  import { SERVICE_NAME_PATTERN as r, serviceSubject as i } from "@voltro/protocol";
3
- //#region src/serviceCredentials.ts
3
+ // src/serviceCredentials.ts
4
4
  var a = "vsvc_", o = /^vsvc_[A-Za-z0-9_-]{43}$/, s = () => `${a}${t(32).toString("base64url")}`, c = (e) => o.test(e), l = (e) => e.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/-/g, "_").toUpperCase(), u = (e) => `VOLTRO_SERVICE_CALLER_${l(e)}_TOKEN`, d = (e) => `${u(e)}_NEXT`, f = (e) => `VOLTRO_API_${l(e)}_TOKEN`, p = (e) => `VOLTRO_API_${l(e)}_URL`, m = (e) => {
5
5
  for (let t of Object.keys(e)) if (!r.test(t)) throw Error(`serviceCallers: ${JSON.stringify(t)} is not an app name — letters, digits and dashes, starting with a letter, at most 56 characters. It is the name the calling app binds this api under and the name its procedures list in \`service: { callers }\`.`);
6
6
  }, h = (t) => e("sha256").update(t).digest(), g = (e, t) => n(e, h(t)), _ = (e, t) => [e[u(t)], e[d(t)]].filter((e) => typeof e == "string" && e !== ""), v = (e) => {
@@ -36,5 +36,4 @@ var a = "vsvc_", o = /^vsvc_[A-Za-z0-9_-]{43}$/, s = () => `${a}${t(32).toString
36
36
  }
37
37
  };
38
38
  };
39
- //#endregion
40
39
  export { a as SERVICE_TOKEN_PREFIX, f as apiBindingTokenEnv, p as apiBindingUrlEnv, m as assertServiceCallersConfig, c as isWellFormedServiceToken, s as mintServiceToken, d as serviceCallerNextTokenEnv, v as serviceCallerStrategy, u as serviceCallerTokenEnv, l as serviceEnvSegment };
@@ -0,0 +1,27 @@
1
+ // src/setReadScopes.ts
2
+ var e = [
3
+ "crossTenant",
4
+ "includeDeleted",
5
+ "includeExpired"
6
+ ], t = (t, n) => {
7
+ let r = (t, i) => {
8
+ let a = t;
9
+ for (let t of e) i?.[t] === !0 && a[t] !== !0 && (a = {
10
+ ...a,
11
+ [t]: !0
12
+ });
13
+ let o = a.setOp;
14
+ if (o === void 0) return n(a);
15
+ if (o.queries.length < 2) throw Error("A set operation requires at least two inputs");
16
+ let s = o.queries.map((e) => r(e, a));
17
+ return s.every((e, t) => e === o.queries[t]) ? a : {
18
+ ...a,
19
+ setOp: {
20
+ ...o,
21
+ queries: s
22
+ }
23
+ };
24
+ };
25
+ return r(t);
26
+ };
27
+ export { t as mapSetReadScopes };
@@ -3,7 +3,7 @@ import { wakeDueOnce as t } from "./wakeOrchestrator.js";
3
3
  import { makeProcessAdapter as n } from "./wakeSupervisor.js";
4
4
  import { isIdleNow as r, makeIdleGate as i } from "./idleDetector.js";
5
5
  import { makeRouterActivity as a, makeWakeProxyServer as o } from "./wakeRouter.js";
6
- //#region src/singleNodeOrchestrator.ts
6
+ // src/singleNodeOrchestrator.ts
7
7
  var s = async (e) => {
8
8
  try {
9
9
  return (await e.query({
@@ -87,5 +87,4 @@ var s = async (e) => {
87
87
  }
88
88
  };
89
89
  };
90
- //#endregion
91
90
  export { s as countRunningWorkflows, c as runOrchestratorTick, l as runSingleNodeOrchestrator };