View Source Commanded.Event.Mapper (Commanded v1.4.6)

Map events to/from the structs used for persistence.

Example

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

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

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

Summary

Functions

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

Types

@type event() :: struct()

Functions

Link to this function

map_from_recorded_event(recorded_event)

View Source
@spec map_from_recorded_event(Commanded.EventStore.RecordedEvent.t()) :: event()

Map an Commanded.EventStore.RecordedEvent struct to its event data.

Link to this function

map_from_recorded_events(recorded_events)

View Source
@spec map_from_recorded_events([Commanded.EventStore.RecordedEvent.t()]) :: [event()]

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

Link to this function

map_to_event_data(events, fields \\ [])

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

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

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

Examples

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

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