@diagc/cli 1.8.0 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/assets/guide/compose.md +84 -0
- package/assets/guide/index.md +9 -1
- package/assets/guide/state-machine.md +77 -0
- package/assets/skill/SKILL.md +3 -2
- package/assets/starters/state-machine/starter.diagram.ts +42 -0
- package/assets/studio/assets/index-Cvrj99Nu.js +114 -0
- package/assets/studio/assets/index-DyO7mVg-.css +1 -0
- package/assets/studio/index.html +2 -2
- package/assets/viewer/index.html +35 -33
- package/assets/viewer/shared/caveat-cyrillic-500-normal.woff +0 -0
- package/assets/viewer/shared/caveat-cyrillic-500-normal.woff2 +0 -0
- package/assets/viewer/shared/caveat-cyrillic-700-normal.woff +0 -0
- package/assets/viewer/shared/caveat-cyrillic-700-normal.woff2 +0 -0
- package/assets/viewer/shared/caveat-cyrillic-ext-500-normal.woff +0 -0
- package/assets/viewer/shared/caveat-cyrillic-ext-500-normal.woff2 +0 -0
- package/assets/viewer/shared/caveat-cyrillic-ext-700-normal.woff +0 -0
- package/assets/viewer/shared/caveat-cyrillic-ext-700-normal.woff2 +0 -0
- package/assets/viewer/shared/caveat-latin-500-normal.woff +0 -0
- package/assets/viewer/shared/caveat-latin-500-normal.woff2 +0 -0
- package/assets/viewer/shared/caveat-latin-700-normal.woff +0 -0
- package/assets/viewer/shared/caveat-latin-700-normal.woff2 +0 -0
- package/assets/viewer/shared/caveat-latin-ext-500-normal.woff +0 -0
- package/assets/viewer/shared/caveat-latin-ext-500-normal.woff2 +0 -0
- package/assets/viewer/shared/caveat-latin-ext-700-normal.woff +0 -0
- package/assets/viewer/shared/caveat-latin-ext-700-normal.woff2 +0 -0
- package/assets/viewer/shared/chakra-petch-latin-500-normal.woff2 +0 -0
- package/assets/viewer/shared/chakra-petch-latin-600-normal.woff2 +0 -0
- package/assets/viewer/shared/inter-latin-400-normal.woff2 +0 -0
- package/assets/viewer/shared/inter-latin-600-normal.woff2 +0 -0
- package/assets/viewer/shared/jetbrains-mono-latin-400-normal.woff2 +0 -0
- package/assets/viewer/shared/jetbrains-mono-latin-600-normal.woff2 +0 -0
- package/assets/viewer/shared/kalam-devanagari-400-normal.woff +0 -0
- package/assets/viewer/shared/kalam-devanagari-400-normal.woff2 +0 -0
- package/assets/viewer/shared/kalam-devanagari-700-normal.woff +0 -0
- package/assets/viewer/shared/kalam-devanagari-700-normal.woff2 +0 -0
- package/assets/viewer/shared/kalam-latin-400-normal.woff +0 -0
- package/assets/viewer/shared/kalam-latin-400-normal.woff2 +0 -0
- package/assets/viewer/shared/kalam-latin-700-normal.woff +0 -0
- package/assets/viewer/shared/kalam-latin-700-normal.woff2 +0 -0
- package/assets/viewer/shared/kalam-latin-ext-400-normal.woff +0 -0
- package/assets/viewer/shared/kalam-latin-ext-400-normal.woff2 +0 -0
- package/assets/viewer/shared/kalam-latin-ext-700-normal.woff +0 -0
- package/assets/viewer/shared/kalam-latin-ext-700-normal.woff2 +0 -0
- package/assets/viewer/shared/viewer.css +2 -0
- package/assets/viewer/shared/viewer.js +48 -0
- package/dist/api/diagrams.d.ts +20 -0
- package/dist/api/diagrams.js +69 -3
- package/dist/api/handlers.d.ts +1 -1
- package/dist/api/handlers.js +1 -1
- package/dist/api/routes.js +13 -0
- package/dist/cli/parse.d.ts +1 -0
- package/dist/cli/parse.js +1 -0
- package/dist/cli.js +2 -0
- package/dist/commands/compile.d.ts +1 -1
- package/dist/commands/compile.js +5 -6
- package/dist/commands/lint.js +4 -5
- package/dist/commands/publish.d.ts +1 -1
- package/dist/commands/publish.js +15 -7
- package/dist/commands/shared.d.ts +9 -0
- package/dist/commands/shared.js +30 -1
- package/dist/compile.d.ts +11 -1
- package/dist/compile.js +25 -6
- package/dist/guide.js +23 -10
- package/dist/home.d.ts +5 -1
- package/dist/home.js +2 -0
- package/dist/init.d.ts +1 -1
- package/dist/init.js +1 -1
- package/dist/lint.js +2 -1
- package/dist/loadHints.d.ts +8 -0
- package/dist/loadHints.js +36 -0
- package/dist/names.js +1 -1
- package/dist/publish/html.d.ts +13 -0
- package/dist/publish/html.js +54 -2
- package/dist/publish/publish.d.ts +10 -0
- package/dist/publish/publish.js +45 -23
- package/dist/publish/snapshot.d.ts +21 -2
- package/dist/publish/snapshot.js +95 -18
- package/dist/text/content.js +21 -4
- package/dist/text/glyphs.d.ts +8 -0
- package/dist/text/glyphs.js +12 -0
- package/dist/text/scene.js +1 -1
- package/dist/text/vocabulary.js +14 -0
- package/dist/tui/details.js +2 -1
- package/dist/watch.js +23 -7
- package/package.json +2 -2
- package/assets/studio/assets/index-CB6jjAka.js +0 -112
- package/assets/studio/assets/index-DzVDK5uD.css +0 -1
package/README.md
CHANGED
|
@@ -42,7 +42,7 @@ diagc studio # opens the editor, recompiling as you edit
|
|
|
42
42
|
|
|
43
43
|
`diagc --help` lists every command and flag, and the [CLI reference](https://ferroman.github.io/diagc/docs/reference/cli.html) has the details.
|
|
44
44
|
|
|
45
|
-
PNG export drives headless Chrome. Without one, `publish` writes HTML and says so;
|
|
45
|
+
PNG export drives headless Chrome. Without one, `publish` writes HTML and says so; `npx playwright-core install chromium` gets a browser it finds, or point `CHROME_PATH` at one.
|
|
46
46
|
|
|
47
47
|
## Two ways to author, one model
|
|
48
48
|
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Compose diagrams
|
|
2
|
+
|
|
3
|
+
An umbrella diagram pulls other diagrams in whole, each as a group of its own, and draws arrows between what is inside them. The parts stay in their own files; recompiling the umbrella picks up their changes. This is `include`, a node option: there is no method for it.
|
|
4
|
+
|
|
5
|
+
## The parts
|
|
6
|
+
|
|
7
|
+
A part is any diagram compiled to JSON: a diagram drawn in the studio, or a `.diagram.ts` once `diagc compile` has written `.diagrams/.artifacts/<name>.diagram.json`. Never include a `.diagram.ts` itself. These two parts are what the umbrella below pulls in; both draw the same users database and say so with `key`.
|
|
8
|
+
|
|
9
|
+
```json billing.diagram.json
|
|
10
|
+
{
|
|
11
|
+
"version": 1, "id": "billing", "name": "Billing",
|
|
12
|
+
"nodes": [
|
|
13
|
+
{ "id": "invoices", "name": "Invoice service", "type": "service" },
|
|
14
|
+
{ "id": "notifier", "name": "Notifier", "type": "service" },
|
|
15
|
+
{ "id": "ledger", "name": "Ledger DB", "type": "database" },
|
|
16
|
+
{ "id": "users", "name": "Users DB", "type": "database", "key": "users-db" }
|
|
17
|
+
],
|
|
18
|
+
"containment": [],
|
|
19
|
+
"relations": [
|
|
20
|
+
{ "id": "b1", "from": "invoices", "to": "ledger", "kind": "writes", "label": "Invoices" },
|
|
21
|
+
{ "id": "b2", "from": "invoices", "to": "users", "kind": "reads" },
|
|
22
|
+
{ "id": "b3", "from": "invoices", "to": "notifier", "kind": "async", "label": "Invoice events" }
|
|
23
|
+
],
|
|
24
|
+
"layers": [], "planes": []
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```json notify.diagram.json
|
|
29
|
+
{
|
|
30
|
+
"version": 1, "id": "notify", "name": "Notify",
|
|
31
|
+
"nodes": [
|
|
32
|
+
{ "id": "router", "name": "Message router", "type": "service" },
|
|
33
|
+
{ "id": "emailgw", "name": "Email gateway", "type": "service" },
|
|
34
|
+
{ "id": "sms", "name": "SMS gateway", "type": "service" },
|
|
35
|
+
{ "id": "users", "name": "User store", "type": "database", "key": "users-db" }
|
|
36
|
+
],
|
|
37
|
+
"containment": [],
|
|
38
|
+
"relations": [
|
|
39
|
+
{ "id": "n1", "from": "router", "to": "emailgw", "kind": "async" },
|
|
40
|
+
{ "id": "n2", "from": "router", "to": "sms", "kind": "async" },
|
|
41
|
+
{ "id": "n3", "from": "router", "to": "users", "kind": "reads" }
|
|
42
|
+
],
|
|
43
|
+
"layers": [], "planes": []
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## The umbrella
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import { model } from '@diagc/core';
|
|
51
|
+
|
|
52
|
+
// One picture of two diagrams that live in their own files. Recompile this one
|
|
53
|
+
// and it follows them.
|
|
54
|
+
const m = model('platform', { name: 'Platform' });
|
|
55
|
+
|
|
56
|
+
// An include node is a group holding everything the named diagram declares. The
|
|
57
|
+
// path is relative to this file; an https:// address works too (see the rules).
|
|
58
|
+
const bill = m.node('bill', { type: 'system', name: 'Billing', include: './billing.diagram.json' });
|
|
59
|
+
const note = m.node('note', { type: 'system', name: 'Notifications', include: './notify.diagram.json' });
|
|
60
|
+
|
|
61
|
+
// An arrow between two nodes that live inside the parts: reach each through its
|
|
62
|
+
// include node's handle, by the id it has in its own diagram.
|
|
63
|
+
m.relate(bill.included('notifier'), note.included('emailgw'), { kind: 'async', label: 'Invoice ready' });
|
|
64
|
+
|
|
65
|
+
export default m;
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## How it works
|
|
69
|
+
|
|
70
|
+
- Composition happens when the umbrella compiles. The artifact holds everything; the source stays this short. The studio shows the composed picture too.
|
|
71
|
+
- Every id a part declares is prefixed with its include node's id: `invoices` in `billing.diagram.json` is `bill/invoices` here, and so are its relation ids. A part's layer keeps its id when the umbrella declares a layer with the same id (they merge), and is prefixed otherwise.
|
|
72
|
+
- `bill.included('notifier')` is the handle for `bill/notifier`. Nothing is declared by it; the arrow is checked once the part is composed, and a node the part does not have fails the compile with `dangling-endpoint` naming `bill/notifier`.
|
|
73
|
+
- Two parts that draw the same thing merge it with `key`: nodes sharing a `key` become one node whose id is the key (`users-db` above), inside both groups, and every arrow from either part lands on it. Declare `key: 'users-db'` on a node in the umbrella too to choose its name and type. A key is inert until the diagram is composed, so adding one costs nothing.
|
|
74
|
+
- One plane's grouping comes along: the part's first-declared plane, or the one `includePlane` names (`includePlane: 'deployment'`). Add `includePlanes` (`includePlanes: true`) to also carry every plane of the part over, as `bill/<plane id>` with its own notation, so a git graph inside a C4 umbrella still reads as a git graph on its own plane.
|
|
75
|
+
- Parts nest: a part may include parts of its own, up to 10 deep.
|
|
76
|
+
- A part at an `https://` address is never fetched by a plain compile. Run `diagc compile --update-includes` once to fetch it into `.diagrams/includes/` and pin its hash in `.diagrams/includes.lock.json`, and commit both. Every later compile reads the pinned copy.
|
|
77
|
+
|
|
78
|
+
## Rules
|
|
79
|
+
|
|
80
|
+
- `include` points at a `.diagram.json`. A `.diagram.ts` must be compiled first, and the include then names its artifact.
|
|
81
|
+
- Do not rebuild a part by hand — not by copying its nodes, and not by importing its JSON and looping over it. That compiles and lints clean, but nothing is prefixed, no `key` merges and nothing is checked; the picture is a copy, not a composition.
|
|
82
|
+
- The umbrella's own ids must not collide with a prefixed one: declaring a node `bill/invoices` beside the include fails validation.
|
|
83
|
+
- The umbrella owns the look. A part's `typeColors`, `layerRules` and `legend` are dropped; declare them on the umbrella.
|
|
84
|
+
- Keys match `^[a-z0-9][a-z0-9-]*$`, and two nodes in one diagram never share one.
|
package/assets/guide/index.md
CHANGED
|
@@ -8,7 +8,7 @@ This guide is for diagc {{version}}.
|
|
|
8
8
|
|
|
9
9
|
1. Write or edit `.diagrams/src/<name>.diagram.ts`. A folder is allowed: `.diagrams/src/team/app.diagram.ts` is the diagram `team/app`.
|
|
10
10
|
2. Run `diagc lint --json`. It prints `[]` and exits 0 when everything is clean. Otherwise each finding has `file`, `severity`, `code` and `message`: fix it and run again. An `error` means the diagram does not compile. A `warning` compiles but is probably a mistake, such as a misspelled type.
|
|
11
|
-
3. Run `diagc show <name>` to read the picture as text: the boxes, what sits inside what, and the arrows with their labels, every group open. It needs nothing else. Run `diagc publish <name>` and look at `.diagrams/static/<name>.png` to check the picture itself; `diagc publish` with no name publishes every diagram. It needs Chrome
|
|
11
|
+
3. Run `diagc show <name>` to read the picture as text: the boxes, what sits inside what, and the arrows with their labels, every group open. It needs nothing else. Run `diagc publish <name>` and look at `.diagrams/static/<name>.png` to check the picture itself; `diagc publish` with no name publishes every diagram. It needs Chrome: `npx playwright-core install chromium` gets one when none is found, or set `CHROME_PATH`. The PNG shows the first plane with every group opened and only the layers that plane turns on; each further plane gets `.diagrams/static/<name>.<plane>.png`, and the other layers are on the page `.diagrams/html/<name>.html`.
|
|
12
12
|
|
|
13
13
|
A person runs `diagc studio` to browse every diagram and to move boxes by hand.
|
|
14
14
|
|
|
@@ -34,6 +34,8 @@ More node options:
|
|
|
34
34
|
| `metadata` | Free-form key and value data. |
|
|
35
35
|
| `plane`, `layer` | Show the node in one plane only, or put it on a layer. |
|
|
36
36
|
|
|
37
|
+
The look of one box — `icon`, `image`, `textColor`, `rich`, `textAlign`, `fontScale` — and a `link` to open from it are usually set in the studio; `reference/builder-api.md` lists them.
|
|
38
|
+
|
|
37
39
|
More relation options: `layer`, `plane` (drawn on that plane only), `description`, `id`, and `style`, one arrow's look: `{ color: '#c0392b', line: 'dashed', shape: 'step', end: 'none' }` (`line` is `solid`, `dashed` or `dotted`; `shape` is `curved`, `straight` or `step`; `end` is `arrow`, `dot`, `square`, `diamond` or `none`; `RelationStyle` in `reference/model.md` has the rest). The file is TypeScript, so to give many arrows one look, declare the style once (`const toProd = { color: '#c0392b' }`) and pass `style: toProd` to each.
|
|
38
40
|
|
|
39
41
|
## Types and kinds
|
|
@@ -105,6 +107,12 @@ Run `diagc guide <topic>` before writing one of these. Some are switched on with
|
|
|
105
107
|
|
|
106
108
|
{{topics}}
|
|
107
109
|
|
|
110
|
+
## Features
|
|
111
|
+
|
|
112
|
+
Any diagram can use these; each has a topic of its own.
|
|
113
|
+
|
|
114
|
+
{{feature-topics}}
|
|
115
|
+
|
|
108
116
|
`diagc guide all` prints this page and every topic.
|
|
109
117
|
|
|
110
118
|
## More
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# State machine
|
|
2
|
+
|
|
3
|
+
A UML state machine: states, the transitions between them, and the events, guards and effects on those transitions. Reach for it to show how one thing moves through its modes, such as an order, a connection or an editor session.
|
|
4
|
+
|
|
5
|
+
{{starter}}
|
|
6
|
+
|
|
7
|
+
## How it works
|
|
8
|
+
|
|
9
|
+
- `m.stateMachine(id, opts?)` draws a machine frame and returns a handle. `opts` takes `name`, `plane` and `planeName`. You can call it again for a second machine. Without `plane` the whole diagram becomes a state machine, and the call throws if it has another notation: pass `plane` to draw the machine beside other views.
|
|
10
|
+
- The machine, a state and a region each offer `state(id, name?, { entry?, exit?, do?, color? })`, `initial(id?)`, `final(id?)`, `choice(id?, name?)`, `junction(id?)`, `bar(id?)` and `terminate(id?)`. `entry`, `exit` and `do` are the state's `behaviors`, each an effect.
|
|
11
|
+
- A transition is `machine.transition(from, to, { trigger?, guard?, effect? })`, or `element.to(target, parts?)`, which returns the target so a path chains. A transition reads `trigger [guard] / effect`. Write the parts as options, never as a `label`.
|
|
12
|
+
- `state.on(trigger, { guard?, effect })` adds an internal transition: the state is not left. It shows in the state's behaviors.
|
|
13
|
+
- A state with children is composite and rests folded in a viewer; double-click unfolds it. `state.region(id?, name?)` adds a concurrent region, and a state with regions is orthogonal. `state.entryPoint(id?, name?)` and `state.exitPoint(id?, name?)` sit on its border.
|
|
14
|
+
- `history({ id?, deep? })` is shallow history (`H`), or deep (`H*`) with `deep: true`. `state.history()` is valid on a plain composite state, and `region.history()` in each region of an orthogonal one, where `state.history()` throws. The machine itself has no history. A transition into a history state resumes the substate that was left.
|
|
15
|
+
|
|
16
|
+
## Node types
|
|
17
|
+
|
|
18
|
+
{{node-types}}
|
|
19
|
+
|
|
20
|
+
You never write these types yourself: the builder creates them. A state is composite when something is inside it.
|
|
21
|
+
|
|
22
|
+
## Rules
|
|
23
|
+
|
|
24
|
+
Every rule is a warning, never an error: the diagram still compiles. Lint reports them under these codes.
|
|
25
|
+
|
|
26
|
+
- `sm-initial-count`, `sm-initial-flow`: one initial per region, with exactly one plain transition out and none in.
|
|
27
|
+
- `sm-final-outgoing`: a final or a terminate has no transition out.
|
|
28
|
+
- `sm-choice-guards`: each exit of a choice or junction has a guard, and at most one is `else`.
|
|
29
|
+
- `sm-bar-shape`: a bar has one transition on one side, and a fork's targets are in different regions.
|
|
30
|
+
- `sm-unreachable`: a state no path from an initial reaches. A machine with no initial is not checked.
|
|
31
|
+
- `sm-transition-ends`, `sm-transition-label`: a transition joins two state-machine nodes, and its parts carry the text.
|
|
32
|
+
- `sm-region-parent`, `sm-region-siblings`, `sm-machine-parent`, `sm-pseudo-children`, `sm-history-parent`, `sm-point-parent`: where each node may sit.
|
|
33
|
+
|
|
34
|
+
## From a Quint spec
|
|
35
|
+
|
|
36
|
+
A Quint spec's mode variable becomes the states. Take this one:
|
|
37
|
+
|
|
38
|
+
```quint
|
|
39
|
+
module order {
|
|
40
|
+
var status: str
|
|
41
|
+
var total: int
|
|
42
|
+
action init = all { status' = "draft", total' = 0 }
|
|
43
|
+
action refund = total' = 0
|
|
44
|
+
action pay = all { status == "draft", total > 0, status' = "paid", total' = total }
|
|
45
|
+
action ship = all { status == "paid", status' = "shipped", total' = total }
|
|
46
|
+
action cancel = any {
|
|
47
|
+
all { status == "draft", status' = "cancelled", total' = total },
|
|
48
|
+
all { status == "paid", refund, status' = "cancelled" },
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
- The variable that holds the mode, a `str` or a sum type, gives one state per value, and `init` is the initial transition, to the state it assigns.
|
|
54
|
+
- An action that changes the mode is a transition. Its name is the trigger, the preconditions on other variables are the guard, and the other updates, or an action it calls for them (`refund`), are the effect. An update that keeps a variable as it was (`total' = total`) is no effect.
|
|
55
|
+
- The alternatives of an `any` from one mode are several transitions from that state.
|
|
56
|
+
- An action that leaves the mode unchanged is an internal transition (`state.on`), or a self-transition when re-entry matters.
|
|
57
|
+
- Independent mode variables that change in one step are orthogonal regions. An invariant has no diagram element yet: write it in a comment.
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { model } from '@diagc/core';
|
|
61
|
+
|
|
62
|
+
const m = model('order-spec', { name: 'Order spec' });
|
|
63
|
+
const order = m.stateMachine('order', { name: 'Order' });
|
|
64
|
+
|
|
65
|
+
const draft = order.state('draft', 'draft');
|
|
66
|
+
const paid = order.state('paid', 'paid');
|
|
67
|
+
const shipped = order.state('shipped', 'shipped');
|
|
68
|
+
const cancelled = order.state('cancelled', 'cancelled');
|
|
69
|
+
|
|
70
|
+
order.initial().to(draft);
|
|
71
|
+
order.transition(draft, paid, { trigger: 'pay', guard: 'total > 0' });
|
|
72
|
+
order.transition(paid, shipped, { trigger: 'ship' });
|
|
73
|
+
order.transition(draft, cancelled, { trigger: 'cancel' });
|
|
74
|
+
order.transition(paid, cancelled, { trigger: 'cancel', effect: 'refund' });
|
|
75
|
+
|
|
76
|
+
export default m;
|
|
77
|
+
```
|
package/assets/skill/SKILL.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: diagc
|
|
3
|
-
description: Write, change or fix a diagc diagram (.diagrams/src/*.diagram.ts) — architecture, C4, deployment, ER, activity, threat model, causal loop, plan and more. Use when asked to draw or update a diagram in a repository that uses diagc.
|
|
3
|
+
description: Write, change or fix a diagc diagram (.diagrams/src/*.diagram.ts) — architecture, C4, deployment, ER, activity, threat model, causal loop, plan, state machine and more. Use when asked to draw or update a diagram in a repository that uses diagc.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
<!-- diagc:begin -->
|
|
@@ -12,12 +12,13 @@ A diagram is a TypeScript file under `.diagrams/src/`; `diagc` validates it, lay
|
|
|
12
12
|
|
|
13
13
|
1. Run `diagc guide`: the DSL, the node types and relation kinds, the rules, and the list of diagram types.
|
|
14
14
|
2. Run `diagc guide <topic>` when the diagram is one of those types (`c4`, `er`, `deployment`, …). Each topic prints a complete starter to begin from.
|
|
15
|
+
3. Run `diagc guide compose` when the diagram pulls other diagrams in. Composition is a node option, `include`; never rebuild another diagram's content by hand.
|
|
15
16
|
|
|
16
17
|
## The loop
|
|
17
18
|
|
|
18
19
|
1. Write or edit `.diagrams/src/<name>.diagram.ts`.
|
|
19
20
|
2. Run `diagc lint --json` until it prints `[]` and exits 0. Each finding has `file`, `severity`, `code` and `message`: an `error` does not compile, a `warning` compiles but is probably a mistake.
|
|
20
|
-
3. Run `diagc show <name>` and read the picture as text: the boxes, the nesting and the arrows with their labels. Then run `diagc publish <name>` and look at `.diagrams/static/<name>.png`; `diagc publish` with no name does every diagram at once. It needs Chrome (
|
|
21
|
+
3. Run `diagc show <name>` and read the picture as text: the boxes, the nesting and the arrows with their labels. Then run `diagc publish <name>` and look at `.diagrams/static/<name>.png`; `diagc publish` with no name does every diagram at once. It needs Chrome (`npx playwright-core install chromium` gets one, or set `CHROME_PATH`); without one it writes the HTML page only.
|
|
21
22
|
|
|
22
23
|
## Rules
|
|
23
24
|
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { model } from '@diagc/core';
|
|
2
|
+
|
|
3
|
+
const m = model('order-lifecycle', { name: 'Order lifecycle' });
|
|
4
|
+
|
|
5
|
+
const order = m.stateMachine('order', { name: 'Order' });
|
|
6
|
+
|
|
7
|
+
const draft = order.state('draft', 'Draft');
|
|
8
|
+
const paid = order.state('paid', 'Paid', { entry: 'reserveStock', exit: 'releaseHold' });
|
|
9
|
+
const fulfil = order.state('fulfil', 'Fulfilment');
|
|
10
|
+
const held = order.state('held', 'On hold');
|
|
11
|
+
const inStock = order.choice('in-stock');
|
|
12
|
+
const done = order.final();
|
|
13
|
+
|
|
14
|
+
// Draft is a plain composite: one substate at a time.
|
|
15
|
+
const editing = draft.state('editing', 'Editing');
|
|
16
|
+
draft.initial().to(editing);
|
|
17
|
+
editing.to(draft.state('reviewing', 'Reviewing'), { trigger: 'submit' });
|
|
18
|
+
|
|
19
|
+
// Two regions make Fulfilment orthogonal: both run at once.
|
|
20
|
+
const pick = fulfil.region('pick', 'Picking');
|
|
21
|
+
const bill = fulfil.region('bill', 'Billing');
|
|
22
|
+
const picking = pick.state('picking', 'Picking');
|
|
23
|
+
pick.initial().to(picking);
|
|
24
|
+
const resumePicking = pick.history();
|
|
25
|
+
bill.initial().to(bill.state('invoicing', 'Invoicing'));
|
|
26
|
+
|
|
27
|
+
order.initial().to(draft);
|
|
28
|
+
order.transition(draft, paid, { trigger: 'pay', guard: 'total > 0', effect: 'charge' });
|
|
29
|
+
order.transition(paid, inStock);
|
|
30
|
+
order.transition(inStock, fulfil, { guard: 'in stock' });
|
|
31
|
+
order.transition(inStock, draft, { guard: 'else' });
|
|
32
|
+
order.transition(fulfil, done, { trigger: 'deliver' });
|
|
33
|
+
|
|
34
|
+
// Resuming enters Picking's history: picking goes on where it was left.
|
|
35
|
+
order.transition(picking, held, { trigger: 'hold' });
|
|
36
|
+
order.transition(held, resumePicking, { trigger: 'resume' });
|
|
37
|
+
order.transition(held, done, { trigger: 'cancel' });
|
|
38
|
+
|
|
39
|
+
// An internal transition: the state is not left.
|
|
40
|
+
paid.on('remind', { guard: 'overdue', effect: 'email' });
|
|
41
|
+
|
|
42
|
+
export default m;
|