npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

nestjs-mediator

v0.0.5

Published

A simple mediator for nestjs

Downloads

18

Readme

Motivation

NestJS has a lightweight CQRS module that works very well but the problem is we can not inject the other provider with scope-request and that is the reason why this package has existed

Description

The nestjs-mediator supports request/response, command, query, and notification with exposing the ability to inject any scope-request provider

Installation

$ npm install --save nestjs-mediator

or with yarn

$ yarn add nestjs-mediator

Quick Start(or reference in github example)

Request/Response

Define your query or command

import { Request } from "nestjs-mediator"

export class TestCommand extends Request<string>{
	//Your properties
}

Then define your handler

import { RequestHandler, IRequestHandler } from "nestjs-mediator"

@RequestHandler(TestCommand)
export class TestCommandHandler implements IRequestHandler<TestCommand, string> {
	handle(data: TestCommand): Promise<string>{
		//Your logic
	}
}

Don't forget to import your CommandHandler and MediatorModule into your module

import { MediatorModule } from "nestjs-mediator"

@Module({
	imports: [MediatorModule],
	providers: [TestCommandHandler]
})

class TestModule{}

Finally, send your command through the mediator:

import { Mediator } from "nestjs-mediator"

@Controller()
export class TestController {
	constructor(private mediator: Mediator){}

	@Post()
	post(){
		return this.mediator.send(new TestCommand());
	}
}

Notification

Define your notification

import { Notification } from "nestjs-mediator"

export class TestNotification extends Notification{
	//Your properties
}

and then define many handlers that you want to receive this notification

import { NotificationHandler, INotificationHandler } from "nestjs-mediator"

@NotificationHandler(TestNotification)
export class TestNotificationHandler1 implements INotificationHandler<TestNotification>{
	handle(data: TestNotification){
		//Your logic
	}
}

@NotificationHandler(TestNotification)
export class TestNotificationHandler2 implements INotificationHandler<TestNotification>{
	handle(data: TestNotification){
		//Your logic
	}
}

Import MediatorModule and your handler the same as above and finally, publish your message via the mediator

import { Mediator } from "nestjs-mediator"

@Controller()
export class TestController {
	constructor(private mediator: Mediator){}

	@Post()
	post(){
		this.mediator.publish(new TestNotification())
	}
}

Types

Request<T> - where T is the returns value

RequestHandler<T> - the decorator where T is your request

IRequestHandler<T, U> - you must implement this interface, T is your request and U is your return value

Notification

NotificationHandler<T> - the decorator where T is your notification

INotificationHandler<T> - the interface that you have to implement to publish your notification