@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/Hint.res
CHANGED
|
@@ -8,12 +8,14 @@
|
|
|
8
8
|
// `locus` is a dotted pointer like "CategoryDecision.decide" filled in by
|
|
9
9
|
// the DSL at `then*` call time when the slice module name is in scope, else a
|
|
10
10
|
// generic pointer. A `StateMismatch` names its fold, so a view's points at
|
|
11
|
-
// `project` rather than `evolve`.
|
|
11
|
+
// `project` rather than `evolve`. A mismatch a flow found carries its step, and
|
|
12
|
+
// the locus names the part that step ran.
|
|
12
13
|
|
|
13
14
|
type t = {
|
|
14
15
|
locus: string,
|
|
15
16
|
branch: option<string>,
|
|
16
17
|
message: string,
|
|
18
|
+
step?: Outcome.step,
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
// The constructor name of an encoded variant, if any: a payload-less variant is
|
|
@@ -32,7 +34,15 @@ let variantTag = (j: JSON.t): option<string> =>
|
|
|
32
34
|
// Generic fallback mapping, parameterised by the slice module name when the
|
|
33
35
|
// caller can supply one. Branch specificity lives in the DSLs (they can pass
|
|
34
36
|
// a richer hint through `withLocus` below).
|
|
35
|
-
let forMismatch = (~slice="<slice>", m: Outcome.mismatch): t =>
|
|
37
|
+
let rec forMismatch = (~slice="<slice>", m: Outcome.mismatch): t =>
|
|
38
|
+
switch Outcome.stepOf(m) {
|
|
39
|
+
| Some(step) => {
|
|
40
|
+
...forMismatchAt(~slice=step.part->Option.mapOr(slice, p => p.name), m),
|
|
41
|
+
step,
|
|
42
|
+
}
|
|
43
|
+
| None => forMismatchAt(~slice, m)
|
|
44
|
+
}
|
|
45
|
+
and forMismatchAt = (~slice, m: Outcome.mismatch): t =>
|
|
36
46
|
switch m {
|
|
37
47
|
| EventsMismatch(_) => {
|
|
38
48
|
locus: `${slice}.decide`,
|
|
@@ -117,17 +127,43 @@ let forMismatch = (~slice="<slice>", m: Outcome.mismatch): t =>
|
|
|
117
127
|
}
|
|
118
128
|
}
|
|
119
129
|
|
|
120
|
-
|
|
130
|
+
let stepJson = ({number, total, verb, ?part}: Outcome.step): JSON.t => {
|
|
131
|
+
let obj = Dict.make()
|
|
132
|
+
obj->Dict.set("number", JSON.Encode.int(number))
|
|
133
|
+
obj->Dict.set("total", JSON.Encode.int(total))
|
|
134
|
+
obj->Dict.set("verb", JSON.Encode.string(verb))
|
|
135
|
+
part->Option.forEach(({kind, name}) =>
|
|
136
|
+
obj->Dict.set(
|
|
137
|
+
"part",
|
|
138
|
+
JSON.Encode.object(
|
|
139
|
+
Dict.fromArray([
|
|
140
|
+
("kind", JSON.Encode.string((kind :> string))),
|
|
141
|
+
("name", JSON.Encode.string(name)),
|
|
142
|
+
]),
|
|
143
|
+
),
|
|
144
|
+
)
|
|
145
|
+
)
|
|
146
|
+
JSON.Encode.object(obj)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Convert to the JSON shape documented in §3.3, with the flow's step when a
|
|
150
|
+
// flow found the mismatch.
|
|
121
151
|
let toJson = (h: t): JSON.t => {
|
|
122
152
|
let obj = Dict.make()
|
|
123
153
|
obj->Dict.set("locus", JSON.Encode.string(h.locus))
|
|
124
154
|
obj->Dict.set("branch", h.branch->Option.mapOr(JSON.Encode.null, JSON.Encode.string))
|
|
125
155
|
obj->Dict.set("message", JSON.Encode.string(h.message))
|
|
156
|
+
h.step->Option.forEach(step => obj->Dict.set("step", stepJson(step)))
|
|
126
157
|
JSON.Encode.object(obj)
|
|
127
158
|
}
|
|
128
159
|
|
|
129
|
-
let format = (h: t) =>
|
|
130
|
-
switch h.branch {
|
|
160
|
+
let format = (h: t) => {
|
|
161
|
+
let hint = switch h.branch {
|
|
131
162
|
| None => `hint: ${h.message}\n Look at ${h.locus}.`
|
|
132
163
|
| Some(b) => `hint: ${h.message}\n Look at ${h.locus}'s branch ${b}.`
|
|
133
164
|
}
|
|
165
|
+
switch h.step {
|
|
166
|
+
| Some(step) => `At ${Outcome.describeStep(step)}.\n${hint}`
|
|
167
|
+
| None => hint
|
|
168
|
+
}
|
|
169
|
+
}
|
package/src/Hint.res.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
3
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
4
|
+
import * as Outcome$ReventlessGwt from "./Outcome.res.mjs";
|
|
4
5
|
|
|
5
6
|
function variantTag(j) {
|
|
6
7
|
if (j === null || Array.isArray(j)) {
|
|
@@ -21,8 +22,7 @@ function variantTag(j) {
|
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
function
|
|
25
|
-
let slice = sliceOpt !== undefined ? sliceOpt : "<slice>";
|
|
25
|
+
function forMismatchAt(slice, m) {
|
|
26
26
|
switch (m.TAG) {
|
|
27
27
|
case "EventsMismatch" :
|
|
28
28
|
return {
|
|
@@ -118,26 +118,64 @@ function forMismatch(sliceOpt, m) {
|
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
+
function forMismatch(sliceOpt, m) {
|
|
122
|
+
let slice = sliceOpt !== undefined ? sliceOpt : "<slice>";
|
|
123
|
+
let step = Outcome$ReventlessGwt.stepOf(m);
|
|
124
|
+
if (step === undefined) {
|
|
125
|
+
return forMismatchAt(slice, m);
|
|
126
|
+
}
|
|
127
|
+
let newrecord = {...forMismatchAt(Stdlib_Option.mapOr(step.part, slice, p => p.name), m)};
|
|
128
|
+
newrecord.step = step;
|
|
129
|
+
return newrecord;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function stepJson(param) {
|
|
133
|
+
let obj = {};
|
|
134
|
+
obj["number"] = param.number;
|
|
135
|
+
obj["total"] = param.total;
|
|
136
|
+
obj["verb"] = param.verb;
|
|
137
|
+
Stdlib_Option.forEach(param.part, param => {
|
|
138
|
+
obj["part"] = Object.fromEntries([
|
|
139
|
+
[
|
|
140
|
+
"kind",
|
|
141
|
+
param.kind
|
|
142
|
+
],
|
|
143
|
+
[
|
|
144
|
+
"name",
|
|
145
|
+
param.name
|
|
146
|
+
]
|
|
147
|
+
]);
|
|
148
|
+
});
|
|
149
|
+
return obj;
|
|
150
|
+
}
|
|
151
|
+
|
|
121
152
|
function toJson(h) {
|
|
122
153
|
let obj = {};
|
|
123
154
|
obj["locus"] = h.locus;
|
|
124
155
|
obj["branch"] = Stdlib_Option.mapOr(h.branch, null, prim => prim);
|
|
125
156
|
obj["message"] = h.message;
|
|
157
|
+
Stdlib_Option.forEach(h.step, step => {
|
|
158
|
+
obj["step"] = stepJson(step);
|
|
159
|
+
});
|
|
126
160
|
return obj;
|
|
127
161
|
}
|
|
128
162
|
|
|
129
163
|
function format(h) {
|
|
130
164
|
let b = h.branch;
|
|
131
|
-
|
|
132
|
-
|
|
165
|
+
let hint = b !== undefined ? `hint: ` + h.message + `\n Look at ` + h.locus + `'s branch ` + b + `.` : `hint: ` + h.message + `\n Look at ` + h.locus + `.`;
|
|
166
|
+
let step = h.step;
|
|
167
|
+
if (step !== undefined) {
|
|
168
|
+
return `At ` + Outcome$ReventlessGwt.describeStep(step) + `.\n` + hint;
|
|
133
169
|
} else {
|
|
134
|
-
return
|
|
170
|
+
return hint;
|
|
135
171
|
}
|
|
136
172
|
}
|
|
137
173
|
|
|
138
174
|
export {
|
|
139
175
|
variantTag,
|
|
140
176
|
forMismatch,
|
|
177
|
+
forMismatchAt,
|
|
178
|
+
stepJson,
|
|
141
179
|
toJson,
|
|
142
180
|
format,
|
|
143
181
|
}
|
package/src/Outcome.res
CHANGED
|
@@ -12,38 +12,116 @@
|
|
|
12
12
|
// `project`. Absent means `Evolve`, so a harness that does not say keeps its hint.
|
|
13
13
|
type fold = Evolve | Project
|
|
14
14
|
|
|
15
|
+
/** The kind of part a flow's step runs. */
|
|
16
|
+
type partKind =
|
|
17
|
+
| @as("Decision") Decision
|
|
18
|
+
| @as("Aggregate") Aggregate
|
|
19
|
+
| @as("View") View
|
|
20
|
+
| @as("Automation") Automation
|
|
21
|
+
| @as("Outbound") Outbound
|
|
22
|
+
| @as("Inbound") Inbound
|
|
23
|
+
| @as("ExtensionPoint") ExtensionPoint
|
|
24
|
+
| @as("Extension") Extension
|
|
25
|
+
| @as("Query") Query
|
|
26
|
+
| @as("SideEffect") SideEffect
|
|
27
|
+
|
|
28
|
+
type part = {kind: partKind, name: string}
|
|
29
|
+
|
|
30
|
+
/** Where in a flow a mismatch was found: the step's number among all `total`
|
|
31
|
+
steps of the flow, its verb, and the part it ran when it ran one. */
|
|
32
|
+
type step = {number: int, total: int, verb: string, part?: part}
|
|
33
|
+
|
|
15
34
|
type mismatch =
|
|
16
|
-
| EventsMismatch({expected: array<JSON.t>, actual: array<JSON.t
|
|
17
|
-
| ErrorMismatch({
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
|
35
|
+
| EventsMismatch({expected: array<JSON.t>, actual: array<JSON.t>, step?: step})
|
|
36
|
+
| ErrorMismatch({
|
|
37
|
+
expected: JSON.t,
|
|
38
|
+
actual: option<JSON.t>,
|
|
39
|
+
actualEvents: array<JSON.t>,
|
|
40
|
+
step?: step,
|
|
41
|
+
})
|
|
42
|
+
| StateMismatch({
|
|
43
|
+
key: string,
|
|
44
|
+
expected: option<JSON.t>,
|
|
45
|
+
actual: option<JSON.t>,
|
|
46
|
+
fold?: fold,
|
|
47
|
+
step?: step,
|
|
48
|
+
})
|
|
49
|
+
| NoEventExpected({actual: array<JSON.t>, step?: step})
|
|
50
|
+
| TodoMismatch({expected: array<(string, JSON.t)>, actual: array<(string, JSON.t)>, step?: step})
|
|
51
|
+
| AppendConditionMismatch({expected: JSON.t, actual: JSON.t, step?: step})
|
|
52
|
+
| TranslateError({expected: string, actual: option<string>, step?: step})
|
|
53
|
+
| QueryRowsMismatch({expected: array<JSON.t>, actual: array<JSON.t>, step?: step})
|
|
24
54
|
// The set of published actions (events/commands) emitted by an ExtensionPoint
|
|
25
55
|
// mapping or an Extension delegate diverged from the expectation. Supports
|
|
26
56
|
// one-to-many fan-out (one inbound message → N published actions). Used by
|
|
27
57
|
// `Delegate_GWT` and the cross-plugin `Flow_GWT` boundary steps.
|
|
28
|
-
| PublishedActionsMismatch({expected: array<JSON.t>, actual: array<JSON.t
|
|
58
|
+
| PublishedActionsMismatch({expected: array<JSON.t>, actual: array<JSON.t>, step?: step})
|
|
29
59
|
// A DCB consistency boundary could not derive its tag scope, so the runtime
|
|
30
60
|
// falls back to `@crossPartition` annotations and loses the cross-partition
|
|
31
61
|
// reference reads named in `dropped`. Not a mismatch between an expectation
|
|
32
62
|
// and a value — every slice in it still behaves correctly in isolation, which
|
|
33
63
|
// is exactly why it needs its own outcome: the defect is in the composition,
|
|
34
64
|
// and nothing that tests one slice can see it.
|
|
35
|
-
| ScopeDegraded({
|
|
65
|
+
| ScopeDegraded({
|
|
66
|
+
boundary: string,
|
|
67
|
+
dropped: array<string>,
|
|
68
|
+
ambiguities: array<string>,
|
|
69
|
+
step?: step,
|
|
70
|
+
})
|
|
36
71
|
// A DCB consistency boundary whose storage partition cannot be derived: a slice
|
|
37
72
|
// with no inferable key, or a `@partitionTag` inference contradicts. Deploy and
|
|
38
73
|
// boot refuse such a boundary, so its flow test fails with the same reasons.
|
|
39
|
-
| PartitionUnresolved({boundary: string, reasons: array<string
|
|
40
|
-
| Throw({error: string, stack: string})
|
|
74
|
+
| PartitionUnresolved({boundary: string, reasons: array<string>, step?: step})
|
|
75
|
+
| Throw({error: string, stack: string, step?: step})
|
|
41
76
|
|
|
42
77
|
type outcome = result<unit, mismatch>
|
|
43
78
|
|
|
44
79
|
let pass: outcome = Ok()
|
|
45
80
|
let fail = (m): outcome => Error(m)
|
|
46
81
|
|
|
82
|
+
/** The flow step a mismatch was found at, if a flow found it. */
|
|
83
|
+
let stepOf = (m: mismatch): option<step> =>
|
|
84
|
+
switch m {
|
|
85
|
+
| EventsMismatch({?step})
|
|
86
|
+
| ErrorMismatch({?step})
|
|
87
|
+
| StateMismatch({?step})
|
|
88
|
+
| NoEventExpected({?step})
|
|
89
|
+
| TodoMismatch({?step})
|
|
90
|
+
| AppendConditionMismatch({?step})
|
|
91
|
+
| TranslateError({?step})
|
|
92
|
+
| QueryRowsMismatch({?step})
|
|
93
|
+
| PublishedActionsMismatch({?step})
|
|
94
|
+
| ScopeDegraded({?step})
|
|
95
|
+
| PartitionUnresolved({?step})
|
|
96
|
+
| Throw({?step}) => step
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** The mismatch, found at a flow's step. */
|
|
100
|
+
let atStep = (m: mismatch, step: step): mismatch =>
|
|
101
|
+
switch m {
|
|
102
|
+
| EventsMismatch(r) => EventsMismatch({...r, step})
|
|
103
|
+
| ErrorMismatch(r) => ErrorMismatch({...r, step})
|
|
104
|
+
| StateMismatch(r) => StateMismatch({...r, step})
|
|
105
|
+
| NoEventExpected(r) => NoEventExpected({...r, step})
|
|
106
|
+
| TodoMismatch(r) => TodoMismatch({...r, step})
|
|
107
|
+
| AppendConditionMismatch(r) => AppendConditionMismatch({...r, step})
|
|
108
|
+
| TranslateError(r) => TranslateError({...r, step})
|
|
109
|
+
| QueryRowsMismatch(r) => QueryRowsMismatch({...r, step})
|
|
110
|
+
| PublishedActionsMismatch(r) => PublishedActionsMismatch({...r, step})
|
|
111
|
+
| ScopeDegraded(r) => ScopeDegraded({...r, step})
|
|
112
|
+
| PartitionUnresolved(r) => PartitionUnresolved({...r, step})
|
|
113
|
+
| Throw(r) => Throw({...r, step})
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** A step as a reader names it: *step 6 of 11, ShipOrder.thenEvent*. */
|
|
117
|
+
let describeStep = ({number, total, verb, ?part}: step) => {
|
|
118
|
+
let at = switch part {
|
|
119
|
+
| Some({name}) => `${name}.${verb}`
|
|
120
|
+
| None => verb
|
|
121
|
+
}
|
|
122
|
+
`step ${number->Int.toString} of ${total->Int.toString}, ${at}`
|
|
123
|
+
}
|
|
124
|
+
|
|
47
125
|
/** A mismatch's kind without its values. Its text is the mismatch's constructor name. */
|
|
48
126
|
type mismatchKind =
|
|
49
127
|
| @as("EventsMismatch") EventsMismatchKind
|
package/src/Outcome.res.mjs
CHANGED
|
@@ -9,6 +9,50 @@ function fail(m) {
|
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
function stepOf(m) {
|
|
13
|
+
switch (m.TAG) {
|
|
14
|
+
case "StateMismatch" :
|
|
15
|
+
return m.step;
|
|
16
|
+
case "NoEventExpected" :
|
|
17
|
+
return m.step;
|
|
18
|
+
case "ErrorMismatch" :
|
|
19
|
+
case "ScopeDegraded" :
|
|
20
|
+
return m.step;
|
|
21
|
+
default:
|
|
22
|
+
return m.step;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function atStep(m, step) {
|
|
27
|
+
switch (m.TAG) {
|
|
28
|
+
case "StateMismatch" :
|
|
29
|
+
let newrecord = {...m};
|
|
30
|
+
newrecord.step = step;
|
|
31
|
+
return newrecord;
|
|
32
|
+
case "NoEventExpected" :
|
|
33
|
+
let newrecord$1 = {...m};
|
|
34
|
+
newrecord$1.step = step;
|
|
35
|
+
return newrecord$1;
|
|
36
|
+
case "ErrorMismatch" :
|
|
37
|
+
case "ScopeDegraded" :
|
|
38
|
+
break;
|
|
39
|
+
default:
|
|
40
|
+
let newrecord$2 = {...m};
|
|
41
|
+
newrecord$2.step = step;
|
|
42
|
+
return newrecord$2;
|
|
43
|
+
}
|
|
44
|
+
let newrecord$3 = {...m};
|
|
45
|
+
newrecord$3.step = step;
|
|
46
|
+
return newrecord$3;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function describeStep(param) {
|
|
50
|
+
let part = param.part;
|
|
51
|
+
let verb = param.verb;
|
|
52
|
+
let at = part !== undefined ? part.name + `.` + verb : verb;
|
|
53
|
+
return `step ` + param.number.toString() + ` of ` + param.total.toString() + `, ` + at;
|
|
54
|
+
}
|
|
55
|
+
|
|
12
56
|
function kindOf(m) {
|
|
13
57
|
switch (m.TAG) {
|
|
14
58
|
case "EventsMismatch" :
|
|
@@ -94,6 +138,9 @@ let pass = {
|
|
|
94
138
|
export {
|
|
95
139
|
pass,
|
|
96
140
|
fail,
|
|
141
|
+
stepOf,
|
|
142
|
+
atStep,
|
|
143
|
+
describeStep,
|
|
97
144
|
kindOf,
|
|
98
145
|
kindName,
|
|
99
146
|
stringifyJson,
|
package/src/Projection_GWT.res
CHANGED
|
@@ -26,6 +26,10 @@ module type Spec = {
|
|
|
26
26
|
type consumedEvent
|
|
27
27
|
|
|
28
28
|
let subIdConfig: option<Reventless.ReadModel.subIdConfig<state>>
|
|
29
|
+
|
|
30
|
+
/** The roles the view's rule names, and the rule: who may read the view at all. */
|
|
31
|
+
type role
|
|
32
|
+
let authorization: Reventless.Authorization.rule<role>
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
// Implementation half — one binding (`project`).
|
|
@@ -49,6 +53,8 @@ module type T = {
|
|
|
49
53
|
type storeThunk = unit => promise<store>
|
|
50
54
|
|
|
51
55
|
let givenEvents: array<Spec.consumedEvent> => promise<store>
|
|
56
|
+
/** Each event recorded at its own time (an ISO instant), as a flow records them. */
|
|
57
|
+
let givenEventsAt: array<(Spec.consumedEvent, string)> => promise<store>
|
|
52
58
|
let whenEvent: (promise<store>, Spec.consumedEvent) => storeThunk
|
|
53
59
|
let whenEvents: (promise<store>, array<Spec.consumedEvent>) => storeThunk
|
|
54
60
|
let thenStates: (storeThunk, array<Spec.state>) => promise<Outcome.outcome>
|
|
@@ -59,6 +65,13 @@ module type T = {
|
|
|
59
65
|
let thenNoState: storeThunk => promise<Outcome.outcome>
|
|
60
66
|
let thenThrow: storeThunk => promise<Outcome.outcome>
|
|
61
67
|
let thenFail: storeThunk => promise<Outcome.outcome>
|
|
68
|
+
|
|
69
|
+
// Who reads the rows; see `Decision_GWT.Caller`. Refused by the view's rule,
|
|
70
|
+
// not the row's owner, or the row retired, all read as no row.
|
|
71
|
+
module Caller: Decision_GWT.Callers with type role = Spec.role
|
|
72
|
+
let asCaller: (storeThunk, Caller.t) => storeThunk
|
|
73
|
+
/** The rows `who` may read, given the groups that read every row. */
|
|
74
|
+
let readableBy: (array<Spec.state>, Caller.t, ~elevated: array<string>) => array<Spec.state>
|
|
62
75
|
}
|
|
63
76
|
|
|
64
77
|
let handleActions = Projection.handleActions // local alias to avoid shadowing
|
|
@@ -161,7 +174,7 @@ module Make = (Spec: Spec, Projection: Projection with module Spec := Spec): (
|
|
|
161
174
|
)
|
|
162
175
|
}
|
|
163
176
|
|
|
164
|
-
let
|
|
177
|
+
let updateAt = async (store, events: array<(Spec.consumedEvent, string)>) => {
|
|
165
178
|
// Projection.project produces an array of actions per event — flatten and
|
|
166
179
|
// feed them through handleActions against the dict store. Each bare event is
|
|
167
180
|
// wrapped in the `consumed` envelope with the deterministic test `meta` /
|
|
@@ -171,17 +184,17 @@ module Make = (Spec: Spec, Projection: Projection with module Spec := Spec): (
|
|
|
171
184
|
// the machinery, so a harness that skipped this would assert an empty one.
|
|
172
185
|
let actions =
|
|
173
186
|
events
|
|
174
|
-
->Array.map(ev =>
|
|
187
|
+
->Array.map(((ev, time)) =>
|
|
175
188
|
{
|
|
176
189
|
Reventless.StateViewSlice.event: ev,
|
|
177
|
-
meta: TestFixtures.meta,
|
|
178
|
-
recordedAt: TestFixtures.recordedAt,
|
|
190
|
+
meta: {...TestFixtures.meta, time},
|
|
191
|
+
recordedAt: time == TestFixtures.meta.time ? TestFixtures.recordedAt : time,
|
|
179
192
|
}
|
|
180
193
|
->Projection.project
|
|
181
194
|
->Array.map(action =>
|
|
182
195
|
action
|
|
183
196
|
->Reventless.Projection.mapActionId(~to_=Spec.Id.toString, ~from=Spec.Id.makeFromString)
|
|
184
|
-
->ReventlessCore.Projection.rewriteTrail(~at=
|
|
197
|
+
->ReventlessCore.Projection.rewriteTrail(~at=time, Spec.stateSchema)
|
|
185
198
|
)
|
|
186
199
|
)
|
|
187
200
|
->Array.flat
|
|
@@ -198,7 +211,45 @@ module Make = (Spec: Spec, Projection: Projection with module Spec := Spec): (
|
|
|
198
211
|
store->sortStore
|
|
199
212
|
}
|
|
200
213
|
|
|
214
|
+
module Caller = Decision_GWT.Callers({
|
|
215
|
+
type role = Spec.role
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
let ownerField = Reventless.Owner.fieldNames(Spec.stateSchema->S.castToUnknown)->Array.get(0)
|
|
219
|
+
let retired =
|
|
220
|
+
Spec.stateSchema
|
|
221
|
+
->S.castToUnknown
|
|
222
|
+
->Reventless.StateAnnotations.getSpec
|
|
223
|
+
->Option.flatMap(spec => spec.retired)
|
|
224
|
+
|
|
225
|
+
let readableBy = (rows: array<Spec.state>, who: Caller.t, ~elevated) => {
|
|
226
|
+
let identity = Decision_GWT.Caller.identity(who)
|
|
227
|
+
rows->Array.filter(row =>
|
|
228
|
+
identity->Reventless.OwnerScope.mayReadRow(
|
|
229
|
+
row->Message.encode(Spec.stateSchema),
|
|
230
|
+
~rule=Reventless.Authorization.named(Spec.authorization),
|
|
231
|
+
~ownerField,
|
|
232
|
+
~retiredField=?retired->Option.map(r => r.field),
|
|
233
|
+
~retiredValues=?retired->Option.flatMap(r => r.values),
|
|
234
|
+
~elevated=elevated->Array.concat([Decision_GWT.Caller.operatorGroup]),
|
|
235
|
+
)
|
|
236
|
+
)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
let asCaller = (thunk: storeThunk, who: Caller.t): storeThunk =>
|
|
240
|
+
async () =>
|
|
241
|
+
(await thunk())
|
|
242
|
+
->Dict.mapValues(rows => rows->readableBy(who, ~elevated=[]))
|
|
243
|
+
->Dict.toArray
|
|
244
|
+
->Array.filter(((_, rows)) => rows->Array.length > 0)
|
|
245
|
+
->Dict.fromArray
|
|
246
|
+
|
|
247
|
+
// Every event at the fixed test time.
|
|
248
|
+
let update = (store, events) =>
|
|
249
|
+
store->updateAt(events->Array.map(ev => (ev, TestFixtures.meta.time)))
|
|
250
|
+
|
|
201
251
|
let givenEvents = events => Dict.make()->update(events)
|
|
252
|
+
let givenEventsAt = events => Dict.make()->updateAt(events)
|
|
202
253
|
|
|
203
254
|
let whenEvent = (store, event): storeThunk =>
|
|
204
255
|
() => (async () => await (await store)->update([event]))()
|
|
@@ -4,14 +4,19 @@ import * as Stdlib_Dict from "@rescript/runtime/lib/es6/Stdlib_Dict.js";
|
|
|
4
4
|
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
5
5
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
6
6
|
import * as Stream from "effect/Stream";
|
|
7
|
+
import * as Owner$Reventless from "@reventlessdev/reventless-spec/src/components/Owner.res.mjs";
|
|
7
8
|
import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.js";
|
|
8
9
|
import * as Primitive_string from "@rescript/runtime/lib/es6/Primitive_string.js";
|
|
9
10
|
import * as Outcome$ReventlessGwt from "./Outcome.res.mjs";
|
|
11
|
+
import * as OwnerScope$Reventless from "@reventlessdev/reventless-spec/src/types/OwnerScope.res.mjs";
|
|
10
12
|
import * as Projection$Reventless from "@reventlessdev/reventless-spec/src/types/Projection.res.mjs";
|
|
11
13
|
import * as JestBind$ReventlessGwt from "./JestBind.res.mjs";
|
|
12
14
|
import * as Message$ReventlessCore from "@reventlessdev/reventless-core/src/Message.res.mjs";
|
|
15
|
+
import * as Authorization$Reventless from "@reventlessdev/reventless-spec/src/types/Authorization.res.mjs";
|
|
13
16
|
import * as Projection$ReventlessCore from "@reventlessdev/reventless-core/src/Projection.res.mjs";
|
|
17
|
+
import * as Decision_GWT$ReventlessGwt from "./Decision_GWT.res.mjs";
|
|
14
18
|
import * as TestFixtures$ReventlessGwt from "./TestFixtures.res.mjs";
|
|
19
|
+
import * as StateAnnotations$Reventless from "@reventlessdev/reventless-spec/src/components/StateAnnotations.res.mjs";
|
|
15
20
|
|
|
16
21
|
function Make(Spec) {
|
|
17
22
|
return Projection => {
|
|
@@ -59,12 +64,16 @@ function Make(Spec) {
|
|
|
59
64
|
store[id] = Stdlib_Option.getOr(Stdlib_Option.map(store[id], states => states.filter(state => Primitive_object.notequal(getSubId(state), subId))), []);
|
|
60
65
|
};
|
|
61
66
|
let runActions = (actions, operations) => Projection$ReventlessCore.handleActions(undefined, undefined, actions, operations, Spec.subIdConfig);
|
|
62
|
-
let
|
|
63
|
-
let actions = events.map(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
let updateAt = async (store, events) => {
|
|
68
|
+
let actions = events.map(param => {
|
|
69
|
+
let time = param[1];
|
|
70
|
+
let newrecord = {...TestFixtures$ReventlessGwt.meta};
|
|
71
|
+
return Projection.project({
|
|
72
|
+
event: param[0],
|
|
73
|
+
meta: (newrecord.time = time, newrecord),
|
|
74
|
+
recordedAt: time === TestFixtures$ReventlessGwt.meta.time ? TestFixtures$ReventlessGwt.recordedAt : time
|
|
75
|
+
}).map(action => Projection$ReventlessCore.rewriteTrail(Projection$Reventless.mapActionId(action, Spec.Id.toString, Spec.Id.makeFromString), time, Spec.stateSchema));
|
|
76
|
+
}).flat();
|
|
68
77
|
await runActions(actions, {
|
|
69
78
|
load: extra => Promise.resolve({
|
|
70
79
|
TAG: "Ok",
|
|
@@ -188,7 +197,20 @@ function Make(Spec) {
|
|
|
188
197
|
return store;
|
|
189
198
|
}
|
|
190
199
|
};
|
|
200
|
+
let Caller = Decision_GWT$ReventlessGwt.Callers({});
|
|
201
|
+
let ownerField = Owner$Reventless.fieldNames(Spec.stateSchema)[0];
|
|
202
|
+
let retired = Stdlib_Option.flatMap(StateAnnotations$Reventless.getSpec(Spec.stateSchema), spec => spec.retired);
|
|
203
|
+
let readableBy = (rows, who, elevated) => {
|
|
204
|
+
let identity = Decision_GWT$ReventlessGwt.Caller.identity(who);
|
|
205
|
+
return rows.filter(row => OwnerScope$Reventless.mayReadRow(identity, Message$ReventlessCore.encode(row, Spec.stateSchema), Authorization$Reventless.named(Spec.authorization), ownerField, Stdlib_Option.map(retired, r => r.field), Stdlib_Option.flatMap(retired, r => r.values), undefined, elevated.concat([Decision_GWT$ReventlessGwt.Caller.operatorGroup])));
|
|
206
|
+
};
|
|
207
|
+
let asCaller = (thunk, who) => (async () => Object.fromEntries(Object.entries(Stdlib_Dict.mapValues(await thunk(), rows => readableBy(rows, who, []))).filter(param => param[1].length !== 0)));
|
|
208
|
+
let update = (store, events) => updateAt(store, events.map(ev => [
|
|
209
|
+
ev,
|
|
210
|
+
TestFixtures$ReventlessGwt.meta.time
|
|
211
|
+
]));
|
|
191
212
|
let givenEvents = events => update({}, events);
|
|
213
|
+
let givenEventsAt = events => updateAt({}, events);
|
|
192
214
|
let whenEvent = (store, event) => (() => (async () => await update(await store, [event]))());
|
|
193
215
|
let whenEvents = (store, events) => (() => (async () => await update(await store, events))());
|
|
194
216
|
let encState = s => Message$ReventlessCore.encode(s, Spec.stateSchema);
|
|
@@ -314,6 +336,7 @@ function Make(Spec) {
|
|
|
314
336
|
todo: JestBind$ReventlessGwt.todo,
|
|
315
337
|
test: test,
|
|
316
338
|
givenEvents: givenEvents,
|
|
339
|
+
givenEventsAt: givenEventsAt,
|
|
317
340
|
whenEvent: whenEvent,
|
|
318
341
|
whenEvents: whenEvents,
|
|
319
342
|
thenStates: thenStates,
|
|
@@ -323,7 +346,10 @@ function Make(Spec) {
|
|
|
323
346
|
thenStateWithId: thenStateWithId,
|
|
324
347
|
thenNoState: thenNoState,
|
|
325
348
|
thenThrow: thenThrow,
|
|
326
|
-
thenFail: thenFail
|
|
349
|
+
thenFail: thenFail,
|
|
350
|
+
Caller: Caller,
|
|
351
|
+
asCaller: asCaller,
|
|
352
|
+
readableBy: readableBy
|
|
327
353
|
};
|
|
328
354
|
};
|
|
329
355
|
}
|
package/src/Query_GWT.res
CHANGED
|
@@ -25,6 +25,10 @@ module type QueryableSpec = {
|
|
|
25
25
|
|
|
26
26
|
let config: Reventless.ReadModel.config
|
|
27
27
|
let subIdConfig: option<Reventless.ReadModel.subIdConfig<state>>
|
|
28
|
+
|
|
29
|
+
/** The roles the view's rule names, and the rule: who may read the view at all. */
|
|
30
|
+
type role
|
|
31
|
+
let authorization: Reventless.Authorization.rule<role>
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
module FromReadModel = (Spec: Reventless.ReadModel.Spec) => {
|
|
@@ -33,6 +37,8 @@ module FromReadModel = (Spec: Reventless.ReadModel.Spec) => {
|
|
|
33
37
|
let stateSchema = Spec.stateSchema
|
|
34
38
|
let config = Spec.config
|
|
35
39
|
let subIdConfig = Spec.subIdConfig
|
|
40
|
+
type role = Spec.role
|
|
41
|
+
let authorization = Spec.authorization
|
|
36
42
|
}
|
|
37
43
|
|
|
38
44
|
module FromStateViewSlice = (Spec: Reventless.StateViewSlice.Spec) => {
|
|
@@ -41,6 +47,8 @@ module FromStateViewSlice = (Spec: Reventless.StateViewSlice.Spec) => {
|
|
|
41
47
|
let stateSchema = Spec.stateSchema
|
|
42
48
|
let config = Spec.config
|
|
43
49
|
let subIdConfig = Spec.subIdConfig
|
|
50
|
+
type role = Spec.role
|
|
51
|
+
let authorization = Spec.authorization
|
|
44
52
|
}
|
|
45
53
|
|
|
46
54
|
// -- Query argument shapes ---------------------------------------------------
|
|
@@ -82,6 +90,12 @@ module type T = {
|
|
|
82
90
|
result<option<Spec.state>, Outcome.mismatch>,
|
|
83
91
|
option<Spec.state>,
|
|
84
92
|
) => Outcome.outcome
|
|
93
|
+
|
|
94
|
+
// Who asks; see `Decision_GWT.Caller`. The rows the caller may not read are
|
|
95
|
+
// not there to be found: refused by the view's rule, not the row's owner, or
|
|
96
|
+
// the row retired.
|
|
97
|
+
module Caller: Decision_GWT.Callers with type role = Spec.role
|
|
98
|
+
let asCaller: (store, Caller.t) => store
|
|
85
99
|
}
|
|
86
100
|
|
|
87
101
|
module Make = (Spec: QueryableSpec): (T with module Spec = Spec) => {
|
|
@@ -101,6 +115,31 @@ module Make = (Spec: QueryableSpec): (T with module Spec = Spec) => {
|
|
|
101
115
|
let givenCompositeStore = triples =>
|
|
102
116
|
triples->Array.map(((id, subId, state)) => {id, subId: Some(subId), state})
|
|
103
117
|
|
|
118
|
+
module Caller = Decision_GWT.Callers({
|
|
119
|
+
type role = Spec.role
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
let ownerField = Reventless.Owner.fieldNames(Spec.stateSchema->S.castToUnknown)->Array.get(0)
|
|
123
|
+
let retired =
|
|
124
|
+
Spec.stateSchema
|
|
125
|
+
->S.castToUnknown
|
|
126
|
+
->Reventless.StateAnnotations.getSpec
|
|
127
|
+
->Option.flatMap(spec => spec.retired)
|
|
128
|
+
|
|
129
|
+
let asCaller = (s: store, who: Caller.t) => {
|
|
130
|
+
let identity = Decision_GWT.Caller.identity(who)
|
|
131
|
+
s->Array.filter(r =>
|
|
132
|
+
identity->Reventless.OwnerScope.mayReadRow(
|
|
133
|
+
encState(r.state),
|
|
134
|
+
~rule=Reventless.Authorization.named(Spec.authorization),
|
|
135
|
+
~ownerField,
|
|
136
|
+
~retiredField=?retired->Option.map(r => r.field),
|
|
137
|
+
~retiredValues=?retired->Option.flatMap(r => r.values),
|
|
138
|
+
~elevated=[Decision_GWT.Caller.operatorGroup],
|
|
139
|
+
)
|
|
140
|
+
)
|
|
141
|
+
}
|
|
142
|
+
|
|
104
143
|
// `whenQueryById` ignores `subId` — returns the first row with the given id.
|
|
105
144
|
// Callers who want composite-id lookup go through `whenQueryByCompositeId`.
|
|
106
145
|
let whenQueryById = (s: store, id) =>
|