PipelineStage(name, opts) → {PipelineStage}

A single stage of a Pipeline. Stages are strung together to create the Pipeline.

new PipelineStage(name, opts) → {PipelineStage}

Creates a new PipelineStage

Parameters:
Name Type Description
name string

The name of this stage

opts Object

Options for this stage

Returns:
PipelineStage -

The newly created PipelineStage

Members

name :string

The name of this stage

nextStage :Array.<PipelineStage>

Outputs connected to this stage

Methods

static clearAll()

Removes all PipelineStages that were registered with register. Mostly used for testing.

static clearConverters()

Removes all converters that were registered with registerConverter. Mostly used for testing.

static create(name, opts) → {PipelineStage}

Creates a new stage with the corresponding name and the specified options

Parameters:
Name Type Description
name string

The name of the stage to create. Name is resolved to a stage using hte global registry (see register)

opts object

The options for creating this stage

Returns:
PipelineStage -

The newly created PipelineStage

static findConverter(inputType, outputType) → {function}

Retreive a converter function that can convert from inputType to outputType

Parameters:
Name Type Description
inputType string

Name of the input type

outputType string

Name of the output type

Returns:
function -

Returns a function that can perform the conversion, or undefined if one doesn't exist

static register(name, fn, force)

Register a new stage in the global registry

Parameters:
Name Type Default Description
name string

The name of this stage

fn function

The function to execute when this stage is run

force boolean false

If true, foreces registration even if a stage with the same name already exists

static registerConverter(inputType, outputType, fn, force)

Register a function for converting between types. Used to automatically convert data types between Pipeline stages

Parameters:
Name Type Default Description
inputType string

The name of the input type

outputType string

The name of the output type

fn function

A function that takes data of type inputType, converts it to outputType, and returns the converted value

force boolean false

If true, forces registration even if an existing converter for the inputType/outputType pair already exists

async run(input) → {Promise.<any>}

Executes this stage of the pipeline with the specified input

Parameters:
Name Type Description
input any

The data to use to execute this stage of the Pipeline

Returns:
Promise.<any> -

A Promise that resolves to the result of this stage or rejects with an Error.

setOutput(stage, force)

Set the next stage after this one. Will automatically convert between data types using a converter if necessary.

Parameters:
Name Type Default Description
stage PipelineStage

The next stage

force boolean false

If true, sets the next stage even if one already exists.