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-events-flow

v0.1.10

Published

A NestJS decorators package for events documentation and visualization

Readme

nestjs-events-flow

Una librería de decoradores para NestJS que proporciona una manera sencilla de documentar y visualizar el flujo de eventos en tu aplicación.

Características

  • Decoradores para documentar eventos emitidos y escuchados
  • Generación automática de documentación de eventos en formato JSON
  • Visualización del flujo de eventos con diagramas Mermaid
  • Generación de definiciones de tipos TypeScript para eventos
  • Soporte para patrones comodín (wildcards) en eventos jerárquicos

Instalación

npm install nestjs-events-flow

Requisitos

  • NestJS 9.x o superior
  • @nestjs/event-emitter 2.x o superior
  • reflect-metadata

Desarrollo local

Este proyecto incluye dos opciones para probar el paquete localmente sin necesidad de publicarlo:

Opción 1: Usando referencia local directa (Recomendado)

# Construir el paquete principal
yarn build

# Ir al directorio del proyecto de ejemplo
cd sample

# Instalar dependencias (usará la referencia file:../ configurada en package.json)
yarn install

# Ejecutar el proyecto de ejemplo
yarn start:dev

Opción 2: Usando Yarn/NPM Link

# En el directorio raíz del paquete
yarn build
yarn link

# En el proyecto donde quieras usar el paquete
cd /ruta/a/tu/proyecto
yarn link nestjs-events-flow

Para más detalles, consulta el README del proyecto de ejemplo.

Uso básico

1. Configurar los módulos necesarios

Hay dos formas recomendadas de usar esta biblioteca:

Opción 1: Mantener EventEmitterModule y agregar EventsFlowGlobalModule

import { Module } from "@nestjs/common";
import { EventEmitterModule } from "@nestjs/event-emitter";
import { EventsFlowGlobalModule } from "nestjs-events-flow";
import { AppController } from "./app.controller";
import { AppService } from "./app.service";

@Module({
  imports: [
    // 1. Configura EventEmitterModule normalmente
    EventEmitterModule.forRoot({
      delimiter: ".",
      wildcard: true,
      global: true,
      verboseMemoryLeak: true,
    }),
    // 2. Añade EventsFlowGlobalModule para habilitar autocompletado en toda la app
    EventsFlowGlobalModule,
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

Opción 2: Proporcionar EventsFlowService en el módulo que lo necesita

import { Module } from "@nestjs/common";
import { EventEmitterModule } from "@nestjs/event-emitter";
import { EventsFlowService } from "nestjs-events-flow";
import { AppController } from "./app.controller";
import { AppService } from "./app.service";

@Module({
  imports: [
    EventEmitterModule.forRoot({...}),
  ],
  controllers: [AppController],
  providers: [
    AppService,
    // Proporcionar EventsFlowService directamente en el módulo
    EventsFlowService,
  ],
  // Exportarlo si es necesario en otros módulos
  exports: [EventsFlowService],
})
export class AppModule {}

Importante: EventsFlowService debe usarse después de configurar EventEmitterModule, ya que depende de su funcionalidad.

2. Usar los decoradores y servicios en tus controladores

import { Controller, Get } from "@nestjs/common";
import { EventsFlowService, Events, OnEvent } from "nestjs-events-flow";

@Controller()
export class AppController {
  // Usar EventsFlowService para obtener autocompletado de eventos
  constructor(private readonly eventService: EventsFlowService) {}

  @Get()
  @Events({
    emit: ["user.created"],
  })
  async createUser() {
    // Ahora tendrás autocompletado en emit
    await this.eventService.emit("user.created", { id: 1, name: "John" });
    return { success: true };
  }

  // Usar OnEvent con autocompletado
  @OnEvent("user.created")
  async handleUserCreated(data: any) {
    console.log("User created:", data);
    // Lógica para manejar el evento
  }

  // También puedes usar el decorador Events para múltiples eventos
  @Events({
    listen: ["user.created", "user.updated"],
  })
  async handleUserEvents(data: any) {
    console.log("User event:", data);
    // Lógica para manejar múltiples eventos
  }
}

3. Generar la documentación de eventos

En tu archivo main.ts:

import { NestFactory } from "@nestjs/core";
import { AppModule } from "./app.module";
import { extractEventsDocumentation } from "nestjs-events-flow";

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  // Generar documentación de eventos
  await extractEventsDocumentation(app, {
    outputDir: ".", // Directorio de salida
    typeFile: "listen-types.d.ts", // Archivo de definiciones TypeScript
    docFile: "public/event-doc.json", // Documentación JSON
    htmlFile: "public/events-flow.html", // Visualización HTML
    generateTypeFileInPackage: true, // Genera el archivo de tipos en el paquete en lugar del proyecto
  });

  await app.listen(3000);
}
bootstrap();

Visualización de flujo de eventos

Después de ejecutar tu aplicación, se generará un archivo HTML con un diagrama Mermaid que muestra el flujo de eventos entre los diferentes métodos de tus controladores y servicios.

Para ver el diagrama, simplemente abre el archivo public/events-flow.html en tu navegador.

Licencia

MIT

Reproducible Build