Update amqplib definitions to v0.5.0 (#12427)

* Update amqplib definitions to v0.5.0

* Remove unused import

* Restore previous 0.3.x amqplib definitions
This commit is contained in:
Nicolás Fantone 2016-11-07 16:45:08 +00:00 committed by Masahiro Wakame
parent ad11ed23f2
commit ba5d738c52
3 changed files with 323 additions and 99 deletions

219
amqplib/amqplib-0.3.d.ts vendored Normal file
View File

@ -0,0 +1,219 @@
// Type definitions for amqplib 0.3.x
// Project: https://github.com/squaremo/amqp.node
// Definitions by: Michael Nahkies <https://github.com/mnahkies>, Ab Reitsma <https://github.com/abreits>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="when" />
/// <reference types="node" />
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<void>;
createChannel(): when.Promise<Channel>;
createConfirmChannel(): when.Promise<Channel>;
}
interface Channel extends events.EventEmitter {
close(): when.Promise<void>;
assertQueue(queue: string, options?: Options.AssertQueue): when.Promise<Replies.AssertQueue>;
checkQueue(queue: string): when.Promise<Replies.AssertQueue>;
deleteQueue(queue: string, options?: Options.DeleteQueue): when.Promise<Replies.DeleteQueue>;
purgeQueue(queue: string): when.Promise<Replies.PurgeQueue>;
bindQueue(queue: string, source: string, pattern: string, args?: any): when.Promise<Replies.Empty>;
unbindQueue(queue: string, source: string, pattern: string, args?: any): when.Promise<Replies.Empty>;
assertExchange(exchange: string, type: string, options?: Options.AssertExchange): when.Promise<Replies.AssertExchange>;
checkExchange(exchange: string): when.Promise<Replies.Empty>;
deleteExchange(exchange: string, options?: Options.DeleteExchange): when.Promise<Replies.Empty>;
bindExchange(destination: string, source: string, pattern: string, args?: any): when.Promise<Replies.Empty>;
unbindExchange(destination: string, source: string, pattern: string, args?: any): when.Promise<Replies.Empty>;
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<Replies.Consume>;
cancel(consumerTag: string): when.Promise<Replies.Empty>;
get(queue: string, options?: Options.Get): when.Promise<Message | boolean>;
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<Replies.Empty>;
recover(): when.Promise<Replies.Empty>;
}
function connect(url: string, socketOptions?: any): when.Promise<Connection>;
}
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;
}

View File

@ -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;
var anqpcbAssertExchangeReplies: amqpcb.Replies.AssertExchange;

161
amqplib/index.d.ts vendored
View File

@ -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 <https://github.com/mnahkies>, Ab Reitsma <https://github.com/abreits>
// Definitions by: Michael Nahkies <https://github.com/mnahkies>, Ab Reitsma <https://github.com/abreits>, Nicolás Fantone <https://github.com/nfantone>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="when" />
/// <reference types="node" />
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<void>;
createChannel(): Promise<Channel>;
createConfirmChannel(): Promise<ConfirmChannel>;
}
export interface Channel extends events.EventEmitter {
close(): Promise<void>;
assertQueue(queue: string, options?: Options.AssertQueue): Promise<Replies.AssertQueue>;
checkQueue(queue: string): Promise<Replies.AssertQueue>;
deleteQueue(queue: string, options?: Options.DeleteQueue): Promise<Replies.DeleteQueue>;
purgeQueue(queue: string): Promise<Replies.PurgeQueue>;
bindQueue(queue: string, source: string, pattern: string, args?: any): Promise<Replies.Empty>;
unbindQueue(queue: string, source: string, pattern: string, args?: any): Promise<Replies.Empty>;
assertExchange(exchange: string, type: string, options?: Options.AssertExchange): Promise<Replies.AssertExchange>;
checkExchange(exchange: string): Promise<Replies.Empty>;
deleteExchange(exchange: string, options?: Options.DeleteExchange): Promise<Replies.Empty>;
bindExchange(destination: string, source: string, pattern: string, args?: any): Promise<Replies.Empty>;
unbindExchange(destination: string, source: string, pattern: string, args?: any): Promise<Replies.Empty>;
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<Replies.Consume>;
cancel(consumerTag: string): Promise<Replies.Empty>;
get(queue: string, options?: Options.Get): Promise<Message | boolean>;
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<Replies.Empty>;
recover(): Promise<Replies.Empty>;
}
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<void>;
}
export function connect(url: string, socketOptions?: any): Promise<Connection>;
}
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<void>;
createChannel(): when.Promise<Channel>;
createConfirmChannel(): when.Promise<Channel>;
}
interface Channel extends events.EventEmitter {
close(): when.Promise<void>;
assertQueue(queue: string, options?: Options.AssertQueue): when.Promise<Replies.AssertQueue>;
checkQueue(queue: string): when.Promise<Replies.AssertQueue>;
deleteQueue(queue: string, options?: Options.DeleteQueue): when.Promise<Replies.DeleteQueue>;
purgeQueue(queue: string): when.Promise<Replies.PurgeQueue>;
bindQueue(queue: string, source: string, pattern: string, args?: any): when.Promise<Replies.Empty>;
unbindQueue(queue: string, source: string, pattern: string, args?: any): when.Promise<Replies.Empty>;
assertExchange(exchange: string, type: string, options?: Options.AssertExchange): when.Promise<Replies.AssertExchange>;
checkExchange(exchange: string): when.Promise<Replies.Empty>;
deleteExchange(exchange: string, options?: Options.DeleteExchange): when.Promise<Replies.Empty>;
bindExchange(destination: string, source: string, pattern: string, args?: any): when.Promise<Replies.Empty>;
unbindExchange(destination: string, source: string, pattern: string, args?: any): when.Promise<Replies.Empty>;
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<Replies.Consume>;
cancel(consumerTag: string): when.Promise<Replies.Empty>;
get(queue: string, options?: Options.Get): when.Promise<Message | boolean>;
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<Replies.Empty>;
recover(): when.Promise<Replies.Empty>;
}
function connect(url: string, socketOptions?: any): when.Promise<Connection>;
}
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;
}