# `A2UIAgent.CatalogTransformer`
[🔗](https://github.com/a2ui-elixir/a2ui/blob/v0.1.1/umbrella/apps/a2ui_agent/lib/a2ui_agent/catalog_transformer.ex#L1)

Rules applied to a catalog before it reaches a prompt or a validator.

A transformer is either a module implementing this behaviour paired
with its argument, `{module, argument}`, or a one-argument function.
Either way it returns a new catalog. Transformers are registered on an
`A2UIAgent.CatalogConfig`, which applies them in order.

Two are built in:

  * `component_pruning/1` keeps only the named components;
  * `function_pruning/1` keeps only the named functions.

The allowlist is read literally: an empty list (or `nil`) keeps
nothing, and a name the catalog does not declare is ignored. To keep
everything, apply no transformer. The pruned catalog's schema is
rebuilt from what it keeps, so its `anyComponent`, `anyFunction` and
helper `$defs` refer only to those entries.

    iex> {:ok, catalog} =
    ...>   A2UICore.Catalog.from_json(%{
    ...>     "catalogId" => "demo",
    ...>     "protocolVersion" => "v1.0",
    ...>     "components" => %{
    ...>       "Label" => %{"type" => "object", "properties" => %{"text" => %{"type" => "string"}}},
    ...>       "Badge" => %{"type" => "object", "properties" => %{"count" => %{"type" => "number"}}}
    ...>     }
    ...>   })
    iex> pruned =
    ...>   A2UIAgent.CatalogTransformer.apply_all(catalog, [
    ...>     A2UIAgent.CatalogTransformer.component_pruning(["Label", "Unknown"])
    ...>   ])
    iex> Map.keys(pruned.components)
    ["Label"]

# `t`
*since 0.1.0* 

```elixir
@type t() :: {module(), term()} | (A2UICore.Catalog.t() -&gt; A2UICore.Catalog.t())
```

A transformer: `{module, argument}` or a function.

# `transform`
*since 0.1.0* 

```elixir
@callback transform(A2UICore.Catalog.t(), argument :: term()) :: A2UICore.Catalog.t()
```

Returns a new catalog derived from `catalog`.

# `apply_all`
*since 0.1.0* 

```elixir
@spec apply_all(A2UICore.Catalog.t(), [t()] | nil) :: A2UICore.Catalog.t()
```

Applies `transformers` to `catalog` one after another.

# `component_pruning`
*since 0.1.0* 

```elixir
@spec component_pruning([String.t()] | nil) :: t()
```

A transformer that keeps only the named components. Functions and
other definitions are kept.

Raises `ArgumentError` for a single string, which is almost always a
mistake for a one-element list.

# `function_pruning`
*since 0.1.0* 

```elixir
@spec function_pruning([String.t()] | nil) :: t()
```

A transformer that keeps only the named functions. Components and
other definitions are kept.

Raises `ArgumentError` for a single string.

---

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