import type { Reader } from "@endo/stream"; import type { Infer } from "@metamask/superstruct"; import type { BaseReader, BaseWriter, ValidateInput } from "./BaseStream.cjs"; export declare const DuplexStreamSentinel: { readonly Syn: "@@Syn"; readonly Ack: "@@Ack"; }; declare const SynStruct: import("@metamask/superstruct").Struct<{ "@@Syn": true; }, { "@@Syn": import("@metamask/superstruct").Struct; }>; type DuplexStreamSyn = Infer; export declare const isSyn: (value: unknown) => value is DuplexStreamSyn; export declare const makeSyn: () => DuplexStreamSyn; declare const AckStruct: import("@metamask/superstruct").Struct<{ "@@Ack": true; }, { "@@Ack": import("@metamask/superstruct").Struct; }>; type DuplexStreamAck = Infer; export declare const isAck: (value: unknown) => value is DuplexStreamAck; export declare const makeAck: () => DuplexStreamAck; type DuplexStreamSignal = DuplexStreamSyn | DuplexStreamAck; export declare const isDuplexStreamSignal: (value: unknown) => value is DuplexStreamSignal; /** * Make a validator for input to a duplex stream. Constructor helper for concrete * duplex stream implementations. * * Validators passed in by consumers must be augmented such that errors aren't * thrown for {@link DuplexStreamSignal} values. * * @param validateInput - The validator for the stream's input type. * @returns A validator for the stream's input type, or `undefined` if no * validation is desired. */ export declare const makeDuplexStreamInputValidator: (validateInput?: ValidateInput) => ((value: unknown) => value is Read) | undefined; /** * The base of a duplex stream. Essentially a {@link BaseReader} with a `write()` method. * Backed up by separate {@link BaseReader} and {@link BaseWriter} instances under the hood. */ export declare abstract class BaseDuplexStream, Write = Read, WriteStream extends BaseWriter = BaseWriter> implements Reader { #private; /** * Reads the next value from the stream. * * @returns The next value from the stream. */ next: () => Promise>; /** * Writes a value to the stream. * * @param value - The next value to write to the stream. * @returns The result of writing the value. */ write: (value: Write) => Promise>; /** * Constructs a new {@link BaseDuplexStream}. * * @param reader - The underlying reader for the duplex stream. * @param writer - The underlying writer for the duplex stream. */ constructor(reader: ReadStream, writer: WriteStream); /** * Synchronizes the duplex stream with its remote counterpart. Must be awaited * before values can be read from or written to the stream. Idempotent. * * @returns A promise that resolves when the stream is synchronized. */ synchronize(): Promise; /** * Returns the async iterator for this stream. * * @returns This stream as an async iterator. */ [Symbol.asyncIterator](): typeof this; /** * Drains the stream by passing each value to a handler function. * * @param handler - The function that will receive each value from the stream. */ drain(handler: (value: Read) => void | Promise): Promise; /** * Pipes the stream to another duplex stream. * * @param sink - The duplex stream to pipe to. */ pipe(sink: DuplexStream): Promise; /** * Closes the stream. Idempotent. * * @returns The final result for this stream. */ return(): Promise>; /** * Closes the stream with an error. Idempotent. * * @param error - The error to close the stream with. * @returns The final result for this stream. */ throw(error: Error): Promise>; /** * Closes the stream. Syntactic sugar for `throw(error)` or `return()`. Idempotent. * * @param error - The error to close the stream with. * @returns The final result for this stream. */ end(error?: Error): Promise>; } /** * A duplex stream. Essentially a {@link Reader} with a `write()` method. */ export type DuplexStream = Pick, Write, BaseWriter>, 'next' | 'write' | 'drain' | 'pipe' | 'return' | 'throw' | 'end'> & { [Symbol.asyncIterator]: () => DuplexStream; }; export {}; //# sourceMappingURL=BaseDuplexStream.d.cts.map