# `Alternera.PluginWasmFramework.Uses`
[🔗](https://github.com/10e-ab/alternera-wasm/blob/v0.9.0/alternera_plugin_wasm_framework/lib/alternera/plugin_wasm_framework/uses.ex#L1)

The named parameters an uploaded module declares, and how a step's
bindings turn them into the tenant's own stores, pipelines, variables
and secrets.

A module declares what it reaches in one custom section,
`alternera.uses`, holding UTF-8 JSON:

    {"stores": {"sessions": ["get", "put"]},
     "pipelines": ["enrich"],
     "variables": ["region"],
     "secrets": ["api_key"]}

Every key is optional. A store parameter names the operations the
module uses on it (`get`, `put`, `update`, `delete`, `list`); a
pipeline, variable or secret parameter is a name alone. A parameter
name is 1 to 64 characters of letters, digits, `_`, `.` and `-`.

The guest calls a host operation with its own parameter name
(`store.get` with `["sessions", key]`); the step's settings bind each
parameter to a real name (`"bindings"`, `bindings/1`), and the host
translates the call (`translate/3`) and refuses one the declaration
does not cover. The binding is the grant: a module reaches exactly the
stores, pipelines, variables and secrets its step names. `log` is
always allowed and is no parameter.

The declaration is read from the module's bytes when the module is
prepared and kept with the compiled module, so what is enforced is
bound to the digest that runs. A module with no section declares
nothing and may only `log`. Shipped languages have no declaration
(`nil`): their scripts call by real name.

# `bindings`

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

A step's bindings: for each kind, parameter name to real name.

# `t`

```elixir
@type t() :: %Alternera.PluginWasmFramework.Uses{
  pipelines: [String.t()],
  secrets: [String.t()],
  stores: %{required(String.t()) =&gt; [String.t()]},
  variables: [String.t()]
}
```

A declaration: each store parameter with the operations used on it,
and the pipeline, variable and secret parameters.

# `bindings`

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

Reads a step's `bindings` setting: for each kind, a map of parameter
name to a real name. Nil is no bindings.

# `check_bindings`

```elixir
@spec check_bindings(t(), bindings()) :: [String.t()]
```

Checks bindings against a declaration: every declared parameter
bound, none bound that is not declared. Answers the problems, each
naming the parameter.

# `empty?`

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

Whether the declaration names nothing.

# `kinds`

```elixir
@spec kinds() :: [String.t()]
```

The kinds, as the settings and the section name them.

# `label`

```elixir
@spec label(atom()) :: String.t()
```

A kind's label in a message (`Store`).

# `params`

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

The declaration's parameters, kind by kind, each as `{name, ops}` (ops
nil for a kind with none): what the step editor lists.

# `parse`

```elixir
@spec parse([binary()]) :: {:ok, t()} | {:error, String.t()}
```

Reads a module's declaration from its custom sections' contents (none,
or exactly one): an empty declaration when there is none.

# `section`

```elixir
@spec section() :: String.t()
```

The section's name.

# `to_map`

```elixir
@spec to_map(t()) :: map()
```

The declaration as the JSON-ready map a step's display keeps.

# `translate`

```elixir
@spec translate(String.t(), list(), {t(), bindings()}) ::
  {:ok, list()} | {:error, String.t(), String.t()}
```

Translates a host call's arguments through the declaration and the
bindings: the parameter name in the first argument becomes the bound
name. `log` passes untouched; an operation outside the declaration is
refused with a message for the guest.

---

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