Skip to content

Commit 32dde40

Browse files
reid-spencerclaude
andcommitted
Upgrade RIDDL to 1.15.0 and update State documentation
States are now branches that can contain handlers and comments, enabling proper state machine modeling where each state defines its own message-handling behavior. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2c04e5c commit 32dde40

6 files changed

Lines changed: 137 additions & 30 deletions

File tree

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ lazy val root = Root(
1818
devs = developers
1919
).configure(
2020
With.Scala3.configure(version = Some("3.7.4")),
21-
With.Riddl.library(version = "1.13.1", nonJVMDependency = false)
21+
With.Riddl.library(version = "1.15.0", nonJVMDependency = false)
2222
).settings(
2323
resolvers += "GitHub Package Registry" at "https://maven.pkg.github.com/ossuminc/riddl",
2424

docs/riddl/concepts/handler.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,23 @@ state accordingly. Projector handlers also respond to queries that read from
6464
the projected data.
6565

6666
## State Handler
67-
State handlers process messages while an entity is in that specific
68-
state, presumably with the intent of updating that state by generating
69-
events from commands.
67+
State handlers process messages while an entity is in that
68+
specific state. They are defined inside a state's body,
69+
enabling each state to respond to messages differently—the
70+
foundation for modeling state machines in RIDDL. When an
71+
entity transitions to a new state via a `morph` statement,
72+
the new state's handlers become active.
73+
74+
```riddl
75+
state ActiveOrder of ActiveOrderData is {
76+
handler ActiveOrderHandler is {
77+
on command ShipOrder {
78+
morph entity Order to state Order.ShippedOrder
79+
with command ShipOrder
80+
}
81+
}
82+
}
83+
```
7084

7185
## Occurs In
7286
* [Adaptors](adaptor.md)

docs/riddl/concepts/state.md

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,46 @@ title: "States"
33
draft: false
44
---
55

6-
A State defines the state of an [entity](entity.md). It is
7-
defined as a set of [fields](field.md) with a
8-
[handler](handler.md) that defines
9-
how messages cause changes to the value of those fields.
6+
A State defines a named state of an [entity](entity.md). It
7+
references a [type](type.md) that defines the data structure
8+
for the state, and optionally contains
9+
[handlers](handler.md) that define how messages are processed
10+
while the entity is in that state.
1011

11-
An [entity](entity.md) can have multiple state definitions with
12-
the implication that this entity would be considered a
13-
[Finite State Machine](https://en.wikipedia.org/wiki/Finite-state_machine).
14-
However, it would only be such if the entity used the
15-
[finite state machine](entity.md#finite-state-machine)
16-
[option](option.md).
12+
An [entity](entity.md) can have multiple state definitions.
13+
When an entity has multiple states with their own handlers,
14+
it naturally models a
15+
[Finite State Machine](https://en.wikipedia.org/wiki/Finite-state_machine)
16+
—each state responds to messages differently. Use the
17+
[finite state machine](entity.md#finite-state-machine)
18+
[option](option.md) to make this intent explicit.
1719

20+
States are branches in the AST, meaning they can contain
21+
their own definitions. The `morph` statement transitions an
22+
entity from one state to another, changing which handlers
23+
are active.
24+
25+
### Syntax
26+
27+
```riddl
28+
state ActiveOrder of ActiveOrderData is {
29+
handler ActiveOrderHandler is {
30+
on command CancelOrder { ??? }
31+
on command ShipOrder { ??? }
32+
}
33+
}
34+
```
35+
36+
The state body (with handlers) is optional—a state can also
37+
be defined simply as:
38+
39+
```riddl
40+
state ActiveOrder of ActiveOrderData
41+
```
1842

1943
## Occurs In
2044
* [Entities](entity.md)
2145

2246
## Contains
23-
* [Fields](field.md)
24-
* [Handler](handler.md)
47+
* [Handlers](handler.md)
48+
* [Comments](comment.md)

docs/riddl/guides/authors/index.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,35 +452,45 @@ Entities can morph between states to model lifecycles:
452452

453453
```riddl
454454
entity Order is {
455-
state Pending is {
455+
record PendingData is { orderId is OrderId }
456+
record PaidData is { orderId is OrderId, paidAt is TimeStamp }
457+
record ShippedData is { orderId is OrderId, shippedAt is TimeStamp }
458+
record CancelledData is { orderId is OrderId }
459+
460+
state Pending of PendingData is {
456461
handler PendingHandler is {
457462
on command ConfirmPayment {
458463
morph entity Order to state Paid
464+
with command ConfirmPayment
459465
send event PaymentConfirmed to outlet Events
460466
}
461467
on command Cancel {
462468
morph entity Order to state Cancelled
469+
with command Cancel
463470
send event OrderCancelled to outlet Events
464471
}
465472
}
466473
}
467474
468-
state Paid is {
475+
state Paid of PaidData is {
469476
handler PaidHandler is {
470477
on command Ship {
471478
morph entity Order to state Shipped
479+
with command Ship
472480
send event OrderShipped to outlet Events
473481
}
474482
}
475483
}
476484
477-
state Shipped is {
485+
state Shipped of ShippedData is {
478486
// Final state - no transitions out
479487
}
480488
481-
state Cancelled is {
489+
state Cancelled of CancelledData is {
482490
// Final state - no transitions out
483491
}
492+
} with {
493+
option is finite state machine
484494
}
485495
```
486496

docs/riddl/references/language-reference.md

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -263,19 +263,27 @@ metadata and cannot contain other RIDDL definitions.
263263

264264
## Entities and States
265265

266-
Entities are stateful objects with explicit states:
266+
Entities are stateful objects with explicit states. Each state
267+
references a type that defines its data structure, and can
268+
optionally contain handlers that define behavior while the
269+
entity is in that state:
267270

268271
```
269272
entity Product is {
270-
state ProductData of ProductRecord with {
271-
briefly as "Product state containing all product information"
272-
described by {
273-
| Contains the complete product information including identification,
274-
| pricing, and inventory information.
273+
state ProductData of ProductRecord is {
274+
handler ProductHandler is {
275+
on command UpdatePrice {
276+
set field ProductRecord.price to "field price of
277+
command UpdatePrice"
278+
send event PriceUpdated to
279+
outlet ProductEvents.Products
280+
}
275281
}
282+
} with {
283+
briefly as "Product state with update handling"
276284
}
277-
278-
// Commands, events, handlers
285+
286+
// Commands, events, types
279287
} with {
280288
briefly as "Represents a purchasable item"
281289
described by {
@@ -285,6 +293,16 @@ entity Product is {
285293
}
286294
```
287295

296+
States can also be defined without a body when handlers are
297+
defined at the entity level instead:
298+
299+
```
300+
entity SimpleProduct is {
301+
state ProductData of ProductRecord
302+
handler ProductHandler is { ??? }
303+
}
304+
```
305+
288306
States reference record types that define the data structure:
289307

290308
```
@@ -296,8 +314,47 @@ type ProductRecord is {
296314
} with {
297315
briefly as "Record type containing product data"
298316
described by {
299-
| Defines the structure of product data including identification and pricing.
317+
| Defines the structure of product data including
318+
| identification and pricing.
319+
}
320+
}
321+
```
322+
323+
When an entity has multiple states with their own handlers,
324+
it models a finite state machine—each state responds to
325+
messages differently, and the `morph` statement transitions
326+
between states:
327+
328+
```
329+
entity Order is {
330+
state PendingOrder of PendingOrderData is {
331+
handler PendingHandler is {
332+
on command ConfirmOrder {
333+
morph entity Order to state Order.ActiveOrder
334+
with command ConfirmOrder
335+
}
336+
}
300337
}
338+
state ActiveOrder of ActiveOrderData is {
339+
handler ActiveHandler is {
340+
on command ShipOrder {
341+
morph entity Order to state Order.ShippedOrder
342+
with command ShipOrder
343+
}
344+
on command CancelOrder {
345+
morph entity Order to state Order.CancelledOrder
346+
with command CancelOrder
347+
}
348+
}
349+
}
350+
state ShippedOrder of ShippedOrderData is {
351+
handler ShippedHandler is { ??? }
352+
}
353+
state CancelledOrder of CancelledOrderData is {
354+
handler CancelledHandler is { ??? }
355+
}
356+
} with {
357+
option is finite state machine
301358
}
302359
```
303360

docs/riddl/references/riddl-grammar.ebnf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ entity = "entity" identifier is "{" entity_body "}" [with_metadata] ;
6464
entity_body = entity_definitions | "???" ;
6565
entity_definitions = {entity_content}+ ;
6666
entity_content = processor_definition_contents | state | entity_include ;
67-
state = "state" identifier ("of" | is) type_ref [with_metadata] ;
67+
state = "state" identifier ("of" | is) type_ref [state_body] [with_metadata] ;
68+
state_body = is "{" (state_content+ | "???") "}" ;
69+
state_content = handler | comment ;
6870
entity_include = "include" literal_string ;
6971
7072
(* Processor Definition Contents *)

0 commit comments

Comments
 (0)