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

Provisional: moved here from the Call step for plugins that pass inputs on,
and a change to it needs a changelog line but no new major
(`docs/USER_PLUGINS_DESIGN.md`). The namespace has nothing to do with the
context's `:provisional?` key.

Named inputs a step passes on: to a pipeline it calls (a Call or For each
step), to a script, to a plugin's own processes. Stored as a list, each
named, with a `value` template or a `from` location resolved in the
exchange the step runs in:

    [%{"name" => "item_number", "value" => "${path.id}"},
     %{"name" => "who", "from" => %{"in" => "request_headers", "name" => "X-User"}}]

A `value` is text. A JSON boolean or number is taken as its text
(`value_text/1`): a parameter of type boolean or number converts that
text when the call runs, as it converts any other.

A row may carry `"omit_empty": true`: a value that resolves or reads as `""`
is then not passed. Without it an empty text is a value. A `from` location
that reads nothing is always left out.

A step parses them in `init/1` (`parse/2`), lists the value templates for
the save's check (`exchange_templates/1`), and when it runs resolves them
(`resolve/2`), bounds them (`check_size/2`) and reads the bodies a `from`
location gave as handles (`read_bodies/1`). Names follow `Plugin.Input.name?/1`.

# `input`

```elixir
@type input() ::
  %{name: String.t(), value: String.t(), omit_empty: boolean()}
  | %{
      name: String.t(),
      from: Alternera.Plugin.Location.t(),
      omit_empty: boolean()
    }
```

A parsed input: its name and a template, or a location to read.

# `check_size`

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

`:ok` when every resolved input holds at most `max_bytes` (a string by its
bytes, a body handle by its length, any other value as JSON, as a variable
is measured), else `{:error, message}` naming the first that holds more: a
`from` location can read a whole body.

# `exchange_templates`

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

The value templates of stored `inputs`, labelled as a refusal of the row is
(`input N`), for the plugin's `exchange_templates/1`.

# `max_inputs`

```elixir
@spec max_inputs() :: pos_integer()
```

The most inputs one step passes.

# `parse`

```elixir
@spec parse(term(), :request | :response | :answer) ::
  {:ok, [input()]} | {:error, String.t()}
```

Parses a step's stored `inputs` (nil is none): `{:ok, inputs}` or
`{:error, message}`. A `from` location must be one a step of `direction`
may read (`Location.allowed/3`).

# `read_bodies`

```elixir
@spec read_bodies(map()) :: {:ok, map()} | {:error, String.t()}
```

The inputs with every body handle a `from` location gave read into its
bytes: `{:ok, inputs}`, or `{:error, message}` when a body in a file cannot
be read (logged). Run after `check_size/2`, which bounds what is read.

# `resolve`

```elixir
@spec resolve([input()], Alternera.Plugin.Location.view()) ::
  {:ok, map()} | {:error, String.t()}
```

The inputs resolved against `view`: `{:ok, %{name => value}}`, a missing
`from` left out, and an empty value left out of a row marked `omit_empty`,
or `{:error, message}` when a location cannot be read. A body a `from`
location reads may come as a handle (`Plugin.Body`). A template that does not
resolve raises `Plugin.UnresolvedVariableError`, as a step's own templates do.

# `value_text`

```elixir
@spec value_text(term()) :: {:ok, String.t()} | :error
```

A stored `value` as the text it stands for: `{:ok, text}` for a text, and
for a JSON boolean or number its text (`false` is `"false"`, `3` is
`"3"`), which the called pipeline converts to its parameter's type as it
does any text; `:error` for anything else.

---

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