Skip to content

Commit

Permalink
Update interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinegomez committed Aug 29, 2018
1 parent c66d7c4 commit 189d3c0
Show file tree
Hide file tree
Showing 21 changed files with 120 additions and 98 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@hapiness/rabbitmq",
"version": "1.5.0",
"version": "1.5.0-alpha2",
"description": "Hapiness module for rabbitmq",
"main": "commonjs/index.js",
"types": "index.d.ts",
Expand Down
60 changes: 0 additions & 60 deletions src/module/decorators.ts

This file was deleted.

18 changes: 18 additions & 0 deletions src/module/decorators/exchange.decorator.ts
@@ -0,0 +1,18 @@
import { createDecorator, CoreDecorator, Type } from '@hapiness/core';
import { Options } from 'amqplib';
import { ExchangeType, ChannelOptions } from '../interfaces';

export interface ExchangeDecoratorInterface {
name: string;
type: ExchangeType;
options?: Options.AssertExchange;
channel?: ChannelOptions;
providers?: Array<Type<any> | any>;
}
export const Exchange: CoreDecorator<ExchangeDecoratorInterface> = createDecorator<ExchangeDecoratorInterface>('Exchange', {
name: undefined,
type: undefined,
options: undefined,
channel: undefined,
providers: [],
});
3 changes: 3 additions & 0 deletions src/module/decorators/index.ts
@@ -0,0 +1,3 @@
export * from './exchange.decorator';
export * from './message.decorator';
export * from './queue.decorator';
21 changes: 21 additions & 0 deletions src/module/decorators/message.decorator.ts
@@ -0,0 +1,21 @@
import { Type } from '@hapiness/core';
import { createDecorator, CoreDecorator } from '@hapiness/core';

export interface MessageDecoratorInterface {
queue: Type<any>;
exchange?: Type<any>;
routingKey?: string | RegExp;
filter?: {
[key: string]: string | RegExp;
};
is_fallback?: boolean;
providers?: Array<Type<any> | any>;
}
export const Message: CoreDecorator<MessageDecoratorInterface> = createDecorator<MessageDecoratorInterface>('Message', {
queue: undefined,
exchange: undefined,
routingKey: undefined,
filter: undefined,
is_fallback: false,
providers: [],
});
21 changes: 21 additions & 0 deletions src/module/decorators/queue.decorator.ts
@@ -0,0 +1,21 @@
import { Type } from '@hapiness/core';
import { createDecorator, CoreDecorator } from '@hapiness/core';
import { Options } from 'amqplib';
import { Bind, ChannelOptions } from '../interfaces';

export interface QueueDecoratorInterface {
name: string;
binds?: Array<Bind>;
options?: Options.AssertQueue;
channel?: ChannelOptions;
force_json_decode?: boolean;
providers?: Array<Type<any> | any>;
}
export const Queue: CoreDecorator<QueueDecoratorInterface> = createDecorator<QueueDecoratorInterface>('Queue', {
name: undefined,
binds: undefined,
options: undefined,
channel: undefined,
force_json_decode: false,
providers: [],
});
2 changes: 1 addition & 1 deletion src/module/extension/get-channel.ts
@@ -1,7 +1,7 @@
import { ConnectionManager } from '../managers/connection-manager';
import { ChannelOptions } from '../decorators';
import { Observable } from 'rxjs/Observable';
import { ChannelManager } from '../managers/channel-manager';
import { ChannelOptions } from '../interfaces';

export function getChannel(connection: ConnectionManager, channel: ChannelOptions): Observable<ChannelManager> {
return connection
Expand Down
6 changes: 6 additions & 0 deletions src/module/extension/index.ts
@@ -0,0 +1,6 @@
export * from './build-exchange';
export * from './build-queues';
export * from './consume-queue';
export * from './get-channel';
export * from './register-annotations';
export * from './register-messages';
22 changes: 11 additions & 11 deletions src/module/index.ts
@@ -1,11 +1,11 @@
export * from './interfaces';
export * from './managers';
export * from './services';
export * from './decorators';
export * from './events';
export * from './message-router';
export * from './message';
export * from './rabbitmq.extension';
export * from './rabbitmq.module';
export * from './extension/register-annotations';
export * from './utils';
export * from './interfaces';
export * from './extension';
export * from './managers';
export * from './decorators';
export * from './events';
export * from './services';
export * from './message-router';
export * from './message';
export * from './rabbitmq.extension';
export * from './rabbitmq.module';
export * from './utils';
6 changes: 6 additions & 0 deletions src/module/interfaces/bind.ts
@@ -0,0 +1,6 @@
import { Type } from '@hapiness/core';

export interface Bind {
exchange: Type<any>;
pattern?: string | string[];
};
5 changes: 5 additions & 0 deletions src/module/interfaces/channel-options.ts
@@ -0,0 +1,5 @@
export interface ChannelOptions {
key: string;
prefetch?: number;
global?: boolean;
};
2 changes: 1 addition & 1 deletion src/module/interfaces/exchange-type.ts
Expand Up @@ -2,4 +2,4 @@ export enum ExchangeType {
Direct = 'direct',
Topic = 'topic',
Fanout = 'fanout'
}
};
27 changes: 15 additions & 12 deletions src/module/interfaces/index.ts
@@ -1,12 +1,15 @@
export * from './config';
export * from './consume-options';
export * from './create-channel.options';
export * from './exchange-type';
export * from './exchange';
export * from './message-options';
export * from './message-result';
export * from './message';
export * from './on-asserted';
export * from './queue-options';
export * from './queue';
export * from './rabbit-message';
export * from './bind';
export * from './channel-options';
export * from './config';
export * from './consume-options';
export * from './create-channel.options';
export * from './exchange-type';
export * from './exchange';
export * from './message-options';
export * from './message-result';
export * from './message-router';
export * from './message';
export * from './on-asserted';
export * from './queue-options';
export * from './queue';
export * from './rabbit-message';
2 changes: 1 addition & 1 deletion src/module/interfaces/queue-options.ts
@@ -1,5 +1,5 @@
import { Options } from 'amqplib';
import { Bind } from '../decorators';
import { Bind } from './bind';

