Skip to content

Context Keywords

Keywords for working with context variables and state.

Assignment

becomes

Sets a context value.

flow
$total becomes 100
$status becomes "active"

is

Used in given: to set initial values.

flow
given:
  $total: number is 100
  order is in #pending

Arithmetic Operations

increases by

Adds to a numeric value.

flow
$total increases by 25
$retry_count increases by 1

decreases by

Subtracts from a numeric value.

flow
$balance decreases by $amount
$stock decreases by $quantity

Collection Operations

adds

Adds an item to a collection.

flow
$items adds "Laptop"
$tags adds "priority"

removes

Removes an item from a collection.

flow
$items removes "Mouse"
$tags removes "draft"

clears

Empties a collection.

flow
$items clears
$cart clears

State Keywords

State Transition Verbs

All equivalent:

  • moves to
  • transitions to
  • enters
  • becomes
  • changes to
flow
order moves to #paid
order transitions to #approved
payment enters #processing
ticket becomes #closed

is in / is not in

Checks current state.

flow
? order is in #pending
  process order

? order is not in #cancelled
  allow modification

Context Validation

Post-Action Validation Table

Defines constraints for context variables after actions. The table follows the action(s).

Single variable:

flow
$retry_count increases by 1
  | $retry_count | required, integer, between 0 and 5 |

Multiple variables:

flow
$total increases by $item.price
$item_count increases by 1
  | $total      | required, number, greater than 0 |
  | $item_count | required, integer                |

Validation Rules

Rules are comma-separated. Common rules:

RuleDescription
requiredMust be present and not null
optionalMay be absent
string, number, integer, boolean, array, objectType rules
greater than N, less than N, between N and MNumeric rules
at least N, at most NNumeric bounds
min N characters, max N charactersString length
valid email, valid uuid, valid urlFormat rules
one of "a", "b"Enum rule
bailStop on first error

See Data Validation for complete rule reference.

Constraint Violation

When a constraint is violated:

  1. The action is rolled back (value unchanged)
  2. :constraint_violated event is emitted
flow
on :constraint_violated
  ? $field is "$retry_count"
    emit :max_retries_exceeded to @customer

Released under the MIT License.