Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nestjs-cqrs-extra

Package Overview
Dependencies
Maintainers
0
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nestjs-cqrs-extra

Library that provides additional features for the NestJS CQRS module.

  • 1.1.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

Nest Logo

A module for that provides additional features for the NestJS CQRS module.

NPM Version NPM License NPM Downloads Last commit

About

Nest CQRS Extra is a module that provides additional features for the NestJS CQRS module. It provides a way to send commands and queries through a message broker (e.g. NATS, Redis, MQTT) to the appropriate handlers in microservices. It also provides a way to create sagas that can be used to handle events.

Features

  • Typings - Provides typings for commands, queries, and events. (Request & Response)
  • Message Broker - Provides a way to send commands and queries to the appropriate handlers in microservices.
  • Saga - Provides a way to create sagas that can be used to handle events.

Installation

$ npm install nestjs-cqrs-extra @nestjs/microservices nats

Usage

Import the module

import { Module } from '@nestjs/common';
import { CqrsModule } from 'nestjs-cqrs-extra';

@Module({
    imports: [
        CqrsModule.forRoot({
            options: { servers: ['nats://localhost:4222'] }
        })
    ]
})
export class AppModule {
}

You can change adapter to redis or mqtt by changing the adapter option.

Create a command

import { BaseCommand } from 'nestjs-cqrs-extra';

export class CreateUserCommand extends BaseCommand<string> {
    constructor(public readonly name: string) {
        super();
    }
}

Create a command handler

import { CommandHandler } from 'nestjs-cqrs-extra';
import { CreateUserCommand } from './create-user.command';
import { Controller } from '@nestjs/common';

@Controller()
export class UserCommandsController {
    @CommandHandler(CreateUserCommand)
    public createUser(command: CreateUserCommand): string {
        return `User ${command.name} created`;
    }
}

Also you can use @QueryHandler and @EventHandler decorators to handle queries and events.

Send a command

import { CommandBus } from 'nestjs-cqrs-extra';
import { Injectable } from '@nestjs/common';

@Injectable()
export class UserService {
    constructor(private readonly commandBus: CommandBus) {
    }

    async createUser(name: string): Promise<string> {
        return this.commandBus.execute(new CreateUserCommand(name));
    }
}

Stay in touch

License

MIT © Alexey Filippov

Keywords

FAQs

Package last updated on 23 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc