UNPKG

2.97 kBTypeScriptView Raw
1/**
2 * Copyright 2020 Google LLC
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16/// <reference types="node" />
17import { Duplex, DuplexOptions, Readable, Stream, Writable } from 'stream';
18import { APICallback, CancellableStream, GRPCCallResult, SimpleCallbackFunction } from '../apitypes';
19import { RetryRequestOptions } from '../gax';
20declare const duplexify: DuplexifyConstructor;
21export interface DuplexifyOptions extends DuplexOptions {
22 autoDestroy?: boolean;
23 end?: boolean;
24}
25export interface Duplexify extends Duplex {
26 readonly destroyed: boolean;
27 setWritable(writable: Writable | false | null): void;
28 setReadable(readable: Readable | false | null): void;
29}
30export interface DuplexifyConstructor {
31 obj(writable?: Writable | false | null, readable?: Readable | false | null, options?: DuplexifyOptions): Duplexify;
32 new (writable?: Writable | false | null, readable?: Readable | false | null, options?: DuplexifyOptions): Duplexify;
33 (writable?: Writable | false | null, readable?: Readable | false | null, options?: DuplexifyOptions): Duplexify;
34}
35/**
36 * The type of gRPC streaming.
37 * @enum {number}
38 */
39export declare enum StreamType {
40 /** Client sends a single request, server streams responses. */
41 SERVER_STREAMING = 1,
42 /** Client streams requests, server returns a single response. */
43 CLIENT_STREAMING = 2,
44 /** Both client and server stream objects. */
45 BIDI_STREAMING = 3
46}
47export declare class StreamProxy extends duplexify implements GRPCCallResult {
48 type: StreamType;
49 private _callback;
50 private _isCancelCalled;
51 stream?: CancellableStream;
52 /**
53 * StreamProxy is a proxy to gRPC-streaming method.
54 *
55 * @private
56 * @constructor
57 * @param {StreamType} type - the type of gRPC stream.
58 * @param {ApiCallback} callback - the callback for further API call.
59 */
60 constructor(type: StreamType, callback: APICallback);
61 cancel(): void;
62 /**
63 * Forward events from an API request stream to the user's stream.
64 * @param {Stream} stream - The API request stream.
65 */
66 forwardEvents(stream: Stream): void;
67 /**
68 * Specifies the target stream.
69 * @param {ApiCall} apiCall - the API function to be called.
70 * @param {Object} argument - the argument to be passed to the apiCall.
71 */
72 setStream(apiCall: SimpleCallbackFunction, argument: {}, retryRequestOptions?: RetryRequestOptions): void;
73}
74export {};