Skip to content
@tde.io/plexis  ·  npm install @tde.io/plexis  ·  npm  ·  GitHub

Handler Input Types

These types are passed as the second argument to guards, actions, hooks, and fork conditions.

Passed to flow guard functions: guard: (ctx, input: GuardInput) => boolean.

FieldTypeRequiredDescription
eventstringYesEvent name that triggered the transition check
payloadunknownNoOptional event payload
traceIdstringYesActive trace ID
import { defineDomain, when, on } from '@tde.io/plexis';
import type { GuardInput } from '@tde.io/plexis';
type Ctx = { balance: number };
const account = defineDomain<Ctx>('account', () => {
when('active', () => {
on('withdraw', () => {
guard((ctx, input: GuardInput) => {
const amount = input.payload as number;
return ctx.balance >= amount;
});
return target('active');
});
});
return { context: { balance: 100 }, initial: 'active' };
});

Passed to flow action functions: action: (ctx, input: OnActionInput) => PatchLike.

FieldTypeRequiredDescription
eventstringYesEvent name that triggered the transition
payloadunknownNoOptional event payload
traceIdstringYesActive trace ID
import { defineDomain, when, on } from '@tde.io/plexis';
import type { OnActionInput } from '@tde.io/plexis';
type Ctx = { balance: number; lastEvent: string };
const account = defineDomain<Ctx>('account', () => {
when('active', () => {
on('deposit', () => {
action((ctx, input: OnActionInput) => ({
balance: ctx.balance + (input.payload as number),
lastEvent: input.event,
}));
return target('active');
});
});
return { context: { balance: 0, lastEvent: '' }, initial: 'active' };
});

Passed to enter and exit hooks: enter(fn) where fn: (ctx, input: PhaseHookInput) => PatchLike.

FieldTypeRequiredDescription
eventstringNoEvent that caused the phase entry or exit; absent for the initial phase entry
payloadunknownNoOptional event payload
traceIdstringYesActive trace ID
import { defineDomain, when, enter, on, target } from '@tde.io/plexis';
import type { PhaseHookInput } from '@tde.io/plexis';
type Ctx = { enteredVia: string };
const machine = defineDomain<Ctx>('machine', () => {
when('idle', () => { on('start', target('running')); });
when('running', () => {
enter((ctx, input: PhaseHookInput) => ({
enteredVia: input.event ?? 'initial',
}));
on('stop', target('idle'));
});
return { context: { enteredVia: '' }, initial: 'idle' };
});

Passed to pipeline node action functions: action(fn) where fn: (ctx, input: PipelineActionInput) => PatchLike.

FieldTypeRequiredDescription
inputunknownNoValue passed as the second argument to pipeline.run(context, input?)
nodeIdstringYesID of the current node
pipelineIdstringYesID of the pipeline
traceIdstringYesActive trace ID
import { definePipeline, node, terminal } from '@tde.io/plexis';
import type { PipelineActionInput } from '@tde.io/plexis';
type Ctx = { processed: boolean; inputValue: unknown };
const pipeline = definePipeline<Ctx>('process', () => {
node('handle', terminal((ctx, input: PipelineActionInput) => ({
processed: true,
inputValue: input.input,
})));
return { initial: 'handle' };
});
// The value passed to run() is available as input.input in the action:
await pipeline.run({ processed: false, inputValue: null }, { userId: 'u1' });

Passed to fork condition functions: fork(label, target, (ctx, input: PipelineConditionInput) => boolean).

FieldTypeRequiredDescription
inputunknownNoValue passed as the second argument to pipeline.run(context, input?)
nodeIdstringYesID of the current node
pipelineIdstringYesID of the pipeline
traceIdstringYesActive trace ID
import { definePipeline, node, action, fork, target, terminal } from '@tde.io/plexis';
import type { PipelineConditionInput } from '@tde.io/plexis';
type Ctx = { score: number };
const pipeline = definePipeline<Ctx>('grade', () => {
node('decide', () => {
fork(
'pass',
target('pass'),
(ctx, input: PipelineConditionInput) => {
const threshold = (input.input as { threshold: number }).threshold;
return ctx.score >= threshold;
}
);
fork('fail', target('fail'));
});
node('pass', terminal());
node('fail', terminal());
return { initial: 'decide' };
});