From c803d1d70ffe176f1a66ea3ec739e9241f4e8a43 Mon Sep 17 00:00:00 2001 From: Suhun Han Date: Fri, 12 Jul 2024 19:47:39 +0900 Subject: [PATCH] refactor: apply Biome lint and format --- lib/sqs.decorators.ts | 3 ++- lib/sqs.module.ts | 43 +++++++++++++++---------------------------- lib/sqs.service.ts | 16 +++++++--------- lib/sqs.types.ts | 4 ++-- 4 files changed, 26 insertions(+), 40 deletions(-) diff --git a/lib/sqs.decorators.ts b/lib/sqs.decorators.ts index 4e703c4..2c9f40c 100644 --- a/lib/sqs.decorators.ts +++ b/lib/sqs.decorators.ts @@ -2,4 +2,5 @@ import { SetMetadata } from '@nestjs/common'; import { SQS_CONSUMER_EVENT_HANDLER, SQS_CONSUMER_METHOD } from './sqs.constants'; export const SqsMessageHandler = (name: string, batch?: boolean) => SetMetadata(SQS_CONSUMER_METHOD, { name, batch }); -export const SqsConsumerEventHandler = (name: string, eventName: string) => SetMetadata(SQS_CONSUMER_EVENT_HANDLER, { name, eventName }); +export const SqsConsumerEventHandler = (name: string, eventName: string) => + SetMetadata(SQS_CONSUMER_EVENT_HANDLER, { name, eventName }); diff --git a/lib/sqs.module.ts b/lib/sqs.module.ts index 34466d7..b82086c 100644 --- a/lib/sqs.module.ts +++ b/lib/sqs.module.ts @@ -1,8 +1,8 @@ +import { DiscoveryModule, DiscoveryService } from '@golevelup/nestjs-discovery'; import { DynamicModule, Global, Module, Provider, Type } from '@nestjs/common'; +import { SQS_OPTIONS } from './sqs.constants'; import { SqsService } from './sqs.service'; import { SqsModuleAsyncOptions, SqsModuleOptionsFactory, SqsOptions } from './sqs.types'; -import { SQS_OPTIONS } from './sqs.constants'; -import { DiscoveryModule, DiscoveryService } from '@golevelup/nestjs-discovery'; @Global() @Module({ @@ -18,6 +18,7 @@ export class SqsModule { }; const sqsProvider: Provider = { provide: SqsService, + // biome-ignore lint/correctness/noUnusedVariables: useFactory: (sqsOptions: SqsOptions, discover: DiscoveryService) => new SqsService(options, discover), inject: [SQS_OPTIONS, DiscoveryService], }; @@ -25,16 +26,9 @@ export class SqsModule { return { global: true, module: SqsModule, - imports: [ - DiscoveryModule, - ], - providers: [ - sqsOptions, - sqsProvider, - ], - exports: [ - sqsProvider, - ], + imports: [DiscoveryModule], + providers: [sqsOptions, sqsProvider], + exports: [sqsProvider], }; } @@ -50,13 +44,8 @@ export class SqsModule { global: true, module: SqsModule, imports: [DiscoveryModule, ...(options.imports ?? [])], - providers: [ - ...asyncProviders, - sqsProvider, - ], - exports: [ - sqsProvider, - ], + providers: [...asyncProviders, sqsProvider], + exports: [sqsProvider], }; } @@ -76,16 +65,14 @@ export class SqsModule { private static createAsyncOptionsProvider(options: SqsModuleAsyncOptions): Provider { if (options.useFactory) { - return { - provide: SQS_OPTIONS, - useFactory: options.useFactory, - inject: options.inject || [], - }; - } + return { + provide: SQS_OPTIONS, + useFactory: options.useFactory, + inject: options.inject || [], + }; + } - const inject = [ - (options.useClass || options.useExisting) as Type, - ]; + const inject = [(options.useClass || options.useExisting) as Type]; return { provide: SQS_OPTIONS, useFactory: async (optionsFactory: SqsModuleOptionsFactory) => await optionsFactory.createOptions(), diff --git a/lib/sqs.service.ts b/lib/sqs.service.ts index 6701c94..ea85b42 100644 --- a/lib/sqs.service.ts +++ b/lib/sqs.service.ts @@ -1,7 +1,9 @@ +import { GetQueueAttributesCommand, PurgeQueueCommand, QueueAttributeName, SQSClient } from '@aws-sdk/client-sqs'; +import { DiscoveryService } from '@golevelup/nestjs-discovery'; import { Inject, Injectable, Logger, LoggerService, OnModuleDestroy, OnModuleInit } from '@nestjs/common'; import { Consumer, StopOptions } from 'sqs-consumer'; import { Producer } from 'sqs-producer'; -import { SQSClient, GetQueueAttributesCommand, PurgeQueueCommand, QueueAttributeName } from '@aws-sdk/client-sqs'; +import { SQS_CONSUMER_EVENT_HANDLER, SQS_CONSUMER_METHOD, SQS_OPTIONS } from './sqs.constants'; import { Message, QueueName, @@ -10,8 +12,6 @@ import { SqsMessageHandlerMeta, SqsOptions, } from './sqs.types'; -import { DiscoveryService } from '@golevelup/nestjs-discovery'; -import { SQS_CONSUMER_EVENT_HANDLER, SQS_CONSUMER_METHOD, SQS_OPTIONS } from './sqs.constants'; @Injectable() export class SqsService implements OnModuleInit, OnModuleDestroy { @@ -30,12 +30,10 @@ export class SqsService implements OnModuleInit, OnModuleDestroy { this.logger = this.options.logger ?? new Logger('SqsService', { timestamp: false }); this.globalStopOptions = this.options.globalStopOptions ?? {}; - const messageHandlers = await this.discover.providerMethodsWithMetaAtKey( - SQS_CONSUMER_METHOD, - ); - const eventHandlers = await this.discover.providerMethodsWithMetaAtKey( - SQS_CONSUMER_EVENT_HANDLER, - ); + const messageHandlers = + await this.discover.providerMethodsWithMetaAtKey(SQS_CONSUMER_METHOD); + const eventHandlers = + await this.discover.providerMethodsWithMetaAtKey(SQS_CONSUMER_EVENT_HANDLER); this.options.consumers?.forEach((options) => { const { name, stopOptions, ...consumerOptions } = options; diff --git a/lib/sqs.types.ts b/lib/sqs.types.ts index 23034b5..75d89c5 100644 --- a/lib/sqs.types.ts +++ b/lib/sqs.types.ts @@ -1,7 +1,7 @@ +import type { MessageAttributeValue } from '@aws-sdk/client-sqs'; +import type { LoggerService, ModuleMetadata, Type } from '@nestjs/common'; import type { Consumer, ConsumerOptions, StopOptions } from 'sqs-consumer'; import type { Producer } from 'sqs-producer'; -import type { LoggerService, ModuleMetadata, Type } from '@nestjs/common'; -import type { MessageAttributeValue } from '@aws-sdk/client-sqs'; export type ProducerOptions = Parameters[0]; export type QueueName = string;