Jun 9, 2026
When building workflows, consider the pipeline pattern. This pattern is an array of step functions that leverage the same context object. The context is created with all the necessary keys, then passed to a step which may/not modify it, and then returns it. Repeat for each step.
// Main
import { one } from "./steps/one.js";
import { two } from "./steps/two.js";
import { three } from "./steps/three.js";
const steps = [one, two, three];
const context = {
inputs: null,
outputs: null,
file: './some/file.txt',
errors: [],
warnings: []
};
for( const step of steps ) {
await step( context );
if( context.errors ) break;
}
// Step function
export async function one( context ) {
// Do some work
// Modify context if needed by later steps
return context;
}
Back to Notes