UNPKG

@grubou/bussy

Version:

Command & query bus implementations

22 lines 851 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CommandBusDispatcherMiddleware = void 0; const CommandNotHandledError_1 = require("../types/CommandNotHandledError"); class CommandBusDispatcherMiddleware { constructor(commandHandlers) { this.commandHandlers = commandHandlers; } static build(handlers) { return new this(handlers); } async handle(command) { const commandName = command.label(); const commandHandler = this.commandHandlers[commandName]; if (!commandHandler) { throw new CommandNotHandledError_1.CommandNotHandledError(commandName); } return commandHandler.handle(command); } } exports.CommandBusDispatcherMiddleware = CommandBusDispatcherMiddleware; //# sourceMappingURL=CommandBusDispatcherMiddleware.js.map