diff --git a/packages/fabric/domain/events/event-store.ts b/packages/fabric/domain/events/event-store.ts index b747c1d..3952fd0 100644 --- a/packages/fabric/domain/events/event-store.ts +++ b/packages/fabric/domain/events/event-store.ts @@ -7,10 +7,10 @@ import type { VariantTag, } from "@fabric/core"; import type { StoreQueryError } from "../errors/query-error.ts"; -import type { Event } from "./event.ts"; +import type { DomainEvent } from "./event.ts"; import type { StoredEvent } from "./stored-event.ts"; -export interface EventStore { +export interface EventStore { /** * Store a new event in the event store. */ @@ -28,7 +28,7 @@ export interface EventStore { ): void; } -export type EventSubscriber = ( +export type EventSubscriber = ( event: StoredEvent, ) => MaybePromise; diff --git a/packages/fabric/domain/events/event.ts b/packages/fabric/domain/events/event.ts index a816666..ee2fd53 100644 --- a/packages/fabric/domain/events/event.ts +++ b/packages/fabric/domain/events/event.ts @@ -1,18 +1,18 @@ // deno-lint-ignore-file no-explicit-any -import type { VariantTag } from "@fabric/core"; +import type { TaggedVariant, VariantTag } from "@fabric/core"; import type { UUID } from "../../core/types/uuid.ts"; /** * An event is a tagged variant with a payload and a timestamp. */ -export interface Event { - readonly [VariantTag]: TTag; +export interface DomainEvent + extends TaggedVariant { readonly id: UUID; readonly streamId: UUID; readonly payload: TPayload; } export type EventFromKey< - TEvents extends Event, + TEvents extends DomainEvent, TKey extends TEvents[VariantTag], > = Extract; diff --git a/packages/fabric/domain/events/stored-event.ts b/packages/fabric/domain/events/stored-event.ts index 2a279a0..e80a9ea 100644 --- a/packages/fabric/domain/events/stored-event.ts +++ b/packages/fabric/domain/events/stored-event.ts @@ -1,10 +1,10 @@ import type { PosixDate } from "@fabric/core"; -import type { Event } from "./event.ts"; +import type { DomainEvent } from "./event.ts"; /** * A stored event is an inmutable event, already stored, with it's version in the stream and timestamp. */ -export type StoredEvent = TEvent & { +export type StoredEvent = TEvent & { readonly version: bigint; readonly timestamp: PosixDate; }; diff --git a/packages/fabric/domain/projections/projection.ts b/packages/fabric/domain/projections/projection.ts index 37335c1..77895d0 100644 --- a/packages/fabric/domain/projections/projection.ts +++ b/packages/fabric/domain/projections/projection.ts @@ -1,11 +1,11 @@ import type { VariantTag } from "@fabric/core"; -import type { Event } from "../events/event.ts"; +import type { DomainEvent } from "../events/event.ts"; import type { StoredEvent } from "../events/stored-event.ts"; import type { AggregateModel, ModelToType } from "../models/model.ts"; export interface Projection< TModel extends AggregateModel, - TEvents extends Event, + TEvents extends DomainEvent, > { model: TModel; events: TEvents[VariantTag][]; diff --git a/packages/fabric/domain/use-case/command.ts b/packages/fabric/domain/use-case/command.ts index 5280260..25012a2 100644 --- a/packages/fabric/domain/use-case/command.ts +++ b/packages/fabric/domain/use-case/command.ts @@ -1,18 +1,24 @@ // deno-lint-ignore-file no-explicit-any import type { TaggedError } from "@fabric/core"; +import type { DomainEvent } from "../events/event.ts"; import type { UseCase } from "./use-case.ts"; export type Command< TDependencies = any, TPayload = any, - TEvent extends Event = any, + TEvent extends DomainEvent = any, TErrors extends TaggedError = any, -> = BasicCommandDefinition; +> = BasicCommandDefinition< + TDependencies, + TPayload, + TEvent, + TErrors +>; interface BasicCommandDefinition< TDependencies, TPayload, - TEvent extends Event, + TEvent extends DomainEvent, TErrors extends TaggedError, > { /**