1 |
|
2 | import { EventEmitter } from 'events';
|
3 | import * as http2 from 'http2';
|
4 | import { Duplex, Readable, Writable } from 'stream';
|
5 | import { Deadline, StatusObject } from './call-stream';
|
6 | import { Deserialize, Serialize } from './make-client';
|
7 | import { Metadata } from './metadata';
|
8 | import { ObjectReadable, ObjectWritable } from './object-stream';
|
9 | import { ChannelOptions } from './channel-options';
|
10 | export declare type ServerStatusResponse = Partial<StatusObject>;
|
11 | export declare type ServerErrorResponse = ServerStatusResponse & Error;
|
12 | export declare type ServerSurfaceCall = {
|
13 | cancelled: boolean;
|
14 | readonly metadata: Metadata;
|
15 | getPeer(): string;
|
16 | sendMetadata(responseMetadata: Metadata): void;
|
17 | getDeadline(): Deadline;
|
18 | } & EventEmitter;
|
19 | export declare type ServerUnaryCall<RequestType, ResponseType> = ServerSurfaceCall & {
|
20 | request: RequestType;
|
21 | };
|
22 | export declare type ServerReadableStream<RequestType, ResponseType> = ServerSurfaceCall & ObjectReadable<RequestType>;
|
23 | export declare type ServerWritableStream<RequestType, ResponseType> = ServerSurfaceCall & ObjectWritable<ResponseType> & {
|
24 | request: RequestType;
|
25 | end: (metadata?: Metadata) => void;
|
26 | };
|
27 | export declare type ServerDuplexStream<RequestType, ResponseType> = ServerSurfaceCall & ObjectReadable<RequestType> & ObjectWritable<ResponseType> & {
|
28 | end: (metadata?: Metadata) => void;
|
29 | };
|
30 | export declare class ServerUnaryCallImpl<RequestType, ResponseType> extends EventEmitter implements ServerUnaryCall<RequestType, ResponseType> {
|
31 | private call;
|
32 | metadata: Metadata;
|
33 | request: RequestType;
|
34 | cancelled: boolean;
|
35 | constructor(call: Http2ServerCallStream<RequestType, ResponseType>, metadata: Metadata, request: RequestType);
|
36 | getPeer(): string;
|
37 | sendMetadata(responseMetadata: Metadata): void;
|
38 | getDeadline(): Deadline;
|
39 | }
|
40 | export declare class ServerReadableStreamImpl<RequestType, ResponseType> extends Readable implements ServerReadableStream<RequestType, ResponseType> {
|
41 | private call;
|
42 | metadata: Metadata;
|
43 | deserialize: Deserialize<RequestType>;
|
44 | cancelled: boolean;
|
45 | constructor(call: Http2ServerCallStream<RequestType, ResponseType>, metadata: Metadata, deserialize: Deserialize<RequestType>, encoding: string);
|
46 | _read(size: number): void;
|
47 | getPeer(): string;
|
48 | sendMetadata(responseMetadata: Metadata): void;
|
49 | getDeadline(): Deadline;
|
50 | }
|
51 | export declare class ServerWritableStreamImpl<RequestType, ResponseType> extends Writable implements ServerWritableStream<RequestType, ResponseType> {
|
52 | private call;
|
53 | metadata: Metadata;
|
54 | serialize: Serialize<ResponseType>;
|
55 | request: RequestType;
|
56 | cancelled: boolean;
|
57 | private trailingMetadata;
|
58 | constructor(call: Http2ServerCallStream<RequestType, ResponseType>, metadata: Metadata, serialize: Serialize<ResponseType>, request: RequestType);
|
59 | getPeer(): string;
|
60 | sendMetadata(responseMetadata: Metadata): void;
|
61 | getDeadline(): Deadline;
|
62 | _write(chunk: ResponseType, encoding: string, callback: (...args: any[]) => void): void;
|
63 | _final(callback: Function): void;
|
64 | end(metadata?: any): this;
|
65 | }
|
66 | export declare class ServerDuplexStreamImpl<RequestType, ResponseType> extends Duplex implements ServerDuplexStream<RequestType, ResponseType> {
|
67 | private call;
|
68 | metadata: Metadata;
|
69 | serialize: Serialize<ResponseType>;
|
70 | deserialize: Deserialize<RequestType>;
|
71 | cancelled: boolean;
|
72 | private trailingMetadata;
|
73 | constructor(call: Http2ServerCallStream<RequestType, ResponseType>, metadata: Metadata, serialize: Serialize<ResponseType>, deserialize: Deserialize<RequestType>, encoding: string);
|
74 | getPeer(): string;
|
75 | sendMetadata(responseMetadata: Metadata): void;
|
76 | getDeadline(): Deadline;
|
77 | end(metadata?: any): this;
|
78 | }
|
79 | export declare type sendUnaryData<ResponseType> = (error: ServerErrorResponse | ServerStatusResponse | null, value?: ResponseType | null, trailer?: Metadata, flags?: number) => void;
|
80 | export declare type handleUnaryCall<RequestType, ResponseType> = (call: ServerUnaryCall<RequestType, ResponseType>, callback: sendUnaryData<ResponseType>) => void;
|
81 | export declare type handleClientStreamingCall<RequestType, ResponseType> = (call: ServerReadableStream<RequestType, ResponseType>, callback: sendUnaryData<ResponseType>) => void;
|
82 | export declare type handleServerStreamingCall<RequestType, ResponseType> = (call: ServerWritableStream<RequestType, ResponseType>) => void;
|
83 | export declare type handleBidiStreamingCall<RequestType, ResponseType> = (call: ServerDuplexStream<RequestType, ResponseType>) => void;
|
84 | export declare type HandleCall<RequestType, ResponseType> = handleUnaryCall<RequestType, ResponseType> | handleClientStreamingCall<RequestType, ResponseType> | handleServerStreamingCall<RequestType, ResponseType> | handleBidiStreamingCall<RequestType, ResponseType>;
|
85 | export interface UnaryHandler<RequestType, ResponseType> {
|
86 | func: handleUnaryCall<RequestType, ResponseType>;
|
87 | serialize: Serialize<ResponseType>;
|
88 | deserialize: Deserialize<RequestType>;
|
89 | type: HandlerType;
|
90 | path: string;
|
91 | }
|
92 | export interface ClientStreamingHandler<RequestType, ResponseType> {
|
93 | func: handleClientStreamingCall<RequestType, ResponseType>;
|
94 | serialize: Serialize<ResponseType>;
|
95 | deserialize: Deserialize<RequestType>;
|
96 | type: HandlerType;
|
97 | path: string;
|
98 | }
|
99 | export interface ServerStreamingHandler<RequestType, ResponseType> {
|
100 | func: handleServerStreamingCall<RequestType, ResponseType>;
|
101 | serialize: Serialize<ResponseType>;
|
102 | deserialize: Deserialize<RequestType>;
|
103 | type: HandlerType;
|
104 | path: string;
|
105 | }
|
106 | export interface BidiStreamingHandler<RequestType, ResponseType> {
|
107 | func: handleBidiStreamingCall<RequestType, ResponseType>;
|
108 | serialize: Serialize<ResponseType>;
|
109 | deserialize: Deserialize<RequestType>;
|
110 | type: HandlerType;
|
111 | path: string;
|
112 | }
|
113 | export declare type Handler<RequestType, ResponseType> = UnaryHandler<RequestType, ResponseType> | ClientStreamingHandler<RequestType, ResponseType> | ServerStreamingHandler<RequestType, ResponseType> | BidiStreamingHandler<RequestType, ResponseType>;
|
114 | export declare type HandlerType = 'bidi' | 'clientStream' | 'serverStream' | 'unary';
|
115 | export declare class Http2ServerCallStream<RequestType, ResponseType> extends EventEmitter {
|
116 | private stream;
|
117 | private handler;
|
118 | private options;
|
119 | cancelled: boolean;
|
120 | deadlineTimer: NodeJS.Timer;
|
121 | private deadline;
|
122 | private wantTrailers;
|
123 | private metadataSent;
|
124 | private canPush;
|
125 | private isPushPending;
|
126 | private bufferedMessages;
|
127 | private messagesToPush;
|
128 | private maxSendMessageSize;
|
129 | private maxReceiveMessageSize;
|
130 | constructor(stream: http2.ServerHttp2Stream, handler: Handler<RequestType, ResponseType>, options: ChannelOptions);
|
131 | private checkCancelled;
|
132 | private getDecompressedMessage;
|
133 | sendMetadata(customMetadata?: Metadata): void;
|
134 | receiveMetadata(headers: http2.IncomingHttpHeaders): Metadata;
|
135 | receiveUnaryMessage(encoding: string): Promise<RequestType>;
|
136 | serializeMessage(value: ResponseType): Buffer;
|
137 | deserializeMessage(bytes: Buffer): RequestType;
|
138 | sendUnaryMessage(err: ServerErrorResponse | ServerStatusResponse | null, value?: ResponseType | null, metadata?: Metadata, flags?: number): Promise<void>;
|
139 | sendStatus(statusObj: StatusObject): void;
|
140 | sendError(error: ServerErrorResponse | ServerStatusResponse): void;
|
141 | write(chunk: Buffer): boolean | undefined;
|
142 | resume(): void;
|
143 | setupSurfaceCall(call: ServerSurfaceCall): void;
|
144 | setupReadable(readable: ServerReadableStream<RequestType, ResponseType> | ServerDuplexStream<RequestType, ResponseType>, encoding: string): void;
|
145 | consumeUnpushedMessages(readable: ServerReadableStream<RequestType, ResponseType> | ServerDuplexStream<RequestType, ResponseType>): boolean;
|
146 | private pushOrBufferMessage;
|
147 | private pushMessage;
|
148 | getPeer(): string;
|
149 | getDeadline(): Deadline;
|
150 | }
|