@reventlessdev/reventless-core 3.0.0-alpha.341 → 3.0.0-alpha.343
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 +23 -0
- package/package.json +7 -7
- package/src/Projection.res +32 -4
- package/src/Projection.res.mjs +51 -4
- package/src/ViewChange.res +1 -9
- package/src/ViewChange.res.mjs +2 -13
- package/src/admin/Platform_ComponentDefinitionsApi.res +29 -1
- package/src/admin/Platform_ComponentDefinitionsApi.res.mjs +47 -1
- package/src/admin/Platform_PluginStructuresApi.res +4 -3
- package/src/admin/Platform_PluginStructuresApi.res.mjs +5 -1
- package/src/components/Api/SuryToJsonSchema.res +7 -0
- package/src/components/Api/SuryToJsonSchema.res.mjs +18 -0
- package/src/components/Dcb/Dcb_Builder.res +59 -0
- package/src/components/Dcb/Dcb_Builder.res.mjs +48 -3
- package/src/components/DcbEventLog/DcbEventLog.res +2 -0
- package/src/components/DcbEventLog/DcbEventLog_Adapter.res +7 -0
- package/src/components/DcbEventLog/DcbEventLog_Builder.res +12 -3
- package/src/components/DcbEventLog/DcbEventLog_Builder.res.mjs +5 -3
- package/src/components/DcbEventLog/DcbEventLog_Operations.res +3 -0
- package/src/components/DcbEventLog/DcbEventLog_Operations.res.mjs +3 -1
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res.mjs +2 -2
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res +156 -107
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res.mjs +174 -154
- package/src/components/StateChangeSlice/StateChangeSlice.res +3 -0
- package/src/components/StateChangeSlice/StateChangeSlice_Builder.res +6 -0
- package/src/components/StateChangeSlice/StateChangeSlice_Builder.res.mjs +5 -4
- package/src/components/StateChangeSlice/StateChangeSlice_Callback.res +369 -279
- package/src/components/StateChangeSlice/StateChangeSlice_Callback.res.mjs +210 -166
- package/src/plugin/component/Plugin_Structure.res +45 -0
- package/src/plugin/component/Plugin_Structure.res.mjs +42 -1
- package/src/util/Logger.res +5 -5
- package/src/util/Logger.res.mjs +3 -3
- package/tests/admin/AdminApiSchemaDriftTest.res +23 -0
- package/tests/admin/AdminApiSchemaDriftTest.res.mjs +21 -1
- package/tests/admin/Platform_ComponentDefinitionsApiTest.res +1 -0
- package/tests/admin/Platform_ComponentDefinitionsApiTest.res.mjs +1 -0
- package/tests/admin/Platform_PluginStructuresApiTest.res +1 -0
- package/tests/admin/Platform_PluginStructuresApiTest.res.mjs +1 -0
- package/tests/api/QuantitySemanticTest.res +68 -0
- package/tests/api/QuantitySemanticTest.res.mjs +68 -0
- package/tests/commandgenerator/OwnerActingTest.res.mjs +1 -1
- package/tests/commandtopic/CommandOutcomeHookTest.res.mjs +1 -1
- package/tests/dcb/DcbFenceCountReadTest.res +213 -0
- package/tests/dcb/DcbFenceCountReadTest.res.mjs +358 -0
- package/tests/dcb/DcbPiiSliceTest.res.mjs +1 -1
- package/tests/dcb/DcbReadsNothingTest.res.mjs +1 -1
- package/tests/dcb/DcbScopeInferenceTest.res +143 -2
- package/tests/dcb/DcbScopeInferenceTest.res.mjs +192 -2
- package/tests/dcb/DcbStateChangeSliceTest.res.mjs +22 -22
- package/tests/dcb/DcbTagTest.res +68 -0
- package/tests/dcb/DcbTagTest.res.mjs +86 -10
- package/tests/dcb/DcbValidationTest.res.mjs +1 -1
- package/tests/logger/LoggerLazyTest.res.mjs +3 -3
- package/tests/plugin/PluginStructureAccessTest.res +1 -0
- package/tests/plugin/PluginStructureAccessTest.res.mjs +1 -1
- package/tests/plugin/PluginStructureTest.res +61 -0
- package/tests/plugin/PluginStructureTest.res.mjs +78 -32
- package/tests/plugin/StateChange/PsRateSession.res +37 -0
- package/tests/plugin/StateChange/PsRateSession.res.mjs +80 -0
- package/tests/plugin/pluginDefinitionRequiredScalars.txt +10 -0
- package/tests/projection/ViewChangeTest.res +32 -0
- package/tests/projection/ViewChangeTest.res.mjs +57 -0
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Sury from "sury";
|
|
4
|
+
import * as Effect from "@reventlessdev/rescript-effect/src/Effect.res.mjs";
|
|
5
|
+
import * as Id$Reventless from "@reventlessdev/reventless-spec/src/types/Id.res.mjs";
|
|
6
|
+
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
7
|
+
import * as Stream from "effect/Stream";
|
|
8
|
+
import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.js";
|
|
9
|
+
import * as DcbTag$Reventless from "@reventlessdev/reventless-spec/src/components/DcbTag.res.mjs";
|
|
10
|
+
import * as DcbFixtures$ReventlessCore from "./DcbFixtures.res.mjs";
|
|
11
|
+
import * as DcbEventLog_Operations$ReventlessCore from "../../src/components/DcbEventLog/DcbEventLog_Operations.res.mjs";
|
|
12
|
+
import * as StateChangeSlice_Callback$ReventlessCore from "../../src/components/StateChangeSlice/StateChangeSlice_Callback.res.mjs";
|
|
13
|
+
|
|
14
|
+
let mock = DcbFixtures$ReventlessCore.makeMockStorage();
|
|
15
|
+
|
|
16
|
+
let storage = mock.operations;
|
|
17
|
+
|
|
18
|
+
let publishJson = mock.mockPublishJson;
|
|
19
|
+
|
|
20
|
+
let LogOps = DcbEventLog_Operations$ReventlessCore.Make({
|
|
21
|
+
name: "FenceCountLog",
|
|
22
|
+
serviceName: "FenceCountLog",
|
|
23
|
+
storage: storage,
|
|
24
|
+
publishJson: publishJson
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
let staleReads = {
|
|
28
|
+
contents: 0
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
let reads = {
|
|
32
|
+
contents: 0
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
let appends = {
|
|
36
|
+
contents: 0
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
let conditions = {
|
|
40
|
+
contents: []
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
let queries = {
|
|
44
|
+
contents: []
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
let counted = {
|
|
48
|
+
contents: true
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
let student = {
|
|
52
|
+
key: "studentId",
|
|
53
|
+
value: "S1"
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
let eventLog_read = LogOps.read;
|
|
57
|
+
|
|
58
|
+
function eventLog_append(events, condition) {
|
|
59
|
+
appends.contents = appends.contents + 1 | 0;
|
|
60
|
+
conditions.contents = conditions.contents.concat([condition]);
|
|
61
|
+
return LogOps.append(events, condition);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function eventLog_readStream(query, after, strongConsistency) {
|
|
65
|
+
reads.contents = reads.contents + 1 | 0;
|
|
66
|
+
queries.contents = queries.contents.concat([query]);
|
|
67
|
+
let stale = reads.contents <= staleReads.contents;
|
|
68
|
+
return Stream.filter(LogOps.readStream(query, after, strongConsistency), param => !stale);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let eventLog_appendStream = LogOps.appendStream;
|
|
72
|
+
|
|
73
|
+
let eventLog_readFences = async tags => tags.map(tag => ({
|
|
74
|
+
tag: tag,
|
|
75
|
+
counted: counted.contents,
|
|
76
|
+
counts: Object.fromEntries([[
|
|
77
|
+
"StudentSubscribed",
|
|
78
|
+
mock.getEvents().filter(e => e.tags.some(t => {
|
|
79
|
+
if (t.key === tag.key) {
|
|
80
|
+
return t.value === tag.value;
|
|
81
|
+
} else {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
})).length
|
|
85
|
+
]])
|
|
86
|
+
}));
|
|
87
|
+
|
|
88
|
+
let eventLog = {
|
|
89
|
+
read: eventLog_read,
|
|
90
|
+
append: eventLog_append,
|
|
91
|
+
readStream: eventLog_readStream,
|
|
92
|
+
appendStream: eventLog_appendStream,
|
|
93
|
+
readFences: eventLog_readFences
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
let name = "Subscribe";
|
|
97
|
+
|
|
98
|
+
let moduleUrl = import.meta.url;
|
|
99
|
+
|
|
100
|
+
let eventSchema = Sury.$schema(s => ({
|
|
101
|
+
TAG: "StudentSubscribed",
|
|
102
|
+
courseId: s.m(DcbTag$Reventless.string),
|
|
103
|
+
studentId: s.m(DcbTag$Reventless.string)
|
|
104
|
+
}));
|
|
105
|
+
|
|
106
|
+
let consumedEventSchema = Sury.$schema(s => ({
|
|
107
|
+
TAG: "StudentSubscribed",
|
|
108
|
+
courseId: s.m(DcbTag$Reventless.string),
|
|
109
|
+
studentId: s.m(DcbTag$Reventless.string)
|
|
110
|
+
}));
|
|
111
|
+
|
|
112
|
+
let commandSchema = Sury.$schema(s => ({
|
|
113
|
+
TAG: "Subscribe",
|
|
114
|
+
courseId: s.m(DcbTag$Reventless.string),
|
|
115
|
+
studentId: s.m(DcbTag$Reventless.string)
|
|
116
|
+
}));
|
|
117
|
+
|
|
118
|
+
let errorSchema = Sury.literal("AlreadySubscribedElsewhere");
|
|
119
|
+
|
|
120
|
+
function authorizationOf(param) {
|
|
121
|
+
return "AllowAuthenticated";
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function commandTransition(param) {
|
|
125
|
+
return "Undeclared";
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
let traits = [];
|
|
129
|
+
|
|
130
|
+
let SubscribeSpec = {
|
|
131
|
+
name: name,
|
|
132
|
+
Id: undefined,
|
|
133
|
+
moduleUrl: moduleUrl,
|
|
134
|
+
eventSchema: eventSchema,
|
|
135
|
+
consumedEventSchema: consumedEventSchema,
|
|
136
|
+
commandSchema: commandSchema,
|
|
137
|
+
errorSchema: errorSchema,
|
|
138
|
+
authorizationOf: authorizationOf,
|
|
139
|
+
commandTransition: commandTransition,
|
|
140
|
+
traits: traits,
|
|
141
|
+
readConsistency: "EscalateOnRetry"
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
function evolve(_state, _event) {
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function decide(subscribed, command) {
|
|
149
|
+
if (subscribed) {
|
|
150
|
+
return {
|
|
151
|
+
TAG: "Error",
|
|
152
|
+
_0: "AlreadySubscribedElsewhere"
|
|
153
|
+
};
|
|
154
|
+
} else {
|
|
155
|
+
return {
|
|
156
|
+
TAG: "Ok",
|
|
157
|
+
_0: [{
|
|
158
|
+
TAG: "StudentSubscribed",
|
|
159
|
+
courseId: command.courseId,
|
|
160
|
+
studentId: command.studentId
|
|
161
|
+
}]
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
let SubscribeDecision = {
|
|
167
|
+
initialState: false,
|
|
168
|
+
moduleUrl: moduleUrl,
|
|
169
|
+
evolve: evolve,
|
|
170
|
+
decide: decide
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
let SubscribeHandler = StateChangeSlice_Callback$ReventlessCore.Make({
|
|
174
|
+
name: name,
|
|
175
|
+
moduleUrl: moduleUrl,
|
|
176
|
+
consumedEventSchema: consumedEventSchema,
|
|
177
|
+
errorSchema: errorSchema,
|
|
178
|
+
eventSchema: eventSchema,
|
|
179
|
+
commandSchema: commandSchema,
|
|
180
|
+
authorizationOf: authorizationOf,
|
|
181
|
+
commandTransition: commandTransition,
|
|
182
|
+
traits: traits,
|
|
183
|
+
readConsistency: "EscalateOnRetry"
|
|
184
|
+
})({
|
|
185
|
+
initialState: false,
|
|
186
|
+
evolve: evolve,
|
|
187
|
+
decide: decide,
|
|
188
|
+
moduleUrl: moduleUrl
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
function subscribe(reference, courseId) {
|
|
192
|
+
return Effect.runPromise(SubscribeHandler.handleCommands(undefined, ["studentId"], undefined, {
|
|
193
|
+
TAG: "Simple",
|
|
194
|
+
_0: {
|
|
195
|
+
key: "courseId"
|
|
196
|
+
}
|
|
197
|
+
}, eventLog, Stream.fromIterable([{
|
|
198
|
+
command: {
|
|
199
|
+
id: Id$Reventless.$$String.makeFromString("cmd-" + reference),
|
|
200
|
+
meta: DcbFixtures$ReventlessCore.testMeta,
|
|
201
|
+
command: {
|
|
202
|
+
TAG: "Subscribe",
|
|
203
|
+
courseId: courseId,
|
|
204
|
+
studentId: "S1"
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
reference: reference
|
|
208
|
+
}])));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
async function givenSubscribedThenStale(n) {
|
|
212
|
+
await subscribe("first", "C1");
|
|
213
|
+
SubscribeHandler.resetCache();
|
|
214
|
+
reads.contents = 0;
|
|
215
|
+
appends.contents = 0;
|
|
216
|
+
staleReads.contents = n;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
globalThis.beforeEach(() => {
|
|
220
|
+
mock.reset();
|
|
221
|
+
SubscribeHandler.resetCache();
|
|
222
|
+
reads.contents = 0;
|
|
223
|
+
appends.contents = 0;
|
|
224
|
+
conditions.contents = [];
|
|
225
|
+
queries.contents = [];
|
|
226
|
+
staleReads.contents = 0;
|
|
227
|
+
counted.contents = true;
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
globalThis.describe("a read of a counted cross-partition fence", () => {
|
|
231
|
+
globalThis.test("reads again until the index shows what was counted", async () => {
|
|
232
|
+
await givenSubscribedThenStale(1);
|
|
233
|
+
let result = await subscribe("second", "C2");
|
|
234
|
+
globalThis.expect([
|
|
235
|
+
result,
|
|
236
|
+
mock.getEvents().length,
|
|
237
|
+
reads.contents,
|
|
238
|
+
appends.contents
|
|
239
|
+
]).toEqual([
|
|
240
|
+
[{
|
|
241
|
+
TAG: "Ok",
|
|
242
|
+
_0: "second"
|
|
243
|
+
}],
|
|
244
|
+
1,
|
|
245
|
+
2,
|
|
246
|
+
0
|
|
247
|
+
]);
|
|
248
|
+
});
|
|
249
|
+
globalThis.test("answers a conflict when the index stays behind", async () => {
|
|
250
|
+
await givenSubscribedThenStale(10);
|
|
251
|
+
let result = await subscribe("second", "C2");
|
|
252
|
+
globalThis.expect([
|
|
253
|
+
result,
|
|
254
|
+
mock.getEvents().length,
|
|
255
|
+
reads.contents,
|
|
256
|
+
appends.contents
|
|
257
|
+
]).toEqual([
|
|
258
|
+
[{
|
|
259
|
+
TAG: "Error",
|
|
260
|
+
_0: "second"
|
|
261
|
+
}],
|
|
262
|
+
1,
|
|
263
|
+
4,
|
|
264
|
+
0
|
|
265
|
+
]);
|
|
266
|
+
});
|
|
267
|
+
globalThis.test("a fence not yet counted is not checked", async () => {
|
|
268
|
+
counted.contents = false;
|
|
269
|
+
await givenSubscribedThenStale(1);
|
|
270
|
+
await subscribe("second", "C2");
|
|
271
|
+
globalThis.expect([
|
|
272
|
+
mock.getEvents().length,
|
|
273
|
+
reads.contents,
|
|
274
|
+
appends.contents
|
|
275
|
+
]).toEqual([
|
|
276
|
+
1,
|
|
277
|
+
2,
|
|
278
|
+
1
|
|
279
|
+
]);
|
|
280
|
+
});
|
|
281
|
+
globalThis.test("the append carries the count it read", async () => {
|
|
282
|
+
await subscribe("first", "C1");
|
|
283
|
+
globalThis.expect(conditions.contents.map(c => Stdlib_Option.flatMap(c, c => c.fenceCounts))).toEqual([[{
|
|
284
|
+
tag: student,
|
|
285
|
+
eventType: "StudentSubscribed",
|
|
286
|
+
count: 0
|
|
287
|
+
}]]);
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
globalThis.describe("a slice that reads a pair", () => {
|
|
292
|
+
globalThis.test("reads the pair's types by its key from the index", async () => {
|
|
293
|
+
await Effect.runPromise(SubscribeHandler.handleCommands(undefined, undefined, [
|
|
294
|
+
{
|
|
295
|
+
reader: "Subscribe",
|
|
296
|
+
eventType: "StudentSubscribed",
|
|
297
|
+
key: "courseId",
|
|
298
|
+
writers: ["Enrol"]
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
reader: "Other",
|
|
302
|
+
eventType: "StudentSubscribed",
|
|
303
|
+
key: "studentId",
|
|
304
|
+
writers: ["Enrol"]
|
|
305
|
+
}
|
|
306
|
+
], {
|
|
307
|
+
TAG: "Simple",
|
|
308
|
+
_0: {
|
|
309
|
+
key: "courseId"
|
|
310
|
+
}
|
|
311
|
+
}, eventLog, Stream.fromIterable([{
|
|
312
|
+
command: {
|
|
313
|
+
id: Id$Reventless.$$String.makeFromString("cmd-pair"),
|
|
314
|
+
meta: DcbFixtures$ReventlessCore.testMeta,
|
|
315
|
+
command: {
|
|
316
|
+
TAG: "Subscribe",
|
|
317
|
+
courseId: "C9",
|
|
318
|
+
studentId: "S1"
|
|
319
|
+
}
|
|
320
|
+
},
|
|
321
|
+
reference: "pair"
|
|
322
|
+
}])));
|
|
323
|
+
let across = queries.contents.flat().filter(qi => Primitive_object.equal(qi.crossPartition, true)).map(qi => [
|
|
324
|
+
qi.tags,
|
|
325
|
+
qi.eventTypes
|
|
326
|
+
]);
|
|
327
|
+
globalThis.expect(across.length !== 0).toBe(true);
|
|
328
|
+
globalThis.expect(across.every(param => {
|
|
329
|
+
if (Primitive_object.equal(param[0], [{
|
|
330
|
+
key: "courseId",
|
|
331
|
+
value: "C9"
|
|
332
|
+
}])) {
|
|
333
|
+
return Primitive_object.equal(param[1], ["StudentSubscribed"]);
|
|
334
|
+
} else {
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
337
|
+
})).toBe(true);
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
export {
|
|
342
|
+
mock,
|
|
343
|
+
LogOps,
|
|
344
|
+
staleReads,
|
|
345
|
+
reads,
|
|
346
|
+
appends,
|
|
347
|
+
conditions,
|
|
348
|
+
queries,
|
|
349
|
+
counted,
|
|
350
|
+
student,
|
|
351
|
+
eventLog,
|
|
352
|
+
SubscribeSpec,
|
|
353
|
+
SubscribeDecision,
|
|
354
|
+
SubscribeHandler,
|
|
355
|
+
subscribe,
|
|
356
|
+
givenSubscribedThenStale,
|
|
357
|
+
}
|
|
358
|
+
/* mock Not a pure module */
|
|
@@ -207,7 +207,7 @@ function fakeProvider(sealsOpt) {
|
|
|
207
207
|
}
|
|
208
208
|
|
|
209
209
|
async function send(reference, command) {
|
|
210
|
-
return await Effect.runPromise(Handler.handleCommands(undefined, undefined, undefined, log, Stream.fromIterable([{
|
|
210
|
+
return await Effect.runPromise(Handler.handleCommands(undefined, undefined, undefined, undefined, log, Stream.fromIterable([{
|
|
211
211
|
command: {
|
|
212
212
|
id: Id$Reventless.$$String.makeFromString("cmd-" + reference),
|
|
213
213
|
meta: DcbFixtures$ReventlessCore.testMeta,
|
|
@@ -133,7 +133,7 @@ let NoteHandler = StateChangeSlice_Callback$ReventlessCore.Make({
|
|
|
133
133
|
});
|
|
134
134
|
|
|
135
135
|
function note(reference) {
|
|
136
|
-
return Effect.runPromise(NoteHandler.handleCommands(undefined, undefined, undefined, eventLog, Stream.fromIterable([{
|
|
136
|
+
return Effect.runPromise(NoteHandler.handleCommands(undefined, undefined, undefined, undefined, eventLog, Stream.fromIterable([{
|
|
137
137
|
command: {
|
|
138
138
|
id: Id$Reventless.$$String.makeFromString("cmd-" + reference),
|
|
139
139
|
meta: DcbFixtures$ReventlessCore.testMeta,
|
|
@@ -5,6 +5,8 @@ module DSI = Reventless.DcbScopeInference
|
|
|
5
5
|
// --- tiny constructors so the golden vectors read like the spec files ---
|
|
6
6
|
let scal = (name): DSI.idField => {name, isList: false}
|
|
7
7
|
let arr = (name): DSI.idField => {name, isList: true}
|
|
8
|
+
// `@crossPartition`, which also declares the tag.
|
|
9
|
+
let cross = (name): DSI.idField => {name, isList: false, declared: true, crossPartition: true}
|
|
8
10
|
let ev = (eventType, idFields): DSI.eventShape => {eventType, idFields}
|
|
9
11
|
let slice = (
|
|
10
12
|
sliceName,
|
|
@@ -600,6 +602,45 @@ describe("DcbScopeInference:", () => {
|
|
|
600
602
|
let issues = check([placeOrder, ship, assign])
|
|
601
603
|
expect(issues.overrides->names)->toEqual([])
|
|
602
604
|
expect(issues.contradictions->names)->toEqual(["ShipOrder"])
|
|
605
|
+
expect(
|
|
606
|
+
issues.contradictions->Array.every(
|
|
607
|
+
e => e.message->String.includes("mark orderId @crossPartition on WarehouseAssigned"),
|
|
608
|
+
),
|
|
609
|
+
)->toBe(true)
|
|
610
|
+
expect(DSI.infer([placeOrder, ship, assign]).crossPartitionPairs)->toEqual([])
|
|
611
|
+
},
|
|
612
|
+
)
|
|
613
|
+
|
|
614
|
+
testSync(
|
|
615
|
+
"marked @crossPartition, the same read is an override with one pair",
|
|
616
|
+
() => {
|
|
617
|
+
let assign = slice(
|
|
618
|
+
"AssignWarehouse",
|
|
619
|
+
~chapter="Warehouse",
|
|
620
|
+
~partitionHint="warehouseId",
|
|
621
|
+
~produced=[ev("WarehouseAssigned", [scal("warehouseId"), scal("orderId")])],
|
|
622
|
+
)
|
|
623
|
+
let ship = {
|
|
624
|
+
...shipOrder,
|
|
625
|
+
consumed: shipOrder.consumed->Array.concat([
|
|
626
|
+
ev("WarehouseAssigned", [scal("warehouseId"), cross("orderId")]),
|
|
627
|
+
]),
|
|
628
|
+
}
|
|
629
|
+
let boundary = [placeOrder, ship, assign]
|
|
630
|
+
let issues = check(boundary)
|
|
631
|
+
expect(issues.contradictions)->toEqual([])
|
|
632
|
+
expect(issues.overrides->names)->toEqual(["ShipOrder"])
|
|
633
|
+
let d = DSI.infer(boundary)
|
|
634
|
+
expect(d.crossPartitionPairs)->toEqual([
|
|
635
|
+
{
|
|
636
|
+
DSI.reader: "ShipOrder",
|
|
637
|
+
eventType: "WarehouseAssigned",
|
|
638
|
+
key: "orderId",
|
|
639
|
+
writers: ["AssignWarehouse"],
|
|
640
|
+
},
|
|
641
|
+
])
|
|
642
|
+
// the pair reads the reader's own key: no key turns cross-partition
|
|
643
|
+
expect(d.crossPartitionTagKeys)->toEqual([])
|
|
603
644
|
},
|
|
604
645
|
)
|
|
605
646
|
|
|
@@ -648,15 +689,115 @@ describe("DcbScopeInference:", () => {
|
|
|
648
689
|
testSync(
|
|
649
690
|
"a hint deciding a slice inference leaves unresolved is accepted",
|
|
650
691
|
() => {
|
|
651
|
-
|
|
692
|
+
// `ReplyPosted`'s writer is outside the boundary: where it is stored is not known here.
|
|
693
|
+
let boundary = [postMessage, questionState]
|
|
694
|
+
let issues = check(boundary)
|
|
652
695
|
expect(issues.contradictions)->toEqual([])
|
|
653
696
|
expect(issues.redundancies)->toEqual([])
|
|
654
697
|
expect(
|
|
655
|
-
DSI.resolvePartitions(
|
|
698
|
+
DSI.resolvePartitions(boundary).partitionBySlice->Dict.get("QuestionState"),
|
|
656
699
|
)->toEqual(Some("messageId"))
|
|
657
700
|
},
|
|
658
701
|
)
|
|
659
702
|
|
|
703
|
+
testSync(
|
|
704
|
+
"a hint deciding an unresolved slice is refused when its read misses events stored elsewhere",
|
|
705
|
+
() => {
|
|
706
|
+
// `ReplyPosted` is stored under the reply, so a read by messageId never finds it.
|
|
707
|
+
let issues = check(questions)
|
|
708
|
+
expect(issues.contradictions->names)->toEqual(["QuestionState"])
|
|
709
|
+
expect(
|
|
710
|
+
issues.contradictions->Array.every(
|
|
711
|
+
e => e.message->String.includes("mark messageId @crossPartition on ReplyPosted"),
|
|
712
|
+
),
|
|
713
|
+
)->toBe(true)
|
|
714
|
+
},
|
|
715
|
+
)
|
|
716
|
+
|
|
717
|
+
let markedReplies = {
|
|
718
|
+
...questionState,
|
|
719
|
+
consumed: questionState.consumed->Array.map(
|
|
720
|
+
e =>
|
|
721
|
+
e.eventType == "ReplyPosted"
|
|
722
|
+
? ev("ReplyPosted", [scal("replyId"), cross("messageId"), scal("channelId")])
|
|
723
|
+
: e,
|
|
724
|
+
),
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
testSync(
|
|
728
|
+
"marked @crossPartition, the question reads its replies as a pair",
|
|
729
|
+
() => {
|
|
730
|
+
let boundary = [postMessage, postReply, markedReplies]
|
|
731
|
+
let issues = check(boundary)
|
|
732
|
+
expect(issues.contradictions)->toEqual([])
|
|
733
|
+
let d = DSI.infer(boundary)
|
|
734
|
+
expect(d.crossPartitionPairs)->toEqual([
|
|
735
|
+
{
|
|
736
|
+
DSI.reader: "QuestionState",
|
|
737
|
+
eventType: "ReplyPosted",
|
|
738
|
+
key: "messageId",
|
|
739
|
+
writers: ["PostReply"],
|
|
740
|
+
},
|
|
741
|
+
])
|
|
742
|
+
expect(d.crossPartitionTagKeys)->toEqual([])
|
|
743
|
+
let arms = Reventless.DcbValidation.validateCrossPartitionArms(
|
|
744
|
+
~shapes=boundary,
|
|
745
|
+
~inferred=d,
|
|
746
|
+
)
|
|
747
|
+
expect(arms.contradictions)->toEqual([])
|
|
748
|
+
expect(arms.redundancies)->toEqual([])
|
|
749
|
+
},
|
|
750
|
+
)
|
|
751
|
+
|
|
752
|
+
testSync(
|
|
753
|
+
"a marker on a key that is not the slice's own is refused",
|
|
754
|
+
() => {
|
|
755
|
+
let byChannel = {
|
|
756
|
+
...questionState,
|
|
757
|
+
consumed: questionState.consumed->Array.map(
|
|
758
|
+
e =>
|
|
759
|
+
e.eventType == "ReplyPosted"
|
|
760
|
+
? ev("ReplyPosted", [scal("replyId"), cross("messageId"), cross("channelId")])
|
|
761
|
+
: e,
|
|
762
|
+
),
|
|
763
|
+
}
|
|
764
|
+
let boundary = [postMessage, postReply, byChannel]
|
|
765
|
+
let arms = Reventless.DcbValidation.validateCrossPartitionArms(
|
|
766
|
+
~shapes=boundary,
|
|
767
|
+
~inferred=DSI.infer(boundary),
|
|
768
|
+
)
|
|
769
|
+
expect(arms.contradictions->names)->toEqual(["QuestionState"])
|
|
770
|
+
expect(
|
|
771
|
+
arms.contradictions->Array.every(e => e.message->String.includes("marks channelId")),
|
|
772
|
+
)->toBe(true)
|
|
773
|
+
},
|
|
774
|
+
)
|
|
775
|
+
|
|
776
|
+
testSync(
|
|
777
|
+
"a marker on an event already stored under the slice's key is redundant",
|
|
778
|
+
() => {
|
|
779
|
+
let markedMessage = {
|
|
780
|
+
...markedReplies,
|
|
781
|
+
consumed: markedReplies.consumed->Array.map(
|
|
782
|
+
e =>
|
|
783
|
+
e.eventType == "MessagePosted"
|
|
784
|
+
? ev("MessagePosted", [cross("messageId"), scal("channelId")])
|
|
785
|
+
: e,
|
|
786
|
+
),
|
|
787
|
+
}
|
|
788
|
+
let boundary = [postMessage, postReply, markedMessage]
|
|
789
|
+
let d = DSI.infer(boundary)
|
|
790
|
+
let arms = Reventless.DcbValidation.validateCrossPartitionArms(
|
|
791
|
+
~shapes=boundary,
|
|
792
|
+
~inferred=d,
|
|
793
|
+
)
|
|
794
|
+
expect(arms.contradictions)->toEqual([])
|
|
795
|
+
expect(arms.redundancies->names)->toEqual(["QuestionState"])
|
|
796
|
+
// and it makes no pair
|
|
797
|
+
expect(d.crossPartitionPairs->Array.map(p => p.eventType))->toEqual(["ReplyPosted"])
|
|
798
|
+
},
|
|
799
|
+
)
|
|
800
|
+
|
|
660
801
|
testSync(
|
|
661
802
|
"a hint naming a key one of the slice's events lacks is still a contradiction",
|
|
662
803
|
() => {
|