Task Graph Kit
Make task dependencies explicit.
Task ordering, bounded retries, failure propagation and structured run records. A small graph runner you can read and execute.
- Dependencies complete before consumers
- Failures are recorded; dependent work is blocked
- Opt-in retries for explicitly idempotent work
import { runGraph } from './graph.mjs';
const report = await runGraph([
{id:'source',run:()=>[{region:'North',amount:120},{region:'North',amount:80},{region:'South',amount:150}]},
{id:'validate',dependsOn:['source'],run:({source})=>{if(source.some(r=>!Number.isFinite(r.amount)))throw new Error('Invalid amount');return source;}},
{id:'aggregate',dependsOn:['validate'],run:({validate})=>validate.reduce((a,r)=>({...a,[r.region]:(a[r.region]??0)+r.amount}),{})},
{id:'report',dependsOn:['aggregate'],run:({aggregate})=>({unit:'CNY',synthetic:true,totals:aggregate})},
]);
console.log(JSON.stringify(report,null,2));Explicit dependencies organise work. Structured outputs connect the next step.
