@reventlessdev/reventless-core 3.0.0-alpha.325 → 3.0.0-alpha.326
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 +8 -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/components/Aggregate/Aggregate_Callback.res +6 -1
- package/src/components/Aggregate/Aggregate_Callback.res.mjs +6 -5
- package/src/components/AutomationSlice/AutomationSlice_Callback.res +21 -9
- package/src/components/AutomationSlice/AutomationSlice_Callback.res.mjs +19 -8
- package/src/components/CommandTopic/CommandTopic.res.mjs +5 -2
- package/src/components/CommandTopic/CommandTopic_Helpers.res +56 -26
- package/src/components/CommandTopic/CommandTopic_Helpers.res.mjs +35 -16
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res +6 -2
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Builder.res.mjs +6 -2
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res +25 -12
- package/src/components/OutboundTranslationSlice/OutboundTranslationSlice_Callback.res.mjs +20 -7
- package/src/components/ReadModel/ReadModel_Callback.res +23 -3
- package/src/components/ReadModel/ReadModel_Callback.res.mjs +14 -2
- package/src/components/StateChangeSlice/StateChangeSlice_Callback.res +7 -0
- package/src/components/StateChangeSlice/StateChangeSlice_Callback.res.mjs +7 -7
- package/src/components/StateViewSlice/StateViewSlice_Builder.res +14 -2
- package/src/components/StateViewSlice/StateViewSlice_Builder.res.mjs +13 -2
- package/src/components/StateViewSlice/StateViewSlice_Callback.res +29 -4
- package/src/components/StateViewSlice/StateViewSlice_Callback.res.mjs +9 -2
- package/src/util/EffectLogger.res +30 -29
- package/src/util/EffectLogger.res.mjs +13 -22
- package/src/util/Logger.res +231 -35
- package/src/util/Logger.res.mjs +263 -42
- package/tests/commandgenerator/OwnerActingTest.res +3 -1
- package/tests/commandtopic/CommandOutcomeHookTest.res +74 -2
- package/tests/commandtopic/CommandOutcomeHookTest.res.mjs +92 -0
- package/tests/commandtopic/CommandTopicHelpersRejectionTest.res.mjs +4 -4
- 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,173 @@
|
|
|
1
|
+
// Which rows an event changed: each row a projection writes or removes is reported
|
|
2
|
+
// once, with the message ids of the events whose actions were applied to it, and
|
|
3
|
+
// the `view changed` log line names the fields that changed, never their values.
|
|
4
|
+
|
|
5
|
+
open JestGlobals
|
|
6
|
+
|
|
7
|
+
@schema
|
|
8
|
+
type row = {
|
|
9
|
+
name: string,
|
|
10
|
+
total: int,
|
|
11
|
+
token: @s.matches(Reventless.Sensitive.string) string,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** A store of one row per key, in memory. */
|
|
15
|
+
let makeOps = (): (dict<row>, QueryDb.operations<string, row>) => {
|
|
16
|
+
let rows: dict<row> = Dict.make()
|
|
17
|
+
let ops: QueryDb.operations<string, row> = {
|
|
18
|
+
load: async id => Ok(rows->Dict.get(id)->Option.mapOr([], r => [r])),
|
|
19
|
+
loadStream: id => rows->Dict.get(id)->Option.mapOr([], r => [r])->Stream.fromIterable,
|
|
20
|
+
save: async (id, state, _, _) => {
|
|
21
|
+
rows->Dict.set(id, state)
|
|
22
|
+
Ok()
|
|
23
|
+
},
|
|
24
|
+
saveBatch: async batch => {
|
|
25
|
+
batch->Array.forEach(((id, state, _)) => rows->Dict.set(id, state))
|
|
26
|
+
Ok()
|
|
27
|
+
},
|
|
28
|
+
count: async (_, _, n) => Ok(n),
|
|
29
|
+
delete: async (id, _) => {
|
|
30
|
+
rows->Dict.delete(id)
|
|
31
|
+
Ok()
|
|
32
|
+
},
|
|
33
|
+
deleteBatch: async ids => {
|
|
34
|
+
ids->Array.forEach(((id, _)) => rows->Dict.delete(id))
|
|
35
|
+
Ok()
|
|
36
|
+
},
|
|
37
|
+
}
|
|
38
|
+
(rows, ops)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
let reporterFor = view =>
|
|
42
|
+
ViewChange.reporter(~comp=`ReadModel(${view})`, ~view, ~stateToJson=state =>
|
|
43
|
+
state->Reventless.Util_Sury.toJson(rowSchema)
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
let source = (msgId): Projection.changeSource => {
|
|
47
|
+
msgId,
|
|
48
|
+
correlationId: "flow-1",
|
|
49
|
+
entityId: "order-1",
|
|
50
|
+
entityType: "Order",
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let heard: ref<array<ViewChange.t>> = ref([])
|
|
54
|
+
let removeListener = ref(() => ())
|
|
55
|
+
|
|
56
|
+
let msgIdsOf = (c: ViewChange.t) => c.sources->Array.map(s => s.msgId)
|
|
57
|
+
|
|
58
|
+
describe("ViewChange", () => {
|
|
59
|
+
beforeEach(() => {
|
|
60
|
+
heard := []
|
|
61
|
+
removeListener := ViewChange.register(c => heard := heard.contents->Array.concat([c]))
|
|
62
|
+
})
|
|
63
|
+
afterEach(() => removeListener.contents())
|
|
64
|
+
|
|
65
|
+
testPromise(
|
|
66
|
+
"one event changing two rows in two views gives two changes with its id",
|
|
67
|
+
async () => {
|
|
68
|
+
let (_, totals) = makeOps()
|
|
69
|
+
let (seeded, names) = makeOps()
|
|
70
|
+
seeded->Dict.set("b", {name: "B", total: 1, token: "t"})
|
|
71
|
+
let sources = [source("m-1")]
|
|
72
|
+
|
|
73
|
+
let _ = await Projection.handleAction(
|
|
74
|
+
~sources,
|
|
75
|
+
~onChange=reporterFor("Totals"),
|
|
76
|
+
Create("a", {name: "A", total: 1, token: "t"}),
|
|
77
|
+
totals,
|
|
78
|
+
None,
|
|
79
|
+
)
|
|
80
|
+
let _ = await Projection.handleAction(
|
|
81
|
+
~sources,
|
|
82
|
+
~onChange=reporterFor("Names"),
|
|
83
|
+
Update("b", r => {...r, total: r.total + 1}),
|
|
84
|
+
names,
|
|
85
|
+
None,
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
expect(
|
|
89
|
+
heard.contents->Array.map(c => (c.view, c.key, ViewChange.kindLabel(c.kind), msgIdsOf(c))),
|
|
90
|
+
)->toEqual([("Totals", "a", "created", ["m-1"]), ("Names", "b", "changed", ["m-1"])])
|
|
91
|
+
expect((heard.contents->Array.getUnsafe(1)).fields)->toEqual(["total"])
|
|
92
|
+
expect((heard.contents->Array.getUnsafe(0)).correlationId)->toEqual(Some("flow-1"))
|
|
93
|
+
expect((heard.contents->Array.getUnsafe(0)).sources->Array.map(s => s.entityId))->toEqual([
|
|
94
|
+
Some("order-1"),
|
|
95
|
+
])
|
|
96
|
+
},
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
testPromise("a merged update keeps the ids of both events", async () => {
|
|
100
|
+
let (seeded, ops) = makeOps()
|
|
101
|
+
seeded->Dict.set("a", {name: "A", total: 0, token: "t"})
|
|
102
|
+
|
|
103
|
+
await Projection.handleSourcedActions(
|
|
104
|
+
~onChange=reporterFor("Totals"),
|
|
105
|
+
[
|
|
106
|
+
{action: Update("a", r => {...r, total: r.total + 1}), sources: [source("m-1")]},
|
|
107
|
+
{action: Update("a", r => {...r, total: r.total + 2}), sources: [source("m-2")]},
|
|
108
|
+
],
|
|
109
|
+
ops,
|
|
110
|
+
None,
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
expect(heard.contents->Array.map(msgIdsOf))->toEqual([["m-1", "m-2"]])
|
|
114
|
+
expect((seeded->Dict.getUnsafe("a")).total)->toBe(3)
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
testPromise("a removal and a write that changed nothing", async () => {
|
|
118
|
+
let (seeded, ops) = makeOps()
|
|
119
|
+
seeded->Dict.set("a", {name: "A", total: 0, token: "t"})
|
|
120
|
+
let sources = [source("m-1")]
|
|
121
|
+
|
|
122
|
+
let _ = await Projection.handleAction(
|
|
123
|
+
~sources,
|
|
124
|
+
~onChange=reporterFor("Totals"),
|
|
125
|
+
Update("a", r => {...r, name: "A"}),
|
|
126
|
+
ops,
|
|
127
|
+
None,
|
|
128
|
+
)
|
|
129
|
+
let _ = await Projection.handleAction(
|
|
130
|
+
~sources,
|
|
131
|
+
~onChange=reporterFor("Totals"),
|
|
132
|
+
Delete("a"),
|
|
133
|
+
ops,
|
|
134
|
+
None,
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
expect(heard.contents->Array.map(c => ViewChange.kindLabel(c.kind)))->toEqual(["removed"])
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
testPromise("the log line names the changed fields and never their values", async () => {
|
|
141
|
+
let lines = []
|
|
142
|
+
let removeSink = Logger.addSink(r => lines->Array.push(r))
|
|
143
|
+
let (seeded, ops) = makeOps()
|
|
144
|
+
seeded->Dict.set("a", {name: "A", total: 0, token: "old-secret"})
|
|
145
|
+
|
|
146
|
+
let _ = await Projection.handleAction(
|
|
147
|
+
~sources=[source("m-1")],
|
|
148
|
+
~onChange=reporterFor("Totals"),
|
|
149
|
+
Update("a", r => {...r, total: 5, token: "new-secret"}),
|
|
150
|
+
ops,
|
|
151
|
+
None,
|
|
152
|
+
)
|
|
153
|
+
removeSink()
|
|
154
|
+
|
|
155
|
+
let viewLines = lines->Array.filter(r => r.message == "view changed")
|
|
156
|
+
expect(viewLines->Array.length)->toBe(1)
|
|
157
|
+
let line = viewLines->Array.getUnsafe(0)
|
|
158
|
+
let printed = line->Logger.recordToJson->JSON.stringify
|
|
159
|
+
expect(line.level)->toEqual(Logger.Info)
|
|
160
|
+
expect(line.comp)->toEqual(Some("ReadModel(Totals)"))
|
|
161
|
+
expect(line.annotations->Dict.get("correlationId"))->toEqual(Some("flow-1"))
|
|
162
|
+
expect(printed->String.includes(`"fields":["total","token"]`))->toBe(true)
|
|
163
|
+
expect(printed->String.includes(`"msgId":"m-1"`))->toBe(true)
|
|
164
|
+
expect(printed->String.includes(`"entityType":"Order"`))->toBe(true)
|
|
165
|
+
expect(printed->String.includes("secret"))->toBe(false)
|
|
166
|
+
// The listener gets the values, for a reader that redacts them itself.
|
|
167
|
+
expect(
|
|
168
|
+
(heard.contents->Array.getUnsafe(0)).after
|
|
169
|
+
->Option.map(j => j->JSON.stringify)
|
|
170
|
+
->Option.mapOr(false, s => s->String.includes("new-secret")),
|
|
171
|
+
)->toBe(true)
|
|
172
|
+
})
|
|
173
|
+
})
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Sury from "sury";
|
|
4
|
+
import * as Stdlib_Dict from "@rescript/runtime/lib/es6/Stdlib_Dict.js";
|
|
5
|
+
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
6
|
+
import * as Stream from "effect/Stream";
|
|
7
|
+
import * as Sensitive$Reventless from "@reventlessdev/reventless-spec/src/components/Sensitive.res.mjs";
|
|
8
|
+
import * as Util_Sury$Reventless from "@reventlessdev/reventless-spec/src/util/Util_Sury.res.mjs";
|
|
9
|
+
import * as Logger$ReventlessCore from "../../src/util/Logger.res.mjs";
|
|
10
|
+
import * as Projection$ReventlessCore from "../../src/Projection.res.mjs";
|
|
11
|
+
import * as ViewChange$ReventlessCore from "../../src/ViewChange.res.mjs";
|
|
12
|
+
|
|
13
|
+
let rowSchema = Sury.$schema(s => ({
|
|
14
|
+
name: s.m(Sury.string),
|
|
15
|
+
total: s.m(Sury.int32),
|
|
16
|
+
token: s.m(Sensitive$Reventless.string)
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
function makeOps() {
|
|
20
|
+
let rows = {};
|
|
21
|
+
let ops_load = async id => ({
|
|
22
|
+
TAG: "Ok",
|
|
23
|
+
_0: Stdlib_Option.mapOr(rows[id], [], r => [r])
|
|
24
|
+
});
|
|
25
|
+
let ops_loadStream = id => Stream.fromIterable(Stdlib_Option.mapOr(rows[id], [], r => [r]));
|
|
26
|
+
let ops_save = async (id, state, param, param$1) => {
|
|
27
|
+
rows[id] = state;
|
|
28
|
+
return {
|
|
29
|
+
TAG: "Ok",
|
|
30
|
+
_0: undefined
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
let ops_saveBatch = async batch => {
|
|
34
|
+
batch.forEach(param => {
|
|
35
|
+
rows[param[0]] = param[1];
|
|
36
|
+
});
|
|
37
|
+
return {
|
|
38
|
+
TAG: "Ok",
|
|
39
|
+
_0: undefined
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
let ops_count = async (param, param$1, n) => ({
|
|
43
|
+
TAG: "Ok",
|
|
44
|
+
_0: n
|
|
45
|
+
});
|
|
46
|
+
let ops_delete = async (id, param) => {
|
|
47
|
+
Stdlib_Dict.$$delete(rows, id);
|
|
48
|
+
return {
|
|
49
|
+
TAG: "Ok",
|
|
50
|
+
_0: undefined
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
let ops_deleteBatch = async ids => {
|
|
54
|
+
ids.forEach(param => Stdlib_Dict.$$delete(rows, param[0]));
|
|
55
|
+
return {
|
|
56
|
+
TAG: "Ok",
|
|
57
|
+
_0: undefined
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
let ops = {
|
|
61
|
+
load: ops_load,
|
|
62
|
+
loadStream: ops_loadStream,
|
|
63
|
+
save: ops_save,
|
|
64
|
+
saveBatch: ops_saveBatch,
|
|
65
|
+
count: ops_count,
|
|
66
|
+
delete: ops_delete,
|
|
67
|
+
deleteBatch: ops_deleteBatch
|
|
68
|
+
};
|
|
69
|
+
return [
|
|
70
|
+
rows,
|
|
71
|
+
ops
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function reporterFor(view) {
|
|
76
|
+
return ViewChange$ReventlessCore.reporter(`ReadModel(` + view + `)`, view, state => Util_Sury$Reventless.toJson(state, rowSchema));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function source(msgId) {
|
|
80
|
+
return {
|
|
81
|
+
msgId: msgId,
|
|
82
|
+
correlationId: "flow-1",
|
|
83
|
+
entityId: "order-1",
|
|
84
|
+
entityType: "Order"
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
let heard = {
|
|
89
|
+
contents: []
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
let removeListener = {
|
|
93
|
+
contents: () => {}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
function msgIdsOf(c) {
|
|
97
|
+
return c.sources.map(s => s.msgId);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
globalThis.describe("ViewChange", () => {
|
|
101
|
+
globalThis.beforeEach(() => {
|
|
102
|
+
heard.contents = [];
|
|
103
|
+
removeListener.contents = ViewChange$ReventlessCore.register(c => {
|
|
104
|
+
heard.contents = heard.contents.concat([c]);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
globalThis.afterEach(() => removeListener.contents());
|
|
108
|
+
globalThis.test("one event changing two rows in two views gives two changes with its id", async () => {
|
|
109
|
+
let match = makeOps();
|
|
110
|
+
let match$1 = makeOps();
|
|
111
|
+
match$1[0]["b"] = {
|
|
112
|
+
name: "B",
|
|
113
|
+
total: 1,
|
|
114
|
+
token: "t"
|
|
115
|
+
};
|
|
116
|
+
let sources = [{
|
|
117
|
+
msgId: "m-1",
|
|
118
|
+
correlationId: "flow-1",
|
|
119
|
+
entityId: "order-1",
|
|
120
|
+
entityType: "Order"
|
|
121
|
+
}];
|
|
122
|
+
await Projection$ReventlessCore.handleAction(undefined, sources, reporterFor("Totals"), {
|
|
123
|
+
TAG: "Create",
|
|
124
|
+
_0: "a",
|
|
125
|
+
_1: {
|
|
126
|
+
name: "A",
|
|
127
|
+
total: 1,
|
|
128
|
+
token: "t"
|
|
129
|
+
}
|
|
130
|
+
}, match[1], undefined);
|
|
131
|
+
await Projection$ReventlessCore.handleAction(undefined, sources, reporterFor("Names"), {
|
|
132
|
+
TAG: "Update",
|
|
133
|
+
_0: "b",
|
|
134
|
+
_1: r => ({
|
|
135
|
+
name: r.name,
|
|
136
|
+
total: r.total + 1 | 0,
|
|
137
|
+
token: r.token
|
|
138
|
+
})
|
|
139
|
+
}, match$1[1], undefined);
|
|
140
|
+
globalThis.expect(heard.contents.map(c => [
|
|
141
|
+
c.view,
|
|
142
|
+
c.key,
|
|
143
|
+
ViewChange$ReventlessCore.kindLabel(c.kind),
|
|
144
|
+
msgIdsOf(c)
|
|
145
|
+
])).toEqual([
|
|
146
|
+
[
|
|
147
|
+
"Totals",
|
|
148
|
+
"a",
|
|
149
|
+
"created",
|
|
150
|
+
["m-1"]
|
|
151
|
+
],
|
|
152
|
+
[
|
|
153
|
+
"Names",
|
|
154
|
+
"b",
|
|
155
|
+
"changed",
|
|
156
|
+
["m-1"]
|
|
157
|
+
]
|
|
158
|
+
]);
|
|
159
|
+
globalThis.expect(heard.contents[1].fields).toEqual(["total"]);
|
|
160
|
+
globalThis.expect(heard.contents[0].correlationId).toEqual("flow-1");
|
|
161
|
+
globalThis.expect(heard.contents[0].sources.map(s => s.entityId)).toEqual(["order-1"]);
|
|
162
|
+
});
|
|
163
|
+
globalThis.test("a merged update keeps the ids of both events", async () => {
|
|
164
|
+
let match = makeOps();
|
|
165
|
+
let seeded = match[0];
|
|
166
|
+
seeded["a"] = {
|
|
167
|
+
name: "A",
|
|
168
|
+
total: 0,
|
|
169
|
+
token: "t"
|
|
170
|
+
};
|
|
171
|
+
await Projection$ReventlessCore.handleSourcedActions(undefined, reporterFor("Totals"), [
|
|
172
|
+
{
|
|
173
|
+
action: {
|
|
174
|
+
TAG: "Update",
|
|
175
|
+
_0: "a",
|
|
176
|
+
_1: r => ({
|
|
177
|
+
name: r.name,
|
|
178
|
+
total: r.total + 1 | 0,
|
|
179
|
+
token: r.token
|
|
180
|
+
})
|
|
181
|
+
},
|
|
182
|
+
sources: [{
|
|
183
|
+
msgId: "m-1",
|
|
184
|
+
correlationId: "flow-1",
|
|
185
|
+
entityId: "order-1",
|
|
186
|
+
entityType: "Order"
|
|
187
|
+
}]
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
action: {
|
|
191
|
+
TAG: "Update",
|
|
192
|
+
_0: "a",
|
|
193
|
+
_1: r => ({
|
|
194
|
+
name: r.name,
|
|
195
|
+
total: r.total + 2 | 0,
|
|
196
|
+
token: r.token
|
|
197
|
+
})
|
|
198
|
+
},
|
|
199
|
+
sources: [{
|
|
200
|
+
msgId: "m-2",
|
|
201
|
+
correlationId: "flow-1",
|
|
202
|
+
entityId: "order-1",
|
|
203
|
+
entityType: "Order"
|
|
204
|
+
}]
|
|
205
|
+
}
|
|
206
|
+
], match[1], undefined);
|
|
207
|
+
globalThis.expect(heard.contents.map(msgIdsOf)).toEqual([[
|
|
208
|
+
"m-1",
|
|
209
|
+
"m-2"
|
|
210
|
+
]]);
|
|
211
|
+
globalThis.expect(seeded["a"].total).toBe(3);
|
|
212
|
+
});
|
|
213
|
+
globalThis.test("a removal and a write that changed nothing", async () => {
|
|
214
|
+
let match = makeOps();
|
|
215
|
+
let ops = match[1];
|
|
216
|
+
match[0]["a"] = {
|
|
217
|
+
name: "A",
|
|
218
|
+
total: 0,
|
|
219
|
+
token: "t"
|
|
220
|
+
};
|
|
221
|
+
let sources = [{
|
|
222
|
+
msgId: "m-1",
|
|
223
|
+
correlationId: "flow-1",
|
|
224
|
+
entityId: "order-1",
|
|
225
|
+
entityType: "Order"
|
|
226
|
+
}];
|
|
227
|
+
await Projection$ReventlessCore.handleAction(undefined, sources, reporterFor("Totals"), {
|
|
228
|
+
TAG: "Update",
|
|
229
|
+
_0: "a",
|
|
230
|
+
_1: r => ({
|
|
231
|
+
name: "A",
|
|
232
|
+
total: r.total,
|
|
233
|
+
token: r.token
|
|
234
|
+
})
|
|
235
|
+
}, ops, undefined);
|
|
236
|
+
await Projection$ReventlessCore.handleAction(undefined, sources, reporterFor("Totals"), {
|
|
237
|
+
TAG: "Delete",
|
|
238
|
+
_0: "a"
|
|
239
|
+
}, ops, undefined);
|
|
240
|
+
globalThis.expect(heard.contents.map(c => ViewChange$ReventlessCore.kindLabel(c.kind))).toEqual(["removed"]);
|
|
241
|
+
});
|
|
242
|
+
globalThis.test("the log line names the changed fields and never their values", async () => {
|
|
243
|
+
let lines = [];
|
|
244
|
+
let removeSink = Logger$ReventlessCore.addSink(r => {
|
|
245
|
+
lines.push(r);
|
|
246
|
+
});
|
|
247
|
+
let match = makeOps();
|
|
248
|
+
match[0]["a"] = {
|
|
249
|
+
name: "A",
|
|
250
|
+
total: 0,
|
|
251
|
+
token: "old-secret"
|
|
252
|
+
};
|
|
253
|
+
await Projection$ReventlessCore.handleAction(undefined, [{
|
|
254
|
+
msgId: "m-1",
|
|
255
|
+
correlationId: "flow-1",
|
|
256
|
+
entityId: "order-1",
|
|
257
|
+
entityType: "Order"
|
|
258
|
+
}], reporterFor("Totals"), {
|
|
259
|
+
TAG: "Update",
|
|
260
|
+
_0: "a",
|
|
261
|
+
_1: r => ({
|
|
262
|
+
name: r.name,
|
|
263
|
+
total: 5,
|
|
264
|
+
token: "new-secret"
|
|
265
|
+
})
|
|
266
|
+
}, match[1], undefined);
|
|
267
|
+
removeSink();
|
|
268
|
+
let viewLines = lines.filter(r => r.message === "view changed");
|
|
269
|
+
globalThis.expect(viewLines.length).toBe(1);
|
|
270
|
+
let line = viewLines[0];
|
|
271
|
+
let printed = JSON.stringify(Logger$ReventlessCore.recordToJson(line));
|
|
272
|
+
globalThis.expect(line.level).toEqual("Info");
|
|
273
|
+
globalThis.expect(line.comp).toEqual("ReadModel(Totals)");
|
|
274
|
+
globalThis.expect(line.annotations["correlationId"]).toEqual("flow-1");
|
|
275
|
+
globalThis.expect(printed.includes(`"fields":["total","token"]`)).toBe(true);
|
|
276
|
+
globalThis.expect(printed.includes(`"msgId":"m-1"`)).toBe(true);
|
|
277
|
+
globalThis.expect(printed.includes(`"entityType":"Order"`)).toBe(true);
|
|
278
|
+
globalThis.expect(printed.includes("secret")).toBe(false);
|
|
279
|
+
globalThis.expect(Stdlib_Option.mapOr(Stdlib_Option.map(heard.contents[0].after, j => JSON.stringify(j)), false, s => s.includes("new-secret"))).toBe(true);
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
export {
|
|
284
|
+
rowSchema,
|
|
285
|
+
makeOps,
|
|
286
|
+
reporterFor,
|
|
287
|
+
source,
|
|
288
|
+
heard,
|
|
289
|
+
removeListener,
|
|
290
|
+
msgIdsOf,
|
|
291
|
+
}
|
|
292
|
+
/* rowSchema Not a pure module */
|