eventsource-api-1.3.1: Provides an eventsourcing high level API.

Copyright(C) 2017 Yorick Laupa
License(see the file LICENSE)
MaintainerYorick Laupa <yo.eight@gmail.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

EventSource.Aggregate.Simple

Description

 

Synopsis

Documentation

type AggIO id command event state = Agg (Simple id command event state) Source #

A stream aggregate. An aggregate updates its internal based on the event it receives. You can read its current state by using snapshot. If it supports validation, through Validated typeclass, it can receive command and emits an event if the command was successful. Otherwise, it will yield an error. When receiving valid command, an aggregate will persist the resulting event. An aggregate is only responsible of its own stream.

class AggregateIO event state | event -> state where Source #

Represents a stream aggregate. An aggregate can rebuild its internal state by replaying all the stream's events that aggregate is responsible for.

Minimal complete definition

applyIO

Methods

applyIO :: state -> event -> IO state Source #

Given current aggregate state, updates it according to the event the aggregate receives.

class AggregateIO event state => ValidateIO command event state | command -> state, command -> event where Source #

Represents an aggregate that support validation. An aggregate that supports validation can receive command and decide if it was valid or not. When the validation is successful, The aggregate emits an event that will be persisted and pass to apply function.

Minimal complete definition

validateIO

Methods

validateIO :: state -> command -> IO (Either SomeException event) Source #

Validates a command. If the command validation succeeds, it will emits an event. Otherwise, it will returns an error.

data Simple id command event state Source #

Simple aggregate abstraction.

Instances

ValidateIO command event state => Validate (Simple id command event state) Source # 

Associated Types

type Cmd (Simple id command event state) :: * Source #

type Err (Simple id command event state) :: * Source #

Methods

validate :: Simple id command event state -> Cmd (Simple id command event state) -> M (Simple id command event state) (Decision (Simple id command event state)) Source #

AggregateIO event state => Aggregate (Simple id command event state) Source # 

Associated Types

type Id (Simple id command event state) :: * Source #

type Evt (Simple id command event state) :: * Source #

type M (Simple id command event state) :: * -> * Source #

Methods

apply :: Simple id command event state -> Evt (Simple id command event state) -> M (Simple id command event state) (Simple id command event state) Source #

type Cmd (Simple id command event state) Source # 
type Cmd (Simple id command event state) = command
type Err (Simple id command event state) Source # 
type Err (Simple id command event state) = SomeException
type Id (Simple id command event state) Source # 
type Id (Simple id command event state) = id
type Evt (Simple id command event state) Source # 
type Evt (Simple id command event state) = event
type M (Simple id command event state) Source # 
type M (Simple id command event state) = IO

newAgg :: AggregateIO event state => SomeStore -> id -> state -> IO (AggIO id command event state) Source #

Creates a new aggregate given an eventstore handle, an id and an initial state.

loadAgg :: (AggregateIO event state, StreamId id, DecodeEvent event) => SomeStore -> id -> state -> IO (Either ForEventFailure (AggIO id command event state)) Source #

Creates an aggregate and replays its entire stream to rebuild its internal state.

loadOrCreateAgg :: (AggregateIO event state, StreamId id, DecodeEvent event) => SomeStore -> id -> state -> IO (AggIO id command event state) Source #

Like loadAgg but call loadAgg in case of ForEventFailure error.

submitCmd :: (ValidateIO command event state, StreamId id, EncodeEvent event) => AggIO id command event state -> command -> IO (Either SomeException event) Source #

Submits a command to the aggregate. If the command was valid, it returns an event otherwise an error. In case of a valid command, the aggregate persist the resulting event to the eventstore. The aggregate will also update its internal state accordingly.

submitEvt :: AggregateIO event state => AggIO id command event state -> event -> IO () Source #

Submits an event. The aggregate will update its internal state accondingly.

closeAgg :: AggIO id command event state -> IO () Source #

Closes internal aggregate state.

snapshot :: AggIO id command event state -> IO state Source #

Returns current aggregate state.

route :: AggIO id command event state -> (SomeStore -> state -> (state -> r -> IO ()) -> IO ()) -> IO r Source #

Uses usually by Root aggregates which usually have unusual workflow and make great use of a CPS-ed computation. http://blog.sapiensworks.com/post/2016/07/14/DDD-Aggregate-Decoded-1