From b5088e9b92f809bbdef5e51deed7847bb836178c Mon Sep 17 00:00:00 2001 From: Alex Duka Date: Tue, 4 Dec 2018 21:36:47 +0200 Subject: [PATCH 1/7] added types to `rabbitmq-schema` --- types/rabbitmq-schema/index.d.ts | 72 +++++++++++++++++++ .../rabbitmq-schema/rabbitmq-schema-tests.ts | 37 ++++++++++ types/rabbitmq-schema/tsconfig.json | 22 ++++++ types/rabbitmq-schema/tslint.json | 1 + 4 files changed, 132 insertions(+) create mode 100644 types/rabbitmq-schema/index.d.ts create mode 100644 types/rabbitmq-schema/rabbitmq-schema-tests.ts create mode 100644 types/rabbitmq-schema/tsconfig.json create mode 100644 types/rabbitmq-schema/tslint.json 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" } From ce4d4743b791628819b26327c19169bb9f25f687 Mon Sep 17 00:00:00 2001 From: Alex Duka Date: Wed, 5 Dec 2018 00:50:04 +0200 Subject: [PATCH 2/7] improved tests and typings --- types/rabbitmq-schema/index.d.ts | 96 +++++++++---------- .../rabbitmq-schema/rabbitmq-schema-tests.ts | 29 ++---- 2 files changed, 54 insertions(+), 71 deletions(-) diff --git a/types/rabbitmq-schema/index.d.ts b/types/rabbitmq-schema/index.d.ts index ccd76b68c5..a577d9c36a 100644 --- a/types/rabbitmq-schema/index.d.ts +++ b/types/rabbitmq-schema/index.d.ts @@ -4,69 +4,69 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare namespace rabbitMqSchemaNc { - interface Binding { - destination: Topology; - source: Exchange; - args?: object; - routingPattern?: string; - } + interface Binding { + destination: Topology; + source: Exchange; + args?: object; + routingPattern?: string; + } - interface TopicBinding extends Binding { - routingPattern: string; - } + interface TopicBinding extends Binding { + routingPattern: string; + } - interface DirectBinding extends Binding { - routingPattern: string; - } + interface DirectBinding extends Binding { + routingPattern: string; + } - interface Topology { - options?: object; - } + interface Topology { + options?: object; + } - interface Exchange extends Topology { - exchange: string; - type: string; - bindings: Binding[]; - } + interface Exchange extends Topology { + exchange: string; + type: string; + bindings: Binding[]; + } - interface FanoutExchange extends Exchange { - type: 'fanout'; - } + interface FanoutExchange extends Exchange { + type: 'fanout'; + } - interface TopicExchange extends Exchange { - type: 'topic'; - bindings: TopicBinding[]; - } + interface TopicExchange extends Exchange { + type: 'topic'; + bindings: TopicBinding[]; + } - interface DirectExchange extends Exchange { - type: 'direct'; - bindings: DirectBinding[]; - } + interface DirectExchange extends Exchange { + type: 'direct'; + bindings: DirectBinding[]; + } - interface Queue extends Topology { - queue: string; - messageSchema: object; - } + interface Queue extends Topology { + queue: string; + messageSchema: object; + } - interface RabbitMQSchema { - new (schema: Topology | Topology[], parentPath?: string): RabbitMQSchema; + interface RabbitMQSchema { + new (schema: Topology | Topology[], parentPath?: string): RabbitMQSchema; - getExchanges(): Exchange[]; - getBindings(): Binding[]; - getQueues(): Queue[]; - getDirectBindings(): DirectBinding[]; + getExchanges(): Exchange[]; + getBindings(): Binding[]; + getQueues(): Queue[]; + getDirectBindings(): DirectBinding[]; - validate(schema: Topology | Topology[], parentPath?: string): void; - validateMessage(exchangeName: string, routingPattern: string, message: T): T; + 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; - } + getQueueByName(name: string): Queue | void; + getExchangeByName(name: string): Exchange | void; + } } declare module 'rabbitmq-schema' { - const schema: rabbitMqSchemaNc.RabbitMQSchema; - export = 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 index 50b36b2e21..e02dc29bae 100644 --- a/types/rabbitmq-schema/rabbitmq-schema-tests.ts +++ b/types/rabbitmq-schema/rabbitmq-schema-tests.ts @@ -1,27 +1,10 @@ import RabbitMqSchema = require('rabbitmq-schema'); -const topology: rabbitMqSchemaNc.Topology = { +const topology: rabbitMqSchemaNc.Exchange = { 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 } - } - } - ] -} + bindings: [] +}; const rabbitSchema = new RabbitMqSchema(topology, ''); @@ -30,8 +13,8 @@ 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'); +const jpgQueue: rabbitMqSchemaNc.Queue | unknown = rabbitSchema.getQueueByName('images.jpeg.get'); +const exchange: rabbitMqSchemaNc.Exchange | unknown = rabbitSchema.getExchangeByName('images'); rabbitSchema.validate(topology); -rabbitSchema.validateMessage('images', 'images.jpeg.get', {testMsg: 'ok'}); \ No newline at end of file +rabbitSchema.validateMessage('images', 'images.jpeg.get', {testMsg: 'ok'}); From c85e8d550f1679ea945d820313f05a9cc1d8ce0f Mon Sep 17 00:00:00 2001 From: Alex Duka Date: Wed, 5 Dec 2018 00:56:07 +0200 Subject: [PATCH 3/7] added strictFunctionTypes option to tsconfig --- types/rabbitmq-schema/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/types/rabbitmq-schema/tsconfig.json b/types/rabbitmq-schema/tsconfig.json index 96c7293272..81e519bb47 100644 --- a/types/rabbitmq-schema/tsconfig.json +++ b/types/rabbitmq-schema/tsconfig.json @@ -4,6 +4,7 @@ "lib": [ "es6" ], + "strictFunctionTypes": true, "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, From 14300e779916b1f19be8334f4a5c135de76d464b Mon Sep 17 00:00:00 2001 From: Alex Duka Date: Wed, 5 Dec 2018 01:45:49 +0200 Subject: [PATCH 4/7] fix tslint issues, updated tests --- types/rabbitmq-schema/index.d.ts | 128 +++++++++--------- .../rabbitmq-schema/rabbitmq-schema-tests.ts | 20 ++- 2 files changed, 72 insertions(+), 76 deletions(-) diff --git a/types/rabbitmq-schema/index.d.ts b/types/rabbitmq-schema/index.d.ts index a577d9c36a..29c12b3c99 100644 --- a/types/rabbitmq-schema/index.d.ts +++ b/types/rabbitmq-schema/index.d.ts @@ -3,70 +3,70 @@ // 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; - } +interface Binding { + destination: Topology; + source: Exchange; + args?: object; + routingPattern?: string; } -declare module 'rabbitmq-schema' { - const schema: rabbitMqSchemaNc.RabbitMQSchema; - export = schema; -} \ No newline at end of file +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(exchangeName: string, routingPattern: string, message: T): T; + + getQueueByName(name: string): Queue | void; + + getExchangeByName(name: string): Exchange | void; +} + +export = RabbitMQSchema; \ No newline at end of file diff --git a/types/rabbitmq-schema/rabbitmq-schema-tests.ts b/types/rabbitmq-schema/rabbitmq-schema-tests.ts index e02dc29bae..067c9c3c5a 100644 --- a/types/rabbitmq-schema/rabbitmq-schema-tests.ts +++ b/types/rabbitmq-schema/rabbitmq-schema-tests.ts @@ -1,20 +1,16 @@ import RabbitMqSchema = require('rabbitmq-schema'); -const topology: rabbitMqSchemaNc.Exchange = { - exchange: 'images', - type: 'topic', - bindings: [] -}; +const topology = {}; -const rabbitSchema = new RabbitMqSchema(topology, ''); +const rabbitSchema = new RabbitMqSchema({}, ''); -const exchanges: rabbitMqSchemaNc.Exchange[] = rabbitSchema.getExchanges(); -const bindings: rabbitMqSchemaNc.Binding[] = rabbitSchema.getBindings(); -const queues: rabbitMqSchemaNc.Queue[] = rabbitSchema.getQueues(); -const directBindings: rabbitMqSchemaNc.DirectBinding[] = rabbitSchema.getDirectBindings(); +rabbitSchema.getExchanges(); +rabbitSchema.getBindings(); +rabbitSchema.getQueues(); +rabbitSchema.getDirectBindings(); -const jpgQueue: rabbitMqSchemaNc.Queue | unknown = rabbitSchema.getQueueByName('images.jpeg.get'); -const exchange: rabbitMqSchemaNc.Exchange | unknown = rabbitSchema.getExchangeByName('images'); +rabbitSchema.getQueueByName('images.jpeg.get'); +rabbitSchema.getExchangeByName('images'); rabbitSchema.validate(topology); rabbitSchema.validateMessage('images', 'images.jpeg.get', {testMsg: 'ok'}); From 539736fa10140c46156aa34e4918a4648ca3c72c Mon Sep 17 00:00:00 2001 From: Alex Duka Date: Wed, 5 Dec 2018 01:52:42 +0200 Subject: [PATCH 5/7] fixed linting issues, ts version > 2.2 --- types/rabbitmq-schema/index.d.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/types/rabbitmq-schema/index.d.ts b/types/rabbitmq-schema/index.d.ts index 29c12b3c99..e2814066ee 100644 --- a/types/rabbitmq-schema/index.d.ts +++ b/types/rabbitmq-schema/index.d.ts @@ -1,9 +1,9 @@ +// TypeScript Version: 2.2' just under the header. // Type definitions for rabbitmq-schema 2.0 // Project: https://github.com/tjmehta/rabbitmq-schema // Definitions by: Alex Duka // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - interface Binding { destination: Topology; source: Exchange; @@ -19,7 +19,6 @@ interface DirectBinding extends Binding { routingPattern: string; } - interface Topology { options?: object; } @@ -69,4 +68,4 @@ declare class RabbitMQSchema { getExchangeByName(name: string): Exchange | void; } -export = RabbitMQSchema; \ No newline at end of file +export = RabbitMQSchema; From 83debe8fbdfb225dfbfc0dd3ebe4dffdd3e7a673 Mon Sep 17 00:00:00 2001 From: Alex Duka Date: Wed, 5 Dec 2018 01:57:10 +0200 Subject: [PATCH 6/7] ts version > 2.2 --- types/rabbitmq-schema/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/rabbitmq-schema/index.d.ts b/types/rabbitmq-schema/index.d.ts index e2814066ee..49d20ea14b 100644 --- a/types/rabbitmq-schema/index.d.ts +++ b/types/rabbitmq-schema/index.d.ts @@ -1,8 +1,8 @@ -// TypeScript Version: 2.2' just under the header. // Type definitions for rabbitmq-schema 2.0 // Project: https://github.com/tjmehta/rabbitmq-schema // Definitions by: Alex Duka // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 interface Binding { destination: Topology; From 17211a0628a38a868f68ebc0cb624deed4648734 Mon Sep 17 00:00:00 2001 From: Alex Duka Date: Wed, 5 Dec 2018 21:38:50 +0200 Subject: [PATCH 7/7] improved Binding field types --- types/rabbitmq-schema/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/rabbitmq-schema/index.d.ts b/types/rabbitmq-schema/index.d.ts index 49d20ea14b..3c607115ab 100644 --- a/types/rabbitmq-schema/index.d.ts +++ b/types/rabbitmq-schema/index.d.ts @@ -5,7 +5,7 @@ // TypeScript Version: 2.2 interface Binding { - destination: Topology; + destination: Exchange | Queue; source: Exchange; args?: object; routingPattern?: string;