class DomainEvent
implements IDomainEvent<T>
Since 0.1.0

Abstract base class for domain events.

Implements IDomainEvent<T>. Auto-generates id and occurredOn from IRuntimeServices (never Date.now()). Optional aggregateId/version are omitted from the object when not supplied (honors exactOptionalPropertyTypes).

Examples

Example 1

// Raw construction when runtime is in scope
class UserCreated extends DomainEvent<{ userId: string }> {
  readonly type = 'UserCreated';
}
const event = new UserCreated(runtime, { userId: '123' });

Constructors

DomainEvent(
runtime: IRuntimeServices,
data: T,
opts?: { aggregateId?: string; version?: number; }
)

Creates a domain event.

Parameters
runtime: IRuntimeServices

Runtime services for uuid/timestamp

data: T

The event payload

optional
opts: { aggregateId?: string; version?: number; }

Optional aggregate metadata

Type Parameters

T = unknown

The event payload type

Properties

readonly
data: T

The event payload.

readonly
id: string

Unique event ID.

readonly
occurredOn: Date

When the event occurred.

abstract
readonly
type: string

Event type name (e.g. "UserCreated").

Usage

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