[fabric/domain] Rename event types to DomainEvent

This commit is contained in:
Pablo Baleztena 2024-10-30 22:40:31 -03:00
parent 55f6d788db
commit e92de85fe8
5 changed files with 20 additions and 14 deletions

View File

@ -7,10 +7,10 @@ import type {
VariantTag, VariantTag,
} from "@fabric/core"; } from "@fabric/core";
import type { StoreQueryError } from "../errors/query-error.ts"; 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"; import type { StoredEvent } from "./stored-event.ts";
export interface EventStore<TEvents extends Event> { export interface EventStore<TEvents extends DomainEvent> {
/** /**
* Store a new event in the event store. * Store a new event in the event store.
*/ */
@ -28,7 +28,7 @@ export interface EventStore<TEvents extends Event> {
): void; ): void;
} }
export type EventSubscriber<TEvents extends Event = Event> = ( export type EventSubscriber<TEvents extends DomainEvent = DomainEvent> = (
event: StoredEvent<TEvents>, event: StoredEvent<TEvents>,
) => MaybePromise<void>; ) => MaybePromise<void>;

View File

@ -1,18 +1,18 @@
// deno-lint-ignore-file no-explicit-any // 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"; import type { UUID } from "../../core/types/uuid.ts";
/** /**
* An event is a tagged variant with a payload and a timestamp. * An event is a tagged variant with a payload and a timestamp.
*/ */
export interface Event<TTag extends string = string, TPayload = any> { export interface DomainEvent<TTag extends string = string, TPayload = any>
readonly [VariantTag]: TTag; extends TaggedVariant<TTag> {
readonly id: UUID; readonly id: UUID;
readonly streamId: UUID; readonly streamId: UUID;
readonly payload: TPayload; readonly payload: TPayload;
} }
export type EventFromKey< export type EventFromKey<
TEvents extends Event, TEvents extends DomainEvent,
TKey extends TEvents[VariantTag], TKey extends TEvents[VariantTag],
> = Extract<TEvents, { [VariantTag]: TKey }>; > = Extract<TEvents, { [VariantTag]: TKey }>;

View File

@ -1,10 +1,10 @@
import type { PosixDate } from "@fabric/core"; 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. * A stored event is an inmutable event, already stored, with it's version in the stream and timestamp.
*/ */
export type StoredEvent<TEvent extends Event> = TEvent & { export type StoredEvent<TEvent extends DomainEvent> = TEvent & {
readonly version: bigint; readonly version: bigint;
readonly timestamp: PosixDate; readonly timestamp: PosixDate;
}; };

View File

@ -1,11 +1,11 @@
import type { VariantTag } from "@fabric/core"; 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 { StoredEvent } from "../events/stored-event.ts";
import type { AggregateModel, ModelToType } from "../models/model.ts"; import type { AggregateModel, ModelToType } from "../models/model.ts";
export interface Projection< export interface Projection<
TModel extends AggregateModel, TModel extends AggregateModel,
TEvents extends Event, TEvents extends DomainEvent,
> { > {
model: TModel; model: TModel;
events: TEvents[VariantTag][]; events: TEvents[VariantTag][];

View File

@ -1,18 +1,24 @@
// deno-lint-ignore-file no-explicit-any // deno-lint-ignore-file no-explicit-any
import type { TaggedError } from "@fabric/core"; import type { TaggedError } from "@fabric/core";
import type { DomainEvent } from "../events/event.ts";
import type { UseCase } from "./use-case.ts"; import type { UseCase } from "./use-case.ts";
export type Command< export type Command<
TDependencies = any, TDependencies = any,
TPayload = any, TPayload = any,
TEvent extends Event = any, TEvent extends DomainEvent = any,
TErrors extends TaggedError<string> = any, TErrors extends TaggedError<string> = any,
> = BasicCommandDefinition<TDependencies, TPayload, TEvent, TErrors>; > = BasicCommandDefinition<
TDependencies,
TPayload,
TEvent,
TErrors
>;
interface BasicCommandDefinition< interface BasicCommandDefinition<
TDependencies, TDependencies,
TPayload, TPayload,
TEvent extends Event, TEvent extends DomainEvent,
TErrors extends TaggedError<string>, TErrors extends TaggedError<string>,
> { > {
/** /**