@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.
- package/CHANGELOG.md +10 -0
- package/package.json +5 -5
- package/src/Boundary_GWT.res +57 -0
- package/src/Boundary_GWT.res.mjs +56 -0
- package/src/Decision_GWT.res +28 -0
- package/src/Decision_GWT.res.mjs +42 -2
- package/src/Flow_GWT.res +1176 -381
- package/src/Flow_GWT.res.mjs +1678 -339
- package/src/Hint.res +41 -5
- package/src/Hint.res.mjs +43 -5
- package/src/Outcome.res +90 -12
- package/src/Outcome.res.mjs +47 -0
- package/src/Projection_GWT.res +56 -5
- package/src/Projection_GWT.res.mjs +33 -7
- package/src/Query_GWT.res +39 -0
- package/src/Query_GWT.res.mjs +22 -14
- package/tests/BoundaryGwtTest.res +73 -0
- package/tests/BoundaryGwtTest.res.mjs +128 -0
- package/tests/FlowAggregateGwtTest.res +3 -3
- package/tests/FlowAggregateGwtTest.res.mjs +17 -17
- package/tests/FlowCrossPluginGwtTest.res +14 -12
- package/tests/FlowCrossPluginGwtTest.res.mjs +26 -28
- package/tests/FlowGwtTest.res +562 -34
- package/tests/FlowGwtTest.res.mjs +794 -69
- package/tests/HintTest.res.mjs +2 -1
- package/tests/QueryGwtTest.res +48 -0
- package/tests/QueryGwtTest.res.mjs +75 -0
- package/tests/StateViewSliceGwtTest.res.mjs +14 -1
package/src/Flow_GWT.res.mjs
CHANGED
|
@@ -1,23 +1,95 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
+
import * as S from "sury/src/S.res.mjs";
|
|
3
4
|
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
4
5
|
import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
|
|
5
6
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
7
|
+
import * as Stdlib_Result from "@rescript/runtime/lib/es6/Stdlib_Result.js";
|
|
8
|
+
import * as Primitive_float from "@rescript/runtime/lib/es6/Primitive_float.js";
|
|
6
9
|
import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.js";
|
|
7
10
|
import * as Primitive_string from "@rescript/runtime/lib/es6/Primitive_string.js";
|
|
8
11
|
import * as DcbTag$Reventless from "@reventlessdev/reventless-spec/src/components/DcbTag.res.mjs";
|
|
9
12
|
import * as Message$Reventless from "@reventlessdev/reventless-spec/src/types/Message.res.mjs";
|
|
10
13
|
import * as DcbDecode$Reventless from "@reventlessdev/reventless-spec/src/components/DcbDecode.res.mjs";
|
|
11
14
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
15
|
+
import * as Util_Sury$Reventless from "@reventlessdev/reventless-spec/src/util/Util_Sury.res.mjs";
|
|
12
16
|
import * as Outcome$ReventlessGwt from "./Outcome.res.mjs";
|
|
13
17
|
import * as JestBind$ReventlessGwt from "./JestBind.res.mjs";
|
|
14
18
|
import * as Message$ReventlessCore from "@reventlessdev/reventless-core/src/Message.res.mjs";
|
|
15
|
-
import * as
|
|
19
|
+
import * as Query_GWT$ReventlessGwt from "./Query_GWT.res.mjs";
|
|
20
|
+
import * as CommandOutcome$Reventless from "@reventlessdev/reventless-spec/src/components/CommandOutcome.res.mjs";
|
|
16
21
|
import * as StubRuntime$ReventlessGwt from "./StubRuntime.res.mjs";
|
|
22
|
+
import * as Decision_GWT$ReventlessGwt from "./Decision_GWT.res.mjs";
|
|
23
|
+
import * as ScheduleTime$ReventlessCore from "@reventlessdev/reventless-core/src/util/ScheduleTime.res.mjs";
|
|
17
24
|
import * as Automation_GWT$ReventlessGwt from "./Automation_GWT.res.mjs";
|
|
18
25
|
import * as DcbScopeInference$Reventless from "@reventlessdev/reventless-spec/src/components/DcbScopeInference.res.mjs";
|
|
19
26
|
import * as Projection_GWT$ReventlessGwt from "./Projection_GWT.res.mjs";
|
|
27
|
+
import * as SideEffect_GWT$ReventlessGwt from "./SideEffect_GWT.res.mjs";
|
|
28
|
+
import * as Capabilities_Fake$ReventlessGwt from "./Capabilities_Fake.res.mjs";
|
|
20
29
|
import * as InboundTranslation_GWT$ReventlessGwt from "./InboundTranslation_GWT.res.mjs";
|
|
30
|
+
import * as AutomationSlice_Schedules$ReventlessCore from "@reventlessdev/reventless-core/src/components/AutomationSlice/AutomationSlice_Schedules.res.mjs";
|
|
31
|
+
|
|
32
|
+
function sourceIdOf(entry) {
|
|
33
|
+
return entry.id;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function handledBy(s, key) {
|
|
37
|
+
return Stdlib_Option.getOr(s.handled[key], []);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function markHandled(s, key, ids) {
|
|
41
|
+
let handled = Object.assign({}, s.handled);
|
|
42
|
+
handled[key] = handledBy(s, key).concat(ids);
|
|
43
|
+
return {
|
|
44
|
+
log: s.log,
|
|
45
|
+
outcome: s.outcome,
|
|
46
|
+
lastEvents: s.lastEvents,
|
|
47
|
+
lastError: s.lastError,
|
|
48
|
+
lastCommands: s.lastCommands,
|
|
49
|
+
lastPublic: s.lastPublic,
|
|
50
|
+
lastIds: s.lastIds,
|
|
51
|
+
lastRefusal: s.lastRefusal,
|
|
52
|
+
steps: s.steps,
|
|
53
|
+
at: s.at,
|
|
54
|
+
failedAt: s.failedAt,
|
|
55
|
+
now: s.now,
|
|
56
|
+
caller: s.caller,
|
|
57
|
+
lastForbidden: s.lastForbidden,
|
|
58
|
+
handled: handled,
|
|
59
|
+
named: s.named,
|
|
60
|
+
lastSent: s.lastSent,
|
|
61
|
+
lastRows: s.lastRows,
|
|
62
|
+
lastCalls: s.lastCalls
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function markNamed(s, key) {
|
|
67
|
+
if (s.named.includes(key)) {
|
|
68
|
+
return s;
|
|
69
|
+
} else {
|
|
70
|
+
return {
|
|
71
|
+
log: s.log,
|
|
72
|
+
outcome: s.outcome,
|
|
73
|
+
lastEvents: s.lastEvents,
|
|
74
|
+
lastError: s.lastError,
|
|
75
|
+
lastCommands: s.lastCommands,
|
|
76
|
+
lastPublic: s.lastPublic,
|
|
77
|
+
lastIds: s.lastIds,
|
|
78
|
+
lastRefusal: s.lastRefusal,
|
|
79
|
+
steps: s.steps,
|
|
80
|
+
at: s.at,
|
|
81
|
+
failedAt: s.failedAt,
|
|
82
|
+
now: s.now,
|
|
83
|
+
caller: s.caller,
|
|
84
|
+
lastForbidden: s.lastForbidden,
|
|
85
|
+
handled: s.handled,
|
|
86
|
+
named: s.named.concat([key]),
|
|
87
|
+
lastSent: s.lastSent,
|
|
88
|
+
lastRows: s.lastRows,
|
|
89
|
+
lastCalls: s.lastCalls
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
21
93
|
|
|
22
94
|
let emptyState_log = [];
|
|
23
95
|
|
|
@@ -27,6 +99,18 @@ let emptyState_lastCommands = [];
|
|
|
27
99
|
|
|
28
100
|
let emptyState_lastPublic = [];
|
|
29
101
|
|
|
102
|
+
let emptyState_lastIds = [];
|
|
103
|
+
|
|
104
|
+
let emptyState_handled = {};
|
|
105
|
+
|
|
106
|
+
let emptyState_named = [];
|
|
107
|
+
|
|
108
|
+
let emptyState_lastSent = [];
|
|
109
|
+
|
|
110
|
+
let emptyState_lastRows = [];
|
|
111
|
+
|
|
112
|
+
let emptyState_lastCalls = [];
|
|
113
|
+
|
|
30
114
|
let emptyState = {
|
|
31
115
|
log: emptyState_log,
|
|
32
116
|
outcome: Outcome$ReventlessGwt.pass,
|
|
@@ -34,15 +118,26 @@ let emptyState = {
|
|
|
34
118
|
lastError: undefined,
|
|
35
119
|
lastCommands: emptyState_lastCommands,
|
|
36
120
|
lastPublic: emptyState_lastPublic,
|
|
37
|
-
|
|
38
|
-
lastRefusal: undefined
|
|
121
|
+
lastIds: emptyState_lastIds,
|
|
122
|
+
lastRefusal: undefined,
|
|
123
|
+
steps: 0,
|
|
124
|
+
at: undefined,
|
|
125
|
+
failedAt: undefined,
|
|
126
|
+
now: 0.0,
|
|
127
|
+
caller: undefined,
|
|
128
|
+
lastForbidden: false,
|
|
129
|
+
handled: emptyState_handled,
|
|
130
|
+
named: emptyState_named,
|
|
131
|
+
lastSent: emptyState_lastSent,
|
|
132
|
+
lastRows: emptyState_lastRows,
|
|
133
|
+
lastCalls: emptyState_lastCalls
|
|
39
134
|
};
|
|
40
135
|
|
|
41
136
|
let start = Promise.resolve(emptyState);
|
|
42
137
|
|
|
43
138
|
function recordOutcome(s, o) {
|
|
44
139
|
let match = s.outcome;
|
|
45
|
-
if (match.TAG === "Ok") {
|
|
140
|
+
if (match.TAG === "Ok" && o.TAG !== "Ok") {
|
|
46
141
|
return {
|
|
47
142
|
log: s.log,
|
|
48
143
|
outcome: o,
|
|
@@ -50,14 +145,117 @@ function recordOutcome(s, o) {
|
|
|
50
145
|
lastError: s.lastError,
|
|
51
146
|
lastCommands: s.lastCommands,
|
|
52
147
|
lastPublic: s.lastPublic,
|
|
53
|
-
|
|
54
|
-
lastRefusal: s.lastRefusal
|
|
148
|
+
lastIds: s.lastIds,
|
|
149
|
+
lastRefusal: s.lastRefusal,
|
|
150
|
+
steps: s.steps,
|
|
151
|
+
at: s.at,
|
|
152
|
+
failedAt: s.at,
|
|
153
|
+
now: s.now,
|
|
154
|
+
caller: s.caller,
|
|
155
|
+
lastForbidden: s.lastForbidden,
|
|
156
|
+
handled: s.handled,
|
|
157
|
+
named: s.named,
|
|
158
|
+
lastSent: s.lastSent,
|
|
159
|
+
lastRows: s.lastRows,
|
|
160
|
+
lastCalls: s.lastCalls
|
|
55
161
|
};
|
|
56
162
|
} else {
|
|
57
163
|
return s;
|
|
58
164
|
}
|
|
59
165
|
}
|
|
60
166
|
|
|
167
|
+
function iso(millis) {
|
|
168
|
+
return new Date(millis).toISOString().replace(".000Z", "Z");
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
async function enter(flowP, verb, part, at) {
|
|
172
|
+
let s = await flowP;
|
|
173
|
+
let number = s.steps + 1 | 0;
|
|
174
|
+
let s_log = s.log;
|
|
175
|
+
let s_outcome = s.outcome;
|
|
176
|
+
let s_lastEvents = s.lastEvents;
|
|
177
|
+
let s_lastError = s.lastError;
|
|
178
|
+
let s_lastCommands = s.lastCommands;
|
|
179
|
+
let s_lastPublic = s.lastPublic;
|
|
180
|
+
let s_lastIds = s.lastIds;
|
|
181
|
+
let s_lastRefusal = s.lastRefusal;
|
|
182
|
+
let s_at = {
|
|
183
|
+
number: number,
|
|
184
|
+
total: 0,
|
|
185
|
+
verb: verb,
|
|
186
|
+
part: part
|
|
187
|
+
};
|
|
188
|
+
let s_failedAt = s.failedAt;
|
|
189
|
+
let s_now = s.now;
|
|
190
|
+
let s_caller = s.caller;
|
|
191
|
+
let s_lastForbidden = s.lastForbidden;
|
|
192
|
+
let s_handled = s.handled;
|
|
193
|
+
let s_named = s.named;
|
|
194
|
+
let s_lastSent = s.lastSent;
|
|
195
|
+
let s_lastRows = s.lastRows;
|
|
196
|
+
let s_lastCalls = s.lastCalls;
|
|
197
|
+
let s$1 = {
|
|
198
|
+
log: s_log,
|
|
199
|
+
outcome: s_outcome,
|
|
200
|
+
lastEvents: s_lastEvents,
|
|
201
|
+
lastError: s_lastError,
|
|
202
|
+
lastCommands: s_lastCommands,
|
|
203
|
+
lastPublic: s_lastPublic,
|
|
204
|
+
lastIds: s_lastIds,
|
|
205
|
+
lastRefusal: s_lastRefusal,
|
|
206
|
+
steps: number,
|
|
207
|
+
at: s_at,
|
|
208
|
+
failedAt: s_failedAt,
|
|
209
|
+
now: s_now,
|
|
210
|
+
caller: s_caller,
|
|
211
|
+
lastForbidden: s_lastForbidden,
|
|
212
|
+
handled: s_handled,
|
|
213
|
+
named: s_named,
|
|
214
|
+
lastSent: s_lastSent,
|
|
215
|
+
lastRows: s_lastRows,
|
|
216
|
+
lastCalls: s_lastCalls
|
|
217
|
+
};
|
|
218
|
+
if (at === undefined) {
|
|
219
|
+
return s$1;
|
|
220
|
+
}
|
|
221
|
+
let millis = new Date(at).getTime();
|
|
222
|
+
if (Number.isNaN(millis)) {
|
|
223
|
+
return recordOutcome(s$1, Outcome$ReventlessGwt.fail({
|
|
224
|
+
TAG: "Throw",
|
|
225
|
+
error: `~at="` + at + `" is not an instant`,
|
|
226
|
+
stack: ""
|
|
227
|
+
}));
|
|
228
|
+
} else if (millis < s_now) {
|
|
229
|
+
return recordOutcome(s$1, Outcome$ReventlessGwt.fail({
|
|
230
|
+
TAG: "Throw",
|
|
231
|
+
error: `~at="` + at + `" is before the flow's time, ` + iso(s_now) + `: time only moves forward`,
|
|
232
|
+
stack: ""
|
|
233
|
+
}));
|
|
234
|
+
} else {
|
|
235
|
+
return {
|
|
236
|
+
log: s_log,
|
|
237
|
+
outcome: s_outcome,
|
|
238
|
+
lastEvents: s_lastEvents,
|
|
239
|
+
lastError: s_lastError,
|
|
240
|
+
lastCommands: s_lastCommands,
|
|
241
|
+
lastPublic: s_lastPublic,
|
|
242
|
+
lastIds: s_lastIds,
|
|
243
|
+
lastRefusal: s_lastRefusal,
|
|
244
|
+
steps: number,
|
|
245
|
+
at: s_at,
|
|
246
|
+
failedAt: s_failedAt,
|
|
247
|
+
now: millis,
|
|
248
|
+
caller: s_caller,
|
|
249
|
+
lastForbidden: s_lastForbidden,
|
|
250
|
+
handled: s_handled,
|
|
251
|
+
named: s_named,
|
|
252
|
+
lastSent: s_lastSent,
|
|
253
|
+
lastRows: s_lastRows,
|
|
254
|
+
lastCalls: s_lastCalls
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
61
259
|
function entryMatchesQuery(entry, query) {
|
|
62
260
|
if (query.length === 0) {
|
|
63
261
|
return true;
|
|
@@ -82,28 +280,34 @@ function entryMatchesQuery(entry, query) {
|
|
|
82
280
|
}
|
|
83
281
|
}
|
|
84
282
|
|
|
85
|
-
function
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
283
|
+
function entryOf(ev, schema, at, aggregateId, id, tagKeys) {
|
|
284
|
+
let json = Message$ReventlessCore.encode(ev, schema);
|
|
285
|
+
let eventType = Message$Reventless.variantNameOfJson(json);
|
|
286
|
+
let tags = DcbTag$Reventless.extractTagsExpanded(schema, ev);
|
|
287
|
+
let keys = Stdlib_Option.flatMap(tagKeys, keys => keys[eventType]);
|
|
288
|
+
let indexed = keys !== undefined ? tags.filter(t => keys.includes(t.key)) : tags;
|
|
289
|
+
return {
|
|
290
|
+
eventType: eventType,
|
|
291
|
+
tags: tags,
|
|
292
|
+
json: json,
|
|
293
|
+
aggregateId: aggregateId,
|
|
294
|
+
at: at,
|
|
295
|
+
id: id !== undefined ? id : (
|
|
296
|
+
aggregateId !== undefined ? aggregateId : Stdlib_Option.mapOr(indexed[0], "", t => t.value)
|
|
297
|
+
)
|
|
298
|
+
};
|
|
95
299
|
}
|
|
96
300
|
|
|
97
|
-
function
|
|
98
|
-
return log.concat(events.map(ev =>
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
301
|
+
function appendEvents(log, at, tagKeys, events, schema) {
|
|
302
|
+
return log.concat(events.map(ev => entryOf(ev, schema, at, undefined, undefined, tagKeys)));
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function appendAggregateEvents(log, id, at, events, schema) {
|
|
306
|
+
return log.concat(events.map(ev => entryOf(ev, schema, at, id, undefined, undefined)));
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function lastIdsOf(log, n) {
|
|
310
|
+
return log.slice(log.length - n | 0).map(e => e.id);
|
|
107
311
|
}
|
|
108
312
|
|
|
109
313
|
function decodeMatching(log, decoder, query) {
|
|
@@ -134,59 +338,384 @@ function decodeAggregateMatching(log, id, decoder) {
|
|
|
134
338
|
});
|
|
135
339
|
}
|
|
136
340
|
|
|
137
|
-
function
|
|
138
|
-
|
|
341
|
+
function outcomeOf(s) {
|
|
342
|
+
let match = s.outcome;
|
|
343
|
+
let match$1 = s.failedAt;
|
|
344
|
+
if (match.TAG === "Ok") {
|
|
345
|
+
return match;
|
|
346
|
+
}
|
|
347
|
+
if (match$1 === undefined) {
|
|
348
|
+
return match;
|
|
349
|
+
}
|
|
350
|
+
let newrecord = {...match$1};
|
|
351
|
+
return {
|
|
352
|
+
TAG: "Error",
|
|
353
|
+
_0: Outcome$ReventlessGwt.atStep(match._0, (newrecord.total = s.steps, newrecord))
|
|
354
|
+
};
|
|
139
355
|
}
|
|
140
356
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
let
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
357
|
+
let elevated = {
|
|
358
|
+
contents: []
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
let flows = {};
|
|
362
|
+
|
|
363
|
+
function test(name, param, groupsOpt, timeout, body) {
|
|
364
|
+
let groups = groupsOpt !== undefined ? groupsOpt : [];
|
|
365
|
+
flows[name] = body;
|
|
366
|
+
JestBind$ReventlessGwt.testPromise("Flow", name, timeout, async () => {
|
|
367
|
+
elevated.contents = groups;
|
|
368
|
+
let outcome = outcomeOf(await body());
|
|
369
|
+
elevated.contents = [];
|
|
370
|
+
return outcome;
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
async function after(title) {
|
|
375
|
+
let notRun = why => ({
|
|
376
|
+
log: emptyState_log,
|
|
377
|
+
outcome: Outcome$ReventlessGwt.fail({
|
|
378
|
+
TAG: "Throw",
|
|
379
|
+
error: why,
|
|
380
|
+
stack: ""
|
|
381
|
+
}),
|
|
382
|
+
lastEvents: emptyState_lastEvents,
|
|
383
|
+
lastError: undefined,
|
|
384
|
+
lastCommands: emptyState_lastCommands,
|
|
385
|
+
lastPublic: emptyState_lastPublic,
|
|
386
|
+
lastIds: emptyState_lastIds,
|
|
387
|
+
lastRefusal: undefined,
|
|
388
|
+
steps: 0,
|
|
389
|
+
at: undefined,
|
|
390
|
+
failedAt: undefined,
|
|
391
|
+
now: 0.0,
|
|
392
|
+
caller: undefined,
|
|
393
|
+
lastForbidden: false,
|
|
394
|
+
handled: emptyState_handled,
|
|
395
|
+
named: emptyState_named,
|
|
396
|
+
lastSent: emptyState_lastSent,
|
|
397
|
+
lastRows: emptyState_lastRows,
|
|
398
|
+
lastCalls: emptyState_lastCalls
|
|
399
|
+
});
|
|
400
|
+
let body = flows[title];
|
|
401
|
+
if (body === undefined) {
|
|
402
|
+
return notRun(`after("` + title + `"): no flow of that title in this file`);
|
|
403
|
+
}
|
|
404
|
+
let before = await body();
|
|
405
|
+
let match = outcomeOf(before);
|
|
406
|
+
if (match.TAG === "Ok") {
|
|
407
|
+
return {
|
|
408
|
+
log: before.log,
|
|
409
|
+
outcome: Outcome$ReventlessGwt.pass,
|
|
410
|
+
lastEvents: emptyState_lastEvents,
|
|
411
|
+
lastError: undefined,
|
|
412
|
+
lastCommands: emptyState_lastCommands,
|
|
413
|
+
lastPublic: emptyState_lastPublic,
|
|
414
|
+
lastIds: emptyState_lastIds,
|
|
415
|
+
lastRefusal: undefined,
|
|
416
|
+
steps: 0,
|
|
417
|
+
at: undefined,
|
|
418
|
+
failedAt: undefined,
|
|
419
|
+
now: before.now,
|
|
420
|
+
caller: undefined,
|
|
421
|
+
lastForbidden: false,
|
|
422
|
+
handled: before.handled,
|
|
423
|
+
named: emptyState_named,
|
|
424
|
+
lastSent: emptyState_lastSent,
|
|
425
|
+
lastRows: emptyState_lastRows,
|
|
426
|
+
lastCalls: emptyState_lastCalls
|
|
427
|
+
};
|
|
428
|
+
} else {
|
|
429
|
+
return notRun(`not run: the flow it starts after, "` + title + `", failed`);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
async function asCaller(flowP, who) {
|
|
434
|
+
let init = await enter(flowP, "asCaller", undefined, undefined);
|
|
435
|
+
return {
|
|
436
|
+
log: init.log,
|
|
437
|
+
outcome: init.outcome,
|
|
438
|
+
lastEvents: init.lastEvents,
|
|
439
|
+
lastError: init.lastError,
|
|
440
|
+
lastCommands: init.lastCommands,
|
|
441
|
+
lastPublic: init.lastPublic,
|
|
442
|
+
lastIds: init.lastIds,
|
|
443
|
+
lastRefusal: init.lastRefusal,
|
|
444
|
+
steps: init.steps,
|
|
445
|
+
at: init.at,
|
|
446
|
+
failedAt: init.failedAt,
|
|
447
|
+
now: init.now,
|
|
448
|
+
caller: who,
|
|
449
|
+
lastForbidden: init.lastForbidden,
|
|
450
|
+
handled: init.handled,
|
|
451
|
+
named: init.named,
|
|
452
|
+
lastSent: init.lastSent,
|
|
453
|
+
lastRows: init.lastRows,
|
|
454
|
+
lastCalls: init.lastCalls
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
function eventsWere(s, expectedJson) {
|
|
459
|
+
let err = s.lastError;
|
|
460
|
+
return recordOutcome(s, err !== undefined ? Outcome$ReventlessGwt.fail({
|
|
461
|
+
TAG: "ErrorMismatch",
|
|
462
|
+
expected: null,
|
|
463
|
+
actual: err,
|
|
464
|
+
actualEvents: s.lastEvents
|
|
465
|
+
}) : (
|
|
466
|
+
Primitive_object.equal(s.lastEvents, expectedJson) ? Outcome$ReventlessGwt.pass : Outcome$ReventlessGwt.fail({
|
|
467
|
+
TAG: "EventsMismatch",
|
|
468
|
+
expected: expectedJson,
|
|
469
|
+
actual: s.lastEvents
|
|
470
|
+
})
|
|
471
|
+
));
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
function errorWas(s, expJson) {
|
|
475
|
+
let actual = s.lastError;
|
|
476
|
+
return recordOutcome(s, actual !== undefined ? (
|
|
477
|
+
Primitive_object.equal(actual, expJson) ? Outcome$ReventlessGwt.pass : Outcome$ReventlessGwt.fail({
|
|
478
|
+
TAG: "ErrorMismatch",
|
|
479
|
+
expected: expJson,
|
|
480
|
+
actual: actual,
|
|
481
|
+
actualEvents: s.lastEvents
|
|
482
|
+
})
|
|
483
|
+
) : Outcome$ReventlessGwt.fail({
|
|
484
|
+
TAG: "ErrorMismatch",
|
|
485
|
+
expected: expJson,
|
|
486
|
+
actual: undefined,
|
|
487
|
+
actualEvents: s.lastEvents
|
|
488
|
+
}));
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
function noEventWas(s) {
|
|
492
|
+
let err = s.lastError;
|
|
493
|
+
return recordOutcome(s, err !== undefined ? Outcome$ReventlessGwt.fail({
|
|
494
|
+
TAG: "ErrorMismatch",
|
|
495
|
+
expected: null,
|
|
496
|
+
actual: err,
|
|
497
|
+
actualEvents: s.lastEvents
|
|
498
|
+
}) : (
|
|
499
|
+
s.lastEvents.length === 0 ? Outcome$ReventlessGwt.pass : Outcome$ReventlessGwt.fail({
|
|
500
|
+
TAG: "NoEventExpected",
|
|
501
|
+
actual: s.lastEvents
|
|
502
|
+
})
|
|
503
|
+
));
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
function acceptedWas(s) {
|
|
507
|
+
let err = s.lastError;
|
|
508
|
+
return recordOutcome(s, err !== undefined ? Outcome$ReventlessGwt.fail({
|
|
509
|
+
TAG: "ErrorMismatch",
|
|
510
|
+
expected: null,
|
|
511
|
+
actual: err,
|
|
512
|
+
actualEvents: s.lastEvents
|
|
513
|
+
}) : Outcome$ReventlessGwt.pass);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
let forbiddenCode = CommandOutcome$Reventless.code("Forbidden");
|
|
517
|
+
|
|
518
|
+
function forbidden(s, refusal) {
|
|
519
|
+
return {
|
|
520
|
+
log: s.log,
|
|
521
|
+
outcome: s.outcome,
|
|
522
|
+
lastEvents: [],
|
|
523
|
+
lastError: refusal,
|
|
524
|
+
lastCommands: s.lastCommands,
|
|
525
|
+
lastPublic: s.lastPublic,
|
|
526
|
+
lastIds: s.lastIds,
|
|
527
|
+
lastRefusal: s.lastRefusal,
|
|
528
|
+
steps: s.steps,
|
|
529
|
+
at: s.at,
|
|
530
|
+
failedAt: s.failedAt,
|
|
531
|
+
now: s.now,
|
|
532
|
+
caller: s.caller,
|
|
533
|
+
lastForbidden: true,
|
|
534
|
+
handled: s.handled,
|
|
535
|
+
named: s.named,
|
|
536
|
+
lastSent: s.lastSent,
|
|
537
|
+
lastRows: s.lastRows,
|
|
538
|
+
lastCalls: s.lastCalls
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
function forbiddenWas(s) {
|
|
543
|
+
return recordOutcome(s, s.lastForbidden ? Outcome$ReventlessGwt.pass : Outcome$ReventlessGwt.fail({
|
|
544
|
+
TAG: "ErrorMismatch",
|
|
545
|
+
expected: Object.fromEntries([[
|
|
546
|
+
"errorCode",
|
|
547
|
+
forbiddenCode
|
|
548
|
+
]]),
|
|
549
|
+
actual: s.lastError,
|
|
550
|
+
actualEvents: s.lastEvents
|
|
551
|
+
}));
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
function issued(s, only, name, schema) {
|
|
555
|
+
let sent = s.lastCommands;
|
|
556
|
+
let picked;
|
|
557
|
+
if (only !== undefined) {
|
|
558
|
+
let c = sent[only - 1 | 0];
|
|
559
|
+
picked = c !== undefined ? ({
|
|
560
|
+
TAG: "Ok",
|
|
561
|
+
_0: [c]
|
|
562
|
+
}) : ({
|
|
563
|
+
TAG: "Error",
|
|
564
|
+
_0: `~only=` + only.toString() + `, but ` + sent.length.toString() + ` command(s) were sent`
|
|
565
|
+
});
|
|
566
|
+
} else {
|
|
567
|
+
picked = {
|
|
568
|
+
TAG: "Ok",
|
|
569
|
+
_0: sent
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
return Stdlib_Result.flatMap(picked, sent => {
|
|
573
|
+
if (sent.length === 0) {
|
|
574
|
+
return {
|
|
575
|
+
TAG: "Error",
|
|
576
|
+
_0: "the step before sent no command"
|
|
577
|
+
};
|
|
156
578
|
} else {
|
|
157
|
-
|
|
579
|
+
return Stdlib_Array.reduce(sent, {
|
|
580
|
+
TAG: "Ok",
|
|
581
|
+
_0: []
|
|
582
|
+
}, (acc, json) => Stdlib_Result.flatMap(acc, commands => {
|
|
583
|
+
let command;
|
|
584
|
+
try {
|
|
585
|
+
command = Util_Sury$Reventless.fromJson(json, schema);
|
|
586
|
+
} catch (raw_e) {
|
|
587
|
+
let e = Primitive_exceptions.internalToException(raw_e);
|
|
588
|
+
if (e.RE_EXN_ID === S.Exn) {
|
|
589
|
+
return {
|
|
590
|
+
TAG: "Error",
|
|
591
|
+
_0: name + ` cannot read ` + JSON.stringify(json) + `: ` + e._1.message
|
|
592
|
+
};
|
|
593
|
+
} else {
|
|
594
|
+
return {
|
|
595
|
+
TAG: "Error",
|
|
596
|
+
_0: name + ` cannot read ` + JSON.stringify(json)
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
return {
|
|
601
|
+
TAG: "Ok",
|
|
602
|
+
_0: commands.concat([command])
|
|
603
|
+
};
|
|
604
|
+
}));
|
|
158
605
|
}
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
function runIssued(s, commands, decideOne) {
|
|
610
|
+
if (commands.TAG === "Ok") {
|
|
611
|
+
return Stdlib_Array.reduce(commands._0, {
|
|
612
|
+
log: s.log,
|
|
613
|
+
outcome: s.outcome,
|
|
614
|
+
lastEvents: [],
|
|
615
|
+
lastError: undefined,
|
|
616
|
+
lastCommands: s.lastCommands,
|
|
617
|
+
lastPublic: s.lastPublic,
|
|
618
|
+
lastIds: s.lastIds,
|
|
619
|
+
lastRefusal: s.lastRefusal,
|
|
620
|
+
steps: s.steps,
|
|
621
|
+
at: s.at,
|
|
622
|
+
failedAt: s.failedAt,
|
|
623
|
+
now: s.now,
|
|
624
|
+
caller: s.caller,
|
|
625
|
+
lastForbidden: s.lastForbidden,
|
|
626
|
+
handled: s.handled,
|
|
627
|
+
named: s.named,
|
|
628
|
+
lastSent: s.lastSent,
|
|
629
|
+
lastRows: s.lastRows,
|
|
630
|
+
lastCalls: s.lastCalls
|
|
631
|
+
}, (acc, command) => {
|
|
632
|
+
let match = acc.lastError;
|
|
633
|
+
if (match !== undefined) {
|
|
634
|
+
return acc;
|
|
635
|
+
}
|
|
636
|
+
let next = decideOne(acc, command);
|
|
637
|
+
return {
|
|
638
|
+
log: next.log,
|
|
639
|
+
outcome: next.outcome,
|
|
640
|
+
lastEvents: acc.lastEvents.concat(next.lastEvents),
|
|
641
|
+
lastError: next.lastError,
|
|
642
|
+
lastCommands: next.lastCommands,
|
|
643
|
+
lastPublic: next.lastPublic,
|
|
644
|
+
lastIds: next.lastIds,
|
|
645
|
+
lastRefusal: next.lastRefusal,
|
|
646
|
+
steps: next.steps,
|
|
647
|
+
at: next.at,
|
|
648
|
+
failedAt: next.failedAt,
|
|
649
|
+
now: next.now,
|
|
650
|
+
caller: next.caller,
|
|
651
|
+
lastForbidden: next.lastForbidden,
|
|
652
|
+
handled: next.handled,
|
|
653
|
+
named: next.named,
|
|
654
|
+
lastSent: next.lastSent,
|
|
655
|
+
lastRows: next.lastRows,
|
|
656
|
+
lastCalls: next.lastCalls
|
|
657
|
+
};
|
|
658
|
+
});
|
|
659
|
+
} else {
|
|
660
|
+
return recordOutcome({
|
|
661
|
+
log: s.log,
|
|
662
|
+
outcome: s.outcome,
|
|
663
|
+
lastEvents: [],
|
|
664
|
+
lastError: undefined,
|
|
665
|
+
lastCommands: s.lastCommands,
|
|
666
|
+
lastPublic: s.lastPublic,
|
|
667
|
+
lastIds: s.lastIds,
|
|
668
|
+
lastRefusal: s.lastRefusal,
|
|
669
|
+
steps: s.steps,
|
|
670
|
+
at: s.at,
|
|
671
|
+
failedAt: s.failedAt,
|
|
672
|
+
now: s.now,
|
|
673
|
+
caller: s.caller,
|
|
674
|
+
lastForbidden: s.lastForbidden,
|
|
675
|
+
handled: s.handled,
|
|
676
|
+
named: s.named,
|
|
677
|
+
lastSent: s.lastSent,
|
|
678
|
+
lastRows: s.lastRows,
|
|
679
|
+
lastCalls: s.lastCalls
|
|
680
|
+
}, Outcome$ReventlessGwt.fail({
|
|
681
|
+
TAG: "TranslateError",
|
|
682
|
+
expected: "a command the decision reads",
|
|
683
|
+
actual: commands._0
|
|
684
|
+
}));
|
|
159
685
|
}
|
|
160
|
-
let outcome = partitionReasons.length !== 0 ? Outcome$ReventlessGwt.fail({
|
|
161
|
-
TAG: "PartitionUnresolved",
|
|
162
|
-
boundary: name,
|
|
163
|
-
reasons: partitionReasons
|
|
164
|
-
}) : (
|
|
165
|
-
scope.droppedCrossPartitionTagKeys.length !== 0 ? Outcome$ReventlessGwt.fail({
|
|
166
|
-
TAG: "ScopeDegraded",
|
|
167
|
-
boundary: name,
|
|
168
|
-
dropped: scope.droppedCrossPartitionTagKeys,
|
|
169
|
-
ambiguities: scope.ambiguities.map(param => param[0] + `: ` + param[1])
|
|
170
|
-
}) : Outcome$ReventlessGwt.pass
|
|
171
|
-
);
|
|
172
|
-
return recordOutcome(s, outcome);
|
|
173
686
|
}
|
|
174
687
|
|
|
175
|
-
function
|
|
688
|
+
function DecisionStep(Spec) {
|
|
176
689
|
return Decision => {
|
|
690
|
+
let part_name = Spec.name;
|
|
691
|
+
let part = {
|
|
692
|
+
kind: "Decision",
|
|
693
|
+
name: part_name
|
|
694
|
+
};
|
|
177
695
|
let consumedDecoder = DcbDecode$Reventless.makeDecoder(Spec.consumedEventSchema);
|
|
178
696
|
let consumedEventTypes = consumedDecoder.eventTypes;
|
|
179
|
-
let givenEvents = async (flowP, events) => {
|
|
180
|
-
let s = await flowP;
|
|
697
|
+
let givenEvents = async (flowP, at, events) => {
|
|
698
|
+
let s = await enter(flowP, "givenEvents", part, at);
|
|
181
699
|
return {
|
|
182
|
-
log: appendEvents(s.log, events, Spec.eventSchema),
|
|
700
|
+
log: appendEvents(s.log, s.now, undefined, events, Spec.eventSchema),
|
|
183
701
|
outcome: s.outcome,
|
|
184
702
|
lastEvents: s.lastEvents,
|
|
185
703
|
lastError: s.lastError,
|
|
186
704
|
lastCommands: s.lastCommands,
|
|
187
705
|
lastPublic: s.lastPublic,
|
|
188
|
-
|
|
189
|
-
lastRefusal: s.lastRefusal
|
|
706
|
+
lastIds: s.lastIds,
|
|
707
|
+
lastRefusal: s.lastRefusal,
|
|
708
|
+
steps: s.steps,
|
|
709
|
+
at: s.at,
|
|
710
|
+
failedAt: s.failedAt,
|
|
711
|
+
now: s.now,
|
|
712
|
+
caller: s.caller,
|
|
713
|
+
lastForbidden: s.lastForbidden,
|
|
714
|
+
handled: s.handled,
|
|
715
|
+
named: s.named,
|
|
716
|
+
lastSent: s.lastSent,
|
|
717
|
+
lastRows: s.lastRows,
|
|
718
|
+
lastCalls: s.lastCalls
|
|
190
719
|
};
|
|
191
720
|
};
|
|
192
721
|
let scopeShape = DcbTag$Reventless.sliceShapeFromSchemas("", Spec.commandSchema, Spec.consumedEventSchema, Spec.eventSchema, undefined);
|
|
@@ -205,10 +734,16 @@ function CommandStep(Spec) {
|
|
|
205
734
|
key: key
|
|
206
735
|
}
|
|
207
736
|
})), crossPartitionTagKeys);
|
|
208
|
-
let
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
737
|
+
let historyFor = (s, command) => decodeMatching(s.log, consumedDecoder, DcbTag$Reventless.buildQueryFromCommand(consumedEventTypes, Spec.commandSchema, command, tagKeysByEventType, crossPartitionTagKeys, payloadTagKeys, undefined));
|
|
738
|
+
let Guard = Decision_GWT$ReventlessGwt.Acting({
|
|
739
|
+
name: Spec.name,
|
|
740
|
+
historySchema: Spec.consumedEventSchema,
|
|
741
|
+
commandSchema: Spec.commandSchema,
|
|
742
|
+
authorizationOf: Spec.authorizationOf,
|
|
743
|
+
ownedById: false
|
|
744
|
+
});
|
|
745
|
+
let decideOne = (s, command) => {
|
|
746
|
+
let history = historyFor(s, command);
|
|
212
747
|
let state = Stdlib_Array.reduce(history, Decision.initialState, Decision.evolve);
|
|
213
748
|
let events = Decision.decide(state, command);
|
|
214
749
|
if (events.TAG !== "Ok") {
|
|
@@ -219,61 +754,89 @@ function CommandStep(Spec) {
|
|
|
219
754
|
lastError: Message$ReventlessCore.encode(events._0, Spec.errorSchema),
|
|
220
755
|
lastCommands: s.lastCommands,
|
|
221
756
|
lastPublic: s.lastPublic,
|
|
222
|
-
|
|
223
|
-
lastRefusal: s.lastRefusal
|
|
757
|
+
lastIds: [],
|
|
758
|
+
lastRefusal: s.lastRefusal,
|
|
759
|
+
steps: s.steps,
|
|
760
|
+
at: s.at,
|
|
761
|
+
failedAt: s.failedAt,
|
|
762
|
+
now: s.now,
|
|
763
|
+
caller: s.caller,
|
|
764
|
+
lastForbidden: false,
|
|
765
|
+
handled: s.handled,
|
|
766
|
+
named: s.named,
|
|
767
|
+
lastSent: s.lastSent,
|
|
768
|
+
lastRows: s.lastRows,
|
|
769
|
+
lastCalls: s.lastCalls
|
|
224
770
|
};
|
|
225
771
|
}
|
|
226
772
|
let events$1 = events._0;
|
|
773
|
+
let log = appendEvents(s.log, s.now, tagKeysByEventType, events$1, Spec.eventSchema);
|
|
227
774
|
return {
|
|
228
|
-
log:
|
|
775
|
+
log: log,
|
|
229
776
|
outcome: s.outcome,
|
|
230
777
|
lastEvents: events$1.map(e => Message$ReventlessCore.encode(e, Spec.eventSchema)),
|
|
231
778
|
lastError: undefined,
|
|
232
779
|
lastCommands: s.lastCommands,
|
|
233
780
|
lastPublic: s.lastPublic,
|
|
234
|
-
|
|
235
|
-
lastRefusal: s.lastRefusal
|
|
781
|
+
lastIds: lastIdsOf(log, events$1.length),
|
|
782
|
+
lastRefusal: s.lastRefusal,
|
|
783
|
+
steps: s.steps,
|
|
784
|
+
at: s.at,
|
|
785
|
+
failedAt: s.failedAt,
|
|
786
|
+
now: s.now,
|
|
787
|
+
caller: s.caller,
|
|
788
|
+
lastForbidden: false,
|
|
789
|
+
handled: s.handled,
|
|
790
|
+
named: s.named,
|
|
791
|
+
lastSent: s.lastSent,
|
|
792
|
+
lastRows: s.lastRows,
|
|
793
|
+
lastCalls: s.lastCalls
|
|
236
794
|
};
|
|
237
795
|
};
|
|
238
|
-
let
|
|
239
|
-
let s = await flowP;
|
|
240
|
-
let
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
actualEvents: s.lastEvents
|
|
247
|
-
}) : (
|
|
248
|
-
Primitive_object.equal(s.lastEvents, expectedJson) ? Outcome$ReventlessGwt.pass : Outcome$ReventlessGwt.fail({
|
|
249
|
-
TAG: "EventsMismatch",
|
|
250
|
-
expected: expectedJson,
|
|
251
|
-
actual: s.lastEvents
|
|
252
|
-
})
|
|
253
|
-
);
|
|
254
|
-
return recordOutcome(s, o);
|
|
255
|
-
};
|
|
256
|
-
let thenEvent = (flowP, event) => thenEvents(flowP, [event]);
|
|
257
|
-
let thenError = async (flowP, expected) => {
|
|
258
|
-
let s = await flowP;
|
|
259
|
-
let expJson = Message$ReventlessCore.encode(expected, Spec.errorSchema);
|
|
260
|
-
let actual = s.lastError;
|
|
261
|
-
let o = actual !== undefined ? (
|
|
262
|
-
Primitive_object.equal(actual, expJson) ? Outcome$ReventlessGwt.pass : Outcome$ReventlessGwt.fail({
|
|
263
|
-
TAG: "ErrorMismatch",
|
|
264
|
-
expected: expJson,
|
|
265
|
-
actual: actual,
|
|
266
|
-
actualEvents: s.lastEvents
|
|
267
|
-
})
|
|
268
|
-
) : Outcome$ReventlessGwt.fail({
|
|
269
|
-
TAG: "ErrorMismatch",
|
|
270
|
-
expected: expJson,
|
|
271
|
-
actual: undefined,
|
|
272
|
-
actualEvents: s.lastEvents
|
|
796
|
+
let whenCommand = async (flowP, at, command) => {
|
|
797
|
+
let s = await enter(flowP, "whenCommand", part, at);
|
|
798
|
+
let who = s.caller;
|
|
799
|
+
if (who !== undefined) {
|
|
800
|
+
Guard.asCaller([], {
|
|
801
|
+
claim: Decision_GWT$ReventlessGwt.Caller.claimWith(who, elevated.contents),
|
|
802
|
+
roles: who.roles,
|
|
803
|
+
signedIn: who.signedIn
|
|
273
804
|
});
|
|
274
|
-
|
|
805
|
+
if (Guard.refuses(historyFor(s, command), command)) {
|
|
806
|
+
return forbidden(s, Stdlib_Option.map(Guard.refusal.contents, Guard.encRefusal));
|
|
807
|
+
} else {
|
|
808
|
+
return decideOne(s, command);
|
|
809
|
+
}
|
|
810
|
+
} else {
|
|
811
|
+
return decideOne(s, command);
|
|
812
|
+
}
|
|
813
|
+
};
|
|
814
|
+
let whenIssued = async (flowP, only, at) => {
|
|
815
|
+
let s = await enter(flowP, "whenIssued", part, at);
|
|
816
|
+
return runIssued(s, issued(s, only, Spec.name, Spec.commandSchema), decideOne);
|
|
275
817
|
};
|
|
818
|
+
let deciding_name = Spec.name;
|
|
819
|
+
let deciding_run = (s, json) => {
|
|
820
|
+
let command;
|
|
821
|
+
try {
|
|
822
|
+
command = Util_Sury$Reventless.fromJson(json, Spec.commandSchema);
|
|
823
|
+
} catch (exn) {
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
826
|
+
return decideOne(s, command);
|
|
827
|
+
};
|
|
828
|
+
let deciding = {
|
|
829
|
+
name: deciding_name,
|
|
830
|
+
run: deciding_run
|
|
831
|
+
};
|
|
832
|
+
let thenEvents = async (flowP, expected) => eventsWere(await enter(flowP, "thenEvents", part, undefined), expected.map(e => Message$ReventlessCore.encode(e, Spec.eventSchema)));
|
|
833
|
+
let thenEvent = async (flowP, event) => eventsWere(await enter(flowP, "thenEvent", part, undefined), [Message$ReventlessCore.encode(event, Spec.eventSchema)]);
|
|
834
|
+
let thenError = async (flowP, expected) => errorWas(await enter(flowP, "thenError", part, undefined), Message$ReventlessCore.encode(expected, Spec.errorSchema));
|
|
835
|
+
let thenNoEvent = async flowP => noEventWas(await enter(flowP, "thenNoEvent", part, undefined));
|
|
836
|
+
let thenAccepted = async flowP => acceptedWas(await enter(flowP, "thenAccepted", part, undefined));
|
|
837
|
+
let thenForbidden = async flowP => forbiddenWas(await enter(flowP, "thenForbidden", part, undefined));
|
|
276
838
|
return {
|
|
839
|
+
part: part,
|
|
277
840
|
consumedDecoder: consumedDecoder,
|
|
278
841
|
consumedEventTypes: consumedEventTypes,
|
|
279
842
|
givenEvents: givenEvents,
|
|
@@ -281,32 +844,62 @@ function CommandStep(Spec) {
|
|
|
281
844
|
crossPartitionTagKeys: crossPartitionTagKeys,
|
|
282
845
|
tagKeysByEventType: tagKeysByEventType,
|
|
283
846
|
payloadTagKeys: payloadTagKeys,
|
|
847
|
+
historyFor: historyFor,
|
|
848
|
+
Guard: Guard,
|
|
849
|
+
decideOne: decideOne,
|
|
284
850
|
whenCommand: whenCommand,
|
|
851
|
+
whenIssued: whenIssued,
|
|
852
|
+
deciding: deciding,
|
|
285
853
|
thenEvents: thenEvents,
|
|
286
854
|
thenEvent: thenEvent,
|
|
287
|
-
thenError: thenError
|
|
855
|
+
thenError: thenError,
|
|
856
|
+
thenNoEvent: thenNoEvent,
|
|
857
|
+
thenAccepted: thenAccepted,
|
|
858
|
+
thenForbidden: thenForbidden
|
|
288
859
|
};
|
|
289
860
|
};
|
|
290
861
|
}
|
|
291
862
|
|
|
292
|
-
function
|
|
863
|
+
function AggregateStep(Spec) {
|
|
293
864
|
return Decision => {
|
|
865
|
+
let part_name = Spec.name;
|
|
866
|
+
let part = {
|
|
867
|
+
kind: "Aggregate",
|
|
868
|
+
name: part_name
|
|
869
|
+
};
|
|
294
870
|
let aggregateDecoder = DcbDecode$Reventless.makeDecoder(Spec.eventSchema);
|
|
295
|
-
let givenEvents = async (flowP, id, events) => {
|
|
296
|
-
let s = await flowP;
|
|
871
|
+
let givenEvents = async (flowP, id, at, events) => {
|
|
872
|
+
let s = await enter(flowP, "givenEvents", part, at);
|
|
297
873
|
return {
|
|
298
|
-
log: appendAggregateEvents(s.log, id, events, Spec.eventSchema),
|
|
874
|
+
log: appendAggregateEvents(s.log, id, s.now, events, Spec.eventSchema),
|
|
299
875
|
outcome: s.outcome,
|
|
300
876
|
lastEvents: s.lastEvents,
|
|
301
877
|
lastError: s.lastError,
|
|
302
878
|
lastCommands: s.lastCommands,
|
|
303
879
|
lastPublic: s.lastPublic,
|
|
304
|
-
|
|
305
|
-
lastRefusal: s.lastRefusal
|
|
880
|
+
lastIds: s.lastIds,
|
|
881
|
+
lastRefusal: s.lastRefusal,
|
|
882
|
+
steps: s.steps,
|
|
883
|
+
at: s.at,
|
|
884
|
+
failedAt: s.failedAt,
|
|
885
|
+
now: s.now,
|
|
886
|
+
caller: s.caller,
|
|
887
|
+
lastForbidden: s.lastForbidden,
|
|
888
|
+
handled: s.handled,
|
|
889
|
+
named: s.named,
|
|
890
|
+
lastSent: s.lastSent,
|
|
891
|
+
lastRows: s.lastRows,
|
|
892
|
+
lastCalls: s.lastCalls
|
|
306
893
|
};
|
|
307
894
|
};
|
|
308
|
-
let
|
|
309
|
-
|
|
895
|
+
let Guard = Decision_GWT$ReventlessGwt.Acting({
|
|
896
|
+
name: Spec.name,
|
|
897
|
+
historySchema: Spec.eventSchema,
|
|
898
|
+
commandSchema: Spec.commandSchema,
|
|
899
|
+
authorizationOf: Spec.authorizationOf,
|
|
900
|
+
ownedById: false
|
|
901
|
+
});
|
|
902
|
+
let decideOne = (s, id, command) => {
|
|
310
903
|
let history = decodeAggregateMatching(s.log, id, aggregateDecoder);
|
|
311
904
|
let state = Stdlib_Array.reduce(history, Decision.initialState, Decision.evolve);
|
|
312
905
|
let events = Decision.decide(state, command);
|
|
@@ -318,194 +911,359 @@ function AggregateCommandStep(Spec) {
|
|
|
318
911
|
lastError: Message$ReventlessCore.encode(events._0, Spec.errorSchema),
|
|
319
912
|
lastCommands: s.lastCommands,
|
|
320
913
|
lastPublic: s.lastPublic,
|
|
321
|
-
|
|
322
|
-
lastRefusal: s.lastRefusal
|
|
914
|
+
lastIds: [],
|
|
915
|
+
lastRefusal: s.lastRefusal,
|
|
916
|
+
steps: s.steps,
|
|
917
|
+
at: s.at,
|
|
918
|
+
failedAt: s.failedAt,
|
|
919
|
+
now: s.now,
|
|
920
|
+
caller: s.caller,
|
|
921
|
+
lastForbidden: false,
|
|
922
|
+
handled: s.handled,
|
|
923
|
+
named: s.named,
|
|
924
|
+
lastSent: s.lastSent,
|
|
925
|
+
lastRows: s.lastRows,
|
|
926
|
+
lastCalls: s.lastCalls
|
|
323
927
|
};
|
|
324
928
|
}
|
|
325
929
|
let events$1 = events._0;
|
|
326
930
|
return {
|
|
327
|
-
log: appendAggregateEvents(s.log, id, events$1, Spec.eventSchema),
|
|
931
|
+
log: appendAggregateEvents(s.log, id, s.now, events$1, Spec.eventSchema),
|
|
328
932
|
outcome: s.outcome,
|
|
329
933
|
lastEvents: events$1.map(e => Message$ReventlessCore.encode(e, Spec.eventSchema)),
|
|
330
934
|
lastError: undefined,
|
|
331
935
|
lastCommands: s.lastCommands,
|
|
332
936
|
lastPublic: s.lastPublic,
|
|
333
|
-
|
|
334
|
-
lastRefusal: s.lastRefusal
|
|
937
|
+
lastIds: events$1.map(param => id),
|
|
938
|
+
lastRefusal: s.lastRefusal,
|
|
939
|
+
steps: s.steps,
|
|
940
|
+
at: s.at,
|
|
941
|
+
failedAt: s.failedAt,
|
|
942
|
+
now: s.now,
|
|
943
|
+
caller: s.caller,
|
|
944
|
+
lastForbidden: false,
|
|
945
|
+
handled: s.handled,
|
|
946
|
+
named: s.named,
|
|
947
|
+
lastSent: s.lastSent,
|
|
948
|
+
lastRows: s.lastRows,
|
|
949
|
+
lastCalls: s.lastCalls
|
|
335
950
|
};
|
|
336
951
|
};
|
|
337
|
-
let
|
|
338
|
-
let s = await flowP;
|
|
339
|
-
let
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
actualEvents: s.lastEvents
|
|
346
|
-
}) : (
|
|
347
|
-
Primitive_object.equal(s.lastEvents, expectedJson) ? Outcome$ReventlessGwt.pass : Outcome$ReventlessGwt.fail({
|
|
348
|
-
TAG: "EventsMismatch",
|
|
349
|
-
expected: expectedJson,
|
|
350
|
-
actual: s.lastEvents
|
|
351
|
-
})
|
|
352
|
-
);
|
|
353
|
-
return recordOutcome(s, o);
|
|
354
|
-
};
|
|
355
|
-
let thenEvent = (flowP, event) => thenEvents(flowP, [event]);
|
|
356
|
-
let thenNoEvent = async flowP => {
|
|
357
|
-
let s = await flowP;
|
|
358
|
-
let err = s.lastError;
|
|
359
|
-
let o = err !== undefined ? Outcome$ReventlessGwt.fail({
|
|
360
|
-
TAG: "ErrorMismatch",
|
|
361
|
-
expected: null,
|
|
362
|
-
actual: err,
|
|
363
|
-
actualEvents: s.lastEvents
|
|
364
|
-
}) : (
|
|
365
|
-
s.lastEvents.length === 0 ? Outcome$ReventlessGwt.pass : Outcome$ReventlessGwt.fail({
|
|
366
|
-
TAG: "NoEventExpected",
|
|
367
|
-
actual: s.lastEvents
|
|
368
|
-
})
|
|
369
|
-
);
|
|
370
|
-
return recordOutcome(s, o);
|
|
371
|
-
};
|
|
372
|
-
let thenError = async (flowP, expected) => {
|
|
373
|
-
let s = await flowP;
|
|
374
|
-
let expJson = Message$ReventlessCore.encode(expected, Spec.errorSchema);
|
|
375
|
-
let actual = s.lastError;
|
|
376
|
-
let o = actual !== undefined ? (
|
|
377
|
-
Primitive_object.equal(actual, expJson) ? Outcome$ReventlessGwt.pass : Outcome$ReventlessGwt.fail({
|
|
378
|
-
TAG: "ErrorMismatch",
|
|
379
|
-
expected: expJson,
|
|
380
|
-
actual: actual,
|
|
381
|
-
actualEvents: s.lastEvents
|
|
382
|
-
})
|
|
383
|
-
) : Outcome$ReventlessGwt.fail({
|
|
384
|
-
TAG: "ErrorMismatch",
|
|
385
|
-
expected: expJson,
|
|
386
|
-
actual: undefined,
|
|
387
|
-
actualEvents: s.lastEvents
|
|
952
|
+
let whenCommand = async (flowP, id, at, command) => {
|
|
953
|
+
let s = await enter(flowP, "whenCommand", part, at);
|
|
954
|
+
let who = s.caller;
|
|
955
|
+
if (who !== undefined) {
|
|
956
|
+
Guard.asCaller([], {
|
|
957
|
+
claim: Decision_GWT$ReventlessGwt.Caller.claimWith(who, elevated.contents),
|
|
958
|
+
roles: who.roles,
|
|
959
|
+
signedIn: who.signedIn
|
|
388
960
|
});
|
|
389
|
-
|
|
961
|
+
if (Guard.refuses(decodeAggregateMatching(s.log, id, aggregateDecoder), command)) {
|
|
962
|
+
return forbidden(s, Stdlib_Option.map(Guard.refusal.contents, Guard.encRefusal));
|
|
963
|
+
} else {
|
|
964
|
+
return decideOne(s, id, command);
|
|
965
|
+
}
|
|
966
|
+
} else {
|
|
967
|
+
return decideOne(s, id, command);
|
|
968
|
+
}
|
|
390
969
|
};
|
|
970
|
+
let whenIssued = async (flowP, id, only, at) => {
|
|
971
|
+
let s = await enter(flowP, "whenIssued", part, at);
|
|
972
|
+
return runIssued(s, issued(s, only, Spec.name, Spec.commandSchema), (s, c) => decideOne(s, id, c));
|
|
973
|
+
};
|
|
974
|
+
let thenEvents = async (flowP, expected) => eventsWere(await enter(flowP, "thenEvents", part, undefined), expected.map(e => Message$ReventlessCore.encode(e, Spec.eventSchema)));
|
|
975
|
+
let thenEvent = async (flowP, event) => eventsWere(await enter(flowP, "thenEvent", part, undefined), [Message$ReventlessCore.encode(event, Spec.eventSchema)]);
|
|
976
|
+
let thenNoEvent = async flowP => noEventWas(await enter(flowP, "thenNoEvent", part, undefined));
|
|
977
|
+
let thenAccepted = async flowP => acceptedWas(await enter(flowP, "thenAccepted", part, undefined));
|
|
978
|
+
let thenForbidden = async flowP => forbiddenWas(await enter(flowP, "thenForbidden", part, undefined));
|
|
979
|
+
let thenError = async (flowP, expected) => errorWas(await enter(flowP, "thenError", part, undefined), Message$ReventlessCore.encode(expected, Spec.errorSchema));
|
|
391
980
|
return {
|
|
981
|
+
part: part,
|
|
392
982
|
aggregateDecoder: aggregateDecoder,
|
|
393
983
|
givenEvents: givenEvents,
|
|
984
|
+
Guard: Guard,
|
|
985
|
+
decideOne: decideOne,
|
|
394
986
|
whenCommand: whenCommand,
|
|
987
|
+
whenIssued: whenIssued,
|
|
395
988
|
thenEvents: thenEvents,
|
|
396
989
|
thenEvent: thenEvent,
|
|
397
990
|
thenNoEvent: thenNoEvent,
|
|
991
|
+
thenAccepted: thenAccepted,
|
|
992
|
+
thenForbidden: thenForbidden,
|
|
398
993
|
thenError: thenError
|
|
399
994
|
};
|
|
400
995
|
};
|
|
401
996
|
}
|
|
402
997
|
|
|
403
|
-
function
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
let
|
|
407
|
-
let
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
let
|
|
412
|
-
let
|
|
998
|
+
function ViewStep(Spec) {
|
|
999
|
+
return Projection => {
|
|
1000
|
+
let P = Projection_GWT$ReventlessGwt.Make(Spec)(Projection);
|
|
1001
|
+
let part_name = Spec.name;
|
|
1002
|
+
let part = {
|
|
1003
|
+
kind: "View",
|
|
1004
|
+
name: part_name
|
|
1005
|
+
};
|
|
1006
|
+
let consumedDecoder = DcbDecode$Reventless.makeDecoder(Spec.consumedEventSchema);
|
|
1007
|
+
let encState = st => Message$ReventlessCore.encode(st, Spec.stateSchema);
|
|
1008
|
+
let rowsOf = async (s, id) => {
|
|
1009
|
+
let events = s.log.flatMap(entry => decodeMatching([entry], consumedDecoder, []).map(e => [
|
|
1010
|
+
e,
|
|
1011
|
+
iso(entry.at)
|
|
1012
|
+
]));
|
|
1013
|
+
let store = await P.givenEventsAt(events);
|
|
1014
|
+
let rows = Stdlib_Option.getOr(store[id], []);
|
|
1015
|
+
let who = s.caller;
|
|
1016
|
+
if (who !== undefined) {
|
|
1017
|
+
return P.readableBy(rows, who, elevated.contents);
|
|
1018
|
+
} else {
|
|
1019
|
+
return rows;
|
|
1020
|
+
}
|
|
1021
|
+
};
|
|
1022
|
+
let compared = (s, id, expected, actual) => recordOutcome(s, Primitive_object.equal(actual, expected) ? Outcome$ReventlessGwt.pass : Outcome$ReventlessGwt.fail({
|
|
1023
|
+
TAG: "StateMismatch",
|
|
1024
|
+
key: id,
|
|
1025
|
+
expected: expected,
|
|
1026
|
+
actual: actual,
|
|
1027
|
+
fold: "Project"
|
|
1028
|
+
}));
|
|
1029
|
+
let rowsAre = async (s, id, expected) => compared(s, id, expected.map(encState), (await rowsOf(s, id)).map(encState));
|
|
1030
|
+
let thenRows = async (flowP, id, expected) => await rowsAre(await enter(flowP, "thenRows", part, undefined), id, expected);
|
|
1031
|
+
let thenRow = async (flowP, id, row) => await rowsAre(await enter(flowP, "thenRow", part, undefined), id, [row]);
|
|
1032
|
+
let thenNoRow = async (flowP, id) => await rowsAre(await enter(flowP, "thenNoRow", part, undefined), id, []);
|
|
1033
|
+
let thenRowShows = async (flowP, id, pick, expected) => {
|
|
1034
|
+
let s = await enter(flowP, "thenRowShows", part, undefined);
|
|
1035
|
+
let shown = (await rowsOf(s, id)).map(pick);
|
|
1036
|
+
let asJson = v => v;
|
|
1037
|
+
if (Primitive_object.equal(shown, [expected])) {
|
|
1038
|
+
return recordOutcome(s, Outcome$ReventlessGwt.pass);
|
|
1039
|
+
} else {
|
|
1040
|
+
return compared(s, id, [expected], shown.map(asJson));
|
|
1041
|
+
}
|
|
1042
|
+
};
|
|
1043
|
+
let thenViewState = (param, param$1, param$2) => {};
|
|
1044
|
+
let thenViewStates = (param, param$1, param$2) => {};
|
|
413
1045
|
return {
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
1046
|
+
P: P,
|
|
1047
|
+
part: part,
|
|
1048
|
+
consumedDecoder: consumedDecoder,
|
|
1049
|
+
encState: encState,
|
|
1050
|
+
rowsOf: rowsOf,
|
|
1051
|
+
compared: compared,
|
|
1052
|
+
rowsAre: rowsAre,
|
|
1053
|
+
thenRows: thenRows,
|
|
1054
|
+
thenRow: thenRow,
|
|
1055
|
+
thenNoRow: thenNoRow,
|
|
1056
|
+
thenRowShows: thenRowShows,
|
|
1057
|
+
thenViewState: thenViewState,
|
|
1058
|
+
thenViewStates: thenViewStates
|
|
422
1059
|
};
|
|
423
1060
|
};
|
|
424
|
-
let thenIssuesCommands = async (flowP, expected) => {
|
|
425
|
-
let s = await flowP;
|
|
426
|
-
let expJson = expected.map(c => Message$ReventlessCore.encode(c, Spec.commandSchema));
|
|
427
|
-
let o = Primitive_object.equal(s.lastCommands, expJson) ? Outcome$ReventlessGwt.pass : Outcome$ReventlessGwt.fail({
|
|
428
|
-
TAG: "EventsMismatch",
|
|
429
|
-
expected: expJson,
|
|
430
|
-
actual: s.lastCommands
|
|
431
|
-
});
|
|
432
|
-
return recordOutcome(s, o);
|
|
433
|
-
};
|
|
434
|
-
let thenIssuesCommand = (flowP, command) => thenIssuesCommands(flowP, [command]);
|
|
435
|
-
let thenIssuesNoCommand = flowP => thenIssuesCommands(flowP, []);
|
|
436
|
-
return {
|
|
437
|
-
consumedDecoder: consumedDecoder,
|
|
438
|
-
whenReacts: whenReacts,
|
|
439
|
-
thenIssuesCommands: thenIssuesCommands,
|
|
440
|
-
thenIssuesCommand: thenIssuesCommand,
|
|
441
|
-
thenIssuesNoCommand: thenIssuesNoCommand
|
|
442
|
-
};
|
|
443
1061
|
}
|
|
444
1062
|
|
|
445
|
-
function
|
|
1063
|
+
function QueryStep(Spec) {
|
|
446
1064
|
return Projection => {
|
|
447
1065
|
let P = Projection_GWT$ReventlessGwt.Make(Spec)(Projection);
|
|
1066
|
+
let Q = Query_GWT$ReventlessGwt.Make({
|
|
1067
|
+
name: Spec.name,
|
|
1068
|
+
stateSchema: Spec.stateSchema,
|
|
1069
|
+
config: Spec.config,
|
|
1070
|
+
subIdConfig: Spec.subIdConfig,
|
|
1071
|
+
authorization: Spec.authorization
|
|
1072
|
+
});
|
|
1073
|
+
let part_name = Spec.name;
|
|
1074
|
+
let part = {
|
|
1075
|
+
kind: "Query",
|
|
1076
|
+
name: part_name
|
|
1077
|
+
};
|
|
448
1078
|
let consumedDecoder = DcbDecode$Reventless.makeDecoder(Spec.consumedEventSchema);
|
|
449
1079
|
let encState = st => Message$ReventlessCore.encode(st, Spec.stateSchema);
|
|
450
|
-
let
|
|
451
|
-
let
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
1080
|
+
let rowsOf = async s => {
|
|
1081
|
+
let store = await P.givenEventsAt(s.log.flatMap(entry => decodeMatching([entry], consumedDecoder, []).map(e => [
|
|
1082
|
+
e,
|
|
1083
|
+
iso(entry.at)
|
|
1084
|
+
])));
|
|
1085
|
+
return Object.entries(store).flatMap(param => {
|
|
1086
|
+
let rows = param[1];
|
|
1087
|
+
let id = param[0];
|
|
1088
|
+
let who = s.caller;
|
|
1089
|
+
let rows$1 = who !== undefined ? P.readableBy(rows, who, elevated.contents) : rows;
|
|
1090
|
+
return rows$1.map(row => [
|
|
1091
|
+
id,
|
|
1092
|
+
row
|
|
1093
|
+
]);
|
|
1094
|
+
});
|
|
1095
|
+
};
|
|
1096
|
+
let whenQueried = async (flowP, args) => {
|
|
1097
|
+
let s = await enter(flowP, "whenQueried", part, undefined);
|
|
1098
|
+
let rows = Q.whenQuery(Q.givenStore(await rowsOf(s)), args);
|
|
1099
|
+
if (rows.TAG === "Ok") {
|
|
1100
|
+
return {
|
|
1101
|
+
log: s.log,
|
|
1102
|
+
outcome: s.outcome,
|
|
1103
|
+
lastEvents: s.lastEvents,
|
|
1104
|
+
lastError: s.lastError,
|
|
1105
|
+
lastCommands: s.lastCommands,
|
|
1106
|
+
lastPublic: s.lastPublic,
|
|
1107
|
+
lastIds: s.lastIds,
|
|
1108
|
+
lastRefusal: s.lastRefusal,
|
|
1109
|
+
steps: s.steps,
|
|
1110
|
+
at: s.at,
|
|
1111
|
+
failedAt: s.failedAt,
|
|
1112
|
+
now: s.now,
|
|
1113
|
+
caller: s.caller,
|
|
1114
|
+
lastForbidden: s.lastForbidden,
|
|
1115
|
+
handled: s.handled,
|
|
1116
|
+
named: s.named,
|
|
1117
|
+
lastSent: s.lastSent,
|
|
1118
|
+
lastRows: rows._0.map(encState),
|
|
1119
|
+
lastCalls: s.lastCalls
|
|
1120
|
+
};
|
|
1121
|
+
} else {
|
|
1122
|
+
return recordOutcome({
|
|
1123
|
+
log: s.log,
|
|
1124
|
+
outcome: s.outcome,
|
|
1125
|
+
lastEvents: s.lastEvents,
|
|
1126
|
+
lastError: s.lastError,
|
|
1127
|
+
lastCommands: s.lastCommands,
|
|
1128
|
+
lastPublic: s.lastPublic,
|
|
1129
|
+
lastIds: s.lastIds,
|
|
1130
|
+
lastRefusal: s.lastRefusal,
|
|
1131
|
+
steps: s.steps,
|
|
1132
|
+
at: s.at,
|
|
1133
|
+
failedAt: s.failedAt,
|
|
1134
|
+
now: s.now,
|
|
1135
|
+
caller: s.caller,
|
|
1136
|
+
lastForbidden: s.lastForbidden,
|
|
1137
|
+
handled: s.handled,
|
|
1138
|
+
named: s.named,
|
|
1139
|
+
lastSent: s.lastSent,
|
|
1140
|
+
lastRows: [],
|
|
1141
|
+
lastCalls: s.lastCalls
|
|
1142
|
+
}, {
|
|
1143
|
+
TAG: "Error",
|
|
1144
|
+
_0: rows._0
|
|
461
1145
|
});
|
|
462
|
-
|
|
1146
|
+
}
|
|
1147
|
+
};
|
|
1148
|
+
let listed = (s, expected) => recordOutcome(s, Primitive_object.equal(s.lastRows, expected) ? Outcome$ReventlessGwt.pass : Outcome$ReventlessGwt.fail({
|
|
1149
|
+
TAG: "QueryRowsMismatch",
|
|
1150
|
+
expected: expected,
|
|
1151
|
+
actual: s.lastRows
|
|
1152
|
+
}));
|
|
1153
|
+
let thenListed = async (flowP, expected) => listed(await enter(flowP, "thenListed", part, undefined), expected.map(encState));
|
|
1154
|
+
let thenCounted = async (flowP, count) => {
|
|
1155
|
+
let s = await enter(flowP, "thenCounted", part, undefined);
|
|
1156
|
+
return recordOutcome(s, s.lastRows.length === count ? Outcome$ReventlessGwt.pass : Outcome$ReventlessGwt.fail({
|
|
1157
|
+
TAG: "StateMismatch",
|
|
1158
|
+
key: "count",
|
|
1159
|
+
expected: count,
|
|
1160
|
+
actual: s.lastRows.length
|
|
1161
|
+
}));
|
|
463
1162
|
};
|
|
464
|
-
let thenViewState = (flowP, id, state) => thenViewStates(flowP, id, [state]);
|
|
465
1163
|
return {
|
|
466
1164
|
P: P,
|
|
1165
|
+
Q: Q,
|
|
1166
|
+
part: part,
|
|
467
1167
|
consumedDecoder: consumedDecoder,
|
|
468
1168
|
encState: encState,
|
|
469
|
-
|
|
470
|
-
|
|
1169
|
+
rowsOf: rowsOf,
|
|
1170
|
+
whenQueried: whenQueried,
|
|
1171
|
+
listed: listed,
|
|
1172
|
+
thenListed: thenListed,
|
|
1173
|
+
thenCounted: thenCounted
|
|
471
1174
|
};
|
|
472
1175
|
};
|
|
473
1176
|
}
|
|
474
1177
|
|
|
475
|
-
function
|
|
476
|
-
let
|
|
477
|
-
let
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
let
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
let
|
|
485
|
-
let
|
|
486
|
-
let
|
|
487
|
-
|
|
488
|
-
|
|
1178
|
+
function SideEffectStep(SE) {
|
|
1179
|
+
let name = Stdlib_Option.getOr(Stdlib_Option.flatMap(SE.moduleUrl.split("/").at(-1), file => file.split(".")[0]), "SideEffect");
|
|
1180
|
+
let part = {
|
|
1181
|
+
kind: "SideEffect",
|
|
1182
|
+
name: name
|
|
1183
|
+
};
|
|
1184
|
+
let decoder = DcbDecode$Reventless.makeDecoder(SE.Source.eventSchema);
|
|
1185
|
+
let key = "sideEffect:" + name;
|
|
1186
|
+
let whenRuns = async (flowP, mock) => {
|
|
1187
|
+
let s = await enter(flowP, "whenRuns", part, undefined);
|
|
1188
|
+
let handled = handledBy(s, key);
|
|
1189
|
+
let fresh = Stdlib_Array.filterMap(s.log.map((entry, i) => [
|
|
1190
|
+
i.toString(),
|
|
1191
|
+
entry
|
|
1192
|
+
]), param => {
|
|
1193
|
+
let i = param[0];
|
|
1194
|
+
if (handled.includes(i)) {
|
|
1195
|
+
return;
|
|
1196
|
+
}
|
|
1197
|
+
let entry = param[1];
|
|
1198
|
+
return Stdlib_Option.map(decodeMatching([entry], decoder, [])[0], ev => [
|
|
1199
|
+
i,
|
|
1200
|
+
entry,
|
|
1201
|
+
ev
|
|
1202
|
+
]);
|
|
1203
|
+
});
|
|
1204
|
+
let before = mock.snapshot().length;
|
|
1205
|
+
let run = async i => {
|
|
1206
|
+
let match = fresh[i];
|
|
1207
|
+
if (match === undefined) {
|
|
1208
|
+
return;
|
|
1209
|
+
}
|
|
1210
|
+
let entry = match[1];
|
|
1211
|
+
let newrecord = {...StubRuntime$ReventlessGwt.meta};
|
|
1212
|
+
await SE.execute(SE.Source.Id.makeFromString(entry.id), (newrecord.time = iso(entry.at), newrecord), match[2], SideEffect_GWT$ReventlessGwt.stubQueryEngine);
|
|
1213
|
+
return await run(i + 1 | 0);
|
|
1214
|
+
};
|
|
1215
|
+
await run(0);
|
|
1216
|
+
let init = markHandled(s, key, fresh.map(param => param[0]));
|
|
1217
|
+
return {
|
|
1218
|
+
log: init.log,
|
|
1219
|
+
outcome: init.outcome,
|
|
1220
|
+
lastEvents: init.lastEvents,
|
|
1221
|
+
lastError: init.lastError,
|
|
1222
|
+
lastCommands: init.lastCommands,
|
|
1223
|
+
lastPublic: init.lastPublic,
|
|
1224
|
+
lastIds: init.lastIds,
|
|
1225
|
+
lastRefusal: init.lastRefusal,
|
|
1226
|
+
steps: init.steps,
|
|
1227
|
+
at: init.at,
|
|
1228
|
+
failedAt: init.failedAt,
|
|
1229
|
+
now: init.now,
|
|
1230
|
+
caller: init.caller,
|
|
1231
|
+
lastForbidden: init.lastForbidden,
|
|
1232
|
+
handled: init.handled,
|
|
1233
|
+
named: init.named,
|
|
1234
|
+
lastSent: init.lastSent,
|
|
1235
|
+
lastRows: init.lastRows,
|
|
1236
|
+
lastCalls: mock.snapshot().slice(before).map(mock.encode)
|
|
1237
|
+
};
|
|
1238
|
+
};
|
|
1239
|
+
let thenDid = async (flowP, mock, expected) => {
|
|
1240
|
+
let s = await enter(flowP, "thenDid", part, undefined);
|
|
1241
|
+
let expectedJson = expected.map(mock.encode);
|
|
1242
|
+
return recordOutcome(s, Primitive_object.equal(s.lastCalls, expectedJson) ? Outcome$ReventlessGwt.pass : Outcome$ReventlessGwt.fail({
|
|
1243
|
+
TAG: "EventsMismatch",
|
|
489
1244
|
expected: expectedJson,
|
|
490
|
-
actual:
|
|
491
|
-
});
|
|
492
|
-
|
|
1245
|
+
actual: s.lastCalls
|
|
1246
|
+
}));
|
|
1247
|
+
};
|
|
1248
|
+
let thenDidNothing = async flowP => {
|
|
1249
|
+
let s = await enter(flowP, "thenDidNothing", part, undefined);
|
|
1250
|
+
return recordOutcome(s, Primitive_object.equal(s.lastCalls, []) ? Outcome$ReventlessGwt.pass : Outcome$ReventlessGwt.fail({
|
|
1251
|
+
TAG: "NoEventExpected",
|
|
1252
|
+
actual: s.lastCalls
|
|
1253
|
+
}));
|
|
493
1254
|
};
|
|
494
|
-
let thenOutboundNothing = flowP => thenOutbound(flowP, []);
|
|
495
1255
|
return {
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
1256
|
+
name: name,
|
|
1257
|
+
part: part,
|
|
1258
|
+
decoder: decoder,
|
|
1259
|
+
key: key,
|
|
1260
|
+
whenRuns: whenRuns,
|
|
1261
|
+
thenDid: thenDid,
|
|
1262
|
+
thenDidNothing: thenDidNothing
|
|
500
1263
|
};
|
|
501
1264
|
}
|
|
502
1265
|
|
|
503
|
-
function
|
|
504
|
-
return Stdlib_Option.getOr(entry.aggregateId, "");
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
async function encodedCommandsMatch(flowP, expJson) {
|
|
508
|
-
let s = await flowP;
|
|
1266
|
+
function encodedCommandsMatch(s, expJson) {
|
|
509
1267
|
let reason = s.lastRefusal;
|
|
510
1268
|
let o = reason !== undefined ? Outcome$ReventlessGwt.fail({
|
|
511
1269
|
TAG: "TranslateError",
|
|
@@ -521,30 +1279,136 @@ async function encodedCommandsMatch(flowP, expJson) {
|
|
|
521
1279
|
return recordOutcome(s, o);
|
|
522
1280
|
}
|
|
523
1281
|
|
|
524
|
-
function
|
|
1282
|
+
function AutomationStep(Spec) {
|
|
525
1283
|
return Automation => {
|
|
526
1284
|
let A = Automation_GWT$ReventlessGwt.FromSlice(Spec)(Automation);
|
|
527
|
-
let
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
return {
|
|
532
|
-
log: s.log,
|
|
533
|
-
outcome: s.outcome,
|
|
534
|
-
lastEvents: s.lastEvents,
|
|
535
|
-
lastError: s.lastError,
|
|
536
|
-
lastCommands: match.commands.map(param => Message$ReventlessCore.encode(param[1], Spec.commandSchema)),
|
|
537
|
-
lastPublic: s.lastPublic,
|
|
538
|
-
lastAggregateId: s.lastAggregateId,
|
|
539
|
-
lastRefusal: undefined
|
|
540
|
-
};
|
|
1285
|
+
let part_name = Spec.name;
|
|
1286
|
+
let part = {
|
|
1287
|
+
kind: "Automation",
|
|
1288
|
+
name: part_name
|
|
541
1289
|
};
|
|
542
|
-
let
|
|
543
|
-
|
|
544
|
-
|
|
1290
|
+
let routedLog = s => s.log.map(entry => [
|
|
1291
|
+
entry,
|
|
1292
|
+
Stdlib_Array.filterMap(A.Route.dispatches, d => d.handle(entry.json, entry.id, A.withRecordedAt(A.testContext, entry.at)))
|
|
1293
|
+
]);
|
|
1294
|
+
let key = "automation:" + Spec.name;
|
|
1295
|
+
let dueTicks = (s, log, from) => {
|
|
1296
|
+
let rows = A.declaredRows(0.0);
|
|
1297
|
+
log.forEach(param => {
|
|
1298
|
+
let entry = param[0];
|
|
1299
|
+
param[1].forEach(r => {
|
|
1300
|
+
r.rescheduled.forEach(change => {
|
|
1301
|
+
AutomationSlice_Schedules$ReventlessCore.apply(rows, change, "flow", entry.at);
|
|
1302
|
+
});
|
|
1303
|
+
});
|
|
1304
|
+
});
|
|
1305
|
+
let firings = Object.values(rows).flatMap(row => {
|
|
1306
|
+
let time = AutomationSlice_Schedules$ReventlessCore.timeOf(row);
|
|
1307
|
+
if (time === undefined) {
|
|
1308
|
+
return [];
|
|
1309
|
+
}
|
|
1310
|
+
let _after = from;
|
|
1311
|
+
let _acc = [];
|
|
1312
|
+
let _tries = 0;
|
|
1313
|
+
while (true) {
|
|
1314
|
+
let tries = _tries;
|
|
1315
|
+
let acc = _acc;
|
|
1316
|
+
let after = _after;
|
|
1317
|
+
let next = ScheduleTime$ReventlessCore.nextFiring(time, after);
|
|
1318
|
+
if (next === undefined) {
|
|
1319
|
+
return acc;
|
|
1320
|
+
}
|
|
1321
|
+
if (!(next <= s.now && tries < 1000)) {
|
|
1322
|
+
return acc;
|
|
1323
|
+
}
|
|
1324
|
+
_tries = tries + 1 | 0;
|
|
1325
|
+
_acc = acc.concat([[
|
|
1326
|
+
row.key,
|
|
1327
|
+
next
|
|
1328
|
+
]]);
|
|
1329
|
+
_after = next;
|
|
1330
|
+
continue;
|
|
1331
|
+
};
|
|
1332
|
+
}).toSorted((param, param$1) => Primitive_float.compare(param[1], param$1[1]));
|
|
1333
|
+
return A.routeEach(firings.map(param => A.tick(param[0], param[1])), A.testContext).flatMap(param => param[1]);
|
|
1334
|
+
};
|
|
1335
|
+
let reactWith = (s, ticksOpt) => {
|
|
1336
|
+
let ticks = ticksOpt !== undefined ? ticksOpt : [];
|
|
1337
|
+
let fromLog = routedLog(s).flatMap(param => param[1]);
|
|
1338
|
+
let handled = handledBy(s, key);
|
|
1339
|
+
let commands = A.sweep(fromLog.concat(ticks), s.now, undefined).commands.filter(param => !handled.includes(param[0]));
|
|
1340
|
+
return [
|
|
1341
|
+
markHandled(s, key, commands.map(param => param[0])),
|
|
1342
|
+
commands
|
|
1343
|
+
];
|
|
1344
|
+
};
|
|
1345
|
+
let sent = (s, commands) => ({
|
|
1346
|
+
log: s.log,
|
|
1347
|
+
outcome: s.outcome,
|
|
1348
|
+
lastEvents: s.lastEvents,
|
|
1349
|
+
lastError: s.lastError,
|
|
1350
|
+
lastCommands: commands.map(param => Message$ReventlessCore.encode(param[1], Spec.commandSchema)),
|
|
1351
|
+
lastPublic: s.lastPublic,
|
|
1352
|
+
lastIds: s.lastIds,
|
|
1353
|
+
lastRefusal: undefined,
|
|
1354
|
+
steps: s.steps,
|
|
1355
|
+
at: s.at,
|
|
1356
|
+
failedAt: s.failedAt,
|
|
1357
|
+
now: s.now,
|
|
1358
|
+
caller: s.caller,
|
|
1359
|
+
lastForbidden: s.lastForbidden,
|
|
1360
|
+
handled: s.handled,
|
|
1361
|
+
named: s.named,
|
|
1362
|
+
lastSent: s.lastSent,
|
|
1363
|
+
lastRows: s.lastRows,
|
|
1364
|
+
lastCalls: s.lastCalls
|
|
1365
|
+
});
|
|
1366
|
+
let whenReacts = async (flowP, at) => {
|
|
1367
|
+
let s = await enter(flowP, "whenReacts", part, at);
|
|
1368
|
+
let match = reactWith(markNamed(s, key), undefined);
|
|
1369
|
+
return sent(match[0], match[1]);
|
|
1370
|
+
};
|
|
1371
|
+
let whenTimePasses = async (flowP, until) => {
|
|
1372
|
+
let from = (await flowP).now;
|
|
1373
|
+
let s = await enter(flowP, "whenTimePasses", part, until);
|
|
1374
|
+
let match = s.outcome;
|
|
1375
|
+
if (match.TAG !== "Ok") {
|
|
1376
|
+
return s;
|
|
1377
|
+
}
|
|
1378
|
+
let match$1 = reactWith(markNamed(s, key), dueTicks(s, routedLog(s), from));
|
|
1379
|
+
return sent(match$1[0], match$1[1]);
|
|
1380
|
+
};
|
|
1381
|
+
let reacting_react = async s => {
|
|
1382
|
+
let match = reactWith(s, undefined);
|
|
1383
|
+
return [
|
|
1384
|
+
match[0],
|
|
1385
|
+
match[1].map(param => ({
|
|
1386
|
+
target: Spec.targetName,
|
|
1387
|
+
command: Message$ReventlessCore.encode(param[1], Spec.commandSchema)
|
|
1388
|
+
}))
|
|
1389
|
+
];
|
|
1390
|
+
};
|
|
1391
|
+
let reacting = {
|
|
1392
|
+
key: key,
|
|
1393
|
+
part: part,
|
|
1394
|
+
react: reacting_react
|
|
1395
|
+
};
|
|
1396
|
+
let issued = async (flowP, verb, expected) => encodedCommandsMatch(await enter(flowP, verb, part, undefined), expected.map(c => Message$ReventlessCore.encode(c, Spec.commandSchema)));
|
|
1397
|
+
let thenIssuesCommands = (flowP, expected) => issued(flowP, "thenIssuesCommands", expected);
|
|
1398
|
+
let thenIssuesCommand = (flowP, command) => issued(flowP, "thenIssuesCommand", [command]);
|
|
1399
|
+
let thenIssuesNoCommand = flowP => issued(flowP, "thenIssuesNoCommand", []);
|
|
545
1400
|
return {
|
|
546
1401
|
A: A,
|
|
1402
|
+
part: part,
|
|
1403
|
+
routedLog: routedLog,
|
|
1404
|
+
key: key,
|
|
1405
|
+
dueTicks: dueTicks,
|
|
1406
|
+
reactWith: reactWith,
|
|
1407
|
+
sent: sent,
|
|
547
1408
|
whenReacts: whenReacts,
|
|
1409
|
+
whenTimePasses: whenTimePasses,
|
|
1410
|
+
reacting: reacting,
|
|
1411
|
+
issued: issued,
|
|
548
1412
|
thenIssuesCommands: thenIssuesCommands,
|
|
549
1413
|
thenIssuesCommand: thenIssuesCommand,
|
|
550
1414
|
thenIssuesNoCommand: thenIssuesNoCommand
|
|
@@ -552,17 +1416,22 @@ function AutomationSlice(Spec) {
|
|
|
552
1416
|
};
|
|
553
1417
|
}
|
|
554
1418
|
|
|
555
|
-
function
|
|
1419
|
+
function OutboundStep(Spec) {
|
|
556
1420
|
return Translation => {
|
|
1421
|
+
let part_name = Spec.name;
|
|
1422
|
+
let part = {
|
|
1423
|
+
kind: "Outbound",
|
|
1424
|
+
name: part_name
|
|
1425
|
+
};
|
|
557
1426
|
let consumedDecoder = DcbDecode$Reventless.makeDecoder(Spec.consumedEventSchema);
|
|
558
1427
|
let encItems = arr => arr.map(param => [
|
|
559
1428
|
param[0],
|
|
560
1429
|
Message$ReventlessCore.encode(param[1], Spec.outboundItemSchema)
|
|
561
1430
|
]);
|
|
562
|
-
let
|
|
563
|
-
|
|
564
|
-
let
|
|
565
|
-
let actual = encItems(collected);
|
|
1431
|
+
let collected = s => s.log.flatMap(entry => decodeMatching([entry], consumedDecoder, []).flatMap(e => Translation.collect(e, entry.id)));
|
|
1432
|
+
let outbound = async (flowP, verb, expected) => {
|
|
1433
|
+
let s = await enter(flowP, verb, part, undefined);
|
|
1434
|
+
let actual = encItems(collected(s));
|
|
566
1435
|
let expectedJson = encItems(expected);
|
|
567
1436
|
let o = Primitive_object.equal(actual, expectedJson) ? Outcome$ReventlessGwt.pass : Outcome$ReventlessGwt.fail({
|
|
568
1437
|
TAG: "TodoMismatch",
|
|
@@ -571,21 +1440,119 @@ function OutboundSlice(Spec) {
|
|
|
571
1440
|
});
|
|
572
1441
|
return recordOutcome(s, o);
|
|
573
1442
|
};
|
|
574
|
-
let
|
|
1443
|
+
let key = "outbound:" + Spec.name;
|
|
1444
|
+
let whenSent = async (flowP, fakesOpt, at) => {
|
|
1445
|
+
let fakes = fakesOpt !== undefined ? fakesOpt : Capabilities_Fake$ReventlessGwt.make(undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined);
|
|
1446
|
+
let s = await enter(flowP, "whenSent", part, at);
|
|
1447
|
+
let handled = handledBy(s, key);
|
|
1448
|
+
let items = collected(s).filter(param => !handled.includes(param[0]));
|
|
1449
|
+
let send = async (i, commands, refusal) => {
|
|
1450
|
+
let match = items[i];
|
|
1451
|
+
if (match === undefined) {
|
|
1452
|
+
return [
|
|
1453
|
+
commands,
|
|
1454
|
+
refusal
|
|
1455
|
+
];
|
|
1456
|
+
}
|
|
1457
|
+
if (refusal !== undefined) {
|
|
1458
|
+
return [
|
|
1459
|
+
commands,
|
|
1460
|
+
refusal
|
|
1461
|
+
];
|
|
1462
|
+
}
|
|
1463
|
+
let reason;
|
|
1464
|
+
try {
|
|
1465
|
+
reason = await Translation.translate(match[0], match[1], fakes.capabilities);
|
|
1466
|
+
} catch (raw_e) {
|
|
1467
|
+
let e = Primitive_exceptions.internalToException(raw_e);
|
|
1468
|
+
if (e.RE_EXN_ID === "JsExn") {
|
|
1469
|
+
return [
|
|
1470
|
+
commands,
|
|
1471
|
+
`translate threw: ` + Stdlib_Option.getOr(Stdlib_JsExn.message(e._1), "an exception")
|
|
1472
|
+
];
|
|
1473
|
+
}
|
|
1474
|
+
throw e;
|
|
1475
|
+
}
|
|
1476
|
+
if (reason.TAG !== "Ok") {
|
|
1477
|
+
return [
|
|
1478
|
+
commands,
|
|
1479
|
+
`translate failed: ` + reason._0
|
|
1480
|
+
];
|
|
1481
|
+
}
|
|
1482
|
+
let match$1 = reason._0;
|
|
1483
|
+
if (match$1 !== undefined) {
|
|
1484
|
+
return await send(i + 1 | 0, commands.concat([match$1[1]]), undefined);
|
|
1485
|
+
} else {
|
|
1486
|
+
return await send(i + 1 | 0, commands, undefined);
|
|
1487
|
+
}
|
|
1488
|
+
};
|
|
1489
|
+
let match = await send(0, [], undefined);
|
|
1490
|
+
let init = markHandled(s, key, items.map(param => param[0]));
|
|
1491
|
+
return {
|
|
1492
|
+
log: init.log,
|
|
1493
|
+
outcome: init.outcome,
|
|
1494
|
+
lastEvents: init.lastEvents,
|
|
1495
|
+
lastError: init.lastError,
|
|
1496
|
+
lastCommands: match[0].map(c => Message$ReventlessCore.encode(c, Spec.inboundCommandSchema)),
|
|
1497
|
+
lastPublic: init.lastPublic,
|
|
1498
|
+
lastIds: init.lastIds,
|
|
1499
|
+
lastRefusal: match[1],
|
|
1500
|
+
steps: init.steps,
|
|
1501
|
+
at: init.at,
|
|
1502
|
+
failedAt: init.failedAt,
|
|
1503
|
+
now: init.now,
|
|
1504
|
+
caller: init.caller,
|
|
1505
|
+
lastForbidden: init.lastForbidden,
|
|
1506
|
+
handled: init.handled,
|
|
1507
|
+
named: init.named,
|
|
1508
|
+
lastSent: fakes.calls(),
|
|
1509
|
+
lastRows: init.lastRows,
|
|
1510
|
+
lastCalls: init.lastCalls
|
|
1511
|
+
};
|
|
1512
|
+
};
|
|
1513
|
+
let thenSent = async (flowP, expected) => {
|
|
1514
|
+
let s = await enter(flowP, "thenSent", part, undefined);
|
|
1515
|
+
return recordOutcome(s, Primitive_object.equal(s.lastSent, expected) ? Outcome$ReventlessGwt.pass : Outcome$ReventlessGwt.fail({
|
|
1516
|
+
TAG: "EventsMismatch",
|
|
1517
|
+
expected: expected.map(Capabilities_Fake$ReventlessGwt.toJson),
|
|
1518
|
+
actual: s.lastSent.map(Capabilities_Fake$ReventlessGwt.toJson)
|
|
1519
|
+
}));
|
|
1520
|
+
};
|
|
1521
|
+
let issued = async (flowP, verb, expected) => encodedCommandsMatch(await enter(flowP, verb, part, undefined), expected.map(c => Message$ReventlessCore.encode(c, Spec.inboundCommandSchema)));
|
|
1522
|
+
let thenIssuesCommands = (flowP, expected) => issued(flowP, "thenIssuesCommands", expected);
|
|
1523
|
+
let thenIssuesCommand = (flowP, command) => issued(flowP, "thenIssuesCommand", [command]);
|
|
1524
|
+
let thenIssuesNoCommand = flowP => issued(flowP, "thenIssuesNoCommand", []);
|
|
1525
|
+
let thenOutbound = (flowP, expected) => outbound(flowP, "thenOutbound", expected);
|
|
1526
|
+
let thenOutboundNothing = flowP => outbound(flowP, "thenOutboundNothing", []);
|
|
575
1527
|
return {
|
|
1528
|
+
part: part,
|
|
576
1529
|
consumedDecoder: consumedDecoder,
|
|
577
1530
|
encItems: encItems,
|
|
1531
|
+
collected: collected,
|
|
1532
|
+
outbound: outbound,
|
|
1533
|
+
key: key,
|
|
1534
|
+
whenSent: whenSent,
|
|
1535
|
+
thenSent: thenSent,
|
|
1536
|
+
issued: issued,
|
|
1537
|
+
thenIssuesCommands: thenIssuesCommands,
|
|
1538
|
+
thenIssuesCommand: thenIssuesCommand,
|
|
1539
|
+
thenIssuesNoCommand: thenIssuesNoCommand,
|
|
578
1540
|
thenOutbound: thenOutbound,
|
|
579
1541
|
thenOutboundNothing: thenOutboundNothing
|
|
580
1542
|
};
|
|
581
1543
|
};
|
|
582
1544
|
}
|
|
583
1545
|
|
|
584
|
-
function
|
|
1546
|
+
function InboundStep(Spec) {
|
|
585
1547
|
return Translation => {
|
|
586
1548
|
let I = InboundTranslation_GWT$ReventlessGwt.FromSlice(Spec)(Translation);
|
|
587
|
-
let
|
|
588
|
-
|
|
1549
|
+
let part_name = Spec.name;
|
|
1550
|
+
let part = {
|
|
1551
|
+
kind: "Inbound",
|
|
1552
|
+
name: part_name
|
|
1553
|
+
};
|
|
1554
|
+
let whenReceived = async (flowP, at, json, fakes) => {
|
|
1555
|
+
let s = await enter(flowP, "whenReceived", part, at);
|
|
589
1556
|
let pairs = (await I.whenReceived(json, fakes, undefined)).outcome;
|
|
590
1557
|
switch (pairs.TAG) {
|
|
591
1558
|
case "Translated" :
|
|
@@ -596,8 +1563,19 @@ function InboundSlice(Spec) {
|
|
|
596
1563
|
lastError: s.lastError,
|
|
597
1564
|
lastCommands: pairs._0.map(param => Message$ReventlessCore.encode(param[1], Spec.commandSchema)),
|
|
598
1565
|
lastPublic: s.lastPublic,
|
|
599
|
-
|
|
600
|
-
lastRefusal: undefined
|
|
1566
|
+
lastIds: s.lastIds,
|
|
1567
|
+
lastRefusal: undefined,
|
|
1568
|
+
steps: s.steps,
|
|
1569
|
+
at: s.at,
|
|
1570
|
+
failedAt: s.failedAt,
|
|
1571
|
+
now: s.now,
|
|
1572
|
+
caller: s.caller,
|
|
1573
|
+
lastForbidden: s.lastForbidden,
|
|
1574
|
+
handled: s.handled,
|
|
1575
|
+
named: s.named,
|
|
1576
|
+
lastSent: s.lastSent,
|
|
1577
|
+
lastRows: s.lastRows,
|
|
1578
|
+
lastCalls: s.lastCalls
|
|
601
1579
|
};
|
|
602
1580
|
case "NotUnderstood" :
|
|
603
1581
|
return {
|
|
@@ -607,8 +1585,19 @@ function InboundSlice(Spec) {
|
|
|
607
1585
|
lastError: s.lastError,
|
|
608
1586
|
lastCommands: [],
|
|
609
1587
|
lastPublic: s.lastPublic,
|
|
610
|
-
|
|
611
|
-
lastRefusal: `not understood: ` + pairs._0
|
|
1588
|
+
lastIds: s.lastIds,
|
|
1589
|
+
lastRefusal: `not understood: ` + pairs._0,
|
|
1590
|
+
steps: s.steps,
|
|
1591
|
+
at: s.at,
|
|
1592
|
+
failedAt: s.failedAt,
|
|
1593
|
+
now: s.now,
|
|
1594
|
+
caller: s.caller,
|
|
1595
|
+
lastForbidden: s.lastForbidden,
|
|
1596
|
+
handled: s.handled,
|
|
1597
|
+
named: s.named,
|
|
1598
|
+
lastSent: s.lastSent,
|
|
1599
|
+
lastRows: s.lastRows,
|
|
1600
|
+
lastCalls: s.lastCalls
|
|
612
1601
|
};
|
|
613
1602
|
case "InputRefused" :
|
|
614
1603
|
return {
|
|
@@ -618,17 +1607,31 @@ function InboundSlice(Spec) {
|
|
|
618
1607
|
lastError: s.lastError,
|
|
619
1608
|
lastCommands: [],
|
|
620
1609
|
lastPublic: s.lastPublic,
|
|
621
|
-
|
|
622
|
-
lastRefusal: `input refused: ` + pairs._0
|
|
1610
|
+
lastIds: s.lastIds,
|
|
1611
|
+
lastRefusal: `input refused: ` + pairs._0,
|
|
1612
|
+
steps: s.steps,
|
|
1613
|
+
at: s.at,
|
|
1614
|
+
failedAt: s.failedAt,
|
|
1615
|
+
now: s.now,
|
|
1616
|
+
caller: s.caller,
|
|
1617
|
+
lastForbidden: s.lastForbidden,
|
|
1618
|
+
handled: s.handled,
|
|
1619
|
+
named: s.named,
|
|
1620
|
+
lastSent: s.lastSent,
|
|
1621
|
+
lastRows: s.lastRows,
|
|
1622
|
+
lastCalls: s.lastCalls
|
|
623
1623
|
};
|
|
624
1624
|
}
|
|
625
1625
|
};
|
|
626
|
-
let
|
|
627
|
-
let
|
|
628
|
-
let
|
|
1626
|
+
let issued = async (flowP, verb, expected) => encodedCommandsMatch(await enter(flowP, verb, part, undefined), expected.map(c => Message$ReventlessCore.encode(c, Spec.commandSchema)));
|
|
1627
|
+
let thenIssuesCommands = (flowP, expected) => issued(flowP, "thenIssuesCommands", expected);
|
|
1628
|
+
let thenIssuesCommand = (flowP, command) => issued(flowP, "thenIssuesCommand", [command]);
|
|
1629
|
+
let thenIssuesNoCommand = flowP => issued(flowP, "thenIssuesNoCommand", []);
|
|
629
1630
|
return {
|
|
630
1631
|
I: I,
|
|
1632
|
+
part: part,
|
|
631
1633
|
whenReceived: whenReceived,
|
|
1634
|
+
issued: issued,
|
|
632
1635
|
thenIssuesCommands: thenIssuesCommands,
|
|
633
1636
|
thenIssuesCommand: thenIssuesCommand,
|
|
634
1637
|
thenIssuesNoCommand: thenIssuesNoCommand
|
|
@@ -636,52 +1639,81 @@ function InboundSlice(Spec) {
|
|
|
636
1639
|
};
|
|
637
1640
|
}
|
|
638
1641
|
|
|
1642
|
+
function portName(name) {
|
|
1643
|
+
return Stdlib_Option.getOr(name.split(".").at(-1), name);
|
|
1644
|
+
}
|
|
1645
|
+
|
|
639
1646
|
function sortJson(arr) {
|
|
640
1647
|
return arr.toSorted((a, b) => Primitive_string.compare(JSON.stringify(a), JSON.stringify(b)));
|
|
641
1648
|
}
|
|
642
1649
|
|
|
643
1650
|
function ExtensionPointStep(M) {
|
|
1651
|
+
let part_name = portName(M.ExtensionPoint.name);
|
|
1652
|
+
let part = {
|
|
1653
|
+
kind: "ExtensionPoint",
|
|
1654
|
+
name: part_name
|
|
1655
|
+
};
|
|
644
1656
|
let delegateDecoder = DcbDecode$Reventless.makeDecoder(M.Delegate.eventSchema);
|
|
645
|
-
let runMapping = async
|
|
1657
|
+
let runMapping = async events => {
|
|
646
1658
|
let f = M.mapOutgoingEvent;
|
|
647
1659
|
if (f === undefined) {
|
|
648
1660
|
return [];
|
|
649
1661
|
}
|
|
650
|
-
let actions = events.map(
|
|
1662
|
+
let actions = events.map(param => f(param[0], param[1], StubRuntime$ReventlessGwt.meta, StubRuntime$ReventlessGwt.queryEngine)).flat();
|
|
651
1663
|
return (await Promise.all(actions.map(async action => {
|
|
652
1664
|
switch (action.TAG) {
|
|
653
1665
|
case "PublishEvent" :
|
|
654
|
-
return [
|
|
1666
|
+
return [[
|
|
1667
|
+
action._0,
|
|
1668
|
+
action._1
|
|
1669
|
+
]];
|
|
655
1670
|
case "PublishEventAsync" :
|
|
656
|
-
|
|
657
|
-
return [match[1]];
|
|
1671
|
+
return [await action._0];
|
|
658
1672
|
case "HandleDirective" :
|
|
659
1673
|
return [];
|
|
660
1674
|
}
|
|
661
1675
|
}))).flat();
|
|
662
1676
|
};
|
|
663
|
-
let
|
|
664
|
-
let s = await flowP;
|
|
665
|
-
let delegateEvents = Stdlib_Array.filterMap(s.lastEvents,
|
|
1677
|
+
let whenPublished = async (flowP, at) => {
|
|
1678
|
+
let s = await enter(flowP, "whenPublished", part, at);
|
|
1679
|
+
let delegateEvents = Stdlib_Array.filterMap(s.lastEvents.map((json, i) => [
|
|
1680
|
+
Stdlib_Option.getOr(s.lastIds[i], ""),
|
|
1681
|
+
json
|
|
1682
|
+
]), param => {
|
|
1683
|
+
let json = param[1];
|
|
1684
|
+
let id = param[0];
|
|
666
1685
|
let data;
|
|
667
1686
|
data = typeof json === "object" && json !== null && !Array.isArray(json) ? json : ({});
|
|
668
|
-
return delegateDecoder.decode(Message$Reventless.variantNameOfJson(json), data)
|
|
1687
|
+
return Stdlib_Option.map(delegateDecoder.decode(Message$Reventless.variantNameOfJson(json), data), ev => [
|
|
1688
|
+
id,
|
|
1689
|
+
ev
|
|
1690
|
+
]);
|
|
669
1691
|
});
|
|
670
|
-
let
|
|
671
|
-
let publicEvents = await runMapping(sourceId, delegateEvents);
|
|
1692
|
+
let publicEvents = await runMapping(delegateEvents);
|
|
672
1693
|
return {
|
|
673
|
-
log:
|
|
1694
|
+
log: s.log.concat(publicEvents.map(param => entryOf(param[1], M.ExtensionPoint.eventSchema, s.now, undefined, param[0], undefined))),
|
|
674
1695
|
outcome: s.outcome,
|
|
675
1696
|
lastEvents: s.lastEvents,
|
|
676
1697
|
lastError: s.lastError,
|
|
677
1698
|
lastCommands: s.lastCommands,
|
|
678
|
-
lastPublic: publicEvents.map(
|
|
679
|
-
|
|
680
|
-
lastRefusal: s.lastRefusal
|
|
1699
|
+
lastPublic: publicEvents.map(param => Message$ReventlessCore.encode(param[1], M.ExtensionPoint.eventSchema)),
|
|
1700
|
+
lastIds: s.lastIds,
|
|
1701
|
+
lastRefusal: s.lastRefusal,
|
|
1702
|
+
steps: s.steps,
|
|
1703
|
+
at: s.at,
|
|
1704
|
+
failedAt: s.failedAt,
|
|
1705
|
+
now: s.now,
|
|
1706
|
+
caller: s.caller,
|
|
1707
|
+
lastForbidden: s.lastForbidden,
|
|
1708
|
+
handled: s.handled,
|
|
1709
|
+
named: s.named,
|
|
1710
|
+
lastSent: s.lastSent,
|
|
1711
|
+
lastRows: s.lastRows,
|
|
1712
|
+
lastCalls: s.lastCalls
|
|
681
1713
|
};
|
|
682
1714
|
};
|
|
683
|
-
let
|
|
684
|
-
let s = await flowP;
|
|
1715
|
+
let published = async (flowP, verb, expected) => {
|
|
1716
|
+
let s = await enter(flowP, verb, part, undefined);
|
|
685
1717
|
let expJson = expected.map(e => Message$ReventlessCore.encode(e, M.ExtensionPoint.eventSchema));
|
|
686
1718
|
let o = Primitive_object.equal(sortJson(s.lastPublic), sortJson(expJson)) ? Outcome$ReventlessGwt.pass : Outcome$ReventlessGwt.fail({
|
|
687
1719
|
TAG: "PublishedActionsMismatch",
|
|
@@ -690,27 +1722,46 @@ function ExtensionPointStep(M) {
|
|
|
690
1722
|
});
|
|
691
1723
|
return recordOutcome(s, o);
|
|
692
1724
|
};
|
|
693
|
-
let
|
|
1725
|
+
let thenPublicEvents = (flowP, expected) => published(flowP, "thenPublicEvents", expected);
|
|
1726
|
+
let thenPublicEvent = (flowP, event) => published(flowP, "thenPublicEvent", [event]);
|
|
694
1727
|
return {
|
|
1728
|
+
part: part,
|
|
695
1729
|
delegateDecoder: delegateDecoder,
|
|
696
1730
|
runMapping: runMapping,
|
|
697
|
-
|
|
1731
|
+
whenPublished: whenPublished,
|
|
1732
|
+
published: published,
|
|
698
1733
|
thenPublicEvents: thenPublicEvents,
|
|
699
1734
|
thenPublicEvent: thenPublicEvent
|
|
700
1735
|
};
|
|
701
1736
|
}
|
|
702
1737
|
|
|
703
1738
|
function ExtensionStep(M) {
|
|
1739
|
+
let part_name = portName(M.ExtensionPoint.name);
|
|
1740
|
+
let part = {
|
|
1741
|
+
kind: "Extension",
|
|
1742
|
+
name: part_name
|
|
1743
|
+
};
|
|
704
1744
|
let epDecoder = DcbDecode$Reventless.makeDecoder(M.ExtensionPoint.eventSchema);
|
|
705
1745
|
let encCmd = c => Message$ReventlessCore.encode(c, M.Delegate.commandSchema);
|
|
706
|
-
let
|
|
707
|
-
|
|
708
|
-
let
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
1746
|
+
let key = "extension:" + part_name;
|
|
1747
|
+
let reactWith = async s => {
|
|
1748
|
+
let handled = handledBy(s, key);
|
|
1749
|
+
let fresh = Stdlib_Array.filterMap(s.log.map((entry, i) => [
|
|
1750
|
+
i.toString(),
|
|
1751
|
+
entry
|
|
1752
|
+
]), param => {
|
|
1753
|
+
let i = param[0];
|
|
1754
|
+
if (handled.includes(i)) {
|
|
1755
|
+
return;
|
|
1756
|
+
}
|
|
1757
|
+
let entry = param[1];
|
|
1758
|
+
return Stdlib_Option.map(decodeMatching([entry], epDecoder, [])[0], ev => [
|
|
1759
|
+
i,
|
|
1760
|
+
entry.id,
|
|
1761
|
+
ev
|
|
1762
|
+
]);
|
|
712
1763
|
});
|
|
713
|
-
let actions =
|
|
1764
|
+
let actions = fresh.map(param => M.mapIncomingEvent(param[1], param[2], StubRuntime$ReventlessGwt.meta, StubRuntime$ReventlessGwt.pluginDefinition, StubRuntime$ReventlessGwt.queryEngine)).flat();
|
|
714
1765
|
let nested = await Promise.all(actions.map(async action => {
|
|
715
1766
|
switch (action.TAG) {
|
|
716
1767
|
case "PublishAggregateCommand" :
|
|
@@ -731,19 +1782,54 @@ function ExtensionStep(M) {
|
|
|
731
1782
|
return [];
|
|
732
1783
|
}
|
|
733
1784
|
}));
|
|
1785
|
+
return [
|
|
1786
|
+
markHandled(s, key, fresh.map(param => param[0])),
|
|
1787
|
+
nested.flat()
|
|
1788
|
+
];
|
|
1789
|
+
};
|
|
1790
|
+
let whenReacts = async (flowP, at) => {
|
|
1791
|
+
let s = await enter(flowP, "whenReacts", part, at);
|
|
1792
|
+
let match = await reactWith(markNamed(s, key));
|
|
1793
|
+
let s$1 = match[0];
|
|
734
1794
|
return {
|
|
735
|
-
log: s.log,
|
|
736
|
-
outcome: s.outcome,
|
|
737
|
-
lastEvents: s.lastEvents,
|
|
738
|
-
lastError: s.lastError,
|
|
739
|
-
lastCommands:
|
|
740
|
-
lastPublic: s.lastPublic,
|
|
741
|
-
|
|
742
|
-
lastRefusal: s.lastRefusal
|
|
1795
|
+
log: s$1.log,
|
|
1796
|
+
outcome: s$1.outcome,
|
|
1797
|
+
lastEvents: s$1.lastEvents,
|
|
1798
|
+
lastError: s$1.lastError,
|
|
1799
|
+
lastCommands: match[1],
|
|
1800
|
+
lastPublic: s$1.lastPublic,
|
|
1801
|
+
lastIds: s$1.lastIds,
|
|
1802
|
+
lastRefusal: s$1.lastRefusal,
|
|
1803
|
+
steps: s$1.steps,
|
|
1804
|
+
at: s$1.at,
|
|
1805
|
+
failedAt: s$1.failedAt,
|
|
1806
|
+
now: s$1.now,
|
|
1807
|
+
caller: s$1.caller,
|
|
1808
|
+
lastForbidden: s$1.lastForbidden,
|
|
1809
|
+
handled: s$1.handled,
|
|
1810
|
+
named: s$1.named,
|
|
1811
|
+
lastSent: s$1.lastSent,
|
|
1812
|
+
lastRows: s$1.lastRows,
|
|
1813
|
+
lastCalls: s$1.lastCalls
|
|
743
1814
|
};
|
|
744
1815
|
};
|
|
745
|
-
let
|
|
746
|
-
let
|
|
1816
|
+
let reacting_react = async s => {
|
|
1817
|
+
let match = await reactWith(s);
|
|
1818
|
+
return [
|
|
1819
|
+
match[0],
|
|
1820
|
+
match[1].map(command => ({
|
|
1821
|
+
target: M.Delegate.name,
|
|
1822
|
+
command: command
|
|
1823
|
+
}))
|
|
1824
|
+
];
|
|
1825
|
+
};
|
|
1826
|
+
let reacting = {
|
|
1827
|
+
key: key,
|
|
1828
|
+
part: part,
|
|
1829
|
+
react: reacting_react
|
|
1830
|
+
};
|
|
1831
|
+
let issued = async (flowP, verb, expected) => {
|
|
1832
|
+
let s = await enter(flowP, verb, part, undefined);
|
|
747
1833
|
let expJson = expected.map(encCmd);
|
|
748
1834
|
let o = Primitive_object.equal(sortJson(s.lastCommands), sortJson(expJson)) ? Outcome$ReventlessGwt.pass : Outcome$ReventlessGwt.fail({
|
|
749
1835
|
TAG: "PublishedActionsMismatch",
|
|
@@ -752,50 +1838,303 @@ function ExtensionStep(M) {
|
|
|
752
1838
|
});
|
|
753
1839
|
return recordOutcome(s, o);
|
|
754
1840
|
};
|
|
755
|
-
let
|
|
756
|
-
let
|
|
1841
|
+
let thenIssuesCommands = (flowP, expected) => issued(flowP, "thenIssuesCommands", expected);
|
|
1842
|
+
let thenIssuesCommand = (flowP, command) => issued(flowP, "thenIssuesCommand", [command]);
|
|
1843
|
+
let thenIssuesNoCommand = flowP => issued(flowP, "thenIssuesNoCommand", []);
|
|
757
1844
|
return {
|
|
1845
|
+
part: part,
|
|
758
1846
|
epDecoder: epDecoder,
|
|
759
1847
|
encCmd: encCmd,
|
|
760
|
-
|
|
1848
|
+
key: key,
|
|
1849
|
+
reactWith: reactWith,
|
|
1850
|
+
whenReacts: whenReacts,
|
|
1851
|
+
reacting: reacting,
|
|
1852
|
+
issued: issued,
|
|
761
1853
|
thenIssuesCommands: thenIssuesCommands,
|
|
762
1854
|
thenIssuesCommand: thenIssuesCommand,
|
|
763
1855
|
thenIssuesNoCommand: thenIssuesNoCommand
|
|
764
1856
|
};
|
|
765
1857
|
}
|
|
766
1858
|
|
|
1859
|
+
async function reactAll(s, reacting) {
|
|
1860
|
+
let go = async (s, i, sent) => {
|
|
1861
|
+
let r = reacting[i];
|
|
1862
|
+
if (r === undefined) {
|
|
1863
|
+
return [
|
|
1864
|
+
s,
|
|
1865
|
+
sent
|
|
1866
|
+
];
|
|
1867
|
+
}
|
|
1868
|
+
let match = await r.react(s);
|
|
1869
|
+
return await go(match[0], i + 1 | 0, sent.concat(match[1].map(x => [
|
|
1870
|
+
r,
|
|
1871
|
+
x
|
|
1872
|
+
])));
|
|
1873
|
+
};
|
|
1874
|
+
return await go(s, 0, []);
|
|
1875
|
+
}
|
|
1876
|
+
|
|
1877
|
+
async function thenNothingElseReacts(flowP, systems) {
|
|
1878
|
+
let s = await enter(flowP, "thenNothingElseReacts", undefined, undefined);
|
|
1879
|
+
let unnamed = systems.flatMap(p => p.reacting).filter(r => !s.named.includes(r.key));
|
|
1880
|
+
let match = await reactAll(s, unnamed);
|
|
1881
|
+
let sent = match[1];
|
|
1882
|
+
let match$1 = sent[0];
|
|
1883
|
+
let s$1;
|
|
1884
|
+
if (match$1 !== undefined) {
|
|
1885
|
+
let r = match$1[0];
|
|
1886
|
+
s$1 = {
|
|
1887
|
+
log: s.log,
|
|
1888
|
+
outcome: s.outcome,
|
|
1889
|
+
lastEvents: s.lastEvents,
|
|
1890
|
+
lastError: s.lastError,
|
|
1891
|
+
lastCommands: s.lastCommands,
|
|
1892
|
+
lastPublic: s.lastPublic,
|
|
1893
|
+
lastIds: s.lastIds,
|
|
1894
|
+
lastRefusal: s.lastRefusal,
|
|
1895
|
+
steps: s.steps,
|
|
1896
|
+
at: Stdlib_Option.map(s.at, step => {
|
|
1897
|
+
let newrecord = {...step};
|
|
1898
|
+
newrecord.part = r.part;
|
|
1899
|
+
return newrecord;
|
|
1900
|
+
}),
|
|
1901
|
+
failedAt: s.failedAt,
|
|
1902
|
+
now: s.now,
|
|
1903
|
+
caller: s.caller,
|
|
1904
|
+
lastForbidden: s.lastForbidden,
|
|
1905
|
+
handled: s.handled,
|
|
1906
|
+
named: s.named,
|
|
1907
|
+
lastSent: s.lastSent,
|
|
1908
|
+
lastRows: s.lastRows,
|
|
1909
|
+
lastCalls: s.lastCalls
|
|
1910
|
+
};
|
|
1911
|
+
} else {
|
|
1912
|
+
s$1 = s;
|
|
1913
|
+
}
|
|
1914
|
+
return recordOutcome(s$1, sent.length !== 0 ? Outcome$ReventlessGwt.fail({
|
|
1915
|
+
TAG: "PublishedActionsMismatch",
|
|
1916
|
+
expected: [],
|
|
1917
|
+
actual: sent.map(param => Object.fromEntries([
|
|
1918
|
+
[
|
|
1919
|
+
"reacts",
|
|
1920
|
+
param[0].part.name
|
|
1921
|
+
],
|
|
1922
|
+
[
|
|
1923
|
+
"sends",
|
|
1924
|
+
param[1].command
|
|
1925
|
+
]
|
|
1926
|
+
]))
|
|
1927
|
+
}) : Outcome$ReventlessGwt.pass);
|
|
1928
|
+
}
|
|
1929
|
+
|
|
1930
|
+
async function whenSettled(flowP, systems) {
|
|
1931
|
+
let s = await enter(flowP, "whenSettled", undefined, undefined);
|
|
1932
|
+
let reacting = systems.flatMap(p => p.reacting);
|
|
1933
|
+
let deciding = systems.flatMap(p => p.deciding);
|
|
1934
|
+
let decide = (s, param) => {
|
|
1935
|
+
let command = param.command;
|
|
1936
|
+
let s$1 = Stdlib_Option.flatMap(Stdlib_Option.flatMap(param.target, t => deciding.find(d => d.name === t)), d => d.run(s, command));
|
|
1937
|
+
if (s$1 !== undefined) {
|
|
1938
|
+
return s$1;
|
|
1939
|
+
} else {
|
|
1940
|
+
return Stdlib_Array.findMap(deciding, d => d.run(s, command));
|
|
1941
|
+
}
|
|
1942
|
+
};
|
|
1943
|
+
let round = async (s, n, events, commands) => {
|
|
1944
|
+
let match = await reactAll(s, reacting);
|
|
1945
|
+
let sent = match[1];
|
|
1946
|
+
let s$1 = Stdlib_Array.reduce(reacting, match[0], (s, r) => markNamed(s, r.key));
|
|
1947
|
+
if (sent.length === 0) {
|
|
1948
|
+
return {
|
|
1949
|
+
log: s$1.log,
|
|
1950
|
+
outcome: s$1.outcome,
|
|
1951
|
+
lastEvents: events,
|
|
1952
|
+
lastError: s$1.lastError,
|
|
1953
|
+
lastCommands: commands,
|
|
1954
|
+
lastPublic: s$1.lastPublic,
|
|
1955
|
+
lastIds: s$1.lastIds,
|
|
1956
|
+
lastRefusal: s$1.lastRefusal,
|
|
1957
|
+
steps: s$1.steps,
|
|
1958
|
+
at: s$1.at,
|
|
1959
|
+
failedAt: s$1.failedAt,
|
|
1960
|
+
now: s$1.now,
|
|
1961
|
+
caller: s$1.caller,
|
|
1962
|
+
lastForbidden: s$1.lastForbidden,
|
|
1963
|
+
handled: s$1.handled,
|
|
1964
|
+
named: s$1.named,
|
|
1965
|
+
lastSent: s$1.lastSent,
|
|
1966
|
+
lastRows: s$1.lastRows,
|
|
1967
|
+
lastCalls: s$1.lastCalls
|
|
1968
|
+
};
|
|
1969
|
+
}
|
|
1970
|
+
if (n >= 20) {
|
|
1971
|
+
return recordOutcome(s$1, Outcome$ReventlessGwt.fail({
|
|
1972
|
+
TAG: "Throw",
|
|
1973
|
+
error: `the flow does not settle: still sending after ` + (20).toString() + ` rounds`,
|
|
1974
|
+
stack: ""
|
|
1975
|
+
}));
|
|
1976
|
+
}
|
|
1977
|
+
let match$1 = Stdlib_Array.reduce(sent, [
|
|
1978
|
+
s$1,
|
|
1979
|
+
events,
|
|
1980
|
+
undefined
|
|
1981
|
+
], (param, param$1) => {
|
|
1982
|
+
let unread = param[2];
|
|
1983
|
+
let events = param[1];
|
|
1984
|
+
let s = param[0];
|
|
1985
|
+
if (unread !== undefined) {
|
|
1986
|
+
return [
|
|
1987
|
+
s,
|
|
1988
|
+
events,
|
|
1989
|
+
unread
|
|
1990
|
+
];
|
|
1991
|
+
}
|
|
1992
|
+
let reaction = param$1[1];
|
|
1993
|
+
let next = decide(s, reaction);
|
|
1994
|
+
if (next !== undefined) {
|
|
1995
|
+
return [
|
|
1996
|
+
next,
|
|
1997
|
+
events.concat(next.lastEvents),
|
|
1998
|
+
undefined
|
|
1999
|
+
];
|
|
2000
|
+
} else {
|
|
2001
|
+
return [
|
|
2002
|
+
s,
|
|
2003
|
+
events,
|
|
2004
|
+
reaction.command
|
|
2005
|
+
];
|
|
2006
|
+
}
|
|
2007
|
+
});
|
|
2008
|
+
let unread = match$1[2];
|
|
2009
|
+
let s$2 = match$1[0];
|
|
2010
|
+
if (unread !== undefined) {
|
|
2011
|
+
return recordOutcome(s$2, Outcome$ReventlessGwt.fail({
|
|
2012
|
+
TAG: "TranslateError",
|
|
2013
|
+
expected: "a decision of the systems given that reads the command",
|
|
2014
|
+
actual: `no decision reads ` + JSON.stringify(unread)
|
|
2015
|
+
}));
|
|
2016
|
+
} else {
|
|
2017
|
+
return await round(s$2, n + 1 | 0, match$1[1], commands.concat(sent.map(param => param[1].command)));
|
|
2018
|
+
}
|
|
2019
|
+
};
|
|
2020
|
+
return await round({
|
|
2021
|
+
log: s.log,
|
|
2022
|
+
outcome: s.outcome,
|
|
2023
|
+
lastEvents: [],
|
|
2024
|
+
lastError: undefined,
|
|
2025
|
+
lastCommands: s.lastCommands,
|
|
2026
|
+
lastPublic: s.lastPublic,
|
|
2027
|
+
lastIds: s.lastIds,
|
|
2028
|
+
lastRefusal: s.lastRefusal,
|
|
2029
|
+
steps: s.steps,
|
|
2030
|
+
at: s.at,
|
|
2031
|
+
failedAt: s.failedAt,
|
|
2032
|
+
now: s.now,
|
|
2033
|
+
caller: s.caller,
|
|
2034
|
+
lastForbidden: s.lastForbidden,
|
|
2035
|
+
handled: s.handled,
|
|
2036
|
+
named: s.named,
|
|
2037
|
+
lastSent: s.lastSent,
|
|
2038
|
+
lastRows: s.lastRows,
|
|
2039
|
+
lastCalls: s.lastCalls
|
|
2040
|
+
}, 0, [], []);
|
|
2041
|
+
}
|
|
2042
|
+
|
|
2043
|
+
function CommandStep(_) {
|
|
2044
|
+
return _ => ({});
|
|
2045
|
+
}
|
|
2046
|
+
|
|
2047
|
+
function AggregateCommandStep(_) {
|
|
2048
|
+
return _ => ({});
|
|
2049
|
+
}
|
|
2050
|
+
|
|
2051
|
+
function AutomationSlice(_) {
|
|
2052
|
+
return _ => ({});
|
|
2053
|
+
}
|
|
2054
|
+
|
|
2055
|
+
function OutboundSlice(_) {
|
|
2056
|
+
return _ => ({});
|
|
2057
|
+
}
|
|
2058
|
+
|
|
2059
|
+
function InboundSlice(_) {
|
|
2060
|
+
return _ => ({});
|
|
2061
|
+
}
|
|
2062
|
+
|
|
2063
|
+
function thenBoundaryScopeResolves(param, param$1, param$2) {
|
|
2064
|
+
|
|
2065
|
+
}
|
|
2066
|
+
|
|
2067
|
+
let Caller;
|
|
2068
|
+
|
|
2069
|
+
let Fakes;
|
|
2070
|
+
|
|
767
2071
|
let EPMapping;
|
|
768
2072
|
|
|
769
2073
|
let ExtMapping;
|
|
770
2074
|
|
|
771
2075
|
let describe = JestBind$ReventlessGwt.describe;
|
|
772
2076
|
|
|
2077
|
+
let settleBound = 20;
|
|
2078
|
+
|
|
773
2079
|
export {
|
|
2080
|
+
Caller,
|
|
2081
|
+
Fakes,
|
|
774
2082
|
EPMapping,
|
|
775
2083
|
ExtMapping,
|
|
2084
|
+
sourceIdOf,
|
|
2085
|
+
handledBy,
|
|
2086
|
+
markHandled,
|
|
2087
|
+
markNamed,
|
|
776
2088
|
emptyState,
|
|
777
2089
|
start,
|
|
778
2090
|
recordOutcome,
|
|
2091
|
+
iso,
|
|
2092
|
+
enter,
|
|
779
2093
|
entryMatchesQuery,
|
|
2094
|
+
entryOf,
|
|
780
2095
|
appendEvents,
|
|
781
2096
|
appendAggregateEvents,
|
|
2097
|
+
lastIdsOf,
|
|
782
2098
|
decodeMatching,
|
|
783
2099
|
decodeAggregateMatching,
|
|
784
2100
|
describe,
|
|
2101
|
+
outcomeOf,
|
|
2102
|
+
elevated,
|
|
2103
|
+
flows,
|
|
785
2104
|
test,
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
2105
|
+
after,
|
|
2106
|
+
asCaller,
|
|
2107
|
+
eventsWere,
|
|
2108
|
+
errorWas,
|
|
2109
|
+
noEventWas,
|
|
2110
|
+
acceptedWas,
|
|
2111
|
+
forbiddenCode,
|
|
2112
|
+
forbidden,
|
|
2113
|
+
forbiddenWas,
|
|
2114
|
+
issued,
|
|
2115
|
+
runIssued,
|
|
2116
|
+
DecisionStep,
|
|
2117
|
+
AggregateStep,
|
|
790
2118
|
ViewStep,
|
|
791
|
-
|
|
792
|
-
|
|
2119
|
+
QueryStep,
|
|
2120
|
+
SideEffectStep,
|
|
793
2121
|
encodedCommandsMatch,
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
2122
|
+
AutomationStep,
|
|
2123
|
+
OutboundStep,
|
|
2124
|
+
InboundStep,
|
|
2125
|
+
portName,
|
|
797
2126
|
sortJson,
|
|
798
2127
|
ExtensionPointStep,
|
|
799
2128
|
ExtensionStep,
|
|
2129
|
+
reactAll,
|
|
2130
|
+
thenNothingElseReacts,
|
|
2131
|
+
settleBound,
|
|
2132
|
+
whenSettled,
|
|
2133
|
+
CommandStep,
|
|
2134
|
+
AggregateCommandStep,
|
|
2135
|
+
AutomationSlice,
|
|
2136
|
+
OutboundSlice,
|
|
2137
|
+
InboundSlice,
|
|
2138
|
+
thenBoundaryScopeResolves,
|
|
800
2139
|
}
|
|
801
2140
|
/* start Not a pure module */
|