Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
A file-based event source and sink using JSON encoding.
This serves as an example of how to create an EventSource
and EventSink
.
Synopsis
- eventPairFromPersistenceIncremental :: (IsChainState tx, MonadSTM m) => PersistenceIncremental (PersistedStateChange tx) m -> m (EventSource (StateEvent tx) m, EventSink (StateEvent tx) m)
- data PersistedStateChange tx
- = Legacy (StateChanged tx)
- | New (StateEvent tx)
Documentation
eventPairFromPersistenceIncremental :: (IsChainState tx, MonadSTM m) => PersistenceIncremental (PersistedStateChange tx) m -> m (EventSource (StateEvent tx) m, EventSink (StateEvent tx) m) Source #
A basic file based event source and sink defined using an
PersistenceIncremental
handle.
The complexity in this implementation mostly stems from the fact that we want
to be backward-compatible with the old, plain format of storing
StateChanged
items directly to disk using PersistenceIncremental
.
If any 'Legacy StateChanged' items are discovered, a running index is used
for the $sel:eventId:StateEvent
, while the 'New StateEvent' values are just stored as is.
A new implementation for an EventSource
with a compatible EventSink
could
be defined more generically with constraints:
(ToJSON e, FromJSON e, HasEventId) e => (EventSource e m, EventSink e m)
data PersistedStateChange tx Source #
Internal data type used by createJSONFileEventSourceAndSink
to be
compatible with plain usage of PersistenceIncrementa
using plain
StateChanged
items to the new StateEvent
persisted items.
Legacy (StateChanged tx) | |
New (StateEvent tx) |