# `A2UICore.CommonTypes`
[🔗](https://github.com/a2ui-elixir/a2ui/blob/v0.1.1/umbrella/apps/a2ui_core/lib/a2ui_core/common_types.ex#L1)

Validates values against the protocol's shared type definitions — the
`$defs` of each version's `common_types.json` (`DynamicValue`,
`FunctionCall`, `ChildList`, `Action`, v1.0 `Extensions`, …).

Validation is catalog-agnostic. `FunctionCall` refers to the active
catalog's functions (`catalog.json#/$defs/anyFunction`), so the
catalog slot is bound to a generic stub that accepts any well-formed
call: in v1.0 an object with a string `@call` (other than the reserved
`"@index"`, which `IndexSystemFunction` owns) and an optional `args`
object; in v0.9.x an object of `call`, `args` and `returnType` only.
Catalog-specific checks (does the function exist, are its arguments
right) belong to catalog validation.

    iex> A2UICore.CommonTypes.validate(%{"path" => "/user/name"}, "DynamicValue", "v0.9.1")
    {:ok, %{"path" => "/user/name"}}

    iex> {:error, error} = A2UICore.CommonTypes.validate(%{"1st" => 1}, "Extensions", "v1.0")
    iex> error.category
    :validation

# `definitions`
*since 0.1.0* 

```elixir
@spec definitions(A2UICore.Version.protocol_version()) :: [String.t()]
```

The definition names `version`'s `common_types.json` declares.

# `dynamic_definitions`
*since 0.1.0* 

```elixir
@spec dynamic_definitions() :: MapSet.t(String.t())
```

The names of the dynamic-value definitions across protocol versions
(`DynamicString`, `DynamicValue`, …): unions that accept a `DataBinding`,
a `FunctionCall` and literal values. `DataBinding` itself is included.

# `function_stub`
*since 0.1.0* 

```elixir
@spec function_stub(A2UICore.Version.protocol_version()) :: map()
```

The schema of a well-formed function call of `version`, standing in
for a catalog's `anyFunction` union where only the shape of a call —
not which functions exist — is to be checked.

# `permissive_catalog`
*since 0.1.0* 

```elixir
@spec permissive_catalog(A2UICore.Version.protocol_version()) :: map()
```

A catalog document that accepts whatever a catalog may define: any
component object, any theme, and a well-formed function call of
`version`. Message envelopes validate against it when the catalog a
component belongs to is only known later.

# `validate`
*since 0.1.0* 

```elixir
@spec validate(term(), String.t(), A2UICore.Version.protocol_version()) ::
  {:ok, term()} | {:error, A2UICore.Error.t()}
```

Validates `value` as the common type `definition` of protocol
`version`.

Returns `{:ok, value}` (the value unchanged — common types carry no
defaults to fill in) or `{:error, %A2UICore.Error{category: :validation}}`
with one detail per violation. Raises `ArgumentError` for a definition
the version does not declare.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
