@reventlessdev/reventless-core 3.0.0-alpha.333 → 3.0.0-alpha.335
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 +6 -6
- package/src/CommandSent.res +10 -0
- package/src/CommandSent.res.mjs +8 -0
- package/src/components/Aggregate/Aggregate_Callback.res +3 -0
- package/src/components/Aggregate/Aggregate_Callback.res.mjs +3 -3
- package/src/components/AutomationSlice/AutomationSlice.res +3 -0
- package/src/components/AutomationSlice/AutomationSlice_Builder.res +24 -8
- package/src/components/AutomationSlice/AutomationSlice_Builder.res.mjs +109 -102
- package/src/components/AutomationSlice/AutomationSlice_Callback.res +75 -8
- package/src/components/AutomationSlice/AutomationSlice_Callback.res.mjs +58 -7
- package/src/components/CommandGenerator/CommandGenerator_Callback.res.mjs +1 -1
- package/src/components/CommandTopic/CommandTopic.res.mjs +9 -0
- package/src/components/CommandTopic/CommandTopic_Helpers.res +118 -33
- package/src/components/CommandTopic/CommandTopic_Helpers.res.mjs +137 -22
- package/src/components/Dcb/Dcb_Builder.res +16 -0
- package/src/components/Dcb/Dcb_Builder.res.mjs +6 -3
- package/src/components/InboundTranslationSlice/InboundTranslationSlice.res +3 -0
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Builder.res +17 -6
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Builder.res.mjs +46 -41
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res +37 -8
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res.mjs +33 -13
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Webhook.res +3 -0
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Webhook.res.mjs +14 -2
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice.res +3 -0
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res +30 -9
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res.mjs +10 -5
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res +40 -2
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res.mjs +57 -11
- package/src/components/StateChangeSlice/StateChangeSlice_Callback.res +20 -2
- package/src/components/StateChangeSlice/StateChangeSlice_Callback.res.mjs +12 -6
- package/tests/commandtopic/CommandOutcomeLineTest.res.mjs +3 -3
- package/tests/commandtopic/CommandTopicHelpersRejectionTest.res +102 -0
- package/tests/commandtopic/CommandTopicHelpersRejectionTest.res.mjs +101 -3
- package/tests/dcb/DcbReadsNothingTest.res +111 -0
- package/tests/dcb/DcbReadsNothingTest.res.mjs +234 -0
- package/tests/plugin/PluginStructureAccessTest.res +6 -1
- package/tests/plugin/PluginStructureAccessTest.res.mjs +1 -1
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// A slice whose `consumedEvent` is `unit` decides from nothing: it records each command without
|
|
2
|
+
// asking the event log to read, and appends without a condition.
|
|
3
|
+
|
|
4
|
+
open JestGlobals
|
|
5
|
+
|
|
6
|
+
let mock = DcbFixtures.makeMockStorage()
|
|
7
|
+
|
|
8
|
+
module LogOps = DcbEventLog_Operations.Make({
|
|
9
|
+
let name = "ReadsNothingLog"
|
|
10
|
+
let serviceName = "ReadsNothingLog"
|
|
11
|
+
let storage = mock.operations
|
|
12
|
+
let publishJson = mock.mockPublishJson
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
// The event log, with every read and every append's condition noted.
|
|
16
|
+
let reads = ref(0)
|
|
17
|
+
let conditions: ref<array<option<Reventless.DcbTag.appendCondition>>> = ref([])
|
|
18
|
+
let eventLog: DcbEventLog.operations = {
|
|
19
|
+
read: LogOps.read,
|
|
20
|
+
readStream: (~query, ~after=?, ~strongConsistency=?) => {
|
|
21
|
+
reads := reads.contents + 1
|
|
22
|
+
LogOps.readStream(~query, ~after?, ~strongConsistency?)
|
|
23
|
+
},
|
|
24
|
+
append: (events, ~condition=?) => {
|
|
25
|
+
conditions := conditions.contents->Array.concat([condition])
|
|
26
|
+
LogOps.append(events, ~condition?)
|
|
27
|
+
},
|
|
28
|
+
appendStream: LogOps.appendStream,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module NoteSpec = {
|
|
32
|
+
let name = "NoteFault"
|
|
33
|
+
module Id = Reventless.Id.String
|
|
34
|
+
let moduleUrl: string = %raw(`import.meta.url`)
|
|
35
|
+
|
|
36
|
+
@schema
|
|
37
|
+
type event = FaultNoted({chargerId: @s.matches(Reventless.DcbTag.string) string})
|
|
38
|
+
|
|
39
|
+
@schema
|
|
40
|
+
type consumedEvent = unit
|
|
41
|
+
|
|
42
|
+
@schema
|
|
43
|
+
type command = NoteFault({chargerId: @s.matches(Reventless.DcbTag.string) string})
|
|
44
|
+
|
|
45
|
+
@schema
|
|
46
|
+
type error = unit
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
module NoteDecision = {
|
|
50
|
+
type state = unit
|
|
51
|
+
let initialState = ()
|
|
52
|
+
let moduleUrl = NoteSpec.moduleUrl
|
|
53
|
+
let evolve = (state, _event) => state
|
|
54
|
+
let decide = (_state, command: NoteSpec.command): result<array<NoteSpec.event>, NoteSpec.error> =>
|
|
55
|
+
switch command {
|
|
56
|
+
| NoteFault({chargerId}) => Ok([FaultNoted({chargerId: chargerId})])
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
module NoteHandler = StateChangeSlice_Callback.Make(NoteSpec, NoteDecision)
|
|
61
|
+
|
|
62
|
+
let note = reference =>
|
|
63
|
+
NoteHandler.handleCommands(
|
|
64
|
+
eventLog,
|
|
65
|
+
Stream.fromIterable([
|
|
66
|
+
{
|
|
67
|
+
ReventlessInfra.CommandTopic.command: {
|
|
68
|
+
Message.id: Reventless.Id.String.makeFromString("cmd-" ++ reference),
|
|
69
|
+
meta: DcbFixtures.testMeta,
|
|
70
|
+
command: NoteSpec.NoteFault({chargerId: "charger-1"}),
|
|
71
|
+
},
|
|
72
|
+
reference,
|
|
73
|
+
},
|
|
74
|
+
]),
|
|
75
|
+
)->Effect.runPromise
|
|
76
|
+
|
|
77
|
+
let _ = beforeEach(() => {
|
|
78
|
+
mock.reset()
|
|
79
|
+
NoteHandler.resetCache()
|
|
80
|
+
reads := 0
|
|
81
|
+
conditions := []
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
describe("a slice that consumes nothing", () => {
|
|
85
|
+
testPromise("records each command without a read and without a condition", async () => {
|
|
86
|
+
let first = await note("ref-1")
|
|
87
|
+
let second = await note("ref-2")
|
|
88
|
+
expect((
|
|
89
|
+
first,
|
|
90
|
+
second,
|
|
91
|
+
mock.getEvents()->Array.length,
|
|
92
|
+
reads.contents,
|
|
93
|
+
conditions.contents,
|
|
94
|
+
))->toEqual(([Ok("ref-1")], [Ok("ref-2")], 2, 0, [None, None]))
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
describe("DcbTag.readsNothing", () => {
|
|
99
|
+
testSync("a query of clauses with no event type reads nothing", () =>
|
|
100
|
+
expect((
|
|
101
|
+
Reventless.DcbTag.readsNothing([{eventTypes: [], tags: [{key: "chargerId", value: "c1"}]}]),
|
|
102
|
+
Reventless.DcbTag.readsNothing([
|
|
103
|
+
{eventTypes: []},
|
|
104
|
+
{eventTypes: ["FaultNoted"], tags: [{key: "chargerId", value: "c1"}]},
|
|
105
|
+
]),
|
|
106
|
+
// An empty query keeps its meaning: every event.
|
|
107
|
+
Reventless.DcbTag.readsNothing([]),
|
|
108
|
+
Reventless.DcbTag.readsNothing([{tags: [{key: "chargerId", value: "c1"}]}]),
|
|
109
|
+
))->toEqual((true, false, false, false))
|
|
110
|
+
)
|
|
111
|
+
})
|
|
@@ -0,0 +1,234 @@
|
|
|
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 Stream from "effect/Stream";
|
|
7
|
+
import * as DcbTag$Reventless from "@reventlessdev/reventless-spec/src/components/DcbTag.res.mjs";
|
|
8
|
+
import * as DcbFixtures$ReventlessCore from "./DcbFixtures.res.mjs";
|
|
9
|
+
import * as DcbEventLog_Operations$ReventlessCore from "../../src/components/DcbEventLog/DcbEventLog_Operations.res.mjs";
|
|
10
|
+
import * as StateChangeSlice_Callback$ReventlessCore from "../../src/components/StateChangeSlice/StateChangeSlice_Callback.res.mjs";
|
|
11
|
+
|
|
12
|
+
let mock = DcbFixtures$ReventlessCore.makeMockStorage();
|
|
13
|
+
|
|
14
|
+
let storage = mock.operations;
|
|
15
|
+
|
|
16
|
+
let publishJson = mock.mockPublishJson;
|
|
17
|
+
|
|
18
|
+
let LogOps = DcbEventLog_Operations$ReventlessCore.Make({
|
|
19
|
+
name: "ReadsNothingLog",
|
|
20
|
+
serviceName: "ReadsNothingLog",
|
|
21
|
+
storage: storage,
|
|
22
|
+
publishJson: publishJson
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
let reads = {
|
|
26
|
+
contents: 0
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
let conditions = {
|
|
30
|
+
contents: []
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
let eventLog_read = LogOps.read;
|
|
34
|
+
|
|
35
|
+
function eventLog_append(events, condition) {
|
|
36
|
+
conditions.contents = conditions.contents.concat([condition]);
|
|
37
|
+
return LogOps.append(events, condition);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function eventLog_readStream(query, after, strongConsistency) {
|
|
41
|
+
reads.contents = reads.contents + 1 | 0;
|
|
42
|
+
return LogOps.readStream(query, after, strongConsistency);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let eventLog_appendStream = LogOps.appendStream;
|
|
46
|
+
|
|
47
|
+
let eventLog = {
|
|
48
|
+
read: eventLog_read,
|
|
49
|
+
append: eventLog_append,
|
|
50
|
+
readStream: eventLog_readStream,
|
|
51
|
+
appendStream: eventLog_appendStream
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
let name = "NoteFault";
|
|
55
|
+
|
|
56
|
+
let moduleUrl = import.meta.url;
|
|
57
|
+
|
|
58
|
+
let eventSchema = Sury.$schema(s => ({
|
|
59
|
+
TAG: "FaultNoted",
|
|
60
|
+
chargerId: s.m(DcbTag$Reventless.string)
|
|
61
|
+
}));
|
|
62
|
+
|
|
63
|
+
let consumedEventSchema = Sury.$unit;
|
|
64
|
+
|
|
65
|
+
let commandSchema = Sury.$schema(s => ({
|
|
66
|
+
TAG: "NoteFault",
|
|
67
|
+
chargerId: s.m(DcbTag$Reventless.string)
|
|
68
|
+
}));
|
|
69
|
+
|
|
70
|
+
let errorSchema = Sury.$unit;
|
|
71
|
+
|
|
72
|
+
function authorizationOf(param) {
|
|
73
|
+
return "AllowAuthenticated";
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function commandTransition(param) {
|
|
77
|
+
return "Undeclared";
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
let traits = [];
|
|
81
|
+
|
|
82
|
+
let NoteSpec = {
|
|
83
|
+
name: name,
|
|
84
|
+
Id: undefined,
|
|
85
|
+
moduleUrl: moduleUrl,
|
|
86
|
+
eventSchema: eventSchema,
|
|
87
|
+
consumedEventSchema: consumedEventSchema,
|
|
88
|
+
commandSchema: commandSchema,
|
|
89
|
+
errorSchema: errorSchema,
|
|
90
|
+
authorizationOf: authorizationOf,
|
|
91
|
+
commandTransition: commandTransition,
|
|
92
|
+
traits: traits,
|
|
93
|
+
readConsistency: "EscalateOnRetry"
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
function evolve(state, _event) {
|
|
97
|
+
return state;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function decide(_state, command) {
|
|
101
|
+
return {
|
|
102
|
+
TAG: "Ok",
|
|
103
|
+
_0: [{
|
|
104
|
+
TAG: "FaultNoted",
|
|
105
|
+
chargerId: command.chargerId
|
|
106
|
+
}]
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
let NoteDecision = {
|
|
111
|
+
initialState: undefined,
|
|
112
|
+
moduleUrl: moduleUrl,
|
|
113
|
+
evolve: evolve,
|
|
114
|
+
decide: decide
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
let NoteHandler = StateChangeSlice_Callback$ReventlessCore.Make({
|
|
118
|
+
name: name,
|
|
119
|
+
moduleUrl: moduleUrl,
|
|
120
|
+
consumedEventSchema: consumedEventSchema,
|
|
121
|
+
errorSchema: errorSchema,
|
|
122
|
+
eventSchema: eventSchema,
|
|
123
|
+
commandSchema: commandSchema,
|
|
124
|
+
authorizationOf: authorizationOf,
|
|
125
|
+
commandTransition: commandTransition,
|
|
126
|
+
traits: traits,
|
|
127
|
+
readConsistency: "EscalateOnRetry"
|
|
128
|
+
})({
|
|
129
|
+
initialState: undefined,
|
|
130
|
+
evolve: evolve,
|
|
131
|
+
decide: decide,
|
|
132
|
+
moduleUrl: moduleUrl
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
function note(reference) {
|
|
136
|
+
return Effect.runPromise(NoteHandler.handleCommands(undefined, undefined, undefined, eventLog, Stream.fromIterable([{
|
|
137
|
+
command: {
|
|
138
|
+
id: Id$Reventless.$$String.makeFromString("cmd-" + reference),
|
|
139
|
+
meta: DcbFixtures$ReventlessCore.testMeta,
|
|
140
|
+
command: {
|
|
141
|
+
TAG: "NoteFault",
|
|
142
|
+
chargerId: "charger-1"
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
reference: reference
|
|
146
|
+
}])));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
globalThis.beforeEach(() => {
|
|
150
|
+
mock.reset();
|
|
151
|
+
NoteHandler.resetCache();
|
|
152
|
+
reads.contents = 0;
|
|
153
|
+
conditions.contents = [];
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
globalThis.describe("a slice that consumes nothing", () => {
|
|
157
|
+
globalThis.test("records each command without a read and without a condition", async () => {
|
|
158
|
+
let first = await note("ref-1");
|
|
159
|
+
let second = await note("ref-2");
|
|
160
|
+
globalThis.expect([
|
|
161
|
+
first,
|
|
162
|
+
second,
|
|
163
|
+
mock.getEvents().length,
|
|
164
|
+
reads.contents,
|
|
165
|
+
conditions.contents
|
|
166
|
+
]).toEqual([
|
|
167
|
+
[{
|
|
168
|
+
TAG: "Ok",
|
|
169
|
+
_0: "ref-1"
|
|
170
|
+
}],
|
|
171
|
+
[{
|
|
172
|
+
TAG: "Ok",
|
|
173
|
+
_0: "ref-2"
|
|
174
|
+
}],
|
|
175
|
+
2,
|
|
176
|
+
0,
|
|
177
|
+
[
|
|
178
|
+
undefined,
|
|
179
|
+
undefined
|
|
180
|
+
]
|
|
181
|
+
]);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
globalThis.describe("DcbTag.readsNothing", () => {
|
|
186
|
+
globalThis.test("a query of clauses with no event type reads nothing", () => {
|
|
187
|
+
globalThis.expect([
|
|
188
|
+
DcbTag$Reventless.readsNothing([{
|
|
189
|
+
eventTypes: [],
|
|
190
|
+
tags: [{
|
|
191
|
+
key: "chargerId",
|
|
192
|
+
value: "c1"
|
|
193
|
+
}]
|
|
194
|
+
}]),
|
|
195
|
+
DcbTag$Reventless.readsNothing([
|
|
196
|
+
{
|
|
197
|
+
eventTypes: []
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
eventTypes: ["FaultNoted"],
|
|
201
|
+
tags: [{
|
|
202
|
+
key: "chargerId",
|
|
203
|
+
value: "c1"
|
|
204
|
+
}]
|
|
205
|
+
}
|
|
206
|
+
]),
|
|
207
|
+
DcbTag$Reventless.readsNothing([]),
|
|
208
|
+
DcbTag$Reventless.readsNothing([{
|
|
209
|
+
tags: [{
|
|
210
|
+
key: "chargerId",
|
|
211
|
+
value: "c1"
|
|
212
|
+
}]
|
|
213
|
+
}])
|
|
214
|
+
]).toEqual([
|
|
215
|
+
true,
|
|
216
|
+
false,
|
|
217
|
+
false,
|
|
218
|
+
false
|
|
219
|
+
]);
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
export {
|
|
224
|
+
mock,
|
|
225
|
+
LogOps,
|
|
226
|
+
reads,
|
|
227
|
+
conditions,
|
|
228
|
+
eventLog,
|
|
229
|
+
NoteSpec,
|
|
230
|
+
NoteDecision,
|
|
231
|
+
NoteHandler,
|
|
232
|
+
note,
|
|
233
|
+
}
|
|
234
|
+
/* mock Not a pure module */
|
|
@@ -173,7 +173,12 @@ module PsTwoRuleFeedSlice: ReventlessInfra.InboundTranslationSlice.T = {
|
|
|
173
173
|
ReventlessInfra.InboundTranslationSlice.operations,
|
|
174
174
|
>
|
|
175
175
|
let queryDbName = "PsTwoRuleFeedAudit"
|
|
176
|
-
let make = (
|
|
176
|
+
let make = (
|
|
177
|
+
~publishJsons as _,
|
|
178
|
+
~publishJsonsAndWait as _=?,
|
|
179
|
+
~runtime as _=?,
|
|
180
|
+
~opts as _=?,
|
|
181
|
+
): component => Obj.magic(0)
|
|
177
182
|
}
|
|
178
183
|
|
|
179
184
|
describe("an inbound slice's roles", () => {
|