cqrs-eda
Version:
Lightweight CQRS and Event-Driven Architecture library using TypeScript decorators, handlers and typings. Perfect for scalable event-driven apps.
18 lines (17 loc) • 535 B
JavaScript
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.
*/
export function Command(name) {
return function (target) {
if (commandRegistry.has(name)) {
throw new Error(`Command with name "${name}" is already registered.`);
}
commandRegistry.set(name, target);
};
}
export function getCommandRegistry() {
return commandRegistry;
}