function defineDomainEvent
Since 0.1.0
defineDomainEvent(runtime: IRuntimeServices): { DomainEvent: new <T>(
data: T,
opts?: { aggregateId?: string; version?: number; }
) => DomainEvent<T>
; IntegrationEvent: new <T>(
data: T,
opts?: { aggregateId?: string; version?: number; }
) => IntegrationEvent<T>
; }

Runtime-bound abstract bases for ergonomic construction.

Call once per app with ctx.runtime; returns abstract classes that can be extended and constructed as new X(data) without threading runtime.

Examples

Example 1

const { DomainEvent } = defineDomainEvent(ctx.runtime);
class UserCreated extends DomainEvent<{ userId: string }> {
  readonly type = 'UserCreated';
}
const event = new UserCreated({ userId: '123' });

Parameters

runtime: IRuntimeServices

Runtime services

Return Type

{ DomainEvent: new <T>(
data: T,
opts?: { aggregateId?: string; version?: number; }
) => DomainEvent<T>
; IntegrationEvent: new <T>(
data: T,
opts?: { aggregateId?: string; version?: number; }
) => IntegrationEvent<T>
; }

Runtime-bound { DomainEvent, IntegrationEvent } abstract bases

Usage

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