@metamask-previews/perps-controller 26.2.0-preview-756d5c648 → 26.2.0-preview-2cd622db9

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.
@@ -1 +1 @@
1
- {"version":3,"file":"StreamChannelManager.d.ts","sourceRoot":"","sources":["../../src/services/StreamChannelManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAE7D;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAC;IACf,yDAAyD;IACzD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qDAAqD;IACrD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kCAAkC;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gEAAgE;IAChE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,mBAAmB,CAAC,IAAI,SAAS,OAAO,EAAE,IAAI;IACxD;;;;;;;;;;;OAWG;IACH,IAAI,CACF,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,IAAI,EAC7B,IAAI,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,KAAK,IAAI,EAClD,GAAG,EAAE,gBAAgB,EACrB,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,KAAK,IAAI,GACnD,MAAM,IAAI,CAAC;IACd;;;;;;;OAOG;IACH,IAAI,CAAC,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,CAAC;IACxD;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;OAIG;IACH,MAAM,CAAC,CAAC,IAAI,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E,2BAAgC,EAGpD;IAED;;;;OAIG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;;;;;;OAOG;IACH,SAAS,CAAC,IAAI,SAAS,OAAO,EAAE,EAC9B,GAAG,EAAE,gBAAgB,EACrB,MAAM,EAAE,mBAAmB,CAAC,IAAI,CAAC,EACjC,UAAU,EAAE,uBAAuB,CAAC,IAAI,CAAC,GACxC,MAAM,IAAI,CA0BZ;IAED;;;;;;;;;;;;OAYG;IACH,MAAM,CACJ,SAAS,EAAE,CAAC,GAAG,EAAE,gBAAgB,KAAK,OAAO,EAC7C,OAAO,EAAE,CAAC,GAAG,EAAE,gBAAgB,KAAK,gBAAgB,EACpD,OAAO,GAAE,mBAAwB,GAChC,IAAI,CAiDN;IAiDD;;;;;;;;OAQG;IACH,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,IAAI,CAuChC;IAED;;;OAGG;IACH,SAAS,IAAI,IAAI,CAMhB;IAED;;;;;OAKG;IACH,OAAO,CAAC,GAAG,EAAE,gBAAgB,GAAG,SAAS,OAAO,EAAE,GAAG,SAAS,CAE7D;IA6BD,kEAAkE;IAClE,KAAK,IAAI,IAAI,CAQZ;CA8VF"}
1
+ {"version":3,"file":"StreamChannelManager.d.ts","sourceRoot":"","sources":["../../src/services/StreamChannelManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAE7D;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,oDAAoD;IACpD,MAAM,EAAE,MAAM,CAAC;IACf,yDAAyD;IACzD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qDAAqD;IACrD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kCAAkC;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gEAAgE;IAChE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC,CAAC;AAEF;;;GAGG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BAAgB,GAAG,SAAS,OAAO,EAAE,GAAG,SAAS,CAE7D;IA6BD,kEAAkE;IAClE,KAAK,IAAI,IAAI,CAQZ;CA8WF"}
@@ -566,14 +566,31 @@ export class StreamChannelManager {
566
566
  return;
567
567
  }
568
568
  // Held while subscribing, so a watcher that answers at once does not
569
- // subscribe again.
570
- this.#stopConnectionWatch = () => undefined;
569
+ // subscribe again. What it answers may stop this watch and start another
570
+ // (a rebind), so the slot is only written while it still holds this one.
571
+ const placeholder = () => undefined;
572
+ this.#stopConnectionWatch = placeholder;
573
+ let stop;
571
574
  try {
572
- this.#stopConnectionWatch = this.#subscribeToConnectionState((state) => this.#onConnectionState(state));
575
+ stop = this.#subscribeToConnectionState((state) => this.#onConnectionState(state));
573
576
  }
574
577
  catch (error) {
575
578
  // No watch: the next channel to open tries again.
576
- this.#stopConnectionWatch = undefined;
579
+ if (this.#stopConnectionWatch === placeholder) {
580
+ this.#stopConnectionWatch = undefined;
581
+ }
582
+ this.#onError(error);
583
+ return;
584
+ }
585
+ if (this.#stopConnectionWatch === placeholder) {
586
+ this.#stopConnectionWatch = stop;
587
+ return;
588
+ }
589
+ // Superseded while it registered.
590
+ try {
591
+ stop();
592
+ }
593
+ catch (error) {
577
594
  this.#onError(error);
578
595
  }
579
596
  }
@@ -1 +1 @@
1
- {"version":3,"file":"StreamChannelManager.js","sourceRoot":"","sources":["../../src/services/StreamChannelManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AA+J7D;;;;;GAKG;AACH,SAAS,SAAS,CAAC,KAAc;IAC/B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IAC/C,CAAC;IACD,IAAI,KAAK,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I,MAAM,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QAChC,OAAO,CAAC,GAAG,OAAO,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC;IACD,IAAI,MAAM,CAAC,QAAQ,KAAK,OAAO,IAAI,MAAM,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED;;;;;GAKG;AACH,SAAS,OAAO,CAAC,KAAc;IAC7B,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AACnE,CAAC","sourcesContent":["import { STREAM_RETRY_CONFIG } from '../constants/perpsConfig.js';\nimport { WebSocketConnectionState } from '../types/index.js';\n\n/**\n * What one shared stream is: the stream name plus everything its source\n * reads. Two subscriptions with equal keys share one venue subscription.\n */\nexport type StreamChannelKey = {\n /** Stream name, such as `prices` or `orderBook`. */\n stream: string;\n /** Provider route, or the default route when omitted. */\n providerId?: string;\n /** Account, or the selected account when omitted. */\n accountId?: string;\n /** Market, for market streams. */\n symbol?: string;\n /** Any other option the source reads. Functions are ignored. */\n options?: Record<string, unknown>;\n};\n\n/**\n * The venue subscription behind a channel. `open` runs once for the first\n * subscriber and its cleanup once the last one leaves.\n */\nexport type StreamChannelSource<Args extends unknown[]> = {\n /**\n * Open the live stream.\n *\n * @param emit - Delivers a value to every subscriber.\n * @param fail - Reports a stream failure, with any detail the source adds\n * (such as the failing venue); the last value stays current. The source\n * stays attached, and heard, until the channel reopens it.\n * @param key - The key the channel opens under, which changes on `rebind`.\n * @param report - Tells the readers of a failure the source recovers from by\n * itself; the channel does not reopen it.\n * @returns Cleanup that stops the stream.\n */\n open(\n emit: (...args: Args) => void,\n fail: (error: Error, ...detail: unknown[]) => void,\n key: StreamChannelKey,\n report: (error: Error, ...detail: unknown[]) => void,\n ): () => void;\n /**\n * One REST read for while the stream is down: it seeds a channel that opens\n * while the transport is disconnected, and runs once each time the\n * connection drops. It is never repeated on a timer.\n * Resolving `undefined` delivers nothing.\n *\n * @param key - The channel's current key.\n */\n read?(key: StreamChannelKey): Promise<Args | undefined>;\n /**\n * Deliver the channel's value to a subscriber that joins an open channel.\n * Defaults to true; turn it off for event streams, such as trades, where a\n * replay would repeat an event.\n */\n replay?: boolean;\n /**\n * Fold each delivery into the value the channel keeps for replay and\n * `getLast`, for streams whose deliveries are deltas. Returning `undefined`\n * keeps no value. Defaults to the latest delivery.\n */\n reduce?(held: Args | undefined, next: Args): Args | undefined;\n /**\n * What a throttled or paused subscriber receives for the deliveries it\n * waited through: the `latest` one (default), all of them `merge`d with\n * `reduce`, or each of them in order from a `queue`. Streams of deltas and\n * events use the last two so that no change is lost.\n */\n delivery?: 'latest' | 'merge' | 'queue';\n /**\n * Stop and reopen the venue subscription when the connection comes back\n * after a drop, for streams the transport does not restore by itself. The\n * channel stays the one owner of that resubscribe, whatever its reader count.\n */\n reopenOnReconnect?: boolean;\n};\n\n/** One reader of a channel. */\nexport type StreamChannelSubscriber<Args extends unknown[]> = {\n /** Receives each value, at most once per `throttleMs` when set. */\n callback: (...args: Args) => void;\n /** Receives stream and seed-read failures. */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onError?: (error: Error, ...detail: any[]) => void;\n /** Minimum time between two deliveries to this subscriber. */\n throttleMs?: number;\n /**\n * Called when the channel moves to another context (provider or account)\n * and its last value no longer applies. The next delivery is the new\n * context's data.\n */\n onReset?: () => void;\n};\n\n/** How `rebind` treats the channels around the ones that move. */\nexport type StreamRebindOptions = {\n /**\n * Channels that keep their key but share the venue state the moving ones\n * use: stopped with them, and restarted after them.\n */\n restart?: (key: StreamChannelKey) => boolean;\n /** Runs once every source concerned has stopped, before any starts. */\n onStopped?: () => void;\n};\n\n/** Watches the transport the channels stream on. */\nexport type StreamConnectionWatcher = (\n listener: (state: WebSocketConnectionState) => void,\n) => () => void;\n\nexport type StreamChannelManagerOptions = {\n /** Connection state source; a drop triggers each channel's `read`. */\n subscribeToConnectionState?: StreamConnectionWatcher;\n /**\n * Receives subscriber callback failures, which never reach the venue, with\n * the key of the channel they came from when there is one.\n */\n onError?: (error: unknown, key?: StreamChannelKey) => void;\n};\n\ntype Reader = {\n subscriber: StreamChannelSubscriber<unknown[]>;\n /** The channel the reader is on; it changes when channels rebind. */\n channel: Channel;\n lastDeliveredAt: number;\n pending: unknown[][];\n timer: ReturnType<typeof setTimeout> | undefined;\n /** Joined while the stream was paused: it gets the replay on release. */\n joinedPaused: boolean;\n};\n\ntype Channel = {\n /** Serialized key the channel is filed under. */\n id: string;\n key: StreamChannelKey;\n source: StreamChannelSource<unknown[]>;\n readers: Set<Reader>;\n last: unknown[] | undefined;\n /** A value arrived since the channel opened or last moved. */\n hasValue: boolean;\n /** Bumped on every delivery so a stale seed read never overwrites a push. */\n version: number;\n /** Bumped on every start and stop, so a stopped source is never heard. */\n generation: number;\n stop: () => void;\n closed: boolean;\n /** The source failed and has not been reopened. */\n failed: boolean;\n /** Reopens since the source was last stable. */\n attempts: number;\n startedAt: number;\n /** A value arrived since the source last started. */\n delivered: boolean;\n retryTimer: ReturnType<typeof setTimeout> | undefined;\n /** Deliveries that arrived while the stream was paused. */\n held: unknown[][];\n};\n\n/**\n * Serialize a key so equal keys match regardless of property order.\n *\n * @param value - Key or nested option value.\n * @returns A stable string form; functions and `undefined` are dropped.\n */\nfunction stableKey(value: unknown): string {\n if (Array.isArray(value)) {\n return `[${value.map(stableKey).join(',')}]`;\n }\n if (value !== null && typeof value === 'object') {\n return `{${Object.keys(value)\n .sort()\n .filter((name) => {\n const entry = (value as Record<string, unknown>)[name];\n return entry !== undefined && typeof entry !== 'function';\n })\n .map(\n (name) =>\n `${JSON.stringify(name)}:${stableKey((value as Record<string, unknown>)[name])}`,\n )\n .join(',')}}`;\n }\n return JSON.stringify(value) ?? 'null';\n}\n\n/**\n * The one stream layer every client shares. Each key gets one ref-counted\n * channel over one venue subscription: it opens with the first subscriber,\n * replays its value to later ones, throttles each subscriber on its own and\n * stops with the last one. The channel is the one owner of reconnect and\n * resubscribe: a source that fails is reopened with a bounded backoff, and\n * again on reconnect, so readers never resubscribe and N readers cost one\n * resubscribe. REST is read only while the transport is down: to seed a\n * channel and once per drop.\n */\nexport class StreamChannelManager {\n readonly #channels = new Map<string, Channel>();\n\n readonly #subscribeToConnectionState: StreamConnectionWatcher | undefined;\n\n readonly #onError: (error: unknown, key?: StreamChannelKey) => void;\n\n #stopConnectionWatch: (() => void) | undefined;\n\n #connectionState: WebSocketConnectionState | undefined;\n\n /** The connection dropped since it was last connected. */\n #dropped = false;\n\n /** Pause holders per stream name. */\n readonly #pauses = new Map<string, number>();\n\n constructor(options: StreamChannelManagerOptions = {}) {\n this.#subscribeToConnectionState = options.subscribeToConnectionState;\n this.#onError = options.onError ?? ((): void => undefined);\n }\n\n /**\n * Open channels, for diagnostics and tests.\n *\n * @returns The number of open channels.\n */\n get size(): number {\n return this.#channels.size;\n }\n\n /**\n * Join the channel for `key`, opening it when it is the first subscriber.\n *\n * @param key - What the channel streams.\n * @param source - Venue subscription used when the channel opens.\n * @param subscriber - Callbacks and throttle for this reader.\n * @returns Cleanup that leaves the channel.\n */\n subscribe<Args extends unknown[]>(\n key: StreamChannelKey,\n source: StreamChannelSource<Args>,\n subscriber: StreamChannelSubscriber<Args>,\n ): () => void {\n const id = stableKey(key);\n const open = this.#channels.get(id);\n const channel = open ?? this.#createChannel(id, key, source);\n const reader: Reader = {\n subscriber: subscriber as StreamChannelSubscriber<unknown[]>,\n channel,\n lastDeliveredAt: 0,\n pending: [],\n timer: undefined,\n joinedPaused: false,\n };\n if (open) {\n this.#join(open, reader);\n if (open.failed && open.retryTimer === undefined) {\n // A new reader is a fresh reason to reach the venue, once its\n // attempts are spent; a pending retry keeps its backoff.\n this.#reopen(open);\n }\n } else {\n // The reader joins before the source opens, so a value the source\n // delivers while opening reaches it.\n channel.readers.add(reader);\n this.#open(channel);\n }\n return () => this.#leave(reader);\n }\n\n /**\n * Move every open channel whose key is no longer current to its next key,\n * such as after the provider or the selected account changed. Every stale\n * source stops before any new one starts, so venue state the old sources\n * shared is released first. Each reader's `onReset` is called when the\n * channel had a value; the channel then reopens under the new key, or its\n * readers join the channel already open there. Reader cleanups stay valid.\n *\n * @param isCurrent - Whether a key still matches the context.\n * @param nextKey - The key a stale channel moves to.\n * @param options - Channels to restart alongside, and a hook between the\n * stops and the starts.\n */\n rebind(\n isCurrent: (key: StreamChannelKey) => boolean,\n nextKey: (key: StreamChannelKey) => StreamChannelKey,\n options: StreamRebindOptions = {},\n ): void {\n const open = [...this.#channels.values()];\n const stale = open.filter((channel) => !isCurrent(channel.key));\n const restarted =\n stale.length > 0 && options.restart\n ? open.filter(\n (channel) =>\n !stale.includes(channel) && options.restart?.(channel.key),\n )\n : [];\n for (const channel of stale) {\n this.#channels.delete(channel.id);\n this.#stopSource(channel);\n }\n for (const channel of restarted) {\n this.#stopSource(channel);\n }\n options.onStopped?.();\n\n let providerMoved = false;\n for (const channel of stale) {\n // A source stopped in this pass may have closed this channel.\n if (channel.closed) {\n continue;\n }\n const key = nextKey(channel.key);\n providerMoved ||= key.providerId !== channel.key.providerId;\n this.#move(channel, key);\n }\n for (const channel of restarted) {\n if (!channel.closed) {\n this.#reopen(channel);\n }\n }\n if (providerMoved) {\n // The connection watch answered for the old transport.\n this.#stopWatch();\n }\n if (this.#channels.size > 0) {\n // Also when a reader that left during its reset closed the last channel.\n this.#watchConnection();\n }\n if (this.#isDown()) {\n for (const channel of stale) {\n if (!channel.closed && !channel.hasValue) {\n this.#seed(channel);\n }\n }\n }\n }\n\n /**\n * Reset a stopped channel's readers and reopen it under another key.\n *\n * @param channel - The stopped channel.\n * @param key - The key it moves to.\n */\n #move(channel: Channel, key: StreamChannelKey): void {\n const id = stableKey(key);\n // Readers hold nothing to reset when no value arrived since the last move.\n const { hasValue } = channel;\n channel.last = undefined;\n channel.hasValue = false;\n channel.held = [];\n channel.attempts = 0;\n // A seed read still in flight answers for the old key.\n channel.version += 1;\n const readers = [...channel.readers];\n for (const reader of readers) {\n this.#cancelPending(reader);\n try {\n if (hasValue) {\n reader.subscriber.onReset?.();\n }\n } catch (error) {\n this.#onError(error, channel.key);\n }\n }\n if (channel.closed) {\n return;\n }\n const existing = this.#channels.get(id);\n if (existing) {\n channel.closed = true;\n const remaining = [...channel.readers];\n channel.readers.clear();\n for (const reader of remaining) {\n reader.channel = existing;\n this.#join(existing, reader);\n }\n return;\n }\n channel.id = id;\n channel.key = key;\n this.#channels.set(id, channel);\n this.#start(channel);\n }\n\n /**\n * Stop delivering one stream while an operation runs. Values keep arriving\n * and are held as the source's `delivery` says; when the last holder\n * releases, each reader receives them together with the throttled\n * deliveries it was still waiting for.\n *\n * @param stream - Stream name, matched against every channel's `key.stream`.\n * @returns Release; calling it again does nothing.\n */\n pause(stream: string): () => void {\n this.#pauses.set(stream, (this.#pauses.get(stream) ?? 0) + 1);\n let released = false;\n return () => {\n if (released) {\n return;\n }\n released = true;\n const count = (this.#pauses.get(stream) ?? 1) - 1;\n if (count > 0) {\n this.#pauses.set(stream, count);\n return;\n }\n this.#pauses.delete(stream);\n for (const channel of [...this.#channels.values()]) {\n if (channel.key.stream !== stream) {\n continue;\n }\n const { held } = channel;\n channel.held = [];\n for (const reader of [...channel.readers]) {\n if (reader.joinedPaused) {\n // Its replay holds everything that arrived during the pause.\n reader.joinedPaused = false;\n if (channel.last && channel.source.replay !== false) {\n this.#deliver(reader, channel.last);\n }\n continue;\n }\n for (const args of held) {\n reader.pending = combine(channel.source, reader.pending, args);\n }\n // A throttled delivery that is not due yet keeps its own timer.\n if (held.length > 0 || reader.timer === undefined) {\n this.#flush(reader);\n }\n }\n }\n };\n }\n\n /**\n * Stop and restart every open channel's source, keeping readers and last\n * values, such as when a socket that looks open has stopped delivering.\n */\n reopenAll(): void {\n for (const channel of [...this.#channels.values()]) {\n if (!channel.closed) {\n this.#reopen(channel);\n }\n }\n }\n\n /**\n * The value an open channel keeps.\n *\n * @param key - What the channel streams.\n * @returns The last delivered (or reduced) arguments, or `undefined`.\n */\n getLast(key: StreamChannelKey): readonly unknown[] | undefined {\n return this.#channels.get(stableKey(key))?.last;\n }\n\n /**\n * Add a reader to an open channel and replay its last value.\n *\n * @param channel - The open channel.\n * @param reader - The joining reader.\n */\n #join(channel: Channel, reader: Reader): void {\n channel.readers.add(reader);\n if (this.#pauses.has(channel.key.stream)) {\n reader.joinedPaused = true;\n return;\n }\n const { last, version } = channel;\n if (last && channel.source.replay !== false) {\n // Replay after `subscribe` returns, so callers hold their cleanup.\n queueMicrotask(() => {\n if (\n reader.channel === channel &&\n channel.readers.has(reader) &&\n channel.version === version\n ) {\n this.#deliver(reader, last);\n }\n });\n }\n }\n\n /** Stop every channel; their subscribers receive nothing more. */\n clear(): void {\n for (const channel of [...this.#channels.values()]) {\n for (const reader of channel.readers) {\n clearTimeout(reader.timer);\n }\n channel.readers.clear();\n this.#close(channel.id, channel);\n }\n }\n\n #createChannel(\n id: string,\n key: StreamChannelKey,\n source: StreamChannelSource<unknown[]>,\n ): Channel {\n return {\n id,\n key,\n source,\n readers: new Set(),\n last: undefined,\n hasValue: false,\n version: 0,\n generation: 0,\n stop: (): void => undefined,\n closed: false,\n failed: false,\n attempts: 0,\n startedAt: 0,\n delivered: false,\n retryTimer: undefined,\n held: [],\n };\n }\n\n #open(channel: Channel): void {\n this.#channels.set(channel.id, channel);\n this.#watchConnection();\n this.#start(channel);\n // Seed only a channel that opens while the transport is known to be down;\n // a connected stream delivers its own first value.\n if (this.#isDown()) {\n this.#seed(channel);\n }\n }\n\n /**\n * Whether the transport is known not to be connected.\n *\n * @returns True while the last reported state is not connected.\n */\n #isDown(): boolean {\n return (\n this.#connectionState !== undefined &&\n this.#connectionState !== WebSocketConnectionState.Connected\n );\n }\n\n #start(channel: Channel): void {\n clearTimeout(channel.retryTimer);\n channel.retryTimer = undefined;\n channel.generation += 1;\n channel.failed = false;\n channel.delivered = false;\n channel.startedAt = Date.now();\n const { generation } = channel;\n const isCurrent = (): boolean =>\n !channel.closed && channel.generation === generation;\n const fail = (error: Error, detail: unknown[]): void => {\n if (isCurrent()) {\n this.#fail(channel, error, detail);\n }\n };\n try {\n const stop = channel.source.open(\n (...args) => {\n if (isCurrent()) {\n channel.delivered = true;\n this.#emit(channel, args);\n }\n },\n (error, ...detail) => fail(error, detail),\n channel.key,\n (error, ...detail) => {\n if (isCurrent()) {\n this.#report(channel, error, detail);\n }\n },\n );\n if (isCurrent()) {\n channel.stop = stop;\n } else {\n // Closed, moved or failed while opening.\n this.#runStop(stop, channel.key);\n }\n } catch (error) {\n queueMicrotask(() => fail(toError(error), []));\n }\n }\n\n /**\n * Stop and start a channel's source with a fresh retry budget.\n *\n * @param channel - The channel to reopen.\n */\n #reopen(channel: Channel): void {\n channel.attempts = 0;\n this.#stopSource(channel);\n this.#start(channel);\n }\n\n #stopSource(channel: Channel): void {\n const { stop } = channel;\n channel.stop = (): void => undefined;\n // From here on nothing the old source says is heard.\n channel.generation += 1;\n clearTimeout(channel.retryTimer);\n channel.retryTimer = undefined;\n this.#runStop(stop, channel.key);\n }\n\n #runStop(stop: () => void, key: StreamChannelKey): void {\n try {\n stop();\n } catch (error) {\n this.#onError(error, key);\n }\n }\n\n #cancelPending(reader: Reader): void {\n clearTimeout(reader.timer);\n reader.timer = undefined;\n reader.pending = [];\n }\n\n #seed(channel: Channel): void {\n const { source, version } = channel;\n if (!source.read) {\n return;\n }\n source\n .read(channel.key)\n .then((args) => {\n if (args && !channel.closed && channel.version === version) {\n this.#emit(channel, args);\n }\n })\n // A failed REST seed leaves the live stream running.\n .catch((error: unknown) => {\n if (!channel.closed && channel.version === version) {\n this.#report(channel, toError(error), []);\n }\n });\n }\n\n #emit(channel: Channel, args: unknown[]): void {\n if (channel.closed) {\n return;\n }\n const { source } = channel;\n channel.last = source.reduce ? source.reduce(channel.last, args) : args;\n channel.hasValue = true;\n channel.version += 1;\n if (this.#pauses.has(channel.key.stream)) {\n channel.held = combine(channel.source, channel.held, args);\n return;\n }\n for (const reader of [...channel.readers]) {\n this.#deliver(reader, args);\n }\n }\n\n /**\n * Handle a source failure: tell the readers and reopen the source with a\n * bounded backoff, also when it delivers meanwhile: one part of a source may\n * stream while the part that failed does not. Once the attempts are spent the\n * source stays attached as it is, and the channel reopens it when the\n * connection comes back, on a move, on `reopenAll` and for a new reader.\n *\n * @param channel - The failing channel.\n * @param error - The failure.\n * @param detail - Detail the source adds, such as the failing venue.\n */\n #fail(channel: Channel, error: Error, detail: unknown[]): void {\n if (\n channel.delivered &&\n Date.now() - channel.startedAt >= STREAM_RETRY_CONFIG.StableMs\n ) {\n channel.attempts = 0;\n }\n channel.failed = true;\n if (\n channel.retryTimer === undefined &&\n channel.attempts < STREAM_RETRY_CONFIG.MaxAttempts\n ) {\n const delay = Math.min(\n STREAM_RETRY_CONFIG.BaseDelayMs * 2 ** channel.attempts,\n STREAM_RETRY_CONFIG.MaxDelayMs,\n );\n channel.attempts += 1;\n channel.retryTimer = setTimeout(() => {\n this.#stopSource(channel);\n this.#start(channel);\n }, delay);\n }\n this.#report(channel, error, detail);\n }\n\n #report(channel: Channel, error: Error, detail: unknown[]): void {\n for (const reader of [...channel.readers]) {\n try {\n reader.subscriber.onError?.(error, ...detail);\n } catch (callbackError) {\n this.#onError(callbackError, channel.key);\n }\n }\n }\n\n #deliver(reader: Reader, args: unknown[]): void {\n const { throttleMs } = reader.subscriber;\n if (!throttleMs || throttleMs <= 0) {\n this.#call(reader, args);\n return;\n }\n const wait = reader.lastDeliveredAt + throttleMs - Date.now();\n if (wait <= 0 && reader.timer === undefined) {\n this.#call(reader, args);\n return;\n }\n const { channel } = reader;\n reader.pending = combine(channel.source, reader.pending, args);\n reader.timer ??= setTimeout(\n () => {\n reader.timer = undefined;\n // A pause delivers what is pending itself when it ends.\n if (this.#pauses.has(reader.channel.key.stream)) {\n return;\n }\n this.#flush(reader);\n },\n Math.max(wait, 0),\n );\n }\n\n /**\n * Deliver everything a reader is waiting for now.\n *\n * @param reader - The reader.\n */\n #flush(reader: Reader): void {\n const { pending } = reader;\n this.#cancelPending(reader);\n for (const args of pending) {\n if (!reader.channel.readers.has(reader)) {\n return;\n }\n this.#call(reader, args);\n }\n }\n\n #call(reader: Reader, args: unknown[]): void {\n reader.lastDeliveredAt = Date.now();\n try {\n reader.subscriber.callback(...args);\n } catch (error) {\n this.#onError(error, reader.channel.key);\n }\n }\n\n #leave(reader: Reader): void {\n const { channel } = reader;\n if (!channel.readers.delete(reader)) {\n return;\n }\n this.#cancelPending(reader);\n if (channel.readers.size === 0) {\n this.#close(channel.id, channel);\n }\n }\n\n #close(id: string, channel: Channel): void {\n if (channel.closed) {\n return;\n }\n channel.closed = true;\n if (this.#channels.get(id) === channel) {\n this.#channels.delete(id);\n }\n this.#stopSource(channel);\n if (this.#channels.size === 0) {\n this.#stopWatch();\n }\n }\n\n #stopWatch(): void {\n const stopWatch = this.#stopConnectionWatch;\n this.#stopConnectionWatch = undefined;\n this.#connectionState = undefined;\n this.#dropped = false;\n try {\n stopWatch?.();\n } catch (error) {\n this.#onError(error);\n }\n }\n\n /** Watch the transport while any channel is open. */\n #watchConnection(): void {\n if (this.#stopConnectionWatch || !this.#subscribeToConnectionState) {\n return;\n }\n // Held while subscribing, so a watcher that answers at once does not\n // subscribe again.\n this.#stopConnectionWatch = (): void => undefined;\n try {\n this.#stopConnectionWatch = this.#subscribeToConnectionState((state) =>\n this.#onConnectionState(state),\n );\n } catch (error) {\n // No watch: the next channel to open tries again.\n this.#stopConnectionWatch = undefined;\n this.#onError(error);\n }\n }\n\n /**\n * Read each channel's REST source once when a live connection drops. When it\n * comes back, reopen the failed channels and those the transport does not\n * restore by itself.\n *\n * @param state - The new transport state.\n */\n #onConnectionState(state: WebSocketConnectionState): void {\n const previous = this.#connectionState;\n this.#connectionState = state;\n if (state !== WebSocketConnectionState.Connected) {\n if (previous === WebSocketConnectionState.Connected) {\n this.#dropped = true;\n for (const channel of [...this.#channels.values()]) {\n this.#seed(channel);\n }\n }\n return;\n }\n const dropped = this.#dropped;\n this.#dropped = false;\n if (previous === state) {\n return;\n }\n for (const channel of [...this.#channels.values()]) {\n if (\n !channel.closed &&\n (channel.failed || (dropped && channel.source.reopenOnReconnect))\n ) {\n this.#reopen(channel);\n }\n }\n }\n}\n\n/**\n * Add a delivery to the ones a reader has yet to receive.\n *\n * @param source - The channel's source, which says how they combine.\n * @param pending - Deliveries not received yet.\n * @param next - The new delivery.\n * @returns The deliveries to make, in order.\n */\nfunction combine(\n source: StreamChannelSource<unknown[]>,\n pending: unknown[][],\n next: unknown[],\n): unknown[][] {\n if (source.delivery === 'queue') {\n return [...pending, next];\n }\n if (source.delivery === 'merge' && source.reduce && pending.length > 0) {\n return [source.reduce(pending[0], next) ?? next];\n }\n return [next];\n}\n\n/**\n * Normalize a thrown value.\n *\n * @param error - Thrown value.\n * @returns An `Error`.\n */\nfunction toError(error: unknown): Error {\n return error instanceof Error ? error : new Error(String(error));\n}\n"]}
1
+ {"version":3,"file":"StreamChannelManager.js","sourceRoot":"","sources":["../../src/services/StreamChannelManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AA+J7D;;;;;GAKG;AACH,SAAS,SAAS,CAAC,KAAc;IAC/B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IAC/C,CAAC;IACD,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,E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AC,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC;YACnD,IACE,CAAC,OAAO,CAAC,MAAM;gBACf,CAAC,OAAO,CAAC,MAAM,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,EACjE,CAAC;gBACD,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACxB,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAED;;;;;;;GAOG;AACH,SAAS,OAAO,CACd,MAAsC,EACtC,OAAoB,EACpB,IAAe;IAEf,IAAI,MAAM,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QAChC,OAAO,CAAC,GAAG,OAAO,EAAE,IAAI,CAAC,CAAC;IAC5B,CAAC;IACD,IAAI,MAAM,CAAC,QAAQ,KAAK,OAAO,IAAI,MAAM,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED;;;;;GAKG;AACH,SAAS,OAAO,CAAC,KAAc;IAC7B,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AACnE,CAAC","sourcesContent":["import { STREAM_RETRY_CONFIG } from '../constants/perpsConfig.js';\nimport { WebSocketConnectionState } from '../types/index.js';\n\n/**\n * What one shared stream is: the stream name plus everything its source\n * reads. Two subscriptions with equal keys share one venue subscription.\n */\nexport type StreamChannelKey = {\n /** Stream name, such as `prices` or `orderBook`. */\n stream: string;\n /** Provider route, or the default route when omitted. */\n providerId?: string;\n /** Account, or the selected account when omitted. */\n accountId?: string;\n /** Market, for market streams. */\n symbol?: string;\n /** Any other option the source reads. Functions are ignored. */\n options?: Record<string, unknown>;\n};\n\n/**\n * The venue subscription behind a channel. `open` runs once for the first\n * subscriber and its cleanup once the last one leaves.\n */\nexport type StreamChannelSource<Args extends unknown[]> = {\n /**\n * Open the live stream.\n *\n * @param emit - Delivers a value to every subscriber.\n * @param fail - Reports a stream failure, with any detail the source adds\n * (such as the failing venue); the last value stays current. The source\n * stays attached, and heard, until the channel reopens it.\n * @param key - The key the channel opens under, which changes on `rebind`.\n * @param report - Tells the readers of a failure the source recovers from by\n * itself; the channel does not reopen it.\n * @returns Cleanup that stops the stream.\n */\n open(\n emit: (...args: Args) => void,\n fail: (error: Error, ...detail: unknown[]) => void,\n key: StreamChannelKey,\n report: (error: Error, ...detail: unknown[]) => void,\n ): () => void;\n /**\n * One REST read for while the stream is down: it seeds a channel that opens\n * while the transport is disconnected, and runs once each time the\n * connection drops. It is never repeated on a timer.\n * Resolving `undefined` delivers nothing.\n *\n * @param key - The channel's current key.\n */\n read?(key: StreamChannelKey): Promise<Args | undefined>;\n /**\n * Deliver the channel's value to a subscriber that joins an open channel.\n * Defaults to true; turn it off for event streams, such as trades, where a\n * replay would repeat an event.\n */\n replay?: boolean;\n /**\n * Fold each delivery into the value the channel keeps for replay and\n * `getLast`, for streams whose deliveries are deltas. Returning `undefined`\n * keeps no value. Defaults to the latest delivery.\n */\n reduce?(held: Args | undefined, next: Args): Args | undefined;\n /**\n * What a throttled or paused subscriber receives for the deliveries it\n * waited through: the `latest` one (default), all of them `merge`d with\n * `reduce`, or each of them in order from a `queue`. Streams of deltas and\n * events use the last two so that no change is lost.\n */\n delivery?: 'latest' | 'merge' | 'queue';\n /**\n * Stop and reopen the venue subscription when the connection comes back\n * after a drop, for streams the transport does not restore by itself. The\n * channel stays the one owner of that resubscribe, whatever its reader count.\n */\n reopenOnReconnect?: boolean;\n};\n\n/** One reader of a channel. */\nexport type StreamChannelSubscriber<Args extends unknown[]> = {\n /** Receives each value, at most once per `throttleMs` when set. */\n callback: (...args: Args) => void;\n /** Receives stream and seed-read failures. */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onError?: (error: Error, ...detail: any[]) => void;\n /** Minimum time between two deliveries to this subscriber. */\n throttleMs?: number;\n /**\n * Called when the channel moves to another context (provider or account)\n * and its last value no longer applies. The next delivery is the new\n * context's data.\n */\n onReset?: () => void;\n};\n\n/** How `rebind` treats the channels around the ones that move. */\nexport type StreamRebindOptions = {\n /**\n * Channels that keep their key but share the venue state the moving ones\n * use: stopped with them, and restarted after them.\n */\n restart?: (key: StreamChannelKey) => boolean;\n /** Runs once every source concerned has stopped, before any starts. */\n onStopped?: () => void;\n};\n\n/** Watches the transport the channels stream on. */\nexport type StreamConnectionWatcher = (\n listener: (state: WebSocketConnectionState) => void,\n) => () => void;\n\nexport type StreamChannelManagerOptions = {\n /** Connection state source; a drop triggers each channel's `read`. */\n subscribeToConnectionState?: StreamConnectionWatcher;\n /**\n * Receives subscriber callback failures, which never reach the venue, with\n * the key of the channel they came from when there is one.\n */\n onError?: (error: unknown, key?: StreamChannelKey) => void;\n};\n\ntype Reader = {\n subscriber: StreamChannelSubscriber<unknown[]>;\n /** The channel the reader is on; it changes when channels rebind. */\n channel: Channel;\n lastDeliveredAt: number;\n pending: unknown[][];\n timer: ReturnType<typeof setTimeout> | undefined;\n /** Joined while the stream was paused: it gets the replay on release. */\n joinedPaused: boolean;\n};\n\ntype Channel = {\n /** Serialized key the channel is filed under. */\n id: string;\n key: StreamChannelKey;\n source: StreamChannelSource<unknown[]>;\n readers: Set<Reader>;\n last: unknown[] | undefined;\n /** A value arrived since the channel opened or last moved. */\n hasValue: boolean;\n /** Bumped on every delivery so a stale seed read never overwrites a push. */\n version: number;\n /** Bumped on every start and stop, so a stopped source is never heard. */\n generation: number;\n stop: () => void;\n closed: boolean;\n /** The source failed and has not been reopened. */\n failed: boolean;\n /** Reopens since the source was last stable. */\n attempts: number;\n startedAt: number;\n /** A value arrived since the source last started. */\n delivered: boolean;\n retryTimer: ReturnType<typeof setTimeout> | undefined;\n /** Deliveries that arrived while the stream was paused. */\n held: unknown[][];\n};\n\n/**\n * Serialize a key so equal keys match regardless of property order.\n *\n * @param value - Key or nested option value.\n * @returns A stable string form; functions and `undefined` are dropped.\n */\nfunction stableKey(value: unknown): string {\n if (Array.isArray(value)) {\n return `[${value.map(stableKey).join(',')}]`;\n }\n if (value !== null && typeof value === 'object') {\n return `{${Object.keys(value)\n .sort()\n .filter((name) => {\n const entry = (value as Record<string, unknown>)[name];\n return entry !== undefined && typeof entry !== 'function';\n })\n .map(\n (name) =>\n `${JSON.stringify(name)}:${stableKey((value as Record<string, unknown>)[name])}`,\n )\n .join(',')}}`;\n }\n return JSON.stringify(value) ?? 'null';\n}\n\n/**\n * The one stream layer every client shares. Each key gets one ref-counted\n * channel over one venue subscription: it opens with the first subscriber,\n * replays its value to later ones, throttles each subscriber on its own and\n * stops with the last one. The channel is the one owner of reconnect and\n * resubscribe: a source that fails is reopened with a bounded backoff, and\n * again on reconnect, so readers never resubscribe and N readers cost one\n * resubscribe. REST is read only while the transport is down: to seed a\n * channel and once per drop.\n */\nexport class StreamChannelManager {\n readonly #channels = new Map<string, Channel>();\n\n readonly #subscribeToConnectionState: StreamConnectionWatcher | undefined;\n\n readonly #onError: (error: unknown, key?: StreamChannelKey) => void;\n\n #stopConnectionWatch: (() => void) | undefined;\n\n #connectionState: WebSocketConnectionState | undefined;\n\n /** The connection dropped since it was last connected. */\n #dropped = false;\n\n /** Pause holders per stream name. */\n readonly #pauses = new Map<string, number>();\n\n constructor(options: StreamChannelManagerOptions = {}) {\n this.#subscribeToConnectionState = options.subscribeToConnectionState;\n this.#onError = options.onError ?? ((): void => undefined);\n }\n\n /**\n * Open channels, for diagnostics and tests.\n *\n * @returns The number of open channels.\n */\n get size(): number {\n return this.#channels.size;\n }\n\n /**\n * Join the channel for `key`, opening it when it is the first subscriber.\n *\n * @param key - What the channel streams.\n * @param source - Venue subscription used when the channel opens.\n * @param subscriber - Callbacks and throttle for this reader.\n * @returns Cleanup that leaves the channel.\n */\n subscribe<Args extends unknown[]>(\n key: StreamChannelKey,\n source: StreamChannelSource<Args>,\n subscriber: StreamChannelSubscriber<Args>,\n ): () => void {\n const id = stableKey(key);\n const open = this.#channels.get(id);\n const channel = open ?? this.#createChannel(id, key, source);\n const reader: Reader = {\n subscriber: subscriber as StreamChannelSubscriber<unknown[]>,\n channel,\n lastDeliveredAt: 0,\n pending: [],\n timer: undefined,\n joinedPaused: false,\n };\n if (open) {\n this.#join(open, reader);\n if (open.failed && open.retryTimer === undefined) {\n // A new reader is a fresh reason to reach the venue, once its\n // attempts are spent; a pending retry keeps its backoff.\n this.#reopen(open);\n }\n } else {\n // The reader joins before the source opens, so a value the source\n // delivers while opening reaches it.\n channel.readers.add(reader);\n this.#open(channel);\n }\n return () => this.#leave(reader);\n }\n\n /**\n * Move every open channel whose key is no longer current to its next key,\n * such as after the provider or the selected account changed. Every stale\n * source stops before any new one starts, so venue state the old sources\n * shared is released first. Each reader's `onReset` is called when the\n * channel had a value; the channel then reopens under the new key, or its\n * readers join the channel already open there. Reader cleanups stay valid.\n *\n * @param isCurrent - Whether a key still matches the context.\n * @param nextKey - The key a stale channel moves to.\n * @param options - Channels to restart alongside, and a hook between the\n * stops and the starts.\n */\n rebind(\n isCurrent: (key: StreamChannelKey) => boolean,\n nextKey: (key: StreamChannelKey) => StreamChannelKey,\n options: StreamRebindOptions = {},\n ): void {\n const open = [...this.#channels.values()];\n const stale = open.filter((channel) => !isCurrent(channel.key));\n const restarted =\n stale.length > 0 && options.restart\n ? open.filter(\n (channel) =>\n !stale.includes(channel) && options.restart?.(channel.key),\n )\n : [];\n for (const channel of stale) {\n this.#channels.delete(channel.id);\n this.#stopSource(channel);\n }\n for (const channel of restarted) {\n this.#stopSource(channel);\n }\n options.onStopped?.();\n\n let providerMoved = false;\n for (const channel of stale) {\n // A source stopped in this pass may have closed this channel.\n if (channel.closed) {\n continue;\n }\n const key = nextKey(channel.key);\n providerMoved ||= key.providerId !== channel.key.providerId;\n this.#move(channel, key);\n }\n for (const channel of restarted) {\n if (!channel.closed) {\n this.#reopen(channel);\n }\n }\n if (providerMoved) {\n // The connection watch answered for the old transport.\n this.#stopWatch();\n }\n if (this.#channels.size > 0) {\n // Also when a reader that left during its reset closed the last channel.\n this.#watchConnection();\n }\n if (this.#isDown()) {\n for (const channel of stale) {\n if (!channel.closed && !channel.hasValue) {\n this.#seed(channel);\n }\n }\n }\n }\n\n /**\n * Reset a stopped channel's readers and reopen it under another key.\n *\n * @param channel - The stopped channel.\n * @param key - The key it moves to.\n */\n #move(channel: Channel, key: StreamChannelKey): void {\n const id = stableKey(key);\n // Readers hold nothing to reset when no value arrived since the last move.\n const { hasValue } = channel;\n channel.last = undefined;\n channel.hasValue = false;\n channel.held = [];\n channel.attempts = 0;\n // A seed read still in flight answers for the old key.\n channel.version += 1;\n const readers = [...channel.readers];\n for (const reader of readers) {\n this.#cancelPending(reader);\n try {\n if (hasValue) {\n reader.subscriber.onReset?.();\n }\n } catch (error) {\n this.#onError(error, channel.key);\n }\n }\n if (channel.closed) {\n return;\n }\n const existing = this.#channels.get(id);\n if (existing) {\n channel.closed = true;\n const remaining = [...channel.readers];\n channel.readers.clear();\n for (const reader of remaining) {\n reader.channel = existing;\n this.#join(existing, reader);\n }\n return;\n }\n channel.id = id;\n channel.key = key;\n this.#channels.set(id, channel);\n this.#start(channel);\n }\n\n /**\n * Stop delivering one stream while an operation runs. Values keep arriving\n * and are held as the source's `delivery` says; when the last holder\n * releases, each reader receives them together with the throttled\n * deliveries it was still waiting for.\n *\n * @param stream - Stream name, matched against every channel's `key.stream`.\n * @returns Release; calling it again does nothing.\n */\n pause(stream: string): () => void {\n this.#pauses.set(stream, (this.#pauses.get(stream) ?? 0) + 1);\n let released = false;\n return () => {\n if (released) {\n return;\n }\n released = true;\n const count = (this.#pauses.get(stream) ?? 1) - 1;\n if (count > 0) {\n this.#pauses.set(stream, count);\n return;\n }\n this.#pauses.delete(stream);\n for (const channel of [...this.#channels.values()]) {\n if (channel.key.stream !== stream) {\n continue;\n }\n const { held } = channel;\n channel.held = [];\n for (const reader of [...channel.readers]) {\n if (reader.joinedPaused) {\n // Its replay holds everything that arrived during the pause.\n reader.joinedPaused = false;\n if (channel.last && channel.source.replay !== false) {\n this.#deliver(reader, channel.last);\n }\n continue;\n }\n for (const args of held) {\n reader.pending = combine(channel.source, reader.pending, args);\n }\n // A throttled delivery that is not due yet keeps its own timer.\n if (held.length > 0 || reader.timer === undefined) {\n this.#flush(reader);\n }\n }\n }\n };\n }\n\n /**\n * Stop and restart every open channel's source, keeping readers and last\n * values, such as when a socket that looks open has stopped delivering.\n */\n reopenAll(): void {\n for (const channel of [...this.#channels.values()]) {\n if (!channel.closed) {\n this.#reopen(channel);\n }\n }\n }\n\n /**\n * The value an open channel keeps.\n *\n * @param key - What the channel streams.\n * @returns The last delivered (or reduced) arguments, or `undefined`.\n */\n getLast(key: StreamChannelKey): readonly unknown[] | undefined {\n return this.#channels.get(stableKey(key))?.last;\n }\n\n /**\n * Add a reader to an open channel and replay its last value.\n *\n * @param channel - The open channel.\n * @param reader - The joining reader.\n */\n #join(channel: Channel, reader: Reader): void {\n channel.readers.add(reader);\n if (this.#pauses.has(channel.key.stream)) {\n reader.joinedPaused = true;\n return;\n }\n const { last, version } = channel;\n if (last && channel.source.replay !== false) {\n // Replay after `subscribe` returns, so callers hold their cleanup.\n queueMicrotask(() => {\n if (\n reader.channel === channel &&\n channel.readers.has(reader) &&\n channel.version === version\n ) {\n this.#deliver(reader, last);\n }\n });\n }\n }\n\n /** Stop every channel; their subscribers receive nothing more. */\n clear(): void {\n for (const channel of [...this.#channels.values()]) {\n for (const reader of channel.readers) {\n clearTimeout(reader.timer);\n }\n channel.readers.clear();\n this.#close(channel.id, channel);\n }\n }\n\n #createChannel(\n id: string,\n key: StreamChannelKey,\n source: StreamChannelSource<unknown[]>,\n ): Channel {\n return {\n id,\n key,\n source,\n readers: new Set(),\n last: undefined,\n hasValue: false,\n version: 0,\n generation: 0,\n stop: (): void => undefined,\n closed: false,\n failed: false,\n attempts: 0,\n startedAt: 0,\n delivered: false,\n retryTimer: undefined,\n held: [],\n };\n }\n\n #open(channel: Channel): void {\n this.#channels.set(channel.id, channel);\n this.#watchConnection();\n this.#start(channel);\n // Seed only a channel that opens while the transport is known to be down;\n // a connected stream delivers its own first value.\n if (this.#isDown()) {\n this.#seed(channel);\n }\n }\n\n /**\n * Whether the transport is known not to be connected.\n *\n * @returns True while the last reported state is not connected.\n */\n #isDown(): boolean {\n return (\n this.#connectionState !== undefined &&\n this.#connectionState !== WebSocketConnectionState.Connected\n );\n }\n\n #start(channel: Channel): void {\n clearTimeout(channel.retryTimer);\n channel.retryTimer = undefined;\n channel.generation += 1;\n channel.failed = false;\n channel.delivered = false;\n channel.startedAt = Date.now();\n const { generation } = channel;\n const isCurrent = (): boolean =>\n !channel.closed && channel.generation === generation;\n const fail = (error: Error, detail: unknown[]): void => {\n if (isCurrent()) {\n this.#fail(channel, error, detail);\n }\n };\n try {\n const stop = channel.source.open(\n (...args) => {\n if (isCurrent()) {\n channel.delivered = true;\n this.#emit(channel, args);\n }\n },\n (error, ...detail) => fail(error, detail),\n channel.key,\n (error, ...detail) => {\n if (isCurrent()) {\n this.#report(channel, error, detail);\n }\n },\n );\n if (isCurrent()) {\n channel.stop = stop;\n } else {\n // Closed, moved or failed while opening.\n this.#runStop(stop, channel.key);\n }\n } catch (error) {\n queueMicrotask(() => fail(toError(error), []));\n }\n }\n\n /**\n * Stop and start a channel's source with a fresh retry budget.\n *\n * @param channel - The channel to reopen.\n */\n #reopen(channel: Channel): void {\n channel.attempts = 0;\n this.#stopSource(channel);\n this.#start(channel);\n }\n\n #stopSource(channel: Channel): void {\n const { stop } = channel;\n channel.stop = (): void => undefined;\n // From here on nothing the old source says is heard.\n channel.generation += 1;\n clearTimeout(channel.retryTimer);\n channel.retryTimer = undefined;\n this.#runStop(stop, channel.key);\n }\n\n #runStop(stop: () => void, key: StreamChannelKey): void {\n try {\n stop();\n } catch (error) {\n this.#onError(error, key);\n }\n }\n\n #cancelPending(reader: Reader): void {\n clearTimeout(reader.timer);\n reader.timer = undefined;\n reader.pending = [];\n }\n\n #seed(channel: Channel): void {\n const { source, version } = channel;\n if (!source.read) {\n return;\n }\n source\n .read(channel.key)\n .then((args) => {\n if (args && !channel.closed && channel.version === version) {\n this.#emit(channel, args);\n }\n })\n // A failed REST seed leaves the live stream running.\n .catch((error: unknown) => {\n if (!channel.closed && channel.version === version) {\n this.#report(channel, toError(error), []);\n }\n });\n }\n\n #emit(channel: Channel, args: unknown[]): void {\n if (channel.closed) {\n return;\n }\n const { source } = channel;\n channel.last = source.reduce ? source.reduce(channel.last, args) : args;\n channel.hasValue = true;\n channel.version += 1;\n if (this.#pauses.has(channel.key.stream)) {\n channel.held = combine(channel.source, channel.held, args);\n return;\n }\n for (const reader of [...channel.readers]) {\n this.#deliver(reader, args);\n }\n }\n\n /**\n * Handle a source failure: tell the readers and reopen the source with a\n * bounded backoff, also when it delivers meanwhile: one part of a source may\n * stream while the part that failed does not. Once the attempts are spent the\n * source stays attached as it is, and the channel reopens it when the\n * connection comes back, on a move, on `reopenAll` and for a new reader.\n *\n * @param channel - The failing channel.\n * @param error - The failure.\n * @param detail - Detail the source adds, such as the failing venue.\n */\n #fail(channel: Channel, error: Error, detail: unknown[]): void {\n if (\n channel.delivered &&\n Date.now() - channel.startedAt >= STREAM_RETRY_CONFIG.StableMs\n ) {\n channel.attempts = 0;\n }\n channel.failed = true;\n if (\n channel.retryTimer === undefined &&\n channel.attempts < STREAM_RETRY_CONFIG.MaxAttempts\n ) {\n const delay = Math.min(\n STREAM_RETRY_CONFIG.BaseDelayMs * 2 ** channel.attempts,\n STREAM_RETRY_CONFIG.MaxDelayMs,\n );\n channel.attempts += 1;\n channel.retryTimer = setTimeout(() => {\n this.#stopSource(channel);\n this.#start(channel);\n }, delay);\n }\n this.#report(channel, error, detail);\n }\n\n #report(channel: Channel, error: Error, detail: unknown[]): void {\n for (const reader of [...channel.readers]) {\n try {\n reader.subscriber.onError?.(error, ...detail);\n } catch (callbackError) {\n this.#onError(callbackError, channel.key);\n }\n }\n }\n\n #deliver(reader: Reader, args: unknown[]): void {\n const { throttleMs } = reader.subscriber;\n if (!throttleMs || throttleMs <= 0) {\n this.#call(reader, args);\n return;\n }\n const wait = reader.lastDeliveredAt + throttleMs - Date.now();\n if (wait <= 0 && reader.timer === undefined) {\n this.#call(reader, args);\n return;\n }\n const { channel } = reader;\n reader.pending = combine(channel.source, reader.pending, args);\n reader.timer ??= setTimeout(\n () => {\n reader.timer = undefined;\n // A pause delivers what is pending itself when it ends.\n if (this.#pauses.has(reader.channel.key.stream)) {\n return;\n }\n this.#flush(reader);\n },\n Math.max(wait, 0),\n );\n }\n\n /**\n * Deliver everything a reader is waiting for now.\n *\n * @param reader - The reader.\n */\n #flush(reader: Reader): void {\n const { pending } = reader;\n this.#cancelPending(reader);\n for (const args of pending) {\n if (!reader.channel.readers.has(reader)) {\n return;\n }\n this.#call(reader, args);\n }\n }\n\n #call(reader: Reader, args: unknown[]): void {\n reader.lastDeliveredAt = Date.now();\n try {\n reader.subscriber.callback(...args);\n } catch (error) {\n this.#onError(error, reader.channel.key);\n }\n }\n\n #leave(reader: Reader): void {\n const { channel } = reader;\n if (!channel.readers.delete(reader)) {\n return;\n }\n this.#cancelPending(reader);\n if (channel.readers.size === 0) {\n this.#close(channel.id, channel);\n }\n }\n\n #close(id: string, channel: Channel): void {\n if (channel.closed) {\n return;\n }\n channel.closed = true;\n if (this.#channels.get(id) === channel) {\n this.#channels.delete(id);\n }\n this.#stopSource(channel);\n if (this.#channels.size === 0) {\n this.#stopWatch();\n }\n }\n\n #stopWatch(): void {\n const stopWatch = this.#stopConnectionWatch;\n this.#stopConnectionWatch = undefined;\n this.#connectionState = undefined;\n this.#dropped = false;\n try {\n stopWatch?.();\n } catch (error) {\n this.#onError(error);\n }\n }\n\n /** Watch the transport while any channel is open. */\n #watchConnection(): void {\n if (this.#stopConnectionWatch || !this.#subscribeToConnectionState) {\n return;\n }\n // Held while subscribing, so a watcher that answers at once does not\n // subscribe again. What it answers may stop this watch and start another\n // (a rebind), so the slot is only written while it still holds this one.\n const placeholder = (): void => undefined;\n this.#stopConnectionWatch = placeholder;\n let stop: () => void;\n try {\n stop = this.#subscribeToConnectionState((state) =>\n this.#onConnectionState(state),\n );\n } catch (error) {\n // No watch: the next channel to open tries again.\n if (this.#stopConnectionWatch === placeholder) {\n this.#stopConnectionWatch = undefined;\n }\n this.#onError(error);\n return;\n }\n if (this.#stopConnectionWatch === placeholder) {\n this.#stopConnectionWatch = stop;\n return;\n }\n // Superseded while it registered.\n try {\n stop();\n } catch (error) {\n this.#onError(error);\n }\n }\n\n /**\n * Read each channel's REST source once when a live connection drops. When it\n * comes back, reopen the failed channels and those the transport does not\n * restore by itself.\n *\n * @param state - The new transport state.\n */\n #onConnectionState(state: WebSocketConnectionState): void {\n const previous = this.#connectionState;\n this.#connectionState = state;\n if (state !== WebSocketConnectionState.Connected) {\n if (previous === WebSocketConnectionState.Connected) {\n this.#dropped = true;\n for (const channel of [...this.#channels.values()]) {\n this.#seed(channel);\n }\n }\n return;\n }\n const dropped = this.#dropped;\n this.#dropped = false;\n if (previous === state) {\n return;\n }\n for (const channel of [...this.#channels.values()]) {\n if (\n !channel.closed &&\n (channel.failed || (dropped && channel.source.reopenOnReconnect))\n ) {\n this.#reopen(channel);\n }\n }\n }\n}\n\n/**\n * Add a delivery to the ones a reader has yet to receive.\n *\n * @param source - The channel's source, which says how they combine.\n * @param pending - Deliveries not received yet.\n * @param next - The new delivery.\n * @returns The deliveries to make, in order.\n */\nfunction combine(\n source: StreamChannelSource<unknown[]>,\n pending: unknown[][],\n next: unknown[],\n): unknown[][] {\n if (source.delivery === 'queue') {\n return [...pending, next];\n }\n if (source.delivery === 'merge' && source.reduce && pending.length > 0) {\n return [source.reduce(pending[0], next) ?? next];\n }\n return [next];\n}\n\n/**\n * Normalize a thrown value.\n *\n * @param error - Thrown value.\n * @returns An `Error`.\n */\nfunction toError(error: unknown): Error {\n return error instanceof Error ? error : new Error(String(error));\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/perps-controller",
3
- "version": "26.2.0-preview-756d5c648",
3
+ "version": "26.2.0-preview-2cd622db9",
4
4
  "description": "Controller for perpetual trading functionality in MetaMask",
5
5
  "keywords": [
6
6
  "Ethereum",