Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
createPipeline
✓ import { createPipeline } from 'farrow-pipeline'
✗ const { createPipeline } = require('farrow-pipeline')
Farrow.js ecosystem strongly favors ES Modules. While CommonJS `require` might work with transpilation, direct usage can lead to module resolution errors or type inference issues in newer Node.js environments.
defineMiddleware
✓ import { defineMiddleware } from 'farrow-pipeline'
✗ import defineMiddleware from 'farrow-pipeline'
This is a named export, not a default export. Incorrectly importing it as a default will result in `undefined` at runtime and potential type errors.
composePipeline
✓ import { composePipeline } from 'farrow-pipeline'
✗ import { compose } from 'farrow-pipeline'
While conceptually similar to `compose` functions in other libraries, the specific named export for combining multiple pipelines or middlewares in `farrow-pipeline` is `composePipeline`.
This example demonstrates creating and running `farrow-pipeline` instances. It showcases defining synchronous and asynchronous type-safe middlewares with `defineMiddleware`, composing them using `createPipeline().use()` and `composePipeline()`, and handling input/output transformation and errors within the pipeline.
import { createPipeline, defineMiddleware, composePipeline } from 'farrow-pipeline';
// Define a simple logging middleware that enriches the output
const loggerMiddleware = defineMiddleware<{ name: string }, { name: string, loggedAt: number }>((input, next) => {
console.log(`[Logger] Processing input for: ${input.name}`);
const result = next(input);
return { ...result, loggedAt: Date.now() };
});
// Define a validation middleware for the name property
const validatorMiddleware = defineMiddleware<{ name: string }, { name: string }>((input, next) => {
if (!input.name || input.name.length < 3) {
throw new Error('Validation Error: Name must be at least 3 characters long.');
}
console.log(`[Validator] Input name "${input.name}" is valid.`);
return next(input);
});
// Define a data processing middleware that transforms the data
const dataProcessorMiddleware = defineMiddleware<{ name: string, data?: any }, { processedData: string }>((input, next) => {
console.log(`[Processor] Handling data for: ${input.name}`);
const processed = `Transformed data for ${input.name} at ${new Date().toISOString()}`;
const nextResult = next(input);
return { ...nextResult, processedData: processed };
});
// Create a pipeline composed of these synchronous middlewares
const myPipeline = createPipeline()
.use(loggerMiddleware)
.use(validatorMiddleware)
.use(dataProcessorMiddleware);
// Define an asynchronous middleware for demonstration purposes
const asyncMiddleware = defineMiddleware<{ id: number }, { id: number, fetchedData: string }>(async (input, next) => {
console.log(`[Async] Starting async operation for ID: ${input.id}`);
await new Promise(resolve => setTimeout(resolve, 100)); // Simulate async work
const fetchedData = `Data for item ${input.id} from external API`;
console.log(`[Async] Finished async operation for ID: ${input.id}`);
const result = await next(input); // Await the result of the next middleware
return { ...result, fetchedData };
});
// Compose multiple middlewares (including async ones) into a single pipeline
const complexPipeline = composePipeline(
asyncMiddleware,
defineMiddleware<{ id: number, fetchedData?: string }, { finalResult: string }>(async (input) => {
console.log(`[Final] Processing final stage for ID: ${input.id} with fetched data: ${input.fetchedData}`);
return { finalResult: `Final output for ID ${input.id} based on: ${input.fetchedData}` };
})
);
// Run the pipelines
async function runExamples() {
try {
console.log('\n--- Running Simple Pipeline (Valid Input) ---');
const result1 = await myPipeline.run({ name: 'Alice' });
console.log('Pipeline Result 1:', result1);
// Expected: { name: 'Alice', loggedAt: <timestamp>, processedData: 'Transformed data for Alice...' }
console.log('\n--- Running Simple Pipeline (Invalid Input) ---');
try {
await myPipeline.run({ name: 'Bo' }); // This should throw due to validation
} catch (error: any) {
console.error('Pipeline Error:', error.message);
// Expected: 'Validation Error: Name must be at least 3 characters long.'
}
console.log('\n--- Running Complex Pipeline ---');
const result2 = await complexPipeline.run({ id: 123 });
console.log('Complex Pipeline Result 2:', result2);
// Expected: { id: 123, fetchedData: 'Data for item 123 from external API', finalResult: 'Final output for ID 123...' }
} catch (e: any) {
console.error("An unexpected error occurred during example execution:", e.message);
}
}
runExamples();
Errors
Common errors & fixes
Argument of type '(...args: any) => any' is not assignable to parameter of type 'Middleware<any, any>'.
Attempting to pass a plain JavaScript function directly into a pipeline's `.use()` method without wrapping it in `defineMiddleware`, or without correctly specifying generic types for `defineMiddleware`.
fixAlways use `defineMiddleware<InputType, OutputType>((input, next) => { ... })` to correctly type and construct your middleware functions, ensuring type compatibility with the pipeline. TypeError: Cannot read properties of undefined (reading 'property')
A middleware expected a certain property on the `input` object that was not provided by the previous middleware or the initial pipeline run, often due to an incorrect type definition or a middleware short-circuiting.
fixCarefully review the type flow (`InputType` and `OutputType`) between your chained middlewares. Ensure that each middleware explicitly passes the required properties to the next in the chain via its `OutputType` or by modifying the `input` object before calling `next()`.
Module not found: Can't resolve 'farrow-pipeline' in '...' OR ReferenceError: require is not defined
This typically occurs when trying to use `farrow-pipeline` (which is designed for ES Modules) within a CommonJS environment without proper configuration, or due to incorrect import paths.
fixEnsure your Node.js project is configured for ES Modules by adding `"type": "module"` to your `package.json` and using `import` statements. Verify the package is installed and the import path `farrow-pipeline` is correct.
Audit
Dependencies
No dependency data recorded yet.