1 |
|
2 |
|
3 | import { EventEmitter } from 'events';
|
4 | import { Duplex, Readable, Writable } from 'stream';
|
5 | import type { Deserialize, Serialize } from './make-client';
|
6 | import { Metadata } from './metadata';
|
7 | import type { ObjectReadable, ObjectWritable } from './object-stream';
|
8 | import type { StatusObject, PartialStatusObject } from './call-interface';
|
9 | import type { Deadline } from './deadline';
|
10 | import type { ServerInterceptingCallInterface } from './server-interceptors';
|
11 | export type ServerStatusResponse = Partial<StatusObject>;
|
12 | export type ServerErrorResponse = ServerStatusResponse & Error;
|
13 | export type ServerSurfaceCall = {
|
14 | cancelled: boolean;
|
15 | readonly metadata: Metadata;
|
16 | getPeer(): string;
|
17 | sendMetadata(responseMetadata: Metadata): void;
|
18 | getDeadline(): Deadline;
|
19 | getPath(): string;
|
20 | getHost(): string;
|
21 | } & EventEmitter;
|
22 | export type ServerUnaryCall<RequestType, ResponseType> = ServerSurfaceCall & {
|
23 | request: RequestType;
|
24 | };
|
25 | export type ServerReadableStream<RequestType, ResponseType> = ServerSurfaceCall & ObjectReadable<RequestType>;
|
26 | export type ServerWritableStream<RequestType, ResponseType> = ServerSurfaceCall & ObjectWritable<ResponseType> & {
|
27 | request: RequestType;
|
28 | end: (metadata?: Metadata) => void;
|
29 | };
|
30 | export type ServerDuplexStream<RequestType, ResponseType> = ServerSurfaceCall & ObjectReadable<RequestType> & ObjectWritable<ResponseType> & {
|
31 | end: (metadata?: Metadata) => void;
|
32 | };
|
33 | export declare function serverErrorToStatus(error: ServerErrorResponse | ServerStatusResponse, overrideTrailers?: Metadata | undefined): PartialStatusObject;
|
34 | export declare class ServerUnaryCallImpl<RequestType, ResponseType> extends EventEmitter implements ServerUnaryCall<RequestType, ResponseType> {
|
35 | private path;
|
36 | private call;
|
37 | metadata: Metadata;
|
38 | request: RequestType;
|
39 | cancelled: boolean;
|
40 | constructor(path: string, call: ServerInterceptingCallInterface, metadata: Metadata, request: RequestType);
|
41 | getPeer(): string;
|
42 | sendMetadata(responseMetadata: Metadata): void;
|
43 | getDeadline(): Deadline;
|
44 | getPath(): string;
|
45 | getHost(): string;
|
46 | }
|
47 | export declare class ServerReadableStreamImpl<RequestType, ResponseType> extends Readable implements ServerReadableStream<RequestType, ResponseType> {
|
48 | private path;
|
49 | private call;
|
50 | metadata: Metadata;
|
51 | cancelled: boolean;
|
52 | constructor(path: string, call: ServerInterceptingCallInterface, metadata: Metadata);
|
53 | _read(size: number): void;
|
54 | getPeer(): string;
|
55 | sendMetadata(responseMetadata: Metadata): void;
|
56 | getDeadline(): Deadline;
|
57 | getPath(): string;
|
58 | getHost(): string;
|
59 | }
|
60 | export declare class ServerWritableStreamImpl<RequestType, ResponseType> extends Writable implements ServerWritableStream<RequestType, ResponseType> {
|
61 | private path;
|
62 | private call;
|
63 | metadata: Metadata;
|
64 | request: RequestType;
|
65 | cancelled: boolean;
|
66 | private trailingMetadata;
|
67 | private pendingStatus;
|
68 | constructor(path: string, call: ServerInterceptingCallInterface, metadata: Metadata, request: RequestType);
|
69 | getPeer(): string;
|
70 | sendMetadata(responseMetadata: Metadata): void;
|
71 | getDeadline(): Deadline;
|
72 | getPath(): string;
|
73 | getHost(): string;
|
74 | _write(chunk: ResponseType, encoding: string, callback: (...args: any[]) => void): void;
|
75 | _final(callback: Function): void;
|
76 | end(metadata?: any): this;
|
77 | }
|
78 | export declare class ServerDuplexStreamImpl<RequestType, ResponseType> extends Duplex implements ServerDuplexStream<RequestType, ResponseType> {
|
79 | private path;
|
80 | private call;
|
81 | metadata: Metadata;
|
82 | cancelled: boolean;
|
83 | private trailingMetadata;
|
84 | private pendingStatus;
|
85 | constructor(path: string, call: ServerInterceptingCallInterface, metadata: Metadata);
|
86 | getPeer(): string;
|
87 | sendMetadata(responseMetadata: Metadata): void;
|
88 | getDeadline(): Deadline;
|
89 | getPath(): string;
|
90 | getHost(): string;
|
91 | _read(size: number): void;
|
92 | _write(chunk: ResponseType, encoding: string, callback: (...args: any[]) => void): void;
|
93 | _final(callback: Function): void;
|
94 | end(metadata?: any): this;
|
95 | }
|
96 | export type sendUnaryData<ResponseType> = (error: ServerErrorResponse | ServerStatusResponse | null, value?: ResponseType | null, trailer?: Metadata, flags?: number) => void;
|
97 | export type handleUnaryCall<RequestType, ResponseType> = (call: ServerUnaryCall<RequestType, ResponseType>, callback: sendUnaryData<ResponseType>) => void;
|
98 | export type handleClientStreamingCall<RequestType, ResponseType> = (call: ServerReadableStream<RequestType, ResponseType>, callback: sendUnaryData<ResponseType>) => void;
|
99 | export type handleServerStreamingCall<RequestType, ResponseType> = (call: ServerWritableStream<RequestType, ResponseType>) => void;
|
100 | export type handleBidiStreamingCall<RequestType, ResponseType> = (call: ServerDuplexStream<RequestType, ResponseType>) => void;
|
101 | export type HandleCall<RequestType, ResponseType> = handleUnaryCall<RequestType, ResponseType> | handleClientStreamingCall<RequestType, ResponseType> | handleServerStreamingCall<RequestType, ResponseType> | handleBidiStreamingCall<RequestType, ResponseType>;
|
102 | export interface UnaryHandler<RequestType, ResponseType> {
|
103 | func: handleUnaryCall<RequestType, ResponseType>;
|
104 | serialize: Serialize<ResponseType>;
|
105 | deserialize: Deserialize<RequestType>;
|
106 | type: 'unary';
|
107 | path: string;
|
108 | }
|
109 | export interface ClientStreamingHandler<RequestType, ResponseType> {
|
110 | func: handleClientStreamingCall<RequestType, ResponseType>;
|
111 | serialize: Serialize<ResponseType>;
|
112 | deserialize: Deserialize<RequestType>;
|
113 | type: 'clientStream';
|
114 | path: string;
|
115 | }
|
116 | export interface ServerStreamingHandler<RequestType, ResponseType> {
|
117 | func: handleServerStreamingCall<RequestType, ResponseType>;
|
118 | serialize: Serialize<ResponseType>;
|
119 | deserialize: Deserialize<RequestType>;
|
120 | type: 'serverStream';
|
121 | path: string;
|
122 | }
|
123 | export interface BidiStreamingHandler<RequestType, ResponseType> {
|
124 | func: handleBidiStreamingCall<RequestType, ResponseType>;
|
125 | serialize: Serialize<ResponseType>;
|
126 | deserialize: Deserialize<RequestType>;
|
127 | type: 'bidi';
|
128 | path: string;
|
129 | }
|
130 | export type Handler<RequestType, ResponseType> = UnaryHandler<RequestType, ResponseType> | ClientStreamingHandler<RequestType, ResponseType> | ServerStreamingHandler<RequestType, ResponseType> | BidiStreamingHandler<RequestType, ResponseType>;
|
131 | export type HandlerType = 'bidi' | 'clientStream' | 'serverStream' | 'unary';
|