Selecto.Domain.Choices
(Selecto v0.4.6)
Copy Markdown
Choice-source membership helpers.
This module is intentionally metadata-only in its first slice. It can resolve a working-domain field to its declared choice source and build a stable membership request, but it only proves membership when a caller supplies an explicit resolver.
Summary
Functions
Resolves the choice-source binding for a working-domain field.
Builds an option-list request directly from a declared choice source.
Builds an invalid membership result.
Resolves an option-list request through an explicit resolver.
Builds an error option-list result.
Builds a choice-source option-list request.
Builds a resolved option-list result.
Builds an unknown option-list result.
Builds a choice-source membership request for a field/value pair.
Builds an unknown membership result.
Builds a valid membership result.
Boolean convenience for callers that already supplied a resolver.
Validates a choice-source membership question.
Types
Functions
@spec binding(map(), field()) :: {:ok, map()} | {:error, choice_error()}
Resolves the choice-source binding for a working-domain field.
Rich references use reference.choice_source; compact bindings use
choice_source directly on the column metadata.
@spec choice_source_options_request(map(), atom() | String.t(), map() | keyword()) :: {:ok, Selecto.Domain.Choices.OptionsRequest.t()} | {:error, choice_error()}
Builds an option-list request directly from a declared choice source.
@spec invalid(atom() | String.t(), map() | keyword()) :: Selecto.Domain.Choices.Result.t()
Builds an invalid membership result.
@spec list_options(map(), field(), map() | keyword()) :: {:ok, Selecto.Domain.Choices.OptionsResult.t()} | {:error, Selecto.Domain.Choices.OptionsResult.t() | choice_error()}
Resolves an option-list request through an explicit resolver.
Without a resolver this returns an :unknown result. A resolver may be a
one-arity function that receives an %OptionsRequest{} and returns an
%OptionsResult{}, {:ok, %OptionsResult{}}, or
{:error, %OptionsResult{}}.
@spec options_error(atom() | String.t(), map() | keyword()) :: Selecto.Domain.Choices.OptionsResult.t()
Builds an error option-list result.
@spec options_request(map(), field(), map() | keyword()) :: {:ok, Selecto.Domain.Choices.OptionsRequest.t()} | {:error, choice_error()}
Builds a choice-source option-list request.
By default the target is treated as a working-domain field and resolved
through its field binding. Pass by: :choice_source to build the request
directly from a declared choice source.
@spec options_resolved([map()], map() | keyword()) :: Selecto.Domain.Choices.OptionsResult.t()
Builds a resolved option-list result.
@spec options_unknown(atom() | String.t(), map() | keyword()) :: Selecto.Domain.Choices.OptionsResult.t()
Builds an unknown option-list result.
@spec request(map(), field(), term(), map() | keyword()) :: {:ok, Selecto.Domain.Choices.Request.t()} | {:error, choice_error()}
Builds a choice-source membership request for a field/value pair.
The domain may be either an authored domain map or a normalized domain from
Selecto.Domain.normalize/1. Invalid domain contracts and unbound fields
return structured errors.
@spec unknown(atom() | String.t(), map() | keyword()) :: Selecto.Domain.Choices.Result.t()
Builds an unknown membership result.
@spec valid(atom() | String.t(), map() | keyword()) :: Selecto.Domain.Choices.Result.t()
Builds a valid membership result.
Boolean convenience for callers that already supplied a resolver.
Unknown and invalid results both return false; use validate_choice/4 when
callers need to distinguish those states.
@spec validate_choice(map(), field(), term(), map() | keyword()) :: {:ok, Selecto.Domain.Choices.Result.t()} | {:error, Selecto.Domain.Choices.Result.t() | choice_error()}
Validates a choice-source membership question.
Without a resolver this returns an :unknown result instead of guessing. A
resolver may be a one-arity function that receives a %Request{} and returns
a %Result{}, {:ok, %Result{}}, or {:error, %Result{}}.