@onlineapps/cookbook-executor
v1.0.12
Published
Workflow execution engine for cookbook definitions - handles context and step processing
Maintainers
Readme
@onlineapps/cookbook-executor
Workflow execution engine for cookbook definitions - handles context management and step processing.
Overview
This package provides the execution engine for cookbook workflows. It manages context, processes different step types, and handles variable resolution throughout workflow execution.
Installation
npm install @onlineapps/cookbook-executorFeatures
- Complete step type support - All step types (task, foreach, fork_join, switch, steps, wait, dispatch)
- Context management - Maintains workflow state and variables
- Variable resolution - Supports $api_input, $steps, JSONPath
- Retry logic - Built-in retry with exponential backoff
- Execution tracing - Complete audit trail of execution
Usage
Basic workflow execution
const { CookbookExecutor } = require('@onlineapps/cookbook-executor');
const cookbook = {
version: '1.0.0',
steps: [
{
id: 'step1',
type: 'task',
service: 'hello-service',
operation: 'greet',
input: {
name: '$api_input.name'
}
}
]
};
const executor = new CookbookExecutor(cookbook);
const result = await executor.execute({ name: 'World' });Context management
const { ContextManager } = require('@onlineapps/cookbook-executor');
const context = new ContextManager();
context.setInput({ user: 'John' });
context.set('workflow_id', 'wf_123');
// Resolve variables
const value = context.resolve('$api_input.user'); // 'John'Variable resolution
const { VariableResolver } = require('@onlineapps/cookbook-executor');
const resolver = new VariableResolver(context);
// Resolve different types
resolver.resolve('$api_input.name');
resolver.resolve('$steps.step1.output');
resolver.resolve('$.steps[?(@.status=="success")]');Step Types
Task Step
Execute service operations:
{
id: 'call-service',
type: 'task',
service: 'my-service',
operation: 'process',
input: { data: '$api_input.data' },
output: { result: '$.response.result' }
}Foreach Step
Iterate over arrays:
{
id: 'process-items',
type: 'foreach',
iterator: '$api_input.items',
body: [/* steps to execute for each item */]
}Fork Join Step
Parallel execution:
{
id: 'parallel-processing',
type: 'fork_join',
branches: [/* parallel steps */],
join: {
strategy: 'merge',
output: { combined: '$.branches' }
}
}Switch Step
Conditional branching:
{
id: 'conditional',
type: 'switch',
expression: '$api_input.type',
cases: {
'A': { /* step for case A */ },
'B': { /* step for case B */ }
},
default: { /* default step */ }
}API Reference
CookbookExecutor
constructor(cookbook, options)- Create executor instanceexecute(input)- Execute workflow with inputexecuteStep(step)- Execute single stepgetContext()- Get current context stategetTrace()- Get execution trace
ContextManager
setInput(input)- Set workflow inputset(key, value)- Set context variableget(key)- Get context variablesetStepResult(stepId, result)- Store step resultresolve(reference)- Resolve variable reference
StepProcessor
process(step)- Process any step typeprocessTask(step)- Process task stepprocessForeach(step)- Process foreach stepprocessForkJoin(step)- Process fork_join step
Options
{
maxRetries: 3, // Maximum retry attempts
defaultTimeout: 30000, // Default timeout in ms
logger: console // Logger instance
}Related Packages
@onlineapps/cookbook-core- Core parsing and validation@onlineapps/cookbook-transformer- OpenAPI mapping@onlineapps/cookbook-router- Message routing@onlineapps/connector-cookbook- Full-featured wrapper
License
PROPRIETARY - All rights reserved
