Jido.Signal.Router.Validator (Jido v1.1.0-rc.2)

View Source

Validates 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 either an instruction or a dispatch config.

Functions

dbug(_, _ \\ [])

(macro)

error(_, _ \\ [])

(macro)

normalize(route)

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 is:
      • %Instruction{}
      • {adapter, opts}
      • [{adapter, opts}, ...]
    • {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

validate_match(match_fn)

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

validate_path(path)

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

validate_priority(priority)

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

validate_target(instruction)

Validates that a target is either an instruction or a dispatch config.

Valid Formats

  • %Instruction{} with an atom action
  • {adapter, opts} where adapter is an atom
  • [{adapter, opts}, ...] list of adapter configs

Returns

  • {:ok, target} if valid
  • {:error, reason} if invalid