Foundation.Validation.EventValidator (foundation v0.1.0)
Pure validation functions for event structures.
Contains only validation logic - no side effects, no business logic. All functions are pure and easily testable.
This module validates Event structs to ensure they contain valid data before storage or processing.
Examples
iex> event = Foundation.Types.Event.new([
...> event_id: 123,
...> event_type: :function_entry,
...> timestamp: System.monotonic_time()
...> ])
iex> Foundation.Validation.EventValidator.validate(event)
:ok
Summary
Types
Maximum allowed size for event data in bytes
Functions
Validate an event structure.
Validate event data size to prevent memory issues.
Validate event type is allowed.
Validate event field types.
Validate that an event has all required fields.
Types
Functions
@spec validate(Foundation.Types.Event.t()) :: :ok | {:error, Foundation.Types.Error.t()}
Validate an event structure.
Performs comprehensive validation including required fields, types, and data size.
Parameters
event
: The Event struct to validate
Examples
iex> valid_event = Event.new([event_id: 1, event_type: :test, timestamp: 123])
iex> EventValidator.validate(valid_event)
:ok
iex> invalid_event = Event.new([event_id: nil, event_type: :test])
iex> EventValidator.validate(invalid_event)
{:error, %Error{error_type: :validation_failed}}
@spec validate_data_size(Foundation.Types.Event.t()) :: :ok | {:error, Foundation.Types.Error.t()}
Validate event data size to prevent memory issues.
Checks that the event data doesn't exceed the maximum allowed size.
@spec validate_event_type(atom()) :: :ok | {:error, Foundation.Types.Error.t()}
Validate event type is allowed.
Checks that the event type is one of the predefined valid types.
Parameters
event_type
: Atom representing the event type
Examples
iex> EventValidator.validate_event_type(:function_entry)
:ok
iex> EventValidator.validate_event_type(:invalid_type)
{:error, %Error{error_type: :invalid_event_type}}
@spec validate_field_types(Foundation.Types.Event.t()) :: :ok | {:error, Foundation.Types.Error.t()}
Validate event field types.
Ensures all fields have the correct data types when present.
@spec validate_required_fields(Foundation.Types.Event.t()) :: :ok | {:error, Foundation.Types.Error.t()}
Validate that an event has all required fields.
Checks that critical fields like event_id, event_type, and timestamp are present.