@dugongjs/core
Version: 
71 lines (70 loc) • 2.77 kB
TypeScript
import type { SerializableObject } from "../../types/serializable-object.type.js";
import type { SerializedDomainEvent } from "./serialized-domain-event.js";
export type DomainEventPayload = SerializableObject | null;
/**
 * Abstract class representing a domain event.
 *
 * @template TPayload - The type of the payload. It can be a SerializableObject or null.
 */
export declare abstract class AbstractDomainEvent<TPayload extends DomainEventPayload = null> {
    abstract readonly origin: string;
    abstract readonly aggregateType: string;
    abstract readonly type: string;
    abstract readonly version: number;
    protected id: string;
    protected aggregateId: string;
    protected payload: TPayload;
    protected sequenceNumber: number;
    protected timestamp: Date;
    protected tenantId?: string;
    protected correlationId?: string;
    protected triggeredByEventId?: string;
    protected triggeredByUserId?: string;
    protected metadata?: SerializableObject;
    constructor(aggregateId: string, ...payload: TPayload extends null ? [] : [payload: TPayload]);
    static get origin(): string;
    static get aggregateType(): string;
    static get type(): string;
    static get version(): number;
    /**
     * Lifecycle method called when the event is created.
     */
    onCreate?(): void;
    /**
     * Lifecycle method called when the event is staged.
     */
    onStage?(): void;
    /**
     * Lifecycle method called when the event is committed.
     */
    onCommit?(): void;
    /**
     * Lifecycle method called when the event is applied.
     */
    onApply?(): void;
    getOrigin(): string;
    getAggregateType(): string;
    getType(): string;
    getVersion(): number;
    getId(): string;
    getAggregateId(): string;
    getPayload(): TPayload;
    getSequenceNumber(): number;
    getTimestamp(): Date;
    getTenantId(): string | undefined;
    getCorrelationId(): string | undefined;
    getTriggeredByEventId(): string | undefined;
    getTriggeredByUserId(): string | undefined;
    getMetadata(): SerializableObject | undefined;
    setId(id: string): this;
    setAggregateId(aggregateId: string): this;
    setSequenceNumber(sequenceNumber: number): this;
    setTimestamp(timestamp: Date): this;
    setTenantId(tenantId: string | undefined): this;
    setCorrelationId(correlationId: string): this;
    setTriggeredByEventId(triggeredByEventId: string): this;
    setTriggeredByUserId(triggeredByUserId: string): this;
    setMetadata(metadata: SerializableObject): this;
    serialize(): SerializedDomainEvent;
    static deserialize<TDomainEventClass extends new (...args: any) => AbstractDomainEvent<any>>(this: TDomainEventClass, serializedDomainEvent: SerializedDomainEvent): InstanceType<TDomainEventClass>;
}