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