diff --git a/package.json b/package.json index c818847eb..255adacf2 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,6 @@ "dependencies": { "@grpc/grpc-js": "^0.3.0", "@grpc/proto-loader": "^0.4.0", - "@types/duplexify": "^3.6.0", "duplexify": "^3.6.0", "google-auth-library": "^3.0.0", "google-proto-files": "^0.20.0", diff --git a/src/streaming.ts b/src/streaming.ts index 2602836d2..1ed0dd29b 100644 --- a/src/streaming.ts +++ b/src/streaming.ts @@ -31,13 +31,35 @@ /* This file describes the gRPC-streaming. */ -import * as Duplexify from 'duplexify'; -import {Duplex, DuplexOptions, Stream} from 'stream'; +import {Duplex, DuplexOptions, Readable, Stream, Writable} from 'stream'; + import {APICall, APICallback} from './apiCallable'; import {warn} from './warnings'; +const duplexify: DuplexifyConstructor = require('duplexify'); const retryRequest = require('retry-request'); +// Directly copy over Duplexify interfaces +export interface DuplexifyOptions extends DuplexOptions { + autoDestroy?: boolean; + end?: boolean; +} + +export interface Duplexify extends Duplex { + readonly destroyed: boolean; + setWritable(writable: Writable|false|null): void; + setReadable(readable: Readable|false|null): void; +} + +export interface DuplexifyConstructor { + obj(writable?: Writable|false|null, readable?: Readable|false|null, + options?: DuplexifyOptions): Duplexify; + new(writable?: Writable|false|null, readable?: Readable|false|null, + options?: DuplexifyOptions): Duplexify; + (writable?: Writable|false|null, readable?: Readable|false|null, + options?: DuplexifyOptions): Duplexify; +} + /** * The type of gRPC streaming. * @enum {number} @@ -53,7 +75,7 @@ export enum StreamType { BIDI_STREAMING = 3, } -export class StreamProxy extends Duplexify { +export class StreamProxy extends duplexify { type: StreamType; private _callback?: Function; private _isCancelCalled: boolean;