/** * This class is used to be part of the Herald Event Message Manager. * It should be used to trigger events to Either RabbitMQ or Kafka through Herald * * It's highly recommended using it instead of declaring manual channel namd and publishing data */ import { GenericObject } from "@mongez/reinforcements"; import { type ObjectValidator } from "@warlock.js/seal"; export declare abstract class EventMessage> { protected data?: TPayload; /** * Event Name */ abstract eventName: string; /** * Event version */ version?: number; /** * Additional metadata (if any) */ metadata?: Record; /** * Event Message id */ messageId?: string; /** * Schema of payload that will be used to determine whether this event should be published */ schema?: ObjectValidator; /** * Data that will be sent with the event (Payload) */ toJSON(): TPayload; constructor(data?: TPayload); /** * Serialize the event to be ready for publishing. * Delegates payload resolution to toJSON() — override toJSON() to customize. * * @throws Error if toJSON() throws (e.g. no data provided) */ serialize(): { payload: TPayload; metadata: Record; messageId: string; eventName: string; version: number; occurredAt: Date; __through: string; }; } type EventOptions = { /** * Shapen the data that will be used */ toJSON?: (data: T) => GenericObject; /** * Validation schema */ schema?: ObjectValidator; }; /** * Represents an EventMessage class constructor. * * @template TIncoming - The type of data accepted by the constructor * @template TOutgoing - The type of data returned by toJSON() (defaults to TIncoming) */ type EventMessageClass, TOutgoing = TIncoming> = new (data?: TIncoming) => EventMessage; /** * A shorthand to define an event without declaring an entire class. * * This factory function creates an EventMessage subclass that transforms * input data (IncomingData) into a different output format (OutgoingData). * * @template IncomingData - The type of data passed to the constructor * @template OutgoingData - The type of data returned by toJSON() * * @example * ```typescript * const UserCreatedEvent = defineEvent( * "user.created", * { toJSON: (user) => user.only(["id", "name"]) } * ); * * publishEvent(new UserCreatedEvent(user)); * ``` */ export declare function defineEvent(eventName: string, options?: EventOptions): EventMessageClass; export {}; //# sourceMappingURL=event-message.d.ts.map