/// /// import { EventEmitter } from 'events'; import { Duplex, Readable, Writable } from 'stream'; import type { Deserialize, Serialize } from './make-client'; import { Metadata } from './metadata'; import type { ObjectReadable, ObjectWritable } from './object-stream'; import type { StatusObject, PartialStatusObject } from './call-interface'; import type { Deadline } from './deadline'; import type { ServerInterceptingCallInterface } from './server-interceptors'; export type ServerStatusResponse = Partial; export type ServerErrorResponse = ServerStatusResponse & Error; export type ServerSurfaceCall = { cancelled: boolean; readonly metadata: Metadata; getPeer(): string; sendMetadata(responseMetadata: Metadata): void; getDeadline(): Deadline; getPath(): string; getHost(): string; } & EventEmitter; export type ServerUnaryCall = ServerSurfaceCall & { request: RequestType; }; export type ServerReadableStream = ServerSurfaceCall & ObjectReadable; export type ServerWritableStream = ServerSurfaceCall & ObjectWritable & { request: RequestType; end: (metadata?: Metadata) => void; }; export type ServerDuplexStream = ServerSurfaceCall & ObjectReadable & ObjectWritable & { end: (metadata?: Metadata) => void; }; export declare function serverErrorToStatus(error: ServerErrorResponse | ServerStatusResponse, overrideTrailers?: Metadata | undefined): PartialStatusObject; export declare class ServerUnaryCallImpl extends EventEmitter implements ServerUnaryCall { private path; private call; metadata: Metadata; request: RequestType; cancelled: boolean; constructor(path: string, call: ServerInterceptingCallInterface, metadata: Metadata, request: RequestType); getPeer(): string; sendMetadata(responseMetadata: Metadata): void; getDeadline(): Deadline; getPath(): string; getHost(): string; } export declare class ServerReadableStreamImpl extends Readable implements ServerReadableStream { private path; private call; metadata: Metadata; cancelled: boolean; constructor(path: string, call: ServerInterceptingCallInterface, metadata: Metadata); _read(size: number): void; getPeer(): string; sendMetadata(responseMetadata: Metadata): void; getDeadline(): Deadline; getPath(): string; getHost(): string; } export declare class ServerWritableStreamImpl extends Writable implements ServerWritableStream { private path; private call; metadata: Metadata; request: RequestType; cancelled: boolean; private trailingMetadata; private pendingStatus; constructor(path: string, call: ServerInterceptingCallInterface, metadata: Metadata, request: RequestType); getPeer(): string; sendMetadata(responseMetadata: Metadata): void; getDeadline(): Deadline; getPath(): string; getHost(): string; _write(chunk: ResponseType, encoding: string, callback: (...args: any[]) => void): void; _final(callback: Function): void; end(metadata?: any): this; } export declare class ServerDuplexStreamImpl extends Duplex implements ServerDuplexStream { private path; private call; metadata: Metadata; cancelled: boolean; private trailingMetadata; private pendingStatus; constructor(path: string, call: ServerInterceptingCallInterface, metadata: Metadata); getPeer(): string; sendMetadata(responseMetadata: Metadata): void; getDeadline(): Deadline; getPath(): string; getHost(): string; _read(size: number): void; _write(chunk: ResponseType, encoding: string, callback: (...args: any[]) => void): void; _final(callback: Function): void; end(metadata?: any): this; } export type sendUnaryData = (error: ServerErrorResponse | ServerStatusResponse | null, value?: ResponseType | null, trailer?: Metadata, flags?: number) => void; export type handleUnaryCall = (call: ServerUnaryCall, callback: sendUnaryData) => void; export type handleClientStreamingCall = (call: ServerReadableStream, callback: sendUnaryData) => void; export type handleServerStreamingCall = (call: ServerWritableStream) => void; export type handleBidiStreamingCall = (call: ServerDuplexStream) => void; export type HandleCall = handleUnaryCall | handleClientStreamingCall | handleServerStreamingCall | handleBidiStreamingCall; export interface UnaryHandler { func: handleUnaryCall; serialize: Serialize; deserialize: Deserialize; type: 'unary'; path: string; } export interface ClientStreamingHandler { func: handleClientStreamingCall; serialize: Serialize; deserialize: Deserialize; type: 'clientStream'; path: string; } export interface ServerStreamingHandler { func: handleServerStreamingCall; serialize: Serialize; deserialize: Deserialize; type: 'serverStream'; path: string; } export interface BidiStreamingHandler { func: handleBidiStreamingCall; serialize: Serialize; deserialize: Deserialize; type: 'bidi'; path: string; } export type Handler = UnaryHandler | ClientStreamingHandler | ServerStreamingHandler | BidiStreamingHandler; export type HandlerType = 'bidi' | 'clientStream' | 'serverStream' | 'unary';