Alternera.Plugin.StepOutputs (alternera_plugin_sdk v0.9.0)

Copy Markdown View Source

The values a step leaves in the exchange under its id, for later steps of the same pipeline to read (spec 056 S2): a Request's body, status and headers, a Script's returned body and its named outputs, a Transform's or a Map's body, a Validate's valid and errors, a pivot's returned status and headers.

The exchange holds them as ex.steps, a map of scope to step id to values (values/0, output name to value). The scope is {pipeline_id, call_scope} (scope_key/2): a pipeline's own steps read their outputs, never another pipeline's, and a called pipeline's steps read theirs apart from their caller's. Variables remain the way to share a value between pipelines.

A later step reads one by a location ({"in": "steps", "id": …, "output": …}, Plugin.Location), a template (${steps.<id>.<output>}, template_refs/1), a step condition (Pipelines.Matcher) or a script's steps table (Plugins.Script.Lua). fetch/3 is the one read all of them share: an output's value, then a key or a JSON path inside it. The first segment below headers is a header name, matched in any case (the values are stored with lower-case names); below any other output the segments walk the value, text read as JSON first (JsonPath.dig/2).

The runner keeps a step's body and outputs only when a later step reads them (Runner.prepare/2 collects the references, refs/1); its other outputs always, since they are small. Each value is held up to the variable cap (Plugin.Location's var_bytes): past it the step fails with step_output_too_large (check_size/3).

Summary

Types

What a pipeline's steps read of each other: step id to the outputs read (:all when a reader cannot be followed, a script reaching steps by a computed name), and :all for the whole map when such a reader may reach any step.

A scope's outputs: step id to values.

Whose outputs: the pipeline and the call it runs in.

A place a term names a step: the path to it from the term's root (map keys and list positions), the step id, the output (nil where the place names the step alone), the key it reads of a keyed output (a location's or a condition's key, a template's segment after the output; nil for none) and its form: a {"in": "steps"} :location or a step :condition (the path leads to the map), or a ${steps.…} :template (the path leads to the text, one site per template in it).

One step's outputs: output name to value.

Functions

:ok when every value holds at most max_bytes (as JSON; text, and a body handle the runner has not read, by its bytes), else {:error, message} naming the step and the output.

The value of step id's output, at segments inside it (see the module doc): {:ok, value}, or :error when the step did not run, kept no such output, or the segments lead nowhere.

The values a step keeps of what it returned (extras.values): its body and outputs only when kept names them (:all, or the output names a later step reads), the rest always.

What of step id's outputs is read (refs/1), for kept/2: :all, the output names sorted, or nil for none. Plain data: a prepared step carries it, and a compile embeds it.

Whether read_of/2's answer reads output.

The references as refs/0: pairs of {id, output} (nil for any output), or :all among them for a reader that may reach any step.

The key of the outputs of pipeline_id's steps in call_scope.

The step outputs a script reads, from its Script.Reads analysis: {:ok, pairs} (an output of nil is any output of that step), or :unknown when it may reach any step.

The step outputs a stored step reads in its settings and a container's conditions: {"in": "steps"} locations at any depth, ${steps.…} templates in any string, step conditions. A Script's source is read by Script.Reads (script_refs/1), not here. The {id, output} pairs of sites/2 that name an output.

Every place term names a step (site/0), depth first, each map before what it holds; base is put in front of every path. A location or a condition without an output, and a ${steps.<id>} template, name the step alone. What settings_refs/1 reads, and what a step's rename rewrites.

The template that reads a step output, for HttpUtils.

The {id, output} pairs the ${steps.…} templates in text read.

The {id, output} pairs the step templates in text name, in order: an output of nil for ${steps.<id>}, which names the step alone.

Types

refs()

@type refs() :: %{required(String.t()) => :all | MapSet.t(String.t())} | :all

What a pipeline's steps read of each other: step id to the outputs read (:all when a reader cannot be followed, a script reaching steps by a computed name), and :all for the whole map when such a reader may reach any step.

scope()

@type scope() :: %{required(String.t()) => values()}

A scope's outputs: step id to values.

scope_key()

@type scope_key() :: {String.t() | nil, String.t()}

Whose outputs: the pipeline and the call it runs in.

site()

@type site() :: %{
  path: [term()],
  id: String.t(),
  output: String.t() | nil,
  key: String.t() | nil,
  form: :location | :condition | :template
}

A place a term names a step: the path to it from the term's root (map keys and list positions), the step id, the output (nil where the place names the step alone), the key it reads of a keyed output (a location's or a condition's key, a template's segment after the output; nil for none) and its form: a {"in": "steps"} :location or a step :condition (the path leads to the map), or a ${steps.…} :template (the path leads to the text, one site per template in it).

values()

@type values() :: %{required(String.t()) => term()}

One step's outputs: output name to value.

Functions

check_size(values, step_id, max_bytes)

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

:ok when every value holds at most max_bytes (as JSON; text, and a body handle the runner has not read, by its bytes), else {:error, message} naming the step and the output.

fetch(scope, arg2, segments)

@spec fetch(scope() | nil, {String.t(), String.t()}, [String.t()]) ::
  {:ok, term()} | :error

The value of step id's output, at segments inside it (see the module doc): {:ok, value}, or :error when the step did not run, kept no such output, or the segments lead nowhere.

kept(values, kept)

@spec kept(values() | nil, :all | [String.t()] | nil) :: values()

The values a step keeps of what it returned (extras.values): its body and outputs only when kept names them (:all, or the output names a later step reads), the rest always.

read_of(refs, id)

@spec read_of(refs(), String.t() | nil) :: :all | [String.t()] | nil

What of step id's outputs is read (refs/1), for kept/2: :all, the output names sorted, or nil for none. Plain data: a prepared step carries it, and a compile embeds it.

reads?(names, output)

@spec reads?(:all | [String.t()] | nil, String.t()) :: boolean()

Whether read_of/2's answer reads output.

refs(pairs)

@spec refs([{String.t(), String.t() | nil}] | :all) :: refs()

The references as refs/0: pairs of {id, output} (nil for any output), or :all among them for a reader that may reach any step.

scope_key(pipeline_id, call_scope)

@spec scope_key(String.t() | nil, String.t()) :: scope_key()

The key of the outputs of pipeline_id's steps in call_scope.

script_refs(arg1)

@spec script_refs(map() | nil) :: {:ok, [{String.t(), String.t() | nil}]} | :unknown

The step outputs a script reads, from its Script.Reads analysis: {:ok, pairs} (an output of nil is any output of that step), or :unknown when it may reach any step.

settings_refs(term)

@spec settings_refs(term()) :: [{String.t(), String.t()}]

The step outputs a stored step reads in its settings and a container's conditions: {"in": "steps"} locations at any depth, ${steps.…} templates in any string, step conditions. A Script's source is read by Script.Reads (script_refs/1), not here. The {id, output} pairs of sites/2 that name an output.

sites(term, base \\ [])

@spec sites(term(), [term()]) :: [site()]

Every place term names a step (site/0), depth first, each map before what it holds; base is put in front of every path. A location or a condition without an output, and a ${steps.<id>} template, name the step alone. What settings_refs/1 reads, and what a step's rename rewrites.

template()

@spec template() :: Regex.t()

The template that reads a step output, for HttpUtils.

template_refs(text)

@spec template_refs(String.t()) :: [{String.t(), String.t()}]

The {id, output} pairs the ${steps.…} templates in text read.

text_refs(text)

@spec text_refs(String.t()) :: [{String.t(), String.t() | nil}]

The {id, output} pairs the step templates in text name, in order: an output of nil for ${steps.<id>}, which names the step alone.