# `Sourced.StoredEvent`
[🔗](https://gitlab.com/dimakula/sourced/-/blob/0.2.0/lib/sourced/stored_event.ex#L1)

An event that has been persisted to an event store.

Returned by `c:Sourced.EventStore.Behaviour.append/3` and
`c: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
`c:Sourced.EventStore.Behaviour.append/3`; see
`t:Sourced.EventStore.Behaviour.event/0` for that shape.

# `data`

```elixir
@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`

```elixir
@type metadata() :: %{optional(String.t()) =&gt; term()}
```

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

# `t`

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

# `tag`

```elixir
@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.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
