Workflow Runtime Library
The @lssm/lib.contracts/workflow library provides the core WorkflowRunner for executing stateful, durable workflows.
WorkflowRunner
The runner manages execution state, step transitions, retries, and compensation.
import { WorkflowRunner } from '@lssm/lib.contracts/workflow/runner';
import { InMemoryStateStore } from '@lssm/lib.contracts/workflow/adapters/memory-store';
import { WorkflowRegistry } from '@lssm/lib.contracts/workflow/spec';
const registry = new WorkflowRegistry();
registry.register(MyWorkflow);
const runner = new WorkflowRunner({
registry,
stateStore: new InMemoryStateStore(),
opExecutor: async (op, input, ctx) => {
// Execute operation using your adapter (REST, GraphQL, etc.)
return await myAdapter.execute(op, input);
},
});
// Start a workflow
const workflowId = await runner.start('my.workflow', 1, { userId: '123' });
// Execute next step (usually called by a worker or queue consumer)
await runner.executeStep(workflowId);State Persistence
The runner relies on a StateStore to persist workflow execution history. ContractSpec ships with:
InMemoryStateStore- for testing and development.PrismaStateStore- for production using Prisma ORM.
Events
The runner emits events that you can subscribe to for monitoring:
workflow.startedworkflow.step_completedworkflow.step_failedworkflow.step_retryingworkflow.completedworkflow.cancelledworkflow.compensation_step_completed