SelectoComponents.QueryContract (selecto_components v0.4.8)

Components-facing adapter for Selecto query contracts.

This module keeps SelectoComponents from walking raw domain internals when it needs query metadata for tooling, documentation, or future AI-facing surfaces. It delegates the actual normalization and projection work to core Selecto.

Link to this section Summary

Functions

Builds a constrained query contract from a domain-shaped input.

Encodes the JSON-ready query contract document.

Builds a JSON-ready query contract document.

Validates a generated query intent against a query contract.

Link to this section Types

Link to this type

diagnostics()

@type diagnostics() :: Selecto.Domain.Diagnostics.t()
@type result() :: {:ok, map(), diagnostics()} | {:error, diagnostics()}

Link to this section Functions

@spec build(term()) :: result()

Builds a constrained query contract from a domain-shaped input.

Accepted inputs are:

  • an authored Selecto domain map
  • an already-normalized Selecto domain
  • a configured %Selecto{} or selecto-like map containing :domain
Link to this function

encode_json(input, opts \\ [])

@spec encode_json(
  term(),
  keyword()
) :: {:ok, String.t(), diagnostics()} | {:error, diagnostics()}

Encodes the JSON-ready query contract document.

Link to this function

json_document(input, opts \\ [])

@spec json_document(
  term(),
  keyword()
) :: result()

Builds a JSON-ready query contract document.

The returned map has string keys and JSON-compatible values so callers can serve it directly from a future query_contract.json endpoint without leaking Elixir atoms or structs into the public artifact.

Link to this function

query_contract(input)

@spec query_contract(term()) :: result()

Alias for build/1.

Link to this function

validate_intent(input, intent, opts \\ [])

Validates a generated query intent against a query contract.

The validator is deliberately non-executing. It accepts either an existing query contract artifact or a domain-shaped input that can be projected into a query contract, then checks that the intent only references exposed detail fields, filter comparators, and sort fields.