Interface IStateStoredAggregate<C, S, E, V, CM, SM>

State stored aggregate interface is using/delegating a decider of type IDecider<C, S, E> to handle commands and produce new state. In order to handle the command, aggregate needs to fetch the current state via IStateRepository.fetchState function first, and then delegate the command to the decider which can produce new state as a result.

New state is then stored via IStateRepository.save function.

Author

Иван Дугалић / Ivan Dugalic /

Idugalic

interface IStateStoredAggregate<C, S, E, V, CM, SM> {
    decide: ((command, state) => readonly E[]);
    evolve: ((state, event) => S);
    fetch: ((command) => Promise<null | S & V & SM>);
    handle: ((command) => Promise<S & V & SM>);
    initialState: S;
    save: ((state, commandMetadata, version) => Promise<S & V & SM>);
}

Type Parameters

  • C

    Commands of type C that this aggregate can handle

  • S

    Aggregate state of type S

  • E

    Events of type E that this aggregate can publish

  • V

    The Version of the stored State

  • CM

    Command Metadata

  • SM

    State Metadata

Hierarchy (view full)

Implemented by

Properties

decide: ((command, state) => readonly E[])

Type declaration

    • (command, state): readonly E[]
    • Parameters

      • command: C
      • state: S

      Returns readonly E[]

evolve: ((state, event) => S)

Type declaration

    • (state, event): S
    • Parameters

      • state: S
      • event: E

      Returns S

fetch: ((command) => Promise<null | S & V & SM>)

Fetch state, version and metadata

Type declaration

    • (command): Promise<null | S & V & SM>
    • Parameters

      • command: C & CM

        Command payload of type C with metadata of type CM

      Returns Promise<null | S & V & SM>

Returns

current State/[S], Version/[V] and State Metadata/[SM]

handle: ((command) => Promise<S & V & SM>)

Type declaration

    • (command): Promise<S & V & SM>
    • Parameters

      • command: C & CM

      Returns Promise<S & V & SM>

initialState: S
save: ((state, commandMetadata, version) => Promise<S & V & SM>)

Save state (with optimistic locking)

You can update/save the item/state, but only if the version number in the storage has not changed.

Type declaration

    • (state, commandMetadata, version): Promise<S & V & SM>
    • Parameters

      • state: S

        State with Command Metadata of type S & CM

      • commandMetadata: CM

        Command Metadata of the command that initiated the state

      • version: null | V

        The current version of the state

      Returns Promise<S & V & SM>

Returns

newly saved State of type S & V & SM

Generated using TypeDoc