import type { IAppError } from "../CallbackArg"; import type IMiddleware from "../Middleware"; import type { NextMiddleware } from "../Middleware"; import type ICommand from "./Command"; import type ICommandHandler from "./CommandHandler"; /** Response type for command execution */ export type CommandResponse = void | IAppError; /** * CommandHandlerResolver is a TERMINAL middleware handler. * * It implements IMiddleware to participate in the middleware chain, * but it intentionally does NOT call next() because it is designed * to be the final handler in the chain that resolves and executes * the appropriate command handler. * * Usage: Always place this resolver as the LAST middleware in the chain. * Any middleware placed after this resolver will NOT be executed. */ export default class CommandHandlerResolver implements IMiddleware { private readonly handlers; /** * Execute the command by resolving its handler. * * Note: The `next` parameter is required by IMiddleware interface * but is intentionally not called as this is a terminal handler. * * @param command - The command to execute * @param _next - Unused. Terminal handler does not continue the chain. */ execute(command: ICommand, _next: NextMiddleware): Promise; addHandler(command: { name: string; }, handler: ICommandHandler): CommandHandlerResolver; private resolve; private getHandlerForCommand; }