diff --git a/src/lib/application/eventsourcing-aggregate.ts b/src/lib/application/eventsourcing-aggregate.ts index c1fa5ba..0456d07 100644 --- a/src/lib/application/eventsourcing-aggregate.ts +++ b/src/lib/application/eventsourcing-aggregate.ts @@ -31,11 +31,11 @@ export interface IEventRepository { /** * Fetch events * - * @param command - Command of type `C` + * @param command - Command of type `C` with metadata of type `CM` * * @return list of Events with Version and Event Metadata */ - readonly fetch: (command: C) => Promise; + readonly fetch: (command: C & CM) => Promise; /** * Get the latest event stream version / sequence @@ -138,7 +138,7 @@ export abstract class EventComputation implements IDecider { * An abstract algorithm to compute new events based on the old events and the command being handled. * It returns all the events, including the events created by handling commands which are triggered by Saga - orchestration included. */ -export abstract class EventOrchestratingComputation +export abstract class EventOrchestratingComputation implements IDecider, ISaga { protected constructor( @@ -175,8 +175,8 @@ export abstract class EventOrchestratingComputation protected async computeNewEvents( events: readonly E[], - command: C, - fetch: (c: C) => Promise + command: C & CM, + fetch: (c: C & CM) => Promise ): Promise { // eslint-disable-next-line functional/no-let let resultingEvents = this.computeNewEventsInternally(events, command); @@ -222,7 +222,7 @@ export class EventSourcingAggregate super(decider); } - async fetch(command: C): Promise { + async fetch(command: C & CM): Promise { return this.eventRepository.fetch(command); } @@ -268,7 +268,7 @@ export class EventSourcingAggregate * @author Иван Дугалић / Ivan Dugalic / @idugalic */ export class EventSourcingOrchestratingAggregate - extends EventOrchestratingComputation + extends EventOrchestratingComputation implements IEventSourcingOrchestratingAggregate { constructor( @@ -279,7 +279,7 @@ export class EventSourcingOrchestratingAggregate super(decider, saga); } - async fetch(command: C): Promise { + async fetch(command: C & CM): Promise { return this.eventRepository.fetch(command); } @@ -301,7 +301,7 @@ export class EventSourcingOrchestratingAggregate await this.computeNewEvents( currentEvents, command, - async (cmd: C) => await this.eventRepository.fetch(cmd) + async (cmd: C & CM) => await this.eventRepository.fetch(cmd) ) ).map((event) => ({ ...event, diff --git a/src/lib/application/materialized-view.ts b/src/lib/application/materialized-view.ts index 6ff921e..d7b51bc 100644 --- a/src/lib/application/materialized-view.ts +++ b/src/lib/application/materialized-view.ts @@ -33,7 +33,7 @@ export interface IViewStateRepository { * * @return current state / `S` with version / `V`, or NULL */ - readonly fetch: (event: E) => Promise<(S & V) | null>; + readonly fetch: (event: E & EM) => Promise<(S & V) | null>; /** * Save state * @@ -93,7 +93,7 @@ export class MaterializedView return this.view.evolve(state, event); } - async fetch(event: E): Promise<(S & V) | null> { + async fetch(event: E & EM): Promise<(S & V) | null> { return this.viewStateRepository.fetch(event); } diff --git a/src/lib/application/statestored-aggregate.ts b/src/lib/application/statestored-aggregate.ts index f98c6d3..3f320f9 100644 --- a/src/lib/application/statestored-aggregate.ts +++ b/src/lib/application/statestored-aggregate.ts @@ -31,10 +31,10 @@ export interface IStateRepository { /** * Fetch state, version and metadata * - * @param command - Command payload + * @param command - Command payload of type C with metadata of type `CM` * @return current State/[S], Version/[V] and State Metadata/[SM] */ - readonly fetch: (command: C) => Promise<(S & V & SM) | null>; + readonly fetch: (command: C & CM) => Promise<(S & V & SM) | null>; /** * Save state (with optimistic locking) @@ -171,7 +171,7 @@ export class StateStoredAggregate ) { super(decider); } - async fetch(command: C): Promise<(S & V & SM) | null> { + async fetch(command: C & CM): Promise<(S & V & SM) | null> { return this.stateRepository.fetch(command); } @@ -180,7 +180,7 @@ export class StateStoredAggregate } async handle(command: C & CM): Promise { - const currentState = await this.stateRepository.fetch(command as C); + const currentState = await this.stateRepository.fetch(command); const newState = this.computeNewState( currentState ? currentState : this.decider.initialState, command @@ -220,7 +220,7 @@ export class StateStoredOrchestratingAggregate super(decider, saga); } - async fetch(command: C): Promise<(S & V & SM) | null> { + async fetch(command: C & CM): Promise<(S & V & SM) | null> { return this.stateRepository.fetch(command); } @@ -229,7 +229,7 @@ export class StateStoredOrchestratingAggregate } async handle(command: C & CM): Promise { - const currentState = await this.stateRepository.fetch(command as C); + const currentState = await this.stateRepository.fetch(command); const newState = this.computeNewState( currentState ? currentState : this.decider.initialState, command