From 827e5dac5982b9889ecbbd2d99807efa58059bcc Mon Sep 17 00:00:00 2001 From: Timm Stelzer Date: Fri, 3 Jan 2020 01:58:11 +0100 Subject: [PATCH] Fix publish and sendToQueue signatures. (#41217) As per the [documentation](https://github.com/benbria/node-amqp-connection-manager#amqpconnectionmanagercreatechanneloptions), the `content` field in `publish` and `sendToQueue` can be a plain object, when `createChannel`s `json` option is set. This commit extends the `content` parameter of those two functions. The change should be backwards compatible, as we're loosening requirements. Fixes #37295 --- .../amqp-connection-manager/amqp-connection-manager-tests.ts | 3 +++ types/amqp-connection-manager/index.d.ts | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/types/amqp-connection-manager/amqp-connection-manager-tests.ts b/types/amqp-connection-manager/amqp-connection-manager-tests.ts index ea2958cfbb..15f1789751 100644 --- a/types/amqp-connection-manager/amqp-connection-manager-tests.ts +++ b/types/amqp-connection-manager/amqp-connection-manager-tests.ts @@ -24,6 +24,9 @@ channelWrapper.sendToQueue("foo", Buffer.from("bar")) // nothing }); +// Test that plain objects are implicitly serialized. +channelWrapper.sendToQueue("foo", {a: 'bar'}).catch(_ => {}); + // Checking connection options amqpConMgr.connect(["foo", "bar"], { findServers(callback) { diff --git a/types/amqp-connection-manager/index.d.ts b/types/amqp-connection-manager/index.d.ts index 5863a5e314..15a30d25bf 100644 --- a/types/amqp-connection-manager/index.d.ts +++ b/types/amqp-connection-manager/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for amqp-connection-manager 2.0 // Project: https://github.com/benbria/node-amqp-connection-manager // Definitions by: rogierschouten +// tstelzer // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 3.2 @@ -158,7 +159,7 @@ export interface ChannelWrapper extends EventEmitter { * @param options * @param callback */ - publish(exchange: string, routingKey: string, content: Buffer, options?: Options.Publish, callback?: (err: any, ok: Replies.Empty) => void): Promise; + publish(exchange: string, routingKey: string, content: Buffer | object, options?: Options.Publish, callback?: (err: any, ok: Replies.Empty) => void): Promise; /** * @see amqplib @@ -167,7 +168,7 @@ export interface ChannelWrapper extends EventEmitter { * @param options * @param callback */ - sendToQueue(queue: string, content: Buffer, options?: Options.Publish, callback?: (err: any, ok: Replies.Empty) => void): Promise; + sendToQueue(queue: string, content: Buffer | object, options?: Options.Publish, callback?: (err: any, ok: Replies.Empty) => void): Promise; /** * @see amqplib