Field validation helpers for the FieldSelector module.
Provides validation functions for checking field selections are valid and properly structured.
This is a shared module used by both AshTypescript and AshKotlinMultiplatform.
Summary
Functions
Checks for duplicate field names in a field selection list.
Checks whether field_specs declares field_name.
Validates that a field exists in the given field specs.
Validates that nested fields are non-empty for fields that require selection.
Types
@type config() :: %{optional(:input_field_formatter) => atom()}
Functions
Checks for duplicate field names in a field selection list.
Normalizes field names using the input formatter before checking for duplicates.
Throws {:duplicate_field, field_name, path} if duplicates are found.
This runs before any field-existence check, so it sees every name a client sent, valid or not. A name that matches no existing atom stays a string here and is reported as such; the caller rejects it as an unknown field moments later.
Parameters
fields- List of field selectionspath- Current path for error reportingconfig- Configuration map with :input_field_formatter
Checks whether field_specs declares field_name.
Accepts a string name, which Keyword.has_key?/2 rejects outright. A client
name that resolved to no existing atom stays a string, and no field spec can
be keyed by one, so the answer is always false — the caller then reports it as
an unknown field.
Validates that a field exists in the given field specs.
Throws {:unknown_field, field_name, error_type, path} if not found.
Parameters
field_name- The field name to checkfield_specs- Keyword list of field specificationspath- Current path for error reportingerror_type- Error type string for error messages
Validates that nested fields are non-empty for fields that require selection.
Throws appropriate errors if validation fails.
Parameters
nested_fields- The nested field selectionsfield_name- The field name for error messagespath- Current path for error reportingerror_type- The type of error to throw (default: :relationship)