PtcRunner.Kernel.SelectionRules (PtcRunner v0.14.0)

Copy Markdown View Source

Sealed, non-executable provider-selection normalization rules.

Rules contain only bounded data: exact fields, scalar or unique-list types, literal or named-set defaults, finite named sets, and the closed cross-rule vocabulary subset_of, required_when_set_nonempty, and ceiling_of_context_limit. They cannot contain functions, modules, MFAs, regular expressions, or caller-owned schemas.

Summary

Functions

Normalizes a selection and names the closed rule that rejected it.

Validates and seals one closed selection-rule program.

Purely normalizes one provider selection under the effective limits.

Checks the complete data-only rule shape and its construction seal.

Types

cross_rule()

@type cross_rule() ::
  {:subset_of, binary(), binary()}
  | {:required_when_set_nonempty, binary(), binary()}
  | {:ceiling_of_context_limit, binary(), atom()}

default()

@type default() ::
  term() | {:named_set, binary()} | {:intersection, binary(), binary()}

field()

@type field() :: %{
  :type => scalar_type(),
  :input => boolean(),
  optional(:required) => boolean(),
  optional(:default) => default(),
  optional(:minimum) => integer(),
  optional(:maximum) => integer(),
  optional(:minimum_items) => non_neg_integer(),
  optional(:members) => binary()
}

rejection()

@type rejection() ::
  :invalid_shape
  | :unknown_property
  | :invalid_selection
  | {:field, binary()}
  | {:members, binary()}
  | {:required, binary()}
  | {:subset_of, binary(), binary()}
  | {:required_when_set_nonempty, binary(), binary()}
  | {:ceiling, binary()}

scalar_type()

@type scalar_type() :: :string | :integer | :boolean | {:unique_list, :string}

t()

@type t() :: %PtcRunner.Kernel.SelectionRules{
  attestation: binary() | nil,
  cross_rules: [cross_rule()],
  fields: %{required(binary()) => field()},
  named_sets: %{required(binary()) => [binary()]}
}

Functions

explain(rules, value, limits)

@spec explain(t(), term(), PtcRunner.Kernel.Limits.t()) ::
  {:ok, map()} | {:error, rejection()}

Normalizes a selection and names the closed rule that rejected it.

new(opts)

@spec new(keyword()) :: {:ok, t()} | {:error, :invalid_selection_rules}

Validates and seals one closed selection-rule program.

normalize(rules, value, limits)

@spec normalize(t(), term(), PtcRunner.Kernel.Limits.t()) ::
  {:ok, map()} | {:error, :invalid_selection}

Purely normalizes one provider selection under the effective limits.

valid?(rules)

@spec valid?(term()) :: boolean()

Checks the complete data-only rule shape and its construction seal.