orpc-fn 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -28
- package/dist/assemble-procedure.d.ts.map +1 -1
- package/dist/assemble-procedure.js +3 -1
- package/dist/assemble-procedure.js.map +1 -1
- package/dist/client.d.ts +13 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +21 -1
- package/dist/client.js.map +1 -1
- package/dist/create-fn.d.ts +63 -5
- package/dist/create-fn.d.ts.map +1 -1
- package/dist/create-fn.js +45 -16
- package/dist/create-fn.js.map +1 -1
- package/dist/expected-client-error.d.ts +6 -0
- package/dist/expected-client-error.d.ts.map +1 -1
- package/dist/expected-client-error.js +16 -0
- package/dist/expected-client-error.js.map +1 -1
- package/dist/hono.d.ts +44 -22
- package/dist/hono.d.ts.map +1 -1
- package/dist/hono.js +51 -20
- package/dist/hono.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/issues.d.ts +12 -0
- package/dist/issues.d.ts.map +1 -0
- package/dist/issues.js +22 -0
- package/dist/issues.js.map +1 -0
- package/dist/json-schema.d.ts +3 -6
- package/dist/json-schema.d.ts.map +1 -1
- package/dist/json-schema.js +12 -7
- package/dist/json-schema.js.map +1 -1
- package/dist/live/codec.d.ts +2 -0
- package/dist/live/codec.d.ts.map +1 -1
- package/dist/live/codec.js +21 -16
- package/dist/live/codec.js.map +1 -1
- package/dist/live/fn-live.d.ts +6 -19
- package/dist/live/fn-live.d.ts.map +1 -1
- package/dist/live/fn-live.js +15 -23
- package/dist/live/fn-live.js.map +1 -1
- package/dist/live/index.d.ts +2 -2
- package/dist/live/index.d.ts.map +1 -1
- package/dist/live/index.js +1 -1
- package/dist/live/index.js.map +1 -1
- package/dist/live/memory.d.ts +11 -1
- package/dist/live/memory.d.ts.map +1 -1
- package/dist/live/memory.js +14 -1
- package/dist/live/memory.js.map +1 -1
- package/dist/live/pub-sub.d.ts +50 -8
- package/dist/live/pub-sub.d.ts.map +1 -1
- package/dist/live/pub-sub.js +79 -26
- package/dist/live/pub-sub.js.map +1 -1
- package/dist/live/redis-bun.d.ts +6 -1
- package/dist/live/redis-bun.d.ts.map +1 -1
- package/dist/live/redis-bun.js +10 -1
- package/dist/live/redis-bun.js.map +1 -1
- package/dist/live/scoped-change-bus.d.ts +3 -1
- package/dist/live/scoped-change-bus.d.ts.map +1 -1
- package/dist/live/scoped-change-bus.js +3 -0
- package/dist/live/scoped-change-bus.js.map +1 -1
- package/dist/mastra.d.ts +16 -3
- package/dist/mastra.d.ts.map +1 -1
- package/dist/mastra.js +15 -3
- package/dist/mastra.js.map +1 -1
- package/dist/mcp/core.d.ts +31 -14
- package/dist/mcp/core.d.ts.map +1 -1
- package/dist/mcp/core.js +39 -20
- package/dist/mcp/core.js.map +1 -1
- package/dist/mcp/sdk.d.ts +6 -2
- package/dist/mcp/sdk.d.ts.map +1 -1
- package/dist/mcp/sdk.js +9 -3
- package/dist/mcp/sdk.js.map +1 -1
- package/dist/mcp/server.d.ts +6 -2
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +9 -3
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp.d.ts +3 -7
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +4 -6
- package/dist/mcp.js.map +1 -1
- package/dist/meta.d.ts +14 -2
- package/dist/meta.d.ts.map +1 -1
- package/dist/meta.js +6 -2
- package/dist/meta.js.map +1 -1
- package/dist/otel.d.ts +16 -4
- package/dist/otel.d.ts.map +1 -1
- package/dist/otel.js +40 -10
- package/dist/otel.js.map +1 -1
- package/dist/react.d.ts +6 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +5 -1
- package/dist/react.js.map +1 -1
- package/dist/route-options.d.ts.map +1 -1
- package/dist/route-options.js +4 -0
- package/dist/route-options.js.map +1 -1
- package/dist/stream-call.d.ts +15 -0
- package/dist/stream-call.d.ts.map +1 -0
- package/dist/stream-call.js +13 -0
- package/dist/stream-call.js.map +1 -0
- package/dist/timing.d.ts +2 -0
- package/dist/timing.d.ts.map +1 -1
- package/dist/timing.js +2 -0
- package/dist/timing.js.map +1 -1
- package/dist/tool-errors.d.ts +24 -0
- package/dist/tool-errors.d.ts.map +1 -0
- package/dist/tool-errors.js +36 -0
- package/dist/tool-errors.js.map +1 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/vue.d.ts +47 -4
- package/dist/vue.d.ts.map +1 -1
- package/dist/vue.js +39 -9
- package/dist/vue.js.map +1 -1
- package/package.json +2 -2
- package/src/assemble-procedure.ts +3 -1
- package/src/client.ts +26 -2
- package/src/create-fn.ts +149 -19
- package/src/expected-client-error.ts +19 -0
- package/src/hono.ts +120 -41
- package/src/index.ts +3 -2
- package/src/issues.ts +35 -0
- package/src/json-schema.ts +16 -10
- package/src/live/codec.ts +21 -19
- package/src/live/fn-live.ts +18 -36
- package/src/live/index.ts +2 -2
- package/src/live/memory.ts +22 -1
- package/src/live/pub-sub.ts +142 -37
- package/src/live/redis-bun.ts +23 -2
- package/src/live/scoped-change-bus.ts +10 -1
- package/src/mastra.ts +25 -6
- package/src/mcp/core.ts +76 -29
- package/src/mcp/sdk.ts +27 -2
- package/src/mcp/server.ts +27 -2
- package/src/mcp.ts +5 -16
- package/src/meta.ts +28 -4
- package/src/otel.ts +41 -9
- package/src/react.ts +10 -3
- package/src/route-options.ts +8 -0
- package/src/stream-call.ts +15 -0
- package/src/timing.ts +3 -0
- package/src/tool-errors.ts +52 -0
- package/src/types.ts +2 -0
- package/src/vue.ts +92 -19
package/dist/live/pub-sub.js
CHANGED
|
@@ -178,6 +178,9 @@ export function createLiveRuntime(options) {
|
|
|
178
178
|
const defaultMaxIngress = positiveInteger(options.pubsub?.maxIngressSize ?? defaultMaxQueue, 'maxIngressSize');
|
|
179
179
|
const defaultMaxReplay = positiveInteger(options.pubsub?.maxReplaySize ?? defaultMaxQueue, 'maxReplaySize');
|
|
180
180
|
const initializationTimeout = positiveInteger(options.pubsub?.initializationTimeoutMs ?? 10000, 'initializationTimeoutMs');
|
|
181
|
+
const maxStreamAge = options.pubsub?.maxStreamAgeMs === undefined
|
|
182
|
+
? undefined
|
|
183
|
+
: positiveInteger(options.pubsub.maxStreamAgeMs, 'maxStreamAgeMs');
|
|
181
184
|
const metric = (event) => safely(() => options.pubsub?.onMetric?.(event));
|
|
182
185
|
const namespace = options.pubsub?.namespace;
|
|
183
186
|
const qualify = (name) => (namespace ? `${namespace}:${name}` : name);
|
|
@@ -265,14 +268,15 @@ export function createLiveRuntime(options) {
|
|
|
265
268
|
span?.setAttribute('pubsub.duration_ms', performance.now() - startTime);
|
|
266
269
|
}
|
|
267
270
|
});
|
|
271
|
+
const safePublish = config.safePublish ?? options.pubsub?.safePublish;
|
|
268
272
|
const guarded = async (operation, items) => {
|
|
269
|
-
if (!
|
|
273
|
+
if (!safePublish)
|
|
270
274
|
return send(operation, items);
|
|
271
275
|
try {
|
|
272
276
|
await send(operation, items);
|
|
273
277
|
}
|
|
274
278
|
catch (error) {
|
|
275
|
-
logger.
|
|
279
|
+
logger.warn('pubsub.publish_failed', {
|
|
276
280
|
name,
|
|
277
281
|
...errorAttributes(error)
|
|
278
282
|
});
|
|
@@ -524,7 +528,7 @@ export function createLiveRuntime(options) {
|
|
|
524
528
|
name,
|
|
525
529
|
maxIngress
|
|
526
530
|
});
|
|
527
|
-
const openInternal = async ({ input, context, signal, recoverGaps = false }) => {
|
|
531
|
+
const openInternal = async ({ input, context, signal, recoverGaps = false, server = false }) => {
|
|
528
532
|
assertOpen();
|
|
529
533
|
signal?.throwIfAborted();
|
|
530
534
|
const initializing = new AbortController();
|
|
@@ -545,9 +549,10 @@ export function createLiveRuntime(options) {
|
|
|
545
549
|
signal?.removeEventListener('abort', cancelInitialization);
|
|
546
550
|
};
|
|
547
551
|
try {
|
|
548
|
-
if (
|
|
552
|
+
if (!server &&
|
|
553
|
+
authFn !== undefined &&
|
|
549
554
|
authFn !== true &&
|
|
550
|
-
!(await waitFor(Promise.resolve(authFn({ input, ctx: context })), initializationTimeout, initializing.signal))) {
|
|
555
|
+
!(await waitFor(Promise.resolve(authFn({ input, context, ctx: context })), initializationTimeout, initializing.signal))) {
|
|
551
556
|
throw new ORPCError('FORBIDDEN', {
|
|
552
557
|
message: 'You do not have access to this subscription'
|
|
553
558
|
});
|
|
@@ -597,16 +602,17 @@ export function createLiveRuntime(options) {
|
|
|
597
602
|
});
|
|
598
603
|
let replaying = useBacklog ? [] : null;
|
|
599
604
|
let replayGap = false;
|
|
600
|
-
|
|
605
|
+
// Overlap exists only between the backlog and live events that arrive
|
|
606
|
+
// while it replays, so ids are recorded only then: at most twice
|
|
607
|
+
// `maxReplay`, and nothing at all without a backlog.
|
|
608
|
+
const seen = useBacklog ? new Set() : null;
|
|
601
609
|
const dedupe = (id) => {
|
|
602
|
-
if (!id)
|
|
610
|
+
if (!id || !seen)
|
|
603
611
|
return false;
|
|
604
612
|
if (seen.has(id))
|
|
605
613
|
return true;
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
Math.max(maxReplay, maxQueue, channelOptions.backlogSize ?? 50) * 2)
|
|
609
|
-
seen.delete(seen.values().next().value);
|
|
614
|
+
if (replaying)
|
|
615
|
+
seen.add(id);
|
|
610
616
|
return false;
|
|
611
617
|
};
|
|
612
618
|
const push = (data, id) => {
|
|
@@ -658,10 +664,12 @@ export function createLiveRuntime(options) {
|
|
|
658
664
|
// stream finishing, or `close()`. Releases everything at once, even
|
|
659
665
|
// while the stream is parked or not yet read.
|
|
660
666
|
let closed = false;
|
|
667
|
+
let ageTimer;
|
|
661
668
|
const close = (...error) => {
|
|
662
669
|
if (closed)
|
|
663
670
|
return;
|
|
664
671
|
closed = true;
|
|
672
|
+
clearTimeout(ageTimer);
|
|
665
673
|
initializing.abort(error[0] ?? new Error('Subscription closed'));
|
|
666
674
|
delivery.close(error[0]);
|
|
667
675
|
activeSubscriberCleanups.delete(stop);
|
|
@@ -690,6 +698,10 @@ export function createLiveRuntime(options) {
|
|
|
690
698
|
signal?.addEventListener('abort', stop);
|
|
691
699
|
if (signal?.aborted)
|
|
692
700
|
close();
|
|
701
|
+
if (maxStreamAge !== undefined && !server && !closed) {
|
|
702
|
+
ageTimer = setTimeout(stop, maxStreamAge * (1 + Math.random() * 0.1));
|
|
703
|
+
ageTimer.unref?.();
|
|
704
|
+
}
|
|
693
705
|
try {
|
|
694
706
|
await waitFor(local.ready, initializationTimeout, initializing.signal);
|
|
695
707
|
if (replaying && !closed) {
|
|
@@ -769,6 +781,25 @@ export function createLiveRuntime(options) {
|
|
|
769
781
|
...channelOptions,
|
|
770
782
|
getChannelName: getPublishChannel
|
|
771
783
|
});
|
|
784
|
+
const readBacklog = async (event) => {
|
|
785
|
+
const channelName = getPublishChannel(event);
|
|
786
|
+
const events = [];
|
|
787
|
+
for (const raw of await requireTransport().readBacklog(channelName)) {
|
|
788
|
+
try {
|
|
789
|
+
events.push(await eventSchema.parseAsync(decodeMessage(raw).value));
|
|
790
|
+
}
|
|
791
|
+
catch (error) {
|
|
792
|
+
metric({
|
|
793
|
+
type: 'parseError',
|
|
794
|
+
stage: 'replay',
|
|
795
|
+
error,
|
|
796
|
+
name,
|
|
797
|
+
channel: channelName
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
return events;
|
|
802
|
+
};
|
|
772
803
|
const open = (params) => {
|
|
773
804
|
const task = openInternal(params);
|
|
774
805
|
pendingOpens.add(task);
|
|
@@ -779,6 +810,7 @@ export function createLiveRuntime(options) {
|
|
|
779
810
|
open,
|
|
780
811
|
publish,
|
|
781
812
|
publishMany,
|
|
813
|
+
readBacklog,
|
|
782
814
|
getChannelName,
|
|
783
815
|
getSubscriptionChannelName: ({ input, context }) => getChannelName(input, context),
|
|
784
816
|
getPublishChannelName: getPublishChannel
|
|
@@ -786,6 +818,8 @@ export function createLiveRuntime(options) {
|
|
|
786
818
|
}
|
|
787
819
|
function createPubSub(pubsubOptions) {
|
|
788
820
|
const { name } = pubsubOptions;
|
|
821
|
+
if (pubsubOptions.authFn === undefined)
|
|
822
|
+
throw new TypeError(`orpc-fn: pub/sub ${name} needs an authFn; pass authFn: true to let every caller of its procedure subscribe`);
|
|
789
823
|
const channel = createChannel(pubsubOptions);
|
|
790
824
|
const { channel: _channel, eventSchema: _eventSchema, inputSchema, filterFn: _filterFn, authFn: _authFn, overflowMarker: _overflowMarker, useBacklog: _useBacklog, backlogSize: _backlogSize, backlogTtl: _backlogTtl, mirrorChannel: _mirrorChannel, safePublish: _safePublish, maxQueueSize: _maxQueueSize, maxIngressSize: _maxIngressSize, maxReplaySize: _maxReplaySize, ...routeOptions } = pubsubOptions;
|
|
791
825
|
const subscribe = options.fn({
|
|
@@ -799,24 +833,27 @@ export function createLiveRuntime(options) {
|
|
|
799
833
|
yield* (await channel.open({ input, context, signal })).events;
|
|
800
834
|
}
|
|
801
835
|
});
|
|
802
|
-
const { publish, publishMany, getChannelName } = channel;
|
|
803
836
|
return {
|
|
804
837
|
subscribe,
|
|
805
|
-
publish,
|
|
806
|
-
publishMany,
|
|
807
|
-
getChannelName,
|
|
838
|
+
publish: channel.publish,
|
|
839
|
+
publishMany: channel.publishMany,
|
|
808
840
|
getSubscriptionChannelName: channel.getSubscriptionChannelName,
|
|
809
|
-
getPublishChannelName: channel.getPublishChannelName
|
|
841
|
+
getPublishChannelName: channel.getPublishChannelName,
|
|
842
|
+
listen: listener(channel),
|
|
843
|
+
readBacklog: channel.readBacklog
|
|
810
844
|
};
|
|
811
845
|
}
|
|
812
846
|
function createPublisher(publisherOptions) {
|
|
813
|
-
const
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
847
|
+
const channel = createChannel(publisherOptions);
|
|
848
|
+
return {
|
|
849
|
+
publish: channel.publish,
|
|
850
|
+
publishMany: channel.publishMany,
|
|
851
|
+
getChannelName: channel.getPublishChannelName,
|
|
852
|
+
listen: (params, listenOptions = {}) => listener(channel)(params, listenOptions),
|
|
853
|
+
readBacklog: channel.readBacklog
|
|
854
|
+
};
|
|
819
855
|
}
|
|
856
|
+
const listener = (channel) => async (input, { signal, context } = {}) => (await channel.open({ input, context, signal, server: true })).events;
|
|
820
857
|
return {
|
|
821
858
|
createChannel,
|
|
822
859
|
shutdown: () => {
|
|
@@ -840,10 +877,9 @@ export function createLiveRuntime(options) {
|
|
|
840
877
|
/** Open subscriptions of this instance (drain progress, gauges). */
|
|
841
878
|
activePubSubSubscriberCount: () => activeSubscriberCleanups.size,
|
|
842
879
|
/** End every open subscription; returns how many were closed. */
|
|
843
|
-
drainPubSubSubscribers: () => {
|
|
880
|
+
drainPubSubSubscribers: (drain) => {
|
|
844
881
|
const cleanups = [...activeSubscriberCleanups];
|
|
845
|
-
|
|
846
|
-
for (const cleanup of cleanups) {
|
|
882
|
+
const run = (cleanup) => {
|
|
847
883
|
try {
|
|
848
884
|
cleanup();
|
|
849
885
|
}
|
|
@@ -853,8 +889,25 @@ export function createLiveRuntime(options) {
|
|
|
853
889
|
error: errorMessageOf(error)
|
|
854
890
|
});
|
|
855
891
|
}
|
|
892
|
+
};
|
|
893
|
+
if (drain === undefined) {
|
|
894
|
+
activeSubscriberCleanups.clear();
|
|
895
|
+
for (const cleanup of cleanups)
|
|
896
|
+
run(cleanup);
|
|
897
|
+
return cleanups.length;
|
|
856
898
|
}
|
|
857
|
-
|
|
899
|
+
const { overMs } = drain;
|
|
900
|
+
if (!Number.isFinite(overMs) || overMs < 0)
|
|
901
|
+
throw new RangeError('orpc-fn: overMs must be finite and nonnegative');
|
|
902
|
+
const step = overMs / Math.max(1, cleanups.length - 1);
|
|
903
|
+
return (async () => {
|
|
904
|
+
for (const [index, cleanup] of cleanups.entries()) {
|
|
905
|
+
if (index > 0)
|
|
906
|
+
await new Promise((resolve) => setTimeout(resolve, step));
|
|
907
|
+
run(cleanup);
|
|
908
|
+
}
|
|
909
|
+
return cleanups.length;
|
|
910
|
+
})();
|
|
858
911
|
}
|
|
859
912
|
};
|
|
860
913
|
}
|
package/dist/live/pub-sub.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pub-sub.js","sourceRoot":"","sources":["../../src/live/pub-sub.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAGxC,OAAO,EACN,eAAe,EACf,cAAc,EAGd,MAAM,YAAY,CAAA;AAWnB,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AACzD,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAmO3E,8EAA8E;AAC9E,gBAAgB;AAChB,8EAA8E;AAE9E;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,uBAAuB,CAAI,IAM1C;IACA,eAAe,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;IACxC,MAAM,KAAK,GAAQ,EAAE,CAAA;IACrB,wEAAwE;IACxE,wEAAwE;IACxE,IAAI,qBAAqB,GAAa,IAAI,CAAA;IAE1C,OAAO;QACN,IAAI,MAAM;YACT,OAAO,KAAK,CAAC,MAAM,CAAA;QACpB,CAAC;QACD,OAAO,CAAC,IAAO;YACd,IAAI,CAAC;gBACJ,IAAI,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;oBAClC,IAAI,qBAAqB,KAAK,IAAI,EAAE,CAAC;wBACpC,gEAAgE;wBAChE,uCAAuC;wBACvC,MAAM,SAAS,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;wBAC5D,IAAI,SAAS,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;4BAC/B,+DAA+D;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AQ,GAAG,CAAC,GAAG,wBAAwB,CAAC,CAAA;YAC9C,wBAAwB,CAAC,KAAK,EAAE,CAAA;YAChC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;gBAChC,IAAI,CAAC;oBACJ,OAAO,EAAE,CAAA;gBACV,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBAChB,4CAA4C;oBAC5C,MAAM,CAAC,IAAI,CAAC,wCAAwC,EAAE;wBACrD,KAAK,EAAE,cAAc,CAAC,KAAK,CAAC;qBAC5B,CAAC,CAAA;gBACH,CAAC;YACF,CAAC;YACD,OAAO,QAAQ,CAAC,MAAM,CAAA;QACvB,CAAC;KACD,CAAA;AACF,CAAC","sourcesContent":["import type { Schema } from '@orpc/contract'\nimport { ORPCError } from '@orpc/server'\nimport type { ZodObject, ZodRawShape, ZodType, z } from 'zod'\nimport type { FnLogger } from '../logger.js'\nimport {\n\terrorAttributes,\n\terrorMessageOf,\n\ttype SpanLike,\n\ttype Tracing\n} from '../otel.js'\nimport type {\n\tGuardOptions,\n\tFnContext,\n\tFnDefinition,\n\tFnProcedure,\n\tFnRouteOptions,\n\tMaybePromise,\n\tProcedureKey,\n\tProcedureOption\n} from '../types.js'\nimport { decodeMessage, encodePayload } from './codec.js'\nimport { LIVE_GAP, positiveInteger, safely, waitFor } from './lifecycle.js'\nimport type {\n\tBacklogOptions,\n\tPubSubMessage,\n\tPubSubTransport\n} from './transport.js'\n\n// ═══════════════════════════════════════════════════════════════════════════\n// Types\n//\n// Publishers pass an event schema's INPUT (`z.input`); subscribers, filters\n// and channel resolvers see its OUTPUT (`z.output`). The raw input travels on\n// the wire and every receiver parses it once.\n// ═══════════════════════════════════════════════════════════════════════════\n\n/** Any Zod object schema, including `.strict()`, `.passthrough()` and `.catchall()`. */\nexport type ObjectSchema = ZodObject<ZodRawShape, z.core.$ZodObjectConfig>\n\n/**\n * A static channel name, or one derived from (partial) subscriber input or\n * event data.\n */\nexport type ChannelDefinition<TInput, TEventData, TContext = unknown> =\n\t| string\n\t| {\n\t\t\tsubscribe: (params: { input: TInput; context: TContext }) => string\n\t\t\tpublish: (event: TEventData) => string\n\t }\n\t| ((\n\t\t\tparams: Partial<TInput> | Partial<TEventData>,\n\t\t\tcontext?: TContext\n\t ) => string)\n\n/** Decides whether one event reaches one subscriber. */\nexport type FilterFn<TInput, TEventData> = (params: {\n\tinput: TInput\n\tdata: TEventData\n}) => MaybePromise<boolean>\n\n/**\n * Checked when a subscription opens, before anything is sent. `true` allows\n * everyone; a function returns false (or throws) to refuse with FORBIDDEN.\n */\nexport type AuthFn<TInput, TContext> =\n\t| ((params: { input: TInput; ctx: TContext }) => MaybePromise<boolean>)\n\t| true\n\nexport type PublisherConfig = {\n\t/** Required name for tracing (e.g. 'chat.messages'). */\n\tname: string\n\t/**\n\t * Store recent events in a backlog list; new subscribers receive it before\n\t * live events. Default: false\n\t */\n\tuseBacklog?: boolean\n\t/** Maximum backlog items to keep (default: 50). */\n\tbacklogSize?: number\n\t/** Backlog TTL in seconds (default: 30). */\n\tbacklogTtl?: number\n\t/**\n\t * Also publish every payload to this channel (with its own backlog when\n\t * `useBacklog`). Subscribers still use `channel`. Equal to the primary\n\t * channel means no duplicate work.\n\t */\n\tmirrorChannel?: string\n\t/**\n\t * Log publish failures (validation or broker) instead of throwing them, so\n\t * a publish after a committed write cannot fail the request. No retry.\n\t */\n\tsafePublish?: boolean\n}\n\n/** Per-definition overrides of the factory queue bounds. */\nexport type ChannelQueueOptions = {\n\tmaxQueueSize?: number\n\tmaxIngressSize?: number\n\tmaxReplaySize?: number\n}\n\n/** Synchronous observational events; failures cannot interrupt delivery. */\nexport type PubSubMetric = { name: string; channel: string } & (\n\t| {\n\t\t\ttype: 'queue'\n\t\t\tstage: 'ingress' | 'replay' | 'delivery'\n\t\t\tdepth: number\n\t\t\tlimit: number\n\t }\n\t| { type: 'drop'; stage: 'ingress' | 'replay' | 'delivery'; count: number }\n\t| { type: 'reconnect' }\n\t| { type: 'parseError'; stage: 'ingress' | 'replay'; error: unknown }\n)\n\nexport type PubSubOptions<\n\tTDef extends FnDefinition,\n\tTInputSchema extends ObjectSchema,\n\tTEventSchema extends ZodType,\n\tTKey extends ProcedureKey<TDef>\n> = PublisherConfig &\n\tChannelQueueOptions & {\n\t\tchannel: ChannelDefinition<\n\t\t\tz.output<TInputSchema>,\n\t\t\tz.output<TEventSchema>,\n\t\t\tFnContext<TDef, TKey>\n\t\t>\n\t\t/** What the subscriber provides. */\n\t\tinputSchema: TInputSchema\n\t\t/** What gets published. */\n\t\teventSchema: TEventSchema\n\t\tfilterFn?: FilterFn<z.output<TInputSchema>, z.output<TEventSchema>>\n\t\tauthFn?: AuthFn<z.output<TInputSchema>, FnContext<TDef, TKey>>\n\t\t/**\n\t\t * When a slow subscriber's queue overflows (drop-oldest), enqueue this\n\t\t * marker INSTEAD of the new event so the subscriber resyncs from its\n\t\t * cursor. A wholly dropped item leaves no per-item gap a consumer could\n\t\t * detect, so the marker is the only reliable live signal of loss. Return\n\t\t * null to skip.\n\t\t */\n\t\toverflowMarker?: (\n\t\t\tinput: z.output<TInputSchema>\n\t\t) => z.output<TEventSchema> | null\n\t\ttags?: TDef['tag'][]\n\t\tsummary?: string\n\t\tdescription?: string\n\t}\n\nexport type PubSub<\n\tTDef extends FnDefinition,\n\tTInputSchema extends ObjectSchema,\n\tTEventSchema extends ZodType,\n\tTKey extends ProcedureKey<TDef>\n> = {\n\tsubscribe: FnProcedure<\n\t\tTDef,\n\t\tTKey,\n\t\tTInputSchema,\n\t\tSchema<\n\t\t\tAsyncGenerator<z.output<TEventSchema>, void, unknown>,\n\t\t\tAsyncGenerator<z.output<TEventSchema>, void, unknown>\n\t\t>\n\t>\n\tpublish: (data: z.input<TEventSchema>) => Promise<void>\n\t/** Publish a batch in one atomic round-trip; items may target different channels. */\n\tpublishMany: (items: readonly z.input<TEventSchema>[]) => Promise<void>\n\tgetSubscriptionChannelName: (params: {\n\t\tinput: z.output<TInputSchema>\n\t\tcontext: FnContext<TDef, TKey>\n\t}) => string\n\tgetPublishChannelName: (event: z.output<TEventSchema>) => string\n\t/** @deprecated Prefer the separate required-input resolver methods. */\n\tgetChannelName: (\n\t\tparams: Partial<z.output<TInputSchema>> | Partial<z.output<TEventSchema>>,\n\t\tcontext?: FnContext<TDef, TKey>\n\t) => string\n}\n\nexport type CreatePubSub<TDef extends FnDefinition> = <\n\tTInputSchema extends ObjectSchema,\n\tTEventSchema extends ZodType,\n\tTKey extends ProcedureKey<TDef> = TDef['default']\n>(\n\toptions: PubSubOptions<TDef, TInputSchema, TEventSchema, NoInfer<TKey>> &\n\t\tGuardOptions<TDef['guards']> &\n\t\tPick<\n\t\t\tFnRouteOptions<TDef, TKey, z.output<TInputSchema>>,\n\t\t\t'meta' | 'guardResolvers'\n\t\t> &\n\t\t/** Which `procedures` builder the subscribe route uses. */ ProcedureOption<\n\t\t\tTDef,\n\t\t\tTKey\n\t\t>\n) => PubSub<TDef, TInputSchema, TEventSchema, TKey>\n\nexport type PublisherOptions<TEventSchema extends ZodType> = PublisherConfig & {\n\t/** Static channel name, or a resolver over (partial) parsed event data. */\n\tchannel: string | ((params: Partial<z.output<TEventSchema>>) => string)\n\teventSchema: TEventSchema\n}\n\nexport type Publisher<TEventSchema extends ZodType> = {\n\tpublish: (data: z.input<TEventSchema>) => Promise<void>\n\tpublishMany: (items: readonly z.input<TEventSchema>[]) => Promise<void>\n\tgetChannelName: (params: Partial<z.output<TEventSchema>>) => string\n}\n\n/**\n * Publish-only counterpart to `createPubSub`, for buses whose subscribe side\n * lives elsewhere (e.g. an `fnLive` route sharing the channel and schema).\n */\nexport type CreatePublisher = <TEventSchema extends ZodType>(\n\toptions: PublisherOptions<TEventSchema>\n) => Publisher<TEventSchema>\n\nexport type PubSubRuntimeOptions = {\n\t/** Queue depths, drops, successful reconnects and parse failures. */\n\tonMetric?: (event: PubSubMetric) => void\n\t/**\n\t * The broker, or a function creating it on first use so importing routes\n\t * opens no connection: `transport: () => bunRedisTransport(getRedis())`.\n\t */\n\ttransport: PubSubTransport | (() => PubSubTransport)\n\t/**\n\t * Called per event dropped from ingress, replay or delivery queues.\n\t * Delivery drops count events before subscriber filtering.\n\t */\n\tonDrop?: (count: number, info: { name: string; channel: string }) => void\n\t/** Per-subscriber queue bound before drop-oldest (default: 1000). */\n\tmaxQueueSize?: number\n\t/** Pending raw messages per channel, before asynchronous parsing. */\n\tmaxIngressSize?: number\n\t/** Buffered live messages during replay. */\n\tmaxReplaySize?: number\n\t/** Broker subscription and backlog wait bound (default 10000ms). */\n\tinitializationTimeoutMs?: number\n\t/** Applied to channels, mirrors and therefore backlog keys. */\n\tnamespace?: string\n\t/** Close this transport only when its ownership is explicitly transferred. */\n\townsTransport?: boolean\n}\n\n/** @internal */\nexport type LiveRuntimeOptions = {\n\tfn: (options: Record<string, unknown>) => import('@orpc/server').AnyProcedure\n\ttracing: Tracing\n\tcreateLogger: (scope: string, span: SpanLike | undefined) => FnLogger\n\tpubsub?: PubSubRuntimeOptions | undefined\n}\n\n// ═══════════════════════════════════════════════════════════════════════════\n// Bounded queue\n// ═══════════════════════════════════════════════════════════════════════════\n\n/**\n * Bounded drop-oldest FIFO with \"one overflow marker per overflow episode\"\n * semantics.\n *\n * On the FIRST overflow of an episode the oldest message is dropped and the\n * marker from `createOverflowMarker` is enqueued INSTEAD of the new event - the\n * subscriber's resync-from-cursor recovers the loss. While that marker is still\n * queued, further overflows drop the oldest NON-marker message (the marker\n * itself is never displaced) and enqueue the new event WITHOUT a second marker:\n * the pending marker's resync already covers every drop that happens before it\n * is delivered. Without this dedupe a sustained overflow converges the whole\n * queue to markers - one full snapshot re-run per queued slot. Dequeuing the\n * marker ends the episode; the next overflow starts a fresh one.\n *\n * `createOverflowMarker` absent (or returning null) falls back to plain\n * drop-oldest with the new event enqueued.\n */\nexport function createBoundedEventQueue<T>(opts: {\n\tmaxSize: number\n\tcreateOverflowMarker?: () => T | null\n\t/** Called once per dropped message (metrics/counters). */\n\tonDrop?: () => void\n\tonDepth?: (depth: number) => void\n}) {\n\tpositiveInteger(opts.maxSize, 'maxSize')\n\tconst items: T[] = []\n\t// The queued marker while an overflow episode is open. Created once per\n\t// episode, so identity is the exact \"is this the pending marker?\" test.\n\tlet pendingOverflowMarker: T | null = null\n\n\treturn {\n\t\tget length() {\n\t\t\treturn items.length\n\t\t},\n\t\tenqueue(data: T): void {\n\t\t\ttry {\n\t\t\t\tif (items.length >= opts.maxSize) {\n\t\t\t\t\tif (pendingOverflowMarker !== null) {\n\t\t\t\t\t\t// Episode already signalled: drop the oldest non-marker message\n\t\t\t\t\t\t// and enqueue WITHOUT a second marker.\n\t\t\t\t\t\tconst dropIndex = items[0] === pendingOverflowMarker ? 1 : 0\n\t\t\t\t\t\tif (dropIndex >= items.length) {\n\t\t\t\t\t\t\t// Degenerate maxSize: the queue is just the pending marker, so\n\t\t\t\t\t\t\t// the new event is the drop - the marker's resync covers it.\n\t\t\t\t\t\t\tsafely(opts.onDrop)\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\t\t\t\t\t\titems.splice(dropIndex, 1)\n\t\t\t\t\t\tsafely(opts.onDrop)\n\t\t\t\t\t\titems.push(data)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\titems.shift()\n\t\t\t\t\tsafely(opts.onDrop)\n\t\t\t\t\tconst marker = opts.createOverflowMarker?.() ?? null\n\t\t\t\t\tif (marker !== null) {\n\t\t\t\t\t\tpendingOverflowMarker = marker\n\t\t\t\t\t\titems.push(marker)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\titems.push(data)\n\t\t\t} finally {\n\t\t\t\tsafely(() => opts.onDepth?.(items.length))\n\t\t\t}\n\t\t},\n\t\tdequeue(): T | undefined {\n\t\t\tconst next = items.shift()\n\t\t\tsafely(() => opts.onDepth?.(items.length))\n\t\t\tif (next !== undefined && next === pendingOverflowMarker) {\n\t\t\t\tpendingOverflowMarker = null\n\t\t\t}\n\t\t\treturn next\n\t\t}\n\t}\n}\n\n/**\n * One subscriber's ordered, bounded delivery. Events wait in a bounded\n * drop-oldest queue (see {@link createBoundedEventQueue}) BEFORE the\n * subscriber's filter runs; the filter runs in order as the consumer reads,\n * so a slow async filter neither reorders events nor lets pending work grow\n * past `maxSize`. Overflow markers skip the filter.\n */\nexport function createSubscriberDelivery<T>(options: {\n\tmaxSize: number\n\taccept?: ((data: T) => MaybePromise<boolean>) | undefined\n\toverflowMarker?: (() => T | null) | undefined\n\tonFilterError: (error: unknown) => void\n\tonDrop: () => void\n\tonDepth?: (depth: number) => void\n}) {\n\ttype Item = { data: T; marker: boolean }\n\tconst queue = createBoundedEventQueue<Item>({\n\t\tmaxSize: options.maxSize,\n\t\tcreateOverflowMarker: () => {\n\t\t\tconst marker = options.overflowMarker?.() ?? null\n\t\t\treturn marker === null ? null : { data: marker, marker: true }\n\t\t},\n\t\tonDrop: options.onDrop,\n\t\t...(options.onDepth ? { onDepth: options.onDepth } : {})\n\t})\n\tlet closed = false\n\tlet failure: unknown\n\tlet wake: (() => void) | null = null\n\tconst notify = () => {\n\t\twake?.()\n\t\twake = null\n\t}\n\n\tasync function* events(): AsyncGenerator<T, void, unknown> {\n\t\twhile (!closed) {\n\t\t\tconst item = queue.dequeue()\n\t\t\tif (!item) {\n\t\t\t\tawait new Promise<void>((resolve) => {\n\t\t\t\t\twake = resolve\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (!item.marker && options.accept) {\n\t\t\t\ttry {\n\t\t\t\t\tif (!(await options.accept(item.data))) continue\n\t\t\t\t} catch (error) {\n\t\t\t\t\tsafely(() => options.onFilterError(error))\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (closed) break\n\t\t\t}\n\t\t\tyield item.data\n\t\t}\n\t\tif (failure !== undefined) throw failure\n\t}\n\n\treturn {\n\t\tpush(data: T, marker = false) {\n\t\t\tif (closed) return\n\t\t\tqueue.enqueue({ data, marker })\n\t\t\tnotify()\n\t\t},\n\t\tevents: events(),\n\t\t/** Stop delivering; a parked read ends at once. */\n\t\tclose(error?: unknown) {\n\t\t\tif (closed) return\n\t\t\tfailure = error\n\t\t\tclosed = true\n\t\t\tsafely(() => options.onDepth?.(0))\n\t\t\tnotify()\n\t\t}\n\t}\n}\n\n// ═══════════════════════════════════════════════════════════════════════════\n// Runtime (internal: the typed surface is what `createFn` returns)\n// ═══════════════════════════════════════════════════════════════════════════\n\nconst DEFAULT_MAX_QUEUE_SIZE = 1000\n\n// Exponential resubscribe backoff with jitter so reconnecting subscribers don't stampede the broker.\nconst RESUBSCRIBE_BASE_DELAY_MS = 1000\nconst RESUBSCRIBE_MAX_DELAY_MS = 30_000\nconst RESUBSCRIBE_MAX_JITTER_MS = 250\n\nfunction getResubscribeDelayMs(attempt: number): number {\n\tconst base = Math.min(\n\t\tRESUBSCRIBE_BASE_DELAY_MS * 2 ** attempt,\n\t\tRESUBSCRIBE_MAX_DELAY_MS\n\t)\n\treturn base + Math.floor(Math.random() * RESUBSCRIBE_MAX_JITTER_MS)\n}\n\ntype Input = Record<string, unknown>\n\ntype LocalSubscriber = {\n\tisActive: () => boolean\n\tpush: (data: unknown, id?: string) => void\n\tgap: () => void\n\tfail: (error: unknown) => void\n}\n\ntype Hub = {\n\tsubscribers: Set<LocalSubscriber>\n\t/** Resolves after a successful broker subscription (or closure). */\n\tready: Promise<void>\n\tclose: () => void\n}\n\n/** An open subscription: registered, authorized and subscribed. */\nexport type LiveSubscription = {\n\t/** Live events, after the backlog replay. Ends when closed or aborted. */\n\tevents: AsyncGenerator<unknown, void, unknown>\n\t/** Release everything; safe to call more than once, and before `events` runs. */\n\tclose: () => void\n\tisClosed: () => boolean\n}\n\n/** @internal Untyped options; `PubSubOptions` is the typed surface. */\nexport type ChannelOptions = PublisherConfig &\n\tChannelQueueOptions & {\n\t\tchannel: ChannelDefinition<Input, unknown>\n\t\teventSchema: ZodType\n\t\tfilterFn?: FilterFn<Input, unknown>\n\t\tauthFn?: AuthFn<Input, unknown>\n\t\toverflowMarker?: (input: Input) => unknown\n\t}\n\n/** @internal */\nexport type Channel = {\n\t/** Authorize and subscribe; resolves once events can be delivered. */\n\topen: (options: {\n\t\tinput: Input\n\t\tcontext: unknown\n\t\tsignal: AbortSignal | undefined\n\t\trecoverGaps?: boolean\n\t}) => Promise<LiveSubscription>\n\tpublish: (data: unknown) => Promise<void>\n\tpublishMany: (items: readonly unknown[]) => Promise<void>\n\tgetChannelName: (params: Input, context?: unknown) => string\n\tgetSubscriptionChannelName: (params: {\n\t\tinput: Input\n\t\tcontext: unknown\n\t}) => string\n\tgetPublishChannelName: (event: Input) => string\n}\n\nconst resolveChannel = (\n\tchannel: ChannelDefinition<Input, unknown>,\n\tparams: Input,\n\tcontext?: unknown,\n\tpublishing = false\n) => {\n\tif (typeof channel === 'string') return channel\n\tif (typeof channel === 'function') return channel(params, context)\n\treturn publishing\n\t\t? channel.publish(params)\n\t\t: channel.subscribe({ input: params, context })\n}\n\n/** @internal */\nexport function createLiveRuntime(options: LiveRuntimeOptions) {\n\tconst { tracing, createLogger } = options\n\tconst logger = createLogger('pubsub', undefined)\n\tlet terminated = false\n\tlet shutdownPromise: Promise<void> | undefined\n\tconst releases = new Set<Promise<void>>()\n\tconst pendingInitialization = new Set<() => void>()\n\tconst pendingOpens = new Set<Promise<LiveSubscription>>()\n\tconst defaultMaxQueue = positiveInteger(\n\t\toptions.pubsub?.maxQueueSize ?? DEFAULT_MAX_QUEUE_SIZE,\n\t\t'maxQueueSize'\n\t)\n\tconst defaultMaxIngress = positiveInteger(\n\t\toptions.pubsub?.maxIngressSize ?? defaultMaxQueue,\n\t\t'maxIngressSize'\n\t)\n\tconst defaultMaxReplay = positiveInteger(\n\t\toptions.pubsub?.maxReplaySize ?? defaultMaxQueue,\n\t\t'maxReplaySize'\n\t)\n\tconst initializationTimeout = positiveInteger(\n\t\toptions.pubsub?.initializationTimeoutMs ?? 10000,\n\t\t'initializationTimeoutMs'\n\t)\n\tconst metric = (event: PubSubMetric) =>\n\t\tsafely(() => options.pubsub?.onMetric?.(event))\n\tconst namespace = options.pubsub?.namespace\n\tconst qualify = (name: string) => (namespace ? `${namespace}:${name}` : name)\n\tconst assertOpen = () => {\n\t\tif (terminated)\n\t\t\tthrow new ORPCError('SERVICE_UNAVAILABLE', {\n\t\t\t\tmessage: 'Live runtime has shut down'\n\t\t\t})\n\t}\n\tconst releaseTransport = (release: (() => Promise<void>) | null) => {\n\t\tif (!release) return\n\t\tconst task = Promise.resolve(release()).catch((error) => {\n\t\t\tlogger.warn('Failed to release subscription', {\n\t\t\t\terror: errorMessageOf(error)\n\t\t\t})\n\t\t})\n\t\treleases.add(task)\n\t\tvoid task.finally(() => releases.delete(task))\n\t}\n\n\t// Deploy drain: every open subscription registers its close here. On\n\t// SIGTERM the app ends them deliberately instead of letting the socket die\n\t// with the process: the generator returns, oRPC closes the SSE response and\n\t// the client's backoff reconnects to the new deployment.\n\tconst activeSubscriberCleanups = new Set<() => void>()\n\n\tlet transport: PubSubTransport | undefined\n\tconst requireTransport = () => {\n\t\tif (!options.pubsub) {\n\t\t\tthrow new Error(\n\t\t\t\t'orpc-fn: live routes need a transport, pass createFn({ pubsub: { transport } })'\n\t\t\t)\n\t\t}\n\t\tif (transport) return transport\n\t\t// A lazy transport is never created during or after shutdown.\n\t\tassertOpen()\n\t\tconst configured = options.pubsub.transport\n\t\ttransport = typeof configured === 'function' ? configured() : configured\n\t\treturn transport\n\t}\n\n\t/**\n\t * Shared publish pipeline: validate the raw event, resolve the channel from\n\t * the parsed event, then publish the raw event (atomically maintaining the\n\t * backlog when enabled) inside a producer span.\n\t */\n\tfunction createChannelPublisher(\n\t\tconfig: PublisherConfig & {\n\t\t\teventSchema: ZodType\n\t\t\tgetChannelName: (data: Input) => string\n\t\t}\n\t) {\n\t\tconst { name, eventSchema, getChannelName } = config\n\t\tconst mirrorChannel = config.mirrorChannel\n\t\t\t? qualify(config.mirrorChannel)\n\t\t\t: undefined\n\t\tif (config.backlogSize !== undefined)\n\t\t\tpositiveInteger(config.backlogSize, 'backlogSize')\n\t\tif (config.backlogTtl !== undefined)\n\t\t\tpositiveInteger(config.backlogTtl, 'backlogTtl')\n\t\tconst backlog: BacklogOptions | undefined = config.useBacklog\n\t\t\t? { size: config.backlogSize ?? 50, ttlSeconds: config.backlogTtl ?? 30 }\n\t\t\t: undefined\n\n\t\tconst toMessages = async (items: readonly unknown[]) => {\n\t\t\tconst messages: PubSubMessage[] = []\n\t\t\tfor (const item of items) {\n\t\t\t\tconst data = (await eventSchema.parseAsync(item)) as Input\n\t\t\t\tconst channel = getChannelName(data)\n\t\t\t\tconst payload = encodePayload(item)\n\t\t\t\tmessages.push({ channel, payload })\n\t\t\t\tif (mirrorChannel && mirrorChannel !== channel) {\n\t\t\t\t\tmessages.push({ channel: mirrorChannel, payload })\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn messages\n\t\t}\n\n\t\tconst send = (\n\t\t\toperation: 'publish' | 'publishMany',\n\t\t\titems: readonly unknown[]\n\t\t) =>\n\t\t\ttracing.inSpan(`${name}:${operation}`, 'PRODUCER', async (span) => {\n\t\t\t\tassertOpen()\n\t\t\t\tconst startTime = performance.now()\n\t\t\t\ttry {\n\t\t\t\t\tspan?.setAttribute('pubsub.operation', operation)\n\t\t\t\t\tspan?.setAttribute('pubsub.name', name)\n\t\t\t\t\tspan?.setAttribute('pubsub.batch_size', items.length)\n\t\t\t\t\tconst messages = await toMessages(items)\n\t\t\t\t\tconst first = messages[0]\n\t\t\t\t\tif (first) {\n\t\t\t\t\t\tspan?.setAttribute('pubsub.channel', first.channel)\n\t\t\t\t\t\tspan?.setAttribute('pubsub.payload_size', first.payload.length)\n\t\t\t\t\t}\n\t\t\t\t\tawait requireTransport().publish(messages, backlog)\n\t\t\t\t} finally {\n\t\t\t\t\tspan?.setAttribute(\n\t\t\t\t\t\t'pubsub.duration_ms',\n\t\t\t\t\t\tperformance.now() - startTime\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t})\n\n\t\tconst guarded = async (\n\t\t\toperation: 'publish' | 'publishMany',\n\t\t\titems: readonly unknown[]\n\t\t) => {\n\t\t\tif (!config.safePublish) return send(operation, items)\n\t\t\ttry {\n\t\t\t\tawait send(operation, items)\n\t\t\t} catch (error) {\n\t\t\t\tlogger.error('pubsub.publish_failed', {\n\t\t\t\t\tname,\n\t\t\t\t\t...errorAttributes(error)\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tpublish: (data: unknown) => guarded('publish', [data]),\n\t\t\tpublishMany: async (items: readonly unknown[]) => {\n\t\t\t\tif (items.length > 0) await guarded('publishMany', items)\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Hubs for one pub/sub definition, keyed by channel. Many subscribers can\n\t * share a channel (an org with many open tabs); one hub decodes and parses\n\t * each payload once and fans the event out to every local subscriber,\n\t * applying each subscriber's own filter. The hub also owns the broker\n\t * subscription and its resubscribe backoff.\n\t */\n\tfunction createChannelHubs(config: {\n\t\teventSchema: ZodType\n\t\tname: string\n\t\tmaxIngress: number\n\t}) {\n\t\tconst { eventSchema } = config\n\t\tconst hubs = new Map<string, Hub>()\n\n\t\tconst createHub = (channel: string): Hub => {\n\t\t\tconst subscribers = new Set<LocalSubscriber>()\n\t\t\tlet closed = false\n\t\t\tlet unsubscribe: (() => Promise<void>) | null = null\n\t\t\tlet attempt = 0\n\t\t\tlet timer: ReturnType<typeof setTimeout> | null = null\n\t\t\tlet markReady = () => {}\n\t\t\tlet connectedOnce = false\n\t\t\tlet connected = false\n\t\t\tlet ready: Promise<void>\n\t\t\tconst markPending = () => {\n\t\t\t\tready = new Promise<void>((resolve) => {\n\t\t\t\t\tmarkReady = resolve\n\t\t\t\t})\n\t\t\t}\n\t\t\tmarkPending()\n\n\t\t\tlet parsing = false\n\t\t\tconst ingress = createBoundedEventQueue<string>({\n\t\t\t\tmaxSize: config.maxIngress,\n\t\t\t\tonDepth: (depth) =>\n\t\t\t\t\tmetric({\n\t\t\t\t\t\ttype: 'queue',\n\t\t\t\t\t\tstage: 'ingress',\n\t\t\t\t\t\tdepth,\n\t\t\t\t\t\tlimit: config.maxIngress,\n\t\t\t\t\t\tname: config.name,\n\t\t\t\t\t\tchannel\n\t\t\t\t\t}),\n\t\t\t\tonDrop: () => {\n\t\t\t\t\tmetric({\n\t\t\t\t\t\ttype: 'drop',\n\t\t\t\t\t\tstage: 'ingress',\n\t\t\t\t\t\tcount: 1,\n\t\t\t\t\t\tname: config.name,\n\t\t\t\t\t\tchannel\n\t\t\t\t\t})\n\t\t\t\t\tsafely(() =>\n\t\t\t\t\t\toptions.pubsub?.onDrop?.(1, { name: config.name, channel })\n\t\t\t\t\t)\n\t\t\t\t\tfor (const sub of [...subscribers]) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tsub.gap()\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tsafely(() => sub.fail(error))\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t})\n\t\t\tconst parsePending = async () => {\n\t\t\t\tif (parsing) return\n\t\t\t\tparsing = true\n\t\t\t\ttry {\n\t\t\t\t\twhile (!closed) {\n\t\t\t\t\t\tconst raw = ingress.dequeue()\n\t\t\t\t\t\tif (raw === undefined) break\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst message = decodeMessage(raw)\n\t\t\t\t\t\t\tconst parsed = await eventSchema.parseAsync(message.value)\n\t\t\t\t\t\t\tif (closed) break\n\t\t\t\t\t\t\tfor (const sub of [...subscribers])\n\t\t\t\t\t\t\t\tif (sub.isActive()) {\n\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\tsub.push(parsed, message.id)\n\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\tsafely(() => sub.fail(error))\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tmetric({\n\t\t\t\t\t\t\t\ttype: 'parseError',\n\t\t\t\t\t\t\t\tstage: 'ingress',\n\t\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\t\tname: config.name,\n\t\t\t\t\t\t\t\tchannel\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tlogger.warn('pubsub.message_dropped', {\n\t\t\t\t\t\t\t\tchannel,\n\t\t\t\t\t\t\t\t...errorAttributes(error)\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} finally {\n\t\t\t\t\tparsing = false\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst release = releaseTransport\n\n\t\t\tconst scheduleResubscribe = (reason: string) => {\n\t\t\t\tif (closed || timer) return\n\t\t\t\tconst delayMs = getResubscribeDelayMs(attempt)\n\t\t\t\tattempt++\n\t\t\t\tlogger.warn('pubsub.resubscribe_scheduled', {\n\t\t\t\t\tchannel,\n\t\t\t\t\treason,\n\t\t\t\t\tattempt,\n\t\t\t\t\tdelayMs\n\t\t\t\t})\n\t\t\t\ttimer = setTimeout(() => {\n\t\t\t\t\ttimer = null\n\t\t\t\t\tif (closed) return\n\t\t\t\t\trelease(unsubscribe)\n\t\t\t\t\tunsubscribe = null\n\t\t\t\t\tvoid connect()\n\t\t\t\t}, delayMs)\n\t\t\t}\n\n\t\t\tconst connect = async () => {\n\t\t\t\ttry {\n\t\t\t\t\tconst next = await requireTransport().subscribe(\n\t\t\t\t\t\tchannel,\n\t\t\t\t\t\t(raw) => {\n\t\t\t\t\t\t\tif (closed) return\n\t\t\t\t\t\t\tingress.enqueue(raw)\n\t\t\t\t\t\t\tvoid parsePending()\n\t\t\t\t\t\t},\n\t\t\t\t\t\t(error) => {\n\t\t\t\t\t\t\tif (connected) {\n\t\t\t\t\t\t\t\tconnected = false\n\t\t\t\t\t\t\t\tmarkPending()\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tlogger.error('pubsub.subscription_lost', {\n\t\t\t\t\t\t\t\tchannel,\n\t\t\t\t\t\t\t\t...errorAttributes(error)\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tscheduleResubscribe('lost')\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tonReconnect: () => {\n\t\t\t\t\t\t\t\tif (closed) return\n\t\t\t\t\t\t\t\tmetric({ type: 'reconnect', name: config.name, channel })\n\t\t\t\t\t\t\t\tfor (const sub of [...subscribers]) {\n\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\tsub.gap()\n\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\tsafely(() => sub.fail(error))\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t)\n\t\t\t\t\tif (closed) return release(next)\n\t\t\t\t\tunsubscribe = next\n\t\t\t\t\tconnected = true\n\t\t\t\t\tif (connectedOnce) {\n\t\t\t\t\t\tmetric({ type: 'reconnect', name: config.name, channel })\n\t\t\t\t\t\tfor (const sub of [...subscribers]) {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tsub.gap()\n\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\tsafely(() => sub.fail(error))\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tconnectedOnce = true\n\t\t\t\t\tmarkReady()\n\t\t\t\t\tattempt = 0\n\t\t\t\t\tlogger.debug('pubsub.subscribed', { channel })\n\t\t\t\t} catch (error) {\n\t\t\t\t\tlogger.error('pubsub.subscribe_failed', {\n\t\t\t\t\t\tchannel,\n\t\t\t\t\t\t...errorAttributes(error)\n\t\t\t\t\t})\n\t\t\t\t\tscheduleResubscribe('subscribe-failed')\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tvoid connect()\n\n\t\t\treturn {\n\t\t\t\tsubscribers,\n\t\t\t\tget ready() {\n\t\t\t\t\treturn ready\n\t\t\t\t},\n\t\t\t\tclose: () => {\n\t\t\t\t\tclosed = true\n\t\t\t\t\tmetric({\n\t\t\t\t\t\ttype: 'queue',\n\t\t\t\t\t\tstage: 'ingress',\n\t\t\t\t\t\tdepth: 0,\n\t\t\t\t\t\tlimit: config.maxIngress,\n\t\t\t\t\t\tname: config.name,\n\t\t\t\t\t\tchannel\n\t\t\t\t\t})\n\t\t\t\t\tif (timer) clearTimeout(timer)\n\t\t\t\t\ttimer = null\n\t\t\t\t\tmarkReady()\n\t\t\t\t\trelease(unsubscribe)\n\t\t\t\t\tunsubscribe = null\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn function addLocalSubscriber(\n\t\t\tchannel: string,\n\t\t\tsubscriber: LocalSubscriber\n\t\t) {\n\t\t\tlet hub = hubs.get(channel)\n\t\t\tif (!hub) {\n\t\t\t\thub = createHub(channel)\n\t\t\t\thubs.set(channel, hub)\n\t\t\t}\n\t\t\thub.subscribers.add(subscriber)\n\t\t\tconst current = hub\n\t\t\treturn {\n\t\t\t\tready: current.ready,\n\t\t\t\tremove: () => {\n\t\t\t\t\tcurrent.subscribers.delete(subscriber)\n\t\t\t\t\tif (current.subscribers.size === 0 && hubs.get(channel) === current) {\n\t\t\t\t\t\tcurrent.close()\n\t\t\t\t\t\thubs.delete(channel)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Publish and open subscriptions on one channel definition. */\n\tfunction createChannel(channelOptions: ChannelOptions): Channel {\n\t\tconst {\n\t\t\tname,\n\t\t\tchannel,\n\t\t\teventSchema,\n\t\t\tfilterFn,\n\t\t\tauthFn,\n\t\t\toverflowMarker,\n\t\t\tuseBacklog = false\n\t\t} = channelOptions\n\n\t\tconst getChannelName = (params: Input, context?: unknown) =>\n\t\t\tqualify(resolveChannel(channel, params, context))\n\t\tconst getPublishChannel = (params: Input) =>\n\t\t\tqualify(resolveChannel(channel, params, undefined, true))\n\t\tconst maxQueue = positiveInteger(\n\t\t\tchannelOptions.maxQueueSize ?? defaultMaxQueue,\n\t\t\t'maxQueueSize'\n\t\t)\n\t\tconst maxIngress = positiveInteger(\n\t\t\tchannelOptions.maxIngressSize ?? defaultMaxIngress,\n\t\t\t'maxIngressSize'\n\t\t)\n\t\tconst maxReplay = positiveInteger(\n\t\t\tchannelOptions.maxReplaySize ?? defaultMaxReplay,\n\t\t\t'maxReplaySize'\n\t\t)\n\t\tconst addLocalSubscriber = createChannelHubs({\n\t\t\teventSchema,\n\t\t\tname,\n\t\t\tmaxIngress\n\t\t})\n\n\t\tconst openInternal: Channel['open'] = async ({\n\t\t\tinput,\n\t\t\tcontext,\n\t\t\tsignal,\n\t\t\trecoverGaps = false\n\t\t}) => {\n\t\t\tassertOpen()\n\t\t\tsignal?.throwIfAborted()\n\t\t\tconst initializing = new AbortController()\n\t\t\tconst transport = requireTransport()\n\t\t\tconst channelName = getChannelName(input, context)\n\t\t\tconst startTime = performance.now()\n\t\t\tconst span = tracing.startSpan(`${name}:subscribe`, 'SERVER', {\n\t\t\t\t'pubsub.channel': channelName,\n\t\t\t\t'pubsub.operation': 'subscribe',\n\t\t\t\t'pubsub.name': name\n\t\t\t})\n\t\t\tconst subscriberLogger = createLogger('pubsub', span)\n\t\t\tconst cancelInitialization = () =>\n\t\t\t\tinitializing.abort(\n\t\t\t\t\tsignal?.reason ?? new Error('Subscription initialization stopped')\n\t\t\t\t)\n\t\t\tpendingInitialization.add(cancelInitialization)\n\t\t\tsignal?.addEventListener('abort', cancelInitialization, { once: true })\n\t\t\tconst finishInitialization = () => {\n\t\t\t\tpendingInitialization.delete(cancelInitialization)\n\t\t\t\tsignal?.removeEventListener('abort', cancelInitialization)\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tif (\n\t\t\t\t\tauthFn !== undefined &&\n\t\t\t\t\tauthFn !== true &&\n\t\t\t\t\t!(await waitFor(\n\t\t\t\t\t\tPromise.resolve(authFn({ input, ctx: context })),\n\t\t\t\t\t\tinitializationTimeout,\n\t\t\t\t\t\tinitializing.signal\n\t\t\t\t\t))\n\t\t\t\t) {\n\t\t\t\t\tthrow new ORPCError('FORBIDDEN', {\n\t\t\t\t\t\tmessage: 'You do not have access to this subscription'\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tfinishInitialization()\n\t\t\t\ttracing.end(span, error)\n\t\t\t\tthrow error\n\t\t\t}\n\n\t\t\tsubscriberLogger.debug('pubsub.subscribing', { channel: channelName })\n\n\t\t\tlet messageCount = 0\n\t\t\tlet droppedCount = 0\n\t\t\tconst delivery = createSubscriberDelivery<unknown>({\n\t\t\t\tmaxSize: maxQueue,\n\t\t\t\tonDepth: (depth) =>\n\t\t\t\t\tmetric({\n\t\t\t\t\t\ttype: 'queue',\n\t\t\t\t\t\tstage: 'delivery',\n\t\t\t\t\t\tdepth,\n\t\t\t\t\t\tlimit: maxQueue,\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tchannel: channelName\n\t\t\t\t\t}),\n\t\t\t\taccept:\n\t\t\t\t\tfilterFn &&\n\t\t\t\t\t((data) => (data === LIVE_GAP ? true : filterFn({ input, data }))),\n\t\t\t\toverflowMarker: recoverGaps\n\t\t\t\t\t? () => LIVE_GAP\n\t\t\t\t\t: overflowMarker && (() => overflowMarker(input)),\n\t\t\t\tonFilterError: (error) =>\n\t\t\t\t\tsubscriberLogger.error('Error processing message', {\n\t\t\t\t\t\terror: errorMessageOf(error)\n\t\t\t\t\t}),\n\t\t\t\tonDrop: () => {\n\t\t\t\t\tdroppedCount++\n\t\t\t\t\tmetric({\n\t\t\t\t\t\ttype: 'drop',\n\t\t\t\t\t\tstage: 'delivery',\n\t\t\t\t\t\tcount: 1,\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tchannel: channelName\n\t\t\t\t\t})\n\t\t\t\t\tsafely(() =>\n\t\t\t\t\t\toptions.pubsub?.onDrop?.(1, { name, channel: channelName })\n\t\t\t\t\t)\n\t\t\t\t\tif (!recoverGaps && !overflowMarker)\n\t\t\t\t\t\tqueueMicrotask(() =>\n\t\t\t\t\t\t\tclose(\n\t\t\t\t\t\t\t\tnew ORPCError('SERVICE_UNAVAILABLE', {\n\t\t\t\t\t\t\t\t\tmessage: 'Subscription queue overflow; reconnect and resync'\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t})\n\n\t\t\tlet replaying: Array<{ data: unknown; id: string | undefined }> | null =\n\t\t\t\tuseBacklog ? [] : null\n\t\t\tlet replayGap = false\n\t\t\tconst seen = new Set<string>()\n\t\t\tconst dedupe = (id: string | undefined) => {\n\t\t\t\tif (!id) return false\n\t\t\t\tif (seen.has(id)) return true\n\t\t\t\tseen.add(id)\n\t\t\t\tif (\n\t\t\t\t\tseen.size >\n\t\t\t\t\tMath.max(maxReplay, maxQueue, channelOptions.backlogSize ?? 50) * 2\n\t\t\t\t)\n\t\t\t\t\tseen.delete(seen.values().next().value as string)\n\t\t\t\treturn false\n\t\t\t}\n\t\t\tconst push = (data: unknown, id?: string) => {\n\t\t\t\tmessageCount++\n\t\t\t\tif (replaying) {\n\t\t\t\t\tif (replaying.length >= maxReplay) {\n\t\t\t\t\t\treplaying.shift()\n\t\t\t\t\t\treplayGap = true\n\t\t\t\t\t\tmetric({\n\t\t\t\t\t\t\ttype: 'drop',\n\t\t\t\t\t\t\tstage: 'replay',\n\t\t\t\t\t\t\tcount: 1,\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\tchannel: channelName\n\t\t\t\t\t\t})\n\t\t\t\t\t\tsafely(() =>\n\t\t\t\t\t\t\toptions.pubsub?.onDrop?.(1, { name, channel: channelName })\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\treplaying.push({ data, id })\n\t\t\t\t\tmetric({\n\t\t\t\t\t\ttype: 'queue',\n\t\t\t\t\t\tstage: 'replay',\n\t\t\t\t\t\tdepth: replaying.length,\n\t\t\t\t\t\tlimit: maxReplay,\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tchannel: channelName\n\t\t\t\t\t})\n\t\t\t\t} else if (!dedupe(id)) delivery.push(data)\n\t\t\t}\n\t\t\tconst gap = () => {\n\t\t\t\tif (replaying) {\n\t\t\t\t\treplayGap = true\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tif (recoverGaps) delivery.push(LIVE_GAP)\n\t\t\t\telse if (overflowMarker) {\n\t\t\t\t\tconst marker = overflowMarker(input)\n\t\t\t\t\tif (marker !== null) delivery.push(marker, true)\n\t\t\t\t} else\n\t\t\t\t\tclose(\n\t\t\t\t\t\tnew ORPCError('SERVICE_UNAVAILABLE', {\n\t\t\t\t\t\t\tmessage: 'Subscription lost events; reconnect and resync'\n\t\t\t\t\t\t})\n\t\t\t\t\t)\n\t\t\t}\n\n\t\t\t// The one way a subscription ends, whatever ends it: abort, drain, the\n\t\t\t// stream finishing, or `close()`. Releases everything at once, even\n\t\t\t// while the stream is parked or not yet read.\n\t\t\tlet closed = false\n\t\t\tconst close = (...error: [] | [unknown]) => {\n\t\t\t\tif (closed) return\n\t\t\t\tclosed = true\n\t\t\t\tinitializing.abort(error[0] ?? new Error('Subscription closed'))\n\t\t\t\tdelivery.close(error[0])\n\t\t\t\tactiveSubscriberCleanups.delete(stop)\n\t\t\t\tsignal?.removeEventListener('abort', stop)\n\t\t\t\tlocal.remove()\n\t\t\t\tconst durationMs = performance.now() - startTime\n\t\t\t\tspan?.setAttribute('pubsub.duration_ms', durationMs)\n\t\t\t\tspan?.setAttribute('pubsub.message_count', messageCount)\n\t\t\t\tspan?.setAttribute('pubsub.dropped_count', droppedCount)\n\t\t\t\ttracing.end(span, ...error)\n\t\t\t\tsubscriberLogger.debug('pubsub.unsubscribed', {\n\t\t\t\t\tchannel: channelName,\n\t\t\t\t\tmessageCount,\n\t\t\t\t\tdroppedCount,\n\t\t\t\t\tdurationMs: Math.round(durationMs)\n\t\t\t\t})\n\t\t\t}\n\t\t\tconst stop = () => close()\n\t\t\tconst local = addLocalSubscriber(channelName, {\n\t\t\t\tisActive: () => !closed,\n\t\t\t\tpush,\n\t\t\t\tgap,\n\t\t\t\tfail: (error) => close(error)\n\t\t\t})\n\t\t\tactiveSubscriberCleanups.add(stop)\n\t\t\tsignal?.addEventListener('abort', stop)\n\t\t\tif (signal?.aborted) close()\n\n\t\t\ttry {\n\t\t\t\tawait waitFor(local.ready, initializationTimeout, initializing.signal)\n\t\t\t\tif (replaying && !closed) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst items = await waitFor(\n\t\t\t\t\t\t\ttransport.readBacklog(channelName),\n\t\t\t\t\t\t\tinitializationTimeout,\n\t\t\t\t\t\t\tinitializing.signal\n\t\t\t\t\t\t)\n\t\t\t\t\t\tspan?.setAttribute('pubsub.backlog_count', items.length)\n\t\t\t\t\t\tfor (const raw of items.slice(-maxReplay)) {\n\t\t\t\t\t\t\tif (closed) break\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tconst message = decodeMessage(raw)\n\t\t\t\t\t\t\t\tif (!dedupe(message.id)) {\n\t\t\t\t\t\t\t\t\tmessageCount++\n\t\t\t\t\t\t\t\t\tdelivery.push(\n\t\t\t\t\t\t\t\t\t\tawait waitFor(\n\t\t\t\t\t\t\t\t\t\t\teventSchema.parseAsync(message.value),\n\t\t\t\t\t\t\t\t\t\t\tinitializationTimeout,\n\t\t\t\t\t\t\t\t\t\t\tinitializing.signal\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\tmetric({\n\t\t\t\t\t\t\t\t\ttype: 'parseError',\n\t\t\t\t\t\t\t\t\tstage: 'replay',\n\t\t\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\t\t\tchannel: channelName\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t/* Malformed backlog entries are skipped. */\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (items.length > maxReplay) replayGap = true\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\treplayGap = true\n\t\t\t\t\t\tsubscriberLogger.warn('pubsub.replay_failed', {\n\t\t\t\t\t\t\tchannel: channelName,\n\t\t\t\t\t\t\t...errorAttributes(error)\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor (const { data, id } of replaying ?? [])\n\t\t\t\t\tif (!dedupe(id)) delivery.push(data)\n\t\t\t\treplaying = null\n\t\t\t\tmetric({\n\t\t\t\t\ttype: 'queue',\n\t\t\t\t\tstage: 'replay',\n\t\t\t\t\tdepth: 0,\n\t\t\t\t\tlimit: maxReplay,\n\t\t\t\t\tname,\n\t\t\t\t\tchannel: channelName\n\t\t\t\t})\n\t\t\t\tif (replayGap && !closed) gap()\n\t\t\t} catch (error) {\n\t\t\t\tif (!closed) {\n\t\t\t\t\tclose(error)\n\t\t\t\t\tthrow new ORPCError('SERVICE_UNAVAILABLE', {\n\t\t\t\t\t\tmessage: 'Unable to establish subscription',\n\t\t\t\t\t\tcause: error\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\tfinishInitialization()\n\t\t\t}\n\n\t\t\tasync function* events() {\n\t\t\t\ttry {\n\t\t\t\t\tyield* delivery.events\n\t\t\t\t} finally {\n\t\t\t\t\tclose()\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn { events: events(), close: () => close(), isClosed: () => closed }\n\t\t}\n\n\t\tconst { publish, publishMany } = createChannelPublisher({\n\t\t\t...channelOptions,\n\t\t\tgetChannelName: getPublishChannel\n\t\t})\n\n\t\tconst open: Channel['open'] = (params) => {\n\t\t\tconst task = openInternal(params)\n\t\t\tpendingOpens.add(task)\n\t\t\tvoid task.then(\n\t\t\t\t() => pendingOpens.delete(task),\n\t\t\t\t() => pendingOpens.delete(task)\n\t\t\t)\n\t\t\treturn task\n\t\t}\n\t\treturn {\n\t\t\topen,\n\t\t\tpublish,\n\t\t\tpublishMany,\n\t\t\tgetChannelName,\n\t\t\tgetSubscriptionChannelName: ({ input, context }) =>\n\t\t\t\tgetChannelName(input, context),\n\t\t\tgetPublishChannelName: getPublishChannel\n\t\t}\n\t}\n\n\tfunction createPubSub(\n\t\tpubsubOptions: ChannelOptions & {\n\t\t\tinputSchema: ZodType\n\t\t\tprocedure?: string\n\t\t\ttags?: string[]\n\t\t\tsummary?: string\n\t\t\tdescription?: string\n\t\t}\n\t) {\n\t\tconst { name } = pubsubOptions\n\t\tconst channel = createChannel(pubsubOptions)\n\n\t\tconst {\n\t\t\tchannel: _channel,\n\t\t\teventSchema: _eventSchema,\n\t\t\tinputSchema,\n\t\t\tfilterFn: _filterFn,\n\t\t\tauthFn: _authFn,\n\t\t\toverflowMarker: _overflowMarker,\n\t\t\tuseBacklog: _useBacklog,\n\t\t\tbacklogSize: _backlogSize,\n\t\t\tbacklogTtl: _backlogTtl,\n\t\t\tmirrorChannel: _mirrorChannel,\n\t\t\tsafePublish: _safePublish,\n\t\t\tmaxQueueSize: _maxQueueSize,\n\t\t\tmaxIngressSize: _maxIngressSize,\n\t\t\tmaxReplaySize: _maxReplaySize,\n\t\t\t...routeOptions\n\t\t} = pubsubOptions\n\t\tconst subscribe = options.fn({\n\t\t\t...routeOptions,\n\t\t\tname,\n\t\t\tstream: true,\n\t\t\tmethod: 'GET',\n\t\t\tinput: inputSchema,\n\t\t\tsummary: pubsubOptions.summary ?? `Subscribe to ${name}`,\n\t\t\thandler: async function* ({\n\t\t\t\tinput,\n\t\t\t\tcontext,\n\t\t\t\tsignal\n\t\t\t}: {\n\t\t\t\tinput: Input\n\t\t\t\tcontext: unknown\n\t\t\t\tsignal: AbortSignal | undefined\n\t\t\t}) {\n\t\t\t\tyield* (await channel.open({ input, context, signal })).events\n\t\t\t}\n\t\t})\n\n\t\tconst { publish, publishMany, getChannelName } = channel\n\t\treturn {\n\t\t\tsubscribe,\n\t\t\tpublish,\n\t\t\tpublishMany,\n\t\t\tgetChannelName,\n\t\t\tgetSubscriptionChannelName: channel.getSubscriptionChannelName,\n\t\t\tgetPublishChannelName: channel.getPublishChannelName\n\t\t}\n\t}\n\n\tfunction createPublisher(publisherOptions: PublisherOptions<ZodType>) {\n\t\tconst getChannelName = (params: Input) =>\n\t\t\tqualify(resolveChannel(publisherOptions.channel, params, undefined, true))\n\t\tconst { publish, publishMany } = createChannelPublisher({\n\t\t\t...publisherOptions,\n\t\t\tgetChannelName\n\t\t})\n\t\treturn { publish, publishMany, getChannelName }\n\t}\n\n\treturn {\n\t\tcreateChannel,\n\t\tshutdown: () => {\n\t\t\tif (shutdownPromise) return shutdownPromise\n\t\t\tterminated = true\n\t\t\tfor (const cancel of [...pendingInitialization]) safely(cancel)\n\t\t\tfor (const cleanup of [...activeSubscriberCleanups]) safely(cleanup)\n\t\t\tshutdownPromise = (async () => {\n\t\t\t\tawait Promise.allSettled([...pendingOpens])\n\t\t\t\tawait Promise.all([...releases])\n\t\t\t\tif (options.pubsub?.ownsTransport) await transport?.close?.()\n\t\t\t})()\n\t\t\treturn shutdownPromise\n\t\t},\n\t\tcreatePubSub,\n\t\tcreatePublisher,\n\t\t/** Open subscriptions of this instance (drain progress, gauges). */\n\t\tactivePubSubSubscriberCount: () => activeSubscriberCleanups.size,\n\t\t/** End every open subscription; returns how many were closed. */\n\t\tdrainPubSubSubscribers: () => {\n\t\t\tconst cleanups = [...activeSubscriberCleanups]\n\t\t\tactiveSubscriberCleanups.clear()\n\t\t\tfor (const cleanup of cleanups) {\n\t\t\t\ttry {\n\t\t\t\t\tcleanup()\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// A failed cleanup must not stop the drain.\n\t\t\t\t\tlogger.warn('Subscriber cleanup failed during drain', {\n\t\t\t\t\t\terror: errorMessageOf(error)\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\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AO,EAAE,EAAE,CAAC;oBACnD,IAAI,KAAK,GAAG,CAAC;wBACZ,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAA;oBAC1D,GAAG,CAAC,OAAO,CAAC,CAAA;gBACb,CAAC;gBACD,OAAO,QAAQ,CAAC,MAAM,CAAA;YACvB,CAAC,CAAC,EAAE,CAAA;QACL,CAAC;KACD,CAAA;AACF,CAAC","sourcesContent":["import type { Schema } from '@orpc/contract'\nimport { ORPCError } from '@orpc/server'\nimport type { ZodObject, ZodRawShape, ZodType, z } from 'zod'\nimport type { FnLogger } from '../logger.js'\nimport {\n\terrorAttributes,\n\terrorMessageOf,\n\ttype SpanLike,\n\ttype Tracing\n} from '../otel.js'\nimport type {\n\tGuardOptions,\n\tFnContext,\n\tFnDefinition,\n\tFnProcedure,\n\tFnRouteOptions,\n\tMaybePromise,\n\tProcedureKey,\n\tProcedureOption\n} from '../types.js'\nimport { decodeMessage, encodePayload } from './codec.js'\nimport { LIVE_GAP, positiveInteger, safely, waitFor } from './lifecycle.js'\nimport type {\n\tBacklogOptions,\n\tPubSubMessage,\n\tPubSubTransport\n} from './transport.js'\n\n// ═══════════════════════════════════════════════════════════════════════════\n// Types\n//\n// Publishers pass an event schema's INPUT (`z.input`); subscribers, filters\n// and channel resolvers see its OUTPUT (`z.output`). The raw input travels on\n// the wire and every receiver parses it once.\n// ═══════════════════════════════════════════════════════════════════════════\n\n/** Any Zod object schema, including `.strict()`, `.passthrough()` and `.catchall()`. */\nexport type ObjectSchema = ZodObject<ZodRawShape, z.core.$ZodObjectConfig>\n\n/**\n * A static channel name, or one derived from (partial) subscriber input or\n * event data.\n */\nexport type ChannelDefinition<TInput, TEventData, TContext = unknown> =\n\t| string\n\t| {\n\t\t\tsubscribe: (params: { input: TInput; context: TContext }) => string\n\t\t\tpublish: (event: TEventData) => string\n\t }\n\t| ((\n\t\t\tparams: Partial<TInput> | Partial<TEventData>,\n\t\t\tcontext?: TContext\n\t ) => string)\n\n/** Decides whether one event reaches one subscriber. */\nexport type FilterFn<TInput, TEventData> = (params: {\n\tinput: TInput\n\tdata: TEventData\n}) => MaybePromise<boolean>\n\n/**\n * Checked when a subscription opens, before anything is sent. `true` allows\n * everyone; a function returns false (or throws) to refuse with FORBIDDEN.\n */\nexport type AuthFn<TInput, TContext> =\n\t| ((params: {\n\t\t\tinput: TInput\n\t\t\tcontext: TContext\n\t\t\t/** @deprecated Use `context`. */\n\t\t\tctx: TContext\n\t }) => MaybePromise<boolean>)\n\t| true\n\nexport type PublisherConfig = {\n\t/** Required name for tracing (e.g. 'chat.messages'). */\n\tname: string\n\t/**\n\t * Store recent events in a backlog list; new subscribers receive it before\n\t * live events. Default: false\n\t */\n\tuseBacklog?: boolean\n\t/** Maximum backlog items to keep (default: 50). */\n\tbacklogSize?: number\n\t/** Backlog TTL in seconds (default: 30). */\n\tbacklogTtl?: number\n\t/**\n\t * Also publish every payload to this channel (with its own backlog when\n\t * `useBacklog`). Subscribers still use `channel`. Equal to the primary\n\t * channel means no duplicate work.\n\t */\n\tmirrorChannel?: string\n\t/**\n\t * Log publish failures (validation or broker) at `warn` instead of throwing\n\t * them, so a publish after a committed write cannot fail the request. No\n\t * retry. Default: `createFn({ pubsub: { safePublish } })`, else false.\n\t */\n\tsafePublish?: boolean\n}\n\n/** Per-definition overrides of the factory queue bounds. */\nexport type ChannelQueueOptions = {\n\tmaxQueueSize?: number\n\tmaxIngressSize?: number\n\tmaxReplaySize?: number\n}\n\n/** Synchronous observational events; failures cannot interrupt delivery. */\nexport type PubSubMetric = { name: string; channel: string } & (\n\t| {\n\t\t\ttype: 'queue'\n\t\t\tstage: 'ingress' | 'replay' | 'delivery'\n\t\t\tdepth: number\n\t\t\tlimit: number\n\t }\n\t| { type: 'drop'; stage: 'ingress' | 'replay' | 'delivery'; count: number }\n\t| { type: 'reconnect' }\n\t| { type: 'parseError'; stage: 'ingress' | 'replay'; error: unknown }\n)\n\nexport type PubSubOptions<\n\tTDef extends FnDefinition,\n\tTInputSchema extends ObjectSchema,\n\tTEventSchema extends ZodType,\n\tTKey extends ProcedureKey<TDef>\n> = PublisherConfig &\n\tChannelQueueOptions & {\n\t\tchannel: ChannelDefinition<\n\t\t\tz.output<TInputSchema>,\n\t\t\tz.output<TEventSchema>,\n\t\t\tFnContext<TDef, TKey>\n\t\t>\n\t\t/** What the subscriber provides. */\n\t\tinputSchema: TInputSchema\n\t\t/** What gets published. */\n\t\teventSchema: TEventSchema\n\t\tfilterFn?: FilterFn<z.output<TInputSchema>, z.output<TEventSchema>>\n\t\t/**\n\t\t * Who may subscribe. Required: `true` says on purpose that anyone who\n\t\t * passes the procedure builder may.\n\t\t */\n\t\tauthFn: AuthFn<z.output<TInputSchema>, FnContext<TDef, TKey>>\n\t\t/**\n\t\t * When a slow subscriber's queue overflows (drop-oldest), enqueue this\n\t\t * marker INSTEAD of the new event so the subscriber resyncs from its\n\t\t * cursor. A wholly dropped item leaves no per-item gap a consumer could\n\t\t * detect, so the marker is the only reliable live signal of loss. Return\n\t\t * null to skip.\n\t\t */\n\t\toverflowMarker?: (\n\t\t\tinput: z.output<TInputSchema>\n\t\t) => z.output<TEventSchema> | null\n\t\ttags?: TDef['tag'][]\n\t\tsummary?: string\n\t\tdescription?: string\n\t}\n\nexport type PubSub<\n\tTDef extends FnDefinition,\n\tTInputSchema extends ObjectSchema,\n\tTEventSchema extends ZodType,\n\tTKey extends ProcedureKey<TDef>\n> = {\n\tsubscribe: FnProcedure<\n\t\tTDef,\n\t\tTKey,\n\t\tTInputSchema,\n\t\tSchema<\n\t\t\tAsyncGenerator<z.output<TEventSchema>, void, unknown>,\n\t\t\tAsyncGenerator<z.output<TEventSchema>, void, unknown>\n\t\t>\n\t>\n\tpublish: (data: z.input<TEventSchema>) => Promise<void>\n\t/** Publish a batch in one atomic round-trip; items may target different channels. */\n\tpublishMany: (items: readonly z.input<TEventSchema>[]) => Promise<void>\n\tgetSubscriptionChannelName: (params: {\n\t\tinput: z.output<TInputSchema>\n\t\tcontext: FnContext<TDef, TKey>\n\t}) => string\n\tgetPublishChannelName: (event: z.output<TEventSchema>) => string\n\t/**\n\t * Read the bus on the server, without the route, its guards or `authFn`.\n\t * Resolves once subscribed; the events end when `signal` aborts.\n\t */\n\tlisten: (\n\t\tinput: z.output<TInputSchema>,\n\t\toptions?: ListenOptions<FnContext<TDef, TKey>>\n\t) => Promise<AsyncGenerator<z.output<TEventSchema>, void, unknown>>\n\t/** The parsed backlog of the channel an event goes to, oldest first. */\n\treadBacklog: (\n\t\tevent: Partial<z.output<TEventSchema>>\n\t) => Promise<z.output<TEventSchema>[]>\n}\n\nexport type ListenOptions<TContext = unknown> = {\n\tsignal?: AbortSignal\n\t/** For a channel resolver that reads the context. */\n\tcontext?: TContext\n}\n\nexport type CreatePubSub<TDef extends FnDefinition> = <\n\tTInputSchema extends ObjectSchema,\n\tTEventSchema extends ZodType,\n\tTKey extends ProcedureKey<TDef> = TDef['default']\n>(\n\toptions: PubSubOptions<TDef, TInputSchema, TEventSchema, NoInfer<TKey>> &\n\t\tGuardOptions<TDef['guards']> &\n\t\tPick<\n\t\t\tFnRouteOptions<TDef, TKey, z.output<TInputSchema>>,\n\t\t\t'meta' | 'guardResolvers'\n\t\t> &\n\t\t/** Which `procedures` builder the subscribe route uses. */ ProcedureOption<\n\t\t\tTDef,\n\t\t\tTKey\n\t\t>\n) => PubSub<TDef, TInputSchema, TEventSchema, TKey>\n\nexport type PublisherOptions<TEventSchema extends ZodType> = PublisherConfig & {\n\t/** Static channel name, or a resolver over (partial) parsed event data. */\n\tchannel: string | ((params: Partial<z.output<TEventSchema>>) => string)\n\teventSchema: TEventSchema\n}\n\nexport type Publisher<TEventSchema extends ZodType> = {\n\tpublish: (data: z.input<TEventSchema>) => Promise<void>\n\tpublishMany: (items: readonly z.input<TEventSchema>[]) => Promise<void>\n\tgetChannelName: (params: Partial<z.output<TEventSchema>>) => string\n\t/** Read the channel on the server. Resolves once subscribed. */\n\tlisten: (\n\t\tparams: Partial<z.output<TEventSchema>>,\n\t\toptions?: Omit<ListenOptions, 'context'>\n\t) => Promise<AsyncGenerator<z.output<TEventSchema>, void, unknown>>\n\t/** The channel's parsed backlog, oldest first. */\n\treadBacklog: (\n\t\tparams: Partial<z.output<TEventSchema>>\n\t) => Promise<z.output<TEventSchema>[]>\n}\n\n/**\n * Publish-only counterpart to `createPubSub`, for buses whose subscribe side\n * lives elsewhere (e.g. an `fnLive` route sharing the channel and schema).\n */\nexport type CreatePublisher = <TEventSchema extends ZodType>(\n\toptions: PublisherOptions<TEventSchema>\n) => Publisher<TEventSchema>\n\nexport type PubSubRuntimeOptions = {\n\t/** Queue depths, drops, successful reconnects and parse failures. */\n\tonMetric?: (event: PubSubMetric) => void\n\t/**\n\t * The broker, or a function creating it on first use so importing routes\n\t * opens no connection: `transport: () => bunRedisTransport(getRedis())`.\n\t */\n\ttransport: PubSubTransport | (() => PubSubTransport)\n\t/**\n\t * Called per event dropped from ingress, replay or delivery queues.\n\t * Delivery drops count events before subscriber filtering.\n\t */\n\tonDrop?: (count: number, info: { name: string; channel: string }) => void\n\t/** Per-subscriber queue bound before drop-oldest (default: 1000). */\n\tmaxQueueSize?: number\n\t/** Pending raw messages per channel, before asynchronous parsing. */\n\tmaxIngressSize?: number\n\t/** Buffered live messages during replay. */\n\tmaxReplaySize?: number\n\t/** Broker subscription and backlog wait bound (default 10000ms). */\n\tinitializationTimeoutMs?: number\n\t/** Applied to channels, mirrors and therefore backlog keys. */\n\tnamespace?: string\n\t/** Close this transport only when its ownership is explicitly transferred. */\n\townsTransport?: boolean\n\t/** Default `safePublish` for every definition of this factory. */\n\tsafePublish?: boolean\n\t/**\n\t * End route streams this long after they opened (plus up to 10% jitter),\n\t * so a client reconnects and its context, and with it its authorization,\n\t * is built again. The client helpers reconnect on their own. Default: never.\n\t */\n\tmaxStreamAgeMs?: number\n}\n\n/** @internal */\nexport type LiveRuntimeOptions = {\n\tfn: (options: Record<string, unknown>) => import('@orpc/server').AnyProcedure\n\ttracing: Tracing\n\tcreateLogger: (scope: string, span: SpanLike | undefined) => FnLogger\n\tpubsub?: PubSubRuntimeOptions | undefined\n}\n\n// ═══════════════════════════════════════════════════════════════════════════\n// Bounded queue\n// ═══════════════════════════════════════════════════════════════════════════\n\n/**\n * Bounded drop-oldest FIFO with \"one overflow marker per overflow episode\"\n * semantics.\n *\n * On the FIRST overflow of an episode the oldest message is dropped and the\n * marker from `createOverflowMarker` is enqueued INSTEAD of the new event - the\n * subscriber's resync-from-cursor recovers the loss. While that marker is still\n * queued, further overflows drop the oldest NON-marker message (the marker\n * itself is never displaced) and enqueue the new event WITHOUT a second marker:\n * the pending marker's resync already covers every drop that happens before it\n * is delivered. Without this dedupe a sustained overflow converges the whole\n * queue to markers - one full snapshot re-run per queued slot. Dequeuing the\n * marker ends the episode; the next overflow starts a fresh one.\n *\n * `createOverflowMarker` absent (or returning null) falls back to plain\n * drop-oldest with the new event enqueued.\n */\nexport function createBoundedEventQueue<T>(opts: {\n\tmaxSize: number\n\tcreateOverflowMarker?: () => T | null\n\t/** Called once per dropped message (metrics/counters). */\n\tonDrop?: () => void\n\tonDepth?: (depth: number) => void\n}) {\n\tpositiveInteger(opts.maxSize, 'maxSize')\n\tconst items: T[] = []\n\t// The queued marker while an overflow episode is open. Created once per\n\t// episode, so identity is the exact \"is this the pending marker?\" test.\n\tlet pendingOverflowMarker: T | null = null\n\n\treturn {\n\t\tget length() {\n\t\t\treturn items.length\n\t\t},\n\t\tenqueue(data: T): void {\n\t\t\ttry {\n\t\t\t\tif (items.length >= opts.maxSize) {\n\t\t\t\t\tif (pendingOverflowMarker !== null) {\n\t\t\t\t\t\t// Episode already signalled: drop the oldest non-marker message\n\t\t\t\t\t\t// and enqueue WITHOUT a second marker.\n\t\t\t\t\t\tconst dropIndex = items[0] === pendingOverflowMarker ? 1 : 0\n\t\t\t\t\t\tif (dropIndex >= items.length) {\n\t\t\t\t\t\t\t// Degenerate maxSize: the queue is just the pending marker, so\n\t\t\t\t\t\t\t// the new event is the drop - the marker's resync covers it.\n\t\t\t\t\t\t\tsafely(opts.onDrop)\n\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t}\n\t\t\t\t\t\titems.splice(dropIndex, 1)\n\t\t\t\t\t\tsafely(opts.onDrop)\n\t\t\t\t\t\titems.push(data)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\titems.shift()\n\t\t\t\t\tsafely(opts.onDrop)\n\t\t\t\t\tconst marker = opts.createOverflowMarker?.() ?? null\n\t\t\t\t\tif (marker !== null) {\n\t\t\t\t\t\tpendingOverflowMarker = marker\n\t\t\t\t\t\titems.push(marker)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\titems.push(data)\n\t\t\t} finally {\n\t\t\t\tsafely(() => opts.onDepth?.(items.length))\n\t\t\t}\n\t\t},\n\t\tdequeue(): T | undefined {\n\t\t\tconst next = items.shift()\n\t\t\tsafely(() => opts.onDepth?.(items.length))\n\t\t\tif (next !== undefined && next === pendingOverflowMarker) {\n\t\t\t\tpendingOverflowMarker = null\n\t\t\t}\n\t\t\treturn next\n\t\t}\n\t}\n}\n\n/**\n * One subscriber's ordered, bounded delivery. Events wait in a bounded\n * drop-oldest queue (see {@link createBoundedEventQueue}) BEFORE the\n * subscriber's filter runs; the filter runs in order as the consumer reads,\n * so a slow async filter neither reorders events nor lets pending work grow\n * past `maxSize`. Overflow markers skip the filter.\n */\nexport function createSubscriberDelivery<T>(options: {\n\tmaxSize: number\n\taccept?: ((data: T) => MaybePromise<boolean>) | undefined\n\toverflowMarker?: (() => T | null) | undefined\n\tonFilterError: (error: unknown) => void\n\tonDrop: () => void\n\tonDepth?: (depth: number) => void\n}) {\n\ttype Item = { data: T; marker: boolean }\n\tconst queue = createBoundedEventQueue<Item>({\n\t\tmaxSize: options.maxSize,\n\t\tcreateOverflowMarker: () => {\n\t\t\tconst marker = options.overflowMarker?.() ?? null\n\t\t\treturn marker === null ? null : { data: marker, marker: true }\n\t\t},\n\t\tonDrop: options.onDrop,\n\t\t...(options.onDepth ? { onDepth: options.onDepth } : {})\n\t})\n\tlet closed = false\n\tlet failure: unknown\n\tlet wake: (() => void) | null = null\n\tconst notify = () => {\n\t\twake?.()\n\t\twake = null\n\t}\n\n\tasync function* events(): AsyncGenerator<T, void, unknown> {\n\t\twhile (!closed) {\n\t\t\tconst item = queue.dequeue()\n\t\t\tif (!item) {\n\t\t\t\tawait new Promise<void>((resolve) => {\n\t\t\t\t\twake = resolve\n\t\t\t\t})\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (!item.marker && options.accept) {\n\t\t\t\ttry {\n\t\t\t\t\tif (!(await options.accept(item.data))) continue\n\t\t\t\t} catch (error) {\n\t\t\t\t\tsafely(() => options.onFilterError(error))\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (closed) break\n\t\t\t}\n\t\t\tyield item.data\n\t\t}\n\t\tif (failure !== undefined) throw failure\n\t}\n\n\treturn {\n\t\tpush(data: T, marker = false) {\n\t\t\tif (closed) return\n\t\t\tqueue.enqueue({ data, marker })\n\t\t\tnotify()\n\t\t},\n\t\tevents: events(),\n\t\t/** Stop delivering; a parked read ends at once. */\n\t\tclose(error?: unknown) {\n\t\t\tif (closed) return\n\t\t\tfailure = error\n\t\t\tclosed = true\n\t\t\tsafely(() => options.onDepth?.(0))\n\t\t\tnotify()\n\t\t}\n\t}\n}\n\n// ═══════════════════════════════════════════════════════════════════════════\n// Runtime (internal: the typed surface is what `createFn` returns)\n// ═══════════════════════════════════════════════════════════════════════════\n\nconst DEFAULT_MAX_QUEUE_SIZE = 1000\n\n// Exponential resubscribe backoff with jitter so reconnecting subscribers don't stampede the broker.\nconst RESUBSCRIBE_BASE_DELAY_MS = 1000\nconst RESUBSCRIBE_MAX_DELAY_MS = 30_000\nconst RESUBSCRIBE_MAX_JITTER_MS = 250\n\nfunction getResubscribeDelayMs(attempt: number): number {\n\tconst base = Math.min(\n\t\tRESUBSCRIBE_BASE_DELAY_MS * 2 ** attempt,\n\t\tRESUBSCRIBE_MAX_DELAY_MS\n\t)\n\treturn base + Math.floor(Math.random() * RESUBSCRIBE_MAX_JITTER_MS)\n}\n\ntype Input = Record<string, unknown>\n\ntype LocalSubscriber = {\n\tisActive: () => boolean\n\tpush: (data: unknown, id?: string) => void\n\tgap: () => void\n\tfail: (error: unknown) => void\n}\n\ntype Hub = {\n\tsubscribers: Set<LocalSubscriber>\n\t/** Resolves after a successful broker subscription (or closure). */\n\tready: Promise<void>\n\tclose: () => void\n}\n\n/** An open subscription: registered, authorized and subscribed. */\nexport type LiveSubscription = {\n\t/** Live events, after the backlog replay. Ends when closed or aborted. */\n\tevents: AsyncGenerator<unknown, void, unknown>\n\t/** Release everything; safe to call more than once, and before `events` runs. */\n\tclose: () => void\n\tisClosed: () => boolean\n}\n\n/** @internal Untyped options; `PubSubOptions` is the typed surface. */\nexport type ChannelOptions = PublisherConfig &\n\tChannelQueueOptions & {\n\t\tchannel: ChannelDefinition<Input, unknown>\n\t\teventSchema: ZodType\n\t\tfilterFn?: FilterFn<Input, unknown>\n\t\tauthFn?: AuthFn<Input, unknown>\n\t\toverflowMarker?: (input: Input) => unknown\n\t}\n\n/** @internal */\nexport type Channel = {\n\t/** Authorize and subscribe; resolves once events can be delivered. */\n\topen: (options: {\n\t\tinput: Input\n\t\tcontext: unknown\n\t\tsignal: AbortSignal | undefined\n\t\trecoverGaps?: boolean\n\t\t/** An in-process reader: no `authFn`, no maximum age. */\n\t\tserver?: boolean\n\t}) => Promise<LiveSubscription>\n\tpublish: (data: unknown) => Promise<void>\n\tpublishMany: (items: readonly unknown[]) => Promise<void>\n\treadBacklog: (event: Input) => Promise<unknown[]>\n\tgetChannelName: (params: Input, context?: unknown) => string\n\tgetSubscriptionChannelName: (params: {\n\t\tinput: Input\n\t\tcontext: unknown\n\t}) => string\n\tgetPublishChannelName: (event: Input) => string\n}\n\nconst resolveChannel = (\n\tchannel: ChannelDefinition<Input, unknown>,\n\tparams: Input,\n\tcontext?: unknown,\n\tpublishing = false\n) => {\n\tif (typeof channel === 'string') return channel\n\tif (typeof channel === 'function') return channel(params, context)\n\treturn publishing\n\t\t? channel.publish(params)\n\t\t: channel.subscribe({ input: params, context })\n}\n\n/** @internal */\nexport function createLiveRuntime(options: LiveRuntimeOptions) {\n\tconst { tracing, createLogger } = options\n\tconst logger = createLogger('pubsub', undefined)\n\tlet terminated = false\n\tlet shutdownPromise: Promise<void> | undefined\n\tconst releases = new Set<Promise<void>>()\n\tconst pendingInitialization = new Set<() => void>()\n\tconst pendingOpens = new Set<Promise<LiveSubscription>>()\n\tconst defaultMaxQueue = positiveInteger(\n\t\toptions.pubsub?.maxQueueSize ?? DEFAULT_MAX_QUEUE_SIZE,\n\t\t'maxQueueSize'\n\t)\n\tconst defaultMaxIngress = positiveInteger(\n\t\toptions.pubsub?.maxIngressSize ?? defaultMaxQueue,\n\t\t'maxIngressSize'\n\t)\n\tconst defaultMaxReplay = positiveInteger(\n\t\toptions.pubsub?.maxReplaySize ?? defaultMaxQueue,\n\t\t'maxReplaySize'\n\t)\n\tconst initializationTimeout = positiveInteger(\n\t\toptions.pubsub?.initializationTimeoutMs ?? 10000,\n\t\t'initializationTimeoutMs'\n\t)\n\tconst maxStreamAge =\n\t\toptions.pubsub?.maxStreamAgeMs === undefined\n\t\t\t? undefined\n\t\t\t: positiveInteger(options.pubsub.maxStreamAgeMs, 'maxStreamAgeMs')\n\tconst metric = (event: PubSubMetric) =>\n\t\tsafely(() => options.pubsub?.onMetric?.(event))\n\tconst namespace = options.pubsub?.namespace\n\tconst qualify = (name: string) => (namespace ? `${namespace}:${name}` : name)\n\tconst assertOpen = () => {\n\t\tif (terminated)\n\t\t\tthrow new ORPCError('SERVICE_UNAVAILABLE', {\n\t\t\t\tmessage: 'Live runtime has shut down'\n\t\t\t})\n\t}\n\tconst releaseTransport = (release: (() => Promise<void>) | null) => {\n\t\tif (!release) return\n\t\tconst task = Promise.resolve(release()).catch((error) => {\n\t\t\tlogger.warn('Failed to release subscription', {\n\t\t\t\terror: errorMessageOf(error)\n\t\t\t})\n\t\t})\n\t\treleases.add(task)\n\t\tvoid task.finally(() => releases.delete(task))\n\t}\n\n\t// Deploy drain: every open subscription registers its close here. On\n\t// SIGTERM the app ends them deliberately instead of letting the socket die\n\t// with the process: the generator returns, oRPC closes the SSE response and\n\t// the client's backoff reconnects to the new deployment.\n\tconst activeSubscriberCleanups = new Set<() => void>()\n\n\tlet transport: PubSubTransport | undefined\n\tconst requireTransport = () => {\n\t\tif (!options.pubsub) {\n\t\t\tthrow new Error(\n\t\t\t\t'orpc-fn: live routes need a transport, pass createFn({ pubsub: { transport } })'\n\t\t\t)\n\t\t}\n\t\tif (transport) return transport\n\t\t// A lazy transport is never created during or after shutdown.\n\t\tassertOpen()\n\t\tconst configured = options.pubsub.transport\n\t\ttransport = typeof configured === 'function' ? configured() : configured\n\t\treturn transport\n\t}\n\n\t/**\n\t * Shared publish pipeline: validate the raw event, resolve the channel from\n\t * the parsed event, then publish the raw event (atomically maintaining the\n\t * backlog when enabled) inside a producer span.\n\t */\n\tfunction createChannelPublisher(\n\t\tconfig: PublisherConfig & {\n\t\t\teventSchema: ZodType\n\t\t\tgetChannelName: (data: Input) => string\n\t\t}\n\t) {\n\t\tconst { name, eventSchema, getChannelName } = config\n\t\tconst mirrorChannel = config.mirrorChannel\n\t\t\t? qualify(config.mirrorChannel)\n\t\t\t: undefined\n\t\tif (config.backlogSize !== undefined)\n\t\t\tpositiveInteger(config.backlogSize, 'backlogSize')\n\t\tif (config.backlogTtl !== undefined)\n\t\t\tpositiveInteger(config.backlogTtl, 'backlogTtl')\n\t\tconst backlog: BacklogOptions | undefined = config.useBacklog\n\t\t\t? { size: config.backlogSize ?? 50, ttlSeconds: config.backlogTtl ?? 30 }\n\t\t\t: undefined\n\n\t\tconst toMessages = async (items: readonly unknown[]) => {\n\t\t\tconst messages: PubSubMessage[] = []\n\t\t\tfor (const item of items) {\n\t\t\t\tconst data = (await eventSchema.parseAsync(item)) as Input\n\t\t\t\tconst channel = getChannelName(data)\n\t\t\t\tconst payload = encodePayload(item)\n\t\t\t\tmessages.push({ channel, payload })\n\t\t\t\tif (mirrorChannel && mirrorChannel !== channel) {\n\t\t\t\t\tmessages.push({ channel: mirrorChannel, payload })\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn messages\n\t\t}\n\n\t\tconst send = (\n\t\t\toperation: 'publish' | 'publishMany',\n\t\t\titems: readonly unknown[]\n\t\t) =>\n\t\t\ttracing.inSpan(`${name}:${operation}`, 'PRODUCER', async (span) => {\n\t\t\t\tassertOpen()\n\t\t\t\tconst startTime = performance.now()\n\t\t\t\ttry {\n\t\t\t\t\tspan?.setAttribute('pubsub.operation', operation)\n\t\t\t\t\tspan?.setAttribute('pubsub.name', name)\n\t\t\t\t\tspan?.setAttribute('pubsub.batch_size', items.length)\n\t\t\t\t\tconst messages = await toMessages(items)\n\t\t\t\t\tconst first = messages[0]\n\t\t\t\t\tif (first) {\n\t\t\t\t\t\tspan?.setAttribute('pubsub.channel', first.channel)\n\t\t\t\t\t\tspan?.setAttribute('pubsub.payload_size', first.payload.length)\n\t\t\t\t\t}\n\t\t\t\t\tawait requireTransport().publish(messages, backlog)\n\t\t\t\t} finally {\n\t\t\t\t\tspan?.setAttribute(\n\t\t\t\t\t\t'pubsub.duration_ms',\n\t\t\t\t\t\tperformance.now() - startTime\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t})\n\n\t\tconst safePublish = config.safePublish ?? options.pubsub?.safePublish\n\t\tconst guarded = async (\n\t\t\toperation: 'publish' | 'publishMany',\n\t\t\titems: readonly unknown[]\n\t\t) => {\n\t\t\tif (!safePublish) return send(operation, items)\n\t\t\ttry {\n\t\t\t\tawait send(operation, items)\n\t\t\t} catch (error) {\n\t\t\t\tlogger.warn('pubsub.publish_failed', {\n\t\t\t\t\tname,\n\t\t\t\t\t...errorAttributes(error)\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tpublish: (data: unknown) => guarded('publish', [data]),\n\t\t\tpublishMany: async (items: readonly unknown[]) => {\n\t\t\t\tif (items.length > 0) await guarded('publishMany', items)\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Hubs for one pub/sub definition, keyed by channel. Many subscribers can\n\t * share a channel (an org with many open tabs); one hub decodes and parses\n\t * each payload once and fans the event out to every local subscriber,\n\t * applying each subscriber's own filter. The hub also owns the broker\n\t * subscription and its resubscribe backoff.\n\t */\n\tfunction createChannelHubs(config: {\n\t\teventSchema: ZodType\n\t\tname: string\n\t\tmaxIngress: number\n\t}) {\n\t\tconst { eventSchema } = config\n\t\tconst hubs = new Map<string, Hub>()\n\n\t\tconst createHub = (channel: string): Hub => {\n\t\t\tconst subscribers = new Set<LocalSubscriber>()\n\t\t\tlet closed = false\n\t\t\tlet unsubscribe: (() => Promise<void>) | null = null\n\t\t\tlet attempt = 0\n\t\t\tlet timer: ReturnType<typeof setTimeout> | null = null\n\t\t\tlet markReady = () => {}\n\t\t\tlet connectedOnce = false\n\t\t\tlet connected = false\n\t\t\tlet ready: Promise<void>\n\t\t\tconst markPending = () => {\n\t\t\t\tready = new Promise<void>((resolve) => {\n\t\t\t\t\tmarkReady = resolve\n\t\t\t\t})\n\t\t\t}\n\t\t\tmarkPending()\n\n\t\t\tlet parsing = false\n\t\t\tconst ingress = createBoundedEventQueue<string>({\n\t\t\t\tmaxSize: config.maxIngress,\n\t\t\t\tonDepth: (depth) =>\n\t\t\t\t\tmetric({\n\t\t\t\t\t\ttype: 'queue',\n\t\t\t\t\t\tstage: 'ingress',\n\t\t\t\t\t\tdepth,\n\t\t\t\t\t\tlimit: config.maxIngress,\n\t\t\t\t\t\tname: config.name,\n\t\t\t\t\t\tchannel\n\t\t\t\t\t}),\n\t\t\t\tonDrop: () => {\n\t\t\t\t\tmetric({\n\t\t\t\t\t\ttype: 'drop',\n\t\t\t\t\t\tstage: 'ingress',\n\t\t\t\t\t\tcount: 1,\n\t\t\t\t\t\tname: config.name,\n\t\t\t\t\t\tchannel\n\t\t\t\t\t})\n\t\t\t\t\tsafely(() =>\n\t\t\t\t\t\toptions.pubsub?.onDrop?.(1, { name: config.name, channel })\n\t\t\t\t\t)\n\t\t\t\t\tfor (const sub of [...subscribers]) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tsub.gap()\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tsafely(() => sub.fail(error))\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t})\n\t\t\tconst parsePending = async () => {\n\t\t\t\tif (parsing) return\n\t\t\t\tparsing = true\n\t\t\t\ttry {\n\t\t\t\t\twhile (!closed) {\n\t\t\t\t\t\tconst raw = ingress.dequeue()\n\t\t\t\t\t\tif (raw === undefined) break\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst message = decodeMessage(raw)\n\t\t\t\t\t\t\tconst parsed = await eventSchema.parseAsync(message.value)\n\t\t\t\t\t\t\tif (closed) break\n\t\t\t\t\t\t\tfor (const sub of [...subscribers])\n\t\t\t\t\t\t\t\tif (sub.isActive()) {\n\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\tsub.push(parsed, message.id)\n\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\tsafely(() => sub.fail(error))\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tmetric({\n\t\t\t\t\t\t\t\ttype: 'parseError',\n\t\t\t\t\t\t\t\tstage: 'ingress',\n\t\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\t\tname: config.name,\n\t\t\t\t\t\t\t\tchannel\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tlogger.warn('pubsub.message_dropped', {\n\t\t\t\t\t\t\t\tchannel,\n\t\t\t\t\t\t\t\t...errorAttributes(error)\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} finally {\n\t\t\t\t\tparsing = false\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst release = releaseTransport\n\n\t\t\tconst scheduleResubscribe = (reason: string) => {\n\t\t\t\tif (closed || timer) return\n\t\t\t\tconst delayMs = getResubscribeDelayMs(attempt)\n\t\t\t\tattempt++\n\t\t\t\tlogger.warn('pubsub.resubscribe_scheduled', {\n\t\t\t\t\tchannel,\n\t\t\t\t\treason,\n\t\t\t\t\tattempt,\n\t\t\t\t\tdelayMs\n\t\t\t\t})\n\t\t\t\ttimer = setTimeout(() => {\n\t\t\t\t\ttimer = null\n\t\t\t\t\tif (closed) return\n\t\t\t\t\trelease(unsubscribe)\n\t\t\t\t\tunsubscribe = null\n\t\t\t\t\tvoid connect()\n\t\t\t\t}, delayMs)\n\t\t\t}\n\n\t\t\tconst connect = async () => {\n\t\t\t\ttry {\n\t\t\t\t\tconst next = await requireTransport().subscribe(\n\t\t\t\t\t\tchannel,\n\t\t\t\t\t\t(raw) => {\n\t\t\t\t\t\t\tif (closed) return\n\t\t\t\t\t\t\tingress.enqueue(raw)\n\t\t\t\t\t\t\tvoid parsePending()\n\t\t\t\t\t\t},\n\t\t\t\t\t\t(error) => {\n\t\t\t\t\t\t\tif (connected) {\n\t\t\t\t\t\t\t\tconnected = false\n\t\t\t\t\t\t\t\tmarkPending()\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tlogger.error('pubsub.subscription_lost', {\n\t\t\t\t\t\t\t\tchannel,\n\t\t\t\t\t\t\t\t...errorAttributes(error)\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tscheduleResubscribe('lost')\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tonReconnect: () => {\n\t\t\t\t\t\t\t\tif (closed) return\n\t\t\t\t\t\t\t\tmetric({ type: 'reconnect', name: config.name, channel })\n\t\t\t\t\t\t\t\tfor (const sub of [...subscribers]) {\n\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\tsub.gap()\n\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\tsafely(() => sub.fail(error))\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t)\n\t\t\t\t\tif (closed) return release(next)\n\t\t\t\t\tunsubscribe = next\n\t\t\t\t\tconnected = true\n\t\t\t\t\tif (connectedOnce) {\n\t\t\t\t\t\tmetric({ type: 'reconnect', name: config.name, channel })\n\t\t\t\t\t\tfor (const sub of [...subscribers]) {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tsub.gap()\n\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\tsafely(() => sub.fail(error))\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tconnectedOnce = true\n\t\t\t\t\tmarkReady()\n\t\t\t\t\tattempt = 0\n\t\t\t\t\tlogger.debug('pubsub.subscribed', { channel })\n\t\t\t\t} catch (error) {\n\t\t\t\t\tlogger.error('pubsub.subscribe_failed', {\n\t\t\t\t\t\tchannel,\n\t\t\t\t\t\t...errorAttributes(error)\n\t\t\t\t\t})\n\t\t\t\t\tscheduleResubscribe('subscribe-failed')\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tvoid connect()\n\n\t\t\treturn {\n\t\t\t\tsubscribers,\n\t\t\t\tget ready() {\n\t\t\t\t\treturn ready\n\t\t\t\t},\n\t\t\t\tclose: () => {\n\t\t\t\t\tclosed = true\n\t\t\t\t\tmetric({\n\t\t\t\t\t\ttype: 'queue',\n\t\t\t\t\t\tstage: 'ingress',\n\t\t\t\t\t\tdepth: 0,\n\t\t\t\t\t\tlimit: config.maxIngress,\n\t\t\t\t\t\tname: config.name,\n\t\t\t\t\t\tchannel\n\t\t\t\t\t})\n\t\t\t\t\tif (timer) clearTimeout(timer)\n\t\t\t\t\ttimer = null\n\t\t\t\t\tmarkReady()\n\t\t\t\t\trelease(unsubscribe)\n\t\t\t\t\tunsubscribe = null\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn function addLocalSubscriber(\n\t\t\tchannel: string,\n\t\t\tsubscriber: LocalSubscriber\n\t\t) {\n\t\t\tlet hub = hubs.get(channel)\n\t\t\tif (!hub) {\n\t\t\t\thub = createHub(channel)\n\t\t\t\thubs.set(channel, hub)\n\t\t\t}\n\t\t\thub.subscribers.add(subscriber)\n\t\t\tconst current = hub\n\t\t\treturn {\n\t\t\t\tready: current.ready,\n\t\t\t\tremove: () => {\n\t\t\t\t\tcurrent.subscribers.delete(subscriber)\n\t\t\t\t\tif (current.subscribers.size === 0 && hubs.get(channel) === current) {\n\t\t\t\t\t\tcurrent.close()\n\t\t\t\t\t\thubs.delete(channel)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/** Publish and open subscriptions on one channel definition. */\n\tfunction createChannel(channelOptions: ChannelOptions): Channel {\n\t\tconst {\n\t\t\tname,\n\t\t\tchannel,\n\t\t\teventSchema,\n\t\t\tfilterFn,\n\t\t\tauthFn,\n\t\t\toverflowMarker,\n\t\t\tuseBacklog = false\n\t\t} = channelOptions\n\n\t\tconst getChannelName = (params: Input, context?: unknown) =>\n\t\t\tqualify(resolveChannel(channel, params, context))\n\t\tconst getPublishChannel = (params: Input) =>\n\t\t\tqualify(resolveChannel(channel, params, undefined, true))\n\t\tconst maxQueue = positiveInteger(\n\t\t\tchannelOptions.maxQueueSize ?? defaultMaxQueue,\n\t\t\t'maxQueueSize'\n\t\t)\n\t\tconst maxIngress = positiveInteger(\n\t\t\tchannelOptions.maxIngressSize ?? defaultMaxIngress,\n\t\t\t'maxIngressSize'\n\t\t)\n\t\tconst maxReplay = positiveInteger(\n\t\t\tchannelOptions.maxReplaySize ?? defaultMaxReplay,\n\t\t\t'maxReplaySize'\n\t\t)\n\t\tconst addLocalSubscriber = createChannelHubs({\n\t\t\teventSchema,\n\t\t\tname,\n\t\t\tmaxIngress\n\t\t})\n\n\t\tconst openInternal: Channel['open'] = async ({\n\t\t\tinput,\n\t\t\tcontext,\n\t\t\tsignal,\n\t\t\trecoverGaps = false,\n\t\t\tserver = false\n\t\t}) => {\n\t\t\tassertOpen()\n\t\t\tsignal?.throwIfAborted()\n\t\t\tconst initializing = new AbortController()\n\t\t\tconst transport = requireTransport()\n\t\t\tconst channelName = getChannelName(input, context)\n\t\t\tconst startTime = performance.now()\n\t\t\tconst span = tracing.startSpan(`${name}:subscribe`, 'SERVER', {\n\t\t\t\t'pubsub.channel': channelName,\n\t\t\t\t'pubsub.operation': 'subscribe',\n\t\t\t\t'pubsub.name': name\n\t\t\t})\n\t\t\tconst subscriberLogger = createLogger('pubsub', span)\n\t\t\tconst cancelInitialization = () =>\n\t\t\t\tinitializing.abort(\n\t\t\t\t\tsignal?.reason ?? new Error('Subscription initialization stopped')\n\t\t\t\t)\n\t\t\tpendingInitialization.add(cancelInitialization)\n\t\t\tsignal?.addEventListener('abort', cancelInitialization, { once: true })\n\t\t\tconst finishInitialization = () => {\n\t\t\t\tpendingInitialization.delete(cancelInitialization)\n\t\t\t\tsignal?.removeEventListener('abort', cancelInitialization)\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tif (\n\t\t\t\t\t!server &&\n\t\t\t\t\tauthFn !== undefined &&\n\t\t\t\t\tauthFn !== true &&\n\t\t\t\t\t!(await waitFor(\n\t\t\t\t\t\tPromise.resolve(authFn({ input, context, ctx: context })),\n\t\t\t\t\t\tinitializationTimeout,\n\t\t\t\t\t\tinitializing.signal\n\t\t\t\t\t))\n\t\t\t\t) {\n\t\t\t\t\tthrow new ORPCError('FORBIDDEN', {\n\t\t\t\t\t\tmessage: 'You do not have access to this subscription'\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tfinishInitialization()\n\t\t\t\ttracing.end(span, error)\n\t\t\t\tthrow error\n\t\t\t}\n\n\t\t\tsubscriberLogger.debug('pubsub.subscribing', { channel: channelName })\n\n\t\t\tlet messageCount = 0\n\t\t\tlet droppedCount = 0\n\t\t\tconst delivery = createSubscriberDelivery<unknown>({\n\t\t\t\tmaxSize: maxQueue,\n\t\t\t\tonDepth: (depth) =>\n\t\t\t\t\tmetric({\n\t\t\t\t\t\ttype: 'queue',\n\t\t\t\t\t\tstage: 'delivery',\n\t\t\t\t\t\tdepth,\n\t\t\t\t\t\tlimit: maxQueue,\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tchannel: channelName\n\t\t\t\t\t}),\n\t\t\t\taccept:\n\t\t\t\t\tfilterFn &&\n\t\t\t\t\t((data) => (data === LIVE_GAP ? true : filterFn({ input, data }))),\n\t\t\t\toverflowMarker: recoverGaps\n\t\t\t\t\t? () => LIVE_GAP\n\t\t\t\t\t: overflowMarker && (() => overflowMarker(input)),\n\t\t\t\tonFilterError: (error) =>\n\t\t\t\t\tsubscriberLogger.error('Error processing message', {\n\t\t\t\t\t\terror: errorMessageOf(error)\n\t\t\t\t\t}),\n\t\t\t\tonDrop: () => {\n\t\t\t\t\tdroppedCount++\n\t\t\t\t\tmetric({\n\t\t\t\t\t\ttype: 'drop',\n\t\t\t\t\t\tstage: 'delivery',\n\t\t\t\t\t\tcount: 1,\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tchannel: channelName\n\t\t\t\t\t})\n\t\t\t\t\tsafely(() =>\n\t\t\t\t\t\toptions.pubsub?.onDrop?.(1, { name, channel: channelName })\n\t\t\t\t\t)\n\t\t\t\t\tif (!recoverGaps && !overflowMarker)\n\t\t\t\t\t\tqueueMicrotask(() =>\n\t\t\t\t\t\t\tclose(\n\t\t\t\t\t\t\t\tnew ORPCError('SERVICE_UNAVAILABLE', {\n\t\t\t\t\t\t\t\t\tmessage: 'Subscription queue overflow; reconnect and resync'\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t})\n\n\t\t\tlet replaying: Array<{ data: unknown; id: string | undefined }> | null =\n\t\t\t\tuseBacklog ? [] : null\n\t\t\tlet replayGap = false\n\t\t\t// Overlap exists only between the backlog and live events that arrive\n\t\t\t// while it replays, so ids are recorded only then: at most twice\n\t\t\t// `maxReplay`, and nothing at all without a backlog.\n\t\t\tconst seen = useBacklog ? new Set<string>() : null\n\t\t\tconst dedupe = (id: string | undefined) => {\n\t\t\t\tif (!id || !seen) return false\n\t\t\t\tif (seen.has(id)) return true\n\t\t\t\tif (replaying) seen.add(id)\n\t\t\t\treturn false\n\t\t\t}\n\t\t\tconst push = (data: unknown, id?: string) => {\n\t\t\t\tmessageCount++\n\t\t\t\tif (replaying) {\n\t\t\t\t\tif (replaying.length >= maxReplay) {\n\t\t\t\t\t\treplaying.shift()\n\t\t\t\t\t\treplayGap = true\n\t\t\t\t\t\tmetric({\n\t\t\t\t\t\t\ttype: 'drop',\n\t\t\t\t\t\t\tstage: 'replay',\n\t\t\t\t\t\t\tcount: 1,\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\tchannel: channelName\n\t\t\t\t\t\t})\n\t\t\t\t\t\tsafely(() =>\n\t\t\t\t\t\t\toptions.pubsub?.onDrop?.(1, { name, channel: channelName })\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\treplaying.push({ data, id })\n\t\t\t\t\tmetric({\n\t\t\t\t\t\ttype: 'queue',\n\t\t\t\t\t\tstage: 'replay',\n\t\t\t\t\t\tdepth: replaying.length,\n\t\t\t\t\t\tlimit: maxReplay,\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tchannel: channelName\n\t\t\t\t\t})\n\t\t\t\t} else if (!dedupe(id)) delivery.push(data)\n\t\t\t}\n\t\t\tconst gap = () => {\n\t\t\t\tif (replaying) {\n\t\t\t\t\treplayGap = true\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tif (recoverGaps) delivery.push(LIVE_GAP)\n\t\t\t\telse if (overflowMarker) {\n\t\t\t\t\tconst marker = overflowMarker(input)\n\t\t\t\t\tif (marker !== null) delivery.push(marker, true)\n\t\t\t\t} else\n\t\t\t\t\tclose(\n\t\t\t\t\t\tnew ORPCError('SERVICE_UNAVAILABLE', {\n\t\t\t\t\t\t\tmessage: 'Subscription lost events; reconnect and resync'\n\t\t\t\t\t\t})\n\t\t\t\t\t)\n\t\t\t}\n\n\t\t\t// The one way a subscription ends, whatever ends it: abort, drain, the\n\t\t\t// stream finishing, or `close()`. Releases everything at once, even\n\t\t\t// while the stream is parked or not yet read.\n\t\t\tlet closed = false\n\t\t\tlet ageTimer: ReturnType<typeof setTimeout> | undefined\n\t\t\tconst close = (...error: [] | [unknown]) => {\n\t\t\t\tif (closed) return\n\t\t\t\tclosed = true\n\t\t\t\tclearTimeout(ageTimer)\n\t\t\t\tinitializing.abort(error[0] ?? new Error('Subscription closed'))\n\t\t\t\tdelivery.close(error[0])\n\t\t\t\tactiveSubscriberCleanups.delete(stop)\n\t\t\t\tsignal?.removeEventListener('abort', stop)\n\t\t\t\tlocal.remove()\n\t\t\t\tconst durationMs = performance.now() - startTime\n\t\t\t\tspan?.setAttribute('pubsub.duration_ms', durationMs)\n\t\t\t\tspan?.setAttribute('pubsub.message_count', messageCount)\n\t\t\t\tspan?.setAttribute('pubsub.dropped_count', droppedCount)\n\t\t\t\ttracing.end(span, ...error)\n\t\t\t\tsubscriberLogger.debug('pubsub.unsubscribed', {\n\t\t\t\t\tchannel: channelName,\n\t\t\t\t\tmessageCount,\n\t\t\t\t\tdroppedCount,\n\t\t\t\t\tdurationMs: Math.round(durationMs)\n\t\t\t\t})\n\t\t\t}\n\t\t\tconst stop = () => close()\n\t\t\tconst local = addLocalSubscriber(channelName, {\n\t\t\t\tisActive: () => !closed,\n\t\t\t\tpush,\n\t\t\t\tgap,\n\t\t\t\tfail: (error) => close(error)\n\t\t\t})\n\t\t\tactiveSubscriberCleanups.add(stop)\n\t\t\tsignal?.addEventListener('abort', stop)\n\t\t\tif (signal?.aborted) close()\n\t\t\tif (maxStreamAge !== undefined && !server && !closed) {\n\t\t\t\tageTimer = setTimeout(stop, maxStreamAge * (1 + Math.random() * 0.1))\n\t\t\t\t;(ageTimer as { unref?: () => void }).unref?.()\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tawait waitFor(local.ready, initializationTimeout, initializing.signal)\n\t\t\t\tif (replaying && !closed) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst items = await waitFor(\n\t\t\t\t\t\t\ttransport.readBacklog(channelName),\n\t\t\t\t\t\t\tinitializationTimeout,\n\t\t\t\t\t\t\tinitializing.signal\n\t\t\t\t\t\t)\n\t\t\t\t\t\tspan?.setAttribute('pubsub.backlog_count', items.length)\n\t\t\t\t\t\tfor (const raw of items.slice(-maxReplay)) {\n\t\t\t\t\t\t\tif (closed) break\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tconst message = decodeMessage(raw)\n\t\t\t\t\t\t\t\tif (!dedupe(message.id)) {\n\t\t\t\t\t\t\t\t\tmessageCount++\n\t\t\t\t\t\t\t\t\tdelivery.push(\n\t\t\t\t\t\t\t\t\t\tawait waitFor(\n\t\t\t\t\t\t\t\t\t\t\teventSchema.parseAsync(message.value),\n\t\t\t\t\t\t\t\t\t\t\tinitializationTimeout,\n\t\t\t\t\t\t\t\t\t\t\tinitializing.signal\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\tmetric({\n\t\t\t\t\t\t\t\t\ttype: 'parseError',\n\t\t\t\t\t\t\t\t\tstage: 'replay',\n\t\t\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\t\t\tchannel: channelName\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t\t/* Malformed backlog entries are skipped. */\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (items.length > maxReplay) replayGap = true\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\treplayGap = true\n\t\t\t\t\t\tsubscriberLogger.warn('pubsub.replay_failed', {\n\t\t\t\t\t\t\tchannel: channelName,\n\t\t\t\t\t\t\t...errorAttributes(error)\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor (const { data, id } of replaying ?? [])\n\t\t\t\t\tif (!dedupe(id)) delivery.push(data)\n\t\t\t\treplaying = null\n\t\t\t\tmetric({\n\t\t\t\t\ttype: 'queue',\n\t\t\t\t\tstage: 'replay',\n\t\t\t\t\tdepth: 0,\n\t\t\t\t\tlimit: maxReplay,\n\t\t\t\t\tname,\n\t\t\t\t\tchannel: channelName\n\t\t\t\t})\n\t\t\t\tif (replayGap && !closed) gap()\n\t\t\t} catch (error) {\n\t\t\t\tif (!closed) {\n\t\t\t\t\tclose(error)\n\t\t\t\t\tthrow new ORPCError('SERVICE_UNAVAILABLE', {\n\t\t\t\t\t\tmessage: 'Unable to establish subscription',\n\t\t\t\t\t\tcause: error\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\tfinishInitialization()\n\t\t\t}\n\n\t\t\tasync function* events() {\n\t\t\t\ttry {\n\t\t\t\t\tyield* delivery.events\n\t\t\t\t} finally {\n\t\t\t\t\tclose()\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn { events: events(), close: () => close(), isClosed: () => closed }\n\t\t}\n\n\t\tconst { publish, publishMany } = createChannelPublisher({\n\t\t\t...channelOptions,\n\t\t\tgetChannelName: getPublishChannel\n\t\t})\n\n\t\tconst readBacklog = async (event: Input) => {\n\t\t\tconst channelName = getPublishChannel(event)\n\t\t\tconst events: unknown[] = []\n\t\t\tfor (const raw of await requireTransport().readBacklog(channelName)) {\n\t\t\t\ttry {\n\t\t\t\t\tevents.push(await eventSchema.parseAsync(decodeMessage(raw).value))\n\t\t\t\t} catch (error) {\n\t\t\t\t\tmetric({\n\t\t\t\t\t\ttype: 'parseError',\n\t\t\t\t\t\tstage: 'replay',\n\t\t\t\t\t\terror,\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tchannel: channelName\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn events\n\t\t}\n\n\t\tconst open: Channel['open'] = (params) => {\n\t\t\tconst task = openInternal(params)\n\t\t\tpendingOpens.add(task)\n\t\t\tvoid task.then(\n\t\t\t\t() => pendingOpens.delete(task),\n\t\t\t\t() => pendingOpens.delete(task)\n\t\t\t)\n\t\t\treturn task\n\t\t}\n\t\treturn {\n\t\t\topen,\n\t\t\tpublish,\n\t\t\tpublishMany,\n\t\t\treadBacklog,\n\t\t\tgetChannelName,\n\t\t\tgetSubscriptionChannelName: ({ input, context }) =>\n\t\t\t\tgetChannelName(input, context),\n\t\t\tgetPublishChannelName: getPublishChannel\n\t\t}\n\t}\n\n\tfunction createPubSub(\n\t\tpubsubOptions: ChannelOptions & {\n\t\t\tinputSchema: ZodType\n\t\t\tprocedure?: string\n\t\t\ttags?: string[]\n\t\t\tsummary?: string\n\t\t\tdescription?: string\n\t\t}\n\t) {\n\t\tconst { name } = pubsubOptions\n\t\tif (pubsubOptions.authFn === undefined)\n\t\t\tthrow new TypeError(\n\t\t\t\t`orpc-fn: pub/sub ${name} needs an authFn; pass authFn: true to let every caller of its procedure subscribe`\n\t\t\t)\n\t\tconst channel = createChannel(pubsubOptions)\n\n\t\tconst {\n\t\t\tchannel: _channel,\n\t\t\teventSchema: _eventSchema,\n\t\t\tinputSchema,\n\t\t\tfilterFn: _filterFn,\n\t\t\tauthFn: _authFn,\n\t\t\toverflowMarker: _overflowMarker,\n\t\t\tuseBacklog: _useBacklog,\n\t\t\tbacklogSize: _backlogSize,\n\t\t\tbacklogTtl: _backlogTtl,\n\t\t\tmirrorChannel: _mirrorChannel,\n\t\t\tsafePublish: _safePublish,\n\t\t\tmaxQueueSize: _maxQueueSize,\n\t\t\tmaxIngressSize: _maxIngressSize,\n\t\t\tmaxReplaySize: _maxReplaySize,\n\t\t\t...routeOptions\n\t\t} = pubsubOptions\n\t\tconst subscribe = options.fn({\n\t\t\t...routeOptions,\n\t\t\tname,\n\t\t\tstream: true,\n\t\t\tmethod: 'GET',\n\t\t\tinput: inputSchema,\n\t\t\tsummary: pubsubOptions.summary ?? `Subscribe to ${name}`,\n\t\t\thandler: async function* ({\n\t\t\t\tinput,\n\t\t\t\tcontext,\n\t\t\t\tsignal\n\t\t\t}: {\n\t\t\t\tinput: Input\n\t\t\t\tcontext: unknown\n\t\t\t\tsignal: AbortSignal | undefined\n\t\t\t}) {\n\t\t\t\tyield* (await channel.open({ input, context, signal })).events\n\t\t\t}\n\t\t})\n\n\t\treturn {\n\t\t\tsubscribe,\n\t\t\tpublish: channel.publish,\n\t\t\tpublishMany: channel.publishMany,\n\t\t\tgetSubscriptionChannelName: channel.getSubscriptionChannelName,\n\t\t\tgetPublishChannelName: channel.getPublishChannelName,\n\t\t\tlisten: listener(channel),\n\t\t\treadBacklog: channel.readBacklog\n\t\t}\n\t}\n\n\tfunction createPublisher(publisherOptions: PublisherOptions<ZodType>) {\n\t\tconst channel = createChannel(publisherOptions)\n\t\treturn {\n\t\t\tpublish: channel.publish,\n\t\t\tpublishMany: channel.publishMany,\n\t\t\tgetChannelName: channel.getPublishChannelName,\n\t\t\tlisten: (params: Input, listenOptions: { signal?: AbortSignal } = {}) =>\n\t\t\t\tlistener(channel)(params, listenOptions),\n\t\t\treadBacklog: channel.readBacklog\n\t\t}\n\t}\n\n\tconst listener =\n\t\t(channel: Channel) =>\n\t\tasync (\n\t\t\tinput: Input,\n\t\t\t{ signal, context }: { signal?: AbortSignal; context?: unknown } = {}\n\t\t) =>\n\t\t\t(await channel.open({ input, context, signal, server: true })).events\n\n\treturn {\n\t\tcreateChannel,\n\t\tshutdown: () => {\n\t\t\tif (shutdownPromise) return shutdownPromise\n\t\t\tterminated = true\n\t\t\tfor (const cancel of [...pendingInitialization]) safely(cancel)\n\t\t\tfor (const cleanup of [...activeSubscriberCleanups]) safely(cleanup)\n\t\t\tshutdownPromise = (async () => {\n\t\t\t\tawait Promise.allSettled([...pendingOpens])\n\t\t\t\tawait Promise.all([...releases])\n\t\t\t\tif (options.pubsub?.ownsTransport) await transport?.close?.()\n\t\t\t})()\n\t\t\treturn shutdownPromise\n\t\t},\n\t\tcreatePubSub,\n\t\tcreatePublisher,\n\t\t/** Open subscriptions of this instance (drain progress, gauges). */\n\t\tactivePubSubSubscriberCount: () => activeSubscriberCleanups.size,\n\t\t/** End every open subscription; returns how many were closed. */\n\t\tdrainPubSubSubscribers: (drain?: {\n\t\t\toverMs: number\n\t\t}): number | Promise<number> => {\n\t\t\tconst cleanups = [...activeSubscriberCleanups]\n\t\t\tconst run = (cleanup: () => void) => {\n\t\t\t\ttry {\n\t\t\t\t\tcleanup()\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// A failed cleanup must not stop the drain.\n\t\t\t\t\tlogger.warn('Subscriber cleanup failed during drain', {\n\t\t\t\t\t\terror: errorMessageOf(error)\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (drain === undefined) {\n\t\t\t\tactiveSubscriberCleanups.clear()\n\t\t\t\tfor (const cleanup of cleanups) run(cleanup)\n\t\t\t\treturn cleanups.length\n\t\t\t}\n\t\t\tconst { overMs } = drain\n\t\t\tif (!Number.isFinite(overMs) || overMs < 0)\n\t\t\t\tthrow new RangeError('orpc-fn: overMs must be finite and nonnegative')\n\t\t\tconst step = overMs / Math.max(1, cleanups.length - 1)\n\t\t\treturn (async () => {\n\t\t\t\tfor (const [index, cleanup] of cleanups.entries()) {\n\t\t\t\t\tif (index > 0)\n\t\t\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, step))\n\t\t\t\t\trun(cleanup)\n\t\t\t\t}\n\t\t\t\treturn cleanups.length\n\t\t\t})()\n\t\t}\n\t}\n}\n"]}
|
package/dist/live/redis-bun.d.ts
CHANGED
|
@@ -11,6 +11,11 @@ export interface BunRedisClientLike {
|
|
|
11
11
|
onconnect: ((this: never) => void) | null;
|
|
12
12
|
onclose: ((this: never, error: Error) => void) | null;
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* What the command client must offer: `send`, and `duplicate` unless a
|
|
16
|
+
* `subscriber` is given. A wrapper with timeouts around Bun's client fits.
|
|
17
|
+
*/
|
|
18
|
+
export type BunRedisCommandClientLike = Pick<BunRedisClientLike, 'send'> & Partial<Pick<BunRedisClientLike, 'duplicate'>>;
|
|
14
19
|
/**
|
|
15
20
|
* `PubSubTransport` for Bun's built-in `RedisClient`. Subscriptions use a
|
|
16
21
|
* dedicated connection (`client.duplicate()` unless `subscriber` is given)
|
|
@@ -19,7 +24,7 @@ export interface BunRedisClientLike {
|
|
|
19
24
|
*
|
|
20
25
|
* Call `close()` on shutdown to close the subscriber connection it created.
|
|
21
26
|
*/
|
|
22
|
-
export declare function bunRedisTransport(client:
|
|
27
|
+
export declare function bunRedisTransport(client: BunRedisCommandClientLike, options?: {
|
|
23
28
|
subscriber?: BunRedisClientLike;
|
|
24
29
|
}): import("./transport.js").PubSubTransport & {
|
|
25
30
|
close(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redis-bun.d.ts","sourceRoot":"","sources":["../../src/live/redis-bun.ts"],"names":[],"mappings":"AAEA,KAAK,QAAQ,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;AAE1D,2DAA2D;AAC3D,MAAM,WAAW,kBAAkB;IAClC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IACvD,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAA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