View Source Jido.Util (Jido v1.0.0-rc.5)

A collection of utility functions for the Jido framework.

This module provides various helper functions that are used throughout the Jido framework, including:

  • ID generation
  • Name validation
  • Error handling
  • Logging utilities

These utilities are designed to support common operations and maintain consistency across the Jido ecosystem. They encapsulate frequently used patterns and provide a centralized location for shared functionality.

Many of the functions in this module are used internally by other Jido modules, but they can also be useful for developers building applications with Jido.

Summary

Functions

debug(message, metadata \\ [])

(macro)

error(message, metadata \\ [])

(macro)

generate_id()

@spec generate_id() :: String.t()

Generates a unique ID.

log(level, message, metadata, opts)

validate_commands(modules)

@spec validate_commands([module()]) :: {:ok, [module()]} | {:error, String.t()}

Validates a list of command modules.

Each module must implement the Jido.Command behavior and have valid command specifications.

Parameters

  • modules: List of modules to validate

Returns

  • {:ok, modules} if all modules are valid
  • {:error, reason} if any module is invalid

Examples

iex> Jido.Util.validate_commands([MyApp.ValidCommand])
{:ok, [MyApp.ValidCommand]}

iex> Jido.Util.validate_commands([InvalidModule])
{:error, "Module InvalidModule does not implement Jido.Command behavior"}

validate_name(name)

@spec validate_name(any()) :: {:ok, String.t()} | {:error, Jido.Error.t()}

Validates the name of a Action.

The name must contain only letters, numbers, and underscores.

Parameters

  • name: The name to validate.

Returns

  • {:ok, name} if the name is valid.
  • {:error, reason} if the name is invalid.

Examples

iex> Jido.Action.validate_name("valid_name_123")
{:ok, "valid_name_123"}

iex> Jido.Action.validate_name("invalid-name")
{:error, %Jido.Error{type: :validation_error, message: "The name must contain only letters, numbers, and underscores."}}