From a3526e98c84b1a11dbc7087d3e9defdb0cf5785d Mon Sep 17 00:00:00 2001 From: Michael Lumish Date: Tue, 24 Mar 2020 12:55:24 -0700 Subject: [PATCH] Delete client-specific options before passing them to the channel --- packages/grpc-js/src/client.ts | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/packages/grpc-js/src/client.ts b/packages/grpc-js/src/client.ts index 54679034..8b4b7eea 100644 --- a/packages/grpc-js/src/client.ts +++ b/packages/grpc-js/src/client.ts @@ -109,10 +109,28 @@ export class Client { credentials: ChannelCredentials, options: ClientOptions = {} ) { + options = Object.assign({}, options); + this[INTERCEPTOR_SYMBOL] = options.interceptors ?? []; + delete options.interceptors; + this[INTERCEPTOR_PROVIDER_SYMBOL] = options.interceptor_providers ?? []; + delete options.interceptor_providers; + if ( + this[INTERCEPTOR_SYMBOL].length > 0 && + this[INTERCEPTOR_PROVIDER_SYMBOL].length > 0 + ) { + throw new Error( + 'Both interceptors and interceptor_providers were passed as options ' + + 'to the client constructor. Only one of these is allowed.' + ); + } + this[CALL_INVOCATION_TRANSFORMER_SYMBOL] = options.callInvocationTransformer; + delete options.callInvocationTransformer; if (options.channelOverride) { this[CHANNEL_SYMBOL] = options.channelOverride; } else if (options.channelFactoryOverride) { - this[CHANNEL_SYMBOL] = options.channelFactoryOverride( + const channelFactoryOverride = options.channelFactoryOverride; + delete options.channelFactoryOverride; + this[CHANNEL_SYMBOL] = channelFactoryOverride( address, credentials, options @@ -124,18 +142,6 @@ export class Client { options ); } - this[INTERCEPTOR_SYMBOL] = options.interceptors ?? []; - this[INTERCEPTOR_PROVIDER_SYMBOL] = options.interceptor_providers ?? []; - if ( - this[INTERCEPTOR_SYMBOL].length > 0 && - this[INTERCEPTOR_PROVIDER_SYMBOL].length > 0 - ) { - throw new Error( - 'Both interceptors and interceptor_providers were passed as options ' + - 'to the client constructor. Only one of these is allowed.' - ); - } - this[CALL_INVOCATION_TRANSFORMER_SYMBOL] = options.callInvocationTransformer; } close(): void {