import { Duplex } from 'stream'; declare const OWNER: unique symbol; /** * Maintains a set of active {@link StreamEndpoint} instances. * * Used by the mock Gapic client to track all open streams (e.g. active * listeners). Provides registration and bulk-destroy semantics. */ export declare class StreamCollection { private _endpoints; /** * Registers an endpoint into this collection. * * @throws {GoogleError} INTERNAL if the endpoint is already registered. * @param endpoint The endpoint to track. */ register(endpoint: StreamEndpoint): void; /** * Destroys the collection by closing all tracked endpoints and * clearing the internal set. * * Each endpoint’s {@link StreamEndpoint.close} method is invoked. */ destroy(): Promise; } /** * Abstract base class representing a bidirectional streaming endpoint * (e.g. a Firestore listen channel). * * Provides a Node.js {@link Duplex} stream configured for object mode, * error-wrapped write handling, and graceful close/abort semantics. * * Subclasses implement {@link onWrite} to process requests written * by the client. Server responses should be pushed onto the duplex * stream via `this.duplex.push()`. * * @typeParam TRequest Type of request objects written by the client. */ export declare abstract class StreamEndpoint { /** Owning collection (if registered). */ private [OWNER]?; private _isClosed; /** Duplex stream representing this endpoint. */ readonly duplex: Duplex; /** * Creates a new streaming endpoint with a {@link Duplex} configured for * object mode. The writable side delegates to {@link onWrite}; the readable * side is application-driven via explicit `duplex.push()` calls. */ constructor(); /** * Indicates whether this endpoint has been closed or aborted. */ get isClosed(): boolean; /** * Executes a synchronous operation and optionally closes the stream * when it completes. Any thrown error will abort the stream. * * @param op Synchronous operation to execute. * @param autoclose If true, {@link close} is invoked after `op` completes. * @returns Nothing. */ run(op: () => void, autoclose?: boolean): void; /** * Schedules a synchronous operation on the microtask queue and optionally * closes the stream when it completes. Any thrown error will abort the stream. * * @param op Synchronous operation to execute in a microtask. * @param autoclose If true, {@link close} is invoked after `op` completes. * @returns Nothing. */ runMicrotask(op: () => void, autoclose?: boolean): void; /** * Executes an asynchronous operation and optionally closes the stream * when it resolves. A rejected promise will abort the stream. * * @param op Asynchronous operation to execute. * @param autoclose If true, {@link close} is invoked after `op` resolves. * @returns Nothing. */ runPromise(op: () => Promise, autoclose?: boolean): void; /** * Gracefully closes the readable side of the stream. * * Removes the endpoint from its owner collection (if any), * marks it closed, and asynchronously pushes `null` to signal * end-of-stream to the client. * * Safe to call multiple times. */ close(): Promise; /** * Aborts the stream, tearing down both readable and writable * sides immediately. * * Removes the endpoint from its owner collection (if any), * marks it closed, and calls {@link Duplex.destroy}, optionally * with an error. * * @param err Optional error that caused the abort. */ abort(err?: Error): void; /** * Hook invoked when the readable side requests more data. * Defaults to a no-op; subclasses may override to react to * backpressure or demand. * * @param size Suggested number of bytes to read (ignored in object mode). * @returns Nothing. */ onRead(size: number): void; /** * Subclasses must implement request handling logic for data written * by the client. Any thrown or rejected error will be wrapped into * a {@link GoogleError}. * * @param request The request object written by the client. * @returns A promise that resolves when the request has been processed. */ protected abstract onWrite(request: TRequest): Promise; } /** * A {@link StreamEndpoint} that ignores all writes and never emits * any responses. Useful for tests that only exercise stream lifecycle. */ export declare class NoOpStreamEndpoint extends StreamEndpoint { protected onWrite(): Promise; } export {}; //# sourceMappingURL=stream-endpoint.d.ts.map