1.0.1 • Published 2 years ago
mps-nestjs-cqrs v1.0.1
Description
A fork of the original @nestjs/cqrs package that uses the names of queries and commands instead of a generated uuid. The pros of this version that handlers are mapped by command/query name which let you resolve them by name instead of type without losing any performance and can let you map your commands/queries without using nestjs controllers. The consequence is that commands and queries names needs to be unique.
What's new
CommandBus
resolveCommandTypeByName(name: string): Type<ICommand>;
// throw CommandHandlerNotFoundException if the command wasn't found
QueryBus
resolveQueryTypeByName(name: string): Type<IQuery>;
// throw QueryHandlerNotFoundException if the query wasn't found
Magic Trick example
const commandName = 'test';
const body = { value: 1 };
// resolve command
let command: ICommand;
try {
const commandType = this.commandBus.resolveCommandTypeByName(commandName);
// plainToClass from class-transformer package
command = plainToClass(commandType, body);
commandResult = await this.commandBus.execute(command);
} catch(error) {
if (error instanceof CommandHandlerNotFoundException) {
// command not found, do something here
}
throw error;
}
Installation
$ npm install --save mps-nestjs-cqrs
License
Nest is MIT licensed.
1.0.1
2 years ago
1.0.0-next.6
2 years ago
1.0.0-next.5
2 years ago
1.0.0-next.4
2 years ago
1.0.0-next.3
2 years ago
1.0.0-next.2
2 years ago
1.0.0-next.1
2 years ago
1.0.0-next
2 years ago