Modules@robinpath/workflow
workflow

@robinpath/workflow

0.1.1Node.jsPublic

Workflow orchestration engine with steps, branching, parallel execution, and loops

Workflow

Workflow orchestration engine with steps, conditions, loops, parallel execution, branching, and context management

Package: @robinpath/workflow | Category: Infrastructure | Type: Utility

Authentication

No authentication required. All functions are available immediately.

Use Cases

Use the workflow module when you need to:

  • Create a new workflow -- Use workflow.create to perform this operation
  • Add a step to a workflow (action, condition, loop, parallel, delay, transform) -- Use workflow.addStep to perform this operation
  • Link one step to the next (set execution order) -- Use workflow.link to perform this operation
  • Execute a workflow with optional input data -- Use workflow.run to perform this operation
  • Pause a running workflow -- Use workflow.pause to perform this operation

Quick Reference

FunctionDescriptionReturns
createCreate a new workflow{id, name, status}
addStepAdd a step to a workflow (action, condition, loop, parallel, delay, transform){id, name, type}
setEntrySet the entry (first) step of a workflow{entryStep}
linkLink one step to the next (set execution order){from, to}
runExecute a workflow with optional input data{id, status, stepsExecuted, duration, result, error}
pausePause a running workflow{id, status: paused}
getStatusGet the current status and metadata of a workflowWorkflow status details
getContextGet workflow context data (all or by key)Context value or full context object
setContextSet a value in the workflow contextTrue
getHistoryGet the execution history of a workflow runArray of step execution records
listStepsList all steps in a workflowArray of step definitions
removeStepRemove a step from a workflowTrue if removed
destroyDestroy a workflow and free resourcesTrue if destroyed
listList all workflowsArray of workflow summaries
cloneClone an existing workflow{id, name}

Functions

create

Create a new workflow

Module: workflow | Returns: object -- {id, name, status}

workflow.create "Send Welcome Email"
ParameterTypeRequiredDescription
namestringYesWorkflow name
optionsobjectNo{context: initial context data}

addStep

Add a step to a workflow (action, condition, loop, parallel, delay, transform)

Module: workflow | Returns: object -- {id, name, type}

workflow.addStep $wfId {"name": "Fetch User", "type": "action", "handler": $fn}
ParameterTypeRequiredDescription
workflowIdstringYesWorkflow ID
stepobjectYes{name, type, handler, config, next, onError}

setEntry

Set the entry (first) step of a workflow

Module: workflow | Returns: object -- {entryStep}

workflow.setEntry $wfId $stepId
ParameterTypeRequiredDescription
workflowIdstringYesWorkflow ID
stepIdstringYesStep ID

link

Link one step to the next (set execution order)

Module: workflow | Returns: object -- {from, to}

workflow.link $wfId $step1 $step2
ParameterTypeRequiredDescription
workflowIdstringYesWorkflow ID
fromStepIdstringYesSource step
toStepIdstringYesTarget step

run

Execute a workflow with optional input data

Module: workflow | Returns: object -- {id, status, stepsExecuted, duration, result, error}

workflow.run $wfId {"userId": 123}
ParameterTypeRequiredDescription
workflowIdstringYesWorkflow ID
inputobjectNoInput data for the workflow context

pause

Pause a running workflow

Module: workflow | Returns: object -- {id, status: paused}

workflow.pause $wfId
ParameterTypeRequiredDescription
workflowIdstringYesWorkflow ID

getStatus

Get the current status and metadata of a workflow

Module: workflow | Returns: object -- Workflow status details

workflow.getStatus $wfId
ParameterTypeRequiredDescription
workflowIdstringYesWorkflow ID

getContext

Get workflow context data (all or by key)

Module: workflow | Returns: any -- Context value or full context object

workflow.getContext $wfId "userId"
ParameterTypeRequiredDescription
workflowIdstringYesWorkflow ID
keystringNoOptional context key

setContext

Set a value in the workflow context

Module: workflow | Returns: boolean -- True

workflow.setContext $wfId "status" "active"
ParameterTypeRequiredDescription
workflowIdstringYesWorkflow ID
keystringYesContext key
valueanyYesValue to set

getHistory

Get the execution history of a workflow run

Module: workflow | Returns: array -- Array of step execution records

workflow.getHistory $wfId
ParameterTypeRequiredDescription
workflowIdstringYesWorkflow ID

listSteps

List all steps in a workflow

Module: workflow | Returns: array -- Array of step definitions

workflow.listSteps $wfId
ParameterTypeRequiredDescription
workflowIdstringYesWorkflow ID

removeStep

Remove a step from a workflow

Module: workflow | Returns: boolean -- True if removed

workflow.removeStep $wfId $stepId
ParameterTypeRequiredDescription
workflowIdstringYesWorkflow ID
stepIdstringYesStep ID

destroy

Destroy a workflow and free resources

Module: workflow | Returns: boolean -- True if destroyed

workflow.destroy $wfId
ParameterTypeRequiredDescription
workflowIdstringYesWorkflow ID

list

List all workflows

Module: workflow | Returns: array -- Array of workflow summaries

workflow.list
ParameterTypeRequiredDescription
(none)NoCall with no arguments

clone

Clone an existing workflow

Module: workflow | Returns: object -- {id, name}

workflow.clone $wfId "My Copy"
ParameterTypeRequiredDescription
workflowIdstringYesSource workflow ID
namestringNoNew workflow name

Error Handling

All functions throw on failure. Common errors:

ErrorCause
Workflow has no stepsCheck the error message for details
No entry step definedCheck the error message for details
Workflow "..." not foundCheck the error message for details
Step "..." not found in workflowCheck the error message for details
Step "..." not foundCheck the error message for details
@desc "Create and validate result"
do
  set $result as workflow.create "Send Welcome Email"
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. List and iterate Status

Retrieve all items and loop through them.

@desc "Get status and iterate results"
do
  set $result as workflow.getStatus $wfId
  each $item in $result
    print $item
  end
enddo

2. Create a new item with create

Create a new resource and capture the result.

set $result as workflow.create "Send Welcome Email"
print "Created: " + $result

3. Check before creating

List existing items and only create if needed.

@desc "Get status and create"
do
  set $existing as workflow.getStatus $wfId
  if $existing == null
    workflow.create "Send Welcome Email"
    print "Item created"
  else
    print "Item already exists"
  end
enddo

4. Multi-step Workflow workflow

Chain multiple workflow operations together.

@desc "Create, add step, and more"
do
  set $r_create as workflow.create "Send Welcome Email"
  set $r_addStep as workflow.addStep $wfId {"name": "Fetch User", "type": "action", "handler": $fn}
  set $r_link as workflow.link $wfId $step1 $step2
  print "All operations complete"
enddo

5. Safe create with validation

Check results before proceeding.

@desc "Create and validate result"
do
  set $result as workflow.create "Send Welcome Email"
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • json -- JSON module for complementary functionality

Versions (1)

VersionTagPublished
0.1.1latest1 months ago
Install
$ robinpath add @robinpath/workflow

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.1
LicenseMIT
Unpacked Size7.4 KB
Versions1
Weekly Downloads21
Total Downloads21
Stars0
Last Publish1 months ago
Created1 months ago

Category

devops