# `Alternera.Plugin.StepOutputs`
[🔗](https://github.com/10e-ab/alternera-sdk/blob/v0.9.0/alternera_plugin_sdk/lib/alternera/plugin/step_outputs.ex#L1)

The values a step leaves in the exchange under its id, for later steps
of the same pipeline to read (spec 056 S2): a Request's `body`, `status`
and `headers`, a Script's returned `body` and its named `outputs`, a
Transform's or a Map's `body`, a Validate's `valid` and `errors`, a pivot's
returned `status` and `headers`.

The exchange holds them as `ex.steps`, a map of scope to step id to
values (`t:values/0`, output name to value). The scope is
`{pipeline_id, call_scope}` (`scope_key/2`): a pipeline's own steps read
their outputs, never another pipeline's, and a called pipeline's steps
read theirs apart from their caller's. Variables remain the way to share
a value between pipelines.

A later step reads one by a location (`{"in": "steps", "id": …,
"output": …}`, `Plugin.Location`), a template (`${steps.<id>.<output>}`,
`template_refs/1`), a `step` condition (`Pipelines.Matcher`) or a
script's `steps` table (`Plugins.Script.Lua`). `fetch/3` is the one read
all of them share: an output's value, then a key or a JSON path inside
it. The first segment below `headers` is a header name, matched in any
case (the values are stored with lower-case names); below any other
output the segments walk the value, text read as JSON first
(`JsonPath.dig/2`).

The runner keeps a step's `body` and `outputs` only when a later step
reads them (`Runner.prepare/2` collects the references, `refs/1`); its
other outputs always, since they are small. Each value is held up to the
variable cap (`Plugin.Location`'s `var_bytes`): past it the step fails
with `step_output_too_large` (`check_size/3`).

# `refs`

```elixir
@type refs() :: %{required(String.t()) =&gt; :all | MapSet.t(String.t())} | :all
```

What a pipeline's steps read of each other: step id to the outputs read
(`:all` when a reader cannot be followed, a script reaching `steps` by a
computed name), and `:all` for the whole map when such a reader may reach
any step.

# `scope`

```elixir
@type scope() :: %{required(String.t()) =&gt; values()}
```

A scope's outputs: step id to values.

# `scope_key`

```elixir
@type scope_key() :: {String.t() | nil, String.t()}
```

Whose outputs: the pipeline and the call it runs in.

# `site`

```elixir
@type site() :: %{
  path: [term()],
  id: String.t(),
  output: String.t() | nil,
  key: String.t() | nil,
  form: :location | :condition | :template
}
```

A place a term names a step: the path to it from the term's root (map keys
and list positions), the step id, the output (nil where the place names the
step alone), the key it reads of a keyed output (a location's or a
condition's `key`, a template's segment after the output; nil for none)
and its form: a `{"in": "steps"}` `:location` or a `step`
`:condition` (the path leads to the map), or a `${steps.…}` `:template` (the
path leads to the text, one site per template in it).

# `values`

```elixir
@type values() :: %{required(String.t()) =&gt; term()}
```

One step's outputs: output name to value.

# `check_size`

```elixir
@spec check_size(values(), String.t(), pos_integer()) :: :ok | {:error, String.t()}
```

`:ok` when every value holds at most `max_bytes` (as JSON; text, and a
body handle the runner has not read, by its bytes), else
`{:error, message}` naming the step and the output.

# `fetch`

```elixir
@spec fetch(scope() | nil, {String.t(), String.t()}, [String.t()]) ::
  {:ok, term()} | :error
```

The value of step `id`'s `output`, at `segments` inside it (see the
module doc): `{:ok, value}`, or `:error` when the step did not run, kept
no such output, or the segments lead nowhere.

# `kept`

```elixir
@spec kept(values() | nil, :all | [String.t()] | nil) :: values()
```

The values a step keeps of what it returned (`extras.values`): its
`body` and `outputs` only when `kept` names them (`:all`, or the output
names a later step reads), the rest always.

# `read_of`

```elixir
@spec read_of(refs(), String.t() | nil) :: :all | [String.t()] | nil
```

What of step `id`'s outputs is read (`refs/1`), for `kept/2`: `:all`,
the output names sorted, or nil for none. Plain data: a prepared step
carries it, and a compile embeds it.

# `reads?`

```elixir
@spec reads?(:all | [String.t()] | nil, String.t()) :: boolean()
```

Whether `read_of/2`'s answer reads `output`.

# `refs`

```elixir
@spec refs([{String.t(), String.t() | nil}] | :all) :: refs()
```

The references as `t:refs/0`: `pairs` of `{id, output}` (`nil` for any
output), or `:all` among them for a reader that may reach any step.

# `scope_key`

```elixir
@spec scope_key(String.t() | nil, String.t()) :: scope_key()
```

The key of the outputs of `pipeline_id`'s steps in `call_scope`.

# `script_refs`

```elixir
@spec script_refs(map() | nil) :: {:ok, [{String.t(), String.t() | nil}]} | :unknown
```

The step outputs a script reads, from its `Script.Reads` analysis:
`{:ok, pairs}` (an output of `nil` is any output of that step), or
`:unknown` when it may reach any step.

# `settings_refs`

```elixir
@spec settings_refs(term()) :: [{String.t(), String.t()}]
```

The step outputs a stored step reads in its `settings` and a container's
conditions: `{"in": "steps"}` locations at any depth, `${steps.…}`
templates in any string, `step` conditions. A Script's source is read by
`Script.Reads` (`script_refs/1`), not here. The `{id, output}` pairs of
`sites/2` that name an output.

# `sites`

```elixir
@spec sites(term(), [term()]) :: [site()]
```

Every place `term` names a step (`t:site/0`), depth first, each map before
what it holds; `base` is put in front of every path. A location or a
condition without an output, and a `${steps.<id>}` template, name the step
alone. What `settings_refs/1` reads, and what a step's rename rewrites.

# `template`

```elixir
@spec template() :: Regex.t()
```

The template that reads a step output, for `HttpUtils`.

# `template_refs`

```elixir
@spec template_refs(String.t()) :: [{String.t(), String.t()}]
```

The `{id, output}` pairs the `${steps.…}` templates in `text` read.

# `text_refs`

```elixir
@spec text_refs(String.t()) :: [{String.t(), String.t() | nil}]
```

The `{id, output}` pairs the step templates in `text` name, in order: an
output of nil for `${steps.<id>}`, which names the step alone.

---

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