eventsourcing-0.9.0: CQRS/ES library.

Safe HaskellSafe
LanguageHaskell2010

Database.CQRS.Event

Description

This module provides the interface between an event stream and the event type of the stream. An Event is something that can be read from an event stream. It can also be a WritableEvent which, unsurprisingly, means it can be added to the stream. Having two different typeclasses allows us to prevent a subset of events to be written as in the following example.

 data Current
 data Deprecated

 data MyEvent a where
   EventA :: MyEvent Current
   EventB :: MyEvent Current
   EventC :: MyEvent Deprecated

 instance Event (MyEvent e) where
   type DecodingFormat = Aeson.Value
   decodeEvent = Aeson.eitherDecode

 instance WritableEvent (MyEvent Current) where
   type EncodingFormat = Aeson.Value
   encodeEvent = Aeson.encode

 instance TypeError (Text "Cannot write deprecated event")
     => WritableEvent (MyEvent Deprecated)
Synopsis

Documentation

class Event e where Source #

Event that can read from some event stream with compatible decoding format and fed to a projection or aggregated in some way.

Associated Types

type EncodingFormat e :: * Source #

Format in which the event is encoded, e.g. Value.

class Event e => WritableEvent e where Source #

Event that can be written to an event stream. This is separate from Event to make it possible to restrict the events that can be written with a GADT.

Methods

encodeEvent :: e -> EncodingFormat e Source #

Format from which the event can be decoded, e.g. Value.