@@ -26,7 +26,6 @@ import {
26
26
SimpleCallbackFunction ,
27
27
} from '../apitypes' ;
28
28
import { RetryRequestOptions } from '../gax' ;
29
- import { StreamArrayParser } from '../streamArrayParser' ;
30
29
31
30
// eslint-disable-next-line @typescript-eslint/no-var-requires
32
31
const duplexify : DuplexifyConstructor = require ( 'duplexify' ) ;
@@ -91,6 +90,7 @@ export class StreamProxy extends duplexify implements GRPCCallResult {
91
90
private _isCancelCalled : boolean ;
92
91
stream ?: CancellableStream ;
93
92
private _responseHasSent : boolean ;
93
+ rest ?: boolean ;
94
94
/**
95
95
* StreamProxy is a proxy to gRPC-streaming method.
96
96
*
@@ -99,7 +99,7 @@ export class StreamProxy extends duplexify implements GRPCCallResult {
99
99
* @param {StreamType } type - the type of gRPC stream.
100
100
* @param {ApiCallback } callback - the callback for further API call.
101
101
*/
102
- constructor ( type : StreamType , callback : APICallback ) {
102
+ constructor ( type : StreamType , callback : APICallback , rest ?: boolean ) {
103
103
super ( undefined , undefined , {
104
104
objectMode : true ,
105
105
readable : type !== StreamType . CLIENT_STREAMING ,
@@ -109,6 +109,7 @@ export class StreamProxy extends duplexify implements GRPCCallResult {
109
109
this . _callback = callback ;
110
110
this . _isCancelCalled = false ;
111
111
this . _responseHasSent = false ;
112
+ this . rest = rest ;
112
113
}
113
114
114
115
cancel ( ) {
@@ -125,9 +126,6 @@ export class StreamProxy extends duplexify implements GRPCCallResult {
125
126
*/
126
127
forwardEvents ( stream : Stream ) {
127
128
const eventsToForward = [ 'metadata' , 'response' , 'status' ] ;
128
- if ( stream instanceof StreamArrayParser ) {
129
- eventsToForward . push ( 'data' , 'end' , 'error' ) ;
130
- }
131
129
eventsToForward . forEach ( event => {
132
130
stream . on ( event , this . emit . bind ( this , event ) ) ;
133
131
} ) ;
@@ -175,26 +173,30 @@ export class StreamProxy extends duplexify implements GRPCCallResult {
175
173
retryRequestOptions : RetryRequestOptions = { }
176
174
) {
177
175
if ( this . type === StreamType . SERVER_STREAMING ) {
178
- const retryStream = retryRequest ( null , {
179
- objectMode : true ,
180
- request : ( ) => {
181
- if ( this . _isCancelCalled ) {
182
- if ( this . stream ) {
183
- this . stream . cancel ( ) ;
176
+ const stream = apiCall ( argument , this . _callback ) as CancellableStream ;
177
+ this . stream = stream ;
178
+ if ( this . rest ) {
179
+ this . setReadable ( stream ) ;
180
+ } else {
181
+ const retryStream = retryRequest ( null , {
182
+ objectMode : true ,
183
+ request : ( ) => {
184
+ if ( this . _isCancelCalled ) {
185
+ if ( this . stream ) {
186
+ this . stream . cancel ( ) ;
187
+ }
188
+ return ;
184
189
}
185
- return ;
186
- }
187
- const stream = apiCall ( argument , this . _callback ) as CancellableStream ;
188
- this . stream = stream ;
189
- this . forwardEvents ( stream ) ;
190
- return stream ;
191
- } ,
192
- retries : retryRequestOptions ! . retries ,
193
- currentRetryAttempt : retryRequestOptions ! . currentRetryAttempt ,
194
- noResponseRetries : retryRequestOptions ! . noResponseRetries ,
195
- shouldRetryFn : retryRequestOptions ! . shouldRetryFn ,
196
- } ) ;
197
- this . setReadable ( retryStream ) ;
190
+ this . forwardEvents ( stream ) ;
191
+ return stream ;
192
+ } ,
193
+ retries : retryRequestOptions ! . retries ,
194
+ currentRetryAttempt : retryRequestOptions ! . currentRetryAttempt ,
195
+ noResponseRetries : retryRequestOptions ! . noResponseRetries ,
196
+ shouldRetryFn : retryRequestOptions ! . shouldRetryFn ,
197
+ } ) ;
198
+ this . setReadable ( retryStream ) ;
199
+ }
198
200
return ;
199
201
}
200
202
0 commit comments