From a87ec5fe4911f3979cdcee9fa5b3ee6fbba1f8b8 Mon Sep 17 00:00:00 2001 From: Cyril Schumacher Date: Sun, 11 Jun 2017 12:31:34 +0200 Subject: [PATCH 1/3] Update bunnymq definition (2.3.2). --- types/bunnymq/bunnymq-tests.ts | 21 ++++------------ types/bunnymq/index.d.ts | 45 +++++++++------------------------- 2 files changed, 16 insertions(+), 50 deletions(-) diff --git a/types/bunnymq/bunnymq-tests.ts b/types/bunnymq/bunnymq-tests.ts index 4105363f25..e83fe606da 100644 --- a/types/bunnymq/bunnymq-tests.ts +++ b/types/bunnymq/bunnymq-tests.ts @@ -4,31 +4,20 @@ import * as bunnymq from "bunnymq"; var instance = bunnymq({ host: 'amqp://localhost' }); // Publisher -instance.producer.produce('queue:name', 'Hello World!'); +instance.publish("queue:name", "message"); // Subscriber -instance.consumer.consume('queue:name', message => { }); +instance.subscribe('queue:name', (message: string) => "hello,world"); // RPC Support -instance.producer.produce('queue:name', { message: 'content' }, { rpc: true }) - .then(function (consumerResponse) { - console.log(consumerResponse); - }); - -// Routing keys -instance.producer.produce('queue:name', { message: 'content' }, { routingKey: 'my-routing-key' }); +instance.publish('queue:name', { message: 'content' }, { routingKey: 'my-routing-key', rpc: true }).then((consumerResponse: string) => { }); // Config var custom = bunnymq({ host: 'amqp://localhost', - //number of fetched messages at once on the channel prefetch: 5, - //requeue put back message into the broker if consumer crashes/trigger exception requeue: true, - //time between two reconnect (ms) timeout: 1000, - consumerSuffix: '', - //generate a hostname so we can track this connection on the broker (rabbitmq management plugin) + consumerSuffix: "", hostname: "", - //the transport to use to debug. if provided, bunnymq will show some logs transport: new Object() -}); \ No newline at end of file +}); diff --git a/types/bunnymq/index.d.ts b/types/bunnymq/index.d.ts index 1167db21ed..867ebfd82c 100644 --- a/types/bunnymq/index.d.ts +++ b/types/bunnymq/index.d.ts @@ -1,25 +1,10 @@ -// Type definitions for node-bunnymq 2.2.1 +// Type definitions for node-bunnymq 2.3.2 // Project: https://github.com/dial-once/node-bunnymq // Definitions by: Cyril Schumacher // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare module "bunnymq" { namespace bunnymq { - export type ConsumerCallback = (message: Object) => void; - - /** - * Consumer. - * @interface - */ - export interface Consumer { - /** - * Handle messages from a named queue. - * @param {string} queue A named queue. - * @param {ConsumerCallback} callback A callback. - */ - consume(queue: string, callback: ConsumerCallback): void; - } - /** * bunnymq instance. * @interface @@ -29,13 +14,13 @@ declare module "bunnymq" { * Consumer. * @type {Consumer} */ - consumer: Consumer; + subscribe(queueName: string, callback: (...args: any[]) => T): void; /** * Producer. * @type {Producer} */ - producer: Producer; + publish(queueName: string, message: any, options?: PublisherOptions): Promise; } /** @@ -73,6 +58,12 @@ declare module "bunnymq" { */ requeue?: boolean; + /** + * Default timeout for RPC calls. + * @type {number} + */ + rpcTimeout?: number; + /** * Time between two reconnect (in milliseconds). * @type {number} @@ -87,24 +78,10 @@ declare module "bunnymq" { } /** - * Producer. - * @inteface - */ - export interface Producer { - /** - * Send messages to a named queue. - * @param {string} queue A named queue. - * @param {Object} message A message. - * @return {Object} The consumer response. - */ - produce(queue: string, message: Object, options?: ProducerOptions): PromiseLike; - } - - /** - * Options for producer. + * Options for publisher. * @interface */ - export interface ProducerOptions { + export interface PublisherOptions { routingKey?: string; rpc?: boolean; } From 94330023d9fe246f72c306086d683c3a4b4946e6 Mon Sep 17 00:00:00 2001 From: Cyril Schumacher Date: Sun, 11 Jun 2017 13:37:59 +0200 Subject: [PATCH 2/3] Update bunnymq definition and tests. --- types/bunnymq/bunnymq-tests.ts | 12 ++-- types/bunnymq/index.d.ts | 113 +++++++++++++++++---------------- 2 files changed, 65 insertions(+), 60 deletions(-) diff --git a/types/bunnymq/bunnymq-tests.ts b/types/bunnymq/bunnymq-tests.ts index e83fe606da..3ab71dbb80 100644 --- a/types/bunnymq/bunnymq-tests.ts +++ b/types/bunnymq/bunnymq-tests.ts @@ -1,19 +1,23 @@ import * as bunnymq from "bunnymq"; // Basic usage -var instance = bunnymq({ host: 'amqp://localhost' }); +var instance = bunnymq({ host: "amqp://localhost" }); // Publisher instance.publish("queue:name", "message"); +instance.producer.produce("queue:name", "message"); + // Subscriber -instance.subscribe('queue:name', (message: string) => "hello,world"); +instance.subscribe("queue:name", (message: string) => "response"); +instance.consumer.consume("queue:name", (message: string) => "response"); // RPC Support -instance.publish('queue:name', { message: 'content' }, { routingKey: 'my-routing-key', rpc: true }).then((consumerResponse: string) => { }); +instance.publish("queue:name", { message: "content" }, { routingKey: "my-routing-key", rpc: true, timeout: 1000 }).then((consumerResponse: string) => "response"); +instance.producer.produce("queue:name", { message: "content" }, { rpc: true, routingKey: "my-routing-key", timeout: 1000 }); // Config var custom = bunnymq({ - host: 'amqp://localhost', + host: "amqp://localhost", prefetch: 5, requeue: true, timeout: 1000, diff --git a/types/bunnymq/index.d.ts b/types/bunnymq/index.d.ts index 867ebfd82c..62b96144b8 100644 --- a/types/bunnymq/index.d.ts +++ b/types/bunnymq/index.d.ts @@ -5,93 +5,94 @@ declare module "bunnymq" { namespace bunnymq { - /** - * bunnymq instance. - * @interface - */ - export interface Instance { - /** - * Consumer. - * @type {Consumer} - */ - subscribe(queueName: string, callback: (...args: any[]) => T): void; + export type ConsumerCallback = (...args: any[]) => T; + export type LoggerOutput = (format: any, ...args: any[]) => void; + export interface Connection { + [address: string]: any; + startedAt: string; + } + export interface Consumer { /** - * Producer. - * @type {Producer} + * Handle messages from a named queue. + * + * @param {string} queue A named queue. + * @param {ConsumerCallback} callback A callback. */ - publish(queueName: string, message: any, options?: PublisherOptions): Promise; + consume(queue: string, callback: ConsumerCallback): void; + } + + export interface Instance { + connection: Connection; + consumer: Consumer; + producer: Producer; + + /** + * Subscriber to handle messages from a named queue. + * + * @param {string} queue A named queue. + * @param {ConsumerCallback} callback A callback. + */ + subscribe(queueName: string, callback: ConsumerCallback): void; + + /** + * Publisher to send messages to a named queue. + * + * @type {Producer} + * @return {Promise} The consumer response. + */ + publish(queueName: string, message: any, options?: ProducerOptions): Promise; + } + + export interface Logger { + debug: LoggerOutput; + error: LoggerOutput; + info: LoggerOutput; + log: LoggerOutput; + warn: LoggerOutput; } - /** - * Options. - * @interface - */ export interface Options { - /** - * Consumer suffix. - * @type {string} - */ consumerSuffix?: string; - - /** - * Host. - * @type {string} - */ host?: string; - - /** - * Hostname. - * @type {string} - */ hostname?: string; /** * Number of fetched messages at once on the channel. + * * @type {number} */ prefetch?: number; /** * Requeue put back message into the broker if consumer crashes/trigger exception. + * * @type {boolean} */ requeue?: boolean; - - /** - * Default timeout for RPC calls. - * @type {number} - */ rpcTimeout?: number; - - /** - * Time between two reconnect (in milliseconds). - * @type {number} - */ timeout?: number; - - /** - * Transport. - * @type {any} - */ transport?: any; } - /** - * Options for publisher. - * @interface - */ - export interface PublisherOptions { + export interface Producer { + /** + * Send messages to a named queue. + * + * @param {string} queue A named queue. + * @param {any} message A message. + * @return {Promise} The consumer response. + */ + produce(queue: string, message: any, options?: ProducerOptions): Promise; + } + + export interface ProducerOptions { routingKey?: string; rpc?: boolean; + timeout?: number; } } - /** - * Constructor. - * @param {Options} [options] Options. - * @return {Instance} A instance of bunnymq. - */ function bunnymq(options?: bunnymq.Options): bunnymq.Instance; export = bunnymq; } From d290995d52892fe613621a59c91ad8c7b0847bba Mon Sep 17 00:00:00 2001 From: Cyril Schumacher Date: Sun, 11 Jun 2017 13:49:55 +0200 Subject: [PATCH 3/3] Add file: "tslint.json". Fix tslint errors. --- types/bunnymq/bunnymq-tests.ts | 4 +- types/bunnymq/index.d.ts | 180 ++++++++++++++++----------------- types/bunnymq/tslint.json | 3 + 3 files changed, 95 insertions(+), 92 deletions(-) create mode 100644 types/bunnymq/tslint.json diff --git a/types/bunnymq/bunnymq-tests.ts b/types/bunnymq/bunnymq-tests.ts index 3ab71dbb80..960c0b6949 100644 --- a/types/bunnymq/bunnymq-tests.ts +++ b/types/bunnymq/bunnymq-tests.ts @@ -1,7 +1,7 @@ import * as bunnymq from "bunnymq"; // Basic usage -var instance = bunnymq({ host: "amqp://localhost" }); +const instance = bunnymq({ host: "amqp://localhost" }); // Publisher instance.publish("queue:name", "message"); @@ -16,7 +16,7 @@ instance.publish("queue:name", { message: "content" }, { routingKey: "my-routing instance.producer.produce("queue:name", { message: "content" }, { rpc: true, routingKey: "my-routing-key", timeout: 1000 }); // Config -var custom = bunnymq({ +const instanceWithCustomOptions = bunnymq({ host: "amqp://localhost", prefetch: 5, requeue: true, diff --git a/types/bunnymq/index.d.ts b/types/bunnymq/index.d.ts index 62b96144b8..c4c0a770e1 100644 --- a/types/bunnymq/index.d.ts +++ b/types/bunnymq/index.d.ts @@ -1,98 +1,98 @@ -// Type definitions for node-bunnymq 2.3.2 +// Type definitions for node-bunnymq 2.3 // Project: https://github.com/dial-once/node-bunnymq // Definitions by: Cyril Schumacher // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare module "bunnymq" { - namespace bunnymq { - export type ConsumerCallback = (...args: any[]) => T; - export type LoggerOutput = (format: any, ...args: any[]) => void; +declare function bunnymq(options?: bunnymq.Options): bunnymq.Instance; +declare namespace bunnymq { + type ConsumerCallback = (...args: any[]) => T; + type LoggerOutput = (format: any, ...args: any[]) => void; - export interface Connection { - [address: string]: any; - startedAt: string; - } - export interface Consumer { - /** - * Handle messages from a named queue. - * - * @param {string} queue A named queue. - * @param {ConsumerCallback} callback A callback. - */ - consume(queue: string, callback: ConsumerCallback): void; - } - - export interface Instance { - connection: Connection; - consumer: Consumer; - producer: Producer; - - /** - * Subscriber to handle messages from a named queue. - * - * @param {string} queue A named queue. - * @param {ConsumerCallback} callback A callback. - */ - subscribe(queueName: string, callback: ConsumerCallback): void; - - /** - * Publisher to send messages to a named queue. - * - * @type {Producer} - * @return {Promise} The consumer response. - */ - publish(queueName: string, message: any, options?: ProducerOptions): Promise; - } - - export interface Logger { - debug: LoggerOutput; - error: LoggerOutput; - info: LoggerOutput; - log: LoggerOutput; - warn: LoggerOutput; - } - - export interface Options { - consumerSuffix?: string; - host?: string; - hostname?: string; - - /** - * Number of fetched messages at once on the channel. - * - * @type {number} - */ - prefetch?: number; - - /** - * Requeue put back message into the broker if consumer crashes/trigger exception. - * - * @type {boolean} - */ - requeue?: boolean; - rpcTimeout?: number; - timeout?: number; - transport?: any; - } - - export interface Producer { - /** - * Send messages to a named queue. - * - * @param {string} queue A named queue. - * @param {any} message A message. - * @return {Promise} The consumer response. - */ - produce(queue: string, message: any, options?: ProducerOptions): Promise; - } - - export interface ProducerOptions { - routingKey?: string; - rpc?: boolean; - timeout?: number; - } + interface Connection { + [address: string]: any; + startedAt: string; } - function bunnymq(options?: bunnymq.Options): bunnymq.Instance; - export = bunnymq; + interface Consumer { + /** + * Handle messages from a named queue. + * + * @param {string} queue A named queue. + * @param {ConsumerCallback} callback A callback. + */ + consume(queue: string, callback: ConsumerCallback): void; + } + + interface Instance { + connection: Connection; + consumer: Consumer; + producer: Producer; + + /** + * Subscriber to handle messages from a named queue. + * + * @param {string} queue A named queue. + * @param {ConsumerCallback} callback A callback. + */ + subscribe(queueName: string, callback: ConsumerCallback): void; + + /** + * Publisher to send messages to a named queue. + * + * @type {Producer} + * @return {Promise} The consumer response. + */ + publish(queueName: string, message: any, options?: ProducerOptions): Promise; + } + + interface Logger { + debug: LoggerOutput; + error: LoggerOutput; + info: LoggerOutput; + log: LoggerOutput; + warn: LoggerOutput; + } + + interface Options { + consumerSuffix?: string; + host?: string; + hostname?: string; + + /** + * Number of fetched messages at once on the channel. + * + * @type {number} + */ + prefetch?: number; + + /** + * Requeue put back message into the broker if consumer crashes/trigger exception. + * + * @type {boolean} + */ + requeue?: boolean; + rpcTimeout?: number; + timeout?: number; + transport?: any; + } + + interface Producer { + /** + * Send messages to a named queue. + * + * @param {string} queue A named queue. + * @param {any} message A message. + * @return {Promise} The consumer response. + */ + produce(queue: string, message: any, options?: ProducerOptions): Promise; + } + + interface ProducerOptions { + routingKey?: string; + rpc?: boolean; + timeout?: number; + } } + +export = bunnymq; +export as namespace bunnymq; diff --git a/types/bunnymq/tslint.json b/types/bunnymq/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/bunnymq/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}