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

Provisional: added for Script, 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.

The tenant's named key-value stores, through `Alternera.Plugin.Host`.
`tenant` is the context's `:store_tenant`. Under `dry_run?: true`, the
context's `:dry_run?`, a write answers what it would have and writes nothing.

A name the proxy does not accept is `{:error, :store_invalid_name}`, and a
write to a key that holds a cache entry `{:error, :store_reserved_key}`.

A store the tenant marked secret (`secret?/2`) holds values the recording
must never show. A step that hands one on says so in its summary:
`secret_outputs: true` records its `value` output as a placeholder, and
`header_vars`, a map of each variable it wrote the value to and
`secret_mark/0`, records those variables the same way.

A cache container keeps its entries in a store of its own, which a step
reaches only through `invalidate/4`: the host gives a step whose options
hold `operation: :invalidate` and `cache: id` the container's target as
`:cache_target` when it prepares the pipeline, and `invalidate/4` makes
the container's key on the exchange and removes its entries.

# `error`

```elixir
@type error() :: atom()
```

# `mode`

```elixir
@type mode() :: {:replace, term()} | {:increment, number()} | {:merge, map()}
```

# `delete`

```elixir
@spec delete(String.t(), String.t(), String.t(), keyword()) ::
  {:ok, boolean()} | {:error, error()}
```

Deletes `key`, answering whether it held one. Takes `:dry_run?`.

# `entries`

```elixir
@spec entries(String.t(), String.t(), keyword()) ::
  {:ok, [%{key: String.t(), value: term(), age_s: non_neg_integer()}],
   %{truncated: boolean()}}
  | {:error, error()}
```

The entries of a store. Takes `:prefix` and `:limit`.

# `get`

```elixir
@spec get(String.t(), String.t(), String.t()) ::
  {:ok, %{value: term(), bytes: non_neg_integer(), age_s: non_neg_integer()}}
  | :miss
  | {:error, error()}
```

The entry of `key` (its value, its size and its age in seconds), or `:miss`.

# `invalidate`

```elixir
@spec invalidate(map(), term(), %{required(String.t()) =&gt; String.t()}, keyword()) ::
  {:ok, %{deleted: boolean(), key: String.t()}}
  | :unresolved
  | {:error, error()}
```

Removes the entries cache container `cache` keeps under the key it would
make on this exchange, `inputs` (key placeholder to value) in place of
what the exchange has. `target` is the step's `:cache_target`; `context`
is the step's, whose view, tenant and store scope the host reads.
Answers whether it removed any and the key as the step may show it
(`"[secret]"` for a secret store's), `{:error, :store_no_cache}` for a
target the host did not make, or `:unresolved` when the key does
not resolve on this exchange. Takes `:cache` (the container's id) and
`:dry_run?`, which answers whether an entry is there and removes none.

# `plain?`

```elixir
@spec plain?(term()) :: boolean()
```

Whether a store can hold `value` as it is: text, numbers, booleans, nil, lists and objects of them.

# `put`

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

Writes `key`. Takes `:ttl`, `:if_absent` and `:dry_run?`.

# `secret?`

```elixir
@spec secret?(String.t(), String.t()) :: boolean()
```

Whether the tenant marked store `name` secret.

# `secret_mark`

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

The mark `header_vars` puts on a variable written from a secret store.

# `update`

```elixir
@spec update(String.t(), String.t(), String.t(), mode(), keyword()) ::
  {:ok, term(), %{created: boolean()}} | {:error, error()}
```

Changes `key` by `mode`, answering the value it holds now and whether the
change created it. Takes `:ttl`, `:create_if_missing`, `:initial` and
`:dry_run?`.

# `valid_name?`

```elixir
@spec valid_name?(term()) :: boolean()
```

Whether the proxy accepts `name` as a store's name.

---

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