@crdsyntax/mondb-event
v1.2.0
Published
This script automatically generates the **event and listener structure** for a NestJS project based on a Mongoose schema. It’s ideal for projects using event-driven architecture with `@nestjs/event-emitter`.
Downloads
11
Readme
Generate Event Script
This script automatically generates the event and listener structure for a NestJS project based on a Mongoose schema. It’s ideal for projects using event-driven architecture with @nestjs/event-emitter.
With this script, you can automatically create:
- The
event/folder with an event enum and a payload class (.event.ts). - The
listener/folder with listeners for single and batch events (.listener.ts). - The payload is automatically generated by reading the corresponding schema properties.
📦 Generated Structure
Example for an entity notification:
notification.event.tscontains:- Event enum (
SINGLE_CREATEandBATCH_CREATE) CreateNotificationEventclass with the schema properties.
- Event enum (
notification.listener.tscontains:- Listener for
SINGLE_CREATE - Listener for
BATCH_CREATE
- Listener for
src/notification/ ├── event/ │ └── notification.event.ts ├── listener/ │ └── notification.listener.ts └── schema/ └── notification.schema.ts
⚡ Requirements
- Node.js >= 18
- NestJS >= 10
- Mongoose
🚀 Installation
To use it as a local script:
- Place the script in
scripts/generate-event.js - Add this to your
package.json:
"scripts": {
"generate:event": "node scripts/generate-event.js"
}