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
85 lines • 2.93 kB
TypeScript
import { IService } from '../interfaces/service.interface';
/**
* Base service class providing common business logic patterns
* Services orchestrate between repositories and external systems
*/
export declare abstract class BaseService implements IService {
protected readonly name: string;
constructor(name: string);
/**
* Get service name
* @returns Service name
*/
getName(): string;
/**
* Initialize service (called during framework setup)
* Override in child classes for custom initialization
*/
initialize(): Promise<void>;
/**
* Cleanup service resources
* Override in child classes for custom cleanup
*/
cleanup(): Promise<void>;
/**
* Health check for the service
* Override in child classes for specific health checks
* @returns Promise with health status
*/
healthCheck(): Promise<{
healthy: boolean;
message?: string;
}>;
/**
* Validate input data using provided schema
* @param data - Data to validate
* @param schema - Validation schema (Zod schema)
* @returns Validated data
* @throws Error if validation fails
*/
protected validate<T>(data: any, schema: any): T;
/**
* Handle service errors consistently
* @param error - Error that occurred
* @param context - Additional context
* @returns Formatted error
*/
protected handleError(error: any, context?: string): Error;
/**
* Execute operation with retry logic
* @param operation - Operation to execute
* @param maxRetries - Maximum number of retries
* @param delay - Delay between retries in milliseconds
* @returns Promise with operation result
*/
protected withRetry<T>(operation: () => Promise<T>, maxRetries?: number, delay?: number): Promise<T>;
/**
* Execute operation with timeout
* @param operation - Operation to execute
* @param timeoutMs - Timeout in milliseconds
* @returns Promise with operation result
*/
protected withTimeout<T>(operation: () => Promise<T>, timeoutMs?: number): Promise<T>;
/**
* Sleep for specified duration
* @param ms - Duration in milliseconds
* @returns Promise that resolves after delay
*/
protected sleep(ms: number): Promise<void>;
/**
* Log service activity
* @param level - Log level (info, warn, error)
* @param message - Log message
* @param data - Additional data to log
*/
protected log(level: 'info' | 'warn' | 'error', message: string, data?: any): void;
/**
* Create a service-specific error
* @param message - Error message
* @param code - Optional error code
* @param cause - Original error cause
* @returns Service error
*/
protected createError(message: string, code?: string, cause?: any): Error;
}
//# sourceMappingURL=base-service.d.ts.map