export interface QueueOptions {
name: string;
Expand Down
3 changes: 1 addition & 2 deletions src/module/managers/queue-manager.ts
Expand Up @@ -3,8 +3,7 @@ import { Observable } from 'rxjs';
import { Channel as ChannelInterface, Replies } from 'amqplib';
import { extractMetadataByDecorator, errorHandler } from '@hapiness/core';
import { sendMessage, decodeJSONContent } from '../message';
import { MessageResult, MessageOptions, RabbitMessage, QueueOptions, ConsumeOptions, QueueInterface } from '../interfaces';
import { Bind } from '../decorators';
import { MessageResult, MessageOptions, RabbitMessage, QueueOptions, ConsumeOptions, QueueInterface, Bind } from '../interfaces';
import { ExchangeDecoratorInterface, ChannelManager } from '..';
import { QueueWrapper } from './queue-wrapper';
import { events } from '../events';
Expand Down
4 changes: 2 additions & 2 deletions src/module/managers/queue-wrapper.ts
@@ -1,6 +1,6 @@
import { QueueDecoratorInterface, Bind } from '../decorators';
import { QueueDecoratorInterface } from '../decorators';
import { Options } from 'amqplib';
import { QueueInterface } from '../interfaces';
import { QueueInterface, Bind } from '../interfaces';

export class QueueWrapper {
private _instance: QueueInterface;
Expand Down
6 changes: 3 additions & 3 deletions src/module/services/message.service.ts
@@ -1,4 +1,4 @@
import { Injectable, extractMetadataByDecorator } from '@hapiness/core';
import { Injectable, extractMetadataByDecorator, Type } from '@hapiness/core';
import { ChannelService } from './channel.service';
import { MessageOptions, QueueInterface, ExchangeInterface } from '../interfaces';
import { sendMessage } from '../message';
Expand All @@ -16,15 +16,15 @@ export class MessageService {
return this._channelService.connectionManager.isConnected();
}

sendToQueue(message, queue: typeof QueueInterface | string, options?: MessageOptions): boolean {
sendToQueue(message, queue: Type<QueueInterface> | string, options?: MessageOptions): boolean {
const ch = this._channelService.getChannel();
const _options: MessageOptions = Object.assign({}, options);
_options.queue = typeof queue === 'string' ? queue : extractMetadataByDecorator<QueueDecoratorInterface>(queue, 'Queue').name;

return this.send(message, _options, ch);
}

publish(message, exchange: typeof ExchangeInterface | string, options?: MessageOptions): boolean {
publish(message, exchange: Type<ExchangeInterface> | string, options?: MessageOptions): boolean {
const ch = this._channelService.getChannel();
const _options: MessageOptions = Object.assign({}, options);
_options.exchange = typeof exchange === 'string' ?
Expand Down
2 changes: 1 addition & 1 deletion tools/files.json
Expand Up @@ -2,4 +2,4 @@
{ "name":"README.md" },
{ "name":"LICENSE.md" },
{ "name":"package.json" }
]
]
2 changes: 1 addition & 1 deletion tools/packaging.ts
Expand Up @@ -98,7 +98,7 @@ class Packaging {
// function to write JSON
const writeJson = (dest: string, data: any): Observable<any> => {
return <Observable<any>> Observable.create((observer) => {
fs.outputJson(dest, data, (error) => {
fs.outputJson(dest, data, { spaces: 2 }, (error) => {
if (error) {
return observer.error(error);
}
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.build.json
Expand Up @@ -6,5 +6,5 @@
"declarationDir": "./dist",
"types": ["node"]
},
"exclude": ["node_modules", "dist", "test", "tools"]
"exclude": ["node_modules", "dist", "test", "tools", "sample"]
}

0 comments on commit 189d3c0

Please sign in to comment.