Imp.Optimizer.Component (Imp v0.5.0)

Copy Markdown View Source

A program-owned description of one optimizable component.

Components pair a persisted, JSON-safe Imp.Optimizer.Parameter with the trusted runtime contract that gives the value meaning. Descriptions, constraints, and dependencies come from the fresh program, not from an optimizer artifact, so loading an artifact cannot weaken validation or gain executable authority.

The supported constraint vocabulary is deliberately small and executable: type, enum, minimum, maximum, minLength, maxLength, minItems, maxItems, and pattern. Unknown constraints are rejected rather than displayed as if Imp enforced them.

Summary

Functions

Returns a JSON-safe public description without executable callbacks.

Returns the component's stable parameter ID.

Builds and validates a described component around a parameter.

Validates a proposed JSON value against the component's enforced constraints.

Types

t()

@type t() :: %Imp.Optimizer.Component{
  constraints: %{optional(String.t()) => Imp.Optimizer.Parameter.json_value()},
  dependencies: [String.t()],
  description: String.t(),
  parameter: Imp.Optimizer.Parameter.t()
}

Functions

dump(component)

@spec dump(t()) :: map()

Returns a JSON-safe public description without executable callbacks.

id(component)

@spec id(t()) :: String.t()

Returns the component's stable parameter ID.

new(parameter, opts \\ [])

@spec new(Imp.Optimizer.Parameter.t(), keyword()) :: t()

Builds and validates a described component around a parameter.

validate_value!(value, value)

@spec validate_value!(t(), Imp.Optimizer.Parameter.json_value()) :: :ok
@spec validate_value!(Imp.Optimizer.Parameter.json_value(), map()) :: :ok

Validates a proposed JSON value against the component's enforced constraints.