# `Macaw.Definition.Static`
[🔗](https://github.com/dcoai/macaw/blob/v0.6.0/lib/macaw/definition/static.ex#L1)

A static source's map and JSON forms (spec/15 §3): an adapter at the edge, moved from
macaw_data (dco-tek/macaw/macaw#478 decision 2, #480), so a captured static source
travels in a bundle. The source is the term, `Macaw.Data.Source.Static`; what is read is
judged by its public parts, `Static.assemble/3` and `Static.judge/2`.

The form holds `"delivery"`, the stored answer: its rows as the columns they pack into
under the schema's types (`[name, type, values]` each, in the table's order), its served
facts, its origin and its schema's version; `"description"`, its schema in
`Macaw.Definition.Schema`'s map form beside its other facts; and `"captured"`.

Values are written as JSON holds them, and what it can't by a tag: a `DateTime` in
`Etc/UTC` `{"$time": iso}`, a `NaiveDateTime` `{"$naive": iso}`, a `Date`
`{"$date": iso}`, a `Duration` `{"$duration": iso}`, a point `{"$point": [x, y]}`. An
atom is written as its string, so a name or a category reads back as its string, as a
packed table reads it; a key that starts with `$` is written with a second. A value with
none of these forms (a time in another zone, a tuple, a function, a string that is not
UTF-8) is `{path, {:type, :term}}`. Each word of a closed vocabulary is read through its
table, so **no atom is made from a document**.

# `format_error`

```elixir
@spec format_error(term()) :: String.t()
```

A fault's words: a tag the form does not read is this module's, another reason the
kernel's gates give (a limit, a URL) macaw_layers' (`Macaw.Layers.Words`), every other
the static source's (`Macaw.Data.Source.Static.format_error/1`).

# `from_json`

```elixir
@spec from_json(term(), keyword()) ::
  {:ok, Macaw.Data.Source.Static.t()} | {:error, [Macaw.Base.Fault.t(), ...]}
```

The static source a JSON document holds: as `from_map/2`, its bytes and nesting held to
the limits before it is decoded.

# `from_json!`

```elixir
@spec from_json!(term(), keyword()) :: Macaw.Data.Source.Static.t()
```

As `from_json/2`, raising `ArgumentError` naming every fault.

# `from_map`

```elixir
@spec from_map(term(), keyword()) ::
  {:ok, Macaw.Data.Source.Static.t()} | {:error, [Macaw.Base.Fault.t(), ...]}
```

The static source a map form holds: through macaw_layers' gates
(`Macaw.Layers.Form.gates/3`: the depth and item limits, the version), `limits:`
tightening or raising them, then read making no atom and judged as
`Macaw.Data.Source.Static.capture/2` judges an answer: the rows packed as a
`Macaw.Data.Table` of the written types, the delivery by `Macaw.Data.Delivery.new/2`, the
description by `Macaw.Data.Source.Description.new/1`, its schema by
`Macaw.Definition.Schema.from_map/1`, all held together by
`Macaw.Data.Source.Static.assemble/3`. `{:ok, source}`, or every fault: a key the form
does not have is `{[key], :unknown_key}`, a missing one `{[key], :required}`, a tag it
does not read `{path, {:unknown_tag, tag}}`, a value of the wrong shape
`{path, {:type, type}}`, and a description supporting anything
`{[:description, :supports], :static}`.

`from_map(to_map(source))` is a source whose `to_map/1` is the same map, which fetched
answers the same rows, packed, and the same served facts in the form's terms.

# `from_map!`

```elixir
@spec from_map!(term(), keyword()) :: Macaw.Data.Source.Static.t()
```

As `from_map/2`, raising `ArgumentError` naming every fault.

# `to_json`

```elixir
@spec to_json(Macaw.Data.Source.Static.t()) ::
  {:ok, String.t()} | {:error, [Macaw.Base.Fault.t(), ...]}
```

The source's JSON form: `to_map/1`, stamped `"$version"` and encoded.

# `to_map`

```elixir
@spec to_map(Macaw.Data.Source.Static.t()) ::
  {:ok, map()} | {:error, [Macaw.Base.Fault.t(), ...]}
```

The source's map form, JSON-ready: `{:ok, map}`, or every value without a form, by
path.

---

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