@mmmnt/cli 0.7.2 → 0.9.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/dist/moment.mjs CHANGED
@@ -36671,6 +36671,20 @@ ${obj.gpgsig ? obj.gpgsig : ""}`;
36671
36671
  import { parseArgs } from "node:util";
36672
36672
  import { resolve as resolve5 } from "node:path";
36673
36673
 
36674
+ // ../core/dist/ir/emits.js
36675
+ function emitOutcomes(cmd) {
36676
+ if (cmd.outcomes !== void 0)
36677
+ return cmd.outcomes.map((o) => ({ ...o, events: [...o.events] }));
36678
+ return cmd.emitsEvent ? [{ events: [cmd.emitsEvent] }] : [];
36679
+ }
36680
+ function emittedEvents(cmd) {
36681
+ return [...new Set(emitOutcomes(cmd).flatMap((o) => o.events))];
36682
+ }
36683
+ function matchEmitOutcome(outcomes, placed) {
36684
+ const exact = outcomes.findIndex((o) => o.events.length === placed.length && placed.every((e) => o.events.includes(e)));
36685
+ return exact !== -1 ? exact : outcomes.findIndex((o) => placed.every((e) => o.events.includes(e)));
36686
+ }
36687
+
36674
36688
  // ../core/dist/services/schema-validator.js
36675
36689
  var SchemaValidator = class {
36676
36690
  /**
@@ -43925,13 +43939,13 @@ var OccurrenceValidationCollector = class extends GAstVisitor {
43925
43939
  };
43926
43940
  function validateRuleDoesNotAlreadyExist(rule, allRules, className, errMsgProvider) {
43927
43941
  const errors = [];
43928
- const occurrences = allRules.reduce((result, curRule) => {
43942
+ const occurrences2 = allRules.reduce((result, curRule) => {
43929
43943
  if (curRule.name === rule.name) {
43930
43944
  return result + 1;
43931
43945
  }
43932
43946
  return result;
43933
43947
  }, 0);
43934
- if (occurrences > 1) {
43948
+ if (occurrences2 > 1) {
43935
43949
  const errMsg = errMsgProvider.buildDuplicateRuleNameError({
43936
43950
  topLevelRule: rule,
43937
43951
  grammarName: className
@@ -55302,6 +55316,15 @@ var DomainServiceDeclaration = {
55302
55316
  function isDomainServiceDeclaration(item) {
55303
55317
  return reflection2.isInstance(item, DomainServiceDeclaration.$type);
55304
55318
  }
55319
+ var EmitOutcome = {
55320
+ $type: "EmitOutcome",
55321
+ events: "events",
55322
+ state: "state"
55323
+ };
55324
+ var EmitsClause = {
55325
+ $type: "EmitsClause",
55326
+ outcomes: "outcomes"
55327
+ };
55305
55328
  var ExternalDeclaration = {
55306
55329
  $type: "ExternalDeclaration",
55307
55330
  description: "description",
@@ -55775,6 +55798,30 @@ var MomentAstReflection = class extends AbstractAstReflection {
55775
55798
  },
55776
55799
  superTypes: [ContextMember.$type]
55777
55800
  },
55801
+ EmitOutcome: {
55802
+ name: EmitOutcome.$type,
55803
+ properties: {
55804
+ events: {
55805
+ name: EmitOutcome.events,
55806
+ defaultValue: []
55807
+ },
55808
+ state: {
55809
+ name: EmitOutcome.state,
55810
+ optional: true
55811
+ }
55812
+ },
55813
+ superTypes: []
55814
+ },
55815
+ EmitsClause: {
55816
+ name: EmitsClause.$type,
55817
+ properties: {
55818
+ outcomes: {
55819
+ name: EmitsClause.outcomes,
55820
+ defaultValue: []
55821
+ }
55822
+ },
55823
+ superTypes: []
55824
+ },
55778
55825
  ExternalDeclaration: {
55779
55826
  name: ExternalDeclaration.$type,
55780
55827
  properties: {
@@ -56381,7 +56428,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
56381
56428
  "terminal": {
56382
56429
  "$type": "RuleCall",
56383
56430
  "rule": {
56384
- "$ref": "#/rules@29"
56431
+ "$ref": "#/rules@31"
56385
56432
  },
56386
56433
  "arguments": []
56387
56434
  }
@@ -56421,7 +56468,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
56421
56468
  "terminal": {
56422
56469
  "$type": "RuleCall",
56423
56470
  "rule": {
56424
- "$ref": "#/rules@54"
56471
+ "$ref": "#/rules@56"
56425
56472
  },
56426
56473
  "arguments": []
56427
56474
  }
@@ -56433,7 +56480,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
56433
56480
  "terminal": {
56434
56481
  "$type": "RuleCall",
56435
56482
  "rule": {
56436
- "$ref": "#/rules@55"
56483
+ "$ref": "#/rules@57"
56437
56484
  },
56438
56485
  "arguments": []
56439
56486
  }
@@ -56474,7 +56521,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
56474
56521
  "terminal": {
56475
56522
  "$type": "RuleCall",
56476
56523
  "rule": {
56477
- "$ref": "#/rules@54"
56524
+ "$ref": "#/rules@56"
56478
56525
  },
56479
56526
  "arguments": []
56480
56527
  }
@@ -56490,7 +56537,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
56490
56537
  "terminal": {
56491
56538
  "$type": "RuleCall",
56492
56539
  "rule": {
56493
- "$ref": "#/rules@54"
56540
+ "$ref": "#/rules@56"
56494
56541
  },
56495
56542
  "arguments": []
56496
56543
  }
@@ -56506,7 +56553,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
56506
56553
  "terminal": {
56507
56554
  "$type": "RuleCall",
56508
56555
  "rule": {
56509
- "$ref": "#/rules@54"
56556
+ "$ref": "#/rules@56"
56510
56557
  },
56511
56558
  "arguments": []
56512
56559
  }
@@ -56525,7 +56572,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
56525
56572
  "terminal": {
56526
56573
  "$type": "RuleCall",
56527
56574
  "rule": {
56528
- "$ref": "#/rules@55"
56575
+ "$ref": "#/rules@57"
56529
56576
  },
56530
56577
  "arguments": []
56531
56578
  }
@@ -56556,7 +56603,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
56556
56603
  "terminal": {
56557
56604
  "$type": "RuleCall",
56558
56605
  "rule": {
56559
- "$ref": "#/rules@55"
56606
+ "$ref": "#/rules@57"
56560
56607
  },
56561
56608
  "arguments": []
56562
56609
  }
@@ -56568,7 +56615,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
56568
56615
  "terminal": {
56569
56616
  "$type": "RuleCall",
56570
56617
  "rule": {
56571
- "$ref": "#/rules@51"
56618
+ "$ref": "#/rules@53"
56572
56619
  },
56573
56620
  "arguments": []
56574
56621
  },
@@ -56588,7 +56635,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
56588
56635
  "terminal": {
56589
56636
  "$type": "RuleCall",
56590
56637
  "rule": {
56591
- "$ref": "#/rules@55"
56638
+ "$ref": "#/rules@57"
56592
56639
  },
56593
56640
  "arguments": []
56594
56641
  }
@@ -56631,28 +56678,28 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
56631
56678
  {
56632
56679
  "$type": "RuleCall",
56633
56680
  "rule": {
56634
- "$ref": "#/rules@20"
56681
+ "$ref": "#/rules@22"
56635
56682
  },
56636
56683
  "arguments": []
56637
56684
  },
56638
56685
  {
56639
56686
  "$type": "RuleCall",
56640
56687
  "rule": {
56641
- "$ref": "#/rules@21"
56688
+ "$ref": "#/rules@23"
56642
56689
  },
56643
56690
  "arguments": []
56644
56691
  },
56645
56692
  {
56646
56693
  "$type": "RuleCall",
56647
56694
  "rule": {
56648
- "$ref": "#/rules@22"
56695
+ "$ref": "#/rules@24"
56649
56696
  },
56650
56697
  "arguments": []
56651
56698
  },
56652
56699
  {
56653
56700
  "$type": "RuleCall",
56654
56701
  "rule": {
56655
- "$ref": "#/rules@28"
56702
+ "$ref": "#/rules@30"
56656
56703
  },
56657
56704
  "arguments": []
56658
56705
  },
@@ -56687,7 +56734,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
56687
56734
  {
56688
56735
  "$type": "RuleCall",
56689
56736
  "rule": {
56690
- "$ref": "#/rules@18"
56737
+ "$ref": "#/rules@20"
56691
56738
  },
56692
56739
  "arguments": []
56693
56740
  },
@@ -56721,7 +56768,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
56721
56768
  "terminal": {
56722
56769
  "$type": "RuleCall",
56723
56770
  "rule": {
56724
- "$ref": "#/rules@54"
56771
+ "$ref": "#/rules@56"
56725
56772
  },
56726
56773
  "arguments": []
56727
56774
  }
@@ -56737,7 +56784,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
56737
56784
  "terminal": {
56738
56785
  "$type": "RuleCall",
56739
56786
  "rule": {
56740
- "$ref": "#/rules@54"
56787
+ "$ref": "#/rules@56"
56741
56788
  },
56742
56789
  "arguments": []
56743
56790
  }
@@ -56756,7 +56803,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
56756
56803
  "terminal": {
56757
56804
  "$type": "RuleCall",
56758
56805
  "rule": {
56759
- "$ref": "#/rules@54"
56806
+ "$ref": "#/rules@56"
56760
56807
  },
56761
56808
  "arguments": []
56762
56809
  }
@@ -56778,7 +56825,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
56778
56825
  "terminal": {
56779
56826
  "$type": "RuleCall",
56780
56827
  "rule": {
56781
- "$ref": "#/rules@55"
56828
+ "$ref": "#/rules@57"
56782
56829
  },
56783
56830
  "arguments": []
56784
56831
  }
@@ -56800,7 +56847,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
56800
56847
  "terminal": {
56801
56848
  "$type": "RuleCall",
56802
56849
  "rule": {
56803
- "$ref": "#/rules@45"
56850
+ "$ref": "#/rules@47"
56804
56851
  },
56805
56852
  "arguments": []
56806
56853
  }
@@ -56844,7 +56891,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
56844
56891
  "terminal": {
56845
56892
  "$type": "RuleCall",
56846
56893
  "rule": {
56847
- "$ref": "#/rules@54"
56894
+ "$ref": "#/rules@56"
56848
56895
  },
56849
56896
  "arguments": []
56850
56897
  }
@@ -56856,7 +56903,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
56856
56903
  "terminal": {
56857
56904
  "$type": "RuleCall",
56858
56905
  "rule": {
56859
- "$ref": "#/rules@55"
56906
+ "$ref": "#/rules@57"
56860
56907
  },
56861
56908
  "arguments": []
56862
56909
  }
@@ -56875,7 +56922,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
56875
56922
  "terminal": {
56876
56923
  "$type": "RuleCall",
56877
56924
  "rule": {
56878
- "$ref": "#/rules@54"
56925
+ "$ref": "#/rules@56"
56879
56926
  },
56880
56927
  "arguments": []
56881
56928
  }
@@ -56887,7 +56934,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
56887
56934
  "terminal": {
56888
56935
  "$type": "RuleCall",
56889
56936
  "rule": {
56890
- "$ref": "#/rules@55"
56937
+ "$ref": "#/rules@57"
56891
56938
  },
56892
56939
  "arguments": []
56893
56940
  }
@@ -56917,7 +56964,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
56917
56964
  "terminal": {
56918
56965
  "$type": "RuleCall",
56919
56966
  "rule": {
56920
- "$ref": "#/rules@55"
56967
+ "$ref": "#/rules@57"
56921
56968
  },
56922
56969
  "arguments": []
56923
56970
  }
@@ -56929,7 +56976,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
56929
56976
  "terminal": {
56930
56977
  "$type": "RuleCall",
56931
56978
  "rule": {
56932
- "$ref": "#/rules@55"
56979
+ "$ref": "#/rules@57"
56933
56980
  },
56934
56981
  "arguments": []
56935
56982
  }
@@ -56957,7 +57004,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
56957
57004
  "terminal": {
56958
57005
  "$type": "RuleCall",
56959
57006
  "rule": {
56960
- "$ref": "#/rules@54"
57007
+ "$ref": "#/rules@56"
56961
57008
  },
56962
57009
  "arguments": []
56963
57010
  }
@@ -56973,7 +57020,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
56973
57020
  "terminal": {
56974
57021
  "$type": "RuleCall",
56975
57022
  "rule": {
56976
- "$ref": "#/rules@54"
57023
+ "$ref": "#/rules@56"
56977
57024
  },
56978
57025
  "arguments": []
56979
57026
  }
@@ -56992,7 +57039,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
56992
57039
  "terminal": {
56993
57040
  "$type": "RuleCall",
56994
57041
  "rule": {
56995
- "$ref": "#/rules@54"
57042
+ "$ref": "#/rules@56"
56996
57043
  },
56997
57044
  "arguments": []
56998
57045
  }
@@ -57014,7 +57061,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57014
57061
  "terminal": {
57015
57062
  "$type": "RuleCall",
57016
57063
  "rule": {
57017
- "$ref": "#/rules@15"
57064
+ "$ref": "#/rules@17"
57018
57065
  },
57019
57066
  "arguments": []
57020
57067
  }
@@ -57033,7 +57080,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57033
57080
  "terminal": {
57034
57081
  "$type": "RuleCall",
57035
57082
  "rule": {
57036
- "$ref": "#/rules@15"
57083
+ "$ref": "#/rules@17"
57037
57084
  },
57038
57085
  "arguments": []
57039
57086
  }
@@ -57058,7 +57105,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57058
57105
  "terminal": {
57059
57106
  "$type": "RuleCall",
57060
57107
  "rule": {
57061
- "$ref": "#/rules@55"
57108
+ "$ref": "#/rules@57"
57062
57109
  },
57063
57110
  "arguments": []
57064
57111
  }
@@ -57089,7 +57136,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57089
57136
  "terminal": {
57090
57137
  "$type": "RuleCall",
57091
57138
  "rule": {
57092
- "$ref": "#/rules@54"
57139
+ "$ref": "#/rules@56"
57093
57140
  },
57094
57141
  "arguments": []
57095
57142
  }
@@ -57130,14 +57177,14 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57130
57177
  {
57131
57178
  "$type": "RuleCall",
57132
57179
  "rule": {
57133
- "$ref": "#/rules@54"
57180
+ "$ref": "#/rules@56"
57134
57181
  },
57135
57182
  "arguments": []
57136
57183
  },
57137
57184
  {
57138
57185
  "$type": "RuleCall",
57139
57186
  "rule": {
57140
- "$ref": "#/rules@55"
57187
+ "$ref": "#/rules@57"
57141
57188
  },
57142
57189
  "arguments": []
57143
57190
  }
@@ -57164,7 +57211,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57164
57211
  "terminal": {
57165
57212
  "$type": "RuleCall",
57166
57213
  "rule": {
57167
- "$ref": "#/rules@55"
57214
+ "$ref": "#/rules@57"
57168
57215
  },
57169
57216
  "arguments": []
57170
57217
  }
@@ -57180,7 +57227,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57180
57227
  "terminal": {
57181
57228
  "$type": "RuleCall",
57182
57229
  "rule": {
57183
- "$ref": "#/rules@45"
57230
+ "$ref": "#/rules@47"
57184
57231
  },
57185
57232
  "arguments": []
57186
57233
  }
@@ -57233,21 +57280,21 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57233
57280
  {
57234
57281
  "$type": "RuleCall",
57235
57282
  "rule": {
57236
- "$ref": "#/rules@17"
57283
+ "$ref": "#/rules@19"
57237
57284
  },
57238
57285
  "arguments": []
57239
57286
  },
57240
57287
  {
57241
57288
  "$type": "RuleCall",
57242
57289
  "rule": {
57243
- "$ref": "#/rules@18"
57290
+ "$ref": "#/rules@20"
57244
57291
  },
57245
57292
  "arguments": []
57246
57293
  },
57247
57294
  {
57248
57295
  "$type": "RuleCall",
57249
57296
  "rule": {
57250
- "$ref": "#/rules@19"
57297
+ "$ref": "#/rules@21"
57251
57298
  },
57252
57299
  "arguments": []
57253
57300
  },
@@ -57296,7 +57343,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57296
57343
  "terminal": {
57297
57344
  "$type": "RuleCall",
57298
57345
  "rule": {
57299
- "$ref": "#/rules@54"
57346
+ "$ref": "#/rules@56"
57300
57347
  },
57301
57348
  "arguments": []
57302
57349
  }
@@ -57313,7 +57360,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57313
57360
  "terminal": {
57314
57361
  "$type": "RuleCall",
57315
57362
  "rule": {
57316
- "$ref": "#/rules@54"
57363
+ "$ref": "#/rules@56"
57317
57364
  },
57318
57365
  "arguments": []
57319
57366
  }
@@ -57329,7 +57376,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57329
57376
  "terminal": {
57330
57377
  "$type": "RuleCall",
57331
57378
  "rule": {
57332
- "$ref": "#/rules@54"
57379
+ "$ref": "#/rules@56"
57333
57380
  },
57334
57381
  "arguments": []
57335
57382
  }
@@ -57345,7 +57392,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57345
57392
  "terminal": {
57346
57393
  "$type": "RuleCall",
57347
57394
  "rule": {
57348
- "$ref": "#/rules@54"
57395
+ "$ref": "#/rules@56"
57349
57396
  },
57350
57397
  "arguments": []
57351
57398
  }
@@ -57377,7 +57424,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57377
57424
  "terminal": {
57378
57425
  "$type": "RuleCall",
57379
57426
  "rule": {
57380
- "$ref": "#/rules@54"
57427
+ "$ref": "#/rules@56"
57381
57428
  },
57382
57429
  "arguments": []
57383
57430
  }
@@ -57396,7 +57443,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57396
57443
  "terminal": {
57397
57444
  "$type": "RuleCall",
57398
57445
  "rule": {
57399
- "$ref": "#/rules@15"
57446
+ "$ref": "#/rules@17"
57400
57447
  },
57401
57448
  "arguments": []
57402
57449
  }
@@ -57415,7 +57462,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57415
57462
  "terminal": {
57416
57463
  "$type": "RuleCall",
57417
57464
  "rule": {
57418
- "$ref": "#/rules@15"
57465
+ "$ref": "#/rules@17"
57419
57466
  },
57420
57467
  "arguments": []
57421
57468
  }
@@ -57440,7 +57487,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57440
57487
  "terminal": {
57441
57488
  "$type": "RuleCall",
57442
57489
  "rule": {
57443
- "$ref": "#/rules@54"
57490
+ "$ref": "#/rules@56"
57444
57491
  },
57445
57492
  "arguments": []
57446
57493
  }
@@ -57459,7 +57506,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57459
57506
  "terminal": {
57460
57507
  "$type": "RuleCall",
57461
57508
  "rule": {
57462
- "$ref": "#/rules@54"
57509
+ "$ref": "#/rules@56"
57463
57510
  },
57464
57511
  "arguments": []
57465
57512
  }
@@ -57477,27 +57524,141 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57477
57524
  "terminal": {
57478
57525
  "$type": "RuleCall",
57479
57526
  "rule": {
57480
- "$ref": "#/rules@16"
57527
+ "$ref": "#/rules@18"
57481
57528
  },
57482
57529
  "arguments": []
57483
57530
  },
57484
57531
  "cardinality": "*"
57485
57532
  },
57533
+ {
57534
+ "$type": "Assignment",
57535
+ "feature": "emits",
57536
+ "operator": "=",
57537
+ "terminal": {
57538
+ "$type": "RuleCall",
57539
+ "rule": {
57540
+ "$ref": "#/rules@15"
57541
+ },
57542
+ "arguments": []
57543
+ }
57544
+ }
57545
+ ]
57546
+ },
57547
+ "entry": false,
57548
+ "fragment": false,
57549
+ "parameters": []
57550
+ },
57551
+ {
57552
+ "$type": "ParserRule",
57553
+ "name": "EmitsClause",
57554
+ "definition": {
57555
+ "$type": "Group",
57556
+ "elements": [
57486
57557
  {
57487
57558
  "$type": "Keyword",
57488
57559
  "value": "emits"
57489
57560
  },
57490
57561
  {
57491
57562
  "$type": "Assignment",
57492
- "feature": "emits",
57493
- "operator": "=",
57563
+ "feature": "outcomes",
57564
+ "operator": "+=",
57494
57565
  "terminal": {
57495
57566
  "$type": "RuleCall",
57496
57567
  "rule": {
57497
- "$ref": "#/rules@54"
57568
+ "$ref": "#/rules@16"
57498
57569
  },
57499
57570
  "arguments": []
57500
57571
  }
57572
+ },
57573
+ {
57574
+ "$type": "Group",
57575
+ "elements": [
57576
+ {
57577
+ "$type": "Keyword",
57578
+ "value": "|"
57579
+ },
57580
+ {
57581
+ "$type": "Assignment",
57582
+ "feature": "outcomes",
57583
+ "operator": "+=",
57584
+ "terminal": {
57585
+ "$type": "RuleCall",
57586
+ "rule": {
57587
+ "$ref": "#/rules@16"
57588
+ },
57589
+ "arguments": []
57590
+ }
57591
+ }
57592
+ ],
57593
+ "cardinality": "*"
57594
+ }
57595
+ ]
57596
+ },
57597
+ "entry": false,
57598
+ "fragment": false,
57599
+ "parameters": []
57600
+ },
57601
+ {
57602
+ "$type": "ParserRule",
57603
+ "name": "EmitOutcome",
57604
+ "definition": {
57605
+ "$type": "Group",
57606
+ "elements": [
57607
+ {
57608
+ "$type": "Assignment",
57609
+ "feature": "events",
57610
+ "operator": "+=",
57611
+ "terminal": {
57612
+ "$type": "RuleCall",
57613
+ "rule": {
57614
+ "$ref": "#/rules@56"
57615
+ },
57616
+ "arguments": []
57617
+ }
57618
+ },
57619
+ {
57620
+ "$type": "Group",
57621
+ "elements": [
57622
+ {
57623
+ "$type": "Keyword",
57624
+ "value": ","
57625
+ },
57626
+ {
57627
+ "$type": "Assignment",
57628
+ "feature": "events",
57629
+ "operator": "+=",
57630
+ "terminal": {
57631
+ "$type": "RuleCall",
57632
+ "rule": {
57633
+ "$ref": "#/rules@56"
57634
+ },
57635
+ "arguments": []
57636
+ }
57637
+ }
57638
+ ],
57639
+ "cardinality": "*"
57640
+ },
57641
+ {
57642
+ "$type": "Group",
57643
+ "elements": [
57644
+ {
57645
+ "$type": "Keyword",
57646
+ "value": "when"
57647
+ },
57648
+ {
57649
+ "$type": "Assignment",
57650
+ "feature": "state",
57651
+ "operator": "=",
57652
+ "terminal": {
57653
+ "$type": "RuleCall",
57654
+ "rule": {
57655
+ "$ref": "#/rules@56"
57656
+ },
57657
+ "arguments": []
57658
+ }
57659
+ }
57660
+ ],
57661
+ "cardinality": "?"
57501
57662
  }
57502
57663
  ]
57503
57664
  },
@@ -57518,7 +57679,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57518
57679
  "terminal": {
57519
57680
  "$type": "RuleCall",
57520
57681
  "rule": {
57521
- "$ref": "#/rules@47"
57682
+ "$ref": "#/rules@49"
57522
57683
  },
57523
57684
  "arguments": []
57524
57685
  }
@@ -57534,7 +57695,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57534
57695
  "terminal": {
57535
57696
  "$type": "RuleCall",
57536
57697
  "rule": {
57537
- "$ref": "#/rules@49"
57698
+ "$ref": "#/rules@51"
57538
57699
  },
57539
57700
  "arguments": []
57540
57701
  }
@@ -57546,7 +57707,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57546
57707
  "terminal": {
57547
57708
  "$type": "RuleCall",
57548
57709
  "rule": {
57549
- "$ref": "#/rules@46"
57710
+ "$ref": "#/rules@48"
57550
57711
  },
57551
57712
  "arguments": []
57552
57713
  },
@@ -57575,7 +57736,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57575
57736
  "terminal": {
57576
57737
  "$type": "RuleCall",
57577
57738
  "rule": {
57578
- "$ref": "#/rules@54"
57739
+ "$ref": "#/rules@56"
57579
57740
  },
57580
57741
  "arguments": []
57581
57742
  }
@@ -57594,7 +57755,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57594
57755
  "terminal": {
57595
57756
  "$type": "RuleCall",
57596
57757
  "rule": {
57597
- "$ref": "#/rules@54"
57758
+ "$ref": "#/rules@56"
57598
57759
  },
57599
57760
  "arguments": []
57600
57761
  }
@@ -57613,7 +57774,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57613
57774
  "terminal": {
57614
57775
  "$type": "RuleCall",
57615
57776
  "rule": {
57616
- "$ref": "#/rules@54"
57777
+ "$ref": "#/rules@56"
57617
57778
  },
57618
57779
  "arguments": []
57619
57780
  }
@@ -57635,7 +57796,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57635
57796
  "terminal": {
57636
57797
  "$type": "RuleCall",
57637
57798
  "rule": {
57638
- "$ref": "#/rules@55"
57799
+ "$ref": "#/rules@57"
57639
57800
  },
57640
57801
  "arguments": []
57641
57802
  }
@@ -57663,7 +57824,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57663
57824
  "terminal": {
57664
57825
  "$type": "RuleCall",
57665
57826
  "rule": {
57666
- "$ref": "#/rules@54"
57827
+ "$ref": "#/rules@56"
57667
57828
  },
57668
57829
  "arguments": []
57669
57830
  }
@@ -57675,7 +57836,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57675
57836
  "terminal": {
57676
57837
  "$type": "RuleCall",
57677
57838
  "rule": {
57678
- "$ref": "#/rules@45"
57839
+ "$ref": "#/rules@47"
57679
57840
  },
57680
57841
  "arguments": []
57681
57842
  },
@@ -57704,7 +57865,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57704
57865
  "terminal": {
57705
57866
  "$type": "RuleCall",
57706
57867
  "rule": {
57707
- "$ref": "#/rules@54"
57868
+ "$ref": "#/rules@56"
57708
57869
  },
57709
57870
  "arguments": []
57710
57871
  }
@@ -57716,7 +57877,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57716
57877
  "terminal": {
57717
57878
  "$type": "RuleCall",
57718
57879
  "rule": {
57719
- "$ref": "#/rules@45"
57880
+ "$ref": "#/rules@47"
57720
57881
  },
57721
57882
  "arguments": []
57722
57883
  },
@@ -57745,7 +57906,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57745
57906
  "terminal": {
57746
57907
  "$type": "RuleCall",
57747
57908
  "rule": {
57748
- "$ref": "#/rules@54"
57909
+ "$ref": "#/rules@56"
57749
57910
  },
57750
57911
  "arguments": []
57751
57912
  }
@@ -57757,7 +57918,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57757
57918
  "terminal": {
57758
57919
  "$type": "RuleCall",
57759
57920
  "rule": {
57760
- "$ref": "#/rules@55"
57921
+ "$ref": "#/rules@57"
57761
57922
  },
57762
57923
  "arguments": []
57763
57924
  }
@@ -57773,7 +57934,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57773
57934
  "terminal": {
57774
57935
  "$type": "RuleCall",
57775
57936
  "rule": {
57776
- "$ref": "#/rules@54"
57937
+ "$ref": "#/rules@56"
57777
57938
  },
57778
57939
  "arguments": []
57779
57940
  }
@@ -57801,7 +57962,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57801
57962
  "terminal": {
57802
57963
  "$type": "RuleCall",
57803
57964
  "rule": {
57804
- "$ref": "#/rules@54"
57965
+ "$ref": "#/rules@56"
57805
57966
  },
57806
57967
  "arguments": []
57807
57968
  }
@@ -57817,7 +57978,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57817
57978
  "terminal": {
57818
57979
  "$type": "RuleCall",
57819
57980
  "rule": {
57820
- "$ref": "#/rules@54"
57981
+ "$ref": "#/rules@56"
57821
57982
  },
57822
57983
  "arguments": []
57823
57984
  }
@@ -57833,7 +57994,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57833
57994
  "terminal": {
57834
57995
  "$type": "RuleCall",
57835
57996
  "rule": {
57836
- "$ref": "#/rules@54"
57997
+ "$ref": "#/rules@56"
57837
57998
  },
57838
57999
  "arguments": []
57839
58000
  }
@@ -57849,7 +58010,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57849
58010
  "terminal": {
57850
58011
  "$type": "RuleCall",
57851
58012
  "rule": {
57852
- "$ref": "#/rules@55"
58013
+ "$ref": "#/rules@57"
57853
58014
  },
57854
58015
  "arguments": []
57855
58016
  }
@@ -57877,7 +58038,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57877
58038
  "terminal": {
57878
58039
  "$type": "RuleCall",
57879
58040
  "rule": {
57880
- "$ref": "#/rules@54"
58041
+ "$ref": "#/rules@56"
57881
58042
  },
57882
58043
  "arguments": []
57883
58044
  }
@@ -57893,7 +58054,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57893
58054
  "terminal": {
57894
58055
  "$type": "RuleCall",
57895
58056
  "rule": {
57896
- "$ref": "#/rules@54"
58057
+ "$ref": "#/rules@56"
57897
58058
  },
57898
58059
  "arguments": []
57899
58060
  }
@@ -57909,7 +58070,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57909
58070
  "terminal": {
57910
58071
  "$type": "RuleCall",
57911
58072
  "rule": {
57912
- "$ref": "#/rules@55"
58073
+ "$ref": "#/rules@57"
57913
58074
  },
57914
58075
  "arguments": []
57915
58076
  }
@@ -57925,7 +58086,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57925
58086
  "terminal": {
57926
58087
  "$type": "RuleCall",
57927
58088
  "rule": {
57928
- "$ref": "#/rules@54"
58089
+ "$ref": "#/rules@56"
57929
58090
  },
57930
58091
  "arguments": []
57931
58092
  }
@@ -57980,7 +58141,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57980
58141
  "terminal": {
57981
58142
  "$type": "RuleCall",
57982
58143
  "rule": {
57983
- "$ref": "#/rules@54"
58144
+ "$ref": "#/rules@56"
57984
58145
  },
57985
58146
  "arguments": []
57986
58147
  }
@@ -57992,7 +58153,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
57992
58153
  "terminal": {
57993
58154
  "$type": "RuleCall",
57994
58155
  "rule": {
57995
- "$ref": "#/rules@23"
58156
+ "$ref": "#/rules@25"
57996
58157
  },
57997
58158
  "arguments": []
57998
58159
  },
@@ -58005,7 +58166,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58005
58166
  "terminal": {
58006
58167
  "$type": "RuleCall",
58007
58168
  "rule": {
58008
- "$ref": "#/rules@17"
58169
+ "$ref": "#/rules@19"
58009
58170
  },
58010
58171
  "arguments": []
58011
58172
  },
@@ -58022,7 +58183,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58022
58183
  "terminal": {
58023
58184
  "$type": "RuleCall",
58024
58185
  "rule": {
58025
- "$ref": "#/rules@54"
58186
+ "$ref": "#/rules@56"
58026
58187
  },
58027
58188
  "arguments": []
58028
58189
  }
@@ -58038,7 +58199,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58038
58199
  "terminal": {
58039
58200
  "$type": "RuleCall",
58040
58201
  "rule": {
58041
- "$ref": "#/rules@24"
58202
+ "$ref": "#/rules@26"
58042
58203
  },
58043
58204
  "arguments": []
58044
58205
  }
@@ -58057,7 +58218,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58057
58218
  "terminal": {
58058
58219
  "$type": "RuleCall",
58059
58220
  "rule": {
58060
- "$ref": "#/rules@24"
58221
+ "$ref": "#/rules@26"
58061
58222
  },
58062
58223
  "arguments": []
58063
58224
  }
@@ -58076,7 +58237,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58076
58237
  "terminal": {
58077
58238
  "$type": "RuleCall",
58078
58239
  "rule": {
58079
- "$ref": "#/rules@54"
58240
+ "$ref": "#/rules@56"
58080
58241
  },
58081
58242
  "arguments": []
58082
58243
  }
@@ -58088,7 +58249,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58088
58249
  "terminal": {
58089
58250
  "$type": "RuleCall",
58090
58251
  "rule": {
58091
- "$ref": "#/rules@25"
58252
+ "$ref": "#/rules@27"
58092
58253
  },
58093
58254
  "arguments": []
58094
58255
  },
@@ -58101,7 +58262,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58101
58262
  "terminal": {
58102
58263
  "$type": "RuleCall",
58103
58264
  "rule": {
58104
- "$ref": "#/rules@26"
58265
+ "$ref": "#/rules@28"
58105
58266
  },
58106
58267
  "arguments": []
58107
58268
  },
@@ -58118,7 +58279,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58118
58279
  "terminal": {
58119
58280
  "$type": "RuleCall",
58120
58281
  "rule": {
58121
- "$ref": "#/rules@27"
58282
+ "$ref": "#/rules@29"
58122
58283
  },
58123
58284
  "arguments": []
58124
58285
  }
@@ -58159,7 +58320,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58159
58320
  "terminal": {
58160
58321
  "$type": "RuleCall",
58161
58322
  "rule": {
58162
- "$ref": "#/rules@54"
58323
+ "$ref": "#/rules@56"
58163
58324
  },
58164
58325
  "arguments": []
58165
58326
  }
@@ -58178,7 +58339,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58178
58339
  "terminal": {
58179
58340
  "$type": "RuleCall",
58180
58341
  "rule": {
58181
- "$ref": "#/rules@15"
58342
+ "$ref": "#/rules@17"
58182
58343
  },
58183
58344
  "arguments": []
58184
58345
  }
@@ -58197,7 +58358,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58197
58358
  "terminal": {
58198
58359
  "$type": "RuleCall",
58199
58360
  "rule": {
58200
- "$ref": "#/rules@15"
58361
+ "$ref": "#/rules@17"
58201
58362
  },
58202
58363
  "arguments": []
58203
58364
  }
@@ -58222,7 +58383,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58222
58383
  "terminal": {
58223
58384
  "$type": "RuleCall",
58224
58385
  "rule": {
58225
- "$ref": "#/rules@54"
58386
+ "$ref": "#/rules@56"
58226
58387
  },
58227
58388
  "arguments": []
58228
58389
  }
@@ -58241,7 +58402,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58241
58402
  "terminal": {
58242
58403
  "$type": "RuleCall",
58243
58404
  "rule": {
58244
- "$ref": "#/rules@54"
58405
+ "$ref": "#/rules@56"
58245
58406
  },
58246
58407
  "arguments": []
58247
58408
  }
@@ -58259,32 +58420,23 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58259
58420
  "terminal": {
58260
58421
  "$type": "RuleCall",
58261
58422
  "rule": {
58262
- "$ref": "#/rules@16"
58423
+ "$ref": "#/rules@18"
58263
58424
  },
58264
58425
  "arguments": []
58265
58426
  },
58266
58427
  "cardinality": "*"
58267
58428
  },
58268
58429
  {
58269
- "$type": "Group",
58270
- "elements": [
58271
- {
58272
- "$type": "Keyword",
58273
- "value": "emits"
58430
+ "$type": "Assignment",
58431
+ "feature": "emits",
58432
+ "operator": "=",
58433
+ "terminal": {
58434
+ "$type": "RuleCall",
58435
+ "rule": {
58436
+ "$ref": "#/rules@15"
58274
58437
  },
58275
- {
58276
- "$type": "Assignment",
58277
- "feature": "emits",
58278
- "operator": "=",
58279
- "terminal": {
58280
- "$type": "RuleCall",
58281
- "rule": {
58282
- "$ref": "#/rules@54"
58283
- },
58284
- "arguments": []
58285
- }
58286
- }
58287
- ],
58438
+ "arguments": []
58439
+ },
58288
58440
  "cardinality": "?"
58289
58441
  }
58290
58442
  ]
@@ -58306,7 +58458,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58306
58458
  "terminal": {
58307
58459
  "$type": "RuleCall",
58308
58460
  "rule": {
58309
- "$ref": "#/rules@54"
58461
+ "$ref": "#/rules@56"
58310
58462
  },
58311
58463
  "arguments": []
58312
58464
  }
@@ -58325,7 +58477,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58325
58477
  "terminal": {
58326
58478
  "$type": "RuleCall",
58327
58479
  "rule": {
58328
- "$ref": "#/rules@54"
58480
+ "$ref": "#/rules@56"
58329
58481
  },
58330
58482
  "arguments": []
58331
58483
  }
@@ -58356,7 +58508,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58356
58508
  "terminal": {
58357
58509
  "$type": "RuleCall",
58358
58510
  "rule": {
58359
- "$ref": "#/rules@54"
58511
+ "$ref": "#/rules@56"
58360
58512
  },
58361
58513
  "arguments": []
58362
58514
  }
@@ -58375,7 +58527,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58375
58527
  "terminal": {
58376
58528
  "$type": "RuleCall",
58377
58529
  "rule": {
58378
- "$ref": "#/rules@54"
58530
+ "$ref": "#/rules@56"
58379
58531
  },
58380
58532
  "arguments": []
58381
58533
  }
@@ -58425,7 +58577,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58425
58577
  "terminal": {
58426
58578
  "$type": "RuleCall",
58427
58579
  "rule": {
58428
- "$ref": "#/rules@54"
58580
+ "$ref": "#/rules@56"
58429
58581
  },
58430
58582
  "arguments": []
58431
58583
  }
@@ -58441,7 +58593,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58441
58593
  "terminal": {
58442
58594
  "$type": "RuleCall",
58443
58595
  "rule": {
58444
- "$ref": "#/rules@24"
58596
+ "$ref": "#/rules@26"
58445
58597
  },
58446
58598
  "arguments": []
58447
58599
  }
@@ -58460,7 +58612,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58460
58612
  "terminal": {
58461
58613
  "$type": "RuleCall",
58462
58614
  "rule": {
58463
- "$ref": "#/rules@24"
58615
+ "$ref": "#/rules@26"
58464
58616
  },
58465
58617
  "arguments": []
58466
58618
  }
@@ -58491,7 +58643,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58491
58643
  "terminal": {
58492
58644
  "$type": "RuleCall",
58493
58645
  "rule": {
58494
- "$ref": "#/rules@54"
58646
+ "$ref": "#/rules@56"
58495
58647
  },
58496
58648
  "arguments": []
58497
58649
  }
@@ -58528,7 +58680,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58528
58680
  "terminal": {
58529
58681
  "$type": "RuleCall",
58530
58682
  "rule": {
58531
- "$ref": "#/rules@54"
58683
+ "$ref": "#/rules@56"
58532
58684
  },
58533
58685
  "arguments": []
58534
58686
  }
@@ -58544,7 +58696,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58544
58696
  "terminal": {
58545
58697
  "$type": "RuleCall",
58546
58698
  "rule": {
58547
- "$ref": "#/rules@54"
58699
+ "$ref": "#/rules@56"
58548
58700
  },
58549
58701
  "arguments": []
58550
58702
  }
@@ -58560,7 +58712,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58560
58712
  "terminal": {
58561
58713
  "$type": "RuleCall",
58562
58714
  "rule": {
58563
- "$ref": "#/rules@53"
58715
+ "$ref": "#/rules@55"
58564
58716
  },
58565
58717
  "arguments": []
58566
58718
  }
@@ -58576,7 +58728,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58576
58728
  "terminal": {
58577
58729
  "$type": "RuleCall",
58578
58730
  "rule": {
58579
- "$ref": "#/rules@55"
58731
+ "$ref": "#/rules@57"
58580
58732
  },
58581
58733
  "arguments": []
58582
58734
  }
@@ -58604,7 +58756,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58604
58756
  "terminal": {
58605
58757
  "$type": "RuleCall",
58606
58758
  "rule": {
58607
- "$ref": "#/rules@55"
58759
+ "$ref": "#/rules@57"
58608
58760
  },
58609
58761
  "arguments": []
58610
58762
  }
@@ -58623,7 +58775,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58623
58775
  "terminal": {
58624
58776
  "$type": "RuleCall",
58625
58777
  "rule": {
58626
- "$ref": "#/rules@55"
58778
+ "$ref": "#/rules@57"
58627
58779
  },
58628
58780
  "arguments": []
58629
58781
  }
@@ -58638,7 +58790,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58638
58790
  "terminal": {
58639
58791
  "$type": "RuleCall",
58640
58792
  "rule": {
58641
- "$ref": "#/rules@30"
58793
+ "$ref": "#/rules@32"
58642
58794
  },
58643
58795
  "arguments": []
58644
58796
  },
@@ -58651,7 +58803,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58651
58803
  "terminal": {
58652
58804
  "$type": "RuleCall",
58653
58805
  "rule": {
58654
- "$ref": "#/rules@31"
58806
+ "$ref": "#/rules@33"
58655
58807
  },
58656
58808
  "arguments": []
58657
58809
  },
@@ -58694,7 +58846,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58694
58846
  "terminal": {
58695
58847
  "$type": "RuleCall",
58696
58848
  "rule": {
58697
- "$ref": "#/rules@35"
58849
+ "$ref": "#/rules@37"
58698
58850
  },
58699
58851
  "arguments": []
58700
58852
  }
@@ -58706,7 +58858,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58706
58858
  "terminal": {
58707
58859
  "$type": "RuleCall",
58708
58860
  "rule": {
58709
- "$ref": "#/rules@55"
58861
+ "$ref": "#/rules@57"
58710
58862
  },
58711
58863
  "arguments": []
58712
58864
  }
@@ -58718,7 +58870,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58718
58870
  "terminal": {
58719
58871
  "$type": "RuleCall",
58720
58872
  "rule": {
58721
- "$ref": "#/rules@51"
58873
+ "$ref": "#/rules@53"
58722
58874
  },
58723
58875
  "arguments": []
58724
58876
  },
@@ -58747,7 +58899,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58747
58899
  "terminal": {
58748
58900
  "$type": "RuleCall",
58749
58901
  "rule": {
58750
- "$ref": "#/rules@55"
58902
+ "$ref": "#/rules@57"
58751
58903
  },
58752
58904
  "arguments": []
58753
58905
  }
@@ -58772,7 +58924,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58772
58924
  "terminal": {
58773
58925
  "$type": "RuleCall",
58774
58926
  "rule": {
58775
- "$ref": "#/rules@34"
58927
+ "$ref": "#/rules@36"
58776
58928
  },
58777
58929
  "arguments": []
58778
58930
  }
@@ -58784,7 +58936,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58784
58936
  "terminal": {
58785
58937
  "$type": "RuleCall",
58786
58938
  "rule": {
58787
- "$ref": "#/rules@33"
58939
+ "$ref": "#/rules@35"
58788
58940
  },
58789
58941
  "arguments": []
58790
58942
  }
@@ -58796,7 +58948,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58796
58948
  "terminal": {
58797
58949
  "$type": "RuleCall",
58798
58950
  "rule": {
58799
- "$ref": "#/rules@32"
58951
+ "$ref": "#/rules@34"
58800
58952
  },
58801
58953
  "arguments": []
58802
58954
  }
@@ -58830,7 +58982,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58830
58982
  "terminal": {
58831
58983
  "$type": "RuleCall",
58832
58984
  "rule": {
58833
- "$ref": "#/rules@35"
58985
+ "$ref": "#/rules@37"
58834
58986
  },
58835
58987
  "arguments": []
58836
58988
  }
@@ -58849,7 +59001,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58849
59001
  "terminal": {
58850
59002
  "$type": "RuleCall",
58851
59003
  "rule": {
58852
- "$ref": "#/rules@55"
59004
+ "$ref": "#/rules@57"
58853
59005
  },
58854
59006
  "arguments": []
58855
59007
  }
@@ -58877,7 +59029,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58877
59029
  "terminal": {
58878
59030
  "$type": "RuleCall",
58879
59031
  "rule": {
58880
- "$ref": "#/rules@54"
59032
+ "$ref": "#/rules@56"
58881
59033
  },
58882
59034
  "arguments": []
58883
59035
  }
@@ -58896,7 +59048,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58896
59048
  "terminal": {
58897
59049
  "$type": "RuleCall",
58898
59050
  "rule": {
58899
- "$ref": "#/rules@35"
59051
+ "$ref": "#/rules@37"
58900
59052
  },
58901
59053
  "arguments": []
58902
59054
  }
@@ -58915,7 +59067,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58915
59067
  "terminal": {
58916
59068
  "$type": "RuleCall",
58917
59069
  "rule": {
58918
- "$ref": "#/rules@34"
59070
+ "$ref": "#/rules@36"
58919
59071
  },
58920
59072
  "arguments": []
58921
59073
  },
@@ -58940,7 +59092,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58940
59092
  "terminal": {
58941
59093
  "$type": "RuleCall",
58942
59094
  "rule": {
58943
- "$ref": "#/rules@35"
59095
+ "$ref": "#/rules@37"
58944
59096
  },
58945
59097
  "arguments": []
58946
59098
  }
@@ -58956,7 +59108,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58956
59108
  "terminal": {
58957
59109
  "$type": "RuleCall",
58958
59110
  "rule": {
58959
- "$ref": "#/rules@54"
59111
+ "$ref": "#/rules@56"
58960
59112
  },
58961
59113
  "arguments": []
58962
59114
  }
@@ -58968,7 +59120,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58968
59120
  "terminal": {
58969
59121
  "$type": "RuleCall",
58970
59122
  "rule": {
58971
- "$ref": "#/rules@36"
59123
+ "$ref": "#/rules@38"
58972
59124
  },
58973
59125
  "arguments": []
58974
59126
  },
@@ -58981,7 +59133,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
58981
59133
  "terminal": {
58982
59134
  "$type": "RuleCall",
58983
59135
  "rule": {
58984
- "$ref": "#/rules@37"
59136
+ "$ref": "#/rules@39"
58985
59137
  },
58986
59138
  "arguments": []
58987
59139
  },
@@ -59001,7 +59153,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
59001
59153
  "terminal": {
59002
59154
  "$type": "RuleCall",
59003
59155
  "rule": {
59004
- "$ref": "#/rules@54"
59156
+ "$ref": "#/rules@56"
59005
59157
  },
59006
59158
  "arguments": []
59007
59159
  }
@@ -59016,7 +59168,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
59016
59168
  "terminal": {
59017
59169
  "$type": "RuleCall",
59018
59170
  "rule": {
59019
- "$ref": "#/rules@40"
59171
+ "$ref": "#/rules@42"
59020
59172
  },
59021
59173
  "arguments": []
59022
59174
  },
@@ -59029,7 +59181,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
59029
59181
  "terminal": {
59030
59182
  "$type": "RuleCall",
59031
59183
  "rule": {
59032
- "$ref": "#/rules@39"
59184
+ "$ref": "#/rules@41"
59033
59185
  },
59034
59186
  "arguments": []
59035
59187
  },
@@ -59051,7 +59203,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
59051
59203
  {
59052
59204
  "$type": "RuleCall",
59053
59205
  "rule": {
59054
- "$ref": "#/rules@54"
59206
+ "$ref": "#/rules@56"
59055
59207
  },
59056
59208
  "arguments": []
59057
59209
  },
@@ -59066,6 +59218,10 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
59066
59218
  {
59067
59219
  "$type": "Keyword",
59068
59220
  "value": "note"
59221
+ },
59222
+ {
59223
+ "$type": "Keyword",
59224
+ "value": "outcome"
59069
59225
  }
59070
59226
  ]
59071
59227
  },
@@ -59097,7 +59253,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
59097
59253
  "terminal": {
59098
59254
  "$type": "RuleCall",
59099
59255
  "rule": {
59100
- "$ref": "#/rules@56"
59256
+ "$ref": "#/rules@58"
59101
59257
  },
59102
59258
  "arguments": []
59103
59259
  }
@@ -59109,7 +59265,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
59109
59265
  "terminal": {
59110
59266
  "$type": "RuleCall",
59111
59267
  "rule": {
59112
- "$ref": "#/rules@54"
59268
+ "$ref": "#/rules@56"
59113
59269
  },
59114
59270
  "arguments": []
59115
59271
  }
@@ -59143,7 +59299,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
59143
59299
  "terminal": {
59144
59300
  "$type": "RuleCall",
59145
59301
  "rule": {
59146
- "$ref": "#/rules@38"
59302
+ "$ref": "#/rules@40"
59147
59303
  },
59148
59304
  "arguments": []
59149
59305
  }
@@ -59172,6 +59328,10 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
59172
59328
  {
59173
59329
  "$type": "Keyword",
59174
59330
  "value": "terminal"
59331
+ },
59332
+ {
59333
+ "$type": "Keyword",
59334
+ "value": "outcome"
59175
59335
  }
59176
59336
  ]
59177
59337
  },
@@ -59188,21 +59348,21 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
59188
59348
  {
59189
59349
  "$type": "RuleCall",
59190
59350
  "rule": {
59191
- "$ref": "#/rules@42"
59351
+ "$ref": "#/rules@44"
59192
59352
  },
59193
59353
  "arguments": []
59194
59354
  },
59195
59355
  {
59196
59356
  "$type": "RuleCall",
59197
59357
  "rule": {
59198
- "$ref": "#/rules@43"
59358
+ "$ref": "#/rules@45"
59199
59359
  },
59200
59360
  "arguments": []
59201
59361
  },
59202
59362
  {
59203
59363
  "$type": "RuleCall",
59204
59364
  "rule": {
59205
- "$ref": "#/rules@44"
59365
+ "$ref": "#/rules@46"
59206
59366
  },
59207
59367
  "arguments": []
59208
59368
  }
@@ -59229,7 +59389,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
59229
59389
  "terminal": {
59230
59390
  "$type": "RuleCall",
59231
59391
  "rule": {
59232
- "$ref": "#/rules@35"
59392
+ "$ref": "#/rules@37"
59233
59393
  },
59234
59394
  "arguments": []
59235
59395
  }
@@ -59245,7 +59405,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
59245
59405
  "terminal": {
59246
59406
  "$type": "RuleCall",
59247
59407
  "rule": {
59248
- "$ref": "#/rules@53"
59408
+ "$ref": "#/rules@55"
59249
59409
  },
59250
59410
  "arguments": []
59251
59411
  }
@@ -59261,7 +59421,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
59261
59421
  "terminal": {
59262
59422
  "$type": "RuleCall",
59263
59423
  "rule": {
59264
- "$ref": "#/rules@41"
59424
+ "$ref": "#/rules@43"
59265
59425
  },
59266
59426
  "arguments": []
59267
59427
  },
@@ -59286,7 +59446,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
59286
59446
  "terminal": {
59287
59447
  "$type": "RuleCall",
59288
59448
  "rule": {
59289
- "$ref": "#/rules@54"
59449
+ "$ref": "#/rules@56"
59290
59450
  },
59291
59451
  "arguments": []
59292
59452
  }
@@ -59302,7 +59462,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
59302
59462
  "terminal": {
59303
59463
  "$type": "RuleCall",
59304
59464
  "rule": {
59305
- "$ref": "#/rules@49"
59465
+ "$ref": "#/rules@51"
59306
59466
  },
59307
59467
  "arguments": []
59308
59468
  }
@@ -59340,7 +59500,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
59340
59500
  "terminal": {
59341
59501
  "$type": "RuleCall",
59342
59502
  "rule": {
59343
- "$ref": "#/rules@54"
59503
+ "$ref": "#/rules@56"
59344
59504
  },
59345
59505
  "arguments": []
59346
59506
  }
@@ -59368,7 +59528,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
59368
59528
  "terminal": {
59369
59529
  "$type": "RuleCall",
59370
59530
  "rule": {
59371
- "$ref": "#/rules@54"
59531
+ "$ref": "#/rules@56"
59372
59532
  },
59373
59533
  "arguments": []
59374
59534
  }
@@ -59396,7 +59556,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
59396
59556
  "terminal": {
59397
59557
  "$type": "RuleCall",
59398
59558
  "rule": {
59399
- "$ref": "#/rules@55"
59559
+ "$ref": "#/rules@57"
59400
59560
  },
59401
59561
  "arguments": []
59402
59562
  }
@@ -59420,7 +59580,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
59420
59580
  "terminal": {
59421
59581
  "$type": "RuleCall",
59422
59582
  "rule": {
59423
- "$ref": "#/rules@48"
59583
+ "$ref": "#/rules@50"
59424
59584
  },
59425
59585
  "arguments": []
59426
59586
  }
@@ -59436,7 +59596,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
59436
59596
  "terminal": {
59437
59597
  "$type": "RuleCall",
59438
59598
  "rule": {
59439
- "$ref": "#/rules@49"
59599
+ "$ref": "#/rules@51"
59440
59600
  },
59441
59601
  "arguments": []
59442
59602
  }
@@ -59448,7 +59608,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
59448
59608
  "terminal": {
59449
59609
  "$type": "RuleCall",
59450
59610
  "rule": {
59451
- "$ref": "#/rules@46"
59611
+ "$ref": "#/rules@48"
59452
59612
  },
59453
59613
  "arguments": []
59454
59614
  },
@@ -59481,7 +59641,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
59481
59641
  "terminal": {
59482
59642
  "$type": "RuleCall",
59483
59643
  "rule": {
59484
- "$ref": "#/rules@55"
59644
+ "$ref": "#/rules@57"
59485
59645
  },
59486
59646
  "arguments": []
59487
59647
  }
@@ -59497,7 +59657,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
59497
59657
  "terminal": {
59498
59658
  "$type": "RuleCall",
59499
59659
  "rule": {
59500
- "$ref": "#/rules@55"
59660
+ "$ref": "#/rules@57"
59501
59661
  },
59502
59662
  "arguments": []
59503
59663
  }
@@ -59522,7 +59682,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
59522
59682
  {
59523
59683
  "$type": "RuleCall",
59524
59684
  "rule": {
59525
- "$ref": "#/rules@48"
59685
+ "$ref": "#/rules@50"
59526
59686
  },
59527
59687
  "arguments": []
59528
59688
  },
@@ -59558,7 +59718,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
59558
59718
  {
59559
59719
  "$type": "RuleCall",
59560
59720
  "rule": {
59561
- "$ref": "#/rules@54"
59721
+ "$ref": "#/rules@56"
59562
59722
  },
59563
59723
  "arguments": []
59564
59724
  },
@@ -59613,6 +59773,10 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
59613
59773
  {
59614
59774
  "$type": "Keyword",
59615
59775
  "value": "note"
59776
+ },
59777
+ {
59778
+ "$type": "Keyword",
59779
+ "value": "outcome"
59616
59780
  }
59617
59781
  ]
59618
59782
  },
@@ -59633,7 +59797,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
59633
59797
  "terminal": {
59634
59798
  "$type": "RuleCall",
59635
59799
  "rule": {
59636
- "$ref": "#/rules@50"
59800
+ "$ref": "#/rules@52"
59637
59801
  },
59638
59802
  "arguments": []
59639
59803
  }
@@ -59692,7 +59856,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
59692
59856
  {
59693
59857
  "$type": "RuleCall",
59694
59858
  "rule": {
59695
- "$ref": "#/rules@54"
59859
+ "$ref": "#/rules@56"
59696
59860
  },
59697
59861
  "arguments": []
59698
59862
  }
@@ -59719,7 +59883,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
59719
59883
  "terminal": {
59720
59884
  "$type": "RuleCall",
59721
59885
  "rule": {
59722
- "$ref": "#/rules@52"
59886
+ "$ref": "#/rules@54"
59723
59887
  },
59724
59888
  "arguments": []
59725
59889
  }
@@ -59805,7 +59969,7 @@ var MomentGrammar = () => loadedMomentGrammar ?? (loadedMomentGrammar = loadGram
59805
59969
  {
59806
59970
  "$type": "RuleCall",
59807
59971
  "rule": {
59808
- "$ref": "#/rules@54"
59972
+ "$ref": "#/rules@56"
59809
59973
  },
59810
59974
  "arguments": []
59811
59975
  }
@@ -60139,7 +60303,7 @@ var MomentValidator = class {
60139
60303
  // those are alternative branch arms, not continuations.
60140
60304
  // =========================================================================
60141
60305
  checkTerminalIsLast(node, accept) {
60142
- if (node.modifier?.type !== "terminal")
60306
+ if (!endsFlow(node))
60143
60307
  return;
60144
60308
  const container = node.$container;
60145
60309
  const siblings = "nodes" in container ? container.nodes : [];
@@ -60610,6 +60774,10 @@ var MomentValidator = class {
60610
60774
  return false;
60611
60775
  }
60612
60776
  };
60777
+ function endsFlow(node) {
60778
+ const type = node.modifier?.type;
60779
+ return type === "terminal" || type === "outcome";
60780
+ }
60613
60781
 
60614
60782
  // ../core/dist/moment-module.js
60615
60783
  var MomentModule = {
@@ -60703,10 +60871,10 @@ function checkExternals(ir) {
60703
60871
  }
60704
60872
  return out;
60705
60873
  }
60706
- var v38 = (ctx, known) => ctx.commands.filter((c) => c.emitsEvent && !known.events.has(c.emitsEvent)).map((c) => ({
60874
+ var v38 = (ctx, known) => ctx.commands.flatMap((c) => emittedEvents(c).filter((e) => !known.events.has(e)).map((e) => ({
60707
60875
  ruleId: "V38",
60708
- message: `Command '${c.name}' emits '${c.emitsEvent}', which is no declared event.`
60709
- }));
60876
+ message: `Command '${c.name}' emits '${e}', which is no declared event.`
60877
+ })));
60710
60878
  function v39(ir) {
60711
60879
  return ir.flows.flatMap((flow) => {
60712
60880
  const placed = new Set(flow.moments.flatMap((m) => [
@@ -60732,6 +60900,167 @@ function validateModelCompleteness(ir) {
60732
60900
  ];
60733
60901
  }
60734
60902
 
60903
+ // ../core/dist/validation/multi-event.js
60904
+ function ownedCommands(ctx) {
60905
+ return [
60906
+ ...ctx.aggregates.flatMap((aggregate) => (aggregate.commands ?? []).map((command2) => ({ command: command2, aggregate }))),
60907
+ ...ctx.sagas.flatMap((saga) => (saga.commands ?? []).map((command2) => ({ command: command2, saga })))
60908
+ ];
60909
+ }
60910
+ function declaredStates({ aggregate, saga }) {
60911
+ if (aggregate !== void 0) {
60912
+ const s = aggregate.states;
60913
+ return new Set(s === void 0 ? [] : [
60914
+ ...s.initials,
60915
+ ...s.initial ? [s.initial] : [],
60916
+ ...s.transitions.flatMap((t) => [t.from, t.to])
60917
+ ]);
60918
+ }
60919
+ return new Set(saga?.states ?? []);
60920
+ }
60921
+ var textOf = (o) => o.events.join(", ");
60922
+ function v44(ctx) {
60923
+ const known = new Set(ctx.events.map((e) => e.name));
60924
+ return ctx.aggregates.flatMap((agg) => (agg.commands ?? []).filter((c) => emittedEvents(c).length > 1).flatMap((c) => emittedEvents(c).filter((e) => known.has(e) && !(agg.events ?? []).some((own) => own.name === e)).map((e) => ({
60925
+ ruleId: "V44",
60926
+ message: `Command '${c.name}' emits '${e}', which aggregate '${agg.name}' does not declare; a command that records more than one event records only its own aggregate's events.`
60927
+ }))));
60928
+ }
60929
+ function v45(ctx) {
60930
+ return ownedCommands(ctx).flatMap(({ command: command2 }) => emitOutcomes(command2).flatMap((o) => [...new Set(o.events.filter((e, i) => o.events.indexOf(e) !== i))].map((e) => ({
60931
+ ruleId: "V45",
60932
+ message: `Command '${command2.name}' lists '${e}' twice in one outcome.`
60933
+ }))));
60934
+ }
60935
+ var v46Error = (message) => ({ ruleId: "V46", message, severity: "error" });
60936
+ function undeclaredGuards(owned, outcomes) {
60937
+ const declared = declaredStates(owned);
60938
+ const ownerText = owned.aggregate ? `aggregate '${owned.aggregate.name}'` : `orchestration '${owned.saga?.name ?? ""}'`;
60939
+ return outcomes.filter((o) => o.whenState !== void 0 && !declared.has(o.whenState)).map((o) => v46Error(`Command '${owned.command.name}' records '${textOf(o)}' when '${o.whenState ?? ""}', which is no state ${ownerText} declares.`));
60940
+ }
60941
+ function sharedGuards(name, guarded) {
60942
+ const states = guarded.map((o) => o.whenState ?? "");
60943
+ return [...new Set(states.filter((s, i) => states.indexOf(s) !== i))].map((s) => v46Error(`Command '${name}' has two outcomes recorded when '${s}'.`));
60944
+ }
60945
+ function guardCoverage(name, outcomes, guarded) {
60946
+ if (guarded === 0)
60947
+ return [
60948
+ {
60949
+ ruleId: "V46",
60950
+ severity: "warning",
60951
+ message: `The choice between the outcomes of '${name}' is not declared; name the state that decides each with 'when <State>'.`
60952
+ }
60953
+ ];
60954
+ return guarded === outcomes.length ? [] : [
60955
+ v46Error(`Command '${name}' guards ${guarded} of its ${outcomes.length} outcomes with 'when'; guard every outcome or none.`)
60956
+ ];
60957
+ }
60958
+ function v46(ctx) {
60959
+ return ownedCommands(ctx).flatMap((owned) => {
60960
+ const { name } = owned.command;
60961
+ const outcomes = emitOutcomes(owned.command);
60962
+ const guarded = outcomes.filter((o) => o.whenState !== void 0);
60963
+ return [
60964
+ ...undeclaredGuards(owned, outcomes),
60965
+ ...outcomes.length < 2 ? [] : [...sharedGuards(name, guarded), ...guardCoverage(name, outcomes, guarded.length)]
60966
+ ];
60967
+ });
60968
+ }
60969
+ function momentPaths(moment) {
60970
+ const main = moment.contextEntries;
60971
+ const branches = moment.branches ?? [];
60972
+ if (moment.sequence === void 0)
60973
+ return [main, ...branches.map((b) => [...main, ...b.entries])];
60974
+ const paths = [main];
60975
+ for (const item of moment.sequence) {
60976
+ if (item.kind !== "branch")
60977
+ continue;
60978
+ const before = moment.sequence.slice(0, moment.sequence.indexOf(item)).flatMap((i) => i.kind === "entry" ? [main[i.index]] : []);
60979
+ paths.push([...before, ...branches[item.index]?.entries ?? []]);
60980
+ }
60981
+ return paths;
60982
+ }
60983
+ function momentPlacements(moment, commandOf) {
60984
+ return momentPaths(moment).flatMap((path) => path.flatMap((entry, i) => {
60985
+ const command2 = entry.nodeKind === "command" ? commandOf(entry.nodeName) : void 0;
60986
+ if (command2 === void 0)
60987
+ return [];
60988
+ const emitted = new Set(emittedEvents(command2));
60989
+ const next = path.findIndex((e, j) => j > i && e.nodeKind === "command" && e.contextId === entry.contextId);
60990
+ const events = path.slice(i + 1, next === -1 ? void 0 : next).filter((e) => e.nodeKind === "event" && emitted.has(e.nodeName));
60991
+ return [{ command: command2, commandEntry: entry, events }];
60992
+ }));
60993
+ }
60994
+ function placementsIn(flow, moment, commands) {
60995
+ return momentPlacements(moment, (name) => commands.get(name)).flatMap((p) => {
60996
+ const placed = [...new Set(p.events.map((e) => e.nodeName))];
60997
+ return placed.length === 0 ? [] : [{ flow, moment: moment.name, command: p.command, placed }];
60998
+ });
60999
+ }
61000
+ function placements(ir) {
61001
+ const commands = /* @__PURE__ */ new Map();
61002
+ for (const ctx of ir.contexts)
61003
+ for (const { command: command2 } of ownedCommands(ctx))
61004
+ if (emittedEvents(command2).length > 1 && !commands.has(command2.name))
61005
+ commands.set(command2.name, command2);
61006
+ if (commands.size === 0)
61007
+ return [];
61008
+ const seen = /* @__PURE__ */ new Set();
61009
+ return (ir.flows ?? []).flatMap((flow) => flow.moments.flatMap((m) => placementsIn(flow.name, m, commands))).filter((p) => {
61010
+ const key = `${p.flow}\0${p.moment}\0${p.command.name}\0${p.placed.join(",")}`;
61011
+ return seen.has(key) ? false : (seen.add(key), true);
61012
+ });
61013
+ }
61014
+ function v47(ir, placed) {
61015
+ const declared = new Set(ir.contexts.flatMap((c) => [
61016
+ ...c.events.map((e) => e.name),
61017
+ ...c.sagas.flatMap((s) => (s.events ?? []).map((e) => e.name))
61018
+ ]));
61019
+ return placed.flatMap((p) => {
61020
+ const outcomes = emitOutcomes(p.command);
61021
+ const where = `Flow '${p.flow}' moment '${p.moment}'`;
61022
+ const i = matchEmitOutcome(outcomes, p.placed);
61023
+ if (i === -1)
61024
+ return [
61025
+ {
61026
+ ruleId: "V47",
61027
+ message: `${where}: ${p.placed.map((e) => `'${e}'`).join(", ")} follow one placement of '${p.command.name}' but no single outcome of it records them together; its outcomes are alternatives.`
61028
+ }
61029
+ ];
61030
+ const missing = outcomes[i].events.filter((e) => !p.placed.includes(e) && declared.has(e));
61031
+ return missing.length === 0 ? [] : [
61032
+ {
61033
+ ruleId: "V47",
61034
+ severity: "warning",
61035
+ message: `${where}: outcome '${textOf(outcomes[i])}' of '${p.command.name}' records ${missing.map((e) => `'${e}'`).join(", ")} together with ${p.placed.map((e) => `'${e}'`).join(", ")}; the flow places ${p.placed.map((e) => `'${e}'`).join(", ")} only.`
61036
+ }
61037
+ ];
61038
+ });
61039
+ }
61040
+ function v48(ir, placed) {
61041
+ const reached = /* @__PURE__ */ new Map();
61042
+ for (const p of placed) {
61043
+ const i = matchEmitOutcome(emitOutcomes(p.command), p.placed);
61044
+ if (i !== -1)
61045
+ reached.set(p.command, (reached.get(p.command) ?? /* @__PURE__ */ new Set()).add(i));
61046
+ }
61047
+ return ir.contexts.flatMap((ctx) => ownedCommands(ctx).filter(({ command: command2 }) => emitOutcomes(command2).length > 1 && emittedEvents(command2).length > 1).flatMap(({ command: command2 }) => emitOutcomes(command2).flatMap((o, i) => reached.get(command2)?.has(i) ? [] : [
61048
+ {
61049
+ ruleId: "V48",
61050
+ severity: "warning",
61051
+ message: `Outcome '${textOf(o)}' of command '${command2.name}' is placed by no flow.`
61052
+ }
61053
+ ])));
61054
+ }
61055
+ function validateMultiEvent(ir, options = {}) {
61056
+ const placed = placements(ir);
61057
+ return [
61058
+ ...ir.contexts.flatMap((ctx) => [...v44(ctx), ...v45(ctx), ...v46(ctx)]),
61059
+ ...v47(ir, placed),
61060
+ ...options.merged ? v48(ir, placed) : []
61061
+ ];
61062
+ }
61063
+
60735
61064
  // ../core/dist/validation/palette-conformance.js
