Four options on field / sub_field / conditional_field that read other
parts of the input. Parsed once at compile time into __from_path__,
__on_path__, __domain_ops__.
auto
Fill in a missing field from an MFA call.
field :id, :string, auto: {Ecto.UUID, :generate}
field :slug, :string, auto: {MyApp.Slug, :from_title, [:title]}| Form | Calls |
|---|---|
{Mod, :fun} | Mod.fun() (no args) |
{Mod, :fun, arg} | Mod.fun(arg) |
- Runs only when the field is missing from input. To overwrite supplied
values, look at the type marker
:editvs:addondo_pipeline. - Compile-time verifier
VerifyAutoMFArejects unknown MFAs.
from
Pull a value from a path elsewhere in the input.
field :user_id, :string, from: "headers::auth_user_id"The string is split on :: into a path. The runtime reads
get_in(input, [:headers, :auth_user_id]) and assigns it as the field's value
if the field is unset.
on
A pre-condition: the field is only allowed when another path satisfies a
predicate. Useful for conditional ownership ("role_id only present when
role: :admin").
field :role_id, :string, on: "role" # role_id requires role to be set
field :role_id, :string, on: "role=admin" # role_id requires role == "admin"If the gate fails, the runtime emits a :domain_parameters / :on error.
domain
Cross-field constraint expressions. Compile-evaluated into a structured op map.
field :status, :string, domain: "!auth_type=Atom[admin::moderator]"Reads: "this field is required when auth_type is in [:admin, :moderator]".
Supports :enum, :equal, presence (!), and absence checks.
Pipeline order
Per do_pipeline/7 (lib/guarded_struct/runtime.ex):
normalize_keys— atom-convert keys (exceptdynamic_fieldvalues).authorized_fields— reject unknown top-level keys when section opted in.check_enforce_keys— required-fields check.apply_auto— fill missing fields via MFAs.check_domain— cross-field constraints.check_on— conditional gates.apply_from— pull from other paths.- Sub-field recursion.
- Per-field validators.
run_main_validator.- Pass-1 derives over virtual fields.
- Pass-2 derives over the merged map.