Decree.Event.Mapper (decree v0.1.0)

Copy Markdown View Source

Map events to/from the structs used for persistence.

Example

Map domain event structs to Decree.EventStore.EventData structs in preparation for appending to the configured event store:

events = [%ExampleEvent1{}, %ExampleEvent2{}]
event_data = Decree.Event.Mapper.map_to_event_data(events)

:ok = Decree.EventStore.append_to_stream("stream-1234", :any_version, event_data)

Summary

Functions

Map a domain event (or list of events) to an Decree.EventStore.EventData struct (or list of structs).

Types

event()

@type event() :: struct()

Functions

map_from_recorded_event(recorded_event)

@spec map_from_recorded_event(Decree.EventStore.RecordedEvent.t()) :: event()

Map a Decree.EventStore.RecordedEvent struct to its event data.

map_from_recorded_events(recorded_events)

@spec map_from_recorded_events([Decree.EventStore.RecordedEvent.t()]) :: [event()]

Map a list of Decree.EventStore.RecordedEvent structs to their event data.

map_to_event_data(events, fields \\ [])

@spec map_to_event_data([event()], Keyword.t()) :: [Decree.EventStore.EventData.t()]
@spec map_to_event_data(struct(), Keyword.t()) :: Decree.EventStore.EventData.t()

Map a domain event (or list of events) to an Decree.EventStore.EventData struct (or list of structs).

Optionally, include the causation_id, correlation_id, and metadata associated with the event(s).

Examples

event_data = Decree.Event.Mapper.map_to_event_data(%ExampleEvent{})

event_data =
  Decree.Event.Mapper.map_to_event_data(
    [
      %ExampleEvent1{},
      %ExampleEvent2{}
    ],
    causation_id: Decree.UUID.uuid4(),
    correlation_id: Decree.UUID.uuid4(),
    metadata: %{"user_id" => user_id}
  )