Jido.Signal.Router.Validator (Jido Signal v1.0.0)
View SourceValidates router configuration and normalizes route specifications.
Summary
Functions
Normalizes route specifications into Route structs.
Validates that a match function returns boolean for a test signal.
Validates a path string against the allowed format.
Validates that a priority value is within allowed bounds.
Validates that a target is a valid term.
Functions
@spec normalize( Jido.Signal.Router.Route.t() | [Jido.Signal.Router.Route.t() | tuple()] | tuple() ) :: {:ok, [Jido.Signal.Router.Route.t()]} | {:error, term()}
Normalizes route specifications into Route structs.
Parameters
input
- One of:- Single Route struct
- List of Route structs
- List of route_spec tuples
- {path, target} tuple where target can be any term
- {path, target, priority} tuple
- {path, match_fn, target} tuple
- {path, match_fn, target, priority} tuple
Returns
{:ok, [%Route{}]}
- List of normalized Route structs{:error, term()}
- If normalization fails
Validates that a match function returns boolean for a test signal.
Parameters
- match_fn: A function that takes a Signal struct and returns a boolean
Returns
{:ok, match_fn}
if valid{:error, reason}
if invalid
@spec validate_path(String.t()) :: {:ok, String.t()} | {:error, term()}
@spec validate_path(term()) :: {:error, term()}
Validates a path string against the allowed format.
Rules
- Must be a string
- Cannot contain consecutive dots (..)
- Cannot have consecutive ** segments
- Each segment must be either:
- A valid identifier (alphanumeric + underscore + hyphen)
- A single wildcard (*)
- A double wildcard (**)
Returns
{:ok, path}
if valid{:error, reason}
if invalid
Validates that a priority value is within allowed bounds.
Parameters
- priority: An integer between -100 and 100, or nil for default priority
Returns
{:ok, priority}
if valid{:error, reason}
if invalid
Validates that a target is a valid term.
Valid Targets
- Any term
Returns
{:ok, target}
- Always succeeds