Macaw.Layers.Limits (macaw_layers v0.2.2)

Copy Markdown View Source

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

LimitDefaultBounds
bytes8_000_000the encoded document's size
depth64how deeply objects and arrays nest; the document itself is depth 1
items100_000the 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.

Summary

Types

A limit's name.

t()

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

Functions

The system's sanity values.

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

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

Types

name()

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

A limit's name.

t()

@type t() :: %{required(name()) => pos_integer()}

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

Functions

defaults()

@spec defaults() :: t()

The system's sanity values.

new(given)

@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(term, limits)

@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.