UNPKG

3.56 kBTypeScriptView Raw
1/// <reference types="node" />
2import { EventEmitter } from 'events';
3import { Duplex, Readable, Writable } from 'stream';
4import { StatusObject } from './call-stream';
5import { EmitterAugmentation1 } from './events';
6import { Metadata } from './metadata';
7import { ObjectReadable, ObjectWritable, WriteCallback } from './object-stream';
8import { InterceptingCallInterface } from './client-interceptors';
9/**
10 * A type extending the built-in Error object with additional fields.
11 */
12export declare type ServiceError = StatusObject & Error;
13/**
14 * A base type for all user-facing values returned by client-side method calls.
15 */
16export declare type SurfaceCall = {
17 call?: InterceptingCallInterface;
18 cancel(): void;
19 getPeer(): string;
20} & EmitterAugmentation1<'metadata', Metadata> & EmitterAugmentation1<'status', StatusObject> & EventEmitter;
21/**
22 * A type representing the return value of a unary method call.
23 */
24export declare type ClientUnaryCall = SurfaceCall;
25/**
26 * A type representing the return value of a server stream method call.
27 */
28export declare type ClientReadableStream<ResponseType> = {
29 deserialize: (chunk: Buffer) => ResponseType;
30} & SurfaceCall & ObjectReadable<ResponseType>;
31/**
32 * A type representing the return value of a client stream method call.
33 */
34export declare type ClientWritableStream<RequestType> = {
35 serialize: (value: RequestType) => Buffer;
36} & SurfaceCall & ObjectWritable<RequestType>;
37/**
38 * A type representing the return value of a bidirectional stream method call.
39 */
40export declare type ClientDuplexStream<RequestType, ResponseType> = ClientWritableStream<RequestType> & ClientReadableStream<ResponseType>;
41/**
42 * Construct a ServiceError from a StatusObject. This function exists primarily
43 * as an attempt to make the error stack trace clearly communicate that the
44 * error is not necessarily a problem in gRPC itself.
45 * @param status
46 */
47export declare function callErrorFromStatus(status: StatusObject): ServiceError;
48export declare class ClientUnaryCallImpl extends EventEmitter implements ClientUnaryCall {
49 call?: InterceptingCallInterface;
50 constructor();
51 cancel(): void;
52 getPeer(): string;
53}
54export declare class ClientReadableStreamImpl<ResponseType> extends Readable implements ClientReadableStream<ResponseType> {
55 readonly deserialize: (chunk: Buffer) => ResponseType;
56 call?: InterceptingCallInterface;
57 constructor(deserialize: (chunk: Buffer) => ResponseType);
58 cancel(): void;
59 getPeer(): string;
60 _read(_size: number): void;
61}
62export declare class ClientWritableStreamImpl<RequestType> extends Writable implements ClientWritableStream<RequestType> {
63 readonly serialize: (value: RequestType) => Buffer;
64 call?: InterceptingCallInterface;
65 constructor(serialize: (value: RequestType) => Buffer);
66 cancel(): void;
67 getPeer(): string;
68 _write(chunk: RequestType, encoding: string, cb: WriteCallback): void;
69 _final(cb: Function): void;
70}
71export declare class ClientDuplexStreamImpl<RequestType, ResponseType> extends Duplex implements ClientDuplexStream<RequestType, ResponseType> {
72 readonly serialize: (value: RequestType) => Buffer;
73 readonly deserialize: (chunk: Buffer) => ResponseType;
74 call?: InterceptingCallInterface;
75 constructor(serialize: (value: RequestType) => Buffer, deserialize: (chunk: Buffer) => ResponseType);
76 cancel(): void;
77 getPeer(): string;
78 _read(_size: number): void;
79 _write(chunk: RequestType, encoding: string, cb: WriteCallback): void;
80 _final(cb: Function): void;
81}