1 |
|
2 | import { PartialStatusObject } from './call-interface';
|
3 | import { ServerMethodDefinition } from './make-client';
|
4 | import { Metadata } from './metadata';
|
5 | import { ChannelOptions } from './channel-options';
|
6 | import { Handler } from './server-call';
|
7 | import { Deadline } from './deadline';
|
8 | import * as http2 from 'http2';
|
9 | import { CallEventTracker } from './transport';
|
10 | export interface ServerMetadataListener {
|
11 | (metadata: Metadata, next: (metadata: Metadata) => void): void;
|
12 | }
|
13 | export interface ServerMessageListener {
|
14 | (message: any, next: (message: any) => void): void;
|
15 | }
|
16 | export interface ServerHalfCloseListener {
|
17 | (next: () => void): void;
|
18 | }
|
19 | export interface ServerCancelListener {
|
20 | (): void;
|
21 | }
|
22 | export interface FullServerListener {
|
23 | onReceiveMetadata: ServerMetadataListener;
|
24 | onReceiveMessage: ServerMessageListener;
|
25 | onReceiveHalfClose: ServerHalfCloseListener;
|
26 | onCancel: ServerCancelListener;
|
27 | }
|
28 | export type ServerListener = Partial<FullServerListener>;
|
29 | export declare class ServerListenerBuilder {
|
30 | private metadata;
|
31 | private message;
|
32 | private halfClose;
|
33 | private cancel;
|
34 | withOnReceiveMetadata(onReceiveMetadata: ServerMetadataListener): this;
|
35 | withOnReceiveMessage(onReceiveMessage: ServerMessageListener): this;
|
36 | withOnReceiveHalfClose(onReceiveHalfClose: ServerHalfCloseListener): this;
|
37 | withOnCancel(onCancel: ServerCancelListener): this;
|
38 | build(): ServerListener;
|
39 | }
|
40 | export interface InterceptingServerListener {
|
41 | onReceiveMetadata(metadata: Metadata): void;
|
42 | onReceiveMessage(message: any): void;
|
43 | onReceiveHalfClose(): void;
|
44 | onCancel(): void;
|
45 | }
|
46 | export declare function isInterceptingServerListener(listener: ServerListener | InterceptingServerListener): listener is InterceptingServerListener;
|
47 | export interface StartResponder {
|
48 | (next: (listener?: ServerListener) => void): void;
|
49 | }
|
50 | export interface MetadataResponder {
|
51 | (metadata: Metadata, next: (metadata: Metadata) => void): void;
|
52 | }
|
53 | export interface MessageResponder {
|
54 | (message: any, next: (message: any) => void): void;
|
55 | }
|
56 | export interface StatusResponder {
|
57 | (status: PartialStatusObject, next: (status: PartialStatusObject) => void): void;
|
58 | }
|
59 | export interface FullResponder {
|
60 | start: StartResponder;
|
61 | sendMetadata: MetadataResponder;
|
62 | sendMessage: MessageResponder;
|
63 | sendStatus: StatusResponder;
|
64 | }
|
65 | export type Responder = Partial<FullResponder>;
|
66 | export declare class ResponderBuilder {
|
67 | private start;
|
68 | private metadata;
|
69 | private message;
|
70 | private status;
|
71 | withStart(start: StartResponder): this;
|
72 | withSendMetadata(sendMetadata: MetadataResponder): this;
|
73 | withSendMessage(sendMessage: MessageResponder): this;
|
74 | withSendStatus(sendStatus: StatusResponder): this;
|
75 | build(): Responder;
|
76 | }
|
77 | export interface ServerInterceptingCallInterface {
|
78 | |
79 |
|
80 |
|
81 | start(listener: InterceptingServerListener): void;
|
82 | |
83 |
|
84 |
|
85 | sendMetadata(metadata: Metadata): void;
|
86 | |
87 |
|
88 |
|
89 | sendMessage(message: any, callback: () => void): void;
|
90 | |
91 |
|
92 |
|
93 | sendStatus(status: PartialStatusObject): void;
|
94 | |
95 |
|
96 |
|
97 | startRead(): void;
|
98 | |
99 |
|
100 |
|
101 | getPeer(): string;
|
102 | |
103 |
|
104 |
|
105 | getDeadline(): Deadline;
|
106 | |
107 |
|
108 |
|
109 | getHost(): string;
|
110 | }
|
111 | export declare class ServerInterceptingCall implements ServerInterceptingCallInterface {
|
112 | private nextCall;
|
113 | private responder;
|
114 | private processingMetadata;
|
115 | private processingMessage;
|
116 | private pendingMessage;
|
117 | private pendingMessageCallback;
|
118 | private pendingStatus;
|
119 | constructor(nextCall: ServerInterceptingCallInterface, responder?: Responder);
|
120 | private processPendingMessage;
|
121 | private processPendingStatus;
|
122 | start(listener: InterceptingServerListener): void;
|
123 | sendMetadata(metadata: Metadata): void;
|
124 | sendMessage(message: any, callback: () => void): void;
|
125 | sendStatus(status: PartialStatusObject): void;
|
126 | startRead(): void;
|
127 | getPeer(): string;
|
128 | getDeadline(): Deadline;
|
129 | getHost(): string;
|
130 | }
|
131 | export interface ServerInterceptor {
|
132 | (methodDescriptor: ServerMethodDefinition<any, any>, call: ServerInterceptingCallInterface): ServerInterceptingCall;
|
133 | }
|
134 | export declare class BaseServerInterceptingCall implements ServerInterceptingCallInterface {
|
135 | private readonly stream;
|
136 | private readonly callEventTracker;
|
137 | private readonly handler;
|
138 | private listener;
|
139 | private metadata;
|
140 | private deadlineTimer;
|
141 | private deadline;
|
142 | private maxSendMessageSize;
|
143 | private maxReceiveMessageSize;
|
144 | private cancelled;
|
145 | private metadataSent;
|
146 | private wantTrailers;
|
147 | private cancelNotified;
|
148 | private incomingEncoding;
|
149 | private decoder;
|
150 | private readQueue;
|
151 | private isReadPending;
|
152 | private receivedHalfClose;
|
153 | private streamEnded;
|
154 | private host;
|
155 | constructor(stream: http2.ServerHttp2Stream, headers: http2.IncomingHttpHeaders, callEventTracker: CallEventTracker | null, handler: Handler<any, any>, options: ChannelOptions);
|
156 | private handleTimeoutHeader;
|
157 | private checkCancelled;
|
158 | private notifyOnCancel;
|
159 | /**
|
160 | * A server handler can start sending messages without explicitly sending
|
161 | * metadata. In that case, we need to send headers before sending any
|
162 | * messages. This function does that if necessary.
|
163 | */
|
164 | private maybeSendMetadata;
|
165 | /**
|
166 | * Serialize a message to a length-delimited byte string.
|
167 | * @param value
|
168 | * @returns
|
169 | */
|
170 | private serializeMessage;
|
171 | private decompressMessage;
|
172 | private decompressAndMaybePush;
|
173 | private maybePushNextMessage;
|
174 | private handleDataFrame;
|
175 | private handleEndEvent;
|
176 | start(listener: InterceptingServerListener): void;
|
177 | sendMetadata(metadata: Metadata): void;
|
178 | sendMessage(message: any, callback: () => void): void;
|
179 | sendStatus(status: PartialStatusObject): void;
|
180 | startRead(): void;
|
181 | getPeer(): string;
|
182 | getDeadline(): Deadline;
|
183 | getHost(): string;
|
184 | }
|
185 | export declare function getServerInterceptingCall(interceptors: ServerInterceptor[], stream: http2.ServerHttp2Stream, headers: http2.IncomingHttpHeaders, callEventTracker: CallEventTracker | null, handler: Handler<any, any>, options: ChannelOptions): ServerInterceptingCallInterface;
|