interface IDomainEvents
Since 0.6.0

Records domain facts raised by one aggregate during its current operation.

The recorder is local state only: application code decides when durable state is saved, whether pending events are dispatched or persisted, and when they are removed. It never publishes to an event bus itself.

Examples

Example 1

class Order {
  readonly events = createDomainEvents();

  place(): void {
    this.events.record(new OrderPlaced());
  }
}

Methods

record<T>(event: IDomainEvent<T>): void

Appends an event reference to the pending facts in insertion order.

pending(): readonly IDomainEvent[]

Returns an ordered, read-only snapshot of pending facts.

Mutating a returned array cannot change the recorder.

remove(event: IDomainEvent): boolean

Removes the first pending reference that is strictly equal to event.

Event IDs are not collection identity; duplicate references are valid.

clear(): void

Removes all pending facts.

Usage

import { type IDomainEvents } from "events-plugin/src/index.ts";