# `Macaw.Frame.Document.Schema`
[🔗](https://github.com/dcoai/macaw_frame/blob/v0.1.0/lib/macaw/frame/document/schema.ex#L1)

The frame document's schema as data (spec/02 §1.2–§1.5, §13.2).

Every node kind of the design map (§1.2) is a list of key specs, each with a type
(§1.4), a facet (§1.3), a default, whether it is required and a merge rule (§1.5). The
validator, the forms, the merge rules of composition and any tool that groups keys read
them here, so a key added to a table reaches every consumer at once. The tables are
written in `Schema.Design`, `Schema.Frame` and `Schema.Layer` and built once, when the
library compiles.

Names in a design are strings; the keys of these tables and the members of their
enumerations are the library's own vocabulary, atoms, read from a document only by
lookup (spec/02 §9.3). Three node kinds are **open** (`open?/1`): a layer's `channels`
and `options` and a data step, whose string keys are their layer kind's and their
operation's to declare.

    iex> Macaw.Frame.Document.Schema.key(:layer, :style).facet
    :style
    iex> Macaw.Frame.Document.Schema.default(:frame, :margin)
    %{top: 20, right: 20, bottom: 30, left: 40}
    iex> hd(Macaw.Frame.Document.Schema.kinds())
    :design

# `facet`

```elixir
@type facet() :: :binding | :channel | :geometry | :style | :content
```

What a key is about (§1.3).

# `key_spec`

```elixir
@type key_spec() :: Macaw.Frame.Document.Schema.Spec.t()
```

One key of a node kind.

# `kind`

```elixir
@type kind() :: atom()
```

A node kind of the design map (§1.2).

# `type`

```elixir
@type type() :: atom() | tuple()
```

A type term of §1.4.

# `column_types`

```elixir
@spec column_types() :: [atom(), ...]
```

The six data-model types a slot's `types` may name, `field_types/0` (§13.2).

# `default`

```elixir
@spec default(term(), term()) :: term()
```

The default of a key: `nil` when it has none, is required, or is no key of the kind.

# `default`

```elixir
@spec default(term(), term(), term()) :: term()
```

The default of a key in a given node, where the node decides it: a label's `style` is
`"title"` at the `:title` anchor and `"label"` elsewhere (§6.1), a frame's `span` is
`[1, 1]` with a `cell` (§4.1); every other key's is `default/2`'s.

    iex> Macaw.Frame.Document.Schema.default(:label, :style, %{anchor: :title})
    "title"
    iex> Macaw.Frame.Document.Schema.default(:label, :style, %{anchor: :caption})
    "label"

# `describe`

```elixir
@spec describe(term()) :: [key_spec()] | {:error, [Macaw.Base.Fault.t(), ...]}
```

The key specs of a node kind, in the order of its table in spec/02;
`{:error, [{[], {:enum, kinds}}]}` for a term that is no kind.

# `enum_members`

```elixir
@spec enum_members() :: [atom(), ...]
```

Every member of every enumeration of the schema (§9.3).

# `facets`

```elixir
@spec facets() :: [facet(), ...]
```

The five facets of §1.3.

# `field_types`

```elixir
@spec field_types() :: [atom(), ...]
```

The six data-model types a slot's `types` may name (§2.3).

# `furniture`

```elixir
@spec furniture() :: [String.t(), ...]
```

The style names every design can name without declaring them (§3.3).

# `key`

```elixir
@spec key(term(), term()) :: key_spec() | nil
```

The spec of one key of a node kind, or `nil` when the kind has no such key.

# `key_names`

```elixir
@spec key_names() :: [atom(), ...]
```

Every atom key of every node kind, once each: the words a document's keys are read in (§9.3).

# `keys`

```elixir
@spec keys(term()) :: [{kind(), atom() | String.t()}]
```

Every `{kind, key}` pair carrying the facet, over every node kind in `kinds/0` order;
`[]` for a term that is no facet.

# `keys`

```elixir
@spec keys(term(), term()) :: [atom() | String.t()]
```

The keys of one node kind carrying the facet, in table order (§1.3); `[]` for a kind or
facet the schema does not have.

    iex> Macaw.Frame.Document.Schema.keys(:grid, :geometry)
    [:columns, :rows, :gap]

# `kinds`

```elixir
@spec kinds() :: [kind(), ...]
```

Every node kind of §1.2, `:design` first, level by level.

# `open?`

```elixir
@spec open?(term()) :: boolean()
```

Whether a node kind's keys are their owner's (§5.3, §5.4): a layer's `channels` and
`options` are its kind's, a step's keys its operation's.

# `parts`

```elixir
@spec parts() :: [atom(), ...]
```

A style's parts, the keys merged by §3.5's rule (§1.5).

# `scale_kinds`

```elixir
@spec scale_kinds() :: [atom(), ...]
```

The scale kinds of macaw_draw spec/06 a `:scale` node names (§4.3).

# `select`

```elixir
@spec select(term(), term()) :: type() | nil
```

The alternative of a `{:one_of, types}` whose shape a value has, or `nil` (§1.4): what
the validator judges the value as, and what canonicalization reads it by. A map is the
first node or name map admitted, a list the first list, a tagged tuple the type that
tags it.

    iex> Macaw.Frame.Document.Schema.select([:name, {:node, :theme}], %{name: "x"})
    {:node, :theme}
    iex> Macaw.Frame.Document.Schema.select([{:ref, :style}, :field_ref], {:field, "f"})
    :field_ref

# `style_entry`

```elixir
@spec style_entry() :: type()
```

The type a `styles` entry takes (§2.6).

# `style_sites`

```elixir
@spec style_sites() :: [{kind(), atom()}, ...]
```

Every style site of the schema (§3.6): each `{kind, key}` whose type is the style stack,
in `kinds/0` order, derived from the tables. A layer kind's own site (a choice's
`style`) is the kind's to declare.

    iex> Macaw.Frame.Document.Schema.style_sites()
    [layer: :style, label: :style, axis: :style, legend: :style, layer_label: :style]

# `style_stack`

```elixir
@spec style_stack() :: type()
```

The type a style site takes (§3.6): a reference, an inline node, a field binding, a
generator call, or a list of them.

---

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