diff --git a/types/rabbitmq-schema/index.d.ts b/types/rabbitmq-schema/index.d.ts new file mode 100644 index 0000000000..ccd76b68c5 --- /dev/null +++ b/types/rabbitmq-schema/index.d.ts @@ -0,0 +1,72 @@ +// Type definitions for rabbitmq-schema 2.0 +// Project: https://github.com/tjmehta/rabbitmq-schema +// Definitions by: Alex Duka +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare namespace rabbitMqSchemaNc { + interface Binding { + destination: Topology; + 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; + } + + interface RabbitMQSchema { + new (schema: Topology | Topology[], parentPath?: string): RabbitMQSchema; + + getExchanges(): Exchange[]; + getBindings(): Binding[]; + getQueues(): Queue[]; + getDirectBindings(): DirectBinding[]; + + validate(schema: Topology | Topology[], parentPath?: string): void; + validateMessage(exchangeName: string, routingPattern: string, message: T): T; + + getQueueByName(name: string): Queue | void; + getExchangeByName(name: string): Exchange | void; + } + +} + +declare module 'rabbitmq-schema' { + const schema: rabbitMqSchemaNc.RabbitMQSchema; + export = schema; +} \ No newline at end of file diff --git a/types/rabbitmq-schema/rabbitmq-schema-tests.ts b/types/rabbitmq-schema/rabbitmq-schema-tests.ts new file mode 100644 index 0000000000..50b36b2e21 --- /dev/null +++ b/types/rabbitmq-schema/rabbitmq-schema-tests.ts @@ -0,0 +1,37 @@ +import RabbitMqSchema = require('rabbitmq-schema'); + +const topology: rabbitMqSchemaNc.Topology = { + exchange: 'images', + type: 'topic', + vhost: '/', + bindings: [ + { + routingPattern: 'images.jpeg.get', + destination: { + queue: 'images.image.get', + messageSchema: { + type: 'object', + properties: { + testMsg: { + type: "string" + } + } + }, + args: { 'message-ttl': 10000 } + } + } + ] +} + +const rabbitSchema = new RabbitMqSchema(topology, ''); + +const exchanges: rabbitMqSchemaNc.Exchange[] = rabbitSchema.getExchanges(); +const bindings: rabbitMqSchemaNc.Binding[] = rabbitSchema.getBindings(); +const queues: rabbitMqSchemaNc.Queue[] = rabbitSchema.getQueues(); +const directBindings: rabbitMqSchemaNc.DirectBinding[] = rabbitSchema.getDirectBindings(); + +const jpgQueue: rabbitMqSchemaNc.Queue = rabbitSchema.getQueueByName('images.jpeg.get'); +const exchange: rabbitMqSchemaNc.Exchange = rabbitSchema.getExchangeByName('images'); + +rabbitSchema.validate(topology); +rabbitSchema.validateMessage('images', 'images.jpeg.get', {testMsg: 'ok'}); \ No newline at end of file diff --git a/types/rabbitmq-schema/tsconfig.json b/types/rabbitmq-schema/tsconfig.json new file mode 100644 index 0000000000..96c7293272 --- /dev/null +++ b/types/rabbitmq-schema/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "rabbitmq-schema-tests.ts" + ] +} diff --git a/types/rabbitmq-schema/tslint.json b/types/rabbitmq-schema/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/rabbitmq-schema/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }