SelectoComponents.QueryContract.ChoiceSource.Client (selecto_components v0.4.8)
Consumer helpers for query-contract choice-source links.
The client reads choice_sources[].links from a JSON-ready query contract,
builds transport-neutral requests for option lookup and membership validation,
and can execute those requests through a caller-supplied transport function.
A transport receives %SelectoComponents.QueryContract.ChoiceSource.Request{}
and may return %{status: status, body: body}, {:ok, response}, or
{:error, reason}. Bodies may already be decoded maps/lists or JSON strings.
Link to this section Summary
Functions
Finds a choice-source entry by id.
Returns the choice-source entries advertised by a query contract.
Fetches options through a configured transport.
Infers the field bound to a choice source when the contract has one match.
Returns the advertised link map for a choice source.
Builds a GET request for a choice-source options endpoint.
Validates membership through a configured transport.
Builds a POST request for a choice-source membership endpoint.
Link to this section Types
choice_source_id()
contract()
@type contract() :: map()
result()
Link to this section Functions
choice_source(contract, choice_source_id)
@spec choice_source(contract(), choice_source_id()) :: {:ok, map()} | {:error, map()}
Finds a choice-source entry by id.
choice_sources(contract)
Returns the choice-source entries advertised by a query contract.
fetch_options(contract, choice_source_id, opts \\ [])
@spec fetch_options(contract(), choice_source_id(), keyword()) :: result()
Fetches options through a configured transport.
inferred_field(contract, choice_source_id)
@spec inferred_field(contract(), choice_source_id()) :: String.t() | nil
Infers the field bound to a choice source when the contract has one match.
links(contract, choice_source_id)
@spec links(contract(), choice_source_id()) :: {:ok, map()} | {:error, map()}
Returns the advertised link map for a choice source.
options_request(contract, choice_source_id, opts \\ [])
@spec options_request(contract(), choice_source_id(), keyword()) :: {:ok, SelectoComponents.QueryContract.ChoiceSource.Request.t()} | {:error, map()}
Builds a GET request for a choice-source options endpoint.
Supported options:
:search:limit:offset:paramsfor extra query parameters:headersfor transport headers:base_urlfor resolving relative links
validate_choice(contract, choice_source_id, value, opts \\ [])
@spec validate_choice(contract(), choice_source_id(), term(), keyword()) :: result()
Validates membership through a configured transport.
validate_request(contract, choice_source_id, value, opts \\ [])
@spec validate_request(contract(), choice_source_id(), term(), keyword()) :: {:ok, SelectoComponents.QueryContract.ChoiceSource.Request.t()} | {:error, map()}
Builds a POST request for a choice-source membership endpoint.
If :field is omitted and the query contract has exactly one
field_choice_bindings entry for the choice source, that field is included in
the request body.