StateBuilder
Declares one state of a Template’s Item state machine and the transitions leaving it.
Remarks
Section titled “Remarks”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.
- TemplateBuilder.addState
- Add states and transitions
- StateDefinition for the emitted Definition
- WriteStateInstance for executing transitions inside an execution
Extends
Section titled “Extends”Properties
Section titled “Properties”
readonlykey:string
State key within its Template.
parent
Section titled “parent”
readonlyparent:TemplateBuilder
Template whose Items use this state.
readonlyprn:string
Platform Resource Name of the declared resource, derived from the App key and resource key.
Inherited from
Section titled “Inherited from”transitions
Section titled “transitions”
readonlytransitions:Record<string,TransitionBuilder>
Transitions leaving this state, keyed by transition key.
Methods
Section titled “Methods”addTransition()
Section titled “addTransition()”addTransition(
key,to):TransitionBuilder
Declares a transition from this state to to.
Parameters
Section titled “Parameters”string
Transition key within this state.
StateBuilder
Target state, which must belong to the same Template.
Returns
Section titled “Returns”The transition builder for payload and Grants.
Remarks
Section titled “Remarks”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.
Throws
Section titled “Throws”When to belongs to another Template.
Example
Section titled “Example”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()
Section titled “setDefault()”setDefault():
this
Makes this state the one new Items start in.
Returns
Section titled “Returns”this
This builder for chaining.
Remarks
Section titled “Remarks”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()
Section titled “setDescription()”setDescription(
description):this
Sets the description emitted into the definition and rendered in generated reference and application assets.
Parameters
Section titled “Parameters”description
Section titled “description”string
Human-readable description of the resource.
Returns
Section titled “Returns”this
This builder for chaining.
Inherited from
Section titled “Inherited from”setInitial()
Section titled “setInitial()”setInitial():
this
Allows new Items to be created directly in this state.
Returns
Section titled “Returns”this
This builder for chaining.
Remarks
Section titled “Remarks”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.
toDefinition()
Section titled “toDefinition()”toDefinition():
StateDefinition
Emits the Definition of this state, including its transitions and whether it is default or initial.

