Skip to main content

Overview

The math function node evaluates a numeric expression stored on the node. You provide a formula string and a list of variables; each variable name is replaced by its value (as text) in the formula, then the expression is evaluated with expr-eval (Parser). mathFunctionActivity delegates to MathFunctionService.process.

When it runs

mathFunctionActivity is invoked from the processSingleNode workflow when the node type is function (NodeType.FUNCTION, stored value mathFunction).

Activity signature

async mathFunctionActivity({
  nodeId: string,
  sessionId: string,
  userId: string,
}): Promise<MathFunctionResponse>
MathFunctionResponse:
{
  result: number;
}
The activity returns { result }; the same number is written to flows_nodes.data.result (see Persisted node data).

End-to-end flow

  1. Load nodeSELECT from flows_nodes by nodeId; read data.
  2. Read inputsformula (string, default "") and variables (array, default []).
  3. Substitute — Start from formula. For each entry in variables, replace every whole-word occurrence of variable.name with variable.value using a global regex \b<name>\b.
  4. Evaluatenew Parser().evaluate(expression); the result must be a number (result is typed as number in the service return).
  5. PersistUPDATE flows_nodes with data containing result and executionStatus: "COMPLETED".
  6. Return{ result }.

Node data fields (Worker expectations)

FieldRole
formulaExpression string, e.g. a + b * 2. Defaults to empty string if missing.
variablesArray of { id: string; name: string; value: string }. Each name is substituted by value before evaluation.
id on each variable is not used by the Worker; it is kept for UI or persistence only.

Variable substitution

  • Replacements run in array order, repeatedly updating the working string.
  • Matching uses word boundaries (\b), so x does not replace the x inside max.
  • Values are inserted as literal substrings into the expression (they should form valid expr-eval syntax, typically numeric literals).

Persisted node data

On success, the service sets:
FieldRole
resultNumeric evaluation result.
executionStatus"COMPLETED".
Other data fields are preserved via spread (...nodeData).

Errors

  • Missing node row → Node not found.
  • Invalid expression, division by zero, or other evaluation failures → thrown by Parser().evaluate (and propagate to the workflow).