From d769540a8ff17d4c1d5e9136d1aea806eb75b8e4 Mon Sep 17 00:00:00 2001 From: Dylan De Sousa Date: Fri, 13 Dec 2024 21:39:21 +0100 Subject: [PATCH] refactor: remove explicit return types for TypeScript inference --- src/core/primitives/entity.base.ts | 2 +- .../repositories/drizzle-account.repository.ts | 4 ++-- .../drizzle-forgot-password-request.repository.ts | 4 ++-- .../repositories/in-memory-account.repository.ts | 6 +++--- .../in-memory-forgot-password-request.repository.ts | 4 ++-- src/shared-kernel/infrastructure/console-mailer.adapter.ts | 2 +- src/shared-kernel/infrastructure/http-logger.interceptor.ts | 3 +-- .../map-error-to-rfc9457-http-exception.interceptor.ts | 6 +++--- .../repositories/drizzle-outbox-message.repository.ts | 2 +- .../use-cases/process-outbox-messages/use-case.spec.ts | 2 +- 10 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/core/primitives/entity.base.ts b/src/core/primitives/entity.base.ts index c296f8f..dacbbd6 100644 --- a/src/core/primitives/entity.base.ts +++ b/src/core/primitives/entity.base.ts @@ -25,7 +25,7 @@ export abstract class Entity< static hydrate any>( this: Constructor, ...args: ConstructorParameters - ): InstanceType { + ) { return new this(...args); } diff --git a/src/identity-and-access/infrastructure/repositories/drizzle-account.repository.ts b/src/identity-and-access/infrastructure/repositories/drizzle-account.repository.ts index 36cb4c5..ad4a74a 100644 --- a/src/identity-and-access/infrastructure/repositories/drizzle-account.repository.ts +++ b/src/identity-and-access/infrastructure/repositories/drizzle-account.repository.ts @@ -30,7 +30,7 @@ export class DrizzleAccountRepository implements AccountRepository { }); } - async isEmailTaken(email: string): Promise { + async isEmailTaken(email: string) { const [record] = await this.database .select({ count: count(), @@ -42,7 +42,7 @@ export class DrizzleAccountRepository implements AccountRepository { return record.count > 0; } - async save(account: Account): Promise { + async save(account: Account) { await this.database .insert(accountSchema) .values(account.properties) diff --git a/src/identity-and-access/infrastructure/repositories/drizzle-forgot-password-request.repository.ts b/src/identity-and-access/infrastructure/repositories/drizzle-forgot-password-request.repository.ts index d029d27..ce44bfd 100644 --- a/src/identity-and-access/infrastructure/repositories/drizzle-forgot-password-request.repository.ts +++ b/src/identity-and-access/infrastructure/repositories/drizzle-forgot-password-request.repository.ts @@ -17,7 +17,7 @@ export class DrizzleForgotPasswordRequestRepository private readonly database: IdentityAndAccessDatabase ) {} - async hasPendingRequest(accountId: string): Promise { + async hasPendingRequest(accountId: string) { const results = await this.database .select({ count: count() }) .from(ForgotPasswordRequestSchema) @@ -27,7 +27,7 @@ export class DrizzleForgotPasswordRequestRepository return results[0].count > 0; } - async save(request: ForgotPasswordRequest): Promise { + async save(request: ForgotPasswordRequest) { const values = { ...request.properties, expiresAt: request.properties.expiresAt.toJSDate(), diff --git a/src/identity-and-access/infrastructure/repositories/in-memory-account.repository.ts b/src/identity-and-access/infrastructure/repositories/in-memory-account.repository.ts index 5ac3ea4..69d163a 100644 --- a/src/identity-and-access/infrastructure/repositories/in-memory-account.repository.ts +++ b/src/identity-and-access/infrastructure/repositories/in-memory-account.repository.ts @@ -4,7 +4,7 @@ import type { AccountRepository } from "@identity-and-access/domain/account/repo export class InMemoryAccountRepository implements AccountRepository { snapshots = new Map(); - async findByEmail(email: string): Promise { + async findByEmail(email: string) { for (const [id, properties] of this.snapshots.entries()) { if (properties.email !== email) continue; @@ -17,13 +17,13 @@ export class InMemoryAccountRepository implements AccountRepository { return null; } - async isEmailTaken(email: string): Promise { + async isEmailTaken(email: string) { return Array.from(this.snapshots.values()).some( (properties) => properties.email === email ); } - async save(account: Account): Promise { + async save(account: Account) { this.snapshots.set(account.id, account.properties); } } diff --git a/src/identity-and-access/infrastructure/repositories/in-memory-forgot-password-request.repository.ts b/src/identity-and-access/infrastructure/repositories/in-memory-forgot-password-request.repository.ts index b96940d..65e18a6 100644 --- a/src/identity-and-access/infrastructure/repositories/in-memory-forgot-password-request.repository.ts +++ b/src/identity-and-access/infrastructure/repositories/in-memory-forgot-password-request.repository.ts @@ -6,13 +6,13 @@ export class InMemoryForgotPasswordRequestRepository { snapshots = new Map(); - async hasPendingRequest(accountId: string): Promise { + async hasPendingRequest(accountId: string) { return [...this.snapshots.values()].some( (request) => request.accountId === accountId ); } - async save(request: ForgotPasswordRequest): Promise { + async save(request: ForgotPasswordRequest) { this.snapshots.set(request.id, request.properties); } } diff --git a/src/shared-kernel/infrastructure/console-mailer.adapter.ts b/src/shared-kernel/infrastructure/console-mailer.adapter.ts index 1a0dec6..539e61c 100644 --- a/src/shared-kernel/infrastructure/console-mailer.adapter.ts +++ b/src/shared-kernel/infrastructure/console-mailer.adapter.ts @@ -8,7 +8,7 @@ export class ConsoleMailer implements Mailer { to: string, templateId: string, variables: Record - ): Promise { + ) { this.logger.log( `Sending email to ${to} using template ${templateId} with variables: ${JSON.stringify( variables diff --git a/src/shared-kernel/infrastructure/http-logger.interceptor.ts b/src/shared-kernel/infrastructure/http-logger.interceptor.ts index 2bb5d28..91db513 100644 --- a/src/shared-kernel/infrastructure/http-logger.interceptor.ts +++ b/src/shared-kernel/infrastructure/http-logger.interceptor.ts @@ -5,14 +5,13 @@ import { Logger, NestInterceptor, } from "@nestjs/common"; -import { Observable } from "rxjs"; import { tap } from "rxjs/operators"; @Injectable() export class HttpLoggerInterceptor implements NestInterceptor { private readonly logger = new Logger(HttpLoggerInterceptor.name); - intercept(context: ExecutionContext, next: CallHandler): Observable { + intercept(context: ExecutionContext, next: CallHandler) { const request = context.switchToHttp().getRequest(); const response = context.switchToHttp().getResponse(); const start = Date.now(); diff --git a/src/shared-kernel/infrastructure/map-error-to-rfc9457-http-exception.interceptor.ts b/src/shared-kernel/infrastructure/map-error-to-rfc9457-http-exception.interceptor.ts index c655736..56a4c7e 100644 --- a/src/shared-kernel/infrastructure/map-error-to-rfc9457-http-exception.interceptor.ts +++ b/src/shared-kernel/infrastructure/map-error-to-rfc9457-http-exception.interceptor.ts @@ -13,20 +13,20 @@ import { NotFoundException, } from "@nestjs/common"; import { DateTime } from "luxon"; -import { Observable, throwError } from "rxjs"; +import { throwError } from "rxjs"; import { catchError } from "rxjs/operators"; @Injectable() export class MapErrorToRfc9457HttpException implements NestInterceptor { private readonly logger = new Logger(MapErrorToRfc9457HttpException.name); - intercept(_context: ExecutionContext, next: CallHandler): Observable { + intercept(_context: ExecutionContext, next: CallHandler) { return next .handle() .pipe(catchError((error) => this.throwAsHttpException(error))); } - private throwAsHttpException(error: unknown): Observable { + private throwAsHttpException(error: unknown) { this.logger.error(error); // @TODO: Map ValidationErrors to RFC9457 diff --git a/src/shared-kernel/infrastructure/repositories/drizzle-outbox-message.repository.ts b/src/shared-kernel/infrastructure/repositories/drizzle-outbox-message.repository.ts index a8985c6..d95cb16 100644 --- a/src/shared-kernel/infrastructure/repositories/drizzle-outbox-message.repository.ts +++ b/src/shared-kernel/infrastructure/repositories/drizzle-outbox-message.repository.ts @@ -16,7 +16,7 @@ export class DrizzleOutboxMessageRepository implements OutboxMessageRepository { private readonly database: SharedKernelDatabase ) {} - async findUnprocessedMessages(): Promise { + async findUnprocessedMessages() { const snapshots = await this.database .select() .from(outboxMessageSchema) diff --git a/src/shared-kernel/use-cases/process-outbox-messages/use-case.spec.ts b/src/shared-kernel/use-cases/process-outbox-messages/use-case.spec.ts index 8e8632d..40474a1 100644 --- a/src/shared-kernel/use-cases/process-outbox-messages/use-case.spec.ts +++ b/src/shared-kernel/use-cases/process-outbox-messages/use-case.spec.ts @@ -9,7 +9,7 @@ class MockEventEmitter implements EventEmitter { shouldThrowError = false; errorMessage: string = "An error occurred"; - async emitAsync(event: string, ...values: any[]): Promise { + async emitAsync(event: string, ...values: any[]) { if (this.shouldThrowError) { throw new Error(this.errorMessage); }