import type EventBus from "./EventBus/EventBus"; import type IEventStoreDBAL from "./IEventStoreDBAL"; import type ISnapshotStoreDBAL from "./Snapshot/SnapshotStoreDBAL"; import type { UpcasterChain } from "./Upcasting/UpcasterChain"; import EventSourcedAggregateRoot from "../Domain/EventSourcedAggregateRoot"; import { Identity } from "../Domain/AggregateRoot"; import DomainEventStream from "../Domain/Event/DomainEventStream"; export type AggregateFactory = new (aggregateRootID: Identity) => T; export default class EventStore { private readonly dbal; private readonly eventBus; private readonly snapshotStore?; private readonly modelConstructor; private readonly snapshotMargin; private readonly upcasterChain?; constructor(modelConstructor: AggregateFactory, dbal: IEventStoreDBAL, eventBus: EventBus, snapshotStoreDbal?: ISnapshotStoreDBAL, snapshotMargin?: number, upcasterChain?: UpcasterChain); load(aggregateRootId: Identity): Promise; save(entity: T): Promise; append(aggregateId: string, stream: DomainEventStream, expectedVersion?: number): Promise; private calculateExpectedVersion; replayFrom(uuid: string, from: number, to?: number): Promise; private takeSnapshot; private isSnapshotNeeded; private fromSnapshot; private aggregateFactory; /** * Applies upcasting to all events in the stream. * Events are migrated through the upcaster chain to their latest versions. * * @param stream - The original event stream * @returns A new stream with upcasted events */ private applyUpcasting; }