import type IEventSourced from "./IEventSourced"; import type DomainEvent from "./Event/DomainEvent"; export default abstract class EventSourced implements IEventSourced { protected eventHandlers: Map void>; private children; /** * Restores entity state from a snapshot. * * Uses a safe rehydration pattern instead of Object.assign to: * - Preserve class prototypes and methods * - Avoid overwriting critical infrastructure (event handlers) * - Only copy data properties, not methods * * @param snapshot - Snapshot data to restore from * @returns This entity with restored state */ fromSnapshot(snapshot: Record): this; recursiveHandling(event: DomainEvent, eventType?: string): void; protected getChildEntities(): EventSourced[]; protected registerChildren(child: EventSourced): void; /** * Register an explicit event handler for a specific event type. * All events raised by the aggregate must have a registered handler. * * Note: Constructor parameters use `any[]` for variance - this allows * registering constructors with any parameter signature. */ protected registerHandler(eventType: new (...args: any[]) => T, handler: (event: T) => void): void; private handle; }