import { IEventMetadata, IDomainEvent } from '@vytches/ddd-contracts'; /** * Abstract base class for all domain events with common functionality. * Provides consistent event structure with auto-generated IDs and timestamps. * * @public * @stable * @since 0.22.0 */ export declare abstract class DomainEvent implements IDomainEvent { /** * Unique identifier for the event */ readonly eventId: string; /** * When the event occurred */ readonly occurredOn: Date; /** * Name of the event, defaults to the class name */ readonly eventName: string; /** * Event payload */ readonly payload?: T | undefined; /** * Event metadata */ readonly metadata?: IEventMetadata; /** * Creates a new domain event * * @param payload - The event data * @param metadata - Optional metadata for the event * @param eventName - Optional custom event name (defaults to constructor.name) */ constructor(payload?: T, metadata?: IEventMetadata, eventName?: string); /** * Generate a unique identifier for the event * This is a simple implementation that can be replaced in production */ protected static generateId(): string; /** * Create a copy of this event with additional metadata. * * This forks the event's identity: the copy is built by calling the * constructor, so it receives a **new** `eventId` and `occurredOn`. That is * the intended behaviour when the copy is meant to be a distinct event. * * Two cases it does not cover: * - Preserving identity — attaching metadata that infrastructure resolves * late (a crypto-shredding key id, a correlation id assigned at dispatch) * while keeping the event the same event. Use `enrichEvent()` from * `@vytches/ddd-contracts`, or `AggregateRoot.transformDomainEvents()` when * the events still live on an aggregate. * - Subclasses with their own constructor signature — this calls * `new EventClass(payload, metadata, eventName)`, so an event declared as * `constructor(orderId, total)` will not survive the round trip. * `enrichEvent()` copies the prototype instead and never calls the * constructor. * * @param metadata - Metadata to merge with existing metadata * @returns A new event instance with combined metadata and a fresh identity */ withMetadata(metadata: Partial): DomainEvent; }