Skip to content

ActionBuilder

ActionBuilder is the fluent API for composing a pipeline. You add activities with .do(), configure hooks, and register a done() finalizer, then hand the builder to an ActionRunner.

import {ActionBuilder} from "@gesslar/actioneer"
new ActionBuilder(action?, config?)
ParameterTypeDescription
actionobject (optional)An action instance with a setup(builder) method. If provided, its setup(builder) runs when the pipeline is built — lazily, on the first run()/pipe() — to populate the pipeline.
configobject (optional)Options: {tag?, debug?}.
// With an action
const builder = new ActionBuilder(new MyAction())
// Empty — add activities directly (common for nested builders)
const nested = new ActionBuilder()

Appends an activity to the pipeline. The arguments after name determine the mode. Returns the builder for chaining.

OverloadMode
.do(name, operation)Default — run once
.do(name, ACTIVITY.WHILE, predicate, operation)WHILE
.do(name, ACTIVITY.UNTIL, predicate, operation)UNTIL
.do(name, ACTIVITY.IF, predicate, operation)IF
.do(name, ACTIVITY.BREAK, predicate)BREAK
.do(name, ACTIVITY.CONTINUE, predicate)CONTINUE
.do(name, ACTIVITY.SPLIT, splitter, rejoiner, operation)SPLIT

The operation may be a function (context) => unknown or a nested ActionBuilder.

Configures the pipeline with a pre-instantiated hooks object. Works in both Node.js and the browser. Returns the builder.

builder.withHooks(new MyActionHooks({debug: console.log}))

Calling withHooks() with the same instance again is idempotent. Configuring hooks more than once with a different source throws "Hooks have already been configured."

Node.js only. Loads hooks from a module file when the action is built. Returns the builder.

ParameterTypeDescription
hooksFilestringPath to the hooks module file.
hooksKindstringName of the exported hooks class to instantiate.
builder.withHooksFile("./hooks/MyActionHooks.js", "MyActionHooks")

See Lifecycle Hooks for the hook authoring conventions.

Sets the action instance if not already set, propagating it to any existing activity definitions that lack one. Primarily used to pass parent action context to nested builders. Returns the builder.

new ActionBuilder().withAction(this)

Registers a finalizer that runs after every activity completes — even on error. Whatever it returns becomes the pipeline’s final result. The callback is bound to the action instance and may be async. Returns the builder.

builder.done(ctx => ({total: ctx.a + ctx.b}))

See Finalizing with done() for behavior details.