@reventlessdev/reventless-gwt 1.0.0-alpha.231 → 1.0.0-alpha.233

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.
@@ -0,0 +1,326 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Sury from "sury";
4
+ import * as Owner$Reventless from "@reventlessdev/reventless-spec/src/components/Owner.res.mjs";
5
+ import * as DcbTag$Reventless from "@reventlessdev/reventless-spec/src/components/DcbTag.res.mjs";
6
+ import * as Behavior_GWT$ReventlessGwt from "../src/Behavior_GWT.res.mjs";
7
+
8
+ let name = "Shelve";
9
+
10
+ let Roles = {};
11
+
12
+ let consumedEventSchema = Sury.$schema(s => ({
13
+ TAG: "ShelfOpened",
14
+ shelfId: s.m(DcbTag$Reventless.string)
15
+ }));
16
+
17
+ let commandSchema = Sury.union([
18
+ Sury.$schema(s => ({
19
+ TAG: "Shelve",
20
+ shelfId: s.m(DcbTag$Reventless.string)
21
+ })),
22
+ Sury.$schema(s => ({
23
+ TAG: "Browse",
24
+ shelfId: s.m(DcbTag$Reventless.string)
25
+ })),
26
+ Sury.$schema(s => ({
27
+ TAG: "Peek",
28
+ shelfId: s.m(DcbTag$Reventless.string)
29
+ })),
30
+ Sury.$schema(s => ({
31
+ TAG: "Purge",
32
+ shelfId: s.m(DcbTag$Reventless.string)
33
+ }))
34
+ ]);
35
+
36
+ let errorSchema = Sury.$unit;
37
+
38
+ let eventSchema = Sury.$schema(s => ({
39
+ TAG: "Done",
40
+ shelfId: s.m(DcbTag$Reventless.string)
41
+ }));
42
+
43
+ function commandAuthorization(command) {
44
+ switch (command.TAG) {
45
+ case "Shelve" :
46
+ return {
47
+ TAG: "AllowRoles",
48
+ _0: [
49
+ "Admin",
50
+ "Merchandiser"
51
+ ]
52
+ };
53
+ case "Browse" :
54
+ return "AllowAuthenticated";
55
+ case "Peek" :
56
+ return "AllowAnonymous";
57
+ case "Purge" :
58
+ return "DenyAll";
59
+ }
60
+ }
61
+
62
+ function commandTransition(param) {
63
+ return "Undeclared";
64
+ }
65
+
66
+ let traits = [];
67
+
68
+ let ShelveSlice = {
69
+ name: name,
70
+ Roles: Roles,
71
+ consumedEventSchema: consumedEventSchema,
72
+ commandSchema: commandSchema,
73
+ errorSchema: errorSchema,
74
+ eventSchema: eventSchema,
75
+ commandAuthorization: commandAuthorization,
76
+ commandTransition: commandTransition,
77
+ traits: traits,
78
+ readConsistency: "EscalateOnRetry"
79
+ };
80
+
81
+ function evolve(_state, _event) {
82
+
83
+ }
84
+
85
+ function decide(_state, command) {
86
+ return {
87
+ TAG: "Ok",
88
+ _0: [{
89
+ TAG: "Done",
90
+ shelfId: command.shelfId
91
+ }]
92
+ };
93
+ }
94
+
95
+ let ShelveSliceBehavior = {
96
+ Spec: undefined,
97
+ initialState: undefined,
98
+ evolve: evolve,
99
+ decide: decide
100
+ };
101
+
102
+ let include = Behavior_GWT$ReventlessGwt.Make({
103
+ name: name,
104
+ consumedEventSchema: consumedEventSchema,
105
+ commandSchema: commandSchema,
106
+ errorSchema: errorSchema,
107
+ eventSchema: eventSchema,
108
+ commandAuthorization: commandAuthorization
109
+ })({
110
+ initialState: undefined,
111
+ evolve: evolve,
112
+ decide: decide
113
+ });
114
+
115
+ let describe = include.describe;
116
+
117
+ let test = include.test;
118
+
119
+ let givenEvents = include.givenEvents;
120
+
121
+ let Caller = include.Caller;
122
+
123
+ let asCaller = include.asCaller;
124
+
125
+ let whenCmd = include.whenCmd;
126
+
127
+ let thenEvent = include.thenEvent;
128
+
129
+ let thenRefused = include.thenRefused;
130
+
131
+ let s1 = "s1";
132
+
133
+ describe("a command's rule, checked against the caller's roles", () => {
134
+ test("accepted for each role the rule names: Admin", () => thenEvent(whenCmd(asCaller(givenEvents([]), Caller.inRoles(["Admin"])), {
135
+ TAG: "Shelve",
136
+ shelfId: s1
137
+ }), {
138
+ TAG: "Done",
139
+ shelfId: s1
140
+ }));
141
+ test("accepted for each role the rule names: Merchandiser", () => thenEvent(whenCmd(asCaller(givenEvents([]), Caller.inRoles(["Merchandiser"])), {
142
+ TAG: "Shelve",
143
+ shelfId: s1
144
+ }), {
145
+ TAG: "Done",
146
+ shelfId: s1
147
+ }));
148
+ test("refused for a signed-in caller holding none of them", () => thenRefused(whenCmd(asCaller(givenEvents([]), Caller.owner("c1", undefined)), {
149
+ TAG: "Shelve",
150
+ shelfId: s1
151
+ })));
152
+ test("refused for an anonymous caller", () => thenRefused(whenCmd(asCaller(givenEvents([]), Caller.anonymous), {
153
+ TAG: "Shelve",
154
+ shelfId: s1
155
+ })));
156
+ test("refused for an operator, who holds no role", () => thenRefused(whenCmd(asCaller(givenEvents([]), Caller.operator), {
157
+ TAG: "Shelve",
158
+ shelfId: s1
159
+ })));
160
+ test("DenyAll refuses every caller, Admin included", () => thenRefused(whenCmd(asCaller(givenEvents([]), Caller.inRoles(["Admin"])), {
161
+ TAG: "Purge",
162
+ shelfId: s1
163
+ })));
164
+ test("AllowAnonymous accepts an anonymous caller", () => thenEvent(whenCmd(asCaller(givenEvents([]), Caller.anonymous), {
165
+ TAG: "Peek",
166
+ shelfId: s1
167
+ }), {
168
+ TAG: "Done",
169
+ shelfId: s1
170
+ }));
171
+ test("the default rule refuses an anonymous caller", () => thenRefused(whenCmd(asCaller(givenEvents([]), Caller.anonymous), {
172
+ TAG: "Browse",
173
+ shelfId: s1
174
+ })));
175
+ test("a scenario without asCaller is checked against no rule", () => thenEvent(whenCmd(givenEvents([]), {
176
+ TAG: "Purge",
177
+ shelfId: s1
178
+ }), {
179
+ TAG: "Done",
180
+ shelfId: s1
181
+ }));
182
+ });
183
+
184
+ let name$1 = "Claim";
185
+
186
+ let Roles$1 = {};
187
+
188
+ let consumedEventSchema$1 = Sury.$schema(s => ({
189
+ TAG: "ShelfClaimed",
190
+ shelfId: s.m(DcbTag$Reventless.string),
191
+ owner: s.m(Owner$Reventless.string)
192
+ }));
193
+
194
+ let commandSchema$1 = Sury.$schema(s => ({
195
+ TAG: "Shelve",
196
+ shelfId: s.m(DcbTag$Reventless.string)
197
+ }));
198
+
199
+ let errorSchema$1 = Sury.$unit;
200
+
201
+ let eventSchema$1 = Sury.$schema(s => ({
202
+ TAG: "Done",
203
+ shelfId: s.m(DcbTag$Reventless.string)
204
+ }));
205
+
206
+ function commandAuthorization$1(command) {
207
+ return {
208
+ TAG: "AllowRoles",
209
+ _0: ["Merchandiser"]
210
+ };
211
+ }
212
+
213
+ function commandTransition$1(param) {
214
+ return "Undeclared";
215
+ }
216
+
217
+ let traits$1 = [];
218
+
219
+ let ClaimSlice = {
220
+ name: name$1,
221
+ Roles: Roles$1,
222
+ consumedEventSchema: consumedEventSchema$1,
223
+ commandSchema: commandSchema$1,
224
+ errorSchema: errorSchema$1,
225
+ eventSchema: eventSchema$1,
226
+ commandAuthorization: commandAuthorization$1,
227
+ commandTransition: commandTransition$1,
228
+ traits: traits$1,
229
+ readConsistency: "EscalateOnRetry"
230
+ };
231
+
232
+ function evolve$1(_state, _event) {
233
+
234
+ }
235
+
236
+ function decide$1(_state, command) {
237
+ return {
238
+ TAG: "Ok",
239
+ _0: [{
240
+ TAG: "Done",
241
+ shelfId: command.shelfId
242
+ }]
243
+ };
244
+ }
245
+
246
+ let Claim = Behavior_GWT$ReventlessGwt.Make({
247
+ name: name$1,
248
+ consumedEventSchema: consumedEventSchema$1,
249
+ commandSchema: commandSchema$1,
250
+ errorSchema: errorSchema$1,
251
+ eventSchema: eventSchema$1,
252
+ commandAuthorization: commandAuthorization$1
253
+ })({
254
+ initialState: undefined,
255
+ evolve: evolve$1,
256
+ decide: decide$1
257
+ });
258
+
259
+ let claimedByC1 = [{
260
+ TAG: "ShelfClaimed",
261
+ shelfId: s1,
262
+ owner: "c1"
263
+ }];
264
+
265
+ describe("the rule, then ownership", () => {
266
+ Claim.test("an owner holding the role acts on what they own", () => Claim.thenEvent(Claim.whenCmd(Claim.asCaller(Claim.givenEvents(claimedByC1), Claim.Caller.owner("c1", ["Merchandiser"])), {
267
+ TAG: "Shelve",
268
+ shelfId: s1
269
+ }), {
270
+ TAG: "Done",
271
+ shelfId: s1
272
+ }));
273
+ Claim.test("passing the rule does not let a caller act on someone else's thing", () => Claim.thenRefused(Claim.whenCmd(Claim.asCaller(Claim.givenEvents(claimedByC1), Claim.Caller.owner("c2", ["Merchandiser"])), {
274
+ TAG: "Shelve",
275
+ shelfId: s1
276
+ })));
277
+ Claim.test("owning a thing does not pass a rule the owner fails", () => Claim.thenRefused(Claim.whenCmd(Claim.asCaller(Claim.givenEvents(claimedByC1), Claim.Caller.owner("c1", undefined)), {
278
+ TAG: "Shelve",
279
+ shelfId: s1
280
+ })));
281
+ });
282
+
283
+ let Spec = include.Spec;
284
+
285
+ let todo = include.todo;
286
+
287
+ let thenEvents = include.thenEvents;
288
+
289
+ let thenNoEvent = include.thenNoEvent;
290
+
291
+ let thenEventWithError = include.thenEventWithError;
292
+
293
+ let thenEventsWithError = include.thenEventsWithError;
294
+
295
+ let thenError = include.thenError;
296
+
297
+ let thenAppendsConditionedOn = include.thenAppendsConditionedOn;
298
+
299
+ let thenAppendsConditionedOnExactly = include.thenAppendsConditionedOnExactly;
300
+
301
+ export {
302
+ ShelveSlice,
303
+ ShelveSliceBehavior,
304
+ Spec,
305
+ describe,
306
+ todo,
307
+ test,
308
+ givenEvents,
309
+ Caller,
310
+ asCaller,
311
+ whenCmd,
312
+ thenEvent,
313
+ thenEvents,
314
+ thenNoEvent,
315
+ thenEventWithError,
316
+ thenEventsWithError,
317
+ thenError,
318
+ thenRefused,
319
+ thenAppendsConditionedOn,
320
+ thenAppendsConditionedOnExactly,
321
+ s1,
322
+ ClaimSlice,
323
+ Claim,
324
+ claimedByC1,
325
+ }
326
+ /* consumedEventSchema Not a pure module */
@@ -405,6 +405,10 @@ let Spec = include.Spec;
405
405
 
406
406
  let todo = include.todo;
407
407
 
408
+ let Caller = include.Caller;
409
+
410
+ let asCaller = include.asCaller;
411
+
408
412
  let thenEvents = include.thenEvents;
409
413
 
410
414
  let thenNoEvent = include.thenNoEvent;
@@ -413,6 +417,8 @@ let thenEventWithError = include.thenEventWithError;
413
417
 
414
418
  let thenEventsWithError = include.thenEventsWithError;
415
419
 
420
+ let thenRefused = include.thenRefused;
421
+
416
422
  export {
417
423
  AddCategorySlice,
418
424
  AddCategorySliceBehavior,
@@ -421,6 +427,8 @@ export {
421
427
  todo,
422
428
  test,
423
429
  givenEvents,
430
+ Caller,
431
+ asCaller,
424
432
  whenCmd,
425
433
  thenEvent,
426
434
  thenEvents,
@@ -428,6 +436,7 @@ export {
428
436
  thenEventWithError,
429
437
  thenEventsWithError,
430
438
  thenError,
439
+ thenRefused,
431
440
  thenAppendsConditionedOn,
432
441
  thenAppendsConditionedOnExactly,
433
442
  MissingTagSlice,