UNPKG

@hexadrop/command

Version:

Hexagonal architecture utils library

52 lines (49 loc) 2.35 kB
import { CommandBusCallback, CommandHandler } 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'; /** * @class InMemoryCommandHandlers * @implements CommandHandlers * @description Class representing in-memory command handlers. */ declare class InMemoryCommandHandlers extends CommandHandlers { /** * @property {Map<string, CommandBusCallback>} commandHandlersMap - The map of command handlers. */ private readonly commandHandlersMap; /** * @constructor * @description Constructs an instance of InMemoryCommandHandlers. */ constructor(); /** * @method register * @description Method to register a command handler. * @param {CommandClass<CommandType>} command - The command class. * @param {CommandBusCallback<CommandType> | CommandHandler<CommandType>} handlerOrCallback - The command bus callback or command handler. * @template CommandType - The type of the command. */ register<CommandType extends Command>(command: CommandClass<CommandType>, handlerOrCallback: CommandBusCallback<CommandType> | CommandHandler<CommandType>): void; /** * @method search * @description Method to search for a command handler. * @param {CommandType | CommandClass<CommandType>} command - The command or command class to search for. * @returns {CommandBusCallback<CommandType>} - The command bus callback for the command. * @throws {InvalidCommandError} - Throws an error if the command is invalid. * @throws {CommandNotRegisteredError} - Throws an error if the command is not registered. * @template CommandType - The type of the command. */ search<CommandType extends Command>(command: CommandClass<CommandType> | CommandType): CommandBusCallback<CommandType>; /** * @method unregister * @description Method to unregister a command handler. * @param {CommandClass<CommandType>} command - The command class to unregister. * @template CommandType - The type of the command. */ unregister<CommandType extends Command>(command: CommandClass<CommandType>): void; } export { InMemoryCommandHandlers as default };