hindsight-memory-store
Safe HaskellNone
LanguageGHC2021

Hindsight.Store.Memory.Internal

Synopsis

Core Types

data StoreState backend Source #

Internal state maintained by the store.

Constructors

StoreState 

Fields

Instances

Instances details
Eq (Cursor backend) => Eq (StoreState backend) Source # 
Instance details

Defined in Hindsight.Store.Memory.Internal

Methods

(==) :: StoreState backend -> StoreState backend -> Bool #

(/=) :: StoreState backend -> StoreState backend -> Bool #

data StoredEvent Source #

Raw stored event with minimal type information.

Constructors

StoredEvent 

Fields

Instances

Instances details
FromJSON StoredEvent Source # 
Instance details

Defined in Hindsight.Store.Memory.Internal

ToJSON StoredEvent Source # 
Instance details

Defined in Hindsight.Store.Memory.Internal

Generic StoredEvent Source # 
Instance details

Defined in Hindsight.Store.Memory.Internal

Show StoredEvent Source # 
Instance details

Defined in Hindsight.Store.Memory.Internal

Eq StoredEvent Source # 
Instance details

Defined in Hindsight.Store.Memory.Internal

type Rep StoredEvent Source # 
Instance details

Defined in Hindsight.Store.Memory.Internal

Cursor that can be rebuilt from sequence numbers

class StoreCursor backend where Source #

Capability for creating cursors from sequence numbers

Methods

makeCursor :: Integer -> Cursor backend Source #

Create a cursor from a sequence number

makeSequenceNo :: Cursor backend -> Integer Source #

Get the current sequence number

Version Control

checkVersionConstraint :: Eq (Cursor backend) => StoreState backend -> StreamId -> ExpectedVersion backend -> Either (VersionMismatch backend) () Source #

Check version constraints for a stream

getCurrentVersion :: StoreState backend -> StreamId -> Maybe (Cursor backend) Source #

Get current version of a stream (global cursor)

getCurrentStreamVersion :: StoreState backend -> StreamId -> Maybe StreamVersion Source #

Get current stream version of a stream (local cursor)

Event Processing

processEvents :: forall (ts :: [Symbol]) m backend. (MonadUnliftIO m, StoreCursor backend, Show (Cursor backend)) => EventMatcher ts backend m -> [StoredEvent] -> m SubscriptionResult Source #

Process events through matcher chain

processEventThroughMatchers :: forall m backend (event :: Symbol) (ts :: [Symbol]). (MonadUnliftIO m, Event event, StoreCursor backend, Show (Cursor backend)) => (Proxy event, EventHandler event m backend) -> EventMatcher ts backend m -> StoredEvent -> m SubscriptionResult Source #

Process a single event through matchers

State Management

updateState :: StoreCursor backend => StoredEvent -> StoreState backend -> StoreState backend Source #

Update store state with new events

Common Operations

makeStoredEvents :: forall (t :: Type -> Type) backend. Foldable t => StoreState backend -> Maybe CorrelationId -> UTCTime -> [EventId] -> StreamId -> StreamWrite t SomeLatestEvent backend -> ([StoredEvent], [Integer]) Source #

Make stored events from raw data

checkAllVersions :: forall (t :: Type -> Type) backend. Eq (Cursor backend) => StoreState backend -> Map StreamId (StreamWrite t SomeLatestEvent backend) -> Either (EventStoreError backend) () Source #

Check version constraints for all streams

insertAllEvents :: forall backend (t :: Type -> Type). (StoreCursor backend, Foldable t) => StoreState backend -> Maybe CorrelationId -> UTCTime -> [EventId] -> Map StreamId (StreamWrite t SomeLatestEvent backend) -> (StoreState backend, Cursor backend, Map StreamId (Cursor backend)) Source #

Insert all events into state Returns: (new state, final global cursor, per-stream cursors)

subscribeToEvents :: forall m backend (ts :: [Symbol]). (MonadUnliftIO m, StoreCursor backend, Show (Cursor backend)) => TVar (StoreState backend) -> EventMatcher ts backend m -> EventSelector backend -> m (SubscriptionHandle backend) Source #

Common implementation of event subscription