{"name":"stream-chain","version":"4.2.2","keywords":["stream","chain","pipeline","transform","backpressure","duplex","generator","async","object-mode","functional","jsonl","json-lines","ndjson","web-streams","esm"],"author":{"url":"https://www.lazutkin.com/","name":"Eugene Lazutkin","email":"eugene.lazutkin@gmail.com"},"license":"BSD-3-Clause","_id":"stream-chain@4.2.2","maintainers":[{"name":"elazutkin","email":"eugene.lazutkin@gmail.com"}],"homepage":"https://github.com/uhop/stream-chain#readme","bugs":{"url":"https://github.com/uhop/stream-chain/issues"},"dist":{"shasum":"5ccdc7347b03f1aabc4d1a3b89fb951ecd2ebee1","tarball":"http://registry-npm.ywwl.com/stream-chain/download/stream-chain-4.2.2.tgz","fileCount":101,"integrity":"sha512-WvCG2zHCTqyZtuQoFLH0RZO7K0cgEDLGRriDI7lrOKvJmva2agz5dhwck49nsepXC0FgaVYkNgBYuhPKsEKxCg==","signatures":[{"sig":"MEUCIQDLJpUjaJ8nqyvs6PUlomU3ZNTUGOtfvWiS+AXkMQyiiwIgUVCjK5dpIBTd7UKghCLTVZmndBdcWzL0JQymzKtvuxM=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":277110,"size":70876,"noattachment":false,"key":"/stream-chain/-/stream-chain-4.2.2.tgz"},"llms":"https://raw.githubusercontent.com/uhop/stream-chain/master/llms.txt","main":"./src/node/index.js","type":"module","tape6":{"cli":["/tests/node/test-*.*js"],"tests":["/tests/core/test-*.*js","/tests/web/test-*.*js"],"importmap":{"imports":{"tape-six":"/node_modules/tape-six/index.js","tape-six/":"/node_modules/tape-six/src/"}}},"types":"./src/node/index.d.ts","engines":{"node":">=22"},"exports":{".":"./src/node/index.js","./*":"./src/*","./web":"./src/web/index.js","./core":"./src/core/index.js","./node":"./src/node/index.js","./web/jsonl":"./src/web/jsonl/index.js","./node/jsonl":"./src/node/jsonl/index.js"},"funding":"https://github.com/sponsors/uhop","gitHead":"207ea173cd85567f7f83dc7cdb7e470aa5b4ed20","scripts":{"lint":"prettier --check .","test":"tape6 --flags FO","bench":"nano-bench","ts-test":"tape6 --flags FO 'tests/**/test-*.*ts'","js-check":"tsc --project tsconfig.check.json","lint:fix":"prettier --write .","test:bun":"tape6-bun --flags FO","test:seq":"tape6-seq --flags FO","ts-check":"tsc --noEmit","test:deno":"tape6-deno --flags FO","test:proc":"tape6-proc --flags FO","ts-test:bun":"tape6-bun --flags FO 'tests/**/test-*.*ts'","test:browser":"tape6-playwright --server-url http://localhost:55555 --start-server --flags FO","test:seq:bun":"bun run `tape6-seq --self` --flags FO","ts-test:deno":"tape6-deno --flags FO 'tests/**/test-*.*ts'","test:proc:bun":"bun run `tape6-proc --self` --flags FO","test:seq:deno":"deno run -A `tape6-seq --self` --flags FO","test:proc:deno":"deno run -A `tape6-proc --self` --flags FO -r -A"},"_npmUser":{"name":"elazutkin","email":"eugene.lazutkin@gmail.com"},"llmsFull":"https://raw.githubusercontent.com/uhop/stream-chain/master/llms-full.txt","repository":{"url":"git+https://github.com/uhop/stream-chain.git","type":"git"},"_npmVersion":"11.13.0","description":"Chain functions, generators, Node streams, and Web streams into a pipeline with backpressure support.","directories":{},"_nodeVersion":"26.2.0","_hasShrinkwrap":false,"devDependencies":{"prettier":"^3.8.3","tape-six":"^1.9.0","typescript":"^6.0.3","@types/node":"^25.9.1","tape-six-proc":"^1.2.9","nano-benchmark":"^1.0.16","tape-six-playwright":"^1.0.3"},"_npmOperationalInternal":{"tmp":"tmp/stream-chain_4.2.2_1780039718280_0.1093588943059649","host":"s3://npm-registry-packages-npm-production"},"readme":"# stream-chain [![NPM version][npm-img]][npm-url] [![Node.js CI][ci-img]][ci-url]\n\n[npm-img]: https://img.shields.io/npm/v/stream-chain.svg\n[npm-url]: https://npmjs.org/package/stream-chain\n[ci-img]: https://github.com/uhop/stream-chain/actions/workflows/tests.yml/badge.svg\n[ci-url]: https://github.com/uhop/stream-chain/actions/workflows/tests.yml\n\n`stream-chain` processes streams of **objects** &mdash; records, not raw text or bytes. It is especially designed for huge streams: multi-gigabyte database dumps, append-only logs, message-queue and other live feeds generated continuously and far too large to hold in memory. You handle one record at a time while the library keeps memory flat, propagating [backpressure](https://nodejs.org/en/learn/modules/backpressuring-in-streams) from end to end.\n\nEach stage of the pipeline is an ordinary function. `stream-chain` wires your functions &mdash; alongside any Node or Web streams you already use &mdash; into a single [Duplex](https://nodejs.org/api/stream.html#stream_class_stream_duplex) stream, so the whole pipeline behaves like one stream you can compose further.\n\nWhy it might be for you:\n\n- **Simple.** A stage is an ordinary function: one input in, one value out, or `chain.none` to drop it. The model goes further &mdash; a stage can emit any number of values per input, from zero to many. A generator function does this naturally by `yield`ing; a plain function can return `chain.many([...])` instead, but that holds every value in memory, so generators are the leaner choice for fan-out.\n- **Flexible.** Mix sync functions, `async` functions, generators, async generators, and real streams in one chain &mdash; on whichever substrate you want: Node streams (the default), native Web Streams (`/web`), or substrate-free async iterables (`/core`).\n- **Performance-minded.** Throughput gets deliberate attention here &mdash; the hot paths are measured and tuned (a sync fast path, automatic stage grouping, fused file edges), the kind of care pipeline code often doesn't get. Real numbers depend on your hardware and workload, so [benchmark](https://github.com/uhop/stream-chain/wiki/benchmarks) on your own.\n- **Solid.** Lightweight, zero-dependency, bundled TypeScript typings, exercised by a broad test suite across Node, Bun, and Deno.\n\n## Example\n\nRead a huge JSONL dump, transform each record, write the result back out &mdash; record by record, in constant memory:\n\n```js\nimport chain from 'stream-chain';\nimport parseFile from 'stream-chain/jsonl/file/parser.js';\nimport stringerToFile from 'stream-chain/jsonl/file/stringer.js';\n\nconst pipeline = chain([\n  parseFile(), // read line-by-line -> {key, value} per record\n  ({value}) => (value.active ? value : chain.none), // drop inactive records\n  async user => ({...user, plan: await lookupPlan(user.id)}), // enrich asynchronously\n  stringerToFile('active-users.jsonl') // write results back out\n]);\n\npipeline.on('finish', () => console.log('done'));\npipeline.end('users.jsonl'); // a 10 TB file is fine\n```\n\nThe middle stages are plain functions; `stream-chain` handles the streaming, backpressure, and file handles. The source and sink don't have to be JSONL &mdash; any object stream works: a database cursor, an HTTP response, [stream-json](https://www.npmjs.com/package/stream-json) assembling tokens into objects, your own generator. JSONL just happens to be the most common on-disk format for object streams, so it ships in the box. See [Intro by examples](https://github.com/uhop/stream-chain/wiki/Intro) for more.\n\n## Installation\n\n```bash\nnpm i --save stream-chain\n```\n\n## What's in the box\n\n- **[chain()](<https://github.com/uhop/stream-chain/wiki/chain()>)** &mdash; the factory: turns an array of functions, arrays, and streams into one `Duplex` pipeline.\n- **Transducers:**\n  - [gen()](https://github.com/uhop/stream-chain/wiki/gen) &mdash; an async generator built from a list of functions: each stage can emit zero-to-many values per input, yielded lazily so memory stays flat no matter how much a stage fans out. It is the substrate-free core under `chain()`, and the safe default for unbounded pipelines.\n  - [fun()](https://github.com/uhop/stream-chain/wiki/fun) &mdash; an async function from a list of functions; collects outputs per input (explicit import).\n- **Adapters:**\n  - [asStream()](https://github.com/uhop/stream-chain/wiki/asStream) &mdash; wraps a function as a Node `Duplex`.\n  - [asWebStream()](https://github.com/uhop/stream-chain/wiki/asWebStream) &mdash; wraps a function as a Web Streams pair, with per-item backpressure.\n- **Helpers** &mdash; slicing (`take`, `skip`, &hellip;), reduce (`fold`, `scan`, &hellip;), stream adapters (`readableFrom`, stream pullers), and more. See [utils](https://github.com/uhop/stream-chain/wiki/utils).\n- **JSONL** &mdash; streaming [JSON Lines](https://jsonlines.org/) I/O for object streams: a substrate-free `parser()` / `stringer()`, Node and Web wrappers, fused local-file edges (`parseFile()` / `stringerToFile()`), and per-line error handling via `errorIndicator`. See [jsonl](https://github.com/uhop/stream-chain/wiki/jsonl).\n- **Subpaths** &mdash; `stream-chain` / `stream-chain/node` (default Node streams), `stream-chain/web` (native Web Streams, browser-safe), `stream-chain/core` (substrate-free async iterables).\n\nFull documentation is in the **[wiki](https://github.com/uhop/stream-chain/wiki)** &mdash; browse the [index](https://github.com/uhop/stream-chain/wiki/Home), or [search it](https://uhop.github.io/wiki-search/app/?wiki=uhop/stream-chain) by name.\n\n## License\n\nBSD-3-Clause\n\n## Release History\n\n- 4.2.5 _Bugfix: `asyncBlockWriter` releases its `FileHandle` when its own write fails, instead of leaking it._\n- 4.2.4 _Bugfix: a failed `pipe()` propagates the original error intact._\n- 4.2.3 _Bugfix: cleanup hook for user resources; cleanup double-faults now surface as an `AggregateError`._\n- 4.2.2 _Bugfix: eliminated file handle leak, cleaned up exports._\n- 4.2.1 _Factory-bundled JSONL entries &mdash; `stream-chain/node/jsonl` & `stream-chain/web/jsonl` carry `.asStream` / `.asWebStream`. Bugfix: removed `checkedParse()`, mistakenly exposed in 4.2.0._\n- 4.2.0 _JSONL file-edge components (perf): `parseFile()`, `stringerToFile()` + `errorIndicator` option. Bugfix: now `/core` chain passes strings as a single value._\n- 4.1.1 _Performance: faster synchronous pipelines._\n- 4.1.0 _Web Streams parity: new `readableWebStreamFrom()`, `reduceWebStream()`, `parserWebStream()`, `stringerWebStream()` + `dataSource()` + minor bugfix._\n- 4.0.2 _`fixUtf8Stream()` now works on browsers._\n- 4.0.1 _Minor bugfixes. No API changes._\n- 4.0.0 _Major: moved to ESM. New subpath split: `/node` (default), `/web` (native Web Streams), `/core` (substrate-free). New `asWebStream()` adapter with per-item backpressure. See the [Migration guide](https://github.com/uhop/stream-chain/wiki/Migration-V3-to-V4)._\n- 3.6.3 _TS inference updates: improvements and found bugs. Updated deps._\n- 3.6.2 _Improved TS typings: `ChainOutput<W, R>` propagates `R` to events and methods (thx [Scover](https://github.com/5cover)). Updated deps._\n- 3.6.1 _Technical release: updated deps._\n- 3.6.0 _Performance: sync-first `fun()` (~2.5&times; faster for sync pipelines, now returns `Many | Promise<Many>`). Sync fast path in `gen()` (~1.6&times; faster). Documented `null`/`undefined` handling differences. Wiki: renamed V2 files for Windows compatibility._\n- 3.5.1 _Fixed `finish` event not firing after `stop`. Web stream detection uses duck-typing instead of `instanceof` (supports non-standard web streams) (thx [Alex Yang](https://github.com/himself65)). Performance: unified fast path in `asStream()`._\n- 3.5.0 _Variadic `combineMany()` and `combineManyMut()`. Fixed `readableFrom()` unhandled rejection bug. Improved TS typings, docs, and `package.json` metadata._\n\nThe full release notes are in the wiki: [Release notes](https://github.com/uhop/stream-chain/wiki/Release-notes).\n","publish_time":1780039718432,"_cnpm_publish_time":1780039718432,"dist-tags":{"latest":"4.4.2"}}