mps-nestjs-cqrs
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Nest Logo

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.

Readme

Keywords

none

Package Sidebar

Install

npm i mps-nestjs-cqrs

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

85.3 kB

Total Files

112

Last publish

Collaborators

  • int128fly