UNPKG

arvox-backend

Version:

Un framework backend moderne et modulaire basé sur Hono, TypeScript et l'architecture hexagonale avec authentification Better Auth + Drizzle intégrée

52 lines 1.82 kB
import { IUseCase } from '../interfaces/use-case.interface'; import { ActivityType } from '../types'; /** * Base class for all use cases following the command pattern * Provides common functionality like logging, error handling, and validation */ export declare abstract class BaseUseCase<TParams, TResponse> implements IUseCase<TParams, TResponse> { /** * Execute the use case logic * @param params - Input parameters for the use case * @returns Promise containing the response */ abstract execute(params: TParams): Promise<TResponse>; /** * Define the activity type for logging purposes * @returns ActivityType enum value */ abstract log(): ActivityType; /** * Validate input parameters before execution * Override this method to add custom validation logic * @param params - Parameters to validate * @throws Error if validation fails */ protected validate(params: TParams): Promise<void>; /** * Handle errors in a consistent way across all use cases * @param error - The error that occurred * @param context - Additional context about the error * @returns Formatted error response */ protected handleError(error: any, context?: string): { success: false; error: string; }; /** * Create a successful response * @param data - The data to return * @returns Formatted success response */ protected createSuccessResponse<T>(data: T): { success: true; data: T; }; /** * Execute the use case with automatic validation and error handling * @param params - Input parameters * @returns Promise containing the response */ run(params: TParams): Promise<TResponse>; } //# sourceMappingURL=base-use-case.d.ts.map