/** * `Wire` — fluent stream wrapper. * * @module */ import { Effect, Stream } from 'effect'; import type { Millis } from './brands.js'; interface WireShape { readonly _tag: 'Wire'; readonly stream: Stream.Stream; map(f: (a: T) => B): WireShape; filter(f: (a: T) => boolean): WireShape; take(n: number): WireShape; takeUntil(predicate: (a: T) => boolean): WireShape; debounce(ms: Millis): WireShape; throttle(ms: Millis): WireShape; scan(initial: B, f: (acc: B, value: T) => B): WireShape; flatMap(f: (a: T) => WireShape): WireShape; merge(other: WireShape): WireShape; run(): Effect.Effect; runCollect(): Effect.Effect; } /** * Creates a Wire from a WebSocket connection. * The socket is closed when the stream finalizes. * * @example * ```ts * const wire = Wire.fromWebSocket('wss://example.com/ws'); * const messages = wire.map(evt => evt.data as string); * await Effect.runPromise(Wire.runForEach(messages, m => Effect.log(m))); * ``` */ /** * The WebSocket surface {@link Wire.fromWebSocket} actually drives. Named so * the dependency is structural rather than ambient: test doubles * (tests/helpers/mock-websocket.ts) conform to THIS type, and any drift * between what the Wire consumes and what the double provides breaks the * build instead of silently diverging. */ export interface WireSocket { onmessage: ((event: MessageEvent) => void) | null; onerror: ((event: Event) => void) | null; onclose: ((event: CloseEvent) => void) | null; readonly readyState: number; close(): void; } /** * Wire -- fluent stream wrapper with chainable operators for map, filter, * scan, debounce, throttle, merge, and more. Wraps Effect Streams. * * @example * ```ts * const wire = Wire.from(Stream.make(1, 2, 3, 4, 5)); * const result = wire.filter(n => n > 2).map(n => n * 10); * const values = Effect.runSync(result.runCollect()); // [30, 40, 50] * ``` */ export declare const Wire: { from: (stream: Stream.Stream) => WireShape; fromSSE: (url: string, options?: EventSourceInit) => WireShape; fromWebSocket: (url: string, protocols?: string | string[]) => WireShape; fromAsyncIterable: (iterable: AsyncIterable) => WireShape; zip: (a: WireShape, b: WireShape) => WireShape; merge: (streams: ReadonlyArray>) => WireShape; runCollect: (stream: WireShape) => Effect.Effect, E>; runForEach: (stream: WireShape, fn: (t: T) => Effect.Effect) => Effect.Effect; }; export declare namespace Wire { /** Structural shape of a {@link Wire}: a fluent wrapper over `Stream.Stream`. */ type Shape = WireShape; } export {}; //# sourceMappingURL=wire.d.ts.map