Alternera.Plugin.Provisional.Store (alternera_plugin_sdk v0.9.0)

Copy Markdown View Source

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.

Summary

Functions

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

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

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

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.

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

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

Whether the tenant marked store name secret.

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

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?.

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

Types

error()

@type error() :: atom()

mode()

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

Functions

delete(tenant, name, key, opts \\ [])

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

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

entries(tenant, name, opts \\ [])

@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(tenant, name, key)

@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(context, target, inputs, opts \\ [])

@spec invalidate(map(), term(), %{required(String.t()) => 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?(value)

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

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

put(tenant, name, key, value, opts \\ [])

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

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

secret?(tenant, name)

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

Whether the tenant marked store name secret.

secret_mark()

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

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

update(tenant, name, key, mode, opts \\ [])

@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?(name)

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

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