From be98baa36c632fc4bff506ab92807166106a7d6e Mon Sep 17 00:00:00 2001 From: chris-wozniak Date: Fri, 11 Sep 2026 23:34:37 -0400 Subject: [PATCH] Add once support to IStream --- typescript/src/types/client.ts | 1 + .../tests/unit/stream/stream/events.test.ts | 21 ++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/typescript/src/types/client.ts b/typescript/src/types/client.ts index 6836d14..d0ec323 100644 --- a/typescript/src/types/client.ts +++ b/typescript/src/types/client.ts @@ -10,6 +10,7 @@ export interface StreamOptions { export interface IStream { on(event: "report", listener: (report: Report) => void): this; + once(event: "report", listener: (report: Report) => void): this; on(event: "error", listener: (error: Error) => void): this; on(event: "disconnected", listener: () => void): this; on( diff --git a/typescript/tests/unit/stream/stream/events.test.ts b/typescript/tests/unit/stream/stream/events.test.ts index 0e82d75..4f60153 100644 --- a/typescript/tests/unit/stream/stream/events.test.ts +++ b/typescript/tests/unit/stream/stream/events.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect, beforeEach, jest } from "@jest/globals"; import { Stream } from "../../../../src/stream"; -import { Config } from "../../../../src/types/client"; +import { Config, IStream } from "../../../../src/types/client"; import { LogLevel } from "../../../../src/types/logger"; import * as originDiscovery from "../../../../src/utils/origin-discovery"; @@ -93,6 +93,25 @@ describe("Stream - Event Re-emission", () => { expect(reconnectingSpy).toHaveBeenCalledWith(reconnectingInfo); }); + it("supports one-time report listeners through IStream", () => { + const typedStream: IStream = stream; + const reportListener = jest.fn(); + const report = { + feedID: "0x0003" + "1".repeat(60), + fullReport: "0x1234", + validFromTimestamp: 1, + observationsTimestamp: 2, + }; + + expect(typedStream.once("report", reportListener)).toBe(typedStream); + + stream.emit("report", report); + stream.emit("report", report); + + expect(reportListener).toHaveBeenCalledTimes(1); + expect(reportListener).toHaveBeenCalledWith(report); + }); + it("re-emits 'connection-lost' event exactly once per transition", async () => { const connectionLostSpy = jest.fn(); stream.on("connection-lost", connectionLostSpy);