Skip to content

Commit

Permalink
fix: linter
Browse files Browse the repository at this point in the history
  • Loading branch information
DIY0R committed Jun 22, 2024
1 parent ee5ce3d commit bccb83b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 32 deletions.
12 changes: 2 additions & 10 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ module.exports = {
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
extends: ['plugin:@typescript-eslint/recommended', 'prettier'],
root: true,
env: {
node: true,
Expand All @@ -20,12 +17,7 @@ module.exports = {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
'prettier/prettier': [
'error',
{
endOfLine: 'auto',
},
],
};
4 changes: 3 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"singleQuote": true,
"trailingComma": "all"
"trailingComma": "all",
"endOfLine": "auto"

}
31 changes: 13 additions & 18 deletions lib/rmq.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ import {
OnModuleInit,
} from '@nestjs/common';

import {
IMessageBroker,
IPublishOptions,
ImqService,
TypeQueue,
} from './interfaces';
import { IMessageBroker, IPublishOptions, TypeQueue } from './interfaces';
import { IMetaTegsMap } from './interfaces/metategs';
import {
DEFAULT_TIMEOUT,
Expand Down Expand Up @@ -45,7 +40,7 @@ export class RmqService implements OnModuleInit, OnModuleDestroy {
private readonly rmqNestjsConnectService: RmqNestjsConnectService,
private readonly metaTegsScannerService: MetaTegsScannerService,
@Inject(RMQ_BROKER_OPTIONS) private options: IMessageBroker,
@Inject(RMQ_APP_OPTIONS) private appOptions: IAppOptions
@Inject(RMQ_APP_OPTIONS) private appOptions: IAppOptions,
) {
this.logger = appOptions.logger
? appOptions.logger
Expand All @@ -62,7 +57,7 @@ export class RmqService implements OnModuleInit, OnModuleDestroy {
public async notify<IMessage>(
topic: string,
message: IMessage,
options?: IPublishOptions
options?: IPublishOptions,
) {
await this.initializationCheck();
this.rmqNestjsConnectService.publish({
Expand All @@ -80,7 +75,7 @@ export class RmqService implements OnModuleInit, OnModuleDestroy {
public async send<IMessage, IReply>(
topic: string,
message: IMessage,
options?: IPublishOptions
options?: IPublishOptions,
): Promise<IReply> {
await this.initializationCheck();
if (!this.replyToQueue) return this.logger.error(INDICATE_ERROR);
Expand Down Expand Up @@ -115,7 +110,7 @@ export class RmqService implements OnModuleInit, OnModuleDestroy {
if (!message) return;
const consumeFunction = this.rmqMessageTegs.get(message.fields.routingKey);
const result = await consumeFunction(
JSON.parse(message.content.toString())
JSON.parse(message.content.toString()),
);
if (message.properties.replyTo) {
await this.rmqNestjsConnectService.sendToReplyQueue({
Expand All @@ -127,7 +122,7 @@ export class RmqService implements OnModuleInit, OnModuleDestroy {
this.rmqNestjsConnectService.ack(message);
}
private async listenReplyQueue(
message: ConsumeMessage | null
message: ConsumeMessage | null,
): Promise<void> {
if (message.properties.correlationId) {
this.sendResponseEmitter.emit(message.properties.correlationId, message);
Expand All @@ -136,7 +131,7 @@ export class RmqService implements OnModuleInit, OnModuleDestroy {

private async init() {
this.exchange = await this.rmqNestjsConnectService.assertExchange(
this.options.exchange
this.options.exchange,
);
if (this.options.replyTo) await this.assertReplyQueueBind();
await this.bindQueueExchange();
Expand All @@ -145,11 +140,11 @@ export class RmqService implements OnModuleInit, OnModuleDestroy {
if (!this.options.queue || !this.rmqMessageTegs?.size)
return this.logger.warn(
this.options.targetModuleName,
INOF_NOT_FULL_OPTIONS
INOF_NOT_FULL_OPTIONS,
);
const queue = await this.rmqNestjsConnectService.assertQueue(
TypeQueue.QUEUE,
this.options.queue
this.options.queue,
);
this.rmqMessageTegs.forEach(async (_, key) => {
await this.rmqNestjsConnectService.bindQueue({
Expand All @@ -160,24 +155,24 @@ export class RmqService implements OnModuleInit, OnModuleDestroy {
});
await this.rmqNestjsConnectService.listenQueue(
this.options.queue.queue,
this.listenQueue.bind(this)
this.listenQueue.bind(this),
);
}

private async assertReplyQueueBind() {
this.replyToQueue = await this.rmqNestjsConnectService.assertQueue(
TypeQueue.REPLY_QUEUE,
{ queue: '', options: this.options.replyTo }
{ queue: '', options: this.options.replyTo },
);
await this.rmqNestjsConnectService.listenReplyQueue(
this.replyToQueue.queue,
this.listenReplyQueue.bind(this)
this.listenReplyQueue.bind(this),
);
}
private async initializationCheck() {
if (this.isInitialized) return;
await new Promise<void>((resolve) =>
setTimeout(resolve, INITIALIZATION_STEP_DELAY)
setTimeout(resolve, INITIALIZATION_STEP_DELAY),
);
await this.initializationCheck();
}
Expand Down
6 changes: 3 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
"noFallthroughCasesInSwitch": false,
"paths": {
"rmq-nestjs/rmq-nestjs": [
"lib/rmq-nestjs/src"
"lib/"
],
"rmq-nestjs/rmq-nestjs/*": [
"lib/rmq-nestjs/src/*"
"lib/*"
]
}
},
"include": [
"src/**/*.ts",
"lib/**/*.ts",
"test/**/*.ts"
],
"exclude": [
Expand Down

0 comments on commit bccb83b

Please sign in to comment.