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/1keeps only the named components;function_pruning/1keeps 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"]
Summary
Callbacks
Returns a new catalog derived from catalog.
Functions
Applies transformers to catalog one after another.
A transformer that keeps only the named components. Functions and other definitions are kept.
A transformer that keeps only the named functions. Components and other definitions are kept.
Types
@type t() :: {module(), term()} | (A2UICore.Catalog.t() -> A2UICore.Catalog.t())
A transformer: {module, argument} or a function.
Callbacks
@callback transform(A2UICore.Catalog.t(), argument :: term()) :: A2UICore.Catalog.t()
Returns a new catalog derived from catalog.
Functions
@spec apply_all(A2UICore.Catalog.t(), [t()] | nil) :: A2UICore.Catalog.t()
Applies transformers to catalog one after another.
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.
A transformer that keeps only the named functions. Components and other definitions are kept.
Raises ArgumentError for a single string.