@reventlessdev/reventless-core 3.0.0-alpha.325 → 3.0.0-alpha.327
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 +7 -7
- package/src/Message.res +46 -0
- package/src/Message.res.mjs +45 -0
- package/src/Projection.res +269 -131
- package/src/Projection.res.mjs +338 -224
- package/src/ViewChange.res +194 -0
- package/src/ViewChange.res.mjs +235 -0
- package/src/adapter/Runtime/AggregateRuntime_Builder_Common.res.mjs +5 -5
- package/src/adapter/Runtime/EventCollectorRuntime_Builder_Single.res.mjs +2 -2
- package/src/admin/Platform_Admin_Callback.res.mjs +1 -1
- package/src/components/Aggregate/Aggregate_Callback.res +93 -18
- package/src/components/Aggregate/Aggregate_Callback.res.mjs +54 -32
- package/src/components/AutomationSlice/AutomationSlice_Builder.res.mjs +1 -1
- package/src/components/AutomationSlice/AutomationSlice_Callback.res +29 -9
- package/src/components/AutomationSlice/AutomationSlice_Callback.res.mjs +35 -20
- package/src/components/CommandGenerator/CommandGenerator_Callback.res +47 -6
- package/src/components/CommandGenerator/CommandGenerator_Callback.res.mjs +41 -4
- package/src/components/CommandTopic/CommandTopic.res.mjs +5 -2
- package/src/components/CommandTopic/CommandTopic_Callback.res.mjs +1 -1
- package/src/components/CommandTopic/CommandTopic_Helpers.res +64 -26
- package/src/components/CommandTopic/CommandTopic_Helpers.res.mjs +37 -17
- package/src/components/CommandTopic/CommandTopic_Operations.res +2 -0
- package/src/components/CommandTopic/CommandTopic_Operations.res.mjs +2 -2
- package/src/components/Counter/Counter_Callback.res.mjs +3 -3
- package/src/components/Counter/Counter_Operations.res.mjs +4 -4
- package/src/components/DcbEventLog/DcbEventLog_Operations.res.mjs +3 -3
- package/src/components/EventLog/EventLog_Operations.res +1 -0
- package/src/components/EventLog/EventLog_Operations.res.mjs +3 -3
- package/src/components/EventMapper/EventMapper_Callback.res +4 -0
- package/src/components/EventMapper/EventMapper_Callback.res.mjs +13 -12
- package/src/components/EventTopic/EventTopic_Operations.res +2 -0
- package/src/components/EventTopic/EventTopic_Operations.res.mjs +2 -2
- package/src/components/Extension/Extension_Operations.res +4 -0
- package/src/components/Extension/Extension_Operations.res.mjs +8 -8
- package/src/components/ExtensionPoint/ExtensionPoint_Callback.res.mjs +2 -2
- package/src/components/ExtensionPoint/ExtensionPoint_Operations.res +2 -0
- package/src/components/ExtensionPoint/ExtensionPoint_Operations.res.mjs +9 -8
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Callback.res.mjs +1 -1
- package/src/components/InboundTranslationSlice/InboundTranslationSlice_Webhook.res.mjs +1 -1
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res +6 -2
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res.mjs +7 -3
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res +33 -12
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res.mjs +30 -17
- package/src/components/ReadModel/ReadModel_Callback.res +24 -3
- package/src/components/ReadModel/ReadModel_Callback.res.mjs +15 -3
- package/src/components/SideEffectHandler/SideEffectHandler_Callback.res +2 -0
- package/src/components/SideEffectHandler/SideEffectHandler_Callback.res.mjs +6 -6
- package/src/components/StateChangeSlice/StateChangeSlice_Callback.res +43 -7
- package/src/components/StateChangeSlice/StateChangeSlice_Callback.res.mjs +38 -20
- package/src/components/StateViewSlice/StateViewSlice_Builder.res +16 -2
- package/src/components/StateViewSlice/StateViewSlice_Builder.res.mjs +15 -4
- package/src/components/StateViewSlice/StateViewSlice_Callback.res +35 -4
- package/src/components/StateViewSlice/StateViewSlice_Callback.res.mjs +12 -4
- package/src/plugin/component/Plugin_Callback.res.mjs +2 -2
- package/src/plugin/connect/PluginExtensionPoint_Plugin.res.mjs +6 -6
- package/src/util/CommandPublisher.res.mjs +9 -9
- package/src/util/EffectLogger.res +111 -42
- package/src/util/EffectLogger.res.mjs +72 -30
- package/src/util/FTPHandler.res.mjs +6 -6
- package/src/util/Logger.res +231 -35
- package/src/util/Logger.res.mjs +263 -42
- package/src/util/ScheduleOps.res.mjs +4 -4
- package/src/util/Util_AdapterRuntime.res.mjs +2 -2
- package/src/util/Util_Promise.res.mjs +1 -1
- package/src/util/Util_QueryDbRuntime.res.mjs +1 -1
- package/src/util/Validation.res.mjs +1 -1
- package/tests/commandgenerator/OwnerActingTest.res +3 -1
- package/tests/commandgenerator/OwnerStampingTest.res +65 -0
- package/tests/commandgenerator/OwnerStampingTest.res.mjs +62 -0
- package/tests/commandtopic/CommandOutcomeHookTest.res +99 -2
- package/tests/commandtopic/CommandOutcomeHookTest.res.mjs +120 -0
- package/tests/commandtopic/CommandTopicHelpersRejectionTest.res.mjs +4 -4
- package/tests/logger/ComponentLineIdsTest.res +97 -0
- package/tests/logger/ComponentLineIdsTest.res.mjs +118 -0
- package/tests/logger/LogFormatTest.res.mjs +5 -5
- package/tests/logger/LoggerSinkTest.res +205 -0
- package/tests/logger/LoggerSinkTest.res.mjs +209 -0
- package/tests/projection/ViewChangeTest.res +173 -0
- package/tests/projection/ViewChangeTest.res.mjs +292 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
// What a projection changed in a view: one row created, changed or removed, and
|
|
2
|
+
// the events that led to it.
|
|
3
|
+
//
|
|
4
|
+
// Each change becomes an info log line `view changed` carrying the view, the
|
|
5
|
+
// row's key, the kind of change, the names of the fields that changed, and the
|
|
6
|
+
// events' message ids and entities, never the values: a log group cannot be swept
|
|
7
|
+
// for one person. A listener registered here (a platform that serves a watching
|
|
8
|
+
// tool, say) receives the change with the row before and after, as JSON, and
|
|
9
|
+
// redacts them itself if it sends them anywhere.
|
|
10
|
+
|
|
11
|
+
type kind = Projection.changeKind
|
|
12
|
+
|
|
13
|
+
/** One row change, as the log line and the listeners see it. */
|
|
14
|
+
type t = {
|
|
15
|
+
view: string,
|
|
16
|
+
key: string,
|
|
17
|
+
subId?: string,
|
|
18
|
+
kind: kind,
|
|
19
|
+
/** The top-level fields whose values differ; every field of the row where
|
|
20
|
+
only one side is known. */
|
|
21
|
+
fields: array<string>,
|
|
22
|
+
before?: JSON.t,
|
|
23
|
+
after?: JSON.t,
|
|
24
|
+
sources: array<Projection.changeSource>,
|
|
25
|
+
/** The flow the events share, when they all share one. */
|
|
26
|
+
correlationId?: string,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type listener = t => unit
|
|
30
|
+
|
|
31
|
+
type registered = {id: int, listener: listener}
|
|
32
|
+
|
|
33
|
+
let listeners: ref<array<registered>> = ref([])
|
|
34
|
+
let nextId = ref(0)
|
|
35
|
+
|
|
36
|
+
/** Adds a listener and returns the function that removes it. */
|
|
37
|
+
let register = (listener: listener): (unit => unit) => {
|
|
38
|
+
nextId := nextId.contents + 1
|
|
39
|
+
let id = nextId.contents
|
|
40
|
+
listeners := listeners.contents->Array.concat([{id, listener}])
|
|
41
|
+
() => listeners := listeners.contents->Array.filter(l => l.id != id)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Removes every listener. */
|
|
45
|
+
let clear = () => listeners := []
|
|
46
|
+
|
|
47
|
+
let kindLabel = (kind: kind) =>
|
|
48
|
+
switch kind {
|
|
49
|
+
| Created => "created"
|
|
50
|
+
| Changed => "changed"
|
|
51
|
+
| Removed => "removed"
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The names of the top-level fields that differ between the two sides. */
|
|
55
|
+
let changedFields = (~before: option<JSON.t>, ~after: option<JSON.t>): array<string> => {
|
|
56
|
+
let objectOf = side => side->Option.flatMap(JSON.Decode.object)
|
|
57
|
+
switch (objectOf(before), objectOf(after)) {
|
|
58
|
+
| (Some(b), Some(a)) =>
|
|
59
|
+
let names = a->Dict.keysToArray
|
|
60
|
+
b
|
|
61
|
+
->Dict.keysToArray
|
|
62
|
+
->Array.forEach(name =>
|
|
63
|
+
if !(names->Array.includes(name)) {
|
|
64
|
+
names->Array.push(name)
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
names->Array.filter(name => b->Dict.get(name) != a->Dict.get(name))
|
|
68
|
+
| (None, Some(one)) | (Some(one), None) => one->Dict.keysToArray
|
|
69
|
+
| (None, None) => []
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
let sharedCorrelationId = (sources: array<Projection.changeSource>): option<string> =>
|
|
74
|
+
switch sources->Array.map(s => s.correlationId) {
|
|
75
|
+
| [] => None
|
|
76
|
+
| ids =>
|
|
77
|
+
let first = ids->Array.getUnsafe(0)
|
|
78
|
+
ids->Array.every(id => id == first) ? first : None
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
let sourceToJson = (s: Projection.changeSource): JSON.t =>
|
|
82
|
+
[("msgId", JSON.Encode.string(s.msgId))]
|
|
83
|
+
->Array.concat(s.correlationId->Option.mapOr([], c => [("correlationId", JSON.Encode.string(c))]))
|
|
84
|
+
->Array.concat(s.entityId->Option.mapOr([], e => [("entityId", JSON.Encode.string(e))]))
|
|
85
|
+
->Array.concat(s.entityType->Option.mapOr([], e => [("entityType", JSON.Encode.string(e))]))
|
|
86
|
+
->Dict.fromArray
|
|
87
|
+
->JSON.Encode.object
|
|
88
|
+
|
|
89
|
+
/** The fields both the log line's detail and a feed line carry: everything but
|
|
90
|
+
the values. */
|
|
91
|
+
let summaryFields = (c: t): array<(string, JSON.t)> =>
|
|
92
|
+
[("view", JSON.Encode.string(c.view)), ("key", JSON.Encode.string(c.key))]
|
|
93
|
+
->Array.concat(c.subId->Option.mapOr([], s => [("subId", JSON.Encode.string(s))]))
|
|
94
|
+
->Array.concat([
|
|
95
|
+
("change", JSON.Encode.string(kindLabel(c.kind))),
|
|
96
|
+
("fields", c.fields->Array.map(JSON.Encode.string)->JSON.Encode.array),
|
|
97
|
+
("sources", c.sources->Array.map(sourceToJson)->JSON.Encode.array),
|
|
98
|
+
])
|
|
99
|
+
|
|
100
|
+
let logLine = (~comp: string, c: t) =>
|
|
101
|
+
Logger.emit(
|
|
102
|
+
~level=Info,
|
|
103
|
+
~comp,
|
|
104
|
+
~annotations=c.correlationId->Option.mapOr(Dict.make(), id =>
|
|
105
|
+
Dict.fromArray([("correlationId", id)])
|
|
106
|
+
),
|
|
107
|
+
~detail=c->summaryFields->Dict.fromArray->JSON.Encode.object,
|
|
108
|
+
"view changed",
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
The `~onChange` a projection's caller passes to `Projection.handleAction`:
|
|
113
|
+
logs each change and hands it to the listeners. `stateToJson` encodes a row the
|
|
114
|
+
way the view stores it; a row it cannot encode counts as unknown. Nothing is
|
|
115
|
+
encoded when the line is below its level and nobody listens.
|
|
116
|
+
*/
|
|
117
|
+
let reporter = (~comp: string, ~view: string, ~stateToJson: 'state => JSON.t): (
|
|
118
|
+
Projection.rowChange<'state> => unit
|
|
119
|
+
) =>
|
|
120
|
+
change => {
|
|
121
|
+
let logs = Logger.shouldLog(Info, ~comp, ())
|
|
122
|
+
let listening = listeners.contents != []
|
|
123
|
+
if logs || listening {
|
|
124
|
+
let toJson = state =>
|
|
125
|
+
switch stateToJson(state) {
|
|
126
|
+
| json => Some(json)
|
|
127
|
+
| exception _ => None
|
|
128
|
+
}
|
|
129
|
+
let before = change.before->Option.flatMap(toJson)
|
|
130
|
+
let after = change.after->Option.flatMap(toJson)
|
|
131
|
+
let fields = changedFields(~before, ~after)
|
|
132
|
+
// An update that wrote the row as it was changed nothing a reader can see.
|
|
133
|
+
let unchanged = switch (change.kind, before, after) {
|
|
134
|
+
| (Changed, Some(_), Some(_)) => fields == []
|
|
135
|
+
| _ => false
|
|
136
|
+
}
|
|
137
|
+
if !unchanged {
|
|
138
|
+
let c = {
|
|
139
|
+
view,
|
|
140
|
+
key: change.key,
|
|
141
|
+
subId: ?change.subId,
|
|
142
|
+
kind: change.kind,
|
|
143
|
+
fields,
|
|
144
|
+
?before,
|
|
145
|
+
?after,
|
|
146
|
+
sources: change.sources,
|
|
147
|
+
correlationId: ?sharedCorrelationId(change.sources),
|
|
148
|
+
}
|
|
149
|
+
if logs {
|
|
150
|
+
logLine(~comp, c)
|
|
151
|
+
}
|
|
152
|
+
listeners.contents->Array.forEach(({listener}) =>
|
|
153
|
+
try listener(c) catch {
|
|
154
|
+
| exn =>
|
|
155
|
+
Console.error(
|
|
156
|
+
`a view-change listener failed and is skipped for that change: ${exn
|
|
157
|
+
->JsExn.fromException
|
|
158
|
+
->Option.flatMap(JsExn.message)
|
|
159
|
+
->Option.getOr("unknown")}`,
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
)
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** The source of a change from an event's meta and the entity it is about. */
|
|
168
|
+
let sourceOf = (
|
|
169
|
+
~meta: Reventless.Message.meta,
|
|
170
|
+
~entityId: option<string>=?,
|
|
171
|
+
~entityType: option<string>=?,
|
|
172
|
+
(),
|
|
173
|
+
): Projection.changeSource => {
|
|
174
|
+
msgId: meta.msgId,
|
|
175
|
+
correlationId: meta.correlationId,
|
|
176
|
+
?entityId,
|
|
177
|
+
?entityType,
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** The entity a stored event's envelope is about: its first tag (value and key)
|
|
181
|
+
when it has tags, a DCB event; otherwise its `id`, an aggregate's. */
|
|
182
|
+
let entityOfEnvelope = (envelope: dict<JSON.t>): (option<string>, option<string>) => {
|
|
183
|
+
let firstTag =
|
|
184
|
+
envelope
|
|
185
|
+
->Dict.get("tags")
|
|
186
|
+
->Option.flatMap(JSON.Decode.array)
|
|
187
|
+
->Option.flatMap(tags => tags->Array.get(0))
|
|
188
|
+
->Option.flatMap(JSON.Decode.object)
|
|
189
|
+
let string = (d, k) => d->Dict.get(k)->Option.flatMap(JSON.Decode.string)
|
|
190
|
+
switch firstTag {
|
|
191
|
+
| Some(tag) => (string(tag, "value"), string(tag, "key"))
|
|
192
|
+
| None => (string(envelope, "id"), None)
|
|
193
|
+
}
|
|
194
|
+
}
|
|
@@ -0,0 +1,235 @@
|
|
|
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 Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
|
|
5
|
+
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
6
|
+
import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.js";
|
|
7
|
+
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
8
|
+
import * as Logger$ReventlessCore from "./util/Logger.res.mjs";
|
|
9
|
+
|
|
10
|
+
let listeners = {
|
|
11
|
+
contents: []
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
let nextId = {
|
|
15
|
+
contents: 0
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
function register(listener) {
|
|
19
|
+
nextId.contents = nextId.contents + 1 | 0;
|
|
20
|
+
let id = nextId.contents;
|
|
21
|
+
listeners.contents = listeners.contents.concat([{
|
|
22
|
+
id: id,
|
|
23
|
+
listener: listener
|
|
24
|
+
}]);
|
|
25
|
+
return () => {
|
|
26
|
+
listeners.contents = listeners.contents.filter(l => l.id !== id);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function clear() {
|
|
31
|
+
listeners.contents = [];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function kindLabel(kind) {
|
|
35
|
+
switch (kind) {
|
|
36
|
+
case "Created" :
|
|
37
|
+
return "created";
|
|
38
|
+
case "Changed" :
|
|
39
|
+
return "changed";
|
|
40
|
+
case "Removed" :
|
|
41
|
+
return "removed";
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function changedFields(before, after) {
|
|
46
|
+
let match = Stdlib_Option.flatMap(before, Stdlib_JSON.Decode.object);
|
|
47
|
+
let match$1 = Stdlib_Option.flatMap(after, Stdlib_JSON.Decode.object);
|
|
48
|
+
if (match === undefined) {
|
|
49
|
+
if (match$1 !== undefined) {
|
|
50
|
+
return Object.keys(match$1);
|
|
51
|
+
} else {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (match$1 === undefined) {
|
|
56
|
+
return Object.keys(match);
|
|
57
|
+
}
|
|
58
|
+
let names = Object.keys(match$1);
|
|
59
|
+
Object.keys(match).forEach(name => {
|
|
60
|
+
if (!names.includes(name)) {
|
|
61
|
+
names.push(name);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return names.filter(name => Primitive_object.notequal(match[name], match$1[name]));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function sharedCorrelationId(sources) {
|
|
69
|
+
let ids = sources.map(s => s.correlationId);
|
|
70
|
+
if (ids.length === 0) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
let first = ids[0];
|
|
74
|
+
if (ids.every(id => Primitive_object.equal(id, first))) {
|
|
75
|
+
return first;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function sourceToJson(s) {
|
|
80
|
+
return Object.fromEntries([[
|
|
81
|
+
"msgId",
|
|
82
|
+
s.msgId
|
|
83
|
+
]].concat(Stdlib_Option.mapOr(s.correlationId, [], c => [[
|
|
84
|
+
"correlationId",
|
|
85
|
+
c
|
|
86
|
+
]])).concat(Stdlib_Option.mapOr(s.entityId, [], e => [[
|
|
87
|
+
"entityId",
|
|
88
|
+
e
|
|
89
|
+
]])).concat(Stdlib_Option.mapOr(s.entityType, [], e => [[
|
|
90
|
+
"entityType",
|
|
91
|
+
e
|
|
92
|
+
]])));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function summaryFields(c) {
|
|
96
|
+
return [
|
|
97
|
+
[
|
|
98
|
+
"view",
|
|
99
|
+
c.view
|
|
100
|
+
],
|
|
101
|
+
[
|
|
102
|
+
"key",
|
|
103
|
+
c.key
|
|
104
|
+
]
|
|
105
|
+
].concat(Stdlib_Option.mapOr(c.subId, [], s => [[
|
|
106
|
+
"subId",
|
|
107
|
+
s
|
|
108
|
+
]])).concat([
|
|
109
|
+
[
|
|
110
|
+
"change",
|
|
111
|
+
kindLabel(c.kind)
|
|
112
|
+
],
|
|
113
|
+
[
|
|
114
|
+
"fields",
|
|
115
|
+
c.fields.map(prim => prim)
|
|
116
|
+
],
|
|
117
|
+
[
|
|
118
|
+
"sources",
|
|
119
|
+
c.sources.map(sourceToJson)
|
|
120
|
+
]
|
|
121
|
+
]);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function logLine(comp, c) {
|
|
125
|
+
Logger$ReventlessCore.emit("Info", comp, undefined, Object.fromEntries(summaryFields(c)), Stdlib_Option.mapOr(c.correlationId, {}, id => Object.fromEntries([[
|
|
126
|
+
"correlationId",
|
|
127
|
+
id
|
|
128
|
+
]])), "view changed");
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function reporter(comp, view, stateToJson) {
|
|
132
|
+
return change => {
|
|
133
|
+
let logs = Logger$ReventlessCore.shouldLog("Info", undefined, comp, undefined);
|
|
134
|
+
let listening = Primitive_object.notequal(listeners.contents, []);
|
|
135
|
+
if (!(logs || listening)) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
let toJson = state => {
|
|
139
|
+
let json;
|
|
140
|
+
try {
|
|
141
|
+
json = stateToJson(state);
|
|
142
|
+
} catch (exn) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
return json;
|
|
146
|
+
};
|
|
147
|
+
let before = Stdlib_Option.flatMap(change.before, toJson);
|
|
148
|
+
let after = Stdlib_Option.flatMap(change.after, toJson);
|
|
149
|
+
let fields = changedFields(before, after);
|
|
150
|
+
let match = change.kind;
|
|
151
|
+
let unchanged;
|
|
152
|
+
switch (match) {
|
|
153
|
+
case "Changed" :
|
|
154
|
+
unchanged = before !== undefined && after !== undefined ? Primitive_object.equal(fields, []) : false;
|
|
155
|
+
break;
|
|
156
|
+
case "Created" :
|
|
157
|
+
case "Removed" :
|
|
158
|
+
unchanged = false;
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
if (unchanged) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
let c_key = change.key;
|
|
165
|
+
let c_subId = change.subId;
|
|
166
|
+
let c_kind = change.kind;
|
|
167
|
+
let c_sources = change.sources;
|
|
168
|
+
let c_correlationId = sharedCorrelationId(change.sources);
|
|
169
|
+
let c = {
|
|
170
|
+
view: view,
|
|
171
|
+
key: c_key,
|
|
172
|
+
subId: c_subId,
|
|
173
|
+
kind: c_kind,
|
|
174
|
+
fields: fields,
|
|
175
|
+
before: before,
|
|
176
|
+
after: after,
|
|
177
|
+
sources: c_sources,
|
|
178
|
+
correlationId: c_correlationId
|
|
179
|
+
};
|
|
180
|
+
if (logs) {
|
|
181
|
+
logLine(comp, c);
|
|
182
|
+
}
|
|
183
|
+
listeners.contents.forEach(param => {
|
|
184
|
+
try {
|
|
185
|
+
return param.listener(c);
|
|
186
|
+
} catch (raw_exn) {
|
|
187
|
+
let exn = Primitive_exceptions.internalToException(raw_exn);
|
|
188
|
+
console.error(`a view-change listener failed and is skipped for that change: ` + Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JsExn.fromException(exn), Stdlib_JsExn.message), "unknown"));
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function sourceOf(meta, entityId, entityType, param) {
|
|
196
|
+
return {
|
|
197
|
+
msgId: meta.msgId,
|
|
198
|
+
correlationId: meta.correlationId,
|
|
199
|
+
entityId: entityId,
|
|
200
|
+
entityType: entityType
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function entityOfEnvelope(envelope) {
|
|
205
|
+
let firstTag = Stdlib_Option.flatMap(Stdlib_Option.flatMap(Stdlib_Option.flatMap(envelope["tags"], Stdlib_JSON.Decode.array), tags => tags[0]), Stdlib_JSON.Decode.object);
|
|
206
|
+
let string = (d, k) => Stdlib_Option.flatMap(d[k], Stdlib_JSON.Decode.string);
|
|
207
|
+
if (firstTag !== undefined) {
|
|
208
|
+
return [
|
|
209
|
+
string(firstTag, "value"),
|
|
210
|
+
string(firstTag, "key")
|
|
211
|
+
];
|
|
212
|
+
} else {
|
|
213
|
+
return [
|
|
214
|
+
string(envelope, "id"),
|
|
215
|
+
undefined
|
|
216
|
+
];
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export {
|
|
221
|
+
listeners,
|
|
222
|
+
nextId,
|
|
223
|
+
register,
|
|
224
|
+
clear,
|
|
225
|
+
kindLabel,
|
|
226
|
+
changedFields,
|
|
227
|
+
sharedCorrelationId,
|
|
228
|
+
sourceToJson,
|
|
229
|
+
summaryFields,
|
|
230
|
+
logLine,
|
|
231
|
+
reporter,
|
|
232
|
+
sourceOf,
|
|
233
|
+
entityOfEnvelope,
|
|
234
|
+
}
|
|
235
|
+
/* Stdlib_JsExn Not a pure module */
|
|
@@ -29,30 +29,30 @@ function Make(RuntimeEnvironment) {
|
|
|
29
29
|
if (info !== undefined) {
|
|
30
30
|
let handler = commandGeneratorHandlers[info];
|
|
31
31
|
if (handler !== undefined) {
|
|
32
|
-
Effect.runSync(EffectLogger$ReventlessCore.logDebug(comp, undefined, `found CommandGenerator handler for ` + info));
|
|
32
|
+
Effect.runSync(EffectLogger$ReventlessCore.logDebug(comp, undefined, undefined, `found CommandGenerator handler for ` + info));
|
|
33
33
|
await runEffect(handler(event, context));
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
36
|
let available = Object.keys(commandGeneratorHandlers).join(",");
|
|
37
|
-
return Effect.runSync(EffectLogger$ReventlessCore.logWarn(comp, undefined, `no handler found: ` + info + ` available=[` + available + `]`));
|
|
37
|
+
return Effect.runSync(EffectLogger$ReventlessCore.logWarn(comp, undefined, undefined, `no handler found: ` + info + ` available=[` + available + `]`));
|
|
38
38
|
}
|
|
39
39
|
await Promise.all(Object.entries(RuntimeEnvironment.groupBySource(event)).map(async param => {
|
|
40
40
|
let event = param[1];
|
|
41
41
|
let urn = param[0];
|
|
42
42
|
let handler = commandTopicHandlers[urn];
|
|
43
43
|
if (handler !== undefined) {
|
|
44
|
-
Effect.runSync(EffectLogger$ReventlessCore.logDebug(comp, undefined, `found CommandTopic handler for ` + urn));
|
|
44
|
+
Effect.runSync(EffectLogger$ReventlessCore.logDebug(comp, undefined, undefined, `found CommandTopic handler for ` + urn));
|
|
45
45
|
return await runEffect(handler(event, context));
|
|
46
46
|
}
|
|
47
47
|
let handlers = eventCollectorHandlers[urn];
|
|
48
48
|
if (handlers !== undefined) {
|
|
49
49
|
let count = handlers.length.toString();
|
|
50
|
-
Effect.runSync(EffectLogger$ReventlessCore.logDebug(comp, undefined, `found ` + count + ` EventCollector handler(s) for ` + urn));
|
|
50
|
+
Effect.runSync(EffectLogger$ReventlessCore.logDebug(comp, undefined, undefined, `found ` + count + ` EventCollector handler(s) for ` + urn));
|
|
51
51
|
await Promise.all(handlers.map(param => Runtime$ReventlessCore.runEffect(correlationId, causationId, param.comp, undefined, timestamp, retryCount, undefined, undefined, param.handler(event, context))));
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
54
|
let available = Object.keys(commandTopicHandlers).concat(Object.keys(eventCollectorHandlers)).join(",");
|
|
55
|
-
return Effect.runSync(EffectLogger$ReventlessCore.logWarn(comp, undefined, `no handler found: ` + urn + ` available=[` + available + `]`));
|
|
55
|
+
return Effect.runSync(EffectLogger$ReventlessCore.logWarn(comp, undefined, undefined, `no handler found: ` + urn + ` available=[` + available + `]`));
|
|
56
56
|
}));
|
|
57
57
|
});
|
|
58
58
|
let getRuntimeSpec = aggregate => Stdlib_Option.getOr(runtimeSpecs[Stdlib_Option.getOr(aggregate.__name, "Unnamed")], {
|
|
@@ -38,10 +38,10 @@ function Make(RuntimeEnvironment) {
|
|
|
38
38
|
let urn = param[0];
|
|
39
39
|
let handlers = eventCollectorHandlers[urn];
|
|
40
40
|
if (handlers === undefined) {
|
|
41
|
-
return Effect.runSync(EffectLogger$ReventlessCore.logWarn(groupComp, undefined, `no handler found: ` + urn));
|
|
41
|
+
return Effect.runSync(EffectLogger$ReventlessCore.logWarn(groupComp, undefined, undefined, `no handler found: ` + urn));
|
|
42
42
|
}
|
|
43
43
|
let count = handlers.length.toString();
|
|
44
|
-
Effect.runSync(EffectLogger$ReventlessCore.logDebug(groupComp, undefined, `found ` + count + ` handler(s) for ` + urn));
|
|
44
|
+
Effect.runSync(EffectLogger$ReventlessCore.logDebug(groupComp, undefined, undefined, `found ` + count + ` handler(s) for ` + urn));
|
|
45
45
|
await Promise.all(handlers.map(param => Runtime$ReventlessCore.runEffect(correlationId, causationId, param.comp, undefined, timestamp, retryCount, undefined, undefined, param.handler(event, context))));
|
|
46
46
|
}));
|
|
47
47
|
});
|
|
@@ -7,7 +7,7 @@ import * as EffectLogger$ReventlessCore from "../util/EffectLogger.res.mjs";
|
|
|
7
7
|
import * as Platform_Admin_Structure$ReventlessCore from "./Platform_Admin_Structure.res.mjs";
|
|
8
8
|
|
|
9
9
|
function Make(Spec) {
|
|
10
|
-
let handleJsonEvents = stream => Stream.runDrain(Stream.mapEffect(stream, eventJson$p => Effect.zipRight(EffectLogger$ReventlessCore.logInfo(Platform_Admin_Structure$ReventlessCore.pluginId, undefined, `handleJsonEvents: outgoing event: ` + LogFormat$ReventlessCore.event$pJsonToLogMessage(eventJson$p)), Effect.map(Effect.all(Spec.outgoingExtensionPointJsonEventsHandlers.map(handleEvent => Effect.promise(() => handleEvent(eventJson$p, Spec.pluginDefinition))), {
|
|
10
|
+
let handleJsonEvents = stream => Stream.runDrain(Stream.mapEffect(stream, eventJson$p => Effect.zipRight(EffectLogger$ReventlessCore.logInfo(Platform_Admin_Structure$ReventlessCore.pluginId, undefined, undefined, `handleJsonEvents: outgoing event: ` + LogFormat$ReventlessCore.event$pJsonToLogMessage(eventJson$p)), Effect.map(Effect.all(Spec.outgoingExtensionPointJsonEventsHandlers.map(handleEvent => Effect.promise(() => handleEvent(eventJson$p, Spec.pluginDefinition))), {
|
|
11
11
|
concurrency: "unbounded"
|
|
12
12
|
}), param => {}))));
|
|
13
13
|
return {
|