mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Add definitions for rabbit.js
This commit is contained in:
parent
3bdf7dd603
commit
527d6686f5
33
rabbit.js/rabbit.js-tests.ts
Normal file
33
rabbit.js/rabbit.js-tests.ts
Normal file
@ -0,0 +1,33 @@
|
||||
/// <reference path="./rabbit.js.d.ts" />
|
||||
|
||||
import rabbit = require('rabbit.js');
|
||||
var context = rabbit.createContext();
|
||||
|
||||
context.on('ready', function () { console.log('ready'); });
|
||||
|
||||
var pub = context.socket<rabbit.PubSocket>('PUB');
|
||||
var sub = context.socket<rabbit.SubSocket>('SUB');
|
||||
var push = context.socket<rabbit.PushSocket>('PUSH');
|
||||
var pull = context.socket<rabbit.PullSocket>('PULL');
|
||||
var req = context.socket<rabbit.ReqSocket>('REQ');
|
||||
var rep = context.socket<rabbit.RepSocket>('REP');
|
||||
var task = context.socket<rabbit.TaskSocket>('TASK');
|
||||
var worker = context.socket<rabbit.WorkerSocket>('WORKER');
|
||||
|
||||
pub.connect('chat');
|
||||
pub.write('hello', 'utf8');
|
||||
pub.close();
|
||||
|
||||
sub.connect('chat');
|
||||
sub.on('data', function (msg: string) { console.log(msg); });
|
||||
sub.close();
|
||||
|
||||
rep.setEncoding('utf8');
|
||||
rep.on('data', function (msg: string) { rep.write('msg', 'utf8'); });
|
||||
rep.connect('uppercase');
|
||||
req.connect('uppercase', function () { req.pipe(process.stdout); });
|
||||
|
||||
push.connect('items', function () { pull.pipe(push); });
|
||||
push.close();
|
||||
pull.connect('items', function () {});
|
||||
pull.close();
|
||||
108
rabbit.js/rabbit.js.d.ts
vendored
Normal file
108
rabbit.js/rabbit.js.d.ts
vendored
Normal file
@ -0,0 +1,108 @@
|
||||
// Type definitions for rabbit.js v0.4.2
|
||||
// Project: https://github.com/squaremo/rabbit.js
|
||||
// Definitions by: Wonshik Kim <https://github.com/wokim>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../node/node.d.ts" />
|
||||
|
||||
declare module "rabbit.js" {
|
||||
import events = require('events');
|
||||
import stream = require('stream');
|
||||
|
||||
export function createContext(url?: string): Context;
|
||||
|
||||
export class Context extends events.EventEmitter {
|
||||
public socket<T>(type: string, options?: SocketOptions):T;
|
||||
public close(callback: Function): any;
|
||||
}
|
||||
|
||||
export interface SocketOptions {
|
||||
prefetch?: any;
|
||||
expiration?: any;
|
||||
persistent?: any;
|
||||
topic?: any;
|
||||
task?: any;
|
||||
}
|
||||
|
||||
export interface Socket {
|
||||
connect(destination: string, callback?: Function): any;
|
||||
setsockopt(opt: string, value: string): any;
|
||||
close(): any;
|
||||
}
|
||||
|
||||
export class PubSocket extends stream.Writable implements Socket {
|
||||
constructor(channel: string, opts: SocketOptions);
|
||||
connect(destination: string, callback?: Function): any;
|
||||
setsockopt(opt: string, value: string): any;
|
||||
close(): any;
|
||||
|
||||
publish(topic: string, chunk: string, encoding?: string): any;
|
||||
publish(topic: string, chunk: Buffer, encoding?: string): any;
|
||||
}
|
||||
|
||||
export class SubSocket extends stream.Readable implements Socket {
|
||||
constructor(channel: string, opts: SocketOptions);
|
||||
connect(source: string, callback?: Function): any;
|
||||
setsockopt(opt: string, value: string): any;
|
||||
close(): any;
|
||||
}
|
||||
|
||||
export class PushSocket extends stream.Writable implements Socket {
|
||||
constructor(channel: string, opts: SocketOptions);
|
||||
connect(destination: string, callback?: Function): any;
|
||||
setsockopt(opt: string, value: string): any;
|
||||
close(): any;
|
||||
}
|
||||
|
||||
export class PullSocket extends stream.Readable implements Socket {
|
||||
constructor(channel: string, opts: SocketOptions);
|
||||
connect(source: string, callback?: Function): any;
|
||||
setsockopt(opt: string, value: string): any;
|
||||
close(): any;
|
||||
}
|
||||
|
||||
export class WorkerSocket extends stream.Readable implements Socket {
|
||||
constructor(channel: string, opts: SocketOptions);
|
||||
connect(source: string, callback?: Function): any;
|
||||
setsockopt(opt: string, value: string): any;
|
||||
close(): any;
|
||||
|
||||
ack(): any;
|
||||
requeue(): any;
|
||||
discard(): any;
|
||||
}
|
||||
|
||||
export interface RequestMessage {
|
||||
properties: { correlationId: number };
|
||||
content: any;
|
||||
}
|
||||
|
||||
export class ReqSocket extends stream.Duplex implements Socket {
|
||||
constructor(channel: string, opts: SocketOptions);
|
||||
connect(destination: string, callback?: Function): any;
|
||||
setsockopt(opt: string, value: string): any;
|
||||
close(): any;
|
||||
|
||||
handleReply(msg: RequestMessage): any;
|
||||
}
|
||||
|
||||
export class RepSocket extends stream.Duplex implements Socket {
|
||||
constructor(channel: string, opts: SocketOptions);
|
||||
connect(source: string, callback?: Function): any;
|
||||
setsockopt(opt: string, value: string): any;
|
||||
close(): any;
|
||||
|
||||
requeue(): any;
|
||||
discard(): any;
|
||||
}
|
||||
|
||||
export class TaskSocket extends stream.Writable implements Socket {
|
||||
constructor(channel: string, opts: SocketOptions);
|
||||
connect(destination: string, callback?: Function): any;
|
||||
setsockopt(opt: string, value: string): any;
|
||||
close(): any;
|
||||
|
||||
post(task: string, chunk: string, encoding?: string): any;
|
||||
post(task: string, chunk: Buffer, encoding?: string): any;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user