Skip to content
ildellaPublic

About

A pragmatic library for sequential async operations with first-class error handling.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Pipelean

Sequential iteration and accumulation with explicit error handling.

Pipelean gives a clear contract to sequential operations: how items are processed, how state accumulates, and what happens when an operation fails. No hand-written loops, accidental error handling, or hidden failure policies.

Plain JavaScript. Eager execution. No framework or scheduler.

Why Pipelean?

Sequential operations often require the same boilerplate: iterate over items, accumulate a value when needed, and decide what happens when an operation fails.

Pipelean makes these three concerns explicit, composable, and reusable.

import {series, collect} from 'pipelean'

const {results, errors} = await series(pages, importPage, {
  strategy: collect,
  onError: ({item, error}) => log.warn(item, error),
})

if (errors.length) report(errors)

Process items sequentially, collect failures without losing successful results, and choose the error policy instead of burying it in a loop.

Install

npm install pipelean

Node.js >= 22.7. ESM.

The core

Pipelean is built around three concepts.

1. Iteration

Process a sequence of independent items, one at a time.

Function Purpose
series Process items, collect results and handle failures through a strategy
filter Select items using a predicate

series and filter support arrays, generators, and async iterables. They can process synchronous or asynchronous callbacks.

const {results, errors} = await series(items, processItem)

Returning undefined from a mapper drops the item.

2. Accumulation

When each item depends on the result of the previous one, use a fold.

Function Keeps Returns
scan Every intermediate accumulator Report with results
reduce Final accumulator only Report with value
const {value: total} = await reduce(
  tracks,
  (sum, track) => sum + track.duration,
  0,
)

Use scan when intermediate states matter, and reduce when only the final state matters.

3. Error strategies

Errors are handled according to an explicit strategy. Strategies determine whether execution continues, stops, or throws.

Strategy Behavior
collect Continue and collect errors in errors
failLate Continue, then report failure after processing
failFast Stop on the first error and return it as failure
skip Continue without collecting errors
rethrow Throw the original error immediately

onError is an observation hook, not an error strategy.

Default strategies:

  • series, filter, and enrich: collect
  • scan and reduce: failFast

Results make handled failures explicit. Use assertOk(result) when a failure must not be ignored.

See the error model in the Guide for result shapes, source errors, recovery, and strategy details.

Additional tools

These complement the core. You don't need them to get started.

Pipeline composition

  • pipe — compose value-in/value-out functions into a reusable pipeline.

Convenience APIs

  • mapSeries — sequential map with a fixed rethrow policy: returns a plain array or throws the original error.
  • foldSync — synchronous fold with a fixed rethrow policy: returns the final accumulator or throws the original error. It is reduceSync(..., {strategy: rethrow}).value.
  • enrich — accumulate object patches over one input.
  • assign — build conditional property-assignment steps for enrich.
  • Sync counterparts — seriesSync, filterSync, mapSeriesSync, scanSync, reduceSync, stopWhenSync, pipeSync, enrichSync, and tryCatchSync. They return directly and reject async-only behavior.

Advanced controls

  • join — run a small set of named tasks concurrently and return a structured result.
  • retry — retry a function after failure.
  • stopWhen — stop an iterable when a predicate matches.
  • forever — produce an unbounded sequence of ticks.

Standalone utilities

These are useful outside iteration and accumulation:

  • tryCatch — wrap a function with error handling and lifecycle hooks.
  • assertOk — ensure a Pipelean result did not fail.
  • where / findSync — predicate helpers and synchronous search.

What Pipelean is not

  • Not concurrent mapping. Iteration and accumulation are sequential. join is for a small set of heterogeneous tasks, not a concurrent collection.
  • Not lazy. Execution starts immediately.
  • Not a stream adapter. Any iterable or async iterable is supported; Node streams need their own adapter.
  • Not a replacement for simple native JavaScript. If a plain map, filter, await, or try/catch is clearer, use it.

Documentation

  • Guide — understand the mental model and how to choose the right operation.
  • Reference — API signatures, options, return shapes, and exact contracts.
  • Examples — practical usage.
  • Patterns — recipes for common problems.
  • ESLint plugin — lint rules and suggestions.
  • Architecture — design principles.
  • Migration — upgrading between versions.
  • Alternatives — when another library owns the problem.

ESLint

Pipelean includes an ESLint plugin that encourages explicit sequential processing and discourages common async mistakes.

import pipeleanConfig from 'pipelean/eslint/config'

export default [pipeleanConfig]

See the ESLint documentation for configuration and individual rules.

Agent Skill

Pipelean includes an Agent Skill for AI coding assistants.

npx skills add https://github.com/ildella/pipelean/tree/master/skills -g -y

See the repository's skills directory for details.

License

MIT

About

A pragmatic library for sequential async operations with first-class error handling.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages

Generated from ildella/lib-template