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

Running the layers' steps (spec/04 §7.3, spec/05 §5.2): each layer's steps are one list,
data and spatial steps in any order, validated together by
`Macaw.Data.Operations.validate/3` against the Frame's operations registry with the
frame's context, and run in order through `Macaw.Data.Operations`: a column-native step
through the held `Macaw.Data.Operations.Cache`, so a delivery of a chunked table re-runs
only the chunks that changed, any other by its `run/3`.

**A plain value the Frame holds** (`t:t/0`), passed back each time, with no process,
ETS or clock. `new/1` makes one from the registry; `run/3` runs every layer and answers
each layer's table, or its faults, with the value to hold next:

    pipeline = Pipeline.new(registry)
    {[{:ok, table}], pipeline} = Pipeline.run(pipeline, [%{steps: steps, table: slot}], context)

The context is the model's `context/1` (spec/03): `frame: %{width, height, center}`,
`projection` and `prepared` where the model has them, with `now`, `schema` and `sources`
as the Frame gives them. A layer's own `context:` (its slot's `schema`) is merged over it.

- **Once per delivery.** A step's result is held under its key: the key of what it
  reads (its input table's chunks by version, or the step before it), the step's
  identity (`Macaw.Data.Operations.step_digest/2` of the checked node, a frame-bound
  `"plot"` already the width), and the parts of the context the step reads: its
  `needs/0` (`frame`, `projection`) and the keys its `reads/0` names (`now`, `schema`,
  `scale`, `level`, `sources`). So a second run over one delivery runs no step, a resize
  re-runs only the steps that read the frame and what follows them, and a render never
  runs one: `now` is the context's, never a clock read.
- **Shared prefixes.** Two layers whose step lists are identical up to some step have
  one key up to it, so the prefix runs once: two layers over `stack(fields)` of one slot
  run the stack once.
- **Prepared once.** A step with `prepare/3` (the `force` layout) is prepared once per
  graph, under its `key/1` where it has one (the node without `output`), so every layer
  reading one graph reads one layout, and the next delivery's preparation is given the
  last as `warm`.
- **Faults are values.** A step's fault stops its own layer, answered as
  `{:error, faults}` at `[:layers, i, :data, :steps, j | key]`; every other layer's
  table is answered.

`last/1` says what the last run did: the steps it ran and the steps it reused.

# `answer`

```elixir
@type answer() :: {:ok, Macaw.Data.Table.t()} | {:error, [{list(), term()}, ...]}
```

A layer's answer: its table after every step, or its faults at its path.

# `layer`

```elixir
@type layer() :: %{
  :steps =&gt; [map()],
  :table =&gt; Macaw.Data.Table.t(),
  optional(:context) =&gt; map()
}
```

A layer's steps and the table of its slot, with its own context.

# `t`

```elixir
@type t() :: %Macaw.Frame.Pipeline{
  cache: Macaw.Data.Operations.Cache.t(),
  checked: %{required(term()) =&gt; {:ok, [map()]} | {:error, list()}},
  last: %{ran: non_neg_integer(), reused: non_neg_integer()},
  memo: %{
    required(term()) =&gt; {:ok, Macaw.Data.Table.t()} | {:error, {term(), term()}}
  },
  prepared: %{required(term()) =&gt; term()},
  registry: Macaw.Data.Operations.Registry.t()
}
```

The value the Frame holds from delivery to delivery.

# `check`

```elixir
@spec check(t(), [map()], map()) :: t()
```

The pipeline with every layer's steps checked in `context` and held (spec/05 §5.2): what
`run/3` would check first, done once when the value is made, so a delivery under the
same context runs no check. Each layer is `%{steps, context}`; a table is not read.

# `last`

```elixir
@spec last(t()) :: %{ran: non_neg_integer(), reused: non_neg_integer()}
```

What the last `run/3` did: `%{ran: steps run, reused: steps whose result was held}`.

# `new`

```elixir
@spec new(Macaw.Data.Operations.Registry.t()) ::
  t() | {:error, [{list(), term()}, ...]}
```

A pipeline over the operations `registry` (`Macaw.Frame.Layers.operations/1`).

# `run`

```elixir
@spec run(t(), [layer()], map()) ::
  {[answer()], t()} | {:error, [{list(), term()}, ...]}
```

Every layer's steps run over its table with `context` (spec/04 §7.3): `{answers,
pipeline}`, one answer per layer in order, and the value to hold for the next run, which
keeps only what this run read.

# `running?`

```elixir
@spec running?(t()) :: boolean()
```

Whether a prepared layout of the last run is still settling (spec/01 §3.6): a force
simulation `Macaw.Draw.Layout.Force.running?/1` holds for.

# `tick`

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

One step of every running layout (spec/01 §3.6): each prepared simulation that is still
`running?/1` steps once, held as the preparation of its graph, and every step result is
let go so the next `run/3` draws from the stepped positions; a settled simulation and
every chunk part of the cache are kept. A pipeline with nothing running answers itself.

---

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