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 withexpr-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
MathFunctionResponse:
{ result }; the same number is written to flows_nodes.data.result (see Persisted node data).
End-to-end flow
- Load node —
SELECTfromflows_nodesbynodeId; readdata. - Read inputs —
formula(string, default"") andvariables(array, default[]). - Substitute — Start from
formula. For each entry invariables, replace every whole-word occurrence ofvariable.namewithvariable.valueusing a global regex\b<name>\b. - Evaluate —
new Parser().evaluate(expression); the result must be a number (resultis typed asnumberin the service return). - Persist —
UPDATE flows_nodeswithdatacontainingresultandexecutionStatus: "COMPLETED". - Return —
{ result }.
Node data fields (Worker expectations)
| Field | Role |
|---|---|
formula | Expression string, e.g. a + b * 2. Defaults to empty string if missing. |
variables | Array 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), soxdoes not replace thexinsidemax. - Values are inserted as literal substrings into the expression (they should form valid
expr-evalsyntax, typically numeric literals).
Persisted node data
On success, the service sets:
| Field | Role |
|---|---|
result | Numeric evaluation result. |
executionStatus | "COMPLETED". |
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).