From e45e04aa69e60442df943e49982aeef746270593 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C5=A0vanda?= <46406259+Papooch@users.noreply.github.com> Date: Wed, 9 Nov 2022 16:08:47 +0100 Subject: [PATCH] fix(microservices): allow falsy values in options --- packages/microservices/client/client-kafka.ts | 24 ++++++++++++------- packages/microservices/client/client-proxy.ts | 2 +- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/packages/microservices/client/client-kafka.ts b/packages/microservices/client/client-kafka.ts index ba9ad099a33..fc3869af416 100644 --- a/packages/microservices/client/client-kafka.ts +++ b/packages/microservices/client/client-kafka.ts @@ -57,14 +57,22 @@ export class ClientKafka extends ClientProxy { constructor(protected readonly options: KafkaOptions['options']) { super(); - const clientOptions = - this.getOptionsProp(this.options, 'client') || ({} as KafkaConfig); - const consumerOptions = - this.getOptionsProp(this.options, 'consumer') || ({} as ConsumerConfig); - const postfixId = - this.getOptionsProp(this.options, 'postfixId') ?? '-client'; - this.producerOnlyMode = - this.getOptionsProp(this.options, 'producerOnlyMode') || false; + const clientOptions = this.getOptionsProp( + this.options, + 'client', + {} as KafkaConfig, + ); + const consumerOptions = this.getOptionsProp( + this.options, + 'consumer', + {} as ConsumerConfig, + ); + const postfixId = this.getOptionsProp(this.options, 'postfixId', '-client'); + this.producerOnlyMode = this.getOptionsProp( + this.options, + 'producerOnlyMode', + false, + ); this.brokers = clientOptions.brokers || [KAFKA_DEFAULT_BROKER]; diff --git a/packages/microservices/client/client-proxy.ts b/packages/microservices/client/client-proxy.ts index bdd3484d7d4..3950cf3dbf2 100644 --- a/packages/microservices/client/client-proxy.ts +++ b/packages/microservices/client/client-proxy.ts @@ -130,7 +130,7 @@ export abstract class ClientProxy { T extends ClientOptions['options'], K extends keyof T, >(obj: T, prop: K, defaultValue: T[K] = undefined) { - return (obj && obj[prop]) || defaultValue; + return obj && prop in obj ? obj[prop] : defaultValue; } protected normalizePattern(pattern: MsPattern): string {