From 8a84896b4fb56f47d2fce711318a8797cadf8775 Mon Sep 17 00:00:00 2001 From: moreal Date: Tue, 10 Dec 2024 22:38:35 +0900 Subject: [PATCH] refactor: apply `yarn lint` --- package.json | 2 +- src/app.controller.spec.ts | 2 +- src/app.controller.ts | 2 +- src/app.module.ts | 24 +++++++++++++---------- src/common/guards/auth.guard.ts | 14 ++++++++----- src/http-response.middleware.ts | 8 ++++---- src/job/dto/create-transfer-assets.dto.ts | 8 ++++---- src/job/job-status.entity.ts | 2 +- src/job/job.controller.ts | 8 ++++---- src/job/job.module.ts | 2 +- src/job/job.service.ts | 14 ++++++------- src/main.ts | 2 +- src/prisma/prisma.service.ts | 2 +- src/queue/queue.cron.ts | 8 ++++---- src/queue/queue.module.ts | 6 +++--- src/queue/queue.service.ts | 8 ++++---- src/transaction/transaction.controller.ts | 2 +- src/transaction/transaction.cron.ts | 2 +- src/transaction/transaction.module.ts | 4 ++-- src/transaction/transaction.service.ts | 4 ++-- src/tx/action.service.ts | 8 +++++--- src/tx/tx.module.ts | 4 ++-- src/tx/tx.service.ts | 20 +++++++++---------- src/utils/currency.ts | 2 +- 24 files changed, 84 insertions(+), 74 deletions(-) diff --git a/package.json b/package.json index 55f74de..9c354f7 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "start:dev": "nest start --watch", "start:debug": "nest start --debug --watch", "start:prod": "node dist/main", - "lint": "biome format --write", + "lint": "biome check --fix", "test": "jest", "test:watch": "jest --watch", "test:cov": "jest --coverage", diff --git a/src/app.controller.spec.ts b/src/app.controller.spec.ts index d22f389..f80369e 100644 --- a/src/app.controller.spec.ts +++ b/src/app.controller.spec.ts @@ -1,4 +1,4 @@ -import { Test, TestingModule } from '@nestjs/testing'; +import { Test, type TestingModule } from '@nestjs/testing'; import { AppController } from './app.controller'; import { AppService } from './app.service'; diff --git a/src/app.controller.ts b/src/app.controller.ts index cce879e..7056a3f 100644 --- a/src/app.controller.ts +++ b/src/app.controller.ts @@ -1,5 +1,5 @@ import { Controller, Get } from '@nestjs/common'; -import { AppService } from './app.service'; +import type { AppService } from './app.service'; @Controller() export class AppController { diff --git a/src/app.module.ts b/src/app.module.ts index 583657d..27ce839 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -1,19 +1,23 @@ -import { MiddlewareConsumer, Module, NestModule } from '@nestjs/common'; -import { AppController } from './app.controller'; -import { AppService } from './app.service'; -import { PrismaModule } from './prisma/prisma.module'; -import { JobModule } from './job/job.module'; -import { ScheduleModule } from '@nestjs/schedule'; -import { QueueModule } from './queue/queue.module'; -import { TransactionModule } from './transaction/transaction.module'; -import { ConfigModule } from '@nestjs/config'; -import { TxModule } from './tx/tx.module'; import { CacheModule } from '@nestjs/cache-manager'; +import { + type MiddlewareConsumer, + Module, + type NestModule, +} from '@nestjs/common'; +import { ConfigModule } from '@nestjs/config'; +import { ScheduleModule } from '@nestjs/schedule'; import { PrometheusModule, makeCounterProvider, } from '@willsoto/nestjs-prometheus'; +import { AppController } from './app.controller'; +import { AppService } from './app.service'; import { HttpResponseMiddleware } from './http-response.middleware'; +import { JobModule } from './job/job.module'; +import { PrismaModule } from './prisma/prisma.module'; +import { QueueModule } from './queue/queue.module'; +import { TransactionModule } from './transaction/transaction.module'; +import { TxModule } from './tx/tx.module'; @Module({ imports: [ diff --git a/src/common/guards/auth.guard.ts b/src/common/guards/auth.guard.ts index 0f73368..b8d9c75 100644 --- a/src/common/guards/auth.guard.ts +++ b/src/common/guards/auth.guard.ts @@ -1,8 +1,12 @@ -import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common'; -import { Reflector } from '@nestjs/core'; +import { + type CanActivate, + type ExecutionContext, + Injectable, +} from '@nestjs/common'; +import type { Reflector } from '@nestjs/core'; +import type { Request } from 'express'; +import type { PrismaService } from 'src/prisma/prisma.service'; import { RequireAuthToken } from '../decorators/required-auth-token.decorator'; -import { PrismaService } from 'src/prisma/prisma.service'; -import { Request } from 'express'; @Injectable() export class AuthGuard implements CanActivate { @@ -23,7 +27,7 @@ export class AuthGuard implements CanActivate { } const splat = header.split(' '); - if (splat.length == 2 && splat[0] == 'Bearer') { + if (splat.length === 2 && splat[0] === 'Bearer') { const authToken = await this.prismaSerivce.authToken.findUnique({ where: { token: splat[1], diff --git a/src/http-response.middleware.ts b/src/http-response.middleware.ts index 054f64a..a3c613a 100644 --- a/src/http-response.middleware.ts +++ b/src/http-response.middleware.ts @@ -1,7 +1,7 @@ -import { Injectable, NestMiddleware } from '@nestjs/common'; +import { Injectable, type NestMiddleware } from '@nestjs/common'; import { InjectMetric } from '@willsoto/nestjs-prometheus'; -import { Request, Response } from 'express'; -import { Counter } from 'prom-client'; +import type { Request, Response } from 'express'; +import type { Counter } from 'prom-client'; @Injectable() export class HttpResponseMiddleware implements NestMiddleware { @@ -12,7 +12,7 @@ export class HttpResponseMiddleware implements NestMiddleware { private readonly httpResponseCounter: Counter, ) {} - use(req: Request, res: Response, next: (error?: any) => void) { + use(req: Request, res: Response, next: (error?: unknown) => void) { if (req.baseUrl === '/metrics') return next(); this.httpRequestCounter diff --git a/src/job/dto/create-transfer-assets.dto.ts b/src/job/dto/create-transfer-assets.dto.ts index 25cf5e4..90cc1d6 100644 --- a/src/job/dto/create-transfer-assets.dto.ts +++ b/src/job/dto/create-transfer-assets.dto.ts @@ -1,13 +1,13 @@ import { Type } from 'class-transformer'; import { + IsDefined, + IsHexadecimal, + IsNumberString, IsObject, IsString, + Length, ValidateIf, ValidateNested, - IsHexadecimal, - Length, - IsDefined, - IsNumberString, } from 'class-validator'; import { IsTicker, diff --git a/src/job/job-status.entity.ts b/src/job/job-status.entity.ts index cd6461d..cbdc8ac 100644 --- a/src/job/job-status.entity.ts +++ b/src/job/job-status.entity.ts @@ -1,4 +1,4 @@ -import { TxResult } from '@prisma/client'; +import type { TxResult } from '@prisma/client'; export enum JobStatus { PENDING = 'PENDING', diff --git a/src/job/job.controller.ts b/src/job/job.controller.ts index 0467983..52111a8 100644 --- a/src/job/job.controller.ts +++ b/src/job/job.controller.ts @@ -1,10 +1,10 @@ import { Body, Controller, Get, Param, Post, UseGuards } from '@nestjs/common'; -import { JobService } from './job.service'; -import { CreateClaimItemsDto } from './dto/create-claim-items.dto'; -import { CreateTransferAssetsDto } from './dto/create-transfer-assets.dto'; import { RequireAuthToken } from 'src/common/decorators/required-auth-token.decorator'; import { AuthGuard } from 'src/common/guards/auth.guard'; -import { CreateClaimItemsEventDto } from './dto/create-claim-items-event.dto'; +import type { CreateClaimItemsEventDto } from './dto/create-claim-items-event.dto'; +import type { CreateClaimItemsDto } from './dto/create-claim-items.dto'; +import type { CreateTransferAssetsDto } from './dto/create-transfer-assets.dto'; +import type { JobService } from './job.service'; @UseGuards(AuthGuard) @Controller('jobs') diff --git a/src/job/job.module.ts b/src/job/job.module.ts index 035b83d..febdd52 100644 --- a/src/job/job.module.ts +++ b/src/job/job.module.ts @@ -1,7 +1,7 @@ import { Module } from '@nestjs/common'; +import { TxModule } from 'src/tx/tx.module'; import { JobController } from './job.controller'; import { JobService } from './job.service'; -import { TxModule } from 'src/tx/tx.module'; @Module({ imports: [TxModule], diff --git a/src/job/job.service.ts b/src/job/job.service.ts index d6b15a4..f02bda3 100644 --- a/src/job/job.service.ts +++ b/src/job/job.service.ts @@ -1,18 +1,18 @@ +import { randomUUID } from 'node:crypto'; import { BadRequestException, Injectable, Logger, NotFoundException, } from '@nestjs/common'; -import { PrismaService } from 'src/prisma/prisma.service'; -import { CreateClaimItemsDto } from './dto/create-claim-items.dto'; -import { CreateTransferAssetsDto } from './dto/create-transfer-assets.dto'; +import type { Job, TxResult } from '@prisma/client'; +import type { PrismaService } from 'src/prisma/prisma.service'; +import type { TxService } from 'src/tx/tx.service'; import { getCurrency } from 'src/utils/currency'; +import type { CreateClaimItemsEventDto } from './dto/create-claim-items-event.dto'; +import type { CreateClaimItemsDto } from './dto/create-claim-items.dto'; +import type { CreateTransferAssetsDto } from './dto/create-transfer-assets.dto'; import { JobStatus, getJobStatusFromTxResult } from './job-status.entity'; -import { TxService } from 'src/tx/tx.service'; -import { Job, TxResult } from '@prisma/client'; -import { CreateClaimItemsEventDto } from './dto/create-claim-items-event.dto'; -import { randomUUID } from 'crypto'; @Injectable() export class JobService { diff --git a/src/main.ts b/src/main.ts index f298e24..063dba3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,6 @@ +import { ValidationPipe } from '@nestjs/common'; import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; -import { ValidationPipe } from '@nestjs/common'; import * as dotenv from 'dotenv'; diff --git a/src/prisma/prisma.service.ts b/src/prisma/prisma.service.ts index 359f950..2e8f50c 100644 --- a/src/prisma/prisma.service.ts +++ b/src/prisma/prisma.service.ts @@ -1,4 +1,4 @@ -import { Injectable, OnModuleInit } from '@nestjs/common'; +import { Injectable, type OnModuleInit } from '@nestjs/common'; import { PrismaClient } from '@prisma/client'; @Injectable() diff --git a/src/queue/queue.cron.ts b/src/queue/queue.cron.ts index 4942e4b..71fac43 100644 --- a/src/queue/queue.cron.ts +++ b/src/queue/queue.cron.ts @@ -1,10 +1,10 @@ +import { CACHE_MANAGER } from '@nestjs/cache-manager'; import { Inject, Injectable } from '@nestjs/common'; -import { QueueService } from './queue.service'; import { Cron, CronExpression } from '@nestjs/schedule'; -import { Cache } from 'cache-manager'; -import { CACHE_MANAGER } from '@nestjs/cache-manager'; import { InjectMetric } from '@willsoto/nestjs-prometheus'; -import { Gauge } from 'prom-client'; +import type { Cache } from 'cache-manager'; +import type { Gauge } from 'prom-client'; +import type { QueueService } from './queue.service'; const handleCronLock = 'HANDLE_CRON_LOCK'; const handleStagingCronLock = 'HANDLE_STAGING_CRON_LOCK'; diff --git a/src/queue/queue.module.ts b/src/queue/queue.module.ts index 4a159bf..aaee5d3 100644 --- a/src/queue/queue.module.ts +++ b/src/queue/queue.module.ts @@ -1,9 +1,9 @@ import { Module } from '@nestjs/common'; -import { QueueService } from './queue.service'; -import { QueueCronController } from './queue.cron'; -import { TxModule } from 'src/tx/tx.module'; import { ConfigModule } from '@nestjs/config'; import { makeGaugeProvider } from '@willsoto/nestjs-prometheus'; +import { TxModule } from 'src/tx/tx.module'; +import { QueueCronController } from './queue.cron'; +import { QueueService } from './queue.service'; @Module({ imports: [TxModule, ConfigModule], diff --git a/src/queue/queue.service.ts b/src/queue/queue.service.ts index 4390b66..bd259b7 100644 --- a/src/queue/queue.service.ts +++ b/src/queue/queue.service.ts @@ -1,9 +1,9 @@ import { Injectable, Logger } from '@nestjs/common'; -import { ConfigService } from '@nestjs/config'; -import { ActionType, Job, Prisma } from '@prisma/client'; +import type { ConfigService } from '@nestjs/config'; +import { ActionType, type Job, Prisma } from '@prisma/client'; -import { PrismaService } from 'src/prisma/prisma.service'; -import { TxService } from 'src/tx/tx.service'; +import type { PrismaService } from 'src/prisma/prisma.service'; +import type { TxService } from 'src/tx/tx.service'; const DEFAULT_TX_ACTIONS_SIZE = 100; const JOT_RETRY_LIMIT = 1; diff --git a/src/transaction/transaction.controller.ts b/src/transaction/transaction.controller.ts index 5d6b679..2696f32 100644 --- a/src/transaction/transaction.controller.ts +++ b/src/transaction/transaction.controller.ts @@ -1,5 +1,5 @@ import { Controller, Get, Param } from '@nestjs/common'; -import { TransactionService } from './transaction.service'; +import type { TransactionService } from './transaction.service'; @Controller('transactions') export class TransactionController { diff --git a/src/transaction/transaction.cron.ts b/src/transaction/transaction.cron.ts index 89bec12..56d2977 100644 --- a/src/transaction/transaction.cron.ts +++ b/src/transaction/transaction.cron.ts @@ -1,6 +1,6 @@ import { Injectable } from '@nestjs/common'; -import { TransactionService } from './transaction.service'; import { Cron, CronExpression } from '@nestjs/schedule'; +import type { TransactionService } from './transaction.service'; @Injectable() export class TransactionCronController { diff --git a/src/transaction/transaction.module.ts b/src/transaction/transaction.module.ts index 34c124d..1fd7b23 100644 --- a/src/transaction/transaction.module.ts +++ b/src/transaction/transaction.module.ts @@ -1,8 +1,8 @@ import { Module } from '@nestjs/common'; -import { TransactionService } from './transaction.service'; +import { TxModule } from 'src/tx/tx.module'; import { TransactionController } from './transaction.controller'; import { TransactionCronController } from './transaction.cron'; -import { TxModule } from 'src/tx/tx.module'; +import { TransactionService } from './transaction.service'; @Module({ imports: [TxModule], diff --git a/src/transaction/transaction.service.ts b/src/transaction/transaction.service.ts index 360938e..dc8f73b 100644 --- a/src/transaction/transaction.service.ts +++ b/src/transaction/transaction.service.ts @@ -5,8 +5,8 @@ import { } from '@nestjs/common'; import { TxResult } from '@prisma/client'; import { getJobStatusFromTxResult } from 'src/job/job-status.entity'; -import { PrismaService } from 'src/prisma/prisma.service'; -import { TxService } from 'src/tx/tx.service'; +import type { PrismaService } from 'src/prisma/prisma.service'; +import type { TxService } from 'src/tx/tx.service'; const UPDATE_TRANSACTIONS_SIZE = 10; diff --git a/src/tx/action.service.ts b/src/tx/action.service.ts index 535299c..f9b9074 100644 --- a/src/tx/action.service.ts +++ b/src/tx/action.service.ts @@ -1,11 +1,11 @@ +import { randomUUID } from 'node:crypto'; import { Injectable } from '@nestjs/common'; import { BencodexDictionary } from '@planetarium/bencodex'; import type { Job } from '@prisma/client'; import { Decimal } from 'decimal.js'; -import { randomUUID } from 'node:crypto'; -import { CURRENCIES } from './tx.constants'; import type { Address as AddressType } from '@planetarium/account'; +import { CURRENCIES } from './tx.constants'; import { Address } from '@planetarium/account'; import { encodeCurrency } from '@planetarium/tx'; @@ -100,7 +100,9 @@ export class ActionService { guid.split('-').reduce((bytes, section, index) => { const bytesInChar = section.match(/.{1,2}/g); if (index < 3) bytesInChar.reverse(); - return bytes.concat(bytesInChar.map((byte) => parseInt(byte, 16))); + return bytes.concat( + bytesInChar.map((byte) => Number.parseInt(byte, 16)), + ); }, []), ); } diff --git a/src/tx/tx.module.ts b/src/tx/tx.module.ts index 51b46b1..080d8e0 100644 --- a/src/tx/tx.module.ts +++ b/src/tx/tx.module.ts @@ -1,8 +1,8 @@ +import { HttpModule } from '@nestjs/axios'; import { Module } from '@nestjs/common'; -import { TxService } from './tx.service'; import { ConfigModule } from '@nestjs/config'; import { ActionService } from './action.service'; -import { HttpModule } from '@nestjs/axios'; +import { TxService } from './tx.service'; @Module({ imports: [ diff --git a/src/tx/tx.service.ts b/src/tx/tx.service.ts index 54dc2ed..bdf22d8 100644 --- a/src/tx/tx.service.ts +++ b/src/tx/tx.service.ts @@ -1,16 +1,16 @@ +import { createHash } from 'node:crypto'; import { Injectable } from '@nestjs/common'; -import { ConfigService } from '@nestjs/config'; -import type { Job, TxResult } from '@prisma/client'; +import type { ConfigService } from '@nestjs/config'; import type { Account } from '@planetarium/account'; +import { BencodexDictionary, type Value, encode } from '@planetarium/bencodex'; import type { UnsignedTx } from '@planetarium/tx/dist/tx'; -import { BencodexDictionary, Value, encode } from '@planetarium/bencodex'; -import { createHash } from 'node:crypto'; +import type { Job, TxResult } from '@prisma/client'; -import { CURRENCIES, SUPER_FUTURE_DATETIME } from './tx.constants'; -import { ActionService } from './action.service'; -import { Tx } from './tx.entity'; -import { HttpService } from '@nestjs/axios'; +import type { HttpService } from '@nestjs/axios'; import { firstValueFrom } from 'rxjs'; +import type { ActionService } from './action.service'; +import { CURRENCIES, SUPER_FUTURE_DATETIME } from './tx.constants'; +import type { Tx } from './tx.entity'; import { Address, PublicKey } from '@planetarium/account'; import { AwsKmsAccount, KMSClient } from '@planetarium/account-aws-kms'; @@ -138,8 +138,8 @@ export class TxService { genesisHash: genesisHash, gasLimit: this.assumeGasLimit(action), maxGasPrice: { - currency: CURRENCIES['MEAD'], - rawValue: BigInt(Math.pow(10, 18)), + currency: CURRENCIES.MEAD, + rawValue: 10n ** 18n, }, }; diff --git a/src/utils/currency.ts b/src/utils/currency.ts index 6b1e29e..cd19e3a 100644 --- a/src/utils/currency.ts +++ b/src/utils/currency.ts @@ -1,4 +1,4 @@ -import { ValidationOptions, registerDecorator } from 'class-validator'; +import { type ValidationOptions, registerDecorator } from 'class-validator'; type Currency = { type: 'constant' | 'prefix' | 'string_prefix';