UNPKG

5.83 kBTypeScriptView Raw
1/// <reference types="node" />
2import { ClientDuplexStream, ClientReadableStream, ClientUnaryCall, ClientWritableStream, ServiceError, SurfaceCall } from './call';
3import { CallCredentials } from './call-credentials';
4import { Deadline } from './call-stream';
5import { Channel } from './channel';
6import { ChannelCredentials } from './channel-credentials';
7import { ChannelOptions } from './channel-options';
8import { Metadata } from './metadata';
9import { ClientMethodDefinition } from './make-client';
10import { Interceptor, InterceptorProvider } from './client-interceptors';
11import { ServerUnaryCall, ServerReadableStream, ServerWritableStream, ServerDuplexStream } from './server-call';
12declare const CHANNEL_SYMBOL: unique symbol;
13declare const INTERCEPTOR_SYMBOL: unique symbol;
14declare const INTERCEPTOR_PROVIDER_SYMBOL: unique symbol;
15declare const CALL_INVOCATION_TRANSFORMER_SYMBOL: unique symbol;
16export interface UnaryCallback<ResponseType> {
17 (err: ServiceError | null, value?: ResponseType): void;
18}
19export interface CallOptions {
20 deadline?: Deadline;
21 host?: string;
22 parent?: ServerUnaryCall<any, any> | ServerReadableStream<any, any> | ServerWritableStream<any, any> | ServerDuplexStream<any, any>;
23 propagate_flags?: number;
24 credentials?: CallCredentials;
25 interceptors?: Interceptor[];
26 interceptor_providers?: InterceptorProvider[];
27}
28export interface CallProperties<RequestType, ResponseType> {
29 argument?: RequestType;
30 metadata: Metadata;
31 call: SurfaceCall;
32 channel: Channel;
33 methodDefinition: ClientMethodDefinition<RequestType, ResponseType>;
34 callOptions: CallOptions;
35 callback?: UnaryCallback<ResponseType>;
36}
37export interface CallInvocationTransformer {
38 (callProperties: CallProperties<any, any>): CallProperties<any, any>;
39}
40export declare type ClientOptions = Partial<ChannelOptions> & {
41 channelOverride?: Channel;
42 channelFactoryOverride?: (address: string, credentials: ChannelCredentials, options: ClientOptions) => Channel;
43 interceptors?: Interceptor[];
44 interceptor_providers?: InterceptorProvider[];
45 callInvocationTransformer?: CallInvocationTransformer;
46};
47/**
48 * A generic gRPC client. Primarily useful as a base class for all generated
49 * clients.
50 */
51export declare class Client {
52 private readonly [CHANNEL_SYMBOL];
53 private readonly [INTERCEPTOR_SYMBOL];
54 private readonly [INTERCEPTOR_PROVIDER_SYMBOL];
55 private readonly [CALL_INVOCATION_TRANSFORMER_SYMBOL]?;
56 constructor(address: string, credentials: ChannelCredentials, options?: ClientOptions);
57 close(): void;
58 getChannel(): Channel;
59 waitForReady(deadline: Deadline, callback: (error?: Error) => void): void;
60 private checkOptionalUnaryResponseArguments;
61 makeUnaryRequest<RequestType, ResponseType>(method: string, serialize: (value: RequestType) => Buffer, deserialize: (value: Buffer) => ResponseType, argument: RequestType, metadata: Metadata, options: CallOptions, callback: UnaryCallback<ResponseType>): ClientUnaryCall;
62 makeUnaryRequest<RequestType, ResponseType>(method: string, serialize: (value: RequestType) => Buffer, deserialize: (value: Buffer) => ResponseType, argument: RequestType, metadata: Metadata, callback: UnaryCallback<ResponseType>): ClientUnaryCall;
63 makeUnaryRequest<RequestType, ResponseType>(method: string, serialize: (value: RequestType) => Buffer, deserialize: (value: Buffer) => ResponseType, argument: RequestType, options: CallOptions, callback: UnaryCallback<ResponseType>): ClientUnaryCall;
64 makeUnaryRequest<RequestType, ResponseType>(method: string, serialize: (value: RequestType) => Buffer, deserialize: (value: Buffer) => ResponseType, argument: RequestType, callback: UnaryCallback<ResponseType>): ClientUnaryCall;
65 makeClientStreamRequest<RequestType, ResponseType>(method: string, serialize: (value: RequestType) => Buffer, deserialize: (value: Buffer) => ResponseType, metadata: Metadata, options: CallOptions, callback: UnaryCallback<ResponseType>): ClientWritableStream<RequestType>;
66 makeClientStreamRequest<RequestType, ResponseType>(method: string, serialize: (value: RequestType) => Buffer, deserialize: (value: Buffer) => ResponseType, metadata: Metadata, callback: UnaryCallback<ResponseType>): ClientWritableStream<RequestType>;
67 makeClientStreamRequest<RequestType, ResponseType>(method: string, serialize: (value: RequestType) => Buffer, deserialize: (value: Buffer) => ResponseType, options: CallOptions, callback: UnaryCallback<ResponseType>): ClientWritableStream<RequestType>;
68 makeClientStreamRequest<RequestType, ResponseType>(method: string, serialize: (value: RequestType) => Buffer, deserialize: (value: Buffer) => ResponseType, callback: UnaryCallback<ResponseType>): ClientWritableStream<RequestType>;
69 private checkMetadataAndOptions;
70 makeServerStreamRequest<RequestType, ResponseType>(method: string, serialize: (value: RequestType) => Buffer, deserialize: (value: Buffer) => ResponseType, argument: RequestType, metadata: Metadata, options?: CallOptions): ClientReadableStream<ResponseType>;
71 makeServerStreamRequest<RequestType, ResponseType>(method: string, serialize: (value: RequestType) => Buffer, deserialize: (value: Buffer) => ResponseType, argument: RequestType, options?: CallOptions): ClientReadableStream<ResponseType>;
72 makeBidiStreamRequest<RequestType, ResponseType>(method: string, serialize: (value: RequestType) => Buffer, deserialize: (value: Buffer) => ResponseType, metadata: Metadata, options?: CallOptions): ClientDuplexStream<RequestType, ResponseType>;
73 makeBidiStreamRequest<RequestType, ResponseType>(method: string, serialize: (value: RequestType) => Buffer, deserialize: (value: Buffer) => ResponseType, options?: CallOptions): ClientDuplexStream<RequestType, ResponseType>;
74}
75export {};