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

Link to this function

autofix_blueprint(blueprint)

View Source

Auto-fix issues in the blueprint when possible.

Link to this function

blueprint_issues(blueprint)

View Source

Get given blueprint inssues (column errors etc.)

Link to this function

blueprint_readonly?(blueprint)

View Source

Check whether a blueprint is readonly

Link to this function

blueprint_stats(blueprint)

View Source

Get given blueprint statistics (number of variables, deductions etc.)

Link to this function

blueprint_version(blueprint_or_id)

View Source

Get the version of the given blueprint or blueprint id.

Link to this function

change_blueprint(blueprint, attrs \\ %{})

View Source

Cast attributes into a changeset Only root attributes are supported (no variables or deductions) Writes nothing in the database.

Link to this function

change_branch(branch, attrs \\ %{})

View Source

Modify the given branch using the given attributes, without persisting the changes in the db.

Link to this function

change_column(column, attrs \\ %{})

View Source

Modify the given column using the given attributes, without persisting the changes in the db.

Link to this function

change_deduction(deduction, attrs \\ %{})

View Source

Modify the given deduction using the given attributes, without persisting the changes in the db.

Link to this function

change_variable(var, attrs)

View Source

Change variable with attributes (no children, used for form validation)

Link to this function

compile_blueprint(blueprint, opts \\ [])

View Source

Compile blueprint into processor

Link to this function

create_blueprint(workspace, attrs)

View Source

Create a blueprint with the given attributes

Link to this function

create_branch(deduction, attrs \\ %{})

View Source

Create a new branch in the given deduction with the given attributes.

Link to this function

create_column(blueprint, deduction, attrs)

View Source

Create a new column in the given deduction, using the given attributes.

Link to this function

create_deduction(blueprint, attrs \\ %{})

View Source

Create a new deduction in the given blueprint with the given attributes.

If no attribute is provided, the default values are used.

Link to this function

create_variable(parent, attrs)

View Source

Create variable with attributes

Link to this function

delete_blueprint(blueprint)

View Source

Delete blueprint (will error if used)

Delete the given branch.

Link to this function

delete_cell(branch, column)

View Source

Remove the cell content in the intersection of the given branch and column.

Delete the given column.

Link to this function

delete_deduction(deduction)

View Source

Delete the given deduction.

Delete variable (will error if variable is in use)

Link to this function

duplicate_blueprint(blueprint)

View Source

Duplicate the given blueprint in it's workspace. If the duplication succeeds it returns:

{:ok, new_blueprint}

Otherwise it returns:

Link to this function

filter_accessible_blueprints(query, role)

View Source

Filter accessible blueprints with role

Link to this function

filter_blueprints_by_workspace(query, workspace)

View Source

Apply a workspace scope to a blueprint query

Link to this function

flush_processor(processor)

View Source

Flush compiled processor

Link to this function

get_blueprint(blueprint_id, queries \\ &(&1))

View Source

Get a blueprint with id, nil if not found.

Link to this function

get_blueprint!(blueprint_id, queries \\ &(&1))

View Source

Get a blueprint with id, raise if not found.

Link to this function

get_full_blueprint!(query, with_cases?)

View Source

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.

Link to this function

list_blueprints(queries \\ &(&1))

View Source

List blueprint

Link to this function

list_compiled_blueprint_modules()

View Source

List all modules that correspond to compiled blueprints.

Link to this function

load_blueprint_active_publications(query)

View Source

Load active publications in the given blueprint query.

Link to this function

load_blueprint_full_deductions(query)

View Source

Load deductions and arrange them, load_blueprint_variables MUST be called first

Link to this function

load_blueprint_inactive_publications(query)

View Source

Load inactive publications in the give blueprint query.

Link to this function

load_blueprint_publications(query)

View Source

Load all publications in the given blueprint query.

Link to this function

load_blueprint_simulation(query, with_cases?)

View Source

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.

Link to this function

load_blueprint_variables(query)

View Source

Load variables and index them

Link to this function

load_blueprint_workspace(query)

View Source

Load blueprint workspace

Link to this function

move_variable(var, new_parent)

View Source

Move variable to new parent

Link to this function

run(processor, input, env \\ %{})

View Source

Run processor with given input

Link to this function

serialize_blueprint(blueprint)

View Source

Convert to map for serialization

Link to this function

update_blueprint(blueprint, attrs)

View Source

Update a blueprint with attributes

Link to this function

update_blueprint_from_file(blueprint, path)

View Source

Load a blueprint from a file.

Used for file upload as phoenix write into temp file.

Link to this function

update_branch(branch, attrs)

View Source

Update the given branch using the given attributes and persist the changes in the db.

Link to this function

update_cell(ast, blueprint, branch, column, attrs \\ %{})

View Source

Update the cell in the given branch and column of the given blueprint with the given ast and attributes.

Link to this function

update_column(column, attrs)

View Source

Update the given column using the given attributes and persist the changes in the db.

Link to this function

update_deduction(deduction, attrs)

View Source

Update the given deduction using the given attributes and persist the changes in the db.

Link to this function

update_variable(var, attrs)

View Source

Update variable with attributes

Check if variable is used (expensive, will hit DB).