Merge pull request #31060 from RuLeZzz1987/master

added types for `rabbitmq-schema`
This commit is contained in:
Andrew Casey
2018-12-05 17:34:24 -08:00
committed by GitHub
4 changed files with 111 additions and 0 deletions
+71
View File
@@ -0,0 +1,71 @@
// Type definitions for rabbitmq-schema 2.0
// Project: https://github.com/tjmehta/rabbitmq-schema
// Definitions by: Alex Duka <https://github.com/rulezzz1987>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
interface Binding {
destination: Exchange | Queue;
source: Exchange;
args?: object;
routingPattern?: string;
}
interface TopicBinding extends Binding {
routingPattern: string;
}
interface DirectBinding extends Binding {
routingPattern: string;
}
interface Topology {
options?: object;
}
interface Exchange extends Topology {
exchange: string;
type: string;
bindings: Binding[];
}
interface FanoutExchange extends Exchange {
type: 'fanout';
}
interface TopicExchange extends Exchange {
type: 'topic';
bindings: TopicBinding[];
}
interface DirectExchange extends Exchange {
type: 'direct';
bindings: DirectBinding[];
}
interface Queue extends Topology {
queue: string;
messageSchema: object;
}
declare class RabbitMQSchema {
constructor(schema: Topology | Topology[], parentPath?: string);
getExchanges(): Exchange[];
getBindings(): Binding[];
getQueues(): Queue[];
getDirectBindings(): DirectBinding[];
validate(schema: Topology | Topology[], parentPath?: string): void;
validateMessage<T>(exchangeName: string, routingPattern: string, message: T): T;
getQueueByName(name: string): Queue | void;
getExchangeByName(name: string): Exchange | void;
}
export = RabbitMQSchema;
@@ -0,0 +1,16 @@
import RabbitMqSchema = require('rabbitmq-schema');
const topology = {};
const rabbitSchema = new RabbitMqSchema({}, '');
rabbitSchema.getExchanges();
rabbitSchema.getBindings();
rabbitSchema.getQueues();
rabbitSchema.getDirectBindings();
rabbitSchema.getQueueByName('images.jpeg.get');
rabbitSchema.getExchangeByName('images');
rabbitSchema.validate(topology);
rabbitSchema.validateMessage('images', 'images.jpeg.get', {testMsg: 'ok'});
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"strictFunctionTypes": true,
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"rabbitmq-schema-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }