UNPKG

@dugongjs/core

Version:

42 lines (41 loc) 2.2 kB
import type { SerializableObject } from "../../types/serializable-object.type.js"; import type { AbstractDomainEvent } from "../abstract-domain-event/abstract-domain-event.js"; import type { DomainEventClass } from "../abstract-domain-event/domain-event-class.js"; import { AbstractEventSourcedAggregateRoot } from "../abstract-event-sourced-aggregate-root/abstract-event-sourced-aggregate-root.js"; export declare const IsInProcessContext: unique symbol; export declare const IsInCreationContext: unique symbol; export declare abstract class AbstractAggregateRoot extends AbstractEventSourcedAggregateRoot { private [IsInProcessContext]; private [IsInCreationContext]; private readonly stagedEvents; /** * Gets the staged domain events. * @returns An array of staged domain events. */ getStagedDomainEvents(): AbstractDomainEvent[]; /** * Gets the staged domain events that have not been applied yet. * @returns An array of staged domain events that have not been applied yet. */ getStagedDomainEventsNotApplied(): AbstractDomainEvent[]; /** * Creates a domain event with the aggregate ID of the current aggregate root. * Also sets the event ID and timestamp on the event. * @param domainEventClass The class of the domain event to create. * @param payload The payload for the domain event, if any. */ createDomainEvent<T extends AbstractDomainEvent>(domainEventClass: new (aggregateId: string) => T): T; createDomainEvent<TPayload extends SerializableObject, T extends AbstractDomainEvent<TPayload>>(domainEventClass: new (aggregateId: string, payload: TPayload) => T, payload: TPayload): T; /** * Stages one or more domain events. The events are given a sequence number based on the current event sequence number. * The sequence number is incremented for each event staged. * @param domainEvents The domain events to stage. */ stageDomainEvent(...domainEvents: InstanceType<DomainEventClass<any>>[]): void; /** * Clears the staged domain events. */ clearStagedDomainEvents(): void; private validateCommandContext; private validateCreationContext; }