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

Reads a catalog document into the parts of an `A2UICore.Catalog`
(`parse/2`) and writes those parts back as a document (`build/1`), so
that `build(parse(document))` equals `document`, apart from the
components and functions that `$defs.anyComponent` /
`$defs.anyFunction` leave out.

Each component and function keeps its definition as written; the
top-level fields (`$schema`, `$id`, `title`, `description`,
`protocolVersion`, `instructions`, the theme and where it sits, the
form of `functions`, the unions, unknown keys) are kept beside them.

A document read as a `Jason.OrderedObject` is kept too, and the
document written back follows its key order.

# `build`
*since 0.1.0* 

```elixir
@spec build(A2UICore.Catalog.t()) :: Jason.OrderedObject.t()
```

Writes a catalog's parts back as its document (`A2UICore.Catalog.to_json/2`),
as ordered objects: the top-level fields in a fixed order (`$schema`,
`$id`, `protocolVersion`, `title`, `description`, `catalogId`,
`instructions`, unknown keys, `components`, `functions`, the theme,
`$defs`), and what was read from a document in that document's order.

# `parse`
*since 0.1.0* 

```elixir
@spec parse(map() | Jason.OrderedObject.t(), keyword()) ::
  {:ok, map()} | {:error, A2UICore.Error.t()}
```

Reads a catalog document (a map, or a `Jason.OrderedObject` decoded
with `objects: :ordered_objects`, whose key order then orders the
components and functions). Options: `:catalog_id`,
`:protocol_version`.

# `to_plain`
*since 0.1.0* 

```elixir
@spec to_plain(term()) :: term()
```

Converts `Jason.OrderedObject`s in `term` to maps.

---

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