60736
61065
  function namesOf2(ir) {
60737
61066
  const contexts = ir.contexts;
@@ -60778,10 +61107,10 @@ function orchestrationFindings(saga, known) {
60778
61107
  const ownEvents = new Set((saga.events ?? []).map((e) => e.name));
60779
61108
  const compensations = saga.compensations ?? [];
60780
61109
  return [
60781
- ...saga.commands.filter((c) => c.emitsEvent !== void 0 && !ownEvents.has(c.emitsEvent)).map((c) => ({
61110
+ ...saga.commands.flatMap((c) => emittedEvents(c).filter((e) => !ownEvents.has(e)).map((e) => ({
60782
61111
  ruleId: "V31",
60783
- message: `Orchestration '${saga.name}' command '${c.name}' emits '${c.emitsEvent ?? ""}', which the orchestration does not declare; it emits only its own events.`
60784
- })),
61112
+ message: `Orchestration '${saga.name}' command '${c.name}' emits '${e}', which the orchestration does not declare; it emits only its own events.`
61113
+ }))),
60785
61114
  ...own.has(saga.trigger) ? [] : [
60786
61115
  {
60787
61116
  ruleId: "V32",
@@ -60970,7 +61299,7 @@ function v43(ir) {
60970
61299
  }));
60971
61300
  });
60972
61301
  }
