@voltro/runtime 0.86.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.
Files changed (70) hide show
  1. package/CHANGELOG.md +5321 -0
  2. package/README.md +43 -0
  3. package/THIRD-PARTY-NOTICES.md +860 -221
  4. package/dist/analyticsSink.js +8 -14
  5. package/dist/apiKeys.js +82 -78
  6. package/dist/apiRoleBucketSampler.js +64 -0
  7. package/dist/apiRoleWorkloadHistory.js +56 -0
  8. package/dist/apiRoleWorkloadMetrics.js +78 -0
  9. package/dist/apiRoleWorkloadStorage.js +95 -0
  10. package/dist/approvals.js +67 -74
  11. package/dist/authMiddlewareLayer.js +7 -6
  12. package/dist/bindEvent.js +48 -28
  13. package/dist/bootListener.js +106 -39
  14. package/dist/bootStoreCodec.js +38 -37
  15. package/dist/circuitBreaker.js +1 -72
  16. package/dist/composeAnalytics.js +31 -10
  17. package/dist/computedQueryCache.js +231 -0
  18. package/dist/connectionsFacade.js +32 -30
  19. package/dist/coordinatedSchedule.js +84 -78
  20. package/dist/dataStore.js +154 -121
  21. package/dist/declaredTablesGuard.js +2 -1
  22. package/dist/dispatcher.js +403 -328
  23. package/dist/effectStore.js +2 -2
  24. package/dist/engineClients.js +24 -0
  25. package/dist/externalizedTasks.js +19 -6
  26. package/dist/fieldCipher.js +109 -40
  27. package/dist/fieldKeyRegistry.js +295 -0
  28. package/dist/fieldKeyRekey.js +286 -0
  29. package/dist/fieldKeyScan.js +136 -0
  30. package/dist/fieldKeyring.js +77 -0
  31. package/dist/hot.d.ts +56 -0
  32. package/dist/hot.js +3 -0
  33. package/dist/hotDataStore.js +148 -0
  34. package/dist/hotDataStoreSnapshot.js +98 -0
  35. package/dist/hotDataStoreTables.js +18 -0
  36. package/dist/http-range.d.ts +53 -0
  37. package/dist/http-range.js +52 -0
  38. package/dist/httpClientSsrf.js +12 -37
  39. package/dist/httpClientTracing.js +12 -9
  40. package/dist/httpCompression.js +17 -17
  41. package/dist/httpInputStream.js +82 -0
  42. package/dist/httpRouteMounts.js +1 -0
  43. package/dist/idempotencyStore.js +92 -52
  44. package/dist/index.d.ts +1164 -451
  45. package/dist/index.js +143 -132
  46. package/dist/kvFacade.js +23 -17
  47. package/dist/memoryQueryJoins.js +16 -16
  48. package/dist/memorySetOperations.js +43 -0
  49. package/dist/metrics.js +38 -24
  50. package/dist/outbox.js +1 -1
  51. package/dist/readRecorder.js +35 -34
  52. package/dist/readScopePredicate.js +12 -0
  53. package/dist/replicatedDataStore.js +22 -4
  54. package/dist/rowFilter.js +56 -39
  55. package/dist/rpcConnections.js +8 -8
  56. package/dist/rpcServer.js +522 -449
  57. package/dist/rpcWorkloadAdmission.js +50 -0
  58. package/dist/rywPositionStore.js +82 -47
  59. package/dist/scheduler.js +6 -1
  60. package/dist/servePipeline.js +215 -146
  61. package/dist/setReadScopes.js +28 -0
  62. package/dist/snapshotValueCodec.js +46 -0
  63. package/dist/sourceResolution.js +34 -24
  64. package/dist/storeMiddleware.js +211 -209
  65. package/dist/subscriber.js +1 -0
  66. package/dist/tenantScope.js +8 -20
  67. package/dist/traceparent.js +8 -19
  68. package/dist/webSocketGatewayRuntime.js +111 -71
  69. package/dist/workflowRuntime.js +9 -9
  70. package/package.json +19 -7
package/dist/rpcServer.js CHANGED
@@ -1,42 +1,45 @@
1
1
  import { crdtFoldCell as e, crdtIncrementalCell as t } from "./crdtMerge.js";
2
- import { makeDefaultRefilter as n, rowFilterMayNarrow as r } from "./rowFilter.js";
3
- import { buildSubjectKey as i } from "./rywPositionStore.js";
4
- import { runWithRoutingContext as a, runWithRoutingContextEffect as o } from "./replicatedDataStore.js";
5
- import { applyKeepAlive as s, resolveKeepAlive as c } from "./httpKeepAlive.js";
6
- import { rpcFrameDefects as l } from "./rpcDefectDiagnostics.js";
7
- import { makeHttpRouteGroupFinder as u, makeUnmatchedGroupFinder as d, planHttpRouteMounts as f } from "./httpRouteMounts.js";
8
- import { isComputedQuery as p } from "./computedQuery.js";
9
- import { registerConnectionStream as m } from "./connectionCredentials.js";
10
- import { getRpcConnection as h, withRpcClientAddress as g, withRpcConnectionIdentity as _ } from "./rpcConnections.js";
11
- import { makeSubscriptionOutbox as v, pumpOutbox as y, reactiveSocketTunables as b } from "./subscriptionOutbox.js";
12
- import { adoptDetached as x, canonicalInputKey as S, detachForResume as C, recordForResume as w } from "./subscriptionResume.js";
13
- import { externalSpanFromTraceparent as ee, newTraceId as T, parseTraceparent as E } from "./traceparent.js";
14
- import { runWithTraceContext as D } from "./traceContext.js";
15
- import { runWithObservedProcedure as O } from "./observedGraph.js";
16
- import { actingUserId as k } from "./storeMiddleware.js";
17
- import { readCappedBody as A, withBufferedBody as te } from "./rpcBodyCap.js";
18
- import { maybeCompress as ne, mergeCompressionHeaders as re } from "./httpCompression.js";
19
- import { runWebSocketGateway as ie } from "./webSocketGatewayRuntime.js";
20
- import { noteResumeVerdict as ae } from "./resumeCensus.js";
21
- import { publishServerTracerLayer as oe } from "./serverTracer.js";
22
- import { boundByCredential as j } from "./credentialBound.js";
23
- import { classifyRequestOrigin as se, isStateChangingMethod as ce, makeOriginGuardExemption as le, resolveOriginGuardConfig as ue } from "./originGuard.js";
24
- import { resolveRequestClientAddress as de, resolveRequestIsHttps as fe, resolveTrustedProxies as pe } from "./trustedProxy.js";
25
- import { resolveSecurityHeaders as me, securityHeadersFor as he } from "./securityHeaders.js";
26
- import { assertWebhookRoutesDeclareVerification as ge } from "./webhookVerification.js";
27
- import { Cause as M, Context as _e, Deferred as N, Effect as P, Fiber as ve, Layer as F, Queue as I, Schema as L, Stream as R } from "effect";
28
- import { extractDbCause as ye, hasEagerLoads as be, runWithWriteAttribution as z } from "@voltro/database";
29
- import { randomUUID as xe } from "node:crypto";
30
- import { ConnectionInfo as B, MUTATION_IN_FLIGHT_RETRY_AFTER_MS as Se, MutationConnectionRequired as Ce, MutationInFlight as we, SubjectService as V, Unauthenticated as Te, beginIdempotent as Ee, defineWebSocket as De, failIdempotent as Oe, finishIdempotent as ke, groupShapeDigests as Ae, holdIdempotentClaim as je, recheckGuardsEffect as Me, wsMutationIdempotencyScope as Ne } from "@voltro/protocol";
31
- import { LoggerLayer as Pe, createLogger as H } from "@voltro/logger";
32
- import { Server as Fe, createServer as Ie } from "node:http";
33
- import { HttpRouter as U, HttpServer as Le, HttpServerError as Re, HttpServerRequest as W, HttpServerResponse as G } from "effect/http";
34
- import { NodeHttpServer as ze, NodeHttpServerRequest as Be, NodeServices as Ve } from "@effect/platform-node";
35
- import { RpcSerialization as He, RpcServer as K } from "effect/rpc";
36
- import { dispatchSharedPath as Ue, restCorsHeaders as We, restCorsPreflight as Ge, routeAcceptsPath as Ke } from "@voltro/protocol/rest";
37
- import { instanceId as qe, replicaId as Je } from "@voltro/protocol/identity";
2
+ import { resolveDependentTables as n } from "./dependencyGraph.js";
3
+ import { buildSubjectKey as r } from "./rywPositionStore.js";
4
+ import { runWithRoutingContext as i, runWithRoutingContextEffect as a } from "./replicatedDataStore.js";
5
+ import { makeDefaultRefilter as o, rowFilterMayNarrow as s } from "./rowFilter.js";
6
+ import { captureRpcWorkloadAdmission as c, selectRpcWorkloadGroup as l } from "./rpcWorkloadAdmission.js";
7
+ import { applyKeepAlive as u, resolveKeepAlive as d } from "./httpKeepAlive.js";
8
+ import { rpcFrameDefects as f } from "./rpcDefectDiagnostics.js";
9
+ import { makeHttpRouteGroupFinder as p, makeUnmatchedGroupFinder as m, planHttpRouteMounts as h } from "./httpRouteMounts.js";
10
+ import { isComputedQuery as g } from "./computedQuery.js";
11
+ import { registerConnectionStream as _ } from "./connectionCredentials.js";
12
+ import { getRpcConnection as v, withRpcClientAddress as y, withRpcConnectionIdentity as b } from "./rpcConnections.js";
13
+ import { makeSubscriptionOutbox as x, pumpOutbox as S, reactiveSocketTunables as C } from "./subscriptionOutbox.js";
14
+ import { adoptDetached as ee, canonicalInputKey as te, detachForResume as ne, recordForResume as re } from "./subscriptionResume.js";
15
+ import { externalSpanFromTraceparent as ie, newTraceId as w, parseTraceparent as T } from "./traceparent.js";
16
+ import { runWithTraceContext as E } from "./traceContext.js";
17
+ import { runWithObservedProcedure as D } from "./observedGraph.js";
18
+ import { actingUserId as O } from "./storeMiddleware.js";
19
+ import { readCappedBody as ae, withBufferedBody as oe } from "./rpcBodyCap.js";
20
+ import { dispatchHttpInputStream as se } from "./httpInputStream.js";
21
+ import { maybeCompress as ce, mergeCompressionHeaders as le } from "./httpCompression.js";
22
+ import { runWebSocketGateway as ue } from "./webSocketGatewayRuntime.js";
23
+ import { noteResumeVerdict as de } from "./resumeCensus.js";
24
+ import { publishServerTracerLayer as fe } from "./serverTracer.js";
25
+ import { boundByCredential as pe } from "./credentialBound.js";
26
+ import { classifyRequestOrigin as me, isStateChangingMethod as he, makeOriginGuardExemption as ge, resolveOriginGuardConfig as _e } from "./originGuard.js";
27
+ import { resolveRequestClientAddress as ve, resolveRequestIsHttps as ye, resolveTrustedProxies as be } from "./trustedProxy.js";
28
+ import { resolveSecurityHeaders as xe, securityHeadersFor as Se } from "./securityHeaders.js";
29
+ import { assertWebhookRoutesDeclareVerification as Ce } from "./webhookVerification.js";
30
+ import { Cause as k, Context as we, Deferred as A, Effect as j, Fiber as Te, Layer as M, Queue as N, Schema as P, Stream as F } from "effect";
31
+ import { extractDbCause as Ee, hasEagerLoads as I, runWithWriteAttribution as L } from "@voltro/database";
32
+ import { randomUUID as De } from "node:crypto";
33
+ import { ConnectionInfo as R, MUTATION_IN_FLIGHT_RETRY_AFTER_MS as Oe, MutationConnectionRequired as z, MutationIdempotencyRefused as ke, MutationInFlight as Ae, SubjectService as je, Unauthenticated as Me, beginIdempotent as Ne, currentSubjectAuthority as Pe, defineWebSocket as Fe, failIdempotent as Ie, finishIdempotent as Le, groupShapeDigests as Re, holdIdempotentClaim as ze, prepareIdempotentInput as Be, recheckGuardsEffect as Ve, validateHttpStreamMaxDuration as He, wsMutationIdempotencyScope as Ue } from "@voltro/protocol";
34
+ import { LoggerLayer as We, createLogger as B } from "@voltro/logger";
35
+ import { RpcSerialization as Ge, RpcServer as V } from "effect/rpc";
36
+ import { Server as Ke, createServer as qe } from "node:http";
37
+ import { HttpRouter as H, HttpServer as Je, HttpServerError as Ye, HttpServerRequest as U, HttpServerResponse as W } from "effect/http";
38
+ import { NodeHttpServer as Xe, NodeHttpServerRequest as Ze, NodeServices as Qe } from "@effect/platform-node";
39
+ import { dispatchSharedPath as $e, restCorsHeaders as et, restCorsPreflight as tt, routeAcceptsPath as nt } from "@voltro/protocol/rest";
40
+ import { instanceId as rt, replicaId as it } from "@voltro/protocol/identity";
38
41
  //#region src/rpcServer.ts
