Skip to main content

Overview

ExecutionContext is the runtime state container for workflow execution. It stores variables, resolves template expressions, and tracks node outputs.
import { ExecutionContext } from '@jam-nodes/core';

const ctx = new ExecutionContext({ user: { name: 'Alice' }, items: [1, 2, 3] });

Variable Management

setVariable / getVariable

ctx.setVariable('count', 42);
ctx.getVariable('count'); // 42

hasVariable / deleteVariable

ctx.hasVariable('count'); // true
ctx.deleteVariable('count');

getAllVariables / clearAll / mergeVariables

ctx.getAllVariables();  // Returns a copy of all variables
ctx.mergeVariables({ a: 1, b: 2 });
ctx.clearAll();

Interpolation

interpolate

Resolves {{variable}} references in strings. If the entire string is a single reference, returns the actual value (not stringified).
ctx.interpolate('Hello {{user.name}}');  // "Hello Alice"
ctx.interpolate('{{items}}');            // [1, 2, 3] (actual array)

interpolateObject

Recursively interpolates all strings in an object or array.
ctx.interpolateObject({
  greeting: 'Hello {{user.name}}',
  data: '{{items}}',
});
// { greeting: 'Hello Alice', data: [1, 2, 3] }
Use interpolateObject with prepareNodeInput to resolve all {{var}} references in node configuration before execution.

Path Resolution

evaluateJsonPath

Evaluate JSONPath expressions against the variable store.
ctx.evaluateJsonPath('$.user.name');  // "Alice"
Single results are automatically unwrapped from arrays.

resolveNestedPath

Resolve dot-notation paths including array indices.
ctx.resolveNestedPath('user.name');     // "Alice"
ctx.resolveNestedPath('items[0]');      // 1

Node Output Storage

storeNodeOutput

Stores a node’s output and merges object keys to the root variable scope.
ctx.storeNodeOutput('search', { contacts: [{ name: 'Bob' }] });
ctx.getVariable('contacts');  // [{ name: 'Bob' }]

getNodeOutput

Retrieve a specific node’s stored output.
ctx.getNodeOutput('search');  // { contacts: [{ name: 'Bob' }] }

Context Conversion

toNodeContext

Create a NodeExecutionContext for passing to node executors.
const nodeCtx = ctx.toNodeContext('user-123', 'wf-456', 'campaign-789');

Serialization

const json = ctx.toJSON();                    // Export variables
const restored = ExecutionContext.fromJSON(json);  // Restore from JSON

Factory Functions

import { createExecutionContext } from '@jam-nodes/core';

const ctx = createExecutionContext({ key: 'value' });

All Methods

MethodSignatureDescription
setVariable(name: string, value: unknown): voidSet a variable
getVariable(name: string): unknownGet a variable
getAllVariables(): Record<string, unknown>Get copy of all variables
hasVariable(name: string): booleanCheck if variable exists
deleteVariable(name: string): voidDelete a variable
clearAll(): voidClear all variables
mergeVariables(vars: Record<string, unknown>): voidMerge multiple variables
evaluateJsonPath(path: string): unknownEvaluate JSONPath expression
interpolate(template: string): unknownInterpolate {{var}} in string
interpolateObject<T>(obj: T): TRecursively interpolate object
resolveNestedPath(path: string): unknownResolve dot-notation path
storeNodeOutput(nodeId: string, output: unknown): voidStore node output
getNodeOutput<T>(nodeId: string): T | undefinedGet stored node output
toNodeContext(userId, workflowExecutionId, campaignId?): NodeExecutionContextCreate executor context
toJSON(): Record<string, unknown>Export variables
static fromJSON(json): ExecutionContextCreate from serialized data