UNPKG

cqrs-eda

Version:

Lightweight CQRS and Event-Driven Architecture library using TypeScript decorators, handlers and typings. Perfect for scalable event-driven apps.

22 lines (21 loc) 674 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Command = Command; exports.getCommandRegistry = getCommandRegistry; const commandRegistry = new Map(); /** * Command decorator to register a class as a command handler. * @param name - Unique name of the command. * @throws If a command with the same name is already registered. */ function Command(name) { return function (target) { if (commandRegistry.has(name)) { throw new Error(`Command with name "${name}" is already registered.`); } commandRegistry.set(name, target); }; } function getCommandRegistry() { return commandRegistry; }