Skip to main content

pipeline

$pipeline

Executes a sequence of processors in order, passing the output of each processor as input to the next. The final processor's output becomes the result.

Note: Handler arrays (normalizers, validators, etc.) implicitly create pipelines, so this processor is rarely used directly. It's primarily used internally by the schema compiler to aggregate handler arrays into single compiled processors.

Parameters

  • processors (Array<ProcessorSpec>, required): Array of processor specifications to execute in sequence. Each element can be a string keyword (e.g., '$trim'), a parameterized processor object (e.g., {$range: {min: 0}}), a RegExp, or a function.

Behavior: Processors execute left-to-right. If any processor throws an error, the pipeline stops and the error propagates. Each processor receives the output of the previous processor as its input value.

Example

// Explicit pipeline (equivalent to passing an array to .normalizer())
new Schema('string').normalizer({$pipeline: ['$trim', '$lowercase', '$alphanum']})

// Use $pipeline inside a conditional to chain processors on a branch
new Schema('string').transformer({
$if: [
'$numeric',
{$pipeline: ['$number', {$clamp: {min: 0, max: 100}}]},
]
})