View Source VacEngine.Processor (Vac Engine v1.1.1)
The Processor module is responsible for generating and executing functions to compute API output from API input.
Processors
Process input
The role of the processor is to compute the output variables of an api call
based on the input variables. Such a computation is made using the run/2
function:
{:ok, %{output: state.output, input: state.input}} = Processor.run(processor, input)
Build a processor
A processor is an in memory function, compiled from a description called "Blueprint". The procedure to obtain a blueprint is described in the "Blueprint edition" and "Blueprint export/import" sections below.
The compilation from a blueprint to a processor is made using the
Processor.compile_blueprint/1
function:
{:ok, processor} = Processor.compile_blueprint(blueprint)
Blueprint
A blueprint is an ecto model living in the database and attached to a workspace. It has the following composition:
_ Blueprint _
| |
0..n 0..n
| |
Variables Deductions
(input, output |
intermediate) 0..n
|
_ Branches _
| |
0..n 1..n
| |
Condition Assignment
| |
1 1
| |
Expession Expression
variables
Variables describe the values the processor can receive (input), return (output) or compute as intermediary values. They are attached to a type, a position in the input or output and some other properties like optional/required.
deductions
Deductions are descriptions of how intermediary and output variables should be computed. They are built as tables whose columns correspond to the involved variables (assigned one or ones playing role in conditions) and the rows to subsidiary conditions/assignement branches (if the conditions of the first branch are not met, the second branch is tested, and so on).
branches
A (possibly empty) set of conditions on certain variables linked with an assignation to other (or same) variables.
condition
An expression describing when the condition is met based on it's column's variable.
assignment
An expression describing the value the column's variable should take in case the branch conditions are met.
expression
Either a constant, a variable or a function involving other expressions that can be computed based on the current variables state. Condition expressions return nullable booleans, assignment expression return a nullable value of the type of the column's variable.
Blueprint manipulation
Creation and import
Blueprints can be created using the create_blueprint/2
function.
This function requires you to provide attributes for the blueprint.
Update to the blueprint such as modifying name or description can be made
using the update_blueprint/2
function.
Populating a whole blueprint can done by importing a blueprint from a
.json file definition. This is done using the update_blueprint_from_file/2
function.
Manipulation
A set of functions allow you to directly load and update variables and deductions.
Schemas
Below, the ecto schemas available in the Processor module.
Assignment
A variable assignment in the branch of a bluprint deduction.
AstType
Ecto type for AST serialization to the database.
Allows to store tuples as JSON.
BindingElement
An expression binding element.
Binding
An expression binding.
Blueprint
A blueprint describing a full processor.
Branch
A deduction branch.
Column
A deduction column (a structuration feature that has no effect when the processor runs on an input.)
Condition
A condition in a branch.
Deduction
A blueprint deduction.
Expression
Expressions can be found in conditions, assignments or variable default values.
ListType
Ecto type to allow storing a list in a json field.
Variable
A blueprint variable.
Link to this section Summary
Functions
Auto-fix issues in the blueprint when possible.
Get given blueprint inssues (column errors etc.)
Check whether a blueprint is readonly
Get given blueprint statistics (number of variables, deductions etc.)
Get the version of the given blueprint or blueprint id.
Cast attributes into a changeset Only root attributes are supported (no variables or deductions) Writes nothing in the database.
Modify the given branch using the given attributes, without persisting the changes in the db.
Modify the given column using the given attributes, without persisting the changes in the db.
Modify the given deduction using the given attributes, without persisting the changes in the db.
Change variable with attributes (no children, used for form validation)
Compile blueprint into processor
Create a blueprint with the given attributes
Create a new branch in the given deduction with the given attributes.
Create a new column in the given deduction, using the given attributes.
Create a new deduction in the given blueprint with the given attributes.
Create variable with attributes
Delete blueprint (will error if used)
Delete the given branch.
Remove the cell content in the intersection of the given branch and column.
Delete the given column.
Delete the given deduction.
Delete variable (will error if variable is in use)
Duplicate the given blueprint in it's workspace. If the duplication succeeds it returns
Filter accessible blueprints with role
Apply a workspace scope to a blueprint query
Flush compiled processor
Get a blueprint with id, nil if not found.
Get a blueprint with id, raise if not found.
Get the fully preloaded version of the blueprint with the given id. If with cases is set to true, it also includes related cases. Otherwise, only stacks, layers and templates are preloaded.
List blueprint
List all modules that correspond to compiled blueprints.
Load active publications in the given blueprint query.
Load deductions and arrange them, load_blueprint_variables MUST be called first
Load inactive publications in the give blueprint query.
Load all publications in the given blueprint query.
Load simulation elements associated with the blueprint (settings, templates
and stacks).
If the with_cases?
parameter is set to true, the associated cases
(with input/output entries) are also loaded.
Load variables and index them
Load blueprint workspace
Move variable to new parent
Run processor with given input
Convert to map for serialization
Update a blueprint with attributes
Load a blueprint from a file.
Update the given branch using the given attributes and persist the changes in the db.
Update the cell in the given branch and column of the given blueprint with the given ast and attributes.
Update the given column using the given attributes and persist the changes in the db.
Update the given deduction using the given attributes and persist the changes in the db.
Update variable with attributes
Check if variable is used (expensive, will hit DB).
Link to this section Functions
Auto-fix issues in the blueprint when possible.
Get given blueprint inssues (column errors etc.)
Check whether a blueprint is readonly
Get given blueprint statistics (number of variables, deductions etc.)
Get the version of the given blueprint or blueprint id.
Cast attributes into a changeset Only root attributes are supported (no variables or deductions) Writes nothing in the database.
Modify the given branch using the given attributes, without persisting the changes in the db.
Modify the given column using the given attributes, without persisting the changes in the db.
Modify the given deduction using the given attributes, without persisting the changes in the db.
Change variable with attributes (no children, used for form validation)
Compile blueprint into processor
Create a blueprint with the given attributes
Create a new branch in the given deduction with the given attributes.
Create a new column in the given deduction, using the given attributes.
Create a new deduction in the given blueprint with the given attributes.
If no attribute is provided, the default values are used.
Create variable with attributes
Delete blueprint (will error if used)
Delete the given branch.
Remove the cell content in the intersection of the given branch and column.
Delete the given column.
Delete the given deduction.
Delete variable (will error if variable is in use)
Duplicate the given blueprint in it's workspace. If the duplication succeeds it returns:
{:ok, new_blueprint}
Otherwise it returns:
Filter accessible blueprints with role
Apply a workspace scope to a blueprint query
Flush compiled processor
Get a blueprint with id, nil if not found.
Get a blueprint with id, raise if not found.
Get the fully preloaded version of the blueprint with the given id. If with cases is set to true, it also includes related cases. Otherwise, only stacks, layers and templates are preloaded.
List blueprint
List all modules that correspond to compiled blueprints.
Load active publications in the given blueprint query.
Load deductions and arrange them, load_blueprint_variables MUST be called first
Load inactive publications in the give blueprint query.
Load all publications in the given blueprint query.
Load simulation elements associated with the blueprint (settings, templates
and stacks).
If the with_cases?
parameter is set to true, the associated cases
(with input/output entries) are also loaded.
Load variables and index them
Load blueprint workspace
Move variable to new parent
Run processor with given input
Convert to map for serialization
Update a blueprint with attributes
Load a blueprint from a file.
Used for file upload as phoenix write into temp file.
Update the given branch using the given attributes and persist the changes in the db.
Update the cell in the given branch and column of the given blueprint with the given ast and attributes.
Update the given column using the given attributes and persist the changes in the db.
Update the given deduction using the given attributes and persist the changes in the db.
Update variable with attributes
Check if variable is used (expensive, will hit DB).