Foundation.Types.Event (foundation v0.1.0)
Event data structure for Foundation.
Events represent actions, state changes, and system events that occur during Foundation operation. This is a pure data structure with no behavior.
While all fields are optional for maximum flexibility, production events typically should have at least an event_type and timestamp.
See @type t
for the complete type specification.
Examples
iex> event = Foundation.Types.Event.new([
...> event_type: :config_updated,
...> event_id: 123,
...> timestamp: System.monotonic_time()
...> ])
iex> event.event_type
:config_updated
iex> empty_event = Foundation.Types.Event.new()
iex> is_nil(empty_event.event_type)
true
Summary
Functions
Create an empty event structure without enforcement (for testing).
Create a new event structure with required fields.
Create a new event structure with a specific event type.
Types
@type correlation_id() :: String.t()
Correlation identifier for tracking related events
@type event_id() :: pos_integer()
Unique identifier for an event
@type t() :: %Foundation.Types.Event{ correlation_id: correlation_id() | nil, data: term() | nil, event_id: event_id() | nil, event_type: atom() | nil, node: node() | nil, parent_id: event_id() | nil, pid: pid() | nil, timestamp: integer() | nil, wall_time: DateTime.t() | nil }
Functions
@spec empty() :: %Foundation.Types.Event{
correlation_id: nil,
data: nil,
event_id: nil,
event_type: nil,
node: nil,
parent_id: nil,
pid: nil,
timestamp: nil,
wall_time: nil
}
Create an empty event structure without enforcement (for testing).
This function bypasses the @enforce_keys constraint to allow creation of events with nil values for testing purposes.
Examples
iex> event = Foundation.Types.Event.empty()
iex> is_nil(event.event_type)
true
@spec new() :: t()
Create a new event structure with required fields.
Creates an event with minimal required fields for enforcement. Additional fields can be provided via keyword list.
Examples
iex> event = Foundation.Types.Event.new()
iex> event.event_type
:default
iex> event = Foundation.Types.Event.new(event_type: :custom)
iex> event.event_type
:custom
Create a new event structure with a specific event type.
Accepts an atom for the event_type and creates an event with default values for required fields.
Parameters
event_type
: An atom representing the event type
Examples
iex> event = Foundation.Types.Event.new(:process_started)
iex> event.event_type
:process_started