From 94ed395897b967a4214f0d00bc8379dd0498edf6 Mon Sep 17 00:00:00 2001 From: Jeremy Meng Date: Mon, 28 Feb 2022 22:38:14 +0000 Subject: [PATCH 1/2] [ServiceBus] correct types for `propertiesToModify` options We claim that we can take `any` type of property values for properties to be modified but it's `applicationProperties` part of a Service Bus message that is modified. That property has a type of `number | boolean | string | Date | null` and is what the service supports. This PR corrects the types for these options to align with `applicationProperties`. Even though it shows as a breaking change, other unsupported types (e.g., an object literal) would cause service errors so they never worked. --- sdk/servicebus/service-bus/review/service-bus.api.md | 6 +++--- sdk/servicebus/service-bus/src/receivers/receiver.ts | 12 ++++++------ .../service-bus/src/receivers/receiverCommon.ts | 8 +++++--- .../service-bus/src/receivers/sessionReceiver.ts | 6 +++--- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/sdk/servicebus/service-bus/review/service-bus.api.md b/sdk/servicebus/service-bus/review/service-bus.api.md index 17708dd3e280..7bc4bd7f72ae 100644 --- a/sdk/servicebus/service-bus/review/service-bus.api.md +++ b/sdk/servicebus/service-bus/review/service-bus.api.md @@ -432,15 +432,15 @@ export interface ServiceBusReceivedMessage extends ServiceBusMessage { // @public export interface ServiceBusReceiver { abandonMessage(message: ServiceBusReceivedMessage, propertiesToModify?: { - [key: string]: any; + [key: string]: number | boolean | string | Date | null; }): Promise; close(): Promise; completeMessage(message: ServiceBusReceivedMessage): Promise; deadLetterMessage(message: ServiceBusReceivedMessage, options?: DeadLetterOptions & { - [key: string]: any; + [key: string]: number | boolean | string | Date | null; }): Promise; deferMessage(message: ServiceBusReceivedMessage, propertiesToModify?: { - [key: string]: any; + [key: string]: number | boolean | string | Date | null; }): Promise; entityPath: string; getMessageIterator(options?: GetMessageIteratorOptions): AsyncIterableIterator; diff --git a/sdk/servicebus/service-bus/src/receivers/receiver.ts b/sdk/servicebus/service-bus/src/receivers/receiver.ts index 7198658b4862..7ffdd559e519 100644 --- a/sdk/servicebus/service-bus/src/receivers/receiver.ts +++ b/sdk/servicebus/service-bus/src/receivers/receiver.ts @@ -193,7 +193,7 @@ export interface ServiceBusReceiver { */ abandonMessage( message: ServiceBusReceivedMessage, - propertiesToModify?: { [key: string]: any } + propertiesToModify?: { [key: string]: number | boolean | string | Date | null } ): Promise; /** * Defers the processing of the message. Save the `sequenceNumber` of the message, in order to @@ -219,7 +219,7 @@ export interface ServiceBusReceiver { */ deferMessage( message: ServiceBusReceivedMessage, - propertiesToModify?: { [key: string]: any } + propertiesToModify?: { [key: string]: number | boolean | string | Date | null } ): Promise; /** * Moves the message to the deadletter sub-queue. To receive a deadletted message, create a new @@ -246,7 +246,7 @@ export interface ServiceBusReceiver { */ deadLetterMessage( message: ServiceBusReceivedMessage, - options?: DeadLetterOptions & { [key: string]: any } + options?: DeadLetterOptions & { [key: string]: number | boolean | string | Date | null } ): Promise; /** * Renews the lock on the message for the duration as specified during the Queue/Subscription @@ -543,7 +543,7 @@ export class ServiceBusReceiverImpl implements ServiceBusReceiver { async abandonMessage( message: ServiceBusReceivedMessage, - propertiesToModify?: { [key: string]: any } + propertiesToModify?: { [key: string]: number | boolean | string | Date | null } ): Promise { this._throwIfReceiverOrConnectionClosed(); throwErrorIfInvalidOperationOnMessage(message, this.receiveMode, this._context.connectionId); @@ -559,7 +559,7 @@ export class ServiceBusReceiverImpl implements ServiceBusReceiver { async deferMessage( message: ServiceBusReceivedMessage, - propertiesToModify?: { [key: string]: any } + propertiesToModify?: { [key: string]: number | boolean | string | Date | null } ): Promise { this._throwIfReceiverOrConnectionClosed(); throwErrorIfInvalidOperationOnMessage(message, this.receiveMode, this._context.connectionId); @@ -575,7 +575,7 @@ export class ServiceBusReceiverImpl implements ServiceBusReceiver { async deadLetterMessage( message: ServiceBusReceivedMessage, - options?: DeadLetterOptions & { [key: string]: any } + options?: DeadLetterOptions & { [key: string]: number | boolean | string | Date | null } ): Promise { this._throwIfReceiverOrConnectionClosed(); throwErrorIfInvalidOperationOnMessage(message, this.receiveMode, this._context.connectionId); diff --git a/sdk/servicebus/service-bus/src/receivers/receiverCommon.ts b/sdk/servicebus/service-bus/src/receivers/receiverCommon.ts index c98c75ec9bb4..69fe9105e03f 100644 --- a/sdk/servicebus/service-bus/src/receivers/receiverCommon.ts +++ b/sdk/servicebus/service-bus/src/receivers/receiverCommon.ts @@ -108,7 +108,7 @@ export function abandonMessage( message: ServiceBusMessageImpl, context: ConnectionContext, entityPath: string, - propertiesToModify: { [key: string]: any } | undefined, + propertiesToModify: { [key: string]: number | boolean | string | Date | null } | undefined, retryOptions: RetryOptions | undefined ): Promise { receiverLogger.verbose( @@ -130,7 +130,7 @@ export function deferMessage( message: ServiceBusMessageImpl, context: ConnectionContext, entityPath: string, - propertiesToModify: { [key: string]: any } | undefined, + propertiesToModify: { [key: string]: number | boolean | string | Date | null } | undefined, retryOptions: RetryOptions | undefined ): Promise { receiverLogger.verbose( @@ -152,7 +152,9 @@ export function deadLetterMessage( message: ServiceBusMessageImpl, context: ConnectionContext, entityPath: string, - propertiesToModify: (DeadLetterOptions & { [key: string]: any }) | undefined, + propertiesToModify: + | (DeadLetterOptions & { [key: string]: number | boolean | string | Date | null }) + | undefined, retryOptions: RetryOptions | undefined ): Promise { receiverLogger.verbose( diff --git a/sdk/servicebus/service-bus/src/receivers/sessionReceiver.ts b/sdk/servicebus/service-bus/src/receivers/sessionReceiver.ts index ff63a7864b0a..5cadd9a2b65e 100644 --- a/sdk/servicebus/service-bus/src/receivers/sessionReceiver.ts +++ b/sdk/servicebus/service-bus/src/receivers/sessionReceiver.ts @@ -510,7 +510,7 @@ export class ServiceBusSessionReceiverImpl implements ServiceBusSessionReceiver async abandonMessage( message: ServiceBusReceivedMessage, - propertiesToModify?: { [key: string]: any } + propertiesToModify?: { [key: string]: number | boolean | string | Date | null } ): Promise { this._throwIfReceiverOrConnectionClosed(); throwErrorIfInvalidOperationOnMessage(message, this.receiveMode, this._context.connectionId); @@ -526,7 +526,7 @@ export class ServiceBusSessionReceiverImpl implements ServiceBusSessionReceiver async deferMessage( message: ServiceBusReceivedMessage, - propertiesToModify?: { [key: string]: any } + propertiesToModify?: { [key: string]: number | boolean | string | Date | null } ): Promise { this._throwIfReceiverOrConnectionClosed(); throwErrorIfInvalidOperationOnMessage(message, this.receiveMode, this._context.connectionId); @@ -542,7 +542,7 @@ export class ServiceBusSessionReceiverImpl implements ServiceBusSessionReceiver async deadLetterMessage( message: ServiceBusReceivedMessage, - options?: DeadLetterOptions & { [key: string]: any } + options?: DeadLetterOptions & { [key: string]: number | boolean | string | Date | null } ): Promise { this._throwIfReceiverOrConnectionClosed(); throwErrorIfInvalidOperationOnMessage(message, this.receiveMode, this._context.connectionId); From ee36f5f789cd4e8d945917e832bca268dd408371 Mon Sep 17 00:00:00 2001 From: Jeremy Meng Date: Tue, 1 Mar 2022 00:11:47 +0000 Subject: [PATCH 2/2] Add CHANGELOG entry --- sdk/servicebus/service-bus/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/servicebus/service-bus/CHANGELOG.md b/sdk/servicebus/service-bus/CHANGELOG.md index e262f242fa3b..06cf74a5b8e8 100644 --- a/sdk/servicebus/service-bus/CHANGELOG.md +++ b/sdk/servicebus/service-bus/CHANGELOG.md @@ -9,6 +9,7 @@ ### Bugs Fixed - Fix an issue where we don't respect user request to close the receiver if the connection is disconnected when using the `subscribe()` method. [PR #20427](https://github.com/Azure/azure-sdk-for-js/pull/20427) +- Correct typing of `propertiesToModify` options to `abandonMessages()`, `deferMessages()`, and "deadLetterMessages()" [PR #20577](https://github.com/Azure/azure-sdk-for-js/pull/20577) ### Other Changes