بنقرة واحدة
getting-started
Use when working with domain events and subscribers in NestJS applications.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Use when working with domain events and subscribers in NestJS applications.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Use when scanning NestJS providers with DiscoveryService-backed utilities.
Use when working with the @wisemen/nestjs-custom-fields package — developer-defined custom fields in NestJS with TypeORM persistence and runtime validation. Covers registering the CustomFieldDefinition entity, authoring definitions with customFieldDefinition(), storing resolved values via @CustomFieldValueColumn(), exposing them through CustomFieldValueDto / @IsCustomFields(), and validating submissions with CustomFieldDefinitionsRepository + validateCustomFieldValues(). Use this whenever a task involves custom field definitions, CustomFieldValue columns, custom-field DTOs, or tenant-scoped field definitions, even if the package is not named explicitly.
Use when defining Typesense collections, collectors, and search queries in NestJS APIs.
Generate PDFs through API2PDF in NestJS. Use when converting HTML or URLs to PDFs in apis.
Use when storing and validating multilingual text in NestJS apis with TypeORM and class-validator.
Use when configuring NATS messaging, subscribers, or the simple NatsClient in NestJS applications.
| name | getting-started |
| description | Use when working with domain events and subscribers in NestJS applications. |
Use @RegisterDomainEvent(...) on DomainEvent subclasses, emit them through
DomainEventEmitter, and register subscriber providers with @Subscribe(...)
or @SubscribeToAll(). In app code, wrap DomainEventEmitterModule in a local
module and import your subscriber modules there.
import { Global, Module } from '@nestjs/common'
import { DomainEventEmitterModule } from '@wisemen/nestjs-domain-events'
import { DomainEventSubscribersModule } from '#src/modules/domain-events/domain-event-subscribers.module.js'
@Global()
@Module({
imports: [
DomainEventEmitterModule.forRoot({
middleware: async (emit) => {
await emit()
}
}),
DomainEventSubscribersModule
]
})
export class DefaultDomainEventModule {}
Switch to forRootAsync(...) when the middleware depends on injected services
such as schedulers or request-scoped logging context.
import { DomainEvent, DomainEventEmitter, RegisterDomainEvent } from '@wisemen/nestjs-domain-events'
import type { SubjectedEventOptions } from '@wisemen/nestjs-domain-events'
export type ContactUuid = string
export enum DomainEventSubjectType {
CONTACT = 'contact'
}
export enum DomainEventType {
CONTACT_CREATED = 'contact.created'
}
export class ContactCreatedEventContent {
constructor (readonly uuid: ContactUuid) {}
}
export class ContactEvent<Content extends object> extends DomainEvent<Content> {
constructor (options: SubjectedEventOptions<Content, { contactUuid: ContactUuid }>) {
super({
...options,
subjectId: options.contactUuid,
subjectType: DomainEventSubjectType.CONTACT
})
}
}
@RegisterDomainEvent(DomainEventType.CONTACT_CREATED, 1)
export class ContactCreatedEvent extends ContactEvent<ContactCreatedEventContent> {
constructor (contactUuid: ContactUuid) {
super({
contactUuid,
content: new ContactCreatedEventContent(contactUuid)
})
}
}
import { Injectable } from '@nestjs/common'
@Injectable()
export class CreateContactUseCase {
constructor (
private readonly eventEmitter: DomainEventEmitter
) {}
async execute(contactUuid: ContactUuid): Promise<void> {
await this.eventEmitter.emit([
new ContactCreatedEvent(contactUuid)
])
}
}
import { Injectable } from '@nestjs/common'
import { DomainEvent, Subscribe, SubscribeToAll } from '@wisemen/nestjs-domain-events'
@Injectable()
export class ContactProjectionSubscriber {
@Subscribe(ContactCreatedEvent)
async handle (events: ContactCreatedEvent[]): Promise<void> {
for (const event of events) {
console.info('Project contact', event.content.uuid)
}
}
}
@Injectable()
export class DomainEventLogSubscriber {
@SubscribeToAll()
handle (events: DomainEvent[]): void {
for (const event of events) {
console.info(event.type, event.subjectId)
}
}
}
Subscriber methods are called with arrays grouped by event type for each
emit(...) call.
Subscribers need to be added to the imports in the forRoot or forRootAsync call of the DomainEventEmitterModule. This is commonly done by grouping them in a DomainEventSubscriberModule which is imported instead.