# `Macaw.Layers.Limits`
[🔗](https://github.com/dcoai/macaw_layers/blob/v0.2.2/lib/macaw/layers/limits.ex#L1)

Sanity limits on a document read from elsewhere (spec/01 §5).

| Limit | Default | Bounds |
|---|---|---|
| `bytes` | `8_000_000` | the encoded document's size |
| `depth` | `64` | how deeply objects and arrays nest; the document itself is depth 1 |
| `items` | `100_000` | the entries any one object or array holds |

They bound what reading a document can be made to cost. **A host may tighten every
limit,** never loosen one: a host loading untrusted input knows its inputs and lowers the
numbers at its layer, and a limit it does not name keeps its default.

A fault is `{path, {:limit, name, max, given}}`, worded by `Macaw.Layers.Fault.format/2`.

The walk over a decoded term is the generic part of visualize's
`Visualize.Chart.Limits.structure/2`.

# `name`

```elixir
@type name() :: :bytes | :depth | :items
```

A limit's name.

# `t`

```elixir
@type t() :: %{required(name()) =&gt; pos_integer()}
```

The limits a reader applies, one positive integer per name.

# `defaults`

```elixir
@spec defaults() :: t()
```

The system's sanity values.

# `new`

```elixir
@spec new(keyword() | map()) :: t()
```

The limits a reader applies: `given` over `defaults/0`.

Raises `ArgumentError` for a name that is not a limit, a value that is not a positive
integer, or one above the default: a host can't loosen a sanity limit by mistake.

    iex> Macaw.Layers.Limits.new(items: 10).items
    10

# `structure`

```elixir
@spec structure(term(), t()) :: [Macaw.Layers.Fault.t()]
```

Every `depth` and `items` fault of a decoded term, ordered by path.

The term itself is depth 1. A struct is a leaf. Past the depth limit a branch is reported
once, at the first map or list beyond it, and not walked further. A map or list over the
items limit is reported at its own path, with the number of entries it holds.

---

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