///
///
///
///
///
import { EventEmitter } from 'events';
import * as http2 from 'http2';
import { Duplex, Readable, Writable } from 'stream';
import { Deserialize, Serialize } from './make-client';
import { Metadata } from './metadata';
import { ObjectReadable, ObjectWritable } from './object-stream';
import { ChannelOptions } from './channel-options';
import { StatusObject, PartialStatusObject } from './call-interface';
import { Deadline } from './deadline';
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;
} & 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 class ServerUnaryCallImpl extends EventEmitter implements ServerUnaryCall {
private call;
metadata: Metadata;
request: RequestType;
cancelled: boolean;
constructor(call: Http2ServerCallStream, metadata: Metadata, request: RequestType);
getPeer(): string;
sendMetadata(responseMetadata: Metadata): void;
getDeadline(): Deadline;
getPath(): string;
}
export declare class ServerReadableStreamImpl extends Readable implements ServerReadableStream {
private call;
metadata: Metadata;
deserialize: Deserialize;
cancelled: boolean;
constructor(call: Http2ServerCallStream, metadata: Metadata, deserialize: Deserialize, encoding: string);
_read(size: number): void;
getPeer(): string;
sendMetadata(responseMetadata: Metadata): void;
getDeadline(): Deadline;
getPath(): string;
}
export declare class ServerWritableStreamImpl extends Writable implements ServerWritableStream {
private call;
metadata: Metadata;
serialize: Serialize;
request: RequestType;
cancelled: boolean;
private trailingMetadata;
constructor(call: Http2ServerCallStream, metadata: Metadata, serialize: Serialize, request: RequestType);
getPeer(): string;
sendMetadata(responseMetadata: Metadata): void;
getDeadline(): Deadline;
getPath(): 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 call;
metadata: Metadata;
serialize: Serialize;
deserialize: Deserialize;
cancelled: boolean;
private trailingMetadata;
constructor(call: Http2ServerCallStream, metadata: Metadata, serialize: Serialize, deserialize: Deserialize, encoding: string);
getPeer(): string;
sendMetadata(responseMetadata: Metadata): void;
getDeadline(): Deadline;
getPath(): string;
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: HandlerType;
path: string;
}
export interface ClientStreamingHandler {
func: handleClientStreamingCall;
serialize: Serialize;
deserialize: Deserialize;
type: HandlerType;
path: string;
}
export interface ServerStreamingHandler {
func: handleServerStreamingCall;
serialize: Serialize;
deserialize: Deserialize;
type: HandlerType;
path: string;
}
export interface BidiStreamingHandler {
func: handleBidiStreamingCall;
serialize: Serialize;
deserialize: Deserialize;
type: HandlerType;
path: string;
}
export type Handler = UnaryHandler | ClientStreamingHandler | ServerStreamingHandler | BidiStreamingHandler;
export type HandlerType = 'bidi' | 'clientStream' | 'serverStream' | 'unary';
export declare class Http2ServerCallStream extends EventEmitter {
private stream;
private handler;
cancelled: boolean;
deadlineTimer: NodeJS.Timeout | null;
private statusSent;
private deadline;
private wantTrailers;
private metadataSent;
private canPush;
private isPushPending;
private bufferedMessages;
private messagesToPush;
private maxSendMessageSize;
private maxReceiveMessageSize;
constructor(stream: http2.ServerHttp2Stream, handler: Handler, options: ChannelOptions);
private checkCancelled;
private getDecompressedMessage;
sendMetadata(customMetadata?: Metadata): void;
receiveMetadata(headers: http2.IncomingHttpHeaders): Metadata;
receiveUnaryMessage(encoding: string): Promise;
private deserializeMessageWithInternalError;
serializeMessage(value: ResponseType): Buffer;
deserializeMessage(bytes: Buffer): RequestType;
sendUnaryMessage(err: ServerErrorResponse | ServerStatusResponse | null, value?: ResponseType | null, metadata?: Metadata | null, flags?: number): Promise;
sendStatus(statusObj: PartialStatusObject): void;
sendError(error: ServerErrorResponse | ServerStatusResponse): void;
write(chunk: Buffer): boolean | undefined;
resume(): void;
setupSurfaceCall(call: ServerSurfaceCall): void;
setupReadable(readable: ServerReadableStream | ServerDuplexStream, encoding: string): void;
consumeUnpushedMessages(readable: ServerReadableStream | ServerDuplexStream): boolean;
private pushOrBufferMessage;
private pushMessage;
getPeer(): string;
getDeadline(): Deadline;
getPath(): string;
}