@hexadrop/aggregate-root
Version:
Hexagonal architecture utils library
36 lines (33 loc) • 1.23 kB
TypeScript
import DomainEvent from '@hexadrop/event';
import { Primitives } from '@hexadrop/types/primitives';
/**
* Abstract class representing an Aggregate Root in Domain-Driven Design.
* This class is responsible for recording and pulling domain events.
*/
declare abstract class AggregateRoot {
#private;
/**
* Constructor for the AggregateRoot class.
* Initializes the domainEvents array.
*/
protected constructor();
/**
* Method to pull all domain events.
* This method removes all events from the domainEvents array and returns them.
* @returns {DomainEvent[]} An array of DomainEvent objects.
*/
pullDomainEvents(): DomainEvent[];
/**
* Method to record domain events.
* This method adds new events to the domainEvents array.
* @param {...DomainEvent[]} event - The domain events to record.
*/
record(...event: DomainEvent[]): void;
/**
* Abstract method to convert the AggregateRoot to primitives.
* This method must be implemented by subclasses.
* @returns {Primitives<unknown>} The primitive representation of the AggregateRoot.
*/
abstract toPrimitives(): Primitives<unknown>;
}
export { AggregateRoot as default };