Counterpoint.Envelope (counterpoint v0.1.0)

Copy Markdown View Source

A deserialized event together with its store metadata.

Projections and commands receive Envelope structs when reading events. Pattern-match on the data field to handle specific event types:

def apply(state, %Counterpoint.Envelope{data: %MyApp.Events.OrderPlaced{order_id: id}}) do
  Map.put(state, :order_id, id)
end

Fields

  • type – the event's type string (e.g. "OrderPlaced").
  • tags – tags stored alongside the event.
  • data – the deserialized event struct.
  • position – opaque store position used for optimistic-concurrency conditions.
  • occurred_at – parsed from the event map's "occurred_at" key, if present.

Summary

Types

t()

@type t() :: %Counterpoint.Envelope{
  data: struct(),
  occurred_at: DateTime.t() | nil,
  position: binary(),
  tags: [String.t()],
  type: String.t()
}