/** * Mediator Pattern Interfaces. * * The Mediator pattern provides a single entry point for all requests. * Each request type maps to exactly one handler. * * This is different from events (fire-and-forget, multiple subscribers). * Requests are "do something and return a result" (single handler, response required). */ /** * Marker interface for requests. * The generic parameter TResponse indicates what the handler returns. * * @example * class GetUserRequest implements IRequest { * constructor(public readonly userId: string) {} * } */ export interface IRequest { /** * Phantom type to carry the response type. * Not used at runtime, only for type inference. */ readonly __responseType?: TResponse; } /** * Handler for a specific request type. * * @example * class GetUserHandler implements IRequestHandler { * async handle(request: GetUserRequest): Promise { * return this.userRepository.findById(request.userId); * } * } */ export interface IRequestHandler, TResponse> { /** * Handle the request and return a response. */ handle(request: TRequest): Promise; } /** * Request type constructor. * Used for registering handlers by request class. */ export interface IRequestType, TResponse = unknown> { new (...args: any[]): TRequest; } /** * Mediator interface. * Routes requests to their registered handlers. */ export interface IMediator { /** * Send a request to its handler and return the response. * * @param request - The request to handle * @returns The handler's response * @throws Error if no handler is registered for the request type * * @example * const user = await mediator.send(new GetUserRequest('123')); */ send(request: IRequest): Promise; /** * Register a handler for a request type. * * @param requestType - The request class constructor * @param handler - The handler instance */ register, TResponse>(requestType: IRequestType, handler: IRequestHandler): void; } //# sourceMappingURL=IMediator.d.ts.map