Sourced.StoredEvent (sourced v0.1.0)

Copy Markdown View Source

An event that has been persisted to an event store.

Returned by Sourced.EventStore.Behaviour.append/3 and Sourced.EventStore.Behaviour.query/2, carrying the store-assigned sequence alongside the fields the event was appended with.

The field types below are shared with the event maps handed to Sourced.EventStore.Behaviour.append/3; see Sourced.EventStore.Behaviour.event/0 for that shape.

Summary

Types

The event payload: a plain map, or a domain event struct when the store is configured with a Sourced.Middleware.Domain.

Free-form metadata attached to an event. Keys are strings so the map round-trips cleanly through JSON-backed stores.

t()

A reference to a domain concept the event concerns, conventionally written as "prefix:id""order:123", "customer:42". Where type says what happened, tags say what it happened to, and Sourced.EventStore.Query queries them directly instead of reaching into the payload.

Types

data()

@type data() :: map() | struct()

The event payload: a plain map, or a domain event struct when the store is configured with a Sourced.Middleware.Domain.

metadata()

@type metadata() :: %{optional(String.t()) => term()}

Free-form metadata attached to an event. Keys are strings so the map round-trips cleanly through JSON-backed stores.

t()

@type t() :: %Sourced.StoredEvent{
  data: data(),
  metadata: metadata(),
  occurred_at: DateTime.t(),
  sequence: non_neg_integer(),
  tags: [tag()],
  type: String.t() | module()
}

tag()

@type tag() :: String.t()

A reference to a domain concept the event concerns, conventionally written as "prefix:id""order:123", "customer:42". Where type says what happened, tags say what it happened to, and Sourced.EventStore.Query queries them directly instead of reaching into the payload.

Tags must be derivable from the event itself. Avoid personal data in them; hash or anonymise values such as usernames and emails.