60973
- function validatePaletteConformance(ir) {
61302
+ function validatePaletteConformance(ir, options = {}) {
60974
61303
  const known = namesOf2(ir);
60975
61304
  const commands = allCommands(ir);
60976
61305
  return [
@@ -60984,6 +61313,7 @@ function validatePaletteConformance(ir) {
60984
61313
  ...v41Declarations(commands),
60985
61314
  ...v41v42Placements(ir, commands),
60986
61315
  ...v43(ir),
61316
+ ...validateMultiEvent(ir, options),
60987
61317
  ...(ir.externals ?? []).flatMap((e) => gatewayFindings(`external '${e.name}'`, e.gateways ?? [], known))
60988
61318
  ];
60989
61319
  }
@@ -61208,6 +61538,15 @@ function transformStates(decls) {
61208
61538
  transitions: decls.filter((d) => !d.initial).map((d) => ({ from: d.from ?? "", to: d.to ?? "", command: d.command ?? "" }))
61209
61539
  };
61210
61540
  }
61541
+ function transformEmits(clause) {
61542
+ const outcomes = clause.outcomes.map((o) => ({
61543
+ events: [...o.events],
61544
+ ...o.state === void 0 ? {} : { whenState: o.state }
61545
+ }));
61546
+ const first2 = outcomes[0]?.events[0] ?? "";
61547
+ const plain = outcomes.length === 1 && outcomes[0].events.length === 1 && !outcomes[0].whenState;
61548
+ return plain ? { emitsEvent: first2 } : { emitsEvent: first2, outcomes };
61549
+ }
61211
61550
  function transformCommand(cmd, annotations) {
61212
61551
  return {
61213
61552
  id: `cmd-${cmd.name}`,
@@ -61216,7 +61555,7 @@ function transformCommand(cmd, annotations) {
61216
61555
  inputs: cmd.inputs.map(transformFieldDeclaration),
61217
61556
  ...cmd.causes.length > 0 ? { causes: [...cmd.causes] } : {},
61218
61557
  preconditions: cmd.preconditions.map(transformPrecondition),
61219
- emitsEvent: cmd.emits
61558
+ ...transformEmits(cmd.emits)
61220
61559
  };
61221
61560
  }
61222
61561
  function transformPrecondition(pre) {
@@ -61298,7 +61637,7 @@ function transformOrchestrationCommand(cmd) {
61298
61637
  inputs: cmd.inputs.map(transformFieldDeclaration),
61299
61638
  ...cmd.causes.length > 0 ? { causes: [...cmd.causes] } : {},
61300
61639
  preconditions: cmd.preconditions.map(transformPrecondition),
61301
- ...cmd.emits ? { emitsEvent: cmd.emits } : {}
61640
+ ...cmd.emits ? transformEmits(cmd.emits) : {}
61302
61641
  };
61303
61642
  }
61304
61643
  function transformCompensation(c) {
@@ -61455,13 +61794,18 @@ function transformNodeToEntry(node, laneContextMap, nodeKindMap) {
61455
61794
  if (node.cause !== void 0) {
61456
61795
  entry.cause = node.cause;
61457
61796
  }
61458
- const modifierType = node.modifier?.type;
61797
+ applyModifier(entry, node.modifier?.type);
61798
+ return entry;
61799
+ }
61800
+ function applyModifier(entry, modifierType) {
61459
61801
  if (modifierType === "optional") {
61460
61802
  entry.optional = true;
61461
61803
  } else if (modifierType === "terminal") {
61462
61804
  entry.terminal = true;
61805
+ } else if (modifierType === "outcome") {
61806
+ entry.terminal = true;
61807
+ entry.exit = "outcome";
61463
61808
  }
61464
- return entry;
61465
61809
  }
61466
61810
  function extractConnections(flow, laneContextMap) {
61467
61811
  const connections = [];
@@ -63875,7 +64219,7 @@ function validateCrossFileReferences(ir) {
63875
64219
  }
63876
64220
 
63877
64221
  // ../core/dist/project/project-loader.js
63878
- var isCompletenessRule = (d) => /^V(2[2-9]|3[0-9]|4[0-3])$/.test(d.ruleId ?? "");
64222
+ var isCompletenessRule = (d) => /^V(2[2-9]|3[0-9]|4[0-8])$/.test(d.ruleId ?? "");
63879
64223
  var ProjectLoader = class {
63880
64224
  parser;
63881
64225
  constructor(parser) {
@@ -63895,6 +64239,7 @@ var ProjectLoader = class {
63895
64239
  const sortedPaths = [...filePaths].sort();
63896
64240
  const allDiagnostics = [];
63897
64241
  const successfulIrs = [];
64242
+ const failedDiagnostics = /* @__PURE__ */ new Set();
63898
64243
  let filesErrored = 0;
63899
64244
  for (const filePath of sortedPaths) {
63900
64245
  const parseResult = await this.parseFile(filePath);
@@ -63903,6 +64248,7 @@ var ProjectLoader = class {
63903
64248
  successfulIrs.push(parseResult.ir);
63904
64249
  } else {
63905
64250
  filesErrored++;
64251
+ parseResult.diagnostics.forEach((d) => failedDiagnostics.add(d));
63906
64252
  }
63907
64253
  }
63908
64254
  const merged = mergeIrs(successfulIrs, metadataOverride);
@@ -63912,12 +64258,12 @@ var ProjectLoader = class {
63912
64258
  };
63913
64259
  allDiagnostics.push(...mergeResult.diagnostics);
63914
64260
  const validationResult = validateCrossFileReferences(mergeResult.ir);
63915
- const perFile = allDiagnostics.filter((d) => !isCompletenessRule(d));
64261
+ const perFile = allDiagnostics.filter((d) => failedDiagnostics.has(d) || !isCompletenessRule(d));
63916
64262
  allDiagnostics.length = 0;
63917
64263
  allDiagnostics.push(...perFile, ...validationResult.diagnostics, ...validateModelCompleteness(mergeResult.ir).map((d) => ({
63918
64264
  severity: "error",
63919
64265
  ...d
63920
- })), ...validatePaletteConformance(mergeResult.ir).map((d) => ({
64266
+ })), ...validatePaletteConformance(mergeResult.ir, { merged: true }).map((d) => ({
63921
64267
  severity: "error",
63922
64268
  ...d
63923
64269
  })));
@@ -64449,6 +64795,60 @@ function isUsableSequence(seq, entryCount, branchCount) {
64449
64795
  return true;
64450
64796
  }
64451
64797
 
64798
+ // ../derive/dist/engine/node-ids.js
64799
+ var occurrences = /* @__PURE__ */ new WeakMap();
64800
+ function occurrencesIn(moment, laneOf) {
64801
+ const known = occurrences.get(moment);
64802
+ if (known)
64803
+ return known;
64804
+ const seen = /* @__PURE__ */ new Map();
64805
+ const result = /* @__PURE__ */ new Map();
64806
+ const visit = (entry, scope) => {
64807
+ const key = `${laneOf(entry)}\0${entry.nodeName}\0${scope}`;
64808
+ const n = (seen.get(key) ?? 0) + 1;
64809
+ seen.set(key, n);
64810
+ result.set(entry, n);
64811
+ };
64812
+ for (const child of orderedMomentChildren(moment, "entries-first")) {
64813
+ if (child.kind === "entry")
64814
+ visit(child.entry, "main");
64815
+ else
64816
+ for (const e of child.branch.entries)
64817
+ visit(e, `br${child.branchIndex}`);
64818
+ }
64819
+ occurrences.set(moment, result);
64820
+ return result;
64821
+ }
64822
+ function nodeId(moment, entry, laneOf, scope) {
64823
+ const n = occurrencesIn(moment, laneOf).get(entry) ?? 1;
64824
+ return `${moment.id}::${laneOf(entry)}::${entry.nodeName}::${scope}${n > 1 ? `#${n}` : ""}`;
64825
+ }
64826
+
64827
+ // ../derive/dist/engine/multi-event-placement.js
64828
+ function multiEventPlacements(steps, commandOf) {
64829
+ return steps.flatMap((step, j) => {
64830
+ const command2 = commandOf(step);
64831
+ if (command2 === void 0 || emittedEvents(command2).length < 2)
64832
+ return [];
64833
+ const emitted = new Set(emittedEvents(command2));
64834
+ const events = [];
64835
+ for (let k = j + 1; k < steps.length; k++) {
64836
+ const next = steps[k];
64837
+ if (next.momentId !== step.momentId)
64838
+ break;
64839
+ if (commandOf(next) !== void 0) {
64840
+ if (next.contextId === step.contextId)
64841
+ break;
64842
+ } else if (emitted.has(next.nodeName))
64843
+ events.push(k);
64844
+ }
64845
+ const outcomes = emitOutcomes(command2);
64846
+ const i = matchEmitOutcome(outcomes, events.map((k) => steps[k].nodeName));
64847
+ const whenState = i === -1 ? void 0 : outcomes[i].whenState;
64848
+ return [{ command: j, events, ...whenState === void 0 ? {} : { whenState } }];
64849
+ });
64850
+ }
64851
+
64452
64852
  // ../derive/dist/engine/simulation-scenario-generator.js
64453
64853
  function resolveNodeKind(nodeName, contextId, contextMap, declaredKind) {
64454
64854
  const ctx = contextMap.get(contextId);
@@ -64502,7 +64902,7 @@ function generateSimulationScenario(ir, flow, options) {
64502
64902
  kind: resolveScenarioKind(walk.reachedBranches),
64503
64903
  description: flow.description ?? `Full lifecycle flow: ${flow.name}`,
64504
64904
  given: `A ${(flow.moments[0]?.name ?? "").toLowerCase()} scenario is initiated`,
64505
- when: buildWhenClause(flow, nodes),
64905
+ when: buildWhenClause(flow, nodes, contextMap),
64506
64906
  then: buildThenClause(flow, nodes, contextNames),
64507
64907
  expectedPath: nodes.map((n) => n.nodeId),
64508
64908
  activeBranches,
@@ -64555,14 +64955,16 @@ function resolveScenarioLabel(flow, reachedBranches) {
64555
64955
  if (deviations.length === 0)
64556
64956
  return `Happy Path: ${flow.name}`;
64557
64957
  const bracket = deviations.map((b) => b.condition).join(", ");
64558
- const hasTerminalArm = deviations.some((b) => b.armHasTerminal);
64559
- return hasTerminalArm ? `Failure Path: ${flow.name} [${bracket}]` : `Variant: ${flow.name} [${bracket}]`;
64958
+ return endsAtFailureExit(deviations) ? `Failure Path: ${flow.name} [${bracket}]` : `Variant: ${flow.name} [${bracket}]`;
64560
64959
  }
64561
64960
  function resolveScenarioKind(reachedBranches) {
64562
64961
  const deviations = reachedBranches.filter((b) => !b.isFirstArm);
64563
64962
  if (deviations.length === 0)
64564
64963
  return "happy";
64565
- return deviations.some((b) => b.armHasTerminal) ? "failure" : "variant";
64964
+ return endsAtFailureExit(deviations) ? "failure" : "variant";
64965
+ }
64966
+ function endsAtFailureExit(deviations) {
64967
+ return deviations.some((b) => b.armHasFailureExit);
64566
64968
  }
64567
64969
  function buildContextMap(ir) {
64568
64970
  return new Map(ir.contexts.map((c) => [c.id, c]));
@@ -64642,6 +65044,10 @@ function selectBranch(moment, branchSelections, state) {
64642
65044
  const branch = (selected ? branches.find((b) => b.condition === selected) : void 0) ?? branches[0];
64643
65045
  return { branch, forced };
64644
65046
  }
65047
+ function armEndsAtFailureExit(branch) {
65048
+ const exit = branch.entries.find((e) => e.terminal);
65049
+ return exit !== void 0 && exit.exit !== "outcome";
65050
+ }
64645
65051
  function recordBranchPoint(state, moment, branch, branchIdx, forced) {
64646
65052
  state.activations.push({ momentName: moment.name, condition: branch.condition });
64647
65053
  if (!forced && !state.reachedNames.has(moment.name)) {
@@ -64650,7 +65056,7 @@ function recordBranchPoint(state, moment, branch, branchIdx, forced) {
64650
65056
  momentName: moment.name,
64651
65057
  condition: branch.condition,
64652
65058
  isFirstArm: branchIdx === 0,
64653
- armHasTerminal: branch.entries.some((e) => e.terminal)
65059
+ armHasFailureExit: armEndsAtFailureExit(branch)
64654
65060
  });
64655
65061
  }
64656
65062
  }
@@ -64695,7 +65101,7 @@ function entryToNode(entry, moment, momentIndex, laneIndex, scope, outcome) {
64695
65101
  const contextName = entry.contextId.replace(/^ctx-/, "");
64696
65102
  const laneId = laneIndex.get(entry.contextId) ?? entry.contextId;
64697
65103
  return {
64698
- nodeId: `${moment.id}::${laneId}::${entry.nodeName}::${scope}`,
65104
+ nodeId: nodeId(moment, entry, (e) => laneIndex.get(e.contextId) ?? e.contextId, scope),
64699
65105
  nodeName: entry.nodeName,
64700
65106
  contextId: entry.contextId,
64701
65107
  contextName,
@@ -64710,14 +65116,20 @@ function entryToNode(entry, moment, momentIndex, laneIndex, scope, outcome) {
64710
65116
  function generateEvents(nodes, flow, contextMap, sessionId, correlationId, baseTime) {
64711
65117
  const events = [];
64712
65118
  const eventIds = nodes.map((_, i) => `evt-${String(i + 1).padStart(3, "0")}`);
65119
+ const placements2 = placementsOf(nodes, contextMap);
65120
+ const commandOfEvent = new Map(placements2.flatMap((p) => p.events.map((k) => [k, p.command])));
64713
65121
  for (let i = 0; i < nodes.length; i++) {
64714
65122
  const node = nodes[i];
64715
- const timestamp = new Date(baseTime.getTime() + i * 1e3).toISOString();
64716
- const causationEventIds = findCausationEvents(node, nodes, flow, eventIds, i);
65123
+ const recordedBy = commandOfEvent.get(i);
65124
+ const timestamp = new Date(baseTime.getTime() + (recordedBy ?? i) * 1e3).toISOString();
65125
+ const causationEventIds = findCausationEvents(node, nodes, flow, eventIds, i, recordedBy);
64717
65126
  const effectiveKind = resolveNodeKind(node.nodeName, node.contextId, contextMap, node.nodeKind);
64718
65127
  const eventType = resolveEventType(node, effectiveKind);
64719
65128
  const productSource = resolveProductSource(node, effectiveKind, contextMap);
64720
65129
  const payload = buildPayload(node, effectiveKind, contextMap, flow);
65130
+ const whenState = placements2.find((p) => p.command === i)?.whenState;
65131
+ if (whenState !== void 0)
65132
+ payload.whenState = whenState;
64721
65133
  events.push({
64722
65134
  eventId: eventIds[i],
64723
65135
  eventType,
@@ -64732,7 +65144,7 @@ function generateEvents(nodes, flow, contextMap, sessionId, correlationId, baseT
64732
65144
  }
64733
65145
  return events;
64734
65146
  }
64735
- function findCausationEvents(node, allNodes, flow, eventIds, currentIndex) {
65147
+ function findCausationEvents(node, allNodes, flow, eventIds, currentIndex, recordedBy) {
64736
65148
  const causation = [];
64737
65149
  for (const conn of flow.connections) {
64738
65150
  if (!isCausationConnectionFor(conn, node))
@@ -64743,7 +65155,9 @@ function findCausationEvents(node, allNodes, flow, eventIds, currentIndex) {
64743
65155
  causation.push(causeId);
64744
65156
  }
64745
65157
  const deduped = [...new Set(causation)];
64746
- if (deduped.length === 0 && currentIndex > 0) {
65158
+ if (deduped.length === 0 && recordedBy !== void 0) {
65159
+ deduped.push(eventIds[recordedBy]);
65160
+ } else if (deduped.length === 0 && currentIndex > 0) {
64747
65161
  deduped.push(eventIds[currentIndex - 1]);
64748
65162
  }
64749
65163
  return deduped;
@@ -64891,23 +65305,40 @@ function findEventAfter(events, eventType, afterIndex) {
64891
65305
  function deriveNegativeScenarios(ir, flow, options) {
64892
65306
  const contextMap = buildContextMap(ir);
64893
65307
  const opts = resolveOptions(flow, options);
64894
- const walk = walkPath(flow, opts.branchSelections);
64895
- const nodes = walk.nodes;
64896
65308
  const scenarios = [];
64897
65309
  const usedIds = /* @__PURE__ */ new Set();
64898
- for (let i = 0; i < nodes.length; i++) {
64899
- const node = nodes[i];
64900
- const kind = resolveNodeKind(node.nodeName, node.contextId, contextMap, node.nodeKind);
64901
- if (kind !== "command")
64902
- continue;
64903
- const preconditions = findPreconditions(node, contextMap);
64904
- for (const pre of preconditions) {
64905
- const baseId = `${opts.scenarioId}-neg-${node.nodeName}-${pre.name}`;
64906
- const scenarioId = usedIds.has(baseId) ? `${baseId}-${i}` : baseId;
64907
- usedIds.add(scenarioId);
64908
- usedIds.add(baseId);
64909
- scenarios.push(buildNegativeScenario(ir, flow, walk, i, pre, contextMap, opts, scenarioId));
65310
+ const covered = /* @__PURE__ */ new Set();
65311
+ const deriveOnPath = (walk, onlyUncovered) => {
65312
+ const nodes = walk.nodes;
65313
+ for (let i = 0; i < nodes.length; i++) {
65314
+ const node = nodes[i];
65315
+ const kind = resolveNodeKind(node.nodeName, node.contextId, contextMap, node.nodeKind);
65316
+ if (kind !== "command")
65317
+ continue;
65318
+ for (const pre of findPreconditions(node, contextMap)) {
65319
+ const key = [node.nodeName, pre.name, node.cause ?? ""].join("\0");
65320
+ if (onlyUncovered && covered.has(key))
65321
+ continue;
65322
+ covered.add(key);
65323
+ const baseId = `${opts.scenarioId}-neg-${node.nodeName}-${pre.name}`;
65324
+ const scenarioId = usedIds.has(baseId) ? `${baseId}-${i}` : baseId;
65325
+ usedIds.add(scenarioId);
65326
+ usedIds.add(baseId);
65327
+ scenarios.push(buildNegativeScenario(ir, flow, walk, i, pre, contextMap, opts, scenarioId));
65328
+ }
64910
65329
  }
65330
+ };
65331
+ deriveOnPath(walkPath(flow, opts.branchSelections), false);
65332
+ if (options?.branchSelections !== void 0)
65333
+ return scenarios;
65334
+ const seenPaths = /* @__PURE__ */ new Set();
65335
+ for (const selections of enumerateBranchCombinations(flow)) {
65336
+ const walk = walkPath(flow, selections);
65337
+ const pathKey = walk.nodes.map((n) => n.nodeId).join("|");
65338
+ if (seenPaths.has(pathKey))
65339
+ continue;
65340
+ seenPaths.add(pathKey);
65341
+ deriveOnPath(walk, true);
64911
65342
  }
64912
65343
  return scenarios;
64913
65344
  }
@@ -65137,9 +65568,26 @@ function generatePlaceholder(type, name) {
65137
65568
  return [];
65138
65569
  return {};
65139
65570
  }
65140
- function buildWhenClause(flow, nodes) {
65571
+ function buildWhenClause(flow, nodes, contextMap) {
65141
65572
  const momentNames = [...new Set(nodes.map((n) => n.momentName))];
65142
- return `The flow progresses through ${momentNames.join(", ")}`;
65573
+ const base = `The flow progresses through ${momentNames.join(", ")}`;
65574
+ const guards = placementsOf(nodes, contextMap).filter((p) => p.whenState !== void 0).map((p) => {
65575
+ const owner = ownerNameOf(nodes[p.command], contextMap);
65576
+ return `${nodes[p.command].nodeName} is invoked while ${owner} is ${p.whenState ?? ""}`;
65577
+ });
65578
+ return [base, ...guards].join("; ");
65579
+ }
65580
+ function placementsOf(nodes, contextMap) {
65581
+ return multiEventPlacements(nodes, (n) => {
65582
+ const ctx = contextMap.get(n.contextId);
65583
+ return ctx ? findCommand(ctx, n.nodeName) : void 0;
65584
+ });
65585
+ }
65586
+ function ownerNameOf(node, contextMap) {
65587
+ const ctx = contextMap.get(node.contextId);
65588
+ const aggregate = ctx?.aggregates.find((a) => a.commands.some((c) => c.name === node.nodeName));
65589
+ const saga = ctx?.sagas.find((s) => (s.commands ?? []).some((c) => c.name === node.nodeName));
65590
+ return aggregate?.name ?? saga?.name ?? node.contextName;
65143
65591
  }
65144
65592
  function buildThenClause(flow, nodes, contextNames) {
65145
65593
  const lastNode = nodes[nodes.length - 1];
@@ -65299,7 +65747,7 @@ function buildCatalogEntry(event, aggregate, context, ir) {
65299
65747
  };
65300
65748
  }
65301
65749
  function buildProcessCatalogEntry(event, saga, context, ir) {
65302
- const command2 = (saga.commands ?? []).find((c) => c.emitsEvent === event.name);
65750
+ const command2 = (saga.commands ?? []).find((c) => emittedEvents(c).includes(event.name));
65303
65751
  return {
65304
65752
  eventName: event.name,
65305
65753
  kind: "event",
@@ -65315,18 +65763,30 @@ function buildProcessCatalogEntry(event, saga, context, ir) {
65315
65763
  context: context.name,
65316
65764
  aggregate: "",
65317
65765
  process: saga.name,
65318
- command: command2?.name ?? ""
65766
+ command: command2?.name ?? "",
65767
+ ...command2 ? recordedAlongside(command2, event.name) : {}
65319
65768
  },
65320
65769
  consumers: findConsumers(event, ir),
65321
65770
  temporalLocation: findTemporalLocation(event, ir)
65322
65771
  };
65323
65772
  }
65324
65773
  function findProducerCommand(event, aggregate, context) {
65325
- const command2 = aggregate.commands.find((c) => c.emitsEvent === event.name);
65774
+ const command2 = aggregate.commands.find((c) => emittedEvents(c).includes(event.name));
65326
65775
  return {
65327
65776
  context: context.name,
65328
65777
  aggregate: aggregate.name,
65329
- command: command2?.name ?? ""
65778
+ command: command2?.name ?? "",
65779
+ ...command2 ? recordedAlongside(command2, event.name) : {}
65780
+ };
65781
+ }
65782
+ function recordedAlongside(command2, eventName) {
65783
+ const outcomes = emitOutcomes(command2);
65784
+ const distinct = (events) => [...new Set(events)].filter((e) => e !== eventName);
65785
+ const recordedWith = distinct(outcomes.filter((o) => o.events.includes(eventName)).flatMap((o) => o.events));
65786
+ const alternativeTo = distinct(outcomes.filter((o) => !o.events.includes(eventName)).flatMap((o) => o.events));
65787
+ return {
65788
+ ...recordedWith.length > 0 ? { recordedWith } : {},
65789
+ ...alternativeTo.length > 0 ? { alternativeTo } : {}
65330
65790
  };
65331
65791
  }
65332
65792
  function findConsumers(event, ir) {
@@ -65417,24 +65877,25 @@ function addCommandNodes(context, nodeMap) {
65417
65877
  for (const agg of context.aggregates) {
65418
65878
  for (const cmd of agg.commands) {
65419
65879
  const cmdNode = getOrCreate(nodeMap, "command", cmd.name, context.name);
65420
- if (cmd.emitsEvent) {
65421
- const evtNode = getOrCreate(nodeMap, "event", cmd.emitsEvent, context.name);
65422
- cmdNode.triggers.push(nodeKey("event", cmd.emitsEvent, context.name));
65423
- evtNode.dependsOn.push(nodeKey("command", cmd.name, context.name));
65424
- }
65880
+ linkCommandToEvents(cmdNode, cmd, context, nodeMap);
65425
65881
  }
65426
65882
  }
65427
65883
  for (const saga of context.sagas) {
65428
65884
  for (const cmd of saga.commands ?? []) {
65429
- if (!cmd.emitsEvent)
65885
+ if (emittedEvents(cmd).length === 0)
65430
65886
  continue;
65431
65887
  const cmdNode = getOrCreate(nodeMap, "command", cmd.name, context.name);
65432
- const evtNode = getOrCreate(nodeMap, "event", cmd.emitsEvent, context.name);
65433
- cmdNode.triggers.push(nodeKey("event", cmd.emitsEvent, context.name));
65434
- evtNode.dependsOn.push(nodeKey("command", cmd.name, context.name));
65888
+ linkCommandToEvents(cmdNode, cmd, context, nodeMap);
65435
65889
  }
65436
65890
  }
65437
65891
  }
65892
+ function linkCommandToEvents(cmdNode, cmd, context, nodeMap) {
65893
+ for (const event of emittedEvents(cmd)) {
65894
+ const evtNode = getOrCreate(nodeMap, "event", event, context.name);
65895
+ cmdNode.triggers.push(nodeKey("event", event, context.name));
65896
+ evtNode.dependsOn.push(nodeKey("command", cmd.name, context.name));
65897
+ }
65898
+ }
65438
65899
  function addEventNodes(context, nodeMap) {
65439
65900
  for (const agg of context.aggregates) {
65440
65901
  for (const event of agg.events) {
@@ -65788,7 +66249,7 @@ function entryToNode2(entry, moment, ctxMap, laneIndex, scope) {
65788
66249
  const nodeKind = resolveNodeKind2(entry, ctx);
65789
66250
  const aggregate = findAggregate(entry.nodeName, ctx);
65790
66251
  return {
65791
- id: `${moment.id}::${laneId}::${entry.nodeName}::${scope}`,
66252
+ id: nodeId(moment, entry, (e) => laneIdOf(e, laneIndex), scope),
65792
66253
  lane: laneId,
65793
66254
  label: entry.nodeName,
65794
66255
  type: nodeKind,
@@ -65801,6 +66262,9 @@ function entryToNode2(entry, moment, ctxMap, laneIndex, scope) {
65801
66262
  eventTypes: nodeKind === "event" ? [entry.nodeName] : void 0
65802
66263
  };
65803
66264
  }
66265
+ function laneIdOf(entry, laneIndex) {
66266
+ return laneIndex.get(entry.contextId)?.id ?? entry.contextId;
66267
+ }
65804
66268
  function resolveNodeKind2(entry, ctx) {
65805
66269
  if (!ctx)
65806
66270
  return entry.nodeKind;
@@ -65833,46 +66297,51 @@ function findProcess(nodeName, ctx) {
65833
66297
  return null;
65834
66298
  }
65835
66299
  function buildConnections(flow) {
65836
- return flow.connections.map((conn) => {
65837
- const eventType = conn.eventId.replace(/^evt-/, "");
65838
- const endpoints = {
65839
- eventType,
65840
- sourceNodeName: conn.sourceNodeName,
65841
- targetNodeName: conn.targetNodeName
65842
- };
65843
- if (conn.connectionType === "returns-to") {
65844
- if (conn.targetMomentId) {
65845
- return {
65846
- from: conn.sourceMomentId,
65847
- to: conn.targetMomentId,
65848
- style: "return",
65849
- targetMomentLabel: conn.targetMomentLabel,
65850
- ...endpoints
65851
- };
65852
- }
66300
+ return flow.connections.map((conn) => ({
66301
+ ...buildConnection(conn),
66302
+ // ADR-044: the IR already states which arm declared the connection.
66303
+ ...conn.branchCondition !== void 0 ? { branchCondition: conn.branchCondition } : {}
66304
+ }));
66305
+ }
66306
+ function buildConnection(conn) {
66307
+ const eventType = conn.eventId.replace(/^evt-/, "");
66308
+ const endpoints = {
66309
+ eventType,
66310
+ sourceNodeName: conn.sourceNodeName,
66311
+ targetNodeName: conn.targetNodeName
66312
+ };
66313
+ if (conn.connectionType === "returns-to") {
66314
+ if (conn.targetMomentId) {
65853
66315
  return {
65854
66316
  from: conn.sourceMomentId,
65855
- to: conn.targetContextId,
65856
- label: `unresolved returns-to target: ${conn.targetMomentLabel ?? "(unknown)"}`,
66317
+ to: conn.targetMomentId,
65857
66318
  style: "return",
65858
66319
  targetMomentLabel: conn.targetMomentLabel,
65859
66320
  ...endpoints
65860
66321
  };
65861
66322
  }
65862
- const isCrossing2 = conn.connectionType === "crosses-to";
65863
66323
  return {
65864
66324
  from: conn.sourceMomentId,
65865
- // For 'triggers' the core now resolves targetContextId to the context
65866
- // where the TARGET node is placed (not the source's own lane).
65867
66325
  to: conn.targetContextId,
65868
- label: isCrossing2 ? eventType : void 0,
65869
- style: mapConnectionStyle(conn),
65870
- crossBoundary: isCrossing2 || void 0,
65871
- relationship: isCrossing2 ? conn.schemaContract.relationshipType : void 0,
65872
- schemaContract: isCrossing2 ? mapSchemaContract(conn) : void 0,
66326
+ label: `unresolved returns-to target: ${conn.targetMomentLabel ?? "(unknown)"}`,
66327
+ style: "return",
66328
+ targetMomentLabel: conn.targetMomentLabel,
65873
66329
  ...endpoints
65874
66330
  };
65875
- });
66331
+ }
66332
+ const isCrossing2 = conn.connectionType === "crosses-to";
66333
+ return {
66334
+ from: conn.sourceMomentId,
66335
+ // For 'triggers' the core now resolves targetContextId to the context
66336
+ // where the TARGET node is placed (not the source's own lane).
66337
+ to: conn.targetContextId,
66338
+ label: isCrossing2 ? eventType : void 0,
66339
+ style: mapConnectionStyle(conn),
66340
+ crossBoundary: isCrossing2 || void 0,
66341
+ relationship: isCrossing2 ? conn.schemaContract.relationshipType : void 0,
66342
+ schemaContract: isCrossing2 ? mapSchemaContract(conn) : void 0,
66343
+ ...endpoints
66344
+ };
65876
66345
  }
65877
66346
  function mapConnectionStyle(conn) {
65878
66347
  if (conn.connectionType === "crosses-to")
@@ -65905,21 +66374,21 @@ function buildEventRouting(flow, ctxMap, laneIndex) {
65905
66374
  const kind = resolveNodeKind2(entry, ctx);
65906
66375
  const lane = laneIndex.get(entry.contextId);
65907
66376
  const laneId = lane?.id ?? entry.contextId;
65908
- const nodeId = `${moment.id}::${laneId}::${entry.nodeName}::${scope}`;
66377
+ const id = nodeId(moment, entry, (e) => laneIdOf(e, laneIndex), scope);
65909
66378
  if (kind === "event") {
65910
66379
  const existing = routing[entry.nodeName] ?? /* @__PURE__ */ new Set();
65911
- existing.add(nodeId);
66380
+ existing.add(id);
65912
66381
  routing[entry.nodeName] = existing;
65913
66382
  }
65914
66383
  if (kind === "policy") {
65915
66384
  const existing = routing[entry.nodeName] ?? /* @__PURE__ */ new Set();
65916
- existing.add(nodeId);
66385
+ existing.add(id);
65917
66386
  routing[entry.nodeName] = existing;
65918
66387
  }
65919
66388
  if (kind === "command") {
65920
66389
  const key = `SimProcess.${entry.nodeName}`;
65921
66390
  const existing = routing[key] ?? /* @__PURE__ */ new Set();
65922
- existing.add(nodeId);
66391
+ existing.add(id);
65923
66392
  routing[key] = existing;
65924
66393
  }
65925
66394
  };
@@ -66145,12 +66614,16 @@ function renderNoteOnlyMoment(lines, moment, flow) {
66145
66614
  lines.push(...noteComments(moment, flow, " "));
66146
66615
  lines.push("");
66147
66616
  }
66617
+ function armEndsAtOutcome(branchEntries) {
66618
+ return branchEntries.find((e) => e.terminal)?.exit === "outcome";
66619
+ }
66148
66620
  function renderTerminalBranchScenario(lines, moment, condition, branchEntries, flow, ctxMap, ir) {
66149
- const tags = ["@terminal", "@failure-path"];
66621
+ const endsAtOutcome = armEndsAtOutcome(branchEntries);
66622
+ const tags = ["@terminal", endsAtOutcome ? "@alt-path" : "@failure-path"];
66150
66623
  lines.push(` ${tags.join(" ")}`);
66151
66624
  lines.push(` Scenario: ${moment.name} [${condition}]`);
66152
66625
  lines.push(...noteComments(moment, flow, " "));
66153
- const failedPrecondition = findFailedPrecondition(moment, ctxMap);
66626
+ const failedPrecondition = endsAtOutcome ? void 0 : findFailedPrecondition(moment, ctxMap);
66154
66627
  lines.push(` Given the ${moment.name.toLowerCase()} is evaluated`);
66155
66628
  if (failedPrecondition) {
66156
66629
  lines.push(` When ${failedPrecondition.name} is not satisfied`);
@@ -66165,7 +66638,8 @@ function renderTerminalBranchScenario(lines, moment, condition, branchEntries, f
66165
66638
  lines.push(` Then the flow terminates because ${failedPrecondition.description}`);
66166
66639
  } else {
66167
66640
  const terminalNode = branchEntries.find((e) => e.terminal)?.nodeName;
66168
- lines.push(` Then the flow terminates${terminalNode ? ` at ${terminalNode}` : ""}`);
66641
+ const verb = endsAtOutcome ? "ends" : "terminates";
66642
+ lines.push(` Then the flow ${verb}${terminalNode ? ` at ${terminalNode}` : ""}`);
66169
66643
  }
66170
66644
  const compensation = findCompensationForMoment(moment, ir);
66171
66645
  if (compensation) {
@@ -66232,9 +66706,30 @@ function renderEntrySteps(lines, entry, moment, branchCondition, flow, ctxMap, s
66232
66706
  if (entry.nodeKind === "command") {
66233
66707
  renderCommandStep(lines, entry, ctx, ctxName, moment, flow, sharedPreconditions);
66234
66708
  } else {
66709
+ const first2 = lines.length;
66235
66710
  renderEventStep(lines, entry, ctx, ctxName, moment, branchCondition, flow, usedConnections);
66711
+ if (first2 < lines.length && coEmittedEntries(moment, ctxMap).has(entry)) {
66712
+ lines[first2] = lines[first2].replace(/^(\s*)Then /, "$1And ");
66713
+ }
66236
66714
  }
66237
66715
  }
66716
+ var coEmittedCache = /* @__PURE__ */ new WeakMap();
66717
+ function coEmittedEntries(moment, ctxMap) {
66718
+ const cached = coEmittedCache.get(moment);
66719
+ if (cached)
66720
+ return cached;
66721
+ const commandOf = (name) => {
66722
+ for (const ctx of ctxMap.values()) {
66723
+ const cmd = findCommand2(ctx, name);
66724
+ if (cmd)
66725
+ return cmd;
66726
+ }
66727
+ return void 0;
66728
+ };
66729
+ const entries = new Set(momentPlacements(moment, commandOf).filter((p) => emittedEvents(p.command).length > 1).flatMap((p) => p.events.slice(1)));
66730
+ coEmittedCache.set(moment, entries);
66731
+ return entries;
66732
+ }
66238
66733
  function renderCommandStep(lines, entry, ctx, ctxName, moment, flow, sharedPreconditions = /* @__PURE__ */ new Set()) {
66239
66734
  const cmd = findCommand2(ctx, entry.nodeName);
66240
66735
  if (cmd) {
@@ -66273,7 +66768,7 @@ function readOrEmit(entry) {
66273
66768
  return "emits";
66274
66769
  }
66275
66770
  function renderInternalEventStep(lines, entry, evt, ctxName) {
66276
- const modifier = entry.optional ? " (optional)" : entry.terminal ? " (terminal)" : "";
66771
+ const modifier = entry.optional ? " (optional)" : entry.terminal ? entry.exit === "outcome" ? " (outcome)" : " (terminal)" : "";
66277
66772
  lines.push(` Then ${ctxName} ${readOrEmit(entry)} ${entry.nodeName}${modifier}`);
66278
66773
  if (evt && evt.fields.length > 0) {
66279
66774
  lines.push(` carrying ${evt.fields.map((f) => f.name).join(", ")}`);
@@ -66613,6 +67108,13 @@ function safeFileName(str) {
66613
67108
  }
66614
67109
 
66615
67110
  // ../generate/dist/services/specification-document-generator.js
67111
+ var hasEvents = (cmd) => emittedEvents(cmd).length > 0;
67112
+ function describeOutcomes(cmd, mark) {
67113
+ const outcomes = emitOutcomes(cmd);
67114
+ const guarded = outcomes.some((o) => o.whenState !== void 0);
67115
+ const parts = outcomes.map((o) => o.events.map(mark).join(", ") + (o.whenState === void 0 ? "" : ` when ${o.whenState}`));
67116
+ return parts.join(guarded ? ", or " : " or ");
67117
+ }
66616
67118
  var SpecificationDocumentGenerator = class {
66617
67119
  generate(ir) {
66618
67120
  if (ir.contexts.length === 0 && ir.flows.length === 0)
@@ -66773,8 +67275,10 @@ var SpecificationDocumentGenerator = class {
66773
67275
  }
66774
67276
  renderTerminalBranch(lines, moment, branch, flow, ir) {
66775
67277
  const usedConnections = /* @__PURE__ */ new Set();
66776
- const terminalNode = branch.entries.find((e) => e.terminal)?.nodeName;
66777
- lines.push(` - \u274C **If ${branch.condition}:** flow terminates${terminalNode ? ` at **${terminalNode}**` : ""}`);
67278
+ const exit = branch.entries.find((e) => e.terminal);
67279
+ const terminalNode = exit?.nodeName;
67280
+ const [mark, verb] = exit?.exit === "outcome" ? ["\u2705", "ends"] : ["\u274C", "terminates"];
67281
+ lines.push(` - ${mark} **If ${branch.condition}:** flow ${verb}${terminalNode ? ` at **${terminalNode}**` : ""}`);
66778
67282
  for (const entry of branch.entries) {
66779
67283
  if (entry.terminal)
66780
67284
  continue;
@@ -66822,7 +67326,7 @@ var SpecificationDocumentGenerator = class {
66822
67326
  renderCommandNarrative(lines, entry, ctx, ctxName, indent) {
66823
67327
  const cmd = this.findCommand(ctx, entry.nodeName);
66824
67328
  const intent = cmd?.preconditions?.[0]?.description;
66825
- const produces = cmd?.emitsEvent ? ` \u2192 produces **${cmd.emitsEvent}**` : "";
67329
+ const produces = cmd && hasEvents(cmd) ? ` \u2192 produces ${describeOutcomes(cmd, (e) => `**${e}**`)}` : "";
66826
67330
  if (intent) {
66827
67331
  lines.push(`${indent}- *Requires:* ${intent}`);
66828
67332
  }
@@ -66928,7 +67432,7 @@ var SpecificationDocumentGenerator = class {
66928
67432
  lines.push("|---------|---------|----------|");
66929
67433
  for (const cmd of agg.commands) {
66930
67434
  const purpose = cmd.preconditions[0]?.description ?? `Accepts ${cmd.inputs.map((i) => i.name).join(", ")}`;
66931
- lines.push(`| **${cmd.name}** | ${purpose} | ${cmd.emitsEvent} |`);
67435
+ lines.push(`| **${cmd.name}** | ${purpose} | ${describeOutcomes(cmd, (e) => e)} |`);
66932
67436
  }
66933
67437
  lines.push("");
66934
67438
  }
@@ -67011,8 +67515,8 @@ var SpecificationDocumentGenerator = class {
67011
67515
  lines.push("graph LR");
67012
67516
  for (const ctx of ir.contexts) {
67013
67517
  const classification = ctx.classification ?? "Generic";
67014
- const nodeId = this.mermaidNodeId(ctx.name);
67015
- lines.push(` ${nodeId}["${ctx.name}<br/><i>${classification}</i>"]`);
67518
+ const nodeId2 = this.mermaidNodeId(ctx.name);
67519
+ lines.push(` ${nodeId2}["${ctx.name}<br/><i>${classification}</i>"]`);
67016
67520
  }
67017
67521
  for (const edge of edges) {
67018
67522
  lines.push(` ${edge.source} -->|${edge.label}| ${edge.target}`);
@@ -67100,8 +67604,11 @@ var SpecificationDocumentGenerator = class {
67100
67604
  }
67101
67605
  renderBranchAltBlock(lines, moment, ctxName, flow, ir) {
67102
67606
  const nonTerminal = moment.branches.filter((b) => !b.entries.some((e) => e.terminal));
67103
- const terminal = moment.branches.filter((b) => b.entries.some((e) => e.terminal));
67104
- if (nonTerminal.length === 0 && terminal.length === 0)
67607
+ const ending = moment.branches.filter((b) => b.entries.some((e) => e.terminal));
67608
+ const isOutcome = (b) => b.entries.find((e) => e.terminal)?.exit === "outcome";
67609
+ const terminal = ending.filter((b) => !isOutcome(b));
67610
+ const outcome = ending.filter(isOutcome);
67611
+ if (nonTerminal.length === 0 && ending.length === 0)
67105
67612
  return;
67106
67613
  for (let i = 0; i < nonTerminal.length; i++) {
67107
67614
  const branch = nonTerminal[i];
@@ -67109,11 +67616,16 @@ var SpecificationDocumentGenerator = class {
67109
67616
  lines.push(` ${keyword} ${branch.condition}`);
67110
67617
  this.renderSequenceEntries(lines, branch.entries, moment, branch.condition, flow, ir);
67111
67618
  }
67112
- if (terminal.length > 0) {
67113
- const keyword = nonTerminal.length === 0 ? "alt" : "else";
67114
- const labels = terminal.map((b) => b.condition).join(" / ");
67115
- lines.push(` ${keyword} ${labels}`);
67116
- lines.push(` Note over ${ctxName}: Flow terminates`);
67619
+ let opened = nonTerminal.length > 0;
67620
+ for (const [arms, note] of [
67621
+ [terminal, "Flow terminates"],
67622
+ [outcome, "Flow ends at an outcome"]
67623
+ ]) {
67624
+ if (arms.length === 0)
67625
+ continue;
67626
+ lines.push(` ${opened ? "else" : "alt"} ${arms.map((b) => b.condition).join(" / ")}`);
67627
+ lines.push(` Note over ${ctxName}: ${note}`);
67628
+ opened = true;
67117
67629
  }
67118
67630
  lines.push(" end");
67119
67631
  }
@@ -67134,7 +67646,7 @@ var SpecificationDocumentGenerator = class {
67134
67646
  lines.push(` ${entryCtx}->>${target}: ${entry.nodeName} (crosses)`);
67135
67647
  } else if (entry.nodeKind === "command") {
67136
67648
  const cmd = this.findCommand(ir.contexts.find((c) => c.id === entry.contextId), entry.nodeName);
67137
- const emits = cmd?.emitsEvent ? ` \u2192 ${cmd.emitsEvent}` : "";
67649
+ const emits = cmd && hasEvents(cmd) ? ` \u2192 ${describeOutcomes(cmd, (e) => e)}` : "";
67138
67650
  lines.push(` ${entryCtx}->>${entryCtx}: ${entry.nodeName}${emits}`);
67139
67651
  } else {
67140
67652
  lines.push(` ${entryCtx}->>${entryCtx}: ${entry.nodeName}`);
@@ -67715,6 +68227,19 @@ function generateTypesFile(aggregate) {
67715
68227
  }
67716
68228
  return parts.join("\n");
67717
68229
  }
68230
+ function handlerReturnType(cmd) {
68231
+ const members = emitOutcomes(cmd).map((o) => {
68232
+ const events = o.events.map(toPascalCase);
68233
+ return events.length === 1 ? events[0] : `readonly [${events.join(", ")}]`;
68234
+ });
68235
+ return members.length === 0 ? "void" : [...new Set(members)].join(" | ");
68236
+ }
68237
+ function emitsTags(cmd) {
68238
+ return [
68239
+ ...emittedEvents(cmd).map((e) => ` * @emits ${toPascalCase(e)}`),
68240
+ ...emitOutcomes(cmd).filter((o) => o.whenState !== void 0).map((o) => ` * @outcome ${o.whenState ?? ""}: ${o.events.map(toPascalCase).join(", ")}`)
68241
+ ];
68242
+ }
67718
68243
  function generateAggregateFile(aggregate) {
67719
68244
  const aggregateName = toPascalCase(aggregate.name);
67720
68245
  const kebabName = toKebabCase2(aggregate.name);
@@ -67741,19 +68266,17 @@ function generateAggregateFile(aggregate) {
67741
68266
  for (const cmd of aggregate.commands) {
67742
68267
  const cmdName = toPascalCase(cmd.name);
67743
68268
  const handlerName = cmd.name.charAt(0).toLowerCase() + cmd.name.slice(1).replace(/[^A-Za-z0-9_$]/g, "");
67744
- const eventName = cmd.emitsEvent ? toPascalCase(cmd.emitsEvent) : "void";
68269
+ const returnType = handlerReturnType(cmd);
67745
68270
  const jsdocLines = [];
67746
68271
  jsdocLines.push(` /**`);
67747
68272
  jsdocLines.push(` * Handle ${cmd.name}.`);
67748
68273
  for (const pre of cmd.preconditions) {
67749
68274
  jsdocLines.push(` * @precondition ${sanitizeJsDoc(pre.description)}`);
67750
68275
  }
67751
- if (cmd.emitsEvent) {
67752
- jsdocLines.push(` * @emits ${toPascalCase(cmd.emitsEvent)}`);
67753
- }
68276
+ jsdocLines.push(...emitsTags(cmd));
67754
68277
  jsdocLines.push(` */`);
67755
68278
  parts.push(jsdocLines.join("\n"));
67756
- parts.push(` ${safePropertyKey(handlerName)}(command: ${cmdName}): ${eventName};`);
68279
+ parts.push(` ${safePropertyKey(handlerName)}(command: ${cmdName}): ${returnType};`);
67757
68280
  }
67758
68281
  parts.push("}");
67759
68282
  parts.push("");