View Source Sorcery.Event (Sorcery v0.1.0)
Defines the structure of an event in the system.
An event represents something that happened in your system that you want to track. Required fields:
- type: String identifying what kind of event it is
- data: The event payload
- metadata: Additional context with required domain and instance_id
- domain_sequence_number: Sequence number within the event's domain
Optional fields:
- sequence_number: Global sequence number (set by the store)
- version: Event schema version
- inserted_at: When the event was stored
Summary
Functions
Creates a new event.
Types
@type t() :: %Sorcery.Event{ data: map(), inserted_at: DateTime.t() | nil, metadata: %{ :domain => String.t(), :instance_id => String.t(), optional(String.t()) => term() }, sequence_number: pos_integer() | nil, type: String.t(), version: pos_integer() | nil }
Functions
Creates a new event.
Required Parameters
:type- String identifying what kind of event it is:data- The event payload as a map:domain- String identifying the domain this event belongs to:instance_id- String identifying the instance that generated this event:domain_sequence_number- Sequence number within the event's domain
Optional Parameters
:version- Event schema version:inserted_at- When the event was stored:additional_metadata- Map of additional metadata to merge with required metadata
Note: The global sequence_number is assigned by the event store when the event is persisted.
Examples
iex> Event.new(%{
...> type: "user_registered",
...> data: %{user_id: "123"},
...> domain: "users",
...> instance_id: "instance_1",
...> domain_sequence_number: 1,
...> version: 1
...> })
%Event{...}