diff --git a/amqplib/amqplib-0.3.d.ts b/amqplib/amqplib-0.3.d.ts new file mode 100644 index 0000000000..3138f7494e --- /dev/null +++ b/amqplib/amqplib-0.3.d.ts @@ -0,0 +1,219 @@ +// Type definitions for amqplib 0.3.x +// Project: https://github.com/squaremo/amqp.node +// Definitions by: Michael Nahkies , Ab Reitsma +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// +/// + +declare module "amqplib/properties" { + namespace Replies { + interface Empty { + } + interface AssertQueue { + queue: string; + messageCount: number; + consumerCount: number; + } + interface PurgeQueue { + messageCount: number; + } + interface DeleteQueue { + messageCount: number; + } + interface AssertExchange { + exchange: string; + } + interface Consume { + consumerTag: string; + } + } + + namespace Options { + interface AssertQueue { + exclusive?: boolean; + durable?: boolean; + autoDelete?: boolean; + arguments?: any; + messageTtl?: number; + expires?: number; + deadLetterExchange?: string; + deadLetterRoutingKey?: string; + maxLength?: number; + } + interface DeleteQueue { + ifUnused?: boolean; + ifEmpty?: boolean; + } + interface AssertExchange { + durable?: boolean; + internal?: boolean; + autoDelete?: boolean; + alternateExchange?: string; + arguments?: any; + } + interface DeleteExchange { + ifUnused?: boolean; + } + interface Publish { + expiration?: string; + userId?: string; + CC?: string | string[]; + + mandatory?: boolean; + persistent?: boolean; + deliveryMode?: boolean | number; + BCC?: string | string[]; + + contentType?: string; + contentEncoding?: string; + headers?: any; + priority?: number; + correlationId?: string; + replyTo?: string; + messageId?: string; + timestamp?: number; + type?: string; + appId?: string; + } + interface Consume { + consumerTag?: string; + noLocal?: boolean; + noAck?: boolean; + exclusive?: boolean; + priority?: number; + arguments?: any; + } + interface Get { + noAck?: boolean; + } + } + + interface Message { + content: Buffer; + fields: any; + properties: any; + } +} + +declare module "amqplib" { + + import events = require("events"); + import when = require("when"); + import shared = require("amqplib/properties") + export import Replies = shared.Replies; + export import Options = shared.Options; + export import Message = shared.Message; + + interface Connection extends events.EventEmitter { + close(): when.Promise; + createChannel(): when.Promise; + createConfirmChannel(): when.Promise; + } + + interface Channel extends events.EventEmitter { + close(): when.Promise; + + assertQueue(queue: string, options?: Options.AssertQueue): when.Promise; + checkQueue(queue: string): when.Promise; + + deleteQueue(queue: string, options?: Options.DeleteQueue): when.Promise; + purgeQueue(queue: string): when.Promise; + + bindQueue(queue: string, source: string, pattern: string, args?: any): when.Promise; + unbindQueue(queue: string, source: string, pattern: string, args?: any): when.Promise; + + assertExchange(exchange: string, type: string, options?: Options.AssertExchange): when.Promise; + checkExchange(exchange: string): when.Promise; + + deleteExchange(exchange: string, options?: Options.DeleteExchange): when.Promise; + + bindExchange(destination: string, source: string, pattern: string, args?: any): when.Promise; + unbindExchange(destination: string, source: string, pattern: string, args?: any): when.Promise; + + publish(exchange: string, routingKey: string, content: Buffer, options?: Options.Publish): boolean; + sendToQueue(queue: string, content: Buffer, options?: Options.Publish): boolean; + + consume(queue: string, onMessage: (msg: Message) => any, options?: Options.Consume): when.Promise; + + cancel(consumerTag: string): when.Promise; + get(queue: string, options?: Options.Get): when.Promise; + + ack(message: Message, allUpTo?: boolean): void; + ackAll(): void; + + nack(message: Message, allUpTo?: boolean, requeue?: boolean): void; + nackAll(requeue?: boolean): void; + reject(message: Message, requeue?: boolean): void; + + prefetch(count: number, global?: boolean): when.Promise; + recover(): when.Promise; + } + + function connect(url: string, socketOptions?: any): when.Promise; +} + +declare module "amqplib/callback_api" { + + import events = require("events"); + import shared = require("amqplib/properties") + export import Replies = shared.Replies; + export import Options = shared.Options; + export import Message = shared.Message; + + interface Connection extends events.EventEmitter { + close(callback?: (err: any) => void): void; + createChannel(callback: (err: any, channel: Channel) => void): void; + createConfirmChannel(callback: (err: any, confirmChannel: ConfirmChannel) => void): void; + } + + interface Channel extends events.EventEmitter { + close(callback: (err: any) => void): void; + + assertQueue(queue?: string, options?: Options.AssertQueue, callback?: (err:any, ok: Replies.AssertQueue) => void): void; + checkQueue(queue: string, callback?: (err: any, ok: Replies.AssertQueue) => void): void; + + deleteQueue(queue: string, options?: Options.DeleteQueue, callback?: (err:any, ok: Replies.DeleteQueue) => void): void; + purgeQueue(queue: string, callback?: (err:any, ok: Replies.PurgeQueue) => void): void; + + bindQueue(queue: string, source: string, pattern: string, args?: any, callback?: (err: any, ok: Replies.Empty) => void): void; + unbindQueue(queue: string, source: string, pattern: string, args?: any, callback?: (err: any, ok: Replies.Empty) => void): void; + + assertExchange(exchange: string, type: string, options?: Options.AssertExchange, callback?: (err: any, ok: Replies.AssertExchange) => void): void; + checkExchange(exchange: string, callback?: (err: any, ok: Replies.Empty) => void): void; + + deleteExchange(exchange: string, options?: Options.DeleteExchange, callback?: (err: any, ok: Replies.Empty) => void): void; + + bindExchange(destination: string, source: string, pattern: string, args?: any, callback?: (err: any, ok: Replies.Empty) => void): void; + unbindExchange(destination: string, source: string, pattern: string, args?: any, callback?: (err: any, ok: Replies.Empty) => void): void; + + publish(exchange: string, routingKey: string, content: Buffer, options?: Options.Publish): boolean; + sendToQueue(queue: string, content: Buffer, options?: Options.Publish): boolean; + + consume(queue: string, onMessage: (msg: Message) => any, options?: Options.Consume, callback?: (err: any, ok: Replies.Consume) => void): void; + + cancel(consumerTag: string, callback?: (err: any, ok: Replies.Empty) => void): void; + get(queue: string, options?: Options.Get, callback?: (err: any, ok: Message | boolean) => void): void; + + ack(message: Message, allUpTo?: boolean): void; + ackAll(): void; + + nack(message: Message, allUpTo?: boolean, requeue?: boolean): void; + nackAll(requeue?: boolean): void; + reject(message: Message, requeue?: boolean): void; + + prefetch(count: number, global?: boolean): void; + recover(callback?: (err: any, ok: Replies.Empty) => void): void; + } + + interface ConfirmChannel extends Channel { + publish(exchange: string, routingKey: string, content: Buffer, options?: Options.Publish, callback?: (err: any, ok: Replies.Empty) => void): boolean; + sendToQueue(queue: string, content: Buffer, options?: Options.Publish, callback?: (err: any, ok: Replies.Empty) => void): boolean; + + waitForConfirms(callback?: (err: any) => void): void; + } + + function connect(callback: (err: any, connection: Connection) => void): void; + function connect(url: string, callback: (err: any, connection: Connection) => void): void; + function connect(url: string, socketOptions: any, callback: (err: any, connection: Connection) => void): void; +} diff --git a/amqplib/amqplib-tests.ts b/amqplib/amqplib-tests.ts index 07b9ec5402..b17128653a 100644 --- a/amqplib/amqplib-tests.ts +++ b/amqplib/amqplib-tests.ts @@ -1,44 +1,42 @@ - - // promise api tests -import amqp = require("amqplib"); +import amqp = require('amqplib'); -var msg = "Hello World"; +var msg = 'Hello World'; // test promise api -amqp.connect("amqp://localhost") +amqp.connect('amqp://localhost') .then(connection => { return connection.createChannel() - .tap(channel => channel.checkQueue("myQueue")) - .then(channel => channel.sendToQueue("myQueue", new Buffer(msg))) - .ensure(() => connection.close()); + .tap(channel => channel.checkQueue('myQueue')) + .then(channel => channel.sendToQueue('myQueue', new Buffer(msg))) + .finally(() => connection.close()); }); -amqp.connect("amqp://localhost") +amqp.connect('amqp://localhost') .then(connection => { return connection.createChannel() - .tap(channel => channel.checkQueue("myQueue")) - .then(channel => channel.consume("myQueue", newMsg => console.log("New Message: " + newMsg.content.toString()))) - .ensure(() => connection.close()); + .tap(channel => channel.checkQueue('myQueue')) + .then(channel => channel.consume('myQueue', newMsg => console.log('New Message: ' + newMsg.content.toString()))) + .finally(() => connection.close()); }); // test promise api properties var amqpMessage: amqp.Message; -amqpMessage.properties.contentType = "application/json"; +amqpMessage.properties.contentType = 'application/json'; var amqpAssertExchangeOptions: amqp.Options.AssertExchange; var anqpAssertExchangeReplies: amqp.Replies.AssertExchange; // callback api tests -import amqpcb = require("amqplib/callback_api"); +import amqpcb = require('amqplib/callback_api'); -amqpcb.connect("amqp://localhost", (err, connection) => { +amqpcb.connect('amqp://localhost', (err, connection) => { if(!err) { connection.createChannel((err, channel) => { if (!err) { - channel.assertQueue("myQueue", {}, (err, ok) => { + channel.assertQueue('myQueue', {}, (err, ok) => { if(!err) { - channel.sendToQueue("myQueue", new Buffer(msg)); + channel.sendToQueue('myQueue', new Buffer(msg)); } }); } @@ -46,13 +44,13 @@ amqpcb.connect("amqp://localhost", (err, connection) => { } }); -amqpcb.connect("amqp://localhost", (err, connection) => { +amqpcb.connect('amqp://localhost', (err, connection) => { if(!err) { connection.createChannel((err, channel) => { if (!err) { - channel.assertQueue("myQueue", {}, (err, ok) => { + channel.assertQueue('myQueue', {}, (err, ok) => { if(!err) { - channel.consume("myQueue", newMsg => console.log("New Message: " + newMsg.content.toString())); + channel.consume('myQueue', newMsg => console.log('New Message: ' + newMsg.content.toString())); } }); } @@ -62,6 +60,6 @@ amqpcb.connect("amqp://localhost", (err, connection) => { // test callback api properties var amqpcbMessage: amqpcb.Message; -amqpcbMessage.properties.contentType = "application/json"; +amqpcbMessage.properties.contentType = 'application/json'; var amqpcbAssertExchangeOptions: amqpcb.Options.AssertExchange; -var anqpcbAssertExchangeReplies: amqpcb.Replies.AssertExchange; \ No newline at end of file +var anqpcbAssertExchangeReplies: amqpcb.Replies.AssertExchange; diff --git a/amqplib/index.d.ts b/amqplib/index.d.ts index 3138f7494e..b406e00ac0 100644 --- a/amqplib/index.d.ts +++ b/amqplib/index.d.ts @@ -1,13 +1,76 @@ -// Type definitions for amqplib 0.3.x +// Type definitions for amqplib 0.5.x // Project: https://github.com/squaremo/amqp.node -// Definitions by: Michael Nahkies , Ab Reitsma +// Definitions by: Michael Nahkies , Ab Reitsma , Nicolás Fantone // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -/// /// -declare module "amqplib/properties" { - namespace Replies { +declare module 'amqplib' { + import * as Promise from 'bluebird'; + import * as events from 'events'; + import shared = require('amqplib/properties'); + + export import Replies = shared.Replies; + export import Options = shared.Options; + export import Message = shared.Message; + + export interface Connection extends events.EventEmitter { + close(): Promise; + createChannel(): Promise; + createConfirmChannel(): Promise; + } + + export interface Channel extends events.EventEmitter { + close(): Promise; + + assertQueue(queue: string, options?: Options.AssertQueue): Promise; + checkQueue(queue: string): Promise; + + deleteQueue(queue: string, options?: Options.DeleteQueue): Promise; + purgeQueue(queue: string): Promise; + + bindQueue(queue: string, source: string, pattern: string, args?: any): Promise; + unbindQueue(queue: string, source: string, pattern: string, args?: any): Promise; + + assertExchange(exchange: string, type: string, options?: Options.AssertExchange): Promise; + checkExchange(exchange: string): Promise; + + deleteExchange(exchange: string, options?: Options.DeleteExchange): Promise; + + bindExchange(destination: string, source: string, pattern: string, args?: any): Promise; + unbindExchange(destination: string, source: string, pattern: string, args?: any): Promise; + + publish(exchange: string, routingKey: string, content: Buffer, options?: Options.Publish): boolean; + sendToQueue(queue: string, content: Buffer, options?: Options.Publish): boolean; + + consume(queue: string, onMessage: (msg: Message) => any, options?: Options.Consume): Promise; + + cancel(consumerTag: string): Promise; + get(queue: string, options?: Options.Get): Promise; + + ack(message: Message, allUpTo?: boolean): void; + ackAll(): void; + + nack(message: Message, allUpTo?: boolean, requeue?: boolean): void; + nackAll(requeue?: boolean): void; + reject(message: Message, requeue?: boolean): void; + + prefetch(count: number, global?: boolean): Promise; + recover(): Promise; + } + + export interface ConfirmChannel extends Channel { + publish(exchange:string, routingKey:string, content:Buffer, options?:Options.Publish, callback?:(err:any, ok:Replies.Empty) => void):boolean; + sendToQueue(queue:string, content:Buffer, options?:Options.Publish, callback?:(err:any, ok:Replies.Empty) => void):boolean; + + waitForConfirms(): Promise; + } + + export function connect(url: string, socketOptions?: any): Promise; +} + +declare module 'amqplib/properties' { + export namespace Replies { interface Empty { } interface AssertQueue { @@ -29,7 +92,7 @@ declare module "amqplib/properties" { } } - namespace Options { + export namespace Options { interface AssertQueue { exclusive?: boolean; durable?: boolean; @@ -40,6 +103,7 @@ declare module "amqplib/properties" { deadLetterExchange?: string; deadLetterRoutingKey?: string; maxLength?: number; + maxPriority?: number; } interface DeleteQueue { ifUnused?: boolean; @@ -56,7 +120,7 @@ declare module "amqplib/properties" { ifUnused?: boolean; } interface Publish { - expiration?: string; + expiration?: string | number; userId?: string; CC?: string | string[]; @@ -89,92 +153,35 @@ declare module "amqplib/properties" { } } - interface Message { + export interface Message { content: Buffer; fields: any; properties: any; } } -declare module "amqplib" { +declare module 'amqplib/callback_api' { + import events = require('events'); + import shared = require('amqplib/properties') - import events = require("events"); - import when = require("when"); - import shared = require("amqplib/properties") export import Replies = shared.Replies; export import Options = shared.Options; export import Message = shared.Message; - interface Connection extends events.EventEmitter { - close(): when.Promise; - createChannel(): when.Promise; - createConfirmChannel(): when.Promise; - } - - interface Channel extends events.EventEmitter { - close(): when.Promise; - - assertQueue(queue: string, options?: Options.AssertQueue): when.Promise; - checkQueue(queue: string): when.Promise; - - deleteQueue(queue: string, options?: Options.DeleteQueue): when.Promise; - purgeQueue(queue: string): when.Promise; - - bindQueue(queue: string, source: string, pattern: string, args?: any): when.Promise; - unbindQueue(queue: string, source: string, pattern: string, args?: any): when.Promise; - - assertExchange(exchange: string, type: string, options?: Options.AssertExchange): when.Promise; - checkExchange(exchange: string): when.Promise; - - deleteExchange(exchange: string, options?: Options.DeleteExchange): when.Promise; - - bindExchange(destination: string, source: string, pattern: string, args?: any): when.Promise; - unbindExchange(destination: string, source: string, pattern: string, args?: any): when.Promise; - - publish(exchange: string, routingKey: string, content: Buffer, options?: Options.Publish): boolean; - sendToQueue(queue: string, content: Buffer, options?: Options.Publish): boolean; - - consume(queue: string, onMessage: (msg: Message) => any, options?: Options.Consume): when.Promise; - - cancel(consumerTag: string): when.Promise; - get(queue: string, options?: Options.Get): when.Promise; - - ack(message: Message, allUpTo?: boolean): void; - ackAll(): void; - - nack(message: Message, allUpTo?: boolean, requeue?: boolean): void; - nackAll(requeue?: boolean): void; - reject(message: Message, requeue?: boolean): void; - - prefetch(count: number, global?: boolean): when.Promise; - recover(): when.Promise; - } - - function connect(url: string, socketOptions?: any): when.Promise; -} - -declare module "amqplib/callback_api" { - - import events = require("events"); - import shared = require("amqplib/properties") - export import Replies = shared.Replies; - export import Options = shared.Options; - export import Message = shared.Message; - - interface Connection extends events.EventEmitter { + export interface Connection extends events.EventEmitter { close(callback?: (err: any) => void): void; createChannel(callback: (err: any, channel: Channel) => void): void; createConfirmChannel(callback: (err: any, confirmChannel: ConfirmChannel) => void): void; } - interface Channel extends events.EventEmitter { + export interface Channel extends events.EventEmitter { close(callback: (err: any) => void): void; - assertQueue(queue?: string, options?: Options.AssertQueue, callback?: (err:any, ok: Replies.AssertQueue) => void): void; + assertQueue(queue?: string, options?: Options.AssertQueue, callback?: (err: any, ok: Replies.AssertQueue) => void): void; checkQueue(queue: string, callback?: (err: any, ok: Replies.AssertQueue) => void): void; - deleteQueue(queue: string, options?: Options.DeleteQueue, callback?: (err:any, ok: Replies.DeleteQueue) => void): void; - purgeQueue(queue: string, callback?: (err:any, ok: Replies.PurgeQueue) => void): void; + deleteQueue(queue: string, options?: Options.DeleteQueue, callback?: (err: any, ok: Replies.DeleteQueue) => void): void; + purgeQueue(queue: string, callback?: (err: any, ok: Replies.PurgeQueue) => void): void; bindQueue(queue: string, source: string, pattern: string, args?: any, callback?: (err: any, ok: Replies.Empty) => void): void; unbindQueue(queue: string, source: string, pattern: string, args?: any, callback?: (err: any, ok: Replies.Empty) => void): void; @@ -206,14 +213,14 @@ declare module "amqplib/callback_api" { recover(callback?: (err: any, ok: Replies.Empty) => void): void; } - interface ConfirmChannel extends Channel { + export interface ConfirmChannel extends Channel { publish(exchange: string, routingKey: string, content: Buffer, options?: Options.Publish, callback?: (err: any, ok: Replies.Empty) => void): boolean; sendToQueue(queue: string, content: Buffer, options?: Options.Publish, callback?: (err: any, ok: Replies.Empty) => void): boolean; waitForConfirms(callback?: (err: any) => void): void; } - function connect(callback: (err: any, connection: Connection) => void): void; - function connect(url: string, callback: (err: any, connection: Connection) => void): void; - function connect(url: string, socketOptions: any, callback: (err: any, connection: Connection) => void): void; + export function connect(callback: (err: any, connection: Connection) => void): void; + export function connect(url: string, callback: (err: any, connection: Connection) => void): void; + export function connect(url: string, socketOptions: any, callback: (err: any, connection: Connection) => void): void; }