Stone.jsDocs
Paradigm

Primitives

Pipeline

@stone-js/pipeline is the chain of responsibility, distilled: send a value through an ordered list of pipes, each free to transform it, pass it on, or stop. It is the single control-flow idea behind the build phase and the middleware chain.

#Send, through, then

Create a pipeline, send a passable value through a list of pipes, and read the result with then. Each pipe receives the value and a next; call it to continue, or return early to short-circuit.

example.tsts
import { Pipeline } from '@stone-js/pipeline'

const result = await Pipeline
  .create<number, number>()
  .send(1)
  .through([
    (n, next) => next(n + 1),         // 2
    (n, next) => next(n * 10),        // 20
    (n, next) => n > 15 ? 15 : next(n) // clamps, may short-circuit
  ])
  .then((n) => n)

// result === 15
A value goes in, flows through ordered pipes, and comes out. Every control flow in the framework is this.

#The three forms of a pipe

A pipe can be a function, a class (with a handle method), or a factory, and can be referenced by alias. Guards like isFunctionPipe and isClassPipeclassify them when a pipeline processes a mixed list.

MemberTypeDescription
Pipeline.create()<T, R>() => PipelineStart a pipeline.
.send(passable)(value) => thisThe value to push through.
.through(pipes)(pipes) => thisThe ordered pipes.
.via(method)(name) => thisThe method to call on class pipes (default handle).
.then(fn)(fn) => RFinalise and read the result.
.sync(...)sync variantRun synchronously when no pipe is async.

#Why it matters

Middleware is a pipeline over events; the build phase is a pipeline over the manifest; adapters normalise causes with pipelines. Learn this one primitive and you have read the framework's control flow, from setup to response.


Stone.js

Your app exists in every runtime. Until you run it.

An open-source project by Stone Foundation
Created by Mr. Stone (Evens Pierre)