Helper functions for Filtr schema processing and plugin management.
Summary
Functions
Returns the default error mode configured for the application.
Parses and structures parameter options into a standardized format.
Converts AST from nested param macro calls into a schema map.
Returns a map of type atoms to their corresponding plugin module.
Functions
@spec default_error_mode() :: atom()
Returns the default error mode configured for the application.
Reads from the application config key :error_mode under :filtr.
Falls back to :fallback if not configured.
Parses and structures parameter options into a standardized format.
Separates type and run options from validation options, grouping
validators under a :validators key.
Run options: error_mode
Converts AST from nested param macro calls into a schema map.
This function recursively processes the AST generated by nested param blocks, transforming them into a structured schema map suitable for validation.
Examples
# Input AST from:
param :user do
param :name, :string, required: true
param :age, :integer, min: 18
end
# Output:
%{
user: %{
name: %{type: :string, validators: [required: true]},
age: %{type: :integer, validators: [min: 18]}
}
}Only param macro calls are valid inside nested blocks. Other expressions
will raise an ArgumentError.
@spec supported_error_modes() :: [atom()]
Returns a map of type atoms to their corresponding plugin module.
This function builds and caches a mapping of all supported types to the
plugin that handle them. The map is cached in :persistent_term for
fast access across the application.