UNPKG

@hexadrop/command

Version:

Hexagonal architecture utils library

33 lines (30 loc) 1.34 kB
import { Container } from '@hexadrop/ioc'; import { CommandBusCallback } from './bus.js'; import Command, { CommandClass } from './command.js'; import CommandHandlers from './command-handlers.js'; import '@hexadrop/either'; import '@hexadrop/error'; import '@hexadrop/types/class'; import '@hexadrop/types/primitives'; /** * IoCCommandHandlers class implements CommandHandlers interface. * It uses inversion of control to manage command handlers. */ declare class IoCCommandHandlers extends CommandHandlers { private readonly container; /** * IoCCommandHandlers constructor. * @param {Container} container - The IoC container. */ constructor(container: Container); /** * Searches for a command handler in the IoC container. * @param {CommandType | CommandClass<CommandType>} command - The command to search for. * @throws {InvalidCommandError} If the command does not have a name. * @throws {CommandNotRegisteredError} If the command handler is not registered in the IoC container. * @returns {CommandBusCallback<CommandType>} The command handler callback. * @template CommandType - The command type. */ search<CommandType extends Command>(command: CommandClass<CommandType> | CommandType): CommandBusCallback<CommandType>; } export { IoCCommandHandlers as default };