nestjs-typed-events
Version:
Typesafe NestJS event emitter module
14 lines (13 loc) • 871 B
TypeScript
import { Constructor } from 'type-fest';
import { z } from 'zod';
import { Entry, EventSchema, Registry } from './types';
export declare const EVENT_LISTENER = "TypedEventEmitter_listener";
export type Watcher<T extends EventSchema> = {
handle(event: z.output<T>): Promise<void>;
};
export type WatcherMeta = {
event: string;
options: Entry<EventSchema>;
};
export declare function EventListener<Resource extends EventSchema, R extends Registry<Resource>, ResourceKey extends keyof R & string>(contract: R, resource: ResourceKey): (target: Constructor<Watcher<R[ResourceKey]['schema']>>) => void;
export declare const EventListenerDecoratorFactory: <Resource extends EventSchema, R extends Registry<Resource>>(contract: R) => <ResourceKey extends keyof R & string>(key: ResourceKey) => (target: Constructor<Watcher<R[ResourceKey]["schema"]>, any[]>) => void;