UNPKG

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