UNPKG

6.49 kBTypeScriptView Raw
1/// <reference types="node" />
2/// <reference types="node" />
3import { EventEmitter } from 'events';
4import { Duplex, Readable, Writable } from 'stream';
5import type { Deserialize, Serialize } from './make-client';
6import { Metadata } from './metadata';
7import type { ObjectReadable, ObjectWritable } from './object-stream';
8import type { StatusObject, PartialStatusObject } from './call-interface';
9import type { Deadline } from './deadline';
10import type { ServerInterceptingCallInterface } from './server-interceptors';
11export type ServerStatusResponse = Partial<StatusObject>;
12export type ServerErrorResponse = ServerStatusResponse & Error;
13export 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;
22export type ServerUnaryCall<RequestType, ResponseType> = ServerSurfaceCall & {
23 request: RequestType;
24};
25export type ServerReadableStream<RequestType, ResponseType> = ServerSurfaceCall & ObjectReadable<RequestType>;
26export type ServerWritableStream<RequestType, ResponseType> = ServerSurfaceCall & ObjectWritable<ResponseType> & {
27 request: RequestType;
28 end: (metadata?: Metadata) => void;
29};
30export type ServerDuplexStream<RequestType, ResponseType> = ServerSurfaceCall & ObjectReadable<RequestType> & ObjectWritable<ResponseType> & {
31 end: (metadata?: Metadata) => void;
32};
33export declare function serverErrorToStatus(error: ServerErrorResponse | ServerStatusResponse, overrideTrailers?: Metadata | undefined): PartialStatusObject;
34export 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}
47export 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}
60export 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}
78export 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}
96export type sendUnaryData<ResponseType> = (error: ServerErrorResponse | ServerStatusResponse | null, value?: ResponseType | null, trailer?: Metadata, flags?: number) => void;
97export type handleUnaryCall<RequestType, ResponseType> = (call: ServerUnaryCall<RequestType, ResponseType>, callback: sendUnaryData<ResponseType>) => void;
98export type handleClientStreamingCall<RequestType, ResponseType> = (call: ServerReadableStream<RequestType, ResponseType>, callback: sendUnaryData<ResponseType>) => void;
99export type handleServerStreamingCall<RequestType, ResponseType> = (call: ServerWritableStream<RequestType, ResponseType>) => void;
100export type handleBidiStreamingCall<RequestType, ResponseType> = (call: ServerDuplexStream<RequestType, ResponseType>) => void;
101export type HandleCall<RequestType, ResponseType> = handleUnaryCall<RequestType, ResponseType> | handleClientStreamingCall<RequestType, ResponseType> | handleServerStreamingCall<RequestType, ResponseType> | handleBidiStreamingCall<RequestType, ResponseType>;
102export interface UnaryHandler<RequestType, ResponseType> {
103 func: handleUnaryCall<RequestType, ResponseType>;
104 serialize: Serialize<ResponseType>;
105 deserialize: Deserialize<RequestType>;
106 type: 'unary';
107 path: string;
108}
109export interface ClientStreamingHandler<RequestType, ResponseType> {
110 func: handleClientStreamingCall<RequestType, ResponseType>;
111 serialize: Serialize<ResponseType>;
112 deserialize: Deserialize<RequestType>;
113 type: 'clientStream';
114 path: string;
115}
116export interface ServerStreamingHandler<RequestType, ResponseType> {
117 func: handleServerStreamingCall<RequestType, ResponseType>;
118 serialize: Serialize<ResponseType>;
119 deserialize: Deserialize<RequestType>;
120 type: 'serverStream';
121 path: string;
122}
123export interface BidiStreamingHandler<RequestType, ResponseType> {
124 func: handleBidiStreamingCall<RequestType, ResponseType>;
125 serialize: Serialize<ResponseType>;
126 deserialize: Deserialize<RequestType>;
127 type: 'bidi';
128 path: string;
129}
130export type Handler<RequestType, ResponseType> = UnaryHandler<RequestType, ResponseType> | ClientStreamingHandler<RequestType, ResponseType> | ServerStreamingHandler<RequestType, ResponseType> | BidiStreamingHandler<RequestType, ResponseType>;
131export type HandlerType = 'bidi' | 'clientStream' | 'serverStream' | 'unary';