# `Alternera.Plugin.Provisional.Analysis`
[🔗](https://github.com/10e-ab/alternera-sdk/blob/v0.9.0/alternera_plugin_sdk/lib/alternera/plugin/provisional/analysis.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.

What a plugin whose settings hold a program tells the proxy about it, from the
stored settings and without running it. Every callback is optional. A plugin
that exports none is read by its settings alone.

# `opener`

```elixir
@type opener() :: %{
  :close_does =&gt; String.t(),
  :refusal_status =&gt; String.t() | nil,
  :holds =&gt; String.t(),
  optional(:lands) =&gt; String.t(),
  optional(:rank) =&gt; non_neg_integer()
}
```

What a plugin whose step opens the rest of the exchange in Before says
about it (`c:exchange_opener/0`); such a step needs an id and a Close in
After that names it (`Pipelines.Constructs.Close`), and the proxy keeps the two paired
while a pipeline is edited.

  * `:close_does`: what the Close does at its place, completing "Close
    <id>: ..." (`"gives the turn back"`);
  * `:refusal_status`: the status a refusal answers with when the step
    skips to After instead of failing (`"429"`), nil for a step that
    refuses nothing;
  * `:holds`: one sentence on what the step holds until its Close
    (`"Holds until its Close in After."`);
  * `:lands`: optional, one sentence on what always skips to the Close
    whatever the step's `on_refusal` (`"Hits skip to here: ..."`);
  * `:rank`: optional, where the step belongs among the openers in
    Before: one that stands after an opener of a higher rank is warned
    about, since what it ends early still goes through the other first.
    An opener without a rank is not ordered.

# `part`

```elixir
@type part() ::
  :url
  | :request_headers
  | :request_body
  | :response_headers
  | :response_body
  | :variables
```

A part of the exchange a step can write: the URL (path and query), either
side's headers or body, or the pipeline's variables.

# `reads`

```elixir
@type reads() :: %{
  :fields =&gt; [String.t()],
  :unknown =&gt; boolean(),
  optional(:steps_unknown) =&gt; true
}
```

What a step reads: `:fields` lists `"req.body"`, `"res.headers"`, `"vars"`,
`"steps.<id>.<output>"`, `"input.<name>"`, `"context.<name>"` and `"context"`
for the whole table. `:unknown` says it may read anything of the exchange, and
`:steps_unknown` any step's output.

# `exchange_opener`
*optional* 

```elixir
@callback exchange_opener() :: opener() | nil
```

Whether the plugin's step opens the rest of the exchange in Before and is
closed by a Close in After (`t:opener/0`), or nil. Read without settings:
it is the plugin's, not a step's.

# `output_renames`
*optional* 

```elixir
@callback output_renames(before :: map(), later :: map()) :: [
  {String.t(), String.t(), String.t()}
]
```

The keys of keyed outputs a change of a step's settings from `before` to
`later` renames, as `{output, old_key, new_key}`: what the plugin's own
declaration of its keys says was renamed, never a guess from its text.
The proxy then takes what reads the old key along. `[]` for none.

# `own_heap?`
*optional* 

```elixir
@callback own_heap?() :: boolean()
```

Whether the plugin limits its own heap, so the runner does not limit the step's.

# `pipelines_called`
*optional* 

```elixir
@callback pipelines_called(settings :: map()) :: [String.t()]
```

The pipelines the step calls by a name its settings show, for cycle checks and
callers. A list, even empty, says the step can call pipelines with inputs the
proxy cannot read.

# `produces_response?`
*optional* 

```elixir
@callback produces_response?(settings :: map()) :: boolean()
```

Whether a step with these settings makes the response in an Implementation
of own steps: one that answers (Respond, Fail), or one whose To rows write
the response (`rows_write_response?/1`). An Implementation with no such
step fails `no_response`, and the editor warns at save. A plugin without
this callback makes no response.

# `rename`
*optional* 

```elixir
@callback rename(
  settings :: map(),
  kind :: atom() | tuple(),
  old :: String.t(),
  new :: String.t()
) ::
  {:ok, map()} | :unknown
```

`settings` with the plugin's own text pointing at `new` wherever it names
`old`, a name of `kind` (`:step`, `:var`, `:context`, `:input`, `:inner`
or `:store`; for a key of a keyed step output, `{:step_output, step_id,
output}` where another step reads it and `{:own_output, output}` in the
step that gives it, its own text and its declaration): the references
`step_reads/1` and `stores/1` report, which the proxy cannot rewrite
itself because it does not know the plugin's language. `:unknown` when the plugin cannot say that
the rewrite moves exactly those references and nothing else; the proxy then
leaves the settings as they are. The proxy rewrites the settings' locations,
conditions and templates itself: a plugin rewrites only what it alone reads.

# `secret_references?`
*optional* 

```elixir
@callback secret_references?(settings :: map()) :: boolean()
```

Whether the step may write a tenant secret into what it writes.

# `shared_names`
*optional* 

```elixir
@callback shared_names(settings :: map()) :: [String.t()]
```

The names under which a step with these settings shares its state with
other steps across the tenant's pipelines, `[]` for none: two steps of
the plugin that give the same name share one state (a Throttle's turns,
a Circuit breaker's circuit), so a misspelt name silently splits it. The
pipeline editor gathers the names in use and hands a step editor those
of its own plugin (`shared_names` in `Alternera.Plugin.Editor`'s
props) to suggest. A plugin without this callback shares nothing by name.

# `step_reads`
*optional* 

```elixir
@callback step_reads(settings :: map()) :: reads() | nil
```

What a step with these settings reads, or nil when it holds nothing to analyse.

# `stores`
*optional* 

```elixir
@callback stores(settings :: map()) :: {[String.t()], [String.t()]}
```

The named stores the step reads and writes: `{reads, writes}`.

# `tenant_vars_unseen?`
*optional* 

```elixir
@callback tenant_vars_unseen?(settings :: map()) :: boolean()
```

Whether the step may read tenant variables by a name its settings do not
show as a template (a script's `tenant.var(name)` with a name built while
it runs): a release's manifest of the variables it needs cannot list
those, and says the step may read others.

# `warnings`
*optional* 

```elixir
@callback warnings(settings :: map()) :: [String.t()]
```

What the plugin finds questionable in a step with `settings`, each a
sentence without the step's name (the proxy prefixes it): a save with
warnings goes through, and the warnings are reported with it. `[]` for
none.

# `writes`
*optional* 

```elixir
@callback writes(settings :: map(), direction :: String.t() | nil) :: [part()]
```

Every part of the exchange a step with these settings can write, in
`direction` (`"request"`, `"response"`, `"answer"`, or nil for a step that
may run on either side). A superset is safe: the proxy scans the parts named
for stamped secret references once one is in the exchange, so a part
missed would let a reference reach the recording unresolved. A plugin
without this callback is taken to write every part of its direction and the
variables. `target_parts/1` gives the parts the step's To rows write.

# `location_part`

```elixir
@spec location_part(String.t()) :: part() | nil
```

The part a location of kind `in` (`Plugin.Location`, as stored: `"vars"`,
`"response_body"`) writes, or nil for one that writes no part (a status,
the error, a step output, an input, a path parameter).

# `parts`

```elixir
@spec parts() :: [part()]
```

Every part (`t:part/0`).

# `rows_write_response?`

```elixir
@spec rows_write_response?(map()) :: boolean()
```

Whether a step's To rows (`"targets"`, and a single `"target"` beside them)
write the response's body, status or headers, for a `produces_response?/1`
answer.

# `target_parts`

```elixir
@spec target_parts(map()) :: [part()]
```

The parts a step's To rows (`"targets"`, `Plugin.Targets`) write, each once,
for a `writes/2` answer.

---

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