@reventlessdev/reventless-core 3.0.0-alpha.180 → 3.0.0-alpha.182

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.
Files changed (115) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/package.json +7 -7
  3. package/src/Message.res +2 -1
  4. package/src/Message.res.mjs +5 -1
  5. package/src/admin/Platform_Admin_Structure.res +2 -0
  6. package/src/admin/Platform_Admin_Structure.res.mjs +2 -0
  7. package/src/admin/Platform_ComponentDefinitionsApi.res +2 -1
  8. package/src/admin/Platform_ComponentDefinitionsApi.res.mjs +5 -1
  9. package/src/admin/UiFragmentRegistry/StateViewSlice/UiFragments_Projection.res +1 -1
  10. package/src/admin/UiFragmentRegistry/StateViewSlice/UiFragments_Projection.res.mjs +2 -1
  11. package/src/components/Api/ApiTargetStateHelpers.res +20 -0
  12. package/src/components/Api/ApiTargetStateHelpers.res.mjs +16 -0
  13. package/src/components/Api/GraphQL_FragmentGenerator.res +1 -0
  14. package/src/components/Api/GraphQL_FragmentGenerator.res.mjs +1 -0
  15. package/src/components/Api/SchemaType.res +6 -1
  16. package/src/components/Api/SchemaType.res.mjs +22 -4
  17. package/src/components/Api/SuryToJsonSchema.res +16 -0
  18. package/src/components/Api/SuryToJsonSchema.res.mjs +28 -0
  19. package/src/components/Dcb/Dcb_Builder.res +4 -5
  20. package/src/components/Dcb/Dcb_Builder.res.mjs +3 -5
  21. package/src/components/DcbEventLog/DcbEventLog_Operations.res +6 -1
  22. package/src/components/DcbEventLog/DcbEventLog_Operations.res.mjs +2 -1
  23. package/src/components/InboundTranslationSlice/InboundTranslationSlice.res +25 -0
  24. package/src/components/InboundTranslationSlice/InboundTranslationSlice.res.mjs +31 -0
  25. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res +8 -8
  26. package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res.mjs +26 -6
  27. package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res +44 -37
  28. package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res.mjs +17 -25
  29. package/src/components/StateChangeSlice/StateChangeSlice_Callback.res +27 -2
  30. package/src/components/StateChangeSlice/StateChangeSlice_Callback.res.mjs +4 -0
  31. package/src/components/StateViewSlice/StateViewSlice_Builder.res +20 -6
  32. package/src/components/StateViewSlice/StateViewSlice_Builder.res.mjs +23 -5
  33. package/src/components/StateViewSlice/StateViewSlice_Callback.res +1 -1
  34. package/src/components/StateViewSlice/StateViewSlice_Callback.res.mjs +5 -1
  35. package/src/plugin/component/Plugin_Helpers.res +4 -1
  36. package/src/plugin/component/Plugin_Structure.res +15 -1
  37. package/src/plugin/component/Plugin_Structure.res.mjs +4 -1
  38. package/src/plugin/lifecycle/PluginsReadModelSpec.res.mjs +2 -0
  39. package/tests/IdentityTest.res.mjs +174 -0
  40. package/tests/ResourceAttributionTest.res.mjs +75 -0
  41. package/tests/adapter/MonitoringTest.res.mjs +116 -0
  42. package/tests/admin/Platform_ComponentDefinitionsApiTest.res +10 -0
  43. package/tests/admin/Platform_ComponentDefinitionsApiTest.res.mjs +365 -0
  44. package/tests/admin/Platform_UIFragmentsApiTest.res.mjs +101 -0
  45. package/tests/aggregate/AggregateCacheTest.res.mjs +433 -0
  46. package/tests/aggregate/AggregateCallbackTest.res.mjs +143 -0
  47. package/tests/aggregate/AggregateCausationTest.res.mjs +47 -0
  48. package/tests/aggregate/AggregateConflictTest.res.mjs +386 -0
  49. package/tests/aggregate/AggregateFixtures.res.mjs +308 -0
  50. package/tests/aggregate/AggregateRejectionTest.res.mjs +166 -0
  51. package/tests/aggregate/AggregateSnapshotTest.res.mjs +645 -0
  52. package/tests/api/ApiNoApiTest.res.mjs +90 -0
  53. package/tests/api/GraphQL_StitcherTest.res.mjs +112 -0
  54. package/tests/api/SimpleTest.res.mjs +10 -0
  55. package/tests/api/SuryToJsonSchemaTest.res +68 -0
  56. package/tests/api/SuryToJsonSchemaTest.res.mjs +843 -0
  57. package/tests/commandgenerator/CommandGeneratorCallbackTest.res.mjs +160 -0
  58. package/tests/commandgenerator/CommandGeneratorFixtures.res.mjs +197 -0
  59. package/tests/commandtopic/CommandTopicCallbackFixtures.res.mjs +152 -0
  60. package/tests/commandtopic/CommandTopicCallbackTest.res.mjs +106 -0
  61. package/tests/commandtopic/CommandTopicHelpersRejectionTest.res.mjs +109 -0
  62. package/tests/counter/CounterCallbackTest.res.mjs +140 -0
  63. package/tests/counter/CounterFixtures.res.mjs +67 -0
  64. package/tests/dcb/DcbDecodeTest.res.mjs +194 -0
  65. package/tests/dcb/DcbEventLogOperationsTest.res.mjs +268 -0
  66. package/tests/dcb/DcbFixtures.res.mjs +534 -0
  67. package/tests/dcb/DcbScopeInferenceTest.res.mjs +480 -0
  68. package/tests/dcb/DcbStateChangeSliceTest.res.mjs +540 -0
  69. package/tests/dcb/DcbTagTest.res.mjs +867 -0
  70. package/tests/dcb/DcbValidationTest.res.mjs +476 -0
  71. package/tests/eventlog/EventLogFixtures.res.mjs +196 -0
  72. package/tests/eventlog/EventLogOperationsTest.res.mjs +192 -0
  73. package/tests/eventlog/EventLogRetryTest.res.mjs +195 -0
  74. package/tests/eventmapper/EventMapperCallbackTest.res.mjs +141 -0
  75. package/tests/eventmapper/EventMapperFixtures.res.mjs +440 -0
  76. package/tests/eventmapper/EventMapperTest.res.mjs +83 -0
  77. package/tests/eventtopic/EventTopicFixtures.res.mjs +65 -0
  78. package/tests/eventtopic/EventTopicOperationsTest.res.mjs +71 -0
  79. package/tests/extensionpoint/ExtensionPointCallbackTest.res.mjs +94 -0
  80. package/tests/extensionpoint/ExtensionPointFixtures.res.mjs +205 -0
  81. package/tests/extensionpoint/ExtensionPointOperationsTest.res.mjs +304 -0
  82. package/tests/extensionpoint/PluginDisconnectScheduleTest.res.mjs +92 -0
  83. package/tests/ftp/FTPTest.res.mjs +88 -0
  84. package/tests/logger/LogFormatTest.res.mjs +329 -0
  85. package/tests/logger/LoggerLazyTest.res.mjs +40 -0
  86. package/tests/message/MessageTest.res.mjs +218 -0
  87. package/tests/message/MetaEnvelopeTest.res.mjs +188 -0
  88. package/tests/plugin/HeartbeatDisconnectGraceTest.res.mjs +91 -0
  89. package/tests/plugin/ManifestVisibilityTest.res.mjs +215 -0
  90. package/tests/plugin/PluginSpecExperiment.res.mjs +31 -0
  91. package/tests/plugin/PluginStructureTest.res +55 -0
  92. package/tests/plugin/PluginStructureTest.res.mjs +467 -0
  93. package/tests/plugin/PluginVersionTest.res.mjs +30 -0
  94. package/tests/plugin/SchemaWalkerTest.res.mjs +160 -0
  95. package/tests/plugin/StateChangeSlice/PsPlaceOrder.res.mjs +62 -0
  96. package/tests/plugin/StateChangeSlice/PsShipOrder.res +4 -1
  97. package/tests/plugin/StateChangeSlice/PsShipOrder.res.mjs +77 -0
  98. package/tests/plugin/StateViewSlice/PsAnnotatedView.res +5 -4
  99. package/tests/plugin/StateViewSlice/PsAnnotatedView.res.mjs +110 -0
  100. package/tests/plugin/StateViewSlice/PsAvailableProductsView.res +1 -1
  101. package/tests/plugin/StateViewSlice/PsAvailableProductsView.res.mjs +70 -0
  102. package/tests/plugin/StateViewSlice/PsCustomersView.res +1 -1
  103. package/tests/plugin/StateViewSlice/PsCustomersView.res.mjs +70 -0
  104. package/tests/plugin/StateViewSlice/PsOrdersView.res +1 -1
  105. package/tests/plugin/StateViewSlice/PsOrdersView.res.mjs +82 -0
  106. package/tests/poc/StructuralSubtypingPoc.res.mjs +61 -0
  107. package/tests/projection/ProjectionOptimizeTest.res.mjs +75 -0
  108. package/tests/querydb/QueryDbFixtures.res.mjs +135 -0
  109. package/tests/querydb/QueryDbOperationsTest.res.mjs +168 -0
  110. package/tests/sideeffecthandler/SideEffectHandlerCallbackTest.res.mjs +77 -0
  111. package/tests/sideeffecthandler/SideEffectHandlerFixtures.res.mjs +139 -0
  112. package/tests/util/CommandPublisherTest.res.mjs +78 -0
  113. package/tests/util/CsvStreamTest.res.mjs +51 -0
  114. package/tests/util/LruTest.res.mjs +105 -0
  115. package/tests/util/MetricsTest.res.mjs +53 -0
