eventmodeler 0.6.2 → 0.6.3
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 +221 -91
- package/dist/index.js +159 -73
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
# eventmodeler
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Works with `.eventmodel` files created by the [Event Modeling App](https://www.eventmodeling.app).
|
|
3
|
+
Command line client for Event Modeler cloud models. Use it to inspect a model, place elements on the canvas, maintain fields and scenarios, and drive code generation loops from a terminal or agent.
|
|
6
4
|
|
|
7
5
|
## Installation
|
|
8
6
|
|
|
@@ -10,166 +8,298 @@ Works with `.eventmodel` files created by the [Event Modeling App](https://www.e
|
|
|
10
8
|
npm install -g eventmodeler
|
|
11
9
|
```
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
# Open Event Modeling app in browser
|
|
17
|
-
eventmodeler
|
|
11
|
+
Requires Node.js 18 or newer.
|
|
18
12
|
|
|
19
|
-
|
|
20
|
-
eventmodeler list slices
|
|
13
|
+
## Setup
|
|
21
14
|
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
```bash
|
|
16
|
+
# Authenticate in the browser
|
|
17
|
+
eventmodeler login
|
|
24
18
|
|
|
25
|
-
#
|
|
26
|
-
eventmodeler
|
|
19
|
+
# Create a cloud model, or use an existing model id from the app
|
|
20
|
+
eventmodeler create model "Ordering"
|
|
27
21
|
|
|
28
|
-
#
|
|
29
|
-
eventmodeler
|
|
22
|
+
# Link the current repo/directory to a model
|
|
23
|
+
eventmodeler init
|
|
30
24
|
```
|
|
31
25
|
|
|
32
|
-
|
|
26
|
+
`eventmodeler init` writes `.eventmodeler.json` in your project. Most commands read the model id from that file. You can also target an element directly with the global `--id <uuid>` option when a command accepts an optional name.
|
|
33
27
|
|
|
34
|
-
|
|
28
|
+
Useful auth commands:
|
|
35
29
|
|
|
36
30
|
```bash
|
|
37
|
-
eventmodeler
|
|
38
|
-
eventmodeler
|
|
39
|
-
eventmodeler list commands # List all commands
|
|
40
|
-
eventmodeler list chapters # List all chapters
|
|
41
|
-
eventmodeler list aggregates # List all aggregates
|
|
42
|
-
eventmodeler list actors # List all actors
|
|
31
|
+
eventmodeler whoami
|
|
32
|
+
eventmodeler logout
|
|
43
33
|
```
|
|
44
34
|
|
|
45
|
-
|
|
35
|
+
## Common Workflow
|
|
46
36
|
|
|
47
37
|
```bash
|
|
48
|
-
|
|
49
|
-
eventmodeler show
|
|
50
|
-
eventmodeler
|
|
51
|
-
eventmodeler show
|
|
52
|
-
eventmodeler
|
|
38
|
+
# Explore the model
|
|
39
|
+
eventmodeler show model
|
|
40
|
+
eventmodeler list slices
|
|
41
|
+
eventmodeler show slice "Place Order"
|
|
42
|
+
eventmodeler search order
|
|
43
|
+
|
|
44
|
+
# Build out the canvas
|
|
45
|
+
eventmodeler create place command PlaceOrder --x 120 --y 200
|
|
46
|
+
eventmodeler create place event OrderPlaced --x 120 --y 360
|
|
47
|
+
eventmodeler create flow --from PlaceOrder --to OrderPlaced
|
|
48
|
+
|
|
49
|
+
# Add fields
|
|
50
|
+
eventmodeler add field PlaceOrder '{"name":"orderId","type":"UUID"}'
|
|
51
|
+
eventmodeler add subfield PlaceOrder --field customer '{"name":"email","type":"String"}'
|
|
52
|
+
|
|
53
|
+
# Create a scenario atomically
|
|
54
|
+
eventmodeler create scenario --slice "Place Order" '{
|
|
55
|
+
"name": "happy path",
|
|
56
|
+
"when": [
|
|
57
|
+
{
|
|
58
|
+
"entryType": "command",
|
|
59
|
+
"elementName": "PlaceOrder",
|
|
60
|
+
"fieldValues": { "orderId": "uuid-1" }
|
|
61
|
+
}
|
|
62
|
+
],
|
|
63
|
+
"then": [
|
|
64
|
+
{
|
|
65
|
+
"entryType": "event",
|
|
66
|
+
"elementName": "OrderPlaced",
|
|
67
|
+
"fieldValues": { "orderId": "uuid-1" }
|
|
68
|
+
}
|
|
69
|
+
]
|
|
70
|
+
}'
|
|
53
71
|
```
|
|
54
72
|
|
|
55
|
-
|
|
73
|
+
## Read Commands
|
|
56
74
|
|
|
57
75
|
```bash
|
|
58
|
-
eventmodeler show
|
|
59
|
-
eventmodeler show
|
|
60
|
-
eventmodeler show
|
|
76
|
+
eventmodeler show model
|
|
77
|
+
eventmodeler show context [name]
|
|
78
|
+
eventmodeler show chapter [name]
|
|
79
|
+
eventmodeler show slice [name]
|
|
80
|
+
eventmodeler show event [name]
|
|
81
|
+
eventmodeler show command [name]
|
|
82
|
+
eventmodeler show readmodel [name]
|
|
83
|
+
eventmodeler show screen [name]
|
|
84
|
+
eventmodeler show processor [name]
|
|
85
|
+
eventmodeler show external-event [name]
|
|
86
|
+
eventmodeler show completeness
|
|
87
|
+
eventmodeler summary
|
|
88
|
+
eventmodeler search <term>
|
|
61
89
|
```
|
|
62
90
|
|
|
63
|
-
|
|
91
|
+
List commands:
|
|
64
92
|
|
|
65
93
|
```bash
|
|
66
|
-
eventmodeler
|
|
94
|
+
eventmodeler list slices [--chapter <name>]
|
|
95
|
+
eventmodeler list events
|
|
96
|
+
eventmodeler list commands
|
|
97
|
+
eventmodeler list readmodels
|
|
98
|
+
eventmodeler list screens
|
|
99
|
+
eventmodeler list processors
|
|
100
|
+
eventmodeler list external-events
|
|
101
|
+
eventmodeler list aggregates
|
|
102
|
+
eventmodeler list actors
|
|
103
|
+
eventmodeler list chapters
|
|
104
|
+
eventmodeler list contexts
|
|
105
|
+
eventmodeler list swimlanes
|
|
106
|
+
eventmodeler list notes
|
|
107
|
+
eventmodeler list scenarios
|
|
67
108
|
```
|
|
68
109
|
|
|
69
|
-
|
|
110
|
+
Output is JSON from the backend SDK. Use `eventmodeler help <topic>` or command-specific `--help` for schema examples.
|
|
111
|
+
|
|
112
|
+
## Canvas And Model Editing
|
|
113
|
+
|
|
114
|
+
Create models, slices, elements, flows, and linked copies:
|
|
70
115
|
|
|
71
116
|
```bash
|
|
72
|
-
|
|
73
|
-
eventmodeler
|
|
74
|
-
eventmodeler
|
|
117
|
+
eventmodeler create model <name>
|
|
118
|
+
eventmodeler create slice '<json>'
|
|
119
|
+
eventmodeler create place <type> <name> --x <n> --y <n>
|
|
120
|
+
eventmodeler create flow --from <source> --to <target>
|
|
121
|
+
eventmodeler create place-copy <type> [originalName] --x <n> --y <n>
|
|
122
|
+
eventmodeler create move-copy <type> [name] --x <n> --y <n>
|
|
123
|
+
eventmodeler create remove-copy <type> [name]
|
|
124
|
+
```
|
|
75
125
|
|
|
76
|
-
|
|
77
|
-
eventmodeler add scenario --slice "Place Order" --json '{"name": "Happy path", ...}'
|
|
126
|
+
Element types for `create place`:
|
|
78
127
|
|
|
79
|
-
|
|
80
|
-
|
|
128
|
+
```text
|
|
129
|
+
command, event, readmodel, screen, processor, external-event,
|
|
130
|
+
aggregate, actor, chapter, context, note, swimlane, slice
|
|
131
|
+
```
|
|
81
132
|
|
|
82
|
-
|
|
83
|
-
eventmodeler remove field --event "OrderPlaced" --field "legacyId"
|
|
133
|
+
Linked copies are supported for:
|
|
84
134
|
|
|
85
|
-
|
|
86
|
-
|
|
135
|
+
```text
|
|
136
|
+
event, readmodel, screen, external-event
|
|
137
|
+
```
|
|
87
138
|
|
|
88
|
-
|
|
89
|
-
|
|
139
|
+
Move, resize, rename, and remove existing elements:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
eventmodeler move <type> [name] --x <n> --y <n>
|
|
143
|
+
eventmodeler resize <type> [name] --width <n> --height <n>
|
|
144
|
+
eventmodeler rename <type> <oldName> <newName>
|
|
145
|
+
eventmodeler remove <type> [name]
|
|
146
|
+
eventmodeler remove flow --from <source> --to <target>
|
|
90
147
|
```
|
|
91
148
|
|
|
92
|
-
|
|
149
|
+
Mark slice status:
|
|
93
150
|
|
|
94
151
|
```bash
|
|
95
|
-
eventmodeler
|
|
96
|
-
eventmodeler
|
|
152
|
+
eventmodeler mark "Place Order" planned
|
|
153
|
+
eventmodeler mark "Place Order" created
|
|
154
|
+
eventmodeler mark "Place Order" in-progress
|
|
155
|
+
eventmodeler mark "Place Order" blocked
|
|
156
|
+
eventmodeler mark "Place Order" done
|
|
97
157
|
```
|
|
98
158
|
|
|
99
|
-
##
|
|
159
|
+
## Fields
|
|
160
|
+
|
|
161
|
+
Fields are supported on commands, events, readmodels, screens, processors, and external events.
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
eventmodeler add field [elementName] '{"name":"customerId","type":"UUID"}'
|
|
165
|
+
eventmodeler add subfield [elementName] --field <parentFieldName> '{"name":"email","type":"String"}'
|
|
166
|
+
|
|
167
|
+
eventmodeler update field [elementName] --field <name> --name <newName>
|
|
168
|
+
eventmodeler update field [elementName] --field <name> --type <newType>
|
|
169
|
+
eventmodeler update field [elementName] --field <name> --optional true
|
|
170
|
+
eventmodeler update field [elementName] --field <name> --generated false
|
|
171
|
+
eventmodeler update field [elementName] --field <name> --list true
|
|
172
|
+
eventmodeler update field [elementName] --field <name> --user-input true
|
|
173
|
+
|
|
174
|
+
eventmodeler update subfield [elementName] --subfield <id> --name <newName>
|
|
175
|
+
eventmodeler update subfield [elementName] --subfield <id> --type <newType>
|
|
176
|
+
eventmodeler update reorder [elementName] --field <name> --position <n>
|
|
177
|
+
eventmodeler update reorder-subfield [elementName] --subfield <id> --position <n>
|
|
178
|
+
|
|
179
|
+
eventmodeler remove field [elementName] --field <name>
|
|
180
|
+
eventmodeler remove subfield [elementName] --subfield <id>
|
|
181
|
+
eventmodeler set aggregate-id [aggregateName] --field-name <name> --field-type UUID
|
|
182
|
+
```
|
|
100
183
|
|
|
101
|
-
|
|
184
|
+
For field mappings:
|
|
102
185
|
|
|
103
186
|
```bash
|
|
104
|
-
eventmodeler
|
|
105
|
-
eventmodeler
|
|
187
|
+
eventmodeler map fields '[{"source":"orderId","target":"orderId"}]' --from PlaceOrder --to OrderPlaced
|
|
188
|
+
eventmodeler remove mapping --from PlaceOrder --to OrderPlaced --mapping <mappingId>
|
|
106
189
|
```
|
|
107
190
|
|
|
108
|
-
|
|
191
|
+
## Scenarios
|
|
109
192
|
|
|
110
|
-
|
|
193
|
+
Create a full Given/When/Then scenario in one backend transaction:
|
|
111
194
|
|
|
112
|
-
**Environment variable:**
|
|
113
195
|
```bash
|
|
114
|
-
|
|
196
|
+
eventmodeler add scenario --slice "Place Order" '<scenario-json>'
|
|
197
|
+
eventmodeler create scenario --slice "Place Order" '<scenario-json>'
|
|
115
198
|
```
|
|
116
199
|
|
|
117
|
-
|
|
200
|
+
Scenario JSON shape:
|
|
201
|
+
|
|
118
202
|
```json
|
|
119
203
|
{
|
|
120
|
-
"
|
|
204
|
+
"name": "happy path",
|
|
205
|
+
"description": "optional",
|
|
206
|
+
"given": [
|
|
207
|
+
{ "entryType": "event", "elementName": "OrderPlaced" }
|
|
208
|
+
],
|
|
209
|
+
"when": [
|
|
210
|
+
{ "entryType": "command", "elementName": "PlaceOrder" }
|
|
211
|
+
],
|
|
212
|
+
"then": [
|
|
213
|
+
{ "entryType": "event", "elementName": "OrderPlaced" },
|
|
214
|
+
{ "entryType": "error", "errorType": "Validation", "errorMessage": "Invalid order" }
|
|
215
|
+
]
|
|
121
216
|
}
|
|
122
217
|
```
|
|
123
218
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
## Options
|
|
219
|
+
Allowed entry types:
|
|
127
220
|
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
-v, --version Show version number
|
|
221
|
+
```text
|
|
222
|
+
given: event, readmodel
|
|
223
|
+
when: command, event
|
|
224
|
+
then: event, command, readmodel, error
|
|
133
225
|
```
|
|
134
226
|
|
|
135
|
-
|
|
227
|
+
Example values can be provided in the scenario JSON via `fieldValues`, or edited later:
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
eventmodeler add entry --scenario "happy path" --section then --type event --element OrderPlaced
|
|
231
|
+
eventmodeler set example --scenario "happy path" --entry <entryId> --type event --field orderId --value uuid-1
|
|
232
|
+
eventmodeler set example --scenario "happy path" --entry <entryId> --type event --field tags --values vip,web
|
|
233
|
+
eventmodeler set example --scenario "happy path" --entry <entryId> --type event --field address --json '{"city":"NYC"}'
|
|
234
|
+
eventmodeler set description --scenario "happy path" --text "Updated description"
|
|
235
|
+
eventmodeler set position --scenario "happy path" --section then --entry <entryId> --position 0
|
|
236
|
+
eventmodeler remove example --scenario "happy path" --entry <entryId> --type event --field orderId
|
|
237
|
+
eventmodeler remove entry --scenario "happy path" --section then --entry <entryId>
|
|
238
|
+
eventmodeler remove scenario "happy path"
|
|
239
|
+
```
|
|
136
240
|
|
|
137
|
-
|
|
241
|
+
Primitive example values are strings. Custom fields use JSON objects, and Custom list fields use arrays of objects.
|
|
138
242
|
|
|
139
|
-
|
|
243
|
+
## Screen And Note Details
|
|
140
244
|
|
|
141
245
|
```bash
|
|
142
|
-
eventmodeler
|
|
246
|
+
eventmodeler design <screenName> '<excalidraw-json-array>'
|
|
247
|
+
eventmodeler set note-description [noteName] --text "Markdown or plain text"
|
|
143
248
|
```
|
|
144
249
|
|
|
145
|
-
|
|
250
|
+
## Automation Loop
|
|
146
251
|
|
|
147
|
-
|
|
252
|
+
The CLI can poll planned slices and run your generator command for each one.
|
|
148
253
|
|
|
149
254
|
```bash
|
|
150
|
-
eventmodeler
|
|
151
|
-
eventmodeler
|
|
255
|
+
eventmodeler init loop
|
|
256
|
+
eventmodeler loop
|
|
152
257
|
```
|
|
153
258
|
|
|
154
|
-
|
|
259
|
+
`eventmodeler init loop` adds a `loop` block to `.eventmodeler.json` and creates a sample `generate.sh`. The generated script marks a slice in progress, exports slice JSON, runs your codegen placeholder, and marks the slice done or blocked.
|
|
155
260
|
|
|
156
|
-
|
|
261
|
+
## Configuration
|
|
157
262
|
|
|
158
|
-
|
|
159
|
-
|
|
263
|
+
Global config lives at:
|
|
264
|
+
|
|
265
|
+
```text
|
|
266
|
+
~/.eventmodeler/config.json
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
Project config lives at:
|
|
270
|
+
|
|
271
|
+
```text
|
|
272
|
+
.eventmodeler.json
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
The production backend is used by default:
|
|
276
|
+
|
|
277
|
+
```text
|
|
278
|
+
https://api.eventmodeler.com
|
|
160
279
|
```
|
|
161
280
|
|
|
162
|
-
|
|
281
|
+
Override endpoints when developing locally:
|
|
163
282
|
|
|
164
|
-
|
|
165
|
-
|
|
283
|
+
```bash
|
|
284
|
+
export EVENTMODELER_BACKEND_URL=http://localhost:8080
|
|
285
|
+
export EVENTMODELER_KEYCLOAK_URL=http://localhost:18180/realms/eventmodeler
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
## Help Topics
|
|
166
289
|
|
|
167
|
-
|
|
290
|
+
Task-oriented help is built into the CLI:
|
|
168
291
|
|
|
169
|
-
|
|
292
|
+
```bash
|
|
293
|
+
eventmodeler help
|
|
294
|
+
eventmodeler help build-slice
|
|
295
|
+
eventmodeler help write-scenarios
|
|
296
|
+
eventmodeler help manipulate-canvas
|
|
297
|
+
eventmodeler help linked-copies
|
|
298
|
+
eventmodeler help check-completeness
|
|
299
|
+
eventmodeler guide json-reference
|
|
300
|
+
```
|
|
170
301
|
|
|
171
302
|
## Links
|
|
172
303
|
|
|
173
|
-
-
|
|
174
|
-
-
|
|
175
|
-
- [GitHub Repository](https://github.com/theoema/event-modeler)
|
|
304
|
+
- Event Modeling: https://eventmodeling.org
|
|
305
|
+
- GitHub: https://github.com/theoema/event-modeler
|
package/dist/index.js
CHANGED
|
@@ -4114,6 +4114,9 @@ EXAMPLE:
|
|
|
4114
4114
|
NOTES:
|
|
4115
4115
|
- The JSON is a positional argument (not a --json flag)
|
|
4116
4116
|
- Every element and flow needs a unique UUID
|
|
4117
|
+
- Field and subfield UUIDs are generated when omitted
|
|
4118
|
+
- Field flags such as isGenerated, isList, isOptional, and isUserInput are not
|
|
4119
|
+
applied by create slice; add or update them after creation
|
|
4117
4120
|
- Valid flow pairs: screen->command, command->event, command->external-event,
|
|
4118
4121
|
event->readmodel, readmodel->screen, readmodel->processor, processor->command,
|
|
4119
4122
|
external-event->processor
|
|
@@ -4322,10 +4325,10 @@ WHEN TO USE: You need to specify slice behavior as Given-When-Then test cases.
|
|
|
4322
4325
|
## Task: Add a full scenario to a slice (compound command)
|
|
4323
4326
|
|
|
4324
4327
|
COMMAND:
|
|
4325
|
-
eventmodeler
|
|
4328
|
+
eventmodeler create scenario '<json>' --slice <sliceName>
|
|
4326
4329
|
|
|
4327
4330
|
EXAMPLE (happy path — state-change slice):
|
|
4328
|
-
eventmodeler
|
|
4331
|
+
eventmodeler create scenario '{
|
|
4329
4332
|
"name": "Successfully place order",
|
|
4330
4333
|
"given": [
|
|
4331
4334
|
{"entryType": "event", "elementName": "CustomerRegistered", "fieldValues": {"customerId": "cust-001"}}
|
|
@@ -4339,7 +4342,7 @@ EXAMPLE (happy path — state-change slice):
|
|
|
4339
4342
|
}' --slice "Place Order"
|
|
4340
4343
|
|
|
4341
4344
|
EXAMPLE (error case):
|
|
4342
|
-
eventmodeler
|
|
4345
|
+
eventmodeler create scenario '{
|
|
4343
4346
|
"name": "Reject order with no items",
|
|
4344
4347
|
"when": [
|
|
4345
4348
|
{"entryType": "command", "elementName": "PlaceOrder", "fieldValues": {"customerId": "cust-001"}}
|
|
@@ -4350,7 +4353,7 @@ EXAMPLE (error case):
|
|
|
4350
4353
|
}' --slice "Place Order"
|
|
4351
4354
|
|
|
4352
4355
|
EXAMPLE (readmodel assertion in then):
|
|
4353
|
-
eventmodeler
|
|
4356
|
+
eventmodeler create scenario '{
|
|
4354
4357
|
"name": "Order appears in summary",
|
|
4355
4358
|
"given": [
|
|
4356
4359
|
{"entryType": "event", "elementName": "OrderPlaced", "fieldValues": {"orderId": "ord-001", "customerId": "cust-001"}}
|
|
@@ -4815,11 +4818,9 @@ WHEN TO USE: You need the exact JSON shape for a CLI command.
|
|
|
4815
4818
|
|
|
4816
4819
|
Field types: UUID, String, Int, Long, Double, Decimal, Boolean, Date, DateTime, Custom
|
|
4817
4820
|
|
|
4818
|
-
|
|
4819
|
-
|
|
4820
|
-
|
|
4821
|
-
"isList": true
|
|
4822
|
-
"isUserInput": true (screens only)
|
|
4821
|
+
Note: create slice generates field/subfield IDs when omitted. Field metadata
|
|
4822
|
+
flags such as isOptional, isGenerated, isList, and isUserInput are not applied
|
|
4823
|
+
by create slice; add or update those flags after creation.
|
|
4823
4824
|
|
|
4824
4825
|
Custom type with subfields:
|
|
4825
4826
|
{
|
|
@@ -4874,9 +4875,9 @@ WHEN TO USE: You need the exact JSON shape for a CLI command.
|
|
|
4874
4875
|
{ "source": "sourceFieldName", "target": "targetFieldName" }
|
|
4875
4876
|
]
|
|
4876
4877
|
|
|
4877
|
-
##
|
|
4878
|
+
## create scenario '<json>' --slice <sliceName>
|
|
4878
4879
|
|
|
4879
|
-
eventmodeler
|
|
4880
|
+
eventmodeler create scenario '<json>' --slice "Place Order"
|
|
4880
4881
|
|
|
4881
4882
|
SCENARIO JSON:
|
|
4882
4883
|
{
|
|
@@ -5455,6 +5456,65 @@ function registerListCommands(program) {
|
|
|
5455
5456
|
}
|
|
5456
5457
|
}
|
|
5457
5458
|
|
|
5459
|
+
// src/lib/scenario-field-values.ts
|
|
5460
|
+
function isPlainObject(v) {
|
|
5461
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
5462
|
+
}
|
|
5463
|
+
function toFieldValueWire(value, path4 = "fieldValues") {
|
|
5464
|
+
if (Array.isArray(value)) {
|
|
5465
|
+
const allObjects = value.length > 0 && value.every(isPlainObject);
|
|
5466
|
+
const anyObject = value.some(isPlainObject);
|
|
5467
|
+
if (allObjects) {
|
|
5468
|
+
return { treeList: value.map((item, i) => toFieldValueWire(item, `${path4}[${i}]`)) };
|
|
5469
|
+
}
|
|
5470
|
+
if (anyObject) {
|
|
5471
|
+
throw new Error(`${path4}: list mixes primitives and objects; use either all scalar values or all objects.`);
|
|
5472
|
+
}
|
|
5473
|
+
return { list: value.map(String) };
|
|
5474
|
+
}
|
|
5475
|
+
if (isPlainObject(value)) {
|
|
5476
|
+
return {
|
|
5477
|
+
tree: Object.fromEntries(Object.entries(value).map(([key, child]) => [key, toFieldValueWire(child, `${path4}.${key}`)]))
|
|
5478
|
+
};
|
|
5479
|
+
}
|
|
5480
|
+
return { scalar: String(value) };
|
|
5481
|
+
}
|
|
5482
|
+
function toFieldValuesWire(values) {
|
|
5483
|
+
if (!values)
|
|
5484
|
+
return {};
|
|
5485
|
+
return Object.fromEntries(Object.entries(values).map(([fieldName, value]) => [fieldName, toFieldValueWire(value, `fieldValues.${fieldName}`)]));
|
|
5486
|
+
}
|
|
5487
|
+
function unwrapFieldValueWire(value) {
|
|
5488
|
+
if (!isPlainObject(value))
|
|
5489
|
+
return value;
|
|
5490
|
+
if ("scalar" in value)
|
|
5491
|
+
return value.scalar;
|
|
5492
|
+
if ("list" in value)
|
|
5493
|
+
return value.list;
|
|
5494
|
+
if ("tree" in value && isPlainObject(value.tree)) {
|
|
5495
|
+
return Object.fromEntries(Object.entries(value.tree).map(([fieldName, child]) => [fieldName, unwrapFieldValueWire(child)]));
|
|
5496
|
+
}
|
|
5497
|
+
if ("treeList" in value && Array.isArray(value.treeList)) {
|
|
5498
|
+
return value.treeList.map((item) => unwrapFieldValueWire(item));
|
|
5499
|
+
}
|
|
5500
|
+
return value;
|
|
5501
|
+
}
|
|
5502
|
+
function unwrapFieldValuesWire(values) {
|
|
5503
|
+
if (!isPlainObject(values))
|
|
5504
|
+
return values;
|
|
5505
|
+
return Object.fromEntries(Object.entries(values).map(([fieldName, value]) => [fieldName, unwrapFieldValueWire(value)]));
|
|
5506
|
+
}
|
|
5507
|
+
function unwrapScenarioFieldValuesInResponse(value) {
|
|
5508
|
+
if (Array.isArray(value))
|
|
5509
|
+
return value.map(unwrapScenarioFieldValuesInResponse);
|
|
5510
|
+
if (!isPlainObject(value))
|
|
5511
|
+
return value;
|
|
5512
|
+
return Object.fromEntries(Object.entries(value).map(([key, child]) => [
|
|
5513
|
+
key,
|
|
5514
|
+
key === "fieldValues" ? unwrapFieldValuesWire(child) : unwrapScenarioFieldValuesInResponse(child)
|
|
5515
|
+
]));
|
|
5516
|
+
}
|
|
5517
|
+
|
|
5458
5518
|
// src/commands/show-schemas.ts
|
|
5459
5519
|
var FIELD_VIEW = `FieldView:
|
|
5460
5520
|
{
|
|
@@ -5713,22 +5773,22 @@ function registerShowCommands(program) {
|
|
|
5713
5773
|
const show = program.command("show").description("Show detailed information");
|
|
5714
5774
|
show.command("model").description("Show full model hierarchy").addHelpText("after", SHOW_MODEL_HELP).action(async () => {
|
|
5715
5775
|
const modelId = requireModelId();
|
|
5716
|
-
out(unwrap(await showModel({ path: { modelId } })));
|
|
5776
|
+
out(unwrapScenarioFieldValuesInResponse(unwrap(await showModel({ path: { modelId } }))));
|
|
5717
5777
|
});
|
|
5718
5778
|
show.command("context [name]").description("Show context with contained chapters and slices").addHelpText("after", SHOW_CONTEXT_HELP).action(async (name, cmd) => {
|
|
5719
5779
|
const modelId = requireModelId();
|
|
5720
5780
|
const contextId = await resolve2(modelId, "context", name ?? "", getGlobalId());
|
|
5721
|
-
out(unwrap(await showContext({ path: { modelId, contextId } })));
|
|
5781
|
+
out(unwrapScenarioFieldValuesInResponse(unwrap(await showContext({ path: { modelId, contextId } }))));
|
|
5722
5782
|
});
|
|
5723
5783
|
show.command("chapter [name]").description("Show chapter with contained slices").addHelpText("after", SHOW_CHAPTER_HELP).action(async (name, cmd) => {
|
|
5724
5784
|
const modelId = requireModelId();
|
|
5725
5785
|
const chapterId = await resolve2(modelId, "chapter", name ?? "", getGlobalId());
|
|
5726
|
-
out(unwrap(await showChapter({ path: { modelId, chapterId } })));
|
|
5786
|
+
out(unwrapScenarioFieldValuesInResponse(unwrap(await showChapter({ path: { modelId, chapterId } }))));
|
|
5727
5787
|
});
|
|
5728
5788
|
show.command("slice [name]").description("Show slice with all elements, flows, and scenarios").addHelpText("after", SHOW_SLICE_HELP).action(async (name, cmd) => {
|
|
5729
5789
|
const modelId = requireModelId();
|
|
5730
5790
|
const sliceId = await resolve2(modelId, "slice", name ?? "", getGlobalId());
|
|
5731
|
-
out(unwrap(await showSlice({ path: { modelId, sliceId } })));
|
|
5791
|
+
out(unwrapScenarioFieldValuesInResponse(unwrap(await showSlice({ path: { modelId, sliceId } }))));
|
|
5732
5792
|
});
|
|
5733
5793
|
for (const type of ["event", "command", "readmodel", "screen", "processor", "external-event"]) {
|
|
5734
5794
|
show.command(`${type} [name]`).description(`Show ${type} detail with fields and flows`).addHelpText("after", SHOW_ELEMENT_HELP).action(async (name, cmd) => {
|
|
@@ -5817,7 +5877,7 @@ var ADD_SUBFIELD_MAP = {
|
|
|
5817
5877
|
processor: addProcessorSubfield,
|
|
5818
5878
|
"external-event": addExternalEventSubfield
|
|
5819
5879
|
};
|
|
5820
|
-
function
|
|
5880
|
+
function isPlainObject2(v) {
|
|
5821
5881
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
5822
5882
|
}
|
|
5823
5883
|
var ENTRY_DISPATCH = {
|
|
@@ -5871,8 +5931,8 @@ async function addEntries(modelId, scenarioId, section, entries, positionOffset
|
|
|
5871
5931
|
if (entry.fieldValues) {
|
|
5872
5932
|
for (const [fieldName, value] of Object.entries(entry.fieldValues)) {
|
|
5873
5933
|
if (Array.isArray(value)) {
|
|
5874
|
-
const allObjects = value.length > 0 && value.every(
|
|
5875
|
-
const anyObject = value.some((v) =>
|
|
5934
|
+
const allObjects = value.length > 0 && value.every(isPlainObject2);
|
|
5935
|
+
const anyObject = value.some((v) => isPlainObject2(v));
|
|
5876
5936
|
if (allObjects) {
|
|
5877
5937
|
if (!info.setFieldCustomListValues)
|
|
5878
5938
|
throw new Error(`Cannot set Custom list values on ${entry.entryType}`);
|
|
@@ -5888,7 +5948,7 @@ async function addEntries(modelId, scenarioId, section, entries, positionOffset
|
|
|
5888
5948
|
body: { modelId, scenarioId, entryId, fieldName, values: value.map(String) }
|
|
5889
5949
|
}));
|
|
5890
5950
|
}
|
|
5891
|
-
} else if (
|
|
5951
|
+
} else if (isPlainObject2(value)) {
|
|
5892
5952
|
if (!info.setFieldCustomValue)
|
|
5893
5953
|
throw new Error(`Cannot set Custom value on ${entry.entryType}`);
|
|
5894
5954
|
unwrap(await info.setFieldCustomValue({
|
|
@@ -5906,6 +5966,60 @@ async function addEntries(modelId, scenarioId, section, entries, positionOffset
|
|
|
5906
5966
|
}
|
|
5907
5967
|
}
|
|
5908
5968
|
}
|
|
5969
|
+
async function createScenarioFromJson(json, sliceName) {
|
|
5970
|
+
const modelId = requireModelId();
|
|
5971
|
+
const sliceId = await resolve2(modelId, "slice", sliceName, getGlobalId());
|
|
5972
|
+
const spec = JSON.parse(json);
|
|
5973
|
+
const scenarioId = randomUUID();
|
|
5974
|
+
const buildEntries = async (section, entries) => {
|
|
5975
|
+
if (!entries)
|
|
5976
|
+
return [];
|
|
5977
|
+
const dispatch = ENTRY_DISPATCH[section];
|
|
5978
|
+
const out2 = [];
|
|
5979
|
+
for (const entry of entries) {
|
|
5980
|
+
const info = dispatch[entry.entryType];
|
|
5981
|
+
if (!info) {
|
|
5982
|
+
throw new Error(`Unknown ${section} entry type: ${entry.entryType}`);
|
|
5983
|
+
}
|
|
5984
|
+
if (entry.entryType === "error") {
|
|
5985
|
+
out2.push({
|
|
5986
|
+
entryType: "error",
|
|
5987
|
+
errorType: entry.errorType ?? "",
|
|
5988
|
+
errorMessage: entry.errorMessage ?? "",
|
|
5989
|
+
fieldValues: {}
|
|
5990
|
+
});
|
|
5991
|
+
} else {
|
|
5992
|
+
if (!entry.elementName) {
|
|
5993
|
+
throw new Error(`${section} ${entry.entryType} entry is missing elementName`);
|
|
5994
|
+
}
|
|
5995
|
+
const elementId = await resolve2(modelId, info.resolveType, entry.elementName);
|
|
5996
|
+
out2.push({
|
|
5997
|
+
entryType: entry.entryType,
|
|
5998
|
+
elementId,
|
|
5999
|
+
fieldValues: toFieldValuesWire(entry.fieldValues)
|
|
6000
|
+
});
|
|
6001
|
+
}
|
|
6002
|
+
}
|
|
6003
|
+
return out2;
|
|
6004
|
+
};
|
|
6005
|
+
const given = await buildEntries("given", spec.given);
|
|
6006
|
+
const when = await buildEntries("when", spec.when);
|
|
6007
|
+
const then = await buildEntries("then", spec.then);
|
|
6008
|
+
unwrap(await createScenario({
|
|
6009
|
+
body: {
|
|
6010
|
+
modelId,
|
|
6011
|
+
sliceId,
|
|
6012
|
+
scenarioId,
|
|
6013
|
+
name: spec.name,
|
|
6014
|
+
...spec.description ? { description: spec.description } : {},
|
|
6015
|
+
given,
|
|
6016
|
+
when,
|
|
6017
|
+
then
|
|
6018
|
+
}
|
|
6019
|
+
}));
|
|
6020
|
+
const entryCount = given.length + when.length + then.length;
|
|
6021
|
+
return { name: spec.name, entryCount };
|
|
6022
|
+
}
|
|
5909
6023
|
function registerAddCommands(program) {
|
|
5910
6024
|
const add = program.command("add").description("Add fields or scenarios");
|
|
5911
6025
|
add.command("field [elementName] <json>").description("Add a field to an element").action(async (elementNameOrJson, jsonOrUndefined, cmd) => {
|
|
@@ -5998,7 +6112,7 @@ element name doesn't resolve, the whole spec is rejected before hitting the
|
|
|
5998
6112
|
backend.
|
|
5999
6113
|
|
|
6000
6114
|
Example (primitives + Custom + list):
|
|
6001
|
-
|
|
6115
|
+
create scenario --slice "Place Order" '{
|
|
6002
6116
|
"name": "happy path",
|
|
6003
6117
|
"when": [{ "entryType": "command", "elementName": "PlaceOrder",
|
|
6004
6118
|
"fieldValues": { "orderId": "uuid-1",
|
|
@@ -6009,58 +6123,8 @@ Example (primitives + Custom + list):
|
|
|
6009
6123
|
{ "sku": "sku-2", "qty": "1" } ] } }]
|
|
6010
6124
|
}'
|
|
6011
6125
|
`).action(async (json, opts, cmd) => {
|
|
6012
|
-
const
|
|
6013
|
-
|
|
6014
|
-
const spec = JSON.parse(json);
|
|
6015
|
-
const scenarioId = randomUUID();
|
|
6016
|
-
const buildEntries = async (section, entries) => {
|
|
6017
|
-
if (!entries)
|
|
6018
|
-
return [];
|
|
6019
|
-
const dispatch = ENTRY_DISPATCH[section];
|
|
6020
|
-
const out2 = [];
|
|
6021
|
-
for (const entry of entries) {
|
|
6022
|
-
const info = dispatch[entry.entryType];
|
|
6023
|
-
if (!info) {
|
|
6024
|
-
throw new Error(`Unknown ${section} entry type: ${entry.entryType}`);
|
|
6025
|
-
}
|
|
6026
|
-
if (entry.entryType === "error") {
|
|
6027
|
-
out2.push({
|
|
6028
|
-
entryType: "error",
|
|
6029
|
-
errorType: entry.errorType ?? "",
|
|
6030
|
-
errorMessage: entry.errorMessage ?? "",
|
|
6031
|
-
fieldValues: {}
|
|
6032
|
-
});
|
|
6033
|
-
} else {
|
|
6034
|
-
if (!entry.elementName) {
|
|
6035
|
-
throw new Error(`${section} ${entry.entryType} entry is missing elementName`);
|
|
6036
|
-
}
|
|
6037
|
-
const elementId = await resolve2(modelId, info.resolveType, entry.elementName);
|
|
6038
|
-
out2.push({
|
|
6039
|
-
entryType: entry.entryType,
|
|
6040
|
-
elementId,
|
|
6041
|
-
fieldValues: entry.fieldValues ?? {}
|
|
6042
|
-
});
|
|
6043
|
-
}
|
|
6044
|
-
}
|
|
6045
|
-
return out2;
|
|
6046
|
-
};
|
|
6047
|
-
const given = await buildEntries("given", spec.given);
|
|
6048
|
-
const when = await buildEntries("when", spec.when);
|
|
6049
|
-
const then = await buildEntries("then", spec.then);
|
|
6050
|
-
unwrap(await createScenario({
|
|
6051
|
-
body: {
|
|
6052
|
-
modelId,
|
|
6053
|
-
sliceId,
|
|
6054
|
-
scenarioId,
|
|
6055
|
-
name: spec.name,
|
|
6056
|
-
...spec.description ? { description: spec.description } : {},
|
|
6057
|
-
given,
|
|
6058
|
-
when,
|
|
6059
|
-
then
|
|
6060
|
-
}
|
|
6061
|
-
}));
|
|
6062
|
-
const entryCount = given.length + when.length + then.length;
|
|
6063
|
-
console.log(`Added scenario "${spec.name}"${entryCount > 0 ? ` with ${entryCount} entries` : ""}.`);
|
|
6126
|
+
const result = await createScenarioFromJson(json, opts.slice);
|
|
6127
|
+
console.log(`Created scenario "${result.name}"${result.entryCount > 0 ? ` with ${result.entryCount} entries` : ""}.`);
|
|
6064
6128
|
});
|
|
6065
6129
|
add.command("entry").description("Add a GWT entry to a scenario").requiredOption("--scenario <name>", "Scenario name").requiredOption("--section <section>", "Section: given, when, or then").requiredOption("--type <type>", "Entry type: event, command, readmodel, or error").option("--element <name>", "Element name (required unless --type error)").option("--error-type <type>", "Error type (for --type error)").option("--error-message <msg>", "Error message (for --type error)").option("--position <n>", "Position within section (appends at end by default)", parseInt).action(async (opts) => {
|
|
6066
6130
|
const modelId = requireModelId();
|
|
@@ -6317,6 +6381,23 @@ function registerResizeCommands(program) {
|
|
|
6317
6381
|
|
|
6318
6382
|
// src/commands/create.ts
|
|
6319
6383
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
6384
|
+
function normalizeSliceFields(fields) {
|
|
6385
|
+
return (fields ?? []).map((field) => ({
|
|
6386
|
+
...field,
|
|
6387
|
+
id: field.id ?? randomUUID2(),
|
|
6388
|
+
type: field.type ?? field.fieldType,
|
|
6389
|
+
subfields: normalizeSliceFields(field.subfields)
|
|
6390
|
+
}));
|
|
6391
|
+
}
|
|
6392
|
+
function normalizeSliceSpec(spec) {
|
|
6393
|
+
return {
|
|
6394
|
+
...spec,
|
|
6395
|
+
elements: (spec.elements ?? []).map((element) => ({
|
|
6396
|
+
...element,
|
|
6397
|
+
fields: normalizeSliceFields(element.fields)
|
|
6398
|
+
}))
|
|
6399
|
+
};
|
|
6400
|
+
}
|
|
6320
6401
|
var FLOW_DISPATCH = {
|
|
6321
6402
|
"screen->command": { fn: specifyScreenToCommandFlow, sourceHandle: "bottom-source", targetHandle: "top-target" },
|
|
6322
6403
|
"command->event": { fn: specifyCommandToEventFlow, sourceHandle: "bottom-source", targetHandle: "top-target" },
|
|
@@ -6372,9 +6453,14 @@ function registerCreateCommands(program) {
|
|
|
6372
6453
|
create.command("slice <json>").description("Create a full slice from JSON specification").action(async (json) => {
|
|
6373
6454
|
const modelId = requireModelId();
|
|
6374
6455
|
const spec = JSON.parse(json);
|
|
6375
|
-
|
|
6456
|
+
const body = { modelId, sliceId: randomUUID2(), ...normalizeSliceSpec(spec) };
|
|
6457
|
+
unwrap(await createSlice({ body }));
|
|
6376
6458
|
console.log("Created slice.");
|
|
6377
6459
|
});
|
|
6460
|
+
create.command("scenario <json>").description("Atomically create a full Given/When/Then scenario").requiredOption("--slice <name>", "Slice name").action(async (json, opts) => {
|
|
6461
|
+
const result = await createScenarioFromJson(json, opts.slice);
|
|
6462
|
+
console.log(`Created scenario "${result.name}"${result.entryCount > 0 ? ` with ${result.entryCount} entries` : ""}.`);
|
|
6463
|
+
});
|
|
6378
6464
|
create.command("flow").description("Create a flow between two elements").requiredOption("--from <source>", "Source element name").requiredOption("--to <target>", "Target element name").option("--source-handle <handle>", "Source handle ID (default: auto based on flow type)").option("--target-handle <handle>", "Target handle ID (default: auto based on flow type)").action(async (opts) => {
|
|
6379
6465
|
const modelId = requireModelId();
|
|
6380
6466
|
const source = await resolveAnyElement(modelId, opts.from);
|
package/package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eventmodeler",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"description": "CLI tool for event modeling - explore, design, and generate code from your event models",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/theoema/event-modeler.git"
|
|
9
|
+
},
|
|
6
10
|
"bin": {
|
|
7
11
|
"eventmodeler": "./dist/index.js"
|
|
8
12
|
},
|