Skip to content

StateBuilder

Declares one state of a Template’s Item state machine and the transitions leaving it.

Items are created in the default state or in a state marked initial. They move between states only through declared transitions, executed at run time via item.state.transitions.

readonly key: string

State key within its Template.


readonly parent: TemplateBuilder

Template whose Items use this state.


readonly prn: string

Platform Resource Name of the declared resource, derived from the App key and resource key.

BaseBuilder.prn


readonly transitions: Record<string, TransitionBuilder>

Transitions leaving this state, keyed by transition key.

addTransition(key, to): TransitionBuilder

Declares a transition from this state to to.

string

Transition key within this state.

StateBuilder

Target state, which must belong to the same Template.

TransitionBuilder

The transition builder for payload and Grants.

Transitions are directional; declare the reverse separately. Loops back to the same state and several transitions between the same pair of states are allowed, each under its own key.

When to belongs to another Template.

Declaring a lifecycle

const scheduled = step.addState('scheduled').setDefault();
const sending = step.addState('sending');
const sent = step.addState('sent');
scheduled.addTransition('send', sending);
sending.addTransition('complete', sent);

setDefault(): this

Makes this state the one new Items start in.

this

This builder for chaining.

The first state added to a Template is the default until this is called; a subsequent call on another state replaces it. The default state is always a valid initial state.


setDescription(description): this

Sets the description emitted into the definition and rendered in generated reference and application assets.

string

Human-readable description of the resource.

this

This builder for chaining.

BaseBuilder.setDescription


setInitial(): this

Allows new Items to be created directly in this state.

this

This builder for chaining.

The default state is initial without this call. Use it for additional entry points, such as a verified state an Item may be created in when verification already happened.

StateBuilder.setDefault


toDefinition(): StateDefinition

Emits the Definition of this state, including its transitions and whether it is default or initial.

StateDefinition