eventful-core-0.1.1: Core module for eventful

Safe HaskellNone
LanguageHaskell2010

Eventful.Store.Class

Contents

Synopsis

EventStore

data EventStore serialized m Source #

The EventStore is the core type of eventful. A store operates in some monad m and stores events by serializing them to the type serialized.

Constructors

EventStore 

Fields

newtype GloballyOrderedEventStore serialized m Source #

Gets all the events ordered starting with a given SequenceNumber, and ordered by SequenceNumber. This is used when replaying all the events in a store.

data ExpectedVersion Source #

ExpectedVersion is used to assert the event stream is at a certain version number. This is used when multiple writers are concurrently writing to the event store. If the expected version is incorrect, then storing fails.

Constructors

AnyVersion

Used when the writer doesn't care what version the stream is at.

NoStream

The stream shouldn't exist yet.

StreamExists

The stream should already exist.

ExactVersion EventVersion

Used to assert the stream is at a particular version.

Utility types

data StoredEvent event Source #

A StoredEvent is an event with associated storage metadata.

Constructors

StoredEvent 

Fields

Instances

Functor StoredEvent Source # 

Methods

fmap :: (a -> b) -> StoredEvent a -> StoredEvent b #

(<$) :: a -> StoredEvent b -> StoredEvent a #

Foldable StoredEvent Source # 

Methods

fold :: Monoid m => StoredEvent m -> m #

foldMap :: Monoid m => (a -> m) -> StoredEvent a -> m #

foldr :: (a -> b -> b) -> b -> StoredEvent a -> b #

foldr' :: (a -> b -> b) -> b -> StoredEvent a -> b #

foldl :: (b -> a -> b) -> b -> StoredEvent a -> b #

foldl' :: (b -> a -> b) -> b -> StoredEvent a -> b #

foldr1 :: (a -> a -> a) -> StoredEvent a -> a #

foldl1 :: (a -> a -> a) -> StoredEvent a -> a #

toList :: StoredEvent a -> [a] #

null :: StoredEvent a -> Bool #

length :: StoredEvent a -> Int #

elem :: Eq a => a -> StoredEvent a -> Bool #

maximum :: Ord a => StoredEvent a -> a #

minimum :: Ord a => StoredEvent a -> a #

sum :: Num a => StoredEvent a -> a #

product :: Num a => StoredEvent a -> a #

Traversable StoredEvent Source # 

Methods

traverse :: Applicative f => (a -> f b) -> StoredEvent a -> f (StoredEvent b) #

sequenceA :: Applicative f => StoredEvent (f a) -> f (StoredEvent a) #

mapM :: Monad m => (a -> m b) -> StoredEvent a -> m (StoredEvent b) #

sequence :: Monad m => StoredEvent (m a) -> m (StoredEvent a) #

Eq event => Eq (StoredEvent event) Source # 

Methods

(==) :: StoredEvent event -> StoredEvent event -> Bool #

(/=) :: StoredEvent event -> StoredEvent event -> Bool #

Show event => Show (StoredEvent event) Source # 

Methods

showsPrec :: Int -> StoredEvent event -> ShowS #

show :: StoredEvent event -> String #

showList :: [StoredEvent event] -> ShowS #

data GloballyOrderedEvent event Source #

A GloballyOrderedEvent is an event that has a global SequenceNumber.

Constructors

GloballyOrderedEvent 

Fields

Instances

Functor GloballyOrderedEvent Source # 
Foldable GloballyOrderedEvent Source # 

Methods

fold :: Monoid m => GloballyOrderedEvent m -> m #

foldMap :: Monoid m => (a -> m) -> GloballyOrderedEvent a -> m #

foldr :: (a -> b -> b) -> b -> GloballyOrderedEvent a -> b #

foldr' :: (a -> b -> b) -> b -> GloballyOrderedEvent a -> b #

foldl :: (b -> a -> b) -> b -> GloballyOrderedEvent a -> b #

foldl' :: (b -> a -> b) -> b -> GloballyOrderedEvent a -> b #

foldr1 :: (a -> a -> a) -> GloballyOrderedEvent a -> a #

foldl1 :: (a -> a -> a) -> GloballyOrderedEvent a -> a #

toList :: GloballyOrderedEvent a -> [a] #

null :: GloballyOrderedEvent a -> Bool #

length :: GloballyOrderedEvent a -> Int #

elem :: Eq a => a -> GloballyOrderedEvent a -> Bool #

maximum :: Ord a => GloballyOrderedEvent a -> a #

minimum :: Ord a => GloballyOrderedEvent a -> a #

sum :: Num a => GloballyOrderedEvent a -> a #

product :: Num a => GloballyOrderedEvent a -> a #

Traversable GloballyOrderedEvent Source # 
Eq event => Eq (GloballyOrderedEvent event) Source # 
Show event => Show (GloballyOrderedEvent event) Source # 

newtype EventVersion Source #

Event versions are a strictly increasing series of integers for each projection. They allow us to order the events when they are replayed, and they also help as a concurrency check in a multi-threaded environment so services modifying the projection can be sure the projection didn't change during their execution.

Constructors

EventVersion 

Fields

Instances

Enum EventVersion Source # 
Eq EventVersion Source # 
Num EventVersion Source # 
Ord EventVersion Source # 
Read EventVersion Source # 
Show EventVersion Source # 
ToJSON EventVersion Source # 
FromJSON EventVersion Source # 

newtype SequenceNumber Source #

The sequence number gives us a global ordering of events in a particular event store. Using sequence numbers is not strictly necessary for an event sourcing and CQRS system, but it makes it way easier to replay events consistently without having to use distributed transactions in an event bus. In SQL-based event stores, they are also very cheap to create.

Constructors

SequenceNumber 

Instances

Enum SequenceNumber Source # 
Eq SequenceNumber Source # 
Num SequenceNumber Source # 
Ord SequenceNumber Source # 
Read SequenceNumber Source # 
Show SequenceNumber Source # 
ToJSON SequenceNumber Source # 
FromJSON SequenceNumber Source # 
ToHttpApiData SequenceNumber Source # 
FromHttpApiData SequenceNumber Source # 
PathPiece SequenceNumber Source # 

Utility functions

transactionalExpectedWriteHelper :: Monad m => (UUID -> m EventVersion) -> (UUID -> [serialized] -> m ()) -> ExpectedVersion -> UUID -> [serialized] -> m (Maybe EventWriteError) Source #

Helper to create storeEventsRaw given a function to get the latest stream version and a function to write to the event store. **NOTE**: This only works if the monad m is transactional.