diff --git a/amqplib/callback_api.d.ts b/amqplib/callback_api.d.ts new file mode 100644 index 0000000000..5d025bf314 --- /dev/null +++ b/amqplib/callback_api.d.ts @@ -0,0 +1,59 @@ +import events = require('events'); +import { Replies, Options, Message } from './properties'; +export * from './properties'; + +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; +} + +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; + 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; +} + +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; +} + +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; diff --git a/amqplib/index.d.ts b/amqplib/index.d.ts index b406e00ac0..6cd326cd67 100644 --- a/amqplib/index.d.ts +++ b/amqplib/index.d.ts @@ -1,226 +1,65 @@ -// Type definitions for amqplib 0.5.x +// Type definitions for amqplib 0.5 // Project: https://github.com/squaremo/amqp.node // Definitions by: Michael Nahkies , Ab Reitsma , Nicolás Fantone // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// -declare module 'amqplib' { - import * as Promise from 'bluebird'; - import * as events from 'events'; - import shared = require('amqplib/properties'); +import * as Promise from 'bluebird'; +import * as events from 'events'; +import { Replies, Options, Message } from './properties'; +export * from './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; +export interface Connection extends events.EventEmitter { + close(): Promise; + createChannel(): Promise; + createConfirmChannel(): Promise; } -declare module 'amqplib/properties' { - export 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; - } - } +export interface Channel extends events.EventEmitter { + close(): Promise; - export namespace Options { - interface AssertQueue { - exclusive?: boolean; - durable?: boolean; - autoDelete?: boolean; - arguments?: any; - messageTtl?: number; - expires?: number; - deadLetterExchange?: string; - deadLetterRoutingKey?: string; - maxLength?: number; - maxPriority?: 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 | number; - userId?: string; - CC?: string | string[]; + assertQueue(queue: string, options?: Options.AssertQueue): Promise; + checkQueue(queue: string): Promise; - mandatory?: boolean; - persistent?: boolean; - deliveryMode?: boolean | number; - BCC?: string | string[]; + deleteQueue(queue: string, options?: Options.DeleteQueue): Promise; + purgeQueue(queue: string): Promise; - 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; - } - } + bindQueue(queue: string, source: string, pattern: string, args?: any): Promise; + unbindQueue(queue: string, source: string, pattern: string, args?: any): Promise; - export interface Message { - content: Buffer; - fields: any; - properties: any; - } + 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; } -declare module 'amqplib/callback_api' { - import events = require('events'); - import shared = require('amqplib/properties') +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; - export import Replies = shared.Replies; - export import Options = shared.Options; - export import Message = shared.Message; - - 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; - } - - 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; - 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; - } - - 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; - } - - 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; + waitForConfirms(): Promise; } + +export function connect(url: string, socketOptions?: any): Promise; diff --git a/amqplib/properties.d.ts b/amqplib/properties.d.ts new file mode 100644 index 0000000000..12514d7810 --- /dev/null +++ b/amqplib/properties.d.ts @@ -0,0 +1,88 @@ +export 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; + } +} + +export namespace Options { + interface AssertQueue { + exclusive?: boolean; + durable?: boolean; + autoDelete?: boolean; + arguments?: any; + messageTtl?: number; + expires?: number; + deadLetterExchange?: string; + deadLetterRoutingKey?: string; + maxLength?: number; + maxPriority?: 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 | number; + 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; + } +} + +export interface Message { + content: Buffer; + fields: any; + properties: any; +} \ No newline at end of file diff --git a/amqplib/tsconfig.json b/amqplib/tsconfig.json index e7bc5a878a..4c3f1a8477 100644 --- a/amqplib/tsconfig.json +++ b/amqplib/tsconfig.json @@ -15,6 +15,7 @@ }, "files": [ "index.d.ts", + "callback_api.d.ts", "amqplib-tests.ts" ] } \ No newline at end of file diff --git a/amqplib/tslint.json b/amqplib/tslint.json new file mode 100644 index 0000000000..9bc375c06b --- /dev/null +++ b/amqplib/tslint.json @@ -0,0 +1,6 @@ +{ + "extends": "../tslint.json", + "rules": { + "no-empty-interface": false + } +} \ No newline at end of file