import { ObjectValidator } from "@warlock.js/seal"; import { GenericObject } from "@mongez/reinforcements"; //#region ../@warlock.js/herald/src/message-managers/event-message.d.ts declare abstract class EventMessage> { protected data?: TPayload | undefined; /** * 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 | undefined); /** * 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 | undefined; messageId: string; eventName: string; version: number | undefined; 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)); * ``` */ declare function defineEvent(eventName: string, options?: EventOptions): EventMessageClass; //#endregion export { EventMessage, defineEvent }; //# sourceMappingURL=event-message.d.mts.map