@@ -0,0 +1,440 @@
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 Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js";
6
+ import * as Message$Reventless from "@reventlessdev/reventless-spec/src/types/Message.res.mjs";
7
+ import * as ReadModel$Reventless from "@reventlessdev/reventless-spec/src/components/ReadModel.res.mjs";
8
+ import * as Projection$Reventless from "@reventlessdev/reventless-spec/src/types/Projection.res.mjs";
9
+ import * as EventMapper_Callback$ReventlessCore from "../../src/components/EventMapper/EventMapper_Callback.res.mjs";
10
+
11
+ S.enableJson();
12
+
13
+ let name = "SourceAggregate";
14
+
15
+ let eventSchema = S.union([
16
+ S.schema(s => ({
17
+ TAG: "ItemCreated",
18
+ name: s.m(S.string),
19
+ price: s.m(S.float)
20
+ })),
21
+ S.schema(s => ({
22
+ TAG: "ItemPriceUpdated",
23
+ newPrice: s.m(S.float)
24
+ })),
25
+ S.literal("ItemRemoved")
26
+ ]);
27
+
28
+ let moduleUrl = import.meta.url;
29
+
30
+ let SourceSpec = {
31
+ Id: undefined,
32
+ name: name,
33
+ eventSchema: eventSchema,
34
+ moduleUrl: moduleUrl
35
+ };
36
+
37
+ let name$1 = "ItemCatalog";
38
+
39
+ let stateSchema = S.schema(s => ({
40
+ name: s.m(S.string),
41
+ price: s.m(S.float)
42
+ }));
43
+
44
+ let config = ReadModel$Reventless.config(undefined, undefined, undefined);
45
+
46
+ let TargetSpec = {
47
+ Id: undefined,
48
+ name: name$1,
49
+ stateSchema: stateSchema,
50
+ config: config,
51
+ subIdConfig: undefined,
52
+ authorization: "AllowAuthenticated",
53
+ visibility: "Public"
54
+ };
55
+
56
+ function project(msg) {
57
+ let match = msg.event;
58
+ if (typeof match !== "object") {
59
+ return {
60
+ TAG: "Delete",
61
+ _0: msg.id
62
+ };
63
+ }
64
+ if (match.TAG === "ItemCreated") {
65
+ return {
66
+ TAG: "Create",
67
+ _0: msg.id,
68
+ _1: {
69
+ name: match.name,
70
+ price: match.price
71
+ }
72
+ };
73
+ }
74
+ let newPrice = match.newPrice;
75
+ return {
76
+ TAG: "Update",
77
+ _0: msg.id,
78
+ _1: s => ({
79
+ name: s.name,
80
+ price: newPrice
81
+ })
82
+ };
83
+ }
84
+
85
+ let ItemMapping = Projection$Reventless.Mapping.Make({
86
+ Id: Id$Reventless.$$String,
87
+ name: name,
88
+ eventSchema: eventSchema
89
+ })({
90
+ Id: Id$Reventless.$$String,
91
+ name: name$1,
92
+ stateSchema: stateSchema,
93
+ subIdConfig: undefined
94
+ })({
95
+ project: project
96
+ });
97
+
98
+ let testMeta = {
99
+ service: "SourceAggregate",
100
+ time: "2024-01-01T00:00:00.000Z",
101
+ ip: "127.0.0.1",
102
+ user: "testuser",
103
+ msgId: "msg-001",
104
+ correlationId: "corr-001"
105
+ };
106
+
107
+ function makeSourceEvent$p(id, event) {
108
+ return {
109
+ id: id,
110
+ meta: testMeta,
111
+ event: event
112
+ };
113
+ }
114
+
115
+ let name$2 = "TestCmdSource";
116
+
117
+ let eventSchema$1 = S.union([
118
+ S.schema(s => ({
119
+ TAG: "OrderPlaced",
120
+ orderId: s.m(S.string),
121
+ amount: s.m(S.float)
122
+ })),
123
+ S.schema(s => ({
124
+ TAG: "OrderShipped",
125
+ orderId: s.m(S.string)
126
+ }))
127
+ ]);
128
+
129
+ let moduleUrl$1 = import.meta.url;
130
+
131
+ let CmdSourceSpec = {
132
+ Id: undefined,
133
+ name: name$2,
134
+ eventSchema: eventSchema$1,
135
+ moduleUrl: moduleUrl$1
136
+ };
137
+
138
+ let name$3 = "TestCmdTarget";
139
+
140
+ let commandSchema = S.union([
141
+ S.schema(s => ({
142
+ TAG: "ProcessOrder",
143
+ orderId: s.m(S.string),
144
+ amount: s.m(S.float)
145
+ })),
146
+ S.schema(s => ({
147
+ TAG: "ShipOrder",
148
+ orderId: s.m(S.string)
149
+ }))
150
+ ]);
151
+
152
+ let moduleUrl$2 = import.meta.url;
153
+
154
+ function commandAuthorization(param) {
155
+ return "AllowAuthenticated";
156
+ }
157
+
158
+ let CmdTargetSpec = {
159
+ Id: undefined,
160
+ name: name$3,
161
+ commandSchema: commandSchema,
162
+ moduleUrl: moduleUrl$2,
163
+ commandAuthorization: commandAuthorization
164
+ };
165
+
166
+ function map(id, event, _queryEngine) {
167
+ if (event.TAG === "OrderPlaced") {
168
+ return [{
169
+ TAG: "Publish",
170
+ _0: id,
171
+ _1: {
172
+ TAG: "ProcessOrder",
173
+ orderId: event.orderId,
174
+ amount: event.amount
175
+ }
176
+ }];
177
+ }
178
+ let cmd = {
179
+ TAG: "ShipOrder",
180
+ orderId: event.orderId
181
+ };
182
+ return [{
183
+ TAG: "Publish",
184
+ _0: id,
185
+ _1: cmd
186
+ }];
187
+ }
188
+
189
+ let OrderMapping = {
190
+ Source: undefined,
191
+ Target: undefined,
192
+ map: map
193
+ };
194
+
195
+ function map$1(_id, event, _queryEngine) {
196
+ if (event.TAG === "OrderPlaced") {
197
+ return [{
198
+ TAG: "Count",
199
+ _0: "order-counter"
200
+ }];
201
+ } else {
202
+ return [{
203
+ TAG: "AddToCounterTarget",
204
+ _0: {
205
+ counterId: "order-counter",
206
+ target: 5
207
+ }
208
+ }];
209
+ }
210
+ }
211
+
212
+ let CountOrderMapping = {
213
+ Source: undefined,
214
+ Target: undefined,
215
+ map: map$1
216
+ };
217
+
218
+ let mappings = [{
219
+ Source: {
220
+ name: name$2,
221
+ Id: {
222
+ schema: Id$Reventless.StringPure.schema,
223
+ make: prim => prim,
224
+ makeFromString: prim => prim,
225
+ toString: prim => prim,
226
+ cmp: Id$Reventless.StringPure.cmp
227
+ },
228
+ eventSchema: eventSchema$1
229
+ },
230
+ map: map
231
+ }];
232
+
233
+ let OrderMappings_Target = {
234
+ Id: Id$Reventless.StringPure,
235
+ name: name$3,
236
+ commandSchema: commandSchema,
237
+ moduleUrl: moduleUrl$2,
238
+ commandAuthorization: commandAuthorization
239
+ };
240
+
241
+ let OrderMappings = {
242
+ Target: OrderMappings_Target,
243
+ mappings: mappings,
244
+ counter: undefined
245
+ };
246
+
247
+ let mappings$1 = [{
248
+ Source: {
249
+ name: name$2,
250
+ Id: {
251
+ schema: Id$Reventless.StringPure.schema,
252
+ make: prim => prim,
253
+ makeFromString: prim => prim,
254
+ toString: prim => prim,
255
+ cmp: Id$Reventless.StringPure.cmp
256
+ },
257
+ eventSchema: eventSchema$1
258
+ },
259
+ map: map$1
260
+ }];
261
+
262
+ let CountOrderMappings_Target = {
263
+ Id: Id$Reventless.StringPure,
264
+ name: name$3,
265
+ commandSchema: commandSchema,
266
+ moduleUrl: moduleUrl$2,
267
+ commandAuthorization: commandAuthorization
268
+ };
269
+
270
+ let CountOrderMappings = {
271
+ Target: CountOrderMappings_Target,
272
+ mappings: mappings$1,
273
+ counter: undefined
274
+ };
275
+
276
+ let capturedCmds = {
277
+ contents: []
278
+ };
279
+
280
+ let capturedCountItems = {
281
+ contents: []
282
+ };
283
+
284
+ let capturedCounterTargets = {
285
+ contents: []
286
+ };
287
+
288
+ async function mockQueryEngine_scan(param, param$1, param$2) {
289
+ return [];
290
+ }
291
+
292
+ async function mockQueryEngine_query(param, param$1, param$2, param$3, param$4, param$5, param$6) {
293
+ return [];
294
+ }
295
+
296
+ let mockQueryEngine = {
297
+ scan: mockQueryEngine_scan,
298
+ query: mockQueryEngine_query
299
+ };
300
+
301
+ async function publishJsons(cmds) {
302
+ capturedCmds.contents = capturedCmds.contents.concat(cmds);
303
+ }
304
+
305
+ let MockCounterOps = {
306
+ publishJsons: publishJsons,
307
+ queryEngine: mockQueryEngine
308
+ };
309
+
310
+ let TestCounterHandler = EventMapper_Callback$ReventlessCore.MakeCounterHandler({
311
+ name: name$3,
312
+ Id: {
313
+ schema: Id$Reventless.StringPure.schema,
314
+ make: prim => prim,
315
+ makeFromString: prim => prim,
316
+ toString: prim => prim,
317
+ cmp: Id$Reventless.StringPure.cmp
318
+ },
319
+ commandSchema: commandSchema
320
+ })({
321
+ mappings: mappings,
322
+ counter: undefined
323
+ })(MockCounterOps);
324
+
325
+ let mockCommonHandler = {
326
+ contents: async param => [
327
+ Promise.resolve([]),
328
+ []
329
+ ]
330
+ };
331
+
332
+ let mockCountFailUntil = {
333
+ contents: 0
334
+ };
335
+
336
+ let mockCountCallCount = {
337
+ contents: 0
338
+ };
339
+
340
+ async function publishJsons$1(cmds) {
341
+ capturedCmds.contents = capturedCmds.contents.concat(cmds);
342
+ }
343
+
344
+ async function count(items) {
345
+ mockCountCallCount.contents = mockCountCallCount.contents + 1 | 0;
346
+ capturedCountItems.contents = capturedCountItems.contents.concat(items);
347
+ if (mockCountCallCount.contents <= mockCountFailUntil.contents) {
348
+ return Stdlib_JsError.throwWithMessage("count failed");
349
+ }
350
+ }
351
+
352
+ async function addToCounterTarget(target) {
353
+ capturedCounterTargets.contents = capturedCounterTargets.contents.concat([target]);
354
+ }
355
+
356
+ async function commonEventsHandler(eventsJson$p) {
357
+ return await mockCommonHandler.contents(eventsJson$p);
358
+ }
359
+
360
+ let MockECOps = {
361
+ publishJsons: publishJsons$1,
362
+ count: count,
363
+ addToCounterTarget: addToCounterTarget,
364
+ commonEventsHandler: commonEventsHandler
365
+ };
366
+
367
+ let TestECHandler = EventMapper_Callback$ReventlessCore.MakeEventCollectorHandler(MockECOps);
368
+
369
+ let evtMapTestMeta_ip = "127.0.0.1";
370
+
371
+ let evtMapTestMeta_user = "test-user";
372
+
373
+ let evtMapTestMeta = {
374
+ service: name$2,
375
+ time: "2024-01-01T00:00:00Z",
376
+ ip: evtMapTestMeta_ip,
377
+ user: evtMapTestMeta_user,
378
+ msgId: "test-msg-1",
379
+ correlationId: "test-corr-1"
380
+ };
381
+
382
+ function makeEventJson(serviceOpt, id, eventJson) {
383
+ let service = serviceOpt !== undefined ? serviceOpt : name$2;
384
+ let newrecord = {...evtMapTestMeta};
385
+ return Object.fromEntries([
386
+ [
387
+ "id",
388
+ id
389
+ ],
390
+ [
391
+ "meta",
392
+ Message$Reventless.encode((newrecord.service = service, newrecord), Message$Reventless.metaSchema)
393
+ ],
394
+ [
395
+ "event",
396
+ eventJson
397
+ ]
398
+ ]);
399
+ }
400
+
401
+ function resetMocks() {
402
+ capturedCmds.contents = [];
403
+ capturedCountItems.contents = [];
404
+ capturedCounterTargets.contents = [];
405
+ mockCountFailUntil.contents = 0;
406
+ mockCountCallCount.contents = 0;
407
+ mockCommonHandler.contents = async param => [
408
+ Promise.resolve([]),
409
+ []
410
+ ];
411
+ }
412
+
413
+ export {
414
+ SourceSpec,
415
+ TargetSpec,
416
+ ItemMapping,
417
+ testMeta,
418
+ makeSourceEvent$p,
419
+ CmdSourceSpec,
420
+ CmdTargetSpec,
421
+ OrderMapping,
422
+ CountOrderMapping,
423
+ OrderMappings,
424
+ CountOrderMappings,
425
+ capturedCmds,
426
+ capturedCountItems,
427
+ capturedCounterTargets,
428
+ mockQueryEngine,
429
+ MockCounterOps,
430
+ TestCounterHandler,
431
+ mockCommonHandler,
432
+ mockCountFailUntil,
433
+ mockCountCallCount,
434
+ MockECOps,
435
+ TestECHandler,
436
+ evtMapTestMeta,
437
+ makeEventJson,
438
+ resetMocks,
439
+ }
440
+ /* Not a pure module */
@@ -0,0 +1,83 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as JestGlobals from "@reventlessdev/rescript-jest/src/JestGlobals.res.mjs";
4
+ import * as EventMapperFixtures$ReventlessCore from "./EventMapperFixtures.res.mjs";
5
+
6
+ globalThis.describe("Mapping.Make:", () => {
7
+ globalThis.describe("sourceName", () => {
8
+ globalThis.test("equals source spec name", () => {
9
+ globalThis.expect(EventMapperFixtures$ReventlessCore.ItemMapping.sourceName).toBe("SourceAggregate");
10
+ });
11
+ });
12
+ globalThis.describe("project", () => {
13
+ globalThis.test("ItemCreated maps to Create action", () => {
14
+ let event$p = EventMapperFixtures$ReventlessCore.makeSourceEvent$p("item-1", {
15
+ TAG: "ItemCreated",
16
+ name: "Widget",
17
+ price: 9.99
18
+ });
19
+ let action = EventMapperFixtures$ReventlessCore.ItemMapping.project(event$p);
20
+ if (typeof action !== "object") {
21
+ return JestGlobals.fail("Expected Create action");
22
+ }
23
+ if (action.TAG !== "Create") {
24
+ return JestGlobals.fail("Expected Create action");
25
+ }
26
+ let state = action._1;
27
+ globalThis.expect([
28
+ action._0,
29
+ state.name,
30
+ state.price
31
+ ]).toEqual([
32
+ "item-1",
33
+ "Widget",
34
+ 9.99
35
+ ]);
36
+ });
37
+ globalThis.test("ItemPriceUpdated maps to Update action", () => {
38
+ let event$p = EventMapperFixtures$ReventlessCore.makeSourceEvent$p("item-1", {
39
+ TAG: "ItemPriceUpdated",
40
+ newPrice: 14.99
41
+ });
42
+ let action = EventMapperFixtures$ReventlessCore.ItemMapping.project(event$p);
43
+ if (typeof action !== "object") {
44
+ return JestGlobals.fail("Expected Update action");
45
+ }
46
+ if (action.TAG !== "Update") {
47
+ return JestGlobals.fail("Expected Update action");
48
+ }
49
+ globalThis.expect(action._0).toBe("item-1");
50
+ });
51
+ globalThis.test("ItemRemoved maps to Delete action", () => {
52
+ let event$p = EventMapperFixtures$ReventlessCore.makeSourceEvent$p("item-1", "ItemRemoved");
53
+ let action = EventMapperFixtures$ReventlessCore.ItemMapping.project(event$p);
54
+ if (typeof action !== "object") {
55
+ return JestGlobals.fail("Expected Delete action");
56
+ }
57
+ if (action.TAG !== "Delete") {
58
+ return JestGlobals.fail("Expected Delete action");
59
+ }
60
+ globalThis.expect(action._0).toBe("item-1");
61
+ });
62
+ globalThis.test("Update action applies function correctly", () => {
63
+ let event$p = EventMapperFixtures$ReventlessCore.makeSourceEvent$p("item-1", {
64
+ TAG: "ItemPriceUpdated",
65
+ newPrice: 14.99
66
+ });
67
+ let action = EventMapperFixtures$ReventlessCore.ItemMapping.project(event$p);
68
+ if (typeof action !== "object") {
69
+ return JestGlobals.fail("Expected Update action");
70
+ }
71
+ if (action.TAG !== "Update") {
72
+ return JestGlobals.fail("Expected Update action");
73
+ }
74
+ let updated = action._1({
75
+ name: "Widget",
76
+ price: 9.99
77
+ });
78
+ globalThis.expect(updated.price).toBe(14.99);
79
+ });
80
+ });
81
+ });
82
+
83
+ /* Not a pure module */
@@ -0,0 +1,65 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as S from "sury/src/S.res.mjs";
4
+
5
+ S.enableJson();
6
+
7
+ let eventSchema = S.union([
8
+ S.schema(s => ({
9
+ TAG: "ItemPublished",
10
+ name: s.m(S.string)
11
+ })),
12
+ S.schema(s => ({
13
+ TAG: "ItemRemoved",
14
+ id: s.m(S.string)
15
+ }))
16
+ ]);
17
+
18
+ let ItemEventTopicSpec = {
19
+ Id: undefined,
20
+ name: "TestItemEventTopic",
21
+ eventSchema: eventSchema
22
+ };
23
+
24
+ let capturedCalls = {
25
+ contents: []
26
+ };
27
+
28
+ async function mockPublishJson(service, meta, json) {
29
+ capturedCalls.contents = capturedCalls.contents.concat([[
30
+ service,
31
+ meta,
32
+ json
33
+ ]]);
34
+ }
35
+
36
+ let testMeta = {
37
+ service: "test",
38
+ time: "2024-01-01T00:00:00.000Z",
39
+ ip: "127.0.0.1",
40
+ user: "testuser",
41
+ msgId: "msg-001",
42
+ correlationId: "corr-001"
43
+ };
44
+
45
+ function makeEvent$p(id, event) {
46
+ return {
47
+ id: id,
48
+ meta: testMeta,
49
+ event: event
50
+ };
51
+ }
52
+
53
+ function reset() {
54
+ capturedCalls.contents = [];
55
+ }
56
+
57
+ export {
58
+ ItemEventTopicSpec,
59
+ capturedCalls,
60
+ mockPublishJson,
61
+ testMeta,
62
+ makeEvent$p,
63
+ reset,
64
+ }
65
+ /* Not a pure module */
@@ -0,0 +1,71 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Stdlib_JSON from "@rescript/runtime/lib/es6/Stdlib_JSON.js";
4
+ import * as Id$Reventless from "@reventlessdev/reventless-spec/src/types/Id.res.mjs";
5
+ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
6
+ import * as EventTopicFixtures$ReventlessCore from "./EventTopicFixtures.res.mjs";
7
+ import * as EventTopic_Operations$ReventlessCore from "../../src/components/EventTopic/EventTopic_Operations.res.mjs";
8
+
9
+ let Ops = EventTopic_Operations$ReventlessCore.Make({
10
+ Id: {
11
+ schema: Id$Reventless.StringPure.schema,
12
+ make: prim => prim,
13
+ makeFromString: prim => prim,
14
+ toString: prim => prim,
15
+ cmp: Id$Reventless.StringPure.cmp
16
+ },
17
+ name: EventTopicFixtures$ReventlessCore.ItemEventTopicSpec.name,
18
+ eventSchema: EventTopicFixtures$ReventlessCore.ItemEventTopicSpec.eventSchema
19
+ })({
20
+ publishJson: EventTopicFixtures$ReventlessCore.mockPublishJson
21
+ });
22
+
23
+ globalThis.beforeEach(() => EventTopicFixtures$ReventlessCore.reset());
24
+
25
+ globalThis.describe("EventTopic_Operations:", () => {
26
+ globalThis.describe("publish", () => {
27
+ globalThis.test("calls publishJson for each event", async () => {
28
+ let events = [
29
+ EventTopicFixtures$ReventlessCore.makeEvent$p("item-1", {
30
+ TAG: "ItemPublished",
31
+ name: "Widget"
32
+ }),
33
+ EventTopicFixtures$ReventlessCore.makeEvent$p("item-2", {
34
+ TAG: "ItemRemoved",
35
+ id: "item-2"
36
+ })
37
+ ];
38
+ await Ops.publish(events);
39
+ globalThis.expect(EventTopicFixtures$ReventlessCore.capturedCalls.contents.length).toBe(2);
40
+ });
41
+ globalThis.test("calls publishJson with correct service (id string)", async () => {
42
+ let event$p = EventTopicFixtures$ReventlessCore.makeEvent$p("item-1", {
43
+ TAG: "ItemPublished",
44
+ name: "Widget"
45
+ });
46
+ await Ops.publish([event$p]);
47
+ let first = EventTopicFixtures$ReventlessCore.capturedCalls.contents[0];
48
+ globalThis.expect(first[0]).toBe("item-1");
49
+ });
50
+ globalThis.test("publishes empty array without error", async () => {
51
+ await Ops.publish([]);
52
+ globalThis.expect(EventTopicFixtures$ReventlessCore.capturedCalls.contents.length).toBe(0);
53
+ });
54
+ globalThis.test("encodes event with correct JSON structure", async () => {
55
+ let event$p = EventTopicFixtures$ReventlessCore.makeEvent$p("item-1", {
56
+ TAG: "ItemPublished",
57
+ name: "Widget"
58
+ });
59
+ await Ops.publish([event$p]);
60
+ let match = EventTopicFixtures$ReventlessCore.capturedCalls.contents[0];
61
+ let json = match[2];
62
+ let hasExpectedFields = Stdlib_Option.getOr(Stdlib_Option.map(Stdlib_JSON.Decode.object(json), d => "event" in d), false) || Stdlib_Option.getOr(Stdlib_Option.map(Stdlib_JSON.Decode.object(json), d => "id" in d), false);
63
+ globalThis.expect(hasExpectedFields).toBe(true);
64
+ });
65
+ });
66
+ });
67
+
68
+ export {
69
+ Ops,
70
+ }
71
+ /* Ops Not a pure module */