{"id":29436870,"url":"https://github.com/stone-foundation/stone-js-pipeline","last_synced_at":"2025-07-13T05:06:55.714Z","repository":{"id":197693992,"uuid":"698604861","full_name":"stone-foundation/stone-js-pipeline","owner":"stone-foundation","description":"An implementation based on the Chain of Responsibility (aka CoR) design pattern","archived":false,"fork":false,"pushed_at":"2025-06-12T00:38:04.000Z","size":347,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-12T00:56:39.695Z","etag":null,"topics":["context-aware","continuum-architecture","javascript","official-stonejs","stone-foundation","stonejs","stonejs-core","typescript"],"latest_commit_sha":null,"homepage":"https://stonejs.dev","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stone-foundation.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-09-30T12:15:32.000Z","updated_at":"2025-06-12T00:36:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"60b76d38-cb6c-43d3-9627-55b344805ffd","html_url":"https://github.com/stone-foundation/stone-js-pipeline","commit_stats":null,"previous_names":["stonemjs/pipeline","stone-foundation/stone-js-pipeline"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/stone-foundation/stone-js-pipeline","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stone-foundation%2Fstone-js-pipeline","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stone-foundation%2Fstone-js-pipeline/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stone-foundation%2Fstone-js-pipeline/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stone-foundation%2Fstone-js-pipeline/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stone-foundation","download_url":"https://codeload.github.com/stone-foundation/stone-js-pipeline/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stone-foundation%2Fstone-js-pipeline/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265091734,"owners_count":23710033,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["context-aware","continuum-architecture","javascript","official-stonejs","stone-foundation","stonejs","stonejs-core","typescript"],"created_at":"2025-07-13T05:06:55.015Z","updated_at":"2025-07-13T05:06:55.702Z","avatar_url":"https://github.com/stone-foundation.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Stone.js - Pipeline\n\n[![npm](https://img.shields.io/npm/l/@stone-js/pipeline)](https://opensource.org/licenses/MIT)\n[![npm](https://img.shields.io/npm/v/@stone-js/pipeline)](https://www.npmjs.com/package/@stone-js/pipeline)\n[![npm](https://img.shields.io/npm/dm/@stone-js/pipeline)](https://www.npmjs.com/package/@stone-js/pipeline)\n![Maintenance](https://img.shields.io/maintenance/yes/2025)\n[![Build Status](https://github.com/stone-foundation/stone-js-pipeline/actions/workflows/main.yml/badge.svg)](https://github.com/stone-foundation/stone-js-pipeline/actions/workflows/main.yml)\n[![Publish Package to npmjs](https://github.com/stone-foundation/stone-js-pipeline/actions/workflows/release.yml/badge.svg)](https://github.com/stone-foundation/stone-js-pipeline/actions/workflows/release.yml)\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=stone-foundation_stone-js-pipeline\u0026metric=alert_status)](https://sonarcloud.io/summary/new_code?id=stone-foundation_stone-js-pipeline)\n[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=stone-foundation_stone-js-pipeline\u0026metric=coverage)](https://sonarcloud.io/summary/new_code?id=stone-foundation_stone-js-pipeline)\n[![Security Policy](https://img.shields.io/badge/Security-Policy-blue.svg)](./SECURITY.md)\n[![CodeQL](https://github.com/stone-foundation/stone-js-pipeline/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/stone-foundation/stone-js-pipeline/security/code-scanning)\n[![Dependabot Status](https://img.shields.io/badge/Dependabot-enabled-brightgreen.svg)](https://github.com/stone-foundation/stone-js-pipeline/network/updates)\n[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)\n\nAn implementation of the Chain of Responsibility (CoR) pattern tailored for modern JavaScript and TypeScript apps using the Continuum Architecture philosophy.\n\n---\n\n## Overview\n\nThe `Pipeline` class is a flexible processor of \"passable\" values through a series of configurable steps called pipes. Pipes can be functions, factory-generated handlers, or class instances. Pipelines can run synchronously or asynchronously, support custom hook events, and allow pipe resolution via a resolver for advanced dependency injection scenarios.\n\n## Installation\n\n```bash\nnpm i @stone-js/pipeline\n# or\nyarn add @stone-js/pipeline\n# or\npnpm add @stone-js/pipeline\n```\n\n\u003e \\[!IMPORTANT]\n\u003e This package is **pure ESM**. Ensure your `package.json` includes `\"type\": \"module\"` or configure your bundler appropriately.\n\n```ts\nimport { Pipeline } from '@stone-js/pipeline'\n```\n\n## Quick Start\n\n```ts\nimport { Pipeline } from '@stone-js/pipeline'\n\nconst addOne = (v, next) =\u003e next(v + 1)\nconst timesTwo = (v, next) =\u003e next(v * 2)\n\nconst result = Pipeline.create\u003cnumber\u003e()\n  .send(1)\n  .through(addOne, timesTwo)\n  .sync()\n  .thenReturn()\n\nconsole.log(result) // Output: 4\n```\n\n## Features\n\n* Chain-of-responsibility execution\n* Supports function, factory, and class-based pipes\n* Works in both sync and async mode\n* Custom `resolver` support\n* Pipe lifecycle hooks via `on()`\n* Priority-based execution order\n* Type-safe with TypeScript, compatible with JavaScript\n\n## Usage Patterns\n\n### Synchronous Pipeline\n\n```ts\nconst pipeline = Pipeline.create\u003cnumber\u003e()\n  .send(2)\n  .through([\n    (v, next) =\u003e next(v + 3),\n    (v, next) =\u003e next(v * 2)\n  ])\n  .sync()\n\nconst result = pipeline.thenReturn()\nconsole.log(result) // Output: 10\n```\n\n### Asynchronous Pipeline\n\n```ts\nconst fetch = async (v, next) =\u003e next(await mockFetch(v))\nconst mockFetch = async (v) =\u003e new Promise(res =\u003e setTimeout(() =\u003e res(v * 10), 500))\n\nconst result = await Pipeline.create\u003cnumber\u003e()\n  .send(5)\n  .through(fetch)\n  .thenReturn()\n\nconsole.log(result) // Output: 50\n```\n\n### Using `.pipe()` Incrementally\n\n```ts\nconst result = Pipeline.create\u003cnumber\u003e()\n  .send(1)\n  .pipe(v =\u003e v + 1)\n  .pipe(v =\u003e v * 5)\n  .sync()\n  .thenReturn()\n\nconsole.log(result) // Output: 10\n```\n\n### Resolver for Dependency Injection\n\n```ts\nclass MyPipe {\n  handle(v, next) {\n    return next(`Resolved: ${v}`)\n  }\n}\n\nconst resolver = () =\u003e new MyPipe()\n\nconst result = Pipeline.create\u003cstring\u003e({ resolver })\n  .send('value')\n  .through({ module: MyPipe, isClass: true })\n  .sync()\n  .thenReturn()\n\nconsole.log(result) // Output: Resolved: value\n```\n\n### Hooking Into Lifecycle\n\n```ts\nconst pipeline = Pipeline.create\u003cnumber\u003e()\n  .on('onProcessingPipe', ({ passable }) =\u003e console.log('Processing', passable))\n  .on('onPipeProcessed', ({ passable }) =\u003e console.log('Processed', passable))\n  .send(3)\n  .through((v, next) =\u003e next(v + 2))\n  .sync()\n\nconst result = pipeline.thenReturn()\nconsole.log(result) // Output: 5\n```\n\n### Factory and Class-Based Pipes\n\n```ts\nconst factoryPipe = () =\u003e (v, next) =\u003e next(v + 2)\n\nclass CustomPipe {\n  handle(v, next) {\n    return next(v * 3)\n  }\n}\n\nconst result = Pipeline.create\u003cnumber\u003e()\n  .send(1)\n  .through(\n    { module: CustomPipe, isClass: true },\n    { module: factoryPipe, isFactory: true }\n  )\n  .sync()\n  .thenReturn()\n\nconsole.log(result) // Output: 9\n```\n\n### Using `.via()` to Customize Method Name\n\n```ts\nclass Pipe {\n  transform(value, next) {\n    return next(value + '!')\n  }\n}\n\nconst result = Pipeline.create\u003cstring\u003e()\n  .send('Wow')\n  .through({ module: Pipe, isClass: true })\n  .via('transform')\n  .sync()\n  .thenReturn()\n\nconsole.log(result) // Output: Wow!\n```\n\n### Priority-based Execution\n\n```ts\nconst p1 = { module: (v, next) =\u003e next(v + 1), priority: 10 }\nconst p2 = { module: (v, next) =\u003e next(v * 2), priority: 20 }\n\nconst result = Pipeline.create\u003cnumber\u003e()\n  .send(1)\n  .through(p1, p2)\n  .sync()\n  .thenReturn()\n\nconsole.log(result) // Output: 4 → (1 + 1) * 2\n```\n\n## API\n\nAll methods are chainable:\n\n* `.send(passable)`\n* `.through(...pipes)`\n* `.pipe(...pipes)`\n* `.sync(true|false)`\n* `.via(methodName)`\n* `.on(hookName, listener)`\n* `.then(fn)`\n* `.thenReturn()`\n\n\u003e Pipes can be:\n\u003e\n\u003e * `Function`: `(value, next) =\u003e next(...)`\n\u003e * `Factory`: `() =\u003e (value, next) =\u003e next(...)`\n\u003e * `Class`: `new MyPipe().handle(...)`\n\n\n## Summary\n\nThe `Pipeline` class provides a powerful and flexible way to process values through a series of steps, allowing for both synchronous and asynchronous operations. It supports various types of pipes, including functions, factories, and classes, and offers lifecycle hooks for custom behavior during processing.\n\n## Learn More\n\nThis package is part of the Stone.js ecosystem, a modern JavaScript framework built around the Continuum Architecture.\n\nExplore the full documentation: [https://stonejs.dev](https://stonejs.dev)\n\n## API documentation\n\n* [API](https://github.com/stone-foundation/stone-js-pipeline/blob/main/docs)\n\n## Contributing\n\nSee [Contributing Guide](https://github.com/stone-foundation/stone-js-pipeline/blob/main/CONTRIBUTING.md)\n\n## Credits\n\nInspired by [Laravel's Pipeline](https://github.com/laravel/framework/blob/10.x/src/Illuminate/Pipeline/Pipeline.php)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstone-foundation%2Fstone-js-pipeline","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstone-foundation%2Fstone-js-pipeline","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstone-foundation%2Fstone-js-pipeline/lists"}