@reventlessdev/reventless-core 3.0.0-alpha.169 → 3.0.0-alpha.171
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 +16 -0
- package/package.json +16 -16
- package/src/admin/Platform_Admin.res +5 -2
- package/src/admin/Platform_Admin.res.mjs +4 -4
- package/src/components/Aggregate/Aggregate.res +5 -1
- package/src/components/Aggregate/Aggregate_Builder.res +21 -6
- package/src/components/Aggregate/Aggregate_Builder.res.mjs +10 -7
- package/src/components/AutomationSlice/AutomationSlice.res +1 -0
- package/src/components/AutomationSlice/AutomationSlice_Builder.res +13 -2
- package/src/components/AutomationSlice/AutomationSlice_Builder.res.mjs +5 -2
- package/src/components/Builder_Helpers.res +16 -2
- package/src/components/Builder_Helpers.res.mjs +6 -6
- package/src/components/Dcb/Dcb_Builder.res +46 -4
- package/src/components/Dcb/Dcb_Builder.res.mjs +13 -9
- package/src/components/ExtensionPoint/ExtensionPoint.res +2 -0
- package/src/components/ExtensionPoint/ExtensionPoint_Builder.res +10 -0
- package/src/components/ExtensionPoint/ExtensionPoint_Builder.res.mjs +6 -4
- package/src/components/InboundTranslationSlice/InboundTranslationSlice.res +1 -0
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Builder.res +8 -1
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Builder.res.mjs +1 -1
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice.res +1 -0
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res +12 -3
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res.mjs +5 -2
- package/src/components/ReadModel/ReadModel.res +1 -0
- package/src/components/ReadModel/ReadModel_Builder.res +9 -1
- package/src/components/ReadModel/ReadModel_Builder.res.mjs +5 -2
- package/src/components/StateChangeSlice/StateChangeSlice.res +1 -0
- package/src/components/StateChangeSlice/StateChangeSlice_Builder.res +6 -0
- package/src/components/StateChangeSlice/StateChangeSlice_Builder.res.mjs +1 -1
- package/src/components/StateViewSlice/StateViewSlice.res +1 -0
- package/src/components/StateViewSlice/StateViewSlice_Builder.res +11 -3
- package/src/components/StateViewSlice/StateViewSlice_Builder.res.mjs +5 -2
- package/src/components/Task/Task.res +1 -0
- package/src/components/Task/Task_Builder.res +11 -2
- package/src/components/Task/Task_Builder.res.mjs +7 -4
- package/src/plugin/component/Plugin.res +5 -0
- package/src/plugin/component/Plugin_Builder.res +10 -2
- package/src/plugin/component/Plugin_Builder.res.mjs +7 -6
- package/src/plugin/component/Plugin_Helpers.res +2 -0
- package/src/plugin/component/Plugin_Helpers.res.mjs +2 -2
- package/src/plugin/connect/PluginExtensionPoint_Builder.res +2 -0
- package/src/plugin/connect/PluginExtensionPoint_Builder.res.mjs +3 -3
- package/tests/plugin/ManifestVisibilityTest.res +2 -2
- package/tests/plugin/PluginStructureTest.res +6 -6
- package/tests/IdentityTest.res.mjs +0 -174
- package/tests/adapter/MonitoringTest.res.mjs +0 -82
- package/tests/admin/Platform_ComponentDefinitionsApiTest.res.mjs +0 -356
- package/tests/admin/Platform_UIFragmentsApiTest.res.mjs +0 -101
- package/tests/aggregate/AggregateCacheTest.res.mjs +0 -433
- package/tests/aggregate/AggregateCallbackTest.res.mjs +0 -143
- package/tests/aggregate/AggregateCausationTest.res.mjs +0 -47
- package/tests/aggregate/AggregateConflictTest.res.mjs +0 -386
- package/tests/aggregate/AggregateFixtures.res.mjs +0 -308
- package/tests/aggregate/AggregateRejectionTest.res.mjs +0 -166
- package/tests/aggregate/AggregateSnapshotTest.res.mjs +0 -645
- package/tests/api/ApiNoApiTest.res.mjs +0 -90
- package/tests/api/GraphQL_StitcherTest.res.mjs +0 -112
- package/tests/api/SimpleTest.res.mjs +0 -10
- package/tests/api/SuryToJsonSchemaTest.res.mjs +0 -674
- package/tests/commandgenerator/CommandGeneratorCallbackTest.res.mjs +0 -160
- package/tests/commandgenerator/CommandGeneratorFixtures.res.mjs +0 -197
- package/tests/commandtopic/CommandTopicCallbackFixtures.res.mjs +0 -152
- package/tests/commandtopic/CommandTopicCallbackTest.res.mjs +0 -106
- package/tests/commandtopic/CommandTopicHelpersRejectionTest.res.mjs +0 -109
- package/tests/counter/CounterCallbackTest.res.mjs +0 -140
- package/tests/counter/CounterFixtures.res.mjs +0 -67
- package/tests/dcb/DcbDecodeTest.res.mjs +0 -194
- package/tests/dcb/DcbEventLogOperationsTest.res.mjs +0 -268
- package/tests/dcb/DcbFixtures.res.mjs +0 -534
- package/tests/dcb/DcbScopeInferenceTest.res.mjs +0 -480
- package/tests/dcb/DcbStateChangeSliceTest.res.mjs +0 -540
- package/tests/dcb/DcbTagTest.res.mjs +0 -867
- package/tests/dcb/DcbValidationTest.res.mjs +0 -476
- package/tests/eventlog/EventLogFixtures.res.mjs +0 -196
- package/tests/eventlog/EventLogOperationsTest.res.mjs +0 -192
- package/tests/eventlog/EventLogRetryTest.res.mjs +0 -195
- package/tests/eventmapper/EventMapperCallbackTest.res.mjs +0 -141
- package/tests/eventmapper/EventMapperFixtures.res.mjs +0 -440
- package/tests/eventmapper/EventMapperTest.res.mjs +0 -83
- package/tests/eventtopic/EventTopicFixtures.res.mjs +0 -65
- package/tests/eventtopic/EventTopicOperationsTest.res.mjs +0 -71
- package/tests/extensionpoint/ExtensionPointCallbackTest.res.mjs +0 -94
- package/tests/extensionpoint/ExtensionPointFixtures.res.mjs +0 -205
- package/tests/extensionpoint/ExtensionPointOperationsTest.res.mjs +0 -304
- package/tests/ftp/FTPTest.res.mjs +0 -88
- package/tests/logger/LogFormatTest.res.mjs +0 -309
- package/tests/logger/LoggerLazyTest.res.mjs +0 -40
- package/tests/message/MessageTest.res.mjs +0 -218
- package/tests/message/MetaEnvelopeTest.res.mjs +0 -188
- package/tests/plugin/ManifestVisibilityTest.res.mjs +0 -215
- package/tests/plugin/PluginSpecExperiment.res.mjs +0 -31
- package/tests/plugin/PluginStructureTest.res.mjs +0 -419
- package/tests/plugin/PluginVersionTest.res.mjs +0 -30
- package/tests/plugin/SchemaWalkerTest.res.mjs +0 -160
- package/tests/plugin/StateChangeSlice/PsPlaceOrder.res.mjs +0 -62
- package/tests/plugin/StateChangeSlice/PsShipOrder.res.mjs +0 -69
- package/tests/plugin/StateViewSlice/PsAnnotatedView.res.mjs +0 -95
- package/tests/plugin/StateViewSlice/PsAvailableProductsView.res.mjs +0 -69
- package/tests/plugin/StateViewSlice/PsCustomersView.res.mjs +0 -69
- package/tests/plugin/StateViewSlice/PsOrdersView.res.mjs +0 -81
- package/tests/poc/StructuralSubtypingPoc.res.mjs +0 -61
- package/tests/projection/ProjectionOptimizeTest.res.mjs +0 -75
- package/tests/querydb/QueryDbFixtures.res.mjs +0 -135
- package/tests/querydb/QueryDbOperationsTest.res.mjs +0 -168
- package/tests/sideeffecthandler/SideEffectHandlerCallbackTest.res.mjs +0 -77
- package/tests/sideeffecthandler/SideEffectHandlerFixtures.res.mjs +0 -139
- package/tests/util/CommandPublisherTest.res.mjs +0 -78
- package/tests/util/CsvStreamTest.res.mjs +0 -51
- package/tests/util/LruTest.res.mjs +0 -105
- package/tests/util/MetricsTest.res.mjs +0 -53
|
@@ -1,386 +0,0 @@
|
|
|
1
|
-
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
-
|
|
3
|
-
import * as S from "sury/src/S.res.mjs";
|
|
4
|
-
import * as Id$Reventless from "@reventlessdev/reventless-spec/src/types/Id.res.mjs";
|
|
5
|
-
import * as Effect from "effect/Effect";
|
|
6
|
-
import * as Stream from "effect/Stream";
|
|
7
|
-
import * as Aggregate_Callback$ReventlessCore from "../../src/components/Aggregate/Aggregate_Callback.res.mjs";
|
|
8
|
-
|
|
9
|
-
S.enableJson();
|
|
10
|
-
|
|
11
|
-
let name = "ConflictTestAggregate";
|
|
12
|
-
|
|
13
|
-
let commandSchema = S.schema(s => ({
|
|
14
|
-
TAG: "Create",
|
|
15
|
-
name: s.m(S.string)
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
|
-
let eventSchema = S.schema(s => ({
|
|
19
|
-
TAG: "Created",
|
|
20
|
-
name: s.m(S.string)
|
|
21
|
-
}));
|
|
22
|
-
|
|
23
|
-
let errorSchema = S.literal("AlreadyExists");
|
|
24
|
-
|
|
25
|
-
let moduleUrl = import.meta.url;
|
|
26
|
-
|
|
27
|
-
function commandAuthorization(param) {
|
|
28
|
-
return "AllowAuthenticated";
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
let AggSpec = {
|
|
32
|
-
Id: undefined,
|
|
33
|
-
name: name,
|
|
34
|
-
commandSchema: commandSchema,
|
|
35
|
-
eventSchema: eventSchema,
|
|
36
|
-
errorSchema: errorSchema,
|
|
37
|
-
moduleUrl: moduleUrl,
|
|
38
|
-
commandAuthorization: commandAuthorization
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
let initialState = {
|
|
42
|
-
name: ""
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
let moduleUrl$1 = import.meta.url;
|
|
46
|
-
|
|
47
|
-
function evolve(_state, event) {
|
|
48
|
-
return {
|
|
49
|
-
name: event.name
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function decide(_state, command) {
|
|
54
|
-
return {
|
|
55
|
-
TAG: "Ok",
|
|
56
|
-
_0: [{
|
|
57
|
-
TAG: "Created",
|
|
58
|
-
name: command.name
|
|
59
|
-
}]
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
let TestBehavior = {
|
|
64
|
-
Spec: undefined,
|
|
65
|
-
initialState: initialState,
|
|
66
|
-
snapshot: undefined,
|
|
67
|
-
moduleUrl: moduleUrl$1,
|
|
68
|
-
evolve: evolve,
|
|
69
|
-
decide: decide
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
function makeMockEL() {
|
|
73
|
-
let storedRef = {
|
|
74
|
-
contents: []
|
|
75
|
-
};
|
|
76
|
-
let failConflictRef = {
|
|
77
|
-
contents: 0
|
|
78
|
-
};
|
|
79
|
-
let appendCount = {
|
|
80
|
-
contents: 0
|
|
81
|
-
};
|
|
82
|
-
let replayCount = {
|
|
83
|
-
contents: 0
|
|
84
|
-
};
|
|
85
|
-
let appendFn = async (_seqNr, _id, newEvents) => {
|
|
86
|
-
appendCount.contents = appendCount.contents + 1 | 0;
|
|
87
|
-
if (failConflictRef.contents > 0) {
|
|
88
|
-
failConflictRef.contents = failConflictRef.contents - 1 | 0;
|
|
89
|
-
return {
|
|
90
|
-
TAG: "Error",
|
|
91
|
-
_0: "Conflict"
|
|
92
|
-
};
|
|
93
|
-
} else {
|
|
94
|
-
storedRef.contents = storedRef.contents.concat(newEvents);
|
|
95
|
-
return {
|
|
96
|
-
TAG: "Ok",
|
|
97
|
-
_0: undefined
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
let replayFn = async id => {
|
|
102
|
-
replayCount.contents = replayCount.contents + 1 | 0;
|
|
103
|
-
return storedRef.contents.filter(e => e.id === id).map(e => e.event);
|
|
104
|
-
};
|
|
105
|
-
let replayStreamFn = id => {
|
|
106
|
-
replayCount.contents = replayCount.contents + 1 | 0;
|
|
107
|
-
return Stream.fromIterable(storedRef.contents.filter(e => e.id === id).map(e => e.event));
|
|
108
|
-
};
|
|
109
|
-
return {
|
|
110
|
-
appendFn: appendFn,
|
|
111
|
-
replayFn: replayFn,
|
|
112
|
-
replayStreamFn: replayStreamFn,
|
|
113
|
-
getAll: () => storedRef.contents,
|
|
114
|
-
failNextAppendsWithConflict: failConflictRef,
|
|
115
|
-
appendCallCount: appendCount,
|
|
116
|
-
replayCallCount: replayCount,
|
|
117
|
-
reset: () => {
|
|
118
|
-
storedRef.contents = [];
|
|
119
|
-
failConflictRef.contents = 0;
|
|
120
|
-
appendCount.contents = 0;
|
|
121
|
-
replayCount.contents = 0;
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
let mock = makeMockEL();
|
|
127
|
-
|
|
128
|
-
let name$1 = "ConflictMockEventLog";
|
|
129
|
-
|
|
130
|
-
let Spec = {
|
|
131
|
-
Id: undefined,
|
|
132
|
-
name: name$1,
|
|
133
|
-
eventSchema: eventSchema
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
function make(param, param$1) {
|
|
137
|
-
return 0;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
let EventLog = {
|
|
141
|
-
Spec: Spec,
|
|
142
|
-
make: make
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
let eventLog_append = mock.appendFn;
|
|
146
|
-
|
|
147
|
-
let eventLog_replay = mock.replayFn;
|
|
148
|
-
|
|
149
|
-
function eventLog_replayStream(id, param) {
|
|
150
|
-
return mock.replayStreamFn(id);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function eventLog_appendStream(_startingSeqNr, _id, stream) {
|
|
154
|
-
return Stream.runDrain(stream);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
async function eventLog_latestSnapshot(param) {
|
|
158
|
-
return {
|
|
159
|
-
TAG: "Ok",
|
|
160
|
-
_0: undefined
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
async function eventLog_writeSnapshot(param, param$1) {
|
|
165
|
-
return {
|
|
166
|
-
TAG: "Ok",
|
|
167
|
-
_0: undefined
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
let eventLog = {
|
|
172
|
-
append: eventLog_append,
|
|
173
|
-
replay: eventLog_replay,
|
|
174
|
-
replayStream: eventLog_replayStream,
|
|
175
|
-
appendStream: eventLog_appendStream,
|
|
176
|
-
latestSnapshot: eventLog_latestSnapshot,
|
|
177
|
-
writeSnapshot: eventLog_writeSnapshot
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
let TestOps = {
|
|
181
|
-
Spec: undefined,
|
|
182
|
-
EventLog: EventLog,
|
|
183
|
-
eventLog: eventLog
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
let TestHandler = Aggregate_Callback$ReventlessCore.Make({
|
|
187
|
-
Id: {
|
|
188
|
-
schema: Id$Reventless.StringPure.schema,
|
|
189
|
-
make: prim => prim,
|
|
190
|
-
makeFromString: prim => prim,
|
|
191
|
-
toString: prim => prim,
|
|
192
|
-
cmp: Id$Reventless.StringPure.cmp
|
|
193
|
-
},
|
|
194
|
-
name: name,
|
|
195
|
-
eventSchema: eventSchema,
|
|
196
|
-
errorSchema: errorSchema,
|
|
197
|
-
commandSchema: commandSchema,
|
|
198
|
-
moduleUrl: moduleUrl,
|
|
199
|
-
commandAuthorization: commandAuthorization
|
|
200
|
-
})({
|
|
201
|
-
initialState: initialState,
|
|
202
|
-
evolve: evolve,
|
|
203
|
-
decide: decide,
|
|
204
|
-
snapshot: undefined,
|
|
205
|
-
moduleUrl: moduleUrl$1
|
|
206
|
-
})({
|
|
207
|
-
Spec: {
|
|
208
|
-
Id: {
|
|
209
|
-
schema: Id$Reventless.StringPure.schema,
|
|
210
|
-
make: prim => prim,
|
|
211
|
-
makeFromString: prim => prim,
|
|
212
|
-
toString: prim => prim,
|
|
213
|
-
cmp: Id$Reventless.StringPure.cmp
|
|
214
|
-
},
|
|
215
|
-
name: name,
|
|
216
|
-
eventSchema: eventSchema,
|
|
217
|
-
errorSchema: errorSchema,
|
|
218
|
-
commandSchema: commandSchema,
|
|
219
|
-
moduleUrl: moduleUrl,
|
|
220
|
-
commandAuthorization: commandAuthorization
|
|
221
|
-
},
|
|
222
|
-
EventLog: {
|
|
223
|
-
Spec: {
|
|
224
|
-
Id: {
|
|
225
|
-
schema: Id$Reventless.StringPure.schema,
|
|
226
|
-
make: prim => prim,
|
|
227
|
-
makeFromString: prim => prim,
|
|
228
|
-
toString: prim => prim,
|
|
229
|
-
cmp: Id$Reventless.StringPure.cmp
|
|
230
|
-
},
|
|
231
|
-
name: name$1,
|
|
232
|
-
eventSchema: eventSchema
|
|
233
|
-
},
|
|
234
|
-
make: make
|
|
235
|
-
},
|
|
236
|
-
eventLog: eventLog
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
let testMeta = {
|
|
240
|
-
service: "ConflictTestAggregate",
|
|
241
|
-
time: "2024-01-01T00:00:00Z",
|
|
242
|
-
ip: "127.0.0.1",
|
|
243
|
-
user: "test-user",
|
|
244
|
-
msgId: "msg-1",
|
|
245
|
-
correlationId: "corr-1"
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
function makeTopicItem(reference, command) {
|
|
249
|
-
return {
|
|
250
|
-
command: {
|
|
251
|
-
id: "agg-1",
|
|
252
|
-
meta: testMeta,
|
|
253
|
-
command: command
|
|
254
|
-
},
|
|
255
|
-
reference: reference
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
globalThis.beforeEach(() => {
|
|
260
|
-
mock.reset();
|
|
261
|
-
TestHandler.resetCache();
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
globalThis.describe("Aggregate_Callback — conflict retry:", () => {
|
|
265
|
-
globalThis.test("1 conflict retries and succeeds", async () => {
|
|
266
|
-
mock.failNextAppendsWithConflict.contents = 1;
|
|
267
|
-
let results = await Effect.runPromise(TestHandler.handleCommands(Stream.fromIterable([{
|
|
268
|
-
command: {
|
|
269
|
-
id: "agg-1",
|
|
270
|
-
meta: testMeta,
|
|
271
|
-
command: {
|
|
272
|
-
TAG: "Create",
|
|
273
|
-
name: "Widget"
|
|
274
|
-
}
|
|
275
|
-
},
|
|
276
|
-
reference: "ref-1"
|
|
277
|
-
}])));
|
|
278
|
-
globalThis.expect(results).toEqual([{
|
|
279
|
-
TAG: "Ok",
|
|
280
|
-
_0: "ref-1"
|
|
281
|
-
}]);
|
|
282
|
-
globalThis.expect(mock.appendCallCount.contents).toBe(2);
|
|
283
|
-
});
|
|
284
|
-
globalThis.test("conflict triggers re-replay", async () => {
|
|
285
|
-
mock.failNextAppendsWithConflict.contents = 1;
|
|
286
|
-
await Effect.runPromise(TestHandler.handleCommands(Stream.fromIterable([{
|
|
287
|
-
command: {
|
|
288
|
-
id: "agg-1",
|
|
289
|
-
meta: testMeta,
|
|
290
|
-
command: {
|
|
291
|
-
TAG: "Create",
|
|
292
|
-
name: "Widget"
|
|
293
|
-
}
|
|
294
|
-
},
|
|
295
|
-
reference: "ref-1"
|
|
296
|
-
}])));
|
|
297
|
-
globalThis.expect(mock.replayCallCount.contents).toBe(2);
|
|
298
|
-
});
|
|
299
|
-
globalThis.test("2 conflicts retry twice and succeed", async () => {
|
|
300
|
-
mock.failNextAppendsWithConflict.contents = 2;
|
|
301
|
-
let results = await Effect.runPromise(TestHandler.handleCommands(Stream.fromIterable([{
|
|
302
|
-
command: {
|
|
303
|
-
id: "agg-1",
|
|
304
|
-
meta: testMeta,
|
|
305
|
-
command: {
|
|
306
|
-
TAG: "Create",
|
|
307
|
-
name: "Widget"
|
|
308
|
-
}
|
|
309
|
-
},
|
|
310
|
-
reference: "ref-1"
|
|
311
|
-
}])));
|
|
312
|
-
globalThis.expect(results).toEqual([{
|
|
313
|
-
TAG: "Ok",
|
|
314
|
-
_0: "ref-1"
|
|
315
|
-
}]);
|
|
316
|
-
globalThis.expect(mock.appendCallCount.contents).toBe(3);
|
|
317
|
-
});
|
|
318
|
-
globalThis.test("max retries exhausted returns Error with detail message", async () => {
|
|
319
|
-
mock.failNextAppendsWithConflict.contents = 4;
|
|
320
|
-
let results = await Effect.runPromise(TestHandler.handleCommands(Stream.fromIterable([{
|
|
321
|
-
command: {
|
|
322
|
-
id: "agg-1",
|
|
323
|
-
meta: testMeta,
|
|
324
|
-
command: {
|
|
325
|
-
TAG: "Create",
|
|
326
|
-
name: "Widget"
|
|
327
|
-
}
|
|
328
|
-
},
|
|
329
|
-
reference: "ref-1"
|
|
330
|
-
}])));
|
|
331
|
-
globalThis.expect(results).toEqual([{
|
|
332
|
-
TAG: "Error",
|
|
333
|
-
_0: "concurrent modification (3 retries exhausted): conflict"
|
|
334
|
-
}]);
|
|
335
|
-
globalThis.expect(mock.appendCallCount.contents).toBe(4);
|
|
336
|
-
});
|
|
337
|
-
globalThis.test("successful append after conflict stores event", async () => {
|
|
338
|
-
mock.failNextAppendsWithConflict.contents = 1;
|
|
339
|
-
await Effect.runPromise(TestHandler.handleCommands(Stream.fromIterable([{
|
|
340
|
-
command: {
|
|
341
|
-
id: "agg-1",
|
|
342
|
-
meta: testMeta,
|
|
343
|
-
command: {
|
|
344
|
-
TAG: "Create",
|
|
345
|
-
name: "Widget"
|
|
346
|
-
}
|
|
347
|
-
},
|
|
348
|
-
reference: "ref-1"
|
|
349
|
-
}])));
|
|
350
|
-
globalThis.expect(mock.getAll().length).toBe(1);
|
|
351
|
-
});
|
|
352
|
-
globalThis.test("no conflict does not retry", async () => {
|
|
353
|
-
let results = await Effect.runPromise(TestHandler.handleCommands(Stream.fromIterable([{
|
|
354
|
-
command: {
|
|
355
|
-
id: "agg-1",
|
|
356
|
-
meta: testMeta,
|
|
357
|
-
command: {
|
|
358
|
-
TAG: "Create",
|
|
359
|
-
name: "Widget"
|
|
360
|
-
}
|
|
361
|
-
},
|
|
362
|
-
reference: "ref-1"
|
|
363
|
-
}])));
|
|
364
|
-
globalThis.expect(results).toEqual([{
|
|
365
|
-
TAG: "Ok",
|
|
366
|
-
_0: "ref-1"
|
|
367
|
-
}]);
|
|
368
|
-
globalThis.expect(mock.appendCallCount.contents).toBe(1);
|
|
369
|
-
globalThis.expect(mock.replayCallCount.contents).toBe(1);
|
|
370
|
-
});
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
let OuterEventLog;
|
|
374
|
-
|
|
375
|
-
export {
|
|
376
|
-
AggSpec,
|
|
377
|
-
TestBehavior,
|
|
378
|
-
makeMockEL,
|
|
379
|
-
mock,
|
|
380
|
-
OuterEventLog,
|
|
381
|
-
TestOps,
|
|
382
|
-
TestHandler,
|
|
383
|
-
testMeta,
|
|
384
|
-
makeTopicItem,
|
|
385
|
-
}
|
|
386
|
-
/* Not a pure module */
|
|
@@ -1,308 +0,0 @@
|
|
|
1
|
-
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
-
|
|
3
|
-
import * as S from "sury/src/S.res.mjs";
|
|
4
|
-
import * as Id$Reventless from "@reventlessdev/reventless-spec/src/types/Id.res.mjs";
|
|
5
|
-
import * as Stream from "effect/Stream";
|
|
6
|
-
import * as Aggregate_Callback$ReventlessCore from "../../src/components/Aggregate/Aggregate_Callback.res.mjs";
|
|
7
|
-
|
|
8
|
-
S.enableJson();
|
|
9
|
-
|
|
10
|
-
let name = "TestAggregate";
|
|
11
|
-
|
|
12
|
-
let commandSchema = S.union([
|
|
13
|
-
S.schema(s => ({
|
|
14
|
-
TAG: "Create",
|
|
15
|
-
name: s.m(S.string)
|
|
16
|
-
})),
|
|
17
|
-
S.schema(s => ({
|
|
18
|
-
TAG: "Rename",
|
|
19
|
-
newName: s.m(S.string)
|
|
20
|
-
}))
|
|
21
|
-
]);
|
|
22
|
-
|
|
23
|
-
let eventSchema = S.union([
|
|
24
|
-
S.schema(s => ({
|
|
25
|
-
TAG: "Created",
|
|
26
|
-
name: s.m(S.string)
|
|
27
|
-
})),
|
|
28
|
-
S.schema(s => ({
|
|
29
|
-
TAG: "Renamed",
|
|
30
|
-
newName: s.m(S.string)
|
|
31
|
-
}))
|
|
32
|
-
]);
|
|
33
|
-
|
|
34
|
-
let errorSchema = S.union([
|
|
35
|
-
S.literal("AlreadyExists"),
|
|
36
|
-
S.literal("NotFound")
|
|
37
|
-
]);
|
|
38
|
-
|
|
39
|
-
let moduleUrl = import.meta.url;
|
|
40
|
-
|
|
41
|
-
function commandAuthorization(param) {
|
|
42
|
-
return "AllowAuthenticated";
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
let AggSpec = {
|
|
46
|
-
Id: undefined,
|
|
47
|
-
name: name,
|
|
48
|
-
commandSchema: commandSchema,
|
|
49
|
-
eventSchema: eventSchema,
|
|
50
|
-
errorSchema: errorSchema,
|
|
51
|
-
moduleUrl: moduleUrl,
|
|
52
|
-
commandAuthorization: commandAuthorization
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
let stateSchema = S.union([
|
|
56
|
-
S.literal("NotCreated"),
|
|
57
|
-
S.schema(s => ({
|
|
58
|
-
TAG: "Created",
|
|
59
|
-
name: s.m(S.string)
|
|
60
|
-
}))
|
|
61
|
-
]);
|
|
62
|
-
|
|
63
|
-
let moduleUrl$1 = import.meta.url;
|
|
64
|
-
|
|
65
|
-
function evolve(_state, event) {
|
|
66
|
-
if (event.TAG === "Created") {
|
|
67
|
-
return {
|
|
68
|
-
TAG: "Created",
|
|
69
|
-
name: event.name
|
|
70
|
-
};
|
|
71
|
-
} else {
|
|
72
|
-
return {
|
|
73
|
-
TAG: "Created",
|
|
74
|
-
name: event.newName
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function decide(state, command) {
|
|
80
|
-
if (typeof state !== "object") {
|
|
81
|
-
if (command.TAG === "Create") {
|
|
82
|
-
return {
|
|
83
|
-
TAG: "Ok",
|
|
84
|
-
_0: [{
|
|
85
|
-
TAG: "Created",
|
|
86
|
-
name: command.name
|
|
87
|
-
}]
|
|
88
|
-
};
|
|
89
|
-
} else {
|
|
90
|
-
return {
|
|
91
|
-
TAG: "Error",
|
|
92
|
-
_0: "NotFound"
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
} else if (command.TAG === "Create") {
|
|
96
|
-
return {
|
|
97
|
-
TAG: "Error",
|
|
98
|
-
_0: "AlreadyExists"
|
|
99
|
-
};
|
|
100
|
-
} else {
|
|
101
|
-
return {
|
|
102
|
-
TAG: "Ok",
|
|
103
|
-
_0: [{
|
|
104
|
-
TAG: "Renamed",
|
|
105
|
-
newName: command.newName
|
|
106
|
-
}]
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
let TestBehavior = {
|
|
112
|
-
Spec: undefined,
|
|
113
|
-
stateSchema: stateSchema,
|
|
114
|
-
initialState: "NotCreated",
|
|
115
|
-
snapshot: undefined,
|
|
116
|
-
moduleUrl: moduleUrl$1,
|
|
117
|
-
evolve: evolve,
|
|
118
|
-
decide: decide
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
function makeMockEL() {
|
|
122
|
-
let storedRef = {
|
|
123
|
-
contents: []
|
|
124
|
-
};
|
|
125
|
-
let failRef = {
|
|
126
|
-
contents: false
|
|
127
|
-
};
|
|
128
|
-
let appendFn = async (_seqNr, _id, newEvents) => {
|
|
129
|
-
if (failRef.contents) {
|
|
130
|
-
failRef.contents = false;
|
|
131
|
-
return {
|
|
132
|
-
TAG: "Error",
|
|
133
|
-
_0: {
|
|
134
|
-
TAG: "StorageFailure",
|
|
135
|
-
_0: "append failed"
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
} else {
|
|
139
|
-
storedRef.contents = storedRef.contents.concat(newEvents);
|
|
140
|
-
return {
|
|
141
|
-
TAG: "Ok",
|
|
142
|
-
_0: undefined
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
let replayFn = async id => storedRef.contents.filter(e => e.id === id).map(e => e.event);
|
|
147
|
-
let replayStreamFn = id => Stream.fromIterable(storedRef.contents.filter(e => e.id === id).map(e => e.event));
|
|
148
|
-
return {
|
|
149
|
-
appendFn: appendFn,
|
|
150
|
-
replayFn: replayFn,
|
|
151
|
-
replayStreamFn: replayStreamFn,
|
|
152
|
-
getAll: () => storedRef.contents,
|
|
153
|
-
failNextAppend: failRef,
|
|
154
|
-
reset: () => {
|
|
155
|
-
storedRef.contents = [];
|
|
156
|
-
failRef.contents = false;
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
let mock = makeMockEL();
|
|
162
|
-
|
|
163
|
-
let name$1 = "MockEventLog";
|
|
164
|
-
|
|
165
|
-
let Spec = {
|
|
166
|
-
Id: undefined,
|
|
167
|
-
name: name$1,
|
|
168
|
-
eventSchema: eventSchema
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
function make(param, param$1) {
|
|
172
|
-
return 0;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
let EventLog = {
|
|
176
|
-
Spec: Spec,
|
|
177
|
-
make: make
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
let eventLog_append = mock.appendFn;
|
|
181
|
-
|
|
182
|
-
let eventLog_replay = mock.replayFn;
|
|
183
|
-
|
|
184
|
-
function eventLog_replayStream(id, param) {
|
|
185
|
-
return mock.replayStreamFn(id);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
function eventLog_appendStream(_startingSeqNr, _id, stream) {
|
|
189
|
-
return Stream.runDrain(stream);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
async function eventLog_latestSnapshot(param) {
|
|
193
|
-
return {
|
|
194
|
-
TAG: "Ok",
|
|
195
|
-
_0: undefined
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
async function eventLog_writeSnapshot(param, param$1) {
|
|
200
|
-
return {
|
|
201
|
-
TAG: "Ok",
|
|
202
|
-
_0: undefined
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
let eventLog = {
|
|
207
|
-
append: eventLog_append,
|
|
208
|
-
replay: eventLog_replay,
|
|
209
|
-
replayStream: eventLog_replayStream,
|
|
210
|
-
appendStream: eventLog_appendStream,
|
|
211
|
-
latestSnapshot: eventLog_latestSnapshot,
|
|
212
|
-
writeSnapshot: eventLog_writeSnapshot
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
let TestOps = {
|
|
216
|
-
Spec: undefined,
|
|
217
|
-
EventLog: EventLog,
|
|
218
|
-
eventLog: eventLog
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
let TestHandler = Aggregate_Callback$ReventlessCore.Make({
|
|
222
|
-
Id: {
|
|
223
|
-
schema: Id$Reventless.StringPure.schema,
|
|
224
|
-
make: prim => prim,
|
|
225
|
-
makeFromString: prim => prim,
|
|
226
|
-
toString: prim => prim,
|
|
227
|
-
cmp: Id$Reventless.StringPure.cmp
|
|
228
|
-
},
|
|
229
|
-
name: name,
|
|
230
|
-
eventSchema: eventSchema,
|
|
231
|
-
errorSchema: errorSchema,
|
|
232
|
-
commandSchema: commandSchema,
|
|
233
|
-
moduleUrl: moduleUrl,
|
|
234
|
-
commandAuthorization: commandAuthorization
|
|
235
|
-
})({
|
|
236
|
-
initialState: "NotCreated",
|
|
237
|
-
evolve: evolve,
|
|
238
|
-
decide: decide,
|
|
239
|
-
snapshot: undefined,
|
|
240
|
-
moduleUrl: moduleUrl$1
|
|
241
|
-
})({
|
|
242
|
-
Spec: {
|
|
243
|
-
Id: {
|
|
244
|
-
schema: Id$Reventless.StringPure.schema,
|
|
245
|
-
make: prim => prim,
|
|
246
|
-
makeFromString: prim => prim,
|
|
247
|
-
toString: prim => prim,
|
|
248
|
-
cmp: Id$Reventless.StringPure.cmp
|
|
249
|
-
},
|
|
250
|
-
name: name,
|
|
251
|
-
eventSchema: eventSchema,
|
|
252
|
-
errorSchema: errorSchema,
|
|
253
|
-
commandSchema: commandSchema,
|
|
254
|
-
moduleUrl: moduleUrl,
|
|
255
|
-
commandAuthorization: commandAuthorization
|
|
256
|
-
},
|
|
257
|
-
EventLog: {
|
|
258
|
-
Spec: {
|
|
259
|
-
Id: {
|
|
260
|
-
schema: Id$Reventless.StringPure.schema,
|
|
261
|
-
make: prim => prim,
|
|
262
|
-
makeFromString: prim => prim,
|
|
263
|
-
toString: prim => prim,
|
|
264
|
-
cmp: Id$Reventless.StringPure.cmp
|
|
265
|
-
},
|
|
266
|
-
name: name$1,
|
|
267
|
-
eventSchema: eventSchema
|
|
268
|
-
},
|
|
269
|
-
make: make
|
|
270
|
-
},
|
|
271
|
-
eventLog: eventLog
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
let testMeta = {
|
|
275
|
-
service: "TestAggregate",
|
|
276
|
-
time: "2024-01-01T00:00:00Z",
|
|
277
|
-
ip: "127.0.0.1",
|
|
278
|
-
user: "test-user",
|
|
279
|
-
msgId: "msg-1",
|
|
280
|
-
correlationId: "corr-1"
|
|
281
|
-
};
|
|
282
|
-
|
|
283
|
-
function makeTopicItem(aggIdOpt, reference, command) {
|
|
284
|
-
let aggId = aggIdOpt !== undefined ? aggIdOpt : "agg-1";
|
|
285
|
-
return {
|
|
286
|
-
command: {
|
|
287
|
-
id: aggId,
|
|
288
|
-
meta: testMeta,
|
|
289
|
-
command: command
|
|
290
|
-
},
|
|
291
|
-
reference: reference
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
let OuterEventLog;
|
|
296
|
-
|
|
297
|
-
export {
|
|
298
|
-
AggSpec,
|
|
299
|
-
TestBehavior,
|
|
300
|
-
makeMockEL,
|
|
301
|
-
mock,
|
|
302
|
-
OuterEventLog,
|
|
303
|
-
TestOps,
|
|
304
|
-
TestHandler,
|
|
305
|
-
testMeta,
|
|
306
|
-
makeTopicItem,
|
|
307
|
-
}
|
|
308
|
-
/* Not a pure module */
|