@reventlessdev/reventless-gwt 1.0.0-alpha.292 → 1.0.0-alpha.293

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.
@@ -1,9 +1,19 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
3
  import * as Sury from "sury";
4
+ import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
4
5
  import * as Id$Reventless from "@reventlessdev/reventless-spec/src/types/Id.res.mjs";
6
+ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
7
+ import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
8
+ import * as Clock$Reventless from "@reventlessdev/reventless-spec/src/components/Clock.res.mjs";
5
9
  import * as DcbTag$Reventless from "@reventlessdev/reventless-spec/src/components/DcbTag.res.mjs";
10
+ import * as Hint$ReventlessGwt from "../src/Hint.res.mjs";
11
+ import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
12
+ import * as Outcome$ReventlessGwt from "../src/Outcome.res.mjs";
6
13
  import * as Flow_GWT$ReventlessGwt from "../src/Flow_GWT.res.mjs";
14
+ import * as JestBind$ReventlessGwt from "../src/JestBind.res.mjs";
15
+ import * as AutomationSlice$Reventless from "@reventlessdev/reventless-spec/src/components/AutomationSlice.res.mjs";
16
+ import * as Decision_GWT$ReventlessGwt from "../src/Decision_GWT.res.mjs";
7
17
 
8
18
  let consumedEventSchema = Sury.$schema(s => ({
9
19
  TAG: "OrderPlaced",
@@ -81,7 +91,45 @@ let PlaceOrderDecision = {
81
91
  decide: decide
82
92
  };
83
93
 
84
- let consumedEventSchema$1 = Sury.union([
94
+ let todoItemSchema = Sury.$schema(s => ({
95
+ orderId: s.m(Sury.string)
96
+ }));
97
+
98
+ let commandSchema$1 = Sury.$schema(s => ({
99
+ TAG: "ShipOrder",
100
+ orderId: s.m(Sury.string)
101
+ }));
102
+
103
+ function authorizationOf$1(param) {
104
+ return "AllowAuthenticated";
105
+ }
106
+
107
+ function commandTransition$1(param) {
108
+ return "Undeclared";
109
+ }
110
+
111
+ let traits$1 = [];
112
+
113
+ let AutoShipSlice = {
114
+ name: "AutoShip",
115
+ moduleUrl: "",
116
+ todoItemSchema: todoItemSchema,
117
+ commandSchema: commandSchema$1,
118
+ maxRetries: 3,
119
+ targetName: "Order",
120
+ schedule: undefined,
121
+ authorizationOf: authorizationOf$1,
122
+ commandTransition: commandTransition$1,
123
+ traits: traits$1
124
+ };
125
+
126
+ let M = AutomationSlice$Reventless.Mappings.Make(AutoShipSlice);
127
+
128
+ let moduleUrl = "";
129
+
130
+ let name = "Orders";
131
+
132
+ let eventSchema$1 = Sury.union([
85
133
  Sury.$schema(s => ({
86
134
  TAG: "OrderPlaced",
87
135
  orderId: s.m(Sury.string)
@@ -92,16 +140,13 @@ let consumedEventSchema$1 = Sury.union([
92
140
  }))
93
141
  ]);
94
142
 
95
- let todoItemSchema = Sury.$schema(s => ({
96
- orderId: s.m(Sury.string)
97
- }));
98
-
99
- let commandSchema$1 = Sury.$schema(s => ({
100
- TAG: "ShipOrder",
101
- orderId: s.m(Sury.string)
102
- }));
143
+ let Orders = {
144
+ Id: undefined,
145
+ name: name,
146
+ eventSchema: eventSchema$1
147
+ };
103
148
 
104
- function collect(event) {
149
+ function collect(event, param, _ctx) {
105
150
  if (event.TAG !== "OrderPlaced") {
106
151
  return [];
107
152
  }
@@ -122,6 +167,22 @@ function resolve(event) {
122
167
  }
123
168
  }
124
169
 
170
+ function reschedule(param) {
171
+ return [];
172
+ }
173
+
174
+ let FromOrders = AutomationSlice$Reventless.Mapping.Make({
175
+ Id: Id$Reventless.$$String,
176
+ name: name,
177
+ eventSchema: eventSchema$1
178
+ })(AutoShipSlice)({
179
+ collect: collect,
180
+ resolve: resolve,
181
+ reschedule: reschedule
182
+ });
183
+
184
+ let mappings = [FromOrders];
185
+
125
186
  function process(id, _todo, param) {
126
187
  return [
127
188
  id,
@@ -136,31 +197,17 @@ function onExhausted(_id, _todo, param) {
136
197
 
137
198
  }
138
199
 
139
- function authorizationOf$1(param) {
140
- return "AllowAuthenticated";
141
- }
142
-
143
- function commandTransition$1(param) {
144
- return "Undeclared";
145
- }
146
-
147
- let traits$1 = [];
148
-
149
- let AutoShipSlice = {
150
- name: "AutoShip",
151
- consumedEventSchema: consumedEventSchema$1,
152
- todoItemSchema: todoItemSchema,
153
- commandSchema: commandSchema$1,
154
- collect: collect,
155
- resolve: resolve,
200
+ let AutoShipAutomation = {
201
+ M: M,
202
+ moduleUrl: moduleUrl,
203
+ Orders: Orders,
204
+ FromOrders: FromOrders,
205
+ mappings: mappings,
156
206
  process: process,
157
- onExhausted: onExhausted,
158
- authorizationOf: authorizationOf$1,
159
- commandTransition: commandTransition$1,
160
- traits: traits$1
207
+ onExhausted: onExhausted
161
208
  };
162
209
 
163
- let consumedEventSchema$2 = Sury.union([
210
+ let consumedEventSchema$1 = Sury.union([
164
211
  Sury.$schema(s => ({
165
212
  TAG: "OrderPlaced",
166
213
  orderId: s.m(DcbTag$Reventless.string)
@@ -178,7 +225,7 @@ let commandSchema$2 = Sury.$schema(s => ({
178
225
 
179
226
  let errorSchema$1 = Sury.literal("NotPlaced");
180
227
 
181
- let eventSchema$1 = Sury.$schema(s => ({
228
+ let eventSchema$2 = Sury.$schema(s => ({
182
229
  TAG: "OrderShipped",
183
230
  orderId: s.m(DcbTag$Reventless.string)
184
231
  }));
@@ -195,10 +242,10 @@ let traits$2 = [];
195
242
 
196
243
  let ShipOrderSlice = {
197
244
  name: "ShipOrder",
198
- consumedEventSchema: consumedEventSchema$2,
245
+ consumedEventSchema: consumedEventSchema$1,
199
246
  commandSchema: commandSchema$2,
200
247
  errorSchema: errorSchema$1,
201
- eventSchema: eventSchema$1,
248
+ eventSchema: eventSchema$2,
202
249
  authorizationOf: authorizationOf$2,
203
250
  commandTransition: commandTransition$2,
204
251
  traits: traits$2,
@@ -255,7 +302,7 @@ let ShipOrderDecision = {
255
302
  decide: decide$1
256
303
  };
257
304
 
258
- let name = "OrdersView";
305
+ let name$1 = "OrdersView";
259
306
 
260
307
  let stateSchema = Sury.$schema(s => ({
261
308
  orderId: s.m(Sury.string),
@@ -263,7 +310,7 @@ let stateSchema = Sury.$schema(s => ({
263
310
  status: s.m(Sury.string)
264
311
  }));
265
312
 
266
- let consumedEventSchema$3 = Sury.union([
313
+ let consumedEventSchema$2 = Sury.union([
267
314
  Sury.$schema(s => ({
268
315
  TAG: "OrderPlaced",
269
316
  orderId: s.m(Sury.string),
@@ -277,9 +324,9 @@ let consumedEventSchema$3 = Sury.union([
277
324
 
278
325
  let OrdersViewSlice = {
279
326
  Id: undefined,
280
- name: name,
327
+ name: name$1,
281
328
  stateSchema: stateSchema,
282
- consumedEventSchema: consumedEventSchema$3,
329
+ consumedEventSchema: consumedEventSchema$2,
283
330
  subIdConfig: undefined,
284
331
  authorization: "AllowAuthenticated",
285
332
  visibility: "Public"
@@ -315,7 +362,7 @@ let OrdersViewProjection = {
315
362
  project: project
316
363
  };
317
364
 
318
- let consumedEventSchema$4 = Sury.$schema(s => ({
365
+ let consumedEventSchema$3 = Sury.$schema(s => ({
319
366
  TAG: "OrderPlaced",
320
367
  orderId: s.m(Sury.string)
321
368
  }));
@@ -326,6 +373,28 @@ let outboundItemSchema = Sury.$schema(s => ({
326
373
 
327
374
  let inboundCommandSchema = Sury.$unit;
328
375
 
376
+ let sourceNames = [];
377
+
378
+ let capabilityNeeds = [];
379
+
380
+ let traits$3 = [];
381
+
382
+ let ConfirmSlice = {
383
+ name: "Confirm",
384
+ moduleUrl: "",
385
+ consumedEventSchema: consumedEventSchema$3,
386
+ outboundItemSchema: outboundItemSchema,
387
+ inboundCommandSchema: inboundCommandSchema,
388
+ maxRetries: 1,
389
+ targetName: undefined,
390
+ sourceNames: sourceNames,
391
+ externalSystem: undefined,
392
+ capabilityNeeds: capabilityNeeds,
393
+ traits: traits$3
394
+ };
395
+
396
+ let moduleUrl$1 = "";
397
+
329
398
  function collect$1(event, param) {
330
399
  let orderId = event.orderId;
331
400
  return [[
@@ -336,31 +405,276 @@ function collect$1(event, param) {
336
405
  ]];
337
406
  }
338
407
 
339
- let ConfirmSlice = {
340
- name: "Confirm",
341
- consumedEventSchema: consumedEventSchema$4,
342
- outboundItemSchema: outboundItemSchema,
343
- inboundCommandSchema: inboundCommandSchema,
408
+ async function translate(_id, _item, param) {
409
+ return {
410
+ TAG: "Ok",
411
+ _0: undefined
412
+ };
413
+ }
414
+
415
+ function onExhausted$1(_id, _item, param) {
416
+
417
+ }
418
+
419
+ let ConfirmTranslation = {
420
+ moduleUrl: moduleUrl$1,
344
421
  collect: collect$1,
345
- externalSystem: undefined
422
+ translate: translate,
423
+ onExhausted: onExhausted$1
424
+ };
425
+
426
+ let todoItemSchema$1 = Sury.$schema(s => ({
427
+ orderId: s.m(Sury.string)
428
+ }));
429
+
430
+ let commandSchema$3 = Sury.$schema(s => ({
431
+ TAG: "ShipOrder",
432
+ order: s.m(Sury.string)
433
+ }));
434
+
435
+ function authorizationOf$3(param) {
436
+ return "AllowAuthenticated";
437
+ }
438
+
439
+ function commandTransition$3(param) {
440
+ return "Undeclared";
441
+ }
442
+
443
+ let traits$4 = [];
444
+
445
+ let AutoShipByOrderSlice = {
446
+ name: "AutoShipByOrder",
447
+ moduleUrl: "",
448
+ todoItemSchema: todoItemSchema$1,
449
+ commandSchema: commandSchema$3,
450
+ maxRetries: 3,
451
+ targetName: "Order",
452
+ schedule: undefined,
453
+ authorizationOf: authorizationOf$3,
454
+ commandTransition: commandTransition$3,
455
+ traits: traits$4
456
+ };
457
+
458
+ let M$1 = AutomationSlice$Reventless.Mappings.Make(AutoShipByOrderSlice);
459
+
460
+ let moduleUrl$2 = "";
461
+
462
+ function collect$2(event, param, _ctx) {
463
+ if (event.TAG !== "OrderPlaced") {
464
+ return [];
465
+ }
466
+ let orderId = event.orderId;
467
+ return [[
468
+ orderId,
469
+ {
470
+ orderId: orderId
471
+ }
472
+ ]];
473
+ }
474
+
475
+ function resolve$1(event) {
476
+ if (event.TAG === "OrderPlaced") {
477
+ return;
478
+ } else {
479
+ return event.orderId;
480
+ }
481
+ }
482
+
483
+ function reschedule$1(param) {
484
+ return [];
485
+ }
486
+
487
+ let FromOrders$1 = AutomationSlice$Reventless.Mapping.Make({
488
+ Id: Id$Reventless.$$String,
489
+ name: name,
490
+ eventSchema: eventSchema$1
491
+ })(AutoShipByOrderSlice)({
492
+ collect: collect$2,
493
+ resolve: resolve$1,
494
+ reschedule: reschedule$1
495
+ });
496
+
497
+ let mappings$1 = [FromOrders$1];
498
+
499
+ function process$1(id, _todo, param) {
500
+ return [
501
+ id,
502
+ {
503
+ TAG: "ShipOrder",
504
+ order: id
505
+ }
506
+ ];
507
+ }
508
+
509
+ function onExhausted$2(_id, _todo, param) {
510
+
511
+ }
512
+
513
+ let AutoShipByOrderAutomation = {
514
+ M: M$1,
515
+ moduleUrl: moduleUrl$2,
516
+ FromOrders: FromOrders$1,
517
+ mappings: mappings$1,
518
+ process: process$1,
519
+ onExhausted: onExhausted$2
520
+ };
521
+
522
+ let todoItemSchema$2 = Sury.$schema(s => ({
523
+ orderId: s.m(Sury.string)
524
+ }));
525
+
526
+ let commandSchema$4 = Sury.$schema(s => ({
527
+ TAG: "RemindCustomer",
528
+ orderId: s.m(Sury.string)
529
+ }));
530
+
531
+ function authorizationOf$4(param) {
532
+ return "AllowAuthenticated";
533
+ }
534
+
535
+ function commandTransition$4(param) {
536
+ return "Undeclared";
537
+ }
538
+
539
+ let traits$5 = [];
540
+
541
+ let RemindSlice = {
542
+ name: "Remind",
543
+ moduleUrl: "",
544
+ todoItemSchema: todoItemSchema$2,
545
+ commandSchema: commandSchema$4,
546
+ maxRetries: 3,
547
+ targetName: "Order",
548
+ schedule: undefined,
549
+ authorizationOf: authorizationOf$4,
550
+ commandTransition: commandTransition$4,
551
+ traits: traits$5
346
552
  };
347
553
 
348
- let Place = Flow_GWT$ReventlessGwt.CommandStep(PlaceOrderSlice)({
554
+ let M$2 = AutomationSlice$Reventless.Mappings.Make(RemindSlice);
555
+
556
+ let moduleUrl$3 = "";
557
+
558
+ function collect$3(param, param$1, _ctx) {
559
+ let key = param.key;
560
+ return [[
561
+ Clock$Reventless.itemId(key, param.at),
562
+ {
563
+ orderId: key
564
+ }
565
+ ]];
566
+ }
567
+
568
+ function resolve$2(param) {
569
+
570
+ }
571
+
572
+ function reschedule$2(param) {
573
+ return [];
574
+ }
575
+
576
+ let FromClock = AutomationSlice$Reventless.Mapping.Make({
577
+ Id: Id$Reventless.$$String,
578
+ name: Clock$Reventless.name,
579
+ eventSchema: Clock$Reventless.eventSchema
580
+ })(RemindSlice)({
581
+ collect: collect$3,
582
+ resolve: resolve$2,
583
+ reschedule: reschedule$2
584
+ });
585
+
586
+ function collect$4(param, param$1, _ctx) {
587
+ return [];
588
+ }
589
+
590
+ function resolve$3(param) {
591
+
592
+ }
593
+
594
+ function reschedule$3(event) {
595
+ if (event.TAG === "OrderPlaced") {
596
+ return [{
597
+ TAG: "Set",
598
+ key: event.orderId,
599
+ time: {
600
+ TAG: "Once",
601
+ moment: {
602
+ TAG: "After",
603
+ _0: {
604
+ TAG: "Hours",
605
+ _0: 1
606
+ }
607
+ }
608
+ }
609
+ }];
610
+ } else {
611
+ return [{
612
+ TAG: "Clear",
613
+ key: event.orderId
614
+ }];
615
+ }
616
+ }
617
+
618
+ let FromOrders$2 = AutomationSlice$Reventless.Mapping.Make({
619
+ Id: Id$Reventless.$$String,
620
+ name: name,
621
+ eventSchema: eventSchema$1
622
+ })(RemindSlice)({
623
+ collect: collect$4,
624
+ resolve: resolve$3,
625
+ reschedule: reschedule$3
626
+ });
627
+
628
+ let mappings$2 = [
629
+ FromClock,
630
+ FromOrders$2
631
+ ];
632
+
633
+ function process$2(id, item, param) {
634
+ return [
635
+ id,
636
+ {
637
+ TAG: "RemindCustomer",
638
+ orderId: item.orderId
639
+ }
640
+ ];
641
+ }
642
+
643
+ function onExhausted$3(_id, _item, param) {
644
+
645
+ }
646
+
647
+ let RemindAutomation = {
648
+ M: M$2,
649
+ moduleUrl: moduleUrl$3,
650
+ FromClock: FromClock,
651
+ FromOrders: FromOrders$2,
652
+ mappings: mappings$2,
653
+ process: process$2,
654
+ onExhausted: onExhausted$3
655
+ };
656
+
657
+ let Place = Flow_GWT$ReventlessGwt.DecisionStep(PlaceOrderSlice)({
349
658
  initialState: initialState,
350
659
  evolve: evolve,
351
660
  decide: decide
352
661
  });
353
662
 
354
- let Auto = Flow_GWT$ReventlessGwt.AutomationStep(AutoShipSlice);
663
+ let Auto = Flow_GWT$ReventlessGwt.AutomationStep(AutoShipSlice)({
664
+ process: process,
665
+ onExhausted: onExhausted,
666
+ moduleUrl: moduleUrl,
667
+ mappings: mappings
668
+ });
355
669
 
356
- let Ship = Flow_GWT$ReventlessGwt.CommandStep(ShipOrderSlice)({
670
+ let Ship = Flow_GWT$ReventlessGwt.DecisionStep(ShipOrderSlice)({
357
671
  initialState: initialState$1,
358
672
  evolve: evolve$1,
359
673
  decide: decide$1
360
674
  });
361
675
 
362
676
  let View = Flow_GWT$ReventlessGwt.ViewStep({
363
- name: name,
677
+ name: name$1,
364
678
  stateSchema: stateSchema,
365
679
  Id: {
366
680
  schema: Id$Reventless.StringPure.schema,
@@ -369,16 +683,36 @@ let View = Flow_GWT$ReventlessGwt.ViewStep({
369
683
  toString: prim => prim,
370
684
  cmp: Id$Reventless.StringPure.cmp
371
685
  },
372
- consumedEventSchema: consumedEventSchema$3,
373
- subIdConfig: undefined
686
+ consumedEventSchema: consumedEventSchema$2,
687
+ subIdConfig: undefined,
688
+ authorization: "AllowAuthenticated"
374
689
  })({
375
690
  project: project
376
691
  });
377
692
 
378
- let Confirm = Flow_GWT$ReventlessGwt.OutboundStep(ConfirmSlice);
693
+ let Confirm = Flow_GWT$ReventlessGwt.OutboundStep(ConfirmSlice)({
694
+ collect: collect$1,
695
+ translate: translate,
696
+ onExhausted: onExhausted$1,
697
+ moduleUrl: moduleUrl$1
698
+ });
699
+
700
+ let AutoByOrder = Flow_GWT$ReventlessGwt.AutomationStep(AutoShipByOrderSlice)({
701
+ process: process$1,
702
+ onExhausted: onExhausted$2,
703
+ moduleUrl: moduleUrl$2,
704
+ mappings: mappings$1
705
+ });
706
+
707
+ let Remind = Flow_GWT$ReventlessGwt.AutomationStep(RemindSlice)({
708
+ process: process$2,
709
+ onExhausted: onExhausted$3,
710
+ moduleUrl: moduleUrl$3,
711
+ mappings: mappings$2
712
+ });
379
713
 
380
714
  Flow_GWT$ReventlessGwt.describe("Order flow (single plugin)", () => {
381
- Flow_GWT$ReventlessGwt.test("place → auto-ship → ship → view Shipped → confirmation fired", undefined, () => Confirm.thenOutbound(View.thenViewState(Ship.thenEvents(Ship.whenCommand(Auto.thenIssuesCommand(Auto.whenReacts(Place.thenEvents(Place.whenCommand(Flow_GWT$ReventlessGwt.start, {
715
+ Flow_GWT$ReventlessGwt.test("place → auto-ship → ship → view Shipped → confirmation fired", "An order ships", undefined, undefined, () => Confirm.thenOutbound(View.thenRow(Ship.thenEvents(Ship.whenIssued(Auto.thenIssuesCommand(Auto.whenReacts(Place.thenEvents(Place.whenCommand(Flow_GWT$ReventlessGwt.start, undefined, {
382
716
  TAG: "PlaceOrder",
383
717
  orderId: "o1",
384
718
  item: "book"
@@ -386,13 +720,10 @@ Flow_GWT$ReventlessGwt.describe("Order flow (single plugin)", () => {
386
720
  TAG: "OrderPlaced",
387
721
  orderId: "o1",
388
722
  item: "book"
389
- }])), {
390
- TAG: "ShipOrder",
391
- orderId: "o1"
392
- }), {
723
+ }]), undefined), {
393
724
  TAG: "ShipOrder",
394
725
  orderId: "o1"
395
- }), [{
726
+ }), undefined, undefined), [{
396
727
  TAG: "OrderShipped",
397
728
  orderId: "o1"
398
729
  }]), "o1", {
@@ -405,24 +736,24 @@ Flow_GWT$ReventlessGwt.describe("Order flow (single plugin)", () => {
405
736
  orderId: "o1"
406
737
  }
407
738
  ]]));
408
- Flow_GWT$ReventlessGwt.test("automation does not re-issue ShipOrder once the order is shipped", undefined, () => Auto.thenIssuesNoCommand(Auto.whenReacts(Ship.whenCommand(Place.whenCommand(Flow_GWT$ReventlessGwt.start, {
739
+ Flow_GWT$ReventlessGwt.test("automation does not re-issue ShipOrder once the order is shipped", undefined, undefined, undefined, () => Auto.thenIssuesNoCommand(Auto.whenReacts(Ship.whenCommand(Place.whenCommand(Flow_GWT$ReventlessGwt.start, undefined, {
409
740
  TAG: "PlaceOrder",
410
741
  orderId: "o1",
411
742
  item: "book"
412
- }), {
743
+ }), undefined, {
413
744
  TAG: "ShipOrder",
414
745
  orderId: "o1"
415
- }))));
416
- Flow_GWT$ReventlessGwt.test("re-placing the same order is rejected", undefined, () => Place.thenError(Place.whenCommand(Place.whenCommand(Flow_GWT$ReventlessGwt.start, {
746
+ }), undefined)));
747
+ Flow_GWT$ReventlessGwt.test("re-placing the same order is rejected", undefined, undefined, undefined, () => Place.thenError(Place.whenCommand(Place.whenCommand(Flow_GWT$ReventlessGwt.start, undefined, {
417
748
  TAG: "PlaceOrder",
418
749
  orderId: "o1",
419
750
  item: "book"
420
- }), {
751
+ }), undefined, {
421
752
  TAG: "PlaceOrder",
422
753
  orderId: "o1",
423
754
  item: "book"
424
755
  }), "AlreadyPlaced"));
425
- Flow_GWT$ReventlessGwt.test("a second, different order is not blocked by the first (DCB tag isolation)", undefined, () => Place.thenEvent(Place.whenCommand(Place.thenEvent(Place.whenCommand(Flow_GWT$ReventlessGwt.start, {
756
+ Flow_GWT$ReventlessGwt.test("a second, different order is not blocked by the first (DCB tag isolation)", undefined, undefined, undefined, () => Place.thenEvent(Place.whenCommand(Place.thenEvent(Place.whenCommand(Flow_GWT$ReventlessGwt.start, undefined, {
426
757
  TAG: "PlaceOrder",
427
758
  orderId: "o1",
428
759
  item: "book"
@@ -430,7 +761,7 @@ Flow_GWT$ReventlessGwt.describe("Order flow (single plugin)", () => {
430
761
  TAG: "OrderPlaced",
431
762
  orderId: "o1",
432
763
  item: "book"
433
- }), {
764
+ }), undefined, {
434
765
  TAG: "PlaceOrder",
435
766
  orderId: "o2",
436
767
  item: "pen"
@@ -439,15 +770,15 @@ Flow_GWT$ReventlessGwt.describe("Order flow (single plugin)", () => {
439
770
  orderId: "o2",
440
771
  item: "pen"
441
772
  }));
442
- Flow_GWT$ReventlessGwt.test("shipping one order leaves a sibling order Placed", undefined, () => View.thenViewState(View.thenViewState(Ship.whenCommand(Place.whenCommand(Place.whenCommand(Flow_GWT$ReventlessGwt.start, {
773
+ Flow_GWT$ReventlessGwt.test("shipping one order leaves a sibling order Placed", undefined, undefined, undefined, () => View.thenRow(View.thenRow(Ship.whenCommand(Place.whenCommand(Place.whenCommand(Flow_GWT$ReventlessGwt.start, undefined, {
443
774
  TAG: "PlaceOrder",
444
775
  orderId: "o1",
445
776
  item: "book"
446
- }), {
777
+ }), undefined, {
447
778
  TAG: "PlaceOrder",
448
779
  orderId: "o2",
449
780
  item: "pen"
450
- }), {
781
+ }), undefined, {
451
782
  TAG: "ShipOrder",
452
783
  orderId: "o1"
453
784
  }), "o1", {
@@ -461,19 +792,413 @@ Flow_GWT$ReventlessGwt.describe("Order flow (single plugin)", () => {
461
792
  }));
462
793
  });
463
794
 
795
+ Flow_GWT$ReventlessGwt.describe("a flow that fails at its sixth step", () => {
796
+ let failed = async () => Flow_GWT$ReventlessGwt.outcomeOf(await Confirm.thenOutbound(View.thenRow(Ship.thenEvent(Ship.whenIssued(Auto.thenIssuesCommand(Auto.whenReacts(Place.thenEvents(Place.whenCommand(Flow_GWT$ReventlessGwt.start, undefined, {
797
+ TAG: "PlaceOrder",
798
+ orderId: "o1",
799
+ item: "book"
800
+ }), [{
801
+ TAG: "OrderPlaced",
802
+ orderId: "o1",
803
+ item: "book"
804
+ }]), undefined), {
805
+ TAG: "ShipOrder",
806
+ orderId: "o1"
807
+ }), undefined, undefined), {
808
+ TAG: "OrderShipped",
809
+ orderId: "o2"
810
+ }), "o1", {
811
+ orderId: "o1",
812
+ item: "book",
813
+ status: "Placed"
814
+ }), [[
815
+ "o1",
816
+ {
817
+ orderId: "o1"
818
+ }
819
+ ]]));
820
+ let mismatchOf = async () => {
821
+ let m = await failed();
822
+ if (m.TAG === "Ok") {
823
+ return Stdlib_JsError.throwWithMessage("the flow was meant to fail");
824
+ } else {
825
+ return m._0;
826
+ }
827
+ };
828
+ globalThis.test("the mismatch carries the step, not a later one", async () => {
829
+ let m = await mismatchOf();
830
+ globalThis.expect(Outcome$ReventlessGwt.stepOf(m)).toEqual({
831
+ number: 6,
832
+ total: 8,
833
+ verb: "thenEvent",
834
+ part: {
835
+ kind: "Decision",
836
+ name: "ShipOrder"
837
+ }
838
+ });
839
+ });
840
+ globalThis.test("the hint names the step and points at its part", async () => {
841
+ let hint = Hint$ReventlessGwt.forMismatch("Flow", await mismatchOf());
842
+ globalThis.expect(hint.locus).toBe("ShipOrder.decide");
843
+ globalThis.expect(Hint$ReventlessGwt.format(hint).startsWith("At step 6 of 8, ShipOrder.thenEvent.\n")).toBe(true);
844
+ });
845
+ globalThis.test("the JSON hint carries the step", async () => {
846
+ let json = Hint$ReventlessGwt.toJson(Hint$ReventlessGwt.forMismatch("Flow", await mismatchOf()));
847
+ globalThis.expect(JSON.stringify(json).includes(`"step":{"number":6,"total":8,"verb":"thenEvent","part":{"kind":"Decision","name":"ShipOrder"}}`)).toBe(true);
848
+ });
849
+ globalThis.test("jest's failure message says the step", async () => {
850
+ let outcome = await failed();
851
+ let message;
852
+ try {
853
+ JestBind$ReventlessGwt.assertOutcome("Flow", outcome);
854
+ message = "";
855
+ } catch (raw_e) {
856
+ let e = Primitive_exceptions.internalToException(raw_e);
857
+ if (e.RE_EXN_ID === "JsExn") {
858
+ message = Stdlib_Option.getOr(Stdlib_JsExn.message(e._1), "");
859
+ } else {
860
+ throw e;
861
+ }
862
+ }
863
+ globalThis.expect(message.includes("At step 6 of 8, ShipOrder.thenEvent.")).toBe(true);
864
+ });
865
+ globalThis.test("a flow that passes has no step to name", async () => {
866
+ let outcome = Flow_GWT$ReventlessGwt.outcomeOf(await Place.thenEvent(Place.whenCommand(Flow_GWT$ReventlessGwt.start, undefined, {
867
+ TAG: "PlaceOrder",
868
+ orderId: "o1",
869
+ item: "book"
870
+ }), {
871
+ TAG: "OrderPlaced",
872
+ orderId: "o1",
873
+ item: "book"
874
+ }));
875
+ globalThis.expect(outcome).toEqual(Outcome$ReventlessGwt.pass);
876
+ });
877
+ });
878
+
879
+ async function failureOf(flowP) {
880
+ let m = Flow_GWT$ReventlessGwt.outcomeOf(await flowP);
881
+ if (m.TAG === "Ok") {
882
+ return;
883
+ } else {
884
+ return m._0;
885
+ }
886
+ }
887
+
888
+ function placed() {
889
+ return Place.thenEvent(Place.whenCommand(Flow_GWT$ReventlessGwt.start, undefined, {
890
+ TAG: "PlaceOrder",
891
+ orderId: "o1",
892
+ item: "book"
893
+ }), {
894
+ TAG: "OrderPlaced",
895
+ orderId: "o1",
896
+ item: "book"
897
+ });
898
+ }
899
+
900
+ Flow_GWT$ReventlessGwt.describe("a command sent by one part and run by the next", () => {
901
+ globalThis.test("typed twice, each side to its own type, it passes", async () => {
902
+ let failure = await failureOf(Ship.thenEvent(Ship.whenCommand(AutoByOrder.thenIssuesCommand(AutoByOrder.whenReacts(placed(), undefined), {
903
+ TAG: "ShipOrder",
904
+ order: "o1"
905
+ }), undefined, {
906
+ TAG: "ShipOrder",
907
+ orderId: "o1"
908
+ }), {
909
+ TAG: "OrderShipped",
910
+ orderId: "o1"
911
+ }));
912
+ globalThis.expect(failure).toEqual(undefined);
913
+ });
914
+ globalThis.test("run as sent, the field the decision cannot read fails it", async () => {
915
+ let failure = await failureOf(Ship.thenEvent(Ship.whenIssued(AutoByOrder.thenIssuesCommand(AutoByOrder.whenReacts(placed(), undefined), {
916
+ TAG: "ShipOrder",
917
+ order: "o1"
918
+ }), undefined, undefined), {
919
+ TAG: "OrderShipped",
920
+ orderId: "o1"
921
+ }));
922
+ if (failure !== undefined && failure.TAG === "TranslateError") {
923
+ let reason = failure.actual;
924
+ if (reason !== undefined) {
925
+ globalThis.expect(reason.startsWith(`ShipOrder cannot read {"TAG":"ShipOrder","order":"o1"}`)).toBe(true);
926
+ globalThis.expect(Stdlib_Option.map(failure.step, s => s.verb)).toEqual("whenIssued");
927
+ return;
928
+ }
929
+ }
930
+ globalThis.expect(failure).toEqual(undefined);
931
+ });
932
+ globalThis.test("~only past what was sent fails, naming how many were", async () => {
933
+ let failure = await failureOf(Ship.whenIssued(Auto.whenReacts(placed(), undefined), 2, undefined));
934
+ if (failure !== undefined && failure.TAG === "TranslateError") {
935
+ let reason = failure.actual;
936
+ if (reason !== undefined) {
937
+ globalThis.expect(reason).toBe("~only=2, but 1 command(s) were sent");
938
+ return;
939
+ }
940
+ }
941
+ globalThis.expect(failure).toEqual(undefined);
942
+ });
943
+ globalThis.test("nothing sent is nothing to run", async () => {
944
+ let failure = await failureOf(Ship.whenIssued(Flow_GWT$ReventlessGwt.start, undefined, undefined));
945
+ if (failure !== undefined && failure.TAG === "TranslateError") {
946
+ let reason = failure.actual;
947
+ if (reason !== undefined) {
948
+ globalThis.expect(reason).toBe("the step before sent no command");
949
+ return;
950
+ }
951
+ }
952
+ globalThis.expect(failure).toEqual(undefined);
953
+ });
954
+ });
955
+
956
+ Flow_GWT$ReventlessGwt.describe("what a flow can expect besides whole events and rows", () => {
957
+ Flow_GWT$ReventlessGwt.test("a decision that records nothing", undefined, undefined, undefined, () => Ship.thenNoEvent(Ship.whenCommand(Ship.whenCommand(placed(), undefined, {
958
+ TAG: "ShipOrder",
959
+ orderId: "o1"
960
+ }), undefined, {
961
+ TAG: "ShipOrder",
962
+ orderId: "o1"
963
+ })));
964
+ Flow_GWT$ReventlessGwt.test("a decision that did not refuse, its events not compared", undefined, undefined, undefined, () => Ship.thenAccepted(Ship.whenCommand(placed(), undefined, {
965
+ TAG: "ShipOrder",
966
+ orderId: "o1"
967
+ })));
968
+ Flow_GWT$ReventlessGwt.test("no row for an order never placed", undefined, undefined, undefined, () => View.thenNoRow(placed(), "o9"));
969
+ Flow_GWT$ReventlessGwt.test("some fields of the row", undefined, undefined, undefined, () => View.thenRowShows(placed(), "o1", row => ({
970
+ status: row.status
971
+ }), {
972
+ status: "Placed"
973
+ }));
974
+ globalThis.test("a field picked and wrong fails, showing what was picked", async () => {
975
+ let failure = await failureOf(View.thenRowShows(placed(), "o1", row => ({
976
+ status: row.status
977
+ }), {
978
+ status: "Shipped"
979
+ }));
980
+ if (failure !== undefined) {
981
+ if (failure.TAG === "StateMismatch") {
982
+ globalThis.expect(failure.key).toBe("o1");
983
+ globalThis.expect(Stdlib_Option.map(failure.expected, j => JSON.stringify(j))).toEqual(`[{"status":"Shipped"}]`);
984
+ globalThis.expect(Stdlib_Option.map(failure.actual, j => JSON.stringify(j))).toEqual(`[{"status":"Placed"}]`);
985
+ return;
986
+ }
987
+ globalThis.expect(failure).toEqual(undefined);
988
+ return;
989
+ }
990
+ globalThis.expect(failure).toEqual(undefined);
991
+ });
992
+ globalThis.test("thenAccepted fails on a refusal", async () => {
993
+ let failure = await failureOf(Ship.thenAccepted(Ship.whenCommand(Flow_GWT$ReventlessGwt.start, undefined, {
994
+ TAG: "ShipOrder",
995
+ orderId: "o1"
996
+ })));
997
+ globalThis.expect(Stdlib_Option.map(failure, Outcome$ReventlessGwt.kindName)).toEqual("ErrorMismatch");
998
+ });
999
+ });
1000
+
1001
+ function placedAtNine() {
1002
+ return Place.whenCommand(Flow_GWT$ReventlessGwt.start, "2026-03-02T09:00:00Z", {
1003
+ TAG: "PlaceOrder",
1004
+ orderId: "o1",
1005
+ item: "book"
1006
+ });
1007
+ }
1008
+
1009
+ Flow_GWT$ReventlessGwt.describe("a flow keeps time", () => {
1010
+ Flow_GWT$ReventlessGwt.test("a schedule an event set fires an hour later, and not before", undefined, undefined, undefined, () => Remind.thenIssuesNoCommand(Remind.whenTimePasses(Remind.thenIssuesCommand(Remind.whenTimePasses(Remind.thenIssuesNoCommand(Remind.whenTimePasses(placedAtNine(), "2026-03-02T09:59:00Z")), "2026-03-02T10:00:00Z"), {
1011
+ TAG: "RemindCustomer",
1012
+ orderId: "o1"
1013
+ }), "2026-03-03T10:00:00Z")));
1014
+ Flow_GWT$ReventlessGwt.test("an event that clears the schedule before it is due stops it", undefined, undefined, undefined, () => Remind.thenIssuesNoCommand(Remind.whenTimePasses(Ship.whenCommand(placedAtNine(), "2026-03-02T09:30:00Z", {
1015
+ TAG: "ShipOrder",
1016
+ orderId: "o1"
1017
+ }), "2026-03-02T11:00:00Z")));
1018
+ globalThis.test("time only moves forward", async () => {
1019
+ let failure = await failureOf(Ship.whenCommand(placedAtNine(), "2026-03-02T08:00:00Z", {
1020
+ TAG: "ShipOrder",
1021
+ orderId: "o1"
1022
+ }));
1023
+ if (failure !== undefined) {
1024
+ if (failure.TAG === "Throw") {
1025
+ globalThis.expect(failure.error).toBe(`~at="2026-03-02T08:00:00Z" is before the flow's time, 2026-03-02T09:00:00Z: time only moves forward`);
1026
+ globalThis.expect(Stdlib_Option.map(failure.step, s => s.number)).toEqual(2);
1027
+ return;
1028
+ }
1029
+ globalThis.expect(failure).toEqual(undefined);
1030
+ return;
1031
+ }
1032
+ globalThis.expect(failure).toEqual(undefined);
1033
+ });
1034
+ });
1035
+
1036
+ Flow_GWT$ReventlessGwt.describe("a flow's caller", () => {
1037
+ Flow_GWT$ReventlessGwt.test("a signed-out caller reads no row of a view that wants a signed-in one", undefined, undefined, undefined, () => View.thenNoRow(Flow_GWT$ReventlessGwt.asCaller(placed(), Decision_GWT$ReventlessGwt.Caller.anonymous), "o1"));
1038
+ globalThis.test("a signed-in caller reads the row", async () => {
1039
+ let failure = await failureOf(View.thenNoRow(Flow_GWT$ReventlessGwt.asCaller(placed(), Decision_GWT$ReventlessGwt.Caller.owner("c1", undefined)), "o1"));
1040
+ globalThis.expect(Stdlib_Option.map(failure, Outcome$ReventlessGwt.kindName)).toEqual("StateMismatch");
1041
+ });
1042
+ Flow_GWT$ReventlessGwt.test("a signed-out caller's command is refused before its decision runs", undefined, undefined, undefined, () => View.thenNoRow(Place.thenForbidden(Place.whenCommand(Flow_GWT$ReventlessGwt.asCaller(Flow_GWT$ReventlessGwt.start, Decision_GWT$ReventlessGwt.Caller.anonymous), undefined, {
1043
+ TAG: "PlaceOrder",
1044
+ orderId: "o1",
1045
+ item: "book"
1046
+ })), "o1"));
1047
+ globalThis.test("thenForbidden fails when the command was decided", async () => {
1048
+ let failure = await failureOf(Place.thenForbidden(Place.whenCommand(Flow_GWT$ReventlessGwt.asCaller(Flow_GWT$ReventlessGwt.start, Decision_GWT$ReventlessGwt.Caller.owner("c1", undefined)), undefined, {
1049
+ TAG: "PlaceOrder",
1050
+ orderId: "o1",
1051
+ item: "book"
1052
+ })));
1053
+ globalThis.expect(Stdlib_Option.map(failure, Outcome$ReventlessGwt.kindName)).toEqual("ErrorMismatch");
1054
+ });
1055
+ });
1056
+
1057
+ let orderParts_reacting = [
1058
+ Auto.reacting,
1059
+ AutoByOrder.reacting
1060
+ ];
1061
+
1062
+ let orderParts_deciding = [
1063
+ Place.deciding,
1064
+ Ship.deciding
1065
+ ];
1066
+
1067
+ let orderParts = {
1068
+ reacting: orderParts_reacting,
1069
+ deciding: orderParts_deciding
1070
+ };
1071
+
1072
+ let shippingParts_reacting = [Auto.reacting];
1073
+
1074
+ let shippingParts_deciding = [
1075
+ Place.deciding,
1076
+ Ship.deciding
1077
+ ];
1078
+
1079
+ let shippingParts = {
1080
+ reacting: shippingParts_reacting,
1081
+ deciding: shippingParts_deciding
1082
+ };
1083
+
1084
+ Flow_GWT$ReventlessGwt.describe("a reaction step called twice", () => Flow_GWT$ReventlessGwt.test("reports only what is new since that automation's last step", undefined, undefined, undefined, () => Auto.thenIssuesNoCommand(Auto.whenReacts(Auto.thenIssuesCommand(Auto.whenReacts(placed(), undefined), {
1085
+ TAG: "ShipOrder",
1086
+ orderId: "o1"
1087
+ }), undefined))));
1088
+
1089
+ Flow_GWT$ReventlessGwt.describe("nothing else reacts", () => {
1090
+ globalThis.test("an automation the flow did not name, that would send, fails it", async () => {
1091
+ let failure = await failureOf(Flow_GWT$ReventlessGwt.thenNothingElseReacts(Auto.thenIssuesCommand(Auto.whenReacts(placed(), undefined), {
1092
+ TAG: "ShipOrder",
1093
+ orderId: "o1"
1094
+ }), [orderParts]));
1095
+ if (failure !== undefined) {
1096
+ if (failure.TAG === "PublishedActionsMismatch") {
1097
+ globalThis.expect(failure.actual.map(j => JSON.stringify(j))).toEqual([`{"reacts":"AutoShipByOrder","sends":{"TAG":"ShipOrder","order":"o1"}}`]);
1098
+ return;
1099
+ }
1100
+ globalThis.expect(failure).toEqual(undefined);
1101
+ return;
1102
+ }
1103
+ globalThis.expect(failure).toEqual(undefined);
1104
+ });
1105
+ Flow_GWT$ReventlessGwt.test("with both named, nothing else reacts", undefined, undefined, undefined, () => Flow_GWT$ReventlessGwt.thenNothingElseReacts(AutoByOrder.thenIssuesCommand(AutoByOrder.whenReacts(Auto.thenIssuesCommand(Auto.whenReacts(placed(), undefined), {
1106
+ TAG: "ShipOrder",
1107
+ orderId: "o1"
1108
+ }), undefined), {
1109
+ TAG: "ShipOrder",
1110
+ order: "o1"
1111
+ }), [orderParts]));
1112
+ });
1113
+
1114
+ Flow_GWT$ReventlessGwt.describe("the app does the rest", () => {
1115
+ Flow_GWT$ReventlessGwt.test("the automation ships the order and the decision records it", undefined, undefined, undefined, () => Flow_GWT$ReventlessGwt.thenNothingElseReacts(View.thenRow(Flow_GWT$ReventlessGwt.whenSettled(placed(), [shippingParts]), "o1", {
1116
+ orderId: "o1",
1117
+ item: "book",
1118
+ status: "Shipped"
1119
+ }), [shippingParts]));
1120
+ globalThis.test("a command no decision reads stops it, named", async () => {
1121
+ let failure = await failureOf(Flow_GWT$ReventlessGwt.whenSettled(placed(), [orderParts]));
1122
+ if (failure !== undefined && failure.TAG === "TranslateError") {
1123
+ let reason = failure.actual;
1124
+ if (reason !== undefined) {
1125
+ globalThis.expect(reason).toBe(`no decision reads {"TAG":"ShipOrder","order":"o1"}`);
1126
+ return;
1127
+ }
1128
+ }
1129
+ globalThis.expect(failure).toEqual(undefined);
1130
+ });
1131
+ });
1132
+
1133
+ Flow_GWT$ReventlessGwt.describe("a flow that starts after another", () => {
1134
+ Flow_GWT$ReventlessGwt.test("an order is placed", undefined, undefined, undefined, () => placed());
1135
+ Flow_GWT$ReventlessGwt.test("it is shipped, on the record the placing left", undefined, undefined, undefined, () => Ship.thenEvent(Ship.whenCommand(Flow_GWT$ReventlessGwt.after("an order is placed"), undefined, {
1136
+ TAG: "ShipOrder",
1137
+ orderId: "o1"
1138
+ }), {
1139
+ TAG: "OrderShipped",
1140
+ orderId: "o1"
1141
+ }));
1142
+ Flow_GWT$ReventlessGwt.flows["an order placed twice"] = () => Place.thenEvent(Place.whenCommand(placed(), undefined, {
1143
+ TAG: "PlaceOrder",
1144
+ orderId: "o1",
1145
+ item: "book"
1146
+ }), {
1147
+ TAG: "OrderPlaced",
1148
+ orderId: "o1",
1149
+ item: "book"
1150
+ });
1151
+ globalThis.test("after a failing flow, it is not run, and says so", async () => {
1152
+ let failure = await failureOf(Ship.thenEvent(Ship.whenCommand(Flow_GWT$ReventlessGwt.after("an order placed twice"), undefined, {
1153
+ TAG: "ShipOrder",
1154
+ orderId: "o1"
1155
+ }), {
1156
+ TAG: "OrderShipped",
1157
+ orderId: "o1"
1158
+ }));
1159
+ if (failure !== undefined) {
1160
+ if (failure.TAG === "Throw") {
1161
+ globalThis.expect(failure.error).toBe(`not run: the flow it starts after, "an order placed twice", failed`);
1162
+ globalThis.expect(failure.step).toEqual(undefined);
1163
+ return;
1164
+ }
1165
+ globalThis.expect(failure).toEqual(undefined);
1166
+ return;
1167
+ }
1168
+ globalThis.expect(failure).toEqual(undefined);
1169
+ });
1170
+ globalThis.test("after a title no flow has, it is not run", async () => {
1171
+ let failure = await failureOf(Flow_GWT$ReventlessGwt.after("no such flow"));
1172
+ globalThis.expect(Stdlib_Option.map(failure, Outcome$ReventlessGwt.kindName)).toEqual("Throw");
1173
+ });
1174
+ });
1175
+
464
1176
  export {
465
1177
  PlaceOrderSlice,
466
1178
  PlaceOrderDecision,
467
1179
  AutoShipSlice,
1180
+ AutoShipAutomation,
468
1181
  ShipOrderSlice,
469
1182
  ShipOrderDecision,
470
1183
  OrdersViewSlice,
471
1184
  OrdersViewProjection,
472
1185
  ConfirmSlice,
1186
+ ConfirmTranslation,
1187
+ AutoShipByOrderSlice,
1188
+ AutoShipByOrderAutomation,
1189
+ RemindSlice,
1190
+ RemindAutomation,
473
1191
  Place,
474
1192
  Auto,
475
1193
  Ship,
476
1194
  View,
477
1195
  Confirm,
1196
+ AutoByOrder,
1197
+ Remind,
1198
+ failureOf,
1199
+ placed,
1200
+ placedAtNine,
1201
+ orderParts,
1202
+ shippingParts,
478
1203
  }
479
1204
  /* consumedEventSchema Not a pure module */