39
- var q = (e) => {
42
+ var at = (e) => {
40
43
  let t = e.indexOf(".");
41
44
  if (t <= 0) return;
42
45
  let n = e.slice(0, t), r = e.slice(t + 1);
@@ -50,137 +53,134 @@ var q = (e) => {
50
53
  kind: n
51
54
  };
52
55
  }
53
- }, J = (e, t) => {
54
- let n = q(e);
55
- return n === void 0 ? t() : O(n, t);
56
- }, Ye = (e, t, n, r) => e === "subject" ? `${t}:s:${n}` : e === "global" ? `${t}:global` : r.tenantId == null ? void 0 : `${t}:t:${r.tenantId}`, Xe = Pe({}), Ze = (e, t) => P.callback((n) => {
57
- let r = z(t, () => P.runFork(e.pipe(P.provide(Xe))));
56
+ }, G = (e, t) => {
57
+ let n = at(e);
58
+ return n === void 0 ? t() : D(n, t);
59
+ }, ot = (e, t, n, r) => e === "subject" ? `${t}:s:${n}` : e === "global" ? `${t}:global` : r.tenantId == null ? void 0 : `${t}:t:${r.tenantId}`, st = We({}), K = (e, t) => j.callback((n) => {
60
+ let r = L(t, () => j.runFork(e.pipe(j.provide(st))));
58
61
  return r.addObserver((e) => {
59
62
  n(e);
60
- }), P.asVoid(ve.interrupt(r));
61
- }), Y = (e, t, n) => {
62
- let r = n === void 0 ? void 0 : h(n);
63
+ }), j.asVoid(Te.interrupt(r));
64
+ }), ct = (e, t, n, r) => {
65
+ let i = n === void 0 ? void 0 : v(n);
63
66
  return {
64
67
  subject: e,
65
- traceId: t?.traceId ?? T(),
68
+ traceId: t?.traceId ?? w(),
69
+ ...r === void 0 ? {} : { cookieHeader: r },
66
70
  ...t?.spanId === void 0 ? {} : { spanId: t.spanId },
67
71
  ...n === void 0 ? {} : { clientId: n },
68
- ...r === void 0 ? {} : { connection: r },
69
- ...r?.remoteAddr === void 0 ? {} : { remoteAddr: r.remoteAddr }
72
+ ...i === void 0 ? {} : { connection: i },
73
+ ...i?.remoteAddr === void 0 ? {} : { remoteAddr: i.remoteAddr }
70
74
  };
71
- }, Qe = P.currentSpan.pipe(P.catch(() => P.succeed(void 0))), $e = (e) => ({
75
+ }, lt = j.currentSpan.pipe(j.catch(() => j.succeed(void 0))), ut = (e) => ({
72
76
  traceId: e.traceId,
73
77
  ...e.spanId === void 0 ? {} : { spanId: e.spanId }
74
- }), et = (e, t, n) => {
78
+ }), dt = (e, t, n) => {
75
79
  e !== void 0 && (e.attribute("rpc.tag", t), e.attribute("subject.type", n.type), n.tenantId !== void 0 && n.tenantId !== null && e.attribute("tenant.id", n.tenantId));
76
- }, tt = (e) => n(e, (e) => {
77
- Q.error("row filter failed to load — subscription", {}, e instanceof Error ? e : Error(String(e)));
78
- }), X = (e) => ({
79
- single: (t) => P.runPromise(I.offer(e, t)),
80
- end: () => I.endUnsafe(e)
81
- }), nt = (n, i, a, o, s, c, l, u, d, f) => R.callback((p) => P.gen(function* () {
82
- let h = d ?? b(), g = i.crdtColumnsFor(n.table), _ = v({
80
+ }, ft = (e) => o(e, (e) => {
81
+ J.error("row filter failed to load — subscription", {}, e instanceof Error ? e : Error(String(e)));
82
+ }), q = (e) => ({
83
+ single: (t) => j.runPromise(N.offer(e, t)),
84
+ end: () => N.endUnsafe(e)
85
+ }), pt = (r, i, a, o, c, l, u, d, f, p) => F.callback((m) => j.gen(function* () {
86
+ let h = f ?? C(), g = i.crdtColumnsFor(r.table), v = x({
83
87
  maxBufferedBytes: h.maxBufferedBytes,
84
88
  overrunAfterMs: h.overrunAfterMs,
85
89
  oversizedEventBytes: h.oversizedEventBytes,
86
- label: s,
90
+ label: c,
87
91
  ...g.size > 0 ? { crdt: {
88
92
  columns: g,
89
93
  merge: e,
90
94
  incremental: t
91
95
  } } : {}
92
96
  });
93
- yield* P.addFinalizer(() => P.sync(() => _.close()));
94
- let ee = u !== void 0 && (be(n) || r([n.table])), T = f !== void 0 && !ee, E = T ? S(f.input) : "unused", D = T && E !== "uncanonical" ? {
95
- label: s,
96
- inputKey: E,
97
+ yield* j.addFinalizer(() => j.sync(() => v.close()));
98
+ let y = s([...n(r)]), b = d !== void 0 && (I(r) || y), ie = p !== void 0 && !b, w = ie ? te(p.input) : "unused", T = ie && w !== "uncanonical" ? {
99
+ label: c,
100
+ inputKey: w,
97
101
  subjectId: a.subject.id ?? "anonymous",
98
102
  tenantId: a.subject.tenantId ?? ""
99
103
  } : void 0;
100
- ae(s, f === void 0 ? "not-offered" : ee ? r([n.table]) ? "row-filter" : "eager-load" : E !== "uncanonical" || "uncanonical-input");
101
- let O = { current: (e) => {
102
- D !== void 0 && w(D, e), _.push(e);
104
+ de(c, p === void 0 ? "not-offered" : b ? y ? "row-filter" : "eager-load" : w !== "uncanonical" || "uncanonical-input");
105
+ let E = { current: (e) => {
106
+ T !== void 0 && re(T, e), v.push(e);
103
107
  } };
104
- if (D !== void 0 && f?.fromRevision !== void 0 && f.reconcile === void 0) {
105
- let e = l !== void 0 && (yield* P.tryPromise(() => l()).pipe(P.match({
108
+ if (T !== void 0 && p?.fromRevision !== void 0 && p.reconcile === void 0) {
109
+ let e = u !== void 0 && (yield* j.tryPromise(() => u()).pipe(j.match({
106
110
  onFailure: () => !0,
107
111
  onSuccess: (e) => !!e
108
- }))) ? void 0 : x(D, f.fromRevision);
112
+ }))) ? void 0 : ee(T, p.fromRevision);
109
113
  if (e !== void 0) {
110
- for (let t of e.deltas) _.push({
114
+ for (let t of e.deltas) v.push({
111
115
  _tag: "delta",
112
116
  revision: t.revision,
113
117
  emittedAt: t.emittedAt,
114
118
  patch: t.patch
115
119
  });
116
- e.sink.current = O.current;
120
+ e.sink.current = E.current;
117
121
  let t = e.unsubscribe;
118
- if (yield* P.addFinalizer(() => P.sync(() => {
119
- e.sink.current = () => {}, C(D, {
122
+ if (yield* j.addFinalizer(() => j.sync(() => {
123
+ e.sink.current = () => {}, ne(T, {
120
124
  sink: e.sink,
121
125
  unsubscribe: t
122
126
  });
123
- })), yield* P.forkScoped(P.promise(() => y(_, X(p), s))), a.clientId !== void 0) {
124
- let e = m(a.clientId, () => {
125
- I.endUnsafe(p);
127
+ })), yield* j.forkScoped(j.promise(() => S(v, q(m), c))), a.clientId !== void 0) {
128
+ let e = _(a.clientId, () => {
129
+ N.endUnsafe(m);
126
130
  });
127
- yield* P.addFinalizer(() => P.sync(() => e()));
131
+ yield* j.addFinalizer(() => j.sync(() => e()));
128
132
  }
129
133
  return;
130
134
  }
131
135
  }
132
- let k = yield* P.tryPromise(() => i.subscribe(n, (e) => {
133
- O.current(e);
134
- }, a, o, s, f?.reconcile === void 0 ? c : void 0, l, u, f?.reconcile !== void 0)).pipe(P.matchCause({
135
- onFailure: (e) => (pt(`subscription.${s}`, a.traceId, e), {
136
+ let D = yield* j.tryPromise(() => i.subscribe(r, (e) => {
137
+ E.current(e);
138
+ }, a, o, c, p?.reconcile === void 0 ? l : void 0, u, d, p?.reconcile !== void 0)).pipe(j.matchCause({
139
+ onFailure: (e) => (X(`subscription.${c}`, a.traceId, e), {
136
140
  ok: !1,
137
- error: bt(e)
141
+ error: Tt(e)
138
142
  }),
139
143
  onSuccess: (e) => ({
140
144
  ok: !0,
141
145
  unsubscribe: e
142
146
  })
143
147
  }));
144
- if (!k.ok) {
145
- I.offerUnsafe(p, {
148
+ if (!D.ok) {
149
+ N.offerUnsafe(m, {
146
150
  _tag: "error",
147
- error: k.error
148
- }), I.endUnsafe(p);
151
+ error: D.error
152
+ }), N.endUnsafe(m);
149
153
  return;
150
154
  }
151
- let A = k.unsubscribe;
152
- if (yield* P.addFinalizer(() => P.sync(() => {
153
- D === void 0 ? A() : (O.current = () => {}, C(D, {
154
- sink: O,
155
- unsubscribe: A
155
+ let O = D.unsubscribe;
156
+ if (yield* j.addFinalizer(() => j.sync(() => {
157
+ T === void 0 ? O() : (E.current = () => {}, ne(T, {
158
+ sink: E,
159
+ unsubscribe: O
156
160
  }));
157
- })), yield* P.forkScoped(P.promise(() => y(_, X(p), s))), a.clientId !== void 0) {
158
- let e = m(a.clientId, () => {
159
- I.endUnsafe(p);
161
+ })), yield* j.forkScoped(j.promise(() => S(v, q(m), c))), a.clientId !== void 0) {
162
+ let e = _(a.clientId, () => {
163
+ N.endUnsafe(m);
160
164
  });
161
- yield* P.addFinalizer(() => P.sync(() => e()));
165
+ yield* j.addFinalizer(() => j.sync(() => e()));
162
166
  }
163
- }), { bufferSize: 1 }), rt = /* @__PURE__ */ new Set(), it = () => {
164
- rt.clear();
165
- }, at = (e) => {
166
- rt.has(e) || (rt.add(e), ft.warn(`${e}: \`cache:\` is declared but NOT applied — this query's handler returns a computed value, and the snapshot cache only wraps a store read. Every subscriber re-runs the handler. Either return a query descriptor (so the read can be cached), or drop \`cache:\` so the declaration matches what happens.`, { label: e }));
167
- }, ot = (e, t, n, r, i) => R.callback((a) => P.gen(function* () {
168
- let o = i ?? b(), s = v({
167
+ }), { bufferSize: 1 }), mt = (e, t, n, r, i) => F.callback((a) => j.gen(function* () {
168
+ let o = i ?? C(), s = x({
169
169
  maxBufferedBytes: o.maxBufferedBytes,
170
170
  overrunAfterMs: o.overrunAfterMs,
171
171
  oversizedEventBytes: o.oversizedEventBytes,
172
172
  label: r
173
173
  });
174
- yield* P.addFinalizer(() => P.sync(() => s.close()));
175
- let c = yield* P.tryPromise(() => t.subscribeComputed(e, (e) => {
174
+ yield* j.addFinalizer(() => j.sync(() => s.close()));
175
+ let c = yield* j.tryPromise(() => t.subscribeComputed(e, (e) => {
176
176
  s.push(e._tag === "snapshot" ? {
177
177
  ...e,
178
178
  computed: !0
179
179
  } : e);
180
- }, n, r)).pipe(P.matchCause({
181
- onFailure: (e) => (pt(`subscription.${r}`, n.traceId, e), {
180
+ }, n, r)).pipe(j.matchCause({
181
+ onFailure: (e) => (X(`subscription.${r}`, n.traceId, e), {
182
182
  ok: !1,
183
- error: bt(e)
183
+ error: Tt(e)
184
184
  }),
185
185
  onSuccess: (e) => ({
186
186
  ok: !0,
@@ -188,38 +188,38 @@ var q = (e) => {
188
188
  })
189
189
  }));
190
190
  if (!c.ok) {
191
- I.offerUnsafe(a, {
191
+ N.offerUnsafe(a, {
192
192
  _tag: "error",
193
193
  error: c.error
194
- }), I.endUnsafe(a);
194
+ }), N.endUnsafe(a);
195
195
  return;
196
196
  }
197
197
  let l = c.unsubscribe;
198
- if (ae(r, "computed"), yield* P.addFinalizer(() => P.sync(() => l())), yield* P.forkScoped(P.promise(() => y(s, X(a), r))), n.clientId !== void 0) {
199
- let e = m(n.clientId, () => {
200
- I.endUnsafe(a);
198
+ if (de(r, "computed"), yield* j.addFinalizer(() => j.sync(() => l())), yield* j.forkScoped(j.promise(() => S(s, q(a), r))), n.clientId !== void 0) {
199
+ let e = _(n.clientId, () => {
200
+ N.endUnsafe(a);
201
201
  });
202
- yield* P.addFinalizer(() => P.sync(() => e()));
202
+ yield* j.addFinalizer(() => j.sync(() => e()));
203
203
  }
204
- }), { bufferSize: 1 }), st = (e, t, n = "rpc.subscription", r, s, c, l) => R.unwrap(P.gen(function* () {
205
- let u = yield* V, d = yield* B, f = (e) => {
206
- let t = R.make({
204
+ }), { bufferSize: 1 }), ht = (e, t, n = "rpc.subscription", o, s, c, l) => F.unwrap(j.gen(function* () {
205
+ let u = yield* je, d = yield* R, f = (e) => {
206
+ let t = F.make({
207
207
  _tag: "error",
208
- error: new Te({ reason: "The session has expired. Sign in again." })
208
+ error: new Me({ reason: "The session has expired. Sign in again." })
209
209
  });
210
- return j(e, d.credentialExpiresAt, t, t);
211
- }, m = yield* Qe;
212
- et(m, n, u);
213
- let h = Y(u, m, d.clientId), g = i(u.id, d.clientId), _ = {
214
- subjectKey: g,
210
+ return pe(e, d.credentialExpiresAt, t, t);
211
+ }, p = yield* lt;
212
+ dt(p, n, u);
213
+ let m = ct(u, p, d.clientId, d.cookieHeader), h = r(u.id, d.clientId), _ = {
214
+ subjectKey: h,
215
215
  ...d.reconcile === void 0 ? {} : { forcePrimary: !0 }
216
- }, v = a(_, () => D({
217
- traceId: h.traceId,
218
- ...h.spanId === void 0 ? {} : { spanId: h.spanId }
219
- }, () => J(n, () => e(h)))), y = P.isEffect(v) ? yield* o(_, v).pipe(P.matchCause({
220
- onFailure: (e) => (pt(`subscription.${n}`, h.traceId, e), {
216
+ }, v = i(_, () => E({
217
+ traceId: m.traceId,
218
+ ...m.spanId === void 0 ? {} : { spanId: m.spanId }
219
+ }, () => G(n, () => e(m)))), y = j.isEffect(v) ? yield* a(_, v).pipe(j.matchCause({
220
+ onFailure: (e) => (X(`subscription.${n}`, m.traceId, e), {
221
221
  ok: !1,
222
- error: bt(e)
222
+ error: Tt(e)
223
223
  }),
224
224
  onSuccess: (e) => ({
225
225
  ok: !0,
@@ -229,43 +229,55 @@ var q = (e) => {
229
229
  ok: !0,
230
230
  value: v
231
231
  };
232
- if (!y.ok) return R.make({
232
+ if (!y.ok) return F.make({
233
233
  _tag: "error",
234
234
  error: y.error
235
235
  });
236
236
  let b = y.value;
237
- if (p(b)) return s !== void 0 && at(n), f(Z(ot(d.reconcile === void 0 ? b : {
237
+ if (g(b)) return f(gt(mt(d.reconcile === void 0 ? b : {
238
238
  ...b,
239
- recompute: () => a(_, b.recompute)
240
- }, t, h, n), d.reconcile));
241
- let x = b, S = r?.(x), C = s === void 0 ? void 0 : Ye(s.scope, s.baseKey, g, u);
242
- return f(Z(nt(x, t, h, S, n, s === void 0 || C === void 0 ? void 0 : {
239
+ recompute: () => i(_, b.recompute)
240
+ }, t, m, n), d.reconcile));
241
+ let x = b, S = o?.(x), C = s === void 0 ? void 0 : ot(s.scope, s.baseKey, h, u);
242
+ return f(gt(pt(x, t, m, S, n, s === void 0 || C === void 0 ? void 0 : {
243
243
  key: C,
244
244
  ttlMs: s.ttlMs,
245
- swrMs: s.swrMs
246
- }, c?.(u), l?.(u) ?? tt(u), void 0, {
245
+ swrMs: s.swrMs,
246
+ label: n.replace(/^subscription\./, "")
247
+ }, c?.(u), l?.(u) ?? ft(u), void 0, {
247
248
  input: x,
248
249
  ...d.resumeFrom === void 0 ? {} : { fromRevision: d.resumeFrom },
249
250
  ...d.reconcile === void 0 ? {} : { reconcile: d.reconcile }
250
251
  }), d.reconcile));
251
- }).pipe(P.withSpan(n, { attributes: { "framework.kind": "subscription" } }))), Z = (e, t) => t === void 0 ? e : e.pipe(R.mapAccum(() => !1, (e, n) => !e && n._tag === "snapshot" ? [!0, [{
252
+ }).pipe(j.withSpan(n, { attributes: { "framework.kind": "subscription" } }))), gt = (e, t) => t === void 0 ? e : e.pipe(F.mapAccum(() => !1, (e, n) => !e && n._tag === "snapshot" ? [!0, [{
252
253
  ...n,
253
254
  reconciles: t
254
- }]] : [e, [n]])), ct = (e, t = "rpc.stream", n, r) => R.unwrap(P.gen(function* () {
255
- let i = yield* V, a = yield* B, o = yield* Qe;
256
- et(o, t, i);
257
- let s = Y(i, o, a.clientId), c = n ?? [], l = () => Me(i, c, r), u = yield* l();
258
- if (u) return R.fail(u);
259
- let d = J(t, () => e(s)), f = P.isEffect(d) ? yield* d.pipe(P.orDie) : d, p = R.flatMap(f, (e) => R.unwrap(l().pipe(P.map((t) => t ? R.fail(t) : R.make(e))))), h = j(p, a.credentialExpiresAt, R.empty);
260
- if (s.clientId === void 0) return h;
261
- let g = s.clientId;
262
- return R.unwrap(P.gen(function* () {
263
- let e = yield* N.make(), t = m(g, () => {
264
- N.doneUnsafe(e, P.void);
255
+ }]] : [e, [n]])), _t = (e, t = "rpc.stream", n, r, i) => F.unwrap(j.gen(function* () {
256
+ let a = yield* je, o = yield* R, s = yield* lt;
257
+ dt(s, t, a);
258
+ let c = ct(a, s, o.clientId, o.cookieHeader), l = n ?? [], u = () => Ve(a, l, r), d = j.gen(function* () {
259
+ let n = yield* u();
260
+ if (n) return yield* j.fail(n);
261
+ let r = G(t, () => e(c));
262
+ return j.isEffect(r) ? yield* r : r;
263
+ }), f = yield* (i?.interceptor ? i.interceptor(d, {
264
+ tag: i.tag,
265
+ kind: "stream",
266
+ input: r,
267
+ subject: a,
268
+ traceId: c.traceId,
269
+ ...c.spanId === void 0 ? {} : { spanId: c.spanId },
270
+ ...c.remoteAddr === void 0 ? {} : { remoteAddr: c.remoteAddr }
271
+ }) : d).pipe(j.catchCause((e) => j.succeed(F.failCause(e)))), p = F.flatMap(f, (e) => F.unwrap(u().pipe(j.map((t) => t ? F.fail(t) : F.make(e))))), m = pe(p, o.credentialExpiresAt, F.empty);
272
+ if (c.clientId === void 0) return m;
273
+ let h = c.clientId;
274
+ return F.unwrap(j.gen(function* () {
275
+ let e = yield* A.make(), t = _(h, () => {
276
+ A.doneUnsafe(e, j.void);
265
277
  });
266
- return yield* P.addFinalizer(() => P.sync(() => t())), h.pipe(R.interruptWhen(N.await(e)));
278
+ return yield* j.addFinalizer(() => j.sync(() => t())), m.pipe(F.interruptWhen(A.await(e)));
267
279
  }));
268
- }).pipe(P.withSpan(t, { attributes: { "framework.kind": "stream" } }))), Q = H({ scope: "voltro:rpc" }), lt = H({ scope: "voltro:http" }), ut = H({ scope: "voltro:shutdown" }), dt = (e) => {
280
+ }).pipe(j.withSpan(t, { attributes: { "framework.kind": "stream" } }))), J = B({ scope: "voltro:rpc" }), vt = B({ scope: "voltro:http" }), Y = B({ scope: "voltro:shutdown" }), yt = (e) => {
269
281
  if (e instanceof Error) {
270
282
  let t = e._tag;
271
283
  return {
@@ -283,40 +295,40 @@ var q = (e) => {
283
295
  };
284
296
  }
285
297
  return { value: String(e).slice(0, 300) };
286
- }, ft = H({ scope: "voltro:rpc" }), pt = (e, t, n) => {
287
- if (M.hasInterruptsOnly(n)) return;
288
- let r = M.squash(n), i = r?._tag, a = r instanceof Error ? r.message : r?.message ?? String(r), o = M.hasDies(n), s = ye(r), c = {
298
+ }, X = (e, t, n) => {
299
+ if (k.hasInterruptsOnly(n)) return;
300
+ let r = k.squash(n), i = r?._tag, a = r instanceof Error ? r.message : r?.message ?? String(r), o = k.hasDies(n), s = Ee(r), c = {
289
301
  traceId: t,
290
302
  ...i === void 0 ? {} : { errorTag: i },
291
303
  ...s
292
304
  }, l = a === "Failed to execute statement" && typeof s.dbMessage == "string" ? s.dbMessage : a;
293
- o ? Q.error(`${e} failed: ${l}`, c) : Q.warn(`${e} failed: ${l}`, c);
294
- }, mt = /* @__PURE__ */ new Set([
305
+ o ? J.error(`${e} failed: ${l}`, c) : J.warn(`${e} failed: ${l}`, c);
306
+ }, bt = /* @__PURE__ */ new Set([
295
307
  "SqlError",
296
308
  "ResultLengthMismatch",
297
309
  "FieldDecryptionError"
298
- ]), ht = (e) => typeof e == "object" && !!e && typeof e._tag == "string" && mt.has(e._tag), gt = (e, t) => {
310
+ ]), Z = (e) => typeof e == "object" && !!e && typeof e._tag == "string" && bt.has(e._tag), xt = (e, t) => {
299
311
  try {
300
- return L.is(e)(t);
312
+ return P.is(e)(t);
301
313
  } catch {
302
314
  return !0;
303
315
  }
304
- }, _t = /* @__PURE__ */ new Set(), vt = (e, t) => {
316
+ }, St = /* @__PURE__ */ new Set(), Ct = (e, t) => {
305
317
  let n = `${e}\u0000${t}`;
306
- _t.has(n) || (_t.size >= 1e3 && _t.clear(), _t.add(n), Q.warn(`${e} failed with '${t}', which is undeclared on its wire union — the client received InternalError instead. Add ${t} to the descriptor's \`error:\`, register it app-wide through a plugin's \`errorSchemas\`, or map it to a declared error (\`Effect.orDie\` if it is a defect). \`defineExecutor\` reports this at compile time.`, {
318
+ St.has(n) || (St.size >= 1e3 && St.clear(), St.add(n), J.warn(`${e} failed with '${t}', which is undeclared on its wire union — the client received InternalError instead. Add ${t} to the descriptor's \`error:\`, register it app-wide through a plugin's \`errorSchemas\`, or map it to a declared error (\`Effect.orDie\` if it is a defect). \`defineExecutor\` reports this at compile time.`, {
307
319
  procedure: e,
308
320
  errorTag: t
309
321
  }));
310
- }, $ = (e, t = "internal server error") => ({
322
+ }, wt = (e, t = "internal server error") => ({
311
323
  _tag: "InternalError",
312
324
  message: t,
313
325
  traceId: e
314
- }), yt = (e) => {
326
+ }), Q = (e) => {
315
327
  let t = e instanceof Error ? e.message : e?.message, n = typeof t == "string" && t.length > 0 ? t : String(e), r = e?._tag, i = typeof r == "string" && r.length > 0 && !n.startsWith(r) ? `${r}: ${n}` : n;
316
328
  return i.length <= 500 ? i : `${i.slice(0, 500)}…`;
317
- }, bt = (e) => {
318
- let t = M.squash(e);
319
- if (t && typeof t == "object" && t._tag === "UnknownError" && (t = t.error ?? t.cause ?? t), ht(t)) return {
329
+ }, Tt = (e) => {
330
+ let t = k.squash(e);
331
+ if (t && typeof t == "object" && t._tag === "UnknownError" && (t = t.error ?? t.cause ?? t), Z(t)) return {
320
332
  _tag: "InternalError",
321
333
  message: "internal server error"
322
334
  };
@@ -328,96 +340,152 @@ var q = (e) => {
328
340
  ...typeof i == "string" ? { _tag: i } : {},
329
341
  message: typeof a == "string" ? a : String(t)
330
342
  };
331
- }, xt = (e) => {
332
- if (e === void 0) return;
333
- let t = L.encodeUnknownSync(e), n = L.decodeUnknownSync(e);
343
+ }, Et = (e, t, n) => {
344
+ let r = P.encodeUnknownSync(t), i = P.decodeUnknownSync(t);
334
345
  return {
346
+ input: e,
347
+ admit: n,
335
348
  encode: (e) => {
336
349
  try {
337
- return t(e);
350
+ return r(e);
338
351
  } catch {
339
- return e;
352
+ throw Error("Mutation output cannot be recorded for replay");
340
353
  }
341
354
  },
342
355
  decode: (e) => {
343
356
  try {
344
- return n(e);
357
+ return i(e);
345
358
  } catch {
346
- return e;
359
+ throw Error("Stored mutation response is incompatible with the current output contract");
347
360
  }
348
361
  }
349
362
  };
350
- }, St = (e) => {
363
+ }, Dt = (e) => {
351
364
  let t = {}, n;
352
365
  for (let [r, i] of Object.entries(e ?? {})) Array.isArray(i) ? r.toLowerCase() === "set-cookie" ? n = i : t[r] = i.join(", ") : t[r] = i;
353
366
  return {
354
367
  headers: t,
355
368
  setCookie: n
356
369
  };
357
- }, Ct = (e, t, n = "rpc.mutation", r, o, s, c = "subject") => P.gen(function* () {
358
- let l = yield* V, u = yield* B, d = yield* Qe;
359
- et(d, n, l);
360
- let f = Y(l, d, u.clientId), p = c === "connection";
361
- if (p && (f.connection?.transport !== "websocket" || f.connection.signal.aborted)) return yield* P.fail(new Ce({ traceId: f.traceId }));
362
- let m = o && u.idempotencyKey ? {
370
+ }, Ot = (e, t, n = "rpc.mutation", a, o, s, c = "subject") => j.gen(function* () {
371
+ let l = t, u = yield* je, d = yield* R, f = yield* lt;
372
+ dt(f, n, u);
373
+ let p = ct(u, f, d.clientId, d.cookieHeader), m = async () => {
374
+ if (typeof a?.admit != "function") throw Error("Missing current mutation admission");
375
+ await a.admit(l, p);
376
+ }, h = () => j.tryPromise({
377
+ try: m,
378
+ catch: (e) => e
379
+ }), g = c === "connection";
380
+ if (g && (p.connection?.transport !== "websocket" || p.connection.signal.aborted)) return yield* j.fail(new z({ traceId: p.traceId }));
381
+ let _ = o && d.idempotencyKey ? {
363
382
  store: o.store,
364
383
  ttlMs: o.ttlMs,
365
- key: u.idempotencyKey,
366
- scope: Ne(l.tenantId, k(l), n, p ? f.connection?.id : void 0)
367
- } : null, h = i(l.id, u.clientId), g = {
368
- traceId: f.traceId,
369
- subjectId: k(l),
384
+ key: d.idempotencyKey,
385
+ scope: Ue(u.tenantId, O(u), n, g ? p.connection?.id : void 0)
386
+ } : null, v = r(u.id, d.clientId), y = {
387
+ traceId: p.traceId,
388
+ subjectId: O(u),
370
389
  procedure: n
371
- }, _ = (r = (e) => e) => P.suspend(() => {
372
- let i = a({ subjectKey: h }, () => D({
373
- traceId: f.traceId,
374
- ...f.spanId === void 0 ? {} : { spanId: f.spanId }
375
- }, () => z(g, () => J(n, () => e(t, f)))));
376
- return P.isEffect(i) ? r(Ze(i, g)) : P.tryPromise({
377
- try: () => Promise.resolve(i),
390
+ }, b = (t = (e) => e) => j.suspend(() => {
391
+ let r = i({ subjectKey: v }, () => E({
392
+ traceId: p.traceId,
393
+ ...p.spanId === void 0 ? {} : { spanId: p.spanId }
394
+ }, () => L(y, () => G(n, () => e(l, {
395
+ ...p,
396
+ subject: Pe(u)
397
+ })))));
398
+ return j.isEffect(r) ? t(K(r, y)) : j.tryPromise({
399
+ try: () => Promise.resolve(r),
378
400
  catch: (e) => e
379
401
  });
380
- }), v = !1, y;
381
- return yield* (m ? P.acquireUseRelease(P.promise(async () => {
382
- let e = await Ee(m.store, m.scope, m.key, m.ttlMs, Date.now());
383
- return e.kind === "fresh" && (y = je(m.store, m.scope, m.key)), e;
384
- }), (e) => P.gen(function* () {
385
- return yield* P.yieldNow, p && f.connection?.signal.aborted ? yield* P.fail(new Ce({ traceId: f.traceId })) : e.kind === "replay" ? r ? r.decode(e.response.body) : e.response.body : e.kind === "conflict" ? yield* P.fail(new we({
386
- traceId: f.traceId,
387
- retryAfterMs: Se
388
- })) : yield* P.uninterruptibleMask((e) => e(P.void).pipe(P.flatMap(() => _(e)), P.tap((e) => (v = !0, P.promise(() => ke(m.store, m.scope, m.key, {
389
- status: 200,
390
- body: r ? r.encode(e) : e
391
- }, Date.now())).pipe(P.ignore)))));
392
- }), (e) => P.sync(() => y?.()).pipe(P.andThen(e.kind === "fresh" && !v ? P.promise(() => Oe(m.store, m.scope, m.key)).pipe(P.ignore) : P.void))) : _()).pipe(P.tapCause((e) => P.sync(() => pt(n, f.traceId, e))), P.catchIf(ht, () => P.die($(f.traceId))), P.catchIf((e) => e instanceof Error && typeof e._tag != "string", (e) => P.die($(f.traceId, yt(e)))), P.catchIf((e) => s !== void 0 && typeof e?._tag == "string" && !gt(s, e), (e) => P.sync(() => vt(n, e._tag)).pipe(P.andThen(P.die($(f.traceId, yt(e)))))), P.catchDefect((e) => e?._tag === "InternalError" ? P.die(e) : P.die($(f.traceId, yt(e)))), P.annotateLogs($e(f)));
393
- }).pipe(P.withSpan(n, { attributes: { "framework.kind": "mutation" } })), wt = 8388608, Tt = (e) => {
394
- let t = e.port ?? 4e3, n = e.host, r = e.path ?? "/ws", i = r, a = e.replicaId ?? Je();
395
- ge(e.webhookRoutes);
396
- let o = e.listener, p = o?.server ?? Ie(), m = /* @__PURE__ */ new Set();
397
- p.on("connection", (e) => {
398
- m.add(e), e.once("close", () => {
399
- m.delete(e);
402
+ }), x = !1, S;
403
+ return yield* (_ ? j.acquireUseRelease(j.tryPromise({
404
+ try: async () => {
405
+ let e;
406
+ try {
407
+ if (!a) throw Error("Missing declared mutation codec");
408
+ let n = await Be(a.input, t, u);
409
+ l = n.input, e = n.fingerprint;
410
+ } catch {
411
+ throw new ke({
412
+ traceId: p.traceId,
413
+ reason: "input-unavailable"
414
+ });
415
+ }
416
+ await m();
417
+ let n = await Ne(_.store, _.scope, _.key, e, _.ttlMs, Date.now());
418
+ return n.kind === "fresh" && (S = ze(_.store, n.claim)), n;
419
+ },
420
+ catch: (e) => e
421
+ }), (e) => j.gen(function* () {
422
+ if (yield* j.yieldNow, yield* h(), g && p.connection?.signal.aborted) return yield* j.fail(new z({ traceId: p.traceId }));
423
+ if (e.kind === "replay") {
424
+ if (e.response.status !== 200) throw Error("Stored mutation response is unavailable");
425
+ try {
426
+ return a ? a.decode(e.response.body) : e.response.body;
427
+ } catch {
428
+ throw Error("Stored mutation response is incompatible with the current output contract");
429
+ }
430
+ }
431
+ return e.kind === "input-conflict" || e.kind === "input-unbound" ? yield* j.fail(new ke({
432
+ traceId: p.traceId,
433
+ reason: e.kind
434
+ })) : e.kind === "conflict" ? yield* j.fail(new Ae({
435
+ traceId: p.traceId,
436
+ retryAfterMs: Oe
437
+ })) : yield* j.uninterruptibleMask((t) => t(j.void).pipe(j.flatMap(() => b(t)), j.tap((t) => {
438
+ x = !0;
439
+ let n;
440
+ try {
441
+ n = {
442
+ status: 200,
443
+ body: a ? a.encode(t) : t
444
+ };
445
+ } catch {
446
+ n = {
447
+ status: 500,
448
+ body: null
449
+ };
450
+ }
451
+ return j.promise(async () => {
452
+ try {
453
+ if (!await Le(_.store, e.claim, n, Date.now())) throw Error("Original mutation claim is no longer owned");
454
+ } catch {
455
+ throw Error("Mutation replay receipt could not be retained");
456
+ }
457
+ if (n.status !== 200) throw Error("Mutation output cannot be recorded for replay");
458
+ });
459
+ })));
460
+ }), (e) => j.sync(() => S?.()).pipe(j.andThen(e.kind === "fresh" && !x ? j.promise(() => Ie(_.store, e.claim)).pipe(j.ignore) : j.void))) : a ? h().pipe(j.flatMap(() => b())) : b()).pipe(j.tapCause((e) => j.sync(() => X(n, p.traceId, e))), j.catchIf(Z, () => j.die(wt(p.traceId))), j.catchIf((e) => e instanceof Error && typeof e._tag != "string", (e) => j.die(wt(p.traceId, Q(e)))), j.catchIf((e) => s !== void 0 && typeof e?._tag == "string" && !xt(s, e), (e) => j.sync(() => Ct(n, e._tag)).pipe(j.andThen(j.die(wt(p.traceId, Q(e)))))), j.catchDefect((e) => e?._tag === "InternalError" ? j.die(e) : j.die(wt(p.traceId, Q(e)))), j.annotateLogs(ut(p)));
461
+ }).pipe(j.withSpan(n, { attributes: { "framework.kind": "mutation" } })), kt = 8388608, At = (e) => {
462
+ let t = c(e.workloadAdmission), n = l(e.group, t, "http"), r = l(e.group, t, "websocket"), i = e.port ?? 4e3, a = e.host, o = e.path ?? "/ws", s = o, g = e.replicaId ?? it();
463
+ Ce(e.webhookRoutes);
464
+ let _ = e.listener, x = _?.server ?? qe(), S = /* @__PURE__ */ new Set();
465
+ x.on("connection", (e) => {
466
+ S.add(e), e.once("close", () => {
467
+ S.delete(e);
400
468
  });
401
- }), s(p, c(e));
402
- let v = (t) => W.HttpServerRequest.pipe(P.flatMap((t) => P.gen(function* () {
403
- if (!e.inspectRoute) return G.text("inspect route not configured", { status: 404 });
469
+ }), u(x, d(e));
470
+ let C = (t) => U.HttpServerRequest.pipe(j.flatMap((t) => j.gen(function* () {
471
+ if (!e.inspectRoute) return W.text("inspect route not configured", { status: 404 });
404
472
  let n = {};
405
473
  for (let [e, r] of Object.entries(t.headers)) r !== void 0 && (n[e.toLowerCase()] = Array.isArray(r) ? r.join(", ") : r);
406
474
  let r = e.inspectRoute, i = r.binary?.[new URL(t.url, "http://inspect.invalid").pathname], a;
407
- !i && t.method !== "GET" && t.method !== "HEAD" && t.method !== "OPTIONS" && (a = yield* t.text.pipe(P.orElseSucceed(() => "")));
408
- let o = yield* P.promise(async (e) => {
475
+ !i && t.method !== "GET" && t.method !== "HEAD" && t.method !== "OPTIONS" && (a = yield* t.text.pipe(j.orElseSucceed(() => "")));
476
+ let o = yield* j.promise(async (e) => {
409
477
  if (!i) return r.handle(t.url, n, t.method, a, e);
410
- let o = R.toReadableStream(t.stream);
478
+ let o = F.toReadableStream(t.stream);
411
479
  return i(t.url, n, t.method, o, e);
412
480
  });
413
- if (o === null) return G.text("inspect route not found", { status: 404 });
481
+ if (o === null) return W.text("inspect route not found", { status: 404 });
414
482
  if (o.byteStream !== void 0) {
415
483
  let e = {
416
484
  ...o.headers,
417
485
  ...o.byteStream.contentLength === void 0 ? {} : { "content-length": String(o.byteStream.contentLength) },
418
486
  ...o.byteStream.contentDisposition === void 0 ? {} : { "content-disposition": o.byteStream.contentDisposition }
419
487
  };
420
- if (t.method === "HEAD") return G.empty({
488
+ if (t.method === "HEAD") return W.empty({
421
489
  status: o.status,
422
490
  headers: {
423
491
  ...e,
@@ -425,7 +493,7 @@ var q = (e) => {
425
493
  }
426
494
  });
427
495
  let n = o.byteStream.stream;
428
- return G.stream(R.fromReadableStream({
496
+ return W.stream(F.fromReadableStream({
429
497
  evaluate: () => typeof n == "function" ? n() : n,
430
498
  onError: (e) => e
431
499
  }), {
@@ -434,25 +502,25 @@ var q = (e) => {
434
502
  headers: e
435
503
  });
436
504
  }
437
- return G.text(o.body, {
505
+ return W.text(o.body, {
438
506
  status: o.status,
439
507
  contentType: o.contentType,
440
508
  headers: o.headers ?? {}
441
509
  });
442
- }))), y = () => W.HttpServerRequest.pipe(P.flatMap((t) => {
510
+ }))), ee = () => U.HttpServerRequest.pipe(j.flatMap((t) => {
443
511
  let n = e.inspectStream;
444
- if (!n) return P.succeed(G.text("inspect stream not configured", { status: 404 }));
512
+ if (!n) return j.succeed(W.text("inspect stream not configured", { status: 404 }));
445
513
  let r = {};
446
514
  for (let [e, n] of Object.entries(t.headers)) n !== void 0 && (r[e.toLowerCase()] = Array.isArray(n) ? n.join(", ") : n);
447
515
  let i = n.corsHeaders(r.origin);
448
- if (n.isDisabled()) return P.succeed(G.text(JSON.stringify({ error: "inspect disabled (VOLTRO_INSPECT=off)" }), {
516
+ if (n.isDisabled()) return j.succeed(W.text(JSON.stringify({ error: "inspect disabled (VOLTRO_INSPECT=off)" }), {
449
517
  status: 503,
450
518
  contentType: "application/json; charset=utf-8",
451
519
  headers: i
452
520
  }));
453
521
  let a = n.authorize(r);
454
- return a.ok ? (n.select?.(t.url, r) ?? P.succeed(void 0)).pipe(P.flatMap((e) => {
455
- if (e?.kind === "stream") return P.succeed(G.stream(e.stream, {
522
+ return a.ok ? (n.select?.(t.url, r) ?? j.succeed(void 0)).pipe(j.flatMap((e) => {
523
+ if (e?.kind === "stream") return j.succeed(W.stream(e.stream, {
456
524
  status: 200,
457
525
  headers: {
458
526
  ...i,
@@ -461,7 +529,7 @@ var q = (e) => {
461
529
  "x-accel-buffering": "no"
462
530
  }
463
531
  }));
464
- if (e?.kind === "refused") return P.succeed(G.text(JSON.stringify(e.body), {
532
+ if (e?.kind === "refused") return j.succeed(W.text(JSON.stringify(e.body), {
465
533
  status: e.status,
466
534
  contentType: "application/json; charset=utf-8",
467
535
  headers: i
@@ -470,18 +538,18 @@ var q = (e) => {
470
538
  if (!u || e.indexOf("event: ") !== 0) return !0;
471
539
  let t = e.indexOf("\n", 7);
472
540
  return t < 0 || u.has(e.slice(7, t).trim());
473
- }, f = R.callback((e) => P.gen(function* () {
474
- if (I.offerUnsafe(e, r.encode("retry: 5000\n\n")), !c) for (let t of n.replay()) d(t) && I.offerUnsafe(e, r.encode(t));
541
+ }, f = F.callback((e) => j.gen(function* () {
542
+ if (N.offerUnsafe(e, r.encode("retry: 5000\n\n")), !c) for (let t of n.replay()) d(t) && N.offerUnsafe(e, r.encode(t));
475
543
  let t = n.subscribe((t) => {
476
- d(t) && I.offerUnsafe(e, r.encode(t));
544
+ d(t) && N.offerUnsafe(e, r.encode(t));
477
545
  }), i = setInterval(() => {
478
- I.offerUnsafe(e, r.encode(n.keepAlive()));
546
+ N.offerUnsafe(e, r.encode(n.keepAlive()));
479
547
  }, a);
480
- yield* P.addFinalizer(() => P.sync(() => {
548
+ yield* j.addFinalizer(() => j.sync(() => {
481
549
  clearInterval(i), t();
482
550
  }));
483
551
  }));
484
- return P.succeed(G.stream(f, {
552
+ return j.succeed(W.stream(f, {
485
553
  status: 200,
486
554
  headers: {
487
555
  "content-type": "text/event-stream; charset=utf-8",
@@ -492,7 +560,7 @@ var q = (e) => {
492
560
  ...i
493
561
  }
494
562
  }));
495
- })) : P.succeed(G.text(JSON.stringify({
563
+ })) : j.succeed(W.text(JSON.stringify({
496
564
  error: "unauthorized",
497
565
  reason: a.reason
498
566
  }), {
@@ -500,17 +568,17 @@ var q = (e) => {
500
568
  contentType: "application/json; charset=utf-8",
501
569
  headers: i
502
570
  }));
503
- })), b = v(!0), x = v(!1), S = U.add("*", "/_voltro/inspect/*", W.HttpServerRequest.pipe(P.flatMap((e) => e.url.split("?")[0] === "/_voltro/inspect" ? b : x))), C = F.empty;
504
- e.inspectRoute !== void 0 && (C = e.inspectStream === void 0 ? S : F.mergeAll(U.add("GET", "/_voltro/inspect/stream", y()), S));
505
- let w = e.publishSurfaceDigest === !0 ? Ae(e.group) : void 0, D = e.serviceSurfaceTags ?? /* @__PURE__ */ new Set(), O = (e) => {
506
- let t = Object.entries(w), n = 0;
507
- for (let r of t) (e ? D.has(r[0]) : !D.has(r[0])) && (t[n++] = r);
571
+ })), te = C(!0), ne = C(!1), re = H.add("*", "/_voltro/inspect/*", U.HttpServerRequest.pipe(j.flatMap((e) => e.url.split("?")[0] === "/_voltro/inspect" ? te : ne))), E = M.empty;
572
+ e.inspectRoute !== void 0 && (E = e.inspectStream === void 0 ? re : M.mergeAll(H.add("GET", "/_voltro/inspect/stream", ee()), re));
573
+ let D = e.publishSurfaceDigest === !0 ? Re(e.group) : void 0, O = e.serviceSurfaceTags ?? /* @__PURE__ */ new Set(), de = (e) => {
574
+ let t = Object.entries(D), n = 0;
575
+ for (let r of t) (e ? O.has(r[0]) : !O.has(r[0])) && (t[n++] = r);
508
576
  return t.length = n, Object.fromEntries(t);
509
- }, k = w === void 0 ? void 0 : O(!1), ae = w === void 0 || D.size === 0 ? void 0 : O(!0), j = P.succeed(G.text(JSON.stringify({
577
+ }, pe = D === void 0 ? void 0 : de(!1), A = D === void 0 || O.size === 0 ? void 0 : de(!0), P = j.succeed(W.text(JSON.stringify({
510
578
  protocol: 1,
511
579
  mutationReplay: e.mutationReplay === !0,
512
- ...k === void 0 ? {} : { surface: k },
513
- ...ae === void 0 ? {} : { serviceSurface: ae }
580
+ ...pe === void 0 ? {} : { surface: pe },
581
+ ...A === void 0 ? {} : { serviceSurface: A }
514
582
  }), {
515
583
  status: 200,
516
584
  contentType: "application/json; charset=utf-8",
@@ -518,135 +586,140 @@ var q = (e) => {
518
586
  "cache-control": "no-store",
519
587
  "access-control-allow-origin": "*"
520
588
  }
521
- })), N = "/_voltro/runtime-capabilities", L = `${i.slice(0, i.lastIndexOf("/"))}/_voltro/runtime-capabilities`, be = L === N ? U.add("GET", N, j) : F.mergeAll(U.add("GET", N, j), U.add("GET", L, j)), z = F.empty;
589
+ })), I = "/_voltro/runtime-capabilities", L = `${s.slice(0, s.lastIndexOf("/"))}/_voltro/runtime-capabilities`, R = L === I ? H.add("GET", I, P) : M.mergeAll(H.add("GET", I, P), H.add("GET", L, P)), Oe = M.empty;
522
590
  if (e.webhookRoutes !== void 0 && e.webhookRoutes.size > 0) {
523
- let t = (t) => W.HttpServerRequest.pipe(P.flatMap((n) => P.gen(function* () {
591
+ let t = (t) => U.HttpServerRequest.pipe(j.flatMap((n) => j.gen(function* () {
524
592
  let r = {};
525
593
  for (let [e, t] of Object.entries(n.headers)) t !== void 0 && (r[e.toLowerCase()] = Array.isArray(t) ? t.join(", ") : t);
526
- let i = n.url.split("?")[0], a = t.maxBodyBytes ?? Ze, o = /* @__PURE__ */ new Uint8Array();
594
+ let i = n.url.split("?")[0], a = t.maxBodyBytes ?? ot, o = /* @__PURE__ */ new Uint8Array();
527
595
  if (n.method !== "GET" && n.method !== "HEAD") {
528
596
  let e = Number(r["content-length"]);
529
- if (Number.isFinite(e) && e > a) return G.text("payload too large", { status: 413 });
530
- let t = yield* A(n.source, a);
531
- if (t._tag === "aborted") return G.text("request aborted", { status: 400 });
532
- if (t._tag === "too-large") return G.text("payload too large", { status: 413 });
597
+ if (Number.isFinite(e) && e > a) return W.text("payload too large", { status: 413 });
598
+ let t = yield* ae(n.source, a);
599
+ if (t._tag === "aborted") return W.text("request aborted", { status: 400 });
600
+ if (t._tag === "too-large") return W.text("payload too large", { status: 413 });
533
601
  o = new Uint8Array(t.bytes);
534
602
  }
535
- let s = ee(r.traceparent), c = yield* P.promise(() => t.handle({
603
+ let s = ie(r.traceparent), c = yield* j.promise(() => t.handle({
536
604
  method: n.method,
537
605
  path: i,
538
606
  headers: r,
539
607
  rawBody: o
540
- })).pipe(P.withSpan(`webhook${i}`, {
608
+ })).pipe(j.withSpan(`webhook${i}`, {
541
609
  attributes: {
542
610
  "framework.kind": "webhook",
543
611
  "http.route": i
544
612
  },
545
613
  ...s ? { parent: s } : {}
546
- })), l = new TextEncoder().encode(c.body), u = ne({
614
+ })), l = new TextEncoder().encode(c.body), u = ce({
547
615
  body: l,
548
616
  contentType: c.contentType,
549
617
  acceptEncoding: r["accept-encoding"],
550
618
  options: e.compression
551
619
  });
552
- return u.compressed ? G.uint8Array(u.bytes, {
620
+ return u.compressed ? W.uint8Array(u.bytes, {
553
621
  status: c.status,
554
622
  contentType: c.contentType,
555
623
  headers: u.headers
556
- }) : G.text(c.body, {
624
+ }) : W.text(c.body, {
557
625
  status: c.status,
558
626
  contentType: c.contentType
559
627
  });
560
- }))), n = Array.from(e.webhookRoutes.entries()).map(([e, n]) => U.add("*", e, t(n)));
561
- z = F.mergeAll(...n);
628
+ }))), n = Array.from(e.webhookRoutes.entries()).map(([e, n]) => H.add("*", e, t(n)));
629
+ Oe = M.mergeAll(...n);
562
630
  }
563
- let B = pe(e.security?.trustedProxies, process.env, e.security?.clientAddressHeader), Se = F.empty, Ce = () => void 0;
631
+ let z = be(e.security?.trustedProxies, process.env, e.security?.clientAddressHeader), ke = M.empty, Ae = () => void 0;
564
632
  if (e.httpRoutes !== void 0 && e.httpRoutes.length > 0) {
565
- let t = (t) => W.HttpServerRequest.pipe(P.flatMap((n) => P.gen(function* () {
633
+ let t = (t) => U.HttpServerRequest.pipe(j.flatMap((n) => j.gen(function* () {
566
634
  let r = {};
567
635
  for (let [e, t] of Object.entries(n.headers)) t !== void 0 && (r[e.toLowerCase()] = Array.isArray(t) ? t.join(", ") : t);
568
636
  let i = n.url.indexOf("?"), a = i >= 0 ? n.url.slice(0, i) : n.url, o = i >= 0 ? n.url.slice(i + 1) : "";
569
- if (!t.some((e) => Ke(e, a))) return G.text("not found", { status: 404 });
570
- let s = t.reduce((e, t) => Math.max(e, t.maxBodyBytes ?? Ze), 0), c = /* @__PURE__ */ new Uint8Array();
571
- if (n.method !== "GET" && n.method !== "HEAD") {
637
+ if (!t.some((e) => nt(e, a))) return W.text("not found", { status: 404 });
638
+ let s = t.reduce((e, t) => Math.max(e, t.maxBodyBytes ?? ot), 0), c = t[0]?.handleStream, l = /* @__PURE__ */ new Uint8Array();
639
+ if (c !== void 0 || n.method !== "GET" && n.method !== "HEAD") {
572
640
  let e = Number(r["content-length"]);
573
- if (Number.isFinite(e) && e > s) return G.text("payload too large", { status: 413 });
574
- let t = yield* A(n.source, s);
575
- if (t._tag === "aborted") return G.text("request aborted", { status: 400 });
576
- if (t._tag === "too-large") return G.text("payload too large", { status: 413 });
577
- c = new Uint8Array(t.bytes);
641
+ if (Number.isFinite(e) && e > s) return W.text("payload too large", { status: 413 });
642
+ if (c === void 0) {
643
+ let e = yield* ae(n.source, s);
644
+ if (e._tag === "aborted") return W.text("request aborted", { status: 400 });
645
+ if (e._tag === "too-large") return W.text("payload too large", { status: 413 });
646
+ l = new Uint8Array(e.bytes);
647
+ }
578
648
  }
579
- let l = e.getStore?.(), u;
649
+ let u = e.getStore?.(), d;
580
650
  try {
581
- u = n.source?.socket?.remoteAddress;
651
+ d = n.source?.socket?.remoteAddress;
582
652
  } catch {
583
- u = void 0;
653
+ d = void 0;
584
654
  }
585
- let d = de({
586
- socketAddress: u,
655
+ let f = ve({
656
+ socketAddress: d,
587
657
  headers: r,
588
- config: B
589
- }), f = {
658
+ config: z
659
+ }), p = {
590
660
  method: n.method,
591
661
  path: a,
592
662
  query: o,
593
663
  headers: r,
594
- rawBody: c,
595
- ...l === void 0 ? {} : { store: l },
596
- ...d === void 0 ? {} : { remoteAddr: d }
597
- }, p = Date.now(), m = yield* P.promise(() => Ue(t, f));
664
+ ...u === void 0 ? {} : { store: u },
665
+ ...f === void 0 ? {} : { remoteAddr: f }
666
+ }, m = Date.now(), h = yield* j.promise((e) => c === void 0 ? $e(t, {
667
+ ...p,
668
+ rawBody: l
669
+ }) : se(n.source, s, p, c, e));
598
670
  if (e.onHttpRoute !== void 0) try {
599
671
  e.onHttpRoute({
600
672
  method: n.method,
601
673
  path: a,
602
- status: m.status,
603
- durationMs: Date.now() - p,
604
- traceId: E(r.traceparent)?.traceId ?? T()
674
+ status: h.status,
675
+ durationMs: Date.now() - m,
676
+ traceId: T(r.traceparent)?.traceId ?? w()
605
677
  });
606
678
  } catch {}
607
- m.status >= 500 && lt.warn(`${n.method} ${a} → ${m.status}`, {
679
+ h.status >= 500 && vt.warn(`${n.method} ${a} → ${h.status}`, {
608
680
  method: n.method,
609
681
  path: a,
610
- status: m.status,
611
- ...typeof m.body == "string" && m.body.length > 0 ? { body: m.body.slice(0, 1e3) } : {},
612
- ...m.cause === void 0 ? {} : { cause: dt(m.cause) }
682
+ status: h.status,
683
+ ...typeof h.body == "string" && h.body.length > 0 ? { body: h.body.slice(0, 1e3) } : {},
684
+ ...h.cause === void 0 ? {} : { cause: yt(h.cause) }
613
685
  });
614
- let h = St(m.headers), g = h.headers, _ = (e) => (h.setCookie !== void 0 && Be.toServerResponse(n).setHeader("set-cookie", [...h.setCookie]), e), v = {
615
- status: m.status,
616
- ...m.contentType ? { contentType: m.contentType } : {},
617
- headers: g
686
+ let g = Dt(h.headers), _ = g.headers, v = (e) => (g.setCookie !== void 0 && Ze.toServerResponse(n).setHeader("set-cookie", [...g.setCookie]), e), y = {
687
+ status: h.status,
688
+ ...h.contentType ? { contentType: h.contentType } : {},
689
+ headers: _
618
690
  };
619
- if (m.byteStream !== void 0) {
620
- let e = m.byteStream.stream, t = typeof e == "function" ? e() : e;
621
- return _(G.stream(R.fromReadableStream({
691
+ if (h.byteStream !== void 0) {
692
+ let e = h.byteStream.stream, t = typeof e == "function" ? e() : e;
693
+ return v(W.stream(F.fromReadableStream({
622
694
  evaluate: () => t,
623
695
  onError: (e) => e
624
696
  }), {
625
- status: m.status,
626
- contentType: m.contentType ?? "application/octet-stream",
697
+ status: h.status,
698
+ contentType: h.contentType ?? "application/octet-stream",
627
699
  headers: {
628
- ...g,
629
- ...m.byteStream.contentLength === void 0 ? {} : { "content-length": String(m.byteStream.contentLength) },
630
- ...m.byteStream.contentDisposition === void 0 ? {} : { "content-disposition": m.byteStream.contentDisposition }
700
+ ..._,
701
+ ...h.byteStream.contentLength === void 0 ? {} : { "content-length": String(h.byteStream.contentLength) },
702
+ ...h.byteStream.contentDisposition === void 0 ? {} : { "content-disposition": h.byteStream.contentDisposition }
631
703
  }
632
704
  }));
633
705
  }
634
- if (m.stream !== void 0) {
635
- let { subscribe: e, keepAliveMs: t } = m.stream, n = new TextEncoder(), r = t ?? 15e3, i = R.callback((t) => P.gen(function* () {
636
- I.offerUnsafe(t, n.encode("retry: 5000\n\n"));
637
- let i = e((e) => {
638
- I.offerUnsafe(t, n.encode(e));
639
- }), a = r > 0 ? setInterval(() => {
640
- I.offerUnsafe(t, n.encode(": keep-alive\n\n"));
641
- }, r) : void 0;
642
- yield* P.addFinalizer(() => P.sync(() => {
643
- a !== void 0 && clearInterval(a), i();
644
- }));
645
- }));
646
- return _(G.stream(i, {
647
- status: m.status,
706
+ if (h.stream !== void 0) {
707
+ let { subscribe: e, keepAliveMs: t } = h.stream, n = He(h.stream.maxDurationMs), r = new TextEncoder(), i = t ?? 15e3, a = F.callback((t) => j.gen(function* () {
708
+ let n, a, o = !1;
709
+ yield* j.addFinalizer(() => j.sync(() => {
710
+ o = !0, a !== void 0 && clearInterval(a), n?.();
711
+ })), N.offerUnsafe(t, r.encode("retry: 5000\n\n"));
712
+ let s = e((e) => {
713
+ o || N.offerUnsafe(t, r.encode(e));
714
+ });
715
+ o ? s() : n = s, a = !o && i > 0 ? setInterval(() => {
716
+ N.offerUnsafe(t, r.encode(": keep-alive\n\n"));
717
+ }, i) : void 0;
718
+ })), o = n === void 0 ? a : a.pipe(F.interruptWhen(j.sleep(n)));
719
+ return v(W.stream(o, {
720
+ status: h.status,
648
721
  headers: {
649
- ...g,
722
+ ..._,
650
723
  "content-type": "text/event-stream; charset=utf-8",
651
724
  "cache-control": "no-cache, no-transform",
652
725
  connection: "keep-alive",
@@ -654,52 +727,52 @@ var q = (e) => {
654
727
  }
655
728
  }));
656
729
  }
657
- if (n.method === "HEAD") return _(G.empty({
658
- status: v.status,
659
- headers: g
730
+ if (n.method === "HEAD") return v(W.empty({
731
+ status: y.status,
732
+ headers: _
660
733
  }));
661
- let y = m.body instanceof Uint8Array ? m.body : new TextEncoder().encode(m.body ?? ""), b = ne({
662
- body: y,
663
- contentType: m.contentType,
734
+ let b = h.body instanceof Uint8Array ? h.body : new TextEncoder().encode(h.body ?? ""), x = ce({
735
+ body: b,
736
+ contentType: h.contentType,
664
737
  acceptEncoding: r["accept-encoding"],
665
738
  options: e.compression
666
739
  });
667
- return _(G.uint8Array(b.bytes, {
668
- ...v,
669
- headers: re(g, b.headers)
740
+ return v(W.uint8Array(x.bytes, {
741
+ ...y,
742
+ headers: le(_, x.headers)
670
743
  }));
671
- })), P.tapCause((e) => M.hasInterruptsOnly(e) ? P.void : P.sync(() => lt.error(`${t.map((e) => e.method).join("|")} ${t[0].path} threw`, { path: t[0].path }, M.squash(e))))), n = f(e.httpRoutes), r = new Map(n.map((e) => [e, t(e.routes)])), i = d(n);
672
- Ce = (e) => {
744
+ })), j.tapCause((e) => k.hasInterruptsOnly(e) ? j.void : j.sync(() => vt.error(`${t.map((e) => e.method).join("|")} ${t[0].path} threw`, { path: t[0].path }, k.squash(e))))), n = h(e.httpRoutes), r = new Map(n.map((e) => [e, t(e.routes)])), i = m(n);
745
+ Ae = (e) => {
673
746
  let t = i(e);
674
747
  return t === void 0 ? void 0 : { effect: r.get(t) };
675
748
  };
676
749
  let a = n.flatMap((e) => {
677
750
  let t = r.get(e);
678
- return e.methods.map((n) => U.add(n, `${e.mountPath}/*`, t));
751
+ return e.methods.map((n) => H.add(n, `${e.mountPath}/*`, t));
679
752
  });
680
- Se = F.mergeAll(...a);
753
+ ke = M.mergeAll(...a);
681
754
  }
682
- let we = K.layerProtocolWebsocket({ path: r }), V = (e) => {
683
- let t = H({ scope: e }), n = /* @__PURE__ */ new Map();
684
- return (e) => F.flatMap(e, (e) => {
685
- let r = _e.get(e, K.Protocol);
686
- return F.succeedContext(_e.make(K.Protocol, {
755
+ let je = V.layerProtocolWebsocket({ path: o }), Me = (e) => {
756
+ let t = B({ scope: e }), n = /* @__PURE__ */ new Map();
757
+ return (e) => M.flatMap(e, (e) => {
758
+ let r = we.get(e, V.Protocol);
759
+ return M.succeedContext(we.make(V.Protocol, {
687
760
  ...r,
688
- run: (e) => r.run((t, r) => P.suspend(() => {
761
+ run: (e) => r.run((t, r) => j.suspend(() => {
689
762
  if (r._tag === "Request") {
690
763
  let e = n.get(t);
691
- e === void 0 && (n.set(t, e = /* @__PURE__ */ new Map()), h(t)?.signal.addEventListener("abort", () => {
764
+ e === void 0 && (n.set(t, e = /* @__PURE__ */ new Map()), v(t)?.signal.addEventListener("abort", () => {
692
765
  n.delete(t);
693
766
  }, { once: !0 })), e.set(String(r.id), r.tag);
694
767
  }
695
768
  return e(t, r);
696
769
  })),
697
770
  end: (e) => (n.delete(e), r.end(e)),
698
- send: (e, i, a) => P.suspend(() => {
771
+ send: (e, i, a) => j.suspend(() => {
699
772
  let o = n.get(e), s = "requestId" in i ? String(i.requestId) : void 0, c = s === void 0 ? o?.size === 1 ? o.values().next().value : void 0 : o?.get(s);
700
773
  i._tag === "Exit" && s !== void 0 && o?.delete(s);
701
- for (let n of l(i)) {
702
- let r = ye(n), i = typeof r.dbMessage == "string" ? r.dbMessage : void 0;
774
+ for (let n of f(i)) {
775
+ let r = Ee(n), i = typeof r.dbMessage == "string" ? r.dbMessage : void 0;
703
776
  t.error(i === void 0 ? "rpc defect sent to client" : `rpc defect sent to client: ${i}`, {
704
777
  clientId: e,
705
778
  defect: n,
@@ -715,60 +788,60 @@ var q = (e) => {
715
788
  })
716
789
  }));
717
790
  });
718
- }, Te = { disableFatalDefects: !0 }, Ee = K.layer(e.group, Te), Oe = K.layer(e.group, Te).pipe(F.provide(V("voltro:rpc:http")(_(K.layerProtocolHttp({ path: "/rpc" }), "http"))), F.provide(He.layerJson), F.provide(e.httpHandlersLayer ?? e.handlersLayer)), ke = Ee.pipe(F.provide(V("voltro:rpc")(_(we, "websocket"))), F.provide(He.layerJson), F.provide(e.handlersLayer)), je = new Set((e.webSocketGateways ?? []).map((e) => e.path)), Me;
791
+ }, Ne = { disableFatalDefects: !0 }, Pe = V.layer(r, Ne), Ie = V.layer(n, Ne).pipe(M.provide(Me("voltro:rpc:http")(b(V.layerProtocolHttp({ path: "/rpc" }), "http"))), M.provide(Ge.layerJson), M.provide(e.httpHandlersLayer ?? e.handlersLayer)), Le = Pe.pipe(M.provide(Me("voltro:rpc")(b(je, "websocket"))), M.provide(Ge.layerJson), M.provide(e.handlersLayer)), ze = new Set((e.webSocketGateways ?? []).map((e) => e.path)), Be;
719
792
  if (e.webSocketGateways !== void 0 && e.webSocketGateways.length > 0) {
720
- let t = H({ scope: "voltro:gateway" }), n = e.webSocketGateways.map(De).map((n) => U.add("GET", n.path, W.HttpServerRequest.pipe(P.flatMap((r) => P.gen(function* () {
793
+ let t = B({ scope: "voltro:gateway" }), n = e.webSocketGateways.map(Fe).map((n) => H.add("GET", n.path, U.HttpServerRequest.pipe(j.flatMap((r) => j.gen(function* () {
721
794
  let i = {};
722
795
  for (let [e, t] of Object.entries(r.headers)) t !== void 0 && (i[e.toLowerCase()] = Array.isArray(t) ? t.join(", ") : t);
723
- if (!ot(r.method, i)) return G.text("upgrade required", {
796
+ if (!gt(r.method, i)) return W.text("upgrade required", {
724
797
  status: 426,
725
798
  headers: { upgrade: "websocket" }
726
799
  });
727
800
  let a = null, o;
728
801
  if (n.auth === "subject") {
729
802
  let r = e.resolveGatewaySubject;
730
- if (r === void 0) return t.error("gateway declares auth: subject but the boot passed no resolveGatewaySubject", { path: n.path }), G.text("gateway auth unavailable", { status: 500 });
731
- let s = yield* P.promise(() => r(i).catch(() => null));
732
- if (s === null) return G.text("unauthorized", { status: 401 });
803
+ if (r === void 0) return t.error("gateway declares auth: subject but the boot passed no resolveGatewaySubject", { path: n.path }), W.text("gateway auth unavailable", { status: 500 });
804
+ let s = yield* j.promise(() => r(i).catch(() => null));
805
+ if (s === null) return W.text("unauthorized", { status: 401 });
733
806
  a = s.subject, o = s.credentialExpiresAt;
734
807
  }
735
808
  let s = yield* r.upgrade;
736
- return yield* ie(s, r.source.socket, n, a, i, o, (e) => t.error("gateway handler failed", { path: n.path }, e)), G.empty({ status: 200 });
809
+ return yield* ue(s, r.source.socket, n, a, i, o, (e) => t.error("gateway handler failed", { path: n.path }, e)), W.empty({ status: 200 });
737
810
  })))));
738
- Me = F.mergeAll(...n);
811
+ Be = M.mergeAll(...n);
739
812
  }
740
- let Ne = U.make.pipe(P.provideService(U.RouterConfig, {
813
+ let Ve = H.make.pipe(j.provideService(H.RouterConfig, {
741
814
  caseSensitive: !0,
742
815
  ignoreTrailingSlash: !1,
743
816
  ignoreDuplicateSlashes: !1
744
- })), Pe = F.mergeAll(ke, Oe, be, C, z, Se, ...Me === void 0 ? [] : [Me]), Fe = e.pluginHttpInterceptor, q = Number(process.env.VOLTRO_MAX_RPC_BODY_BYTES), J = e.maxRpcBodyBytes ?? (Number.isFinite(q) && q > 0 ? q : 8388608), Ye = Number(process.env.VOLTRO_MAX_BODY_BYTES), Ze = e.maxBodyBytes ?? (Number.isFinite(Ye) && Ye > 0 ? Ye : 8388608), Y = { "cache-control": "no-store" }, Qe = e.httpRoutes?.some((e) => e.cors !== void 0 || e.credentials !== void 0) ? u(f(e.httpRoutes)) : () => void 0, $e = ue({
817
+ })), Ue = M.mergeAll(R, ...t === void 0 || r.requests.size > 0 ? [Le] : [], ...t === void 0 || n.requests.size > 0 ? [Ie] : [], E, Oe, ke, ...Be === void 0 ? [] : [Be]), We = e.pluginHttpInterceptor, Ke = Number(process.env.VOLTRO_MAX_RPC_BODY_BYTES), at = e.maxRpcBodyBytes ?? (Number.isFinite(Ke) && Ke > 0 ? Ke : 8388608), G = Number(process.env.VOLTRO_MAX_BODY_BYTES), ot = e.maxBodyBytes ?? (Number.isFinite(G) && G > 0 ? G : 8388608), K = { "cache-control": "no-store" }, ct = e.httpRoutes?.some((e) => e.cors !== void 0 || e.credentials !== void 0) ? p(h(e.httpRoutes)) : () => void 0, lt = _e({
745
818
  ...e.security?.originGuard === void 0 ? {} : { mode: e.security.originGuard },
746
819
  ...e.security?.allowedOrigins === void 0 ? {} : { allowedOrigins: e.security.allowedOrigins }
747
- }), et = le({
820
+ }), ut = ge({
748
821
  ...e.webhookRoutes === void 0 ? {} : { webhookPaths: e.webhookRoutes.keys() },
749
822
  ...e.httpRoutes === void 0 ? {} : { httpRoutes: e.httpRoutes }
750
- }), tt = me(e.security?.headers), X = H({ scope: "voltro:security" }), nt = H({ scope: "voltro:rpc" }), rt = (e) => {
823
+ }), dt = xe(e.security?.headers), ft = B({ scope: "voltro:security" }), q = B({ scope: "voltro:rpc" }), pt = (e) => {
751
824
  try {
752
825
  let t = new URL(e, "http://voltro.invalid").searchParams.get("voltro-socket-id");
753
826
  return t !== null && /^[A-Za-z0-9-]{1,80}$/.test(t) ? t : void 0;
754
827
  } catch {
755
828
  return;
756
829
  }
757
- }, it = (e) => {
830
+ }, mt = (e) => {
758
831
  let t = Object.create(e);
759
832
  return Object.defineProperty(t, "upgrade", {
760
833
  configurable: !0,
761
- get: () => P.gen(function* () {
762
- let t = yield* e.upgrade, n = xe(), r = rt(e.url), i = Date.now();
763
- return nt.info("rpc websocket opened", {
764
- replicaId: a,
765
- instanceId: qe(),
834
+ get: () => j.gen(function* () {
835
+ let t = yield* e.upgrade, n = De(), r = pt(e.url), i = Date.now();
836
+ return q.info("rpc websocket opened", {
837
+ replicaId: g,
838
+ instanceId: rt(),
766
839
  connectionId: n,
767
840
  ...r === void 0 ? {} : { clientSocketId: r }
768
- }), yield* P.addFinalizer(() => P.sync(() => {
769
- nt.info("rpc websocket closed", {
770
- replicaId: a,
771
- instanceId: qe(),
841
+ }), yield* j.addFinalizer(() => j.sync(() => {
842
+ q.info("rpc websocket closed", {
843
+ replicaId: g,
844
+ instanceId: rt(),
772
845
  connectionId: n,
773
846
  ...r === void 0 ? {} : { clientSocketId: r },
774
847
  durationMs: Date.now() - i
@@ -776,151 +849,151 @@ var q = (e) => {
776
849
  })), t;
777
850
  })
778
851
  }), t;
779
- }, at = (e, t) => {
780
- let n = e.headers, r = he(tt, {
852
+ }, ht = (e, t) => {
853
+ let n = e.headers, r = Se(dt, {
781
854
  contentType: n["content-type"],
782
855
  https: t
783
856
  }), i = {};
784
857
  for (let [e, t] of Object.entries(r)) n[e] === void 0 && (i[e] = t);
785
- return Object.keys(i).length === 0 ? e : G.setHeaders(e, i);
786
- }, ot = (e, t) => e.toUpperCase() === "GET" && (t.upgrade ?? "").toLowerCase().includes("websocket"), st = (e) => P.gen(function* () {
787
- let t = yield* W.HttpServerRequest, n = {};
858
+ return Object.keys(i).length === 0 ? e : W.setHeaders(e, i);
859
+ }, gt = (e, t) => e.toUpperCase() === "GET" && (t.upgrade ?? "").toLowerCase().includes("websocket"), _t = (e) => j.gen(function* () {
860
+ let t = yield* U.HttpServerRequest, n = {};
788
861
  for (let [e, r] of Object.entries(t.headers)) r !== void 0 && (n[e.toLowerCase()] = Array.isArray(r) ? r.join(", ") : r);
789
- let r = t.url.indexOf("?"), a = r === -1 ? t.url : t.url.slice(0, r), o, s = !1;
862
+ let r = t.url.indexOf("?"), i = r === -1 ? t.url : t.url.slice(0, r), a, o = !1;
790
863
  try {
791
864
  let e = t.source?.socket;
792
- o = e?.remoteAddress, s = e?.encrypted === !0;
865
+ a = e?.remoteAddress, o = e?.encrypted === !0;
793
866
  } catch {
794
- o = void 0;
867
+ a = void 0;
795
868
  }
796
- let c = fe({
797
- socketEncrypted: s,
798
- socketAddress: o,
869
+ let c = ye({
870
+ socketEncrypted: o,
871
+ socketAddress: a,
799
872
  xForwardedProto: n["x-forwarded-proto"],
800
- config: B
801
- }), l = de({
802
- socketAddress: o,
873
+ config: z
874
+ }), l = ve({
875
+ socketAddress: a,
803
876
  headers: n,
804
- config: B
805
- }), u = t.method === "OPTIONS" ? n["access-control-request-method"] ?? t.method : t.method, d = (Qe(a)?.routes ?? []).filter((e) => Ke(e, a)), f = d.find((e) => e.method === u || e.method === "*" || u === "HEAD" && e.method === "GET"), p = f ?? d[0], m = We(p?.cors, n.origin), h = (e) => {
877
+ config: z
878
+ }), u = t.method === "OPTIONS" ? n["access-control-request-method"] ?? t.method : t.method, d = (ct(i)?.routes ?? []).filter((e) => nt(e, i)), f = d.find((e) => e.method === u || e.method === "*" || u === "HEAD" && e.method === "GET"), p = f ?? d[0], m = et(p?.cors, n.origin), h = (e) => {
806
879
  let t = e.headers.vary, n = p?.cors !== void 0 && t !== void 0 ? {
807
880
  ...m,
808
881
  vary: [...new Set(`${t}, Origin`.split(",").map((e) => e.trim()))].join(", ")
809
882
  } : m;
810
- return at(G.setHeaders(e, n), c);
883
+ return ht(W.setHeaders(e, n), c);
811
884
  };
812
885
  if (t.method === "OPTIONS" && f?.cors !== void 0 && n["access-control-request-method"] !== void 0) {
813
- let e = Ge(f.cors, f.method, n);
814
- return h(G.empty({
886
+ let e = tt(f.cors, f.method, n);
887
+ return h(W.empty({
815
888
  status: e.status,
816
889
  headers: e.headers
817
890
  }));
818
891
  }
819
- if (t.method === "POST" && a === "/rpc") {
892
+ if (t.method === "POST" && i === "/rpc") {
820
893
  let e = n["content-length"];
821
- if (e !== void 0 && Number(e) > J) return h(G.text("rpc payload too large", {
894
+ if (e !== void 0 && Number(e) > at) return h(W.text("rpc payload too large", {
822
895
  status: 413,
823
- headers: Y
896
+ headers: K
824
897
  }));
825
898
  }
826
- let _ = a === "/rpc" && ce(t.method), v = (a === i || je.has(a)) && ot(t.method, n);
827
- if (ce(t.method) && !et(a) && f?.credentials !== "bearer" || v) {
828
- let e = se({
899
+ let g = i === "/rpc" && he(t.method), _ = (i === s || ze.has(i)) && gt(t.method, n);
900
+ if (he(t.method) && !ut(i) && f?.credentials !== "bearer" || _) {
901
+ let e = me({
829
902
  headers: n,
830
- config: $e
903
+ config: lt
831
904
  });
832
- if (!e.allowed) return X.warn("refused cross-site request", {
833
- path: a,
905
+ if (!e.allowed) return ft.warn("refused cross-site request", {
906
+ path: i,
834
907
  method: t.method,
835
908
  reason: e.reason,
836
909
  origin: e.origin,
837
- surface: v ? "websocket-upgrade" : _ ? "rpc" : "http-route"
838
- }), h(G.text("origin not allowed", {
910
+ surface: _ ? "websocket-upgrade" : g ? "rpc" : "http-route"
911
+ }), h(W.text("origin not allowed", {
839
912
  status: 403,
840
- headers: Y
913
+ headers: K
841
914
  }));
842
915
  }
843
- let y = _ ? P.gen(function* () {
844
- let r = yield* A(t.source, J);
845
- return r._tag === "aborted" ? h(G.text("rpc request body incomplete", {
916
+ let v = g ? j.gen(function* () {
917
+ let r = yield* ae(t.source, at);
918
+ return r._tag === "aborted" ? h(W.text("rpc request body incomplete", {
846
919
  status: 400,
847
- headers: Y
848
- })) : r._tag === "too-large" ? (X.warn("refused an over-cap rpc body", {
849
- path: a,
850
- cap: J,
920
+ headers: K
921
+ })) : r._tag === "too-large" ? (ft.warn("refused an over-cap rpc body", {
922
+ path: i,
923
+ cap: at,
851
924
  receivedAtLeast: r.received,
852
925
  declaredLength: n["content-length"] ?? null
853
- }), h(G.text("rpc payload too large", {
926
+ }), h(W.text("rpc payload too large", {
854
927
  status: 413,
855
- headers: Y
856
- }))) : yield* P.provideService(e, W.HttpServerRequest, te(g(t, l), r.bytes));
857
- }) : e, b = v && a === i ? it(g(t, l)) : t, x = b === t ? y : P.provideService(y, W.HttpServerRequest, b);
858
- if (!Fe) {
928
+ headers: K
929
+ }))) : yield* j.provideService(e, U.HttpServerRequest, oe(y(t, l), r.bytes));
930
+ }) : e, b = _ && i === s ? mt(y(t, l)) : t, x = b === t ? v : j.provideService(v, U.HttpServerRequest, b);
931
+ if (!We) {
859
932
  let e = yield* x;
860
- return G.isHttpServerResponse(e) ? h(e) : e;
933
+ return W.isHttpServerResponse(e) ? h(e) : e;
861
934
  }
862
- let S = yield* P.tryPromise(() => Fe(async () => null, {
935
+ let S = yield* j.tryPromise(() => We(async () => null, {
863
936
  method: t.method,
864
- path: a,
937
+ path: i,
865
938
  headers: n,
866
939
  remoteAddr: l
867
- })).pipe(P.catch((e) => P.sync(() => (lt.error("http interceptor threw — request REFUSED (fail-closed)", {
940
+ })).pipe(j.catch((e) => j.sync(() => (vt.error("http interceptor threw — request REFUSED (fail-closed)", {
868
941
  method: t.method,
869
- path: a
942
+ path: i
870
943
  }, e), {
871
944
  status: 500,
872
945
  body: "internal error",
873
946
  headers: void 0
874
947
  }))));
875
- if (S !== null) return h(G.text(S.body ?? "", {
948
+ if (S !== null) return h(W.text(S.body ?? "", {
876
949
  status: S.status,
877
950
  ...S.headers ? { headers: S.headers } : {}
878
951
  }));
879
952
  let C = yield* x;
880
- return G.isHttpServerResponse(C) ? h(C) : C;
881
- }), Z = o === void 0 ? void 0 : new Et(p);
882
- if (o !== void 0 && Z !== void 0) {
953
+ return W.isHttpServerResponse(C) ? h(C) : C;
954
+ }), J = _ === void 0 ? void 0 : new jt(x);
955
+ if (_ !== void 0 && J !== void 0) {
883
956
  let e = new Promise((e) => {
884
957
  let t = (n) => {
885
- n === "request" && (Z.removeListener("newListener", t), e());
958
+ n === "request" && (J.removeListener("newListener", t), e());
886
959
  };
887
- Z.on("newListener", t);
960
+ J.on("newListener", t);
888
961
  });
889
- Dt.set(p, e), e.then(() => {
890
- o.delegate({
962
+ Mt.set(x, e), e.then(() => {
963
+ _.delegate({
891
964
  request: (e, t) => {
892
- Z.emit("request", e, t);
965
+ J.emit("request", e, t);
893
966
  },
894
967
  upgrade: (e, t, n) => {
895
- Z.emit("upgrade", e, t, n);
968
+ J.emit("upgrade", e, t, n);
896
969
  }
897
970
  });
898
971
  });
899
972
  }
900
- let ct = F.unwrap(P.gen(function* () {
901
- let e = yield* Ne;
902
- return yield* F.build(F.provide(Pe, F.succeed(U.HttpRouter, e))), e.asHttpEffect();
903
- }).pipe(P.map((e) => Le.serve(st(e.pipe(P.catchIf((e) => Re.isHttpServerError(e) && e.reason._tag === "RouteNotFound", (e) => {
904
- let t = Ce(e.request.url.split("?")[0]);
905
- return t === void 0 ? P.fail(e) : t.effect;
906
- }))))))).pipe(F.provide(ze.layer(() => Z ?? p, n === void 0 ? { port: t } : {
907
- port: t,
908
- host: n
909
- })), F.provide(Ve.layer), F.provide(Xe));
910
- e.tracerLayer && (ct = ct.pipe(F.provide(oe), F.provide(e.tracerLayer)));
911
- let Q = H({ scope: "voltro:rpc" }), ut = F.launch(ct).pipe(P.catchCause((e) => P.sync(() => {
912
- Q.error("rpc server crashed", {}, M.squash(e)), process.exit(1);
913
- }))), ft = P.runFork(ut);
914
- return Ot.add(ft), Lt(), {
915
- server: p,
973
+ let Y = M.unwrap(j.gen(function* () {
974
+ let e = yield* Ve;
975
+ return yield* M.build(M.provide(Ue, M.succeed(H.HttpRouter, e))), e.asHttpEffect();
976
+ }).pipe(j.map((e) => Je.serve(_t(e.pipe(j.catchIf((e) => Ye.isHttpServerError(e) && e.reason._tag === "RouteNotFound", (e) => {
977
+ let t = Ae(e.request.url.split("?")[0]);
978
+ return t === void 0 ? j.fail(e) : t.effect;
979
+ }))))))).pipe(M.provide(Xe.layer(() => J ?? x, a === void 0 ? { port: i } : {
980
+ port: i,
981
+ host: a
982
+ })), M.provide(Qe.layer), M.provide(st));
983
+ e.tracerLayer && (Y = Y.pipe(M.provide(fe), M.provide(e.tracerLayer)));
984
+ let X = B({ scope: "voltro:rpc" }), bt = M.launch(Y).pipe(j.catchCause((e) => j.sync(() => {
985
+ X.error("rpc server crashed", {}, k.squash(e)), process.exit(1);
986
+ }))), Z = j.runFork(bt);
987
+ return $.add(Z), Vt(), {
988
+ server: x,
916
989
  shutdown: async () => {
917
- Ot.delete(ft);
918
- let e = P.runPromise(ve.interrupt(ft)).then(() => void 0, () => void 0);
919
- for (let e of m) e.destroy();
920
- p.closeIdleConnections(), await e, o !== void 0 && await o.close();
990
+ $.delete(Z);
991
+ let e = j.runPromise(Te.interrupt(Z)).then(() => void 0, () => void 0);
992
+ for (let e of S) e.destroy();
993
+ x.closeIdleConnections(), await e, _ !== void 0 && await _.close();
921
994
  }
922
995
  };
923
- }, Et = class extends Fe {
996
+ }, jt = class extends Ke {
924
997
  bound;
925
998
  constructor(e) {
926
999
  super(), this.bound = e;
@@ -932,40 +1005,40 @@ var q = (e) => {
932
1005
  address() {
933
1006
  return this.bound.address();
934
1007
  }
935
- }, Dt = /* @__PURE__ */ new WeakMap(), Ot = /* @__PURE__ */ new Set(), kt = /* @__PURE__ */ new Set(), At = !1, jt = (e) => (kt.add(e), () => {
936
- kt.delete(e);
937
- }), Mt = 1e4, Nt = 1e3, Pt = 3e5, Ft = () => {
1008
+ }, Mt = /* @__PURE__ */ new WeakMap(), $ = /* @__PURE__ */ new Set(), Nt = /* @__PURE__ */ new Set(), Pt = !1, Ft = (e) => (Nt.add(e), () => {
1009
+ Nt.delete(e);
1010
+ }), It = 1e4, Lt = 1e3, Rt = 3e5, zt = () => {
938
1011
  let e = process.env.VOLTRO_SHUTDOWN_GRACE_MS;
939
- if (e === void 0 || e === "") return Mt;
1012
+ if (e === void 0 || e === "") return It;
940
1013
  let t = Number(e);
941
- return !Number.isFinite(t) || t <= 0 ? Mt : Math.min(Pt, Math.max(Nt, Math.trunc(t)));
942
- }, It = (e) => {
1014
+ return !Number.isFinite(t) || t <= 0 ? It : Math.min(Rt, Math.max(Lt, Math.trunc(t)));
1015
+ }, Bt = (e) => {
943
1016
  let t = Date.now(), n = !1, r = (r) => () => {
944
1017
  n || (n = !0, clearTimeout(i), e.onOutcome?.({
945
1018
  reason: r,
946
1019
  ms: Date.now() - t
947
1020
  }), e.exit());
948
1021
  }, i = setTimeout(r("deadline"), e.deadlineMs);
949
- i.unref?.(), Promise.all(e.hooks.map((e) => Promise.resolve().then(e).then(() => void 0, () => void 0))).then(() => Promise.all(e.fibers.map((e) => P.runPromise(ve.interrupt(e)).then(() => void 0, () => void 0)))).then(r("drained"), r("drained"));
950
- }, Lt = () => {
951
- if (At) return;
952
- At = !0;
1022
+ i.unref?.(), Promise.all(e.hooks.map((e) => Promise.resolve().then(e).then(() => void 0, () => void 0))).then(() => Promise.all(e.fibers.map((e) => j.runPromise(Te.interrupt(e)).then(() => void 0, () => void 0)))).then(r("drained"), r("drained"));
1023
+ }, Vt = () => {
1024
+ if (Pt) return;
1025
+ Pt = !0;
953
1026
  let e = () => {
954
- let e = [...Ot], t = [...kt];
955
- Ot.clear(), kt.clear(), It({
1027
+ let e = [...$], t = [...Nt];
1028
+ $.clear(), Nt.clear(), Bt({
956
1029
  fibers: e,
957
1030
  hooks: t,
958
- deadlineMs: Ft(),
1031
+ deadlineMs: zt(),
959
1032
  exit: () => process.exit(0),
960
1033
  onOutcome: ({ reason: e, ms: t }) => {
961
- e === "drained" ? ut.info(`drained in ${t}ms`) : ut.error(`drain deadline exceeded — cut at ${t}ms`, { hint: "a shutdown hook or a pool drain did not complete; whatever had not finished did not happen" });
1034
+ e === "drained" ? Y.info(`drained in ${t}ms`) : Y.error(`drain deadline exceeded — cut at ${t}ms`, { hint: "a shutdown hook or a pool drain did not complete; whatever had not finished did not happen" });
962
1035
  }
963
1036
  });
964
1037
  };
965
1038
  process.once("SIGINT", e), process.once("SIGTERM", e);
966
- }, Rt = (e, t = 1e4) => new Promise((n, r) => {
1039
+ }, Ht = (e, t = 1e4) => new Promise((n, r) => {
967
1040
  if (e.listening) {
968
- let i = Dt.get(e);
1041
+ let i = Mt.get(e);
969
1042
  if (i === void 0) {
970
1043
  n();
971
1044
  return;
@@ -989,4 +1062,4 @@ var q = (e) => {
989
1062
  a = setTimeout(() => o(/* @__PURE__ */ Error(`rpc server did not bind within ${t}ms`)), t), e.on("listening", s), e.on("error", c);
990
1063
  });
991
1064
  //#endregion
992
- export { wt as DEFAULT_MAX_RPC_BODY_BYTES, Rt as awaitServerListening, ot as bindComputedUntyped, Ct as bindMutation, ct as bindStream, st as bindSubscription, nt as bindSubscriptionUntyped, yt as defectMessage, It as drainForShutdown, ht as isInfraError, xt as makeMutationOutputCodec, jt as onProcessShutdown, it as resetComputedQueryCacheWarnings, Ft as shutdownGraceMsFromEnv, Tt as startRpcServer };
1065
+ export { kt as DEFAULT_MAX_RPC_BODY_BYTES, Ht as awaitServerListening, mt as bindComputedUntyped, Ot as bindMutation, _t as bindStream, ht as bindSubscription, pt as bindSubscriptionUntyped, Q as defectMessage, Bt as drainForShutdown, Z as isInfraError, Et as makeMutationCodec, Ft as onProcessShutdown, zt as shutdownGraceMsFromEnv, At as startRpcServer };