@reventlessdev/reventless-core 3.0.0-alpha.260 → 3.0.0-alpha.262
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 +24 -0
- package/package.json +10 -10
- package/src/Behavior.res +1 -4
- package/src/Message.res +17 -14
- package/src/Projection.res +51 -25
- package/src/RequestContext.res +8 -9
- package/src/ResourceAttribution.res +28 -14
- package/src/adapter/Adapter.res +48 -4
- package/src/adapter/EventLogProvisioning/EventLogProvisioning.res +5 -5
- package/src/adapter/Messaging/Messaging_Log_Backend.res +10 -7
- package/src/adapter/Messaging/Messaging_Log_Backend.res.mjs +2 -4
- package/src/adapter/Monitoring/Monitoring.res +16 -17
- package/src/adapter/QueryInterception/QueryInterception.res +0 -1
- package/src/adapter/Runtime/AggregateRuntime_Builder_Common.res +12 -5
- package/src/adapter/Runtime/EventCollectorRuntime_Builder_Single.res +11 -7
- package/src/adapter/Runtime/PluginRuntime_Builder_Micro.res +1 -7
- package/src/adapter/Runtime/PluginRuntime_Builder_Single.res +1 -7
- package/src/adapter/RuntimeExtension/RuntimeExtension.res +0 -1
- package/src/adapter/Secrets/Secrets_Node_Backend.res +60 -0
- package/src/adapter/Secrets/Secrets_Node_Backend.res.mjs +69 -0
- package/src/admin/Platform_Admin.res +17 -6
- package/src/admin/Platform_AdminApi.res +14 -9
- package/src/admin/Platform_Admin_Callback.res +1 -1
- package/src/admin/Platform_BakedManifest.res +34 -34
- package/src/admin/Platform_ComponentDefinitionsApi.res +9 -21
- package/src/admin/Platform_PluginStructuresApi.res +15 -12
- package/src/admin/UiFragmentRegistry/StateChange/UiFragmentRegistry.res +1 -1
- package/src/components/Aggregate/Aggregate.res +13 -12
- package/src/components/Aggregate/Aggregate_Builder.res +22 -21
- package/src/components/Aggregate/Aggregate_Callback.res +91 -86
- package/src/components/Api/ApiNoApiHelpers.res +1 -3
- package/src/components/Api/Api_Ids.res +0 -1
- package/src/components/Api/Api_Naming.res +41 -18
- package/src/components/Api/GraphQL_FragmentGenerator.res +38 -51
- package/src/components/Api/GraphQL_SchemaInspector.res +5 -3
- package/src/components/Api/GraphQL_Stitcher.res +9 -10
- package/src/components/Api/MCP_SchemaGenerator.res +8 -12
- package/src/components/Api/OwnerScopeDiagnostics.res +1 -2
- package/src/components/Api/QueryDbListQuery.res +13 -6
- package/src/components/Api/SchemaType.res +28 -23
- package/src/components/Api/SuryToJsonSchema.res +9 -10
- package/src/components/AutomationSlice/AutomationSlice.res +4 -4
- package/src/components/AutomationSlice/AutomationSlice_Builder.res +15 -14
- package/src/components/AutomationSlice/AutomationSlice_Callback.res +3 -3
- package/src/components/Builder_Helpers.res +12 -23
- package/src/components/CommandGenerator/CommandGenerator.res +6 -1
- package/src/components/CommandGenerator/CommandGenerator_Builder.res +29 -21
- package/src/components/CommandGenerator/CommandGenerator_Callback.res +17 -21
- package/src/components/CommandTopic/CommandTopic.res +3 -3
- package/src/components/CommandTopic/CommandTopic_Builder.res +10 -10
- package/src/components/CommandTopic/CommandTopic_Callback.res +1 -4
- package/src/components/CommandTopic/CommandTopic_Helpers.res +1 -2
- package/src/components/Counter/Counter_Builder.res +1 -6
- package/src/components/Counter/Counter_Callback.res +3 -3
- package/src/components/Dcb/Dcb_Builder.res +970 -956
- package/src/components/DcbEventLog/DcbEventLog.res +4 -4
- package/src/components/DcbEventLog/DcbEventLog_Builder.res +0 -1
- package/src/components/DcbEventLog/DcbEventLog_Operations.res +17 -18
- package/src/components/EventCollector/EventCollector_Builder.res +2 -1
- package/src/components/EventLog/EventLog.res +5 -1
- package/src/components/EventLog/EventLog_Operations.res +12 -8
- package/src/components/EventMapper/EventMapper.res +8 -10
- package/src/components/EventMapper/EventMapper_Builder.res +4 -1
- package/src/components/EventMapper/EventMapper_Callback.res +46 -31
- package/src/components/EventTopic/EventTopic.res +3 -3
- package/src/components/EventTopic/EventTopic_Builder.res +1 -1
- package/src/components/Extension/Extension.res +4 -1
- package/src/components/Extension/Extension_Operations.res +11 -3
- package/src/components/ExtensionPoint/ExtensionPoint.res +3 -3
- package/src/components/ExtensionPoint/ExtensionPoint_Builder.res +9 -10
- package/src/components/ExtensionPoint/ExtensionPoint_Callback.res +2 -6
- package/src/components/ExtensionPoint/ExtensionPoint_Operations.res +13 -5
- package/src/components/Heartbeat/Heartbeat_Callback.res +3 -3
- package/src/components/InboundTranslationSlice/InboundTranslationSlice.res +4 -4
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Builder.res +7 -10
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice.res +4 -4
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res +15 -14
- package/src/components/QueryDb/QueryDb_Adapter.res +1 -3
- package/src/components/QueryDb/QueryDb_Operations.res +10 -10
- package/src/components/ReadModel/ReadModel.res +3 -3
- package/src/components/ReadModel/ReadModel_Builder.res +1 -2
- package/src/components/ReadModel/ReadModel_Callback.res +2 -1
- package/src/components/SideEffectHandler/SideEffectHandler_Callback.res +5 -2
- package/src/components/StateChangeSlice/StateChangeSlice.res +3 -3
- package/src/components/StateChangeSlice/StateChangeSlice_Builder.res +23 -4
- package/src/components/StateChangeSlice/StateChangeSlice_Callback.res +22 -6
- package/src/components/StateTopic.res +1 -3
- package/src/components/StateViewSlice/StateViewSlice.res +4 -4
- package/src/components/StateViewSlice/StateViewSlice_Builder.res +79 -68
- package/src/components/StateViewSlice/StateViewSlice_Callback.res +3 -1
- package/src/components/Task/Task.res +3 -3
- package/src/components/Task/Task_Adapter.res +4 -1
- package/src/components/Task/Task_Builder.res +24 -21
- package/src/plugin/api/PluginBaseFragment.res +9 -3
- package/src/plugin/component/Capability_Inference.res +8 -10
- package/src/plugin/component/Plugin.res +6 -6
- package/src/plugin/component/Plugin_Builder.res +54 -50
- package/src/plugin/component/Plugin_Callback.res +10 -6
- package/src/plugin/component/Plugin_Helpers.res +264 -230
- package/src/plugin/component/Plugin_Structure.res +370 -324
- package/src/plugin/component/Plugin_SubscriptionSchema.res +8 -6
- package/src/plugin/component/SchemaWalker.res +11 -12
- package/src/plugin/connect/PluginConnectExtension_Mapping.res +45 -50
- package/src/plugin/lifecycle/PluginBehavior.res +3 -4
- package/src/plugin/lifecycle/PluginSpec.res +1 -2
- package/src/plugin/lifecycle/PluginsProjection.res +16 -5
- package/src/plugin/lifecycle/PluginsReadModelSpec.res +0 -2
- package/src/util/CommandPublisher.res +9 -2
- package/src/util/CsvStream.res +3 -3
- package/src/util/Interstack.res +7 -15
- package/src/util/Interstack.resi +3 -3
- package/src/util/LogFormat.res +5 -9
- package/src/util/Logger.res +1 -2
- package/src/util/Lru.res +2 -1
- package/src/util/Lru.resi +2 -3
- package/src/util/ScheduleOps.res +24 -27
- package/src/util/StorePrefixCollision.res +6 -9
- package/src/util/Util_Promise.res +4 -1
- package/src/util/Util_Promise.res.mjs +1 -1
- package/tests/IdentityTest.res +166 -113
- package/tests/ResourceAttributionTest.res +28 -25
- package/tests/Secrets_Node_BackendTest.res +141 -0
- package/tests/Secrets_Node_BackendTest.res.mjs +152 -0
- package/tests/StorePrefixCollisionTest.res +2 -1
- package/tests/TaskBucketNamingTest.res +3 -2
- package/tests/adapter/EventLogProvisioningTest.res +51 -48
- package/tests/adapter/MonitoringTest.res +81 -38
- package/tests/adapter/QueryInterceptionTest.res +2 -2
- package/tests/adapter/RefusalVocabularyTest.res +31 -23
- package/tests/adapter/RuntimeExtensionHookReachTest.res +9 -8
- package/tests/adapter/RuntimeExtensionTest.res +5 -3
- package/tests/admin/AdminApiSchemaDriftTest.res +22 -16
- package/tests/admin/Platform_Admin_StructureTest.res +22 -14
- package/tests/admin/Platform_Admin_StructureTest.res.mjs +4 -3
- package/tests/admin/Platform_BakedManifestTest.res +31 -35
- package/tests/admin/Platform_ComponentDefinitionsApiTest.res +18 -15
- package/tests/admin/Platform_PluginStructuresApiTest.res +5 -3
- package/tests/admin/Platform_UIFragmentsApiTest.res +6 -3
- package/tests/aggregate/AggregateCacheTest.res +10 -12
- package/tests/aggregate/AggregateCallbackTest.res +75 -46
- package/tests/aggregate/AggregateCausationTest.res +19 -20
- package/tests/aggregate/AggregateConflictTest.res +41 -19
- package/tests/aggregate/AggregateFixtures.res +15 -5
- package/tests/aggregate/AggregateRejectionTest.res +97 -80
- package/tests/aggregate/AggregateSnapshotTest.res +44 -16
- package/tests/api/Api_IdsTest.res +10 -4
- package/tests/api/BrandedMarkerCompositionTest.res +48 -36
- package/tests/api/GeolocationSemanticTest.res +3 -3
- package/tests/api/GraphQL_FragmentGeneratorTest.res +66 -54
- package/tests/api/OwnerScopeDiagnosticsTest.res +31 -27
- package/tests/api/StorageRefFieldsTest.res +30 -18
- package/tests/api/SuryToJsonSchemaTest.res +1315 -1014
- package/tests/api/TaggedUnionSchemaTest.res +17 -24
- package/tests/commandgenerator/CommandGeneratorCallbackTest.res +235 -179
- package/tests/commandgenerator/CommandGeneratorFixtures.res +8 -13
- package/tests/commandgenerator/OwnerStampingTest.res +91 -76
- package/tests/commandtopic/CommandOutcomeHookTest.res +198 -155
- package/tests/commandtopic/CommandTopicCallbackFixtures.res +5 -4
- package/tests/commandtopic/CommandTopicCallbackTest.res +61 -43
- package/tests/commandtopic/CommandTopicHelpersRejectionTest.res +70 -55
- package/tests/counter/CounterCallbackTest.res +40 -34
- package/tests/counter/CounterFixtures.res +4 -4
- package/tests/dcb/DcbDecodeTest.res +115 -84
- package/tests/dcb/DcbEventLogOperationsTest.res +194 -143
- package/tests/dcb/DcbEventLogSchemaTest.res +13 -13
- package/tests/dcb/DcbFixtures.res +4 -5
- package/tests/dcb/DcbScopeInferenceTest.res +173 -114
- package/tests/dcb/DcbStateChangeSliceTest.res +391 -262
- package/tests/dcb/DcbTagTest.res +22 -11
- package/tests/dcb/DcbValidationTest.res +288 -218
- package/tests/eventlog/EventLogFixtures.res +4 -4
- package/tests/eventlog/EventLogOperationsTest.res +102 -67
- package/tests/eventlog/EventLogRetryTest.res +104 -65
- package/tests/eventmapper/EventMapperCallbackTest.res +118 -83
- package/tests/eventmapper/EventMapperFixtures.res +15 -23
- package/tests/eventmapper/EventMapperTest.res +54 -38
- package/tests/eventtopic/EventTopicFixtures.res +3 -4
- package/tests/eventtopic/EventTopicOperationsTest.res +41 -29
- package/tests/extensionpoint/ExtensionPointCallbackTest.res +58 -45
- package/tests/extensionpoint/ExtensionPointFixtures.res +16 -20
- package/tests/extensionpoint/ExtensionPointOperationsTest.res +70 -49
- package/tests/extensionpoint/PluginDisconnectScheduleTest.res +2 -1
- package/tests/logger/LogFormatTest.res +104 -82
- package/tests/logger/LoggerLazyTest.res +21 -12
- package/tests/message/MessageTest.res +96 -93
- package/tests/message/MetaEnvelopeTest.res +26 -30
- package/tests/plugin/HeartbeatDisconnectGraceTest.res +31 -25
- package/tests/plugin/ManifestVisibilityTest.res +20 -12
- package/tests/plugin/PluginDefinitionScalars.res +1 -2
- package/tests/plugin/PluginLifecycleCorpusTest.res +15 -12
- package/tests/plugin/PluginSpecExperiment.res +0 -1
- package/tests/plugin/PluginStructureTest.res +1529 -1045
- package/tests/plugin/Plugin_EventQuerySchemaTest.res +21 -10
- package/tests/plugin/SchemaWalkerTest.res +116 -70
- package/tests/plugin/StateChange/PsReserveStock.res +4 -4
- package/tests/plugin/StateView/PsAnnotatedView.res +4 -4
- package/tests/plugin/StateView/PsCustomersView.res +4 -4
- package/tests/plugin/StateView/PsShipmentsView.res +3 -2
- package/tests/projection/LifecycleTrailTest.res +1 -4
- package/tests/projection/ProjectionOptimizeTest.res +13 -9
- package/tests/querydb/QueryDbFixtures.res +0 -1
- package/tests/querydb/QueryDbOperationsTest.res +99 -64
- package/tests/querydb/TaggedUnionStampTest.res +10 -8
- package/tests/sideeffecthandler/SideEffectHandlerCallbackTest.res +50 -35
- package/tests/sideeffecthandler/SideEffectHandlerFixtures.res +4 -10
- package/tests/util/CommandPublisherTest.res +0 -1
- package/tests/util/CsvStreamTest.res +3 -3
- package/tests/util/LruTest.res +84 -56
|
@@ -9,41 +9,54 @@ let _ = beforeEach(() => resetMocks())
|
|
|
9
9
|
|
|
10
10
|
describe("MakeCounterHandler.handleCounterEvents:", () => {
|
|
11
11
|
describe("event with matching source mapping", () => {
|
|
12
|
-
testPromise(
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
testPromise(
|
|
13
|
+
"publishes command JSON for OrderPlaced",
|
|
14
|
+
async () => {
|
|
15
|
+
let eventJson = makeEventJson(
|
|
15
16
|
"src-1",
|
|
16
17
|
CmdSourceSpec.OrderPlaced({orderId: "order-1", amount: 99.99})->Message.encode(
|
|
17
18
|
CmdSourceSpec.eventSchema,
|
|
18
19
|
),
|
|
19
20
|
)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
await TestCounterHandler.handleCounterEvents(
|
|
22
|
+
Stream.fromIterable([eventJson]),
|
|
23
|
+
)->Effect.runPromise
|
|
24
|
+
// publishJsons should have been called with 1 command
|
|
25
|
+
expect(capturedCmds.contents->Array.length)->toBe(1)
|
|
26
|
+
},
|
|
27
|
+
)
|
|
24
28
|
})
|
|
25
29
|
|
|
26
30
|
describe("event with unknown service", () => {
|
|
27
|
-
testPromise(
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
testPromise(
|
|
32
|
+
"skipped — no publish",
|
|
33
|
+
async () => {
|
|
34
|
+
let eventJson = makeEventJson(
|
|
30
35
|
~service="UnknownService",
|
|
31
36
|
"src-1",
|
|
32
37
|
CmdSourceSpec.OrderPlaced({orderId: "order-1", amount: 50.0})->Message.encode(
|
|
33
38
|
CmdSourceSpec.eventSchema,
|
|
34
39
|
),
|
|
35
40
|
)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
await TestCounterHandler.handleCounterEvents(
|
|
42
|
+
Stream.fromIterable([eventJson]),
|
|
43
|
+
)->Effect.runPromise
|
|
44
|
+
expect(capturedCmds.contents->Array.length)->toBe(0)
|
|
45
|
+
},
|
|
46
|
+
)
|
|
39
47
|
})
|
|
40
48
|
|
|
41
49
|
describe("invalid event JSON", () => {
|
|
42
|
-
testPromise(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
testPromise(
|
|
51
|
+
"skipped gracefully — no throw, no publish",
|
|
52
|
+
async () => {
|
|
53
|
+
let invalidJson = JSON.Encode.string("not-an-object")
|
|
54
|
+
await TestCounterHandler.handleCounterEvents(
|
|
55
|
+
Stream.fromIterable([invalidJson]),
|
|
56
|
+
)->Effect.runPromise
|
|
57
|
+
expect(capturedCmds.contents->Array.length)->toBe(0)
|
|
58
|
+
},
|
|
59
|
+
)
|
|
47
60
|
})
|
|
48
61
|
})
|
|
49
62
|
|
|
@@ -53,82 +66,104 @@ describe("MakeCounterHandler.handleCounterEvents:", () => {
|
|
|
53
66
|
|
|
54
67
|
describe("MakeEventCollectorHandler.handleJsonEvents:", () => {
|
|
55
68
|
describe("Count action", () => {
|
|
56
|
-
testPromise(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
69
|
+
testPromise(
|
|
70
|
+
"calls count with the countItem",
|
|
71
|
+
async () => {
|
|
72
|
+
let countItem: ReventlessInfra.Counter.countItem = {
|
|
73
|
+
counterId: "c1",
|
|
74
|
+
reference: "ref-1",
|
|
75
|
+
inc: 1,
|
|
76
|
+
}
|
|
77
|
+
mockCommonHandler := (async _ => (Promise.resolve([]), [Counter.Count(countItem)]))
|
|
78
|
+
await TestECHandler.handleJsonEvents(
|
|
79
|
+
Stream.fromIterable([JSON.Encode.null]),
|
|
80
|
+
)->Effect.runPromise
|
|
81
|
+
expect(capturedCountItems.contents)->toEqual([countItem])
|
|
82
|
+
},
|
|
83
|
+
)
|
|
67
84
|
})
|
|
68
85
|
|
|
69
86
|
describe("AddToCounterTarget action", () => {
|
|
70
|
-
testPromise(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
target:
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
87
|
+
testPromise(
|
|
88
|
+
"calls addToCounterTarget with the counterTargetRef",
|
|
89
|
+
async () => {
|
|
90
|
+
let target: ReventlessInfra.Counter.counterTargetRef = {
|
|
91
|
+
counterId: "c1",
|
|
92
|
+
target: 5,
|
|
93
|
+
targetRef: "ref-1",
|
|
94
|
+
}
|
|
95
|
+
mockCommonHandler :=
|
|
96
|
+
(async _ => (Promise.resolve([]), [Counter.AddToCounterTarget(target)]))
|
|
97
|
+
await TestECHandler.handleJsonEvents(
|
|
98
|
+
Stream.fromIterable([JSON.Encode.null]),
|
|
99
|
+
)->Effect.runPromise
|
|
100
|
+
expect(capturedCounterTargets.contents)->toEqual([target])
|
|
101
|
+
},
|
|
102
|
+
)
|
|
81
103
|
})
|
|
82
104
|
|
|
83
105
|
describe("Publisher action", () => {
|
|
84
|
-
testPromise(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
106
|
+
testPromise(
|
|
107
|
+
"calls publishJsons with the command",
|
|
108
|
+
async () => {
|
|
109
|
+
let cmd: Message.commandJson = {
|
|
110
|
+
id: "agg-1",
|
|
111
|
+
meta: evtMapTestMeta,
|
|
112
|
+
commandJson: JSON.Encode.string("DoSomething"),
|
|
113
|
+
}
|
|
114
|
+
mockCommonHandler := (async _ => (Promise.resolve([cmd]), []))
|
|
115
|
+
await TestECHandler.handleJsonEvents(
|
|
116
|
+
Stream.fromIterable([JSON.Encode.null]),
|
|
117
|
+
)->Effect.runPromise
|
|
118
|
+
expect(capturedCmds.contents->Array.length)->toBe(1)
|
|
119
|
+
},
|
|
120
|
+
)
|
|
94
121
|
})
|
|
95
122
|
|
|
96
123
|
describe("mixed actions", () => {
|
|
97
|
-
testPromise(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
124
|
+
testPromise(
|
|
125
|
+
"both publish and count called",
|
|
126
|
+
async () => {
|
|
127
|
+
let countItem: ReventlessInfra.Counter.countItem = {
|
|
128
|
+
counterId: "c1",
|
|
129
|
+
reference: "ref-1",
|
|
130
|
+
inc: 2,
|
|
131
|
+
}
|
|
132
|
+
let cmd: Message.commandJson = {
|
|
133
|
+
id: "agg-1",
|
|
134
|
+
meta: evtMapTestMeta,
|
|
135
|
+
commandJson: JSON.Encode.string("Cmd"),
|
|
136
|
+
}
|
|
137
|
+
mockCommonHandler := (async _ => (Promise.resolve([cmd]), [Counter.Count(countItem)]))
|
|
138
|
+
await TestECHandler.handleJsonEvents(
|
|
139
|
+
Stream.fromIterable([JSON.Encode.null]),
|
|
140
|
+
)->Effect.runPromise
|
|
141
|
+
expect((
|
|
142
|
+
capturedCmds.contents->Array.length,
|
|
143
|
+
capturedCountItems.contents->Array.length,
|
|
144
|
+
))->toEqual((1, 1))
|
|
145
|
+
},
|
|
146
|
+
)
|
|
116
147
|
})
|
|
117
148
|
|
|
118
149
|
describe("doCount retry", () => {
|
|
119
|
-
testPromise(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
150
|
+
testPromise(
|
|
151
|
+
"retries when count throws, eventually succeeds",
|
|
152
|
+
async () => {
|
|
153
|
+
let countItem: ReventlessInfra.Counter.countItem = {
|
|
154
|
+
counterId: "c1",
|
|
155
|
+
reference: "ref-1",
|
|
156
|
+
inc: 1,
|
|
157
|
+
}
|
|
158
|
+
// Fail on first call, succeed on second
|
|
159
|
+
mockCountFailUntil := 1
|
|
160
|
+
mockCommonHandler := (async _ => (Promise.resolve([]), [Counter.Count(countItem)]))
|
|
161
|
+
await TestECHandler.handleJsonEvents(
|
|
162
|
+
Stream.fromIterable([JSON.Encode.null]),
|
|
163
|
+
)->Effect.runPromise
|
|
164
|
+
// count was called at least twice (1 failure + 1 success)
|
|
165
|
+
expect(mockCountCallCount.contents >= 2)->toBe(true)
|
|
166
|
+
},
|
|
167
|
+
)
|
|
133
168
|
})
|
|
134
169
|
})
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
open Reventless.Projection
|
|
2
2
|
|
|
3
|
-
|
|
4
3
|
// ─────────────────────────────────────────────────────────────
|
|
5
4
|
// Source event spec (aggregate events)
|
|
6
5
|
// ─────────────────────────────────────────────────────────────
|
|
@@ -63,11 +62,11 @@ let testMeta: Reventless.Message.meta = {
|
|
|
63
62
|
correlationId: "corr-001",
|
|
64
63
|
}
|
|
65
64
|
|
|
66
|
-
let makeSourceEvent' = (id, event) =>
|
|
65
|
+
let makeSourceEvent' = (id, event): Reventless.Message.event'<string, SourceSpec.event> => {
|
|
67
66
|
Reventless.Message.id,
|
|
68
67
|
meta: testMeta,
|
|
69
68
|
event,
|
|
70
|
-
}
|
|
69
|
+
}
|
|
71
70
|
|
|
72
71
|
// ─────────────────────────────────────────────────────────────
|
|
73
72
|
// EventMapper_Callback test fixtures
|
|
@@ -103,14 +102,13 @@ module OrderMapping = {
|
|
|
103
102
|
module Source = CmdSourceSpec
|
|
104
103
|
module Target = CmdTargetSpec
|
|
105
104
|
|
|
106
|
-
let map = (
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
_queryEngine,
|
|
110
|
-
): array<Reventless.EventMapping.action<CmdTargetSpec.Id.t, CmdTargetSpec.command>> =>
|
|
105
|
+
let map = (id: CmdSourceSpec.Id.t, event: CmdSourceSpec.event, _queryEngine): array<
|
|
106
|
+
Reventless.EventMapping.action<CmdTargetSpec.Id.t, CmdTargetSpec.command>,
|
|
107
|
+
> =>
|
|
111
108
|
switch event {
|
|
112
|
-
| OrderPlaced({orderId, amount}) =>
|
|
113
|
-
|
|
109
|
+
| OrderPlaced({orderId, amount}) => [
|
|
110
|
+
Reventless.EventMapping.Publish(id, CmdTargetSpec.ProcessOrder({orderId, amount})),
|
|
111
|
+
]
|
|
114
112
|
| OrderShipped({orderId}) =>
|
|
115
113
|
let cmd = CmdTargetSpec.ShipOrder({orderId: orderId})
|
|
116
114
|
[Reventless.EventMapping.Publish(id, cmd)]
|
|
@@ -122,15 +120,12 @@ module CountOrderMapping = {
|
|
|
122
120
|
module Source = CmdSourceSpec
|
|
123
121
|
module Target = CmdTargetSpec
|
|
124
122
|
|
|
125
|
-
let map = (
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
_queryEngine,
|
|
129
|
-
): array<Reventless.EventMapping.action<CmdTargetSpec.Id.t, CmdTargetSpec.command>> =>
|
|
123
|
+
let map = (_id: CmdSourceSpec.Id.t, event: CmdSourceSpec.event, _queryEngine): array<
|
|
124
|
+
Reventless.EventMapping.action<CmdTargetSpec.Id.t, CmdTargetSpec.command>,
|
|
125
|
+
> =>
|
|
130
126
|
switch event {
|
|
131
127
|
| OrderPlaced(_) => [Reventless.EventMapping.Count("order-counter")]
|
|
132
|
-
| OrderShipped(_) =>
|
|
133
|
-
[
|
|
128
|
+
| OrderShipped(_) => [
|
|
134
129
|
Reventless.EventMapping.AddToCounterTarget({
|
|
135
130
|
counterId: "order-counter",
|
|
136
131
|
target: 5,
|
|
@@ -191,10 +186,7 @@ module TestCounterHandler = EventMapper_Callback.MakeCounterHandler(
|
|
|
191
186
|
|
|
192
187
|
// configurable mock for commonEventsHandler — reassigned in each test
|
|
193
188
|
let mockCommonHandler: ref<
|
|
194
|
-
array<JSON.t> => promise<(
|
|
195
|
-
promise<array<Reventless.Message.commandJson>>,
|
|
196
|
-
array<Counter.action>,
|
|
197
|
-
)>,
|
|
189
|
+
array<JSON.t> => promise<(promise<array<Reventless.Message.commandJson>>, array<Counter.action>)>,
|
|
198
190
|
> = ref(async _ => (Promise.resolve([]), []))
|
|
199
191
|
|
|
200
192
|
let mockCountFailUntil = ref(0)
|
|
@@ -237,7 +229,7 @@ let makeEventJson = (~service=CmdSourceSpec.name, id, eventJson): JSON.t =>
|
|
|
237
229
|
("id", JSON.Encode.string(id)),
|
|
238
230
|
(
|
|
239
231
|
"meta",
|
|
240
|
-
{...evtMapTestMeta, service
|
|
232
|
+
{...evtMapTestMeta, service}->Reventless.Message.encode(Reventless.Message.metaSchema),
|
|
241
233
|
),
|
|
242
234
|
("event", eventJson),
|
|
243
235
|
]
|
|
@@ -250,5 +242,5 @@ let resetMocks = () => {
|
|
|
250
242
|
capturedCounterTargets := []
|
|
251
243
|
mockCountFailUntil := 0
|
|
252
244
|
mockCountCallCount := 0
|
|
253
|
-
mockCommonHandler := async _ => (Promise.resolve([]), [])
|
|
245
|
+
mockCommonHandler := (async _ => (Promise.resolve([]), []))
|
|
254
246
|
}
|
|
@@ -4,50 +4,66 @@ open EventMapperFixtures
|
|
|
4
4
|
|
|
5
5
|
describe("Mapping.Make:", () => {
|
|
6
6
|
describe("sourceName", () => {
|
|
7
|
-
testSync(
|
|
8
|
-
|
|
7
|
+
testSync(
|
|
8
|
+
"equals source spec name",
|
|
9
|
+
() => expect(ItemMapping.sourceName)->toBe("SourceAggregate"),
|
|
9
10
|
)
|
|
10
11
|
})
|
|
11
12
|
|
|
12
13
|
describe("project", () => {
|
|
13
|
-
testSync(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
testSync(
|
|
15
|
+
"ItemCreated maps to Create action",
|
|
16
|
+
() => {
|
|
17
|
+
let event' = makeSourceEvent'(
|
|
18
|
+
"item-1",
|
|
19
|
+
SourceSpec.ItemCreated({name: "Widget", price: 9.99}),
|
|
20
|
+
)
|
|
21
|
+
let action = ItemMapping.project(event')
|
|
22
|
+
switch action {
|
|
23
|
+
| Create(id, state) =>
|
|
24
|
+
expect((id, state.name, state.price))->toEqual(("item-1", "Widget", 9.99))
|
|
25
|
+
| _ => fail("Expected Create action")
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
)
|
|
22
29
|
|
|
23
|
-
testSync(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
testSync(
|
|
31
|
+
"ItemPriceUpdated maps to Update action",
|
|
32
|
+
() => {
|
|
33
|
+
let event' = makeSourceEvent'("item-1", SourceSpec.ItemPriceUpdated({newPrice: 14.99}))
|
|
34
|
+
let action = ItemMapping.project(event')
|
|
35
|
+
switch action {
|
|
36
|
+
| Update(id, _) => expect(id)->toBe("item-1")
|
|
37
|
+
| _ => fail("Expected Update action")
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
)
|
|
31
41
|
|
|
32
|
-
testSync(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
testSync(
|
|
43
|
+
"ItemRemoved maps to Delete action",
|
|
44
|
+
() => {
|
|
45
|
+
let event' = makeSourceEvent'("item-1", SourceSpec.ItemRemoved)
|
|
46
|
+
let action = ItemMapping.project(event')
|
|
47
|
+
switch action {
|
|
48
|
+
| Delete(id) => expect(id)->toBe("item-1")
|
|
49
|
+
| _ => fail("Expected Delete action")
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
)
|
|
40
53
|
|
|
41
|
-
testSync(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
testSync(
|
|
55
|
+
"Update action applies function correctly",
|
|
56
|
+
() => {
|
|
57
|
+
let event' = makeSourceEvent'("item-1", SourceSpec.ItemPriceUpdated({newPrice: 14.99}))
|
|
58
|
+
let action = ItemMapping.project(event')
|
|
59
|
+
switch action {
|
|
60
|
+
| Update(_, fn) =>
|
|
61
|
+
let originalState: TargetSpec.state = {name: "Widget", price: 9.99}
|
|
62
|
+
let updated = fn(originalState)
|
|
63
|
+
expect(updated.price)->toBe(14.99)
|
|
64
|
+
| _ => fail("Expected Update action")
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
)
|
|
52
68
|
})
|
|
53
69
|
})
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
2
1
|
// Test event spec for EventTopic
|
|
3
2
|
module ItemEventTopicSpec = {
|
|
4
3
|
module Id = Reventless.Id.StringPure
|
|
5
4
|
let name = "TestItemEventTopic"
|
|
6
5
|
|
|
7
6
|
@schema
|
|
8
|
-
type event =
|
|
7
|
+
type event = ItemPublished({name: string}) | ItemRemoved({id: string})
|
|
9
8
|
}
|
|
10
9
|
|
|
11
10
|
// Captured publish calls
|
|
@@ -24,11 +23,11 @@ let testMeta: Message.meta = {
|
|
|
24
23
|
correlationId: "corr-001",
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
let makeEvent' = (id, event) =>
|
|
26
|
+
let makeEvent' = (id, event): Message.event'<string, ItemEventTopicSpec.event> => {
|
|
28
27
|
Reventless.Message.id,
|
|
29
28
|
meta: testMeta,
|
|
30
29
|
event,
|
|
31
|
-
}
|
|
30
|
+
}
|
|
32
31
|
|
|
33
32
|
let reset = () => {
|
|
34
33
|
capturedCalls := []
|
|
@@ -12,37 +12,49 @@ let _ = beforeEach(() => reset())
|
|
|
12
12
|
|
|
13
13
|
describe("EventTopic_Operations:", () => {
|
|
14
14
|
describe("publish", () => {
|
|
15
|
-
testPromise(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
testPromise(
|
|
16
|
+
"calls publishJson for each event",
|
|
17
|
+
async () => {
|
|
18
|
+
let events = [
|
|
19
|
+
makeEvent'("item-1", ItemEventTopicSpec.ItemPublished({name: "Widget"})),
|
|
20
|
+
makeEvent'("item-2", ItemEventTopicSpec.ItemRemoved({id: "item-2"})),
|
|
21
|
+
]
|
|
22
|
+
await Ops.publish(events)
|
|
23
|
+
expect(capturedCalls.contents->Array.length)->toBe(2)
|
|
24
|
+
},
|
|
25
|
+
)
|
|
23
26
|
|
|
24
|
-
testPromise(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
testPromise(
|
|
28
|
+
"calls publishJson with correct service (id string)",
|
|
29
|
+
async () => {
|
|
30
|
+
let event' = makeEvent'("item-1", ItemEventTopicSpec.ItemPublished({name: "Widget"}))
|
|
31
|
+
await Ops.publish([event'])
|
|
32
|
+
let first = capturedCalls.contents->Array.getUnsafe(0)
|
|
33
|
+
let (service, _, _) = first
|
|
34
|
+
expect(service)->toBe("item-1")
|
|
35
|
+
},
|
|
36
|
+
)
|
|
31
37
|
|
|
32
|
-
testPromise(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
testPromise(
|
|
39
|
+
"publishes empty array without error",
|
|
40
|
+
async () => {
|
|
41
|
+
await Ops.publish([])
|
|
42
|
+
expect(capturedCalls.contents->Array.length)->toBe(0)
|
|
43
|
+
},
|
|
44
|
+
)
|
|
36
45
|
|
|
37
|
-
testPromise(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
testPromise(
|
|
47
|
+
"encodes event with correct JSON structure",
|
|
48
|
+
async () => {
|
|
49
|
+
let event' = makeEvent'("item-1", ItemEventTopicSpec.ItemPublished({name: "Widget"}))
|
|
50
|
+
await Ops.publish([event'])
|
|
51
|
+
let (_, _, json) = capturedCalls.contents->Array.getUnsafe(0)
|
|
52
|
+
// JSON should contain the event type info
|
|
53
|
+
let hasExpectedFields =
|
|
54
|
+
json->JSON.Decode.object->Option.map(d => d->Dict.has("event"))->Option.getOr(false) ||
|
|
55
|
+
json->JSON.Decode.object->Option.map(d => d->Dict.has("id"))->Option.getOr(false)
|
|
56
|
+
expect(hasExpectedFields)->toBe(true)
|
|
57
|
+
},
|
|
58
|
+
)
|
|
47
59
|
})
|
|
48
60
|
})
|